This file is indexed.

/usr/share/pari/doc/usersch3.tex is in pari-doc 2.5.1-2.

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
% $Id$
% Copyright (c) 2000  The PARI Group
%
% This file is part of the PARI/GP documentation
%
% Permission is granted to copy, distribute and/or modify this document
% under the terms of the GNU General Public License
\chapter{Functions and Operations Available in PARI and GP}
\label{se:functions}

The functions and operators available in PARI and in the GP/PARI calculator
are numerous and ever-expanding. Here is a description of the ones available
in version \vers. It should be noted that many of these functions accept
quite different types as arguments, but others are more restricted. The list
of acceptable types will be given for each function or class of functions.
Except when stated otherwise, it is understood that a function or operation
which should make natural sense is legal. In this chapter, we will describe
the functions according to a rough classification. The general entry looks
something like:

\key{foo}$(x,\{\fl=0\})$: short description.

The library syntax is \kbd{GEN foo(GEN x, long fl = 0)}.

\noindent
This means that the GP function \kbd{foo} has one mandatory argument $x$, and
an optional one, $\fl$, whose default value is 0. (The $\{\}$ should not be
typed, it is just a convenient notation we will use throughout to denote
optional arguments.) That is, you can type \kbd{foo(x,2)}, or \kbd{foo(x)},
which is then understood to mean \kbd{foo(x,0)}. As well, a comma or closing
parenthesis, where an optional argument should have been, signals to GP it
should use the default. Thus, the syntax \kbd{foo(x,)} is also accepted as a
synonym for our last expression. When a function has more than one optional
argument, the argument list is filled with user supplied values, in order.
When none are left, the defaults are used instead. Thus, assuming that
\kbd{foo}'s prototype had been
$$\hbox{%
\key{foo}$(\{x=1\},\{y=2\},\{z=3\})$,%
}$$
typing in \kbd{foo(6,4)} would give
you \kbd{foo(6,4,3)}. In the rare case when you want to set some far away
argument, and leave the defaults in between as they stand, you can use the
``empty arg'' trick alluded to above: \kbd{foo(6,,1)} would yield
\kbd{foo(6,2,1)}. By the way, \kbd{foo()} by itself yields
\kbd{foo(1,2,3)} as was to be expected.

In this rather special case of a function having no mandatory argument, you
can even omit the $()$: a standalone \kbd{foo} would be enough (though we
do not recommend it for your scripts, for the sake of clarity). In defining
GP syntax, we strove to put optional arguments at the end of the argument
list (of course, since they would not make sense otherwise), and in order of
decreasing usefulness so that, most of the time, you will be able to ignore
them.

Finally, an optional argument (between braces) followed by a star, like
$\{\var{x}\}*$, means that any number of such arguments (possibly none) can
be given. This is in particular used by the various \kbd{print} routines.

\misctitle{Flags} A \tev{flag} is an argument which, rather than conveying
actual information to the routine, instructs it to change its default
behavior, e.g.~return more or less information. All such
flags are optional, and will be called \fl\ in the function descriptions to
follow. There are two different kind of flags

\item generic: all valid values for the flag are individually
described (``If \fl\ is equal to $1$, then\dots'').

\item binary:\sidx{binary flag} use customary binary notation as a
compact way to represent many toggles with just one integer. Let
$(p_0,\dots,p_n)$ be a list of switches (i.e.~of properties which take either
the value $0$ or~$1$), the number $2^3 + 2^5 = 40$ means that $p_3$ and $p_5$
are set (that is, set to $1$), and none of the others are (that is, they
are set to $0$). This is announced as ``The binary digits of $\fl$ mean 1:
$p_0$, 2: $p_1$, 4: $p_2$'', and so on, using the available consecutive
powers of~$2$.

\misctitle{Mnemonics for flags} Numeric flags as mentioned above are
obscure, error-prone, and quite rigid: should the authors
want to adopt a new flag numbering scheme (for instance when noticing
flags with the same meaning but different numeric values across a set of
routines), it would break backward compatibility. The only advantage of
explicit numeric values is that they are fast to type, so their use is only
advised when using the calculator \kbd{gp}.

As an alternative, one can replace a numeric flag by a character string
containing symbolic identifiers. For a generic flag, the mnemonic
corresponding to the numeric identifier is given after it as in

\bprog
fun(x, {flag = 0} ):

  If flag is equal to 1 = AGM, use an agm formula ...
@eprog\noindent
which means that one can use indifferently \kbd{fun($x$, 1)} or
\kbd{fun($x$, "AGM")}.

For a binary flag, mnemonics corresponding to the various toggles are given
after each of them. They can be negated by prepending \kbd{no\_} to the
mnemonic, or by removing such a prefix. These toggles are grouped together
using any punctuation character (such as ',' or ';'). For instance (taken
from description of $\tet{ploth}(X=a,b,\var{expr},\{\fl=0\},\{n=0\})$)

\centerline{Binary digits of flags mean: $1=\kbd{Parametric}$,
$2=\kbd{Recursive}$, \dots}

\noindent so that, instead of $1$, one could use the mnemonic
\kbd{"Parametric; no\_Recursive"}, or simply \kbd{"Parametric"} since
\kbd{Recursive} is unset by default (default value of $\fl$ is $0$,
i.e.~everything unset). People used to the bit-or notation in languages like
C may also use the form \kbd{"Parametric | no\_Recursive"}.

\misctitle{Pointers} \varsidx{pointer} If a parameter in the function
prototype is prefixed with a \& sign, as in

\key{foo}$(x,\&e)$

\noindent it means that, besides the normal return value, the function may
assign a value to $e$ as a side effect. When passing the argument, the \&
sign has to be typed in explicitly. As of version \vers, this \tev{pointer}
argument is optional for all documented functions, hence the \& will always
appear between brackets as in \kbd{Z\_issquare}$(x,\{\&e\})$.

\misctitle{About library programming}
The \var{library} function \kbd{foo}, as defined at the beginning of this
section, is seen to have two mandatory arguments, $x$ and \fl: no function
seen in the present chapter has been implemented so as to accept a variable
number of arguments, so all arguments are mandatory when programming with the
library (usually, variants are provided corresponding to the various flag values).
We include an \kbd{= default value} token in the prototype to signal how a missing
argument should be encoded. Most of the time, it will be a \kbd{NULL} pointer, or
-1 for a variable number. Refer to the \emph{User's Guide to the PARI library}
for general background and details.

\section{Standard monadic or dyadic operators}

\subseckbd{+$/$-}: The expressions \kbd{+}$x$ and \kbd{-}$x$ refer
to monadic operators (the first does nothing, the second negates $x$).

The library syntax is \fun{GEN}{gneg}{GEN x} for \kbd{-}$x$.

\subseckbd{+}, \kbd{-}: The expression $x$ \kbd{+} $y$ is the \idx{sum} and
$x$ \kbd{-} $y$ is the \idx{difference} of $x$ and $y$. Addition/subtraction
between a scalar type $x$ and a \typ{COL} or \typ{MAT} $y$ returns
respectively $[y[1] \pm x, y[2],\dots]$ and $y \pm x \text{Id}$. Other
addition/subtraction between a scalar type and a vector or a matrix, or
between vector/matrices of incompatible sizes are forbidden.

The library syntax is \fun{GEN}{gadd}{GEN x, GEN y} for $x$ \kbd{+} $y$,
\fun{GEN}{gsub}{GEN x, GEN y} for $x$ \kbd{-} $y$.

\subseckbd{*}: The expression $x$ \kbd{*} $y$ is the \idx{product} of $x$
and $y$. Among the prominent impossibilities are multiplication between
vector/matrices of incompatible sizes, between a \typ{INTMOD} or \typ{PADIC}
Restricted to scalars, \kbd{*} is commutative; because of vector and matrix
operations, it is not commutative in general.

Multiplication between two \typ{VEC}s or two \typ{COL}s is not
allowed; to take the \idx{scalar product} of two vectors of the same length,
transpose one of the vectors (using the operator \kbd{\til} or the function
\kbd{mattranspose}, see \secref{se:linear_algebra}) and multiply a line vector
by a column vector:
\bprog
? a = [1,2,3];
? a * a
  ***   at top-level: a*a
  ***                  ^--
  *** _*_: forbidden multiplication t_VEC * t_VEC.
? a * a~
%2 = 14
@eprog

If $x,y$ are binary quadratic forms, compose them; see also
\kbd{qfbnucomp} and \kbd{qfbnupow}. If $x,y$ are \typ{VECSMALL} of the same
length, understand them as permutations and compose them.

The library syntax is \fun{GEN}{gmul}{GEN x, GEN y} for $x$ \kbd{*} $y$.
Also available is \fun{GEN}{gsqr}{GEN x} for $x$ \kbd{*} $x$.

\subseckbd{/}: The expression $x$ \kbd{/} $y$ is the \idx{quotient} of $x$
and $y$. In addition to the impossibilities for multiplication, note that if
the divisor is a matrix, it must be an invertible square matrix, and in that
case the result is $x*y^{-1}$. Furthermore note that the result is as exact
as possible: in particular, division of two integers always gives a rational
number (which may be an integer if the quotient is exact) and \emph{not} the
Euclidean quotient (see $x$ \kbd{\bs} $y$ for that), and similarly the
quotient of two polynomials is a rational function in general. To obtain the
approximate real value of the quotient of two integers, add \kbd{0.} to the
result; to obtain the approximate $p$-adic value of the quotient of two
integers, add \kbd{O(p\pow k)} to the result; finally, to obtain the
\idx{Taylor series} expansion of the quotient of two polynomials, add
\kbd{O(X\pow k)} to the result or use the \kbd{taylor} function
(see \secref{se:taylor}). \label{se:gdiv}

The library syntax is \fun{GEN}{gdiv}{GEN x, GEN y} for $x$ \kbd{/} $y$.

\subseckbd{\bs}: The expression \kbd{$x$ \bs\ $y$} is the \idx{Euclidean
quotient} of $x$ and $y$. If $y$ is a real scalar, this is defined as
\kbd{floor($x$/$y$)} if $y > 0$, and \kbd{ceil($x$/$y$)} if $y < 0$ and
the division is not exact. Hence the remainder \kbd{$x$ - ($x$\bs$y$)*$y$}
is in $[0, |y|[$.

Note that when $y$ is an integer and $x$ a polynomial, $y$ is first promoted
to a polynomial of degree $0$. When $x$ is a vector or matrix, the operator
is applied componentwise.

The library syntax is \fun{GEN}{gdivent}{GEN x, GEN y}
for $x$ \kbd{\bs} $y$.

\subseckbd{\bs/}: The expression $x$ \b{/} $y$ evaluates to the rounded
\idx{Euclidean quotient} of $x$ and $y$. This is the same as \kbd{$x$ \bs\ $y$}
except for scalar division: the quotient is such that the corresponding
remainder is smallest in absolute value and in case of a tie the quotient
closest to $+\infty$ is chosen (hence the remainder would belong to
$]{-}|y|/2, |y|/2]$).

When $x$ is a vector or matrix, the operator is applied componentwise.

The library syntax is \fun{GEN}{gdivround}{GEN x, GEN y}
for $x$ \b{/} $y$.

\subseckbd{\%}: The expression \kbd{$x$ \% $y$} evaluates to the modular
\idx{Euclidean remainder} of $x$ and $y$, which we now define. When $x$ or $y$
is a non-integral real number, \kbd{$x$\%$y$} is defined as \kbd{$x$ -
($x$\bs$y$)*$y$}. Otherwise, if $y$ is an integer, this is the smallest
non-negative integer congruent to $x$ modulo $y$. (This actually coincides with
the previous definition if and only if $x$ is an integer.) If $y$ is a
polynomial, this is the polynomial of smallest degree congruent to $x$ modulo
$y$. For instance:
\bprog
? (1/2) % 3
%1 = 2
? 0.5 % 3
%2 = 0.5000000000000000000000000000
? (1/2) % 3.0
%3 = 1/2
@eprog
Note that when $y$ is an integer and $x$ a polynomial, $y$ is first promoted
to a polynomial of degree $0$. When $x$ is a vector or matrix, the operator
is applied componentwise.

The library syntax is \fun{GEN}{gmod}{GEN x, GEN y}
for $x$ \kbd{\%} $y$.

\subseckbd{\pow}: The expression $x\hbox{\kbd{\pow}}n$ is \idx{powering}.
If the exponent is an integer, then exact operations are performed using
binary (left-shift) powering techniques. In particular, in this case $x$
cannot be a vector or matrix unless it is a square matrix (invertible
if the exponent is negative). If $x$ is a $p$-adic number, its
precision will increase if $v_p(n) > 0$. Powering a binary quadratic form
(types \typ{QFI} and \typ{QFR}) returns a reduced representative of the
class, provided the input is reduced. In particular, $x\hbox{\kbd{\pow}}1$ is
identical to $x$.

PARI is able to rewrite the multiplication $x * x$ of two \emph{identical}
objects as $x^2$, or $\kbd{sqr}(x)$. Here, identical means the operands are
two different labels referencing the same chunk of memory; no equality test
is performed. This is no longer true when more than two arguments are
involved.

If the exponent is not of type integer, this is treated as a transcendental
function (see \secref{se:trans}), and in particular has the effect of
componentwise powering on vector or matrices.

As an exception, if the exponent is a rational number $p/q$ and $x$ an
integer modulo a prime or a $p$-adic number, return a solution $y$ of
$y^q=x^p$ if it exists. Currently, $q$ must not have large prime factors.
Beware that
\bprog
? Mod(7,19)^(1/2)
%1 = Mod(11, 19) /* is any square root */
? sqrt(Mod(7,19))
%2 = Mod(8, 19)  /* is the smallest square root */
? Mod(7,19)^(3/5)
%3 = Mod(1, 19)
? %3^(5/3)
%4 = Mod(1, 19)  /* Mod(7,19) is just another cubic root */
@eprog

If the exponent is a negative integer, an \idx{inverse} must be computed.
For non-invertible \typ{INTMOD}, this will fail and implicitly exhibit a
non trivial factor of the modulus:
\bprog
? Mod(4,6)^(-1)
  ***   at top-level: Mod(4,6)^(-1)
  ***                         ^-----
  *** _^_: impossible inverse modulo: Mod(2, 6).
@eprog\noindent
(Here, a factor 2 is obtained directly. In general, take the gcd of the
representative and the modulus.) This is most useful when performing
complicated operations modulo an integer $N$ whose factorization is
unknown. Either the computation succeeds and all is well, or a factor $d$
is discovered and the computation may be restarted modulo $d$ or $N/d$.

For non-invertible \typ{POLMOD}, this will fail without exhibiting a
factor.
\bprog
? Mod(x^2, x^3-x)^(-1)
  ***   at top-level: Mod(x^2,x^3-x)^(-1)
  ***                               ^-----
  *** _^_: non-invertible polynomial in RgXQ_inv.
? a = Mod(3,4)*y^3 + Mod(1,4); b = y^6+y^5+y^4+y^3+y^2+y+1;
? Mod(a, b)^(-1);
  ***   at top-level: Mod(a,b)^(-1)
  ***                         ^-----
  *** _^_: impossible inverse modulo: Mod(0, 4).
@eprog\noindent
In fact the latter polynomial is invertible, but the algorithm used
(subresultant) assumes the base ring is a domain. If it is not the case,
as here for $\Z/4\Z$, a result will be correct but chances are an error
will occur first. In this specific case, one should work with $2$-adics.
In general, one can try the following approach
\bprog
? inversemod(a, b) =
{ my(m);
  m = polsylvestermatrix(polrecip(a), polrecip(b));
  m = matinverseimage(m, matid(#m)[,1]);
  Polrev( vecextract(m, Str("..", poldegree(b))), variable(b) )
}
? inversemod(a,b)
%2 = Mod(2,4)*y^5 + Mod(3,4)*y^3 + Mod(1,4)*y^2 + Mod(3,4)*y + Mod(2,4)
@eprog\noindent
This is not guaranteed to work either since it must invert pivots. See
\secref{se:linear_algebra}.

The library syntax is \fun{GEN}{gpow}{GEN x, GEN n, long prec}
for $x\hbox{\kbd{\pow}}n$.


\subsecidx{divrem}$(x,y,\{v\})$: \label{se:divrem}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

The library syntax is \fun{GEN}{divrem}{GEN x, GEN y, long v = -1}, where \kbd{v} is a variable number.
Also available is \fun{GEN}{gdiventres}{GEN x, GEN y} when $v$ is
not needed.

\subsecidx{lex}$(x,y)$: \label{se:lex}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

The library syntax is \fun{GEN}{lexcmp}{GEN x, GEN y}.

\subsecidx{max}$(x,y)$: \label{se:max}creates the maximum of $x$ and $y$ when they can be compared.

The library syntax is \fun{GEN}{gmax}{GEN x, GEN y}.

\subsecidx{min}$(x,y)$: \label{se:min}creates the minimum of $x$ and $y$ when they can be compared.

The library syntax is \fun{GEN}{gmin}{GEN x, GEN y}.

\subsecidx{shift}$(x,n)$: \label{se:shift}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$.

The library syntax is \fun{GEN}{gshift}{GEN x, long n}.

\subsecidx{shiftmul}$(x,n)$: \label{se:shiftmul}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.

The library syntax is \fun{GEN}{gmul2n}{GEN x, long n}.

\subsecidx{sign}$(x)$: \label{se:sign}\idx{sign} ($0$, $1$ or $-1$) of $x$, which must be of
type integer, real or fraction.

The library syntax is \fun{GEN}{gsigne}{GEN x}.

\subsecidx{vecmax}$(x)$: \label{se:vecmax}if $x$ is a vector or a matrix, returns the maximum
of the elements of $x$, otherwise returns a copy of $x$. Error if $x$ is
empty.

The library syntax is \fun{GEN}{vecmax}{GEN x}.

\subsecidx{vecmin}$(x)$: \label{se:vecmin}if $x$ is a vector or a matrix, returns the minimum
of the elements of $x$, otherwise returns a copy of $x$. Error if $x$ is
empty.

The library syntax is \fun{GEN}{vecmin}{GEN x}.
%SECTION: operators

\subsec{Comparison and Boolean operators}\sidx{Boolean operators} The six
standard \idx{comparison operators} \kbd{<=}, \kbd{<}, \kbd{>=}, \kbd{>},
\kbd{==}, \kbd{!=} are available in GP. The result is 1 if the comparison is
true, 0 if it is false. The operator \kbd{==} is quite liberal : for
instance, the integer 0, a 0 polynomial, and a vector with 0 entries are all
tested equal.

The extra operator \kbd{===} tests whether two objects are identical and is
much stricter than \kbd{==} : objects of different type or length are never
identical.


For the purpose of comparison, \typ{STR} objects are strictly larger than any
other non-string type; two \typ{STR} objects are compared using the standard
lexicographic order.

GP accepts the following synonyms for some of the above functions:
\kbd{|} and \kbd{\&} are accepted as\sidx{bitwise and}\sidx{bitwise or}
synonyms of \kbd{||} and \kbd{\&\&} respectively. Also, \kbd{<>} is accepted
as a synonym for \kbd{!=}. On the other hand, \kbd{=} is definitely
\emph{not} a synonym for \kbd{==}: it is the assignment statement. (We do not
use the customary C operators for bitwise \kbd{and} or bitwise \kbd{or}; use
\tet{bitand} or \tet{bitor}.)

The standard boolean operators \kbd{||} (\idx{inclusive or}), \kbd{\&\&}
(\idx{and})\sidx{or} and \kbd{!} (\idx{not}) are also available.

\section{Conversions and similar elementary functions or commands}
\label{se:conversion}

\noindent
Many of the conversion functions are rounding or truncating operations. In
this case, if the argument is a rational function, the result is the
Euclidean quotient of the numerator by the denominator, and if the argument
is a vector or a matrix, the operation is done componentwise. This will not
be restated for every function.


\subsecidx{Col}$(\{x=[\,]\})$: \label{se:Col}
transforms the object $x$ into a column vector.
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 column vector),

\item a matrix (the column of row vectors comprising the matrix is
returned),

\item a character string (a column of individual characters is returned),

\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{Col} is the reciprocal function of \kbd{Pol} and \kbd{Ser}
respectively.

Note that the function \kbd{Colrev} does not exist, use \kbd{Vecrev}.

The library syntax is \fun{GEN}{gtocol}{GEN x = NULL}.

\subsecidx{List}$(\{x=[\,]\})$: \label{se:List}
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.

The library syntax is \fun{GEN}{gtolist}{GEN x = NULL}.
The variant \fun{GEN}{listcreate}{void} creates an empty list.

\subsecidx{Mat}$(\{x=[\,]\})$: \label{se:Mat}
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 associated big matrix is returned.
If $x$ is a binary quadratic form, creates the associated $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

The library syntax is \fun{GEN}{gtomat}{GEN x = NULL}.

\subsecidx{Mod}$(x,y)$: \label{se:Mod}
creates the PARI object
$(x \mod y)$, i.e.~an intmod or a polmod. $y$ must be an integer or a
polynomial. If $y$ is an integer, $x$ must be an integer, a rational
number, or a $p$-adic number compatible with the modulus $y$. If $y$ is a
polynomial, $x$ must be a scalar (which is not a polmod), a polynomial, a
rational function, or a power series.

This function is not the same as $x$ \kbd{\%} $y$, the result of which is an
integer or a polynomial.

The library syntax is \fun{GEN}{gmodulo}{GEN x, GEN y}.

\subsecidx{Pol}$(x,\{v=x\})$: \label{se:Pol}
transforms the object $x$ into a polynomial with main variable $v$. If $x$
is a scalar, this gives a constant polynomial. If $x$ 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 $x$ is a vector: it creates the
polynomial whose coefficients are given by $x$, with $x[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

The library syntax is \fun{GEN}{gtopoly}{GEN x, long v = -1}, where \kbd{v} is a variable number.

\subsecidx{Polrev}$(x,\{v=x\})$: \label{se:Polrev}
transform the object $x$ into a polynomial
with main variable $v$. If $x$ is a scalar, this gives a constant polynomial.
If $x$ 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 $x$ is a vector: it creates the
polynomial whose coefficients are given by $x$, with $x[1]$ being the
constant term. \tet{Pol} can be used if one wants $x[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}).

The library syntax is \fun{GEN}{gtopolyrev}{GEN x, long v = -1}, where \kbd{v} is a variable number.

\subsecidx{Qfb}$(a,b,c,\{D=0.\})$: \label{se:Qfb}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.

The library syntax is \fun{GEN}{Qfb0}{GEN a, GEN b, GEN c, GEN D = NULL, long prec}.
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$).

\subsecidx{Ser}$(s,\{v=x\},\{d=\var{seriesprecision}\})$: \label{se:Ser}transforms the object $s$ into a power series with main variable $v$
($x$ by default) and precision (number of significant terms) equal to
$d$ (= the default \kbd{seriesprecision} by default). If $s$ is a
scalar, this gives a constant power series with precision \kbd{d}. If $s$
is a polynomial, the precision is the maximum of \kbd{d} and the degree of
the polynomial. If $s$ is a vector, 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.
\bprog
? Ser(x^2,, 5)
%1 = x^2 + O(x^7)
? Ser([1,2,3], t)
%2 = 1 + 2*t + 3*t^2 + O(t^3)
@eprog\noindent
The warning given for \kbd{Pol} also applies here: this is not a substitution
function.

The library syntax is \fun{GEN}{gtoser}{GEN s, long v = -1, long precdl}, where \kbd{v} is a variable number.

\subsecidx{Set}$(\{x=[\,]\})$: \label{se:Set}
converts $x$ into a set, i.e.~into a row
vector of character strings, with strictly increasing entries with respect to
lexicographic ordering. The components of $x$ are put in canonical form (type
\typ{STR}) so as to be easily sorted. To recover an ordinary \kbd{GEN} from
such an element, you can apply \tet{eval} to it.

Note that most set functions also accept ordinary vectors, provided their
components can be compared with \kbd{<}. Sets as created by this function
are only useful when e.g. polynomial or vector entries are involved.

The library syntax is \fun{GEN}{gtoset}{GEN x = NULL}.

\subsecidx{Str}$(\{x\}*)$: \label{se:Str}
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}

\subsecidx{Strchr}$(x)$: \label{se:Strchr}
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

The library syntax is \fun{GEN}{Strchr}{GEN x}.

\subsecidx{Strexpand}$(\{x\}*)$: \label{se:Strexpand}
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}

\subsecidx{Strtex}$(\{x\}*)$: \label{se:Strtex}
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}

\subsecidx{Vec}$(\{x=[\,]\})$: \label{se:Vec}
transforms the object $x$ into a row vector.
That 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 matrix (the vector of columns comprising the matrix is return),

\item a character string (a vector of individual
characters is returned),

\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.

The library syntax is \fun{GEN}{gtovec}{GEN x = NULL}.

\subsecidx{Vecrev}$(\{x=[\,]\})$: \label{se:Vecrev}
as $\kbd{Vec}(x)$, then reverse the result. In particular
In this case, \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.

The library syntax is \fun{GEN}{gtovecrev}{GEN x = NULL}.

\subsecidx{Vecsmall}$(\{x=[\,]\})$: \label{se:Vecsmall}
transforms the object $x$ into a row
vector of type \typ{VECSMALL}. This acts as \kbd{Vec}, but only on a
limited set of objects (the result must be representable as a vector of small
integers). In particular, polynomials and power series are forbidden.
If $x$ is a character string, a vector of individual characters in ASCII
encoding is returned (\tet{Strchr} yields back the character string).

The library syntax is \fun{GEN}{gtovecsmall}{GEN x = NULL}.

\subsecidx{binary}$(x)$: \label{se:binary}
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.

The library syntax is \fun{GEN}{binaire}{GEN x}.

\subsecidx{bitand}$(x,y)$: \label{se:bitand}
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

The library syntax is \fun{GEN}{gbitand}{GEN x, GEN y}.
Also available is
\fun{GEN}{ibitand}{GEN x, GEN y}, which returns the bitwise \emph{and}
of $|x|$ and $|y|$, two integers.

\subsecidx{bitneg}$(x,\{n=-1\})$: \label{se:bitneg}
\idx{bitwise negation} of an integer $x$,
truncated to $n$ bits, 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.

The library syntax is \fun{GEN}{gbitneg}{GEN x, long n}.

\subsecidx{bitnegimply}$(x,y)$: \label{se:bitnegimply}
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.

The library syntax is \fun{GEN}{gbitnegimply}{GEN x, GEN y}.
Also available is
\fun{GEN}{ibitnegimply}{GEN x, GEN y}, which returns the bitwise negated
imply of $|x|$ and $|y|$, two integers.

\subsecidx{bitor}$(x,y)$: \label{se:bitor}
\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.

The library syntax is \fun{GEN}{gbitor}{GEN x, GEN y}.
Also available is
\fun{GEN}{ibitor}{GEN x, GEN y}, which returns the bitwise \emph{ir}
of $|x|$ and $|y|$, two integers.

\subsecidx{bittest}$(x,n)$: \label{se:bittest}
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, 3)
%1 = 1 \\ the 3rd bit is 1
? bittest(7, 4)
%2 = 0 \\ the 4th bit is 0
@eprog\noindent
See \secref{se:bitand} for the behavior at negative arguments.

The library syntax is \fun{GEN}{gbittest}{GEN x, long n}.
For a \typ{INT} $x$, the variant \fun{long}{bittest}{GEN x, long n} is
generally easier to use.

\subsecidx{bitxor}$(x,y)$: \label{se:bitxor}
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.

The library syntax is \fun{GEN}{gbitxor}{GEN x, GEN y}.
Also available is
\fun{GEN}{ibitxor}{GEN x, GEN y}, which returns the bitwise \emph{xor}
of $|x|$ and $|y|$, two integers.

\subsecidx{ceil}$(x)$: \label{se:ceil}
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.

The library syntax is \fun{GEN}{gceil}{GEN x}.

\subsecidx{centerlift}$(x,\{v\})$: \label{se:centerlift}
lifts an element $x=a \bmod n$ of $\Z/n\Z$
to $a$ in $\Z$, and similarly lifts a polmod to a polynomial. This is the
same as \tet{lift} except that in the particular case of elements of
$\Z/n\Z$, the lift $y$ is such that $-n/2<y\le n/2$.  A \typ{PADIC} is lifted
as above if its valuation $v$ is non-negative; if not, returns the fraction
$p^v$ \kbd{centerlift}$(x^{-v})$; in particular, note that rational
reconstruction is not attempted.

If $x$ is of type fraction, complex, quadratic, polynomial, power series,
rational function, vector or matrix, the lift is done for each coefficient.
Reals are forbidden.

The library syntax is \fun{GEN}{centerlift0}{GEN x, long v = -1}, where \kbd{v} is a variable number.
Also available is \fun{GEN}{centerlift}{GEN x} corresponding to
\kbd{centerlift0(x,-1)}.

\subsecidx{component}$(x,n)$: \label{se:component}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 acurracy)
    ? component(x, 1)
    %3 = 3    \\ p
    ? q = Qfb(1,2,3);
    ? component(q, 1)
    %5 = 1
@eprog

The library syntax is \fun{GEN}{compo}{GEN x, long n}.

\subsecidx{conj}$(x)$: \label{se:conj}
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).

The library syntax is \fun{GEN}{gconj}{GEN x}.

\subsecidx{conjvec}$(z)$: \label{se:conjvec}
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$.

The library syntax is \fun{GEN}{conjvec}{GEN z, long prec}.

\subsecidx{denominator}$(x)$: \label{se:denominator}
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}.

The library syntax is \fun{GEN}{denom}{GEN x}.

\subsecidx{floor}$(x)$: \label{se:floor}
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.

The library syntax is \fun{GEN}{gfloor}{GEN x}.

\subsecidx{frac}$(x)$: \label{se:frac}
fractional part of $x$. Identical to
$x-\text{floor}(x)$. If $x$ is real, the result is in $[0,1[$.

The library syntax is \fun{GEN}{gfrac}{GEN x}.

\subsecidx{imag}$(x)$: \label{se:imag}imaginary part of $x$. When $x$ is a quadratic number, this is the
coefficient of $\omega$ in the ``canonical'' integral basis $(1,\omega)$.

The library syntax is \fun{GEN}{gimag}{GEN x}.

\subsecidx{length}$(x)$: \label{se:length}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.

The library syntax is \fun{long}{glength}{GEN x}.

\subsecidx{lift}$(x,\{v\})$: \label{se:lift}lifts an element $x=a \bmod n$ of $\Z/n\Z$ to
$a$ in $\Z$, and similarly lifts a polmod to a polynomial if $v$ is omitted.
Otherwise, lifts only polmods whose modulus has main variable $v$ (if $v$
does not occur in $x$, lifts only intmods). If $x$ is of recursive (non
modular) type, the lift is done coefficientwise. For $p$-adics, this routine
acts as \tet{truncate}. It is not allowed to have $x$ of type \typ{REAL}.
\bprog
? lift(Mod(5,3))
%1 = 2
? lift(3 + O(3^9))
%2 = 3
? lift(Mod(x,x^2+1))
%3 = x
? 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(2, y^2+1)
@eprog

The library syntax is \fun{GEN}{lift0}{GEN x, long v = -1}, where \kbd{v} is a variable number.
Also available is \fun{GEN}{lift}{GEN x} corresponding to
\kbd{lift0(x,-1)}.

\subsecidx{norm}$(x)$: \label{se:norm}
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.

The library syntax is \fun{GEN}{gnorm}{GEN x}.

\subsecidx{norml2}$(x)$: \label{se:norml2}
square of the $L^2$-norm of $x$. More precisely,
if $x$ is a scalar, $\kbd{norml2}(x)$ is defined to be \kbd{$x$ * conj($x$)}.
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

The library syntax is \fun{GEN}{gnorml2}{GEN x}.

\subsecidx{numerator}$(x)$: \label{se:numerator}
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}.

The library syntax is \fun{GEN}{numer}{GEN x}.

\subsecidx{numtoperm}$(n,k)$: \label{se:numtoperm}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 library syntax is \fun{GEN}{numtoperm}{long n, GEN k}.

\subsecidx{padicprec}$(x,p)$: \label{se:padicprec}absolute $p$-adic precision of the object $x$. This is the minimum
precision of the components of $x$. The result is \tet{LONG_MAX}
($2^{31}-1$ for 32-bit machines or $2^{63}-1$ for 64-bit machines) if $x$ is
an exact object.

The library syntax is \fun{long}{padicprec}{GEN x, GEN p}.

\subsecidx{permtonum}$(x)$: \label{se:permtonum}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 library syntax is \fun{GEN}{permtonum}{GEN x}.

\subsecidx{precision}$(x,\{n\})$: \label{se:precision}gives the precision in decimal digits of the PARI object $x$. If $x$ is
an exact object, the largest single precision integer is returned.
\bprog
? precision(exp(1e-100))
%1 = 134                \\ 134 significant decimal digits
? precision(2 + x)
%2 = 2147483647         \\ exact object
? precision(0.5 + O(x))
%3 = 28                 \\ floating point accuracy, NOT series precision
? precision( [ exp(1e-100), 0.5 ] )
%4 = 28                 \\ minimal accuracy among components
@eprog\noindent
The return value for exact objects is meaningless since it is not even the
same on 32 and 64-bit machines. The proper way to test whether an object is
exact is
\bprog
? isexact(x) = precision(x) == precision(0)
@eprog

If $n$ is not omitted, creates a new object equal to $x$ with a new
``precision'' $n$. (This never changes the type of the result. In particular
it is not possible to use it to obtain a polynomial from a power series; tor
that, see \tet{truncate}.) Now the meaning of precision is different from the
above (floating point accuracy), and depends on the type of $x$:

For exact types, no change. For $x$ a vector or a matrix, the operation is
done componentwise.

For real $x$, $n$ is the number of desired significant \emph{decimal}
digits. If $n$ is smaller than the precision of $x$, $x$ is truncated,
otherwise $x$ is extended with zeros.

For $x$ a $p$-adic or a power series, $n$ is the desired number of
\emph{significant} $p$-adic or $X$-adic digits, where $X$ is the main
variable of $x$. (Note: yes, this is inconsistent.)
Note that the precision is a priori distinct from the exponent $k$ appearing
in $O(*^k)$; it is indeed equal to $k$ if and only if $x$ is a $p$-adic
or $X$-adic \emph{unit}.
\bprog
? precision(1 + O(x), 10)
%1 = 1 + O(x^10)
? precision(x^2 + O(x^10), 3)
%2 = x^2 + O(x^5)
? precision(7^2 + O(7^10), 3)
%3 = 7^2 + O(7^5)
@eprog\noindent
For the last two examples, note that $x^2 + O(x^5) = x^2(1 + O(x^3))$
indeed has 3 significant coefficients

The library syntax is \fun{GEN}{precision0}{GEN x, long n}.
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).

\subsecidx{random}$(\{N=2^{\var{31}}\})$: \label{se:random}
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} 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 an
abscissa is drawn uniformly at random until \tet{ellordinate} succeeds.
In particular, the curves over $\F_2$ with a single point (at infinity!)
will trigger an infinite loop. Note that this is definitely not a uniform
distribution over $E(k)$.

