/usr/share/singular/LIB/recover.lib is in singular-data 4.0.3+ds-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 | //////////////////////////////////////////////////////////////////////////////
version="version recover.lib 4.0.2.0 30.03.2015 "; // $Id: b927729927611a7d28bab0afd4a692f0cbc92260 $
category="Algebraic Geometry";
info="
LIBRARY: recover.lib Hybrid numerical/symbolical algorithms for algebraic geometry
AUTHOR: Adrian Koch (kocha at rhrk.uni-kl.de)
OVERVIEW: In this library you'll find implementations of some of the algorithms presented
in the paper listed below: Bertini is used to compute a witness set of a given
ideal I. Then a lattice basis reduction algorithm is used to recover exact
results from the inexact numerical data. More precisely, we obtain elements
of prime components of I, the radical of I, or an elimination ideal of I.
NOTE that Bertini may create quite a lot of files in the current directory
(or overwrite files which have the same names as the files it wants to create).
It also prints information to the screen.
The usefulness of the results of the exactness recovery algorithms heavily
depends on the quality of the witness set and the quality of the lattice basis
reduction algorithm.
The procedures requiring a witness set as part of their input use a simple,
unsofisticated version of the LLL algorithm.
REFERENCES:
Daniel Bates, Jonathan Hauenstein, Timothy McCoy, Chris Peterson, and Andrew Sommese;
Recovering exact results from inexact numerical data in algebraic geometry;
Published in Experimental Mathematics 22(1) on pages 38-50 in 2013
KEYWORDS: numerical algebraic geometry; hybrid algorithms; exactness recovery
PROCEDURES:
substAll(v,p); poly: ring variables in v substituted by elements of p
veronese(d,p); ideal: image of p under the degree d Veronese embedding
getRelations(p,..); list of ideals: homogeneous polynomial relations between
components of p
getRelationsRadical(p,..); modified version of getRelations
gaussRowWithoutPerm(M); matrix: a row-reduced form of M
gaussColWithoutPerm(M); matrix: a column-reduced form of M
getWitnessSet(); extracts the witness set from the file \"main_data\" produced
by Bertini
writeBertiniInput(J); writes the input-file for bertini with the polynomials in J
as functions
num_prime_decom(I,..); is supposed to compute a prime decomposition of the radical of I
num_prime_decom1(P,..); is supposed to compute a prime decomposition for the ideal
represented by the witness point set P
num_radical_via_decom(I,..);
compute elements of the radical of I by using num_prime_decom
num_radical_via_randlincom(I,..);
computes elements of the radical of I by using a different method
num_radical1(P,..); computes elements of the radical via num_prime_decom1
num_radical2(P,..); computes elements of the radical using a different method
num_elim(I,f,..); computes elements of the elimination ideal of I w.r.t. the
variables specified by f
num_elim1(P,..,v); computes elements of the elimination ideal of the ideal
represented by the witness point set P (w.r.t. the variables
specified in v)
realLLL(M); simple version of the LLL-algorithm;works only over real numbers
";
LIB "matrix.lib";
LIB "linalg.lib";
LIB "inout.lib";
LIB "atkins.lib";
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////// static procs for rounding ///////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
static proc getposi(string s)
{//returns the position of the . in a complex number, or 0 if there is no . in s
int i;
for(i=1; i<=size(s); i++)
{
if(s[i] == "."){return(i);}
}
return(0);
}
static proc string2digit(string ti)
{
intvec v=0,1,2,3,4,5,6,7,8,9;
int i;
for(i=1; i<=size(v); i++)
{
if( ti == string(v[i]) )
{
return(poly(v[i]));
}
}
}
static proc string2poly(string t)
{
poly r=string2digit(t[1]);
int i;
for(i=2; i<=size(t); i++)
{
r=r*10+string2digit(t[i]);
}
return(r);
}
static proc roundstringpoly(string s, int posi)
{//returns the
string t;
//first check, whether s is negative or not
int e=0;
if(s[1]=="-")
{
e=1;
t=s[2..(posi-1)];//start at the second symbol (to drop the minus)
}
else
{
t=s[1..(posi-1)];
}
poly r=string2poly(t);//this is always the rounded-down version of the absolute value
//of r
//we have to check now, whether we should have rounded up
//for that, we check the digit after the .
if(string2digit(s[posi+1]) >= 5)
{
r=r+1;
}
if(e == 1)
{//readjust the sign, if needed
r=-r;
}
return(r);
}
static proc roundpoly(poly r)
{
string s=string(r);
int posi=getposi(s);
if(posi == 0)
{//there is no . in r, so r is an integer
return(r);
}
return(roundstringpoly(s, posi));
}
/////////////////////////////////////////////////////////////////////////////////////////
///////////////////////// Veronese embedding ////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
proc substAll(poly v, list p)
"USAGE: substAll(v,p); poly v, list p
RETURN: poly: the polynomial obtained from v by substituting the elements of p for the
ring variables
NOTE: The list p should have as many elements as there are ring variables.
EXAMPLE: example substAll; shows an example
"
{//substitutes the elements of p for the ring variables
//used to obtain the value of the veronese map
int i;
poly f=v;
for(i=1; i<=nvars(basering); i++)
{
f=subst(f,var(i),p[i]);
}
return(f);
}
example
{ "EXAMPLE:"; echo=2;
ring r=0,(x,y,z),dp;
poly v=x+y+z;
list p=7/11,5/11,-1/11;
poly f=substAll(v,p);
f;
}
proc veronese(int d, list p)
"USAGE: veronese(d,p); int d, list p
RETURN: ideal: the image of the point p under the degree d Veronese embedding
NOTE: The list p should have as many elements as there are ring variables.
The order of the points in the returned ideal corresponds to the order of the
monomials in maxideal(d).
SEE ALSO: maxideal
EXAMPLE: example veronese; shows an example
"
{//image of p under the degree d Veronese embedding
ideal V=maxideal(d);
int i;
poly v;
int len=size(V);
for(i=1; i <= len; i++)
{
v=V[i];
v=substAll(v,p);
V[i]=v;
}
return(V);
}
example
{ "EXAMPLE:"; echo=2;
ring R=0,(x,y,z),dp;
list p=2,3,5;
ideal V=veronese(1,p);
V;
V=veronese(2,p);
V;
}
static proc veronese_radical(int d, list P)
{//returns a random linear combination of the images of the points in P under the
//degree d Veronese embedding
list p;//one of the points in P
ideal Vp;//the Veronese embedding of p
int i;
for(i=1; i<=size(P); i++)
{
p=P[i];
Vp=veronese(d,p);
P[i]=Vp;
}
//so we've replaced the points p with their images under the Veronese embedding
//now we do a random linear combination of all these images
//first, we rand some factors
int di=10**7;
int de=1;
ideal F=poly(random(de,di))/di;
poly f;
for(i=2; i<=size(P); i++)
{
f=poly(random(de,di))/di;
F=F,f;
}
//then we compute the linear combination
poly v;
int j;
for(j=1; j<=size(P); j++)
{
Vp=P[j];
v=v+F[j]*Vp[1];
}
ideal V=v;
int len=size(maxideal(d));
for(i=2; i<=len; i++)
{
v=0;
for(j=1; j<=size(P); j++)
{
Vp=P[j];
v=v+F[j]*Vp[i];
}
V=V,v;
}
return(V);
}
/////////////////////////////////////////////////////////////////////////////////////////
////////////////////////// some static procs //////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
static proc randlincom(ideal V, int len)
{//produces a random linear combination of the real vectors defined by the real and the
//imaginary part of V, respectively
//(V is the image of a complex point p under a veronese embedding)
poly randre,randim;
int di=10**9;
int de=1;
//we get one of 2(di-de) numbers between (-)de/di and (-)1
randre=(-1)**random(1,2)*poly(random(de,di))/di;
randim=(-1)**random(1,2)*poly(random(de,di))/di;
ideal lincom=randre*repart(leadcoef(V[1]))+randim*impart(leadcoef(V[1]));
int i;
for(i=2; i<=len; i++)
{
lincom=lincom,randre*repart(leadcoef(V[i]))+randim*impart(leadcoef(V[i]));
}
return(lincom);
}
static proc getmatrix(ideal V, bigint C, int len)
{//constructs the stacked matrix, but with randlincom(V,len) instead of V
ideal rl=randlincom(V,len);
matrix v=transpose(matrix(rl));
matrix E=diag(1,len);
v=C*v;
E=concat(E,v);
E=transpose(E);
return(E);
}
static proc getpolys(matrix B, int d)
{//takes the integer parts* of the columns of B and uses them as coefficients in a
//homogeneous poly of degree d
//i.e. the first nrows-1 entries
ideal V=maxideal(d);
poly r=0;//will be one of the relation-polys
ideal R;//will contain all the relations
intvec rM=1..(nrows(B)-1);
intvec cM=1..ncols(B);
matrix M=submat(B,rM,cM);//B without the last row
//poly nu=poly(10)**(2*d);
int i,j;
for(i=1; i<=ncols(M); i++)
{
if(absValue(B[nrows(B),i]) < 10)//if(is_almost_zero(B,i,d))
{//we should check first, if the value of the generated poly in p (i.e. the last
//entry of the respective column in B) is "almost" 0
if(1)
{
for(j=1; j<=size(V); j++)
{
r=r+M[j,i]*V[j];
}
R=R,r;
r=0;
}
}
}
R=simplify(R,2);//gets rid of the zeroes
return(R);
}
static proc getD(ideal J)
{
//computes the maximal degree among elements of J
int maxdeg,c,i;
poly g;
for(i=1; i<=size(J); i++)
{
g=J[i];
c=deg(g);
if(c > maxdeg)
{
maxdeg=c;
}
}
return(maxdeg);
}
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////// use_LLL procedures //////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
static proc mat2list(bigintmat B)
{
list c;//column of B
list M;//the matrix: list of column-lists
int i,j;
for(i=1; i<=ncols(B); i++)
{
for(j=1; j<=nrows(B); j++)
{
c=c+list(B[j,i]);
}
M=M+list(c);
c=list();
}
return(M);
}
static proc list2bigintmat(list L);
{
int c=size(L);
int r=size(L[1]);
bigintmat B[r][c];
list Li;
int i,j;
for(i=1; i<=c; i++)
{
Li=L[i];
for(j=1; j<=r; j++)
{
B[j,i]=Li[j];
}
}
return(B);
}
static proc bigint2poly(bigint b)
{
poly p;
string bs=string(b);
int st=1;
int c;
if(bs[1] == "-")
{
st=2;
c=1;
}
int i;
for(i=st; i<=size(bs); i++)
{
p=p*10+string2intdigit(bs[i]);
}
if(c == 1)
{
return(-p);
}
return(p);
}
static proc bigintmat2matrix(bigintmat B)
{//type conversion via matrix(B) does not work
int r=nrows(B);
int c=ncols(B);
matrix M[r][c];
int i,j;
for(i=1; i<=r; i++)
{
for(j=1; j<=c; j++)
{
M[i,j]=bigint2poly(B[i,j]);
}
}
return(M);
}
static proc use_LLL(matrix A)
{
//first, we round the entries in the last row of A
int r=nrows(A);
int c=ncols(A);
int i;
for(i=1; i<=c; i++)
{
A[r,i]=roundpoly(A[r,i]);
}
//now, all entries of A are integers, but still have type poly
//so we convert A to a bigintmat B
bigintmat B=mat2bigintmat(A);
//apply LLL
list M=mat2list(B);
list L=LLL(M);
B=list2bigintmat(L);
return(bigintmat2matrix(B));
}
static proc use_LLL_bigintmat(matrix A)
{//returns a bigintmat instead of a matrix
//first, we round the entries in the last row of A
int r=nrows(A);
int c=ncols(A);
int i;
for(i=1; i<=c; i++)
{
A[r,i]=roundpoly(A[r,i]);
}
//now, all entries of A are integers, but still have type poly
//so we convert A to a bigintmat B
bigintmat B=mat2bigintmat(A);
//apply LLL
list M=mat2list(B);
list L=LLL(M);
B=list2bigintmat(L);
return(B);
}
static proc use_FLINT_LLL(matrix A)
{
//first, we round the entries in the last row of A
int r=nrows(A);
int c=ncols(A);
int i;
for(i=1; i<=c; i++)
{
A[r,i]=roundpoly(A[r,i]);
}
//now, all entries of A are integers, but still have type poly
//so we convert A to a bigintmat B
bigintmat B=mat2bigintmat(A);
//apply LLL
bigintmat BB=system("LLL_Flint",B);
return(BB);
}
static proc use_NTL_LLL(matrix A)
{
//first, we round the entries in the last row of A
int r=nrows(A);
int c=ncols(A);
int i;
for(i=1; i<=c; i++)
{
A[r,i]=roundpoly(A[r,i]);
}
//now, all entries of A are integers, but still have type poly
//so we convert A to a bigintmat B
bigintmat B=mat2bigintmat(A);
def br=basering;
ring newr=0,x,dp;
matrix A=bigintmat2matrix(B);
//NTL wants the lattice-vectors as row-vectors and returns a matrix of row-vectors
A=transpose(A);
matrix AA=system("LLL",A);
AA=transpose(AA);
bigintmat BB=mat2bigintmat(AA);
setring br;
return(BB);
}
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////// the main procedure(s) //////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
proc getRelations(list p, int D, bigint C)
"USAGE: getRelations(p,D,C); list p, int D, bigint C
RETURN: list K: a list of ideals; the ideals contain homogeneous polynomial relations of
degree <=D between the components of the point p
NOTE: This procedure uses only the images of the one point p under the Veronese
embeddings to find homogeneous polynomial relations.
SEE ALSO: getRelationsRadical
EXAMPLE: example getRelations; shows an example
"
{//uses degree d Veronese embeddings (for all d<=D) and LLL-algorithm to find
//(homogeneous) polynomial relations between the entries of p
//C is the Value with which the Veronese embedding is being multiplied (cf getmatrix)
if(nvars(basering) != size(p) )
{
ERROR("Number of variables not equal to the number of components of p.");
}
//get the precision
list RL=ringlist(basering);
RL=RL[1];
RL=RL[2];
int Prec=RL[2];
list P=list(p);
int d,i,len;
intvec rm;
ideal vd,Kd;
list K;
matrix A,B;
for(d=1; d<=D; d++)
{
vd=veronese(d,p);
len=size(maxideal(d));
A=getmatrix(vd,C,len);
B=realLLL(A);
Kd=getpolys(B,d);
if(size(Kd) == 0)//i.e. Kd has only zero-entries
{//then dont add Kd to the list of relations
d++;
continue;
}
rm=check_is_zero_lincomradical(Prec,Kd,P);
for(i=1; i<=size(rm); i++)
{
if( rm[i] == 1 )
{
Kd[i] = 0;
}
}
Kd=simplify(Kd,2);
if(size(Kd) == 0)//i.e. Kd has only zero-entries
{//then dont add Kd to the list of relations
d++;
continue;
}
K=K+list(Kd);
}
return(K);
}
example
{ "EXAMPLE:"; echo=2;
ring r=(complex,50),(x,y,z),dp;
list p=1,-1,0.5;
getRelations(p,2,10000);
}
proc getRelationsRadical(list P, int D, bigint C)
"USAGE: getRelationsRadical(P,D,C); list P, int D, bigint C
RETURN: list K: a list of ideals; the ideals contain homogeneous polynomial relations of
degree <=D between the components of the points in P
NOTE: This procedure uses random linear combination of the Veronese embeddings of all
points in P to find homogeneous polynomial relations.
SEE ALSO: getRelations
EXAMPLE: example getRelationsRadical; shows an example
"
{//here we compute random linear combinations of the degree d Veronese embeddings of the
//points in P and then proceed as in getRelations to get homogeneous polynomials
//which vanish on all points in P (with high probability)
if(nvars(basering) != size(P[1]) )
{
ERROR("Number of variables not equal to the number of components of P[1].");
}
//get the precision
list RL=ringlist(basering);
RL=RL[1];
RL=RL[2];
int Prec=RL[2];
int d,i,len;
intvec rm;
ideal vd,Kd;
list K;
matrix A,B;
for(d=1; d<=D; d++)
{
vd=veronese_radical(d,P);
len=size(maxideal(d));
A=getmatrix(vd,C,len);
B=realLLL(A);
Kd=getpolys(B,d);
if(size(Kd) == 0)//i.e. Kd has only zero-entries
{//then dont add Kd to the list of relations
d++;
continue;
}
rm=check_is_zero_lincomradical(Prec,Kd,P);
for(i=1; i<=size(rm); i++)
{
if( rm[i] == 1 )
{
Kd[i] = 0;
}
}
Kd=simplify(Kd,2);
if(size(Kd) == 0)//i.e. Kd has only zero-entries
{//then dont add Kd to the list of relations
d++;
continue;
}
K=K+list(Kd);
}
return(K);
}
example
{ "EXAMPLE:"; echo=2;
ring r=(complex,50),(x,y,z),dp;
list p1=1,-1,0.5;
list p2=1,0,-1;
list P=list(p1)+list(p2);
getRelationsRadical(P,2,10**5);
}
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////// Gauss reduction //////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
static proc find_unused_nonzero(matrix M, int j, intvec used)
{//look in column j of M for a non-zero entry in an unused row
//if there is one, return its row index
//if there isn't, return 0
int i;
int r=nrows(M);
for(i=1; i<=r; i++)
{
if(used[i] == 0)
{
if(M[i,j] != 0)
{
return(i);
}
}
}
return(0);
}
proc gaussRowWithoutPerm(matrix M)
"USAGE: gaussRowWithoutPerm(M); M a matrix of constant polynomials
RETURN: matrix: basic Gaussian row reduction of M, just without permuting the rows
EXAMPLE: example gaussRowWithoutPerm; shows an example
"
{//M a matrix of constant polys
int n=ncols(M);
int r=nrows(M);
int i,j,k;
intvec used;//the rows we already used to make entries in other rows 0
used[r]=0;//makes it a zero-intvec of length r
//we dont want to change these used rows anymore and we dont want to use them again
//entry i will be set to 1 if we used row i already
for(j=1; j<=n; j++)//go through all columns of M
{
//find the first non-zero entry
i=find_unused_nonzero(M,j,used);
if(i != 0)
{//and use it to make all non-pivot entries in the column equal to 0
used[i]=1;
for(k=1; k<=r; k++)
{
if(used[k] == 0)
{
if(M[k,j] != 0)
{
M=addrow(M,i,-M[k,j]/M[i,j],k);
}
}
}
}
}
return(M);
}
example
{ "EXAMPLE:"; echo=2;
ring r=0,x,dp;
matrix M[5][4]=0,0,2,1,4,5,1,3,0,9,2,0,8,1,0,6,0,9,4,1;
print(M);
print(gaussRowWithoutPerm(M));
}
proc gaussColWithoutPerm(matrix M)
"USAGE: gaussColWithoutPerm(M); M a matrix of constant polynomials
RETURN: matrix: basic Gaussian column reduction of M, just without permuting the columns
EXAMPLE: example gaussColWithoutPerm; shows an example
"
{
matrix T=transpose(M);
matrix G=gaussRowWithoutPerm(T);
return(transpose(G));
}
example
{ "EXAMPLE:"; echo=2;
ring r=0,x,dp;
matrix M[3][4]=0,1,0,2,1,2,3,4,1,0,5,0;
print(M);
print(gaussColWithoutPerm(M));
}
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
/////////////////////// static procs needed for minrelations //////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
static proc multwithmaxideal(ideal I, int a)
{//returns the ideal IM containing all products of elements of I and maxideal(a)
ideal M=maxideal(a);
int sM=size(M);
ideal IM=I*M[1];
int i;
for(i=2; i<=sM; i++)
{
IM=IM,I*M[i];
}
return(IM);
}
static proc prodofallringvars(int dummy)
{//returns the product of all ring variables
poly f=1;
int i;
for(i=1; i<=nvars(basering); i++)
{
f=f*var(i);
}
return(f);
}
static proc getcoefmat(ideal IM, int m)
{//computes the matrix of coefficients of the elements of IM
//the order of the coefficients in each column corresponds to the order of the
//monomials in maxideal(m);
matrix Co;
ideal M=maxideal(m);
int sM=size(M);
matrix C[sM][1];//the coeff vector of an element of IM with the coeffs placed at
//the appropriate positions
IM=simplify(IM,2);//be sure that size(IM) is the right thing -> get rid of zeroes
int sIM=size(IM);
matrix B;
poly pr=prodofallringvars(1);
poly g, Coj;
int i,j,k;
for(i=1; i<=sIM; i++)
{
g=IM[i];
Co=coef(g,pr);
//we now have to put the coeffs in the appropriate places (corresponding to the
//position of the respective monomial in maxideal)
for(j=1; j<=ncols(Co); j++)
{
Coj=Co[1,j];//arranged as row vectors
//compare the monomials of g with the elements of maxideal(m)
//and when we find a match, place the coef at the appropriate place in C
for(k=1; k<=sM; k++)
{
if(M[k] == Coj)
{
C[k,1]=Co[2,j];
break;//we dont need to check any other elements of M
//since theyre all different
}
}
}
if(i==1)
{
B=C;
C=0;
i++;
continue;
}
B=concat(B,C);
C=0;//reset C to the zero vector
}
return(B);
}
static proc getconcatcoefmats(list L)
{//L the first size(L) entries of K
//returns the concatenated coef matrices
//more precisely: let m be the degree of the elements of L[size(L)], then we want
//to know, which homogenous polynomials of degree m can be written as a combination
//of polynomials in the ideals contained in L. In particular, we want to know which
//of the elements of L[size(L)] can be written as a combination of other polys
//in L and are thereby superfluous (cf superfluousL)
//what we do here is, we multiply each polynomial (of degree, say, d) in L with a
//monomial of degree m-d and then store the coefficients of the resulting poly
//in a matrix
//(this is rather cumbersome and can probably be improved upon significantly)
matrix B,C;
ideal IM,I;
int i,d,m;
poly l;
int sL=size(L);
l=L[sL][1];//the polys are homogeneous; deg rising along L; deg same in L[j]
//for all j
m=deg(l);//the max degree
if(sL == 1)
{//then we only consider polys of one certain degree, so we don't have to
//multiply any of the ideals with any maxideal
C=getcoefmat(L[1],m);
return(C);//we dont concatenate anything here, so the initialization of
//C as the 1x1-zero-matrix is not an issue
}
for(i=1; i<sL; i++)
{
I=L[i];
d=deg(I[1]);
IM=multwithmaxideal(I,m-d);
B=getcoefmat(IM,m);
C=concat(C,B);//will again have as first column the zero vector
}
//if i=sL, the polys in L[i] already have the degree m, so we dont need to multiply
B=getcoefmat(L[sL],m);
C=concat(C,B);
//C will contain a zero-column at the beginning, because of the
//initialization of B as the 1x1-mat with single entry 0 + the way
//concat handles that situation
return( submat(C,1..nrows(C),2..ncols(C)) );
}
static proc string2intdigit(string ti)
{//ti a string of size 1, containing an integer digit
//return the digit
intvec v=0,1,2,3,4,5,6,7,8,9;
int i;
for(i=1; i<=size(v); i++)
{
if( ti == string(v[i]) )
{
return(v[i]);
}
}
}
static proc string2bigint(string s)
{
string t=s;
int e=0;
if(s[1]=="-")
{
e=1;
t=s[2..size(s)];//start at the second symbol (to drop the minus)
}
bigint r=string2intdigit(t[1]);
int i;
for(i=2; i<=size(t); i++)
{
r=r*10+string2intdigit(t[i]);
}
if(e == 1)
{//readjust the sign, if needed
r=-r;
}
return(r);
}
static proc mat2bigintmat(matrix M)
{//M a matrix filled with constant polys of integer value
//return the corresponding bigintmat
int c=ncols(M);
int r=nrows(M);
bigintmat intM[r][c];
int i,j;
for(i=1; i<=r; i++)
{
for(j=1; j<=c; j++)
{
intM[i,j]=string2bigint(string(M[i,j]));
}
}
return(intM);
}
static proc findnonzero(matrix M, int j)
{//look in column j of M for a non-zero entry
//if there is one, return its row index
//if there isn't, return 0
int i;
int r=nrows(M);
for(i=1; i<=r; i++)
{
if(M[i,j] != 0)
{
return(i);
}
}
return(0);
}
//////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////// minrelations ///////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
static proc superfluousL(list L)
{//returns an intvec containing the indices of the elements (of the ideal with highest
//degree in L) which can be dropped
intvec sprfls;
matrix C=getconcatcoefmats(L);
bigintmat intC=mat2bigintmat(C);
int l=size(L[size(L)]);
ring ratr=0,x,dp;
matrix M=bigintmat2matrix(intC);
M=gaussColWithoutPerm(M);
int i;
int c=1;//counts the number of elements (+1) of sprfls
int k=ncols(M)-l;//the number of cols in M which correspond to polys of lower degree
//is = ncols(M) - number of elements in L[size(L)]
for(i=k+1; i<=ncols(M); i++)
{
if( findnonzero(M,i) == 0 )
{
sprfls[c]=i-k;
c++;
}
}
return(sprfls);
}
static proc minrelations(list K)
{//K a list of homogeneous ideals - all individually of "pure degree d" -
//ordered from d=1 up to D
list L;
intvec sprfls;
int sj;
int i,j;
ideal Ki;
for(i=1; i<=size(K); i++)
{
L=K[1..i];//will give the list with one ideal as the only entry, when i=1
//i=1 would make trouble, if K was a list of lists: then L would be the first
//list in K
sprfls=superfluousL(L);
if(sprfls[1] == 0)
{//then sprfls returned the intvec v=0; so there are no superfluous elements
i++;
continue;
}
Ki=K[i];
for(j=1; j<=size(sprfls); j++)
{
sj=sprfls[j];
Ki[sj]=0;
}
Ki=simplify(Ki,2);
if( size(Ki) == 0 )
{//then all polys in K[i] can be generated by polys in the K[<i], so we can delete
//K[i] from the list
K=delete(K,i);
continue;
//but we dont want to change i
//size(K) adjusts itself, so we're fine there
}
K[i]=Ki;
}
return(K);
}
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//////////////// Procs for Bertini-Singular-Conversation /////////////////////
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
proc getWitnessSet()
"USAGE: getWitnessSet();
ASSUME: There is a text-document \"main_data\" in the current directory which was
produced by Bertini.
The basefield is the field of real numbers or the field of complex numbers.
RETURN: list; a list P of lists p_i of numbers: P a set of witness points
NOTE: Reads the file \"main_data\", searches the strings containing the witness points,
and converts them into floating point numbers.
EXAMPLE: example getWitnessSet; shows an example
"
{//goes through the file main_data generated by bertini and returns the witness points
//as a list of complex numbers
//(the precision specified in the definition of the basering should* be at least as
//high as the precision used by/to be expected from bertini)
string r;
list P,p;
int i, j;
r=read("main_data");
intvec posi=find_string("Estimated",r);
intvec endpos=find_string("Multiplicity",r);
for(i=1; i<=size(posi); i++)
{
p=read_point(r,posi[i],endpos[i]);
if( size(p) == 0 )
{
ERROR("Bertini nicht erfolgreich");
}
P=P+list( convert_p(p) );
}
return(P);
}
example
{ "EXAMPLE:"; echo=2;
//First, we write the input file for bertini, then run bertini
ring r=0,(x,y,z),dp;
ideal I=(x-y)*(y-z)*(x-z);
writeBertiniInput(I,40);
system("sh","bertini input");
//Then we change the ring and extract the witness set from main_data
ring R=(complex,40,i),(x,y,z),dp;
list P=getWitnessSet();
P;
}
static proc get_hom_var_group_str(int dummy)
{
string vg=varstr(basering);
int i;
for(i=1; i<size(vg); i++)
{
if(vg[i]==",")
{
vg=vg[1,i]+" "+vg[(i+1),size(vg)-i];
}
if( vg[i] == "(" )
{
vg=vg[1,i-1]+vg[(i+1),size(vg)-i];
continue;
}
if( vg[i] == ")" )
{
vg=vg[1,(i-1)]+vg[(i+1),size(vg)-i];
continue;
}
}
i=size(vg);
if(vg[i]==",")
{
vg=vg[1,i];
}
if( vg[i] == "(" )
{
vg=vg[1,i-1];
}
if( vg[i] == ")" )
{
vg=vg[1,(i-1)];
}
vg="hom_variable_group "+vg+";"+newline;
return(vg);
}
static proc get_declare_function_str(ideal J)
{
string dfs;
int i;
for(i=1; i<=size(J); i++)
{
if(size(dfs) > 0)
{
dfs=dfs+", f"+string(i);
}
else
{
dfs=dfs+"f"+string(i);
}
}
dfs="function "+dfs+";"+newline;
return(dfs);
}
static proc remove_brackets(string vg)
{//removes any round brackets from a string
int i;
for(i=1; i<size(vg); i++)
{
if( vg[i] == "(" )
{
vg=vg[1,i-1]+vg[(i+1),size(vg)-i];
continue;
}
if( vg[i] == ")" )
{
vg=vg[1,(i-1)]+vg[(i+1),size(vg)-i];
continue;
}
}
i=size(vg);
if( vg[i] == "(" )
{
vg=vg[1,i-1];
}
if( vg[i] == ")" )
{
vg=vg[1,(i-1)];
}
return(vg);
}
static proc get_function_str(ideal J)
{
string fs, m;
matrix C;
poly fi;
int i,j,k;
string s;
for(i=1; i<=size(J); i++)
{
fs=fs+"f"+string(i)+" = ";
fi=J[i];
s=string(fi);
s=remove_brackets(s);
fs=fs+s;
fs=fs+";"+newline;
}
return(fs);
}
static proc get_coef_bound_poly(poly f)
{
poly pr=prodofallringvars(1);
matrix C=coef(f,pr);
int c=ncols(C);
poly b;
int i;
for(i=1; i<=c; i++)
{
b=b+absValue(C[2,i]);
}
return(b);
}
static proc get_coef_bound_ideal(ideal J)
{//is supposed to compute the maximum among the sums of coefficients in each individual
//polynomial in J
if(size(J) == 0){ return(1); }
J=simplify(J,2);
poly b=get_coef_bound_poly(J[1]);
poly a;
int i;
for(i=2; i<=size(J); i++)
{
a=get_coef_bound_poly(J[i]);
if(a > b)
{
b=a;
}
}
return(string(b));
}
static proc get_prec_in_bits(int Prec)
{//log_10(2) is approximately 3,3219281
//conversion from decimal digits to bits, rounded up
int pb = (3322*Prec div 1000) + 1;
int upb=3328;//upper bound on the precision
if( pb > upb )
{//bertini allows a maximum of 3328 bits of precision
return(upb);
}
int lowb=64;//lower bound
if( pb < lowb)
{//bertini requires a minimum of 64 bits of precision
//however, using such a low precision is not recommended, since it will
//probably not yield any useful results
return(lowb);
}
//bertini wants the precision to be a multiple of 32
pb = pb + 32 - (pb mod 32);
return(pb);
}
proc writeBertiniInput(ideal J, int Prec)
"USAGE: writeBertiniInput(J); ideal J
RETURN: none; writes the input-file for bertini using the polynomials given by J as
functions
NOTE: Either creates a file named input in the current directory or overwrites the
existing one.
If you want to pass different parameters to bertini, you can edit the produced
input file or redefine this procedure.
EXAMPLE: example writeBertiniInput; shows an example
"
{//writes the input-file for bertini
//we change the ring so that the names of the ring variables are convenient for us
def br=basering;
int nv=nvars(br);
ring r=0,x(1..nv),dp;
ideal J=fetch(br,J);
link l=":w ./input";
write(l,"CONFIG");
write(l,"");
write(l,"TRACKTYPE: 1;");
write(l,"TRACKTOLBEFOREEG: 1e-8;");
write(l,"TRACKTOLDURINGEG: 1e-11;");
write(l,"FINALTOL: 1e-14;");
write(l,"");
write(l,"");
write(l,"PrintPathProgress: 1;");
write(l,"MPTYPE: 2;");
int pb=get_prec_in_bits(Prec);
write(l,"AMPMaxPrec: "+string(pb)+";");
string cb=get_coef_bound_ideal(J);
write(l,"COEFFBOUND: "+cb+";");
string db=string(getD(J));
write(l,"DEGREEBOUND: "+db+";");
write(l,"");
write(l,"SHARPENDIGITS: "+string(Prec)+";");
write(l,"END;");
write(l,"");
write(l,"");
write(l,"INPUT"+newline);
string vg=get_hom_var_group_str(1);
write(l,vg);
string dfs=get_declare_function_str(J);
write(l,dfs);
string fs=get_function_str(J);
write(l,fs);
write(l,"END;");
}
example
{ "EXAMPLE:"; echo=2;
ring r=0,(x,y,z),dp;
poly f1=x+y+z;
poly f2=x2+xy+y2;
ideal I=f1,f2;
writeBertiniInput(I,300);
}
static proc find_string(string F, string S)
{//search in string S for the string F
//output all the positions in an intvec v
string s;
intvec v;
int c=1;//counts the number of elements of v
int i;
int a=size(S);
int len=size(F);
for(i=1; i<=a; i++)
{
s=S[i,len];
if(F==s)
{
v[c]=i;
c++;
}
}
return(v);
}
static proc read_point(string r, int po, int endpo)
{//reads out a single point from main_data
//return as string representing a floating point number split into real and imaginary
//part
int i, b;
for(i=po; i<=size(r); i++)
{
if(r[i] == newline)
{
b=i+1;//b is the first character in the line containing components of the point
break;
}
}
list p;
string pj;
int len, strt;
strt=b;
for(i=b; i<=endpo; i++)
{
if(r[i] == newline)
{
len=i-strt;
pj=r[strt,len];
p=p+list(pj);
strt=i+1;
}
}
return(p);
}
static proc string2num(string numstr)
{
number n=0;
int c=0;
if(numstr[1] == "-")
{
numstr=numstr[2,size(numstr)-1];
c=1;
}
int i;
for(i=size(numstr); i>=3; i--)
{
n=n/10+string2intdigit(numstr[i]);
}
n=n/10+string2intdigit(numstr[1]);
if(c==1)
{
n=-n;
}
return(n);
}
static proc string2e(string estr)
{//compute the exponent from the scientific notation
int e=0;
int c=0;
if(estr[1] == "-")
{
c=1;
}
else
{
if(estr[1] != "+")
{
estr="+"+estr;
return(string2e(estr));
}
}
estr=estr[2,size(estr)-1];
int i;
for(i=1; i<=size(estr); i++)
{
e=e*10+string2intdigit(estr[i]);
}
if(c==1)
{
e=-e;
}
return(e);
}
static proc dismantle_string(string si)
{//cuts the string into the real/imaginary parts and their exponents
//example of a string si:
//1.124564280901713e+00 -2.550064206873323e-01
int e1,e2;
number im,re;
string prt;//the currently considered part of the string
int i, len;
int strt=1;
for(i=1; i<=size(si); i++)
{
if( si[i] == "e" )
{
len=i-strt;
prt=si[strt,len];
re=string2num(prt);
break;
}
}
strt=i+1;//start at the character coming after "e"
for(i=strt; i<=size(si); i++)
{
if( si[i] == " " )
{
len=i-strt;
prt=si[strt,len];
e1=string2e(prt);
break;
}
}
strt=i+1;//start at the character coming after " "
for(i=strt; i<=size(si); i++)
{
if( si[i] == "e" )
{
len=i-strt;
prt=si[strt,len];
im=string2num(prt);
break;
}
}
strt=i+1;//start at the character coming after "e"
len=size(si)-strt+1;
prt=si[strt,len];
e2=string2e(prt);
number ten=10;
if(0)//e1 < -1000
{
re=0;
}
else
{
re=re*(ten^e1);
}
if(0)//e2 < -1000
{
im=0;
}
else
{
im=im*(ten^e2);
}
number n=re + IUnit*im;
return(n);
}
static proc convert_p(list p)
{//p a list of strings representing the components of the point p
//converts the list of strings to a list of numbers
//interesting: apparently, since p is a list of strings to begin with, it is not
//bound to the basering, so it will exist in the ring r, as well. But, as we change
//the entries of p from type string to type number/poly, it gets bound to the ring r,
//so it doesnt exist in br anymore. Hence, we have do define list p=fetch.
//we change the ring, so that we know, what the imaginary unit is called, define the
//points over that ring and then fetch them to the original ring
def br=basering;
list l=ringlist(br);
l[1][3]="IUnit";
def r=ring(l);
setring r;
string si;
number pi;
int i;
for(i=1; i<=size(p); i++)
{
pi=dismantle_string(p[i]);
p[i]=pi;
}
setring br;
list p=fetch(r,p);
return(p);
}
static proc getP_plus_posis(int dummy)
{//goes through the file main_data generated by bertini and returns the witness points
//as a list of complex numbers
//(the precision specified in the definition of the basering should* be at least as
//high as the precision used by/to be expected from bertini)
string r;
list P,p;
int i, j;
r=read("main_data");
intvec posi=find_string("Estimated",r);
intvec endpos=find_string("Multiplicity",r);
for(i=1; i<=size(posi); i++)
{
p=read_point(r,posi[i],endpos[i]);
if( size(p) == 0 )
{
ERROR("Bertini nicht erfolgreich");
}
P=P+list( convert_p(p) );
}
return(posi, endpos, P);
}
static proc getPi_from_main_data(int i, intvec posi, intvec endpos)
{//gets only the i-th point in main_data; is used by check_is_zero
string r;
list P,p;
int j;
r=read("main_data");
p=read_point(r,posi[i],endpos[i]);
if( size(p) == 0 )
{
ERROR("Bertini nicht erfolgreich");
}
P=P+list( convert_p(p) );
return(P);
}
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////// Applications //////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
////////////////// static procs to get the relations from the //////////////////////////
////////////////// complex to the rational numbers //////////////////
//////////////////////////////////////////////////////////////////////////////////////////
static proc get_relations_as_bigintmats(list p, int D, bigint C)
{//uses degree d Veronese embeddings (for all d<=D) and LLL-algorithm to find
//(homogeneous) polynomial relations between the entries of p
//C is the Value with which the Veronese embedding is being multiplied (cf getmatrix)
//returns the list of the bigintmats computed by the LLL-algorithm
//these are then processed further by get_relations_over_rationals after a switch
//of rings in the level above
if(nvars(basering) != size(p) )
{
ERROR("Number of variables not equal to the number of components of p.");
}
int d,len;
list mats;
ideal vd;
matrix A;
bigintmat B;
for(d=1; d<=D; d++)
{
vd=veronese(d,p);
len=size(maxideal(d));
A=getmatrix(vd,C,len);
//B=use_FLINT_LLL(A);
B=use_NTL_LLL(A);
//B=use_LLL_bigintmat(A);
mats=mats+list(B);
}
return(mats);
}
static proc get_relations_radical_as_bigintmats(list P, int D, bigint C)
{//is to get_relations_as_bigintmats what get_relationsRadical is to get_relations
//ie uses a random linear combination of the Veronese embeddings of all points in P
//in order to get polynomials which vanish over all points simultaneously
int d,len;
list mats;
ideal vd;
matrix A;
bigintmat B;
for(d=1; d<=D; d++)
{
vd=veronese_radical(d,P);
len=size(maxideal(d));
A=getmatrix(vd,C,len);
//B=use_FLINT_LLL(A);
B=use_NTL_LLL(A);
//B=use_LLL_bigintmat(A);
mats=mats+list(B);
}
return(mats);
}
static proc check_is_zero(int Prec, ideal Kd, intvec posi, intvec endpos, int k)
{
def br=basering;
int n=nvars(basering);
ring R=(complex,Prec,IUnit),x(1..n),dp;
ideal I=fetch(br,Kd);
list P=getPi_from_main_data(k, posi, endpos);
list p;
poly v;
number eps=number(10)**(5-Prec);
number a;
int i,j,c;
int len = size(I);
intvec rm;
rm[len]=0;
for(i=1; i<=len; i++)
{
for(j=1;j<=size(P); j++)
{
p=P[j];
v=substAll(I[i],p);
a=number(v);
a=absValue(repart(a))+absValue(impart(a));
//v=v*( poly(10)**(Prec-10) );
if( a > eps)
{
rm[i] = 1;
break;
}
}
}
return(rm);
}
static proc get_relations_over_rationals(int D, int Prec, list mats, intvec posi,
intvec endpos, int k)
{//finds the relations by passing the bigintmats to getpolys
//returns a list of ideals containing the corresponding polynomials
bigintmat B;
int d;
list K;
ideal Kd;
intvec rm;
int i;
for(d=1; d<=D; d++)
{
B=mats[d];
Kd=getpolys(bigintmat2matrix(B),d);
if(size(Kd) != 0)
{
rm=check_is_zero(Prec,Kd,posi,endpos,k);
for(i=1; i<=size(rm); i++)
{
if( rm[i] == 1 )
{
Kd[i] = 0;
}
}
Kd=simplify(Kd,2);
}
if(size(Kd) == 0)//i.e. Kd has only zero-entries
{//then dont add Kd to the list of relations
d++;
continue;
}
K=K+list(Kd);
}
return(K);
}
static proc getP_from_known_posis(intvec posi, intvec endpos)
{//goes through the file main_data generated by bertini and returns the witness points
//as a list of complex numbers
//(the precision specified in the definition of the basering should* be at least as
//high as the precision used by/to be expected from bertini)
string r;
list P,p;
int i, j;
r=read("main_data");
for(i=1; i<=size(posi); i++)
{
p=read_point(r,posi[i],endpos[i]);
if( size(p) == 0 )
{
ERROR("Bertini nicht erfolgreich");
}
P=P+list( convert_p(p) );
}
return(P);
}
static proc check_is_zero_lincomradical(int Prec, ideal I, list P)
{
//altered ckeck_is_zero for the linear-combination-of-Veronese-embeddings version
//of the procedures
list p;
poly v;
number eps=number(10)**(5-Prec);
number a;
int i,j,c;
int len = size(I);
intvec rm;
rm[len]=0;
for(i=1; i<=len; i++)
{
for(j=1;j<=size(P); j++)
{
p=P[j];
v=substAll(I[i],p);
a=number(v);
a=absValue(repart(a))+absValue(impart(a));
//v=v*( poly(10)**(Prec-10) );
if( a > eps)
{
rm[i] = 1;
break;
}
}
}
return(rm);
}
static proc get_relations_lincomradical_over_rationals(int D, int Prec, list mats,
intvec posi, intvec endpos)
{//finds the relations by passing the bigintmats to getpolys
//returns a list of ideals containing the corresponding polynomials
bigintmat B;
int d;
list K;
ideal Kd;
intvec rm;
int i;
//set up the ring to check whether the supposed relations have value zero at
//all the witness points
def br=basering;
int n=nvars(br);
ring cr=(complex,Prec,IUnit),x(1..n),dp;
list P=getP_from_known_posis(posi, endpos);
ideal I;
int le;
setring br;
for(d=1; d<=D; d++)
{
B=mats[d];
Kd=getpolys(bigintmat2matrix(B),d);
//go to the complex ring to see which candidate relations should be removed
setring cr;
I=fetch(br,Kd);
le=size(I);
if(le != 0)
{
rm=check_is_zero_lincomradical(Prec,I,P);
}
//remove from the ideal over the rational numbers
setring br;
if(le != 0)
{
for(i=1; i<=size(rm); i++)
{
if( rm[i] == 1 )
{
Kd[i] = 0;
}
}
Kd=simplify(Kd,2);
}
if(size(Kd) == 0)//i.e. Kd has only zero-entries
{//then dont add Kd to the list of relations
d++;
continue;
}
K=K+list(Kd);
}
return(K);
}
//////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////// num_prime_decom /////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
proc num_prime_decom(ideal I, int D, int Prec)
"USAGE: num_prime_decom(I,D); ideal I, int D
D a bound to the degree of the elements of the components of a prime
decomposition of I.
RETURN: list of ideals: each of the ideals a prime component of the radical of I
REMARKS: Uses Bertini.
NOTE: Should only be called from a ring over the rational numbers.
EXAMPLE: example num_prime_decom; shows an example
"
{//App. 3.1: computes a prime decomposition of the radical of I
//returns a list of ideals, each of them a prime component
def br=basering;
int n=nvars(br);
list K;//will contain the relations over the basering
list Q;//will contain the components
ideal M;
writeBertiniInput(I,Prec);
//move to a ring over the complex numbers to get the points computed by bertini
ring Ri=(complex,Prec,IUnit),x(1..n),dp;
system("sh","bertini input");
list P;
intvec posi, endpos;
(posi, endpos, P)=getP_plus_posis(1);
int sP=size(P);
bigint C=bigint(10)**Prec;//digits of precision
list p, mats;
int i,j;
for(i=1; i<=sP; i++)
{
setring Ri;
//compute the relations (with LLL, NTL_LLL or FLINT_LLL) in the form of bigintmats
p=P[i];
mats=get_relations_as_bigintmats(p,D,C);
//move to br again to obtain the relation-polynomials over the rational numbers
setring br;
K=get_relations_over_rationals(D, Prec, mats, posi, endpos, i);
if(size(K) == 0)//ie K the empty list
{
i++;
continue;
}
K=minrelations(K);
//K is now the list of ideals containing min gens in the respective degrees
//now, we put these min gens in one ideal
M=K[1];
for(j=2; j<=size(K); j++)
{
M=M+K[j];
}
Q=Q+list(M);
}
return(Q);
}
example
{ "EXAMPLE:"; echo=2;
ring R=0,(x,y,z),dp;
ideal I=(x+y)*(y+2z), (x+y)*(x-3z);
int D=2;
int Prec=300;
num_prime_decom(I,D,Prec);
//Let us compare that to the result of primdecSY:
primdecSY(I);
}
proc num_prime_decom1(list P, int D, bigint C)
"USAGE: num_prime_decom1(P,D,C); list P, int D, bigint C
P a list of lists representing a witness point set representing an ideal I
D should be a bound to the degree of the elements of the components of the
prime decomposition of I
C the number with which the images of the Veronese embeddings are multiplied
RETURN: list of ideals: each of the ideals a prime component of the radical of I
NOTE: Should only be called from a ring over the complex numbers.
EXAMPLE: example num_prime_decom1; shows an example
"
{//P a list of lists containing the witness points
//returns (or is supposed to return) a list containing the prime components
//of the radical of the ideal which is represented by the witness points in P
list p,K,Q;
int i,j;
ideal M;
for(i=1; i<=size(P); i++)
{
p=P[i];
K=getRelations(p,D,C);
if(size(K) == 0)//ie K the empty list
{
i++;
continue;
}
K=minrelations(K);
//K is now the list of ideals containing min gens in the respective degrees
//now, we put these min gens in one ideal
M=K[1];
for(j=2; j<=size(K); j++)
{
M=M+K[j];
}
Q=Q+list(M);
}
return(Q);
}
example
{ "EXAMPLE:"; echo=2;
//First, we compute a prime decomposition of the ideal I=x+y;
ring R1=(complex,300,IUnit),(x,y),dp;
list p1=1,-1;
list P=list(p1);
int D=2;
bigint C=bigint(10)**300;
num_prime_decom1(P,D,C);
//Now, we try to obtain a prime decomposition of the ideal I=(x+y)*(y+2z), (x+y)*(x-3z);
ring R2=(complex,20,IUnit),(x,y,z),dp;
p1=1.7381623928,-1.7381623928,0.2819238763;
list p2=-3.578512854,2.385675236,-1.192837618;
P=p1,p2;
num_prime_decom1(P,D,10000);
//Now, we look at the result of a purely symbolic algorithm
ring r2=0,(x,y,z),dp;
ideal I=(x+y)*(y+2z), (x+y)*(x-3z);
primdecSY(I);
//If you compare the results, you may find that they don't match.
//Most likely, the hybrid algorithm got the second component wrong. This is due to the
//way the algorithm looks for homogeneous polynomial relations, and the specific version
//of the LLL algorithm used here (an implementation into Singular of a rather simple
//version which allows real input). It looks in degree 1, finds one relation and is
//thereafter unable to see a second one. Then it moves on to degree 2 and finds
//relations containing degree-1 relations as a factor.
}
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// num_radical ///////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
proc num_radical_via_decom(ideal I, int D, int Prec)
"USAGE: num_radical_via_decom(I,D); ideal I, int D
D a bound to the degree of the elements of the components.
RETURN: ideal: the radical of I
REMARKS: Uses Bertini.
This procedure merely calls num_prime_decom with the same input and then
intersects the returned components.
NOTE: Should only be called from a ring over the rational numbers.
SEE ALSO: num_prime_decom, num_radical_via_randlincom
EXAMPLE: example num_radical_via_decom; shows an example
"
{//check p.14/15, App. 3.2
list Q=num_prime_decom(I,D,Prec);
ideal interQ=1;
int i;
for(i=1; i<=size(Q); i++)
{
interQ=intersect(interQ,Q[i]);
}
return(interQ);
}
example
{ "EXAMPLE:"; echo=2;
//First, we attempt to compute the radical via the hybrid algorithm.
ring R=0,(x,y,z),dp;
ideal I=(x+y)^2*(y+2z)^3, (x+y)^3*(x-3z)^2;
int D=2;
int Prec=300;
ideal numRad=num_radical_via_decom(I,D,Prec);
numRad;
//Then we compute the radical symbolically and compare the results.
ideal Rad=radical(I);
Rad;
reduce(Rad,std(numRad));
reduce(numRad,std(Rad));
}
proc num_radical_via_randlincom(ideal I, int D, int Prec)
"USAGE: num_radical_via_randlincom(I,D); ideal I, int D
D a bound to the degree of the elements of the components.
RETURN: ideal: the radical of I
REMARKS: Uses Bertini.
Instead of using the images of the Veronese embeddings of each individual witness
point, this procedure first computes a random linear combination of those images
and searches for homogeneous polynomial relations for this linear combination.
NOTE: Should only be called from a ring over the rational numbers.
SEE ALSO: num_radical_via_decom
EXAMPLE: example num_radical_via_randlincom; shows an example
"
{//check p.14/15, App. 3.2
bigint C=bigint(10)**Prec;//digits of precision
def br=basering;
int n=nvars(br);
writeBertiniInput(I,Prec);
//move to a ring over the complex numbers to get the points computed by bertini
ring Ri=(complex,Prec,IUnit),x(1..n),dp;
system("sh","bertini input");
list P;
intvec posi, endpos;
(posi, endpos, P)=getP_plus_posis(1);
list mats=get_relations_radical_as_bigintmats(P,D,C);
setring br;
list K=get_relations_lincomradical_over_rationals(D,Prec,mats,posi,endpos);
ideal Q;
if(size(K) > 0)
{
K=minrelations(K);
Q=K[1];
int i;
for(i=2; i<=size(K); i++)
{
Q=Q,K[i];
}
}
return(Q);
}
example
{ "EXAMPLE:"; echo=2;
//First, we attempt to compute the radical via the hybrid algorithm.
ring R=0,(x,y,z),dp;
ideal I=(x+y)^2*(y+2z)^3, (x+y)^3*(x-3z)^2;
int D=2;
int Prec=300;
ideal numRad=num_radical_via_randlincom(I,D,Prec);
numRad;
//Then we compute the radical symbolically and compare the results.
ideal Rad=radical(I);
Rad;
reduce(Rad,std(numRad));
reduce(numRad,std(Rad));
}
proc num_radical1(list P, int D, bigint C)
"USAGE: num_radical1(P,D,C); list P, int D, bigint C
P a list of lists representing a witness point set representing an ideal I
D should be a bound to the degree of the elements of the components
C the number with which the images of the Veronese embeddings are multiplied
RETURN: list of ideals: each of the ideals a prime component of the radical of I
REMARKS: This procedure merely calls num_prime_decom1 with the same input and then
intersects the returned components.
NOTE: Should only be called from a ring over the complex numbers.
SEE ALSO: num_prime_decom1, num_radical2
EXAMPLE: example num_radical1; shows an example
"
{//computes the radical via num_prime_decom (intersecting the obtained prime decom)
list Q=num_prime_decom1(P,D,C);
ideal interQ=1;
int i;
for(i=1; i<=size(Q); i++)
{
interQ=intersect(interQ,Q[i]);
}
return(interQ);
}
example
{ "EXAMPLE:"; echo=2;
//First, we write the input file for bertini and compute the radical symbolically.
ring r=0,(x,y,z),dp;
ideal I=4xy2-4z3,-2x2y+5xz2;
ideal Rad=radical(I);
writeBertiniInput(I,100);
//Then we attempt to compute the radical via the hybrid algorithm.
ring R=(complex,100,i),(x,y,z),dp;
system("sh","bertini input");
list P=getWitnessSet();
int D=2;
bigint C=bigint(10)**30;
ideal Rad1=num_radical1(P,D,C);
//Lastly, we compare the results.
Rad1;
ideal Rad=fetch(r,Rad);
Rad;
reduce(Rad,std(Rad1));
reduce(Rad1,std(Rad));
}
proc num_radical2(list P, int D, bigint C)
"USAGE: num_radical2(P,D,C); list P, int D, bigint C
P a list of lists representing a witness point set representing an ideal I
D should be a bound to the degree of the elements of the components
C the number with which the images of the Veronese embeddings are multiplied
RETURN: list of ideals: each of the ideals a prime component of the radical of I
REMARKS: Instead of using the images of the Veronese embeddings of each individual witness
point, this procedure first computes a random linear combination of those images
and searches for homogeneous polynomial relations for this linear combination.
NOTE: Should only be called from a ring over the complex numbers.
SEE ALSO: num_radical1
EXAMPLE: example num_radical2; shows an example
"
{//computes the radical via getRelationsRadical
list K=getRelationsRadical(P,D,C);
K=minrelations(K);
K;
//unite the elements of K into one ideal
ideal Q=K[1];
int i;
for(i=2; i<=size(K); i++)
{
Q=Q,K[i];
}
return(Q);
}
example
{ "EXAMPLE:"; echo=2;
//First, we write the input file for bertini and compute the radical symbolically.
ring r=0,(x,y,z),dp;
ideal I=4xy2-4z3,-2x2y+5xz2;
ideal Rad=radical(I);
writeBertiniInput(I,100);
//Then we attempt to compute the radical via the hybrid algorithm.
ring R=(complex,100,i),(x,y,z),dp;
system("sh","bertini input");
list P=getWitnessSet();
int D=2;
bigint C=bigint(10)**30;
ideal Rad2=num_radical2(P,D,C);
//Lastly, we compare the results.
Rad2;
ideal Rad=fetch(r,Rad);
Rad;
reduce(Rad,std(Rad2));
reduce(Rad2,std(Rad));
}
//////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////// num_elim /////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
static proc project_p(list p, intvec projvec)
{//projects a single point p onto the components specified in projvec
list pr;//the projection
int i,k;
for(i=1; i<=size(projvec); i++)
{
k=projvec[i];
pr=pr+list(p[k]);
}
return(pr);
}
static proc project_P(list P, intvec projvec)
{//projects the points in P onto the components specified in projvec
list p;//elements of P
list Pr;//the list of projections
list pr;//projection of a point p
int i;
for(i=1; i<=size(P); i++)
{
p=P[i];
pr=project_p(p,projvec);
Pr=Pr+list(pr);
}
return(Pr);
}
static proc get_projection_intvec(intvec elvec)
{//computes the intvec containing the indices of the variables which are not to be
//eliminated
int nv=nvars(basering);
intvec projvec;
int i,j,c,count;//count counts the elements of projvec
for(i=1; i<=nv; i++)
{
c=1;
for(j=1; j<=size(elvec); j++)
{
if(i == elvec[j])
{
c=0;
break;
}
}
//if i is not among the elements of elvec, store it in projvec
if(c == 1)
{
count++;
projvec[count]=i;
}
}
return(projvec);
}
static proc get_elvec(poly f)
{//computes the elimination intvec from a product of ring variables
if(size(f) != 1)
{
ERROR("f must be a product of ringvariables, i.e. a monomial.");
}
int n=nvars(basering);
intvec elvec;
int i, c;
for(i=1; i<=n; i++)
{
if( f/var(i) != 0)
{
c++;
elvec[c]=i;
}
}
return(elvec);
}
proc num_elim(ideal I, poly f, int D, int Prec)
"USAGE: num_elim(I,f,D); ideal I, poly f, int D
f the product of the ring variables you want to eliminate
D a bound to the degree of the elements of the components
RETURN: ideal: the ideal obtained from I by eliminating the variables specified in f
REMARKS: This procedure uses Bertini to compute a set of witness points for I, projects
them onto the components corresponding to the variables specified in f and then
proceeds as num_radical_via_randlincom.
NOTE: Should only be called from a ring over the rational numbers.
EXAMPLE: example num_elim; shows an example
"
{//App. 3.3
bigint C=bigint(10)**Prec;//digits of precision
//first, get elvec and projvec
intvec elvec=get_elvec(f);
intvec projvec=get_projection_intvec(elvec);
writeBertiniInput(I,Prec);
//define the ring with eliminated variables
//we have to compute the relations over this ring, since the number of variables
//must be the same as the number of components of the projected point
def br=basering;
list l=ringlist(br);
int i;
for(i=size(elvec); i>=1; i--)
{
l[2]=delete(l[2],elvec[i]);
}
def brel=ring(l);
int n=nvars(brel);
//move to a ring over the complex numbers to get the points computed by bertini
ring Ri=(complex,Prec,IUnit),x(1..n),dp;
system("sh","bertini input");
list P;
intvec posi, endpos;
(posi, endpos, P)=getP_plus_posis(1);
list Pr=project_P(P,projvec);
list mats=get_relations_radical_as_bigintmats(Pr,D,C);
setring brel;
list K=get_relations_lincomradical_over_rationals(D,Prec,mats,posi,endpos);
ideal R;
if(size(K) > 0)
{
K=minrelations(K);
R=K[1];
for(i=2; i<=size(K); i++)
{
R=R,K[i];
}
}
setring br;
ideal R=imap(brel,R);
return(R);
}
example
{ "EXAMPLE:"; echo=2;
ring r=0,(x,y,z),dp;
poly f1=x-y;
poly f2=z*(x+3y);
poly f3=z*(x2+y2);
ideal I=f1,f2,f3;
//First, we attempt to compute the elimination ideal with the hybrid algorithm.
ideal E1=num_elim(I,z,3,200);
//Now, we compute the elimination ideal symbolically.
ideal E2=elim(I,z);
//Lastly, we compare the results.
E1;
E2;
}
proc num_elim1(list P, int D, bigint C, intvec elvec)
"USAGE: num_elim1(P,D,C,v); list P, int D, bigint C, intvec v
P a list of lists representing a witness point set representing an ideal J
D should be a bound to the degree of the elements of the components
C the number with which the images of the Veronese embeddings are multiplied
v an intvec specifying the numbers/positions of the variables to be eliminated
RETURN: ideal: the ideal obtained from J by eliminating the variables specified in v
REMARKS: This procedure just canonically projects the witness points onto the components
specified in the intvec v and then applies num_radical1 to the resulting points.
NOTE: Should only be called from a ring over the complex numbers.
EXAMPLE: example num_elim1; shows an example
"
{//let J be the ideal represented by the witness points in P
//returns (or is supposed to return) the prime decomposition of the radical of the
//elimination ideal of J
//(where we eliminate the variables with the indices specified in elvec)
//Note that, since we are in a homogeneous setting eliminating all variables
//is quite simple, since we only have to decide, whether its the 0-ideal or the
//whole ring. This procedure won't work in that case.
intvec projvec=get_projection_intvec(elvec);
list Pr=project_P(P,projvec);
//We now have to change the ring we work over: we delete the variables which are
//to be eliminated. -> The number of variables and the number of components in
//the projected point are the same. Then we can apply our procedure and imap the
//results to our original ring, since we didnt change the names of the variables.
def br=basering;
list l=ringlist(br);
int i;
for(i=size(elvec); i>=1; i--)
{
l[2]=delete(l[2],elvec[i]);
}
def r=ring(l);
setring r;
list Pr=fetch(br,Pr);
ideal R=num_radical1(Pr,D,C);
setring br;
ideal R=imap(r,R);
return(R);
}
example
{ "EXAMPLE:"; echo=2;
//First, we write the input file for bertini and compute the elimination ideal
//symbolically.
ring r=0,(x,y,z),dp;
poly f1=x-y;
poly f2=z*(x+3y);
poly f3=z*(x2+y2);
ideal J=f1,f2,f3;
ideal E2=elim(J,z);
writeBertiniInput(J,100);
//Then we attempt to compute the elimination ideal via the hybrid algorithm.
ring R=(complex,100,i),(x,y,z),dp;
system("sh","bertini input");
list P=getWitnessSet();
intvec v=3;
bigint C=bigint(10)**25;
ideal E1=num_elim1(P,2,C,v);
//Lastly, we compare the results.
E1;
setring r;
E2;
}
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
//////////////////////////// lattice basis reduction //////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
//An implementation of a simple LLL algorithm
//Works with real numbers
//Is only used by those procedures which require the user to provide a witness set,
// instead of calling Bertini to compute one.
static proc eucl(int m, vector u)
{//the square of the Euclidean norm of u
poly e=inner_product(u,u);
return(e);
}
static proc red(int i, module B, module U)
{
int j;
poly r;
for(j=i-1; j>=1; j--)
{
r=roundpoly(U[i][j]);
B[i]=B[i]-r*B[j];
U[i]=U[i]-r*U[j];
}
return(B,matrix(U));
}
static proc initBBsU(matrix M)
{//the columns of M a basis of a lattice over R
int m=nrows(M);
int c=ncols(M);
module B=M;
module Bs=M;
poly f,k,u;
matrix U=diag(1,c);
int i,j;
for(i=1; i<=c; i++)
{
for(j=1; j<=i-1; j++)
{
f=inner_product(B[i],Bs[j]);
k=inner_product(Bs[j],Bs[j]);
u=f/k;
U[j,i]=u;
Bs[i]=Bs[i]-u*Bs[j];
}
(B,U)=red(i,B,U);
}
return(B,Bs,U);
}
static proc mymax(int i, int k)
{
if(i >= k)
{
return(i);
}
return(k);
}
proc realLLL(matrix M)
"USAGE: realLLL(M); matrix M
ASSUME: The columns of M represent a basis of a lattice.
The groundfield is the field of real number or the field of complex numbers, the
elements of M are real numbers.
RETURN: matrix: the columns representing an LLL-reduced basis of the lattice given by M
EXAMPLE: example realLLL; shows an example
"
{
int n=ncols(M);
int m=nrows(M);
matrix U;
module B,Bs;
poly f,k,u;
(B,Bs,U)=initBBsU(M);
int i=1;
int j;
while(i<n)
{
//check whether there is an i sth eucl(Bs[i,i]) <= 4/3*euclid(Bs[i+1,i])
//if so, thats fine
//if not, b_i and b_i+1 are swapped + we do the necessary changes in Bs and U
if(inner_product(B[i],B[i]) <= (301/300)*inner_product(B[i+1],B[i+1]))
{
i++;
}
else
{
Bs[i+1]=Bs[i+1]+U[i,i+1]*Bs[i];
f=inner_product(B[i],Bs[i+1]);
k=inner_product(Bs[i+1],Bs[i+1]);
u=f/k;
U[i,i]=u;
U[i+1,i]=1;
U[i,i+1]=1;
U[i+1,i+1]=0;
Bs[i]=Bs[i]-U[i,i]*Bs[i+1];
U=permcol(U,i,i+1);
Bs=permcol(Bs,i,i+1);
B=permcol(B,i,i+1);
for(j=i+2; j<=n; j++)
{
f=inner_product(B[j],Bs[i]);
k=inner_product(Bs[i],Bs[i]);
u=f/k;
U[i,j]=u;
f=inner_product(B[j],Bs[i+1]);
k=inner_product(Bs[i+1],Bs[i+1]);
u=f/k;
U[i+1,j]=u;
}
if(absValue(U[i,i+1]) > 1/2)
{
(B,U)=red(i+1,B,U);
}
i=mymax(i-1,1);
}
}
return(B);
}
example
{ "EXAMPLE:"; echo=2;
ring r=(real,50),x,dp;
matrix M[5][4]=
1,0,0,0,
0,1,0,0,
0,0,1,0,
0,0,0,1,
5*81726716.91827716, 817267.1691827716, poly(10)**30, 13*81726716.91827716;
matrix L=realLLL(M);
print(L);
}
|