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
|
// Buchberger.cc
// implementation of Buchberger's Algorithm.
#ifndef BUCHBERGER_CC
#define BUCHBERGER_CC
#include "ideal.h"
/////////////////////////////////////////////////////////////////////////////
/////////////// S-pair computation //////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
BOOLEAN ideal::unnecessary_S_pair(list_iterator& first_iter,
list_iterator& second_iter) const
{
// This function checks several criteria to discard th S-pair of the
// binomials referenced by the iterators. The criteria depend on the
// settings of the ideal´s S-pair flags.
// The arguments are iterators instead of the referenced binomials
// because we have to do some equality tests. These are more efficient on
// iterators than on binomials.
///////////// criterion of relatively prime leading terms ///////////////////
// An S-pair can discarded if the leading terms of the two binomials are
// relatively prime.
if(rel_primeness)
if(relatively_prime(first_iter.get_element(),second_iter.get_element())
==TRUE)
return TRUE;
//////////// criterion M ///////////////////////////////////////////////////
if(M_criterion)
{
list_iterator iter;
binomial& bin1=first_iter.get_element();
binomial& bin2=second_iter.get_element();
// The M-criterion of Gebauer/Moeller checks binomial triples as
// explained in binomial.h; these are built of the elements referenced
// by the argument iterators and a third element appearing before the
// element referenced by second_iter in the generator lists.
#ifdef NO_SUPPORT_DRIVEN_METHODS_EXTENDED
iter.set_to_list(generators);
#endif // NO_SUPPORT_DRIVEN_METHODS_EXTENDED
#ifdef SUPPORT_DRIVEN_METHODS_EXTENDED
// The support of the lcm of two monomials is the union of their supports.
// To test criterion M, we then only have to consider lists whose support
// is a subset of the union of (first_iter.get_element()).head_support and
// (second_iter.get_element()).head_support. As only elements before
// second_iter.get_element() are tested, we can stop iteration as soon as
// we reach this element.
int supp2=bin2.head_support%Number_of_Lists;
int supp_union=(bin1.head_support%Number_of_Lists)|supp2;
// supp_union (read as binary vector) is the union of the supports of
// first_iter.get_element() and second_iter.get_element()
// (restricted to List_Support_Variables variables).
for(int i=0;i<S.number_of_subsets[supp_union];i++)
// Go through the lists that contain elements whose support is a
// subset of supp_union.
{
int actual_list=S.subsets_of_support[supp_union][i];
iter.set_to_list(generators[actual_list]);
// This is the i-th list among the generator list with elements
// whose support is a subset of supp_union.
if(actual_list==supp2)
break;
// The iteration has reached the list referenced by second_iter,
// this is handled alone to avoid unnecessary checks.
// Before breakin the loop, iter has to be set to this list.
while(iter.is_at_end()==FALSE)
// Iterate over the list with three iterators according to the
// description of criterion M.
{
if(M(iter.get_element(),bin1,bin2)==TRUE)
return TRUE;
iter.next();
}
}
#endif // SUPPORT_DRIVEN_METHODS_EXTENDED
// Now, iter references second_iter's list,
// if SUPPORT_DRIVEN_METHODS_EXTENDED are enabled or not.
while(iter!=second_iter)
{
if(M(iter.get_element(),bin1,bin2)==TRUE)
return TRUE;
iter.next();
}
}
/////////////////////// criterion F ////////////////////////////////////////
if(F_criterion)
{
list_iterator iter;
binomial& bin1=first_iter.get_element();
binomial& bin2=second_iter.get_element();
// The F-criterion of Gebauer/Moeller checks binomial triples as
// explained in binomial.h; these are built of the elements referenced
// by the argument iterators and a third element appearing before the
// element referenced by first_iter in the generator lists.
#ifdef NO_SUPPORT_DRIVEN_METHODS_EXTENDED
iter.set_to_list(generators);
#endif // NO_SUPPORT_DRIVEN_METHODS_EXTENDED
#ifdef SUPPORT_DRIVEN_METHODS_EXTENDED
// Again, we only have to consider lists whose support is a subset of the
// union of (first_iter.get_element()).head_support and
// (second_iter.get_element()).head_support.
// Additionally,we can override lists whose support is to small.
int supp1=bin1.head_support%Number_of_Lists;
int supp2=bin2.head_support%Number_of_Lists;
int supp_union=supp1|supp2;
// supp_union (read as binary vector) is the union of the supports of
// first_iter.get_element() and second_iter.get_element()
// (restricted to List_Support_Variables variables).
for(int i=0;i<S.number_of_subsets[supp_union];i++)
// Go through the lists that contain elements whose support is a
// subset of supp_union.
{
int actual_list=S.subsets_of_support[supp_union][i];
if((actual_list|supp2) != supp_union)
continue;
// The support of the actual list is too small, so its elements cannot
// satisfie criterion F.
iter.set_to_list(generators[actual_list]);
// This is the i-th list among the generator list with elements
// whose support is a subset of supp_union.
if(actual_list==supp1)
break;
// The iteration has reached the list referenced by first_iter;
// this is handled alone to avoid unnecessary checks.
// iter has to be set to that list before breaking the loop.
while(iter.is_at_end()==FALSE)
// Iterate over the list with three iterators according to the
// description of criterion F.
{
if(F(iter.get_element(),bin1,bin2)==TRUE)
return TRUE;
iter.next();
}
}
#endif // SUPPORT_DRIVEN_METHODS_EXTENDED
// Now, iter references first_iter's list,
// if SUPPORT_DRIVEN_METHODS_EXTENDED are enabled or not.
while(iter!=first_iter)
{
if(F(iter.get_element(),bin1,bin2)==TRUE)
return TRUE;
iter.next();
}
}
/////////////////////// criterion B /////////////////////////////////////////
if(B_criterion)
{
list_iterator iter;
binomial& bin1=first_iter.get_element();
binomial& bin2=second_iter.get_element();
// The B-criterion of Gebauer/Moeller checks binomial triples as
// explained in binomial.h; these are built of the elements referenced
// by the argument iterators and a third element appearing after the
// element referenced by second_iter in the generator lists.
iter=second_iter;
iter.next();
// First test second_iter's list.
// This is the only list if NO_SUPPORT_DRIVEN_METHODS are enabled.
while(iter.is_at_end()==FALSE)
{
if(B(iter.get_element(),bin1,bin2)==TRUE)
return(TRUE);
iter.next();
}
#ifdef SUPPORT_DRIVEN_METHODS_EXTENDED
// Now consider the other lists.
// Again, we only have to consider lists whose support is a subset of the
// union of (first_iter.get_element()).head_support and
// (second_iter.get_element()).head_support.
int supp2=bin2.head_support%Number_of_Lists;
int supp_union=(bin1.head_support%Number_of_Lists)|supp2;
// supp_union (read as binary vector) is the union of the supports of
// first_iter.get_element() and second_iter.get_element()
// (restricted to List_Support_Variables variables).
for(int i=0;i<S.number_of_subsets[supp_union];i++)
// Go through the lists that contain elements whose support is a
// subset of supp_union.
{
int actual_list=S.subsets_of_support[supp_union][i];
if(actual_list<=supp2)
continue;
// Only lists after second_iter's list have to be considered.
iter.set_to_list(generators[actual_list]);
// This is the i-th list among the generator list with elements
// whose support is a subset of supp_union.
while(iter.is_at_end()==FALSE)
{
// Iterate over the list with three iterators according to the
// description of criterion B.
if(B(iter.get_element(),bin1,bin2)==TRUE)
return TRUE;
iter.next();
}
}
#endif // SUPPORT_DRIVEN_METHODS_EXTENDED
}
////////////////////// Buchberger´s second criterion ////////////////////////
if(second_criterion)
{
list_iterator iter;
binomial& bin1=first_iter.get_element();
binomial& bin2=second_iter.get_element();
// The Buchberger´s second criterion checks binomial triples as
// explained in binomial.h; these are built of the elements referenced
// by the argument iterators and a third element appearing anywhere
// in the generator lists.
#ifdef NO_SUPPORT_DRIVEN_METHODS_EXTENDED
iter.set_to_list(generators);
while(iter.is_at_end()==FALSE)
// Iterate over the list with three iterators according to the
// description of the second criterion.
{
if((iter!=first_iter) && (iter!=second_iter))
// Else the second criterion must not be applied
// (lcm(a,b) is, of course, divisible by a and by b).
if(second_crit(iter.get_element(),bin1,bin2)==TRUE)
return TRUE;
iter.next();
}
#endif // NO_SUPPORT_DRIVEN_METHODS_EXTENDED
#ifdef SUPPORT_DRIVEN_METHODS_EXTENDED
// Again, we only have to consider lists whose support is a subset of
// the union of (first_iter.get_element()).head_support
// and (second_iter.get_element()).head_support.
int supp1=bin1.head_support%Number_of_Lists;
int supp2=bin2.head_support%Number_of_Lists;
int supp_union=supp1|supp2;
// supp_union (read as binary vector) is the union of the supports of
// first_iter.get_element() and second_iter.get_element()
// (restricted to List_Support_Variables variables)
for(int i=0;i<S.number_of_subsets[supp_union];i++)
// Go through the lists that contain elements whose support is a
// subset of supp_union.
{
int actual_list=S.subsets_of_support[supp_union][i];
if((actual_list==supp1) || (actual_list==supp2))
continue;
// The lists containing the elements referenced by the argument
// iterators are tested separately to avoid unnecessary checks for
// equality.
iter.set_to_list(generators[actual_list]);
// This is the i-th list among the generator list with elements
// whose support is a subset of supp_union.
while(iter.is_at_end()==FALSE)
// Iterate over the list with three iterators according to the
// description of the second criterion.
{
if(second_crit(iter.get_element(),bin1,bin2)==TRUE)
return TRUE;
iter.next();
}
}
if(supp1==supp2)
// The elements referenced by first_iter and second_iter appear in the
// same list.
{
iter.set_to_list(generators[supp1]);
while(iter.is_at_end()==FALSE)
{
if((iter!=first_iter) && (iter!=second_iter))
// Else the second criterion must not be applied
// (lcm(a,b) is, of course, divisible by a and by b).
if(second_crit(iter.get_element(),bin1,bin2)==TRUE)
return TRUE;
iter.next();
}
}
else
// The elements referenced by first_iter and second_iter appear in
// different lists.
{
// Test first_iter´s list.
iter.set_to_list(generators[supp1]);
while(iter.is_at_end()==FALSE)
{
if(iter!=first_iter)
// Else the second criterion must not be applied
// (lcm(a,b) is, of course, divisible by a and by b).
if(second_crit(iter.get_element(),bin1,bin2)==TRUE)
return TRUE;
iter.next();
}
// Test second_iter´s list.
iter.set_to_list(generators[supp2]);
while(iter.is_at_end()==FALSE)
{
if(iter!=second_iter)
// Else the second criterion must not be applied
// (lcm(a,b) is, of course, divisible by a and by b).
if(second_crit(iter.get_element(),bin1,bin2)==TRUE)
return TRUE;
iter.next();
}
}
#endif // SUPPORT_DRIVEN_METHODS_EXTENDED
}
// no criterion found to discard the S-Pair to compute
return FALSE;
}
ideal& ideal::compute_actual_S_pairs_1()
{
// This routine implements the simplest method for the S-pair computation
// (and one of the most efficient methods). We simply iterate over the
// generator list(s) with two pointers to look at each binomial pair.
// The "done"-mark of each list element tells us if this element was
// already considered in a previous S-pair computation; pairs of such
// "old" binomials do not have to be computed anymore (but pairs of an old
// and a new one have to be computed, of course). As the generator list are
// ordered with respect to the "done"-flag (all undone elements precede all
// done elements), we can avoid unnecessary iteration steps by breaking
// the iteration at the right point.
// The computed S-pairs are stored in the aux_list for further computations.
// For a better overview, the code for NO_SUPPORT_DRIVEN_METHODS_EXTENDED
// and SUPPORT_DRIVEN_METHODS_EXTENDED is completely separated in this
// function.
// Note that the "next()"-operations in the following routine do not reach a
// NULL pointer because of the implementation of the "is_at_end()"-function
// and because the "done"-component of the dummy element is set to zero.
#ifdef NO_SUPPORT_DRIVEN_METHODS_EXTENDED
list_iterator first_iter(generators);
while(first_iter.element_is_marked_done()==FALSE)
// new generator, compute S-pairs with all following generators
// Notice that the new generators are always at the beginning,
// the old generators at the end of the generator list.
{
binomial& bin=first_iter.get_element();
first_iter.mark_element_done();
list_iterator second_iter(first_iter);
second_iter.next();
// This may be the dummy element.
while(second_iter.is_at_end()==FALSE)
{
if(unnecessary_S_pair(first_iter,second_iter)==FALSE)
aux_list._insert(S_binomial(bin,second_iter.get_element(),w));
second_iter.next();
}
first_iter.next();
}
// Now, first_iter references an old generator or the end of the generator
// list. As all following generators are old ones, we are done.
#endif // NO_SUPPORT_DRIVEN_METHODS_EXTENDED
#ifdef SUPPORT_DRIVEN_METHODS_EXTENDED
list_iterator first_iter;
for(int i=0;i<Number_of_Lists;i++)
{
first_iter.set_to_list(generators[i]);
while(first_iter.element_is_marked_done()==FALSE)
// new generator, compute S-pairs with all following elements
// Notice that the new generators are always at the beginning,
// the old generators at the end of the generator lists.
{
binomial& bin=first_iter.get_element();
first_iter.mark_element_done();
// First search over the actual list with the second iterator.
list_iterator second_iter(first_iter);
second_iter.next();
while(second_iter.is_at_end()==FALSE)
{
if(unnecessary_S_pair(first_iter,second_iter)==FALSE)
aux_list._insert(S_binomial(bin,second_iter.get_element(),w));
second_iter.next();
}
// Then search over the remaining lists.
for(int j=i+1;j<Number_of_Lists;j++)
{
second_iter.set_to_list(generators[j]);
while(second_iter.is_at_end()==FALSE)
{
if(unnecessary_S_pair(first_iter,second_iter)==FALSE)
aux_list._insert(S_binomial(bin,second_iter.get_element(),w));
second_iter.next();
}
}
first_iter.next();
}
while(first_iter.is_at_end()==FALSE)
// old generator, compute only S-pairs with the following new generators
// (S-pairs with the following old generators were already computed
// before, first_iter.element_is_marked_done()==TRUE)
// As all generators in the actual list are old ones, we can
// start iteration with the next list.
{
binomial& bin=first_iter.get_element();
list_iterator second_iter;
for(int j=i+1;j<Number_of_Lists;j++)
// search over remaining lists
{
second_iter.set_to_list(generators[j]);
while(second_iter.element_is_marked_done()==FALSE)
// consider only new generators
{
if(unnecessary_S_pair(first_iter,second_iter)==FALSE)
aux_list._insert(S_binomial(bin,second_iter.get_element(),w));
second_iter.next();
}
}
first_iter.next();
}
}
#endif // SUPPORT_DRIVEN_METHODS_EXTENDED
return(*this);
}
ideal& ideal::compute_actual_S_pairs_1a()
{
// The only difference to the previous routine is that the aux_list is kept
// ordered with respect to the ideal´s term ordering, i.e. the inserts are
// replaced by ordered inserts.
#ifdef NO_SUPPORT_DRIVEN_METHODS_EXTENDED
list_iterator first_iter(generators);
while(first_iter.element_is_marked_done()==FALSE)
// new generator, compute S-pairs with all following generators
// Notice that the new generators are always at the beginning,
// the old generators at the end of the generator list.
{
binomial& bin=first_iter.get_element();
first_iter.mark_element_done();
list_iterator second_iter(first_iter);
second_iter.next();
// This may be the dummy element.
while(second_iter.is_at_end()==FALSE)
{
if(unnecessary_S_pair(first_iter,second_iter)==FALSE)
aux_list._ordered_insert
(S_binomial(bin,second_iter.get_element(),w),w);
second_iter.next();
}
first_iter.next();
}
// Now, first_iter references an old generator or the end of the generator
// list. As all following generators are old ones, we are done.
#endif // NO_SUPPORT_DRIVEN_METHODS_EXTENDED
#ifdef SUPPORT_DRIVEN_METHODS_EXTENDED
list_iterator first_iter;
for(int i=0;i<Number_of_Lists;i++)
{
first_iter.set_to_list(generators[i]);
while(first_iter.element_is_marked_done()==FALSE)
// new generator, compute S-pairs with all following elements
// Notice that the new generators are always at the beginning,
// the old generators at the end of the generator lists.
{
binomial& bin=first_iter.get_element();
first_iter.mark_element_done();
// First search over the actual list with the second iterator.
list_iterator second_iter(first_iter);
second_iter.next();
while(second_iter.is_at_end()==FALSE)
{
if(unnecessary_S_pair(first_iter,second_iter)==FALSE)
aux_list._ordered_insert
(S_binomial(bin,second_iter.get_element(),w),w);
second_iter.next();
}
// Then search over the remaining lists.
for(int j=i+1;j<Number_of_Lists;j++)
{
second_iter.set_to_list(generators[j]);
while(second_iter.is_at_end()==FALSE)
{
if(unnecessary_S_pair(first_iter,second_iter)==FALSE)
aux_list._ordered_insert
(S_binomial(bin,second_iter.get_element(),w),w);
second_iter.next();
}
}
first_iter.next();
}
while(first_iter.is_at_end()==FALSE)
// old generator, compute only S-pairs with the following new generators
// (S-pairs with the following old generators were already computed
// before, first_iter.element_is_marked_done()==TRUE)
// As all generators in the actual list are old ones, we can
// start iteration with the next list.
{
binomial& bin=first_iter.get_element();
list_iterator second_iter;
for(int j=i+1;j<Number_of_Lists;j++)
// search over remaining lists
{
second_iter.set_to_list(generators[j]);
while(second_iter.element_is_marked_done()==FALSE)
// consider only new generators
{
if(unnecessary_S_pair(first_iter,second_iter)==FALSE)
aux_list._ordered_insert
(S_binomial(bin,second_iter.get_element(),w),w);
second_iter.next();
}
}
first_iter.next();
}
}
#endif // SUPPORT_DRIVEN_METHODS_EXTENDED
return(*this);
}
ideal& ideal::compute_actual_S_pairs_2()
{
// This routine implements more dynamic S-pair-computation. As in the
// previous routines, we iterate over the generator list(s) with two
// iterators, forming pairs under the consideration of the "done"-flags.
// But before inserting into the aux_list, these S-pairs are reduced by
// the ideal generators. This seems to be clever, but shows to be a
// disadvantage:
// In the previous S-pair routines, the computed S-bionomials are not reduced
// at all. This is done in the appropriate Groebner basis routine
// (reduced_Groebner_basis_1 or ..._1a) when moving them from the aux_list
// to the generator lists. This means that S-binomials cannot only be reduced
// by the generators known at the time of their computation, but also by
// the S-pairs that where already treated.
// The advantage of the current routine is that the immediately reduced
// S-binomial can be used to reduce the ideal itself. This strategy keeps
// the ideal almost reduced, so the minimalization will be faster.
// Furthermore, the computation of S-pairs with unreduced generators is
// avoided.
// To provide a possibility to compensate the mentioned disadvantage,
// I have written the routine minimalize_S_pairs() that interreduces the
// binomials stored in aux_list.
#ifdef NO_SUPPORT_DRIVEN_METHODS_EXTENDED
list_iterator first_iter(generators);
Integer first_reduced=0;
Integer second_reduced=0;
// When reducing the ideal immediately by newly found generators, it
// can happen that the binomials referenced by the iterators are
// reduced to zero and then deleted. We need to make sure that the
// iterators do not reference freed memory in such a case. These two
// flags help us with this task.
while(first_iter.element_is_marked_done()==FALSE)
// new generator, compute S-pairs with all following generators
{
binomial& bin1=first_iter.get_element();
first_iter.mark_element_done();
list_iterator second_iter(first_iter);
second_iter.next();
// This may be the dummy element.
while((second_iter.is_at_end()==FALSE) && (first_reduced<=0))
{
if(unnecessary_S_pair(first_iter,second_iter)==FALSE)
{
binomial& bin2=second_iter.get_element();
// compute S-binomial
binomial& S_bin=S_binomial(bin1,bin2,w);
// reduce S-binomial by the actual ideal generators
reduce(S_bin,FALSE);
if(S_bin!=0)
{
// reduce the ideal generators by the S-binomial
first_reduced=bin1.head_reductions_by(S_bin);
second_reduced=bin2.head_reductions_by(S_bin);
reduce_by(S_bin,first_iter,second_iter);
aux_list._insert(S_bin);
}
else
delete &S_bin;
}
// Move second_iter to the next element if its referenced binomial
// has not changed (if it has changed, the binomial was moved to the
// aux_list during the reduce_by(...)-procedure, and second_iter
// already references a new binomial).
if(second_reduced<=0)
second_iter.next();
else
second_reduced=0;
}
// same procedure for first_iter
if(first_reduced<=0)
first_iter.next();
else
first_reduced=0;
}
#endif // NO_SUPPORT_DRIVEN_METHODS_EXTENDED
#ifdef SUPPORT_DRIVEN_METHODS_EXTENDED
list_iterator first_iter;
Integer first_reduced=0;
Integer second_reduced=0;
// When reducing the ideal immediately by newly found generators, it
// can happen that the binomials referenced by the iterators are
// changed (including their support!) or even reduced to zero and then
// deleted. We need to make sure that the iterators do not reference
// freed memory in such a case. These two flags help us with this task.
for(int i=0;i<Number_of_Lists;i++)
{
first_iter.set_to_list(generators[i]);
while(first_iter.element_is_marked_done()==FALSE)
// new generator, compute S-pairs with all following elements
{
binomial& bin1=first_iter.get_element();
first_iter.mark_element_done();
list_iterator second_iter(first_iter);
second_iter.next();
// First search over the actual list.
while((second_iter.is_at_end()==FALSE) && (first_reduced<=0))
{
if(unnecessary_S_pair(first_iter,second_iter)==FALSE)
{
binomial& bin2=second_iter.get_element();
// compute S-binomial
binomial& S_bin=S_binomial(bin1,bin2,w);
// reduce S-binomial by the actual ideal generators
reduce(S_bin,FALSE);
if((S_bin)!=0)
{
// reduce the ideal generators by the S-binomial
first_reduced=bin1.head_reductions_by(S_bin);
second_reduced=bin2.head_reductions_by(S_bin);
reduce_by(S_bin,first_iter,second_iter);
aux_list._insert(S_bin);
}
else
delete &S_bin;
}
// Move second_iter to the next element if its referenced binomial
// has not changed (if it has changed, the binomial was moved to the
// aux_list during the reduce_by(...)-procedure, and second_iter
// already references a new binomial).
if(second_reduced<=0)
second_iter.next();
else
second_reduced=0;
}
// Then search over the remaining lists.
for(int j=i+1;(j<Number_of_Lists) && (first_reduced<=0);j++)
{
second_iter.set_to_list(generators[j]);
while((second_iter.is_at_end()==FALSE) && (first_reduced<=0))
{
if(unnecessary_S_pair(first_iter,second_iter)==FALSE)
{
binomial& bin2=second_iter.get_element();
// compute S-binomial
binomial& S_bin=S_binomial(bin1,bin2,w);
// reduce S-binomial by the actual ideal generators
reduce(S_bin,FALSE);
if((S_bin)!=0)
{
// reduce the ideal generators by the S-binomial
first_reduced=bin1.head_reductions_by(S_bin);
second_reduced=bin2.head_reductions_by(S_bin);
reduce_by(S_bin,first_iter,second_iter);
aux_list._insert(S_bin);
}
else
delete& S_bin;
}
// Move second_iter to the next element if its referenced binomial
// has not changed.
if(second_reduced<=0)
second_iter.next();
else
second_reduced=0;
}
}
// same procedure for first_iter
if(first_reduced<=0)
first_iter.next();
else
first_reduced=0;
}
while(first_iter.is_at_end()==FALSE)
// old generator, compute only S-pairs with the following new generators
// As all generators in the actual list are old ones, we can
// start iteration with the next list.
{
binomial& bin1=first_iter.get_element();
list_iterator second_iter(first_iter);
second_iter.next();
for(int j=i+1;(j<Number_of_Lists) && (first_reduced<=0);j++)
{
second_iter.set_to_list(generators[j]);
while((second_iter.element_is_marked_done()==FALSE) &&
(first_reduced<=0))
// consider only new generators
{
if(unnecessary_S_pair(first_iter,second_iter)==FALSE)
{
binomial& bin2=second_iter.get_element();
// compute S-binomial
binomial& S_bin=S_binomial(bin1,bin2,w);
// reduce S-binomial by the actual ideal generators
reduce(S_bin,FALSE);
if((S_bin)!=0)
{
// reduce the ideal generators by the S-binomial
first_reduced=bin1.head_reductions_by(S_bin);
second_reduced=bin2.head_reductions_by(S_bin);
reduce_by(S_bin,first_iter,second_iter);
aux_list._insert(S_bin);
}
else
delete& S_bin;
}
// Move second_iter to the next element if its referenced binomial
// has not changed.
if(second_reduced<=0)
second_iter.next();
else
second_reduced=0;
}
}
// same procedure for first_iter
if(first_reduced<=0)
first_iter.next();
else
first_reduced=0;
}
}
#endif // SUPPORT_DRIVEN_METHODS_EXTENDED
return(*this);
}
ideal& ideal::compute_actual_S_pairs_3()
{
// This routine is quite similar to the preceding one.
// The main difference is that the computed S-binomials are not stored in the
// aux_list, but in new_generators. This makes a difference when minimalizing
// the S-binomials in the appropriate Groebner basis routine
// (reduced_Groebner_basis_3) with the help of the procedure
// minimalize_new_generators(...).
// If NO_SUPPORT_DRIVEN_METHODS_EXTENDED are enabled, only the organization
// of the minimalization is different.
// If SUPPORT_DRIVEN_METHODS_EXTENDED are enabled, the minimalization can
// use the support information.
#ifdef NO_SUPPORT_DRIVEN_METHODS_EXTENDED
list_iterator first_iter(generators);
Integer first_reduced=0;
Integer second_reduced=0;
// When reducing the ideal immediately by newly found generators, it
// can happen that the binomials referenced by the iterators are
// reduced to zero and then deleted. We need to make sure that the
// iterators do not reference freed memory in such a case. These two
// flags help us with this task.
while(first_iter.element_is_marked_done()==FALSE)
// new generator, compute S-pairs with all following generators
{
binomial& bin1=first_iter.get_element();
first_iter.mark_element_done();
list_iterator second_iter(first_iter);
second_iter.next();
// This may be the dummy element.
while((second_iter.is_at_end()==FALSE) && (first_reduced<=0))
{
if(unnecessary_S_pair(first_iter,second_iter)==FALSE)
{
binomial& bin2=second_iter.get_element();
// compute S-binomial
binomial& S_bin=S_binomial(bin1,bin2,w);
// reduce S-binomial by the actual ideal generators
reduce(S_bin,FALSE);
if(S_bin!=0)
{
// reduce the ideal generators by the S-binomial
first_reduced=bin1.head_reductions_by(S_bin);
second_reduced=bin2.head_reductions_by(S_bin);
reduce_by(S_bin,first_iter,second_iter);
add_new_generator(S_bin);
}
else
delete &S_bin;
}
// Move second_iter to the next element if its referenced binomial
// has not changed (if it has changed, the binomial was moved to the
// aux_list during the reduce_by(...)-procedure, and second_iter
// already references a new binomial).
if(second_reduced<=0)
second_iter.next();
else
second_reduced=0;
}
// same procedure for first_iter
if(first_reduced<=0)
first_iter.next();
else
first_reduced=0;
}
#endif // NO_SUPPORT_DRIVEN_METHODS_EXTENDED
#ifdef SUPPORT_DRIVEN_METHODS_EXTENDED
list_iterator first_iter;
Integer first_reduced=0;
Integer second_reduced=0;
// When reducing the ideal immediately by newly found generators, it
// can happen that the binomials referenced by the iterators are
// changed (including their support!) or even reduced to zero and then
// deleted. We need to make sure that the iterators do not reference
// freed memory in such a case. These two flags help us with this task.
for(int i=0;i<Number_of_Lists;i++)
{
first_iter.set_to_list(generators[i]);
while(first_iter.element_is_marked_done()==FALSE)
// new generator, compute S-pairs with all following elements
{
binomial& bin1=first_iter.get_element();
first_iter.mark_element_done();
list_iterator second_iter(first_iter);
second_iter.next();
// First search over the actual list.
while((second_iter.is_at_end()==FALSE) && (first_reduced<=0))
{
if(unnecessary_S_pair(first_iter,second_iter)==FALSE)
{
binomial& bin2=second_iter.get_element();
// compute S-binomial
binomial& S_bin=S_binomial(bin1,bin2,w);
// reduce S-binomial by the actual ideal generators
reduce(S_bin,FALSE);
if((S_bin)!=0)
{
// reduce the ideal generators by the S-binomial
first_reduced=bin1.head_reductions_by(S_bin);
second_reduced=bin2.head_reductions_by(S_bin);
reduce_by(S_bin,first_iter,second_iter);
add_new_generator(S_bin);
}
else
delete &S_bin;
}
// Move second_iter to the next element if its referenced binomial
// has not changed (if it has changed, the binomial was moved to the
// aux_list during the reduce_by(...)-procedure, and second_iter
// already references a new binomial).
if(second_reduced<=0)
second_iter.next();
else
second_reduced=0;
}
// Then search over the remaining lists.
for(int j=i+1;(j<Number_of_Lists) && (first_reduced<=0);j++)
{
second_iter.set_to_list(generators[j]);
while((second_iter.is_at_end()==FALSE) && (first_reduced<=0))
{
if(unnecessary_S_pair(first_iter,second_iter)==FALSE)
{
binomial& bin2=second_iter.get_element();
// compute S-binomial
binomial& S_bin=S_binomial(bin1,bin2,w);
// reduce S-binomial by the actual ideal generators
reduce(S_bin,FALSE);
if((S_bin)!=0)
{
// reduce the ideal generators by the S-binomial
first_reduced=bin1.head_reductions_by(S_bin);
second_reduced=bin2.head_reductions_by(S_bin);
reduce_by(S_bin,first_iter,second_iter);
add_new_generator(S_bin);
}
else
delete& S_bin;
}
// Move second_iter to the next element if its referenced binomial
// has not changed.
if(second_reduced<=0)
second_iter.next();
else
second_reduced=0;
}
}
// same procedure for first_iter
if(first_reduced<=0)
first_iter.next();
else
first_reduced=0;
}
while(first_iter.is_at_end()==FALSE)
// old generator, compute only S-pairs with the following new generators
// As all generators in the actual list are old ones, we can
// start iteration with the next list.
{
binomial& bin1=first_iter.get_element();
list_iterator second_iter(first_iter);
second_iter.next();
for(int j=i+1;(j<Number_of_Lists) && (first_reduced<=0);j++)
{
second_iter.set_to_list(generators[j]);
while((second_iter.element_is_marked_done()==FALSE) &&
(first_reduced<=0))
// consider only new generators
{
if(unnecessary_S_pair(first_iter,second_iter)==FALSE)
{
binomial& bin2=second_iter.get_element();
// compute S-binomial
binomial& S_bin=S_binomial(bin1,bin2,w);
// reduce S-binomial by the actual ideal generators
reduce(S_bin,FALSE);
if((S_bin)!=0)
{
// reduce the ideal generators by the S-binomial
first_reduced=bin1.head_reductions_by(S_bin);
second_reduced=bin2.head_reductions_by(S_bin);
reduce_by(S_bin,first_iter,second_iter);
add_new_generator(S_bin);
}
else
delete& S_bin;
}
// Move second_iter to the next element if its referenced binomial
// has not changed.
if(second_reduced<=0)
second_iter.next();
else
second_reduced=0;
}
}
// same procedure for first_iter
if(first_reduced<=0)
first_iter.next();
else
first_reduced=0;
}
}
#endif // SUPPORT_DRIVEN_METHODS_EXTENDED
// During the reduce_by(...)-routines, some reduced generators were
// perhaps moved to the aux_list. This list is emptied now: Like the
// computed S-pairs, its elements are moved to the list(s) new_generators.
// To avoid this construction, we would have to write a second version
// of the reduce_by(...)-procedure. The efficiency gains would however
// not be considerable.
list_iterator iter(aux_list);
while(iter.is_at_end()==FALSE)
{
add_new_generator(iter.get_element());
iter.extract_element();
}
return(*this);
}
//////////////////////////////////////////////////////////////////////////////
//////////// minimalization / autoreduction //////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
ideal& ideal::reduce_by(const binomial& bin, list_iterator& first_iter,
list_iterator& second_iter)
{
// This routine reduces the ideal by the argument binomial and takes
// care that the argument list iterators are not corrupted.
// Only head reductions are performed.
#ifdef NO_SUPPORT_DRIVEN_METHODS_EXTENDED
list_iterator iter(generators);
Integer reduced;
while(iter.is_at_end()==FALSE)
{
binomial& actual=iter.get_element();
// reduce actual binomial by bin
reduced=actual.head_reductions_by(bin);
if(reduced<=0)
iter.next();
else
// the actual binomial has changed and will be removed or
// moved to the aux_list
{
#ifdef SL_LIST
// If we use a simply linked list, we have to take care of the
// following binomial.
if(iter.next_is(first_iter)==TRUE)
first_iter=iter;
if(iter.next_is(second_iter)==TRUE)
second_iter=iter;
#endif // SL_LIST
#ifdef DL_LIST
// If we use a doubly linked list, we have to take care of the
// binomial itself.
if(iter==first_iter)
first_iter.next();
if(iter==second_iter)
second_iter.next();
#endif // DL_LIST
// move changed generator to the aux_list or delete it
if(actual==0)
iter.delete_element();
else
{
aux_list._insert(actual);
iter.extract_element();
}
size--;
}
}
#endif // NO_SUPPORT_DRIVEN_METHOD_EXTENDED
#ifdef SUPPORT_DRIVEN_METHODS_EXTENDED
int supp1=(first_iter.get_element()).head_support%Number_of_Lists;
int supp2=(second_iter.get_element()).head_support%Number_of_Lists;
// Determine the lists over which we have to iterate.
// These are the lists with elements whose support contains the support
// of bin.
// List i has to be checked iff the set of bits in i that are 1 contains
// the set of bits in supp that are 1.
// Equivalent: List i has to be checked iff the set of bits in i
// that are 0 is contained in the set of bits of supp that are 0.
// With this formulation, we can use the subset tree as follows:
int supp=bin.head_support%Number_of_Lists;
int inv_supp=Number_of_Lists-supp-1;
// This bit vector is the bitwise inverse of bin.head_support (restricted
// to the variables considered in the list indices.
list_iterator iter;
Integer reduced;
for(int i=0;i<S.number_of_subsets[inv_supp];i++)
{
int actual_list=Number_of_Lists-S.subsets_of_support[inv_supp][i]-1;
// the actual list for iteration
// The support of S.subsets_of_support[inv_supp][i] as a bit vector
// is contained in that of inv_supp.
// I.e. the support of
// Number_of_Lists-S.subsets_of_support[inv_supp][i]-1
// - which is the bitwise inverse of S.subsets_of_support[inv_supp][i] -
// contains the support of the bitwise inverse of inv_supp, hence the
// support of supp.
if((actual_list==supp1) || (actual_list==supp2))
// The lists referenced by first_iter and second_iter are tested
// separately to avoid unnecessary checks.
continue;
iter.set_to_list(generators[actual_list]);
while(iter.is_at_end()==FALSE)
{
binomial& actual=iter.get_element();
// reduce actual binomial by bin
reduced=actual.head_reductions_by(bin);
if(reduced<=0)
iter.next();
else
// the actual binomial has changed and will be removed or
{
if(actual==0)
iter.delete_element();
else
{
aux_list._insert(actual);
iter.extract_element();
}
size--;
}
}
}
// Now test the lists referenced by first_iter and second_iter.
if(supp1==supp2)
// first_iter and second_iter reference the same list
{
if((supp1|supp)==supp1)
// support of bin contained in that of the element referenced by
// first_iter, else this list has not to be tested
{
iter.set_to_list(generators[supp1]);
while(iter.is_at_end()==FALSE)
{
binomial& actual=iter.get_element();
reduced=actual.head_reductions_by(bin);
if(reduced<=0)
iter.next();
else
{
#ifdef SL_LIST
if(iter.next_is(first_iter)==TRUE)
first_iter=iter;
if(iter.next_is(second_iter)==TRUE)
second_iter=iter;
#endif // SL_LIST
#ifdef DL_LIST
if(iter==first_iter)
first_iter.next();
if(iter==second_iter)
second_iter.next();
#endif // DL_LIST
if(actual==0)
iter.delete_element();
else
{
aux_list._insert(actual);
iter.extract_element();
}
size--;
}
}
}
}
else
// first_iter and second_iter reference different lists
{
if((supp1|supp)==supp1)
// support of bin contained in that of the element referenced by
// first_iter, else this list has not to be tested
{
iter.set_to_list(generators[supp1]);
while(iter.is_at_end()==FALSE)
{
binomial& actual=iter.get_element();
reduced=actual.head_reductions_by(bin);
if(reduced<=0)
iter.next();
else
{
#ifdef SL_LIST
if(iter.next_is(first_iter)==TRUE)
first_iter=iter;
#endif // SL_LIST
#ifdef DL_LIST
if(iter==first_iter)
first_iter.next();
#endif // DL_LIST
if(actual==0)
iter.delete_element();
else
{
aux_list._insert(actual);
iter.extract_element();
}
size--;
}
}
}
if((supp2|supp)==supp2)
// support of bin contained in that of the element referenced by
// second_iter, else this list has not to be tested
{
iter.set_to_list(generators[supp2]);
while(iter.is_at_end()==FALSE)
{
binomial& actual=iter.get_element();
reduced=actual.head_reductions_by(bin);
if(reduced<=0)
iter.next();
else
{
#ifdef SL_LIST
if(iter.next_is(second_iter)==TRUE)
second_iter=iter;
#endif // SL_LIST
#ifdef DL_LIST
if(iter==second_iter)
second_iter.next();
#endif // DL_LIST
if(actual==0)
iter.delete_element();
else
{
aux_list._insert(actual);
iter.extract_element();
}
size--;
}
}
}
}
#endif
return *this;
}
ideal& ideal::minimalize_S_pairs()
{
// This routine implements a very simple minimalization method. We iterate
// over the S-pair lists with two iterators, interreducing the two referenced
// binomials. Remember that the S-pair list does not use the "head_reduced"-
// flags. The iteration is repeated as long as some interreduction is done.
list_iterator first_iter;
int found;
// to control if a reduction has occurred during the actual iteration
do
{
first_iter.set_to_list(aux_list);
found=0;
// no reduction occurred yet
while(first_iter.is_at_end()==FALSE)
{
binomial& bin1=first_iter.get_element();
int first_changed=0;
// to control if the first element has been reduced
// look at all following binomials
list_iterator second_iter(first_iter);
second_iter.next();
// this may be the dummy element
while(second_iter.is_at_end()==FALSE)
{
binomial& bin2=second_iter.get_element();
int second_changed=0;
if(bin1.reduce_head_by(bin2,w)!=0)
// head of first binomial can be reduced by second
{
if(bin1!=0)
found=1;
// found has not to be set if a binomial is reduced to zero
// (then there are no new binomials)
else
// the binomial referenced by bin1 is zero
{
#ifdef SL_LIST
if(first_iter.next_is(second_iter))
second_iter.next();
#endif // SL_LIST
first_iter.delete_element();
first_changed=1;
}
break;
// Breaks the while-loop.
// As the element referenced by first_iter has changed,
// the iteration with the second iterator can be restarted.
// (We try to reduce as many elements as possible in one iteration.)
}
if(bin2.reduce_head_by(bin1,w)!=0)
// head of second binomial can be reduced by first
{
if(bin2!=0)
found=1;
// found has not to be set if a binomial is reduced to zero
// (then there are no new binomials)
else
// binomial referenced by bin2 is zero
{
second_iter.delete_element();
second_changed=1;
}
// As the second iterator always references an element coming
// after first_iter's element in the generator list, we do not
// pay attention to the deletion...
}
if(second_changed==0)
second_iter.next();
}
// Now second_iter has reached the end of the generator list or the
// element referenced by first_iter has been reduced...The iteration
// is continued with a new (or changed) first binomial.
if(first_changed==0)
first_iter.next();
}
}
while(found==1);
// When leaving the loop, no generators have been interreduced during
// the last iteration.
return *this;
}
ideal& ideal::minimalize_new_generators()
{
// This routine is very similar to the following one, minimalize().
// The only difference is that we interreduce the elements stored in
// new_generators instead of those stored in generators.
// The size of the ideal has not to be manipulated hereby.
#ifdef NO_SUPPORT_DRIVEN_METHODS_EXTENDED
list_iterator first_iter;
int found;
// to control if a reduction has occurred during the actual iteration
do
{
first_iter.set_to_list(new_generators);
found=0;
// no reduction occurred yet
while(first_iter.element_is_marked_head_reduced()==FALSE)
// only the first element is tested for this flag
// the second may be an old one
{
binomial& bin1=first_iter.get_element();
int first_changed=0;
// to control if the first element has been reduced
// look at all following binomials
list_iterator second_iter(first_iter);
second_iter.next();
// this may be the dummy element
while(second_iter.is_at_end()==FALSE)
{
binomial& bin2=second_iter.get_element();
if(bin1.reduce_head_by(bin2,w)!=0)
// head of first binomial can be reduced by second
{
#ifdef SL_LIST
// The binomial referenced by first_iter will be deleted or
// extracted. When using a simply linked list, this also affects
// the following element. We need to assure that this element does
// not reference freed memory.
if(first_iter.next_is(second_iter))
second_iter.next();
#endif // SL_LIST
if(bin1!=0)
{
found=1;
// found has not to be set if a binomial is reduced to zero
// (then there are no new binomials to insert)
aux_list._insert(bin1);
first_iter.extract_element();
// moved changed binomial to aux_list
}
else
first_iter.delete_element();
first_changed=1;
break;
// As the binomial referenced by first_iter has changed,
// the iteration with the second iterator can be restarted.
// (We try to reduce as many elements as possible in one iteration.)
}
if(bin2.reduce_head_by(bin1,w)!=0)
// head of second binomial can be reduced by first
{
// Here we do not have to pay attention to the deletion or the
// extraction of the element referenced by second_iter because
// the element referenced by second_iter always comes after the
// element referenced by first_iter in new_generators.
if(bin2!=0)
{
found=1;
// found has not to be set if a binomial is reduced to zero
// (then there are no new binomials to insert)
aux_list._insert(bin2);
second_iter.extract_element();
// move the element referenced by second_iter to aux_list
}
else
second_iter.delete_element();
// Here it makes not sense to restart iteration because the
// deletion sets the pointers as desired.
}
else
// no reduction possible
second_iter.next();
}
// Now second_iter has reached the end of the list new_generators or the
// binomial referenced first_iter has been reduced...The iteration
// is continued with a new (or changed) first binomial.
if(first_changed==0)
first_iter.next();
}
// Now we have found all currently possible reductions.
// The elements remaining in new_generators cannot be interreduced
// and are marked head_reduced.
first_iter.set_to_list(new_generators);
// if(first_iter.is_at_end()==FALSE)
while(first_iter.element_is_marked_head_reduced()==FALSE)
{
first_iter.mark_element_head_reduced();
first_iter.next();
}
// Now reinsert reduced elements.
first_iter.set_to_list(aux_list);
while(first_iter.is_at_end()==FALSE)
{
binomial& bin=first_iter.get_element();
reduce(bin,FALSE);
// The binomial was only reduced by one other binomial before it was
// moved to aux_list. To reduce it by all other binomials now can
// diminish the number of iterations (do-while-loop).
if(bin==0)
first_iter.delete_element();
else
{
add_new_generator(bin);
first_iter.extract_element();
}
}
}
while(found==1);
// When leaving the loop, no generators have been interreduced during
// the last iteration; we are done.
#endif // NO_SUPPORT_DRIVEN_METHODS_EXTENDED
#ifdef SUPPORT_DRIVEN_METHODS_EXTENDED
list_iterator first_iter;
list_iterator second_iter;
int found;
// to control if a reduction has occurred during the actual iteration
do
{
found=0;
// no reduction occurred yet
for(int i=0;i<Number_of_Lists;i++)
{
first_iter.set_to_list(new_generators[i]);
// First try to reduce the binomials that are marked unreduced.
while(first_iter.element_is_marked_head_reduced()==FALSE)
// all other elements have to be tested for interreduction
{
binomial& bin=first_iter.get_element();
Integer changed=0;
// binomial referenced by bin not yet reduced
// Look for head reductions:
// Iterate over the lists that could contain reducers for the head of bin.
// The list containing bin is tested separately to avoid an interreduction
// of a binomial by itself respectively unnecessary checks for this when the
// two iterators reference different lists.
for(int j=0;(j<S.number_of_subsets[i]-1)&&(changed==0);j++)
{
second_iter.set_to_list(new_generators[S.subsets_of_support[i][j]]);
// This is the j-th list among the new_generator lists with elements
// whose support is a subset of that of i.
// The support of i is just the head support of bin (restricted
// to the corresponding variables).
while((second_iter.is_at_end()==FALSE)&&(changed==0))
{
changed=bin.reduce_head_by(second_iter.get_element(),w);
if(changed!=0)
// bin has been reduced
{
if(bin!=0)
{
found=1;
// found has only to be set if the binomial has not been
// reduced to zero (else there are no new binomials)
aux_list._insert(bin);
first_iter.extract_element();
}
else
first_iter.delete_element();
}
second_iter.next();
}
}
// The list new_generators[i]
// =new_generators[S.subsets_of_support[i][S.number_of_subsets[i]-1]]
// has to be tested separately to avoid a reduction of the actual
// binomial by itself.
if(changed==0)
// binomial referenced by first_iter has not yet been reduced
{
second_iter.set_to_list(new_generators[i]);
while((second_iter.is_at_end()==FALSE) && (changed==0))
{
if(second_iter!=first_iter)
// the two iterators do not reference the same element
changed=bin.reduce_head_by(second_iter.get_element(),w);
if(changed!=0)
// bin has been reduced
{
#ifdef SL_LIST
// bin will be deleted ar extracted - maybe dangerous for
// second_iter
if(first_iter.next_is(second_iter))
second_iter.next();
#endif // SL_LIST
if(bin!=0)
{
found=1;
aux_list._insert(bin);
first_iter.extract_element();
}
else
first_iter.delete_element();
}
else
// bin has not been reduced
second_iter.next();
}
}
if(changed==0)
first_iter.next();
// Else first_iter has already been set to the next element by deletion
// or extraction.
}
// Now try to reduce the binomials that are marked reduced.
while(first_iter.is_at_end()==FALSE)
// only unreduced elements have to be tested for interreduction
{
binomial& bin=first_iter.get_element();
Integer changed=0;
// binomial referenced by bin not yet reduced
// Look for head reductions:
// Iterate over the lists that could contain reducers for the head of bin.
// The list containing bin is tested separately to avoid an interreduction
// of a binomial by itself respectively unnecessary checks for this when the
// two iterators reference different lists.
for(int j=0;(j<S.number_of_subsets[i]-1)&&(changed==0);j++)
{
second_iter.set_to_list(new_generators[S.subsets_of_support[i][j]]);
// This is the j-th list among the new_generators lists with elements
// whose support is a subset of that of i.
// The support of i is just the head support of bin (restricted
// to the corresponding variables).
while((second_iter.element_is_marked_head_reduced()==FALSE) &&
(changed==0))
{
changed=bin.reduce_head_by(second_iter.get_element(),w);
if(changed!=0)
// bin has been reduced
{
if(bin!=0)
{
found=1;
// found has only to be set if the binomial has not been
// reduced to zero (else there are no new binomials)
aux_list._insert(bin);
first_iter.extract_element();
}
else
first_iter.delete_element();
}
second_iter.next();
}
}
// The list new_generators[i]
// =new_generators[S.subsets_of_support[i][S.number_of_subsets[i]-1]]
// has to be tested separately to avoid a reduction of the actual
// binomial by itself.
if(changed==0)
// binomial referenced by first_iter has not yet been reduced
{
second_iter.set_to_list(new_generators[i]);
while((second_iter.element_is_marked_head_reduced()==FALSE) &&
(changed==0))
{
if(second_iter!=first_iter)
// the two iterators do not reference the same element
changed=bin.reduce_head_by(second_iter.get_element(),w);
if(changed!=0)
// bin has been reduced
{
#ifdef SL_LIST
// bin will be deleted ar extracted - maybe dangerous for
// second_iter
if(first_iter.next_is(second_iter))
second_iter.next();
#endif // SL_LIST
if(bin!=0)
{
found=1;
aux_list._insert(bin);
first_iter.extract_element();
}
else
first_iter.delete_element();
}
else
// bin has not been reduced
second_iter.next();
}
}
if(changed==0)
first_iter.next();
// Else first_iter has already been set to the next element by deletion
// or extraction.
}
}
// Now we have found all currently possible reductions.
// The elements remaining in the new_generator lists cannot be interreduced
// and are marked reduced.
for(int i=0;i<Number_of_Lists;i++)
{
first_iter.set_to_list(new_generators[i]);
if(first_iter.is_at_end()==FALSE)
while(first_iter.element_is_marked_head_reduced()==FALSE)
{
first_iter.mark_element_head_reduced();
first_iter.next();
}
}
// Now reinsert reduced elements
// It seems to be quite unimportant for the performance if an element is
// completely reduced before reinsertion or not.
first_iter.set_to_list(aux_list);
while(first_iter.is_at_end()==FALSE)
{
binomial& bin=first_iter.get_element();
reduce(bin,FALSE);
if(bin==0)
first_iter.delete_element();
else
{
add_new_generator(bin);
first_iter.extract_element();
}
}
}
while(found==1);
// When leaving the loop, no generators have been interreduced during
// the last iteration; we are done.
#endif // SUPPORT_DRIVEN_METHODS_EXTENDED
return(*this);
}
ideal& ideal::minimalize()
{
// For a better overview, the code for NO_SUPPORT_DRIVEN_METHODS_EXTENDED
// and SUPPORT_DRIVEN_METHODS_EXTENDED is completely separated in this
// function. Note that th iteration methods are quite different for those
// two possibilities.
#ifdef NO_SUPPORT_DRIVEN_METHODS_EXTENDED
// For technical simplicity, the interreduction is done as follows:
// We iterate over the generators with two iterators.
// For each binomial pair, we examine if one binomial´s head can be
// reduced by the other. If this is the case, the reducible binomial is
// reduced and moved to the aux_list if it is not 0, else deleted.
// After one iteration, the elements of the aux_list are reinserted;
// then the interreduction is restarted until no new elements are found.
// The above method of deleting and inserting is chosen for the following
// reasons:
// - The order undone elements - done elements in the generator lists
// is not destroyed. Newly found elements are automatically marked
// undone when they are reinserted.
// The S-pair computation can as usually make use of this fact.
// - In analogy, the order head_unreduced elements - head_reduced elements
// is not destroyed. Remark that an undone element can never be reduced, as
// reduction is only done after an S-pair computation. Newly found
// elements are automatically marked unreduced. With the "head_reduced"-
// flag we make sure that any binomial pair is tested only once for
// interreduction during the whole algorithm.
list_iterator first_iter;
int found;
// to control if a reduction has occurred during the actual iteration
do
{
first_iter.set_to_list(generators);
found=0;
// no reduction occurred yet
while(first_iter.element_is_marked_head_reduced()==FALSE)
// only the first element is tested for this flag
// the second may be an old one
{
binomial& bin1=first_iter.get_element();
int first_changed=0;
// to control if the first element has been reduced
// look at all following binomials
list_iterator second_iter(first_iter);
second_iter.next();
// this may be the dummy element
while(second_iter.is_at_end()==FALSE)
{
binomial& bin2=second_iter.get_element();
if(bin1.reduce_head_by(bin2,w)!=0)
// head of first binomial can be reduced by second
{
#ifdef SL_LIST
// The binomial referenced by first_iter will be deleted or
// extracted. When using a simply linked list, this also affects
// the following element. We need to assure that this element does
// not reference freed memory.
if(first_iter.next_is(second_iter))
second_iter.next();
#endif // SL_LIST
if(bin1!=0)
{
found=1;
// found has not to be set if a binomial is reduced to zero
// (then there are no new binomials to insert)
aux_list._insert(bin1);
first_iter.extract_element();
// moved changed binomial to aux_list
}
else
first_iter.delete_element();
first_changed=1;
size--;
break;
// As the binomial referenced by first_iter has changed,
// the iteration with the second iterator can be restarted.
// (We try to reduce as many elements as possible in one iteration.)
}
if(bin2.reduce_head_by(bin1,w)!=0)
// head of second binomial can be reduced by first
{
// Here we do not have to pay attention to the deletion or the
// extraction of the element referenced by second_iter because
// the element referenced by second_iter always comes after the
// element referenced by first_iter in the generator list.
if(bin2!=0)
{
found=1;
// found has not to be set if a binomial is reduced to zero
// (then there are no new binomials to insert)
aux_list._insert(bin2);
second_iter.extract_element();
// move the element referenced by second_iter to aux_list
}
else
second_iter.delete_element();
size--;
// Here it makes not sense to restart iteration because the
// deletion sets the pointers as desired.
}
else
// no reduction possible
second_iter.next();
}
// Now second_iter has reached the end of the generator list or the
// binomial referenced first_iter has been reduced...The iteration
// is continued with a new (or changed) first binomial.
if(first_changed==0)
first_iter.next();
}
// Now we have found all currently possible reductions.
// The elements remaining in the generator list cannot be interreduced
// and are marked head_reduced.
first_iter.set_to_list(generators);
// if(first_iter.is_at_end()==FALSE)
while(first_iter.element_is_marked_head_reduced()==FALSE)
{
first_iter.mark_element_head_reduced();
first_iter.next();
}
// Now reinsert reduced elements.
first_iter.set_to_list(aux_list);
while(first_iter.is_at_end()==FALSE)
{
binomial& bin=first_iter.get_element();
reduce(bin,FALSE);
// The binomial was only reduced by one other generator before it was
// moved to aux_list. To reduce it by all other generators now can
// diminish the number of iterations (do-while-loop).
if(bin==0)
first_iter.delete_element();
else
{
generators.insert(bin);
// We do not call the add_generator(...)-routine because we do not
// want number_of_new_binomials to be incremented.
size++;
first_iter.extract_element();
}
}
}
while(found==1);
// When leaving the loop, no generators have been interreduced during
// the last iteration; we are done.
#endif // NO_SUPPORT_DRIVEN_METHODS_EXTENDED
#ifdef SUPPORT_DRIVEN_METHODS_EXTENDED
// In this case, the reduction has to be organized in a different way to
// use the support information to its full extend. Without the support
// methods, we test interreduction symmetrically: if we have a pair of
// generators, we test if generator 1 can be reduced by generator 2 AND
// if generator 2 can be reduced by generator 1. So each unordered pair is
// considered only once.
// If we would implement the same for the support methods, the second head
// reduction could not use the support information.
// For this reason, we test ordered pairs: For a given generator, we
// try to reduce his head by all other generators, considering its head
// support vector.
// The method of moving changed binomials to aux_list and later reinserting
// them is kept. When using SUPPORT_DRIVEN_METHODS_EXTENDED, it is even
// necessary to choose such a method because the head support of some
// binomials may change, too, a fact that requires the list structure to be
// rebuilt.
list_iterator first_iter;
list_iterator second_iter;
int found;
// to control if a reduction has occurred during the actual iteration
do
{
found=0;
// no reduction occurred yet
for(int i=0;i<Number_of_Lists;i++)
{
first_iter.set_to_list(generators[i]);
// First try to reduce the binomials that are marked unreduced.
while(first_iter.element_is_marked_head_reduced()==FALSE)
// all other elements have to be tested for interreduction
{
binomial& bin=first_iter.get_element();
Integer changed=0;
// binomial referenced by bin not yet reduced
// Look for head reductions:
// Iterate over the lists that could contain reducers for the head of bin.
// The list containing bin is tested separately to avoid an interreduction
// of a binomial by itself respectively unnecessary checks for this when the
// two iterators reference different lists.
for(int j=0;(j<S.number_of_subsets[i]-1)&&(changed==0);j++)
{
second_iter.set_to_list(generators[S.subsets_of_support[i][j]]);
// This is the j-th list among the generator lists with elements
// whose support is a subset of that of i.
// The support of i is just the head support of bin (restricted
// to the corresponding variables).
while((second_iter.is_at_end()==FALSE)&&(changed==0))
{
changed=bin.reduce_head_by(second_iter.get_element(),w);
if(changed!=0)
// bin has been reduced
{
if(bin!=0)
{
found=1;
// found has only to be set if the binomial has not been
// reduced to zero (else there are no new binomials)
aux_list._insert(bin);
first_iter.extract_element();
}
else
first_iter.delete_element();
size--;
}
second_iter.next();
}
}
// The list generators[i]
// =generators[S.subsets_of_support[i][S.number_of_subsets[i]-1]]
// has to be tested separately to avoid a reduction of the actual
// binomial by itself.
if(changed==0)
// binomial referenced by first_iter has not yet been reduced
{
second_iter.set_to_list(generators[i]);
while((second_iter.is_at_end()==FALSE) && (changed==0))
{
if(second_iter!=first_iter)
// the two iterators do not reference the same element
changed=bin.reduce_head_by(second_iter.get_element(),w);
if(changed!=0)
// bin has been reduced
{
#ifdef SL_LIST
// bin will be deleted ar extracted - maybe dangerous for
// second_iter
if(first_iter.next_is(second_iter))
second_iter.next();
#endif // SL_LIST
if(bin!=0)
{
found=1;
aux_list._insert(bin);
first_iter.extract_element();
}
else
first_iter.delete_element();
size--;
}
else
// bin has not been reduced
second_iter.next();
}
}
if(changed==0)
first_iter.next();
// Else first_iter has already been set to the next element by deletion
// or extraction.
}
// Now try to reduce the binomials that are marked reduced.
while(first_iter.is_at_end()==FALSE)
// only unreduced elements have to be tested for interreduction
{
binomial& bin=first_iter.get_element();
Integer changed=0;
// binomial referenced by bin not yet reduced
// Look for head reductions:
// Iterate over the lists that could contain reducers for the head of bin.
// The list containing bin is tested separately to avoid an interreduction
// of a binomial by itself respectively unnecessary checks for this when the
// two iterators reference different lists.
for(int j=0;(j<S.number_of_subsets[i]-1)&&(changed==0);j++)
{
second_iter.set_to_list(generators[S.subsets_of_support[i][j]]);
// This is the j-th list among the generator lists with elements
// whose support is a subset of that of i.
// The support of i is just the head support of bin (restricted
// to the corresponding variables).
while((second_iter.element_is_marked_head_reduced()==FALSE) &&
(changed==0))
{
changed=bin.reduce_head_by(second_iter.get_element(),w);
if(changed!=0)
// bin has been reduced
{
if(bin!=0)
{
found=1;
// found has only to be set if the binomial has not been
// reduced to zero (else there are no new binomials)
aux_list._insert(bin);
first_iter.extract_element();
}
else
first_iter.delete_element();
size--;
}
second_iter.next();
}
}
// The list generators[i]
// =generators[S.subsets_of_support[i][S.number_of_subsets[i]-1]]
// has to be tested separately to avoid a reduction of the actual
// binomial by itself.
if(changed==0)
// binomial referenced by first_iter has not yet been reduced
{
second_iter.set_to_list(generators[i]);
while((second_iter.element_is_marked_head_reduced()==FALSE) &&
(changed==0))
{
if(second_iter!=first_iter)
// the two iterators do not reference the same element
changed=bin.reduce_head_by(second_iter.get_element(),w);
if(changed!=0)
// bin has been reduced
{
#ifdef SL_LIST
// bin will be deleted ar extracted - maybe dangerous for
// second_iter
if(first_iter.next_is(second_iter))
second_iter.next();
#endif // SL_LIST
if(bin!=0)
{
found=1;
aux_list._insert(bin);
first_iter.extract_element();
}
else
first_iter.delete_element();
size--;
}
else
// bin has not been reduced
second_iter.next();
}
}
if(changed==0)
first_iter.next();
// Else first_iter has already been set to the next element by deletion
// or extraction.
}
}
// Now we have found all currently possible reductions.
// The elements remaining in the generator lists cannot be interreduced
// and are marked reduced.
for(int i=0;i<Number_of_Lists;i++)
{
first_iter.set_to_list(generators[i]);
if(first_iter.is_at_end()==FALSE)
while(first_iter.element_is_marked_head_reduced()==FALSE)
{
first_iter.mark_element_head_reduced();
first_iter.next();
}
}
// Now reinsert reduced elements
// It seems to be quite unimportant for the performance if an element is
// completely reduced before reinsertion or not.
first_iter.set_to_list(aux_list);
while(first_iter.is_at_end()==FALSE)
{
binomial& bin=first_iter.get_element();
reduce(bin,FALSE);
if(bin==0)
first_iter.delete_element();
else
{
generators[bin.head_support%Number_of_Lists].insert(bin);
size++;
// We do not call the add_generator(...)-routine because we do not
// want number_of_new_binomials to be incremented.
first_iter.extract_element();
}
}
}
while(found==1);
// When leaving the loop, no generators have been interreduced during
// the last iteration; we are done.
#endif // SUPPORT_DRIVEN_METHODS_EXTENDED
return(*this);
}
ideal& ideal::final_reduce()
{
// During Buchberger´s algorithm, we perform only head reductions
// (minimalizations). This strategy showed to be a little more efficient
// than the strategy to do reduce the ideal always completely.
// This method leads to a minimal, but in general not to the reduced Groebner
// basis. The actual procedure reduces such a minimal basis at the end of
// Buchberger´s algorithm. It will probably cause problems when called
// in the course of the algorithm. For an explanation of this fact, see
// the following comment.
minimalize();
// Now there remain only tail reductions. They are quite simple: Each
// binomial's tail is reduced as long as possible. As no binomial can be
// reduced to zero by that and a binomial cannot reduce its own tail,
// we do not have to pay special attention to that (under the assumption
// that a real term ordering (i.e. a well-ordering) is used and that
// the head and the tail of the binomial are coorect with respect to this
// ordering).
// Notice that the head can change because of a tail reduction due to the
// trivial factors elimination (the new head will always divide the
// old one). This change is especially dangerous if
// SUPPORT_DRIVEN_METHODS_EXTENDED are enabled: It may happen that the
// binomial is in the wrong list after a tail reduction.
// Furthermore, if a head change occurs, it may happen that the generating
// set is no more minimalized after this. So the reduction has to be restarted
// after such a head change (and the respective binomial has to be marked
// head_unreduced before).
// This does not seem to be very efficient.
// For this reason, the reduction routine is only written for a final
// reduction (having already computed a Groebner basis of the ideal).
// This Groebner basis is first minimalized. After that, a head change during
// tail reduction is impossible because the head is already a minimal
// generator of the initial ideal (and the new head would divide the old).
// However, this argumentation is only valid if the input ideal is saturated.
// In some algorithms (Hosten_Sturmfels...) this is not the case in
// intermediate steps. The final reduction may cause inconsistencies here.
// But as the list structure is rebuild after each intermediate Groebner
// basis calculation (change of the term ordering) and as the last Groebner
// basis calculation deals with a saturated ideal, the final result will be
// correct.
// (For non-saturated input ideals, the computed Groebner basis is in general
// not a Groebner basis of the input ideal, but one for an ideal "between"
// the input ideal and its saturation.)
#ifdef NO_SUPPORT_DRIVEN_METHODS_EXTENDED
list_iterator first_iter;
first_iter.set_to_list(generators);
while(first_iter.is_at_end()==FALSE)
{
binomial& bin=first_iter.get_element();
int changed;
// to control if bin has been reduced
do
{
changed=0;
list_iterator second_iter;
second_iter.set_to_list(generators);
while(second_iter.is_at_end()==FALSE)
{
changed+=bin.reduce_tail_by(second_iter.get_element(),w);
// As soon as a reduction occurs, changed is set to a value !=0.
second_iter.next();
}
}
while(changed>0);
first_iter.next();
}
#endif // NO_SUPPORT_DRIVEN_METHODS_EXTENDED
#ifdef SUPPORT_DRIVEN_METHODS_EXTENDED
// In this case, the reduction has to be organized in a slightly different
// way to use the support information to its full extend.
// As soon as an reduction has taken place, the iteration over the reducer
// lists is restarted using the new tail support information.
list_iterator first_iter;
for(int i=0;i<Number_of_Lists;i++)
{
first_iter.set_to_list(generators[i]);
while(first_iter.is_at_end()==FALSE)
{
binomial& bin=first_iter.get_element();
int changed;
// to control if bin has been reduced
do
{
changed=0;
list_iterator second_iter;
int supp=bin.tail_support%Number_of_Lists;
// determine the lists over which we have to iterate
for(int j=0;(j<S.number_of_subsets[supp]) && (changed==0);j++)
{
second_iter.set_to_list(generators[S.subsets_of_support[supp][j]]);
// This is the j-th list among the generator lists with elements
// whose support is a subset of supp.
while((second_iter.is_at_end()==FALSE) && (changed==0))
{
changed=bin.reduce_tail_by(second_iter.get_element(),w);
// Here we can do a simple assignment; as the iteration is stopped
// as soon as some reduction is done, reduced cannot be reset to
// zero in this assignment.
second_iter.next();
}
}
}
while(changed>0);
first_iter.next();
}
}
#endif // SUPPORT_DRIVEN_METHODS_EXTENDED
return(*this);
}
//////////////////////////////////////////////////////////////////////////////
////////////////////// auxiliary stuff ///////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
int ideal::add_new_generators()
{
// Reduces the binomials in the "new_generators" list(s) by the generators
// and moves them to the "generators" list(s).
#ifdef NO_SUPPORT_DRIVEN_METHODS_EXTENDED
int result=0;
// element inserted?
list_iterator iter(new_generators);
while(iter.is_at_end()==FALSE)
{
binomial& bin=iter.get_element();
reduce(bin,FALSE);
if(bin==0)
iter.delete_element();
else
{
add_generator(bin);
iter.extract_element();
result=1;
}
}
#endif // NO_SUPPORT_DRIVEN_METHODS_EXTENDED
#ifdef SUPPORT_DRIVEN_METHODS_EXTENDED
int result=0;
// element inserted?
list_iterator iter;
for(int i=0;i<Number_of_Lists;i++)
{
iter.set_to_list(new_generators[i]);
while(iter.is_at_end()==FALSE)
{
binomial& bin=iter.get_element();
reduce(bin,FALSE);
if(bin==0)
iter.delete_element();
else
{
add_generator(bin);
iter.extract_element();
result=1;
}
}
}
#endif // SUPPORT_DRIVEN_METHODS_EXTENDED
return result;
}
/////////////////////////////////////////////////////////////////////////////
///////////////////// binomial reduction ////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
binomial& ideal::reduce(binomial& bin, BOOLEAN complete) const
{
// As bin is reduced by a fixed set of binomials, it is sufficient to do
// head reductions first, then tail reductions (cf. Pottier).
list_iterator iter;
Integer reduced;
// to control if the binomial has been reduced during the actual iteration
#ifdef NO_SUPPORT_DRIVEN_METHODS_EXTENDED
do
{
iter.set_to_list(generators);
reduced=0;
// not yet reduced
while(iter.is_at_end()==FALSE)
{
reduced+=bin.reduce_head_by(iter.get_element(),w);
// reduced is incremented (and so set to a value >0) as soon as bin
// is really reduced
iter.next();
}
}
while((reduced>0) && (bin!=0));
if(complete==TRUE)
do
{
iter.set_to_list(generators);
reduced=0;
// not yet reduced
while(iter.is_at_end()==FALSE)
{
reduced+=bin.reduce_tail_by(iter.get_element(),w);
// reduced is incremented (and so set to a value >0) as soon as bin
// is really reduced
iter.next();
}
}
while((reduced>0) && (bin!=0));
#endif // NO_SUPPORT_DRIVEN_METHODS_EXTENDED
#ifdef SUPPORT_DRIVEN_METHODS_EXTENDED
do
{
reduced=0;
// not yet reduced
int supp=bin.head_support%Number_of_Lists;
// determine the lists over which we have to iterate
// As soon as some reduction is done, the iteration is started with
// the new support information; so we do not finish iterations over lists
// that cannot contain reducers any more.
for(int i=0;(i<S.number_of_subsets[supp]) && (reduced==0);i++)
{
iter.set_to_list(generators[S.subsets_of_support[supp][i]]);
// This is the i-th list among the generator lists with elements
// whose support is a subset of that of supp.
while((iter.is_at_end()==FALSE)&&(reduced==0))
{
reduced=bin.reduce_head_by(iter.get_element(),w);
// Here we can do a simple assignment; as the iteration is stopped
// as soon as some reduction is done, reduced cannot be reset to zero
// in this assignment.
iter.next();
}
}
}
while((reduced>0) && (bin!=0));
if(complete==TRUE)
do
{
reduced=0;
// not yet reduced
int supp=bin.tail_support%Number_of_Lists;
// determine the lists over which we have to iterate
// As soon as some reduction is done, the iteration is started with
// the new support information; so we do not finish iterations over
// lists that cannot contain reducers any more.
for(int i=0;(i<S.number_of_subsets[supp]) && (reduced==0);i++)
{
iter.set_to_list(generators[S.subsets_of_support[supp][i]]);
// This is the i-th list among the generator lists with elements
// whose support is a subset of that of supp.
while((iter.is_at_end()==FALSE)&&(reduced==0))
{
reduced=bin.reduce_tail_by(iter.get_element(),w);
// Here we can do a simple assignment; as the iteration is stopped
// as soon as some reduction is done, reduced cannot be reset to
// zero in this assignment
iter.next();
}
}
}
while(reduced>0);
// bin cannot be reduced to zero by a tail reduction
#endif // SUPPORT_DRIVEN_METHODS_EXTENDED
return(bin);
}
//////////////////////////////////////////////////////////////////////////////
/////////// variants of Buchberger´s algorithm ///////////////////////////////
//////////////////////////////////////////////////////////////////////////////
ideal& ideal::reduced_Groebner_basis_1(const int& S_pair_criteria,
const float& interred_percentage)
{
// set flags for the use of the S-pair criteria
// for an explanation see in globals.h
rel_primeness=(S_pair_criteria & 1);
M_criterion=(S_pair_criteria & 2);
F_criterion=(S_pair_criteria & 4);
B_criterion=(S_pair_criteria & 8);
second_criterion=(S_pair_criteria & 16);
interreduction_percentage=interred_percentage;
int done;
// control variable for recognizing when Buchberger's algorithm has reached
// his end
// first minimalize the initial generating system
minimalize();
do
{
done=1;
// no new generators found yet
compute_actual_S_pairs_1();
// compute the S-pairs of the actual generators
// These are stored in a unreduced form in aux_list.
list_iterator S_pair_iter(aux_list);
// now reduce and insert the computed S-pairs
while(S_pair_iter.is_at_end()==FALSE)
{
binomial& S_bin=S_pair_iter.get_element();
reduce(S_bin,FALSE);
if(S_bin!=0)
// new generator found
{
add_generator(S_bin);
S_pair_iter.extract_element();
done=0;
// algorithm does not terminate when a new generator is found
}
else
S_pair_iter.delete_element();
}
// now all computed S-pairs are inserted as generators
// enough for a minimalization?
if(interreduction_percentage>=0)
// intermediate interreductions allowed
{
if(number_of_new_binomials>=size*interreduction_percentage/100)
// enough new generators since last minimalization
{
minimalize();
number_of_new_binomials=0;
}
}
// now we restart the algorithm with the new generating system
// if the generating system has changed during the last iteration
}
while(done==0);
// if done==1, all computed S-pairs reduced to zero
// compute reduced from minimal Groebner basis
final_reduce();
return(*this);
}
ideal& ideal::reduced_Groebner_basis_1a(const int& S_pair_criteria,
const float& interred_percentage)
{
// set flags for the use of the S-pair criteria
// for an explanation see in globals.h
rel_primeness=(S_pair_criteria & 1);
M_criterion=(S_pair_criteria & 2);
F_criterion=(S_pair_criteria & 4);
B_criterion=(S_pair_criteria & 8);
second_criterion=(S_pair_criteria & 16);
interreduction_percentage=interred_percentage;
int done;
// control variable for recognizing when Buchberger's algorithm has reached
// his end
// first minimalize the initial generating system
minimalize();
do
{
done=1;
// no new generators found yet
compute_actual_S_pairs_1a();
// compute the S-pairs of the actual generators
// These are stored in a unreduced form in aux_list.
// aux_list is ordered according to the ideal´s term ordering.
list_iterator S_pair_iter(aux_list);
// now reduce and insert the computed S-pairs
while(S_pair_iter.is_at_end()==FALSE)
{
binomial& S_bin=S_pair_iter.get_element();
reduce(S_bin,FALSE);
if(S_pair_iter.get_element()!=0)
// new generator found
{
add_generator(S_bin);
S_pair_iter.extract_element();
done=0;
// algorithm does not terminate when a new generator is found
}
else
S_pair_iter.delete_element();
}
// now all computed S-pairs are inserted as generators
// enough for a minimalization?
if(interreduction_percentage>=0)
// intermediate interreductions allowed
{
if(number_of_new_binomials>=size*interreduction_percentage/100)
// enough new generators since last minimalization
{
minimalize();
number_of_new_binomials=0;
}
}
// now we restart the algorithm with the new generating system
// if the generating system has changed during the last iteration
}
while(done==0);
// if done==1, all computed S-pairs reduced to zero
// compute reduced from minimal Groebner basis
final_reduce();
return(*this);
}
ideal& ideal::reduced_Groebner_basis_2(const int& S_pair_criteria,
const float& interred_percentage)
{
// set flags for the use of the S-pair criteria
// for an explanation see in globals.h
rel_primeness=(S_pair_criteria & 1);
M_criterion=(S_pair_criteria & 2);
F_criterion=(S_pair_criteria & 4);
B_criterion=(S_pair_criteria & 8);
second_criterion=(S_pair_criteria & 16);
interreduction_percentage=interred_percentage;
int done;
// control variable for recognizing when Buchberger's algorithm has reached
// his end
// first minimalize the initial generating system
minimalize();
do
{
done=1;
// no new generators found yet
compute_actual_S_pairs_2();
// compute the S-pairs of the actual generators
// These are stored in a reduced version in aux_list.
minimalize_S_pairs();
// minimalize the binomials in aux_list
// These are not only S-pairs, but also ideal generators that were
// reduced by an S-pair during the S-pair computation.
list_iterator S_pair_iter(aux_list);
if(S_pair_iter.is_at_end()==FALSE)
// Zero binomials are not inserted in aux_list during the S-pair
// computation; i.e. if aux_list is not empty, a further iteration step
// has to be done.
done=0;
// now insert the computed S-pairs
while(S_pair_iter.is_at_end()==FALSE)
// S_pairs remaining
{
add_generator(S_pair_iter.get_element());
S_pair_iter.extract_element();
}
// now all computed S-pairs are inserted as generators
// enough for a minimalization?
if(interreduction_percentage>=0)
// intermediate interreductions allowed
{
if(number_of_new_binomials>=size*interreduction_percentage/100)
// enough new generators since last minimalization
{
minimalize();
number_of_new_binomials=0;
}
}
// now we restart the algorithm with the new generating system
// if the generating system has changed during the last iteration
}
while(done==0);
// if done==1, all computed S-pairs reduced to zero
// compute reduced from minimal Groebner basis
final_reduce();
return(*this);
}
ideal& ideal::reduced_Groebner_basis_3(const int& S_pair_criteria,
const float& interred_percentage)
{
// set flags for the use of the S-pair criteria
// for an explanation see in globals.h
rel_primeness=(S_pair_criteria & 1);
M_criterion=(S_pair_criteria & 2);
F_criterion=(S_pair_criteria & 4);
B_criterion=(S_pair_criteria & 8);
second_criterion=(S_pair_criteria & 16);
interreduction_percentage=interred_percentage;
int not_done;
// control variable for recognizing when Buchberger's algorithm has reached
// his end
// first minimalize the initial generating system
minimalize();
do
{
compute_actual_S_pairs_3();
// compute the S-pairs of the actual generators
// These are stored in areduced version in the list(s) new_generators.
minimalize_new_generators();
// minimalize the binomials in aux_list
// These are not only S-pairs, but also ideal generators that were
// reduced by an S-pair during the S-pair computation.
not_done=add_new_generators();
// move binomials from new_generators to generators
// now all computed S-pairs are inserted as generators
// enough for a minimalization?
if(interreduction_percentage>=0)
// intermediate interreductions allowed
{
if(number_of_new_binomials>=size*interreduction_percentage/100)
// enough new generators since last reduction
{
minimalize();
number_of_new_binomials=0;
}
}
// now we restart the algorithm with the new generating system
// if the generating system has changed during the last iteration
}
while(not_done==1);
// if not_done==0, all computed S-pairs reduced to zero
// compute reduced from minimal Groebner basis
final_reduce();
return(*this);
}
ideal& ideal::reduced_Groebner_basis(const int& version,
const int& S_pair_criteria,
const float& interred_percentage)
{
switch(version)
{
case 0:
return reduced_Groebner_basis_1a(S_pair_criteria, interred_percentage);
case 1:
return reduced_Groebner_basis_1(S_pair_criteria, interred_percentage);
case 2:
return reduced_Groebner_basis_2(S_pair_criteria, interred_percentage);
case 3:
return reduced_Groebner_basis_3(S_pair_criteria, interred_percentage);
default:
cerr<<"WARNING: ideal& ideal::reduced_Groebner_basis(const int&, "
"const int&, const float&):\n"
"version argument out of range, nothing done"<<endl;
return*this;
}
}
#endif // BUCHBERGER_CC
|