\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([0,0,0,3,7]*Mod(1,109)); random(E)
%4 = [Mod(103, 109), Mod(10, 109)]
? E = ellinit([0,0,0,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 the system's random number generator.
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.

\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
\kbd{http://wwwmaths.anu.edu.au/\til{}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.

The library syntax is \fun{GEN}{genrand}{GEN N = NULL}.

 Also available: \fun{GEN}{ellrandom}{GEN E} and \fun{GEN}{ffrandom}{GEN a}.

\subsecidx{real}$(x)$: \label{se:real}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)$.

The library syntax is \fun{GEN}{greal}{GEN x}.

\subsecidx{round}$(x,\{\&e\})$: \label{se:round}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.

The library syntax is \fun{GEN}{round0}{GEN x, GEN *e = NULL}.
Also available are \fun{GEN}{grndtoi}{GEN x, long *e} and
\fun{GEN}{ground}{GEN x}.

\subsecidx{simplify}$(x)$: \label{se:simplify}
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

The library syntax is \fun{GEN}{simplify}{GEN x}.

\subsecidx{sizebyte}$(x)$: \label{se:sizebyte}outputs the total number of bytes occupied by the tree representing the
PARI object $x$.

The library syntax is \fun{long}{gsizebyte}{GEN x}.
Also available is \fun{long}{gsizeword}{GEN x} returning a
number of \emph{words}.

\subsecidx{sizedigit}$(x)$: \label{se:sizedigit}
outputs a quick bound for the number of decimal
digits of (the components of) $x$, off by at most $1$. If you want the
exact value, you can use \kbd{\#Str(x)}, which is slower.

The library syntax is \fun{long}{sizedigit}{GEN x}.

\subsecidx{truncate}$(x,\{\&e\})$: \label{se:truncate}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)$.

The library syntax is \fun{GEN}{trunc0}{GEN x, GEN *e = NULL}.
The following functions are also available: \fun{GEN}{gtrunc}{GEN x}
and \fun{GEN}{gcvtoi}{GEN x, long *e}.

\subsecidx{valuation}$(x,p)$: \label{se:valuation}
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 \tet{LONG_MAX} ($2^{31}-1$ for 32-bit machines or
$2^{63}-1$ for 64-bit machines) 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.

The library syntax is \fun{long}{ggval}{GEN x, GEN p}.

\subsecidx{variable}$(\{x\})$: \label{se:variable}
gives the main variable of the object $x$, and
$p$ if $x$ is a $p$-adic number. Gives an error if $x$ has no variable
associated to it. If $x$ is omitted, returns the list of user variables known
to the interpreter, by order of decreasing priority. (Highest priority is $x$,
which always come first.)

The library syntax is \fun{GEN}{gpolvar}{GEN x = NULL}.
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.
%SECTION: conversions

\section{Transcendental functions}\label{se:trans}

Since the values of transcendental functions cannot be exactly represented,
these functions will always return an inexact object: a real number,
a complex number, a $p$-adic number or a power series.  All these objects
have a certain finite precision.

As a general rule, which of course in some cases may have exceptions,
transcendental functions operate in the following way:

\item If the argument is either a real number or an inexact complex number
(like \kbd{1.0 + I} or \kbd{Pi*I} but not \kbd{2 - 3*I}), then the
computation is done with the precision of the argument.
In the example below, we see that changing the precision to $50$ digits does
not matter, because $x$ only had a precision of $19$ digits.
\bprog
? \p 15
   realprecision = 19 significant digits (15 digits displayed)
? x = Pi/4
%1 = 0.785398163397448
? \p 50
   realprecision = 57 significant digits (50 digits displayed)
? sin(x)
%2 = 0.7071067811865475244
@eprog

Note that even if the argument is real, the result may be complex
(e.g.~$\text{acos}(2.0)$ or $\text{acosh}(0.0)$). See each individual
function help for the definition of the branch cuts and choice of principal
value.

\item If the argument is either an integer, a rational, an exact complex
number or a quadratic number, it is first converted to a real
or complex number using the current \idx{precision} held in the default
\tet{realprecision}.  This precision (the number of decimal digits) can be
changed using \b{p} or \kbd{default(realprecision,...)}).
After this conversion, the computation proceeds as above for real or complex
arguments.

In library mode, the \kbd{realprecision} does not matter; instead the
precision is taken from the \kbd{prec} parameter which every transcendental
function has.  As in \kbd{gp}, this \kbd{prec} is not used when the
argument to a function is already inexact.
Note that the argument \var{prec} stands for the length in words of a real
number, including codewords. Hence we must have $\var{prec} \geq 3$.

Some accuracies attainable on 32-bit machines cannot be attained
on 64-bit machines for parity reasons. For example the default \kbd{gp} accuracy
is 28 decimal digits on 32-bit machines, corresponding to \var{prec} having
the value 5, but this cannot be attained on 64-bit machines.

\item If the argument is a polmod (representing an algebraic number),
then the function is evaluated for every possible complex embedding of that
algebraic number.  A column vector of results is returned, with one component
for each complex embedding.  Therefore, the number of components equals
the degree of the \typ{POLMOD} modulus.

\item If the argument is an intmod or a $p$-adic, at present only a
few functions like \kbd{sqrt} (square root), \kbd{sqr} (square), \kbd{log},
\kbd{exp}, powering, \kbd{teichmuller} (Teichm\"uller character) and
\kbd{agm} (arithmetic-geometric mean) are implemented.

Note that in the case of a $2$-adic number, $\kbd{sqr}(x)$ may not be
identical to $x*x$: for example if $x = 1+O(2^5)$ and $y = 1+O(2^5)$ then
$x*y = 1+O(2^5)$ while $\kbd{sqr}(x) = 1+O(2^6)$. Here, $x * x$ yields the
same result as $\kbd{sqr}(x)$ since the two operands are known to be
\emph{identical}. The same statement holds true for $p$-adics raised to the
power $n$, where $v_p(n) > 0$.

\misctitle{Remark} If we wanted to be strictly consistent with
the PARI philosophy, we should have $x*y = (4 \mod 8)$ and $\kbd{sqr}(x) =
(4 \mod 32)$ when both $x$ and $y$ are congruent to $2$ modulo $4$.
However, since intmod is an exact object, PARI assumes that the modulus
must not change, and the result is hence $(0\, \mod\, 4)$ in both cases. On
the other hand, $p$-adics are not exact objects, hence are treated
differently.

\item If the argument is a polynomial, a power series or a rational function,
it is, if necessary, first converted to a power series using the current
series precision, held in the default \tet{seriesprecision}. This precision
(the number of significant terms) can be changed using \b{ps} or
\kbd{default(seriesprecision,...)}. Then the Taylor series expansion of the
function around $X=0$ (where $X$ is the main variable) is computed to a
number of terms depending on the number of terms of the argument and the
function being computed.

Under \kbd{gp} this again is transparent to the user. When programming in
library mode, however, it is \emph{strongly} advised to perform an explicit
conversion to a power series first, as in \kbd{x = gtoser(x, seriesprec)},
where the number of significant terms \kbd{seriesprec} can be specified
explicitly. If you do not do this, a global variable \kbd{precdl} is used
instead, to convert polynomials and rational functions to a power series with
a reasonable number of terms; tampering with the value of this global
variable is \emph{deprecated} and strongly discouraged.


\item If the argument is a vector or a matrix, the result is the
componentwise evaluation of the function. In particular, transcendental
functions on square matrices, which are not implemented in the present
version \vers, will have a different name if they are implemented some day.

\subseckbd{\pow}: If $y$ is not of type integer, \kbd{x\pow y} has the same
effect as \kbd{exp(y*log(x))}. It can be applied to $p$-adic numbers as well
as to the more usual types.\sidx{powering}

The library syntax is \fun{GEN}{gpow}{GEN x, GEN n, long prec}
for $x\hbox{\kbd{\pow}}n$.


\subsecidx{Euler}: \label{se:Euler}Euler's constant $\gamma=0.57721\cdots$. Note that
\kbd{Euler} is one of the few special reserved names which cannot be used for
variables (the others are \kbd{I} and \kbd{Pi}, as well as all function
names).

The library syntax is \fun{GEN}{mpeuler}{long prec}.

\subsecidx{I}: \label{se:I}the complex number $\sqrt{-1}$.

The library syntax is \fun{GEN}{gen_I}{}.

\subsecidx{Pi}: \label{se:Pi}the constant $\pi$ ($3.14159\cdots$).

The library syntax is \fun{GEN}{mppi}{long prec}.

\subsecidx{abs}$(x)$: \label{se:abs}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.

The library syntax is \fun{GEN}{gabs}{GEN x, long prec}.

\subsecidx{acos}$(x)$: \label{se:acos}principal branch of $\text{cos}^{-1}(x) = -i \log (x + i\sqrt{1-x^2})$.
In particular, $\text{Re(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$.

The library syntax is \fun{GEN}{gacos}{GEN x, long prec}.

\subsecidx{acosh}$(x)$: \label{se:acosh}principal branch of $\text{cosh}^{-1}(x) = 2
 \log(\sqrt{(x+1)/2} + \sqrt{(x-1)/2})$. In particular,
$\text{Re}(\text{acosh}(x))\geq 0$ and
$\text{In}(\text{acosh}(x))\in ]-\pi,\pi]0$; if $x\in \R$ and $x<1$, then
$\text{acosh}(x)$ is complex.

The library syntax is \fun{GEN}{gach}{GEN x, long prec}.

\subsecidx{agm}$(x,y)$: \label{se:agm}arithmetic-geometric mean of $x$ and $y$. In the
case of complex or negative numbers, the principal square root is always
chosen. $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.

The library syntax is \fun{GEN}{agm}{GEN x, GEN y, long prec}.

\subsecidx{arg}$(x)$: \label{se:arg}argument of the complex number $x$, such that $-\pi<\text{arg}(x)\le\pi$.

The library syntax is \fun{GEN}{garg}{GEN x, long prec}.

\subsecidx{asin}$(x)$: \label{se:asin}principal branch of $\text{sin}^{-1}(x) = -i \log(ix + \sqrt{1 - x^2})$.
In particular, $\text{Re(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)$.

The library syntax is \fun{GEN}{gasin}{GEN x, long prec}.

\subsecidx{asinh}$(x)$: \label{se:asinh}principal branch of $\text{sinh}^{-1}(x) = \log(x + \sqrt{1+x^2})$. In
particular $\text{Im(asinh}(x))\in [-\pi/2,\pi/2]$.
The branch cut is in two pieces: [-i oo ,-i],  continuous with quadrant III
and [i,+i oo [ continuous with quadrant I.

The library syntax is \fun{GEN}{gash}{GEN x, long prec}.

\subsecidx{atan}$(x)$: \label{se:atan}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 $i \text{atan}(x) =
-i\text{atanh}(ix)$ for all $x\neq \pm i$.

The library syntax is \fun{GEN}{gatan}{GEN x, long prec}.

\subsecidx{atanh}$(x)$: \label{se:atanh}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.

The library syntax is \fun{GEN}{gath}{GEN x, long prec}.

\subsecidx{bernfrac}$(x)$: \label{se:bernfrac}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.

The library syntax is \fun{GEN}{bernfrac}{long x}.

\subsecidx{bernreal}$(x)$: \label{se:bernreal}Bernoulli number\sidx{Bernoulli numbers}
$B_x$, as \kbd{bernfrac}, but $B_x$ is returned as a real number
(with the current precision).

The library syntax is \fun{GEN}{bernreal}{long x, long prec}.

\subsecidx{bernvec}$(x)$: \label{se:bernvec}creates a vector containing, as rational numbers,
the \idx{Bernoulli numbers} $B_0$, $B_2$,\dots, $B_{2x}$.
This routine is obsolete. Use \kbd{bernfrac} instead each time you need a
Bernoulli number in exact form.

\misctitle{Note} This routine is implemented using repeated independent
calls to \kbd{bernfrac}, which is faster than the standard recursion in exact
arithmetic. It is only kept for backward compatibility: it is not faster than
individual calls to \kbd{bernfrac}, its output uses a lot of memory space,
and coping with the index shift is awkward.

The library syntax is \fun{GEN}{bernvec}{long x}.

\subsecidx{besselh1}$(\var{nu},x)$: \label{se:besselh1}$H^1$-Bessel function of index \var{nu} and argument $x$.

The library syntax is \fun{GEN}{hbessel1}{GEN nu, GEN x, long prec}.

\subsecidx{besselh2}$(\var{nu},x)$: \label{se:besselh2}$H^2$-Bessel function of index \var{nu} and argument $x$.

The library syntax is \fun{GEN}{hbessel2}{GEN nu, GEN x, long prec}.

\subsecidx{besseli}$(\var{nu},x)$: \label{se:besseli}$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).

The library syntax is \fun{GEN}{ibessel}{GEN nu, GEN x, long prec}.

\subsecidx{besselj}$(\var{nu},x)$: \label{se:besselj}$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).

The library syntax is \fun{GEN}{jbessel}{GEN nu, GEN x, long prec}.

\subsecidx{besseljh}$(n,x)$: \label{se:besseljh}$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.

The library syntax is \fun{GEN}{jbesselh}{GEN n, GEN x, long prec}.

\subsecidx{besselk}$(\var{nu},x)$: \label{se:besselk}$K$-Bessel function of index \var{nu} and argument $x$.

The library syntax is \fun{GEN}{kbessel}{GEN nu, GEN x, long prec}.

\subsecidx{besseln}$(\var{nu},x)$: \label{se:besseln}$N$-Bessel function of index \var{nu} and argument $x$.

The library syntax is \fun{GEN}{nbessel}{GEN nu, GEN x, long prec}.

\subsecidx{cos}$(x)$: \label{se:cos}cosine of $x$.

The library syntax is \fun{GEN}{gcos}{GEN x, long prec}.

\subsecidx{cosh}$(x)$: \label{se:cosh}hyperbolic cosine of $x$.

The library syntax is \fun{GEN}{gch}{GEN x, long prec}.

\subsecidx{cotan}$(x)$: \label{se:cotan}cotangent of $x$.

The library syntax is \fun{GEN}{gcotan}{GEN x, long prec}.

\subsecidx{dilog}$(x)$: \label{se:dilog}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$.

The library syntax is \fun{GEN}{dilog}{GEN x, long prec}.

\subsecidx{eint1}$(x,\{n\})$: \label{se:eint1}exponential integral $\int_x^\infty \dfrac{e^{-t}}{t}\,dt$ ($x\in\R$)

If $n$ is present, outputs the $n$-dimensional vector
$[\kbd{eint1}(x),\dots,\kbd{eint1}(nx)]$ ($x \geq 0$). This is faster than
repeatedly calling \kbd{eint1($i$ * x)}.

The library syntax is \fun{GEN}{veceint1}{GEN x, GEN n = NULL, long prec}.
Also available is \fun{GEN}{eint1}{GEN x, long prec}.

\subsecidx{erfc}$(x)$: \label{se:erfc}complementary error function, analytic continuation of
$(2/\sqrt\pi)\int_x^\infty e^{-t^2}\,dt$ ($x\in\R$).

The library syntax is \fun{GEN}{gerfc}{GEN x, long prec}.

\subsecidx{eta}$(z,\{\fl=0\})$: \label{se:eta}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}$.

The library syntax is \fun{GEN}{eta0}{GEN z, long flag, long prec}.

Also available is \fun{GEN}{trueeta}{GEN x, long prec} ($\fl=1$).

\subsecidx{exp}$(x)$: \label{se:exp}exponential of $x$.
$p$-adic arguments with positive valuation are accepted.

The library syntax is \fun{GEN}{gexp}{GEN x, long prec}.
For a \typ{PADIC} $x$, the function
\fun{GEN}{Qp_exp}{GEN x} is also available.

\subsecidx{gamma}$(s)$: \label{se:gamma}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 $p$-adic number, 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

The library syntax is \fun{GEN}{ggamma}{GEN s, long prec}.
For a \typ{PADIC} $x$, the function
\fun{GEN}{Qp_gamma}{GEN x} is also available.

\subsecidx{gammah}$(x)$: \label{se:gammah}gamma function evaluated at the argument $x+1/2$.

The library syntax is \fun{GEN}{ggamd}{GEN x, long prec}.

\subsecidx{hyperu}$(a,b,x)$: \label{se:hyperu}$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.

The library syntax is \fun{GEN}{hyperu}{GEN a, GEN b, GEN x, long prec}.

\subsecidx{incgam}$(s,x,\{y\})$: \label{se:incgam}incomplete gamma function. The argument $x$
and $s$ are complex numbers ($x$ must be a positive real number if $s = 0$).
The result returned is $\int_x^\infty e^{-t}t^{s-1}\,dt$. When $y$ is given,
assume (of course without checking!) that $y=\Gamma(s)$. For small $x$, this
will speed up the computation.

The library syntax is \fun{GEN}{incgam0}{GEN s, GEN x, GEN y = NULL, long prec}.
Also available is \fun{GEN}{incgam}{GEN s, GEN x, long prec}.

\subsecidx{incgamc}$(s,x)$: \label{se:incgamc}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$.

The library syntax is \fun{GEN}{incgamc}{GEN s, GEN x, long prec}.

\subsecidx{lngamma}$(x)$: \label{se:lngamma}principal branch of the logarithm of the gamma
function of $x$. This function is analytic on the complex plane with
non-positive integers removed. Can have much larger arguments than \kbd{gamma}
itself. The $p$-adic \kbd{lngamma} function is not implemented.

The library syntax is \fun{GEN}{glngamma}{GEN x, long prec}.

\subsecidx{log}$(x)$: \label{se:log}principal branch of the natural logarithm of
$x \in \C^*$, i.e.~such that $\text{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$.

The library syntax is \fun{GEN}{glog}{GEN x, long prec}.
For a \typ{PADIC} $x$, the function
\fun{GEN}{Qp_log}{GEN x} is also available.

\subsecidx{polylog}$(m,x,\{\fl=0\})$: \label{se:polylog}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)$.

The library syntax is \fun{GEN}{polylog0}{long m, GEN x, long flag, long prec}.
Also available is
\fun{GEN}{gpolylog}{long m, GEN x, long prec} (\fl = 0).

\subsecidx{psi}$(x)$: \label{se:psi}the $\psi$-function of $x$, i.e.~the
logarithmic derivative $\Gamma'(x)/\Gamma(x)$.

The library syntax is \fun{GEN}{gpsi}{GEN x, long prec}.

\subsecidx{sin}$(x)$: \label{se:sin}sine of $x$.

The library syntax is \fun{GEN}{gsin}{GEN x, long prec}.

\subsecidx{sinh}$(x)$: \label{se:sinh}hyperbolic sine of $x$.

The library syntax is \fun{GEN}{gsh}{GEN x, long prec}.

\subsecidx{sqr}$(x)$: \label{se:sqr}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).

The library syntax is \fun{GEN}{gsqr}{GEN x}.

\subsecidx{sqrt}$(x)$: \label{se:sqrt}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$ and $p$-adics are allowed as arguments. In that case,
the square root (if it exists) which is returned is the one whose
first $p$-adic digit is in the interval $[0,p/2]$. When the argument is an
intmod a non-prime (or a non-prime-adic), the result is undefined.

The library syntax is \fun{GEN}{gsqrt}{GEN x, long prec}.
For a \typ{PADIC} $x$, the function
\fun{GEN}{Qp_sqrt}{GEN x} is also available.

\subsecidx{sqrtn}$(x,n,\{\&z\})$: \label{se:sqrtn}principal branch of the $n$th root of $x$,
i.e.~such that $\text{Arg}(\text{sqrt}(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 square root exist,
$0$ is returned instead or raising an error.
\bprog
? sqrtn(Mod(2,7), 2)
%1 = Mod(4, 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

The library syntax is \fun{GEN}{gsqrtn}{GEN x, GEN n, GEN *z = NULL, long prec}.
If $x$ is a \typ{PADIC}, the function
\fun{GEN}{Qp_sqrt}{GEN x, GEN n, GEN *z} is also available.

\subsecidx{tan}$(x)$: \label{se:tan}tangent of $x$.

The library syntax is \fun{GEN}{gtan}{GEN x, long prec}.

\subsecidx{tanh}$(x)$: \label{se:tanh}hyperbolic tangent of $x$.

The library syntax is \fun{GEN}{gth}{GEN x, long prec}.

\subsecidx{teichmuller}$(x)$: \label{se:teichmuller}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$.

The library syntax is \fun{GEN}{teich}{GEN x}.

\subsecidx{theta}$(q,z)$: \label{se:theta}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).$$

The library syntax is \fun{GEN}{theta}{GEN q, GEN z, long prec}.

\subsecidx{thetanullk}$(q,k)$: \label{se:thetanullk}$k$-th derivative at $z=0$ of $\kbd{theta}(q,z)$.

The library syntax is \fun{GEN}{thetanullk}{GEN q, long k, long prec}.

\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$.

\subsecidx{weber}$(x,\{\fl=0\})$: \label{se:weber}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$.

The library syntax is \fun{GEN}{weber0}{GEN x, long flag, long prec}.
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}.

\subsecidx{zeta}$(s)$: \label{se:zeta}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$).

The library syntax is \fun{GEN}{gzeta}{GEN s, long prec}.
%SECTION: transcendental

\section{Arithmetic functions}\label{se:arithmetic}

These functions are by definition functions whose natural domain of
definition is either $\Z$ (or $\Z_{>0}$). The way these functions are used is
completely different from transcendental functions in that there are no
automatic type conversions: in general only integers are accepted as
arguments.

\subsec{Arithmetic functions and factorization}
All arithmetic functions in the narrow sense of the word~--- Euler's
totient\sidx{Euler totient function} function, the \idx{Moebius} function,
the sums over divisors or powers of divisors etc.--- call, after trial
division by small primes, the same versatile factoring machinery described
under \kbd{factorint}. It includes \idx{Shanks SQUFOF}, \idx{Pollard Rho},
\idx{ECM} and \idx{MPQS} stages, and has an early exit option for the
functions \teb{moebius} and (the integer function underlying)
\teb{issquarefree}. This machinery relies on a fairly strong
probabilistic primality test, see \kbd{ispseudoprime}, but you may also set
\bprog
  default(factor_proven, 1)
@eprog\noindent to ensure that all tentative factorizations are fully proven.
This should not slow down PARI too much, unless prime numbers with
hundreds of decimal digits occur frequently in your application.

\subsec{Orders in finite groups and Discrete Logarithm functions}
\label{se:DLfun}

The following functions compute the order of an element in a finite group:
\kbd{ellorder} (the rational points on an elliptic curve defined over a
finite field), \kbd{fforder} (the multiplicative group of a finite field),
\kbd{znorder} (the invertible elements in $\Z/n\Z$). The following functions
compute discrete logarithms in the same groups (whenever this is meaningful)
\kbd{elllog}, \kbd{fflog}, \kbd{znlog}.

All such functions allow an optional argument specifying an integer
$N$, representing the order of the group. (The \emph{order} functions also
allows any non-zero multiple of the order, with a minor loss of efficiency.)
The meaning of that optional argument is as follows and depends on its type

\item \typ{INT}: the integer $N$,

\item \typ{MAT}: the factorization \kbd{fa = factor($N$)},

\item \typ{VEC}: this is the preferred format and provides both the
integer $N$ and its factorization in a two-component vector \kbd{[$N$,
fa]}.

When the group is fixed and many orders or discrete logarithms will be
computed, it is much more efficient to initialize this data once and for all
and pass it to the relevant functions, as in
\bprog
? p = nextprime(10^40);
? v = [p-1, factor(p-1)]; \\ data for discrete log & order computations
? znorder(Mod(2,p), v)
%3 = 500000000000000000000000000028
? g = znprimroot(p);
? znlog(2, g, v)
%5 = 543038070904014908801878611374
@eprog
\bigskip


\subsecidx{addprimes}$(\{x=[\,]\})$: \label{se:addprimes}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}.

The library syntax is \fun{GEN}{addprimes}{GEN x = NULL}.

\subsecidx{bestappr}$(x, \{A\},\{B\})$: \label{se:bestappr}if $B$ is omitted, finds the best rational approximation to $x\in\R$
using continued fractions. If $A$ is omitted, return the best approximation
affordable given the input accuracy; otherwise make sure that denominator is
at most equal to $A$.

If $B$ is
present perform rational modular reconstruction (see below). In both cases,
the function applies recursively to components of complex objects
(polynomials, vectors, \dots).
\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, $n/d$ is the best rational approximation to $x$ if
$|d x - n| < |v x - u|$ for all integers $(u,v)$ with $v \leq A$. (Which
implies that $n/d$ is a convergent of the continued fraction of $x$.)

If $x$ is an \typ{INTMOD},  (or a recursive combination of
those), modulo $N$ say, $B$ must be present. The routine then returns the
unique rational number $a/b$ in coprime integers $a\leq A$ and $b\leq B$ which
is congruent to $x$ modulo $N$. If $N \leq 2AB$, uniqueness is not guaranteed
and the function fails with an error message. If rational reconstruction is not
possible (no such $a/b$ exists for at least one component of $x$), returns
$-1$.

\bprog
? bestappr(Mod(18526731858, 11^10), 10^10, 10^10)
 ***   at top-level: bestappr(Mod(1852673
 ***                 ^--------------------
 *** bestappr: ratlift: must have 2*amax*bmax < m, found
       amax=10000000000
       bmax=10000000000
       m=25937424601
? bestappr(Mod(18526731858, 11^10), 10^5, 10^5)
%1 = 1/7
? bestappr(Mod(18526731858, 11^20), 10^10, 10^10)
%2 = -1
@eprog\noindent In most concrete uses, $B$ is a prime power and we performed
Hensel lifting to obtain $x$.

If $x$ is a \typ{POLMOD}, modulo $T$ say, $B$ must be present. The routine
then returns the unique rational function $P/Q$ with  $\deg P\leq A$ and $\deg
Q\leq B$ which is congruent to $x$ modulo $T$. If $\deg T \leq A+B$, uniqueness
is not guaranteed and the function fails with an error message. If rational
reconstruction is not possible, returns $-1$.

The library syntax is \fun{GEN}{bestappr0}{GEN x, GEN A = NULL, GEN B = NULL}.
Also available is \fun{GEN}{bestappr}{GEN x, GEN A}.

\subsecidx{bezout}$(x,y)$: \label{se:bezout}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}

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

? bezout(a,a)
%2 = [0, 1, x + 0.E-28]

? bezout(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.

The library syntax is \fun{GEN}{vecbezout}{GEN x, GEN y}.

\subsecidx{bezoutres}$(x,y)$: \label{se:bezoutres}finds $u$ and $v$ such that $x*u + y*v = d$, where $d$ is the resultant
of $x$ and $y$. The result is the row vector $[u,v,d]$. \sidx{extended gcd}
The algorithm used (subresultant) assumes that the base ring is a domain.

The library syntax is \fun{GEN}{vecbezoutres}{GEN x, GEN y}.

\subsecidx{bigomega}$(x)$: \label{se:bigomega}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
The function accepts vector/matrices arguments, and is then applied
componentwise.

The library syntax is \fun{GEN}{gbigomega}{GEN x}.
For a \typ{INT} $x$, the variant
\fun{long}{bigomega}{GEN n} is generally easier to use.

\subsecidx{binomial}$(x,y)$: \label{se:binomial}\idx{binomial coefficient} $\binom{x}{y}$.
Here $y$ must be an integer, but $x$ can be any PARI object.

The library syntax is \fun{GEN}{binomial}{GEN x, long y}.
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$.

\subsecidx{chinese}$(x,\{y\})$: \label{se:chinese}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.

This function also allows vector and matrix arguments, in which case the
operation is recursively applied to each component of the vector or matrix.
For polynomial arguments, it is applied to each coefficient.

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.

The library syntax is \fun{GEN}{chinese}{GEN x, GEN y = NULL}.
\fun{GEN}{chinese1}{GEN x} is also available.

\subsecidx{content}$(x)$: \label{se:content}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

The library syntax is \fun{GEN}{content}{GEN x}.

\subsecidx{contfrac}$(x,\{b\},\{\var{nmax}\})$: \label{se:contfrac}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$)}.

The library syntax is \fun{GEN}{contfrac0}{GEN x, GEN b = NULL, long nmax}.
Also available are \fun{GEN}{gboundcf}{GEN x, long nmax},
\fun{GEN}{gcf}{GEN x} and \fun{GEN}{gcf2}{GEN b, GEN x}.

\subsecidx{contfracpnqn}$(x)$: \label{se:contfracpnqn}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$.

The library syntax is \fun{GEN}{pnqn}{GEN x}.

\subsecidx{core}$(n,\{\fl=0\})$: \label{se:core}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]$.

The library syntax is \fun{GEN}{core0}{GEN n, long flag}.
Also available are \fun{GEN}{core}{GEN n} ($\fl = 0$) and
\fun{GEN}{core2}{GEN n} ($\fl = 1$)

\subsecidx{coredisc}$(n,\{\fl=0\})$: \label{se:coredisc}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^*$.

The library syntax is \fun{GEN}{coredisc0}{GEN n, long flag}.
Also available are \fun{GEN}{coredisc}{GEN n} ($\fl = 0$) and
\fun{GEN}{coredisc2}{GEN n} ($\fl = 1$)

\subsecidx{dirdiv}$(x,y)$: \label{se:dirdiv}$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.

The library syntax is \fun{GEN}{dirdiv}{GEN x, GEN y}.

\subsecidx{direuler}$(p=a,b,\var{expr},\{c\})$: \label{se:direuler}computes the \idx{Dirichlet series} associated 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 present, output
only the first $c$ coefficients in the series. The following command computes
the \teb{sigma} function, associated 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]
@eprog

\synt{direuler}{void *E, GEN (*eval)(void*,GEN), GEN a, GEN b}

\subsecidx{dirmul}$(x,y)$: \label{se:dirmul}$x$ and $y$ being vectors of perhaps different lengths considered as
\idx{Dirichlet series}, computes the product of $x$ by $y$, again as a vector.

The library syntax is \fun{GEN}{dirmul}{GEN x, GEN y}.

\subsecidx{divisors}$(x)$: \label{se:divisors}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.

The library syntax is \fun{GEN}{divisors}{GEN x}.

\subsecidx{eulerphi}$(x)$: \label{se:eulerphi}Euler's $\phi$ (totient)\sidx{Euler totient function} function of $|x|$,
in other words $|(\Z/x\Z)^*|$. Normally, $x$ must be of type integer, but
the function accepts vector/matrices arguments, and is then applied
componentwise.

The library syntax is \fun{GEN}{geulerphi}{GEN x}.
For a \typ{INT} $x$, the variant
\fun{GEN}{eulerphi}{GEN n} is also available.

\subsecidx{factor}$(x,\{\var{lim}\})$: \label{se:factor}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 10^{15}$ (whose norm is $\leq 10^{15}$ 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 and
satisfy
$\var{lim} \leq \kbd{primelimit} + 1$; setting $\var{lim}=0$ is the same
as setting it to $\kbd{primelimit} + 1$. 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
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]

? default(primelimit,10^9)
time = 4,360 ms.
%5 = 1000000000
? factor(F, 10^9)    \\ very slow
time = 6,120 ms.
%6 =
[1009 1]

[100003 1]

[340282366920938463463374607431768211457 1]

? factorint(F, 1+8)  \\ much faster, all small primes were found
time = 40 ms.
%7 =
[1009 1]

[100003 1]

[340282366920938463463374607431768211457 1]

? factorint(F)   \\ complete factorisation
time = 260 ms.
%8 =
[1009 1]

[100003 1]

[59649589127497217 1]

[5704689200685129054721 1]
@eprog

\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. See \tet{factormod} and \tet{factorff} for
the algorithms used over finite fields, \tet{factornf} for the algorithms
over number fields. Over $\Q$, \idx{van Hoeij}'s method is used, which is
able to cope with hundreds of modular factors.

The routine guesses a sensible ring over which you want 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).
Note that 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\noindent
See also \tet{nffactor}.

The library syntax is \fun{GEN}{gp_factor0}{GEN x, GEN lim = NULL}.
This function should only be used by the \kbd{gp} interface. Use
directly \fun{GEN}{factor}{GEN x} or \fun{GEN}{boundfact}{GEN x, long lim}.
The obsolete function \fun{GEN}{factor0}{GEN x, long lim} is kept for
backward compatibility.

\subsecidx{factorback}$(f,\{e\})$: \label{se:factorback}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

The library syntax is \fun{GEN}{factorback2}{GEN f, GEN e = NULL}.
Also available is \fun{GEN}{factorback}{GEN f} (case $e = \kbd{NULL}$).

\subsecidx{factorcantor}$(x,p)$: \label{se:factorcantor}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}.

The library syntax is \fun{GEN}{factcantor}{GEN x, GEN p}.

\subsecidx{factorff}$(x,\{p\},\{a\})$: \label{se:factorff}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.

The library syntax is \fun{GEN}{factorff}{GEN x, GEN p = NULL, GEN a = NULL}.

\subsecidx{factorial}$(x)$: \label{se:factorial}factorial of $x$. The expression $x!$ gives a result which is an integer,
while $\kbd{factorial}(x)$ gives a real number.

The library syntax is \fun{GEN}{mpfactr}{long x, long prec}.
\fun{GEN}{mpfact}{long x} returns $x!$ as a \typ{INT}.

\subsecidx{factorint}$(x,\{\fl=0\})$: \label{se:factorint}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).

The library syntax is \fun{GEN}{factorint}{GEN x, long flag}.

\subsecidx{factormod}$(x,p,\{\fl=0\})$: \label{se:factormod}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.

The library syntax is \fun{GEN}{factormod0}{GEN x, GEN p, long flag}.

\subsecidx{ffgen}$(P,\{v\})$: \label{se:ffgen}return the generator $g=X \pmod{P(X)}$ of the
finite field defined by the polynomial $P$ (which must have \typ{INTMOD}
coefficients). If \kbd{v} is given, the variable name is used to display $g$,
else the variable of the polynomial $P$ is used.

The library syntax is \fun{GEN}{ffgen}{GEN P, long v = -1}, where \kbd{v} is a variable number.

\subsecidx{ffinit}$(p,n,\{v=x\})$: \label{se:ffinit}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-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,g)}.

The library syntax is \fun{GEN}{ffinit}{GEN p, long n, long v = -1}, where \kbd{v} is a variable number.

\subsecidx{fflog}$(x,g,\{o\})$: \label{se:fflog}discrete logarithm of the finite field element $x$ in base $g$. 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.
See \tet{znlog} for the limitations of the underlying discrete log algorithms.
\bprog
? t = ffgen(ffinit(7,5));
? o = fforder(t)
%2 = 5602   \\@com \emph{not} a primitive root.
? fflog(t^10,t)
%3 = 11214  \\@com Actually correct modulo o. We are lucky !
? 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  \\ no surprise there !
? fforder(g^10000, g, o)
? fflog(g^10000, g, o)
%9 = 10000
@eprog

The library syntax is \fun{GEN}{fflog}{GEN x, GEN g, GEN o = NULL}.

\subsecidx{fforder}$(x,\{o\})$: \label{se:fforder}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

The library syntax is \fun{GEN}{fforder}{GEN x, GEN o = NULL}.

\subsecidx{ffprimroot}$(x, \{\&o\})$: \label{se:ffprimroot}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

The library syntax is \fun{GEN}{ffprimroot}{GEN x, GEN *o = NULL}.

\subsecidx{fibonacci}$(x)$: \label{se:fibonacci}$x^{\text{th}}$ Fibonacci number.

The library syntax is \fun{GEN}{fibo}{long x}.

\subsecidx{gcd}$(x,\{y\})$: \label{se:gcd}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)
%2 = 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{bezout}, which does try to compute an approximate gcd
$d$ and provides $u$, $v$ to check whether $u x + v y$ is close to $d$.

The library syntax is \fun{GEN}{ggcd0}{GEN x, GEN y = NULL}.
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}$.

\subsecidx{hilbert}$(x,y,\{p\})$: \label{se:hilbert}\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.)

The library syntax is \fun{long}{hilbert}{GEN x, GEN y, GEN p = NULL}.

\subsecidx{isfundamental}$(x)$: \label{se:isfundamental}true (1) if $x$ is equal to 1 or to the discriminant of a quadratic
field, false (0) otherwise.
The function accepts vector/matrices arguments, and is then applied
componentwise.

The library syntax is \fun{GEN}{gisfundamental}{GEN x}.

\subsecidx{ispower}$(x,\{k\},\{\&n\})$: \label{se:ispower}if $k$ is given, returns true (1) if $x$ is a $k$-th power, false
(0) if not.

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 ^ poldegree(x.pol) - 1) / fforder(x)
@eprog

The library syntax is \fun{long}{ispower}{GEN x, GEN k = NULL, GEN *n = NULL}.
Also available is
\fun{long}{gisanypower}{GEN x, GEN *pty} ($k$ omitted).

\subsecidx{isprime}$(x,\{\fl=0\})$: \label{se:isprime}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.

The library syntax is \fun{GEN}{gisprime}{GEN x, long flag}.

\subsecidx{ispseudoprime}$(x,\{\fl\})$: \label{se:ispseudoprime}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$ is a Baillie-Pomerance-Selfridge-Wagstaff
pseudo prime (strong Rabin-Miller pseudo prime for base $2$, followed by
strong 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 this test, although it is
expected that infinitely many such numbers exist. In particular, all
composites $\leq 2^{64}$ are correctly detected (checked using
\kbd{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$).

The library syntax is \fun{GEN}{gispseudoprime}{GEN x, long flag}.

\subsecidx{issquare}$(x,\{\&n\})$: \label{se:issquare}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
? issquare([4, x^2], &n)
%3 = [1, 1]  \\ both are squares
? n
%4 = [2, x]  \\ the square roots
@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.
The function accepts vector/matrices arguments, and is then applied
componentwise.

The library syntax is \fun{GEN}{gissquareall}{GEN x, GEN *n = NULL}.
Also available is \fun{GEN}{gissquare}{GEN x}.

\subsecidx{issquarefree}$(x)$: \label{se:issquarefree}true (1) if $x$ is squarefree, false (0) if not. Here $x$ can be an
integer or a polynomial.
The function accepts vector/matrices arguments, and is then applied
componentwise.

The library syntax is \fun{GEN}{gissquarefree}{GEN x}.
For scalar arguments $x$ (\typ{INT} or \typ{POL}), the function
\fun{long}{issquarefree}{GEN x} is easier to use.

\subsecidx{kronecker}$(x,y)$: \label{se:kronecker}
\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$.

The library syntax is \fun{GEN}{gkronecker}{GEN x, GEN y}.

\subsecidx{lcm}$(x,\{y\})$: \label{se:lcm}least common multiple of $x$ and $y$, i.e.~such
that $\lcm(x,y)*\gcd(x,y) = \text{abs}(x*y)$. If $y$ is omitted and $x$
is a vector, returns the $\text{lcm}$ of all components of $x$.

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^4, i, random);
? lcm(v);
time = 323 ms.
? l = v[1]; for (i = 1, #v, l = lcm(l, v[i]))
time = 833 ms.
@eprog

The library syntax is \fun{GEN}{glcm0}{GEN x, GEN y = NULL}.

\subsecidx{moebius}$(x)$: \label{se:moebius}\idx{Moebius} $\mu$-function of $|x|$. $x$ must be of type integer.
The function accepts vector/matrices arguments, and is then applied
componentwise.

The library syntax is \fun{GEN}{gmoebius}{GEN x}.
For a \typ{INT} $x$, the variant
\fun{long}{moebius}{GEN n} is generally easier to use.

\subsecidx{nextprime}$(x)$: \label{se:nextprime}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}.
The function accepts vector/matrices arguments, and is then applied
componentwise.

The library syntax is \fun{GEN}{gnextprime}{GEN x}.
For a scalar $x$,
\fun{long}{nextprime}{GEN n} is also available.

\subsecidx{numbpart}$(n)$: \label{se:numbpart}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}.

The library syntax is \fun{GEN}{numbpart}{GEN n}.

\subsecidx{numdiv}$(x)$: \label{se:numdiv}number of divisors of $|x|$. $x$ must be of type integer.
The function accepts vector/matrices arguments, and is then applied
componentwise.

The library syntax is \fun{GEN}{gnumbdiv}{GEN x}.
If $x$ is a \typ{INT}, one may use \fun{GEN}{numbdiv}{GEN n} directly.

\subsecidx{omega}$(x)$: \label{se:omega}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
The function accepts vector/matrices arguments, and is then applied
componentwise.

The library syntax is \fun{GEN}{gomega}{GEN x}.
For a \typ{INT} $x$, the variant
\fun{long}{omega}{GEN n} is generally easier to use.

\subsecidx{partitions}$(n,\{\var{restr}=0\})$: \label{se:partitions}returns vector of partitions of the integer $n$ (negative values return
\kbd{[]}, $n = 0$ returns the trivial partition of the empty set).
The second optional argument may be set to a non-negative number smaller than
$n$ to restrict the value of each element in the partitions to that value.
The default of 0 means that this maximum is $n$ itself.

A partition is given by a \typ{VECSMALL}:
\bprog
? partitions(4, 2)
%1 = [Vecsmall([2, 2]), Vecsmall([1, 1, 2]), Vecsmall([1, 1, 1, 1])]
@eprog\noindent
correspond to $2+2$, $1+1+2$, $1+1+1+1$.

The library syntax is \fun{GEN}{partitions}{long n, long restr}.

\subsecidx{polrootsff}$(x,\{p\},\{a\})$: \label{se:polrootsff}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.

The library syntax is \fun{GEN}{polrootsff}{GEN x, GEN p = NULL, GEN a = NULL}.

\subsecidx{precprime}$(x)$: \label{se:precprime}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}.
The function accepts vector/matrices arguments, and is then applied
componentwise.

The library syntax is \fun{GEN}{gprecprime}{GEN x}.
For a scalar $x$, \fun{long}{precprime}{GEN n} is also available.

\subsecidx{prime}$(n)$: \label{se:prime}the $x^{\text{th}}$ prime number, which must be among
the precalculated primes.

The library syntax is \fun{GEN}{prime}{long n}.

