/usr/share/pari/pari.desc is in libpari-dev 2.9.4-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | Function: !_
Class: basic
Section: symbolic_operators
C-Name: gnot
Prototype: G
Help: !_
Description:
(negbool):bool:parens $1
(bool):negbool:parens $1
Function: #_
Class: basic
Section: symbolic_operators
C-Name: glength
Prototype: lG
Help: #x: number of non code words in x, number of characters for a string.
Description:
(vecsmall):lg lg($1)
(vec):lg lg($1)
(pol):small lgpol($1)
(gen):small glength($1)
Function: %
Class: basic
Section: symbolic_operators
C-Name: pari_get_hist
Prototype: D0,L,
Help: last history item.
Function: %#
Class: basic
Section: symbolic_operators
C-Name: pari_get_histtime
Prototype: lD0,L,
Help: time to compute last history item.
Function: +_
Class: basic
Section: symbolic_operators
Help: +_
Description:
(small):small:parens $1
(int):int:parens:copy $1
(real):real:parens:copy $1
(mp):mp:parens:copy $1
(gen):gen:parens:copy $1
Function: -_
Class: basic
Section: symbolic_operators
C-Name: gneg
Prototype: G
Help: -_
Description:
(small):small:parens -$(1)
(int):int negi($1)
(real):real negr($1)
(mp):mp mpneg($1)
(gen):gen gneg($1)
(Fp):Fp Fp_neg($1, p)
(FpX):FpX FpX_neg($1, p)
(Fq):Fq Fq_neg($1, T, p)
(FqX):FqX FqX_neg($1, T, p)
Function: Catalan
Class: basic
Section: transcendental
C-Name: mpcatalan
Prototype: p
Help: Catalan=Catalan(): Catalan's number with current precision.
Description:
():real:prec mpcatalan($prec)
Doc: Catalan's constant $G = \sum_{n>=0}\dfrac{(-1)^n}{(2n+1)^2}=0.91596\cdots$.
Note that \kbd{Catalan} is one of the few reserved names which cannot be
used for user variables.
Function: Col
Class: basic
Section: conversions
C-Name: gtocol0
Prototype: GD0,L,
Help: Col(x, {n}): transforms the object x into a column vector of dimension n.
Description:
(gen):vec gtocol($1)
Doc:
transforms the object $x$ into a column vector. The dimension of the
resulting vector can be optionally specified via the extra parameter $n$.
If $n$ is omitted or $0$, the dimension depends on the type of $x$; the
vector has a single component, except when $x$ is
\item a vector or a quadratic form (in which case the resulting vector
is simply the initial object considered as a row vector),
\item a polynomial or a power series. In the case of a polynomial, the
coefficients of the vector start with the leading coefficient of the
polynomial, while for power series only the significant coefficients are
taken into account, but this time by increasing order of degree.
In this last case, \kbd{Vec} is the reciprocal function of \kbd{Pol} and
\kbd{Ser} respectively,
\item a matrix (the column of row vector comprising the matrix is returned),
\item a character string (a vector of individual characters is returned).
In the last two cases (matrix and character string), $n$ is meaningless and
must be omitted or an error is raised. Otherwise, if $n$ is given, $0$
entries are appended at the end of the vector if $n > 0$, and prepended at
the beginning if $n < 0$. The dimension of the resulting vector is $|n|$.
Variant: \fun{GEN}{gtocol}{GEN x} is also available.
Function: Colrev
Class: basic
Section: conversions
C-Name: gtocolrev0
Prototype: GD0,L,
Help: Colrev(x, {n}): transforms the object x into a column vector of
dimension n in reverse order with respect to Col(x, {n}). Empty vector if x
is omitted.
Description:
(gen):vec gtocolrev($1)
Doc:
as $\kbd{Col}(x, -n)$, then reverse the result. In particular,
\kbd{Colrev} is the reciprocal function of \kbd{Polrev}: the
coefficients of the vector start with the constant coefficient of the
polynomial and the others follow by increasing degree.
Variant: \fun{GEN}{gtocolrev}{GEN x} is also available.
Function: DEBUGLEVEL
Class: gp2c
C-Name: DEBUGLEVEL
Prototype: v
Description:
():small DEBUGLEVEL
Function: Euler
Class: basic
Section: transcendental
C-Name: mpeuler
Prototype: p
Help: Euler=Euler(): Euler's constant with current precision.
Description:
():real:prec mpeuler($prec)
Doc: Euler's constant $\gamma=0.57721\cdots$. Note that
\kbd{Euler} is one of the few reserved names which cannot be used for
user variables.
Function: I
Class: basic
Section: transcendental
C-Name: gen_I
Prototype:
Help: I=I(): square root of -1.
Description:
Doc: the complex number $\sqrt{-1}$.
Function: List
Class: basic
Section: conversions
C-Name: gtolist
Prototype: DG
Help: List({x=[]}): transforms the vector or list x into a list. Empty list
if x is omitted.
Description:
():list mklist()
(gen):list gtolist($1)
Doc:
transforms a (row or column) vector $x$ into a list, whose components are
the entries of $x$. Similarly for a list, but rather useless in this case.
For other types, creates a list with the single element $x$. Note that,
except when $x$ is omitted, this function creates a small memory leak; so,
either initialize all lists to the empty list, or use them sparingly.
Variant: The variant \fun{GEN}{mklist}{void} creates an empty list.
Function: Map
Class: basic
Section: conversions
C-Name: gtomap
Prototype: DG
Help: Map({x}): converts the matrix [a_1,b_1;a_2,b_2;...;a_n,b_n] to the map a_i->b_i.
Doc: A ``Map'' is an associative array, or dictionary: a data
type composed of a collection of (\emph{key}, \emph{value}) pairs, such that
each key appears just once in the collection. This function
converts the matrix $[a_1,b_1;a_2,b_2;\dots;a_n,b_n]$ to the map $a_i\mapsto
b_i$.
\bprog
? M = Map(factor(13!));
? mapget(M,3)
%2 = 5
@eprog\noindent If the argument $x$ is omitted, creates an empty map, which
may be filled later via \tet{mapput}.
Function: Mat
Class: basic
Section: conversions
C-Name: gtomat
Prototype: DG
Help: Mat({x=[]}): transforms any GEN x into a matrix. Empty matrix if x is
omitted.
Description:
():vec cgetg(1, t_MAT)
(gen):vec gtomat($1)
Doc:
transforms the object $x$ into a matrix.
If $x$ is already a matrix, a copy of $x$ is created.
If $x$ is a row (resp. column) vector, this creates a 1-row (resp.
1-column) matrix, \emph{unless} all elements are column (resp.~row) vectors
of the same length, in which case the vectors are concatenated sideways
and the attached big matrix is returned.
If $x$ is a binary quadratic form, creates the attached $2\times 2$
matrix. Otherwise, this creates a $1\times 1$ matrix containing $x$.
\bprog
? Mat(x + 1)
%1 =
[x + 1]
? Vec( matid(3) )
%2 = [[1, 0, 0]~, [0, 1, 0]~, [0, 0, 1]~]
? Mat(%)
%3 =
[1 0 0]
[0 1 0]
[0 0 1]
? Col( [1,2; 3,4] )
%4 = [[1, 2], [3, 4]]~
? Mat(%)
%5 =
[1 2]
[3 4]
? Mat(Qfb(1,2,3))
%6 =
[1 1]
[1 3]
@eprog
Function: Mod
Class: basic
Section: conversions
C-Name: gmodulo
Prototype: GG
Help: Mod(a,b): creates 'a modulo b'.
Description:
(small, small):gen gmodulss($1, $2)
(small, gen):gen gmodulsg($1, $2)
(gen, gen):gen gmodulo($1, $2)
Doc: in its basic form, creates an intmod or a polmod $(a \mod b)$; $b$ must
be an integer or a polynomial. We then obtain a \typ{INTMOD} and a
\typ{POLMOD} respectively:
\bprog
? t = Mod(2,17); t^8
%1 = Mod(1, 17)
? t = Mod(x,x^2+1); t^2
%2 = Mod(-1, x^2+1)
@eprog\noindent If $a \% b$ makes sense and yields a result of the
appropriate type (\typ{INT} or scalar/\typ{POL}), the operation succeeds as
well:
\bprog
? Mod(1/2, 5)
%3 = Mod(3, 5)
? Mod(7 + O(3^6), 3)
%4 = Mod(1, 3)
? Mod(Mod(1,12), 9)
%5 = Mod(1, 3)
? Mod(1/x, x^2+1)
%6 = Mod(-1, x^2+1)
? Mod(exp(x), x^4)
%7 = Mod(1/6*x^3 + 1/2*x^2 + x + 1, x^4)
@eprog
If $a$ is a complex object, ``base change'' it to $\Z/b\Z$ or $K[x]/(b)$,
which is equivalent to, but faster than, multiplying it by \kbd{Mod(1,b)}:
\bprog
? Mod([1,2;3,4], 2)
%8 =
[Mod(1, 2) Mod(0, 2)]
[Mod(1, 2) Mod(0, 2)]
? Mod(3*x+5, 2)
%9 = Mod(1, 2)*x + Mod(1, 2)
? Mod(x^2 + y*x + y^3, y^2+1)
%10 = Mod(1, y^2 + 1)*x^2 + Mod(y, y^2 + 1)*x + Mod(-y, y^2 + 1)
@eprog
This function is not the same as $x$ \kbd{\%} $y$, the result of which
has no knowledge of the intended modulus $y$. Compare
\bprog
? x = 4 % 5; x + 1
%1 = 5
? x = Mod(4,5); x + 1
%2 = Mod(0,5)
@eprog Note that such ``modular'' objects can be lifted via \tet{lift} or
\tet{centerlift}. The modulus of a \typ{INTMOD} or \typ{POLMOD} $z$ can
be recovered via \kbd{$z$.mod}.
Function: O
Class: basic
Section: polynomials
C-Name: ggrando
Prototype:
Help: O(p^e): p-adic or power series zero with precision given by e.
Doc: if $p$ is an integer
greater than $2$, returns a $p$-adic $0$ of precision $e$. In all other
cases, returns a power series zero with precision given by $e v$, where $v$
is the $X$-adic valuation of $p$ with respect to its main variable.
Variant: \fun{GEN}{zeropadic}{GEN p, long e} for a $p$-adic and
\fun{GEN}{zeroser}{long v, long e} for a power series zero in variable $v$.
Function: O(_^_)
Class: basic
Section: programming/internals
C-Name: ggrando
Prototype: GD1,L,
Help: O(p^e): p-adic or power series zero with precision given by e.
Description:
(gen):gen ggrando($1, 1)
(1,small):gen ggrando(gen_1, $2)
(int,small):gen zeropadic($1, $2)
(gen,small):gen ggrando($1, $2)
(var,small):gen zeroser($1, $2)
Function: Pi
Class: basic
Section: transcendental
C-Name: mppi
Prototype: p
Help: Pi=Pi(): the constant pi, with current precision.
Description:
():real:prec mppi($prec)
Doc: the constant $\pi$ ($3.14159\cdots$). Note that \kbd{Pi} is one of the few
reserved names which cannot be used for user variables.
Function: Pol
Class: basic
Section: conversions
C-Name: gtopoly
Prototype: GDn
Help: Pol(t,{v='x}): convert t (usually a vector or a power series) into a
polynomial with variable v, starting with the leading coefficient.
Description:
(gen,?var):pol gtopoly($1, $2)
Doc:
transforms the object $t$ into a polynomial with main variable $v$. If $t$
is a scalar, this gives a constant polynomial. If $t$ is a power series with
non-negative valuation or a rational function, the effect is similar to
\kbd{truncate}, i.e.~we chop off the $O(X^k)$ or compute the Euclidean
quotient of the numerator by the denominator, then change the main variable
of the result to $v$.
The main use of this function is when $t$ is a vector: it creates the
polynomial whose coefficients are given by $t$, with $t[1]$ being the leading
coefficient (which can be zero). It is much faster to evaluate
\kbd{Pol} on a vector of coefficients in this way, than the corresponding
formal expression $a_n X^n + \dots + a_0$, which is evaluated naively exactly
as written (linear versus quadratic time in $n$). \tet{Polrev} can be used if
one wants $x[1]$ to be the constant coefficient:
\bprog
? Pol([1,2,3])
%1 = x^2 + 2*x + 3
? Polrev([1,2,3])
%2 = 3*x^2 + 2*x + 1
@eprog\noindent
The reciprocal function of \kbd{Pol} (resp.~\kbd{Polrev}) is \kbd{Vec} (resp.~
\kbd{Vecrev}).
\bprog
? Vec(Pol([1,2,3]))
%1 = [1, 2, 3]
? Vecrev( Polrev([1,2,3]) )
%2 = [1, 2, 3]
@eprog\noindent
\misctitle{Warning} This is \emph{not} a substitution function. It will not
transform an object containing variables of higher priority than~$v$.
\bprog
? Pol(x + y, y)
*** at top-level: Pol(x+y,y)
*** ^----------
*** Pol: variable must have higher priority in gtopoly.
@eprog
Function: Polrev
Class: basic
Section: conversions
C-Name: gtopolyrev
Prototype: GDn
Help: Polrev(t,{v='x}): convert t (usually a vector or a power series) into a
polynomial with variable v, starting with the constant term.
Description:
(gen,?var):pol gtopolyrev($1, $2)
Doc:
transform the object $t$ into a polynomial
with main variable $v$. If $t$ is a scalar, this gives a constant polynomial.
If $t$ is a power series, the effect is identical to \kbd{truncate}, i.e.~it
chops off the $O(X^k)$.
The main use of this function is when $t$ is a vector: it creates the
polynomial whose coefficients are given by $t$, with $t[1]$ being the
constant term. \tet{Pol} can be used if one wants $t[1]$ to be the leading
coefficient:
\bprog
? Polrev([1,2,3])
%1 = 3*x^2 + 2*x + 1
? Pol([1,2,3])
%2 = x^2 + 2*x + 3
@eprog
The reciprocal function of \kbd{Pol} (resp.~\kbd{Polrev}) is \kbd{Vec} (resp.~
\kbd{Vecrev}).
Function: Qfb
Class: basic
Section: conversions
C-Name: Qfb0
Prototype: GGGDGp
Help: Qfb(a,b,c,{D=0.}): binary quadratic form a*x^2+b*x*y+c*y^2. D is
optional (0.0 by default) and initializes Shanks's distance if b^2-4*a*c>0.
Doc: creates the binary quadratic form\sidx{binary quadratic form}
$ax^2+bxy+cy^2$. If $b^2-4ac>0$, initialize \idx{Shanks}' distance
function to $D$. Negative definite forms are not implemented,
use their positive definite counterpart instead.
Variant: Also available are
\fun{GEN}{qfi}{GEN a, GEN b, GEN c} (assumes $b^2-4ac<0$) and
\fun{GEN}{qfr}{GEN a, GEN b, GEN c, GEN D} (assumes $b^2-4ac>0$).
Function: Ser
Class: basic
Section: conversions
C-Name: gtoser
Prototype: GDnDP
Help: Ser(s,{v='x},{d=seriesprecision}): convert s into a power series with
variable v and precision d, starting with the constant coefficient.
Doc: transforms the object $s$ into a power series with main variable $v$
($x$ by default) and precision (number of significant terms) equal to
$d \geq 0$ ($d = \kbd{seriesprecision}$ by default). If $s$ is a
scalar, this gives a constant power series in $v$ with precision \kbd{d}.
If $s$ is a polynomial, the polynomial is truncated to $d$ terms if needed
\bprog
? Ser(1, 'y, 5)
%1 = 1 + O(y^5)
? Ser(x^2,, 5)
%2 = x^2 + O(x^7)
? T = polcyclo(100)
%3 = x^40 - x^30 + x^20 - x^10 + 1
? Ser(T, 'x, 11)
%4 = 1 - x^10 + O(x^11)
@eprog\noindent The function is more or less equivalent with multiplication by
$1 + O(v^d)$ in theses cases, only faster.
If $s$ is a vector, on the other hand, the coefficients of the vector are
understood to be the coefficients of the power series starting from the
constant term (as in \tet{Polrev}$(x)$), and the precision $d$ is ignored:
in other words, in this case, we convert \typ{VEC} / \typ{COL} to the power
series whose significant terms are exactly given by the vector entries.
Finally, if $s$ is already a power series in $v$, we return it verbatim,
ignoring $d$ again. If $d$ significant terms are desired in the last two
cases, convert/truncate to \typ{POL} first.
\bprog
? v = [1,2,3]; Ser(v, t, 7)
%5 = 1 + 2*t + 3*t^2 + O(t^3) \\ 3 terms: 7 is ignored!
? Ser(Polrev(v,t), t, 7)
%6 = 1 + 2*t + 3*t^2 + O(t^7)
? s = 1+x+O(x^2); Ser(s, x, 7)
%7 = 1 + x + O(x^2) \\ 2 terms: 7 ignored
? Ser(truncate(s), x, 7)
%8 = 1 + x + O(x^7)
@eprog\noindent
The warning given for \kbd{Pol} also applies here: this is not a substitution
function.
Function: Set
Class: basic
Section: conversions
C-Name: gtoset
Prototype: DG
Help: Set({x=[]}): convert x into a set, i.e. a row vector with strictly
increasing coefficients. Empty set if x is omitted.
Description:
():vec cgetg(1,t_VEC)
(gen):vec gtoset($1)
Doc:
converts $x$ into a set, i.e.~into a row vector, with strictly increasing
entries with respect to the (somewhat arbitrary) universal comparison function
\tet{cmp}. Standard container types \typ{VEC}, \typ{COL}, \typ{LIST} and
\typ{VECSMALL} are converted to the set with corresponding elements. All
others are converted to a set with one element.
\bprog
? Set([1,2,4,2,1,3])
%1 = [1, 2, 3, 4]
? Set(x)
%2 = [x]
? Set(Vecsmall([1,3,2,1,3]))
%3 = [1, 2, 3]
@eprog
Function: Str
Class: basic
Section: conversions
C-Name: Str
Prototype: s*
Help: Str({x}*): concatenates its (string) argument into a single string.
Description:
(gen):genstr:copy:parens $genstr:1
(gen,gen):genstr Str(mkvec2($1, $2))
(gen,gen,gen):genstr Str(mkvec3($1, $2, $3))
(gen,gen,gen,gen):genstr Str(mkvec4($1, $2, $3, $4))
(gen,...):genstr Str(mkvecn($#, $2))
Doc:
converts its argument list into a
single character string (type \typ{STR}, the empty string if $x$ is omitted).
To recover an ordinary \kbd{GEN} from a string, apply \kbd{eval} to it. The
arguments of \kbd{Str} are evaluated in string context, see \secref{se:strings}.
\bprog
? x2 = 0; i = 2; Str(x, i)
%1 = "x2"
? eval(%)
%2 = 0
@eprog\noindent
This function is mostly useless in library mode. Use the pair
\tet{strtoGEN}/\tet{GENtostr} to convert between \kbd{GEN} and \kbd{char*}.
The latter returns a malloced string, which should be freed after usage.
%\syn{NO}
Function: Strchr
Class: basic
Section: conversions
C-Name: Strchr
Prototype: G
Help: Strchr(x): converts x to a string, translating each integer into a
character.
Doc:
converts $x$ to a string, translating each integer
into a character.
\bprog
? Strchr(97)
%1 = "a"
? Vecsmall("hello world")
%2 = Vecsmall([104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100])
? Strchr(%)
%3 = "hello world"
@eprog
Function: Strexpand
Class: basic
Section: conversions
C-Name: Strexpand
Prototype: s*
Help: Strexpand({x}*): concatenates its (string) argument into a single
string, performing tilde expansion.
Doc:
converts its argument list into a
single character string (type \typ{STR}, the empty string if $x$ is omitted).
Then perform \idx{environment expansion}, see \secref{se:envir}.
This feature can be used to read \idx{environment variable} values.
\bprog
? Strexpand("$HOME/doc")
%1 = "/home/pari/doc"
@eprog
The individual arguments are read in string context, see \secref{se:strings}.
%\syn{NO}
Function: Strprintf
Class: basic
Section: programming/specific
C-Name: Strprintf
Prototype: ss*
Help: Strprintf(fmt,{x}*): returns a string built from the remaining
arguments according to the format fmt.
Doc: returns a string built from the remaining arguments according to the
format fmt. The format consists of ordinary characters (not \%), printed
unchanged, and conversions specifications. See \kbd{printf}.
%\syn{NO}
Function: Strtex
Class: basic
Section: conversions
C-Name: Strtex
Prototype: s*
Help: Strtex({x}*): translates its (string) arguments to TeX format and
returns the resulting string.
Doc:
translates its arguments to TeX
format, and concatenates the results into a single character string (type
\typ{STR}, the empty string if $x$ is omitted).
The individual arguments are read in string context, see \secref{se:strings}.
%\syn{NO}
Function: Vec
Class: basic
Section: conversions
C-Name: gtovec0
Prototype: GD0,L,
Help: Vec(x, {n}): transforms the object x into a vector of dimension n.
Description:
(gen):vec gtovec($1)
Doc:
transforms the object $x$ into a row vector. The dimension of the
resulting vector can be optionally specified via the extra parameter $n$.
If $n$ is omitted or $0$, the dimension depends on the type of $x$; the
vector has a single component, except when $x$ is
\item a vector or a quadratic form: returns the initial object considered as a
row vector,
\item a polynomial or a power series: returns a vector consisting of the coefficients.
In the case of a polynomial, the coefficients of the vector start with the leading
coefficient of the polynomial, while for power series only the significant coefficients
are taken into account, but this time by increasing order of degree.
\kbd{Vec} is the reciprocal function of \kbd{Pol} for a polynomial and of
\kbd{Ser} for a power series,
\item a matrix: returns the vector of columns comprising the matrix,
\item a character string: returns the vector of individual characters,
\item a map: returns the vector of the domain of the map,
\item an error context (\typ{ERROR}): returns the error components, see
\tet{iferr}.
In the last four cases (matrix, character string, map, error), $n$ is
meaningless and must be omitted or an error is raised. Otherwise, if $n$ is
given, $0$ entries are appended at the end of the vector if $n > 0$, and
prepended at the beginning if $n < 0$. The dimension of the resulting vector
is $|n|$. Variant: \fun{GEN}{gtovec}{GEN x} is also available.
Function: Vecrev
Class: basic
Section: conversions
C-Name: gtovecrev0
Prototype: GD0,L,
Help: Vecrev(x, {n}): transforms the object x into a vector of dimension n
in reverse order with respect to Vec(x, {n}). Empty vector if x is omitted.
Description:
(gen):vec gtovecrev($1)
Doc:
as $\kbd{Vec}(x, -n)$, then reverse the result. In particular,
\kbd{Vecrev} is the reciprocal function of \kbd{Polrev}: the
coefficients of the vector start with the constant coefficient of the
polynomial and the others follow by increasing degree.
Variant: \fun{GEN}{gtovecrev}{GEN x} is also available.
Function: Vecsmall
Class: basic
Section: conversions
C-Name: gtovecsmall0
Prototype: GD0,L,
Help: Vecsmall(x, {n}): transforms the object x into a VECSMALL of dimension n.
Description:
(gen):vecsmall gtovecsmall($1)
Doc:
transforms the object $x$ into a row vector of type \typ{VECSMALL}. The
dimension of the resulting vector can be optionally specified via the extra
parameter $n$.
This acts as \kbd{Vec}$(x,n)$, but only on a limited set of objects:
the result must be representable as a vector of small integers.
If $x$ is a character string, a vector of individual characters in ASCII
encoding is returned (\tet{Strchr} yields back the character string).
Variant: \fun{GEN}{gtovecsmall}{GEN x} is also available.
Function: [_.._]
Class: basic
Section: programming/internals
C-Name: vecrange
Prototype: GG
Help: [a..b] = [a,a+1,...,b]
Description:
(gen,gen):vec vecrange($1, $2)
(small,small):vec vecrangess($1, $2)
Function: [_|_<-_,_;_]
Class: basic
Section: programming/internals
C-Name: vecexpr1
Prototype: mGVDEDE
Help: [a(x)|x<-b,c(x);...]
Wrapper: (,,G,bG)
Description:
(gen,,closure):gen veccatapply(${3 cookie}, ${3 wrapper}, $1)
(gen,,closure,closure):gen veccatselapply(${4 cookie}, ${4 wrapper}, ${3 cookie}, ${3 wrapper}, $1)
Function: [_|_<-_,_]
Class: basic
Section: programming/internals
C-Name: vecexpr0
Prototype: GVDEDE
Help: [a(x)|x<-b,c(x)] = apply(a,select(c,b))
Wrapper: (,,G,bG)
Description:
(gen,,closure):gen vecapply(${3 cookie}, ${3 wrapper}, $1)
(gen,,,closure):gen vecselect(${4 cookie}, ${4 wrapper}, $1)
(gen,,closure,closure):gen vecselapply(${4 cookie}, ${4 wrapper}, ${3 cookie}, ${3 wrapper}, $1)
Function: _!
Class: basic
Section: symbolic_operators
C-Name: mpfact
Prototype: L
Help: n!: factorial of n.
Description:
(small):int mpfact($1)
Function: _!=_
Class: basic
Section: symbolic_operators
C-Name: gne
Prototype: GG
Help: _!=_
Description:
(small, small):bool:parens $(1) != $(2)
(lg, lg):bool:parens $(1) != $(2)
(small, int):bool:parens cmpsi($1, $2) != 0
(int, small):bool:parens cmpis($1, $2) != 0
(int, 1):negbool equali1($1)
(int, -1):negbool equalim1($1)
(int, int):negbool equalii($1, $2)
(real,real):bool cmprr($1, $2) != 0
(mp, mp):bool:parens mpcmp($1, $2) != 0
(errtyp, errtyp):bool:parens $(1) != $(2)
(errtyp, #str):bool:parens $(1) != $(errtyp:2)
(#str, errtyp):bool:parens $(errtyp:1) != $(2)
(typ, typ):bool:parens $(1) != $(2)
(typ, #str):bool:parens $(1) != $(typ:2)
(#str, typ):bool:parens $(typ:1) != $(2)
(str, str):bool strcmp($1, $2)
(small, gen):negbool gequalsg($1, $2)
(gen, small):negbool gequalgs($1, $2)
(gen, gen):negbool gequal($1, $2)
Function: _%=_
Class: basic
Section: symbolic_operators
C-Name: gmode
Prototype: &G
Help: x%=y: shortcut for x=x%y.
Description:
(*small, small):small:parens $1 = smodss($1, $2)
(*int, small):int:parens $1 = modis($1, $2)
(*int, int):int:parens $1 = modii($1, $2)
(*pol, gen):gen:parens $1 = gmod($1, $2)
(*gen, small):gen:parens $1 = gmodgs($1, $2)
(*gen, gen):gen:parens $1 = gmod($1, $2)
Function: _%_
Class: basic
Section: symbolic_operators
C-Name: gmod
Prototype: GG
Help: x%y: Euclidean remainder of x and y.
Description:
(small, small):small smodss($1, $2)
(small, int):int modsi($1, $2)
(int, small):small smodis($1, $2)
(int, int):int modii($1, $2)
(gen, small):gen gmodgs($1, $2)
(small, gen):gen gmodsg($1, $2)
(gen, gen):gen gmod($1, $2)
(FpX,FpX):FpX FpX_rem($1, $2, p)
(FqX,FqX):FqX FqX_rem($1, $2, T, p)
Function: _&&_
Class: basic
Section: symbolic_operators
C-Name: andpari
Prototype: GE
Help: _&&_
Description:
(bool, bool):bool:parens $(1) && $(2)
Function: _'
Class: basic
Section: symbolic_operators
C-Name: deriv
Prototype: GDn
Help: x': derivative of x with respect to the main variable.
Description:
(gen):gen deriv($1,-1)
(FpX):FpX FpX_deriv($1, p)
(FqX):FqX FqX_deriv($1, T, p)
Function: _(_)
Class: basic
Section: symbolic_operators
Help: f(a,b,...): evaluates the function f on a,b,...
Description:
(gen):gen closure_callgenall($1, 0)
(gen,gen):gen closure_callgen1($1, $2)
(gen,gen,gen):gen closure_callgen2($1, $2, $3)
(gen,gen,...):gen closure_callgenall($1, ${nbarg 1 sub}, $3)
Function: _*=_
Class: basic
Section: symbolic_operators
C-Name: gmule
Prototype: &G
Help: x*=y: shortcut for x=x*y.
Description:
(*small, small):small:parens $1 *= $(2)
(*int, small):int:parens $1 = mulis($1, $2)
(*int, int):int:parens $1 = mulii($1, $2)
(*real, small):real:parens $1 = mulrs($1, $2)
(*real, int):real:parens $1 = mulri($1, $2)
(*real, real):real:parens $1 = mulrr($1, $2)
(*mp, mp):mp:parens $1 = mpmul($1, $2)
(*pol, small):gen:parens $1 = gmulgs($1, $2)
(*pol, gen):gen:parens $1 = gmul($1, $2)
(*vec, gen):gen:parens $1 = gmul($1, $2)
(*gen, small):gen:parens $1 = gmulgs($1, $2)
(*gen, gen):gen:parens $1 = gmul($1, $2)
Function: _*_
Class: basic
Section: symbolic_operators
C-Name: gmul
Prototype: GG
Help: x*y: product of x and y.
Description:
(small, small):small:parens $(1)*$(2)
(int, small):int mulis($1, $2)
(small, int):int mulsi($1, $2)
(int, int):int mulii($1, $2)
(0, mp):small ($2, 0)/*for side effect*/
(#small, real):real mulsr($1, $2)
(small, real):mp mulsr($1, $2)
(real, small):mp mulrs($1, $2)
(real, real):real mulrr($1, $2)
(mp, mp):mp mpmul($1, $2)
(gen, small):gen gmulgs($1, $2)
(small, gen):gen gmulsg($1, $2)
(vecsmall, vecsmall):vecsmall perm_mul($1, $2)
(gen, gen):gen gmul($1, $2)
(usmall,Fp):Fp Fp_mulu($2, $1, p)
(small,Fp):Fp Fp_muls($2, $1, p)
(Fp, usmall):Fp Fp_mulu($1, $2, p)
(Fp, small):Fp Fp_muls($1, $2, p)
(usmall,FpX):FpX FpX_mulu($2, $1, p)
(FpX, usmall):FpX FpX_mulu($1, $2, p)
(Fp, FpX):FpX FpX_Fp_mul($2, $1, p)
(FpX, Fp):FpX FpX_Fp_mul($1, $2, p)
(FpX, FpX):FpX FpX_mul($1, $2, p)
(usmall,Fq):Fq Fq_mulu($2, $1, T, p)
(Fq, usmall):Fq Fq_mulu($1, $2, T, p)
(Fq,Fp):Fq Fq_Fp_mul($1, $2, T, p)
(Fp,Fq):Fq Fq_Fp_mul($2, $1, T, p)
(usmall,FqX):FqX FqX_mulu($2, $1, T, p)
(FqX, usmall):FqX FqX_mulu($1, $2, T, p)
(FqX,Fp):FqX FqX_Fp_mul($1, $2, T, p)
(Fp,FqX):FqX FqX_Fp_mul($2, $1, T, p)
(Fq, FqX):FqX FqX_Fq_mul($2, $1, T, p)
(FqX, Fq):FqX FqX_Fq_mul($1, $2, T, p)
(FqX, FqX):FqX FqX_mul($1, $2, T, p)
Function: _++
Class: basic
Section: symbolic_operators
C-Name: gadd1e
Prototype: &
Help: x++
Description:
(*bptr):bptr ++$1
(*small):small ++$1
(*lg):lg ++$1
(*int):int:parens $1 = addis($1, 1)
(*real):real:parens $1 = addrs($1, 1)
(*mp):mp:parens $1 = mpadd($1, gen_1)
(*pol):pol:parens $1 = gaddgs($1, 1)
(*gen):gen:parens $1 = gaddgs($1, 1)
Function: _+=_
Class: basic
Section: symbolic_operators
C-Name: gadde
Prototype: &G
Help: x+=y: shortcut for x=x+y.
Description:
(*small, small):small:parens $1 += $(2)
(*lg, small):lg:parens $1 += $(2)
(*int, small):int:parens $1 = addis($1, $2)
(*int, int):int:parens $1 = addii($1, $2)
(*real, small):real:parens $1 = addrs($1, $2)
(*real, int):real:parens $1 = addir($2, $1)
(*real, real):real:parens $1 = addrr($1, $2)
(*mp, mp):mp:parens $1 = mpadd($1, $2)
(*pol, small):gen:parens $1 = gaddgs($1, $2)
(*pol, gen):gen:parens $1 = gadd($1, $2)
(*vec, gen):gen:parens $1 = gadd($1, $2)
(*gen, small):gen:parens $1 = gaddgs($1, $2)
(*gen, gen):gen:parens $1 = gadd($1, $2)
Function: _+_
Class: basic
Section: symbolic_operators
C-Name: gadd
Prototype: GG
Help: x+y: sum of x and y.
Description:
(lg, 1):small:parens $(1)
(small, small):small:parens $(1) + $(2)
(lg, small):lg:parens $(1) + $(2)
(small, lg):lg:parens $(1) + $(2)
(int, small):int addis($1, $2)
(small, int):int addsi($1, $2)
(int, int):int addii($1, $2)
(real, small):real addrs($1, $2)
(small, real):real addsr($1, $2)
(real, real):real addrr($1, $2)
(mp, real):real mpadd($1, $2)
(real, mp):real mpadd($1, $2)
(mp, mp):mp mpadd($1, $2)
(gen, small):gen gaddgs($1, $2)
(small, gen):gen gaddsg($1, $2)
(gen, gen):gen gadd($1, $2)
(Fp, Fp):Fp Fp_add($1, $2, p)
(FpX, Fp):FpX FpX_Fp_add($1, $2, p)
(Fp, FpX):FpX FpX_Fp_add($2, $1, p)
(FpX, FpX):FpX FpX_add($1, $2, p)
(Fq, Fq):Fq Fq_add($1, $2, T, p)
(FqX, Fq):FqX FqX_Fq_add($1, $2, T, p)
(Fq, FqX):FqX FqX_Fq_add($2, $1, T, p)
(FqX, FqX):FqX FqX_add($1, $2, T, p)
Function: _--
Class: basic
Section: symbolic_operators
C-Name: gsub1e
Prototype: &
Help: x--
Description:
(*bptr):bptr --$1
(*small):small --$1
(*lg):lg --$1
(*int):int:parens $1 = subis($1, 1)
(*real):real:parens $1 = subrs($1, 1)
(*mp):mp:parens $1 = mpsub($1, gen_1)
(*pol):pol:parens $1 = gsubgs($1, 1)
(*gen):gen:parens $1 = gsubgs($1, 1)
Function: _-=_
Class: basic
Section: symbolic_operators
C-Name: gsube
Prototype: &G
Help: x-=y: shortcut for x=x-y.
Description:
(*small, small):small:parens $1 -= $(2)
(*lg, small):lg:parens $1 -= $(2)
(*int, small):int:parens $1 = subis($1, $2)
(*int, int):int:parens $1 = subii($1, $2)
(*real, small):real:parens $1 = subrs($1, $2)
(*real, int):real:parens $1 = subri($1, $2)
(*real, real):real:parens $1 = subrr($1, $2)
(*mp, mp):mp:parens $1 = mpsub($1, $2)
(*pol, small):gen:parens $1 = gsubgs($1, $2)
(*pol, gen):gen:parens $1 = gsub($1, $2)
(*vec, gen):gen:parens $1 = gsub($1, $2)
(*gen, small):gen:parens $1 = gsubgs($1, $2)
(*gen, gen):gen:parens $1 = gsub($1, $2)
Function: _-_
Class: basic
Section: symbolic_operators
C-Name: gsub
Prototype: GG
Help: x-y: difference of x and y.
Description:
(small, small):small:parens $(1) - $(2)
(lg, small):lg:parens $(1) - $(2)
(int, small):int subis($1, $2)
(small, int):int subsi($1, $2)
(int, int):int subii($1, $2)
(real, small):real subrs($1, $2)
(small, real):real subsr($1, $2)
(real, real):real subrr($1, $2)
(mp, real):real mpsub($1, $2)
(real, mp):real mpsub($1, $2)
(mp, mp):mp mpsub($1, $2)
(gen, small):gen gsubgs($1, $2)
(small, gen):gen gsubsg($1, $2)
(gen, gen):gen gsub($1, $2)
(Fp, Fp):Fp Fp_sub($1, $2, p)
(Fp, FpX):FpX Fp_FpX_sub($1, $2, p)
(FpX, Fp):FpX FpX_Fp_sub($1, $2, p)
(FpX, FpX):FpX FpX_sub($1, $2, p)
(Fq, Fq):Fq Fq_sub($1, $2, T, p)
(FqX, FqX):FqX FqX_sub($1, $2, T, p)
Function: _.a1
Class: basic
Section: member_functions
C-Name: member_a1
Prototype: mG
Help: _.a1
Description:
(ell):gen:copy ell_get_a1($1)
Function: _.a2
Class: basic
Section: member_functions
C-Name: member_a2
Prototype: mG
Help: _.a2
Description:
(ell):gen:copy ell_get_a2($1)
Function: _.a3
Class: basic
Section: member_functions
C-Name: member_a3
Prototype: mG
Help: _.a3
Description:
(ell):gen:copy ell_get_a3($1)
Function: _.a4
Class: basic
Section: member_functions
C-Name: member_a4
Prototype: mG
Help: _.a4
Description:
(ell):gen:copy ell_get_a4($1)
Function: _.a6
Class: basic
Section: member_functions
C-Name: member_a6
Prototype: mG
Help: _.a6
Description:
(ell):gen:copy ell_get_a6($1)
Function: _.area
Class: basic
Section: member_functions
C-Name: member_area
Prototype: mG
Help: _.area
Function: _.b2
Class: basic
Section: member_functions
C-Name: member_b2
Prototype: mG
Help: _.b2
Description:
(ell):gen:copy ell_get_b2($1)
Function: _.b4
Class: basic
Section: member_functions
C-Name: member_b4
Prototype: mG
Help: _.b4
Description:
(ell):gen:copy ell_get_b4($1)
Function: _.b6
Class: basic
Section: member_functions
C-Name: member_b6
Prototype: mG
Help: _.b6
Description:
(ell):gen:copy ell_get_b6($1)
Function: _.b8
Class: basic
Section: member_functions
C-Name: member_b8
Prototype: mG
Help: _.b8
Description:
(ell):gen:copy ell_get_b8($1)
Function: _.bid
Class: basic
Section: member_functions
C-Name: member_bid
Prototype: mG
Help: _.bid
Description:
(bnr):gen:copy bnr_get_bid($1)
(gen):gen:copy member_bid($1)
Function: _.bnf
Class: basic
Section: member_functions
C-Name: member_bnf
Prototype: mG
Help: _.bnf
Description:
(bnf):bnf:parens $1
(bnr):bnf:copy:parens $bnf:1
(gen):bnf:copy member_bnf($1)
Function: _.c4
Class: basic
Section: member_functions
C-Name: member_c4
Prototype: mG
Help: _.c4
Description:
(ell):gen:copy ell_get_c4($1)
Function: _.c6
Class: basic
Section: member_functions
C-Name: member_c6
Prototype: mG
Help: _.c6
Description:
(ell):gen:copy ell_get_c6($1)
Function: _.clgp
Class: basic
Section: member_functions
C-Name: member_clgp
Prototype: mG
Help: _.clgp
Description:
(bnf):clgp:copy:parens $clgp:1
(bnr):clgp:copy:parens $clgp:1
(clgp):clgp:parens $1
(gen):clgp:copy member_clgp($1)
Function: _.codiff
Class: basic
Section: member_functions
C-Name: member_codiff
Prototype: mG
Help: _.codiff
Function: _.cyc
Class: basic
Section: member_functions
C-Name: member_cyc
Prototype: mG
Help: _.cyc
Description:
(bnr):vec:copy bnr_get_cyc($1)
(bnf):vec:copy bnf_get_cyc($1)
(clgp):vec:copy gel($1, 2)
(gen):vec:copy member_cyc($1)
Function: _.diff
Class: basic
Section: member_functions
C-Name: member_diff
Prototype: mG
Help: _.diff
Description:
(nf):gen:copy nf_get_diff($1)
(gen):gen:copy member_diff($1)
Function: _.disc
Class: basic
Section: member_functions
C-Name: member_disc
Prototype: mG
Help: _.disc
Description:
(nf):int:copy nf_get_disc($1)
(ell):gen:copy ell_get_disc($1)
(gen):gen:copy member_disc($1)
Function: _.e
Class: basic
Section: member_functions
C-Name: member_e
Prototype: mG
Help: _.e
Description:
(prid):small pr_get_e($1)
Function: _.eta
Class: basic
Section: member_functions
C-Name: member_eta
Prototype: mG
Help: _.eta
Function: _.f
Class: basic
Section: member_functions
C-Name: member_f
Prototype: mG
Help: _.f
Description:
(prid):small pr_get_f($1)
Function: _.fu
Class: basic
Section: member_functions
C-Name: member_fu
Prototype: G
Help: _.fu
Description:
(bnr):void $"ray units not implemented"
(bnf):gen:copy bnf_get_fu($1)
(gen):gen member_fu($1)
Function: _.futu
Class: basic
Section: member_functions
C-Name: member_futu
Prototype: mG
Help: _.futu
Function: _.gen
Class: basic
Section: member_functions
C-Name: member_gen
Prototype: mG
Help: _.gen
Description:
(bnr):vec:copy bnr_get_gen($1)
(bnf):vec:copy bnf_get_gen($1)
(gal):vec:copy gal_get_gen($1)
(clgp):vec:copy gel($1, 3)
(prid):gen:copy pr_get_gen($1)
(gen):gen:copy member_gen($1)
Function: _.group
Class: basic
Section: member_functions
C-Name: member_group
Prototype: mG
Help: _.group
Description:
(gal):vec:copy gal_get_group($1)
(gen):vec:copy member_group($1)
Function: _.index
Class: basic
Section: member_functions
C-Name: member_index
Prototype: mG
Help: _.index
Description:
(nf):int:copy nf_get_index($1)
(gen):int:copy member_index($1)
Function: _.j
Class: basic
Section: member_functions
C-Name: member_j
Prototype: mG
Help: _.j
Description:
(ell):gen:copy ell_get_j($1)
Function: _.mod
Class: basic
Section: member_functions
C-Name: member_mod
Prototype: mG
Help: _.mod
Function: _.nf
Class: basic
Section: member_functions
C-Name: member_nf
Prototype: mG
Help: _.nf
Description:
(nf):nf:parens $1
(gen):nf:copy member_nf($1)
Function: _.no
Class: basic
Section: member_functions
C-Name: member_no
Prototype: mG
Help: _.no
Description:
(bnr):int:copy bnr_get_no($1)
(bnf):int:copy bnf_get_no($1)
(clgp):int:copy gel($1, 1)
(gen):int:copy member_no($1)
Function: _.omega
Class: basic
Section: member_functions
C-Name: member_omega
Prototype: mG
Help: _.omega
Function: _.orders
Class: basic
Section: member_functions
C-Name: member_orders
Prototype: mG
Help: _.orders
Description:
(gal):vecsmall:copy gal_get_orders($1)
Function: _.p
Class: basic
Section: member_functions
C-Name: member_p
Prototype: mG
Help: _.p
Description:
(gal):int:copy gal_get_p($1)
(prid):int:copy pr_get_p($1)
(gen):int:copy member_p($1)
Function: _.pol
Class: basic
Section: member_functions
C-Name: member_pol
Prototype: mG
Help: _.pol
Description:
(gal):gen:copy gal_get_pol($1)
(nf):gen:copy nf_get_pol($1)
(gen):gen:copy member_pol($1)
Function: _.polabs
Class: basic
Section: member_functions
C-Name: member_polabs
Prototype: mG
Help: _.polabs
Function: _.r1
Class: basic
Section: member_functions
C-Name: member_r1
Prototype: mG
Help: _.r1
Description:
(nf):small nf_get_r1($1)
(gen):int:copy member_r1($1)
Function: _.r2
Class: basic
Section: member_functions
C-Name: member_r2
Prototype: mG
Help: _.r2
Description:
(nf):small nf_get_r2($1)
(gen):int:copy member_r2($1)
Function: _.reg
Class: basic
Section: member_functions
C-Name: member_reg
Prototype: mG
Help: _.reg
Description:
(bnr):real $"ray regulator not implemented"
(bnf):real:copy bnf_get_reg($1)
(gen):real:copy member_reg($1)
Function: _.roots
Class: basic
Section: member_functions
C-Name: member_roots
Prototype: mG
Help: _.roots
Description:
(gal):vec:copy gal_get_roots($1)
(nf):vec:copy nf_get_roots($1)
(gen):vec:copy member_roots($1)
Function: _.sign
Class: basic
Section: member_functions
C-Name: member_sign
Prototype: mG
Help: _.sign
Description:
(nf):vec:copy gel($1, 2)
(gen):vec:copy member_sign($1)
Function: _.t2
Class: basic
Section: member_functions
C-Name: member_t2
Prototype: G
Help: _.t2
Description:
(gen):vec member_t2($1)
Function: _.tate
Class: basic
Section: member_functions
C-Name: member_tate
Prototype: mG
Help: _.tate
Function: _.tu
Class: basic
Section: member_functions
C-Name: member_tu
Prototype: G
Help: _.tu
Description:
(gen):gen:copy member_tu($1)
Function: _.tufu
Class: basic
Section: member_functions
C-Name: member_tufu
Prototype: mG
Help: _.tufu
Function: _.zk
Class: basic
Section: member_functions
C-Name: member_zk
Prototype: mG
Help: _.zk
Description:
(nf):vec:copy nf_get_zk($1)
(gen):vec:copy member_zk($1)
Function: _.zkst
Class: basic
Section: member_functions
C-Name: member_zkst
Prototype: mG
Help: _.zkst
Description:
(bnr):gen:copy bnr_get_bid($1)
Function: _/=_
Class: basic
Section: symbolic_operators
C-Name: gdive
Prototype: &G
Help: x/=y: shortcut for x=x/y.
Description:
(*small, gen):void $"cannot divide small: use \= instead."
(*int, gen):void $"cannot divide int: use \= instead."
(*real, real):real:parens $1 = divrr($1, $2)
(*real, small):real:parens $1 = divrs($1, $2)
(*real, mp):real:parens $1 = mpdiv($1, $2)
(*mp, real):mp:parens $1 = mpdiv($1, $2)
(*pol, gen):gen:parens $1 = gdiv($1, $2)
(*vec, gen):gen:parens $1 = gdiv($1, $2)
(*gen, small):gen:parens $1 = gdivgs($1, $2)
(*gen, gen):gen:parens $1 = gdiv($1, $2)
Function: _/_
Class: basic
Section: symbolic_operators
C-Name: gdiv
Prototype: GG
Help: x/y: quotient of x and y.
Description:
(0, mp):small ($2, 0)/*for side effect*/
(1, real):real invr($2)
(#small, real):real divsr($1, $2)
(small, real):mp divsr($1, $2)
(real, small):real divrs($1, $2)
(real, real):real divrr($1, $2)
(real, mp):real mpdiv($1, $2)
(mp, real):mp mpdiv($1, $2)
(1, gen):gen ginv($2)
(gen, small):gen gdivgs($1, $2)
(small, gen):gen gdivsg($1, $2)
(gen, gen):gen gdiv($1, $2)
(Fp, 2):Fp Fp_halve($1, p)
(Fp, Fp):Fp Fp_div($1, $2, p)
(Fq, 2):Fq Fq_halve($1, T, p)
(Fq, Fq):Fq Fq_div($1, $2, T, p)
Function: _<<=_
Class: basic
Section: symbolic_operators
C-Name: gshiftle
Prototype: &L
Help: x<<=y: shortcut for x=x<<y.
Description:
(*small, small):small:parens $1 <<= $(2)
(*int, small):int:parens $1 = shifti($1, $2)
(*mp, small):mp:parens $1 = mpshift($1, $2)
(*gen, small):mp:parens $1 = gshift($1, $2)
Function: _<<_
Class: basic
Section: symbolic_operators
C-Name: gshift
Prototype: GL
Help: x<<y
Description:
(int, small):int shifti($1, $2)
(mp, small):mp mpshift($1, $2)
(gen, small):mp gshift($1, $2)
Function: _<=_
Class: basic
Section: symbolic_operators
C-Name: gle
Prototype: GG
Help: x<=y: return 1 if x is less or equal to y, 0 otherwise.
Description:
(small, small):bool:parens $(1) <= $(2)
(small, lg):bool:parens $(1) < $(2)
(lg, lg):bool:parens $(1) <= $(2)
(small, int):bool:parens cmpsi($1, $2) <= 0
(int, lg):bool:parens cmpis($1, $2) < 0
(int, small):bool:parens cmpis($1, $2) <= 0
(int, int):bool:parens cmpii($1, $2) <= 0
(mp, mp):bool:parens mpcmp($1, $2) <= 0
(str, str):bool:parens strcmp($1, $2) <= 0
(small, gen):bool:parens gcmpsg($1, $2) <= 0
(gen, small):bool:parens gcmpgs($1, $2) <= 0
(gen, gen):bool:parens gcmp($1, $2) <= 0
Function: _<_
Class: basic
Section: symbolic_operators
C-Name: glt
Prototype: GG
Help: x<y: return 1 if x is strictly less than y, 0 otherwise.
Description:
(small, small):bool:parens $(1) < $(2)
(lg, lg):bool:parens $(1) < $(2)
(lg, small):bool:parens $(1) <= $(2)
(small, int):bool:parens cmpsi($1, $2) < 0
(int, small):bool:parens cmpis($1, $2) < 0
(int, int):bool:parens cmpii($1, $2) < 0
(mp, mp):bool:parens mpcmp($1, $2) < 0
(str, str):bool:parens strcmp($1, $2) < 0
(small, gen):bool:parens gcmpsg($1, $2) < 0
(gen, small):bool:parens gcmpgs($1, $2) < 0
(gen, gen):bool:parens gcmp($1, $2) < 0
Function: _===_
Class: basic
Section: symbolic_operators
C-Name: gidentical
Prototype: iGG
Help: a === b : true if a and b are identical
Function: _==_
Class: basic
Section: symbolic_operators
C-Name: geq
Prototype: GG
Help: _==_
Description:
(small, small):bool:parens $(1) == $(2)
(lg, lg):bool:parens $(1) == $(2)
(small, int):bool:parens cmpsi($1, $2) == 0
(mp, 0):bool !signe($1)
(int, 1):bool equali1($1)
(int, -1):bool equalim1($1)
(int, small):bool:parens cmpis($1, $2) == 0
(int, int):bool equalii($1, $2)
(gen, 0):bool gequal0($1)
(gen, 1):bool gequal1($1)
(gen, -1):bool gequalm1($1)
(real,real):bool cmprr($1, $2) == 0
(mp, mp):bool:parens mpcmp($1, $2) == 0
(errtyp, errtyp):bool:parens $(1) == $(2)
(errtyp, #str):bool:parens $(1) == $(errtyp:2)
(#str, errtyp):bool:parens $(errtyp:1) == $(2)
(typ, typ):bool:parens $(1) == $(2)
(typ, #str):bool:parens $(1) == $(typ:2)
(#str, typ):bool:parens $(typ:1) == $(2)
(str, str):negbool strcmp($1, $2)
(small, gen):bool gequalsg($1, $2)
(gen, small):bool gequalgs($1, $2)
(gen, gen):bool gequal($1, $2)
Function: _>=_
Class: basic
Section: symbolic_operators
C-Name: gge
Prototype: GG
Help: x>=y: return 1 if x is greater or equal to y, 0 otherwise.
Description:
(small, small):bool:parens $(1) >= $(2)
(lg, lg):bool:parens $(1) >= $(2)
(lg, small):bool:parens $(1) > $(2)
(small, int):bool:parens cmpsi($1, $2) >= 0
(int, small):bool:parens cmpis($1, $2) >= 0
(int, int):bool:parens cmpii($1, $2) >= 0
(mp, mp):bool:parens mpcmp($1, $2) >= 0
(str, str):bool:parens strcmp($1, $2) >= 0
(small, gen):bool:parens gcmpsg($1, $2) >= 0
(gen, small):bool:parens gcmpgs($1, $2) >= 0
(gen, gen):bool:parens gcmp($1, $2) >= 0
Function: _>>=_
Class: basic
Section: symbolic_operators
C-Name: gshiftre
Prototype: &L
Help: x>>=y: shortcut for x=x>>y.
Description:
(*small, small):small:parens $1 >>= $(2)
(*int, small):int:parens $1 = shifti($1, -$(2))
(*mp, small):mp:parens $1 = mpshift($1, -$(2))
(*gen, small):mp:parens $1 = gshift($1, -$(2))
Function: _>>_
Class: basic
Section: symbolic_operators
C-Name: gshift_right
Prototype: GL
Help: x>>y
Description:
(small, small):small:parens $(1)>>$(2)
(int, small):int shifti($1, -$(2))
(mp, small):mp mpshift($1, -$(2))
(gen, small):mp gshift($1, -$(2))
Function: _>_
Class: basic
Section: symbolic_operators
C-Name: ggt
Prototype: GG
Help: x>y: return 1 if x is strictly greater than y, 0 otherwise.
Description:
(small, small):bool:parens $(1) > $(2)
(lg, lg):bool:parens $(1) > $(2)
(small, lg):bool:parens $(1) >= $(2)
(small, int):bool:parens cmpsi($1, $2) > 0
(int, small):bool:parens cmpis($1, $2) > 0
(int, int):bool:parens cmpii($1, $2) > 0
(mp, mp):bool:parens mpcmp($1, $2) > 0
(str, str):bool:parens strcmp($1, $2) > 0
(small, gen):bool:parens gcmpsg($1, $2) > 0
(gen, small):bool:parens gcmpgs($1, $2) > 0
(gen, gen):bool:parens gcmp($1, $2) > 0
Function: _ZX_resultant_worker
Class: basic
Section: programming/internals
C-Name: ZX_resultant_worker
Prototype: GGGG
Help: worker for ZX_resultant
Function: _[_,]
Class: basic
Section: symbolic_operators
Help: x[y,]: y-th row of x.
Description:
(mp,small):gen $"Scalar has no rows"
(vec,small):vec rowcopy($1, $2)
(gen,small):vec rowcopy($1, $2)
Function: _[_,_]
Class: basic
Section: symbolic_operators
Help: x[i{,j}]: i coefficient of a vector, i,j coefficient of a matrix
Description:
(mp,small):gen $"Scalar has no components"
(mp,small,small):gen $"Scalar has no components"
(vecsmall,small):small $(1)[$2]
(vecsmall,small,small):gen $"Vecsmall are single-dimensional"
(list,small):gen:copy gel(list_data($1), $2)
(vec,small):gen:copy gel($1, $2)
(vec,small,small):gen:copy gcoeff($1, $2, $3)
(gen,small):gen:copy gel($1, $2)
(gen,small,small):gen:copy gcoeff($1, $2, $3)
Function: _[_.._,_.._]
Class: basic
Section: symbolic_operators
C-Name: matslice0
Prototype: GD0,L,D0,L,D0,L,D0,L,
Help: x[a..b,c..d] = [x[a,c], x[a+1,c], ...,x[b,c];
x[a,c+1],x[a+1,c+1],...,x[b,c+1];
... ... ...
x[a,d], x[a+1,d] ,...,x[b,d]]
Function: _[_.._]
Class: basic
Section: symbolic_operators
C-Name: vecslice0
Prototype: GD0,L,L
Help: x[a..b] = [x[a],x[a+1],...,x[b]]
Function: _\/=_
Class: basic
Section: symbolic_operators
C-Name: gdivrounde
Prototype: &G
Help: x\/=y: shortcut for x=x\/y.
Description:
(*int, int):int:parens $1 = gdivround($1, $2)
(*pol, gen):gen:parens $1 = gdivround($1, $2)
(*gen, gen):gen:parens $1 = gdivround($1, $2)
Function: _\/_
Class: basic
Section: symbolic_operators
C-Name: gdivround
Prototype: GG
Help: x\/y: rounded Euclidean quotient of x and y.
Description:
(int, int):int gdivround($1, $2)
(gen, gen):gen gdivround($1, $2)
Function: _\=_
Class: basic
Section: symbolic_operators
C-Name: gdivente
Prototype: &G
Help: x\=y: shortcut for x=x\y.
Description:
(*small, small):small:parens $1 /= $(2)
(*int, int):int:parens $1 = gdivent($1, $2)
(*pol, gen):gen:parens $1 = gdivent($1, $2)
(*gen, gen):gen:parens $1 = gdivent($1, $2)
Function: _\_
Class: basic
Section: symbolic_operators
C-Name: gdivent
Prototype: GG
Help: x\y: Euclidean quotient of x and y.
Description:
(small, small):small:parens $(1)/$(2)
(int, small):int truedivis($1, $2)
(small, int):int gdiventsg($1, $2)
(int, int):int truedivii($1, $2)
(gen, small):gen gdiventgs($1, $2)
(small, gen):gen gdiventsg($1, $2)
(gen, gen):gen gdivent($1, $2)
Function: _^_
Class: basic
Section: symbolic_operators
C-Name: gpow
Prototype: GGp
Help: x^y: compute x to the power y.
Description:
(int, 2):int sqri($1)
(int, 3):int powiu($1, 3)
(int, 4):int powiu($1, 4)
(int, 5):int powiu($1, 5)
(real, -1):real invr($1)
(mp, -1):mp ginv($1)
(gen, -1):gen ginv($1)
(real, 2):real sqrr($1)
(mp, 2):mp mpsqr($1)
(gen, 2):gen gsqr($1)
(int, small):gen powis($1, $2)
(real, small):real gpowgs($1, $2)
(gen, small):gen gpowgs($1, $2)
(real, int):real powgi($1, $2)
(gen, int):gen powgi($1, $2)
(gen, gen):gen:prec gpow($1, $2, $prec)
(Fp, 2):Fp Fp_sqr($1, p)
(Fp, usmall):Fp Fp_powu($1, $2, p)
(Fp, small):Fp Fp_pows($1, $2, p)
(Fp, int):Fp Fp_pow($1, $2, p)
(FpX, 2):FpX FpX_sqr($1, p)
(FpX, usmall):FpX FpX_powu($1, $2, p)
(Fq, 2):Fq Fq_sqr($1, T, p)
(Fq, usmall):Fq Fq_powu($1, $2, T, p)
(Fq, int):Fq Fq_pow($1, $2, T, p)
(Fq, 2):Fq Fq_sqr($1, T, p)
(Fq, usmall):Fq Fq_powu($1, $2, T, p)
(Fq, int):Fq Fq_pow($1, $2, T, p)
(FqX, 2):FqX FqX_sqr($1, T, p)
(FqX, usmall):FqX FqX_powu($1, $2, T, p)
Function: _^s
Class: basic
Section: programming/internals
C-Name: gpowgs
Prototype: GL
Help: return x^n where n is a small integer
Function: __
Class: basic
Section: symbolic_operators
Help: __
Description:
(genstr, genstr):genstr gconcat($1, $2)
(genstr, gen):genstr gconcat($1, $2)
(gen, genstr):genstr gconcat($1, $2)
(gen, gen):genstr gconcat($genstr:1, $2)
Function: _avma
Class: gp2c_internal
Description:
():pari_sp avma
Function: _badtype
Class: gp2c_internal
Help: Code to check types. If not void, will be used as if(...).
Description:
(int):bool:parens typ($1) != t_INT
(real):bool:parens typ($1) != t_REAL
(mp):negbool is_intreal_t(typ($1))
(vec):negbool is_matvec_t(typ($1))
(vecsmall):bool:parens typ($1) != t_VECSMALL
(pol):bool:parens typ($1) != t_POL
(*nf):void:parens $1 = checknf($1)
(*bnf):void:parens $1 = checkbnf($1)
(bnr):void checkbnr($1)
(prid):void checkprid($1)
(clgp):void checkabgrp($1)
(ell):void checkell($1)
(*gal):gal:parens $1 = checkgal($1)
Function: _cast
Class: gp2c_internal
Help: (type1):type2 : cast expression of type1 to type2
Description:
(void):bool 0
(#negbool):bool ${1 value not}
(negbool):bool !$(1)
(small_int):bool
(usmall):bool
(small):bool
(lg):bool:parens $(1)!=1
(bptr):bool *$(1)
(gen):bool !gequal0($1)
(real):bool signe($1)
(int):bool signe($1)
(mp):bool signe($1)
(pol):bool signe($1)
(void):negbool 1
(#bool):negbool ${1 value not}
(bool):negbool !$(1)
(lg):negbool:parens $(1)==1
(bptr):negbool !*$(1)
(gen):negbool gequal0($1)
(int):negbool !signe($1)
(real):negbool !signe($1)
(mp):negbool !signe($1)
(pol):negbool !signe($1)
(bool):small_int
(typ):small_int
(small):small_int
(bool):usmall
(typ):usmall
(small):usmall
(bool):small
(typ):small
(small_int):small
(usmall):small
(bptr):small *$(1)
(int):small itos($1)
(int):usmall itou($1)
(#lg):small:parens ${1 value 1 sub}
(lg):small:parens $(1)-1
(gen):small gtos($1)
(gen):usmall gtou($1)
(void):int gen_0
(-2):int gen_m2
(-1):int gen_m1
(0):int gen_0
(1):int gen_1
(2):int gen_2
(bool):int stoi($1)
(small):int stoi($1)
(usmall):int utoi($1)
(mp):int
(gen):int
(mp):real
(gen):real
(int):mp
(real):mp
(gen):mp
(#bool):lg:parens ${1 1 value add}
(bool):lg:parens $(1)+1
(#small):lg:parens ${1 1 value add}
(small):lg:parens $(1)+1
(gen):error
(gen):closure
(gen):vecsmall
(nf):vec
(bnf):vec
(bnr):vec
(ell):vec
(clgp):vec
(prid):vec
(gal):vec
(gen):vec
(gen):list
(pol):var varn($1)
(gen):var gvar($1)
(var):pol pol_x($1)
(gen):pol
(int):gen
(mp):gen
(vecsmall):gen
(vec):gen
(list):gen
(pol):gen
(genstr):gen
(error):gen
(closure):gen
(Fp):gen
(FpX):gen
(Fq):gen
(FqX):gen
(gen):genstr GENtoGENstr($1)
(str):genstr strtoGENstr($1)
(gen):str GENtostr_unquoted($1)
(genstr):str GSTR($1)
(typ):str type_name($1)
(errtyp):str numerr_name($1)
(#str):typ ${1 str_format}
(#str):errtyp ${1 str_format}
(bnf):nf bnf_get_nf($1)
(gen):nf
(bnr):bnf bnr_get_bnf($1)
(gen):bnf
(gen):bnr
(bnf):clgp bnf_get_clgp($1)
(bnr):clgp bnr_get_clgp($1)
(gen):clgp
(gen):ell
(gen):gal
(gen):prid
(Fp):Fq
Function: _cgetg
Class: gp2c_internal
Description:
(lg,#str):gen cgetg($1, ${2 str_raw})
(gen,lg,#str):gen $1 = cgetg($2, ${3 str_raw})
Function: _const_expr
Class: gp2c_internal
Description:
(str):gen readseq($1)
Function: _const_quote
Class: gp2c_internal
Description:
(str):var fetch_user_var($1)
Function: _const_real
Class: gp2c_internal
Description:
(str):real:prec strtor($1, $prec)
Function: _const_smallreal
Class: gp2c_internal
Description:
(0):real:prec real_0($prec)
(1):real:prec real_1($prec)
(-1):real:prec real_m1($prec)
(small):real:prec stor($1, $prec)
Function: _decl_base
Class: gp2c_internal
Description:
(C!void) void
(C!long) long
(C!ulong) ulong
(C!int) int
(C!GEN) GEN
(C!char*) char
(C!byteptr) byteptr
(C!pari_sp) pari_sp
(C!func_GG) GEN
(C!forprime_t) forprime_t
(C!forcomposite_t) forcomposite_t
(C!forpart_t) forpart_t
(C!forvec_t) forvec_t
Function: _decl_ext
Class: gp2c_internal
Description:
(C!char*) *$1
(C!func_GG) (*$1)(GEN, GEN)
Function: _def_TeXstyle
Class: default
Section: default
C-Name: sd_TeXstyle
Prototype:
Help:
Doc: the bits of this default allow
\kbd{gp} to use less rigid TeX formatting commands in the logfile. This
default is only taken into account when $\kbd{log} = 3$. The bits of
\kbd{TeXstyle} have the following meaning
2: insert \kbd{\bs right} / \kbd{\bs left} pairs where appropriate.
4: insert discretionary breaks in polynomials, to enhance the probability of
a good line break.
The default value is \kbd{0}.
Function: _def_breakloop
Class: default
Section: default
C-Name: sd_breakloop
Prototype:
Help:
Doc: if true, enables the ``break loop'' debugging mode, see
\secref{se:break_loop}.
The default value is \kbd{1} if we are running an interactive \kbd{gp}
session, and \kbd{0} otherwise.
Function: _def_colors
Class: default
Section: default
C-Name: sd_colors
Prototype:
Help:
Doc: this default is only usable if \kbd{gp}
is running within certain color-capable terminals. For instance \kbd{rxvt},
\kbd{color\_xterm} and modern versions of \kbd{xterm} under X Windows, or
standard Linux/DOS text consoles. It causes \kbd{gp} to use a small palette of
colors for its output. With xterms, the colormap used corresponds to the
resources \kbd{Xterm*color$n$} where $n$ ranges from $0$ to $15$ (see the
file \kbd{misc/color.dft} for an example). Accepted values for this
default are strings \kbd{"$a_1$,\dots,$a_k$"} where $k\le7$ and each
$a_i$ is either
\noindent\item the keyword \kbd{no} (use the default color, usually
black on transparent background)
\noindent\item an integer between 0 and 15 corresponding to the
aforementioned colormap
\noindent\item a triple $[c_0,c_1,c_2]$ where $c_0$ stands for foreground
color, $c_1$ for background color, and $c_2$ for attributes (0 is default, 1
is bold, 4 is underline).
The output objects thus affected are respectively error messages,
history numbers, prompt, input line, output, help messages, timer (that's
seven of them). If $k < 7$, the remaining $a_i$ are assumed to be $no$. For
instance
%
\bprog
default(colors, "9, 5, no, no, 4")
@eprog
\noindent
typesets error messages in color $9$, history numbers in color $5$, output in
color $4$, and does not affect the rest.
A set of default colors for dark (reverse video or PC console) and light
backgrounds respectively is activated when \kbd{colors} is set to
\kbd{darkbg}, resp.~\kbd{lightbg} (or any proper prefix: \kbd{d} is
recognized as an abbreviation for \kbd{darkbg}). A bold variant of
\kbd{darkbg}, called \kbd{boldfg}, is provided if you find the former too
pale.
\emacs In the present version, this default is incompatible with PariEmacs.
Changing it will just fail silently (the alternative would be to display
escape sequences as is, since Emacs will refuse to interpret them).
You must customize color highlighting from the PariEmacs side, see its
documentation.
The default value is \kbd{""} (no colors).
Function: _def_compatible
Class: default
Section: default
C-Name: sd_compatible
Prototype:
Help:
Doc: Obsolete. This default is now a no-op.
Obsolete: 2014-10-11
Function: _def_datadir
Class: default
Section: default
C-Name: sd_datadir
Prototype:
Help:
Doc: the name of directory containing the optional data files. For now,
this includes the \kbd{elldata}, \kbd{galdata}, \kbd{galpol}, \kbd{seadata}
packages.
The default value is \kbd{/usr/local/share/pari}, or the override specified
via \kbd{Configure --datadir=}.
Function: _def_debug
Class: default
Section: default
C-Name: sd_debug
Prototype:
Help:
Doc: debugging level. If it is non-zero, some extra messages may be printed,
according to what is going on (see~\b{g}).
The default value is \kbd{0} (no debugging messages).
Function: _def_debugfiles
Class: default
Section: default
C-Name: sd_debugfiles
Prototype:
Help:
Doc: file usage debugging level. If it is non-zero, \kbd{gp} will print
information on file descriptors in use, from PARI's point of view
(see~\b{gf}).
The default value is \kbd{0} (no debugging messages).
Function: _def_debugmem
Class: default
Section: default
C-Name: sd_debugmem
Prototype:
Help:
Doc: memory debugging level. If it is non-zero, \kbd{gp} will regularly print
information on memory usage. If it's greater than 2, it will indicate any
important garbage collecting and the function it is taking place in
(see~\b{gm}).
\noindent {\bf Important Note:} As it noticeably slows down the performance,
the first functionality (memory usage) is disabled if you're not running a
version compiled for debugging (see Appendix~A).
The default value is \kbd{0} (no debugging messages).
Function: _def_echo
Class: default
Section: default
C-Name: sd_echo
Prototype:
Help:
Doc: this toggle is either 1 (on) or 0 (off). When \kbd{echo}
mode is on, each command is reprinted before being executed. This can be
useful when reading a file with the \b{r} or \kbd{read} commands. For
example, it is turned on at the beginning of the test files used to check
whether \kbd{gp} has been built correctly (see \b{e}).
The default value is \kbd{0} (no echo).
Function: _def_factor_add_primes
Class: default
Section: default
C-Name: sd_factor_add_primes
Prototype:
Help:
Doc: this toggle is either 1 (on) or 0 (off). If on,
the integer factorization machinery calls \tet{addprimes} on prime
factors that were difficult to find (larger than $2^{24}$), so they are
automatically tried first in other factorizations. If a routine is performing
(or has performed) a factorization and is interrupted by an error or via
Control-C, this lets you recover the prime factors already found. The
downside is that a huge \kbd{addprimes} table unrelated to the current
computations will slow down arithmetic functions relying on integer
factorization; one should then empty the table using \tet{removeprimes}.
The default value is \kbd{0}.
Function: _def_factor_proven
Class: default
Section: default
C-Name: sd_factor_proven
Prototype:
Help:
Doc: this toggle is either 1 (on) or 0 (off). By
default, the factors output by the integer factorization machinery are
only pseudo-primes, not proven primes. If this toggle is
set, a primality proof is done for each factor and all results depending on
integer factorization are fully proven. This flag does not affect partial
factorization when it is explicitly requested. It also does not affect the
private table managed by \tet{addprimes}: its entries are included as is in
factorizations, without being tested for primality.
The default value is \kbd{0}.
Function: _def_format
Class: default
Section: default
C-Name: sd_format
Prototype:
Help:
Doc: of the form x$.n$, where x (conversion style)
is a letter in $\{\kbd{e},\kbd{f},\kbd{g}\}$, and $n$ (precision) is an
integer; this affects the way real numbers are printed:
\item If the conversion style is \kbd{e}, real numbers are printed in
\idx{scientific format}, always with an explicit exponent,
e.g.~\kbd{3.3 E-5}.
\item In style \kbd{f}, real numbers are generally printed in
\idx{fixed floating point format} without exponent, e.g.~\kbd{0.000033}. A
large real number, whose integer part is not well defined (not enough
significant digits), is printed in style~\kbd{e}. For instance
\kbd{10.\pow 100} known to ten significant digits is always printed in style
\kbd{e}.
\item In style \kbd{g}, non-zero real numbers are printed in \kbd{f} format,
except when their decimal exponent is $< -4$, in which case they are printed
in \kbd{e} format. Real zeroes (of arbitrary exponent) are printed in \kbd{e}
format.
The precision $n$ is the number of significant digits printed for real
numbers, except if $n<0$ where all the significant digits will be printed
(initial default 28, or 38 for 64-bit machines). For more powerful formatting
possibilities, see \tet{printf} and \tet{Strprintf}.
The default value is \kbd{"g.28"} and \kbd{"g.38"} on 32-bit and
64-bit machines, respectively.
Function: _def_graphcolormap
Class: default
Section: default
C-Name: sd_graphcolormap
Prototype:
Help:
Doc: a vector of colors, to be
used by hi-res graphing routines. Its length is arbitrary, but it must
contain at least 3 entries: the first 3 colors are used for background,
frame/ticks and axes respectively. All colors in the colormap may be freely
used in \tet{plotcolor} calls.
A color is either given as in the default by character strings or by an RGB
code. For valid character strings, see the standard \kbd{rgb.txt} file in X11
distributions, where we restrict to lowercase letters and remove all
whitespace from color names. An RGB code is a vector with 3 integer entries
between 0 and 255. For instance \kbd{[250, 235, 215]} and
\kbd{"antiquewhite"} represent the same color. RGB codes are cryptic but
often easier to generate.
The default value is [\kbd{"white"}, \kbd{"black"}, \kbd{"blue"},
\kbd{"violetred"}, \kbd{"red"}, \kbd{"green"}, \kbd{"grey"},
\kbd{"gainsboro"}].
Function: _def_graphcolors
Class: default
Section: default
C-Name: sd_graphcolors
Prototype:
Help:
Doc: entries in the
\tet{graphcolormap} that will be used to plot multi-curves. The successive
curves are drawn in colors
\kbd{graphcolormap[graphcolors[1]]}, \kbd{graphcolormap[graphcolors[2]]},
\dots
cycling when the \kbd{graphcolors} list is exhausted.
The default value is \kbd{[4,5]}.
Function: _def_help
Class: default
Section: default
C-Name: sd_help
Prototype:
Help:
Doc: name of the external help program to use from within \kbd{gp} when
extended help is invoked, usually through a \kbd{??} or \kbd{???} request
(see \secref{se:exthelp}), or \kbd{M-H} under readline (see
\secref{se:readline}).
The default value is the path to the \kbd{gphelp} script we install.
Function: _def_histfile
Class: default
Section: default
C-Name: sd_histfile
Prototype:
Help:
Doc: name of a file where
\kbd{gp} will keep a history of all \emph{input} commands (results are
omitted). If this file exists when the value of \kbd{histfile} changes,
it is read in and becomes part of the session history. Thus, setting this
default in your gprc saves your readline history between sessions. Setting
this default to the empty string \kbd{""} changes it to
\kbd{$<$undefined$>$}
The default value is \kbd{$<$undefined$>$} (no history file).
Function: _def_histsize
Class: default
Section: default
C-Name: sd_histsize
Prototype:
Help:
Doc: \kbd{gp} keeps a history of the last
\kbd{histsize} results computed so far, which you can recover using the
\kbd{\%} notation (see \secref{se:history}). When this number is exceeded,
the oldest values are erased. Tampering with this default is the only way to
get rid of the ones you do not need anymore.
The default value is \kbd{5000}.
Function: _def_lines
Class: default
Section: default
C-Name: sd_lines
Prototype:
Help:
Doc: if set to a positive value, \kbd{gp} prints at
most that many lines from each result, terminating the last line shown with
\kbd{[+++]} if further material has been suppressed. The various \kbd{print}
commands (see \secref{se:gp_program}) are unaffected, so you can always type
\kbd{print(\%)} or \b{a} to view the full result. If the actual screen width
cannot be determined, a ``line'' is assumed to be 80 characters long.
The default value is \kbd{0}.
Function: _def_linewrap
Class: default
Section: default
C-Name: sd_linewrap
Prototype:
Help:
Doc: if set to a positive value, \kbd{gp} wraps every single line after
printing that many characters.
The default value is \kbd{0} (unset).
Function: _def_log
Class: default
Section: default
C-Name: sd_log
Prototype:
Help:
Doc: this can be either 0 (off) or 1, 2, 3
(on, see below for the various modes). When logging mode is turned on, \kbd{gp}
opens a log file, whose exact name is determined by the \kbd{logfile}
default. Subsequently, all the commands and results will be written to that
file (see \b{l}). In case a file with this precise name already existed, it
will not be erased: your data will be \emph{appended} at the end.
The specific positive values of \kbd{log} have the following meaning
1: plain logfile
2: emit color codes to the logfile (if \kbd{colors} is set).
3: write LaTeX output to the logfile (can be further customized using
\tet{TeXstyle}).
The default value is \kbd{0}.
Function: _def_logfile
Class: default
Section: default
C-Name: sd_logfile
Prototype:
Help:
Doc: name of the log file to be used when the \kbd{log} toggle is on.
Environment and time expansion are performed.
The default value is \kbd{"pari.log"}.
Function: _def_nbthreads
Class: default
Section: default
C-Name: sd_nbthreads
Prototype:
Help:
Doc: Number of threads to use for parallel computing.
The exact meaning an default depend on the \kbd{mt} engine used:
\item \kbd{single}: not used (always one thread).
\item \kbd{pthread}: number of threads (unlimited, default: number of core)
\item \kbd{mpi}: number of MPI process to use (limited to the number allocated by \kbd{mpirun},
default: use all allocated process).
Function: _def_new_galois_format
Class: default
Section: default
C-Name: sd_new_galois_format
Prototype:
Help:
Doc: this toggle is either 1 (on) or 0 (off). If on,
the \tet{polgalois} command will use a different, more
consistent, naming scheme for Galois groups. This default is provided to
ensure that scripts can control this behavior and do not break unexpectedly.
The default value is \kbd{0}. This value will change to $1$ (set) in the next
major version.
Function: _def_output
Class: default
Section: default
C-Name: sd_output
Prototype:
Help:
Doc: there are three possible values: 0
(=~\var{raw}), 1 (=~\var{prettymatrix}), or 3
(=~\var{external} \var{prettyprint}). This
means that, independently of the default \kbd{format} for reals which we
explained above, you can print results in three ways:
\item \tev{raw format}, i.e.~a format which is equivalent to what you
input, including explicit multiplication signs, and everything typed on a
line instead of two dimensional boxes. This can have several advantages, for
instance it allows you to pick the result with a mouse or an editor, and to
paste it somewhere else.
\item \tev{prettymatrix format}: this is identical to raw format, except
that matrices are printed as boxes instead of horizontally. This is
prettier, but takes more space and cannot be used for input. Column vectors
are still printed horizontally.
\item \tev{external prettyprint}: pipes all \kbd{gp}
output in TeX format to an external prettyprinter, according to the value of
\tet{prettyprinter}. The default script (\tet{tex2mail}) converts its input
to readable two-dimensional text.
Independently of the setting of this default, an object can be printed
in any of the three formats at any time using the commands \b{a} and \b{m}
and \b{B} respectively.
The default value is \kbd{1} (\var{prettymatrix}).
Function: _def_parisize
Class: default
Section: default
C-Name: sd_parisize
Prototype:
Help:
Doc: \kbd{gp}, and in fact any program using the PARI
library, needs a \tev{stack} in which to do its computations; \kbd{parisize}
is the stack size, in bytes. It is recommended to increase this
default using a \tet{gprc}, to the value you believe PARI should be happy
with, given your typical computation. We strongly recommend to also
set \tet{parisizemax} to a much larger value, about what you believe your
machine can stand: PARI will then try to fit its computations within about
\kbd{parisize} bytes, but will increase the stack size if needed (up to
\kbd{parisizemax}). Once the memory intensive computation is over, PARI
will restore the stack size to the originally requested \kbd{parisize}.
The default value is 4M, resp.~8M on a 32-bit, resp.~64-bit machine.
Function: _def_parisizemax
Class: default
Section: default
C-Name: sd_parisizemax
Prototype:
Help:
Doc: \kbd{gp}, and in fact any program using the PARI library, needs a
\tev{stack} in which to do its computations. If non-zero, \kbd{parisizemax}
is the maximum size the stack can grow to, in bytes. If zero, the stack will
not automatically grow, and will be limited to the value of \kbd{parisize}.
We strongly recommend to set \tet{parisizemax} to a non-zero value, about
what you believe your machine can stand: PARI will then try to fit its
computations within about \kbd{parisize} bytes, but will increase the stack
size if needed (up to \kbd{parisizemax}). Once the memory intensive
computation is over, PARI will restore the stack size to the originally
requested \kbd{parisize}.
The default value is $0$.
Function: _def_path
Class: default
Section: default
C-Name: sd_path
Prototype:
Help:
Doc: this is a list of directories, separated by colons ':'
(semicolons ';' in the DOS world, since colons are preempted for drive names).
When asked to read a file whose name is not given by an absolute path
(does not start with \kbd{/}, \kbd{./} or \kbd{../}), \kbd{gp} will look for
it in these directories, in the order they were written in \kbd{path}. Here,
as usual, \kbd{.} means the current directory, and \kbd{..} its immediate
parent. Environment expansion is performed.
The default value is \kbd{".:\til:\til/gp"} on UNIX systems,
\kbd{".;C:\bs;C:\bs GP"} on DOS, OS/2 and Windows, and \kbd{"."} otherwise.
Function: _def_prettyprinter
Class: default
Section: default
C-Name: sd_prettyprinter
Prototype:
Help:
Doc: the name of an external prettyprinter to use when
\kbd{output} is~3 (alternate prettyprinter). Note that the default
\tet{tex2mail} looks much nicer than the built-in ``beautified
format'' ($\kbd{output} = 2$).
The default value is \kbd{"tex2mail -TeX -noindent -ragged -by\_par"}.
Function: _def_primelimit
Class: default
Section: default
C-Name: sd_primelimit
Prototype:
Help:
Doc: \kbd{gp} precomputes a list of
all primes less than \kbd{primelimit} at initialization time, and can build
fast sieves on demand to quickly iterate over primes up to the \emph{square}
of \kbd{primelimit}. These are used by many arithmetic functions, usually for
trial division purposes. The maximal value is $2^{32} - 2049$ (resp $2^{64} -
2049$) on a 32-bit (resp.~64-bit) machine, but values beyond $10^8$,
allowing to iterate over primes up to $10^{16}$, do not seem useful.
Since almost all arithmetic functions eventually require some table of prime
numbers, PARI guarantees that the first 6547 primes, up to and
including 65557, are precomputed, even if \kbd{primelimit} is $1$.
This default is only used on startup: changing it will not recompute a new
table.
\misctitle{Deprecated feature} \kbd{primelimit} was used in some
situations by algebraic number theory functions using the
\tet{nf_PARTIALFACT} flag (\tet{nfbasis}, \tet{nfdisc}, \tet{nfinit}, \dots):
this assumes that all primes $p > \kbd{primelimit}$ have a certain
property (the equation order is $p$-maximal). This is never done by default,
and must be explicitly set by the user of such functions. Nevertheless,
these functions now provide a more flexible interface, and their use
of the global default \kbd{primelimit} is deprecated.
\misctitle{Deprecated feature} \kbd{factor(N, 0)} was used to partially
factor integers by removing all prime factors $\leq$ \kbd{primelimit}.
Don't use this, supply an explicit bound: \kbd{factor(N, bound)},
which avoids relying on an unpredictable global variable.
The default value is \kbd{500k}.
Function: _def_prompt
Class: default
Section: default
C-Name: sd_prompt
Prototype:
Help:
Doc: a string that will be printed as
prompt. Note that most usual escape sequences are available there: \b{e} for
Esc, \b{n} for Newline, \dots, \kbd{\bs\bs} for \kbd{\bs}. Time expansion is
performed.
This string is sent through the library function \tet{strftime} (on a
Unix system, you can try \kbd{man strftime} at your shell prompt). This means
that \kbd{\%} constructs have a special meaning, usually related to the time
and date. For instance, \kbd{\%H} = hour (24-hour clock) and \kbd{\%M} =
minute [00,59] (use \kbd{\%\%} to get a real \kbd{\%}).
If you use \kbd{readline}, escape sequences in your prompt will result in
display bugs. If you have a relatively recent \kbd{readline} (see the comment
at the end of \secref{se:def,colors}), you can brace them with special sequences
(\kbd{\bs[} and \kbd{\bs]}), and you will be safe. If these just result in
extra spaces in your prompt, then you'll have to get a more recent
\kbd{readline}. See the file \kbd{misc/gprc.dft} for an example.
\emacs {\bf Caution}: PariEmacs needs to know about the prompt pattern to
separate your input from previous \kbd{gp} results, without ambiguity. It is
not a trivial problem to adapt automatically this regular expression to an
arbitrary prompt (which can be self-modifying!). See PariEmacs's
documentation.
The default value is \kbd{"? "}.
Function: _def_prompt_cont
Class: default
Section: default
C-Name: sd_prompt_cont
Prototype:
Help:
Doc: a string that will be printed
to prompt for continuation lines (e.g. in between braces, or after a
line-terminating backslash). Everything that applies to \kbd{prompt}
applies to \kbd{prompt\_cont} as well.
The default value is \kbd{""}.
Function: _def_psfile
Class: default
Section: default
C-Name: sd_psfile
Prototype:
Help:
Doc: name of the default file where
\kbd{gp} is to dump its PostScript drawings (these are appended, so that no
previous data are lost). Environment and time expansion are performed.
The default value is \kbd{"pari.ps"}.
Function: _def_readline
Class: default
Section: default
C-Name: sd_readline
Prototype:
Help:
Doc: switches readline line-editing
facilities on and off. This may be useful if you are running \kbd{gp} in a Sun
\tet{cmdtool}, which interacts badly with readline. Of course, until readline
is switched on again, advanced editing features like automatic completion
and editing history are not available.
The default value is \kbd{1}.
Function: _def_realbitprecision
Class: default
Section: default
C-Name: sd_realbitprecision
Prototype:
Help:
Doc: the number of significant bits used to convert exact inputs given to
transcendental functions (see \secref{se:trans}), or to create
absolute floating point constants (input as \kbd{1.0} or \kbd{Pi} for
instance). Unless you tamper with the \tet{format} default, this is also
the number of significant bits used to print a \typ{REAL} number;
\kbd{format} will override this latter behaviour, and allow you to have a
large internal precision while outputting few digits for instance.
Note that most PARI's functions currently handle precision on a word basis (by
increments of 32 or 64 bits), hence bit precision may be a little larger
than the number of bits you expected. For instance to get 10 bits of
precision, you need one word of precision which, on a 64-bit machine,
correspond to 64 bits. To make things even more confusing, this internal bit
accuracy is converted to decimal digits when printing floating point numbers:
now 64 bits correspond to 19 printed decimal digits
($19 < \log_{10}(2^{64}) < 20$).
The value returned when typing \kbd{default(realbitprecision)} is the internal
number of significant bits, not the number of printed decimal digits:
\bprog
? default(realbitprecision, 10)
? \pb
realbitprecision = 64 significant bits
? default(realbitprecision)
%1 = 64
? \p
realprecision = 3 significant digits
? default(realprecision)
%2 = 19
@eprog\noindent Note that \tet{realprecision} and \kbd{\bs p} allow
to view and manipulate the internal precision in decimal digits.
The default value is \kbd{128}, resp.~\kbd{96}, on a 64-bit, resp~.32-bit,
machine.
Function: _def_realprecision
Class: default
Section: default
C-Name: sd_realprecision
Prototype:
Help:
Doc: the number of significant digits used to convert exact inputs given to
transcendental functions (see \secref{se:trans}), or to create
absolute floating point constants (input as \kbd{1.0} or \kbd{Pi} for
instance). Unless you tamper with the \tet{format} default, this is also
the number of significant digits used to print a \typ{REAL} number;
\kbd{format} will override this latter behaviour, and allow you to have a
large internal precision while outputting few digits for instance.
Note that PARI's internal precision works on a word basis (by increments of
32 or 64 bits), hence may be a little larger than the number of decimal
digits you expected. For instance to get 2 decimal digits you need one word
of precision which, on a 64-bit machine, actually gives you 19 digits ($19 <
\log_{10}(2^{64}) < 20$). The value returned when typing
\kbd{default(realprecision)} is the internal number of significant digits,
not the number of printed digits:
\bprog
? default(realprecision, 2)
realprecision = 19 significant digits (2 digits displayed)
? default(realprecision)
%1 = 19
@eprog
The default value is \kbd{38}, resp.~\kbd{28}, on a 64-bit, resp.~32-bit,
machine.
Function: _def_recover
Class: default
Section: default
C-Name: sd_recover
Prototype:
Help:
Doc: this toggle is either 1 (on) or 0 (off). If you change this to $0$, any
error becomes fatal and causes the gp interpreter to exit immediately. Can be
useful in batch job scripts.
The default value is \kbd{1}.
Function: _def_secure
Class: default
Section: default
C-Name: sd_secure
Prototype:
Help:
Doc: this toggle is either 1 (on) or 0 (off). If on, the \tet{system} and
\tet{extern} command are disabled. These two commands are potentially
dangerous when you execute foreign scripts since they let \kbd{gp} execute
arbitrary UNIX commands. \kbd{gp} will ask for confirmation before letting
you (or a script) unset this toggle.
The default value is \kbd{0}.
Function: _def_seriesprecision
Class: default
Section: default
C-Name: sd_seriesprecision
Prototype:
Help:
Doc: number of significant terms
when converting a polynomial or rational function to a power series
(see~\b{ps}).
The default value is \kbd{16}.
Function: _def_simplify
Class: default
Section: default
C-Name: sd_simplify
Prototype:
Help:
Doc: this toggle is either 1 (on) or 0 (off). When the PARI library computes
something, the type of the
result is not always the simplest possible. The only type conversions which
the PARI library does automatically are rational numbers to integers (when
they are of type \typ{FRAC} and equal to integers), and similarly rational
functions to polynomials (when they are of type \typ{RFRAC} and equal to
polynomials). This feature is useful in many cases, and saves time, but can
be annoying at times. Hence you can disable this and, whenever you feel like
it, use the function \kbd{simplify} (see Chapter 3) which allows you to
simplify objects to the simplest possible types recursively (see~\b{y}).
\sidx{automatic simplification}
The default value is \kbd{1}.
Function: _def_sopath
Class: default
Section: default
C-Name: sd_sopath
Prototype:
Help:
Doc: this is a list of directories, separated by colons ':'
(semicolons ';' in the DOS world, since colons are preempted for drive names).
When asked to \tet{install} an external symbol from a shared library whose
name is not given by an absolute path (does not start with \kbd{/}, \kbd{./}
or \kbd{../}), \kbd{gp} will look for it in these directories, in the order
they were written in \kbd{sopath}. Here, as usual, \kbd{.} means the current
directory, and \kbd{..} its immediate parent. Environment expansion is
performed.
The default value is \kbd{""}, corresponding to an empty list of
directories: \tet{install} will use the library name as input (and look in
the current directory if the name is not an absolute path).
Function: _def_strictargs
Class: default
Section: default
C-Name: sd_strictargs
Prototype:
Help:
Doc: this toggle is either 1 (on) or 0 (off). If on, all arguments to \emph{new}
user functions are mandatory unless the function supplies an explicit default
value.
Otherwise arguments have the default value $0$.
In this example,
\bprog
fun(a,b=2)=a+b
@eprog
\kbd{a} is mandatory, while \kbd{b} is optional. If \kbd{strictargs} is on:
\bprog
? fun()
*** at top-level: fun()
*** ^-----
*** in function fun: a,b=2
*** ^-----
*** missing mandatory argument 'a' in user function.
@eprog
This applies to functions defined while \kbd{strictargs} is on. Changing \kbd{strictargs}
does not affect the behavior of previously defined functions.
The default value is \kbd{0}.
Function: _def_strictmatch
Class: default
Section: default
C-Name: sd_strictmatch
Prototype:
Help:
Doc: Obsolete. This toggle is now a no-op.
Obsolete: 2014-10-11
Function: _def_threadsize
Class: default
Section: default
C-Name: sd_threadsize
Prototype:
Help:
Doc: In parallel mode, each thread needs its own private \tev{stack} in which
to do its computations, see \kbd{parisize}. This value determines the size
in bytes of the stacks of each thread, so the total memory allocated will be
$\kbd{parisize}+\kbd{nbthreads}\times\kbd{threadsize}$.
If set to $0$, the value used is the same as \kbd{parisize}.
The default value is $0$.
Function: _def_threadsizemax
Class: default
Section: default
C-Name: sd_threadsizemax
Prototype:
Help:
Doc: In parallel mode, each threads needs its own private \tev{stack} in which
to do its computations, see \kbd{parisize}. This value determines the maximal
size in bytes of the stacks of each thread, so the total memory allocated will
be between $\kbd{parisize}+\kbd{nbthreads}\times\kbd{threadsize}$. and
$\kbd{parisize}+\kbd{nbthreads}\times\kbd{threadsizemax}$.
If set to $0$, the value used is the same as \kbd{threadsize}.
The default value is $0$.
Function: _def_timer
Class: default
Section: default
C-Name: sd_timer
Prototype:
Help:
Doc: this toggle is either 1 (on) or 0 (off). Every instruction sequence
in the gp calculator (anything ended by a newline in your input) is timed,
to some accuracy depending on the hardware and operating system. When
\tet{timer} is on, each such timing is printed immediately before the
output as follows:
\bprog
? factor(2^2^7+1)
time = 108 ms. \\ this line omitted if 'timer' is 0
%1 =
[ 59649589127497217 1]
[5704689200685129054721 1]
@eprog\noindent (See also \kbd{\#} and \kbd{\#\#}.)
The time measured is the user \idx{CPU time}, \emph{not} including the time
for printing the results. If the time is negligible ($< 1$ ms.), nothing is
printed: in particular, no timing should be printed when defining a user
function or an alias, or installing a symbol from the library.
The default value is \kbd{0} (off).
Function: _default_check
Class: gp2c_internal
Help: Code to check for the default marker
Description:
(C!GEN):bool !$(1)
(var):bool $(1) == -1
Function: _default_marker
Class: gp2c_internal
Help: Code for default value of GP function
Description:
(C!GEN) NULL
(var) -1
(small) 0
(str) ""
Function: _derivfun
Class: basic
Section: programming/internals
C-Name: derivfun0
Prototype: GGp
Help: _derivfun(closure,[args]) numerical derivation of closure with respect to
the first variable at (args).
Function: _diffptr
Class: gp2c_internal
Help: Table of difference of primes.
Description:
():bptr diffptr
Function: _err_primes
Class: gp2c_internal
Description:
():void pari_err(e_MAXPRIME)
Function: _err_type
Class: gp2c_internal
Description:
(str,gen):void pari_err_TYPE($1,$2)
Function: _eval_mnemonic
Class: basic
Section: programming/internals
C-Name: eval_mnemonic
Prototype: lGs
Help: Convert a mnemonic string to a flag.
Function: _factor_Aurifeuille
Class: basic
Section: programming/internals
C-Name: factor_Aurifeuille
Prototype: GL
Help: _factor_Aurifeuille(a,d): return an algebraic factor of Phi_d(a), a != 0
Function: _factor_Aurifeuille_prime
Class: basic
Section: programming/internals
C-Name: factor_Aurifeuille_prime
Prototype: GL
Help: _factor_Aurifeuille_prime(p,d): return an algebraic factor of Phi_d(p), p prime
Function: _forcomposite_init
Class: gp2c_internal
Help: Initialize forcomposite_t.
Description:
(forcomposite,int):void forcomposite_init(&$1, $2, NULL)
(forcomposite,int,int):void forcomposite_init(&$1, $2, $3)
Function: _forcomposite_next
Class: gp2c_internal
Help: Compute the next composite.
Description:
(forcomposite):int forcomposite_next(&$1)
Function: _formatcode
Class: gp2c_internal
Description:
(#small):void $1
(small):small %ld
(#str):void $%1
(str):str %s
(gen):gen %Ps
Function: _forpart_init
Class: gp2c_internal
Help: Initialize forpart_t
Description:
(forpart,small,?gen,?gen):void forpart_init(&$1, $2, $3, $4)
Function: _forpart_next
Class: gp2c_internal
Help: Compute the next part
Description:
(forpart):vecsmall forpart_next(&$1)
Function: _forprime_init
Class: gp2c_internal
Help: Initialize forprime_t.
Description:
(forprime,int,?int):void forprime_init(&$1, $2, $3);
Function: _forprime_next
Class: gp2c_internal
Help: Compute the next prime from the diffptr table.
Description:
(*small,*bptr):void NEXT_PRIME_VIADIFF($1, $2)
Function: _forprime_next_
Class: gp2c_internal
Help: Compute the next prime.
Description:
(forprime):int forprime_next(&$1)
Function: _forvec_init
Class: gp2c_internal
Help: Initializes parameters for forvec.
Description:
(forvec, gen, ?small):void forvec_init(&$1, $2, $3)
Function: _forvec_next
Class: gp2c_internal
Help: Initializes parameters for forvec.
Description:
(forvec):vec forvec_next(&$1)
Function: _gc_needed
Class: gp2c_internal
Description:
(pari_sp):bool gc_needed($1, 1)
Function: _gerepileall
Class: gp2c_internal
Description:
(pari_sp,gen):void:parens $2 = gerepilecopy($1, $2)
(pari_sp,gen,...):void gerepileall($1, ${nbarg 1 sub}, ${stdref 3 code})
Function: _gerepileupto
Class: gp2c_internal
Description:
(pari_sp, int):int gerepileuptoint($1, $2)
(pari_sp, mp):mp gerepileuptoleaf($1, $2)
(pari_sp, vecsmall):vecsmall gerepileuptoleaf($1, $2)
(pari_sp, vec):vec gerepileupto($1, $2)
(pari_sp, gen):gen gerepileupto($1, $2)
Function: _iferr_CATCH
Class: gp2c_internal
Description:
(0) pari_CATCH(CATCH_ALL)
(small) pari_CATCH2(__iferr_old$1, CATCH_ALL)
Function: _iferr_CATCH_reset
Class: gp2c_internal
Description:
(0):void pari_CATCH_reset()
(small):void pari_CATCH2_reset(__iferr_old$1)
Function: _iferr_ENDCATCH
Class: gp2c_internal
Description:
(0) pari_ENDCATCH
(small) pari_ENDCATCH2(__iferr_old$1)
Function: _iferr_error
Class: gp2c_internal
Description:
():error pari_err_last()
Function: _iferr_rethrow
Class: gp2c_internal
Description:
(error):void pari_err(0, $1)
Function: _low_stack_lim
Class: gp2c_internal
Description:
(pari_sp,pari_sp):bool low_stack($1, stack_lim($2, 1))
Function: _maxprime
Class: gp2c_internal
Description:
():small maxprime()
Function: _multi_if
Class: basic
Section: programming/internals
C-Name: ifpari_multi
Prototype: GE*
Help: internal variant of if() that allows more than 3 arguments.
Function: _ndec2nbits
Class: gp2c_internal
Description:
(small):small ndec2nbits($1)
Function: _ndec2prec
Class: gp2c_internal
Description:
(small):small ndec2prec($1)
Function: _norange
Class: gp2c_internal
Description:
():small LONG_MAX
Function: _parapply_worker
Class: basic
Section: programming/internals
C-Name: parapply_worker
Prototype: GG
Help: _parapply_worker(d,C): evaluate the closure C on d.
Function: _pareval_worker
Class: basic
Section: programming/internals
C-Name: pareval_worker
Prototype: G
Help: _pareval_worker(C): evaluate the closure C.
Function: _parfor_worker
Class: basic
Section: programming/internals
C-Name: parfor_worker
Prototype: GG
Help: _parfor_worker(i,C): evaluate the closure C on i and return [i,C(i)]
Function: _parvector_worker
Class: basic
Section: programming/internals
C-Name: parvector_worker
Prototype: GG
Help: _parvector_worker(i,C): evaluate the closure C on i.
Function: _polint_worker
Class: basic
Section: programming/internals
C-Name: nmV_polint_center_tree_worker
Prototype: GGGGG
Help: used for parallel chinese
Doc: used for parallel chinese
Function: _polmodular_worker
Class: basic
Section: programming/internals
C-Name: polmodular_worker
Prototype: UUUGGGGLGG
Help: used by polmodular
Doc: used by polmodular
Function: _proto_code
Class: gp2c_internal
Help: Code for argument of a function
Description:
(var) n
(C!long) L
(C!ulong) U
(C!GEN) G
(C!char*) s
Function: _proto_max_args
Class: gp2c_internal
Help: Max number of arguments supported by install.
Description:
(20)
Function: _proto_ret
Class: gp2c_internal
Help: Code for return value of functions
Description:
(C!void) v
(C!int) i
(C!long) l
(C!ulong) u
(C!GEN)
Function: _safecoeff
Class: basic
Section: symbolic_operators
Help: safe version of x[a], x[,a] and x[a,b]. Must be lvalues.
Description:
(vecsmall,small):small *safeel($1, $2)
(list,small):gen:copy *safelistel($1, $2)
(gen,small):gen:copy *safegel($1, $2)
(gen,small,small):gen:copy *safegcoeff($1, $2, $3)
Function: _stack_lim
Class: gp2c_internal
Description:
(pari_sp,small):pari_sp stack_lim($1, $2)
Function: _strtoclosure
Class: gp2c_internal
Description:
(str):closure strtofunction($1)
(str,gen,...):closure strtoclosure($1, ${nbarg 1 sub}, $3)
Function: _tovec
Class: gp2c_internal
Help: Create a vector holding the arguments (shallow)
Description:
():vec cgetg(1, t_VEC)
(gen):vec mkvec($1)
(gen,gen):vec mkvec2($1, $2)
(gen,gen,gen):vec mkvec3($1, $2, $3)
(gen,gen,gen,gen):vec mkvec4($1, $2, $3, $4)
(gen,gen,gen,gen,gen):vec mkvec5($1, $2, $3, $4, $5)
(gen,...):vec mkvecn($#, $2)
Function: _tovecprec
Class: gp2c_internal
Help: Create a vector holding the arguments and prec (shallow)
Description:
():vec:prec mkvecs($prec)
(gen):vec:prec mkvec2($1, stoi($prec))
(gen,gen):vec:prec mkvec3($1, $2, stoi($prec))
(gen,gen,gen):vec:prec mkvec4($1, $2, $3, stoi($prec))
(gen,gen,gen,gen):vec:prec mkvec5($1, $2, $3, $4, stoi($prec))
(gen,...):vec:prec mkvecn(${nbarg 1 add}, $2, stoi($prec))
Function: _type_preorder
Class: gp2c_internal
Help: List of chains of type preorder.
Description:
(empty, void, bool, small, int, mp, gen)
(empty, real, mp)
(empty, bptr, small)
(empty, bool, lg, small)
(empty, bool, small_int, small)
(empty, bool, usmall, small)
(empty, void, negbool, bool)
(empty, typ, str, genstr,gen)
(empty, errtyp, str)
(empty, vecsmall, gen)
(empty, vec, gen)
(empty, list, gen)
(empty, closure, gen)
(empty, error, gen)
(empty, bnr, bnf, nf, vec)
(empty, bnr, bnf, clgp, vec)
(empty, ell, vec)
(empty, prid, vec)
(empty, gal, vec)
(empty, var, pol, gen)
(empty, Fp, Fq, gen)
(empty, FpX, FqX, gen)
Function: _typedef
Class: gp2c_internal
Description:
(empty) void
(void) void
(negbool) long
(bool) long
(small_int) int
(usmall) ulong
(small) long
(int) GEN
(real) GEN
(mp) GEN
(lg) long
(vecsmall) GEN
(vec) GEN
(list) GEN
(var) long
(pol) GEN
(gen) GEN
(closure) GEN
(error) GEN
(genstr) GEN
(str) char*
(bptr) byteptr
(forcomposite) forcomposite_t
(forpart) forpart_t
(forprime) forprime_t
(forvec) forvec_t
(func_GG) func_GG
(pari_sp) pari_sp
(typ) long
(errtyp) long
(nf) GEN
(bnf) GEN
(bnr) GEN
(ell) GEN
(clgp) GEN
(prid) GEN
(gal) GEN
(Fp) GEN
(FpX) GEN
(Fq) GEN
(FqX) GEN
Function: _u_forprime_init
Class: gp2c_internal
Help: Initialize forprime_t (ulong version).
Description:
(forprime,small,):void u_forprime_init(&$1, $2, LONG_MAX);
(forprime,small,small):void u_forprime_init(&$1, $2, $3);
Function: _u_forprime_next
Class: gp2c_internal
Help: Compute the next prime (ulong version).
Description:
(forprime):small u_forprime_next(&$1)
Function: _void_if
Class: basic
Section: programming/internals
C-Name: ifpari_void
Prototype: vGDIDI
Help: internal variant of if() that does not return a value.
Function: _wrap_G
Class: gp2c_internal
C-Name: gp_call
Prototype: G
Description:
(gen):gen $1
Function: _wrap_GG
Class: gp2c_internal
C-Name: gp_call2
Prototype: GG
Description:
(gen):gen $1
Function: _wrap_Gp
Class: gp2c_internal
C-Name: gp_callprec
Prototype: Gp
Description:
(gen):gen $1
Function: _wrap_bG
Class: gp2c_internal
C-Name: gp_callbool
Prototype: lG
Description:
(bool):bool $1
Function: _wrap_vG
Class: gp2c_internal
C-Name: gp_callvoid
Prototype: lG
Description:
(void):small 0
Function: _||_
Class: basic
Section: symbolic_operators
C-Name: orpari
Prototype: GE
Help: x||y: inclusive OR.
Description:
(bool, bool):bool:parens $(1) || $(2)
Function: _~
Class: basic
Section: symbolic_operators
C-Name: gtrans
Prototype: G
Help: x~: transpose of x.
Description:
(vec):vec gtrans($1)
(gen):gen gtrans($1)
Function: abs
Class: basic
Section: transcendental
C-Name: gabs
Prototype: Gp
Help: abs(x): absolute value (or modulus) of x.
Description:
(small):small labs($1)
(int):int mpabs($1)
(real):real mpabs($1)
(mp):mp mpabs($1)
(gen):gen:prec gabs($1, $prec)
Doc: absolute value of $x$ (modulus if $x$ is complex).
Rational functions are not allowed. Contrary to most transcendental
functions, an exact argument is \emph{not} converted to a real number before
applying \kbd{abs} and an exact result is returned if possible.
\bprog
? abs(-1)
%1 = 1
? abs(3/7 + 4/7*I)
%2 = 5/7
? abs(1 + I)
%3 = 1.414213562373095048801688724
@eprog\noindent
If $x$ is a polynomial, returns $-x$ if the leading coefficient is
real and negative else returns $x$. For a power series, the constant
coefficient is considered instead.
Function: acos
Class: basic
Section: transcendental
C-Name: gacos
Prototype: Gp
Help: acos(x): arc cosine of x.
Doc: principal branch of $\cos^{-1}(x) = -i \log (x + i\sqrt{1-x^2})$.
In particular, $\Re(\text{acos}(x))\in [0,\pi]$ and if $x\in \R$ and $|x|>1$,
then $\text{acos}(x)$ is complex. The branch cut is in two pieces:
$]-\infty,-1]$ , continuous with quadrant II, and $[1,+\infty[$, continuous
with quadrant IV. We have $\text{acos}(x) = \pi/2 - \text{asin}(x)$ for all
$x$.
Function: acosh
Class: basic
Section: transcendental
C-Name: gacosh
Prototype: Gp
Help: acosh(x): inverse hyperbolic cosine of x.
Doc: principal branch of $\cosh^{-1}(x) = 2
\log(\sqrt{(x+1)/2} + \sqrt{(x-1)/2})$. In particular,
$\Re(\text{acosh}(x))\geq 0$ and
$\Im(\text{acosh}(x))\in ]-\pi,\pi]$; if $x\in \R$ and $x<1$, then
$\text{acosh}(x)$ is complex.
Function: addhelp
Class: basic
Section: programming/specific
C-Name: addhelp
Prototype: vrs
Help: addhelp(sym,str): add/change help message for the symbol sym.
Doc: changes the help message for the symbol \kbd{sym}. The string \var{str}
is expanded on the spot and stored as the online help for \kbd{sym}. It is
recommended to document global variables and user functions in this way,
although \kbd{gp} will not protest if you don't.
You can attach a help text to an alias, but it will never be
shown: aliases are expanded by the \kbd{?} help operator and we get the help
of the symbol the alias points to. Nothing prevents you from modifying the
help of built-in PARI functions. But if you do, we would like to hear why you
needed it!
Without \tet{addhelp}, the standard help for user functions consists of its
name and definition.
\bprog
gp> f(x) = x^2;
gp> ?f
f =
(x)->x^2
@eprog\noindent Once addhelp is applied to $f$, the function code is no
longer included. It can still be consulted by typing the function name:
\bprog
gp> addhelp(f, "Square")
gp> ?f
Square
gp> f
%2 = (x)->x^2
@eprog
Function: addprimes
Class: basic
Section: number_theoretical
C-Name: addprimes
Prototype: DG
Help: addprimes({x=[]}): add primes in the vector x to the prime table to
be used in trial division. x may also be a single integer. Composite
"primes" are NOT allowed.
Doc: adds the integers contained in the
vector $x$ (or the single integer $x$) to a special table of
``user-defined primes'', and returns that table. Whenever \kbd{factor} is
subsequently called, it will trial divide by the elements in this table.
If $x$ is empty or omitted, just returns the current list of extra
primes.
The entries in $x$ must be primes: there is no internal check, even if
the \tet{factor_proven} default is set. To remove primes from the list use
\kbd{removeprimes}.
Function: agm
Class: basic
Section: transcendental
C-Name: agm
Prototype: GGp
Help: agm(x,y): arithmetic-geometric mean of x and y.
Doc: arithmetic-geometric mean of $x$ and $y$. In the
case of complex or negative numbers, the optimal AGM is returned
(the largest in absolute value over all choices of the signs of the square
roots). $p$-adic or power series arguments are also allowed. Note that
a $p$-adic agm exists only if $x/y$ is congruent to 1 modulo $p$ (modulo
16 for $p=2$). $x$ and $y$ cannot both be vectors or matrices.
Function: alarm
Class: basic
Section: programming/specific
C-Name: gp_alarm
Prototype: D0,L,DE
Help: alarm({s = 0},{code}): if code is omitted, trigger an "e_ALARM"
exception after s seconds, cancelling any previously set alarm; stop a pending
alarm if s = 0 or is omitted. Otherwise, evaluate code, aborting after s
seconds.
Doc: if \var{code} is omitted, trigger an \var{e\_ALARM} exception after $s$
seconds, cancelling any previously set alarm; stop a pending alarm if $s =
0$ or is omitted.
Otherwise, if $s$ is positive, the function evaluates \var{code},
aborting after $s$ seconds. The return value is the value of \var{code} if
it ran to completion before the alarm timeout, and a \typ{ERROR} object
otherwise.
\bprog
? p = nextprime(10^25); q = nextprime(10^26); N = p*q;
? E = alarm(1, factor(N));
? type(E)
%3 = "t_ERROR"
? print(E)
%4 = error("alarm interrupt after 964 ms.")
? alarm(10, factor(N)); \\ enough time
%5 =
[ 10000000000000000000000013 1]
[100000000000000000000000067 1]
@eprog\noindent Here is a more involved example: the function
\kbd{timefact(N,sec)} below tries to factor $N$ and gives up after \var{sec}
seconds, returning a partial factorisation.
\bprog
\\ Time-bounded partial factorization
default(factor_add_primes,1);
timefact(N,sec)=
{
F = alarm(sec, factor(N));
if (type(F) == "t_ERROR", factor(N, 2^24), F);
}
@eprog\noindent We either return the factorization directly, or replace the
\typ{ERROR} result by a simple bounded factorization \kbd{factor(N, 2\pow 24)}.
Note the \tet{factor_add_primes} trick: any prime larger than $2^{24}$
discovered while attempting the initial factorization is stored and
remembered. When the alarm rings, the subsequent bounded factorization finds
it right away.
\misctitle{Caveat} It is not possible to set a new alarm \emph{within}
another \kbd{alarm} code: the new timer erases the parent one.
Function: algabsdim
Class: basic
Section: algebras
C-Name: algabsdim
Prototype: lG
Help: algabsdim(al): dimension of the algebra al over its prime subfield.
Doc: Given an algebra \var{al} output by \tet{alginit} or by
\tet{algtableinit}, returns the dimension of \var{al} over its prime subfield
($\Q$ or $\F_p$).
\bprog
? nf = nfinit(y^3-y+1);
? A = alginit(nf, [-1,-1]);
? algabsdim(A)
%3 = 12
@eprog
Function: algadd
Class: basic
Section: algebras
C-Name: algadd
Prototype: GGG
Help: algadd(al,x,y): element x+y in al.
Doc: Given two elements $x$ and $y$ in \var{al}, computes their sum $x+y$ in
the algebra~\var{al}.
\bprog
? A = alginit(nfinit(y),[-1,1]);
? algadd(A,[1,0]~,[1,2]~)
%2 = [2, 2]~
@eprog
Also accepts matrices with coefficients in \var{al}.
Function: algalgtobasis
Class: basic
Section: algebras
C-Name: algalgtobasis
Prototype: GG
Help: algalgtobasis(al,x): transforms the element x of the algebra al into a
column vector on the integral basis of al.
Doc: Given an element \var{x} in the central simple algebra \var{al} output
by \tet{alginit}, transforms it to a column vector on the integral basis of
\var{al}. This is the inverse function of \tet{algbasistoalg}.
\bprog
? A = alginit(nfinit(y^2-5),[2,y]);
? algalgtobasis(A,[y,1]~)
%2 = [0, 2, 0, -1, 2, 0, 0, 0]~
? algbasistoalg(A,algalgtobasis(A,[y,1]~))
%3 = [Mod(Mod(y, y^2 - 5), x^2 - 2), 1]~
@eprog
Function: algaut
Class: basic
Section: algebras
C-Name: algaut
Prototype: mG
Help: algaut(al): the stored automorphism of the splitting field of the
cyclic algebra al.
Doc: Given a cyclic algebra $\var{al} = (L/K,\sigma,b)$ output by
\tet{alginit}, returns the automorphism $\sigma$.
\bprog
? nf = nfinit(y);
? p = idealprimedec(nf,7)[1];
? p2 = idealprimedec(nf,11)[1];
? A = alginit(nf,[3,[[p,p2],[1/3,2/3]],[0]]);
? algaut(A)
%5 = -1/3*x^2 + 1/3*x + 26/3
@eprog
Function: algb
Class: basic
Section: algebras
C-Name: algb
Prototype: mG
Help: algb(al): the element b of the center of the cyclic algebra al used
to define it.
Doc: Given a cyclic algebra $\var{al} = (L/K,\sigma,b)$ output by
\tet{alginit}, returns the element $b\in K$.
\bprog
nf = nfinit(y);
? p = idealprimedec(nf,7)[1];
? p2 = idealprimedec(nf,11)[1];
? A = alginit(nf,[3,[[p,p2],[1/3,2/3]],[0]]);
? algb(A)
%5 = Mod(-77, y)
@eprog
Function: algbasis
Class: basic
Section: algebras
C-Name: algbasis
Prototype: mG
Help: algbasis(al): basis of the stored order of the central simple algebra al.
Doc: Given an central simple algebra \var{al} output by \tet{alginit}, returns
a $\Z$-basis of the order~${\cal O}_0$ stored in \var{al} with respect to the
natural order in \var{al}. It is a maximal order if one has been computed.
\bprog
A = alginit(nfinit(y), [-1,-1]);
? algbasis(A)
%2 =
[1 0 0 1/2]
[0 1 0 1/2]
[0 0 1 1/2]
[0 0 0 1/2]
@eprog
Function: algbasistoalg
Class: basic
Section: algebras
C-Name: algbasistoalg
Prototype: GG
Help: algbasistoalg(al,x): transforms the column vector x on the integral
basis of al into an element of al in algebraic form.
Doc: Given an element \var{x} in the central simple algebra \var{al} output
by \tet{alginit}, transforms it to its algebraic representation in \var{al}.
This is the inverse function of \tet{algalgtobasis}.
\bprog
? A = alginit(nfinit(y^2-5),[2,y]);
? z = algbasistoalg(A,[0,1,0,0,2,-3,0,0]~);
? liftall(z)
%3 = [(-1/2*y - 2)*x + (-1/4*y + 5/4), -3/4*y + 7/4]~
? algalgtobasis(A,z)
%4 = [0, 1, 0, 0, 2, -3, 0, 0]~
@eprog
Function: algcenter
Class: basic
Section: algebras
C-Name: algcenter
Prototype: mG
Help: algcenter(al): center of the algebra al.
Doc: If \var{al} is a table algebra output by \tet{algtableinit}, returns a
basis of the center of the algebra~\var{al} over its prime field ($\Q$ or
$\F_p$). If \var{al} is a central simple algebra output by \tet{alginit},
returns the center of~\var{al}, which is stored in \var{al}.
A simple example: the $2\times 2$ upper triangular matrices over $\Q$,
generated by $I_2$, $a = \kbd{[0,1;0,0]}$ and $b = \kbd{[0,0;0,1]}$,
such that $a^2 = 0$, $ab = a$, $ba = 0$, $b^2 = b$: the diagonal matrices
form the center.
\bprog
? mt = [matid(3),[0,0,0;1,0,1;0,0,0],[0,0,0;0,0,0;1,0,1]];
? A = algtableinit(mt);
? algcenter(A) \\ = (I_2)
%3 =
[1]
[0]
[0]
@eprog
An example in the central simple case:
\bprog
? nf = nfinit(y^3-y+1);
? A = alginit(nf, [-1,-1]);
? algcenter(A).pol
%3 = y^3 - y + 1
@eprog
Function: algcentralproj
Class: basic
Section: algebras
C-Name: alg_centralproj
Prototype: GGD0,L,
Help: algcentralproj(al,z,{maps=0}): projections of the algebra al on the
orthogonal central idempotents z[i].
Doc: Given a table algebra \var{al} output by \tet{algtableinit} and a
\typ{VEC} $\var{z}=[z_1,\dots,z_n]$ of orthogonal central idempotents,
returns a \typ{VEC} $[al_1,\dots,al_n]$ of algebras such that
$al_i = z_i\, al$. If $\var{maps}=1$, each $al_i$ is a \typ{VEC}
$[quo,proj,lift]$ where \var{quo} is the quotient algebra, \var{proj} is a
\typ{MAT} representing the projection onto this quotient and \var{lift} is a
\typ{MAT} representing a lift.
A simple example: $\F_2\oplus \F_4$, generated by~$1=(1,1)$, $e=(1,0)$
and~$x$ such that~$x^2+x+1=0$. We have~$e^2=e$, $x^2=x+1$ and~$ex=0$.
\bprog
? mt = [matid(3), [0,0,0; 1,1,0; 0,0,0], [0,0,1; 0,0,0; 1,0,1]];
? A = algtableinit(mt,2);
? e = [0,1,0]~;
? e2 = algsub(A,[1,0,0]~,e);
? [a,a2] = algcentralproj(A,[e,e2]);
? algdim(a)
%6 = 1
? algdim(a2)
%7 = 2
@eprog
Function: algchar
Class: basic
Section: algebras
C-Name: algchar
Prototype: mG
Help: algchar(al): characteristic of the algebra al.
Doc: Given an algebra \var{al} output by \tet{alginit} or \tet{algtableinit},
returns the characteristic of \var{al}.
\bprog
? mt = [matid(3), [0,0,0; 1,1,0; 0,0,0], [0,0,1; 0,0,0; 1,0,1]];
? A = algtableinit(mt,13);
? algchar(A)
%3 = 13
@eprog
Function: algcharpoly
Class: basic
Section: algebras
C-Name: algcharpoly
Prototype: GGDn
Help: algcharpoly(al,b,{v='x}): (reduced) characteristic polynomial of b in
\var{al}, with respect to the variable $v$.
Doc: Given an element $b$ in \var{al}, returns its characteristic polynomial
as a polynomial in the variable $v$. If \var{al} is a table algebra output
by \tet{algtableinit}, returns the absolute characteristic polynomial of
\var{b}, which is an element of $\F_p[v]$ or~$\Q[v]$; if \var{al} is a
central simple algebra output by \tet{alginit}, returns the reduced
characteristic polynomial of \var{b}, which is an element of $K[v]$ where~$K$
is the center of \var{al}.
\bprog
? al = alginit(nfinit(y), [-1,-1]); \\ (-1,-1)_Q
? algcharpoly(al, [0,1]~)
%2 = x^2 + 1
@eprog
Also accepts a square matrix with coefficients in \var{al}.
Function: algdecomposition
Class: basic
Section: algebras
C-Name: alg_decomposition
Prototype: G
Help: algdecomposition(al): semisimple decomposition of the algebra al.
Doc: \var{al} being a table algebra output by \tet{algtableinit}, returns
$[J,[al_1,\dots,al_n]]$ where $J$ is a basis of the Jacobson radical of
\var{al} and $al_1,\dots,al_n$ are the simple factors of the semisimple
algebra $al/J$.
Function: algdegree
Class: basic
Section: algebras
C-Name: algdegree
Prototype: lG
Help: algdegree(al): degree of the central simple algebra al.
Doc: Given a central simple algebra \var{al} output by \tet{alginit}, returns
the degree of \var{al}.
\bprog
? nf = nfinit(y^3-y+1);
? A = alginit(nf, [-1,-1]);
? algdegree(A)
%3 = 2
@eprog
Function: algdep
Class: basic
Section: linear_algebra
C-Name: algdep0
Prototype: GLD0,L,
Help: algdep(z,k,{flag=0}): algebraic relations up to degree n of z, using
lindep([1,z,...,z^(k-1)], flag).
Doc: \sidx{algebraic dependence}
$z$ being real/complex, or $p$-adic, finds a polynomial (in the variable
\kbd{'x}) of degree at most
$k$, with integer coefficients, having $z$ as approximate root. Note that the
polynomial which is obtained is not necessarily the ``correct'' one. In fact
it is not even guaranteed to be irreducible. One can check the closeness
either by a polynomial evaluation (use \tet{subst}), or by computing the
roots of the polynomial given by \kbd{algdep} (use \tet{polroots} or
\tet{polrootspadic}).
Internally, \tet{lindep}$([1,z,\ldots,z^k], \fl)$ is used. A non-zero value of
$\fl$ may improve on the default behavior if the input number is known to a
\emph{huge} accuracy, and you suspect the last bits are incorrect: if $\fl > 0$
the computation is done with an accuracy of $\fl$ decimal digits; to get
meaningful results, the parameter $\fl$ should be smaller than the number of
correct decimal digits in the input.
But default values are usually sufficient, so try without $\fl$ first:
\bprog
? \p200
? z = 2^(1/6)+3^(1/5);
? algdep(z, 30); \\ right in 280ms
? algdep(z, 30, 100); \\ wrong in 169ms
? algdep(z, 30, 170); \\ right in 288ms
? algdep(z, 30, 200); \\ wrong in 320ms
? \p250
? z = 2^(1/6)+3^(1/5); \\ recompute to new, higher, accuracy !
? algdep(z, 30); \\ right in 329ms
? algdep(z, 30, 200); \\ right in 324ms
? \p500
? algdep(2^(1/6)+3^(1/5), 30); \\ right in 677ms
? \p1000
? algdep(2^(1/6)+3^(1/5), 30); \\ right in 1.5s
@eprog\noindent
The changes in \kbd{realprecision} only affect the quality of the
initial approximation to $2^{1/6} + 3^{1/5}$, \kbd{algdep} itself uses
exact operations. The size of its operands depend on the accuracy of the
input of course: more accurate input means slower operations.
Proceeding by increments of 5 digits of accuracy, \kbd{algdep} with default
flag produces its first correct result at 195 digits, and from then on a
steady stream of correct results:
\bprog
\\ assume T contains the correct result, for comparison
forstep(d=100, 250, 5, localprec(d);\
print(d, " ", algdep(2^(1/6)+3^(1/5),30) == T))
@eprog
The above example is the test case studied in a 2000 paper by Borwein and
Lisonek: Applications of integer relation algorithms, \emph{Discrete Math.},
{\bf 217}, p.~65--82. The version of PARI tested there was 1.39, which
succeeded reliably from precision 265 on, in about 200 as much time as the
current version.
Variant: Also available is \fun{GEN}{algdep}{GEN z, long k} ($\fl=0$).
Function: algdim
Class: basic
Section: algebras
C-Name: algdim
Prototype: lG
Help: algdim(al): dimension of the algebra al.
Doc: Given a central simple algebra \var{al} output by \tet{alginit}, returns
the dimension of \var{al} over its center. Given a table algebra \var{al}
output by \tet{algtableinit}, returns the dimension of \var{al} over its prime
subfield ($\Q$ or $\F_p$).
\bprog
? nf = nfinit(y^3-y+1);
? A = alginit(nf, [-1,-1]);
? algdim(A)
%3 = 4
@eprog
Function: algdisc
Class: basic
Section: algebras
C-Name: algdisc
Prototype: G
Help: algdisc(al): discriminant of the stored order of the algebra al.
Doc: Given a central simple algebra \var{al} output by \tet{alginit}, computes
the discriminant of the order ${\cal O}_0$ stored in \var{al}, that is the
determinant of the trace form $\rm{Tr} : {\cal O}_0\times {\cal O}_0 \to \Z$.
\bprog
? nf = nfinit(y^2-5);
? A = alginit(nf, [-3,1-y]);
? [PR,h] = alghassef(A);
%3 = [[[2, [2, 0]~, 1, 2, 1], [3, [3, 0]~, 1, 2, 1]], Vecsmall([0, 1])]
? n = algdegree(A);
? D = algabsdim(A);
? h = vector(#h, i, n - gcd(n,h[i]));
? n^D * nf.disc^(n^2) * idealnorm(nf, idealfactorback(nf,PR,h))^n
%4 = 12960000
? algdisc(A)
%5 = 12960000
@eprog
Function: algdivl
Class: basic
Section: algebras
C-Name: algdivl
Prototype: GGG
Help: algdivl(al,x,y): element x\y in al.
Doc: Given two elements $x$ and $y$ in \var{al}, computes their left quotient
$x\backslash y$ in the algebra \var{al}: an element $z$ such that $xz=y$ (such
an element is not unique when $x$ is a zerodivisor). If~$x$ is invertible, this
is the same as $x^{-1}y$. Assumes that $y$ is left divisible by $x$ (i.e. that
$z$ exists). Also accepts matrices with coefficients in~\var{al}.
Function: algdivr
Class: basic
Section: algebras
C-Name: algdivr
Prototype: GGG
Help: algdivr(al,x,y): element x/y in al.
Doc: Given two elements $x$ and $y$ in \var{al}, return $xy^{-1}$. Also accepts
matrices with coefficients in \var{al}.
Function: alggroup
Class: basic
Section: algebras
C-Name: alggroup
Prototype: GDG
Help: alggroup(gal, {p=0}): constructs the group algebra of gal over Q (resp. Fp).
Doc: initialize the group algebra~$K[G]$ over~$K=\Q$ ($p$ omitted) or~$\F_p$
where~$G$ is the underlying group of the \kbd{galoisinit} structure~\var{gal}.
The input~\var{gal} is also allowed to be a \typ{VEC} of permutations that is
closed under products.
Example:
\bprog
? K = nfsplitting(x^3-x+1);
? gal = galoisinit(K);
? al = alggroup(gal);
? algissemisimple(al)
%4 = 1
? G = [Vecsmall([1,2,3]), Vecsmall([1,3,2])];
? al2 = alggroup(G, 2);
? algissemisimple(al2)
%8 = 0
@eprog
Function: alghasse
Class: basic
Section: algebras
C-Name: alghasse
Prototype: GG
Help: alghasse(al,pl): the hasse invariant of the central simple algebra al at
the place pl.
Doc: Given a central simple algebra \var{al} output by \tet{alginit} and a prime
ideal or an integer between $1$ and $r_1+r_2$, returns a \typ{FRAC} $h$ : the
local Hasse invariant of \var{al} at the place specified by \var{pl}.
\bprog
? nf = nfinit(y^2-5);
? A = alginit(nf, [-1,y]);
? alghasse(A, 1)
%3 = 1/2
? alghasse(A, 2)
%4 = 0
? alghasse(A, idealprimedec(nf,2)[1])
%5 = 1/2
? alghasse(A, idealprimedec(nf,5)[1])
%6 = 0
@eprog
Function: alghassef
Class: basic
Section: algebras
C-Name: alghassef
Prototype: mG
Help: alghassef(al): the hasse invariant of the central simple algebra al at finite places.
Doc: Given a central simple algebra \var{al} output by \tet{alginit}, returns
a \typ{VEC} $[\kbd{PR}, h_f]$ describing the local Hasse invariants at the
finite places of the center: \kbd{PR} is a \typ{VEC} of primes and $h_f$ is a
\typ{VECSMALL} of integers modulo the degree $d$ of \var{al}.
\bprog
? nf = nfinit(y^2-5);
? A = alginit(nf, [-1,2*y-1]);
? [PR,hf] = alghassef(A);
? PR
%4 = [[19, [10, 2]~, 1, 1, [-8, 2; 2, -10]], [2, [2, 0]~, 1, 2, 1]]
? hf
%5 = Vecsmall([1, 0])
@eprog
Function: alghassei
Class: basic
Section: algebras
C-Name: alghassei
Prototype: mG
Help: alghassei(al): the hasse invariant of the central simple algebra al
at infinite places.
Doc: Given a central simple algebra \var{al} output by \tet{alginit}, returns
a \typ{VECSMALL} $h_i$ of $r_1$ integers modulo the degree $d$ of \var{al},
where $r_1$ is the number of real places of the center: the local Hasse
invariants of \var{al} at infinite places.
\bprog
? nf = nfinit(y^2-5);
? A = alginit(nf, [-1,y]);
? alghassei(A)
%3 = Vecsmall([1, 0])
@eprog
Function: algindex
Class: basic
Section: algebras
C-Name: algindex
Prototype: lGDG
Help: algindex(al,{pl}): the index of the central simple algebra al. If pl is
set, it should be a prime ideal of the center or an integer between 1 and
r1+r2, and in that case return the local index at the place pl instead.
Doc: Return the index of the central simple algebra~$A$ over~$K$ (as output by
alginit), that is the degree~$e$ of the unique central division algebra~$D$
over $K$ such that~$A$ is isomorphic to some matrix algebra~$M_d(D)$. If
\var{pl} is set, it should be a prime ideal of~$K$ or an integer between~$1$
and~$r_1+r_2$, and in that case return the local index at the place \var{pl}
instead.
\bprog
? nf = nfinit(y^2-5);
? A = alginit(nf, [-1,y]);
? algindex(A, 1)
%3 = 2
? algindex(A, 2)
%4 = 1
? algindex(A, idealprimedec(nf,2)[1])
%5 = 2
? algindex(A, idealprimedec(nf,5)[1])
%6 = 1
? algindex(A)
%7 = 2
@eprog
Function: alginit
Class: basic
Section: algebras
C-Name: alginit
Prototype: GGDnD1,L,
Help: alginit(B, C, {v}, {flag = 1}): initialize the central simple algebra
defined by data B, C. If flag = 1, compute a maximal order.
Doc: initialize the central simple algebra defined by data $B$, $C$ and
variable $v$, as follows.
\item (multiplication table) $B$ is the base number field $K$ in \tet{nfinit}
form, $C$ is a ``multiplication table'' over $K$.
As a $K$-vector space, the algebra is generated by a basis
$(e_1 = 1,\dots, e_n)$; the table is given as a \typ{VEC} of $n$ matrices in
$M_n(K)$, giving the left multiplication by the basis elements $e_i$, in the
given basis.
Assumes that $e_1= 1$, that the multiplication table is integral, and that
$K[e_1,\dots,e_n]$ describes a central simple algebra over $K$.
\bprog
{ m_i = [0,-1,0, 0;
1, 0,0, 0;
0, 0,0,-1;
0, 0,1, 0];
m_j = [0, 0,-1,0;
0, 0, 0,1;
1, 0, 0,0;
0,-1, 0,0];
m_k = [0, 0, 0, 0;
0, 0,-1, 0;
0, 1, 0, 0;
1, 0, 0,-1];
A = alginit(nfinit(y), [matid(4), m_i,m_j,m_k], 0); }
@eprog represents (in a complicated way) the quaternion algebra $(-1,-1)_\Q$.
See below for a simpler solution.
\item (cyclic algebra) $B$ is an \kbd{rnf} structure attached to a cyclic
number field extension $L/K$ of degree $d$, $C$ is a \typ{VEC}
\kbd{[sigma,b]} with 2 components: \kbd{sigma} is a \typ{POLMOD} representing
an automorphism generating $\text{Gal}(L/K)$, $b$ is an element in $K^*$. This
represents the cyclic algebra~$(L/K,\sigma,b)$. Currently the element $b$ has
to be integral.
\bprog
? Q = nfinit(y); T = polcyclo(5, 'x); F = rnfinit(Q, T);
? A = alginit(F, [Mod(x^2,T), 3]);
@eprog defines the cyclic algebra $(L/\Q, \sigma, 3)$, where
$L = \Q(\zeta_5)$ and $\sigma:\zeta\mapsto\zeta^2$ generates
$\text{Gal}(L/\Q)$.
\item (quaternion algebra, special case of the above) $B$ is an \kbd{nf}
structure attached to a number field $K$, $C = [a,b]$ is a vector
containing two elements of $K^*$ with $a$ not a square in $K$, returns the quaternion algebra $(a,b)_K$.
The variable $v$ (\kbd{'x} by default) must have higher priority than the
variable of $K$\kbd{.pol} and is used to represent elements in the splitting
field $L = K[x]/(x^2-a)$.
\bprog
? Q = nfinit(y); A = alginit(Q, [-1,-1]); \\@com $(-1,-1)_\Q$
@eprog
\item (algebra/$K$ defined by local Hasse invariants)
$B$ is an \kbd{nf} structure attached to a number field $K$,
$C = [d, [\kbd{PR},h_f], h_i]$ is a triple
containing an integer $d > 1$, a pair $[\kbd{PR}, h_f]$ describing the
Hasse invariants at finite places, and $h_i$ the Hasse invariants
at archimedean (real) places. A local Hasse invariant belongs to $(1/d)\Z/\Z
\subset \Q/\Z$, and is given either as a \typ{FRAC} (lift to $(1/d)\Z$),
a \typ{INT} or \typ{INTMOD} modulo $d$ (lift to $\Z/d\Z$); a whole vector
of local invariants can also be given as a \typ{VECSMALL}, whose
entries are handled as \typ{INT}s. \kbd{PR} is a list of prime ideals
(\kbd{prid} structures), and $h_f$ is a vector of the same length giving the
local invariants at those maximal ideals. The invariants at infinite real
places are indexed by the real roots $K$\kbd{.roots}: if the Archimedean
place $v$ is attached to the $j$-th root, the value of
$h_v$ is given by $h_i[j]$, must be $0$ or $1/2$ (or~$d/2$ modulo~$d$), and
can be nonzero only if~$d$ is even.
By class field theory, provided the local invariants $h_v$ sum to $0$, up
to Brauer equivalence, there is a unique central simple algebra over $K$
with given local invariants and trivial invariant elsewhere. In particular,
up to isomorphism, there is a unique such algebra $A$ of degree $d$.
We realize $A$ as a cyclic algebra through class field theory. The variable $v$
(\kbd{'x} by default) must have higher priority than the variable of
$K$\kbd{.pol} and is used to represent elements in the (cyclic) splitting
field extension $L/K$ for $A$.
\bprog
? nf = nfinit(y^2+1);
? PR = idealprimedec(nf,5); #PR
%2 = 2
? hi = [];
? hf = [PR, [1/3,-1/3]];
? A = alginit(nf, [3,hf,hi]);
? algsplittingfield(A).pol
%6 = x^3 - 21*x + 7
@eprog
\item (matrix algebra, toy example) $B$ is an \kbd{nf} structure attached
to a number field $K$, $C = d$ is a positive integer. Returns a cyclic
algebra isomorphic to the matrix algebra $M_d(K)$.
In all cases, this function computes a maximal order for the algebra by default,
which may require a lot of time. Setting $\fl = 0$ prevents this computation.
The pari object representing such an algebra $A$ is a \typ{VEC} with the
following data:
\item A splitting field $L$ of $A$ of the same degree over $K$ as $A$, in
\kbd{rnfinit} format, accessed with \kbd{algsplittingfield}.
\item The same splitting field $L$ in \kbd{nfinit} format.
\item The Hasse invariants at the real places of $K$, accessed with
\kbd{alghassei}.
\item The Hasse invariants of $A$ at the finite primes of $K$ that ramify in
the natural order of $A$, accessed with \kbd{alghassef}.
\item A basis of an order ${\cal O}_0$ expressed on the basis of the natural
order, accessed with \kbd{algbasis}.
\item A basis of the natural order expressed on the basis of ${\cal O}_0$,
accessed with \kbd{alginvbasis}.
\item The left multiplication table of ${\cal O}_0$ on the previous basis,
accessed with \kbd{algmultable}.
\item The characteristic of $A$ (always $0$), accessed with \kbd{algchar}.
\item The absolute traces of the elements of the basis of ${\cal O}_0$.
\item If $A$ was constructed as a cyclic algebra~$(L/K,\sigma,b)$ of degree
$d$, a \typ{VEC} $[\sigma,\sigma^2,\dots,\sigma^{d-1}]$. The function
\kbd{algaut} returns $\sigma$.
\item If $A$ was constructed as a cyclic algebra~$(L/K,\sigma,b)$, the
element $b$, accessed with \kbd{algb}.
\item If $A$ was constructed with its multiplication table $mt$ over $K$,
the \typ{VEC} of \typ{MAT} $mt$, accessed with \kbd{algrelmultable}.
\item If $A$ was constructed with its multiplication table $mt$ over $K$,
a \typ{VEC} with three components: a \typ{COL} representing an element of $A$
generating the splitting field $L$ as a maximal subfield of $A$, a \typ{MAT}
representing an $L$-basis ${\cal B}$ of $A$ expressed on the $\Z$-basis of
${\cal O}_0$, and a \typ{MAT} representing the $\Z$-basis of ${\cal O}_0$
expressed on ${\cal B}$. This data is accessed with \kbd{algsplittingdata}.
Function: alginv
Class: basic
Section: algebras
C-Name: alginv
Prototype: GG
Help: alginv(al,x): element 1/x in al.
Doc: Given an element $x$ in \var{al}, computes its inverse $x^{-1}$ in the
algebra \var{al}. Assumes that $x$ is invertible.
\bprog
? A = alginit(nfinit(y), [-1,-1]);
? alginv(A,[1,1,0,0]~)
%2 = [1/2, 1/2, 0, 0]~
@eprog
Also accepts matrices with coefficients in \var{al}.
Function: alginvbasis
Class: basic
Section: algebras
C-Name: alginvbasis
Prototype: mG
Help: alginvbasis(al): basis of the natural order of the central simple algebra
al in terms of the stored order.
Doc: Given an central simple algebra \var{al} output by \tet{alginit}, returns
a $\Z$-basis of the natural order in \var{al} with respect to the
order~${\cal O}_0$ stored in \var{al}.
\bprog
A = alginit(nfinit(y), [-1,-1]);
? alginvbasis(A)
%2 =
[1 0 0 -1]
[0 1 0 -1]
[0 0 1 -1]
[0 0 0 2]
@eprog
Function: algisassociative
Class: basic
Section: algebras
C-Name: algisassociative
Prototype: iGD0,G,
Help: algisassociative(mt,p=0): true (1) if the multiplication table mt is
suitable for algtableinit(mt,p), false (0) otherwise.
Doc: Returns 1 if the multiplication table \kbd{mt} is suitable for
\kbd{algtableinit(mt,p)}, 0 otherwise. More precisely, \kbd{mt} should be
a \typ{VEC} of $n$ matrices in $M_n(K)$, giving the left multiplications
by the basis elements $e_1, \dots, e_n$ (structure constants).
We check whether the first basis element $e_1$ is $1$ and $e_i(e_je_k) =
(e_ie_j)e_k$ for all $i,j,k$.
\bprog
? mt = [matid(3),[0,0,0;1,0,1;0,0,0],[0,0,0;0,0,0;1,0,1]];
? algisassociative(mt)
%2 = 1
@eprog
May be used to check a posteriori an algebra: we also allow \kbd{mt} as
output by \tet{algtableinit} ($p$ is ignored in this case).
Function: algiscommutative
Class: basic
Section: algebras
C-Name: algiscommutative
Prototype: iG
Help: algiscommutative(al): test whether the algebra al is commutative.
Doc: \var{al} being a table algebra output by \tet{algtableinit} or a central
simple algebra output by \tet{alginit}, tests whether the algebra \var{al} is
commutative.
\bprog
? mt = [matid(3),[0,0,0;1,0,1;0,0,0],[0,0,0;0,0,0;1,0,1]];
? A = algtableinit(mt);
? algiscommutative(A)
%3 = 0
? mt = [matid(3), [0,0,0; 1,1,0; 0,0,0], [0,0,1; 0,0,0; 1,0,1]];
? A = algtableinit(mt,2);
? algiscommutative(A)
%6 = 1
@eprog
Function: algisdivision
Class: basic
Section: algebras
C-Name: algisdivision
Prototype: iGDG
Help: algisdivision(al,{pl}): test whether the central simple algebra al is a
division algebra. If pl is set, it should be a prime ideal of the center or an
integer between 1 and r1+r2, and in that case test whether al is locally a
division algebra at the place pl instead.
Doc: Given a central simple algebra \var{al} output by \tet{alginit}, test
whether \var{al} is a division algebra. If \var{pl} is set, it should be a
prime ideal of~$K$ or an integer between~$1$ and~$r_1+r_2$, and in that case
test whether \var{al} is locally a division algebra at the place \var{pl}
instead.
\bprog
? nf = nfinit(y^2-5);
? A = alginit(nf, [-1,y]);
? algisdivision(A, 1)
%3 = 1
? algisdivision(A, 2)
%4 = 0
? algisdivision(A, idealprimedec(nf,2)[1])
%5 = 1
? algisdivision(A, idealprimedec(nf,5)[1])
%6 = 0
? algisdivision(A)
%7 = 1
@eprog
Function: algisdivl
Class: basic
Section: algebras
C-Name: algisdivl
Prototype: iGGGD&
Help: algisdivl(al,x,y,{&z}): tests whether y is left divisible by x and sets z
to the left quotient x\y.
Doc: Given two elements $x$ and $y$ in \var{al}, tests whether $y$ is left
divisible by $x$, that is whether there exists~$z$ in \var{al} such
that~$xz=y$, and sets $z$ to this element if it exists.
\bprog
? A = alginit(nfinit(y), [-1,1]);
? algisdivl(A,[x+2,-x-2]~,[x,1]~)
%2 = 0
? algisdivl(A,[x+2,-x-2]~,[-x,x]~,&z)
%3 = 1
? z
%4 = [Mod(-2/5*x - 1/5, x^2 + 1), 0]~
@eprog
Also accepts matrices with coefficients in \var{al}.
Function: algisinv
Class: basic
Section: algebras
C-Name: algisinv
Prototype: iGGD&
Help: algisinv(al,x,{&ix}): tests whether x is invertible and sets ix to the
inverse of x.
Doc: Given an element $x$ in \var{al}, tests whether $x$ is invertible, and sets
$ix$ to the inverse of $x$.
\bprog
? A = alginit(nfinit(y), [-1,1]);
? algisinv(A,[-1,1]~)
%2 = 0
? algisinv(A,[1,2]~,&ix)
%3 = 1
? ix
%4 = [Mod(Mod(-1/3, y), x^2 + 1), Mod(Mod(2/3, y), x^2 + 1)]~
@eprog
Also accepts matrices with coefficients in \var{al}.
Function: algisramified
Class: basic
Section: algebras
C-Name: algisramified
Prototype: iGDG
Help: algisramified(al,{pl}): test whether the central simple algebra al is
ramified, i.e. not isomorphic to a matrix ring over its center. If pl is set,
it should be a prime ideal of the center or an integer between 1 and r1+r2, and
in that case test whether al is locally ramified at the place pl instead.
Doc: Given a central simple algebra \var{al} output by \tet{alginit}, test
whether \var{al} is ramified, i.e. not isomorphic to a matrix algebra over its
center. If \var{pl} is set, it should be a prime ideal of~$K$ or an integer
between~$1$ and~$r_1+r_2$, and in that case test whether \var{al} is locally
ramified at the place \var{pl} instead.
\bprog
? nf = nfinit(y^2-5);
? A = alginit(nf, [-1,y]);
? algisramified(A, 1)
%3 = 1
? algisramified(A, 2)
%4 = 0
? algisramified(A, idealprimedec(nf,2)[1])
%5 = 1
? algisramified(A, idealprimedec(nf,5)[1])
%6 = 0
? algisramified(A)
%7 = 1
@eprog
Function: algissemisimple
Class: basic
Section: algebras
C-Name: algissemisimple
Prototype: iG
Help: algissemisimple(al): test whether the algebra al is semisimple.
Doc: \var{al} being a table algebra output by \tet{algtableinit} or a central
simple algebra output by \tet{alginit}, tests whether the algebra \var{al} is
semisimple.
\bprog
? mt = [matid(3),[0,0,0;1,0,1;0,0,0],[0,0,0;0,0,0;1,0,1]];
? A = algtableinit(mt);
? algissemisimple(A)
%3 = 0
? m_i=[0,-1,0,0;1,0,0,0;0,0,0,-1;0,0,1,0]; \\ quaternion algebra (-1,-1)
? m_j=[0,0,-1,0;0,0,0,1;1,0,0,0;0,-1,0,0];
? m_k=[0,0,0,-1;0,0,-1,0;0,1,0,0;1,0,0,0];
? mt = [matid(4), m_i, m_j, m_k];
? A = algtableinit(mt);
? algissemisimple(A)
%9 = 1
@eprog
Function: algissimple
Class: basic
Section: algebras
C-Name: algissimple
Prototype: iGD0,L,
Help: algissimple(al, {ss = 0}): test whether the algebra al is simple.
Doc: \var{al} being a table algebra output by \tet{algtableinit} or a central
simple algebra output by \tet{alginit}, tests whether the algebra \var{al} is
simple. If $\var{ss}=1$, assumes that the algebra~\var{al} is semisimple
without testing it.
\bprog
? mt = [matid(3),[0,0,0;1,0,1;0,0,0],[0,0,0;0,0,0;1,0,1]];
? A = algtableinit(mt); \\ matrices [*,*; 0,*]
? algissimple(A)
%3 = 0
? algissimple(A,1) \\ incorrectly assume that A is semisimple
%4 = 1
? m_i=[0,-1,0,0;1,0,0,0;0,0,0,-1;0,0,1,0];
? m_j=[0,0,-1,0;0,0,0,1;1,0,0,0;0,-1,0,0];
? m_k=[0,0,0,-1;0,0,b,0;0,1,0,0;1,0,0,0];
? mt = [matid(4), m_i, m_j, m_k];
? A = algtableinit(mt); \\ quaternion algebra (-1,-1)
? algissimple(A)
%10 = 1
? mt = [matid(3), [0,0,0; 1,1,0; 0,0,0], [0,0,1; 0,0,0; 1,0,1]];
? A = algtableinit(mt,2); \\ direct sum F_4+F_2
? algissimple(A)
%13 = 0
@eprog
Function: algissplit
Class: basic
Section: algebras
C-Name: algissplit
Prototype: iGDG
Help: algissplit(al,{pl}): test whether the central simple algebra al is
split, i.e. isomorphic to a matrix ring over its center. If pl is set, it
should be a prime ideal of the center or an integer between 1 and r1+r2, and in
that case test whether al is locally split at the place pl instead.
Doc: Given a central simple algebra \var{al} output by \tet{alginit}, test
whether \var{al} is split, i.e. isomorphic to a matrix algebra over its center.
If \var{pl} is set, it should be a prime ideal of~$K$ or an integer between~$1$
and~$r_1+r_2$, and in that case test whether \var{al} is locally split at the
place \var{pl} instead.
\bprog
? nf = nfinit(y^2-5);
? A = alginit(nf, [-1,y]);
? algissplit(A, 1)
%3 = 0
? algissplit(A, 2)
%4 = 1
? algissplit(A, idealprimedec(nf,2)[1])
%5 = 0
? algissplit(A, idealprimedec(nf,5)[1])
%6 = 1
? algissplit(A)
%7 = 0
@eprog
Function: alglathnf
Class: basic
Section: algebras
C-Name: alglathnf
Prototype: GG
Help: alglathnf(al,m): the lattice generated by the columns of m.
Doc: Given an algebra \var{al} and a square invertible matrix \var{m} with size
the dimension of \var{al}, returns the lattice generated by the columns of
\var{m}.
\bprog
? al = alginit(nfinit(y^2+7), [-1,-1]);
? a = [1,1,-1/2,1,1/3,-1,1,1]~;
? mt = algleftmultable(al,a);
? lat = alglathnf(al,mt);
? lat[2]
%5 = 1/6
@eprog
Function: algleftmultable
Class: basic
Section: algebras
C-Name: algleftmultable
Prototype: GG
Help: algleftmultable(al,x): left multiplication table of x.
Doc: Given an element \var{x} in \var{al}, computes its left multiplication
table. If \var{x} is given in basis form, returns its multiplication table on
the integral basis; if \var{x} is given in algebraic form, returns its
multiplication table on the basis corresponding to the algebraic form of
elements of \var{al}. In every case, if \var{x} is a \typ{COL} of length $n$,
then the output is a $n\times n$ \typ{MAT}.
Also accepts a square matrix with coefficients in \var{al}.
\bprog
? A = alginit(nfinit(y), [-1,-1]);
? algleftmultable(A,[0,1,0,0]~)
%2 =
[0 -1 1 0]
[1 0 1 1]
[0 0 1 1]
[0 0 -2 -1]
@eprog
Function: algmul
Class: basic
Section: algebras
C-Name: algmul
Prototype: GGG
Help: algmul(al,x,y): element x*y in al.
Doc: Given two elements $x$ and $y$ in \var{al}, computes their product $x*y$
in the algebra~\var{al}.
\bprog
? A = alginit(nfinit(y), [-1,-1]);
? algmul(A,[1,1,0,0]~,[0,0,2,1]~)
%2 = [2, 3, 5, -4]~
@eprog
Also accepts matrices with coefficients in \var{al}.
Function: algmultable
Class: basic
Section: algebras
C-Name: algmultable
Prototype: mG
Help: algmultable(al): multiplication table of al over its prime subfield.
Doc:
returns a multiplication table of \var{al} over its
prime subfield ($\Q$ or $\F_p$), as a \typ{VEC} of \typ{MAT}: the left
multiplication tables of basis elements. If \var{al} was output by
\tet{algtableinit}, returns the multiplication table used to define \var{al}.
If \var{al} was output by \tet{alginit}, returns the multiplication table of
the order~${\cal O}_0$ stored in \var{al}.
\bprog
? A = alginit(nfinit(y), [-1,-1]);
? M = algmultable(A);
? #M
%3 = 4
? M[1] \\ multiplication by e_1 = 1
%4 =
[1 0 0 0]
[0 1 0 0]
[0 0 1 0]
[0 0 0 1]
? M[2]
%5 =
[0 -1 1 0]
[1 0 1 1]
[0 0 1 1]
[0 0 -2 -1]
@eprog
Function: algneg
Class: basic
Section: algebras
C-Name: algneg
Prototype: GG
Help: algneg(al,x): element -x in al.
Doc: Given an element $x$ in \var{al}, computes its opposite $-x$ in the
algebra \var{al}.
\bprog
? A = alginit(nfinit(y), [-1,-1]);
? algneg(A,[1,1,0,0]~)
%2 = [-1, -1, 0, 0]~
@eprog
Also accepts matrices with coefficients in \var{al}.
Function: algnorm
Class: basic
Section: algebras
C-Name: algnorm
Prototype: GG
Help: algnorm(al,x): (reduced) norm of x.
Doc: Given an element \var{x} in \var{al}, computes its norm. If \var{al} is
a table algebra output by \tet{algtableinit}, returns the absolute norm of
\var{x}, which is an element of $\F_p$ of~$\Q$; if \var{al} is a central
simple algebra output by \tet{alginit}, returns the reduced norm of \var{x},
which is an element of the center of \var{al}.
\bprog
? mt = [matid(3), [0,0,0; 1,1,0; 0,0,0], [0,0,1; 0,0,0; 1,0,1]];
? A = algtableinit(mt,19);
? algnorm(A,[0,-2,3]~)
%3 = 18
@eprog
Also accepts a square matrix with coefficients in \var{al}.
Function: algpoleval
Class: basic
Section: algebras
C-Name: algpoleval
Prototype: GGG
Help: algpoleval(al,T,b): T in K[X] evaluate T(b) in al.
Doc: Given an element $b$ in \var{al} and a polynomial $T$ in $K[X]$,
computes $T(b)$ in \var{al}.
Function: algpow
Class: basic
Section: algebras
C-Name: algpow
Prototype: GGG
Help: algpow(al,x,n): element x^n in al.
Doc: Given an element $x$ in \var{al} and an integer $n$, computes the
power $x^n$ in the algebra \var{al}.
\bprog
? A = alginit(nfinit(y), [-1,-1]);
? algpow(A,[1,1,0,0]~,7)
%2 = [8, -8, 0, 0]~
@eprog
Also accepts a square matrix with coefficients in \var{al}.
Function: algprimesubalg
Class: basic
Section: algebras
C-Name: algprimesubalg
Prototype: G
Help: algprimesubalg(al): prime subalgebra of the positive characteristic,
semisimple algebra al.
Doc: \var{al} being the output of \tet{algtableinit} representing a semisimple
algebra of positive characteristic, returns a basis of the prime subalgebra
of~\var{al}. The prime subalgebra of~\var{al} is the subalgebra fixed by the
Frobenius automorphism of the center of \var{al}. It is abstractly isomorphic
to a product of copies of $\F_p$.
\bprog
? mt = [matid(3), [0,0,0; 1,1,0; 0,0,0], [0,0,1; 0,0,0; 1,0,1]];
? A = algtableinit(mt,2);
? algprimesubalg(A)
%3 =
[1 0]
[0 1]
[0 0]
@eprog
Function: algquotient
Class: basic
Section: algebras
C-Name: alg_quotient
Prototype: GGD0,L,
Help: algquotient(al,I,{flag=0}): quotient of the algebra al by the two-sided
ideal I.
Doc: \var{al} being a table algebra output by \tet{algtableinit} and \var{I}
being a basis of a two-sided ideal of \var{al} represented by a matrix,
returns the quotient $\var{al}/\var{I}$. When $\var{flag}=1$, returns a
\typ{VEC} $[\var{al}/\var{I},\var{proj},\var{lift}]$ where \var{proj} and
\var{lift} are matrices respectively representing the projection map and a
section of it.
\bprog
? mt = [matid(3), [0,0,0; 1,1,0; 0,0,0], [0,0,1; 0,0,0; 1,0,1]];
? A = algtableinit(mt,2);
? AQ = algquotient(A,[0;1;0]);
? algdim(AQ)
%4 = 2
@eprog
Function: algradical
Class: basic
Section: algebras
C-Name: algradical
Prototype: G
Help: algradical(al): Jacobson radical of the algebra al.
Doc: \var{al} being a table algebra output by \tet{algtableinit}, returns a
basis of the Jacobson radical of the algebra \var{al} over its prime field
($\Q$ or $\F_p$).
Here is an example with $A = \Q[x]/(x^2)$, generated by $(1,x)$:
\bprog
? mt = [matid(2),[0,0;1,0]];
? A = algtableinit(mt);
? algradical(A) \\ = (x)
%3 =
[0]
[1]
@eprog
Another one with $2\times 2$ upper triangular matrices over $\Q$, generated
by $I_2$, $a = \kbd{[0,1;0,0]}$ and $b = \kbd{[0,0;0,1]}$, such that $a^2 =
0$, $ab = a$, $ba = 0$, $b^2 = b$:
\bprog
? mt = [matid(3),[0,0,0;1,0,1;0,0,0],[0,0,0;0,0,0;1,0,1]];
? A = algtableinit(mt);
? algradical(A) \\ = (a)
%6 =
[0]
[1]
[0]
@eprog
Function: algramifiedplaces
Class: basic
Section: algebras
C-Name: algramifiedplaces
Prototype: G
Help: algramifiedplaces(al): vector of the places of the center of al that
ramify in al. Each place is described as an integer between 1 and r1 or as a
prime ideal.
Doc: Given a central simple algebra \var{al} output by \tet{alginit}, return a
\typ{VEC} containing the list of places of the center of \var{al} that are
ramified in \var{al}. Each place is described as an integer between~$1$
and~$r_1$ or as a prime ideal.
\bprog
? nf = nfinit(y^2-5);
? A = alginit(nf, [-1,y]);
? algramifiedplaces(A)
%3 = [1, [2, [2, 0]~, 1, 2, 1]]
@eprog
Function: algrandom
Class: basic
Section: algebras
C-Name: algrandom
Prototype: GG
Help: algrandom(al,b): random element in al with coefficients in [-b,b].
Doc: Given an algebra \var{al} and an integer \var{b}, returns a random
element in \var{al} with coefficients in~$[-b,b]$.
Function: algrelmultable
Class: basic
Section: algebras
C-Name: algrelmultable
Prototype: mG
Help: algrelmultable(al): multiplication table of the central simple
algebra al over its center.
Doc: Given a central simple algebra \var{al} output by \tet{alginit} defined by a multiplication table over its center (a number field), returns this multiplication table.
\bprog
? nf = nfinit(y^3-5); a = y; b = y^2;
? {m_i = [0,a,0,0;
1,0,0,0;
0,0,0,a;
0,0,1,0];}
? {m_j = [0, 0,b, 0;
0, 0,0,-b;
1, 0,0, 0;
0,-1,0, 0];}
? {m_k = [0, 0,0,-a*b;
0, 0,b, 0;
0,-a,0, 0;
1, 0,0, 0];}
? mt = [matid(4), m_i, m_j, m_k];
? A = alginit(nf,mt,'x);
? M = algrelmultable(A);
? M[2] == m_i
%8 = 1
? M[3] == m_j
%9 = 1
? M[4] == m_k
%10 = 1
@eprog
Function: algsimpledec
Class: basic
Section: algebras
C-Name: algsimpledec
Prototype: GD0,L,
Help: algsimpledec(al,{flag=0}): decomposition into simple algebras of the
semisimple algebra al.
Doc: \var{al} being the output of \tet{algtableinit} representing a semisimple
algebra, returns a \typ{VEC} $[\var{al}_1,\var{al}_2,\dots,\var{al}_n]$ such
that~\var{al} is isomorphic to the direct sum of the simple algebras
$\var{al}_i$. When $\var{flag}=1$, each component is instead a \typ{VEC}
$[\var{al}_i,\var{proj}_i,\var{lift}_i]$ where $\var{proj}_i$
and~$\var{lift}_i$ are matrices respectively representing the projection map
on the $i$-th factor and a section of it. The factors are sorted by
increasing dimension, then increasing dimension of the center. This ensures
that the ordering of the isomorphism classes of the factors is deterministic
over finite fields, but not necessarily over~$\Q$.
\misctitle{Warning} The images of the $\var{lift}_i$ are not guaranteed to form a direct sum.
Function: algsplittingdata
Class: basic
Section: algebras
C-Name: algsplittingdata
Prototype: mG
Help: algsplittingdata(al): data stored in the central simple algebra al to
compute a splitting of al over an extension.
Doc: Given a central simple algebra \var{al} output by \tet{alginit} defined
by a multiplication table over its center~$K$ (a number field), returns data
stored to compute a splitting of \var{al} over an extension. This data is a
\typ{VEC} \kbd{[t,Lbas,Lbasinv]} with $3$ components:
\item an element $t$ of \var{al} such that $L=K(t)$ is a maximal subfield
of \var{al};
\item a matrix \kbd{Lbas} expressing a $L$-basis of \var{al} (given an
$L$-vector space structure by multiplication on the right) on the integral
basis of \var{al};
\item a matrix \kbd{Lbasinv} expressing the integral basis of \var{al} on
the previous $L$-basis.
\bprog
? nf = nfinit(y^3-5); a = y; b = y^2;
? {m_i = [0,a,0,0;
1,0,0,0;
0,0,0,a;
0,0,1,0];}
? {m_j = [0, 0,b, 0;
0, 0,0,-b;
1, 0,0, 0;
0,-1,0, 0];}
? {m_k = [0, 0,0,-a*b;
0, 0,b, 0;
0,-a,0, 0;
1, 0,0, 0];}
? mt = [matid(4), m_i, m_j, m_k];
? A = alginit(nf,mt,'x);
? [t,Lb,Lbi] = algsplittingdata(A);
? t
%8 = [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0]~;
? matsize(Lb)
%9 = [12, 2]
? matsize(Lbi)
%10 = [2, 12]
@eprog
Function: algsplittingfield
Class: basic
Section: algebras
C-Name: algsplittingfield
Prototype: mG
Help: algsplittingfield(al): the stored splitting field of the central simple
algebra al.
Doc: Given a central simple algebra \var{al} output by \tet{alginit}, returns
an \kbd{rnf} structure: the splitting field of \var{al} that is stored in
\var{al}, as a relative extension of the center.
\bprog
nf = nfinit(y^3-5);
a = y; b = y^2;
{m_i = [0,a,0,0;
1,0,0,0;
0,0,0,a;
0,0,1,0];}
{m_j = [0, 0,b, 0;
0, 0,0,-b;
1, 0,0, 0;
0,-1,0, 0];}
{m_k = [0, 0,0,-a*b;
0, 0,b, 0;
0,-a,0, 0;
1, 0,0, 0];}
mt = [matid(4), m_i, m_j, m_k];
A = alginit(nf,mt,'x);
algsplittingfield(A).pol
%8 = x^2 - y
@eprog
Function: algsplittingmatrix
Class: basic
Section: algebras
C-Name: algsplittingmatrix
Prototype: GG
Help: algsplittingmatrix(al,x): image of x under a splitting of al.
Doc: A central simple algebra \var{al} output by \tet{alginit} contains data
describing an isomorphism~$\phi : A\otimes_K L \to M_d(L)$, where $d$ is the
degree of the algebra and $L$ is an extension of $L$ with~$[L:K]=d$. Returns
the matrix $\phi(x)$.
\bprog
? A = alginit(nfinit(y), [-1,-1]);
? algsplittingmatrix(A,[0,0,0,2]~)
%2 =
[Mod(x + 1, x^2 + 1) Mod(Mod(1, y)*x + Mod(-1, y), x^2 + 1)]
[Mod(x + 1, x^2 + 1) Mod(-x + 1, x^2 + 1)]
@eprog
Also accepts matrices with coefficients in \var{al}.
Function: algsqr
Class: basic
Section: algebras
C-Name: algsqr
Prototype: GG
Help: algsqr(al,x): element x^2 in al.
Doc: Given an element $x$ in \var{al}, computes its square $x^2$ in the
algebra \var{al}.
\bprog
? A = alginit(nfinit(y), [-1,-1]);
? algsqr(A,[1,0,2,0]~)
%2 = [-3, 0, 4, 0]~
@eprog
Also accepts a square matrix with coefficients in \var{al}.
Function: algsub
Class: basic
Section: algebras
C-Name: algsub
Prototype: GGG
Help: algsub(al,x,y): element x-y in al.
Doc: Given two elements $x$ and $y$ in \var{al}, computes their difference
$x-y$ in the algebra \var{al}.
\bprog
? A = alginit(nfinit(y), [-1,-1]);
? algsub(A,[1,1,0,0]~,[1,0,1,0]~)
%2 = [0, 1, -1, 0]~
@eprog
Also accepts matrices with coefficients in \var{al}.
Function: algsubalg
Class: basic
Section: algebras
C-Name: algsubalg
Prototype: GG
Help: algsubalg(al,B): subalgebra of al with basis B.
Doc: \var{al} being a table algebra output by \tet{algtableinit} and \var{B}
being a basis of a subalgebra of \var{al} represented by a matrix, returns an
algebra isomorphic to \var{B}.
\bprog
? mt = [matid(3), [0,0,0; 1,1,0; 0,0,0], [0,0,1; 0,0,0; 1,0,1]];
? A = algtableinit(mt,2);
? B = algsubalg(A,[1,0; 0,0; 0,1]);
? algdim(A)
%4 = 3
? algdim(B)
%5 = 2
@eprog
Function: algtableinit
Class: basic
Section: algebras
C-Name: algtableinit
Prototype: GDG
Help: algtableinit(mt, {p=0}): initialize the associative algebra
over Q (resp. Fp) defined by the multiplication table mt.
Doc: initialize the associative algebra over $K = \Q$ (p omitted) or $\F_p$
defined by the multiplication table \var{mt}.
As a $K$-vector space, the algebra is generated by a basis
$(e_1 = 1, e_2, \dots, e_n)$; the table is given as a \typ{VEC} of $n$ matrices in
$M_n(K)$, giving the left multiplication by the basis elements $e_i$, in the
given basis.
Assumes that $e_1=1$, that $K e_1\oplus \dots\oplus K e_n]$ describes an
associative algebra over $K$, and in the case $K=\Q$ that the multiplication
table is integral. If the algebra is already known to be central
and simple, then the case $K = \F_p$ is useless, and one should use
\tet{alginit} directly.
The point of this function is to input a finite dimensional $K$-algebra, so
as to later compute its radical, then to split the quotient algebra as a
product of simple algebras over $K$.
The pari object representing such an algebra $A$ is a \typ{VEC} with the
following data:
\item The characteristic of $A$, accessed with \kbd{algchar}.
\item The multiplication table of $A$, accessed with \kbd{algmultable}.
\item The traces of the elements of the basis.
A simple example: the $2\times 2$ upper triangular matrices over $\Q$,
generated by $I_2$, $a = \kbd{[0,1;0,0]}$ and $b = \kbd{[0,0;0,1]}$,
such that $a^2 = 0$, $ab = a$, $ba = 0$, $b^2 = b$:
\bprog
? mt = [matid(3),[0,0,0;1,0,1;0,0,0],[0,0,0;0,0,0;1,0,1]];
? A = algtableinit(mt);
? algradical(A) \\ = (a)
%6 =
[0]
[1]
[0]
? algcenter(A) \\ = (I_2)
%7 =
[1]
[0]
[0]
@eprog
Function: algtensor
Class: basic
Section: algebras
C-Name: algtensor
Prototype: GGD1,L,
Help: algtensor(al1,al2,{maxord=1}): tensor product of al1 and al2.
Doc: Given two algebras \var{al1} and \var{al2}, computes their tensor
product. For table algebras output by \tet{algtableinit}, the flag
\var{maxord} is ignored. For central simple algebras output by \tet{alginit},
computes a maximal order by default. Prevent this computation by setting
$\var{maxord}=0$.
Currently only implemented for cyclic algebras of coprime degree over the same
center~$K$, and the tensor product is over~$K$.
Function: algtrace
Class: basic
Section: algebras
C-Name: algtrace
Prototype: GG
Help: algtrace(al,x): (reduced) trace of x.
Doc: Given an element \var{x} in \var{al}, computes its trace. If \var{al} is
a table algebra output by \tet{algtableinit}, returns the absolute trace of
\var{x}, which is an element of $\F_p$ or~$\Q$; if \var{al} is the output of
\tet{alginit}, returns the reduced trace of \var{x}, which is an element of
the center of \var{al}.
\bprog
? A = alginit(nfinit(y), [-1,-1]);
? algtrace(A,[5,0,0,1]~)
%2 = 11
@eprog
Also accepts a square matrix with coefficients in \var{al}.
Function: algtype
Class: basic
Section: algebras
C-Name: algtype
Prototype: lG
Help: algtype(al): type of the algebra al.
Doc: Given an algebra \var{al} output by \tet{alginit} or by \tet{algtableinit}, returns an integer indicating the type of algebra:
\item $0$: not a valid algebra.
\item $1$: table algebra output by \tet{algtableinit}.
\item $2$: central simple algebra output by \tet{alginit} and represented by
a multiplication table over its center.
\item $3$: central simple algebra output by \tet{alginit} and represented by
a cyclic algebra.
\bprog
? algtype([])
%1 = 0
? mt = [matid(3), [0,0,0; 1,1,0; 0,0,0], [0,0,1; 0,0,0; 1,0,1]];
? A = algtableinit(mt,2);
? algtype(A)
%4 = 1
? nf = nfinit(y^3-5);
? a = y; b = y^2;
? {m_i = [0,a,0,0;
1,0,0,0;
0,0,0,a;
0,0,1,0];}
? {m_j = [0, 0,b, 0;
0, 0,0,-b;
1, 0,0, 0;
0,-1,0, 0];}
? {m_k = [0, 0,0,-a*b;
0, 0,b, 0;
0,-a,0, 0;
1, 0,0, 0];}
? mt = [matid(4), m_i, m_j, m_k];
? A = alginit(nf,mt,'x);
? algtype(A)
%12 = 2
? A = alginit(nfinit(y), [-1,-1]);
? algtype(A)
%14 = 3
@eprog
Function: alias
Class: basic
Section: programming/specific
C-Name: alias0
Prototype: vrr
Help: alias(newsym,sym): defines the symbol newsym as an alias for the symbol
sym.
Doc: defines the symbol \var{newsym} as an alias for the symbol \var{sym}:
\bprog
? alias("det", "matdet");
? det([1,2;3,4])
%1 = -2
@eprog\noindent
You are not restricted to ordinary functions, as in the above example:
to alias (from/to) member functions, prefix them with `\kbd{\_.}';
to alias operators, use their internal name, obtained by writing
\kbd{\_} in lieu of the operators argument: for instance, \kbd{\_!} and
\kbd{!\_} are the internal names of the factorial and the
logical negation, respectively.
\bprog
? alias("mod", "_.mod");
? alias("add", "_+_");
? alias("_.sin", "sin");
? mod(Mod(x,x^4+1))
%2 = x^4 + 1
? add(4,6)
%3 = 10
? Pi.sin
%4 = 0.E-37
@eprog
Alias expansion is performed directly by the internal GP compiler.
Note that since alias is performed at compilation-time, it does not
require any run-time processing, however it only affects GP code
compiled \emph{after} the alias command is evaluated. A slower but more
flexible alternative is to use variables. Compare
\bprog
? fun = sin;
? g(a,b) = intnum(t=a,b,fun(t));
? g(0, Pi)
%3 = 2.0000000000000000000000000000000000000
? fun = cos;
? g(0, Pi)
%5 = 1.8830410776607851098 E-39
@eprog\noindent
with
\bprog
? alias(fun, sin);
? g(a,b) = intnum(t=a,b,fun(t));
? g(0,Pi)
%2 = 2.0000000000000000000000000000000000000
? alias(fun, cos); \\ Oops. Does not affect *previous* definition!
? g(0,Pi)
%3 = 2.0000000000000000000000000000000000000
? g(a,b) = intnum(t=a,b,fun(t)); \\ Redefine, taking new alias into account
? g(0,Pi)
%5 = 1.8830410776607851098 E-39
@eprog
A sample alias file \kbd{misc/gpalias} is provided with
the standard distribution.
Function: allocatemem
Class: basic
Section: programming/specific
C-Name: gp_allocatemem
Prototype: vDG
Help: allocatemem({s=0}): allocates a new stack of s bytes. doubles the
stack if s is omitted.
Doc: this special operation changes the stack size \emph{after}
initialization. $x$ must be a non-negative integer. If $x > 0$, a new stack
of at least $x$ bytes is allocated. We may allocate more than $x$ bytes if
$x$ is way too small, or for alignment reasons: the current formula is
$\max(16*\ceil{x/16}, 500032)$ bytes.
If $x=0$, the size of the new stack is twice the size of the old one.
This command is much more useful if \tet{parisizemax} is non-zero, and we
describe this case first. With \kbd{parisizemax} enabled, there are three
sizes of interest:
\item a virtual stack size, \tet{parisizemax}, which is an absolute upper
limit for the stack size; this is set by \kbd{default(parisizemax, ...)}.
\item the desired typical stack size, \tet{parisize}, that will grow as
needed, up to \tet{parisizemax}; this is set by \kbd{default(parisize, ...)}.
\item the current stack size, which is less that \kbd{parisizemax},
typically equal to \kbd{parisize} but possibly larger and increasing
dynamically as needed; \kbd{allocatemem} allows to change that one
explicitly.
The \kbd{allocatemem} command forces stack
usage to increase temporarily (up to \kbd{parisizemax} of course); for
instance if you notice using \kbd{\bs gm2} that we seem to collect garbage a
lot, e.g.
\bprog
? \gm2
debugmem = 2
? default(parisize,"32M")
*** Warning: new stack size = 32000000 (30.518 Mbytes).
? bnfinit('x^2+10^30-1)
*** bnfinit: collecting garbage in hnffinal, i = 1.
*** bnfinit: collecting garbage in hnffinal, i = 2.
*** bnfinit: collecting garbage in hnffinal, i = 3.
@eprog\noindent and so on for hundred of lines. Then, provided the
\tet{breakloop} default is set, you can interrupt the computation, type
\kbd{allocatemem(100*10\pow6)} at the break loop prompt, then let the
computation go on by typing \kbd{<Enter>}. Back at the \kbd{gp} prompt,
the desired stack size of \kbd{parisize} is restored. Note that changing either
\kbd{parisize} or \kbd{parisizemax} at the break loop prompt would interrupt
the computation, contrary to the above.
In most cases, \kbd{parisize} will increase automatically (up to
\kbd{parisizemax}) and there is no need to perform the above maneuvers.
But that the garbage collector is sufficiently efficient that
a given computation can still run without increasing the stack size,
albeit very slowly due to the frequent garbage collections.
\misctitle{Deprecated: when \kbd{parisizemax} is unset}
This is currently still the default behavior in order not to break backward
compatibility. The rest of this section documents the
behavior of \kbd{allocatemem} in that (deprecated) situation: it becomes a
synonym for \kbd{default(parisize,...)}. In that case, there is no
notion of a virtual stack, and the stack size is always equal to
\kbd{parisize}. If more memory is needed, the PARI stack overflows, aborting
the computation.
Thus, increasing \kbd{parisize} via \kbd{allocatemem} or
\kbd{default(parisize,...)} before a big computation is important.
Unfortunately, either must be typed at the \kbd{gp} prompt in
interactive usage, or left by itself at the start of batch files.
They cannot be used meaningfully in loop-like constructs, or as part of a
larger expression sequence, e.g
\bprog
allocatemem(); x = 1; \\@com This will not set \kbd{x}!
@eprog\noindent
In fact, all loops are immediately exited, user functions terminated, and
the rest of the sequence following \kbd{allocatemem()} is silently
discarded, as well as all pending sequences of instructions. We just go on
reading the next instruction sequence from the file we are in (or from the
user). In particular, we have the following possibly unexpected behavior: in
\bprog
read("file.gp"); x = 1
@eprog\noindent were \kbd{file.gp} contains an \kbd{allocatemem} statement,
the \kbd{x = 1} is never executed, since all pending instructions in the
current sequence are discarded.
The reason for these unfortunate side-effects is that, with
\kbd{parisizemax} disabled, increasing the stack size physically
moves the stack, so temporary objects created during the current expression
evaluation are not correct anymore. (In particular byte-compiled expressions,
which are allocated on the stack.) To avoid accessing obsolete pointers to
the old stack, this routine ends by a \kbd{longjmp}.
Function: apply
Class: basic
Section: programming/specific
C-Name: apply0
Prototype: GG
Help: apply(f, A): apply function f to each entry in A.
Wrapper: (G)
Description:
(closure,gen):gen genapply(${1 cookie}, ${1 wrapper}, $2)
Doc: Apply the \typ{CLOSURE} \kbd{f} to the entries of \kbd{A}. If \kbd{A}
is a scalar, return \kbd{f(A)}. If \kbd{A} is a polynomial or power series,
apply \kbd{f} on all coefficients. If \kbd{A} is a vector or list, return
the elements $f(x)$ where $x$ runs through \kbd{A}. If \kbd{A} is a matrix,
return the matrix whose entries are the $f(\kbd{A[i,j]})$.
\bprog
? apply(x->x^2, [1,2,3,4])
%1 = [1, 4, 9, 16]
? apply(x->x^2, [1,2;3,4])
%2 =
[1 4]
[9 16]
? apply(x->x^2, 4*x^2 + 3*x+ 2)
%3 = 16*x^2 + 9*x + 4
@eprog\noindent Note that many functions already act componentwise on
vectors or matrices, but they almost never act on lists; in this
case, \kbd{apply} is a good solution:
\bprog
? L = List([Mod(1,3), Mod(2,4)]);
? lift(L)
*** at top-level: lift(L)
*** ^-------
*** lift: incorrect type in lift.
? apply(lift, L);
%2 = List([1, 2])
@eprog
\misctitle{Remark} For $v$ a \typ{VEC}, \typ{COL}, \typ{LIST} or \typ{MAT},
the alternative set-notations
\bprog
[g(x) | x <- v, f(x)]
[x | x <- v, f(x)]
[g(x) | x <- v]
@eprog\noindent
are available as shortcuts for
\bprog
apply(g, select(f, Vec(v)))
select(f, Vec(v))
apply(g, Vec(v))
@eprog\noindent respectively:
\bprog
? L = List([Mod(1,3), Mod(2,4)]);
? [ lift(x) | x<-L ]
%2 = [1, 2]
@eprog
\synt{genapply}{void *E, GEN (*fun)(void*,GEN), GEN a}.
Function: arg
Class: basic
Section: transcendental
C-Name: garg
Prototype: Gp
Help: arg(x): argument of x, such that -pi<arg(x)<=pi.
Doc: argument of the complex number $x$, such that $-\pi < \arg(x) \le \pi$.
Function: asin
Class: basic
Section: transcendental
C-Name: gasin
Prototype: Gp
Help: asin(x): arc sine of x.
Doc: principal branch of $\sin^{-1}(x) = -i \log(ix + \sqrt{1 - x^2})$.
In particular, $\Re(\text{asin}(x))\in [-\pi/2,\pi/2]$ and if $x\in \R$ and
$|x|>1$ then $\text{asin}(x)$ is complex. The branch cut is in two pieces:
$]-\infty,-1]$, continuous with quadrant II, and $[1,+\infty[$ continuous
with quadrant IV. The function satisfies $i \text{asin}(x) =
\text{asinh}(ix)$.
Function: asinh
Class: basic
Section: transcendental
C-Name: gasinh
Prototype: Gp
Help: asinh(x): inverse hyperbolic sine of x.
Doc: principal branch of $\sinh^{-1}(x) = \log(x + \sqrt{1+x^2})$. In
particular $\Im(\text{asinh}(x))\in [-\pi/2,\pi/2]$.
The branch cut is in two pieces: $]-i \infty ,-i]$, continuous with quadrant
III and $[+i,+i \infty[$, continuous with quadrant I.
Function: asympnum
Class: basic
Section: sums
C-Name: asympnum0
Prototype: GD0,L,DGp
Help: asympnum(expr,{k=20},{alpha = 1}): asymptotic expansion of expr assuming
it has rational coefficients with reasonable height; k and alpha are as
in limitnum.
Doc: Asymptotic expansion of \var{expr}, corresponding to a sequence $u(n)$,
assuming it has the shape
$$u(n) \approx \sum_{i \geq 0} a_i n^{-i\alpha}$$
with rational coefficients $a_i$ with reasonable height; the algorithm
is heuristic and performs repeated calls to limitnum, with
\kbd{k} and \kbd{alpha} are as in \kbd{limitnum}
\bprog
? f(n) = n! / (n^n*exp(-n)*sqrt(n));
? asympnum(f)
%2 = [] \\ failure !
? l = limitnum(f)
%3 = 2.5066282746310005024157652848110452530
? asympnum(n->f(n)/l) \\ normalize
%4 = [1, 1/12, 1/288, -139/51840]
@eprog\noindent and we indeed get a few terms of Stirling's expansion. Note
that it helps to normalize with a limit computed to higher accuracy:
\bprog
? \p100
? L = limitnum(f)
? \p38
? asympnum(n->f(n)/L) \\ we get more terms!
%6 = [1, 1/12, 1/288, -139/51840, -571/2488320, 163879/209018880,\
5246819/75246796800, -534703531/902961561600]
@eprog\noindent If \kbd{alpha} is not an integer, loss of accuracy is
expected, so it should be precomputed to double accuracy, say:
\bprog
? \p38
? asympnum(n->-log(1-1/n^Pi),,Pi)
%1 = [0, 1, 1/2, 1/3]
? asympnum(n->-log(1-1/sqrt(n)),,1/2)
%2 = [0, 1, 1/2, 1/3, 1/4, 1/5, 1/6, 1/7, 1/8, 1/9, 1/10, 1/11, 1/12, \
1/13, 1/14, 1/15, 1/16, 1/17, 1/18, 1/19, 1/20, 1/21, 1/22]
? localprec(100); a = Pi;
? asympnum(n->-log(1-1/n^a),,a) \\ better !
%4 = [0, 1, 1/2, 1/3, 1/4, 1/5, 1/6, 1/7, 1/8, 1/9, 1/10, 1/11, 1/12]
@eprog
\synt{asympnum}{void *E, GEN (*u)(void *,GEN,long), long muli, GEN alpha, long prec}, where \kbd{u(E, n, prec)} must return $u(n)$ in precision \kbd{prec}.
Also available is
\fun{GEN}{asympnum0}{GEN u, long muli, GEN alpha, long prec}, where $u$
must be a vector of sufficient length as above.
Function: atan
Class: basic
Section: transcendental
C-Name: gatan
Prototype: Gp
Help: atan(x): arc tangent of x.
Doc: principal branch of $\text{tan}^{-1}(x) = \log ((1+ix)/(1-ix)) /
2i$. In particular the real part of $\text{atan}(x)$ belongs to
$]-\pi/2,\pi/2[$.
The branch cut is in two pieces:
$]-i\infty,-i[$, continuous with quadrant IV, and $]i,+i \infty[$ continuous
with quadrant II. The function satisfies $\text{atan}(x) =
-i\text{atanh}(ix)$ for all $x\neq \pm i$.
Function: atanh
Class: basic
Section: transcendental
C-Name: gatanh
Prototype: Gp
Help: atanh(x): inverse hyperbolic tangent of x.
Doc: principal branch of $\text{tanh}^{-1}(x) = \log ((1+x)/(1-x)) / 2$. In
particular the imaginary part of $\text{atanh}(x)$ belongs to
$[-\pi/2,\pi/2]$; if $x\in \R$ and $|x|>1$ then $\text{atanh}(x)$ is complex.
Function: bernfrac
Class: basic
Section: transcendental
C-Name: bernfrac
Prototype: L
Help: bernfrac(x): Bernoulli number B_x, as a rational number.
Doc: Bernoulli number\sidx{Bernoulli numbers} $B_x$,
where $B_0=1$, $B_1=-1/2$, $B_2=1/6$,\dots, expressed as a rational number.
The argument $x$ should be of type integer.
Function: bernpol
Class: basic
Section: transcendental
C-Name: bernpol
Prototype: LDn
Help: bernpol(n, {v = 'x}): Bernoulli polynomial B_n, in variable v.
Doc: \idx{Bernoulli polynomial} $B_n$ in variable $v$.
\bprog
? bernpol(1)
%1 = x - 1/2
? bernpol(3)
%2 = x^3 - 3/2*x^2 + 1/2*x
@eprog
Function: bernreal
Class: basic
Section: transcendental
C-Name: bernreal
Prototype: Lp
Help: bernreal(x): Bernoulli number B_x, as a real number with the current
precision.
Doc: Bernoulli number\sidx{Bernoulli numbers}
$B_x$, as \kbd{bernfrac}, but $B_x$ is returned as a real number
(with the current precision).
Function: bernvec
Class: basic
Section: transcendental
C-Name: bernvec
Prototype: L
Help: bernvec(x): this routine is obsolete, use bernfrac repeatedly.
Doc: This routine is obsolete, kept for backward compatibility only.
Obsolete: 2007-03-30
Function: besselh1
Class: basic
Section: transcendental
C-Name: hbessel1
Prototype: GGp
Help: besselh1(nu,x): H^1-bessel function of index nu and argument x.
Doc: $H^1$-Bessel function of index \var{nu} and argument $x$.
Function: besselh2
Class: basic
Section: transcendental
C-Name: hbessel2
Prototype: GGp
Help: besselh2(nu,x): H^2-bessel function of index nu and argument x.
Doc: $H^2$-Bessel function of index \var{nu} and argument $x$.
Function: besseli
Class: basic
Section: transcendental
C-Name: ibessel
Prototype: GGp
Help: besseli(nu,x): I-bessel function of index nu and argument x.
Doc: $I$-Bessel function of index \var{nu} and
argument $x$. If $x$ converts to a power series, the initial factor
$(x/2)^\nu/\Gamma(\nu+1)$ is omitted (since it cannot be represented in PARI
when $\nu$ is not integral).
Function: besselj
Class: basic
Section: transcendental
C-Name: jbessel
Prototype: GGp
Help: besselj(nu,x): J-bessel function of index nu and argument x.
Doc: $J$-Bessel function of index \var{nu} and
argument $x$. If $x$ converts to a power series, the initial factor
$(x/2)^\nu/\Gamma(\nu+1)$ is omitted (since it cannot be represented in PARI
when $\nu$ is not integral).
Function: besseljh
Class: basic
Section: transcendental
C-Name: jbesselh
Prototype: GGp
Help: besseljh(n,x): J-bessel function of index n+1/2 and argument x, where
n is a non-negative integer.
Doc: $J$-Bessel function of half integral index.
More precisely, $\kbd{besseljh}(n,x)$ computes $J_{n+1/2}(x)$ where $n$
must be of type integer, and $x$ is any element of $\C$. In the
present version \vers, this function is not very accurate when $x$ is small.
Function: besselk
Class: basic
Section: transcendental
C-Name: kbessel
Prototype: GGp
Help: besselk(nu,x): K-bessel function of index nu and argument x.
Doc: $K$-Bessel function of index \var{nu} and argument $x$.
Function: besseln
Class: basic
Section: transcendental
C-Name: nbessel
Prototype: GGp
Help: besseln(nu,x): N-bessel function of index nu and argument x.
Doc: $N$-Bessel function of index \var{nu} and argument $x$.
Function: bestappr
Class: basic
Section: number_theoretical
C-Name: bestappr
Prototype: GDG
Help: bestappr(x, {B}): returns a rational approximation to x, whose
denominator is limited by B, if present. This function applies to reals,
intmods, p-adics, and rationals of course. Otherwise it applies recursively
to all components.
Doc: using variants of the extended Euclidean algorithm, returns a rational
approximation $a/b$ to $x$, whose denominator is limited
by $B$, if present. If $B$ is omitted, return the best approximation
affordable given the input accuracy; if you are looking for true rational
numbers, presumably approximated to sufficient accuracy, you should first
try that option. Otherwise, $B$ must be a positive real scalar (impose
$0 < b \leq B$).
\item If $x$ is a \typ{REAL} or a \typ{FRAC}, this function uses continued
fractions.
\bprog
? bestappr(Pi, 100)
%1 = 22/7
? bestappr(0.1428571428571428571428571429)
%2 = 1/7
? bestappr([Pi, sqrt(2) + 'x], 10^3)
%3 = [355/113, x + 1393/985]
@eprog
By definition, $a/b$ is the best rational approximation to $x$ if
$|b x - a| < |v x - u|$ for all integers $(u,v)$ with $0 < v \leq B$.
(Which implies that $n/d$ is a convergent of the continued fraction of $x$.)
\item If $x$ is a \typ{INTMOD} modulo $N$ or a \typ{PADIC} of precision $N =
p^k$, this function performs rational modular reconstruction modulo $N$. The
routine then returns the unique rational number $a/b$ in coprime integers
$|a| < N/2B$ and $b\leq B$ which is congruent to $x$ modulo $N$. Omitting
$B$ amounts to choosing it of the order of $\sqrt{N/2}$. If rational
reconstruction is not possible (no suitable $a/b$ exists), returns $[]$.
\bprog
? bestappr(Mod(18526731858, 11^10))
%1 = 1/7
? bestappr(Mod(18526731858, 11^20))
%2 = []
? bestappr(3 + 5 + 3*5^2 + 5^3 + 3*5^4 + 5^5 + 3*5^6 + O(5^7))
%2 = -1/3
@eprog\noindent In most concrete uses, $B$ is a prime power and we performed
Hensel lifting to obtain $x$.
The function applies recursively to components of complex objects
(polynomials, vectors, \dots). If rational reconstruction fails for even a
single entry, return $[]$.
Function: bestapprPade
Class: basic
Section: number_theoretical
C-Name: bestapprPade
Prototype: GD-1,L,
Help: bestapprPade(x, {B}): returns a rational function approximation to x.
This function applies to series, polmods, and rational functions of course.
Otherwise it applies recursively to all components.
Doc: using variants of the extended Euclidean algorithm, returns a rational
function approximation $a/b$ to $x$, whose denominator is limited
by $B$, if present. If $B$ is omitted, return the best approximation
affordable given the input accuracy; if you are looking for true rational
functions, presumably approximated to sufficient accuracy, you should first
try that option. Otherwise, $B$ must be a non-negative real
(impose $0 \leq \text{degree}(b) \leq B$).
\item If $x$ is a \typ{POLMOD} modulo $N$ this function performs rational
modular reconstruction modulo $N$. The routine then returns the unique
rational function $a/b$ in coprime polynomials, with $\text{degree}(b)\leq B$
and $\text{degree}(a)$ minimal, which is congruent to $x$ modulo $N$.
Omitting $B$ amounts to choosing it equal to the floor of
$\text{degree}(N) / 2$. If rational reconstruction is not possible (no
suitable $a/b$ exists), returns $[]$.
\bprog
? T = Mod(x^3 + x^2 + x + 3, x^4 - 2);
? bestapprPade(T)
%2 = (2*x - 1)/(x - 1)
? U = Mod(1 + x + x^2 + x^3 + x^5, x^9);
? bestapprPade(U) \\ internally chooses B = 4
%3 = []
? bestapprPade(U, 5) \\ with B = 5, a solution exists
%4 = (2*x^4 + x^3 - x - 1)/(-x^5 + x^3 + x^2 - 1)
@eprog
\item If $x$ is a \typ{RFRAC} or \typ{SER}, this function implicitly
converts the input to \typ{POLMOD} modulo $N = t^k$
fractions.
\bprog
? T = 1 + x + x^2 + x^3 + x^4 + x^5 + x^6 + O(x^7);
? bestapprPade(T)
%1 = 1/(-x + 1)
@eprog\noindent
The function applies recursively to components of complex objects
(polynomials, vectors, \dots). If rational reconstruction fails for even a
single entry, return $[]$.
Function: bezout
Class: basic
Section: number_theoretical
C-Name: gcdext0
Prototype: GG
Help: bezout(x,y): deprecated alias for gcdext.
Doc: deprecated alias for \kbd{gcdext}
Obsolete: 2013-04-03
Function: bezoutres
Class: basic
Section: polynomials
C-Name: polresultantext0
Prototype: GGDn
Help: bezoutres(A,B,{v}): deprecated alias for polresultantext.
Doc: deprecated alias for \kbd{polresultantext}
Obsolete: 2015-01-13
Function: bigomega
Class: basic
Section: number_theoretical
C-Name: bigomega
Prototype: lG
Help: bigomega(x): number of prime divisors of x, counted with multiplicity.
Doc: number of prime divisors of the integer $|x|$ counted with
multiplicity:
\bprog
? factor(392)
%1 =
[2 3]
[7 2]
? bigomega(392)
%2 = 5; \\ = 3+2
? omega(392)
%3 = 2; \\ without multiplicity
@eprog
Function: binary
Class: basic
Section: conversions
C-Name: binaire
Prototype: G
Help: binary(x): gives the vector formed by the binary digits of x (x
integer).
Doc:
outputs the vector of the binary digits of $|x|$. Here $x$ can be an
integer, a real number (in which case the result has two components, one for
the integer part, one for the fractional part) or a vector/matrix.
\bprog
? binary(10)
%1 = [1, 0, 1, 0]
? binary(3.14)
%2 = [[1, 1], [0, 0, 1, 0, 0, 0, [...]]
? binary([1,2])
%3 = [[1], [1, 0]]
@eprog\noindent By convention, $0$ has no digits:
\bprog
? binary(0)
%4 = []
@eprog
Function: binomial
Class: basic
Section: number_theoretical
C-Name: binomial
Prototype: GL
Help: binomial(x,y): binomial coefficient x*(x-1)...*(x-y+1)/y! defined for
y in Z and any x.
Doc: \idx{binomial coefficient} $\binom{x}{y}$.
Here $y$ must be an integer, but $x$ can be any PARI object.
Variant: The function
\fun{GEN}{binomialuu}{ulong n, ulong k} is also available, and so is
\fun{GEN}{vecbinome}{long n}, which returns a vector $v$
with $n+1$ components such that $v[k+1] = \kbd{binomial}(n,k)$ for $k$ from
$0$ up to $n$.
Function: bitand
Class: basic
Section: conversions
C-Name: gbitand
Prototype: GG
Help: bitand(x,y): bitwise "and" of two integers x and y. Negative numbers
behave as if modulo big power of 2.
Description:
(small, small):small:parens $(1)&$(2)
(gen, gen):int gbitand($1, $2)
Doc:
bitwise \tet{and}
\sidx{bitwise and}of two integers $x$ and $y$, that is the integer
$$\sum_i (x_i~\kbd{and}~y_i) 2^i$$
Negative numbers behave $2$-adically, i.e.~the result is the $2$-adic limit
of \kbd{bitand}$(x_n,y_n)$, where $x_n$ and $y_n$ are non-negative integers
tending to $x$ and $y$ respectively. (The result is an ordinary integer,
possibly negative.)
\bprog
? bitand(5, 3)
%1 = 1
? bitand(-5, 3)
%2 = 3
? bitand(-5, -3)
%3 = -7
@eprog
Variant: Also available is
\fun{GEN}{ibitand}{GEN x, GEN y}, which returns the bitwise \emph{and}
of $|x|$ and $|y|$, two integers.
Function: bitneg
Class: basic
Section: conversions
C-Name: gbitneg
Prototype: GD-1,L,
Help: bitneg(x,{n=-1}): bitwise negation of an integers x truncated to n
bits. n=-1 means represent infinite sequences of bit 1 as negative numbers.
Negative numbers behave as if modulo big power of 2.
Doc:
\idx{bitwise negation} of an integer $x$,
truncated to $n$ bits, $n\geq 0$, that is the integer
$$\sum_{i=0}^{n-1} \kbd{not}(x_i) 2^i.$$
The special case $n=-1$ means no truncation: an infinite sequence of
leading $1$ is then represented as a negative number.
See \secref{se:bitand} for the behavior for negative arguments.
Function: bitnegimply
Class: basic
Section: conversions
C-Name: gbitnegimply
Prototype: GG
Help: bitnegimply(x,y): bitwise "negated imply" of two integers x and y,
in other words, x BITAND BITNEG(y). Negative numbers behave as if modulo big
power of 2.
Description:
(small, small):small:parens $(1)&~$(2)
(gen, gen):int gbitnegimply($1, $2)
Doc:
bitwise negated imply of two integers $x$ and
$y$ (or \kbd{not} $(x \Rightarrow y)$), that is the integer $$\sum
(x_i~\kbd{and not}(y_i)) 2^i$$
See \secref{se:bitand} for the behavior for negative arguments.
Variant: Also available is
\fun{GEN}{ibitnegimply}{GEN x, GEN y}, which returns the bitwise negated
imply of $|x|$ and $|y|$, two integers.
Function: bitor
Class: basic
Section: conversions
C-Name: gbitor
Prototype: GG
Help: bitor(x,y): bitwise "or" of two integers x and y. Negative numbers
behave as if modulo big power of 2.
Description:
(small, small):small:parens $(1)|$(2)
(gen, gen):int gbitor($1, $2)
Doc:
\sidx{bitwise inclusive or}bitwise (inclusive)
\tet{or} of two integers $x$ and $y$, that is the integer $$\sum
(x_i~\kbd{or}~y_i) 2^i$$
See \secref{se:bitand} for the behavior for negative arguments.
Variant: Also available is
\fun{GEN}{ibitor}{GEN x, GEN y}, which returns the bitwise \emph{ir}
of $|x|$ and $|y|$, two integers.
Function: bitprecision
Class: basic
Section: conversions
C-Name: bitprecision0
Prototype: GD0,L,
Help: bitprecision(x,{n}): if n is present and positive, return x at precision
n bits. If n is omitted, return real precision of object x in bits.
Doc: the function behaves differently according to whether $n$ is
present and positive or not. If $n$ is missing, the function returns the
(floating point) precision in bits of the PARI object $x$. If $x$ is an
exact object, the function returns \kbd{+oo}.
\bprog
? bitprecision(exp(1e-100))
%1 = 512 \\ 512 bits
? bitprecision( [ exp(1e-100), 0.5 ] )
%2 = 128 \\ minimal accuracy among components
? bitprecision(2 + x)
%3 = +oo \\ exact object
@eprog
If $n$ is present and positive, the function creates a new object equal to $x$
with the new bit-precision roughly $n$. In fact, the smallest multiple of 64
(resp.~32 on a 32-bit machine) larger than or equal to $n$.
For $x$ a vector or a matrix, the operation is
done componentwise; for series and polynomials, the operation is done
coefficientwise. For real $x$, $n$ is the number of desired significant
\emph{bits}. If $n$ is smaller than the precision of $x$, $x$ is truncated,
otherwise $x$ is extended with zeros. For exact or non-floating point types,
no change.
\bprog
? bitprecision(Pi, 10) \\ actually 64 bits ~ 19 decimal digits
%1 = 3.141592653589793239
? bitprecision(1, 10)
%2 = 1
? bitprecision(1 + O(x), 10)
%3 = 1 + O(x)
? bitprecision(2 + O(3^5), 10)
%4 = 2 + O(3^5)
@eprog\noindent
Function: bittest
Class: basic
Section: conversions
C-Name: gbittest
Prototype: GL
Help: bittest(x,n): gives bit number n (coefficient of 2^n) of the integer x.
Negative numbers behave as if modulo big power of 2.
Description:
(small, small):bool:parens ($(1)>>$(2))&1
(int, small):bool bittest($1, $2)
(gen, small):gen gbittest($1, $2)
Doc:
outputs the $n^{\text{th}}$ bit of $x$ starting
from the right (i.e.~the coefficient of $2^n$ in the binary expansion of $x$).
The result is 0 or 1.
\bprog
? bittest(7, 0)
%1 = 1 \\ the bit 0 is 1
? bittest(7, 2)
%2 = 1 \\ the bit 2 is 1
? bittest(7, 3)
%3 = 0 \\ the bit 3 is 0
@eprog\noindent
See \secref{se:bitand} for the behavior at negative arguments.
Variant: For a \typ{INT} $x$, the variant \fun{long}{bittest}{GEN x, long n} is
generally easier to use, and if furthermore $n\ge 0$ the low-level function
\fun{ulong}{int_bit}{GEN x, long n} returns \kbd{bittest(abs(x),n)}.
Function: bitxor
Class: basic
Section: conversions
C-Name: gbitxor
Prototype: GG
Help: bitxor(x,y): bitwise "exclusive or" of two integers x and y.
Negative numbers behave as if modulo big power of 2.
Description:
(small, small):small:parens $(1)^$(2)
(gen, gen):int gbitxor($1, $2)
Doc:
bitwise (exclusive) \tet{or}
\sidx{bitwise exclusive or}of two integers $x$ and $y$, that is the integer
$$\sum (x_i~\kbd{xor}~y_i) 2^i$$
See \secref{se:bitand} for the behavior for negative arguments.
Variant: Also available is
\fun{GEN}{ibitxor}{GEN x, GEN y}, which returns the bitwise \emph{xor}
of $|x|$ and $|y|$, two integers.
Function: bnfcertify
Class: basic
Section: number_fields
C-Name: bnfcertify0
Prototype: lGD0,L,
Help: bnfcertify(bnf,{flag = 0}): certify the correctness (i.e. remove the GRH) of the bnf data output by bnfinit. If flag is present, only certify that the class group is a quotient of the one computed in bnf (much simpler in general).
Doc: $\var{bnf}$ being as output by
\kbd{bnfinit}, checks whether the result is correct, i.e.~whether it is
possible to remove the assumption of the Generalized Riemann
Hypothesis\sidx{GRH}. It is correct if and only if the answer is 1. If it is
incorrect, the program may output some error message, or loop indefinitely.
You can check its progress by increasing the debug level. The \var{bnf}
structure must contain the fundamental units:
\bprog
? K = bnfinit(x^3+2^2^3+1); bnfcertify(K)
*** at top-level: K=bnfinit(x^3+2^2^3+1);bnfcertify(K)
*** ^-------------
*** bnfcertify: missing units in bnf.
? K = bnfinit(x^3+2^2^3+1, 1); \\ include units
? bnfcertify(K)
%3 = 1
@eprog
If flag is present, only certify that the class group is a quotient of the
one computed in bnf (much simpler in general); likewise, the computed units
may form a subgroup of the full unit group. In this variant, the units are
no longer needed:
\bprog
? K = bnfinit(x^3+2^2^3+1); bnfcertify(K, 1)
%4 = 1
@eprog
Variant: Also available is \fun{GEN}{bnfcertify}{GEN bnf} ($\fl=0$).
Function: bnfcompress
Class: basic
Section: number_fields
C-Name: bnfcompress
Prototype: G
Help: bnfcompress(bnf): converts bnf to a much smaller sbnf, containing the
same information. Use bnfinit(sbnf) to recover a true bnf.
Doc: computes a compressed version of \var{bnf} (from \tet{bnfinit}), a
``small Buchmann's number field'' (or \var{sbnf} for short) which contains
enough information to recover a full $\var{bnf}$ vector very rapidly, but
which is much smaller and hence easy to store and print. Calling
\kbd{bnfinit} on the result recovers a true \kbd{bnf}, in general different
from the original. Note that an \tev{snbf} is useless for almost all
purposes besides storage, and must be converted back to \tev{bnf} form
before use; for instance, no \kbd{nf*}, \kbd{bnf*} or member function
accepts them.
An \var{sbnf} is a 12 component vector $v$, as follows. Let \kbd{bnf} be
the result of a full \kbd{bnfinit}, complete with units. Then $v[1]$ is
\kbd{bnf.pol}, $v[2]$ is the number of real embeddings \kbd{bnf.sign[1]},
$v[3]$ is \kbd{bnf.disc}, $v[4]$ is \kbd{bnf.zk}, $v[5]$ is the list of roots
\kbd{bnf.roots}, $v[7]$ is the matrix $\kbd{W} = \kbd{bnf[1]}$,
$v[8]$ is the matrix $\kbd{matalpha}=\kbd{bnf[2]}$,
$v[9]$ is the prime ideal factor base \kbd{bnf[5]} coded in a compact way,
and ordered according to the permutation \kbd{bnf[6]}, $v[10]$ is the
2-component vector giving the number of roots of unity and a generator,
expressed on the integral basis, $v[11]$ is the list of fundamental units,
expressed on the integral basis, $v[12]$ is a vector containing the algebraic
numbers alpha corresponding to the columns of the matrix \kbd{matalpha},
expressed on the integral basis.
All the components are exact (integral or rational), except for the roots in
$v[5]$.
Function: bnfdecodemodule
Class: basic
Section: number_fields
C-Name: decodemodule
Prototype: GG
Help: bnfdecodemodule(nf,m): given a coded module m as in bnrdisclist,
gives the true module.
Doc: if $m$ is a module as output in the
first component of an extension given by \kbd{bnrdisclist}, outputs the
true module.
\bprog
? K = bnfinit(x^2+23); L = bnrdisclist(K, 10); s = L[1][2]
%1 = [[Mat([8, 1]), [[0, 0, 0]]], [Mat([9, 1]), [[0, 0, 0]]]]
? bnfdecodemodule(K, s[1][1])
%2 =
[2 0]
[0 1]
@eprog
Function: bnfinit
Class: basic
Section: number_fields
C-Name: bnfinit0
Prototype: GD0,L,DGp
Help: bnfinit(P,{flag=0},{tech=[]}): compute the necessary data for future
use in ideal and unit group computations, including fundamental units if
they are not too large. flag and tech are both optional. flag can be any of
0: default, 1: insist on having fundamental units.
See manual for details about tech.
Description:
(gen):bnf:prec Buchall($1, 0, $prec)
(gen, 0):bnf:prec Buchall($1, 0, $prec)
(gen, 1):bnf:prec Buchall($1, nf_FORCE, $prec)
(gen, ?small, ?gen):bnf:prec bnfinit0($1, $2, $3, $prec)
Doc: initializes a
\kbd{bnf} structure. Used in programs such as \kbd{bnfisprincipal},
\kbd{bnfisunit} or \kbd{bnfnarrow}. By default, the results are conditional
on the GRH, see \ref{se:GRHbnf}. The result is a
10-component vector \var{bnf}.
This implements \idx{Buchmann}'s sub-exponential algorithm for computing the
class group, the regulator and a system of \idx{fundamental units} of the
general algebraic number field $K$ defined by the irreducible polynomial $P$
with integer coefficients.
If the precision becomes insufficient, \kbd{gp} does not strive to compute
the units by default ($\fl=0$).
When $\fl=1$, we insist on finding the fundamental units exactly. Be
warned that this can take a very long time when the coefficients of the
fundamental units on the integral basis are very large. If the fundamental
units are simply too large to be represented in this form, an error message
is issued. They could be obtained using the so-called compact representation
of algebraic numbers as a formal product of algebraic integers. The latter is
implemented internally but not publicly accessible yet.
$\var{tech}$ is a technical vector (empty by default, see \ref{se:GRHbnf}).
Careful use of this parameter may speed up your computations,
but it is mostly obsolete and you should leave it alone.
\smallskip
The components of a \var{bnf} or \var{sbnf} are technical and never used by
the casual user. In fact: \emph{never access a component directly, always use
a proper member function.} However, for the sake of completeness and internal
documentation, their description is as follows. We use the notations
explained in the book by H. Cohen, \emph{A Course in Computational Algebraic
Number Theory}, Graduate Texts in Maths \key{138}, Springer-Verlag, 1993,
Section 6.5, and subsection 6.5.5 in particular.
$\var{bnf}[1]$ contains the matrix $W$, i.e.~the matrix in Hermite normal
form giving relations for the class group on prime ideal generators
$(\goth{p}_i)_{1\le i\le r}$.
$\var{bnf}[2]$ contains the matrix $B$, i.e.~the matrix containing the
expressions of the prime ideal factorbase in terms of the $\goth{p}_i$.
It is an $r\times c$ matrix.
$\var{bnf}[3]$ contains the complex logarithmic embeddings of the system of
fundamental units which has been found. It is an $(r_1+r_2)\times(r_1+r_2-1)$
matrix.
$\var{bnf}[4]$ contains the matrix $M''_C$ of Archimedean components of the
relations of the matrix $(W|B)$.
$\var{bnf}[5]$ contains the prime factor base, i.e.~the list of prime
ideals used in finding the relations.
$\var{bnf}[6]$ used to contain a permutation of the prime factor base, but
has been obsoleted. It contains a dummy $0$.
$\var{bnf}[7]$ or \kbd{\var{bnf}.nf} is equal to the number field data
$\var{nf}$ as would be given by \kbd{nfinit}.
$\var{bnf}[8]$ is a vector containing the classgroup \kbd{\var{bnf}.clgp}
as a finite abelian group, the regulator \kbd{\var{bnf}.reg}, a $1$ (used to
contain an obsolete ``check number''), the number of roots of unity and a
generator \kbd{\var{bnf}.tu}, the fundamental units \kbd{\var{bnf}.fu}.
$\var{bnf}[9]$ is a 3-element row vector used in \tet{bnfisprincipal} only
and obtained as follows. Let $D = U W V$ obtained by applying the
\idx{Smith normal form} algorithm to the matrix $W$ (= $\var{bnf}[1]$) and
let $U_r$ be the reduction of $U$ modulo $D$. The first elements of the
factorbase are given (in terms of \kbd{bnf.gen}) by the columns of $U_r$,
with Archimedean component $g_a$; let also $GD_a$ be the Archimedean
components of the generators of the (principal) ideals defined by the
\kbd{bnf.gen[i]\pow bnf.cyc[i]}. Then $\var{bnf}[9]=[U_r, g_a, GD_a]$.
$\var{bnf}[10]$ is by default unused and set equal to 0. This field is used
to store further information about the field as it becomes available, which
is rarely needed, hence would be too expensive to compute during the initial
\kbd{bnfinit} call. For instance, the generators of the principal ideals
\kbd{bnf.gen[i]\pow bnf.cyc[i]} (during a call to \tet{bnrisprincipal}), or
those corresponding to the relations in $W$ and $B$ (when the \kbd{bnf}
internal precision needs to be increased).
Variant:
Also available is \fun{GEN}{Buchall}{GEN P, long flag, long prec},
corresponding to \kbd{tech = NULL}, where
\kbd{flag} is either $0$ (default) or \tet{nf_FORCE} (insist on finding
fundamental units). The function
\fun{GEN}{Buchall_param}{GEN P, double c1, double c2, long nrpid, long flag, long prec} gives direct access to the technical parameters.
Function: bnfisintnorm
Class: basic
Section: number_fields
C-Name: bnfisintnorm
Prototype: GG
Help: bnfisintnorm(bnf,x): compute a complete system of solutions (modulo
units of positive norm) of the absolute norm equation N(a)=x, where a
belongs to the maximal order of big number field bnf (if bnf is not
certified, this depends on GRH).
Doc: computes a complete system of
solutions (modulo units of positive norm) of the absolute norm equation
$\Norm(a)=x$,
where $a$ is an integer in $\var{bnf}$. If $\var{bnf}$ has not been certified,
the correctness of the result depends on the validity of \idx{GRH}.
See also \tet{bnfisnorm}.
Variant: The function \fun{GEN}{bnfisintnormabs}{GEN bnf, GEN a}
returns a complete system of solutions modulo units of the absolute norm
equation $|\Norm(x)| = |a|$. As fast as \kbd{bnfisintnorm}, but solves
the two equations $\Norm(x) = \pm a$ simultaneously.
Function: bnfisnorm
Class: basic
Section: number_fields
C-Name: bnfisnorm
Prototype: GGD1,L,
Help: bnfisnorm(bnf,x,{flag=1}): tries to tell whether x (in Q) is the norm
of some fractional y (in bnf). Returns a vector [a,b] where x=Norm(a)*b.
Looks for a solution which is a S-unit, with S a certain list of primes (in
bnf) containing (among others) all primes dividing x. If bnf is known to be
Galois, set flag=0 (in this case, x is a norm iff b=1). If flag is non zero
the program adds to S all the primes: dividing flag if flag<0, or less than
flag if flag>0. The answer is guaranteed (i.e x norm iff b=1) under GRH, if
S contains all primes less than 12.log(disc(Bnf))^2, where Bnf is the Galois
closure of bnf.
Doc: tries to tell whether the
rational number $x$ is the norm of some element y in $\var{bnf}$. Returns a
vector $[a,b]$ where $x=Norm(a)*b$. Looks for a solution which is an $S$-unit,
with $S$ a certain set of prime ideals containing (among others) all primes
dividing $x$. If $\var{bnf}$ is known to be \idx{Galois}, set $\fl=0$ (in
this case, $x$ is a norm iff $b=1$). If $\fl$ is non zero the program adds to
$S$ the following prime ideals, depending on the sign of $\fl$. If $\fl>0$,
the ideals of norm less than $\fl$. And if $\fl<0$ the ideals dividing $\fl$.
Assuming \idx{GRH}, the answer is guaranteed (i.e.~$x$ is a norm iff $b=1$),
if $S$ contains all primes less than $12\log(\disc(\var{Bnf}))^2$, where
$\var{Bnf}$ is the Galois closure of $\var{bnf}$.
See also \tet{bnfisintnorm}.
Function: bnfisprincipal
Class: basic
Section: number_fields
C-Name: bnfisprincipal0
Prototype: GGD1,L,
Help: bnfisprincipal(bnf,x,{flag=1}): bnf being output by bnfinit (with
flag<=2), gives [v,alpha], where v is the vector of exponents on
the class group generators and alpha is the generator of the resulting
principal ideal. In particular x is principal if and only if v is the zero
vector. flag is optional, whose binary digits mean 1: output [v,alpha] (only v
if unset); 2: increase precision until alpha can be computed (do not insist
if unset).
Doc: $\var{bnf}$ being the \sidx{principal ideal}
number field data output by \kbd{bnfinit}, and $x$ being an ideal, this
function tests whether the ideal is principal or not. The result is more
complete than a simple true/false answer and solves general discrete
logarithm problem. Assume the class group is $\oplus (\Z/d_i\Z)g_i$
(where the generators $g_i$ and their orders $d_i$ are respectively given by
\kbd{bnf.gen} and \kbd{bnf.cyc}). The routine returns a row vector $[e,t]$,
where $e$ is a vector of exponents $0 \leq e_i < d_i$, and $t$ is a number
field element such that
$$ x = (t) \prod_i g_i^{e_i}.$$
For \emph{given} $g_i$ (i.e. for a given \kbd{bnf}), the $e_i$ are unique,
and $t$ is unique modulo units.
In particular, $x$ is principal if and only if $e$ is the zero vector. Note
that the empty vector, which is returned when the class number is $1$, is
considered to be a zero vector (of dimension $0$).
\bprog
? K = bnfinit(y^2+23);
? K.cyc
%2 = [3]
? K.gen
%3 = [[2, 0; 0, 1]] \\ a prime ideal above 2
? P = idealprimedec(K,3)[1]; \\ a prime ideal above 3
? v = bnfisprincipal(K, P)
%5 = [[2]~, [3/4, 1/4]~]
? idealmul(K, v[2], idealfactorback(K, K.gen, v[1]))
%6 =
[3 0]
[0 1]
? % == idealhnf(K, P)
%7 = 1
@eprog
\noindent The binary digits of \fl mean:
\item $1$: If set, outputs $[e,t]$ as explained above, otherwise returns
only $e$, which is much easier to compute. The following idiom only tests
whether an ideal is principal:
\bprog
is_principal(bnf, x) = !bnfisprincipal(bnf,x,0);
@eprog
\item $2$: It may not be possible to recover $t$, given the initial accuracy
to which the \kbd{bnf} structure was computed. In that case, a warning is
printed and $t$ is set equal to the empty vector \kbd{[]\til}. If this bit is
set, increase the precision and recompute needed quantities until $t$ can be
computed. Warning: setting this may induce \emph{lengthy} computations.
Variant: Instead of the above hardcoded numerical flags, one should
rather use an or-ed combination of the symbolic flags \tet{nf_GEN} (include
generators, possibly a place holder if too difficult) and \tet{nf_FORCE}
(insist on finding the generators).
Function: bnfissunit
Class: basic
Section: number_fields
C-Name: bnfissunit
Prototype: GGG
Help: bnfissunit(bnf,sfu,x): bnf being output by bnfinit (with flag<=2), sfu
by bnfsunit, gives the column vector of exponents of x on the fundamental
S-units and the roots of unity if x is a unit, the empty vector otherwise.
Doc: $\var{bnf}$ being output by
\kbd{bnfinit}, \var{sfu} by \kbd{bnfsunit}, gives the column vector of
exponents of $x$ on the fundamental $S$-units and the roots of unity.
If $x$ is not a unit, outputs an empty vector.
Function: bnfisunit
Class: basic
Section: number_fields
C-Name: bnfisunit
Prototype: GG
Help: bnfisunit(bnf,x): bnf being output by bnfinit, gives
the column vector of exponents of x on the fundamental units and the roots
of unity if x is a unit, the empty vector otherwise.
Doc: \var{bnf} being the number field data
output by \kbd{bnfinit} and $x$ being an algebraic number (type integer,
rational or polmod), this outputs the decomposition of $x$ on the fundamental
units and the roots of unity if $x$ is a unit, the empty vector otherwise.
More precisely, if $u_1$,\dots,$u_r$ are the fundamental units, and $\zeta$
is the generator of the group of roots of unity (\kbd{bnf.tu}), the output is
a vector $[x_1,\dots,x_r,x_{r+1}]$ such that $x=u_1^{x_1}\cdots
u_r^{x_r}\cdot\zeta^{x_{r+1}}$. The $x_i$ are integers for $i\le r$ and is an
integer modulo the order of $\zeta$ for $i=r+1$.
Note that \var{bnf} need not contain the fundamental unit explicitly:
\bprog
? setrand(1); bnf = bnfinit(x^2-x-100000);
? bnf.fu
*** at top-level: bnf.fu
*** ^--
*** _.fu: missing units in .fu.
? u = [119836165644250789990462835950022871665178127611316131167, \
379554884019013781006303254896369154068336082609238336]~;
? bnfisunit(bnf, u)
%3 = [-1, Mod(0, 2)]~
@eprog\noindent The given $u$ is the inverse of the fundamental unit
implicitly stored in \var{bnf}. In this case, the fundamental unit was not
computed and stored in algebraic form since the default accuracy was too
low. (Re-run the command at \bs g1 or higher to see such diagnostics.)
Function: bnflog
Class: basic
Section: number_fields
C-Name: bnflog
Prototype: GG
Help: bnflog(bnf, l): let bnf be attached to a number field F and let l be
a prime number. Return the logarithmic l-class group Cl~_F.
Doc: let \var{bnf} be attached to a number field $F$ and let $l$ be
a prime number (hereafter denoted $\ell$ for typographical reasons). Return
the logarithmic $\ell$-class group $\widetilde{Cl}_F$
of $F$. This is an abelian group, conjecturally finite (known to be finite
if $F/\Q$ is abelian). The function returns if and only if
the group is indeed finite (otherwise it would run into an infinite loop).
Let $S = \{ \goth{p}_1,\dots, \goth{p}_k\}$ be the set of $\ell$-adic places
(maximal ideals containing $\ell$).
The function returns $[D, G(\ell), G']$, where
\item $D$ is the vector of elementary divisors for $\widetilde{Cl}_F$;
\item $G(\ell)$ is the vector of elementary divisors for
the (conjecturally finite) abelian group
$$\widetilde{\Cl}(\ell) =
\{ \goth{a} = \sum_{i \leq k} a_i \goth{p}_i :~\deg_F \goth{a} = 0\},$$
where the $\goth{p}_i$ are the $\ell$-adic places of $F$; this is a
subgroup of $\widetilde{\Cl}$.
\item $G'$ is the vector of elementary divisors for the $\ell$-Sylow $Cl'$
of the $S$-class group of $F$; the group $\widetilde{\Cl}$ maps to $Cl'$
with a simple co-kernel.
Function: bnflogdegree
Class: basic
Section: number_fields
C-Name: bnflogdegree
Prototype: GGG
Help: bnflogdegree(nf, A, l): let A be an ideal, return exp(deg_F A)
the exponential of the l-adic logarithmic degree.
Doc: Let \var{nf} be the number field data output by \kbd{nfinit},
attached to the field $F$, and let $l$ be a prime number (hereafter
denoted $\ell$). The
$\ell$-adified group of id\`{e}les of $F$ quotiented by
the group of logarithmic units is identified to the $\ell$-group
of logarithmic divisors $\oplus \Z_\ell [\goth{p}]$, generated by the
maximal ideals of $F$.
The \emph{degree} map $\deg_F$ is additive with values in $\Z_\ell$,
defined by $\deg_F \goth{p} = \tilde{f}_{\goth{p}} \deg_\ell p$,
where the integer $\tilde{f}$ is as in \tet{bnflogef} and $\deg_\ell p$
is $\log_\ell p$ for $p\neq \ell$, $\log_\ell (1 + \ell)$ for
$p = \ell\neq 2$ and $\log_\ell (1 + 2^2)$ for $p = \ell = 2$.
Let $A = \prod \goth{p}^{n_{\goth{p}}}$ be an ideal and let $\tilde{A} =
\sum n_\goth{p} [\goth{p}]$ be the attached logarithmic divisor. Return the
exponential of the $\ell$-adic logarithmic degree $\deg_F A$, which is a
natural number.
Function: bnflogef
Class: basic
Section: number_fields
C-Name: bnflogef
Prototype: GG
Help: bnflogef(nf,pr): return [e~, f~] the logarithmic ramification and
residue degrees for the maximal ideal pr.
Doc: let $F$ be a number field represented by the \var{nf} structure,
and let \var{pr} be a \kbd{prid} structure attached to the
maximal ideal $\goth{p} / p$. Return
$[\tilde{e}(F_\goth{p} / \Q_p), \tilde{f}(F_\goth{p} / \Q_p)]$
the logarithmic ramification and residue degrees. Let $\Q_p^c/\Q_p$ be the
cyclotomic $\Z_p$-extension, then
$\tilde{e} = [F_\goth{p} \colon F_\goth{p} \cap \Q_p^c]$
$\tilde{f} = [F_\goth{p} \cap \Q_p^c \colon \Q_p]$. Note that
$\tilde{e}\tilde{f} = e(\goth{p}/p) f(\goth{p}/p)$, where $e,f$ denote the
usual ramification and residue degrees.
\bprog
? F = nfinit(y^6 - 3*y^5 + 5*y^3 - 3*y + 1);
? bnflogef(F, idealprimedec(F,2)[1])
%2 = [6, 1]
? bnflogef(F, idealprimedec(F,5)[1])
%3 = [1, 2]
@eprog
Function: bnfnarrow
Class: basic
Section: number_fields
C-Name: buchnarrow
Prototype: G
Help: bnfnarrow(bnf): given a big number field as output by bnfinit, gives
as a 3-component vector the structure of the narrow class group.
Doc: \var{bnf} being as output by
\kbd{bnfinit}, computes the narrow class group of \var{bnf}. The output is
a 3-component row vector $v$ analogous to the corresponding class group
component \kbd{\var{bnf}.clgp}: the first component
is the narrow class number \kbd{$v$.no}, the second component is a vector
containing the SNF\sidx{Smith normal form} cyclic components \kbd{$v$.cyc} of
the narrow class group, and the third is a vector giving the generators of
the corresponding \kbd{$v$.gen} cyclic groups. Note that this function is a
special case of \kbd{bnrinit}; the \var{bnf} need not contain fundamental
units.
Function: bnfsignunit
Class: basic
Section: number_fields
C-Name: signunits
Prototype: G
Help: bnfsignunit(bnf): matrix of signs of the real embeddings of the system
of fundamental units found by bnfinit.
Doc: $\var{bnf}$ being as output by
\kbd{bnfinit}, this computes an $r_1\times(r_1+r_2-1)$ matrix having $\pm1$
components, giving the signs of the real embeddings of the fundamental units.
The following functions compute generators for the totally positive units:
\bprog
/* exponents of totally positive units generators on bnf.tufu */
tpuexpo(bnf)=
{ my(K, S = bnfsignunit(bnf), [m,n] = matsize(S));
\\ m = bnf.r1, n = r1+r2-1
S = matrix(m,n, i,j, if (S[i,j] < 0, 1,0));
S = concat(vectorv(m,i,1), S); \\ add sign(-1)
K = matker(S * Mod(1,2));
if (K, mathnfmodid(lift(K), 2), 2*matid(n+1))
}
/* totally positive fundamental units */
tpu(bnf)=
{ my(ex = tpuexpo(bnf)[,2..-1]); \\ remove ex[,1], corresponds to 1 or -1
vector(#ex, i, nffactorback(bnf, bnf.tufu, ex[,i]));
}
@eprog
Function: bnfsunit
Class: basic
Section: number_fields
C-Name: bnfsunit
Prototype: GGp
Help: bnfsunit(bnf,S): compute the fundamental S-units of the number field
bnf output by bnfinit, S being a list of prime ideals. res[1] contains the
S-units, res[5] the S-classgroup. See manual for details.
Doc: computes the fundamental $S$-units of the
number field $\var{bnf}$ (output by \kbd{bnfinit}), where $S$ is a list of
prime ideals (output by \kbd{idealprimedec}). The output is a vector $v$ with
6 components.
$v[1]$ gives a minimal system of (integral) generators of the $S$-unit group
modulo the unit group.
$v[2]$ contains technical data needed by \kbd{bnfissunit}.
$v[3]$ is an empty vector (used to give the logarithmic embeddings of the
generators in $v[1]$ in version 2.0.16).
$v[4]$ is the $S$-regulator (this is the product of the regulator, the
determinant of $v[2]$ and the natural logarithms of the norms of the ideals
in $S$).
$v[5]$ gives the $S$-class group structure, in the usual format
(a row vector whose three components give in order the $S$-class number,
the cyclic components and the generators).
$v[6]$ is a copy of $S$.
Function: bnrL1
Class: basic
Section: number_fields
C-Name: bnrL1
Prototype: GDGD0,L,p
Help: bnrL1(bnr, {H}, {flag=0}): bnr being output by bnrinit(,,1) and
H being a square matrix defining a congruence subgroup of bnr (the
trivial subgroup if omitted), for each character of bnr trivial on this
subgroup, compute L(1, chi) (or equivalently the first non-zero term c(chi)
of the expansion at s = 0). The binary digits of flag mean 1: if 0 then
compute the term c(chi) and return [r(chi), c(chi)] where r(chi) is the
order of L(s, chi) at s = 0, or if 1 then compute the value at s = 1 (and in
this case, only for non-trivial characters), 2: if 0 then compute the value
of the primitive L-function attached to chi, if 1 then compute the value
of the L-function L_S(s, chi) where S is the set of places dividing the
modulus of bnr (and the infinite places), 3: return also the characters.
Doc: let \var{bnr} be the number field data output by \kbd{bnrinit(,,1)} and
\var{H} be a square matrix defining a congruence subgroup of the
ray class group corresponding to \var{bnr} (the trivial congruence subgroup
if omitted). This function returns, for each \idx{character} $\chi$ of the ray
class group which is trivial on $H$, the value at $s = 1$ (or $s = 0$) of the
abelian $L$-function attached to $\chi$. For the value at $s = 0$, the
function returns in fact for each $\chi$ a vector $[r_\chi, c_\chi]$ where
$$L(s, \chi) = c \cdot s^r + O(s^{r + 1})$$
\noindent near $0$.
The argument \fl\ is optional, its binary digits
mean 1: compute at $s = 0$ if unset or $s = 1$ if set, 2: compute the
primitive $L$-function attached to $\chi$ if unset or the $L$-function
with Euler factors at prime ideals dividing the modulus of \var{bnr} removed
if set (that is $L_S(s, \chi)$, where $S$ is the
set of infinite places of the number field together with the finite prime
ideals dividing the modulus of \var{bnr}), 3: return also the character if
set.
\bprog
K = bnfinit(x^2-229);
bnr = bnrinit(K,1,1);
bnrL1(bnr)
@eprog\noindent
returns the order and the first non-zero term of $L(s, \chi)$ at $s = 0$
where $\chi$ runs through the characters of the class group of
$K = \Q(\sqrt{229})$. Then
\bprog
bnr2 = bnrinit(K,2,1);
bnrL1(bnr2,,2)
@eprog\noindent
returns the order and the first non-zero terms of $L_S(s, \chi)$ at $s = 0$
where $\chi$ runs through the characters of the class group of $K$ and $S$ is
the set of infinite places of $K$ together with the finite prime $2$. Note
that the ray class group modulo $2$ is in fact the class group, so
\kbd{bnrL1(bnr2,0)} returns the same answer as \kbd{bnrL1(bnr,0)}.
This function will fail with the message
\bprog
*** bnrL1: overflow in zeta_get_N0 [need too many primes].
@eprog\noindent if the approximate functional equation requires us to sum
too many terms (if the discriminant of $K$ is too large).
Function: bnrchar
Class: basic
Section: number_fields
C-Name: bnrchar
Prototype: GGDG
Help: bnrchar(bnr,g,{v}): returns all characters chi on bnr.clgp such that
chi(g[i]) = e(v[i]); if v is omitted, returns all characters that are
trivial on the g[i].
Doc: returns all characters $\chi$ on \kbd{bnr.clgp} such that
$\chi(g_i) = e(v_i)$, where $e(x) = \exp(2i\pi x)$. If $v$ is omitted,
returns all characters that are trivial on the $g_i$. Else the vectors $g$
and $v$ must have the same length, the $g_i$ must be ideals in any form, and
each $v_i$ is a rational number whose denominator must divide the order of
$g_i$ in the ray class group. For convenience, the vector of the $g_i$
can be replaced by a matrix whose columns give their discrete logarithm,
as given by \kbd{bnrisprincipal}; this allows to specify abstractly a
subgroup of the ray class group.
\bprog
? bnr = bnrinit(bnfinit(x), [160,[1]], 1); /* (Z/160Z)^* */
? bnr.cyc
%2 = [8, 4, 2]
? g = bnr.gen;
? bnrchar(bnr, g, [1/2,0,0])
%4 = [[4, 0, 0]] \\ a unique character
? bnrchar(bnr, [g[1],g[3]]) \\ all characters trivial on g[1] and g[3]
%5 = [[0, 1, 0], [0, 2, 0], [0, 3, 0], [0, 0, 0]]
? bnrchar(bnr, [1,0,0;0,1,0;0,0,2])
%6 = [[0, 0, 1], [0, 0, 0]] \\ characters trivial on given subgroup
@eprog
Function: bnrclassno
Class: basic
Section: number_fields
C-Name: bnrclassno0
Prototype: GDGDG
Help: bnrclassno(A,{B},{C}): relative degree of the class field defined by
A,B,C. [A,{B},{C}] is of type [bnr], [bnr,subgroup], [bnf,modulus],
or [bnf,modulus,subgroup].
Faster than bnrinit if only the ray class number is wanted.
Doc:
let $A$, $B$, $C$ define a class field $L$ over a ground field $K$
(of type \kbd{[\var{bnr}]},
\kbd{[\var{bnr}, \var{subgroup}]},
or \kbd{[\var{bnf}, \var{modulus}]},
or \kbd{[\var{bnf}, \var{modulus},\var{subgroup}]},
\secref{se:CFT}); this function returns the relative degree $[L:K]$.
In particular if $A$ is a \var{bnf} (with units), and $B$ a modulus,
this function returns the corresponding ray class number modulo $B$.
One can input the attached \var{bid} (with generators if the subgroup
$C$ is non trivial) for $B$ instead of the module itself, saving some time.
This function is faster than \kbd{bnrinit} and should be used if only the
ray class number is desired. See \tet{bnrclassnolist} if you need ray class
numbers for all moduli less than some bound.
Variant: Also available is
\fun{GEN}{bnrclassno}{GEN bnf,GEN f} to compute the ray class number
modulo~$f$.
Function: bnrclassnolist
Class: basic
Section: number_fields
C-Name: bnrclassnolist
Prototype: GG
Help: bnrclassnolist(bnf,list): if list is as output by ideallist or
similar, gives list of corresponding ray class numbers.
Doc: $\var{bnf}$ being as
output by \kbd{bnfinit}, and \var{list} being a list of moduli (with units) as
output by \kbd{ideallist} or \kbd{ideallistarch}, outputs the list of the
class numbers of the corresponding ray class groups. To compute a single
class number, \tet{bnrclassno} is more efficient.
\bprog
? bnf = bnfinit(x^2 - 2);
? L = ideallist(bnf, 100, 2);
? H = bnrclassnolist(bnf, L);
? H[98]
%4 = [1, 3, 1]
? l = L[1][98]; ids = vector(#l, i, l[i].mod[1])
%5 = [[98, 88; 0, 1], [14, 0; 0, 7], [98, 10; 0, 1]]
@eprog
The weird \kbd{l[i].mod[1]}, is the first component of \kbd{l[i].mod}, i.e.
the finite part of the conductor. (This is cosmetic: since by construction
the Archimedean part is trivial, I do not want to see it). This tells us that
the ray class groups modulo the ideals of norm 98 (printed as \kbd{\%5}) have
respectively order $1$, $3$ and $1$. Indeed, we may check directly:
\bprog
? bnrclassno(bnf, ids[2])
%6 = 3
@eprog
Function: bnrconductor
Class: basic
Section: number_fields
C-Name: bnrconductor0
Prototype: GDGDGD0,L,
Help: bnrconductor(A,{B},{C},{flag=0}): conductor f of the subfield of
the ray class field given by A,B,C. flag is optional and
can be 0: default, 1: returns [f, Cl_f, H], H subgroup of the ray class
group modulo f defining the extension, 2: returns [f, bnr(f), H].
Doc: conductor $f$ of the subfield of a ray class field as defined by $[A,B,C]$
(of type \kbd{[\var{bnr}]},
\kbd{[\var{bnr}, \var{subgroup}]},
\kbd{[\var{bnf}, \var{modulus}]} or
\kbd{[\var{bnf}, \var{modulus}, \var{subgroup}]},
\secref{se:CFT})
If $\fl = 0$, returns $f$.
If $\fl = 1$, returns $[f, Cl_f, H]$, where $Cl_f$ is the ray class group
modulo $f$, as a finite abelian group; finally $H$ is the subgroup of $Cl_f$
defining the extension.
If $\fl = 2$, returns $[f, \var{bnr}(f), H]$, as above except $Cl_f$ is
replaced by a \kbd{bnr} structure, as output by $\tet{bnrinit}(,f,1)$.
In place of a subgroup $H$, this function also accepts a character
\kbd{chi} $=(a_j)$, expressed as usual in terms of the generators
\kbd{bnr.gen}: $\chi(g_j) = \exp(2i\pi a_j / d_j)$, where $g_j$ has
order $d_j = \kbd{bnr.cyc[j]}$. In which case, the function returns
respectively
If $\fl = 0$, the conductor $f$ of $\text{Ker} \chi$.
If $\fl = 1$, $[f, Cl_f, \chi_f]$, where $\chi_f$ is $\chi$ expressed
on the minimal ray class group, whose modulus is the conductor.
If $\fl = 2$, $[f, \var{bnr}(f), \chi_f]$.
Variant:
Also available is \fun{GEN}{bnrconductor}{GEN bnr, GEN H, long flag}
Function: bnrconductorofchar
Class: basic
Section: number_fields
C-Name: bnrconductorofchar
Prototype: GG
Help: bnrconductorofchar(bnr,chi): this function is obsolete, use bnrconductor.
Doc: This function is obsolete, use \tev{bnrconductor}.
Obsolete: 2015-11-11
Function: bnrdisc
Class: basic
Section: number_fields
C-Name: bnrdisc0
Prototype: GDGDGD0,L,
Help: bnrdisc(A,{B},{C},{flag=0}): absolute or relative [N,R1,discf] of
the field defined by A,B,C. [A,{B},{C}] is of type [bnr],
[bnr,subgroup], [bnf, modulus] or [bnf,modulus,subgroup], where bnf is as
output by bnfinit, bnr by bnrinit, and
subgroup is the HNF matrix of a subgroup of the corresponding ray class
group (if omitted, the trivial subgroup). flag is optional whose binary
digits mean 1: give relative data; 2: return 0 if modulus is not the
conductor.
Doc: $A$, $B$, $C$ defining a class field $L$ over a ground field $K$
(of type \kbd{[\var{bnr}]},
\kbd{[\var{bnr}, \var{subgroup}]},
\kbd{[\var{bnr}, \var{character}]},
\kbd{[\var{bnf}, \var{modulus}]} or
\kbd{[\var{bnf}, \var{modulus}, \var{subgroup}]},
\secref{se:CFT}), outputs data $[N,r_1,D]$ giving the discriminant and
signature of $L$, depending on the binary digits of \fl:
\item 1: if this bit is unset, output absolute data related to $L/\Q$:
$N$ is the absolute degree $[L:\Q]$, $r_1$ the number of real places of $L$,
and $D$ the discriminant of $L/\Q$. Otherwise, output relative data for $L/K$:
$N$ is the relative degree $[L:K]$, $r_1$ is the number of real places of $K$
unramified in $L$ (so that the number of real places of $L$ is equal to $r_1$
times $N$), and $D$ is the relative discriminant ideal of $L/K$.
\item 2: if this bit is set and if the modulus is not the conductor of $L$,
only return 0.
Function: bnrdisclist
Class: basic
Section: number_fields
C-Name: bnrdisclist0
Prototype: GGDG
Help: bnrdisclist(bnf,bound,{arch}): gives list of discriminants of
ray class fields of all conductors up to norm bound, in a long vector
The ramified Archimedean places are given by arch; all possible values are
taken if arch is omitted. Supports the alternative syntax
bnrdisclist(bnf,list), where list is as output by ideallist or ideallistarch
(with units).
Doc: $\var{bnf}$ being as output by \kbd{bnfinit} (with units), computes a
list of discriminants of Abelian extensions of the number field by increasing
modulus norm up to bound \var{bound}. The ramified Archimedean places are
given by \var{arch}; all possible values are taken if \var{arch} is omitted.
The alternative syntax $\kbd{bnrdisclist}(\var{bnf},\var{list})$ is
supported, where \var{list} is as output by \kbd{ideallist} or
\kbd{ideallistarch} (with units), in which case \var{arch} is disregarded.
The output $v$ is a vector of vectors, where $v[i][j]$ is understood to be in
fact $V[2^{15}(i-1)+j]$ of a unique big vector $V$. (This awkward scheme
allows for larger vectors than could be otherwise represented.)
$V[k]$ is itself a vector $W$, whose length is the number of ideals of norm
$k$. We consider first the case where \var{arch} was specified. Each
component of $W$ corresponds to an ideal $m$ of norm $k$, and
gives invariants attached to the ray class field $L$ of $\var{bnf}$ of
conductor $[m, \var{arch}]$. Namely, each contains a vector $[m,d,r,D]$ with
the following meaning: $m$ is the prime ideal factorization of the modulus,
$d = [L:\Q]$ is the absolute degree of $L$, $r$ is the number of real places
of $L$, and $D$ is the factorization of its absolute discriminant. We set $d
= r = D = 0$ if $m$ is not the finite part of a conductor.
If \var{arch} was omitted, all $t = 2^{r_1}$ possible values are taken and a
component of $W$ has the form $[m, [[d_1,r_1,D_1], \dots, [d_t,r_t,D_t]]]$,
where $m$ is the finite part of the conductor as above, and
$[d_i,r_i,D_i]$ are the invariants of the ray class field of conductor
$[m,v_i]$, where $v_i$ is the $i$-th Archimedean component, ordered by
inverse lexicographic order; so $v_1 = [0,\dots,0]$, $v_2 = [1,0\dots,0]$,
etc. Again, we set $d_i = r_i = D_i = 0$ if $[m,v_i]$ is not a conductor.
Finally, each prime ideal $pr = [p,\alpha,e,f,\beta]$ in the prime
factorization $m$ is coded as the integer $p\cdot n^2+(f-1)\cdot n+(j-1)$,
where $n$ is the degree of the base field and $j$ is such that
\kbd{pr = idealprimedec(\var{nf},p)[j]}.
\noindent $m$ can be decoded using \tet{bnfdecodemodule}.
Note that to compute such data for a single field, either \tet{bnrclassno}
or \tet{bnrdisc} is more efficient.
Function: bnrgaloisapply
Class: basic
Section: number_fields
C-Name: bnrgaloisapply
Prototype: GGG
Help: bnrgaloisapply(bnr, mat, H): apply the automorphism given by its matrix
mat to the congruence subgroup H given as a HNF matrix. The matrix mat can be
computed with bnrgaloismatrix.
Doc: apply the automorphism given by its matrix \var{mat} to the congruence
subgroup $H$ given as a HNF matrix.
The matrix \var{mat} can be computed with \tet{bnrgaloismatrix}.
Function: bnrgaloismatrix
Class: basic
Section: number_fields
C-Name: bnrgaloismatrix
Prototype: GG
Help: bnrgaloismatrix(bnr,aut): return the matrix of the action of the
automorphism aut of the base field bnf.nf on the generators of the ray class
field bnr.gen. aut can be given as a polynomial, or a vector of automorphisms
or a galois group as output by galoisinit, in which case a vector of matrices
is returned (in the later case, only for the generators aut.gen).
Doc: return the matrix of the action of the automorphism \var{aut} of the base
field \kbd{bnf.nf} on the generators of the ray class field \kbd{bnr.gen}.
\var{aut} can be given as a polynomial, an algebraic number, or a vector of
automorphisms or a Galois group as output by \kbd{galoisinit}, in which case a
vector of matrices is returned (in the later case, only for the generators
\kbd{aut.gen}).
See \kbd{bnrisgalois} for an example.
Variant: When $aut$ is a polynomial or an algebraic number,
\fun{GEN}{bnrautmatrix}{GEN bnr, GEN aut} is available.
Function: bnrinit
Class: basic
Section: number_fields
C-Name: bnrinit0
Prototype: GGD0,L,
Help: bnrinit(bnf,f,{flag=0}): given a bnf as output by
bnfinit and a modulus f, initializes data
linked to the ray class group structure corresponding to this module. flag
is optional, and can be 0: default, 1: compute also the generators.
Description:
(gen,gen,?small):bnr bnrinit0($1, $2, $3)
Doc: $\var{bnf}$ is as
output by \kbd{bnfinit} (including fundamental units), $f$ is a modulus,
initializes data linked to the ray class group structure corresponding to
this module, a so-called \kbd{bnr} structure. One can input the attached
\var{bid} with generators for $f$ instead of the module itself, saving some
time. (As in \tet{idealstar}, the finite part of the conductor may be given
by a factorization into prime ideals, as produced by \tet{idealfactor}.)
The following member functions are available
on the result: \kbd{.bnf} is the underlying \var{bnf},
\kbd{.mod} the modulus, \kbd{.bid} the \kbd{bid} structure attached to the
modulus; finally, \kbd{.clgp}, \kbd{.no}, \kbd{.cyc}, \kbd{.gen} refer to the
ray class group (as a finite abelian group), its cardinality, its elementary
divisors, its generators (only computed if $\fl = 1$).
The last group of functions are different from the members of the underlying
\var{bnf}, which refer to the class group; use \kbd{\var{bnr}.bnf.\var{xxx}}
to access these, e.g.~\kbd{\var{bnr}.bnf.cyc} to get the cyclic decomposition
of the class group.
They are also different from the members of the underlying \var{bid}, which
refer to $(\Z_K/f)^*$; use \kbd{\var{bnr}.bid.\var{xxx}} to access these,
e.g.~\kbd{\var{bnr}.bid.no} to get $\phi(f)$.
If $\fl=0$ (default), the generators of the ray class group are not computed,
which saves time. Hence \kbd{\var{bnr}.gen} would produce an error.
If $\fl=1$, as the default, except that generators are computed.
Variant: Instead the above hardcoded numerical flags, one should rather use
\fun{GEN}{Buchray}{GEN bnf, GEN module, long flag}
where flag is an or-ed combination of \kbd{nf\_GEN} (include generators)
and \kbd{nf\_INIT} (if omitted, return just the cardinality of the ray class
group and its structure), possibly 0.
Function: bnrisconductor
Class: basic
Section: number_fields
C-Name: bnrisconductor0
Prototype: lGDGDG
Help: bnrisconductor(A,{B},{C}): returns 1 if the modulus is the
conductor of the subfield of the ray class field given by A,B,C (see
bnrdisc), and 0 otherwise. Slightly faster than bnrconductor if this is the
only desired result.
Doc: fast variant of \kbd{bnrconductor}$(A,B,C)$; $A$, $B$, $C$ represent
an extension of the base field, given by class field theory
(see~\secref{se:CFT}). Outputs 1 if this modulus is the conductor, and 0
otherwise. This is slightly faster than \kbd{bnrconductor} when the
character or subgroup is not primitive.
Function: bnrisgalois
Class: basic
Section: number_fields
C-Name: bnrisgalois
Prototype: lGGG
Help: bnrisgalois(bnr, gal, H): check whether the class field attached to
the subgroup H is Galois over the subfield of bnr.nf fixed by the Galois
group gal, which can be given as output by galoisinit, or as a matrix or a
vector of matrices as output by bnrgaloismatrix. The ray class field
attached to bnr need to be Galois, which is not checked.
Doc: check whether the class field attached to the subgroup $H$ is Galois
over the subfield of \kbd{bnr.nf} fixed by the group \var{gal}, which can be
given as output by \tet{galoisinit}, or as a matrix or a vector of matrices as
output by \kbd{bnrgaloismatrix}, the second option being preferable, since it
saves the recomputation of the matrices. Note: The function assumes that the
ray class field attached to bnr is Galois, which is not checked.
In the following example, we lists the congruence subgroups of subextension of
degree at most $3$ of the ray class field of conductor $9$ which are Galois
over the rationals.
\bprog
K=bnfinit(a^4-3*a^2+253009);
G=galoisinit(K);
B=bnrinit(K,9,1);
L1=[H|H<-subgrouplist(B,3), bnrisgalois(B,G,H)]
##
M=bnrgaloismatrix(B,G)
L2=[H|H<-subgrouplist(B,3), bnrisgalois(B,M,H)]
##
@eprog
The second computation is much faster since \kbd{bnrgaloismatrix(B,G)} is
computed only once.
Function: bnrisprincipal
Class: basic
Section: number_fields
C-Name: bnrisprincipal
Prototype: GGD1,L,
Help: bnrisprincipal(bnr,x,{flag=1}): bnr being output by bnrinit, gives
[v,alpha], where v is the vector of exponents on the class group
generators and alpha is the generator of the resulting principal ideal. In
particular x is principal if and only if v is the zero vector. If (optional)
flag is set to 0, output only v.
Doc: \var{bnr} being the
number field data which is output by \kbd{bnrinit}$(,,1)$ and $x$ being an
ideal in any form, outputs the components of $x$ on the ray class group
generators in a way similar to \kbd{bnfisprincipal}. That is a 2-component
vector $v$ where $v[1]$ is the vector of components of $x$ on the ray class
group generators, $v[2]$ gives on the integral basis an element $\alpha$ such
that $x=\alpha\prod_ig_i^{x_i}$.
If $\fl=0$, outputs only $v_1$. In that case, \var{bnr} need not contain the
ray class group generators, i.e.~it may be created with \kbd{bnrinit}$(,,0)$
If $x$ is not coprime to the modulus of \var{bnr} the result is undefined.
Variant: Instead of hardcoded numerical flags, one should rather
use
\fun{GEN}{isprincipalray}{GEN bnr, GEN x} for $\kbd{flag} = 0$, and if you
want generators:
\bprog
bnrisprincipal(bnr, x, nf_GEN)
@eprog
Function: bnrrootnumber
Class: basic
Section: number_fields
C-Name: bnrrootnumber
Prototype: GGD0,L,p
Help: bnrrootnumber(bnr,chi,{flag=0}): returns the so-called Artin Root
Number, i.e. the constant W appearing in the functional equation of the
Hecke L-function attached to chi. Set flag = 1 if the character is known
to be primitive.
Doc: if $\chi=\var{chi}$ is a
\idx{character} over \var{bnr}, not necessarily primitive, let
$L(s,\chi) = \sum_{id} \chi(id) N(id)^{-s}$ be the attached
\idx{Artin L-function}. Returns the so-called \idx{Artin root number}, i.e.~the
complex number $W(\chi)$ of modulus 1 such that
%
$$\Lambda(1-s,\chi) = W(\chi) \Lambda(s,\overline{\chi})$$
%
\noindent where $\Lambda(s,\chi) = A(\chi)^{s/2}\gamma_\chi(s) L(s,\chi)$ is
the enlarged L-function attached to $L$.
The generators of the ray class group are needed, and you can set $\fl=1$ if
the character is known to be primitive. Example:
\bprog
bnf = bnfinit(x^2 - x - 57);
bnr = bnrinit(bnf, [7,[1,1]], 1);
bnrrootnumber(bnr, [2,1])
@eprog\noindent
returns the root number of the character $\chi$ of
$\Cl_{7\infty_1\infty_2}(\Q(\sqrt{229}))$ defined by $\chi(g_1^ag_2^b)
= \zeta_1^{2a}\zeta_2^b$. Here $g_1, g_2$ are the generators of the
ray-class group given by \kbd{bnr.gen} and $\zeta_1 = e^{2i\pi/N_1},
\zeta_2 = e^{2i\pi/N_2}$ where $N_1, N_2$ are the orders of $g_1$ and
$g_2$ respectively ($N_1=6$ and $N_2=3$ as \kbd{bnr.cyc} readily tells us).
Function: bnrstark
Class: basic
Section: number_fields
C-Name: bnrstark
Prototype: GDGp
Help: bnrstark(bnr,{subgroup}): bnr being as output by
bnrinit(,,1), finds a relative equation for the class field corresponding to
the module in bnr and the given congruence subgroup (the trivial subgroup if
omitted) using Stark's units. The ground field and the class field must be
totally real.
Doc: \var{bnr} being as output by \kbd{bnrinit(,,1)}, finds a relative equation
for the class field corresponding to the modulus in \var{bnr} and the given
congruence subgroup (as usual, omit $\var{subgroup}$ if you want the whole ray
class group).
The main variable of \var{bnr} must not be $x$, and the ground field and the
class field must be totally real. When the base field is $\Q$, the vastly
simpler \tet{galoissubcyclo} is used instead. Here is an example:
\bprog
bnf = bnfinit(y^2 - 3);
bnr = bnrinit(bnf, 5, 1);
bnrstark(bnr)
@eprog\noindent
returns the ray class field of $\Q(\sqrt{3})$ modulo $5$. Usually, one wants
to apply to the result one of
\bprog
rnfpolredabs(bnf, pol, 16) \\@com compute a reduced relative polynomial
rnfpolredabs(bnf, pol, 16 + 2) \\@com compute a reduced absolute polynomial
@eprog
The routine uses \idx{Stark units} and needs to find a suitable auxiliary
conductor, which may not exist when the class field is not cyclic over the
base. In this case \kbd{bnrstark} is allowed to return a vector of
polynomials defining \emph{independent} relative extensions, whose compositum
is the requested class field. It was decided that it was more useful
to keep the extra information thus made available, hence the user has to take
the compositum herself.
Even if it exists, the auxiliary conductor may be so large that later
computations become unfeasible. (And of course, Stark's conjecture may simply
be wrong.) In case of difficulties, try \tet{rnfkummer}:
\bprog
? bnr = bnrinit(bnfinit(y^8-12*y^6+36*y^4-36*y^2+9,1), 2, 1);
? bnrstark(bnr)
*** at top-level: bnrstark(bnr)
*** ^-------------
*** bnrstark: need 3919350809720744 coefficients in initzeta.
*** Computation impossible.
? lift( rnfkummer(bnr) )
time = 24 ms.
%2 = x^2 + (1/3*y^6 - 11/3*y^4 + 8*y^2 - 5)
@eprog
Function: break
Class: basic
Section: programming/control
C-Name: break0
Prototype: D1,L,
Help: break({n=1}): interrupt execution of current instruction sequence, and
exit from the n innermost enclosing loops.
Doc: interrupts execution of current \var{seq}, and
immediately exits from the $n$ innermost enclosing loops, within the
current function call (or the top level loop); the integer $n$ must be
positive. If $n$ is greater than the number of enclosing loops, all
enclosing loops are exited.
Function: breakpoint
Class: gp
Section: programming/control
C-Name: pari_breakpoint
Prototype: v
Help: breakpoint(): interrupt the program and enter the breakloop. The program
continues when the breakloop is exited.
Doc: Interrupt the program and enter the breakloop. The program continues when
the breakloop is exited.
\bprog
? f(N,x)=my(z=x^2+1);breakpoint();gcd(N,z^2+1-z);
? f(221,3)
*** at top-level: f(221,3)
*** ^--------
*** in function f: my(z=x^2+1);breakpoint();gcd(N,z
*** ^--------------------
*** Break loop: type <Return> to continue; 'break' to go back to GP
break> z
10
break>
%2 = 13
@eprog
Function: call
Class: basic
Section: programming/specific
C-Name: call0
Prototype: GG
Help: call(f, A): A being a vector, evaluates f(A[1],...,A[#A]).
Doc: $A=[a_1,\dots, a_n]$ being a vector and $f$ being a function, returns the
evaluation of $f(a_1,\dots,a_n)$.
$f$ can also be the name of a built-in GP function.
If $\# A =1$, \tet{call}($f,A$) = \tet{apply}($f,A$)[1].
If $f$ is variadic, the variadic arguments must grouped in a vector in
the last component of $A$.
This function is useful
\item when writing a variadic function, to call another one:
\bprog
fprintf(file,format,args[..]) = write(file,call(Strprintf,[format,args]))
@eprog
\item when dealing with function arguments with unspecified arity
The function below implements a global memoization interface:
\bprog
memo=Map();
memoize(f,A[..])=
{
my(res);
if(!mapisdefined(memo, [f,A], &res),
res = call(f,A);
mapput(memo,[f,A],res));
res;
}
@eprog
for example:
\bprog
? memoize(factor,2^128+1)
%3 = [59649589127497217,1;5704689200685129054721,1]
? ##
*** last result computed in 76 ms.
? memoize(factor,2^128+1)
%4 = [59649589127497217,1;5704689200685129054721,1]
? ##
*** last result computed in 0 ms.
? memoize(ffinit,3,3)
%5 = Mod(1,3)*x^3+Mod(1,3)*x^2+Mod(1,3)*x+Mod(2,3)
? fibo(n)=if(n==0,0,n==1,1,memoize(fibo,n-2)+memoize(fibo,n-1));
? fibo(100)
%7 = 354224848179261915075
@eprog
\item to call operators through their internal names without using
\kbd{alias}
\bprog
matnbelts(M) = call("_*_",matsize(M))
@eprog
Function: ceil
Class: basic
Section: conversions
C-Name: gceil
Prototype: G
Help: ceil(x): ceiling of x = smallest integer >= x.
Description:
(small):small:parens $1
(int):int:copy:parens $1
(real):int ceilr($1)
(mp):int mpceil($1)
(gen):gen gceil($1)
Doc:
ceiling of $x$. When $x$ is in $\R$, the result is the
smallest integer greater than or equal to $x$. Applied to a rational
function, $\kbd{ceil}(x)$ returns the Euclidean quotient of the numerator by
the denominator.
Function: centerlift
Class: basic
Section: conversions
C-Name: centerlift0
Prototype: GDn
Help: centerlift(x,{v}): centered lift of x. Same as lift except for
intmod and padic components.
Description:
(pol):pol centerlift($1)
(vec):vec centerlift($1)
(gen):gen centerlift($1)
(pol, var):pol centerlift0($1, $2)
(vec, var):vec centerlift0($1, $2)
(gen, var):gen centerlift0($1, $2)
Doc: Same as \tet{lift}, except that \typ{INTMOD} and \typ{PADIC} components
are lifted using centered residues:
\item for a \typ{INTMOD} $x\in \Z/n\Z$, the lift $y$ is such that
$-n/2<y\le n/2$.
\item a \typ{PADIC} $x$ is lifted in the same way as above (modulo
$p^\kbd{padicprec(x)}$) if its valuation $v$ is non-negative; if not, returns
the fraction $p^v$ \kbd{centerlift}$(x p^{-v})$; in particular, rational
reconstruction is not attempted. Use \tet{bestappr} for this.
For backward compatibility, \kbd{centerlift(x,'v)} is allowed as an alias
for \kbd{lift(x,'v)}.
\synt{centerlift}{GEN x}.
Function: characteristic
Class: basic
Section: conversions
C-Name: characteristic
Prototype: mG
Help: characteristic(x): characteristic of the base ring over which x is
defined.
Doc:
returns the characteristic of the base ring over which $x$ is defined (as
defined by \typ{INTMOD} and \typ{FFELT} components). The function raises an
exception if incompatible primes arise from \typ{FFELT} and \typ{PADIC}
components.
\bprog
? characteristic(Mod(1,24)*x + Mod(1,18)*y)
%1 = 6
@eprog
Function: charconj
Class: basic
Section: number_theoretical
C-Name: charconj0
Prototype: GG
Help: charconj(cyc,chi): given a finite abelian group (by its elementary
divisors cyc) and a character chi, return the conjugate character.
Doc: let \var{cyc} represent a finite abelian group by its elementary
divisors, i.e. $(d_j)$ represents $\sum_{j \leq k} \Z/d_j\Z$ with $d_k
\mid \dots \mid d_1$; any object which has a \kbd{.cyc} method is also
allowed, e.g.~the output of \kbd{znstar} or \kbd{bnrinit}. A character
on this group is given by a row vector $\chi = [a_1,\ldots,a_n]$ such that
$\chi(\prod g_j^{n_j}) = \exp(2\pi i\sum a_j n_j / d_j)$, where $g_j$ denotes
the generator (of order $d_j$) of the $j$-th cyclic component.
This function returns the conjugate character.
\bprog
? cyc = [15,5]; chi = [1,1];
? charconj(cyc, chi)
%2 = [14, 4]
? bnf = bnfinit(x^2+23);
? bnf.cyc
%4 = [3]
? charconj(bnf, [1])
%5 = [2]
@eprog\noindent For Dirichlet characters (when \kbd{cyc} is
\kbd{idealstar(,q)}), characters in Conrey representation are available,
see \secref{se:dirichletchar} or \kbd{??character}:
\bprog
? G = idealstar(,8); \\ (Z/8Z)^*
? charorder(G, 3) \\ Conrey label
%2 = 2
? chi = znconreylog(G, 3);
? charorder(G, chi) \\ Conrey logarithm
%4 = 2
@eprog
Variant: Also available is
\fun{GEN}{charconj}{GEN cyc, GEN chi}, when \kbd{cyc} is known to
be a vector of elementary divisors and \kbd{chi} a compatible character
(no checks).
Function: chardiv
Class: basic
Section: number_theoretical
C-Name: chardiv0
Prototype: GGG
Help: chardiv(cyc, a,b): given a finite abelian group (by its elementary
divisors cyc) and two characters a and b, return the character a/b.
Doc: let \var{cyc} represent a finite abelian group by its elementary
divisors, i.e. $(d_j)$ represents $\sum_{j \leq k} \Z/d_j\Z$ with $d_k
\mid \dots \mid d_1$; any object which has a \kbd{.cyc} method is also
allowed, e.g.~the output of \kbd{znstar} or \kbd{bnrinit}. A character
on this group is given by a row vector $a = [a_1,\ldots,a_n]$ such that
$\chi(\prod g_j^{n_j}) = \exp(2\pi i\sum a_j n_j / d_j)$, where $g_j$ denotes
the generator (of order $d_j$) of the $j$-th cyclic component.
Given two characters $a$ and $b$, return the character
$a / b = a \overline{b}$.
\bprog
? cyc = [15,5]; a = [1,1]; b = [2,4];
? chardiv(cyc, a,b)
%2 = [14, 2]
? bnf = bnfinit(x^2+23);
? bnf.cyc
%4 = [3]
? chardiv(bnf, [1], [2])
%5 = [2]
@eprog\noindent For Dirichlet characters on $(\Z/N\Z)^*$, additional
representations are available (Conrey labels, Conrey logarithm),
see \secref{se:dirichletchar} or \kbd{??character}.
If the two characters are in the same format, the
result is given in the same format, otherwise a Conrey logarithm is used.
\bprog
? G = idealstar(,100);
? G.cyc
%2 = [20, 2]
? a = [10, 1]; \\ usual representation for characters
? b = 7; \\ Conrey label;
? c = znconreylog(G, 11); \\ Conrey log
? chardiv(G, b,b)
%6 = 1 \\ Conrey label
? chardiv(G, a,b)
%7 = [0, 5]~ \\ Conrey log
? chardiv(G, a,c)
%7 = [0, 14]~ \\ Conrey log
@eprog
Variant: Also available is
\fun{GEN}{chardiv}{GEN cyc, GEN a, GEN b}, when \kbd{cyc} is known to
be a vector of elementary divisors and $a, b$ are compatible characters
(no checks).
Function: chareval
Class: basic
Section: number_theoretical
C-Name: chareval
Prototype: GGGDG
Help: chareval(G, chi, x, {z})): given an abelian group structure affording
a discrete logarithm method, e.g. G = idealstar(,N) or a bnr structure,
let x be an element of G and let chi be a character of G. This function
returns the value of chi at x, where the encoding depends on the optional
argument z; if z is omitted, we fix a canonical o-th root of 1, zeta_o,
where o is the character order and return the rational number c/o where
chi(x) = (zeta_o)^c.
Doc:
Let $G$ be an abelian group structure affording a discrete logarithm
method, e.g $G = \kbd{idealstar}(,N)$ for $(\Z/N\Z)^*$ or a \kbd{bnr}
structure, let $x$ be an element of $G$ and let \var{chi} be a character of
$G$ (see the note below for details). This function returns the value of
\var{chi} at $x$.
\misctitle{Note on characters}
Let $K$ be some field. If $G$ is an abelian group,
let $\chi: G \to K^*$ be a character of finite order and let $o$ be a
multiple of the character order such that $\chi(n) = \zeta^{c(n)}$ for some
fixed $\zeta\in K^*$ of multiplicative order $o$ and a unique morphism $c: G
\to (\Z/o\Z,+)$. Our usual convention is to write
$$G = (\Z/o_1\Z) g_1 \oplus \cdots \oplus (\Z/o_d\Z) g_d$$
for some generators $(g_i)$ of respective order $d_i$, where the group has
exponent $o := \text{lcm}_i o_i$. Since $\zeta^o = 1$, the vector $(c_i)$ in
$\prod (\Z/o_i\Z)$ defines a character $\chi$ on $G$ via $\chi(g_i) =
\zeta^{c_i (o/o_i)}$ for all $i$. Classical Dirichlet characters have values
in $K = \C$ and we can take $\zeta = \exp(2i\pi/o)$.
\misctitle{Note on Dirichlet characters}
In the special case where \var{bid} is attached to $G = (\Z/q\Z)^*$
(as per \kbd{bid = idealstar(,q)}), the Dirichlet
character \var{chi} can be written in one of the usual 3 formats: a \typ{VEC}
in terms of \kbd{bid.gen} as above, a \typ{COL} in terms of the Conrey
generators, or a \typ{INT} (Conrey label);
see \secref{se:dirichletchar} or \kbd{??character}.
The character value is encoded as follows, depending on the optional
argument $z$:
\item If $z$ is omitted: return the rational number $c(x)/o$ for $x$ coprime
to $q$, where we normalize $0\leq c(x) < o$. If $x$ can not be mapped to the
group (e.g. $x$ is not coprime to the conductor of a Dirichlet or Hecke
character) we return the sentinel value $-1$.
\item If $z$ is an integer $o$, then we assume that $o$ is a multiple of the
character order and we return the integer $c(x)$ when $x$ belongs
to the group, and the sentinel value $-1$ otherwise.
\item $z$ can be of the form $[\var{zeta}, o]$, where \var{zeta}
is an $o$-th root of $1$ and $o$ is a multiple of the character order.
We return $\zeta^{c(x)}$ if $x$ belongs to the group, and the sentinel
value $0$ otherwise. (Note that this coincides with the usual extension
of Dirichlet characters to $\Z$, or of Hecke characters to general ideals.)
\item Finally, $z$ can be of the form $[\var{vzeta}, o]$, where
\var{vzeta} is a vector of powers $\zeta^0, \dots, \zeta^{o-1}$
of some $o$-th root of $1$ and $o$ is a multiple of the character order.
As above, we return $\zeta^{c(x)}$ after a table lookup. Or the sentinel
value $0$.
Function: charker
Class: basic
Section: number_theoretical
C-Name: charker0
Prototype: GG
Help: charker(cyc,chi): given a finite abelian group (by its elementary
divisors cyc) and a character chi, return its kernel.
Doc: let \var{cyc} represent a finite abelian group by its elementary
divisors, i.e. $(d_j)$ represents $\sum_{j \leq k} \Z/d_j\Z$ with $d_k
\mid \dots \mid d_1$; any object which has a \kbd{.cyc} method is also
allowed, e.g.~the output of \kbd{znstar} or \kbd{bnrinit}. A character
on this group is given by a row vector $\chi = [a_1,\ldots,a_n]$ such that
$\chi(\prod g_j^{n_j}) = \exp(2\pi i\sum a_j n_j / d_j)$, where $g_j$ denotes
the generator (of order $d_j$) of the $j$-th cyclic component.
This function returns the kernel of $\chi$, as a matrix $K$ in HNF which is a
left-divisor of \kbd{matdiagonal(d)}. Its columns express in terms of
the $g_j$ the generators of the subgroup. The determinant of $K$ is the
kernel index.
\bprog
? cyc = [15,5]; chi = [1,1];
? charker(cyc, chi)
%2 =
[15 12]
[ 0 1]
? bnf = bnfinit(x^2+23);
? bnf.cyc
%4 = [3]
? charker(bnf, [1])
%5 =
[3]
@eprog\noindent Note that for Dirichlet characters (when \kbd{cyc} is
\kbd{idealstar(,q)}), characters in Conrey representation are available,
see \secref{se:dirichletchar} or \kbd{??character}.
\bprog
? G = idealstar(,8); \\ (Z/8Z)^*
? charker(G, 1) \\ Conrey label for trivial character
%2 =
[1 0]
[0 1]
@eprog
Variant: Also available is
\fun{GEN}{charker}{GEN cyc, GEN chi}, when \kbd{cyc} is known to
be a vector of elementary divisors and \kbd{chi} a compatible character
(no checks).
Function: charmul
Class: basic
Section: number_theoretical
C-Name: charmul0
Prototype: GGG
Help: charmul(cyc, a,b): given a finite abelian group (by its elementary
divisors cyc) and two characters a and b, return the product character
ab.
Doc: let \var{cyc} represent a finite abelian group by its elementary
divisors, i.e. $(d_j)$ represents $\sum_{j \leq k} \Z/d_j\Z$ with $d_k
\mid \dots \mid d_1$; any object which has a \kbd{.cyc} method is also
allowed, e.g.~the output of \kbd{znstar} or \kbd{bnrinit}. A character
on this group is given by a row vector $a = [a_1,\ldots,a_n]$ such that
$\chi(\prod g_j^{n_j}) = \exp(2\pi i\sum a_j n_j / d_j)$, where $g_j$ denotes
the generator (of order $d_j$) of the $j$-th cyclic component.
Given two characters $a$ and $b$, return the product character $ab$.
\bprog
? cyc = [15,5]; a = [1,1]; b = [2,4];
? charmul(cyc, a,b)
%2 = [3, 0]
? bnf = bnfinit(x^2+23);
? bnf.cyc
%4 = [3]
? charmul(bnf, [1], [2])
%5 = [0]
@eprog\noindent For Dirichlet characters on $(\Z/N\Z)^*$, additional
representations are available (Conrey labels, Conrey logarithm), see
\secref{se:dirichletchar} or \kbd{??character}. If the two characters are in
the same format, their
product is given in the same format, otherwise a Conrey logarithm is used.
\bprog
? G = idealstar(,100);
? G.cyc
%2 = [20, 2]
? a = [10, 1]; \\ usual representation for characters
? b = 7; \\ Conrey label;
? c = znconreylog(G, 11); \\ Conrey log
? charmul(G, b,b)
%6 = 49 \\ Conrey label
? charmul(G, a,b)
%7 = [0, 15]~ \\ Conrey log
? charmul(G, a,c)
%7 = [0, 6]~ \\ Conrey log
@eprog
Variant: Also available is
\fun{GEN}{charmul}{GEN cyc, GEN a, GEN b}, when \kbd{cyc} is known to
be a vector of elementary divisors and $a, b$ are compatible characters
(no checks).
Function: charorder
Class: basic
Section: number_theoretical
C-Name: charorder0
Prototype: GG
Help: charorder(cyc,chi): given a finite abelian group (by its elementary
divisors cyc) and a character chi, return the order of chi.
Doc: let \var{cyc} represent a finite abelian group by its elementary
divisors, i.e. $(d_j)$ represents $\sum_{j \leq k} \Z/d_j\Z$ with $d_k
\mid \dots \mid d_1$; any object which has a \kbd{.cyc} method is also
allowed, e.g.~the output of \kbd{znstar} or \kbd{bnrinit}. A character
on this group is given by a row vector $\chi = [a_1,\ldots,a_n]$ such that
$\chi(\prod g_j^{n_j}) = \exp(2\pi i\sum a_j n_j / d_j)$, where $g_j$ denotes
the generator (of order $d_j$) of the $j$-th cyclic component.
This function returns the order of the character \kbd{chi}.
\bprog
? cyc = [15,5]; chi = [1,1];
? charorder(cyc, chi)
%2 = 15
? bnf = bnfinit(x^2+23);
? bnf.cyc
%4 = [3]
? charorder(bnf, [1])
%5 = 3
@eprog\noindent For Dirichlet characters (when \kbd{cyc} is
\kbd{idealstar(,q)}), characters in Conrey representation are available,
see \secref{se:dirichletchar} or \kbd{??character}:
\bprog
? G = idealstar(,100); \\ (Z/100Z)^*
? charorder(G, 7) \\ Conrey label
%2 = 4
@eprog
Variant: Also available is
\fun{GEN}{charorder}{GEN cyc, GEN chi}, when \kbd{cyc} is known to
be a vector of elementary divisors and \kbd{chi} a compatible character
(no checks).
Function: charpoly
Class: basic
Section: linear_algebra
C-Name: charpoly0
Prototype: GDnD5,L,
Help: charpoly(A,{v='x},{flag=5}): det(v*Id-A)=characteristic polynomial of
the matrix or polmod A. flag is optional and ignored unless A is a matrix;
it may be set to 0 (Le Verrier), 1 (Lagrange interpolation),
2 (Hessenberg form), 3 (Berkowitz), 4 (modular) if A is integral,
or 5 (default, choose best method).
Algorithms 0 (Le Verrier) and 1 (Lagrange) assume that n! is invertible,
where n is the dimension of the matrix.
Doc:
\idx{characteristic polynomial}
of $A$ with respect to the variable $v$, i.e.~determinant of $v*I-A$ if $A$
is a square matrix.
\bprog
? charpoly([1,2;3,4]);
%1 = x^2 - 5*x - 2
? charpoly([1,2;3,4],, 't)
%2 = t^2 - 5*t - 2
@eprog\noindent
If $A$ is not a square matrix, the function returns the characteristic
polynomial of the map ``multiplication by $A$'' if $A$ is a scalar:
\bprog
? charpoly(Mod(x+2, x^3-2))
%1 = x^3 - 6*x^2 + 12*x - 10
? charpoly(I)
%2 = x^2 + 1
? charpoly(quadgen(5))
%3 = x^2 - x - 1
? charpoly(ffgen(ffinit(2,4)))
%4 = Mod(1, 2)*x^4 + Mod(1, 2)*x^3 + Mod(1, 2)*x^2 + Mod(1, 2)*x + Mod(1, 2)
@eprog
The value of $\fl$ is only significant for matrices, and we advise to stick
to the default value. Let $n$ be the dimension of $A$.
If $\fl=0$, same method (Le Verrier's) as for computing the adjoint matrix,
i.e.~using the traces of the powers of $A$. Assumes that $n!$ is
invertible; uses $O(n^4)$ scalar operations.
If $\fl=1$, uses Lagrange interpolation which is usually the slowest method.
Assumes that $n!$ is invertible; uses $O(n^4)$ scalar operations.
If $\fl=2$, uses the Hessenberg form. Assumes that the base ring is a field.
Uses $O(n^3)$ scalar operations, but suffers from coefficient explosion
unless the base field is finite or $\R$.
If $\fl=3$, uses Berkowitz's division free algorithm, valid over any
ring (commutative, with unit). Uses $O(n^4)$ scalar operations.
If $\fl=4$, $x$ must be integral. Uses a modular algorithm: Hessenberg form
for various small primes, then Chinese remainders.
If $\fl=5$ (default), uses the ``best'' method given $x$.
This means we use Berkowitz unless the base ring is $\Z$ (use $\fl=4$)
or a field where coefficient explosion does not occur,
e.g.~a finite field or the reals (use $\fl=2$).
Variant: Also available are
\fun{GEN}{charpoly}{GEN x, long v} ($\fl=5$),
\fun{GEN}{caract}{GEN A, long v} ($\fl=1$),
\fun{GEN}{carhess}{GEN A, long v} ($\fl=2$),
\fun{GEN}{carberkowitz}{GEN A, long v} ($\fl=3$) and
\fun{GEN}{caradj}{GEN A, long v, GEN *pt}. In this
last case, if \var{pt} is not \kbd{NULL}, \kbd{*pt} receives the address of
the adjoint matrix of $A$ (see \tet{matadjoint}), so both can be obtained at
once.
Function: chinese
Class: basic
Section: number_theoretical
C-Name: chinese
Prototype: GDG
Help: chinese(x,{y}): x,y being both intmods (or polmods) computes z in the
same residue classes as x and y.
Description:
(gen):gen chinese1($1)
(gen, gen):gen chinese($1, $2)
Doc: if $x$ and $y$ are both intmods or both polmods, creates (with the same
type) a $z$ in the same residue class as $x$ and in the same residue class as
$y$, if it is possible.
\bprog
? chinese(Mod(1,2), Mod(2,3))
%1 = Mod(5, 6)
? chinese(Mod(x,x^2-1), Mod(x+1,x^2+1))
%2 = Mod(-1/2*x^2 + x + 1/2, x^4 - 1)
@eprog\noindent
This function also allows vector and matrix arguments, in which case the
operation is recursively applied to each component of the vector or matrix.
\bprog
? chinese([Mod(1,2),Mod(1,3)], [Mod(1,5),Mod(2,7)])
%3 = [Mod(1, 10), Mod(16, 21)]
@eprog\noindent
For polynomial arguments in the same variable, the function is applied to each
coefficient; if the polynomials have different degrees, the high degree terms
are copied verbatim in the result, as if the missing high degree terms in the
polynomial of lowest degree had been \kbd{Mod(0,1)}. Since the latter
behavior is usually \emph{not} the desired one, we propose to convert the
polynomials to vectors of the same length first:
\bprog
? P = x+1; Q = x^2+2*x+1;
? chinese(P*Mod(1,2), Q*Mod(1,3))
%4 = Mod(1, 3)*x^2 + Mod(5, 6)*x + Mod(3, 6)
? chinese(Vec(P,3)*Mod(1,2), Vec(Q,3)*Mod(1,3))
%5 = [Mod(1, 6), Mod(5, 6), Mod(4, 6)]
? Pol(%)
%6 = Mod(1, 6)*x^2 + Mod(5, 6)*x + Mod(4, 6)
@eprog
If $y$ is omitted, and $x$ is a vector, \kbd{chinese} is applied recursively
to the components of $x$, yielding a residue belonging to the same class as all
components of $x$.
Finally $\kbd{chinese}(x,x) = x$ regardless of the type of $x$; this allows
vector arguments to contain other data, so long as they are identical in both
vectors.
Variant: \fun{GEN}{chinese1}{GEN x} is also available.
Function: clone
Class: gp2c
Description:
(small):small:parens $1
(int):int gclone($1)
(real):real gclone($1)
(mp):mp gclone($1)
(vecsmall):vecsmall gclone($1)
(vec):vec gclone($1)
(pol):pol gclone($1)
(list):list gclone($1)
(closure):closure gclone($1)
(genstr):genstr gclone($1)
(gen):gen gclone($1)
Function: cmp
Class: basic
Section: operators
C-Name: cmp_universal
Prototype: iGG
Help: cmp(x,y): compare two arbitrary objects x and y (1 if x>y, 0 if x=y, -1
if x<y). The function is used to implement sets, and has no useful
mathematical meaning.
Doc: gives the result of a comparison between arbitrary objects $x$ and $y$
(as $-1$, $0$ or $1$). The underlying order relation is transitive,
the function returns $0$ if and only if $x~\kbd{===}~y$, and its
restriction to integers coincides with the customary one. Besides that,
it has no useful mathematical meaning.
In case all components are equal up to the smallest length of the operands,
the more complex is considered to be larger. More precisely, the longest is
the largest; when lengths are equal, we have matrix $>$ vector $>$ scalar.
For example:
\bprog
? cmp(1, 2)
%1 = -1
? cmp(2, 1)
%2 = 1
? cmp(1, 1.0) \\ note that 1 == 1.0, but (1===1.0) is false.
%3 = -1
? cmp(x + Pi, [])
%4 = -1
@eprog\noindent This function is mostly useful to handle sorted lists or
vectors of arbitrary objects. For instance, if $v$ is a vector, the
construction \kbd{vecsort(v, cmp)} is equivalent to \kbd{Set(v)}.
Function: component
Class: basic
Section: conversions
C-Name: compo
Prototype: GL
Help: component(x,n): the n'th component of the internal representation of
x. For vectors or matrices, it is simpler to use x[]. For list objects such
as nf, bnf, bnr or ell, it is much easier to use member functions starting
with ".".
Description:
(error,small):gen err_get_compo($1, $2)
(gen,small):gen compo($1,$2)
Doc: extracts the $n^{\text{th}}$-component of $x$. This is to be understood
as follows: every PARI type has one or two initial \idx{code words}. The
components are counted, starting at 1, after these code words. In particular
if $x$ is a vector, this is indeed the $n^{\text{th}}$-component of $x$, if
$x$ is a matrix, the $n^{\text{th}}$ column, if $x$ is a polynomial, the
$n^{\text{th}}$ coefficient (i.e.~of degree $n-1$), and for power series,
the $n^{\text{th}}$ significant coefficient.
For polynomials and power series, one should rather use \tet{polcoeff}, and
for vectors and matrices, the \kbd{[$\,$]} operator. Namely, if $x$ is a
vector, then \tet{x[n]} represents the $n^{\text{th}}$ component of $x$. If
$x$ is a matrix, \tet{x[m,n]} represents the coefficient of row \kbd{m} and
column \kbd{n} of the matrix, \tet{x[m,]} represents the $m^{\text{th}}$
\emph{row} of $x$, and \tet{x[,n]} represents the $n^{\text{th}}$
\emph{column} of $x$.
Using of this function requires detailed knowledge of the structure of the
different PARI types, and thus it should almost never be used directly.
Some useful exceptions:
\bprog
? x = 3 + O(3^5);
? component(x, 2)
%2 = 81 \\ p^(p-adic accuracy)
? component(x, 1)
%3 = 3 \\ p
? q = Qfb(1,2,3);
? component(q, 1)
%5 = 1
@eprog
Function: concat
Class: basic
Section: linear_algebra
C-Name: gconcat
Prototype: GDG
Help: concat(x,{y}): concatenation of x and y, which can be scalars, vectors
or matrices, or lists (in this last case, both x and y have to be lists). If
y is omitted, x has to be a list or row vector and its elements are
concatenated.
Description:
(mp,mp):vec gconcat($1, $2)
(vec,mp):vec gconcat($1, $2)
(mp,vec):vec gconcat($1, $2)
(vec,vec):vec gconcat($1, $2)
(list,list):list gconcat($1, $2)
(genstr,gen):genstr gconcat($1, $2)
(gen,genstr):genstr gconcat($1, $2)
(gen):gen gconcat1($1)
(gen,):gen gconcat1($1)
(gen,gen):gen gconcat($1, $2)
Doc: concatenation of $x$ and $y$. If $x$ or $y$ is
not a vector or matrix, it is considered as a one-dimensional vector. All
types are allowed for $x$ and $y$, but the sizes must be compatible. Note
that matrices are concatenated horizontally, i.e.~the number of rows stays
the same. Using transpositions, one can concatenate them vertically,
but it is often simpler to use \tet{matconcat}.
\bprog
? x = matid(2); y = 2*matid(2);
? concat(x,y)
%2 =
[1 0 2 0]
[0 1 0 2]
? concat(x~,y~)~
%3 =
[1 0]
[0 1]
[2 0]
[0 2]
? matconcat([x;y])
%4 =
[1 0]
[0 1]
[2 0]
[0 2]
@eprog\noindent
To concatenate vectors sideways (i.e.~to obtain a two-row or two-column
matrix), use \tet{Mat} instead, or \tet{matconcat}:
\bprog
? x = [1,2];
? y = [3,4];
? concat(x,y)
%3 = [1, 2, 3, 4]
? Mat([x,y]~)
%4 =
[1 2]
[3 4]
? matconcat([x;y])
%5 =
[1 2]
[3 4]
@eprog
Concatenating a row vector to a matrix having the same number of columns will
add the row to the matrix (top row if the vector is $x$, i.e.~comes first, and
bottom row otherwise).
The empty matrix \kbd{[;]} is considered to have a number of rows compatible
with any operation, in particular concatenation. (Note that this is
\emph{not} the case for empty vectors \kbd{[~]} or \kbd{[~]\til}.)
If $y$ is omitted, $x$ has to be a row vector or a list, in which case its
elements are concatenated, from left to right, using the above rules.
\bprog
? concat([1,2], [3,4])
%1 = [1, 2, 3, 4]
? a = [[1,2]~, [3,4]~]; concat(a)
%2 =
[1 3]
[2 4]
? concat([1,2; 3,4], [5,6]~)
%3 =
[1 2 5]
[3 4 6]
? concat([%, [7,8]~, [1,2,3,4]])
%5 =
[1 2 5 7]
[3 4 6 8]
[1 2 3 4]
@eprog
Variant: \fun{GEN}{gconcat1}{GEN x} is a shortcut for \kbd{gconcat(x,NULL)}.
Function: conj
Class: basic
Section: conversions
C-Name: gconj
Prototype: G
Help: conj(x): the algebraic conjugate of x.
Doc:
conjugate of $x$. The meaning of this
is clear, except that for real quadratic numbers, it means conjugation in the
real quadratic field. This function has no effect on integers, reals,
intmods, fractions or $p$-adics. The only forbidden type is polmod
(see \kbd{conjvec} for this).
Function: conjvec
Class: basic
Section: conversions
C-Name: conjvec
Prototype: Gp
Help: conjvec(z): conjugate vector of the algebraic number z.
Doc:
conjugate vector representation of $z$. If $z$ is a
polmod, equal to \kbd{Mod}$(a,T)$, this gives a vector of length
$\text{degree}(T)$ containing:
\item the complex embeddings of $z$ if $T$ has rational coefficients,
i.e.~the $a(r[i])$ where $r = \kbd{polroots}(T)$;
\item the conjugates of $z$ if $T$ has some intmod coefficients;
\noindent if $z$ is a finite field element, the result is the vector of
conjugates $[z,z^p,z^{p^2},\ldots,z^{p^{n-1}}]$ where $n=\text{degree}(T)$.
\noindent If $z$ is an integer or a rational number, the result is~$z$. If
$z$ is a (row or column) vector, the result is a matrix whose columns are
the conjugate vectors of the individual elements of $z$.
Function: content
Class: basic
Section: number_theoretical
C-Name: content
Prototype: G
Help: content(x): gcd of all the components of x, when this makes sense.
Doc: computes the gcd of all the coefficients of $x$,
when this gcd makes sense. This is the natural definition
if $x$ is a polynomial (and by extension a power series) or a
vector/matrix. This is in general a weaker notion than the \emph{ideal}
generated by the coefficients:
\bprog
? content(2*x+y)
%1 = 1 \\ = gcd(2,y) over Q[y]
@eprog
If $x$ is a scalar, this simply returns the absolute value of $x$ if $x$ is
rational (\typ{INT} or \typ{FRAC}), and either $1$ (inexact input) or $x$
(exact input) otherwise; the result should be identical to \kbd{gcd(x, 0)}.
The content of a rational function is the ratio of the contents of the
numerator and the denominator. In recursive structures, if a
matrix or vector \emph{coefficient} $x$ appears, the gcd is taken
not with $x$, but with its content:
\bprog
? content([ [2], 4*matid(3) ])
%1 = 2
@eprog\noindent The content of a \typ{VECSMALL} is computed assuming the
entries are signed integers.
Function: contfrac
Class: basic
Section: number_theoretical
C-Name: contfrac0
Prototype: GDGD0,L,
Help: contfrac(x,{b},{nmax}): continued fraction expansion of x (x
rational,real or rational function). b and nmax are both optional, where b
is the vector of numerators of the continued fraction, and nmax is a bound
for the number of terms in the continued fraction expansion.
Doc: returns the row vector whose components are the partial quotients of the
\idx{continued fraction} expansion of $x$. In other words, a result
$[a_0,\dots,a_n]$ means that $x \approx a_0+1/(a_1+\dots+1/a_n)$. The
output is normalized so that $a_n \neq 1$ (unless we also have $n = 0$).
The number of partial quotients $n+1$ is limited by \kbd{nmax}. If
\kbd{nmax} is omitted, the expansion stops at the last significant partial
quotient.
\bprog
? \p19
realprecision = 19 significant digits
? contfrac(Pi)
%1 = [3, 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 2, 1, 1, 2, 2]
? contfrac(Pi,, 3) \\ n = 2
%2 = [3, 7, 15]
@eprog\noindent
$x$ can also be a rational function or a power series.
If a vector $b$ is supplied, the numerators are equal to the coefficients
of $b$, instead of all equal to $1$ as above; more precisely, $x \approx
(1/b_0)(a_0+b_1/(a_1+\dots+b_n/a_n))$; for a numerical continued fraction
($x$ real), the $a_i$ are integers, as large as possible; if $x$ is a
rational function, they are polynomials with $\deg a_i = \deg b_i + 1$.
The length of the result is then equal to the length of $b$, unless the next
partial quotient cannot be reliably computed, in which case the expansion
stops. This happens when a partial remainder is equal to zero (or too small
compared to the available significant digits for $x$ a \typ{REAL}).
A direct implementation of the numerical continued fraction
\kbd{contfrac(x,b)} described above would be
\bprog
\\ "greedy" generalized continued fraction
cf(x, b) =
{ my( a= vector(#b), t );
x *= b[1];
for (i = 1, #b,
a[i] = floor(x);
t = x - a[i]; if (!t || i == #b, break);
x = b[i+1] / t;
); a;
}
@eprog\noindent There is some degree of freedom when choosing the $a_i$; the
program above can easily be modified to derive variants of the standard
algorithm. In the same vein, although no builtin
function implements the related \idx{Engel expansion} (a special kind of
\idx{Egyptian fraction} decomposition: $x = 1/a_1 + 1/(a_1a_2) + \dots$ ),
it can be obtained as follows:
\bprog
\\ n terms of the Engel expansion of x
engel(x, n = 10) =
{ my( u = x, a = vector(n) );
for (k = 1, n,
a[k] = ceil(1/u);
u = u*a[k] - 1;
if (!u, break);
); a
}
@eprog
\misctitle{Obsolete hack} (don't use this): if $b$ is an integer, \var{nmax}
is ignored and the command is understood as \kbd{contfrac($x,, b$)}.
Variant: Also available are \fun{GEN}{gboundcf}{GEN x, long nmax},
\fun{GEN}{gcf}{GEN x} and \fun{GEN}{gcf2}{GEN b, GEN x}.
Function: contfraceval
Class: basic
Section: sums
C-Name: contfraceval
Prototype: GGD-1,L,
Help: contfraceval(CF,t,{lim=-1}): given a continued fraction CF from
contfracinit, evaluate the first lim terms of the continued fraction at t
(all terms if lim is negative or omitted).
Doc: Given a continued fraction \kbd{CF} output by \kbd{contfracinit}, evaluate
the first \kbd{lim} terms of the continued fraction at \kbd{t} (all
terms if \kbd{lim} is negative or omitted; if positive, \kbd{lim} must be
less than or equal to the length of \kbd{CF}.
Function: contfracinit
Class: basic
Section: sums
C-Name: contfracinit
Prototype: GD-1,L,
Help: contfracinit(M,{lim = -1}): given M representing the power
series S = sum_{n>=0} M[n+1]z^n, transform it into a continued fraction
suitable for evaluation.
Doc: Given $M$ representing the power series $S=\sum_{n\ge0} M[n+1]z^n$,
transform it into a continued fraction; restrict to $n\leq \kbd{lim}$
if latter is non-negative. $M$ can be a vector, a power
series, a polynomial, or a rational function.
The result is a 2-component vector $[A,B]$ such that
$S = M[1] / (1+A[1]z+B[1]z^2/(1+A[2]z+B[2]z^2/(1+...1/(1+A[lim/2]z))))$.
Does not work if any coefficient of $M$ vanishes, nor for series for
which certain partial denominators vanish.
Function: contfracpnqn
Class: basic
Section: number_theoretical
C-Name: contfracpnqn
Prototype: GD-1,L,
Help: contfracpnqn(x, {n=-1}): [p_n,p_{n-1}; q_n,q_{n-1}] corresponding to the
continued fraction x. If n >= 0 is present, returns all convergents from
p_0/q_0 up to p_n/q_n.
Doc: when $x$ is a vector or a one-row matrix, $x$
is considered as the list of partial quotients $[a_0,a_1,\dots,a_n]$ of a
rational number, and the result is the 2 by 2 matrix
$[p_n,p_{n-1};q_n,q_{n-1}]$ in the standard notation of continued fractions,
so $p_n/q_n=a_0+1/(a_1+\dots+1/a_n)$. If $x$ is a matrix with two rows
$[b_0,b_1,\dots,b_n]$ and $[a_0,a_1,\dots,a_n]$, this is then considered as a
generalized continued fraction and we have similarly
$p_n/q_n=(1/b_0)(a_0+b_1/(a_1+\dots+b_n/a_n))$. Note that in this case one
usually has $b_0=1$.
If $n \geq 0$ is present, returns all convergents from $p_0/q_0$ up to
$p_n/q_n$. (All convergents if $x$ is too small to compute the $n+1$
requested convergents.)
\bprog
? a=contfrac(Pi,20)
%1 = [3, 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 2, 1, 1, 2, 2, 2, 2]
? contfracpnqn(a,3)
%2 =
[3 22 333 355]
[1 7 106 113]
? contfracpnqn(a,7)
%3 =
[3 22 333 355 103993 104348 208341 312689]
[1 7 106 113 33102 33215 66317 99532]
@eprog
Variant: also available is \fun{GEN}{pnqn}{GEN x} for $n = -1$.
Function: copy
Class: gp2c
Description:
(small):small:parens $1
(int):int icopy($1)
(real):real gcopy($1)
(mp):mp gcopy($1)
(vecsmall):vecsmall gcopy($1)
(vec):vec gcopy($1)
(pol):pol gcopy($1)
(gen):gen gcopy($1)
Function: core
Class: basic
Section: number_theoretical
C-Name: core0
Prototype: GD0,L,
Help: core(n,{flag=0}): unique squarefree integer d
dividing n such that n/d is a square. If (optional) flag is non-null, output
the two-component row vector [d,f], where d is the unique squarefree integer
dividing n such that n/d=f^2 is a square.
Doc: if $n$ is an integer written as
$n=df^2$ with $d$ squarefree, returns $d$. If $\fl$ is non-zero,
returns the two-element row vector $[d,f]$. By convention, we write $0 = 0
\times 1^2$, so \kbd{core(0, 1)} returns $[0,1]$.
Variant: Also available are \fun{GEN}{core}{GEN n} ($\fl = 0$) and
\fun{GEN}{core2}{GEN n} ($\fl = 1$)
Function: coredisc
Class: basic
Section: number_theoretical
C-Name: coredisc0
Prototype: GD0,L,
Help: coredisc(n,{flag=0}): discriminant of the quadratic field Q(sqrt(n)).
If (optional) flag is non-null, output a two-component row vector [d,f],
where d is the discriminant of the quadratic field Q(sqrt(n)) and n=df^2. f
may be a half integer.
Doc: a \emph{fundamental discriminant} is an integer of the form $t\equiv 1
\mod 4$ or $4t \equiv 8,12 \mod 16$, with $t$ squarefree (i.e.~$1$ or the
discriminant of a quadratic number field). Given a non-zero integer
$n$, this routine returns the (unique) fundamental discriminant $d$
such that $n=df^2$, $f$ a positive rational number. If $\fl$ is non-zero,
returns the two-element row vector $[d,f]$. If $n$ is congruent to
0 or 1 modulo 4, $f$ is an integer, and a half-integer otherwise.
By convention, \kbd{coredisc(0, 1))} returns $[0,1]$.
Note that \tet{quaddisc}$(n)$ returns the same value as \kbd{coredisc}$(n)$,
and also works with rational inputs $n\in\Q^*$.
Variant: Also available are \fun{GEN}{coredisc}{GEN n} ($\fl = 0$) and
\fun{GEN}{coredisc2}{GEN n} ($\fl = 1$)
Function: cos
Class: basic
Section: transcendental
C-Name: gcos
Prototype: Gp
Help: cos(x): cosine of x.
Doc: cosine of $x$.
Function: cosh
Class: basic
Section: transcendental
C-Name: gcosh
Prototype: Gp
Help: cosh(x): hyperbolic cosine of x.
Doc: hyperbolic cosine of $x$.
Function: cotan
Class: basic
Section: transcendental
C-Name: gcotan
Prototype: Gp
Help: cotan(x): cotangent of x.
Doc: cotangent of $x$.
Function: cotanh
Class: basic
Section: transcendental
C-Name: gcotanh
Prototype: Gp
Help: cotanh(x): hyperbolic cotangent of x.
Doc: hyperbolic cotangent of $x$.
Function: dbg_down
Class: gp
Section: programming/control
C-Name: dbg_down
Prototype: vD1,L,
Help: dbg_down({n=1}): (break loop) go down n frames. Cancel a previous dbg_up.
Doc: (In the break loop) go down n frames. This allows to cancel a previous call to
\kbd{dbg\_up}.
Function: dbg_err
Class: gp
Section: programming/control
C-Name: dbg_err
Prototype:
Help: dbg_err(): (break loop) return the error data of the current error, if any.
Doc: In the break loop, return the error data of the current error, if any.
See \tet{iferr} for details about error data. Compare:
\bprog
? iferr(1/(Mod(2,12019)^(6!)-1),E,Vec(E))
%1 = ["e_INV", "Fp_inv", Mod(119, 12019)]
? 1/(Mod(2,12019)^(6!)-1)
*** at top-level: 1/(Mod(2,12019)^(6!)-
*** ^--------------------
*** _/_: impossible inverse in Fp_inv: Mod(119, 12019).
*** Break loop: type 'break' to go back to GP prompt
break> Vec(dbg_err())
["e_INV", "Fp_inv", Mod(119, 12019)]
@eprog
Function: dbg_up
Class: gp
Section: programming/control
C-Name: dbg_up
Prototype: vD1,L,
Help: dbg_up({n=1}): (break loop) go up n frames. Allow to inspect data of the parent function.
Doc: (In the break loop) go up n frames. This allows to inspect data of the
parent function. To cancel a \tet{dbg_up} call, use \tet{dbg_down}
Function: dbg_x
Class: basic
Section: programming/control
C-Name: dbgGEN
Prototype: vGD-1,L,
Help: dbg_x(A,{n}): print inner structure of A, complete if n is omitted, up to
level n otherwise. Intended for debugging.
Doc: Print the inner structure of \kbd{A}, complete if \kbd{n} is omitted, up
to level \kbd{n} otherwise. This is useful for debugging. This is similar to
\b{x} but does not require \kbd{A} to be an history entry. In particular,
it can be used in the break loop.
Function: default
Class: basic
Section: programming/specific
C-Name: default0
Prototype: DrDs
Help: default({key},{val}): returns the current value of the
default key. If val is present, set opt to val first. If no argument is
given, print a list of all defaults as well as their values.
Description:
("realprecision"):small:prec getrealprecision()
("realprecision",small):small:prec setrealprecision($2, &$prec)
("seriesprecision"):small precdl
("seriesprecision",small):small:parens precdl = $2
("debug"):small DEBUGLEVEL
("debug",small):small:parens DEBUGLEVEL = $2
("debugmem"):small DEBUGMEM
("debugmem",small):small:parens DEBUGMEM = $2
("debugfiles"):small DEBUGFILES
("debugfiles",small):small:parens DEBUGFILES = $2
("factor_add_primes"):small factor_add_primes
("factor_add_primes",small):small factor_add_primes = $2
("factor_proven"):small factor_proven
("factor_proven",small):small factor_proven = $2
("new_galois_format"):small new_galois_format
("new_galois_format",small):small new_galois_format = $2
Doc: returns the default corresponding to keyword \var{key}. If \var{val} is
present, sets the default to \var{val} first (which is subject to string
expansion first). Typing \kbd{default()} (or \b{d}) yields the complete
default list as well as their current values. See \secref{se:defaults} for an
introduction to GP defaults, \secref{se:gp_defaults} for a
list of available defaults, and \secref{se:meta} for some shortcut
alternatives. Note that the shortcuts are meant for interactive use and
usually display more information than \kbd{default}.
Function: denominator
Class: basic
Section: conversions
C-Name: denom
Prototype: G
Help: denominator(x): denominator of x (or lowest common denominator in case
of an array).
Doc:
denominator of $x$. The meaning of this
is clear when $x$ is a rational number or function. If $x$ is an integer
or a polynomial, it is treated as a rational number or function,
respectively, and the result is equal to $1$. For polynomials, you
probably want to use
\bprog
denominator( content(x) )
@eprog\noindent
instead. As for modular objects, \typ{INTMOD} and \typ{PADIC} have
denominator $1$, and the denominator of a \typ{POLMOD} is the denominator
of its (minimal degree) polynomial representative.
If $x$ is a recursive structure, for instance a vector or matrix, the lcm
of the denominators of its components (a common denominator) is computed.
This also applies for \typ{COMPLEX}s and \typ{QUAD}s.
\misctitle{Warning} Multivariate objects are created according to variable
priorities, with possibly surprising side effects ($x/y$ is a polynomial, but
$y/x$ is a rational function). See \secref{se:priority}.
Function: deriv
Class: basic
Section: polynomials
C-Name: deriv
Prototype: GDn
Help: deriv(x,{v}): derivative of x with respect to v, or to the main
variable of x if v is omitted.
Doc:
derivative of $x$ with respect to the main
variable if $v$ is omitted, and with respect to $v$ otherwise. The derivative
of a scalar type is zero, and the derivative of a vector or matrix is done
componentwise. One can use $x'$ as a shortcut if the derivative is with
respect to the main variable of $x$.
By definition, the main variable of a \typ{POLMOD} is the main variable among
the coefficients from its two polynomial components (representative and
modulus); in other words, assuming a polmod represents an element of
$R[X]/(T(X))$, the variable $X$ is a mute variable and the derivative is
taken with respect to the main variable used in the base ring $R$.
Function: derivnum
Class: basic
Section: sums
C-Name: derivnum0
Prototype: V=GEp
Help: derivnum(X=a,expr): numerical derivation of expr with respect to
X at X = a.
Wrapper: (,Gp)
Description:
(gen,gen):gen:prec derivnum(${2 cookie}, ${2 wrapper}, $1, $prec)
Doc: numerical derivation of \var{expr} with respect to $X$ at $X=a$.
\bprog
? derivnum(x=0,sin(exp(x))) - cos(1)
%1 = -1.262177448 E-29
@eprog
A clumsier approach, which would not work in library mode, is
\bprog
? f(x) = sin(exp(x))
? f'(0) - cos(1)
%1 = -1.262177448 E-29
@eprog
When $a$ is a power series, compute \kbd{derivnum(t=a,f)} as $f'(a) =
(f(a))'/a'$.
\synt{derivnum}{void *E, GEN (*eval)(void*,GEN), GEN a, long prec}. Also
available is \fun{GEN}{derivfun}{void *E, GEN (*eval)(void *, GEN), GEN a, long prec}, which also allows power series for $a$.
Function: diffop
Class: basic
Section: polynomials
C-Name: diffop0
Prototype: GGGD1,L,
Help: diffop(x,v,d,{n=1}): apply the differential operator D to x, where D is defined
by D(v[i])=d[i], where v is a vector of variable names. D is 0 for variables
outside of v unless they appear as modulus of a POLMOD. If the optional parameter n
is given, return D^n(x) instead.
Description:
(gen,gen,gen,?1):gen diffop($1, $2, $3)
(gen,gen,gen,small):gen diffop0($1, $2, $3, $4)
Doc:
Let $v$ be a vector of variables, and $d$ a vector of the same length,
return the image of $x$ by the $n$-power ($1$ if n is not given) of the differential
operator $D$ that assumes the value \kbd{d[i]} on the variable \kbd{v[i]}.
The value of $D$ on a scalar type is zero, and $D$ applies componentwise to a vector
or matrix. When applied to a \typ{POLMOD}, if no value is provided for the variable
of the modulus, such value is derived using the implicit function theorem.
Some examples:
This function can be used to differentiate formal expressions:
If $E=\exp(X^2)$ then we have $E'=2*X*E$. We can derivate $X*exp(X^2)$ as follow:
\bprog
? diffop(E*X,[X,E],[1,2*X*E])
%1 = (2*X^2 + 1)*E
@eprog
Let \kbd{Sin} and \kbd{Cos} be two function such that $\kbd{Sin}^2+\kbd{Cos}^2=1$
and $\kbd{Cos}'=-\kbd{Sin}$. We can differentiate $\kbd{Sin}/\kbd{Cos}$ as follow,
PARI inferring the value of $\kbd{Sin}'$ from the equation:
\bprog
? diffop(Mod('Sin/'Cos,'Sin^2+'Cos^2-1),['Cos],[-'Sin])
%1 = Mod(1/Cos^2, Sin^2 + (Cos^2 - 1))
@eprog
Compute the Bell polynomials (both complete and partial) via the Faa di Bruno formula:
\bprog
Bell(k,n=-1)=
{
my(var(i)=eval(Str("X",i)));
my(x,v,dv);
v=vector(k,i,if(i==1,'E,var(i-1)));
dv=vector(k,i,if(i==1,'X*var(1)*'E,var(i)));
x=diffop('E,v,dv,k)/'E;
if(n<0,subst(x,'X,1),polcoeff(x,n,'X))
}
@eprog
Variant:
For $n=1$, the function \fun{GEN}{diffop}{GEN x, GEN v, GEN d} is also available.
Function: digits
Class: basic
Section: conversions
C-Name: digits
Prototype: GDG
Help: digits(x,{b=10}): gives the vector formed by the digits of x in base b (x and b
integers).
Doc:
outputs the vector of the digits of $|x|$ in base $b$, where $x$ and $b$ are
integers ($b = 10$ by default). See \kbd{fromdigits} for the reverse
operation.
\bprog
? digits(123)
%1 = [1, 2, 3, 0]
? digits(10, 2) \\ base 2
%2 = [1, 0, 1, 0]
@eprog\noindent By convention, $0$ has no digits:
\bprog
? digits(0)
%3 = []
@eprog
Function: dilog
Class: basic
Section: transcendental
C-Name: dilog
Prototype: Gp
Help: dilog(x): dilogarithm of x.
Doc: principal branch of the dilogarithm of $x$,
i.e.~analytic continuation of the power series $\log_2(x)=\sum_{n\ge1}x^n/n^2$.
Function: dirdiv
Class: basic
Section: number_theoretical
C-Name: dirdiv
Prototype: GG
Help: dirdiv(x,y): division of the Dirichlet series x by the Dirichlet
series y.
Doc: $x$ and $y$ being vectors of perhaps different
lengths but with $y[1]\neq 0$ considered as \idx{Dirichlet series}, computes
the quotient of $x$ by $y$, again as a vector.
Function: direuler
Class: basic
Section: number_theoretical
C-Name: direuler0
Prototype: V=GGEDG
Help: direuler(p=a,b,expr,{c}): Dirichlet Euler product of expression expr
from p=a to p=b, limited to b terms. Expr should be a polynomial or rational
function in p and X, and X is understood to mean p^(-s). If c is present,
output only the first c terms.
Wrapper: (,,G)
Description:
(gen,gen,closure,?gen):gen direuler(${3 cookie}, ${3 wrapper}, $1, $2, $4)
Doc: computes the \idx{Dirichlet series} attached to the
\idx{Euler product} of expression \var{expr} as $p$ ranges through the primes
from $a$
to $b$. \var{expr} must be a polynomial or rational function in another
variable than $p$ (say $X$) and $\var{expr}(X)$ is understood as the local
factor $\var{expr}(p^{-s})$.
The series is output as a vector of coefficients. If $c$ is omitted, output
the first $b$ coefficients of the series; otherwise, output the first $c$
coefficients. The following command computes the \teb{sigma} function,
attached to $\zeta(s)\zeta(s-1)$:
\bprog
? direuler(p=2, 10, 1/((1-X)*(1-p*X)))
%1 = [1, 3, 4, 7, 6, 12, 8, 15, 13, 18]
? direuler(p=2, 10, 1/((1-X)*(1-p*X)), 5) \\ fewer terms
%2 = [1, 3, 4, 7, 6]
@eprog\noindent Setting $c < b$ is useless (the same effect would be
achieved by setting $b = c)$. If $c > b$, the computed coefficients are
``missing'' Euler factors:
\bprog
? direuler(p=2, 10, 1/((1-X)*(1-p*X)), 15) \\ more terms, no longer = sigma !
%3 = [1, 3, 4, 7, 6, 12, 8, 15, 13, 18, 0, 28, 0, 24, 24]
@eprog
\synt{direuler}{void *E, GEN (*eval)(void*,GEN), GEN a, GEN b}
Function: dirmul
Class: basic
Section: number_theoretical
C-Name: dirmul
Prototype: GG
Help: dirmul(x,y): multiplication of the Dirichlet series x by the Dirichlet
series y.
Doc: $x$ and $y$ being vectors of perhaps different lengths representing
the \idx{Dirichlet series} $\sum_n x_n n^{-s}$ and $\sum_n y_n n^{-s}$,
computes the product of $x$ by $y$, again as a vector.
\bprog
? dirmul(vector(10,n,1), vector(10,n,moebius(n)))
%1 = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
@eprog\noindent
The product
length is the minimum of $\kbd{\#}x\kbd{*}v(y)$ and $\kbd{\#}y\kbd{*}v(x)$,
where $v(x)$ is the index of the first non-zero coefficient.
\bprog
? dirmul([0,1], [0,1]);
%2 = [0, 0, 0, 1]
@eprog
Function: dirzetak
Class: basic
Section: number_fields
C-Name: dirzetak
Prototype: GG
Help: dirzetak(nf,b): Dirichlet series of the Dedekind zeta function of the
number field nf up to the bound b-1.
Doc: gives as a vector the first $b$
coefficients of the \idx{Dedekind} zeta function of the number field $\var{nf}$
considered as a \idx{Dirichlet series}.
Function: divisors
Class: basic
Section: number_theoretical
C-Name: divisors
Prototype: G
Help: divisors(x): gives a vector formed by the divisors of x in increasing
order.
Description:
(gen):vec divisors($1)
Doc: creates a row vector whose components are the
divisors of $x$. The factorization of $x$ (as output by \tet{factor}) can
be used instead.
By definition, these divisors are the products of the irreducible
factors of $n$, as produced by \kbd{factor(n)}, raised to appropriate
powers (no negative exponent may occur in the factorization). If $n$ is
an integer, they are the positive divisors, in increasing order.
Function: divrem
Class: basic
Section: operators
C-Name: divrem
Prototype: GGDn
Help: divrem(x,y,{v}): euclidean division of x by y giving as a
2-dimensional column vector the quotient and the remainder, with respect to
v (to main variable if v is omitted).
Doc: creates a column vector with two components, the first being the Euclidean
quotient (\kbd{$x$ \bs\ $y$}), the second the Euclidean remainder
(\kbd{$x$ - ($x$\bs$y$)*$y$}), of the division of $x$ by $y$. This avoids the
need to do two divisions if one needs both the quotient and the remainder.
If $v$ is present, and $x$, $y$ are multivariate
polynomials, divide with respect to the variable $v$.
Beware that \kbd{divrem($x$,$y$)[2]} is in general not the same as
\kbd{$x$ \% $y$}; no GP operator corresponds to it:
\bprog
? divrem(1/2, 3)[2]
%1 = 1/2
? (1/2) % 3
%2 = 2
? divrem(Mod(2,9), 3)[2]
*** at top-level: divrem(Mod(2,9),3)[2
*** ^--------------------
*** forbidden division t_INTMOD \ t_INT.
? Mod(2,9) % 6
%3 = Mod(2,3)
@eprog
Variant: Also available is \fun{GEN}{gdiventres}{GEN x, GEN y} when $v$ is
not needed.
Function: eint1
Class: basic
Section: transcendental
C-Name: veceint1
Prototype: GDGp
Help: eint1(x,{n}): exponential integral E1(x). If n is present and x > 0,
computes the vector of the first n values of the exponential integral E1(n x).
Doc: exponential integral $\int_x^\infty \dfrac{e^{-t}}{t}\,dt =
\kbd{incgam}(0, x)$, where the latter expression extends the function
definition from real $x > 0$ to all complex $x \neq 0$.
If $n$ is present, we must have $x > 0$; the function returns the
$n$-dimensional vector $[\kbd{eint1}(x),\dots,\kbd{eint1}(nx)]$. Contrary to
other transcendental functions, and to the default case ($n$ omitted), the
values are correct up to a bounded \emph{absolute}, rather than relative,
error $10^{-n}$, where $n$ is \kbd{precision}$(x)$ if $x$ is a \typ{REAL}
and defaults to \kbd{realprecision} otherwise. (In the most important
application, to the computation of $L$-functions via approximate functional
equations, those values appear as weights in long sums and small individual
relative errors are less useful than controlling the absolute error.) This is
faster than repeatedly calling \kbd{eint1($i$ * x)}, but less precise.
Variant: Also available is \fun{GEN}{eint1}{GEN x, long prec}.
Function: ellL1
Class: basic
Section: elliptic_curves
C-Name: ellL1_bitprec
Prototype: GD0,L,b
Help: ellL1(e, {r = 0}): returns the value at s=1 of the derivative of order r of the L-function of the elliptic curve e.
Doc: returns the value at $s=1$ of the derivative of order $r$ of the
$L$-function of the elliptic curve $e$.
\bprog
? e = ellinit("11a1"); \\ order of vanishing is 0
? ellL1(e)
%2 = 0.2538418608559106843377589233
? e = ellinit("389a1"); \\ order of vanishing is 2
? ellL1(e)
%4 = -5.384067311837218089235032414 E-29
? ellL1(e, 1)
%5 = 0
? ellL1(e, 2)
%6 = 1.518633000576853540460385214
@eprog\noindent
The main use of this function, after computing at \emph{low} accuracy the
order of vanishing using \tet{ellanalyticrank}, is to compute the
leading term at \emph{high} accuracy to check (or use) the Birch and
Swinnerton-Dyer conjecture:
\bprog
? \p18
realprecision = 18 significant digits
? e = ellinit("5077a1"); ellanalyticrank(e)
time = 8 ms.
%1 = [3, 10.3910994007158041]
? \p200
realprecision = 202 significant digits (200 digits displayed)
? ellL1(e, 3)
time = 104 ms.
%3 = 10.3910994007158041387518505103609170697263563756570092797@com$[\dots]$
@eprog
Function: elladd
Class: basic
Section: elliptic_curves
C-Name: elladd
Prototype: GGG
Help: elladd(E,z1,z2): sum of the points z1 and z2 on elliptic curve E.
Doc:
sum of the points $z1$ and $z2$ on the
elliptic curve corresponding to $E$.
Function: ellak
Class: basic
Section: elliptic_curves
C-Name: akell
Prototype: GG
Help: ellak(E,n): computes the n-th Fourier coefficient of the L-function of
the elliptic curve E (assumed E is an integral model).
Doc:
computes the coefficient $a_n$ of the $L$-function of the elliptic curve
$E/\Q$, i.e.~coefficients of a newform of weight 2 by the modularity theorem
(\idx{Taniyama-Shimura-Weil conjecture}). $E$ must be an \kbd{ell} structure
over $\Q$ as output by \kbd{ellinit}. $E$ must be given by an integral model,
not necessarily minimal, although a minimal model will make the function
faster.
\bprog
? E = ellinit([0,1]);
? ellak(E, 10)
%2 = 0
? e = ellinit([5^4,5^6]); \\ not minimal at 5
? ellak(e, 5) \\ wasteful but works
%3 = -3
? E = ellminimalmodel(e); \\ now minimal
? ellak(E, 5)
%5 = -3
@eprog\noindent If the model is not minimal at a number of bad primes, then
the function will be slower on those $n$ divisible by the bad primes.
The speed should be comparable for other $n$:
\bprog
? for(i=1,10^6, ellak(E,5))
time = 820 ms.
? for(i=1,10^6, ellak(e,5)) \\ 5 is bad, markedly slower
time = 1,249 ms.
? for(i=1,10^5,ellak(E,5*i))
time = 977 ms.
? for(i=1,10^5,ellak(e,5*i)) \\ still slower but not so much on average
time = 1,008 ms.
@eprog
Function: ellan
Class: basic
Section: elliptic_curves
C-Name: ellan
Prototype: GL
Help: ellan(E,n): computes the first n Fourier coefficients of the
L-function of the elliptic curve E defined over a number field
(n<2^24 on a 32-bit machine).
Doc: computes the vector of the first $n$ Fourier coefficients $a_k$
corresponding to the elliptic curve $E$ defined over a number field.
If $E$ is defined over $\Q$, the curve may be given by an
arbitrary model, not necessarily minimal,
although a minimal model will make the function faster. Over a more general
number field, the model must be locally minimal at all primes above $2$
and $3$.
Variant: Also available is \fun{GEN}{ellanQ_zv}{GEN e, long n}, which
returns a \typ{VECSMALL} instead of a \typ{VEC}, saving on memory.
Function: ellanalyticrank
Class: basic
Section: elliptic_curves
C-Name: ellanalyticrank_bitprec
Prototype: GDGb
Help: ellanalyticrank(e, {eps}): returns the order of vanishing at s=1
of the L-function of the elliptic curve e and the value of the first
non-zero derivative. To determine this order, it is assumed that any
value less than eps is zero. If no value of eps is given, a value of
half the current precision is used.
Doc: returns the order of vanishing at $s=1$ of the $L$-function of the
elliptic curve $e$ and the value of the first non-zero derivative. To
determine this order, it is assumed that any value less than \kbd{eps} is
zero. If no value of \kbd{eps} is given, a value of half the current
precision is used.
\bprog
? e = ellinit("11a1"); \\ rank 0
? ellanalyticrank(e)
%2 = [0, 0.2538418608559106843377589233]
? e = ellinit("37a1"); \\ rank 1
? ellanalyticrank(e)
%4 = [1, 0.3059997738340523018204836835]
? e = ellinit("389a1"); \\ rank 2
? ellanalyticrank(e)
%6 = [2, 1.518633000576853540460385214]
? e = ellinit("5077a1"); \\ rank 3
? ellanalyticrank(e)
%8 = [3, 10.39109940071580413875185035]
@eprog
Function: ellap
Class: basic
Section: elliptic_curves
C-Name: ellap
Prototype: GDG
Help: ellap(E,{p}): computes the trace of Frobenius a_p for the elliptic
curve E, defined over Q or a finite field.
Doc:
Let $E$ be an \kbd{ell} structure as output by \kbd{ellinit}, defined over
a number field or a finite field $\F_q$. The argument $p$ is best left
omitted if the curve is defined over a finite field, and must be a prime
number or a maximal ideal otherwise. This function computes the trace of
Frobenius $t$ for the elliptic curve $E$, defined by the equation $\#E(\F_q)
= q+1 - t$ (for primes of good reduction).
When the characteristic of the finite field is large, the availability of
the \kbd{seadata} package will speed the computation.
If the curve is defined over $\Q$, $p$ must be explicitly given and the
function computes the trace of the reduction over $\F_p$.
The trace of Frobenius is also the $a_p$ coefficient in the curve $L$-series
$L(E,s) = \sum_n a_n n^{-s}$, whence the function name. The equation must be
integral at $p$ but need not be minimal at $p$; of course, a minimal model
will be more efficient.
\bprog
? E = ellinit([0,1]); \\ y^2 = x^3 + 0.x + 1, defined over Q
? ellap(E, 7) \\ 7 necessary here
%2 = -4 \\ #E(F_7) = 7+1-(-4) = 12
? ellcard(E, 7)
%3 = 12 \\ OK
? E = ellinit([0,1], 11); \\ defined over F_11
? ellap(E) \\ no need to repeat 11
%4 = 0
? ellap(E, 11) \\ ... but it also works
%5 = 0
? ellgroup(E, 13) \\ ouch, inconsistent input!
*** at top-level: ellap(E,13)
*** ^-----------
*** ellap: inconsistent moduli in Rg_to_Fp:
11
13
? Fq = ffgen(ffinit(11,3), 'a); \\ defines F_q := F_{11^3}
? E = ellinit([a+1,a], Fq); \\ y^2 = x^3 + (a+1)x + a, defined over F_q
? ellap(E)
%8 = -3
@eprog
If the curve is defined over a more general number field than $\Q$,
the maximal ideal $p$ must be explicitly given in \kbd{idealprimedec}
format. If $p$ is above $2$ or $3$, the function currently assumes (without
checking) that the given model is locally minimal at $p$. There is no
restriction at other primes.
\bprog
? K = nfinit(a^2+1); E = ellinit([1+a,0,1,0,0], K);
? fa = idealfactor(K, E.disc)
%2 =
[ [5, [-2, 1]~, 1, 1, [2, -1; 1, 2]] 1]
[[13, [5, 1]~, 1, 1, [-5, -1; 1, -5]] 2]
? ellap(E, fa[1,1])
%3 = -1 \\ non-split multiplicative reduction
? ellap(E, fa[2,1])
%4 = 1 \\ split multiplicative reduction
? P17 = idealprimedec(K,17)[1];
? ellap(E, P17)
%6 = 6 \\ good reduction
? E2 = ellchangecurve(E, [17,0,0,0]);
? ellap(E2, P17)
%8 = 6 \\ same, starting from a non-miminal model
? P3 = idealprimedec(K,3)[1];
? E3 = ellchangecurve(E, [3,0,0,0]);
? ellap(E, P3) \\ OK: E is minimal at P3
%11 = -2
? ellap(E3, P3) \\ junk: E3 is not minimal at P3 | 3
%12 = 0
@eprog
\misctitle{Algorithms used} If $E/\F_q$ has CM by a principal imaginary
quadratic order we use a fast explicit formula (involving essentially
Kronecker symbols and Cornacchia's algorithm), in $O(\log q)^2$.
Otherwise, we use Shanks-Mestre's baby-step/giant-step method, which runs in
time $\tilde{O}(q^{1/4})$ using $\tilde{O}(q^{1/4})$ storage, hence becomes
unreasonable when $q$ has about 30~digits. Above this range, the \tet{SEA}
algorithm becomes available, heuristically in $\tilde{O}(\log q)^4$, and
primes of the order of 200~digits become feasible. In small
characteristic we use Mestre's (p=2), Kohel's (p=3,5,7,13), Satoh-Harley
(all in $\tilde{O}(p^{2}\*n^2)$) or Kedlaya's (in $\tilde{O}(p\*n^3)$)
algorithms.
Function: ellbil
Class: basic
Section: elliptic_curves
C-Name: bilhell
Prototype: GGGp
Help: ellbil(E,z1,z2): deprecated alias for ellheight(E,P,Q).
Doc: deprecated alias for \kbd{ellheight(E,P,Q)}.
Obsolete: 2014-05-21
Function: ellcard
Class: basic
Section: elliptic_curves
C-Name: ellcard
Prototype: GDG
Help: ellcard(E,{p}): computes the order of the group E(Fq)
for the elliptic curve E, defined over Q (for q=p) or a finite field.
Doc: Let $E$ be an \kbd{ell} structure as output by \kbd{ellinit}, defined over
$\Q$ or a finite field $\F_q$. The argument $p$ is best left omitted if the
curve is defined over a finite field, and must be a prime number otherwise.
This function computes the order of the group $E(\F_q)$ (as would be
computed by \tet{ellgroup}).
When the characteristic of the finite field is large, the availability of
the \kbd{seadata} package will speed the computation.
If the curve is defined over $\Q$, $p$ must be explicitly given and the
function computes the cardinality of the reduction over $\F_p$; the
equation need not be minimal at $p$, but a minimal model will be more
efficient. The reduction is allowed to be singular, and we return the order
of the group of non-singular points in this case.
Variant: Also available is \fun{GEN}{ellcard}{GEN E, GEN p} where $p$ is not
\kbd{NULL}.
Function: ellchangecurve
Class: basic
Section: elliptic_curves
C-Name: ellchangecurve
Prototype: GG
Help: ellchangecurve(E,v): change data on elliptic curve according to
v=[u,r,s,t].
Description:
(gen, gen):ell ellchangecurve($1, $2)
Doc:
changes the data for the elliptic curve $E$
by changing the coordinates using the vector \kbd{v=[u,r,s,t]}, i.e.~if $x'$
and $y'$ are the new coordinates, then $x=u^2x'+r$, $y=u^3y'+su^2x'+t$.
$E$ must be an \kbd{ell} structure as output by \kbd{ellinit}. The special
case $v = 1$ is also used instead of $[1,0,0,0]$ to denote the
trivial coordinate change.
Function: ellchangepoint
Class: basic
Section: elliptic_curves
C-Name: ellchangepoint
Prototype: GG
Help: ellchangepoint(x,v): change data on point or vector of points x on an
elliptic curve according to v=[u,r,s,t].
Doc:
changes the coordinates of the point or
vector of points $x$ using the vector \kbd{v=[u,r,s,t]}, i.e.~if $x'$ and
$y'$ are the new coordinates, then $x=u^2x'+r$, $y=u^3y'+su^2x'+t$ (see also
\kbd{ellchangecurve}).
\bprog
? E0 = ellinit([1,1]); P0 = [0,1]; v = [1,2,3,4];
? E = ellchangecurve(E0, v);
? P = ellchangepoint(P0,v)
%3 = [-2, 3]
? ellisoncurve(E, P)
%4 = 1
? ellchangepointinv(P,v)
%5 = [0, 1]
@eprog
Variant: The reciprocal function \fun{GEN}{ellchangepointinv}{GEN x, GEN ch}
inverts the coordinate change.
Function: ellchangepointinv
Class: basic
Section: elliptic_curves
C-Name: ellchangepointinv
Prototype: GG
Help: ellchangepointinv(x,v): change data on point or vector of points x on an
elliptic curve according to v=[u,r,s,t], inverse of ellchangepoint.
Doc:
changes the coordinates of the point or vector of points $x$ using
the inverse of the isomorphism attached to \kbd{v=[u,r,s,t]},
i.e.~if $x'$ and $y'$ are the old coordinates, then $x=u^2x'+r$,
$y=u^3y'+su^2x'+t$ (inverse of \kbd{ellchangepoint}).
\bprog
? E0 = ellinit([1,1]); P0 = [0,1]; v = [1,2,3,4];
? E = ellchangecurve(E0, v);
? P = ellchangepoint(P0,v)
%3 = [-2, 3]
? ellisoncurve(E, P)
%4 = 1
? ellchangepointinv(P,v)
%5 = [0, 1] \\ we get back P0
@eprog
Function: ellconvertname
Class: basic
Section: elliptic_curves
C-Name: ellconvertname
Prototype: G
Help: ellconvertname(name): convert an elliptic curve name (as found in
the elldata database) from a string to a triplet [conductor, isogeny class,
index]. It will also convert a triplet back to a curve name.
Doc:
converts an elliptic curve name, as found in the \tet{elldata} database,
from a string to a triplet $[\var{conductor}, \var{isogeny class},
\var{index}]$. It will also convert a triplet back to a curve name.
Examples:
\bprog
? ellconvertname("123b1")
%1 = [123, 1, 1]
? ellconvertname(%)
%2 = "123b1"
@eprog
Function: elldivpol
Class: basic
Section: elliptic_curves
C-Name: elldivpol
Prototype: GLDn
Help: elldivpol(E,n,{v='x}): n-division polynomial f_n for the curve E in the
variable v.
Doc: $n$-division polynomial $f_n$ for the curve $E$ in the
variable $v$. In standard notation, for any affine point $P = (X,Y)$ on the
curve, we have
$$[n]P = (\phi_n(P)\psi_n(P) : \omega_n(P) : \psi_n(P)^3)$$
for some polynomials $\phi_n,\omega_n,\psi_n$ in
$\Z[a_1,a_2,a_3,a_4,a_6][X,Y]$. We have $f_n(X) = \psi_n(X)$ for $n$ odd, and
$f_n(X) = \psi_n(X,Y) (2Y + a_1X+a_3)$ for $n$ even. We have
$$ f_1 = 1,\quad f_2 = 4X^3 + b_2X^2 + 2b_4 X + b_6, \quad f_3 = 3 X^4 + b_2 X^3 + 3b_4 X^2 + 3 b_6 X + b8, $$
$$ f_4 = f_2(2X^6 + b_2 X^5 + 5b_4 X^4 + 10 b_6 X^3 + 10 b_8 X^2 +
(b_2b_8-b_4b_6)X + (b_8b_4 - b_6^2)), \dots $$
For $n \geq 2$, the roots of $f_n$ are the $X$-coordinates of points in $E[n]$.
Function: elleisnum
Class: basic
Section: elliptic_curves
C-Name: elleisnum
Prototype: GLD0,L,p
Help: elleisnum(w,k,{flag=0}): k being an even positive integer, computes the
numerical value of the Eisenstein series of weight k at the lattice
w, as given by ellperiods. When flag is non-zero and k=4 or 6, this gives the
elliptic invariants g2 or g3 with the correct normalization.
Doc: $k$ being an even positive integer, computes the numerical value of the
Eisenstein series of weight $k$ at the lattice $w$, as given by
\tet{ellperiods}, namely
$$
(2i \pi/\omega_2)^k
\Big(1 + 2/\zeta(1-k) \sum_{n\geq 1} n^{k-1}q^n / (1-q^n)\Big),
$$
where $q = \exp(2i\pi \tau)$ and $\tau:=\omega_1/\omega_2$ belongs to the
complex upper half-plane. It is also possible to directly input $w =
[\omega_1,\omega_2]$, or an elliptic curve $E$ as given by \kbd{ellinit}.
\bprog
? w = ellperiods([1,I]);
? elleisnum(w, 4)
%2 = 2268.8726415508062275167367584190557607
? elleisnum(w, 6)
%3 = -3.977978632282564763 E-33
? E = ellinit([1, 0]);
? elleisnum(E, 4, 1)
%5 = -47.999999999999999999999999999999999998
@eprog
When \fl\ is non-zero and $k=4$ or 6, returns the elliptic invariants $g_2$
or $g_3$, such that
$$y^2 = 4x^3 - g_2 x - g_3$$
is a Weierstrass equation for $E$.
Function: elleta
Class: basic
Section: elliptic_curves
C-Name: elleta
Prototype: Gp
Help: elleta(w): w=[w1,w2], returns the vector [eta1,eta2] of quasi-periods
attached to [w1,w2].
Doc: returns the quasi-periods $[\eta_1,\eta_2]$
attached to the lattice basis $\var{w} = [\omega_1, \omega_2]$.
Alternatively, \var{w} can be an elliptic curve $E$ as output by
\kbd{ellinit}, in which case, the quasi periods attached to the period
lattice basis \kbd{$E$.omega} (namely, \kbd{$E$.eta}) are returned.
\bprog
? elleta([1, I])
%1 = [3.141592653589793238462643383, 9.424777960769379715387930149*I]
@eprog
Function: ellformaldifferential
Class: basic
Section: elliptic_curves
C-Name: ellformaldifferential
Prototype: GDPDn
Help: ellformaldifferential(E, {n=seriesprecision}, {t = 'x}) : E elliptic curve,
n integer. Returns n terms of the power series [f, g] such that
omega = dx/(2y+a_1x+a_3) = f(t) dt and eta = x(t) * omega = g(t) dt in the
local parameter t=-x/y.
Doc: Let $\omega := dx / (2y+a_1x+a_3)$ be the invariant differential form
attached to the model $E$ of some elliptic curve (\kbd{ellinit} form),
and $\eta := x(t)\omega$. Return $n$ terms (\tet{seriesprecision} by default)
of $f(t),g(t)$ two power series in the formal parameter $t=-x/y$ such that
$\omega = f(t) dt$, $\eta = g(t) dt$:
$$f(t) = 1+a_1 t + (a_1^2 + a_2) t^2 + \dots,\quad
g(t) = t^{-2} +\dots $$
\bprog
? E = ellinit([-1,1/4]); [f,g] = ellformaldifferential(E,7,'t);
? f
%2 = 1 - 2*t^4 + 3/4*t^6 + O(t^7)
? g
%3 = t^-2 - t^2 + 1/2*t^4 + O(t^5)
@eprog
Function: ellformalexp
Class: basic
Section: elliptic_curves
C-Name: ellformalexp
Prototype: GDPDn
Help: ellformalexp(E, {n = seriesprecision}, {z = 'x}) : E elliptic curve,
returns n terms of the formal elliptic exponential on E as a series in z.
Doc: The elliptic formal exponential \kbd{Exp} attached to $E$ is the
isomorphism from the formal additive law to the formal group of $E$. It is
normalized so as to be the inverse of the elliptic logarithm (see
\tet{ellformallog}): $\kbd{Exp} \circ L = \Id$. Return $n$ terms of this
power series:
\bprog
? E=ellinit([-1,1/4]); Exp = ellformalexp(E,10,'z)
%1 = z + 2/5*z^5 - 3/28*z^7 + 2/15*z^9 + O(z^11)
? L = ellformallog(E,10,'t);
? subst(Exp,z,L)
%3 = t + O(t^11)
@eprog
Function: ellformallog
Class: basic
Section: elliptic_curves
C-Name: ellformallog
Prototype: GDPDn
Help: ellformallog(E, {n = seriesprecision}, {v = 'x}): E elliptic curve,
returns n terms of the elliptic logarithm as a series of t =-x/y.
Doc: The formal elliptic logarithm is a series $L$ in $t K[[t]]$
such that $d L = \omega = dx / (2y + a_1x + a_3)$, the canonical invariant
differential attached to the model $E$. It gives an isomorphism
from the formal group of $E$ to the additive formal group.
\bprog
? E = ellinit([-1,1/4]); L = ellformallog(E, 9, 't)
%1 = t - 2/5*t^5 + 3/28*t^7 + 2/3*t^9 + O(t^10)
? [f,g] = ellformaldifferential(E,8,'t);
? L' - f
%3 = O(t^8)
@eprog
Function: ellformalpoint
Class: basic
Section: elliptic_curves
C-Name: ellformalpoint
Prototype: GDPDn
Help: ellformalpoint(E, {n = seriesprecision}, {v = 'x}): E elliptic curve,
n integer; return the coordinates [x(t), y(t)] on the elliptic curve as a
formal expansion in the formal parameter t = -x/y.
Doc: If $E$ is an elliptic curve, return the coordinates $x(t), y(t)$ in the
formal group of the elliptic curve $E$ in the formal parameter $t = -x/y$
at $\infty$:
$$ x = t^{-2} -a_1 t^{-1} - a_2 - a_3 t + \dots $$
$$ y = - t^{-3} -a_1 t^{-2} - a_2t^{-1} -a_3 + \dots $$
Return $n$ terms (\tet{seriesprecision} by default) of these two power
series, whose coefficients are in $\Z[a_1,a_2,a_3,a_4,a_6]$.
\bprog
? E = ellinit([0,0,1,-1,0]); [x,y] = ellformalpoint(E,8,'t);
? x
%2 = t^-2 - t + t^2 - t^4 + 2*t^5 + O(t^6)
? y
%3 = -t^-3 + 1 - t + t^3 - 2*t^4 + O(t^5)
? E = ellinit([0,1/2]); ellformalpoint(E,7)
%4 = [x^-2 - 1/2*x^4 + O(x^5), -x^-3 + 1/2*x^3 + O(x^4)]
@eprog
Function: ellformalw
Class: basic
Section: elliptic_curves
C-Name: ellformalw
Prototype: GDPDn
Help: ellformalw(E, {n = seriesprecision}, {t = 'x}): E elliptic curve,
n integer; returns n terms of the formal expansion of w = -1/y in the formal
parameter t = -x/y.
Doc: Return the formal power series $w$ attached to the elliptic curve $E$,
in the variable $t$:
$$ w(t) = t^3 + a_1 t^4 + (a_2 + a_1^2) t^5 + \cdots + O(t^{n+3}),$$
which is the formal expansion of $-1/y$ in the formal parameter $t := -x/y$
at $\infty$ (take $n = \tet{seriesprecision}$ if $n$ is omitted). The
coefficients of $w$ belong to $\Z[a_1,a_2,a_3,a_4,a_6]$.
\bprog
? E=ellinit([3,2,-4,-2,5]); ellformalw(E, 5, 't)
%1 = t^3 + 3*t^4 + 11*t^5 + 35*t^6 + 101*t^7 + O(t^8)
@eprog
Function: ellfromeqn
Class: basic
Section: elliptic_curves
C-Name: ellfromeqn
Prototype: G
Help: ellfromeqn(P): given a genus 1 plane curve, defined by the affine
equation f(x,y) = 0, return the coefficients [a1,a2,a3,a4,a6] of a
Weierstrass equation for its Jacobian.
This allows to recover a Weierstrass model for an elliptic curve given by a
general plane cubic or by a binary quartic or biquadratic model.
Doc:
Given a genus $1$ plane curve, defined by the affine equation $f(x,y) = 0$,
return the coefficients $[a_1,a_2,a_3,a_4,a_6]$ of a Weierstrass equation
for its Jacobian. This allows to recover a Weierstrass model for an elliptic
curve given by a general plane cubic or by a binary quartic or biquadratic
model. The function implements the $f \mapsto f^*$ formulae of Artin, Tate
and Villegas (Advances in Math. 198 (2005), pp. 366--382).
In the example below, the function is used to convert between twisted Edwards
coordinates and Weierstrass coordinates.
\bprog
? e = ellfromeqn(a*x^2+y^2 - (1+d*x^2*y^2))
%1 = [0, -a - d, 0, -4*d*a, 4*d*a^2 + 4*d^2*a]
? E = ellinit(ellfromeqn(y^2-x^2 - 1 +(121665/121666*x^2*y^2)),2^255-19);
? isprime(ellcard(E) / 8)
%3 = 1
@eprog
The elliptic curve attached to the sum of two cubes is given by
\bprog
? ellfromeqn(x^3+y^3 - a)
%1 = [0, 0, -9*a, 0, -27*a^2]
@eprog
\misctitle{Congruent number problem:}
Let $n$ be an integer, if $a^2+b^2=c^2$ and $a\*b=2\*n$,
then by substituting $b$ by $2\*n/a$ in the first equation,
we get $((a^2+(2\*n/a)^2)-c^2)\*a^2 = 0$.
We set $x=a$, $y=a\*c$.
\bprog
? En = ellfromeqn((x^2 + (2*n/x)^2 - (y/x)^2)*x^2)
%1 = [0, 0, 0, -16*n^2, 0]
@eprog
For example $23$ is congruent since the curve has a point of infinite order,
namely:
\bprog
? ellheegner( ellinit(subst(En, n, 23)) )
%2 = [168100/289, 68053440/4913]
@eprog
Function: ellfromj
Class: basic
Section: elliptic_curves
C-Name: ellfromj
Prototype: G
Help: ellfromj(j): returns the coefficients [a1,a2,a3,a4,a6] of a fixed
elliptic curve with j-invariant j.
Doc: returns the coefficients $[a_1,a_2,a_3,a_4,a_6]$ of a fixed elliptic curve
with $j$-invariant $j$.
Function: ellgenerators
Class: basic
Section: elliptic_curves
C-Name: ellgenerators
Prototype: G
Help: ellgenerators(E): if E is an elliptic curve over the rationals,
return the generators of the Mordell-Weil group attached to the curve.
This relies on the curve being referenced in the elldata database.
If E is an elliptic curve over a finite field Fq as output by ellinit(),
return a minimal set of generators for the group E(Fq).
Doc:
If $E$ is an elliptic curve over the rationals, return a $\Z$-basis of the
free part of the \idx{Mordell-Weil group} attached to $E$. This relies on
the \tet{elldata} database being installed and referencing the curve, and so
is only available for curves over $\Z$ of small conductors.
If $E$ is an elliptic curve over a finite field $\F_q$ as output by
\tet{ellinit}, return a minimal set of generators for the group $E(\F_q)$.
Function: ellglobalred
Class: basic
Section: elliptic_curves
C-Name: ellglobalred
Prototype: G
Help: ellglobalred(E): E being an elliptic curve over a number field,
returns [N, v, c, faN, L], where N is the conductor of E,
c is the product of the local Tamagawa numbers c_p, faN is the
factorization of N and L[i] is elllocalred(E, faN[i,1]); v is an obsolete
field.
Description:
(gen):gen ellglobalred($1)
Doc: let $E$ be an \kbd{ell} structure as output by \kbd{ellinit} attached
to an elliptic curve defined over a number field. This function calculates
the arithmetic conductor and the global \idx{Tamagawa number} $c$.
The result $[N,v,c,F,L]$ is slightly different if $E$ is defined
over $\Q$ (domain $D = 1$ in \kbd{ellinit}) or over a number field
(domain $D$ is a number field structure, including \kbd{nfinit(x)}
representing $\Q$ !):
\item $N$ is the arithmetic conductor of the curve,
\item $v$ is an obsolete field, left in place for backward compatibility.
If $E$ is defined over $\Q$, $v$ gives the coordinate change for $E$ to the
standard minimal integral model (\tet{ellminimalmodel} provides it in a
cheaper way); if $E$ is defined over another number field, $v$ gives a
coordinate change to an integral model (\tet{ellintegralmodel} provides it
in a cheaper way).
\item $c$ is the product of the local Tamagawa numbers $c_p$, a quantity
which enters in the \idx{Birch and Swinnerton-Dyer conjecture},
\item $F$ is the factorization of $N$,
\item $L$ is a vector, whose $i$-th entry contains the local data
at the $i$-th prime ideal divisor of $N$, i.e.
\kbd{L[i] = elllocalred(E,F[i,1])}. If $E$ is defined over $\Q$, the local
coordinate change has been deleted and replaced by a 0; if $E$ is defined
over another number field the local coordinate change to a local minimal
model is given relative to the integral model afforded by $v$ (so either
start from an integral model so that $v$ be trivial, or apply $v$ first).
Function: ellgroup
Class: basic
Section: elliptic_curves
C-Name: ellgroup0
Prototype: GDGD0,L,
Help: ellgroup(E,{p},{flag}): computes the structure of the group E(Fp)
If flag is 1, return also generators.
Doc: Let $E$ be an \kbd{ell} structure as output by \kbd{ellinit}, defined over
$\Q$ or a finite field $\F_q$. The argument $p$ is best left omitted if the
curve is defined over a finite field, and must be a prime number otherwise.
This function computes the structure of the group $E(\F_q) \sim \Z/d_1\Z
\times \Z/d_2\Z$, with $d_2\mid d_1$.
If the curve is defined over $\Q$, $p$ must be explicitly given and the
function computes the structure of the reduction over $\F_p$; the
equation need not be minimal at $p$, but a minimal model will be more
efficient. The reduction is allowed to be singular, and we return the
structure of the (cyclic) group of non-singular points in this case.
If the flag is $0$ (default), return $[d_1]$ or $[d_1, d_2]$, if $d_2>1$.
If the flag is $1$, return a triple $[h,\var{cyc},\var{gen}]$, where
$h$ is the curve cardinality, \var{cyc} gives the group structure as a
product of cyclic groups (as per $\fl = 0$). More precisely, if $d_2 > 1$,
the output is $[d_1d_2, [d_1,d_2],[P,Q]]$ where $P$ is
of order $d_1$ and $[P,Q]$ generates the curve.
\misctitle{Caution} It is not guaranteed that $Q$ has order $d_2$, which in
the worst case requires an expensive discrete log computation. Only that
\kbd{ellweilpairing(E, P, Q, d1)} has order $d_2$.
\bprog
? E = ellinit([0,1]); \\ y^2 = x^3 + 0.x + 1, defined over Q
? ellgroup(E, 7)
%2 = [6, 2] \\ Z/6 x Z/2, non-cyclic
? E = ellinit([0,1] * Mod(1,11)); \\ defined over F_11
? ellgroup(E) \\ no need to repeat 11
%4 = [12]
? ellgroup(E, 11) \\ ... but it also works
%5 = [12]
? ellgroup(E, 13) \\ ouch, inconsistent input!
*** at top-level: ellgroup(E,13)
*** ^--------------
*** ellgroup: inconsistent moduli in Rg_to_Fp:
11
13
? ellgroup(E, 7, 1)
%6 = [12, [6, 2], [[Mod(2, 7), Mod(4, 7)], [Mod(4, 7), Mod(4, 7)]]]
@eprog\noindent
If $E$ is defined over $\Q$, we allow singular reduction and in this case we
return the structure of the group of non-singular points, satisfying
$\#E_{ns}(\F_p) = p - a_p$.
\bprog
? E = ellinit([0,5]);
? ellgroup(E, 5, 1)
%2 = [5, [5], [[Mod(4, 5), Mod(2, 5)]]]
? ellap(E, 5)
%3 = 0 \\ additive reduction at 5
? E = ellinit([0,-1,0,35,0]);
? ellgroup(E, 5, 1)
%5 = [4, [4], [[Mod(2, 5), Mod(2, 5)]]]
? ellap(E, 5)
%6 = 1 \\ split multiplicative reduction at 5
? ellgroup(E, 7, 1)
%7 = [8, [8], [[Mod(3, 7), Mod(5, 7)]]]
? ellap(E, 7)
%8 = -1 \\ non-split multiplicative reduction at 7
@eprog
Variant: Also available is \fun{GEN}{ellgroup}{GEN E, GEN p}, corresponding
to \fl = 0.
Function: ellheegner
Class: basic
Section: elliptic_curves
C-Name: ellheegner
Prototype: G
Help: ellheegner(E): return a rational non-torsion point on the elliptic curve E
assumed to be of rank 1.
Doc: Let $E$ be an elliptic curve over the rationals, assumed to be of
(analytic) rank $1$. This returns a non-torsion rational point on the curve,
whose canonical height is equal to the product of the elliptic regulator by the
analytic Sha.
This uses the Heegner point method, described in Cohen GTM 239; the complexity
is proportional to the product of the square root of the conductor and the
height of the point (thus, it is preferable to apply it to strong Weil curves).
\bprog
? E = ellinit([-157^2,0]);
? u = ellheegner(E); print(u[1], "\n", u[2])
69648970982596494254458225/166136231668185267540804
538962435089604615078004307258785218335/67716816556077455999228495435742408
? ellheegner(ellinit([0,1])) \\ E has rank 0 !
*** at top-level: ellheegner(E=ellinit
*** ^--------------------
*** ellheegner: The curve has even analytic rank.
@eprog
Function: ellheight
Class: basic
Section: elliptic_curves
C-Name: ellheight0
Prototype: GGDGp
Help: ellheight(E,P,{Q}): canonical height of point P on elliptic curve E,
resp. the value of the attached bilinear form at (P,Q).
Doc: global N\'eron-Tate height $h(P)$ of the point $P$ on the elliptic curve
$E/\Q$, using the normalization in Cremona's \emph{Algorithms for modular
elliptic curves}. $E$ must be an \kbd{ell} as output by \kbd{ellinit}; it
needs not be given by a minimal model although the computation will be faster
if it is.
If the argument $Q$ is present, computes the value of the bilinear
form $(h(P+Q)-h(P-Q)) / 4$.
Variant: Also available is \fun{GEN}{ellheight}{GEN E, GEN P, long prec}
($Q$ omitted).
Function: ellheightmatrix
Class: basic
Section: elliptic_curves
C-Name: ellheightmatrix
Prototype: GGp
Help: ellheightmatrix(E,x): gives the height matrix for vector of points x
on elliptic curve E.
Doc: $x$ being a vector of points, this
function outputs the Gram matrix of $x$ with respect to the N\'eron-Tate
height, in other words, the $(i,j)$ component of the matrix is equal to
\kbd{ellbil($E$,x[$i$],x[$j$])}. The rank of this matrix, at least in some
approximate sense, gives the rank of the set of points, and if $x$ is a
basis of the \idx{Mordell-Weil group} of $E$, its determinant is equal to
the regulator of $E$. Note our height normalization follows Cremona's
\emph{Algorithms for modular elliptic curves}: this matrix should be divided
by 2 to be in accordance with, e.g., Silverman's normalizations.
Function: ellidentify
Class: basic
Section: elliptic_curves
C-Name: ellidentify
Prototype: G
Help: ellidentify(E): look up the elliptic curve E in the elldata database and
return [[N, M, ...], C] where N is the name of the curve in Cremona's
database, M the minimal model and C the coordinates change (see
ellchangecurve).
Doc: look up the elliptic curve $E$, defined by an arbitrary model over $\Q$,
in the \tet{elldata} database.
Return \kbd{[[N, M, G], C]} where $N$ is the curve name in Cremona's
elliptic curve database, $M$ is the minimal model, $G$ is a $\Z$-basis of
the free part of the \idx{Mordell-Weil group} $E(\Q)$ and $C$ is the
change of coordinates change, suitable for \kbd{ellchangecurve}.
Function: ellinit
Class: basic
Section: elliptic_curves
C-Name: ellinit
Prototype: GDGp
Help: ellinit(x,{D=1}): let x be a vector [a1,a2,a3,a4,a6], or [a4,a6] if
a1=a2=a3=0, defining the curve Y^2 + a1.XY + a3.Y = X^3 + a2.X^2 + a4.X +
a6; x can also be a string, in which case the curve with matching name is
retrieved from the elldata database, if available. This function initializes
an elliptic curve over the domain D (inferred from coefficients if omitted).
Description:
(gen, gen, small):ell:prec ellinit($1, $2, $prec)
Doc:
initialize an \tet{ell} structure, attached to the elliptic curve $E$.
$E$ is either
\item a $5$-component vector $[a_1,a_2,a_3,a_4,a_6]$ defining the elliptic
curve with Weierstrass equation
$$ Y^2 + a_1 XY + a_3 Y = X^3 + a_2 X^2 + a_4 X + a_6, $$
\item a $2$-component vector $[a_4,a_6]$ defining the elliptic
curve with short Weierstrass equation
$$ Y^2 = X^3 + a_4 X + a_6, $$
\item a character string in Cremona's notation, e.g. \kbd{"11a1"}, in which
case the curve is retrieved from the \tet{elldata} database if available.
The optional argument $D$ describes the domain over which the curve is
defined:
\item the \typ{INT} $1$ (default): the field of rational numbers $\Q$.
\item a \typ{INT} $p$, where $p$ is a prime number: the prime finite field
$\F_p$.
\item an \typ{INTMOD} \kbd{Mod(a, p)}, where $p$ is a prime number: the
prime finite field $\F_p$.
\item a \typ{FFELT}, as returned by \tet{ffgen}: the corresponding finite
field $\F_q$.
\item a \typ{PADIC}, $O(p^n)$: the field $\Q_p$, where $p$-adic quantities
will be computed to a relative accuracy of $n$ digits. We advise to input a
model defined over $\Q$ for such curves. In any case, if you input an
approximate model with \typ{PADIC} coefficients, it will be replaced by a lift
to $\Q$ (an exact model ``close'' to the one that was input) and all quantities
will then be computed in terms of this lifted model, at the given accuracy.
\item a \typ{REAL} $x$: the field $\C$ of complex numbers, where floating
point quantities are by default computed to a relative accuracy of
\kbd{precision}$(x)$. If no such argument is given, the value of
\kbd{realprecision} at the time \kbd{ellinit} is called will be used.
\item a number field $K$, given by a \kbd{nf} or \kbd{bnf} structure; a
\kbd{bnf} is required for \kbd{ellminimalmodel}.
\item a prime ideal $\goth{p}$, given by a \kbd{prid} structure; valid if
$x$ is a curve defined over a number field $K$ and the equation is integral
and minimal at $\goth{p}$.
This argument $D$ is indicative: the curve coefficients are checked for
compatibility, possibly changing $D$; for instance if $D = 1$ and
an \typ{INTMOD} is found. If inconsistencies are detected, an error is
raised:
\bprog
? ellinit([1 + O(5), 1], O(7));
*** at top-level: ellinit([1+O(5),1],O
*** ^--------------------
*** ellinit: inconsistent moduli in ellinit: 7 != 5
@eprog\noindent If the curve coefficients are too general to fit any of the
above domain categories, only basic operations, such as point addition, will
be supported later.
If the curve (seen over the domain $D$) is singular, fail and return an
empty vector $[]$.
\bprog
? E = ellinit([0,0,0,0,1]); \\ y^2 = x^3 + 1, over Q
? E = ellinit([0,1]); \\ the same curve, short form
? E = ellinit("36a1"); \\ sill the same curve, Cremona's notations
? E = ellinit([0,1], 2) \\ over F2: singular curve
%4 = []
? E = ellinit(['a4,'a6] * Mod(1,5)); \\ over F_5[a4,a6], basic support !
@eprog\noindent
The result of \tet{ellinit} is an \tev{ell} structure. It contains at least
the following information in its components:
%
$$ a_1,a_2,a_3,a_4,a_6,b_2,b_4,b_6,b_8,c_4,c_6,\Delta,j.$$
%
All are accessible via member functions. In particular, the discriminant is
\kbd{$E$.disc}, and the $j$-invariant is \kbd{$E$.j}.
\bprog
? E = ellinit([a4, a6]);
? E.disc
%2 = -64*a4^3 - 432*a6^2
? E.j
%3 = -6912*a4^3/(-4*a4^3 - 27*a6^2)
@eprog
Further components contain domain-specific data, which are in general dynamic:
only computed when needed, and then cached in the structure.
\bprog
? E = ellinit([2,3], 10^60+7); \\ E over F_p, p large
? ellap(E)
time = 4,440 ms.
%2 = -1376268269510579884904540406082
? ellcard(E); \\ now instantaneous !
time = 0 ms.
? ellgenerators(E);
time = 5,965 ms.
? ellgenerators(E); \\ second time instantaneous
time = 0 ms.
@eprog
See the description of member functions related to elliptic curves at the
beginning of this section.
Function: ellintegralmodel
Class: basic
Section: elliptic_curves
C-Name: ellintegralmodel
Prototype: GD&
Help: ellintegralmodel(E,{&v}): given an elliptic curve E defined
over a number field, returns an integral model. If v is present,
sets the variable v to the corresponding change of variable.
Doc: Let $E$ be an \kbd{ell} structure over a number field $K$. This function
returns an integral model. If $v$ is present, sets $v = [u,0,0,0]$ to the
corresponding change of variable: the return value is identical to that of
\kbd{ellchangecurve(E, v)}.
Function: ellisdivisible
Class: basic
Section: elliptic_curves
C-Name: ellisdivisible
Prototype: lGGGD&
Help: ellisdivisible(E,P,n,{&Q})): given E/K and P in E(K),
checks whether P = [n]R for some R in E(K) and sets Q to one such R if so;
the integer n >= 0 may be given as ellxn(E,n).
Doc: given $E/K$ a number field and $P$ in $E(K)$
return $1$ if $P = [n]R$ for some $R$ in $E(K)$ and set $Q$ to one such $R$;
and return $0$ otherwise. The integer $n \geq 0$ may be given as
\kbd{ellxn(E,n)}, if many points need to be tested.
\bprog
? K = nfinit(polcyclo(11,t));
? E = ellinit([0,-1,1,0,0], K);
? P = [0,0];
? ellorder(E,P)
%4 = 5
? ellisdivisible(E,P,5, &Q)
%5 = 1
? lift(Q)
%6 = [-t^7-t^6-t^5-t^4+1, -t^9-2*t^8-2*t^7-3*t^6-3*t^5-2*t^4-2*t^3-t^2-1]
? ellorder(E, Q)
%7 = 25
@eprog\noindent The algebraic complexity of the underlying algorithm is in
$O(n^4)$, so it is advisable to first factor $n$, then use a chain of checks
attached to the prime divisors of $n$: the function will do it itself unless
$n$ is given in \kbd{ellxn} form.
Function: ellisogeny
Class: basic
Section: elliptic_curves
C-Name: ellisogeny
Prototype: GGD0,L,DnDn
Help: ellisogeny(E, G, {only_image = 0}, {x = 'x}, {y = 'y}): compute the image
and isogeny corresponding to the quotient of E by the subgroup G.
Doc:
Given an elliptic curve $E$, a finite subgroup $G$ of $E$ is given either
as a generating point $P$ (for a cyclic $G$) or as a polynomial whose roots
vanish on the $x$-coordinates of the non-zero elements of $G$ (general case
and more efficient if available). This function returns the
$[a_1,a_2,a_3,a_4,a_6]$ invariants of the quotient elliptic curve $E/G$ and
(if \var{only\_image} is zero (the default)) a vector of rational
functions $[f, g, h]$ such that the isogeny $E \to E/G$ is given by $(x,y)
\mapsto (f(x)/h(x)^2, g(x,y)/h(x)^3)$.
\bprog
? E = ellinit([0,1]);
? elltors(E)
%2 = [6, [6], [[2, 3]]]
? ellisogeny(E, [2,3], 1) \\ Weierstrass model for E/<P>
%3 = [0, 0, 0, -135, -594]
? ellisogeny(E,[-1,0])
%4 = [[0,0,0,-15,22], [x^3+2*x^2+4*x+3, y*x^3+3*y*x^2-2*y, x+1]]
@eprog
Function: ellisogenyapply
Class: basic
Section: elliptic_curves
C-Name: ellisogenyapply
Prototype: GG
Help: ellisogenyapply(f, g): given an isogeny f and g either a point P (in the
domain of f) or an isogeny, apply f to g: return the image of P under f or
the composite isogeny f o g.
Doc:
Given an isogeny of elliptic curves $f:E'\to E$ (being the result of a call
to \tet{ellisogeny}), apply $f$ to $g$:
\item if $g$ is a point $P$ in the domain of $f$, return the image $f(P)$;
\item if $g:E''\to E'$ is a compatible isogeny, return the composite
isogeny $f \circ g: E''\to E$.
\bprog
? one = ffgen(101, 't)^0;
? E = ellinit([6, 53, 85, 32, 34] * one);
? P = [84, 71] * one;
? ellorder(E, P)
%4 = 5
? [F, f] = ellisogeny(E, P); \\ f: E->F = E/<P>
? ellisogenyapply(f, P)
%6 = [0]
? F = ellinit(F);
? Q = [89, 44] * one;
? ellorder(F, Q)
%9 = 2
? [G, g] = ellisogeny(F, Q); \\ g: F->G = F/<Q>
? gof = ellisogenyapply(g, f); \\ gof: E -> G
@eprog
Function: ellisomat
Class: basic
Section: elliptic_curves
C-Name: ellisomat
Prototype: GD0,L,
Help: ellisomat(E, {fl=0}): E being an elliptic curve over Q, return a list of
representatives of the isomorphism classes of elliptic curves isogenous to E,
with the corresponding isogenies from E and their dual, and the matrix of the
degrees of the isogenies between the curves. If the flag fl is 1, the
isogenies are not computed, which saves time.
Doc:
Given an elliptic curve $E$ defined over $\Q$, compute representatives of the
isomorphism classes of elliptic curves $\Q$-isogenous to $E$. The function
returns a vector $[L,M]$ where $L$ is a list of triples $[E_i, f_i, g_i]$,
where $E_i$ is an elliptic curve in $[a_4,a_6]$ form, $f_i: E \to E_i$
is a rational isogeny, $g_i: E_i \to E$ is the dual isogeny of $f_i$,
and $M$ is the matrix such that $M_{i,j}$ is the degree of the isogeny between
$E_i$ and $E_j$. Furthermore the first curve $E_1$ is isomorphic to $E$
by $f_1$. If the flag $\var{fl}=1$, the $f_i$ and $g_i$ are not computed,
which saves time, and $L$ is the list of the curves $E_i$.
\bprog
? E = ellinit("14a1");
? [L,M] = ellisomat(E);
? LE = apply(x->x[1], L) \\ list of curves
%3 = [[215/48,-5291/864],[-675/16,6831/32],[-8185/48,-742643/864],
[-1705/48,-57707/864],[-13635/16,306207/32],[-131065/48,-47449331/864]]
? L[2][2] \\ isogeny f_2
%4 = [x^3+3/4*x^2+19/2*x-311/12,
1/2*x^4+(y+1)*x^3+(y-4)*x^2+(-9*y+23)*x+(55*y+55/2),x+1/3]
? L[2][3] \\ dual isogeny g_2
%5 = [1/9*x^3-1/4*x^2-141/16*x+5613/64,
-1/18*x^4+(1/27*y-1/3)*x^3+(-1/12*y+87/16)*x^2+(49/16*y-48)*x
+(-3601/64*y+16947/512),x-3/4]
? apply(E->ellidentify(ellinit(E))[1][1], LE)
%6 = ["14a1","14a4","14a3","14a2","14a6","14a5"]
? M
%7 =
[1 3 3 2 6 6]
[3 1 9 6 2 18]
[3 9 1 6 18 2]
[2 6 6 1 3 3]
[6 2 18 3 1 9]
[6 18 2 3 9 1]
@eprog
Function: ellisoncurve
Class: basic
Section: elliptic_curves
C-Name: ellisoncurve
Prototype: GG
Help: ellisoncurve(E,z): true(1) if z is on elliptic curve E, false(0) if not.
Doc: gives 1 (i.e.~true) if the point $z$ is on the elliptic curve $E$, 0
otherwise. If $E$ or $z$ have imprecise coefficients, an attempt is made to
take this into account, i.e.~an imprecise equality is checked, not a precise
one. It is allowed for $z$ to be a vector of points in which case a vector
(of the same type) is returned.
Variant: Also available is \fun{int}{oncurve}{GEN E, GEN z} which does not
accept vectors of points.
Function: ellissupersingular
Class: basic
Section: elliptic_curves
C-Name: ellissupersingular
Prototype: iGDG
Help: ellissupersingular(E,{p}): decide whether the elliptic curve E, defined
over a number field or a finite field, is supersingular at p or not.
Doc:
Return 1 if the elliptic curve $E$ defined over a number field
or a finite field is supersingular at $p$, and $0$ otherwise.
If the curve is defined over a number field, $p$ must be explicitly given,
and must be a prime number, resp.~a maximal ideal, if the curve is defined
over $\Q$, resp.~a general number field: we return $1$ if and only if $E$
has supersingular good reduction at $p$.
Alternatively, $E$ can be given by its $j$-invariant in a finite field. In
this case $p$ must be omitted.
\bprog
? g = ffprimroot(ffgen(7^5))
%1 = x^3 + 2*x^2 + 3*x + 1
? [g^n | n <- [1 .. 7^5 - 1], ellissupersingular(g^n)]
%2 = [6]
? K = nfinit(y^3-2); P = idealprimedec(K, 2)[1];
? E = ellinit([y,1], K);
? ellissupersingular(E, P)
%5 = 1
@eprog
Variant: Also available is
\fun{int}{elljissupersingular}{GEN j} where $j$ is a $j$-invariant of a curve
over a finite field.
Function: ellj
Class: basic
Section: elliptic_curves
C-Name: jell
Prototype: Gp
Help: ellj(x): elliptic j invariant of x.
Doc:
elliptic $j$-invariant. $x$ must be a complex number
with positive imaginary part, or convertible into a power series or a
$p$-adic number with positive valuation.
Function: elllocalred
Class: basic
Section: elliptic_curves
C-Name: elllocalred
Prototype: GG
Help: elllocalred(E,p): E being an elliptic curve, returns
[f,kod,[u,r,s,t],c], where f is the conductor's exponent, kod is the Kodaira
type for E at p, [u,r,s,t] is the change of variable needed to make E
minimal at p, and c is the local Tamagawa number c_p.
Doc:
calculates the \idx{Kodaira} type of the local fiber of the elliptic curve
$E$ at $p$. $E$ must be an \kbd{ell} structure as output by
\kbd{ellinit}, over $\Q$ ($p$ a rational prime) or a number field $K$ ($p$
a maximal ideal given by a \kbd{prid} structure), and is assumed to have all
its coefficients $a_i$ integral.
The result is a 4-component vector $[f,kod,v,c]$. Here $f$ is the exponent of
$p$ in the arithmetic conductor of $E$, and $kod$ is the Kodaira type which
is coded as follows:
1 means good reduction (type I$_0$), 2, 3 and 4 mean types II, III and IV
respectively, $4+\nu$ with $\nu>0$ means type I$_\nu$;
finally the opposite values $-1$, $-2$, etc.~refer to the starred types
I$_0^*$, II$^*$, etc. The third component $v$ is itself a vector $[u,r,s,t]$
giving the coordinate changes done during the local reduction;
$u = 1$ if and only if the given equation was already minimal at $p$.
Finally, the last component $c$ is the local \idx{Tamagawa number} $c_p$.
Function: elllog
Class: basic
Section: elliptic_curves
C-Name: elllog
Prototype: GGGDG
Help: elllog(E,P,G,{o}): return the discrete logarithm of the point P of
the elliptic curve E in base G. If present, o represents the order of G.
If not present, assume that G generates the curve.
Doc: given two points $P$ and $G$ on the elliptic curve $E/\F_q$, returns the
discrete logarithm of $P$ in base $G$, i.e. the smallest non-negative
integer $n$ such that $P = [n]G$.
See \tet{znlog} for the limitations of the underlying discrete log algorithms.
If present, $o$ represents the order of $G$, see \secref{se:DLfun};
the preferred format for this parameter is \kbd{[N, factor(N)]}, where $N$
is the order of $G$.
If no $o$ is given, assume that $G$ generates the curve.
The function also assumes that $P$ is a multiple of $G$.
\bprog
? a = ffgen(ffinit(2,8),'a);
? E = ellinit([a,1,0,0,1]); \\ over F_{2^8}
? x = a^3; y = ellordinate(E,x)[1];
? P = [x,y]; G = ellmul(E, P, 113);
? ord = [242, factor(242)]; \\ P generates a group of order 242. Initialize.
? ellorder(E, G, ord)
%4 = 242
? e = elllog(E, P, G, ord)
%5 = 15
? ellmul(E,G,e) == P
%6 = 1
@eprog
Function: elllseries
Class: basic
Section: elliptic_curves
C-Name: elllseries
Prototype: GGDGp
Help: elllseries(E,s,{A=1}): L-series at s of the elliptic curve E, where A
a cut-off point close to 1.
Doc:
This function is deprecated, use \kbd{lfun(E,s)} instead.
$E$ being an elliptic curve, given by an arbitrary model over $\Q$ as output
by \kbd{ellinit}, this function computes the value of the $L$-series of $E$ at
the (complex) point $s$. This function uses an $O(N^{1/2})$ algorithm, where
$N$ is the conductor.
The optional parameter $A$ fixes a cutoff point for the integral and is best
left omitted; the result must be independent of $A$, up to
\kbd{realprecision}, so this allows to check the function's accuracy.
Obsolete: 2016-08-08
Function: ellminimalmodel
Class: basic
Section: elliptic_curves
C-Name: ellminimalmodel
Prototype: GD&
Help: ellminimalmodel(E,{&v}): determines whether the elliptic curve E defined
over a number field admits a global minimal model. If so return it
and sets v to the corresponding change of variable. Else return the
(non-principal) Weierstrass class of E.
Doc: Let $E$ be an \kbd{ell} structure over a number field $K$. This function
determines whether $E$ admits a global minimal integral model. If so, it
returns it and sets $v = [u,r,s,t]$ to the corresponding change of variable:
the return value is identical to that of \kbd{ellchangecurve(E, v)}.
Else return the (non-principal) Weierstrass class of $E$, i.e. the class of
$\prod \goth{p}^{(v_{\goth{p}}{\Delta} - \delta_{\goth{p}}) / 12}$ where
$\Delta = \kbd{E.disc}$ is the model's discriminant and
$\goth{p} ^ \delta_{\goth{p}}$ is the local minimal discriminant.
This function requires either that $E$ be defined
over the rational field $\Q$ (with domain $D = 1$ in \kbd{ellinit}),
in which case a global minimal model always exists, or over a number
field given by a \var{bnf} structure. The Weierstrass class is given in
\kbd{bnfisprincipal} format, i.e. in terms of the \kbd{K.gen} generators.
The resulting model has integral coefficients and is everywhere minimal, the
coefficients $a_1$ and $a_3$ are reduced modulo $2$ (in terms of the fixed
integral basis \kbd{K.zk}) and $a_2$ is reduced modulo $3$. Over $\Q$, we
further require that $a_1$ and $a_3$ be $0$ or $1$, that $a_2$ be $0$ or $\pm
1$ and that $u > 0$ in the change of variable: both the model and the change
of variable $v$ are then unique.\sidx{minimal model}
\bprog
? e = ellinit([6,6,12,55,233]); \\ over Q
? E = ellminimalmodel(e, &v);
? E[1..5]
%3 = [0, 0, 0, 1, 1]
? v
%4 = [2, -5, -3, 9]
@eprog
\bprog
? K = bnfinit(a^2-65); \\ over a non-principal number field
? K.cyc
%2 = [2]
? u = Mod(8+a, K.pol);
? E = ellinit([1,40*u+1,0,25*u^2,0], K);
? ellminimalmodel(E) \\ no global minimal model exists over Z_K
%6 = [1]~
@eprog
Function: ellminimaltwist
Class: basic
Section: elliptic_curves
C-Name: ellminimaltwist0
Prototype: GD0,L,
Help: ellminimaltwist(E, {flag=0}): E being an elliptic curve defined over Q, return
a discriminant D such the twist of E by D is minimal among all possible quadratic
twists, i.e. if flag=0, its minimal model has minimal discriminant,
or if flag=1, it has minimal conductor.
Doc: Let $E$ be an elliptic curve defined over $\Q$, return
a discriminant $D$ such that the twist of $E$ by $D$ is minimal among all
possible quadratic twists, i.e. if $\fl=0$, its minimal model has minimal
discriminant, or if $\fl=1$, it has minimal conductor.
In the example below, we find a curve with $j$-invariant $3$ and minimal
conductor.
\bprog
? E=ellminimalmodel(ellinit(ellfromj(3)));
? ellglobalred(E)[1]
%2 = 357075
? D = ellminimaltwist(E,1)
%3 = -15
? E2=ellminimalmodel(ellinit(elltwist(E,D)));
? ellglobalred(E2)[1]
%5 = 14283
@eprog
Variant: Also available are
\fun{GEN}{ellminimaltwist}{E} for $\fl=0$, and
\fun{GEN}{ellminimaltwistcond}{E} for $\fl=1$.
Function: ellmoddegree
Class: basic
Section: elliptic_curves
C-Name: ellmoddegree
Prototype: Gb
Help: ellmoddegree(e): e being an elliptic curve defined over Q output by
ellinit, compute the modular degree of e divided by the square of the
Manin constant. Return [D, err], where D is a rational number and
err is the exponent of the truncation error.
Doc: $e$ being an elliptic curve defined over $\Q$ output by \kbd{ellinit},
compute the modular degree of $e$ divided by the square of
the Manin constant. Return $[D, err]$, where $D$ is a rational number and
err is exponent of the truncation error.
Function: ellmodulareqn
Class: basic
Section: elliptic_curves
C-Name: ellmodulareqn
Prototype: LDnDn
Help: ellmodulareqn(N,{x},{y}): given a prime N < 500, return a vector [P, t]
where P(x,y) is a modular equation of level N. This requires the package
seadata. The equation is either of canonical type (t=0) or of Atkin type (t=1).
Doc: given a prime $N < 500$, return a vector $[P,t]$ where $P(x,y)$
is a modular equation of level $N$, i.e.~a bivariate polynomial with integer
coefficients; $t$ indicates the type of this equation: either
\emph{canonical} ($t = 0$) or \emph{Atkin} ($t = 1$). This function requires
the \kbd{seadata} package and its only use is to give access to the package
contents. See \tet{polmodular} for a more general and more flexible function.
Let $j$ be the $j$-invariant function. The polynomial $P$ satisfies
the functional equation,
$$ P(f,j) = P(f \mid W_N, j \mid W_N) = 0 $$
for some modular function $f = f_N$ (hand-picked for each fixed $N$ to
minimize its size, see below), where $W_N(\tau) = -1 / (N\*\tau)$ is the
Atkin-Lehner involution. These two equations allow to compute the values of
the classical modular polynomial $\Phi_N$, such that $\Phi_N(j(\tau),
j(N\tau)) = 0$, while being much smaller than the latter. More precisely, we
have $j(W_N(\tau)) = j(N\*\tau)$; the function $f$ is invariant under
$\Gamma_0(N)$ and also satisfies
\item for Atkin type: $f \mid W_N = f$;
\item for canonical type: let $s = 12/\gcd(12,N-1)$, then
$f \mid W_N = N^s / f$. In this case, $f$ has a simple definition:
$f(\tau) = N^s \* \big(\eta(N\*\tau) / \eta(\tau) \big)^{2\*s}$,
where $\eta$ is Dedekind's eta function.
The following GP function returns values of the classical modular polynomial
by eliminating $f_N(\tau)$ in the above functional equation,
for $N\leq 31$ or $N\in\{41,47,59,71\}$.
\bprog
classicaleqn(N, X='X, Y='Y)=
{
my([P,t] = ellmodulareqn(N), Q, d);
if (poldegree(P,'y) > 2, error("level unavailable in classicaleqn"));
if (t == 0, \\ Canonical
my(s = 12/gcd(12,N-1));
Q = 'x^(N+1) * substvec(P,['x,'y],[N^s/'x,Y]);
d = N^(s*(2*N+1)) * (-1)^(N+1);
, \\ Atkin
Q = subst(P,'y,Y);
d = (X-Y)^(N+1));
polresultant(subst(P,'y,X), Q) / d;
}
@eprog
Function: ellmul
Class: basic
Section: elliptic_curves
C-Name: ellmul
Prototype: GGG
Help: ellmul(E,z,n): n times the point z on elliptic curve E (n in Z).
Doc:
computes $[n]z$, where $z$ is a point on the elliptic curve $E$. The
exponent $n$ is in $\Z$, or may be a complex quadratic integer if the curve $E$
has complex multiplication by $n$ (if not, an error message is issued).
\bprog
? Ei = ellinit([1,0]); z = [0,0];
? ellmul(Ei, z, 10)
%2 = [0] \\ unsurprising: z has order 2
? ellmul(Ei, z, I)
%3 = [0, 0] \\ Ei has complex multiplication by Z[i]
? ellmul(Ei, z, quadgen(-4))
%4 = [0, 0] \\ an alternative syntax for the same query
? Ej = ellinit([0,1]); z = [-1,0];
? ellmul(Ej, z, I)
*** at top-level: ellmul(Ej,z,I)
*** ^--------------
*** ellmul: not a complex multiplication in ellmul.
? ellmul(Ej, z, 1+quadgen(-3))
%6 = [1 - w, 0]
@eprog
The simple-minded algorithm for the CM case assumes that we are in
characteristic $0$, and that the quadratic order to which $n$ belongs has
small discriminant.
Function: ellneg
Class: basic
Section: elliptic_curves
C-Name: ellneg
Prototype: GG
Help: ellneg(E,z): opposite of the point z on elliptic curve E.
Doc:
Opposite of the point $z$ on elliptic curve $E$.
Function: ellnonsingularmultiple
Class: basic
Section: elliptic_curves
C-Name: ellnonsingularmultiple
Prototype: GG
Help: ellnonsingularmultiple(E,P): given E/Q and P in E(Q), returns the pair
[R,n] where n is the least positive integer such that R = [n]P has
everywhere good reduction. More precisely, its image in a minimal model
is everywhere non-singular.
Doc: given an elliptic curve $E/\Q$ (more precisely, a model defined over $\Q$
of a curve) and a rational point $P \in E(\Q)$, returns the pair $[R,n]$,
where $n$ is the least positive integer such that $R := [n]P$ has good
reduction at every prime. More precisely, its image in a minimal model is
everywhere non-singular.
\bprog
? e = ellinit("57a1"); P = [2,-2];
? ellnonsingularmultiple(e, P)
%2 = [[1, -1], 2]
? e = ellinit("396b2"); P = [35, -198];
? [R,n] = ellnonsingularmultiple(e, P);
? n
%5 = 12
@eprog
Function: ellorder
Class: basic
Section: elliptic_curves
C-Name: ellorder
Prototype: GGDG
Help: ellorder(E,z,{o}): order of the point z on the elliptic curve E over
a number field or a finite field, 0 if non-torsion. The parameter o,
if present, represents a non-zero multiple of the order of z.
Doc: gives the order of the point $z$ on the elliptic
curve $E$, defined over a finite field or a number field.
Return (the impossible value) zero if the point has infinite order.
\bprog
? E = ellinit([-157^2,0]); \\ the "157-is-congruent" curve
? P = [2,2]; ellorder(E, P)
%2 = 2
? P = ellheegner(E); ellorder(E, P) \\ infinite order
%3 = 0
? K = nfinit(polcyclo(11,t)); E=ellinit("11a3", K); T = elltors(E);
? ellorder(E, T.gen[1])
%5 = 25
? E = ellinit(ellfromj(ffgen(5^10)));
? ellcard(E)
%7 = 9762580
? P = random(E); ellorder(E, P)
%8 = 4881290
? p = 2^160+7; E = ellinit([1,2], p);
? N = ellcard(E)
%9 = 1461501637330902918203686560289225285992592471152
? o = [N, factor(N)];
? for(i=1,100, ellorder(E,random(E)))
time = 260 ms.
@eprog
The parameter $o$, is now mostly useless, and kept for backward
compatibility. If present, it represents a non-zero multiple of the order
of $z$, see \secref{se:DLfun}; the preferred format for this parameter is
\kbd{[ord, factor(ord)]}, where \kbd{ord} is the cardinality of the curve.
It is no longer needed since PARI is now able to compute it over large
finite fields (was restricted to small prime fields at the time this feature
was introduced), \emph{and} caches the result in $E$ so that it is computed
and factored only once. Modifying the last example, we see that including
this extra parameter provides no improvement:
\bprog
? o = [N, factor(N)];
? for(i=1,100, ellorder(E,random(E),o))
time = 260 ms.
@eprog
Variant: The obsolete form \fun{GEN}{orderell}{GEN e, GEN z} should no longer be
used.
Function: ellordinate
Class: basic
Section: elliptic_curves
C-Name: ellordinate
Prototype: GGp
Help: ellordinate(E,x): y-coordinates corresponding to x-ordinate x on
elliptic curve E.
Doc:
gives a 0, 1 or 2-component vector containing
the $y$-coordinates of the points of the curve $E$ having $x$ as
$x$-coordinate.
Function: ellpadicL
Class: basic
Section: elliptic_curves
C-Name: ellpadicL
Prototype: GGLDGD0,L,DG
Help: ellpadicL(E, p, n, {s = 0}, {r = 0}, {D = 1}): returns the value
on a character of Z_p^* represented by an integer s or a vector [s1,s2]
of the derivative of order r of the p-adic L-function of
the elliptic curve E (twisted by D, if present).
Doc: Returns the value (or $r$-th derivative) on a character $\chi^s$ of
$\Z_p^*$ of the $p$-adic $L$-function of the elliptic curve $E/\Q$, twisted by
$D$, given modulo $p^n$.
\misctitle{Characters} The set of continuous characters of
$\text{Gal}(\Q(\mu_{p^{\infty}})/ \Q)$ is identified to $\Z_p^*$ via the
cyclotomic character $\chi$ with values in $\overline{\Q_p}^*$. Denote by
$\tau:\Z_p^*\to\Z_p^*$ the Teichm\"uller character, with values
in the $(p-1)$-th roots of $1$ for $p\neq 2$, and $\{-1,1\}$ for $p = 2$;
finally, let
$\langle\chi\rangle =\chi \tau^{-1}$, with values in $1 + 2p\Z_p$.
In GP, the continuous character of
$\text{Gal}(\Q(\mu_{p^{\infty}})/ \Q)$ given by $\langle\chi\rangle^{s_1}
\tau^{s_2}$ is represented by the pair of integers $s=(s_1,s_2)$, with $s_1
\in \Z_p$ and $s_2 \bmod p-1$ for $p > 2$, (resp. mod $2$ for $p = 2$); $s$
may be also an integer, representing $(s,s)$ or $\chi^s$.
\misctitle{The $p$-adic $L$ function}
The $p$-adic $L$ function $L_p$ is defined on the set of continuous
characters of $\text{Gal}(\Q(\mu_{p^{\infty}})/ \Q)$, as $\int_{\Z_p^*}
\chi^s d \mu$ for a certain $p$-adic distribution $\mu$ on $\Z_p^*$. The
derivative is given by
$$L_p^{(r)}(E, \chi^s) = \int_{\Z_p^*} \log_p^r(a) \chi^s(a) d\mu(a).$$
More precisely:
\item When $E$ has good supersingular reduction, $L_p$ takes its
values in $\Q_p \otimes H^1_{dR}(E/\Q)$ and satisfies
$$(1-p^{-1} F)^{-2} L_p(E, \chi^0)= (L(E,1) / \Omega) \cdot \omega$$
where $F$ is the Frobenius, $L(E,1)$ is the value of the complex $L$
function at $1$, $\omega$ is the N\'eron differential
and $\Omega$ the attached period on $E(\R)$. Here, $\chi^0$ represents
the trivial character.
The function returns the components of $L_p^{(r)}(E,\chi^s)$ in
the basis $(\omega, F(\omega))$.
\item When $E$ has ordinary good reduction, this method only defines
the projection of $L_p(E,\chi^s)$ on the $\alpha$-eigenspace,
where $\alpha$ is the unit eigenvalue for $F$. This is what the function
returns. We have
$$(1- \alpha^{-1})^{-2} L_{p,\alpha}(E,\chi^0)= L(E,1) / \Omega.$$
Two supersingular examples:
\bprog
? cxL(e) = bestappr( ellL1(e) / e.omega[1] );
? e = ellinit("17a1"); p=3; \\ supersingular, a3 = 0
? L = ellpadicL(e,p,4);
? F = [0,-p;1,ellap(e,p)]; \\ Frobenius matrix in the basis (omega,F(omega))
? (1-p^(-1)*F)^-2 * L / cxL(e)
%5 = [1 + O(3^5), O(3^5)]~ \\ [1,0]~
? e = ellinit("116a1"); p=3; \\ supersingular, a3 != 0~
? L = ellpadicL(e,p,4);
? F = [0,-p; 1,ellap(e,p)];
? (1-p^(-1)*F)^-2*L~ / cxL(e)
%9 = [1 + O(3^4), O(3^5)]~
@eprog
Good ordinary reduction:
\bprog
? e = ellinit("17a1"); p=5; ap = ellap(e,p)
%1 = -2 \\ ordinary
? L = ellpadicL(e,p,4)
%2 = 4 + 3*5 + 4*5^2 + 2*5^3 + O(5^4)
? al = padicappr(x^2 - ap*x + p, ap + O(p^7))[1];
? (1-al^(-1))^(-2) * L / cxL(e)
%4 = 1 + O(5^4)
@eprog
Twist and Teichm\"uller:
\bprog
? e = ellinit("17a1"); p=5; \\ ordinary
\\ 2nd derivative at tau^1, twist by -7
? ellpadicL(e, p, 4, [0,1], 2, -7)
%2 = 2*5^2 + 5^3 + O(5^4)
@eprog
This function is a special case of \tet{mspadicL}, and it also appears
as the first term of \tet{mspadicseries}:
\bprog
? e = ellinit("17a1"); p=5;
? L = ellpadicL(e,p,4)
%2 = 4 + 3*5 + 4*5^2 + 2*5^3 + O(5^4)
? [M,phi] = msfromell(e, 1);
? Mp = mspadicinit(M, p, 4);
? mu = mspadicmoments(Mp, phi);
? mspadicL(mu)
%6 = 4 + 3*5 + 4*5^2 + 2*5^3 + 2*5^4 + 5^5 + O(5^6)
? mspadicseries(mu)
%7 = (4 + 3*5 + 4*5^2 + 2*5^3 + 2*5^4 + 5^5 + O(5^6))
+ (3 + 3*5 + 5^2 + 5^3 + O(5^4))*x
+ (2 + 3*5 + 5^2 + O(5^3))*x^2
+ (3 + 4*5 + 4*5^2 + O(5^3))*x^3
+ (3 + 2*5 + O(5^2))*x^4 + O(x^5)
@eprog\noindent These are more cumbersome than \kbd{ellpadicL} but allow to
compute at different characters, or successive derivatives, or to
twist by a quadratic character essentially for the cost of a single call to
\kbd{ellpadicL} due to precomputations.
Function: ellpadicfrobenius
Class: basic
Section: elliptic_curves
C-Name: ellpadicfrobenius
Prototype: GLL
Help: ellpadicfrobenius(E,p,n): matrix of the Frobenius at p>2 in the standard
basis of H^1_dR(E) to absolute p-adic precision p^n.
Doc: If $p>2$ is a prime and $E$ is a elliptic curve on $\Q$ with good
reduction at $p$, return the matrix of the Frobenius endomorphism $\varphi$ on
the crystalline module $D_p(E)= \Q_p \otimes H^1_{dR}(E/\Q)$ with respect to
the basis of the given model $(\omega, \eta=x\*\omega)$, where
$\omega = dx/(2\*y+a_1\*x+a_3)$ is the invariant differential.
The characteristic polynomial of $\varphi$ is $x^2 - a_p\*x + p$.
The matrix is computed to absolute $p$-adic precision $p^n$.
\bprog
? E = ellinit([1,-1,1,0,0]);
? F = ellpadicfrobenius(E,5,3);
? lift(F)
%3 =
[120 29]
[ 55 5]
? charpoly(F)
%4 = x^2 + O(5^3)*x + (5 + O(5^3))
? ellap(E, 5)
%5 = 0
@eprog
Function: ellpadicheight
Class: basic
Section: elliptic_curves
C-Name: ellpadicheight0
Prototype: GGLGDG
Help: ellpadicheight(E, p,n, P,{Q}): E elliptic curve/Q, P in E(Q),
p prime, n an integer; returns the cyclotomic p-adic heights of P.
Resp. the value of the attached bilinear form at (P,Q).
Doc: cyclotomic $p$-adic height of the rational point $P$ on the elliptic curve
$E$ (defined over $\Q$), given to $n$ $p$-adic digits.
If the argument $Q$ is present, computes the value of the bilinear
form $(h(P+Q)-h(P-Q)) / 4$.
Let $D_{dR}(E) := H^1_{dR}(E) \otimes_\Q \Q_p$ be the $\Q_p$ vector space
spanned by $\omega$
(invariant differential $dx/(2y+a_1x+a3)$ related to the given model) and
$\eta = x \omega$. Then the cyclotomic $p$-adic height associates to
$P\in E(\Q)$ an element $f \omega + g\eta$ in $D_{dR}$.
This routine returns the vector $[f, g]$ to $n$ $p$-adic digits.
If $P\in E(\Q)$ is in the kernel of reduction mod $p$ and if its reduction
at all finite places is non singular, then $g = -(\log_E P)^2$, where
$\log_E$ is the logarithm for the formal group of $E$ at $p$.
If furthermore the model is of the form $Y^2 = X^3 + a X + b$ and $P = (x,y)$,
then
$$ f = \log_p(\kbd{denominator}(x)) - 2 \log_p(\sigma(P))$$
where $\sigma(P)$ is given by \kbd{ellsigma}$(E,P)$.
Recall (\emph{Advanced topics in the arithmetic of elliptic
curves}, Theorem~3.2) that the local height function over the complex numbers
is of the form
$$ \lambda(z) = -\log (|\kbd{E.disc}|) / 6 + \Re(z \eta(z)) - 2 \log(
\sigma(z). $$
(N.B. our normalization for local and global heights is twice that of
Silverman's).
\bprog
? E = ellinit([1,-1,1,0,0]); P = [0,0];
? ellpadicheight(E,5,4, P)
%2 = [3*5 + 5^2 + 2*5^3 + O(5^4), 5^2 + 4*5^4 + O(5^6)]
? E = ellinit("11a1"); P = [5,5]; \\ torsion point
? ellpadicheight(E,19,6, P)
%4 = O(19^6)
? E = ellinit([0,0,1,-4,2]); P = [-2,1];
? ellpadicheight(E,3,5, P)
%6 = [2*3^2 + 2*3^3 + 3^4 + O(3^5), 2*3^2 + 3^4 + 2*3^5 + 3^6 + O(3^7)]
? ellpadicheight(E,3,5, P, elladd(E,P,P))
@eprog
One can replace the parameter $p$ prime by a vector $[p,[a,b]]$, in which
case the routine returns the $p$-adic number $af + bg$.
When $E$ has good ordinary reduction at $p$, the ``canonical''
$p$-adic height is given by
\bprog
s2 = ellpadics2(E,p,n);
ellpadicheight(E, [p,[1,-s2]], n, P)
@eprog\noindent Since $s_2$ does not depend on $P$, it is preferable to
compute it only once:
\bprog
? E = ellinit("5077a1"); p = 5; n = 7;
? s2 = ellpadics2(E,p,n);
? M = ellpadicheightmatrix(E,[p,[1,-s2]], n, E.gen);
? matdet(M) \\ p-adic regulator
%4 = 5 + 5^2 + 4*5^3 + 2*5^4 + 2*5^5 + 5^6 + O(5^7)
@eprog
Function: ellpadicheightmatrix
Class: basic
Section: elliptic_curves
C-Name: ellpadicheightmatrix
Prototype: GGLG
Help: ellpadicheightmatrix(E,p,n,v): gives the height-pairing matrix for vector
of points v on elliptic curve E.
Doc: $v$ being a vector of points, this function outputs the Gram matrix of
$v$ with respect to the cyclotomic $p$-adic height, given to $n$ $p$-adic
digits; in other words, the $(i,j)$ component of the matrix is equal to
\kbd{ellpadicheight}$(E,p,n, v[i],v[j]) = [f,g]$.
See \tet{ellpadicheight}; in particular one can replace the parameter $p$
prime by a vector $[p,[a,b]]$, in which case the routine returns the matrix
containing the $p$-adic numbers $af + bg$.
Function: ellpadiclog
Class: basic
Section: elliptic_curves
C-Name: ellpadiclog
Prototype: GGLG
Help: ellpadiclog(E,p,n,P): returns the logarithm of P (in the kernel of
reduction) to absolute p-adic precision p^n.
Doc: Given $E$ defined over $K = \Q$ or $\Q_p$ and $P = [x,y]$ on $E(K)$ in the
kernel of reduction mod $p$, let $t(P) = -x/y$ be the formal group
parameter; this function returns $L(t)$, where $L$ denotes the formal
logarithm (mapping the formal group of $E$ to the additive formal group)
attached to the canonical invariant differential:
$dL = dx/(2y + a_1x + a_3)$.
Function: ellpadics2
Class: basic
Section: elliptic_curves
C-Name: ellpadics2
Prototype: GGL
Help: ellpadics2(E,p,n): returns s2 to absolute p-adic precision p^n.
Doc: If $p>2$ is a prime and $E/\Q$ is a elliptic curve with ordinary good
reduction at $p$, returns the slope of the unit eigenvector
of \kbd{ellpadicfrobenius(E,p,n)}, i.e. the action of Frobenius $\varphi$ on
the crystalline module $D_p(E)= \Q_p \otimes H^1_{dR}(E/\Q)$ in the basis of
the given model $(\omega, \eta=x\*\omega)$, where $\omega$ is the invariant
differential $dx/(2\*y+a_1\*x+a_3)$. In other words, $\eta + s_2\omega$
is an eigenvector for the unit eigenvalue of $\varphi$.
This slope is the unique $c \in 3^{-1}\Z_p$ such that the odd solution
$\sigma(t) = t + O(t^2)$ of
$$ - d(\dfrac{1}{\sigma} \dfrac{d \sigma}{\omega})
= (x(t) + c) \omega$$
is in $t\Z_p[[t]]$.
It is equal to $b_2/12 - E_2/12$ where $E_2$ is the value of the Katz
$p$-adic Eisenstein series of weight 2 on $(E,\omega)$. This is
used to construct a canonical $p$-adic height when $E$ has good ordinary
reduction at $p$ as follows
\bprog
s2 = ellpadics2(E,p,n);
h(E,p,n, P, s2) = ellpadicheight(E, [p,[1,-s2]],n, P);
@eprog\noindent Since $s_2$ does not depend on the point $P$, we compute it
only once.
Function: ellperiods
Class: basic
Section: elliptic_curves
C-Name: ellperiods
Prototype: GD0,L,p
Help: ellperiods(w, {flag = 0}): w describes a complex period lattice ([w1,w2]
or an ellinit structure). Returns normalized periods [W1,W2] generating the
same lattice such that tau := W1/W2 satisfies Im(tau) > 0 and lies in the
standard fundamental domain for SL2. If flag is 1, the return value is
[[W1,W2], [eta1,eta2]], where eta1, eta2 are the quasi-periods attached to
[W1,W2], satisfying eta1 W2 - eta2 W1 = 2 I Pi.
Doc: Let $w$ describe a complex period lattice ($w = [w_1,w_2]$
or an \kbd{ellinit} structure). Returns normalized periods $[W_1,W_2]$ generating
the same lattice such that $\tau := W_1/W_2$ has positive imaginary part
and lies in the standard fundamental domain for $\text{SL}_2(\Z)$.
If $\fl = 1$, the function returns $[[W_1,W_2], [\eta_1,\eta_2]]$, where
$\eta_1$ and $\eta_2$ are the quasi-periods attached to
$[W_1,W_2]$, satisfying $\eta_1 W_2 - \eta_2 W_1 = 2 i \pi$.
The output of this function is meant to be used as the first argument
given to ellwp, ellzeta, ellsigma or elleisnum. Quasi-periods are
needed by ellzeta and ellsigma only.
Function: ellpointtoz
Class: basic
Section: elliptic_curves
C-Name: zell
Prototype: GGp
Help: ellpointtoz(E,P): lattice point z corresponding to the point P on the
elliptic curve E.
Doc:
if $E/\C \simeq \C/\Lambda$ is a complex elliptic curve ($\Lambda =
\kbd{E.omega}$),
computes a complex number $z$, well-defined modulo the lattice $\Lambda$,
corresponding to the point $P$; i.e.~such that
$P = [\wp_\Lambda(z),\wp'_\Lambda(z)]$
satisfies the equation
$$y^2 = 4x^3 - g_2 x - g_3,$$
where $g_2$, $g_3$ are the elliptic invariants.
If $E$ is defined over $\R$ and $P\in E(\R)$, we have more precisely, $0 \leq
\Re(t) < w1$ and $0 \leq \Im(t) < \Im(w2)$, where $(w1,w2)$ are the real and
complex periods of $E$.
\bprog
? E = ellinit([0,1]); P = [2,3];
? z = ellpointtoz(E, P)
%2 = 3.5054552633136356529375476976257353387
? ellwp(E, z)
%3 = 2.0000000000000000000000000000000000000
? ellztopoint(E, z) - P
%4 = [2.548947057811923643 E-57, 7.646841173435770930 E-57]
? ellpointtoz(E, [0]) \\ the point at infinity
%5 = 0
@eprog
If $E/\Q_p$ has multiplicative reduction, then $E/\bar{\Q_p}$ is analytically
isomorphic to $\bar{\Q}_p^*/q^\Z$ (Tate curve) for some $p$-adic integer $q$.
The behaviour is then as follows:
\item If the reduction is split ($E.\kbd{tate[2]}$ is a \typ{PADIC}), we have
an isomorphism $\phi: E(\Q_p) \simeq \Q_p^*/q^\Z$ and the function returns
$\phi(P)\in \Q_p$.
\item If the reduction is \emph{not} split ($E.\kbd{tate[2]}$ is a
\typ{POLMOD}), we only have an isomorphism $\phi: E(K) \simeq K^*/q^\Z$ over
the unramified quadratic extension $K/\Q_p$. In this case, the output
$\phi(P)\in K$ is a \typ{POLMOD}.
\bprog
? E = ellinit([0,-1,1,0,0], O(11^5)); P = [0,0];
? [u2,u,q] = E.tate; type(u) \\ split multiplicative reduction
%2 = "t_PADIC"
? ellmul(E, P, 5) \\ P has order 5
%3 = [0]
? z = ellpointtoz(E, [0,0])
%4 = 3 + 11^2 + 2*11^3 + 3*11^4 + 6*11^5 + 10*11^6 + 8*11^7 + O(11^8)
? z^5
%5 = 1 + O(11^9)
? E = ellinit(ellfromj(1/4), O(2^6)); x=1/2; y=ellordinate(E,x)[1];
? z = ellpointtoz(E,[x,y]); \\ t_POLMOD of t_POL with t_PADIC coeffs
? liftint(z) \\ lift all p-adics
%8 = Mod(8*u + 7, u^2 + 437)
@eprog
Function: ellpow
Class: basic
Section: elliptic_curves
C-Name: ellmul
Prototype: GGG
Help: ellpow(E,z,n): deprecated alias for ellmul.
Doc: deprecated alias for \kbd{ellmul}.
Obsolete: 2012-06-06
Function: ellrootno
Class: basic
Section: elliptic_curves
C-Name: ellrootno
Prototype: lGDG
Help: ellrootno(E,{p}): root number for the L-function of the elliptic
curve E/Q at a prime p (including 0, for the infinite place); global root
number if p is omitted.
Doc: $E$ being an \kbd{ell} structure over $\Q$ as output by \kbd{ellinit},
this function computes the local root number of its $L$-series at the place
$p$ (at the infinite place if $p = 0$). If $p$ is omitted, return the global
root number. Note that the global root number is the sign of the functional
equation and conjecturally is the parity of the rank of the
\idx{Mordell-Weil group}. The equation for $E$ needs not be minimal at $p$,
but if the model is already minimal the function will run faster.
Function: ellsea
Class: basic
Section: elliptic_curves
C-Name: ellsea
Prototype: GD0,U,
Help: ellsea(E,{tors=0}): computes the order of the group E(Fq)
for the elliptic curve E, defined over a finite field,
using SEA algorithm, with early abort for curves with non prime orders.
Doc: Let $E$ be an \var{ell} structure as output by \kbd{ellinit}, defined over
a finite field $\F_q$. This low-level function computes the order of the
group $E(\F_q)$ using the SEA algorithm; compared to the high-level
function \kbd{ellcard}, which includes SEA among its choice of algorithms,
the \kbd{tors} argument allows to speed up a search for curves having almost
prime order.
When \kbd{tors} is set to a non-zero value, the function returns $0$ as soon
as it detects that the order has a small prime factor not dividing \kbd{tors};
SEA considers modular polynomials of increasing prime degree $\ell$ and we
return $0$ as soon as we hit an $\ell$ (coprime to \kbd{tors}) dividing
$\#E(\F_q)$:
\bprog
? ellsea(ellinit([1,1], 2^56+3477), 1)
%1 = 72057594135613381
? forprime(p=2^128,oo, q = ellcard(ellinit([1,1],p)); if(isprime(q),break))
time = 6,571 ms.
? forprime(p=2^128,oo, q = ellsea(ellinit([1,1],p),1);if(isprime(q),break))
time = 522 ms.
@eprog\noindent
In particular, set \kbd{tors} to $1$ if you want a curve with prime order,
to $2$ if you want to allow a cofactor which is a power of two (e.g. for
Edwards's curves), etc. The early exit on bad curves yields a massive
speedup compared to running the cardinal algorithm to completion.
The following function returns a curve of prime order over $\F_p$.
\bprog
cryptocurve(p) =
{
while(1,
my(E, N, j = Mod(random(p), p));
E = ellinit(ellfromj(j));
N = ellsea(E, 1); if(!N, continue);
if (isprime(N), return(E));
\\ try the quadratic twist for free
if (isprime(2*p+2 - N), return(ellinit(elltwist(E))));
);
}
? p = randomprime([2^255, 2^256]);
? E = cryptocurve(p); \\ insist on prime order
%2 = 47,447ms
@eprog\noindent The same example without early abort (using \kbd{ellsea(E,1)}
instead of \kbd{ellsea(E)}) runs for about 5 minutes before finding a
suitable curve.
The availability of the \kbd{seadata} package will speed up the computation,
and is strongly recommended. The generic function \kbd{ellcard} should be
preferred when you only want to compute the cardinal of a given curve without
caring about it having almost prime order:
\item If the characteristic is too small ($p \leq 7$) or the field
cardinality is tiny ($q \leq 523$) the generic algorithm
\kbd{ellcard} is used instead and the \kbd{tors} argument is ignored.
(The reason for this is that SEA is not implemented for $p \leq 7$ and
that if $q \leq 523$ it is likely to run into an infinite loop.)
\item If the field cardinality is smaller than about $2^{50}$, the
generic algorithm will be faster.
\item Contrary to \kbd{ellcard}, \kbd{ellsea} does not store the computed
cardinality in $E$.
Function: ellsearch
Class: basic
Section: elliptic_curves
C-Name: ellsearch
Prototype: G
Help: ellsearch(N): returns all curves in the elldata database matching
constraint N: given name (N = "11a1" or [11,0,1]),
given isogeny class (N = "11a" or [11,0]), or
given conductor (N = 11, "11", or [11]).
Doc: This function finds all curves in the \tet{elldata} database satisfying
the constraint defined by the argument $N$:
\item if $N$ is a character string, it selects a given curve, e.g.
\kbd{"11a1"}, or curves in the given isogeny class, e.g. \kbd{"11a"}, or
curves with given conductor, e.g. \kbd{"11"};
\item if $N$ is a vector of integers, it encodes the same constraints
as the character string above, according to the \tet{ellconvertname}
correspondance, e.g. \kbd{[11,0,1]} for \kbd{"11a1"}, \kbd{[11,0]} for
\kbd{"11a"} and \kbd{[11]} for \kbd{"11"};
\item if $N$ is an integer, curves with conductor $N$ are selected.
If $N$ codes a full curve name, for instance \kbd{"11a1"} or \kbd{[11,0,1]},
the output format is $[N, [a_1,a_2,a_3,a_4,a_6], G]$ where
$[a_1,a_2,a_3,a_4,a_6]$ are the coefficients of the Weierstrass equation of
the curve and $G$ is a $\Z$-basis of the free part of the
\idx{Mordell-Weil group} attached to the curve.
\bprog
? ellsearch("11a3")
%1 = ["11a3", [0, -1, 1, 0, 0], []]
? ellsearch([11,0,3])
%2 = ["11a3", [0, -1, 1, 0, 0], []]
@eprog\noindent
If $N$ is not a full curve name, then the output is a vector of all matching
curves in the above format:
\bprog
? ellsearch("11a")
%1 = [["11a1", [0, -1, 1, -10, -20], []],
["11a2", [0, -1, 1, -7820, -263580], []],
["11a3", [0, -1, 1, 0, 0], []]]
? ellsearch("11b")
%2 = []
@eprog
Variant: Also available is \fun{GEN}{ellsearchcurve}{GEN N} that only
accepts complete curve names (as \typ{STR}).
Function: ellsigma
Class: basic
Section: elliptic_curves
C-Name: ellsigma
Prototype: GDGD0,L,p
Help: ellsigma(L,{z='x},{flag=0}): computes the value at z of the Weierstrass
sigma function attached to the lattice w, as given by ellperiods(,1).
If flag = 1, returns an arbitrary determination of the logarithm of sigma.
Doc: Computes the value at $z$ of the Weierstrass $\sigma$ function attached to
the lattice $L$ as given by \tet{ellperiods}$(,1)$: including quasi-periods
is useful, otherwise there are recomputed from scratch for each new $z$.
$$ \sigma(z, L) = z \prod_{\omega\in L^*} \left(1 -
\dfrac{z}{\omega}\right)e^{\dfrac{z}{\omega} + \dfrac{z^2}{2\omega^2}}.$$
It is also possible to directly input $L = [\omega_1,\omega_2]$,
or an elliptic curve $E$ as given by \kbd{ellinit} ($L = \kbd{E.omega}$).
\bprog
? w = ellperiods([1,I], 1);
? ellsigma(w, 1/2)
%2 = 0.47494937998792065033250463632798296855
? E = ellinit([1,0]);
? ellsigma(E) \\ at 'x, implicitly at default seriesprecision
%4 = x + 1/60*x^5 - 1/10080*x^9 - 23/259459200*x^13 + O(x^17)
@eprog
If $\fl=1$, computes an arbitrary determination of $\log(\sigma(z))$.
Function: ellsub
Class: basic
Section: elliptic_curves
C-Name: ellsub
Prototype: GGG
Help: ellsub(E,z1,z2): difference of the points z1 and z2 on elliptic curve E.
Doc:
difference of the points $z1$ and $z2$ on the
elliptic curve corresponding to $E$.
Function: elltaniyama
Class: basic
Section: elliptic_curves
C-Name: elltaniyama
Prototype: GDP
Help: elltaniyama(E, {d = seriesprecision}): modular parametrization of
elliptic curve E/Q.
Doc:
computes the modular parametrization of the elliptic curve $E/\Q$,
where $E$ is an \kbd{ell} structure as output by \kbd{ellinit}. This returns
a two-component vector $[u,v]$ of power series, given to $d$ significant
terms (\tet{seriesprecision} by default), characterized by the following two
properties. First the point $(u,v)$ satisfies the equation of the elliptic
curve. Second, let $N$ be the conductor of $E$ and $\Phi: X_0(N)\to E$
be a modular parametrization; the pullback by $\Phi$ of the
N\'eron differential $du/(2v+a_1u+a_3)$ is equal to $2i\pi
f(z)dz$, a holomorphic differential form. The variable used in the power
series for $u$ and $v$ is $x$, which is implicitly understood to be equal to
$\exp(2i\pi z)$.
The algorithm assumes that $E$ is a \emph{strong} \idx{Weil curve}
and that the Manin constant is equal to 1: in fact, $f(x) = \sum_{n > 0}
\kbd{ellan}(E, n) x^n$.
Function: elltatepairing
Class: basic
Section: elliptic_curves
C-Name: elltatepairing
Prototype: GGGG
Help: elltatepairing(E, P, Q, m): computes the Tate pairing of the two points
P and Q on the elliptic curve E. The point P must be of m-torsion.
Doc: Computes the Tate pairing of the two points $P$ and $Q$ on the elliptic
curve $E$. The point $P$ must be of $m$-torsion.
Function: elltors
Class: basic
Section: elliptic_curves
C-Name: elltors
Prototype: G
Help: elltors(E): torsion subgroup of elliptic curve E: order, structure,
generators.
Doc:
if $E$ is an elliptic curve defined over a number field or a finite field,
outputs the torsion subgroup of $E$ as a 3-component vector \kbd{[t,v1,v2]},
where \kbd{t} is the order of the torsion group, \kbd{v1} gives the structure
of the torsion group as a product of cyclic groups (sorted by decreasing
order), and \kbd{v2} gives generators for these cyclic groups. $E$ must be an
\kbd{ell} structure as output by \kbd{ellinit}.
\bprog
? E = ellinit([-1,0]);
? elltors(E)
%1 = [4, [2, 2], [[0, 0], [1, 0]]]
@eprog\noindent
Here, the torsion subgroup is isomorphic to $\Z/2\Z \times \Z/2\Z$, with
generators $[0,0]$ and $[1,0]$.
Function: elltwist
Class: basic
Section: elliptic_curves
C-Name: elltwist
Prototype: GDG
Help: elltwist(E,{P}): returns the coefficients [a1,a2,a3,a4,a6] of
the twist of the elliptic curve E by the quadratic extension defined by
P (when P is a polynomial of degree 2) or quadpoly(P) (when P is an integer).
If E is defined over a finite field, then P can be omitted.
Doc: returns the coefficients $[a_1,a_2,a_3,a_4,a_6]$ of the twist of the
elliptic curve $E$ by the quadratic extension of the coefficient ring
defined by $P$ (when $P$ is a polynomial) or \kbd{quadpoly(P)} when $P$ is an
integer. If $E$ is defined over a finite field, then $P$ can be omitted,
in which case a random model of the unique non-trivial twist is returned.
If $E$ is defined over a number field, the model should be replaced by a
minimal model (if one exists).
Example: Twist by discriminant $-3$:
\bprog
? elltwist(ellinit([0,a2,0,a4,a6]),-3)
%1 = [0,-3*a2,0,9*a4,-27*a6]
@eprog
Twist by the Artin-Shreier extension given by $x^2+x+T$ in
characteristic $2$:
\bprog
? lift(elltwist(ellinit([a1,a2,a3,a4,a6]*Mod(1,2)),x^2+x+T))
%1 = [a1,a2+a1^2*T,a3,a4,a6+a3^2*T]
@eprog
Twist of an elliptic curve defined over a finite field:
\bprog
? E=ellinit([1,7]*Mod(1,19));lift(elltwist(E))
%1 = [0,0,0,11,12]
@eprog
Function: ellweilpairing
Class: basic
Section: elliptic_curves
C-Name: ellweilpairing
Prototype: GGGG
Help: ellweilpairing(E, P, Q, m): computes the Weil pairing of the two points
of m-torsion P and Q on the elliptic curve E.
Doc: Computes the Weil pairing of the two points of $m$-torsion $P$ and $Q$
on the elliptic curve $E$.
Function: ellwp
Class: basic
Section: elliptic_curves
C-Name: ellwp0
Prototype: GDGD0,L,p
Help: ellwp(w,{z='x},{flag=0}): computes the value at z of the Weierstrass P
function attached to the lattice w, as given by ellperiods. Optional flag
means 0 (default), compute only P(z), 1 compute [P(z),P'(z)].
Doc: Computes the value at $z$ of the Weierstrass $\wp$ function attached to
the lattice $w$ as given by \tet{ellperiods}. It is also possible to
directly input $w = [\omega_1,\omega_2]$, or an elliptic curve $E$ as given
by \kbd{ellinit} ($w = \kbd{E.omega}$).
\bprog
? w = ellperiods([1,I]);
? ellwp(w, 1/2)
%2 = 6.8751858180203728274900957798105571978
? E = ellinit([1,1]);
? ellwp(E, 1/2)
%4 = 3.9413112427016474646048282462709151389
@eprog\noindent One can also compute the series expansion around $z = 0$:
\bprog
? E = ellinit([1,0]);
? ellwp(E) \\ 'x implicitly at default seriesprecision
%5 = x^-2 - 1/5*x^2 + 1/75*x^6 - 2/4875*x^10 + O(x^14)
? ellwp(E, x + O(x^12)) \\ explicit precision
%6 = x^-2 - 1/5*x^2 + 1/75*x^6 + O(x^9)
@eprog
Optional \fl\ means 0 (default): compute only $\wp(z)$, 1: compute
$[\wp(z),\wp'(z)]$.
Variant: For $\fl = 0$, we also have
\fun{GEN}{ellwp}{GEN w, GEN z, long prec}, and
\fun{GEN}{ellwpseries}{GEN E, long v, long precdl} for the power series in
variable $v$.
Function: ellxn
Class: basic
Section: elliptic_curves
C-Name: ellxn
Prototype: GLDn
Help: ellxn(E,n,{v='x}): polynomials [phi_n, (psi_n)^2] in variable v,
where x([n]P) = phi_n/(psi_n)^2.
Doc: In standard notation, for any affine point $P = (v,w)$ on the
curve $E$, we have
$$[n]P = (\phi_n(P)\psi_n(P) : \omega_n(P) : \psi_n(P)^3)$$
for some polynomials $\phi_n,\omega_n,\psi_n$ in
$\Z[a_1,a_2,a_3,a_4,a_6][v,w]$. This function returns
$[\phi_n(P),\psi_n(P)^2]$, which give the numerator and denominator of
the abcissa of $[n]P$ and depend only on $v$.
Function: ellzeta
Class: basic
Section: elliptic_curves
C-Name: ellzeta
Prototype: GDGp
Help: ellzeta(w,{z='x}): computes the value at z of the Weierstrass Zeta
function attached to the lattice w, as given by ellperiods(,1).
Doc: Computes the value at $z$ of the Weierstrass $\zeta$ function attached to
the lattice $w$ as given by \tet{ellperiods}$(,1)$: including quasi-periods
is useful, otherwise there are recomputed from scratch for each new $z$.
$$ \zeta(z, L) = \dfrac{1}{z} + z^2\sum_{\omega\in L^*}
\dfrac{1}{\omega^2(z-\omega)}.$$
It is also possible to directly input $w = [\omega_1,\omega_2]$,
or an elliptic curve $E$ as given by \kbd{ellinit} ($w = \kbd{E.omega}$).
The quasi-periods of $\zeta$, such that
$$\zeta(z + a\omega_1 + b\omega_2) = \zeta(z) + a\eta_1 + b\eta_2 $$
for integers $a$ and $b$ are obtained as $\eta_i = 2\zeta(\omega_i/2)$.
Or using directly \tet{elleta}.
\bprog
? w = ellperiods([1,I],1);
? ellzeta(w, 1/2)
%2 = 1.5707963267948966192313216916397514421
? E = ellinit([1,0]);
? ellzeta(E, E.omega[1]/2)
%4 = 0.84721308479397908660649912348219163647
@eprog\noindent One can also compute the series expansion around $z = 0$
(the quasi-periods are useless in this case):
\bprog
? E = ellinit([0,1]);
? ellzeta(E) \\ at 'x, implicitly at default seriesprecision
%4 = x^-1 + 1/35*x^5 - 1/7007*x^11 + O(x^15)
? ellzeta(E, x + O(x^20)) \\ explicit precision
%5 = x^-1 + 1/35*x^5 - 1/7007*x^11 + 1/1440257*x^17 + O(x^18)
@eprog\noindent
Function: ellztopoint
Class: basic
Section: elliptic_curves
C-Name: pointell
Prototype: GGp
Help: ellztopoint(E,z): inverse of ellpointtoz. Returns the coordinates of
point P on the curve E corresponding to a complex or p-adic z.
Doc:
$E$ being an \var{ell} as output by
\kbd{ellinit}, computes the coordinates $[x,y]$ on the curve $E$
corresponding to the complex or $p$-adic parameter $z$. Hence this is the
inverse function of \kbd{ellpointtoz}.
\item If $E$ is defined over a $p$-adic field and has multiplicative
reduction, then $z$ is understood as an element on the
Tate curve $\bar{Q}_p^* / q^\Z$.
\bprog
? E = ellinit([0,-1,1,0,0], O(11^5));
? [u2,u,q] = E.tate; type(u)
%2 = "t_PADIC" \\ split multiplicative reduction
? z = ellpointtoz(E, [0,0])
%3 = 3 + 11^2 + 2*11^3 + 3*11^4 + 6*11^5 + 10*11^6 + 8*11^7 + O(11^8)
? ellztopoint(E,z)
%4 = [O(11^9), O(11^9)]
? E = ellinit(ellfromj(1/4), O(2^6)); x=1/2; y=ellordinate(E,x)[1];
? z = ellpointtoz(E,[x,y]); \\ non-split: t_POLMOD with t_PADIC coefficients
? P = ellztopoint(E, z);
? P[1] \\ y coordinate is analogous, more complicated
%8 = Mod(O(2^4)*x + (2^-1 + O(2^5)), x^2 + (1 + 2^2 + 2^4 + 2^5 + O(2^7)))
@eprog
\item If $E$ is defined over the complex numbers (for instance over $\Q$),
$z$ is understood as a complex number in $\C/\Lambda_E$. If the
short Weierstrass equation is $y^2 = 4x^3 - g_2x - g_3$, then $[x,y]$
represents the Weierstrass $\wp$-function\sidx{Weierstrass $\wp$-function}
and its derivative. For a general Weierstrass equation we have
$$x = \wp(z) - b_2/12,\quad y = \wp'(z) - (a_1 x + a_3)/2.$$
If $z$ is in the lattice defining $E$ over $\C$, the result is the point at
infinity $[0]$.
\bprog
? E = ellinit([0,1]); P = [2,3];
? z = ellpointtoz(E, P)
%2 = 3.5054552633136356529375476976257353387
? ellwp(E, z)
%3 = 2.0000000000000000000000000000000000000
? ellztopoint(E, z) - P
%4 = [2.548947057811923643 E-57, 7.646841173435770930 E-57]
? ellztopoint(E, 0)
%5 = [0] \\ point at infinity
@eprog
Function: erfc
Class: basic
Section: transcendental
C-Name: gerfc
Prototype: Gp
Help: erfc(x): complementary error function.
Doc: complementary error function, analytic continuation of
$(2/\sqrt\pi)\int_x^\infty e^{-t^2}\,dt = \kbd{incgam}(1/2,x^2)/\sqrt\pi$,
where the latter expression extends the function definition from real $x$ to
all complex $x \neq 0$.
Function: errname
Class: basic
Section: programming/specific
C-Name: errname
Prototype: G
Help: errname(E): returns the type of the error message E.
Description:
(gen):errtyp err_get_num($1)
Doc: returns the type of the error message \kbd{E} as a string.
Function: error
Class: basic
Section: programming/specific
C-Name: error0
Prototype: vs*
Help: error({str}*): abort script with error message str.
Description:
(error):void pari_err(0, $1)
(?gen,...):void pari_err(e_MISC, "${2 format_string}"${2 format_args})
Doc: outputs its argument list (each of
them interpreted as a string), then interrupts the running \kbd{gp} program,
returning to the input prompt. For instance
\bprog
error("n = ", n, " is not squarefree!")
@eprog\noindent
% \syn{NO}
Function: eta
Class: basic
Section: transcendental
C-Name: eta0
Prototype: GD0,L,p
Help: eta(z,{flag=0}): if flag=0, returns prod(n=1,oo, 1-q^n), where
q = exp(2 i Pi z) if z is a complex scalar (belonging to the upper half plane);
q = z if z is a p-adic number or can be converted to a power series.
If flag is non-zero, the function only applies to complex scalars and returns
the true eta function, with the factor q^(1/24) included.
Doc: Variants of \idx{Dedekind}'s $\eta$ function.
If $\fl = 0$, return $\prod_{n=1}^\infty(1-q^n)$, where $q$ depends on $x$
in the following way:
\item $q = e^{2i\pi x}$ if $x$ is a \emph{complex number} (which must then
have positive imaginary part); notice that the factor $q^{1/24}$ is
missing!
\item $q = x$ if $x$ is a \typ{PADIC}, or can be converted to a
\emph{power series} (which must then have positive valuation).
If $\fl$ is non-zero, $x$ is converted to a complex number and we return the
true $\eta$ function, $q^{1/24}\prod_{n=1}^\infty(1-q^n)$,
where $q = e^{2i\pi x}$.
Variant:
Also available is \fun{GEN}{trueeta}{GEN x, long prec} ($\fl=1$).
Function: eulerphi
Class: basic
Section: number_theoretical
C-Name: eulerphi
Prototype: G
Help: eulerphi(x): Euler's totient function of x.
Description:
(gen):int eulerphi($1)
Doc: Euler's $\phi$ (totient)\sidx{Euler totient function} function of the
integer $|x|$, in other words $|(\Z/x\Z)^*|$.
\bprog
? eulerphi(40)
%1 = 16
@eprog\noindent
According to this definition we let $\phi(0) := 2$, since $\Z^* = \{-1,1\}$;
this is consistent with \kbd{znstar(0)}: we have
\kbd{znstar$(n)$.no = eulerphi(n)} for all $n\in\Z$.
Function: eval
Class: basic
Section: polynomials
C-Name: geval_gp
Prototype: GC
Help: eval(x): evaluation of x, replacing variables by their value.
Description:
(gen):gen geval($1)
Doc: replaces in $x$ the formal variables by the values that
have been assigned to them after the creation of $x$. This is mainly useful
in GP, and not in library mode. Do not confuse this with substitution (see
\kbd{subst}).
If $x$ is a character string, \kbd{eval($x$)} executes $x$ as a GP
command, as if directly input from the keyboard, and returns its
output.
\bprog
? x1 = "one"; x2 = "two";
? n = 1; eval(Str("x", n))
%2 = "one"
? f = "exp"; v = 1;
? eval(Str(f, "(", v, ")"))
%4 = 2.7182818284590452353602874713526624978
@eprog\noindent Note that the first construct could be implemented in a
simpler way by using a vector \kbd{x = ["one","two"]; x[n]}, and the second
by using a closure \kbd{f = exp; f(v)}. The final example is more interesting:
\bprog
? genmat(u,v) = matrix(u,v,i,j, eval( Str("x",i,j) ));
? genmat(2,3) \\ generic 2 x 3 matrix
%2 =
[x11 x12 x13]
[x21 x22 x23]
@eprog
A syntax error in the evaluation expression raises an \kbd{e\_SYNTAX}
exception, which can be trapped as usual:
\bprog
? 1a
*** syntax error, unexpected variable name, expecting $end or ';': 1a
*** ^-
? E(expr) =
{
iferr(eval(expr),
e, print("syntax error"),
errname(e) == "e_SYNTAX");
}
? E("1+1")
%1 = 2
? E("1a")
syntax error
@eprog
\synt{geval}{GEN x}.
Function: exp
Class: basic
Section: transcendental
C-Name: gexp
Prototype: Gp
Help: exp(x): exponential of x.
Description:
(real):real mpexp($1)
(mp):mp:prec gexp($1, $prec)
(gen):gen:prec gexp($1, $prec)
Doc: exponential of $x$.
$p$-adic arguments with positive valuation are accepted.
Variant: For a \typ{PADIC} $x$, the function
\fun{GEN}{Qp_exp}{GEN x} is also available.
Function: expm1
Class: basic
Section: transcendental
C-Name: gexpm1
Prototype: Gp
Help: expm1(x): exp(x)-1.
Description:
(real):real mpexpm1($1)
Doc: return $\exp(x)-1$, computed in a way that is also accurate
when the real part of $x$ is near $0$.
A naive direct computation would suffer from catastrophic cancellation;
PARI's direct computation of $\exp(x)$ alleviates this well known problem at
the expense of computing $\exp(x)$ to a higher accuracy when $x$ is small.
Using \kbd{expm1} is recommended instead:
\bprog
? default(realprecision, 10000); x = 1e-100;
? a = expm1(x);
time = 4 ms.
? b = exp(x)-1;
time = 28 ms.
? default(realprecision, 10040); x = 1e-100;
? c = expm1(x); \\ reference point
? abs(a-c)/c \\ relative error in expm1(x)
%7 = 0.E-10017
? abs(b-c)/c \\ relative error in exp(x)-1
%8 = 1.7907031188259675794 E-9919
@eprog\noindent As the example above shows, when $x$ is near $0$,
\kbd{expm1} is both faster and more accurate than \kbd{exp(x)-1}.
Function: extern
Class: basic
Section: programming/specific
C-Name: gpextern
Prototype: s
Help: extern(str): execute shell command str, and feeds the result to GP (as
if loading from file).
Doc: the string \var{str} is the name of an external command (i.e.~one you
would type from your UNIX shell prompt). This command is immediately run and
its output fed into \kbd{gp}, just as if read from a file.
Function: externstr
Class: basic
Section: programming/specific
C-Name: externstr
Prototype: s
Help: externstr(str): execute shell command str, and returns the result as a
vector of GP strings, one component per output line.
Doc: the string \var{str} is the name of an external command (i.e.~one you
would type from your UNIX shell prompt). This command is immediately run and
its output is returned as a vector of GP strings, one component per output
line.
Function: factor
Class: basic
Section: number_theoretical
C-Name: gp_factor0
Prototype: GDG
Help: factor(x,{lim}): factorization of x. lim is optional and can be set
whenever x is of (possibly recursive) rational type. If lim is set return
partial factorization, using primes < lim.
Description:
(int, ?-1):vec Z_factor($1)
(gen, ?-1):vec factor($1)
(gen, small):vec factor0($1, $2)
Doc: general factorization function, where $x$ is a
rational (including integers), a complex number with rational
real and imaginary parts, or a rational function (including polynomials).
The result is a two-column matrix: the first contains the irreducibles
dividing $x$ (rational or Gaussian primes, irreducible polynomials),
and the second the exponents. By convention, $0$ is factored as $0^1$.
\misctitle{$\Q$ and $\Q(i)$}
See \tet{factorint} for more information about the algorithms used.
The rational or Gaussian primes are in fact \var{pseudoprimes}
(see \kbd{ispseudoprime}), a priori not rigorously proven primes. In fact,
any factor which is $\leq 2^{64}$ (whose norm is $\leq 2^{64}$ for an
irrational Gaussian prime) is a genuine prime. Use \kbd{isprime} to prove
primality of other factors, as in
\bprog
? fa = factor(2^2^7 + 1)
%1 =
[59649589127497217 1]
[5704689200685129054721 1]
? isprime( fa[,1] )
%2 = [1, 1]~ \\ both entries are proven primes
@eprog\noindent
Another possibility is to set the global default \tet{factor_proven}, which
will perform a rigorous primality proof for each pseudoprime factor.
A \typ{INT} argument \var{lim} can be added, meaning that we look only for
prime factors $p < \var{lim}$. The limit \var{lim} must be non-negative.
In this case, all but the last factor are proven primes, but the remaining
factor may actually be a proven composite! If the remaining factor is less
than $\var{lim}^2$, then it is prime.
\bprog
? factor(2^2^7 +1, 10^5)
%3 =
[340282366920938463463374607431768211457 1]
@eprog\noindent
\misctitle{Deprecated feature} Setting $\var{lim}=0$ is the same
as setting it to $\kbd{primelimit} + 1$. Don't use this: it is unwise to
rely on global variables when you can specify an explicit argument.
\smallskip
This routine uses trial division and perfect power tests, and should not be
used for huge values of \var{lim} (at most $10^9$, say):
\kbd{factorint(, 1 + 8)} will in general be faster. The latter does not
guarantee that all small
prime factors are found, but it also finds larger factors, and in a much more
efficient way.
\bprog
? F = (2^2^7 + 1) * 1009 * 100003; factor(F, 10^5) \\ fast, incomplete
time = 0 ms.
%4 =
[1009 1]
[34029257539194609161727850866999116450334371 1]
? factor(F, 10^9) \\ very slow
time = 6,892 ms.
%6 =
[1009 1]
[100003 1]
[340282366920938463463374607431768211457 1]
? factorint(F, 1+8) \\ much faster, all small primes were found
time = 12 ms.
%7 =
[1009 1]
[100003 1]
[340282366920938463463374607431768211457 1]
? factor(F) \\ complete factorisation
time = 112 ms.
%8 =
[1009 1]
[100003 1]
[59649589127497217 1]
[5704689200685129054721 1]
@eprog\noindent Over $\Q$, the prime factors are sorted in increasing order.
\misctitle{Rational functions}
The polynomials or rational functions to be factored must have scalar
coefficients. In particular PARI does not know how to factor
\emph{multivariate} polynomials. The following domains are currently
supported: $\Q$, $\R$, $\C$, $\Q_p$, finite fields and number fields. See
\tet{factormod} and \tet{factorff} for the algorithms used over finite
fields, \tet{nffactor} for the algorithms over number fields. The irreducible
factors are sorted by increasing degree.
The routine guesses a sensible ring over which to factor: the
smallest ring containing all coefficients, taking into account quotient
structures induced by \typ{INTMOD}s and \typ{POLMOD}s (e.g.~if a coefficient
in $\Z/n\Z$ is known, all rational numbers encountered are first mapped to
$\Z/n\Z$; different moduli will produce an error). Factoring modulo a
non-prime number is not supported; to factor in $\Q_p$, use \typ{PADIC}
coefficients not \typ{INTMOD} modulo $p^n$.
\bprog
? T = x^2+1;
? factor(T); \\ over Q
? factor(T*Mod(1,3)) \\ over F_3
? factor(T*ffgen(ffinit(3,2,'t))^0) \\ over F_{3^2}
? factor(T*Mod(Mod(1,3), t^2+t+2)) \\ over F_{3^2}, again
? factor(T*(1 + O(3^6)) \\ over Q_3, precision 6
? factor(T*1.) \\ over R, current precision
? factor(T*(1.+0.*I)) \\ over C
? factor(T*Mod(1, y^3-2)) \\ over Q(2^{1/3})
@eprog\noindent In most cases, it is clearer and simpler to call an
explicit variant than to rely on the generic \kbd{factor} function and
the above detection mechanism:
\bprog
? factormod(T, 3) \\ over F_3
? factorff(T, 3, t^2+t+2)) \\ over F_{3^2}
? factorpadic(T, 3,6) \\ over Q_3, precision 6
? nffactor(y^3-2, T) \\ over Q(2^{1/3})
? polroots(T) \\ over C
? polrootsreal(T) \\ over R (real polynomial)
@eprog
\misctitle{Note about inseparable polynomials} Polynomials with inexact
coefficients (e.g. floating point or $p$-adic numbers) are assumed to be
squarefree: in fact, there exist a squarefree polynomial arbitrarily close
to the input, and they cannot be distinguished at the input accuracy. This
means that irreducible factors are repeated according to their apparent
multiplicity. On the contrary, using a specialized function such as
\kbd{factorpadic} with an \emph{exact} rational input yields the correct
multiplicity when the (now exact) input is not separable. Compare:
\bprog
? factor(z^2 * (1 + O(5^2)))
%1 =
[(1 + O(5^2))*z + O(5^2) 1]
[(1 + O(5^2))*z + O(5^2) 1]
? factorpadic(z^2, 5, 2)
%2 =
[1 + O(5^2))*z + O(5^2) 2]
@eprog
\misctitle{Note about contents}
Factorization of polynomials is done up to
multiplication by a constant. In particular, the factors of rational
polynomials will have integer coefficients, and the content of a polynomial
or rational function is discarded and not included in the factorization. If
needed, you can always ask for the content explicitly:
\bprog
? factor(t^2 + 5/2*t + 1)
%1 =
[2*t + 1 1]
[t + 2 1]
? content(t^2 + 5/2*t + 1)
%2 = 1/2
@eprog
Variant: This function should only be used by the \kbd{gp} interface. Use
directly \fun{GEN}{factor}{GEN x} or \fun{GEN}{boundfact}{GEN x, ulong lim}.
The obsolete function \fun{GEN}{factor0}{GEN x, long lim} is kept for
backward compatibility.
Function: factorback
Class: basic
Section: number_theoretical
C-Name: factorback2
Prototype: GDG
Help: factorback(f,{e}): given a factorisation f, gives the factored
object back. If this is a prime ideal factorisation you must supply the
corresponding number field as last argument. If e is present, f has to be a
vector of the same length, and we return the product of the f[i]^e[i].
Description:
(gen):gen factorback($1)
(gen,):gen factorback($1)
(gen,gen):gen factorback2($1, $2)
Doc: gives back the factored object
corresponding to a factorization. The integer $1$ corresponds to the empty
factorization.
If $e$ is present, $e$ and $f$ must be vectors of the same length ($e$ being
integral), and the corresponding factorization is the product of the
$f[i]^{e[i]}$.
If not, and $f$ is vector, it is understood as in the preceding case with $e$
a vector of 1s: we return the product of the $f[i]$. Finally, $f$ can be a
regular factorization, as produced with any \kbd{factor} command. A few
examples:
\bprog
? factor(12)
%1 =
[2 2]
[3 1]
? factorback(%)
%2 = 12
? factorback([2,3], [2,1]) \\ 2^3 * 3^1
%3 = 12
? factorback([5,2,3])
%4 = 30
@eprog
Variant: Also available is \fun{GEN}{factorback}{GEN f} (case $e = \kbd{NULL}$).
Function: factorcantor
Class: basic
Section: number_theoretical
C-Name: factcantor
Prototype: GG
Help: factorcantor(x,p): factorization mod p of the polynomial x using
Cantor-Zassenhaus.
Doc: factors the polynomial $x$ modulo the
prime $p$, using distinct degree plus
\idx{Cantor-Zassenhaus}\sidx{Zassenhaus}. The coefficients of $x$ must be
operation-compatible with $\Z/p\Z$. The result is a two-column matrix, the
first column being the irreducible polynomials dividing $x$, and the second
the exponents. If you want only the \emph{degrees} of the irreducible
polynomials (for example for computing an $L$-function), use
$\kbd{factormod}(x,p,1)$. Note that the \kbd{factormod} algorithm is
usually faster than \kbd{factorcantor}.
Function: factorff
Class: basic
Section: number_theoretical
C-Name: factorff
Prototype: GDGDG
Help: factorff(x,{p},{a}): factorization of the polynomial x in the finite field
F_p[X]/a(X)F_p[X].
Doc: factors the polynomial $x$ in the field
$\F_q$ defined by the irreducible polynomial $a$ over $\F_p$. The
coefficients of $x$ must be operation-compatible with $\Z/p\Z$. The result
is a two-column matrix: the first column contains the irreducible factors of
$x$, and the second their exponents. If all the coefficients of $x$ are in
$\F_p$, a much faster algorithm is applied, using the computation of
isomorphisms between finite fields.
Either $a$ or $p$ can omitted (in which case both are ignored) if x has
\typ{FFELT} coefficients; the function then becomes identical to \kbd{factor}:
\bprog
? factorff(x^2 + 1, 5, y^2+3) \\ over F_5[y]/(y^2+3) ~ F_25
%1 =
[Mod(Mod(1, 5), Mod(1, 5)*y^2 + Mod(3, 5))*x
+ Mod(Mod(2, 5), Mod(1, 5)*y^2 + Mod(3, 5)) 1]
[Mod(Mod(1, 5), Mod(1, 5)*y^2 + Mod(3, 5))*x
+ Mod(Mod(3, 5), Mod(1, 5)*y^2 + Mod(3, 5)) 1]
? t = ffgen(y^2 + Mod(3,5), 't); \\ a generator for F_25 as a t_FFELT
? factorff(x^2 + 1) \\ not enough information to determine the base field
*** at top-level: factorff(x^2+1)
*** ^---------------
*** factorff: incorrect type in factorff.
? factorff(x^2 + t^0) \\ make sure a coeff. is a t_FFELT
%3 =
[x + 2 1]
[x + 3 1]
? factorff(x^2 + t + 1)
%11 =
[x + (2*t + 1) 1]
[x + (3*t + 4) 1]
@eprog\noindent
Notice that the second syntax is easier to use and much more readable.
Function: factorial
Class: basic
Section: number_theoretical
C-Name: mpfactr
Prototype: Lp
Help: factorial(x): factorial of x, the result being given as a real number.
Doc: factorial of $x$. The expression $x!$ gives a result which is an integer,
while $\kbd{factorial}(x)$ gives a real number.
Variant: \fun{GEN}{mpfact}{long x} returns $x!$ as a \typ{INT}.
Function: factorint
Class: basic
Section: number_theoretical
C-Name: factorint
Prototype: GD0,L,
Help: factorint(x,{flag=0}): factor the integer x. flag is optional, whose
binary digits mean 1: avoid MPQS, 2: avoid first-stage ECM (may fall back on
it later), 4: avoid Pollard-Brent Rho and Shanks SQUFOF, 8: skip final ECM
(huge composites will be declared prime).
Doc: factors the integer $n$ into a product of
pseudoprimes (see \kbd{ispseudoprime}), using a combination of the
\idx{Shanks SQUFOF} and \idx{Pollard Rho} method (with modifications due to
Brent), \idx{Lenstra}'s \idx{ECM} (with modifications by Montgomery), and
\idx{MPQS} (the latter adapted from the \idx{LiDIA} code with the kind
permission of the LiDIA maintainers), as well as a search for pure powers.
The output is a two-column matrix as for \kbd{factor}: the first column
contains the ``prime'' divisors of $n$, the second one contains the
(positive) exponents.
By convention $0$ is factored as $0^1$, and $1$ as the empty factorization;
also the divisors are by default not proven primes is they are larger than
$2^{64}$, they only failed the BPSW compositeness test (see
\tet{ispseudoprime}). Use \kbd{isprime} on the result if you want to
guarantee primality or set the \tet{factor_proven} default to $1$.
Entries of the private prime tables (see \tet{addprimes}) are also included
as is.
This gives direct access to the integer factoring engine called by most
arithmetical functions. \fl\ is optional; its binary digits mean 1: avoid
MPQS, 2: skip first stage ECM (we may still fall back to it later), 4: avoid
Rho and SQUFOF, 8: don't run final ECM (as a result, a huge composite may be
declared to be prime). Note that a (strong) probabilistic primality test is
used; thus composites might not be detected, although no example is known.
You are invited to play with the flag settings and watch the internals at
work by using \kbd{gp}'s \tet{debug} default parameter (level 3 shows
just the outline, 4 turns on time keeping, 5 and above show an increasing
amount of internal details).
Function: factormod
Class: basic
Section: number_theoretical
C-Name: factormod0
Prototype: GGD0,L,
Help: factormod(x,p,{flag=0}): factors the polynomial x modulo the prime p, using Berlekamp. flag is optional, and can be 0: default or 1:
only the degrees of the irreducible factors are given.
Doc: factors the polynomial $x$ modulo the prime integer $p$, using
\idx{Berlekamp}. The coefficients of $x$ must be operation-compatible with
$\Z/p\Z$. The result is a two-column matrix, the first column being the
irreducible polynomials dividing $x$, and the second the exponents. If $\fl$
is non-zero, outputs only the \emph{degrees} of the irreducible polynomials
(for example, for computing an $L$-function). A different algorithm for
computing the mod $p$ factorization is \kbd{factorcantor} which is sometimes
faster.
Function: factornf
Class: basic
Section: number_fields
C-Name: polfnf
Prototype: GG
Help: factornf(x,t): this function is obsolete, use nffactor.
Doc: This function is obsolete, use \kbd{nffactor}.
factorization of the univariate polynomial $x$
over the number field defined by the (univariate) polynomial $t$. $x$ may
have coefficients in $\Q$ or in the number field. The algorithm reduces to
factorization over $\Q$ (\idx{Trager}'s trick). The direct approach of
\tet{nffactor}, which uses \idx{van Hoeij}'s method in a relative setting, is
in general faster.
The main variable of $t$ must be of \emph{lower} priority than that of $x$
(see \secref{se:priority}). However if non-rational number field elements
occur (as polmods or polynomials) as coefficients of $x$, the variable of
these polmods \emph{must} be the same as the main variable of $t$. For
example
\bprog
? factornf(x^2 + Mod(y, y^2+1), y^2+1);
? factornf(x^2 + y, y^2+1); \\@com these two are OK
? factornf(x^2 + Mod(z,z^2+1), y^2+1)
*** at top-level: factornf(x^2+Mod(z,z
*** ^--------------------
*** factornf: inconsistent data in rnf function.
? factornf(x^2 + z, y^2+1)
*** at top-level: factornf(x^2+z,y^2+1
*** ^--------------------
*** factornf: incorrect variable in rnf function.
@eprog
Obsolete: 2016-08-08
Function: factorpadic
Class: basic
Section: polynomials
C-Name: factorpadic
Prototype: GGL
Help: factorpadic(pol,p,r): p-adic factorization of the polynomial pol
to precision r.
Doc: $p$-adic factorization
of the polynomial \var{pol} to precision $r$, the result being a
two-column matrix as in \kbd{factor}. Note that this is not the same
as a factorization over $\Z/p^r\Z$ (polynomials over that ring do not form a
unique factorization domain, anyway), but approximations in $\Q/p^r\Z$ of
the true factorization in $\Q_p[X]$.
\bprog
? factorpadic(x^2 + 9, 3,5)
%1 =
[(1 + O(3^5))*x^2 + O(3^5)*x + (3^2 + O(3^5)) 1]
? factorpadic(x^2 + 1, 5,3)
%2 =
[ (1 + O(5^3))*x + (2 + 5 + 2*5^2 + O(5^3)) 1]
[(1 + O(5^3))*x + (3 + 3*5 + 2*5^2 + O(5^3)) 1]
@eprog\noindent
The factors are normalized so that their leading coefficient is a power of
$p$. The method used is a modified version of the \idx{round 4} algorithm of
\idx{Zassenhaus}.
If \var{pol} has inexact \typ{PADIC} coefficients, this is not always
well-defined; in this case, the polynomial is first made integral by dividing
out the $p$-adic content, then lifted to $\Z$ using \tet{truncate}
coefficientwise.
Hence we actually factor exactly a polynomial which is only $p$-adically
close to the input. To avoid pitfalls, we advise to only factor polynomials
with exact rational coefficients.
\synt{factorpadic}{GEN f,GEN p, long r} . The function \kbd{factorpadic0} is
deprecated, provided for backward compatibility.
Function: ffgen
Class: basic
Section: number_theoretical
C-Name: ffgen
Prototype: GDn
Help: ffgen(q,{v}): return a generator X mod P(X) for the finite field with
q elements. If v is given, the variable name is used to display g, else the
variable 'x' is used. Alternative syntax, q = P(X) an irreducible
polynomial with t_INTMOD
coefficients, return the generator X mod P(X) of the finite field defined
by P. If v is given, the variable name is used to display g, else the
variable of the polynomial P is used.
Doc: return a \typ{FFELT} generator for the finite field with $q$ elements;
$q = p^f$ must be a prime power. This functions computes an irreducible
monic polynomial $P\in\F_p[X]$ of degree~$f$ (via \tet{ffinit}) and
returns $g = X \pmod{P(X)}$. If \kbd{v} is given, the variable name is used
to display $g$, else the variable $x$ is used.
\bprog
? g = ffgen(8, 't);
? g.mod
%2 = t^3 + t^2 + 1
? g.p
%3 = 2
? g.f
%4 = 3
? ffgen(6)
*** at top-level: ffgen(6)
*** ^--------
*** ffgen: not a prime number in ffgen: 6.
@eprog\noindent Alternative syntax: instead of a prime power $q=p^f$, one may
input the pair $[p,f]$:
\bprog
? g = ffgen([2,4], 't);
? g.p
%2 = 2
? g.mod
%3 = t^4 + t^3 + t^2 + t + 1
@eprog\noindent Finally, one may input
directly the polynomial $P$ (monic, irreducible, with \typ{INTMOD}
coefficients), and the function returns the generator $g = X \pmod{P(X)}$,
inferring $p$ from the coefficients of $P$. If \kbd{v} is given, the
variable name is used to display $g$, else the variable of the polynomial
$P$ is used. If $P$ is not irreducible, we create an invalid object and
behaviour of functions dealing with the resulting \typ{FFELT}
is undefined; in fact, it is much more costly to test $P$ for
irreducibility than it would be to produce it via \kbd{ffinit}.
Variant:
To create a generator for a prime finite field, the function
\fun{GEN}{p_to_GEN}{GEN p, long v} returns \kbd{1+ffgen(x*Mod(1,p),v)}.
Function: ffinit
Class: basic
Section: number_theoretical
C-Name: ffinit
Prototype: GLDn
Help: ffinit(p,n,{v='x}): monic irreducible polynomial of degree n over F_p[v].
Description:
(int, small, ?var):pol ffinit($1, $2, $3)
Doc: computes a monic polynomial of degree $n$ which is irreducible over
$\F_p$, where $p$ is assumed to be prime. This function uses a fast variant
of Adleman and Lenstra's algorithm.
It is useful in conjunction with \tet{ffgen}; for instance if
\kbd{P = ffinit(3,2)}, you can represent elements in $\F_{3^2}$ in term of
\kbd{g = ffgen(P,'t)}. This can be abbreviated as
\kbd{g = ffgen(3\pow2, 't)}, where the defining polynomial $P$ can be later
recovered as \kbd{g.mod}.
Function: fflog
Class: basic
Section: number_theoretical
C-Name: fflog
Prototype: GGDG
Help: fflog(x,g,{o}): return the discrete logarithm of the finite field
element x in base g. If present, o must represents the multiplicative
order of g. If no o is given, assume that g is a primitive root.
Doc: discrete logarithm of the finite field element $x$ in base $g$, i.e.~
an $e$ in $\Z$ such that $g^e = o$. If
present, $o$ represents the multiplicative order of $g$, see
\secref{se:DLfun}; the preferred format for
this parameter is \kbd{[ord, factor(ord)]}, where \kbd{ord} is the
order of $g$. It may be set as a side effect of calling \tet{ffprimroot}.
If no $o$ is given, assume that $g$ is a primitive root. The result is
undefined if $e$ does not exist. This function uses
\item a combination of generic discrete log algorithms (see \tet{znlog})
\item a cubic sieve index calculus algorithm for large fields of degree at
least $5$.
\item Coppersmith's algorithm for fields of characteristic at most $5$.
\bprog
? t = ffgen(ffinit(7,5));
? o = fforder(t)
%2 = 5602 \\@com \emph{not} a primitive root.
? fflog(t^10,t)
%3 = 10
? fflog(t^10,t, o)
%4 = 10
? g = ffprimroot(t, &o);
? o \\ order is 16806, bundled with its factorization matrix
%6 = [16806, [2, 1; 3, 1; 2801, 1]]
? fforder(g, o)
%7 = 16806
? fflog(g^10000, g, o)
%8 = 10000
@eprog
Function: ffnbirred
Class: basic
Section: number_theoretical
C-Name: ffnbirred0
Prototype: GLD0,L,
Help: ffnbirred(q,n,{fl=0}): number of monic irreducible polynomials over F_q, of
degree n (fl=0, default) or at most n (fl=1).
Description:
(int, small, ?0):int ffnbirred($1, $2)
(int, small, 1):int ffsumnbirred($1, $2)
(int, small, ?small):int ffnbirred0($1, $2, $3)
Doc: computes the number of monic irreducible polynomials over $\F_q$ of degree exactly $n$,
($\fl=0$ or omitted) or at most $n$ ($\fl=1$).
Variant: Also available are
\fun{GEN}{ffnbirred}{GEN q, long n} (for $\fl=0$)
and \fun{GEN}{ffsumnbirred}{GEN q, long n} (for $\fl=1$).
Function: fforder
Class: basic
Section: number_theoretical
C-Name: fforder
Prototype: GDG
Help: fforder(x,{o}): multiplicative order of the finite field element x.
Optional o represents a multiple of the order of the element.
Doc: multiplicative order of the finite field element $x$. If $o$ is
present, it represents a multiple of the order of the element,
see \secref{se:DLfun}; the preferred format for
this parameter is \kbd{[N, factor(N)]}, where \kbd{N} is the cardinality
of the multiplicative group of the underlying finite field.
\bprog
? t = ffgen(ffinit(nextprime(10^8), 5));
? g = ffprimroot(t, &o); \\@com o will be useful!
? fforder(g^1000000, o)
time = 0 ms.
%5 = 5000001750000245000017150000600250008403
? fforder(g^1000000)
time = 16 ms. \\@com noticeably slower, same result of course
%6 = 5000001750000245000017150000600250008403
@eprog
Function: ffprimroot
Class: basic
Section: number_theoretical
C-Name: ffprimroot
Prototype: GD&
Help: ffprimroot(x, {&o}): return a primitive root of the multiplicative group
of the definition field of the finite field element x (not necessarily the
same as the field generated by x). If present, o is set to [ord, fa], where
ord is the order of the group, and fa its factorization
(useful in fflog and fforder).
Doc: return a primitive root of the multiplicative
group of the definition field of the finite field element $x$ (not necessarily
the same as the field generated by $x$). If present, $o$ is set to
a vector \kbd{[ord, fa]}, where \kbd{ord} is the order of the group
and \kbd{fa} its factorisation \kbd{factor(ord)}. This last parameter is
useful in \tet{fflog} and \tet{fforder}, see \secref{se:DLfun}.
\bprog
? t = ffgen(ffinit(nextprime(10^7), 5));
? g = ffprimroot(t, &o);
? o[1]
%3 = 100000950003610006859006516052476098
? o[2]
%4 =
[2 1]
[7 2]
[31 1]
[41 1]
[67 1]
[1523 1]
[10498781 1]
[15992881 1]
[46858913131 1]
? fflog(g^1000000, g, o)
time = 1,312 ms.
%5 = 1000000
@eprog
Function: fibonacci
Class: basic
Section: number_theoretical
C-Name: fibo
Prototype: L
Help: fibonacci(x): fibonacci number of index x (x C-integer).
Doc: $x^{\text{th}}$ Fibonacci number.
Function: floor
Class: basic
Section: conversions
C-Name: gfloor
Prototype: G
Help: floor(x): floor of x = largest integer <= x.
Description:
(small):small:parens $1
(int):int:copy:parens $1
(real):int floorr($1)
(mp):int mpfloor($1)
(gen):gen gfloor($1)
Doc:
floor of $x$. When $x$ is in $\R$, the result is the
largest integer smaller than or equal to $x$. Applied to a rational function,
$\kbd{floor}(x)$ returns the Euclidean quotient of the numerator by the
denominator.
Function: fold
Class: basic
Section: programming/specific
C-Name: fold0
Prototype: GG
Help: fold(f, A): return f(...f(f(A[1],A[2]),A[3]),...,A[#A]).
Wrapper: (GG)
Description:
(closure,gen):gen genfold(${1 cookie}, ${1 wrapper}, $2)
Doc: Apply the \typ{CLOSURE} \kbd{f} of arity $2$ to the entries of \kbd{A},
in order to return \kbd{f(\dots f(f(A[1],A[2]),A[3])\dots ,A[\#A])}.
\bprog
? fold((x,y)->x*y, [1,2,3,4])
%1 = 24
? fold((x,y)->[x,y], [1,2,3,4])
%2 = [[[1, 2], 3], 4]
? fold((x,f)->f(x), [2,sqr,sqr,sqr])
%3 = 256
? fold((x,y)->(x+y)/(1-x*y),[1..5])
%4 = -9/19
? bestappr(tan(sum(i=1,5,atan(i))))
%5 = -9/19
@eprog
Variant: Also available is
\fun{GEN}{genfold}{void *E, GEN (*fun)(void*,GEN, GEN), GEN A}.
Function: for
Class: basic
Section: programming/control
C-Name: forpari
Prototype: vV=GGI
Help: for(X=a,b,seq): the sequence is evaluated, X going from a up to b.
If b is set to +oo, the loop will not stop.
Doc: evaluates \var{seq}, where
the formal variable $X$ goes from $a$ to $b$. Nothing is done if $a>b$.
$a$ and $b$ must be in $\R$. If $b$ is set to \kbd{+oo}, the loop will not
stop; it is expected that the caller will break out of the loop itself at some
point, using \kbd{break} or \kbd{return}.
Function: forcomposite
Class: basic
Section: programming/control
C-Name: forcomposite
Prototype: vV=GDGI
Help: forcomposite(n=a,{b},seq): the sequence is evaluated, n running over the
composite numbers between a and b. Omitting b runs through composites >= a.
Iterator:
(gen,gen,?gen) (forcomposite, _forcomposite_init, _forcomposite_next)
Doc: evaluates \var{seq},
where the formal variable $n$ ranges over the composite numbers between the
non-negative real numbers $a$ to $b$, including $a$ and $b$ if they are
composite. Nothing is done if $a>b$.
\bprog
? forcomposite(n = 0, 10, print(n))
4
6
8
9
10
@eprog\noindent Omitting $b$ means we will run through all composites $\geq a$,
starting an infinite loop; it is expected that the user will break out of
the loop himself at some point, using \kbd{break} or \kbd{return}.
Note that the value of $n$ cannot be modified within \var{seq}:
\bprog
? forcomposite(n = 2, 10, n = [])
*** at top-level: forcomposite(n=2,10,n=[])
*** ^---
*** index read-only: was changed to [].
@eprog
Function: fordiv
Class: basic
Section: programming/control
C-Name: fordiv
Prototype: vGVI
Help: fordiv(n,X,seq): the sequence is evaluated, X running over the
divisors of n.
Doc: evaluates \var{seq}, where
the formal variable $X$ ranges through the divisors of $n$
(see \tet{divisors}, which is used as a subroutine). It is assumed that
\kbd{factor} can handle $n$, without negative exponents. Instead of $n$,
it is possible to input a factorization matrix, i.e. the output of
\kbd{factor(n)}.
This routine uses \kbd{divisors} as a subroutine, then loops over the
divisors. In particular, if $n$ is an integer, divisors are sorted by
increasing size.
To avoid storing all divisors, possibly using a lot of memory, the following
(much slower) routine loops over the divisors using essentially constant
space:
\bprog
FORDIV(N)=
{ my(P, E);
P = factor(N); E = P[,2]; P = P[,1];
forvec( v = vector(#E, i, [0,E[i]]),
X = factorback(P, v)
\\ ...
);
}
? for(i=1,10^5, FORDIV(i))
time = 3,445 ms.
? for(i=1,10^5, fordiv(i, d, ))
time = 490 ms.
@eprog
Function: forell
Class: basic
Section: programming/control
C-Name: forell0
Prototype: vVLLID0,L,
Help: forell(E,a,b,seq,{flag=0}): execute seq for each elliptic curves E of
conductor between a and b in the elldata database. If flag is non-zero, select
only the first curve in each isogeny class.
Wrapper: (,,,vG,)
Description:
(,small,small,closure,?small):void forell(${4 cookie}, ${4 wrapper}, $2, $3, $5)
Doc: evaluates \var{seq}, where the formal variable $E = [\var{name}, M, G]$
ranges through all elliptic curves of conductors from $a$ to $b$. In this
notation \var{name} is the curve name in Cremona's elliptic curve database,
$M$ is the minimal model, $G$ is a $\Z$-basis of the free part of the
Mordell-Weil group $E(\Q)$. If flag is non-zero, select
only the first curve in each isogeny class.
\bprog
? forell(E, 1, 500, my([name,M,G] = E); \
if (#G > 1, print(name)))
389a1
433a1
446d1
? c = 0; forell(E, 1, 500, c++); c \\ number of curves
%2 = 2214
? c = 0; forell(E, 1, 500, c++, 1); c \\ number of isogeny classes
%3 = 971
@eprog\noindent
The \tet{elldata} database must be installed and contain data for the
specified conductors.
\synt{forell}{void *data, long (*call)(void*,GEN), long a, long b, long flag}.
Function: forpart
Class: basic
Section: programming/control
C-Name: forpart0
Prototype: vV=GIDGDG
Help: forpart(X=k,seq,{a=k},{n=k}): evaluate seq where the Vecsmall X
goes over the partitions of k. Optional parameter n (n=nmax or n=[nmin,nmax])
restricts the length of the partition. Optional parameter a (a=amax or
a=[amin,amax]) restricts the range of the parts. Zeros are removed unless one
sets amin=0 to get X of fixed length nmax (=k by default).
Iterator:
(gen,small,?gen,?gen) (forpart, _forpart_init, _forpart_next)
Wrapper: (,vG,,)
Description:
(small,closure,?gen,?gen):void forpart(${2 cookie}, ${2 wrapper}, $1, $3, $4)
Doc: evaluate \var{seq} over the partitions $X=[x_1,\dots x_n]$ of the
integer $k$, i.e.~increasing sequences $x_1\leq x_2\dots \leq x_n$ of sum
$x_1+\dots + x_n=k$. By convention, $0$ admits only the empty partition and
negative numbers have no partitions. A partition is given by a
\typ{VECSMALL}, where parts are sorted in nondecreasing order:
\bprog
? forpart(X=3, print(X))
Vecsmall([3])
Vecsmall([1, 2])
Vecsmall([1, 1, 1])
@eprog\noindent Optional parameters $n$ and $a$ are as follows:
\item $n=\var{nmax}$ (resp. $n=[\var{nmin},\var{nmax}]$) restricts
partitions to length less than $\var{nmax}$ (resp. length between
$\var{nmin}$ and $nmax$), where the \emph{length} is the number of nonzero
entries.
\item $a=\var{amax}$ (resp. $a=[\var{amin},\var{amax}]$) restricts the parts
to integers less than $\var{amax}$ (resp. between $\var{amin}$ and
$\var{amax}$).
By default, parts are positive and we remove zero entries unless $amin\leq0$,
in which case $X$ is of constant length $\var{nmax}$.
\bprog
\\ at most 3 non-zero parts, all <= 4
? forpart(v=5,print(Vec(v)),4,3)
[1, 4]
[2, 3]
[1, 1, 3]
[1, 2, 2]
\\ between 2 and 4 parts less than 5, fill with zeros
? forpart(v=5,print(Vec(v)),[0,5],[2,4])
[0, 0, 1, 4]
[0, 0, 2, 3]
[0, 1, 1, 3]
[0, 1, 2, 2]
[1, 1, 1, 2]
@eprog\noindent
The behavior is unspecified if $X$ is modified inside the loop.
\synt{forpart}{void *data, long (*call)(void*,GEN), long k, GEN a, GEN n}.
Function: forprime
Class: basic
Section: programming/control
C-Name: forprime
Prototype: vV=GDGI
Help: forprime(p=a,{b},seq): the sequence is evaluated, p running over the
primes between a and b. Omitting b runs through primes >= a.
Iterator:
(*notype,small,small) (forprime, _u_forprime_init, _u_forprime_next)
(*small,gen,?gen) (forprime, _u_forprime_init, _u_forprime_next)
(*int,gen,?gen) (forprime, _forprime_init, _forprime_next_)
(gen,gen,?gen) (forprime, _forprime_init, _forprime_next_)
Doc: evaluates \var{seq},
where the formal variable $p$ ranges over the prime numbers between the real
numbers $a$ to $b$, including $a$ and $b$ if they are prime. More precisely,
the value of
$p$ is incremented to \kbd{nextprime($p$ + 1)}, the smallest prime strictly
larger than $p$, at the end of each iteration. Nothing is done if $a>b$.
\bprog
? forprime(p = 4, 10, print(p))
5
7
@eprog\noindent Setting $b$ to \kbd{+oo} means we will run through all primes
$\geq a$, starting an infinite loop; it is expected that the caller will break
out of the loop itself at some point, using \kbd{break} or \kbd{return}.
Note that the value of $p$ cannot be modified within \var{seq}:
\bprog
? forprime(p = 2, 10, p = [])
*** at top-level: forprime(p=2,10,p=[])
*** ^---
*** prime index read-only: was changed to [].
@eprog
Function: forqfvec
Class: basic
Section: linear_algebra
C-Name: forqfvec0
Prototype: vVGDGI
Help: forqfvec(v,q,b,expr): q being a square and symmetric integral matrix
representing an positive definite quadratic form, evaluate expr
for all vectors v such that q(v)<=b.
Doc: $q$ being a square and symmetric integral matrix representing a positive
definite
quadratic form, evaluate \kbd{expr} for all vector $v$ such that $q(v)\leq b$.
The formal variable $v$ runs through all such vectors in turn.
\bprog
? forqfvec(v, [3,2;2,3], 3, print(v))
[0, 1]~
[1, 0]~
[-1, 1]~
@eprog
Variant: The following function is also available:
\fun{void}{forqfvec}{void *E, long (*fun)(void *, GEN, GEN, double), GEN q, GEN b}:
Evaluate \kbd{fun(E,w,v,m)} on all $v$ such that $q(v)<b$, where $v$ is a
\typ{VECSMALL} and $m=q(v)$ is a C double. The function \kbd{fun} must
return $0$, unless \kbd{forqfvec} should stop, in which case, it should
return $1$.
Function: forstep
Class: basic
Section: programming/control
C-Name: forstep
Prototype: vV=GGGI
Help: forstep(X=a,b,s,seq): the sequence is evaluated, X going from a to b
in steps of s (can be a vector of steps). If b is set to +oo the loop will
not stop.
Doc: evaluates \var{seq},
where the formal variable $X$ goes from $a$ to $b$, in increments of $s$.
Nothing is done if $s>0$ and $a>b$ or if $s<0$ and $a<b$. $s$ must be in
$\R^*$ or a vector of steps $[s_1,\dots,s_n]$. In the latter case, the
successive steps are used in the order they appear in $s$.
\bprog
? forstep(x=5, 20, [2,4], print(x))
5
7
11
13
17
19
@eprog\noindent Setting $b$ to \kbd{+oo} will start an infinite loop; it is
expected that the caller will break out of the loop itself at some point,
using \kbd{break} or \kbd{return}.
Function: forsubgroup
Class: basic
Section: programming/control
C-Name: forsubgroup0
Prototype: vV=GDGI
Help: forsubgroup(H=G,{bound},seq): execute seq for each subgroup H of the
abelian group G, whose index is bounded by bound if not omitted. H is given
as a left divisor of G in HNF form.
Wrapper: (,,vG)
Description:
(gen,?gen,closure):void forsubgroup(${3 cookie}, ${3 wrapper}, $1, $2)
Doc: evaluates \var{seq} for
each subgroup $H$ of the \emph{abelian} group $G$ (given in
SNF\sidx{Smith normal form} form or as a vector of elementary divisors).
If \var{bound} is present, and is a positive integer, restrict the output to
subgroups of index less than \var{bound}. If \var{bound} is a vector
containing a single positive integer $B$, then only subgroups of index
exactly equal to $B$ are computed
The subgroups are not ordered in any
obvious way, unless $G$ is a $p$-group in which case Birkhoff's algorithm
produces them by decreasing index. A \idx{subgroup} is given as a matrix
whose columns give its generators on the implicit generators of $G$. For
example, the following prints all subgroups of index less than 2 in $G =
\Z/2\Z g_1 \times \Z/2\Z g_2$:
\bprog
? G = [2,2]; forsubgroup(H=G, 2, print(H))
[1; 1]
[1; 2]
[2; 1]
[1, 0; 1, 1]
@eprog\noindent
The last one, for instance is generated by $(g_1, g_1 + g_2)$. This
routine is intended to treat huge groups, when \tet{subgrouplist} is not an
option due to the sheer size of the output.
For maximal speed the subgroups have been left as produced by the algorithm.
To print them in canonical form (as left divisors of $G$ in HNF form), one
can for instance use
\bprog
? G = matdiagonal([2,2]); forsubgroup(H=G, 2, print(mathnf(concat(G,H))))
[2, 1; 0, 1]
[1, 0; 0, 2]
[2, 0; 0, 1]
[1, 0; 0, 1]
@eprog\noindent
Note that in this last representation, the index $[G:H]$ is given by the
determinant. See \tet{galoissubcyclo} and \tet{galoisfixedfield} for
applications to \idx{Galois} theory.
\synt{forsubgroup}{void *data, long (*call)(void*,GEN), GEN G, GEN bound}.
Function: forvec
Class: basic
Section: programming/control
C-Name: forvec
Prototype: vV=GID0,L,
Help: forvec(X=v,seq,{flag=0}): v being a vector of two-component vectors of
length n, the sequence is evaluated with X[i] going from v[i][1] to v[i][2]
for i=n,..,1 if flag is zero or omitted. If flag = 1 (resp. flag = 2),
restrict to increasing (resp. strictly increasing) sequences.
Iterator: (gen,gen,?small) (forvec, _forvec_init, _forvec_next)
Doc: Let $v$ be an $n$-component
vector (where $n$ is arbitrary) of two-component vectors $[a_i,b_i]$
for $1\le i\le n$, where all entries $a_i$, $b_i$ are real numbers.
This routine lets $X$ vary over the $n$-dimensional hyperrectangle
given by $v$, that is, $X$ is an $n$-dimensional vector taking
successively its entries $X[i]$ in the range $[a_i,b_i]$ with lexicographic
ordering. (The component with the highest index moves the fastest.)
The type of $X$ is the same as the type of $v$: \typ{VEC} or \typ{COL}.
The expression \var{seq} is evaluated with the successive values of $X$.
If $\fl=1$, generate only nondecreasing vectors $X$, and
if $\fl=2$, generate only strictly increasing vectors $X$.
\bprog
? forvec (X=[[0,1],[-1,1]], print(X));
[0, -1]
[0, 0]
[0, 1]
[1, -1]
[1, 0]
[1, 1]
? forvec (X=[[0,1],[-1,1]], print(X), 1);
[0, 0]
[0, 1]
[1, 1]
? forvec (X=[[0,1],[-1,1]], print(X), 2)
[0, 1]
@eprog
Function: frac
Class: basic
Section: conversions
C-Name: gfrac
Prototype: G
Help: frac(x): fractional part of x = x-floor(x).
Doc:
fractional part of $x$. Identical to
$x-\text{floor}(x)$. If $x$ is real, the result is in $[0,1[$.
Function: fromdigits
Class: basic
Section: conversions
C-Name: fromdigits
Prototype: GDG
Help: fromdigits(x,{b=10}): gives the integer formed by the elements of x seen
as the digits of a number in base b.
Doc: gives the integer formed by the elements of $x$ seen as the digits of a
number in base $b$ ($b = 10$ by default). This is the reverse of \kbd{digits}:
\bprog
? digits(1234,5)
%1 = [1,4,4,1,4]
? fromdigits([1,4,4,1,4],5)
%2 = 1234
@eprog\noindent By convention, $0$ has no digits:
\bprog
? fromdigits([])
%3 = 0
@eprog
Function: galoisexport
Class: basic
Section: number_fields
C-Name: galoisexport
Prototype: GD0,L,
Help: galoisexport(gal,{flag}): gal being a Galois group as output by
galoisinit, output a string representing the underlying permutation group in
GAP notation (default) or Magma notation (flag = 1).
Doc: \var{gal} being be a Galois group as output by \tet{galoisinit},
export the underlying permutation group as a string suitable
for (no flags or $\fl=0$) GAP or ($\fl=1$) Magma. The following example
compute the index of the underlying abstract group in the GAP library:
\bprog
? G = galoisinit(x^6+108);
? s = galoisexport(G)
%2 = "Group((1, 2, 3)(4, 5, 6), (1, 4)(2, 6)(3, 5))"
? extern("echo \"IdGroup("s");\" | gap -q")
%3 = [6, 1]
? galoisidentify(G)
%4 = [6, 1]
@eprog\noindent
This command also accepts subgroups returned by \kbd{galoissubgroups}.
To \emph{import} a GAP permutation into gp (for \tet{galoissubfields} for
instance), the following GAP function may be useful:
\bprog
PermToGP := function(p, n)
return Permuted([1..n],p);
end;
gap> p:= (1,26)(2,5)(3,17)(4,32)(6,9)(7,11)(8,24)(10,13)(12,15)(14,27)
(16,22)(18,28)(19,20)(21,29)(23,31)(25,30)
gap> PermToGP(p,32);
[ 26, 5, 17, 32, 2, 9, 11, 24, 6, 13, 7, 15, 10, 27, 12, 22, 3, 28, 20, 19,
29, 16, 31, 8, 30, 1, 14, 18, 21, 25, 23, 4 ]
@eprog
Function: galoisfixedfield
Class: basic
Section: number_fields
C-Name: galoisfixedfield
Prototype: GGD0,L,Dn
Help: galoisfixedfield(gal,perm,{flag},{v=y}): gal being a Galois group as
output by galoisinit and perm a subgroup, an element of gal.group or a vector
of such elements, return [P,x] such that P is a polynomial defining the fixed
field of gal[1] by the subgroup generated by perm, and x is a root of P in gal
expressed as a polmod in gal.pol. If flag is 1 return only P. If flag is 2
return [P,x,F] where F is the factorization of gal.pol over the field
defined by P, where the variable v stands for a root of P.
Description:
(gen, gen, ?small, ?var):vec galoisfixedfield($1, $2, $3, $4)
Doc: \var{gal} being be a Galois group as output by \tet{galoisinit} and
\var{perm} an element of $\var{gal}.group$, a vector of such elements
or a subgroup of \var{gal} as returned by galoissubgroups,
computes the fixed field of \var{gal} by the automorphism defined by the
permutations \var{perm} of the roots $\var{gal}.roots$. $P$ is guaranteed to
be squarefree modulo $\var{gal}.p$.
If no flags or $\fl=0$, output format is the same as for \tet{nfsubfield},
returning $[P,x]$ such that $P$ is a polynomial defining the fixed field, and
$x$ is a root of $P$ expressed as a polmod in $\var{gal}.pol$.
If $\fl=1$ return only the polynomial $P$.
If $\fl=2$ return $[P,x,F]$ where $P$ and $x$ are as above and $F$ is the
factorization of $\var{gal}.pol$ over the field defined by $P$, where
variable $v$ ($y$ by default) stands for a root of $P$. The priority of $v$
must be less than the priority of the variable of $\var{gal}.pol$ (see
\secref{se:priority}). Example:
\bprog
? G = galoisinit(x^4+1);
? galoisfixedfield(G,G.group[2],2)
%2 = [x^2 + 2, Mod(x^3 + x, x^4 + 1), [x^2 - y*x - 1, x^2 + y*x - 1]]
@eprog\noindent
computes the factorization $x^4+1=(x^2-\sqrt{-2}x-1)(x^2+\sqrt{-2}x-1)$
Function: galoisgetpol
Class: basic
Section: number_fields
C-Name: galoisgetpol
Prototype: LD0,L,D1,L,
Help: galoisgetpol(a,{b},{s}): query the galpol package for a polynomial with
Galois group isomorphic to GAP4(a,b), totally real if s=1 (default) and
totally complex if s=2. The output is a vector [pol, den] where pol is the
polynomial and den is the common denominator of the conjugates expressed
as a polynomial in a root of pol. If b and s are omitted, return the number of
isomorphism classes of groups of order a.
Description:
(small):int galoisnbpol($1)
(small,):int galoisnbpol($1)
(small,,):int galoisnbpol($1)
(small,small,small):vec galoisgetpol($1, $2 ,$3)
Doc: Query the galpol package for a polynomial with Galois group isomorphic to
GAP4(a,b), totally real if $s=1$ (default) and totally complex if $s=2$. The
output is a vector [\kbd{pol}, \kbd{den}] where
\item \kbd{pol} is the polynomial of degree $a$
\item \kbd{den} is the denominator of \kbd{nfgaloisconj(pol)}.
Pass it as an optional argument to \tet{galoisinit} or \tet{nfgaloisconj} to
speed them up:
\bprog
? [pol,den] = galoisgetpol(64,4,1);
? G = galoisinit(pol);
time = 352ms
? galoisinit(pol, den); \\ passing 'den' speeds up the computation
time = 264ms
? % == %`
%4 = 1 \\ same answer
@eprog
If $b$ and $s$ are omitted, return the number of isomorphism classes of
groups of order $a$.
Variant: Also available is \fun{GEN}{galoisnbpol}{long a} when $b$ and $s$
are omitted.
Function: galoisidentify
Class: basic
Section: number_fields
C-Name: galoisidentify
Prototype: G
Help: galoisidentify(gal): gal being a Galois group as output by galoisinit,
output the isomorphism class of the underlying abstract group as a
two-components vector [o,i], where o is the group order, and i is the group
index in the GAP4 small group library.
Doc: \var{gal} being be a Galois group as output by \tet{galoisinit},
output the isomorphism class of the underlying abstract group as a
two-components vector $[o,i]$, where $o$ is the group order, and $i$ is the
group index in the GAP4 Small Group library, by Hans Ulrich Besche, Bettina
Eick and Eamonn O'Brien.
This command also accepts subgroups returned by \kbd{galoissubgroups}.
The current implementation is limited to degree less or equal to $127$.
Some larger ``easy'' orders are also supported.
The output is similar to the output of the function \kbd{IdGroup} in GAP4.
Note that GAP4 \kbd{IdGroup} handles all groups of order less than $2000$
except $1024$, so you can use \tet{galoisexport} and GAP4 to identify large
Galois groups.
Function: galoisinit
Class: basic
Section: number_fields
C-Name: galoisinit
Prototype: GDG
Help: galoisinit(pol,{den}): pol being a polynomial or a number field as
output by nfinit defining a Galois extension of Q, compute the Galois group
and all necessary information for computing fixed fields. den is optional
and has the same meaning as in nfgaloisconj(,4)(see manual).
Description:
(gen, ?int):gal galoisinit($1, $2)
Doc: computes the Galois group
and all necessary information for computing the fixed fields of the
Galois extension $K/\Q$ where $K$ is the number field defined by
$\var{pol}$ (monic irreducible polynomial in $\Z[X]$ or
a number field as output by \tet{nfinit}). The extension $K/\Q$ must be
Galois with Galois group ``weakly'' super-solvable, see below;
returns 0 otherwise. Hence this permits to quickly check whether a polynomial
of order strictly less than $36$ is Galois or not.
The algorithm used is an improved version of the paper
``An efficient algorithm for the computation of Galois automorphisms'',
Bill Allombert, Math.~Comp, vol.~73, 245, 2001, pp.~359--375.
A group $G$ is said to be ``weakly'' super-solvable if there exists a
normal series
$\{1\} = H_0 \triangleleft H_1 \triangleleft \cdots \triangleleft H_{n-1}
\triangleleft H_n$
such that each $H_i$ is normal in $G$ and for $i<n$, each quotient group
$H_{i+1}/H_i$ is cyclic, and either $H_n=G$ (then $G$ is super-solvable) or
$G/H_n$ is isomorphic to either $A_4$ or $S_4$.
In practice, almost all small groups are WKSS, the exceptions having order
36(1 exception), 48(2), 56(1), 60(1), 72(5), 75(1), 80(1), 96(10) and $\geq
108$.
This function is a prerequisite for most of the \kbd{galois}$xxx$ routines.
For instance:
\bprog
P = x^6 + 108;
G = galoisinit(P);
L = galoissubgroups(G);
vector(#L, i, galoisisabelian(L[i],1))
vector(#L, i, galoisidentify(L[i]))
@eprog
The output is an 8-component vector \var{gal}.
$\var{gal}[1]$ contains the polynomial \var{pol}
(\kbd{\var{gal}.pol}).
$\var{gal}[2]$ is a three-components vector $[p,e,q]$ where $p$ is a
prime number (\kbd{\var{gal}.p}) such that \var{pol} totally split
modulo $p$ , $e$ is an integer and $q=p^e$ (\kbd{\var{gal}.mod}) is the
modulus of the roots in \kbd{\var{gal}.roots}.
$\var{gal}[3]$ is a vector $L$ containing the $p$-adic roots of
\var{pol} as integers implicitly modulo \kbd{\var{gal}.mod}.
(\kbd{\var{gal}.roots}).
$\var{gal}[4]$ is the inverse of the Vandermonde matrix of the
$p$-adic roots of \var{pol}, multiplied by $\var{gal}[5]$.
$\var{gal}[5]$ is a multiple of the least common denominator of the
automorphisms expressed as polynomial in a root of \var{pol}.
$\var{gal}[6]$ is the Galois group $G$ expressed as a vector of
permutations of $L$ (\kbd{\var{gal}.group}).
$\var{gal}[7]$ is a generating subset $S=[s_1,\ldots,s_g]$ of $G$
expressed as a vector of permutations of $L$ (\kbd{\var{gal}.gen}).
$\var{gal}[8]$ contains the relative orders $[o_1,\ldots,o_g]$ of
the generators of $S$ (\kbd{\var{gal}.orders}).
Let $H_n$ be as above, we have the following properties:
\quad\item if $G/H_n\simeq A_4$ then $[o_1,\ldots,o_g]$ ends by
$[2,2,3]$.
\quad\item if $G/H_n\simeq S_4$ then $[o_1,\ldots,o_g]$ ends by
$[2,2,3,2]$.
\quad\item for $1\leq i \leq g$ the subgroup of $G$ generated by
$[s_1,\ldots,s_g]$ is normal, with the exception of $i=g-2$ in the
$A_4$ case and of $i=g-3$ in the $S_A$ case.
\quad\item the relative order $o_i$ of $s_i$ is its order in the
quotient group $G/\langle s_1,\ldots,s_{i-1}\rangle$, with the same
exceptions.
\quad\item for any $x\in G$ there exists a unique family
$[e_1,\ldots,e_g]$ such that (no exceptions):
-- for $1\leq i \leq g$ we have $0\leq e_i<o_i$
-- $x=g_1^{e_1}g_2^{e_2}\ldots g_n^{e_n}$
If present $den$ must be a suitable value for $\var{gal}[5]$.
Function: galoisisabelian
Class: basic
Section: number_fields
C-Name: galoisisabelian
Prototype: GD0,L,
Help: galoisisabelian(gal,{flag=0}): gal being as output by galoisinit,
return 0 if gal is not abelian, the HNF matrix of gal over gal.gen if
flag=0, 1 if flag is 1, and the SNF of gal is flag=2.
Doc: \var{gal} being as output by \kbd{galoisinit}, return $0$ if
\var{gal} is not an abelian group, and the HNF matrix of \var{gal} over
\kbd{gal.gen} if $fl=0$, $1$ if $fl=1$.
This command also accepts subgroups returned by \kbd{galoissubgroups}.
Function: galoisisnormal
Class: basic
Section: number_fields
C-Name: galoisisnormal
Prototype: lGG
Help: galoisisnormal(gal,subgrp): gal being as output by galoisinit,
and subgrp a subgroup of gal as output by galoissubgroups,
return 1 if subgrp is a normal subgroup of gal, else return 0.
Doc: \var{gal} being as output by \kbd{galoisinit}, and \var{subgrp} a subgroup
of \var{gal} as output by \kbd{galoissubgroups},return $1$ if \var{subgrp} is a
normal subgroup of \var{gal}, else return 0.
This command also accepts subgroups returned by \kbd{galoissubgroups}.
Function: galoispermtopol
Class: basic
Section: number_fields
C-Name: galoispermtopol
Prototype: GG
Help: galoispermtopol(gal,perm): gal being a Galois group as output by
galoisinit and perm a element of gal.group, return the polynomial defining
the corresponding Galois automorphism.
Doc: \var{gal} being a
Galois group as output by \kbd{galoisinit} and \var{perm} a element of
$\var{gal}.group$, return the polynomial defining the Galois
automorphism, as output by \kbd{nfgaloisconj}, attached to the
permutation \var{perm} of the roots $\var{gal}.roots$. \var{perm} can
also be a vector or matrix, in this case, \kbd{galoispermtopol} is
applied to all components recursively.
\noindent Note that
\bprog
G = galoisinit(pol);
galoispermtopol(G, G[6])~
@eprog\noindent
is equivalent to \kbd{nfgaloisconj(pol)}, if degree of \var{pol} is greater
or equal to $2$.
Function: galoissubcyclo
Class: basic
Section: number_fields
C-Name: galoissubcyclo
Prototype: GDGD0,L,Dn
Help: galoissubcyclo(N,H,{fl=0},{v}): compute a polynomial (in variable v)
defining the subfield of Q(zeta_n) fixed by the subgroup H of (Z/nZ)*. N can
be an integer n, znstar(n) or bnrinit(bnfinit(y),[n,[1]],1). H can be given
by a generator, a set of generator given by a vector or a HNF matrix (see
manual). If flag is 1, output only the conductor of the abelian extension.
If flag is 2 output [pol,f] where pol is the polynomial and f the conductor.
Doc: computes the subextension
of $\Q(\zeta_n)$ fixed by the subgroup $H \subset (\Z/n\Z)^*$. By the
Kronecker-Weber theorem, all abelian number fields can be generated in this
way (uniquely if $n$ is taken to be minimal).
\noindent The pair $(n, H)$ is deduced from the parameters $(N, H)$ as follows
\item $N$ an integer: then $n = N$; $H$ is a generator, i.e. an
integer or an integer modulo $n$; or a vector of generators.
\item $N$ the output of \kbd{znstar($n$)}. $H$ as in the first case
above, or a matrix, taken to be a HNF left divisor of the SNF for $(\Z/n\Z)^*$
(of type \kbd{$N$.cyc}), giving the generators of $H$ in terms of \kbd{$N$.gen}.
\item $N$ the output of \kbd{bnrinit(bnfinit(y), $m$, 1)} where $m$ is a
module. $H$ as in the first case, or a matrix taken to be a HNF left
divisor of the SNF for the ray class group modulo $m$
(of type \kbd{$N$.cyc}), giving the generators of $H$ in terms of \kbd{$N$.gen}.
In this last case, beware that $H$ is understood relatively to $N$; in
particular, if the infinite place does not divide the module, e.g if $m$ is
an integer, then it is not a subgroup of $(\Z/n\Z)^*$, but of its quotient by
$\{\pm 1\}$.
If $fl=0$, compute a polynomial (in the variable \var{v}) defining
the subfield of $\Q(\zeta_n)$ fixed by the subgroup \var{H} of $(\Z/n\Z)^*$.
If $fl=1$, compute only the conductor of the abelian extension, as a module.
If $fl=2$, output $[pol, N]$, where $pol$ is the polynomial as output when
$fl=0$ and $N$ the conductor as output when $fl=1$.
The following function can be used to compute all subfields of
$\Q(\zeta_n)$ (of exact degree \kbd{d}, if \kbd{d} is set):
\bprog
polsubcyclo(n, d = -1)=
{ my(bnr,L,IndexBound);
IndexBound = if (d < 0, n, [d]);
bnr = bnrinit(bnfinit(y), [n,[1]], 1);
L = subgrouplist(bnr, IndexBound, 1);
vector(#L,i, galoissubcyclo(bnr,L[i]));
}
@eprog\noindent
Setting \kbd{L = subgrouplist(bnr, IndexBound)} would produce subfields of exact
conductor $n\infty$.
Function: galoissubfields
Class: basic
Section: number_fields
C-Name: galoissubfields
Prototype: GD0,L,Dn
Help: galoissubfields(G,{flag=0},{v}): output all the subfields of G. flag
has the same meaning as for galoisfixedfield.
Doc: outputs all the subfields of the Galois group \var{G}, as a vector.
This works by applying \kbd{galoisfixedfield} to all subgroups. The meaning of
\var{flag} is the same as for \kbd{galoisfixedfield}.
Function: galoissubgroups
Class: basic
Section: number_fields
C-Name: galoissubgroups
Prototype: G
Help: galoissubgroups(G): output all the subgroups of G.
Doc: outputs all the subgroups of the Galois group \kbd{gal}. A subgroup is a
vector [\var{gen}, \var{orders}], with the same meaning
as for $\var{gal}.gen$ and $\var{gal}.orders$. Hence \var{gen} is a vector of
permutations generating the subgroup, and \var{orders} is the relatives
orders of the generators. The cardinality of a subgroup is the product of the
relative orders. Such subgroup can be used instead of a Galois group in the
following command: \kbd{galoisisabelian}, \kbd{galoissubgroups},
\kbd{galoisexport} and \kbd{galoisidentify}.
To get the subfield fixed by a subgroup \var{sub} of \var{gal}, use
\bprog
galoisfixedfield(gal,sub[1])
@eprog
Function: gamma
Class: basic
Section: transcendental
C-Name: ggamma
Prototype: Gp
Help: gamma(s): gamma function at s, a complex or p-adic number, or a series.
Doc: For $s$ a complex number, evaluates Euler's gamma
function \sidx{gamma-function}
$$\Gamma(s)=\int_0^\infty t^{s-1}\exp(-t)\,dt.$$
Error if $s$ is a non-positive integer, where $\Gamma$ has a pole.
For $s$ a \typ{PADIC}, evaluates the Morita gamma function at $s$, that
is the unique continuous $p$-adic function on the $p$-adic integers
extending $\Gamma_p(k)=(-1)^k \prod_{j<k}'j$, where the prime means that $p$
does not divide $j$.
\bprog
? gamma(1/4 + O(5^10))
%1= 1 + 4*5 + 3*5^4 + 5^6 + 5^7 + 4*5^9 + O(5^10)
? algdep(%,4)
%2 = x^4 + 4*x^2 + 5
@eprog
Variant: For a \typ{PADIC} $x$, the function \fun{GEN}{Qp_gamma}{GEN x} is
also available.
Function: gammah
Class: basic
Section: transcendental
C-Name: ggammah
Prototype: Gp
Help: gammah(x): gamma of x+1/2 (x integer).
Doc: gamma function evaluated at the argument $x+1/2$.
Function: gammamellininv
Class: basic
Section: transcendental
C-Name: gammamellininv
Prototype: GGD0,L,b
Help: gammamellininv(G,t,{m=0}): returns G(t), where G is as output
by gammamellininvinit. The alternative syntax gammamellininv(A,t,m)
is also available.
Doc: returns the value at $t$ of the inverse Mellin transform
$G$ initialized by \tet{gammamellininvinit}.
\bprog
? G = gammamellininvinit([0]);
? gammamellininv(G, 2) - 2*exp(-Pi*2^2)
%2 = -4.484155085839414627 E-44
@eprog
The alternative shortcut
\bprog
gammamellininv(A,t,m)
@eprog\noindent for
\bprog
gammamellininv(gammamellininvinit(A,m), t)
@eprog\noindent is available.
Function: gammamellininvasymp
Class: basic
Section: transcendental
C-Name: gammamellininvasymp
Prototype: GDPD0,L,
Help: gammamellininvasymp(A,n,{m=0}): return the first n terms of the
asymptotic expansion at infinity of the m-th derivative K^m(t) of the
inverse Mellin transform of the function
f(s)=Gamma_R(s+a_1)*...*Gamma_R(s+a_d), where Vga is the vector [a_1,...,a_d]
and Gamma_R(s)=Pi^(-s/2)*gamma(s/2). The result is a vector [M[1]...M[n]]
with M[1]=1, such that
K^m(t) = \sqrt{2^{d+1}/d}t^{a+m(2/d-1)}e^{-d pi t^{2/d}}\sum_{n\ge0}M[n+1]
(pi t^{2n/d})^{-n}, with a = (1-d+sum_ja_j)/d.
Doc: Return the first $n$ terms of the asymptotic expansion at infinity
of the $m$-th derivative $K^{(m)}(t)$ of the inverse Mellin transform of the
function
$$f(s) = \Gamma_\R(s+a_1)\*\ldots\*\Gamma_\R(s+a_d)\;,$$
where \kbd{A} is the vector $[a_1,\ldots,a_d]$ and
$\Gamma_\R(s)=\pi^{-s/2}\*\Gamma(s/2)$ (Euler's \kbd{gamma}).
The result is a vector
$[M[1]...M[n]]$ with M[1]=1, such that
$$K^{(m)}(t)=\sqrt{2^{d+1}/d}t^{a+m(2/d-1)}e^{-d\pi t^{2/d}}
\sum_{n\ge0} M[n+1] (\pi t^{2/d})^{-n} $$
with $a=(1-d+\sum_{1\le j\le d}a_j)/d$.
Function: gammamellininvinit
Class: basic
Section: transcendental
C-Name: gammamellininvinit
Prototype: GD0,L,b
Help: gammamellininvinit(A,{m=0}): initialize data for the computation by
gammamellininv() of the m-th derivative of the inverse Mellin transform
of the function f(s) = Gamma_R(s+a1)*...*Gamma_R(s+ad), where
A is the vector [a1,...,ad] and Gamma_R(s) = Pi^(-s/2)*gamma(s/2).
Doc: initialize data for the computation by \tet{gammamellininv} of
the $m$-th derivative of the inverse Mellin transform of the function
$$f(s) = \Gamma_\R(s+a_1)\*\ldots\*\Gamma_\R(s+a_d)$$
where \kbd{A} is the vector $[a_1,\ldots,a_d]$ and
$\Gamma_\R(s)=\pi^{-s/2}\*\Gamma(s/2)$ (Euler's \kbd{gamma}). This is the
special case of Meijer's $G$ functions used to compute $L$-values via the
approximate functional equation.
\misctitle{Caveat} Contrary to the PARI convention, this function
guarantees an \emph{absolute} (rather than relative) error bound.
For instance, the inverse Mellin transform of $\Gamma_\R(s)$ is
$2\exp(-\pi z^2)$:
\bprog
? G = gammamellininvinit([0]);
? gammamellininv(G, 2) - 2*exp(-Pi*2^2)
%2 = -4.484155085839414627 E-44
@eprog
The inverse Mellin transform of $\Gamma_\R(s+1)$ is
$2 z\exp(-\pi z^2)$, and its second derivative is
$ 4\pi z \exp(-\pi z^2)(2\pi z^2 - 3)$:
\bprog
? G = gammamellininvinit([1], 2);
? a(z) = 4*Pi*z*exp(-Pi*z^2)*(2*Pi*z^2-3);
? b(z) = gammamellininv(G,z);
? t(z) = b(z) - a(z);
? t(3/2)
%3 = -1.4693679385278593850 E-39
@eprog
Function: gcd
Class: basic
Section: number_theoretical
C-Name: ggcd0
Prototype: GDG
Help: gcd(x,{y}): greatest common divisor of x and y.
Description:
(small, small):small cgcd($1, $2)
(int, int):int gcdii($1, $2)
(gen):gen content($1)
(gen, gen):gen ggcd($1, $2)
Doc: creates the greatest common divisor of $x$ and $y$.
If you also need the $u$ and $v$ such that $x*u + y*v = \gcd(x,y)$,
use the \tet{bezout} function. $x$ and $y$ can have rather quite general
types, for instance both rational numbers. If $y$ is omitted and $x$ is a
vector, returns the $\text{gcd}$ of all components of $x$, i.e.~this is
equivalent to \kbd{content(x)}.
When $x$ and $y$ are both given and one of them is a vector/matrix type,
the GCD is again taken recursively on each component, but in a different way.
If $y$ is a vector, resp.~matrix, then the result has the same type as $y$,
and components equal to \kbd{gcd(x, y[i])}, resp.~\kbd{gcd(x, y[,i])}. Else
if $x$ is a vector/matrix the result has the same type as $x$ and an
analogous definition. Note that for these types, \kbd{gcd} is not
commutative.
The algorithm used is a naive \idx{Euclid} except for the following inputs:
\item integers: use modified right-shift binary (``plus-minus''
variant).
\item univariate polynomials with coefficients in the same number
field (in particular rational): use modular gcd algorithm.
\item general polynomials: use the \idx{subresultant algorithm} if
coefficient explosion is likely (non modular coefficients).
If $u$ and $v$ are polynomials in the same variable with \emph{inexact}
coefficients, their gcd is defined to be scalar, so that
\bprog
? a = x + 0.0; gcd(a,a)
%1 = 1
? b = y*x + O(y); gcd(b,b)
%2 = y
? c = 4*x + O(2^3); gcd(c,c)
%3 = 4
@eprog\noindent A good quantitative check to decide whether such a
gcd ``should be'' non-trivial, is to use \tet{polresultant}: a value
close to $0$ means that a small deformation of the inputs has non-trivial gcd.
You may also use \tet{gcdext}, which does try to compute an approximate gcd
$d$ and provides $u$, $v$ to check whether $u x + v y$ is close to $d$.
Variant: Also available are \fun{GEN}{ggcd}{GEN x, GEN y}, if \kbd{y} is not
\kbd{NULL}, and \fun{GEN}{content}{GEN x}, if $\kbd{y} = \kbd{NULL}$.
Function: gcdext
Class: basic
Section: number_theoretical
C-Name: gcdext0
Prototype: GG
Help: gcdext(x,y): returns [u,v,d] such that d=gcd(x,y) and u*x+v*y=d.
Doc: Returns $[u,v,d]$ such that $d$ is the gcd of $x,y$,
$x*u+y*v=\gcd(x,y)$, and $u$ and $v$ minimal in a natural sense.
The arguments must be integers or polynomials. \sidx{extended gcd}
\sidx{Bezout relation}
\bprog
? [u, v, d] = gcdext(32,102)
%1 = [16, -5, 2]
? d
%2 = 2
? gcdext(x^2-x, x^2+x-2)
%3 = [-1/2, 1/2, x - 1]
@eprog
If $x,y$ are polynomials in the same variable and \emph{inexact}
coefficients, then compute $u,v,d$ such that $x*u+y*v = d$, where $d$
approximately divides both and $x$ and $y$; in particular, we do not obtain
\kbd{gcd(x,y)} which is \emph{defined} to be a scalar in this case:
\bprog
? a = x + 0.0; gcd(a,a)
%1 = 1
? gcdext(a,a)
%2 = [0, 1, x + 0.E-28]
? gcdext(x-Pi, 6*x^2-zeta(2))
%3 = [-6*x - 18.8495559, 1, 57.5726923]
@eprog\noindent For inexact inputs, the output is thus not well defined
mathematically, but you obtain explicit polynomials to check whether the
approximation is close enough for your needs.
Function: genus2red
Class: basic
Section: elliptic_curves
C-Name: genus2red
Prototype: GDG
Help: genus2red(PQ,{p}): let PQ be a polynomial P, resp. a vector [P,Q] of
polynomials, with rational coefficients. Determines the reduction at p > 2
of the (proper, smooth) hyperelliptic curve C/Q of genus 2 defined by
y^2 = P, resp. y^2 + Q*y = P. More precisely, determines the special fiber X_p
of the minimal regular model X of C over Z.
Doc: Let $PQ$ be a polynomial $P$, resp. a vector $[P,Q]$ of polynomials, with
rational coefficients.
Determines the reduction at $p > 2$ of the (proper, smooth) genus~2
curve $C/\Q$, defined by the hyperelliptic equation $y^2 = P(x)$, resp.
$y^2 + Q(x)*y = P(x)$.
(The special fiber $X_p$ of the minimal regular model $X$ of $C$ over $\Z$.)
If $p$ is omitted, determines the reduction type for all (odd) prime
divisors of the discriminant.
\noindent This function was rewritten from an implementation of Liu's
algorithm by Cohen and Liu (1994), \kbd{genus2reduction-0.3}, see
\url{http://www.math.u-bordeaux.fr/~liu/G2R/}.
\misctitle{CAVEAT} The function interface may change: for the
time being, it returns $[N,\var{FaN}, T, V]$
where $N$ is either the local conductor at $p$ or the
global conductor, \var{FaN} is its factorization, $y^2 = T$ defines a
minimal model over $\Z[1/2]$ and $V$ describes the reduction type at the
various considered~$p$. Unfortunately, the program is not complete for
$p = 2$, and we may return the odd part of the conductor only: this is the
case if the factorization includes the (impossible) term $2^{-1}$; if the
factorization contains another power of $2$, then this is the exact local
conductor at $2$ and $N$ is the global conductor.
\bprog
? default(debuglevel, 1);
? genus2red(x^6 + 3*x^3 + 63, 3)
(potential) stable reduction: [1, []]
reduction at p: [III{9}] page 184, [3, 3], f = 10
%1 = [59049, Mat([3, 10]), x^6 + 3*x^3 + 63, [3, [1, []],
["[III{9}] page 184", [3, 3]]]]
? [N, FaN, T, V] = genus2red(x^3-x^2-1, x^2-x); \\ X_1(13), global reduction
p = 13
(potential) stable reduction: [5, [Mod(0, 13), Mod(0, 13)]]
reduction at p: [I{0}-II-0] page 159, [], f = 2
? N
%3 = 169
? FaN
%4 = Mat([13, 2]) \\ in particular, good reduction at 2 !
? T
%5 = x^6 + 58*x^5 + 1401*x^4 + 18038*x^3 + 130546*x^2 + 503516*x + 808561
? V
%6 = [[13, [5, [Mod(0, 13), Mod(0, 13)]], ["[I{0}-II-0] page 159", []]]]
@eprog\noindent
We now first describe the format of the vector $V = V_p$ in the case where
$p$ was specified (local reduction at~$p$): it is a triple $[p, \var{stable},
\var{red}]$. The component $\var{stable} = [\var{type}, \var{vecj}]$ contains
information about the stable reduction after a field extension;
depending on \var{type}s, the stable reduction is
\item 1: smooth (i.e. the curve has potentially good reduction). The
Jacobian $J(C)$ has potentially good reduction.
\item 2: an elliptic curve $E$ with an ordinary double point; \var{vecj}
contains $j$ mod $p$, the modular invariant of $E$. The (potential)
semi-abelian reduction of $J(C)$ is the extension of an elliptic curve (with
modular invariant $j$ mod $p$) by a torus.
\item 3: a projective line with two ordinary double points. The Jacobian
$J(C)$ has potentially multiplicative reduction.
\item 4: the union of two projective lines crossing transversally at three
points. The Jacobian $J(C)$ has potentially multiplicative reduction.
\item 5: the union of two elliptic curves $E_1$ and $E_2$ intersecting
transversally at one point; \var{vecj} contains their modular invariants
$j_1$ and $j_2$, which may live in a quadratic extension of $\F_p$ and need
not be distinct. The Jacobian $J(C)$ has potentially good reduction,
isomorphic to the product of the reductions of $E_1$ and $E_2$.
\item 6: the union of an elliptic curve $E$ and a projective line which has
an ordinary double point, and these two components intersect transversally
at one point; \var{vecj} contains $j$ mod $p$, the modular invariant of $E$.
The (potential) semi-abelian reduction of $J(C)$ is the extension of an
elliptic curve (with modular invariant $j$ mod $p$) by a torus.
\item 7: as in type 6, but the two components are both singular. The
Jacobian $J(C)$ has potentially multiplicative reduction.
The component $\var{red} = [\var{NUtype}, \var{neron}]$ contains two data
concerning the reduction at $p$ without any ramified field extension.
The \var{NUtype} is a \typ{STR} describing the reduction at $p$ of $C$,
following Namikawa-Ueno, \emph{The complete classification of fibers in
pencils of curves of genus two}, Manuscripta Math., vol. 9, (1973), pages
143-186. The reduction symbol is followed by the corresponding page number
or page range in this article.
The second datum \var{neron} is the group of connected components (over an
algebraic closure of $\F_p$) of the N\'eron model of $J(C)$, given as a
finite abelian group (vector of elementary divisors).
\smallskip
If $p = 2$, the \var{red} component may be omitted altogether (and
replaced by \kbd{[]}, in the case where the program could not compute it.
When $p$ was not specified, $V$ is the vector of all $V_p$, for all
considered $p$.
\misctitle{Notes about Namikawa-Ueno types}
\item A lower index is denoted between braces: for instance,
\kbd{[I\obr2\cbr-II-5]} means \kbd{[I\_2-II-5]}.
\item If $K$ and $K'$ are Kodaira symbols for singular fibers of elliptic
curves, then \kbd{[$K$-$K'$-m]} and \kbd{[$K'$-$K$-m]} are the same.
We define a total ordering on Kodaira symbol by fixing $\kbd{I} < \kbd{I*} <
\kbd{II} < \kbd{II*}, \dots$. If the reduction type is the same, we order by
the number of components, e.g. $\kbd{I}_2 < \kbd{I}_4$, etc.
Then we normalize our output so that $K \leq K'$.
\item \kbd{[$K$-$K'$-$-1$]} is \kbd{[$K$-$K'$-$\alpha$]} in the notation of
Namikawa-Ueno.
\item The figure \kbd{[2I\_0-m]} in Namikawa-Ueno, page 159, must be denoted
by \kbd{[2I\_0-(m+1)]}.
Function: getabstime
Class: basic
Section: programming/specific
C-Name: getabstime
Prototype: l
Help: getabstime(): time (in milliseconds) since startup.
Doc: returns the CPU time (in milliseconds) elapsed since \kbd{gp} startup.
This provides a reentrant version of \kbd{gettime}:
\bprog
my (t = getabstime());
...
print("Time: ", getabstime() - t);
@eprog
For a version giving wall-clock time, see \tet{getwalltime}.
Function: getenv
Class: basic
Section: programming/specific
C-Name: gp_getenv
Prototype: s
Help: getenv(s): value of the environment variable s, 0 if it is not defined.
Doc: return the value of the environment variable \kbd{s} if it is defined, otherwise return 0.
Function: getheap
Class: basic
Section: programming/specific
C-Name: getheap
Prototype:
Help: getheap(): 2-component vector giving the current number of objects in
the heap and the space they occupy (in long words).
Doc: returns a two-component row vector giving the
number of objects on the heap and the amount of memory they occupy in long
words. Useful mainly for debugging purposes.
Function: getrand
Class: basic
Section: programming/specific
C-Name: getrand
Prototype:
Help: getrand(): current value of random number seed.
Doc: returns the current value of the seed used by the
pseudo-random number generator \tet{random}. Useful mainly for debugging
purposes, to reproduce a specific chain of computations. The returned value
is technical (reproduces an internal state array), and can only be used as an
argument to \tet{setrand}.
Function: getstack
Class: basic
Section: programming/specific
C-Name: getstack
Prototype: l
Help: getstack(): current value of stack pointer avma.
Doc: returns the current value of $\kbd{top}-\kbd{avma}$, i.e.~the number of
bytes used up to now on the stack. Useful mainly for debugging purposes.
Function: gettime
Class: basic
Section: programming/specific
C-Name: gettime
Prototype: l
Help: gettime(): time (in milliseconds) since last call to gettime.
Doc: returns the CPU time (in milliseconds) used since either the last call to
\kbd{gettime}, or to the beginning of the containing GP instruction (if
inside \kbd{gp}), whichever came last.
For a reentrant version, see \tet{getabstime}.
For a version giving wall-clock time, see \tet{getwalltime}.
Function: getwalltime
Class: basic
Section: programming/specific
C-Name: getwalltime
Prototype:
Help: getwalltime(): time (in milliseconds) since the UNIX Epoch.
Doc: returns the time (in milliseconds) elapsed since the UNIX Epoch
(1970-01-01 00:00:00 (UTC)).
\bprog
my (t = getwalltime());
...
print("Time: ", getwalltime() - t);
@eprog
Function: global
Class: basic
Section: programming/specific
Help: global(list of variables): obsolete. Scheduled for deletion.
Doc: obsolete. Scheduled for deletion.
% \syn{NO}
Obsolete: 2007-10-03
Function: hammingweight
Class: basic
Section: conversions
C-Name: hammingweight
Prototype: lG
Help: hammingweight(x): returns the Hamming weight of x.
Doc:
If $x$ is a \typ{INT}, return the binary Hamming weight of $|x|$. Otherwise
$x$ must be of type \typ{POL}, \typ{VEC}, \typ{COL}, \typ{VECSMALL}, or
\typ{MAT} and the function returns the number of non-zero coefficients of
$x$.
\bprog
? hammingweight(15)
%1 = 4
? hammingweight(x^100 + 2*x + 1)
%2 = 3
? hammingweight([Mod(1,2), 2, Mod(0,3)])
%3 = 2
? hammingweight(matid(100))
%4 = 100
@eprog
Function: hilbert
Class: basic
Section: number_theoretical
C-Name: hilbert
Prototype: lGGDG
Help: hilbert(x,y,{p}): Hilbert symbol at p of x,y.
Doc: \idx{Hilbert symbol} of $x$ and $y$ modulo the prime $p$, $p=0$ meaning
the place at infinity (the result is undefined if $p\neq 0$ is not prime).
It is possible to omit $p$, in which case we take $p = 0$ if both $x$
and $y$ are rational, or one of them is a real number. And take $p = q$
if one of $x$, $y$ is a \typ{INTMOD} modulo $q$ or a $q$-adic. (Incompatible
types will raise an error.)
Function: hyperellcharpoly
Class: basic
Section: elliptic_curves
C-Name: hyperellcharpoly
Prototype: G
Help: hyperellcharpoly(X): X being a non-singular hyperelliptic curve defined
over a finite field, return the characteristic polynomial of the Frobenius
automorphism. X can be given either by a squarefree polynomial P such that
X:y^2=P(x) or by a vector [P,Q] such that X:y^2+Q(x)*y=P(x) and Q^2+4P is
squarefree.
Doc:
$X$ being a non-singular hyperelliptic curve defined over a finite field,
return the characteristic polynomial of the Frobenius automorphism.
$X$ can be given either by a squarefree polynomial $P$ such that
$X: y^2 = P(x)$ or by a vector $[P,Q]$ such that
$X: y^2 + Q(x)\*y = P(x)$ and $Q^2+4\*P$ is squarefree.
Function: hyperellpadicfrobenius
Class: basic
Section: elliptic_curves
C-Name: hyperellpadicfrobenius
Prototype: GUL
Help: hyperellpadicfrobenius(Q,p,n): Q being a rational polynomial of degree
d and X being the curve defined by y^2=Q(x), return the matrix of the
Frobenius at p>=d in the standard basis of H^1_dR(X) to absolute p-adic
precision p^n.
Doc:
Let $X$ be the curve defined by $y^2=Q(x)$, where $Q$ is a polynomial of
degree $d$ over $\Q$ and $p\ge d$ a prime such that $X$ has good reduction
at $p$ return the matrix of the Frobenius endomorphism $\varphi$ on the
crystalline module $D_p(X) = \Q_p \otimes H^1_{dR}(X/\Q)$ with respect to the
basis of the given model $(\omega, x\*\omega,\ldots,x^{g-1}\*\omega)$, where
$\omega = dx/(2\*y)$ is the invariant differential, where $g$ is the genus of
$X$ (either $d=2\*g+1$ or $d=2\*g+2$). The characteristic polynomial of
$\varphi$ is the numerator of the zeta-function of the reduction of the curve
$X$ modulo $p$. The matrix is computed to absolute $p$-adic precision $p^n$.
Function: hyperu
Class: basic
Section: transcendental
C-Name: hyperu
Prototype: GGGp
Help: hyperu(a,b,x): U-confluent hypergeometric function.
Doc: $U$-confluent hypergeometric function with
parameters $a$ and $b$. The parameters $a$ and $b$ can be complex but
the present implementation requires $x$ to be positive.
Function: idealadd
Class: basic
Section: number_fields
C-Name: idealadd
Prototype: GGG
Help: idealadd(nf,x,y): sum of two ideals x and y in the number field
defined by nf.
Doc: sum of the two ideals $x$ and $y$ in the number field $\var{nf}$. The
result is given in HNF.
\bprog
? K = nfinit(x^2 + 1);
? a = idealadd(K, 2, x + 1) \\ ideal generated by 2 and 1+I
%2 =
[2 1]
[0 1]
? pr = idealprimedec(K, 5)[1]; \\ a prime ideal above 5
? idealadd(K, a, pr) \\ coprime, as expected
%4 =
[1 0]
[0 1]
@eprog\noindent
This function cannot be used to add arbitrary $\Z$-modules, since it assumes
that its arguments are ideals:
\bprog
? b = Mat([1,0]~);
? idealadd(K, b, b) \\ only square t_MATs represent ideals
*** idealadd: non-square t_MAT in idealtyp.
? c = [2, 0; 2, 0]; idealadd(K, c, c) \\ non-sense
%6 =
[2 0]
[0 2]
? d = [1, 0; 0, 2]; idealadd(K, d, d) \\ non-sense
%7 =
[1 0]
[0 1]
@eprog\noindent In the last two examples, we get wrong results since the
matrices $c$ and $d$ do not correspond to an ideal: the $\Z$-span of their
columns (as usual interpreted as coordinates with respect to the integer basis
\kbd{K.zk}) is not an $O_K$-module. To add arbitrary $\Z$-modules generated
by the columns of matrices $A$ and $B$, use \kbd{mathnf(concat(A,B))}.
Function: idealaddtoone
Class: basic
Section: number_fields
C-Name: idealaddtoone0
Prototype: GGDG
Help: idealaddtoone(nf,x,{y}): if y is omitted, when the sum of the ideals
in the number field K defined by nf and given in the vector x is equal to
Z_K, gives a vector of elements of the corresponding ideals who sum to 1.
Otherwise, x and y are ideals, and if they sum up to 1, find one element in
each of them such that the sum is 1.
Doc: $x$ and $y$ being two co-prime
integral ideals (given in any form), this gives a two-component row vector
$[a,b]$ such that $a\in x$, $b\in y$ and $a+b=1$.
The alternative syntax $\kbd{idealaddtoone}(\var{nf},v)$, is supported, where
$v$ is a $k$-component vector of ideals (given in any form) which sum to
$\Z_K$. This outputs a $k$-component vector $e$ such that $e[i]\in x[i]$ for
$1\le i\le k$ and $\sum_{1\le i\le k}e[i]=1$.
Function: idealappr
Class: basic
Section: number_fields
C-Name: idealappr0
Prototype: GGD0,L,
Help: idealappr(nf,x,{flag}): x being a fractional ideal, gives an element
b such that v_p(b)=v_p(x) for all prime ideals p dividing x, and v_p(b)>=0
for all other p; x may also be a prime ideal factorization with possibly
zero exponents. flag is deprecated (ignored), kept for backward compatibility
Doc: if $x$ is a fractional ideal
(given in any form), gives an element $\alpha$ in $\var{nf}$ such that for
all prime ideals $\goth{p}$ such that the valuation of $x$ at $\goth{p}$ is
non-zero, we have $v_{\goth{p}}(\alpha)=v_{\goth{p}}(x)$, and
$v_{\goth{p}}(\alpha)\ge0$ for all other $\goth{p}$.
The argument $x$ may also be given as a prime ideal factorization, as
output by \kbd{idealfactor}, but allowing zero exponents.
This yields an element $\alpha$ such that for all prime ideals $\goth{p}$
occurring in $x$, $v_{\goth{p}}(\alpha) = v_{\goth{p}}(x)$;
for all other prime ideals, $v_{\goth{p}}(\alpha)\ge0$.
flag is deprecated (ignored), kept for backward compatibility
Variant: Use directly \fun{GEN}{idealappr}{GEN nf, GEN x} since \fl is ignored.
Function: idealchinese
Class: basic
Section: number_fields
C-Name: idealchinese
Prototype: GGDG
Help: idealchinese(nf,x,{y}): x being a prime ideal factorization and y a
vector of elements, gives an element b such that v_p(b-y_p)>=v_p(x) for all
prime ideals p dividing x, and v_p(b)>=0 for all other p. If y is omitted,
return a data structure which can be used in place of x in later calls.
Doc: $x$ being a prime ideal factorization
(i.e.~a 2 by 2 matrix whose first column contains prime ideals, and the second
column integral exponents), $y$ a vector of elements in $\var{nf}$ indexed by
the ideals in $x$, computes an element $b$ such that
$v_{\goth{p}}(b - y_{\goth{p}}) \geq v_{\goth{p}}(x)$ for all prime ideals
in $x$ and $v_{\goth{p}}(b)\geq 0$ for all other $\goth{p}$.
\bprog
? K = nfinit(t^2-2);
? x = idealfactor(K, 2^2*3)
%2 =
[[2, [0, 1]~, 2, 1, [0, 2; 1, 0]] 4]
[ [3, [3, 0]~, 1, 2, 1] 1]
? y = [t,1];
? idealchinese(K, x, y)
%4 = [4, -3]~
@eprog
The argument $x$ may also be of the form $[x, s]$ where the first component
is as above and $s$ is a vector of signs, with $r_1$ components
$s_i$ in $\{-1,0,1\}$:
if $\sigma_i$ denotes the $i$-th real embedding of the number field,
the element $b$ returned satisfies further
$s_i \kbd{sign}(\sigma_i(b)) \geq 0$ for all $i$. In other words, the sign is
fixed to $s_i$ at the $i$-th embedding whenever $s_i$ is non-zero.
\bprog
? idealchinese(K, [x, [1,1]], y)
%5 = [16, -3]~
? idealchinese(K, [x, [-1,-1]], y)
%6 = [-20, -3]~
? idealchinese(K, [x, [1,-1]], y)
%7 = [4, -3]~
@eprog
If $y$ is omitted, return a data structure which can be used in
place of $x$ in later calls and allows to solve many chinese remainder
problems for a given $x$ more efficiently.
\bprog
? C = idealchinese(K, [x, [1,1]]);
? idealchinese(K, C, y) \\ as above
%9 = [16, -3]~
? for(i=1,10^4, idealchinese(K,C,y)) \\ ... but faster !
time = 80 ms.
? for(i=1,10^4, idealchinese(K,[x,[1,1]],y))
time = 224 ms.
@eprog
Finally, this structure is itself allowed in place of $x$, the
new $s$ overriding the one already present in the structure. This allows to
initialize for different sign conditions more efficiently when the underlying
ideal factorization remains the same.
\bprog
? D = idealchinese(K, [C, [1,-1]]); \\ replaces [1,1]
? idealchinese(K, D, y)
%13 = [4, -3]~
? for(i=1,10^4,idealchinese(K,[C,[1,-1]]))
time = 40 ms. \\ faster than starting from scratch
? for(i=1,10^4,idealchinese(K,[x,[1,-1]]))
time = 128 ms.
@eprog
Variant: Also available is
\fun{GEN}{idealchineseinit}{GEN nf, GEN x} when $y = \kbd{NULL}$.
Function: idealcoprime
Class: basic
Section: number_fields
C-Name: idealcoprime
Prototype: GGG
Help: idealcoprime(nf,x,y): gives an element b in nf such that b. x is an
integral ideal coprime to the integral ideal y.
Doc: given two integral ideals $x$ and $y$
in the number field $\var{nf}$, returns a $\beta$ in the field,
such that $\beta\cdot x$ is an integral ideal coprime to $y$.
Function: idealdiv
Class: basic
Section: number_fields
C-Name: idealdiv0
Prototype: GGGD0,L,
Help: idealdiv(nf,x,y,{flag=0}): quotient x/y of two ideals x and y in HNF
in the number field nf. If (optional) flag is non-null, the quotient is
supposed to be an integral ideal (slightly faster).
Description:
(gen, gen, gen, ?0):gen idealdiv($1, $2, $3)
(gen, gen, gen, 1):gen idealdivexact($1, $2, $3)
(gen, gen, gen, #small):gen $"invalid flag in idealdiv"
(gen, gen, gen, small):gen idealdiv0($1, $2, $3, $4)
Doc: quotient $x\cdot y^{-1}$ of the two ideals $x$ and $y$ in the number
field $\var{nf}$. The result is given in HNF.
If $\fl$ is non-zero, the quotient $x \cdot y^{-1}$ is assumed to be an
integral ideal. This can be much faster when the norm of the quotient is
small even though the norms of $x$ and $y$ are large.
Variant: Also available are \fun{GEN}{idealdiv}{GEN nf, GEN x, GEN y}
($\fl=0$) and \fun{GEN}{idealdivexact}{GEN nf, GEN x, GEN y} ($\fl=1$).
Function: idealfactor
Class: basic
Section: number_fields
C-Name: idealfactor
Prototype: GG
Help: idealfactor(nf,x): factorization of the ideal x into prime ideals in the
number field nf.
Doc: factors into prime ideal powers the
ideal $x$ in the number field $\var{nf}$. The output format is similar to the
\kbd{factor} function, and the prime ideals are represented in the form
output by the \kbd{idealprimedec} function.
Function: idealfactorback
Class: basic
Section: number_fields
C-Name: idealfactorback
Prototype: GGDGD0,L,
Help: idealfactorback(nf,f,{e},{flag = 0}): given a factorisation f, gives the
ideal product back. If e is present, f has to be a
vector of the same length, and we return the product of the f[i]^e[i]. If
flag is non-zero, perform idealred along the way.
Doc: gives back the ideal corresponding to a factorization. The integer $1$
corresponds to the empty factorization.
If $e$ is present, $e$ and $f$ must be vectors of the same length ($e$ being
integral), and the corresponding factorization is the product of the
$f[i]^{e[i]}$.
If not, and $f$ is vector, it is understood as in the preceding case with $e$
a vector of 1s: we return the product of the $f[i]$. Finally, $f$ can be a
regular factorization, as produced by \kbd{idealfactor}.
\bprog
? nf = nfinit(y^2+1); idealfactor(nf, 4 + 2*y)
%1 =
[[2, [1, 1]~, 2, 1, [1, 1]~] 2]
[[5, [2, 1]~, 1, 1, [-2, 1]~] 1]
? idealfactorback(nf, %)
%2 =
[10 4]
[0 2]
? f = %1[,1]; e = %1[,2]; idealfactorback(nf, f, e)
%3 =
[10 4]
[0 2]
? % == idealhnf(nf, 4 + 2*y)
%4 = 1
@eprog
If \kbd{flag} is non-zero, perform ideal reductions (\tet{idealred}) along the
way. This is most useful if the ideals involved are all \emph{extended}
ideals (for instance with trivial principal part), so that the principal parts
extracted by \kbd{idealred} are not lost. Here is an example:
\bprog
? f = vector(#f, i, [f[i], [;]]); \\ transform to extended ideals
? idealfactorback(nf, f, e, 1)
%6 = [[1, 0; 0, 1], [2, 1; [2, 1]~, 1]]
? nffactorback(nf, %[2])
%7 = [4, 2]~
@eprog
The extended ideal returned in \kbd{\%6} is the trivial ideal $1$, extended
with a principal generator given in factored form. We use \tet{nffactorback}
to recover it in standard form.
Function: idealfrobenius
Class: basic
Section: number_fields
C-Name: idealfrobenius
Prototype: GGG
Help: idealfrobenius(nf,gal,pr): returns the Frobenius element (pr|nf/Q)
attached to the unramified prime ideal pr in prid format, in the Galois
group gal of the number field nf.
Doc: Let $K$ be the number field defined by $nf$ and assume $K/\Q$ be a
Galois extension with Galois group given \kbd{gal=galoisinit(nf)},
and that \var{pr} is an unramified prime ideal $\goth{p}$ in \kbd{prid}
format.
This function returns a permutation of \kbd{gal.group} which defines
the Frobenius element $\Frob_{\goth{p}}$ attached to $\goth{p}$.
If $p$ is the unique prime number in $\goth{p}$, then
$\Frob(x)\equiv x^p\mod\goth{p}$ for all $x\in\Z_K$.
\bprog
? nf = nfinit(polcyclo(31));
? gal = galoisinit(nf);
? pr = idealprimedec(nf,101)[1];
? g = idealfrobenius(nf,gal,pr);
? galoispermtopol(gal,g)
%5 = x^8
@eprog\noindent This is correct since $101\equiv 8\mod{31}$.
Function: idealhnf
Class: basic
Section: number_fields
C-Name: idealhnf0
Prototype: GGDG
Help: idealhnf(nf,u,{v}): hermite normal form of the ideal u in the number
field nf if v is omitted. If called as idealhnf(nf,u,v), the ideal
is given as uZ_K + vZ_K in the number field K defined by nf.
Doc: gives the \idx{Hermite normal form} of the ideal $u\Z_K+v\Z_K$, where $u$
and $v$ are elements of the number field $K$ defined by \var{nf}.
\bprog
? nf = nfinit(y^3 - 2);
? idealhnf(nf, 2, y+1)
%2 =
[1 0 0]
[0 1 0]
[0 0 1]
? idealhnf(nf, y/2, [0,0,1/3]~)
%3 =
[1/3 0 0]
[0 1/6 0]
[0 0 1/6]
@eprog
If $b$ is omitted, returns the HNF of the ideal defined by $u$: $u$ may be an
algebraic number (defining a principal ideal), a maximal ideal (as given by
\kbd{idealprimedec} or \kbd{idealfactor}), or a matrix whose columns give
generators for the ideal. This last format is a little complicated, but
useful to reduce general modules to the canonical form once in a while:
\item if strictly less than $N = [K:\Q]$ generators are given, $u$
is the $\Z_K$-module they generate,
\item if $N$ or more are given, it is \emph{assumed} that they form a
$\Z$-basis of the ideal, in particular that the matrix has maximal rank $N$.
This acts as \kbd{mathnf} since the $\Z_K$-module structure is (taken for
granted hence) not taken into account in this case.
\bprog
? idealhnf(nf, idealprimedec(nf,2)[1])
%4 =
[2 0 0]
[0 1 0]
[0 0 1]
? idealhnf(nf, [1,2;2,3;3,4])
%5 =
[1 0 0]
[0 1 0]
[0 0 1]
@eprog\noindent Finally, when $K$ is quadratic with discriminant $D_K$, we
allow $u =$ \kbd{Qfb(a,b,c)}, provided $b^2 - 4ac = D_K$. As usual,
this represents the ideal $a \Z + (1/2)(-b + \sqrt{D_K}) \Z$.
\bprog
? K = nfinit(x^2 - 60); K.disc
%1 = 60
? idealhnf(K, qfbprimeform(60,2))
%2 =
[2 1]
[0 1]
? idealhnf(K, Qfb(1,2,3))
*** at top-level: idealhnf(K,Qfb(1,2,3
*** ^--------------------
*** idealhnf: Qfb(1, 2, 3) has discriminant != 60 in idealhnf.
@eprog
Variant: Also available is \fun{GEN}{idealhnf}{GEN nf, GEN a}.
Function: idealintersect
Class: basic
Section: number_fields
C-Name: idealintersect
Prototype: GGG
Help: idealintersect(nf,A,B): intersection of two ideals A and B in the
number field defined by nf.
Doc: intersection of the two ideals
$A$ and $B$ in the number field $\var{nf}$. The result is given in HNF.
\bprog
? nf = nfinit(x^2+1);
? idealintersect(nf, 2, x+1)
%2 =
[2 0]
[0 2]
@eprog
This function does not apply to general $\Z$-modules, e.g.~orders, since its
arguments are replaced by the ideals they generate. The following script
intersects $\Z$-modules $A$ and $B$ given by matrices of compatible
dimensions with integer coefficients:
\bprog
ZM_intersect(A,B) =
{ my(Ker = matkerint(concat(A,B)));
mathnf( A * Ker[1..#A,] )
}
@eprog
Function: idealinv
Class: basic
Section: number_fields
C-Name: idealinv
Prototype: GG
Help: idealinv(nf,x): inverse of the ideal x in the number field nf.
Description:
(gen, gen):gen idealinv($1, $2)
Doc: inverse of the ideal $x$ in the
number field $\var{nf}$, given in HNF. If $x$ is an extended
ideal\sidx{ideal (extended)}, its principal part is suitably
updated: i.e. inverting $[I,t]$, yields $[I^{-1}, 1/t]$.
Function: ideallist
Class: basic
Section: number_fields
C-Name: ideallist0
Prototype: GLD4,L,
Help: ideallist(nf,bound,{flag=4}): vector of vectors L of all idealstar of
all ideals of norm<=bound. If (optional) flag is present, its binary digits
are toggles meaning 1: give generators; 2: add units; 4: give only the
ideals and not the bid.
Doc: computes the list
of all ideals of norm less or equal to \var{bound} in the number field
\var{nf}. The result is a row vector with exactly \var{bound} components.
Each component is itself a row vector containing the information about
ideals of a given norm, in no specific order, depending on the value of
$\fl$:
The possible values of $\fl$ are:
\quad 0: give the \var{bid} attached to the ideals, without generators.
\quad 1: as 0, but include the generators in the \var{bid}.
\quad 2: in this case, \var{nf} must be a \var{bnf} with units. Each
component is of the form $[\var{bid},U]$, where \var{bid} is as case 0
and $U$ is a vector of discrete logarithms of the units. More precisely, it
gives the \kbd{ideallog}s with respect to \var{bid} of \kbd{bnf.tufu}.
This structure is technical, and only meant to be used in conjunction with
\tet{bnrclassnolist} or \tet{bnrdisclist}.
\quad 3: as 2, but include the generators in the \var{bid}.
\quad 4: give only the HNF of the ideal.
\bprog
? nf = nfinit(x^2+1);
? L = ideallist(nf, 100);
? L[1]
%3 = [[1, 0; 0, 1]] \\@com A single ideal of norm 1
? #L[65]
%4 = 4 \\@com There are 4 ideals of norm 4 in $\Z[i]$
@eprog
If one wants more information, one could do instead:
\bprog
? nf = nfinit(x^2+1);
? L = ideallist(nf, 100, 0);
? l = L[25]; vector(#l, i, l[i].clgp)
%3 = [[20, [20]], [16, [4, 4]], [20, [20]]]
? l[1].mod
%4 = [[25, 18; 0, 1], []]
? l[2].mod
%5 = [[5, 0; 0, 5], []]
? l[3].mod
%6 = [[25, 7; 0, 1], []]
@eprog\noindent where we ask for the structures of the $(\Z[i]/I)^*$ for all
three ideals of norm $25$. In fact, for all moduli with finite part of norm
$25$ and trivial Archimedean part, as the last 3 commands show. See
\tet{ideallistarch} to treat general moduli.
Function: ideallistarch
Class: basic
Section: number_fields
C-Name: ideallistarch
Prototype: GGG
Help: ideallistarch(nf,list,arch): list is a vector of vectors of bid's as
output by ideallist. Return a vector of vectors with the same number of
components as the original list. The leaves give information about
moduli whose finite part is as in original list, in the same order, and
Archimedean part is now arch. The information contained is of the same kind
as was present in the input.
Doc:
\var{list} is a vector of vectors of bid's, as output by \tet{ideallist} with
flag $0$ to $3$. Return a vector of vectors with the same number of
components as the original \var{list}. The leaves give information about
moduli whose finite part is as in original list, in the same order, and
Archimedean part is now \var{arch} (it was originally trivial). The
information contained is of the same kind as was present in the input; see
\tet{ideallist}, in particular the meaning of \fl.
\bprog
? bnf = bnfinit(x^2-2);
? bnf.sign
%2 = [2, 0] \\@com two places at infinity
? L = ideallist(bnf, 100, 0);
? l = L[98]; vector(#l, i, l[i].clgp)
%4 = [[42, [42]], [36, [6, 6]], [42, [42]]]
? La = ideallistarch(bnf, L, [1,1]); \\@com add them to the modulus
? l = La[98]; vector(#l, i, l[i].clgp)
%6 = [[168, [42, 2, 2]], [144, [6, 6, 2, 2]], [168, [42, 2, 2]]]
@eprog
Of course, the results above are obvious: adding $t$ places at infinity will
add $t$ copies of $\Z/2\Z$ to $(\Z_K/f)^*$. The following application
is more typical:
\bprog
? L = ideallist(bnf, 100, 2); \\@com units are required now
? La = ideallistarch(bnf, L, [1,1]);
? H = bnrclassnolist(bnf, La);
? H[98];
%4 = [2, 12, 2]
@eprog
Function: ideallog
Class: basic
Section: number_fields
C-Name: ideallog
Prototype: DGGG
Help: ideallog({nf},x,bid): if bid is a big ideal, as given by
idealstar(nf,D,...), gives the vector of exponents on the generators bid.gen
(even if these generators have not been explicitly computed).
Doc: $\var{nf}$ is a number field,
\var{bid} is as output by \kbd{idealstar(nf, D, \dots)} and $x$ a
non-necessarily integral element of \var{nf} which must have valuation
equal to 0 at all prime ideals in the support of $\kbd{D}$. This function
computes the discrete logarithm of $x$ on the generators given in
\kbd{\var{bid}.gen}. In other words, if $g_i$ are these generators, of orders
$d_i$ respectively, the result is a column vector of integers $(x_i)$ such
that $0\le x_i<d_i$ and
$$x \equiv \prod_i g_i^{x_i} \pmod{\ ^*D}\enspace.$$
Note that when the support of \kbd{D} contains places at infinity, this
congruence implies also sign conditions on the attached real embeddings.
See \tet{znlog} for the limitations of the underlying discrete log algorithms.
When \var{nf} is omitted, take it to be the rational number field. In that
case, $x$ must be a \typ{INT} and \var{bid} must have been initialized by
\kbd{idealstar(,N)}.
Variant: Also available is
\fun{GEN}{Zideallog}{GEN bid, GEN x} when \kbd{nf} is \kbd{NULL}.
Function: idealmin
Class: basic
Section: number_fields
C-Name: idealmin
Prototype: GGDG
Help: idealmin(nf,ix,{vdir}): pseudo-minimum of the ideal ix in the direction
vdir in the number field nf.
Doc: \emph{This function is useless and kept for backward compatibility only,
use \kbd{idealred}}. Computes a pseudo-minimum of the ideal $x$ in the
direction \var{vdir} in the number field \var{nf}.
Function: idealmul
Class: basic
Section: number_fields
C-Name: idealmul0
Prototype: GGGD0,L,
Help: idealmul(nf,x,y,{flag=0}): product of the two ideals x and y in the
number field nf. If (optional) flag is non-nul, reduce the result.
Description:
(gen, gen, gen, ?0):gen idealmul($1, $2, $3)
(gen, gen, gen, 1):gen idealmulred($1, $2, $3)
(gen, gen, gen, #small):gen $"invalid flag in idealmul"
(gen, gen, gen, small):gen idealmul0($1, $2, $3, $4)
Doc: ideal multiplication of the ideals $x$ and $y$ in the number field
\var{nf}; the result is the ideal product in HNF. If either $x$ or $y$
are extended ideals\sidx{ideal (extended)}, their principal part is suitably
updated: i.e. multiplying $[I,t]$, $[J,u]$ yields $[IJ, tu]$; multiplying
$I$ and $[J, u]$ yields $[IJ, u]$.
\bprog
? nf = nfinit(x^2 + 1);
? idealmul(nf, 2, x+1)
%2 =
[4 2]
[0 2]
? idealmul(nf, [2, x], x+1) \\ extended ideal * ideal
%3 = [[4, 2; 0, 2], x]
? idealmul(nf, [2, x], [x+1, x]) \\ two extended ideals
%4 = [[4, 2; 0, 2], [-1, 0]~]
@eprog\noindent
If $\fl$ is non-zero, reduce the result using \kbd{idealred}.
Variant:
\noindent See also
\fun{GEN}{idealmul}{GEN nf, GEN x, GEN y} ($\fl=0$) and
\fun{GEN}{idealmulred}{GEN nf, GEN x, GEN y} ($\fl\neq0$).
Function: idealnorm
Class: basic
Section: number_fields
C-Name: idealnorm
Prototype: GG
Help: idealnorm(nf,x): norm of the ideal x in the number field nf.
Doc: computes the norm of the ideal~$x$ in the number field~$\var{nf}$.
Function: idealnumden
Class: basic
Section: number_fields
C-Name: idealnumden
Prototype: GG
Help: idealnumden(nf,x): returns [A,B], where A,B are coprime integer ideals
such that x = A/B.
Doc: returns $[A,B]$, where $A,B$ are coprime integer ideals
such that $x = A/B$, in the number field $\var{nf}$.
\bprog
? nf = nfinit(x^2+1);
? idealnumden(nf, (x+1)/2)
%2 = [[1, 0; 0, 1], [2, 1; 0, 1]]
@eprog
Function: idealpow
Class: basic
Section: number_fields
C-Name: idealpow0
Prototype: GGGD0,L,
Help: idealpow(nf,x,k,{flag=0}): k-th power of the ideal x in HNF in the
number field nf. If (optional) flag is non-null, reduce the result.
Doc: computes the $k$-th power of
the ideal $x$ in the number field $\var{nf}$; $k\in\Z$.
If $x$ is an extended
ideal\sidx{ideal (extended)}, its principal part is suitably
updated: i.e. raising $[I,t]$ to the $k$-th power, yields $[I^k, t^k]$.
If $\fl$ is non-zero, reduce the result using \kbd{idealred}, \emph{throughout
the (binary) powering process}; in particular, this is \emph{not} the same
as $\kbd{idealpow}(\var{nf},x,k)$ followed by reduction.
Variant:
\noindent See also
\fun{GEN}{idealpow}{GEN nf, GEN x, GEN k} and
\fun{GEN}{idealpows}{GEN nf, GEN x, long k} ($\fl = 0$).
Corresponding to $\fl=1$ is \fun{GEN}{idealpowred}{GEN nf, GEN vp, GEN k}.
Function: idealprimedec
Class: basic
Section: number_fields
C-Name: idealprimedec_limit_f
Prototype: GGD0,L,
Help: idealprimedec(nf,p,{f=0}): prime ideal decomposition of the prime number
p in the number field nf as a vector of prime ideals. If f is present
and non-zero, restrict the result to primes of residue degree <= f.
Description:
(gen, gen):vec idealprimedec($1, $2)
(gen, gen, ?small):vec idealprimedec_limit_f($1, $2, $3)
Doc: computes the prime ideal
decomposition of the (positive) prime number $p$ in the number field $K$
represented by \var{nf}. If a non-prime $p$ is given the result is undefined.
If $f$ is present and non-zero, restrict the result to primes of residue
degree $\leq f$.
The result is a vector of \tev{prid} structures, each representing one of the
prime ideals above $p$ in the number field $\var{nf}$. The representation
$\kbd{pr}=[p,a,e,f,\var{mb}]$ of a prime ideal means the following: $a$
is an algebraic integer in the maximal order $\Z_K$ and the prime ideal is
equal to $\goth{p} = p\Z_K + a\Z_K$;
$e$ is the ramification index; $f$ is the residual index;
finally, \var{mb} is the multiplication table attached to the algebraic
integer $b$ is such that $\goth{p}^{-1}=\Z_K+ b/ p\Z_K$, which is used
internally to compute valuations. In other words if $p$ is inert,
then \var{mb} is the integer $1$, and otherwise it is a square \typ{MAT}
whose $j$-th column is $b \cdot \kbd{nf.zk[j]}$.
The algebraic number $a$ is guaranteed to have a
valuation equal to 1 at the prime ideal (this is automatic if $e>1$).
The components of \kbd{pr} should be accessed by member functions: \kbd{pr.p},
\kbd{pr.e}, \kbd{pr.f}, and \kbd{pr.gen} (returns the vector $[p,a]$):
\bprog
? K = nfinit(x^3-2);
? P = idealprimedec(K, 5);
? #P \\ 2 primes above 5 in Q(2^(1/3))
%3 = 2
? [p1,p2] = P;
? [p1.e, p1.f] \\ the first is unramified of degree 1
%5 = [1, 1]
? [p2.e, p2.f] \\ the second is unramified of degree 2
%6 = [1, 2]
? p1.gen
%7 = [5, [2, 1, 0]~]
? nfbasistoalg(K, %[2]) \\ a uniformizer for p1
%8 = Mod(x + 2, x^3 - 2)
? #idealprimedec(K, 5, 1) \\ restrict to f = 1
%9 = 1 \\ now only p1
@eprog
Function: idealprincipalunits
Class: basic
Section: number_fields
C-Name: idealprincipalunits
Prototype: GGL
Help: idealprincipalunits(nf,pr,k): returns the structure [no, cyc, gen]
of the multiplicative group (1 + pr) / (1 + pr^k).
Doc: given a prime ideal in \tet{idealprimedec} format,
returns the multiplicative group $(1 + \var{pr}) / (1 + \var{pr}^k)$ as an
abelian group. This function is much faster than \tet{idealstar} when the
norm of \var{pr} is large, since it avoids (useless) work in the
multiplicative group of the residue field.
\bprog
? K = nfinit(y^2+1);
? P = idealprimedec(K,2)[1];
? G = idealprincipalunits(K, P, 20);
? G.cyc
%4 = [512, 256, 4] \\ Z/512 x Z/256 x Z/4
? G.gen
%5 = [[-1, -2]~, 1021, [0, -1]~] \\ minimal generators of given order
@eprog
Function: idealramgroups
Class: basic
Section: number_fields
C-Name: idealramgroups
Prototype: GGG
Help: idealramgroups(nf,gal,pr): let pr be a prime ideal in prid format, and
gal the Galois group of the number field nf, return a vector g such that g[1]
is the decomposition group of pr, g[2] is the inertia group, g[i] is the
(i-2)th ramification group of pr, all trivial subgroups being omitted.
Doc: Let $K$ be the number field defined by \var{nf} and assume that $K/\Q$ is
Galois with Galois group $G$ given by \kbd{gal=galoisinit(nf)}.
Let \var{pr} be the prime ideal $\goth{P}$ in prid format.
This function returns a vector $g$ of subgroups of \kbd{gal}
as follow:
\item \kbd{g[1]} is the decomposition group of $\goth{P}$,
\item \kbd{g[2]} is $G_0(\goth{P})$, the inertia group of $\goth{P}$,
and for $i\geq 2$,
\item \kbd{g[i]} is $G_{i-2}(\goth{P})$, the $i-2$-th
\idx{ramification group} of $\goth{P}$.
\noindent The length of $g$ is the number of non-trivial groups in the
sequence, thus is $0$ if $e=1$ and $f=1$, and $1$ if $f>1$ and $e=1$.
The following function computes the cardinality of a subgroup of $G$,
as given by the components of $g$:
\bprog
card(H) =my(o=H[2]); prod(i=1,#o,o[i]);
@eprog
\bprog
? nf=nfinit(x^6+3); gal=galoisinit(nf); pr=idealprimedec(nf,3)[1];
? g = idealramgroups(nf, gal, pr);
? apply(card,g)
%3 = [6, 6, 3, 3, 3] \\ cardinalities of the G_i
@eprog
\bprog
? nf=nfinit(x^6+108); gal=galoisinit(nf); pr=idealprimedec(nf,2)[1];
? iso=idealramgroups(nf,gal,pr)[2]
%5 = [[Vecsmall([2, 3, 1, 5, 6, 4])], Vecsmall([3])]
? nfdisc(galoisfixedfield(gal,iso,1))
%6 = -3
@eprog\noindent The field fixed by the inertia group of $2$ is not ramified at
$2$.
Function: idealred
Class: basic
Section: number_fields
C-Name: idealred0
Prototype: GGDG
Help: idealred(nf,I,{v=0}): LLL reduction of the ideal I in the number
field nf along direction v, in HNF.
Doc: \idx{LLL} reduction of
the ideal $I$ in the number field $K$ attached to \var{nf}, along the
direction $v$. The $v$ parameter is best left omitted, but if it is present,
it must be an $\kbd{nf.r1} + \kbd{nf.r2}$-component vector of
\emph{non-negative} integers. (What counts is the relative magnitude of the
entries: if all entries are equal, the effect is the same as if the vector
had been omitted.)
This function finds an $a\in K^*$ such that $J = (a)I$ is
``small'' and integral (see the end for technical details).
The result is the Hermite normal form of
the ``reduced'' ideal $J$.
\bprog
? K = nfinit(y^2+1);
? P = idealprimedec(K,5)[1];
? idealred(K, P)
%3 =
[1 0]
[0 1]
@eprog\noindent More often than not, a \idx{principal ideal} yields the unit
ideal as above. This is a quick and dirty way to check if ideals are principal,
but it is not a necessary condition: a non-trivial result does not prove that
the ideal is non-principal. For guaranteed results, see \kbd{bnfisprincipal},
which requires the computation of a full \kbd{bnf} structure.
If the input is an extended ideal $[I,s]$, the output is $[J, sa]$; in
this way, one keeps track of the principal ideal part:
\bprog
? idealred(K, [P, 1])
%5 = [[1, 0; 0, 1], [2, -1]~]
@eprog\noindent
meaning that $P$ is generated by $[2, -1]~$. The number field element in the
extended part is an algebraic number in any form \emph{or} a factorization
matrix (in terms of number field elements, not ideals!). In the latter case,
elements stay in factored form, which is a convenient way to avoid
coefficient explosion; see also \tet{idealpow}.
\misctitle{Technical note} The routine computes an LLL-reduced
basis for the lattice $I^(-1)$ equipped with the quadratic
form
$$|| x ||_v^2 = \sum_{i=1}^{r_1+r_2} 2^{v_i}\varepsilon_i|\sigma_i(x)|^2,$$
where as usual the $\sigma_i$ are the (real and) complex embeddings and
$\varepsilon_i = 1$, resp.~$2$, for a real, resp.~complex place. The element
$a$ is simply the first vector in the LLL basis. The only reason you may want
to try to change some directions and set some $v_i\neq 0$ is to randomize
the elements found for a fixed ideal, which is heuristically useful in index
calculus algorithms like \tet{bnfinit} and \tet{bnfisprincipal}.
\misctitle{Even more technical note} In fact, the above is a white lie.
We do not use $||\cdot||_v$ exactly but a rescaled rounded variant which
gets us faster and simpler LLLs. There's no harm since we are not using any
theoretical property of $a$ after all, except that it belongs to $I^(-1)$
and that $a I$ is ``expected to be small''.
Function: idealstar
Class: basic
Section: number_fields
C-Name: idealstar0
Prototype: DGGD1,L,
Help: idealstar({nf},N,{flag=1}): gives the structure of (Z_K/N)^*, where N is
a modulus (an ideal in any form or a vector [f0, foo], where f0 is an ideal
and foo is a {0,1}-vector with r1 components. flag is
optional, and can be 0: simply gives the structure as an abelian group, i.e.
a 3-component vector [h,d,g] where h is the order, d the orders of the cyclic
factors and g the generators;
if flag=1 (default), gives a bid structure used in ideallog
to compute discrete logarithms; underlying generators are well-defined but not
explicitly computed, which saves time; if flag=2, same as with flag=1 except
that the generators are also given.
If nf is omitted, N must be an integer and
we return the structure of (Z/NZ)^*.
Doc: outputs a \kbd{bid} structure,
necessary for computing in the finite abelian group $G = (\Z_K/N)^*$. Here,
\var{nf} is a number field and $N$ is a \var{modulus}: either an ideal in any
form, or a row vector whose first component is an ideal and whose second
component is a row vector of $r_1$ 0 or 1. Ideals can also be given
by a factorization into prime ideals, as produced by \tet{idealfactor}.
This \var{bid} is used in \tet{ideallog} to compute discrete logarithms. It
also contains useful information which can be conveniently retrieved as
\kbd{\var{bid}.mod} (the modulus),
\kbd{\var{bid}.clgp} ($G$ as a finite abelian group),
\kbd{\var{bid}.no} (the cardinality of $G$),
\kbd{\var{bid}.cyc} (elementary divisors) and
\kbd{\var{bid}.gen} (generators).
If $\fl=1$ (default), the result is a \kbd{bid} structure without
generators: they are well defined but not explicitly computed, which saves
time.
If $\fl=2$, as $\fl=1$, but including generators.
If $\fl=0$, only outputs $(\Z_K/N)^*$ as an abelian group,
i.e as a 3-component vector $[h,d,g]$: $h$ is the order, $d$ is the vector of
SNF\sidx{Smith normal form} cyclic components and $g$ the corresponding
generators.
If \var{nf} is omitted, we take it to be the rational number fields, $N$ must
be an integer and we return the structure of $(\Z/N\Z)^*$. In other words
\kbd{idealstar(, N, flag)} is short for
\bprog
idealstar(nfinit(x), N, flag)
@eprog\noindent but much faster. The alternative syntax \kbd{znstar(N, flag)}
is also available for the same effect, but due to an unfortunate historical
oversight, the default value of \kbd{flag} is different in the two
functions (\kbd{znstar} does not initialize by default).
Variant: Instead the above hardcoded numerical flags, one should rather use
\fun{GEN}{Idealstar}{GEN nf, GEN ideal, long flag}, where \kbd{flag} is
an or-ed combination of \tet{nf_GEN} (include generators) and \tet{nf_INIT}
(return a full \kbd{bid}, not a group), possibly $0$. This offers
one more combination: gen, but no init.
Function: idealtwoelt
Class: basic
Section: number_fields
C-Name: idealtwoelt0
Prototype: GGDG
Help: idealtwoelt(nf,x,{a}): two-element representation of an ideal x in the
number field nf. If (optional) a is non-zero, first element will be equal to a.
Doc: computes a two-element
representation of the ideal $x$ in the number field $\var{nf}$, combining a
random search and an approximation theorem; $x$ is an ideal
in any form (possibly an extended ideal, whose principal part is ignored)
\item When called as \kbd{idealtwoelt(nf,x)}, the result is a row vector
$[a,\alpha]$ with two components such that $x=a\Z_K+\alpha\Z_K$ and $a$ is
chosen to be the positive generator of $x\cap\Z$, unless $x$ was given as a
principal ideal (in which case we may choose $a = 0$). The algorithm
uses a fast lazy factorization of $x\cap \Z$ and runs in randomized
polynomial time.
\item When called as \kbd{idealtwoelt(nf,x,a)} with an explicit non-zero $a$
supplied as third argument, the function assumes that $a \in x$ and returns
$\alpha\in x$ such that $x = a\Z_K + \alpha\Z_K$. Note that we must factor
$a$ in this case, and the algorithm is generally much slower than the
default variant.
Variant: Also available are
\fun{GEN}{idealtwoelt}{GEN nf, GEN x} and
\fun{GEN}{idealtwoelt2}{GEN nf, GEN x, GEN a}.
Function: idealval
Class: basic
Section: number_fields
C-Name: gpidealval
Prototype: GGG
Help: idealval(nf,x,pr): valuation at pr given in idealprimedec format of the
ideal x in the number field nf.
Doc: gives the valuation of the ideal $x$ at the prime ideal \var{pr} in the
number field $\var{nf}$, where \var{pr} is in \kbd{idealprimedec} format.
The valuation of the $0$ ideal is \kbd{+oo}.
Variant: Also available is
\fun{long}{idealval}{GEN nf, GEN x, GEN pr}, which returns
\tet{LONG_MAX} if $x = 0$ and the valuation as a \kbd{long} integer.
Function: if
Class: basic
Section: programming/control
C-Name: ifpari
Prototype: GDEDE
Help: if(a,{seq1},{seq2}): if a is nonzero, seq1 is evaluated, otherwise seq2.
seq1 and seq2 are optional, and if seq2 is omitted, the preceding comma can
be omitted also.
Doc: evaluates the expression sequence \var{seq1} if $a$ is non-zero, otherwise
the expression \var{seq2}. Of course, \var{seq1} or \var{seq2} may be empty:
\kbd{if ($a$,\var{seq})} evaluates \var{seq} if $a$ is not equal to zero
(you don't have to write the second comma), and does nothing otherwise,
\kbd{if ($a$,,\var{seq})} evaluates \var{seq} if $a$ is equal to zero, and
does nothing otherwise. You could get the same result using the \kbd{!}
(\kbd{not}) operator: \kbd{if (!$a$,\var{seq})}.
The value of an \kbd{if} statement is the value of the branch that gets
evaluated: for instance
\bprog
x = if(n % 4 == 1, y, z);
@eprog\noindent sets $x$ to $y$ if $n$ is $1$ modulo $4$, and to $z$
otherwise.
Successive 'else' blocks can be abbreviated in a single compound \kbd{if}
as follows:
\bprog
if (test1, seq1,
test2, seq2,
...
testn, seqn,
seqdefault);
@eprog\noindent is equivalent to
\bprog
if (test1, seq1
, if (test2, seq2
, ...
if (testn, seqn, seqdefault)...));
@eprog For instance, this allows to write traditional switch / case
constructions:
\bprog
if (x == 0, do0(),
x == 1, do1(),
x == 2, do2(),
dodefault());
@eprog
\misctitle{Remark}
The boolean operators \kbd{\&\&} and \kbd{||} are evaluated
according to operator precedence as explained in \secref{se:operators}, but,
contrary to other operators, the evaluation of the arguments is stopped
as soon as the final truth value has been determined. For instance
\bprog
if (x != 0 && f(1/x), ...)
@eprog
\noindent is a perfectly safe statement.
\misctitle{Remark} Functions such as \kbd{break} and \kbd{next} operate on
\emph{loops}, such as \kbd{for$xxx$}, \kbd{while}, \kbd{until}. The \kbd{if}
statement is \emph{not} a loop. (Obviously!)
Function: iferr
Class: basic
Section: programming/control
C-Name: iferrpari
Prototype: EVEDE
Help: iferr(seq1,E,seq2,{pred}): evaluates the expression sequence seq1. If
an error occurs, set the formal parameter E set to the error data.
If pred is not present or evaluates to true, catch the error and evaluate
seq2. Both pred and seq2 can reference E.
Doc: evaluates the expression sequence \var{seq1}. If an error occurs,
set the formal parameter \var{E} set to the error data.
If \var{pred} is not present or evaluates to true, catch the error
and evaluate \var{seq2}. Both \var{pred} and \var{seq2} can reference \var{E}.
The error type is given by \kbd{errname(E)}, and other data can be
accessed using the \tet{component} function. The code \var{seq2} should check
whether the error is the one expected. In the negative the error can be
rethrown using \tet{error(E)} (and possibly caught by an higher \kbd{iferr}
instance). The following uses \kbd{iferr} to implement Lenstra's ECM factoring
method
\bprog
? ecm(N, B = 1000!, nb = 100)=
{
for(a = 1, nb,
iferr(ellmul(ellinit([a,1]*Mod(1,N)), [0,1]*Mod(1,N), B),
E, return(gcd(lift(component(E,2)),N)),
errname(E)=="e_INV" && type(component(E,2)) == "t_INTMOD"))
}
? ecm(2^101-1)
%2 = 7432339208719
@eprog
The return value of \kbd{iferr} itself is the value of \var{seq2} if an
error occurs, and the value of \var{seq1} otherwise. We now describe the
list of valid error types, and the attached error data \var{E}; in each
case, we list in order the components of \var{E}, accessed via
\kbd{component(E,1)}, \kbd{component(E,2)}, etc.
\misctitle{Internal errors, ``system'' errors}
\item \kbd{"e\_ARCH"}. A requested feature $s$ is not available on this
architecture or operating system.
\var{E} has one component (\typ{STR}): the missing feature name $s$.
\item \kbd{"e\_BUG"}. A bug in the PARI library, in function $s$.
\var{E} has one component (\typ{STR}): the function name $s$.
\item \kbd{"e\_FILE"}. Error while trying to open a file.
\var{E} has two components, 1 (\typ{STR}): the file type (input, output,
etc.), 2 (\typ{STR}): the file name.
\item \kbd{"e\_IMPL"}. A requested feature $s$ is not implemented.
\var{E} has one component, 1 (\typ{STR}): the feature name $s$.
\item \kbd{"e\_PACKAGE"}. Missing optional package $s$.
\var{E} has one component, 1 (\typ{STR}): the package name $s$.
\misctitle{Syntax errors, type errors}
\item \kbd{"e\_DIM"}. The dimensions of arguments $x$ and $y$ submitted
to function $s$ does not match up.
E.g., multiplying matrices of inconsistent dimension, adding vectors of
different lengths,\dots
\var{E} has three component, 1 (\typ{STR}): the function name $s$, 2: the
argument $x$, 3: the argument $y$.
\item \kbd{"e\_FLAG"}. A flag argument is out of bounds in function $s$.
\var{E} has one component, 1 (\typ{STR}): the function name $s$.
\item \kbd{"e\_NOTFUNC"}. Generated by the PARI evaluator; tried to use a
\kbd{GEN} $x$ which is not a \typ{CLOSURE} in a function call syntax (as in
\kbd{f = 1; f(2);}).
\var{E} has one component, 1: the offending \kbd{GEN} $x$.
\item \kbd{"e\_OP"}. Impossible operation between two objects than cannot
be typecast to a sensible common domain for deeper reasons than a type
mismatch, usually for arithmetic reasons. As in \kbd{O(2) + O(3)}: it is
valid to add two \typ{PADIC}s, provided the underlying prime is the same; so
the addition is not forbidden a priori for type reasons, it only becomes so
when inspecting the objects and trying to perform the operation.
\var{E} has three components, 1 (\typ{STR}): the operator name \var{op},
2: first argument, 3: second argument.
\item \kbd{"e\_TYPE"}. An argument $x$ of function $s$ had an unexpected type.
(As in \kbd{factor("blah")}.)
\var{E} has two components, 1 (\typ{STR}): the function name $s$,
2: the offending argument $x$.
\item \kbd{"e\_TYPE2"}. Forbidden operation between two objects than cannot be
typecast to a sensible common domain, because their types do not match up.
(As in \kbd{Mod(1,2) + Pi}.)
\var{E} has three components, 1 (\typ{STR}): the operator name \var{op},
2: first argument, 3: second argument.
\item \kbd{"e\_PRIORITY"}. Object $o$ in function $s$ contains
variables whose priority is incompatible with the expected operation.
E.g.~\kbd{Pol([x,1], 'y)}: this raises an error because it's not possible to
create a polynomial whose coefficients involve variables with higher priority
than the main variable. $E$ has four components: 1 (\typ{STR}): the function
name $s$, 2: the offending argument $o$, 3 (\typ{STR}): an operator
$\var{op}$ describing the priority error, 4 (\typ{POL}):
the variable $v$ describing the priority error. The argument
satisfies $\kbd{variable}(x)~\var{op} \kbd{variable}(v)$.
\item \kbd{"e\_VAR"}. The variables of arguments $x$ and $y$ submitted
to function $s$ does not match up. E.g., considering the algebraic number
\kbd{Mod(t,t\pow2+1)} in \kbd{nfinit(x\pow2+1)}.
\var{E} has three component, 1 (\typ{STR}): the function name $s$, 2
(\typ{POL}): the argument $x$, 3 (\typ{POL}): the argument $y$.
\misctitle{Overflows}
\item \kbd{"e\_COMPONENT"}. Trying to access an inexistent component in a
vector/matrix/list in a function: the index is less than $1$ or greater
than the allowed length.
\var{E} has four components,
1 (\typ{STR}): the function name
2 (\typ{STR}): an operator $\var{op}$ ($<$ or $>$),
2 (\typ{GEN}): a numerical limit $l$ bounding the allowed range,
3 (\kbd{GEN}): the index $x$. It satisfies $x$ \var{op} $l$.
\item \kbd{"e\_DOMAIN"}. An argument is not in the function's domain.
\var{E} has five components, 1 (\typ{STR}): the function name,
2 (\typ{STR}): the mathematical name of the out-of-domain argument
3 (\typ{STR}): an operator $\var{op}$ describing the domain error,
4 (\typ{GEN}): the numerical limit $l$ describing the domain error,
5 (\kbd{GEN}): the out-of-domain argument $x$. The argument satisfies $x$
\var{op} $l$, which prevents it from belonging to the function's domain.
\item \kbd{"e\_MAXPRIME"}. A function using the precomputed list of prime
numbers ran out of primes.
\var{E} has one component, 1 (\typ{INT}): the requested prime bound, which
overflowed \kbd{primelimit} or $0$ (bound is unknown).
\item \kbd{"e\_MEM"}. A call to \tet{pari_malloc} or \tet{pari_realloc}
failed. \var{E} has no component.
\item \kbd{"e\_OVERFLOW"}. An object in function $s$ becomes too large to be
represented within PARI's hardcoded limits. (As in \kbd{2\pow2\pow2\pow10} or
\kbd{exp(1e100)}, which overflow in \kbd{lg} and \kbd{expo}.)
\var{E} has one component, 1 (\typ{STR}): the function name $s$.
\item \kbd{"e\_PREC"}. Function $s$ fails because input accuracy is too low.
(As in \kbd{floor(1e100)} at default accuracy.)
\var{E} has one component, 1 (\typ{STR}): the function name $s$.
\item \kbd{"e\_STACK"}. The PARI stack overflows.
\var{E} has no component.
\misctitle{Errors triggered intentionally}
\item \kbd{"e\_ALARM"}. A timeout, generated by the \tet{alarm} function.
\var{E} has one component (\typ{STR}): the error message to print.
\item \kbd{"e\_USER"}. A user error, as triggered by
\tet{error}($g_1,\dots,g_n)$.
\var{E} has one component, 1 (\typ{VEC}): the vector of $n$ arguments given
to \kbd{error}.
\misctitle{Mathematical errors}
\item \kbd{"e\_CONSTPOL"}. An argument of function $s$ is a constant
polynomial, which does not make sense. (As in \kbd{galoisinit(Pol(1))}.)
\var{E} has one component, 1 (\typ{STR}): the function name $s$.
\item \kbd{"e\_COPRIME"}. Function $s$ expected coprime arguments,
and did receive $x,y$, which were not.
\var{E} has three component, 1 (\typ{STR}): the function name $s$,
2: the argument $x$, 3: the argument $y$.
\item \kbd{"e\_INV"}. Tried to invert a non-invertible object $x$ in
function $s$.
\var{E} has two components, 1 (\typ{STR}): the function name $s$,
2: the non-invertible $x$. If $x = \kbd{Mod}(a,b)$
is a \typ{INTMOD} and $a$ is not $0$ mod $b$, this allows to factor
the modulus, as \kbd{gcd}$(a,b)$ is a non-trivial divisor of $b$.
\item \kbd{"e\_IRREDPOL"}. Function $s$ expected an irreducible polynomial,
and did receive $T$, which was not. (As in \kbd{nfinit(x\pow2-1)}.)
\var{E} has two component, 1 (\typ{STR}): the function name $s$,
2 (\typ{POL}): the polynomial $x$.
\item \kbd{"e\_MISC"}. Generic uncategorized error.
\var{E} has one component (\typ{STR}): the error message to print.
\item \kbd{"e\_MODULUS"}. moduli $x$ and $y$ submitted to function $s$ are
inconsistent. As in
\bprog
nfalgtobasis(nfinit(t^3-2), Mod(t,t^2+1)
@eprog\noindent
\var{E} has three component, 1 (\typ{STR}): the function $s$,
2: the argument $x$, 3: the argument $x$.
\item \kbd{"e\_PRIME"}. Function $s$ expected a prime number,
and did receive $p$, which was not. (As in \kbd{idealprimedec(nf, 4)}.)
\var{E} has two component, 1 (\typ{STR}): the function name $s$,
2: the argument $p$.
\item \kbd{"e\_ROOTS0"}. An argument of function $s$ is a zero polynomial,
and we need to consider its roots. (As in \kbd{polroots(0)}.) \var{E} has
one component, 1 (\typ{STR}): the function name $s$.
\item \kbd{"e\_SQRTN"}. Trying to compute an $n$-th root of $x$, which does
not exist, in function $s$. (As in \kbd{sqrt(Mod(-1,3))}.)
\var{E} has two components, 1 (\typ{STR}): the function name $s$,
2: the argument $x$.
Function: imag
Class: basic
Section: conversions
C-Name: gimag
Prototype: G
Help: imag(x): imaginary part of x.
Doc: imaginary part of $x$. When $x$ is a quadratic number, this is the
coefficient of $\omega$ in the ``canonical'' integral basis $(1,\omega)$.
Function: incgam
Class: basic
Section: transcendental
C-Name: incgam0
Prototype: GGDGp
Help: incgam(s,x,{g}): incomplete gamma function. g is optional and is the
precomputed value of gamma(s).
Doc: incomplete gamma function $\int_x^\infty e^{-t}t^{s-1}\,dt$, extended by
analytic continuation to all complex $x, s$ not both $0$. The relative error
is bounded in terms of the precision of $s$ (the accuracy of $x$ is ignored
when determining the output precision). When $g$ is given, assume that
$g=\Gamma(s)$. For small $|x|$, this will speed up the computation.
Variant: Also available is \fun{GEN}{incgam}{GEN s, GEN x, long prec}.
Function: incgamc
Class: basic
Section: transcendental
C-Name: incgamc
Prototype: GGp
Help: incgamc(s,x): complementary incomplete gamma function.
Doc: complementary incomplete gamma function.
The arguments $x$ and $s$ are complex numbers such that $s$ is not a pole of
$\Gamma$ and $|x|/(|s|+1)$ is not much larger than 1 (otherwise the
convergence is very slow). The result returned is $\int_0^x
e^{-t}t^{s-1}\,dt$.
Function: inline
Class: basic
Section: programming/specific
Help: inline(x,...,z): declares x,...,z as inline variables [EXPERIMENTAL].
Doc: (Experimental) declare $x,\ldots, z$ as inline variables. Such variables
behave like lexically scoped variable (see my()) but with unlimited scope.
It is however possible to exit the scope by using \kbd{uninline()}.
When used in a GP script, it is recommended to call \kbd{uninline()} before
the script's end to avoid inline variables leaking outside the script.
Function: input
Class: basic
Section: programming/specific
C-Name: gp_input
Prototype:
Help: input(): read an expression from the input file or standard input.
Doc: reads a string, interpreted as a GP expression,
from the input file, usually standard input (i.e.~the keyboard). If a
sequence of expressions is given, the result is the result of the last
expression of the sequence. When using this instruction, it is useful to
prompt for the string by using the \kbd{print1} function. Note that in the
present version 2.19 of \kbd{pari.el}, when using \kbd{gp} under GNU Emacs (see
\secref{se:emacs}) one \emph{must} prompt for the string, with a string
which ends with the same prompt as any of the previous ones (a \kbd{"? "}
will do for instance).
Function: install
Class: basic
Section: programming/specific
C-Name: gpinstall
Prototype: vrrD"",r,D"",s,
Help: install(name,code,{gpname},{lib}): load from dynamic library 'lib' the
function 'name'. Assign to it the name 'gpname' in this GP session, with
prototype 'code'. If 'lib' is omitted, all symbols known to gp
(includes the whole 'libpari.so' and possibly others) are available.
If 'gpname' is omitted, use 'name'.
Doc: loads from dynamic library \var{lib} the function \var{name}. Assigns to it
the name \var{gpname} in this \kbd{gp} session, with \emph{prototype}
\var{code} (see below). If \var{gpname} is omitted, uses \var{name}.
If \var{lib} is omitted, all symbols known to \kbd{gp} are available: this
includes the whole of \kbd{libpari.so} and possibly others (such as
\kbd{libc.so}).
Most importantly, \kbd{install} gives you access to all non-static functions
defined in the PARI library. For instance, the function
\bprog
GEN addii(GEN x, GEN y)
@eprog\noindent adds two PARI integers, and is not directly accessible under
\kbd{gp} (it is eventually called by the \kbd{+} operator of course):
\bprog
? install("addii", "GG")
? addii(1, 2)
%1 = 3
@eprog\noindent
It also allows to add external functions to the \kbd{gp} interpreter.
For instance, it makes the function \tet{system} obsolete:
\bprog
? install(system, vs, sys,/*omitted*/)
? sys("ls gp*")
gp.c gp.h gp_rl.c
@eprog\noindent This works because \kbd{system} is part of \kbd{libc.so},
which is linked to \kbd{gp}. It is also possible to compile a shared library
yourself and provide it to gp in this way: use \kbd{gp2c}, or do it manually
(see the \kbd{modules\_build} variable in \kbd{pari.cfg} for hints).
Re-installing a function will print a warning and update the prototype code
if needed. However, it will not reload a symbol from the library, even if the
latter has been recompiled.
\misctitle{Prototype} We only give a simplified description here, covering
most functions, but there are many more possibilities. The full documentation
is available in \kbd{libpari.dvi}, see
\bprog
??prototype
@eprog
\item First character \kbd{i}, \kbd{l}, \kbd{v} : return type int / long /
void. (Default: \kbd{GEN})
\item One letter for each mandatory argument, in the same order as they appear
in the argument list: \kbd{G} (\kbd{GEN}), \kbd{\&}
(\kbd{GEN*}), \kbd{L} (\kbd{long}), \kbd{s} (\kbd{char *}), \kbd{n}
(variable).
\item \kbd{p} to supply \kbd{realprecision} (usually \kbd{long prec} in the
argument list), \kbd{P} to supply \kbd{seriesprecision}
(usually \kbd{long precdl}).
\noindent We also have special constructs for optional arguments and default
values:
\item \kbd{DG} (optional \kbd{GEN}, \kbd{NULL} if omitted),
\item \kbd{D\&} (optional \kbd{GEN*}, \kbd{NULL} if omitted),
\item \kbd{Dn} (optional variable, $-1$ if omitted),
For instance the prototype corresponding to
\bprog
long issquareall(GEN x, GEN *n = NULL)
@eprog\noindent is \kbd{lGD\&}.
\misctitle{Caution} This function may not work on all systems, especially
when \kbd{gp} has been compiled statically. In that case, the first use of an
installed function will provoke a Segmentation Fault (this should never
happen with a dynamically linked executable). If you intend to use this
function, please check first on some harmless example such as the one above
that it works properly on your machine.
Function: intcirc
Class: basic
Section: sums
C-Name: intcirc0
Prototype: V=GGEDGp
Help: intcirc(X=a,R,expr,{tab}): numerical integration of expr on the circle
|z-a|=R, divided by 2*I*Pi. tab is as in intnum.
Wrapper: (,,G)
Description:
(gen,gen,gen,?gen):gen:prec intcirc(${3 cookie}, ${3 wrapper}, $1, $2, $4, $prec)
Doc: numerical
integration of $(2i\pi)^{-1}\var{expr}$ with respect to $X$ on the circle
$|X-a| = R$.
In other words, when \var{expr} is a meromorphic
function, sum of the residues in the corresponding disk; \var{tab} is as in
\kbd{intnum}, except that if computed with \kbd{intnuminit} it should be with
the endpoints \kbd{[-1, 1]}.
\bprog
? \p105
? intcirc(s=1, 0.5, zeta(s)) - 1
time = 496 ms.
%1 = 1.2883911040127271720 E-101 + 0.E-118*I
@eprog
\synt{intcirc}{void *E, GEN (*eval)(void*,GEN), GEN a,GEN R,GEN tab, long prec}.
Function: intformal
Class: basic
Section: polynomials
C-Name: integ
Prototype: GDn
Help: intformal(x,{v}): formal integration of x with respect to v, or to the
main variable of x if v is omitted.
Doc: \idx{formal integration} of $x$ with respect to the variable $v$ (wrt.
the main variable if $v$ is omitted). Since PARI cannot represent
logarithmic or arctangent terms, any such term in the result will yield an
error:
\bprog
? intformal(x^2)
%1 = 1/3*x^3
? intformal(x^2, y)
%2 = y*x^2
? intformal(1/x)
*** at top-level: intformal(1/x)
*** ^--------------
*** intformal: domain error in intformal: residue(series, pole) != 0
@eprog
The argument $x$ can be of any type. When $x$ is a rational function, we
assume that the base ring is an integral domain of characteristic zero.
By definition, the main variable of a \typ{POLMOD} is the main variable
among the coefficients from its two polynomial components
(representative and modulus); in other words, assuming a polmod represents an
element of $R[X]/(T(X))$, the variable $X$ is a mute variable and the
integral is taken with respect to the main variable used in the base ring $R$.
In particular, it is meaningless to integrate with respect to the main
variable of \kbd{x.mod}:
\bprog
? intformal(Mod(1,x^2+1), 'x)
*** intformal: incorrect priority in intformal: variable x = x
@eprog
Function: intfuncinit
Class: basic
Section: sums
C-Name: intfuncinit0
Prototype: V=GGED0,L,p
Help: intfuncinit(t=a,b,f,{m=0}): initialize tables for integrations
from a to b using a weight f(t). For integral transforms such
as Fourier or Mellin transforms.
Wrapper: (,,G)
Description:
(gen,gen,gen,?small):gen:prec intfuncinit(${3 cookie}, ${3 wrapper}, $1, $2, $4, $prec)
Doc: initialize tables for use with integral transforms such Fourier,
Laplace or Mellin transforms, in order to compute
$$ \int_a^b f(t) k(t,z) \, dt $$
for some kernel $k(t,z)$.
The endpoints $a$ and $b$ are coded as in \kbd{intnum}, $f$ is the
function to which the integral transform is to be applied and the
non-negative integer $m$ is as in \kbd{intnum}: multiply the number of
sampling points roughly by $2^m$, hopefully increasing the accuracy. This
function is particularly useful when the function $f$ is hard to compute,
such as a gamma product.
\misctitle{Limitation} the endpoints $a$ and $b$ must be at infinity,
with the same asymptotic behaviour. Oscillating types are not supported.
This is easily overcome by integrating vectors of functions, see example
below.
\misctitle{Examples}
\item numerical Fourier transform
$$F(z) = \int_{-\infty}^{+\infty} f(t)e^{-2i\pi z t}\, dt. $$
First the easy case, assume that $f$ decrease exponentially:
\bprog
f(t) = exp(-t^2);
A = [-oo,1];
B = [+oo,1];
\p200
T = intfuncinit(t = A,B , f(t));
F(z) =
{ my(a = -2*I*Pi*z);
intnum(t = A,B, exp(a*t), T);
}
? F(1) - sqrt(Pi)*exp(-Pi^2)
%1 = -1.3... E-212
@eprog\noindent
Now the harder case, $f$ decrease slowly: we must specify the oscillating
behaviour. Thus, we cannot precompute usefully since everything depends on
the point we evaluate at:
\bprog
f(t) = 1 / (1+ abs(t));
\p200
\\ Fourier cosine transform
FC(z) =
{ my(a = 2*Pi*z);
intnum(t = [-oo, a*I], [+oo, a*I], cos(a*t)*f(t));
}
FC(1)
@eprog
\item Fourier coefficients: we must integrate over a period, but
\kbd{intfuncinit} does not support finite endpoints.
The solution is to integrate a vector of functions !
\bprog
FourierSin(f, T, k) = \\ first k sine Fourier coeffs
{
my (w = 2*Pi/T);
my (v = vector(k+1));
intnum(t = -T/2, T/2,
my (z = exp(I*w*t));
v[1] = z;
for (j = 2, k, v[j] = v[j-1]*z);
f(t) * imag(v)) * 2/T;
}
FourierSin(t->sin(2*t), 2*Pi, 10)
@eprog\noindent The same technique can be used instead of \kbd{intfuncinit}
to integrate $f(t) k(t,z)$ whenever the list of $z$-values is known
beforehand.
Note that the above code includes an unrelated optimization: the
$\sin(j w t)$ are computed as imaginary parts of $\exp(i j w t)$ and the
latter by successive multiplications.
\item numerical Mellin inversion
$$F(z) = (2i\pi)^{-1} \int_{c -i\infty}^{c+i\infty} f(s)z^{-s}\, ds
= (2\pi)^{-1} \int_{-\infty}^{+\infty}
f(c + i t)e^{-\log z(c + it)}\, dt. $$
We take $c = 2$ in the program below:
\bprog
f(s) = gamma(s)^3; \\ f(c+it) decrease as exp(-3Pi|t|/2)
c = 2; \\ arbitrary
A = [-oo,3*Pi/2];
B = [+oo,3*Pi/2];
T = intfuncinit(t=A,B, f(c + I*t));
F(z) =
{ my (a = -log(z));
intnum(t=A,B, exp(a*I*t), T)*exp(a*c) / (2*Pi);
}
@eprog
\synt{intfuncinit}{void *E, GEN (*eval)(void*,GEN), GEN a,GEN b,long m, long prec}.
Function: intnum
Class: basic
Section: sums
C-Name: intnum0
Prototype: V=GGEDGp
Help: intnum(X=a,b,expr,{tab}): numerical integration of expr from a to b with
respect to X. Plus/minus infinity is coded as +oo/-oo. Finally tab is
either omitted (let the program choose the integration step), a non-negative
integer m (divide integration step by 2^m), or data precomputed with
intnuminit.
Wrapper: (,,G)
Description:
(gen,gen,gen,?gen):gen:prec intnum(${3 cookie}, ${3 wrapper}, $1, $2, $4, $prec)
Doc: numerical integration
of \var{expr} on $]a,b[$ with respect to $X$, using the
double-exponential method, and thus $O(D\log D)$ evaluation of
the integrand in precision $D$. The integrand may have values
belonging to a vector space over the real numbers; in particular, it can be
complex-valued or vector-valued. But it is assumed that the function is
regular on $]a,b[$. If the endpoints $a$ and $b$ are finite and the
function is regular there, the situation is simple:
\bprog
? intnum(x = 0,1, x^2)
%1 = 0.3333333333333333333333333333
? intnum(x = 0,Pi/2, [cos(x), sin(x)])
%2 = [1.000000000000000000000000000, 1.000000000000000000000000000]
@eprog\noindent
An endpoint equal to $\pm\infty$ is coded as \kbd{+oo} or \kbd{-oo}, as
expected:
\bprog
? intnum(x = 1,+oo, 1/x^2)
%3 = 1.000000000000000000000000000
@eprog\noindent
In basic usage, it is assumed that the function does not decrease
exponentially fast at infinity:
\bprog
? intnum(x=0,+oo, exp(-x))
*** at top-level: intnum(x=0,+oo,exp(-
*** ^--------------------
*** exp: overflow in expo().
@eprog\noindent
We shall see in a moment how to avoid that last problem, after describing
the last \emph{optional} argument \var{tab}.
\misctitle{The \var{tab} argument}
The routine uses weights $w_i$, which are mostly independent of the function
being integrated, evaluated at many sampling points $x_i$ and
approximates the integral by $\sum w_i f(x_i)$. If \var{tab} is
\item a non-negative integer $m$, we multiply the number of sampling points
by $2^m$, hopefully increasing accuracy. Note that the running time
increases roughly by a factor $2^m$. One may try consecutive values of $m$
until they give the same value up to an accepted error.
\item a set of integration tables containing precomputed $x_i$ and $w_i$
as output by \tet{intnuminit}. This is useful if several integrations of
the same type are performed (on the same kind of interval and functions,
for a given accuracy): we skip a precomputation of $O(D\log D)$
elementary functions in accuracy $D$, whose running time has the same order
of magnitude as the evaluation of the integrand. This is in particular
useful for multivariate integrals.
\misctitle{Specifying the behavior at endpoints}
This is done as follows. An endpoint $a$ is either given as such (a scalar,
real or complex, \kbd{oo} or \kbd{-oo} for $\pm\infty$), or as a two
component vector $[a,\alpha]$, to indicate the behavior of the integrand in a
neighborhood of $a$.
If $a$ is finite, the code $[a,\alpha]$ means the function has a
singularity of the form $(x-a)^{\alpha}$, up to logarithms. (If $\alpha \ge
0$, we only assume the function is regular, which is the default assumption.)
If a wrong singularity exponent is used, the result will lose a catastrophic
number of decimals:
\bprog
? intnum(x=0, 1, x^(-1/2)) \\@com assume $x^{-1/2}$ is regular at 0
%1 = 1.9999999999999999999999999999827931660
? intnum(x=[0,-1/2], 1, x^(-1/2)) \\@com no, it's not
%2 = 2.0000000000000000000000000000000000000
? intnum(x=[0,-1/10], 1, x^(-1/2)) \\@com using a wrong exponent is bad
%3 = 1.9999999999999999999999999999999901912
@eprog
If $a$ is $\pm\infty$, which is coded as \kbd{+oo} or \kbd{-oo},
the situation is more complicated, and $[\pm\kbd{oo},\alpha]$ means:
\item $\alpha=0$ (or no $\alpha$ at all, i.e. simply $\pm\kbd{oo}$)
assumes that the integrand tends to zero moderately quickly, at least as
$O(x^{-2})$ but not exponentially fast.
\item $\alpha>0$ assumes that the function tends to zero exponentially fast
approximately as $\exp(-\alpha x)$. This includes oscillating but quickly
decreasing functions such as $\exp(-x)\sin(x)$.
\bprog
? intnum(x=0, +oo, exp(-2*x))
*** at top-level: intnum(x=0,+oo,exp(-
*** ^--------------------
*** exp: exponent (expo) overflow
? intnum(x=0, [+oo, 2], exp(-2*x)) \\@com OK!
%1 = 0.50000000000000000000000000000000000000
? intnum(x=0, [+oo, 3], exp(-2*x)) \\@com imprecise exponent, still OK !
%2 = 0.50000000000000000000000000000000000000
? intnum(x=0, [+oo, 10], exp(-2*x)) \\@com wrong exponent $\Rightarrow$ disaster
%3 = 0.49999999999952372962457451698256707393
@eprog\noindent As the last exemple shows, the exponential decrease rate
\emph{must} be indicated to avoid overflow, but the method is robust enough
for a rough guess to be acceptable.
\item $\alpha<-1$ assumes that the function tends to $0$ slowly, like
$x^{\alpha}$. Here the algorithm is less robust and it is essential to give a
sharp $\alpha$, unless $\alpha \le -2$ in which case we use
the default algorithm as if $\alpha$ were missing (or equal to $0$).
\bprog
? intnum(x=1, +oo, x^(-3/2)) \\ default
%1 = 1.9999999999999999999999999999646391207
? intnum(x=1, [+oo,-3/2], x^(-3/2)) \\ precise decrease rate
%2 = 2.0000000000000000000000000000000000000
? intnum(x=1, [+oo,-11/10], x^(-3/2)) \\ worse than default
%3 = 2.0000000000000000000000000089298011973
@eprog
\smallskip The last two codes are reserved for oscillating functions.
Let $k > 0$ real, and $g(x)$ a non-oscillating function tending slowly to $0$
(e.g. like a negative power of $x$), then
\item $\alpha=k * I$ assumes that the function behaves like $\cos(kx)g(x)$.
\item $\alpha=-k* I$ assumes that the function behaves like $\sin(kx)g(x)$.
\noindent Here it is critical to give the exact value of $k$. If the
oscillating part is not a pure sine or cosine, one must expand it into a
Fourier series, use the above codings, and sum the resulting contributions.
Otherwise you will get nonsense. Note that $\cos(kx)$, and similarly
$\sin(kx)$, means that very function, and not a translated version such as
$\cos(kx+a)$.
\misctitle{Note} If $f(x)=\cos(kx)g(x)$ where $g(x)$ tends to zero
exponentially fast as $\exp(-\alpha x)$, it is up to the user to choose
between $[\pm\kbd{oo},\alpha]$ and $[\pm\kbd{oo},k* I]$, but a good rule of
thumb is that
if the oscillations are weaker than the exponential decrease, choose
$[\pm\kbd{oo},\alpha]$, otherwise choose $[\pm\kbd{oo},k*I]$, although the
latter can
reasonably be used in all cases, while the former cannot. To take a specific
example, in the inverse Mellin transform, the integrand is almost always a
product of an exponentially decreasing and an oscillating factor. If we
choose the oscillating type of integral we perhaps obtain the best results,
at the expense of having to recompute our functions for a different value of
the variable $z$ giving the transform, preventing us to use a function such
as \kbd{intfuncinit}. On the other hand using the exponential type of
integral, we obtain less accurate results, but we skip expensive
recomputations. See \kbd{intfuncinit} for more explanations.
\smallskip
We shall now see many examples to get a feeling for what the various
parameters achieve. All examples below assume precision is set to $115$
decimal digits. We first type
\bprog
? \p 115
@eprog
\misctitle{Apparent singularities} In many cases, apparent singularities
can be ignored. For instance, if $f(x) = 1
/(\exp(x)-1) - \exp(-x)/x$, then $\int_0^\infty f(x)\,dx=\gamma$, Euler's
constant \kbd{Euler}. But
\bprog
? f(x) = 1/(exp(x)-1) - exp(-x)/x
? intnum(x = 0, [oo,1], f(x)) - Euler
%1 = 0.E-115
@eprog\noindent
But close to $0$ the function $f$ is computed with an enormous loss of
accuracy, and we are in fact lucky that it get multiplied by weights which are
sufficiently close to $0$ to hide this:
\bprog
? f(1e-200)
%2 = -3.885337784451458142 E84
@eprog
A more robust solution is to define the function differently near special
points, e.g. by a Taylor expansion
\bprog
? F = truncate( f(t + O(t^10)) ); \\@com expansion around t = 0
? poldegree(F)
%4 = 7
? g(x) = if (x > 1e-18, f(x), subst(F,t,x)); \\@com note that $7 \cdot 18 > 105$
? intnum(x = 0, [oo,1], g(x)) - Euler
%2 = 0.E-115
@eprog\noindent It is up to the user to determine constants such as the
$10^{-18}$ and $10$ used above.
\misctitle{True singularities} With true singularities the result is worse.
For instance
\bprog
? intnum(x = 0, 1, x^(-1/2)) - 2
%1 = -3.5... E-68 \\@com only $68$ correct decimals
? intnum(x = [0,-1/2], 1, x^(-1/2)) - 2
%2 = 0.E-114 \\@com better
@eprog
\misctitle{Oscillating functions}
\bprog
? intnum(x = 0, oo, sin(x) / x) - Pi/2
%1 = 16.19.. \\@com nonsense
? intnum(x = 0, [oo,1], sin(x)/x) - Pi/2
%2 = -0.006.. \\@com bad
? intnum(x = 0, [oo,-I], sin(x)/x) - Pi/2
%3 = 0.E-115 \\@com perfect
? intnum(x = 0, [oo,-I], sin(2*x)/x) - Pi/2 \\@com oops, wrong $k$
%4 = 0.06...
? intnum(x = 0, [oo,-2*I], sin(2*x)/x) - Pi/2
%5 = 0.E-115 \\@com perfect
? intnum(x = 0, [oo,-I], sin(x)^3/x) - Pi/4
%6 = -0.0008... \\@com bad
? sin(x)^3 - (3*sin(x)-sin(3*x))/4
%7 = O(x^17)
@eprog\noindent
We may use the above linearization and compute two oscillating integrals with
endpoints \kbd{[oo, -I]} and \kbd{[oo, -3*I]} respectively, or
notice the obvious change of variable, and reduce to the single integral
${1\over 2}\int_0^\infty \sin(x)/x\,dx$. We finish with some more complicated
examples:
\bprog
? intnum(x = 0, [oo,-I], (1-cos(x))/x^2) - Pi/2
%1 = -0.0003... \\@com bad
? intnum(x = 0, 1, (1-cos(x))/x^2) \
+ intnum(x = 1, oo, 1/x^2) - intnum(x = 1, [oo,I], cos(x)/x^2) - Pi/2
%2 = 0.E-115 \\@com perfect
? intnum(x = 0, [oo, 1], sin(x)^3*exp(-x)) - 0.3
%3 = -7.34... E-55 \\@com bad
? intnum(x = 0, [oo,-I], sin(x)^3*exp(-x)) - 0.3
%4 = 8.9... E-103 \\@com better. Try higher $m$
? tab = intnuminit(0,[oo,-I], 1); \\@com double number of sampling points
? intnum(x = 0, oo, sin(x)^3*exp(-x), tab) - 0.3
%6 = 0.E-115 \\@com perfect
@eprog
\misctitle{Warning} Like \tet{sumalt}, \kbd{intnum} often assigns a
reasonable value to diverging integrals. Use these values at your own risk!
For example:
\bprog
? intnum(x = 0, [oo, -I], x^2*sin(x))
%1 = -2.0000000000...
@eprog\noindent
Note the formula
$$ \int_0^\infty \sin(x)/x^s\,dx = \cos(\pi s/2) \Gamma(1-s)\;, $$
a priori valid only for $0 < \Re(s) < 2$, but the right hand side provides an
analytic continuation which may be evaluated at $s = -2$\dots
\misctitle{Multivariate integration}
Using successive univariate integration with respect to different formal
parameters, it is immediate to do naive multivariate integration. But it is
important to use a suitable \kbd{intnuminit} to precompute data for the
\emph{internal} integrations at least!
For example, to compute the double integral on the unit disc $x^2+y^2\le1$
of the function $x^2+y^2$, we can write
\bprog
? tab = intnuminit(-1,1);
? intnum(x=-1,1, intnum(y=-sqrt(1-x^2),sqrt(1-x^2), x^2+y^2, tab),tab) - Pi/2
%2 = -7.1... E-115 \\@com OK
@eprog\noindent
The first \var{tab} is essential, the second optional. Compare:
\bprog
? tab = intnuminit(-1,1);
time = 4 ms.
? intnum(x=-1,1, intnum(y=-sqrt(1-x^2),sqrt(1-x^2), x^2+y^2));
time = 3,092 ms. \\@com slow
? intnum(x=-1,1, intnum(y=-sqrt(1-x^2),sqrt(1-x^2), x^2+y^2, tab), tab);
time = 252 ms. \\@com faster
? intnum(x=-1,1, intnum(y=-sqrt(1-x^2),sqrt(1-x^2), x^2+y^2, tab));
time = 261 ms. \\@com the \emph{internal} integral matters most
@eprog
\synt{intnum}{void *E, GEN (*eval)(void*,GEN), GEN a,GEN b,GEN tab, long prec},
where an omitted \var{tab} is coded as \kbd{NULL}.
Function: intnumgauss
Class: basic
Section: sums
C-Name: intnumgauss0
Prototype: V=GGEDGp
Help: intnumgauss(X=a,b,expr,{tab}): numerical integration of expr from
a to b, a compact interval, with respect to X using Gauss-Legendre
quadrature. tab is either omitted (and will be recomputed) or
precomputed with intnumgaussinit.
Wrapper: (,,G)
Description:
(gen,gen,gen,?gen):gen:prec intnumgauss(${3 cookie}, ${3 wrapper}, $1, $2, $4, $prec)
Doc: numerical integration of \var{expr} on the compact interval $[a,b]$ with
respect to $X$ using Gauss-Legendre quadrature; \kbd{tab} is either omitted
or precomputed with \kbd{intnumgaussinit}. As a convenience, it can be an
integer $n$ in which case we call
\kbd{intnumgaussinit}$(n)$ and use $n$-point quadrature.
\bprog
? test(n, b = 1) = T=intnumgaussinit(n);\
intnumgauss(x=-b,b, 1/(1+x^2),T) - 2*atan(b);
? test(0) \\ default
%1 = -9.490148553624725335 E-22
? test(40)
%2 = -6.186629001816965717 E-31
? test(50)
%3 = -1.1754943508222875080 E-38
? test(50, 2) \\ double interval length
%4 = -4.891779568527713636 E-21
? test(90, 2) \\ n must almost be doubled as well!
%5 = -9.403954806578300064 E-38
@eprog\noindent On the other hand, we recommend to split the integral
and change variables rather than increasing $n$ too much:
\bprog
? f(x) = 1/(1+x^2);
? b = 100;
? intnumgauss(x=0,1, f(x)) + intnumgauss(x=1,1/b, f(1/x)*(-1/x^2)) - atan(b)
%3 = -1.0579449157400587572 E-37
@eprog
Function: intnumgaussinit
Class: basic
Section: sums
C-Name: intnumgaussinit
Prototype: D0,L,p
Help: intnumgaussinit({n}): initialize tables for n-point Gauss-Legendre
integration on a compact interval.
Doc: initialize tables for $n$-point Gauss-Legendre integration of
a smooth function $f$ lon a compact
interval $[a,b]$ at current \kbd{realprecision}. If $n$ is omitted, make a
default choice $n \approx \kbd{realprecision}$, suitable for analytic
functions on $[-1,1]$. The error is bounded by
$$
\dfrac{(b-a)^{2n+1} (n!)^4}{(2n+1)[(2n)!]^3} f^{(2n)} (\xi) ,
\qquad a < \xi < b
$$
so, if the interval length increases, $n$ should be increased as well.
\bprog
? T = intnumgaussinit();
? intnumgauss(t=-1,1,exp(t), T) - exp(1)+exp(-1)
%1 = -5.877471754111437540 E-39
? intnumgauss(t=-10,10,exp(t), T) - exp(10)+exp(-10)
%2 = -8.358367809712546836 E-35
? intnumgauss(t=-1,1,1/(1+t^2), T) - Pi/2
%3 = -9.490148553624725335 E-22
? T = intnumgaussinit(50);
? intnumgauss(t=-1,1,1/(1+t^2), T) - Pi/2
%5 = -1.1754943508222875080 E-38
? intnumgauss(t=-5,5,1/(1+t^2), T) - 2*atan(5)
%6 = -1.2[...]E-8
@eprog
On the other hand, we recommend to split the integral and change variables
rather than increasing $n$ too much, see \tet{intnumgauss}.
Function: intnuminit
Class: basic
Section: sums
C-Name: intnuminit
Prototype: GGD0,L,p
Help: intnuminit(a,b,{m=0}): initialize tables for integrations from a to b.
See help for intnum for coding of a and b. Possible types: compact interval,
semi-compact (one extremity at + or - infinity) or R, and very slowly, slowly
or exponentially decreasing, or sine or cosine oscillating at infinities.
Doc: initialize tables for integration from
$a$ to $b$, where $a$ and $b$ are coded as in \kbd{intnum}. Only the
compactness, the possible existence of singularities, the speed of decrease
or the oscillations at infinity are taken into account, and not the values.
For instance {\tt intnuminit(-1,1)} is equivalent to {\tt intnuminit(0,Pi)},
and {\tt intnuminit([0,-1/2],oo)} is equivalent to
{\tt intnuminit([-1,-1/2], -oo)}; on the other hand, the order matters
and
{\tt intnuminit([0,-1/2], [1,-1/3])} is \emph{not} equivalent to
{\tt intnuminit([0,-1/3], [1,-1/2])} !
If $m$ is present, it must be non-negative and we multiply the default
number of sampling points by $2^m$ (increasing the running time by a
similar factor).
The result is technical and liable to change in the future, but we document
it here for completeness. Let $x=\phi(t)$, $t\in ]-\infty,\infty[$ be an
internally chosen change of variable, achieving double exponential decrease of
the integrand at infinity. The integrator \kbd{intnum} will compute
$$ h \sum_{|n| < N} \phi'(nh) F(\phi(nh)) $$
for some integration step $h$ and truncation parameter $N$.
In basic use, let
\bprog
[h, x0, w0, xp, wp, xm, wm] = intnuminit(a,b);
@eprog
\item $h$ is the integration step
\item $x_0 = \phi(0)$ and $w_0 = \phi'(0)$,
\item \var{xp} contains the $\phi(nh)$, $0 < n < N$,
\item \var{xm} contains the $\phi(nh)$, $0 < -n < N$, or is empty.
\item \var{wp} contains the $\phi'(nh)$, $0 < n < N$,
\item \var{wm} contains the $\phi'(nh)$, $0 < -n < N$, or is empty.
The arrays \var{xm} and \var{wm} are left empty when $\phi$ is an odd
function. In complicated situations when non-default behaviour is specified at
end points, \kbd{intnuminit} may return up to $3$ such arrays, corresponding
to a splitting of up to $3$ integrals of basic type.
If the functions to be integrated later are of the form $F = f(t) k(t,z)$
for some kernel $k$ (e.g. Fourier, Laplace, Mellin, \dots), it is
useful to also precompute the values of $f(\phi(nh))$, which is accomplished
by \tet{intfuncinit}. The hard part is to determine the behaviour
of $F$ at endpoints, depending on $z$.
Function: intnumromb
Class: basic
Section: sums
C-Name: intnumromb0_bitprec
Prototype: V=GGED0,L,b
Help: intnumromb(X=a,b,expr,{flag=0}): numerical integration of expr (smooth in
]a,b[) from a to b with respect to X. flag is optional and mean 0: default.
expr can be evaluated exactly on [a,b]; 1: general function; 2: a or b can be
plus or minus infinity (chosen suitably), but of same sign; 3: expr has only
limits at a or b.
Wrapper: (,,G)
Description:
(gen,gen,gen,?small):gen:prec intnumromb(${3 cookie}, ${3 wrapper}, $1, $2, $4, $bitprec)
Doc: numerical integration of \var{expr} (smooth in $]a,b[$), with respect to
$X$. Suitable for low accuracy; if \var{expr} is very regular (e.g. analytic
in a large region) and high accuracy is desired, try \tet{intnum} first.
Set $\fl=0$ (or omit it altogether) when $a$ and $b$ are not too large, the
function is smooth, and can be evaluated exactly everywhere on the interval
$[a,b]$.
If $\fl=1$, uses a general driver routine for doing numerical integration,
making no particular assumption (slow).
$\fl=2$ is tailored for being used when $a$ or $b$ are infinite using the
change of variable $t = 1/X$. One \emph{must} have $ab>0$, and in fact if
for example $b=+\infty$, then it is preferable to have $a$ as large as
possible, at least $a\ge1$.
If $\fl=3$, the function is allowed to be undefined
at $a$ (but right continuous) or $b$ (left continuous),
for example the function $\sin(x)/x$ between $x=0$ and $1$.
The user should not require too much accuracy: \tet{realprecision} about
30 decimal digits (\tet{realbitprecision} about 100 bits) is OK,
but not much more. In addition, analytical cleanup of the integral must have
been done: there must be no singularities in the interval or at the
boundaries. In practice this can be accomplished with a change of
variable. Furthermore, for improper integrals, where one or both of the
limits of integration are plus or minus infinity, the function must decrease
sufficiently rapidly at infinity, which can often be accomplished through
integration by parts. Finally, the function to be integrated should not be
very small (compared to the current precision) on the entire interval. This
can of course be accomplished by just multiplying by an appropriate constant.
Note that \idx{infinity} can be represented with essentially no loss of
accuracy by an appropriate huge number. However beware of real underflow
when dealing with rapidly decreasing functions. For example, in order to
compute the $\int_0^\infty e^{-x^2}\,dx$ to 28 decimal digits, then one can
set infinity equal to 10 for example, and certainly not to \kbd{1e1000}.
\synt{intnumromb_bitprec}{void *E, GEN (*eval)(void*,GEN), GEN a, GEN b, long flag, long bitprec},
where $\kbd{eval}(x, E)$ returns the value of the function at $x$.
You may store any additional information required by \kbd{eval} in $E$, or set
it to \kbd{NULL}. The historical variant
\synt{intnumromb}{\dots, long prec}, where \kbd{prec} is expressed in words,
not bits, is obsolete and should no longer be used.
Function: isfundamental
Class: basic
Section: number_theoretical
C-Name: isfundamental
Prototype: lG
Help: isfundamental(x): true(1) if x is a fundamental discriminant
(including 1), false(0) if not.
Description:
(int):bool Z_isfundamental($1)
(gen):bool isfundamental($1)
Doc: true (1) if $x$ is equal to 1 or to the discriminant of a quadratic
field, false (0) otherwise.
Function: ispolygonal
Class: basic
Section: number_theoretical
C-Name: ispolygonal
Prototype: lGGD&
Help: ispolygonal(x,s,{&N}): true(1) if x is an s-gonal number, false(0) if
not (s > 2). If N is given set it to n if x is the n-th s-gonal number.
Doc: true (1) if the integer $x$ is an s-gonal number, false (0) if not.
The parameter $s > 2$ must be a \typ{INT}. If $N$ is given, set it to $n$
if $x$ is the $n$-th $s$-gonal number.
\bprog
? ispolygonal(36, 3, &N)
%1 = 1
? N
@eprog
Function: ispower
Class: basic
Section: number_theoretical
C-Name: ispower
Prototype: lGDGD&
Help: ispower(x,{k},{&n}): if k > 0 is given, return true (1) if x is a k-th
power, false (0) if not. If k is omitted, return the maximal k >= 2 such
that x = n^k is a perfect power, or 0 if no such k exist.
If n is present, and the function returns a non-zero result, set n to the
k-th root of x.
Description:
(int):small Z_isanypower($1, NULL)
(int, &int):small Z_isanypower($1, &$2)
Doc: if $k$ is given, returns true (1) if $x$ is a $k$-th power, false
(0) if not. What it means to be a $k$-th power depends on the type of
$x$; see \tet{issquare} for details.
If $k$ is omitted, only integers and fractions are allowed for $x$ and the
function returns the maximal $k \geq 2$ such that $x = n^k$ is a perfect
power, or 0 if no such $k$ exist; in particular \kbd{ispower(-1)},
\kbd{ispower(0)}, and \kbd{ispower(1)} all return $0$.
If a third argument $\&n$ is given and $x$ is indeed a $k$-th power, sets
$n$ to a $k$-th root of $x$.
\noindent For a \typ{FFELT} \kbd{x}, instead of omitting \kbd{k} (which is
not allowed for this type), it may be natural to set
\bprog
k = (x.p ^ x.f - 1) / fforder(x)
@eprog
Variant: Also available is
\fun{long}{gisanypower}{GEN x, GEN *pty} ($k$ omitted).
Function: ispowerful
Class: basic
Section: number_theoretical
C-Name: ispowerful
Prototype: lG
Help: ispowerful(x): true(1) if x is a powerful integer (valuation at all
primes dividing x is greater than 1), false(0) if not.
Doc: true (1) if $x$ is a powerful integer, false (0) if not;
an integer is powerful if and only if its valuation at all primes dividing
$x$ is greater than 1.
\bprog
? ispowerful(50)
%1 = 0
? ispowerful(100)
%2 = 1
? ispowerful(5^3*(10^1000+1)^2)
%3 = 1
@eprog
Function: isprime
Class: basic
Section: number_theoretical
C-Name: gisprime
Prototype: GD0,L,
Help: isprime(x,{flag=0}): true(1) if x is a (proven) prime number, false(0)
if not. If flag is 0 or omitted, use a combination of algorithms. If flag is
1, the primality is certified by the Pocklington-Lehmer Test. If flag is 2,
the primality is certified using the APRCL test.
Description:
(int, ?0):bool isprime($1)
(gen, ?small):gen gisprime($1, $2)
Doc: true (1) if $x$ is a prime
number, false (0) otherwise. A prime number is a positive integer having
exactly two distinct divisors among the natural numbers, namely 1 and
itself.
This routine proves or disproves rigorously that a number is prime, which can
be very slow when $x$ is indeed prime and has more than $1000$ digits, say.
Use \tet{ispseudoprime} to quickly check for compositeness. See also
\kbd{factor}. It accepts vector/matrices arguments, and is then applied
componentwise.
If $\fl=0$, use a combination of Baillie-PSW pseudo primality test (see
\tet{ispseudoprime}), Selfridge ``$p-1$'' test if $x-1$ is smooth enough, and
Adleman-Pomerance-Rumely-Cohen-Lenstra (APRCL) for general $x$.
If $\fl=1$, use Selfridge-Pocklington-Lehmer ``$p-1$'' test and output a
primality certificate as follows: return
\item 0 if $x$ is composite,
\item 1 if $x$ is small enough that passing Baillie-PSW test guarantees
its primality (currently $x < 2^{64}$, as checked by Jan Feitsma),
\item $2$ if $x$ is a large prime whose primality could only sensibly be
proven (given the algorithms implemented in PARI) using the APRCL test.
\item Otherwise ($x$ is large and $x-1$ is smooth) output a three column
matrix as a primality certificate. The first column contains prime
divisors $p$ of $x-1$ (such that $\prod p^{v_p(x-1)} > x^{1/3}$), the second
the corresponding elements $a_p$ as in Proposition~8.3.1 in GTM~138 , and the
third the output of isprime(p,1).
The algorithm fails if one of the pseudo-prime factors is not prime, which is
exceedingly unlikely and well worth a bug report. Note that if you monitor
\kbd{isprime} at a high enough debug level, you may see warnings about
untested integers being declared primes. This is normal: we ask for partial
factorisations (sufficient to prove primality if the unfactored part is not
too large), and \kbd{factor} warns us that the cofactor hasn't been tested.
It may or may not be tested later, and may or may not be prime. This does
not affect the validity of the whole \kbd{isprime} procedure.
If $\fl=2$, use APRCL.
Function: isprimepower
Class: basic
Section: number_theoretical
C-Name: isprimepower
Prototype: lGD&
Help: isprimepower(x,{&n}): if x = p^k is a prime power (p prime, k > 0),
return k, else return 0. If n is present, and the function returns a non-zero
result, set n to p, the k-th root of x.
Doc: if $x = p^k$ is a prime power ($p$ prime, $k > 0$), return $k$, else
return 0. If a second argument $\&n$ is given and $x$ is indeed
the $k$-th power of a prime $p$, sets $n$ to $p$.
Function: ispseudoprime
Class: basic
Section: number_theoretical
C-Name: gispseudoprime
Prototype: GD0,L,
Help: ispseudoprime(x,{flag}): true(1) if x is a strong pseudoprime, false(0)
if not. If flag is 0 or omitted, use BPSW test, otherwise use strong
Rabin-Miller test for flag randomly chosen bases.
Description:
(int,?0):bool BPSW_psp($1)
(int,#small):bool millerrabin($1,$2)
(int,small):bool ispseudoprime($1, $2)
(gen,?small):gen gispseudoprime($1, $2)
Doc: true (1) if $x$ is a strong pseudo
prime (see below), false (0) otherwise. If this function returns false, $x$
is not prime; if, on the other hand it returns true, it is only highly likely
that $x$ is a prime number. Use \tet{isprime} (which is of course much
slower) to prove that $x$ is indeed prime.
The function accepts vector/matrices arguments, and is then applied
componentwise.
If $\fl = 0$, checks whether $x$ has no small prime divisors (up to $101$
included) and is a Baillie-Pomerance-Selfridge-Wagstaff pseudo prime.
Such a pseudo prime passes a Rabin-Miller test for base $2$,
followed by a Lucas test for the sequence $(P,-1)$, $P$ smallest
positive integer such that $P^2 - 4$ is not a square mod $x$).
There are no known composite numbers passing the above test, although it is
expected that infinitely many such numbers exist. In particular, all
composites $\leq 2^{64}$ are correctly detected (checked using
\url{http://www.cecm.sfu.ca/Pseudoprimes/index-2-to-64.html}).
If $\fl > 0$, checks whether $x$ is a strong Miller-Rabin pseudo prime for
$\fl$ randomly chosen bases (with end-matching to catch square roots of $-1$).
Function: ispseudoprimepower
Class: basic
Section: number_theoretical
C-Name: ispseudoprimepower
Prototype: lGD&
Help: ispseudoprimepower(x,{&n}): if x = p^k is a pseudo-prime power (p
pseudo-prime, k > 0),
return k, else return 0. If n is present, and the function returns a non-zero
result, set n to p, the k-th root of x.
Doc: if $x = p^k$ is a pseudo-prime power ($p$ pseudo-prime as per
\tet{ispseudoprime}, $k > 0$), return $k$, else
return 0. If a second argument $\&n$ is given and $x$ is indeed
the $k$-th power of a prime $p$, sets $n$ to $p$.
More precisely, $k$ is always the largest integer such that $x = n^k$ for
some integer $n$ and, when $n \leq 2^{64}$ the function returns $k > 0$ if and
only if $n$ is indeed prime. When $n > 2^{64}$ is larger than the threshold,
the function may return $1$ even though $n$ is composite: it only passed
an \kbd{ispseudoprime(n)} test.
Function: issquare
Class: basic
Section: number_theoretical
C-Name: issquareall
Prototype: lGD&
Help: issquare(x,{&n}): true(1) if x is a square, false(0) if not. If n is
given puts the exact square root there if it was computed.
Description:
(int):bool Z_issquare($1)
(gen):bool issquare($1)
(int, &int):bool Z_issquareall($1, &$2)
(gen, &gen):bool issquareall($1, &$2)
Doc: true (1) if $x$ is a square, false (0)
if not. What ``being a square'' means depends on the type of $x$: all
\typ{COMPLEX} are squares, as well as all non-negative \typ{REAL}; for
exact types such as \typ{INT}, \typ{FRAC} and \typ{INTMOD}, squares are
numbers of the form $s^2$ with $s$ in $\Z$, $\Q$ and $\Z/N\Z$ respectively.
\bprog
? issquare(3) \\ as an integer
%1 = 0
? issquare(3.) \\ as a real number
%2 = 1
? issquare(Mod(7, 8)) \\ in Z/8Z
%3 = 0
? issquare( 5 + O(13^4) ) \\ in Q_13
%4 = 0
@eprog
If $n$ is given, a square root of $x$ is put into $n$.
\bprog
? issquare(4, &n)
%1 = 1
? n
%2 = 2
@eprog
For polynomials, either we detect that the characteristic is 2 (and check
directly odd and even-power monomials) or we assume that $2$ is invertible
and check whether squaring the truncated power series for the square root
yields the original input.
For \typ{POLMOD} $x$, we only support \typ{POLMOD}s of \typ{INTMOD}s
encoding finite fields, assuming without checking that the intmod modulus
$p$ is prime and that the polmod modulus is irreducible modulo $p$.
\bprog
? issquare(Mod(Mod(2,3), x^2+1), &n)
%1 = 1
? n
%2 = Mod(Mod(2, 3)*x, Mod(1, 3)*x^2 + Mod(1, 3))
@eprog
Variant: Also available is \fun{long}{issquare}{GEN x}. Deprecated
GP-specific functions \fun{GEN}{gissquare}{GEN x} and
\fun{GEN}{gissquareall}{GEN x, GEN *pt} return \kbd{gen\_0} and \kbd{gen\_1}
instead of a boolean value.
Function: issquarefree
Class: basic
Section: number_theoretical
C-Name: issquarefree
Prototype: lG
Help: issquarefree(x): true(1) if x is squarefree, false(0) if not.
Description:
(gen):bool issquarefree($1)
Doc: true (1) if $x$ is squarefree, false (0) if not. Here $x$ can be an
integer or a polynomial with coefficients in an integral domain.
\bprog
? issquarefree(12)
%1 = 0
? issquarefree(6)
%2 = 1
? issquarefree(x^3+x^2)
%3 = 0
? issquarefree(Mod(1,4)*(x^2+x+1)) \\ Z/4Z is not a domain !
*** at top-level: issquarefree(Mod(1,4)*(x^2+x+1))
*** ^--------------------------------
*** issquarefree: impossible inverse in Fp_inv: Mod(2, 4).
@eprog\noindent A polynomial is declared squarefree if \kbd{gcd}$(x,x')$ is
$1$. In particular a non-zero polynomial with inexact coefficients is
considered to be squarefree. Note that this may be inconsistent with
\kbd{factor}, which first rounds the input to some exact approximation before
factoring in the apropriate domain; this is correct when the input is not
close to an inseparable polynomial (the resultant of $x$ and $x'$ is not
close to $0$).
Function: istotient
Class: basic
Section: number_theoretical
C-Name: istotient
Prototype: lGD&
Help: istotient(x,{&N}): true(1) if x = eulerphi(n) for some integer n,
false(0) if not. If N is given, set N = n as well.
Doc: true (1) if $x = \phi(n)$ for some integer $n$, false (0)
if not.
\bprog
? istotient(14)
%1 = 0
? istotient(100)
%2 = 0
@eprog
If $N$ is given, set $N = n$ as well.
\bprog
? istotient(4, &n)
%1 = 1
? n
%2 = 10
@eprog
Function: kill
Class: basic
Section: programming/specific
C-Name: kill0
Prototype: vr
Help: kill(sym): restores the symbol sym to its ``undefined'' status and kill
attached help messages.
Doc: restores the symbol \kbd{sym} to its ``undefined'' status, and deletes any
help messages attached to \kbd{sym} using \kbd{addhelp}. Variable names
remain known to the interpreter and keep their former priority: you cannot
make a variable ``less important" by killing it!
\bprog
? z = y = 1; y
%1 = 1
? kill(y)
? y \\ restored to ``undefined'' status
%2 = y
? variable()
%3 = [x, y, z] \\ but the variable name y is still known, with y > z !
@eprog\noindent
For the same reason, killing a user function (which is an ordinary
variable holding a \typ{CLOSURE}) does not remove its name from the list of
variable names.
If the symbol is attached to a variable --- user functions being an
important special case ---, one may use the \idx{quote} operator
\kbd{a = 'a} to reset variables to their starting values. However, this
will not delete a help message attached to \kbd{a}, and is also slightly
slower than \kbd{kill(a)}.
\bprog
? x = 1; addhelp(x, "foo"); x
%1 = 1
? x = 'x; x \\ same as 'kill', except we don't delete help.
%2 = x
? ?x
foo
@eprog\noindent
On the other hand, \kbd{kill} is the only way to remove aliases and installed
functions.
\bprog
? alias(fun, sin);
? kill(fun);
? install(addii, GG);
? kill(addii);
@eprog
Function: kronecker
Class: basic
Section: number_theoretical
C-Name: kronecker
Prototype: lGG
Help: kronecker(x,y): kronecker symbol (x/y).
Description:
(small, small):small kross($1, $2)
(int, small):small krois($1, $2)
(small, int):small krosi($1, $2)
(gen, gen):small kronecker($1, $2)
Doc:
\idx{Kronecker symbol} $(x|y)$, where $x$ and $y$ must be of type integer. By
definition, this is the extension of \idx{Legendre symbol} to $\Z \times \Z$
by total multiplicativity in both arguments with the following special rules
for $y = 0, -1$ or $2$:
\item $(x|0) = 1$ if $|x| = 1$ and $0$ otherwise.
\item $(x|-1) = 1$ if $x \geq 0$ and $-1$ otherwise.
\item $(x|2) = 0$ if $x$ is even and $1$ if $x = 1,-1 \mod 8$ and $-1$
if $x=3,-3 \mod 8$.
Function: lambertw
Class: basic
Section: transcendental
C-Name: glambertW
Prototype: Gp
Help: lambertw(y): solution of the implicit equation x*exp(x)=y.
Doc: Lambert $W$ function, solution of the implicit equation $xe^x=y$,
for $y > 0$.
Function: lcm
Class: basic
Section: number_theoretical
C-Name: glcm0
Prototype: GDG
Help: lcm(x,{y}): least common multiple of x and y, i.e. x*y / gcd(x,y)
up to units.
Description:
(int, int):int lcmii($1, $2)
(gen):gen glcm0($1, NULL)
(gen, gen):gen glcm($1, $2)
Doc: least common multiple of $x$ and $y$, i.e.~such
that $\lcm(x,y)*\gcd(x,y) = x*y$, up to units. If $y$ is omitted and $x$
is a vector, returns the $\text{lcm}$ of all components of $x$.
For integer arguments, return the non-negative \text{lcm}.
When $x$ and $y$ are both given and one of them is a vector/matrix type,
the LCM is again taken recursively on each component, but in a different way.
If $y$ is a vector, resp.~matrix, then the result has the same type as $y$,
and components equal to \kbd{lcm(x, y[i])}, resp.~\kbd{lcm(x, y[,i])}. Else
if $x$ is a vector/matrix the result has the same type as $x$ and an
analogous definition. Note that for these types, \kbd{lcm} is not
commutative.
Note that \kbd{lcm(v)} is quite different from
\bprog
l = v[1]; for (i = 1, #v, l = lcm(l, v[i]))
@eprog\noindent
Indeed, \kbd{lcm(v)} is a scalar, but \kbd{l} may not be (if one of
the \kbd{v[i]} is a vector/matrix). The computation uses a divide-conquer tree
and should be much more efficient, especially when using the GMP
multiprecision kernel (and more subquadratic algorithms become available):
\bprog
? v = vector(10^5, i, random);
? lcm(v);
time = 546 ms.
? l = v[1]; for (i = 1, #v, l = lcm(l, v[i]))
time = 4,561 ms.
@eprog
Function: length
Class: basic
Section: conversions
C-Name: glength
Prototype: lG
Help: length(x): number of non code words in x, number of characters for a
string.
Description:
(vecsmall):lg lg($1)
(vec):lg lg($1)
(pol):small lgpol($1)
(gen):small glength($1)
Doc: length of $x$; \kbd{\#}$x$ is a shortcut for \kbd{length}$(x)$.
This is mostly useful for
\item vectors: dimension (0 for empty vectors),
\item lists: number of entries (0 for empty lists),
\item matrices: number of columns,
\item character strings: number of actual characters (without
trailing \kbd{\bs 0}, should you expect it from $C$ \kbd{char*}).
\bprog
? #"a string"
%1 = 8
? #[3,2,1]
%2 = 3
? #[]
%3 = 0
? #matrix(2,5)
%4 = 5
? L = List([1,2,3,4]); #L
%5 = 4
@eprog
The routine is in fact defined for arbitrary GP types, but is awkward and
useless in other cases: it returns the number of non-code words in $x$, e.g.
the effective length minus 2 for integers since the \typ{INT} type has two code
words.
Function: lex
Class: basic
Section: operators
C-Name: lexcmp
Prototype: iGG
Help: lex(x,y): compare x and y lexicographically (1 if x>y, 0 if x=y, -1 if x<y).
Doc: gives the result of a lexicographic comparison
between $x$ and $y$ (as $-1$, $0$ or $1$). This is to be interpreted in quite
a wide sense: It is admissible to compare objects of different types
(scalars, vectors, matrices), provided the scalars can be compared, as well
as vectors/matrices of different lengths. The comparison is recursive.
In case all components are equal up to the smallest length of the operands,
the more complex is considered to be larger. More precisely, the longest is
the largest; when lengths are equal, we have matrix $>$ vector $>$ scalar.
For example:
\bprog
? lex([1,3], [1,2,5])
%1 = 1
? lex([1,3], [1,3,-1])
%2 = -1
? lex([1], [[1]])
%3 = -1
? lex([1], [1]~)
%4 = 0
@eprog
Function: lfun
Class: basic
Section: l_functions
C-Name: lfun0
Prototype: GGD0,L,b
Help: lfun(L,s,{D=0}): compute the L-function value L(s), or
if D is set, the derivative of order D at s. L is either an
Lmath, an Ldata or an Linit.
Description:
(gen,gen):gen:prec lfun($1, $2, $bitprec)
(gen,gen,?0):gen:prec lfun($1, $2, $bitprec)
(gen,gen,small):gen:prec lfun0($1, $2, $3, $bitprec)
Doc: compute the L-function value $L(s)$, or if \kbd{D} is set, the
derivative of order \kbd{D} at $s$. The parameter
\kbd{L} is either an Lmath, an Ldata (created by \kbd{lfuncreate}, or an
Linit (created by \kbd{lfuninit}), preferrably the latter if many values
are to be computed.
The argument $s$ is also allowed to be a power series; for instance, if $s =
\alpha + x + O(x^n)$, the function returns the Taylor expansion of order $n$
around $\alpha$. The result is given with absolute error less than $2^{-B}$,
where $B = \text{realbitprecision}$.
\misctitle{Caveat} The requested precision has a major impact on runtimes.
It is advised to manipulate precision via \tet{realbitprecision} as
explained above instead of \tet{realprecision} as the latter allows less
granularity: \kbd{realprecision} increases by increments of 64 bits, i.e. 19
decimal digits at a time.
\bprog
? lfun(x^2+1, 2) \\ Lmath: Dedekind zeta for Q(i) at 2
%1 = 1.5067030099229850308865650481820713960
? L = lfuncreate(ellinit("5077a1")); \\ Ldata: Hasse-Weil zeta function
? lfun(L, 1+x+O(x^4)) \\ zero of order 3 at the central point
%3 = 0.E-58 - 5.[...] E-40*x + 9.[...] E-40*x^2 + 1.7318[...]*x^3 + O(x^4)
\\ Linit: zeta(1/2+it), |t| < 100, and derivative
? L = lfuninit(1, [100], 1);
? T = lfunzeros(L, [1,25]);
%5 = [14.134725[...], 21.022039[...]]
? z = 1/2 + I*T[1];
? abs( lfun(L, z) )
%7 = 8.7066865533412207420780392991125136196 E-39
? abs( lfun(L, z, 1) )
%8 = 0.79316043335650611601389756527435211412 \\ simple zero
@eprog
Function: lfunabelianrelinit
Class: basic
Section: l_functions
C-Name: lfunabelianrelinit
Prototype: GGGGD0,L,b
Help: lfunabelianrelinit(bnfL,bnfK,polrel,sdom,{der=0}): returns the
Linit structure attached to the Dedekind zeta function of the number field
L, given a subfield K such that L/K is abelian, where polrel defines
L over K. The priority of the variable
of bnfK must be lower than that of polrel; bnfL is the absolute polynomial
corresponding to polrel, and sdom and der are as in lfuninit.
Doc: returns the \kbd{Linit} structure attached to the Dedekind zeta function
of the number field $L$ (see \tet{lfuninit}), given a subfield $K$ such that
$L/K$ is abelian.
Here \kbd{polrel} defines $L$ over $K$, as usual with the priority of the
variable of \kbd{bnfK} lower than that of \kbd{polrel}.
\kbd{sdom} and \kbd{der} are as in \kbd{lfuninit}.
\bprog
? D = -47; K = bnfinit(y^2-D);
? rel = quadhilbert(D); T = rnfequation(K.pol, rel); \\ degree 10
? L = lfunabelianrelinit(T,K,rel, [2,0,0]); \\ at 2
time = 84 ms.
? lfun(L, 2)
%4 = 1.0154213394402443929880666894468182650
? lfun(T, 2) \\ using parisize > 300MB
time = 652 ms.
%5 = 1.0154213394402443929880666894468182656
@eprog\noindent As the example shows, using the (abelian) relative structure
is more efficient than a direct computation. The difference becomes drastic
as the absolute degree increases while the subfield degree remains constant.
Function: lfunan
Class: basic
Section: l_functions
C-Name: lfunan
Prototype: GLp
Help: lfunan(L,n): compute the first n terms of the Dirichlet series
attached to the L-function given by L (Lmath, Ldata or Linit).
Doc: Compute the first $n$ terms of the Dirichlet series attached to the
$L$-function given by \kbd{L} (\kbd{Lmath}, \kbd{Ldata} or \kbd{Linit}).
\bprog
? lfunan(1, 10) \\ Riemann zeta
%1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
? lfunan(5, 10) \\ Dirichlet L-function for kronecker(5,.)
%2 = [1, -1, -1, 1, 0, 1, -1, -1, 1, 0]
@eprog
Function: lfunartin
Class: basic
Section: l_functions
C-Name: lfunartin
Prototype: GGGL
Help: lfunartin(nf,gal,M,n): returns the Ldata structure attached to the
Artin L-function attached to the representation R of the Galois group
of the extension K/Q, defined over the cyclotomic field Q(zeta_n),
where nf is the nfinit structure attached to K,
gal is the galoisinit structure attached to K/Q, and M is the vector
of the image of the generators G.gen by R. The elements of M are matrices
with polynomial entries, whose variable is understood as the complex
number exp(2*I*Pi/n).
Doc: returns the \kbd{Ldata} structure attached to the
Artin $L$-function attached to the representation $\rho$ of the Galois group
of the extension $K/\Q$, defined over the cyclotomic field $\Q(\zeta_n)$,
where \var{nf} is the nfinit structure attached to $K$,
\var{gal} is the galoisinit structure attached to $K/\Q$, and $M$ is
the vector of the image of the generators \kbd{\var{gal}.gen} by $\rho$.
The elements of $M$ are matrices with polynomial entries, whose variable
is understood as the complex number $\exp(2\*i\*\pi/n)$.
In the following example we build the Artin $L$-functions attached to the two
irreducible degree $2$ representations of the dihedral group $D_{10}$ defined
over $\Q(\zeta_5)$, for the extension $H/\Q$ where $H$ is the Hilbert class
field of $\Q(\sqrt{-47})$.
We show numerically some identities involving Dedekind $\zeta$ functions and
Hecke $L$ series.
\bprog
? P = quadhilbert(-47);
? N = nfinit(nfsplitting(P));
? G = galoisinit(N);
? L1 = lfunartin(N,G, [[a,0;0,a^-1],[0,1;1,0]], 5);
? L2 = lfunartin(N,G, [[a^2,0;0,a^-2],[0,1;1,0]], 5);
? s = 1 + x + O(x^4);
? lfun(1,s)*lfun(-47,s)*lfun(L1,s)^2*lfun(L2,s)^2 - lfun(N,s)
%6 ~ 0
? lfun(1,s)*lfun(L1,s)*lfun(L2,s) - lfun(P,s)
%7 ~ 0
? bnr = bnrinit(bnfinit(x^2+47),1,1);
? lfun([bnr,[1]], s) - lfun(L1, s)
%9 ~ 0
? lfun([bnr,[1]], s) - lfun(L1, s)
%10 ~ 0
@eprog
The first identity is the factorisation of the regular representation of
$D_{10}$, the second the factorisation of the natural representation of
$D_{10}\subset S_5$, the next two are the expressions of the degree $2$
representations as induced from degree $1$ representations.
Function: lfuncheckfeq
Class: basic
Section: l_functions
C-Name: lfuncheckfeq
Prototype: lGDGb
Help: lfuncheckfeq(L,{t}): given an L-function (Lmath, Ldata or Linit),
check whether the functional equation is satisfied. If the function has
poles, the polar part must be specified. The program returns a bit accuracy
which should be a large negative value close to the current bit accuracy.
If t is given, it checks the functional equation for the theta function
at t and 1/t.
Doc: Given the data attached to an $L$-function (\kbd{Lmath}, \kbd{Ldata}
or \kbd{Linit}), check whether the functional equation is satisfied.
This is most useful for an \kbd{Ldata} constructed ``by hand'', via
\kbd{lfuncreate}, to detect mistakes.
If the function has poles, the polar part must be specified. The routine
returns a bit accuracy $b$ such that $|w - \hat{w}| < 2^{b}$, where $w$ is
the root number contained in \kbd{data}, and $\hat{w}$ is a computed value
derived from $\overline{\theta}(t)$ and $\theta(1/t)$ at some $t\neq 0$ and
the assumed functional equation. Of course, a large negative value of the
order of \kbd{realbitprecision} is expected.
If $t$ is given, it should be close to the unit disc for efficiency and
such that $\overline{\theta}(t) \neq 0$. We then check the functional
equation at that $t$.
\bprog
? \pb 128 \\ 128 bits of accuracy
? default(realbitprecision)
%1 = 128
? L = lfuncreate(1); \\ Riemann zeta
? lfuncheckfeq(L)
%3 = -124
@eprog\noindent i.e. the given data is consistent to within 4 bits for the
particular check consisting of estimating the root number from all other
given quantities. Checking away from the unit disc will either fail with
a precision error, or give disappointing results (if $\theta(1/t)$ is
large it will be computed with a large absolute error)
\bprog
? lfuncheckfeq(L, 2+I)
%4 = -115
? lfuncheckfeq(L,10)
*** at top-level: lfuncheckfeq(L,10)
*** ^------------------
*** lfuncheckfeq: precision too low in lfuncheckfeq.
@eprog
Function: lfunconductor
Class: basic
Section: l_functions
C-Name: lfunconductor
Prototype: GDGD0,L,b
Help: lfunconductor(L,{ab=[1,10000]},{flag=0}): give the conductor
of the given L-function; ab = [a,b] is the interval where we expect
to find the conductor.
If flag=0 (default), give either the conductor found as an integer, or a
vector (possibly empty) of conductors found. If flag=1, same but give the
computed floating point approximations to the conductors found, without
rounding to integers.
If flag=2, give all the conductors found, even those far from integers.
Note: this program is heuristic and should only be used if the primes
dividing the conductor are unknown. If they are known, a direct search
through possible prime exponents using lfuncheckfeq will be more efficient.
Doc: Compute the conductor of the given $L$-function
(if the structure contains a conductor, it is ignored);
$\kbd{ab} = [a,b]$ is the interval where we expect to find the conductor;
it may be given as a single scalar $b$, in which case we look in $[1,b]$.
Increasing \kbd{ab} slows down the program but gives better accuracy for the
result.
If \kbd{flag} is $0$ (default), give either the conductor found as an
integer, or a vector (possibly empty) of conductors found. If \kbd{flag} is
$1$, same but give the computed floating point approximations to the
conductors found, without rounding to integers. It \kbd{flag} is $2$, give
all the conductors found, even those far from integers.
\misctitle{Caveat} This is a heuristic program and the result is not
proven in any way:
\bprog
? L = lfuncreate(857); \\ Dirichlet L function for kronecker(857,.)
? \p19
realprecision = 19 significant digits
? lfunconductor(L)
%2 = [17, 857]
? lfunconductor(L,,1) \\ don't round
%3 = [16.99999999999999999, 857.0000000000000000]
? \p38
realprecision = 38 significant digits
? lfunconductor(L)
%4 = 857
@eprog
\misctitle{Note} This program should only be used if the primes dividing the
conductor are unknown, which is rare. If they are known, a direct
search through possible prime exponents using \kbd{lfuncheckfeq} will
be more efficient and rigorous:
\bprog
? E = ellinit([0,0,0,4,0]); /* Elliptic curve y^2 = x^3+4x */
? E.disc \\ |disc E| = 2^12
%2 = -4096
\\ create Ldata by hand. Guess that root number is 1 and conductor N
? L(N) = lfuncreate([n->ellan(E,n), 0, [0,1], 1, N, 1]);
? fordiv(E.disc, d, print(d,": ",lfuncheckfeq(L(d))))
1: 0
2: 0
4: -1
8: -2
16: -3
32: -127
64: -3
128: -2
256: -2
512: -1
1024: -1
2048: 0
4096: 0
? lfunconductor(L(1)) \\ lfunconductor ignores conductor = 1 in Ldata !
%5 = 32
@eprog\noindent The above code assumed that root number was $1$;
had we set it to $-1$, none of the \kbd{lfuncheckfeq} values would have been
acceptable:
\bprog
? L2(N) = lfuncreate([n->ellan(E,n), 0, [0,1], 1, N, -1]);
? [ lfuncheckfeq(L2(d)) | d<-divisors(E.disc) ]
%7 = [0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, -1, -1]
@eprog
Function: lfuncost
Class: basic
Section: l_functions
C-Name: lfuncost0
Prototype: GDGD0,L,b
Help: lfuncost(L,{sdom},{der=0}): estimate the cost of running
lfuninit(L,sdom,der) at current bit precision. Returns [t,b], to indicate
that t coefficients a_n will be computed at bit accuracy b. Subsequent
evaluation of lfun at s evaluates a polynomial of degree t at exp(h s).
If L is already an Linit, then sdom and der are ignored.
Doc: estimate the cost of running
\kbd{lfuninit(L,sdom,der)} at current bit precision. Returns $[t,b]$, to
indicate that $t$ coefficients $a_n$ will be computed, as well as $t$ values of
\tet{gammamellininv}, all at bit accuracy $b$.
A subsequent call to \kbd{lfun} at $s$ evaluates a polynomial of degree $t$
at $\exp(h s)$ for some real parameter $h$, at the same bit accuracy $b$.
If $L$ is already an \kbd{Linit}, then \var{sdom} and \var{der} are ignored
and are best left omitted; the bit accuracy is also inferred from $L$: in
short we get an estimate of the cost of using that particular \kbd{Linit}.
\bprog
? \pb 128
? lfuncost(1, [100]) \\ for zeta(1/2+I*t), |t| < 100
%1 = [7, 242] \\ 7 coefficients, 242 bits
? lfuncost(1, [1/2, 100]) \\ for zeta(s) in the critical strip, |Im s| < 100
%2 = [7, 246] \\ now 246 bits
? lfuncost(1, [100], 10) \\ for zeta(1/2+I*t), |t| < 100
%3 = [8, 263] \\ 10th derivative increases the cost by a small amount
? lfuncost(1, [10^5])
%3 = [158, 113438] \\ larger imaginary part: huge accuracy increase
? L = lfuncreate(polcyclo(5)); \\ Dedekind zeta for Q(zeta_5)
? lfuncost(L, [100]) \\ at s = 1/2+I*t), |t| < 100
%5 = [11457, 582]
? lfuncost(L, [200]) \\ twice higher
%6 = [36294, 1035]
? lfuncost(L, [10^4]) \\ much higher: very costly !
%7 = [70256473, 45452]
? \pb 256
? lfuncost(L, [100]); \\ doubling bit accuracy
%8 = [17080, 710]
@eprog\noindent In fact, some $L$ functions can be factorized algebraically
by the \kbd{lfuninit} call, e.g. the Dedekind zeta function of abelian
fields, leading to much faster evaluations than the above upper bounds.
In that case, the function returns a vector of costs as above for each
individual function in the product actually evaluated:
\bprog
? L = lfuncreate(polcyclo(5)); \\ Dedekind zeta for Q(zeta_5)
? lfuncost(L, [100]) \\ a priori cost
%2 = [11457, 582]
? L = lfuninit(L, [100]); \\ actually perform all initializations
? lfuncost(L)
%4 = [[16, 242], [16, 242], [7, 242]]
@eprog\noindent The Dedekind function of this abelian quartic field
is the product of four Dirichlet $L$-functions attached to the trivial
character, a non-trivial real character and two complex conjugate
characters. The non-trivial characters happen to have the same conductor
(hence same evaluation costs), and correspond to two evaluations only
since the two conjugate characters are evaluated simultaneously.
For a total of three $L$-functions evaluations, which explains the three
components above. Note that the actual cost is much lower than the a priori
cost in this case.
Variant: Also available is
\fun{GEN}{lfuncost}{GEN L, GEN dom, long der, long bitprec}
when $L$ is \emph{not} an \kbd{Linit}; the return value is a \typ{VECSMALL}
in this case.
Function: lfuncreate
Class: basic
Section: l_functions
C-Name: lfuncreate
Prototype: G
Help: lfuncreate(obj): given either an object such as a polynomial, elliptic
curve, Dirichlet or Hecke character, eta quotient, etc., or an explicit
6 or 7 component vector [dir,real,Vga,k,N,eps,r],
create the Ldata structure necessary for lfun computation.
Doc: This low-level routine creates \tet{Ldata} structures, needed by
\var{lfun} functions, describing an $L$-function and its functional equation.
You are urged to use a high-level constructor when one is available,
and this function accepts them, see \kbd{??lfun}:
\bprog
? L = lfuncreate(1); \\ Riemann zeta
? L = lfuncreate(5); \\ Dirichlet L-function for quadratic character (5/.)
? L = lfuncreate(x^2+1); \\ Dedekind zeta for Q(i)
? L = lfuncreate(ellinit([0,1])); \\ L-function of E/Q: y^2=x^3+1
@eprog\noindent One can then use, e.g., \kbd{Lfun(L,s)} to directly
evaluate the respective $L$-functions at $s$, or \kbd{lfuninit(L, [c,w,h]}
to initialize computations in the rectangular box $\Re(s-c) \leq w$,
$\Im(s) \leq h$.
We now describe the low-level interface, used to input non-builtin
$L$-functions. The input is now a $6$ or $7$ component vector
$V=[a,astar,Vga,k,N,eps,poles]$, whose components are as follows:
\item \kbd{V[1]=a} encodes the Dirichlet series coefficients. The
preferred format is a closure of arity 1: \kbd{n->vector(n,i,a(i))} giving
the vector of the first $n$ coefficients. The closure is allowed to return
a vector of more than $n$ coefficients (only the first $n$ will be
considered) or even less than $n$, in which case loss of accuracy will occur
and a warning that \kbd{\#an} is less than expected is issued. This
allows to precompute and store a fixed large number of Dirichlet
coefficients in a vector $v$ and use the closure \kbd{n->v}, which
does not depend on $n$. As a shorthand for this latter case, you can input
the vector $v$ itself instead of the closure.
A second format is limited to multiplicative $L$ functions affording an
Euler product. It is a closure of arity 2 \kbd{(p,d)->L(p)} giving the local
factor $L_p$ at $p$ as a rational function, to be evaluated at $p^{-s}$ as in
\kbd{direuler}; $d$ is set to the floor of $\log_p(n)$, where $n$ is the
total number of Dirichlet coefficients $(a_1,\dots,a_n)$ that will be
computed in this way. This parameter $d$ allows to compute only part of $L_p$
when $p$ is large and $L_p$ expensive to compute, but it can of course be
ignored by the closure.
Finally one can describe separately the generic Dirichlet coefficients
and the bad local factors by setting $\kbd{dir} = [an, [p_1,L^{-1}_{p_1}],
\dots,[p_k,L^{-1}_{p_k}]]$, where \kbd{an} describes the generic coefficients
in one of the two formats above, except that coefficients $a_n$ with
$p_i \mid n$ for some $i \leq k$ will be ignored. The subsequent pairs $[p,
L_p^{-1}]$ give the bad primes and corresponding \emph{inverse} local
factors.
\item \kbd{V[2]=astar} is the Dirichlet series coefficients of the dual
function, encoded as \kbd{a} above. The sentinel values $0$ and $1$ may
be used for the special cases where $a = a^*$ and $a = \overline{a^*}$,
respectively.
\item \kbd{V[3]=Vga} is the vector of $\alpha_j$ such that the gamma
factor of the $L$-function is equal to
$$\gamma_A(s)=\prod_{1\le j\le d}\Gamma_{\R}(s+\alpha_j),$$
where $\Gamma_{\R}(s)=\pi^{-s/2}\Gamma(s/2)$.
This same syntax is used in the \kbd{gammamellininv} functions.
In particular the length $d$ of \kbd{Vga} is the degree of the $L$-function.
In the present implementation, the $\alpha_j$ are assumed to be exact
rational numbers. However when calling theta functions with \emph{complex}
(as opposed to real) arguments, determination problems occur which may
give wrong results when the $\alpha_j$ are not integral.
\item \kbd{V[4]=k} is a positive integer $k$. The functional equation relates
values at $s$ and $k-s$. For instance, for an Artin $L$-series such as a
Dedekind zeta function we have $k = 1$, for an elliptic curve $k = 2$, and
for a modular form, $k$ is its weight. For motivic $L$-functions, the
\emph{motivic} weight $w$ is $w = k-1$.
\item \kbd{V[5]=N} is the conductor, an integer $N\ge1$, such that
$\Lambda(s)=N^{s/2}\gamma_A(s)L(s)$ with $\gamma_A(s)$ as above.
\item \kbd{V[6]=eps} is the root number $\varepsilon$, i.e., the
complex number (usually of modulus $1$) such that
$\Lambda(a, k-s) = \varepsilon \Lambda(a^*, s)$.
\item The last optional component \kbd{V[7]=poles} encodes the poles of the
$L$ or $\Lambda$-functions, and is omitted if they have no poles.
A polar part is given by a list of $2$-component vectors
$[\beta,P_{\beta}(x)]$, where
$\beta$ is a pole and the power series $P_{\beta}(x)$ describes
the attached polar part, such that $L(s) - P_\beta(s-\beta)$ is holomorphic
in a neighbourhood of $\beta$. For instance $P_\beta = r/x+O(1)$ for a
simple pole at $\beta$ or $r_1/x^2+r_2/x+O(1)$ for a double pole.
The type of the list describing the polar part allows to distinguish between
$L$ and $\Lambda$: a \typ{VEC} is attached to $L$, and a \typ{COL}
is attached to $\Lambda$.
The latter is mandatory unless $a = \overline{a^*}$ (coded by \kbd{astar}
equal to $0$ or $1$): otherwise, the poles of $L^*$ cannot be infered from
the poles of $L$ ! (Whereas the functional equation allows to deduce
the polar part of $\Lambda^*$ from the polar part of $\Lambda$.)
The special coding $\kbd{poles} = r$ a complex scalar is available in this
case, to describe a $L$ function with at most a single simple pole at $s =
k$ and residue $r$. (This is the usual situation, for instance for Dedekind
zeta functions.) This value $r$ can be set to $0$ if unknown, and it will be
computed.
Function: lfundiv
Class: basic
Section: l_functions
C-Name: lfundiv
Prototype: GGb
Help: lfundiv(L1,L2): creates the Ldata structure (without
initialization) corresponding to the quotient of the Dirichlet series
given by L1 and L2.
Doc: creates the \kbd{Ldata} structure (without initialization) corresponding
to the quotient of the Dirichlet series $L_1$ and $L_2$ given by
\kbd{L1} and \kbd{L2}. Assume that $v_z(L_1) \geq v_z(L_2)$ at all
complex numbers $z$: the construction may not create new poles, nor increase
the order of existing ones.
Function: lfunetaquo
Class: basic
Section: l_functions
C-Name: lfunetaquo
Prototype: G
Help: lfunetaquo(M): returns the Ldata structure attached to the
modular form z->prod(i=1,#M[,1],eta(M[i,1]*z)^M[i,2]).
Doc: returns the \kbd{Ldata} structure attached to the $L$ function
attached to the modular form
$z\mapsto \prod_{i=1}^n \eta(M_{i,1}\*z)^{M_{i,2}}$
It is currently assumed that $f$ is a self-dual cuspidal form on
$\Gamma_0(N)$ for some $N$.
For instance, the $L$-function $\sum \tau(n) n^{-s}$
attached to Ramanujan's $\Delta$ function is encoded as follows
\bprog
? L = lfunetaquo(Mat([1,24]));
? lfunan(L, 100) \\ first 100 values of tau(n)
@eprog
Function: lfungenus2
Class: basic
Section: l_functions
C-Name: lfungenus2
Prototype: G
Help: lfungenus2(F): returns the Ldata structure attached to the
L-function attached to the genus-2 curve defined by y^2=F(x)
or y^2+Q(x)*y=P(x) if F=[P,Q].
Currently, only odd conductors are supported, and the model needs to
be minimal at 2.
Doc: returns the \kbd{Ldata} structure attached to the $L$ function
attached to the genus-2 curve defined by $y^2=F(x)$ or
$y^2+Q(x)\*y=P(x)$ if $F=[P,Q]$.
Currently, the model needs to be minimal at 2, and if the conductor
is even, its valuation at $2$ might be incorrect (a warning is issued).
Function: lfunhardy
Class: basic
Section: l_functions
C-Name: lfunhardy
Prototype: GGb
Help: lfunhardy(L,t): variant of the Hardy L-function attached to L, used for
plotting on the critical line.
Doc: Variant of the Hardy $Z$-function given by \kbd{L}, used for
plotting or locating zeros of $L(k/2+it)$ on the critical line.
The precise definition is as
follows: if as usual $k/2$ is the center of the critical strip, $d$ is the
degree, $\alpha_j$ the entries of \kbd{Vga} giving the gamma factors,
and $\varepsilon$ the root number, then if we set
$s = k/2+it = \rho e^{i\theta}$ and
$E=(d(k/2-1)+\sum_{1\le j\le d}\alpha_j)/2$, the computed function at $t$ is
equal to
$$Z(t) = \varepsilon^{-1/2}\Lambda(s) \cdot |s|^{-E}e^{dt\theta/2}\;,$$
which is a real function of $t$ for self-dual $\Lambda$,
vanishing exactly when $L(k/2+it)$ does on the critical line. The
normalizing factor $|s|^{-E}e^{dt\theta/2}$ compensates the
exponential decrease of $\gamma_A(s)$ as $t\to\infty$ so that
$Z(t) \approx 1$.
\bprog
? T = 100; \\ maximal height
? L = lfuninit(1, [T]); \\ initialize for zeta(1/2+it), |t|<T
? \p19 \\ no need for large accuracy
? ploth(t = 0, T, lfunhardy(L,t))
@eprog\noindent Using \kbd{lfuninit} is critical for this particular
applications since thousands of values are computed. Make sure to initialize
up to the maximal $t$ needed: otherwise expect to see many warnings for
unsufficient initialization and suffer major slowdowns.
Function: lfuninit
Class: basic
Section: l_functions
C-Name: lfuninit0
Prototype: GGD0,L,b
Help: lfuninit(L,sdom,{der=0}): precompute data
for evaluating the L-function given by 'L' (and its derivatives
of order der, if set) in rectangular domain sdom = [center,w,h]
centered on the real axis, |Re(s)-center| <= w, |Im(s)| <= h,
where all three components of sdom are real and w,h are non-negative.
The subdomain [k/2, 0, h] on the critical line can be encoded as [h] for
brevity.
Doc: initalization function for all functions linked to the
computation of the $L$-function $L(s)$ encoded by \kbd{L}, where
$s$ belongs to the rectangular domain $\kbd{sdom} = [\var{center},w,h]$
centered on the real axis, $|\Re(s)-\var{center}| \leq w$, $|\Im(s)| \leq h$,
where all three components of \kbd{sdom} are real and $w$, $h$ are
non-negative. \kbd{der} is the maximum order of derivation that will be used.
The subdomain $[k/2, 0, h]$ on the critical line (up to height $h$)
can be encoded as $[h]$ for brevity. The subdomain $[k/2, w, h]$
centered on the critical line can be encoded as $[w, h]$ for brevity.
The argument \kbd{L} is an \kbd{Lmath}, an \kbd{Ldata} or an \kbd{Linit}. See
\kbd{??Ldata} and \kbd{??lfuncreate} for how to create it.
The height $h$ of the domain is a \emph{crucial} parameter: if you only
need $L(s)$ for real $s$, set $h$ to~0.
The running time is roughly proportional to
$$(B / d+\pi h/4)^{d/2+3}N^{1/2},$$
where $B$ is the default bit accuracy, $d$ is the degree of the
$L$-function, and $N$ is the conductor (the exponent $d/2+3$ is reduced
to $d/2+2$ when $d=1$ and $d=2$). There is also a dependency on $w$,
which is less crucial, but make sure to use the smallest rectangular
domain that you need.
\bprog
? L0 = lfuncreate(1); \\ Riemann zeta
? L = lfuninit(L0, [1/2, 0, 100]); \\ for zeta(1/2+it), |t| < 100
? lfun(L, 1/2 + I)
? L = lfuninit(L0, [100]); \\ same as above !
@eprog
Function: lfunlambda
Class: basic
Section: l_functions
C-Name: lfunlambda0
Prototype: GGD0,L,b
Help: lfunlambda(L,s,{D=0}): compute the completed L function Lambda(s),
or if D is set, the derivative of order D at s. L is either
an Lmath, an Ldata or an Linit.
Doc: compute the completed $L$-function $\Lambda(s) = N^{s/2}\gamma(s)L(s)$,
or if \kbd{D} is set, the derivative of order \kbd{D} at $s$.
The parameter \kbd{L} is either an \kbd{Lmath}, an \kbd{Ldata} (created by
\kbd{lfuncreate}, or an \kbd{Linit} (created by \kbd{lfuninit}), preferrably the
latter if many values are to be computed.
The result is given with absolute error less than $2^{-B}|\gamma(s)N^{s/2}|$,
where $B = \text{realbitprecision}$.
Function: lfunmfspec
Class: basic
Section: l_functions
C-Name: lfunmfspec
Prototype: Gb
Help: lfunmfspec(L): L corresponding to a modular form, returns
[valeven,valodd,omminus,omplus], where valeven (resp., valodd) is the vector
of even (resp., odd) periods, and omminus and omplus the corresponding
real numbers omega^- and omega^+. For the moment, only for modular forms of even weight.
Doc: returns \kbd{[valeven,valodd,omminus,omplus]},
where \kbd{valeven} (resp., \kbd{valodd}) is the vector of even (resp., odd)
periods of the modular form given by \kbd{L}, and \kbd{omminus} and
\kbd{omplus} the corresponding real numbers $\omega^-$ and $\omega^+$
normalized in a noncanonical way. For the moment, only for modular forms of even weight.
Function: lfunmul
Class: basic
Section: l_functions
C-Name: lfunmul
Prototype: GGb
Help: lfunmul(L1,L2): creates the Ldata structure (without
initialization) corresponding to the product of the Dirichlet series
given by L1 and L2.
Doc: creates the \kbd{Ldata} structure (without initialization) corresponding
to the product of the Dirichlet series given by \kbd{L1} and
\kbd{L2}.
Function: lfunorderzero
Class: basic
Section: l_functions
C-Name: lfunorderzero
Prototype: lGD-1,L,b
Help: lfunorderzero(L, {m = -1}): computes the order of the possible zero
of the L-function at the center k/2 of the critical strip. If $m$ is
given and has a non-negative value, assumes the order is at most $m$.
Doc: Computes the order of the possible zero of the $L$-function at the
center $k/2$ of the critical strip; return $0$ if $L(k/2)$ does not vanish.
If $m$ is given and has a non-negative value, assumes the order is at most $m$.
Otherwise, the algorithm chooses a sensible default:
\item if the $L$ argument is an \kbd{Linit}, assume that a multiple zero at
$s = k / 2$ has order less than or equal to the maximal allowed derivation
order.
\item else assume the order is less than $4$.
You may explicitly increase this value using optional argument~$m$; this
overrides the default value above. (Possibly forcing a recomputation
of the \kbd{Linit}.)
Function: lfunqf
Class: basic
Section: l_functions
C-Name: lfunqf
Prototype: Gp
Help: lfunqf(Q): returns the Ldata structure attached to the
theta function of the lattice attached to the definite positive quadratic
form Q.
Doc: returns the \kbd{Ldata} structure attached to the $\Theta$ function
of the lattice attached to the definite positive quadratic form $Q$.
\bprog
? L = lfunqf(matid(2));
? lfunqf(L,2)
%2 = 6.0268120396919401235462601927282855839
? lfun(x^2+1,2)*4
%3 = 6.0268120396919401235462601927282855839
@eprog
Function: lfunrootres
Class: basic
Section: l_functions
C-Name: lfunrootres
Prototype: Gb
Help: lfunrootres(data): given the Ldata attached to an L-function (or the
output of lfunthetainit), compute the root number and the
residues. In the present implementation, if the polar part is not already
known completely, at most a single pole is allowed.
The output is a 3-component vector [r,R,w], where r is the residue of L(s)
at the unique pole (0 if no pole), R is the residue of Lambda(s), and w is
the root number.
Doc: Given the \kbd{Ldata} attached to an $L$-function (or the output of
\kbd{lfunthetainit}), compute the root number and the residues.
The output is a 3-component vector $[r,R,w]$, where $r$ is the
residue of $L(s)$ at the unique pole, $R$ is the residue of $\Lambda(s)$,
and $w$ is the root number. In the present implementation,
\item either the polar part must be completely known (and is then arbitrary):
the function determines the root number,
\bprog
? L = lfunmul(1,1); \\ zeta^2
? [r,R,w] = lfunrootres(L);
? r \\ single pole at 1, double
%3 = [[1, 1.[...]*x^-2 + 1.1544[...]*x^-1 + O(x^0)]]
? w
%4 = 1
? R \\ double pole at 0 and 1
%5 = [[1,[...]], [0,[...]]
@eprog
\item or at most a single pole is allowed: the function computes both
the root number and the residue ($0$ if no pole).
Function: lfuntheta
Class: basic
Section: l_functions
C-Name: lfuntheta
Prototype: GGD0,L,b
Help: lfuntheta(data,t,{m=0}): compute the value of the m-th derivative
at t of the theta function attached to the L-function given by data.
data can be either the standard L-function data, or the output of
lfunthetainit.
Doc: compute the value of the $m$-th derivative
at $t$ of the theta function attached to the $L$-function given by \kbd{data}.
\kbd{data} can be either the standard $L$-function data, or the output of
\kbd{lfunthetainit}.
The theta function is defined by the formula
$\Theta(t)=\sum_{n\ge1}a(n)K(nt/\sqrt(N))$, where $a(n)$ are the coefficients
of the Dirichlet series, $N$ is the conductor, and $K$ is the inverse Mellin
transform of the gamma product defined by the \kbd{Vga} component.
Its Mellin transform is equal to $\Lambda(s)-P(s)$, where $\Lambda(s)$
is the completed $L$-function and the rational function $P(s)$ its polar part.
In particular, if the $L$-function is the $L$-function of a modular form
$f(\tau)=\sum_{n\ge0}a(n)q^n$ with $q=\exp(2\pi i\tau)$, we have
$\Theta(t)=2(f(it/\sqrt{N})-a(0))$. Note that an easy theorem on modular
forms implies that $a(0)$ can be recovered by the formula $a(0)=-L(f,0)$.
Function: lfunthetacost
Class: basic
Section: l_functions
C-Name: lfunthetacost0
Prototype: lGDGD0,L,b
Help: lfunthetacost(L,{tdom},{m=0}): estimates the cost of running
lfunthetainit(L,tdom,m) at current bit precision. Returns the number of
coefficients an that would be computed. Subsequent evaluation of lfuntheta
computes that many values of gammamellininv.
If L is already an Linit, then tdom and m are ignored.
Doc: This function estimates the cost of running
\kbd{lfunthetainit(L,tdom,m)} at current bit precision. Returns the number of
coefficients $a_n$ that would be computed. This also estimates the
cost of a subsequent evaluation \kbd{lfuntheta}, which must compute
that many values of \kbd{gammamellininv} at the current bit precision.
If $L$ is already an \kbd{Linit}, then \var{tdom} and $m$ are ignored
and are best left omitted: we get an estimate of the cost of using that
particular \kbd{Linit}.
\bprog
? \pb 1000
? L = lfuncreate(1); \\ Riemann zeta
? lfunthetacost(L); \\ cost for theta(t), t real >= 1
%1 = 15
? lfunthetacost(L, 1 + I); \\ cost for theta(1+I). Domain error !
*** at top-level: lfunthetacost(1,1+I)
*** ^--------------------
*** lfunthetacost: domain error in lfunthetaneed: arg t > 0.785
? lfunthetacost(L, 1 + I/2) \\ for theta(1+I/2).
%2 = 23
? lfunthetacost(L, 1 + I/2, 10) \\ for theta^((10))(1+I/2).
%3 = 24
? lfunthetacost(L, [2, 1/10]) \\ cost for theta(t), |t| >= 2, |arg(t)| < 1/10
%4 = 8
? L = lfuncreate( ellinit([1,1]) );
? lfunthetacost(L) \\ for t >= 1
%6 = 2471
@eprog
Function: lfunthetainit
Class: basic
Section: l_functions
C-Name: lfunthetainit
Prototype: GDGD0,L,b
Help: lfunthetainit(L,{tdom},{m=0}): precompute data for evaluating
the m-th derivative of theta functions with argument in domain tdom
(by default t is real >= 1).
Doc: Initalization function for evaluating the $m$-th derivative of theta
functions with argument $t$ in domain \var{tdom}. By default (\var{tdom}
omitted), $t$ is real, $t \geq 1$. Otherwise, \var{tdom} may be
\item a positive real scalar $\rho$: $t$ is real, $t \geq \rho$.
\item a non-real complex number: compute at this particular $t$; this
allows to compute $\theta(z)$ for any complex $z$ satisfying $|z|\geq |t|$
and $|\arg z| \leq |\arg t|$; we must have $|2 \arg z / d| < \pi/2$, where
$d$ is the degree of the $\Gamma$ factor.
\item a pair $[\rho,\alpha]$: assume that $|t| \geq \rho$ and $|\arg t| \leq
\alpha$; we must have $|2\alpha / d| < \pi/2$, where $d$ is the degree of
the $\Gamma$ factor.
\bprog
? \p500
? L = lfuncreate(1); \\ Riemann zeta
? t = 1+I/2;
? lfuntheta(L, t); \\ direct computation
time = 30 ms.
? T = lfunthetainit(L, 1+I/2);
time = 30 ms.
? lfuntheta(T, t); \\ instantaneous
@eprog\noindent The $T$ structure would allow to quickly compute $\theta(z)$
for any $z$ in the cone delimited by $t$ as explained above. On the other hand
\bprog
? lfuntheta(T,I)
*** at top-level: lfuntheta(T,I)
*** ^--------------
*** lfuntheta: domain error in lfunthetaneed: arg t > 0.785398163397448
@eprog
The initialization is equivalent to
\bprog
? lfunthetainit(L, [abs(t), arg(t)])
@eprog
Function: lfunzeros
Class: basic
Section: l_functions
C-Name: lfunzeros
Prototype: GGD8,L,b
Help: lfunzeros(L,lim,{divz=8}): lim being
either an upper limit or a real interval, computes an ordered list of
zeros of L(s) on the critical line up to the given upper limit or in the
given interval. Use a naive algorithm which may miss some zeros.
To use a finer search mesh, set divz to some integral value
larger than the default (= 8).
Doc: \kbd{lim} being either a positive upper limit or a non-empty real
interval inside $[0,+\infty[$, computes an
ordered list of zeros of $L(s)$ on the critical line up to the given
upper limit or in the given interval. Use a naive algorithm which may miss
some zeros: it assumes that two consecutive zeros at height $T \geq 1$
differ at least by $2\pi/\omega$, where
$$\omega := \kbd{divz} \cdot \big(d\log(T/2\pi) +d+ 2\log(N/(\pi/2)^d)\big).$$
To use a finer search mesh, set divz to some integral value
larger than the default (= 8).
\bprog
? lfunzeros(1, 30) \\ zeros of Rieman zeta up to height 30
%1 = [14.134[...], 21.022[...], 25.010[...]]
? #lfunzeros(1, [100,110]) \\ count zeros with 100 <= Im(s) <= 110
%2 = 4
@eprog\noindent The algorithm also assumes that all zeros are simple except
possibly on the real axis at $s = k/2$ and that there are no poles in the
search interval. (The possible zero at $s = k/2$ is repeated according to
its multiplicity.)
Should you pass an \kbd{Linit} argument to the function, beware that the
algorithm needs at least
\bprog
L = lfuninit(Ldata, T+1)
@eprog\noindent where $T$ is the upper bound of the interval defined by
\kbd{lim}: this allows to detect zeros near $T$. Make sure that your
\kbd{Linit} domain contains this one. The algorithm assumes
that a multiple zero at $s = k / 2$ has order less than or equal to
the maximal derivation order allowed by the \kbd{Linit}. You may increase
that value in the \kbd{Linit} but this is costly: only do it for zeros
of low height or in \kbd{lfunorderzero} instead.
Function: lift
Class: basic
Section: conversions
C-Name: lift0
Prototype: GDn
Help: lift(x,{v}):
if v is omitted, lifts elements of Z/nZ to Z, of Qp to Q, and of K[x]/(P) to
K[x]. Otherwise lift only polmods with main variable v.
Description:
(pol):pol lift($1)
(vec):vec lift($1)
(gen):gen lift($1)
(pol, var):pol lift0($1, $2)
(vec, var):vec lift0($1, $2)
(gen, var):gen lift0($1, $2)
Doc:
if $v$ is omitted, lifts intmods from $\Z/n\Z$ in $\Z$,
$p$-adics from $\Q_p$ to $\Q$ (as \tet{truncate}), and polmods to
polynomials. Otherwise, lifts only polmods whose modulus has main
variable~$v$. \typ{FFELT} are not lifted, nor are List elements: you may
convert the latter to vectors first, or use \kbd{apply(lift,L)}. More
generally, components for which such lifts are meaningless (e.g. character
strings) are copied verbatim.
\bprog
? lift(Mod(5,3))
%1 = 2
? lift(3 + O(3^9))
%2 = 3
? lift(Mod(x,x^2+1))
%3 = x
? lift(Mod(x,x^2+1))
%4 = x
@eprog
Lifts are performed recursively on an object components, but only
by \emph{one level}: once a \typ{POLMOD} is lifted, the components of
the result are \emph{not} lifted further.
\bprog
? lift(x * Mod(1,3) + Mod(2,3))
%4 = x + 2
? lift(x * Mod(y,y^2+1) + Mod(2,3))
%5 = y*x + Mod(2, 3) \\@com do you understand this one?
? lift(x * Mod(y,y^2+1) + Mod(2,3), 'x)
%6 = Mod(y, y^2 + 1)*x + Mod(Mod(2, 3), y^2 + 1)
? lift(%, y)
%7 = y*x + Mod(2, 3)
@eprog\noindent To recursively lift all components not only by one level,
but as long as possible, use \kbd{liftall}. To lift only \typ{INTMOD}s and
\typ{PADIC}s components, use \tet{liftint}. To lift only \typ{POLMOD}s
components, use \tet{liftpol}. Finally, \tet{centerlift} allows to lift
\typ{INTMOD}s and \typ{PADIC}s using centered residues (lift of smallest
absolute value).
Variant: Also available is \fun{GEN}{lift}{GEN x} corresponding to
\kbd{lift0(x,-1)}.
Function: liftall
Class: basic
Section: conversions
C-Name: liftall
Prototype: G
Help: liftall(x): lifts every element of Z/nZ to Z, of Qp to Q, and of
K[x]/(P) to K[x].
Description:
(pol):pol liftall($1)
(vec):vec liftall($1)
(gen):gen liftall($1)
Doc:
recursively lift all components of $x$ from $\Z/n\Z$ to $\Z$,
from $\Q_p$ to $\Q$ (as \tet{truncate}), and polmods to
polynomials. \typ{FFELT} are not lifted, nor are List elements: you may
convert the latter to vectors first, or use \kbd{apply(liftall,L)}. More
generally, components for which such lifts are meaningless (e.g. character
strings) are copied verbatim.
\bprog
? liftall(x * (1 + O(3)) + Mod(2,3))
%1 = x + 2
? liftall(x * Mod(y,y^2+1) + Mod(2,3)*Mod(z,z^2))
%2 = y*x + 2*z
@eprog
Function: liftint
Class: basic
Section: conversions
C-Name: liftint
Prototype: G
Help: liftint(x): lifts every element of Z/nZ to Z, of Qp to Q, and of
K[x]/(P) to K[x].
Description:
(pol):pol liftint($1)
(vec):vec liftint($1)
(gen):gen liftint($1)
Doc: recursively lift all components of $x$ from $\Z/n\Z$ to $\Z$ and
from $\Q_p$ to $\Q$ (as \tet{truncate}).
\typ{FFELT} are not lifted, nor are List elements: you may
convert the latter to vectors first, or use \kbd{apply(liftint,L)}. More
generally, components for which such lifts are meaningless (e.g. character
strings) are copied verbatim.
\bprog
? liftint(x * (1 + O(3)) + Mod(2,3))
%1 = x + 2
? liftint(x * Mod(y,y^2+1) + Mod(2,3)*Mod(z,z^2))
%2 = Mod(y, y^2 + 1)*x + Mod(Mod(2*z, z^2), y^2 + 1)
@eprog
Function: liftpol
Class: basic
Section: conversions
C-Name: liftpol
Prototype: G
Help: liftpol(x): lifts every polmod component of x to polynomials.
Description:
(pol):pol liftpol($1)
(vec):vec liftpol($1)
(gen):gen liftpol($1)
Doc: recursively lift all components of $x$ which are polmods to
polynomials. \typ{FFELT} are not lifted, nor are List elements: you may
convert the latter to vectors first, or use \kbd{apply(liftpol,L)}. More
generally, components for which such lifts are meaningless (e.g. character
strings) are copied verbatim.
\bprog
? liftpol(x * (1 + O(3)) + Mod(2,3))
%1 = (1 + O(3))*x + Mod(2, 3)
? liftpol(x * Mod(y,y^2+1) + Mod(2,3)*Mod(z,z^2))
%2 = y*x + Mod(2, 3)*z
@eprog
Function: limitnum
Class: basic
Section: sums
C-Name: limitnum0
Prototype: GD0,L,DGp
Help: limitnum(expr,{k = 20},{alpha=1}): numerical limit of sequence expr
using Lagrange-Zagier extrapolation; k is a multiplier so that we extrapolate
from expr(k*n). Assume u(n) ~ sum a_i n^(-alpha*i). flag=2, assuming that the
asymptotic expansion is in powers of 1/n^2.
Doc: Lagrange-Zagier numerical extrapolation of \var{expr}, corresponding to a
sequence
$u_n$, either given by a closure \kbd{n->u(n)} or by a vector of values
I.e., assuming that $u_n$ tends to a finite limit $\ell$, try to determine
$\ell$. This routine is purely numerical and heuristic, thus may or may not
work on your examples; $k$ is ignored if $u$ is given by a vector,
and otherwise is a multiplier such that we extrapolate from $u(kn)$.
Assume that $u_n$ has an asymptotic expansion in $n^{-\alpha}$ :
$$u_n = \ell + \sum_{i\geq 1} a_i n^{-i\alpha}$$
for some $a_i$.
\bprog
? limitnum(n -> n*sin(1/n))
%1 = 1.0000000000000000000000000000000000000
? limitnum(n -> (1+1/n)^n) - exp(1)
%2 = 0.E-37
? limitnum(n -> 2^(4*n+1)*(n!)^4 / (2*n)! /(2*n+1)! )
%3 = 3.1415926535897932384626433832795028842
? Pi
%4 = 3.1415926535897932384626433832795028842
@eprog\noindent
If $u_n$ is given by a vector, it must be long enough for the extrapolation
to make sense: at least $k$ times the current \kbd{realprecision}. The
preferred format is thus a closure, although it becomes inconvenient
when $u_n$ cannot be directly computed in time polynomial in $\log n$,
for instance if it is defined as a sum or by induction. In that case,
passing a vector of values is the best option. It usually pays off to
interpolate $u(kn)$ for some $k > 1$:
\bprog
? limitnum(vector(10,n,(1+1/n)^n))
*** ^--------------------
*** limitnum: non-existent component in limitnum: index < 20
\\ at this accuracy, we must have at least 20 values
? limitnum(vector(20,n,(1+1/n)^n)) - exp(1)
%5 = -2.05... E-20
? limitnum(vector(20,n, m=10*n;(1+1/m)^m)) - exp(1) \\ better accuracy
%6 = 0.E-37
? v = vector(20); s = 0;
? for(i=1,#v, s += 1/i; v[i]= s - log(i));
? limitnum(v) - Euler
%9 = -1.6... E-19
? V = vector(200); s = 0;
? for(i=1,#V, s += 1/i; V[i]= s);
? v = vector(#V \ 10, i, V[10*i] - log(10*i));
? limitnum(v) - Euler
%13 = 6.43... E-29
@eprog
\synt{limitnum}{void *E, GEN (*u)(void *,GEN,long), long muli, GEN alpha, long prec}, where \kbd{u(E, n, prec)} must return $u(n)$ in precision \kbd{prec}.
Also available is
\fun{GEN}{limitnum0}{GEN u, long muli, GEN alpha, long prec}, where $u$
must be a vector of sufficient length as above.
Function: lindep
Class: basic
Section: linear_algebra
C-Name: lindep0
Prototype: GD0,L,
Help: lindep(v,{flag=0}): integral linear dependencies between components of v.
flag is optional, and can be 0: default, guess a suitable
accuracy, or positive: accuracy to use for the computation, in decimal
digits.
Doc: \sidx{linear dependence} finds a small non-trivial integral linear
combination between components of $v$. If none can be found return an empty
vector.
If $v$ is a vector with real/complex entries we use a floating point
(variable precision) LLL algorithm. If $\fl = 0$ the accuracy is chosen
internally using a crude heuristic. If $\fl > 0$ the computation is done with
an accuracy of $\fl$ decimal digits. To get meaningful results in the latter
case, the parameter $\fl$ should be smaller than the number of correct
decimal digits in the input.
\bprog
? lindep([sqrt(2), sqrt(3), sqrt(2)+sqrt(3)])
%1 = [-1, -1, 1]~
@eprog
If $v$ is $p$-adic, $\fl$ is ignored and the algorithm LLL-reduces a
suitable (dual) lattice.
\bprog
? lindep([1, 2 + 3 + 3^2 + 3^3 + 3^4 + O(3^5)])
%2 = [1, -2]~
@eprog
If $v$ is a matrix (or a vector of column vectors, or a vector of row
vectors), $\fl$ is ignored and the function returns a non trivial kernel
vector if one exists, else an empty vector.
\bprog
? lindep([1,2,3;4,5,6;7,8,9])
%3 = [1, -2, 1]~
? lindep([[1,0], [2,0]])
%4 = [2, -1]~
? lindep([[1,0], [0,1]])
%5 = []~
@eprog
If $v$ contains polynomials or power series over some base field, finds a
linear relation with coefficients in the field.
\bprog
? lindep([x*y, x^2 + y, x^2*y + x*y^2, 1])
%4 = [y, y, -1, -y^2]~
@eprog\noindent For better control, it is preferable to use \typ{POL} rather
than \typ{SER} in the input, otherwise one gets a linear combination which is
$t$-adically small, but not necessarily $0$. Indeed, power series are first
converted to the minimal absolute accuracy occurring among the entries of $v$
(which can cause some coefficients to be ignored), then truncated to
polynomials:
\bprog
? v = [t^2+O(t^4), 1+O(t^2)]; L=lindep(v)
%1 = [1, 0]~
? v*L
%2 = t^2+O(t^4) \\ small but not 0
@eprog
Variant: Also available are \fun{GEN}{lindep}{GEN v} (real/complex entries,
$\fl=0$), \fun{GEN}{lindep2}{GEN v, long flag} (real/complex entries)
\fun{GEN}{padic_lindep}{GEN v} ($p$-adic entries) and
\fun{GEN}{Xadic_lindep}{GEN v} (polynomial entries).
Finally \fun{GEN}{deplin}{GEN v} returns a non-zero kernel vector for a
\typ{MAT} input.
Function: listcreate
Class: basic
Section: programming/specific
C-Name: listcreate_gp
Prototype: D0,L,
Help: listcreate({n}): this function is obsolete, use List().
Description:
(?gen):list mklist()
Doc: This function is obsolete, use \kbd{List}.
Creates an empty list. This routine used to have a mandatory argument,
which is now ignored (for backward compatibility).
% \syn{NO}
Obsolete: 2007-08-10
Function: listinsert
Class: basic
Section: programming/specific
C-Name: listinsert
Prototype: WGL
Help: listinsert(L,x,n): insert x at index n in list L, shifting the
remaining elements to the right.
Description:
(list, gen, small):gen listinsert($1, $2, $3)
Doc: inserts the object $x$ at
position $n$ in $L$ (which must be of type \typ{LIST}). This has
complexity $O(\#L - n + 1)$: all the
remaining elements of \var{list} (from position $n+1$ onwards) are shifted
to the right.
Function: listkill
Class: basic
Section: programming/specific
C-Name: listkill
Prototype: vG
Help: listkill(L): obsolete, retained for backward compatibility.
Doc: obsolete, retained for backward compatibility. Just use \kbd{L = List()}
instead of \kbd{listkill(L)}. In most cases, you won't even need that, e.g.
local variables are automatically cleared when a user function returns.
Obsolete: 2007-08-10
Function: listpop
Class: basic
Section: programming/specific
C-Name: listpop0
Prototype: vWD0,L,
Help: listpop(list,{n}): removes n-th element from list. If n is
omitted or greater than the current list length, removes last element.
Description:
(list, small):void listpop($1, $2)
Doc:
removes the $n$-th element of the list
\var{list} (which must be of type \typ{LIST}). If $n$ is omitted,
or greater than the list current length, removes the last element.
If the list is already empty, do nothing. This runs in time $O(\#L - n + 1)$.
Function: listput
Class: basic
Section: programming/specific
C-Name: listput0
Prototype: WGD0,L,
Help: listput(list,x,{n}): sets n-th element of list equal to x. If n is
omitted or greater than the current list length, appends x.
Description:
(list, gen, small):gen listput($1, $2, $3)
Doc:
sets the $n$-th element of the list
\var{list} (which must be of type \typ{LIST}) equal to $x$. If $n$ is omitted,
or greater than the list length, appends $x$. The function returns the
inserted element.
\bprog
? L = List();
? listput(L, 1)
%2 = 1
? listput(L, 2)
%3 = 2
? L
%4 = List([1, 2])
@eprog
You may put an element into an occupied cell (not changing the
list length), but it is easier to use the standard \kbd{list[n] = x}
construct.
\bprog
? listput(L, 3, 1) \\ insert at position 1
%5 = 3
? L
%6 = List([3, 2])
? L[2] = 4 \\ simpler
%7 = List([3, 4])
? L[10] = 1 \\ can't insert beyond the end of the list
*** at top-level: L[10]=1
*** ^------
*** non-existent component: index > 2
? listput(L, 1, 10) \\ but listput can
%8 = 1
? L
%9 = List([3, 2, 1])
@eprog
This function runs in time $O(\#L)$ in the worst case (when the list must
be reallocated), but in time $O(1)$ on average: any number of successive
\kbd{listput}s run in time $O(\#L)$, where $\#L$ denotes the list
\emph{final} length.
Function: listsort
Class: basic
Section: programming/specific
C-Name: listsort
Prototype: vWD0,L,
Help: listsort(L,{flag=0}): sort the list L in place. If flag is non-zero,
suppress all but one occurence of each element in list.
Doc: sorts the \typ{LIST} \var{list} in place, with respect to the (somewhat
arbitrary) universal comparison function \tet{cmp}. In particular, the
ordering is the same as for sets and \tet{setsearch} can be used on a sorted
list.
\bprog
? L = List([1,2,4,1,3,-1]); listsort(L); L
%1 = List([-1, 1, 1, 2, 3, 4])
? setsearch(L, 4)
%2 = 6
? setsearch(L, -2)
%3 = 0
@eprog\noindent This is faster than the \kbd{vecsort} command since the list
is sorted in place: no copy is made. No value returned.
If $\fl$ is non-zero, suppresses all repeated coefficients.
Function: lngamma
Class: basic
Section: transcendental
C-Name: glngamma
Prototype: Gp
Help: lngamma(x): logarithm of the gamma function of x.
Doc: principal branch of the logarithm of the gamma function of $x$. This
function is analytic on the complex plane with non-positive integers
removed, and can have much larger arguments than \kbd{gamma} itself.
For $x$ a power series such that $x(0)$ is not a pole of \kbd{gamma},
compute the Taylor expansion. (PARI only knows about regular power series
and can't include logarithmic terms.)
\bprog
? lngamma(1+x+O(x^2))
%1 = -0.57721566490153286060651209008240243104*x + O(x^2)
? lngamma(x+O(x^2))
*** at top-level: lngamma(x+O(x^2))
*** ^-----------------
*** lngamma: domain error in lngamma: valuation != 0
? lngamma(-1+x+O(x^2))
*** lngamma: Warning: normalizing a series with 0 leading term.
*** at top-level: lngamma(-1+x+O(x^2))
*** ^--------------------
*** lngamma: domain error in intformal: residue(series, pole) != 0
@eprog
Function: local
Class: basic
Section: programming/specific
Help: local(x,...,z): declare x,...,z as (dynamically scoped) local variables.
Function: localbitprec
Class: basic
Section: programming/specific
C-Name: localbitprec
Prototype: vL
Help: localbitprec(p): set the real precision to p bits in the dynamic scope.
Doc: set the real precision to $p$ bits in the dynamic scope. All computations
are performed as if \tet{realbitprecision} was $p$:
transcendental constants (e.g.~\kbd{Pi}) and
conversions from exact to floating point inexact data use $p$ bits, as well as
iterative routines implicitly using a floating point
accuracy as a termination criterion (e.g.~\tet{solve} or \tet{intnum}).
But \kbd{realbitprecision} itself is unaffected
and is ``unmasked'' when we exit the dynamic (\emph{not} lexical) scope.
In effect, this is similar to
\bprog
my(bit = default(realbitprecision));
default(realbitprecision,p);
...
default(realbitprecision, bit);
@eprog\noindent but is both less cumbersome, cleaner (no need to manipulate
a global variable, which in fact never changes and is only temporarily masked)
and more robust: if the above computation is interrupted or an exception
occurs, \kbd{realbitprecision} will not be restored as intended.
Such \kbd{localbitprec} statements can be nested, the innermost one taking
precedence as expected. Beware that \kbd{localbitprec} follows the semantic of
\tet{local}, not \tet{my}: a subroutine called from \kbd{localbitprec} scope
uses the local accuracy:
\bprog
? f()=bitprecision(1.0);
? f()
%2 = 128
? localbitprec(1000); f()
%3 = 1024
@eprog\noindent Note that the bit precision of \emph{data} (\kbd{1.0} in the
above example) increases by steps of 64 (32 on a 32-bit machine) so we get
$1024$ instead of the expected $1000$; \kbd{localbitprec} bounds the
relative error exactly as specified in functions that support that
granularity (e.g.~\kbd{lfun}), and rounded to the next multiple of 64
(resp.~32) everywhere else.
\misctitle{Warning} Changing \kbd{realbitprecision} or \kbd{realprecision}
in programs is deprecated in favor of \kbd{localbitprec} and
\kbd{localprec}. Think about the \kbd{realprecision} and
\kbd{realbitprecision} defaults as interactive commands for the \kbd{gp}
interpreter, best left out of GP programs. Indeed, the above rules imply that
mixing both constructs yields surprising results:
\bprog
? \p38
? localprec(19); default(realprecision,1000); Pi
%1 = 3.141592653589793239
? \p
realprecision = 1001 significant digits (1000 digits displayed)
@eprog\noindent Indeed, \kbd{realprecision} itself is ignored within
\kbd{localprec} scope, so \kbd{Pi} is computed to a low accuracy. And when
we leave the \kbd{localprec} scope, \kbd{realprecision} only regains precedence,
it is not ``restored'' to the original value.
%\syn{NO}
Function: localprec
Class: basic
Section: programming/specific
C-Name: localprec
Prototype: vL
Help: localprec(p): set the real precision to p in the dynamic scope.
Doc: set the real precision to $p$ in the dynamic scope. All computations
are performed as if \tet{realprecision} was $p$:
transcendental constants (e.g.~\kbd{Pi}) and
conversions from exact to floating point inexact data use $p$ decimal
digits, as well as iterative routines implicitly using a floating point
accuracy as a termination criterion (e.g.~\tet{solve} or \tet{intnum}).
But \kbd{realprecision} itself is unaffected
and is ``unmasked'' when we exit the dynamic (\emph{not} lexical) scope.
In effect, this is similar to
\bprog
my(prec = default(realprecision));
default(realprecision,p);
...
default(realprecision, prec);
@eprog\noindent but is both less cumbersome, cleaner (no need to manipulate
a global variable, which in fact never changes and is only temporarily masked)
and more robust: if the above computation is interrupted or an exception
occurs, \kbd{realprecision} will not be restored as intended.
Such \kbd{localprec} statements can be nested, the innermost one taking
precedence as expected. Beware that \kbd{localprec} follows the semantic of
\tet{local}, not \tet{my}: a subroutine called from \kbd{localprec} scope
uses the local accuracy:
\bprog
? f()=precision(1.);
? f()
%2 = 38
? localprec(19); f()
%3 = 19
@eprog\noindent
\misctitle{Warning} Changing \kbd{realprecision} itself in programs is
now deprecated in favor of \kbd{localprec}. Think about the
\kbd{realprecision} default as an interactive command for the \kbd{gp}
interpreter, best left out of GP programs. Indeed, the above rules
imply that mixing both constructs yields surprising results:
\bprog
? \p38
? localprec(19); default(realprecision,100); Pi
%1 = 3.141592653589793239
? \p
realprecision = 115 significant digits (100 digits displayed)
@eprog\noindent Indeed, \kbd{realprecision} itself is ignored within
\kbd{localprec} scope, so \kbd{Pi} is computed to a low accuracy. And when
we leave \kbd{localprec} scope, \kbd{realprecision} only regains precedence,
it is not ``restored'' to the original value.
%\syn{NO}
Function: log
Class: basic
Section: transcendental
C-Name: glog
Prototype: Gp
Help: log(x): natural logarithm of x.
Description:
(gen):gen:prec glog($1, $prec)
Doc: principal branch of the natural logarithm of
$x \in \C^*$, i.e.~such that $\Im(\log(x))\in{} ]-\pi,\pi]$.
The branch cut lies
along the negative real axis, continuous with quadrant 2, i.e.~such that
$\lim_{b\to 0^+} \log (a+bi) = \log a$ for $a \in\R^*$. The result is complex
(with imaginary part equal to $\pi$) if $x\in \R$ and $x < 0$. In general,
the algorithm uses the formula
$$\log(x) \approx {\pi\over 2\text{agm}(1, 4/s)} - m \log 2, $$
if $s = x 2^m$ is large enough. (The result is exact to $B$ bits provided
$s > 2^{B/2}$.) At low accuracies, the series expansion near $1$ is used.
$p$-adic arguments are also accepted for $x$, with the convention that
$\log(p)=0$. Hence in particular $\exp(\log(x))/x$ is not in general equal to
1 but to a $(p-1)$-th root of unity (or $\pm1$ if $p=2$) times a power of $p$.
Variant: For a \typ{PADIC} $x$, the function
\fun{GEN}{Qp_log}{GEN x} is also available.
Function: logint
Class: basic
Section: number_theoretical
C-Name: logint0
Prototype: lGGD&
Help: logint(x,b,{&z}): return the largest integer e so that b^e <= x, where the
parameters b > 1 and x > 0 are both integers. If the parameter z is present,
set it to b^e.
Description:
(gen,2):small expi($1)
(gen,gen,&int):small logint0($1, $2, &$3)
Doc: Return the largest integer $e$ so that $b^e \leq x$, where the
parameters $b > 1$ and $x > 0$ are both integers. If the parameter $z$ is
present, set it to $b^e$.
\bprog
? logint(1000, 2)
%1 = 9
? 2^9
%2 = 512
? logint(1000, 2, &z)
%3 = 9
? z
%4 = 512
@eprog\noindent The number of digits used to write $b$ in base $x$ is
\kbd{1 + logint(x,b)}:
\bprog
? #digits(1000!, 10)
%5 = 2568
? logint(1000!, 10)
%6 = 2567
@eprog\noindent This function may conveniently replace
\bprog
floor( log(x) / log(b) )
@eprog\noindent which may not give the correct answer since PARI
does not guarantee exact rounding.
Function: mapdelete
Class: basic
Section: programming/specific
C-Name: mapdelete
Prototype: vGG
Help: mapdelete(M,x): removes x from the domain of the map M.
Doc: removes $x$ from the domain of the map $M$.
\bprog
? M = Map(["a",1; "b",3; "c",7]);
? mapdelete(M,"b");
? Mat(M)
["a" 1]
["c" 7]
@eprog
Function: mapget
Class: basic
Section: programming/specific
C-Name: mapget
Prototype: GG
Help: mapget(M,x): returns the image of x by the map M.
Doc: Returns the image of $x$ by the map $M$.
\bprog
? M=Map(["a",23;"b",43]);
? mapget(M,"a")
%2 = 23
? mapget(M,"b")
%3 = 43
@eprog\noindent Raises an exception when the key $x$ is not present in $M$.
\bprog
? mapget(M,"c")
*** at top-level: mapget(M,"c")
*** ^-------------
*** mapget: non-existent component in mapget: index not in map
@eprog
Function: mapisdefined
Class: basic
Section: programming/specific
C-Name: mapisdefined
Prototype: iGGD&
Help: mapisdefined(M,x,{&z}): true (1) if x has an image by the map M,
false (0) otherwise.
If z is present, set it to the image of x, if it exists.
Doc: Returns true ($1$) if \kbd{x} has an image by the map $M$, false ($0$)
otherwise. If \kbd{z} is present, set \kbd{z} to the image of $x$, if it exists.
\bprog
? M1 = Map([1, 10; 2, 20]);
? mapisdefined(M1,3)
%1 = 0
? mapisdefined(M1, 1, &z)
%2 = 1
? z
%3 = 10
@eprog
\bprog
? M2 = Map(); N = 19;
? for (a=0, N-1, mapput(M2, a^3%N, a));
? {for (a=0, N-1,
if (mapisdefined(M2, a, &b),
printf("%d is the cube of %d mod %d\n",a,b,N)));}
0 is the cube of 0 mod 19
1 is the cube of 11 mod 19
7 is the cube of 9 mod 19
8 is the cube of 14 mod 19
11 is the cube of 17 mod 19
12 is the cube of 15 mod 19
18 is the cube of 18 mod 19
@eprog
Function: mapput
Class: basic
Section: programming/specific
C-Name: mapput
Prototype: vWGG
Help: mapput(M,x,y): associates x to y in the map M.
Doc: Associates $x$ to $y$ in the map $M$. The value $y$ can be retrieved
with \tet{mapget}.
\bprog
? M = Map();
? mapput(M, "foo", 23);
? mapput(M, 7718, "bill");
? mapget(M, "foo")
%4 = 23
? mapget(M, 7718)
%5 = "bill"
? Vec(M) \\ keys
%6 = [7718, "foo"]
? Mat(M)
%7 =
[ 7718 "bill"]
["foo" 23]
@eprog
Function: matadjoint
Class: basic
Section: linear_algebra
C-Name: matadjoint0
Prototype: GD0,L,
Help: matadjoint(M,{flag=0}): adjoint matrix of M using Leverrier-Faddeev's
algorithm. If flag is 1, compute the characteristic polynomial independently
first.
Doc:
\idx{adjoint matrix} of $M$, i.e.~a matrix $N$
of cofactors of $M$, satisfying $M*N=\det(M)*\Id$. $M$ must be a
(non-necessarily invertible) square matrix of dimension $n$.
If $\fl$ is 0 or omitted, we try to use Leverrier-Faddeev's algorithm,
which assumes that $n!$ invertible. If it fails or $\fl = 1$,
compute $T = \kbd{charpoly}(M)$ independently first and return
$(-1)^{n-1} (T(x)-T(0))/x$ evaluated at $M$.
\bprog
? a = [1,2,3;3,4,5;6,7,8] * Mod(1,4);
%2 =
[Mod(1, 4) Mod(2, 4) Mod(3, 4)]
[Mod(3, 4) Mod(0, 4) Mod(1, 4)]
[Mod(2, 4) Mod(3, 4) Mod(0, 4)]
@eprog\noindent
Both algorithms use $O(n^4)$ operations in the base ring, and are usually
slower than computing the characteristic polynomial or the inverse of $M$
directly.
Variant: Also available are
\fun{GEN}{adj}{GEN x} (\fl=0) and
\fun{GEN}{adjsafe}{GEN x} (\fl=1).
Function: matalgtobasis
Class: basic
Section: number_fields
C-Name: matalgtobasis
Prototype: GG
Help: matalgtobasis(nf,x): nfalgtobasis applied to every element of the
vector or matrix x.
Doc: This function is deprecated, use \kbd{apply}.
$\var{nf}$ being a number field in \kbd{nfinit} format, and $x$ a
(row or column) vector or matrix, apply \tet{nfalgtobasis} to each entry
of $x$.
Obsolete: 2016-08-08
Function: matbasistoalg
Class: basic
Section: number_fields
C-Name: matbasistoalg
Prototype: GG
Help: matbasistoalg(nf,x): nfbasistoalg applied to every element of the
matrix or vector x.
Doc: This function is deprecated, use \kbd{apply}.
$\var{nf}$ being a number field in \kbd{nfinit} format, and $x$ a
(row or column) vector or matrix, apply \tet{nfbasistoalg} to each entry
of $x$.
Obsolete: 2016-08-08
Function: matcompanion
Class: basic
Section: linear_algebra
C-Name: matcompanion
Prototype: G
Help: matcompanion(x): companion matrix to polynomial x.
Doc:
the left companion matrix to the non-zero polynomial $x$.
Function: matconcat
Class: basic
Section: linear_algebra
C-Name: matconcat
Prototype: G
Help: matconcat(v): concatenate the entries of v and return the resulting
matrix.
Doc: returns a \typ{MAT} built from the entries of $v$, which may
be a \typ{VEC} (concatenate horizontally), a \typ{COL} (concatenate
vertically), or a \typ{MAT} (concatenate vertically each column, and
concatenate vertically the resulting matrices). The entries of $v$ are always
considered as matrices: they can themselves be \typ{VEC} (seen as a row
matrix), a \typ{COL} seen as a column matrix), a \typ{MAT}, or a scalar (seen
as an $1 \times 1$ matrix).
\bprog
? A=[1,2;3,4]; B=[5,6]~; C=[7,8]; D=9;
? matconcat([A, B]) \\ horizontal
%1 =
[1 2 5]
[3 4 6]
? matconcat([A, C]~) \\ vertical
%2 =
[1 2]
[3 4]
[7 8]
? matconcat([A, B; C, D]) \\ block matrix
%3 =
[1 2 5]
[3 4 6]
[7 8 9]
@eprog\noindent
If the dimensions of the entries to concatenate do not match up, the above
rules are extended as follows:
\item each entry $v_{i,j}$ of $v$ has a natural length and height: $1 \times
1$ for a scalar, $1 \times n$ for a \typ{VEC} of length $n$, $n \times 1$
for a \typ{COL}, $m \times n$ for an $m\times n$ \typ{MAT}
\item let $H_i$ be the maximum over $j$ of the lengths of the $v_{i,j}$,
let $L_j$ be the maximum over $i$ of the heights of the $v_{i,j}$.
The dimensions of the $(i,j)$-th block in the concatenated matrix are
$H_i \times L_j$.
\item a scalar $s = v_{i,j}$ is considered as $s$ times an identity matrix
of the block dimension $\min (H_i,L_j)$
\item blocks are extended by 0 columns on the right and 0 rows at the
bottom, as needed.
\bprog
? matconcat([1, [2,3]~, [4,5,6]~]) \\ horizontal
%4 =
[1 2 4]
[0 3 5]
[0 0 6]
? matconcat([1, [2,3], [4,5,6]]~) \\ vertical
%5 =
[1 0 0]
[2 3 0]
[4 5 6]
? matconcat([B, C; A, D]) \\ block matrix
%6 =
[5 0 7 8]
[6 0 0 0]
[1 2 9 0]
[3 4 0 9]
? U=[1,2;3,4]; V=[1,2,3;4,5,6;7,8,9];
? matconcat(matdiagonal([U, V])) \\ block diagonal
%7 =
[1 2 0 0 0]
[3 4 0 0 0]
[0 0 1 2 3]
[0 0 4 5 6]
[0 0 7 8 9]
@eprog
Function: matdet
Class: basic
Section: linear_algebra
C-Name: det0
Prototype: GD0,L,
Help: matdet(x,{flag=0}): determinant of the matrix x using an appropriate
algorithm depending on the coefficients. If (optional) flag is set to 1, use
classical Gaussian elimination (usually worse than the default).
Description:
(gen, ?0):gen det($1)
(gen, 1):gen det2($1)
(gen, #small):gen $"incorrect flag in matdet"
(gen, small):gen det0($1, $2)
Doc: determinant of the square matrix $x$.
If $\fl=0$, uses an appropriate algorithm depending on the coefficients:
\item integer entries: modular method due to Dixon, Pernet and Stein.
\item real or $p$-adic entries: classical Gaussian elimination using maximal
pivot.
\item intmod entries: classical Gaussian elimination using first non-zero
pivot.
\item other cases: Gauss-Bareiss.
If $\fl=1$, uses classical Gaussian elimination with appropriate pivoting
strategy (maximal pivot for real or $p$-adic coefficients). This is usually
worse than the default.
Variant: Also available are \fun{GEN}{det}{GEN x} ($\fl=0$),
\fun{GEN}{det2}{GEN x} ($\fl=1$) and \fun{GEN}{ZM_det}{GEN x} for integer
entries.
Function: matdetint
Class: basic
Section: linear_algebra
C-Name: detint
Prototype: G
Help: matdetint(B): some multiple of the determinant of the lattice
generated by the columns of B (0 if not of maximal rank). Useful with
mathnfmod.
Doc:
Let $B$ be an $m\times n$ matrix with integer coefficients. The
\emph{determinant} $D$ of the lattice generated by the columns of $B$ is
the square root of $\det(B^T B)$ if $B$ has maximal rank $m$, and $0$
otherwise.
This function uses the Gauss-Bareiss algorithm to compute a positive
\emph{multiple} of $D$. When $B$ is square, the function actually returns
$D = |\det B|$.
This function is useful in conjunction with \kbd{mathnfmod}, which needs to
know such a multiple. If the rank is maximal and the matrix non-square,
you can obtain $D$ exactly using
\bprog
matdet( mathnfmod(B, matdetint(B)) )
@eprog\noindent
Note that as soon as one of the dimensions gets large ($m$ or $n$ is larger
than 20, say), it will often be much faster to use \kbd{mathnf(B, 1)} or
\kbd{mathnf(B, 4)} directly.
Function: matdiagonal
Class: basic
Section: linear_algebra
C-Name: diagonal
Prototype: G
Help: matdiagonal(x): creates the diagonal matrix whose diagonal entries are
the entries of the vector x.
Doc: $x$ being a vector, creates the diagonal matrix
whose diagonal entries are those of $x$.
\bprog
? matdiagonal([1,2,3]);
%1 =
[1 0 0]
[0 2 0]
[0 0 3]
@eprog\noindent Block diagonal matrices are easily created using
\tet{matconcat}:
\bprog
? U=[1,2;3,4]; V=[1,2,3;4,5,6;7,8,9];
? matconcat(matdiagonal([U, V]))
%1 =
[1 2 0 0 0]
[3 4 0 0 0]
[0 0 1 2 3]
[0 0 4 5 6]
[0 0 7 8 9]
@eprog
Function: mateigen
Class: basic
Section: linear_algebra
C-Name: mateigen
Prototype: GD0,L,p
Help: mateigen(x,{flag=0}): complex eigenvectors of the matrix x given as
columns of a matrix H. If flag=1, return [L,H], where L contains the
eigenvalues and H the corresponding eigenvectors.
Doc: returns the (complex) eigenvectors of $x$ as columns of a matrix.
If $\fl=1$, return $[L,H]$, where $L$ contains the
eigenvalues and $H$ the corresponding eigenvectors; multiple eigenvalues are
repeated according to the eigenspace dimension (which may be less
than the eigenvalue multiplicity in the characteristic polynomial).
This function first computes the characteristic polynomial of $x$ and
approximates its complex roots $(\lambda_i)$, then tries to compute the
eigenspaces as kernels of the $x - \lambda_i$. This algorithm is
ill-conditioned and is likely to miss kernel vectors if some roots of the
characteristic polynomial are close, in particular if it has multiple roots.
\bprog
? A = [13,2; 10,14]; mateigen(A)
%1 =
[-1/2 2/5]
[ 1 1]
? [L,H] = mateigen(A, 1);
? L
%3 = [9, 18]
? H
%4 =
[-1/2 2/5]
[ 1 1]
@eprog\noindent
For symmetric matrices, use \tet{qfjacobi} instead; for Hermitian matrices,
compute
\bprog
A = real(x);
B = imag(x);
y = matconcat([A, -B; B, A]);
@eprog\noindent and apply \kbd{qfjacobi} to $y$.
Variant: Also available is \fun{GEN}{eigen}{GEN x, long prec} ($\fl = 0$)
Function: matfrobenius
Class: basic
Section: linear_algebra
C-Name: matfrobenius
Prototype: GD0,L,Dn
Help: matfrobenius(M,{flag},{v='x}): return the Frobenius form of the square
matrix M. If flag is 1, return only the elementary divisors as a vector of
polynomials in the variable v. If flag is 2, return a two-components vector
[F,B] where F is the Frobenius form and B is the basis change so that
M=B^-1*F*B.
Doc: returns the Frobenius form of
the square matrix \kbd{M}. If $\fl=1$, returns only the elementary divisors as
a vector of polynomials in the variable \kbd{v}. If $\fl=2$, returns a
two-components vector [F,B] where \kbd{F} is the Frobenius form and \kbd{B} is
the basis change so that $M=B^{-1}FB$.
Function: mathess
Class: basic
Section: linear_algebra
C-Name: hess
Prototype: G
Help: mathess(x): Hessenberg form of x.
Doc: returns a matrix similar to the square matrix $x$, which is in upper Hessenberg
form (zero entries below the first subdiagonal).
Function: mathilbert
Class: basic
Section: linear_algebra
C-Name: mathilbert
Prototype: L
Help: mathilbert(n): Hilbert matrix of order n.
Doc: $x$ being a \kbd{long}, creates the
\idx{Hilbert matrix}of order $x$, i.e.~the matrix whose coefficient
($i$,$j$) is $1/ (i+j-1)$.
Function: mathnf
Class: basic
Section: linear_algebra
C-Name: mathnf0
Prototype: GD0,L,
Help: mathnf(M,{flag=0}): (upper triangular) Hermite normal form of M, basis
for the lattice formed by the columns of M. flag is optional whose value
range from 0 to 3 have a binary meaning. Bit 1: complete output, returns
a 2-component vector [H,U] such that H is the HNF of M, and U is an
invertible matrix such that MU=H. Bit 2: allow polynomial entries, otherwise
assume that M is integral. These use a naive algorithm; larger values
correspond to more involved algorithms and are restricted to integer
matrices; flag = 4: returns [H,U] using LLL reduction along the way;
flag = 5: return [H,U,P] where P is a permutation of row indices such that
P applied to M U is H.
Doc: let $R$ be a Euclidean ring, equal to $\Z$ or to $K[X]$ for some field
$K$. If $M$ is a (not necessarily square) matrix with entries in $R$, this
routine finds the \emph{upper triangular} \idx{Hermite normal form} of $M$.
If the rank of $M$ is equal to its number of rows, this is a square
matrix. In general, the columns of the result form a basis of the $R$-module
spanned by the columns of $M$.
The values $0,1,2,3$ of $\fl$ have a binary meaning, analogous to the one
in \tet{matsnf}; in this case, binary digits of $\fl$ mean:
\item 1 (complete output): if set, outputs $[H,U]$, where $H$ is the Hermite
normal form of $M$, and $U$ is a transformation matrix such that $MU=[0|H]$.
The matrix $U$ belongs to $\text{GL}(R)$. When $M$ has a large kernel, the
entries of $U$ are in general huge.
\item 2 (generic input): \emph{Deprecated}. If set, assume that $R = K[X]$ is
a polynomial ring; otherwise, assume that $R = \Z$. This flag is now useless
since the routine always checks whether the matrix has integral entries.
\noindent For these 4 values, we use a naive algorithm, which behaves well
in small dimension only. Larger values correspond to different algorithms,
are restricted to \emph{integer} matrices, and all output the unimodular
matrix $U$. From now on all matrices have integral entries.
\item $\fl=4$, returns $[H,U]$ as in ``complete output'' above, using a
variant of \idx{LLL} reduction along the way. The matrix $U$ is provably
small in the $L_2$ sense, and in general close to optimal; but the
reduction is in general slow, although provably polynomial-time.
If $\fl=5$, uses Batut's algorithm and output $[H,U,P]$, such that $H$ and
$U$ are as before and $P$ is a permutation of the rows such that $P$ applied
to $MU$ gives $H$. This is in general faster than $\fl=4$ but the matrix $U$
is usually worse; it is heuristically smaller than with the default algorithm.
When the matrix is dense and the dimension is large (bigger than 100, say),
$\fl = 4$ will be fastest. When $M$ has maximal rank, then
\bprog
H = mathnfmod(M, matdetint(M))
@eprog\noindent will be even faster. You can then recover $U$ as $M^{-1}H$.
\bprog
? M = matrix(3,4,i,j,random([-5,5]))
%1 =
[ 0 2 3 0]
[-5 3 -5 -5]
[ 4 3 -5 4]
? [H,U] = mathnf(M, 1);
? U
%3 =
[-1 0 -1 0]
[ 0 5 3 2]
[ 0 3 1 1]
[ 1 0 0 0]
? H
%5 =
[19 9 7]
[ 0 9 1]
[ 0 0 1]
? M*U
%6 =
[0 19 9 7]
[0 0 9 1]
[0 0 0 1]
@eprog
For convenience, $M$ is allowed to be a \typ{VEC}, which is then
automatically converted to a \typ{MAT}, as per the \tet{Mat} function.
For instance to solve the generalized extended gcd problem, one may use
\bprog
? v = [116085838, 181081878, 314252913,10346840];
? [H,U] = mathnf(v, 1);
? U
%2 =
[ 103 -603 15 -88]
[-146 13 -1208 352]
[ 58 220 678 -167]
[-362 -144 381 -101]
? v*U
%3 = [0, 0, 0, 1]
@eprog\noindent This also allows to input a matrix as a \typ{VEC} of
\typ{COL}s of the same length (which \kbd{Mat} would concatenate to
the \typ{MAT} having those columns):
\bprog
? v = [[1,0,4]~, [3,3,4]~, [0,-4,-5]~]; mathnf(v)
%1 =
[47 32 12]
[ 0 1 0]
[ 0 0 1]
@eprog
Variant: Also available are \fun{GEN}{hnf}{GEN M} ($\fl=0$) and
\fun{GEN}{hnfall}{GEN M} ($\fl=1$). To reduce \emph{huge} relation matrices
(sparse with small entries, say dimension $400$ or more), you can use the
pair \kbd{hnfspec} / \kbd{hnfadd}. Since this is quite technical and the
calling interface may change, they are not documented yet. Look at the code
in \kbd{basemath/hnf\_snf.c}.
Function: mathnfmod
Class: basic
Section: linear_algebra
C-Name: hnfmod
Prototype: GG
Help: mathnfmod(x,d): (upper triangular) Hermite normal form of x, basis for
the lattice formed by the columns of x, where d is a multiple of the
non-zero determinant of this lattice.
Doc: if $x$ is a (not necessarily square) matrix of
maximal rank with integer entries, and $d$ is a multiple of the (non-zero)
determinant of the lattice spanned by the columns of $x$, finds the
\emph{upper triangular} \idx{Hermite normal form} of $x$.
If the rank of $x$ is equal to its number of rows, the result is a square
matrix. In general, the columns of the result form a basis of the lattice
spanned by the columns of $x$. Even when $d$ is known, this is in general
slower than \kbd{mathnf} but uses much less memory.
Function: mathnfmodid
Class: basic
Section: linear_algebra
C-Name: hnfmodid
Prototype: GG
Help: mathnfmodid(x,d): (upper triangular) Hermite normal form of x
concatenated with matdiagonal(d).
Doc: outputs the (upper triangular)
\idx{Hermite normal form} of $x$ concatenated with the diagonal
matrix with diagonal $d$. Assumes that $x$ has integer entries.
Variant: if $d$ is an integer instead of a vector, concatenate $d$ times the
identity matrix.
\bprog
? m=[0,7;-1,0;-1,-1]
%1 =
[ 0 7]
[-1 0]
[-1 -1]
? mathnfmodid(m, [6,2,2])
%2 =
[2 1 1]
[0 1 0]
[0 0 1]
? mathnfmodid(m, 10)
%3 =
[10 7 3]
[ 0 1 0]
[ 0 0 1]
@eprog
Function: mathouseholder
Class: basic
Section: linear_algebra
C-Name: mathouseholder
Prototype: GG
Help: mathouseholder(Q,v): applies a sequence Q of Householder transforms
to the vector or matrix v.
Doc: \sidx{Householder transform}applies a sequence $Q$ of Householder
transforms, as returned by \kbd{matqr}$(M,1)$ to the vector or matrix $v$.
Function: matid
Class: basic
Section: linear_algebra
C-Name: matid
Prototype: L
Help: matid(n): identity matrix of order n.
Description:
(small):vec matid($1)
Doc: creates the $n\times n$ identity matrix.
Function: matimage
Class: basic
Section: linear_algebra
C-Name: matimage0
Prototype: GD0,L,
Help: matimage(x,{flag=0}): basis of the image of the matrix x. flag is
optional and can be set to 0 or 1, corresponding to two different algorithms.
Description:
(gen, ?0):vec image($1)
(gen, 1):vec image2($1)
(gen, #small) $"incorrect flag in matimage"
(gen, small):vec matimage0($1, $2)
Doc: gives a basis for the image of the
matrix $x$ as columns of a matrix. A priori the matrix can have entries of
any type. If $\fl=0$, use standard Gauss pivot. If $\fl=1$, use
\kbd{matsupplement} (much slower: keep the default flag!).
Variant: Also available is \fun{GEN}{image}{GEN x} ($\fl=0$).
Function: matimagecompl
Class: basic
Section: linear_algebra
C-Name: imagecompl
Prototype: G
Help: matimagecompl(x): vector of column indices not corresponding to the
indices given by the function matimage.
Description:
(gen):vecsmall imagecompl($1)
Doc: gives the vector of the column indices which
are not extracted by the function \kbd{matimage}, as a permutation
(\typ{VECSMALL}). Hence the number of
components of \kbd{matimagecompl(x)} plus the number of columns of
\kbd{matimage(x)} is equal to the number of columns of the matrix $x$.
Function: matindexrank
Class: basic
Section: linear_algebra
C-Name: indexrank
Prototype: G
Help: matindexrank(x): gives two extraction vectors (rows and columns) for
the matrix x such that the extracted matrix is square of maximal rank.
Doc: $x$ being a matrix of rank $r$, returns a vector with two
\typ{VECSMALL} components $y$ and $z$ of length $r$ giving a list of rows
and columns respectively (starting from 1) such that the extracted matrix
obtained from these two vectors using $\tet{vecextract}(x,y,z)$ is
invertible.
Function: matintersect
Class: basic
Section: linear_algebra
C-Name: intersect
Prototype: GG
Help: matintersect(x,y): intersection of the vector spaces whose bases are
the columns of x and y.
Doc: $x$ and $y$ being two matrices with the same
number of rows each of whose columns are independent, finds a basis of the
$\Q$-vector space equal to the intersection of the spaces spanned by the
columns of $x$ and $y$ respectively. The faster function
\tet{idealintersect} can be used to intersect fractional ideals (projective
$\Z_K$ modules of rank $1$); the slower but much more general function
\tet{nfhnf} can be used to intersect general $\Z_K$-modules.
Function: matinverseimage
Class: basic
Section: linear_algebra
C-Name: inverseimage
Prototype: GG
Help: matinverseimage(x,y): an element of the inverse image of the vector y
by the matrix x if one exists, the empty vector otherwise.
Doc: given a matrix $x$ and
a column vector or matrix $y$, returns a preimage $z$ of $y$ by $x$ if one
exists (i.e such that $x z = y$), an empty vector or matrix otherwise. The
complete inverse image is $z + \text{Ker} x$, where a basis of the kernel of
$x$ may be obtained by \kbd{matker}.
\bprog
? M = [1,2;2,4];
? matinverseimage(M, [1,2]~)
%2 = [1, 0]~
? matinverseimage(M, [3,4]~)
%3 = []~ \\@com no solution
? matinverseimage(M, [1,3,6;2,6,12])
%4 =
[1 3 6]
[0 0 0]
? matinverseimage(M, [1,2;3,4])
%5 = [;] \\@com no solution
? K = matker(M)
%6 =
[-2]
[1]
@eprog
Function: matisdiagonal
Class: basic
Section: linear_algebra
C-Name: isdiagonal
Prototype: iG
Help: matisdiagonal(x): true(1) if x is a diagonal matrix, false(0)
otherwise.
Doc: returns true (1) if $x$ is a diagonal matrix, false (0) if not.
Function: matker
Class: basic
Section: linear_algebra
C-Name: matker0
Prototype: GD0,L,
Help: matker(x,{flag=0}): basis of the kernel of the matrix x. flag is
optional, and may be set to 0: default; non-zero: x is known to have
integral entries.
Description:
(gen, ?0):vec ker($1)
(gen, 1):vec keri($1)
(gen, #small) $"incorrect flag in matker"
(gen, small):vec matker0($1, $2)
Doc: gives a basis for the kernel of the matrix $x$ as columns of a matrix.
The matrix can have entries of any type, provided they are compatible with
the generic arithmetic operations ($+$, $\times$ and $/$).
If $x$ is known to have integral entries, set $\fl=1$.
Variant: Also available are \fun{GEN}{ker}{GEN x} ($\fl=0$),
\fun{GEN}{keri}{GEN x} ($\fl=1$).
Function: matkerint
Class: basic
Section: linear_algebra
C-Name: matkerint0
Prototype: GD0,L,
Help: matkerint(x,{flag=0}): LLL-reduced Z-basis of the kernel of the matrix
x with integral entries. flag is deprecated, and may be set to 0 or 1
for backward compatibility.
Doc: gives an \idx{LLL}-reduced $\Z$-basis
for the lattice equal to the kernel of the matrix $x$ with rational entries.
\fl is deprecated, kept for backward compatibility.
Variant: Use directly \fun{GEN}{kerint}{GEN x} if $x$ is known to have
integer entries, and \tet{Q_primpart} first otherwise.
Function: matmuldiagonal
Class: basic
Section: linear_algebra
C-Name: matmuldiagonal
Prototype: GG
Help: matmuldiagonal(x,d): product of matrix x by diagonal matrix whose
diagonal coefficients are those of the vector d, equivalent but faster than
x*matdiagonal(d).
Doc: product of the matrix $x$ by the diagonal
matrix whose diagonal entries are those of the vector $d$. Equivalent to,
but much faster than $x*\kbd{matdiagonal}(d)$.
Function: matmultodiagonal
Class: basic
Section: linear_algebra
C-Name: matmultodiagonal
Prototype: GG
Help: matmultodiagonal(x,y): product of matrices x and y, knowing that the
result will be a diagonal matrix. Much faster than general multiplication in
that case.
Doc: product of the matrices $x$ and $y$ assuming that the result is a
diagonal matrix. Much faster than $x*y$ in that case. The result is
undefined if $x*y$ is not diagonal.
Function: matpascal
Class: basic
Section: linear_algebra
C-Name: matqpascal
Prototype: LDG
Help: matpascal(n,{q}): Pascal triangle of order n if q is omitted. q-Pascal
triangle otherwise.
Doc: creates as a matrix the lower triangular
\idx{Pascal triangle} of order $x+1$ (i.e.~with binomial coefficients
up to $x$). If $q$ is given, compute the $q$-Pascal triangle (i.e.~using
$q$-binomial coefficients).
Variant: Also available is \fun{GEN}{matpascal}{GEN x}.
Function: matqr
Class: basic
Section: linear_algebra
C-Name: matqr
Prototype: GD0,L,p
Help: matqr(M,{flag=0}): returns [Q,R], the QR-decomposition of the square
invertible matrix M. If flag=1, Q is given as a sequence of Householder
transforms (faster and stabler).
Doc: returns $[Q,R]$, the \idx{QR-decomposition} of the square invertible
matrix $M$ with real entries: $Q$ is orthogonal and $R$ upper triangular. If
$\fl=1$, the orthogonal matrix is returned as a sequence of Householder
transforms: applying such a sequence is stabler and faster than
multiplication by the corresponding $Q$ matrix.\sidx{Householder transform}
More precisely, if
\bprog
[Q,R] = matqr(M);
[q,r] = matqr(M, 1);
@eprog\noindent then $r = R$ and \kbd{mathouseholder}$(q, M)$ is
(close to) $R$; furthermore
\bprog
mathouseholder(q, matid(#M)) == Q~
@eprog\noindent the inverse of $Q$. This function raises an error if the
precision is too low or $x$ is singular.
Function: matrank
Class: basic
Section: linear_algebra
C-Name: rank
Prototype: lG
Help: matrank(x): rank of the matrix x.
Doc: rank of the matrix $x$.
Function: matrix
Class: basic
Section: linear_algebra
C-Name: matrice
Prototype: GGDVDVDE
Help: matrix(m,n,{X},{Y},{expr=0}): mXn matrix of expression expr, the row
variable X going from 1 to m and the column variable Y going from 1 to n. By
default, fill with 0s.
Doc: creation of the
$m\times n$ matrix whose coefficients are given by the expression
\var{expr}. There are two formal parameters in \var{expr}, the first one
($X$) corresponding to the rows, the second ($Y$) to the columns, and $X$
goes from 1 to $m$, $Y$ goes from 1 to $n$. If one of the last 3 parameters
is omitted, fill the matrix with zeroes.
%\syn{NO}
Function: matrixqz
Class: basic
Section: linear_algebra
C-Name: matrixqz0
Prototype: GDG
Help: matrixqz(A,{p=0}): if p>=0, transforms the rational or integral mxn (m>=n)
matrix A into an integral matrix with gcd of maximal determinants coprime to
p. If p=-1, finds a basis of the intersection with Z^n of the lattice spanned
by the columns of A. If p=-2, finds a basis of the intersection with Z^n of
the Q-vector space spanned by the columns of A.
Doc: $A$ being an $m\times n$ matrix in $M_{m,n}(\Q)$, let
$\text{Im}_\Q A$ (resp.~$\text{Im}_\Z A$) the $\Q$-vector space
(resp.~the $\Z$-module) spanned by the columns of $A$. This function has
varying behavior depending on the sign of $p$:
If $p \geq 0$, $A$ is assumed to have maximal rank $n\leq m$. The function
returns a matrix $B\in M_{m,n}(\Z)$, with $\text{Im}_\Q B = \text{Im}_\Q A$,
such that the GCD of all its $n\times n$ minors is coprime to
$p$; in particular, if $p = 0$ (default), this GCD is $1$.
\bprog
? minors(x) = vector(#x[,1], i, matdet(x[^i,]));
? A = [3,1/7; 5,3/7; 7,5/7]; minors(A)
%1 = [4/7, 8/7, 4/7] \\ determinants of all 2x2 minors
? B = matrixqz(A)
%2 =
[3 1]
[5 2]
[7 3]
? minors(%)
%3 = [1, 2, 1] \\ B integral with coprime minors
@eprog
If $p=-1$, returns the HNF basis of the lattice $\Z^n \cap \text{Im}_\Z A$.
If $p=-2$, returns the HNF basis of the lattice $\Z^n \cap \text{Im}_\Q A$.
\bprog
? matrixqz(A,-1)
%4 =
[8 5]
[4 3]
[0 1]
? matrixqz(A,-2)
%5 =
[2 -1]
[1 0]
[0 1]
@eprog
Function: matsize
Class: basic
Section: linear_algebra
C-Name: matsize
Prototype: G
Help: matsize(x): number of rows and columns of the vector/matrix x as a
2-vector.
Doc: $x$ being a vector or matrix, returns a row vector
with two components, the first being the number of rows (1 for a row vector),
the second the number of columns (1 for a column vector).
Function: matsnf
Class: basic
Section: linear_algebra
C-Name: matsnf0
Prototype: GD0,L,
Help: matsnf(X,{flag=0}): Smith normal form (i.e. elementary divisors) of
the matrix X, expressed as a vector d. Binary digits of flag mean 1: returns
[u,v,d] where d=u*X*v, otherwise only the diagonal d is returned, 2: allow
polynomial entries, otherwise assume X is integral, 4: removes all
information corresponding to entries equal to 1 in d.
Doc: if $X$ is a (singular or non-singular) matrix outputs the vector of
\idx{elementary divisors} of $X$, i.e.~the diagonal of the
\idx{Smith normal form} of $X$, normalized so that $d_n \mid d_{n-1} \mid
\ldots \mid d_1$.
The binary digits of \fl\ mean:
1 (complete output): if set, outputs $[U,V,D]$, where $U$ and $V$ are two
unimodular matrices such that $UXV$ is the diagonal matrix $D$. Otherwise
output only the diagonal of $D$. If $X$ is not a square matrix, then $D$
will be a square diagonal matrix padded with zeros on the left or the top.
2 (generic input): if set, allows polynomial entries, in which case the
input matrix must be square. Otherwise, assume that $X$ has integer
coefficients with arbitrary shape.
4 (cleanup): if set, cleans up the output. This means that elementary
divisors equal to $1$ will be deleted, i.e.~outputs a shortened vector $D'$
instead of $D$. If complete output was required, returns $[U',V',D']$ so
that $U'XV' = D'$ holds. If this flag is set, $X$ is allowed to be of the
form `vector of elementary divisors' or $[U,V,D]$ as would normally be output with the cleanup flag
unset.
Function: matsolve
Class: basic
Section: linear_algebra
C-Name: gauss
Prototype: GG
Help: matsolve(M,B): solution of MX=B (M matrix, B column vector).
Doc: $M$ being an invertible matrix and $B$ a column
vector, finds the solution $X$ of $MX=B$, using Dixon $p$-adic lifting method
if $M$ and $B$ are integral and Gaussian elimination otherwise. This
has the same effect as, but is faster, than $M^{-1}*B$.
Variant: For integral input, the function
\fun{GEN}{ZM_gauss}{GEN M,GEN B} is also available.
Function: matsolvemod
Class: basic
Section: linear_algebra
C-Name: matsolvemod0
Prototype: GGGD0,L,
Help: matsolvemod(M,D,B,{flag=0}): one solution of system of congruences
MX=B mod D (M matrix, B and D column vectors). If (optional) flag is
non-null return all solutions.
Doc: $M$ being any integral matrix,
$D$ a column vector of non-negative integer moduli, and $B$ an integral
column vector, gives a small integer solution to the system of congruences
$\sum_i m_{i,j}x_j\equiv b_i\pmod{d_i}$ if one exists, otherwise returns
zero. Shorthand notation: $B$ (resp.~$D$) can be given as a single integer,
in which case all the $b_i$ (resp.~$d_i$) above are taken to be equal to $B$
(resp.~$D$).
\bprog
? M = [1,2;3,4];
? matsolvemod(M, [3,4]~, [1,2]~)
%2 = [-2, 0]~
? matsolvemod(M, 3, 1) \\ M X = [1,1]~ over F_3
%3 = [-1, 1]~
? matsolvemod(M, [3,0]~, [1,2]~) \\ x + 2y = 1 (mod 3), 3x + 4y = 2 (in Z)
%4 = [6, -4]~
@eprog
If $\fl=1$, all solutions are returned in the form of a two-component row
vector $[x,u]$, where $x$ is a small integer solution to the system of
congruences and $u$ is a matrix whose columns give a basis of the homogeneous
system (so that all solutions can be obtained by adding $x$ to any linear
combination of columns of $u$). If no solution exists, returns zero.
Variant: Also available are \fun{GEN}{gaussmodulo}{GEN M, GEN D, GEN B}
($\fl=0$) and \fun{GEN}{gaussmodulo2}{GEN M, GEN D, GEN B} ($\fl=1$).
Function: matsupplement
Class: basic
Section: linear_algebra
C-Name: suppl
Prototype: G
Help: matsupplement(x): supplement the columns of the matrix x to an
invertible matrix.
Doc: assuming that the columns of the matrix $x$
are linearly independent (if they are not, an error message is issued), finds
a square invertible matrix whose first columns are the columns of $x$,
i.e.~supplement the columns of $x$ to a basis of the whole space.
\bprog
? matsupplement([1;2])
%1 =
[1 0]
[2 1]
@eprog
Raises an error if $x$ has 0 columns, since (due to a long standing design
bug), the dimension of the ambient space (the number of rows) is unknown in
this case:
\bprog
? matsupplement(matrix(2,0))
*** at top-level: matsupplement(matrix
*** ^--------------------
*** matsupplement: sorry, suppl [empty matrix] is not yet implemented.
@eprog
Function: mattranspose
Class: basic
Section: linear_algebra
C-Name: gtrans
Prototype: G
Help: mattranspose(x): x~ = transpose of x.
Doc: transpose of $x$ (also $x\til$).
This has an effect only on vectors and matrices.
Function: max
Class: basic
Section: operators
C-Name: gmax
Prototype: GG
Help: max(x,y): maximum of x and y.
Description:
(small, small):small maxss($1, $2)
(small, int):int gmaxsg($1, $2)
(int, small):int gmaxgs($1, $2)
(int, int):int gmax($1, $2)
(small, mp):mp gmaxsg($1, $2)
(mp, small):mp gmaxgs($1, $2)
(mp, mp):mp gmax($1, $2)
(small, gen):gen gmaxsg($1, $2)
(gen, small):gen gmaxgs($1, $2)
(gen, gen):gen gmax($1, $2)
Doc: creates the maximum of $x$ and $y$ when they can be compared.
Function: min
Class: basic
Section: operators
C-Name: gmin
Prototype: GG
Help: min(x,y): minimum of x and y.
Description:
(small, small):small minss($1, $2)
(small, int):int gminsg($1, $2)
(int, small):int gmings($1, $2)
(int, int):int gmin($1, $2)
(small, mp):mp gminsg($1, $2)
(mp, small):mp gmings($1, $2)
(mp, mp):mp gmin($1, $2)
(small, gen):gen gminsg($1, $2)
(gen, small):gen gmings($1, $2)
(gen, gen):gen gmin($1, $2)
Doc: creates the minimum of $x$ and $y$ when they can be compared.
Function: minpoly
Class: basic
Section: linear_algebra
C-Name: minpoly
Prototype: GDn
Help: minpoly(A,{v='x}): minimal polynomial of the matrix or polmod A.
Doc: \idx{minimal polynomial}
of $A$ with respect to the variable $v$., i.e. the monic polynomial $P$
of minimal degree (in the variable $v$) such that $P(A) = 0$.
Function: modreverse
Class: basic
Section: number_fields
C-Name: modreverse
Prototype: G
Help: modreverse(z): reverse polmod of the polmod z, if it exists.
Doc: let $z = \kbd{Mod(A, T)}$ be a polmod, and $Q$ be its minimal
polynomial, which must satisfy $\text{deg}(Q) = \text{deg}(T)$.
Returns a ``reverse polmod'' \kbd{Mod(B, Q)}, which is a root of $T$.
This is quite useful when one changes the generating element in algebraic
extensions:
\bprog
? u = Mod(x, x^3 - x -1); v = u^5;
? w = modreverse(v)
%2 = Mod(x^2 - 4*x + 1, x^3 - 5*x^2 + 4*x - 1)
@eprog\noindent
which means that $x^3 - 5x^2 + 4x -1$ is another defining polynomial for the
cubic field
$$\Q(u) = \Q[x]/(x^3 - x - 1) = \Q[x]/(x^3 - 5x^2 + 4x - 1) = \Q(v),$$
and that $u \to v^2 - 4v + 1$ gives an explicit isomorphism. From this, it is
easy to convert elements between the $A(u)\in \Q(u)$ and $B(v)\in \Q(v)$
representations:
\bprog
? A = u^2 + 2*u + 3; subst(lift(A), 'x, w)
%3 = Mod(x^2 - 3*x + 3, x^3 - 5*x^2 + 4*x - 1)
? B = v^2 + v + 1; subst(lift(B), 'x, v)
%4 = Mod(26*x^2 + 31*x + 26, x^3 - x - 1)
@eprog
If the minimal polynomial of $z$ has lower degree than expected, the routine
fails
\bprog
? u = Mod(-x^3 + 9*x, x^4 - 10*x^2 + 1)
? modreverse(u)
*** modreverse: domain error in modreverse: deg(minpoly(z)) < 4
*** Break loop: type 'break' to go back to GP prompt
break> Vec( dbg_err() ) \\ ask for more info
["e_DOMAIN", "modreverse", "deg(minpoly(z))", "<", 4,
Mod(-x^3 + 9*x, x^4 - 10*x^2 + 1)]
break> minpoly(u)
x^2 - 8
@eprog
Function: moebius
Class: basic
Section: number_theoretical
C-Name: moebius
Prototype: lG
Help: moebius(x): Moebius function of x.
Doc: \idx{Moebius} $\mu$-function of $|x|$. $x$ must be of type integer.
Function: msatkinlehner
Class: basic
Section: modular_symbols
C-Name: msatkinlehner
Prototype: GLDG
Help: msatkinlehner(M,Q,{H}): M being a full modular symbol space of level N,
as given by msinit, let Q | N, (Q,N/Q) = 1, and let H be a subspace stable
under the Atkin-Lehner involution w_Q. Return the matrix of w_Q
acting on H (M if omitted).
Doc: Let $M$ be a full modular symbol space of level $N$,
as given by \kbd{msinit}, let $Q \mid N$, $(Q,N/Q) = 1$,
and let $H$ be a subspace stable under the Atkin-Lehner involution $w_Q$.
Return the matrix of $w_Q$ acting on $H$ ($M$ if omitted).
\bprog
? M = msinit(36,2); \\ M_2(Gamma_0(36))
? w = msatkinlehner(M,4); w^2 == 1
%2 = 1
? #w \\ involution acts on a 13-dimensional space
%3 = 13
? M = msinit(36,2, -1); \\ M_2(Gamma_0(36))^-
? w = msatkinlehner(M,4); w^2 == 1
%5 = 1
? #w
%6 = 4
@eprog
Function: mscuspidal
Class: basic
Section: modular_symbols
C-Name: mscuspidal
Prototype: GD0,L,
Help: mscuspidal(M, {flag=0}): M being a full modular symbol space, as given
by msinit, return its cuspidal part S. If flag = 1, return [S,E] its
decomposition into Eisenstein and cuspidal parts.
Doc:
$M$ being a full modular symbol space, as given by \kbd{msinit},
return its cuspidal part $S$. If $\fl = 1$, return
$[S,E]$ its decomposition into cuspidal and Eisenstein parts.
A subspace is given by a structure allowing quick projection and
restriction of linear operators; its first component is
a matrix with integer coefficients whose columns form a $\Q$-basis of
the subspace.
\bprog
? M = msinit(2,8, 1); \\ M_8(Gamma_0(2))^+
? [S,E] = mscuspidal(M, 1);
? E[1] \\ 2-dimensional
%3 =
[0 -10]
[0 -15]
[0 -3]
[1 0]
? S[1] \\ 1-dimensional
%4 =
[ 3]
[30]
[ 6]
[-8]
@eprog
Function: mseisenstein
Class: basic
Section: modular_symbols
C-Name: mseisenstein
Prototype: G
Help: mseisenstein(M): M being a full modular symbol space, as given by msinit,
return its Eisenstein subspace.
Doc:
$M$ being a full modular symbol space, as given by \kbd{msinit},
return its Eisenstein subspace.
A subspace is given by a structure allowing quick projection and
restriction of linear operators; its first component is
a matrix with integer coefficients whose columns form a $\Q$-basis of
the subspace.
This is the same basis as given by the second component of
\kbd{mscuspidal}$(M, 1)$.
\bprog
? M = msinit(2,8, 1); \\ M_8(Gamma_0(2))^+
? E = mseisenstein(M);
? E[1] \\ 2-dimensional
%3 =
[0 -10]
[0 -15]
[0 -3]
[1 0]
? E == mscuspidal(M,1)[2]
%4 = 1
@eprog
Function: mseval
Class: basic
Section: modular_symbols
C-Name: mseval
Prototype: GGDG
Help: mseval(M,s,{p}): M being a full modular symbol space, as given by
msinit, s being a modular symbol from M and p being a path between two
elements in P^1(Q), return s(p).
Doc: Let $\Delta:=\text{Div}^0(\P^1 (\Q))$.
Let $M$ be a full modular symbol space, as given by \kbd{msinit},
let $s$ be a modular symbol from $M$, i.e. an element
of $\Hom_G(\Delta, V)$, and let $p=[a,b] \in \Delta$ be a path between
two elements in $\P^1(\Q)$, return $s(p)\in V$. The path extremities $a$ and
$b$ may be given as \typ{INT}, \typ{FRAC} or $\kbd{oo} = (1:0)$.
The symbol $s$ is either
\item a \typ{COL} coding an element of a modular symbol subspace in terms of
the fixed basis of $\Hom_G(\Delta,V)$ chosen in $M$; if $M$ was
initialized with a non-zero \emph{sign} ($+$ or $-$), then either the
basis for the full symbol space or the $\pm$-part can be used (the dimension
being used to distinguish the two).
\item a \typ{VEC} $(v_i)$ of elements of $V$, where the $v_i = s(g_i)$ give
the image of the generators $g_i$ of $\Delta$, see \tet{mspathgens}.
We assume that $s$ is a proper symbol, i.e.~that the $v_i$ satisfy
the \kbd{mspathgens} relations.
If $p$ is omitted, convert the symbol $s$ to the second form: a vector of
the $s(g_i)$.
\bprog
? M = msinit(2,8,1); \\ M_8(Gamma_0(2))^+
? g = mspathgens(M)[1]
%2 = [[+oo, 0], [0, 1]]
? N = msnew(M)[1]; #N \\ Q-basis of new subspace, dimension 1
%3 = 1
? s = N[,1] \\ t_COL representation
%4 = [-3, 6, -8]~
? S = mseval(M, s) \\ t_VEC representation
%5 = [64*x^6-272*x^4+136*x^2-8, 384*x^5+960*x^4+192*x^3-672*x^2-432*x-72]
? mseval(M,s, g[1])
%6 = 64*x^6 - 272*x^4 + 136*x^2 - 8
? mseval(M,S, g[1])
%7 = 64*x^6 - 272*x^4 + 136*x^2 - 8
@eprog\noindent Note that the symbol should have values in
$V = \Q[x,y]_{k-2}$, we return the de-homogenized values corresponding to $y
= 1$ instead.
Function: msfromcusp
Class: basic
Section: modular_symbols
C-Name: msfromcusp
Prototype: GG
Help: msfromcusp(M, c): returns the modular symbol attached to the cusp
c, where M is a modular symbol space of level N.
Doc: returns the modular symbol attached to the cusp
$c$, where $M$ is a modular symbol space of level $N$, attached to
$G = \Gamma_0(N)$. The cusp $c$ in $\P^1(\Q)/G$
can be given either as \kbd{oo} ($=(1:0)$), as a rational number $a/b$
($=(a:b)$). The attached symbol maps the path $[b] - [a] \in
\text{Div}^0 (\P^1(\Q))$ to $E_c(b) - E_c(a)$, where $E_c(r)$ is
$0$ when $r \neq c$ and $X^{k-2} \mid \gamma_r$ otherwise, where
$\gamma_r \cdot r = (1:0)$. These symbol span the Eisenstein subspace
of $M$.
\bprog
? M = msinit(2,8); \\ M_8(Gamma_0(2))
? E = mseisenstein(M);
? E[1] \\ two-dimensional
%3 =
[0 -10]
[0 -15]
[0 -3]
[1 0]
? s = msfromcusp(M,oo)
%4 = [0, 0, 0, 1]~
? mseval(M, s)
%5 = [1, 0]
? s = msfromcusp(M,1)
%6 = [-5/16, -15/32, -3/32, 0]~
? mseval(M,s)
%7 = [-x^6, -6*x^5 - 15*x^4 - 20*x^3 - 15*x^2 - 6*x - 1]
@eprog
In case $M$ was initialized with a non-zero \emph{sign}, the symbol is given
in terms of the fixed basis of the whole symbol space, not the $+$ or $-$
part (to which it need not belong).
\bprog
? M = msinit(2,8, 1); \\ M_8(Gamma_0(2))^+
? E = mseisenstein(M);
? E[1] \\ still two-dimensional, in a smaller space
%3 =
[ 0 -10]
[ 0 3]
[-1 0]
? s = msfromcusp(M,oo) \\ in terms of the basis for M_8(Gamma_0(2)) !
%4 = [0, 0, 0, 1]~
? mseval(M, s) \\ same symbol as before
%5 = [1, 0]
@eprog
Function: msfromell
Class: basic
Section: modular_symbols
C-Name: msfromell
Prototype: GD0,L,
Help: msfromell(E, {sign=0}): return the [M, x], where M is msinit(N,2)
and x is the modular symbol in M attached to the elliptic curve E/Q.
Doc: Let $E/\Q$ be an elliptic curve of conductor $N$. For $\varepsilon =
\pm1$, we define the (cuspidal, new) modular symbol $x^\varepsilon$ in
$H^1_c(X_0(N),\Q)^\varepsilon$ attached to
$E$. For all primes $p$ not dividing $N$ we have
$T_p(x^\varepsilon) = a_p x^\varepsilon$, where $a_p = p+1-\#E(\F_p)$.
Let $\Omega^+ = \kbd{E.omega[1]}$ be the real period of $E$
(integration of the N\'eron differential $dx/(2y+a_1x+a3)$ on the connected
component of $E(\R)$, i.e.~the generator of $H_1(E,\Z)^+$) normalized by
$\Omega^+>0$. Let $i\Omega^-$ the integral on a generator of $H_1(E,\Z)^-$ with
$\Omega^- \in \R_{>0}$. If $c_\infty$ is the number of connected
components of $E(\R)$, $\Omega^-$ is equal to
$(-2/c_\infty) \times \kbd{imag(E.omega[2])}$.
The complex modular symbol is defined by
$$F: \delta \to 2i\pi \int_{\delta} f(z) dz$$
The modular symbols $x^\varepsilon$ are normalized so that
$ F = x^+ \Omega^+ + x^- i\Omega^-$.
In particular, we have
$$ x^+([0]-[\infty]) = L(E,1) / \Omega^+,$$
which defines $x^{\pm}$ unless $L(E,1)=0$.
Furthermore, for all fundamental discriminants $D$ such
that $\varepsilon \cdot D > 0$, we also have
$$\sum_{0\leq a<|D|} (D|a) x^\varepsilon([a/|D|]-[\infty])
= L(E,(D|.),1) / \Omega^{\varepsilon},$$
where $(D|.)$ is the Kronecker symbol.
The period $\Omega^-$ is also $2/c_\infty \times$ the real period
of the twist $E^{(-4)} = \kbd{elltwist(E,-4)}$.
This function returns the pair $[M, x]$, where $M$ is
\kbd{msinit}$(N,2)$ and $x$ is $x^{\var{sign}}$ as above when $\var{sign}=
\pm1$, and $x = [x^+,x^-]$ when \var{sign} is $0$.
The modular symbols $x^\pm$ are given as a \typ{COL} (in terms
of the fixed basis of $\Hom_G(\Delta,\Q)$ chosen in $M$).
\bprog
? E=ellinit([0,-1,1,-10,-20]); \\ X_0(11)
? [M,xp]= msfromell(E,1);
? xp
%3 = [1/5, -1/2, -1/2]~
? [M,x]= msfromell(E);
? x \\ both x^+ and x^-
%5 = [[1/5, -1/2, -1/2]~, [0, 1/2, -1/2]~]
? p = 23; (mshecke(M,p) - ellap(E,p))*x[1]
%6 = [0, 0, 0]~ \\ true at all primes, including p = 11; same for x[2]
@eprog
Function: msfromhecke
Class: basic
Section: modular_symbols
C-Name: msfromhecke
Prototype: GGDG
Help: msfromhecke(M, v, {H}): given a msinit M and a vector v
of pairs [p, P] (where p is prime and P is a polynomial with integer
coefficients), return a basis of all modular symbols such that
P(Tp) * s = 0. If H is present, it must be a Hecke-stable subspace
and we restrict to s in H.
Doc: given a msinit $M$ and a vector $v$ of pairs $[p, P]$ (where $p$ is prime
and $P$ is a polynomial with integer coefficients), return a basis of all
modular symbols such that $P(T_p)(s) = 0$. If $H$ is present, it must
be a Hecke-stable subspace and we restrict to $s \in H$. When $T_p$ has
a rational eigenvalue and $P(x) = x-a_p$ has degree $1$, we also accept the
integer $a_p$ instead of $P$.
\bprog
? E = ellinit([0,-1,1,-10,-20]) \\11a1
? ellap(E,2)
%2 = -2
? ellap(E,3)
%3 = -1
? M = msinit(11,2);
? S = msfromhecke(M, [[2,-2],[3,-1]])
%5 =
[ 1 1]
[-5 0]
[ 0 -5]
? mshecke(M, 2, S)
%6 =
[-2 0]
[ 0 -2]
? M = msinit(23,4);
? S = msfromhecke(M, [[5, x^4-14*x^3-244*x^2+4832*x-19904]]);
? factor( charpoly(mshecke(M,5,S)) )
%9 =
[x^4 - 14*x^3 - 244*x^2 + 4832*x - 19904 2]
@eprog
Function: msgetlevel
Class: basic
Section: modular_symbols
C-Name: msgetlevel
Prototype: lG
Help: msgetlevel(M): M being a full modular symbol space, as given by msinit, return its level N.
Doc: $M$ being a full modular symbol space, as given by \kbd{msinit}, return
its level $N$.
Function: msgetsign
Class: basic
Section: modular_symbols
C-Name: msgetsign
Prototype: lG
Help: msgetsign(M): M being a full modular symbol space, as given by msinit, return its sign.
Doc: $M$ being a full modular symbol space, as given by \kbd{msinit}, return
its sign: $\pm1$ or 0 (unset).
\bprog
? M = msinit(11,4, 1);
? msgetsign(M)
%2 = 1
? M = msinit(11,4);
? msgetsign(M)
%4 = 0
@eprog
Function: msgetweight
Class: basic
Section: modular_symbols
C-Name: msgetweight
Prototype: lG
Help: msgetweight(M): M being a full modular symbol space, as given by msinit, return its weight k.
Doc: $M$ being a full modular symbol space, as given by \kbd{msinit}, return
its weight $k$.
\bprog
? M = msinit(11,4);
? msgetweight(M)
%2 = 4
@eprog
Function: mshecke
Class: basic
Section: modular_symbols
C-Name: mshecke
Prototype: GLDG
Help: mshecke(M,p,{H}): M being a full modular symbol space, as given by msinit,
p being a prime number, and H being a Hecke-stable subspace (M if omitted),
return the matrix of T_p acting on H (U_p if p divides the level).
Doc: $M$ being a full modular symbol space, as given by \kbd{msinit},
$p$ being a prime number, and $H$ being a Hecke-stable subspace ($M$ if
omitted) return the matrix of $T_p$ acting on $H$
($U_p$ if $p$ divides $N$). Result is undefined if $H$ is not stable
by $T_p$ (resp.~$U_p$).
\bprog
? M = msinit(11,2); \\ M_2(Gamma_0(11))
? T2 = mshecke(M,2)
%2 =
[3 0 0]
[1 -2 0]
[1 0 -2]
? M = msinit(11,2, 1); \\ M_2(Gamma_0(11))^+
? T2 = mshecke(M,2)
%4 =
[ 3 0]
[-1 -2]
? N = msnew(M)[1] \\ Q-basis of new cuspidal subspace
%5 =
[-2]
[-5]
? p = 1009; mshecke(M, p, N) \\ action of T_1009 on N
%6 =
[-10]
? ellap(ellinit("11a1"), p)
%7 = -10
@eprog
Function: msinit
Class: basic
Section: modular_symbols
C-Name: msinit
Prototype: GGD0,L,
Help: msinit(G, V, {sign=0}): given G a finite index subgroup of SL(2,Z)
and a finite dimensional representation V of GL(2,Q), creates a space of
modular symbols, the G-module Hom_G(Div^0(P^1 Q), V). This is canonically
isomorphic to H^1_c(X(G), V), and allows to compute modular forms for G.
If sign is present and non-zero, it must be +1 or -1 and we consider
the subspace defined by Ker (Sigma - sign), where Sigma is induced by
[-1,0;0,1]. Currently the only supported groups are the Gamma_0(N), coded by
the integer N. The only supported representation is V_k = Q[X,Y]_{k-2}, coded
by the integer k >= 2.
Doc: given $G$ a finite index subgroup of $\text{SL}(2,\Z)$
and a finite dimensional representation $V$ of $\text{GL}(2,\Q)$, creates a
space of modular symbols, the $G$-module $\Hom_G(\text{Div}^0(\P^1
(\Q)), V)$. This is canonically isomorphic to $H^1_c(X(G), V)$, and allows to
compute modular forms for $G$. If \emph{sign} is present and non-zero, it
must be $\pm1$ and we consider the subspace defined by $\text{Ker} (\sigma -
\var{sign})$, where $\sigma$ is induced by \kbd{[-1,0;0,1]}. Currently the
only supported groups are the $\Gamma_0(N)$, coded by the integer $N > 1$.
The only supported representation is $V_k = \Q[X,Y]_{k-2}$, coded by the
integer $k \geq 2$.
Function: msissymbol
Class: basic
Section: modular_symbols
C-Name: msissymbol
Prototype: lGG
Help: msissymbol(M,s): M being a full modular symbol space, as given by msinit,
check whether s is a modular symbol attached to M.
Doc:
$M$ being a full modular symbol space, as given by \kbd{msinit},
check whether $s$ is a modular symbol attached to $M$.
\bprog
? M = msinit(7,8, 1); \\ M_8(Gamma_0(7))^+
? N = msnew(M)[1];
? s = N[,1];
? msissymbol(M, s)
%4 = 1
? S = mseval(M,s);
? msissymbol(M, S)
%6 = 1
? [g,R] = mspathgens(M); g
%7 = [[+oo, 0], [0, 1/2], [1/2, 1]]
? #R \\ 3 relations among the generators g_i
%8 = 3
? T = S; T[3]++; \\ randomly perturb S(g_3)
? msissymbol(M, T)
%10 = 0 \\ no longer satisfies the relations
@eprog
Function: msnew
Class: basic
Section: modular_symbols
C-Name: msnew
Prototype: G
Help: msnew(M): M being a full modular symbol space, as given by msinit,
return its new cuspidal subspace.
Doc:
$M$ being a full modular symbol space, as given by \kbd{msinit},
return the \emph{new} part of its cuspidal subspace. A subspace is given by
a structure allowing quick projection and restriction of linear operators;
its first component is a matrix with integer coefficients whose columns form
a $\Q$-basis of the subspace.
\bprog
? M = msinit(11,8, 1); \\ M_8(Gamma_0(11))^+
? N = msnew(M);
? #N[1] \\ 6-dimensional
%3 = 6
@eprog
Function: msomseval
Class: basic
Section: modular_symbols
C-Name: msomseval
Prototype: GGG
Help: msomseval(Mp, PHI, path):
return the vectors of moments of the p-adic distribution attached
to the path 'path' via the overconvergent modular symbol 'PHI'.
Doc: return the vectors of moments of the $p$-adic distribution attached
to the path \kbd{path} by the overconvergent modular symbol \kbd{PHI}.
\bprog
? M = msinit(3,6,1);
? Mp= mspadicinit(M,5,10);
? phi = [5,-3,-1]~;
? msissymbol(M,phi)
%4 = 1
? PHI = mstooms(Mp,phi);
? ME = msomseval(Mp,PHI,[oo, 0]);
@eprog
Function: mspadicL
Class: basic
Section: modular_symbols
C-Name: mspadicL
Prototype: GDGD0,L,
Help: mspadicL(mu, {s = 0}, {r = 0}): given
mu from mspadicmoments (p-adic distributions attached to an
overconvergent symbol PHI) returns the value on a
character of Z_p^* represented by s of the derivative of order r of the
p-adic L-function attached to PHI.
Doc: Returns the value (or $r$-th derivative)
on a character $\chi^s$ of $\Z_p^*$ of the $p$-adic $L$-function
attached to \kbd{mu}.
Let $\Phi$ be the $p$-adic distribution-valued overconvergent symbol
attached to a modular symbol $\phi$ for $\Gamma_0(N)$ (eigenvector for
$T_N(p)$ for the eigenvalue $a_p$). Then $L_p(\Phi,\chi^s)=L_p(\mu,s)$ is the
$p$-adic $L$ function defined by
$$L_p(\Phi,\chi^s)= \int_{\Z_p^*} \chi^s(z) d\mu(z)$$
where $\mu$ is the distribution on $\Z_p^*$ defined by the restriction of
$\Phi([\infty]-[0])$ to $\Z_p^*$. The $r$-th derivative is taken in
direction $\langle \chi\rangle$:
$$L_p^{(r)}(\Phi,\chi^s)= \int_{\Z_p^*} \chi^s(z) (\log z)^r d\mu(z).$$
In the argument list,
\item \kbd{mu} is as returned by \tet{mspadicmoments} (distributions
attached to $\Phi$ by restriction to discs $a + p^\nu\Z_p$, $(a,p)=1$).
\item $s=[s_1,s_2]$ with $s_1 \in \Z \subset \Z_p$ and $s_2 \bmod p-1$ or
$s_2 \bmod 2$ for $p=2$, encoding the $p$-adic character $\chi^s := \langle
\chi \rangle^{s_1} \tau^{s_2}$; here $\chi$ is the cyclotomic character from
$\text{Gal}(\Q_p(\mu_{p^\infty})/\Q_p)$ to $\Z_p^*$, and $\tau$ is the
Teichm\"uller character (for $p>2$ and the character of order 2 on
$(\Z/4\Z)^*$ if $p=2$); for convenience, the character $[s,s]$ can also be
represented by the integer $s$.
When $a_p$ is a $p$-adic unit, $L_p$ takes its values in $\Q_p$.
When $a_p$ is not a unit, it takes its values in the
two-dimensional $\Q_p$-vector space $D_{cris}(M(\phi))$ where $M(\phi)$ is
the ``motive'' attached to $\phi$, and we return the two $p$-adic components
with respect to some fixed $\Q_p$-basis.
\bprog
? M = msinit(3,6,1); phi=[5, -3, -1]~;
? msissymbol(M,phi)
%2 = 1
? Mp = mspadicinit(M, 5, 4);
? mu = mspadicmoments(Mp, phi); \\ no twist
\\ End of initializations
? mspadicL(mu,0) \\ L_p(chi^0)
%5 = 5 + 2*5^2 + 2*5^3 + 2*5^4 + ...
? mspadicL(mu,1) \\ L_p(chi), zero for parity reasons
%6 = [O(5^13)]~
? mspadicL(mu,2) \\ L_p(chi^2)
%7 = 3 + 4*5 + 4*5^2 + 3*5^5 + ...
? mspadicL(mu,[0,2]) \\ L_p(tau^2)
%8 = 3 + 5 + 2*5^2 + 2*5^3 + ...
? mspadicL(mu, [1,0]) \\ L_p(<chi>)
%9 = 3*5 + 2*5^2 + 5^3 + 2*5^7 + 5^8 + 5^10 + 2*5^11 + O(5^13)
? mspadicL(mu,0,1) \\ L_p'(chi^0)
%10 = 2*5 + 4*5^2 + 3*5^3 + ...
? mspadicL(mu, 2, 1) \\ L_p'(chi^2)
%11 = 4*5 + 3*5^2 + 5^3 + 5^4 + ...
@eprog
Now several quadratic twists: \tet{mstooms} is indicated.
\bprog
? PHI = mstooms(Mp,phi);
? mu = mspadicmoments(Mp, PHI, 12); \\ twist by 12
? mspadicL(mu)
%14 = 5 + 5^2 + 5^3 + 2*5^4 + ...
? mu = mspadicmoments(Mp, PHI, 8); \\ twist by 8
? mspadicL(mu)
%16 = 2 + 3*5 + 3*5^2 + 2*5^4 + ...
? mu = mspadicmoments(Mp, PHI, -3); \\ twist by -3 < 0
? mspadicL(mu)
%18 = O(5^13) \\ always 0, phi is in the + part and D < 0
@eprog
One can locate interesting symbols of level $N$ and weight $k$ with
\kbd{msnew} and \kbd{mssplit}. Note that instead of a symbol, one can
input a 1-dimensional Hecke-subspace from \kbd{mssplit}: the function will
automatically use the underlying basis vector.
\bprog
? M=msinit(5,4,1); \\ M_4(Gamma_0(5))^+
? L = mssplit(M, msnew(M)); \\ list of irreducible Hecke-subspaces
? phi = L[1]; \\ one Galois orbit of newforms
? #phi[1] \\... this one is rational
%4 = 1
? Mp = mspadicinit(M, 3, 4);
? mu = mspadicmoments(Mp, phi);
? mspadicL(mu)
%7 = 1 + 3 + 3^3 + 3^4 + 2*3^5 + 3^6 + O(3^9)
? M = msinit(11,8, 1); \\ M_8(Gamma_0(11))^+
? Mp = mspadicinit(M, 3, 4);
? L = mssplit(M, msnew(M));
? phi = L[1]; #phi[1] \\ ... this one is two-dimensional
%11 = 2
? mu = mspadicmoments(Mp, phi);
*** at top-level: mu=mspadicmoments(Mp,ph
*** ^--------------------
*** mspadicmoments: incorrect type in mstooms [dim_Q (eigenspace) > 1]
@eprog
Function: mspadicinit
Class: basic
Section: modular_symbols
C-Name: mspadicinit
Prototype: GLLD-1,L,
Help: mspadicinit(M, p, n, {flag}): M being a full modular symbol space,
as given by msinit and a prime p, initialize
technical data needed to compute with overconvergent modular symbols
(modulo p^n). If flag is unset, allow all symbols; if flag = 0, restrict
to ordinary symbols; else initialize for symbols phi such that
Tp(phi) = a_p * phi, with v_p(a_p) >= flag.
Doc: $M$ being a full modular symbol space, as given by \kbd{msinit}, and $p$
a prime, initialize technical data needed to compute with overconvergent
modular symbols, modulo $p^n$. If $\fl$ is unset, allow
all symbols; else initialize only for a restricted range of symbols
depending on $\fl$: if $\fl = 0$ restrict to ordinary symbols, else
restrict to symbols $\phi$ such that $T_p(\phi) = a_p \phi$,
with $v_p(a_p) \geq \fl$, which is faster as $\fl$ increases.
(The fastest initialization is obtained for $\fl = 0$ where we only allow
ordinary symbols.) For supersingular eigensymbols, such that $p\mid a_p$, we
must further assume that $p$ does not divide the level.
\bprog
? E = ellinit("11a1");
? [M,phi] = msfromell(E,1);
? ellap(E,3)
%3 = -1
? Mp = mspadicinit(M, 3, 10, 0); \\ commit to ordinary symbols
? PHI = mstooms(Mp,phi);
@eprog
If we restrict the range of allowed symbols with \fl (for faster
initialization), exceptions will occur if $v_p(a_p)$ violates this bound:
\bprog
? E = ellinit("15a1");
? [M,phi] = msfromell(E,1);
? ellap(E,7)
%3 = 0
? Mp = mspadicinit(M,7,5,0); \\ restrict to ordinary symbols
? PHI = mstooms(Mp,phi)
*** at top-level: PHI=mstooms(Mp,phi)
*** ^---------------
*** mstooms: incorrect type in mstooms [v_p(ap) > mspadicinit flag] (t_VEC).
? Mp = mspadicinit(M,7,5); \\ no restriction
? PHI = mstooms(Mp,phi);
@eprog\noindent This function uses $O(N^2(n+k)^2p)$ memory, where $N$ is the
level of $M$.
Function: mspadicmoments
Class: basic
Section: modular_symbols
C-Name: mspadicmoments
Prototype: GGD1,L,
Help: mspadicmoments(Mp, PHI, {D = 1}): given Mp from mspadicinit, an
overconvergent eigensymbol PHI, and optionally a fundamental discriminant
D coprime to p, return the moments of the p-1 distributions
PHI^D([0]-[oo]) | (a + pZp), 0 < a < p. To be used by mspadicL and
mspadicseries.
Doc: given \kbd{Mp} from \kbd{mspadicinit}, an overconvergent
eigensymbol \kbd{PHI} from \kbd{mstooms} and a fundamental discriminant
$D$ coprime to $p$,
let $\kbd{PHI}^D$ denote the twisted symbol. This function computes
the distribution $\mu = \kbd{PHI}^D([0] - \infty]) \mid \Z_p^*$ restricted
to $\Z_p^*$. More precisely, it returns
the moments of the $p-1$ distributions $\kbd{PHI}^D([0]-[\infty])
\mid (a + p\Z_p)$, $0 < a < p$.
We also allow \kbd{PHI} to be given as a classical
symbol, which is then lifted to an overconvergent symbol by \kbd{mstooms};
but this is wasteful if more than one twist is later needed.
The returned data $\mu$ ($p$-adic distributions attached to \kbd{PHI})
can then be used in \tet{mspadicL} or \tet{mspadicseries}.
This precomputation allows to quickly compute derivatives of different
orders or values at different characters.
\bprog
? M = msinit(3,6, 1);
? phi = [5,-3,-1]~;
? msissymbol(M, phi)
%3 = 1
? p = 5; mshecke(M,p) * phi \\ eigenvector of T_5, a_5 = 6
%4 = [30, -18, -6]~
? Mp = mspadicinit(M, p, 10, 0); \\ restrict to ordinary symbols, mod p^10
? PHI = mstooms(Mp, phi);
? mu = mspadicmoments(Mp, PHI);
? mspadicL(mu)
%8 = 5 + 2*5^2 + 2*5^3 + ...
? mu = mspadicmoments(Mp, PHI, 12); \\ twist by 12
? mspadicL(mu)
%10 = 5 + 5^2 + 5^3 + 2*5^4 + ...
@eprog
Function: mspadicseries
Class: basic
Section: modular_symbols
C-Name: mspadicseries
Prototype: GD0,L,
Help: mspadicseries(mu, {i=0}): given mu from mspadicmoments,
returns the attached p-adic series with maximal p-adic precision, depending
on the precision of M (i-th Teichmueller component, if present).
Doc: Let $\Phi$ be the $p$-adic distribution-valued overconvergent symbol
attached to a modular symbol $\phi$ for $\Gamma_0(N)$ (eigenvector for
$T_N(p)$ for the eigenvalue $a_p$).
If $\mu$ is the distribution on $\Z_p^*$ defined by the restriction of
$\Phi([\infty]-[0])$ to $\Z_p^*$, let
$$\hat{L}_p(\mu,\tau^{i})(x)
= \int_{\Z_p^*} \tau^i(t) (1+x)^{\log_p(t)/\log_p(u)}d\mu(t)$$
Here, $\tau$ is the Teichm\"uller character and $u$ is a specific
multiplicative generator of $1+2p\Z_p$. (Namely $1+p$ if $p>2$ or $5$
if $p=2$.) To explain
the formula, let $G_\infty := \text{Gal}(\Q(\mu_{p^{\infty}})/ \Q)$,
let $\chi:G_\infty\to \Z_p^*$ be the cyclotomic character (isomorphism)
and $\gamma$ the element of $G_\infty$ such that $\chi(\gamma)=u$;
then
$\chi(\gamma)^{\log_p(t)/\log_p(u)}= \langle t \rangle$.
The $p$-padic precision of individual terms is maximal given the precision of
the overconvergent symbol $\mu$.
\bprog
? [M,phi] = msfromell(ellinit("17a1"),1);
? Mp = mspadicinit(M, 5,7);
? mu = mspadicmoments(Mp, phi,1); \\ overconvergent symbol
? mspadicseries(mu)
%4 = (4 + 3*5 + 4*5^2 + 2*5^3 + 2*5^4 + 5^5 + 4*5^6 + 3*5^7 + O(5^9)) \
+ (3 + 3*5 + 5^2 + 5^3 + 2*5^4 + 5^6 + O(5^7))*x \
+ (2 + 3*5 + 5^2 + 4*5^3 + 2*5^4 + O(5^5))*x^2 \
+ (3 + 4*5 + 4*5^2 + O(5^3))*x^3 \
+ (3 + O(5))*x^4 + O(x^5)
@eprog\noindent
An example with non-zero Teichm\"uller:
\bprog
? [M,phi] = msfromell(ellinit("11a1"),1);
? Mp = mspadicinit(M, 3,10);
? mu = mspadicmoments(Mp, phi,1);
? mspadicseries(mu, 2)
%4 = (2 + 3 + 3^2 + 2*3^3 + 2*3^5 + 3^6 + 3^7 + 3^10 + 3^11 + O(3^12)) \
+ (1 + 3 + 2*3^2 + 3^3 + 3^5 + 2*3^6 + 2*3^8 + O(3^9))*x \
+ (1 + 2*3 + 3^4 + 2*3^5 + O(3^6))*x^2 \
+ (3 + O(3^2))*x^3 + O(x^4)
@eprog\noindent
Supersingular example (not checked)
\bprog
? E = ellinit("17a1"); ellap(E,3)
%1 = 0
? [M,phi] = msfromell(E,1);
? Mp = mspadicinit(M, 3,7);
? mu = mspadicmoments(Mp, phi,1);
? mspadicseries(mu)
%5 = [(2*3^-1 + 1 + 3 + 3^2 + 3^3 + 3^4 + 3^5 + 3^6 + O(3^7)) \
+ (2 + 3^3 + O(3^5))*x \
+ (1 + 2*3 + O(3^2))*x^2 + O(x^3),\
(3^-1 + 1 + 3 + 3^2 + 3^3 + 3^4 + 3^5 + 3^6 + O(3^7)) \
+ (1 + 2*3 + 2*3^2 + 3^3 + 2*3^4 + O(3^5))*x \
+ (3^-2 + 3^-1 + O(3^2))*x^2 + O(3^-2)*x^3 + O(x^4)]
@eprog\noindent
Example with a twist:
\bprog
? E = ellinit("11a1");
? [M,phi] = msfromell(E,1);
? Mp = mspadicinit(M, 3,10);
? mu = mspadicmoments(Mp, phi,5); \\ twist by 5
? L = mspadicseries(mu)
%5 = (2*3^2 + 2*3^4 + 3^5 + 3^6 + 2*3^7 + 2*3^10 + O(3^12)) \
+ (2*3^2 + 2*3^6 + 3^7 + 3^8 + O(3^9))*x \
+ (3^3 + O(3^6))*x^2 + O(3^2)*x^3 + O(x^4)
? mspadicL(mu)
%6 = [2*3^2 + 2*3^4 + 3^5 + 3^6 + 2*3^7 + 2*3^10 + O(3^12)]~
? ellpadicL(E,3,10,,5)
%7 = 2 + 2*3^2 + 3^3 + 2*3^4 + 2*3^5 + 3^6 + 2*3^7 + O(3^10)
? mspadicseries(mu,1) \\ must be 0
%8 = O(3^12) + O(3^9)*x + O(3^6)*x^2 + O(3^2)*x^3 + O(x^4)
@eprog
Function: mspathgens
Class: basic
Section: modular_symbols
C-Name: mspathgens
Prototype: G
Help: mspathgens(M): M being a full modular symbol space, as given by
msinit, return a set of Z[G]-generators for Div^0(P^1 Q). The output
is [g,R], where g is a minimal system of generators and R the vector of
Z[G]-relations between the given generators.
Doc: Let $\Delta:=\text{Div}^0(\P^1(\Q))$.
Let $M$ being a full modular symbol space, as given by \kbd{msinit},
return a set of $\Z[G]$-generators for $\Delta$. The output
is $[g,R]$, where $g$ is a minimal system of generators and $R$
the vector of $\Z[G]$-relations between the given generators. A
relation is coded by a vector of pairs $[a_i,i]$ with $a_i\in \Z[G]$
and $i$ the index of a generator, so that $\sum_i a_i g[i] = 0$.
An element $[v]-[u]$ in $\Delta$ is coded by the ``path'' $[u,v]$,
where \kbd{oo} denotes the point at infinity $(1:0)$ on the projective
line.
An element of $\Z[G]$ is coded by a ``factorization matrix'': the first
column contains distinct elements of $G$, and the second integers:
\bprog
? M = msinit(11,8); \\ M_8(Gamma_0(11))
? [g,R] = mspathgens(M);
? g
%3 = [[+oo, 0], [0, 1/3], [1/3, 1/2]] \\ 3 paths
? #R \\ a single relation
%4 = 1
? r = R[1]; #r \\ ...involving all 3 generators
%5 = 3
? r[1]
%6 = [[1, 1; [1, 1; 0, 1], -1], 1]
? r[2]
%7 = [[1, 1; [7, -2; 11, -3], -1], 2]
? r[3]
%8 = [[1, 1; [8, -3; 11, -4], -1], 3]
@eprog\noindent
The given relation is of the form $\sum_i (1-\gamma_i) g_i = 0$, with
$\gamma_i\in \Gamma_0(11)$. There will always be a single relation involving
all generators (corresponding to a round trip along all cusps), then
relations involving a single generator (corresponding to $2$ and $3$-torsion
elements in the group:
\bprog
? M = msinit(2,8); \\ M_8(Gamma_0(2))
? [g,R] = mspathgens(M);
? g
%3 = [[+oo, 0], [0, 1]]
@eprog\noindent
Note that the output depends only on the group $G$, not on the
representation $V$.
Function: mspathlog
Class: basic
Section: modular_symbols
C-Name: mspathlog
Prototype: GG
Help: mspathlog(M,p): M being a full modular symbol space, as given by
msinit and p being a path between two elements in P^1(Q), return (p_i)
in Z[G] such that p = \sum p_i g_i, and the g_i are fixed Z[G]-generators
for Div^0(P^1 Q), see mspathgens.
Doc: Let $\Delta:=\text{Div}^0(\P^1(\Q))$.
Let $M$ being a full modular symbol space, as given by \kbd{msinit},
encoding fixed $\Z[G]$-generators $(g_i)$ of $\Delta$ (see \tet{mspathgens}).
A path $p=[a,b]$ between two elements in $\P^1(\Q)$ corresponds to
$[b]-[a]\in \Delta$. The path extremities $a$ and $b$ may be given as
\typ{INT}, \typ{FRAC} or $\kbd{oo} = (1:0)$.
Returns $(p_i)$ in $\Z[G]$ such that $p = \sum_i p_i g_i$.
\bprog
? M = msinit(2,8); \\ M_8(Gamma_0(2))
? [g,R] = mspathgens(M);
? g
%3 = [[+oo, 0], [0, 1]]
? p = mspathlog(M, [1/2,2/3]);
? p[1]
%5 =
[[1, 0; 2, 1] 1]
? p[2]
%6 =
[[1, 0; 0, 1] 1]
[[3, -1; 4, -1] 1]
@eprog\noindent
Note that the output depends only on the group $G$, not on the
representation $V$.
Function: msqexpansion
Class: basic
Section: modular_symbols
C-Name: msqexpansion
Prototype: GGDP
Help: msqexpansion(M,projH,{B = seriesprecision}): M being a full modular
symbol space, as given by msinit, and projH being a projector on a
Hecke-simple subspace, return the Fourier coefficients [a_n, n <= B]
of the corresponding normalized newform. If B omitted, use seriesprecision.
Doc:
$M$ being a full modular symbol space, as given by \kbd{msinit},
and \var{projH} being a projector on a Hecke-simple subspace (as given
by \tet{mssplit}), return the Fourier coefficients $a_n$, $n\leq B$ of the
corresponding normalized newform. If $B$ is omitted, use
\kbd{seriesprecision}.
This function uses a naive $O(B^2 d^3)$
algorithm, where $d = O(kN)$ is the dimension of $M_k(\Gamma_0(N))$.
\bprog
? M = msinit(11,2, 1); \\ M_2(Gamma_0(11))^+
? L = mssplit(M, msnew(M));
? msqexpansion(M,L[1], 20)
%3 = [1, -2, -1, 2, 1, 2, -2, 0, -2, -2, 1, -2, 4, 4, -1, -4, -2, 4, 0, 2]
? ellan(ellinit("11a1"), 20)
%4 = [1, -2, -1, 2, 1, 2, -2, 0, -2, -2, 1, -2, 4, 4, -1, -4, -2, 4, 0, 2]
@eprog\noindent The shortcut \kbd{msqexpansion(M, s, B)} is available for
a symbol $s$, provided it is a Hecke eigenvector:
\bprog
? E = ellinit("11a1");
? [M,s]=msfromell(E);
? msqexpansion(M,s,10)
%3 = [1, -2, -1, 2, 1, 2, -2, 0, -2, -2]
? ellan(E, 10)
%4 = [1, -2, -1, 2, 1, 2, -2, 0, -2, -2]
@eprog
Function: mssplit
Class: basic
Section: modular_symbols
C-Name: mssplit
Prototype: GGD0,L,
Help: mssplit(M,H,{dimlim}): M being a full modular symbol space, as given by
msinit, and H being a subspace, split H into Hecke-simple subspaces.
If dimlim is present and positive, restrict to dim <= dimlim.
Doc:
Let $M$ denote a full modular symbol space, as given by \kbd{msinit}$(N,k,1)$
or $\kbd{msinit}(N,k,-1)$ and let $H$ be a Hecke-stable subspace of
\kbd{msnew}$(M)$. This function split $H$ into Hecke-simple subspaces. If
\kbd{dimlim} is present and positive, restrict to subspaces of dimension
$\leq \kbd{dimlim}$. A subspace is given by a structure allowing quick
projection and restriction of linear operators; its first component is a
matrix with integer coefficients whose columns form a $\Q$-basis of the
subspace.
\bprog
? M = msinit(11,8, 1); \\ M_8(Gamma_0(11))^+
? L = mssplit(M, msnew(M));
? #L
%3 = 2
? f = msqexpansion(M,L[1],5); f[1].mod
%4 = x^2 + 8*x - 44
? lift(f)
%5 = [1, x, -6*x - 27, -8*x - 84, 20*x - 155]
? g = msqexpansion(M,L[2],5); g[1].mod
%6 = x^4 - 558*x^2 + 140*x + 51744
@eprog\noindent To a Hecke-simple subspace corresponds an orbit of
(normalized) newforms, defined over a number field. In the above example,
we printed the polynomials defining the said fields, as well as the first
5 Fourier coefficients (at the infinite cusp) of one such form.
Function: msstar
Class: basic
Section: modular_symbols
C-Name: msstar
Prototype: GDG
Help: msstar(M,{H}): M being a full modular symbol space,
as given by msinit, return the matrix of the * involution, induced by
complex conjugation, acting on the (stable) subspace H (M if omitted).
Doc: $M$ being a full modular symbol space, as given by \kbd{msinit},
return the matrix of the \kbd{*} involution, induced by complex conjugation,
acting on the (stable) subspace $H$ ($M$ if omitted).
\bprog
? M = msinit(11,2); \\ M_2(Gamma_0(11))
? w = msstar(M);
? w^2 == 1
%3 = 1
@eprog
Function: mstooms
Class: basic
Section: modular_symbols
C-Name: mstooms
Prototype: GG
Help: mstooms(Mp, phi): given Mp from mspadicinit, lift the
(classical) eigen symbol phi to a distribution-valued overconvergent symbol
in the sense of Pollack and Stevens.
The resulting overconvergent eigensymbol can then be used in
mspadicmoments, then mspadicL or mspadicseries.
Doc: given \kbd{Mp} from \kbd{mspadicinit}, lift the (classical) eigen symbol
\kbd{phi} to a $p$-adic distribution-valued overconvergent symbol in the
sense of Pollack and Stevens. More precisely, let $\phi$ belong to the space
$W$ of modular symbols of level $N$, $v_p(N) \leq 1$, and weight $k$ which is
an eigenvector for the Hecke operator $T_N(p)$ for a non-zero eigenvalue
$a_p$ and let $N_0 = \text{lcm}(N,p)$.
Under the action of $T_{N_0}(p)$, $\phi$ generates a subspace $W_\phi$ of
dimension $1$ (if $p\mid N$) or $2$ (if $p$ does not divide $N$) in the
space of modular symbols of level $N_0$.
Let $V_p=[p,0;0,1]$ and $C_p=[a_p,p^{k-1};-1,0]$.
When $p$ does not divide $N$ and $a_p$ is divisible by $p$, \kbd{mstooms}
returns the lift $\Phi$ of $(\phi,\phi|_k V_p)$ such that
$$T_{N_0}(p) \Phi = C_p \Phi$$
When $p$ does not divide $N$ and $a_p$ is not divisible by $p$, \kbd{mstooms}
returns the lift $\Phi$ of $\phi - \alpha^{-1} \phi|_k V_p$
which is an eigenvector of $T_{N_0}(p)$ for the unit eigenvalue
where $\alpha^2 - a_p \alpha + p^{k-1}=0$.
The resulting overconvergent eigensymbol can then be used in
\tet{mspadicmoments}, then \tet{mspadicL} or \tet{mspadicseries}.
\bprog
? M = msinit(3,6, 1); p = 5;
? Tp = mshecke(M, p); factor(charpoly(Tp))
%2 =
[x - 3126 2]
[ x - 6 1]
? phi = matker(Tp - 6)[,1] \\ generator of p-Eigenspace, a_p = 6
%3 = [5, -3, -1]~
? Mp = mspadicinit(M, p, 10, 0); \\ restrict to ordinary symbols, mod p^10
? PHI = mstooms(Mp, phi);
? mu = mspadicmoments(Mp, PHI);
? mspadicL(mu)
%7 = 5 + 2*5^2 + 2*5^3 + ...
@eprog
A non ordinary symbol.
\bprog
? M = msinit(4,6,1); p = 3;
? Tp = mshecke(M, p); factor(charpoly(Tp))
%2 =
[x - 244 3]
[ x + 12 1]
? phi = matker(Tp + 12)[,1] \\ a_p = -12 is divisible by p = 3
%3 = [-1/32, -1/4, -1/32, 1]~
? msissymbol(M,phi)
%4 = 1
? Mp = mspadicinit(M,3,5,0);
? PHI = mstooms(Mp,phi);
*** at top-level: PHI=mstooms(Mp,phi)
*** ^---------------
*** mstooms: incorrect type in mstooms [v_p(ap) > mspadicinit flag] (t_VEC).
? Mp = mspadicinit(M,3,5,1);
? PHI = mstooms(Mp,phi);
@eprog
Function: my
Class: basic
Section: programming/specific
Help: my(x,...,z): declare x,...,z as lexically-scoped local variables.
Function: newtonpoly
Class: basic
Section: number_fields
C-Name: newtonpoly
Prototype: GG
Help: newtonpoly(x,p): Newton polygon of polynomial x with respect to the
prime p.
Doc: gives the vector of the slopes of the Newton
polygon of the polynomial $x$ with respect to the prime number $p$. The $n$
components of the vector are in decreasing order, where $n$ is equal to the
degree of $x$. Vertical slopes occur iff the constant coefficient of $x$ is
zero and are denoted by \kbd{+oo}.
Function: next
Class: basic
Section: programming/control
C-Name: next0
Prototype: D1,L,
Help: next({n=1}): interrupt execution of current instruction sequence, and
start another iteration from the n-th innermost enclosing loops.
Doc: interrupts execution of current $seq$,
resume the next iteration of the innermost enclosing loop, within the
current function call (or top level loop). If $n$ is specified, resume at
the $n$-th enclosing loop. If $n$ is bigger than the number of enclosing
loops, all enclosing loops are exited.
Function: nextprime
Class: basic
Section: number_theoretical
C-Name: nextprime
Prototype: G
Help: nextprime(x): smallest pseudoprime >= x.
Description:
(gen):int nextprime($1)
Doc: finds the smallest pseudoprime (see
\tet{ispseudoprime}) greater than or equal to $x$. $x$ can be of any real
type. Note that if $x$ is a pseudoprime, this function returns $x$ and not
the smallest pseudoprime strictly larger than $x$. To rigorously prove that
the result is prime, use \kbd{isprime}.
Function: nfalgtobasis
Class: basic
Section: number_fields
C-Name: algtobasis
Prototype: GG
Help: nfalgtobasis(nf,x): transforms the algebraic number x into a column
vector on the integral basis nf.zk.
Doc: Given an algebraic number $x$ in the number field $\var{nf}$,
transforms it to a column vector on the integral basis \kbd{\var{nf}.zk}.
\bprog
? nf = nfinit(y^2 + 4);
? nf.zk
%2 = [1, 1/2*y]
? nfalgtobasis(nf, [1,1]~)
%3 = [1, 1]~
? nfalgtobasis(nf, y)
%4 = [0, 2]~
? nfalgtobasis(nf, Mod(y, y^2+4))
%5 = [0, 2]~
@eprog
This is the inverse function of \kbd{nfbasistoalg}.
Function: nfbasis
Class: basic
Section: number_fields
C-Name: nfbasis_gp
Prototype: G
Help: nfbasis(T): integral basis of the field Q[a], where a is
a root of the polynomial T, using the round 4 algorithm. An argument
[T,listP] is possible, where listP is a list of primes (to get an
order which is maximal at certain primes only) or a prime bound.
Doc:
Let $T(X)$ be an irreducible polynomial with integral coefficients. This
function returns an \idx{integral basis} of the number field defined by $T$,
that is a $\Z$-basis of its maximal order. The basis elements are given as
elements in $\Q[X]/(T)$:
\bprog
? nfbasis(x^2 + 1)
%1 = [1, x]
@eprog
This function uses a modified version of the \idx{round 4} algorithm,
due to David \idx{Ford}, Sebastian \idx{Pauli} and Xavier \idx{Roblot}.
\misctitle{Local basis, orders maximal at certain primes}
Obtaining the maximal order is hard: it requires factoring the discriminant
$D$ of $T$. Obtaining an order which is maximal at a finite explicit set of
primes is easy, but it may then be a strict suborder of the maximal order. To
specify that we are interested in a given set of places only, we can replace
the argument $T$ by an argument $[T,\var{listP}]$, where \var{listP} encodes
the primes we are interested in: it must be a factorization matrix, a vector
of integers or a single integer.
\item Vector: we assume that it contains distinct \emph{prime} numbers.
\item Matrix: we assume that it is a two-column matrix of a
(partial) factorization of $D$; namely the first column contains
distinct \emph{primes} and the second one the valuation of $D$ at each of
these primes.
\item Integer $B$: this is replaced by the vector of primes up to $B$. Note
that the function will use at least $O(B)$ time: a small value, about
$10^5$, should be enough for most applications. Values larger than $2^{32}$
are not supported.
In all these cases, the primes may or may not divide the discriminant $D$
of $T$. The function then returns a $\Z$-basis of an order whose index is
not divisible by any of these prime numbers. The result is actually a global
integral basis if all prime divisors of the \emph{field} discriminant are
included! Note that \kbd{nfinit} has built-in support for such
a check:
\bprog
? K = nfinit([T, listP]);
? nfcertify(K) \\ we computed an actual maximal order
%2 = [];
@eprog\noindent The first line initializes a number field structure
incorporating \kbd{nfbasis([T, listP]} in place of a proven integral basis.
The second line certifies that the resulting structure is correct. This
allows to create an \kbd{nf} structure attached to the number field $K =
\Q[X]/(T)$, when the discriminant of $T$ cannot be factored completely,
whereas the prime divisors of $\disc K$ are known.
Of course, if \var{listP} contains a single prime number $p$,
the function returns a local integral basis for $\Z_p[X]/(T)$:
\bprog
? nfbasis(x^2+x-1001)
%1 = [1, 1/3*x - 1/3]
? nfbasis( [x^2+x-1001, [2]] )
%2 = [1, x]
@eprog
\misctitle{The Buchmann-Lenstra algorithm}
We now complicate the picture: it is in fact allowed to include
\emph{composite} numbers instead of primes
in \kbd{listP} (Vector or Matrix case), provided they are pairwise coprime.
The result will still be a correct integral basis \emph{if}
the field discriminant factors completely over the actual primes in the list.
Adding a composite $C$ such that $C^2$ \emph{divides} $D$ may help because
when we consider $C$ as a prime and run the algorithm, two good things can
happen: either we
succeed in proving that no prime dividing $C$ can divide the index
(without actually needing to find those primes), or the computation
exhibits a non-trivial zero divisor, thereby factoring $C$ and
we go on with the refined factorization. (Note that including a $C$
such that $C^2$ does not divide $D$ is useless.) If neither happen, then the
computed basis need not generate the maximal order. Here is an example:
\bprog
? B = 10^5;
? P = factor(poldisc(T), B)[,1]; \\ primes <= B dividing D + cofactor
? basis = nfbasis([T, listP])
? disc = nfdisc([T, listP])
@eprog\noindent We obtain the maximal order and its discriminant if the
field discriminant factors
completely over the primes less than $B$ (together with the primes
contained in the \tet{addprimes} table). This can be tested as follows:
\bprog
check = factor(disc, B);
lastp = check[-1..-1,1];
if (lastp > B && !setsearch(addprimes(), lastp),
warning("nf may be incorrect!"))
@eprog\noindent
This is a sufficient but not a necessary condition, hence the warning,
instead of an error. N.B. \kbd{lastp} is the last entry
in the first column of the \kbd{check} matrix, i.e. the largest prime
dividing \kbd{nf.disc} if $\leq B$ or if it belongs to the prime table.
The function \tet{nfcertify} speeds up and automates the above process:
\bprog
? B = 10^5;
? nf = nfinit([T, B]);
? nfcertify(nf)
%3 = [] \\ nf is unconditionally correct
? basis = nf.zk;
? disc = nf.disc;
@eprog
\synt{nfbasis}{GEN T, GEN *d, GEN listP = NULL}, which returns the order
basis, and where \kbd{*d} receives the order discriminant.
Function: nfbasistoalg
Class: basic
Section: number_fields
C-Name: basistoalg
Prototype: GG
Help: nfbasistoalg(nf,x): transforms the column vector x on the integral
basis into an algebraic number.
Doc: Given an algebraic number $x$ in the number field \var{nf}, transforms it
into \typ{POLMOD} form.
\bprog
? nf = nfinit(y^2 + 4);
? nf.zk
%2 = [1, 1/2*y]
? nfbasistoalg(nf, [1,1]~)
%3 = Mod(1/2*y + 1, y^2 + 4)
? nfbasistoalg(nf, y)
%4 = Mod(y, y^2 + 4)
? nfbasistoalg(nf, Mod(y, y^2+4))
%5 = Mod(y, y^2 + 4)
@eprog
This is the inverse function of \kbd{nfalgtobasis}.
Function: nfcertify
Class: basic
Section: number_fields
C-Name: nfcertify
Prototype: G
Help: nfcertify(nf): returns a vector of composite integers used to certify
nf.zk and nf.disc unconditionally (both are correct when the output
is the empty vector).
Doc: $\var{nf}$ being as output by
\kbd{nfinit}, checks whether the integer basis is known unconditionally.
This is in particular useful when the argument to \kbd{nfinit} was of the
form $[T, \kbd{listP}]$, specifying a finite list of primes when
$p$-maximality had to be proven, or a list of coprime integers to which
Buchmann-Lenstra algorithm was to be applied.
The function returns a vector of coprime composite integers. If this vector
is empty, then \kbd{nf.zk} and \kbd{nf.disc} are correct. Otherwise, the
result is dubious. In order to obtain a certified result, one must completely
factor each of the given integers, then \kbd{addprime} each of their prime
factors, then check whether \kbd{nfdisc(nf.pol)} is equal to \kbd{nf.disc}.
Function: nfcompositum
Class: basic
Section: number_fields
C-Name: nfcompositum
Prototype: GGGD0,L,
Help: nfcompositum(nf,P,Q,{flag=0}): vector of all possible compositums
of the number fields defined by the polynomials P and Q; flag is
optional, whose binary digits mean 1: output for each compositum, not only
the compositum polynomial pol, but a vector [R,a,b,k] where a (resp. b) is a
root of P (resp. Q) expressed as a polynomial modulo R, and a small integer k
such that al2+k*al1 is the chosen root of R; 2: assume that the number
fields defined by P and Q are linearly disjoint.
Doc: Let \var{nf} be a number field structure attached to the field $K$
and let \sidx{compositum} $P$ and $Q$
be squarefree polynomials in $K[X]$ in the same variable. Outputs
the simple factors of the \'etale $K$-algebra $A = K[X, Y] / (P(X), Q(Y))$.
The factors are given by a list of polynomials $R$ in $K[X]$, attached to
the number field $K[X]/ (R)$, and sorted by increasing degree (with respect
to lexicographic ordering for factors of equal degrees). Returns an error if
one of the polynomials is not squarefree.
Note that it is more efficient to reduce to the case where $P$ and $Q$ are
irreducible first. The routine will not perform this for you, since it may be
expensive, and the inputs are irreducible in most applications anyway. In
this case, there will be a single factor $R$ if and only if the number
fields defined by $P$ and $Q$ are linearly disjoint (their intersection is
$K$).
The binary digits of $\fl$ mean
1: outputs a vector of 4-component vectors $[R,a,b,k]$, where $R$
ranges through the list of all possible compositums as above, and $a$
(resp. $b$) expresses the root of $P$ (resp. $Q$) as an element of
$K[X]/(R)$. Finally, $k$ is a small integer such that $b + ka = X$ modulo
$R$.
2: assume that $P$ and $Q$ define number fields that are linearly disjoint:
both polynomials are irreducible and the corresponding number fields
have no common subfield besides $K$. This allows to save a costly
factorization over $K$. In this case return the single simple factor
instead of a vector with one element.
A compositum is often defined by a complicated polynomial, which it is
advisable to reduce before further work. Here is an example involving
the field $K(\zeta_5, 5^{1/10})$, $K=\Q(\sqrt{5})$:
\bprog
? K = nfinit(y^2-5);
? L = nfcompositum(K, x^5 - y, polcyclo(5), 1); \\@com list of $[R,a,b,k]$
? [R, a] = L[1]; \\@com pick the single factor, extract $R,a$ (ignore $b,k$)
? lift(R) \\@com defines the compositum
%4 = x^10 + (-5/2*y + 5/2)*x^9 + (-5*y + 20)*x^8 + (-20*y + 30)*x^7 + \
(-45/2*y + 145/2)*x^6 + (-71/2*y + 121/2)*x^5 + (-20*y + 60)*x^4 + \
(-25*y + 5)*x^3 + 45*x^2 + (-5*y + 15)*x + (-2*y + 6)
? a^5 - y \\@com a fifth root of $y$
%5 = 0
? [T, X] = rnfpolredbest(K, R, 1);
? lift(T) \\@com simpler defining polynomial for $K[x]/(R)$
%7 = x^10 + (-11/2*y + 25/2)
? liftall(X) \\ @com root of $R$ in $K[x]/(T(x))$
%8 = (3/4*y + 7/4)*x^7 + (-1/2*y - 1)*x^5 + 1/2*x^2 + (1/4*y - 1/4)
? a = subst(a.pol, 'x, X); \\@com \kbd{a} in the new coordinates
? liftall(a)
%10 = (-3/4*y - 7/4)*x^7 - 1/2*x^2
? a^5 - y
%11 = 0
@eprog
The main variables of $P$ and $Q$ must be the same and have higher priority
than that of \var{nf} (see~\kbd{varhigher} and~\kbd{varlower}).
Function: nfdetint
Class: basic
Section: number_fields
C-Name: nfdetint
Prototype: GG
Help: nfdetint(nf,x): multiple of the ideal determinant of the pseudo
generating set x.
Doc: given a pseudo-matrix $x$, computes a
non-zero ideal contained in (i.e.~multiple of) the determinant of $x$. This
is particularly useful in conjunction with \kbd{nfhnfmod}.
Function: nfdisc
Class: basic
Section: number_fields
C-Name: nfdisc
Prototype: G
Help: nfdisc(T): discriminant of the number field defined by
the polynomial T. An argument [T,listP] is possible, where listP is a list
of primes or a prime bound.
Doc: \idx{field discriminant} of the number field defined by the integral,
preferably monic, irreducible polynomial $T(X)$. Returns the discriminant of
the number field $\Q[X]/(T)$, using the Round $4$ algorithm.
\misctitle{Local discriminants, valuations at certain primes}
As in \kbd{nfbasis}, the argument $T$ can be replaced by $[T,\var{listP}]$,
where \kbd{listP} is as in \kbd{nfbasis}: a vector of
pairwise coprime integers (usually distinct primes), a factorization matrix,
or a single integer. In that case, the function returns the discriminant of
an order whose basis is given by \kbd{nfbasis(T,listP)}, which need not be
the maximal order, and whose valuation at a prime entry in \kbd{listP} is the
same as the valuation of the field discriminant.
In particular, if \kbd{listP} is $[p]$ for a prime $p$, we can
return the $p$-adic discriminant of the maximal order of $\Z_p[X]/(T)$,
as a power of $p$, as follows:
\bprog
? padicdisc(T,p) = p^valuation(nfdisc(T,[p]), p);
? nfdisc(x^2 + 6)
%2 = -24
? padicdisc(x^2 + 6, 2)
%3 = 8
? padicdisc(x^2 + 6, 3)
%4 = 3
@eprog
\synt{nfdisc}{GEN T} (\kbd{listP = NULL}). Also available is
\fun{GEN}{nfbasis}{GEN T, GEN *d, GEN listP = NULL}, which returns the order
basis, and where \kbd{*d} receives the order discriminant.
Function: nfeltadd
Class: basic
Section: number_fields
C-Name: nfadd
Prototype: GGG
Help: nfeltadd(nf,x,y): element x+y in nf.
Doc:
given two elements $x$ and $y$ in
\var{nf}, computes their sum $x+y$ in the number field $\var{nf}$.
Function: nfeltdiv
Class: basic
Section: number_fields
C-Name: nfdiv
Prototype: GGG
Help: nfeltdiv(nf,x,y): element x/y in nf.
Doc: given two elements $x$ and $y$ in
\var{nf}, computes their quotient $x/y$ in the number field $\var{nf}$.
Function: nfeltdiveuc
Class: basic
Section: number_fields
C-Name: nfdiveuc
Prototype: GGG
Help: nfeltdiveuc(nf,x,y): gives algebraic integer q such that x-qy is small.
Doc: given two elements $x$ and $y$ in
\var{nf}, computes an algebraic integer $q$ in the number field $\var{nf}$
such that the components of $x-qy$ are reasonably small. In fact, this is
functionally identical to \kbd{round(nfdiv(\var{nf},x,y))}.
Function: nfeltdivmodpr
Class: basic
Section: number_fields
C-Name: nfdivmodpr
Prototype: GGGG
Help: nfeltdivmodpr(nf,x,y,pr): this function is obsolete, use nfmodpr.
Doc: this function is obsolete, use \kbd{nfmodpr}.
Given two elements $x$
and $y$ in \var{nf} and \var{pr} a prime ideal in \kbd{modpr} format (see
\tet{nfmodprinit}), computes their quotient $x / y$ modulo the prime ideal
\var{pr}.
Obsolete: 2016-08-09
Variant: This function is normally useless in library mode. Project your
inputs to the residue field using \kbd{nf\_to\_Fq}, then work there.
Function: nfeltdivrem
Class: basic
Section: number_fields
C-Name: nfdivrem
Prototype: GGG
Help: nfeltdivrem(nf,x,y): gives [q,r] such that r=x-qy is small.
Doc: given two elements $x$ and $y$ in
\var{nf}, gives a two-element row vector $[q,r]$ such that $x=qy+r$, $q$ is
an algebraic integer in $\var{nf}$, and the components of $r$ are
reasonably small.
Function: nfeltmod
Class: basic
Section: number_fields
C-Name: nfmod
Prototype: GGG
Help: nfeltmod(nf,x,y): gives r such that r=x-qy is small with q algebraic
integer.
Doc:
given two elements $x$ and $y$ in
\var{nf}, computes an element $r$ of $\var{nf}$ of the form $r=x-qy$ with
$q$ and algebraic integer, and such that $r$ is small. This is functionally
identical to
$$\kbd{x - nfmul(\var{nf},round(nfdiv(\var{nf},x,y)),y)}.$$
Function: nfeltmul
Class: basic
Section: number_fields
C-Name: nfmul
Prototype: GGG
Help: nfeltmul(nf,x,y): element x.y in nf.
Doc:
given two elements $x$ and $y$ in
\var{nf}, computes their product $x*y$ in the number field $\var{nf}$.
Function: nfeltmulmodpr
Class: basic
Section: number_fields
C-Name: nfmulmodpr
Prototype: GGGG
Help: nfeltmulmodpr(nf,x,y,pr): this function is obsolete, use nfmodpr.
Doc: this function is obsolete, use \kbd{nfmodpr}.
Given two elements $x$ and
$y$ in \var{nf} and \var{pr} a prime ideal in \kbd{modpr} format (see
\tet{nfmodprinit}), computes their product $x*y$ modulo the prime ideal
\var{pr}.
Obsolete: 2016-08-09
Variant: This function is normally useless in library mode. Project your
inputs to the residue field using \kbd{nf\_to\_Fq}, then work there.
Function: nfeltnorm
Class: basic
Section: number_fields
C-Name: nfnorm
Prototype: GG
Help: nfeltnorm(nf,x): norm of x.
Doc: returns the absolute norm of $x$.
Function: nfeltpow
Class: basic
Section: number_fields
C-Name: nfpow
Prototype: GGG
Help: nfeltpow(nf,x,k): element x^k in nf.
Doc: given an element $x$ in \var{nf}, and a positive or negative integer $k$,
computes $x^k$ in the number field $\var{nf}$.
Variant: \fun{GEN}{nfinv}{GEN nf, GEN x} correspond to $k = -1$, and
\fun{GEN}{nfsqr}{GEN nf,GEN x} to $k = 2$.
Function: nfeltpowmodpr
Class: basic
Section: number_fields
C-Name: nfpowmodpr
Prototype: GGGG
Help: nfeltpowmodpr(nf,x,k,pr): this function is obsolete, use nfmodpr.
Doc: this function is obsolete, use \kbd{nfmodpr}.
Given an element $x$ in \var{nf}, an integer $k$ and a prime ideal
\var{pr} in \kbd{modpr} format
(see \tet{nfmodprinit}), computes $x^k$ modulo the prime ideal \var{pr}.
Obsolete: 2016-08-09
Variant: This function is normally useless in library mode. Project your
inputs to the residue field using \kbd{nf\_to\_Fq}, then work there.
Function: nfeltreduce
Class: basic
Section: number_fields
C-Name: nfreduce
Prototype: GGG
Help: nfeltreduce(nf,a,id): gives r such that a-r is in the ideal id and r
is small.
Doc: given an ideal \var{id} in
Hermite normal form and an element $a$ of the number field $\var{nf}$,
finds an element $r$ in $\var{nf}$ such that $a-r$ belongs to the ideal
and $r$ is small.
Function: nfeltreducemodpr
Class: basic
Section: number_fields
C-Name: nfreducemodpr
Prototype: GGG
Help: nfeltreducemodpr(nf,x,pr): this function is obsolete, use nfmodpr.
Doc: this function is obsolete, use \kbd{nfmodpr}.
Given an element $x$ of the number field $\var{nf}$ and a prime ideal
\var{pr} in \kbd{modpr} format compute a canonical representative for the
class of $x$ modulo \var{pr}.
Obsolete: 2016-08-09
Variant: This function is normally useless in library mode. Project your
inputs to the residue field using \kbd{nf\_to\_Fq}, then work there.
Function: nfelttrace
Class: basic
Section: number_fields
C-Name: nftrace
Prototype: GG
Help: nfelttrace(nf,x): trace of x.
Doc: returns the absolute trace of $x$.
Function: nfeltval
Class: basic
Section: number_fields
C-Name: gpnfvalrem
Prototype: GGGD&
Help: nfeltval(nf,x,pr,{&y}): valuation of element x at the prime pr as output
by idealprimedec.
Doc: given an element $x$ in
\var{nf} and a prime ideal \var{pr} in the format output by
\kbd{idealprimedec}, computes the valuation $v$ at \var{pr} of the
element $x$. The valuation of $0$ is \kbd{+oo}.
\bprog
? nf = nfinit(x^2 + 1);
? P = idealprimedec(nf, 2)[1];
? nfeltval(nf, x+1, P)
%3 = 1
@eprog\noindent
This particular valuation can also be obtained using
\kbd{idealval(\var{nf},x,\var{pr})}, since $x$ is then converted to a
principal ideal.
If the $y$ argument is present, sets $y = x \tau^v$, where $\tau$ is a
fixed ``anti-uniformizer'' for \var{pr}: its valuation at \var{pr} is $-1$;
its valuation is $0$ at other prime ideals dividing \kbd{\var{pr}.p} and
nonnegative at all other primes. In other words $y$ is the part of $x$
coprime to \var{pr}. If $x$ is an algebraic integer, so is $y$.
\bprog
? nfeltval(nf, x+1, P, &y); y
%4 = [0, 1]~
@eprog
For instance if $x = \prod_i x_i^{e_i}$ is known to be coprime to \var{pr},
where the $x_i$ are algebraic integers and $e_i\in\Z$ then,
if $v_i = \kbd{nfeltval}(\var{nf}, x_i, \var{pr}, \&y_i)$, we still
have $x = \prod_i y_i^{e_i}$, where the $y_i$ are still algebraic integers
but now all of them are coprime to \var{pr}. They can then be mapped to
the residue field of \var{pr} more efficiently than if the product had
been expanded beforehand: we can reduce mod \var{pr} after each ring
operation.
Variant: Also available is
\fun{long}{nfvalrem}{GEN nf, GEN x, GEN pr, GEN *y = NULL}, which returns
\tet{LONG_MAX} if $x = 0$ and the valuation as a \kbd{long} integer.
Function: nffactor
Class: basic
Section: number_fields
C-Name: nffactor
Prototype: GG
Help: nffactor(nf,T): factor polynomial T in number field nf.
Doc: factorization of the univariate
polynomial $T$ over the number field $\var{nf}$ given by \kbd{nfinit}; $T$
has coefficients in $\var{nf}$ (i.e.~either scalar, polmod, polynomial or
column vector). The factors are sorted by increasing degree.
The main variable of $\var{nf}$ must be of \emph{lower}
priority than that of $T$, see \secref{se:priority}. However if
the polynomial defining the number field occurs explicitly in the
coefficients of $T$ as modulus of a \typ{POLMOD} or as a \typ{POL}
coefficient, its main variable must be \emph{the same} as the main variable
of $T$. For example,
\bprog
? nf = nfinit(y^2 + 1);
? nffactor(nf, x^2 + y); \\@com OK
? nffactor(nf, x^2 + Mod(y, y^2+1)); \\ @com OK
? nffactor(nf, x^2 + Mod(z, z^2+1)); \\ @com WRONG
@eprog
It is possible to input a defining polynomial for \var{nf}
instead, but this is in general less efficient since parts of an \kbd{nf}
structure will then be computed internally. This is useful in two
situations: when you do not need the \kbd{nf} elsewhere, or when you cannot
initialize an \kbd{nf} due to integer factorization difficulties when
attempting to compute the field discriminant and maximal order. In all
cases, the function runs in polynomial time using Belabas's variant
of \idx{van Hoeij}'s algorithm, which copes with hundreds of modular factors.
\misctitle{Caveat} \kbd{nfinit([T, listP])} allows to compute in polynomial
time a conditional \var{nf} structure, which sets \kbd{nf.zk} to an order
which is not guaranteed to be maximal at all primes. Always either use
\kbd{nfcertify} first (which may not run in polynomial time) or make sure
to input \kbd{nf.pol} instead of the conditional \var{nf}: \kbd{nffactor} is
able to recover in polynomial time in this case, instead of potentially
missing a factor.
Function: nffactorback
Class: basic
Section: number_fields
C-Name: nffactorback
Prototype: GGDG
Help: nffactorback(nf,f,{e}): given a factorisation f, returns
the factored object back as an nf element.
Doc: gives back the \var{nf} element corresponding to a factorization.
The integer $1$ corresponds to the empty factorization.
If $e$ is present, $e$ and $f$ must be vectors of the same length ($e$ being
integral), and the corresponding factorization is the product of the
$f[i]^{e[i]}$.
If not, and $f$ is vector, it is understood as in the preceding case with $e$
a vector of 1s: we return the product of the $f[i]$. Finally, $f$ can be a
regular factorization matrix.
\bprog
? nf = nfinit(y^2+1);
? nffactorback(nf, [3, y+1, [1,2]~], [1, 2, 3])
%2 = [12, -66]~
? 3 * (I+1)^2 * (1+2*I)^3
%3 = 12 - 66*I
@eprog
Function: nffactormod
Class: basic
Section: number_fields
C-Name: nffactormod
Prototype: GGG
Help: nffactormod(nf,Q,pr): this routine is obsolete, use nfmodpr and
factorff. Factor polynomial Q modulo prime ideal pr
in number field nf.
Doc: this routine is obsolete, use \kbd{nfmodpr} and \kbd{factorff}.
Factors the univariate polynomial $Q$ modulo the prime ideal \var{pr} in
the number field $\var{nf}$. The coefficients of $Q$ belong to the number
field (scalar, polmod, polynomial, even column vector) and the main variable
of $\var{nf}$ must be of lower priority than that of $Q$ (see
\secref{se:priority}). The prime ideal \var{pr} is either in
\tet{idealprimedec} or (preferred) \tet{modprinit} format. The coefficients
of the polynomial factors are lifted to elements of \var{nf}:
\bprog
? K = nfinit(y^2+1);
? P = idealprimedec(K, 3)[1];
? nffactormod(K, x^2 + y*x + 18*y+1, P)
%3 =
[x + (2*y + 1) 1]
[x + (2*y + 2) 1]
? P = nfmodprinit(K, P); \\ convert to nfmodprinit format
? nffactormod(K, x^2 + y*x + 18*y+1)
%5 =
[x + (2*y + 1) 1]
[x + (2*y + 2) 1]
@eprog\noindent Same result, of course, here about 10\% faster due to the
precomputation.
Obsolete: 2016-09-18
Function: nfgaloisapply
Class: basic
Section: number_fields
C-Name: galoisapply
Prototype: GGG
Help: nfgaloisapply(nf,aut,x): apply the Galois automorphism aut to the object
x (element or ideal) in the number field nf.
Doc: let $\var{nf}$ be a
number field as output by \kbd{nfinit}, and let \var{aut} be a \idx{Galois}
automorphism of $\var{nf}$ expressed by its image on the field generator
(such automorphisms can be found using \kbd{nfgaloisconj}). The function
computes the action of the automorphism \var{aut} on the object $x$ in the
number field; $x$ can be a number field element, or an ideal (possibly
extended). Because of possible confusion with elements and ideals, other
vector or matrix arguments are forbidden.
\bprog
? nf = nfinit(x^2+1);
? L = nfgaloisconj(nf)
%2 = [-x, x]~
? aut = L[1]; /* the non-trivial automorphism */
? nfgaloisapply(nf, aut, x)
%4 = Mod(-x, x^2 + 1)
? P = idealprimedec(nf,5); /* prime ideals above 5 */
? nfgaloisapply(nf, aut, P[2]) == P[1]
%6 = 0 \\ !!!!
? idealval(nf, nfgaloisapply(nf, aut, P[2]), P[1])
%7 = 1
@eprog\noindent The surprising failure of the equality test (\kbd{\%7}) is
due to the fact that although the corresponding prime ideals are equal, their
representations are not. (A prime ideal is specified by a uniformizer, and
there is no guarantee that applying automorphisms yields the same elements
as a direct \kbd{idealprimedec} call.)
The automorphism can also be given as a column vector, representing the
image of \kbd{Mod(x, nf.pol)} as an algebraic number. This last
representation is more efficient and should be preferred if a given
automorphism must be used in many such calls.
\bprog
? nf = nfinit(x^3 - 37*x^2 + 74*x - 37);
? aut = nfgaloisconj(nf)[2]; \\ @com an automorphism in basistoalg form
%2 = -31/11*x^2 + 1109/11*x - 925/11
? AUT = nfalgtobasis(nf, aut); \\ @com same in algtobasis form
%3 = [16, -6, 5]~
? v = [1, 2, 3]~; nfgaloisapply(nf, aut, v) == nfgaloisapply(nf, AUT, v)
%4 = 1 \\ @com same result...
? for (i=1,10^5, nfgaloisapply(nf, aut, v))
time = 463 ms.
? for (i=1,10^5, nfgaloisapply(nf, AUT, v))
time = 343 ms. \\ @com but the latter is faster
@eprog
Function: nfgaloisconj
Class: basic
Section: number_fields
C-Name: galoisconj0
Prototype: GD0,L,DGp
Help: nfgaloisconj(nf,{flag=0},{d}): list of conjugates of a root of the
polynomial x=nf.pol in the same number field. flag is optional (set to 0 by
default), meaning 0: use combination of flag 4 and 1, always complete; 1:
use nfroots; 4: use Allombert's algorithm, complete if the field is Galois of
degree <= 35 (see manual for details). nf can be simply a polynomial.
Doc: $\var{nf}$ being a number field as output by \kbd{nfinit}, computes the
conjugates of a root $r$ of the non-constant polynomial $x=\var{nf}[1]$
expressed as polynomials in $r$. This also makes sense when the number field
is not \idx{Galois} since some conjugates may lie in the field.
$\var{nf}$ can simply be a polynomial.
If no flags or $\fl=0$, use a combination of flag $4$ and $1$ and the result
is always complete. There is no point whatsoever in using the other flags.
If $\fl=1$, use \kbd{nfroots}: a little slow, but guaranteed to work in
polynomial time.
If $\fl=4$, use \kbd{galoisinit}: very fast, but only applies to (most)
Galois fields. If the field is Galois with weakly super-solvable Galois
group (see \tet{galoisinit}), return the complete list of automorphisms, else
only the identity element. If present, $d$ is assumed to be a multiple of the
least common denominator of the conjugates expressed as polynomial in a root
of \var{pol}.
This routine can only compute $\Q$-automorphisms, but it may be used to get
$K$-automorphism for any base field $K$ as follows:
\bprog
rnfgaloisconj(nfK, R) = \\ K-automorphisms of L = K[X] / (R)
{
my(polabs, N,al,S, ala,k, vR);
R *= Mod(1, nfK.pol); \\ convert coeffs to polmod elts of K
vR = variable(R);
al = Mod(variable(nfK.pol),nfK.pol);
[polabs,ala,k] = rnfequation(nfK, R, 1);
Rt = if(k==0,R,subst(R,vR,vR-al*k));
N = nfgaloisconj(polabs) % Rt; \\ Q-automorphisms of L
S = select(s->subst(Rt, vR, Mod(s,Rt)) == 0, N);
if (k==0, S, apply(s->subst(s,vR,vR+k*al)-k*al,S));
}
K = nfinit(y^2 + 7);
rnfgaloisconj(K, x^4 - y*x^3 - 3*x^2 + y*x + 1) \\ K-automorphisms of L
@eprog
Variant: Use directly
\fun{GEN}{galoisconj}{GEN nf, GEN d}, corresponding to $\fl = 0$, the others
only have historical interest.
Function: nfgrunwaldwang
Class: basic
Section: number_fields
C-Name: nfgrunwaldwang
Prototype: GGGGDn
Help: nfgrunwaldwang(nf,Lpr,Ld,pl,{v='x}): a polynomial in the variable v
defining a cyclic extension of nf (given in nf or bnf form) with local
behaviour prescribed by Lpr, Ld and pl: the extension has local degree a
multiple of Ld[i] at the prime Lpr[i], and the extension is complex at the
i-th real place of nf if pl[i]=-1 (no condition if pl[i]=0). The extension
has degree the LCM of the local degrees.
Doc: Given \var{nf} a number field in \var{nf} or \var{bnf} format,
a \typ{VEC} \var{Lpr} of primes of \var{nf} and a \typ{VEC} \var{Ld} of
positive integers of the same length, a \typ{VECSMALL} \var{pl} of length
$r_1$ the number of real places of \var{nf}, computes a polynomial with
coefficients in \var{nf} defining a cyclic extension of \var{nf} of
minimal degree satisfying certain local conditions:
\item at the prime \kbd{Lpr[i]}, the extension has local degree a multiple of
\kbd{Ld[i]};
\item at the $i$-th real place of \var{nf}, it is complex if $pl[i]=-1$
(no condition if $pl[i]=0$).
The extension has degree the LCM of the local degrees. Currently, the degree
is restricted to be a prime power for the search, and to be prime for the
construction because of the \kbd{rnfkummer} restrictions.
When \var{nf} is $\Q$, prime integers are accepted instead of \kbd{prid}
structures. However, their primality is not checked and the behaviour is
undefined if you provide a composite number.
\misctitle{Warning} If the number field \var{nf} does not contain the $n$-th
roots of unity where $n$ is the degree of the extension to be computed,
triggers the computation of the \var{bnf} of $nf(\zeta_n)$, which may be
costly.
\bprog
? nf = nfinit(y^2-5);
? pr = idealprimedec(nf,13)[1];
? pol = nfgrunwaldwang(nf, [pr], [2], [0,-1], 'x)
%3 = x^2 + Mod(3/2*y + 13/2, y^2 - 5)
@eprog
Function: nfhilbert
Class: basic
Section: number_fields
C-Name: nfhilbert0
Prototype: lGGGDG
Help: nfhilbert(nf,a,b,{pr}): if pr is omitted, global Hilbert symbol (a,b) in
nf, that is 1 if X^2-aY^2-bZ^2 has a non-trivial solution (X,Y,Z) in nf, -1
otherwise. Otherwise compute the local symbol modulo the prime ideal pr.
Doc: if \var{pr} is omitted,
compute the global quadratic \idx{Hilbert symbol} $(a,b)$ in $\var{nf}$, that
is $1$ if $x^2 - a y^2 - b z^2$ has a non trivial solution $(x,y,z)$ in
$\var{nf}$, and $-1$ otherwise. Otherwise compute the local symbol modulo
the prime ideal \var{pr}, as output by \kbd{idealprimedec}.
Variant:
Also available is \fun{long}{nfhilbert}{GEN bnf,GEN a,GEN b} (global
quadratic Hilbert symbol).
Function: nfhnf
Class: basic
Section: number_fields
C-Name: nfhnf0
Prototype: GGD0,L,
Help: nfhnf(nf,x,{flag=0}): if x=[A,I], gives a pseudo-basis [B,J] of the module
sum A_jI_j. If flag is non-zero, return [[B,J], U], where U is the
transformation matrix such that AU = [0|B].
Doc: given a pseudo-matrix $(A,I)$, finds a
pseudo-basis $(B,J)$ in \idx{Hermite normal form} of the module it generates.
If $\fl$ is non-zero, also return the transformation matrix $U$ such that
$AU = [0|B]$.
Variant: Also available:
\fun{GEN}{nfhnf}{GEN nf, GEN x} ($\fl = 0$).
\fun{GEN}{rnfsimplifybasis}{GEN bnf, GEN x} simplifies the pseudo-basis
given by $x = (A,I)$. The ideals in the list $I$ are integral, primitive and
either trivial (equal to the full ring of integer) or non-principal.
Function: nfhnfmod
Class: basic
Section: number_fields
C-Name: nfhnfmod
Prototype: GGG
Help: nfhnfmod(nf,x,detx): if x=[A,I], and detx is a multiple of the ideal
determinant of x, gives a pseudo-basis of the module sum A_jI_j.
Doc: given a pseudo-matrix $(A,I)$
and an ideal \var{detx} which is contained in (read integral multiple of) the
determinant of $(A,I)$, finds a pseudo-basis in \idx{Hermite normal form}
of the module generated by $(A,I)$. This avoids coefficient explosion.
\var{detx} can be computed using the function \kbd{nfdetint}.
Function: nfinit
Class: basic
Section: number_fields
C-Name: nfinit0
Prototype: GD0,L,p
Help: nfinit(pol,{flag=0}): pol being a nonconstant irreducible polynomial,
gives the vector: [pol,[r1,r2],discf,index,[M,MC,T2,T,different] (see
manual),r1+r2 first roots, integral basis, matrix of power basis in terms of
integral basis, multiplication table of basis]. flag is optional and can be
set to 0: default; 1: do not compute different; 2: first use polred to find
a simpler polynomial; 3: outputs a two-element vector [nf,Mod(a,P)], where
nf is as in 2 and Mod(a,P) is a polmod equal to Mod(x,pol) and P=nf.pol.
Description:
(gen, ?0):nf:prec nfinit0($1, 0, $prec)
(gen, 1):nf:prec nfinit0($1, 1, $prec)
(gen, 2):nf:prec nfinit0($1, 2, $prec)
(gen, 3):gen:prec nfinit0($1, 3, $prec)
(gen, 4):nf:prec nfinit0($1, 4, $prec)
(gen, 5):gen:prec nfinit0($1, 5, $prec)
(gen, #small):void $"incorrect flag in nfinit"
(gen, small):gen:prec nfinit0($1, $2, $prec)
Doc: \var{pol} being a non-constant,
preferably monic, irreducible polynomial in $\Z[X]$, initializes a
\emph{number field} structure (\kbd{nf}) attached to the field $K$ defined
by \var{pol}. As such, it's a technical object passed as the first argument
to most \kbd{nf}\var{xxx} functions, but it contains some information which
may be directly useful. Access to this information via \emph{member
functions} is preferred since the specific data organization given below
may change in the future. Currently, \kbd{nf} is a row vector with 9
components:
$\var{nf}[1]$ contains the polynomial \var{pol} (\kbd{\var{nf}.pol}).
$\var{nf}[2]$ contains $[r1,r2]$ (\kbd{\var{nf}.sign}, \kbd{\var{nf}.r1},
\kbd{\var{nf}.r2}), the number of real and complex places of $K$.
$\var{nf}[3]$ contains the discriminant $d(K)$ (\kbd{\var{nf}.disc}) of $K$.
$\var{nf}[4]$ contains the index of $\var{nf}[1]$ (\kbd{\var{nf}.index}),
i.e.~$[\Z_K : \Z[\theta]]$, where $\theta$ is any root of $\var{nf}[1]$.
$\var{nf}[5]$ is a vector containing 7 matrices $M$, $G$, \var{roundG}, $T$,
$MD$, $TI$, $MDI$ useful for certain computations in the number field $K$.
\quad\item $M$ is the $(r1+r2)\times n$ matrix whose columns represent
the numerical values of the conjugates of the elements of the integral
basis.
\quad\item $G$ is an $n\times n$ matrix such that $T2 = {}^t G G$,
where $T2$ is the quadratic form $T_2(x) = \sum |\sigma(x)|^2$, $\sigma$
running over the embeddings of $K$ into $\C$.
\quad\item \var{roundG} is a rescaled copy of $G$, rounded to nearest
integers.
\quad\item $T$ is the $n\times n$ matrix whose coefficients are
$\text{Tr}(\omega_i\omega_j)$ where the $\omega_i$ are the elements of the
integral basis. Note also that $\det(T)$ is equal to the discriminant of the
field $K$. Also, when understood as an ideal, the matrix $T^{-1}$
generates the codifferent ideal.
\quad\item The columns of $MD$ (\kbd{\var{nf}.diff}) express a $\Z$-basis
of the different of $K$ on the integral basis.
\quad\item $TI$ is equal to the primitive part of $T^{-1}$, which has integral
coefficients.
\quad\item Finally, $MDI$ is a two-element representation (for faster
ideal product) of $d(K)$ times the codifferent ideal
(\kbd{\var{nf}.disc$*$\var{nf}.codiff}, which is an integral ideal). $MDI$
is only used in \tet{idealinv}.
$\var{nf}[6]$ is the vector containing the $r1+r2$ roots
(\kbd{\var{nf}.roots}) of $\var{nf}[1]$ corresponding to the $r1+r2$
embeddings of the number field into $\C$ (the first $r1$ components are real,
the next $r2$ have positive imaginary part).
$\var{nf}[7]$ is an integral basis for $\Z_K$ (\kbd{\var{nf}.zk}) expressed
on the powers of~$\theta$. Its first element is guaranteed to be $1$. This
basis is LLL-reduced with respect to $T_2$ (strictly speaking, it is a
permutation of such a basis, due to the condition that the first element be
$1$).
$\var{nf}[8]$ is the $n\times n$ integral matrix expressing the power
basis in terms of the integral basis, and finally
$\var{nf}[9]$ is the $n\times n^2$ matrix giving the multiplication table
of the integral basis.
If a non monic polynomial is input, \kbd{nfinit} will transform it into a
monic one, then reduce it (see $\fl=3$). It is allowed, though not very
useful given the existence of \tet{nfnewprec}, to input a \var{nf} or a
\var{bnf} instead of a polynomial. It is also allowed to
input a \var{rnf}, in which case an \kbd{nf} structure attached to the
absolute defining polynomial \kbd{polabs} is returned (\fl is then ignored).
\bprog
? nf = nfinit(x^3 - 12); \\ initialize number field Q[X] / (X^3 - 12)
? nf.pol \\ defining polynomial
%2 = x^3 - 12
? nf.disc \\ field discriminant
%3 = -972
? nf.index \\ index of power basis order in maximal order
%4 = 2
? nf.zk \\ integer basis, lifted to Q[X]
%5 = [1, x, 1/2*x^2]
? nf.sign \\ signature
%6 = [1, 1]
? factor(abs(nf.disc )) \\ determines ramified primes
%7 =
[2 2]
[3 5]
? idealfactor(nf, 2)
%8 =
[[2, [0, 0, -1]~, 3, 1, [0, 1, 0]~] 3] \\ @com $\goth{p}_2^3$
@eprog
\misctitle{Huge discriminants, helping nfdisc}
In case \var{pol} has a huge discriminant which is difficult to factor,
it is hard to compute from scratch the maximal order. The special input
format $[\var{pol}, B]$ is also accepted where \var{pol} is a polynomial as
above and $B$ has one of the following forms
\item an integer basis, as would be computed by \tet{nfbasis}: a vector of
polynomials with first element $1$. This is useful if the maximal order is
known in advance.
\item an argument \kbd{listP} which specifies a list of primes (see
\tet{nfbasis}). Instead of the maximal order, \kbd{nfinit} then computes an
order which is maximal at these particular primes as well as the primes
contained in the private prime table (see \tet{addprimes}). The result is
unconditionaly correct when the discriminant \kbd{nf.disc} factors
completely over this set of primes. The function \tet{nfcertify} automates
this:
\bprog
? pol = polcompositum(x^5 - 101, polcyclo(7))[1];
? nf = nfinit( [pol, 10^3] );
? nfcertify(nf)
%3 = []
@eprog\noindent A priori, \kbd{nf.zk} defines an order which is only known
to be maximal at all primes $\leq 10^3$ (no prime $\leq 10^3$ divides
\kbd{nf.index}). The certification step proves the correctness of the
computation. Had it failed, that particular \kbd{nf} structure could
not have been trusted and may have caused routines using it to fail randomly.
One particular functions that remains trustworthy in all cases is
\kbd{idealprimedec} when applied to a prime included in the above list
of primes.
\medskip
If $\fl=2$: \var{pol} is changed into another polynomial $P$ defining the same
number field, which is as simple as can easily be found using the
\tet{polredbest} algorithm, and all the subsequent computations are done
using this new polynomial. In particular, the first component of the result
is the modified polynomial.
If $\fl=3$, apply \kbd{polredbest} as in case 2, but outputs
$[\var{nf},\kbd{Mod}(a,P)]$, where $\var{nf}$ is as before and
$\kbd{Mod}(a,P)=\kbd{Mod}(x,\var{pol})$ gives the change of
variables. This is implicit when \var{pol} is not monic: first a linear change
of variables is performed, to get a monic polynomial, then \kbd{polredbest}.
Variant: Also available are
\fun{GEN}{nfinit}{GEN x, long prec} ($\fl = 0$),
\fun{GEN}{nfinitred}{GEN x, long prec} ($\fl = 2$),
\fun{GEN}{nfinitred2}{GEN x, long prec} ($\fl = 3$).
Instead of the above hardcoded numerical flags in \kbd{nfinit0}, one should
rather use
\fun{GEN}{nfinitall}{GEN x, long flag, long prec}, where \fl\ is an
or-ed combination of
\item \tet{nf_RED}: find a simpler defining polynomial,
\item \tet{nf_ORIG}: if \tet{nf_RED} set, also return the change of variable,
\item \tet{nf_ROUND2}: \emph{Deprecated}. Slow down the routine by using an
obsolete normalization algorithm (do not use this one!),
\item \tet{nf_PARTIALFACT}: \emph{Deprecated}. Lazy factorization of the
polynomial discriminant. Result is conditional unless \kbd{nfcertify}
can certify it.
Function: nfisideal
Class: basic
Section: number_fields
C-Name: isideal
Prototype: lGG
Help: nfisideal(nf,x): true(1) if x is an ideal in the number field nf,
false(0) if not.
Doc: returns 1 if $x$ is an ideal in the number field $\var{nf}$, 0 otherwise.
Function: nfisincl
Class: basic
Section: number_fields
C-Name: nfisincl
Prototype: GG
Help: nfisincl(x,y): tests whether the number field x is isomorphic to a
subfield of y (where x and y are either polynomials or number fields as
output by nfinit). Return 0 if not, and otherwise all the isomorphisms. If y
is a number field, a faster algorithm is used.
Doc: tests whether the number field $K$ defined
by the polynomial $x$ is conjugate to a subfield of the field $L$ defined
by $y$ (where $x$ and $y$ must be in $\Q[X]$). If they are not, the output
is the number 0. If they are, the output is a vector of polynomials, each
polynomial $a$ representing an embedding of $K$ into $L$, i.e.~being such
that $y\mid x\circ a$.
If $y$ is a number field (\var{nf}), a much faster algorithm is used
(factoring $x$ over $y$ using \tet{nffactor}). Before version 2.0.14, this
wasn't guaranteed to return all the embeddings, hence was triggered by a
special flag. This is no longer the case.
Function: nfisisom
Class: basic
Section: number_fields
C-Name: nfisisom
Prototype: GG
Help: nfisisom(x,y): as nfisincl but tests whether x is isomorphic to y.
Doc: as \tet{nfisincl}, but tests for isomorphism. If either $x$ or $y$ is a
number field, a much faster algorithm will be used.
Function: nfislocalpower
Class: basic
Section: number_fields
C-Name: nfislocalpower
Prototype: lGGGG
Help: nfislocalpower(nf,pr,a,n): true(1) if a is an n-th power in
the local field K_v, false(0) if not.
Doc: Let \var{nf} be a number field structure attached to $K$,
let $a \in K$ and let \var{pr} be a \var{prid} attched to the
maximal ideal $v$. Return $1$ if $a$ is an $n$-th power in the completed
local field $K_v$, and $0$ otherwise.
\bprog
? K = nfinit(y^2+1);
? P = idealprimedec(K,2)[1]; \\ the ramified prime above 2
? nfislocalpower(K,P,-1, 2) \\ -1 is a square
%3 = 1
? nfislocalpower(K,P,-1, 4) \\ ... but not a 4-th power
%4 = 0
? nfislocalpower(K,P,2, 2) \\ 2 is not a square
%5 = 0
? Q = idealprimedec(K,5)[1]; \\ a prime above 5
? nfislocalpower(K,Q, [0, 32]~, 30) \\ 32*I is locally a 30-th power
%7 = 1
@eprog
Function: nfkermodpr
Class: basic
Section: number_fields
C-Name: nfkermodpr
Prototype: GGG
Help: nfkermodpr(nf,x,pr): this function is obsolete, use nfmodpr.
Doc: this function is obsolete, use \kbd{nfmodpr}.
Kernel of the matrix $a$ in $\Z_K/\var{pr}$, where \var{pr} is in
\key{modpr} format (see \kbd{nfmodprinit}).
Obsolete: 2016-08-09
Variant: This function is normally useless in library mode. Project your
inputs to the residue field using \kbd{nfM\_to\_FqM}, then work there.
Function: nfmodpr
Class: basic
Section: number_fields
C-Name: nfmodpr
Prototype: GGG
Help: nfmodpr(nf,x,pr): map x to the residue field mod pr.
Doc: map $x$ to the residue field modulo \var{pr}, to a \typ{FFELT}.
The argument \var{pr} is either a maximal ideal in \kbd{idealprimedec}
format or, preferably, a \kbd{modpr} structure from \tet{nfmodprinit}. The
function \tet{nfmodprlift} allows to lift back to $\Z_K$.
Note that the function applies to number field elements and not to
vector / matrices / polynomials of such. Use \kbd{apply} to convert
recursive structures.
\bprog
? K = nfinit(y^3-250);
? P = idealprimedec(K, 5)[2]
? modP = nfmodprinit(K,P);
? K.zk
%4 = [1, 1/5*y, 1/25*y^2]
? apply(t->nfmodpr(K,t,modP), K.zk)
%5 = [1, y, 2*y + 1]
@eprog
Function: nfmodprinit
Class: basic
Section: number_fields
C-Name: nfmodprinit
Prototype: GG
Help: nfmodprinit(nf,pr): transform the prime ideal pr into modpr format
necessary for all operations mod pr in the number field nf.
Doc: transforms the prime ideal \var{pr} into \tet{modpr} format necessary
for all operations modulo \var{pr} in the number field \var{nf}.
The functions \tet{nfmodpr} and \tet{nfmodprlift} allow to project
to and lift from the residue field.
Function: nfmodprlift
Class: basic
Section: number_fields
C-Name: nfmodprlift
Prototype: GGG
Help: nfmodprlift(nf,x,pr): lift x from residue field mod pr to nf.
Doc: lift the \typ{FFELT} $x$ (from \tet{nfmodpr}) to the residue field
modulo \var{pr}. Vectors and matrices are also supported. For polynomials,
use \kbd{apply} and the present function.
The argument \kbd{pr} is either a maximal ideal in \kbd{idealprimedec}
format or, preferably, a \kbd{modpr} structure from \tet{nfmodprinit}.
There are no compatibility checks to try and decide whether $x$ is attached
the same residue field as defined by \kbd{pr}: the result is undefined
if not.
The function \tet{nfmodpr} allows to reduce to the residue field.
\bprog
? K = nfinit(y^3-250);
? P = idealprimedec(K, 5)[2]
? modP = nfmodprinit(K,P);
? K.zk
%4 = [1, 1/5*y, 1/25*y^2]
? apply(t->nfmodpr(K,t,modP), K.zk)
%5 = [1, y, 2*y + 1]
? nfmodprlift(K, %, modP)
%6 = [1, 1/5*y, 2/5*y + 1]
? nfeltval(K, %[3] - K.zk[3], P)
%7 = 1
@eprog
Function: nfnewprec
Class: basic
Section: number_fields
C-Name: nfnewprec
Prototype: Gp
Help: nfnewprec(nf): transform the number field data nf into new data using
the current (usually larger) precision.
Doc: transforms the number field $\var{nf}$
into the corresponding data using current (usually larger) precision. This
function works as expected if \var{nf} is in fact a \var{bnf} or a \var{bnr}
(update structure to current precision) but may be quite slow: many
generators of principal ideals have to be computed; note that in this latter
case, the \var{bnf} must contain fundamental units.
Variant: See also \fun{GEN}{bnfnewprec}{GEN bnf, long prec} and
\fun{GEN}{bnrnewprec}{GEN bnr, long prec}.
Function: nfroots
Class: basic
Section: number_fields
C-Name: nfroots
Prototype: DGG
Help: nfroots({nf},x): roots of polynomial x belonging to nf (Q if
omitted) without multiplicity.
Doc: roots of the polynomial $x$ in the
number field $\var{nf}$ given by \kbd{nfinit} without multiplicity (in $\Q$
if $\var{nf}$ is omitted). $x$ has coefficients in the number field (scalar,
polmod, polynomial, column vector). The main variable of $\var{nf}$ must be
of lower priority than that of $x$ (see \secref{se:priority}). However if the
coefficients of the number field occur explicitly (as polmods) as
coefficients of $x$, the variable of these polmods \emph{must} be the same as
the main variable of $t$ (see \kbd{nffactor}).
It is possible to input a defining polynomial for \var{nf}
instead, but this is in general less efficient since parts of an \kbd{nf}
structure will then be computed internally. This is useful in two
situations: when you do not need the \kbd{nf} elsewhere, or when you cannot
initialize an \kbd{nf} due to integer factorization difficulties when
attempting to compute the field discriminant and maximal order.
\misctitle{Caveat} \kbd{nfinit([T, listP])} allows to compute in polynomial
time a conditional \var{nf} structure, which sets \kbd{nf.zk} to an order
which is not guaranteed to be maximal at all primes. Always either use
\kbd{nfcertify} first (which may not run in polynomial time) or make sure
to input \kbd{nf.pol} instead of the conditional \var{nf}: \kbd{nfroots} is
able to recover in polynomial time in this case, instead of potentially
missing a factor.
Variant: See also \fun{GEN}{nfrootsQ}{GEN x},
corresponding to $\kbd{nf} = \kbd{NULL}$.
Function: nfrootsof1
Class: basic
Section: number_fields
C-Name: rootsof1
Prototype: G
Help: nfrootsof1(nf): number of roots of unity and primitive root of unity
in the number field nf.
Doc: Returns a two-component vector $[w,z]$ where $w$ is the number of roots of
unity in the number field \var{nf}, and $z$ is a primitive $w$-th root
of unity.
\bprog
? K = nfinit(polcyclo(11));
? nfrootsof1(K)
%2 = [22, [0, 0, 0, 0, 0, -1, 0, 0, 0, 0]~]
? z = nfbasistoalg(K, %[2]) \\ in algebraic form
%3 = Mod(-x^5, x^10 + x^9 + x^8 + x^7 + x^6 + x^5 + x^4 + x^3 + x^2 + x + 1)
? [lift(z^11), lift(z^2)] \\ proves that the order of z is 22
%4 = [-1, -x^9 - x^8 - x^7 - x^6 - x^5 - x^4 - x^3 - x^2 - x - 1]
@eprog
This function guesses the number $w$ as the gcd of the $\#k(v)^*$ for
unramified $v$ above odd primes, then computes the roots in \var{nf}
of the $w$-th cyclotomic polynomial: the algorithm is polynomial time with
respect to the field degree and the bitsize of the multiplication table in
\var{nf} (both of them polynomially bounded in terms of the size of the
discriminant). Fields of degree up to $100$ or so should require less than
one minute.
Variant: Also available is \fun{GEN}{rootsof1_kannan}{GEN nf}, that computes
all algebraic integers of $T_2$ norm equal to the field degree
(all roots of $1$, by Kronecker's theorem). This is in general a little
faster than the default when there \emph{are} roots of $1$ in the field
(say twice faster), but can be much slower (say, \emph{days} slower), since
the algorithm is a priori exponential in the field degree.
Function: nfsnf
Class: basic
Section: number_fields
C-Name: nfsnf0
Prototype: GGD0,L,
Help: nfsnf(nf,x,{flag=0}): if x=[A,I,J], outputs D=[d_1,...d_n] Smith normal
form of x. If flag is non-zero return [D,U,V], where UAV = Id.
Doc: given a torsion $\Z_K$-module $x$ attached to the square integral
invertible pseudo-matrix $(A,I,J)$, returns an ideal list
$D=[d_1,\dots,d_n]$ which is the \idx{Smith normal form} of $x$. In other
words, $x$ is isomorphic to $\Z_K/d_1\oplus\cdots\oplus\Z_K/d_n$ and $d_i$
divides $d_{i-1}$ for $i\ge2$. If $\fl$ is non-zero return $[D,U,V]$, where
$UAV$ is the identity.
See \secref{se:ZKmodules} for the definition of integral pseudo-matrix;
briefly, it is input as a 3-component row vector $[A,I,J]$ where
$I = [b_1,\dots,b_n]$ and $J = [a_1,\dots,a_n]$ are two ideal lists,
and $A$ is a square $n\times n$ matrix with columns $(A_1,\dots,A_n)$,
seen as elements in $K^n$ (with canonical basis $(e_1,\dots,e_n)$).
This data defines the $\Z_K$ module $x$ given by
$$ (b_1e_1\oplus\cdots\oplus b_ne_n) / (a_1A_1\oplus\cdots\oplus a_nA_n)
\enspace, $$
The integrality condition is $a_{i,j} \in b_i a_j^{-1}$ for all $i,j$. If it
is not satisfied, then the $d_i$ will not be integral. Note that every
finitely generated torsion module is isomorphic to a module of this form and
even with $b_i=Z_K$ for all $i$.
Variant: Also available:
\fun{GEN}{nfsnf}{GEN nf, GEN x} ($\fl = 0$).
Function: nfsolvemodpr
Class: basic
Section: number_fields
C-Name: nfsolvemodpr
Prototype: GGGG
Help: nfsolvemodpr(nf,a,b,P): this function is obsolete, use nfmodpr.
Doc: this function is obsolete, use \kbd{nfmodpr}.
Let $P$ be a prime ideal in \key{modpr} format (see \kbd{nfmodprinit}),
let $a$ be a matrix, invertible over the residue field, and let $b$ be
a column vector or matrix. This function returns a solution of $a\cdot x =
b$; the coefficients of $x$ are lifted to \var{nf} elements.
\bprog
? K = nfinit(y^2+1);
? P = idealprimedec(K, 3)[1];
? P = nfmodprinit(K, P);
? a = [y+1, y; y, 0]; b = [1, y]~
? nfsolvemodpr(K, a,b, P)
%5 = [1, 2]~
@eprog
Obsolete: 2016-08-09
Variant: This function is normally useless in library mode. Project your
inputs to the residue field using \kbd{nfM\_to\_FqM}, then work there.
Function: nfsplitting
Class: basic
Section: number_fields
C-Name: nfsplitting
Prototype: GDG
Help: nfsplitting(nf,{d}): defining polynomial over Q for the splitting field of
the number field nf; if d is given, it must be a multiple of the splitting
field degree.
Doc: defining polynomial over~$\Q$ for the splitting field of \var{nf};
if $d$ is given, it must be a multiple of the splitting field degree.
Instead of~\kbd{nf}, it is possible to input a defining (irreducible)
polynomial $T$ for~\kbd{nf}, but in general this is less efficient.
\bprog
? K = nfinit(x^3-2);
? nfsplitting(K)
%2 = x^6 + 108
? nfsplitting(x^8-2)
%3 = x^16 + 272*x^8 + 64
@eprog
\noindent
Specifying the degree of the splitting field can make the computation faster.
\bprog
? nfsplitting(x^17-123);
time = 3,607 ms.
? poldegree(%)
%2 = 272
? nfsplitting(x^17-123,272);
time = 150 ms.
? nfsplitting(x^17-123,273);
*** nfsplitting: Warning: ignoring incorrect degree bound 273
time = 3,611 ms.
@eprog
\noindent
The complexity of the algorithm is polynomial in the degree $d$ of the
splitting field and the bitsize of $T$; if $d$ is large the result will
likely be unusable, e.g. \kbd{nfinit} will not be an option:
\bprog
? nfsplitting(x^6-x-1)
[... degree 720 polynomial deleted ...]
time = 11,020 ms.
@eprog
Function: nfsubfields
Class: basic
Section: number_fields
C-Name: nfsubfields
Prototype: GD0,L,
Help: nfsubfields(pol,{d=0}): find all subfields of degree d of number field
defined by pol (all subfields if d is null or omitted). Result is a vector of
subfields, each being given by [g,h], where g is an absolute equation and h
expresses one of the roots of g in terms of the root x of the polynomial
defining nf.
Doc: finds all subfields of degree
$d$ of the number field defined by the (monic, integral) polynomial
\var{pol} (all subfields if $d$ is null or omitted). The result is a vector
of subfields, each being given by $[g,h]$, where $g$ is an absolute equation
and $h$ expresses one of the roots of $g$ in terms of the root $x$ of the
polynomial defining $\var{nf}$. This routine uses J.~Kl\"uners's algorithm
in the general case, and B.~Allombert's \tet{galoissubfields} when \var{nf}
is Galois (with weakly supersolvable Galois group).\sidx{Galois}\sidx{subfield}
Function: norm
Class: basic
Section: conversions
C-Name: gnorm
Prototype: G
Help: norm(x): norm of x.
Doc:
algebraic norm of $x$, i.e.~the product of $x$ with
its conjugate (no square roots are taken), or conjugates for polmods. For
vectors and matrices, the norm is taken componentwise and hence is not the
$L^2$-norm (see \kbd{norml2}). Note that the norm of an element of
$\R$ is its square, so as to be compatible with the complex norm.
Function: norml2
Class: basic
Section: linear_algebra
C-Name: gnorml2
Prototype: G
Help: norml2(x): square of the L2-norm of x.
Doc: square of the $L^2$-norm of $x$. More precisely,
if $x$ is a scalar, $\kbd{norml2}(x)$ is defined to be the square
of the complex modulus of $x$ (real \typ{QUAD}s are not supported).
If $x$ is a polynomial, a (row or column) vector or a matrix, \kbd{norml2($x$)} is
defined recursively as $\sum_i \kbd{norml2}(x_i)$, where $(x_i)$ run through
the components of $x$. In particular, this yields the usual $\sum |x_i|^2$
(resp.~$\sum |x_{i,j}|^2$) if $x$ is a polynomial or vector (resp.~matrix) with
complex components.
\bprog
? norml2( [ 1, 2, 3 ] ) \\ vector
%1 = 14
? norml2( [ 1, 2; 3, 4] ) \\ matrix
%2 = 30
? norml2( 2*I + x )
%3 = 5
? norml2( [ [1,2], [3,4], 5, 6 ] ) \\ recursively defined
%4 = 91
@eprog
Function: normlp
Class: basic
Section: linear_algebra
C-Name: gnormlp
Prototype: GDGp
Help: normlp(x,{p=oo}): Lp-norm of x; sup norm if p is omitted.
Doc:
$L^p$-norm of $x$; sup norm if $p$ is omitted or \kbd{+oo}. More precisely,
if $x$ is a scalar, \kbd{normlp}$(x, p)$ is defined to be \kbd{abs}$(x)$.
If $x$ is a polynomial, a (row or column) vector or a matrix:
\item if $p$ is omitted or \kbd{+oo}, then \kbd{normlp($x$)} is defined
recursively as $\max_i \kbd{normlp}(x_i))$, where $(x_i)$ run through the
components of~$x$. In particular, this yields the usual sup norm if $x$ is a
polynomial or vector with complex components.
\item otherwise, \kbd{normlp($x$, $p$)} is defined recursively as $(\sum_i
\kbd{normlp}^p(x_i,p))^{1/p}$. In particular, this yields the usual $(\sum
|x_i|^p)^{1/p}$ if $x$ is a polynomial or vector with complex components.
\bprog
? v = [1,-2,3]; normlp(v) \\ vector
%1 = 3
? normlp(v, +oo) \\ same, more explicit
%2 = 3
? M = [1,-2;-3,4]; normlp(M) \\ matrix
%3 = 4
? T = (1+I) + I*x^2; normlp(T)
%4 = 1.4142135623730950488016887242096980786
? normlp([[1,2], [3,4], 5, 6]) \\ recursively defined
%5 = 6
? normlp(v, 1)
%6 = 6
? normlp(M, 1)
%7 = 10
? normlp(T, 1)
%8 = 2.4142135623730950488016887242096980786
@eprog
Function: numbpart
Class: basic
Section: number_theoretical
C-Name: numbpart
Prototype: G
Help: numbpart(n): number of partitions of n.
Doc: gives the number of unrestricted partitions of
$n$, usually called $p(n)$ in the literature; in other words the number of
nonnegative integer solutions to $a+2b+3c+\cdots=n$. $n$ must be of type
integer and $n<10^{15}$ (with trivial values $p(n) = 0$ for $n < 0$ and
$p(0) = 1$). The algorithm uses the Hardy-Ramanujan-Rademacher formula.
To explicitly enumerate them, see \tet{partitions}.
Function: numdiv
Class: basic
Section: number_theoretical
C-Name: numdiv
Prototype: G
Help: numdiv(x): number of divisors of x.
Description:
(gen):int numdiv($1)
Doc: number of divisors of $|x|$. $x$ must be of type integer.
Function: numerator
Class: basic
Section: conversions
C-Name: numer
Prototype: G
Help: numerator(x): numerator of x.
Doc:
numerator of $x$. The meaning of this
is clear when $x$ is a rational number or function. If $x$ is an integer
or a polynomial, it is treated as a rational number or function,
respectively, and the result is $x$ itself. For polynomials, you
probably want to use
\bprog
numerator( content(x) )
@eprog\noindent
instead.
In other cases, \kbd{numerator(x)} is defined to be
\kbd{denominator(x)*x}. This is the case when $x$ is a vector or a
matrix, but also for \typ{COMPLEX} or \typ{QUAD}. In particular since a
\typ{PADIC} or \typ{INTMOD} has denominator $1$, its numerator is
itself.
\misctitle{Warning} Multivariate objects are created according to variable
priorities, with possibly surprising side effects ($x/y$ is a polynomial, but
$y/x$ is a rational function). See \secref{se:priority}.
Function: numtoperm
Class: basic
Section: conversions
C-Name: numtoperm
Prototype: LG
Help: numtoperm(n,k): permutation number k (mod n!) of n letters (n
C-integer).
Doc: generates the $k$-th permutation (as a row vector of length $n$) of the
numbers $1$ to $n$. The number $k$ is taken modulo $n!\,$, i.e.~inverse
function of \tet{permtonum}. The numbering used is the standard lexicographic
ordering, starting at $0$.
Function: omega
Class: basic
Section: number_theoretical
C-Name: omega
Prototype: lG
Help: omega(x): number of distinct prime divisors of x.
Doc: number of distinct prime divisors of $|x|$. $x$ must be of type integer.
\bprog
? factor(392)
%1 =
[2 3]
[7 2]
? omega(392)
%2 = 2; \\ without multiplicity
? bigomega(392)
%3 = 5; \\ = 3+2, with multiplicity
@eprog
Function: oo
Class: basic
Section: conversions
C-Name: mkoo
Prototype:
Help: oo=oo(): infinity.
Description:
Doc: returns an object meaning $+\infty$, for use in functions such as
\kbd{intnum}. It can be negated (\kbd{-oo} represents $-\infty$), and
compared to real numbers (\typ{INT}, \typ{FRAC}, \typ{REAL}), with the
expected meaning: $+\infty$ is greater than any real number and $-\infty$ is
smaller.
Function: padicappr
Class: basic
Section: polynomials
C-Name: padicappr
Prototype: GG
Help: padicappr(pol,a): p-adic roots of the polynomial pol congruent to a mod p.
Doc: vector of $p$-adic roots of the
polynomial $pol$ congruent to the $p$-adic number $a$ modulo $p$, and with
the same $p$-adic precision as $a$. The number $a$ can be an ordinary
$p$-adic number (type \typ{PADIC}, i.e.~an element of $\Z_p$) or can be an
integral element of a finite extension of $\Q_p$, given as a \typ{POLMOD}
at least one of whose coefficients is a \typ{PADIC}. In this case, the result
is the vector of roots belonging to the same extension of $\Q_p$ as $a$.
Variant: Also available is \fun{GEN}{Zp_appr}{GEN f, GEN a} when $a$ is a
\typ{PADIC}.
Function: padicfields
Class: basic
Section: polynomials
C-Name: padicfields0
Prototype: GGD0,L,
Help: padicfields(p, N, {flag=0}): returns polynomials generating all
the extensions of degree N of the field of p-adic rational numbers; N is
allowed to be a 2-component vector [n,d], in which case, returns the
extensions of degree n and discriminant p^d. flag is optional,
and can be 0: default, 1: return also the ramification index, the residual
degree, the valuation of the discriminant and the number of conjugate fields,
or 2: return only the number of extensions in a fixed algebraic closure.
Doc: returns a vector of polynomials generating all the extensions of degree
$N$ of the field $\Q_p$ of $p$-adic rational numbers; $N$ is
allowed to be a 2-component vector $[n,d]$, in which case we return the
extensions of degree $n$ and discriminant $p^d$.
The list is minimal in the sense that two different polynomials generate
non-isomorphic extensions; in particular, the number of polynomials is the
number of classes of non-isomorphic extensions. If $P$ is a polynomial in this
list, $\alpha$ is any root of $P$ and $K = \Q_p(\alpha)$, then $\alpha$
is the sum of a uniformizer and a (lift of a) generator of the residue field
of $K$; in particular, the powers of $\alpha$ generate the ring of $p$-adic
integers of $K$.
If $\fl = 1$, replace each polynomial $P$ by a vector $[P, e, f, d, c]$
where $e$ is the ramification index, $f$ the residual degree, $d$ the
valuation of the discriminant, and $c$ the number of conjugate fields.
If $\fl = 2$, only return the \emph{number} of extensions in a fixed
algebraic closure (Krasner's formula), which is much faster.
Variant: Also available is
\fun{GEN}{padicfields}{GEN p, long n, long d, long flag}, which computes
extensions of $\Q_p$ of degree $n$ and discriminant $p^d$.
Function: padicprec
Class: basic
Section: conversions
C-Name: gppadicprec
Prototype: GG
Help: padicprec(x,p):
return the absolute p-adic precision of object x.
Doc: returns the absolute $p$-adic precision of the object $x$; this is the
minimum precision of the components of $x$. The result is \tet{+oo} if $x$
is an exact object (as a $p$-adic):
\bprog
? padicprec((1 + O(2^5)) * x + (2 + O(2^4)), 2)
%1 = 4
? padicprec(x + 2, 2)
%2 = +oo
? padicprec(2 + x + O(x^2), 2)
%3 = +oo
@eprog\noindent The function raises an exception if it encounters
an object incompatible with $p$-adic computations:
\bprog
? padicprec(O(3), 2)
*** at top-level: padicprec(O(3),2)
*** ^-----------------
*** padicprec: inconsistent moduli in padicprec: 3 != 2
? padicprec(1.0, 2)
*** at top-level: padicprec(1.0,2)
*** ^----------------
*** padicprec: incorrect type in padicprec (t_REAL).
@eprog
Variant: Also available is the function \fun{long}{padicprec}{GEN x, GEN p},
which returns \tet{LONG_MAX} if $x = 0$ and the $p$-adic precision as a
\kbd{long} integer.
Function: parapply
Class: basic
Section: programming/parallel
C-Name: parapply
Prototype: GG
Help: parapply(f, x): parallel evaluation of f on the elements of x.
Doc: parallel evaluation of \kbd{f} on the elements of \kbd{x}.
The function \kbd{f} must not access global variables or variables
declared with local(), and must be free of side effects.
\bprog
parapply(factor,[2^256 + 1, 2^193 - 1])
@eprog
factors $2^{256} + 1$ and $2^{193} - 1$ in parallel.
\bprog
{
my(E = ellinit([1,3]), V = vector(12,i,randomprime(2^200)));
parapply(p->ellcard(E,p), V)
}
@eprog
computes the order of $E(\F_p)$ for $12$ random primes of $200$ bits.
Function: pareval
Class: basic
Section: programming/parallel
C-Name: pareval
Prototype: G
Help: pareval(x): parallel evaluation of the elements of the vector of
closures x.
Doc: parallel evaluation of the elements of \kbd{x}, where \kbd{x} is a
vector of closures. The closures must be of arity $0$, must not access
global variables or variables declared with \kbd{local} and must be
free of side effects.
Function: parfor
Class: basic
Section: programming/parallel
C-Name: parfor0
Prototype: vV=GDGJDVDI
Help: parfor(i=a,{b},expr1,{r},{expr2}):
evaluates the expression expr1 in parallel for all i between a and b
(if b is set to +oo, the loop will not stop), resulting in as many
values; if the formal variables r and expr2 are present, evaluate
sequentially expr2, in which r has been replaced by the different results
obtained for expr1 and i with the corresponding arguments.
Description:
(gen,gen,closure):void parfor($1, $2, $3, NULL, NULL)
Doc: evaluates in parallel the expression \kbd{expr1} in the formal
argument $i$ running from $a$ to $b$.
If $b$ is set to \kbd{+oo}, the loop runs indefinitely.
If $r$ and \kbd{expr2} are present, the expression \kbd{expr2} in the
formal variables $r$ and $i$ is evaluated with $r$ running through all
the different results obtained for \kbd{expr1} and $i$ takes the
corresponding argument.
The computations of \kbd{expr1} are \emph{started} in increasing order
of $i$; otherwise said, the computation for $i=c$ is started after those
for $i=1, \ldots, c-1$ have been started, but before the computation for
$i=c+1$ is started. Notice that the order of \emph{completion}, that is,
the order in which the different $r$ become available, may be different;
\kbd{expr2} is evaluated sequentially on each $r$ as it appears.
The following example computes the sum of the squares of the integers
from $1$ to $10$ by computing the squares in parallel and is equivalent
to \kbd{parsum (i=1, 10, i\^{}2)}:
\bprog
? s=0;
? parfor (i=1, 10, i^2, r, s=s+r)
? s
%3 = 385
@eprog
More precisely, apart from a potentially different order of evaluation
due to the parallelism, the line containing \kbd{parfor} is equivalent to
\bprog
? my (r); for (i=1, 10, r=i^2; s=s+r)
@eprog
The sequentiality of the evaluation of \kbd{expr2} ensures that the
variable \kbd{s} is not modified concurrently by two different additions,
although the order in which the terms are added is non-deterministic.
It is allowed for \kbd{expr2} to exit the loop using
\kbd{break}/\kbd{next}/\kbd{return}. If that happens for $i=c$,
then the evaluation of \kbd{expr1} and \kbd{expr2} is continued
for all values $i<c$, and the return value is the one obtained for
the smallest $i$ causing an interruption in \kbd{expr2} (it may be
undefined if this is a \kbd{break}/\kbd{next}).
In that case, using side-effects
in \kbd{expr2} may lead to undefined behavior, as the exact
number of values of $i$ for which it is executed is non-deterministic.
The following example computes \kbd{nextprime(1000)} in parallel:
\bprog
? parfor (i=1000, , isprime (i), r, if (r, return (i)))
%1 = 1009
@eprog
%\syn{NO}
Function: parforprime
Class: basic
Section: programming/parallel
C-Name: parforprime0
Prototype: vV=GDGJDVDI
Help: parforprime(p=a,{b},expr1,{r},{expr2}):
evaluates the expression expr1 in parallel for all primes p between a and b
(if b is set to +oo, the loop will not stop), resulting in as many
values; if the formal variables r and expr2 are present, evaluate
sequentially expr2, in which r has been replaced by the different results
obtained for expr1 and p with the corresponding arguments.
Description:
(gen,gen,closure):void parforprime($1, $2, $3, NULL, NULL)
Doc:
behaves exactly as \kbd{parfor}, but loops only over prime values $p$.
Precisely, the functions evaluates in parallel the expression \kbd{expr1}
in the formal
argument $p$ running through the primes from $a$ to $b$.
If $b$ is set to \kbd{+oo}, the loop runs indefinitely.
If $r$ and \kbd{expr2} are present, the expression \kbd{expr2} in the
formal variables $r$ and $p$ is evaluated with $r$ running through all
the different results obtained for \kbd{expr1} and $p$ takes the
corresponding argument.
It is allowed fo \kbd{expr2} to exit the loop using
\kbd{break}/\kbd{next}/\kbd{return}; see the remarks in the documentation
of \kbd{parfor} for details.
%\syn{NO}
Function: parforvec
Class: basic
Section: programming/parallel
C-Name: parforvec0
Prototype: vV=GJDVDID0,L,
Help: parforvec(X=v,expr1,{j},{expr2},{flag}): evaluates the sequence expr2
(dependent on X and j) for X as generated by forvec, in random order,
computed in parallel. Substitute for j the value of expr1 (dependent on X).
Description:
(gen,closure,,,?small):void parforvec($1, $2, $5, NULL, NULL)
Doc: evaluates the sequence \kbd{expr2} (dependent on $X$ and $j$) for $X$
as generated by \kbd{forvec}, in random order, computed in parallel. Substitute
for $j$ the value of \kbd{expr1} (dependent on $X$).
It is allowed fo \kbd{expr2} to exit the loop using
\kbd{break}/\kbd{next}/\kbd{return}, however in that case, \kbd{expr2} will
still be evaluated for all remaining value of $p$ less than the current one,
unless a subsequent \kbd{break}/\kbd{next}/\kbd{return} happens.
%\syn{NO}
Function: parselect
Class: basic
Section: programming/parallel
C-Name: parselect
Prototype: GGD0,L,
Help: parselect(f, A, {flag = 0}): (parallel select) selects elements of A
according to the selection function f which is tested in parallel. If flag
is 1, return the indices of those elements (indirect selection).
Doc: selects elements of $A$ according to the selection function $f$, done in
parallel. If \fl is $1$, return the indices of those elements (indirect
selection) The function \kbd{f} must not access global variables or
variables declared with local(), and must be free of side effects.
Function: parsum
Class: basic
Section: programming/parallel
C-Name: parsum
Prototype: V=GGJDG
Help: parsum(i=a,b,expr,{x}): x plus the sum (X goes from a to b) of
expression expr, evaluated in parallel (in random order).
Description:
(gen,gen,closure,?gen):gen parsum($1, $2, $3, $4)
Doc: sum of expression \var{expr}, initialized at $x$, the formal parameter
going from $a$ to $b$, evaluated in parallel in random order.
The expression \kbd{expr} must not access global variables or
variables declared with \kbd{local()}, and must be free of side effects.
\bprog
parsum(i=1,1000,ispseudoprime(2^prime(i)-1))
@eprog
returns the numbers of prime numbers among the first $1000$ Mersenne numbers.
%\syn{NO}
Function: partitions
Class: basic
Section: number_theoretical
C-Name: partitions
Prototype: LDGDG
Help: partitions(k,{a=k},{n=k})): vector of partitions of the integer k.
You can restrict the length of the partitions with parameter n (n=nmax or
n=[nmin,nmax]), or the range of the parts with parameter a (a=amax
or a=[amin,amax]). By default remove zeros, but one can set amin=0 to get X of
fixed length nmax (=k by default).
Doc: returns the vector of partitions of the integer $k$ as a sum of positive
integers (parts); for $k < 0$, it returns the empty set \kbd{[]}, and for $k
= 0$ the trivial partition (no parts). A partition is given by a
\typ{VECSMALL}, where parts are sorted in nondecreasing order:
\bprog
? partitions(3)
%1 = [Vecsmall([3]), Vecsmall([1, 2]), Vecsmall([1, 1, 1])]
@eprog\noindent correspond to $3$, $1+2$ and $1+1+1$. The number
of (unrestricted) partitions of $k$ is given
by \tet{numbpart}:
\bprog
? #partitions(50)
%1 = 204226
? numbpart(50)
%2 = 204226
@eprog
\noindent Optional parameters $n$ and $a$ are as follows:
\item $n=\var{nmax}$ (resp. $n=[\var{nmin},\var{nmax}]$) restricts
partitions to length less than $\var{nmax}$ (resp. length between
$\var{nmin}$ and $nmax$), where the \emph{length} is the number of nonzero
entries.
\item $a=\var{amax}$ (resp. $a=[\var{amin},\var{amax}]$) restricts the parts
to integers less than $\var{amax}$ (resp. between $\var{amin}$ and
$\var{amax}$).
\bprog
? partitions(4, 2) \\ parts bounded by 2
%1 = [Vecsmall([2, 2]), Vecsmall([1, 1, 2]), Vecsmall([1, 1, 1, 1])]
? partitions(4,, 2) \\ at most 2 parts
%2 = [Vecsmall([4]), Vecsmall([1, 3]), Vecsmall([2, 2])]
? partitions(4,[0,3], 2) \\ at most 2 parts
%3 = [Vecsmall([4]), Vecsmall([1, 3]), Vecsmall([2, 2])]
@eprog\noindent
By default, parts are positive and we remove zero entries unless
$amin\leq0$, in which case $nmin$ is ignored and $X$ is of constant length
$\var{nmax}$:
\bprog
? partitions(4, [0,3]) \\ parts between 0 and 3
%1 = [Vecsmall([0, 0, 1, 3]), Vecsmall([0, 0, 2, 2]),\
Vecsmall([0, 1, 1, 2]), Vecsmall([1, 1, 1, 1])]
@eprog
Function: parvector
Class: basic
Section: programming/parallel
C-Name: parvector
Prototype: LVJ
Help: parvector(N,i,expr): as vector(N,i,expr) but the evaluations of expr are
done in parallel.
Description:
(small,,closure):vec parvector($1, $3)
Doc: As \kbd{vector(N,i,expr)} but the evaluations of \kbd{expr} are done in
parallel. The expression \kbd{expr} must not access global variables or
variables declared with \kbd{local()}, and must be free of side effects.
\bprog
parvector(10,i,quadclassunit(2^(100+i)+1).no)
@eprog\noindent
computes the class numbers in parallel.
%\syn{NO}
Function: permtonum
Class: basic
Section: conversions
C-Name: permtonum
Prototype: G
Help: permtonum(x): ordinal (between 1 and n!) of permutation x.
Doc: given a permutation $x$ on $n$ elements, gives the number $k$ such that
$x=\kbd{numtoperm(n,k)}$, i.e.~inverse function of \tet{numtoperm}.
The numbering used is the standard lexicographic ordering, starting at $0$.
Function: plot
Class: basic
Section: graphic
C-Name: pariplot
Prototype: vV=GGEDGDGp
Help: plot(X=a,b,expr,{Ymin},{Ymax}): crude plot of expression expr, X goes
from a to b, with Y ranging from Ymin to Ymax. If Ymin (resp. Ymax) is not
given, the minimum (resp. the maximum) of the expression is used instead.
Doc: crude ASCII plot of the function represented by expression \var{expr}
from $a$ to $b$, with \var{Y} ranging from \var{Ymin} to \var{Ymax}. If
\var{Ymin} (resp. \var{Ymax}) is not given, the minimum (resp. the maximum)
of the computed values of the expression is used instead.
Function: plotbox
Class: highlevel
Section: graphic
C-Name: rectbox
Prototype: vLGG
Help: plotbox(w,x2,y2): if the cursor is at position (x1,y1), draw a box
with diagonal (x1,y1) and (x2,y2) in rectwindow w (cursor does not move).
Doc: let $(x1,y1)$ be the current position of the virtual cursor. Draw in the
rectwindow $w$ the outline of the rectangle which is such that the points
$(x1,y1)$ and $(x2,y2)$ are opposite corners. Only the part of the rectangle
which is in $w$ is drawn. The virtual cursor does \emph{not} move.
Function: plotclip
Class: highlevel
Section: graphic
C-Name: rectclip
Prototype: vL
Help: plotclip(w): clip the contents of the rectwindow to the bounding box
(except strings).
Doc: `clips' the content of rectwindow $w$, i.e remove all parts of the
drawing that would not be visible on the screen. Together with
\tet{plotcopy} this function enables you to draw on a scratchpad before
committing the part you're interested in to the final picture.
Function: plotcolor
Class: highlevel
Section: graphic
C-Name: rectcolor
Prototype: vLL
Help: plotcolor(w,c): in rectwindow w, set default color to c. Possible
values for c are given by the graphcolormap default: factory settings
are 1=black, 2=blue, 3=sienna, 4=red, 5=green, 6=grey, 7=gainsborough.
Doc: set default color to $c$ in rectwindow $w$.
This is only implemented for the X-windows, fltk and Qt graphing engines.
Possible values for $c$ are given by the \tet{graphcolormap} default,
factory setting are
1=black, 2=blue, 3=violetred, 4=red, 5=green, 6=grey, 7=gainsborough.
but this can be considerably extended.
Function: plotcopy
Class: highlevel
Section: graphic
C-Name: rectcopy_gen
Prototype: vLLGGD0,L,
Help: plotcopy(sourcew,destw,dx,dy,{flag=0}): copy the contents of
rectwindow sourcew to rectwindow destw with offset (dx,dy). If flag's bit 1
is set, dx and dy express fractions of the size of the current output
device, otherwise dx and dy are in pixels. dx and dy are relative positions
of northwest corners if other bits of flag vanish, otherwise of: 2:
southwest, 4: southeast, 6: northeast corners.
Doc: copy the contents of rectwindow \var{sourcew} to rectwindow \var{destw}
with offset (dx,dy). If flag's bit 1 is set, dx and dy express fractions of
the size of the current output device, otherwise dx and dy are in pixels. dx
and dy are relative positions of northwest corners if other bits of flag
vanish, otherwise of: 2: southwest, 4: southeast, 6: northeast corners
Function: plotcursor
Class: highlevel
Section: graphic
C-Name: rectcursor
Prototype: L
Help: plotcursor(w): current position of cursor in rectwindow w.
Doc: give as a 2-component vector the current
(scaled) position of the virtual cursor corresponding to the rectwindow $w$.
Function: plotdraw
Class: highlevel
Section: graphic
C-Name: rectdraw_flag
Prototype: vGD0,L,
Help: plotdraw(list, {flag=0}): draw vector of rectwindows list at indicated
x,y positions; list is a vector w1,x1,y1,w2,x2,y2,etc. If flag!=0, x1, y1
etc. express fractions of the size of the current output device.
Doc: physically draw the rectwindows given in $list$
which must be a vector whose number of components is divisible by 3. If
$list=[w1,x1,y1,w2,x2,y2,\dots]$, the windows $w1$, $w2$, etc.~are
physically placed with their upper left corner at physical position
$(x1,y1)$, $(x2,y2)$,\dots\ respectively, and are then drawn together.
Overlapping regions will thus be drawn twice, and the windows are considered
transparent. Then display the whole drawing in a special window on your
screen. If $\fl \neq 0$, x1, y1 etc. express fractions of the size of the
current output device
Function: ploth
Class: highlevel
Section: graphic
C-Name: ploth
Prototype: V=GGEpD0,M,D0,L,\nParametric|1; Recursive|2; no_Rescale|4; no_X_axis|8; no_Y_axis|16; no_Frame|32; no_Lines|64; Points_too|128; Splines|256; no_X_ticks|512; no_Y_ticks|1024; Same_ticks|2048; Complex|4096
Help: ploth(X=a,b,expr,{flags=0},{n=0}): plot of expression expr, X goes
from a to b in high resolution. Both flags and n are optional. Binary digits
of flags mean: 1=Parametric, 2=Recursive, 4=no_Rescale, 8=no_X_axis,
16=no_Y_axis, 32=no_Frame, 64=no_Lines (do not join points), 128=Points_too
(plot both lines and points), 256=Splines (use cubic splines),
512=no_X_ticks, 1024= no_Y_ticks, 2048=Same_ticks (plot all ticks with the
same length), 4096=Complex (the two coordinates of each point are encoded
as a complex number). n specifies number of reference points on the graph
(0=use default value). Returns a vector for the bounding box.
Doc: high precision plot of the function $y=f(x)$ represented by the expression
\var{expr}, $x$ going from $a$ to $b$. This opens a specific window (which is
killed whenever you click on it), and returns a four-component vector giving
the coordinates of the bounding box in the form
$[\var{xmin},\var{xmax},\var{ymin},\var{ymax}]$.
\misctitle{Important note} \kbd{ploth} may evaluate \kbd{expr} thousands of
times; given the relatively low resolution of plotting devices, few
significant digits of the result will be meaningful. Hence you should keep
the current precision to a minimum (e.g.~9) before calling this function.
$n$ specifies the number of reference point on the graph, where a value of 0
means we use the hardwired default values (1000 for general plot, 1500 for
parametric plot, and 8 for recursive plot).
If no $\fl$ is given, \var{expr} is either a scalar expression $f(X)$, in which
case the plane curve $y=f(X)$ will be drawn, or a vector
$[f_1(X),\dots,f_k(X)]$, and then all the curves $y=f_i(X)$ will be drawn in
the same window.
\noindent The binary digits of $\fl$ mean:
\item $1 = \kbd{Parametric}$: \tev{parametric plot}. Here \var{expr} must
be a vector with an even number of components. Successive pairs are then
understood as the parametric coordinates of a plane curve. Each of these are
then drawn.
For instance:
\bprog
ploth(X=0,2*Pi,[sin(X),cos(X)], "Parametric")
ploth(X=0,2*Pi,[sin(X),cos(X)])
ploth(X=0,2*Pi,[X,X,sin(X),cos(X)], "Parametric")
@eprog\noindent draw successively a circle, two entwined sinusoidal curves
and a circle cut by the line $y=x$.
\item $2 = \kbd{Recursive}$: \tev{recursive plot}. If this flag is set,
only \emph{one} curve can be drawn at a time, i.e.~\var{expr} must be either a
two-component vector (for a single parametric curve, and the parametric flag
\emph{has} to be set), or a scalar function. The idea is to choose pairs of
successive reference points, and if their middle point is not too far away
from the segment joining them, draw this as a local approximation to the
curve. Otherwise, add the middle point to the reference points. This is
fast, and usually more precise than usual plot. Compare the results of
\bprog
ploth(X=-1,1, sin(1/X), "Recursive")
ploth(X=-1,1, sin(1/X))
@eprog\noindent
for instance. But beware that if you are extremely unlucky, or choose too few
reference points, you may draw some nice polygon bearing little resemblance
to the original curve. For instance you should \emph{never} plot recursively
an odd function in a symmetric interval around 0. Try
\bprog
ploth(x = -20, 20, sin(x), "Recursive")
@eprog\noindent
to see why. Hence, it's usually a good idea to try and plot the same curve
with slightly different parameters.
The other values toggle various display options:
\item $4 = \kbd{no\_Rescale}$: do not rescale plot according to the
computed extrema. This is used in conjunction with \tet{plotscale} when
graphing multiple functions on a rectwindow (as a \tet{plotrecth} call):
\bprog
s = plothsizes();
plotinit(0, s[2]-1, s[2]-1);
plotscale(0, -1,1, -1,1);
plotrecth(0, t=0,2*Pi, [cos(t),sin(t)], "Parametric|no_Rescale")
plotdraw([0, -1,1]);
@eprog\noindent
This way we get a proper circle instead of the distorted ellipse produced by
\bprog
ploth(t=0,2*Pi, [cos(t),sin(t)], "Parametric")
@eprog
\item $8 = \kbd{no\_X\_axis}$: do not print the $x$-axis.
\item $16 = \kbd{no\_Y\_axis}$: do not print the $y$-axis.
\item $32 = \kbd{no\_Frame}$: do not print frame.
\item $64 = \kbd{no\_Lines}$: only plot reference points, do not join them.
\item $128 = \kbd{Points\_too}$: plot both lines and points.
\item $256 = \kbd{Splines}$: use splines to interpolate the points.
\item $512 = \kbd{no\_X\_ticks}$: plot no $x$-ticks.
\item $1024 = \kbd{no\_Y\_ticks}$: plot no $y$-ticks.
\item $2048 = \kbd{Same\_ticks}$: plot all ticks with the same length.
\item $4096 = \kbd{Complex}$: is a parametric plot but where each member of
\kbd{expr} is considered a complex number encoding the two coordinates of a
point. For instance:
\bprog
ploth(X=0,2*Pi,exp(I*X), "Complex")
ploth(X=0,2*Pi,[(1+I)*X,exp(I*X)], "Complex")
@eprog\noindent will draw respectively a circle and a circle cut by the line
$y=x$.
Function: plothraw
Class: highlevel
Section: graphic
C-Name: plothraw
Prototype: GGD0,L,
Help: plothraw(listx,listy,{flag=0}): plot in high resolution points whose x
(resp. y) coordinates are in listx (resp. listy). If flag is 1, join points,
other non-0 flags should be combinations of bits 8,16,32,64,128,256 meaning
the same as for ploth().
Doc: given \var{listx} and \var{listy} two vectors of equal length, plots (in
high precision) the points whose $(x,y)$-coordinates are given in
\var{listx} and \var{listy}. Automatic positioning and scaling is done, but
with the same scaling factor on $x$ and $y$. If $\fl$ is 1, join points,
other non-0 flags toggle display options and should be combinations of bits
$2^k$, $k \geq 3$ as in \kbd{ploth}.
Function: plothsizes
Class: highlevel
Section: graphic
C-Name: plothsizes_flag
Prototype: D0,L,
Help: plothsizes({flag=0}): returns array of 6 elements: terminal width and
height, sizes for ticks in horizontal and vertical directions, width and
height of characters. If flag=0, sizes of ticks and characters are in
pixels, otherwise are fractions of the screen size.
Doc: return data corresponding to the output window
in the form of a 6-component vector: window width and height, sizes for ticks
in horizontal and vertical directions (this is intended for the \kbd{gnuplot}
interface and is currently not significant), width and height of characters.
If $\fl = 0$, sizes of ticks and characters are in
pixels, otherwise are fractions of the screen size
Function: plotinit
Class: highlevel
Section: graphic
C-Name: initrect_gen
Prototype: vLDGDGD0,L,
Help: plotinit(w,{x},{y},{flag=0}): initialize rectwindow w to size x,y.
If flag!=0, x and y express fractions of the size of the current output
device. Omitting x or y means use the full size of the device.
Doc: initialize the rectwindow $w$,
destroying any rect objects you may have already drawn in $w$. The virtual
cursor is set to $(0,0)$. The rectwindow size is set to width $x$ and height
$y$; omitting either $x$ or $y$ means we use the full size of the device
in that direction.
If $\fl=0$, $x$ and $y$ represent pixel units. Otherwise, $x$ and $y$
are understood as fractions of the size of the current output device (hence
must be between $0$ and $1$) and internally converted to pixels.
The plotting device imposes an upper bound for $x$ and $y$, for instance the
number of pixels for screen output. These bounds are available through the
\tet{plothsizes} function. The following sequence initializes in a portable
way (i.e independent of the output device) a window of maximal size, accessed
through coordinates in the $[0,1000] \times [0,1000]$ range:
\bprog
s = plothsizes();
plotinit(0, s[1]-1, s[2]-1);
plotscale(0, 0,1000, 0,1000);
@eprog
Function: plotkill
Class: highlevel
Section: graphic
C-Name: killrect
Prototype: vL
Help: plotkill(w): erase the rectwindow w.
Doc: erase rectwindow $w$ and free the corresponding memory. Note that if you
want to use the rectwindow $w$ again, you have to use \kbd{plotinit} first
to specify the new size. So it's better in this case to use \kbd{plotinit}
directly as this throws away any previous work in the given rectwindow.
Function: plotlines
Class: highlevel
Section: graphic
C-Name: rectlines
Prototype: vLGGD0,L,
Help: plotlines(w,X,Y,{flag=0}): draws an open polygon in rectwindow
w where X and Y contain the x (resp. y) coordinates of the vertices.
If X and Y are both single values (i.e not vectors), draw the
corresponding line (and move cursor). If (optional) flag is non-zero, close
the polygon.
Doc: draw on the rectwindow $w$
the polygon such that the (x,y)-coordinates of the vertices are in the
vectors of equal length $X$ and $Y$. For simplicity, the whole
polygon is drawn, not only the part of the polygon which is inside the
rectwindow. If $\fl$ is non-zero, close the polygon. In any case, the
virtual cursor does not move.
$X$ and $Y$ are allowed to be scalars (in this case, both have to).
There, a single segment will be drawn, between the virtual cursor current
position and the point $(X,Y)$. And only the part thereof which
actually lies within the boundary of $w$. Then \emph{move} the virtual cursor
to $(X,Y)$, even if it is outside the window. If you want to draw a
line from $(x1,y1)$ to $(x2,y2)$ where $(x1,y1)$ is not necessarily the
position of the virtual cursor, use \kbd{plotmove(w,x1,y1)} before using this
function.
Function: plotlinetype
Class: highlevel
Section: graphic
C-Name: rectlinetype
Prototype: vLL
Help: plotlinetype(w,type): this function is obsolete; no graphing engine
implement this functionality.
Doc: This function is obsolete and currently a no-op.
Change the type of lines subsequently plotted in rectwindow $w$.
\var{type} $-2$ corresponds to frames, $-1$ to axes, larger values may
correspond to something else. $w = -1$ changes highlevel plotting.
Obsolete: 2007-05-11
Function: plotmove
Class: highlevel
Section: graphic
C-Name: rectmove
Prototype: vLGG
Help: plotmove(w,x,y): move cursor to position x,y in rectwindow w.
Doc: move the virtual cursor of the rectwindow $w$ to position $(x,y)$.
Function: plotpoints
Class: highlevel
Section: graphic
C-Name: rectpoints
Prototype: vLGG
Help: plotpoints(w,X,Y): draws in rectwindow w the points whose x
(resp y) coordinates are in X (resp Y). If X and Y are both
single values (i.e not vectors), draw the corresponding point (and move
cursor).
Doc: draw on the rectwindow $w$ the
points whose $(x,y)$-coordinates are in the vectors of equal length $X$ and
$Y$ and which are inside $w$. The virtual cursor does \emph{not} move. This
is basically the same function as \kbd{plothraw}, but either with no scaling
factor or with a scale chosen using the function \kbd{plotscale}.
As was the case with the \kbd{plotlines} function, $X$ and $Y$ are allowed to
be (simultaneously) scalar. In this case, draw the single point $(X,Y)$ on
the rectwindow $w$ (if it is actually inside $w$), and in any case
\emph{move} the virtual cursor to position $(x,y)$.
Function: plotpointsize
Class: highlevel
Section: graphic
C-Name: rectpointsize
Prototype: vLG
Help: plotpointsize(w,size): change the "size" of following points in
rectwindow w. w=-1 changes global value.
Doc: This function is obsolete. It is currently a no-op.
Changes the ``size'' of following points in rectwindow $w$. If $w = -1$,
change it in all rectwindows.
Obsolete: 2007-05-11
Function: plotpointtype
Class: highlevel
Section: graphic
C-Name: rectpointtype
Prototype: vLL
Help: plotpointtype(w,type): this function is obsolete; no graphing engine
implement this functionality.
Doc: This function is obsolete and currently a no-op.
change the type of points subsequently plotted in rectwindow $w$.
$\var{type} = -1$ corresponds to a dot, larger values may correspond to
something else. $w = -1$ changes highlevel plotting.
Obsolete: 2007-05-11
Function: plotrbox
Class: highlevel
Section: graphic
C-Name: rectrbox
Prototype: vLGG
Help: plotrbox(w,dx,dy): if the cursor is at (x1,y1), draw a box with
diagonal (x1,y1)-(x1+dx,y1+dy) in rectwindow w (cursor does not move).
Doc: draw in the rectwindow $w$ the outline of the rectangle which is such
that the points $(x1,y1)$ and $(x1+dx,y1+dy)$ are opposite corners, where
$(x1,y1)$ is the current position of the cursor. Only the part of the
rectangle which is in $w$ is drawn. The virtual cursor does \emph{not} move.
Function: plotrecth
Class: highlevel
Section: graphic
C-Name: rectploth
Prototype: LV=GGEpD0,M,D0,L,\nParametric|1; Recursive|2; no_Rescale|4; no_X_axis|8; no_Y_axis|16; no_Frame|32; no_Lines|64; Points_too|128; Splines|256; no_X_ticks|512; no_Y_ticks|1024; Same_ticks|2048; Complex|4096
Help: plotrecth(w,X=a,b,expr,{flag=0},{n=0}):
writes to rectwindow w the curve output of
ploth(w,X=a,b,expr,flag,n). Returns a vector for the bounding box.
Doc: writes to rectwindow $w$ the curve output of
\kbd{ploth}$(w,X=a,b,\var{expr},\fl,n)$. Returns a vector for the bounding box.
Function: plotrecthraw
Class: highlevel
Section: graphic
C-Name: rectplothraw
Prototype: LGD0,L,
Help: plotrecthraw(w,data,{flags=0}): plot graph(s) for data in rectwindow
w, where data is a vector of vectors. If plot is parametric, length of data
should be even, and pairs of entries give curves to plot. If not, first
entry gives x-coordinate, and the other ones y-coordinates. Admits the same
optional flags as plotrecth, save that recursive plot is meaningless.
Doc: plot graph(s) for
\var{data} in rectwindow $w$. $\fl$ has the same significance here as in
\kbd{ploth}, though recursive plot is no more significant.
\var{data} is a vector of vectors, each corresponding to a list a coordinates.
If parametric plot is set, there must be an even number of vectors, each
successive pair corresponding to a curve. Otherwise, the first one contains
the $x$ coordinates, and the other ones contain the $y$-coordinates
of curves to plot.
Function: plotrline
Class: highlevel
Section: graphic
C-Name: rectrline
Prototype: vLGG
Help: plotrline(w,dx,dy): if the cursor is at (x1,y1), draw a line from
(x1,y1) to (x1+dx,y1+dy) (and move the cursor) in the rectwindow w.
Doc: draw in the rectwindow $w$ the part of the segment
$(x1,y1)-(x1+dx,y1+dy)$ which is inside $w$, where $(x1,y1)$ is the current
position of the virtual cursor, and move the virtual cursor to
$(x1+dx,y1+dy)$ (even if it is outside the window).
Function: plotrmove
Class: highlevel
Section: graphic
C-Name: rectrmove
Prototype: vLGG
Help: plotrmove(w,dx,dy): move cursor to position (dx,dy) relative to the
present position in the rectwindow w.
Doc: move the virtual cursor of the rectwindow $w$ to position
$(x1+dx,y1+dy)$, where $(x1,y1)$ is the initial position of the cursor
(i.e.~to position $(dx,dy)$ relative to the initial cursor).
Function: plotrpoint
Class: highlevel
Section: graphic
C-Name: rectrpoint
Prototype: vLGG
Help: plotrpoint(w,dx,dy): draw a point (and move cursor) at position dx,dy
relative to present position of the cursor in rectwindow w.
Doc: draw the point $(x1+dx,y1+dy)$ on the rectwindow $w$ (if it is inside
$w$), where $(x1,y1)$ is the current position of the cursor, and in any case
move the virtual cursor to position $(x1+dx,y1+dy)$.
Function: plotscale
Class: highlevel
Section: graphic
C-Name: rectscale
Prototype: vLGGGG
Help: plotscale(w,x1,x2,y1,y2): scale the coordinates in rectwindow w so
that x goes from x1 to x2 and y from y1 to y2 (y2<y1 is allowed).
Doc: scale the local coordinates of the rectwindow $w$ so that $x$ goes from
$x1$ to $x2$ and $y$ goes from $y1$ to $y2$ ($x2<x1$ and $y2<y1$ being
allowed). Initially, after the initialization of the rectwindow $w$ using
the function \kbd{plotinit}, the default scaling is the graphic pixel count,
and in particular the $y$ axis is oriented downwards since the origin is at
the upper left. The function \kbd{plotscale} allows to change all these
defaults and should be used whenever functions are graphed.
Function: plotstring
Class: highlevel
Section: graphic
C-Name: rectstring3
Prototype: vLsD0,L,
Help: plotstring(w,x,{flags=0}): draw in rectwindow w the string
corresponding to x. Bits 1 and 2 of flag regulate horizontal alignment: left
if 0, right if 2, center if 1. Bits 4 and 8 regulate vertical alignment:
bottom if 0, top if 8, v-center if 4. Can insert additional gap between
point and string: horizontal if bit 16 is set, vertical if bit 32 is set.
Doc: draw on the rectwindow $w$ the String $x$ (see \secref{se:strings}), at
the current position of the cursor.
\fl\ is used for justification: bits 1 and 2 regulate horizontal alignment:
left if 0, right if 2, center if 1. Bits 4 and 8 regulate vertical
alignment: bottom if 0, top if 8, v-center if 4. Can insert additional small
gap between point and string: horizontal if bit 16 is set, vertical if bit
32 is set (see the tutorial for an example).
Function: polchebyshev
Class: basic
Section: polynomials
C-Name: polchebyshev_eval
Prototype: LD1,L,DG
Help: polchebyshev(n,{flag=1},{a='x}): Chebychev polynomial of the first (flag
= 1) or second (flag = 2) kind, of degree n, evaluated at a.
Description:
(small,?1,?var):gen polchebyshev1($1,$3)
(small,2,?var):gen polchebyshev2($1,$3)
(small,small,?var):gen polchebyshev($1,$2,$3)
Doc: returns the $n^{\text{th}}$
\idx{Chebyshev} polynomial of the first kind $T_n$ ($\fl=1$) or the second
kind $U_n$ ($\fl=2$), evaluated at $a$ (\kbd{'x} by default). Both series of
polynomials satisfy the 3-term relation
$$ P_{n+1} = 2xP_n - P_{n-1}, $$
and are determined by the initial conditions $U_0 = T_0 = 1$, $T_1 = x$,
$U_1 = 2x$. In fact $T_n' = n U_{n-1}$ and, for all complex numbers $z$, we
have $T_n(\cos z) = \cos (nz)$ and $U_{n-1}(\cos z) = \sin(nz)/\sin z$.
If $n \geq 0$, then these polynomials have degree $n$. For $n < 0$,
$T_n$ is equal to $T_{-n}$ and $U_n$ is equal to $-U_{-2-n}$.
In particular, $U_{-1} = 0$.
Variant: Also available are
\fun{GEN}{polchebyshev}{long n, long flag, long v},
\fun{GEN}{polchebyshev1}{long n, long v} and
\fun{GEN}{polchebyshev2}{long n, long v} for $T_n$ and $U_n$ respectively.
Function: polclass
Class: basic
Section: polynomials
C-Name: polclass
Prototype: GD0,L,Dn
Help: polclass(D, {inv = 0}, {x = 'x}): return a polynomial generating the
Hilbert class field of Q(sqrt(D)) for the discriminant D<0.
Doc:
Return a polynomial in $\Z[x]$ generating the Hilbert class field for the
imaginary quadratic discriminant $D$. If $inv$ is 0 (the default),
use the modular $j$-function and return the classical Hilbert polynomial,
otherwise use a class invariant. The following invariants correspond to
the different values of $inv$, where $f$ denotes Weber's function
\kbd{weber}, and $w_{p,q}$ the double eta quotient given by
$w_{p,q} = \dfrac{ \eta(x/p)\*\eta(x/q) }{ \eta(x)\*\eta(x/{pq}) }$
The invariants $w_{p,q}$ are not allowed unless they satisfy the following
technical conditions ensuring they do generate the Hilbert class
field and not a strict subfield:
\item if $p\neq q$, we need them both non-inert, prime to the conductor of
$\Z[\sqrt{D}]$. Let $P, Q$ be prime ideals above $p$ and $q$; if both are
unramified, we further require that $P^{\pm 1} Q^{\pm 1}$ be all distinct in
the class group of $\Z[\sqrt{D}]$; if both are ramified, we require that $PQ
\neq 1$ in the class group.
\item if $p = q$, we want it split and prime to the conductor and
the prime ideal above it must have order $\neq 1, 2, 4$ in the class group.
\noindent Invariants are allowed under the additional conditions on $D$
listed below.
\item 0 : $j$
\item 1 : $f$, $D = 1 \mod 8$ and $D = 1,2 \mod 3$;
\item 2 : $f^2$, $D = 1 \mod 8$ and $D = 1,2 \mod 3$;
\item 3 : $f^3$, $D = 1 \mod 8$;
\item 4 : $f^4$, $D = 1 \mod 8$ and $D = 1,2 \mod 3$;
\item 5 : $\gamma_2= j^{1/3}$, $D = 1,2 \mod 3$;
\item 6 : $w_{2,3}$, $D = 1 \mod 8$ and $D = 1,2 \mod 3$;
\item 8 : $f^8$, $D = 1 \mod 8$ and $D = 1,2 \mod 3$;
\item 9 : $w_{3,3}$, $D = 1 \mod 2$ and $D = 1,2 \mod 3$;
\item 10: $w_{2,5}$, $D \neq 60 \mod 80$ and $D = 1,2 \mod 3$;
\item 14: $w_{2,7}$, $D = 1 \mod 8$;
\item 15: $w_{3,5}$, $D = 1,2 \mod 3$;
\item 21: $w_{3,7}$, $D = 1 \mod 2$ and $21$ does not divide $D$
\item 23: $w_{2,3}^2$, $D = 1,2 \mod 3$;
\item 24: $w_{2,5}^2$, $D = 1,2 \mod 3$;
\item 26: $w_{2,13}$, $D \neq 156 \mod 208$;
\item 27: $w_{2,7}^2$, $D\neq 28 \mod 112$;
\item 28: $w_{3,3}^2$, $D = 1,2 \mod 3$;
\item 35: $w_{5,7}$, $D = 1,2 \mod 3$;
\item 39: $w_{3,13}$, $D = 1 \mod 2$ and $D = 1,2 \mod 3$;
The algorithm for computing the polynomial does not use the floating point
approach, which would evaluate a precise modular function in a precise
complex argument. Instead, it relies on a faster Chinese remainder based
approach modulo small primes, in which the class invariant is only defined
algebraically by the modular polynomial relating the modular function to $j$.
So in fact, any of the several roots of the modular polynomial may actually
be the class invariant, and more precise assertions cannot be made.
For instance, while \kbd{polclass(D)} returns the minimal polynomial of
$j(\tau)$ with $\tau$ (any) quadratic integer for the discriminant $D$,
the polynomial returned by \kbd{polclass(D, 5)} can be the minimal polynomial
of any of $\gamma_2 (\tau)$, $\zeta_3 \gamma_2 (\tau)$ or
$\zeta_3^2 \gamma_2 (\tau)$, the three roots of the modular polynomial
$j = \gamma_2^3$, in which $j$ has been specialised to $j (\tau)$.
The modular polynomial is given by
$j = {(f^{24}-16)^3 \over f^{24}}$ for Weber's function $f$.
For the double eta quotients of level $N = p q$, all functions are covered
such that the modular curve $X_0^+ (N)$, the function field of which is
generated by the functions invariant under $\Gamma^0 (N)$ and the
Fricke--Atkin--Lehner involution, is of genus $0$ with function field
generated by (a power of) the double eta quotient $w$.
This ensures that the full Hilbert class field (and not a proper subfield)
is generated by class invariants from these double eta quotients.
Then the modular polynomial is of degree $2$ in $j$, and
of degree $\psi (N) = (p+1)(q+1)$ in $w$.
\bprog
? polclass(-163)
%1 = x + 262537412640768000
? polclass(-51, , 'z)
%2 = z^2 + 5541101568*z + 6262062317568
? polclass(-151,1)
x^7 - x^6 + x^5 + 3*x^3 - x^2 + 3*x + 1
@eprog
Function: polcoeff
Class: basic
Section: polynomials
C-Name: polcoeff0
Prototype: GLDn
Help: polcoeff(x,n,{v}): coefficient of degree n of x, or the n-th component
for vectors or matrices (for which it is simpler to use x[]). With respect
to the main variable if v is omitted, with respect to the variable v
otherwise.
Description:
(pol, 0):gen:copy constant_coeff($1)
(pol, 0,):gen:copy constant_coeff($1)
(pol, small):gen:copy RgX_coeff($1, $2)
(pol, small,):gen:copy RgX_coeff($1, $2)
(gen, small, ?var):gen polcoeff0($1, $2, $3)
Doc: coefficient of degree $n$ of the polynomial $x$, with respect to the
main variable if $v$ is omitted, with respect to $v$ otherwise. If $n$
is greater than the degree, the result is zero.
Naturally applies to scalars (polynomial of degree $0$), as well as to
rational functions whose denominator is a monomial.
It also applies to power series: if $n$ is less than the valuation, the result
is zero. If it is greater than the largest significant degree, then an error
message is issued.
For greater flexibility, $x$ can be a vector or matrix type and the
function then returns \kbd{component(x,n)}.
Function: polcompositum
Class: basic
Section: number_fields
C-Name: polcompositum0
Prototype: GGD0,L,
Help: polcompositum(P,Q,{flag=0}): vector of all possible compositums
of the number fields defined by the polynomials P and Q; flag is
optional, whose binary digits mean 1: output for each compositum, not only
the compositum polynomial pol, but a vector [R,a,b,k] where a (resp. b) is a
root of P (resp. Q) expressed as a polynomial modulo R, and a small integer k
such that al2+k*al1 is the chosen root of R; 2: assume that the number
fields defined by P and Q are linearly disjoint.
Doc: \sidx{compositum} $P$ and $Q$
being squarefree polynomials in $\Z[X]$ in the same variable, outputs
the simple factors of the \'etale $\Q$-algebra $A = \Q(X, Y) / (P(X), Q(Y))$.
The factors are given by a list of polynomials $R$ in $\Z[X]$, attached to
the number field $\Q(X)/ (R)$, and sorted by increasing degree (with respect
to lexicographic ordering for factors of equal degrees). Returns an error if
one of the polynomials is not squarefree.
Note that it is more efficient to reduce to the case where $P$ and $Q$ are
irreducible first. The routine will not perform this for you, since it may be
expensive, and the inputs are irreducible in most applications anyway. In
this case, there will be a single factor $R$ if and only if the number
fields defined by $P$ and $Q$ are linearly disjoint (their intersection is
$\Q$).
Assuming $P$ is irreducible (of smaller degree than $Q$ for efficiency), it
is in general much faster to proceed as follows
\bprog
nf = nfinit(P); L = nffactor(nf, Q)[,1];
vector(#L, i, rnfequation(nf, L[i]))
@eprog\noindent
to obtain the same result. If you are only interested in the degrees of the
simple factors, the \kbd{rnfequation} instruction can be replaced by a
trivial \kbd{poldegree(P) * poldegree(L[i])}.
The binary digits of $\fl$ mean
1: outputs a vector of 4-component vectors $[R,a,b,k]$, where $R$
ranges through the list of all possible compositums as above, and $a$
(resp. $b$) expresses the root of $P$ (resp. $Q$) as an element of
$\Q(X)/(R)$. Finally, $k$ is a small integer such that $b + ka = X$ modulo
$R$.
2: assume that $P$ and $Q$ define number fields which are linearly disjoint:
both polynomials are irreducible and the corresponding number fields
have no common subfield besides $\Q$. This allows to save a costly
factorization over $\Q$. In this case return the single simple factor
instead of a vector with one element.
A compositum is often defined by a complicated polynomial, which it is
advisable to reduce before further work. Here is an example involving
the field $\Q(\zeta_5, 5^{1/5})$:
\bprog
? L = polcompositum(x^5 - 5, polcyclo(5), 1); \\@com list of $[R,a,b,k]$
? [R, a] = L[1]; \\@com pick the single factor, extract $R,a$ (ignore $b,k$)
? R \\@com defines the compositum
%3 = x^20 + 5*x^19 + 15*x^18 + 35*x^17 + 70*x^16 + 141*x^15 + 260*x^14\
+ 355*x^13 + 95*x^12 - 1460*x^11 - 3279*x^10 - 3660*x^9 - 2005*x^8 \
+ 705*x^7 + 9210*x^6 + 13506*x^5 + 7145*x^4 - 2740*x^3 + 1040*x^2 \
- 320*x + 256
? a^5 - 5 \\@com a fifth root of $5$
%4 = 0
? [T, X] = polredbest(R, 1);
? T \\@com simpler defining polynomial for $\Q[x]/(R)$
%6 = x^20 + 25*x^10 + 5
? X \\ @com root of $R$ in $\Q[y]/(T(y))$
%7 = Mod(-1/11*x^15 - 1/11*x^14 + 1/22*x^10 - 47/22*x^5 - 29/11*x^4 + 7/22,\
x^20 + 25*x^10 + 5)
? a = subst(a.pol, 'x, X) \\@com \kbd{a} in the new coordinates
%8 = Mod(1/11*x^14 + 29/11*x^4, x^20 + 25*x^10 + 5)
? a^5 - 5
%9 = 0
@eprog\noindent In the above example, $x^5-5$ and the $5$-th cyclotomic
polynomial are irreducible over $\Q$; they have coprime degrees so
define linearly disjoint extensions and we could have started by
\bprog
? [R,a] = polcompositum(x^5 - 5, polcyclo(5), 3); \\@com $[R,a,b,k]$
@eprog
Variant: Also available are
\fun{GEN}{compositum}{GEN P, GEN Q} ($\fl = 0$) and
\fun{GEN}{compositum2}{GEN P, GEN Q} ($\fl = 1$).
Function: polcyclo
Class: basic
Section: polynomials
C-Name: polcyclo_eval
Prototype: LDG
Help: polcyclo(n,{a = 'x}): n-th cyclotomic polynomial evaluated at a.
Description:
(small,?var):gen polcyclo($1,$2)
(small,gen):gen polcyclo_eval($1,$2)
Doc: $n$-th cyclotomic polynomial, evaluated at $a$ (\kbd{'x} by default). The
integer $n$ must be positive.
Algorithm used: reduce to the case where $n$ is squarefree; to compute the
cyclotomic polynomial, use $\Phi_{np}(x)=\Phi_n(x^p)/\Phi(x)$; to compute
it evaluated, use $\Phi_n(x) = \prod_{d\mid n} (x^d-1)^{\mu(n/d)}$. In the
evaluated case, the algorithm assumes that $a^d - 1$ is either $0$ or
invertible, for all $d\mid n$. If this is not the case (the base ring has
zero divisors), use \kbd{subst(polcyclo(n),x,a)}.
Variant: The variant \fun{GEN}{polcyclo}{long n, long v} returns the $n$-th
cyclotomic polynomial in variable $v$.
Function: polcyclofactors
Class: basic
Section: polynomials
C-Name: polcyclofactors
Prototype: G
Help: polcyclofactors(f): returns a vector of polynomials, whose product is
the product of distinct cyclotomic polynomials dividing f.
Doc: returns a vector of polynomials, whose product is the product of
distinct cyclotomic polynomials dividing $f$.
\bprog
? f = x^10+5*x^8-x^7+8*x^6-4*x^5+8*x^4-3*x^3+7*x^2+3;
? v = polcyclofactors(f)
%2 = [x^2 + 1, x^2 + x + 1, x^4 - x^3 + x^2 - x + 1]
? apply(poliscycloprod, v)
%3 = [1, 1, 1]
? apply(poliscyclo, v)
%4 = [4, 3, 10]
@eprog\noindent In general, the polynomials are products of cyclotomic
polynomials and not themselves irreducible:
\bprog
? g = x^8+2*x^7+6*x^6+9*x^5+12*x^4+11*x^3+10*x^2+6*x+3;
? polcyclofactors(g)
%2 = [x^6 + 2*x^5 + 3*x^4 + 3*x^3 + 3*x^2 + 2*x + 1]
? factor(%[1])
%3 =
[ x^2 + x + 1 1]
[x^4 + x^3 + x^2 + x + 1 1]
@eprog
Function: poldegree
Class: basic
Section: polynomials
C-Name: gppoldegree
Prototype: GDn
Help: poldegree(x,{v}): degree of the polynomial or rational function x with
respect to main variable if v is omitted, with respect to v otherwise.
For scalar x, return 0 if x is non-zero and -oo otherwise.
Doc: degree of the polynomial $x$ in the main variable if $v$ is omitted, in
the variable $v$ otherwise.
The degree of $0$ is \kbd{-oo}. The degree of a non-zero scalar is $0$.
Finally, when $x$ is a non-zero polynomial or rational function, returns the
ordinary degree of $x$. Raise an error otherwise.
Variant: Also available is
\fun{long}{poldegree}{GEN x, long v}, which returns \tet{-LONG_MAX} if $x = 0$
and the degree as a \kbd{long} integer.
Function: poldisc
Class: basic
Section: polynomials
C-Name: poldisc0
Prototype: GDn
Help: poldisc(pol,{v}): discriminant of the polynomial pol, with respect to main
variable if v is omitted, with respect to v otherwise.
Description:
(gen):gen poldisc0($1, -1)
(gen, var):gen poldisc0($1, $2)
Doc: discriminant of the polynomial
\var{pol} in the main variable if $v$ is omitted, in $v$ otherwise. Uses a
modular algorithm over $\Z$ or $\Q$, and the \idx{subresultant algorithm}
otherwise.
\bprog
? T = x^4 + 2*x+1;
? poldisc(T)
%2 = -176
? poldisc(T^2)
%3 = 0
@eprog
For convenience, the function also applies to types \typ{QUAD} and
\typ{QFI}/\typ{QFR}:
\bprog
? z = 3*quadgen(8) + 4;
? poldisc(z)
%2 = 8
? q = Qfb(1,2,3);
? poldisc(q)
%4 = -8
@eprog
Function: poldiscreduced
Class: basic
Section: polynomials
C-Name: reduceddiscsmith
Prototype: G
Help: poldiscreduced(f): vector of elementary divisors of Z[a]/f'(a)Z[a],
where a is a root of the polynomial f.
Doc: reduced discriminant vector of the
(integral, monic) polynomial $f$. This is the vector of elementary divisors
of $\Z[\alpha]/f'(\alpha)\Z[\alpha]$, where $\alpha$ is a root of the
polynomial $f$. The components of the result are all positive, and their
product is equal to the absolute value of the discriminant of~$f$.
Function: polgalois
Class: basic
Section: number_fields
C-Name: polgalois
Prototype: Gp
Help: polgalois(T): Galois group of the polynomial T (see manual for group
coding). Return [n, s, k, name] where n is the group order, s the signature,
k the index and name is the GAP4 name of the transitive group.
Doc: \idx{Galois} group of the non-constant
polynomial $T\in\Q[X]$. In the present version \vers, $T$ must be irreducible
and the degree $d$ of $T$ must be less than or equal to 7. If the
\tet{galdata} package has been installed, degrees 8, 9, 10 and 11 are also
implemented. By definition, if $K = \Q[x]/(T)$, this computes the action of
the Galois group of the Galois closure of $K$ on the $d$ distinct roots of
$T$, up to conjugacy (corresponding to different root orderings).
The output is a 4-component vector $[n,s,k,name]$ with the
following meaning: $n$ is the cardinality of the group, $s$ is its signature
($s=1$ if the group is a subgroup of the alternating group $A_d$, $s=-1$
otherwise) and name is a character string containing name of the transitive
group according to the GAP 4 transitive groups library by Alexander Hulpke.
$k$ is more arbitrary and the choice made up to version~2.2.3 of PARI is rather
unfortunate: for $d > 7$, $k$ is the numbering of the group among all
transitive subgroups of $S_d$, as given in ``The transitive groups of degree up
to eleven'', G.~Butler and J.~McKay, \emph{Communications in Algebra}, vol.~11,
1983,
pp.~863--911 (group $k$ is denoted $T_k$ there). And for $d \leq 7$, it was ad
hoc, so as to ensure that a given triple would denote a unique group.
Specifically, for polynomials of degree $d\leq 7$, the groups are coded as
follows, using standard notations
\smallskip
In degree 1: $S_1=[1,1,1]$.
\smallskip
In degree 2: $S_2=[2,-1,1]$.
\smallskip
In degree 3: $A_3=C_3=[3,1,1]$, $S_3=[6,-1,1]$.
\smallskip
In degree 4: $C_4=[4,-1,1]$, $V_4=[4,1,1]$, $D_4=[8,-1,1]$, $A_4=[12,1,1]$,
$S_4=[24,-1,1]$.
\smallskip
In degree 5: $C_5=[5,1,1]$, $D_5=[10,1,1]$, $M_{20}=[20,-1,1]$,
$A_5=[60,1,1]$, $S_5=[120,-1,1]$.
\smallskip
In degree 6: $C_6=[6,-1,1]$, $S_3=[6,-1,2]$, $D_6=[12,-1,1]$, $A_4=[12,1,1]$,
$G_{18}=[18,-1,1]$, $S_4^-=[24,-1,1]$, $A_4\times C_2=[24,-1,2]$,
$S_4^+=[24,1,1]$, $G_{36}^-=[36,-1,1]$, $G_{36}^+=[36,1,1]$,
$S_4\times C_2=[48,-1,1]$, $A_5=PSL_2(5)=[60,1,1]$, $G_{72}=[72,-1,1]$,
$S_5=PGL_2(5)=[120,-1,1]$, $A_6=[360,1,1]$, $S_6=[720,-1,1]$.
\smallskip
In degree 7: $C_7=[7,1,1]$, $D_7=[14,-1,1]$, $M_{21}=[21,1,1]$,
$M_{42}=[42,-1,1]$, $PSL_2(7)=PSL_3(2)=[168,1,1]$, $A_7=[2520,1,1]$,
$S_7=[5040,-1,1]$.
\smallskip
This is deprecated and obsolete, but for reasons of backward compatibility,
we cannot change this behavior yet. So you can use the default
\tet{new_galois_format} to switch to a consistent naming scheme, namely $k$ is
always the standard numbering of the group among all transitive subgroups of
$S_n$. If this default is in effect, the above groups will be coded as:
\smallskip
In degree 1: $S_1=[1,1,1]$.
\smallskip
In degree 2: $S_2=[2,-1,1]$.
\smallskip
In degree 3: $A_3=C_3=[3,1,1]$, $S_3=[6,-1,2]$.
\smallskip
In degree 4: $C_4=[4,-1,1]$, $V_4=[4,1,2]$, $D_4=[8,-1,3]$, $A_4=[12,1,4]$,
$S_4=[24,-1,5]$.
\smallskip
In degree 5: $C_5=[5,1,1]$, $D_5=[10,1,2]$, $M_{20}=[20,-1,3]$,
$A_5=[60,1,4]$, $S_5=[120,-1,5]$.
\smallskip
In degree 6: $C_6=[6,-1,1]$, $S_3=[6,-1,2]$, $D_6=[12,-1,3]$, $A_4=[12,1,4]$,
$G_{18}=[18,-1,5]$, $A_4\times C_2=[24,-1,6]$, $S_4^+=[24,1,7]$,
$S_4^-=[24,-1,8]$, $G_{36}^-=[36,-1,9]$, $G_{36}^+=[36,1,10]$,
$S_4\times C_2=[48,-1,11]$, $A_5=PSL_2(5)=[60,1,12]$, $G_{72}=[72,-1,13]$,
$S_5=PGL_2(5)=[120,-1,14]$, $A_6=[360,1,15]$, $S_6=[720,-1,16]$.
\smallskip
In degree 7: $C_7=[7,1,1]$, $D_7=[14,-1,2]$, $M_{21}=[21,1,3]$,
$M_{42}=[42,-1,4]$, $PSL_2(7)=PSL_3(2)=[168,1,5]$, $A_7=[2520,1,6]$,
$S_7=[5040,-1,7]$.
\smallskip
\misctitle{Warning} The method used is that of resolvent polynomials and is
sensitive to the current precision. The precision is updated internally but,
in very rare cases, a wrong result may be returned if the initial precision
was not sufficient.
Variant: To enable the new format in library mode,
set the global variable \tet{new_galois_format} to $1$.
Function: polgraeffe
Class: basic
Section: polynomials
C-Name: polgraeffe
Prototype: G
Help: polgraeffe(f): returns the Graeffe transform g of f, such that
g(x^2) = f(x)f(-x).
Doc: returns the \idx{Graeffe} transform $g$ of $f$, such that $g(x^2) = f(x)
f(-x)$.
Function: polhensellift
Class: basic
Section: polynomials
C-Name: polhensellift
Prototype: GGGL
Help: polhensellift(A, B, p, e): lift the factorization B of A modulo p to a
factorization modulo p^e using Hensel lift. The factors in B must be
pairwise relatively prime modulo p.
Doc: given a prime $p$, an integral polynomial $A$ whose leading coefficient
is a $p$-unit, a vector $B$ of integral polynomials that are monic and
pairwise relatively prime modulo $p$, and whose product is congruent to
$A/\text{lc}(A)$ modulo $p$, lift the elements of $B$ to polynomials whose
product is congruent to $A$ modulo $p^e$.
More generally, if $T$ is an integral polynomial irreducible mod $p$, and
$B$ is a factorization of $A$ over the finite field $\F_p[t]/(T)$, you can
lift it to $\Z_p[t]/(T, p^e)$ by replacing the $p$ argument with $[p,T]$:
\bprog
? { T = t^3 - 2; p = 7; A = x^2 + t + 1;
B = [x + (3*t^2 + t + 1), x + (4*t^2 + 6*t + 6)];
r = polhensellift(A, B, [p, T], 6) }
%1 = [x + (20191*t^2 + 50604*t + 75783), x + (97458*t^2 + 67045*t + 41866)]
? liftall( r[1] * r[2] * Mod(Mod(1,p^6),T) )
%2 = x^2 + (t + 1)
@eprog
Function: polhermite
Class: basic
Section: polynomials
C-Name: polhermite_eval
Prototype: LDG
Help: polhermite(n,{a='x}): Hermite polynomial H(n,v) of degree n, evaluated
at a.
Description:
(small,?var):gen polhermite($1,$2)
(small,gen):gen polhermite_eval($1,$2)
Doc: $n^{\text{th}}$ \idx{Hermite} polynomial $H_n$ evaluated at $a$
(\kbd{'x} by default), i.e.
$$ H_n(x) = (-1)^n\*e^{x^2} \dfrac{d^n}{dx^n}e^{-x^2}.$$
Variant: The variant \fun{GEN}{polhermite}{long n, long v} returns the $n$-th
Hermite polynomial in variable $v$.
Function: polinterpolate
Class: basic
Section: polynomials
C-Name: polint
Prototype: GDGDGD&
Help: polinterpolate(X,{Y},{t = 'x},{&e}): polynomial interpolation at t
according to data vectors X, Y (i.e. given P of minimal degree
such that P(X[i]) = Y[i] for all i, return P(t)). If Y is omitted,
take P such that P(i) = X[i]. If present, e will contain an error estimate on
the returned value.
Doc: given the data vectors
$X$ and $Y$ of the same length $n$ ($X$ containing the $x$-coordinates,
and $Y$ the corresponding $y$-coordinates), this function finds the
\idx{interpolating polynomial} $P$ of minimal degree passing through these
points and evaluates it at~$t$. If $Y$ is omitted, the polynomial $P$
interpolates the $(i,X[i])$. If present, $e$ will contain an error estimate
on the returned value.
Function: poliscyclo
Class: basic
Section: polynomials
C-Name: poliscyclo
Prototype: lG
Help: poliscyclo(f): returns 0 if f is not a cyclotomic polynomial, and n
> 0 if f = Phi_n, the n-th cyclotomic polynomial.
Doc: returns 0 if $f$ is not a cyclotomic polynomial, and $n > 0$ if $f =
\Phi_n$, the $n$-th cyclotomic polynomial.
\bprog
? poliscyclo(x^4-x^2+1)
%1 = 12
? polcyclo(12)
%2 = x^4 - x^2 + 1
? poliscyclo(x^4-x^2-1)
%3 = 0
@eprog
Function: poliscycloprod
Class: basic
Section: polynomials
C-Name: poliscycloprod
Prototype: lG
Help: poliscycloprod(f): returns 1 if f is a product of cyclotomic
polynonials, and 0 otherwise.
Doc: returns 1 if $f$ is a product of cyclotomic polynomial, and $0$
otherwise.
\bprog
? f = x^6+x^5-x^3+x+1;
? poliscycloprod(f)
%2 = 1
? factor(f)
%3 =
[ x^2 + x + 1 1]
[x^4 - x^2 + 1 1]
? [ poliscyclo(T) | T <- %[,1] ]
%4 = [3, 12]
? polcyclo(3) * polcyclo(12)
%5 = x^6 + x^5 - x^3 + x + 1
@eprog
Function: polisirreducible
Class: basic
Section: polynomials
C-Name: isirreducible
Prototype: lG
Help: polisirreducible(pol): true(1) if pol is an irreducible non-constant
polynomial, false(0) if pol is reducible or constant.
Doc: \var{pol} being a polynomial (univariate in the present version \vers),
returns 1 if \var{pol} is non-constant and irreducible, 0 otherwise.
Irreducibility is checked over the smallest base field over which \var{pol}
seems to be defined.
Function: pollead
Class: basic
Section: polynomials
C-Name: pollead
Prototype: GDn
Help: pollead(x,{v}): leading coefficient of polynomial or series x, or x
itself if x is a scalar. Error otherwise. With respect to the main variable
of x if v is omitted, with respect to the variable v otherwise.
Description:
(pol):gen:copy leading_coeff($1)
(gen):gen pollead($1, -1)
(gen, var):gen pollead($1, $2)
Doc: leading coefficient of the polynomial or power series $x$. This is
computed with respect to the main variable of $x$ if $v$ is omitted, with
respect to the variable $v$ otherwise.
Function: pollegendre
Class: basic
Section: polynomials
C-Name: pollegendre_eval
Prototype: LDG
Help: pollegendre(n,{a='x}): legendre polynomial of degree n evaluated at a.
Description:
(small,?var):gen pollegendre($1,$2)
(small,gen):gen pollegendre_eval($1,$2)
Doc: $n^{\text{th}}$ \idx{Legendre polynomial} evaluated at $a$ (\kbd{'x} by
default).
Variant: To obtain the $n$-th Legendre polynomial in variable $v$,
use \fun{GEN}{pollegendre}{long n, long v}.
Function: polmodular
Class: basic
Section: polynomials
C-Name: polmodular
Prototype: LD0,L,DGDnD0,L,
Help: polmodular(L, {inv = 0}, {x = 'x}, {y = 'y}, {derivs = 0}):
return the modular polynomial of level L and invariant inv.
Doc: Return the modular polynomial of prime level $L$ in variables $x$ and $y$
for the modular function specified by \kbd{inv}. If \kbd{inv} is 0 (the
default), use the modular $j$ function, if \kbd{inv} is 1 use the
Weber-$f$ function, and if \kbd{inv} is 5 use $\gamma_2 =
\sqrt[3]{j}$.
See \kbd{polclass} for the full list of invariants.
If $x$ is given as \kbd{Mod(j, p)} or an element $j$ of
a finite field (as a \typ{FFELT}), then return the modular polynomial of
level $L$ evaluated at $j$. If $j$ is from a finite field and
\kbd{derivs} is non-zero, then return a triple where the
last two elements are the first and second derivatives of the modular
polynomial evaluated at $j$.
\bprog
? polmodular(3)
%1 = x^4 + (-y^3 + 2232*y^2 - 1069956*y + 36864000)*x^3 + ...
? polmodular(7, 1, , 'J)
%2 = x^8 - J^7*x^7 + 7*J^4*x^4 - 8*J*x + J^8
? polmodular(7, 5, 7*ffgen(19)^0, 'j)
%3 = j^8 + 4*j^7 + 4*j^6 + 8*j^5 + j^4 + 12*j^2 + 18*j + 18
? polmodular(7, 5, Mod(7,19), 'j)
%4 = Mod(1, 19)*j^8 + Mod(4, 19)*j^7 + Mod(4, 19)*j^6 + ...
? u = ffgen(5)^0; T = polmodular(3,0,,'j)*u;
? polmodular(3, 0, u,'j,1)
%6 = [j^4 + 3*j^2 + 4*j + 1, 3*j^2 + 2*j + 4, 3*j^3 + 4*j^2 + 4*j + 2]
? subst(T,x,u)
%7 = j^4 + 3*j^2 + 4*j + 1
? subst(T',x,u)
%8 = 3*j^2 + 2*j + 4
? subst(T'',x,u)
%9 = 3*j^3 + 4*j^2 + 4*j + 2
@eprog
Function: polrecip
Class: basic
Section: polynomials
C-Name: polrecip
Prototype: G
Help: polrecip(pol): reciprocal polynomial of pol.
Doc: reciprocal polynomial of \var{pol}, i.e.~the coefficients are in
reverse order. \var{pol} must be a polynomial.
Function: polred
Class: basic
Section: number_fields
C-Name: polred0
Prototype: GD0,L,DG
Help: polred(T,{flag=0}): deprecated, use polredbest. Reduction of the
polynomial T (gives minimal polynomials only). The following binary digits of
(optional) flag are significant 1: partial reduction, 2: gives also elements.
Doc: This function is \emph{deprecated}, use \tet{polredbest} instead.
Finds polynomials with reasonably small coefficients defining subfields of
the number field defined by $T$. One of the polynomials always defines $\Q$
(hence is equal to $x-1$), and another always defines the same number field
as $T$ if $T$ is irreducible.
All $T$ accepted by \tet{nfinit} are also allowed here;
in particular, the format \kbd{[T, listP]} is recommended, e.g. with
$\kbd{listP} = 10^5$ or a vector containing all ramified primes. Otherwise,
the maximal order of $\Q[x]/(T)$ must be computed.
The following binary digits of $\fl$ are significant:
1: Possibly use a suborder of the maximal order. The
primes dividing the index of the order chosen are larger than
\tet{primelimit} or divide integers stored in the \tet{addprimes} table.
This flag is \emph{deprecated}, the \kbd{[T, listP]} format is more
flexible.
2: gives also elements. The result is a two-column matrix, the first column
giving primitive elements defining these subfields, the second giving the
corresponding minimal polynomials.
\bprog
? M = polred(x^4 + 8, 2)
%1 =
[1 x - 1]
[1/2*x^2 x^2 + 2]
[1/4*x^3 x^4 + 2]
[x x^4 + 8]
? minpoly(Mod(M[2,1], x^4+8))
%2 = x^2 + 2
@eprog
\synt{polred}{GEN T} ($\fl = 0$). Also available is
\fun{GEN}{polred2}{GEN T} ($\fl = 2$). The function \kbd{polred0} is
deprecated, provided for backward compatibility.
Obsolete: 2013-03-27
Function: polredabs
Class: basic
Section: number_fields
C-Name: polredabs0
Prototype: GD0,L,
Help: polredabs(T,{flag=0}): a smallest generating polynomial of the number
field for the T2 norm on the roots, with smallest index for the minimal T2
norm. flag is optional, whose binary digit mean 1: give the element whose
characteristic polynomial is the given polynomial. 4: give all polynomials
of minimal T2 norm (give only one of P(x) and P(-x)).
Doc: returns a canonical defining polynomial $P$ for the number field
$\Q[X]/(T)$ defined by $T$, such that the sum of the squares of the modulus
of the roots (i.e.~the $T_2$-norm) is minimal. Different $T$ defining
isomorphic number fields will yield the same $P$. All $T$ accepted by
\tet{nfinit} are also allowed here, e.g. non-monic polynomials, or pairs
\kbd{[T, listP]} specifying that a non-maximal order may be used. For
convenience, any number field structure (\var{nf}, \var{bnf},\dots) can also
be used instead of $T$.
\bprog
? polredabs(x^2 + 16)
%1 = x^2 + 1
? K = bnfinit(x^2 + 16); polredabs(K)
%2 = x^2 + 1
@eprog
\misctitle{Warning 1} Using a \typ{POL} $T$ requires computing
and fully factoring the discriminant $d_K$ of the maximal order which may be
very hard. You can use the format \kbd{[T, listP]}, where \kbd{listP}
encodes a list of known coprime divisors of $\disc(T)$ (see \kbd{??nfbasis}),
to help the routine, thereby replacing this part of the algorithm by a
polynomial time computation But this may only compute a suborder of the
maximal order, when the divisors are not squarefree or do not include all
primes dividing $d_K$. The routine attempts to certify the result
independently of this order computation as per \tet{nfcertify}: we try to
prove that the computed order is maximal. If the certification fails,
the routine then fully factors the integers returned by \kbd{nfcertify}.
You can use \tet{polredbest} or \kbd{polredabs(,16)} to avoid this
factorization step; in both cases, the result is no longer canonical.
\misctitle{Warning 2} Apart from the factorization of the discriminant of
$T$, this routine runs in polynomial time for a \emph{fixed} degree.
But the complexity is exponential in the degree: this routine
may be exceedingly slow when the number field has many subfields, hence a
lot of elements of small $T_2$-norm. If you do not need a canonical
polynomial, the function \tet{polredbest} is in general much faster (it runs
in polynomial time), and tends to return polynomials with smaller
discriminants.
The binary digits of $\fl$ mean
1: outputs a two-component row vector $[P,a]$, where $P$ is the default
output and \kbd{Mod(a, P)} is a root of the original $T$.
4: gives \emph{all} polynomials of minimal $T_2$ norm; of the two polynomials
$P(x)$ and $\pm P(-x)$, only one is given.
16: Possibly use a suborder of the maximal order, \emph{without} attempting to
certify the result as in Warning 1: we always return a polynomial and never
$0$. The result is a priori not canonical.
\bprog
? T = x^16 - 136*x^14 + 6476*x^12 - 141912*x^10 + 1513334*x^8 \
- 7453176*x^6 + 13950764*x^4 - 5596840*x^2 + 46225
? T1 = polredabs(T); T2 = polredbest(T);
? [ norml2(polroots(T1)), norml2(polroots(T2)) ]
%3 = [88.0000000, 120.000000]
? [ sizedigit(poldisc(T1)), sizedigit(poldisc(T2)) ]
%4 = [75, 67]
@eprog
Variant: Instead of the above hardcoded numerical flags, one should use an
or-ed combination of
\item \tet{nf_PARTIALFACT}: possibly use a suborder of the maximal order,
\emph{without} attempting to certify the result.
\item \tet{nf_ORIG}: return $[P, a]$, where \kbd{Mod(a, P)} is a root of $T$.
\item \tet{nf_RAW}: return $[P, b]$, where \kbd{Mod(b, T)} is a root of $P$.
The algebraic integer $b$ is the raw result produced by the small vectors
enumeration in the maximal order; $P$ was computed as the characteristic
polynomial of \kbd{Mod(b, T)}. \kbd{Mod(a, P)} as in \tet{nf_ORIG}
is obtained with \tet{modreverse}.
\item \tet{nf_ADDZK}: if $r$ is the result produced with some of the above
flags (of the form $P$ or $[P,c]$), return \kbd{[r,zk]}, where \kbd{zk} is a
$\Z$-basis for the maximal order of $\Q[X]/(P)$.
\item \tet{nf_ALL}: return a vector of results of the above form, for all
polynomials of minimal $T_2$-norm.
Function: polredbest
Class: basic
Section: number_fields
C-Name: polredbest
Prototype: GD0,L,
Help: polredbest(T,{flag=0}): reduction of the polynomial T (gives minimal
polynomials only). If flag=1, gives also elements.
Doc: finds a polynomial with reasonably
small coefficients defining the same number field as $T$.
All $T$ accepted by \tet{nfinit} are also allowed here (e.g. non-monic
polynomials, \kbd{nf}, \kbd{bnf}, \kbd{[T,Z\_K\_basis]}). Contrary to
\tet{polredabs}, this routine runs in polynomial time, but it offers no
guarantee as to the minimality of its result.
This routine computes an LLL-reduced basis for the ring of integers of
$\Q[X]/(T)$, then examines small linear combinations of the basis vectors,
computing their characteristic polynomials. It returns the \emph{separable}
$P$ polynomial of smallest discriminant (the one with lexicographically
smallest \kbd{abs(Vec(P))} in case of ties). This is a good candidate
for subsequent number field computations, since it guarantees that
the denominators of algebraic integers, when expressed in the power basis,
are reasonably small. With no claim of minimality, though.
It can happen that iterating this functions yields better and better
polynomials, until it stabilizes:
\bprog
? \p5
? P = X^12+8*X^8-50*X^6+16*X^4-3069*X^2+625;
? poldisc(P)*1.
%2 = 1.2622 E55
? P = polredbest(P);
? poldisc(P)*1.
%4 = 2.9012 E51
? P = polredbest(P);
? poldisc(P)*1.
%6 = 8.8704 E44
@eprog\noindent In this example, the initial polynomial $P$ is the one
returned by \tet{polredabs}, and the last one is stable.
If $\fl = 1$: outputs a two-component row vector $[P,a]$, where $P$ is the
default output and \kbd{Mod(a, P)} is a root of the original $T$.
\bprog
? [P,a] = polredbest(x^4 + 8, 1)
%1 = [x^4 + 2, Mod(x^3, x^4 + 2)]
? charpoly(a)
%2 = x^4 + 8
@eprog\noindent In particular, the map $\Q[x]/(T) \to \Q[x]/(P)$,
$x\mapsto \kbd{Mod(a,P)}$ defines an isomorphism of number fields, which can
be computed as
\bprog
subst(lift(Q), 'x, a)
@eprog\noindent if $Q$ is a \typ{POLMOD} modulo $T$; \kbd{b = modreverse(a)}
returns a \typ{POLMOD} giving the inverse of the above map (which should be
useless since $\Q[x]/(P)$ is a priori a better representation for the number
field and its elements).
Function: polredord
Class: basic
Section: number_fields
C-Name: polredord
Prototype: G
Help: polredord(x): this function is obsolete, use polredbest.
Doc: This function is obsolete, use polredbest.
Obsolete: 2008-07-20
Function: polresultant
Class: basic
Section: polynomials
C-Name: polresultant0
Prototype: GGDnD0,L,
Help: polresultant(x,y,{v},{flag=0}): resultant of the polynomials x and y,
with respect to the main variables of x and y if v is omitted, with respect
to the variable v otherwise. flag is optional, and can be 0: default,
uses either the subresultant algorithm, a modular algorithm or Sylvester's
matrix, depending on the inputs; 1 uses Sylvester's matrix (should always be
slower than the default).
Doc: resultant of the two
polynomials $x$ and $y$ with exact entries, with respect to the main
variables of $x$ and $y$ if $v$ is omitted, with respect to the variable $v$
otherwise. The algorithm assumes the base ring is a domain. If you also need
the $u$ and $v$ such that $x*u + y*v = \text{Res}(x,y)$, use the
\tet{polresultantext} function.
If $\fl=0$ (default), uses the algorithm best suited to the inputs,
either the \idx{subresultant algorithm} (Lazard/Ducos variant, generic case),
a modular algorithm (inputs in $\Q[X]$) or Sylvester's matrix (inexact
inputs).
If $\fl=1$, uses the determinant of Sylvester's matrix instead; this should
always be slower than the default.
Function: polresultantext
Class: basic
Section: polynomials
C-Name: polresultantext0
Prototype: GGDn
Help: polresultantext(A,B,{v}): return [U,V,R] such that
R=polresultant(A,B,v) and U*A+V*B = R, where A and B are polynomials.
Doc: finds polynomials $U$ and $V$ such that $A*U + B*V = R$, where $R$ is
the resultant of $U$ and $V$ with respect to the main variables of $A$ and
$B$ if $v$ is omitted, and with respect to $v$ otherwise. Returns the row
vector $[U,V,R]$. The algorithm used (subresultant) assumes that the base
ring is a domain.
\bprog
? A = x*y; B = (x+y)^2;
? [U,V,R] = polresultantext(A, B)
%2 = [-y*x - 2*y^2, y^2, y^4]
? A*U + B*V
%3 = y^4
? [U,V,R] = polresultantext(A, B, y)
%4 = [-2*x^2 - y*x, x^2, x^4]
? A*U+B*V
%5 = x^4
@eprog
Variant: Also available is
\fun{GEN}{polresultantext}{GEN x, GEN y}.
Function: polroots
Class: basic
Section: polynomials
C-Name: roots
Prototype: Gp
Help: polroots(T): complex roots of the polynomial T using
Schonhage's method, as modified by Gourdon.
Doc: complex roots of the polynomial
$T$, given as a column vector where each root is repeated according to
its multiplicity. The precision is given as for transcendental functions: in
GP it is kept in the variable \kbd{realprecision} and is transparent to the
user, but it must be explicitly given as a second argument in library mode.
The algorithm used is a modification of Sch\"onhage\sidx{Sch\"onage}'s
root-finding algorithm, due to and originally implemented by Gourdon.
It is guaranteed to converge; if furthermore $T$ has rational coefficients,
roots are guaranteed to the required relative accuracy.
Function: polrootsff
Class: basic
Section: number_theoretical
C-Name: polrootsff
Prototype: GDGDG
Help: polrootsff(x,{p},{a}): returns the roots of the polynomial x in the finite
field F_p[X]/a(X)F_p[X]. a or p can be omitted if x has t_FFELT coefficients.
Doc: returns the vector of distinct roots of the polynomial $x$ in the field
$\F_q$ defined by the irreducible polynomial $a$ over $\F_p$. The
coefficients of $x$ must be operation-compatible with $\Z/p\Z$.
Either $a$ or $p$ can omitted (in which case both are ignored) if x has
\typ{FFELT} coefficients:
\bprog
? polrootsff(x^2 + 1, 5, y^2+3) \\ over F_5[y]/(y^2+3) ~ F_25
%1 = [Mod(Mod(3, 5), Mod(1, 5)*y^2 + Mod(3, 5)),
Mod(Mod(2, 5), Mod(1, 5)*y^2 + Mod(3, 5))]
? t = ffgen(y^2 + Mod(3,5), 't); \\ a generator for F_25 as a t_FFELT
? polrootsff(x^2 + 1) \\ not enough information to determine the base field
*** at top-level: polrootsff(x^2+1)
*** ^-----------------
*** polrootsff: incorrect type in factorff.
? polrootsff(x^2 + t^0) \\ make sure one coeff. is a t_FFELT
%3 = [3, 2]
? polrootsff(x^2 + t + 1)
%4 = [2*t + 1, 3*t + 4]
@eprog\noindent
Notice that the second syntax is easier to use and much more readable.
Function: polrootsmod
Class: basic
Section: polynomials
C-Name: rootmod0
Prototype: GGD0,L,
Help: polrootsmod(pol,p,{flag=0}): roots mod the prime p of the polynomial pol. flag is
optional, and can be 0: default, or 1: use a naive search, useful for small p.
Description:
(pol, int, ?0):vec rootmod($1, $2)
(pol, int, 1):vec rootmod2($1, $2)
(pol, int, #small):vec $"Bad flag in polrootsmod"
(pol, int, small):vec rootmod0($1, $2, $3)
Doc: row vector of roots modulo $p$ of the polynomial \var{pol}.
Multiple roots are \emph{not} repeated.
\bprog
? polrootsmod(x^2-1,2)
%1 = [Mod(1, 2)]~
@eprog\noindent
If $p$ is very small, you may set $\fl=1$, which uses a naive search.
Function: polrootspadic
Class: basic
Section: polynomials
C-Name: rootpadic
Prototype: GGL
Help: polrootspadic(x,p,r): p-adic roots of the polynomial x to precision r.
Doc: vector of $p$-adic roots of the polynomial \var{pol}, given to
$p$-adic precision $r$ $p$ is assumed to be a prime. Multiple roots are
\emph{not} repeated. Note that this is not the same as the roots in
$\Z/p^r\Z$, rather it gives approximations in $\Z/p^r\Z$ of the true roots
living in $\Q_p$.
\bprog
? polrootspadic(x^3 - x^2 + 64, 2, 5)
%1 = [2^3 + O(2^5), 2^3 + 2^4 + O(2^5), 1 + O(2^5)]~
@eprog
If \var{pol} has inexact \typ{PADIC} coefficients, this is not always
well-defined; in this case, the polynomial is first made integral by dividing
out the $p$-adic content, then lifted
to $\Z$ using \tet{truncate} coefficientwise. Hence the roots given are
approximations of the roots of an exact polynomial which is $p$-adically
close to the input. To avoid pitfalls, we advise to only factor polynomials
with exact rational coefficients.
Function: polrootsreal
Class: basic
Section: polynomials
C-Name: realroots
Prototype: GDGp
Help: polrootsreal(T, {ab}): real roots of the polynomial T with rational
coefficients, using Uspensky's method. In interval ab = [a,b] if present.
Doc: real roots of the polynomial $T$ with rational coefficients, multiple
roots being included according to their multiplicity. The roots are given
to a relative accuracy of \kbd{realprecision}. If argument \var{ab} is
present, it must be a vector $[a,b]$ with two components (of type
\typ{INT}, \typ{FRAC} or \typ{INFINITY}) and we restrict to roots belonging
to that closed interval.
\bprog
? \p9
? polrootsreal(x^2-2)
%1 = [-1.41421356, 1.41421356]~
? polrootsreal(x^2-2, [1,+oo])
%2 = [1.41421356]~
? polrootsreal(x^2-2, [2,3])
%3 = []~
? polrootsreal((x-1)*(x-2), [2,3])
%4 = [2.00000000]~
@eprog\noindent
The algorithm used is a modification of Uspensky's method (relying on
Descartes's rule of sign), following Rouillier and Zimmerman's article
``Efficient isolation of a polynomial real roots''
(\url{http://hal.inria.fr/inria-00072518/}). Barring bugs, it is guaranteed
to converge and to give the roots to the required accuracy.
\misctitle{Remark} If the polynomial $T$ is of the
form $Q(x^h)$ for some $h\geq 2$ and \var{ab} is omitted, the routine will
apply the algorithm to $Q$ (restricting to non-negative roots when $h$ is
even), then take $h$-th roots. On the other hand, if you want to specify
\var{ab}, you should apply the routine to $Q$ yourself and a suitable
interval $[a',b']$ using approximate $h$-th roots adapted to your problem:
the function will not perform this change of variables if \var{ab} is present.
Function: polsturm
Class: basic
Section: polynomials
C-Name: sturmpart
Prototype: lGDGDG
Help: polsturm(T,{ab}): number of real roots of the squarefree polynomial
T (in the interval ab = [a,b] if present).
Doc: number of real roots of the real squarefree polynomial \var{T}. If
the argument \var{ab} is present, it must be a vector $[a,b]$ with
two real components (of type \typ{INT}, \typ{REAL}, \typ{FRAC}
or \typ{INFINITY}) and we count roots belonging to that closed interval.
If possible, you should stick to exact inputs, that is avoid \typ{REAL}s in
$T$ and the bounds $a,b$: the result is then guaranteed and we use a fast
algorithm (Uspensky's method, relying on Descartes's rule of sign, see
\tet{polrootsreal}); otherwise, we use Sturm's algorithm and the result
may be wrong due to round-off errors.
\bprog
? T = (x-1)*(x-2)*(x-3);
? polsturm(T)
%2 = 3
? polsturm(T, [-oo,2])
%3 = 2
? polsturm(T, [1/2,+oo])
%4 = 3
? polsturm(T, [1, Pi]) \\ Pi inexact: not recommended !
%5 = 3
? polsturm(T*1., [0, 4]) \\ T*1. inexact: not recommended !
%6 = 3
? polsturm(T^2, [0, 4]) \\ not squarefree
*** at top-level: polsturm(T^2,[0,4])
*** ^-------------------
*** polsturm: domain error in polsturm: issquarefree(pol) = 0
? polsturm((T*1.)^2, [0, 4]) \\ not squarefree AND inexact
*** at top-level: polsturm((T*1.)^2,[0
*** ^--------------------
*** polsturm: precision too low in polsturm.
@eprog\noindent In the last example, the input polynomial is not
squarefree but there is no way to ascertain it from the given
floating point approximation: we get a precision error in this case.
%\syn{NO}
The library syntax is \fun{long}{RgX_sturmpart}{GEN T, GEN ab} or
\fun{long}{sturm}{GEN T} (for the case \kbd{ab = NULL}). The function
\fun{long}{sturmpart}{GEN T, GEN a, GEN b} is obsolete and deprecated.
Function: polsubcyclo
Class: basic
Section: polynomials
C-Name: polsubcyclo
Prototype: LLDn
Help: polsubcyclo(n,d,{v='x}): finds an equation (in variable v) for the d-th
degree subfields of Q(zeta_n). Output is a polynomial, or a vector of
polynomials if there are several such fields or none.
Doc: gives polynomials (in variable $v$) defining the sub-Abelian extensions
of degree $d$ of the cyclotomic field $\Q(\zeta_n)$, where $d\mid \phi(n)$.
If there is exactly one such extension the output is a polynomial, else it is
a vector of polynomials, possibly empty. To get a vector in all cases,
use \kbd{concat([], polsubcyclo(n,d))}.
The function \tet{galoissubcyclo} allows to specify exactly which
sub-Abelian extension should be computed.
Function: polsylvestermatrix
Class: basic
Section: polynomials
C-Name: sylvestermatrix
Prototype: GG
Help: polsylvestermatrix(x,y): forms the sylvester matrix attached to the
two polynomials x and y. Warning: the polynomial coefficients are in
columns, not in rows.
Doc: forms the Sylvester matrix
corresponding to the two polynomials $x$ and $y$, where the coefficients of
the polynomials are put in the columns of the matrix (which is the natural
direction for solving equations afterwards). The use of this matrix can be
essential when dealing with polynomials with inexact entries, since
polynomial Euclidean division doesn't make much sense in this case.
Function: polsym
Class: basic
Section: polynomials
C-Name: polsym
Prototype: GL
Help: polsym(x,n): column vector of symmetric powers of the roots of x up to n.
Doc: creates the column vector of the \idx{symmetric powers} of the roots of the
polynomial $x$ up to power $n$, using Newton's formula.
Function: poltchebi
Class: basic
Section: polynomials
C-Name: polchebyshev1
Prototype: LDn
Help: poltchebi(n,{v='x}): deprecated alias for polchebyshev.
Doc: deprecated alias for \kbd{polchebyshev}
Obsolete: 2013-04-03
Function: poltschirnhaus
Class: basic
Section: number_fields
C-Name: tschirnhaus
Prototype: G
Help: poltschirnhaus(x): random Tschirnhausen transformation of the
polynomial x.
Doc: applies a random Tschirnhausen
transformation to the polynomial $x$, which is assumed to be non-constant
and separable, so as to obtain a new equation for the \'etale algebra
defined by $x$. This is for instance useful when computing resolvents,
hence is used by the \kbd{polgalois} function.
Function: polylog
Class: basic
Section: transcendental
C-Name: polylog0
Prototype: LGD0,L,p
Help: polylog(m,x,{flag=0}): m-th polylogarithm of x. flag is optional, and
can be 0: default, 1: D_m~-modified m-th polylog of x, 2: D_m-modified m-th
polylog of x, 3: P_m-modified m-th polylog of x.
Doc: one of the different polylogarithms, depending on \fl:
If $\fl=0$ or is omitted: $m^\text{th}$ polylogarithm of $x$, i.e.~analytic
continuation of the power series $\text{Li}_m(x)=\sum_{n\ge1}x^n/n^m$
($x < 1$). Uses the functional equation linking the values at $x$ and $1/x$
to restrict to the case $|x|\leq 1$, then the power series when
$|x|^2\le1/2$, and the power series expansion in $\log(x)$ otherwise.
Using $\fl$, computes a modified $m^\text{th}$ polylogarithm of $x$.
We use Zagier's notations; let $\Re_m$ denote $\Re$ or $\Im$ depending
on whether $m$ is odd or even:
If $\fl=1$: compute $\tilde D_m(x)$, defined for $|x|\le1$ by
$$\Re_m\left(\sum_{k=0}^{m-1} \dfrac{(-\log|x|)^k}{k!}\text{Li}_{m-k}(x)
+\dfrac{(-\log|x|)^{m-1}}{m!}\log|1-x|\right).$$
If $\fl=2$: compute $D_m(x)$, defined for $|x|\le1$ by
$$\Re_m\left(\sum_{k=0}^{m-1}\dfrac{(-\log|x|)^k}{k!}\text{Li}_{m-k}(x)
-\dfrac{1}{2}\dfrac{(-\log|x|)^m}{m!}\right).$$
If $\fl=3$: compute $P_m(x)$, defined for $|x|\le1$ by
$$\Re_m\left(\sum_{k=0}^{m-1}\dfrac{2^kB_k}{k!}(\log|x|)^k\text{Li}_{m-k}(x)
-\dfrac{2^{m-1}B_m}{m!}(\log|x|)^m\right).$$
These three functions satisfy the functional equation
$f_m(1/x) = (-1)^{m-1}f_m(x)$.
Variant: Also available is
\fun{GEN}{gpolylog}{long m, GEN x, long prec} (\fl = 0).
Function: polzagier
Class: basic
Section: polynomials
C-Name: polzag
Prototype: LL
Help: polzagier(n,m): Zagier's polynomials of index n,m.
Doc: creates Zagier's polynomial $P_n^{(m)}$ used in
the functions \kbd{sumalt} and \kbd{sumpos} (with $\fl=1$), see
``Convergence acceleration of alternating series'', Cohen et al.,
\emph{Experiment.~Math.}, vol.~9, 2000, pp.~3--12.
If $m < 0$ or $m \ge n$, $P_n^{(m)} = 0$.
We have
$P_n := P_n^{(0)}$ is $T_n(2x-1)$, where $T_n$ is the Legendre polynomial of
the second kind. For $n > m > 0$, $P_n^{(m)}$ is the $m$-th difference with
step $2$ of the sequence $n^{m+1}P_n$; in this case, it satisfies
$$2 P_n^{(m)}(sin^2 t) = \dfrac{d^{m+1}}{dt^{m+1}}(\sin(2t)^m \sin(2(n-m)t)).$$
%@article {MR2001m:11222,
% AUTHOR = {Cohen, Henri and Rodriguez Villegas, Fernando and Zagier, Don},
% TITLE = {Convergence acceleration of alternating series},
% JOURNAL = {Experiment. Math.},
% VOLUME = {9},
% YEAR = {2000},
% NUMBER = {1},
% PAGES = {3--12},
%}
Function: powers
Class: basic
Section: operators
C-Name: gpowers0
Prototype: GLDG
Help: powers(x,n,{x0}): return the vector [1,x,...,x^n] if x0 is omitted,
and [x0, x0*x, ..., x0*x^n] otherwise.
Description:
(gen, small):vec gpowers($1, $2)
Doc: for non-negative $n$, return the vector with $n+1$ components
$[1,x,\dots,x^n]$ if \kbd{x0} is omitted, and $[x_0, x_0*x, ..., x_0*x^n]$
otherwise.
\bprog
? powers(Mod(3,17), 4)
%1 = [Mod(1, 17), Mod(3, 17), Mod(9, 17), Mod(10, 17), Mod(13, 17)]
? powers(Mat([1,2;3,4]), 3)
%2 = [[1, 0; 0, 1], [1, 2; 3, 4], [7, 10; 15, 22], [37, 54; 81, 118]]
? powers(3, 5, 2)
%3 = [2, 6, 18, 54, 162, 486]
@eprog\noindent When $n < 0$, the function returns the empty vector \kbd{[]}.
Variant: Also available is
\fun{GEN}{gpowers}{GEN x, long n} when \kbd{x0} is \kbd{NULL}.
Function: precision
Class: basic
Section: conversions
C-Name: precision0
Prototype: GD0,L,
Help: precision(x,{n}): if n is present, return x at precision n. If n is
omitted, return real precision of object x.
Description:
(real):small prec2ndec(gprecision($1))
(gen):int precision0($1, 0)
(real,0):small prec2ndec(gprecision($1))
(gen,0):int precision0($1, 0)
(real,#small):real rtor($1, ndec2prec($2))
(gen,#small):gen gprec($1, $2)
(real,small):real precision0($1, $2)
(mp,small):mp precision0($1, $2)
(gen,small):gen precision0($1, $2)
Doc: the function behaves differently according to whether $n$ is
present and positive or not. If $n$ is missing, the function returns the
precision in decimal digits of the PARI object $x$. If $x$ is an exact
object, the function returns \kbd{+oo}.
\bprog
? precision(exp(1e-100))
%1 = 154 \\ 154 significant decimal digits
? precision(2 + x)
%2 = +oo \\ exact object
? precision(0.5 + O(x))
%3 = 38 \\ floating point accuracy, NOT series precision
? precision( [ exp(1e-100), 0.5 ] )
%4 = 38 \\ minimal accuracy among components
@eprog
If $n$ is present, the function creates a new object equal to $x$ with a new
floating point precision $n$: $n$ is the number of desired significant
\emph{decimal} digits. If $n$ is smaller than the precision of a \typ{REAL}
component of $x$, it is truncated, otherwise it is extended with zeros.
For exact or non-floating point types, no change.
Variant: Also available are \fun{GEN}{gprec}{GEN x, long n} and
\fun{long}{precision}{GEN x}. In both, the accuracy is expressed in
\emph{words} (32-bit or 64-bit depending on the architecture).
Function: precprime
Class: basic
Section: number_theoretical
C-Name: precprime
Prototype: G
Help: precprime(x): largest pseudoprime <= x, 0 if x<=1.
Description:
(gen):int precprime($1)
Doc: finds the largest pseudoprime (see
\tet{ispseudoprime}) less than or equal to $x$. $x$ can be of any real type.
Returns 0 if $x\le1$. Note that if $x$ is a prime, this function returns $x$
and not the largest prime strictly smaller than $x$. To rigorously prove that
the result is prime, use \kbd{isprime}.
Function: prime
Class: basic
Section: number_theoretical
C-Name: prime
Prototype: L
Help: prime(n): returns the n-th prime (n C-integer).
Doc: the $n^{\text{th}}$ prime number
\bprog
? prime(10^9)
%1 = 22801763489
@eprog\noindent Uses checkpointing and a naive $O(n)$ algorithm.
Function: primepi
Class: basic
Section: number_theoretical
C-Name: primepi
Prototype: G
Help: primepi(x): the prime counting function pi(x) = #{p <= x, p prime}.
Description:
(gen):int primepi($1)
Doc: the prime counting function. Returns the number of
primes $p$, $p \leq x$.
\bprog
? primepi(10)
%1 = 4;
? primes(5)
%2 = [2, 3, 5, 7, 11]
? primepi(10^11)
%3 = 4118054813
@eprog\noindent Uses checkpointing and a naive $O(x)$ algorithm.
Function: primes
Class: basic
Section: number_theoretical
C-Name: primes0
Prototype: G
Help: primes(n): returns the vector of the first n primes (integer), or the
primes in interval n = [a,b].
Doc: creates a row vector whose components are the first $n$ prime numbers.
(Returns the empty vector for $n \leq 0$.) A \typ{VEC} $n = [a,b]$ is also
allowed, in which case the primes in $[a,b]$ are returned
\bprog
? primes(10) \\ the first 10 primes
%1 = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
? primes([0,29]) \\ the primes up to 29
%2 = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
? primes([15,30])
%3 = [17, 19, 23, 29]
@eprog
Function: print
Class: basic
Section: programming/specific
C-Name: print
Prototype: vs*
Help: print({str}*): outputs its string arguments (in raw format) ending with
a newline.
Description:
(?gen,...):void pari_printf("${2 format_string}\n"${2 format_args})
Doc: outputs its (string) arguments in raw format, ending with a newline.
%\syn{NO}
Function: print1
Class: basic
Section: programming/specific
C-Name: print1
Prototype: vs*
Help: print1({str}*): outputs its string arguments (in raw format) without
ending with newline.
Description:
(?gen,...):void pari_printf("${2 format_string}"${2 format_args})
Doc: outputs its (string) arguments in raw
format, without ending with a newline. Note that you can still embed newlines
within your strings, using the \b{n} notation~!
%\syn{NO}
Function: printf
Class: basic
Section: programming/specific
C-Name: printf0
Prototype: vss*
Help: printf(fmt,{x}*): prints its arguments according to the format fmt.
Doc: This function is based on the C library command of the same name.
It prints its arguments according to the format \var{fmt}, which specifies how
subsequent arguments are converted for output. The format is a
character string composed of zero or more directives:
\item ordinary characters (not \kbd{\%}), printed unchanged,
\item conversions specifications (\kbd{\%} followed by some characters)
which fetch one argument from the list and prints it according to the
specification.
More precisely, a conversion specification consists in a \kbd{\%}, one or more
optional flags (among \kbd{\#}, \kbd{0}, \kbd{-}, \kbd{+}, ` '), an optional
decimal digit string specifying a minimal field width, an optional precision
in the form of a period (`\kbd{.}') followed by a decimal digit string, and
the conversion specifier (among \kbd{d},\kbd{i}, \kbd{o}, \kbd{u},
\kbd{x},\kbd{X}, \kbd{p}, \kbd{e},\kbd{E}, \kbd{f}, \kbd{g},\kbd{G}, \kbd{s}).
\misctitle{The flag characters} The character \kbd{\%} is followed by zero or
more of the following flags:
\item \kbd{\#}: the value is converted to an ``alternate form''. For
\kbd{o} conversion (octal), a \kbd{0} is prefixed to the string. For \kbd{x}
and \kbd{X} conversions (hexa), respectively \kbd{0x} and \kbd{0X} are
prepended. For other conversions, the flag is ignored.
\item \kbd{0}: the value should be zero padded. For
\kbd{d},
\kbd{i},
\kbd{o},
\kbd{u},
\kbd{x},
\kbd{X}
\kbd{e},
\kbd{E},
\kbd{f},
\kbd{F},
\kbd{g}, and
\kbd{G} conversions, the value is padded on the left with zeros rather than
blanks. (If the \kbd{0} and \kbd{-} flags both appear, the \kbd{0} flag is
ignored.)
\item \kbd{-}: the value is left adjusted on the field boundary. (The
default is right justification.) The value is padded on the right with
blanks, rather than on the left with blanks or zeros. A \kbd{-} overrides a
\kbd{0} if both are given.
\item \kbd{` '} (a space): a blank is left before a positive number
produced by a signed conversion.
\item \kbd{+}: a sign (+ or -) is placed before a number produced by a
signed conversion. A \kbd{+} overrides a space if both are used.
\misctitle{The field width} An optional decimal digit string (whose first
digit is non-zero) specifying a \emph{minimum} field width. If the value has
fewer characters than the field width, it is padded with spaces on the left
(or right, if the left-adjustment flag has been given). In no case does a
small field width cause truncation of a field; if the value is wider than
the field width, the field is expanded to contain the conversion result.
Instead of a decimal digit string, one may write \kbd{*} to specify that the
field width is given in the next argument.
\misctitle{The precision} An optional precision in the form of a period
(`\kbd{.}') followed by a decimal digit string. This gives
the number of digits to appear after the radix character for \kbd{e},
\kbd{E}, \kbd{f}, and \kbd{F} conversions, the maximum number of significant
digits for \kbd{g} and \kbd{G} conversions, and the maximum number of
characters to be printed from an \kbd{s} conversion.
Instead of a decimal digit string, one may write \kbd{*} to specify that the
field width is given in the next argument.
\misctitle{The length modifier} This is ignored under \kbd{gp}, but
necessary for \kbd{libpari} programming. Description given here for
completeness:
\item \kbd{l}: argument is a \kbd{long} integer.
\item \kbd{P}: argument is a \kbd{GEN}.
\misctitle{The conversion specifier} A character that specifies the type of
conversion to be applied.
\item \kbd{d}, \kbd{i}: a signed integer.
\item \kbd{o}, \kbd{u}, \kbd{x}, \kbd{X}: an unsigned integer, converted
to unsigned octal (\kbd{o}), decimal (\kbd{u}) or hexadecimal (\kbd{x} or
\kbd{X}) notation. The letters \kbd{abcdef} are used for \kbd{x}
conversions; the letters \kbd{ABCDEF} are used for \kbd{X} conversions.
\item \kbd{e}, \kbd{E}: the (real) argument is converted in the style
\kbd{[ -]d.ddd e[ -]dd}, where there is one digit before the decimal point,
and the number of digits after it is equal to the precision; if the
precision is missing, use the current \kbd{realprecision} for the total
number of printed digits. If the precision is explicitly 0, no decimal-point
character appears. An \kbd{E} conversion uses the letter \kbd{E} rather
than \kbd{e} to introduce the exponent.
\item \kbd{f}, \kbd{F}: the (real) argument is converted in the style
\kbd{[ -]ddd.ddd}, where the number of digits after the decimal point
is equal to the precision; if the precision is missing, use the current
\kbd{realprecision} for the total number of printed digits. If the precision
is explicitly 0, no decimal-point character appears. If a decimal point
appears, at least one digit appears before it.
\item \kbd{g}, \kbd{G}: the (real) argument is converted in style
\kbd{e} or \kbd{f} (or \kbd{E} or \kbd{F} for \kbd{G} conversions)
\kbd{[ -]ddd.ddd}, where the total number of digits printed
is equal to the precision; if the precision is missing, use the current
\kbd{realprecision}. If the precision is explicitly 0, it is treated as 1.
Style \kbd{e} is used when
the decimal exponent is $< -4$, to print \kbd{0.}, or when the integer
part cannot be decided given the known significant digits, and the \kbd{f}
format otherwise.
\item \kbd{c}: the integer argument is converted to an unsigned char, and the
resulting character is written.
\item \kbd{s}: convert to a character string. If a precision is given, no
more than the specified number of characters are written.
\item \kbd{p}: print the address of the argument in hexadecimal (as if by
\kbd{\%\#x}).
\item \kbd{\%}: a \kbd{\%} is written. No argument is converted. The complete
conversion specification is \kbd{\%\%}.
\noindent Examples:
\bprog
? printf("floor: %d, field width 3: %3d, with sign: %+3d\n", Pi, 1, 2);
floor: 3, field width 3: 1, with sign: +2
? printf("%.5g %.5g %.5g\n",123,123/456,123456789);
123.00 0.26974 1.2346 e8
? printf("%-2.5s:%2.5s:%2.5s\n", "P", "PARI", "PARIGP");
P :PARI:PARIG
\\ min field width and precision given by arguments
? x = 23; y=-1/x; printf("x=%+06.2f y=%+0*.*f\n", x, 6, 2, y);
x=+23.00 y=-00.04
\\ minimum fields width 5, pad left with zeroes
? for (i = 2, 5, printf("%05d\n", 10^i))
00100
01000
10000
100000 \\@com don't truncate fields whose length is larger than the minimum width
? printf("%.2f |%06.2f|", Pi,Pi)
3.14 | 3.14|
@eprog\noindent All numerical conversions apply recursively to the entries
of vectors and matrices:
\bprog
? printf("%4d", [1,2,3]);
[ 1, 2, 3]
? printf("%5.2f", mathilbert(3));
[ 1.00 0.50 0.33]
[ 0.50 0.33 0.25]
[ 0.33 0.25 0.20]
@eprog
\misctitle{Technical note} Our implementation of \tet{printf}
deviates from the C89 and C99 standards in a few places:
\item whenever a precision is missing, the current \kbd{realprecision} is
used to determine the number of printed digits (C89: use 6 decimals after
the radix character).
\item in conversion style \kbd{e}, we do not impose that the
exponent has at least two digits; we never write a \kbd{+} sign in the
exponent; 0 is printed in a special way, always as \kbd{0.E\var{exp}}.
\item in conversion style \kbd{f}, we switch to style \kbd{e} if the
exponent is greater or equal to the precision.
\item in conversion \kbd{g} and \kbd{G}, we do not remove trailing zeros
from the fractional part of the result; nor a trailing decimal point;
0 is printed in a special way, always as \kbd{0.E\var{exp}}.
%\syn{NO}
Function: printsep
Class: basic
Section: programming/specific
C-Name: printsep
Prototype: vss*
Help: printsep(sep,{str}*): outputs its string arguments (in raw format),
separated by 'sep', ending with a newline.
Doc: outputs its (string) arguments in raw format, ending with a newline.
Successive entries are separated by \var{sep}:
\bprog
? printsep(":", 1,2,3,4)
1:2:3:4
@eprog
%\syn{NO}
Function: printsep1
Class: basic
Section: programming/specific
C-Name: printsep1
Prototype: vss*
Help: printsep1(sep,{str}*): outputs its string arguments (in raw format),
separated by 'sep', without ending with a newline.
Doc: outputs its (string) arguments in raw format, without ending with a
newline. Successive entries are separated by \var{sep}:
\bprog
? printsep1(":", 1,2,3,4);print("|")
1:2:3:4
@eprog
%\syn{NO}
Function: printtex
Class: basic
Section: programming/specific
C-Name: printtex
Prototype: vs*
Help: printtex({str}*): outputs its string arguments in TeX format.
Doc: outputs its (string) arguments in \TeX\ format. This output can then be
used in a \TeX\ manuscript.
The printing is done on the standard output. If you want to print it to a
file you should use \kbd{writetex} (see there).
Another possibility is to enable the \tet{log} default
(see~\secref{se:defaults}).
You could for instance do:\sidx{logfile}
%
\bprog
default(logfile, "new.tex");
default(log, 1);
printtex(result);
@eprog
%\syn{NO}
Function: prod
Class: basic
Section: sums
C-Name: produit
Prototype: V=GGEDG
Help: prod(X=a,b,expr,{x=1}): x times the product (X runs from a to b) of
expression.
Doc: product of expression
\var{expr}, initialized at $x$, the formal parameter $X$ going from $a$ to
$b$. As for \kbd{sum}, the main purpose of the initialization parameter $x$
is to force the type of the operations being performed. For example if it is
set equal to the integer 1, operations will start being done exactly. If it
is set equal to the real $1.$, they will be done using real numbers having
the default precision. If it is set equal to the power series $1+O(X^k)$ for
a certain $k$, they will be done using power series of precision at most $k$.
These are the three most common initializations.
\noindent As an extreme example, compare
\bprog
? prod(i=1, 100, 1 - X^i); \\@com this has degree $5050$ !!
time = 128 ms.
? prod(i=1, 100, 1 - X^i, 1 + O(X^101))
time = 8 ms.
%2 = 1 - X - X^2 + X^5 + X^7 - X^12 - X^15 + X^22 + X^26 - X^35 - X^40 + \
X^51 + X^57 - X^70 - X^77 + X^92 + X^100 + O(X^101)
@eprog\noindent
Of course, in this specific case, it is faster to use \tet{eta},
which is computed using Euler's formula.
\bprog
? prod(i=1, 1000, 1 - X^i, 1 + O(X^1001));
time = 589 ms.
? \ps1000
seriesprecision = 1000 significant terms
? eta(X) - %
time = 8ms.
%4 = O(X^1001)
@eprog
\synt{produit}{GEN a, GEN b, char *expr, GEN x}.
Function: prodeuler
Class: basic
Section: sums
C-Name: prodeuler0
Prototype: V=GGEp
Help: prodeuler(X=a,b,expr): Euler product (X runs over the primes between a
and b) of real or complex expression.
Doc: product of expression \var{expr},
initialized at 1. (i.e.~to a \emph{real} number equal to 1 to the current
\kbd{realprecision}), the formal parameter $X$ ranging over the prime numbers
between $a$ and $b$.\sidx{Euler product}
\synt{prodeuler}{void *E, GEN (*eval)(void*,GEN), GEN a,GEN b, long prec}.
Function: prodinf
Class: basic
Section: sums
C-Name: prodinf0
Prototype: V=GED0,L,p
Help: prodinf(X=a,expr,{flag=0}): infinite product (X goes from a to
infinity) of real or complex expression. flag can be 0 (default) or 1, in
which case compute the product of the 1+expr instead.
Wrapper: (,G)
Description:
(gen,gen,?small):gen:prec prodinf(${2 cookie}, ${2 wrapper}, $1, $3, $prec)
Doc: \idx{infinite product} of
expression \var{expr}, the formal parameter $X$ starting at $a$. The evaluation
stops when the relative error of the expression minus 1 is less than the
default precision. In particular, non-convergent products result in infinite
loops. The expressions must always evaluate to an element of $\C$.
If $\fl=1$, do the product of the ($1+\var{expr}$) instead.
\synt{prodinf}{void *E, GEN (*eval)(void*,GEN), GEN a, long prec}
($\fl=0$), or \tet{prodinf1} with the same arguments ($\fl=1$).
Function: psdraw
Class: highlevel
Section: graphic
C-Name: postdraw_flag
Prototype: vGD0,L,
Help: psdraw(list, {flag=0}): same as plotdraw, except that the output is a
PostScript program in psfile (pari.ps by default), and flag!=0 scales the
plot from size of the current output device to the standard PostScript
plotting size.
Doc: same as \kbd{plotdraw}, except that the output is a PostScript program
appended to the \kbd{psfile}, and flag!=0 scales the plot from size of the
current output device to the standard PostScript plotting size
Function: psi
Class: basic
Section: transcendental
C-Name: gpsi
Prototype: Gp
Help: psi(x): psi-function at x.
Doc: the $\psi$-function of $x$, i.e.~the logarithmic derivative
$\Gamma'(x)/\Gamma(x)$.
Function: psploth
Class: highlevel
Section: graphic
C-Name: postploth
Prototype: V=GGEpD0,L,D0,L,
Help: psploth(X=a,b,expr,{flags=0},{n=0}): same as ploth, except that the
output is a PostScript program in psfile (pari.ps by default).
Doc: same as \kbd{ploth}, except that the output is a PostScript program
appended to the \kbd{psfile}.
Function: psplothraw
Class: highlevel
Section: graphic
C-Name: postplothraw
Prototype: GGD0,L,
Help: psplothraw(listx,listy,{flag=0}): same as plothraw, except that the
output is a postscript program in psfile (pari.ps by default).
Doc: same as \kbd{plothraw}, except that the output is a PostScript program
appended to the \kbd{psfile}.
Function: qfauto
Class: basic
Section: linear_algebra
C-Name: qfauto0
Prototype: GDG
Help: qfauto(G,{fl}): automorphism group of the positive definite quadratic
form G.
Doc:
$G$ being a square and symmetric matrix with integer entries representing a
positive definite quadratic form, outputs the automorphism group of the
associate lattice.
Since this requires computing the minimal vectors, the computations can
become very lengthy as the dimension grows. $G$ can also be given by an
\kbd{qfisominit} structure.
See \kbd{qfisominit} for the meaning of \var{fl}.
The output is a two-components vector $[o,g]$ where $o$ is the group order
and $g$ is the list of generators (as a vector). For each generator $H$,
the equality $G={^t}H\*G\*H$ holds.
The interface of this function is experimental and will likely change in the
future.
This function implements an algorithm of Plesken and Souvignier, following
Souvignier's implementation.
Variant: The function \fun{GEN}{qfauto}{GEN G, GEN fl} is also available
where $G$ is a vector of \kbd{zm} matrices.
Function: qfautoexport
Class: basic
Section: linear_algebra
C-Name: qfautoexport
Prototype: GD0,L,
Help: qfautoexport(qfa,{flag}): qfa being an automorphism group as output by
qfauto, output a string representing the underlying matrix group in
GAP notation (default) or Magma notation (flag = 1).
Doc: \var{qfa} being an automorphism group as output by
\tet{qfauto}, export the underlying matrix group as a string suitable
for (no flags or $\fl=0$) GAP or ($\fl=1$) Magma. The following example
computes the size of the matrix group using GAP:
\bprog
? G = qfauto([2,1;1,2])
%1 = [12, [[-1, 0; 0, -1], [0, -1; 1, 1], [1, 1; 0, -1]]]
? s = qfautoexport(G)
%2 = "Group([[-1, 0], [0, -1]], [[0, -1], [1, 1]], [[1, 1], [0, -1]])"
? extern("echo \"Order("s");\" | gap -q")
%3 = 12
@eprog
Function: qfbclassno
Class: basic
Section: number_theoretical
C-Name: qfbclassno0
Prototype: GD0,L,
Help: qfbclassno(D,{flag=0}): class number of discriminant D using Shanks's
method by default. If (optional) flag is set to 1, use Euler products.
Doc: ordinary class number of the quadratic order of discriminant $D$, for
``small'' values of $D$.
\item if $D > 0$ or $\fl = 1$, use a $O(|D|^{1/2})$
algorithm (compute $L(1,\chi_D)$ with the approximate functional equation).
This is slower than \tet{quadclassunit} as soon as $|D| \approx 10^2$ or
so and is not meant to be used for large $D$.
\item if $D < 0$ and $\fl = 0$ (or omitted), use a $O(|D|^{1/4})$
algorithm (Shanks's baby-step/giant-step method). It should
be faster than \tet{quadclassunit} for small values of $D$, say
$|D| < 10^{18}$.
\misctitle{Important warning} In the latter case, this function only
implements part of \idx{Shanks}'s method (which allows to speed it up
considerably). It gives unconditionnally correct results for $|D| < 2\cdot
10^{10}$, but may give incorrect results for larger values if the class
group has many cyclic factors. We thus recommend to double-check results
using the function \kbd{quadclassunit}, which is about 2 to 3 times slower in
the above range, assuming GRH. We currently have no counter-examples but
they should exist: we'd appreciate a bug report if you find one.
\misctitle{Warning} Contrary to what its name implies, this routine does not
compute the number of classes of binary primitive forms of discriminant $D$,
which is equal to the \emph{narrow} class number. The two notions are the same
when $D < 0$ or the fundamental unit $\varepsilon$ has negative norm; when $D
> 0$ and $N\varepsilon > 0$, the number of classes of forms is twice the
ordinary class number. This is a problem which we cannot fix for backward
compatibility reasons. Use the following routine if you are only interested
in the number of classes of forms:
\bprog
QFBclassno(D) =
qfbclassno(D) * if (D < 0 || norm(quadunit(D)) < 0, 1, 2)
@eprog\noindent
Here are a few examples:
\bprog
? qfbclassno(400000028)
time = 3,140 ms.
%1 = 1
? quadclassunit(400000028).no
time = 20 ms. \\@com{ much faster}
%2 = 1
? qfbclassno(-400000028)
time = 0 ms.
%3 = 7253 \\@com{ correct, and fast enough}
? quadclassunit(-400000028).no
time = 0 ms.
%4 = 7253
@eprog\noindent
See also \kbd{qfbhclassno}.
Variant: The following functions are also available:
\fun{GEN}{classno}{GEN D} ($\fl = 0$)
\fun{GEN}{classno2}{GEN D} ($\fl = 1$).
\noindent Finally
\fun{GEN}{hclassno}{GEN D} computes the class number of an imaginary
quadratic field by counting reduced forms, an $O(|D|)$ algorithm.
Function: qfbcompraw
Class: basic
Section: number_theoretical
C-Name: qfbcompraw
Prototype: GG
Help: qfbcompraw(x,y): Gaussian composition without reduction of the binary
quadratic forms x and y.
Doc: \idx{composition} of the binary quadratic forms $x$ and $y$, without
\idx{reduction} of the result. This is useful e.g.~to compute a generating
element of an ideal. The result is undefined if $x$ and $y$ do not have the
same discriminant.
Function: qfbhclassno
Class: basic
Section: number_theoretical
C-Name: hclassno
Prototype: G
Help: qfbhclassno(x): Hurwitz-Kronecker class number of x>0.
Doc: \idx{Hurwitz class number} of $x$, where
$x$ is non-negative and congruent to 0 or 3 modulo 4. For $x > 5\cdot
10^5$, we assume the GRH, and use \kbd{quadclassunit} with default
parameters.
Function: qfbil
Class: basic
Section: linear_algebra
C-Name: qfbil
Prototype: GGDG
Help: qfbil(x,y,{q}): this function is obsolete, use qfeval.
Doc: this function is obsolete, use \kbd{qfeval}.
Obsolete: 2016-08-08
Function: qfbnucomp
Class: basic
Section: number_theoretical
C-Name: nucomp
Prototype: GGG
Help: qfbnucomp(x,y,L): composite of primitive positive definite quadratic
forms x and y using nucomp and nudupl, where L=[|D/4|^(1/4)] is precomputed.
Doc: \idx{composition} of the primitive positive
definite binary quadratic forms $x$ and $y$ (type \typ{QFI}) using the NUCOMP
and NUDUPL algorithms of \idx{Shanks}, \`a la Atkin. $L$ is any positive
constant, but for optimal speed, one should take $L=|D/4|^{1/4}$, i.e.
\kbd{sqrtnint(abs(D)>>2,4)}, where $D$ is the common discriminant of $x$ and
$y$. When $x$ and $y$ do not have the same discriminant, the result is
undefined.
The current implementation is slower than the generic routine for small $D$,
and becomes faster when $D$ has about $45$ bits.
Variant: Also available is \fun{GEN}{nudupl}{GEN x, GEN L} when $x=y$.
Function: qfbnupow
Class: basic
Section: number_theoretical
C-Name: nupow
Prototype: GGDG
Help: qfbnupow(x,n,{L}): n-th power of primitive positive definite quadratic
form x using nucomp and nudupl.
Doc: $n$-th power of the primitive positive definite
binary quadratic form $x$ using \idx{Shanks}'s NUCOMP and NUDUPL algorithms;
if set, $L$ should be equal to \kbd{sqrtnint(abs(D)>>2,4)}, where $D < 0$ is
the discriminant of $x$.
The current implementation is slower than the generic routine for small
discriminant $D$, and becomes faster for $D \approx 2^{45}$.
Function: qfbpowraw
Class: basic
Section: number_theoretical
C-Name: qfbpowraw
Prototype: GL
Help: qfbpowraw(x,n): n-th power without reduction of the binary quadratic
form x.
Doc: $n$-th power of the binary quadratic form
$x$, computed without doing any \idx{reduction} (i.e.~using \kbd{qfbcompraw}).
Here $n$ must be non-negative and $n<2^{31}$.
Function: qfbprimeform
Class: basic
Section: number_theoretical
C-Name: primeform
Prototype: GGp
Help: qfbprimeform(x,p): returns the prime form of discriminant x, whose
first coefficient is p.
Doc: prime binary quadratic form of discriminant
$x$ whose first coefficient is $p$, where $|p|$ is a prime number.
By abuse of notation,
$p = \pm 1$ is also valid and returns the unit form. Returns an
error if $x$ is not a quadratic residue mod $p$, or if $x < 0$ and $p < 0$.
(Negative definite \typ{QFI} are not implemented.) In the case where $x>0$,
the ``distance'' component of the form is set equal to zero according to the
current precision.
Function: qfbred
Class: basic
Section: number_theoretical
C-Name: qfbred0
Prototype: GD0,L,DGDGDG
Help: qfbred(x,{flag=0},{d},{isd},{sd}): reduction of the binary
quadratic form x. All other args. are optional. The arguments d, isd and
sd, if
present, supply the values of the discriminant, floor(sqrt(d)) and sqrt(d)
respectively. If d<0, its value is not used and all references to Shanks's
distance hereafter are meaningless. flag can be any of 0: default, uses
Shanks's distance function d; 1: use d, do a single reduction step; 2: do
not use d; 3: do not use d, single reduction step.
Doc: reduces the binary quadratic form $x$ (updating Shanks's distance function
if $x$ is indefinite). The binary digits of $\fl$ are toggles meaning
\quad 1: perform a single \idx{reduction} step
\quad 2: don't update \idx{Shanks}'s distance
The arguments $d$, \var{isd}, \var{sd}, if present, supply the values of the
discriminant, $\floor{\sqrt{d}}$, and $\sqrt{d}$ respectively
(no checking is done of these facts). If $d<0$ these values are useless,
and all references to Shanks's distance are irrelevant.
Variant: Also available are
\fun{GEN}{redimag}{GEN x} (for definite $x$),
\noindent and for indefinite forms:
\fun{GEN}{redreal}{GEN x}
\fun{GEN}{rhoreal}{GEN x} (= \kbd{qfbred(x,1)}),
\fun{GEN}{redrealnod}{GEN x, GEN isd} (= \kbd{qfbred(x,2,,isd)}),
\fun{GEN}{rhorealnod}{GEN x, GEN isd} (= \kbd{qfbred(x,3,,isd)}).
Function: qfbredsl2
Class: basic
Section: number_theoretical
C-Name: qfbredsl2
Prototype: GDG
Help: qfbredsl2(x,{data}): reduction of the binary quadratic form x, return
[y,g] where y is reduced and g in Sl(2,Z) is such that g.x = y; data, if
present, must be equal to [D, sqrtint(D)], where D > 0 is the discriminant
of x.
Doc:
reduction of the (real or imaginary) binary quadratic form $x$, return
$[y,g]$ where $y$ is reduced and $g$ in $\text{SL}(2,\Z)$ is such that
$g \cdot x = y$; \var{data}, if
present, must be equal to $[D, \kbd{sqrtint}(D)]$, where $D > 0$ is the
discriminant of $x$. In case $x$ is \typ{QFR}, the distance component is
unaffected.
Function: qfbsolve
Class: basic
Section: number_theoretical
C-Name: qfbsolve
Prototype: GG
Help: qfbsolve(Q,p): return [x,y] so that Q(x,y)=p where Q is a binary
quadratic form and p a prime number, or 0 if there is no solution.
Doc: Solve the equation $Q(x,y)=p$ over the integers,
where $Q$ is a binary quadratic form and $p$ a prime number.
Return $[x,y]$ as a two-components vector, or zero if there is no solution.
Note that this function returns only one solution and not all the solutions.
Let $D = \disc Q$. The algorithm used runs in probabilistic polynomial time
in $p$ (through the computation of a square root of $D$ modulo $p$); it is
polynomial time in $D$ if $Q$ is imaginary, but exponential time if $Q$ is
real (through the computation of a full cycle of reduced forms). In the
latter case, note that \tet{bnfisprincipal} provides a solution in heuristic
subexponential time in $D$ assuming the GRH.
Function: qfeval
Class: basic
Section: linear_algebra
C-Name: qfeval0
Prototype: DGGDG
Help: qfeval({q},x,{y}): evaluate the binary quadratic form q (symmetric matrix)
at x; if y is present, evaluate the polar form at (x,y);
if q omitted, use the standard Euclidean form.
Doc: evaluate the binary quadratic form $q$ (given by a symmetric matrix)
at the vector $x$; if $y$ is present, evaluate the polar form at $(x,y)$;
if $q$ omitted, use the standard Euclidean scalar product, corresponding to
the identity matrix.
Roughly equivalent to \kbd{x\til * q * y}, but a little faster and
more convenient (does not distinguish between column and row vectors):
\bprog
? x = [1,2,3]~; y = [-1,3,1]~; q = [1,2,3;2,2,-1;3,-1,9];
? qfeval(q,x,y)
%2 = 23
? for(i=1,10^6, qfeval(q,x,y))
time = 661ms
? for(i=1,10^6, x~*q*y)
time = 697ms
@eprog\noindent The speedup is noticeable for the quadratic form,
compared to \kbd{x\til * q * x}, since we save almost half the
operations:
\bprog
? for(i=1,10^6, qfeval(q,x))
time = 487ms
@eprog\noindent The special case $q = \text{Id}$ is handled faster if we
omit $q$ altogether:
\bprog
? qfeval(,x,y)
%1 = 2
? q = matid(#x);
? for(i=1,10^6, qfeval(q,x,y))
time = 529 ms.
? for(i=1,10^6, qfeval(,x,y))
time = 228 ms.
? for(i=1,10^6, x~*y)
time = 274 ms.
@eprog
We also allow \typ{MAT}s of compatible dimensions for $x$,
and return \kbd{x\til * q * x} in this case as well:
\bprog
? M = [1,2,3;4,5,6;7,8,9]; qfeval(,M) \\ Gram matrix
%5 =
[66 78 90]
[78 93 108]
[90 108 126]
? q = [1,2,3;2,2,-1;3,-1,9];
? for(i=1,10^6, qfeval(q,M))
time = 2,008 ms.
? for(i=1,10^6, M~*q*M)
time = 2,368 ms.
? for(i=1,10^6, qfeval(,M))
time = 1,053 ms.
? for(i=1,10^6, M~*M)
time = 1,171 ms.
@eprog
If $q$ is a \typ{QFI} or \typ{QFR}, it is implicitly converted to the
attached symmetric \typ{MAT}. This is done more
efficiently than by direct conversion, since we avoid introducing a
denominator $2$ and rational arithmetic:
\bprog
? q = Qfb(2,3,4); x = [2,3];
? qfeval(q, x)
%2 = 62
? Q = Mat(q)
%3 =
[ 2 3/2]
[3/2 4]
? qfeval(Q, x)
%4 = 62
? for (i=1, 10^6, qfeval(q,x))
time = 758 ms.
? for (i=1, 10^6, qfeval(Q,x))
time = 1,110 ms.
@eprog
Finally, when $x$ is a \typ{MAT} with \emph{integral} coefficients, we allow
a \typ{QFI} or \typ{QFR} for $q$ and return the binary
quadratic form $q \circ M$. Again, the conversion to \typ{MAT} is less
efficient in this case:
\bprog
? q = Qfb(2,3,4); Q = Mat(q); x = [1,2;3,4];
? qfeval(q, x)
%2 = Qfb(47, 134, 96)
? qfeval(Q,x)
%3 =
[47 67]
[67 96]
? for (i=1, 10^6, qfeval(q,x))
time = 701 ms.
? for (i=1, 10^6, qfeval(Q,x))
time = 1,639 ms.
@eprog
Function: qfgaussred
Class: basic
Section: linear_algebra
C-Name: qfgaussred
Prototype: G
Help: qfgaussred(q): square reduction of the (symmetric) matrix q (returns a
square matrix whose i-th diagonal term is the coefficient of the i-th square
in which the coefficient of the i-th variable is 1).
Doc:
\idx{decomposition into squares} of the
quadratic form represented by the symmetric matrix $q$. The result is a
matrix whose diagonal entries are the coefficients of the squares, and the
off-diagonal entries on each line represent the bilinear forms. More
precisely, if $(a_{ij})$ denotes the output, one has
$$ q(x) = \sum_i a_{ii} (x_i + \sum_{j \neq i} a_{ij} x_j)^2 $$
\bprog
? qfgaussred([0,1;1,0])
%1 =
[1/2 1]
[-1 -1/2]
@eprog\noindent This means that $2xy = (1/2)(x+y)^2 - (1/2)(x-y)^2$.
Singular matrices are supported, in which case some diagonal coefficients
will vanish:
\bprog
? qfgaussred([1,1;1,1])
%1 =
[1 1]
[1 0]
@eprog\noindent This means that $x^2 + 2xy + y^2 = (x+y)^2$.
Variant: \fun{GEN}{qfgaussred_positive}{GEN q} assumes that $q$ is
positive definite and is a little faster; returns \kbd{NULL} if a vector
with negative norm occurs (non positive matrix or too many rounding errors).
Function: qfisom
Class: basic
Section: linear_algebra
C-Name: qfisom0
Prototype: GGDG
Help: qfisom(G,H,{fl}): find an isomorphism between the integral positive
definite quadratic forms G and H if it exists. G can also be given by a
qfisominit structure which is preferable if several forms need to be compared
to G.
Doc:
$G$, $H$ being square and symmetric matrices with integer entries representing
positive definite quadratic forms, return an invertible matrix $S$ such that
$G={^t}S\*H\*S$. This defines a isomorphism between the corresponding lattices.
Since this requires computing the minimal vectors, the computations can
become very lengthy as the dimension grows.
See \kbd{qfisominit} for the meaning of \var{fl}.
$G$ can also be given by an \kbd{qfisominit} structure which is preferable if
several forms $H$ need to be compared to $G$.
This function implements an algorithm of Plesken and Souvignier, following
Souvignier's implementation.
Variant: Also available is \fun{GEN}{qfisom}{GEN G, GEN H, GEN fl}
where $G$ is a vector of \kbd{zm}, and $H$ is a \kbd{zm}.
Function: qfisominit
Class: basic
Section: linear_algebra
C-Name: qfisominit0
Prototype: GDGDG
Help: qfisominit(G,{fl},{m}): G being a square and symmetric matrix representing an
integral positive definite quadratic form, this function returns a structure
allowing to compute isomorphisms between G and other quadratic form faster.
Doc:
$G$ being a square and symmetric matrix with integer entries representing a
positive definite quadratic form, return an \kbd{isom} structure allowing to
compute isomorphisms between $G$ and other quadratic forms faster.
The interface of this function is experimental and will likely change in future
release.
If present, the optional parameter \var{fl} must be a \typ{VEC} with two
components. It allows to specify the invariants used, which can make the
computation faster or slower. The components are
\item \kbd{fl[1]} Depth of scalar product combination to use.
\item \kbd{fl[2]} Maximum level of Bacher polynomials to use.
If present, $m$ must be the set of vectors of norm up to the maximal of the
diagonal entry of $G$, either as a matrix or as given by \kbd{qfminim}.
Otherwise this function computes the minimal vectors so it become very
lengthy as the dimension of $G$ grows.
Variant: Also available is
\fun{GEN}{qfisominit}{GEN F, GEN fl}
where $F$ is a vector of \kbd{zm}.
Function: qfjacobi
Class: basic
Section: linear_algebra
C-Name: jacobi
Prototype: Gp
Help: qfjacobi(A): eigenvalues and orthogonal matrix of eigenvectors of the
real symmetric matrix A.
Doc: apply Jacobi's eigenvalue algorithm to the real symmetric matrix $A$.
This returns $[L, V]$, where
\item $L$ is the vector of (real) eigenvalues of $A$, sorted in increasing
order,
\item $V$ is the corresponding orthogonal matrix of eigenvectors of $A$.
\bprog
? \p19
? A = [1,2;2,1]; mateigen(A)
%1 =
[-1 1]
[ 1 1]
? [L, H] = qfjacobi(A);
? L
%3 = [-1.000000000000000000, 3.000000000000000000]~
? H
%4 =
[ 0.7071067811865475245 0.7071067811865475244]
[-0.7071067811865475244 0.7071067811865475245]
? norml2( (A-L[1])*H[,1] ) \\ approximate eigenvector
%5 = 9.403954806578300064 E-38
? norml2(H*H~ - 1)
%6 = 2.350988701644575016 E-38 \\ close to orthogonal
@eprog
Function: qflll
Class: basic
Section: linear_algebra
C-Name: qflll0
Prototype: GD0,L,
Help: qflll(x,{flag=0}): LLL reduction of the vectors forming the matrix x
(gives the unimodular transformation matrix T such that x*T is LLL-reduced). flag is
optional, and can be 0: default, 1: assumes x is integral, 2: assumes x is
integral, returns a partially reduced basis,
4: assumes x is integral, returns [K,T] where K is the integer kernel of x
and T the LLL reduced image, 5: same as 4 but x may have polynomial
coefficients, 8: same as 0 but x may have polynomial coefficients.
Description:
(vec, ?0):vec lll($1)
(vec, 1):vec lllint($1)
(vec, 2):vec lllintpartial($1)
(vec, 4):vec lllkerim($1)
(vec, 5):vec lllkerimgen($1)
(vec, 8):vec lllgen($1)
(vec, #small):vec $"Bad flag in qflll"
(vec, small):vec qflll0($1, $2)
Doc: \idx{LLL} algorithm applied to the
\emph{columns} of the matrix $x$. The columns of $x$ may be linearly
dependent. The result is a unimodular transformation matrix $T$ such that $x
\cdot T$ is an LLL-reduced basis of the lattice generated by the column
vectors of $x$. Note that if $x$ is not of maximal rank $T$ will not be
square. The LLL parameters are $(0.51,0.99)$, meaning that the Gram-Schmidt
coefficients for the final basis satisfy $\mu_{i,j} \leq |0.51|$, and the
Lov\'{a}sz's constant is $0.99$.
If $\fl=0$ (default), assume that $x$ has either exact (integral or
rational) or real floating point entries. The matrix is rescaled, converted
to integers and the behavior is then as in $\fl = 1$.
If $\fl=1$, assume that $x$ is integral. Computations involving Gram-Schmidt
vectors are approximate, with precision varying as needed (Lehmer's trick,
as generalized by Schnorr). Adapted from Nguyen and Stehl\'e's algorithm
and Stehl\'e's code (\kbd{fplll-1.3}).
If $\fl=2$, $x$ should be an integer matrix whose columns are linearly
independent. Returns a partially reduced basis for $x$, using an unpublished
algorithm by Peter Montgomery: a basis is said to be \emph{partially reduced}
if $|v_i \pm v_j| \geq |v_i|$ for any two distinct basis vectors $v_i, \,
v_j$.
This is faster than $\fl=1$, esp. when one row is huge compared
to the other rows (knapsack-style), and should quickly produce relatively
short vectors. The resulting basis is \emph{not} LLL-reduced in general.
If LLL reduction is eventually desired, avoid this partial reduction:
applying LLL to the partially reduced matrix is significantly \emph{slower}
than starting from a knapsack-type lattice.
If $\fl=4$, as $\fl=1$, returning a vector $[K, T]$ of matrices: the
columns of $K$ represent a basis of the integer kernel of $x$
(not LLL-reduced in general) and $T$ is the transformation
matrix such that $x\cdot T$ is an LLL-reduced $\Z$-basis of the image
of the matrix $x$.
If $\fl=5$, case as case $4$, but $x$ may have polynomial coefficients.
If $\fl=8$, same as case $0$, but $x$ may have polynomial coefficients.
Variant: Also available are \fun{GEN}{lll}{GEN x} ($\fl=0$),
\fun{GEN}{lllint}{GEN x} ($\fl=1$), and \fun{GEN}{lllkerim}{GEN x} ($\fl=4$).
Function: qflllgram
Class: basic
Section: linear_algebra
C-Name: qflllgram0
Prototype: GD0,L,
Help: qflllgram(G,{flag=0}): LLL reduction of the lattice whose gram matrix
is G (gives the unimodular transformation matrix). flag is optional and can
be 0: default,1: assumes x is integral, 4: assumes x is integral,
returns [K,T], where K is the integer kernel of x
and T the LLL reduced image, 5: same as 4 but x may have polynomial
coefficients, 8: same as 0 but x may have polynomial coefficients.
Doc: same as \kbd{qflll}, except that the
matrix $G = \kbd{x\til * x}$ is the Gram matrix of some lattice vectors $x$,
and not the coordinates of the vectors themselves. In particular, $G$ must
now be a square symmetric real matrix, corresponding to a positive
quadratic form (not necessarily definite: $x$ needs not have maximal rank).
The result is a unimodular
transformation matrix $T$ such that $x \cdot T$ is an LLL-reduced basis of
the lattice generated by the column vectors of $x$. See \tet{qflll} for
further details about the LLL implementation.
If $\fl=0$ (default), assume that $G$ has either exact (integral or
rational) or real floating point entries. The matrix is rescaled, converted
to integers and the behavior is then as in $\fl = 1$.
If $\fl=1$, assume that $G$ is integral. Computations involving Gram-Schmidt
vectors are approximate, with precision varying as needed (Lehmer's trick,
as generalized by Schnorr). Adapted from Nguyen and Stehl\'e's algorithm
and Stehl\'e's code (\kbd{fplll-1.3}).
$\fl=4$: $G$ has integer entries, gives the kernel and reduced image of $x$.
$\fl=5$: same as $4$, but $G$ may have polynomial coefficients.
Variant: Also available are \fun{GEN}{lllgram}{GEN G} ($\fl=0$),
\fun{GEN}{lllgramint}{GEN G} ($\fl=1$), and \fun{GEN}{lllgramkerim}{GEN G}
($\fl=4$).
Function: qfminim
Class: basic
Section: linear_algebra
C-Name: qfminim0
Prototype: GDGDGD0,L,p
Help: qfminim(x,{b},{m},{flag=0}): x being a square and symmetric
matrix representing a positive definite quadratic form, this function
deals with the vectors of x whose norm is less than or equal to b,
enumerated using the Fincke-Pohst algorithm, storing at most m vectors (no
limit if m is omitted). The function searches for
the minimal non-zero vectors if b is omitted. The precise behavior
depends on flag. 0: returns at most 2m vectors (unless m omitted), returns
[N,M,mat] where N is the number of vectors enumerated, M the maximum norm among
these, and mat lists half the vectors (the other half is given by -mat). 1:
ignores m and returns the first vector whose norm is less than b. 2: as 0
but uses a more robust, slower implementation, valid for non integral
quadratic forms.
Doc: $x$ being a square and symmetric matrix representing a positive definite
quadratic form, this function deals with the vectors of $x$ whose norm is
less than or equal to $b$, enumerated using the Fincke-Pohst algorithm,
storing at most $m$ vectors (no limit if $m$ is omitted). The function
searches for the minimal non-zero vectors if $b$ is omitted. The behavior is
undefined if $x$ is not positive definite (a ``precision too low'' error is
most likely, although more precise error messages are possible). The precise
behavior depends on $\fl$.
If $\fl=0$ (default), returns at most $2m$ vectors. The result is a
three-component vector, the first component being the number of vectors
enumerated (which may be larger than $2m$), the second being the maximum
norm found, and the last vector
is a matrix whose columns are found vectors, only one being given for each
pair $\pm v$ (at most $m$ such pairs, unless $m$ was omitted). The vectors
are returned in no particular order.
If $\fl=1$, ignores $m$ and returns $[N,v]$, where $v$ is a non-zero vector
of length $N \leq b$, or $[]$ if no non-zero vector has length $\leq b$.
If no explicit $b$ is provided, return a vector of smallish norm
(smallest vector in an LLL-reduced basis).
In these two cases, $x$ must have \emph{integral} entries. The
implementation uses low precision floating point computations for maximal
speed, which gives incorrect result when $x$ has large entries. (The
condition is checked in the code and the routine raises an error if
large rounding errors occur.) A more robust, but much slower,
implementation is chosen if the following flag is used:
If $\fl=2$, $x$ can have non integral real entries. In this case, if $b$
is omitted, the ``minimal'' vectors only have approximately the same norm.
If $b$ is omitted, $m$ is an upper bound for the number of vectors that
will be stored and returned, but all minimal vectors are nevertheless
enumerated. If $m$ is omitted, all vectors found are stored and returned;
note that this may be a huge vector!
\bprog
? x = matid(2);
? qfminim(x) \\@com 4 minimal vectors of norm 1: $\pm[0,1]$, $\pm[1,0]$
%2 = [4, 1, [0, 1; 1, 0]]
? { x =
[4, 2, 0, 0, 0,-2, 0, 0, 0, 0, 0, 0, 1,-1, 0, 0, 0, 1, 0,-1, 0, 0, 0,-2;
2, 4,-2,-2, 0,-2, 0, 0, 0, 0, 0, 0, 0,-1, 0, 0, 0, 0, 0,-1, 0, 1,-1,-1;
0,-2, 4, 0,-2, 0, 0, 0, 0, 0, 0, 0,-1, 1, 0, 0, 1, 0, 0, 1,-1,-1, 0, 0;
0,-2, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 1,-1, 0, 0, 0, 1,-1, 0, 1,-1, 1, 0;
0, 0,-2, 0, 4, 0, 0, 0, 1,-1, 0, 0, 1, 0, 0, 0,-2, 0, 0,-1, 1, 1, 0, 0;
-2, -2,0, 0, 0, 4,-2, 0,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0,-1, 1, 1;
0, 0, 0, 0, 0,-2, 4,-2, 0, 0, 0, 0, 0, 1, 0, 0, 0,-1, 0, 0, 0, 1,-1, 0;
0, 0, 0, 0, 0, 0,-2, 4, 0, 0, 0, 0,-1, 0, 0, 0, 0, 0,-1,-1,-1, 0, 1, 0;
0, 0, 0, 0, 1,-1, 0, 0, 4, 0,-2, 0, 1, 1, 0,-1, 0, 1, 0, 0, 0, 0, 0, 0;
0, 0, 0, 0,-1, 0, 0, 0, 0, 4, 0, 0, 1, 1,-1, 1, 0, 0, 0, 1, 0, 0, 1, 0;
0, 0, 0, 0, 0, 0, 0, 0,-2, 0, 4,-2, 0,-1, 0, 0, 0,-1, 0,-1, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-2, 4,-1, 1, 0, 0,-1, 1, 0, 1, 1, 1,-1, 0;
1, 0,-1, 1, 1, 0, 0,-1, 1, 1, 0,-1, 4, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1,-1;
-1,-1, 1,-1, 0, 0, 1, 0, 1, 1,-1, 1, 0, 4, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1;
0, 0, 0, 0, 0, 0, 0, 0, 0,-1, 0, 0, 0, 1, 4, 0, 0, 0, 1, 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0,-1, 1, 0, 0, 1, 1, 0, 4, 0, 0, 0, 0, 1, 1, 0, 0;
0, 0, 1, 0,-2, 0, 0, 0, 0, 0, 0,-1, 0, 0, 0, 0, 4, 1, 1, 1, 0, 0, 1, 1;
1, 0, 0, 1, 0, 0,-1, 0, 1, 0,-1, 1, 1, 0, 0, 0, 1, 4, 0, 1, 1, 0, 1, 0;
0, 0, 0,-1, 0, 1, 0,-1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 4, 0, 1, 1, 0, 1;
-1, -1,1, 0,-1, 1, 0,-1, 0, 1,-1, 1, 0, 1, 0, 0, 1, 1, 0, 4, 0, 0, 1, 1;
0, 0,-1, 1, 1, 0, 0,-1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 4, 1, 0, 1;
0, 1,-1,-1, 1,-1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 4, 0, 1;
0,-1, 0, 1, 0, 1,-1, 1, 0, 1, 0,-1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 4, 1;
-2,-1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,-1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 4]; }
? qfminim(x,,0) \\ the Leech lattice has 196560 minimal vectors of norm 4
time = 648 ms.
%4 = [196560, 4, [;]]
? qfminim(x,,0,2); \\ safe algorithm. Slower and unnecessary here.
time = 18,161 ms.
%5 = [196560, 4.000061035156250000, [;]]
@eprog\noindent\sidx{Leech lattice}\sidx{minimal vector}
In the last example, we store 0 vectors to limit memory use. All minimal
vectors are nevertheless enumerated. Provided \kbd{parisize} is about 50MB,
\kbd{qfminim(x)} succeeds in 2.5 seconds.
Variant: Also available are
\fun{GEN}{minim}{GEN x, GEN b = NULL, GEN m = NULL} ($\fl=0$),
\fun{GEN}{minim2}{GEN x, GEN b = NULL, GEN m = NULL} ($\fl=1$).
\fun{GEN}{minim_raw}{GEN x, GEN b = NULL, GEN m = NULL} (do not perform LLL
reduction on x and return \kbd{NULL} on accuracy error).
Function: qfnorm
Class: basic
Section: linear_algebra
C-Name: qfnorm
Prototype: GDG
Help: qfnorm(x,{q}): this function is obsolete, use qfeval.
Doc: this function is obsolete, use \kbd{qfeval}.
Obsolete: 2016-08-08
Function: qforbits
Class: basic
Section: linear_algebra
C-Name: qforbits
Prototype: GG
Help: qforbits(G,V): return the orbits of V under the action of the group
of linear transformation generated by the set G, which must stabilize V.
Doc: return the orbits of $V$ under the action of the group
of linear transformation generated by the set $G$.
It is assumed that $G$ contains minus identity, and only one vector
in $\{v, -v\}$ should be given.
If $G$ does not stabilize $V$, the function return $0$.
In the example below, we compute representatives and lengths of the orbits of
the vectors of norm $\leq 3$ under the automorphisms of the lattice $A_1^6$.
\bprog
? Q=matid(6); G=qfauto(Q); V=qfminim(Q,3);
? apply(x->[x[1],#x],qforbits(G,V))
%2 = [[[0,0,0,0,0,1]~,6],[[0,0,0,0,1,-1]~,30],[[0,0,0,1,-1,-1]~,80]]
@eprog
Function: qfparam
Class: basic
Section: linear_algebra
C-Name: qfparam
Prototype: GGD0,L,
Help: qfparam(G, sol, {flag = 0}):
coefficients of binary quadratic forms that parametrize the
solutions of the ternary quadratic form G, using the particular
solution sol.
Doc: coefficients of binary quadratic forms that parametrize the
solutions of the ternary quadratic form $G$, using the particular
solution~\var{sol}.
\fl is optional and can be 1, 2, or 3, in which case the \fl-th form is
reduced. The default is \fl=0 (no reduction).
\bprog
? G = [1,0,0;0,1,0;0,0,-34];
? M = qfparam(G, qfsolve(G))
%2 =
[ 3 -10 -3]
[-5 -6 5]
[ 1 0 1]
@eprog
Indeed, the solutions can be parametrized as
$$(3x^2 - 10xy - 3y^2)^2 + (-5x^2 - 6xy + 5y^2)^2 -34(x^2 + y^2)^2 = 0.$$
\bprog
? v = y^2 * M*[1,x/y,(x/y)^2]~
%3 = [3*x^2 - 10*y*x - 3*y^2, -5*x^2 - 6*y*x + 5*y^2, -x^2 - y^2]~
? v~*G*v
%4 = 0
@eprog
Function: qfperfection
Class: basic
Section: linear_algebra
C-Name: perf
Prototype: G
Help: qfperfection(G): rank of matrix of xx~ for x minimal vectors of a gram
matrix G.
Doc:
$G$ being a square and symmetric matrix with
integer entries representing a positive definite quadratic form, outputs the
perfection rank of the form. That is, gives the rank of the family of the $s$
symmetric matrices $v_iv_i^t$, where $s$ is half the number of minimal
vectors and the $v_i$ ($1\le i\le s$) are the minimal vectors.
Since this requires computing the minimal vectors, the computations can
become very lengthy as the dimension of $x$ grows.
Function: qfrep
Class: basic
Section: linear_algebra
C-Name: qfrep0
Prototype: GGD0,L,
Help: qfrep(q,B,{flag=0}): vector of (half) the number of vectors of norms
from 1 to B for the integral and definite quadratic form q. If flag is 1,
count vectors of even norm from 1 to 2B.
Doc:
$q$ being a square and symmetric matrix with integer entries representing a
positive definite quadratic form, count the vectors representing successive
integers.
\item If $\fl = 0$, count all vectors. Outputs the vector whose $i$-th
entry, $1 \leq i \leq B$ is half the number of vectors $v$ such that $q(v)=i$.
\item If $\fl = 1$, count vectors of even norm. Outputs the vector
whose $i$-th entry, $1 \leq i \leq B$ is half the number of vectors such
that $q(v) = 2i$.
\bprog
? q = [2, 1; 1, 3];
? qfrep(q, 5)
%2 = Vecsmall([0, 1, 2, 0, 0]) \\ 1 vector of norm 2, 2 of norm 3, etc.
? qfrep(q, 5, 1)
%3 = Vecsmall([1, 0, 0, 1, 0]) \\ 1 vector of norm 2, 0 of norm 4, etc.
@eprog\noindent
This routine uses a naive algorithm based on \tet{qfminim}, and
will fail if any entry becomes larger than $2^{31}$ (or $2^{63}$).
Function: qfsign
Class: basic
Section: linear_algebra
C-Name: qfsign
Prototype: G
Help: qfsign(x): signature of the symmetric matrix x.
Doc:
returns $[p,m]$ the signature of the quadratic form represented by the
symmetric matrix $x$. Namely, $p$ (resp.~$m$) is the number of positive
(resp.~negative) eigenvalues of $x$. The result is computed using Gaussian
reduction.
Function: qfsolve
Class: basic
Section: linear_algebra
C-Name: qfsolve
Prototype: G
Help: qfsolve(G): solve over Q the quadratic equation X^t G X = 0, where
G is a symmetric matrix.
Doc: Given a square symmetric matrix $G$ of dimension $n \geq 1$, solve over
$\Q$ the quadratic equation $X^tGX = 0$. The matrix $G$ must have rational
coefficients. The solution might be a single non-zero vector (vectorv) or a
matrix (whose columns generate a totally isotropic subspace).
If no solution exists, returns an integer, that can be a prime $p$ such that
there is no local solution at $p$, or $-1$ if there is no real solution,
or $-2$ if $n = 2$ and $-\det G$ is positive but not a square (which implies
there is a real solution, but no local solution at some $p$ dividing $\det G$).
\bprog
? G = [1,0,0;0,1,0;0,0,-34];
? qfsolve(G)
%1 = [-3, -5, 1]~
? qfsolve([1,0; 0,2])
%2 = -1 \\ no real solution
? qfsolve([1,0,0;0,3,0; 0,0,-2])
%3 = 3 \\ no solution in Q_3
? qfsolve([1,0; 0,-2])
%4 = -2 \\ no solution, n = 2
@eprog
Function: quadclassunit
Class: basic
Section: number_theoretical
C-Name: quadclassunit0
Prototype: GD0,L,DGp
Help: quadclassunit(D,{flag=0},{tech=[]}): compute the structure of the
class group and the regulator of the quadratic field of discriminant D.
See manual for the optional technical parameters.
Doc: \idx{Buchmann-McCurley}'s sub-exponential algorithm for computing the
class group of a quadratic order of discriminant $D$.
This function should be used instead of \tet{qfbclassno} or \tet{quadregula}
when $D<-10^{25}$, $D>10^{10}$, or when the \emph{structure} is wanted. It
is a special case of \tet{bnfinit}, which is slower, but more robust.
The result is a vector $v$ whose components should be accessed using member
functions:
\item \kbd{$v$.no}: the class number
\item \kbd{$v$.cyc}: a vector giving the structure of the class group as a
product of cyclic groups;
\item \kbd{$v$.gen}: a vector giving generators of those cyclic groups (as
binary quadratic forms).
\item \kbd{$v$.reg}: the regulator, computed to an accuracy which is the
maximum of an internal accuracy determined by the program and the current
default (note that once the regulator is known to a small accuracy it is
trivial to compute it to very high accuracy, see the tutorial).
The $\fl$ is obsolete and should be left alone. In older versions,
it supposedly computed the narrow class group when $D>0$, but this did not
work at all; use the general function \tet{bnfnarrow}.
Optional parameter \var{tech} is a row vector of the form $[c_1, c_2]$,
where $c_1 \leq c_2$ are non-negative real numbers which control the execution
time and the stack size, see \ref{se:GRHbnf}. The parameter is used as a
threshold to balance the relation finding phase against the final linear
algebra. Increasing the default $c_1$ means that relations are easier
to find, but more relations are needed and the linear algebra will be
harder. The default value for $c_1$ is $0$ and means that it is taken equal
to $c_2$. The parameter $c_2$ is mostly obsolete and should not be changed,
but we still document it for completeness: we compute a tentative class
group by generators and relations using a factorbase of prime ideals
$\leq c_1 (\log |D|)^2$, then prove that ideals of norm
$\leq c_2 (\log |D|)^2$ do
not generate a larger group. By default an optimal $c_2$ is chosen, so that
the result is provably correct under the GRH --- a famous result of Bach
states that $c_2 = 6$ is fine, but it is possible to improve on this
algorithmically. You may provide a smaller $c_2$, it will be ignored
(we use the provably correct
one); you may provide a larger $c_2$ than the default value, which results
in longer computing times for equally correct outputs (under GRH).
Variant: If you really need to experiment with the \var{tech} parameter, it is
usually more convenient to use
\fun{GEN}{Buchquad}{GEN D, double c1, double c2, long prec}
Function: quaddisc
Class: basic
Section: number_theoretical
C-Name: quaddisc
Prototype: G
Help: quaddisc(x): discriminant of the quadratic field Q(sqrt(x)).
Doc: discriminant of the \'etale algebra $\Q(\sqrt{x})$, where $x\in\Q^*$.
This is the same as \kbd{coredisc}$(d)$ where $d$ is the integer square-free
part of $x$, so x=$d f^2$ with $f\in \Q^*$ and $d\in\Z$.
This returns $0$ for $x = 0$, $1$ for $x$ square and the discriminant of the
quadratic field $\Q(\sqrt{x})$ otherwise.
\bprog
? quaddisc(7)
%1 = 28
? quaddisc(-7)
%2 = -7
@eprog
Function: quadgen
Class: basic
Section: number_theoretical
C-Name: quadgen
Prototype: G
Help: quadgen(D): standard generator of quadratic order of discriminant D.
Doc: creates the quadratic
number\sidx{omega} $\omega=(a+\sqrt{D})/2$ where $a=0$ if $D\equiv0\mod4$,
$a=1$ if $D\equiv1\mod4$, so that $(1,\omega)$ is an integral basis for the
quadratic order of discriminant $D$. $D$ must be an integer congruent to 0 or
1 modulo 4, which is not a square.
Function: quadhilbert
Class: basic
Section: number_theoretical
C-Name: quadhilbert
Prototype: Gp
Help: quadhilbert(D): relative equation for the Hilbert class field
of the quadratic field of discriminant D (which can also be a bnf).
Doc: relative equation defining the
\idx{Hilbert class field} of the quadratic field of discriminant $D$.
If $D < 0$, uses complex multiplication (\idx{Schertz}'s variant).
If $D > 0$ \idx{Stark units} are used and (in rare cases) a
vector of extensions may be returned whose compositum is the requested class
field. See \kbd{bnrstark} for details.
Function: quadpoly
Class: basic
Section: number_theoretical
C-Name: quadpoly0
Prototype: GDn
Help: quadpoly(D,{v='x}): quadratic polynomial corresponding to the
discriminant D, in variable v.
Doc: creates the ``canonical'' quadratic
polynomial (in the variable $v$) corresponding to the discriminant $D$,
i.e.~the minimal polynomial of $\kbd{quadgen}(D)$. $D$ must be an integer
congruent to 0 or 1 modulo 4, which is not a square.
Function: quadray
Class: basic
Section: number_theoretical
C-Name: quadray
Prototype: GGp
Help: quadray(D,f): relative equation for the ray class field of
conductor f for the quadratic field of discriminant D (which can also be a
bnf).
Doc: relative equation for the ray
class field of conductor $f$ for the quadratic field of discriminant $D$
using analytic methods. A \kbd{bnf} for $x^2 - D$ is also accepted in place
of $D$.
For $D < 0$, uses the $\sigma$ function and Schertz's method.
For $D>0$, uses Stark's conjecture, and a vector of relative equations may be
returned. See \tet{bnrstark} for more details.
Function: quadregulator
Class: basic
Section: number_theoretical
C-Name: quadregulator
Prototype: Gp
Help: quadregulator(x): regulator of the real quadratic field of
discriminant x.
Doc: regulator of the quadratic field of positive discriminant $x$. Returns
an error if $x$ is not a discriminant (fundamental or not) or if $x$ is a
square. See also \kbd{quadclassunit} if $x$ is large.
Function: quadunit
Class: basic
Section: number_theoretical
C-Name: quadunit
Prototype: G
Help: quadunit(D): fundamental unit of the quadratic field of discriminant D
where D must be positive.
Doc: fundamental unit\sidx{fundamental units} of the
real quadratic field $\Q(\sqrt D)$ where $D$ is the positive discriminant
of the field. If $D$ is not a fundamental discriminant, this probably gives
the fundamental unit of the corresponding order. $D$ must be an integer
congruent to 0 or 1 modulo 4, which is not a square; the result is a
quadratic number (see \secref{se:quadgen}).
Function: quit
Class: gp
Section: programming/specific
C-Name: gp_quit
Prototype: vD0,L,
Help: quit({status = 0}): quit, return to the system with exit status
'status'.
Doc: exits \kbd{gp} and return to the system with exit status
\kbd{status}, a small integer. A non-zero exit status normally indicates
abnormal termination. (Note: the system actually sees only
\kbd{status} mod $256$, see your man pages for \kbd{exit(3)} or \kbd{wait(2)}).
Function: ramanujantau
Class: basic
Section: number_theoretical
C-Name: ramanujantau
Prototype: G
Help: ramanujantau(n): compute the value of Ramanujan's tau function at n,
assuming the GRH. Algorithm in O(n^{1/2+eps}).
Doc: compute the value of Ramanujan's tau function at an individual $n$,
assuming the truth of the GRH (to compute quickly class numbers of imaginary
quadratic fields using \tet{quadclassunit}).
Algorithm in $\tilde{O}(n^{1/2})$ using $O(\log n)$ space. If all values up
to $N$ are required, then
$$\sum \tau(n)q^n = q \prod_{n\geq 1} (1-q^n)^{24}$$
will produce them in time $\tilde{O}(N)$, against $\tilde{O}(N^{3/2})$ for
individual calls to \kbd{ramanujantau}; of course the space complexity then
becomes $\tilde{O}(N)$.
\bprog
? tauvec(N) = Vec(q*eta(q + O(q^N))^24);
? N = 10^4; v = tauvec(N);
time = 26 ms.
? ramanujantau(N)
%3 = -482606811957501440000
? w = vector(N, n, ramanujantau(n)); \\ much slower !
time = 13,190 ms.
? v == w
%4 = 1
@eprog
Function: random
Class: basic
Section: conversions
C-Name: genrand
Prototype: DG
Help: random({N=2^31}): random object, depending on the type of N.
Integer between 0 and N-1 (t_INT), int mod N (t_INTMOD), element in a finite
field (t_FFELT), point on an elliptic curve (ellinit mod p or over a finite
field).
Description:
(?int):int genrand($1)
(gen):gen genrand($1)
Doc:
returns a random element in various natural sets depending on the
argument $N$.
\item \typ{INT}: returns an integer
uniformly distributed between $0$ and $N-1$. Omitting the argument
is equivalent to \kbd{random(2\pow31)}.
\item \typ{REAL}: returns a real number in $[0,1[$ with the same accuracy as
$N$ (whose mantissa has the same number of significant words).
\item \typ{INTMOD}: returns a random intmod for the same modulus.
\item \typ{FFELT}: returns a random element in the same finite field.
\item \typ{VEC} of length $2$, $N = [a,b]$: returns an integer uniformly
distributed between $a$ and $b$.
\item \typ{VEC} generated by \kbd{ellinit} over a finite field $k$
(coefficients are \typ{INTMOD}s modulo a prime or \typ{FFELT}s): returns a
``random'' $k$-rational \emph{affine} point on the curve. More precisely
if the curve has a single point (at infinity!) we return it; otherwise
we return an affine point by drawing an abscissa uniformly at
random until \tet{ellordinate} succeeds. Note that this is definitely not a
uniform distribution over $E(k)$, but it should be good enough for
applications.
\item \typ{POL} return a random polynomial of degree at most the degree of $N$.
The coefficients are drawn by applying \kbd{random} to the leading
coefficient of $N$.
\bprog
? random(10)
%1 = 9
? random(Mod(0,7))
%2 = Mod(1, 7)
? a = ffgen(ffinit(3,7), 'a); random(a)
%3 = a^6 + 2*a^5 + a^4 + a^3 + a^2 + 2*a
? E = ellinit([3,7]*Mod(1,109)); random(E)
%4 = [Mod(103, 109), Mod(10, 109)]
? E = ellinit([1,7]*a^0); random(E)
%5 = [a^6 + a^5 + 2*a^4 + 2*a^2, 2*a^6 + 2*a^4 + 2*a^3 + a^2 + 2*a]
? random(Mod(1,7)*x^4)
%6 = Mod(5, 7)*x^4 + Mod(6, 7)*x^3 + Mod(2, 7)*x^2 + Mod(2, 7)*x + Mod(5, 7)
@eprog
These variants all depend on a single internal generator, and are
independent from your operating system's random number generators.
A random seed may be obtained via \tet{getrand}, and reset
using \tet{setrand}: from a given seed, and given sequence of \kbd{random}s,
the exact same values will be generated. The same seed is used at each
startup, reseed the generator yourself if this is a problem. Note that
internal functions also call the random number generator; adding such a
function call in the middle of your code will change the numbers produced.
\misctitle{Technical note}
Up to
version 2.4 included, the internal generator produced pseudo-random numbers
by means of linear congruences, which were not well distributed in arithmetic
progressions. We now
use Brent's XORGEN algorithm, based on Feedback Shift Registers, see
\url{http://wwwmaths.anu.edu.au/~brent/random.html}. The generator has period
$2^{4096}-1$, passes the Crush battery of statistical tests of L'Ecuyer and
Simard, but is not suitable for cryptographic purposes: one can reconstruct
the state vector from a small sample of consecutive values, thus predicting
the entire sequence.
Variant:
Also available: \fun{GEN}{ellrandom}{GEN E} and \fun{GEN}{ffrandom}{GEN a}.
Function: randomprime
Class: basic
Section: number_theoretical
C-Name: randomprime
Prototype: DG
Help: randomprime({N = 2^31}): returns a strong pseudo prime in [2, N-1].
Doc: returns a strong pseudo prime (see \tet{ispseudoprime}) in $[2,N-1]$.
A \typ{VEC} $N = [a,b]$ is also allowed, with $a \leq b$ in which case a
pseudo prime $a \leq p \leq b$ is returned; if no prime exists in the
interval, the function will run into an infinite loop. If the upper bound
is less than $2^{64}$ the pseudo prime returned is a proven prime.
Function: read
Class: basic
Section: programming/specific
C-Name: gp_read_file
Prototype: D"",s,
Help: read({filename}): read from the input file filename. If filename is
omitted, reread last input file, be it from read() or \r.
Description:
(str):gen gp_read_file($1)
Doc: reads in the file
\var{filename} (subject to string expansion). If \var{filename} is
omitted, re-reads the last file that was fed into \kbd{gp}. The return
value is the result of the last expression evaluated.
If a GP \tet{binary file} is read using this command (see
\secref{se:writebin}), the file is loaded and the last object in the file
is returned.
In case the file you read in contains an \tet{allocatemem} statement (to be
generally avoided), you should leave \kbd{read} instructions by themselves,
and not part of larger instruction sequences.
Function: readstr
Class: basic
Section: programming/specific
C-Name: readstr
Prototype: D"",s,
Help: readstr({filename}): returns the vector of GP strings containing
the lines in filename.
Doc: Reads in the file \var{filename} and return a vector of GP strings,
each component containing one line from the file. If \var{filename} is
omitted, re-reads the last file that was fed into \kbd{gp}.
Function: readvec
Class: basic
Section: programming/specific
C-Name: gp_readvec_file
Prototype: D"",s,
Help: readvec({filename}): create a vector whose components are the evaluation
of all the expressions found in the input file filename.
Description:
(str):gen gp_readvec_file($1)
Doc: reads in the file
\var{filename} (subject to string expansion). If \var{filename} is
omitted, re-reads the last file that was fed into \kbd{gp}. The return
value is a vector whose components are the evaluation of all sequences
of instructions contained in the file. For instance, if \var{file} contains
\bprog
1
2
3
@eprog\noindent
then we will get:
\bprog
? \r a
%1 = 1
%2 = 2
%3 = 3
? read(a)
%4 = 3
? readvec(a)
%5 = [1, 2, 3]
@eprog
In general a sequence is just a single line, but as usual braces and
\kbd{\bs} may be used to enter multiline sequences.
Variant: The underlying library function
\fun{GEN}{gp_readvec_stream}{FILE *f} is usually more flexible.
Function: real
Class: basic
Section: conversions
C-Name: greal
Prototype: G
Help: real(x): real part of x.
Doc: real part of $x$. In the case where $x$ is a quadratic number, this is the
coefficient of $1$ in the ``canonical'' integral basis $(1,\omega)$.
Function: removeprimes
Class: basic
Section: number_theoretical
C-Name: removeprimes
Prototype: DG
Help: removeprimes({x=[]}): remove primes in the vector x from the prime table.
x can also be a single integer. List the current extra primes if x is omitted.
Doc: removes the primes listed in $x$ from
the prime number table. In particular \kbd{removeprimes(addprimes())} empties
the extra prime table. $x$ can also be a single integer. List the current
extra primes if $x$ is omitted.
Function: return
Class: basic
Section: programming/control
C-Name: return0
Prototype: DG
Help: return({x=0}): return from current subroutine with result x.
Doc: returns from current subroutine, with
result $x$. If $x$ is omitted, return the \kbd{(void)} value (return no
result, like \kbd{print}).
Function: rnfalgtobasis
Class: basic
Section: number_fields
C-Name: rnfalgtobasis
Prototype: GG
Help: rnfalgtobasis(rnf,x): relative version of nfalgtobasis, where rnf is a
relative numberfield.
Doc: expresses $x$ on the relative
integral basis. Here, $\var{rnf}$ is a relative number field extension $L/K$
as output by \kbd{rnfinit}, and $x$ an element of $L$ in absolute form, i.e.
expressed as a polynomial or polmod with polmod coefficients, \emph{not} on
the relative integral basis.
Function: rnfbasis
Class: basic
Section: number_fields
C-Name: rnfbasis
Prototype: GG
Help: rnfbasis(bnf,M): given a projective Z_K-module M as output by
rnfpseudobasis or rnfsteinitz, gives either a basis of M if it is free, or an
n+1-element generating set.
Doc: let $K$ the field represented by
\var{bnf}, as output by \kbd{bnfinit}. $M$ is a projective $\Z_K$-module
of rank $n$ ($M\otimes K$ is an $n$-dimensional $K$-vector space), given by a
pseudo-basis of size $n$. The routine returns either a true $\Z_K$-basis of
$M$ (of size $n$) if it exists, or an $n+1$-element generating set of $M$ if
not.
It is allowed to use an irreducible polynomial $P$ in $K[X]$ instead of $M$,
in which case, $M$ is defined as the ring of integers of $K[X]/(P)$, viewed
as a $\Z_K$-module.
Function: rnfbasistoalg
Class: basic
Section: number_fields
C-Name: rnfbasistoalg
Prototype: GG
Help: rnfbasistoalg(rnf,x): relative version of nfbasistoalg, where rnf is a
relative numberfield.
Doc: computes the representation of $x$
as a polmod with polmods coefficients. Here, $\var{rnf}$ is a relative number
field extension $L/K$ as output by \kbd{rnfinit}, and $x$ an element of
$L$ expressed on the relative integral basis.
Function: rnfcharpoly
Class: basic
Section: number_fields
C-Name: rnfcharpoly
Prototype: GGGDn
Help: rnfcharpoly(nf,T,a,{var='x}): characteristic polynomial of a
over nf, where a belongs to the algebra defined by T over nf. Returns a
polynomial in variable var (x by default).
Doc: characteristic polynomial of
$a$ over $\var{nf}$, where $a$ belongs to the algebra defined by $T$ over
$\var{nf}$, i.e.~$\var{nf}[X]/(T)$. Returns a polynomial in variable $v$
($x$ by default).
\bprog
? nf = nfinit(y^2+1);
? rnfcharpoly(nf, x^2+y*x+1, x+y)
%2 = x^2 + Mod(-y, y^2 + 1)*x + 1
@eprog
Function: rnfconductor
Class: basic
Section: number_fields
C-Name: rnfconductor
Prototype: GG
Help: rnfconductor(bnf,pol): conductor of the Abelian extension
of bnf defined by pol. The result is [conductor,bnr,subgroup],
where conductor is the conductor itself, bnr the attached bnr
structure, and subgroup the HNF defining the norm
group (Artin or Takagi group) on the given generators bnr.gen.
Doc: given $\var{bnf}$
as output by \kbd{bnfinit}, and \var{pol} a relative polynomial defining an
\idx{Abelian extension}, computes the class field theory conductor of this
Abelian extension. The result is a 3-component vector
$[\var{conductor},\var{bnr},\var{subgroup}]$, where \var{conductor} is
the conductor of the extension given as a 2-component row vector
$[f_0,f_\infty]$, \var{bnr} is the attached \kbd{bnr} structure
and \var{subgroup} is a matrix in HNF defining the subgroup of the ray class
group on \kbd{bnr.gen}.
Function: rnfdedekind
Class: basic
Section: number_fields
C-Name: rnfdedekind
Prototype: GGDGD0,L,
Help: rnfdedekind(nf,pol,{pr},{flag=0}): relative Dedekind criterion over the
number field K, represented by nf, applied to the order O_K[X]/(P),
modulo the prime ideal pr (at all primes if pr omitted, in which case
flag is automatically set to 1).
P is assumed to be monic, irreducible, in O_K[X].
Returns [max,basis,v], where basis is a pseudo-basis of the
enlarged order, max is 1 iff this order is pr-maximal, and v is the
valuation at pr of the order discriminant. If flag is set, just return 1 if
the order is maximal, and 0 if not.
Doc: given a number field $K$ coded by $\var{nf}$ and a monic
polynomial $P\in \Z_K[X]$, irreducible over $K$ and thus defining a relative
extension $L$ of $K$, applies \idx{Dedekind}'s criterion to the order
$\Z_K[X]/(P)$, at the prime ideal \var{pr}. It is possible to set \var{pr}
to a vector of prime ideals (test maximality at all primes in the vector),
or to omit altogether, in which case maximality at \emph{all} primes is tested;
in this situation \fl\ is automatically set to $1$.
The default historic behavior (\fl\ is 0 or omitted and \var{pr} is a
single prime ideal) is not so useful since
\kbd{rnfpseudobasis} gives more information and is generally not that
much slower. It returns a 3-component vector $[\var{max}, \var{basis}, v]$:
\item \var{basis} is a pseudo-basis of an enlarged order $O$ produced by
Dedekind's criterion, containing the original order $\Z_K[X]/(P)$
with index a power of \var{pr}. Possibly equal to the original order.
\item \var{max} is a flag equal to 1 if the enlarged order $O$
could be proven to be \var{pr}-maximal and to 0 otherwise; it may still be
maximal in the latter case if \var{pr} is ramified in $L$,
\item $v$ is the valuation at \var{pr} of the order discriminant.
If \fl\ is non-zero, on the other hand, we just return $1$ if the order
$\Z_K[X]/(P)$ is \var{pr}-maximal (resp.~maximal at all relevant primes, as
described above), and $0$ if not. This is much faster than the default,
since the enlarged order is not computed.
\bprog
? nf = nfinit(y^2-3); P = x^3 - 2*y;
? pr3 = idealprimedec(nf,3)[1];
? rnfdedekind(nf, P, pr3)
%3 = [1, [[1, 0, 0; 0, 1, 0; 0, 0, 1], [1, 1, 1]], 8]
? rnfdedekind(nf, P, pr3, 1)
%4 = 1
@eprog\noindent In this example, \kbd{pr3} is the ramified ideal above $3$,
and the order generated by the cube roots of $y$ is already
\kbd{pr3}-maximal. The order-discriminant has valuation $8$. On the other
hand, the order is not maximal at the prime above 2:
\bprog
? pr2 = idealprimedec(nf,2)[1];
? rnfdedekind(nf, P, pr2, 1)
%6 = 0
? rnfdedekind(nf, P, pr2)
%7 = [0, [[2, 0, 0; 0, 1, 0; 0, 0, 1], [[1, 0; 0, 1], [1, 0; 0, 1],
[1, 1/2; 0, 1/2]]], 2]
@eprog
The enlarged order is not proven to be \kbd{pr2}-maximal yet. In fact, it
is; it is in fact the maximal order:
\bprog
? B = rnfpseudobasis(nf, P)
%8 = [[1, 0, 0; 0, 1, 0; 0, 0, 1], [1, 1, [1, 1/2; 0, 1/2]],
[162, 0; 0, 162], -1]
? idealval(nf,B[3], pr2)
%9 = 2
@eprog\noindent
It is possible to use this routine with non-monic
$P = \sum_{i\leq n} a_i X^i \in \Z_K[X]$ if $\fl = 1$;
in this case, we test maximality of Dedekind's order generated by
$$1, a_n \alpha, a_n\alpha^2 + a_{n-1}\alpha, \dots,
a_n\alpha^{n-1} + a_{n-1}\alpha^{n-2} + \cdots + a_1\alpha.$$
The routine will fail if $P$ is $0$ on the projective line over the residue
field $\Z_K/\kbd{pr}$ (FIXME).
Function: rnfdet
Class: basic
Section: number_fields
C-Name: rnfdet
Prototype: GG
Help: rnfdet(nf,M): given a pseudo-matrix M, compute its determinant.
Doc: given a pseudo-matrix $M$ over the maximal
order of $\var{nf}$, computes its determinant.
Function: rnfdisc
Class: basic
Section: number_fields
C-Name: rnfdiscf
Prototype: GG
Help: rnfdisc(nf,pol): given a pol with coefficients in nf, gives a
2-component vector [D,d], where D is the relative ideal discriminant, and d
is the relative discriminant in nf^*/nf*^2.
Doc: given a number field $\var{nf}$ as
output by \kbd{nfinit} and a polynomial \var{pol} with coefficients in
$\var{nf}$ defining a relative extension $L$ of $\var{nf}$, computes the
relative discriminant of $L$. This is a two-element row vector $[D,d]$, where
$D$ is the relative ideal discriminant and $d$ is the relative discriminant
considered as an element of $\var{nf}^*/{\var{nf}^*}^2$. The main variable of
$\var{nf}$ \emph{must} be of lower priority than that of \var{pol}, see
\secref{se:priority}.
Function: rnfeltabstorel
Class: basic
Section: number_fields
C-Name: rnfeltabstorel
Prototype: GG
Help: rnfeltabstorel(rnf,x): transforms the element x from absolute to
relative representation.
Doc: Let $\var{rnf}$ be a relative
number field extension $L/K$ as output by \kbd{rnfinit} and let $x$ be an
element of $L$ expressed as a polynomial modulo the absolute equation
\kbd{\var{rnf}.pol}, or in terms of the absolute $\Z$-basis for $\Z_L$
if \var{rnf} contains one (as in \kbd{rnfinit(nf,pol,1)}, or after
a call to \kbd{nfinit(rnf)}).
Computes $x$ as an element of the relative extension
$L/K$ as a polmod with polmod coefficients.
\bprog
? K = nfinit(y^2+1); L = rnfinit(K, x^2-y);
? L.polabs
%2 = x^4 + 1
? rnfeltabstorel(L, Mod(x, L.polabs))
%3 = Mod(x, x^2 + Mod(-y, y^2 + 1))
? rnfeltabstorel(L, 1/3)
%4 = 1/3
? rnfeltabstorel(L, Mod(x, x^2-y))
%5 = Mod(x, x^2 + Mod(-y, y^2 + 1))
? rnfeltabstorel(L, [0,0,0,1]~) \\ Z_L not initialized yet
*** at top-level: rnfeltabstorel(L,[0,
*** ^--------------------
*** rnfeltabstorel: incorrect type in rnfeltabstorel, apply nfinit(rnf).
? nfinit(L); \\ initialize now
? rnfeltabstorel(L, [0,0,0,1]~)
%6 = Mod(Mod(y, y^2 + 1)*x, x^2 + Mod(-y, y^2 + 1))
@eprog
Function: rnfeltdown
Class: basic
Section: number_fields
C-Name: rnfeltdown0
Prototype: GGD0,L,
Help: rnfeltdown(rnf,x,{flag=0}): expresses x on the base field if possible;
returns an error otherwise.
Doc: $\var{rnf}$ being a relative number
field extension $L/K$ as output by \kbd{rnfinit} and $x$ being an element of
$L$ expressed as a polynomial or polmod with polmod coefficients (or as a
\typ{COL} on \kbd{nfinit(rnf).zk}), computes
$x$ as an element of $K$ as a \typ{POLMOD} if $\fl = 0$ and as a \typ{COL}
otherwise. If $x$ is not in $K$, a domain error occurs.
\bprog
? K = nfinit(y^2+1); L = rnfinit(K, x^2-y);
? L.pol
%2 = x^4 + 1
? rnfeltdown(L, Mod(x^2, L.pol))
%3 = Mod(y, y^2 + 1)
? rnfeltdown(L, Mod(x^2, L.pol), 1)
%4 = [0, 1]~
? rnfeltdown(L, Mod(y, x^2-y))
%5 = Mod(y, y^2 + 1)
? rnfeltdown(L, Mod(y,K.pol))
%6 = Mod(y, y^2 + 1)
? rnfeltdown(L, Mod(x, L.pol))
*** at top-level: rnfeltdown(L,Mod(x,x
*** ^--------------------
*** rnfeltdown: domain error in rnfeltdown: element not in the base field
? rnfeltdown(L, Mod(y, x^2-y), 1) \\ as a t_COL
%7 = [0, 1]~
? rnfeltdown(L, [0,1,0,0]~) \\ not allowed without absolute nf struct
*** rnfeltdown: incorrect type in rnfeltdown (t_COL).
? nfinit(L); \\ add absolute nf structure to L
? rnfeltdown(L, [0,1,0,0]~) \\ now OK
%8 = Mod(y, y^2 + 1)
@eprog\noindent If we had started with
\kbd{L = rnfinit(K, x\pow2-y, 1)}, then the final would have worked directly.
Variant: Also available is
\fun{GEN}{rnfeltdown}{GEN rnf, GEN x} ($\fl = 0$).
Function: rnfeltnorm
Class: basic
Section: number_fields
C-Name: rnfeltnorm
Prototype: GG
Help: rnfeltnorm(rnf,x): returns the relative norm N_{L/K}(x), as an element
of K.
Doc: $\var{rnf}$ being a relative number field extension $L/K$ as output by
\kbd{rnfinit} and $x$ being an element of $L$, returns the relative norm
$N_{L/K}(x)$ as an element of $K$.
\bprog
? K = nfinit(y^2+1); L = rnfinit(K, x^2-y);
? rnfeltnorm(L, Mod(x, L.pol))
%2 = Mod(x, x^2 + Mod(-y, y^2 + 1))
? rnfeltnorm(L, 2)
%3 = 4
? rnfeltnorm(L, Mod(x, x^2-y))
@eprog
Function: rnfeltreltoabs
Class: basic
Section: number_fields
C-Name: rnfeltreltoabs
Prototype: GG
Help: rnfeltreltoabs(rnf,x): transforms the element x from relative to
absolute representation.
Doc: $\var{rnf}$ being a relative
number field extension $L/K$ as output by \kbd{rnfinit} and $x$ being an
element of $L$ expressed as a polynomial or polmod with polmod
coefficients, computes $x$ as an element of the absolute extension $L/\Q$ as
a polynomial modulo the absolute equation \kbd{\var{rnf}.pol}.
\bprog
? K = nfinit(y^2+1); L = rnfinit(K, x^2-y);
? L.pol
%2 = x^4 + 1
? rnfeltreltoabs(L, Mod(x, L.pol))
%3 = Mod(x, x^4 + 1)
? rnfeltreltoabs(L, Mod(y, x^2-y))
%4 = Mod(x^2, x^4 + 1)
? rnfeltreltoabs(L, Mod(y,K.pol))
%5 = Mod(x^2, x^4 + 1)
@eprog
Function: rnfelttrace
Class: basic
Section: number_fields
C-Name: rnfelttrace
Prototype: GG
Help: rnfelttrace(rnf,x): returns the relative trace Tr_{L/K}(x), as an element
of K.
Doc: $\var{rnf}$ being a relative number field extension $L/K$ as output by
\kbd{rnfinit} and $x$ being an element of $L$, returns the relative trace
$Tr_{L/K}(x)$ as an element of $K$.
\bprog
? K = nfinit(y^2+1); L = rnfinit(K, x^2-y);
? rnfelttrace(L, Mod(x, L.pol))
%2 = 0
? rnfelttrace(L, 2)
%3 = 4
? rnfelttrace(L, Mod(x, x^2-y))
@eprog
Function: rnfeltup
Class: basic
Section: number_fields
C-Name: rnfeltup0
Prototype: GGD0,L,
Help: rnfeltup(rnf,x,{flag=0}): expresses x (belonging to the base field) on
the relative field. As a t_POLMOD if flag = 0 and as a t_COL on the absolute
field integer basis if flag = 1.
Doc: $\var{rnf}$ being a relative number field extension $L/K$ as output by
\kbd{rnfinit} and $x$ being an element of $K$, computes $x$ as an element of
the absolute extension $L/\Q$. As a \typ{POLMOD} modulo \kbd{\var{rnf}.pol}
if $\fl = 0$ and as a \typ{COL} on the absolute field integer basis if
$\fl = 1$.
\bprog
? K = nfinit(y^2+1); L = rnfinit(K, x^2-y);
? L.pol
%2 = x^4 + 1
? rnfeltup(L, Mod(y, K.pol))
%3 = Mod(x^2, x^4 + 1)
? rnfeltup(L, y)
%4 = Mod(x^2, x^4 + 1)
? rnfeltup(L, [1,2]~) \\ in terms of K.zk
%5 = Mod(2*x^2 + 1, x^4 + 1)
? rnfeltup(L, y, 1) \\ in terms of nfinit(L).zk
%6 = [0, 1, 0, 0]~
? rnfeltup(L, [1,2]~, 1)
%7 = [1, 2, 0, 0]~
@eprog
Function: rnfequation
Class: basic
Section: number_fields
C-Name: rnfequation0
Prototype: GGD0,L,
Help: rnfequation(nf,pol,{flag=0}): given a pol with coefficients in nf,
gives an absolute equation z of the number field defined by pol. flag is
optional, and can be 0: default, or non-zero, gives [z,al,k], where
z defines the absolute equation L/Q as in the default behavior,
al expresses as an element of L a root of the polynomial
defining the base field nf, and k is a small integer such that
t = b + k al is a root of z, for b a root of pol.
Doc: given a number field
$\var{nf}$ as output by \kbd{nfinit} (or simply a polynomial) and a
polynomial \var{pol} with coefficients in $\var{nf}$ defining a relative
extension $L$ of $\var{nf}$, computes an absolute equation of $L$ over
$\Q$.
The main variable of $\var{nf}$ \emph{must} be of lower priority than that
of \var{pol} (see \secref{se:priority}). Note that for efficiency, this does
not check whether the relative equation is irreducible over $\var{nf}$, but
only if it is squarefree. If it is reducible but squarefree, the result will
be the absolute equation of the \'etale algebra defined by \var{pol}. If
\var{pol} is not squarefree, raise an \kbd{e\_DOMAIN} exception.
\bprog
? rnfequation(y^2+1, x^2 - y)
%1 = x^4 + 1
? T = y^3-2; rnfequation(nfinit(T), (x^3-2)/(x-Mod(y,T)))
%2 = x^6 + 108 \\ Galois closure of Q(2^(1/3))
@eprog
If $\fl$ is non-zero, outputs a 3-component row vector $[z,a,k]$, where
\item $z$ is the absolute equation of $L$ over $\Q$, as in the default
behavior,
\item $a$ expresses as a \typ{POLMOD} modulo $z$ a root $\alpha$ of the
polynomial defining the base field $\var{nf}$,
\item $k$ is a small integer such that $\theta = \beta+k\alpha$
is a root of $z$, where $\beta$ is a root of $\var{pol}$.
\bprog
? T = y^3-2; pol = x^2 +x*y + y^2;
? [z,a,k] = rnfequation(T, pol, 1);
? z
%3 = x^6 + 108
? subst(T, y, a)
%4 = 0
? alpha= Mod(y, T);
? beta = Mod(x*Mod(1,T), pol);
? subst(z, x, beta + k*alpha)
%7 = 0
@eprog
Variant: Also available are
\fun{GEN}{rnfequation}{GEN nf, GEN pol} ($\fl = 0$) and
\fun{GEN}{rnfequation2}{GEN nf, GEN pol} ($\fl = 1$).
Function: rnfhnfbasis
Class: basic
Section: number_fields
C-Name: rnfhnfbasis
Prototype: GG
Help: rnfhnfbasis(bnf,x): given an order x as output by rnfpseudobasis,
gives either a true HNF basis of the order if it exists, zero otherwise.
Doc: given $\var{bnf}$ as output by
\kbd{bnfinit}, and either a polynomial $x$ with coefficients in $\var{bnf}$
defining a relative extension $L$ of $\var{bnf}$, or a pseudo-basis $x$ of
such an extension, gives either a true $\var{bnf}$-basis of $L$ in upper
triangular Hermite normal form, if it exists, and returns $0$ otherwise.
Function: rnfidealabstorel
Class: basic
Section: number_fields
C-Name: rnfidealabstorel
Prototype: GG
Help: rnfidealabstorel(rnf,x): transforms the ideal x from absolute to
relative representation.
Doc: let $\var{rnf}$ be a relative
number field extension $L/K$ as output by \kbd{rnfinit} and $x$ be an ideal of
the absolute extension $L/\Q$ given by a $\Z$-basis of elements of $L$.
Returns the relative pseudo-matrix in HNF giving the ideal $x$ considered as
an ideal of the relative extension $L/K$, i.e.~as a $\Z_K$-module.
The reason why the input does not use the customary HNF in terms of a fixed
$\Z$-basis for $\Z_L$ is precisely that no such basis has been explicitly
specified. On the other hand, if you already computed an (absolute) \kbd{nf}
structure \kbd{Labs} attached to $L$, and $m$ is in HNF, defining
an (absolute) ideal with respect to the $\Z$-basis \kbd{Labs.zk}, then
\kbd{Labs.zk * m} is a suitable $\Z$-basis for the ideal, and
\bprog
rnfidealabstorel(rnf, Labs.zk * m)
@eprog\noindent converts $m$ to a relative ideal.
\bprog
? K = nfinit(y^2+1); L = rnfinit(K, x^2-y); Labs = nfinit(L);
? m = idealhnf(Labs, 17, x^3+2);
? B = rnfidealabstorel(L, Labs.zk * m)
%3 = [[1, 8; 0, 1], [[17, 4; 0, 1], 1]] \\ pseudo-basis for m as Z_K-module
? A = rnfidealreltoabs(L, B)
%4 = [17, x^2 + 4, x + 8, x^3 + 8*x^2] \\ Z-basis for m in Q[x]/(L.pol)
? mathnf(matalgtobasis(Labs, A))
%5 =
[17 8 4 2]
[ 0 1 0 0]
[ 0 0 1 0]
[ 0 0 0 1]
? % == m
%6 = 1
@eprog
Function: rnfidealdown
Class: basic
Section: number_fields
C-Name: rnfidealdown
Prototype: GG
Help: rnfidealdown(rnf,x): finds the intersection of the ideal x with the
base field.
Doc: let $\var{rnf}$ be a relative number
field extension $L/K$ as output by \kbd{rnfinit}, and $x$ an ideal of
$L$, given either in relative form or by a $\Z$-basis of elements of $L$
(see \secref{se:rnfidealabstorel}). This function returns the ideal of $K$
below $x$, i.e.~the intersection of $x$ with $K$.
Function: rnfidealfactor
Class: basic
Section: number_fields
C-Name: rnfidealfactor
Prototype: GG
Help: rnfidealfactor(rnf,x): factorization of the ideal x into
prime ideals in the number field nfinit(rnf).
Doc: factors into prime ideal powers the
ideal $x$ in the attached absolute number field $L = \kbd{nfinit}(\var{rnf})$.
The output format is similar to the \kbd{factor} function, and the prime
ideals are represented in the form output by the \kbd{idealprimedec}
function for $L$.
\bprog
? rnf = rnfinit(nfinit(y^2+1), x^2-y+1);
? rnfidealfactor(rnf, y+1) \\ P_2^2
%2 =
[[2, [0,0,1,0]~, 4, 1, [0,0,0,2;0,0,-2,0;-1,-1,0,0;1,-1,0,0]] 2]
? rnfidealfactor(rnf, x) \\ P_2
%3 =
[[2, [0,0,1,0]~, 4, 1, [0,0,0,2;0,0,-2,0;-1,-1,0,0;1,-1,0,0]] 1]
? L = nfinit(rnf);
? id = idealhnf(L, idealhnf(L, 25, (x+1)^2));
? idealfactor(L, id) == rnfidealfactor(rnf, id)
%6 = 1
@eprog\noindent Note that ideals of the base field $K$ must be explicitly
lifted to $L$ via \kbd{rnfidealup} before they can be factored.
Function: rnfidealhnf
Class: basic
Section: number_fields
C-Name: rnfidealhnf
Prototype: GG
Help: rnfidealhnf(rnf,x): relative version of idealhnf, where rnf is a
relative numberfield.
Doc: $\var{rnf}$ being a relative number
field extension $L/K$ as output by \kbd{rnfinit} and $x$ being a relative
ideal (which can be, as in the absolute case, of many different types,
including of course elements), computes the HNF pseudo-matrix attached to
$x$, viewed as a $\Z_K$-module.
Function: rnfidealmul
Class: basic
Section: number_fields
C-Name: rnfidealmul
Prototype: GGG
Help: rnfidealmul(rnf,x,y): relative version of idealmul, where rnf is a
relative numberfield.
Doc: $\var{rnf}$ being a relative number
field extension $L/K$ as output by \kbd{rnfinit} and $x$ and $y$ being ideals
of the relative extension $L/K$ given by pseudo-matrices, outputs the ideal
product, again as a relative ideal.
Function: rnfidealnormabs
Class: basic
Section: number_fields
C-Name: rnfidealnormabs
Prototype: GG
Help: rnfidealnormabs(rnf,x): absolute norm of the ideal x.
Doc: let $\var{rnf}$ be a relative
number field extension $L/K$ as output by \kbd{rnfinit} and let $x$ be a
relative ideal (which can be, as in the absolute case, of many different
types, including of course elements). This function computes the norm of the
$x$ considered as an ideal of the absolute extension $L/\Q$. This is
identical to
\bprog
idealnorm(rnf, rnfidealnormrel(rnf,x))
@eprog\noindent but faster.
Function: rnfidealnormrel
Class: basic
Section: number_fields
C-Name: rnfidealnormrel
Prototype: GG
Help: rnfidealnormrel(rnf,x): relative norm of the ideal x.
Doc: let $\var{rnf}$ be a relative
number field extension $L/K$ as output by \kbd{rnfinit} and let $x$ be a
relative ideal (which can be, as in the absolute case, of many different
types, including of course elements). This function computes the relative
norm of $x$ as an ideal of $K$ in HNF.
Function: rnfidealprimedec
Class: basic
Section: number_fields
C-Name: rnfidealprimedec
Prototype: GG
Help: rnfidealprimedec(rnf,pr): prime ideal decomposition of the maximal
ideal pr of K in L/K; pr is also allowed to be a prime number p, in which
case we return a pair of vectors [SK,SL], where SK contains the primes of K
above p and SL[i] is the vector of primes of L above SK[i].
Doc: let \var{rnf} be a relative number
field extension $L/K$ as output by \kbd{rnfinit}, and \kbd{pr} a maximal
ideal of $K$ (\kbd{prid}), this function completes the \var{rnf}
with a \var{nf} structure attached to $L$ (see \secref{se:rnfinit})
and returns the prime ideal decomposition of \kbd{pr} in $L/K$.
\bprog
? K = nfinit(y^2+1); rnf = rnfinit(K, x^3+y+1);
? P = idealprimedec(K, 2)[1];
? S = rnfidealprimedec(rnf, P);
? #S
%4 = 1
@eprog
The argument \kbd{pr} is also allowed to be a prime number $p$, in which
case we return a pair of vectors \kbd{[SK,SL]}, where \kbd{SK} contains
the primes of $K$ above $p$ and \kbd{SL}$[i]$ is the vector of primes of $L$
above \kbd{SK}$[i]$.
\bprog
? [SK,SL] = rnfidealprimedec(rnf, 5);
? [#SK, vector(#SL,i,#SL[i])]
%6 = [2, [2, 2]]
@eprog
Function: rnfidealreltoabs
Class: basic
Section: number_fields
C-Name: rnfidealreltoabs0
Prototype: GGD0,L,
Help: rnfidealreltoabs(rnf,x,{flag=0}): transforms the ideal x from relative to
absolute representation. As a vector of t_POLMODs if flag = 0 and as an ideal
in HNF in the absolute field if flag = 1.
Doc: Let $\var{rnf}$ be a relative
number field extension $L/K$ as output by \kbd{rnfinit} and let $x$ be a
relative ideal, given as a $\Z_K$-module by a pseudo matrix $[A,I]$.
This function returns the ideal $x$ as an absolute ideal of $L/\Q$.
If $\fl = 0$, the result is given by a vector of \typ{POLMOD}s modulo
\kbd{rnf.pol} forming a $\Z$-basis; if $\fl = 1$, it is given in HNF in terms
of the fixed $\Z$-basis for $\Z_L$, see \secref{se:rnfinit}.
\bprog
? K = nfinit(y^2+1); rnf = rnfinit(K, x^2-y);
? P = idealprimedec(K,2)[1];
? P = rnfidealup(rnf, P)
%3 = [2, x^2 + 1, 2*x, x^3 + x]
? Prel = rnfidealhnf(rnf, P)
%4 = [[1, 0; 0, 1], [[2, 1; 0, 1], [2, 1; 0, 1]]]
? rnfidealreltoabs(rnf,Prel)
%5 = [2, x^2 + 1, 2*x, x^3 + x]
? rnfidealreltoabs(rnf,Prel,1)
%6 =
[2 1 0 0]
[0 1 0 0]
[0 0 2 1]
[0 0 0 1]
@eprog
The reason why we do not return by default ($\fl = 0$) the customary HNF in
terms of a fixed $\Z$-basis for $\Z_L$ is precisely because
a \var{rnf} does not contain such a basis by default. Completing the
structure so that it contains a \var{nf} structure for $L$ is polynomial
time but costly when the absolute degree is large, thus it is not done by
default. Note that setting $\fl = 1$ will complete the \var{rnf}.
Variant: Also available is
\fun{GEN}{rnfidealreltoabs}{GEN rnf, GEN x} ($\fl = 0$).
Function: rnfidealtwoelt
Class: basic
Section: number_fields
C-Name: rnfidealtwoelement
Prototype: GG
Help: rnfidealtwoelt(rnf,x): relative version of idealtwoelt, where rnf
is a relative numberfield.
Doc: $\var{rnf}$ being a relative
number field extension $L/K$ as output by \kbd{rnfinit} and $x$ being an
ideal of the relative extension $L/K$ given by a pseudo-matrix, gives a
vector of two generators of $x$ over $\Z_L$ expressed as polmods with polmod
coefficients.
Function: rnfidealup
Class: basic
Section: number_fields
C-Name: rnfidealup0
Prototype: GGD0,L,
Help: rnfidealup(rnf,x,{flag=0}): lifts the ideal x (of the base field) to the
relative field. As a vector of t_POLMODs if flag = 0 and as an ideal in HNF
in the absolute field if flag = 1.
Doc: let $\var{rnf}$ be a relative number
field extension $L/K$ as output by \kbd{rnfinit} and let $x$ be an ideal of
$K$. This function returns the ideal $x\Z_L$ as an absolute ideal of $L/\Q$,
in the form of a $\Z$-basis. If $\fl = 0$, the result is given by a vector of
polynomials (modulo \kbd{rnf.pol}); if $\fl = 1$, it is given in HNF in terms
of the fixed $\Z$-basis for $\Z_L$, see \secref{se:rnfinit}.
\bprog
? K = nfinit(y^2+1); rnf = rnfinit(K, x^2-y);
? P = idealprimedec(K,2)[1];
? rnfidealup(rnf, P)
%3 = [2, x^2 + 1, 2*x, x^3 + x]
? rnfidealup(rnf, P,1)
%4 =
[2 1 0 0]
[0 1 0 0]
[0 0 2 1]
[0 0 0 1]
@eprog
The reason why we do not return by default ($\fl = 0$) the customary HNF in
terms of a fixed $\Z$-basis for $\Z_L$ is precisely because
a \var{rnf} does not contain such a basis by default. Completing the
structure so that it contains a \var{nf} structure for $L$ is polynomial
time but costly when the absolute degree is large, thus it is not done by
default. Note that setting $\fl = 1$ will complete the \var{rnf}.
Variant: Also available is
\fun{GEN}{rnfidealup}{GEN rnf, GEN x} ($\fl = 0$).
Function: rnfinit
Class: basic
Section: number_fields
C-Name: rnfinit0
Prototype: GGD0,L,
Help: rnfinit(nf,pol,{flag=0}): pol being an irreducible polynomial
defined over the number field nf, initializes a vector of data necessary for
working in relative number fields (rnf functions). See manual for technical
details.
Doc: $\var{nf}$ being a number field in \kbd{nfinit}
format considered as base field, and \var{pol} a polynomial defining a relative
extension over $\var{nf}$, this computes data to work in the
relative extension. The main variable of \var{pol} must be of higher priority
(see \secref{se:priority}) than that of $\var{nf}$, and the coefficients of
\var{pol} must be in $\var{nf}$.
The result is a row vector, whose components are technical. In the following
description, we let $K$ be the base field defined by $\var{nf}$ and $L/K$
the extension attached to the \var{rnf}. Furthermore, we let
$m = [K:\Q]$ the degree of the base field, $n = [L:K]$ the relative degree,
$r_1$ and $r_2$ the number of real and complex places of $K$. Access to this
information via \emph{member functions} is preferred since the specific
data organization specified below will change in the future.
If $\fl = 1$, add an \var{nf} structure attached to $L$ to \var{rnf}.
This is likely to be very expensive if the absolute degree $mn$ is large,
but fixes an integer basis for $\Z_L$ as a $\Z$-module and allows to input
and output elements of $L$ in absolute form: as \typ{COL} for elements,
as \typ{MAT} in HNF for ideals, as \kbd{prid} for prime ideals. Without such
a call, elements of $L$ are represented as \typ{POLMOD}, etc.
Note that a subsequent \kbd{nfinit}$(\var{rnf})$ will also explicitly
add such a component, and so will the following functions \kbd{rnfidealmul},
\kbd{rnfidealtwoelt}, \kbd{rnfidealprimedec}, \kbd{rnfidealup} (with flag 1)
and \kbd{rnfidealreltoabs} (with flag 1). The absolute \var{nf} structure
attached to $L$ can be recovered using \kbd{nfinit(rnf)}.
$\var{rnf}[1]$(\kbd{rnf.pol}) contains the relative polynomial \var{pol}.
$\var{rnf}[2]$ contains the integer basis $[A,d]$ of $K$, as
(integral) elements of $L/\Q$. More precisely, $A$ is a vector of
polynomial with integer coefficients, $d$ is a denominator, and the integer
basis is given by $A/d$.
$\var{rnf}[3]$ (\kbd{rnf.disc}) is a two-component row vector
$[\goth{d}(L/K),s]$ where $\goth{d}(L/K)$ is the relative ideal discriminant
of $L/K$ and $s$ is the discriminant of $L/K$ viewed as an element of
$K^*/(K^*)^2$, in other words it is the output of \kbd{rnfdisc}.
$\var{rnf}[4]$(\kbd{rnf.index}) is the ideal index $\goth{f}$, i.e.~such
that $d(pol)\Z_K=\goth{f}^2\goth{d}(L/K)$.
$\var{rnf}[5]$ is currently unused.
$\var{rnf}[6]$ is currently unused.
$\var{rnf}[7]$ (\kbd{rnf.zk}) is the pseudo-basis $(A,I)$ for the maximal
order $\Z_L$ as a $\Z_K$-module: $A$ is the relative integral pseudo basis
expressed as polynomials (in the variable of $pol$) with polmod coefficients
in $\var{nf}$, and the second component $I$ is the ideal list of the
pseudobasis in HNF.
$\var{rnf}[8]$ is the inverse matrix of the integral basis matrix, with
coefficients polmods in $\var{nf}$.
$\var{rnf}[9]$ is currently unused.
$\var{rnf}[10]$ (\kbd{rnf.nf}) is $\var{nf}$.
$\var{rnf}[11]$ is an extension of \kbd{rnfequation(K, pol, 1)}. Namely, a
vector $[P, a, k, \kbd{K.pol}, \kbd{pol}]$ describing the \emph{absolute}
extension
$L/\Q$: $P$ is an absolute equation, more conveniently obtained
as \kbd{rnf.polabs}; $a$ expresses the generator $\alpha = y \mod \kbd{K.pol}$
of the number field $K$ as an element of $L$, i.e.~a polynomial modulo the
absolute equation $P$;
$k$ is a small integer such that, if $\beta$ is an abstract root of \var{pol}
and $\alpha$ the generator of $K$ given above, then $P(\beta + k\alpha) = 0$.
\misctitle{Caveat} Be careful if $k\neq0$ when dealing simultaneously with
absolute and relative quantities since $L = \Q(\beta + k\alpha) =
K(\alpha)$, and the generator chosen for the absolute extension is not the
same as for the relative one. If this happens, one can of course go on
working, but we advise to change the relative polynomial so that its root
becomes $\beta + k \alpha$. Typical GP instructions would be
\bprog
[P,a,k] = rnfequation(K, pol, 1);
if (k, pol = subst(pol, x, x - k*Mod(y, K.pol)));
L = rnfinit(K, pol);
@eprog
$\var{rnf}[12]$ is by default unused and set equal to 0. This field is used
to store further information about the field as it becomes available (which
is rarely needed, hence would be too expensive to compute during the initial
\kbd{rnfinit} call).
Variant: Also available is
\fun{GEN}{rnfinit}{GEN nf,GEN pol} ($\fl = 0$).
Function: rnfisabelian
Class: basic
Section: number_fields
C-Name: rnfisabelian
Prototype: lGG
Help: rnfisabelian(nf,T): T being a relative polynomial with coefficients
in nf, return 1 if it defines an abelian extension, and 0 otherwise.
Doc: $T$ being a relative polynomial with coefficients
in \var{nf}, return 1 if it defines an abelian extension, and 0 otherwise.
\bprog
? K = nfinit(y^2 + 23);
? rnfisabelian(K, x^3 - 3*x - y)
%2 = 1
@eprog
Function: rnfisfree
Class: basic
Section: number_fields
C-Name: rnfisfree
Prototype: lGG
Help: rnfisfree(bnf,x): given an order x as output by rnfpseudobasis or
rnfsteinitz, outputs true (1) or false (0) according to whether the order is
free or not.
Doc: given $\var{bnf}$ as output by
\kbd{bnfinit}, and either a polynomial $x$ with coefficients in $\var{bnf}$
defining a relative extension $L$ of $\var{bnf}$, or a pseudo-basis $x$ of
such an extension, returns true (1) if $L/\var{bnf}$ is free, false (0) if
not.
Function: rnfislocalcyclo
Class: basic
Section: number_fields
C-Name: rnfislocalcyclo
Prototype: lG
Help: rnfislocalcyclo(rnf): true(1) if the l-extension attached to rnf
is locally cyclotomic (locally contained in the Z_l extension of K_v at
all places v | l), false(0) if not.
Doc: Let \var{rnf} a a relative number field extension $L/K$ as output
by \kbd{rnfinit} whole degree $[L:K]$ is a power of a prime $\ell$.
Return $1$ if the $\ell$-extension is locally cyclotomic (locally contained in
the cyclotomic $\Z_\ell$-extension of $K_v$ at all places $v | \ell$), and
$0$ if not.
\bprog
? K = nfinit(y^2 + y + 1);
? L = rnfinit(K, x^3 - y); /* = K(zeta_9), globally cyclotomic */
? rnfislocalcyclo(L)
%3 = 1
\\ we expect 3-adic continuity by Krasner's lemma
? vector(5, i, rnfislocalcyclo(rnfinit(K, x^3 - y + 3^i)))
%5 = [0, 1, 1, 1, 1]
@eprog
Function: rnfisnorm
Class: basic
Section: number_fields
C-Name: rnfisnorm
Prototype: GGD0,L,
Help: rnfisnorm(T,a,{flag=0}): T is as output by rnfisnorminit applied to
L/K. Tries to tell whether a is a norm from L/K. Returns a vector [x,q]
where a=Norm(x)*q. Looks for a solution which is a S-integer, with S a list
of places in K containing the ramified primes, generators of the class group
of ext, as well as those primes dividing a. If L/K is Galois, omit flag,
otherwise it is used to add more places to S: all the places above the
primes p <= flag (resp. p | flag) if flag > 0 (resp. flag < 0). The answer
is guaranteed (i.e a is a norm iff q=1) if L/K is Galois or, under GRH, if S
contains all primes less than 12.log(disc(M))^2, where M is the normal
closure of L/K.
Doc: similar to
\kbd{bnfisnorm} but in the relative case. $T$ is as output by
\tet{rnfisnorminit} applied to the extension $L/K$. This tries to decide
whether the element $a$ in $K$ is the norm of some $x$ in the extension
$L/K$.
The output is a vector $[x,q]$, where $a = \Norm(x)*q$. The
algorithm looks for a solution $x$ which is an $S$-integer, with $S$ a list
of places of $K$ containing at least the ramified primes, the generators of
the class group of $L$, as well as those primes dividing $a$. If $L/K$ is
Galois, then this is enough; otherwise, $\fl$ is used to add more primes to
$S$: all the places above the primes $p \leq \fl$ (resp.~$p|\fl$) if $\fl>0$
(resp.~$\fl<0$).
The answer is guaranteed (i.e.~$a$ is a norm iff $q = 1$) if the field is
Galois, or, under \idx{GRH}, if $S$ contains all primes less than
$12\log^2\left|\disc(M)\right|$, where $M$ is the normal
closure of $L/K$.
If \tet{rnfisnorminit} has determined (or was told) that $L/K$ is
\idx{Galois}, and $\fl \neq 0$, a Warning is issued (so that you can set
$\fl = 1$ to check whether $L/K$ is known to be Galois, according to $T$).
Example:
\bprog
bnf = bnfinit(y^3 + y^2 - 2*y - 1);
p = x^2 + Mod(y^2 + 2*y + 1, bnf.pol);
T = rnfisnorminit(bnf, p);
rnfisnorm(T, 17)
@eprog\noindent
checks whether $17$ is a norm in the Galois extension $\Q(\beta) /
\Q(\alpha)$, where $\alpha^3 + \alpha^2 - 2\alpha - 1 = 0$ and $\beta^2 +
\alpha^2 + 2\alpha + 1 = 0$ (it is).
Function: rnfisnorminit
Class: basic
Section: number_fields
C-Name: rnfisnorminit
Prototype: GGD2,L,
Help: rnfisnorminit(pol,polrel,{flag=2}): let K be defined by a root of pol,
L/K the extension defined by polrel. Compute technical data needed by
rnfisnorm to solve norm equations Nx = a, for x in L, and a in K. If flag=0,
do not care whether L/K is Galois or not; if flag = 1, assume L/K is Galois;
if flag = 2, determine whether L/K is Galois.
Doc: let $K$ be defined by a root of \var{pol}, and $L/K$ the extension defined
by the polynomial \var{polrel}. As usual, \var{pol} can in fact be an \var{nf},
or \var{bnf}, etc; if \var{pol} has degree $1$ (the base field is $\Q$),
polrel is also allowed to be an \var{nf}, etc. Computes technical data needed
by \tet{rnfisnorm} to solve norm equations $Nx = a$, for $x$ in $L$, and $a$
in $K$.
If $\fl = 0$, do not care whether $L/K$ is Galois or not.
If $\fl = 1$, $L/K$ is assumed to be Galois (unchecked), which speeds up
\tet{rnfisnorm}.
If $\fl = 2$, let the routine determine whether $L/K$ is Galois.
Function: rnfkummer
Class: basic
Section: number_fields
C-Name: rnfkummer
Prototype: GDGD0,L,p
Help: rnfkummer(bnr,{subgp},{d=0}): bnr being as output by bnrinit,
finds a relative equation for the class field corresponding to the module in
bnr and the given congruence subgroup (the ray class field if subgp is
omitted). d can be zero (default), or positive, and in this case the
output is the list of all relative equations of degree d for the given bnr,
with the same conductor as (bnr, subgp).
Doc: \var{bnr}
being as output by \kbd{bnrinit}, finds a relative equation for the
class field corresponding to the module in \var{bnr} and the given
congruence subgroup (the full ray class field if \var{subgp} is omitted).
If $d$ is positive, outputs the list of all relative equations of
degree $d$ contained in the ray class field defined by \var{bnr}, with
the \emph{same} conductor as $(\var{bnr}, \var{subgp})$.
\misctitle{Warning} This routine only works for subgroups of prime index. It
uses Kummer theory, adjoining necessary roots of unity (it needs to compute a
tough \kbd{bnfinit} here), and finds a generator via Hecke's characterization
of ramification in Kummer extensions of prime degree. If your extension does
not have prime degree, for the time being, you have to split it by hand as a
tower / compositum of such extensions.
Function: rnflllgram
Class: basic
Section: number_fields
C-Name: rnflllgram
Prototype: GGGp
Help: rnflllgram(nf,pol,order): given a pol with coefficients in nf and an
order as output by rnfpseudobasis or similar, gives [[neworder],U], where
neworder is a reduced order and U is the unimodular transformation matrix.
Doc: given a polynomial
\var{pol} with coefficients in \var{nf} defining a relative extension $L$ and
a suborder \var{order} of $L$ (of maximal rank), as output by
\kbd{rnfpseudobasis}$(\var{nf},\var{pol})$ or similar, gives
$[[\var{neworder}],U]$, where \var{neworder} is a reduced order and $U$ is
the unimodular transformation matrix.
Function: rnfnormgroup
Class: basic
Section: number_fields
C-Name: rnfnormgroup
Prototype: GG
Help: rnfnormgroup(bnr,pol): norm group (or Artin or Takagi group)
corresponding to the Abelian extension of bnr.bnf defined by pol, where
the module corresponding to bnr is assumed to be a multiple of the
conductor. The result is the HNF defining the norm group on the
generators in bnr.gen.
Doc:
\var{bnr} being a big ray
class field as output by \kbd{bnrinit} and \var{pol} a relative polynomial
defining an \idx{Abelian extension}, computes the norm group (alias Artin
or Takagi group) corresponding to the Abelian extension of
$\var{bnf}=$\kbd{bnr.bnf}
defined by \var{pol}, where the module corresponding to \var{bnr} is assumed
to be a multiple of the conductor (i.e.~\var{pol} defines a subextension of
bnr). The result is the HNF defining the norm group on the given generators
of \kbd{bnr.gen}. Note that neither the fact that \var{pol} defines an
Abelian extension nor the fact that the module is a multiple of the conductor
is checked. The result is undefined if the assumption is not correct,
but the function will return the empty matrix \kbd{[;]} if it detects a
problem; it may also not detect the problem and return a wrong result.
Function: rnfpolred
Class: basic
Section: number_fields
C-Name: rnfpolred
Prototype: GGp
Help: rnfpolred(nf,pol): given a pol with coefficients in nf, finds a list
of relative polynomials defining some subfields, hopefully simpler.
Doc: This function is obsolete: use \tet{rnfpolredbest} instead.
Relative version of \kbd{polred}. Given a monic polynomial \var{pol} with
coefficients in $\var{nf}$, finds a list of relative polynomials defining some
subfields, hopefully simpler and containing the original field. In the present
version \vers, this is slower and less efficient than \kbd{rnfpolredbest}.
\misctitle{Remark} this function is based on an incomplete reduction
theory of lattices over number fields, implemented by \kbd{rnflllgram}, which
deserves to be improved.
Obsolete: 2013-12-28
Function: rnfpolredabs
Class: basic
Section: number_fields
C-Name: rnfpolredabs
Prototype: GGD0,L,
Help: rnfpolredabs(nf,pol,{flag=0}): given a pol with coefficients in nf,
finds a relative simpler polynomial defining the same field. Binary digits
of flag mean: 1: return also the element whose characteristic polynomial is
the given polynomial, 2: return an absolute polynomial, 16: partial
reduction.
Doc: This function is obsolete: use \tet{rnfpolredbest} instead.
Relative version of \kbd{polredabs}. Given a monic polynomial \var{pol}
with coefficients in $\var{nf}$, finds a simpler relative polynomial defining
the same field. The binary digits of $\fl$ mean
The binary digits of $\fl$ correspond to $1$: add information to convert
elements to the new representation, $2$: absolute polynomial, instead of
relative, $16$: possibly use a suborder of the maximal order. More precisely:
0: default, return $P$
1: returns $[P,a]$ where $P$ is the default output and $a$,
a \typ{POLMOD} modulo $P$, is a root of \var{pol}.
2: returns \var{Pabs}, an absolute, instead of a relative, polynomial.
Same as but faster than
\bprog
rnfequation(nf, rnfpolredabs(nf,pol))
@eprog
3: returns $[\var{Pabs},a,b]$, where \var{Pabs} is an absolute polynomial
as above, $a$, $b$ are \typ{POLMOD} modulo \var{Pabs}, roots of \kbd{nf.pol}
and \var{pol} respectively.
16: possibly use a suborder of the maximal order. This is slower than the
default when the relative discriminant is smooth, and much faster otherwise.
See \secref{se:polredabs}.
\misctitle{Warning} In the present implementation, \kbd{rnfpolredabs}
produces smaller polynomials than \kbd{rnfpolred} and is usually
faster, but its complexity is still exponential in the absolute degree.
The function \tet{rnfpolredbest} runs in polynomial time, and tends to
return polynomials with smaller discriminants.
Obsolete: 2013-12-28
Function: rnfpolredbest
Class: basic
Section: number_fields
C-Name: rnfpolredbest
Prototype: GGD0,L,
Help: rnfpolredbest(nf,pol,{flag=0}): given a pol with coefficients in nf,
finds a relative polynomial P defining the same field, hopefully simpler
than pol; flag
can be 0: default, 1: return [P,a], where a is a root of pol
2: return an absolute polynomial Pabs, 3:
return [Pabs, a,b], where a is a root of nf.pol and b is a root of pol.
Doc: relative version of \kbd{polredbest}. Given a monic polynomial \var{pol}
with coefficients in $\var{nf}$, finds a simpler relative polynomial $P$
defining the same field. As opposed to \tet{rnfpolredabs} this function does
not return a \emph{smallest} (canonical) polynomial with respect to some
measure, but it does run in polynomial time.
The binary digits of $\fl$ correspond to $1$: add information to convert
elements to the new representation, $2$: absolute polynomial, instead of
relative. More precisely:
0: default, return $P$
1: returns $[P,a]$ where $P$ is the default output and $a$,
a \typ{POLMOD} modulo $P$, is a root of \var{pol}.
2: returns \var{Pabs}, an absolute, instead of a relative, polynomial.
Same as but faster than
\bprog
rnfequation(nf, rnfpolredbest(nf,pol))
@eprog
3: returns $[\var{Pabs},a,b]$, where \var{Pabs} is an absolute polynomial
as above, $a$, $b$ are \typ{POLMOD} modulo \var{Pabs}, roots of \kbd{nf.pol}
and \var{pol} respectively.
\bprog
? K = nfinit(y^3-2); pol = x^2 +x*y + y^2;
? [P, a] = rnfpolredbest(K,pol,1);
? P
%3 = x^2 - x + Mod(y - 1, y^3 - 2)
? a
%4 = Mod(Mod(2*y^2+3*y+4,y^3-2)*x + Mod(-y^2-2*y-2,y^3-2),
x^2 - x + Mod(y-1,y^3-2))
? subst(K.pol,y,a)
%5 = 0
? [Pabs, a, b] = rnfpolredbest(K,pol,3);
? Pabs
%7 = x^6 - 3*x^5 + 5*x^3 - 3*x + 1
? a
%8 = Mod(-x^2+x+1, x^6-3*x^5+5*x^3-3*x+1)
? b
%9 = Mod(2*x^5-5*x^4-3*x^3+10*x^2+5*x-5, x^6-3*x^5+5*x^3-3*x+1)
? subst(K.pol,y,a)
%10 = 0
? substvec(pol,[x,y],[a,b])
%11 = 0
@eprog
Function: rnfpseudobasis
Class: basic
Section: number_fields
C-Name: rnfpseudobasis
Prototype: GG
Help: rnfpseudobasis(nf,pol): given a pol with coefficients in nf, gives a
4-component vector [A,I,D,d] where [A,I] is a pseudo basis of the maximal
order in HNF on the power basis, D is the relative ideal discriminant, and d
is the relative discriminant in nf^*/nf*^2.
Doc: given a number field
$\var{nf}$ as output by \kbd{nfinit} and a polynomial \var{pol} with
coefficients in $\var{nf}$ defining a relative extension $L$ of $\var{nf}$,
computes a pseudo-basis $(A,I)$ for the maximal order $\Z_L$ viewed as a
$\Z_K$-module, and the relative discriminant of $L$. This is output as a
four-element row vector $[A,I,D,d]$, where $D$ is the relative ideal
discriminant and $d$ is the relative discriminant considered as an element of
$\var{nf}^*/{\var{nf}^*}^2$.
Function: rnfsteinitz
Class: basic
Section: number_fields
C-Name: rnfsteinitz
Prototype: GG
Help: rnfsteinitz(nf,x): given an order x as output by rnfpseudobasis,
gives [A,I,D,d] where (A,I) is a pseudo basis where all the ideals except
perhaps the last are trivial.
Doc: given a number field $\var{nf}$ as
output by \kbd{nfinit} and either a polynomial $x$ with coefficients in
$\var{nf}$ defining a relative extension $L$ of $\var{nf}$, or a pseudo-basis
$x$ of such an extension as output for example by \kbd{rnfpseudobasis},
computes another pseudo-basis $(A,I)$ (not in HNF in general) such that all
the ideals of $I$ except perhaps the last one are equal to the ring of
integers of $\var{nf}$, and outputs the four-component row vector $[A,I,D,d]$
as in \kbd{rnfpseudobasis}. The name of this function comes from the fact
that the ideal class of the last ideal of $I$, which is well defined, is the
\idx{Steinitz class} of the $\Z_K$-module $\Z_L$ (its image in $SK_0(\Z_K)$).
Function: round
Class: basic
Section: conversions
C-Name: round0
Prototype: GD&
Help: round(x,{&e}): take the nearest integer to all the coefficients of x.
If e is present, do not take into account loss of integer part precision,
and set e = error estimate in bits.
Description:
(small):small:parens $1
(int):int:copy:parens $1
(real):int roundr($1)
(mp):int mpround($1)
(mp, &small):int grndtoi($1, &$2)
(mp, &int):int round0($1, &$2)
(gen):gen ground($1)
(gen, &small):gen grndtoi($1, &$2)
(gen, &int):gen round0($1, &$2)
Doc: If $x$ is in $\R$, rounds $x$ to the nearest integer (rounding to
$+\infty$ in case of ties), then and sets $e$ to the number of error bits,
that is the binary exponent of the difference between the original and the
rounded value (the ``fractional part''). If the exponent of $x$ is too large
compared to its precision (i.e.~$e>0$), the result is undefined and an error
occurs if $e$ was not given.
\misctitle{Important remark} Contrary to the other truncation functions,
this function operates on every coefficient at every level of a PARI object.
For example
$$\text{truncate}\left(\dfrac{2.4*X^2-1.7}{X}\right)=2.4*X,$$
whereas
$$\text{round}\left(\dfrac{2.4*X^2-1.7}{X}\right)=\dfrac{2*X^2-2}{X}.$$
An important use of \kbd{round} is to get exact results after an approximate
computation, when theory tells you that the coefficients must be integers.
Variant: Also available are \fun{GEN}{grndtoi}{GEN x, long *e} and
\fun{GEN}{ground}{GEN x}.
Function: select
Class: basic
Section: programming/specific
C-Name: select0
Prototype: GGD0,L,
Help: select(f, A, {flag = 0}): selects elements of A according to the selection
function f. If flag is 1, return the indices of those elements (indirect
selection).
Wrapper: (bG)
Description:
(gen,gen):gen genselect(${1 cookie}, ${1 wrapper}, $2)
(gen,gen,0):gen genselect(${1 cookie}, ${1 wrapper}, $2)
(gen,gen,1):vecsmall genindexselect(${1 cookie}, ${1 wrapper}, $2)
Doc: We first describe the default behavior, when $\fl$ is 0 or omitted.
Given a vector or list \kbd{A} and a \typ{CLOSURE} \kbd{f}, \kbd{select}
returns the elements $x$ of \kbd{A} such that $f(x)$ is non-zero. In other
words, \kbd{f} is seen as a selection function returning a boolean value.
\bprog
? select(x->isprime(x), vector(50,i,i^2+1))
%1 = [2, 5, 17, 37, 101, 197, 257, 401, 577, 677, 1297, 1601]
? select(x->(x<100), %)
%2 = [2, 5, 17, 37]
@eprog\noindent returns the primes of the form $i^2+1$ for some $i\leq 50$,
then the elements less than 100 in the preceding result. The \kbd{select}
function also applies to a matrix \kbd{A}, seen as a vector of columns, i.e. it
selects columns instead of entries, and returns the matrix whose columns are
the selected ones.
\misctitle{Remark} For $v$ a \typ{VEC}, \typ{COL}, \typ{LIST} or \typ{MAT},
the alternative set-notations
\bprog
[g(x) | x <- v, f(x)]
[x | x <- v, f(x)]
[g(x) | x <- v]
@eprog\noindent
are available as shortcuts for
\bprog
apply(g, select(f, Vec(v)))
select(f, Vec(v))
apply(g, Vec(v))
@eprog\noindent respectively:
\bprog
? [ x | x <- vector(50,i,i^2+1), isprime(x) ]
%1 = [2, 5, 17, 37, 101, 197, 257, 401, 577, 677, 1297, 1601]
@eprog
\noindent If $\fl = 1$, this function returns instead the \emph{indices} of
the selected elements, and not the elements themselves (indirect selection):
\bprog
? V = vector(50,i,i^2+1);
? select(x->isprime(x), V, 1)
%2 = Vecsmall([1, 2, 4, 6, 10, 14, 16, 20, 24, 26, 36, 40])
? vecextract(V, %)
%3 = [2, 5, 17, 37, 101, 197, 257, 401, 577, 677, 1297, 1601]
@eprog\noindent
The following function lists the elements in $(\Z/N\Z)^*$:
\bprog
? invertibles(N) = select(x->gcd(x,N) == 1, [1..N])
@eprog
\noindent Finally
\bprog
? select(x->x, M)
@eprog\noindent selects the non-0 entries in \kbd{M}. If the latter is a
\typ{MAT}, we extract the matrix of non-0 columns. Note that \emph{removing}
entries instead of selecting them just involves replacing the selection
function \kbd{f} with its negation:
\bprog
? select(x->!isprime(x), vector(50,i,i^2+1))
@eprog
\synt{genselect}{void *E, long (*fun)(void*,GEN), GEN a}. Also available
is \fun{GEN}{genindexselect}{void *E, long (*fun)(void*, GEN), GEN a},
corresponding to $\fl = 1$.
Function: self
Class: basic
Section: programming/specific
C-Name: pari_self
Prototype: m
Help: self(): return the calling function or closure. Useful for defining
anonymous recursive functions.
Doc: return the calling function or closure as a \typ{CLOSURE} object.
This is useful for defining anonymous recursive functions.
\bprog
? (n->if(n==0,1,n*self()(n-1)))(5)
%1 = 120
@eprog
Function: seralgdep
Class: basic
Section: linear_algebra
C-Name: seralgdep
Prototype: GLL
Help: seralgdep(s,p,r): find a linear relation between powers (1,s, ..., s^p)
of the series s, with polynomial coefficients of degree <= r.
Doc: \sidx{algebraic dependence} finds a linear relation between powers $(1,s,
\dots, s^p)$ of the series $s$, with polynomial coefficients of degree
$\leq r$. In case no relation is found, return $0$.
\bprog
? s = 1 + 10*y - 46*y^2 + 460*y^3 - 5658*y^4 + 77740*y^5 + O(y^6);
? seralgdep(s, 2, 2)
%2 = -x^2 + (8*y^2 + 20*y + 1)
? subst(%, x, s)
%3 = O(y^6)
? seralgdep(s, 1, 3)
%4 = (-77*y^2 - 20*y - 1)*x + (310*y^3 + 231*y^2 + 30*y + 1)
? seralgdep(s, 1, 2)
%5 = 0
@eprog\noindent The series main variable must not be $x$, so as to be able
to express the result as a polynomial in $x$.
Function: serconvol
Class: basic
Section: polynomials
C-Name: convol
Prototype: GG
Help: serconvol(x,y): convolution (or Hadamard product) of two power series.
Doc: convolution (or \idx{Hadamard product}) of the
two power series $x$ and $y$; in other words if $x=\sum a_k*X^k$ and $y=\sum
b_k*X^k$ then $\kbd{serconvol}(x,y)=\sum a_k*b_k*X^k$.
Function: serlaplace
Class: basic
Section: polynomials
C-Name: laplace
Prototype: G
Help: serlaplace(x): replaces the power series sum of a_n*x^n/n! by sum of
a_n*x^n. For the reverse operation, use serconvol(x,exp(X)).
Doc: $x$ must be a power series with non-negative
exponents or a polynomial. If $x=\sum (a_k/k!)*X^k$ then the result is $\sum
a_k*X^k$.
Function: serprec
Class: basic
Section: conversions
C-Name: gpserprec
Prototype: Gn
Help: serprec(x,v):
return the absolute precision x with respect to power series in the variable v.
Doc: returns the absolute precision of $x$ with respect to power series
in the variable $v$; this is the
minimum precision of the components of $x$. The result is \tet{+oo} if $x$
is an exact object (as a series in $v$):
\bprog
? serprec(x + O(y^2), y)
%1 = 2
? serprec(x + 2, x)
%2 = +oo
? serprec(2 + x + O(x^2), y)
%3 = +oo
@eprog
Variant: Also available is \fun{long}{serprec}{GEN x, GEN p}, which returns
\tet{LONG_MAX} if $x = 0$ and the series precision as a \kbd{long} integer.
Function: serreverse
Class: basic
Section: polynomials
C-Name: serreverse
Prototype: G
Help: serreverse(s): reversion of the power series s.
Doc: reverse power series of $s$, i.e. the series $t$ such that $t(s) = x$;
$s$ must be a power series whose valuation is exactly equal to one.
\bprog
? \ps 8
? t = serreverse(tan(x))
%2 = x - 1/3*x^3 + 1/5*x^5 - 1/7*x^7 + O(x^8)
? tan(t)
%3 = x + O(x^8)
@eprog
Function: setbinop
Class: basic
Section: linear_algebra
C-Name: setbinop
Prototype: GGDG
Help: setbinop(f,X,{Y}): the set {f(x,y), x in X, y in Y}. If Y is omitted,
assume that X = Y and that f is symmetric.
Doc: the set whose elements are the f(x,y), where x,y run through X,Y.
respectively. If $Y$ is omitted, assume that $X = Y$ and that $f$ is symmetric:
$f(x,y) = f(y,x)$ for all $x,y$ in $X$.
\bprog
? X = [1,2,3]; Y = [2,3,4];
? setbinop((x,y)->x+y, X,Y) \\ set X + Y
%2 = [3, 4, 5, 6, 7]
? setbinop((x,y)->x-y, X,Y) \\ set X - Y
%3 = [-3, -2, -1, 0, 1]
? setbinop((x,y)->x+y, X) \\ set 2X = X + X
%2 = [2, 3, 4, 5, 6]
@eprog
Function: setintersect
Class: basic
Section: linear_algebra
C-Name: setintersect
Prototype: GG
Help: setintersect(x,y): intersection of the sets x and y.
Description:
(vec, vec):vec setintersect($1, $2)
Doc: intersection of the two sets $x$ and $y$ (see \kbd{setisset}).
If $x$ or $y$ is not a set, the result is undefined.
Function: setisset
Class: basic
Section: linear_algebra
C-Name: setisset
Prototype: lG
Help: setisset(x): true(1) if x is a set (row vector with strictly
increasing entries), false(0) if not.
Doc:
returns true (1) if $x$ is a set, false (0) if
not. In PARI, a set is a row vector whose entries are strictly
increasing with respect to a (somewhat arbitrary) universal comparison
function. To convert any object into a set (this is most useful for
vectors, of course), use the function \kbd{Set}.
\bprog
? a = [3, 1, 1, 2];
? setisset(a)
%2 = 0
? Set(a)
%3 = [1, 2, 3]
@eprog
Function: setminus
Class: basic
Section: linear_algebra
C-Name: setminus
Prototype: GG
Help: setminus(x,y): set of elements of x not belonging to y.
Description:
(vec, vec):vec setminus($1, $2)
Doc: difference of the two sets $x$ and $y$ (see \kbd{setisset}),
i.e.~set of elements of $x$ which do not belong to $y$.
If $x$ or $y$ is not a set, the result is undefined.
Function: setrand
Class: basic
Section: programming/specific
C-Name: setrand
Prototype: vG
Help: setrand(n): reset the seed of the random number generator to n.
Doc: reseeds the random number generator using the seed $n$. No value is
returned. The seed is either a technical array output by \kbd{getrand}, or a
small positive integer, used to generate deterministically a suitable state
array. For instance, running a randomized computation starting by
\kbd{setrand(1)} twice will generate the exact same output.
Function: setsearch
Class: basic
Section: linear_algebra
C-Name: setsearch
Prototype: lGGD0,L,
Help: setsearch(S,x,{flag=0}): determines whether x belongs to the set (or
sorted list) S.
If flag is 0 or omitted, returns 0 if it does not, otherwise returns the index
j such that x==S[j]. If flag is non-zero, return 0 if x belongs to S,
otherwise the index j where it should be inserted.
Doc: determines whether $x$ belongs to the set $S$ (see \kbd{setisset}).
We first describe the default behaviour, when $\fl$ is zero or omitted. If $x$
belongs to the set $S$, returns the index $j$ such that $S[j]=x$, otherwise
returns 0.
\bprog
? T = [7,2,3,5]; S = Set(T);
? setsearch(S, 2)
%2 = 1
? setsearch(S, 4) \\ not found
%3 = 0
? setsearch(T, 7) \\ search in a randomly sorted vector
%4 = 0 \\ WRONG !
@eprog\noindent
If $S$ is not a set, we also allow sorted lists with
respect to the \tet{cmp} sorting function, without repeated entries,
as per \tet{listsort}$(L,1)$; otherwise the result is undefined.
\bprog
? L = List([1,4,2,3,2]); setsearch(L, 4)
%1 = 0 \\ WRONG !
? listsort(L, 1); L \\ sort L first
%2 = List([1, 2, 3, 4])
? setsearch(L, 4)
%3 = 4 \\ now correct
@eprog\noindent
If $\fl$ is non-zero, this function returns the index $j$ where $x$ should be
inserted, and $0$ if it already belongs to $S$. This is meant to be used for
dynamically growing (sorted) lists, in conjunction with \kbd{listinsert}.
\bprog
? L = List([1,5,2,3,2]); listsort(L,1); L
%1 = List([1,2,3,5])
? j = setsearch(L, 4, 1) \\ 4 should have been inserted at index j
%2 = 4
? listinsert(L, 4, j); L
%3 = List([1, 2, 3, 4, 5])
@eprog
Function: setunion
Class: basic
Section: linear_algebra
C-Name: setunion
Prototype: GG
Help: setunion(x,y): union of the sets x and y.
Description:
(vec, vec):vec setunion($1, $2)
Doc: union of the two sets $x$ and $y$ (see \kbd{setisset}).
If $x$ or $y$ is not a set, the result is undefined.
Function: shift
Class: basic
Section: operators
C-Name: gshift
Prototype: GL
Help: shift(x,n): shift x left n bits if n>=0, right -n bits if
n<0.
Doc: shifts $x$ componentwise left by $n$ bits if $n\ge0$ and right by $|n|$
bits if $n<0$. May be abbreviated as $x$ \kbd{<<} $n$ or $x$ \kbd{>>} $(-n)$.
A left shift by $n$ corresponds to multiplication by $2^n$. A right shift of an
integer $x$ by $|n|$ corresponds to a Euclidean division of $x$ by $2^{|n|}$
with a remainder of the same sign as $x$, hence is not the same (in general) as
$x \kbd{\bs} 2^n$.
Function: shiftmul
Class: basic
Section: operators
C-Name: gmul2n
Prototype: GL
Help: shiftmul(x,n): multiply x by 2^n (n>=0 or n<0).
Doc: multiplies $x$ by $2^n$. The difference with
\kbd{shift} is that when $n<0$, ordinary division takes place, hence for
example if $x$ is an integer the result may be a fraction, while for shifts
Euclidean division takes place when $n<0$ hence if $x$ is an integer the result
is still an integer.
Function: sigma
Class: basic
Section: number_theoretical
C-Name: sumdivk
Prototype: GD1,L,
Help: sigma(x,{k=1}): sum of the k-th powers of the divisors of x. k is
optional and if omitted is assumed to be equal to 1.
Description:
(gen, ?1):int sumdiv($1)
(gen, 0):int numdiv($1)
Doc: sum of the $k^{\text{th}}$ powers of the positive divisors of $|x|$. $x$
and $k$ must be of type integer.
Variant: Also available is \fun{GEN}{sumdiv}{GEN n}, for $k = 1$.
Function: sign
Class: basic
Section: operators
C-Name: gsigne
Prototype: iG
Help: sign(x): sign of x, of type integer, real or fraction.
Description:
(mp):small signe($1)
(gen):small gsigne($1)
Doc: \idx{sign} ($0$, $1$ or $-1$) of $x$, which must be of
type integer, real or fraction; \typ{QUAD} with positive discriminants and
\typ{INFINITY} are also supported.
Function: simplify
Class: basic
Section: conversions
C-Name: simplify
Prototype: G
Help: simplify(x): simplify the object x as much as possible.
Doc:
this function simplifies $x$ as much as it can. Specifically, a complex or
quadratic number whose imaginary part is the integer 0 (i.e.~not \kbd{Mod(0,2)}
or \kbd{0.E-28}) is converted to its real part, and a polynomial of degree $0$
is converted to its constant term. Simplifications occur recursively.
This function is especially useful before using arithmetic functions,
which expect integer arguments:
\bprog
? x = 2 + y - y
%1 = 2
? isprime(x)
*** at top-level: isprime(x)
*** ^----------
*** isprime: not an integer argument in an arithmetic function
? type(x)
%2 = "t_POL"
? type(simplify(x))
%3 = "t_INT"
@eprog
Note that GP results are simplified as above before they are stored in the
history. (Unless you disable automatic simplification with \b{y}, that is.)
In particular
\bprog
? type(%1)
%4 = "t_INT"
@eprog
Function: sin
Class: basic
Section: transcendental
C-Name: gsin
Prototype: Gp
Help: sin(x): sine of x.
Doc: sine of $x$.
Function: sinc
Class: basic
Section: transcendental
C-Name: gsinc
Prototype: Gp
Help: sinc(x): sinc function of x.
Doc: cardinal sine of $x$, i.e. $\sin(x)/x$ if $x\neq 0$, $1$ otherwise.
Note that this function also allows to compute
$$(1-\cos(x)) / x^2 = \kbd{sinc}(x/2)^2 / 2$$
accurately near $x = 0$.
Function: sinh
Class: basic
Section: transcendental
C-Name: gsinh
Prototype: Gp
Help: sinh(x): hyperbolic sine of x.
Doc: hyperbolic sine of $x$.
Function: sizebyte
Class: basic
Section: conversions
C-Name: gsizebyte
Prototype: lG
Help: sizebyte(x): number of bytes occupied by the complete tree of the
object x.
Doc: outputs the total number of bytes occupied by the tree representing the
PARI object $x$.
Variant: Also available is \fun{long}{gsizeword}{GEN x} returning a
number of \emph{words}.
Function: sizedigit
Class: basic
Section: conversions
C-Name: sizedigit
Prototype: lG
Help: sizedigit(x): rough upper bound for the number of decimal digits
of (the components of) $x$. DEPRECATED.
Doc:
This function is DEPRECATED, essentially meaningless, and provided for
backwards compatibility only. Don't use it!
outputs a quick upper bound for the number of decimal digits of (the
components of) $x$, off by at most $1$. More precisely, for a positive
integer $x$, it computes (approximately) the ceiling of
$$\kbd{floor}(1 + \log_2 x) \log_{10}2,$$
To count the number of decimal digits of a positive integer $x$, use
\kbd{\#digits(x)}. To estimate (recursively) the size of $x$, use
\kbd{normlp(x)}.
Obsolete: 2015-01-13
Function: solve
Class: basic
Section: sums
C-Name: zbrent0
Prototype: V=GGEp
Help: solve(X=a,b,expr): real root of expression expr (X between a and b),
where expr(a)*expr(b)<=0.
Wrapper: (,,G)
Description:
(gen,gen,gen):gen:prec zbrent(${3 cookie}, ${3 wrapper}, $1, $2, $prec)
Doc: find a real root of expression
\var{expr} between $a$ and $b$, under the condition
$\var{expr}(X=a) * \var{expr}(X=b) \le 0$. (You will get an error message
\kbd{roots must be bracketed in solve} if this does not hold.)
This routine uses Brent's method and can fail miserably if \var{expr} is
not defined in the whole of $[a,b]$ (try \kbd{solve(x=1, 2, tan(x))}).
\synt{zbrent}{void *E,GEN (*eval)(void*,GEN),GEN a,GEN b,long prec}.
Function: solvestep
Class: basic
Section: sums
C-Name: solvestep0
Prototype: V=GGGED0,L,p
Help: solvestep(X=a,b,step,expr,{flag=0}): find zeros of a function in the real
interval [a,b] by naive interval splitting.
Wrapper: (,,,G)
Description:
(gen,gen,gen,gen, ?0$):gen:prec solvestep(${4 cookie}, ${4 wrapper}, $1, $2, $3, $5, $prec)
Doc: find zeros of a continuous function in the real interval $[a,b]$ by naive
interval splitting. This function is heuristic and may or may not find the
intended zeros. Binary digits of \fl\ mean
\item 1: return as soon as one zero is found, otherwise return all
zeros found;
\item 2: refine the splitting until at least one zero is found
(may loop indefinitely if there are no zeros);
\item 4: do a multiplicative search (we must have $a > 0$ and $\var{step} >
1$), otherwise an additive search; \var{step} is the multiplicative or
additive step.
\item 8: refine the splitting until at least one zero is very close to an
integer.
\bprog
? solvestep(X=0,10,1,sin(X^2),1)
%1 = 1.7724538509055160272981674833411451828
? solvestep(X=1,12,2,besselj(4,X),4)
%2 = [7.588342434..., 11.064709488...]
@eprog\noindent
\synt{solvestep}{void *E, GEN (*eval)(void*,GEN), GEN a,GEN b, GEN step,long flag,long prec}.
Function: sqr
Class: basic
Section: transcendental
C-Name: gsqr
Prototype: G
Help: sqr(x): square of x. NOT identical to x*x.
Description:
(int):int sqri($1)
(mp):mp gsqr($1)
(gen):gen gsqr($1)
Doc: square of $x$. This operation is not completely
straightforward, i.e.~identical to $x * x$, since it can usually be
computed more efficiently (roughly one-half of the elementary
multiplications can be saved). Also, squaring a $2$-adic number increases
its precision. For example,
\bprog
? (1 + O(2^4))^2
%1 = 1 + O(2^5)
? (1 + O(2^4)) * (1 + O(2^4))
%2 = 1 + O(2^4)
@eprog\noindent
Note that this function is also called whenever one multiplies two objects
which are known to be \emph{identical}, e.g.~they are the value of the same
variable, or we are computing a power.
\bprog
? x = (1 + O(2^4)); x * x
%3 = 1 + O(2^5)
? (1 + O(2^4))^4
%4 = 1 + O(2^6)
@eprog\noindent
(note the difference between \kbd{\%2} and \kbd{\%3} above).
Function: sqrt
Class: basic
Section: transcendental
C-Name: gsqrt
Prototype: Gp
Help: sqrt(x): square root of x.
Description:
(real):gen sqrtr($1)
(gen):gen:prec gsqrt($1, $prec)
Doc: principal branch of the square root of $x$, defined as $\sqrt{x} =
\exp(\log x / 2)$. In particular, we have
$\text{Arg}(\text{sqrt}(x))\in{} ]-\pi/2, \pi/2]$, and if $x\in \R$ and $x<0$,
then the result is complex with positive imaginary part.
Intmod a prime $p$, \typ{PADIC} and \typ{FFELT} are allowed as arguments. In
the first 2 cases (\typ{INTMOD}, \typ{PADIC}), the square root (if it
exists) which is returned is the one whose first $p$-adic digit is in the
interval $[0,p/2]$. For other arguments, the result is undefined.
Variant: For a \typ{PADIC} $x$, the function
\fun{GEN}{Qp_sqrt}{GEN x} is also available.
Function: sqrtint
Class: basic
Section: number_theoretical
C-Name: sqrtint
Prototype: G
Help: sqrtint(x): integer square root of x, where x is a non-negative integer.
Description:
(gen):int sqrtint($1)
Doc: returns the integer square root of $x$, i.e. the largest integer $y$
such that $y^2 \leq x$, where $x$ a non-negative integer.
\bprog
? N = 120938191237; sqrtint(N)
%1 = 347761
? sqrt(N)
%2 = 347761.68741970412747602130964414095216
@eprog
Function: sqrtn
Class: basic
Section: transcendental
C-Name: gsqrtn
Prototype: GGD&p
Help: sqrtn(x,n,{&z}): nth-root of x, n must be integer. If present, z is
set to a suitable root of unity to recover all solutions. If it was not
possible, z is set to zero.
Doc: principal branch of the $n$th root of $x$,
i.e.~such that $\text{Arg}(\text{sqrtn}(x))\in{} ]-\pi/n, \pi/n]$. Intmod
a prime and $p$-adics are allowed as arguments.
If $z$ is present, it is set to a suitable root of unity allowing to
recover all the other roots. If it was not possible, z is
set to zero. In the case this argument is present and no $n$th root exist,
$0$ is returned instead of raising an error.
\bprog
? sqrtn(Mod(2,7), 2)
%1 = Mod(3, 7)
? sqrtn(Mod(2,7), 2, &z); z
%2 = Mod(6, 7)
? sqrtn(Mod(2,7), 3)
*** at top-level: sqrtn(Mod(2,7),3)
*** ^-----------------
*** sqrtn: nth-root does not exist in gsqrtn.
? sqrtn(Mod(2,7), 3, &z)
%2 = 0
? z
%3 = 0
@eprog
The following script computes all roots in all possible cases:
\bprog
sqrtnall(x,n)=
{ my(V,r,z,r2);
r = sqrtn(x,n, &z);
if (!z, error("Impossible case in sqrtn"));
if (type(x) == "t_INTMOD" || type(x)=="t_PADIC",
r2 = r*z; n = 1;
while (r2!=r, r2*=z;n++));
V = vector(n); V[1] = r;
for(i=2, n, V[i] = V[i-1]*z);
V
}
addhelp(sqrtnall,"sqrtnall(x,n):compute the vector of nth-roots of x");
@eprog\noindent
Variant: If $x$ is a \typ{PADIC}, the function
\fun{GEN}{Qp_sqrtn}{GEN x, GEN n, GEN *z} is also available.
Function: sqrtnint
Class: basic
Section: number_theoretical
C-Name: sqrtnint
Prototype: GL
Help: sqrtnint(x,n): integer n-th root of x, where x is non-negative integer.
Description:
(gen,small):int sqrtnint($1, $2)
Doc: returns the integer $n$-th root of $x$, i.e. the largest integer $y$ such
that $y^n \leq x$, where $x$ is a non-negative integer.
\bprog
? N = 120938191237; sqrtnint(N, 5)
%1 = 164
? N^(1/5)
%2 = 164.63140849829660842958614676939677391
@eprog\noindent The special case $n = 2$ is \tet{sqrtint}
Function: stirling
Class: basic
Section: number_theoretical
C-Name: stirling
Prototype: LLD1,L,
Help: stirling(n,k,{flag=1}): if flag=1 (default) return the Stirling number
of the first kind s(n,k), if flag=2, return the Stirling number of the second
kind S(n,k).
Doc: \idx{Stirling number} of the first kind $s(n,k)$ ($\fl=1$, default) or
of the second kind $S(n,k)$ (\fl=2), where $n$, $k$ are non-negative
integers. The former is $(-1)^{n-k}$ times the
number of permutations of $n$ symbols with exactly $k$ cycles; the latter is
the number of ways of partitioning a set of $n$ elements into $k$ non-empty
subsets. Note that if all $s(n,k)$ are needed, it is much faster to compute
$$\sum_k s(n,k) x^k = x(x-1)\dots(x-n+1).$$
Similarly, if a large number of $S(n,k)$ are needed for the same $k$,
one should use
$$\sum_n S(n,k) x^n = \dfrac{x^k}{(1-x)\dots(1-kx)}.$$
(Should be implemented using a divide and conquer product.) Here are
simple variants for $n$ fixed:
\bprog
/* list of s(n,k), k = 1..n */
vecstirling(n) = Vec( factorback(vector(n-1,i,1-i*'x)) )
/* list of S(n,k), k = 1..n */
vecstirling2(n) =
{ my(Q = x^(n-1), t);
vector(n, i, t = divrem(Q, x-i); Q=t[1]; simplify(t[2]));
}
@eprog
Variant: Also available are \fun{GEN}{stirling1}{ulong n, ulong k}
($\fl=1$) and \fun{GEN}{stirling2}{ulong n, ulong k} ($\fl=2$).
Function: subgrouplist
Class: basic
Section: number_fields
C-Name: subgrouplist0
Prototype: GDGD0,L,
Help: subgrouplist(bnr,{bound},{flag=0}): bnr being as output by bnrinit or
a list of cyclic components of a finite Abelian group G, outputs the list of
subgroups of G (of index bounded by bound, if not omitted), given as HNF
left divisors of the SNF matrix corresponding to G. If flag=0 (default) and
bnr is as output by bnrinit, gives only the subgroups for which the modulus
is the conductor.
Doc: \var{bnr} being as output by \kbd{bnrinit} or a list of cyclic components
of a finite Abelian group $G$, outputs the list of subgroups of $G$. Subgroups
are given as HNF left divisors of the SNF matrix corresponding to $G$.
If $\fl=0$ (default) and \var{bnr} is as output by \kbd{bnrinit}, gives
only the subgroups whose modulus is the conductor. Otherwise, the modulus is
not taken into account.
If \var{bound} is present, and is a positive integer, restrict the output to
subgroups of index less than \var{bound}. If \var{bound} is a vector
containing a single positive integer $B$, then only subgroups of index
exactly equal to $B$ are computed. For instance
\bprog
? subgrouplist([6,2])
%1 = [[6, 0; 0, 2], [2, 0; 0, 2], [6, 3; 0, 1], [2, 1; 0, 1], [3, 0; 0, 2],
[1, 0; 0, 2], [6, 0; 0, 1], [2, 0; 0, 1], [3, 0; 0, 1], [1, 0; 0, 1]]
? subgrouplist([6,2],3) \\@com index less than 3
%2 = [[2, 1; 0, 1], [1, 0; 0, 2], [2, 0; 0, 1], [3, 0; 0, 1], [1, 0; 0, 1]]
? subgrouplist([6,2],[3]) \\@com index 3
%3 = [[3, 0; 0, 1]]
? bnr = bnrinit(bnfinit(x), [120,[1]], 1);
? L = subgrouplist(bnr, [8]);
@eprog\noindent
In the last example, $L$ corresponds to the 24 subfields of
$\Q(\zeta_{120})$, of degree $8$ and conductor $120\infty$ (by setting \fl,
we see there are a total of $43$ subgroups of degree $8$).
\bprog
? vector(#L, i, galoissubcyclo(bnr, L[i]))
@eprog\noindent
will produce their equations. (For a general base field, you would
have to rely on \tet{bnrstark}, or \tet{rnfkummer}.)
Function: subst
Class: basic
Section: polynomials
C-Name: gsubst
Prototype: GnG
Help: subst(x,y,z): in expression x, replace the variable y by the
expression z.
Doc: replace the simple variable $y$ by the argument $z$ in the ``polynomial''
expression $x$. Every type is allowed for $x$, but if it is not a genuine
polynomial (or power series, or rational function), the substitution will be
done as if the scalar components were polynomials of degree zero. In
particular, beware that:
\bprog
? subst(1, x, [1,2; 3,4])
%1 =
[1 0]
[0 1]
? subst(1, x, Mat([0,1]))
*** at top-level: subst(1,x,Mat([0,1])
*** ^--------------------
*** subst: forbidden substitution by a non square matrix.
@eprog\noindent
If $x$ is a power series, $z$ must be either a polynomial, a power
series, or a rational function. Finally, if $x$ is a vector,
matrix or list, the substitution is applied to each individual entry.
Use the function \kbd{substvec} to replace several variables at once,
or the function \kbd{substpol} to replace a polynomial expression.
Function: substpol
Class: basic
Section: polynomials
C-Name: gsubstpol
Prototype: GGG
Help: substpol(x,y,z): in expression x, replace the polynomial y by the
expression z, using remainder decomposition of x.
Doc: replace the ``variable'' $y$ by the argument $z$ in the ``polynomial''
expression $x$. Every type is allowed for $x$, but the same behavior
as \kbd{subst} above apply.
The difference with \kbd{subst} is that $y$ is allowed to be any polynomial
here. The substitution is done moding out all components of $x$
(recursively) by $y - t$, where $t$ is a new free variable of lowest
priority. Then substituting $t$ by $z$ in the resulting expression. For
instance
\bprog
? substpol(x^4 + x^2 + 1, x^2, y)
%1 = y^2 + y + 1
? substpol(x^4 + x^2 + 1, x^3, y)
%2 = x^2 + y*x + 1
? substpol(x^4 + x^2 + 1, (x+1)^2, y)
%3 = (-4*y - 6)*x + (y^2 + 3*y - 3)
@eprog
Variant: Further, \fun{GEN}{gdeflate}{GEN T, long v, long d} attempts to
write $T(x)$ in the form $t(x^d)$, where $x=$\kbd{pol\_x}$(v)$, and returns
\kbd{NULL} if the substitution fails (for instance in the example \kbd{\%2}
above).
Function: substvec
Class: basic
Section: polynomials
C-Name: gsubstvec
Prototype: GGG
Help: substvec(x,v,w): in expression x, make a best effort to replace the
variables v1,...,vn by the expression w1,...,wn.
Doc: $v$ being a vector of monomials of degree 1 (variables),
$w$ a vector of expressions of the same length, replace in the expression
$x$ all occurrences of $v_i$ by $w_i$. The substitutions are done
simultaneously; more precisely, the $v_i$ are first replaced by new
variables in $x$, then these are replaced by the $w_i$:
\bprog
? substvec([x,y], [x,y], [y,x])
%1 = [y, x]
? substvec([x,y], [x,y], [y,x+y])
%2 = [y, x + y] \\ not [y, 2*y]
@eprog
Function: sum
Class: basic
Section: sums
C-Name: somme
Prototype: V=GGEDG
Help: sum(X=a,b,expr,{x=0}): x plus the sum (X goes from a to b) of
expression expr.
Doc: sum of expression \var{expr},
initialized at $x$, the formal parameter going from $a$ to $b$. As for
\kbd{prod}, the initialization parameter $x$ may be given to force the type
of the operations being performed.
\noindent As an extreme example, compare
\bprog
? sum(i=1, 10^4, 1/i); \\@com rational number: denominator has $4345$ digits.
time = 236 ms.
? sum(i=1, 5000, 1/i, 0.)
time = 8 ms.
%2 = 9.787606036044382264178477904
@eprog
\synt{somme}{GEN a, GEN b, char *expr, GEN x}.
Function: sumalt
Class: basic
Section: sums
C-Name: sumalt0
Prototype: V=GED0,L,p
Help: sumalt(X=a,expr,{flag=0}): Cohen-Villegas-Zagier's acceleration of
alternating series expr, X starting at a. flag is optional, and can be 0:
default, or 1: uses a slightly different method using Zagier's polynomials.
Wrapper: (,G)
Description:
(gen,gen,?0):gen:prec sumalt(${2 cookie}, ${2 wrapper}, $1, $prec)
(gen,gen,1):gen:prec sumalt2(${2 cookie}, ${2 wrapper}, $1, $prec)
Doc: numerical summation of the series \var{expr}, which should be an
\idx{alternating series} $(-1)^k a_k$, the formal variable $X$ starting at
$a$. Use an algorithm of Cohen, Villegas and Zagier (\emph{Experiment. Math.}
{\bf 9} (2000), no.~1, 3--12).
If $\fl=0$, assuming that the $a_k$ are the moments of a positive
measure on $[0,1]$, the relative error is $O(3+\sqrt8)^{-n}$ after using
$a_k$ for $k\leq n$. If \kbd{realprecision} is $p$, we thus set
$n = \log(10)p/\log(3+\sqrt8)\approx 1.3 p$; besides the time needed to
compute the $a_k$, $k\leq n$, the algorithm overhead is negligible: time
$O(p^2)$ and space $O(p)$.
If $\fl=1$, use a variant with more complicated polynomials, see
\tet{polzagier}. If the $a_k$ are the moments of $w(x)dx$ where $w$
(or only $xw(x^2)$) is a smooth function extending analytically to the whole
complex plane, convergence is in $O(14.4^{-n})$. If $xw(x^2)$ extends
analytically to a smaller region, we still have exponential convergence,
with worse constants. Usually faster when the computation of $a_k$ is
expensive. If \kbd{realprecision} is $p$, we thus set
$n = \log(10)p/\log(14.4)\approx 0.86 p$; besides the time needed to
compute the $a_k$, $k\leq n$, the algorithm overhead is \emph{not}
negligible: time $O(p^3)$ and space $O(p^2)$. Thus, even if the analytic
conditions for rigorous use are met, this variant is only worthwile if the
$a_k$ are hard to compute, at least $O(p^2)$ individually on average:
otherwise we gain a small constant factor (1.5, say) in the number of
needed $a_k$ at the expense of a large overhead.
The conditions for rigorous use are hard to check but the routine is best used
heuristically: even divergent alternating series can sometimes be summed by
this method, as well as series which are not exactly alternating (see for
example \secref{se:user_defined}). It should be used to try and guess the
value of an infinite sum. (However, see the example at the end of
\secref{se:userfundef}.)
If the series already converges geometrically,
\tet{suminf} is often a better choice:
\bprog
? \p28
? sumalt(i = 1, -(-1)^i / i) - log(2)
time = 0 ms.
%1 = -2.524354897 E-29
? suminf(i = 1, -(-1)^i / i) \\@com Had to hit \kbd{C-C}
*** at top-level: suminf(i=1,-(-1)^i/i)
*** ^------
*** suminf: user interrupt after 10min, 20,100 ms.
? \p1000
? sumalt(i = 1, -(-1)^i / i) - log(2)
time = 90 ms.
%2 = 4.459597722 E-1002
? sumalt(i = 0, (-1)^i / i!) - exp(-1)
time = 670 ms.
%3 = -4.03698781490633483156497361352190615794353338591897830587 E-944
? suminf(i = 0, (-1)^i / i!) - exp(-1)
time = 110 ms.
%4 = -8.39147638 E-1000 \\ @com faster and more accurate
@eprog
\synt{sumalt}{void *E, GEN (*eval)(void*,GEN),GEN a,long prec}. Also
available is \tet{sumalt2} with the same arguments ($\fl = 1$).
Function: sumdedekind
Class: basic
Section: number_theoretical
C-Name: sumdedekind
Prototype: GG
Help: sumdedekind(h,k): Dedekind sum attached to h,k.
Doc: returns the \idx{Dedekind sum} attached to the integers $h$ and $k$,
corresponding to a fast implementation of
\bprog
s(h,k) = sum(n = 1, k-1, (n/k)*(frac(h*n/k) - 1/2))
@eprog
Function: sumdigits
Class: basic
Section: number_theoretical
C-Name: sumdigits0
Prototype: GDG
Help: sumdigits(n,{B=10}): sum of digits in the integer n, when written in
base B.
Doc: sum of digits in the integer $n$, when written in base $B > 1$.
\bprog
? sumdigits(123456789)
%1 = 45
? sumdigits(123456789, 2)
%1 = 16
@eprog\noindent Note that the sum of bits in $n$ is also returned by
\tet{hammingweight}. This function is much faster than
\kbd{vecsum(digits(n,B))} when $B$ is $10$ or a power of $2$, and only
slightly faster in other cases.
Variant: Also available is \fun{GEN}{sumdigits}{GEN n}, for $B = 10$.
Function: sumdiv
Class: basic
Section: sums
C-Name: sumdivexpr
Prototype: GVE
Help: sumdiv(n,X,expr): sum of expression expr, X running over the divisors
of n.
Doc: sum of expression \var{expr} over the positive divisors of $n$.
This function is a trivial wrapper essentially equivalent to
\bprog
D = divisors(n);
for (i = 1, #D, X = D[i]; eval(expr))
@eprog\noindent (except that \kbd{X} is lexically scoped to the \kbd{sumdiv}
loop). If \var{expr} is a multiplicative function, use \tet{sumdivmult}.
%\syn{NO}
Function: sumdivmult
Class: basic
Section: sums
C-Name: sumdivmultexpr
Prototype: GVE
Help: sumdivmult(n,d,expr): sum of multiplicative function expr,
d running over the divisors of n.
Doc: sum of \emph{multiplicative} expression \var{expr} over the positive
divisors $d$ of $n$. Assume that \var{expr} evaluates to $f(d)$
where $f$ is multiplicative: $f(1) = 1$ and $f(ab) = f(a)f(b)$ for coprime
$a$ and $b$.
%\syn{NO}
Function: sumformal
Class: basic
Section: polynomials
C-Name: sumformal
Prototype: GDn
Help: sumformal(f,{v}): formal sum of f with respect to v, or to the
main variable of f if v is omitted.
Doc: \idx{formal sum} of the polynomial expression $f$ with respect to the
main variable if $v$ is omitted, with respect to the variable $v$ otherwise;
it is assumed that the base ring has characteristic zero. In other words,
considering $f$ as a polynomial function in the variable $v$,
returns $F$, a polynomial in $v$ vanishing at $0$, such that $F(b) - F(a)
= sum_{v = a+1}^b f(v)$:
\bprog
? sumformal(n) \\ 1 + ... + n
%1 = 1/2*n^2 + 1/2*n
? f(n) = n^3+n^2+1;
? F = sumformal(f(n)) \\ f(1) + ... + f(n)
%3 = 1/4*n^4 + 5/6*n^3 + 3/4*n^2 + 7/6*n
? sum(n = 1, 2000, f(n)) == subst(F, n, 2000)
%4 = 1
? sum(n = 1001, 2000, f(n)) == subst(F, n, 2000) - subst(F, n, 1000)
%5 = 1
? sumformal(x^2 + x*y + y^2, y)
%6 = y*x^2 + (1/2*y^2 + 1/2*y)*x + (1/3*y^3 + 1/2*y^2 + 1/6*y)
? x^2 * y + x * sumformal(y) + sumformal(y^2) == %
%7 = 1
@eprog
Function: suminf
Class: basic
Section: sums
C-Name: suminf0
Prototype: V=GEp
Help: suminf(X=a,expr): infinite sum (X goes from a to infinity) of real or
complex expression expr.
Wrapper: (,G)
Description:
(gen,gen):gen:prec suminf(${2 cookie}, ${2 wrapper}, $1, $prec)
Doc: \idx{infinite sum} of expression
\var{expr}, the formal parameter $X$ starting at $a$. The evaluation stops
when the relative error of the expression is less than the default precision
for 3 consecutive evaluations. The expressions must always evaluate to a
complex number.
If the series converges slowly, make sure \kbd{realprecision} is low (even 28
digits may be too much). In this case, if the series is alternating or the
terms have a constant sign, \tet{sumalt} and \tet{sumpos} should be used
instead.
\bprog
? \p28
? suminf(i = 1, -(-1)^i / i) \\@com Had to hit \kbd{C-C}
*** at top-level: suminf(i=1,-(-1)^i/i)
*** ^------
*** suminf: user interrupt after 10min, 20,100 ms.
? sumalt(i = 1, -(-1)^i / i) - log(2)
time = 0 ms.
%1 = -2.524354897 E-29
@eprog
\synt{suminf}{void *E, GEN (*eval)(void*,GEN), GEN a, long prec}.
Function: sumnum
Class: basic
Section: sums
C-Name: sumnum0
Prototype: V=GEDGp
Help: sumnum(n=a,f,{tab}): numerical summation of f(n) from
n = a to +infinity using Euler-MacLaurin summation. Assume that f
corresponds to a series with positive terms and is a C^oo function; a
must be an integer, and tab, if given, is the output of sumnuminit.
Wrapper: (,G)
Description:
(gen,gen,?gen):gen:prec sumnum(${2 cookie}, ${2 wrapper}, $1, $3, $prec)
Doc: Numerical summation of $f(n)$ at high accuracy using Euler-MacLaurin,
the variable $n$ taking values from $a$ to $+\infty$, where $f$ is assumed to
have positive values and is a $C^\infty$ function; \kbd{a} must be an integer
and \kbd{tab}, if given, is the output of \kbd{sumnuminit}. The latter
precomputes abcissas and weights, speeding up the computation; it also allows
to specify the behaviour at infinity via \kbd{sumnuminit([+oo, asymp])}.
\bprog
? \p500
? z3 = zeta(3);
? sumpos(n = 1, n^-3) - z3
time = 2,332 ms.
%2 = 2.438468843 E-501
? sumnum(n = 1, n^-3) - z3 \\ here slower than sumpos
time = 2,752 ms.
%3 = 0.E-500
@eprog
\misctitle{Complexity}
The function $f$ will be evaluated at $O(D \log D)$ real arguments,
where $D \approx \kbd{realprecision} \cdot \log(10)$. The routine is geared
towards slowly decreasing functions: if $f$ decreases exponentially fast,
then one of \kbd{suminf} or \kbd{sumpos} should be preferred.
If $f$ satisfies the stronger hypotheses required for Monien summation,
i.e. if $f(1/z)$ is holomorphic in a complex neighbourhood of $[0,1]$,
then \tet{sumnummonien} will be faster since it only requires $O(D/\log D)$
evaluations:
\bprog
? sumnummonien(n = 1, 1/n^3) - z3
time = 1,985 ms.
%3 = 0.E-500
@eprog\noindent The \kbd{tab} argument precomputes technical data
not depending on the expression being summed and valid for a given accuracy,
speeding up immensely later calls:
\bprog
? tab = sumnuminit();
time = 2,709 ms.
? sumnum(n = 1, 1/n^3, tab) - z3 \\ now much faster than sumpos
time = 40 ms.
%5 = 0.E-500
? tabmon = sumnummonieninit(); \\ Monien summation allows precomputations too
time = 1,781 ms.
? sumnummonien(n = 1, 1/n^3, tabmon) - z3
time = 2 ms.
%7 = 0.E-500
@eprog\noindent The speedup due to precomputations becomes less impressive
when the function $f$ is expensive to evaluate, though:
\bprog
? sumnum(n = 1, lngamma(1+1/n)/n, tab);
time = 14,180 ms.
? sumnummonien(n = 1, lngamma(1+1/n)/n, tabmon); \\ fewer evaluations
time = 717 ms.
@eprog
\misctitle{Behaviour at infinity}
By default, \kbd{sumnum} assumes that \var{expr} decreases slowly at infinity,
but at least like $O(n^{-2})$. If the function decreases like $n^{\alpha}$
for some $-2 < \alpha < -1$, then it must be indicated via
\bprog
tab = sumnuminit([+oo, alpha]); /* alpha < 0 slow decrease */
@eprog\noindent otherwise loss of accuracy is expected.
If the functions decreases quickly, like $\exp(-\alpha n)$ for some
$\alpha > 0$, then it must be indicated via
\bprog
tab = sumnuminit([+oo, alpha]); /* alpha > 0 exponential decrease */
@eprog\noindent otherwise exponent overflow will occur.
\bprog
? sumnum(n=1,2^-n)
*** at top-level: sumnum(n=1,2^-n)
*** ^----
*** _^_: overflow in expo().
? tab = sumnuminit([+oo,log(2)]); sumnum(n=1,2^-n, tab)
%1 = 1.000[...]
@eprog
As a shortcut, one can also input
\bprog
sumnum(n = [a, asymp], f)
@eprog\noindent instead of
\bprog
tab = sumnuminit(asymp);
sumnum(n = a, f, tab)
@eprog
\misctitle{Further examples}
\bprog
? \p200
? sumnum(n = 1, n^(-2)) - zeta(2) \\ accurate, fast
time = 200 ms.
%1 = -2.376364457868949779 E-212
? sumpos(n = 1, n^(-2)) - zeta(2) \\ even faster
time = 96 ms.
%2 = 0.E-211
? sumpos(n=1,n^(-4/3)) - zeta(4/3) \\ now much slower
time = 13,045 ms.
%3 = -9.980730723049589073 E-210
? sumnum(n=1,n^(-4/3)) - zeta(4/3) \\ fast but inaccurate
time = 365 ms.
%4 = -9.85[...]E-85
? sumnum(n=[1,-4/3],n^(-4/3)) - zeta(4/3) \\ with decrease rate, now accurate
time = 416 ms.
%5 = -4.134874156691972616 E-210
? tab = sumnuminit([+oo,-4/3]);
time = 196 ms.
? sumnum(n=1, n^(-4/3), tab) - zeta(4/3) \\ faster with precomputations
time = 216 ms.
%5 = -4.134874156691972616 E-210
? sumnum(n=1,-log(n)*n^(-4/3), tab) - zeta'(4/3)
time = 321 ms.
%7 = 7.224147951921607329 E-210
@eprog
Note that in the case of slow decrease ($\alpha < 0$), the exact
decrease rate must be indicated, while in the case of exponential decrease,
a rough value will do. In fact, for exponentially decreasing functions,
\kbd{sumnum} is given for completeness and comparison purposes only: one
of \kbd{suminf} or \kbd{sumpos} should always be preferred.
\bprog
? sumnum(n=[1, 1], 2^-n) \\ pretend we decrease as exp(-n)
time = 240 ms.
%8 = 1.000[...] \\ perfect
? sumpos(n=1, 2^-n)
%9 = 1.000[...] \\ perfect and instantaneous
@eprog
\synt{sumnum}{(void *E, GEN (*eval)(void*, GEN), GEN a, GEN tab, long prec)}
where an omitted \var{tab} is coded as \kbd{NULL}.
Function: sumnuminit
Class: basic
Section: sums
C-Name: sumnuminit
Prototype: DGp
Help: sumnuminit({asymp}): initialize tables for Euler-MacLaurin delta
summation of a series with positive terms.
Doc: initialize tables for Euler--MacLaurin delta summation of a series with
positive terms. If given, \kbd{asymp} is of the form $[\kbd{+oo}, \alpha]$,
as in \tet{intnum} and indicates the decrease rate at infinity of functions
to be summed. A positive
$\alpha > 0$ encodes an exponential decrease of type $\exp(-\alpha n)$ and
a negative $-2 < \alpha < -1$ encodes a slow polynomial decrease of type
$n^{\alpha}$.
\bprog
? \p200
? sumnum(n=1, n^-2);
time = 200 ms.
? tab = sumnuminit();
time = 188 ms.
? sumnum(n=1, n^-2, tab); \\ faster
time = 8 ms.
? tab = sumnuminit([+oo, log(2)]); \\ decrease like 2^-n
time = 200 ms.
? sumnum(n=1, 2^-n, tab)
time = 44 ms.
? tab = sumnuminit([+oo, -4/3]); \\ decrease like n^(-4/3)
time = 200 ms.
? sumnum(n=1, n^(-4/3), tab);
time = 221 ms.
@eprog
Function: sumnummonien
Class: basic
Section: sums
C-Name: sumnummonien0
Prototype: V=GEDGp
Help: sumnummonien(n=a,f,{tab}): numerical summation from
n = a to +infinity using Monien summation.
Wrapper: (,G)
Description:
(gen,gen,?gen):gen:prec sumnummonien(${2 cookie}, ${2 wrapper}, $1, $3, $prec)
Doc: numerical summation $\sum_{n\geq a} f(n)$ at high accuracy, the variable
$n$ taking values from the integer $a$ to $+\infty$ using Monien summation,
which assumes that $f(1/z)$ has a complex analytic continuation in a (complex)
neighbourhood of the segment $[0,1]$.
The function $f$ is evaluated at $O(D / \log D)$ real arguments,
where $D \approx \kbd{realprecision} \cdot \log(10)$.
By default, assume that $f(n) = O(n^{-2})$ and has a non-zero asymptotic
expansion
$$f(n) = \sum_{i\geq 2} a_i n^{-i}$$
at infinity. To handle more complicated behaviours and allow time-saving
precomputations (for a given \kbd{realprecision}), see \kbd{sumnummonieninit}.
Function: sumnummonieninit
Class: basic
Section: sums
C-Name: sumnummonieninit
Prototype: DGDGDGp
Help: sumnummonieninit({asymp},{w},{n0 = 1}): initialize tables for Monien summation of a series with positive terms.
Doc: initialize tables for Monien summation of a series $\sum_{n\geq n_0}
f(n)$ where $f(1/z)$ has a complex analytic continuation in a (complex)
neighbourhood of the segment $[0,1]$.
By default, assume that $f(n) = O(n^{-2})$ and has a non-zero asymptotic
expansion
$$f(n) = \sum_{i\geq 2} a_i / n^i$$
at infinity. Note that the sum starts at $i = 2$! The argument \kbd{asymp}
allows to specify different expansions:
\item a real number $\alpha > 1$ means
$$f(n) = \sum_{i\geq 1} a_i / n^{\alpha i}$$
(Now the summation starts at $1$.)
\item a vector $[\alpha,\beta]$ of reals, where we must have $\alpha > 0$
and $\alpha + \beta > 1$ to ensure convergence, means that
$$f(n) = \sum_{i\geq 1} a_i / n^{\alpha i + \beta}$$
Note that $\kbd{asymp} = [\alpha, \alpha]$ is equivalent to
$\kbd{asymp}=\alpha$.
\bprog
? \p57
? s = sumnum(n = 1, sin(1/sqrt(n)) / n); \\ reference point
? \p38
? sumnummonien(n = 1, sin(1/sqrt(n)) / n) - s
%2 = -0.001[...] \\ completely wrong
? t = sumnummonieninit([1,1/2]); \\ f(n) = sum_i 1 / n^(i/2+1)
? sumnummonien(n = 1, sin(1/sqrt(n)) / n, t) - s
%3 = 0.E-37 \\ now correct
@eprog\noindent (As a matter of fact, in the above summation, the
result given by \kbd{sumnum} at \kbd{\bs p38} is slighly incorrect,
so we had to increase the accuracy to \kbd{\bs p57}.)
The argument $w$ is used to sum expressions of the form
$$ \sum_{n\geq n_0} f(n) w(n),$$
for varying $f$ \emph{as above}, and fixed weight function $w$, where we
further assume that the auxiliary sums
$$g_w(m) = \sum_{n\geq n_0} w(n) / n^{\alpha m + \beta} $$
converge for all $m\geq 1$. Note that for non-negative integers $k$,
and weight $w(n) = (\log n)^k$, the function $g_w(m) = \zeta^{(k)}(\alpha m +
\beta)$ has a simple expression; for general weights, $g_w$ is
computed using \kbd{sumnum}. The following variants are available
\item an integer $k \geq 0$, to code $w(n) = (\log n)^k$;
only the cases $k = 0,1$ are presently implemented; due to a poor
implementation of $\zeta$ derivatives, it is not currently worth it
to exploit the special shape of $g_w$ when $k > 0$;
\item a \typ{CLOSURE} computing the values $w(n)$, where we
assume that $w(n) = O(n^\epsilon)$ for all $\epsilon > 0$;
\item a vector $[w, \kbd{fast}]$, where $w$ is a closure as above
and \kbd{fast} is a scalar;
we assume that $w(n) = O(n^{\kbd{fast}+\epsilon})$; note that
$\kbd{w} = [w, 0]$ is equivalent to $\kbd{w} = w$.
\item a vector $[w, \kbd{oo}]$, where $w$ is a closure as above;
we assume that $w(n)$ decreases exponentially. Note that in this case,
\kbd{sumnummonien} is provided for completeness and comparison purposes only:
one of \kbd{suminf} or \kbd{sumpos} should be preferred in practice.
The cases where $w$ is a closure or $w(n) = \log n$ are the only ones where
$n_0$ is taken into account and stored in the result. The subsequent call to
\kbd{sumnummonien} \emph{must} use the same value.
\bprog
? \p300
? sumnummonien(n = 1, n^-2*log(n)) + zeta'(2)
time = 536 ms.
%1 = -1.323[...]E-6 \\ completely wrong, f does not satisfy hypotheses !
? tab = sumnummonieninit(, 1); \\ codes w(n) = log(n)
time = 18,316 ms.
? sumnummonien(n = 1, n^-2, tab) + zeta'(2)
time = 44 ms.
%3 = -5.562684646268003458 E-309 \\ now perfect
? tab = sumnummonieninit(, n->log(n)); \\ generic, about as fast
time = 18,693 ms.
? sumnummonien(n = 1, n^-2, tab) + zeta'(2)
time = 40 ms.
%5 = -5.562684646268003458 E-309 \\ identical result
@eprog
Function: sumpos
Class: basic
Section: sums
C-Name: sumpos0
Prototype: V=GED0,L,p
Help: sumpos(X=a,expr,{flag=0}): sum of positive (or negative) series expr,
the formal
variable X starting at a. flag is optional, and can be 0: default, or 1:
uses a slightly different method using Zagier's polynomials.
Wrapper: (,G)
Description:
(gen,gen,?0):gen:prec sumpos(${2 cookie}, ${2 wrapper}, $1, $prec)
(gen,gen,1):gen:prec sumpos2(${2 cookie}, ${2 wrapper}, $1, $prec)
Doc: numerical summation of the series \var{expr}, which must be a series of
terms having the same sign, the formal variable $X$ starting at $a$. The
algorithm used is Van Wijngaarden's trick for converting such a series into
an alternating one, then we use \tet{sumalt}. For regular functions, the
function \kbd{sumnum} is in general much faster once the initializations
have been made using \kbd{sumnuminit}.
The routine is heuristic and assumes that \var{expr} is more or less a
decreasing function of $X$. In particular, the result will be completely
wrong if \var{expr} is 0 too often. We do not check either that all terms
have the same sign. As \tet{sumalt}, this function should be used to
try and guess the value of an infinite sum.
If $\fl=1$, use \kbd{sumalt}$(,1)$ instead of \kbd{sumalt}$(,0)$, see
\secref{se:sumalt}. Requiring more stringent analytic properties for
rigorous use, but allowing to compute fewer series terms.
To reach accuracy $10^{-p}$, both algorithms require $O(p^2)$ space;
furthermore, assuming the terms decrease polynomially (in $O(n^{-C})$), both
need to compute $O(p^2)$ terms. The \kbd{sumpos}$(,1)$ variant has a smaller
implied constant (roughly 1.5 times smaller). Since the \kbd{sumalt}$(,1)$
overhead is now small compared to the time needed to compute series terms,
this last variant should be about 1.5 faster. On the other hand, the
achieved accuracy may be much worse: as for \tet{sumalt}, since
conditions for rigorous use are hard to check, the routine is best used
heuristically.
\synt{sumpos}{void *E, GEN (*eval)(void*,GEN),GEN a,long prec}. Also
available is \tet{sumpos2} with the same arguments ($\fl = 1$).
Function: system
Class: basic
Section: programming/specific
C-Name: gpsystem
Prototype: vs
Help: system(str): str being a string, execute the system command str.
Doc: \var{str} is a string representing a system command. This command is
executed, its output written to the standard output (this won't get into your
logfile), and control returns to the PARI system. This simply calls the C
\kbd{system} command.
Function: tan
Class: basic
Section: transcendental
C-Name: gtan
Prototype: Gp
Help: tan(x): tangent of x.
Doc: tangent of $x$.
Function: tanh
Class: basic
Section: transcendental
C-Name: gtanh
Prototype: Gp
Help: tanh(x): hyperbolic tangent of x.
Doc: hyperbolic tangent of $x$.
Function: taylor
Class: basic
Section: polynomials
C-Name: tayl
Prototype: GnDP
Help: taylor(x,t,{d=seriesprecision}): taylor expansion of x with respect to
t, adding O(t^d) to all components of x.
Doc: Taylor expansion around $0$ of $x$ with respect to
the simple variable $t$. $x$ can be of any reasonable type, for example a
rational function. Contrary to \tet{Ser}, which takes the valuation into
account, this function adds $O(t^d)$ to all components of $x$.
\bprog
? taylor(x/(1+y), y, 5)
%1 = (y^4 - y^3 + y^2 - y + 1)*x + O(y^5)
? Ser(x/(1+y), y, 5)
*** at top-level: Ser(x/(1+y),y,5)
*** ^----------------
*** Ser: main variable must have higher priority in gtoser.
@eprog
Function: teichmuller
Class: basic
Section: transcendental
C-Name: teichmuller
Prototype: GDG
Help: teichmuller(x,{tab}): teichmuller character of p-adic number x. If
x = [p,n], return the lifts of all teichmuller(i + O(p^n)) for
i = 1, ..., p-1. Such a vector can be fed back to teichmuller, as the
optional argument tab, to speed up later computations.
Doc: Teichm\"uller character of the $p$-adic number $x$, i.e. the unique
$(p-1)$-th root of unity congruent to $x / p^{v_p(x)}$ modulo $p$.
If $x$ is of the form $[p,n]$, for a prime $p$ and integer $n$,
return the lifts to $\Z$ of the images of $i + O(p^n)$ for
$i = 1, \dots, p-1$, i.e. all roots of $1$ ordered by residue class modulo
$p$. Such a vector can be fed back to \kbd{teichmuller}, as the
optional argument \kbd{tab}, to speed up later computations.
\bprog
? z = teichmuller(2 + O(101^5))
%1 = 2 + 83*101 + 18*101^2 + 69*101^3 + 62*101^4 + O(101^5)
? z^100
%2 = 1 + O(101^5)
? T = teichmuller([101, 5]);
? teichmuller(2 + O(101^5), T)
%4 = 2 + 83*101 + 18*101^2 + 69*101^3 + 62*101^4 + O(101^5)
@eprog\noindent As a rule of thumb, if more than
$$p \,/\, 2(\log_2(p) + \kbd{hammingweight}(p))$$
values of \kbd{teichmuller} are to be computed, then it is worthwile to
initialize:
\bprog
? p = 101; n = 100; T = teichmuller([p,n]); \\ instantaneous
? for(i=1,10^3, vector(p-1, i, teichmuller(i+O(p^n), T)))
time = 60 ms.
? for(i=1,10^3, vector(p-1, i, teichmuller(i+O(p^n))))
time = 1,293 ms.
? 1 + 2*(log(p)/log(2) + hammingweight(p))
%8 = 22.316[...]
@eprog\noindent Here the precompuation induces a speedup by a factor
$1293/ 60 \approx 21.5$.
\misctitle{Caveat}
If the accuracy of \kbd{tab} (the argument $n$ above) is lower than the
precision of $x$, the \emph{former} is used, i.e. the cached value is not
refined to higher accuracy. It the accuracy of \kbd{tab} is larger, then
the precision of $x$ is used:
\bprog
? Tlow = teichmuller([101, 2]); \\ lower accuracy !
? teichmuller(2 + O(101^5), Tlow)
%10 = 2 + 83*101 + O(101^5) \\ no longer a root of 1
? Thigh = teichmuller([101, 10]); \\ higher accuracy
? teichmuller(2 + O(101^5), Thigh)
%12 = 2 + 83*101 + 18*101^2 + 69*101^3 + 62*101^4 + O(101^5)
@eprog
Variant:
Also available are the functions \fun{GEN}{teich}{GEN x} (\kbd{tab} is
\kbd{NULL}) as well as
\fun{GEN}{teichmullerinit}{long p, long n}.
Function: theta
Class: basic
Section: transcendental
C-Name: theta
Prototype: GGp
Help: theta(q,z): Jacobi sine theta-function.
Doc: Jacobi sine theta-function
$$ \theta_1(z, q) = 2q^{1/4} \sum_{n\geq 0} (-1)^n q^{n(n+1)} \sin((2n+1)z).$$
Function: thetanullk
Class: basic
Section: transcendental
C-Name: thetanullk
Prototype: GLp
Help: thetanullk(q,k): k-th derivative at z=0 of theta(q,z).
Doc: $k$-th derivative at $z=0$ of $\kbd{theta}(q,z)$.
Variant:
\fun{GEN}{vecthetanullk}{GEN q, long k, long prec} returns the vector
of all $\dfrac{d^i\theta}{dz^i}(q,0)$ for all odd $i = 1, 3, \dots, 2k-1$.
\fun{GEN}{vecthetanullk_tau}{GEN tau, long k, long prec} returns
\kbd{vecthetanullk\_tau} at $q = \exp(2i\pi \kbd{tau})$.
Function: thue
Class: basic
Section: polynomials
C-Name: thue
Prototype: GGDG
Help: thue(tnf,a,{sol}): solve the equation P(x,y)=a, where tnf was created
with thueinit(P), and sol, if present, contains the solutions of Norm(x)=a
modulo units in the number field defined by P. If tnf was computed without
assuming GRH (flag 1 in thueinit), the result is unconditional. If tnf is a
polynomial, compute thue(thueinit(P,0), a).
Doc: returns all solutions of the equation
$P(x,y)=a$ in integers $x$ and $y$, where \var{tnf} was created with
$\kbd{thueinit}(P)$. If present, \var{sol} must contain the solutions of
$\Norm(x)=a$ modulo units of positive norm in the number field
defined by $P$ (as computed by \kbd{bnfisintnorm}). If there are infinitely
many solutions, an error is issued.
It is allowed to input directly the polynomial $P$ instead of a \var{tnf},
in which case, the function first performs \kbd{thueinit(P,0)}. This is
very wasteful if more than one value of $a$ is required.
If \var{tnf} was computed without assuming GRH (flag $1$ in \tet{thueinit}),
then the result is unconditional. Otherwise, it depends in principle of the
truth of the GRH, but may still be unconditionally correct in some
favorable cases. The result is conditional on the GRH if
$a\neq \pm 1$ and, $P$ has a single irreducible rational factor, whose
attached tentative class number $h$ and regulator $R$ (as computed
assuming the GRH) satisfy
\item $h > 1$,
\item $R/0.2 > 1.5$.
Here's how to solve the Thue equation $x^{13} - 5y^{13} = - 4$:
\bprog
? tnf = thueinit(x^13 - 5);
? thue(tnf, -4)
%1 = [[1, 1]]
@eprog\noindent In this case, one checks that \kbd{bnfinit(x\pow13 -5).no}
is $1$. Hence, the only solution is $(x,y) = (1,1)$, and the result is
unconditional. On the other hand:
\bprog
? P = x^3-2*x^2+3*x-17; tnf = thueinit(P);
? thue(tnf, -15)
%2 = [[1, 1]] \\ a priori conditional on the GRH.
? K = bnfinit(P); K.no
%3 = 3
? K.reg
%4 = 2.8682185139262873674706034475498755834
@eprog
This time the result is conditional. All results computed using this
particular \var{tnf} are likewise conditional, \emph{except} for a right-hand
side of $\pm 1$.
The above result is in fact correct, so we did not just disprove the GRH:
\bprog
? tnf = thueinit(x^3-2*x^2+3*x-17, 1 /*unconditional*/);
? thue(tnf, -15)
%4 = [[1, 1]]
@eprog
Note that reducible or non-monic polynomials are allowed:
\bprog
? tnf = thueinit((2*x+1)^5 * (4*x^3-2*x^2+3*x-17), 1);
? thue(tnf, 128)
%2 = [[-1, 0], [1, 0]]
@eprog\noindent Reducible polynomials are in fact much easier to handle.
Function: thueinit
Class: basic
Section: polynomials
C-Name: thueinit
Prototype: GD0,L,p
Help: thueinit(P,{flag=0}): initialize the tnf corresponding to P, that will
be used to solve Thue equations P(x,y) = some-integer. If flag is non-zero,
certify the result unconditionaly. Otherwise, assume GRH (much faster of
course).
Doc: initializes the \var{tnf} corresponding to $P$, a non-constant
univariate polynomial with integer coefficients.
The result is meant to be used in conjunction with \tet{thue} to solve Thue
equations $P(X / Y)Y^{\deg P} = a$, where $a$ is an integer. Accordingly,
$P$ must either have at least two distinct irreducible factors over $\Q$,
or have one irreducible factor $T$ with degree $>2$ or two conjugate
complex roots: under these (necessary and sufficient) conditions, the
equation has finitely many integer solutions.
\bprog
? S = thueinit(t^2+1);
? thue(S, 5)
%2 = [[-2, -1], [-2, 1], [-1, -2], [-1, 2], [1, -2], [1, 2], [2, -1], [2, 1]]
? S = thueinit(t+1);
*** at top-level: thueinit(t+1)
*** ^-------------
*** thueinit: domain error in thueinit: P = t + 1
@eprog\noindent The hardest case is when $\deg P > 2$ and $P$ is irreducible
with at least one real root. The routine then uses Bilu-Hanrot's algorithm.
If $\fl$ is non-zero, certify results unconditionally. Otherwise, assume
\idx{GRH}, this being much faster of course. In the latter case, the result
may still be unconditionally correct, see \tet{thue}. For instance in most
cases where $P$ is reducible (not a pure power of an irreducible), \emph{or}
conditional computed class groups are trivial \emph{or} the right hand side
is $\pm1$, then results are unconditional.
\misctitle{Note} The general philosophy is to disprove the existence of large
solutions then to enumerate bounded solutions naively. The implementation
will overflow when there exist huge solutions and the equation has degree
$> 2$ (the quadratic imaginary case is special, since we can use
\kbd{bnfisintnorm}):
\bprog
? thue(t^3+2, 10^30)
*** at top-level: L=thue(t^3+2,10^30)
*** ^-----------------
*** thue: overflow in thue (SmallSols): y <= 80665203789619036028928.
? thue(x^2+2, 10^30) \\ quadratic case much easier
%1 = [[-1000000000000000, 0], [1000000000000000, 0]]
@eprog
\misctitle{Note} It is sometimes possible to circumvent the above, and in any
case obtain an important speed-up, if you can write $P = Q(x^d)$ for some $d >
1$ and $Q$ still satisfying the \kbd{thueinit} hypotheses. You can then solve
the equation attached to $Q$ then eliminate all solutions $(x,y)$ such that
either $x$ or $y$ is not a $d$-th power.
\bprog
? thue(x^4+1, 10^40); \\ stopped after 10 hours
? filter(L,d) =
my(x,y); [[x,y] | v<-L, ispower(v[1],d,&x)&&ispower(v[2],d,&y)];
? L = thue(x^2+1, 10^40);
? filter(L, 2)
%4 = [[0, 10000000000], [10000000000, 0]]
@eprog\noindent The last 2 commands use less than 20ms.
Function: trace
Class: basic
Section: linear_algebra
C-Name: gtrace
Prototype: G
Help: trace(x): trace of x.
Doc: this applies to quite general $x$. If $x$ is not a
matrix, it is equal to the sum of $x$ and its conjugate, except for polmods
where it is the trace as an algebraic number.
For $x$ a square matrix, it is the ordinary trace. If $x$ is a
non-square matrix (but not a vector), an error occurs.
Function: trap
Class: basic
Section: programming/specific
C-Name: trap0
Prototype: DrDEDE
Help: trap({e}, {rec}, seq): this function is obsolete, use "iferr".
Try to execute seq, trapping runtime error e (all of them if e omitted);
sequence rec is executed if the error occurs and is the result of the command.
Wrapper: (,_,_)
Description:
(?str,?closure,?closure):gen trap0($1, $2, $3)
Doc: This function is obsolete, use \tet{iferr}, which has a nicer and much
more powerful interface. For compatibility's sake we now describe the
\emph{obsolete} function \tet{trap}.
This function tries to
evaluate \var{seq}, trapping runtime error $e$, that is effectively preventing
it from aborting computations in the usual way; the recovery sequence
\var{rec} is executed if the error occurs and the evaluation of \var{rec}
becomes the result of the command. If $e$ is omitted, all exceptions are
trapped. See \secref{se:errorrec} for an introduction to error recovery
under \kbd{gp}.
\bprog
? \\@com trap division by 0
? inv(x) = trap (e_INV, INFINITY, 1/x)
? inv(2)
%1 = 1/2
? inv(0)
%2 = INFINITY
@eprog\noindent
Note that \var{seq} is effectively evaluated up to the point that produced
the error, and the recovery sequence is evaluated starting from that same
context, it does not "undo" whatever happened in the other branch (restore
the evaluation context):
\bprog
? x = 1; trap (, /* recover: */ x, /* try: */ x = 0; 1/x)
%1 = 0
@eprog
\misctitle{Note} The interface is currently not adequate for trapping
individual exceptions. In the current version \vers, the following keywords
are recognized, but the name list will be expanded and changed in the
future (all library mode errors can be trapped: it's a matter of defining
the keywords to \kbd{gp}):
\kbd{e\_ALARM}: alarm time-out
\kbd{e\_ARCH}: not available on this architecture or operating system
\kbd{e\_STACK}: the PARI stack overflows
\kbd{e\_INV}: impossible inverse
\kbd{e\_IMPL}: not yet implemented
\kbd{e\_OVERFLOW}: all forms of arithmetic overflow, including length
or exponent overflow (when a larger value is supplied than the
implementation can handle).
\kbd{e\_SYNTAX}: syntax error
\kbd{e\_MISC}: miscellaneous error
\kbd{e\_TYPE}: wrong type
\kbd{e\_USER}: user error (from the \kbd{error} function)
Obsolete: 2012-01-17
Function: truncate
Class: basic
Section: conversions
C-Name: trunc0
Prototype: GD&
Help: truncate(x,{&e}): truncation of x; when x is a power series,take away
the O(X^). If e is present, do not take into account loss of integer part
precision, and set e = error estimate in bits.
Description:
(small):small:parens $1
(int):int:copy:parens $1
(real):int truncr($1)
(mp):int mptrunc($1)
(mp, &small):int gcvtoi($1, &$2)
(mp, &int):int trunc0($1, &$2)
(gen):gen gtrunc($1)
(gen, &small):gen gcvtoi($1, &$2)
(gen, &int):gen trunc0($1, &$2)
Doc: truncates $x$ and sets $e$ to the number of
error bits. When $x$ is in $\R$, this means that the part after the decimal
point is chopped away, $e$ is the binary exponent of the difference between
the original and the truncated value (the ``fractional part''). If the
exponent of $x$ is too large compared to its precision (i.e.~$e>0$), the
result is undefined and an error occurs if $e$ was not given. The function
applies componentwise on vector / matrices; $e$ is then the maximal number of
error bits. If $x$ is a rational function, the result is the ``integer part''
(Euclidean quotient of numerator by denominator) and $e$ is not set.
Note a very special use of \kbd{truncate}: when applied to a power series, it
transforms it into a polynomial or a rational function with denominator
a power of $X$, by chopping away the $O(X^k)$. Similarly, when applied to
a $p$-adic number, it transforms it into an integer or a rational number
by chopping away the $O(p^k)$.
Variant: The following functions are also available: \fun{GEN}{gtrunc}{GEN x}
and \fun{GEN}{gcvtoi}{GEN x, long *e}.
Function: type
Class: basic
Section: programming/specific
C-Name: type0
Prototype: G
Help: type(x): return the type of the GEN x.
Description:
(gen):typ typ($1)
Doc: this is useful only under \kbd{gp}. Returns the internal type name of
the PARI object $x$ as a string. Check out existing type names with the
metacommand \b{t}. For example \kbd{type(1)} will return "\typ{INT}".
Variant: The macro \kbd{typ} is usually simpler to use since it returns a
\kbd{long} that can easily be matched with the symbols \typ{*}. The name
\kbd{type} was avoided since it is a reserved identifier for some compilers.
Function: unclone
Class: gp2c
Description:
(small):void (void)0 /*unclone*/
(gen):void gunclone($1)
Function: uninline
Class: basic
Section: programming/specific
Help: uninline(): forget all inline variables [EXPERIMENTAL].
Doc: (Experimental) Exit the scope of all current \kbd{inline} variables.
Function: until
Class: basic
Section: programming/control
C-Name: untilpari
Prototype: vEI
Help: until(a,seq): evaluate the expression sequence seq until a is nonzero.
Doc: evaluates \var{seq} until $a$ is not
equal to 0 (i.e.~until $a$ is true). If $a$ is initially not equal to 0,
\var{seq} is evaluated once (more generally, the condition on $a$ is tested
\emph{after} execution of the \var{seq}, not before as in \kbd{while}).
Function: valuation
Class: basic
Section: conversions
C-Name: gpvaluation
Prototype: GG
Help: valuation(x,p): valuation of x with respect to p.
Doc:
computes the highest
exponent of $p$ dividing $x$. If $p$ is of type integer, $x$ must be an
integer, an intmod whose modulus is divisible by $p$, a fraction, a
$q$-adic number with $q=p$, or a polynomial or power series in which case the
valuation is the minimum of the valuation of the coefficients.
If $p$ is of type polynomial, $x$ must be of type polynomial or rational
function, and also a power series if $x$ is a monomial. Finally, the
valuation of a vector, complex or quadratic number is the minimum of the
component valuations.
If $x=0$, the result is \kbd{+oo} if $x$ is an exact object. If $x$ is a
$p$-adic numbers or power series, the result is the exponent of the zero.
Any other type combinations gives an error.
Variant: Also available is
\fun{long}{gvaluation}{GEN x, GEN p}, which returns \tet{LONG_MAX} if $x = 0$
and the valuation as a \kbd{long} integer.
Function: varhigher
Class: basic
Section: conversions
C-Name: varhigher
Prototype: sDn
Help: varhigher(name,{v}): return a variable 'name' whose priority is
higher than the priority of v (of all existing variables if v is omitted).
Doc: return a variable \emph{name} whose priority is higher
than the priority of $v$ (of all existing variables if $v$ is omitted).
This is a counterpart to \tet{varlower}.
\bprog
? Pol([x,x], t)
*** at top-level: Pol([x,x],t)
*** ^------------
*** Pol: incorrect priority in gtopoly: variable x <= t
? t = varhigher("t", x);
? Pol([x,x], t)
%3 = x*t + x
@eprog\noindent This routine is useful since new GP variables directly
created by the interpreter always have lower priority than existing
GP variables. When some basic objects already exist in a variable
that is incompatible with some function requirement, you can now
create a new variable with a suitable priority instead of changing variables
in existing objects:
\bprog
? K = nfinit(x^2+1);
? rnfequation(K,y^2-2)
*** at top-level: rnfequation(K,y^2-2)
*** ^--------------------
*** rnfequation: incorrect priority in rnfequation: variable y >= x
? y = varhigher("y", x);
? rnfequation(K, y^2-2)
%3 = y^4 - 2*y^2 + 9
@eprog\noindent
\misctitle{Caution 1}
The \emph{name} is an arbitrary character string, only used for display
purposes and need not be related to the GP variable holding the result, nor
to be a valid variable name. In particular the \emph{name} can
not be used to retrieve the variable, it is not even present in the parser's
hash tables.
\bprog
? x = varhigher("#");
? x^2
%2 = #^2
@eprog
\misctitle{Caution 2} There are a limited number of variables and if no
existing variable with the given display name has the requested
priority, the call to \kbd{varhigher} uses up one such slot. Do not create
new variables in this way unless it's absolutely necessary,
reuse existing names instead and choose sensible priority requirements:
if you only need a variable with higher priority than $x$, state so
rather than creating a new variable with highest priority.
\bprog
\\ quickly use up all variables
? n = 0; while(1,varhigher("tmp"); n++)
*** at top-level: n=0;while(1,varhigher("tmp");n++)
*** ^-------------------
*** varhigher: no more variables available.
*** Break loop: type 'break' to go back to GP prompt
break> n
65510
\\ infinite loop: here we reuse the same 'tmp'
? n = 0; while(1,varhigher("tmp", x); n++)
@eprog
Function: variable
Class: basic
Section: conversions
C-Name: gpolvar
Prototype: DG
Help: variable({x}): main variable of object x. Gives p for p-adic x, 0
if no variable can be attached to x. Returns the list of user variables if
x is omitted.
Description:
(pol):var:parens:copy $var:1
(gen):gen gpolvar($1)
Doc:
gives the main variable of the object $x$ (the variable with the highest
priority used in $x$), and $p$ if $x$ is a $p$-adic number. Return $0$ if
$x$ has no variable attached to it.
\bprog
? variable(x^2 + y)
%1 = x
? variable(1 + O(5^2))
%2 = 5
? variable([x,y,z,t])
%3 = x
? variable(1)
%4 = 0
@eprog\noindent The construction
\bprog
if (!variable(x),...)
@eprog\noindent can be used to test whether a variable is attached to $x$.
If $x$ is omitted, returns the list of user variables known to the
interpreter, by order of decreasing priority. (Highest priority is initially
$x$, which come first until \tet{varhigher} is used.) If \kbd{varhigher}
or \kbd{varlower} are used, it is quite possible to end up with different
variables (with different priorities) printed in the same way: they
will then appear multiple times in the output:
\bprog
? varhigher("y");
? varlower("y");
? variable()
%4 = [y, x, y]
@eprog\noindent Using \kbd{v = variable()} then \kbd{v[1]}, \kbd{v[2]},
etc.~allows to recover and use existing variables.
Variant: However, in library mode, this function should not be used for $x$
non-\kbd{NULL}, since \tet{gvar} is more appropriate. Instead, for
$x$ a $p$-adic (type \typ{PADIC}), $p$ is $gel(x,2)$; otherwise, use
\fun{long}{gvar}{GEN x} which returns the variable number of $x$ if
it exists, \kbd{NO\_VARIABLE} otherwise, which satisfies the property
$\kbd{varncmp}(\kbd{NO\_VARIABLE}, v) > 0$ for all valid variable number
$v$, i.e. it has lower priority than any variable.
Function: variables
Class: basic
Section: conversions
C-Name: variables_vec
Prototype: DG
Help: variables({x}): all variables occuring in object x, sorted by
decreasing priority. Returns the list of user variables if x is omitted.
Doc:
returns the list of all variables occuring in object $x$ (all user
variables known to the interpreter if $x$ is omitted), sorted by
decreasing priority.
\bprog
? variables([x^2 + y*z + O(t), a+x])
%1 = [x, y, z, t, a]
@eprog\noindent The construction
\bprog
if (!variables(x),...)
@eprog\noindent can be used to test whether a variable is attached to $x$.
If \kbd{varhigher} or \kbd{varlower} are used, it is quite possible to end up
with different variables (with different priorities) printed in the same
way: they will then appear multiple times in the output:
\bprog
? y1 = varhigher("y");
? y2 = varlower("y");
? variables(y*y1*y2)
%4 = [y, y, y]
@eprog
Variant:
Also available is \fun{GEN}{variables_vecsmall}{GEN x} which returns
the (sorted) variable numbers instead of the attached monomials of degree 1.
Function: varlower
Class: basic
Section: conversions
C-Name: varlower
Prototype: sDn
Help: varlower(name,{v}): return a variable 'name' whose priority is lower
than the priority of v (of all existing variables if v is omitted.
Doc: return a variable \emph{name} whose priority is lower
than the priority of $v$ (of all existing variables if $v$ is omitted).
This is a counterpart to \tet{varhigher}.
New GP variables directly created by the interpreter always
have lower priority than existing GP variables, but it is not easy
to check whether an identifier is currently unused, so that the
corresponding variable has the expected priority when it's created!
Thus, depending on the session history, the same command may fail or succeed:
\bprog
? t; z; \\ now t > z
? rnfequation(t^2+1,z^2-t)
*** at top-level: rnfequation(t^2+1,z^
*** ^--------------------
*** rnfequation: incorrect priority in rnfequation: variable t >= t
@eprog\noindent Restart and retry:
\bprog
? z; t; \\ now z > t
? rnfequation(t^2+1,z^2-t)
%2 = z^4 + 1
@eprog\noindent It is quite annoying for package authors, when trying to
define a base ring, to notice that the package may fail for some users
depending on their session history. The safe way to do this is as follows:
\bprog
? z; t; \\ In new session: now z > t
...
? t = varlower("t", 'z);
? rnfequation(t^2+1,z^2-2)
%2 = z^4 - 2*z^2 + 9
? variable()
%3 = [x, y, z, t]
@eprog
\bprog
? t; z; \\ In new session: now t > z
...
? t = varlower("t", 'z); \\ create a new variable, still printed "t"
? rnfequation(t^2+1,z^2-2)
%2 = z^4 - 2*z^2 + 9
? variable()
%3 = [x, y, t, z, t]
@eprog\noindent Now both constructions succeed. Note that in the
first case, \kbd{varlower} is essentially a no-op, the existing variable $t$
has correct priority. While in the second case, two different variables are
displayed as \kbd{t}, one with higher priority than $z$ (created in the first
line) and another one with lower priority (created by \kbd{varlower}).
\misctitle{Caution 1}
The \emph{name} is an arbitrary character string, only used for display
purposes and need not be related to the GP variable holding the result, nor
to be a valid variable name. In particular the \emph{name} can
not be used to retrieve the variable, it is not even present in the parser's
hash tables.
\bprog
? x = varlower("#");
? x^2
%2 = #^2
@eprog
\misctitle{Caution 2} There are a limited number of variables and if no
existing variable with the given display name has the requested
priority, the call to \kbd{varlower} uses up one such slot. Do not create
new variables in this way unless it's absolutely necessary,
reuse existing names instead and choose sensible priority requirements:
if you only need a variable with higher priority than $x$, state so
rather than creating a new variable with highest priority.
\bprog
\\ quickly use up all variables
? n = 0; while(1,varlower("x"); n++)
*** at top-level: n=0;while(1,varlower("x");n++)
*** ^-------------------
*** varlower: no more variables available.
*** Break loop: type 'break' to go back to GP prompt
break> n
65510
\\ infinite loop: here we reuse the same 'tmp'
? n = 0; while(1,varlower("tmp", x); n++)
@eprog
Function: vecextract
Class: basic
Section: linear_algebra
C-Name: extract0
Prototype: GGDG
Help: vecextract(x,y,{z}): extraction of the components of the matrix or
vector x according to y and z. If z is omitted, y represents columns, otherwise
y corresponds to rows and z to columns. y and z can be vectors (of indices),
strings (indicating ranges as in "1..10") or masks (integers whose binary
representation indicates the indices to extract, from left to right 1, 2, 4,
8, etc.).
Description:
(vec,gen,?gen):vec extract0($1, $2, $3)
Doc: extraction of components of the vector or matrix $x$ according to $y$.
In case $x$ is a matrix, its components are the \emph{columns} of $x$. The
parameter $y$ is a component specifier, which is either an integer, a string
describing a range, or a vector.
If $y$ is an integer, it is considered as a mask: the binary bits of $y$ are
read from right to left, but correspond to taking the components from left to
right. For example, if $y=13=(1101)_2$ then the components 1,3 and 4 are
extracted.
If $y$ is a vector (\typ{VEC}, \typ{COL} or \typ{VECSMALL}), which must have
integer entries, these entries correspond to the component numbers to be
extracted, in the order specified.
If $y$ is a string, it can be
\item a single (non-zero) index giving a component number (a negative
index means we start counting from the end).
\item a range of the form \kbd{"$a$..$b$"}, where $a$ and $b$ are
indexes as above. Any of $a$ and $b$ can be omitted; in this case, we take
as default values $a = 1$ and $b = -1$, i.e.~ the first and last components
respectively. We then extract all components in the interval $[a,b]$, in
reverse order if $b < a$.
In addition, if the first character in the string is \kbd{\pow}, the
complement of the given set of indices is taken.
If $z$ is not omitted, $x$ must be a matrix. $y$ is then the \emph{row}
specifier, and $z$ the \emph{column} specifier, where the component specifier
is as explained above.
\bprog
? v = [a, b, c, d, e];
? vecextract(v, 5) \\@com mask
%1 = [a, c]
? vecextract(v, [4, 2, 1]) \\@com component list
%2 = [d, b, a]
? vecextract(v, "2..4") \\@com interval
%3 = [b, c, d]
? vecextract(v, "-1..-3") \\@com interval + reverse order
%4 = [e, d, c]
? vecextract(v, "^2") \\@com complement
%5 = [a, c, d, e]
? vecextract(matid(3), "2..", "..")
%6 =
[0 1 0]
[0 0 1]
@eprog
The range notations \kbd{v[i..j]} and \kbd{v[\pow i]} (for \typ{VEC} or
\typ{COL}) and \kbd{M[i..j, k..l]} and friends (for \typ{MAT}) implement a
subset of the above, in a simpler and \emph{faster} way, hence should be
preferred in most common situations. The following features are not
implemented in the range notation:
\item reverse order,
\item omitting either $a$ or $b$ in \kbd{$a$..$b$}.
Function: vecmax
Class: basic
Section: operators
C-Name: vecmax0
Prototype: GD&
Help: vecmax(x,{&v}): largest entry in the vector/matrix x. If v
is present, set it to the index of a largest entry (indirect max).
Description:
(gen):gen vecmax($1)
(gen, &gen):gen vecmax0($1, &$2)
Doc: if $x$ is a vector or a matrix, returns the largest entry of $x$,
otherwise returns a copy of $x$. Error if $x$ is empty.
If $v$ is given, set it to the index of a largest entry (indirect maximum),
when $x$ is a vector. If $x$ is a matrix, set $v$ to coordinates $[i,j]$
such that $x[i,j]$ is a largest entry. This flag is ignored if $x$ is not a
vector or matrix.
\bprog
? vecmax([10, 20, -30, 40])
%1 = 40
? vecmax([10, 20, -30, 40], &v); v
%2 = 4
? vecmax([10, 20; -30, 40], &v); v
%3 = [2, 2]
@eprog
Variant: When $v$ is not needed, the function \fun{GEN}{vecmax}{GEN x} is
also available.
Function: vecmin
Class: basic
Section: operators
C-Name: vecmin0
Prototype: GD&
Help: vecmin(x,{&v}): smallest entry in the vector/matrix x. If v is
present, set it to the index of a smallest
entry (indirect min).
Description:
(gen):gen vecmin($1)
(gen, &gen):gen vecmin0($1, &$2)
Doc: if $x$ is a vector or a matrix, returns the smallest entry of $x$,
otherwise returns a copy of $x$. Error if $x$ is empty.
If $v$ is given, set it to the index of a smallest entry (indirect minimum),
when $x$ is a vector. If $x$ is a matrix, set $v$ to coordinates $[i,j]$ such
that $x[i,j]$ is a smallest entry. This is ignored if $x$ is not a vector or
matrix.
\bprog
? vecmin([10, 20, -30, 40])
%1 = -30
? vecmin([10, 20, -30, 40], &v); v
%2 = 3
? vecmin([10, 20; -30, 40], &v); v
%3 = [2, 1]
@eprog
Variant: When $v$ is not needed, the function \fun{GEN}{vecmin}{GEN x} is also
available.
Function: vecsearch
Class: basic
Section: linear_algebra
C-Name: vecsearch
Prototype: lGGDG
Help: vecsearch(v,x,{cmpf}): determines whether x belongs to the sorted
vector v. If the comparison function cmpf is explicitly given, assume
that v was sorted according to vecsort(, cmpf).
Doc: determines whether $x$ belongs to the sorted vector or list $v$: return
the (positive) index where $x$ was found, or $0$ if it does not belong to
$v$.
If the comparison function cmpf is omitted, we assume that $v$ is sorted in
increasing order, according to the standard comparison function \kbd{lex},
thereby restricting the possible types for $x$ and the elements of $v$
(integers, fractions, reals, and vectors of such).
If \kbd{cmpf} is present, it is understood as a comparison function and we
assume that $v$ is sorted according to it, see \tet{vecsort} for how to
encode comparison functions.
\bprog
? v = [1,3,4,5,7];
? vecsearch(v, 3)
%2 = 2
? vecsearch(v, 6)
%3 = 0 \\ not in the list
? vecsearch([7,6,5], 5) \\ unsorted vector: result undefined
%4 = 0
@eprog
By abuse of notation, $x$ is also allowed to be a matrix, seen as a vector
of its columns; again by abuse of notation, a \typ{VEC} is considered
as part of the matrix, if its transpose is one of the matrix columns.
\bprog
? v = vecsort([3,0,2; 1,0,2]) \\ sort matrix columns according to lex order
%1 =
[0 2 3]
[0 2 1]
? vecsearch(v, [3,1]~)
%2 = 3
? vecsearch(v, [3,1]) \\ can search for x or x~
%3 = 3
? vecsearch(v, [1,2])
%4 = 0 \\ not in the list
@eprog\noindent
Function: vecsort
Class: basic
Section: linear_algebra
C-Name: vecsort0
Prototype: GDGD0,L,
Help: vecsort(x,{cmpf},{flag=0}): sorts the vector of vectors (or matrix) x in
ascending order, according to the comparison function cmpf, if not omitted.
(If cmpf is an integer, sort according to the value of the k-th component
of each entry.) Binary digits of flag (if present) mean: 1: indirect sorting,
return the permutation instead of the permuted vector, 4: use descending
instead of ascending order, 8: remove duplicate entries.
Description:
(vecsmall,?gen):vecsmall vecsort0($1, $2, 0)
(vecsmall,?gen,small):vecsmall vecsort0($1, $2, $3)
(vec, , ?0):vec sort($1)
(vec, , 1):vecsmall indexsort($1)
(vec, , 2):vec lexsort($1)
(vec, gen):vec vecsort0($1, $2, 0)
(vec, ?gen, 1):vecsmall vecsort0($1, $2, 1)
(vec, ?gen, 3):vecsmall vecsort0($1, $2, 3)
(vec, ?gen, 5):vecsmall vecsort0($1, $2, 5)
(vec, ?gen, 7):vecsmall vecsort0($1, $2, 7)
(vec, ?gen, 9):vecsmall vecsort0($1, $2, 9)
(vec, ?gen, 11):vecsmall vecsort0($1, $2, 11)
(vec, ?gen, 13):vecsmall vecsort0($1, $2, 13)
(vec, ?gen, 15):vecsmall vecsort0($1, $2, 15)
(vec, ?gen, #small):vec vecsort0($1, $2, $3)
(vec, ?gen, small):gen vecsort0($1, $2, $3)
Doc: sorts the vector $x$ in ascending order, using a mergesort method.
$x$ must be a list, vector or matrix (seen as a vector of its columns).
Note that mergesort is stable, hence the initial ordering of ``equal''
entries (with respect to the sorting criterion) is not changed.
If \kbd{cmpf} is omitted, we use the standard comparison function
\kbd{lex}, thereby restricting the possible types for the elements of $x$
(integers, fractions or reals and vectors of those). If \kbd{cmpf} is
present, it is understood as a comparison function and we sort according to
it. The following possibilities exist:
\item an integer $k$: sort according to the value of the $k$-th
subcomponents of the components of~$x$.
\item a vector: sort lexicographically according to the components listed in
the vector. For example, if $\kbd{cmpf}=\kbd{[2,1,3]}$, sort with respect to
the second component, and when these are equal, with respect to the first,
and when these are equal, with respect to the third.
\item a comparison function (\typ{CLOSURE}), with two arguments $x$ and $y$,
and returning an integer which is $<0$, $>0$ or $=0$ if $x<y$, $x>y$ or
$x=y$ respectively. The \tet{sign} function is very useful in this context:
\bprog
? vecsort([3,0,2; 1,0,2]) \\ sort columns according to lex order
%1 =
[0 2 3]
[0 2 1]
? vecsort(v, (x,y)->sign(y-x)) \\@com reverse sort
? vecsort(v, (x,y)->sign(abs(x)-abs(y))) \\@com sort by increasing absolute value
? cmpf(x,y) = my(dx = poldisc(x), dy = poldisc(y)); sign(abs(dx) - abs(dy))
? vecsort([x^2+1, x^3-2, x^4+5*x+1], cmpf)
@eprog\noindent
The last example used the named \kbd{cmpf} instead of an anonymous function,
and sorts polynomials with respect to the absolute value of their
discriminant. A more efficient approach would use precomputations to ensure
a given discriminant is computed only once:
\bprog
? DISC = vector(#v, i, abs(poldisc(v[i])));
? perm = vecsort(vector(#v,i,i), (x,y)->sign(DISC[x]-DISC[y]))
? vecextract(v, perm)
@eprog\noindent Similar ideas apply whenever we sort according to the values
of a function which is expensive to compute.
\noindent The binary digits of \fl\ mean:
\item 1: indirect sorting of the vector $x$, i.e.~if $x$ is an
$n$-component vector, returns a permutation of $[1,2,\dots,n]$ which
applied to the components of $x$ sorts $x$ in increasing order.
For example, \kbd{vecextract(x, vecsort(x,,1))} is equivalent to
\kbd{vecsort(x)}.
\item 4: use descending instead of ascending order.
\item 8: remove ``duplicate'' entries with respect to the sorting function
(keep the first occurring entry). For example:
\bprog
? vecsort([Pi,Mod(1,2),z], (x,y)->0, 8) \\@com make everything compare equal
%1 = [3.141592653589793238462643383]
? vecsort([[2,3],[0,1],[0,3]], 2, 8)
%2 = [[0, 1], [2, 3]]
@eprog
Function: vecsum
Class: basic
Section: linear_algebra
C-Name: vecsum
Prototype: G
Help: vecsum(v): return the sum of the components of the vector v.
Doc: return the sum of the components of the vector $v$. Return $0$ on an
empty vector.
\bprog
? vecsum([1,2,3])
%1 = 6
? vecsum([])
%2 = 0
@eprog
Function: vector
Class: basic
Section: linear_algebra
C-Name: vecteur
Prototype: GDVDE
Help: vector(n,{X},{expr=0}): row vector with n components of expression
expr (X ranges from 1 to n). By default, fill with 0s.
Doc: creates a row vector (type
\typ{VEC}) with $n$ components whose components are the expression
\var{expr} evaluated at the integer points between 1 and $n$. If one of the
last two arguments is omitted, fill the vector with zeroes.
\bprog
? vector(3,i, 5*i)
%1 = [5, 10, 15]
? vector(3)
%2 = [0, 0, 0]
@eprog
The variable $X$ is lexically scoped to each evaluation of \var{expr}. Any
change to $X$ within \var{expr} does not affect subsequent evaluations, it
still runs 1 to $n$. A local change allows for example different indexing:
\bprog
vector(10, i, i=i-1; f(i)) \\ i = 0, ..., 9
vector(10, i, i=2*i; f(i)) \\ i = 2, 4, ..., 20
@eprog\noindent
This per-element scope for $X$ differs from \kbd{for} loop evaluations,
as the following example shows:
\bprog
n = 3
v = vector(n); vector(n, i, i++) ----> [2, 3, 4]
v = vector(n); for (i = 1, n, v[i] = i++) ----> [2, 0, 4]
@eprog\noindent
%\syn{NO}
Function: vectorsmall
Class: basic
Section: linear_algebra
C-Name: vecteursmall
Prototype: GDVDE
Help: vectorsmall(n,{X},{expr=0}): VECSMALL with n components of expression
expr (X ranges from 1 to n) which must be small integers. By default, fill
with 0s.
Doc: creates a row vector of small integers (type
\typ{VECSMALL}) with $n$ components whose components are the expression
\var{expr} evaluated at the integer points between 1 and $n$. If one of the
last two arguments is omitted, fill the vector with zeroes.
%\syn{NO}
Function: vectorv
Class: basic
Section: linear_algebra
C-Name: vvecteur
Prototype: GDVDE
Help: vectorv(n,{X},{expr=0}): column vector with n components of expression
expr (X ranges from 1 to n). By default, fill with 0s.
Doc: as \tet{vector}, but returns a column vector (type \typ{COL}).
%\syn{NO}
Function: version
Class: basic
Section: programming/specific
C-Name: pari_version
Prototype:
Help: version(): returns the PARI version as [major,minor,patch] or [major,minor,patch,VCSversion].
Doc: returns the current version number as a \typ{VEC} with three integer
components (major version number, minor version number and patchlevel);
if your sources were obtained through our version control system, this will
be followed by further more precise arguments, including
e.g.~a~\kbd{git} \emph{commit hash}.
This function is present in all versions of PARI following releases 2.3.4
(stable) and 2.4.3 (testing).
Unless you are working with multiple development versions, you probably only
care about the 3 first numeric components. In any case, the \kbd{lex} function
offers a clever way to check against a particular version number, since it will
compare each successive vector entry, numerically or as strings, and will not
mind if the vectors it compares have different lengths:
\bprog
if (lex(version(), [2,3,5]) >= 0,
\\ code to be executed if we are running 2.3.5 or more recent.
,
\\ compatibility code
);
@eprog\noindent On a number of different machines, \kbd{version()} could return either of
\bprog
%1 = [2, 3, 4] \\ released version, stable branch
%1 = [2, 4, 3] \\ released version, testing branch
%1 = [2, 6, 1, 15174, ""505ab9b"] \\ development
@eprog
In particular, if you are only working with released versions, the first
line of the gp introductory message can be emulated by
\bprog
[M,m,p] = version();
printf("GP/PARI CALCULATOR Version %s.%s.%s", M,m,p);
@eprog\noindent If you \emph{are} working with many development versions of
PARI/GP, the 4th and/or 5th components can be profitably included in the
name of your logfiles, for instance.
\misctitle{Technical note} For development versions obtained via \kbd{git},
the 4th and 5th components are liable to change eventually, but we document
their current meaning for completeness. The 4th component counts the number
of reachable commits in the branch (analogous to \kbd{svn}'s revision
number), and the 5th is the \kbd{git} commit hash. In particular, \kbd{lex}
comparison still orders correctly development versions with respect to each
others or to released versions (provided we stay within a given branch,
e.g. \kbd{master})!
Function: warning
Class: basic
Section: programming/specific
C-Name: warning0
Prototype: vs*
Help: warning({str}*): display warning message str.
Description:
(?gen,...):void pari_warn(warnuser, "${2 format_string}"${2 format_args})
Doc: outputs the message ``user warning''
and the argument list (each of them interpreted as a string).
If colors are enabled, this warning will be in a different color,
making it easy to distinguish.
\bprog
warning(n, " is very large, this might take a while.")
@eprog
% \syn{NO}
Function: weber
Class: basic
Section: transcendental
C-Name: weber0
Prototype: GD0,L,p
Help: weber(x,{flag=0}): one of Weber's f function of x. flag is optional,
and can be 0: default, function f(x)=exp(-i*Pi/24)*eta((x+1)/2)/eta(x),
1: function f1(x)=eta(x/2)/eta(x)
2: function f2(x)=sqrt(2)*eta(2*x)/eta(x). Note that
j = (f^24-16)^3/f^24 = (f1^24+16)^3/f1^24 = (f2^24+16)^3/f2^24.
Doc: one of Weber's three $f$ functions.
If $\fl=0$, returns
$$f(x)=\exp(-i\pi/24)\cdot\eta((x+1)/2)\,/\,\eta(x) \quad\hbox{such that}\quad
j=(f^{24}-16)^3/f^{24}\,,$$
where $j$ is the elliptic $j$-invariant (see the function \kbd{ellj}).
If $\fl=1$, returns
$$f_1(x)=\eta(x/2)\,/\,\eta(x)\quad\hbox{such that}\quad
j=(f_1^{24}+16)^3/f_1^{24}\,.$$
Finally, if $\fl=2$, returns
$$f_2(x)=\sqrt{2}\eta(2x)\,/\,\eta(x)\quad\hbox{such that}\quad
j=(f_2^{24}+16)^3/f_2^{24}.$$
Note the identities $f^8=f_1^8+f_2^8$ and $ff_1f_2=\sqrt2$.
Variant: Also available are \fun{GEN}{weberf}{GEN x, long prec},
\fun{GEN}{weberf1}{GEN x, long prec} and \fun{GEN}{weberf2}{GEN x, long prec}.
Function: whatnow
Class: gp
Section: programming/specific
C-Name: whatnow0
Prototype: vr
Help: whatnow(key): if key was present in GP version 1.39.15, gives
the new function name.
Description:
(str):void whatnow($1, 0)
Doc: if keyword \var{key} is the name of a function that was present in GP
version 1.39.15, outputs the new function name and syntax, if it
changed at all. Functions that where introduced since then, then modified
are also recognized.
\bprog
? whatnow("mu")
New syntax: mu(n) ===> moebius(n)
moebius(x): Moebius function of x.
? whatnow("sin")
This function did not change
@eprog When a function was removed and the underlying functionality
is not available under a compatible interface, no equivalent is mentioned:
\bprog
? whatnow("buchfu")
This function no longer exists
@eprog\noindent (The closest equivalent would be to set \kbd{K = bnfinit(T)}
then access \kbd{K.fu}.)
Function: while
Class: basic
Section: programming/control
C-Name: whilepari
Prototype: vEI
Help: while(a,seq): while a is nonzero evaluate the expression sequence seq.
Otherwise 0.
Doc: while $a$ is non-zero, evaluates the expression sequence \var{seq}. The
test is made \emph{before} evaluating the $seq$, hence in particular if $a$
is initially equal to zero the \var{seq} will not be evaluated at all.
Function: write
Class: basic
Section: programming/specific
C-Name: write0
Prototype: vss*
Help: write(filename,{str}*): appends the remaining arguments (same output as
print) to filename.
Doc: writes (appends) to \var{filename} the remaining arguments, and appends a
newline (same output as \kbd{print}).
%\syn{NO}
Function: write1
Class: basic
Section: programming/specific
C-Name: write1
Prototype: vss*
Help: write1(filename,{str}*): appends the remaining arguments (same output as
print1) to filename.
Doc: writes (appends) to \var{filename} the remaining arguments without a
trailing newline (same output as \kbd{print1}).
%\syn{NO}
Function: writebin
Class: basic
Section: programming/specific
C-Name: gpwritebin
Prototype: vsDG
Help: writebin(filename,{x}): write x as a binary object to file filename.
If x is omitted, write all session variables.
Doc: writes (appends) to
\var{filename} the object $x$ in binary format. This format is not human
readable, but contains the exact internal structure of $x$, and is much
faster to save/load than a string expression, as would be produced by
\tet{write}. The binary file format includes a magic number, so that such a
file can be recognized and correctly input by the regular \tet{read} or \b{r}
function. If saved objects refer to polynomial variables that are not
defined in the new session, they will be displayed as \kbd{t$n$} for some
integer $n$ (the attached variable number).
Installed functions and history objects can not be saved via this function.
If $x$ is omitted, saves all user variables from the session, together with
their names. Reading such a ``named object'' back in a \kbd{gp} session will set
the corresponding user variable to the saved value. E.g after
\bprog
x = 1; writebin("log")
@eprog\noindent
reading \kbd{log} into a clean session will set \kbd{x} to $1$.
The relative variables priorities (see \secref{se:priority}) of new variables
set in this way remain the same (preset variables retain their former
priority, but are set to the new value). In particular, reading such a
session log into a clean session will restore all variables exactly as they
were in the original one.
Just as a regular input file, a binary file can be compressed
using \tet{gzip}, provided the file name has the standard \kbd{.gz}
extension.\sidx{binary file}
In the present implementation, the binary files are architecture dependent
and compatibility with future versions of \kbd{gp} is not guaranteed. Hence
binary files should not be used for long term storage (also, they are
larger and harder to compress than text files).
Function: writetex
Class: basic
Section: programming/specific
C-Name: writetex
Prototype: vss*
Help: writetex(filename,{str}*): appends the remaining arguments (same format as
print) to filename, in TeX format.
Doc: as \kbd{write}, in \TeX\ format.
%\syn{NO}
Function: zeta
Class: basic
Section: transcendental
C-Name: gzeta
Prototype: Gp
Help: zeta(s): Riemann zeta function at s with s a complex or a p-adic number.
Doc: For $s$ a complex number, Riemann's zeta
function \sidx{Riemann zeta-function} $\zeta(s)=\sum_{n\ge1}n^{-s}$,
computed using the \idx{Euler-Maclaurin} summation formula, except
when $s$ is of type integer, in which case it is computed using
Bernoulli numbers\sidx{Bernoulli numbers} for $s\le0$ or $s>0$ and
even, and using modular forms for $s>0$ and odd.
For $s$ a $p$-adic number, Kubota-Leopoldt zeta function at $s$, that
is the unique continuous $p$-adic function on the $p$-adic integers
that interpolates the values of $(1 - p^{-k}) \zeta(k)$ at negative
integers $k$ such that $k \equiv 1 \pmod{p-1}$ (resp. $k$ is odd) if
$p$ is odd (resp. $p = 2$).
Function: zetamult
Class: basic
Section: transcendental
C-Name: zetamult
Prototype: Gp
Help: zetamult(s): multiple zeta value at integral s = [s1,...,sd].
Doc: For $s$ a vector of positive integers such that $s[1] \geq 2$,
returns the multiple zeta value (MZV)
$$\zeta(s_1,\dots, s_k) = \sum_{n_1>\dots>n_k>0} n_1^{-s_1}\dots n_k^{-s_k}.$$
\bprog
? zetamult([2,1]) - zeta(3) \\ Euler's identity
%1 = 0.E-38
@eprog
Function: zncharinduce
Class: basic
Section: number_theoretical
C-Name: zncharinduce
Prototype: GGG
Help: zncharinduce(G, chi, N): let G be idealstar(,q), let chi
be a Dirichlet character mod q and let N be a multiple of q. Return
the character modulo N induced by chi.
Doc: Let $G$ be attached to $(\Z/q\Z)^*$ (as per \kbd{G = idealstar(,q)})
and let \kbd{chi} be a Dirichlet character on $(\Z/q\Z)^*$, given by
\item a \typ{VEC}: a standard character on \kbd{bid.gen},
\item a \typ{INT} or a \typ{COL}: a Conrey index in $(\Z/q\Z)^*$ or its
Conrey logarithm;
see \secref{se:dirichletchar} or \kbd{??character}.
Let $N$ be a multiple of $q$, return the character modulo $N$ induced by
\kbd{chi}. As usual for arithmetic functions, the new modulus $N$ can be
given as a \typ{INT}, via a factorization matrix or a pair
\kbd{[N, factor(N)]}, or by \kbd{idealstar(,N)}.
\bprog
? G = idealstar(,4);
? chi = znconreylog(G,1); \\ trivial character mod 4
? zncharinduce(G, chi, 80) \\ now mod 80
%3 = [0, 0, 0]~
? zncharinduce(G, 1, 80) \\ same using directly Conrey label
%4 = [0, 0, 0]~
? G2 = idealstar(,80);
? zncharinduce(G, 1, G2) \\ same
%4 = [0, 0, 0]~
? chi = zncharinduce(G, 3, G2) \\ induce the non-trivial character mod 4
%5 = [1, 0, 0]~
? znconreyconductor(G2, chi, &chi0)
%6 = [4, Mat([2, 2])]
? chi0
%7 = [1]~
@eprog\noindent Here is a larger example:
\bprog
? G = idealstar(,126000);
? label = 1009;
? chi = znconreylog(G, label)
%3 = [0, 0, 0, 14, 0]~
? N0 = znconreyconductor(G, label, &chi0)
%4 = [125, Mat([5, 3])]
? chi0 \\ primitive character mod 5^3 attached to chi
%5 = [14]~
? G0 = idealstar(,N0);
? zncharinduce(G0, chi0, G) \\ induce back
%7 = [0, 0, 0, 14, 0]~
? znconreyexp(G, %)
%8 = 1009
@eprog
Function: zncharisodd
Class: basic
Section: number_theoretical
C-Name: zncharisodd
Prototype: lGG
Help: zncharisodd(G, chi): let G be idealstar(,N), let chi
be a Dirichlet character mod N, return 1 if and only if chi(-1) = -1
and 0 otherwise.
Doc: Let $G$ be attached to $(\Z/N\Z)^*$ (as per \kbd{G = idealstar(,N)})
and let \kbd{chi} be a Dirichlet character on $(\Z/N\Z)^*$, given by
\item a \typ{VEC}: a standard character on \kbd{bid.gen},
\item a \typ{INT} or a \typ{COL}: a Conrey index in $(\Z/q\Z)^*$ or its
Conrey logarithm;
see \secref{se:dirichletchar} or \kbd{??character}.
Return $1$ if and only if \kbd{chi}$(-1) = -1$ and $0$ otherwise.
\bprog
? G = idealstar(,8);
? zncharisodd(G, 1) \\ trivial character
%2 = 0
? zncharisodd(G, 3)
%3 = 1
? chareval(G, 3, -1)
%4 = 1/2
@eprog
Function: znchartokronecker
Class: basic
Section: number_theoretical
C-Name: znchartokronecker
Prototype: GGD0,L,
Help: znchartokronecker(G, chi, {flag=0}): let G be idealstar(,N), let chi
be a Dirichlet character mod N, return the discriminant D if chi is
real equal to the Kronecker symbol (D/.) and 0 otherwise. If flag
is set, return the fundamental discriminant attached to the corresponding
primitive character.
Doc: Let $G$ be attached to $(\Z/N\Z)^*$ (as per \kbd{G = idealstar(,N)})
and let \kbd{chi} be a Dirichlet character on $(\Z/N\Z)^*$, given by
\item a \typ{VEC}: a standard character on \kbd{bid.gen},
\item a \typ{INT} or a \typ{COL}: a Conrey index in $(\Z/q\Z)^*$ or its
Conrey logarithm;
see \secref{se:dirichletchar} or \kbd{??character}.
If $\fl = 0$, return the discriminant $D$ if \kbd{chi} is real equal to the
Kronecker symbol $(D/.)$ and $0$ otherwise. The discriminant $D$ is
fundamental if and only if \kbd{chi} is primitive.
If $\fl = 1$, return the fundamental discriminant attached to the
corresponding primitive character.
\bprog
? G = idealstar(,8); CHARS = [1,3,5,7]; \\ Conrey labels
? apply(t->znchartokronecker(G,t), CHARS)
%2 = [4, -8, 8, -4]
? apply(t->znchartokronecker(G,t,1), CHARS)
%3 = [1, -8, 8, -4]
@eprog
Function: znconreychar
Class: basic
Section: number_theoretical
C-Name: znconreychar
Prototype: GG
Help: znconreychar(bid,m): Dirichlet character attached to m in (Z/qZ)*
in Conrey's notation, where bid is idealstar(,q).
Doc: Given a \var{bid} attached to $(\Z/q\Z)^*$ (as per
\kbd{bid = idealstar(,q)}), this function returns the Dirichlet character
attached to $m \in (\Z/q\Z)^*$ via Conrey's logarithm, which
establishes a ``canonical'' bijection between $(\Z/q\Z)^*$ and its dual.
Let $q = \prod_p p^{e_p}$ be the factorization of $q$ into distinct primes.
For all odd $p$ with $e_p > 0$, let $g_p$ be the element in $(\Z/q\Z)^*$
which is
\item congruent to $1$ mod $q/p^{e_p}$,
\item congruent mod $p^{e_p}$ to the smallest integer whose order
is $\phi(p^{e_p})$.
For $p = 2$, we let $g_4$ (if $2^{e_2} \geq 4$) and $g_8$ (if furthermore
($2^{e_2} \geq 8$) be the elements in $(\Z/q\Z)^*$ which
are
\item congruent to $1$ mod $q/2^{e_2}$,
\item $g_4 = -1 \mod 2^{e_2}$,
\item $g_8 = 5 \mod 2^{e_2}$.
Then the $g_p$ (and the extra $g_4$ and $g_8$ if $2^{e_2}\geq 2$) are
independent
generators of $(\Z/q\Z)^*$, i.e. every $m$ in $(\Z/q\Z)^*$ can be written
uniquely as $\prod_p g_p^{m_p}$, where $m_p$ is defined modulo the order
$o_p$ of $g_p$
and $p \in S_q$, the set of prime divisors of $q$ together with $4$
if $4 \mid q$ and $8$ if $8 \mid q$. Note that the $g_p$ are in general
\emph{not} SNF
generators as produced by \kbd{znstar} or \kbd{idealstar} whenever
$\omega(q) \geq 2$, although their number is the same. They however allow
to handle the finite abelian group $(\Z/q\Z)^*$ in a fast and elegant
way. (Which unfortunately does not generalize to ray class groups or Hecke
characters.)
The Conrey logarithm of $m$ is the vector $(m_p)_{p\in S_q}$, obtained
via \tet{znconreylog}. The Conrey character $\chi_q(m,\cdot)$ attached to
$m$ mod $q$ maps
each $g_p$, $p\in S_q$ to $e(m_p / o_p)$, where $e(x) = \exp(2i\pi x)$.
This function returns the Conrey character expressed in the standard PARI
way in terms of the SNF generators \kbd{bid.gen}.
\misctitle{Note} It is useless to include the generators
in the \var{bid}, except for debugging purposes: they are well defined from
elementary matrix operations and Chinese remaindering, their explicit value
as elements in $(\Z/q\Z)^*$ is never used.
\bprog
? G = idealstar(,8,2); /*add generators for debugging:*/
? G.cyc
%2 = [2, 2] \\ Z/2 x Z/2
? G.gen
%3 = [7, 3]
? znconreychar(G,1) \\ 1 is always the trivial character
%4 = [0, 0]
? znconreychar(G,2) \\ 2 is not coprime to 8 !!!
*** at top-level: znconreychar(G,2)
*** ^-----------------
*** znconreychar: elements not coprime in Zideallog:
2
8
*** Break loop: type 'break' to go back to GP prompt
break>
? znconreychar(G,3)
%5 = [0, 1]
? znconreychar(G,5)
%6 = [1, 1]
? znconreychar(G,7)
%7 = [1, 0]
@eprog\noindent We indeed get all 4 characters of $(\Z/8\Z)^*$.
For convenience, we allow to input the \emph{Conrey logarithm} of $m$
instead of $m$:
\bprog
? G = idealstar(,55);
? znconreychar(G,7)
%2 = [7, 0]
? znconreychar(G, znconreylog(G,7))
%3 = [7, 0]
@eprog
Function: znconreyconductor
Class: basic
Section: number_theoretical
C-Name: znconreyconductor
Prototype: GGD&
Help: znconreyconductor(bid,chi, {&chi0}): let bid be idealstar(,q) and chi
be a Dirichlet character on (Z/qZ)* given by its Conrey logarithm. Return
the conductor of chi, and set chi0 to (the Conrey logarithm of) the
attached primitive character. If chi0 != chi, return the conductor
and its factorization.
Doc: Let \var{bid} be attached to $(\Z/q\Z)^*$ (as per
\kbd{bid = idealstar(,q)}) and \kbd{chi} be a Dirichlet character on
$(\Z/q\Z)^*$, given by
\item a \typ{VEC}: a standard character on \kbd{bid.gen},
\item a \typ{INT} or a \typ{COL}: a Conrey index in $(\Z/q\Z)^*$ or its
Conrey logarithm;
see \secref{se:dirichletchar} or \kbd{??character}.
Return the conductor of \kbd{chi}, as the \typ{INT} \kbd{bid.mod}
if \kbd{chi} is primitive, and as a pair \kbd{[N, faN]} (with \kbd{faN} the
factorization of $N$) otherwise.
If \kbd{chi0} is present, set it to the Conrey logarithm of the attached
primitive character.
\bprog
? G = idealstar(,126000);
? znconreyconductor(G,11) \\ primitive
%2 = 126000
? znconreyconductor(G,1) \\ trivial character, not primitive!
%3 = [1, matrix(0,2)]
? N0 = znconreyconductor(G,1009, &chi0) \\ character mod 5^3
%4 = [125, Mat([5, 3])]
? chi0
%5 = [14]~
? G0 = idealstar(,N0); \\ format [N,factor(N)] accepted
? znconreyexp(G0, chi0)
%7 = 9
? znconreyconductor(G0, chi0) \\ now primitive, as expected
%8 = 125
@eprog\noindent The group \kbd{G0} is not computed as part of
\kbd{znconreyconductor} because it needs to be computed only once per
conductor, not once per character.
Function: znconreyexp
Class: basic
Section: number_theoretical
C-Name: znconreyexp
Prototype: GG
Help: znconreyexp(bid, chi): Conrey exponential attached to bid =
idealstar(,q). Returns the element m in (Z/qZ)^* attached to the character
chi on bid: znconreylog(bid, m) = chi.
Doc: Given a \var{bid} attached to $(\Z/q\Z)^*$ (as per
\kbd{bid = idealstar(,q)}), this function returns the Conrey exponential of
the character \var{chi}: it returns the integer
$m \in (\Z/q\Z)^*$ such that \kbd{znconreylog(\var{bid}, $m$)} is \var{chi}.
The character \var{chi} is given either as a
\item \typ{VEC}: in terms of the generators \kbd{\var{bid}.gen};
\item \typ{COL}: a Conrey logarithm.
\bprog
? G = idealstar(,126000)
? znconreylog(G,1)
%2 = [0, 0, 0, 0, 0]~
? znconreyexp(G,%)
%3 = 1
? G.cyc \\ SNF generators
%4 = [300, 12, 2, 2, 2]
? chi = [100, 1, 0, 1, 0]; \\ some random character on SNF generators
? znconreylog(G, chi) \\ in terms of Conrey generators
%6 = [0, 3, 3, 0, 2]~
? znconreyexp(G, %) \\ apply to a Conrey log
%7 = 18251
? znconreyexp(G, chi) \\ ... or a char on SNF generators
%8 = 18251
? znconreychar(G,%)
%9 = [100, 1, 0, 1, 0]
@eprog
Function: znconreylog
Class: basic
Section: number_theoretical
C-Name: znconreylog
Prototype: GG
Help: znconreylog(bid,m): Conrey logarithm attached to m in (Z/qZ)*,
where bid is idealstar(,q).
Doc: Given a \var{bid} attached to $(\Z/q\Z)^*$ (as per
\kbd{bid = idealstar(,q)}), this function returns the Conrey logarithm of
$m \in (\Z/q\Z)^*$.
Let $q = \prod_p p^{e_p}$ be the factorization of $q$ into distinct primes,
where we assume $e_2 = 0$ or $e_2 \geq 2$. (If $e_2 = 1$, we can ignore $2$
from the factorization, as if we replaced $q$ by $q/2$, since $(\Z/q\Z)^*
\sim (\Z/(q/2)\Z)^*$.)
For all odd $p$ with $e_p > 0$, let $g_p$ be the element in $(\Z/q\Z)^*$
which is
\item congruent to $1$ mod $q/p^{e_p}$,
\item congruent mod $p^{e_p}$ to the smallest integer whose order
is $\phi(p^{e_p})$ for $p$ odd,
For $p = 2$, we let $g_4$ (if $2^{e_2} \geq 4$) and $g_8$ (if furthermore
($2^{e_2} \geq 8$) be the elements in $(\Z/q\Z)^*$ which
are
\item congruent to $1$ mod $q/2^{e_2}$,
\item $g_4 = -1 \mod 2^{e_2}$,
\item $g_8 = 5 \mod 2^{e_2}$.
Then the $g_p$ (and the extra $g_4$ and $g_8$ if $2^{e_2}\geq 2$) are
independent
generators of $\Z/q\Z^*$, i.e. every $m$ in $(\Z/q\Z)^*$ can be written
uniquely as $\prod_p g_p^{m_p}$, where $m_p$ is defined modulo the
order $o_p$ of $g_p$
and $p \in S_q$, the set of prime divisors of $q$ together with $4$
if $4 \mid q$ and $8$ if $8 \mid q$.
Note that the $g_p$ are in general \emph{not} SNF
generators as produced by \kbd{znstar} or \kbd{idealstar} whenever
$\omega(q) \geq 2$, although their number is the same. They however allow
to handle the finite abelian group $(\Z/q\Z)^*$ in a fast and elegant
way. (Which unfortunately does not generalize to ray class groups or Hecke
characters.)
The Conrey logarithm of $m$ is the vector $(m_p)_{p\in S_q}$. The inverse
function \tet{znconreyexp} recovers the Conrey label $m$ from a character.
\bprog
? G = idealstar(,126000);
? znconreylog(G,1)
%2 = [0, 0, 0, 0, 0]~
? znconreyexp(G, %)
%3 = 1
? znconreylog(G,2) \\ 2 is not coprime to modulus !!!
*** at top-level: znconreylog(G,2)
*** ^-----------------
*** znconreylog: elements not coprime in Zideallog:
2
126000
*** Break loop: type 'break' to go back to GP prompt
break>
? znconreylog(G,11) \\ wrt. Conrey generators
%4 = [0, 3, 1, 76, 4]~
? log11 = ideallog(,11,G) \\ wrt. SNF generators
%5 = [178, 3, -75, 1, 0]~
@eprog\noindent
For convenience, we allow to input the ordinary discrete log of $m$,
$\kbd{ideallog(,m,bid)}$, which allows to convert discrete logs
from \kbd{bid.gen} generators to Conrey generators.
\bprog
? znconreylog(G, log11)
%7 = [0, 3, 1, 76, 4]~
@eprog\noindent We also allow a character (\typ{VEC}) on \kbd{bid.gen} and
return its representation on the Conrey generators.
\bprog
? G.cyc
%8 = [300, 12, 2, 2, 2]
? chi = [10,1,0,1,1];
? znconreylog(G, chi)
%10 = [1, 3, 3, 10, 2]~
? n = znconreyexp(G, chi)
%11 = 84149
? znconreychar(G, n)
%12 = [10, 1, 0, 1, 1]
@eprog
Function: zncoppersmith
Class: basic
Section: number_theoretical
C-Name: zncoppersmith
Prototype: GGGDG
Help: zncoppersmith(P, N, X, {B=N}): finds all integers x
with |x| <= X such that gcd(N, P(x)) >= B. X should be smaller than
exp((log B)^2 / (deg(P) log N)).
Doc: $N$ being an integer and $P\in \Z[X]$, finds all integers $x$ with
$|x| \leq X$ such that
$$\gcd(N, P(x)) \geq B,$$
using \idx{Coppersmith}'s algorithm (a famous application of the \idx{LLL}
algorithm). $X$ must be smaller than $\exp(\log^2 B / (\deg(P) \log N))$:
for $B = N$, this means $X < N^{1/\deg(P)}$. Some $x$ larger than $X$ may
be returned if you are very lucky. The smaller $B$ (or the larger $X$), the
slower the routine will be. The strength of Coppersmith method is the
ability to find roots modulo a general \emph{composite} $N$: if $N$ is a prime
or a prime power, \tet{polrootsmod} or \tet{polrootspadic} will be much
faster.
We shall now present two simple applications. The first one is
finding non-trivial factors of $N$, given some partial information on the
factors; in that case $B$ must obviously be smaller than the largest
non-trivial divisor of $N$.
\bprog
setrand(1); \\ to make the example reproducible
interval = [10^30, 10^31];
p = randomprime(interval);
q = randomprime(interval); N = p*q;
p0 = p % 10^20; \\ assume we know 1) p > 10^29, 2) the last 19 digits of p
L = zncoppersmith(10^19*x + p0, N, 10^12, 10^29)
\\ result in 10ms.
%6 = [738281386540]
? gcd(L[1] * 10^19 + p0, N) == p
%7 = 1
@eprog\noindent and we recovered $p$, faster than by trying all
possibilities $ < 10^{12}$.
The second application is an attack on RSA with low exponent, when the
message $x$ is short and the padding $P$ is known to the attacker. We use
the same RSA modulus $N$ as in the first example:
\bprog
setrand(1);
P = random(N); \\ known padding
e = 3; \\ small public encryption exponent
X = floor(N^0.3); \\ N^(1/e - epsilon)
x0 = random(X); \\ unknown short message
C = lift( (Mod(x0,N) + P)^e ); \\ known ciphertext, with padding P
zncoppersmith((P + x)^3 - C, N, X)
\\ result in 244ms.
%14 = [2679982004001230401]
? %[1] == x0
%15 = 1
@eprog\noindent
We guessed an integer of the order of $10^{18}$, almost instantly.
Function: znlog
Class: basic
Section: number_theoretical
C-Name: znlog0
Prototype: GGDG
Help: znlog(x,g,{o}): return the discrete logarithm of x in
(Z/nZ)* in base g. If present, o represents the multiplicative
order of g. Return [] if no solution exist.
Doc: This functions allows two distinct modes of operation depending
on $g$:
\item if $g$ is the output of \tet{znstar} (with initialization),
we compute the discrete logarithm of $x$ with respect to the generators
contained in the structure. See \tet{ideallog} for details.
\item else $g$ is an explicit element in $(\Z/N\Z)^*$, we compute the
discrete logarithm of $x$ in $(\Z/N\Z)^*$ in base $g$. The rest of this
entry describes the latter possibility.
The result is $[]$ when $x$ is not a power of $g$, though the function may
also enter an infinite loop in this case.
If present, $o$ represents the multiplicative order of $g$, see
\secref{se:DLfun}; the preferred format for this parameter is
\kbd{[ord, factor(ord)]}, where \kbd{ord} is the order of $g$.
This provides a definite speedup when the discrete log problem is simple:
\bprog
? p = nextprime(10^4); g = znprimroot(p); o = [p-1, factor(p-1)];
? for(i=1,10^4, znlog(i, g, o))
time = 205 ms.
? for(i=1,10^4, znlog(i, g))
time = 244 ms. \\ a little slower
@eprog
The result is undefined if $g$ is not invertible mod $N$ or if the supplied
order is incorrect.
This function uses
\item a combination of generic discrete log algorithms (see below).
\item in $(\Z/N\Z)^*$ when $N$ is prime: a linear sieve index calculus
method, suitable for $N < 10^{50}$, say, is used for large prime divisors of
the order.
The generic discrete log algorithms are:
\item Pohlig-Hellman algorithm, to reduce to groups of prime order $q$,
where $q | p-1$ and $p$ is an odd prime divisor of $N$,
\item Shanks baby-step/giant-step ($q < 2^{32}$ is small),
\item Pollard rho method ($q > 2^{32}$).
The latter two algorithms require $O(\sqrt{q})$ operations in the group on
average, hence will not be able to treat cases where $q > 10^{30}$, say.
In addition, Pollard rho is not able to handle the case where there are no
solutions: it will enter an infinite loop.
\bprog
? g = znprimroot(101)
%1 = Mod(2,101)
? znlog(5, g)
%2 = 24
? g^24
%3 = Mod(5, 101)
? G = znprimroot(2 * 101^10)
%4 = Mod(110462212541120451003, 220924425082240902002)
? znlog(5, G)
%5 = 76210072736547066624
? G^% == 5
%6 = 1
? N = 2^4*3^2*5^3*7^4*11; g = Mod(13, N); znlog(g^110, g)
%7 = 110
? znlog(6, Mod(2,3)) \\ no solution
%8 = []
@eprog\noindent For convenience, $g$ is also allowed to be a $p$-adic number:
\bprog
? g = 3+O(5^10); znlog(2, g)
%1 = 1015243
? g^%
%2 = 2 + O(5^10)
@eprog
Variant: The function
\fun{GEN}{znlog}{GEN x, GEN g, GEN o} is also available
Function: znorder
Class: basic
Section: number_theoretical
C-Name: znorder
Prototype: GDG
Help: znorder(x,{o}): order of the integermod x in (Z/nZ)*.
Optional o represents a multiple of the order of the element.
Description:
(gen):int order($1)
(gen,):int order($1)
(gen,int):int znorder($1, $2)
Doc: $x$ must be an integer mod $n$, and the
result is the order of $x$ in the multiplicative group $(\Z/n\Z)^*$. Returns
an error if $x$ is not invertible.
The parameter o, if present, represents a non-zero
multiple of the order of $x$, see \secref{se:DLfun}; the preferred format for
this parameter is \kbd{[ord, factor(ord)]}, where \kbd{ord = eulerphi(n)}
is the cardinality of the group.
Variant: Also available is \fun{GEN}{order}{GEN x}.
Function: znprimroot
Class: basic
Section: number_theoretical
C-Name: znprimroot
Prototype: G
Help: znprimroot(n): returns a primitive root of n when it exists.
Doc: returns a primitive root (generator) of $(\Z/n\Z)^*$, whenever this
latter group is cyclic ($n = 4$ or $n = 2p^k$ or $n = p^k$, where $p$ is an
odd prime and $k \geq 0$). If the group is not cyclic, the result is
undefined. If $n$ is a prime power, then the smallest positive primitive
root is returned. This may not be true for $n = 2p^k$, $p$ odd.
Note that this function requires factoring $p-1$ for $p$ as above,
in order to determine the exact order of elements in
$(\Z/n\Z)^*$: this is likely to be costly if $p$ is large.
Function: znstar
Class: basic
Section: number_theoretical
C-Name: znstar0
Prototype: GD0,L,
Help: znstar(n,{flag=0}): 3-component vector v = [no,cyc,gen], giving the
structure of the abelian group (Z/nZ)^*;
no is the order (i.e. eulerphi(n)), cyc is a vector of cyclic components,
and gen is a vector giving the corresponding generators.
Doc: gives the structure of the multiplicative group $(\Z/n\Z)^*$.
The output $G$ depends on the value of \fl:
\item $\fl = 0$ (default), an abelian group structure $[h,d,g]$,
where $h = \phi(n)$ is the order (\kbd{G.no}), $d$ (\kbd{G.cyc})
is a $k$-component row-vector $d$ of integers $d_i$ such that $d_i>1$,
$d_i \mid d_{i-1}$ for $i \ge 2$ and
$$ (\Z/n\Z)^* \simeq \prod_{i=1}^k (\Z/d_i\Z), $$
and $g$ (\kbd{G.gen}) is a $k$-component row vector giving generators of
the image of the cyclic groups $\Z/d_i\Z$.
\item $\fl = 1$ the result is a \kbd{bid} structure without generators
(which are well defined but not explicitly computed, which saves time);
this allows computing discrite logarithms using \tet{znlog} (also in the
non-cyclic case!).
\item $\fl = 2$ same as $\fl = 1$ with generators.
\bprog
? G = znstar(40)
%1 = [16, [4, 2, 2], [Mod(17, 40), Mod(21, 40), Mod(11, 40)]]
? G.no \\ eulerphi(40)
%2 = 16
? G.cyc \\ cycle structure
%3 = [4, 2, 2]
? G.gen \\ generators for the cyclic components
%4 = [Mod(17, 40), Mod(21, 40), Mod(11, 40)]
? apply(znorder, G.gen)
%5 = [4, 2, 2]
@eprog\noindent According to the above definitions, \kbd{znstar(0)} is
\kbd{[2, [2], [-1]]}, corresponding to $\Z^*$.
Variant: Instead the above hardcoded numerical flags, one should rather use
\fun{GEN}{ZNstar}{GEN N, long flag}, where \kbd{flag} is
an or-ed combination of \tet{nf_GEN} (include generators) and \tet{nf_INIT}
(return a full \kbd{bid}, not a group), possibly $0$. This offers
one more combination: no gen and no init.
|