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

; ACL2 Version 3.1  A Computational Logic for Applicative Common Lisp
; Copyright (C) 2006 University of Texas at Austin
; This version of ACL2 is a descendent of ACL2 Version 1.9, Copyright
; (C) 1997 Computational Logic, Inc. See the documentation topic NOTE20.
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
; Written by: Matt Kaufmann and J Strother Moore
; email: Kaufmann@cs.utexas.edu and Moore@cs.utexas.edu
; Department of Computer Sciences
; University of Texas at Austin
; Austin, TX 787121188 U.S.A.
(inpackage "ACL2")
(defun selectxclset (clset inducthintval)
; This function produces the clause set we explore to collect
; induction candidates. The x in this name means "explore." If
; inducthintval is nonnil and nont, we use the usersupplied
; induction hint value (which, if t means use clset); otherwise, we
; use clset.
(cond ((null inducthintval) clset)
((equal inducthintval *t*) clset)
(t (list (list inducthintval)))))
(defun unchangeables (formals args quickblockinfo subset ans)
; We compute the set of all variable names occurring in args in
; unchanging measured formal positions. We accumulate the answer onto
; ans.
(cond ((null formals) ans)
((and (membereq (car formals) subset)
(eq (car quickblockinfo) 'unchanging))
(unchangeables (cdr formals) (cdr args) (cdr quickblockinfo) subset
(allvars1 (car args) ans)))
(t
(unchangeables (cdr formals) (cdr args) (cdr quickblockinfo) subset
ans))))
(defun changeables (formals args quickblockinfo subset ans)
; We compute the args in changing measured formal positions. We
; accumulate the answer onto ans.
(cond ((null formals) ans)
((and (membereq (car formals) subset)
(not (eq (car quickblockinfo) 'unchanging)))
(changeables (cdr formals) (cdr args) (cdr quickblockinfo)
subset
(cons (car args) ans)))
(t
(changeables (cdr formals) (cdr args) (cdr quickblockinfo)
subset
ans))))
(defun soundinductionprinciplemask1 (formals args quickblockinfo
subset
unchangeables
changeables)
; See soundinductionprinciplemask.
(cond
((null formals) nil)
(t (let ((var (car formals))
(arg (car args))
(q (car quickblockinfo)))
(mvlet (maskele newunchangeables newchangeables)
(cond ((membereq var subset)
(cond ((eq q 'unchanging)
(mv 'unchangeable unchangeables changeables))
(t (mv 'changeable unchangeables changeables))))
((and (variablep arg)
(eq q 'unchanging))
(cond ((membereq arg changeables)
(mv nil unchangeables changeables))
(t (mv 'unchangeable
(addtoseteq arg unchangeables)
changeables))))
((and (variablep arg)
(not (membereq arg changeables))
(not (membereq arg unchangeables)))
(mv 'changeable
unchangeables
(cons arg changeables)))
(t (mv nil unchangeables changeables)))
(cons maskele
(soundinductionprinciplemask1 (cdr formals)
(cdr args)
(cdr quickblockinfo)
subset
newunchangeables
newchangeables)))))))
(defun soundinductionprinciplemask (term formals quickblockinfo subset)
; Term is a call of some fn on some args. The formals and
; quickblockinfo are those of fn, and subset is one of fn's measured
; subset (a subset of formals). We wish to determine, in the
; terminology of ACL, whether the induction applies to term. If so we
; return a mask indicating how to build the substitutions for the
; induction from args and the machine for fn. Otherwise we return
; nil.
; Let the changeables be those args that are in measured formal
; positions that sometimes change in the recursion. Let the
; unchangeables be all of the variables occurring in measured actuals
; that never change in recursion. The induction applies if
; changeables is a sequence of distinct variable names and has an
; empty intersection with unchangeables.
; If the induction is applicable then the substitutions should
; substitute for the changeables just as the recursion would, and hold
; each unchangeable fixed  i.e., substitute each for itself. With
; such substitutions it is possible to prove the measure lemmas
; analogous to those proved when justification of subset was stored,
; except that the measure is obtained by instantiating the measure
; term used in the justification by the measured actuals in unchanging
; slots. Actual variables that are neither among the changeables or
; unchangeables may be substituted for arbitrarily.
; If the induction is applicable we return a mask with as many
; elements as there are args. For each arg the mask contains either
; 'changeable, 'unchangeable, or nil. 'Changeable means the arg
; should be instantiated as specified in the recursion. 'Unchangeable
; means each var in the actual should be held fixed. Nil means that
; the corresponding substitution pairs in the machine for the function
; should be ignored.
; Abstractly, this function builds the mask by first putting either
; 'changeable or 'unchangeable in each measured slot. It then fills
; in the remaining slots from the left so as to permit the actual to
; be instantiated or held fixed as desired by the recursion, provided
; that in so doing it does not permit substitutions for previously
; allocated actuals.
(let ((unchangeables
(unchangeables formals (fargs term) quickblockinfo subset nil))
(changeables
(changeables formals (fargs term) quickblockinfo subset nil)))
(cond ((or (not (noduplicatespequal changeables))
(not (allvariablep changeables))
(intersectpeq changeables unchangeables))
nil)
(t (soundinductionprinciplemask1 formals
(fargs term)
quickblockinfo
subset
unchangeables
changeables)))))
(defrec candidate
(score controllers changedvars unchangeablevars
testsandalistslst justification inductionterm otherterms
xinductionterm xotherterms xancestry
ttree)
nil)
; This record is used to represent one of the plausible inductions that must be
; considered. The SCORE represents some fairly artificial estimation of how
; many terms in the conjecture want this induction. CONTROLLERS is the list of
; the controllers  including unchanging controllers  for all the inductions
; merged to form this one. The CHANGEDVARS is a list of all those variables
; that will be instantiated (nonidentically) in some induction hypotheses.
; Thus, CHANGEDVARS include both variables that actually contribute to why
; some measure goes down and variables like accumulators that are just along
; for the ride. UNCHANGEABLEVARS is a list of all those vars which may not be
; changed by any substitution if this induction is to be sound for the reasons
; specified. TESTSANDALISTSLST is a list of TESTSANDALISTS which
; indicates the case analysis for the induction and how the various induction
; hypotheses are obtained via substitutions. JUSTIFICATION is the
; JUSTIFICATION that justifies this induction, and INDUCTIONTERM is the term
; that suggested this induction and from which you obtain the actuals to
; substitute into the template. OTHERTERMS are the inductionterms of
; candidates that have been merged into this one for heuristic reasons.
; Because of induction rules we can think of some terms being aliases for
; others. We have to make a distinction between the terms in the conjecture
; that suggested an induction and the actual terms that suggested the
; induction. For example, if an induction rule maps (fn x y) to (recur x y),
; then (recur x y) will be the INDUCTIONTERM because it suggested the
; induction and we will, perhaps, have to recover its induction machine or
; quick block information to implement various heuristics. But we do not wish
; to report (recur x y) to the user, preferring instead to report (fn x y).
; Therefore, corresponding to INDUCTIONTERM and OTHERTERMS we have
; XINDUCTIONTERM and XOTHERTERMS, which are maintained in exactly the same
; way as their counterparts but which deal completely with the userlevel view
; of the induction. In practice this means that we will initialize the
; XINDUCTIONTERM field of a candidate with the term from the conjecture,
; initialize the INDUCTIONTERM with its alias, and then merge the fields
; completely independently but analogously. XANCESTRY is a field maintained by
; merging to contain the userlevel terms that caused us to change our
; testsandalists. (Some candidates may be flushed or merged into this one
; without changing it.)
; The ttree of a candidate contains 'LEMMA tags listing the :induction rules
; (if any) involved in the suggestion of the candidate.
(defun countnonnils (lst)
(cond ((null lst) 0)
((car lst) (1+ (countnonnils (cdr lst))))
(t (countnonnils (cdr lst)))))
(defun controllers (formals args subset ans)
(cond ((null formals) ans)
((member (car formals) subset)
(controllers (cdr formals) (cdr args) subset
(allvars1 (car args) ans)))
(t (controllers (cdr formals) (cdr args) subset ans))))
(defun changed/unchangedvars (x args mask ans)
(cond ((null mask) ans)
((eq (car mask) x)
(changed/unchangedvars x (cdr args) (cdr mask)
(allvars1 (car args) ans)))
(t (changed/unchangedvars x (cdr args) (cdr mask) ans))))
(defrec testsandalists (tests alists) nil)
(defun testsandalists/alist (alist args mask callargs)
; Alist is an alist that maps the formals of some fn to its actuals,
; args. Mask is a soundinductionprinciplemask indicating the args
; for which we will build substitution pairs. Callargs is the list of
; arguments to some recursive call of fn occurring in the induction
; machine for fn. We build an alist mapping the masked args to the
; instantiations (under alist) of the values in callargs.
(cond
((null mask) nil)
((null (car mask))
(testsandalists/alist alist (cdr args) (cdr mask) (cdr callargs)))
((eq (car mask) 'changeable)
(cons (cons (car args)
(sublisvar alist (car callargs)))
(testsandalists/alist alist
(cdr args)
(cdr mask)
(cdr callargs))))
(t (let ((vars (allvars (car args))))
(append (pairlis$ vars vars)
(testsandalists/alist alist
(cdr args)
(cdr mask)
(cdr callargs)))))))
(defun testsandalists/alists (alist args mask calls)
; Alist is an alist that maps the formals of some fn to its actuals,
; args. Mask is a soundinductionprinciplemask indicating the args
; for which we will build substitution pairs. Calls is the list of
; calls for a given case of the induction machine. We build the alists
; from those calls.
(cond
((null calls) nil)
(t (cons (testsandalists/alist alist args mask (fargs (car calls)))
(testsandalists/alists alist args mask (cdr calls))))))
; The following record contains the tests leading to a collection of
; recursive calls at the end of a branch through a defun. In general,
; the calls may not be to the function being defuned but rather to
; some other function in the same mutually recursive clique, but in
; the context of induction we know that all the calls are to the same
; fn because we haven't implemented mutually recursive inductions yet.
; A list of these records constitute the induction machine for a function.
(defrec testsandcalls (tests . calls) nil)
; The justification record contains a subset of the formals of the function
; under which it is stored. Only the subset field has semantic content! The
; other fields are the domain predicate, mp; the relation, rel, which is
; wellfounded on mp objects; and the mpmeasure term which has been proved to
; decrease in the recursion. The latter three fields are correct at the time
; the function is admitted, but note that they might all be local and hence
; have disappeared by the time these fields are read. Thus, we include them
; only for heuristic purposes, for example as used in
; books/workshops/2004/legato/support/generictheories.lisp.
; A list of justification records is stored under each function symbol by the
; defun principle.
(defrec justification (subset mp rel measure) nil)
(defun testsandalists (alist args mask tc)
; Alist is an alist that maps the formals of some fn to its actuals,
; args. Mask is a soundinductionprinciplemask indicating the args
; for which we will build substitution pairs. Tc is one of the
; testsandcalls in the induction machine for the function. We make
; a testsandalists record containing the instantiated tests of tc
; and alists derived from the calls of tc.
(make testsandalists
:tests (sublisvarlst alist (access testsandcalls tc :tests))
:alists (testsandalists/alists alist
args
mask
(access testsandcalls tc :calls))))
(defun testsandalistslst (alist args mask machine)
; We build a list of testsandalists from machine, instantiating it
; with alist, which is a map from the formals of the function to the
; actuals, args. Mask is the soundinductionprinciplemask that
; indicates the args for which we substitute.
(cond
((null machine) nil)
(t (cons (testsandalists alist args mask (car machine))
(testsandalistslst alist args mask (cdr machine))))))
(defun fleshoutinductionprinciple (term formals justification mask machine
xterm ttree)
; Term is a call of some function the indicated formals and induction machine.
; Justification is its 'justification and mask is a soundinduction
; principlemask for the term. We build the induction candidate suggested by
; term.
(make candidate
:score
(/ (countnonnils mask) (length mask))
:controllers
(controllers formals (fargs term)
(access justification justification :subset)
nil)
:changedvars
(changed/unchangedvars 'changeable (fargs term) mask nil)
:unchangeablevars
(changed/unchangedvars 'unchangeable (fargs term) mask nil)
:testsandalistslst
(testsandalistslst (pairlis$ formals (fargs term))
(fargs term) mask machine)
:justification justification
:inductionterm term
:xinductionterm xterm
:otherterms nil
:xotherterms nil
:xancestry nil
:ttree ttree))
(defun intrinsicsuggestedinductioncand
(term formals quickblockinfo justification machine xterm ttree ens wrld)
; Note: An "intrinsically suggested" induction scheme is an induction scheme
; suggested by a justification of a recursive function. The rune controlling
; the intrinsic suggestion from the justification of fn is (:induction fn). We
; distinguish between intrinsically suggested inductions and those suggested
; via records of inductionrule type. Intrinsic inductions have no embodiment
; as inductionrules but are, instead, the basis of the semantics of such
; rules. That is, the inductions suggested by (fn x y) is the union of those
; suggested by the terms to which it is linked via inductionrules together
; with the intrinsic suggestion for (fn x y).
; Term, above, is a call of some fn with the given formals, quickblockinfo,
; justification and induction machine. We return a list of induction
; candidates, said list either being empty or the singleton list containing the
; induction candidate intrinsically suggested by term. Xterm is logically
; unrelated to term and is the term appearing in the original conjecture from
; which we (somehow) obtained term for consideration.
(let ((inductionrune (list :induction (ffnsymb term))))
(cond
((enabledrunep inductionrune ens wrld)
(let ((mask (soundinductionprinciplemask term formals
quickblockinfo
(access justification
justification
:subset))))
(cond
(mask
(list (fleshoutinductionprinciple term formals
justification
mask
machine
xterm
(pushlemma inductionrune
ttree))))
(t nil))))
(t nil))))
(defrec inductionrule (nume (pattern . condition) scheme . rune) nil)
(mutualrecursion
(defun applyinductionrule (rule term typealist xterm ttree ens wrld)
; We apply the inductionrule, rule, to term, and return a possibly empty list
; of suggested inductions. The basic idea is to check that the rule is enabled
; and that the :pattern of the rule matches term. If so, we check that the
; :condition of the rule is true under the current typealist. This check is
; heuristic only and so we indicate that the guards have been checked and we
; allow forcing. We ignore the ttree because we are making a heuristic choice
; only. If typeset says the :condition is nonnil, we fire the rule by
; instantiating the :scheme and recursively getting the suggested inductions
; for that term. Note that we are not recursively exploring the instantiated
; scheme but just getting the inductions suggested by its toplevel function
; symbol.
(cond
((enablednumep (access inductionrule rule :nume) ens)
(mvlet
(ans alist)
(onewayunify (access inductionrule rule :pattern)
term)
(cond
(ans
(withaccumulatedpersistence
(access inductionrule rule :rune)
(suggestions)
(mvlet
(ts ttree1)
(typeset (sublisvar alist
(access inductionrule rule :condition))
t nil typealist nil ens wrld nil
nil nil)
(declare (ignore ttree1))
(cond
((tsintersectp *tsnil* ts) nil)
(t (let ((term1 (sublisvar alist
(access inductionrule rule :scheme))))
(cond ((or (variablep term1)
(fquotep term1))
nil)
(t (suggestedinductioncands term1 typealist
xterm
(pushlemma
(access inductionrule
rule
:rune)
ttree)
ens wrld)))))))))
(t nil))))
(t nil)))
(defun suggestedinductioncands1
(inductionrules term typealist xterm ttree ens wrld)
; We map down inductionrules and apply each enabled rule to term, which is
; known to be an application of the function symbol fn to some args. Each rule
; gives us a possibly empty list of suggested inductions. We append all these
; suggestions together. In addition, if fn is recursively defined and is
; enabled (or, even if fn is disabled if we are exploring a usersupplied
; induction hint) we collect the intrinsic suggestion for term as well.
(cond
((null inductionrules)
(let* ((fn (ffnsymb term))
(machine (getprop fn 'inductionmachine nil
'currentacl2world wrld)))
(cond
((null machine) nil)
(t
; Historical note: Before Version_2.6 we had the following note:
; Note: The intrinsic suggestion will be nonnil only if (:INDUCTION fn) is
; enabled and so here we have a case in which two runes have to be enabled
; (the :DEFINITION and the :INDUCTION runes) to get the desired effect. It
; is not clear if this is a good design but at first sight it seems to
; provide upward compatibility because in Nqthm a disabled function suggests
; no inductions.
; We no longer make any such requirement: the test above (t) replaces the
; following.
; (or (enabledfnp fn nil ens wrld)
; (and inducthintval
; (not (equal inducthintval *t*))))
(intrinsicsuggestedinductioncand
term
(formals fn wrld)
(getprop fn 'quickblockinfo
'(:error "See SUGGESTEDINDUCTIONCANDS1.")
'currentacl2world wrld)
(getprop fn 'justification
'(:error "See SUGGESTEDINDUCTIONCANDS1.")
'currentacl2world wrld)
machine
xterm
ttree
ens
wrld)))))
(t (append (applyinductionrule (car inductionrules)
term typealist
xterm ttree ens wrld)
(suggestedinductioncands1 (cdr inductionrules)
term typealist
xterm ttree ens wrld)))))
(defun suggestedinductioncands
(term typealist xterm ttree ens wrld)
; Term is some fn applied to args. Xterm is some term occurring in the
; conjecture we are exploring and is the term upon which this induction
; suggestion will be "blamed" and from which we have obtained term via
; inductionrules. We return all of the induction candidates suggested by
; term. Lambda applications suggest no inductions. Disabled functions suggest
; no inductions  unless we are applying the user's induct hint value (in
; which case we, quite reasonably, assume every function in the value is worthy
; of analysis since any function could have been omitted).
(cond
((flambdap (ffnsymb term)) nil)
(t (suggestedinductioncands1
(getprop (ffnsymb term) 'inductionrules nil 'currentacl2world wrld)
term typealist xterm ttree ens wrld))))
)
(mutualrecursion
(defun getinductioncands (term typealist ens wrld ans)
; We explore term and accumulate onto ans all of the induction
; candidates suggested by it.
(cond ((variablep term) ans)
((fquotep term) ans)
((eq (ffnsymb term) 'hide)
ans)
(t (getinductioncandslst
(fargs term)
typealist ens wrld
(append (suggestedinductioncands term typealist
term nil ens wrld)
ans)))))
(defun getinductioncandslst (lst typealist ens wrld ans)
; We explore the list of terms, lst, and accumulate onto ans all of
; the induction candidates.
(cond ((null lst) ans)
(t (getinductioncands
(car lst)
typealist ens wrld
(getinductioncandslst
(cdr lst)
typealist ens wrld ans)))))
)
(defun getinductioncandsfromclset1 (clset ens oncepoverride wrld state
ans)
; We explore clset and accumulate onto ans all of the induction
; candidates.
(cond
((null clset) ans)
(t (mvlet (contradictionp typealist fcpairs)
(forwardchain (car clset) nil t
nil ; donotreconsiderp
wrld ens oncepoverride state)
; We need a typealist with which to compute induction aliases. It is of
; heuristic use only, so we may as well turn the forceflg on. We assume no
; contradiction is found. If by chance one is, then typealist is nil, which
; is an acceptable typealist.
(declare (ignore contradictionp fcpairs))
(getinductioncandslst
(car clset)
typealist ens wrld
(getinductioncandsfromclset1 (cdr clset)
ens oncepoverride wrld state
ans))))))
(defun getinductioncandsfromclset (clset pspv wrld state)
; We explore clset and collect all induction candidates.
(let ((rcnst (access provespecvar pspv :rewriteconstant)))
(getinductioncandsfromclset1 clset
(access rewriteconstant
rcnst
:currentenabledstructure)
(access rewriteconstant
rcnst
:oncepoverride)
wrld
state
nil)))
; That completes the development of the code for exploring a clause set
; and gathering the induction candidates suggested.
; Section: PigeonHolep
; We next develop pigeonholep, which tries to fit some "pigeons" into
; some "holes" using a function to determine the sense of the word
; "fit". Since ACL2 is firstorder we can't pass arbitrary functions
; and hence we pass symbols and define our own specialpurpose "apply"
; that interprets the particular symbols passed to calls of
; pigeonholep.
; However, it turns out that the applications of pigeonholep require
; passing functions that themselves call pigeonholep. And so
; pigeonholepapply is mutually recursive with pigeonholep (but only
; because the application functions use pigeonholep).
(mutualrecursion
(defun pigeonholepapply (fn pigeon hole)
; See pigeonholep for the problem and terminology. This function
; takes a symbol denoting a predicate and two arguments. It applies
; the predicate to the arguments. When the predicate holds we say
; the pigeon argument "fits" into the hole argument.
(case fn
(pairfitp
; This predicate is applied to two pairs, each taken from two substitutions.
; We say (v1 . term1) (the "pigeon") fits into (v2 . term2) (the "hole")
; if v1 is v2 and term1 occurs in term2.
(and (eq (car pigeon) (car hole))
(occur (cdr pigeon) (cdr hole))))
(alistfitp
; This predicate is applied to two substitutions. We say the pigeon
; alist fits into the hole alist if each pair of the pigeon fits into
; a pair of the hole and no pair of the hole is used more than once.
(pigeonholep pigeon hole nil 'pairfitp))
(testsandalistsfitp
; This predicate is applied to two testsandalists records. The
; first fits into the second if the tests of the first are a subset
; of those of the second and either they are both base cases (i.e., have
; no alists) or each substitution of the first fits into a substitution of
; the second, using no substitution of the second more than once.
(and (subsetpequal (access testsandalists pigeon :tests)
(access testsandalists hole :tests))
(or (and (null (access testsandalists pigeon :alists))
(null (access testsandalists hole :alists)))
(pigeonholep (access testsandalists pigeon :alists)
(access testsandalists hole :alists)
nil
'alistfitp))))))
(defun pigeonholep (pigeons holes filledholes fn)
; Both pigeons and holes are lists of arbitrary objects. The holes
; are implicitly enumerated lefttoright from 0. Filledholes is a
; list of the indices of holes we consider "filled." Fn is a
; predicate known to pigeonholepapply. If fn applied to a pigeon and
; a hole is nonnil, then we say the pigeon "fits" into the hole. We
; can only "put" a pigeon into a hole if the hole is unfilled and the
; pigeon fits. The act of putting the pigeon into the hole causes the
; hole to become filled. We return t iff it is possible to put each
; pigeon into a hole under these rules.
(cond
((null pigeons) t)
(t (pigeonholep1 (car pigeons)
(cdr pigeons)
holes 0
holes filledholes fn))))
(defun pigeonholep1 (pigeon pigeons lst n holes filledholes fn)
; Lst is a terminal sublist of holes, whose first element has index n.
; We map over lst looking for an unfilled hole h such that (a) we can
; put pigeon into h and (b) we can dispose of the rest of the pigeons
; after filling h.
(cond
((null lst) nil)
((member n filledholes)
(pigeonholep1 pigeon pigeons (cdr lst) (1+ n) holes filledholes fn))
((and (pigeonholepapply fn pigeon (car lst))
(pigeonholep pigeons holes
(cons n filledholes)
fn))
t)
(t (pigeonholep1 pigeon pigeons (cdr lst) (1+ n)
holes filledholes fn))))
)
(defun flushcand1downcand2 (cand1 cand2)
; This function takes two induction candidates and determines whether
; the first is subsumed by the second. If so, it constructs a new
; candidate that is logically equivalent (vis a vis the induction
; suggested) to the second but which now carries with it the weight
; and heuristic burdens of the first.
(cond
((and (subsetpeq (access candidate cand1 :changedvars)
(access candidate cand2 :changedvars))
(subsetpeq (access candidate cand1 :unchangeablevars)
(access candidate cand2 :unchangeablevars))
(pigeonholep (access candidate cand1 :testsandalistslst)
(access candidate cand2 :testsandalistslst)
nil
'testsandalistsfitp))
(change candidate cand2
:score (+ (access candidate cand1 :score)
(access candidate cand2 :score))
:controllers (unioneq (access candidate cand1 :controllers)
(access candidate cand2 :controllers))
:otherterms (addtosetequal
(access candidate cand1 :inductionterm)
(unionequal
(access candidate cand1 :otherterms)
(access candidate cand2 :otherterms)))
:xotherterms (addtosetequal
(access candidate cand1 :xinductionterm)
(unionequal
(access candidate cand1 :xotherterms)
(access candidate cand2 :xotherterms)))
:ttree (constagtrees (access candidate cand1 :ttree)
(access candidate cand2 :ttree))))
(t nil)))
(defun flushcandidates (cand1 cand2)
; This function determines whether one of the two induction candidates
; given flushes down the other and if so returns the appropriate
; new candidate. This function is a mate and merge function used
; by m&m and is hence known to m&mapply.
(or (flushcand1downcand2 cand1 cand2)
(flushcand1downcand2 cand2 cand1)))
; We now begin the development of the merging of two induction
; candidates. The basic idea is that if two functions both replace x
; by x', and one of them simultaneously replaces a by a' while the
; other replaces b by b', then we should consider inducting on x, a,
; and b, by x', a', and b'. Of course, by the time we get here, the
; recursion is coded into substitution alists: ((x . x') (a . a')) and
; ((x . x') (b . b')). We merge these two alists into ((x . x') (a .
; a') (b . b')). The merge of two sufficiently compatible alists is
; accomplished by just unioning them together.
; The key ideas are (1) recognizing when two alists are describing the
; "same" recursive step (i.e., they are both replacing x by x', where
; x is somehow a key variable); (2) observing that they do not
; explicitly disagree on what to do with the other variables.
(defun alistsagreep (alist1 alist2 vars)
; Two alists agree on vars iff for each var in vars the image of var under
; the first alist is equal to that under the second.
(cond ((null vars) t)
((equal (let ((temp (assoceq (car vars) alist1)))
(cond (temp (cdr temp))(t (car vars))))
(let ((temp (assoceq (car vars) alist2)))
(cond (temp (cdr temp))(t (car vars)))))
(alistsagreep alist1 alist2 (cdr vars)))
(t nil)))
(defun irreconcilablealistsp (alist1 alist2)
; Two alists are irreconcilable iff there is a var v that they both
; explicitly map to different values. Put another way, there exists a
; v such that (v . a) is a member of alist1 and (v . b) is a member of
; alist2, where a and b are different. If two substitutions are
; reconcilable then their union is a substitution.
; We rely on the fact that this function return t or nil.
(cond ((null alist1) nil)
(t (let ((temp (assoceq (caar alist1) alist2)))
(cond ((null temp)
(irreconcilablealistsp (cdr alist1) alist2))
((equal (cdar alist1) (cdr temp))
(irreconcilablealistsp (cdr alist1) alist2))
(t t))))))
(defun affinity (aff alist1 alist2 vars)
; We say two alists that agree on vars but are irreconcilable are
; "antagonists". Two alists that agree on vars and are not irreconcilable
; are "mates".
; Aff is either 'antagonists or 'mates and denotes one of the two relations
; above. We return t iff the other args are in the given relation.
(and (alistsagreep alist1 alist2 vars)
(eq (irreconcilablealistsp alist1 alist2)
(eq aff 'antagonists))))
(defun memberaffinity (aff alist alistlst vars)
; We determine if some member of alistlst has the given affinity with alist.
(cond ((null alistlst) nil)
((affinity aff alist (car alistlst) vars)
t)
(t (memberaffinity aff alist (cdr alistlst) vars))))
(defun occuraffinity (aff alist lst vars)
; Lst is a list of testsandalists. We determine whether alist has
; the given affinity with some alist in lst. We call this occur
; because we are looking inside the elements of lst. But it is
; technically a misnomer because we don't look inside recursively; we
; treat lst as though it were a list of lists.
(cond
((null lst) nil)
((memberaffinity aff alist
(access testsandalists (car lst) :alists)
vars)
t)
(t (occuraffinity aff alist (cdr lst) vars))))
(defun someoccuraffinity (aff alists lst vars)
; Lst is a list of testsandalists. We determine whether some alist
; in alists has the given affinity with some alist in lst.
(cond ((null alists) nil)
(t (or (occuraffinity aff (car alists) lst vars)
(someoccuraffinity aff (cdr alists) lst vars)))))
(defun alloccuraffinity (aff alists lst vars)
; Lst is a list of testsandalists. We determine whether every alist
; in alists has the given affinity with some alist in lst.
(cond ((null alists) t)
(t (and (occuraffinity aff (car alists) lst vars)
(alloccuraffinity aff (cdr alists) lst vars)))))
(defun containsaffinity (aff lst vars)
; We determine if two members of lst have the given affinity.
(cond ((null lst) nil)
((memberaffinity aff (car lst) (cdr lst) vars) t)
(t (containsaffinity aff (cdr lst) vars))))
; So much for generalpurpose scanners. We now develop the predicates
; that are used to determine if we can merge lst1 into lst2 on vars.
; See mergetestsandalistslsts for extensive comments on the ideas
; behind the following functions.
(defun antagonistictestsandalistslstp (lst vars)
; Lst is a list of testsandalists. Consider just the set of all
; alists in lst. We return t iff that set contains an antagonistic
; pair.
; We operate as follows. Each element of lst contains some alists.
; We take the first element and ask whether its alists contain an
; antagonistic pair. If so, we're done. Otherwise, we ask whether
; any alist in that first element is antagonistic with the alists in
; the rest of lst. If so, we're done. Otherwise, we recursively
; look at the rest of lst.
(cond
((null lst) nil)
(t (or (containsaffinity
'antagonists
(access testsandalists (car lst) :alists)
vars)
(someoccuraffinity
'antagonists
(access testsandalists (car lst) :alists)
(cdr lst)
vars)
(antagonistictestsandalistslstp (cdr lst) vars)))))
(defun antagonistictestsandalistslstsp (lst1 lst2 vars)
; Both lst1 and lst2 are lists of testsandalists. We determine whether
; there exists an alist1 in lst1 and an alist2 in lst2 such that alist1
; and alist2 are antagonists.
(cond
((null lst1) nil)
(t (or (someoccuraffinity
'antagonists
(access testsandalists (car lst1) :alists)
lst2
vars)
(antagonistictestsandalistslstsp (cdr lst1) lst2 vars)))))
(defun everyalist1matedp (lst1 lst2 vars)
; Both lst1 and lst2 are lists of testsandalists. We determine for every
; alist1 in lst1 there exists an alist2 in lst2 that agrees with alist1 on
; vars and that is not irreconcilable.
(cond ((null lst1) t)
(t (and (alloccuraffinity
'mates
(access testsandalists (car lst1) :alists)
lst2
vars)
(everyalist1matedp (cdr lst1) lst2 vars)))))
; The functions above are used to determine that lst1 and lst2 contain
; no antagonistic pairs, that every alist in lst1 has a mate somewhere in
; lst2, and that the process of merging alists from lst1 with their
; mates will not produce alists that are antagonistic with other alists
; in lst1. We now develop the code for merging nonantagonistic alists
; and work up the structural hierarchy to merging lists of tests and alists.
(defun mergealist1intoalist2 (alist1 alist2 vars)
; We assume alist1 and alist2 are not antagonists. Thus, either they
; agree on vars and have no explicit disagreements, or they simply
; don't agree on vars. If they agree on vars, we merge alist1 into
; alist2 by just unioning them together. If they don't agree on vars,
; then we merge alist1 into alist2 by ignoring alist1.
(cond
((alistsagreep alist1 alist2 vars)
(unionequal alist1 alist2))
(t alist2)))
; Now we begin working up the structural hierarchy. Our strategy is
; to focus on a given alist2 and hit it with every alist1 we have.
; Then we'll use that to copy lst2 once, hitting each alist2 in it
; with everything we have. We could decompose the problem the other
; way: hit lst2 with successive alist1's. That suffers from forcing
; us to copy lst2 repeatedly, and there are parts of that structure
; (i.e., the :tests) that don't change.
(defun mergealist1lstintoalist2 (alist1lst alist2 vars)
; Alist1lst is a list of alists and alist2 is an alist. We know that
; there is no antagonists between the elements of alist1lst and in
; alist2. We merge each alist1 into alist2 and return
; the resulting extension of alist2.
(cond
((null alist1lst) alist2)
(t (mergealist1lstintoalist2
(cdr alist1lst)
(mergealist1intoalist2 (car alist1lst) alist2 vars)
vars))))
(defun mergelst1intoalist2 (lst1 alist2 vars)
; Given a list of testsandalists, lst1, and an alist2, we hit alist2
; with every alist1 in lst1.
(cond ((null lst1) alist2)
(t (mergelst1intoalist2
(cdr lst1)
(mergealist1lstintoalist2
(access testsandalists (car lst1) :alists)
alist2
vars)
vars))))
; So now we write the code to copy lst2, hitting each alist in it with lst1.
(defun mergelst1intoalist2lst (lst1 alist2lst vars)
(cond ((null alist2lst) nil)
(t (cons (mergelst1intoalist2 lst1 (car alist2lst) vars)
(mergelst1intoalist2lst lst1 (cdr alist2lst) vars)))))
(defun mergelst1intolst2 (lst1 lst2 vars)
(cond ((null lst2) nil)
(t (cons (change testsandalists (car lst2)
:alists
(mergelst1intoalist2lst
lst1
(access testsandalists (car lst2) :alists)
vars))
(mergelst1intolst2 lst1 (cdr lst2) vars)))))
(defun mergetestsandalistslsts (lst1 lst2 vars)
; Lst1 and lst2 are each testsandalistslsts from some induction
; candidates. Intuitively, we try to stuff the alists of lst1 into
; those of lst2 to construct a new lst2 that combines the induction
; schemes of both. If we fail we return nil. Otherwise we return the
; modified lst2. The modified lst2 has exactly the same tests as
; before; only its alists are different and they are different only by
; virtue of having been extended with some addition pairs. So the
; justification of the merged induction is the same as the
; justification of the original lst2.
; Given an alist1 from lst1, which alist2's of lst2 do you extend and
; how? Suppose alist1 maps x to x' and y to y'. Then intuitively we
; think "the first candidate is trying to keep x and y in step, so
; that when x goes to x' y goes to y'." So, if you see an alist in
; lst2 that is replacing x by x', one might be tempted to augment it
; by replacing y by y'. However, what if x is just an accumulator?
; The role of vars is to specify upon which variables two
; substitutions must agree in order to be merged. Usually, vars
; consists of the measured variables.
; So now we get a little more technical. We will try to "merge" each
; alist1 from lst1 into each alist2 from lst2 (preserving the case structure
; of lst2). If alist1 and alist2 do not agree on vars then their merge
; is just alist2. If they do agree on vars, then their merge is their
; union, provided that is a substitution. It may fail to be a substitution
; because the two alists disagree on some other variable. In that case
; we say the two are irreconcilable. We now give three simple examples:
; Let vars be {x}. Let alist2 be {(x . x') (z . z')}. If alist1 maps
; x to x'', then their merge is just alist2 because alist1 is
; addressing a different case of the induction. If alist1 maps x to x'
; and y to y', then their merge is {(x . x') (y . y') (z . z')}. If
; alist1 maps x to x' and z to z'', then the two are irreconcilable.
; Two irreconcilable alists that agree on vars are called "antagonists"
; because they "want" to merge but can't. We cannot merge lst1 into lst2
; if they have an antagonistic pair between them. If an antagonistic pair
; is discovered, the entire merge operation fails.
; Now we will successively consider each alist1 in lst1 and merge it
; into lst2, forming successive lst2's. We insist that each alist1 of
; lst1 have at least one mate in lst2 with which it agrees and is
; reconcilable. (Otherwise, we could merge completely disjoint
; substitutions.)
; Because we try the alist1's successively, each alist1 is actually
; merged into the lst2 produced by all the previous alist1's. That
; produces an apparent order dependence. However, this is avoided by
; the requirement that we never produce antagonistic pairs.
; For example, suppose that in one case of lst1, x is mapped to x' and
; y is mapped to y', but in another case x is mapped to x' and y is
; mapped to y''. Now imagine trying to merge that lst1 into a lst2 in
; which x is mapped to x' and z is mapped to z'. The first alist of
; lst1 extends lst2 to (((x . x') (y . y') (z . z'))). But the second
; alist is then antagonistic. The same thing happens if we tried the two
; alists of lst1 in the other order. Thus, the above lst1 cannot be merged
; into lst2. Note that they can be merged in the other order! That is,
; lst2 can be merged into lst1, because the case structure of lst1 is
; richer.
; We can detect the situation above without forming the intermediate
; lst2. In particular, if lst1 contains an antagonistic pair, then it
; cannot be merged with any lst2 and we can quit.
; Note: Once upon a time, indeed, for the first 20 years or so of the
; existence of the merge routine, we took the attitude that if
; irreconcilable but agreeable alists arose, then we just added to
; alist2 those pairs of alist1 that were reconcilable and we left out
; the irreconcilable pairs. This however resulted in the system often
; merging complicated accumulator using functions (like TAUTOLOGYP)
; into simpler functions (like NORMALIZEDP) by dropping the
; accumulators that got in the way. This idea of just not doing
; "hostile merges" is being tried out for the first time in ACL2.
(cond ((antagonistictestsandalistslstp lst1 vars) nil)
((antagonistictestsandalistslstsp lst1 lst2 vars) nil)
((not (everyalist1matedp lst1 lst2 vars)) nil)
(t (mergelst1intolst2 lst1 lst2 vars))))
(defun mergecand1intocand2 (cand1 cand2)
; Can induction candidate cand1 be merged into cand2? If so, return
; their merge. The guts of this function is mergetestsandalists
; lsts. The tests preceding it are heuristic only. If
; mergetestsandalistslsts returns nonnil, then it returns a sound
; induction; indeed, it merely extends some of the substitutions in
; the second candidate.
(let ((vars (or (intersectioneq
(access candidate cand1 :controllers)
(intersectioneq
(access candidate cand2 :controllers)
(intersectioneq
(access candidate cand1 :changedvars)
(access candidate cand2 :changedvars))))
(intersectioneq
(access candidate cand1 :changedvars)
(access candidate cand2 :changedvars)))))
; Historical Plaque from Nqthm:
; We once merged only if both cands agreed on the intersection of the
; changedvars. But the theorem that, under suitable conditions, (EV
; FLG X VA FA N) = (EV FLG X VA FA K) made us realize it was important
; only to agree on the intersection of the controllers. Note in fact
; that we mean the changing controllers  there seems to be no need
; to merge two inductions if they only share unchanging controllers.
; However the theorem that (GET I (SET J VAL MEM)) = ... (GET I MEM)
; ... illustrates the situation in which the controllers, {I} and {J}
; do not even overlap; but the accumulators {MEM} do and we want a
; merge. So we want agreement on the intersection of the changing
; controllers (if that is nonempty) or on the accumulators.
; For soundness it does not matter what list of vars we want to agree
; on because no matter what, mergetestsandalistslsts returns
; either nil or an extension of the second candidate's alists.
(cond
((and vars
(not (intersectpeq (access candidate cand1 :unchangeablevars)
(access candidate cand2 :changedvars)))
(not (intersectpeq (access candidate cand2 :unchangeablevars)
(access candidate cand1 :changedvars))))
(let ((temp (mergetestsandalistslsts
(access candidate cand1 :testsandalistslst)
(access candidate cand2 :testsandalistslst)
vars)))
(cond (temp
(make candidate
:score (+ (access candidate cand1 :score)
(access candidate cand2 :score))
:controllers (unioneq
(access candidate cand1 :controllers)
(access candidate cand2 :controllers))
:changedvars (unioneq
(access candidate cand1 :changedvars)
(access candidate cand2 :changedvars))
:unchangeablevars (unioneq
(access candidate cand1
:unchangeablevars)
(access candidate cand2
:unchangeablevars))
:testsandalistslst temp
:justification (access candidate cand2 :justification)
:inductionterm (access candidate cand2 :inductionterm)
:otherterms (addtosetequal
(access candidate cand1 :inductionterm)
(unionequal
(access candidate cand1 :otherterms)
(access candidate cand2 :otherterms)))
:xinductionterm (access candidate cand2 :xinductionterm)
:xotherterms (addtosetequal
(access candidate cand1 :xinductionterm)
(unionequal
(access candidate cand1 :xotherterms)
(access candidate cand2 :xotherterms)))
:xancestry (cond
((equal temp
(access candidate cand2
:testsandalistslst))
(access candidate cand2 :xancestry))
(t (addtosetequal
(access candidate cand1 :xinductionterm)
(unionequal
(access candidate cand1 :xancestry)
(access candidate cand2 :xancestry)))))
; Note that :xancestry, computed just above, may not reflect cand1, but we
; always include the :ttree of cand1 just below. This is deliberate, since
; cand1 is contributing to the :score, and hence the eventual induction scheme
; chosen; so we want to report its induction rules in the final proof.
:ttree (constagtrees (access candidate cand1 :ttree)
(access candidate cand2 :ttree))))
(t nil))))
(t nil))))
(defun mergecandidates (cand1 cand2)
; This function determines whether one of the two induction candidates
; can be merged into the other. If so, it returns their merge. This
; function is a mate and merge function used by m&m and is hence known
; to m&mapply.
(or (mergecand1intocand2 cand1 cand2)
(mergecand1intocand2 cand2 cand1)))
; We now move from merging to flawing. The idea is to determine which
; inductions get in the way of others.
(defun controllervariables1 (args controllerpocket)
; Controllerpocket is a list of t's and nil's in 1:1 correspondence with
; args, indicating which args are controllers. We collect those controller
; args that are variable symbols.
(cond ((null controllerpocket) nil)
((and (car controllerpocket)
(variablep (car args)))
(addtoseteq (car args)
(controllervariables1 (cdr args)
(cdr controllerpocket))))
(t (controllervariables1 (cdr args)
(cdr controllerpocket)))))
(defun controllervariables (term controlleralist)
; Controlleralist comes from the defbody of the function symbol, fn, of term.
; Recall that controlleralist is an alist that associates with each function
; in fn's mutually recursive clique the controller pockets used in a given
; justification of the clique. In induction, as things stand today, we know
; that fn is singly recursive because we don't know how to handle mutual
; recursion yet. But no use is made of that here. We collect all the
; variables in controller slots of term.
(controllervariables1 (fargs term)
(cdr (assoceq (ffnsymb term)
controlleralist))))
(defun inductvars1 (lst wrld)
; Lst is a list of terms. We collect every variable symbol occuring in a
; controller slot of any term in lst.
(cond ((null lst) nil)
(t (unioneq
(controllervariables
(car lst)
(access defbody
(defbody (ffnsymb (car lst)) wrld)
:controlleralist))
(inductvars1 (cdr lst) wrld)))))
(defun inductvars (cand wrld)
; Historical Plaque from Nqthm:
; Get all skos occupying controller slots in any of the terms associated
; with this candidate.
; The age of that comment is not known, but the fact that we referred
; to the variables as "skos" (Skolem constants) suggests that it may
; date from the Interlisp version. Meta comment: Perhaps someday some
; enterprising PhD student (in History?) will invent Software
; Archeology, in which decrepit fragments of archive tapes are pieced
; together and scrutinized for clues as to the way people thought back
; in the early days.
(inductvars1 (cons (access candidate cand :inductionterm)
(access candidate cand :otherterms))
wrld))
(defun vetoedp (cand vars lst changedvarsflg)
; Vars is a list of variables. We return t iff there exists a candidate
; in lst, other than cand, whose unchangeablevars (or, if changedvarsflg,
; changedvars or unchangeablevars) intersect with vars.
; This function is used both by computevetoes1, where flg is t and
; vars is the list of changing induction vars of cand, and by
; computevetoes2, where flg is nil and vars is the list of
; changedvars cand. We combine these two into one function simply to
; eliminate a definition from the system.
(cond ((null lst) nil)
((equal cand (car lst))
(vetoedp cand vars (cdr lst) changedvarsflg))
((and changedvarsflg
(intersectpeq vars
(access candidate (car lst) :changedvars)))
t)
((intersectpeq vars
(access candidate (car lst) :unchangeablevars))
t)
(t (vetoedp cand vars (cdr lst) changedvarsflg))))
(defun computevetoes1 (lst candlst wrld)
; Lst is a tail of candlst. We throw out from lst any candidate
; whose changing inductvars intersect the changing or unchanging vars
; of another candidate in candlst. We assume no two elements of
; candlst are equal, an invariant assured by the fact that we have
; done merging and flushing before this.
(cond ((null lst) nil)
((vetoedp (car lst)
(intersectioneq
(access candidate (car lst) :changedvars)
(inductvars (car lst) wrld))
candlst
t)
(computevetoes1 (cdr lst) candlst wrld))
(t (cons (car lst)
(computevetoes1 (cdr lst) candlst wrld)))))
; If the first veto computation throws out all candidates, we revert to
; another heuristic.
(defun computevetoes2 (lst candlst)
; Lst is a tail of candlst. We throw out from lst any candidate
; whose changedvars intersect the unchangeablevars of another
; candidate in candlst. Again, we assume no two elements of candlst
; are equal.
(cond ((null lst) nil)
((vetoedp (car lst)
(access candidate (car lst) :changedvars)
candlst
nil)
(computevetoes2 (cdr lst) candlst))
(t (cons (car lst)
(computevetoes2 (cdr lst) candlst)))))
(defun computevetoes (candlst wrld)
; We try two different techniques for throwing out candidates. If the
; first throws out everything, we try the second. If the second throws
; out everything, we throw out nothing.
; The two are: (1) throw out a candidate if its changing inductvars
; (the variables in control slots that change) intersect with either
; the changedvars or the unchangeablevars of another candidate. (2)
; throw out a candidate if its changedvars intersect the
; unchangeablevars of another candidate.
; Historical Plaque from Nqthm:
; This function weeds out "unclean" induction candidates. The
; intuition behind the notion "clean" is that an induction is clean
; if nobody is competing with it for instantiation of its variables.
; What we actually do is throw out any candidate whose changing
; induction variables  that is the induction variables as computed
; by inductvars intersected with the changed vars of candidate 
; intersect the changed or unchanged variables of another candidate.
; The reason we do not care about the first candidates unchanging
; vars is as follows. The reason you want a candidate clean is so
; that the terms riding on that cand will reoccur in both the
; hypothesis and conclusion of an induction. There are two ways to
; assure (or at least make likely) this: change the variables in the
; terms as specified or leave them constant. Thus, if the first
; cand's changing vars are clean but its unchanging vars intersect
; another cand it means that the first cand is keeping those other
; terms constant, which is fine. (Note that the first cand would be
; clean here. The second might be clean or dirty depending on
; whether its changed vars or unchanged vars intersected the first
; cand's vars.) The reason we check only the induction vars and not
; all of the changed vars is if cand1's changed vars include some
; induction vars and some accumulators and the accumulators are
; claimed by another cand2 we believe that cand1 is still clean.
; The motivating example was
; (IMPLIES (MEMBER A C) (MEMBER A (UNION1 B C)))
; where the induction on C is dirty because the induction on B and C
; claims C, but the induction on B and C is clean because the B does
; not occur in the C induction. We do not even bother to check the
; C from the (B C) induction because since it is necessarily an
; accumulator it is probably being constructed and thus, if it
; occurs in somebody else's ind vars it is probably being eaten so
; it will be ok. In formulating this heuristic we did not consider
; the possibility that the accums of one candidate occur as
; constants in the other. Oh well.
; July 20, 1978. We have added an additional heuristic, to be
; applied if the above one eliminates all cands. We consider a cand
; flawed if it changes anyone else's constants. The motivating
; example was GREATESTFACTORLESSP  which was previously proved
; only by virtue of a very ugly use of the noop fn ID to make a
; certain induction flawed.
(or (computevetoes1 candlst candlst wrld)
(computevetoes2 candlst candlst)
candlst))
; The next heuristic is to select complicated candidates, based on
; support for nonprimitive recursive function schemas.
(defun inductioncomplexity1 (lst wrld)
; The "function" inductioncomplexity does not exist. It is a symbol
; passed to maximalelementsapply which calls this function on the list
; of terms supported by an induction candidate. We count the number of
; non pr fns supported.
(cond ((null lst) 0)
((getprop (ffnsymb (car lst)) 'primitiverecursivedefunp nil
'currentacl2world wrld)
(inductioncomplexity1 (cdr lst) wrld))
(t (1+ (inductioncomplexity1 (cdr lst) wrld)))))
; We develop a generalpurpose function for selecting maximal elements from
; a list under a measure. That function, maximalelements, is then used
; with the inductioncomplexity measure to collect both the most complex
; inductions and then to select those with the highest scores.
(defun maximalelementsapply (fn x wrld)
; This function must produce an integerp. This is just the apply function
; for maximalelements.
(case fn
(inductioncomplexity
(inductioncomplexity1 (cons (access candidate x :inductionterm)
(access candidate x :otherterms))
wrld))
(score (access candidate x :score))
(otherwise 0)))
(defun maximalelements1 (lst winners maximum fn wrld)
; We are scanning down lst collecting into winners all those elements
; with maximal scores as computed by fn. Maximum is the maximal score seen
; so far and winners is the list of all the elements passed so far with
; that score.
(cond ((null lst) winners)
(t (let ((temp (maximalelementsapply fn (car lst) wrld)))
(cond ((> temp maximum)
(maximalelements1 (cdr lst)
(list (car lst))
temp fn wrld))
; PETE
; In other versions the = below is, mistakenly, an int=!
((= temp maximum)
(maximalelements1 (cdr lst)
(cons (car lst) winners)
maximum fn wrld))
(t
(maximalelements1 (cdr lst)
winners
maximum fn wrld)))))))
(defun maximalelements (lst fn wrld)
; Return the subset of lst that have the highest score as computed by
; fn. The functional parameter fn must be known to maximalelementsapply.
; We reverse the accumulated elements to preserve the order used by
; nqthm.
(cond ((null lst) nil)
((null (cdr lst)) lst)
(t (reverse
(maximalelements1 (cdr lst)
(list (car lst))
(maximalelementsapply fn (car lst) wrld)
fn wrld)))))
; All that is left in the heuristic selection of the induction candidate is
; the function m&m that mates and merges arbitrary objects. We develop that
; now.
; The following three functions are not part of induction but are
; used by other callers of m&m and so have to be introduced now
; so we can define m&mapply and get on with induct.
(defun intersectpeq/unionequal (x y)
(cond ((intersectpeq (car x) (car y))
(cons (unioneq (car x) (car y))
(unionequal (cdr x) (cdr y))))
(t nil)))
(defun equal/unionequal (x y)
(cond ((equal (car x) (car y))
(cons (car x)
(unionequal (cdr x) (cdr y))))
(t nil)))
(defun subsetpequal/smaller (x y)
(cond ((subsetpequal x y) x)
((subsetpequal y x) y)
(t nil)))
(defun m&mapply (fn x y)
; This is a firstorder function that really just applies fn to x and
; y, but does so only for a fixed set of fns. In fact, this function
; handles exactly those functions that we give to m&m.
(case fn
(intersectpeq/unionequal (intersectpeq/unionequal x y))
(equal/unionequal (equal/unionequal x y))
(flushcandidates (flushcandidates x y))
(mergecandidates (mergecandidates x y))
(subsetpequal/smaller (subsetpequal/smaller x y))))
(defun countoff (n lst)
; Pair the elements of lst with successive integers starting at n.
(cond ((null lst) nil)
(t (cons (cons n (car lst))
(countoff (1+ n) (cdr lst))))))
(defun m&msearch (x ylst del fn)
; Ylst is a list of pairs, (id . y). The ids are integers. If id is
; a member of del, we think of y as "deleted" from ylst. That is,
; ylst and del together characterize a list of precisely those y such
; that (id . y) is in ylst and id is not in del.
; We search ylst for the first y that is not deleted and that mates
; with x. We return two values, the merge of x and y and the integer
; id of y. If no such y exists, return two nils.
(cond ((null ylst) (mv nil nil))
((member (caar ylst) del)
(m&msearch x (cdr ylst) del fn))
(t (let ((z (m&mapply fn x (cdar ylst))))
(cond (z (mv z (caar ylst)))
(t (m&msearch x (cdr ylst) del fn)))))))
(defun m&m1 (pairs del ans n fn)
; This is workhorse for m&m. See that fn for a general description of
; the problem and the terminology. Pairs is a list of pairs. The car
; of each pair is an integer and the cdr is a possible element of the
; bag we are closing under fn. Del is a list of the integers
; identifying all the elements of pairs that have already been
; deleted. Abstractly, pairs and del together represent a bag we call
; the "unprocessed bag". The elements of the unprocessed bag are
; precisely those ele such that (i . ele) is in pairs and i is not in
; del.
; Without assuming any properties of fn, this function can be
; specified as follows: If the first element, x, of the unprocessed
; bag, mates with some y in the rest of the uprocessed bag, then put
; the merge of x and the first such y in place of x, delete that y,
; and iterate. If the first element has no such mate, put it in the
; answer accumulator ans. N, by the way, is the next available unique
; identifier integer.
; If one is willing to make the assumptions that the mate and merge
; fns of fn are associative and commutative and have the distributive
; and nonpreclusion properties, then it is possible to say more about
; this function. The rest of this comment makes those assumptions.
; Ans is a bag with the property that no element of ans mates with any
; other element of ans or with any element of the unprocessed bag. N
; is the next available unique identifier integer; it is always larger
; than any such integer in pairs or in del.
; Abstractly, this function closes B under fn, where B is the bag
; union of the unprocessed bag and ans.
(cond
((null pairs) ans)
((member (caar pairs) del)
(m&m1 (cdr pairs) del ans n fn))
(t (mvlet (mrg yid)
(m&msearch (cdar pairs) (cdr pairs) del fn)
(cond
((null mrg)
(m&m1 (cdr pairs)
del
(cons (cdar pairs) ans)
n fn))
(t (m&m1 (cons (cons n mrg) (cdr pairs))
(cons yid del)
ans
(1+ n)
fn)))))))
(defun m&m (bag fn)
; This function takes a bag and a symbol naming a dyadic function, fn,
; known to m&mapply and about which we assume certain properties
; described below. Let z be (m&mapply fn x y). Then we say x and y
; "mate" if z is nonnil. If x and y mate, we say z is the "merge" of
; x and y. The name of this function abbreviates the phrase "mate and
; merge".
; We consider each element, x, of bag in turn and seek the first
; successive element, y, that mates with it. If we find one, we throw
; out both, add their merge in place of x and iterate. If we find no
; mate for x, we deposit it in our answer accumulator.
; The specification above is explicit about the order in which we try
; the elements of the bag. If we try to loosen the specification so
; that order is unimportant, we must require that fn have certain
; properties. We discuss this below.
; First, note that we have implicitly assumed that mate and merge are
; commutative because we haven't said in which order we present the
; arguments.
; Second, note that if x doesn't mate with any y, we set it aside in
; our accumulating answer. We do not even try to mate such an x with
; the offspring of the y's it didn't like. This makes us order
; dependent. For example, consider the bag {x y1 y2}. Suppose x
; won't mate with either y1 or y2, but that y1 mates with y2 to
; produce y3 and x mates with y3 to produce y4. Then if we seek mates
; for x first we find none and it gets into our final answer. Then y1
; and y2 mate to form y3. The final answer is hence {x y3}. But if
; we seek mates for y1 first we find y2, produce y3, add it to the
; bag, forming {y3 x}, and then mate x with y3 to get the final answer
; {y4}. This order dependency cannot arise if fn has the property
; that if x mates with the merge of y and z then x mates with either y
; or z. This is called the "distributive" property of mate over merge.
; Third, note that if x does mate with y to produce z then we throw x
; out in favor of z. Thus, x is not mated against any but the first
; y. Thus, if we have {x y1 y2} and x mates with y1 to form z1 and x
; mates with y2 to form z2 and there are no other mates, then we can
; either get {z1 y2} or {z2 y1} as the final bag, depending on whether
; we mate x with y1 or y2. This order dependency cannot arise if fn
; has the property that if x mates with y1 and x mates with y2, then
; (a) the merge of x and y1 mates with y2, and (b) merge has the
; "commutativity2" (merge (merge x y1) y2) = (merge (merge x y2) y1).
; We call property (a) "nonpreclusion" property of mate and merge,
; i.e., merging doesn't preclude mating.
; The commutativity2 property is implied by associativity and (the
; already assumed commutativity). Thus, another way to avoid the
; third order dependency is if legal merges are associative and have
; the nonpreclusion property.
; Important Note: The commonly used fn of unioning together two alists
; that agree on the intersection of their domains, does not have the
; nonpreclusion property! Suppose x, y1, and y2 are all alists and
; all map A to 0. Suppose in addition y1 maps B to 1 but y2 maps B to
; 2. Finally, suppose x maps C to 3. Then x mates with both y1 and
; y2. But merging y1 into x precludes mating with y2 and vice versa.
; We claim, but do not prove, that if the mate and merge functions for
; fn are commutative and associative, and have the distributive and
; nonpreclusion properties, then m&m is order independent.
; For efficiency we have chosen to implement deletion by keeping a
; list of the deleted elements. But we cannot make a list of the
; deleted elements themselves because there may be duplicate elements
; in the bag and we need to be able to delete occurrences. Thus, the
; workhorse function actually operates on a list of pairs, (i . ele),
; where i is a unique identification integer and ele is an element of
; the bag. In fact we just assign the position of each occurrence to
; each element of the initial bag and thereafter count up as we
; generate new elements.
;
; See m&m1 for the details.
(m&m1 (countoff 0 bag) nil nil (length bag) fn))
; We now develop a much more powerful concept, that of mapping m&m over the
; powerset of a set. This is how we actually merge induction candidates.
; That is, we try to mash together every possible subset of the candidates,
; largest subsets first. See m&moverpowerset for some implementation
; commentary before going on.
(defun conssubsettree (x y)
; We are representing full binary trees of t's and nil's and
; collapsing trees of all nil's to nil and trees of all t's to t. See
; the long comment in m&moverpowerset. We avoid consing when
; convenient.
(if (eq x t)
(if (eq y t)
t
(if y (cons x y) '(t)))
(if x
(cons x y)
(if (eq y t)
'(nil . t)
(if y (cons x y) nil)))))
(defabbrev carsubsettree (x)
; See conssubsettree.
(if (eq x t) t (car x)))
(defabbrev cdrsubsettree (x)
; See conssubsettree.
(if (eq x t) t (cdr x)))
(defun orsubsettrees (tree1 tree2)
; We disjoin the tips of two binary t/nil trees. See conssubsettree.
(cond ((or (eq tree1 t)(eq tree2 t)) t)
((null tree1) tree2)
((null tree2) tree1)
(t (conssubsettree (orsubsettrees (carsubsettree tree1)
(carsubsettree tree2))
(orsubsettrees (cdrsubsettree tree1)
(cdrsubsettree tree2))))))
(defun m&moverpowerset1 (st subset stree ans fn)
; See m&moverpowerset.
(cond
((eq stree t) (mv t ans))
((null st)
(let ((z (m&m subset fn)))
(cond ((and z (null (cdr z)))
(mv t (cons (car z) ans)))
(t (mv nil ans)))))
(t
(mvlet (stree1 ans1)
(m&moverpowerset1 (cdr st)
(cons (car st) subset)
(cdrsubsettree stree)
ans fn)
(mvlet (stree2 ans2)
(m&moverpowerset1 (cdr st)
subset
(orsubsettrees
(carsubsettree stree)
stree1)
ans1 fn)
(mv (conssubsettree stree2 stree1) ans2))))))
(defun m&moverpowerset (st fn)
; Fn is a function known to m&mapply. Let (fn* s) be defined to be z,
; if (m&m s fn) = {z} and nil otherwise. Informally, (fn* s) is the
; result of somehow mating and merging all the elements of s into a single
; object, or nil if you can't.
; This function applies fn* to the powerset of st and collects all those
; nonnil values produced from maximal s's. I.e., we keep (fn* s) iff it
; is nonnil and no superset of s produces a nonnil value.
; We do this amazing feat (recall that the powerset of a set of n
; things contains 2**n subsets) by generating the powerset in order
; from largest to smallest subsets and don't generate or test any
; subset under a nonnil fn*. Nevertheless, if the size of set is
; very big, this function will get you.
; An informal specification of this function is that it is like m&m
; except that we permit an element to be merged into more than one
; other element (but an element can be used at most once per final
; element) and we try to maximize the amount of merging we can do.
; For example, if x mates with y1 to form z1, and x mates with y2 to
; form z2, and no other mates occur, then this function would
; transform {x y1 y2} into {z1 z2}. It searches by generate and test:
; s (fn* s)
; (x y1 y2) nil
; (x y1) z1
; (x y2) z2
; (x) subsumed
; (y1 y2) nil
; (y1) subsumed
; (y2) subsumed
; nil subsumed
; Here, s1 is "subsumed" by s2 means s1 is a subset of s2. (Just the
; opposite technical definition but exactly the same meaning as in the
; clausal sense.)
; The way we generate the powerset elements is suggested by the
; following trivial von Neumann function, ps, which, when called as in
; (ps set nil), calls PROCESS on each member of the powerset of set,
; in the order in which we generate them:
; (defun ps (set subset)
; (cond ((null set) (PROCESS subset))
; (t (ps (cdr set) (cons (car set) subset)) ;rhs
; (ps (cdr set) subset)))) ;lhs
; By generating larger subsets first we know that if a subset subsumes
; the set we are considering then that subset has already been
; considered. Therefore, we need a way to keep track of the subsets
; with nonnil values. We do this with a "subset tree". Let U be the
; universe of objects in some order. Then the full binary tree with
; depth U can be thought of as the powerset of U. In particular,
; any branch through the tree, from topmost node to tip, represents a
; subset of U by labelling the nodes at successive depth by the
; successive elements of U (the topmost node being labelled with the
; first element of U) and adopting the convention that taking a
; righthand (cdr) branch at a node indicates that the label is in the
; subset and a lefthand (car) branch indicates that the label is not
; in the subset. At the tip of the tree we store a T indicating that
; the subset had a nonnil value or a NIL indicating that it had a nil
; value.
; For storage efficiency we let nil represent an arbitrarily deep full
; binary tree will nil at every tip and we let t represent the
; analogous trees with t at every tip. Carsubsettree,
; cdrsubsettree and conssubsettree implement these abstractions.
; Of course, we don't have the tree when we start and we generate it
; as we go. That is a really weird idea because generating the tree
; that tells us who was a subset of whom in the past seems to have little
; use as we move forward. But that is not true.
; Observe that there is a correspondence between these trees and the
; function ps above for generating the power set. The recursion
; labelled "rhs" above is going down the righthand side of the tree
; and the "lhs" recursion is going down the lefthand side. Note that
; we go down the rhs first.
; The neat fact about these trees is that there is a close
; relationship between the righthand subtree (rhs) and lefthand
; subtree (lhs) of any given node of the tree: lhs can be obtained
; from rhs by turning some nils into ts. The reason is that the tips
; of the lhs of a node labelled by x denote exactly the same subsets
; as the corresponding tips of the righthand side, except that on the
; right x was present in the subset and on the left it is not. So
; when we do the right hand side we come back with a tree and if we
; used that very tree for the left hand side (interpreting nil as
; meaning "compute it and see" and t as meaning "a superset of this
; set has nonnil value") then it is correct. But we can do a little
; better than that because we might have come into this node with a
; tree (i.e., one to go into the right hand side with and another to go
; into the left hand side with) and so after we have gone into the
; right and come back with its new tree, we can disjoin the output of
; the right side with the input for the left side to form the tree we
; will actually use to explore the left side.
(mvlet (stree ans)
(m&moverpowerset1 st nil nil nil fn)
(declare (ignore stree))
ans))
; Ok, so now we have finished the selection process and we begin the
; construction of the induction formula itself.
(defun allpicks2 (pocket pick ans)
; See allpicks.
(cond ((null pocket) ans)
(t (cons (cons (car pocket) pick)
(allpicks2 (cdr pocket) pick ans)))))
(defun allpicks2r (pocket pick ans)
; See allpicks.
(cond ((null pocket) ans)
(t (allpicks2r (cdr pocket) pick
(cons (cons (car pocket) pick) ans)))))
(defun allpicks1 (pocket picks ans rflg)
; See allpicks.
(cond ((null picks) ans)
(t (allpicks1 pocket (cdr picks)
(if rflg
(allpicks2r pocket (car picks) ans)
(allpicks2 pocket (car picks) ans))
rflg))))
(defun allpicks (pockets rflg)
; Pockets is a list of pockets, each pocket containing 0 or more
; objects. We return a list of all the possible ways you can pick one
; thing from each pocket. If rflg is nil initially, then the order of
; the resulting list is exactly the same as it was in nqthm. There is
; not much else to recommend this particular choice of definition!
; Historical Plaque from Nqthm:
; (DEFUN ALLPICKS (POCKETLIST)
; (COND ((NULL POCKETLIST) (LIST NIL))
; (T (ITERATE FOR PICK IN (ALLPICKS (CDR POCKETLIST))
; NCONC (ITERATE FOR CHOICE IN (CAR POCKETLIST)
; COLLECT (CONS CHOICE PICK))))))
; Nqthm's construction is a very natural recursive one, except that it
; used nconc to join together the various segments of the answer. If
; we tried the analogous construction here we would have to append the
; segments together and copy a very long list. So we do it via an
; accumulator. The trouble however is that we reverse the order of
; the little buckets in our answer every time we process a pocket. We
; could avoid that if we wanted to recurse down the length of our
; answer on recursive calls, but we were afraid of running out of
; stack, and so we have coded this with tail recursion only. We do
; nontail recursion only over short things like individual pockets or
; the list of pockets. And so to (a) avoid unnecessary copying, (b)
; nontail recursion, and (c) constructing our answer in a different
; order, we introduced rflg. Rflg causes us either to reverse or not
; reverse a certain intermediate result every other recursion. It
; would be reassuring to see a mechanically checked proof that this
; definition of allpicks is equivalent to nqthm's.
(cond ((null pockets) '(nil))
(t (allpicks1 (car pockets)
(allpicks (cdr pockets) (not rflg))
nil
rflg))))
(defun dumbnegatelitlstlst (clset)
; We apply dumbnegatelitlst to every list in clset and collect the
; result. You can think of this as negating a clause set (i.e., an
; implicit conjunction of disjunctions), but you have to then imagine
; that the implicit "and" at the top has been turned into an "or" and
; vice versa at the lower level.
(cond ((null clset) nil)
(t (cons (dumbnegatelitlst (car clset))
(dumbnegatelitlstlst (cdr clset))))))
(defun inductionhypclausesegments2 (alists cl ans)
; See inductionhypclausesegments1.
(cond ((null alists) ans)
(t (cons (sublisvarlst (car alists) cl)
(inductionhypclausesegments2 (cdr alists) cl ans)))))
(defun inductionhypclausesegments1 (alists clset ans)
; This function applies all of the substitutions in alists to all of
; the clauses in clset and appends the result to ans to create one
; list of instantiated clauses.
(cond ((null clset) ans)
(t (inductionhypclausesegments2
alists
(car clset)
(inductionhypclausesegments1 alists (cdr clset) ans)))))
(defun inductionhypclausesegments (alists clset)
; Clset is a set of clauses. We are trying to prove the conjunction
; over that set, i.e., cl1 & cl2 ... & clk, by induction. We are in a
; case in which we can assume every instance under alists of that
; conjunction. Thus, we can assume any lit from cl1, any lit from
; cl2, etc., instantiated via all of the alists. We wish to return a
; list of clause segments. Each segment will be spliced into the a
; clause we are trying to prove and together the resulting set of
; clauses is supposed to be equivalent to assuming all instances of
; the conjunction over clset.
; So one way to create the answer would be to first instantiate each
; of the k clauses with each of the n alists, getting a set of n*k
; clauses. Then we could run allpicks over that, selecting one
; literal from each of the instantiated clauses to assume. Then we'd
; negate each literal within each pick to create a clause hypothesis
; segment. That is nearly what we do, except that we do the negation
; first so as to share structure among the allpicks answers.
; Note: The code below calls (dumbnegatelit lit) on each lit. Nqthm
; used (negatelit lit nil ...) on each lit, employing
; negatelitlstlst, which has since been deleted but was strictly
; analogous to the dumb version called below. But since the
; typealist is nil in Nqthm's call, it seems unlikely that the
; literal will be decided by typeset. We changed to dumbnegatelit
; to avoid having to deal both with ttrees and the enabled structure
; implicit in typeset.
(allpicks
(inductionhypclausesegments1 alists
(dumbnegatelitlstlst clset)
nil)
nil))
(defun inductionformula3 (negtests hypsegments cl ans)
; Negtests is the list of the negated tests of an induction
; testsandalists entry. hypsegments is a list of hypothesis clause
; segments (i.e., more negated tests), and cl is a clause. For each
; hyp segment we create the clause obtained by disjoining the tests,
; the segment, and cl. We conjoin the resulting clauses to ans.
; See inductionformula for a comment about this iteration.
(cond
((null hypsegments) ans)
(t (inductionformula3 negtests
(cdr hypsegments)
cl
(conjoinclausetoclauseset
; Historical Plaque from Nqthm:
; We once implemented the idea of "homographication" in which we combined
; both induction, opening up of the recursive fns in the conclusion, and
; generalizing away some recursive calls. This function did the expansion
; and generalization. If the idea is reconsidered the following theorems are
; worthy of consideration:
; (ORDERED (SORT X)),
; (IMPLIES (ORDERED X)
; (ORDERED (ADDTOLIST I X))),
; (IMPLIES (AND (NUMBERLISTP X)
; (ORDERED X)
; (NUMBERP I)
; (NOT (< (CAR X) I)))
; (EQUAL (ADDTOLIST I X) (CONS I X))), and
; (IMPLIES (AND (NUMBERLISTP X) (ORDERED X)) (EQUAL (SORT X) X)).
; Observe that we simply disjoin the negated tests, hyp segments, and clause.
; Homographication further manipulated the clause before adding it to the
; answer.
(disjoinclauses
negtests
(disjoinclauses (car hypsegments) cl))
ans)))))
(defun inductionformula2 (cl clset talst ans)
; Cl is a clause in clset, which is a set of clauses we are proving
; by induction. Talst is the testsandalistslst component of the
; induction candidate we are applying to prove clset. We are now
; focussed on the proof of cl, using the induction schema of talst
; but getting to assume all the clauses in clset in our induction
; hypothesis. We will map across talst, getting a set of tests and
; some alists at each stop, and for each stop add a bunch of clauses
; to ans.
(cond
((null talst) ans)
(t (inductionformula2 cl clset (cdr talst)
(inductionformula3
; Note: Nqthm used (negatelitlst ... nil ...), but since the
; typealist supplied was nil, we decided it was probably no buying us
; much  not as much as passing up the ttrees would cost in terms of
; coding work!
(dumbnegatelitlst
(access testsandalists (car talst) :tests))
(inductionhypclausesegments
(access testsandalists (car talst) :alists)
clset)
cl
ans)))))
(defun inductionformula1 (lst clset talst ans)
; Lst is a tail of clset. Clset is a set of clauses we are trying to prove.
; Talst is the testsandalistslst component of the induction candidate
; we wish to apply to clset. We map down lst forming a set of clauses
; for each cl in lst. Basically, the set we form for cl is of the form
; ... > cl, where ... involves all the case analysis under the tests in
; talst and all the induction hypotheses from clset under the alists in
; each testandalists. We add our clauses to ans.
(cond
((null lst) ans)
(t (inductionformula1 (cdr lst) clset talst
(inductionformula2 (car lst)
clset talst ans)))))
(defun inductionformula (clset talst)
; Clset is a set of clauses we are to try to prove by induction, applying
; the inductive scheme described by the testsandalistslst, talst,
; of some induction candidate. The following historical plaque tells all.
; Historical Plaque from Nqthm:
; TESTSANDALISTSLST is a such a list that the disjunction of the
; conjunctions of the TESTS components of the members is T. Furthermore,
; there exists a measure M, a wellfounded relation R, and a sequence of
; variables x1, ..., xn such that for each T&Ai in TESTSANDALISTSLST, for
; each alist alst in the ALISTS component of T&Ai, the conjunction of the
; TESTS component, say qi, implies that (R (M x1 ... xn)/alst (M x1 ... xn)).
; To prove thm, the conjunction of the disjunctions of the members of CLSET,
; it is sufficient, by the principle of induction, to prove instead the
; conjunction of the terms qi & thm' & thm'' ... > thm, where the primed
; terms are the results of substituting the alists in the ALISTS field of the
; ith member of TESTSANDALISTSLST into thm.
; If thm1, thm2, ..., thmn are the disjunctions of the members of CLSET,
; then it is sufficient to prove all of the formulas qi & thm' & thm'' ...
; > thmj. This is a trivial proposition fact, to prove (IMPLIES A (AND B
; C)) it is sufficient to prove (IMPLIES A B) and (IMPLIES A C).
; The (ITERATE FOR PICK ...)* expression below returns a list of
; clauses whose conjunction propositionally implies qi & thm' &
; thm'' ... > thmj, where TA is the ith member of
; TESTSANDALISTSLST and CL is the jth member of CLSET. Proof:
; Let THM have the form:
;
; (AND (OR a1 ...)
; (OR b1 ...)
; ...
; (OR z1 ...)).
; Then qi & thm' & thm'' ... > thmj has the form:
; (IMPLIES (AND qi
; (AND (OR a1 ... )
; (OR b1 ... )
; ...
; (OR z1 ... ))'
; (AND (OR a1 ... )
; (OR b1 ... )
; ...
; (OR z1 ... ))''
; ...
; (AND (OR a1 ... )
; (OR b1 ... )
; ...
; (OR z1 ... )))'''...'
; thmj).
;
; Suppose this formula is false for some values of the free variables. Then
; under those values, each disjunction in the hypothesis is true. Thus there
; exists a way of choosing one literal from each of the disjunctions, all of
; which are true. This choice is one of the PICKs below. But we prove that
; (IMPLIES (AND qi PICK) thmj).
; Note: The (ITERATE FOR PICK ...) expression mentioned above is the function
; inductionformula3 above.
(m&m (reverse (inductionformula1 clset clset talst nil))
'subsetpequal/smaller))
; Because the preceding computation is potentially explosive we will
; sometimes reduce its complexity by shrinking the given clause set to
; a singleton set containing a unit clause. To decide whether to do that
; we will use the following rough measures:
(defun allpickssize (clset)
; This returns the size of the allpicks computed by inductionformula3.
(cond ((null clset) 1)
(t (* (length (car clset)) (allpickssize (cdr clset))))))
(defun inductionformulasize1 (hypssize conclsize talst)
; We determine roughly the number of clauses that talst will generate when
; the number of allpicks through the hypotheses is hypssize and the
; number of conclusion clauses is conclsize. The individual cases of
; the testsandalists combine additively. But we must pick our way through
; the hyps for each instantiation.
(cond ((null talst) 0)
(t
(+ (* conclsize (expt hypssize
(length (access testsandalists
(car talst)
:alists))))
(inductionformulasize1 hypssize conclsize (cdr talst))))))
(defun inductionformulasize (clset talst)
; This function returns a rough upper bound on the number of clauses
; that will be generated by inductionformula on the given arguments.
; See the comment in that function.
(inductionformulasize1 (allpickssize clset)
(length clset)
talst))
; The following constant determines the limit on the estimated number of
; clauses induct, below, will return. When normal processing would exceed
; this number, we try to cut down the combinatorics by collapsing clauses
; back into terms.
(defconst *maximuminductsize* 100)
; And here is how we convert a hairy set of clauses into a term when we
; have to.
(defun termifyclauseset (clauses)
; This function is similar to termifyclause except that it converts a
; set of clauses into an equivalent term. The set of clauses is
; understood to be implicitly conjoined and we therefore produce a
; conjunction expressed as (if cl1 cl2 nil).
(cond ((null clauses) *t*)
((null (cdr clauses)) (disjoin (car clauses)))
(t (mconsterm* 'if
(disjoin (car clauses))
(termifyclauseset (cdr clauses))
*nil*))))
; Once we have created the set of clauses to prove, we inform the
; simplifier of what to look out for during the early processing.
(defun informsimplify3 (alist terms ans)
; Instantiate every term in terms with alist and add them to ans.
(cond ((null terms) ans)
(t (informsimplify3 alist (cdr terms)
(addtosetequal (sublisvar alist (car terms))
ans)))))
(defun informsimplify2 (alists terms ans)
; Using every alist in alists, instantiate every term in terms and add
; them all to ans.
(cond ((null alists) ans)
(t (informsimplify2 (cdr alists) terms
(informsimplify3 (car alists) terms ans)))))
(defun informsimplify1 (talst terms ans)
; Using every alist mentioned in any testsandalists record of talst
; we instantiate every term in terms and add them all to ans.
(cond ((null talst) ans)
(t (informsimplify1 (cdr talst) terms
(informsimplify2 (access testsandalists
(car talst)
:alists)
terms
ans)))))
(defun informsimplify (talst terms pspv)
; Historical Plaque from Nqthm:
; Two of the variables effecting REWRITE are TERMSTOBEIGNOREDBYREWRITE
; and EXPANDLST. When any term on the former is encountered REWRITE returns
; it without rewriting it. Terms on the latter must be calls of defined fns
; and when encountered are replaced by the rewritten body.
; We believe that the theorem prover will perform significantly faster on
; many theorems if, after an induction, it does not waste time (a) trying to
; simplify the recursive calls introduced in the induction hypotheses and (b)
; trying to decide whether to expand the terms inducted for in the induction
; conclusion. This suspicion is due to some testing done with the idea of
; "homographication" which was just a jokingly suggested name for the idea of
; generalizing the recursive calls away at INDUCT time after expanding the
; induction terms in the conclusion. Homographication speeded the
; theoremprover on many theorems but lost on several others because of the
; premature generalization. See the comment in FORMINDUCTIONCLAUSE.
; To avoid the generalization at INDUCT time we are going to try using
; TERMSTOBEIGNOREDBYREWRITE. The idea is this, during the initial
; simplification of a clause produced by INDUCT we will have the recursive
; terms on TERMSTOBEIGNOREDBYREWRITE. When the clause settles down 
; hopefully it will often be proved first  we will restore
; TERMSTOBEIGNOREDBYREWRITE to its preINDUCT value. Note however that
; we have to mess with TERMSTOBEIGNOREDBYREWRITE on a clause by clause
; basis, not just once in INDUCT.
; So here is the plan. INDUCT will set INDUCTIONHYPTERMS to the list of
; instances of the induction terms, and will set INDUCTIONCONCLTERMS to the
; induction terms themselves. SIMPLIFYCLAUSE will look at the history of
; the clause to determine whether it has settled down since induction. If
; not it will bind TERMSTOBEIGNOREDBYREWRITE to the concatenation of
; INDUCTIONHYPTERMS and its old value and will analogously bind EXPANDLST.
; A new process, called SETTLEDDOWNSENT, will be used to mark when in the
; history the clause settled down.
; In a departure from Nqthm, starting with Version_2.8, we do not wait for
; settleddown before turning off the above special consideration given to
; inductionhypterms and inductionconclterms. See simplifyclause for
; details.
(change provespecvar pspv
:inductionconclterms terms
:inductionhypterms (informsimplify1 talst terms nil)))
; Ok, except for our output and putting it all together, that's induction.
; We now turn to the output. Induct prints two different messages. One
; reports the successful choice of an induction. The other reports failure.
(defun allvars1lstlst (lst ans)
; Lst is a list of lists of terms. For example, it might be a set of
; clauses. We compute the set of all variables occuring in it.
(cond ((null lst) ans)
(t (allvars1lstlst (cdr lst)
(allvars1lst (car lst) ans)))))
(defun gennewname1 (charlst wrld i)
(let ((name (intern
(coerce
(append charlst
(explodenonnegativeinteger i 10 nil))
'string)
"ACL2")))
(cond ((newnamep name wrld) name)
(t (gennewname1 charlst wrld (1+ i))))))
(defun gennewname (root wrld)
; Create from the symbol root a possibly different symbol that
; is a newnamep in wrld.
(cond ((newnamep root wrld) root)
(t (gennewname1 (coerce (symbolname root) 'list) wrld 0))))
(defun unmeasuredvariables3 (vars alist)
; See unmeasuredvariables.
(cond ((null alist) nil)
((or (membereq (caar alist) vars)
(eq (caar alist) (cdar alist)))
(unmeasuredvariables3 vars (cdr alist)))
(t (cons (caar alist) (unmeasuredvariables3 vars (cdr alist))))))
(defun unmeasuredvariables2 (vars alists)
; See unmeasuredvariables.
(cond ((null alists) nil)
(t (unioneq (unmeasuredvariables3 vars (car alists))
(unmeasuredvariables2 vars (cdr alists))))))
(defun unmeasuredvariables1 (vars talst)
; See unmeasuredvariables.
(cond ((null talst) nil)
(t (unioneq (unmeasuredvariables2 vars
(access testsandalists
(car talst)
:alists))
(unmeasuredvariables1 vars (cdr talst))))))
(defun unmeasuredvariables (measuredvars cand)
; Measuredvars is the :subset of measured variables from the measure of term,
; computed above, for cand. We collect those variables that are changed by
; some substitution but are not measured by our induction measure. These are
; simply brought to the user's attention because we find it often surprising to
; see them.
(unmeasuredvariables1 measuredvars
(access candidate cand :testsandalistslst)))
(defun tilde@wellfoundedrelationphrase (rel wrld)
; We return a ~@ message that prints as "the relation rel (which, by name, is
; known to be wellfounded on the domain recognized by mp)" and variants of
; that obtained when name is nil (meaning the wellfoundedness is builtin)
; and/or mp is t (meaning the domain is the universe).
(let* ((temp (assoceq rel (globalval 'wellfoundedrelationalist wrld)))
(mp (cadr temp))
(basesymbol (basesymbol (cddr temp))))
(msg "the relation ~x0 (which~#1~[ ~/, by ~x2, ~]is known to be ~
wellfounded~#3~[~/ on the domain recognized by ~x4~])"
rel
(if (null basesymbol) 0 1)
basesymbol
(if (eq mp t) 0 1)
mp)))
(defun measuredvariables (cand wrld)
(allvars1lst
(subcorvarlst (formals (ffnsymb (access candidate cand :inductionterm))
wrld)
(fargs (access candidate cand :inductionterm))
(access justification
(access candidate cand :justification)
:subset))
nil))
(defun inductmsg/continue (poolname
clset
inducthintval
lencandidates
lenflushedcandidates
lenmergedcandidates
lenunvetoedcandidates
lencomplicatedcandidates
lenhighscoringcandidates
winningcandidate
estimatedsize
clauses
wrld
state)
; Poolname is the tilde@poolnamephrase (q.v.) of the set of
; clauses clset to which we are applying induction. Lencandidates
; is the length of the list of induction candidates we found.
; Lenflushedcandidates is the length of the candidates after
; flushing some down others, etc. Winningcandidate is the final
; selection. Clauses is the clause set generated by applying
; winningcandidate to clset. Wrld and state are the usual.
; This function increments timers. Upon entry, the accumulated time is
; charged to 'provetime. The time spent in this function is charged
; to 'printtime.
; Warning: This function should be called under (io? prove ...).
(pprogn
(incrementtimer 'provetime state)
(let* ((p (cons :p
(mergesorttermorder (allvars1lstlst clset nil))))
(measuredvariables (measuredvariables winningcandidate wrld))
(unmeasuredvariables (unmeasuredvariables measuredvariables
winningcandidate))
(attributionphrase (tilde*simpphrase
(access candidate winningcandidate :ttree))))
(fms "~#H~[We have been told to use induction. ~N0 induction ~
scheme~#1~[ is~/s are~] suggested by the induction ~
hint.~/~
We have been told to use induction. ~N0 induction ~
scheme~#1~[ is~/s are~] suggested by this ~
conjecture.~/~
Perhaps we can prove ~@n by induction. ~
~N0 induction scheme~#1~[ is~/s are~] suggested by this ~
conjecture.~] ~
~#a~[~/Subsumption reduces that number to ~n2. ~]~
~#b~[~/These merge into ~n3 derived induction scheme~#4~[~/s~]. ~]~
~#c~[~/However, ~n5 of these ~#6~[is~/are~] flawed and so we are ~
left with ~nq viable ~#r~[~/candidate~/candidates~]. ~]~
~#d~[~/By considering those suggested by the largest number of ~
nonprimitive recursive functions, we narrow the field ~
to ~n7. ~]~
~#e~[~/~N8 of these ~
~#9~[has a score higher than the other~#A~[~/s~]. ~/~
are tied for the highest score. ~]~]~
~#f~[~/We will choose arbitrarily among these. ~]~
~~%We will induct according to a scheme suggested by ~
~#h~[~pg.~/~pg, but modified to accommodate ~*i.~]~
~#w~[~/ ~#h~[This suggestion was~/These suggestions were~] ~
produced using ~*x.~] ~
If we let ~ ~pp denote ~@n above then the induction scheme ~
we'll use is~~
~qs.~
This induction is justified by the same argument used ~
to admit ~xj. ~
~#l~[~/Note, however, that the unmeasured ~
variable~#m~[ ~&m is~/s ~&m are~] being instantiated. ~]~
When applied to the goal at hand the above induction scheme ~
produces ~#v~[no nontautological subgoals~/one nontautological ~
subgoal~/the following ~no nontautological subgoals~].~
~#t~[~/ However, to achieve this relatively small number of ~
cases we had to fold ~@n into a single IFexpression. Had we ~
left it as a set of clauses this induction would have produced ~
approximately ~nu cases! Chances are that this proof attempt ~
is about to blow up in your face (and all over our memory ~
boards).~]~"
(list (cons #\H (cond ((null inducthintval) 2)
((equal inducthintval *t*) 1)
(t 0)))
(cons #\n poolname)
(cons #\0 lencandidates)
(cons #\1 (if (int= lencandidates 1) 0 1))
(cons #\a (if (< lenflushedcandidates
lencandidates)
1 0))
(cons #\2 lenflushedcandidates)
(cons #\b (if (< lenmergedcandidates
lenflushedcandidates)
1 0))
(cons #\3 lenmergedcandidates)
(cons #\4 (if (int= lenmergedcandidates 1) 0 1))
(cons #\c (if (< lenunvetoedcandidates
lenmergedcandidates)
1 0))
(cons #\5 ( lenmergedcandidates
lenunvetoedcandidates))
(cons #\q lenunvetoedcandidates)
(cons #\r (zerooneormore lenunvetoedcandidates))
(cons #\6 (if (int= ( lenmergedcandidates
lenunvetoedcandidates)
1)
0 1))
(cons #\d (if (< lencomplicatedcandidates
lenunvetoedcandidates)
1 0))
(cons #\7 lencomplicatedcandidates)
(cons #\e (if (< lenhighscoringcandidates
lencomplicatedcandidates)
1 0))
(cons #\8 lenhighscoringcandidates)
(cons #\9 (if (int= lenhighscoringcandidates 1) 0 1))
(cons #\A (if (int= ( lencomplicatedcandidates
lenhighscoringcandidates)
1)
0 1))
(cons #\f (if (int= lenhighscoringcandidates 1) 0 1))
(cons #\p p)
(cons #\s (prettyifyclauseset
(inductionformula
(list (list p))
(access candidate
winningcandidate
:testsandalistslst))
(let*abstractionp state)
wrld))
(cons #\g (access candidate winningcandidate
:xinductionterm))
(cons #\h (if (access candidate winningcandidate :xancestry)
1 0))
(cons #\i (tilde*untranslatelstphrase
(access candidate winningcandidate :xancestry)
nil wrld))
(cons #\j (ffnsymb
(access candidate winningcandidate
:xinductionterm)))
(cons #\l (if unmeasuredvariables 1 0))
(cons #\m unmeasuredvariables)
(cons #\o (length clauses))
(cons #\t (if (> estimatedsize *maximuminductsize*)
1
0))
(cons #\u estimatedsize)
(cons #\v (if (null clauses) 0 (if (cdr clauses) 2 1)))
(cons #\w (if (nth 4 attributionphrase) 1 0))
(cons #\x attributionphrase))
(proofsco state)
state
(termevisctuple nil state)))
(incrementtimer 'printtime state)))
(defun inductmsg/lose (poolname inducthintval state)
; We print the message that no induction was suggested.
; This function increments timers. Upon entry, the accumulated time is
; charged to 'provetime. The time spent in this function is charged
; to 'printtime.
; Warning: This function should be called under (io? prove ...).
(pprogn
(incrementtimer 'provetime state)
(fms "No induction schemes are suggested by ~#H~[the induction ~
hint~/~@n~]. Consequently, the proof attempt has ~
failed.~"
(list (cons #\H (cond (inducthintval 0)(t 1)))
(cons #\n poolname))
(proofsco state)
state
(termevisctuple nil state))
(incrementtimer 'printtime state)))
; When induct is called it is supplied the hintsettings that were
; attached to the clause by the user. Induct has the job of loading
; the hint settings into the pspv it returns. Most of the content of
; the hintsettings is loaded into the rewriteconstant of the pspv.
(defun loadhintsettingsintorcnst (hintsettings rcnst wrld ctx state)
; Certain user supplied hint settings find their way into the
; rewriteconstant. They are :expand, :restrict, :handsoff, and
; :intheory. Our convention is that if a given hint key/val is
; provided it replaces what was in the rcnst. Otherwise, we leave the
; corresponding field of rcnst unchanged.
(erlet* ((newens
(cond
((assoceq :intheory hintsettings)
(loadtheoryintoenabledstructure
:fromhint
(cdr (assoceq :intheory hintsettings))
nil
(access rewriteconstant rcnst :currentenabledstructure)
t
nil
wrld ctx state))
(t (value (access rewriteconstant rcnst
:currentenabledstructure))))))
(value (change rewriteconstant rcnst
:expandlst
(cond
((assoceq :expand hintsettings)
(cdr (assoceq :expand hintsettings)))
(t (access rewriteconstant rcnst :expandlst)))
:restrictionsalist
(cond
((assoceq :restrict hintsettings)
(cdr (assoceq :restrict hintsettings)))
(t (access rewriteconstant rcnst
:restrictionsalist)))
:fnstobeignoredbyrewrite
(cond
((assoceq :handsoff hintsettings)
(cdr (assoceq :handsoff hintsettings)))
(t (access rewriteconstant rcnst
:fnstobeignoredbyrewrite)))
:currentenabledstructure
newens
:nonlinearp
(cond
((assoceq :nonlinearp hintsettings)
(cdr (assoceq :nonlinearp hintsettings)))
(t (access rewriteconstant rcnst :nonlinearp)))))))
(defun updatehintsettings (newhintsettings oldhintsettings)
(cond
((endp newhintsettings) oldhintsettings)
((assoceq (caar newhintsettings) oldhintsettings)
(updatehintsettings
(cdr newhintsettings)
(cons (car newhintsettings)
(deleteassoceq (caar newhintsettings)
oldhintsettings))))
(t (updatehintsettings
(cdr newhintsettings)
(cons (car newhintsettings) oldhintsettings)))))
; Thus, a given hintsettings causes us to modify the pspv as follows:
(defun loadhintsettingsintopspv (incrementflg hintsettings pspv wrld ctx
state)
; We load the hintsettings into the rewriteconstant of pspv, thereby
; making available the :expand, :restrict, :handsoff, and :intheory
; hint settings. We also store the hintsettings in the hintsettings
; field of the pspv, making available the :induct and :donotinduct
; hint settings.
; When incrementflg is nonnil, we want to preserve the input pspv's hint
; settings except when they collide with hintsettings. Otherwise (for
; example, when induct is called), we completely replace the input pspv's
; :hintsettings with hintsettings.
; Warning: Restorehintsettingsinpspv, below, is supposed to undo
; these changes while not affecting the rest of a newly obtained pspv.
; Keep these two functions in step.
(erlet* ((rcnst (loadhintsettingsintorcnst
hintsettings
(access provespecvar pspv :rewriteconstant)
wrld ctx state)))
(value
(change provespecvar pspv
:rewriteconstant rcnst
:hintsettings
(if incrementflg
(updatehintsettings hintsettings
(access provespecvar pspv
:hintsettings))
hintsettings)))))
(defun restorehintsettingsinpspv (newpspv oldpspv)
; This considers the fields changed by loadhintsettingsintopspv above
; and restores them in newpspv to the values they have in oldpspv. The
; Idea is that we start with a pspv1, load hints into it to get pspv2,
; pass that around the prover and obtain pspv3 (which has a new tag tree
; and pool etc), and then restore the hint settings as they were in pspv1.
; In this example, newpspv would be pspv3 and oldpspv would be pspv1.
(change provespecvar newpspv
:rewriteconstant (access provespecvar oldpspv :rewriteconstant)
:hintsettings (access provespecvar oldpspv :hintsettings)))
(defun removetrivialclauses (clauses wrld)
(cond
((null clauses) nil)
((trivialclausep (car clauses) wrld)
(removetrivialclauses (cdr clauses) wrld))
(t (cons (car clauses)
(removetrivialclauses (cdr clauses) wrld)))))
#+:nonstandardanalysis
(defun classicalp (fn wrld)
; WARNING: This function is expected to return t for fn = :?, in support of
; measures (:? v1 ... vk), since classicalp is called by
; getnonclassicalfnsfromlist in support of getnonclassicalfnsaux.
(getprop fn 'classicalp
; We guarantee a 'classicalp property of nil for all nonclassical
; functions. We make no claims about the existence of a 'classicalp
; property for classical functions; in fact, as of Version_2.5 our
; intention is to put no 'classicalp property for classical functions.
t
'currentacl2world wrld))
;; RAG  This function tests whether a list of names is made up purely
;; of classical function names (i.e., not descended from the
;; nonstandard function symbols)
#+:nonstandardanalysis
(defun classicalfnlistp (names wrld)
(cond ((null names) t)
((not (classicalp (car names) wrld))
nil)
(t (classicalfnlistp (cdr names) wrld))))
#+:nonstandardanalysis
(defun nonstandardvectorcheck (vars accum)
(if (null vars)
accum
(nonstandardvectorcheck (cdr vars)
(cons (mconsterm* 'standardnumberp (car vars))
accum))))
#+:nonstandardanalysis
(defun mergenscheck (checks clause accum)
(if (null checks)
accum
(mergenscheck (cdr checks) clause (cons (cons (car checks)
clause)
accum))))
#+:nonstandardanalysis
(defun trapnonstandardvectoraux (clset accumcl checks wrld)
(cond ((null clset) accumcl)
((classicalfnlistp (allfnnameslst (car clset)) wrld)
(trapnonstandardvectoraux (cdr clset) accumcl checks wrld))
(t
(trapnonstandardvectoraux (cdr clset)
(append (mergenscheck checks
(car clset)
nil)
accumcl)
checks
wrld))))
#+:nonstandardanalysis
(defun removeadjacentduplicates (lst)
(cond ((or (null lst) (null (cdr lst))) lst)
((equal (car lst) (car (cdr lst)))
(removeadjacentduplicates (cdr lst)))
(t (cons (car lst) (removeadjacentduplicates (cdr lst))))))
#+:nonstandardanalysis
(defun nonstandardinductionvars (candidate wrld)
(removeadjacentduplicates
(mergesorttermorder
(append (access candidate candidate :changedvars)
; The following line was changed after Version_3.0.1. It seems like a correct
; change, but we'll leave this comment here until Ruben Gamboa (ACL2(r) author)
; checks this change.
(measuredvariables candidate wrld)))))
#+:nonstandardanalysis
(defun trapnonstandardvector (clset candidate accumcl wrld)
(trapnonstandardvectoraux clset accumcl
(nonstandardvectorcheck
(nonstandardinductionvars
candidate wrld)
nil)
wrld))
(defun induct (poolname clset hintsettings pspv wrld ctx state)
; We take a set of clauses, clset, and return four values. The first
; is either the signal 'lose (meaning we could find no induction to do
; and have explained that to the user) or 'continue, meaning we're
; going to use induction. The second value is a list of clauses,
; representing the induction base cases and steps. The last two
; things are new values for pspv and state. We modify pspv to store
; the inductionhypterms and inductionconclterms for the
; simplifier.
; The clause set we explore to collect the induction candidates,
; xclset, is not necessarily clset. If the value, v, of :induct in
; the hintsettings is nonnil and non*t*, then we explore the clause
; set {{v}} for candidates.
(let ((inducthintval
(cdr (assoceq :induct hintsettings))))
(mvlet
(erp newpspv state)
(loadhintsettingsintopspv
nil
(if inducthintval
(deleteassoceq :induct hintsettings)
hintsettings)
pspv wrld ctx state)
(cond
(erp (mv 'lose nil pspv state))
(t
(let* ((candidates
(getinductioncandsfromclset
(selectxclset clset inducthintval)
newpspv wrld state))
(flushedcandidates
(m&m candidates 'flushcandidates))
; In nqthm we flushed and merged at the same time. However, flushing
; is a mate and merge function that has the distributive and nonpreclusion
; properties and hence can be done with a simple m&m. Merging on the other
; hand is preclusive and so we wait and run m&moverpowerset to do
; that. In nqthm, we did preclusive merging with m&m (then called
; TRANSITIVECLOSURE) and just didn't worry about the fact that we
; messed up some potential merges by earlier merges. Of course, the
; powerset computation is so expensive for large sets that we can't
; just go into it blindly, so we don't use the m&moverpowerset to do
; flushing and merging at the same time. Flushing eliminates duplicates
; and subsumed inductions and thus shrinks the set as much as we know how.
(mergedcandidates
(cond ((< (length flushedcandidates) 10)
(m&moverpowerset flushedcandidates 'mergecandidates))
(t (m&m flushedcandidates 'mergecandidates))))
; Note: We really respect powerset. If the set we're trying to merge
; has more than 10 things in it  an arbitrary choice at the time of
; this writing  we just do the m&m instead, which causes us to miss
; some merges because we only use each candidate once and merging
; early merges can prevent later ones.
(unvetoedcandidates
(computevetoes mergedcandidates wrld))
(complicatedcandidates
(maximalelements unvetoedcandidates 'inductioncomplexity wrld))
(highscoringcandidates
(maximalelements complicatedcandidates 'score wrld))
(winningcandidate (car highscoringcandidates)))
(cond
(winningcandidate
(mvlet
(erp candidatettree state)
(accumulatettreeintostate
(access candidate winningcandidate :ttree)
state)
(declare (ignore erp))
(let* (
; First, we estimate the size of the answer if we persist in using clset.
(estimatedsize
(inductionformulasize clset
(access candidate
winningcandidate
:testsandalistslst)))
; Next we create clauses, the set of clauses we wish to prove.
; Observe that if the estimated size is greater than
; *maximuminductsize* we squeeze the clset into the form {{p}},
; where p is a single term. This eliminates the combinatoric
; explosion at the expense of making the rest of the theorem prover
; suffer through opening things back up. The idea, however, is that
; it is better to give the user something to look at, so he see's the
; problem blowing up in front of him in rewrite, than to just
; disappear into induction and never come out. We have seen simple
; cases where failed guard conjectures would have led to inductions
; containing thousands of cases had induct been allowed to compute
; them out.
(clauses0
(inductionformula
(cond ((> estimatedsize *maximuminductsize*)
(list (list (termifyclauseset clset))))
(t clset))
(access candidate winningcandidate :testsandalistslst)))
(clauses1
#+:nonstandardanalysis
(trapnonstandardvector clset
winningcandidate
clauses0
wrld)
#:nonstandardanalysis
clauses0)
(clauses
(cond ((> estimatedsize *maximuminductsize*)
clauses1)
(t (removetrivialclauses clauses1 wrld))))
; Now we inform the simplifier of this induction and store the ttree of
; the winning candidate into the tagtree of the pspv.
(newerpspv
(informsimplify
(access candidate winningcandidate :testsandalistslst)
(cons (access candidate winningcandidate :xinductionterm)
(access candidate winningcandidate :xotherterms))
(change provespecvar newpspv
:tagtree
(constagtrees
candidatettree
(access provespecvar newpspv :tagtree))))))
; Now we print out the induct message.
(let ((state
(io? prove nil state
(wrld clauses estimatedsize winningcandidate
highscoringcandidates complicatedcandidates
unvetoedcandidates mergedcandidates
flushedcandidates candidates inducthintval
clset poolname)
(inductmsg/continue poolname
clset
inducthintval
(length candidates)
(length flushedcandidates)
(length mergedcandidates)
(length unvetoedcandidates)
(length complicatedcandidates)
(length highscoringcandidates)
winningcandidate
estimatedsize
clauses
wrld
state))))
(mv 'continue
clauses
newerpspv
state)))))
(t
; Otherwise, we report our failure to find an induction and return the
; 'lose signal.
(let ((state (io? prove nil state
(inducthintval poolname)
(inductmsg/lose poolname inducthintval state))))
(mv 'lose nil pspv state))))))))))
; We now define the elimination of irrelevance. Logically this ought
; to be defined when the other processors are defined. But to
; partition the literals of the clause by variables we use m&m, which
; is not defined until induction. We could have moved m&mapply back
; into the earlier processors, but that would require moving about a
; third of induction back there. So we have just put all of
; irrelevance elimination here.
(defun pairvarswithlits (cl)
; We pair each lit of clause cl with its variables. The variables are
; in the car of the pair, the singleton set containing the lit is in
; the cdr.
(cond ((null cl) nil)
(t (cons (cons (allvars (car cl)) (list (car cl)))
(pairvarswithlits (cdr cl))))))
(mutualrecursion
(defun ffnnamessubsetp (term lst)
; Collect the ffnames in term and say whether it is a subset of lst.
; We don't consider fnnames of constants, e.g., the cons of '(a b).
(cond ((variablep term) t)
((fquotep term) t)
((flambdaapplicationp term)
(and (ffnnamessubsetplistp (fargs term) lst)
(ffnnamessubsetp (lambdabody term) lst)))
((membereq (ffnsymb term) lst)
(ffnnamessubsetplistp (fargs term) lst))
(t nil)))
(defun ffnnamessubsetplistp (terms lst)
(cond ((null terms) t)
((ffnnamessubsetp (car terms) lst)
(ffnnamessubsetplistp (cdr terms) lst))
(t nil)))
)
;; RAG  I added realp and complexp to the list of function names
;; simplification can decide.
(defun probablynotvalidp (cl)
; Cl is a clause. We return t if we think there is an instantiation
; of cl that makes each literal false. It is assumed that cl has
; survived simplification.
; We have two trivial heuristics. One is to detect whether the only
; function symbols in cl are ones that we think make up a fragment
; of the theory that simplification can decide. The other heuristic
; is to bet that any cl consisting of a single literal which is of the
; form (fn v1 ... vn) or (not (fn v1 ... vn)), where the vi are
; distinct variables, is probably not valid.
; It's pretty bold to include a recursive function, namely truelistp, in the
; list below. However, as long as it's the only one, we feel safe.
(or (ffnnamessubsetplistp cl '(consp integerp rationalp
#+:nonstandardanalysis realp
acl2numberp
truelistp complexrationalp
#+:nonstandardanalysis complexp
stringp characterp
symbolp cons car cdr equal
binary+ unary < apply))
(casematch cl
((('not (& . args)))
(and (allvariablep args)
(noduplicatespequal args)))
(((& . args))
(and (allvariablep args)
(noduplicatespequal args)))
(& nil))))
(defun irrelevantlits (alist)
; Alist is an alist that associates a set of literals with each key.
; The keys are irrelevant. We consider each set of literals and decide
; if it is probably not valid. If so we consider it irrelevant.
; We return the concatenation of all the irrelevant literal sets.
(cond ((null alist) nil)
((probablynotvalidp (cdar alist))
(append (cdar alist) (irrelevantlits (cdr alist))))
(t (irrelevantlits (cdr alist)))))
(defun eliminateirrelevanceclause (cl hist pspv wrld state)
; A standard clause processor of the waterfall.
; We return 4 values. The first is a signal that is either 'hit, or
; 'miss. When the signal is 'miss, the other 3 values are irrelevant.
; When the signal is 'hit, the second result is the list of new
; clauses, the third is a ttree that will become that component of the
; historyentry for this elimination, and the fourth is an
; unmodified pspv. (We return the fourth thing to adhere to the
; convention used by all clause processors in the waterfall (q.v.).)
(declare (ignore hist wrld state))
(cond
((not (assoceq 'beingprovedbyinduction
(access provespecvar pspv :pool)))
(mv 'miss nil nil nil))
(t (let* ((partitioning (m&m (pairvarswithlits cl)
'intersectpeq/unionequal))
(irrelevantlits (irrelevantlits partitioning)))
(cond ((null irrelevantlits)
(mv 'miss nil nil nil))
(t (mv 'hit
(list (setdifferenceequal cl irrelevantlits))
(addtotagtree
'irrelevantlits irrelevantlits
(addtotagtree
'clause cl nil))
pspv)))))))
(defun eliminateirrelevanceclausemsg1 (signal clauses ttree pspv state)
; The arguments to this function are the standard ones for an output
; function in the waterfall. See the discussion of the waterfall.
(declare (ignore signal pspv clauses))
(let* ((lits (cdr (taggedobject 'irrelevantlits ttree)))
(clause (cdr (taggedobject 'clause ttree)))
(concl (car (last clause))))
(cond
((equal (length lits)
(length clause))
(fms "We suspect that this conjecture is not a theorem. We ~
might as well be trying to prove~"
nil
(proofsco state)
state
(termevisctuple nil state)))
(t
(let ((iterms (cond
((memberequal concl lits)
(append
(dumbnegatelitlst
(remove1equal concl lits))
(list concl)))
(t (dumbnegatelitlst lits)))))
(fms "We suspect that the term~#0~[ ~*1 is~/s ~*1 are~] ~
irrelevant to the truth of this conjecture and throw ~
~#0~[it~/them~] out. We will thus try to prove~"
(list
(cons #\0 iterms)
(cons #\1 (tilde*untranslatelstphrase iterms t (w state))))
(proofsco state)
state
(termevisctuple nil state)))))))