\subsecidx{primepi}$(x)$: \label{se:primepi}the prime counting function. Returns the number of
primes $p$, $p \leq x$. Uses a naive algorithm so that $x$ must be less than
\kbd{primelimit}.

The library syntax is \fun{GEN}{primepi}{GEN x}.

\subsecidx{primes}$(x)$: \label{se:primes}creates a row vector whose components
are the first $x$ prime numbers, which must be among the precalculated primes.
\bprog
? primes(10)           \\ the first 10 primes
%1 = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
? primes(primepi(10))  \\ the primes up to 10
%2 = [2, 3, 5, 7]
@eprog

The library syntax is \fun{GEN}{primes}{long x}.

\subsecidx{qfbclassno}$(D,\{\fl=0\})$: \label{se:qfbclassno}ordinary class number of the quadratic
order of discriminant $D$. In the present version \vers, a $O(D^{1/2})$
algorithm is used for $D > 0$ (using Euler product and the functional
equation) so $D$ should not be too large, say $D < 10^8$, for the time to be
reasonable. On the other hand, for $D < 0$ one can reasonably compute
\kbd{qfbclassno($D$)} for $|D|<10^{25}$, since the routine uses
\idx{Shanks}'s method which is in $O(|D|^{1/4})$. For larger values of $|D|$,
see \kbd{quadclassunit}.

If $\fl=1$, compute the class number using \idx{Euler product}s and the
functional equation. However, it is in $O(|D|^{1/2})$.

\misctitle{Important warning} For $D < 0$, this function may give incorrect
results when the class group has many cyclic factors,
because implementing \idx{Shanks}'s method in full generality slows it down
immensely. It is therefore strongly recommended to double-check results using
either the version with $\fl = 1$ or the function \kbd{quadclassunit}.

\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}.

The library syntax is \fun{GEN}{qfbclassno0}{GEN D, long flag}.
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.

\subsecidx{qfbcompraw}$(x,y)$: \label{se:qfbcompraw}\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 library syntax is \fun{GEN}{qfbcompraw}{GEN x, GEN y}.

\subsecidx{qfbhclassno}$(x)$: \label{se:qfbhclassno}\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.

The library syntax is \fun{GEN}{hclassno}{GEN x}.

\subsecidx{qfbnucomp}$(x,y,L)$: \label{se:qfbnucomp}\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|^{1/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 straightforward and in general \emph{slower}
than the generic routine (since the latter takes advantage of asymptotically
fast operations and careful optimizations).

The library syntax is \fun{GEN}{nucomp}{GEN x, GEN y, GEN L}.
Also available is \fun{GEN}{nudupl}{GEN x, GEN L} when $x=y$.

\subsecidx{qfbnupow}$(x,n)$: \label{se:qfbnupow}$n$-th power of the primitive positive definite
binary quadratic form $x$ using \idx{Shanks}'s NUCOMP and NUDUPL algorithms
(see \kbd{qfbnucomp}, in particular the final warning).

The library syntax is \fun{GEN}{nupow}{GEN x, GEN n}.

\subsecidx{qfbpowraw}$(x,n)$: \label{se:qfbpowraw}$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}$.

The library syntax is \fun{GEN}{qfbpowraw}{GEN x, long n}.

\subsecidx{qfbprimeform}$(x,p)$: \label{se:qfbprimeform}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.

The library syntax is \fun{GEN}{primeform}{GEN x, GEN p, long prec}.

\subsecidx{qfbred}$(x,\{\fl=0\},\{d\},\{\var{isd}\},\{\var{sd}\})$: \label{se:qfbred}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.

The library syntax is \fun{GEN}{qfbred0}{GEN x, long flag, GEN d = NULL, GEN isd = NULL, GEN sd = NULL}.
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)}).

\subsecidx{qfbsolve}$(Q,p)$: \label{se:qfbsolve}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.

The library syntax is \fun{GEN}{qfbsolve}{GEN Q, GEN p}.

\subsecidx{quadclassunit}$(D,\{\fl=0\},\{\var{tech}=[\,]\})$: \label{se:quadclassunit}\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 positive 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 = 0.2$ means that relations are easier
to find, but more relations are needed and the linear algebra will be
harder. 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).

The library syntax is \fun{GEN}{quadclassunit0}{GEN D, long flag, GEN tech = NULL, long prec}.
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}

\subsecidx{quaddisc}$(x)$: \label{se:quaddisc}discriminant of the quadratic field $\Q(\sqrt{x})$, where $x\in\Q$.

The library syntax is \fun{GEN}{quaddisc}{GEN x}.

\subsecidx{quadgen}$(D)$: \label{se:quadgen}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.

The library syntax is \fun{GEN}{quadgen}{GEN D}.

\subsecidx{quadhilbert}$(D)$: \label{se:quadhilbert}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.

The library syntax is \fun{GEN}{quadhilbert}{GEN D, long prec}.

\subsecidx{quadpoly}$(D,\{v=x\})$: \label{se:quadpoly}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.

The library syntax is \fun{GEN}{quadpoly0}{GEN D, long v = -1}, where \kbd{v} is a variable number.

\subsecidx{quadray}$(D,f)$: \label{se:quadray}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.

The library syntax is \fun{GEN}{quadray}{GEN D, GEN f, long prec}.

\subsecidx{quadregulator}$(x)$: \label{se:quadregulator}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.

The library syntax is \fun{GEN}{quadregulator}{GEN x, long prec}.

\subsecidx{quadunit}$(D)$: \label{se:quadunit}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}).

The library syntax is \fun{GEN}{quadunit}{GEN D}.

\subsecidx{removeprimes}$(\{x=[\,]\})$: \label{se:removeprimes}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.

The library syntax is \fun{GEN}{removeprimes}{GEN x = NULL}.

\subsecidx{sigma}$(x,\{k=1\})$: \label{se:sigma}sum of the $k^{\text{th}}$ powers of the positive divisors of $|x|$. $x$
and $k$ must be of type integer.
The function accepts vector/matrices arguments for $x$, and is then applied
componentwise.

The library syntax is \fun{GEN}{gsumdivk}{GEN x, long k}.
Also available are
\fun{GEN}{gsumdiv}{GEN n} ($k = 1$), \fun{GEN}{sumdivk}{GEN n,long k}
($n$ a \typ{INT}) and \fun{GEN}{sumdiv}{GEN n} ($k = 1$, $n$ a \typ{INT})

\subsecidx{sqrtint}$(x)$: \label{se:sqrtint}integer square root of $x$, which must be a non-negative integer. The
result is non-negative and rounded towards zero.

The library syntax is \fun{GEN}{sqrtint}{GEN x}.

\subsecidx{stirling}$(n,k,\{\fl=1\})$: \label{se:stirling}\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]; t[2]);
}
@eprog

The library syntax is \fun{GEN}{stirling}{long n, long k, long flag}.
Also available are \fun{GEN}{stirling1}{ulong n, ulong k}
($\fl=1$) and \fun{GEN}{stirling2}{ulong n, ulong k} ($\fl=2$).

\subsecidx{sumdedekind}$(h,k)$: \label{se:sumdedekind}returns the \idx{Dedekind sum} associated 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

The library syntax is \fun{GEN}{sumdedekind}{GEN h, GEN k}.

\subsecidx{zncoppersmith}$(P, N, X, \{B=N\})$: \label{se:zncoppersmith}$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
p = nextprime(random(10^30));
q = nextprime(random(10^30)); N = p*q;
p0 = p % 10^20; \\ assume we know 1) p > 10^29, 2) the last 19 digits of p
p1 = zncoppersmith(10^19*x + p0, N, 10^12, 10^29)

\\ result in 10ms.
%1 = [35023733690]
? gcd(p1[1] * 10^19 + p0, N) == p
%2 = 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 3.8s.
%3 = [265174753892462432]
? %[1] == x0
%4 = 1
@eprog\noindent
We guessed an integer of the order of $10^{18}$ in a couple of seconds.

The library syntax is \fun{GEN}{zncoppersmith}{GEN P, GEN N, GEN X, GEN B = NULL}.

\subsecidx{znlog}$(x,g,\{o\})$: \label{se:znlog}discrete logarithm of $x$ in $(\Z/N\Z)^*$ in base $g$.
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$.
If no $o$ is given, assume that $g$ generate $(\Z/N\Z)^*$.

This function uses a simple-minded combination of generic
discrete log algorithms (index calculus methods are not yet implemented).

\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$ small),

\item Pollard rho method ($q$ large).

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.
\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
@eprog\noindent The result is undefined when $x$ is not a power of $g$ or
when $x$ is not invertible mod $N$:
\bprog
? znlog(6, Mod(2,3))
  ***   at top-level: znlog(6,Mod(2,3))
  ***                 ^-----------------
  *** znlog: impossible inverse modulo: Mod(0, 3).
@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

The library syntax is \fun{GEN}{znlog}{GEN x, GEN g, GEN o = NULL}.

\subsecidx{znorder}$(x,\{o\})$: \label{se:znorder}$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.

The library syntax is \fun{GEN}{znorder}{GEN x, GEN o = NULL}.
Also available is \fun{GEN}{order}{GEN x}.

\subsecidx{znprimroot}$(n)$: \label{se:znprimroot}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, then the smallest positive primitive root is
returned. This is no longer true for composites.

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 very costly if $p$ is large.
The function accepts vector/matrices arguments, and is then applied
componentwise.

The library syntax is \fun{GEN}{znprimroot0}{GEN n}.
For a \typ{INT} $x$, the special case
\fun{GEN}{znprimroot}{GEN n} is also available.

\subsecidx{znstar}$(n)$: \label{se:znstar}gives the structure of the multiplicative group
$(\Z/n\Z)^*$ as a 3-component row vector $v$, where $v[1]=\phi(n)$ is the
order of that group, $v[2]$ is a $k$-component row-vector $d$ of integers
$d[i]$ such that $d[i]>1$ and $d[i]\mid d[i-1]$ for $i \ge 2$ and
$(\Z/n\Z)^* \simeq \prod_{i=1}^k(\Z/d[i]\Z)$, and $v[3]$ is a $k$-component row
vector giving generators of the image of the cyclic groups $\Z/d[i]\Z$.

The library syntax is \fun{GEN}{znstar}{GEN n}.
%SECTION: number_theoretical

\section{Functions related to elliptic curves}

We have implemented a number of functions which are useful for number
theorists working on elliptic curves. We always use \idx{Tate}'s notations.
The functions assume that the curve is given by a general Weierstrass
model\sidx{Weierstrass equation}
$$
  y^2+a_1xy+a_3y=x^3+a_2x^2+a_4x+a_6,
$$
where a priori the $a_i$ can be of any scalar type. This curve can be
considered as a five-component vector \kbd{E=[a1,a2,a3,a4,a6]}. Points on
\kbd{E} are represented as two-component vectors \kbd{[x,y]}, except for the
point at infinity, i.e.~the identity element of the group law, represented by
the one-component vector \kbd{[0]}.

  It is useful to have at one's disposal more information. This is given by
the function \tet{ellinit}, which initializes and returns an
\tev{ell} structure by default. If a specific flag is added, a
shortened \tev{smallell} is returned, which is much
faster to compute but contains less information. The following \idx{member
functions} are available to deal with the output of \kbd{ellinit},
both \var{ell} and \var{smallell}:
\settabs\+xxxxxxxxxxxxxxxxxx&: &\cr

\+ \kbd{a1}--\kbd{a6}, \kbd{b2}--\kbd{b8}, \kbd{c4}--\kbd{c6} &: &
coefficients of the elliptic curve.\cr

\+ \tet{area} &: &  volume of the complex lattice defining $E$.\cr

\+ \tet{disc} &: & discriminant of the curve.\cr

\+ \tet{j}    &: & $j$-invariant of the curve.\cr

\+ \tet{omega}&: & $[\omega_1,\omega_2]$, periods forming a basis of
the complex lattice defining $E$ ($\omega_1$ is the\cr

\+            &   & real period, and $\omega_1/\omega_2$ belongs to
Poincar\'e's half-plane).\cr

\+ \tet{eta}  &: & quasi-periods $[\eta_1, \eta_2]$, such that
$\eta_1\omega_2-\eta_2\omega_1=2i\pi$.\cr

\+ \tet{roots}&: & roots of the associated Weierstrass equation.\cr

\+ \tet{tate} &: & $[u^2,u,v]$ in the notation of Tate.\cr

\+ \tet{w} &: & Mestre's $w$ (this is technical).\cr

\noindent
{\bf Warning:} as for the orientation of the basis of the period lattice,
beware that many sources use the inverse convention where $\omega_2/\omega_1$
has positive imaginary part and our $\omega_2$ is the negative of theirs. Our
convention $\tau = \omega_1/\omega_2$  ensures that the action of $\text{PSL}_2$ is the natural
one:
$$[a,b;c,d]\cdot\tau = (a\tau+b)/(c\tau+d)
  = (a \omega_1 + b\omega_2)/(c\omega_1 + d\omega_2),$$
instead of a twisted one. (Our $tau$ is $-1/\tau$ in the above inverse
convention.)

The member functions \kbd{area}, \kbd{eta} and \kbd{omega} are only available
for curves over $\Q$. Conversely, \kbd{tate} and \kbd{w} are only available
for curves defined over $\Q_p$. The use of member functions is best described
by an example:
\bprog
  ? E = ellinit([0,0,0,0,1]); \\@com The curve $y^2 = x^3 + 1$
  ? E.a6
  %2 = 1
  ? E.c6
  %3 = -864
  ? E.disc
  %4 = -432
@eprog
\smallskip

Some functions, in particular those relative to height computations (see
\kbd{ellheight}) require also that the curve be in minimal Weierstrass
form, which is duly stressed in their description below. This is achieved by
the function \kbd{ellminimalmodel}. \emph{Using a non-minimal model in such a
routine will yield a wrong result!}

All functions related to elliptic curves share the prefix \kbd{ell}, and the
precise curve we are interested in is always the first argument, in either
one of the three formats discussed above, unless otherwise specified. The
requirements are given as the \emph{minimal} ones: any richer structure may
replace the ones requested. For instance, in functions which have no use for
the extra information given by an \tev{ell} structure, the curve can be given
either as a five-component vector, as a \var{smallell}, or as an \var{ell};
if a \var{smallell} is requested, an \var{ell} may equally be given.


A few routines --- namely \tet{ellgenerators}, \tet{ellidentify},
\tet{ellsearch}, \tet{forell} --- require the optional package \tet{elldata}
(John Cremona's database) to be installed. The function \tet{ellinit} will
also allow alternative inputs, e.g.~\kbd{ellinit("11a1")}. Functions using
this package need to load chunks of a large database in memory and require
at least 2MB stack to avoid stack overflows.


\subsecidx{ellL1}$(e, r)$: \label{se:ellL1}returns the value at $s=1$ of the derivative of order $r$ of the
$L$-function of the elliptic curve $e$ assuming that $r$ is at most the order
of vanishing of the $L$-function at $s=1$. (The result is wrong if $r$ is
strictly larger than the order of vanishing at 1.)
\bprog
? e = ellinit("11a1"); \\ order of vanishing is 0
? ellL1(e, 0)
%2 = 0.2538418608559106843377589233
? e = ellinit("389a1");  \\ order of vanishing is 2
? ellL1(e, 0)
%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
? ellanalyticrank(ellinit([0, 0, 1, -7, 6]))
time = 32 ms.
%1 = [3, 10.3910994007158041]
? \p200
  realprecision = 202 significant digits (200 digits displayed)
? ellL1(e, 3)
time = 23,113 ms.
%3 = 10.3910994007158041387518505103609170697263563756570092797@com$[\dots]$
@eprog

The library syntax is \fun{GEN}{ellL1}{GEN e, long r, long prec}.

\subsecidx{elladd}$(E,\var{z1},\var{z2})$: \label{se:elladd}
sum of the points $z1$ and $z2$ on the
elliptic curve corresponding to $E$.

The library syntax is \fun{GEN}{addell}{GEN E, GEN z1, GEN z2}.

\subsecidx{ellak}$(E,n)$: \label{se:ellak}
computes the coefficient $a_n$ of the
$L$-function of the elliptic curve $E$, i.e.~in principle coefficients of a
newform of weight 2 assuming \idx{Taniyama-Weil conjecture} (which is now
known to hold in full generality thanks to the work of \idx{Breuil},
\idx{Conrad}, \idx{Diamond}, \idx{Taylor} and \idx{Wiles}). $E$ must be a
\var{smallell} as output by \kbd{ellinit}. For this function
to work for every $n$ and not just those prime to the conductor, $E$ must
be a minimal Weierstrass equation. If this is not the case, use the
function \kbd{ellminimalmodel} before using \kbd{ellak}.

The library syntax is \fun{GEN}{akell}{GEN E, GEN n}.

\subsecidx{ellan}$(E,n)$: \label{se:ellan}
computes the vector of the first $n$ $a_k$
corresponding to the elliptic curve $E$. All comments in \kbd{ellak}
description remain valid.

The library syntax is \fun{GEN}{anell}{GEN E, long n}.

\subsecidx{ellanalyticrank}$(e, \{\var{eps}\})$: \label{se:ellanalyticrank}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

The library syntax is \fun{GEN}{ellanalyticrank}{GEN e, GEN eps = NULL, long prec}.

\subsecidx{ellap}$(E,\{p\})$: \label{se:ellap}computes the trace of Frobenius $a_p$ for the elliptic curve $E$ and the
prime number $p$. This is defined by the equation $\#E(\F_p) = p+1 - a_p$,
where $\#E(\F_p)$ stands for the number of points of the curve $E$ over the
finite field $\F_p$.

No checking is done that $p$ is indeed prime. $E$ must be a \var{smallell} as
output by \kbd{ellinit}, defined over $\Q$, $\Q_p$, or $\F_p$. The prime $p$
may be omitted if the curve was defined over $\F_p$ (\typ{INTMOD}
coefficients) or $\Q_p$ (\typ{PADIC} coefficients). Otherwise the curve must
be defined over $\Q$, and $p$ must be explicitly given. Over $\Q$ or
$\Q_p$, the equation is assumed to be minimal at $p$.
\bprog
? E = ellinit([0,0,0,0,1]);  \\ defined over Q
? ellap(E, 3)  \\ 3 necessary here
%2 = 0    \\ #E(F_3) = 3+1 - 0 = 4
? ellap(E, 7)
%3 = -4   \\ #E(F_7) = 12

? E = ellinit([0,0,0,0,1] * Mod(1,11));  \\ defined over F_11
? ellap(E)       \\ no need to repeat 11
%5 = 0
? ellap(E, 11)   \\ ... but it also works
%6 = 0
? ellgroup(E, 13) \\ ouch, inconsistent input !
   ***   at top-level: ellap(E,13)
   ***                 ^-----------
   *** ellap: inconsistent moduli in Rg_to_Fp: 11, 13.
@eprog
\misctitle{Algorithms used} If $E/\F_p$ has CM by a principal imaginary
quadratic order we use an explicit formula (involving essentially Kronecker
symbols and Cornacchia's algorithm, hence very fast: $O(\log p)^2$).
Otherwise, we use Shanks-Mestre's baby-step/giant-step method, which runs in
time $O(p^{1/4})$ using $O(p^{1/4})$ storage, hence becomes unreasonable when
$p$ has about 30~digits. If the \tet{seadata} package is installed, the
\tet{SEA} algorithm becomes available and primes of the order of 200~digits
become feasible.

The library syntax is \fun{GEN}{ellap}{GEN E, GEN p = NULL}.

\subsecidx{ellbil}$(E,\var{z1},\var{z2})$: \label{se:ellbil}
if $z1$ and $z2$ are points on the elliptic
curve $E$, assumed to be integral given by a minimal model, this function
computes the value of the canonical bilinear form on $z1$, $z2$:
$$ ( h(E,z1\kbd{+}z2) - h(E,z1) - h(E,z2) ) / 2 $$
where \kbd{+} denotes of course addition on $E$. In addition, $z1$ or $z2$
(but not both) can be vectors or matrices.

The library syntax is \fun{GEN}{bilhell}{GEN E, GEN z1, GEN z2, long prec}.

\subsecidx{ellchangecurve}$(E,v)$: \label{se:ellchangecurve}
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 a \var{smallell} as output by \kbd{ellinit}.

The library syntax is \fun{GEN}{ellchangecurve}{GEN E, GEN v}.

\subsecidx{ellchangepoint}$(x,v)$: \label{se:ellchangepoint}
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}).

The library syntax is \fun{GEN}{ellchangepoint}{GEN x, GEN v}.
The reciprocal function \fun{GEN}{ellchangepointinv}{GEN x, GEN ch}
inverts the coordinate change.

\subsecidx{ellconvertname}$(\var{name})$: \label{se:ellconvertname}
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

The library syntax is \fun{GEN}{ellconvertname}{GEN name}.

