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
|
@comment -*-texinfo-*-
@comment this file contains the type definitions
@c The following directives are necessary for proper compilation
@c with emacs (C-c C-e C-r). Please keep it as it is. Since it
@c is wrapped in `@ignore' and `@end ignore' it does not harm `tex' or
@c `makeinfo' but is a great help in editing this file (emacs
@c ignores the conditionals).
@ignore
%**start
\input texinfo.tex
@setfilename reference.info
@node Top, Data types
@menu
* Data types::
@end menu
@node Data types, Functions and system Variables, General concepts, Top
@chapter Data types
%**end
@end ignore
@cindex expression list
This chapter explains all data types of @sc{Singular} in
alphabetical order. For every type, there is a description of the
declaration syntax as well as information about how to build expressions
of certain types.
The term expression list in @sc{Singular} refers to any comma separated
list of expressions.
For the general syntax of a declaration see @ref{General command syntax}.
@menu
* cring::
* bigint::
* bigintmat::
* bigintvec::
* def::
* ideal::
* int::
* intmat::
* intvec::
* link::
* list::
* map::
* matrix::
* module::
* number::
* package::
* poly::
* proc::
* resolution::
* ring::
* smatrix::
* string::
* vector::
* User defined types::
* cone::
* fan::
* polytope::
* pyobject::
* countedref::
@end menu
@c ---------------------------------------
@node cring, bigint, Data types, Data types
@section cring
@cindex cring
Variables of type cring represent the ring of coefficients (see @ref{number})
@menu
* cring declarations::
* cring expressions::
* cring operations::
* cring related functions::
@end menu
@c ---------------------------------------
@node cring declarations, cring expressions, cring, cring
@subsection cring declarations
@cindex cring declarations
@table @strong
@item Syntax:
@code{cring} name @code{=} cring_expression @code{;}
@item Purpose:
defines a new coefficient ring resp. field
to be used for a ring definition (see @ref{ring}).
Most objects of this type are predefined.
@item Default:
none
@item Example:
@smallexample
@c example
ZZ;
ZZ/3;
@c example
@end smallexample
@end table
@c ------------------------------
@node cring expressions, cring operations, cring declarations, cring
@subsection cring expressions
@cindex cring expressions
@cindex QQ
@cindex ZZ
A cring expression is:
@enumerate
@item
an identifier of type cring:
@itemize
@item QQ - the rational numbers
@item ZZ - the integers
@end itemize
@item
a function returning cring
@item
an expression involving crings and the arithmetic operations
@code{/}.
@end enumerate
@*@strong{Example:}
@smallexample
@c example
ZZ/3;
@c example
@end smallexample
@c ref
See
@ref{ring}.
@c ref
@c ------------------------------
@node cring operations, cring related functions, cring expressions, cring
@subsection cring operations
@cindex cring operations
@cindex /
@c remark: the following table should have style @asis, since the
@c commas below should not by set in style @code.
@table @asis
@item @code{/}
residue class ring
@end table
@*@strong{Example:}
@smallexample
@c example
ZZ/101;
@c example
@end smallexample
@c ------------------------------
@node cring related functions, ,cring operations, cring
@subsection cring related functions
@cindex cring related functions
@table @code
@item crossprod
crooss product of several objects of type cring (see @ref{crossprod})
@item Float
several variants of Floating point (inexact) real and complex numbers
(see @ref{Float}).
@item flintQ
multivariate rational functions over Q (via flint, requires >=2.5.3)
(see @ref{flintQ}).
@end table
@c ref
See
@ref{crossprod};
@ref{flintQ};
@ref{Float}.
@c ref
@c ---------------------------------------
@node bigint, bigintmat, cring, Data types
@section bigint
@cindex bigint
Variables of type bigint represent the arbitrary long integers.
They can only be constructed from other types (int, number).
@menu
* bigint declarations::
* bigint expressions::
* bigint operations::
* bigint related functions::
@end menu
@c ---------------------------------------
@node bigint declarations, bigint expressions, bigint, bigint
@subsection bigint declarations
@cindex bigint declarations
@table @strong
@item Syntax:
@code{bigint} name @code{=} int_expression @code{;}
@item Purpose:
defines a long integer variable
@item Default:
0
@item Example:
@smallexample
@c example
bigint i = 42;
ring r=0,x,dp;
number n=2;
bigint j = i + bigint(n)^50; j;
@c example
@end smallexample
@end table
@c ------------------------------
@node bigint expressions, bigint operations, bigint declarations, bigint
@subsection bigint expressions
@cindex bigint expressions
A bigint expression is:
@enumerate
@item
an identifier of type bigint
@item
a function returning bigint
@item
an expression involving bigints and the arithmetic operations
@code{+}, @code{-}, @code{*}, @code{div},
@code{%} (@code{mod}), or @code{^}
@item
a type cast to bigint.
@end enumerate
@*@strong{Example:}
@smallexample
@c example
// Note: 11*13*17*100*200*2000*503*1111*222222
// returns a machine integer:
11*13*17*100*200*2000*503*1111*222222;
// using the type cast number for a greater allowed range
bigint(11)*13*17*100*200*2000*503*1111*222222;
@c example
@end smallexample
@c ref
See
@ref{int};
@ref{number};
@ref{Type conversion and casting}.
@c ref
@c ------------------------------
@node bigint operations, bigint related functions, bigint expressions, bigint
@subsection bigint operations
@cindex bigint operations
@cindex mod
@cindex div
@cindex +
@cindex -
@cindex *
@cindex ^
@cindex %
@c remark: the following table should have style @asis, since the
@c commas below should not by set in style @code.
@table @asis
@item @code{+}
addition
@item @code{-}
negation or subtraction
@item @code{*}
multiplication
@item @code{div}
integer division (omitting the remainder >= 0)
@item @code{mod}, @code{%}
integer modulo (the remainder of the division @code{div})
@item @code{^}, @code{**}
exponentiation (exponent must be non-negative)
@item @code{<}, @code{>}, @code{<=}, @code{>=}, @code{==}, @code{<>}
comparators
@end table
@*@strong{Example:}
@smallexample
@c example
bigint(5)*2, bigint(2)^100-10;
bigint(-5) div 2, bigint(-5) mod 2;
@c example
@end smallexample
@c ------------------------------
@node bigint related functions, ,bigint operations, bigint
@subsection bigint related functions
@cindex bigint related functions
@table @code
@item gcd
greatest common divisor (see @ref{gcd})
@item memory
memory usage (see @ref{memory})
@end table
@c ref
See
@ref{memory};
@c ref
@c ---------------------------------------
@node bigintmat, bigintvec, bigint, Data types
@section bigintmat
@cindex bigintmat
Big integer matrices are matrices with big integer entries.
No basering definition is required to use bigint matrices, for they
do not belong to a ring. Bigintmat entries can have any size because
of the use of bigint.
@menu
* bigintmat declarations::
* bigintmat expressions::
* bigintmat type cast::
* bigintmat operations::
@end menu
@c ------------------------------
@node bigintmat declarations, bigintmat expressions, bigintmat, bigintmat
@subsection bigintmat declarations
@cindex bigintmat declarations
@table @strong
@item Syntax:
@code{bigintmat} name @code{=} bigintmat_expression @code{;}
@*@code{bigintmat} name @code{[} rows @code{] [} cols @code{] =} bigintmat_expression @code{;}
@*@code{bigintmat} name @code{[} rows @code{] [} cols @code{] =} list_of_int_and_bigint expressions @code{;}
@*rows and cols must be positive int expressions.
@item Purpose:
defines a bigintmat variable.
@* Given a list of (big) integers, the matrix is filled
up with the first row from the left to the right, then the second
one and so on. If the (big-)int_list contains less than rows*cols
elements, the remaining ones are set to zero; if it contains
more elements, only the first rows*cols ones are considered.
@item Default:
empty (1x0 matrix)
@item Example:
@smallexample
@c example
bigintmat bim[4][3]=2, 5, 224553233465, 232444, 434, 0, 0, 4544232222;
bim;
bim[2, 1];
@c example
@end smallexample
@end table
@c ------------------------------
@node bigintmat expressions, bigintmat type cast, bigintmat declarations, bigintmat
@subsection bigintmat expressions
@cindex bigintmat expressions
A bigintmat expression is:
@enumerate
@item
an identifier of type bigintmat
@item
a function returning bigintmat
@item
a bigintmat operation involving (big-)ints and int operations (@code{+}, @code{-}, @code{*})
@item
an expression involving bigintmats and the operations (@code{+}, @code{-}, @code{*})
@item
a type cast to bigintmat (@pxref{bigintmat type cast})
@end enumerate
@*@strong{Example:}
@smallexample
@c example
bigintmat m1[2][2]=1, 2, 6, 3;
m1*3;
intmat im[3][2] = intmat(m1*3);
bigintmat m2 = bigintmat(im); // cast intmat im to bigintmat
m2;
m2*m1+m2;
_+4;
@c example
@end smallexample
@c ref
See
@ref{bigintmat};
@ref{Type conversion and casting}.
@c ref
@c ------------------------------
@node bigintmat type cast, bigintmat operations, bigintmat expressions, bigintmat
@subsection bigintmat type cast
@cindex bigintmat type cast
@table @code
@item @strong{Syntax:}
@code{bigintmat (} expression @code{)}
@item @strong{Type:}
bigintmat
@item @strong{Purpose:}
Converts expression to a bigintmat, where expression must be of type
intmat, bigintvec, or bigintmat.The size (resp.@: dimension) of the
created bigintmat equals the size (resp.@: dimension) of the expression.
@item @strong{Example:}
@smallexample
@c example
intmat im[2][1]=2, 3;
bigintmat(im);
bigintmat(_);
bigintmat(intmat(intvec(1,2,3,4), 2, 2)); //casts at first to intmat, then to bigintmat
@c example
@end smallexample
@end table
@c ref
See
@ref{bigintmat};
@ref{Type conversion and casting};
@ref{intmat type cast}.
@c ref
@c ------------------------------
@node bigintmat operations,, bigintmat type cast, bigintmat
@subsection bigintmat operations
@cindex bigintmat operations
@cindex +
@cindex -
@cindex *
@table @asis
@item @code{+}
addition with intmat, int, or bigint. In case of (big-)int, it is added to
every entry of the matrix.
@item @code{-}
negation or subtraction with intmat, int, or bigint. In case of (big-)int,
it is subtracted from every entry of the matrix.
@item @code{*}
multiplication with intmat, int, or bigint; In case of (big-)int, every entry
of the matrix is multiplied by the (big-)int
@item @code{<>}, @code{==}
comparators
@item bigintmat_expression @code{[} int@code{,} int @code{]}
is a bigintmat entry, where the first index indicates the row and the
second the column
@end table
@*@strong{Example:}
@smallexample
@c example error
bigintmat m[3][4] = 3,3,6,3,5,2,2,7,0,0,45,3;
m;
m[1,3]; // show entry at [row 1, col 3]
m[1,3] = 10; // set entry at [row 1, col 3] to 10
m;
size(m); // number of entries
bigintmat n[2][3] = 2,6,0,4,0,5;
n * m;
typeof(_);
-m;
bigintmat o;
o=n-10;
o;
m*2; // double each entry of m
o-2*m;
@c example
@end smallexample
@c ---------------------------------------
@node bigintvec, def, bigintmat, Data types
@section bigintvec
@cindex bigintvec
Big integer vectors are vectors with big integer entries.
No basering definition is required to use bigint vectors, for they
do not belong to a ring. Bigintvec entries can have any size because
of the use of bigint.
@menu
* bigintvec declarations::
* bigintvec expressions::
* bigintvec type cast::
* bigintvec operations::
@end menu
@c ------------------------------
@node bigintvec declarations, bigintvec expressions, bigintvec, bigintvec
@subsection bigintvec declarations
@cindex bigintvec declarations
@table @strong
@item Syntax:
@code{bigintvec} name @code{=} bigintvec_expression @code{;}
@*@code{bigintvec} name @code{] =} list_of_int_and_bigint expressions @code{;}
@item Purpose:
defines a bigintvec variable.
@item Default:
empty
@item Example:
@smallexample
@c example
bigintvec v=2, 5, 224553233465, 232444, 434, 0, 0, 4544232222;
v;
v[2];
@c example
@end smallexample
@end table
@c ------------------------------
@node bigintvec expressions, bigintvec type cast, bigintvec declarations, bigintvec
@subsection bigintvec expressions
@cindex bigintvec expressions
A bigintvec expression is:
@enumerate
@item
an identifier of type bigintvec
@item
a function returning bigintvec
@item
a type cast to bigintvec (@pxref{bigintvec type cast})
@end enumerate
@*@strong{Example:}
@smallexample
@c example
bigintmat m1[2][2]=1, 2, 6, 3;
bigintvec v=m1[1,1..2];
v;
@c example
@end smallexample
@c ref
See
@ref{bigintvec};
@ref{Type conversion and casting}.
@c ref
@c ------------------------------
@node bigintvec type cast, bigintvec operations, bigintvec expressions, bigintvec
@subsection bigintvec type cast
@cindex bigintvec type cast
@table @code
@item @strong{Syntax:}
@code{bigintvec (} expression @code{)}
@item @strong{Type:}
bigintvec
@item @strong{Purpose:}
Converts expression to a bigintvec, where expression must be of type
intvec, or bigintmat.The size of the created bigintvec
equals the size of the expression.
@item @strong{Example:}
@smallexample
@c example
// TODO
@c example
@end smallexample
@end table
@c ref
See
@ref{bigintvec};
@ref{Type conversion and casting}.
@c ref
@c ------------------------------
@node bigintvec operations,, bigintvec type cast, bigintvec
@subsection bigintvec operations
@cindex bigintvec operations
@cindex +
@cindex -
@cindex *
@table @asis
@item @code{+}
addition with intvec, int, or bigint. In case of (big-)int, it is added to
every entry of the vector.
@item @code{-}
negation or subtraction with intvec, int, or bigint. In case of (big-)int,
it is subtracted from every entry of the matrix.
@item @code{*}
multiplication with int, or bigint; every entry
of the vector is multiplied by the (big-)int
@item @code{<>}, @code{==}
comparators
@item bigintvec_expression @code{[} int @code{]}
is a bigintvec entry.
@end table
@*@strong{Example:}
@smallexample
@c example error
bigintvec v = 3,3,6,3,5,2,2,7,0,0,45,3;
v;
v[3]; // show entry at [3]
v[3] = 10; // set entry at [3] to 10
v;
size(v); // number of entries
-v;
v-10;
v*2; // double each entry of v
@c example
@end smallexample
@c ---------------------------------------
@node def, ideal, bigintvec, Data types
@section def
@cindex def
@cindex untyped definitions
@cindex basering
Objects may be defined without a specific type: they inherit their
type from the first assignment to them.
E.g., @code{ideal i=x,y,z; def j=i^2;} defines the ideal @code{i^2}
with the name @code{j}.
@strong{Note:} Unlike other assignments a ring as an untyped object
is not a copy but another reference to the same (possibly unnamed) ring.
This means that entries in one of these rings appear also in the other ones.
The following defines a ring @code{s} which is just another reference (or name)
for the basering @code{r}.
The name @code{basering} is an alias for the current ring.
@smallexample
@c example
ring r=32003,(x,y,z),dp;
poly f = x;
def s=basering;
setring s;
nameof(basering);
listvar();
poly g = y;
kill f;
listvar(r);
ring t=32003,(u,w),dp;
def rt=r+t;
rt;
@c example
@end smallexample
This reference to a ring with def is useful if the basering
is not local to the procedure (so it cannot be accessed by its name) but one
needs a name for it (e.g., for a use with @code{setring} or @code{map}).
@code{setring r;} does not work in this case, because
@code{r} may not be local to the procedure.
@menu
* def declarations::
@end menu
@c ------------------------------
@node def declarations, , def, def
@subsection def declarations
@cindex def declarations
@table @strong
@item Syntax:
@code{def} name @code{=} expression @code{;}
@item Purpose:
defines an object of the same type as the right-hand side.
@item Default:
none
@item Note:
This is useful if the right-hand side may be of
variable type as a consequence of a computation (e.g., ideal or module or
matrix). It may also be used in procedures to give the basering a name which
is local to the procedure.
@item Example:
@smallexample
@c example
def i=2;
typeof(i);
@c example
@end smallexample
@end table
@c ref
See
@ref{typeof}.
@c ref
@c ---------------------------------------
@node ideal, int, def, Data types
@section ideal
@cindex ideal
Ideals are represented as lists of polynomials which generate the ideal.
Like polynomials they
can only be defined or accessed with respect to a basering.
@strong{Note:} @code{size} counts only the non-zero generators of an ideal
whereas @code{ncols} counts all generators; see @ref{size}, @ref{ncols}.
@menu
* ideal declarations::
* ideal expressions::
* ideal operations::
* ideal related functions::
@end menu
@c ---------------------------------------
@node ideal declarations, ideal expressions, ideal, ideal
@subsection ideal declarations
@cindex ideal declarations
@table @strong
@item Syntax:
@code{ideal} name @code{=} list_of_poly_and_ideal_expressions @code{;}
@*@code{ideal} name @code{=} ideal_expression @code{;}
@item Purpose:
defines an ideal.
@item Default:
0
@item Example:
@smallexample
@c example
ring r=0,(x,y,z),dp;
poly s1 = x2;
poly s2 = y3;
poly s3 = z;
ideal i = s1, s2-s1, 0,s2*s3, s3^4;
i;
size(i);
ncols(i);
@c example
@end smallexample
@end table
@c ------------------------------
@node ideal expressions, ideal operations, ideal declarations, ideal
@subsection ideal expressions
@cindex ideal expressions
An ideal expression is:
@enumerate
@item
an identifier of type ideal
@item
a function returning an ideal
@item
a combination of ideal expressions by the arithmetic operations
@code{+} or @code{*}
@item
a power of an ideal expression (operator @code{^} or @code{**})
@*Note that the computation of the product @code{i*i} involves
all products of generators of @code{i} while @code{i^2} involves
only the different ones, and is therefore faster.
@item
a type cast to ideal
@end enumerate
@*@strong{Example:}
@smallexample
@c example
ring r=0,(x,y,z),dp;
ideal m = maxideal(1);
m;
poly f = x2;
poly g = y3;
ideal i = x*y*z , f-g, g*(x-y) + f^4 ,0, 2x-z2y;
ideal M = i + maxideal(10);
timer =0;
i = M*M;
timer;
ncols(i);
timer =0;
i = M^2;
ncols(i);
timer;
i[ncols(i)];
vector v = [x,y-z,x2,y-x,x2yz2-y];
ideal j = ideal(v);
@c example
@end smallexample
@c ------------------------------
@node ideal operations, ideal related functions, ideal expressions, ideal
@subsection ideal operations
@cindex ideal operations
@cindex +
@cindex *
@cindex ^
@table @asis
@item @code{+}
addition (concatenation of the generators and simplification)
@item @code{*}
multiplication (with ideal, poly, vector, module; simplification in case of
multiplication with ideal)
@item @code{^}
exponentiation (by a non-negative integer)
@item ideal_expression @code{[} intvec_expression @code{]}
are polynomial generators of the ideal, index 1 gives the first generator.
@end table
@strong{Note:} For simplification of an ideal, see also @ref{simplify}.
@*@strong{Example:}
@smallexample
@c example
ring r=0,(x,y,z),dp;
ideal I = 0,x,0,1;
I;
I + 0; // simplification
ideal J = I,0,x,x-z;;
J;
I * J; // multiplication with simplification
I*x;
vector V = [x,y,z];
print(V*I);
ideal m = maxideal(1);
m^2;
ideal II = I[2..4];
II;
@c example
@end smallexample
@c ------------------------------
@node ideal related functions, , ideal operations, ideal
@subsection ideal related functions
@cindex ideal related functions
@table @code
@item char_series
irreducible characteristic series (see @ref{char_series})
@item coeffs
matrix of coefficients (see @ref{coeffs})
@item contract
contraction by an ideal (see @ref{contract})
@item diff
partial derivative (see @ref{diff})
@item degree
multiplicity, dimension and codimension of the ideal of leading terms (see @ref{degree})
@item dim
Krull dimension of basering modulo the ideal of leading terms (see @ref{dim})
@item eliminate
elimination of variables (see @ref{eliminate})
@item facstd
factorizing Groebner basis algorithm (see @ref{facstd})
@item factorize
ideal of factors of a polynomial (see @ref{factorize})
@item fglm
Groebner basis computation from a Groebner basis w.r.t.@: a different
ordering (see @ref{fglm})
@item finduni
computation of univariate polynomials lying in a zero dimensional ideal
(see @ref{finduni})
@item fres
free resolution of a standard basis (see @ref{fres})
@item groebner
Groebner basis computation (a wrapper around @code{std,stdhilb,stdfglm},...)
(see @ref{groebner})
@item highcorner
the smallest monomial not contained in the ideal.
The ideal has to be zero-dimensional.
(see @ref{highcorner})
@item homog
homogenization with respect to a variable (see @ref{homog})
@item hilb
Hilbert series of a standard basis (see @ref{hilb})
@item indepSet
sets of independent variables of an ideal (see @ref{indepSet})
@item interred
interreduction of an ideal (see @ref{interred})
@item intersect
ideal intersection (see @ref{intersect})
@item jacob
ideal of all partial derivatives resp.@: jacobian matrix (see @ref{jacob})
@item jet
Taylor series up to a given order (see @ref{jet})
@item kbase
vector space basis of basering modulo ideal of leading terms
(see @ref{kbase})
@item koszul
Koszul matrix (see @ref{koszul})
@item lead
leading terms of a set of generators (see @ref{lead})
@item lift
lift-matrix (see @ref{lift})
@item liftstd
standard basis and transformation matrix computation (see @ref{liftstd})
@item lres
free resolution for homogeneous ideals (see @ref{lres})
@item maxideal
power of the maximal ideal at 0 (see @ref{maxideal})
@item minbase
minimal generating set of a homogeneous ideal, resp.@: module, or an ideal, resp.@: module, in a local ring
(see @ref{minbase})
@item minor
set of minors of a matrix (see @ref{minor})
@item modulo
representation of
@tex
$(h1+h2)/h1 \cong h2/(h1 \cap h2)$
@end tex
@ifinfo
(h1+h2)/h1=h2/(h1 intersect h2)
@end ifinfo
(see @ref{modulo})
@item mres
minimal free resolution of an ideal resp.@: module w.r.t. a minimal set of generators of the given ideal resp.@: module
(see @ref{mres})
@item mstd
standard basis and minimal generating set of an ideal (see @ref{mstd})
@item mult
multiplicity, resp.@: degree, of the ideal of leading terms (see @ref{mult})
@item ncols
number of columns (see @ref{ncols})
@item nres
a free resolution of an ideal resp.@: module M which is
minimized from the second free module on (see @ref{nres})
@item preimage
preimage under a ring map (see @ref{preimage})
@item qhweight
quasihomogeneous weights of an ideal (see @ref{qhweight})
@item quotient
ideal quotient (see @ref{quotient})
@item reduce
normalform with respect to a standard basis (see @ref{reduce})
@item res
free resolution of an ideal resp.@: module but not changing the given ideal resp.@: module
(see @ref{res})
@item simplify
simplification of a set of polynomials (see @ref{simplify})
@item size
number of non-zero generators (see @ref{size})
@item slimgb
Groebner basis computation with slim technique (see @ref{slimgb})
@item sortvec
permutation for sorting ideals resp@:. modules (see @ref{sortvec})
@item sres
free resolution of a standard basis (see @ref{sres})
@item std
standard basis computation (see @ref{std})
@item stdfglm
standard basis computation with fglm technique (see @ref{stdfglm})
@item stdhilb
Hilbert driven standard basis computation (see @ref{stdhilb})
@item subst
substitution of a ring variable (see @ref{subst})
@item syz
computation of the first syzygy module (see @ref{syz})
@item vdim
vector space dimension of basering modulo ideal of leading terms
(see @ref{vdim})
@item weight
optimal weights (see @ref{weight})
@end table
@c ---------------------------------------
@node int, intmat, ideal, Data types
@section int
@cindex int
Variables of type int represent the machine integers and are, therefore,
limited in their range (e.g., the range is between
-2147483647 and 2147483647 on 32-bit machines). They are mainly used
to count things (dimension, rank, etc.),
in loops (see @ref{for}), and
to represent boolean values
(FALSE is represented by 0, every other value means TRUE, see
@ref{boolean expressions}).
Integers consist of a sequence of digits, possibly preceded by a sign.
A space is considered as a separator, so it is not allowed between digits.
A sequence of digits outside the allowed range is converted to the type
@code{bigint}, see @ref{bigint}.
@menu
* int declarations::
* int expressions::
* int operations::
* boolean expressions::
* boolean operations::
* int related functions::
@end menu
@c ---------------------------------------
@node int declarations, int expressions, int, int
@subsection int declarations
@cindex int declarations
@table @strong
@item Syntax:
@code{int} name @code{=} int_expression @code{;}
@item Purpose:
defines an integer variable.
@item Default:
0
@item Example:
@smallexample
@c example
int i = 42;
int j = i + 3; j;
i = i * 3 - j; i;
int k; // assigning the default value 0 to k
k;
@c example
@end smallexample
@end table
@c ------------------------------
@node int expressions, int operations, int declarations, int
@subsection int expressions
@cindex int expressions
An int expression is:
@enumerate
@item
a sequence of digits (if the number represented by this sequence is too
large to fit into the range of integers it is automatically
converted to the type number, if a basering is defined)
@item
an identifier of type int
@item
a function returning int
@item
an expression involving ints and the arithmetic operations
@code{+}, @code{-}, @code{*}, @code{div} (@code{/}),
@code{%} (@code{mod}), or @code{^}
@item a boolean expression
@item
a type cast to int
@end enumerate
@strong{Note:}
Variables of type int represent the compiler integers and are, therefore,
limited in their range (see @ref{Limitations}). If this range is too small
the expression must be converted to the type number over a ring with
characteristic 0.
@*@strong{Example:}
@smallexample
@c example error
12345678901; // too large
typeof(_);
ring r=0,x,dp;
12345678901;
typeof(_);
// Note: 11*13*17*100*200*2000*503*1111*222222
// returns a machine integer:
11*13*17*100*200*2000*503*1111*222222;
// using the type cast number for a greater allowed range
number(11)*13*17*100*200*2000*503*1111*222222;
ring rp=32003,x,dp;
12345678901;
typeof(_);
intmat m[2][2] = 1,2,3,4;
m;
m[2,2];
typeof(_);
det(m);
m[1,1] + m[2,1] == trace(m);
! 0;
1 and 2;
intvec v = 1,2,3;
def d =transpose(v)*v; // scalarproduct gives an 1x1 intvec
typeof(d);
int i = d[1]; // access the first (the only) entry in the intvec
ring rr=31,(x,y,z),dp;
poly f = 1;
i = int(f); // cast to int
// Integers may be converted to constant polynomials by an assignment,
poly g=37;
// define the constant polynomial g equal to the image of
// the integer 37 in the actual coefficient field, here it equals 6
g;
@c example
@end smallexample
@c ref
See
@ref{number};
@ref{Type conversion and casting}.
@c ref
@c ------------------------------
@node int operations, int related functions, int expressions, int
@subsection int operations
@cindex int operations
@cindex mod
@cindex div
@cindex +
@cindex -
@cindex *
@cindex %
@c remark: the following table should have style @asis, since the
@c commas below should not by set in style @code.
@table @asis
@item @code{++}
changes its operand to its successor, is itself no int expression
@item @code{--}
changes its operand to its predecessor, is itself no int expression
@item @code{+}
addition
@item @code{-}
negation or subtraction
@item @code{*}
multiplication
@item @code{div}
integer division (omitting the remainder), rounding toward 0
@item @code{%}, @code{mod}
integer modulo (the remainder of the division
@item @code{^}, @code{**}
exponentiation (exponent must be non-negative)
@item @code{<}, @code{>}, @code{<=}, @code{>=}, @code{==}, @code{<>}
comparators
@end table
@strong{Note:} An assignment @code{j=i++;} or @code{j=i--;} is not allowed,
in particular it does not change
the value of @code{j}, see @ref{Limitations}.
@*@strong{Example:}
@smallexample
@c example error
int i=1;
int j;
i++; i; i--; i;
// ++ and -- do not return a value as in C, cannot assign
j = i++;
// the value of j is unchanged
j; i;
i+2, 2-i, 5^2;
5 div 2, 8%3;
-5 div 2, -5 mod 2, -5 % 2;
1<2, 2<=2;
@c example
@end smallexample
@c ------------------------------
@node int related functions, boolean expressions,int operations, int
@subsection int related functions
@cindex int related functions
@table @code
@item char
characteristic of the coefficient field of a ring (see @ref{char})
@item deg
degree of a polynomial resp.@: vector (see @ref{deg})
@item det
determinant (see @ref{det})
@item dim
Krull dimension of basering modulo ideal of leading terms, resp.@:
dimension of module of leading terms (see @ref{dim})
@item extgcd
Bezout representation of gcd (see @ref{extgcd})
@item find
position of a substring in a string (see @ref{find})
@item gcd
greatest common divisor (see @ref{gcd})
@item koszul
Koszul matrix (see @ref{koszul})
@item memory
memory usage (see @ref{memory})
@item mult
multiplicity of an ideal, resp.@: module, of leading terms (see @ref{mult})
@item ncols
number of columns (see @ref{ncols})
@item npars
number of ring parameters (see @ref{npars})
@item nrows
number of rows of a matrix, resp.@:
the rank of the free module where the vector or module lives
(see @ref{nrows})
@item nvars
number of ring variables (see @ref{nvars})
@item ord
degree of the leading term of a polynomial resp.@: vector (see @ref{ord})
@item par
n-th parameter of the basering (see @ref{par})
@item pardeg
degree of a number considered as a polynomial in the ring parameters (see @ref{pardeg})
@item prime
the next lower prime (see @ref{prime})
@item random
a pseudo random integer between the given limits (see @ref{random})
@item regularity
regularity of a resolution (see @ref{regularity})
@item rvar
test, if the given expression or string is a ring variable (see @ref{rvar})
@item size
number of elements in an object (see @ref{size})
@item trace
trace of an integer matrix (see @ref{trace})
@item var
n-th ring variable of the basering (see @ref{var})
@item vdim
vector space dimension of basering modulo ideal of leading terms,
resp.@: of freemodule modulo module of leading terms (see @ref{vdim})
@end table
@c ------------------------------
@node boolean expressions, boolean operations, int related functions, int
@subsection boolean expressions
@cindex boolean expressions
@cindex ==
@cindex !=
@cindex <>
@cindex <=
@cindex >=
A boolean expression is an int expression used in a logical context:
@c item
@*An int expression <> 0 evaluates to @emph{TRUE} (represented by 1),
0 evaluates to @emph{FALSE} (represented by 0).
The following is the list of available comparisons of objects of the same type.
@strong{Note:} There are no comparisons for ideals and modules, resolutions
and maps.
@enumerate
@item
integer comparisons:
@smallexample
i == j
i != j // or i <> j
i <= j
i >= j
i > j
i < j
@end smallexample
@item
number comparisons:
@smallexample
m == n
m != n // or m <> n
m < n
m > n
m <= n
m >= n
@end smallexample
For numbers from Z/p or from field extensions not all operations are useful:
@* - 0 is always the smallest element,
@* - in Z/p the representatives in the range -(p-1)/2..(p-1)/2 when p>2 resp.
0 and 1 for p=2 are used for comparisons,
@* - in field extensions the last two operations
(@code{>=,<=}) yield always TRUE (1) and
the @code{<} and @code{>} are equivalent to @code{!=}.
@item
polynomial or vector comparisons:
@smallexample
f == g
f != g // or f <> g
f <= g // comparing the leading term w.r.t. the monomial order
f < g
f >= g
f > g
@end smallexample
@item
intmat or matrix comparisons:
@smallexample
v == w
v != w // or v <> w
@end smallexample
@item
intvec or string comparisons:
@smallexample
f == g
f != g // or f <> g
f <= g // comparing lexicographically
f >= g // w.r.t. the order specified by ASCII
f > g
f < g
@end smallexample
@item
boolean expressions combined by boolean operations (@code{and},
@code{or}, @code{not})
@end enumerate
@strong{Note:}
@c ------------------------------------------------------------
@c This piece of text exists also in the file singular.doc,
@c chapter "Evaluation of logical expressions".
@c If you change something here, change it there, too!
@c ------------------------------------------------------------
All arguments of a logical expression are first evaluated and
then the value of the logical expression is determined. For example, the
logical expression @code{(a || b)} is evaluated by first evaluating
@code{a} @emph{and} @code{b}, even though the value of @code{b} has no
influence on the value of @code{(a || b)}, if @code{a} evaluates to
true.
Note that this evaluation is different from the left-to-right, conditional
evaluation of logical expressions (as found in most programming
languages). For example, in these other languages, the value of @code{(1
|| b)} is determined without ever evaluating @code{b}.
See @ref{Major differences to the C programming language}.
@c ------------------------------
@node boolean operations, , boolean expressions, int
@subsection boolean operations
@cindex boolean operations
@cindex and
@cindex &&
@cindex or
@cindex ||
@cindex not
@table @code
@item and
logical @code{and}, may also be written as @code{&&}
@item or
logical @code{or}, may also be written as @code{||}
@item not
logical @code{not}, may also be written as @code{!}
@end table
The precedence of the boolean operations is:
@enumerate
@item parentheses
@item comparisons
@item not
@item and
@item or
@end enumerate
@*@strong{Example:}
@smallexample
@c example
(1>2) and 3;
1 > 2 and 3;
! 0 or 1;
!(0 or 1);
@c example
@end smallexample
@c ---------------------------------------
@node intmat, intvec, int, Data types
@section intmat
@cindex intmat
Integer matrices are matrices with integer entries. For the range of
integers see @ref{Limitations}. Integer matrices do not belong to a
ring, they may be defined without a basering being defined. An intmat
can be multiplied by and added to an int; in this case the int is
converted into an intmat of the right size with the integer on the
diagonal. The integer @code{1}, for example, is converted into the unit
matrix.
@menu
* intmat declarations::
* intmat expressions::
* intmat type cast::
* intmat operations::
* intmat related functions::
@end menu
@c ------------------------------
@node intmat declarations, intmat expressions, intmat, intmat
@subsection intmat declarations
@cindex intmat declarations
@table @strong
@item Syntax:
@code{intmat} name @code{=} intmat_expression @code{;}
@*@code{intmat} name @code{[} rows @code{] [} cols @code{] =} intmat_expression @code{;}
@*@code{intmat} name @code{[} rows @code{] [} cols @code{] =} list_of_int_and_intvec_and_intmat_expressions @code{;}
@*rows and cols must be positive int expressions.
@item Purpose:
defines an intmat variable.
@* Given a list of integers, the matrix is filled up with the first row
from the left to the right, then the second row and so on.
If the int_list contains less than rows*cols elements,
the matrix is filled up with zeros; if it contains more
elements, only the first rows*cols elements are used.
@item Default:
0 (1 x 1 matrix)
@item Example:
@smallexample
@c example
intmat im[3][5]=1,3,5,7,8,9,10,11,12,13;
im;
im[3,2];
intmat m[2][3] = im[1..2,3..5]; // defines a submatrix
m;
@c example
@end smallexample
@end table
@c ------------------------------
@node intmat expressions, intmat type cast, intmat declarations, intmat
@subsection intmat expressions
@cindex intmat expressions
An intmat expression is:
@enumerate
@item
an identifier of type intmat
@item
a function returning intmat
@item
an intmat operation involving ints and int operations (@code{+}, @code{-}, @code{*}, @code{div}, @code{%})
@item
an expression involving intmats and the operations (@code{+}, @code{-}, @code{*})
@item
a type cast to intmat (@pxref{intmat type cast})
@end enumerate
@*@strong{Example:}
@smallexample
@c example
intmat Idm[2][2];
Idm +1; // add the unit intmat
intmat m1[3][2] = _,1,-2; // take entries from the last result
m1;
intmat m2[2][3]=1,0,2,4,5,1;
transpose(m2);
intvec v1=1,2,4;
intvec v2=5,7,8;
m1=v1,v2; // fill m1 with v1 and v2
m1;
trace(m1*m2);
@c example
@end smallexample
@c ref
See
@ref{number};
@ref{Type conversion and casting}.
@c ref
@c ------------------------------
@node intmat type cast, intmat operations, intmat expressions, intmat
@subsection intmat type cast
@cindex intmat type cast
@table @code
@item @strong{Syntax:}
@code{intmat (} expression @code{)}
@*@code{intmat (} expression, int_n, int_m @code{)}
@item @strong{Type:}
intmat
@item @strong{Purpose:}
Converts expression to an intmat, where expression must be of type
intvec, intmat, or bigintmat. If
int_n and int_m are supplied, then they specify the dimension of the
intmat. Otherwise, the size (resp.@: dimensions) of the intmat
are determined by the size (resp.@: dimensions) of the
expression. If expression is a bigintmat containing an entry larger the the
limit of int, it is set to 0 in the returning intmat.
@item @strong{Example:}
@smallexample
@c example
intmat(intvec(1));
intmat(intvec(1), 1, 2);
intmat(intvec(1,2,3,4), 2, 2);
intmat(_, 2, 3);
intmat(_, 2, 1);
bigintmat bim[2][3]=34, 64, 345553234, 35553, 6434, 6563335675;
intmat(bim);
@c example
@end smallexample
@end table
@c ref
See
@ref{intmat};
@ref{Type conversion and casting};
@ref{matrix type cast}.
@c ref
@c ------------------------------
@node intmat operations, intmat related functions, intmat type cast, intmat
@subsection intmat operations
@cindex intmat operations
@cindex +
@cindex -
@cindex *
@table @asis
@item @code{+}
addition with intmat or int; the int is converted into a diagonal intmat
@item @code{-}
negation or subtraction with intmat or int; the int is converted into a
diagonal intmat
@item @code{*}
multiplication with intmat, intvec, or int; the int is converted into a
diagonal intmat
@item @code{div,/}
division of entries in the integers (omitting the remainder)
@item @code{%, mod}
entries modulo int (remainder of the division)
@item @code{<>}, @code{==}
comparators
@item intmat_expression @code{[} intvec_expression@code{,} intvec_expression @code{]}
is an intmat entry, where the first index indicates the row and the
second the column
@end table
@*@strong{Example:}
@smallexample
@c example
intmat m[2][4] = 1,0,2,4,0,1,-1,0,3,2,1,-2;
m;
m[2,3]; // entry at row 2, col 3
size(m); // number of entries
intvec v = 1,0,-1,2;
m * v;
typeof(_);
intmat m1[4][3] = 0,1,2,3,v,1;
intmat m2 = m * m1;
m2; // 2 x 3 intmat
m2*10; // multiply each entry of m with 10;
-m2;
m2 % 2;
m2 div 2;
m2[2,1]; // entry at row 2, col 1
m1[2..3,2..3]; // submatrix
m2[nrows(m2),ncols(m2)]; // the last entry of intmat m2
@c example
@end smallexample
@c ------------------------------
@node intmat related functions, , intmat operations, intmat
@subsection intmat related functions
@cindex intmat related functions
@table @code
@item betti
Betti numbers of a free resolution (see @ref{betti})
@item det
determinant (see @ref{det})
@item ncols
number of cols (see @ref{ncols})
@item nrows
number of rows (see @ref{nrows})
@item random
pseudo random intmat (see @ref{random})
@item size
total number of entries (see @ref{size})
@item transpose
transpose of an intmat (see @ref{transpose})
@item trace
trace of an intmat (see @ref{trace})
@end table
@c ---------------------------------------
@node intvec, link, intmat, Data types
@section intvec
@cindex intvec
Variables of type intvec are lists of integers. For the range of
integers see @ref{Limitations}. They may be used for simulating
sets of integers (and other sets if the intvec is used as an index set
for other objects). Addition and subtraction of an
intvec with an int or an intvec is done element-wise.
@c @example
@c @c example
@c intvec iv=1,2,5,7;
@c iv;
@c iv[3];
@c iv[7]=1;
@c iv;
@c @c example
@c @end example
@menu
* intvec declarations::
* intvec expressions::
* intvec operations::
* intvec related functions::
@end menu
@c ------------------------------
@node intvec declarations, intvec expressions, intvec, intvec
@subsection intvec declarations
@cindex intvec declarations
@table @strong
@item Syntax:
@code{intvec} name @code{=} intvec_expression @code{;}
@*@code{intvec} name @code{=} list_of_int_and_intvec_expressions @code{;}
@item Purpose:
defines an intvec variable.
@* An intvec consists of an ordered list of integers.
@item Default:
0
@item Example:
@smallexample
@c example
intvec iv=1,3,5,7,8;
iv;
iv[4];
iv[3..size (iv)];
@c example
@end smallexample
@end table
@c ------------------------------
@node intvec expressions, intvec operations, intvec declarations, intvec
@subsection intvec expressions
@cindex intvec expressions
@cindex :
@cindex +
@cindex -
@cindex *
@cindex /
@cindex %
An intvec expression is:
@enumerate
@item
a range: int expression @code{..} int expression
@item
a repeated entry: int expression @code{:} positive int expression
@*(@code{a:b} generates an @code{intvec} of length @code{b}>0 with identical entries @code{a})
@item
a function returning intvec
@item
an expression involving intvec operations with int (@code{+}, @code{-}, @code{*}, @code{/}, @code{%})
@item
an expression of intvecs involving intvec operations (@code{+}, @code{-})
@item
an expression involving an intvec operation with intmat (@code{*})
@item
a type cast to intvec
@end enumerate
@*@strong{Example:}
@smallexample
@c example
intvec v=-1,2;
intvec w=v,v; // concatenation
w;
w=2:3; // repetition
w;
int k = 3;
v = 7:k;
v;
v=-1,2;
w=-2..2,v,1;
w;
intmat m[3][2] = 0,1,2,-2,3,1;
m*v;
typeof(_);
v = intvec(m);
v;
ring r;
poly f = x2z + 2xy-z;
f;
v = leadexp(f);
v;
@c example
@end smallexample
@c ------------------------------
@node intvec operations, intvec related functions, intvec expressions, intvec
@subsection intvec operations
@cindex intvec operations
@table @asis
@item @code{+}
addition with intvec or int (component-wise)
@item @code{-}
negation or subtraction with intvec or int (component-wise)
@item @code{*}
multiplication with int (component-wise)
@item @code{/}, @code{div}
division by int (component-wise)
@item @code{%, mod}
modulo (component-wise)
@item @code{<>}, @code{==}, @code{<=}, @code{>=}, @code{>}, @code{<}
comparison (done lexicographically, different length will be filled with 0 at th right)
@item intvec_expression @code{[} int_expression @code{]}
is an element of the intvec; the first element has index one.
@end table
@*@strong{Example:}
@smallexample
@c example
intvec iv = 1,3,5,7,8;
iv+1; // add 1 to each entry
iv*2;
iv;
iv-10;
iv=iv,0;
iv;
iv div 2;
iv+iv; // component-wise addition
iv[size(iv)-1]; // last-1 entry
intvec iw=2,3,4,0;
iv==iw; // lexicographic comparison
iv < iw;
iv != iw;
iv[2];
iw = 4,1,2;
iv[iw];
@c example
@end smallexample
@c ------------------------------
@node intvec related functions, , intvec operations, intvec
@subsection intvec related functions
@cindex intvec related functions
@table @code
@item hilb
Hilbert series as intvec (see @ref{hilb})
@item indepSet
sets of independent variables of an ideal (see @ref{indepSet})
@item leadexp
the exponent vector of the leading monomial (see @ref{leadexp})
@item monomial
the power product corresponding to the exponent vector (see @ref{monomial})
@item nrows
number of rows (see @ref{nrows})
@item qhweight
quasihomogeneous weights (see @ref{qhweight})
@item size
length of the intvec (see @ref{size})
@item sortvec
permutation for sorting ideals/modules (see @ref{sortvec})
@item transpose
transpose of an intvec, returns an intmat (see @ref{transpose})
@item weight
weights for the weighted ecart method (see @ref{weight})
@end table
@c ---------------------------------------
@node link, list, intvec, Data types
@section link
@cindex link
@c {{{ section link }}}
Links are the communication channels of @sc{Singular}, i.e.,
something @sc{Singular} can write to and/or read from. Currently,
@sc{Singular} supports four different link types:
@itemize @bullet
@item ASCII links (see
@ref{ASCII links})
@item ssi links (see
@ref{Ssi links})
@item pipe links (see
@ref{Pipe links})
@item DBM links (see
@ref{DBM links})
@end itemize
@menu
* link declarations::
* link expressions::
* link related functions::
* ASCII links::
* Ssi links::
* Pipe links::
* DBM links::
@end menu
@c ------------------------------
@node link declarations, link expressions, link, link
@subsection link declarations
@cindex link declarations
@table @strong
@item Syntax:
@code{link} name @code{=} string_expression @code{;}
@item Purpose:
defines a new communication link.
@item Default:
none
@item Example:
@smallexample
@c Tim: Let's only do the read here once, doing it twice without closing
@c it first might be confusing
@c example
link l=":w example.txt";
int i=22; // cf. ASCII links for explanation
string s="An int follows:";
write(l,s,i);
l;
close(l); //
read(l);
close(l);
@c example
@end smallexample
@end table
@c ------------------------------
@node link expressions, link related functions, link declarations, link
@subsection link expressions
@cindex link expressions
A link expression is:
@enumerate
@item
an identifier of type link
@item
a string describing the link
@end enumerate
A link is described by a string which consists of two parts: a property
string followed by a name string. The property string describes the type
of the link (@code{ASCII}, @code{ssi} or @code{DBM})
and the mode of the link (e.g., open for read, write or append). The name
string describes the filename of the link, resp.@: a network connection
for ssi links.
For a detailed format description of the link describing string see:
@iftex
@itemize @bullet
@item for ASCII links:
@ref{ASCII links}
@item ssi links (see
@ref{Ssi links})
@item pipe links (see
@ref{Pipe links})
@item for DBM links:
@ref{DBM links}
@end itemize
@end iftex
@menu
* ASCII links::
* Ssi links::
* Pipe links::
* DBM links::
@end menu
@c ------------------------------
@node link related functions, ASCII links, link expressions, link
@subsection link related functions
@cindex link related functions
@table @code
@item close
closes a link (see @ref{close})
@item dump
generates a dump of all variables and their values (see @ref{dump})
@item getdump
reads a dump (see @ref{getdump})
@item open
opens a link (see @ref{open})
@item read
reads from a link (see @ref{read})
@item status
gets the status of a link (see @ref{status})
@item write
writes to a link (see @ref{write})
@item kill
closes and kills a link (see @ref{kill})
@item waitall
wait till all links of a list of links become ready (only ssi:tcp links)
(see @ref{waitall})
@item waitfirst
wait till at least one link of a list of links become ready (only ssi:tcp links)
(see @ref{waitfirst})
@end table
@c ------------------------------
@node ASCII links, Ssi links, link related functions, link
@subsection ASCII links
@cindex ASCII links
Via ASCII links data that can be converted to a string can be written
into files for storage or communication with other programs. The data is
written in plain ASCII format. The output format of polynomials is done
w.r.t@:. the value of the global variable @code{short} (see @ref{short}).
Reading from an ASCII link returns a string --- conversion into other data
is up to the user. This can be done, for example,
using the command @code{execute}
(see @ref{execute}).
The ASCII link describing string has to be one of the following:
@enumerate
@item @code{"ASCII: "} + filename
@*the mode (read or append) is set by the first @code{read} or
@code{write} command.
@item @code{"ASCII:r "} + filename
@*opens the file for reading.
@item @code{"ASCII:w "} + filename
@*opens the file for overwriting.
@item @code{"ASCII:a "} + filename
@*opens the file for appending.
@end enumerate
There are the following default values:
@itemize @bullet
@item the type @code{ASCII} may be omitted since ASCII links are the
default links.
@item if non of @code{r}, @code{w}, or @code{a} is specified, the mode of
the link is set by the first @code{read} or @code{write} command on the
link. If the first command is @code{write}, the mode is set to @code{a}
(append mode).
@item if the filename is omitted, @code{read} reads from stdin and
@code{write} writes to stdout.
@end itemize
Using these default rules, the string @code{":r temp"} describes a link
which is equivalent to the link @code{"ASCII:r temp"}: an ASCII link to
the file @code{temp} which is opened for reading. The string
@code{"temp"} describes an ASCII link to the file @code{temp}, where the
mode is set by the first @code{read} or @code{write} command. See also
the example below.
Note that the filename may contain a path. On Microsoft Windows
(resp.@: MS-DOS) platforms, names of a drive can precede the filename, but
must be started with a @code{//} (as in @code{//c/temp/ex}. An ASCII
link can be used either for reading or for writing, but not for both at
the same time. A @code{close} command must be used before a change of
I/O direction. Types without a conversion to @code{string} cannot be
written.
@*@strong{Example:}
@smallexample
@c example
ring r=32003,(x,y,z),dp;
link l=":w example.txt"; // type is ASCII, mode is overwrite
l;
status(l, "open", "yes"); // link is not yet opened
ideal i=x2,y2,z2;
write (l,1,";",2,";","ideal i=",i,";");
status(l, "open", "yes"); // now link is open
status(l, "mode"); // for writing
close(l); // link is closed
write("example.txt","int j=5;");// data is appended to file
read("example.txt"); // data is returned as string
execute(read(l)); // read string is executed
close(l); // link is closed
@c example
@c // dump vars overwriting previous file content:
@c dump(":w example.txt");
@end smallexample
@c -------------------------------------------------------------------
@node Ssi links, Pipe links, ASCII links, link
@subsection Ssi links
@cindex Ssi links
Ssi (simple singular interface) links give the possibility to store
and communicate data betweenm Singular processes:
Read and write access is very fast
compared to ASCII links. Ssi links can be established using files
or using TCP sockets.
For ring-dependent data, a
ring description is written together with the data. Reading from an Ssi
link returns an expression (not a string) which was evaluated after the
read operation. If the expression read from an Ssi link is not from the
same ring as the current ring, then a @code{read} changes the current
ring.
Currently under development - not everything is implemtented.
@menu
* Ssi file links::
* Ssi tcp links::
@end menu
@c -------------------------------------------------------------
@node Ssi file links, Ssi tcp links, Ssi links, Ssi links
@subsubsection Ssi file links
@cindex Ssi file links
Ssi file links provide the possibility to store data in a file using the
ssi format.
For storing large amounts of data, ssi file links
should be used instead of ASCII links. Unlike ASCII links, data read
from ssi file links is returned as expressions one at a time.
The ssi file link describing string has to be one of the following:
@enumerate
@item @code{"ssi:r "} + filename
@*opens the file for reading.
@item @code{"ssi:w "} + filename
@*opens the file for overwriting.
@item @code{"ssi:a "} + filename
@*opens the file for appending.
@end enumerate
Note that the filename may contain a path. An ssi file link can be used
either for reading or for writing, but not for both at the same time. A
@code{close} command must be used before a change of I/O direction.
@*@strong{Example:}
@smallexample
@c example
ring r;
link l="ssi:w example.ssi"; // type=ssi, mode=overwrite
l;
ideal i=x2,y2,z2;
write (l,1, i, "hello world");// write three expressions
write(l,4); // append one more expression
close(l); // link is closed
// open the file for reading now
read(l); // only first expression is read
kill r; // no basering active now
def i = read(l); // second expression
// notice that current ring was set, the name was assigned
// automatically
listvar(ring);
def s = read(l); // third expression
listvar();
close(l); // link is closed
@c example
@end smallexample
@c -------------------------------------------------------------
@node Ssi tcp links, , Ssi file links, Ssi links
@subsubsection Ssi tcp links
@cindex Ssi tcp links
Ssi tcp links give the possibility to exchange data
between two processes which may run on the same or on different
computers. Ssi tcp links can be opened in four different modes:
@table @code
@item tcp
@sc{Singular} acts as a server.
@item connect
@sc{Singular} acts as a client.
@item tcp <host>:<program>
@sc{Singular} acts as a client, launching an application as server.
This requires @code{ssh}/@code{sshd} to be installed an the computers
(and preferably an automatic login via @code{.ssh/authorized_keys}).
@item fork
@sc{Singular} acts as a client, forking another @sc{Singular} as
server.
@end table
The Ssi tcp link describing string has to be
@itemize @bullet
@item tcp mode:
@enumerate
@item @code{"ssi:tcp"}
@end enumerate
@sc{Singular} becomes a server and waits at the first free port (>1024) for a
connect call.
@item connect mode:
@enumerate 2
@item @code{"ssi:connect "} + host@code{:}port
@end enumerate
@sc{Singular} becomes a client and connects to a server waiting at
the host and port.
@item launch mode:
@enumerate 4
@item @code{"ssi:tcp"} + host@code{:}application
@end enumerate
@sc{Singular} becomes a client and starts (launches) the application
using ssh on a (possibly) different host
which then acts as a server.
@item fork mode:
@enumerate 8
@item @code{"ssi:fork"}
@end enumerate
@sc{Singular} becomes a client and forks another @sc{Singular} on the
same host which acts as a server.
@end itemize
To open an ssi tcp link in launch mode, the application to launch must
either be given with an absolute pathname, or must be in a directory
contained in the search path. The launched application acts as a server,
whereas the @sc{Singular} that actually opened the link acts as a
client.
The client "listens" at the some free port until the server
application does a connect call.
If the ssi tcp link is opened in fork mode a child of the current
@sc{Singular} is forked. All variables and their values are inherited by
the child. The child acts as a server whereas the @sc{Singular} that
actually opened the link acts as a client.
To arrange the evaluation of an expression by a server, the expression
must be quoted using the command @code{quote} (see @ref{quote}), so that
a local evaluation is prevented. Otherwise, the expression is evaluated
first, and the result of the evaluation is written, instead of the
expression which is to be evaluated.
If @sc{Singular} is in server mode, the value of the variable
@code{link_ll} is the ssi link connecting to the client and
@sc{Singular} is in an infinite read-eval-write loop until the
connection is closed from the client side (by closing its connecting
link).
Reading and writing is done to the link @code{link_ll}:
After an
expression is read, it is evaluated and the result of the evaluation is
written back. That is, for each expression which was written to the
server, there is exactly one expression written back. This might be an
"empty" expression, if the evaluation on the server side does not return
a value.
Ssi tcp links should explicitly be opened before being used. Ssi tcp links
are bidirectional, i.e. can be used for both, writing and
reading. Reading from an ssi tcp link blocks until data was written to
that link. The @code{status} command can be used to check whether there
is data to read.
@*@strong{Example:}
@smallexample
@c example unix_only
int i=7;
link l = "ssi:fork"; // fork link declaration
open(l); l;
write(l,quote(i)); // Child inherited vars and their values
read(l);
close(l); // shut down forked child
@c example
@end smallexample
@c -------------------------------------------------------------------
@node Pipe links, DBM links, Ssi links, link
@subsection Pipe links
@cindex Pipe links
Pipe links provide access to stdin and stdout of any program.
Pipe links are bidirectional.
@strong{Syntax:} @code{"|: "} + string_for_system
The string_for system will be passed to @code{system} after connecting
the input and output to the corresponding stdout and stdin.
@strong{Example:}
@smallexample
@c example
link l="|: date";
open(l); l;
read(l);
l;
close(l);
@c example
@end smallexample
@c ------------------------------
@node DBM links, , Pipe links, link
@subsection DBM links
@cindex DBM links
DBM links provide access to data stored in a data base.
Each entry in the data base consists of a (key_string,
value_string) pair. Such a pair can be inserted with the command
@code{write(}link@code{,} key_string@code{,} value_string@code{)}. By
calling @code{write(}link@code{,} key_string@code{)}, the entry with key
key_string is deleted from the data base. The value of an entry is
returned by the command @code{read(}link@code{,}
key_string@code{)}. With only one argument, @code{read(}link@code{)}
returns the next key in the data base. Using this feature a
data base can be scanned in order to access all entries of the data base.
If a data base with name @code{name} is opened for writing for the first
time, two files (@code{name.pag} and @code{name.dir}), which contain the
data base, are automatically created.
The DBM link describing string has to be one of the following:
@enumerate
@item @code{"DBM: "} + name
@*opens the data base for reading (default mode).
@item @code{"DBM:r "} + name
@*opens the data base for reading.
@item @code{"DBM:rw "} + name
@*opens the data base for reading and writing.
@end enumerate
Note that @code{name} must be given without the suffix @code{.pag} or
@code{.dir}. The name may contain an (absolute) path.
@*@strong{Example:}
@smallexample
@c example unix_only
link l="DBM:rw example";
write(l,"1","abc");
write(l,"3","XYZ");
write(l,"2","ABC");
l;
close(l);
// read all keys (till empty string):
read(l);
read(l);
read(l);
read(l);
// read data corresponding to key "1"
read(l,"1");
// read all data:
read(l,read(l));
read(l,read(l));
read(l,read(l));
// close
close(l);
@c example
@end smallexample
@c ---------------------------------------
@node list, map, link, Data types
@section list
@cindex list
Lists are arrays whose elements can be of different types (including ring).
If one element belongs to a ring the whole list belongs to that
ring. This applies also to the special list @code{#}. The expression
@code{list()} is the empty list.
Note that a list stores the objects itself and not the names. Hence, if
@code{L} is a list, @code{L[1]} for example has no name. A name, say
@code{R}, can be created for @code{L[1]} by @code{def R=L[1];}. To store
also the name of an object, say @code{r}, it can be added to the list
with @code{nameof(r);}. Rings may be objects of a list.
@strong{Note}: Unlike other assignments a ring as an element of a list
is not a copy but another reference to the same ring.
@menu
* list declarations::
* list expressions::
* list operations::
* list related functions::
@end menu
@c ------------------------------
@node list declarations, list expressions, list, list
@subsection list declarations
@cindex list declarations
@table @strong
@item Syntax:
@code{list} name @code{=} expression_list@code{;}
@*@code{list} name @code{=} list_expression@code{;}
@item Purpose:
defines a list (of objects of possibly different types).
@item Default:
empty list
@item Example:
@smallexample
@c example
list l=1,"str";
l[1];
l[2];
ring r;
listvar(r);
ideal i = x^2, y^2 + z^3;
l[3] = i;
l;
listvar(r); // the list l belongs now to the ring r
@c example
@end smallexample
@end table
@c ------------------------------
@node list expressions, list operations, list declarations, list
@subsection list expressions
@cindex list expressions
A list expression is:
@enumerate
@item
the empty list @code{list()}
@item
an identifier of type list
@item
a function returning list
@item
list expressions combined by the arithmetic operation @code{+}
@item
a type cast to list
@end enumerate
@c ref
See @ref{Type conversion and casting}.
@c ref
@*@strong{Example:}
@smallexample
@c example
list l = "hello",1;
l;
l = list();
l;
ring r =0,x,dp;
factorize((x+1)^2);
list(1,2,3);
@c example
@end smallexample
@c ------------------------------
@node list operations, list related functions, list expressions, list
@subsection list operations
@cindex list operations
@cindex +
@cindex delete
@cindex insert
@table @asis
@item @code{+}
concatenation
@item @code{delete}
deletes one element from list, returns new list
@item @code{insert}
inserts or appends a new element to list, returns a new list
@item list_expression @code{[} int_expression @code{]}
is a list entry; the index 1 gives the first element.
@end table
@*@strong{Example:}
@smallexample
@c example
list l1 = 1,"hello",list(-1,1);
list l2 = list(1,5,7);
l1 + l2; // a new list
l2 = delete(l2, 2); // delete 2nd entry
l2;
@c example
@end smallexample
@c ------------------------------
@node list related functions, , list operations, list
@subsection list related functions
@cindex list related functions
@table @code
@item bareiss
returns a list of a matrix (lower triangular) and
of an intvec (permutations of columns, see @ref{bareiss})
@item betti
Betti numbers of a resolution (see @ref{betti})
@item delete
deletion of an element from a list (see @ref{delete})
@item facstd
factorizing Groebner basis algorithm (see @ref{facstd})
@item factorize
list of factors of a polynomial (see @ref{factorize})
@item insert
insertion of a new element into a list (see @ref{insert})
@item minres
minimization of a free resolution (see @ref{minres})
@item names
list of all user-defined variable names (see @ref{names})
@item size
number of entries (see @ref{size})
@item conversion from @code{resolution}
(see @ref{resolution})
@end table
@c ---------------------------------------
@node map, matrix, list, Data types
@section map
@cindex map
Maps are ring maps from a preimage ring into the basering.
@strong{Note:}
@itemize @bullet
@item
The target of a map is @strong{ALWAYS} the actual basering
@item
The preimage ring has to be stored "by its name", that means, maps can only be
used in such contexts, where the name of the preimage ring can be
resolved (this has to be considered in subprocedures).
@c (i.e., there might be problems for rings/maps defined in subprocedures).
See also @ref{Identifier resolution}, @ref{Names in procedures}.
@end itemize
Maps between rings with different coefficient fields are
possible and listed below.
Canonically realized are
@itemize @bullet
@item
@tex
$Q \rightarrow Q(a, \ldots)$
@end tex
@ifinfo
Q -> Q(a,..)
@end ifinfo
(@math{Q}: the rational numbers)
@item
@tex
$Q \rightarrow R$
@end tex
@ifinfo
Q -> R
@end ifinfo
(@math{R}: the real numbers)
@item
@tex
$Q \rightarrow C$
@end tex
@ifinfo
Q -> C
@end ifinfo
(@math{C}: the complex numbers)
@item
@tex
$Z/p \rightarrow (Z/p)(a, \ldots)$
@end tex
@ifinfo
Z/p ->(Z/p)(a,...)
@end ifinfo
(@math{Z}: the integers)
@item
@tex
$Z/p \rightarrow GF(p^n)$
@end tex
@ifinfo
Z/p -> GF(p^n)
@end ifinfo
(@math{GF}: the Galois field)
@item
@tex
$Z/p \rightarrow R$
@end tex
@ifinfo
Z/p -> R
@end ifinfo
@item
@tex
$R \rightarrow C$
@end tex
@ifinfo
R -> C
@end ifinfo
@end itemize
Possible are furthermore
@itemize @bullet
@item
@tex
$Z/p \rightarrow Q,
\quad
[i]_p \mapsto i \in [-p/2, \, p/2]
\subseteq Z$
@end tex
@ifinfo
Z/p -> Q : [i]_p -> i in [-p/2, p/2] in Z
@end ifinfo
@item
@tex
$Z/p \rightarrow Z/p^\prime,
\quad
[i]_p \mapsto i \in [-p/2, \, p/2] \subseteq Z, \;
i \mapsto [i]_{p^\prime} \in Z/p^\prime$
@end tex
@ifinfo
Z/p -> Z/p' : [i]_p in Z/p -> i in [-p/2,p/2] in Z, i -> [i]_p' in Z/p'
@end ifinfo
@item
@tex
$C \rightarrow R, \quad$ by taking the real part
@end tex
@ifinfo
C -> R by taking the real part.
@end ifinfo
@end itemize
Finally, in @sc{Singular} we allow the mapping from rings
with coefficient field Q to rings whose ground fields
have finite characteristic:
@itemize @bullet
@item
@tex
$Q \rightarrow Z/p$
@end tex
@ifinfo
Q -> Z/p
@end ifinfo
@item
@tex
$Q \rightarrow (Z/p)(a, \ldots)$
@end tex
@ifinfo
Q -> (Z/p)(a,..)
@end ifinfo
@end itemize
In these cases the denominator and the numerator
of a number are mapped separately by the usual
map from Z to Z/p, and the image of the number
is built again afterwards by division. It is thus
not allowed to map numbers whose denominator is
divisible by the characteristic of the target
ground field, or objects containing such numbers.
We, therefore, strongly recommend using such
maps only to map objects with integer coefficients.
@menu
* map declarations::
* map expressions::
* map operations::
* map related functions::
@end menu
@c @iftex
@c See @ref{imap}; @ref{fetch}; @ref{subst}.
@c @end iftex
@c ------------------------------
@node map declarations, map expressions, map, map
@subsection map declarations
@cindex map declarations
@table @strong
@item Syntax:
@code{map} name @code{=} preimage_ring_name @code{,} ideal_expression @code{;}
@*@code{map} name @code{=} preimage_ring_name @code{,} list_of_poly_and_ideal_expressions @code{;}
@*@code{map} name @code{=} map_expression @code{;}
@item Purpose:
defines a ring map from preimage_ring to basering.
@* Maps the variables of the preimage ring to the generators of the ideal.
If the ideal contains less elements than variables in the
preimage_ring the remaining variables are mapped to 0, if the ideal contains
more elements these are ignored.
The image ring is always the current basering.
For the mapping of coefficients from different fields see @ref{map}.
@item Default:
none
@item Note:
There are standard mappings for maps which are close to the identity
map: @code{fetch} and @code{imap}.
The name of a map serves as the function which maps objects from the
preimage_ring into the basering. These objects must be defined
by names (no evaluation in the preimage ring is possible).
@item Example:
@smallexample
@c example
ring r1=32003,(x,y,z),dp;
ideal i=x,y,z;
ring r2=32003,(a,b),dp;
map f=r1,a,b,a+b;
// maps from r1 to r2,
// x -> a
// y -> b
// z -> a+b
f(i);
// operations like f(i[1]) or f(i*i) are not allowed
ideal i=f(i);
// objects in different rings may have the same name
map g = r2,a2,b2;
map phi = g(f);
// composition of map f and g
// maps from r1 to r2,
// x -> a2
// y -> b2
// z -> a2+b2
phi(i);
@c example
@end smallexample
@end table
@c ref
See @ref{map}; @ref{ideal expressions}; @ref{ring};
@ref{imap}; @ref{fetch}.
@c ref
@c ------------------------------
@node map expressions, map operations, map declarations, map
@subsection map expressions
@cindex map expressions
A map expression is:
@enumerate
@item
an identifier of type map
@item
a function returning map
@item
map expressions combined by composition using parentheses (@code{(}, @code{)})
@end enumerate
@c ------------------------------
@node map operations, map related functions, map expressions, map
@subsection map operations
@cindex map operations
@cindex ()
@table @asis
@item @code{( )}
composition of maps. If, for example, @code{f} and @code{g} are maps,
then @code{f(g)} is a map expression giving the composition
@tex
$f \circ g$
@end tex
@ifinfo
@code{f} @bullet{} @code{g}
@end ifinfo
of @code{f} and @code{g},
@* provided the target ring of @code{g} is the basering of @code{f}.
@item map_expression @code{[} int_expressions @code{]}
is a map entry (the image of the corresponding variable)
@end table
@*@strong{Example:}
@smallexample
@c example
ring r=0,(x,y),dp;
map f=r,y,x; // the map f permutes the variables
f;
poly p=x+2y3;
f(p);
map g=f(f); // the map g defined as f^2 is the identity
g;
g(p) == p;
@c example
@end smallexample
@c ------------------------------
@node map related functions, , map operations, map
@subsection map related functions
@cindex map related functions
@table @code
@item fetch
the identity map between rings (see @ref{fetch})
@item imap
a convenient map procedure for inclusions and projections of rings (see @ref{imap})
@item preimage
preimage under a ring map (see @ref{preimage})
@item subst
substitution of a ring variable (see @ref{subst})
@end table
See also the libraries @ref{algebra_lib} and @ref{ring_lib}, which contain more
functions, related to maps.
@c ---------------------------------------
@node matrix, module, map, Data types
@section matrix
@cindex matrix
Objects of type matrix are matrices with polynomial entries.
Like polynomials they can
only be defined or accessed with respect to a basering. In order to
compute with matrices having integer or rational entries, define a ring
with characteristic 0 and at least one variable.
A matrix can be multiplied by and added to a poly; in this case the
polynomial is converted into a matrix of the right size with the polynomial on the
diagonal.
If A is a matrix then the assignment @code{module M=A;} or @code{module
M=module(A);} creates a module generated by the columns of A. Note that
the trailing zero columns of A may be deleted by module operations with
M.
@menu
* matrix declarations::
* matrix expressions::
* matrix type cast::
* matrix operations::
* matrix related functions::
@end menu
@c ------------------------------
@node matrix declarations, matrix expressions, matrix, matrix
@subsection matrix declarations
@cindex matrix declarations
@table @strong
@item Syntax:
@code{matrix} name@code{[}rows@code{][}cols@code{] =} list_of_poly_expressions @code{;}
@*@code{matrix} name = matrix_expression @code{;}
@item Purpose:
defines a matrix (of polynomials).
The given poly_list fills up the matrix beginning with the first row
from the left to the right, then the second row and so on.
If the poly_list contains less than rows*cols elements,
the matrix is filled up with zeros; if it contains more
elements, then only the first rows*cols elements are used.
If the right-hand side is a matrix expression
the matrix on the left-hand side gets the same size as the right-hand side,
otherwise the size is determined by the left-hand side.
If the size is omitted a 1x1 matrix is created.
@item Default:
0 (1 x 1 matrix)
@item Example:
@smallexample
@c example
int ro = 3;
ring r = 32003,(x,y,z),dp;
poly f=xyz;
poly g=z*f;
ideal i=f,g,g^2;
matrix m[ro][3] = x3y4, 0, i, f ; // a 3 x 3 matrix
m;
print(m);
matrix A; // the 1 x 1 zero matrix
matrix B[2][2] = m[1..2, 2..3]; //defines a submatrix
print(B);
matrix C=m; // defines C as a 3 x 3 matrix equal to m
print(C);
@c example
@end smallexample
@end table
@c ------------------------------
@node matrix expressions, matrix type cast, matrix declarations, matrix
@subsection matrix expressions
@cindex matrix expressions
A matrix expression is:
@enumerate
@item
an identifier of type matrix
@item
a function returning matrix
@item
matrix expressions combined by the arithmetic operations
@code{+}, @code{-} or @code{*}
@item
a type cast to matrix (@pxref{matrix type cast})
@end enumerate
@*@strong{Example:}
@smallexample
@c example
ring r=0,(x,y),dp;
poly f= x3y2 + 2x2y2 +2;
matrix H = jacob(jacob(f)); // the Hessian of f
matrix mc = coef(f,y);
print(mc);
module MD = [x+y,1,x],[x+y,0,y];
matrix M = MD;
print(M);
@c example
@end smallexample
@c ------------------------------
@node matrix type cast, matrix operations, matrix expressions, matrix
@subsection matrix type cast
@cindex matrix type cast
@table @code
@item @strong{Syntax:}
@code{matrix (} expression @code{)}
@*@code{matrix (} expression, int_n, int_m @code{)}
@item @strong{Type:}
matrix
@item @strong{Purpose:}
Converts expression to a matrix, where expression must be of type int,
intmat, intvec, number, poly, ideal, vector, module, or matrix. If
int_n and int_m are supplied, then they specify the dimension of the
matrix. Otherwise, the size (resp.@: dimensions) of the matrix
is determined by the size (resp.@: dimensions) of the
expression.
@item @strong{Example:}
@smallexample
@c example
ring r=32003,(x,y,z),dp;
matrix(x);
matrix(x, 1, 2);
matrix(intmat(intvec(1,2,3,4), 2, 2));
matrix(_, 2, 3);
matrix(_, 2, 1);
@c example
@end smallexample
@end table
@c ref
See
@ref{matrix};
@ref{Type conversion and casting};
@ref{intmat type cast}.
@c ref
@c ------------------------------
@node matrix operations, matrix related functions, matrix type cast, matrix
@subsection matrix operations
@cindex matrix operations
@cindex +
@cindex -
@cindex *
@cindex /
@cindex ==
@cindex <>
@table @asis
@item @code{+}
addition with matrix or poly; the polynomial is converted into a diagonal
matrix
@item @code{-}
negation or subtraction with matrix or poly
(the first operand is expected to be a matrix);
the polynomial is converted into a diagonal matrix
@item @code{*}
multiplication with matrix or poly; the polynomial is converted into a
diagonal matrix
@item @code{/}
division by poly
@item @code{==}, @code{<>}, @code{!=}
comparators
@item matrix_expression @code{[} int_expression@code{,} int_expression @code{]}
is a matrix entry, where the first index indicates the row and the
second the column
@end table
@*@strong{Example:}
@smallexample
@c example
ring r=32003,x,dp;
matrix A[3][3] = 1,3,2,5,0,3,2,4,5; // define a matrix
print(A); // nice printing of small matrices
A[2,3]; // matrix entry
A[2,3] = A[2,3] + 1; // change entry
A[2,1..3] = 1,2,3; // change 2nd row
print(A);
matrix E[3][3]; E = E + 1; // the unit matrix
matrix B =x*E - A;
print(B);
// the same (but x-A does not work):
B = -A+x;
print(B);
det(B); // the characteristic polynomial of A
A*A*A - 8 * A*A - 2*A == E; // Cayley-Hamilton
vector v =[x,-1,x2];
A*v; // multiplication of matrix and vector
matrix m[2][2]=1,2,3;
print(m-transpose(m));
@c example
@end smallexample
@c ------------------------------
@node matrix related functions, , matrix operations, matrix
@subsection matrix related functions
@cindex matrix related functions
@table @code
@item bareiss
Gauss-Bareiss algorithm (see @ref{bareiss})
@item coef
matrix of coefficients and monomials (see @ref{coef})
@item coeffs
matrix of coefficients (see @ref{coeffs})
@item det
determinant (see @ref{det})
@item diff
partial derivative (see @ref{diff})
@item jacob
Jacobi matrix (see @ref{jacob})
@item koszul
Koszul matrix (see @ref{koszul})
@item lift
lift-matrix (see @ref{lift})
@item liftstd
standard basis and transformation matrix computation (see @ref{liftstd})
@item minor
set of minors of a matrix (see @ref{minor})
@item ncols
number of columns (see @ref{ncols})
@item nrows
number of rows (see @ref{nrows})
@item print
nice print format (see @ref{print})
@item size
number of matrix entries (see @ref{size})
@item subst
substitute a ring variable (see @ref{subst})
@item trace
trace of a matrix (see @ref{trace})
@item transpose
transposed matrix (see @ref{transpose})
@item wedge
wedge product (see @ref{wedge})
@end table
See also the library @ref{matrix_lib}, which contains more
matrix-related functions.
@c @*@strong{Example:}
@c @example
@c @end example
@c ---------------------------------------
@node module, number, matrix, Data types
@section module
@cindex module
Modules are submodules of a free module over the basering with basis
@code{gen(1)}, @code{gen(2)}, @dots{} .
They are represented by lists of vectors which generate the submodule.
Like vectors they
can only be defined or accessed with respect to a basering.
@iftex
If @math{R} is the basering, and @math{M} is a submodule of @math{R^n}
generated by vectors @math{v_1, \ldots, v_k}, then @math{v_1, \ldots, v_k}
may be considered as the generators of relations of @math{R^n/M} between the
canonical generators @code{gen(1)},@dots{},@code{gen(n)}. Hence any finitely
generated @math{R}-module can be represented in @sc{Singular} by its module
of relations. The assignments @code{module M=v1,...,vk; matrix A=M;} create
the presentation matrix of size n@math{\times}k for @math{R^n/M}, i.e., the
columns of A are the vectors @math{v_1, \ldots, v_k} which generate M (cf.
@ref{Representation of mathematical objects}).
@end iftex
@ifinfo
If @math{M} is a submodule of R^n,
@math{R} the basering, generated by vectors
v_1, @dots{}, v_k, then v_1, @dots{}, v_k
may be considered as the generators of relations of R^n/M
between the canonical generators @code{gen(1)},@dots{},@code{gen(n)}.
Hence any finitely generated @math{R}-module can be represented in @sc{Singular}
by its module of relations. The assignments
@code{module M=v1,...,vk; matrix A=M;}
create the presentation matrix of size
n x k for R^n/M,
i.e., the columns of A are the vectors v_1, @dots{}, v_k
which generate M (cf. @ref{Representation of mathematical objects}).
@end ifinfo
@menu
* module declarations::
* module expressions::
* module operations::
* module related functions::
@end menu
@c ------------------------------
@node module declarations, module expressions, module, module
@subsection module declarations
@cindex module declarations
@table @strong
@item Syntax:
@code{module} name @code{=} list_of_vector_expressions @code{;}
@*@code{module} name @code{=} module_expression @code{;}
@item Purpose:
defines a module.
@item Default:
[0]
@item Example:
@smallexample
@c example
ring r=0,(x,y,z),(c,dp);
vector s1 = [x2,y3,z];
vector s2 = [xy,1,0];
vector s3 = [0,x2-y2,z];
poly f = xyz;
module m = s1, s2-s1,f*(s3-s1);
m;
// show m in matrix format (columns generate m)
print(m);
@c example
@end smallexample
@end table
@c ------------------------------
@node module expressions, module operations, module declarations, module
@subsection module expressions
@cindex module expressions
A module expression is:
@enumerate
@item
an identifier of type module
@item
a function returning module
@item
module expressions combined by the arithmetic operation @code{+}
@item
multiplication of a module expression with an ideal or a poly expression: @code{*}
@item
a type cast to module
@end enumerate
@c ref
See
@ref{ideal};
@ref{poly};
@ref{Type conversion and casting};
@ref{vector}.
@c ref
@c @*@strong{Example:}
@c @example
@c @c example
@c @c example
@c @end example
@c ------------------------------
@node module operations, module related functions, module expressions, module
@subsection module operations
@cindex module operations
@cindex +
@cindex *
@cindex []
@table @asis
@item @code{+}
addition (concatenation of the generators and simplification)
@item @code{*}
multiplication with ideal or poly (but not `module` * `module`!)
@item module_expression @code{[} int_expression @code{,} int_expression @code{]}
is a module entry, where the first index indicates the row and
the second the column
@item module_expressions @code{[} int_expression @code{]}
is a vector, where the index indicates the column (generator)
@end table
@*@strong{Example:}
@smallexample
@c example
ring r=0,(x,y,z),dp;
module m=[x,y],[0,0,z];
print(m*(x+y));
// this is not distributive:
print(m*x+m*y);
@c example
@end smallexample
@c ------------------------------
@node module related functions, , module operations, module
@subsection module related functions
@cindex module related functions
@table @code
@item coeffs
matrix of coefficients (see @ref{coeffs})
@item degree
multiplicity, dimension and codimension of the module of leading terms (see @ref{degree})
@item diff
partial derivative (see @ref{diff})
@item dim
Krull dimension of free module over the basering modulo the module of leading terms (see @ref{dim})
@item eliminate
elimination of variables (see @ref{eliminate})
@item freemodule
the free module of given rank (see @ref{freemodule})
@item fres
free resolution of a standard basis (see @ref{fres})
@item groebner
Groebner basis computation (a wrapper around @code{std,stdhilb,stdfglm},...)
(see @ref{groebner})
@item hilb
Hilbert function of a standard basis (see @ref{hilb})
@item homog
homogenization with respect to a variable (see @ref{homog})
@item interred
interreduction of a module (see @ref{interred})
@item intersect
module intersection (see @ref{intersect})
@item jet
Taylor series up to a given order (see @ref{jet})
@item kbase
vector space basis of free module over the basering modulo the module of
leading terms (see @ref{kbase})
@item lead
initial module (see @ref{lead})
@item lift
lift-matrix (see @ref{lift})
@item liftstd
standard basis and transformation matrix computation (see @ref{liftstd})
@item lres
free resolution (see @ref{lres})
@item minbase
minimal generating set of a homogeneous ideal, resp.@: module, or an ideal, resp.@: module,
over a local ring
@item modulo
represents
@tex
$(h1+h2)/h1=h2/(h1 \cap h2)$
@end tex
@ifinfo
(h1+h2)/h1=h2/(h1 intersect h2)
@end ifinfo
(see @ref{modulo})
@item mres
minimal free resolution of an ideal resp.@: module w.r.t. a minimal set of generators of the given module
(see @ref{mres})
@item mult
multiplicity, resp.@: degree, of the module of leading terms (see @ref{mult})
@item nres
computation of a free resolution of an ideal resp.@: module M which is
minimized from the second free module on (see @ref{nres})
@item ncols
number of columns (see @ref{ncols})
@item nrows
number of rows (see @ref{nrows})
@item print
nice print format (see @ref{print})
@item prune
minimization of the embedding into a free module (see @ref{prune})
@item qhweight
quasihomogeneous weights of an ideal, resp.@: module (see @ref{qhweight})
@item quotient
module quotient (see @ref{quotient})
@item reduce
normalform with respect to a standard basis (see @ref{reduce})
@item res
free resolution of an ideal, resp.@: module, but not changing the given ideal, resp.@: module
(see @ref{res})
@item simplify
simplification of a set of vectors (see @ref{simplify})
@item size
number of non-zero generators (see @ref{size})
@item sortvec
permutation for sorting ideals/modules (see @ref{sortvec})
@item sres
free resolution of a standard basis (see @ref{sres})
@item std
standard basis computation (see @ref{std}, @ref{liftstd})
@item subst
substitution of a ring variable (see @ref{subst})
@item syz
computation of the first syzygy module (see @ref{syz})
@item vdim
vector space dimension of free module over the basering modulo module
of leading terms (see @ref{vdim})
@item weight
"optimal" weights (see @ref{weight})
@end table
@c @*@strong{Example:}
@c @example
@c @end example
@c ---------------------------------------
@node number, package, module, Data types
@section number
@cindex number
@cindex coefficient field
@cindex ground field
@cindex field
@cindex galois field
@cindex finite field
@cindex parameter, as numbers
Numbers are elements from the coefficient ring (or ground ring).
They can only be defined or accessed with respect to a basering
which determines the coefficient field. See @ref{ring declarations} for
declarations of coefficient fields.
@strong{Warning:} Beware of the special meaning of the letter @code{e}
(immediately following a sequence of digits) if the field is real (or complex),
@ref{Miscellaneous oddities}.
@menu
* number declarations::
* number expressions::
* number operations::
* number related functions::
@end menu
@c ------------------------------
@node number declarations, number expressions, number, number
@subsection number declarations
@cindex number declarations
@table @strong
@item Syntax:
@code{number} name @code{=} number_expression @code{;}
@item Purpose:
defines a number.
@item Default:
0
@item Note:
Numbers may only be declared w.r.t. the coefficient field of the current
basering, i.e., a ring
has to be defined prior to any number declaration. See @ref{Rings and
orderings} for a list of the available coefficient fields.
@item Example:
@smallexample
@c example
// finite field Z/p, p<= 32003
ring r = 32003,(x,y,z),dp;
number n = 4/6;
n;
// finite field GF(p^n), p^n <= 32767
// z is a primitive root of the minimal polynomial
ring rg= (7^2,z),x,dp;
number n = 4/9+z;
n;
// the rational numbers
ring r0 = 0,x,dp;
number n = 4/6;
n;
// algebraic extensions of Z/p or Q
ring ra=(0,a),x,dp;
minpoly=a^2+1;
number n=a3+a2+2a-1;
n;
a^2;
// transcedental extensions of Z/p or Q
ring rt=(0,a),x,dp;
number n=a3+a2+2a-1;
n;
a^2;
// machine floating point numbers, single precision
ring R_0=real,x,dp;
number n=4/6;
n;
n=0.25e+2;
n;
// floating point numbers, arbitrary prescribed precision
ring R_1=(real,50),x,dp;
number n=4.0/6;
n;
n=0.25e+2;
n;
// floating point complex numbers, arbitrary prescribed precision
// the third parameter gives the name of the imaginary unit
ring R_2=(complex,50,i),x,dp;
number n=4.0/6;
n;
n=0.25e+2*i+n;
n;
@c example
@end smallexample
@end table
@c ------------------------------
@node number expressions, number operations, number declarations, number
@subsection number expressions
@cindex number expressions
A number expression is:
@enumerate
@item
a rational number (there are NO spaces allowed inside a rational number,
see @ref{int expressions})
@item
a floating point number (if the coefficient field is @code{real}):
@*<digits>@code{.}<digits>@code{e}<sign><digits>
@item
an identifier of type number
@item
a function returning number
@item
an int expression (see @ref{Type conversion and casting})
@item
number expressions combined by the arithmetic operations
@code{+}, @code{-}, @code{*}, @code{/}, @code{^}, or @code{**}.
@item
a type cast to number
@end enumerate
@*@strong{Example:}
@smallexample
@c example
// the following expressions are in any ring int expressions
2 / 3;
4/ 8;
2 /2; // the notation of / for div might change in the future
ring r0=0,x,dp;
2/3, 4/8, 2/2 ; // are numbers
poly f = 2x2 +1;
leadcoef(f);
typeof(_);
ring rr =real,x,dp;
1.7e-2; 1.7e+2; // are valid (but 1.7e2 not), if the field is `real`
ring rp = (31,t),x,dp;
2/3, 4/8, 2/2 ; // are numbers
poly g = (3t2 +1)*x2 +1;
leadcoef(g);
typeof(_);
par(1);
typeof(_);
@c example
@end smallexample
@c ref
See
@ref{ring};
@ref{Type conversion and casting}.
@c ref
@c ------------------------------
@node number operations, number related functions, number expressions, number
@subsection number operations
@cindex number operations
@cindex mod
@cindex +
@cindex -
@cindex *
@cindex /
@cindex %
@cindex ^
@cindex <=
@cindex >=
@cindex ==
@cindex <>
@table @asis
@item @code{+}
addition
@item @code{-}
negation or subtraction
@item @code{*}
multiplication
@item @code{/}
division
@item @code{%}, @code{mod}
modulo
@item @code{^}, @code{**}
power, exponentiation (by an integer)
@item @code{<=, >=, ==, <>}
comparison
@item @code{mod}
integer modulo (the remainder of the division @code{div}), always non-negative
@end table
@strong{Note:} Quotient and exponentiation is only recognized as a
number expression if it is already a number, see @ref{Miscellaneous
oddities}.
@* For the behavior of comparison operators in rings with
ground field different from real or the rational numbers, see @ref{boolean
expressions}.
@*@strong{Example:}
@smallexample
@c example error
ring r=0,x,dp;
number n = 1/2 +1/3;
n;
n/2;
1/2/3;
1/2 * 1/3;
n = 2;
n^-2;
// the following oddities appear here
2/(2+3);
number(2)/(2+3);
2^-2; // for int's exponent must be non-negative
number(2)^-2;
3/4>=2/5;
2/6==1/3;
@c example
@end smallexample
@c ------------------------------
@node number related functions, , number operations, number
@subsection number related functions
@cindex number related functions
@table @code
@item cleardenom
cancellation of denominators of numbers in polyomial and divide it by its content
(see @ref{cleardenom})
@item impart
imaginary part of a complex number, 0 otherwise
(see @ref{impart}, @ref{repart})
@item numerator, denominator
the numerator/denominator of a rational number
(see @ref{numerator}, @ref{denominator})
@item leadcoef
coefficient of the leading term (see @ref{leadcoef})
@item par
n-th parameter of the basering (see @ref{par})
@item pardeg
degree of a number in ring parameters (see @ref{pardeg})
@item parstr
string form of ring parameters (see @ref{parstr})
@item repart
real part of a complex number
(see @ref{impart}, @ref{repart})
@end table
@c ---------------------------------------
@node package, poly, number, Data types
@section package
@cindex package
@cindex ::
The data type package is used to group identifiers into collections.
It is mainly used as an internal means to avoid collisions of names
of identifiers in libraries with variable names defined by the user.
The most important package is the toplevel package, called @code{Top}.
It contains all user defined identifiers as well as all user accessible
library procedures. Identifiers which are local to a library are contained
in a package whose name is obtained from the name of the library, where the
first letter is converted to uppercase, the remaining ones to lowercase.
Another reserved package name is @code{Current} which denotes the current
package name in use.
See also @ref{Libraries}.
@c * package expressions::
@c * package operations::
@menu
* package declarations::
* package related functions::
@end menu
@c ------------------------------
@node package declarations, package related functions, package, package
@subsection package declarations
@cindex package declarations
@table @strong
@item Syntax:
@code{package} name @code{;}
@item Purpose:
defines a package (Only relevant in very special situations).
@item Example:
@smallexample
@c example error
package Test;
int i=3; exportto(Test,i);
Test::i+2;
i;
listvar();
listvar(Test);
package dummy = Test;
kill Test;
listvar(dummy);
@c example
@end smallexample
@end table
@c ------------------------------
@node package related functions, , package declarations, package
@subsection package related functions
@cindex package related functions
@table @code
@item exportto
transfer an identifier to the specified package
(see @ref{exportto})
@item importfrom
generate a copy of an identifier from the specified package in the
current package
(see @ref{importfrom})
@item listvar
list variables currently defined in a given package
(see @ref{listvar})
@item load
load a library or dynamic module
(see @ref{load})
@item LIB
load a library or dynamic module
(see @ref{LIB})
@end table
@c ---------------------------------------
@node poly, proc, package, Data types
@section poly
@cindex poly
Polynomials are the basic data for all main algorithms in
@code{@sc{Singular}}. They consist of finitely many terms
(coefficient*monomial) which are combined by the usual polynomial
operations (see @ref{poly expressions}). Polynomials can only be defined
or accessed with respect to a basering which determines the coefficient
type, the names of the indeterminates and the monomial ordering.
@smallexample
@c example
ring r=32003,(x,y,z),dp;
poly f=x3+y5+z2;
@c example
@end smallexample
@menu
* poly declarations::
* poly expressions::
* poly operations::
* poly related functions::
@end menu
@c ------------------------------
@node poly declarations, poly expressions, poly, poly
@subsection poly declarations
@cindex poly declarations
@table @strong
@item Syntax:
@code{poly} name @code{=} poly_expression @code{;}
@item Purpose:
defines a polynomial.
@item Default:
0
@item Example:
@smallexample
@c example
ring r = 32003,(x,y,z),dp;
poly s1 = x3y2+151x5y+186xy6+169y9;
poly s2 = 1*x^2*y^2*z^2+3z8;
poly s3 = 5/4x4y2+4/5*x*y^5+2x2y2z3+y7+11x10;
int a,b,c,t=37,5,4,1;
poly f=3*x^a+x*y^(b+c)+t*x^a*y^b*z^c;
f;
short = 0;
f;
@c example
@end smallexample
@end table
@c ref
@ref{short}
@c ref
@c ------------------------------
@node poly expressions, poly operations, poly declarations, poly
@subsection poly expressions
@cindex poly expressions
A polynomial expression is (optional parts in square brackets):
@enumerate
@item
a monomial (there are NO spaces allowed inside a monomial)
@smallexample
[coefficient] ring_variable [ exponent] [ring_variable [exponent] @dots{}].
@end smallexample
Monomials which contain an indexed ring variable
must be built from @code{ring_variable} and @code{coefficient}
with the operations @code{*} and @code{^}
@item
an identifier of type poly
@item
a function returning poly
@item
polynomial expressions combined by the arithmetic operations
@code{+}, @code{-}, @code{*}, @code{/}, or @code{^}
@item
an int expression (see @ref{Type conversion and casting})
@item
a type cast to poly
@end enumerate
@*@strong{Example:}
@smallexample
ring S=0,(x,y,z,a(1)),dp;
2x, x3, 2x2y3, xyz, 2xy2; // are monomials
2*x, x^3, 2*x^2*y^3, x*y*z, 2*x*y^2; // are poly expressions
2*a(1); // is a valid polynomial expression (a(1) is a name of a variable),
// but not 2a(1) (is a syntax error)
2*x^3; // is a valid polynomial expression equal to 2x3 (a valid monomial)
// but not equal to 2x^3 which will be interpreted as (2x)^3
// since 2x is a monomial
@c example
ring r=0,(x,y),dp;
poly f = 10x2y3 +2x2y2-2xy+y -x+2;
lead(f);
leadmonom(f);
simplify(f,1); // normalize leading coefficient
poly g = 1/2x2 + 1/3y;
cleardenom(g);
int i = 102;
poly(i);
typeof(_);
@c example
@end smallexample
@c ref
See @ref{ring}; @ref{Type conversion and casting}.
@c ref
@c ------------------------------
@node poly operations, poly related functions, poly expressions, poly
@subsection poly operations
@cindex poly operations
@cindex +
@cindex -
@cindex *
@cindex /
@cindex div
@cindex %
@cindex mod
@cindex ^
@cindex <
@cindex <=
@cindex >
@cindex >=
@cindex ==
@cindex <>
@cindex []
@table @asis
@item @code{+}
addition
@item @code{-}
negation or subtraction
@item @code{*}
multiplication
@item @code{/}, @code{div}
division by a polynomial, ignoring the remainder
(only implemented for polynomials over QQ, ZZ/p and field extensions of them)@*
(See also @ref{quotient},@ref{division},@ref{reduce})
@item @code{%}, @code{mod}
the remainder from the division by a polynomial
(only implemented for polynomials over QQ, ZZ/p and field extensions of them)@*
(See also @ref{quotient},@ref{division},@ref{reduce})
@item @code{^}, @code{**}
power by a positive integer
@item @code{<}, @code{<=}, @code{>}, @code{>=}, @code{==}, @code{<>}
comparators (considering leading monomials w.r.t. monomial ordering)
@item poly_expression @code{[} intvec_expression @code{]}
the sum of monomials at the indicated places w.r.t. the monomial ordering
@end table
@*@strong{Example:}
@smallexample
@c example
ring R=0,(x,y),dp;
poly f = x3y2 + 2x2y2 + xy - x + y + 1;
f;
f + x5 + 2;
f * x2;
(x+y)/x;
f/3x2;
x5 > f;
x<=y;
x>y;
ring r=0,(x,y),ds;
poly f = fetch(R,f);
f;
x5 > f;
f[2..4];
size(f);
f[size(f)+1]; f[-1]; // monomials out of range are 0
intvec v = 6,1,3;
f[v]; // the polynom built from the 1st, 3rd and 6th monomial of f
@c example
@end smallexample
@c ------------------------------
@node poly related functions, , poly operations, poly
@subsection poly related functions
@cindex poly related functions
@table @code
@item cleardenom
cancellation of denominators of numbers in polynomial and divide it by its content
(see @ref{cleardenom}; @ref{content})
@item coef
matrix of coefficients and monomials (see @ref{coef})
@item coeffs
matrix of coefficients (see @ref{coeffs})
@item deg
degree (see @ref{deg})
@c @item det
@c determinant (see @ref{det})
@item diff
partial derivative (see @ref{diff})
@item extgcd
Bezout representation of gcd (see @ref{extgcd})
@item factorize
factorization of polynomial (see @ref{factorize})
@item finduni
univariate polynomials in a zero-dimensional ideal (see @ref{finduni})
@item gcd
greatest common divisor (see @ref{gcd})
@item homog
homogenization (see @ref{homog})
@item jacob
ideal, resp.@: matrix, of all partial derivatives (see @ref{jacob})
@item lead
leading term (see @ref{lead})
@item leadcoef
coefficient of the leading term (see @ref{leadcoef})
@item leadexp
the exponent vector of the leading monomial (see @ref{leadexp})
@item leadmonom
leading monomial (see @ref{leadmonom})
@item jet
monomials of degree at most k (see @ref{jet})
@item ord
degree of the leading monomial (see @ref{ord})
@item qhweight
quasihomogeneous weights (see @ref{qhweight})
@item reduce
normal form with respect to a standard base (see @ref{reduce})
@item rvar
test for ring variable (see @ref{rvar})
@item simplify
normalization of a polynomial (see @ref{simplify})
@item size
number of monomials (see @ref{size})
@item subst
substitution of a ring variable (see @ref{subst})
@item trace
trace of a matrix (see @ref{trace})
@item var
the indicated variable of the ring (see @ref{var})
@item varstr
variable(s) in string form (see @ref{varstr})
@end table
@c @*@strong{Example:}
@c @example
@c @end example
@c ---------------------------------------
@node proc, resolution, poly, Data types
@section proc
@cindex proc
Procedures are sequences of @sc{Singular} commands in a special
format. They are used to extend the set of @sc{Singular} commands with
user defined commands. Once a procedure is defined it can be used as
any other @sc{Singular} command. Procedures may be defined by either
typing them on the command line or by loading them from a file. For a
detailed description on the concept of procedures in @sc{Singular} see
@ref{Procedures}. A file containing procedure definitions which comply with
certain syntax rules is called a library. Such a file is loaded
using the command @code{LIB}. For more information on libraries see
@ref{Libraries}.
@menu
* proc declaration::
* proc expression::
* procs with different argument types::
@end menu
@c ---------------------------------------
@node proc declaration, proc expression , proc, proc
@subsection proc declaration
@cindex proc declaration
@c ------------------------------------------------------------
@c This piece of text exists also in the file general.doc,
@c chapter "Proc in a library".
@c If you change something here, change it there, too!
@c ------------------------------------------------------------
@table @strong
@item Syntax:
[@code{static}] @code{proc} proc_name [(<parameter_list>)
@*[<help_string>]
@*@code{@{}
@*
@tex
\quad
@end tex
<procedure_body>
@*@code{@}}
@*[@code{example}
@*@code{@{}
@*
@tex
\quad
@end tex
<sequence_of_commands>
@*@code{@}}]
@item Purpose:
Defines a new function, the @code{proc} proc_name. Once loaded in a
@sc{Singular} session, the information provided in the help string will be
displayed upon entering @code{help proc_name;}, while the @code{example}
section will be executed upon entering @code{example proc_name;}.
@xref{Parameter list}, @ref{Help string}, and the example in
@ref{Procedures in a library}.
@* The help string, the parameter list, and the example section are optional.
They are, however, mandatory for the procedures listed in the header of a library.
The help string is ignored and no example section is allowed if the procedure is defined
interactively, i.e., if it is not loaded from a file by the @code{LIB} or @code{load}
command (@pxref{LIB} and @pxref{load} ).
@* In the body of a library, each procedure not meant to be accessible by
users should be declared static. @xref{Procedures in a library}.
@item Example:
@smallexample
@c example
proc milnor_number (poly p)
{
ideal i= std(jacob(p));
int m_nr=vdim(i);
if (m_nr<0)
{
"// not an isolated singularity";
}
return(m_nr); // the value of m_nr is returned
}
ring r1=0,(x,y,z),ds;
poly p=x^2+y^2+z^5;
milnor_number(p);
@c example
@end smallexample
@end table
@c ref
See
@ref{apply};
@ref{LIB};
@ref{Libraries};
@ref{Procedures}
@c ref
@c ---------------------------------------
@node proc expression,procs with different argument types,proc declaration, proc
@subsection proc expression
@cindex proc expression
@cindex ->
@table @strong
@item Syntax:
variable_name @code{-> @{} expression(s) @code{@}}
@item Purpose:
Defines a new function, within @code{apply} or for assigning.
@item Example:
@smallexample
@c example
apply(1..3,x->{x**2});
@c example
@end smallexample
@end table
@c ref
See
@ref{apply};
@ref{proc};
@ref{proc declaration}
@c ref
@c ---------------------------------------
@node procs with different argument types, ,proc expression, proc
@subsection procs with different argument types
@cindex procs with different argument types
@cindex branchTo
@table @strong
@item Syntax:
@code{branchTo (} string_expression @code{,} ... proc_name @code{)}
@item Purpose:
branch to the given procedure if the argument types matches the
types given as strings (which may be empty - matching the empty argument list).
The main procedure (@code{p} in the example) must be defined without an argument list, and @code{branchTo} statement must be the first statement within
the procedure body.
@item Example:
@smallexample
@c example error
proc p1(int i) { "int:",i; }
proc p21(string s) { "string:",s; }
proc p22(string s1, string s2) { "two strings:",s1,s2; }
proc p()
{ branchTo("int",p1);
branchTo("string","string",p22);
branchTo("string",p21);
ERROR("not defined for these argument types");
}
p(1);
p("hu");
p("ha","ha");
p(1,"hu");
@c example
@end smallexample
@end table
@c ref
See
@ref{proc};
@ref{proc declaration}
@c ref
@c ---------------------------------------
@node resolution, ring, proc, Data types
@section resolution
@cindex resolution
The type resolution is intended as an intermediate representation which
internally retains additional information obtained during computation of
resolutions. It furthermore enables the use of partial results to
compute, for example, Betti numbers or minimal resolutions. Like ideals
and modules, a resolution can only be defined w.r.t.@: a basering
(see @ref{Syzygies and resolutions}).
@strong{Note:}
To access the elements of a resolution, it has to be assigned to a list.
This assignment also completes computations and may therefore take time,
(resp.@: an access directly with the brackets @code{[ , ]} causes
implicitly a cast to a list).
@menu
* resolution declarations::
* resolution expressions::
* resolution related functions::
@end menu
@c ---------------------------------------
@node resolution declarations, resolution expressions, resolution, resolution
@subsection resolution declarations
@cindex resolution declarations
@table @strong
@item Syntax:
@code{resolution} name @code{=} resolution_expression @code{;}
@item Purpose:
defines a resolution.
@item Default:
none
@item Example:
@smallexample
@c example
ring R;
ideal i=z2,x;
resolution re=res(i,0);
re;
betti(re);
list l = re;
l;
@c example
@end smallexample
@end table
@c ------------------------------
@node resolution expressions, resolution related functions, resolution declarations, resolution
@subsection resolution expressions
@cindex resolution expressions
A resolution expression is:
@enumerate
@item
an identifier of type resolution
@item
a function returning a resolution
@item
a type cast to resolution from a list of ideals, resp.@: modules..
@end enumerate
@c ref
See @ref{Type conversion and casting}.
@c ref
@c ------------------------------
@node resolution related functions, , resolution expressions, resolution
@subsection resolution related functions
@cindex resolution related functions
@table @code
@item betti
Betti numbers of a resolution (see @ref{betti})
@item fres
free resolution of a standard basis (see @ref{fres})
@item lres
free resolution (see @ref{lres})
@item minres
minimize a free resolution (see @ref{minres})
@item mres
minimal free resolution of an ideal, resp.@: module and a minimal set of generators of
the given ideal, resp.@: module (see @ref{mres})
@item res
free resolution of an ideal, resp.@: module, but not changing the
given ideal, resp.@: module (see @ref{res})
@item sres
free resolution of a standard basis (see @ref{sres})
@end table
@c @*@strong{Example:}
@c @example
@c @end example
@c ---------------------------------------
@node ring
@section ring
@cindex ring
Rings are used to describe properties of polynomials, ideals etc.
Almost all computations in @sc{Singular} require a basering.
For a detailed description of the concept of rings see
@ref{Rings and orderings}.
@menu
* qring::
* ring declarations::
* ring related functions::
* ring operations::
* qring declaration::
@end menu
@c --------------------------------------------
@node qring
@subsection qring
@cindex qring
@sc{Singular} offers the opportunity to calculate in quotient rings
(factor rings), i.e., rings modulo an ideal. The ideal has to be given
as a standard basis. For a detailed description of the concept
of rings and quotient rings see @ref{Rings and orderings}.
Beside the construction, an object describing a quotient ring is of type @code{ring}.
@c ref
See
@ref{qring declaration}.
@c ref
@c ---------------------------------------
@node ring declarations, ring related functions, qring, ring
@subsection ring declarations
@cindex ring declarations
@table @strong
@item Syntax:
@code{ring} name @code{= (} coefficients @code{),}
@code{(} names_of_ring_variables @code{),}
@code{(} ordering @code{);}
or@*
@code{ring} name @code{=} cring
@code{[} names_of_ring_variables @code{]}
@item Default:
@code{(ZZ/32003)[x,y,z]}
@item Purpose:
declares a ring and sets it as the actual basering.
The second form sets the ordering to @code{(dp,C)}.
@end table
For the second form: @code{cring} stands currently for @code{QQ} (the rationals), @code{ZZ} (the integers)
or @code{(ZZ/m)} (the field (m prime and <2147483648) resp. ring of the integers modulo m).
The coefficients for the first form are given by one of the following:
@enumerate
@item
a @code{cring} as given above
@item
a non-negative int_expression less or equal 2147483647.
@item
an expression_list of an int_expression and one or more names.
@item
the name @code{real}
@item
an expression_list of the name @code{real} and an int_expression.
@item
an expression_list of the name @code{complex}, an optional int_expression
and a name.
@item
an expression_list of the name @code{ZZ}.
@item
an expression_list of the name @code{integer} and following int_expressions.
@item
an expression_list of the name @code{integer} and two int_expressions.
@end enumerate
For the definition of the 'coefficients', see @ref{Rings and orderings}.
'names_of_ring_variables' must be a list of names or (multi-)indexed names.
'ordering' is a list of block orderings where each block ordering is either
@enumerate
@item
@code{lp}, @code{dp}, @code{Dp}, @code{rp}, @code{ls}, @code{ds}, @code{Ds},
or @code{rs} optionally followed by a size parameter in parentheses.
@item
@code{wp}, @code{Wp}, @code{ws}, @code{Ws}, @code{am}, @code{aa}, or @code{a} followed by a
weight vector given as an intvec_expression in parentheses.
@item
@code{M} followed by an intmat_expression in parentheses.
@item
@code{c} or @code{C}.
@end enumerate
For the definition of the orderings, see @ref{Term orderings},
@ref{Monomial orderings}.
If one of coefficients, names_of_ring_variables, and ordering
consists of only one entry, the parentheses around this entry may be
omitted.
@c ref
See also
@ref{Examples of ring declarations};
@ref{ring};
@ref{ringlist}.
@c ref
@c ---------------------------------------
@node ring related functions, ring operations, ring declarations, ring
@subsection ring related functions
@cindex ring related functions
@table @code
@item charstr
description of the coefficient field of a ring (see @ref{charstr})
@item keepring
move ring to next upper level (see @ref{keepring})
@item npars
number of ring parameters (see @ref{npars})
@item nvars
number of ring variables (see @ref{nvars})
@item ordstr
monomial ordering of a ring (see @ref{ordstr})
@item parstr
names of all ring parameters or the
name of the n-th ring parameter (see @ref{parstr})
@item qring
quotient ring (see @ref{qring})
@item ringlist
decomposition of a ring into a list of its components (see @ref{ringlist})
@item setring
setting of a new basering (see @ref{setring})
@item varstr
names of all ring variables or the
name of the n-th ring variable (see @ref{varstr})
@end table
@c ---------------------------------------
@node ring operations, qring declaration, ring related functions, ring
@subsection ring operations
@cindex ring operations
@cindex +
@cindex ==
@cindex <>
@table @asis
@item @code{+}
construct a new ring @math{k[X,Y]} from @math{k_1[X]} and @math{k_2[Y]}.
(The sets of variables must be distinct).
@item @code{==},@code{<>}
compare two rings
@end table
@strong{Note:}
Concerning the ground fields @math{k_1} and @math{k_2} take the
following guide lines into consideration:
@itemize @bullet
@item Neither @math{k_1} nor @math{k_2} may be @math{R} or @math{C}.
@item If the characteristic of @math{k_1} and @math{k_2} differs, then one of them must be @math{Q}.
@item At most one of @math{k_1} and @math{k_2} may have parameters.
@item If one of @math{k_1} and @math{k_2} is an algebraic extension of @math{Z/p} it may not be defined by a @code{charstr} of type @code{(p^n,a)}.
@end itemize
@strong{Example:}
@smallexample
@c example
ring R1=0,(x,y),dp;
ring R2=32003,(a,b),dp;
def R=R1+R2;
R;
@c example
@end smallexample
@c ref
@ref{ring_lib}
@c ref
@c ---------------------------------------
@node qring declaration, , ring operations, qring
@subsection qring declaration
@cindex qring declaration
@c ------------------------------------------------------------
@c This piece of text exists also in the file general.doc,
@c chapter "General syntax of a ring declaration".
@c If you change something here, change it there, too!
@c ------------------------------------------------------------
@table @strong
@item Syntax:
@code{qring} name @code{=} ideal_expression @code{;}
@item Default:
none
@item Purpose:
declares a quotient ring as the basering modulo ideal_expression and sets
it as current basering.
Operations based on standard bases (e.g. @code{std},@code{groebner}, etc., @code{reduce}) and functions which require a standard basis (e.g. @code{dim},@code{hilb}, etc.) operated with the residue classes; all others on the polynomial objects.
@item Example:
@smallexample
@c example
ring r=0,(x,y,z),dp;
ideal i=xy;
qring q=std(i);
basering;
// simplification is not immediate:
(x+y)^2;
reduce(_,std(0));
// polynomial and residue class:
ring R=0,(x,y),dp;
qring Q=std(y);
poly p1=x;
poly p2=x+y;
// comparing polynomial objects:
p1==p2;
// comparing residue classes:
reduce(p1,std(0))==reduce(p2,std(0));
@c example
@end smallexample
@end table
@c ---------------------------------------
@node smatrix
@section smatrix
@cindex smatrix
An experimental type:@*
Objects of type smatrix are (sparse) matrices with polynomial entries.
Like polynomials they can
only be defined or accessed with respect to a basering.
Objects of type @code{smatrix} can be converted to and from @code{matrix} and @code{module}.@*
Operations are @code{+}, @code{-}, @code{*}, @code{==}, @code{<>}.@*
Functions are @code{chinrem}, @code{farey}, @code{ncols}, @code{nrows},
@code{std}, @code{transpose}, @code{tensor}.
Additional @code{flatten(m)} and @code{system("unflatten",m,col)}.@*
Resizing can be done via @code{smatrix(m,r,c)} where m is of type @code{module} or @code{smatrix}.@*
Access to single entries: @code{m[i,j]}
@c ref
See
@ref{ring};
@ref{matrix};
@ref{module};
@ref{chinrem};
@ref{farey};
@ref{ncols};
@ref{nrows};
@ref{std};
@ref{transpose};
@ref{tensor};
@ref{flatten}.
@c ref
@c ---------------------------------------
@node string
@section string
@cindex string
@cindex newline
Variables of type @code{string} are used for output (almost every type
can be "converted" to @code{string}) and for creating new
commands at runtime see @ref{execute}. They are also return values of
certain interpreter related functions (see @ref{Functions}). String
constants consist of a sequence of ANY characters (including newline!)
between a starting @code{"} and a closing @code{"}. There is also a
string constant @code{newline}, which is the newline character. The
@code{+} sign "adds" strings, @code{""} is the empty string (hence
strings form a semigroup). Strings may be used to comment the output of
a computation or to give it a nice format. Strings may also be used for
intermediate conversion of one type into another.
@smallexample
@c example
string s="Hi";
string s1="a string with new line at the end"+newline;
string s2="another string with new line at the end
";
s;s1;s2;
ring r; ideal i=std(ideal(x,y^3));
"dimension of i =",dim(i),", multiplicity of i =",mult(i);
"dimension of i = "+string(dim(i))+", multiplicity of i = "+string(mult(i));
"a"+"b","c";
@c example
@end smallexample
A comma between two strings makes an expression list out of them
(such a list is printed with a separating blank in between),
while a @code{+} concatenates strings.
@menu
* string declarations::
* string expressions::
* string type cast::
* string operations::
* string related functions::
@end menu
@c ------------------------------
@node string declarations, string expressions, string, string
@subsection string declarations
@cindex string declarations
@table @strong
@item Syntax:
@code{string} name @code{=} string_expression @code{;}
@*@code{string} name @code{=} list_of_string_expressions @code{;}
@item Purpose:
defines a string variable.
@item Default:
"" (the empty string)
@item Example:
@smallexample
@c example
string s1="Now I know";
string s2="how to encode a \" in a string...";
string s=s1+" "+s2; // concatenation of 3 strings
s;
s1,s2; // 2 strings, separated by a blank in the output:
@c example
@end smallexample
@end table
@c ------------------------------
@node string expressions, string type cast, string declarations, string
@subsection string expressions
@cindex string expressions
A string expression is:
@enumerate
@item
a sequence of characters between two unescaped quotes (@code{"})
@item
an identifier of type string
@item
a function returning string
@item
a substring (using the bracket operator)
@item
a type cast to string (@pxref{string type cast})
@item
string expressions combined by the operation @code{+}.
@end enumerate
@*@strong{Example:}
@smallexample
@c // a string constant
@c "@dots{}";
@c // a type cast from name
@c string(name)
@c // concatenation
@c string_expression + string_expression
@c example
// string_expression[start, length] : a substring
// (possibly filled up with blanks)
// the substring of s starting at position 2
// with a length of 4
string s="123456";
s[2,4];
"abcd"[2,2];
// string_expression[position] : a character from a string
s[3];
// string_expression[position..position] :
// a substring starting at the first position up to the second
// given position
s[2..4];
// a function returning a string
typeof(s);
@c example
@end smallexample
@c ref
See @ref{Type conversion and casting}
@ref{string type cast}
@c ref
@c ------------------------------
@node string type cast, string operations, string expressions, string
@subsection string type cast
@cindex string type cast
@table @code
@item @strong{Syntax:}
@code{string (} expression [, expression_2, ... expression_n]@code{)}
@item @strong{Type:}
string
@item @strong{Purpose:}
Converts each expression to a string, where expression can be of any
type. The concatenated string of all converted expressions is returned.
@*The elements of intvec, intmat, ideal, module, matrix, and list, are
separated by a comma. No newlines are inserted.
@*Not defined elements of a list are omitted.
@*For link, the name of the link is used.
@*For map, the ideal defining the mapping is converted.
@item @strong{Note:}
When applied to a list, elements of type intvec, intmat, ideal, module,
matrix, and list become indistinguishable.
@item @strong{Example:}
@smallexample
@c example
string("1+1=", 2);
string(intvec(1,2,3,4));
string(intmat(intvec(1,2,3,4), 2, 2));
ring r;
string(r);
string(ideal(x,y));
qring R = std(ideal(x,y));
string(R);
map phi = r, ideal(x,z);
string(phi);
list l;
string(l);
l[3] = 1;
string(l); // notice that l[1],l[2] are omitted
l[2] = l;
l;
string(l); // notice that lists of list is flattened
l[1] = intvec(1,2,3);
l;
string(l); // notice that intvec elements are not distinguishable
@c example
@end smallexample
@end table
@c ref
See
@ref{string};
@ref{Type conversion and casting};
@ref{print}.
@c ref
@c ------------------------------
@node string operations, string related functions, string type cast, string
@subsection string operations
@cindex string operations
@cindex +
@cindex <=
@cindex >=
@cindex ==
@cindex <>
@cindex []
@table @asis
@item @code{+}
concatenation
@item @code{<=}, @code{>=}, @code{==}, @code{<>}
comparison (lexicographical with respect to the ASCII encoding)
@item string_expression @code{[} int_expression @code{]}
is a character of the string; the index 1 gives the first character.
@item string_expression @code{[} int_expression@code{,} int_expression @code{]}
is a substring, where the first argument is the start index and the
second is the length of the substring, filled up with blanks if the
length exceeds the total size of the string
@item string_expression @code{[} intvec_expression @code{]}
is a expression list of characters from the string
@end table
@*@strong{Example:}
@smallexample
@c example
string s="abcde";
s[2];
s[3,2];
">>"+s[1,10]+"<<";
s[2]="BC"; s;
intvec v=1,3,5;
s=s[v]; s;
s="654321"; s=s[3..5]; s;
@c example
@end smallexample
@c ------------------------------
@node string related functions, , string operations, string
@subsection string related functions
@cindex string related functions
@table @code
@item charstr
description of the coefficient field of a ring (see @ref{charstr})
@item execute
executing string as command (see @ref{execute})
@item find
position of a substring in a string (see @ref{find})
@item names
list of strings of all user-defined variable names (see @ref{names})
@item nameof
name of an object (see @ref{nameof})
@item option
lists all defined options (see @ref{option})
@item ordstr
monomial ordering of a ring (see @ref{ordstr})
@item parstr
names of all ring parameters or the
name of the n-th ring parameter (see @ref{parstr})
@item read
read a file (see @ref{read})
@item size
length of a string (see @ref{size})
@item sprintf
string formatting (see @ref{sprintf})
@item typeof
type of an object (see @ref{typeof})
@item varstr
names of all ring variables or the
name of the n-th ring variable (see @ref{varstr})
@end table
@c @*@strong{Example:}
@c @example
@c @end example
@c ---------------------------------------
@node vector, User defined types , string, Data types
@section vector
@cindex vector
Vectors are elements of a free module over the basering with basis
@code{gen(1)}, @code{gen(2)}, @dots{} .
Like polynomials they
can only be defined or accessed with respect to the basering.
Each vector belongs to a free module of rank equal to the biggest index
of a generator with non-zero coefficient. Since generators with zero
coefficients need not be written any vector may be considered
also as an element of a free module of higher rank.
(E.g., if @code{f} and @code{g} are polynomials then
@code{f*gen(1)+g*gen(3)+gen(4)} may also be written as @code{[f,0,g,1]}
or as @code{[f,0,g,1,0]}.)
Note that the elements of a vector have to be
surrounded by square brackets (@code{[} , @code{]})
(cf. @ref{Representation of mathematical objects}).
@menu
* vector declarations::
* vector expressions::
* vector operations::
* vector related functions::
@end menu
@c ------------------------------
@node vector declarations, vector expressions, vector, vector
@subsection vector declarations
@cindex vector declarations
@table @strong
@item Syntax:
@code{vector} name @code{=} vector_expression @code{;}
@item Purpose:
defines a vector of polynomials (an element of a free module).
@item Default:
[0]
@item Example:
@smallexample
@c example
ring r=0,(x,y,z),(c,dp);
poly s1 = x2;
poly s2 = y3;
poly s3 = z;
vector v = [s1, s2-s1, s3-s1]+ s1*gen(5);
// v is a vector in the free module of rank 5
v;
@c example
@end smallexample
@end table
@c ------------------------------
@node vector expressions, vector operations, vector declarations, vector
@subsection vector expressions
@cindex vector expressions
A vector expression is:
@enumerate
@item
an identifier of type vector
@item
a function returning vector
@item
a polynomial expression (via the canonical embedding @code{p} @expansion{} @code{p*gen(1)})
@item
vector expressions combined by the arithmetic operations @code{+} or
@code{-}
@item
a polynomial expression and a vector expression combined by the arithmetic
operation @code{*}
@item
a type cast to vector using the brackets @code{[} , @code{]}
@end enumerate
@*@strong{Example:}
@smallexample
@c example
// ordering gives priority to components:
ring rr=0,(x,y,z),(c,dp);
vector v=[x2+y3,2,0,x*y]+gen(6)*x6;
v;
vector w=[z3-x,3y];
v-w;
v*(z+x);
// ordering gives priority to monomials:
// this results in a different output
ring r=0,(x,y,z),(dp,c);
imap(rr,v);
@c example
@end smallexample
@c ref
See
@ref{ring};
@ref{Type conversion and casting}.
@c ref
@c ------------------------------
@node vector operations, vector related functions, vector expressions, vector
@subsection vector operations
@cindex vector operations
@cindex +
@cindex -
@cindex /
@cindex <
@cindex <=
@cindex >
@cindex >=
@cindex ==
@cindex <>
@cindex []
@table @asis
@item @code{+}
addition
@item @code{-}
negation or subtraction
@item @code{/}
division by a monomial, not divisible terms yield 0
@item @code{<}, @code{<=}, @code{>}, @code{>=}, @code{==}, @code{<>}
comparators (considering leading terms w.r.t. monomial ordering)
@item vector_expression @code{[} int_expressions @code{]}
is a vector entry; the index 1 gives the first entry.
@end table
@*@strong{Example:}
@smallexample
@c example
ring R=0,(x,y),(c,dp);
[x,y]-[1,x];
[1,2,x,4][3];
@c example
@end smallexample
@c ------------------------------
@node vector related functions, , vector operations, vector
@subsection vector related functions
@cindex vector related functions
@table @code
@item cleardenom
quotient of a vector by its content (see @ref{cleardenom})
@item coeffs
matrix of coefficients (see @ref{coeffs})
@item deg
degree (see @ref{deg})
@item diff
partial derivative (see @ref{diff})
@item gen
i-th generator (see @ref{gen})
@item homog
homogenization (see @ref{homog})
@item jet
k-jet: monomials of degree at most k (see @ref{jet})
@item lead
leading term (see @ref{lead})
@item leadcoef
leading coefficient (see @ref{leadcoef})
@item leadexp
the exponent vector of the leading monomial (see @ref{leadexp})
@item leadmonom
leading monomial (see @ref{leadmonom})
@item nrows
number of rows (see @ref{nrows})
@item ord
degree of the leading monomial (see @ref{ord})
@item reduce
normal form with respect to a standard base (see @ref{reduce})
@item simplify
normalize a vector (see @ref{simplify})
@item size
number of monomials (see @ref{size})
@item subst
substitute a ring variable (see @ref{subst})
@end table
@c @*@strong{Example:}
@c @example
@c @end example
@c ---------------------------------------
@node User defined types, cone, vector, Data types
@section User defined types
@cindex User defined types
@cindex newstruct
User defined types are (non-empty) lists with a fixed size
whose element can be accessed by names (and not indices).
These elements have a predefined type (which can also be a user defined type).
If these elements depend on a ring they can only be accessed if
their base ring is the current base ring.
In contrast to usual lists the elements of a user defined type may
belong to different rings.
@menu
* Definition of a user defined type::
* Declaration of objects of a user defined type::
* Access to elements of a user defined type::
* Commands for user defined types::
* Assignments for user defined types::
@end menu
@c ------------------------------
@node Definition of a user defined type, Declaration of objects of a user defined type, User defined types, User defined types
@subsection Definition of a user defined type
@cindex Definition of a user defined type
@cindex type,custom
@cindex custom type
@table @strong
@item Syntax:
@code{newstruct(} name @code{,} string_expression @code{);}
@*@code{newstruct(} name @code{,} name @code{,} string_expression @code{);}
@item Purpose:
defines a new type with elements given by the last argument (string_expression).
The name of the new type is the first argument (of type string) and must
be longer than one character.
@*The second name (of type string) is an already defined type
which should be extended by the new type.
@*The last argument (of type string) must be an comma separated list of
a type followed by a name.
If there are duplicate member names, the last one wins.
@*(User defined) member names are restricted to alphanumeric characters and must start with a letter.
@item Operations:
the only operations of user defined types are:
@table @asis
@item assignment (between objects of the same or extended type)
@item @code{typeof}
@item @code{string} and printing
@item operator @code{.} to access the elements
@end table
@item Example:
@smallexample
@c example
newstruct("nt","int a,poly b,string c");
nt A;
nt B;
A.a=3;
A.c=string(A.a);
B=A;
newstruct("t2","nt","string c");
t2 C; C.c="t2-c";
A=C;
typeof(A);
A;
// a motivating example ------------------------------------------
newstruct("IDEAL","ideal I,proc prettyprint");
newstruct("HOMOGENEOUS_IDEAL","IDEAL","intvec weights,proc prettyprint");
proc IDEAL_pretty_print(IDEAL I)
{
"ideal generated by";
I.I;
}
proc H_IDEAL_pretty_print(HOMOGENEOUS_IDEAL I)
{
"homogeneous ideal generated by";
I.I;
"with weights";
I.weights;
}
proc p_print(IDEAL I) { I.prettyprint(I); }
ring r;
IDEAL I;
I.I=ideal(x+y2,z);
I.prettyprint=IDEAL_pretty_print;
HOMOGENEOUS_IDEAL H;
H.I=ideal(x,y,z);
H.prettyprint=H_IDEAL_pretty_print;
H.weights=intvec(1,1,1);
p_print(I);
p_print(H);
@c example
@end smallexample
@end table
@c ------------------------------------------------------------------
@node Declaration of objects of a user defined type, Access to elements of a user defined type, Definition of a user defined type, User defined types
@subsection Declaration of objects of a user defined type
@cindex Declaration of objects of a user defined type
@*@strong{Example:}
@smallexample
@c example
newstruct("nt","int a,poly b,string c");
nt A;
// as long as there is no value assigned to A.b, no ring is needed
nt B=A;
@c example
@end smallexample
@c @c ref
@c See
@c @ref{ring};
@c @ref{Type conversion and casting}.
@c @c ref
@c ------------------------------
@node Access to elements of a user defined type, Commands for user defined types, Declaration of objects of a user defined type, User defined types
@subsection Access to elements of a user defined type
@cindex Access to elements of a user defined type
Access to elements of a user defined type via @code{.}:
<object>.<element_name>. The <element_names> are from the definition of the type. Additional, all (potentially) ring dependent elements have an additional
entry @code{r_}<element_name> for the corresponding ring.
@*@strong{Example:}
@smallexample
@c example
newstruct("nt","int a,poly b,string c");
nt A;
3+A.a;
A.c="example string";
ring r;
A.b=poly(1); // assignment: expression must be of the given type
A;
A.r_b;
@c example
@end smallexample
@c ------------------------------
@node Commands for user defined types, Assignments for user defined types,Access to elements of a user defined type, User defined types
@subsection Commands for user defined types
@cindex Commands for user defined types
@cindex command,custom
@cindex custom command
User defined types are normal data types (which do not belong to a ring,
even if they have ring dependent parts), so they can be passed as argument
to procedures, and received as result from procedures.
In order to apply kernel commands to these types (like @code{string}, @code{+}),
provide a usual procedure (say @code{proc p}..) for that task and
install it via @code{system("install",} user_type @code{,} kernel_command @code{,p,} number_of_args @code{);}.
The user_type and kernel_command have to be given as strings.
For kernel_command having a variable number of arguments (internal @code{CMD_M})
use 4 independent of the number of really supplied arguments.
List of available kernel commands and the required number_of_args,
some accept several variants and appear therefore at several places:
@itemize
@item inplace binary operands: @code{+,-,*,/,div,%,&,|, [}, number_of_args:2
@item unary functions:
@code{attrib, bareiss, betti, char, char_series, charstr, cleardenom, close, convhull,
defined, deg, degree, denominator, det, dim, dump, ERROR, envelope, execute, facstd,
factorize, finduni, gen, getdump, hilb, impart, indepSet, interred, jacob, janet,
kbase, killattrib, lead, leadcoef, leadexp, leadmonom, load, ludecomp, maxideal,
memory, minbase, minres, monitor, monomial, mult, mstd, nameof, ncols, npars, nrows,
numerator, nvars, open, opposite, ord, ordstr, par, pardeg, parstr, preimage, prime,
primefactors, prune, qhweight, rank, read, regularity, repart, ringlist, rvar, sba,
size, slimgb, sortvec, sqrfree, syz, trace, transpose, twostd, typeof, univariate,
var, variables, varstr, vdim, waitfirst, waitall, weight}
@item functions with 2 arguments:
@code{attrib, betti, bracket, chinrem, coeffs, contract, deg, delete, diff, dim, extgcd,
eliminate, exportto, facstd, factorize, farey, fetch, fglm, fglmquot, find, fres, frwalk, gcd,
hilb, homog, hres, imap, importfrom, indepSet, insert, interpolation, janet, kbase, kernel,
killattrib, koszul, lift, liftstd, load, lres, modulo, mpresmat, mres, newstruct, nc_algebra,
nres, oppose, parstr, primefactors, quotient, random, rank, read, sba, simplify, sqrfree,
sres, varstr, waitfirst, waitall, wedge}
@item functions with 3 arguments:
@code{attrib, bareiss, coeffs, eliminate, find, fres, frwalk, hilb, homog, insert, koszul,
laguerre, lift, liftstd, newstruct, preimage, random, resultant, sba, vandermonde}
@item functions with variable number of arguments arguments (number_of_args:4):
@code{breakpoint, coef, dbprint, division, factmodd, intersect, jet, luinverse, lusolve,
minor, names, option, qrds, reduce, reservedName, simplex, status, std, subst, system,
test, uressolve, write}
@c @item type casts
@end itemize
@*@strong{Example:}
@smallexample
@c example
newstruct("nt","int a,poly b,string c");
nt A;
A;
ring r;
// a pretty print routine for nt:
proc pretty_print(nt A)
{
"nt with string c:"+A.c+" and poly:"+string(A.b);
}
system("install","nt","print",pretty_print,1); // default printing uses print
A;
// a custem add for nt:
proc nt_add(nt A,nt B)
{
nt C;
C.a=A.a+B.a; C.b=A.b+B.b; C.c=A.c+B.c;
return(C);
}
system("install","nt","+",nt_add,2);
A.b=x;
nt B; B.c="B"; B.b=y;
A+B;
@c example
@end smallexample
@c ------------------------------
@node Assignments for user defined types,,Commands for user defined types, User defined types
@subsection Assignments for user defined types
@cindex Assignments for user defined types
@cindex assignment,custom
@cindex custom assignment
By default, only objects of the same (user defined) type can be assigned,
there is no automatic type conversion as for the kernel data types.
But the operator @code{=} can be overridden in oder to write custom
constructors (the custom constructor does not apply to assignments
of the same type):
via @code{system("install",} user_type @code{,"="} @code{,p,1);}.
The user_type has to be given as a string.
@*@strong{Example:}
@smallexample
@c example
newstruct("wrapping","poly p");
proc wrap(poly p)
{
wrapping w; w.p = p;
return (w);
}
system("install", "wrapping", "=", wrap, 1);
ring r = 0,x,dp;
wrapping w = x+1;
w;
w = int(1); // via conversion int->poly
w;
w=number(2); // via conversion number->poly
w;
@c example
@end smallexample
The user defined procedure for @code{=} provides also generic type conversions:
@code{hh A=hh(b);} is equivalent to @code{hh tmp=b; hh A=tmp; kill tmp;}.
@c ------------------------------
@include cones.tex
@c ------------------------------
@ifset withpython
@include pyobject.tex
@end ifset
@ifclear withpython
@node pyobject,countedref,polytope, Data types
@section pyobject
@cindex pyobject
@cindex blackbox
This version of Singular does not support pyobject.
@end ifclear
@c ------------------------------
@include countedref.tex
@c ------------------------------
|