\subsecidx{elldivpol}$(E,n,\{v='x\})$: \label{se:elldivpol}$n$-division polynomial for the curve \kbd{E} in the
variable $v$.

The library syntax is \fun{GEN}{elldivpol}{GEN E, long n, long v = -1}, where \kbd{v} is a variable number.

\subsecidx{elleisnum}$(E,k,\{\fl=0\})$: \label{se:elleisnum}
$E$ being an elliptic curve as
output by \kbd{ellinit} (or, alternatively, given by a 2-component vector
$[\omega_1,\omega_2]$ representing its periods), and $k$ being an even
positive integer, computes the numerical value of the Eisenstein series of
weight $k$ at $E$, namely
$$
(2i \pi/\omega_2)^k
\Big(1 + 2/\zeta(1-k) \sum_{n\geq 0} 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.

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$.

The library syntax is \fun{GEN}{elleisnum}{GEN E, long k, long flag, long prec}.

\subsecidx{elleta}$(\var{om})$: \label{se:elleta}
returns the quasi-periods $[\eta_1,\eta_2]$
associated to the lattice basis $\var{om} = [\omega_1, \omega_2]$.
Alternatively, \var{om} can be an elliptic curve $E$ as output by
\kbd{ellinit}, in which case, the quasi periods associated 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

The library syntax is \fun{GEN}{elleta}{GEN om, long prec}.

\subsecidx{ellgenerators}$(E)$: \label{se:ellgenerators}
returns a $\Z$-basis of the free part of the
\idx{Mordell-Weil group} associated to $E$.  This function depends on the
\tet{elldata} database being installed and referencing the curve, and so
is only available for curves over $\Z$ of small conductors.

The library syntax is \fun{GEN}{ellgenerators}{GEN E}.

\subsecidx{ellglobalred}$(E)$: \label{se:ellglobalred}
calculates the arithmetic conductor, the global
minimal model of $E$ and the global \idx{Tamagawa number} $c$.
$E$ must be a \var{smallell} as output by \kbd{ellinit}, \emph{and is supposed
to have all its coefficients $a_i$ in} $\Q$. The result is a 3 component
vector $[N,v,c]$. $N$ is the arithmetic conductor of the curve. $v$ gives the
coordinate change for $E$ over $\Q$ to the minimal integral model (see
\tet{ellminimalmodel}). Finally $c$ is the product of the local Tamagawa
numbers $c_p$, a quantity which enters in the \idx{Birch and Swinnerton-Dyer
conjecture}.\sidx{minimal model}

The library syntax is \fun{GEN}{ellglobalred}{GEN E}.

\subsecidx{ellgroup}$(E,\{p\})$: \label{se:ellgroup}computes the structure of the group $E(\F_p) \sim \Z/d_1\Z \times
\Z/d_2\Z$, with $d_2\mid d_1$. The prime $p$ may be omitted if the curve
was defined over $\F_p$ (\typ{INTMOD} coefficients) or $\Q_p$ (\typ{PADIC}
coefficients). Otherwise the curve must be defined over $\Q$, and $p$ must
be explicitly given. Over $\Q$ or $\Q_p$, the equation is assumed to be
minimal at $p$.
\bprog
? E = ellinit([0,0,0,0,1]);  \\ defined over Q
? ellgroup(E, 3)  \\ 3 necessary here
%2 = [4]    \\ cyclic
? ellgroup(E, 7)
%3 = [6, 2] \\ non-cyclic

? E = ellinit([0,0,0,0,1] * Mod(1,11));  \\ defined over F_11
? ellgroup(E)   \\ no need to repeat 11
%5 = [12]
? ellgroup(E, 11)   \\ ... but it also works
%6 = [12]
? ellgroup(E, 13) \\ ouch, inconsistent input !
   ***   at top-level: ellgroup(E,13)
   ***                 ^--------------
   *** ellgroup: inconsistent moduli in Rg_to_Fp: 11, 13.
@eprog

The library syntax is \fun{GEN}{ellgroup}{GEN E, GEN p = NULL}.

\subsecidx{ellheight}$(E,x,\{\fl=2\})$: \label{se:ellheight}global \idx{N\'eron-Tate height} of the point $z$ on the elliptic curve
$E$ (defined over $\Q$), given by a standard minimal integral model. $E$
must be an \kbd{ell} as output by \kbd{ellinit}. \fl selects the algorithm
used to compute the Archimedean local height. If $\fl=0$, this computation
is done using sigma and theta-functions and a trick due to J.~Silverman. If
$\fl=1$, use Tate's $4^n$ algorithm. If $\fl=2$, use Mestre's AGM algorithm.
The latter is much faster than the other two, both in theory (converges
quadratically) and in practice.

The library syntax is \fun{GEN}{ellheight0}{GEN E, GEN x, long flag, long prec}.
Also available is \fun{GEN}{ghell}{GEN E, GEN x, long prec}
($\fl=2$).

\subsecidx{ellheightmatrix}$(E,x)$: \label{se:ellheightmatrix}
$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 that this matrix should be divided by 2 to be in
accordance with certain normalizations. $E$ is assumed to be integral,
given by a minimal model.

The library syntax is \fun{GEN}{mathell}{GEN E, GEN x, long prec}.

\subsecidx{ellidentify}$(E)$: \label{se:ellidentify}
look up the elliptic curve $E$ (over $\Z$)
in the \tet{elldata} database and return \kbd{[[N, M, G], C]}  where $N$
is the name of the curve in the J.~E.~Cremona database, $M$ the minimal
model, $G$ a $\Z$-basis of the free part of the \idx{Mordell-Weil group}
of $E$ and $C$ the coordinates change (see \kbd{ellchangecurve}).

The library syntax is \fun{GEN}{ellidentify}{GEN E}.

\subsecidx{ellinit}$(x,\{\fl=0\})$: \label{se:ellinit}
initialize an \tet{ell} structure,
associated to the elliptic curve $E$. $E$ is either 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 $$
or a string, in this case the coefficients of the curve with matching name
are looked in the \tet{elldata} database if available.
\bprog
? E = ellinit([0,0,0,0,1]); \\ y^2 = x^3 + 1
? E = ellinit("36a1");      \\ the same curve, using Cremona's notations
@eprog\noindent
For the time being, only curves over a prime field $\F_p$ and over the
$p$-adic or real numbers (including rational numbers) are fully supported.
Other domains are only supported for very basic operations such as point
addition.

The result of \tet{ellinit} is an \tev{ell} structure by default, and
a shorter \tev{sell} if $\fl=1$. Both contain the following information in
their 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}.

The other six components are only present if $\fl$ is $0$ or omitted, in
which case the computation will be 10 ($p$-adic) to 200 (complex) times
slower. Their content depends on whether the curve is defined over $\R$ or
not:
\smallskip
\item When $E$ is defined over $\R$, \kbd{$E$.roots} is a vector whose
three components contain the roots of the right hand side of the associated
Weierstrass equation.
$$ (y + a_1x/2 + a_3/2)^2 = g(x) $$
If the roots are all real, they are ordered by decreasing value. If only
one is real, it is the first component.

Then $\omega_1 = $\kbd{$E$.omega[1]} is the real period of $E$ (integral of
$dx/(2y+a_1x+a_3)$ over the connected component of the identity element of
the real points of the curve), and $\omega_2 = $\kbd{$E$.omega[2]} is a
complex period. \kbd{$E$.omega} forms a basis of the
complex lattice defining $E$, such that
$\tau=\dfrac{\omega_1}{\omega_2}$ has positive imaginary part.

\kbd{$E$.eta} is a row vector containing the quasi-periods $\eta_1$ and
$\eta_2$ such that $\eta_i = 2\zeta(\omega_i/2)$, where $\zeta$ is the
Weierstrass zeta function associated to the period lattice (see
\tet{ellzeta}). In particular, the Legendre relation holds:
$\eta_2\omega_1 - \eta_1\omega_2 = 2i\pi$.

Finally, \kbd{$E$.area} is the volume of the complex lattice defining
$E$.\smallskip

\item When $E$ is defined over $\Q_p$, the $p$-adic valuation of $j$
must be negative. Then \kbd{$E$.roots} is the vector with a single component
equal to the $p$-adic root of the associated Weierstrass equation
corresponding to $-1$ under the Tate parametrization.

\kbd{$E$.tate} yields the three-component vector $[u^2,u,q]$, in the
notations of Tate. If the $u$-component does not belong to $\Q_p$, it is set
to zero.

\kbd{$E$.w} is Mestre's $w$ (this is technical).

\smallskip For all other base fields or rings, the last six components are
arbitrarily set to zero. See also the description of member functions
related to elliptic curves at the beginning of this section.

The library syntax is \fun{GEN}{ellinit0}{GEN x, long flag, long prec}.
Also available are \fun{GEN}{ellinit}{GEN E, long prec} ($\fl=0$) and
\fun{GEN}{smallellinit}{GEN E, long prec} ($\fl=1$).

\subsecidx{ellisoncurve}$(E,z)$: \label{se:ellisoncurve}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.

The library syntax is \fun{GEN}{ellisoncurve}{GEN E, GEN z}.
Also available is \fun{int}{oncurve}{GEN E, GEN z} which does not
accept vectors of points.

\subsecidx{ellj}$(x)$: \label{se:ellj}
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.

The library syntax is \fun{GEN}{jell}{GEN x, long prec}.

\subsecidx{elllocalred}$(E,p)$: \label{se:elllocalred}
calculates the \idx{Kodaira} type of the
local fiber of the elliptic curve $E$ at the prime $p$.
$E$ must be a \var{smallell} as output by \kbd{ellinit}, and is assumed to have
all its coefficients $a_i$ in $\Z$. 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. Normally, this
has no use if $u$ is 1, that is, if the given equation was already minimal.
Finally, the last component $c$ is the local \idx{Tamagawa number} $c_p$.

The library syntax is \fun{GEN}{elllocalred}{GEN E, GEN p}.

\subsecidx{elllog}$(E,P,G,\{o\})$: \label{se:elllog}discrete logarithm of the point $P$ of the elliptic curve $E$ in base $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 = ellpow(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
? ellpow(E,G,e) == P
%6 = 1
@eprog

The library syntax is \fun{GEN}{elllog}{GEN E, GEN P, GEN G, GEN o = NULL}.

\subsecidx{elllseries}$(E,s,\{A=1\})$: \label{se:elllseries}
$E$ being an \var{sell} as output by
\kbd{ellinit}, this computes the value of the L-series of $E$ at $s$. It is
assumed that $E$ is defined over $\Q$, not necessarily minimal. The optional
parameter $A$ is a cutoff point for the integral, which must be chosen close
to 1 for best speed. The result must be independent of $A$, so this allows
some internal checking of the function.

Note that if the conductor of the curve is large, say greater than $10^{12}$,
this function will take an unreasonable amount of time since it uses an
$O(N^{1/2})$ algorithm.

The library syntax is \fun{GEN}{elllseries}{GEN E, GEN s, GEN A = NULL, long prec}.

\subsecidx{ellminimalmodel}$(E,\{\&v\})$: \label{se:ellminimalmodel}return the standard minimal integral model of the rational elliptic
curve $E$. If present, sets $v$ to the corresponding change of variables,
which is a vector $[u,r,s,t]$ with rational components. The return value is
identical to that of \kbd{ellchangecurve(E, v)}.

The resulting model has integral coefficients, is everywhere minimal, $a_1$
is 0 or 1, $a_2$ is 0, 1 or $-1$ and $a_3$ is 0 or 1. Such a model is
unique, and the vector $v$ is unique if we specify that $u$ is positive,
which we do. \sidx{minimal model}

The library syntax is \fun{GEN}{ellminimalmodel}{GEN E, GEN *v = NULL}.

\subsecidx{ellmodulareqn}$(l,\{x\},\{y\})$: \label{se:ellmodulareqn}return a vector [\kbd{eqn},$t$] where \kbd{eqn} is a modular equation of
level $l$, for $l<500$, $l$ prime. This requires the package seadata to be
installed. The equation is either of canonical type ($t=0$) or of Atkin type
($t=1$).

The library syntax is \fun{GEN}{ellmodulareqn}{long l, long x = -1, long y = -1}, where \kbd{x}, \kbd{y} are variable numbers.

\subsecidx{ellorder}$(E,z,\{o\})$: \label{se:ellorder}
gives the order of the point $z$ on the elliptic
curve $E$. If the curve is defined over $\Q$, return zero if the point has
infinite order. The parameter $o$, if present, 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.

For a curve defined over $\F_p$, it is very important to supply $o$ since
its computation is very expensive and should only be done once, using
\bprog
? N = p+1-ellap(E,p); o = [N, factor(N)];
@eprog\noindent possibly using the \tet{seadata} package; for a curve defined
over a non-prime finite field,
giving the order is \emph{mandatory} since no function is available yet to
compute the cardinality or trace of Frobenius in that case.

The library syntax is \fun{GEN}{ellorder}{GEN E, GEN z, GEN o = NULL}.
The obsolete form \fun{GEN}{orderell}{GEN e, GEN z} should no longer be
used.

\subsecidx{ellordinate}$(E,x)$: \label{se:ellordinate}
gives a 0, 1 or 2-component vector containing
the $y$-coordinates of the points of the curve $E$ having $x$ as
$x$-coordinate.

The library syntax is \fun{GEN}{ellordinate}{GEN E, GEN x, long prec}.

\subsecidx{ellpointtoz}$(E,P)$: \label{se:ellpointtoz}
if $E$ is an elliptic curve with coefficients
in $\R$, this computes a complex number $t$ (modulo the lattice defining
$E$) corresponding to the point $z$, i.e.~such that, in the standard
Weierstrass model, $\wp(t)=z[1],\wp'(t)=z[2]$. In other words, this is the
inverse function of \kbd{ellztopoint}. More precisely, if $(w1,w2)$ are the
real and complex periods of $E$, $t$ is such that $0 \leq \Re(t) < w1$
and $0 \leq \Im(t) < \Im(w2)$.

If $E$ has coefficients in $\Q_p$, then either Tate's $u$ is in $\Q_p$, in
which case the output is a $p$-adic number $t$ corresponding to the point $z$
under the Tate parametrization, or only its square is, in which case the
output is $t+1/t$. $E$ must be an \var{ell} as output by \kbd{ellinit}.

The library syntax is \fun{GEN}{zell}{GEN E, GEN P, long prec}.

\subsecidx{ellpow}$(E,z,n)$: \label{se:ellpow}
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([0,0,0,1,0]); z = [0,0];
? ellpow(Ei, z, 10)
%2 = [0]     \\ unsurprising: z has order 2
? ellpow(Ei, z, I)
%3 = [0, 0]  \\ Ei has complex multiplication by Z[i]
? ellpow(Ei, z, quadgen(-4))
%4 = [0, 0]  \\ an alternative syntax for the same query
? Ej  = ellinit([0,0,0,0,1]); z = [-1,0];
? ellpow(Ej, z, I)
  ***   at top-level: ellpow(Ej,z,I)
  ***                 ^--------------
  *** ellpow: not a complex multiplication in powell.
? ellpow(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.

The library syntax is \fun{GEN}{powell}{GEN E, GEN z, GEN n}.

\subsecidx{ellrootno}$(E,\{p=1\})$: \label{se:ellrootno}
$E$ being a \var{smallell} as output by
\kbd{ellinit}, this computes the local (if $p\neq 1$) or global (if $p=1$)
root number of the L-series of the elliptic curve $E$. 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$ must
have coefficients in $\Q$ but need \emph{not} be minimal.

The library syntax is \fun{long}{ellrootno}{GEN E, GEN p = NULL}.

\subsecidx{ellsearch}$(N)$: \label{se:ellsearch}if $N$ is an integer, it is taken as a conductor else if $N$ is a
string, it can be a curve name ("11a1"), an isogeny class ("11a") or a
conductor "11". This function finds all curves in the \tet{elldata} database
with the given property.

If $N$ is a full curve name, 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} associated to the curve.

If $N$ is not a full-curve name, the output is a vector of all matching
curves in the above format.

The library syntax is \fun{GEN}{ellsearch}{GEN N}.
Also available is \fun{GEN}{ellsearchcurve}{GEN N} that only
accepts complete curve names.

\subsecidx{ellsigma}$(E,z,\{\fl=0\})$: \label{se:ellsigma}
$E$ being given by \kbd{ellinit},
returns the value at $z$ of the Weierstrass $\sigma$ function of the period
lattice $L$ of $E$:
$$ \sigma(z, L) = z \prod_{\omega\in L^*} \left(1 -
\dfrac{z}{\omega}\right)e^{\dfrac{z}{\omega} + \dfrac{z^2}{2\omega^2}}$$
Alternatively, one can input a lattice basis $[\omega_1,\omega_2]$ directly
instead of $E$.

If $\fl=1$, computes an (arbitrary) determination of $\log(\sigma(z))$.

If $\fl=2,3$, same using the product expansion instead of theta series.

The library syntax is \fun{GEN}{ellsigma}{GEN E, GEN z, long flag, long prec}.

\subsecidx{ellsub}$(E,\var{z1},\var{z2})$: \label{se:ellsub}
difference of the points $z1$ and $z2$ on the
elliptic curve corresponding to $E$.

The library syntax is \fun{GEN}{subell}{GEN E, GEN z1, GEN z2}.

\subsecidx{elltaniyama}$(E, \{d = \var{seriesprecision}\})$: \label{se:elltaniyama}
computes the modular parametrization of the
elliptic curve $E$, where $E$ is a \var{smallell} as output by \kbd{ellinit},
in the form of a two-component vector $[u,v]$ of power series, given to $d$
significant terms (\tet{seriesprecision} by default). This vector is
characterized by the
following two properties. First the point $(x,y)=(u,v)$ satisfies the
equation of the elliptic curve. Second, the differential $du/(2v+a_1u+a_3)$
is equal to $f(z)dz$, a differential form on $H/\Gamma_0(N)$ where $N$ is the
conductor of the curve. 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)$. It is
assumed that the curve is a \emph{strong} \idx{Weil curve}, and that the
Manin constant is equal to 1. The equation of the curve $E$ must be minimal
(use \kbd{ellminimalmodel} to get a minimal equation).

The library syntax is \fun{GEN}{elltaniyama}{GEN E, long precdl}.

\subsecidx{elltatepairing}$(E, P, Q, m)$: \label{se:elltatepairing}Computes the Tate pairing of the two points $P$ and $Q$ on the elliptic
curve $E$. The point $P$ must be of $m$-torsion.

The library syntax is \fun{GEN}{elltatepairing}{GEN E, GEN P, GEN Q, GEN m}.

\subsecidx{elltors}$(E,\{\fl=0\})$: \label{se:elltors}
if $E$ is an elliptic curve \emph{defined
over $\Q$}, 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 \var{ell} as output by \kbd{ellinit}.

\bprog
?  E = ellinit([0,0,0,-1,0]);
?  elltors(E)
%1 = [4, [2, 2], [[0, 0], [1, 0]]]
@eprog
Here, the torsion subgroup is isomorphic to $\Z/2\Z \times \Z/2\Z$, with
generators $[0,0]$ and $[1,0]$.

If $\fl = 0$, use Doud's algorithm: bound torsion by computing $\#E(\F_p)$
for small primes of good reduction, then look for torsion points using
Weierstrass parametrization (and Mazur's classification).

If $\fl = 1$, use Lutz-Nagell (\emph{much} slower), $E$ is allowed to be a
\var{smallell}.

The library syntax is \fun{GEN}{elltors0}{GEN E, long flag}.
Also available is \fun{GEN}{elltors}{GEN E} for \kbd{elltors(E, 0)}.

\subsecidx{ellweilpairing}$(E, P, Q, m)$: \label{se:ellweilpairing}Computes the Weil pairing of the two points of $m$-torsion $P$ and $Q$
on the elliptic curve $E$.

The library syntax is \fun{GEN}{ellweilpairing}{GEN E, GEN P, GEN Q, GEN m}.

\subsecidx{ellwp}$(E,\{z=x\},\{\fl=0\},\{d=\var{seriesprecision}\})$: \label{se:ellwp}Computes the value at $z$ of the Weierstrass $\wp$ function attached to
the elliptic curve $E$ as given by \kbd{ellinit} (alternatively, $E$ can be
given as a lattice $[\omega_1,\omega_2]$).

If $z$ is omitted or is a simple variable, computes the \emph{power series}
expansion in $z$ (starting $z^{-2}+O(z^2)$). The series is given to $d$
significant terms (\tet{seriesprecision} by default).

Optional \fl\ is (for now) only taken into account when $z$ is numeric, and
means 0: compute only $\wp(z)$, 1: compute $[\wp(z),\wp'(z)]$.

The library syntax is \fun{GEN}{ellwp0}{GEN E, GEN z = NULL, long flag, long precdl, long prec}.
Also available is \fun{GEN}{weipell}{GEN E, long precdl} for the power
series.

\subsecidx{ellzeta}$(E,z)$: \label{se:ellzeta}
$E$ being given by \kbd{ellinit}, returns the
value at $z$ of the Weierstrass $\zeta$ function of the period lattice $L$
of $E$:
$$ \zeta(z, L) = \dfrac{1}{z} + z^2\sum_{\omega\in L^*}
\dfrac{1}{\omega^2(z-\omega)}.$$
Alternatively, one can input a lattice basis $[\omega_1,\omega_2]$ directly
instead of $E$.
\bprog
? e = ellinit([0,0,0,1,0]);
? ellzeta(e, e.omega[1]/2)
%2 = 0.8472130847939790866064991234 + 4.417621070 E-29*I
? 2*ellzeta([1,I], 1/2)
%3 = 3.141592653589793238462643384 + 0.E-37*I
@eprog\noindent
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 directly as $\eta_i =
2\zeta(\omega_i/2)$ or using \tet{elleta}.

The library syntax is \fun{GEN}{ellzeta}{GEN E, GEN z, long prec}.

\subsecidx{ellztopoint}$(E,z)$: \label{se:ellztopoint}
$E$ being an \var{ell} as output by
\kbd{ellinit}, computes the coordinates $[x,y]$ on the curve $E$
corresponding to the complex number $z$. Hence this is the inverse function
of \kbd{ellpointtoz}. In other words, if the curve is put in Weierstrass
form, $[x,y]$ represents the \idx{Weierstrass $\wp$-function} and its
derivative. If $z$ is in the lattice defining $E$ over $\C$, the result is
the point at infinity $[0]$.

The library syntax is \fun{GEN}{pointell}{GEN E, GEN z, long prec}.
%SECTION: elliptic_curves

\section{Functions related to general number fields}

In this section can be found functions which are used almost exclusively for
working in general number fields. Other less specific functions can be found
in the next section on polynomials. Functions related to quadratic number
fields are found in section \secref{se:arithmetic} (Arithmetic functions).

\subsec{Number field structures}

Let $K = \Q[X] / (T)$ a number field, $\Z_K$ its ring of integers, $T\in\Z[X]$
is monic. Three basic number field structures can be associated to $K$ in
GP:

\item $\tev{nf}$ denotes a number field, i.e.~a data structure output by
\tet{nfinit}. This contains the basic arithmetic data associated to the
number field: signature, maximal order (given by a basis \kbd{nf.zk}),
discriminant, defining polynomial $T$, etc.

\item $\tev{bnf}$ denotes a ``Buchmann's number field'', i.e.~a
data structure output by \tet{bnfinit}. This contains
$\var{nf}$ and the deeper invariants of the field: units $U(K)$, class group
$\Cl(K)$, as well as technical data required to solve the two associated
discrete logarithm problems.

\item $\tev{bnr}$ denotes a ``ray number field'', i.e.~a data structure
output by \kbd{bnrinit}, corresponding to the ray class group structure of
the field, for some modulus $f$. It contains a \var{bnf}, the modulus
$f$, the ray class group $\Cl_f(K)$ and data associated to
the discrete logarithm problem therein.

\subsec{Algebraic numbers and ideals}

\noindent An \tev{algebraic number} belonging to $K = \Q[X]/(T)$ is given as

\item a \typ{INT}, \typ{FRAC} or \typ{POL} (implicitly modulo $T$), or

\item a \typ{POLMOD} (modulo $T$), or

\item a \typ{COL}~\kbd{v} of dimension $N = [K:\Q]$, representing
the element in terms of the computed integral basis, as
\kbd{sum(i = 1, N,~v[i] * nf.zk[i])}. Note that a \typ{VEC}
will not be recognized.
\medskip

\noindent An \tev{ideal} is given in any of the following ways:

\item an algebraic number in one of the above forms, defining a principal ideal.

\item a prime ideal, i.e.~a 5-component vector in the format output by
\kbd{idealprimedec} or \kbd{idealfactor}.

\item a \typ{MAT}, square and in Hermite Normal Form (or at least
upper triangular with non-negative coefficients), whose columns represent a
$\Z$-basis of the ideal.

One may use \kbd{idealhnf} to convert any ideal to the last (preferred) format.

\item an \emph{extended ideal} \sidx{ideal (extended)} is a 2-component
vector $[I, t]$, where $I$ is an ideal as above and $t$ is an algebraic
number, representing the ideal $(t)I$. This is useful whenever \tet{idealred}
is involved, implicitly working in the ideal class group, while keeping track
of principal ideals. Ideal operations suitably update the principal part
when it makes sense (in a multiplicative context), e.g.~using \kbd{idealmul}
on $[I,t]$, $[J,u]$, we obtain $[IJ, tu]$. When it does not make sense, the
extended part is silently discarded, e.g.~using \kbd{idealadd} with the above
input produces $I+J$.

The ``principal part'' $t$ in an extended ideal may be
represented in any of the above forms, and \emph{also} as a factorization
matrix (in terms of number field elements, not ideals!), possibly the empty
matrix \kbd{[;]} representing $1$. In the latter case, elements stay in
factored form, or \tev{famat} for \emph{fa}ctorization \emph{mat}rix, which
is a convenient way to avoid coefficient explosion. To recover the
conventional expanded form, try \tet{nffactorback}; but many functions
already accept \var{famat}s as input, for instance \tet{ideallog}, so
expanding huge elements should never be necessary.

\subsec{Finite abelian groups}

A finite abelian group $G$ in user-readable format is given by its Smith
Normal Form as a pair $[h,d]$ or triple $[h,d,g]$.
Here $h$ is the cardinality of $G$, $(d_i)$ is the vector of elementary
divisors, and $(g_i)$ is a vector of generators. In short,
$G = \oplus_{i\leq n} (\Z/d_i\Z) g_i$, with $d_n \mid \dots \mid d_2 \mid d_1$
and $\prod d_i = h$. This information can also be retrieved as
$G.\kbd{no}$, $G.\kbd{cyc}$ and $G.\kbd{gen}$.

\item a \tev{character} on the abelian group
$\oplus (\Z/d_i\Z) g_i$
is given by a row vector $\chi = [a_1,\ldots,a_n]$ such that
$\chi(\prod g_i^{n_i}) = \exp(2i\pi\sum a_i n_i / d_i)$.

\item given such a structure, a \tev{subgroup} $H$ is input as a square
matrix in HNF, whose columns express generators of $H$ on the given generators
$g_i$. Note that the determinant of that matrix is equal to the index $(G:H)$.

\subsec{Relative extensions}

We now have a look at data structures associated to relative extensions
of number fields $L/K$, and to projective $\Z_K$-modules. When defining a
relative extension $L/K$, the $\var{nf}$ associated to the base field $K$
must be defined by a variable having a lower priority (see
\secref{se:priority}) than the variable defining the extension. For example,
you may use the variable name $y$ to define the base field $K$, and $x$ to
define the relative extension $L/K$.

\subsubsec{Basic definitions}\label{se:ZKmodules}

\item $\tev{rnf}$ denotes a relative number field, i.e.~a data structure
output by \kbd{rnfinit}, associated to the extension $L/K$. The \var{nf}
associated to be base field $K$ is \kbd{rnf.nf}.

\item A \emph{relative matrix} is an $m\times n$ matrix whose entries are
elements of $K$, in any form. Its $m$ columns $A_j$ represent elements
in $K^n$.

\item An \tev{ideal list} is a row vector of fractional ideals of the number
field $\var{nf}$.

\item A \tev{pseudo-matrix} is a 2-component row vector $(A,I)$ where $A$
is a relative $m\times n$ matrix and $I$ an ideal list of length $n$. If $I =
\{{\Bbb a}_1,\dots, {\Bbb a}_n\}$ and the columns of $A$ are $(A_1,\dots,
A_n)$, this data defines the torsion-free (projective) $\Z_K$-module ${\Bbb
a}_1 A_1\oplus {\Bbb a}_n A_n$.

\item An \tev{integral pseudo-matrix} is a 3-component row vector w$(A,I,J)$
where $A = (a_{i,j})$ is an $m\times n$ relative matrix and $I = ({\Bbb
b}_1,\dots, {\Bbb b}_m)$, $J = ({\Bbb a}_1,\dots, {\Bbb a}_n)$ are ideal
lists, such that $a_{i,j} \in {\Bbb b}_i {\Bbb a}_j^{-1}$ for all $i,j$. This
data defines two abstract projective $\Z_K$-modules $N = {\Bbb
a_1}\omega_1\oplus \cdots\oplus {\Bbb a_n}\omega_n $ in $K^n$, $P = {\Bbb
b_1}\eta_1\oplus \cdots\oplus {\Bbb b_m}\eta_m$ in $K^m$, and a $\Z_K$-linear
map $f:N\to P$ given by
$$ f(\sum \alpha_j\omega_j) = \sum_i \Big(a_{i,j}\alpha_j\Big) \eta_i.$$
This data defines the $\Z_K$-module $M = P/f(N)$.

\item Any \emph{projective} $\Z_K$-module\varsidx{projective module} $M$
of finite type in $K^m$ can be given by a pseudo matrix $(A,I)$.

\item An arbitrary $\Z_K$ modules of finite type in $K^m$, with non-trivial
torsion, is given by an integral pseudo-matrix $(A,I,J)$

\subsubsec{Pseudo-bases, determinant}

\item The pair $(A,I)$ is a \tev{pseudo-basis} of the module it
generates if the ${\Bbb a_j}$ are non-zero, and the $A_j$ are $K$-linearly
independent. We call $n$ the \emph{size} of the pseudo-basis. If $A$ is a
relative matrix, the latter condition means it is square with non-zero
determinant; we say that it is in Hermite Normal Form\sidx{Hermite normal
form} (HNF) if it is upper triangular and all the elements of the diagonal
are equal to 1.

\item For instance, the relative integer basis \kbd{rnf.zk} is a pseudo-basis
$(A,I)$ of $\Z_L$, where $A = \kbd{rnf.zk[1]}$ is a vector of elements of $L$,
which are $K$-linearly independent. Most \var{rnf} routines return and handle
$\Z_K$-modules contained in $L$ (e.g.~$\Z_L$-ideals) via a pseudo-basis
$(A',I')$, where $A'$ is a relative matrix representing a vector of elements of
$L$ in terms of the fixed basis \kbd{rnf.zk[1]}

\item The \emph{determinant} of a pseudo-basis $(A,I)$ is the ideal
equal to the product of the determinant of $A$ by all the ideals of $I$. The
determinant of a pseudo-matrix is the determinant of any pseudo-basis of the
module it generates.

\subsec{Class field theory}\label{se:CFT}

A $\tev{modulus}$, in the sense of class field theory, is a divisor supported
on the non-complex places of $K$. In PARI terms, this means either an
ordinary ideal $I$ as above (no Archimedean component), or a pair $[I,a]$,
where $a$ is a vector with $r_1$ $\{0,1\}$-components, corresponding to the
infinite part of the divisor. More precisely, the $i$-th component of $a$
corresponds to the real embedding associated to the $i$-th real root of
\kbd{K.roots}. (That ordering is not canonical, but well defined once a
defining polynomial for $K$ is chosen.) For instance, \kbd{[1, [1,1]]} is a
modulus for a real quadratic field, allowing ramification at any of the two
places at infinity, and nowhere else.

A \tev{bid} or ``big ideal'' is a structure output by \kbd{idealstar}
needed to compute in $(\Z_K/I)^*$, where $I$ is a modulus in the above sense.
It is a finite abelian group as described above, supplemented by
technical data needed to solve discrete log problems.

Finally we explain how to input ray number fields (or \var{bnr}), using class
field theory. These are defined by a triple $A$, $B$, $C$, where the
defining set $[A,B,C]$ can have any of the following forms: $[\var{bnr}]$,
$[\var{bnr},\var{subgroup}]$, $[\var{bnf},\var{mod}]$,
$[\var{bnf},\var{mod},\var{subgroup}]$. The last two forms are kept for
backward compatibility, but no longer serve any real purpose (see example
below); no newly written function will accept them.

\item $\var{bnf}$ is as output by \kbd{bnfinit}, where units are mandatory
unless the modulus is trivial; \var{bnr} is as output by \kbd{bnrinit}. This
is the ground field $K$.

\item \emph{mod} is a modulus $\goth{f}$, as described above.

\item \emph{subgroup} a subgroup of the ray class group modulo $\goth{f}$ of
$K$. As described above, this is input as a square matrix expressing
generators of a subgroup of the ray class group \kbd{\var{bnr}.clgp} on the
given generators.

The corresponding \var{bnr} is the subfield of the ray class field of $K$
modulo $\goth{f}$, fixed by the given subgroup.

\bprog
  ? K = bnfinit(y^2+1);
  ? bnr = bnrinit(K, 13)
  ? %.clgp
  %3 = [36, [12, 3]]
  ? bnrdisc(bnr); \\ discriminant of the full ray class field
  ? bnrdisc(bnr, [3,1;0,1]); \\ discriminant of cyclic cubic extension of K
@eprog\noindent
We could have written directly
\bprog
  ? bnrdisc(K, 13);
  ? bnrdisc(K, 13, [3,1;0,1]);
@eprog\noindent
avoiding one \tet{bnrinit}, but this would actually be slower since the
\kbd{bnrinit} is called internally anyway. And now twice!

\subsec{General use}

All the functions which are specific to relative extensions, number fields,
Buchmann's number fields, Buchmann's number rays, share the prefix \kbd{rnf},
\kbd{nf}, \kbd{bnf}, \kbd{bnr} respectively. They take as first argument a
number field of that precise type, respectively output by \kbd{rnfinit},
\kbd{nfinit}, \kbd{bnfinit}, and \kbd{bnrinit}.

However, and even though it may not be specified in the descriptions of the
functions below, it is permissible, if the function expects a $\var{nf}$, to
use a $\var{bnf}$ instead, which contains much more information. On the other
hand, if the function requires a \kbd{bnf}, it will \emph{not} launch
\kbd{bnfinit} for you, which is a costly operation. Instead, it will give you
a specific error message. In short, the types
$$ \kbd{nf} \leq \kbd{bnf} \leq \kbd{bnr}$$
are ordered, each function requires a minimal type to work properly, but you
may always substitute a larger type.

The data types corresponding to the structures described above are rather
complicated. Thus, as we already have seen it with elliptic curves, GP
provides ``member functions'' to retrieve data from these structures (once
they have been initialized of course). The relevant types of number fields
are indicated between parentheses: \smallskip

\sidx{member functions}
\settabs\+xxxxxxx&(\var{bnr},x&\var{bnf},x&nf\hskip2pt&)x&: &\cr
\+\tet{bid}    &(\var{bnr}&&&)&: & bid ideal structure.\cr

\+\tet{bnf}    &(\var{bnr},& \var{bnf}&&)&: & Buchmann's number field.\cr

\+\tet{clgp}  &(\var{bnr},& \var{bnf}&&)&: & classgroup. This one admits the
following three subclasses:\cr

\+      \quad \tet{cyc} &&&&&: & \quad cyclic decomposition
 (SNF)\sidx{Smith normal form}.\cr

\+      \quad \kbd{gen}\sidx{gen (member function)} &&&&&: &
 \quad generators.\cr

\+      \quad \tet{no}  &&&&&: & \quad number of elements.\cr

\+\tet{diff}  &(\var{bnr},& \var{bnf},& \var{nf}&)&: & the different ideal.\cr

\+\tet{codiff}&(\var{bnr},& \var{bnf},& \var{nf}&)&: & the codifferent
(inverse of the different in the ideal group).\cr

\+\tet{disc} &(\var{bnr},& \var{bnf},& \var{nf}&)&: & discriminant.\cr

\+\tet{fu}   &(\var{bnr},& \var{bnf}&&)&: & \idx{fundamental units}.\cr

\+\tet{index}   &(\var{bnr},& \var{bnf},& \var{nf}&)&: &
 \idx{index} of the power order in the ring of integers.\cr

\+\tet{mod}   &(\var{bnr}&&&)&: & modulus.\cr

\+\tet{nf}   &(\var{bnr},& \var{bnf},& \var{nf}&)&: & number field.\cr

\+\tet{pol}   &(\var{bnr},& \var{bnf},& \var{nf}&)&: & defining polynomial.\cr

\+\tet{r1} &(\var{bnr},& \var{bnf},& \var{nf}&)&: & the number
of real embeddings.\cr

\+\tet{r2} &(\var{bnr},& \var{bnf},& \var{nf}&)&: & the number
of pairs of complex embeddings.\cr

\+\tet{reg}  &(\var{bnr},& \var{bnf}&&)&: & regulator.\cr

\+\tet{roots}&(\var{bnr},& \var{bnf},& \var{nf}&)&: & roots of the
polynomial generating the field.\cr

\+\tet{sign} &(\var{bnr},& \var{bnf},& \var{nf}&)&: & signature $[r1,r2]$.\cr

\+\tet{t2}   &(\var{bnr},& \var{bnf},& \var{nf}&)&: & the $T_2$ matrix (see
\kbd{nfinit}).\cr

\+\tet{tu}   &(\var{bnr},& \var{bnf}&&)&: & a generator for the torsion
units.\cr

\+\tet{zk}   &(\var{bnr},& \var{bnf},& \var{nf}&)&: & integral basis, i.e.~a
$\Z$-basis of the maximal order.\cr

\+\tet{zkst}   &(\var{bnr}&&&)&: & structure of $(\Z_K/m)^*$.\cr

\misctitle{Deprecated} The following member functions are still available, but deprecated and should not be used in new scripts :
\+\tet{futu} &(\var{bnr},& \var{bnf},&&)&: &
 $[u_1,...,u_r,w]$, $(u_i)$ is a vector of fundamental units,\cr
\+&&&&&& $w$ generates the torsion units.\cr

\+\tet{tufu} &(\var{bnr},& \var{bnf},&&)&: &
 $[w,u_1,...,u_r]$, $(u_i)$ is a vector of fundamental units,\cr
\+&&&&&& $w$ generates the torsion units.\cr


  For instance, assume that $\var{bnf} = \kbd{bnfinit}(\var{pol})$, for some
polynomial. Then \kbd{\var{bnf}.clgp} retrieves the class group, and
\kbd{\var{bnf}.clgp.no} the class number. If we had set $\var{bnf} =
\kbd{nfinit}(\var{pol})$, both would have output an error message. All these
functions are completely recursive, thus for instance
\kbd{\var{bnr}.bnf.nf.zk} will yield the maximal order of \var{bnr}, which
you could get directly with a simple \kbd{\var{bnr}.zk}.

\subsec{Class group, units, and the GRH}\label{se:GRHbnf}

Some of the functions starting with \kbd{bnf} are implementations of the
sub-exponential algorithms for finding class and unit groups under \idx{GRH},
due to Hafner-McCurley, \idx{Buchmann} and Cohen-Diaz-Olivier. The general
call to the functions concerning class groups of general number fields
(i.e.~excluding \kbd{quadclassunit}) involves a polynomial $P$ and a
technical vector
$$\var{tech} = [c_1, c_2, \var{nrpid} ],$$
where the parameters are to be understood as follows:

$P$ is the defining polynomial for the number field, which must be in
$\Z[X]$, irreducible and monic. In fact, if you supply a non-monic polynomial
at this point, \kbd{gp} issues a warning, then \emph{transforms your
polynomial} so that it becomes monic. The \kbd{nfinit} routine
will return a different result in this case: instead of \kbd{res}, you get a
vector \kbd{[res,Mod(a,Q)]}, where \kbd{Mod(a,Q) = Mod(X,P)} gives the change
of variables. In all other routines, the variable change is simply lost.

The \var{tech} interface is obsolete and you should not tamper with
these parameters. Indeed, from version 2.4.0 on,

\item the results are always rigorous under \idx{GRH} (before that version,
they relied on a heuristic strengthening, hence the need for overrides).

\item the influence of these parameters on execution time and stack size is
marginal. They \emph{can} be useful to fine-tune and experiment with the
\kbd{bnfinit} code, but you will be better off modifying all tuning
parameters in the C code (there are many more than just those three).
We nevertheless describe it for completeness.

The numbers $c_1 \leq c_2$ are positive real numbers. For $i = 1,2$, let $B_i
= c_i(\log |d_K|)^2$, and denote by $S(B)$ the set of maximal ideals of $K$
whose norm is less than $B$. We want $S(B_1)$ to generate $\Cl(K)$ and hope
that $S(B_2)$ can be \emph{proven} to generate $\Cl(K)$.

More precisely, $S(B_1)$ is a factorbase used to compute a tentative
$\Cl(K)$ by generators and relations. We then check explicitly, using
essentially \kbd{bnfisprincipal}, that the elements of $S(B_2)$ belong to the
span of $S(B_1)$. Under the assumption that $S(B_2)$ generates $\Cl(K)$, we
are done. User-supplied $c_i$ are only used to compute initial guesses for
the bounds $B_i$, and the algorithm increases them until one can \emph{prove}
under GRH that $S(B_2)$ generates $\Cl(K)$. A uniform result of Bach says
that $c_2 = 12$ is always suitable, but this bound is very pessimistic and a
direct algorithm due to Belabas-Diaz-Friedman is used to check the condition,
assuming GRH. The default values are $c_1 = c_2 = 0.3$.

$\var{nrpid}$ is the maximal number of small norm relations associated to each
ideal in the factor base. Set it to $0$ to disable the search for small norm
relations. Otherwise, reasonable values are between 4 and 20. The default is
4.

\misctitle{Warning} Make sure you understand the above! By default, most of
the \kbd{bnf} routines depend on the correctness of the GRH. In particular,
any of the class number, class group structure, class group generators,
regulator and fundamental units may be wrong, independently of each other.
Any result computed from such a \kbd{bnf} may be wrong. The only guarantee is
that the units given generate a subgroup of finite index in the full unit
group. You must use \kbd{bnfcertify} to certify the computations
unconditionally.

\misctitle{Remarks}

You do not need to supply the technical parameters (under the library you
still need to send at least an empty vector, coded as \kbd{NULL}). However,
should you choose to set some of them, they \emph{must} be given in the
requested order. For example, if you want to specify a given value of
\var{nrpid}, you must give some values as well for $c_1$ and $c_2$, and provide
a vector $[c_1,c_2,\var{nrpid}]$.

Note also that you can use an $\var{nf}$ instead of $P$, which avoids
recomputing the integral basis and analogous quantities.

\smallskip


\subsecidx{bnfcertify}$(\var{bnf},\{\fl = 0\})$: \label{se:bnfcertify}$\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.

If flag is present, only certify that the class group is a quotient of the
one computed in bnf (much simpler in general).

The library syntax is \fun{long}{bnfcertify0}{GEN bnf, long flag }.
Also available is  \fun{GEN}{bnfcertify}{GEN bnf} ($\fl=0$).

\subsecidx{bnfcompress}$(\var{bnf})$: \label{se:bnfcompress}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]$.

The library syntax is \fun{GEN}{bnfcompress}{GEN bnf}.

\subsecidx{bnfdecodemodule}$(\var{nf},m)$: \label{se:bnfdecodemodule}if $m$ is a module as output in the
first component of an extension given by \kbd{bnrdisclist}, outputs the
true module.

The library syntax is \fun{GEN}{decodemodule}{GEN nf, GEN m}.

\subsecidx{bnfinit}$(P,\{\fl=0\},\{\var{tech}=[\,]\})$: \label{se:bnfinit}initializes a
\var{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).

The library syntax is \fun{GEN}{bnfinit0}{GEN P, long flag, GEN tech = NULL, long prec}.

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.

\subsecidx{bnfisintnorm}$(\var{bnf},x)$: \label{se:bnfisintnorm}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}.

The library syntax is \fun{GEN}{bnfisintnorm}{GEN bnf, GEN x}.

\subsecidx{bnfisnorm}$(\var{bnf},x,\{\fl=1\})$: \label{se:bnfisnorm}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}.

The library syntax is \fun{GEN}{bnfisnorm}{GEN bnf, GEN x, long flag}.

\subsecidx{bnfisprincipal}$(\var{bnf},x,\{\fl=1\})$: \label{se:bnfisprincipal}$\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 \kbd{bnf} 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{very} lengthy computations.

The library syntax is \fun{GEN}{bnfisprincipal0}{GEN bnf, GEN x, long flag}.
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).

\subsecidx{bnfissunit}$(\var{bnf},\var{sfu},x)$: \label{se:bnfissunit}$\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.

The library syntax is \fun{GEN}{bnfissunit}{GEN bnf, GEN sfu, GEN x}.

\subsecidx{bnfisunit}$(\var{bnf},x)$: \label{se:bnfisunit}\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.)

The library syntax is \fun{GEN}{bnfisunit}{GEN bnf, GEN x}.

\subsecidx{bnfnarrow}$(\var{bnf})$: \label{se:bnfnarrow}$\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} (\kbd{\var{bnf}[8][1]}): 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 library syntax is \fun{GEN}{buchnarrow}{GEN bnf}.

\subsecidx{bnfsignunit}$(\var{bnf})$: \label{se:bnfsignunit}$\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(S,d,K);

  S = bnfsignunit(bnf); d = matsize(S);
  S = matrix(d[1],d[2], i,j, if (S[i,j] < 0, 1,0));
  S = concat(vectorv(d[1],i,1), S);   \\ add sign(-1)
  K = lift(matker(S * Mod(1,2)));
  if (K, mathnfmodid(K, 2), 2*matid(d[1]))
}

/* totally positive units */
tpu(bnf)=
{ my(vu = bnf.tufu, ex = tpuexpo(bnf));

  vector(#ex-1, i, factorback(vu, ex[,i+1]))  \\ ex[,1] is 1
}
@eprog

The library syntax is \fun{GEN}{signunits}{GEN bnf}.

\subsecidx{bnfsunit}$(\var{bnf},S)$: \label{se:bnfsunit}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$.

The library syntax is \fun{GEN}{bnfsunit}{GEN bnf, GEN S, long prec}.

\subsecidx{bnrL1}$(\var{bnr}, \{\var{subgrp}\}, \{\fl=0\})$: \label{se:bnrL1}\var{bnr} being
the number field data which is output by \kbd{bnrinit(,,1)} and
\var{subgrp} being a square matrix defining a congruence subgroup of the
ray class group corresponding to \var{bnr} (the trivial congruence subgroup
if omitted), returns for each \idx{character} $\chi$ of the ray class group
which is trivial on this subgroup, the value at $s = 1$ (or $s = 0$) of the
abelian $L$-function associated to $\chi$. For the value at $s = 0$, the
function returns in fact for each character $\chi$ a vector $[r_\chi ,
c_\chi]$ where $r_\chi$ is the order of $L(s, \chi)$ at $s = 0$ and $c_\chi$
the first non-zero term in the expansion of $L(s, \chi)$ at $s = 0$; in other
words
%
$$L(s, \chi) = c_\chi \cdot s^{r_\chi} + O(s^{r_\chi + 1})$$
%
\noindent near $0$. \fl\ is optional, default value is 0; its binary digits
mean 1: compute at $s = 1$ if set to 1 or $s = 0$ if set to 0, 2: compute the
primitive $L$-functions associated to $\chi$ if set to 0 or the $L$-function
with Euler factors at prime ideals dividing the modulus of \var{bnr} removed
if set to 1 (this is the so-called $L_S(s, \chi)$ function where $S$ is the
set of infinite places of the number field together with the finite prime
ideals dividing the modulus of \var{bnr}, see the example below), 3: returns
also the character. Example:
\bprog
bnf = bnfinit(x^2 - 229);
bnr = bnrinit(bnf,1,1);
bnrL1(bnr)
@eprog\noindent
returns the order and the first non-zero term of the abelian
$L$-functions $L(s, \chi)$ at $s = 0$ where $\chi$ runs through the
characters of the class group of $\Q(\sqrt{229})$. Then
\bprog
bnr2 = bnrinit(bnf,2,1);
bnrL1(bnr2,,2)
@eprog\noindent
returns the order and the first non-zero terms of the abelian
$L$-functions $L_S(s, \chi)$ at $s = 0$ where $\chi$ runs through the
characters of the class group of $\Q(\sqrt{229})$ and $S$ is the set
of infinite places of $\Q(\sqrt{229})$ 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 exactly the same answer as
\kbd{bnrL1(bnr,0)}.

The library syntax is \fun{GEN}{bnrL1}{GEN bnr, GEN subgrp = NULL, long flag, long prec}.

\subsecidx{bnrclassno}$(\var{bnf},I)$: \label{se:bnrclassno}$\var{bnf}$ being as output by
\kbd{bnfinit} (units are mandatory unless the ideal is trivial), and $I$
being a modulus, computes the ray class number of the number field for the
modulus $I$. One can input the associated \var{bid} for $I$ 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.

The library syntax is \fun{GEN}{bnrclassno}{GEN bnf, GEN I}.

\subsecidx{bnrclassnolist}$(\var{bnf},\var{list})$: \label{se:bnrclassnolist}$\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

The library syntax is \fun{GEN}{bnrclassnolist}{GEN bnf, GEN list}.

\subsecidx{bnrconductor}$(A,\{B\},\{C\},\{\fl=0\})$: \label{se:bnrconductor}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)$.

The library syntax is \fun{GEN}{bnrconductor0}{GEN A, GEN B = NULL, GEN C = NULL, long flag}.

Also available is \fun{GEN}{bnrconductor}{GEN bnr, GEN H, long flag}

\subsecidx{bnrconductorofchar}$(\var{bnr},\var{chi})$: \label{se:bnrconductorofchar}\var{bnr} being a big
ray number field as output by \kbd{bnrinit}, and \var{chi} being a row vector
representing a \idx{character} as expressed on the generators of the ray
class group, gives the conductor of this character as a modulus.

The library syntax is \fun{GEN}{bnrconductorofchar}{GEN bnr, GEN chi}.

\subsecidx{bnrdisc}$(A,\{B\},\{C\},\{\fl=0\})$: \label{se:bnrdisc}$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{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.

The library syntax is \fun{GEN}{bnrdisc0}{GEN A, GEN B = NULL, GEN C = NULL, long flag}.

\subsecidx{bnrdisclist}$(\var{bnf},\var{bound},\{\var{arch}\})$: \label{se:bnrdisclist}$\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 associated 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.

The library syntax is \fun{GEN}{bnrdisclist0}{GEN bnf, GEN bound, GEN arch = NULL}.

\subsecidx{bnrinit}$(\var{bnf},f,\{\fl=0\})$: \label{se:bnrinit}$\var{bnf}$ is as
output by \kbd{bnfinit}, $f$ is a modulus, initializes data linked to
the ray class group structure corresponding to this module, a so-called
\var{bnr} structure. The following member functions are available
on the result: \kbd{.bnf} is the underlying \var{bnf},
\kbd{.mod} the modulus, \kbd{.bid} the \var{bid} structure associated 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.

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.

The library syntax is \fun{GEN}{bnrinit0}{GEN bnf, GEN f, long flag}.
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 cardinal of the ray class group
and its structure), possibly 0.

\subsecidx{bnrisconductor}$(A,\{B\},\{C\})$: \label{se:bnrisconductor}$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}.

The library syntax is \fun{long}{bnrisconductor0}{GEN A, GEN B = NULL, GEN C = NULL}.

\subsecidx{bnrisprincipal}$(\var{bnr},x,\{\fl=1\})$: \label{se:bnrisprincipal}\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.

The library syntax is \fun{GEN}{bnrisprincipal}{GEN bnr, GEN x, long flag}.
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

\subsecidx{bnrrootnumber}$(\var{bnr},\var{chi},\{\fl=0\})$: \label{se:bnrrootnumber}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 associated
\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 associated 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).

The library syntax is \fun{GEN}{bnrrootnumber}{GEN bnr, GEN chi, long flag, long prec}.

\subsecidx{bnrstark}$(\var{bnr},\{\var{subgroup}\})$: \label{se:bnrstark}\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

The library syntax is \fun{GEN}{bnrstark}{GEN bnr, GEN subgroup = NULL, long prec}.

\subsecidx{dirzetak}$(\var{nf},b)$: \label{se:dirzetak}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}.

The library syntax is \fun{GEN}{dirzetak}{GEN nf, GEN b}.

\subsecidx{factornf}$(x,t)$: \label{se:factornf}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

The library syntax is \fun{GEN}{polfnf}{GEN x, GEN t}.

\subsecidx{galoisexport}$(\var{gal},\{\fl\})$: \label{se:galoisexport}\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

The library syntax is \fun{GEN}{galoisexport}{GEN gal, long flag}.

\subsecidx{galoisfixedfield}$(\var{gal},\var{perm},\{\fl\},\{v=y\})$: \label{se:galoisfixedfield}\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)$

The library syntax is \fun{GEN}{galoisfixedfield}{GEN gal, GEN perm, long flag, long v = -1}, where \kbd{v} is a variable number.

\subsecidx{galoisgetpol}$(a,\{b\},\{s\})$: \label{se:galoisgetpol}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 \kbd{pol} is the polynomial and
\kbd{den} is the common denominator of the conjugates expressed as a
polynomial in a root of \kbd{pol}, which can be passed as an optional argument
to \tet{galoisinit} and \tet{nfgaloisconj} as follows:
\bprog
V=galoisgetpol(8,4,1);
G=galoisinit(V[1], V[2])  \\ passing V[2] speeds up the computation
@eprog

If $b$ and $s$ are omitted, return the number of isomorphic class of groups
of order $a$.

The library syntax is \fun{GEN}{galoisgetpol}{long a, long b, long s}.
Also available is \fun{GEN}{galoisnbpol}{long a} when $b$ and $s$
are omitted.

\subsecidx{galoisidentify}$(\var{gal})$: \label{se:galoisidentify}\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.

The library syntax is \fun{GEN}{galoisidentify}{GEN gal}.

\subsecidx{galoisinit}$(\var{pol},\{\var{den}\})$: \label{se:galoisinit}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]$.

The library syntax is \fun{GEN}{galoisinit}{GEN pol, GEN den = NULL}.

\subsecidx{galoisisabelian}$(\var{gal},\{\fl=0\})$: \label{se:galoisisabelian}\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}.

The library syntax is \fun{GEN}{galoisisabelian}{GEN gal, long flag}.

\subsecidx{galoisisnormal}$(\var{gal},\var{subgrp})$: \label{se:galoisisnormal}\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}.

The library syntax is \fun{long}{galoisisnormal}{GEN gal, GEN subgrp}.

\subsecidx{galoispermtopol}$(\var{gal},\var{perm})$: \label{se:galoispermtopol}\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}, associated with 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$.

The library syntax is \fun{GEN}{galoispermtopol}{GEN gal, GEN perm}.

\subsecidx{galoissubcyclo}$(N,H,\{\var{fl}=0\},\{v\})$: \label{se:galoissubcyclo}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
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$.

The library syntax is \fun{GEN}{galoissubcyclo}{GEN N, GEN H = NULL, long fl, long v = -1}, where \kbd{v} is a variable number.

\subsecidx{galoissubfields}$(G,\{\var{flags}=0\},\{v\})$: \label{se:galoissubfields}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
the flag \var{fl} is the same as for \kbd{galoisfixedfield}.

The library syntax is \fun{GEN}{galoissubfields}{GEN G, long flags, long v = -1}, where \kbd{v} is a variable number.

\subsecidx{galoissubgroups}$(G)$: \label{se:galoissubgroups}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 cardinal 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

The library syntax is \fun{GEN}{galoissubgroups}{GEN G}.

\subsecidx{idealadd}$(\var{nf},x,y)$: \label{se:idealadd}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))}.

The library syntax is \fun{GEN}{idealadd}{GEN nf, GEN x, GEN y}.

\subsecidx{idealaddtoone}$(\var{nf},x,\{y\})$: \label{se:idealaddtoone}$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$.

The library syntax is \fun{GEN}{idealaddtoone0}{GEN nf, GEN x, GEN y = NULL}.

\subsecidx{idealappr}$(\var{nf},x,\{\fl=0\})$: \label{se:idealappr}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}$.

If $\fl$ is non-zero, $x$ must be given as a prime ideal factorization, as
output by \kbd{idealfactor}, but possibly with zero or negative exponents.
This yields an element $\alpha$ such that for all prime ideals $\goth{p}$
occurring in $x$, $v_{\goth{p}}(\alpha)$ is equal to the exponent of
$\goth{p}$ in $x$, and for all other prime ideals,
$v_{\goth{p}}(\alpha)\ge0$. This generalizes $\kbd{idealappr}(\var{nf},x,0)$
since zero exponents are allowed. Note that the algorithm used is slightly
different, so that
\bprog
  idealappr(nf, idealfactor(nf,x))
@eprog\noindent
may not be the same as \kbd{idealappr(nf,x,1)}.

The library syntax is \fun{GEN}{idealappr0}{GEN nf, GEN x, long flag}.

\subsecidx{idealchinese}$(\var{nf},x,y)$: \label{se:idealchinese}$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}$.

The library syntax is \fun{GEN}{idealchinese}{GEN nf, GEN x, GEN y}.

\subsecidx{idealcoprime}$(\var{nf},x,y)$: \label{se:idealcoprime}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$.

The library syntax is \fun{GEN}{idealcoprime}{GEN nf, GEN x, GEN y}.

\subsecidx{idealdiv}$(\var{nf},x,y,\{\fl=0\})$: \label{se:idealdiv}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.

The library syntax is \fun{GEN}{idealdiv0}{GEN nf, GEN x, GEN y, long flag}.
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$).

\subsecidx{idealfactor}$(\var{nf},x)$: \label{se:idealfactor}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, i.e.~as 5-element vectors.

The library syntax is \fun{GEN}{idealfactor}{GEN nf, GEN x}.

\subsecidx{idealfactorback}$(\var{nf},f,\{e\},\{\fl = 0\})$: \label{se:idealfactorback}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.

The library syntax is \fun{GEN}{idealfactorback}{GEN nf, GEN f, GEN e = NULL, long flag }.

\subsecidx{idealfrobenius}$(\var{nf},\var{gal},\var{pr})$: \label{se:idealfrobenius}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 $pr$ is the prime ideal $\goth{P}$ in prid format, and that
$\goth{P}$ is unramified.
This function returns a permutation of \kbd{gal.group} which defines the
automorphism $\sigma=\left(\goth{P}\over K/\Q \right)$, i.e the Frobenius
element associated to $\goth{P}$. If $p$ is the unique prime number
in $\goth{P}$, then $\sigma(x)\equiv x^p\mod\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}$.

The library syntax is \fun{GEN}{idealfrobenius}{GEN nf, GEN gal, GEN pr}.

\subsecidx{idealhnf}$(\var{nf},a,\{b\})$: \label{se:idealhnf}gives the \idx{Hermite normal form} of the ideal $a\Z_K+b\Z_K$, where $a$
and $b$ are elements of the number field $K$ defined by \kbd{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 $a$: $a$ 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, $a$
is the $\Z_K$-module they generate,

\item if $N$ or more are given, it is \emph{assumed} that they form a
$\Z$-basis (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

The library syntax is \fun{GEN}{idealhnf0}{GEN nf, GEN a, GEN b = NULL}.
Also available is \fun{GEN}{idealhnf}{GEN nf, GEN a}.

\subsecidx{idealintersect}$(\var{nf},A,B)$: \label{se:idealintersect}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 * vecextract(Ker, Str("..", #A), "..") )
}
@eprog

The library syntax is \fun{GEN}{idealintersect}{GEN nf, GEN A, GEN B}.

\subsecidx{idealinv}$(\var{nf},x)$: \label{se:idealinv}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]$.

The library syntax is \fun{GEN}{idealinv}{GEN nf, GEN x}.

\subsecidx{ideallist}$(\var{nf},\var{bound},\{\fl=4\})$: \label{se:ideallist}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} associated 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.

The library syntax is \fun{GEN}{ideallist0}{GEN nf, long bound, long flag}.

\subsecidx{ideallistarch}$(\var{nf},\var{list},\var{arch})$: \label{se:ideallistarch}
\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 the ray class group. 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];
%6 = [2, 12, 2]
@eprog

The library syntax is \fun{GEN}{ideallistarch}{GEN nf, GEN list, GEN arch}.

\subsecidx{ideallog}$(\var{nf},x,\var{bid})$: \label{se:ideallog}$\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 associated real embeddings.
See \tet{znlog} for the limitations of the underlying discrete log algorithms.

The library syntax is \fun{GEN}{ideallog}{GEN nf, GEN x, GEN bid}.

\subsecidx{idealmin}$(\var{nf},\var{ix},\{\var{vdir}\})$: \label{se:idealmin}\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}.

The library syntax is \fun{GEN}{idealmin}{GEN nf, GEN ix, GEN vdir = NULL}.

\subsecidx{idealmul}$(\var{nf},x,y,\{\fl=0\})$: \label{se:idealmul}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
%4 = [[4, 2; 0, 2], x]
? idealmul(nf, [2, x], [x+1, x])   \\ two extended ideals
%5 = [[4, 2; 0, 2], [-1, 0]~]
@eprog\noindent
If $\fl$ is non-zero, reduce the result using \kbd{idealred}.

The library syntax is \fun{GEN}{idealmul0}{GEN nf, GEN x, GEN y, long flag}.

\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$).

\subsecidx{idealnorm}$(\var{nf},x)$: \label{se:idealnorm}computes the norm of the ideal~$x$ in the number field~$\var{nf}$.

The library syntax is \fun{GEN}{idealnorm}{GEN nf, GEN x}.

\subsecidx{idealpow}$(\var{nf},x,k,\{\fl=0\})$: \label{se:idealpow}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
as $\kbd{idealpow}(\var{nf},x,k)$ followed by reduction.

The library syntax is \fun{GEN}{idealpow0}{GEN nf, GEN x, GEN k, long flag}.

\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}.

\subsecidx{idealprimedec}$(\var{nf},p)$: \label{se:idealprimedec}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.

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,b]$ of a prime ideal means the following: $a$ and $b$ are
algebraic integers in the maximal order $\Z_K$; the prime ideal is
equal to $\goth{p} = p\Z_K + a\Z_K$;
$e$ is the ramification index; $f$ is the residual index;
and $b$ is such that $\goth{p}^{-1}=\Z_K+ b/ p\Z_K$, which is used internally
to compute valuations. 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);
? L = idealprimedec(K, 5);
? #L       \\ 2 primes above 5 in Q(2^(1/3))
%3 = 2
? p1 = L[1]; p2 = L[2];
? [p1.e, p1.f]    \\ the first is unramified of degree 1
%4 = [1, 1]
? [p2.e, p2.f]    \\ the second is unramified of degree 2
%5 = [1, 2]
? p1.gen
%6 = [5, [2, 1, 0]~]
? nfbasistoalg(K, %[2])  \\ a uniformizer for p1
%7 = Mod(x + 2, x^3 - 2)
@eprog

The library syntax is \fun{GEN}{idealprimedec}{GEN nf, GEN p}.

\subsecidx{idealramgroups}$(\var{nf},\var{gal},\var{pr})$: \label{se:idealramgroups}Let $K$ be the number field defined by $nf$ and assume $K/\Q$ be a
Galois extension with Galois group $G$ given \kbd{gal=galoisinit(nf)},
and that $pr$ is 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 ramification group of
$\goth{P}$.

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$.

\bprog
? nf=nfinit(x^6+108);
? gal=galoisinit(nf);
? pr=idealprimedec(nf,2)[1];
? iso=idealramgroups(nf,gal,pr)[2]
%4 = [[Vecsmall([2, 3, 1, 5, 6, 4])], Vecsmall([3])]
? nfdisc(galoisfixedfield(gal,iso,1))
%5 = -3
@eprog\noindent The field fixed by the inertia group of $2$ is not ramified at
$2$.

The library syntax is \fun{GEN}{idealramgroups}{GEN nf, GEN gal, GEN pr}.

\subsecidx{idealred}$(\var{nf},I,\{v=0\})$: \label{se:idealred}\idx{LLL} reduction of
the ideal $I$ in the number field \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 a ``small'' $a$ in $I$ (see the end for technical details).
The result is the Hermite normal form of
the ``reduced'' ideal $J = r I/a$, where $r$ is the unique rational number such
that $J$ is integral and primitive. (This is usually not a reduced ideal in
the sense of \idx{Buchmann}.)
\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/r]$; this way,
one can keep 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$ 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$ and is
``expected to be small''.

The library syntax is \fun{GEN}{idealred0}{GEN nf, GEN I, GEN v = NULL}.

\subsecidx{idealstar}$(\var{nf},I,\{\fl=1\})$: \label{se:idealstar}outputs a \var{bid} structure,
necessary for computing in the finite abelian group $G = (\Z_K/I)^*$. Here,
\var{nf} is a number field and $I$ 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.

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 \var{bid} structure without
generators.

If $\fl=2$, as $\fl=1$, but including generators, which wastes some time.

If $\fl=0$, only outputs $(\Z_K/I)^*$ 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.

The library syntax is \fun{GEN}{idealstar0}{GEN nf, GEN I, long flag}.
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.

\subsecidx{idealtwoelt}$(\var{nf},x,\{a\})$: \label{se:idealtwoelt}computes a two-element
representation of the ideal $x$ in the number field $\var{nf}$, combining a
random search and an explicit approximation theorem. $x$ is an ideal
in any form (possibly an extended ideal, whose principal part is ignored)
and the
result is a row vector $[a,\alpha]$ with two components such that
$x=a\Z_K+\alpha\Z_K$ and $a\in\Z$, where $a$ is the one passed as argument if
any. Unless $x$ was given as a principal ideal, $a$ is chosen to be the
positive generator of $x\cap\Z$.

Note that when an explicit $a$ is given, we must factor it and this may
be costly. When $a$ is omitted, we use a fast lazy factorization of $x\cap
\Z$, yielding an algorithm in randomized polynomial time (and generally
much faster in practice).

The library syntax is \fun{GEN}{idealtwoelt0}{GEN nf, GEN x, GEN a = NULL}.
Also available are
\fun{GEN}{idealtwoelt}{GEN nf, GEN x} and
\fun{GEN}{idealtwoelt2}{GEN nf, GEN x, GEN a}.

\subsecidx{idealval}$(\var{nf},x,\var{pr})$: \label{se:idealval}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 library syntax is \fun{long}{idealval}{GEN nf, GEN x, GEN pr}.

\subsecidx{matalgtobasis}$(\var{nf},x)$: \label{se:matalgtobasis}$\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$.

The library syntax is \fun{GEN}{matalgtobasis}{GEN nf, GEN x}.

\subsecidx{matbasistoalg}$(\var{nf},x)$: \label{se:matbasistoalg}$\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$.

The library syntax is \fun{GEN}{matbasistoalg}{GEN nf, GEN x}.

\subsecidx{modreverse}$(z)$: \label{se:modreverse}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)
  ***   at top-level: modreverse(u)
  ***                 ^-------------
  *** modreverse: reverse polmod does not exist: Mod(-x^3+9*x, x^4-10*x^2+1).
? minpoly(u)
%6 = x^2 - 8
@eprog

The library syntax is \fun{GEN}{modreverse}{GEN z}.

\subsecidx{newtonpoly}$(x,p)$: \label{se:newtonpoly}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 \tet{LONG_MAX}, the biggest single precision
integer representable on the machine ($2^{31}-1$ (resp.~$2^{63}-1$) on 32-bit
(resp.~64-bit) machines), see \secref{se:valuation}.

The library syntax is \fun{GEN}{newtonpoly}{GEN x, GEN p}.

\subsecidx{nfalgtobasis}$(\var{nf},x)$: \label{se:nfalgtobasis}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))
%4 = [0, 2]~
@eprog
This is the inverse function of \kbd{nfbasistoalg}.

The library syntax is \fun{GEN}{algtobasis}{GEN nf, GEN x}.

\subsecidx{nfbasis}$(x,\{\fl=0\},\{\var{fa}\})$: \label{se:nfbasis}\idx{integral basis} of the number
field defined by the irreducible, preferably monic, polynomial $x$, using a
modified version of the \idx{round 4} algorithm by default, due to David
\idx{Ford}, Sebastian \idx{Pauli} and Xavier \idx{Roblot}. The binary digits
of $\fl$ have the following meaning:

1: assume that no square of a prime greater than the default \kbd{primelimit}
divides the discriminant of $x$, i.e.~that the index of $x$ has only small
prime divisors.

2: use \idx{round 2} algorithm. For small degrees and coefficient size, this
is sometimes a little faster. (This program is the translation into C of a
program written by David \idx{Ford} in Algeb.)

Thus for instance, if $\fl=3$, this uses the round 2 algorithm and outputs
an order which will be maximal at all the small primes.

If \var{fa} is present, we assume (without checking!) that it is the two-column
matrix of the factorization of the discriminant of the polynomial $x$. Note
that it does \emph{not} have to be a complete factorization. This is
especially useful if only a local integral basis for some small set of places
is desired: only factors with exponents greater or equal to 2 will be
considered.

The library syntax is \fun{GEN}{nfbasis0}{GEN x, long flag, GEN fa = NULL}.
An extended version is
\fun{GEN}{nfbasis}{GEN x, GEN *d, long flag, GEN fa = NULL}, where \kbd{*d}
receives the discriminant of the number field
(\emph{not} of the polynomial $x$).

\subsecidx{nfbasistoalg}$(\var{nf},x)$: \label{se:nfbasistoalg}Given an algebraic number $x$ in the number field \kbd{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))
%4 = Mod(y, y^2 + 4)
@eprog
This is the inverse function of \kbd{nfalgtobasis}.

The library syntax is \fun{GEN}{basistoalg}{GEN nf, GEN x}.

\subsecidx{nfdetint}$(\var{nf},x)$: \label{se:nfdetint}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}.

The library syntax is \fun{GEN}{nfdetint}{GEN nf, GEN x}.

\subsecidx{nfdisc}$(x,\{\fl=0\},\{\var{fa}\})$: \label{se:nfdisc}\idx{field discriminant} of the number field defined by the integral,
preferably monic, irreducible polynomial $x$. $\fl$ and $fa$ are exactly as
in \kbd{nfbasis}. That is, $fa$ provides the matrix of a partial
factorization of the discriminant of $x$, and binary digits of $\fl$ are as
follows:

1: assume that no square of a prime greater than \kbd{primelimit}
divides the discriminant.

2: use the round 2 algorithm, instead of the default \idx{round 4}. This
should be slower except maybe for polynomials of small degree and
coefficients.

The library syntax is \fun{GEN}{nfdisc0}{GEN x, long flag, GEN fa = NULL}.
Also available is \fun{GEN}{nfdisc}{GEN x} ($\fl=0$).

\subsecidx{nfeltadd}$(\var{nf},x,y)$: \label{se:nfeltadd}
given two elements $x$ and $y$ in
\var{nf}, computes their sum $x+y$ in the number field $\var{nf}$.

The library syntax is \fun{GEN}{nfadd}{GEN nf, GEN x, GEN y}.

\subsecidx{nfeltdiv}$(\var{nf},x,y)$: \label{se:nfeltdiv}given two elements $x$ and $y$ in
\var{nf}, computes their quotient $x/y$ in the number field $\var{nf}$.

The library syntax is \fun{GEN}{nfdiv}{GEN nf, GEN x, GEN y}.

\subsecidx{nfeltdiveuc}$(\var{nf},x,y)$: \label{se:nfeltdiveuc}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))}.

The library syntax is \fun{GEN}{nfdiveuc}{GEN nf, GEN x, GEN y}.

\subsecidx{nfeltdivmodpr}$(\var{nf},x,y,\var{pr})$: \label{se:nfeltdivmodpr}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}.

The library syntax is \fun{GEN}{nfdivmodpr}{GEN nf, GEN x, GEN y, GEN pr}.
This function is normally useless in library mode. Project your
inputs to the residue field using \kbd{nf\_to\_Fq}, then work there.

\subsecidx{nfeltdivrem}$(\var{nf},x,y)$: \label{se:nfeltdivrem}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.

The library syntax is \fun{GEN}{nfdivrem}{GEN nf, GEN x, GEN y}.

\subsecidx{nfeltmod}$(\var{nf},x,y)$: \label{se:nfeltmod}
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)}.$$

The library syntax is \fun{GEN}{nfmod}{GEN nf, GEN x, GEN y}.

\subsecidx{nfeltmul}$(\var{nf},x,y)$: \label{se:nfeltmul}
given two elements $x$ and $y$ in
\var{nf}, computes their product $x*y$ in the number field $\var{nf}$.

The library syntax is \fun{GEN}{nfmul}{GEN nf, GEN x, GEN y}.

\subsecidx{nfeltmulmodpr}$(\var{nf},x,y,\var{pr})$: \label{se:nfeltmulmodpr}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}.

The library syntax is \fun{GEN}{nfmulmodpr}{GEN nf, GEN x, GEN y, GEN pr}.
This function is normally useless in library mode. Project your
inputs to the residue field using \kbd{nf\_to\_Fq}, then work there.

\subsecidx{nfeltnorm}$(\var{nf},x)$: \label{se:nfeltnorm}returns the absolute norm of $x$.

The library syntax is \fun{GEN}{nfnorm}{GEN nf, GEN x}.

\subsecidx{nfeltpow}$(\var{nf},x,k)$: \label{se:nfeltpow}given an element $x$ in \var{nf}, and a positive or negative integer $k$,
computes $x^k$ in the number field $\var{nf}$.

The library syntax is \fun{GEN}{nfpow}{GEN nf, GEN x, GEN k}.
\fun{GEN}{nfinv}{GEN nf, GEN x} correspond to $k = -1$, and
\fun{GEN}{nfsqr}{GEN nf,GEN x} to $k = 2$.

\subsecidx{nfeltpowmodpr}$(\var{nf},x,k,\var{pr})$: \label{se:nfeltpowmodpr}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}.

The library syntax is \fun{GEN}{nfpowmodpr}{GEN nf, GEN x, GEN k, GEN pr}.
This function is normally useless in library mode. Project your
inputs to the residue field using \kbd{nf\_to\_Fq}, then work there.

\subsecidx{nfeltreduce}$(\var{nf},a,\var{id})$: \label{se:nfeltreduce}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.

The library syntax is \fun{GEN}{nfreduce}{GEN nf, GEN a, GEN id}.

\subsecidx{nfeltreducemodpr}$(\var{nf},x,\var{pr})$: \label{se:nfeltreducemodpr}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}.

The library syntax is \fun{GEN}{nfreducemodpr}{GEN nf, GEN x, GEN pr}.
This function is normally useless in library mode. Project your
inputs to the residue field using \kbd{nf\_to\_Fq}, then work there.

\subsecidx{nfelttrace}$(\var{nf},x)$: \label{se:nfelttrace}returns the absolute trace of $x$.

The library syntax is \fun{GEN}{nftrace}{GEN nf, GEN x}.

\subsecidx{nfeltval}$(\var{nf},x,\var{pr})$: \label{se:nfeltval}given an element $x$ in
\var{nf} and a prime ideal \var{pr} in the format output by
\kbd{idealprimedec}, computes their the valuation at \var{pr} of the
element $x$. The same result could be obtained using
\kbd{idealval(\var{nf},x,\var{pr})} (since $x$ would then be converted to a
principal ideal), but it would be less efficient.

The library syntax is \fun{long}{nfval}{GEN nf, GEN x, GEN pr}.

\subsecidx{nffactor}$(\var{nf},x)$: \label{se:nffactor}factorization of the univariate
polynomial $x$ over the number field $\var{nf}$ given by \kbd{nfinit}. $x$
has coefficients in $\var{nf}$ (i.e.~either scalar, polmod, polynomial or
column vector). The main variable of $\var{nf}$ must be of \emph{lower}
priority than that of $x$ (see \secref{se:priority}). However if
the polynomial defining the number field occurs explicitly  in the
coefficients of $x$ (as modulus of a \typ{POLMOD}), its main variable must be
\emph{the same} as the main variable of $x$. 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\noindent 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 be computed internally. This is useful in two situations: when
you don't need the \kbd{nf}, or when you can't compute its discriminant due
to integer factorization difficulties. In the latter case, \tet{addprimes} is
a possibility but a dangerous one: factors will probably be missed if the
(true) field discriminant and an \kbd{addprimes} entry are strictly divisible
by some prime. If you have such an unsafe \var{nf}, it is safer to input
\kbd{nf.pol}.

The library syntax is \fun{GEN}{nffactor}{GEN nf, GEN x}.

\subsecidx{nffactorback}$(\var{nf},f,\{e\})$: \label{se:nffactorback}gives back the \kbd{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

The library syntax is \fun{GEN}{nffactorback}{GEN nf, GEN f, GEN e = NULL}.

\subsecidx{nffactormod}$(\var{nf},\var{pol},\var{pr})$: \label{se:nffactormod}factorization of the
univariate polynomial $x$ modulo the prime ideal \var{pr} in the number
field $\var{nf}$. $x$ can have coefficients in the number field (scalar,
polmod, polynomial, column vector) or modulo the prime ideal (intmod
modulo the rational prime under \var{pr}, polmod or polynomial with
intmod coefficients, column vector of intmod). The prime ideal
\var{pr} \emph{must} be in the format output by \kbd{idealprimedec}. 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}).

The library syntax is \fun{GEN}{nffactormod}{GEN nf, GEN pol, GEN pr}.

\subsecidx{nfgaloisapply}$(\var{nf},\var{aut},x)$: \label{se:nfgaloisapply}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]
 %7 = 0 \\ !!!!
 ? idealval(nf, nfgaloisapply(nf, aut, P[2]), P[1])
 %8 = 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 specificed 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);
 ? l = nfgaloisconj(nf); aut = l[2] \\ @com automorphisms in basistoalg form
 %2 = -31/11*x^2 + 1109/11*x - 925/11
 ? L = matalgtobasis(nf, l); AUT = L[2] \\ @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 = 1,451 ms.
 ? for (i=1,10^5, nfgaloisapply(nf, AUT, v))
 time = 1,045 ms.  \\ @com but the latter is faster
@eprog

The library syntax is \fun{GEN}{galoisapply}{GEN nf, GEN aut, GEN x}.

\subsecidx{nfgaloisconj}$(\var{nf},\{\fl=0\},\{d\})$: \label{se:nfgaloisconj}$\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=2$ (OBSOLETE), use complex approximations to the roots and an integral
\idx{LLL}. The result is not guaranteed to be complete: some
conjugates may be missing (a warning is issued if the result is not proved
complete), especially so if the corresponding polynomial has a huge index,
and increasing the default precision may help. This variant is slow and
unreliable: don't use it.

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);
  R *= Mod(1, nfK.pol);             \\ convert coeffs to polmod elts of K
  polabs = rnfequation(nfK, R);
  N = nfgaloisconj(polabs) % R;     \\ Q-automorphisms of L
  \\ select the ones that fix K
  select(s->subst(R, variable(R), Mod(s,R)) == 0, N);
}
K  = nfinit(y^2 + 7);
rnfgaloisconj(K, x^4 - y*x^3 - 3*x^2 + y*x + 1)  \\ K-automorphisms of L
@eprog

The library syntax is \fun{GEN}{galoisconj0}{GEN nf, long flag, GEN d = NULL, long prec}.
Use directly
\fun{GEN}{galoisconj}{GEN nf, GEN d}, corresponding to $\fl = 0$, the others
only have historical interest.

\subsecidx{nfhilbert}$(\var{nf},a,b,\{\var{pr}\})$: \label{se:nfhilbert}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}.

The library syntax is \fun{long}{nfhilbert0}{GEN nf, GEN a, GEN b, GEN pr = NULL}.

Also available is \fun{long}{nfhilbert}{GEN bnf,GEN a,GEN b} (global
quadratic Hilbert symbol).

\subsecidx{nfhnf}$(\var{nf},x)$: \label{se:nfhnf}given a pseudo-matrix $(A,I)$, finds a
pseudo-basis in \idx{Hermite normal form} of the module it generates.

The library syntax is \fun{GEN}{nfhnf}{GEN nf, GEN x}.
Also available:

\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.

\subsecidx{nfhnfmod}$(\var{nf},x,\var{detx})$: \label{se:nfhnfmod}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}.

The library syntax is \fun{GEN}{nfhnfmod}{GEN nf, GEN x, GEN detx}.

\subsecidx{nfinit}$(\var{pol},\{\fl=0\})$: \label{se:nfinit}\var{pol} being a non-constant,
preferably monic, irreducible polynomial in $\Z[X]$, initializes a
\emph{number field} structure (\kbd{nf}) associated 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 specified 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 \kbd{nf} or a
\kbd{bnf} instead of a polynomial.

\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

In case \var{pol} has a huge discriminant which is difficult to factor,
the special input format $[\var{pol},B]$ is also accepted where \var{pol} is a
polynomial as above and $B$ is the integer basis, as would be computed by
\tet{nfbasis}. This is useful if the integer basis is known in advance,
or was computed conditionally.
\bprog
? pol = polcompositum(x^5 - 101, polcyclo(7))[1];
? B = nfbasis(pol, 1);   \\ faster than nfbasis(pol), but conditional
? nf = nfinit( [pol, B] );
? factor( abs(nf.disc) )
[5 18]

[7 25]

[101 24]
@eprog
\kbd{B} is conditional when its discriminant, which is \kbd{nf.disc}, can't be
factored. In this example, the above factorization proves the correctness of
the computation.
\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 \kbd{polred}
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$, does a \kbd{polred} 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 a \kbd{polred}
reduction.

The library syntax is \fun{GEN}{nfinit0}{GEN pol, long flag, long prec}.
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}: slow down the routine by using an obsolete
normalization algorithm (do not use this one!),

\item \tet{nf_PARTIALFACT}: lazy factorization of the polynomial discriminant.
Result is conditional unless the \emph{field} discriminant obtained
is fully factored by
\bprog
  Z_factor_limit(disc, 0)
@eprog\noindent Namely the ``maximal order'' may not be maximal at any prime
bigger than \kbd{primelimit} dividing the field discriminant.

\subsecidx{nfisideal}$(\var{nf},x)$: \label{se:nfisideal}returns 1 if $x$ is an ideal in the number field $\var{nf}$, 0 otherwise.

The library syntax is \fun{long}{isideal}{GEN nf, GEN x}.

\subsecidx{nfisincl}$(x,y)$: \label{se:nfisincl}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 more the case.

The library syntax is \fun{GEN}{nfisincl}{GEN x, GEN y}.

\subsecidx{nfisisom}$(x,y)$: \label{se:nfisisom}as \tet{nfisincl}, but tests for isomorphism. If either $x$ or $y$ is a
number field, a much faster algorithm will be used.

The library syntax is \fun{GEN}{nfisisom}{GEN x, GEN y}.

\subsecidx{nfkermodpr}$(\var{nf},x,\var{pr})$: \label{se:nfkermodpr}kernel of the matrix $a$ in $\Z_K/\var{pr}$, where \var{pr} is in
\key{modpr} format (see \kbd{nfmodprinit}).

The library syntax is \fun{GEN}{nfkermodpr}{GEN nf, GEN x, GEN pr}.
This function is normally useless in library mode. Project your
inputs to the residue field using \kbd{nfM\_to\_FqM}, then work there.

\subsecidx{nfmodprinit}$(\var{nf},\var{pr})$: \label{se:nfmodprinit}transforms the prime ideal \var{pr} into \tet{modpr} format necessary
for all operations modulo \var{pr} in the number field \var{nf}.

The library syntax is \fun{GEN}{nfmodprinit}{GEN nf, GEN pr}.

\subsecidx{nfnewprec}$(\var{nf})$: \label{se:nfnewprec}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}$ (update
$\var{bnf}$ to current precision) but may be quite slow (many generators of
principal ideals have to be computed).

The library syntax is \fun{GEN}{nfnewprec}{GEN nf, long prec}.
See also \fun{GEN}{bnfnewprec}{GEN bnf, long prec}
and \fun{GEN}{bnrnewprec}{GEN bnr, long prec}.

\subsecidx{nfroots}$(\{\var{nf}\},x)$: \label{se:nfroots}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 be computed internally. This is useful in two situations: when
you don't need the \kbd{nf}, or when you can't compute its discriminant due
to integer factorization difficulties. In the latter case, \tet{addprimes} is
a possibility but a dangerous one: roots will probably be missed if the
(true) field discriminant and an \kbd{addprimes} entry are strictly divisible
by some prime. If you have such an unsafe \var{nf}, it is safer to input
\kbd{nf.pol}.

The library syntax is \fun{GEN}{nfroots}{GEN nf = NULL, GEN x}.
See also \fun{GEN}{nfrootsQ}{GEN x},
corresponding to $\kbd{nf} = \kbd{NULL}$.

\subsecidx{nfrootsof1}$(\var{nf})$: \label{se:nfrootsof1}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.

The library syntax is \fun{GEN}{rootsof1}{GEN nf}.
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.

\subsecidx{nfsnf}$(\var{nf},x)$: \label{se:nfsnf}given a $\Z_K$-module $x$ associated to the integral pseudo-matrix
$(A,I,J)$, returns an ideal list $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$.

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$.

The library syntax is \fun{GEN}{nfsnf}{GEN nf, GEN x}.

\subsecidx{nfsolvemodpr}$(\var{nf},a,b,\var{pr})$: \label{se:nfsolvemodpr}solution of $a\cdot x = b$
in $\Z_K/\var{pr}$, where $a$ is a matrix and $b$ a column vector, and where
\var{pr} is in \key{modpr} format (see \kbd{nfmodprinit}).

The library syntax is \fun{GEN}{nfsolvemodpr}{GEN nf, GEN a, GEN b, GEN pr}.
This function is normally useless in library mode. Project your
inputs to the residue field using \kbd{nfM\_to\_FqM}, then work there.

\subsecidx{nfsubfields}$(\var{pol},\{d=0\})$: \label{se:nfsubfields}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}

The library syntax is \fun{GEN}{nfsubfields}{GEN pol, long d}.

\subsecidx{polcompositum}$(P,Q,\{\fl=0\})$: \label{se:polcompositum}\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]$, associated 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.
Assuming $P$ is irreducible (of smaller degree than $Q$ for efficiency), it
is in general \emph{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])}.

If $\fl=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$.

A compositum is quite often defined by a complicated polynomial, which it is
advisable to reduce before further work. Here is a simple example involving
the field $\Q(\zeta_5, 5^{1/5})$:
\bprog
? z = polcompositum(x^5 - 5, polcyclo(5), 1)[1];
? pol = z[1]                 \\@com \kbd{pol} defines the compositum
%2 = 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 = z[2]; a^5 - 5          \\@com \kbd{a} is a fifth root of $5$
%3 = 0
? z = polredabs(pol, 1);     \\@com look for a simpler polynomial
? pol = z[1]
%5 = x^20 + 25*x^10 + 5
? a = subst(a.pol, x, z[2])  \\@com \kbd{a} in the new coordinates
%6 = Mod(-5/22*x^19 + 1/22*x^14 - 123/22*x^9 + 9/11*x^4, x^20 + 25*x^10 + 5)
@eprog

The library syntax is \fun{GEN}{polcompositum0}{GEN P, GEN Q, long flag}.
Also available are
\fun{GEN}{compositum}{GEN P, GEN Q} ($\fl = 0$) and
\fun{GEN}{compositum2}{GEN P, GEN Q} ($\fl = 1$).

\subsecidx{polgalois}$(x)$: \label{se:polgalois}\idx{Galois} group of the non-constant
polynomial $x\in\Q[X]$. In the present version \vers, $x$ must be irreducible
and the degree of $x$ must be less than or equal to 7. On certain versions for
which the data file of Galois resolvents has been installed (available in the
Unix distribution as a separate package), degrees 8, 9, 10 and 11 are also
implemented.

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_n$, $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 $n > 7$, $k$ is the numbering of the group among all
transitive subgroups of $S_n$, 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 $n \leq 7$, it was ad
hoc, so as to ensure that a given triple would design a unique group.
Specifically, for polynomials of degree $\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.

The library syntax is \fun{GEN}{polgalois}{GEN x, long prec}.
To enable the new format in library mode,
set the global variable \tet{new_galois_format} to $1$.

\subsecidx{polred}$(x,\{\fl=0\},\{\var{fa}\})$: \label{se:polred}finds polynomials with reasonably
small coefficients defining subfields of the number field defined by $x$.
One of the polynomials always defines $\Q$ (hence is equal to $x-1$),
and another always defines the same number field as $x$ if $x$ is irreducible.
All $x$ accepted by \tet{nfinit} are also allowed here (e.g. non-monic
polynomials, \kbd{nf}, \kbd{bnf}, \kbd{[x,Z\_K\_basis]}).

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.

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\noindent
If $fa$ is given, it is assumed that it is the two-column matrix of the
factorization of the discriminant of the polynomial $x$.

The library syntax is \fun{GEN}{polred0}{GEN x, long flag, GEN fa = NULL}.
Also available is \fun{GEN}{polred}{GEN x} ($\fl = 0$). The function
\kbd{polred0} is provided for backward compatibility; instead of the above
hardcoded numerical flags (which happen to be inconsistent), one should use
\fun{GEN}{Polred}{GEN x, long flag, GEN fa} where  flag  is  an or-ed
combination of \tet{nf_PARTIALFACT} (partial factorization of the
discriminant) and \tet{nf_ORIG} (give also elements).

\subsecidx{polredabs}$(T,\{\fl=0\})$: \label{se:polredabs}returns a canonical defining polynomial $P$ for the same number field
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: non-monic
polynomials, \kbd{nf}, \kbd{bnf}, \kbd{[T, Z\_K\_basis]}.

\misctitle{Warning} This routine uses an exponential-time algorithm to
enumerate all potential generators, and may be exceedingly slow when the
number field has many subfields, hence a lot of elements of small $T_2$-norm.
E.g. do not try it on the compositum of many quadratic fields; in that case,
use \tet{polred} instead.

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. The primes dividing the
index of the order chosen are larger than \tet{primelimit} or divide integers
stored in the \tet{addprimes} table. In that case the polynomial $P$ is
no longer canonical, and it may happen that it does not have minimal
$T_2$ norm. You should always include this flag; without it, the routine
will often spend infinite time trying to factor the discriminant of $T$. As
long as the discriminant of the \emph{field} $\Q[X]/(T)$ is easy to factor
(has at most one large prime factor not in the \kbd{addprimes} table), the
result is the same.

The library syntax is \fun{GEN}{polredabs0}{GEN T, long flag}.
Instead of the above hardcoded numerical flags, one should use an
or-ed combination of

\item \tet{nf_PARTIALFACT}: partial factorization of the discriminant,
possibly work in a non-maximal order. You should always include this.

\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.

\subsecidx{polredord}$(x)$: \label{se:polredord}finds polynomials with reasonably small
coefficients and of the same degree as that of $x$ defining suborders of the
order defined by $x$. One of the polynomials always defines $\Q$ (hence
is equal to $(x-1)^n$, where $n$ is the degree), and another always defines
the same order as $x$ if $x$ is irreducible. Useless function: try
\kbd{polred(,1)} or \kbd{polredabs(,16)}.

The library syntax is \fun{GEN}{ordred}{GEN x}.

\subsecidx{poltschirnhaus}$(x)$: \label{se:poltschirnhaus}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.

The library syntax is \fun{GEN}{tschirnhaus}{GEN x}.

\subsecidx{rnfalgtobasis}$(\var{rnf},x)$: \label{se:rnfalgtobasis}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.

The library syntax is \fun{GEN}{rnfalgtobasis}{GEN rnf, GEN x}.

\subsecidx{rnfbasis}$(\var{bnf},M)$: \label{se:rnfbasis}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.

The library syntax is \fun{GEN}{rnfbasis}{GEN bnf, GEN M}.

\subsecidx{rnfbasistoalg}$(\var{rnf},x)$: \label{se:rnfbasistoalg}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.

The library syntax is \fun{GEN}{rnfbasistoalg}{GEN rnf, GEN x}.

\subsecidx{rnfcharpoly}$(\var{nf},T,a,\{\var{var}=x\})$: \label{se:rnfcharpoly}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

The library syntax is \fun{GEN}{rnfcharpoly}{GEN nf, GEN T, GEN a, long var = -1}, where \kbd{var} is a variable number.

\subsecidx{rnfconductor}$(\var{bnf},\var{pol})$: \label{se:rnfconductor}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{rayclgp},\var{subgroup}]$, where \var{conductor} is
the conductor of the extension given as a 2-component row vector
$[f_0,f_\infty]$, \var{rayclgp} is the full ray class group corresponding to
the conductor given as a 3-component vector [h,cyc,gen] as usual for a group,
and \var{subgroup} is a matrix in HNF defining the subgroup of the ray class
group on the given generators gen.

The library syntax is \fun{GEN}{rnfconductor}{GEN bnf, GEN pol, long }.

\subsecidx{rnfdedekind}$(\var{nf},\var{pol},\{\var{pr}\},\{\fl=0\})$: \label{se:rnfdedekind}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)
%2 = [1, [[1, 0, 0; 0, 1, 0; 0, 0, 1], [1, 1, 1]], 8]
? rnfdedekind(nf, P, pr3, 1)
%3 = 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)
%5 = 0
? rnfdedekind(nf, P, pr2)
%6 = [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)
%7 = [[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)
%4 = 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).

The library syntax is \fun{GEN}{rnfdedekind}{GEN nf, GEN pol, GEN pr = NULL, long flag}.

\subsecidx{rnfdet}$(\var{nf},M)$: \label{se:rnfdet}given a pseudo-matrix $M$ over the maximal
order of $\var{nf}$, computes its determinant.

The library syntax is \fun{GEN}{rnfdet}{GEN nf, GEN M}.

\subsecidx{rnfdisc}$(\var{nf},\var{pol})$: \label{se:rnfdisc}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}.

The library syntax is \fun{GEN}{rnfdiscf}{GEN nf, GEN pol}.

\subsecidx{rnfeltabstorel}$(\var{rnf},x)$: \label{se:rnfeltabstorel}$\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 modulo the absolute equation
\kbd{\var{rnf}.pol}, computes $x$ as an element of the relative extension
$L/K$ as a polmod with polmod coefficients.

The library syntax is \fun{GEN}{rnfelementabstorel}{GEN rnf, GEN x}.

\subsecidx{rnfeltdown}$(\var{rnf},x)$: \label{se:rnfeltdown}$\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 $K$ as a polmod, assuming $x$ is in $K$ (otherwise an
error will occur). If $x$ is given on the relative integral basis, apply
\kbd{rnfbasistoalg} first, otherwise PARI will believe you are dealing with a
vector.

The library syntax is \fun{GEN}{rnfelementdown}{GEN rnf, GEN x}.

\subsecidx{rnfeltreltoabs}$(\var{rnf},x)$: \label{se:rnfeltreltoabs}$\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}. If $x$ is
given on the relative integral basis, apply \kbd{rnfbasistoalg} first,
otherwise PARI will believe you are dealing with a vector.

The library syntax is \fun{GEN}{rnfelementreltoabs}{GEN rnf, GEN x}.

\subsecidx{rnfeltup}$(\var{rnf},x)$: \label{se:rnfeltup}$\var{rnf}$ being a relative number
field extension $L/K$ as output by \kbd{rnfinit} and $x$ being an element of
$K$ expressed as a polynomial or polmod, computes $x$ as an element of the
absolute extension $L/\Q$ as a polynomial modulo the absolute equation
\kbd{\var{rnf}.pol}. If $x$ is given on the integral basis of $K$, apply
\kbd{nfbasistoalg} first, otherwise PARI will believe you are dealing with a
vector.

The library syntax is \fun{GEN}{rnfelementup}{GEN rnf, GEN x}.

\subsecidx{rnfequation}$(\var{nf},\var{pol},\{\fl=0\})$: \label{se:rnfequation}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 the absolute equation of $L$ over
$\Q$.

If $\fl$ is non-zero, outputs a 3-component row vector $[z,a,k]$, where
$z$ is the absolute equation of $L$ over $\Q$, as in the default behavior,
$a$ expresses as an element of $L$ a root $\alpha$ of the polynomial
defining the base field $\var{nf}$, and $k$ is a small integer such that
$\theta = \beta+k\alpha$ where $\theta$ is a root of $z$ and $\beta$ a root
of $\var{pol}$.

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, an error message will be issued.

The library syntax is \fun{GEN}{rnfequation0}{GEN nf, GEN pol, long flag}.
Also available are
\fun{GEN}{rnfequation}{GEN nf, GEN pol} ($\fl = 0$) and
\fun{GEN}{rnfequation2}{GEN nf, GEN pol} ($\fl = 1$).

\subsecidx{rnfhnfbasis}$(\var{bnf},x)$: \label{se:rnfhnfbasis}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.

The library syntax is \fun{GEN}{rnfhnfbasis}{GEN bnf, GEN x}.

\subsecidx{rnfidealabstorel}$(\var{rnf},x)$: \label{se:rnfidealabstorel}let $\var{rnf}$ be a relative
number field extension $L/K$ as output by \kbd{rnfinit}, and $x$ 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$.

If $x$ is an ideal in HNF form, associated to an \var{nf} structure, for
instance as output by $\tet{idealhnf}(\var{nf},\dots)$,
use \kbd{rnfidealabstorel(rnf, nf.zk * x)} to convert it to a relative ideal.

The library syntax is \fun{GEN}{rnfidealabstorel}{GEN rnf, GEN x}.

\subsecidx{rnfidealdown}$(\var{rnf},x)$: \label{se:rnfidealdown}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}), returns the ideal of $K$ below $x$,
i.e.~the intersection of $x$ with $K$.

The library syntax is \fun{GEN}{rnfidealdown}{GEN rnf, GEN x}.

\subsecidx{rnfidealhnf}$(\var{rnf},x)$: \label{se:rnfidealhnf}$\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 associated to
$x$, viewed as a $\Z_K$-module.

The library syntax is \fun{GEN}{rnfidealhermite}{GEN rnf, GEN x}.

\subsecidx{rnfidealmul}$(\var{rnf},x,y)$: \label{se:rnfidealmul}$\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.

The library syntax is \fun{GEN}{rnfidealmul}{GEN rnf, GEN x, GEN y}.

\subsecidx{rnfidealnormabs}$(\var{rnf},x)$: \label{se:rnfidealnormabs}$\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 norm of the ideal $x$
considered as an ideal of the absolute extension $L/\Q$. This is identical to
\kbd{idealnorm(rnfidealnormrel(\var{rnf},x))}, but faster.

The library syntax is \fun{GEN}{rnfidealnormabs}{GEN rnf, GEN x}.

\subsecidx{rnfidealnormrel}$(\var{rnf},x)$: \label{se:rnfidealnormrel}$\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 relative norm of $x$ as a
ideal of $K$ in HNF.

The library syntax is \fun{GEN}{rnfidealnormrel}{GEN rnf, GEN x}.

\subsecidx{rnfidealreltoabs}$(\var{rnf},x)$: \label{se:rnfidealreltoabs}$\var{rnf}$ being a relative
number field extension $L/K$ as output by \kbd{rnfinit} and $x$ being a
relative ideal, gives the ideal $x\Z_L$ as an absolute ideal of $L/\Q$, in
the form of a $\Z$-basis, given by a vector of polynomials (modulo
\kbd{rnf.pol}).
The following routine might be useful:
\bprog
\\ return y = rnfidealreltoabs(rnf,...) as an ideal in HNF form
\\ associated to nf = nfinit( rnf.pol );
idealgentoHNF(nf, y) = mathnf( Mat( nfalgtobasis(nf, y) ) );
@eprog

The library syntax is \fun{GEN}{rnfidealreltoabs}{GEN rnf, GEN x}.

\subsecidx{rnfidealtwoelt}$(\var{rnf},x)$: \label{se:rnfidealtwoelt}$\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.

The library syntax is \fun{GEN}{rnfidealtwoelement}{GEN rnf, GEN x}.

\subsecidx{rnfidealup}$(\var{rnf},x)$: \label{se:rnfidealup}$\var{rnf}$ being a relative number
field extension $L/K$ as output by \kbd{rnfinit} and $x$ being an ideal of
$K$, gives the ideal $x\Z_L$ as an absolute ideal of $L/\Q$, in the form of a
$\Z$-basis, given by a vector of polynomials (modulo \kbd{rnf.pol}).
The following routine might be useful:
\bprog
\\ return y = rnfidealup(rnf,...) as an ideal in HNF form
\\ associated to nf = nfinit( rnf.pol );
idealgentoHNF(nf, y) = mathnf( Mat( matalgtobasis(nf, y) ) );
@eprog

The library syntax is \fun{GEN}{rnfidealup}{GEN rnf, GEN x}.

\subsecidx{rnfinit}$(\var{nf},\var{pol})$: \label{se:rnfinit}$\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 all the necessary 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}$, $m$ the
degree of the base field, $n$ the relative degree, $L$ the large field (of
relative degree $n$ or absolute degree $nm$), $r_1$ and $r_2$ the number of
real and complex places of $K$.

$\var{rnf}[1]$ contains the relative polynomial \var{pol}.

$\var{rnf}[2]$ is currently unused.

$\var{rnf}[3]$ 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]$ 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]$ is a two-component row vector, where the first component is
the relative integral pseudo basis expressed as polynomials (in the variable of
$pol$) with polmod coefficients in $\var{nf}$, and the second component 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]$ is $\var{nf}$.

$\var{rnf}[11]$ is the output of \kbd{rnfequation(nf, pol, 1)}. Namely, a
vector \var{vabs} with 3 entries describing the \emph{absolute} extension
$L/\Q$. $\var{vabs}[1]$ is an absolute equation, more conveniently obtained
as \kbd{rnf.pol}. $\var{vabs}[2]$ expresses the generator $\alpha$ of the
number field $\var{nf}$ as a polynomial modulo the absolute equation
$\var{vabs}[1]$. $\var{vabs}[3]$ is a small integer $k$ such that, if $\beta$
is an abstract root of \var{pol} and $\alpha$ the generator of $\var{nf}$,
the generator whose root is \var{vabs} will be
$\beta + k \alpha$. Note that one must be very careful if $k\neq0$ when
dealing simultaneously with absolute and relative quantities since 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
strongly advise to change the relative polynomial so that its root will be
$\beta + k \alpha$. Typically, the GP instruction would be

\kbd{pol = subst(pol, x, x - k*Mod(y,\var{nf}.pol))}

$\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).

The library syntax is \fun{GEN}{rnfinit}{GEN nf, GEN pol}.

\subsecidx{rnfisabelian}$(\var{nf},T)$: \label{se:rnfisabelian}$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

The library syntax is \fun{long}{rnfisabelian}{GEN nf, GEN T}.

\subsecidx{rnfisfree}$(\var{bnf},x)$: \label{se:rnfisfree}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.

The library syntax is \fun{long}{rnfisfree}{GEN bnf, GEN x}.

\subsecidx{rnfisnorm}$(T,a,\{\fl=0\})$: \label{se:rnfisnorm}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).

The library syntax is \fun{GEN}{rnfisnorm}{GEN T, GEN a, long flag}.

\subsecidx{rnfisnorminit}$(\var{pol},\var{polrel},\{\fl=2\})$: \label{se:rnfisnorminit}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.

The library syntax is \fun{GEN}{rnfisnorminit}{GEN pol, GEN polrel, long flag}.

\subsecidx{rnfkummer}$(\var{bnr},\{\var{subgp}\},\{d=0\})$: \label{se:rnfkummer}\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.

The library syntax is \fun{GEN}{rnfkummer}{GEN bnr, GEN subgp = NULL, long d, long prec}.

\subsecidx{rnflllgram}$(\var{nf},\var{pol},\var{order})$: \label{se:rnflllgram}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.

The library syntax is \fun{GEN}{rnflllgram}{GEN nf, GEN pol, GEN order, long prec}.

\subsecidx{rnfnormgroup}$(\var{bnr},\var{pol})$: \label{se:rnfnormgroup}
\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.

The library syntax is \fun{GEN}{rnfnormgroup}{GEN bnr, GEN pol}.

\subsecidx{rnfpolred}$(\var{nf},\var{pol})$: \label{se:rnfpolred}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{rnfpolredabs}.

The library syntax is \fun{GEN}{rnfpolred}{GEN nf, GEN pol, long prec}.

\subsecidx{rnfpolredabs}$(\var{nf},\var{pol},\{\fl=0\})$: \label{se:rnfpolredabs}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

1: returns $[P,a]$ where $P$ is the default output and $a$ is an
element expressed on a root of $P$ whose characteristic polynomial is
\var{pol}

2: returns an absolute polynomial (same as
{\tt rnfequation(\var{nf},rnfpolredabs(\var{nf},\var{pol}))}
but faster).

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{Remark} In the present implementation, this is both faster and
much more efficient than \kbd{rnfpolred}, the difference being more
dramatic than in the absolute case. This is because the implementation of
\kbd{rnfpolred} is based on (a partial implementation of) an incomplete
reduction theory of lattices over number fields, the function
\kbd{rnflllgram}, which deserves to be improved.

The library syntax is \fun{GEN}{rnfpolredabs}{GEN nf, GEN pol, long flag}.

\subsecidx{rnfpseudobasis}$(\var{nf},\var{pol})$: \label{se:rnfpseudobasis}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$.

The library syntax is \fun{GEN}{rnfpseudobasis}{GEN nf, GEN pol}.

\subsecidx{rnfsteinitz}$(\var{nf},x)$: \label{se:rnfsteinitz}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)$).

The library syntax is \fun{GEN}{rnfsteinitz}{GEN nf, GEN x}.

\subsecidx{subgrouplist}$(\var{bnr},\{\var{bound}\},\{\fl=0\})$: \label{se:subgrouplist}\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}.)

The library syntax is \fun{GEN}{subgrouplist0}{GEN bnr, GEN bound = NULL, long flag}.

\subsecidx{zetak}$(\var{nfz},x,\{\fl=0\})$: \label{se:zetak}\var{znf} being a number
field initialized by \kbd{zetakinit} (\emph{not} by \kbd{nfinit}),
computes the value of the \idx{Dedekind} zeta function of the number
field at the complex number $x$. If $\fl=1$ computes Dedekind $\Lambda$
function instead (i.e.~the product of the Dedekind zeta function by its gamma
and exponential factors).

\misctitle{CAVEAT} This implementation is not satisfactory and must be
rewritten. In particular

\item The accuracy of the result depends in an essential way on the
accuracy of both the \kbd{zetakinit} program and the current accuracy.
Be wary in particular that $x$ of large imaginary part or, on the
contrary, very close to an ordinary integer will suffer from precision
loss, yielding fewer significant digits than expected. Computing with 28
digits of relative accuracy, we have
\bprog
? zeta(3)
%1 = 1.202056903159594285399738161
? zeta(3-1e-20)
%2 = 1.202056903159594285401719424
? zetak(zetakinit(x), 3-1e-20)
%3 = 1.2020569031595952919  \\ 5 digits are wrong
? zetak(zetakinit(x), 3-1e-28)
%4 = -25.33411749           \\ junk
@eprog

\item As the precision increases, results become unexpectedly
completely wrong:
\bprog
? \p100
? zetak(zetakinit(x^2-5), -1) - 1/30
%1 = 7.26691813 E-108    \\ perfect
? \p150
? zetak(zetakinit(x^2-5), -1) - 1/30
%2 = -2.486113578 E-156  \\ perfect
? \p200
? zetak(zetakinit(x^2-5), -1) - 1/30
%3 = 4.47... E-75        \\ more than half of the digits are wrong
? \p250
? zetak(zetakinit(x^2-5), -1) - 1/30
%4 = 1.6 E43             \\ junk
@eprog

The library syntax is \fun{GEN}{gzetakall}{GEN nfz, GEN x, long flag, long prec}.
See also \fun{GEN}{glambdak}{GEN znf, GEN x, long prec} or
\fun{GEN}{gzetak}{GEN znf, GEN x, long prec}.

\subsecidx{zetakinit}$(\var{bnf})$: \label{se:zetakinit}computes a number of initialization data
concerning the number field associated to \kbd{bnf} so as to be able
to compute the \idx{Dedekind} zeta and lambda functions, respectively
$\kbd{zetak}(x)$ and $\kbd{zetak}(x,1)$, at the current real precision. If
you do not need the \kbd{bnfinit} data somewhere else, you may call it
with an irreducible polynomial instead of a \var{bnf}: it will call
\kbd{bnfinit} itself.

The result is a 9-component vector $v$ whose components are very technical
and cannot really be used except through the \kbd{zetak} function.

This function is very inefficient and should be rewritten. It needs to
computes millions of coefficients of the corresponding Dirichlet series if
the precision is big. Unless the discriminant is small it will not be able
to handle more than 9 digits of relative precision. For instance,
\kbd{zetakinit(x\pow 8 - 2)} needs 440MB of memory at default precision.

The library syntax is \fun{GEN}{initzeta}{GEN bnf, long prec}.
%SECTION: number_fields

\section{Polynomials and power series}

We group here all functions which are specific to polynomials or power
series. Many other functions which can be applied on these objects are
described in the other sections. Also, some of the functions described here
can be applied to other types.


\subsecidx{O}$(p\hbox{\kbd{\pow}}e)$: \label{se:O}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.

The library syntax is \fun{GEN}{ggrando}{}.
\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$.

\subsecidx{deriv}$(x,\{v\})$: \label{se:deriv}
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$.

The library syntax is \fun{GEN}{deriv}{GEN x, long v = -1}, where \kbd{v} is a variable number.

\subsecidx{diffop}$(x,v,d,\{n=1\})$: \label{se:diffop}
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

The library syntax is \fun{GEN}{diffop0}{GEN x, GEN v, GEN d, long n}.

For $n=1$, the function \fun{GEN}{diffop}{GEN x, GEN v, GEN d} is also available.

\subsecidx{eval}$(x)$: \label{se:eval}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. For convenience, $x$ is evaluated as if
\kbd{strictmatch} was off. In particular, unused characters at the end of
$x$ do not prevent its evaluation:
\bprog
? eval("1a")
  *** eval: Warning: unused characters: a.
% 1 = 1
@eprog

\synt{geval}{GEN x}.

\subsecidx{factorpadic}$(\var{pol},p,r,\{\fl=0\})$: \label{se:factorpadic}$p$-adic factorization
of the polynomial \var{pol} to precision $r$, the result being a
two-column matrix as in \kbd{factor}. The factors are normalized so that
their leading coefficient is a power of $p$. $r$ must be strictly larger than
the $p$-adic valuation of the discriminant of \var{pol} for the result to
make any sense. The method used is a modified version of the \idx{round 4}
algorithm of \idx{Zassenhaus}.

If $\fl=1$, use an algorithm due to \idx{Buchmann} and \idx{Lenstra}, which is
much less efficient.

The library syntax is \fun{GEN}{factorpadic0}{GEN pol, GEN p, long r, long flag}.

\fun{GEN}{factorpadic}{GEN f,GEN p, long r} corresponds to the default
$\fl=0$.

\subsecidx{intformal}$(x,\{v\})$: \label{se:intformal}\idx{formal integration} of $x$ with respect to the main variable if $v$
is omitted, with respect to the variable $v$ otherwise. Since PARI does not
know about ``abstract'' logarithms (they are immediately evaluated, if only
to a power series), logarithmic terms in the result will yield an error. $x$
can be of any type. When $x$ is a rational function, it is assumed that the
base ring is an integral domain of characteristic zero.

The library syntax is \fun{GEN}{integ}{GEN x, long v = -1}, where \kbd{v} is a variable number.

\subsecidx{padicappr}$(\var{pol},a)$: \label{se:padicappr}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$.

The library syntax is \fun{GEN}{padicappr}{GEN pol, GEN a}.

\subsecidx{padicfields}$(p, N, \{\fl=0\})$: \label{se:padicfields}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 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.

The library syntax is \fun{GEN}{padicfields0}{GEN p, GEN N, long flag}.
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$.

\subsecidx{polchebyshev}$(n,\{\fl=1\},\{a='x\})$: \label{se:polchebyshev}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$.

The library syntax is \fun{GEN}{polchebyshev_eval}{long n, long flag, GEN a = NULL}.
Also available are \fun{GEN}{polchebyshev1}{long n, long v} and
\fun{GEN}{polchebyshev2}{long n, long v} for $T_n$ and $U_n$ respectively.

\subsecidx{polcoeff}$(x,n,\{v\})$: \label{se:polcoeff}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, vector or matrix types are also accepted for $x$,
 and the meaning is then identical with that of \kbd{component(x,n)}.

The library syntax is \fun{GEN}{polcoeff0}{GEN x, long n, long v = -1}, where \kbd{v} is a variable number.

\subsecidx{polcyclo}$(n,\{a = 'x\})$: \label{se:polcyclo}$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 can deal with all rational values $a$;
otherwise it assumes that $a^d - 1$ is invertible for all $d\mid n$. If this
is not the case, use \kbd{subst(polcyclo(n),x,a)}.

The library syntax is \fun{GEN}{polcyclo_eval}{long n, GEN a  = NULL}.
The variant \fun{GEN}{polcyclo}{long n, long v} returns the $n$-th
cyclotomic polynomial in variable $v$.

\subsecidx{poldegree}$(x,\{v\})$: \label{se:poldegree}degree of the polynomial $x$ in the main variable if $v$ is omitted, in
the variable $v$ otherwise.

The degree of $0$ is a fixed negative number, whose exact value should not
be used. 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.

The library syntax is \fun{long}{poldegree}{GEN x, long v = -1}, where \kbd{v} is a variable number.

\subsecidx{poldisc}$(\var{pol},\{v\})$: \label{se:poldisc}discriminant of the polynomial
\var{pol} in the main variable if $v$ is omitted, in $v$ otherwise. The
algorithm used is the \idx{subresultant algorithm}.

The library syntax is \fun{GEN}{poldisc0}{GEN pol, long v = -1}, where \kbd{v} is a variable number.

\subsecidx{poldiscreduced}$(f)$: \label{se:poldiscreduced}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$.

The library syntax is \fun{GEN}{reduceddiscsmith}{GEN f}.

\subsecidx{polhensellift}$(A, B, p, e)$: \label{se:polhensellift}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)]
? lift(lift( r[1] * r[2] * Mod(Mod(1,p^6),T) ))
%2 = x^2 + (t + 1)
@eprog

The library syntax is \fun{GEN}{polhensellift}{GEN A, GEN B, GEN p, long e}.

\subsecidx{polhermite}$(n,\{a='x\})$: \label{se:polhermite}$n^{\text{th}}$ \idx{Hermite} polynomial $H_n$ evaluated at $a$
(\kbd{'x} by default), i.e.
$$ H_(x) = (-1)^n e^{x^2} \dfrac{d^n}{dx^n}e^{-x^2}.$$

The library syntax is \fun{GEN}{polhermite_eval}{long n, GEN a = NULL}.
The variant \fun{GEN}{polhermite}{long n, long v} returns the $n$-th
Hermite polynomial in variable $v$.

\subsecidx{polinterpolate}$(X,\{Y\},\{x\},\{\&e\})$: \label{se:polinterpolate}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} passing through these points and evaluates it
at~$x$. If $Y$ is omitted, return the polynomial interpolating the
$(i,X[i])$. If present, $e$ will contain an error estimate on the returned
value.

The library syntax is \fun{GEN}{polint}{GEN X, GEN Y = NULL, GEN x = NULL, GEN *e = NULL}.

\subsecidx{polisirreducible}$(\var{pol})$: \label{se:polisirreducible}\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.

The library syntax is \fun{GEN}{gisirreducible}{GEN pol}.

\subsecidx{pollead}$(x,\{v\})$: \label{se:pollead}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.

The library syntax is \fun{GEN}{pollead}{GEN x, long v = -1}, where \kbd{v} is a variable number.

\subsecidx{pollegendre}$(n,\{a='x\})$: \label{se:pollegendre}$n^{\text{th}}$ \idx{Legendre polynomial} evaluated at $a$ (\kbd{'x} by
default).

The library syntax is \fun{GEN}{pollegendre_eval}{long n, GEN a = NULL}.
To obtain the $n$-th Legendre polynomial in variable $v$,
use \fun{GEN}{pollegendre}{long n, long v}.

\subsecidx{polrecip}$(\var{pol})$: \label{se:polrecip}reciprocal polynomial of \var{pol}, i.e.~the coefficients are in
reverse order. \var{pol} must be a polynomial.

The library syntax is \fun{GEN}{polrecip}{GEN pol}.

\subsecidx{polresultant}$(x,y,\{v\},\{\fl=0\})$: \label{se:polresultant}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 = res(x,y)$, use the \tet{bezoutres}
function.

If $\fl=0$ (default), uses the 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.

The library syntax is \fun{GEN}{polresultant0}{GEN x, GEN y, long v = -1, long flag}, where \kbd{v} is a variable number.

\subsecidx{polroots}$(x,\{\fl=0\})$: \label{se:polroots}complex roots of the polynomial
\var{pol}, 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 A.~Sch\"onhage\sidx{Sch\"onage}'s
root-finding algorithm, due to and implemented by X.~Gourdon. Barring bugs, it
is guaranteed to converge and to give the roots to the required accuracy.

If $\fl=1$, use a variant of the Newton-Raphson method, which is \emph{not}
guaranteed to converge, nor to give accurate results, but is rather
fast when it does. If you get the messages ``too many iterations in roots''
or ``INTERNAL ERROR: incorrect result in roots'', use the default algorithm.

The library syntax is \fun{GEN}{roots0}{GEN x, long flag, long prec}.
Also available is \fun{GEN}{roots}{GEN x, long prec}, as well as
\fun{GEN}{cleanroots}{GEN x, long prec} which ensures that real roots of
real polynomials are returned as \typ{REAL} (instead of \typ{COMPLEX}s with
0 imaginary part).

\subsecidx{polrootsmod}$(\var{pol},p,\{\fl=0\})$: \label{se:polrootsmod}row vector of roots modulo $p$ of the polynomial \var{pol}. The
particular non-prime value $p=4$ is accepted, mainly for $2$-adic
computations. Multiple roots are \emph{not} repeated.
\bprog
? polrootsmod(x^2-1,2)
%1 = [Mod(1, 2)]~
? polrootsmod(x^2-1,4)
%2 = [Mod(1, 4), Mod(3, 4)]~
@eprog\noindent
If $p$ is very small, you may set $\fl=1$, which uses a naive search.

The library syntax is \fun{GEN}{rootmod0}{GEN pol, GEN p, long flag}.

\subsecidx{polrootspadic}$(x,p,r)$: \label{se:polrootspadic}row vector of $p$-adic roots of
the polynomial \var{pol}, given to $p$-adic precision $r$. Multiple roots are
\emph{not} repeated. $p$ is assumed to be a prime, and \var{pol} to be
non-zero modulo $p$. 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$.

If \var{pol} has inexact \typ{PADIC} coefficients, this is not always
well-defined; in this case, the equation is first made integral, then lifted
to $\Z$. Hence the roots given are approximations of the roots of a
polynomial which is $p$-adically close to the input.

The library syntax is \fun{GEN}{rootpadic}{GEN x, GEN p, long r}.

\subsecidx{polsturm}$(\var{pol},\{a\},\{b\})$: \label{se:polsturm}number of real roots of the real squarefree polynomial \var{pol} in the
interval $]a,b]$, using Sturm's algorithm. $a$ (resp.~$b$) is taken to be
$-\infty$ (resp.~$+\infty$) if omitted.

The library syntax is \fun{long}{sturmpart}{GEN pol, GEN a = NULL, GEN b = NULL}.
Also available is \fun{long}{sturm}{GEN pol} (total number of real
roots).

\subsecidx{polsubcyclo}$(n,d,\{v=x\})$: \label{se:polsubcyclo}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 more closely which
sub-Abelian extension should be computed.

The library syntax is \fun{GEN}{polsubcyclo}{long n, long d, long v = -1}, where \kbd{v} is a variable number.

\subsecidx{polsylvestermatrix}$(x,y)$: \label{se:polsylvestermatrix}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.

The library syntax is \fun{GEN}{sylvestermatrix}{GEN x, GEN y}.

\subsecidx{polsym}$(x,n)$: \label{se:polsym}creates the column vector of the \idx{symmetric powers} of the roots of the
polynomial $x$ up to power $n$, using Newton's formula.

The library syntax is \fun{GEN}{polsym}{GEN x, long n}.

\subsecidx{poltchebi}$(n,\{v=x\})$: \label{se:poltchebi}creates the $n^{\text{th}}$ \idx{Chebyshev} polynomial~$T_n$ of the
first kind in variable $v$. This function is retained for backward
compatibility only. Use \tet{polchebyshev}.

The library syntax is \fun{GEN}{polchebyshev1}{long n, long v = -1}, where \kbd{v} is a variable number.

\subsecidx{polzagier}$(n,m)$: \label{se:polzagier}creates Zagier's polynomial $P_n^{(m)}$ used in
the functions \kbd{sumalt} and \kbd{sumpos} (with $\fl=1$). One must have $m\le
n$. The exact definition can be found in ``Convergence acceleration of
alternating series'', Cohen et al., Experiment.~Math., vol.~9, 2000, pp.~3--12.

%@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},
%}

The library syntax is \fun{GEN}{polzag}{long n, long m}.

\subsecidx{serconvol}$(x,y)$: \label{se:serconvol}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$.

The library syntax is \fun{GEN}{convol}{GEN x, GEN y}.

\subsecidx{serlaplace}$(x)$: \label{se:serlaplace}$x$ must be a power series with non-negative
exponents. If $x=\sum (a_k/k!)*X^k$ then the result is $\sum a_k*X^k$.

The library syntax is \fun{GEN}{laplace}{GEN x}.

\subsecidx{serreverse}$(x)$: \label{se:serreverse}reverse power series (i.e.~$x^{-1}$, not $1/x$)
of $x$. $x$ must be a power series whose valuation is exactly equal to one.

The library syntax is \fun{GEN}{recip}{GEN x}.

\subsecidx{subst}$(x,y,z)$: \label{se:subst}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.

The library syntax is \fun{GEN}{gsubst}{GEN x, long y, GEN z}, where \kbd{y} is a variable number.

\subsecidx{substpol}$(x,y,z)$: \label{se:substpol}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

The library syntax is \fun{GEN}{gsubstpol}{GEN x, GEN y, GEN z}.
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).

\subsecidx{substvec}$(x,v,w)$: \label{se:substvec}$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

The library syntax is \fun{GEN}{gsubstvec}{GEN x, GEN v, GEN w}.

\subsecidx{taylor}$(x,t,\{d=\var{seriesprecision}\})$: \label{se:taylor}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

The library syntax is \fun{GEN}{tayl}{GEN x, long t, long precdl}, where \kbd{t} is a variable number.

\subsecidx{thue}$(\var{tnf},a,\{\var{sol}\})$: \label{se:thue}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 will be issued.

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
favourable cases. The result is conditional on the GRH if
$a\neq \pm 1$ and, $P$ has a single irreducible rational factor, whose
associated 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
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.ref
%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.

The library syntax is \fun{GEN}{thue}{GEN tnf, GEN a, GEN sol = NULL}.

\subsecidx{thueinit}$(P,\{\fl=0\})$: \label{se:thueinit}initializes the \var{tnf} corresponding to $P$, a 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.

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 always unconditional.

The library syntax is \fun{GEN}{thueinit}{GEN P, long flag, long prec}.
%SECTION: polynomials

\section{Vectors, matrices, linear algebra and sets}
\label{se:linear_algebra}

Note that most linear algebra functions operating on subspaces defined by
generating sets (such as \tet{mathnf}, \tet{qflll}, etc.) take matrices as
arguments. As usual, the generating vectors are taken to be the
\emph{columns} of the given matrix.

Since PARI does not have a strong typing system, scalars live in
unspecified commutative base rings. It is very difficult to write
robust linear algebra routines in such a general setting. We thus
assume that the base ring is a domain and work over its field of
fractions. If the base ring is \emph{not} a domain, one gets an error as soon
as a non-zero pivot turns out to be non-invertible. Some functions,
e.g.~\kbd{mathnf} or \kbd{mathnfmod}, specifically assume that the base ring is
$\Z$.


\subsecidx{algdep}$(x,k,\{\fl=0\})$: \label{se:algdep}\sidx{algebraic dependence}
$x$ being real/complex, or $p$-adic, finds a polynomial of degree at most
$k$ with integer coefficients having $x$ 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}).

Internally, \tet{lindep}$([1,x,\ldots,x^k], \fl)$ is used. If
\tet{lindep} is not able to find a relation and returns a lower bound for the
sup norm of the smallest relation, \tet{algdep} returns that bound instead.
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  (this truncates the number, throwing away the least
significant bits), but default values are usually sufficient:
\bprog
\\\\\\\\\ LLL
? \p200
? algdep(2^(1/6)+3^(1/5), 30);      \\ wrong in 0.8s
? algdep(2^(1/6)+3^(1/5), 30, 100); \\ wrong in 0.4s
? algdep(2^(1/6)+3^(1/5), 30, 170); \\ right in 0.8s
? algdep(2^(1/6)+3^(1/5), 30, 200); \\ wrong in 1.0s
? \p250
? algdep(2^(1/6)+3^(1/5), 30);      \\ right in 1.0s
? algdep(2^(1/6)+3^(1/5), 30, 200); \\ right in 1.0s
? \p500
? algdep(2^(1/6)+3^(1/5), 30);      \\ right in 2.9s
? \p1000
? algdep(2^(1/6)+3^(1/5), 30);      \\ right in 10.6s
\\\\\\\\\ PSLQ
? \p200
? algdep(2^(1/6)+3^(1/5), 30, -3);  \\ failure in 15s
? \p250
? algdep(2^(1/6)+3^(1/5), 30, -3);  \\ right in 20s
? \p500
? algdep(2^(1/6)+3^(1/5), 30, -3);  \\ right in 52s
? \p1000
? algdep(2^(1/6)+3^(1/5), 30, -3);  \\ right in 164s
@eprog\noindent
The changes in \kbd{defaultprecision} 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 205 digits, and from then on a
steady stream of correct results. Interestingly enough, our PSLQ also
reliably succeeds from 205 digits on (and is 15 times slower at that
accuracy).

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 paper concludes in the superiority of the PSLQ
algorithm, which either shows that PARI's implementation of PSLQ is lacking,
or that its LLL is extremely good. 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.

The library syntax is \fun{GEN}{algdep0}{GEN x, long k, long flag}.
Also available is \fun{GEN}{algdep}{GEN x, long k} ($\fl=0$).

\subsecidx{charpoly}$(A,\{v=x\},\{\fl=3\})$: \label{se:charpoly}
\idx{characteristic polynomial}
of $A$ with respect to the variable $v$, i.e.~determinant of $v*I-A$ if $A$
is a square matrix. If $A$ is not a square matrix, it returns the
characteristic polynomial of the map ``multiplication by $A$'' if $A$ is a
scalar, in particular a polmod. E.g.~\kbd{charpoly(I) = x\pow2+1}.

The value of $\fl$ is only significant for matrices. 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.

In practice one should use the default (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$).

The library syntax is \fun{GEN}{charpoly0}{GEN A, long v = -1, long flag}, where \kbd{v} is a variable number.
Also available are \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.

\subsecidx{concat}$(x,\{y\})$: \label{se:concat}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, it is easy to concatenate them vertically.

To concatenate vectors sideways (i.e.~to obtain a two-row or two-column
matrix), use \tet{Mat} instead (see the example there). 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
definitely \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

The library syntax is \fun{GEN}{concat}{GEN x, GEN y = NULL}.
\fun{GEN}{concat1}{GEN x} is a shortcut for \kbd{concat(x,NULL)}.

\subsecidx{lindep}$(x,\{\fl=0\})$: \label{se:lindep}\sidx{linear dependence}$x$ being a
vector with $p$-adic or real/complex coefficients, finds a small integral
linear combination among these coefficients.

If $x$ is $p$-adic, $\fl$ is meaningless and the algorithm LLL-reduces a
suitable (dual) lattice.

Otherwise, the value of $\fl$ determines the algorithm used; in the current
version of PARI, we suggest to use \emph{non-negative} values, since it is by
far the fastest and most robust implementation. See the detailed example in
\secref{se:algdep} (\kbd{algdep}).

If $\fl\geq 0$, uses a floating point (variable precision) LLL algorithm.
This is in general much faster than the other variants.
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.

If $\fl=-1$, uses a variant of the \idx{LLL} algorithm due to Hastad,
Lagarias and Schnorr (STACS 1986). If the precision is too low, the routine
may enter an infinite loop. Faster than the alternatives if it converges,
especially when the accuracy is much larger than what is really necessary;
usually diverges, though.

If $\fl=-2$, $x$ is allowed to be (and in any case interpreted as) a matrix.
Returns a non trivial element of the kernel of $x$, or $0$ if $x$ has trivial
kernel. The element is defined over the field of coefficients of $x$, and is
in general not integral.

If $\fl=-3$, uses the PSLQ algorithm. This may return a real number $B$,
indicating that the input accuracy was exhausted and that no relation exist
whose sup norm is less than $B$.

If $\fl=-4$, uses an experimental 2-level PSLQ, which does not work at all.
Don't use it!

The library syntax is \fun{GEN}{lindep0}{GEN x, long flag}.
Also available are \fun{GEN}{lindep}{GEN x} ($\fl=0$)
\fun{GEN}{lindep2}{GEN x, long bit} ($\fl\geq 0$, bypasses the check for
$p$-adic inputs) and \fun{GEN}{deplin}{GEN x} ($\fl=-2$).

\subsecidx{listcreate}$()$: \label{se:listcreate}creates an empty list. This routine used to have a mandatory argument,
which is now ignored (for backward compatibility). In fact, this function
has become redundant and obsolete; it will disappear in future versions of
PARI: just use \kbd{List()}
% \syn{NO}

\subsecidx{listinsert}$(L,x,n)$: \label{se:listinsert}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.

The library syntax is \fun{GEN}{listinsert}{GEN L, GEN x, long n}.

\subsecidx{listkill}$(L)$: \label{se:listkill}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.

The library syntax is \fun{void}{listkill}{GEN L}.

\subsecidx{listpop}$(\var{list},\{n\})$: \label{se:listpop}
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.
This runs in time $O(\#L - n + 1)$.

The library syntax is \fun{void}{listpop}{GEN list, long n}.

\subsecidx{listput}$(\var{list},x,\{n\})$: \label{se:listput}
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$.
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. This 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.

The library syntax is \fun{GEN}{listput}{GEN list, GEN x, long n}.

\subsecidx{listsort}$(L,\{\fl=0\})$: \label{se:listsort}sorts the \typ{LIST} \var{list} in place. If $\fl$ is non-zero,
suppresses all repeated coefficients. This is faster than the \kbd{vecsort}
command since no copy has to be made. No value returned.

The library syntax is \fun{void}{listsort}{GEN L, long flag}.

\subsecidx{matadjoint}$(x,\{\fl=0\})$: \label{se:matadjoint}
\idx{adjoint matrix} of $x$, i.e.~the matrix $y$
of cofactors of $x$, satisfying $x*y=\det(x)*\Id$. $x$ must be a
(non-necessarily invertible) square matrix of dimension $n$.
If $\fl$ is 0 or omitted, use a fast algorithm which assumes that $n!$ is
invertible. If $\fl$ is 1, use a slower division-free algorithm.
\bprog
? a = [1,2,3;3,4,5;6,7,8] * Mod(1,2);
? matadjoint(a)
 ***   at top-level: matadjoint([1,2,3;3,
 ***                 ^--------------------
 *** matadjoint: impossible inverse modulo: Mod(0, 2).
? matadjoint(a, 1)  \\ use safe algorithm
%2 =
[Mod(1, 2) Mod(1, 2) Mod(0, 2)]

[Mod(0, 2) Mod(0, 2) Mod(0, 2)]

[Mod(1, 2) Mod(1, 2) Mod(0, 2)]
@eprog\noindent
Both algorithms use $O(n^4)$ operations in the base ring.

The library syntax is \fun{GEN}{matadjoint0}{GEN x, long flag}.
Also available are
\fun{GEN}{adj}{GEN x} (\fl=0) and
\fun{GEN}{adjsafe}{GEN x} (\fl=1).

\subsecidx{matcompanion}$(x)$: \label{se:matcompanion}
the left companion matrix to the polynomial $x$.

The library syntax is \fun{GEN}{matcompanion}{GEN x}.

\subsecidx{matdet}$(x,\{\fl=0\})$: \label{se:matdet}determinant of $x$. $x$ must be a square matrix.

If $\fl=0$, uses Gauss-Bareiss.

If $\fl=1$, uses classical Gaussian elimination, which is better when the
entries of the matrix are reals or integers for example, but usually much
worse for more complicated entries like multivariate polynomials.

The library syntax is \fun{GEN}{det0}{GEN x, long flag}.
Also available are \fun{GEN}{det}{GEN x} ($\fl=0$) and
\fun{GEN}{det2}{GEN x} ($\fl=1$).

\subsecidx{matdetint}$(x)$: \label{se:matdetint}
$x$ being an $m\times n$ matrix with integer
coefficients, this function computes a non-zero \emph{multiple} of the
determinant of
the lattice generated by the columns of $x$ if it has maximal rank $m$, and
returns zero otherwise, using the Gauss-Bareiss algorithm. When $x$ is square,
the exact determinant is obtained.

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 the exact determinant using
\bprog
  matdet( mathnfmod(x, matdetint(x)) )
@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(x, 1)} or
\kbd{mathnf(x, 4)} directly.

The library syntax is \fun{GEN}{detint}{GEN x}.

\subsecidx{matdiagonal}$(x)$: \label{se:matdiagonal}$x$ being a vector, creates the diagonal matrix
whose diagonal entries are those of $x$.

The library syntax is \fun{GEN}{diagonal}{GEN x}.

\subsecidx{mateigen}$(x)$: \label{se:mateigen}gives the eigenvectors of $x$ as columns of a matrix.

The library syntax is \fun{GEN}{eigen}{GEN x, long prec}.

\subsecidx{matfrobenius}$(M,\{\fl\},\{v=x\})$: \label{se:matfrobenius}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$.

The library syntax is \fun{GEN}{matfrobenius}{GEN M, long flag, long v = -1}, where \kbd{v} is a variable number.

\subsecidx{mathess}$(x)$: \label{se:mathess}returns a matrix similar to the square matrix $x$, which is in upper Hessenberg
form (zero entries below the first subdiagonal).

The library syntax is \fun{GEN}{hess}{GEN x}.

\subsecidx{mathilbert}$(n)$: \label{se:mathilbert}$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)$.

The library syntax is \fun{GEN}{mathilbert}{long n}.

\subsecidx{mathnf}$(x,\{\fl=0\})$: \label{se:mathnf}if $x$ is a (not necessarily square)
matrix with integer entries, 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$.

If $\fl=0$, uses the naive algorithm. This is in general fastest but may
require too much memory as the dimension gets large (bigger than 100, say),
in which case you may try \kbd{mathnfmod(x, matdetint(x))} when $x$ has
maximal rank, and \kbd{mathnf(x, 4)} otherwise.

If $\fl=1$, outputs a two-component row vector $[H,U]$, where $H$ is the
Hermite normal form of $x$ defined as above,  and $U$ is the
unimodular transformation matrix such that $xU=[0|H]$. When the kernel is
large, $U$ has in general huge coefficients. In the worst case, the
running time is exponential with respect to the dimension, but the
routine behaves well in small dimension (less than 50 or 100, say).

If $\fl=3$, 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 $xU$ gives $H$. This is in general slower than $\fl=1$ but the matrix $U$
is smaller; it may still be large.

If $\fl=4$, as in case 1 above, but uses a variant of \idx{LLL}
reduction along the way. The matrix $U$ is in general close to optimal (in
terms of smallest $L_2$ norm), but the reduction is in general slow,
although provably polynomial-time.

The library syntax is \fun{GEN}{mathnf0}{GEN x, long flag}.
Also available are \fun{GEN}{hnf}{GEN x} ($\fl=0$) and
\fun{GEN}{hnfall}{GEN x} ($\fl=1$). To reduce \emph{huge} (say $400 \times
400$ and more) relation matrices (sparse with small entries), 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/alglin1.c}.

\subsecidx{mathnfmod}$(x,d)$: \label{se:mathnfmod}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.

The library syntax is \fun{GEN}{hnfmod}{GEN x, GEN d}.

\subsecidx{mathnfmodid}$(x,d)$: \label{se:mathnfmodid}outputs the (upper triangular)
\idx{Hermite normal form} of $x$ concatenated with $d$ times
the identity matrix. Assumes that $x$ has integer entries.

The library syntax is \fun{GEN}{hnfmodid}{GEN x, GEN d}.

\subsecidx{matid}$(n)$: \label{se:matid}creates the $n\times n$ identity matrix.

The library syntax is \fun{GEN}{matid}{long n}.

\subsecidx{matimage}$(x,\{\fl=0\})$: \label{se:matimage}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!).

The library syntax is \fun{GEN}{matimage0}{GEN x, long flag}.
Also available is \fun{GEN}{image}{GEN x} ($\fl=0$).

\subsecidx{matimagecompl}$(x)$: \label{se:matimagecompl}gives the vector of the column indices which
are not extracted by the function \kbd{matimage}. 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$.

The library syntax is \fun{GEN}{imagecompl}{GEN x}.

\subsecidx{matindexrank}$(x)$: \label{se:matindexrank}$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.

The library syntax is \fun{GEN}{indexrank}{GEN x}.

\subsecidx{matintersect}$(x,y)$: \label{se:matintersect}$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.

The library syntax is \fun{GEN}{intersect}{GEN x, GEN y}.

\subsecidx{matinverseimage}$(x,y)$: \label{se:matinverseimage}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

The library syntax is \fun{GEN}{inverseimage}{GEN x, GEN y}.

\subsecidx{matisdiagonal}$(x)$: \label{se:matisdiagonal}returns true (1) if $x$ is a diagonal matrix, false (0) if not.

The library syntax is \fun{GEN}{isdiagonal}{GEN x}.

\subsecidx{matker}$(x,\{\fl=0\})$: \label{se:matker}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$.

The library syntax is \fun{GEN}{matker0}{GEN x, long flag}.
Also available are \fun{GEN}{ker}{GEN x} ($\fl=0$),
\fun{GEN}{keri}{GEN x} ($\fl=1$).

\subsecidx{matkerint}$(x,\{\fl=0\})$: \label{se:matkerint}gives an \idx{LLL}-reduced $\Z$-basis
for the lattice equal to the kernel of the matrix $x$ as columns of the
matrix $x$ with integer entries (rational entries are not permitted).

If $\fl=0$, uses an integer LLL algorithm.

If $\fl=1$, uses $\kbd{matrixqz}(x,-2)$. Many orders of magnitude slower
than the default: never use this.

The library syntax is \fun{GEN}{matkerint0}{GEN x, long flag}.
See also \fun{GEN}{kerint}{GEN x} ($\fl=0$), which is a trivial
wrapper around
\bprog
ZM_lll(ZM_lll(x, 0.99, LLL_KER), 0.99, LLL_INPLACE);
@eprog\noindent Remove the outermost \kbd{ZM\_lll} if LLL-reduction is not
desired (saves time).

\subsecidx{matmuldiagonal}$(x,d)$: \label{se:matmuldiagonal}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)$.

The library syntax is \fun{GEN}{matmuldiagonal}{GEN x, GEN d}.

\subsecidx{matmultodiagonal}$(x,y)$: \label{se:matmultodiagonal}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.

The library syntax is \fun{GEN}{matmultodiagonal}{GEN x, GEN y}.

\subsecidx{matpascal}$(n,\{q\})$: \label{se:matpascal}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).

The library syntax is \fun{GEN}{matqpascal}{long n, GEN q = NULL}.
Also available is \fun{GEN}{matpascal}{GEN x}.

\subsecidx{matrank}$(x)$: \label{se:matrank}rank of the matrix $x$.

The library syntax is \fun{long}{rank}{GEN x}.

\subsecidx{matrix}$(m,n,\{X\},\{Y\},\{\var{expr}=0\})$: \label{se:matrix}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}

\subsecidx{matrixqz}$(A,\{p=0\})$: \label{se:matrixqz}$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( vecextract(x, Str("^",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

The library syntax is \fun{GEN}{matrixqz0}{GEN A, GEN p = NULL}.

\subsecidx{matsize}$(x)$: \label{se:matsize}$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).

The library syntax is \fun{GEN}{matsize}{GEN x}.

\subsecidx{matsnf}$(X,\{\fl=0\})$: \label{se:matsnf}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.

The library syntax is \fun{GEN}{matsnf0}{GEN X, long flag}.

\subsecidx{matsolve}$(M,B)$: \label{se:matsolve}$M$ being an invertible matrix and $B$ a column
vector, finds the solution $X$ of $MX=B$, using Gaussian elimination. This
has the same effect as, but is a bit faster, than $M^{-1}*B$.

The library syntax is \fun{GEN}{gauss}{GEN M, GEN B}.

\subsecidx{matsolvemod}$(M,D,B,\{\fl=0\})$: \label{se:matsolvemod}$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.

The library syntax is \fun{GEN}{matsolvemod0}{GEN M, GEN D, GEN B, long flag}.
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$).

\subsecidx{matsupplement}$(x)$: \label{se:matsupplement}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.

The library syntax is \fun{GEN}{suppl}{GEN x}.

\subsecidx{mattranspose}$(x)$: \label{se:mattranspose}transpose of $x$ (also $x\til$).
This has an effect only on vectors and matrices.

The library syntax is \fun{GEN}{gtrans}{GEN x}.

\subsecidx{minpoly}$(A,\{v=x\})$: \label{se:minpoly}\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$.

The library syntax is \fun{GEN}{minpoly}{GEN A, long v = -1}, where \kbd{v} is a variable number.

\subsecidx{qfgaussred}$(q)$: \label{se:qfgaussred}
\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$.

The library syntax is \fun{GEN}{qfgaussred}{GEN q}.
\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).

\subsecidx{qfjacobi}$(x)$: \label{se:qfjacobi}$x$ being a real symmetric matrix, this gives a
vector having two components: the first one is the vector of (real)
eigenvalues of $x$, sorted in increasing order, the second is the
corresponding orthogonal matrix of eigenvectors of $x$. The method used is
Jacobi's method for symmetric matrices.

The library syntax is \fun{GEN}{jacobi}{GEN x, long prec}.

\subsecidx{qflll}$(x,\{\fl=0\})$: \label{se:qflll}\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.

The library syntax is \fun{GEN}{qflll0}{GEN x, long flag}.
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$).

\subsecidx{qflllgram}$(G,\{\fl=0\})$: \label{se:qflllgram}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.

The library syntax is \fun{GEN}{qflllgram0}{GEN G, long flag}.
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$).

\subsecidx{qfminim}$(x,\{b\},\{m\},\{\fl=0\})$: \label{se:qfminim}$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), seeks at most $2m$ vectors. The result is a
three-component vector, the first component being the number of vectors
found, the second being the maximum norm found, and the last vector is a
matrix whose columns are the vectors found, 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 the first vector whose norm is less
than $b$. In this variant, an explicit $b$ must be provided.

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.

The library syntax is \fun{GEN}{qfminim0}{GEN x, GEN b = NULL, GEN m = NULL, long flag, long prec}.
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$).

\subsecidx{qfperfection}$(G)$: \label{se:qfperfection}
$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.

The library syntax is \fun{GEN}{perf}{GEN G}.

\subsecidx{qfrep}$(q,B,\{\fl=0\})$: \label{se:qfrep}
$q$ being a square and symmetric
matrix with integer entries representing a positive definite quadratic form,
outputs the vector whose $i$-th entry, $1 \leq i \leq B$ is half the number
of vectors $v$ such that $q(v) = i$. This routine uses a naive algorithm
based on \tet{qfminim}, and will fail if any entry becomes larger than
$2^{31}$.

\noindent The binary digits of \fl\ mean:

\item 1: count vectors of even norm from $1$ to $2B$.

\item 2: return a \typ{VECSMALL} instead of a \typ{VEC}

The library syntax is \fun{GEN}{qfrep0}{GEN q, GEN B, long flag}.

\subsecidx{qfsign}$(x)$: \label{se:qfsign}
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.

The library syntax is \fun{GEN}{qfsign}{GEN x}.

\subsecidx{setintersect}$(x,y)$: \label{se:setintersect}intersection of the two sets $x$ and $y$ (see \kbd{setisset}).
The function also works if both $x$ and $y$ are vectors of strictly increasing
entries, according to \kbd{<}); in that case we return a vector of strictly
increasing entries, not a set. Otherwise, the result is undefined.

The library syntax is \fun{GEN}{setintersect}{GEN x, GEN y}.

\subsecidx{setisset}$(x)$: \label{se:setisset}
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 \typ{STR}s. 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

The library syntax is \fun{long}{setisset}{GEN x}.

\subsecidx{setminus}$(x,y)$: \label{se:setminus}difference of the two sets $x$ and $y$ (see \kbd{setisset}),
i.e.~set of elements of $x$ which do not belong to $y$.
The function also works if both $x$ and $y$ are vectors of strictly increasing
entries, according to \kbd{<}); in that case we return a vector of strictly
increasing entries, not a set. Otherwise, the result is undefined.

The library syntax is \fun{GEN}{setminus}{GEN x, GEN y}.

\subsecidx{setsearch}$(S,x,\{\fl=0\})$: \label{se:setsearch}searches if $x$ belongs to the set $S$ (see \kbd{setisset}).
A set is a vector of \typ{STR}, but this function
works also if $S$ is a arbitrary \emph{sorted} vector or list (see
\kbd{listsort}): if $x$ is not a \typ{STR}, we first
replace it by \kbd{Str}$(x)$ \emph{unless} the first element of $S$ is also
not a \typ{STR}.

If $x$ belongs to the set and $\fl$ is zero or omitted, returns the
index $j$ such that $S[j]=x$, otherwise returns 0. If $\fl$ is non-zero
returns the index $j$ where $x$ should be inserted, and $0$ if it already
belongs to $S$ (this is meant to be used in conjunction with
\kbd{listinsert}, see below).
\bprog
? T = [2,3,5,7]; S = Set(T);
? setsearch(S, 2)      \\ search in a true set, t_INT 2 converted to string
%2 = 1
? setsearch(S, Str(2)) \\ search in a true set, no need for conversion
%3 = 1
? setsearch(T, 2)      \\ search in a sorted vector, no need for conversion
%4 = 1
? setsearch(T, Str(2)) \\ search in a sorted vector, t_STR "2" not found
%5 = 0
? setsearch(S, 4)      \\ not found
%6 = 0
? setsearch(S, 4, 1)   \\ should have been inserted at index 3
%7 = 3
@eprog

The library syntax is \fun{long}{setsearch}{GEN S, GEN x, long flag}.

\subsecidx{setunion}$(x,y)$: \label{se:setunion}union of the two sets $x$ and $y$ (see \kbd{setisset}).
The function also works if both $x$ and $y$ are vectors of strictly increasing
entries, according to \kbd{<}); in that case we return a vector of strictly
increasing entries, not a set. Otherwise, the result is undefined.

The library syntax is \fun{GEN}{setunion}{GEN x, GEN y}.

\subsecidx{trace}$(x)$: \label{se:trace}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.

The library syntax is \fun{GEN}{gtrace}{GEN x}.

\subsecidx{vecextract}$(x,y,\{z\})$: \label{se:vecextract}extraction of components of the
vector or matrix $x$ according to $y$. In case $x$ is a matrix, its
components are as usual 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, 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{line}
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 library syntax is \fun{GEN}{extract0}{GEN x, GEN y, GEN z = NULL}.

\subsecidx{vecsort}$(x,\{\var{cmp}\},\{\fl=0\})$: \label{se:vecsort}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{cmp} is omitted, we use the standard comparison function
\kbd{<}, thereby restricting the possible types for the elements of $x$
(integers, fractions or reals). If \kbd{cmp} 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{cmp}=\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],lex) \\ sort columns according to lex order
%1 =
[2 3]

[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
? cmp(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], cmp)
@eprog\noindent
The last example used the named \kbd{cmp} 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 2: sorts $x$ by ascending lexicographic order (as per the
\kbd{lex} comparison function).

\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

The library syntax is \fun{GEN}{vecsort0}{GEN x, GEN cmp = NULL, long flag}.

\subsecidx{vector}$(n,\{X\},\{\var{expr}=0\})$: \label{se:vector}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.

Avoid modifying $X$ within \var{expr}; if you do, the formal variable
still runs from $1$ to $n$. In particular, \kbd{vector(n,i,expr)} is not
equivalent to
\bprog
v = vector(n)
for (i = 1, n, v[i] = expr)
@eprog\noindent
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}

\subsecidx{vectorsmall}$(n,\{X\},\{\var{expr}=0\})$: \label{se:vectorsmall}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}

\subsecidx{vectorv}$(n,\{X\},\{\var{expr}=0\})$: \label{se:vectorv}as \tet{vector}, but returns a column vector (type \typ{COL}).
%\syn{NO}
%SECTION: linear_algebra

\section{Sums, products, integrals and similar functions}
\label{se:sums}

Although the \kbd{gp} calculator is programmable, it is useful to have
a number of preprogrammed loops, including sums, products, and a certain
number of recursions. Also, a number of functions from numerical analysis
like numerical integration and summation of series will be described here.

One of the parameters in these loops must be the control variable, hence a
simple variable name. In the descriptions, the letter $X$ will always denote
any simple variable name, and represents the formal parameter used in the
function. The expression to be summed, integrated, etc. is any legal PARI
expression, including of course expressions using loops.

\misctitle{Library mode}
Since it is easier to program directly the loops in library mode, these
functions are mainly useful for GP programming. On the other hand, numerical
routines code a function (to be integrated, summed, etc.) with two parameters
named
\bprog
  GEN (*eval)(void*,GEN)
  void *E;  \\ context: eval(E, x) must evaluate your function at x.
@eprog\noindent
see the Libpari manual for details.

\misctitle{Numerical integration}\sidx{numerical integration}
Starting with version 2.2.9 the ``double exponential'' univariate
integration method is implemented in \tet{intnum} and its variants. Romberg
integration is still available under the name \kbd{intnumromb}, but
superseded. It is possible to compute numerically integrals to thousands of
decimal places in reasonable time, as long as the integrand is regular. It is
also reasonable to compute numerically integrals in several variables,
although more than two becomes lengthy. The integration domain may be
non-compact, and the integrand may have reasonable singularities at
endpoints. To use \kbd{intnum}, you must split the integral into a sum
of subintegrals where the function has no singularities except at the
endpoints. Polynomials in logarithms are not considered singular, and
neglecting these logs, singularities are assumed to be algebraic (asymptotic
to $C(x-a)^{-\alpha}$ for some $\alpha > -1$ when $x$ is
close to $a$), or to correspond to simple discontinuities of some (higher)
derivative of the function. For instance, the point $0$ is a singularity of
$\text{abs}(x)$.

See also the discrete summation methods below, sharing the prefix \kbd{sum}.


\subsecidx{derivnum}$(X=a,\var{expr})$: \label{se:derivnum}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$.

\subsecidx{intcirc}$(X=a,R,\var{expr},\{\var{tab}\})$: \label{se:intcirc}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
%1 = -2.398082982 E-104 - 7.94487211 E-107*I
@eprog

\synt{intcirc}{void *E, GEN (*eval)(void*,GEN), GEN a,GEN R,GEN tab, long prec}.

\subsecidx{intfouriercos}$(X=a,b,z,\var{expr},\{\var{tab}\})$: \label{se:intfouriercos}numerical
integration of $\var{expr}(X)\cos(2\pi zX)$ from $a$ to $b$, in other words
Fourier cosine transform (from $a$ to $b$) of the function represented by
\var{expr}. Endpoints $a$ and $b$ are coded as in \kbd{intnum}, and are not
necessarily at infinity, but if they are, oscillations (i.e. $[[\pm1],\alpha
I]$) are forbidden.

\synt{intfouriercos}{void *E, GEN (*eval)(void*,GEN), GEN a, GEN b, GEN z, GEN tab, long prec}.

\subsecidx{intfourierexp}$(X=a,b,z,\var{expr},\{\var{tab}\})$: \label{se:intfourierexp}numerical
integration of $\var{expr}(X)\exp(-2i\pi zX)$ from $a$ to $b$, in other words
Fourier transform (from $a$ to $b$) of the function represented by
\var{expr}. Note the minus sign. Endpoints $a$ and $b$ are coded as in
\kbd{intnum}, and are not necessarily at infinity but if they are,
oscillations (i.e. $[[\pm1],\alpha I]$) are forbidden.

\synt{intfourierexp}{void *E, GEN (*eval)(void*,GEN), GEN a, GEN b, GEN z, GEN tab, long prec}.

\subsecidx{intfouriersin}$(X=a,b,z,\var{expr},\{\var{tab}\})$: \label{se:intfouriersin}numerical
integration of $\var{expr}(X)\sin(2\pi zX)$ from $a$ to $b$, in other words
Fourier sine transform (from $a$ to $b$) of the function represented by
\var{expr}. Endpoints $a$ and $b$ are coded as in \kbd{intnum}, and are not
necessarily at infinity but if they are, oscillations (i.e. $[[\pm1],\alpha
I]$) are forbidden.

\synt{intfouriersin}{void *E, GEN (*eval)(void*,GEN), GEN a, GEN b, GEN z, GEN tab, long prec}.

\subsecidx{intfuncinit}$(X=a,b,\var{expr},\{\fl=0\},\{m=0\})$: \label{se:intfuncinit}initialize tables for use with integral transforms such as \kbd{intmellininv},
etc., where $a$ and $b$ are coded as in \kbd{intnum}, $\var{expr}$ is the
function $s(X)$ to which the integral transform is to be applied (which will
multiply the weights of integration) and $m$ is as in \kbd{intnuminit}. If
$\fl$ is nonzero, assumes that $s(-X)=\overline{s(X)}$, which makes the
computation twice as fast. See \kbd{intmellininvshort} for examples of the
use of this function, which is particularly useful when the function $s(X)$
is lengthy to compute, such as a gamma product.

\synt{intfuncinit}{void *E, GEN (*eval)(void*,GEN), GEN a,GEN b,long m, long
flag, long prec}. Note that the order of $m$ and $\fl$ are reversed compared
to the \kbd{GP} syntax.

\subsecidx{intlaplaceinv}$(X=\var{sig},z,\var{expr},\{\var{tab}\})$: \label{se:intlaplaceinv}numerical integration of $(2i\pi)^{-1}\var{expr}(X)e^{Xz}$ with respect
to $X$ on the line $\Re(X)=sig$. In other words, inverse Laplace transform
of the function corresponding to \var{expr} at the value $z$.

$sig$ is coded as follows. Either it is a real number $\sigma$, equal to the
abscissa of integration, and then the integrand is assumed to
be slowly decreasing when the imaginary part of the variable tends to
$\pm\infty$. Or it is a two component vector $[\sigma,\alpha]$, where
$\sigma$ is as before, and either $\alpha=0$ for slowly decreasing functions,
or $\alpha>0$ for functions decreasing like $\exp(-\alpha t)$. Note that it
is not necessary to choose the exact value of $\alpha$. \var{tab} is as in
\kbd{intnum}.

It is often a good idea to use this function with a value of $m$ one or two
higher than the one chosen by default (which can be viewed thanks to the
function \kbd{intnumstep}), or to increase the abscissa of integration
$\sigma$. For example:

\bprog
? \p 105
? intlaplaceinv(x=2, 1, 1/x) - 1
time = 350 ms.
%1 = 7.37... E-55 + 1.72... E-54*I \\@com not so good
? m = intnumstep()
%2 = 7
? intlaplaceinv(x=2, 1, 1/x, m+1) - 1
time = 700 ms.
%3 = 3.95... E-97 + 4.76... E-98*I \\@com better
? intlaplaceinv(x=2, 1, 1/x, m+2) - 1
time = 1400 ms.
%4 = 0.E-105 + 0.E-106*I \\@com perfect but slow.
? intlaplaceinv(x=5, 1, 1/x) - 1
time = 340 ms.
%5 = -5.98... E-85 + 8.08... E-85*I \\@com better than \%1
? intlaplaceinv(x=5, 1, 1/x, m+1) - 1
time = 680 ms.
%6 = -1.09... E-106 + 0.E-104*I \\@com perfect, fast.
? intlaplaceinv(x=10, 1, 1/x) - 1
time = 340 ms.
%7 = -4.36... E-106 + 0.E-102*I \\@com perfect, fastest, but why $sig=10$?
? intlaplaceinv(x=100, 1, 1/x) - 1
time = 330 ms.
%7 = 1.07... E-72 + 3.2... E-72*I \\@com too far now...
@eprog

\synt{intlaplaceinv}{void *E, GEN (*eval)(void*,GEN), GEN sig,GEN z, GEN tab, long prec}.

\subsecidx{intmellininv}$(X=\var{sig},z,\var{expr},\{\var{tab}\})$: \label{se:intmellininv}numerical
integration of $(2i\pi)^{-1}\var{expr}(X)z^{-X}$ with respect to $X$ on the
line $\Re(X)=sig$,  in other words, inverse Mellin transform of
the function corresponding to \var{expr} at the value $z$.

$sig$ is coded as follows. Either it is a real number $\sigma$, equal to the
abscissa of integration, and then the integrated is assumed to decrease
exponentially fast, of the order of $\exp(-t)$ when the imaginary part of the
variable tends to $\pm\infty$. Or it is a two component vector
$[\sigma,\alpha]$, where $\sigma$ is as before, and either $\alpha=0$ for
slowly decreasing functions, or $\alpha>0$ for functions decreasing like
$\exp(-\alpha t)$, such as gamma products. Note that it is not necessary to
choose the exact value of $\alpha$, and that $\alpha=1$ (equivalent to $sig$
alone) is usually sufficient. \var{tab} is as in \kbd{intnum}.

As all similar functions, this function is provided for the convenience of
the user, who could use \kbd{intnum} directly. However it is in general
better to use \kbd{intmellininvshort}.

\bprog
? \p 105
? intmellininv(s=2,4, gamma(s)^3);
time = 1,190 ms. \\@com reasonable.
? \p 308
? intmellininv(s=2,4, gamma(s)^3);
time = 51,300 ms. \\@com slow because of $\Gamma(s)^3$.
@eprog\noindent

\synt{intmellininv}{void *E, GEN (*eval)(void*,GEN), GEN sig, GEN z, GEN tab, long prec}.

\subsecidx{intmellininvshort}$(\var{sig},z,\var{tab})$: \label{se:intmellininvshort}numerical integration
of $(2i\pi)^{-1}s(X)z^{-X}$ with respect to $X$ on the line $\Re(X)=sig$.
In other words, inverse Mellin transform of $s(X)$ at the value $z$.
Here $s(X)$ is implicitly contained in \var{tab} in \kbd{intfuncinit} format,
typically
\bprog
tab = intfuncinit(T = [-1], [1], s(sig + I*T))
@eprog\noindent
or similar commands. Take the example of the inverse Mellin transform of
$\Gamma(s)^3$ given in \kbd{intmellininv}:

\bprog
? \p 105
? oo = [1]; \\@com for clarity
? A = intmellininv(s=2,4, gamma(s)^3);
time = 2,500 ms. \\@com not too fast because of $\Gamma(s)^3$.
\\ @com function of real type, decreasing as $\exp(-3\pi/2\cdot |t|)$
? tab = intfuncinit(t=[-oo, 3*Pi/2],[oo, 3*Pi/2], gamma(2+I*t)^3, 1);
time = 1,370 ms.
? intmellininvshort(2,4, tab) - A
time = 50 ms.
%4 = -1.26... - 3.25...E-109*I \\@com 50 times faster than \kbd{A} and perfect.
? tab2 = intfuncinit(t=-oo, oo, gamma(2+I*t)^3, 1);
? intmellininvshort(2,4, tab2)
%6 = -1.2...E-42 - 3.2...E-109*I  \\@com 63 digits lost
@eprog\noindent
In the computation of \var{tab}, it was not essential to include the
\emph{exact} exponential decrease of $\Gamma(2+it)^3$. But as the last
example shows, a rough indication \emph{must} be given, otherwise slow
decrease is assumed, resulting in catastrophic loss of accuracy.

The library syntax is \fun{GEN}{intmellininvshort}{GEN sig, GEN z, GEN tab, long prec}.

\subsecidx{intnum}$(X=a,b,\var{expr},\{\var{tab}\})$: \label{se:intnum}numerical integration
of \var{expr} on $]a,b[$ with respect to $X$. 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 the single-component vector
$[\pm1]$. You are welcome to set, e.g \kbd{oo = [1]} or \kbd{INFINITY = [1]},
then using \kbd{+oo}, \kbd{-oo}, \kbd{-INFINITY}, etc. will have the expected
behavior.
\bprog
? oo = [1];  \\@com for clarity
? intnum(x = 1,+oo, 1/x^2)
%2 = 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: exponent (expo) overflow
@eprog\noindent
We shall see in a moment how to avoid the last problem, after describing
the last argument \var{tab}, which is both optional and technical. The
routine uses weights, which are mostly independent of the function being
integrated, evaluated at many sampling points. If \var{tab} is

\item a positive integer $m$, we use $2^m$ sampling points, hopefully
increasing accuracy. But note that the running time is roughly proportional
to $2^m$. One may try consecutive values of $m$ until they give the same
value up to an accepted error. If \var{tab} is omitted, the algorithm guesses
a reasonable value for $m$ depending on the current precision only, which
should be sufficient for regular functions. That value may be obtained from
\tet{intnumstep}, and increased in case of difficulties.

\item a set of integration tables as output by \tet{intnuminit},
they are used directly. This is useful if several integrations of the same
type are performed (on the same kind of interval and functions, for a given
accuracy), in particular for multivariate integrals, since we then skip
expensive precomputations.

\misctitle{Specifying the behavior at endpoints}
This is done as follows. An endpoint $a$ is either given as such (a scalar,
real or complex, or $[\pm1]$ 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.999999999999999999990291881
? intnum(x=[0,-1/2], 1, x^(-1/2))  \\@com no, it's not
%2 = 2.000000000000000000000000000
? intnum(x=[0,-1/10], 1, x^(-1/2))
%3 = 1.999999999999999999999946438 \\@com using a wrong exponent is bad
@eprog

If $a$ is $\pm\infty$, which is coded as $[\pm 1]$, the situation is more
complicated, and $[[\pm1],\alpha]$ means:

\item $\alpha=0$ (or no $\alpha$ at all, i.e. simply $[\pm1]$) assumes that the
integrand tends to zero, but not exponentially fast, and not
oscillating such as $\sin(x)/x$.

\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
? oo = [1];
? 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))
%1 = 0.5000000000000000000000000000 \\@com OK!
? intnum(x=0, [+oo, 4], exp(-2*x))
%2 = 0.4999999999999999999961990984 \\@com wrong exponent $\Rightarrow$ imprecise result
? intnum(x=0, [+oo, 20], exp(-2*x))
%2 = 0.4999524997739071283804510227 \\@com disaster
@eprog

\item $\alpha<-1$ assumes that the function tends to $0$ slowly, like
$x^{\alpha}$. Here it is essential to give the correct $\alpha$, if possible,
but on the other hand $\alpha\le -2$ is equivalent to $\alpha=0$, in other
words to no $\alpha$ at all.

\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 $[[\pm1],\alpha]$ and $[[\pm1],k* I]$, but a good rule of thumb is that
if the oscillations are much weaker than the exponential decrease, choose
$[[\pm1],\alpha]$, otherwise choose $[[\pm1],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{intmellininvshort}. On the other hand using the exponential type of
integral, we obtain less accurate results, but we skip expensive
recomputations. See \kbd{intmellininvshort} and \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 $105$
decimal digits. We first type
\bprog
? \p 105
? oo = [1]  \\@com for clarity
@eprog

\misctitle{Apparent singularities} Even if the function $f(x)$ represented
by \var{expr} has no singularities, it may be important to define the
function differently near special points. 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 = 6.00... E-67
@eprog\noindent
thus only correct to $67$ decimal digits. This is because close to $0$ the
function $f$ is computed with an enormous loss of accuracy.
A better solution is

\bprog
? f(x) = 1/(exp(x)-1)-exp(-x)/x
? F = truncate( f(t + O(t^7)) ); \\@com expansion around t = 0
? g(x) = if (x > 1e-18, f(x), subst(F,t,x))  \\@com note that $6 \cdot 18 > 105$
? intnum(x = 0, [oo,1],  g(x)) - Euler
%2 = 0.E-106 \\@com perfect
@eprog\noindent
It is up to the user to determine constants such as the $10^{-18}$ and $7$
used above.

\misctitle{True singularities} With true singularities the result is worse.
For instance

\bprog
? intnum(x = 0, 1,  1/sqrt(x)) - 2
%1 = -1.92... E-59 \\@com only $59$ correct decimals

? intnum(x = [0,-1/2], 1,  1/sqrt(x)) - 2
%2 = 0.E-105 \\@com better
@eprog

\misctitle{Oscillating functions}

\bprog
? intnum(x = 0, oo, sin(x) / x) - Pi/2
%1 = 20.78.. \\@com nonsense
? intnum(x = 0, [oo,1], sin(x)/x) - Pi/2
%2 = 0.004.. \\@com bad
? intnum(x = 0, [oo,-I], sin(x)/x) - Pi/2
%3 = 0.E-105 \\@com perfect
? intnum(x = 0, [oo,-I], sin(2*x)/x) - Pi/2  \\@com oops, wrong $k$
%4 = 0.07...
? intnum(x = 0, [oo,-2*I], sin(2*x)/x) - Pi/2
%5 = 0.E-105 \\@com perfect

? intnum(x = 0, [oo,-I], sin(x)^3/x) - Pi/4
%6 = 0.0092... \\@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
``infinite 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.0004... \\@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 = -2.18... E-106 \\@com OK

? intnum(x = 0, [oo, 1], sin(x)^3*exp(-x)) - 0.3
%3 = 5.45... E-107 \\@com OK
? intnum(x = 0, [oo,-I], sin(x)^3*exp(-x)) - 0.3
%4 = -1.33... E-89 \\@com lost 16 decimals. Try higher $m$:
? m = intnumstep()
%5 = 7 \\@com the value of $m$ actually used above.
? tab = intnuminit(0,[oo,-I], m+1); \\@com try $m$ one higher.
? intnum(x = 0, oo, sin(x)^3*exp(-x), tab) - 0.3
%6 = 5.45... E-107 \\@com OK this time.
@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)
@eprog\noindent
The first \var{tab} is essential, the second optional. Compare:

\bprog
? tab = intnuminit(-1,1);
time = 30 ms.
? intnum(x=-1,1, intnum(y=-sqrt(1-x^2),sqrt(1-x^2), x^2+y^2));
time = 54,410 ms. \\@com slow
? intnum(x=-1,1, intnum(y=-sqrt(1-x^2),sqrt(1-x^2), x^2+y^2, tab), tab);
time = 7,210 ms.  \\@com faster
@eprog\noindent
However, the \kbd{intnuminit} program is usually pessimistic when it comes to
choosing the integration step $2^{-m}$. It is often possible to improve the
speed by trial and error. Continuing the above example:
\bprog
? test(M) =
{
tab = intnuminit(-1,1, M);
intnum(x=-1,1, intnum(y=-sqrt(1-x^2),sqrt(1-x^2), x^2+y^2,tab), tab) - Pi/2
}
? m = intnumstep() \\@com what value of $m$ did it take ?
%1 = 7
? test(m - 1)
time = 1,790 ms.
%2 = -2.05... E-104 \\@com $4 = 2^2$ times faster and still OK.
? test(m - 2)
time = 430 ms.
%3 = -1.11... E-104 \\@com $16 = 2^4$ times faster and still OK.
? test(m - 3)
time = 120 ms.
%3 = -7.23... E-60 \\@com $64 = 2^6$ times faster, lost $45$ decimals.
@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}.

\subsecidx{intnuminit}$(a,b,\{m=0\})$: \label{se:intnuminit}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],[1])} is equivalent to {\tt
intnuminit([-1],[-1,-1/2])}. If $m$ is not given, it is computed according to
the current precision. Otherwise the integration step is $1/2^m$. Reasonable
values of $m$ are $m=6$ or $m=7$ for $100$ decimal digits, and $m=9$ for
$1000$ decimal digits.

The result is technical, but in some cases it is useful to know the output.
Let $x=\phi(t)$ be the change of variable which is used. \var{tab}[1] contains
the integer $m$ as above, either given by the user or computed from the default
precision, and can be recomputed directly using the function \kbd{intnumstep}.
\var{tab}[2] and \var{tab}[3] contain respectively the abscissa and weight
corresponding to $t=0$ ($\phi(0)$ and $\phi'(0)$). \var{tab}[4] and
\var{tab}[5] contain the abscissas and weights corresponding to positive
$t=nh$ for $1\le n\le N$ and $h=1/2^m$ ($\phi(nh)$ and $\phi'(nh)$). Finally
\var{tab}[6] and \var{tab}[7] contain either the abscissas and weights
corresponding to negative $t=nh$ for $-N\le n\le -1$, or may be empty (but
not always) if $\phi(t)$ is an odd function (implicitly we would have
$\var{tab}[6]=-\var{tab}[4]$ and $\var{tab}[7]=\var{tab}[5]$).

The library syntax is \fun{GEN}{intnuminit}{GEN a, GEN b, long m, long prec}.

\subsecidx{intnuminitgen}$(t,a,b,\var{ph},\{m=0\},\{\fl=0\})$: \label{se:intnuminitgen}initialize tables for integrations from $a$ to $b$ using abscissas
$ph(t)$ and weights $ph'(t)$. Note that there is no equal sign after the
variable name $t$ since $t$ always goes from $-\infty$ to $+infty$, but it
is $ph(t)$ which goes from $a$ to $b$, and this is not checked. If \fl = 1
or 2, multiply the reserved table length by $4^{\fl}$, to avoid corresponding
error.

\synt{intnuminitgen}{void *E, GEN (*eval)(void*,GEN), GEN a, GEN b, long m, long flag, long prec}

\subsecidx{intnumromb}$(X=a,b,\var{expr},\{\fl=0\})$: \label{se:intnumromb}numerical integration of
\var{expr} (smooth in $]a,b[$), with respect to $X$. This function is
deprecated, use \tet{intnum} instead.

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. 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 (but continuous) at $a$
or $b$, for example the function $\sin(x)/x$ at $x=0$.

The user should not require too much accuracy: 18 or 28 decimal digits 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 simple 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. This 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 1e1000. However beware of real underflow when dealing with
rapidly decreasing functions. For example, if one wants to compute the
$\int_0^\infty e^{-x^2}\,dx$ to 28 decimal digits, then one should set
infinity equal to 10 for example, and certainly not to 1e1000.

\synt{intnumromb}{void *E, GEN (*eval)(void*,GEN), GEN a, GEN b, long flag, long prec},
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}.

\subsecidx{intnumstep}$()$: \label{se:intnumstep}give the value of $m$ used in all the
\kbd{intnum} and \kbd{sumnum} programs, hence such that the integration
step is equal to $1/2^m$.

The library syntax is \fun{long}{intnumstep}{long prec}.

\subsecidx{prod}$(X=a,b,\var{expr},\{x=1\})$: \label{se:prod}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}.

\subsecidx{prodeuler}$(X=a,b,\var{expr})$: \label{se:prodeuler}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}.

\subsecidx{prodinf}$(X=a,\var{expr},\{\fl=0\})$: \label{se:prodinf}\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$).

\subsecidx{solve}$(X=a,b,\var{expr})$: \label{se:solve}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}.

\subsecidx{sum}$(X=a,b,\var{expr},\{x=0\})$: \label{se:sum}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}.

\subsecidx{sumalt}$(X=a,\var{expr},\{\fl=0\})$: \label{se:sumalt}numerical summation of the series \var{expr}, which should be an
\idx{alternating series}, 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=1$, use a variant with slightly different polynomials. Sometimes
faster.

The routine is heuristic and a rigorous proof assumes that the values of
\var{expr} are the moments of a positive measure on $[0,1]$. 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 <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$).

\subsecidx{sumdiv}$(n,X,\var{expr})$: \label{se:sumdiv}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).
Arithmetic functions like \tet{sigma} use the multiplicativity of the
underlying expression to speed up the computation. Since there is no way to
indicate that \var{expr} is multiplicative in $n$, specialized functions
should always be preferred.
%\syn{NO}

\subsecidx{suminf}$(X=a,\var{expr})$: \label{se:suminf}\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 <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}.

\subsecidx{sumnum}$(X=a,\var{sig},\var{expr},\{\var{tab}\},\{\fl=0\})$: \label{se:sumnum}numerical summation of \var{expr}, the variable $X$ taking integer values
from ceiling of $a$ to $+\infty$, where \var{expr} is assumed to be a
holomorphic function $f(X)$ for $\Re(X)\ge \sigma$.

The parameter $\sigma\in\R$ is coded in the argument \kbd{sig} as follows: it
is either

\item a real number $\sigma$. Then the function $f$ is assumed to
decrease at least as $1/X^2$ at infinity, but not exponentially;

\item a two-component vector $[\sigma,\alpha]$, where $\sigma$ is as
before, $\alpha < -1$. The function $f$ is assumed to decrease like
$X^{\alpha}$. In particular, $\alpha\le-2$ is equivalent to no $\alpha$ at all.

\item a two-component vector $[\sigma,\alpha]$, where $\sigma$ is as
before, $\alpha > 0$. The function $f$ is assumed to decrease like
$\exp(-\alpha X)$. In this case it is essential that $\alpha$ be exactly the
rate of exponential decrease, and it is usually a good idea to increase
the default value of $m$ used for the integration step. In practice, if
the function is exponentially decreasing \kbd{sumnum} is slower and less
accurate than \kbd{sumpos} or \kbd{suminf}, so should not be used.

The function uses the \tet{intnum} routines and integration on the line
$\Re(s) = \sigma$. The optional argument \var{tab} is as in intnum, except it
must be initialized with \kbd{sumnuminit} instead of \kbd{intnuminit}.

When \var{tab} is not precomputed, \kbd{sumnum} can be slower than
\kbd{sumpos}, when the latter is applicable. It is in general faster for
slowly decreasing functions.

Finally, if $\fl$ is nonzero, we assume that the function $f$ to be summed is
of real type, i.e. satisfies $\overline{f(z)}=f(\overline{z})$, which
speeds up the computation.

\bprog
? \p 308
? a = sumpos(n=1, 1/(n^3+n+1));
time = 1,410 ms.
? tab = sumnuminit(2);
time = 1,620 ms. \\@com slower but done once and for all.
? b = sumnum(n=1, 2, 1/(n^3+n+1), tab);
time = 460 ms. \\@com 3 times as fast as \kbd{sumpos}
? a - b
%4 = -1.0... E-306 + 0.E-320*I \\@com perfect.
? sumnum(n=1, 2, 1/(n^3+n+1), tab, 1) - a; \\@com function of real type
time = 240 ms.
%2 = -1.0... E-306 \\@com twice as fast, no imaginary part.
? c = sumnum(n=1, 2, 1/(n^2+1), tab, 1);
time = 170 ms. \\@com fast
? d = sumpos(n=1, 1 / (n^2+1));
time = 2,700 ms. \\@com slow.
? d - c
time = 0 ms.
%5 = 1.97... E-306 \\@com perfect.
@eprog

For slowly decreasing function, we must indicate singularities:
\bprog
? \p 308
? a = sumnum(n=1, 2, n^(-4/3));
time = 9,930 ms. \\@com slow because of the computation of $n^{-4/3}$.
? a - zeta(4/3)
time = 110 ms.
%1 = -2.42... E-107 \\@com lost 200 decimals because of singularity at $\infty$
? b = sumnum(n=1, [2,-4/3], n^(-4/3), /*omitted*/, 1); \\@com of real type
time = 12,210 ms.
? b - zeta(4/3)
%3 = 1.05... E-300 \\@com better
@eprog

Since the \emph{complex} values of the function are used, beware of
determination problems. For instance:
\bprog
? \p 308
? tab = sumnuminit([2,-3/2]);
time = 1,870 ms.
? sumnum(n=1,[2,-3/2], 1/(n*sqrt(n)), tab,1) - zeta(3/2)
time = 690 ms.
%1 = -1.19... E-305 \\@com fast and correct
? sumnum(n=1,[2,-3/2], 1/sqrt(n^3), tab,1) - zeta(3/2)
time = 730 ms.
%2 = -1.55... \\@com nonsense. However
? sumnum(n=1,[2,-3/2], 1/n^(3/2), tab,1) - zeta(3/2)
time = 8,990 ms.
%3 = -1.19... E-305 \\@com perfect, as $1/(n*\sqrt{n})$ above but much slower
@eprog

For exponentially decreasing functions, \kbd{sumnum} is given for
completeness, but one of \tet{suminf} or \tet{sumpos} should always be
preferred. If you experiment with such functions and \kbd{sumnum} anyway,
indicate the exact rate of decrease and increase $m$ by $1$ or $2$:

\bprog
? suminf(n=1, 2^(-n)) - 1
time = 10 ms.
%1 = -1.11... E-308 \\@com fast and perfect
? sumpos(n=1, 2^(-n)) - 1
time = 10 ms.
%2 = -2.78... E-308 \\@com also fast and perfect
? sumnum(n=1,2, 2^(-n)) - 1
%3 = -1.321115060 E320 + 0.E311*I \\@com nonsense
? sumnum(n=1, [2,log(2)], 2^(-n), /*omitted*/, 1) - 1 \\@com of real type
time = 5,860 ms.
%4 = -1.5... E-236 \\@com slow and lost $70$ decimals
? m = intnumstep()
%5 = 9
? sumnum(n=1,[2,log(2)], 2^(-n), m+1, 1) - 1
time = 11,770 ms.
%6 = -1.9... E-305 \\@com now perfect, but slow.
@eprog

\synt{sumnum}{void *E, GEN (*eval)(void*,GEN), GEN a,GEN sig,GEN tab,long flag, long prec}.

\subsecidx{sumnumalt}$(X=a,\var{sig},\var{expr},\{\var{tab}\},\{\fl=0\})$: \label{se:sumnumalt}numerical
summation of $(-1)^X\var{expr}(X)$, the variable $X$ taking integer values from
ceiling of $a$ to $+\infty$, where \var{expr} is assumed to be a holomorphic
function for $\Re(X)\ge sig$ (or $sig[1]$).

\misctitle{Warning} This function uses the \kbd{intnum} routines and is
orders of magnitude slower than \kbd{sumalt}. It is only given for
completeness and should not be used in practice.

\misctitle{Warning 2} The expression \var{expr} must \emph{not} include the
$(-1)^X$ coefficient. Thus $\kbd{sumalt}(n=a,(-1)^nf(n))$ is (approximately)
equal to $\kbd{sumnumalt}(n=a,sig,f(n))$.

$sig$ is coded as in \kbd{sumnum}. However for slowly decreasing functions
(where $sig$ is coded as $[\sigma,\alpha]$ with $\alpha<-1$), it is not
really important to indicate $\alpha$. In fact, as for \kbd{sumalt}, the
program will often give meaningful results (usually analytic continuations)
even for divergent series. On the other hand the exponential decrease must be
indicated.

\var{tab} is as in \kbd{intnum}, but if used must be initialized with
\kbd{sumnuminit}. If $\fl$ is nonzero, assumes that the function $f$ to be
summed is of real type, i.e. satisfies $\overline{f(z)}=f(\overline{z})$, and
then twice faster when \var{tab} is precomputed.

\bprog
? \p 308
? tab = sumnuminit(2, /*omitted*/, -1); \\@com abscissa $\sigma=2$, alternating sums.
time = 1,620 ms. \\@com slow, but done once and for all.
? a = sumnumalt(n=1, 2, 1/(n^3+n+1), tab, 1);
time = 230 ms. \\@com similar speed to \kbd{sumnum}
? b = sumalt(n=1, (-1)^n/(n^3+n+1));
time = 0 ms. \\@com infinitely faster!
? a - b
time = 0 ms.
%1 = -1.66... E-308 \\@com perfect
@eprog

\synt{sumnumalt}{void *E, GEN (*eval)(void*,GEN), GEN a, GEN sig, GEN tab, long flag, long prec}.

\subsecidx{sumnuminit}$(\var{sig}, \{m=0\}, \{\var{sgn}=1\})$: \label{se:sumnuminit}initialize tables for numerical summation using \kbd{sumnum} (with
$\var{sgn}=1$) or \kbd{sumnumalt} (with $\var{sgn}=-1$), $sig$ is the
abscissa of integration coded as in \kbd{sumnum}, and $m$ is as in
\kbd{intnuminit}.

The library syntax is \fun{GEN}{sumnuminit}{GEN sig, long m, long sgn, long prec}.

\subsecidx{sumpos}$(X=a,\var{expr},\{\fl=0\})$: \label{se:sumpos}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 slightly different polynomials. Sometimes faster.

\synt{sumpos}{void *E, GEN (*eval)(void*,GEN),GEN a,long prec}. Also
available is \tet{sumpos2} with the same arguments ($\fl = 1$).
%SECTION: sums

\section{Plotting functions}

  Although plotting is not even a side purpose of PARI, a number of plotting
functions are provided. Moreover, a lot of people
\footnote{*}{Among these, special thanks go to Klaus-Peter Nischke who
suggested the recursive plotting and forking/resizing stuff the graphical
window, and Ilya Zakharevich who rewrote the graphic code from scratch
implementing many new primitives (splines, clipping). Nils Skoruppa and Bill
Allombert wrote the \tet{Qt} and \tet{fltk} graphic drivers respectively.}
suggested ideas or submitted patches for this section of the code. There are
three types of graphic functions.

\subsec{High-level plotting functions} (all the functions starting with
\kbd{ploth}) in which the user has little to do but explain what type of plot
he wants, and whose syntax is similar to the one used in the preceding
section.

\subsec{Low-level plotting functions} (called \var{rectplot} functions,
sharing the prefix \kbd{plot}), where every drawing primitive (point, line,
box, etc.) is specified by the user. These low-level functions work as
follows. You have at your disposal 16 virtual windows which are filled
independently, and can then be physically ORed on a single window at
user-defined positions. These windows are numbered from 0 to 15, and must be
initialized before being used by the function \kbd{plotinit}, which specifies
the height and width of the virtual window (called a \var{rectwindow} in the
sequel). At all times, a virtual cursor (initialized at $[0,0]$) is associated
to the window, and its current value can be obtained using the function
\kbd{plotcursor}.

A number of primitive graphic objects (called \var{rect} objects) can then
be drawn in these windows, using a default color associated to that window
(which can be changed using the \kbd{plotcolor} function) and only the part
of the object which is inside the window will be drawn, with the exception of
polygons and strings which are drawn entirely. The ones sharing the prefix
\kbd{plotr} draw relatively to the current position of the virtual cursor,
the others use absolute coordinates. Those having the prefix \kbd{plotrecth}
put in the rectwindow a large batch of rect objects corresponding to the
output of the related \kbd{ploth} function.

   Finally, the actual physical drawing is done using \kbd{plotdraw}. The
rectwindows are preserved so that further drawings using the same windows at
different positions or different windows can be done without extra work. To
erase a window, use \kbd{plotkill}. It is not possible to partially erase a
window: erase it completely, initialize it again, then fill it with the
graphic objects that you want to keep.

   In addition to initializing the window, you may use a scaled window to
avoid unnecessary conversions. For this, use \kbd{plotscale}. As long as this
function is not called, the scaling is simply the number of pixels, the
origin being at the upper left and the $y$-coordinates going downwards.

   Plotting functions are platform independent, but a number of graphical
drivers are available for screen output: X11-windows (hence also for GUI's
based on X11 such as Openwindows and Motif), and the Qt and FLTK graphical
libraries. The physical window opened by \kbd{plotdraw} or any of the
\kbd{ploth*} functions is completely separated from \kbd{gp} (technically, a
\kbd{fork} is done, and the non-graphical memory is immediately freed in the
child process), which means you can go on working in the current \kbd{gp}
session, without having to kill the window first. This window can be closed,
enlarged or reduced using the standard window manager functions. No zooming
procedure is implemented though (yet).

\subsec{Functions for PostScript output:} in the same way that \kbd{printtex} allows you to have a \TeX\ output
corresponding to printed results, the functions starting with \kbd{ps} allow
you to have \tet{PostScript} output of the plots. This will not be identical
with the screen output, but sufficiently close. Note that you can use
PostScript output even if you do not have the plotting routines enabled. The
PostScript output is written in a file whose name is derived from the
\tet{psfile} default (\kbd{./pari.ps} if you did not tamper with it). Each
time a new PostScript output is asked for, the PostScript output is appended
to that file. Hence you probably want to remove this file, or change the
value of \kbd{psfile}, in between plots. On the other hand, in this manner,
as many plots as desired can be kept in a single file. \smallskip

\subsec{And library mode ?} \emph{None of the graphic functions are available
within the PARI library, you must be under \kbd{gp} to use them}. The reason
for that is that you really should not use PARI for heavy-duty graphical work,
there are better specialized alternatives around. This whole set of routines
was only meant as a convenient, but simple-minded, visual aid. If you really
insist on using these in your program (we warned you), the source
(\kbd{plot*.c}) should be readable enough for you to achieve something.


\subsecidx{plot}$(X=a,b,\var{expr},\{\var{Ymin}\},\{\var{Ymax}\})$: \label{se:plot}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 minima (resp. the maxima) of
the computed values of the expression is used instead.

\subsecidx{plotbox}$(w,\var{x2},\var{y2})$: \label{se:plotbox}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.

\subsecidx{plotclip}$(w)$: \label{se:plotclip}`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.

\subsecidx{plotcolor}$(w,c)$: \label{se:plotcolor}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.

\subsecidx{plotcopy}$(\var{sourcew},\var{destw},\var{dx},\var{dy},\{\fl=0\})$: \label{se:plotcopy}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

\subsecidx{plotcursor}$(w)$: \label{se:plotcursor}give as a 2-component vector the current
(scaled) position of the virtual cursor corresponding to the rectwindow $w$.

\subsecidx{plotdraw}$(\var{list}, \{\fl=0\})$: \label{se:plotdraw}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

\subsecidx{ploth}$(X=a,b,\var{expr},\{\var{flags}=0\},\{n=0\})$: \label{se:ploth}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 15 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$.

\subsecidx{plothraw}$(\var{listx},\var{listy},\{\fl=0\})$: \label{se:plothraw}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}.

\subsecidx{plothsizes}$(\{\fl=0\})$: \label{se:plothsizes}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

\subsecidx{plotinit}$(w,\{x\},\{y\},\{\fl=0\})$: \label{se:plotinit}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

\subsecidx{plotkill}$(w)$: \label{se:plotkill}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.

\subsecidx{plotlines}$(w,X,Y,\{\fl=0\})$: \label{se:plotlines}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.

\subsecidx{plotlinetype}$(w,\var{type})$: \label{se:plotlinetype}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. This is
only taken into account by the \kbd{gnuplot} interface.

\subsecidx{plotmove}$(w,x,y)$: \label{se:plotmove}move the virtual cursor of the rectwindow $w$ to position $(x,y)$.

\subsecidx{plotpoints}$(w,X,Y)$: \label{se:plotpoints}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)$.

\subsecidx{plotpointsize}$(w,\var{size})$: \label{se:plotpointsize}changes the ``size'' of following points in rectwindow $w$. If $w = -1$,
change it in all rectwindows. This only works in the \kbd{gnuplot} interface.

\subsecidx{plotpointtype}$(w,\var{type})$: \label{se:plotpointtype}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. This is only taken into
account by the \kbd{gnuplot} interface.

\subsecidx{plotrbox}$(w,\var{dx},\var{dy})$: \label{se:plotrbox}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.

\subsecidx{plotrecth}$(w,X=a,b,\var{expr},\{\fl=0\},\{n=0\})$: \label{se:plotrecth}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.

\subsecidx{plotrecthraw}$(w,\var{data},\{\var{flags}=0\})$: \label{se:plotrecthraw}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.

\subsecidx{plotrline}$(w,\var{dx},\var{dy})$: \label{se:plotrline}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).

\subsecidx{plotrmove}$(w,\var{dx},\var{dy})$: \label{se:plotrmove}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).

\subsecidx{plotrpoint}$(w,\var{dx},\var{dy})$: \label{se:plotrpoint}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)$.

\subsecidx{plotscale}$(w,\var{x1},\var{x2},\var{y1},\var{y2})$: \label{se:plotscale}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.

\subsecidx{plotstring}$(w,x,\{\var{flags}=0\})$: \label{se:plotstring}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).

\subsecidx{psdraw}$(\var{list}, \{\fl=0\})$: \label{se:psdraw}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

\subsecidx{psploth}$(X=a,b,\var{expr},\{\var{flags}=0\},\{n=0\})$: \label{se:psploth}same as \kbd{ploth}, except that the output is a PostScript program
appended to the \kbd{psfile}.

\subsecidx{psplothraw}$(\var{listx},\var{listy},\{\fl=0\})$: \label{se:psplothraw}same as \kbd{plothraw}, except that the output is a PostScript program
appended to the \kbd{psfile}.
%SECTION: graphic

\section{Programming in GP: control statements}
\sidx{programming}\label{se:programming}

  A number of control statements are available in GP. They are simpler and
have a syntax slightly different from their C counterparts, but are quite
powerful enough to write any kind of program. Some of them are specific to
GP, since they are made for number theorists. As usual, $X$ will denote any
simple variable name, and \var{seq} will always denote a sequence of
expressions, including the empty sequence.

\misctitle{Caveat} In constructs like
\bprog
    for (X = a,b, seq)
@eprog\noindent
the variable \kbd{X} is lexically scoped to the loop, leading to possibly
unexpected behavior:
\bprog
    n = 5;
    for (n = 1, 10,
      if (something_nice(), break);
    );
    \\ @com at this point \kbd{n} is 5 !
@eprog\noindent
If the sequence \kbd{seq} modifies the loop index, then the loop
is modified accordingly:
\bprog
    ? for (n = 1, 10, n += 2; print(n))
    3
    6
    9
    12
@eprog


\subsecidx{break}$(\{n=1\})$: \label{se:break}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.

\subsecidx{for}$(X=a,b,\var{seq})$: \label{se:for}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$.

\subsecidx{fordiv}$(n,X,\var{seq})$: \label{se:fordiv}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

\subsecidx{forell}$(E,a,b,\var{seq})$: \label{se:forell}evaluates \var{seq}, where the formal variable $E$ ranges through all
elliptic curves of conductors from $a$ to $b$. Th \tet{elldata} database must
be installed and contain data for the specified conductors.

\synt{forell}{void *data, long (*call)(void*,GEN), GEN a, GEN b}.

\subsecidx{forprime}$(X=a,b,\var{seq})$: \label{se:forprime}evaluates \var{seq},
where the formal variable $X$ ranges over the prime numbers between $a$ to
$b$ (including $a$ and $b$ if they are prime). More precisely, the value of
$X$ is incremented to the smallest prime strictly larger than $X$ at the end
of each iteration. Nothing is done if $a>b$. Note that $a$ and $b$ must be in
$\R$.

\bprog
f(N) =
{
  forprime(p = 2, N,
    print(p);
    if (p == 3, p = 6);
  )
}
? f(12)
2
3
7
11
@eprog

\subsecidx{forstep}$(X=a,b,s,\var{seq})$: \label{se:forstep}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

\subsecidx{forsubgroup}$(H=G,\{\var{bound}\},\var{seq})$: \label{se:forsubgroup}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),
whose index is bounded by $B$. 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}.

\subsecidx{forvec}$(X=v,\var{seq},\{\fl=0\})$: \label{se:forvec}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$. This routine evaluates \var{seq}, where the formal
variables $X[1],\dots, X[n]$ go from $a_1$ to $b_1$,\dots, from $a_n$ to
$b_n$, i.e.~$X$ goes from $[a_1,\dots,a_n]$ to $[b_1,\dots,b_n]$ with respect
to the lexicographic ordering. (The formal variable with the highest index
moves the fastest.) If $\fl=1$, generate only nondecreasing vectors $X$, and
if $\fl=2$, generate only strictly increasing vectors $X$.

The type of $X$ is the same as the type of $v$: \typ{VEC} or \typ{COL}.

\subsecidx{if}$(a,\{\var{seq1}\},\{\var{seq2}\})$: \label{se:if}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})}.

Note that the boolean operators \kbd{\&\&} and \kbd{||} are evaluated
according to operator precedence as explained in \secref{se:operators}, but
that, 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 (reallydoit && longcomplicatedfunction(), ...)
@eprog
\noindent is a perfectly safe statement.

Recall that 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!).

\subsecidx{next}$(\{n=1\})$: \label{se:next}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.

\subsecidx{return}$(\{x=0\})$: \label{se:return}returns from current subroutine, with
result $x$. If $x$ is omitted, return the \kbd{(void)} value (return no
result, like \kbd{print}).

\subsecidx{until}$(a,\var{seq})$: \label{se:until}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}).

\subsecidx{while}$(a,\var{seq})$: \label{se:while}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.
%SECTION: programming/control

\section{Programming in GP: other specific functions}
\label{se:gp_program}

  In addition to the general PARI functions, it is necessary to have some
functions which will be of use specifically for \kbd{gp}, though a few of these can
be accessed under library mode. Before we start describing these, we recall
the difference between \emph{strings} and \emph{keywords} (see
\secref{se:strings}): the latter don't get expanded at all, and you can type
them without any enclosing quotes. The former are dynamic objects, where
everything outside quotes gets immediately expanded.


\subsecidx{Strprintf}$(\var{fmt},\{x\}*)$: \label{se:Strprintf}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}

\subsecidx{addhelp}$(\var{sym},\var{str})$: \label{se:addhelp}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}. If \kbd{sym}
is a function \emph{you} have defined, its definition will still be printed
before the message \var{str}.  It is recommended that you document global
variables and user functions in this way. Of course \kbd{gp} will not protest
if you skip this.  It is possible to 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 functions 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 to do it!

The library syntax is \fun{void}{addhelp}{const char *sym, const char *str}.

\subsecidx{alarm}$(\{s = 0\})$: \label{se:alarm}trigger an \var{alarmer} exception after $s$ seconds, cancelling any
previously set alarm. Stop a pending alarm if s = 0 or is omitted.

For example, the function \kbd{timefact(N,sec)} below
will try to factor $N$ and give up after \var{sec} seconds,
returning a partial factorisation.

\bprog
default(factor_add_primes,1);
default(primelimit,16777216);
timefact(N,sec)=
{
  trap(alarmer,factor(N,0),alarm(sec);my(F=factor(N));alarm(0);F);
}
@eprog

\subsecidx{alias}$(\var{newsym},\var{sym})$: \label{se:alias}defines the symbol \var{newsym} as an alias for the 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.

The library syntax is \fun{void}{alias0}{const char *newsym, const char *sym}.

\subsecidx{allocatemem}$(\{s=0\})$: \label{se:allocatemem}this very special operation
allows the user to change the stack size \emph{after} initialization. $x$
must be a non-negative integer. If $x \neq 0$, a new stack of size
$16*\ceil{x/16}$ bytes is allocated. If $x=0$, the size of
the new stack is twice the size of the old one. The old stack is discarded.

\misctitle{Warning} This function should be typed at the \kbd{gp} prompt in
interactive usage, or left by itself at the start of batch files.
It 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're 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 technical reason is that this routine 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}.

\subsecidx{apply}$(f, A)$: \label{se:apply}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

\synt{genapply}{void *E, GEN (*fun)(void*,GEN), GEN a}.

\subsecidx{default}$(\{\var{key}\},\{\var{val}\})$: \label{se:default}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}.

The library syntax is \fun{GEN}{default0}{const char *key = NULL, const char *val = NULL}.

\subsecidx{error}$(\{\var{str}\}*)$: \label{se:error}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}

\subsecidx{extern}$(\var{str})$: \label{se:extern}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.

\subsecidx{externstr}$(\var{str})$: \label{se:externstr}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.

\subsecidx{getheap}$()$: \label{se:getheap}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.

The library syntax is \fun{GEN}{getheap}{}.

\subsecidx{getrand}$()$: \label{se:getrand}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}.

The library syntax is \fun{GEN}{getrand}{}.

\subsecidx{getstack}$()$: \label{se:getstack}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.

The library syntax is \fun{long}{getstack}{}.

\subsecidx{gettime}$()$: \label{se:gettime}returns the time (in milliseconds) elapsed since either the last call to
\kbd{gettime}, or to the beginning of the containing GP instruction (if
inside \kbd{gp}), whichever came last.

The library syntax is \fun{long}{gettime}{}.

\subsecidx{global}$(\var{list} \var{of} \var{variables})$: \label{se:global}obsolete. Scheduled for deletion.
% \syn{NO}

\subsecidx{input}$()$: \label{se:input}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).

\subsecidx{install}$(\var{name},\var{code},\{\var{gpname}\},\{\var{lib}\})$: \label{se:install}loads from dynamic library \var{lib} the function \var{name}. Assigns to it
the name \var{gpname} in this \kbd{gp} session, with argument code \var{code}
(see the Libpari Manual for an explanation of those). If \var{lib} is
omitted, uses \kbd{libpari.so}. If \var{gpname} is omitted, uses
\var{name}.

This function is useful for adding custom functions to the \kbd{gp} interpreter,
or picking useful functions from unrelated libraries. For instance, it
makes the function \tet{system} obsolete:

\bprog
? install(system, vs, sys, "libc.so")
? sys("ls gp*")
gp.c            gp.h            gp_rl.c
@eprog

But it also gives you access to all (non static) functions defined in the
PARI library. For instance, the function \kbd{GEN addii(GEN x, GEN y)} 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
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 it the
latter has been recompiled.

\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, i.e.~a major internal
blunder (this should never happen with a dynamically linked executable).
Hence, if you intend to use this function, please check first on some
harmless example such as the ones above that it works properly on your
machine.

\subsecidx{kill}$(\var{sym})$: \label{se:kill}restores the symbol \kbd{sym} to its ``undefined'' status, and deletes any
help messages associated 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 associated 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 associated 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

The library syntax is \fun{void}{kill0}{const char *sym}.

\subsecidx{print}$(\{\var{str}\}*)$: \label{se:print}outputs its (string) arguments in raw format, ending with a newline.
%\syn{NO}

\subsecidx{print1}$(\{\var{str}\}*)$: \label{se:print1}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}

\subsecidx{printf}$(\var{fmt},\{x\}*)$: \label{se:printf}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}

\subsecidx{printtex}$(\{\var{str}\}*)$: \label{se:printtex}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}

\subsecidx{quit}$(\{\var{status} = 0\})$: \label{se:quit}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)}).

\subsecidx{read}$(\{\var{filename}\})$: \label{se:read}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.

\subsecidx{readvec}$(\{\var{filename}\})$: \label{se:readvec}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.

The library syntax is \fun{GEN}{gp_readvec_file}{const char *filename}.
The underlying library function
\fun{GEN}{gp_readvec_stream}{FILE *f} is usually more flexible.

\subsecidx{select}$(f, A)$: \label{se:select}Given a vector, list or matrix \kbd{A} and a \typ{CLOSURE} \kbd{f},
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 following
function lists the elements in $(\Z/N\Z)^*$:
\bprog
? invertibles(N) = select(x->gcd(x,N) == 1, vector(N,i,i))
@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}.

\subsecidx{setrand}$(n)$: \label{se:setrand}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.

The library syntax is \fun{void}{setrand}{GEN n}.

\subsecidx{system}$(\var{str})$: \label{se:system}\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.

\subsecidx{trap}$(\{e\}, \{\var{rec}\}, \var{seq})$: \label{se:trap}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 (gdiver, 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{alarmer}: alarm time-out

\kbd{archer}: not available on this architecture or operating system

\kbd{errpile}: the PARI stack overflows

\kbd{gdiver}: division by 0

\kbd{impl}: not yet implemented

\kbd{invmoder}: impossible inverse modulo

\kbd{overflower}: all forms of arithmetic overflow, including length
or exponent overflow (when a larger value is supplied than the
implementation can handle).

\kbd{syntaxer}: syntax error

\kbd{talker}: miscellaneous error

\kbd{typeer}: wrong type

\kbd{user}: user error (from the \kbd{error} function)

The library syntax is \fun{GEN}{trap0}{const char *e = NULL, GEN rec = NULL, GEN seq = NULL}.

\subsecidx{type}$(x)$: \label{se:type}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}".

The library syntax is \fun{GEN}{type0}{GEN x}.
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.

\subsecidx{version}$()$: \label{se:version}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 a more precise version string, e.g.~\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, 0, "git-2cce227"] \\ development
@eprog

In particular the first line of the gp introductory message can be essentially
emulated by
\bprog
   v = version();
   n = Str(v[1], ".", v[2], ".", v[3]);
   s = if (#v > 3, v[4], "");
   print("GP/PARI CALCULATOR Version ", n, " (", s, ")");
 @eprog\noindent If you \emph{are} working with many development versions of
 PARI/GP, the last component can be profitably included in the name of
 your logfile, for instance.

The library syntax is \fun{GEN}{pari_version}{}.

\subsecidx{warning}$(\{\var{str}\}*)$: \label{se:warning}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}

\subsecidx{whatnow}$(\var{key})$: \label{se:whatnow}if keyword \var{key} is the name of a function that was present in GP
version 1.39.15 or lower, outputs the new function name and syntax, if it
changed at all ($387$ out of $560$ did).

\subsecidx{write}$(\var{filename},\{\var{str}\}*)$: \label{se:write}writes (appends) to \var{filename} the remaining arguments, and appends a
newline (same output as \kbd{print}).
%\syn{NO}

\subsecidx{write1}$(\var{filename},\{\var{str}\}*)$: \label{se:write1}writes (appends) to \var{filename} the remaining arguments without a
trailing newline (same output as \kbd{print1}).
%\syn{NO}

\subsecidx{writebin}$(\var{filename},\{x\})$: \label{se:writebin}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 in a funny way (see
\secref{se:kill}).

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.

User functions, installed functions and history objects can not be saved via
this function. 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).

The library syntax is \fun{void}{gpwritebin}{const char *filename, GEN x = NULL}.

\subsecidx{writetex}$(\var{filename},\{\var{str}\}*)$: \label{se:writetex}as \kbd{write}, in \TeX\ format.
%\syn{NO}
%SECTION: programming/specific

\section{GP defaults}
\label{se:gp_defaults} This section documents the GP defaults


\subsecidx{TeXstyle}: \label{se:def,TeXstyle}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}.

\subsecidx{breakloop}: \label{se:def,breakloop}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.

\subsecidx{colors}: \label{se:def,colors}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 $\bullet$ the keyword \kbd{no} (use the default color, usually
black on transparent background)

\noindent $\bullet$ an integer between 0 and 15 corresponding to the
aforementioned colormap

\noindent $\bullet$ 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).

\subsecidx{compatible}: \label{se:def,compatible}The GP function names and syntax
have changed tremendously between versions 1.xx and 2.00. To help you cope
with this we provide some kind of backward compatibility, depending on the
value of this default:

\quad \kbd{compatible} = 0: no backward compatibility. In this mode, a very
handy function, to be described in \secref{se:whatnow}, is \kbd{whatnow},
which tells you what has become of your favourite functions, which \kbd{gp}
suddenly can't seem to remember.

\quad \kbd{compatible} = 1: warn when using obsolete functions, but
otherwise accept them. The output uses the new conventions though, and
there may be subtle incompatibilities between the behavior of former and
current functions, even when they share the same name (the current function
is used in such cases, of course!). We thought of this one as a transitory
help for \kbd{gp} old-timers. Thus, to encourage switching to \kbd{compatible}=0,
it is not possible to disable the warning.

\quad \kbd{compatible} = 2: use only the old function naming scheme (as
used up to version 1.39.15), but \emph{taking case into account}. Thus
\kbd{I} (${}=\sqrt{-1}$) is not the same as \kbd{i} (user variable, unbound
by default), and you won't get an error message using \kbd{i} as a loop
index as used to be the case.

\quad \kbd{compatible} = 3: try to mimic exactly the former behavior. This
is not always possible when functions have changed in a fundamental way.
But these differences are usually for the better (they were meant to,
anyway), and will probably not be discovered by the casual user.

One adverse side effect is that any user functions and aliases that have
been defined \emph{before} changing \kbd{compatible} will get erased if this
change modifies the function list, i.e.~if you move between groups
$\{0,1\}$ and $\{2,3\}$ (variables are unaffected). We of course strongly
encourage you to try and get used to the setting \kbd{compatible}=0.

Note that the default \tet{new_galois_format} is another compatibility setting,
which is completely independent of \kbd{compatible}.

The default value is \kbd{0}.

\subsecidx{datadir}: \label{se:def,datadir}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 \datadir (the location of installed precomputed data,
can be specified via \kbd{Configure --datadir=}).

\subsecidx{debug}: \label{se:def,debug}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).

\subsecidx{debugfiles}: \label{se:def,debugfiles}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).

\subsecidx{debugmem}: \label{se:def,debugmem}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).

\subsecidx{echo}: \label{se:def,echo}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).

\subsec{factor\_add\_primes}: \kbdsidx{def,factor_add_primes}\label{se:def,factor_add_primes}this toggle is either 1 (on) or 0 (off). If on,
the integer factorization machinery calls \tet{addprimes} on primes
factor 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 defaut value is \kbd{0}.

\subsec{factor\_proven}: \kbdsidx{def,factor_proven}\label{se:def,factor_proven}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 defaut value is \kbd{0}.

\subsecidx{format}: \label{se:def,format}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.

\subsecidx{graphcolormap}: \label{se:def,graphcolormap}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{"antique
white"} represent the same color. RGB codes are a little 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"}].

\subsecidx{graphcolors}: \label{se:def,graphcolors}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]}.

\subsecidx{help}: \label{se:def,help}name of the external help program which will be used 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 local of the \kbd{gphelp} script.

\subsecidx{histfile}: \label{se:def,histfile}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).

\subsecidx{histsize}: \label{se:def,histsize}\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}.

\subsecidx{lines}: \label{se:def,lines}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}.

\subsecidx{log}: \label{se:def,log}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}.

\subsecidx{logfile}: \label{se:def,logfile}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"}.

\subsec{new\_galois\_format}: \kbdsidx{def,new_galois_format}\label{se:def,new_galois_format}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 defaut value is \kbd{0}. This value will change to $1$ (set) in the next
major version.

\subsecidx{output}: \label{se:def,output}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:

$\bullet$ \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.

$\bullet$ \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.

$\bullet$ \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}).

\subsecidx{parisize}: \label{se:def,parisize}\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 strongly recommended you increase this
default (using the \kbd{-s} command-line switch, or a \tet{gprc}) if you can
afford it. Don't increase it beyond the actual amount of RAM installed on
your computer or \kbd{gp} will spend most of its time paging.

In case of emergency, you can use the \tet{allocatemem} function to
increase \kbd{parisize}, once the session is started.

The default value is 4M, resp.~8M on a 32-bit, resp.~64-bit machine.

\subsecidx{path}: \label{se:def,path}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.

\subsecidx{prettyprinter}: \label{se:def,prettyprinter}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"}.

\subsecidx{primelimit}: \label{se:def,primelimit}\kbd{gp} precomputes a list of
all primes less than \kbd{primelimit} at initialization time. These are used
by many arithmetic functions, usually for trial division purposes. If you do
not plan to invoke any of them, you can just set this to 1. The maximal value
is a little less than $2^{32}$ (resp $2^{64}$) on a 32-bit (resp.~64-bit)
machine.

Since almost all arithmetic functions eventually require some table of prime
numbers, PARI currently guarantees that the first 6547 primes, up to and
including 65557, are precomputed, even if \kbd{primelimit} is $1$.

The default value is \kbd{500k}.

\subsecidx{prompt}: \label{se:def,prompt}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{"? "}.

\subsec{prompt\_cont}: \kbdsidx{def,prompt_cont}\label{se:def,prompt_cont}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 defaut value is \kbd{""}.

\subsecidx{psfile}: \label{se:def,psfile}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"}.

\subsecidx{readline}: \label{se:def,readline}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}.

\subsecidx{realprecision}: \label{se:def,realprecision}
\subsecidx{realprecision} : the number of significant digits and, at the same
time, the number of printed digits of real numbers (see~\b{p}). Note that
PARI internal precision works on a word basis (32 or 64 bits), hence may not
coincide with the number of decimal digits you input. For instance to get 2
decimal digits you need one word of precision which, on a 32-bit machine,
actually gives you 9 digits ($9 < \log_{10}(2^{32}) < 10$):

\bprog
? default(realprecision, 2)
      realprecision = 9 significant digits (2 digits displayed)
@eprog

The default value is \kbd{28}, resp.~\kbd{38} on a 32-bit, resp~.64-bit,
machine.

\subsecidx{recover}: \label{se:def,recover}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}.

\subsecidx{secure}: \label{se:def,secure}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}.

\subsecidx{seriesprecision}: \label{se:def,seriesprecision}number of significant terms
when converting a polynomial or rational function to a power series
(see~\b{ps}).

The default value is \kbd{16}.

\subsecidx{simplify}: \label{se:def,simplify}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}.

\subsecidx{strictmatch}: \label{se:def,strictmatch}this toggle is either 1 (on) or 0 (off). If on, unused characters after a
sequence has been
processed will produce an error. Otherwise just a warning is printed. This
can be useful when you are unsure how many parentheses you have to close
after complicated nested loops. Please do not use this; find a decent
text-editor instead.

The default value is \kbd{1}.

\subsecidx{timer}: \label{se:def,timer}this toggle is either 1 (on) or 0 (off). If on, every instruction
sequence (anything ended by a
newline in your input) is timed, to some accuracy depending on the hardware
and operating system. The time measured is the user \idx{CPU time},
\emph{not} including the time for printing the results (see \kbd{\#} and
\kbd{\#\#}).

The default value is \kbd{0}.
%SECTION: default

\vfill\eject