/usr/share/minlog/src/proof.scm is in minlog 4.0.99.20100221-5.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 7555 7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 7801 7802 7803 7804 7805 7806 7807 7808 7809 7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 7863 7864 7865 7866 7867 7868 7869 7870 7871 7872 7873 7874 7875 7876 7877 7878 7879 7880 7881 7882 7883 7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 7895 7896 7897 7898 7899 7900 7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 7921 7922 7923 7924 7925 7926 7927 7928 7929 7930 7931 7932 7933 7934 7935 7936 7937 7938 7939 7940 7941 7942 7943 7944 7945 7946 7947 7948 7949 7950 7951 7952 7953 7954 7955 7956 7957 7958 7959 7960 7961 7962 7963 7964 7965 7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 7976 7977 7978 7979 7980 7981 7982 7983 7984 7985 7986 7987 7988 7989 7990 7991 7992 7993 7994 7995 7996 7997 7998 7999 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 8020 8021 8022 8023 8024 8025 8026 8027 8028 8029 8030 8031 8032 8033 8034 8035 8036 8037 8038 8039 8040 8041 8042 8043 8044 8045 8046 8047 8048 8049 8050 8051 8052 8053 8054 8055 8056 8057 8058 8059 8060 8061 8062 8063 8064 8065 8066 8067 8068 8069 8070 8071 8072 8073 8074 8075 8076 8077 8078 8079 8080 8081 8082 8083 8084 8085 8086 8087 8088 8089 8090 8091 8092 8093 8094 8095 8096 8097 8098 8099 8100 8101 8102 8103 8104 8105 8106 8107 8108 8109 8110 8111 8112 8113 8114 8115 8116 8117 8118 8119 8120 8121 8122 8123 8124 8125 8126 8127 8128 8129 8130 8131 8132 8133 8134 8135 8136 8137 8138 8139 8140 8141 8142 8143 8144 8145 8146 8147 8148 8149 8150 8151 8152 8153 8154 8155 8156 8157 8158 8159 8160 8161 8162 8163 8164 8165 8166 8167 8168 8169 8170 8171 8172 8173 8174 8175 8176 8177 8178 8179 8180 8181 8182 8183 8184 8185 8186 8187 8188 8189 8190 8191 8192 8193 8194 8195 8196 8197 8198 8199 8200 8201 8202 8203 8204 8205 8206 8207 8208 8209 8210 8211 8212 8213 8214 8215 8216 8217 8218 8219 8220 8221 8222 8223 8224 8225 8226 8227 8228 8229 8230 8231 8232 8233 8234 8235 8236 8237 8238 8239 8240 8241 8242 8243 8244 8245 8246 8247 8248 8249 8250 8251 8252 8253 8254 8255 8256 8257 8258 8259 8260 8261 8262 8263 8264 8265 8266 8267 8268 8269 8270 8271 8272 8273 8274 8275 8276 8277 8278 8279 8280 8281 8282 8283 8284 8285 8286 8287 8288 8289 8290 8291 8292 8293 8294 8295 8296 8297 8298 8299 8300 8301 8302 8303 8304 8305 8306 8307 8308 8309 8310 8311 8312 8313 8314 8315 8316 8317 8318 8319 8320 8321 8322 8323 8324 8325 8326 8327 8328 8329 8330 8331 8332 8333 8334 8335 8336 8337 8338 8339 8340 8341 8342 8343 8344 8345 8346 8347 8348 8349 8350 8351 8352 8353 8354 8355 8356 8357 8358 8359 8360 8361 8362 8363 8364 8365 8366 8367 8368 8369 8370 8371 8372 8373 8374 8375 8376 8377 8378 8379 8380 8381 8382 8383 8384 8385 8386 8387 8388 8389 8390 8391 8392 8393 8394 8395 8396 8397 8398 8399 8400 8401 8402 8403 8404 8405 8406 8407 8408 8409 8410 8411 8412 8413 8414 8415 8416 8417 8418 8419 8420 8421 8422 8423 8424 8425 8426 8427 8428 8429 8430 8431 8432 8433 8434 8435 8436 8437 8438 8439 8440 8441 8442 8443 8444 8445 8446 8447 8448 8449 8450 8451 8452 8453 8454 8455 8456 8457 8458 8459 8460 8461 8462 8463 8464 8465 8466 8467 8468 8469 8470 8471 8472 8473 8474 8475 8476 8477 8478 8479 8480 8481 8482 8483 8484 8485 8486 8487 8488 8489 8490 8491 8492 8493 8494 8495 8496 8497 8498 8499 8500 8501 8502 8503 8504 8505 8506 8507 8508 8509 8510 8511 8512 8513 8514 8515 8516 8517 8518 8519 8520 8521 8522 8523 8524 8525 8526 8527 8528 8529 8530 8531 8532 8533 8534 8535 8536 8537 8538 8539 8540 8541 8542 8543 8544 8545 8546 8547 8548 8549 8550 8551 8552 8553 8554 8555 8556 8557 8558 8559 8560 8561 8562 8563 8564 8565 8566 8567 8568 8569 8570 8571 8572 8573 8574 8575 8576 8577 8578 8579 8580 8581 8582 8583 8584 8585 8586 8587 8588 8589 8590 8591 8592 8593 8594 8595 8596 8597 8598 8599 8600 8601 8602 8603 8604 8605 8606 8607 8608 8609 8610 8611 8612 8613 8614 8615 8616 8617 8618 8619 8620 8621 8622 8623 8624 8625 8626 8627 8628 8629 8630 8631 8632 8633 8634 8635 8636 8637 8638 8639 8640 8641 8642 8643 8644 8645 8646 8647 8648 8649 8650 8651 8652 8653 8654 8655 8656 8657 8658 8659 8660 8661 8662 8663 8664 8665 8666 8667 8668 8669 8670 8671 8672 8673 8674 8675 8676 8677 8678 8679 8680 8681 8682 8683 8684 8685 8686 8687 8688 8689 8690 8691 8692 8693 8694 8695 8696 8697 8698 8699 8700 8701 8702 8703 8704 8705 8706 8707 8708 8709 8710 8711 8712 8713 8714 8715 8716 8717 8718 8719 8720 8721 8722 8723 8724 8725 8726 8727 8728 8729 8730 8731 8732 8733 8734 8735 8736 8737 8738 8739 8740 8741 8742 8743 8744 8745 8746 8747 8748 8749 8750 8751 8752 8753 8754 8755 8756 8757 8758 8759 8760 8761 8762 8763 8764 8765 8766 8767 8768 8769 8770 8771 8772 8773 8774 8775 8776 8777 8778 8779 8780 8781 8782 8783 8784 8785 8786 8787 8788 8789 8790 8791 8792 8793 8794 8795 8796 8797 8798 8799 8800 8801 8802 8803 8804 8805 8806 8807 8808 8809 8810 8811 8812 8813 8814 8815 8816 8817 8818 8819 8820 8821 8822 8823 8824 8825 8826 8827 8828 8829 8830 8831 8832 8833 8834 8835 8836 8837 8838 8839 8840 8841 8842 8843 8844 8845 8846 8847 8848 8849 8850 8851 8852 8853 8854 8855 8856 8857 8858 8859 8860 8861 8862 8863 8864 8865 8866 8867 8868 8869 8870 8871 8872 8873 8874 8875 8876 8877 8878 8879 8880 8881 8882 8883 8884 8885 8886 8887 8888 8889 8890 8891 8892 8893 8894 8895 8896 8897 8898 8899 8900 8901 8902 8903 8904 8905 8906 8907 8908 8909 8910 8911 8912 8913 8914 8915 8916 8917 8918 8919 8920 8921 8922 8923 8924 8925 8926 8927 8928 8929 8930 8931 8932 8933 8934 8935 8936 8937 8938 8939 8940 8941 8942 8943 8944 8945 8946 8947 8948 8949 8950 8951 8952 8953 8954 8955 8956 8957 8958 8959 8960 8961 8962 8963 8964 8965 8966 8967 8968 8969 8970 8971 8972 8973 8974 8975 8976 8977 8978 8979 8980 8981 8982 8983 8984 8985 8986 8987 8988 8989 8990 8991 8992 8993 8994 8995 8996 8997 8998 8999 9000 9001 9002 9003 9004 9005 9006 9007 9008 9009 9010 9011 9012 9013 9014 9015 9016 9017 9018 9019 9020 9021 9022 9023 9024 9025 9026 9027 9028 9029 9030 9031 9032 9033 9034 9035 9036 9037 9038 9039 9040 9041 9042 9043 9044 9045 9046 9047 9048 9049 9050 9051 9052 9053 9054 9055 9056 9057 9058 9059 9060 9061 9062 9063 9064 9065 9066 9067 9068 9069 9070 9071 9072 9073 9074 9075 9076 9077 9078 9079 9080 9081 9082 9083 9084 9085 9086 9087 9088 9089 9090 9091 9092 9093 9094 9095 9096 9097 9098 9099 9100 9101 9102 9103 9104 9105 9106 9107 9108 9109 9110 9111 9112 9113 9114 9115 9116 9117 9118 9119 9120 9121 9122 9123 9124 9125 9126 9127 9128 9129 9130 9131 9132 9133 9134 9135 9136 9137 9138 9139 9140 9141 9142 9143 9144 9145 9146 9147 9148 9149 9150 9151 9152 9153 9154 9155 9156 9157 9158 9159 9160 9161 9162 9163 9164 9165 9166 9167 9168 9169 9170 9171 9172 9173 9174 9175 9176 9177 9178 9179 9180 9181 9182 9183 9184 9185 9186 9187 9188 9189 9190 9191 9192 9193 9194 9195 9196 9197 9198 9199 9200 9201 9202 9203 9204 9205 9206 9207 9208 9209 9210 9211 9212 9213 9214 9215 9216 9217 9218 9219 9220 9221 9222 9223 9224 9225 9226 9227 9228 9229 9230 9231 9232 9233 9234 9235 9236 9237 9238 9239 9240 9241 9242 9243 9244 9245 9246 9247 9248 9249 9250 9251 9252 9253 9254 9255 9256 9257 9258 9259 9260 9261 9262 9263 9264 9265 9266 9267 9268 9269 9270 9271 9272 9273 9274 9275 9276 9277 9278 9279 9280 9281 9282 9283 9284 9285 9286 9287 9288 9289 9290 9291 9292 9293 9294 9295 9296 9297 9298 9299 9300 9301 9302 9303 9304 9305 9306 9307 9308 9309 9310 9311 9312 9313 9314 9315 9316 9317 9318 9319 9320 9321 9322 9323 9324 9325 9326 9327 9328 9329 9330 9331 9332 9333 9334 9335 9336 9337 9338 9339 9340 9341 9342 9343 9344 9345 9346 9347 9348 9349 9350 9351 9352 9353 9354 9355 9356 9357 9358 9359 9360 9361 9362 9363 9364 9365 9366 9367 9368 9369 9370 9371 9372 9373 9374 9375 9376 9377 9378 9379 9380 9381 9382 9383 9384 9385 9386 9387 9388 9389 9390 9391 9392 9393 9394 9395 9396 9397 9398 9399 9400 9401 9402 9403 9404 9405 9406 9407 9408 9409 9410 9411 9412 9413 | ; $Id: proof.scm 2357 2009-12-10 17:10:45Z schwicht $
; 10. Proofs
; ==========
; 10-1. Constructors and accessors
; ================================
; Proofs are built from assumption variables and assumption constants
; (i.e., axioms, theorems and global assumption) by the usual rules of
; natural deduction, i.e., introduction and elimination rules for
; implication, conjunction and universal quantification. From a proof
; we can read off its context, which is an ordered list of object and
; assumption variables.
(define proof-to-formula cadr)
; Proofs always have the form (tag formula ...) where ... is a list with
; further information.
; Constructor, accessor and test for proofs in assumption variable form:
; (proof-in-avar-form formula avar)
(define (make-proof-in-avar-form avar)
(list 'proof-in-avar-form (avar-to-formula avar) avar))
(define proof-in-avar-form-to-avar caddr)
(define (proof-in-avar-form? proof)
(eq? 'proof-in-avar-form (tag proof)))
; Constructor, accessor and test for proofs in assumption constant form:
(define (make-proof-in-aconst-form aconst)
(list 'proof-in-aconst-form (aconst-to-formula aconst) aconst))
(define proof-in-aconst-form-to-aconst caddr)
(define (proof-in-aconst-form? proof)
(eq? 'proof-in-aconst-form (tag proof)))
; Constructors, accessors and test for implication introduction:
(define (make-proof-in-imp-intro-form avar proof)
(list 'proof-in-imp-intro-form
(make-imp (avar-to-formula avar) (proof-to-formula proof))
avar
proof))
(define proof-in-imp-intro-form-to-avar caddr)
(define proof-in-imp-intro-form-to-kernel cadddr)
(define (proof-in-imp-intro-form? proof)
(eq? 'proof-in-imp-intro-form (tag proof)))
(define (make-proof-in-impnc-intro-form avar proof)
(list 'proof-in-impnc-intro-form
(make-impnc (avar-to-formula avar) (proof-to-formula proof))
avar
proof))
(define proof-in-impnc-intro-form-to-avar caddr)
(define proof-in-impnc-intro-form-to-kernel cadddr)
(define (proof-in-impnc-intro-form? proof)
(eq? 'proof-in-impnc-intro-form (tag proof)))
; (mk-proof-in-intro-form x1 ... proof) is formed from proof by first
; abstracting x1, then x2 and so on. Here x1, x2 ... can be
; assumption or object variables.
(define (mk-proof-in-intro-form x . rest)
(if (null? rest)
x
(cond ((avar-form? x)
(let ((prev (apply mk-proof-in-intro-form rest)))
(make-proof-in-imp-intro-form x prev)))
((var-form? x)
(let ((prev (apply mk-proof-in-intro-form rest)))
(make-proof-in-all-intro-form x prev)))
(else (myerror "mk-proof-in-intro-form"
"assumption or object variable expected"
x)))))
(define (mk-proof-in-nc-intro-form x . rest)
(if (null? rest)
x
(cond ((avar-form? x)
(let ((prev (apply mk-proof-in-nc-intro-form rest)))
(make-proof-in-impnc-intro-form x prev)))
((var-form? x)
(let ((prev (apply mk-proof-in-nc-intro-form rest)))
(make-proof-in-allnc-intro-form x prev)))
(else (myerror "mk-proof-in-nc-intro-form"
"assumption or object variable expected"
x)))))
(define (proof-in-intro-form-to-kernel-and-vars proof)
(case (tag proof)
((proof-in-imp-intro-form)
(let* ((prev (proof-in-intro-form-to-kernel-and-vars
(proof-in-imp-intro-form-to-kernel proof)))
(prev-kernel (car prev))
(prev-vars (cdr prev)))
(cons prev-kernel
(cons (proof-in-imp-intro-form-to-avar proof) prev-vars))))
((proof-in-impnc-intro-form)
(let* ((prev (proof-in-intro-form-to-kernel-and-vars
(proof-in-impnc-intro-form-to-kernel proof)))
(prev-kernel (car prev))
(prev-vars (cdr prev)))
(cons prev-kernel
(cons (proof-in-impnc-intro-form-to-avar proof) prev-vars))))
((proof-in-all-intro-form)
(let* ((prev (proof-in-intro-form-to-kernel-and-vars
(proof-in-all-intro-form-to-kernel proof)))
(prev-kernel (car prev))
(prev-vars (cdr prev)))
(cons prev-kernel
(cons (proof-in-all-intro-form-to-var proof) prev-vars))))
((proof-in-allnc-intro-form)
(let* ((prev (proof-in-intro-form-to-kernel-and-vars
(proof-in-allnc-intro-form-to-kernel proof)))
(prev-kernel (car prev))
(prev-vars (cdr prev)))
(cons prev-kernel
(cons (proof-in-allnc-intro-form-to-var proof) prev-vars))))
(else (list proof))))
(define (proof-in-intro-form-to-vars proof . x)
(cond
((null? x)
(if (proof-in-imp-impnc-all-allnc-intro-form? proof)
(cons (proof-in-imp-impnc-all-allnc-intro-form-to-var proof)
(proof-in-intro-form-to-vars
(proof-in-imp-impnc-all-allnc-intro-form-to-kernel proof)))
'()))
((and (integer? (car x)) (not (negative? (car x))))
(let ((n (car x)))
(do ((p proof (proof-in-imp-impnc-all-allnc-intro-form-to-kernel p))
(i 0 (+ 1 i))
(res '() (cons (proof-in-imp-impnc-all-allnc-intro-form-to-var p)
res)))
((or (= n i) (not (proof-in-imp-impnc-all-allnc-intro-form? p)))
(reverse res)))))
(else (myerror "proof-in-intro-form-to-vars" "non-negative integer expected"
(car x)))))
; proof-in-intro-form-to-final-kernel computes the final kernel (the
; kernel after removing at most (car x) abstracted avars and vars) of
; a proof.
(define (proof-in-intro-form-to-final-kernel proof . x)
(cond
((null? x)
(if (proof-in-imp-impnc-all-allnc-intro-form? proof)
(proof-in-intro-form-to-final-kernel
(proof-in-imp-impnc-all-allnc-intro-form-to-kernel proof))
proof))
((and (integer? (car x)) (not (negative? (car x))))
(let ((n (car x)))
(do ((p proof (proof-in-imp-impnc-all-allnc-intro-form-to-kernel p))
(i 0 (+ 1 i))
(res proof (proof-in-imp-impnc-all-allnc-intro-form-to-kernel res)))
((or (= n i) (not (proof-in-imp-impnc-all-allnc-intro-form? p)))
res))))
(else (myerror "proof-in-intro-form-to-final-kernel"
"non-negative integer expected"
(car x)))))
(define (intro-proof-and-new-kernel-and-depth-to-proof proof new-kernel . x)
(cond
((null? x)
(case (tag proof)
((proof-in-imp-intro-form)
(make-proof-in-imp-intro-form
(proof-in-imp-intro-form-to-avar proof)
(intro-proof-and-new-kernel-and-depth-to-proof
(proof-in-imp-intro-form-to-kernel proof) new-kernel)))
((proof-in-impnc-intro-form)
(make-proof-in-impnc-intro-form
(proof-in-impnc-intro-form-to-avar proof)
(intro-proof-and-new-kernel-and-depth-to-proof
(proof-in-impnc-intro-form-to-kernel proof) new-kernel)))
((proof-in-all-intro-form)
(make-proof-in-all-intro-form
(proof-in-all-intro-form-to-var proof)
(intro-proof-and-new-kernel-and-depth-to-proof
(proof-in-all-intro-form-to-kernel proof) new-kernel)))
((proof-in-allnc-intro-form)
(make-proof-in-allnc-intro-form
(proof-in-allnc-intro-form-to-var proof)
(intro-proof-and-new-kernel-and-depth-to-proof
(proof-in-allnc-intro-form-to-kernel proof) new-kernel)))
(else new-kernel)))
((and (integer? (car x)) (not (negative? (car x))))
(let ((n (car x)))
(if
(zero? n) new-kernel
(case (tag proof)
((proof-in-imp-intro-form)
(make-proof-in-imp-intro-form
(proof-in-imp-intro-form-to-avar proof)
(intro-proof-and-new-kernel-and-depth-to-proof
(proof-in-imp-intro-form-to-kernel proof) new-kernel (- n 1))))
((proof-in-impnc-intro-form)
(make-proof-in-impnc-intro-form
(proof-in-impnc-intro-form-to-avar proof)
(intro-proof-and-new-kernel-and-depth-to-proof
(proof-in-impnc-intro-form-to-kernel proof) new-kernel (- n 1))))
((proof-in-all-intro-form)
(make-proof-in-all-intro-form
(proof-in-all-intro-form-to-var proof)
(intro-proof-and-new-kernel-and-depth-to-proof
(proof-in-all-intro-form-to-kernel proof) new-kernel (- n 1))))
((proof-in-allnc-intro-form)
(make-proof-in-allnc-intro-form
(proof-in-allnc-intro-form-to-var proof)
(intro-proof-and-new-kernel-and-depth-to-proof
(proof-in-allnc-intro-form-to-kernel proof) new-kernel (- n 1))))
(else new-kernel)))))))
; Constructors, accessors and test for implication eliminations:
(define (make-proof-in-imp-elim-form proof1 proof2)
(list 'proof-in-imp-elim-form
(imp-form-to-conclusion (proof-to-formula proof1))
proof1
proof2))
(define proof-in-imp-elim-form-to-op caddr)
(define proof-in-imp-elim-form-to-arg cadddr)
(define (proof-in-imp-elim-form? proof)
(eq? 'proof-in-imp-elim-form (tag proof)))
(define (proof-to-final-imp-elim-op proof)
(if (proof-in-imp-elim-form? proof)
(proof-to-final-imp-elim-op (proof-in-imp-elim-form-to-op proof))
proof))
(define (proof-to-imp-elim-args proof)
(if (proof-in-imp-elim-form? proof)
(append (proof-to-imp-elim-args
(proof-in-imp-elim-form-to-op proof))
(list (proof-in-imp-elim-form-to-arg proof)))
'()))
(define (make-proof-in-impnc-elim-form proof1 proof2)
(list 'proof-in-impnc-elim-form
(impnc-form-to-conclusion (proof-to-formula proof1))
proof1
proof2))
(define proof-in-impnc-elim-form-to-op caddr)
(define proof-in-impnc-elim-form-to-arg cadddr)
(define (proof-in-impnc-elim-form? proof)
(eq? 'proof-in-impnc-elim-form (tag proof)))
(define (proof-to-final-impnc-elim-op proof)
(if (proof-in-impnc-elim-form? proof)
(proof-to-final-impnc-elim-op (proof-in-impnc-elim-form-to-op proof))
proof))
(define (proof-to-impnc-elim-args proof)
(if (proof-in-impnc-elim-form? proof)
(append (proof-to-impnc-elim-args
(proof-in-impnc-elim-form-to-op proof))
(list (proof-in-impnc-elim-form-to-arg proof)))
'()))
(define (proof-in-imp-impnc-all-allnc-intro-form? proof)
(or (proof-in-imp-intro-form? proof)
(proof-in-impnc-intro-form? proof)
(proof-in-all-intro-form? proof)
(proof-in-allnc-intro-form? proof)))
(define (proof-in-imp-impnc-all-allnc-intro-form-to-var proof)
(case (tag proof)
((proof-in-imp-intro-form)
(proof-in-imp-intro-form-to-avar proof))
((proof-in-impnc-intro-form)
(proof-in-impnc-intro-form-to-avar proof))
((proof-in-all-intro-form)
(proof-in-all-intro-form-to-var proof))
((proof-in-allnc-intro-form)
(proof-in-allnc-intro-form-to-var proof))
(else (myerror "proof-in-imp-impnc-all-allnc-intro-form-to-var"
"unexpected proof with tag" (tag proof)))))
(define (proof-in-imp-impnc-all-allnc-intro-form-to-kernel proof)
(case (tag proof)
((proof-in-imp-intro-form)
(proof-in-imp-intro-form-to-kernel proof))
((proof-in-impnc-intro-form)
(proof-in-impnc-intro-form-to-kernel proof))
((proof-in-all-intro-form)
(proof-in-all-intro-form-to-kernel proof))
((proof-in-allnc-intro-form)
(proof-in-allnc-intro-form-to-kernel proof))
(else (myerror "proof-in-imp-impnc-all-allnc-intro-form-to-kernel"
"unexpected proof with tag" (tag proof)))))
(define (mk-proof-in-elim-form proof . elim-items)
(if
(null? elim-items)
proof
(let ((formula (unfold-formula (proof-to-formula proof))))
(cond
((or (prime-form? formula)
(ex-form? formula)
(exnc-form? formula)
(exd-form? formula)
(exl-form? formula)
(exr-form? formula)
(exu-form? formula)
(exdt-form? formula)
(exlt-form? formula)
(exrt-form? formula)
(exut-form? formula))
(myerror "mk-proof-in-elim-form"
"applicable formula expected" formula))
((imp-form? formula)
(apply mk-proof-in-elim-form
(cons (make-proof-in-imp-elim-form proof (car elim-items))
(cdr elim-items))))
((impnc-form? formula)
(apply mk-proof-in-elim-form
(cons (make-proof-in-impnc-elim-form proof (car elim-items))
(cdr elim-items))))
((and-form? formula)
(cond ((eq? 'left (car elim-items))
(apply mk-proof-in-elim-form
(cons (make-proof-in-and-elim-left-form proof)
(cdr elim-items))))
((eq? 'right (car elim-items))
(apply mk-proof-in-elim-form
(cons (make-proof-in-and-elim-right-form proof)
(cdr elim-items))))
(else (myerror "mk-proof-in-elim-form" "left or right expected"
(car elim-items)))))
((and (bicon-form? formula)
(memq (bicon-form-to-bicon formula)
'(andd andl andr andu)))
(let ((left-conjunct (bicon-form-to-left formula))
(right-conjunct (bicon-form-to-right formula)))
(myerror "mk-proof-in-elim-form"
"not implemented for"
formula)))
((all-form? formula)
(if (term-form? (car elim-items))
(apply mk-proof-in-elim-form
(cons (make-proof-in-all-elim-form proof (car elim-items))
(cdr elim-items)))
(myerror "mk-proof-in-elim-form" "term expected"
(car elim-items))))
((allnc-form? formula)
(if (term-form? (car elim-items))
(apply mk-proof-in-elim-form
(cons (make-proof-in-allnc-elim-form proof (car elim-items))
(cdr elim-items)))
(myerror "mk-proof-in-elim-form" "term expected"
(car elim-items))))
(else (myerror "mk-proof-in-elim-form" "formula expected" formula))))))
(define (proof-in-elim-form-to-final-op proof)
(case (tag proof)
((proof-in-imp-elim-form)
(proof-in-elim-form-to-final-op
(proof-in-imp-elim-form-to-op proof)))
((proof-in-impnc-elim-form)
(proof-in-elim-form-to-final-op
(proof-in-impnc-elim-form-to-op proof)))
((proof-in-and-elim-left-form)
(proof-in-elim-form-to-final-op
(proof-in-and-elim-left-form-to-kernel proof)))
((proof-in-and-elim-right-form)
(proof-in-elim-form-to-final-op
(proof-in-and-elim-right-form-to-kernel proof)))
((proof-in-all-elim-form)
(proof-in-elim-form-to-final-op
(proof-in-all-elim-form-to-op proof)))
((proof-in-allnc-elim-form)
(proof-in-elim-form-to-final-op
(proof-in-allnc-elim-form-to-op proof)))
(else proof)))
(define (proof-in-elim-form-to-args proof)
(case (tag proof)
((proof-in-imp-elim-form)
(append (proof-in-elim-form-to-args
(proof-in-imp-elim-form-to-op proof))
(list (proof-in-imp-elim-form-to-arg proof))))
((proof-in-impnc-elim-form)
(append (proof-in-elim-form-to-args
(proof-in-impnc-elim-form-to-op proof))
(list (proof-in-impnc-elim-form-to-arg proof))))
((proof-in-and-elim-left-form)
(append (proof-in-elim-form-to-args
(proof-in-and-elim-left-form-to-kernel proof))
(list 'left)))
((proof-in-and-elim-right-form)
(append (proof-in-elim-form-to-args
(proof-in-and-elim-right-form-to-kernel proof))
(list 'right)))
((proof-in-all-elim-form)
(append (proof-in-elim-form-to-args
(proof-in-all-elim-form-to-op proof))
(list (proof-in-all-elim-form-to-arg proof))))
((proof-in-allnc-elim-form)
(append (proof-in-elim-form-to-args
(proof-in-allnc-elim-form-to-op proof))
(list (proof-in-allnc-elim-form-to-arg proof))))
(else '())))
(define (proof-in-elim-form-to-final-op-and-args proof)
(case (tag proof)
((proof-in-imp-elim-form)
(append (proof-in-elim-form-to-final-op-and-args
(proof-in-imp-elim-form-to-op proof))
(list (proof-in-imp-elim-form-to-arg proof))))
((proof-in-impnc-elim-form)
(append (proof-in-elim-form-to-final-op-and-args
(proof-in-impnc-elim-form-to-op proof))
(list (proof-in-impnc-elim-form-to-arg proof))))
((proof-in-and-elim-left-form)
(append (proof-in-elim-form-to-final-op-and-args
(proof-in-and-elim-left-form-to-kernel proof))
(list 'left)))
((proof-in-and-elim-right-form)
(append (proof-in-elim-form-to-final-op-and-args
(proof-in-and-elim-right-form-to-kernel proof))
(list 'right)))
((proof-in-all-elim-form)
(append (proof-in-elim-form-to-final-op-and-args
(proof-in-all-elim-form-to-op proof))
(list (proof-in-all-elim-form-to-arg proof))))
((proof-in-allnc-elim-form)
(append (proof-in-elim-form-to-final-op-and-args
(proof-in-allnc-elim-form-to-op proof))
(list (proof-in-allnc-elim-form-to-arg proof))))
(else (list proof))))
; We need to generalize mk-proof-in-gen-elim-form, to also cover the
; case of Ex-Elim written in application notation.
(define (mk-proof-in-gen-elim-form proof . elim-items)
(if
(null? elim-items)
proof
(let ((formula (unfold-formula (proof-to-formula proof))))
(case (tag formula)
((atom predicate)
(myerror "mk-proof-in-gen-elim-form" "applicable formula expected"
formula))
((ex)
(let* ((side-premise (car elim-items))
(concl (imp-form-to-conclusion
(all-form-to-kernel
(proof-to-formula side-premise))))
(ex-elim-aconst
(ex-formula-and-concl-to-ex-elim-aconst formula concl))
(free (union (formula-to-free formula) (formula-to-free concl)))
(free-terms (map make-term-in-var-form free)))
(apply mk-proof-in-gen-elim-form
(cons (make-proof-in-aconst-form ex-elim-aconst)
(append free-terms elim-items)))))
((exnc)
(let* ((side-premise (car elim-items))
(concl (imp-form-to-conclusion
(all-form-to-kernel
(proof-to-formula side-premise))))
(exnc-elim-aconst
(exnc-formula-and-concl-to-exnc-elim-aconst formula concl))
(free (union (formula-to-free formula) (formula-to-free concl)))
(free-terms (map make-term-in-var-form free)))
(apply mk-proof-in-gen-elim-form
(cons (make-proof-in-aconst-form exnc-elim-aconst)
(append free-terms elim-items)))))
((imp)
(apply mk-proof-in-gen-elim-form
(cons (make-proof-in-imp-elim-form proof (car elim-items))
(cdr elim-items))))
((impnc)
(apply mk-proof-in-gen-elim-form
(cons (make-proof-in-impnc-elim-form proof (car elim-items))
(cdr elim-items))))
((and)
(cond ((eq? 'left (car elim-items))
(apply mk-proof-in-gen-elim-form
(cons (make-proof-in-and-elim-left-form proof)
(cdr elim-items))))
((eq? 'right (car elim-items))
(apply mk-proof-in-gen-elim-form
(cons (make-proof-in-and-elim-right-form proof)
(cdr elim-items))))
(else (myerror "mk-proof-in-gen-elim-form"
"left or right expected"
(car elim-items)))))
((all)
(if (term-form? (car elim-items))
(apply mk-proof-in-gen-elim-form
(cons (make-proof-in-all-elim-form proof (car elim-items))
(cdr elim-items)))
(myerror "mk-proof-in-gen-elim-form" "term expected"
(car elim-items))))
((allnc)
(if (term-form? (car elim-items))
(apply mk-proof-in-gen-elim-form
(cons (make-proof-in-allnc-elim-form proof (car elim-items))
(cdr elim-items)))
(myerror "mk-proof-in-gen-elim-form" "term expected"
(car elim-items))))
(else (myerror "mk-proof-in-gen-elim-form" "formula expected"
formula))))))
; We generalize proof-in-elim-form-to-final-op and
; proof-in-elim-form-to-args to treat Ex-Elim axioms as if they
; were rules in application notation.
(define (proof-in-gen-elim-form-to-final-op proof)
(case (tag proof)
((proof-in-imp-elim-form)
(let ((op (proof-in-imp-elim-form-to-op proof))
(arg (proof-in-imp-elim-form-to-arg proof)))
(if (and (proof-in-aconst-form? op)
(string=? "Ex-Elim" (aconst-to-name
(proof-in-aconst-form-to-aconst op))))
(proof-in-gen-elim-form-to-final-op arg)
(proof-in-gen-elim-form-to-final-op op))))
((proof-in-impnc-elim-form)
(let ((op (proof-in-impnc-elim-form-to-op proof))
(arg (proof-in-impnc-elim-form-to-arg proof)))
(if (and (proof-in-aconst-form? op)
(string=? "Ex-Elim" (aconst-to-name
(proof-in-aconst-form-to-aconst op))))
(proof-in-gen-elim-form-to-final-op arg)
(proof-in-gen-elim-form-to-final-op op))))
((proof-in-and-elim-left-form)
(let ((kernel (proof-in-and-elim-left-form-to-kernel proof)))
(proof-in-gen-elim-form-to-final-op kernel)))
((proof-in-and-elim-right-form)
(let ((kernel (proof-in-and-elim-right-form-to-kernel proof)))
(proof-in-gen-elim-form-to-final-op kernel)))
((proof-in-all-elim-form)
(let ((op (proof-in-all-elim-form-to-op proof)))
(proof-in-gen-elim-form-to-final-op op)))
((proof-in-allnc-elim-form)
(let ((op (proof-in-allnc-elim-form-to-op proof)))
(proof-in-gen-elim-form-to-final-op op)))
(else proof)))
(define (proof-in-gen-elim-form-to-args proof)
(case (tag proof)
((proof-in-imp-elim-form)
(let ((op (proof-in-imp-elim-form-to-op proof))
(arg (proof-in-imp-elim-form-to-arg proof)))
(if (and (proof-in-aconst-form? op)
(string=? "Ex-Elim" (aconst-to-name
(proof-in-aconst-form-to-aconst op))))
(proof-in-gen-elim-form-to-args arg)
(append (proof-in-gen-elim-form-to-args op) (list arg)))))
((proof-in-impnc-elim-form)
(let ((op (proof-in-impnc-elim-form-to-op proof))
(arg (proof-in-impnc-elim-form-to-arg proof)))
(if (and (proof-in-aconst-form? op)
(string=? "Ex-Elim" (aconst-to-name
(proof-in-aconst-form-to-aconst op))))
(proof-in-gen-elim-form-to-args arg)
(append (proof-in-gen-elim-form-to-args op) (list arg)))))
((proof-in-and-elim-left-form)
(append (proof-in-gen-elim-form-to-args
(proof-in-and-elim-left-form-to-kernel proof))
(list 'left)))
((proof-in-and-elim-right-form)
(append (proof-in-gen-elim-form-to-args
(proof-in-and-elim-right-form-to-kernel proof))
(list 'right)))
((proof-in-all-elim-form)
(append (proof-in-gen-elim-form-to-args
(proof-in-all-elim-form-to-op proof))
(list (proof-in-all-elim-form-to-arg proof))))
((proof-in-allnc-elim-form)
(append (proof-in-gen-elim-form-to-args
(proof-in-allnc-elim-form-to-op proof))
(list (proof-in-allnc-elim-form-to-arg proof))))
(else '())))
; Constructors, accessors and test for and introduction:
(define (make-proof-in-and-intro-form proof1 proof2)
(list 'proof-in-and-intro-form
(make-and (proof-to-formula proof1) (proof-to-formula proof2))
proof1
proof2))
(define proof-in-and-intro-form-to-left caddr)
(define proof-in-and-intro-form-to-right cadddr)
(define (proof-in-and-intro-form? proof)
(eq? 'proof-in-and-intro-form (tag proof)))
(define (mk-proof-in-and-intro-form proof . proofs)
(if
(null? proofs)
proof
(let ((last-proof (car (last-pair proofs)))
(init-proofs (reverse (cdr (reverse proofs)))))
(make-proof-in-and-intro-form
(apply mk-proof-in-and-intro-form (cons proof init-proofs))
last-proof))))
; Constructors, accessors and test for the left and right and elimination:
(define (make-proof-in-and-elim-left-form proof)
(let ((formula (proof-to-formula proof)))
(if (and-form? formula)
(list 'proof-in-and-elim-left-form
(and-form-to-left formula)
proof)
(myerror "make-proof-in-and-elim-left-form" "and form expected"
formula))))
(define proof-in-and-elim-left-form-to-kernel caddr)
(define (proof-in-and-elim-left-form? proof)
(eq? 'proof-in-and-elim-left-form (tag proof)))
(define (make-proof-in-and-elim-right-form proof)
(let ((formula (proof-to-formula proof)))
(if (and-form? formula)
(list 'proof-in-and-elim-right-form
(and-form-to-right formula)
proof)
(myerror "make-proof-in-and-elim-right-form" "and form expected"
formula))))
(define proof-in-and-elim-right-form-to-kernel caddr)
(define (proof-in-and-elim-right-form? proof)
(eq? 'proof-in-and-elim-right-form (tag proof)))
; Constructors, accessors and test for all introduction:
(define (make-proof-in-all-intro-form var proof)
(list 'proof-in-all-intro-form
(make-all var (proof-to-formula proof))
var
proof))
(define proof-in-all-intro-form-to-var caddr)
(define proof-in-all-intro-form-to-kernel cadddr)
(define (proof-in-all-intro-form? proof)
(eq? 'proof-in-all-intro-form (tag proof)))
; Constructors, accessors and test for all elimination:
(define (make-proof-in-all-elim-form proof term . conclusion)
(if (null? conclusion)
(let* ((formula (proof-to-formula proof))
(var (all-form-to-var formula))
(kernel (all-form-to-kernel formula)))
(list 'proof-in-all-elim-form
(if (and (term-in-var-form? term)
(equal? var (term-in-var-form-to-var term)))
kernel
(formula-subst kernel var term))
proof
term))
(list 'proof-in-all-elim-form
(car conclusion)
proof
term)))
(define proof-in-all-elim-form-to-op caddr)
(define proof-in-all-elim-form-to-arg cadddr)
(define (proof-in-all-elim-form? proof)
(eq? 'proof-in-all-elim-form (tag proof)))
(define (proof-to-final-all-elim-op proof)
(if (proof-in-all-elim-form? proof)
(proof-to-final-all-elim-op (proof-in-all-elim-form-to-op proof))
proof))
; Constructors, accessors and test for allnc introduction:
(define (make-proof-in-allnc-intro-form var proof)
(list 'proof-in-allnc-intro-form
(make-allnc var (proof-to-formula proof))
var
proof))
(define proof-in-allnc-intro-form-to-var caddr)
(define proof-in-allnc-intro-form-to-kernel cadddr)
(define (proof-in-allnc-intro-form? proof)
(eq? 'proof-in-allnc-intro-form (tag proof)))
; Constructors, accessors and test for allnc-elimination:
(define (make-proof-in-allnc-elim-form proof term . conclusion)
(if (null? conclusion)
(let* ((formula (proof-to-formula proof))
(var (allnc-form-to-var formula))
(kernel (allnc-form-to-kernel formula)))
(list 'proof-in-allnc-elim-form
(if (and (term-in-var-form? term)
(equal? var (term-in-var-form-to-var term)))
kernel
(formula-subst kernel var term))
proof
term))
(list 'proof-in-allnc-elim-form
(car conclusion)
proof
term)))
(define proof-in-allnc-elim-form-to-op caddr)
(define proof-in-allnc-elim-form-to-arg cadddr)
(define (proof-in-allnc-elim-form? proof)
(eq? 'proof-in-allnc-elim-form (tag proof)))
(define (proof-to-final-allnc-elim-op proof)
(if (proof-in-allnc-elim-form? proof)
(proof-to-final-allnc-elim-op (proof-in-allnc-elim-form-to-op proof))
proof))
(define (proof-to-final-allnc-elim-op-and-args proof)
(if (proof-in-allnc-elim-form? proof)
(let* ((op (proof-in-allnc-elim-form-to-op proof))
(arg (proof-in-allnc-elim-form-to-arg proof))
(prev (proof-to-final-allnc-elim-op-and-args op)))
(cons (car prev) (append (cdr prev) (list arg))))
(list proof)))
; Sometimes it is useful to have a replacement to the ex-intro rule:
(define (make-proof-in-ex-intro-form term ex-formula proof-of-inst)
(let* ((var (ex-form-to-var ex-formula))
(kernel (ex-form-to-kernel ex-formula))
(free (formula-to-free ex-formula)))
(apply mk-proof-in-elim-form
(append (list (make-proof-in-aconst-form
(ex-formula-to-ex-intro-aconst ex-formula)))
(map make-term-in-var-form free)
(list term proof-of-inst)))))
(define (mk-proof-in-ex-intro-form . terms-and-ex-formula-and-proof-of-inst)
(let* ((revargs (reverse terms-and-ex-formula-and-proof-of-inst))
(proof-of-inst
(if (pair? revargs)
(car revargs)
(myerror "mk-proof-in-ex-intro-form" "arguments expected")))
(ex-formula
(if (pair? (cdr revargs))
(cadr revargs)
(myerror "mk-proof-in-ex-intro-form" ">= 2 arguments expected"
terms-and-ex-formula-and-proof-of-inst)))
(terms (reverse (cddr revargs))))
(if
(null? terms)
proof-of-inst
(let* ((var (ex-form-to-var ex-formula))
(kernel (ex-form-to-kernel ex-formula))
(free (formula-to-free ex-formula))
(prev (apply mk-proof-in-ex-intro-form
(append (cdr terms)
(list (formula-subst kernel var (car terms))
proof-of-inst)))))
(apply mk-proof-in-elim-form
(append (list (make-proof-in-aconst-form
(ex-formula-to-ex-intro-aconst ex-formula)))
(map make-term-in-var-form free)
(list (car terms) prev)))))))
(define (proof-in-ind-rule-form? proof)
(let ((final-imp-op (proof-to-final-imp-elim-op proof))
(arglength (length (proof-to-imp-elim-args proof))))
(and
(proof-in-all-elim-form? final-imp-op)
(let ((final-op (proof-to-final-allnc-elim-op
(proof-in-all-elim-form-to-op final-imp-op))))
(and (proof-in-aconst-form? final-op)
(string=? "Ind" (aconst-to-name
(proof-in-aconst-form-to-aconst final-op)))
(let* ((uninst-kernel (all-form-to-kernel
(aconst-to-uninst-formula
(proof-in-aconst-form-to-aconst
final-op))))
(indlength (length (imp-form-to-premises uninst-kernel))))
(= indlength arglength)))))))
(define (proof-in-cases-rule-form? proof)
(let ((final-imp-op (proof-to-final-imp-elim-op proof))
(arglength (length (proof-to-imp-elim-args proof))))
(and
(proof-in-all-elim-form? final-imp-op)
(let ((final-op (proof-to-final-allnc-elim-op
(proof-in-all-elim-form-to-op final-imp-op))))
(and (proof-in-aconst-form? final-op)
(string=? "Cases" (aconst-to-name
(proof-in-aconst-form-to-aconst final-op)))
(let* ((uninst-kernel (all-form-to-kernel
(aconst-to-uninst-formula
(proof-in-aconst-form-to-aconst
final-op))))
(caseslength (length (imp-form-to-premises uninst-kernel))))
(= caseslength arglength)))))))
(define (proof-in-ex-elim-rule-form? proof)
(and (proof-in-imp-elim-form? proof)
(let ((op1 (proof-in-imp-elim-form-to-op proof))
(arg1 (proof-in-imp-elim-form-to-arg proof)))
(and (all-form? (proof-to-formula arg1))
(proof-in-imp-elim-form? op1)
(let ((op2 (proof-in-imp-elim-form-to-op op1))
(arg2 (proof-in-imp-elim-form-to-arg op1)))
(and (ex-form? (proof-to-formula arg2))
(let ((final-op (proof-to-final-allnc-elim-op op2)))
(and (proof-in-aconst-form? final-op)
(string=? "Ex-Elim"
(aconst-to-name
(proof-in-aconst-form-to-aconst
final-op)))))))))))
(define (proof-in-exnc-elim-rule-form? proof)
(and (proof-in-imp-elim-form? proof)
(let ((op1 (proof-in-imp-elim-form-to-op proof))
(arg1 (proof-in-imp-elim-form-to-arg proof)))
(and (allnc-form? (proof-to-formula arg1))
(proof-in-imp-elim-form? op1)
(let ((op2 (proof-in-imp-elim-form-to-op op1))
(arg2 (proof-in-imp-elim-form-to-arg op1)))
(and (exnc-form? (proof-to-formula arg2))
(let ((final-op (proof-to-final-allnc-elim-op op2)))
(and (proof-in-aconst-form? final-op)
(string=? "Exnc-Elim"
(aconst-to-name
(proof-in-aconst-form-to-aconst
final-op)))))))))))
; Sometimes it is useful to have a replacement to the exnc-intro rule:
(define (make-proof-in-exnc-intro-form term exnc-formula proof-of-inst)
(let* ((var (exnc-form-to-var exnc-formula))
(kernel (exnc-form-to-kernel exnc-formula))
(free (formula-to-free exnc-formula)))
(apply mk-proof-in-elim-form
(append (list (make-proof-in-aconst-form
(exnc-formula-to-exnc-intro-aconst exnc-formula)))
(map make-term-in-var-form free)
(list term proof-of-inst)))))
(define (mk-proof-in-exnc-intro-form .
terms-and-exnc-formula-and-proof-of-inst)
(let* ((revargs (reverse terms-and-exnc-formula-and-proof-of-inst))
(proof-of-inst
(if (pair? revargs)
(car revargs)
(myerror "mk-proof-in-exnc-intro-form" "arguments expected")))
(exnc-formula
(if (pair? (cdr revargs))
(cadr revargs)
(myerror "mk-proof-in-exnc-intro-form" ">= 2 arguments expected"
terms-and-exnc-formula-and-proof-of-inst)))
(terms (reverse (cddr revargs))))
(if
(null? terms)
proof-of-inst
(let* ((var (exnc-form-to-var exnc-formula))
(kernel (exnc-form-to-kernel exnc-formula))
(free (formula-to-free exnc-formula))
(prev (apply mk-proof-in-exnc-intro-form
(append (cdr terms)
(list (formula-subst kernel var (car terms))
proof-of-inst)))))
(apply mk-proof-in-elim-form
(append (list (make-proof-in-aconst-form
(exnc-formula-to-exnc-intro-aconst exnc-formula)))
(map make-term-in-var-form free)
(list (car terms) prev)))))))
(define (proof-form? x)
(and (pair? x)
(memq (tag x) '(proof-in-avar-form
proof-in-aconst-form
proof-in-imp-intro-form
proof-in-imp-elim-form
proof-in-impnc-intro-form
proof-in-impnc-elim-form
proof-in-and-intro-form
proof-in-and-elim-left-form
proof-in-and-elim-right-form
proof-in-all-intro-form
proof-in-all-elim-form
proof-in-allnc-intro-form
proof-in-allnc-elim-form))))
; To define alpha-equality for proofs we use (following Robert Staerk)
; an auxiliary function (corr x y alist alistrev). Here
; alist = ((u1 v1) ... (un vn)), alistrev = ((v1 u1) ... (vn un)).
; (corr-avar x y alist alistrev) iff one of the following holds.
; 1. There is a first entry (x v) of the form (x _) in alist
; and a first entry (y u) of the form (y _) in alistrev,
; and we have v=y and u=x.
; 2. There is no entry of the form (x _) in alist
; and no entry of the form (y _) in alistrev,
; and we have x=y.
(define (corr-avar x y alist alistrev)
(let ((info-x (assoc-wrt avar-form? x alist))
(info-y (assoc-wrt avar-form? y alistrev)))
(if info-x
(and (avar=? (car info-x) (cadr info-y))
(avar=? (car info-y) (cadr info-x)))
(and (not info-y) (avar=? x y)))))
(define (proof=? proof1 proof2)
(proof=-aux? proof1 proof2 '() '()))
(define (proofs=? proofs1 proofs2)
(proofs=-aux? proofs1 proofs2 '() '()))
(define (proof=-aux? proof1 proof2 alist alistrev)
(or (and (proof-in-avar-form? proof1) (proof-in-avar-form? proof2)
(corr (proof-in-avar-form-to-avar proof1)
(proof-in-avar-form-to-avar proof2)
alist alistrev))
(and (proof-in-aconst-form? proof1) (proof-in-aconst-form? proof2)
(aconst=? (proof-in-aconst-form-to-aconst proof1)
(proof-in-aconst-form-to-aconst proof2)))
(and (proof-in-imp-intro-form? proof1) (proof-in-imp-intro-form? proof2)
(let ((avar1 (proof-in-imp-intro-form-to-avar proof1))
(avar2 (proof-in-imp-intro-form-to-avar proof2))
(kernel1 (proof-in-imp-intro-form-to-kernel proof1))
(kernel2 (proof-in-imp-intro-form-to-kernel proof2)))
(proof=-aux? kernel1 kernel2
(cons (list avar1 avar2) alist)
(cons (list avar2 avar1) alistrev))))
(and (proof-in-imp-elim-form? proof1) (proof-in-imp-elim-form? proof2)
(let ((op1 (proof-in-imp-elim-form-to-op proof1))
(op2 (proof-in-imp-elim-form-to-op proof2))
(arg1 (proof-in-imp-elim-form-to-arg proof1))
(arg2 (proof-in-imp-elim-form-to-arg proof2)))
(and (proof=-aux? op1 op2 alist alistrev)
(proof=-aux? arg1 arg2 alist alistrev))))
(and (proof-in-impnc-intro-form? proof1)
(proof-in-impnc-intro-form? proof2)
(let ((avar1 (proof-in-impnc-intro-form-to-avar proof1))
(avar2 (proof-in-impnc-intro-form-to-avar proof2))
(kernel1 (proof-in-impnc-intro-form-to-kernel proof1))
(kernel2 (proof-in-impnc-intro-form-to-kernel proof2)))
(proof=-aux? kernel1 kernel2
(cons (list avar1 avar2) alist)
(cons (list avar2 avar1) alistrev))))
(and (proof-in-impnc-elim-form? proof1)
(proof-in-impnc-elim-form? proof2)
(let ((op1 (proof-in-impnc-elim-form-to-op proof1))
(op2 (proof-in-impnc-elim-form-to-op proof2))
(arg1 (proof-in-impnc-elim-form-to-arg proof1))
(arg2 (proof-in-impnc-elim-form-to-arg proof2)))
(and (proof=-aux? op1 op2 alist alistrev)
(proof=-aux? arg1 arg2 alist alistrev))))
(and (proof-in-and-intro-form? proof1) (proof-in-and-intro-form? proof2)
(let ((left1 (proof-in-and-intro-form-to-left proof1))
(left2 (proof-in-and-intro-form-to-left proof2))
(right1 (proof-in-and-intro-form-to-right proof1))
(right2 (proof-in-and-intro-form-to-right proof2)))
(and (proof=-aux? left1 left2 alist alistrev)
(proof=-aux? right1 right2 alist alistrev))))
(and (proof-in-and-elim-left-form? proof1)
(proof-in-and-elim-left-form? proof2)
(let ((kernel1 (proof-in-and-elim-left-form-to-kernel proof1))
(kernel2 (proof-in-and-elim-left-form-to-kernel proof2)))
(proof=-aux? kernel1 kernel2 alist alistrev)))
(and (proof-in-and-elim-right-form? proof1)
(proof-in-and-elim-right-form? proof2)
(let ((kernel1 (proof-in-and-elim-right-form-to-kernel proof1))
(kernel2 (proof-in-and-elim-right-form-to-kernel proof2)))
(proof=-aux? kernel1 kernel2 alist alistrev)))
(and (proof-in-all-intro-form? proof1) (proof-in-all-intro-form? proof2)
(let ((var1 (proof-in-all-intro-form-to-var proof1))
(var2 (proof-in-all-intro-form-to-var proof2))
(kernel1 (proof-in-all-intro-form-to-kernel proof1))
(kernel2 (proof-in-all-intro-form-to-kernel proof2)))
(proof=-aux? kernel1 kernel2
(cons (list var1 var2) alist)
(cons (list var2 var1) alistrev))))
(and (proof-in-all-elim-form? proof1) (proof-in-all-elim-form? proof2)
(let ((op1 (proof-in-all-elim-form-to-op proof1))
(op2 (proof-in-all-elim-form-to-op proof2))
(arg1 (proof-in-all-elim-form-to-arg proof1))
(arg2 (proof-in-all-elim-form-to-arg proof2)))
(and (proof=-aux? op1 op2 alist alistrev)
(term=-aux? arg1 arg2 alist alistrev))))
(and (proof-in-allnc-intro-form? proof1)
(proof-in-allnc-intro-form? proof2)
(let ((var1 (proof-in-allnc-intro-form-to-var proof1))
(var2 (proof-in-allnc-intro-form-to-var proof2))
(kernel1 (proof-in-allnc-intro-form-to-kernel proof1))
(kernel2 (proof-in-allnc-intro-form-to-kernel proof2)))
(proof=-aux? kernel1 kernel2
(cons (list var1 var2) alist)
(cons (list var2 var1) alistrev))))
(and (proof-in-allnc-elim-form? proof1)
(proof-in-allnc-elim-form? proof2)
(let ((op1 (proof-in-allnc-elim-form-to-op proof1))
(op2 (proof-in-allnc-elim-form-to-op proof2))
(arg1 (proof-in-allnc-elim-form-to-arg proof1))
(arg2 (proof-in-allnc-elim-form-to-arg proof2)))
(and (proof=-aux? op1 op2 alist alistrev)
(term=-aux? arg1 arg2 alist alistrev))))))
(define (proofs=-aux? proofs1 proofs2 alist alistrev)
(or (and (null? proofs1) (null? proofs2))
(and (proof=-aux? (car proofs1) (car proofs2) alist alistrev)
(proofs=-aux? (cdr proofs1) (cdr proofs2) alist alistrev))))
; For efficiency reasons (when working with goal in interactive proof
; development) it will be useful to optionally allow the context in a
; proof.
(define (proof-with-context? proof)
(case (tag proof)
((proof-in-avar-form
proof-in-aconst-form
proof-in-and-elim-left-form
proof-in-and-elim-right-form)
(pair? (cdddr proof)))
((proof-in-imp-intro-form
proof-in-imp-elim-form
proof-in-impnc-intro-form
proof-in-impnc-elim-form
proof-in-and-intro-form
proof-in-all-intro-form
proof-in-all-elim-form
proof-in-allnc-intro-form
proof-in-allnc-elim-form)
(pair? (cddddr proof)))
(else (myerror "proof-with-context?" "proof tag expected" (tag proof)))))
(define (proof-with-context-to-context proof)
(case (tag proof)
((proof-in-avar-form
proof-in-aconst-form
proof-in-and-elim-left-form
proof-in-and-elim-right-form)
(car (cdddr proof)))
((proof-in-imp-intro-form
proof-in-imp-elim-form
proof-in-impnc-intro-form
proof-in-impnc-elim-form
proof-in-and-intro-form
proof-in-all-intro-form
proof-in-all-elim-form
proof-in-allnc-intro-form
proof-in-allnc-elim-form)
(car (cddddr proof)))
(else (myerror "proof-with-context-to-context" "proof tag expected"
(tag proof)))))
(define (context-item=? x y)
(or (and (var-form? x) (var-form? y) (equal? x y))
(and (avar-form? x) (avar-form? y) (avar=? x y))))
(define (proof-to-context proof)
(if
(proof-with-context? proof)
(proof-with-context-to-context proof)
(case (tag proof)
((proof-in-avar-form)
(let ((avar (proof-in-avar-form-to-avar proof)))
(append (formula-to-free (avar-to-formula avar)) (list avar))))
((proof-in-aconst-form) '())
((proof-in-imp-intro-form)
(let* ((avar (proof-in-imp-intro-form-to-avar proof))
(kernel (proof-in-imp-intro-form-to-kernel proof))
(context (proof-to-context kernel)))
(remove-wrt avar=? avar context)))
((proof-in-imp-elim-form)
(let ((context1 (proof-to-context (proof-in-imp-elim-form-to-op proof)))
(context2 (proof-to-context
(proof-in-imp-elim-form-to-arg proof))))
(union-wrt context-item=? context1 context2)))
((proof-in-impnc-intro-form)
(let* ((avar (proof-in-impnc-intro-form-to-avar proof))
(kernel (proof-in-impnc-intro-form-to-kernel proof))
(context (proof-to-context kernel)))
(remove-wrt avar=? avar context)))
((proof-in-impnc-elim-form)
(let ((context1
(proof-to-context (proof-in-impnc-elim-form-to-op proof)))
(context2
(proof-to-context (proof-in-impnc-elim-form-to-arg proof))))
(union-wrt context-item=? context1 context2)))
((proof-in-and-intro-form)
(union-wrt context-item=?
(proof-to-context (proof-in-and-intro-form-to-left proof))
(proof-to-context (proof-in-and-intro-form-to-right proof))))
((proof-in-and-elim-left-form)
(proof-to-context (proof-in-and-elim-left-form-to-kernel proof)))
((proof-in-and-elim-right-form)
(proof-to-context (proof-in-and-elim-right-form-to-kernel proof)))
((proof-in-all-intro-form)
(let* ((var (proof-in-all-intro-form-to-var proof))
(kernel (proof-in-all-intro-form-to-kernel proof))
(context (proof-to-context kernel)))
(remove var context)))
((proof-in-all-elim-form)
(let ((context (proof-to-context (proof-in-all-elim-form-to-op proof)))
(free (term-to-free (proof-in-all-elim-form-to-arg proof))))
(union context free)))
((proof-in-allnc-intro-form)
(let* ((var (proof-in-allnc-intro-form-to-var proof))
(kernel (proof-in-allnc-intro-form-to-kernel proof))
(context (proof-to-context kernel)))
(remove var context)))
((proof-in-allnc-elim-form)
(let ((context (proof-to-context (proof-in-allnc-elim-form-to-op proof)))
(free (term-to-free (proof-in-allnc-elim-form-to-arg proof))))
(union context free)))
(else (myerror "proof-to-context" "proof tag expected" (tag proof))))))
(define (proof-to-context-wrt avar-eq proof)
(case (tag proof)
((proof-in-avar-form)
(let ((avar (proof-in-avar-form-to-avar proof)))
(append (formula-to-free (avar-to-formula avar)) (list avar))))
((proof-in-aconst-form) '())
((proof-in-imp-intro-form)
(let* ((avar (proof-in-imp-intro-form-to-avar proof))
(kernel (proof-in-imp-intro-form-to-kernel proof))
(context (proof-to-context-wrt avar-eq kernel)))
(remove-wrt avar-eq avar context)))
((proof-in-imp-elim-form)
(let ((context1 (proof-to-context-wrt
avar-eq (proof-in-imp-elim-form-to-op proof)))
(context2 (proof-to-context-wrt
avar-eq (proof-in-imp-elim-form-to-arg proof))))
(union-wrt context-item-full=? context1 context2)))
((proof-in-impnc-intro-form)
(let* ((avar (proof-in-impnc-intro-form-to-avar proof))
(kernel (proof-in-impnc-intro-form-to-kernel proof))
(context (proof-to-context-wrt avar-eq kernel)))
(remove-wrt avar-eq avar context)))
((proof-in-impnc-elim-form)
(let ((context1 (proof-to-context-wrt
avar-eq (proof-in-impnc-elim-form-to-op proof)))
(context2 (proof-to-context-wrt
avar-eq (proof-in-impnc-elim-form-to-arg proof))))
(union-wrt context-item-full=? context1 context2)))
((proof-in-and-intro-form)
(union-wrt context-item-full=?
(proof-to-context-wrt
avar-eq (proof-in-and-intro-form-to-left proof))
(proof-to-context-wrt
avar-eq (proof-in-and-intro-form-to-right proof))))
((proof-in-and-elim-left-form)
(proof-to-context-wrt
avar-eq (proof-in-and-elim-left-form-to-kernel proof)))
((proof-in-and-elim-right-form)
(proof-to-context-wrt
avar-eq (proof-in-and-elim-right-form-to-kernel proof)))
((proof-in-all-intro-form)
(let* ((var (proof-in-all-intro-form-to-var proof))
(kernel (proof-in-all-intro-form-to-kernel proof))
(context (proof-to-context-wrt avar-eq kernel)))
(remove var context)))
((proof-in-all-elim-form)
(let ((context (proof-to-context-wrt
avar-eq (proof-in-all-elim-form-to-op proof)))
(free (term-to-free (proof-in-all-elim-form-to-arg proof))))
(union context free)))
((proof-in-allnc-intro-form)
(let* ((var (proof-in-allnc-intro-form-to-var proof))
(kernel (proof-in-allnc-intro-form-to-kernel proof))
(context (proof-to-context-wrt avar-eq kernel)))
(remove var context)))
((proof-in-allnc-elim-form)
(let ((context (proof-to-context-wrt
avar-eq (proof-in-allnc-elim-form-to-op proof)))
(free (term-to-free (proof-in-allnc-elim-form-to-arg proof))))
(union context free)))
(else (myerror "proof-to-context-wrt" "proof tag expected"
(tag proof)))))
(define (context-to-vars context)
(do ((l context (cdr l))
(res '() (if (avar-form? (car l)) res (cons (car l) res))))
((null? l) (reverse res))))
(define (context-to-avars context)
(do ((l context (cdr l))
(res '() (if (avar-form? (car l)) (cons (car l) res) res)))
((null? l) (reverse res))))
(define (context=? context1 context2)
(if (= (length context1) (length context2))
(let context=?-aux ((c1 context1) (c2 context2))
(if (null? c1)
#t
(let ((x1 (car c1))
(rest1 (cdr c1))
(x2 (car c2))
(rest2 (cdr c2)))
(if (context-item=? x1 x2)
(context=?-aux rest1 rest2)
#f))))
#f))
(define (context-item-full=? x y)
(or (and (var-form? x) (var-form? y) (equal? x y))
(and (avar-form? x) (avar-form? y) (avar-full=? x y))))
(define (context-full=? context1 context2)
(and (null? (context-fullminus context1 context2))
(null? (context-fullminus context2 context1))))
(define (context-fullminus context1 context2)
(do ((l context2 (cdr l))
(res context1 (remove-wrt context-item-full=? (car l) res)))
((null? l) res)))
(define (pp-context context)
(do ((c context (cdr c))
(i 1 (if (avar-form? (car c)) (+ 1 i) i))
(line "" line))
((null? c) (if (> (string-length line) 0)
(begin (display-comment line) (newline))))
(if (avar-form? (car c))
(let* ((string (string-append (avar-to-name (car c)) "_"
(number-to-string i))))
(set! line (string-append line " " string ":"))
(if (> (* 3 (string-length line)) pp-width)
(begin
(display-comment line)
(newline)
(set! line " ")))
(set! line (string-append
line
(pretty-print-string
(string-length line)
(- pp-width (string-length COMMENT-STRING))
(fold-formula (avar-to-formula (car c))))))
(if (pair? (cdr c))
(begin (display-comment line) (newline)
(set! line ""))))
(let* ((var (car c))
(varstring (var-to-string var)))
(set! line (string-append line " " varstring))))))
; We use acproof to mean proof-with-avar-contexts. An acproof is a
; proof in the sense of check-and-display-proof. It is used to avoid
; recomputation of avar-contexts when pruning.
(define (make-acproof-in-avar-form avar)
(list 'proof-in-avar-form (avar-to-formula avar) avar (list avar)))
(define (make-acproof-in-aconst-form aconst)
(list 'proof-in-aconst-form (aconst-to-formula aconst) aconst '()))
(define (make-acproof-in-imp-intro-form avar proof)
(list 'proof-in-imp-intro-form
(make-imp (avar-to-formula avar) (proof-to-formula proof))
avar
proof
(remove-wrt avar=? avar (proof-with-context-to-context proof))))
(define (make-acproof-in-imp-elim-form proof1 proof2)
(list 'proof-in-imp-elim-form
(imp-form-to-conclusion (proof-to-formula proof1))
proof1
proof2
(union-wrt avar=?
(proof-to-context proof1) (proof-to-context proof2))))
(define (make-acproof-in-impnc-intro-form avar proof)
(list 'proof-in-impnc-intro-form
(make-impnc (avar-to-formula avar) (proof-to-formula proof))
avar
proof
(remove-wrt avar=? avar (proof-with-context-to-context proof))))
(define (make-acproof-in-impnc-elim-form proof1 proof2)
(list 'proof-in-impnc-elim-form
(impnc-form-to-conclusion (proof-to-formula proof1))
proof1
proof2
(union-wrt avar=?
(proof-to-context proof1) (proof-to-context proof2))))
(define (make-acproof-in-and-intro-form proof1 proof2)
(list 'proof-in-and-intro-form
(make-and (proof-to-formula proof1) (proof-to-formula proof2))
proof1
proof2
(union-wrt avar=?
(proof-to-context proof1) (proof-to-context proof2))))
(define (make-acproof-in-and-elim-left-form proof)
(let ((formula (proof-to-formula proof)))
(if (and-form? formula)
(list 'proof-in-and-elim-left-form
(and-form-to-left formula)
proof
(proof-to-context proof))
(myerror "make-acproof-in-and-elim-left-form" "and form expected"
formula))))
(define (make-acproof-in-and-elim-right-form proof)
(let ((formula (proof-to-formula proof)))
(if (and-form? formula)
(list 'proof-in-and-elim-right-form
(and-form-to-right formula)
proof
(proof-to-context proof))
(myerror "make-acproof-in-and-elim-right-form" "and form expected"
formula))))
(define (make-acproof-in-all-intro-form var proof)
(list 'proof-in-all-intro-form
(make-all var (proof-to-formula proof))
var
proof
(proof-to-context proof)))
(define (make-acproof-in-all-elim-form proof term . conclusion)
(if (null? conclusion)
(let* ((formula (proof-to-formula proof))
(var (all-form-to-var formula))
(kernel (all-form-to-kernel formula)))
(list 'proof-in-all-elim-form
(if (and (term-in-var-form? term)
(equal? var (term-in-var-form-to-var term)))
kernel
(formula-subst kernel var term))
proof
term
(proof-to-context proof)))
(list 'proof-in-all-elim-form
(car conclusion)
proof
term
(proof-to-context proof))))
(define (make-acproof-in-allnc-intro-form var proof)
(list 'proof-in-allnc-intro-form
(make-allnc var (proof-to-formula proof))
var
proof
(proof-to-context proof)))
(define (make-acproof-in-allnc-elim-form proof term . conclusion)
(if (null? conclusion)
(let* ((formula (proof-to-formula proof))
(var (allnc-form-to-var formula))
(kernel (allnc-form-to-kernel formula)))
(list 'proof-in-allnc-elim-form
(if (and (term-in-var-form? term)
(equal? var (term-in-var-form-to-var term)))
kernel
(formula-subst kernel var term))
proof
term
(proof-to-context proof)))
(list 'proof-in-allnc-elim-form
(car conclusion)
proof
term
(proof-to-context proof))))
(define (proof-to-acproof proof)
(case (tag proof)
((proof-in-avar-form)
(let ((avar (proof-in-avar-form-to-avar proof)))
(make-acproof-in-avar-form avar)))
((proof-in-aconst-form)
(let ((aconst (proof-in-aconst-form-to-aconst proof)))
(make-acproof-in-aconst-form aconst)))
((proof-in-imp-intro-form)
(let* ((avar (proof-in-imp-intro-form-to-avar proof))
(kernel (proof-in-imp-intro-form-to-kernel proof))
(prev (proof-to-acproof kernel)))
(make-acproof-in-imp-intro-form avar prev)))
((proof-in-imp-elim-form)
(let* ((op (proof-in-imp-elim-form-to-op proof))
(arg (proof-in-imp-elim-form-to-arg proof))
(prev1 (proof-to-acproof op))
(prev2 (proof-to-acproof arg)))
(make-acproof-in-imp-elim-form prev1 prev2)))
((proof-in-impnc-intro-form)
(let* ((avar (proof-in-impnc-intro-form-to-avar proof))
(kernel (proof-in-impnc-intro-form-to-kernel proof))
(prev (proof-to-acproof kernel)))
(make-acproof-in-impnc-intro-form avar prev)))
((proof-in-impnc-elim-form)
(let* ((op (proof-in-impnc-elim-form-to-op proof))
(arg (proof-in-impnc-elim-form-to-arg proof))
(prev1 (proof-to-acproof op))
(prev2 (proof-to-acproof arg)))
(make-acproof-in-impnc-elim-form prev1 prev2)))
((proof-in-and-intro-form)
(let* ((left (proof-in-and-intro-form-to-left proof))
(right (proof-in-and-intro-form-to-right proof))
(prev1 (proof-to-acproof left))
(prev2 (proof-to-acproof right)))
(make-acproof-in-and-intro-form prev1 prev2)))
((proof-in-and-elim-left-form)
(let* ((kernel (proof-in-and-elim-left-form-to-kernel proof))
(prev (proof-to-acproof kernel)))
(make-acproof-in-and-elim-left-form prev)))
((proof-in-and-elim-right-form)
(let* ((kernel (proof-in-and-elim-right-form-to-kernel proof))
(prev (proof-to-acproof kernel)))
(make-acproof-in-and-elim-right-form prev)))
((proof-in-all-intro-form)
(let* ((var (proof-in-all-intro-form-to-var proof))
(kernel (proof-in-all-intro-form-to-kernel proof))
(prev (proof-to-acproof kernel)))
(make-acproof-in-all-intro-form var prev)))
((proof-in-all-elim-form)
(let* ((op (proof-in-all-elim-form-to-op proof))
(prev (proof-to-acproof op))
(arg (proof-in-all-elim-form-to-arg proof))
(conclusion (proof-to-formula proof)))
(make-acproof-in-all-elim-form prev arg conclusion)))
((proof-in-allnc-intro-form)
(let* ((var (proof-in-allnc-intro-form-to-var proof))
(kernel (proof-in-allnc-intro-form-to-kernel proof))
(prev (proof-to-acproof kernel)))
(make-acproof-in-allnc-intro-form var prev)))
((proof-in-allnc-elim-form)
(let* ((op (proof-in-allnc-elim-form-to-op proof))
(prev (proof-to-acproof op))
(arg (proof-in-allnc-elim-form-to-arg proof))
(conclusion (proof-to-formula proof)))
(make-acproof-in-allnc-elim-form prev arg conclusion)))
(else (myerror "proof-to-acproof" "proof tag expected" (tag proof)))))
; The variable condition for allnc refers to the computational variables.
(define (proof-to-cvars proof)
(if (formula-of-nulltype? (proof-to-formula proof))
'()
(proof-to-cvars-aux proof)))
; In proof-to-cvars-aux we can assume that the proved formula has
; computational content.
(define (proof-to-cvars-aux proof)
(case (tag proof)
((proof-in-avar-form) (list (proof-in-avar-form-to-avar proof)))
((proof-in-aconst-form) '())
((proof-in-imp-intro-form)
(remove-wrt avar=? (proof-in-imp-intro-form-to-avar proof)
(proof-to-cvars-aux
(proof-in-imp-intro-form-to-kernel proof))))
((proof-in-imp-elim-form)
(let* ((op (proof-in-imp-elim-form-to-op proof))
(arg (proof-in-imp-elim-form-to-arg proof))
(prevop (proof-to-cvars-aux op))
(prevarg (proof-to-cvars arg)))
(union prevop prevarg)))
((proof-in-impnc-intro-form)
(proof-to-cvars-aux (proof-in-impnc-intro-form-to-kernel proof)))
((proof-in-impnc-elim-form)
(proof-to-cvars-aux (proof-in-impnc-elim-form-to-op proof)))
((proof-in-and-intro-form)
(let* ((left (proof-in-and-intro-form-to-left proof))
(right (proof-in-and-intro-form-to-right proof)))
(if (formula-of-nulltype? (proof-to-formula left))
(proof-to-cvars-aux right)
(union (proof-to-cvars-aux left)
(proof-to-cvars right)))))
((proof-in-and-elim-left-form)
(proof-to-cvars-aux
(proof-in-and-elim-left-form-to-kernel proof)))
((proof-in-and-elim-right-form)
(proof-to-cvars-aux
(proof-in-and-elim-right-form-to-kernel proof)))
((proof-in-all-intro-form)
(remove (proof-in-all-intro-form-to-var proof)
(proof-to-cvars-aux
(proof-in-all-intro-form-to-kernel proof))))
((proof-in-all-elim-form)
(let* ((op (proof-in-all-elim-form-to-op proof))
(arg (proof-in-all-elim-form-to-arg proof))
(prev (proof-to-cvars-aux op)))
(union prev (term-to-free arg))))
((proof-in-allnc-intro-form)
(proof-to-cvars-aux
(proof-in-allnc-intro-form-to-kernel proof)))
((proof-in-allnc-elim-form)
(proof-to-cvars-aux
(proof-in-allnc-elim-form-to-op proof)))
(else (myerror "proof-to-cvars" "proof tag expected" (tag proof)))))
(define (proof-to-free proof)
(case (tag proof)
((proof-in-avar-form)
(formula-to-free (proof-to-formula proof)))
((proof-in-aconst-form) '())
((proof-in-imp-intro-form)
(let ((free1 (formula-to-free
(avar-to-formula (proof-in-imp-intro-form-to-avar proof))))
(free2 (proof-to-free (proof-in-imp-intro-form-to-kernel proof))))
(union free1 free2)))
((proof-in-imp-elim-form)
(union (proof-to-free (proof-in-imp-elim-form-to-op proof))
(proof-to-free (proof-in-imp-elim-form-to-arg proof))))
((proof-in-impnc-intro-form)
(let ((free1 (formula-to-free
(avar-to-formula
(proof-in-impnc-intro-form-to-avar proof))))
(free2 (proof-to-free (proof-in-impnc-intro-form-to-kernel proof))))
(union free1 free2)))
((proof-in-impnc-elim-form)
(union (proof-to-free (proof-in-impnc-elim-form-to-op proof))
(proof-to-free (proof-in-impnc-elim-form-to-arg proof))))
((proof-in-and-intro-form)
(union (proof-to-free (proof-in-and-intro-form-to-left proof))
(proof-to-free (proof-in-and-intro-form-to-right proof))))
((proof-in-and-elim-left-form)
(proof-to-free (proof-in-and-elim-left-form-to-kernel proof)))
((proof-in-and-elim-right-form)
(proof-to-free (proof-in-and-elim-right-form-to-kernel proof)))
((proof-in-all-intro-form)
(remove (proof-in-all-intro-form-to-var proof)
(proof-to-free (proof-in-all-intro-form-to-kernel proof))))
((proof-in-all-elim-form)
(union (proof-to-free (proof-in-all-elim-form-to-op proof))
(term-to-free (proof-in-all-elim-form-to-arg proof))))
((proof-in-allnc-intro-form)
(remove (proof-in-allnc-intro-form-to-var proof)
(proof-to-free (proof-in-allnc-intro-form-to-kernel proof))))
((proof-in-allnc-elim-form)
(union (proof-to-free (proof-in-allnc-elim-form-to-op proof))
(term-to-free (proof-in-allnc-elim-form-to-arg proof))))
(else (myerror "proof-to-free" "proof tag expected" (tag proof)))))
(define (proof-to-free-avars proof)
(case (tag proof)
((proof-in-avar-form) (list (proof-in-avar-form-to-avar proof)))
((proof-in-aconst-form) '())
((proof-in-imp-intro-form)
(let* ((avar (proof-in-imp-intro-form-to-avar proof))
(kernel (proof-in-imp-intro-form-to-kernel proof))
(free-avars (proof-to-free-avars kernel)))
(remove-wrt avar=? avar free-avars)))
((proof-in-imp-elim-form)
(let ((free-avars1
(proof-to-free-avars (proof-in-imp-elim-form-to-op proof)))
(free-avars2
(proof-to-free-avars (proof-in-imp-elim-form-to-arg proof))))
(union-wrt avar=? free-avars1 free-avars2)))
((proof-in-impnc-intro-form)
(let* ((avar (proof-in-impnc-intro-form-to-avar proof))
(kernel (proof-in-impnc-intro-form-to-kernel proof))
(free-avars (proof-to-free-avars kernel)))
(remove-wrt avar=? avar free-avars)))
((proof-in-impnc-elim-form)
(let ((free-avars1
(proof-to-free-avars (proof-in-impnc-elim-form-to-op proof)))
(free-avars2
(proof-to-free-avars (proof-in-impnc-elim-form-to-arg proof))))
(union-wrt avar=? free-avars1 free-avars2)))
((proof-in-and-intro-form)
(union-wrt
avar=?
(proof-to-free-avars (proof-in-and-intro-form-to-left proof))
(proof-to-free-avars (proof-in-and-intro-form-to-right proof))))
((proof-in-and-elim-left-form)
(proof-to-free-avars (proof-in-and-elim-left-form-to-kernel proof)))
((proof-in-and-elim-right-form)
(proof-to-free-avars (proof-in-and-elim-right-form-to-kernel proof)))
((proof-in-all-intro-form)
(proof-to-free-avars (proof-in-all-intro-form-to-kernel proof)))
((proof-in-all-elim-form)
(proof-to-free-avars (proof-in-all-elim-form-to-op proof)))
((proof-in-allnc-intro-form)
(proof-to-free-avars (proof-in-allnc-intro-form-to-kernel proof)))
((proof-in-allnc-elim-form)
(proof-to-free-avars (proof-in-allnc-elim-form-to-op proof)))
(else (myerror "proof-to-free-avars" "proof tag expected" (tag proof)))))
(define (proof-to-bound-avars proof)
(case (tag proof)
((proof-in-avar-form proof-in-aconst-form) '())
((proof-in-imp-intro-form)
(let* ((avar (proof-in-imp-intro-form-to-avar proof))
(kernel (proof-in-imp-intro-form-to-kernel proof))
(bound (proof-to-bound-avars kernel)))
(adjoin-wrt avar=? avar bound)))
((proof-in-imp-elim-form)
(let ((bound1 (proof-to-bound-avars
(proof-in-imp-elim-form-to-op proof)))
(bound2 (proof-to-bound-avars
(proof-in-imp-elim-form-to-arg proof))))
(union-wrt avar=? bound1 bound2)))
((proof-in-impnc-intro-form)
(let* ((avar (proof-in-impnc-intro-form-to-avar proof))
(kernel (proof-in-impnc-intro-form-to-kernel proof))
(bound (proof-to-bound-avars kernel)))
(adjoin-wrt avar=? avar bound)))
((proof-in-impnc-elim-form)
(let ((bound1 (proof-to-bound-avars
(proof-in-impnc-elim-form-to-op proof)))
(bound2 (proof-to-bound-avars
(proof-in-impnc-elim-form-to-arg proof))))
(union-wrt avar=? bound1 bound2)))
((proof-in-and-intro-form)
(union-wrt
avar=?
(proof-to-bound-avars (proof-in-and-intro-form-to-left proof))
(proof-to-bound-avars (proof-in-and-intro-form-to-right proof))))
((proof-in-and-elim-left-form)
(proof-to-bound-avars (proof-in-and-elim-left-form-to-kernel proof)))
((proof-in-and-elim-right-form)
(proof-to-bound-avars (proof-in-and-elim-right-form-to-kernel proof)))
((proof-in-all-intro-form)
(proof-to-bound-avars (proof-in-all-intro-form-to-kernel proof)))
((proof-in-all-elim-form)
(proof-to-bound-avars (proof-in-all-elim-form-to-op proof)))
((proof-in-allnc-intro-form)
(proof-to-bound-avars (proof-in-allnc-intro-form-to-kernel proof)))
((proof-in-allnc-elim-form)
(proof-to-bound-avars (proof-in-allnc-elim-form-to-op proof)))
(else (myerror "proof-to-bound-avars" "proof tag expected" (tag proof)))))
(define (proof-to-free-and-bound-avars-wrt avar-eq proof)
(case (tag proof)
((proof-in-avar-form) (list (proof-in-avar-form-to-avar proof)))
((proof-in-aconst-form) '())
((proof-in-imp-intro-form)
(let* ((avar (proof-in-imp-intro-form-to-avar proof))
(kernel (proof-in-imp-intro-form-to-kernel proof))
(free-and-bound-avars
(proof-to-free-and-bound-avars-wrt avar-eq kernel)))
(union-wrt avar-eq (list avar) free-and-bound-avars)))
((proof-in-imp-elim-form)
(let ((free-and-bound-avars1
(proof-to-free-and-bound-avars-wrt
avar-eq (proof-in-imp-elim-form-to-op proof)))
(free-and-bound-avars2
(proof-to-free-and-bound-avars-wrt
avar-eq (proof-in-imp-elim-form-to-arg proof))))
(union-wrt avar-eq free-and-bound-avars1 free-and-bound-avars2)))
((proof-in-impnc-intro-form)
(let* ((avar (proof-in-impnc-intro-form-to-avar proof))
(kernel (proof-in-impnc-intro-form-to-kernel proof))
(free-and-bound-avars
(proof-to-free-and-bound-avars-wrt avar-eq kernel)))
(union-wrt avar-eq (list avar) free-and-bound-avars)))
((proof-in-impnc-elim-form)
(let ((free-and-bound-avars1
(proof-to-free-and-bound-avars-wrt
avar-eq (proof-in-impnc-elim-form-to-op proof)))
(free-and-bound-avars2
(proof-to-free-and-bound-avars-wrt
avar-eq (proof-in-impnc-elim-form-to-arg proof))))
(union-wrt avar-eq free-and-bound-avars1 free-and-bound-avars2)))
((proof-in-and-intro-form)
(union-wrt avar-eq
(proof-to-free-and-bound-avars-wrt
avar-eq (proof-in-and-intro-form-to-left proof))
(proof-to-free-and-bound-avars-wrt
avar-eq (proof-in-and-intro-form-to-right proof))))
((proof-in-and-elim-left-form)
(proof-to-free-and-bound-avars-wrt
avar-eq (proof-in-and-elim-left-form-to-kernel proof)))
((proof-in-and-elim-right-form)
(proof-to-free-and-bound-avars-wrt
avar-eq (proof-in-and-elim-right-form-to-kernel proof)))
((proof-in-all-intro-form)
(proof-to-free-and-bound-avars-wrt
avar-eq (proof-in-all-intro-form-to-kernel proof)))
((proof-in-all-elim-form)
(proof-to-free-and-bound-avars-wrt
avar-eq (proof-in-all-elim-form-to-op proof)))
((proof-in-allnc-intro-form)
(proof-to-free-and-bound-avars-wrt
avar-eq (proof-in-allnc-intro-form-to-kernel proof)))
((proof-in-allnc-elim-form)
(proof-to-free-and-bound-avars-wrt
avar-eq (proof-in-allnc-elim-form-to-op proof)))
(else (myerror "proof-to-free-and-bound-avars-wrt" "proof tag expected"
(tag proof)))))
(define (proof-to-free-and-bound-avars proof)
(proof-to-free-and-bound-avars-wrt avar=? proof))
(define (proof-respects-avar-convention? proof)
(let* ((avars (proof-to-free-and-bound-avars-wrt avar-full=? proof))
(l (map (lambda (avar)
(list (avar-to-name avar) (avar-to-index avar)))
avars)))
(equal? (remove-duplicates l) l)))
(define (proof-to-aconsts-without-rules-aux proof)
(case (tag proof)
((proof-in-avar-form) '())
((proof-in-aconst-form)
(let ((aconst (proof-in-aconst-form-to-aconst proof)))
(if (aconst-without-rules? aconst) (list aconst) '())))
((proof-in-imp-intro-form)
(proof-to-aconsts-without-rules-aux
(proof-in-imp-intro-form-to-kernel proof)))
((proof-in-imp-elim-form)
(let ((aconsts1 (proof-to-aconsts-without-rules-aux
(proof-in-imp-elim-form-to-op proof)))
(aconsts2 (proof-to-aconsts-without-rules-aux
(proof-in-imp-elim-form-to-arg proof))))
(append aconsts1 aconsts2)))
((proof-in-impnc-intro-form)
(proof-to-aconsts-without-rules-aux
(proof-in-impnc-intro-form-to-kernel proof)))
((proof-in-impnc-elim-form)
(let ((aconsts1 (proof-to-aconsts-without-rules-aux
(proof-in-impnc-elim-form-to-op proof)))
(aconsts2 (proof-to-aconsts-without-rules-aux
(proof-in-impnc-elim-form-to-arg proof))))
(append aconsts1 aconsts2)))
((proof-in-and-intro-form)
(append (proof-to-aconsts-without-rules-aux
(proof-in-and-intro-form-to-left proof))
(proof-to-aconsts-without-rules-aux
(proof-in-and-intro-form-to-right proof))))
((proof-in-and-elim-left-form)
(proof-to-aconsts-without-rules-aux
(proof-in-and-elim-left-form-to-kernel proof)))
((proof-in-and-elim-right-form)
(proof-to-aconsts-without-rules-aux
(proof-in-and-elim-right-form-to-kernel proof)))
((proof-in-all-intro-form)
(proof-to-aconsts-without-rules-aux
(proof-in-all-intro-form-to-kernel proof)))
((proof-in-all-elim-form)
(proof-to-aconsts-without-rules-aux
(proof-in-all-elim-form-to-op proof)))
((proof-in-allnc-intro-form)
(proof-to-aconsts-without-rules-aux
(proof-in-allnc-intro-form-to-kernel proof)))
((proof-in-allnc-elim-form)
(proof-to-aconsts-without-rules-aux
(proof-in-allnc-elim-form-to-op proof)))
(else (myerror "proof-to-aconsts-without-rules-aux" "proof tag expected"
(tag proof)))))
(define (proof-to-aconsts-without-rules proof)
(remove-duplicates-wrt aconst=? (proof-to-aconsts-without-rules-aux proof)))
(define (proof-to-aconsts-with-repetitions proof)
(case (tag proof)
((proof-in-avar-form) '())
((proof-in-aconst-form)
(list (proof-in-aconst-form-to-aconst proof)))
((proof-in-imp-intro-form)
(proof-to-aconsts-with-repetitions
(proof-in-imp-intro-form-to-kernel proof)))
((proof-in-imp-elim-form)
(let ((aconsts1 (proof-to-aconsts-with-repetitions
(proof-in-imp-elim-form-to-op proof)))
(aconsts2 (proof-to-aconsts-with-repetitions
(proof-in-imp-elim-form-to-arg proof))))
(append aconsts1 aconsts2)))
((proof-in-impnc-intro-form)
(proof-to-aconsts-with-repetitions
(proof-in-impnc-intro-form-to-kernel proof)))
((proof-in-impnc-elim-form)
(let ((aconsts1 (proof-to-aconsts-with-repetitions
(proof-in-impnc-elim-form-to-op proof)))
(aconsts2 (proof-to-aconsts-with-repetitions
(proof-in-impnc-elim-form-to-arg proof))))
(append aconsts1 aconsts2)))
((proof-in-and-intro-form)
(append (proof-to-aconsts-with-repetitions
(proof-in-and-intro-form-to-left proof))
(proof-to-aconsts-with-repetitions
(proof-in-and-intro-form-to-right proof))))
((proof-in-and-elim-left-form)
(proof-to-aconsts-with-repetitions
(proof-in-and-elim-left-form-to-kernel proof)))
((proof-in-and-elim-right-form)
(proof-to-aconsts-with-repetitions
(proof-in-and-elim-right-form-to-kernel proof)))
((proof-in-all-intro-form)
(proof-to-aconsts-with-repetitions
(proof-in-all-intro-form-to-kernel proof)))
((proof-in-all-elim-form)
(proof-to-aconsts-with-repetitions (proof-in-all-elim-form-to-op proof)))
((proof-in-allnc-intro-form)
(proof-to-aconsts-with-repetitions
(proof-in-allnc-intro-form-to-kernel proof)))
((proof-in-allnc-elim-form)
(proof-to-aconsts-with-repetitions
(proof-in-allnc-elim-form-to-op proof)))
(else (myerror "proof-to-aconsts-with-repetitions" "proof tag expected"
(tag proof)))))
(define (proof-to-aconsts proof)
(remove-duplicates-wrt aconst=? (proof-to-aconsts-with-repetitions proof)))
(define (proof-to-global-assumptions-with-repetitions proof)
(case (tag proof)
((proof-in-avar-form) '())
((proof-in-aconst-form)
(let* ((aconst (proof-in-aconst-form-to-aconst proof))
(name (aconst-to-name aconst)))
(case (aconst-to-kind aconst)
((theorem)
(proof-to-global-assumptions-with-repetitions
(theorem-name-to-proof (aconst-to-name aconst))))
((global-assumption)
(list aconst))
(else '()))))
((proof-in-imp-intro-form)
(proof-to-global-assumptions-with-repetitions
(proof-in-imp-intro-form-to-kernel proof)))
((proof-in-imp-elim-form)
(let ((aconsts1 (proof-to-global-assumptions-with-repetitions
(proof-in-imp-elim-form-to-op proof)))
(aconsts2 (proof-to-global-assumptions-with-repetitions
(proof-in-imp-elim-form-to-arg proof))))
(append aconsts1 aconsts2)))
((proof-in-impnc-intro-form)
(proof-to-global-assumptions-with-repetitions
(proof-in-impnc-intro-form-to-kernel proof)))
((proof-in-impnc-elim-form)
(let ((aconsts1 (proof-to-global-assumptions-with-repetitions
(proof-in-impnc-elim-form-to-op proof)))
(aconsts2 (proof-to-global-assumptions-with-repetitions
(proof-in-impnc-elim-form-to-arg proof))))
(append aconsts1 aconsts2)))
((proof-in-and-intro-form)
(append (proof-to-global-assumptions-with-repetitions
(proof-in-and-intro-form-to-left proof))
(proof-to-global-assumptions-with-repetitions
(proof-in-and-intro-form-to-right proof))))
((proof-in-and-elim-left-form)
(proof-to-global-assumptions-with-repetitions
(proof-in-and-elim-left-form-to-kernel proof)))
((proof-in-and-elim-right-form)
(proof-to-global-assumptions-with-repetitions
(proof-in-and-elim-right-form-to-kernel proof)))
((proof-in-all-intro-form)
(proof-to-global-assumptions-with-repetitions
(proof-in-all-intro-form-to-kernel proof)))
((proof-in-all-elim-form)
(proof-to-global-assumptions-with-repetitions
(proof-in-all-elim-form-to-op proof)))
((proof-in-allnc-intro-form)
(proof-to-global-assumptions-with-repetitions
(proof-in-allnc-intro-form-to-kernel proof)))
((proof-in-allnc-elim-form)
(proof-to-global-assumptions-with-repetitions
(proof-in-allnc-elim-form-to-op proof)))
(else (myerror
"proof-to-global-assumptions-with-repetitions" "proof tag expected"
(tag proof)))))
(define (proof-to-global-assumptions proof)
(remove-duplicates-wrt aconst=?
(proof-to-global-assumptions-with-repetitions proof)))
(define (thm-or-ga-name-to-proof x)
(cond
((and (string? x) (assoc x THEOREMS))
(make-proof-in-aconst-form (theorem-name-to-aconst x)))
((and (string? x) (assoc x GLOBAL-ASSUMPTIONS))
(make-proof-in-aconst-form (global-assumption-name-to-aconst x)))
(else (myerror "thm-or-ga-name-to-proof"
"name of theorem or global assumption expected"
x))))
; proof-to-undec-proof turns every imp, all formula in the given proof
; in an impnc, allnc formula, including the parts of an aconst which
; come from its uninstatiated formula. Hence undec-proof is in
; general not a proof.
(define (proof-to-undec-proof proof)
(case (tag proof)
((proof-in-avar-form)
(let* ((avar (proof-in-avar-form-to-avar proof))
(undec-avar (make-avar
(formula-to-undec-formula (proof-to-formula proof))
(avar-to-index avar) (avar-to-name avar))))
(make-proof-in-avar-form undec-avar)))
((proof-in-aconst-form)
(let ((aconst (proof-in-aconst-form-to-aconst proof)))
(list 'proof-in-aconst-form
(formula-to-undec-formula (aconst-to-formula aconst))
(aconst-to-undec-aconst aconst))))
((proof-in-imp-intro-form)
(let* ((kernel (proof-in-imp-intro-form-to-kernel proof))
(avar (proof-in-imp-intro-form-to-avar proof))
(undec-avar (make-avar
(formula-to-undec-formula (avar-to-formula avar))
(avar-to-index avar) (avar-to-name avar))))
(make-proof-in-impnc-intro-form
undec-avar (proof-to-undec-proof kernel))))
((proof-in-impnc-intro-form)
(let* ((kernel (proof-in-impnc-intro-form-to-kernel proof))
(avar (proof-in-impnc-intro-form-to-avar proof))
(undec-avar (make-avar
(formula-to-undec-formula (avar-to-formula avar))
(avar-to-index avar) (avar-to-name avar))))
(make-proof-in-impnc-intro-form
undec-avar (proof-to-undec-proof kernel))))
((proof-in-imp-elim-form)
(make-proof-in-impnc-elim-form
(proof-to-undec-proof (proof-in-imp-elim-form-to-op proof))
(proof-to-undec-proof (proof-in-imp-elim-form-to-arg proof))))
((proof-in-impnc-elim-form)
(make-proof-in-impnc-elim-form
(proof-to-undec-proof (proof-in-impnc-elim-form-to-op proof))
(proof-to-undec-proof (proof-in-impnc-elim-form-to-arg proof))))
((proof-in-and-intro-form)
(make-proof-in-and-intro-form
(proof-to-undec-proof (proof-in-and-intro-form-to-left proof))
(proof-to-undec-proof (proof-in-and-intro-form-to-right proof))))
((proof-in-and-elim-left-form)
(make-proof-in-and-elim-left-form
(proof-to-undec-proof (proof-in-and-elim-left-form-to-kernel proof))))
((proof-in-and-elim-right-form)
(make-proof-in-and-elim-right-form
(proof-to-undec-proof (proof-in-and-elim-right-form-to-kernel proof))))
((proof-in-all-intro-form)
(make-proof-in-allnc-intro-form
(proof-in-all-intro-form-to-var proof)
(proof-to-undec-proof
(proof-in-all-intro-form-to-kernel proof))))
((proof-in-allnc-intro-form)
(make-proof-in-allnc-intro-form
(proof-in-allnc-intro-form-to-var proof)
(proof-to-undec-proof
(proof-in-allnc-intro-form-to-kernel proof))))
((proof-in-all-elim-form)
(make-proof-in-allnc-elim-form
(proof-to-undec-proof (proof-in-all-elim-form-to-op proof))
(proof-in-all-elim-form-to-arg proof)))
((proof-in-allnc-elim-form)
(make-proof-in-allnc-elim-form
(proof-to-undec-proof (proof-in-allnc-elim-form-to-op proof))
(proof-in-allnc-elim-form-to-arg proof)))
(else (myerror "proof-to-undec-proof" "proof tag expected" (tag proof)))))
; (dp (proof-to-undec-proof (theorem-name-to-proof "NatPlusComm")))
; (dp (proof-to-undec-proof (theorem-name-to-proof "ListAppendNil")))
(define (undec-proof-and-decavars-and-decfla-to-decproof-and-ext-decavars
proof decavars decfla)
(if ;application of an aconst with a less extending alternative
(and
(or (and (predicate-form? decfla)
(idpredconst-form? (predicate-form-to-predicate decfla)))
;temporarily we still have
(ex-form? decfla)
(exnc-form? decfla)
(and-form? decfla))
(let ((op (proof-in-elim-form-to-final-op proof)))
(and
(proof-in-aconst-form? op)
(let ((opname (aconst-to-name (proof-in-aconst-form-to-aconst op))))
(and
(or (assoc opname THEOREMS)
(assoc opname GLOBAL-ASSUMPTIONS))
(let ((altops (decfla-and-opname-to-altops decfla opname)))
(and
(pair? altops)
(let*
((args (proof-in-elim-form-to-args proof))
(extending-proofs-or-f
(map
(lambda (altop)
(op-and-args-and-altop-and-decfla-and-decavars-to-proof
op args altop decfla decavars))
altops))
(extending-proofs ;take only those that are not #f
(list-transform-positive extending-proofs-or-f
(lambda (x) x))))
(pair? extending-proofs)))))))))
;take the first (or "least extended"?)
(let* ((op (proof-in-elim-form-to-final-op proof))
(opname (aconst-to-name (proof-in-aconst-form-to-aconst op)))
(altops (decfla-and-opname-to-altops decfla opname))
(args (proof-in-elim-form-to-args proof))
(extending-proofs-or-f
(map
(lambda (altop)
(op-and-args-and-altop-and-decfla-and-decavars-to-proof
op args altop decfla decavars))
altops))
(extending-proofs ;take only those that are not #f
(list-transform-positive extending-proofs-or-f
(lambda (x) x))))
(list (car extending-proofs) decavars))
;else carry on
(case (tag proof)
((proof-in-avar-form)
(let*
((avar (proof-in-avar-form-to-avar proof))
(test (member-wrt avar=? avar decavars))
(decavar
(if
test (car test)
(myerror
"undec-proof-and-decavars-and-decfla-to-decproof-and-ext-decavars"
"avar" (avar-to-name avar) (avar-to-index avar)
"missing in decavars"
(pp-context decavars))))
(decavar-fla (avar-to-formula decavar))
(ext-fla (dec-variants-to-lub decfla decavar-fla))
(decavar
(make-avar ext-fla (avar-to-index avar) (avar-to-name avar))))
(list (make-proof-in-avar-form decavar)
(list decavar))))
((proof-in-aconst-form)
(let* ((aconst (proof-in-aconst-form-to-aconst proof))
(name (aconst-to-name aconst))
(kind (aconst-to-kind aconst)))
(cond
((string=? "Intro" name)
(let ((min-intro-aconst
(intro-aconst-and-decfla-to-min-intro-aconst aconst decfla)))
(list (make-proof-in-aconst-form min-intro-aconst) '())))
((string=? "Elim" name)
(let ((min-elim-aconst
(elim-aconst-and-decfla-to-min-elim-aconst aconst decfla)))
(list (make-proof-in-aconst-form min-elim-aconst) '())))
((eq? 'axiom kind)
(list (make-proof-in-aconst-form
(let* ((name (aconst-to-name aconst))
(uninst-fla (aconst-to-uninst-formula aconst))
(extended-tpinst
(aconst-and-dec-inst-formula-to-extended-tpinst
aconst decfla))
(aconst-without-repro-formulas
(make-aconst name kind uninst-fla extended-tpinst)))
(apply make-aconst
(append (list name kind uninst-fla extended-tpinst)
(aconst-to-computed-repro-formulas
aconst-without-repro-formulas)))))
'()))
(else
(let ((min-aconst
(let* ((aconsts
(map cadr (append THEOREMS GLOBAL-ASSUMPTIONS)))
(extending-aconsts
(list-transform-positive aconsts
(lambda (ac)
(let ((match2-res ;ignore-deco-flag set to #t
(match2 (aconst-to-uninst-formula ac)
decfla #t)))
(and match2-res
(extending-dec-variants?
(formula-substitute
(aconst-to-uninst-formula ac)
match2-res)
decfla)))))))
(if
(pair? extending-aconsts)
(let aconst-and-aconsts-to-min-aconst
((a (car extending-aconsts))
(as (cdr extending-aconsts)))
(if (null? as) a
(let* ((b (car as))
(rest (cdr as))
(fla (aconst-to-formula a)))
(if (apply
or-op (map
(lambda (c)
(extending-dec-variants?
fla (aconst-to-formula c)))
rest))
(aconst-and-aconsts-to-min-aconst b rest)
a))))
(myerror
"undec-proof-and-decavars-and-decfla-to-decproof-and-ext-decavars"
"no theorem or global assumption found extending"
decfla)))))
(list
(make-proof-in-aconst-form
(let* ((name (aconst-to-name min-aconst))
(kind (aconst-to-kind min-aconst))
(uninst-fla (aconst-to-uninst-formula min-aconst))
(extended-tpinst
(aconst-and-dec-inst-formula-to-extended-tpinst
min-aconst decfla))
(aconst-without-repro-formulas
(make-aconst name kind uninst-fla extended-tpinst)))
(apply make-aconst
(append (list name kind uninst-fla extended-tpinst)
(aconst-to-computed-repro-formulas
aconst-without-repro-formulas)))))
'()))))))
((proof-in-impnc-intro-form)
(let* ((kernel (proof-in-impnc-intro-form-to-kernel proof))
(avar (proof-in-impnc-intro-form-to-avar proof))
(free-avars (proof-to-free-avars kernel))
(decprem (imp-impnc-form-to-premise decfla))
(decconc (imp-impnc-form-to-conclusion decfla))
(decavar
(make-avar decprem (avar-to-index avar) (avar-to-name avar)))
(decavars-for-kernel
(do ((l free-avars (cdr l))
(res '() (let ((test (member-wrt avar=? (car l) decavars)))
(cond (test
(cons (car test) res))
((avar=? (car l) avar)
(cons decavar res))
(else
(myerror "unexpected avar"
(avar-to-name (car l))
(avar-to-index (car l))
(avar-to-formula (car l))))))))
((null? l) (reverse res))))
(decproof-and-ext-decavars
(undec-proof-and-decavars-and-decfla-to-decproof-and-ext-decavars
kernel decavars-for-kernel decconc))
(decproof (car decproof-and-ext-decavars))
(ext-decavars (cadr decproof-and-ext-decavars))
(reduced-ext-decavars (remove-wrt avar=? avar ext-decavars))
(test (member-wrt avar=? avar ext-decavars))
(ext-decavar1 (if test (car test) decavar)))
(list (if (and (impnc-form? decfla)
(not
(member-wrt avar=? avar (proof-to-cvars decproof))))
(make-proof-in-impnc-intro-form ext-decavar1 decproof)
(make-proof-in-imp-intro-form ext-decavar1 decproof))
reduced-ext-decavars)))
((proof-in-impnc-elim-form)
(let* ((op (proof-in-impnc-elim-form-to-op proof))
(arg (proof-in-impnc-elim-form-to-arg proof))
(avars1 (proof-to-free-avars op))
(avars2 (proof-to-free-avars arg))
(avars-int (intersection-wrt avar=? avars1 avars2))
(avars-lft (set-minus-wrt avar=? avars1 avars-int))
(avars-rht (set-minus-wrt avar=? avars2 avars-int))
(avars-to-int
(lambda (avars)
(list-transform-positive avars
(lambda (x) (member-wrt avar=? x avars-int)))))
(avars-to-lft
(lambda (avars)
(list-transform-positive avars
(lambda (x) (member-wrt avar=? x avars-lft)))))
(avars-to-rht
(lambda (avars)
(list-transform-positive avars
(lambda (x) (member-wrt avar=? x avars-rht)))))
(decavars-int (avars-to-int decavars))
(decavars-lft (avars-to-lft decavars))
(decavars-rht (avars-to-rht decavars)))
(do ((decproof-and-decavars-list
(let* ((decproof-and-decavars1
(undec-proof-and-decavars-and-decfla-to-decproof-and-ext-decavars
op (append decavars-lft decavars-int)
(make-impnc
(impnc-form-to-premise (proof-to-formula op))
decfla)))
(decproof1 (car decproof-and-decavars1))
(decavars1 (cadr decproof-and-decavars1))
(decavars1-lft (avars-to-lft decavars1))
(decavars1-int (avars-to-int decavars1))
(decfla1 (proof-to-formula decproof1))
(decproof-and-decavars2
(undec-proof-and-decavars-and-decfla-to-decproof-and-ext-decavars
arg (append decavars1-int decavars-rht)
(imp-impnc-form-to-premise decfla1))))
(list decproof-and-decavars1 decproof-and-decavars2))
(let* ((decproof-and-decavars1 (car decproof-and-decavars-list))
(decproof1 (car decproof-and-decavars1))
(decavars1 (cadr decproof-and-decavars1))
(decavars1-lft (avars-to-lft decavars1))
(decfla1 (proof-to-formula decproof1))
(decproof-and-decavars2 (cadr decproof-and-decavars-list))
(decproof2 (car decproof-and-decavars2))
(decavars2 (cadr decproof-and-decavars2))
(decavars2-int (avars-to-int decavars2))
(decavars2-rht (avars-to-rht decavars2))
(decfla2 (proof-to-formula decproof2))
(decproof-and-decavars3
(undec-proof-and-decavars-and-decfla-to-decproof-and-ext-decavars
op (append decavars1-lft decavars2-int)
(if (impnc-form? decfla1)
(make-impnc decfla2
(impnc-form-to-conclusion decfla1))
(make-imp decfla2
(imp-form-to-conclusion decfla1)))))
(decproof3 (car decproof-and-decavars3))
(decavars3 (cadr decproof-and-decavars3))
(decavars3-int (avars-to-int decavars3))
(decfla3 (proof-to-formula decproof3))
(decproof-and-decavars4
(undec-proof-and-decavars-and-decfla-to-decproof-and-ext-decavars
arg (append decavars3-int decavars2-rht)
(imp-impnc-form-to-premise decfla3))))
(list decproof-and-decavars3 decproof-and-decavars4)))
(i 0 (+ 1 i)))
((let* ((decproof-and-decavars1 (car decproof-and-decavars-list))
(decproof1 (car decproof-and-decavars1))
(decavars1 (cadr decproof-and-decavars1))
(decproof-and-decavars2 (cadr decproof-and-decavars-list))
(decproof2 (car decproof-and-decavars2))
(decavars2 (cadr decproof-and-decavars2))
(decavars1-int (avars-to-int decavars1))
(decavars2-int (avars-to-int decavars2))
(decfla1 (proof-to-formula decproof1))
(decfla2 (proof-to-formula decproof2)))
(or (and (null? (set-minus-wrt
avar-full=? decavars1-int decavars2-int))
(null? (set-minus-wrt
avar-full=? decavars2-int decavars1-int))
(classical-formula=?
(imp-impnc-form-to-premise decfla1) decfla2))
(= 2 i)))
(let* ((decproof-and-decavars1 (car decproof-and-decavars-list))
(decproof1 (car decproof-and-decavars1))
(decavars1 (cadr decproof-and-decavars1))
(decfla1 (proof-to-formula decproof1))
(decproof-and-decavars2 (cadr decproof-and-decavars-list))
(decproof2 (car decproof-and-decavars2))
(decavars2 (cadr decproof-and-decavars2))
(decavars2-rht (avars-to-rht decavars2)))
;(display "exit loop") (newline)
(if (= 3 i)
(begin (display "forced exit") (newline)
(display "decavars1-int: ")
(pp-context (avars-to-int decavars1))
(display "decavars2-int: ")
(pp-context (avars-to-int decavars2)) (newline)
(display "prem: ")
(pp (imp-impnc-form-to-premise decfla1))
(display "decfla2: ")
(pp (nf (proof-to-formula decproof2)))))
(list (if (impnc-form? decfla1)
(make-proof-in-impnc-elim-form decproof1 decproof2)
(make-proof-in-imp-elim-form decproof1 decproof2))
(append decavars1 decavars2-rht)))))))
((proof-in-allnc-intro-form)
(let* ((var (proof-in-allnc-intro-form-to-var proof))
(kernel (proof-in-allnc-intro-form-to-kernel proof))
(decvar (all-allnc-form-to-var decfla))
(deckernel (all-allnc-form-to-kernel decfla))
(subst-deckernel
(if (equal? var decvar)
deckernel
(formula-subst deckernel decvar (make-term-in-var-form var))))
(decproof-and-ext-decavars
(undec-proof-and-decavars-and-decfla-to-decproof-and-ext-decavars
kernel decavars subst-deckernel))
(decproof (car decproof-and-ext-decavars))
(ext-decavars (cadr decproof-and-ext-decavars)))
(list (if (and (allnc-form? decfla)
(not (member var (proof-to-cvars decproof))))
(make-proof-in-allnc-intro-form var decproof)
(make-proof-in-all-intro-form var decproof))
ext-decavars)))
((proof-in-allnc-elim-form)
(let* ((op (proof-in-allnc-elim-form-to-op proof))
(arg (proof-in-allnc-elim-form-to-arg proof))
(op-formula (proof-to-formula op))
(var (allnc-form-to-var op-formula))
(kernel (allnc-form-to-kernel op-formula))
(allnc-decfla
(make-allnc var (dec-variants-to-lub kernel decfla)))
(decproof-and-ext-decavars
(undec-proof-and-decavars-and-decfla-to-decproof-and-ext-decavars
op decavars allnc-decfla))
(decproof (car decproof-and-ext-decavars))
(ext-decavars (cadr decproof-and-ext-decavars)))
(list (if (allnc-form? (proof-to-formula decproof))
(make-proof-in-allnc-elim-form decproof arg)
(make-proof-in-all-elim-form decproof arg))
ext-decavars)))
((proof-in-and-intro-form)
(let* ((left (proof-in-and-intro-form-to-left proof))
(right (proof-in-and-intro-form-to-right proof))
(avars1 (proof-to-free-avars left))
(avars2 (proof-to-free-avars right))
(avars-int (intersection-wrt avar=? avars1 avars2))
(avars-lft (set-minus-wrt avar=? avars1 avars-int))
(avars-rht (set-minus-wrt avar=? avars2 avars-int))
(avars-to-int
(lambda (avars)
(list-transform-positive avars
(lambda (x) (member-wrt avar=? x avars-int)))))
(avars-to-lft
(lambda (avars)
(list-transform-positive avars
(lambda (x) (member-wrt avar=? x avars-lft)))))
(avars-to-rht
(lambda (avars)
(list-transform-positive avars
(lambda (x) (member-wrt avar=? x avars-rht)))))
(decavars-int (avars-to-int decavars))
(decavars-lft (avars-to-lft decavars))
(decavars-rht (avars-to-rht decavars)))
(do ((decproof-and-decavars-list
(let* ((decproof-and-decavars1
(undec-proof-and-decavars-and-decfla-to-decproof-and-ext-decavars
left (append decavars-lft decavars-int)
(and-form-to-left decfla)))
(decproof1 (car decproof-and-decavars1))
(decavars1 (cadr decproof-and-decavars1))
(decavars1-lft (avars-to-lft decavars1))
(decavars1-int (avars-to-int decavars1))
(decfla1 (proof-to-formula decproof1))
(decproof-and-decavars2
(undec-proof-and-decavars-and-decfla-to-decproof-and-ext-decavars
right (append decavars1-int decavars-rht)
(and-form-to-right decfla))))
(list decproof-and-decavars1 decproof-and-decavars2))
(let* ((decproof-and-decavars1 (car decproof-and-decavars-list))
(decproof1 (car decproof-and-decavars1))
(decavars1 (cadr decproof-and-decavars1))
(decavars1-lft (avars-to-lft decavars1))
(decfla1 (proof-to-formula decproof1))
(decproof-and-decavars2 (cadr decproof-and-decavars-list))
(decproof2 (car decproof-and-decavars2))
(decavars2 (cadr decproof-and-decavars2))
(decavars2-int (avars-to-int decavars2))
(decavars2-rht (avars-to-rht decavars2))
(decfla2 (proof-to-formula decproof2))
(decproof-and-decavars3
(undec-proof-and-decavars-and-decfla-to-decproof-and-ext-decavars
left (append decavars1-lft decavars2-int) decfla1))
(decproof3 (car decproof-and-decavars3))
(decavars3 (cadr decproof-and-decavars3))
(decavars3-int (avars-to-int decavars3))
(decfla3 (proof-to-formula decproof3))
(decproof-and-decavars4
(undec-proof-and-decavars-and-decfla-to-decproof-and-ext-decavars
right (append decavars3-int decavars2-rht) decfla2)))
(list decproof-and-decavars3 decproof-and-decavars4)))
(i 0 (+ 1 i)))
((let* ((decproof-and-decavars1 (car decproof-and-decavars-list))
(decavars1 (cadr decproof-and-decavars1))
(decproof-and-decavars2 (cadr decproof-and-decavars-list))
(decavars2 (cadr decproof-and-decavars2))
(decavars1-int (avars-to-int decavars1))
(decavars2-int (avars-to-int decavars2)))
(or (and (null? (set-minus-wrt
avar-full=? decavars1-int decavars2-int))
(null? (set-minus-wrt
avar-full=? decavars2-int decavars1-int)))
(= 2 i)))
(let* ((decproof-and-decavars1 (car decproof-and-decavars-list))
(decproof1 (car decproof-and-decavars1))
(decavars1 (cadr decproof-and-decavars1))
(decproof-and-decavars2 (cadr decproof-and-decavars-list))
(decproof2 (car decproof-and-decavars2))
(decavars2 (cadr decproof-and-decavars2))
(decavars2-rht (avars-to-rht decavars2)))
;(display "exit loop") (newline)
(if (= 2 i)
(begin (display "forced exit") (newline)
(display "decavars1-int: ")
(pp-context (avars-to-int decavars1))
(display "decavars2-int: ")
(pp-context (avars-to-int decavars2)) (newline)))
(list (make-proof-in-and-intro-form decproof1 decproof2)
(append decavars1 decavars2-rht)))))))
((proof-in-and-elim-left-form)
(let* ((kernel (proof-in-and-elim-left-form-to-kernel proof))
(decproof-and-ext-decavars
(undec-proof-and-decavars-and-decfla-to-decproof-and-ext-decavars
kernel decavars
(make-and decfla (and-form-to-right
(proof-to-formula kernel)))))
(decproof (car decproof-and-ext-decavars))
(ext-decavars (cadr decproof-and-ext-decavars)))
(list (make-proof-in-and-elim-left-form decproof)
ext-decavars)))
((proof-in-and-elim-right-form)
(let* ((kernel (proof-in-and-elim-right-form-to-kernel proof))
(decproof-and-ext-decavars
(undec-proof-and-decavars-and-decfla-to-decproof-and-ext-decavars
kernel decavars
(make-and (and-form-to-left (proof-to-formula kernel)) decfla)))
(decproof (car decproof-and-ext-decavars))
(ext-decavars (cadr decproof-and-ext-decavars)))
(list (make-proof-in-and-elim-right-form decproof)
ext-decavars)))
(else (myerror
"undec-proof-and-decavars-and-decfla-to-decproof-and-ext-decavars"
"unexpected proof tag"
(tag proof))))))
; op-and-args-and-altop-and-decfla-and-decavars-to-proof assumes that
; op applied to args proves an extension of decfla, and that altop
; differs from op only in possibly requiring additional premises. It
; is tested whether altop applied to args and some of decavars is
; between op applied to args and decfla w.r.t. extension. If so, a
; proof based on altop is returned, else #f.
(define (op-and-args-and-altop-and-decfla-and-decavars-to-proof
op args altop decfla decavars)
(do ((altproof-and-restargs-and-proof
(list altop args op)
(let* ((altproof (car altproof-and-restargs-and-proof))
(restargs (cadr altproof-and-restargs-and-proof))
(proof (caddr altproof-and-restargs-and-proof))
(altfla (proof-to-formula altproof))
(fla (proof-to-formula proof)))
(cond
((or (and (all-allnc-form? fla)
(all-allnc-form? altfla))
(and (imp-impnc-form? fla)
(imp-impnc-form? altfla)
(formula=? (imp-impnc-form-to-premise fla)
(imp-impnc-form-to-premise altfla))))
(list (mk-proof-in-elim-form altproof (car restargs))
(cdr restargs)
(mk-proof-in-elim-form proof (car restargs))))
((and (imp-impnc-form? altfla)
(member-wrt formula=?
(imp-impnc-form-to-premise altfla)
(map avar-to-formula decavars)))
(let ((decavar
(car (list-transform-positive decavars
(lambda (avar)
(formula=? (imp-impnc-form-to-premise altfla)
(avar-to-formula avar)))))))
(list (mk-proof-in-elim-form
altproof (make-proof-in-avar-form decavar))
restargs
proof)))
(else (list #f restargs proof))))))
((or (not (car altproof-and-restargs-and-proof))
(let* ((altproof (car altproof-and-restargs-and-proof))
(proof (caddr altproof-and-restargs-and-proof))
(fla (proof-to-formula proof))
(altfla (proof-to-formula altproof)))
(and (dec-variants? fla altfla)
(extending-dec-variants? fla altfla)
(dec-variants? altfla decfla)
(extending-dec-variants? altfla decfla))))
(car altproof-and-restargs-and-proof))))
; decfla-and-opname-to-altops returns a list of alternative operators
; (assumption constants) possibly usable to prove decfla.
(define (decfla-and-opname-to-altops decfla opname)
(let* ((thm-or-ga-items (append THEOREMS GLOBAL-ASSUMPTIONS))
(candidate-thm-or-ga-items ;c.r., no pvar as final conclusion
(list-transform-positive thm-or-ga-items
(lambda (thm-or-ga-item)
(let* ((ac (cadr thm-or-ga-item))
(uninst-fla (aconst-to-uninst-formula ac))
(concl (imp-impnc-all-allnc-form-to-final-conclusion
uninst-fla)))
(and
(or (and (predicate-form? concl)
(idpredconst-form?
(predicate-form-to-predicate concl)))
;temporarily we still have
(ex-form? concl)
(exnc-form? concl)
(and-form? concl))
(not (formula-of-nulltype? concl))
(not (string=? (car thm-or-ga-item) opname)))))))
(candidate-aconsts (map cadr candidate-thm-or-ga-items))
(fitting-aconsts-with-psubst
(do ((l candidate-aconsts (cdr l))
(res
'()
(let* ((ac (car l))
(uninst-fla (aconst-to-uninst-formula ac))
(match-res
(do ((concl
uninst-fla
(cond ((imp-impnc-form? concl)
(imp-impnc-form-to-conclusion concl))
((all-allnc-form? concl)
(all-allnc-form-to-kernel concl))
(else #f)))
(mres ;ignore-deco-flag set to #t
(match2 uninst-fla decfla #t)
(or mres (match2 concl decfla #t))))
((or mres (not concl)) mres))))
(if match-res
(let ((psubst (list-transform-positive match-res
(lambda (p) (pvar-form? (caar p))))))
(cons (list ac psubst) res))
res))))
((null? l) (reverse res)))))
(map (lambda (x)
(let* ((ac (car x))
(psubst (cadr x))
(subst-proof (proof-substitute
(make-proof-in-aconst-form ac) psubst))
(free (formula-to-free
(proof-to-formula subst-proof))))
(apply mk-proof-in-nc-intro-form
(append free (list subst-proof)))))
fitting-aconsts-with-psubst)))
; We assume that in IDS variants appear in decreasing order (i.e., the
; more extended ones are introduced first), that all possible variants
; do appear and that their clauses use the same parameter predicate
; variables.
(define (intro-aconst-and-decfla-to-min-intro-aconst aconst decfla)
(let* ((repro-data (aconst-to-repro-formulas aconst))
(i (car repro-data))
(uninst-fla (aconst-to-uninst-formula aconst))
(uninst-idpc-fla (imp-impnc-form-to-final-conclusion
(all-allnc-form-to-final-kernel uninst-fla)))
(idpc (if (predicate-form? uninst-idpc-fla)
(predicate-form-to-predicate uninst-idpc-fla)
(myerror "intro-aconst-and-decfla-to-min-intro-aconst"
"predicate form expected" uninst-idpc-fla)))
(idpc-name (idpredconst-to-name idpc))
(given-clauses (idpredconst-name-to-clauses idpc-name))
(l (length given-clauses))
(variant-idpc-names ;assumed to be in increasing order in IDS
(list-transform-positive (map car IDS)
(lambda (name)
(let ((clauses (idpredconst-name-to-clauses name)))
(and (= l (length clauses))
(apply and-op (map (lambda (cl1 cl2)
(dec-variants-up-to-pvars? cl1 cl2))
given-clauses clauses)))))))
(decfla-without-param-vars
(allnc-form-to-final-kernel
decfla (length (formula-to-free (aconst-to-inst-formula aconst)))))
(dec-kernel
(all-allnc-form-to-final-kernel decfla-without-param-vars))
(dec-idpc-fla (imp-impnc-form-to-final-conclusion dec-kernel))
(dec-idpc (predicate-form-to-predicate dec-idpc-fla))
(dec-args (predicate-form-to-args dec-idpc-fla))
(fitting-idpc-names ;whose i-th clause exactly fits decfla
(list-transform-positive variant-idpc-names
(lambda (name)
(let ((clauses (idpredconst-name-to-clauses name)))
(and (= l (length clauses)) ;do not ignore decs
(match2 (list-ref clauses i)
decfla-without-param-vars #f))))))
(min-idpc-name
(if (pair? fitting-idpc-names)
(car fitting-idpc-names)
(myerror "intro-aconst-and-decfla-to-min-intro-aconst"
"fitting idpredconst missing for" decfla)))
(min-dec-idpc
(make-idpredconst min-idpc-name
(idpredconst-to-types dec-idpc)
(idpredconst-to-cterms dec-idpc))))
(number-and-idpredconst-to-intro-aconst i min-dec-idpc)))
(define (elim-aconst-and-decfla-to-min-elim-aconst aconst decfla)
(let* ((name (aconst-to-name aconst)) ;"Elim"
(kind (aconst-to-kind aconst))
(uninst-fla (aconst-to-uninst-formula aconst))
(uninst-idpc-fla
(if (imp-form? uninst-fla)
(imp-form-to-premise uninst-fla)
(myerror "elim-aconst-and-decfla-to-min-elim-aconst"
"unexpected uninstatiated formula" uninst-fla)))
(idpc (if (predicate-form? uninst-idpc-fla)
(predicate-form-to-predicate uninst-idpc-fla)
(myerror "elim-aconst-and-decfla-to-min-elim-aconst"
"predicate form expected" uninst-idpc-fla)))
(idpc-name (idpredconst-to-name idpc))
(given-clauses (idpredconst-name-to-clauses idpc-name))
(l (length given-clauses))
(variant-idpc-names ;assumed to be in increasing order in IDS
(list-transform-positive (map car IDS)
(lambda (name)
(let ((clauses (idpredconst-name-to-clauses name)))
(and (= l (length clauses))
(apply and-op (map (lambda (cl1 cl2)
(dec-variants-up-to-pvars? cl1 cl2))
given-clauses clauses)))))))
(dec-kernel (all-allnc-form-to-final-kernel decfla))
(dec-idpc-fla (imp-form-to-premise dec-kernel))
(dec-idpc (predicate-form-to-predicate dec-idpc-fla))
(dec-args (predicate-form-to-args dec-idpc-fla))
(dec-concl (imp-form-to-conclusion dec-kernel))
(dec-clauses (imp-impnc-form-to-premises dec-concl l))
(dec-final-concl (imp-impnc-form-to-final-conclusion dec-concl l))
(fitting-idpc-names ;whose clauses exactly fit dec-clauses
(list-transform-positive variant-idpc-names
(lambda (name)
(let* ((clauses (idpredconst-name-to-clauses name)))
(apply and-op (map (lambda (cl dec-cl)
(match2 cl dec-cl #f)) ;do not ignore decs
clauses dec-clauses))))))
(min-idpc-name
(if (pair? fitting-idpc-names)
(car fitting-idpc-names)
(myerror "elim-aconst-and-decfla-to-min-elim-aconst"
"fitting idpredconst missing for" decfla)))
(min-dec-idpc
(make-idpredconst min-idpc-name
(idpredconst-to-types dec-idpc)
(idpredconst-to-cterms dec-idpc)))
(min-dec-idpc-fla (apply make-predicate-formula
(cons min-dec-idpc dec-args)))
(min-imp-fla (make-imp min-dec-idpc-fla dec-final-concl))
(min-elim-aconst (imp-formulas-to-elim-aconst min-imp-fla))
(min-uninst-fla (aconst-to-uninst-formula min-elim-aconst))
(extended-tpinst (aconst-and-dec-inst-formula-to-extended-tpinst
min-elim-aconst decfla))
(aconst-without-repro-formulas
(make-aconst name kind min-uninst-fla extended-tpinst)))
(apply make-aconst (append (list name kind min-uninst-fla extended-tpinst)
(aconst-to-computed-repro-formulas
aconst-without-repro-formulas)))))
(define (undec-proof-and-decavars-and-decfla-to-decproof
proof decavars decfla)
(car (undec-proof-and-decavars-and-decfla-to-decproof-and-ext-decavars
proof decavars decfla)))
(define (decorate proof)
(if (formula-of-nulltype? (proof-to-formula proof))
proof
(undec-proof-and-decavars-and-decfla-to-decproof
(proof-to-undec-proof proof)
(proof-to-free-avars proof)
(proof-to-formula proof))))
; 10-2. Normalization by evaluation
; =================================
; Normalization of proofs will be done by reduction to normalization of
; terms. (1) Construct a term from the proof. To do this properly,
; create for every free avar in the given proof a new var whose type
; comes from the formula of the avar. Store this information. Note
; that in this construction one also has to first create new vars for
; the bound avars. Similary to avars we have to treat assumption
; constants which are not axioms, i.e., theorems or global assumptions.
; (2) Normalize the resulting term. (3) Reconstruct a normal proof from
; this term, the end formula and the stored information. - The critical
; variables are carried along for efficiency reasons.
; To assign recursion constants to induction constants, we need to
; associate type variables with predicate variables, in such a way
; that we can later refer to this assignment. Therefore we use a
; global variable PVAR-TO-TVAR-ALIST, which memorizes the assigment
; done so far. A fixed PVAR-TO-TVAR refers to and updates
; PVAR-TO-TVAR-ALIST.
; For term extraction, in particular in formula-to-et-type and
; formula-to-etd-types, we will also need to assign type variables to
; predicate variables, this time only for those with positive or
; negative computational content. There we will also refer to the
; same PVAR-TO-TVAR and PVAR-TO-TVARP and PVAR-TO-TVARN. Later
; reference is necessary, because such tvars will appear in extracted
; terms of theorems involving pvars, and in a given development there
; may be many auxiliary lemmata containing the same pvar. In a
; finished development with no free pvars left PVAR-TO-TVAR
; PVAR-TO-TVARP and PVAR-TO-TVARN are not relevant any more, because
; all pvars (in aconsts or idpcs) are bound. In an unfinished
; development we want to assign the same tvar to all occurrences of a
; pvar, and it does not matter which tvar it is.
; Example Id: all alpha, beta all P^(alpha=>prop+beta). P^ -> P^ has
; [beta][y]y as extracted term. The tvar beta disappears as soon as
; Id is applied to some cterm without pvars.
(define PVAR-TO-TVAR-ALIST '())
(define INITIAL-PVAR-TO-TVAR-ALIST PVAR-TO-TVAR-ALIST)
(define (PVAR-TO-TVAR pvar)
(let ((info (assoc pvar PVAR-TO-TVAR-ALIST)))
(if info
(cadr info)
(let ((newtvar (new-tvar)))
(set! PVAR-TO-TVAR-ALIST
(cons (list pvar newtvar) PVAR-TO-TVAR-ALIST))
newtvar))))
; Probably PVAR-TO-TVARP is not necessary; PVAR-TO-TVAR should suffice.
(define PVAR-TO-TVARP-ALIST '())
(define INITIAL-PVAR-TO-TVARP-ALIST PVAR-TO-TVARP-ALIST)
(define (PVAR-TO-TVARP pvar)
(let ((info (assoc pvar PVAR-TO-TVARP-ALIST)))
(if info
(cadr info)
(let ((newtvarp (new-tvar)))
(set! PVAR-TO-TVARP-ALIST
(cons (list pvar newtvarp) PVAR-TO-TVARP-ALIST))
newtvarp))))
(define PVAR-TO-TVARN-ALIST '())
(define INITIAL-PVAR-TO-TVARN-ALIST PVAR-TO-TVARN-ALIST)
(define (PVAR-TO-TVARN pvar)
(let ((info (assoc pvar PVAR-TO-TVARN-ALIST)))
(if info
(cadr info)
(let ((newtvarn (new-tvar)))
(set! PVAR-TO-TVARN-ALIST
(cons (list pvar newtvarn) PVAR-TO-TVARN-ALIST))
newtvarn))))
; Given a proof and suppose we want to extract its content. Then we
; can concentrate on its computationally relevant parts, and replace
; the rest by newly introduced assumption variables. This is useful
; for efficiency reasons when normalizing, and also for studying the
; need and the effect of pi-normalization, simplification and pruning.
(define (nbe-normalize-proof-without-eta proof)
(nbe-normalize-proof-without-eta-aux proof #f #t))
(define (nbe-normalize-proof-without-eta-for-extraction proof)
(nbe-normalize-proof-without-eta-aux
proof #t (not (formula-of-nulltype? (proof-to-formula proof)))))
(define (nbe-normalize-proof-without-eta-aux
proof extraction-flag content-flag)
(if
(and extraction-flag (not content-flag))
(let* ((proof-and-asubst (proof-to-c-r-proof-and-asubst proof))
(proof1 (car proof-and-asubst))
(asubst1 (cadr proof-and-asubst))
(nproof1 (nbe-normalize-proof-without-eta proof1)))
(proof-substitute nproof1 asubst1))
(let* ((formula (proof-to-formula proof))
(genavars (append (proof-to-free-and-bound-avars proof)
(proof-to-aconsts-without-rules proof)))
(vars (map (lambda (x)
(type-to-new-var
(nbe-formula-to-type
(cond ((avar-form? x) (avar-to-formula x))
((aconst-form? x) (aconst-to-formula x))
(else (myerror
"nbe-normalize-proof"
"genavar expected" x))))))
genavars))
(genavar-var-alist (map (lambda (u x) (list u x)) genavars vars))
(var-genavar-alist (map (lambda (x u) (list x u)) vars genavars))
(pterm (proof-and-genavar-var-alist-to-pterm
genavar-var-alist proof))
(npterm (nbe-normalize-term-without-eta pterm)))
(npterm-and-var-genavar-alist-and-formula-to-proof
npterm var-genavar-alist '() (unfold-formula formula)))))
(define (proof-to-c-r-proof-and-asubst proof)
(if
(formula-of-nulltype? (proof-to-formula proof))
(let* ((context (proof-to-context proof))
(cvars (proof-to-cvars proof))
(avar (formula-to-new-avar
(context-and-cvars-and-formula-to-formula
context cvars (proof-to-formula proof)))))
(list
(apply mk-proof-in-elim-form
(append (list (make-proof-in-avar-form avar))
(map (lambda (x) (if (var-form? x)
(make-term-in-var-form x)
(make-proof-in-avar-form x)))
context)))
(list (list avar
(apply mk-proof-in-intro-form
(append context (list proof)))))))
(case (tag proof)
((proof-in-avar-form proof-in-aconst-form) (list proof '()))
((proof-in-imp-intro-form)
(let* ((avar (proof-in-imp-intro-form-to-avar proof))
(kernel (proof-in-imp-intro-form-to-kernel proof))
(prev (proof-to-c-r-proof-and-asubst kernel))
(prev-proof (car prev))
(prev-asubst (cadr prev)))
(list (make-proof-in-imp-intro-form avar prev-proof)
prev-asubst)))
((proof-in-imp-elim-form)
(let* ((op (proof-in-imp-elim-form-to-op proof))
(arg (proof-in-imp-elim-form-to-arg proof))
(prev1 (proof-to-c-r-proof-and-asubst op))
(prev-proof1 (car prev1))
(prev-asubst1 (cadr prev1))
(prev2 (proof-to-c-r-proof-and-asubst arg))
(prev-proof2 (car prev2))
(prev-asubst2 (cadr prev2)))
(list (make-proof-in-imp-elim-form prev-proof1 prev-proof2)
(append prev-asubst1 prev-asubst2))))
((proof-in-and-intro-form)
(let* ((left (proof-in-and-intro-form-to-left proof))
(right (proof-in-and-intro-form-to-right proof))
(prev1 (proof-to-c-r-proof-and-asubst left))
(prev-proof1 (car prev1))
(prev-asubst1 (cadr prev1))
(prev2 (proof-to-c-r-proof-and-asubst right))
(prev-proof2 (car prev2))
(prev-asubst2 (cadr prev2)))
(list (make-proof-in-and-intro-form prev-proof1 prev-proof2)
(append prev-asubst1 prev-asubst2))))
((proof-in-and-elim-left-form)
(let* ((kernel (proof-in-and-elim-left-form-to-kernel proof))
(prev (proof-to-c-r-proof-and-asubst kernel))
(prev-proof (car prev))
(prev-asubst (cadr prev)))
(list (make-proof-in-and-elim-left-form prev-proof) prev-asubst)))
((proof-in-and-elim-right-form)
(let* ((kernel (proof-in-and-elim-right-form-to-kernel proof))
(prev (proof-to-c-r-proof-and-asubst kernel))
(prev-proof (car prev))
(prev-asubst (cadr prev)))
(list (make-proof-in-and-elim-right-form prev-proof) prev-asubst)))
((proof-in-all-intro-form)
(let* ((var (proof-in-all-intro-form-to-var proof))
(kernel (proof-in-all-intro-form-to-kernel proof))
(prev (proof-to-c-r-proof-and-asubst kernel))
(prev-proof (car prev))
(prev-asubst (cadr prev)))
(list (make-proof-in-all-intro-form var prev-proof)
prev-asubst)))
((proof-in-all-elim-form)
(let* ((op (proof-in-all-elim-form-to-op proof))
(arg (proof-in-all-elim-form-to-arg proof))
(prev (proof-to-c-r-proof-and-asubst op))
(prev-proof (car prev))
(prev-asubst (cadr prev)))
(list (make-proof-in-all-elim-form prev-proof arg) prev-asubst)))
((proof-in-allnc-intro-form)
(let* ((var (proof-in-allnc-intro-form-to-var proof))
(kernel (proof-in-allnc-intro-form-to-kernel proof))
(prev (proof-to-c-r-proof-and-asubst kernel))
(prev-proof (car prev))
(prev-asubst (cadr prev)))
(list (make-proof-in-allnc-intro-form var prev-proof)
prev-asubst)))
((proof-in-allnc-elim-form)
(let* ((op (proof-in-allnc-elim-form-to-op proof))
(arg (proof-in-allnc-elim-form-to-arg proof))
(prev (proof-to-c-r-proof-and-asubst op))
(prev-proof (car prev))
(prev-asubst (cadr prev)))
(list (make-proof-in-allnc-elim-form prev-proof arg) prev-asubst)))
(else (myerror "proof-to-c-r-proof-and-asubst" "not implemented for"
(tag proof))))))
(define (genavar=? genavar1 genavar2)
(or (and (avar-form? genavar1) (avar-form? genavar2)
(avar=? genavar1 genavar2))
(and (aconst-form? genavar1) (aconst-form? genavar2)
(aconst=? genavar1 genavar2))))
(define (proof-and-genavar-var-alist-to-pterm genavar-var-alist proof)
(case (tag proof)
((proof-in-avar-form)
(let* ((avar (proof-in-avar-form-to-avar proof))
(info (assoc-wrt genavar=? avar genavar-var-alist))
(var (cadr info)))
(make-term-in-var-form var)))
((proof-in-aconst-form)
(let* ((aconst (proof-in-aconst-form-to-aconst proof))
(name (aconst-to-name aconst))
(repro-formulas (aconst-to-repro-formulas aconst)))
(if (aconst-without-rules? aconst)
(let ((info (assoc-wrt genavar=? aconst genavar-var-alist)))
(if info
(make-term-in-var-form (cadr info))
(myerror
"proof-and-genavar-var-alist-to-pterm" "genavar expected"
(aconst-to-string aconst))))
(make-term-in-const-form
(cond
((string=? "Ind" name)
(apply all-formulas-to-rec-const repro-formulas))
((string=? "Cases" name)
(all-formula-to-cases-const (car repro-formulas)))
((string=? "GInd" name)
(let* ((uninst-formula (aconst-to-uninst-formula aconst))
(vars (all-form-to-vars uninst-formula))
(m (- (length vars) 1)))
(all-formula-to-grecguard-const (car repro-formulas) m)))
((string=? "Intro" name)
(apply number-and-idpredconst-to-intro-const
repro-formulas)) ;better repro-data
((string=? "Efq" name) ;This is a hack. The formula should be (?)
;in the repro-data but isn't because
;Efq is a global-assumption.
(let ((formula (imp-form-to-conclusion
(allnc-form-to-final-kernel
(aconst-to-formula aconst)))))
(formula-to-efq-const formula)))
((string=? "Elim" name)
(apply imp-formulas-to-rec-const repro-formulas))
((string=? "Ex-Intro" name)
(ex-formula-to-ex-intro-const (car repro-formulas)))
((string=? "Ex-Elim" name)
(apply ex-formula-and-concl-to-ex-elim-const repro-formulas))
(else
(myerror "proof-and-genavar-var-alist-to-pterm" "aconst expected"
name)))))))
((proof-in-imp-intro-form)
(let* ((avar (proof-in-imp-intro-form-to-avar proof))
(kernel (proof-in-imp-intro-form-to-kernel proof))
(info (assoc-wrt avar=? avar genavar-var-alist))
(var (cadr info)))
(make-term-in-abst-form var (proof-and-genavar-var-alist-to-pterm
genavar-var-alist kernel))))
((proof-in-imp-elim-form)
(let* ((op (proof-in-imp-elim-form-to-op proof))
(arg (proof-in-imp-elim-form-to-arg proof)))
(make-term-in-app-form
(proof-and-genavar-var-alist-to-pterm genavar-var-alist op)
(proof-and-genavar-var-alist-to-pterm genavar-var-alist arg))))
((proof-in-impnc-intro-form)
(let* ((avar (proof-in-impnc-intro-form-to-avar proof))
(kernel (proof-in-impnc-intro-form-to-kernel proof))
(info (assoc-wrt avar=? avar genavar-var-alist))
(var (cadr info)))
(make-term-in-abst-form var (proof-and-genavar-var-alist-to-pterm
genavar-var-alist kernel))))
((proof-in-impnc-elim-form)
(let* ((op (proof-in-impnc-elim-form-to-op proof))
(arg (proof-in-impnc-elim-form-to-arg proof)))
(make-term-in-app-form
(proof-and-genavar-var-alist-to-pterm genavar-var-alist op)
(proof-and-genavar-var-alist-to-pterm genavar-var-alist arg))))
((proof-in-and-intro-form)
(let ((left (proof-in-and-intro-form-to-left proof))
(right (proof-in-and-intro-form-to-right proof)))
(make-term-in-pair-form
(proof-and-genavar-var-alist-to-pterm genavar-var-alist left)
(proof-and-genavar-var-alist-to-pterm genavar-var-alist right))))
((proof-in-and-elim-left-form)
(let* ((kernel (proof-in-and-elim-left-form-to-kernel proof)))
(make-term-in-lcomp-form
(proof-and-genavar-var-alist-to-pterm genavar-var-alist kernel))))
((proof-in-and-elim-right-form)
(let* ((kernel (proof-in-and-elim-right-form-to-kernel proof)))
(make-term-in-rcomp-form
(proof-and-genavar-var-alist-to-pterm genavar-var-alist kernel))))
((proof-in-all-intro-form)
(let* ((var (proof-in-all-intro-form-to-var proof))
(kernel (proof-in-all-intro-form-to-kernel proof)))
(make-term-in-abst-form
var (proof-and-genavar-var-alist-to-pterm genavar-var-alist kernel))))
((proof-in-all-elim-form)
(let* ((op (proof-in-all-elim-form-to-op proof))
(arg (proof-in-all-elim-form-to-arg proof)))
(make-term-in-app-form
(proof-and-genavar-var-alist-to-pterm genavar-var-alist op)
arg)))
((proof-in-allnc-intro-form)
(let* ((var (proof-in-allnc-intro-form-to-var proof))
(kernel (proof-in-allnc-intro-form-to-kernel proof)))
(make-term-in-abst-form
var (proof-and-genavar-var-alist-to-pterm genavar-var-alist kernel))))
((proof-in-allnc-elim-form)
(let* ((op (proof-in-allnc-elim-form-to-op proof))
(arg (proof-in-allnc-elim-form-to-arg proof)))
(make-term-in-app-form
(proof-and-genavar-var-alist-to-pterm genavar-var-alist op)
arg)))
(else
(myerror "proof-and-genavar-var-alist-to-pterm" "proof tag expected"
(tag proof)))))
(define (npterm-and-var-genavar-alist-and-formula-to-proof
npterm var-genavar-alist crit formula)
(case (tag npterm)
((term-in-abst-form)
(let* ((npterm-var (term-in-abst-form-to-var npterm))
(npterm-kernel (term-in-abst-form-to-kernel npterm)))
(cond
((imp-form? formula)
(let* ((premise (imp-form-to-premise formula))
(avar (formula-to-new-avar premise))
(conclusion (imp-form-to-conclusion formula)))
(make-proof-in-imp-intro-form
avar
(npterm-and-var-genavar-alist-and-formula-to-proof
npterm-kernel
(cons (list npterm-var avar) var-genavar-alist)
(union (formula-to-free premise) crit)
conclusion))))
((impnc-form? formula)
(let* ((premise (impnc-form-to-premise formula))
(avar (formula-to-new-avar premise))
(conclusion (impnc-form-to-conclusion formula)))
(make-proof-in-impnc-intro-form
avar
(npterm-and-var-genavar-alist-and-formula-to-proof
npterm-kernel
(cons (list npterm-var avar) var-genavar-alist)
(union (formula-to-free premise) crit)
conclusion))))
((all-form? formula)
(let* ((var (all-form-to-var formula))
(kernel (all-form-to-kernel formula))
(var-is-crit? (member var crit))
(new-var (if var-is-crit? (var-to-new-var var) var))
(new-kernel
(if var-is-crit?
(formula-subst kernel var (make-term-in-var-form new-var))
kernel))
(new-npterm-kernel
(if (equal? npterm-var new-var)
npterm-kernel
(term-subst npterm-kernel
npterm-var
(make-term-in-var-form new-var)))))
(make-proof-in-all-intro-form
new-var
(npterm-and-var-genavar-alist-and-formula-to-proof
new-npterm-kernel var-genavar-alist crit new-kernel))))
((allnc-form? formula)
(let* ((var (allnc-form-to-var formula))
(kernel (allnc-form-to-kernel formula))
(var-is-crit? (member var crit))
(new-var (if var-is-crit? (var-to-new-var var) var))
(new-kernel
(if var-is-crit?
(formula-subst kernel var (make-term-in-var-form new-var))
kernel))
(new-npterm-kernel
(if (equal? npterm-var new-var)
npterm-kernel
(term-subst npterm-kernel
npterm-var
(make-term-in-var-form new-var)))))
(make-proof-in-allnc-intro-form
new-var
(npterm-and-var-genavar-alist-and-formula-to-proof
new-npterm-kernel var-genavar-alist crit new-kernel))))
(else
(myerror
"npterm-and-var-genavar-alist-and-formula-to-proof"
"imp- or all-formula expected"
formula)))))
((term-in-pair-form)
(let ((npterm-left (term-in-pair-form-to-left npterm))
(npterm-right (term-in-pair-form-to-right npterm)))
(cond ((and-form? formula)
(let ((left-formula (and-form-to-left formula))
(right-formula (and-form-to-right formula)))
(make-proof-in-and-intro-form
(npterm-and-var-genavar-alist-and-formula-to-proof
npterm-left var-genavar-alist crit left-formula)
(npterm-and-var-genavar-alist-and-formula-to-proof
npterm-right var-genavar-alist crit right-formula))))
(else (myerror
"npterm-and-var-genavar-alist-and-formula-to-proof"
"and-formula expected"
formula)))))
(else
(let ((prev (elim-npterm-and-var-genavar-alist-to-proof
npterm var-genavar-alist crit)))
(if (classical-formula=? formula (proof-to-formula prev))
prev
(myerror "npterm-and-var-genavar-alist-and-formula-to-proof"
"classical equal formulas expected"
formula
(proof-to-formula prev)))))))
(define (elim-npterm-and-var-genavar-alist-to-proof
npterm var-genavar-alist crit)
(case (tag npterm)
((term-in-var-form)
(let* ((var (term-in-var-form-to-var npterm))
(info (assoc var var-genavar-alist)))
(if info
(let ((genavar (cadr info)))
(cond
((avar-form? genavar) (make-proof-in-avar-form genavar))
((aconst-form? genavar) (make-proof-in-aconst-form genavar))
(else (myerror "elim-npterm-and-var-genavar-alist-to-proof"
"unexpected genavar" genavar))))
(myerror
"elim-npterm-and-var-genavar-alist-to-proof" "unexpected term"
npterm))))
((term-in-const-form)
(let* ((const (term-in-const-form-to-const npterm))
(name (const-to-name const))
(repro-formulas (const-to-type-info-or-repro-formulas const)))
(make-proof-in-aconst-form
(cond
((string=? "Rec" name) ;first repro fla depends on type of rec const
(if
(all-form? (car repro-formulas))
(let* ((uninst-recop-type (const-to-uninst-type const))
(f (length (formula-to-free (car repro-formulas))))
(arg-types (arrow-form-to-arg-types uninst-recop-type))
(alg-type (list-ref arg-types f))
(alg-name (alg-form-to-name alg-type))
(transformed-repro-formulas
(list-transform-positive repro-formulas
(lambda (x)
(let* ((type (var-to-type (all-form-to-var x))))
(and (alg-form? type)
(equal? (alg-form-to-name type) alg-name))))))
(repro-formula
(if (= 1 (length transformed-repro-formulas))
(car transformed-repro-formulas)
(myerror
"elim-npterm-and-var-genavar-alist-to-proof"
"unexpected repro formulas" repro-formulas)))
(permuted-repro-formulas
(cons repro-formula
(remove-wrt classical-formula=?
repro-formula repro-formulas))))
(apply all-formulas-to-ind-aconst permuted-repro-formulas))
(let* ((uninst-recop-type (const-to-uninst-type const))
(f (length (formula-to-free (car repro-formulas))))
(arg-types (arrow-form-to-arg-types uninst-recop-type))
(alg-type (list-ref arg-types f))
(alg-name (alg-form-to-name alg-type))
(transformed-repro-formulas
(list-transform-positive repro-formulas
(lambda (x)
(let* ((prem (imp-form-to-premise x))
(pred (predicate-form-to-predicate prem))
(name (idpredconst-to-name pred))
(nbe-alg-name (idpredconst-name-to-nbe-alg-name
name)))
(equal? nbe-alg-name alg-name)))))
(repro-formula
(if (= 1 (length transformed-repro-formulas))
(car transformed-repro-formulas)
(myerror
"elim-npterm-and-var-genavar-alist-to-proof"
"unexpected repro formulas" repro-formulas)))
(permuted-repro-formulas
(cons repro-formula
(remove-wrt classical-formula=?
repro-formula repro-formulas))))
(apply imp-formulas-to-elim-aconst permuted-repro-formulas))))
((string=? "Cases" name)
(all-formula-to-cases-aconst (car repro-formulas)))
((string=? "GRec" name) ;should not happen since "GRec" is not normal
(myerror "elim-npterm-and-var-genavar-alist-to-proof"
"unexpected term"
name))
((string=? "GRecGuard" name)
(let* ((free (formula-to-free (car repro-formulas)))
(f (length free))
(type (term-to-type npterm))
(auxtype (arrow-form-to-final-val-type type f))
(argtypes (arrow-form-to-arg-types
(arrow-form-to-arg-type auxtype)))
(m (length argtypes)))
(all-formula-to-gind-aconst (car repro-formulas) m)))
((string=? "Efq" name)
(formula-to-efq-aconst (car repro-formulas)))
((string=? "Intro" name)
(apply number-and-idpredconst-to-intro-aconst repro-formulas))
((string=? "Ex-Intro" name)
(ex-formula-to-ex-intro-aconst (car repro-formulas)))
((string=? "Ex-Elim" name)
(apply ex-formula-and-concl-to-ex-elim-aconst repro-formulas))
(else (myerror
"elim-npterm-and-var-genavar-alist-to-proof" "unexpected term"
name))))))
((term-in-app-form)
(let* ((op (term-in-app-form-to-op npterm))
(arg (term-in-app-form-to-arg npterm))
(prev1 (elim-npterm-and-var-genavar-alist-to-proof
op var-genavar-alist crit))
(formula ;unfolding might still be necessary for aconsts 02-07-10
(unfold-formula (proof-to-formula prev1))))
(cond
((imp-form? formula)
(make-proof-in-imp-elim-form
prev1
(npterm-and-var-genavar-alist-and-formula-to-proof
arg var-genavar-alist crit (imp-form-to-premise formula))))
((impnc-form? formula)
(make-proof-in-impnc-elim-form
prev1
(npterm-and-var-genavar-alist-and-formula-to-proof
arg var-genavar-alist crit (impnc-form-to-premise formula))))
((all-form? formula) (make-proof-in-all-elim-form prev1 arg))
((allnc-form? formula) (make-proof-in-allnc-elim-form prev1 arg))
(else (myerror "elim-npterm-and-var-genavar-alist-to-proof"
"imp- or all-formula expected"
formula)))))
((term-in-lcomp-form)
(let* ((kernel (term-in-lcomp-form-to-kernel npterm))
(prev (elim-npterm-and-var-genavar-alist-to-proof
kernel var-genavar-alist crit))
(formula (proof-to-formula prev)))
(cond
((and-form? formula)
(make-proof-in-and-elim-left-form prev))
(else (myerror "elim-npterm-and-var-genavar-alist-to-proof"
"and-formula expected"
formula)))))
((term-in-rcomp-form)
(let* ((kernel (term-in-rcomp-form-to-kernel npterm))
(prev (elim-npterm-and-var-genavar-alist-to-proof
kernel var-genavar-alist crit))
(formula (proof-to-formula prev)))
(cond
((and-form? formula)
(make-proof-in-and-elim-right-form prev))
(else (myerror "elim-npterm-and-var-genavar-alist-to-proof"
"and-formula expected"
formula)))))
(else
(myerror "elim-npterm-and-var-genavar-alist-to-proof" "unexpected term"
npterm))))
(define (proof-to-c-r-proof-and-asubst proof)
(if
(formula-of-nulltype? (proof-to-formula proof))
(let* ((context (proof-to-context proof))
(cvars (proof-to-cvars proof))
(avar (formula-to-new-avar
(context-and-cvars-and-formula-to-formula
context cvars (proof-to-formula proof)))))
(list
(apply mk-proof-in-elim-form
(append (list (make-proof-in-avar-form avar))
(map (lambda (x) (if (var-form? x)
(make-term-in-var-form x)
(make-proof-in-avar-form x)))
context)))
(list (list avar
(apply mk-proof-in-intro-form
(append context (list proof)))))))
(case (tag proof)
((proof-in-avar-form proof-in-aconst-form) (list proof '()))
((proof-in-imp-intro-form)
(let* ((avar (proof-in-imp-intro-form-to-avar proof))
(kernel (proof-in-imp-intro-form-to-kernel proof))
(prev (proof-to-c-r-proof-and-asubst kernel))
(prev-proof (car prev))
(prev-asubst (cadr prev)))
(list (make-proof-in-imp-intro-form avar prev-proof)
prev-asubst)))
((proof-in-imp-elim-form)
(let* ((op (proof-in-imp-elim-form-to-op proof))
(arg (proof-in-imp-elim-form-to-arg proof))
(prev1 (proof-to-c-r-proof-and-asubst op))
(prev-proof1 (car prev1))
(prev-asubst1 (cadr prev1))
(prev2 (proof-to-c-r-proof-and-asubst arg))
(prev-proof2 (car prev2))
(prev-asubst2 (cadr prev2)))
(list (make-proof-in-imp-elim-form prev-proof1 prev-proof2)
(append prev-asubst1 prev-asubst2))))
((proof-in-and-intro-form)
(let* ((left (proof-in-and-intro-form-to-left proof))
(right (proof-in-and-intro-form-to-right proof))
(prev1 (proof-to-c-r-proof-and-asubst left))
(prev-proof1 (car prev1))
(prev-asubst1 (cadr prev1))
(prev2 (proof-to-c-r-proof-and-asubst right))
(prev-proof2 (car prev2))
(prev-asubst2 (cadr prev2)))
(list (make-proof-in-and-intro-form prev-proof1 prev-proof2)
(append prev-asubst1 prev-asubst2))))
((proof-in-and-elim-left-form)
(let* ((kernel (proof-in-and-elim-left-form-to-kernel proof))
(prev (proof-to-c-r-proof-and-asubst kernel))
(prev-proof (car prev))
(prev-asubst (cadr prev)))
(list (make-proof-in-and-elim-left-form prev-proof) prev-asubst)))
((proof-in-and-elim-right-form)
(let* ((kernel (proof-in-and-elim-right-form-to-kernel proof))
(prev (proof-to-c-r-proof-and-asubst kernel))
(prev-proof (car prev))
(prev-asubst (cadr prev)))
(list (make-proof-in-and-elim-right-form prev-proof) prev-asubst)))
((proof-in-all-intro-form)
(let* ((var (proof-in-all-intro-form-to-var proof))
(kernel (proof-in-all-intro-form-to-kernel proof))
(prev (proof-to-c-r-proof-and-asubst kernel))
(prev-proof (car prev))
(prev-asubst (cadr prev)))
(list (make-proof-in-all-intro-form var prev-proof)
prev-asubst)))
((proof-in-all-elim-form)
(let* ((op (proof-in-all-elim-form-to-op proof))
(arg (proof-in-all-elim-form-to-arg proof))
(prev (proof-to-c-r-proof-and-asubst op))
(prev-proof (car prev))
(prev-asubst (cadr prev)))
(list (make-proof-in-all-elim-form prev-proof arg) prev-asubst)))
((proof-in-allnc-intro-form)
(let* ((var (proof-in-allnc-intro-form-to-var proof))
(kernel (proof-in-allnc-intro-form-to-kernel proof))
(prev (proof-to-c-r-proof-and-asubst kernel))
(prev-proof (car prev))
(prev-asubst (cadr prev)))
(list (make-proof-in-allnc-intro-form var prev-proof)
prev-asubst)))
((proof-in-allnc-elim-form)
(let* ((op (proof-in-allnc-elim-form-to-op proof))
(arg (proof-in-allnc-elim-form-to-arg proof))
(prev (proof-to-c-r-proof-and-asubst op))
(prev-proof (car prev))
(prev-asubst (cadr prev)))
(list (make-proof-in-allnc-elim-form prev-proof arg) prev-asubst)))
(else (myerror "proof-to-c-r-proof-and-asubst" "not implemented for"
(tag proof))))))
(define (proof-to-eta-nf proof)
(proof-to-eta-nf-aux proof #f #t))
(define (proof-to-eta-nf-for-extraction proof)
(proof-to-eta-nf-aux
proof #t (not (formula-of-nulltype? (proof-to-formula proof)))))
(define (proof-to-eta-nf-aux proof extraction-flag content-flag)
(if
(and extraction-flag (not content-flag))
proof
(case (tag proof)
((proof-in-imp-intro-form) ;[u]Mu -> M, if u is not free in M
(let* ((avar (proof-in-imp-intro-form-to-avar proof))
(kernel (proof-in-imp-intro-form-to-kernel proof))
(prev (proof-to-eta-nf-aux kernel extraction-flag content-flag)))
(if (and (proof-in-imp-elim-form? prev)
(proof=? (proof-in-imp-elim-form-to-arg prev)
(make-proof-in-avar-form avar))
(not (member-wrt
avar=? avar (proof-to-context
(proof-in-imp-elim-form-to-op prev)))))
(proof-in-imp-elim-form-to-op prev)
(make-proof-in-imp-intro-form avar prev))))
((proof-in-imp-elim-form)
(let ((op (proof-in-imp-elim-form-to-op proof))
(arg (proof-in-imp-elim-form-to-arg proof)))
(make-proof-in-imp-elim-form
(proof-to-eta-nf-aux op extraction-flag content-flag)
(proof-to-eta-nf-aux
arg extraction-flag
(not (formula-of-nulltype? (proof-to-formula arg)))))))
((proof-in-impnc-intro-form) ;[u]Mu -> M, if u is not free in M
(let* ((avar (proof-in-impnc-intro-form-to-avar proof))
(kernel (proof-in-impnc-intro-form-to-kernel proof))
(prev (proof-to-eta-nf-aux kernel extraction-flag content-flag)))
(if (and (proof-in-impnc-elim-form? prev)
(proof=? (proof-in-impnc-elim-form-to-arg prev)
(make-proof-in-avar-form avar))
(not (member-wrt
avar=? avar (proof-to-context
(proof-in-impnc-elim-form-to-op prev)))))
(proof-in-impnc-elim-form-to-op prev)
(make-proof-in-impnc-intro-form avar prev))))
((proof-in-impnc-elim-form)
(let ((op (proof-in-impnc-elim-form-to-op proof))
(arg (proof-in-impnc-elim-form-to-arg proof)))
(make-proof-in-impnc-elim-form
(proof-to-eta-nf-aux op extraction-flag content-flag)
(proof-to-eta-nf-aux arg extraction-flag #f))))
((proof-in-and-intro-form) ;(and-intro p_1M p_2M) -> M
(let* ((left (proof-in-and-intro-form-to-left proof))
(right (proof-in-and-intro-form-to-right proof))
(prev-left
(proof-to-eta-nf-aux
left extraction-flag
(not (formula-of-nulltype? (proof-to-formula left)))))
(prev-right
(proof-to-eta-nf-aux
right extraction-flag
(not (formula-of-nulltype? (proof-to-formula right))))))
(if (and (proof-in-and-elim-left-form? prev-left)
(proof-in-and-elim-right-form? prev-right)
(proof=?
(proof-in-and-elim-left-form-to-kernel prev-left)
(proof-in-and-elim-right-form-to-kernel prev-right)))
(proof-in-and-elim-left-form-to-kernel prev-left)
(make-proof-in-and-intro-form prev-left prev-right))))
((proof-in-and-elim-left-form)
(let* ((kernel (proof-in-and-elim-left-form-to-kernel proof))
(prev (proof-to-eta-nf-aux kernel extraction-flag content-flag)))
(if (proof-in-and-intro-form? prev)
(proof-in-and-intro-form-to-left prev)
(make-proof-in-and-elim-left-form prev))))
((proof-in-and-elim-right-form)
(let* ((kernel (proof-in-and-elim-right-form-to-kernel proof))
(prev (proof-to-eta-nf-aux kernel extraction-flag content-flag)))
(if (proof-in-and-intro-form? prev)
(proof-in-and-intro-form-to-right prev)
(make-proof-in-and-elim-right-form prev))))
((proof-in-all-intro-form) ;[x]Mx -> M, if x is not free in M
(let* ((var (proof-in-all-intro-form-to-var proof))
(kernel (proof-in-all-intro-form-to-kernel proof))
(prev (proof-to-eta-nf-aux kernel extraction-flag content-flag)))
(if (and (proof-in-all-elim-form? prev)
(term=? (proof-in-all-elim-form-to-arg prev)
(make-term-in-var-form var))
(not (member var (proof-to-context
(proof-in-all-elim-form-to-op prev)))))
(proof-in-all-elim-form-to-op prev)
(make-proof-in-all-intro-form var prev))))
((proof-in-all-elim-form)
(let ((op (proof-in-all-elim-form-to-op proof))
(arg (proof-in-all-elim-form-to-arg proof)))
(make-proof-in-all-elim-form
(proof-to-eta-nf-aux op extraction-flag content-flag)
(term-to-eta-nf arg))))
((proof-in-allnc-intro-form) ;[x]Mx -> M, if x is not free in M
(let* ((var (proof-in-allnc-intro-form-to-var proof))
(kernel (proof-in-allnc-intro-form-to-kernel proof))
(prev (proof-to-eta-nf-aux kernel extraction-flag content-flag)))
(if (and (proof-in-allnc-elim-form? prev)
(term=? (proof-in-allnc-elim-form-to-arg prev)
(make-term-in-var-form var))
(not (member var (proof-to-context
(proof-in-allnc-elim-form-to-op prev)))))
(proof-in-allnc-elim-form-to-op prev)
(make-proof-in-allnc-intro-form var prev))))
((proof-in-allnc-elim-form)
(let ((op (proof-in-allnc-elim-form-to-op proof))
(arg (proof-in-allnc-elim-form-to-arg proof)))
(make-proof-in-allnc-elim-form
(proof-to-eta-nf-aux op extraction-flag content-flag)
(term-to-eta-nf arg))))
(else proof))))
; For a full normalization of proofs, including permutative
; conversions, we define a preprocessing step that eta expands
; permutative aconsts such that the conclusion is atomic or
; existential.
(define (proof-to-proof-with-eta-expanded-permutative-aconsts proof)
(proof-to-proof-with-eta-expanded-permutative-aconsts-aux proof #f #t))
(define (proof-to-proof-with-eta-expanded-permutative-aconsts-for-extraction
proof)
(proof-to-proof-with-eta-expanded-permutative-aconsts-aux
proof #t (not (formula-of-nulltype? (proof-to-formula proof)))))
(define (proof-to-proof-with-eta-expanded-permutative-aconsts-aux
proof extraction-flag content-flag)
(if
(and extraction-flag (not content-flag))
proof
(case (tag proof)
((proof-in-aconst-form)
(if (permutative-aconst? (proof-in-aconst-form-to-aconst proof))
(permutative-aconst-proof-to-eta-expansion proof)
proof))
((proof-in-imp-intro-form)
(let* ((avar (proof-in-imp-intro-form-to-avar proof))
(kernel (proof-in-imp-intro-form-to-kernel proof)))
(make-proof-in-imp-intro-form
avar (proof-to-proof-with-eta-expanded-permutative-aconsts-aux
kernel extraction-flag content-flag))))
((proof-in-imp-elim-form)
(let ((op (proof-in-imp-elim-form-to-op proof))
(arg (proof-in-imp-elim-form-to-arg proof)))
(make-proof-in-imp-elim-form
(proof-to-proof-with-eta-expanded-permutative-aconsts-aux
op extraction-flag content-flag)
(proof-to-proof-with-eta-expanded-permutative-aconsts-aux
arg extraction-flag
(not (formula-of-nulltype? (proof-to-formula arg)))))))
((proof-in-impnc-intro-form)
(let* ((avar (proof-in-impnc-intro-form-to-avar proof))
(kernel (proof-in-impnc-intro-form-to-kernel proof)))
(make-proof-in-impnc-intro-form
avar (proof-to-proof-with-eta-expanded-permutative-aconsts-aux
kernel extraction-flag content-flag))))
((proof-in-impnc-elim-form)
(let ((op (proof-in-impnc-elim-form-to-op proof))
(arg (proof-in-impnc-elim-form-to-arg proof)))
(make-proof-in-impnc-elim-form
(proof-to-proof-with-eta-expanded-permutative-aconsts-aux
op extraction-flag content-flag)
(if (not extraction-flag)
(proof-to-proof-with-eta-expanded-permutative-aconsts-aux
arg #f #t) ;content flag irrelevant here
arg))))
((proof-in-and-intro-form)
(let* ((left (proof-in-and-intro-form-to-left proof))
(right (proof-in-and-intro-form-to-right proof)))
(make-proof-in-and-intro-form
(proof-to-proof-with-eta-expanded-permutative-aconsts-aux
left extraction-flag
(not (formula-of-nulltype? (proof-to-formula left))))
(proof-to-proof-with-eta-expanded-permutative-aconsts-aux
right extraction-flag
(not (formula-of-nulltype? (proof-to-formula right)))))))
((proof-in-and-elim-left-form)
(let ((kernel (proof-in-and-elim-left-form-to-kernel proof)))
(make-proof-in-and-elim-left-form
(proof-to-proof-with-eta-expanded-permutative-aconsts-aux
kernel extraction-flag content-flag))))
((proof-in-and-elim-right-form)
(let ((kernel (proof-in-and-elim-right-form-to-kernel proof)))
(make-proof-in-and-elim-right-form
(proof-to-proof-with-eta-expanded-permutative-aconsts-aux
kernel extraction-flag content-flag))))
((proof-in-all-intro-form)
(let* ((var (proof-in-all-intro-form-to-var proof))
(kernel (proof-in-all-intro-form-to-kernel proof)))
(make-proof-in-all-intro-form
var (proof-to-proof-with-eta-expanded-permutative-aconsts-aux
kernel extraction-flag content-flag))))
((proof-in-all-elim-form)
(let ((op (proof-in-all-elim-form-to-op proof))
(arg (proof-in-all-elim-form-to-arg proof)))
(make-proof-in-all-elim-form
(proof-to-proof-with-eta-expanded-permutative-aconsts-aux
op extraction-flag content-flag) arg)))
((proof-in-allnc-intro-form)
(let* ((var (proof-in-allnc-intro-form-to-var proof))
(kernel (proof-in-allnc-intro-form-to-kernel proof)))
(make-proof-in-allnc-intro-form
var (proof-to-proof-with-eta-expanded-permutative-aconsts-aux
kernel extraction-flag content-flag))))
((proof-in-allnc-elim-form)
(let ((op (proof-in-allnc-elim-form-to-op proof))
(arg (proof-in-allnc-elim-form-to-arg proof)))
(make-proof-in-allnc-elim-form
(proof-to-proof-with-eta-expanded-permutative-aconsts-aux
op extraction-flag content-flag) arg)))
(else proof))))
(define (permutative-aconst-proof-to-eta-expansion proof)
(let* ((aconst (proof-in-aconst-form-to-aconst proof))
(uninst-formula (aconst-to-uninst-formula aconst))
(final-concl (imp-impnc-all-allnc-form-to-final-conclusion
uninst-formula))
(var-or-prem-list
(imp-impnc-all-allnc-form-to-vars-and-premises uninst-formula))
(pvar (predicate-form-to-predicate final-concl))
(tpinst (aconst-to-tpinst aconst))
(info (assoc pvar tpinst))
(tpinst-without-pvar
(if info
(list-transform-positive tpinst
(lambda (x) (not (equal? (car x) pvar))))
tpinst))
(orig-formula (if info (cterm-to-formula (cadr info)) final-concl))
(formula
(if (quant-form? orig-formula)
(let* ((quant (quant-form-to-quant orig-formula))
(vars (quant-form-to-vars orig-formula))
(kernel (quant-form-to-kernel orig-formula))
(bound-vars (formula-to-bound uninst-formula)))
(if (pair? (intersection vars bound-vars))
(let* ((new-vars (map var-to-new-var vars)))
(make-quant
quant new-vars
(formula-substitute
kernel
(map (lambda (var new-var)
(list var (make-term-in-var-form new-var)))
vars new-vars))))
orig-formula))
orig-formula)))
(case (tag formula)
((imp)
(permutative-aconst-proof-to-eta-expansion-aux
proof var-or-prem-list pvar tpinst-without-pvar formula
make-proof-in-imp-intro-form
(formula-to-new-avar (imp-form-to-premise formula))))
((impnc)
(permutative-aconst-proof-to-eta-expansion-aux
proof var-or-prem-list pvar tpinst-without-pvar formula
make-proof-in-impnc-intro-form
(formula-to-new-avar (impnc-form-to-premise formula))))
((and)
(permutative-aconst-proof-to-eta-expansion-aux
proof var-or-prem-list pvar tpinst-without-pvar formula
make-proof-in-and-intro-form))
((all)
(permutative-aconst-proof-to-eta-expansion-aux
proof var-or-prem-list pvar tpinst-without-pvar formula
make-proof-in-all-intro-form))
((allnc)
(permutative-aconst-proof-to-eta-expansion-aux
proof var-or-prem-list pvar tpinst-without-pvar formula
make-proof-in-allnc-intro-form))
(else proof))))
; permutative-aconst-proof-to-eta-expansion-aux is a generic helper
; function, which does eta-expansion in a perm-aconst with a composite
; formula (imp, impnc, and, all or allnc), where the introduction
; proof constructor is make-intro. It returns the final proof.
(define (permutative-aconst-proof-to-eta-expansion-aux
proof var-or-prem-list pvar tpinst-without-pvar formula
make-intro . possible-avar)
(let* ((aconst (proof-in-aconst-form-to-aconst proof))
(name (aconst-to-name aconst))
(kind (aconst-to-kind aconst))
(uninst-formula (aconst-to-uninst-formula aconst))
(inst-formula (proof-to-formula proof))
(free (formula-to-free inst-formula))
(var-or-inst-prem-list
(imp-impnc-all-allnc-form-to-vars-and-premises
inst-formula (length var-or-prem-list)))
(var-and-args-list ;((var1 arg11 arg12 ..) (var2 args21 arg22 ..) ..)
(do ((l1 var-or-prem-list (cdr l1))
(l2 var-or-inst-prem-list (cdr l2))
(res
'()
(let ((var-or-prem (car l1))
(var-or-inst-prem (car l2)))
(cond
((var-form? var-or-prem)
(cons (list var-or-prem
(make-term-in-var-form var-or-prem))
res))
((not (member pvar (formula-to-pvars var-or-prem)))
(let ((avar (formula-to-new-avar var-or-inst-prem)))
(cons (list avar (make-proof-in-avar-form avar))
res)))
(else
(let*
((l (length
(imp-impnc-all-allnc-form-to-vars-and-premises
var-or-prem)))
(new-avar (formula-to-new-avar var-or-inst-prem))
(inner-var-or-prem-list
(imp-impnc-all-allnc-form-to-vars-and-premises
var-or-inst-prem l))
(inner-vars-and-avars
(map (lambda (x)
(if (var-form? x) x
(formula-to-new-avar x)))
inner-var-or-prem-list))
(inner-elim-proof ;of inst pvar
(apply
mk-proof-in-elim-form
(append
(list (make-proof-in-avar-form new-avar))
(map (lambda (x)
(if (var-form? x)
(make-term-in-var-form x)
(make-proof-in-avar-form x)))
inner-vars-and-avars))))
(abst-applied-inner-elim-proofs
(case (tag formula)
((imp)
(let* ((prem (imp-form-to-premise formula))
(prem-avar (car possible-avar))
(applied-inner-elim-proof
(make-proof-in-imp-elim-form
inner-elim-proof
(make-proof-in-avar-form prem-avar))))
(list
(apply mk-proof-in-intro-form
(append
inner-vars-and-avars
(list applied-inner-elim-proof))))))
((impnc)
(let* ((prem (impnc-form-to-premise formula))
(prem-avar (car possible-avar))
(applied-inner-elim-proof
(make-proof-in-impnc-elim-form
inner-elim-proof
(make-proof-in-avar-form prem-avar))))
(list
(apply mk-proof-in-intro-form
(append
inner-vars-and-avars
(list applied-inner-elim-proof))))))
((and)
(let* ((left (and-form-to-left formula))
(right (and-form-to-right formula))
(applied-inner-elim-proofs
(list (make-proof-in-and-elim-left-form
inner-elim-proof)
(make-proof-in-and-elim-right-form
inner-elim-proof))))
(map (lambda (p)
(apply mk-proof-in-intro-form
(append inner-vars-and-avars
(list p))))
applied-inner-elim-proofs)))
((all)
(let* ((var (all-form-to-var formula))
(applied-inner-elim-proof
(make-proof-in-all-elim-form
inner-elim-proof
(make-term-in-var-form var))))
(list
(apply mk-proof-in-intro-form
(append
inner-vars-and-avars
(list applied-inner-elim-proof))))))
((allnc)
(let* ((var (allnc-form-to-var formula))
(applied-inner-elim-proof
(make-proof-in-allnc-elim-form
inner-elim-proof
(make-term-in-var-form var))))
(list
(apply mk-proof-in-intro-form
(append
inner-vars-and-avars
(list applied-inner-elim-proof))))))
(else (myerror "not implemented")))))
(cons (cons new-avar abst-applied-inner-elim-proofs)
res)))))))
((null? l1) (reverse res))))
(vars (map car var-and-args-list))
(args-list (map cdr var-and-args-list))
(args-left (map car args-list))
(args-right (map (lambda (args)
(if (= 1 (length args)) (car args) (cadr args)))
args-list))
(intro-items
(case (tag formula)
((imp)
(let* ((prem (imp-form-to-premise formula))
(concl (imp-form-to-conclusion formula))
(prem-avar (car possible-avar))
(cterm (make-cterm concl))
(new-tpinst (if (pvar-cterm-equal? pvar cterm)
tpinst-without-pvar
(append tpinst-without-pvar
(list (list pvar cterm)))))
(new-aconst
(let ((aconst-without-repro-formulas
(make-aconst
name kind uninst-formula new-tpinst)))
(apply
make-aconst
(append (list name kind uninst-formula new-tpinst)
(aconst-to-computed-repro-formulas
aconst-without-repro-formulas)))))
(new-inst-formula (aconst-to-inst-formula new-aconst))
(new-free (formula-to-free new-inst-formula)))
(list prem-avar
(apply mk-proof-in-elim-form
(append
(list (permutative-aconst-proof-to-eta-expansion
(make-proof-in-aconst-form new-aconst)))
(map make-term-in-var-form new-free)
args-left)))))
((impnc)
(let* ((prem (impnc-form-to-premise formula))
(concl (impnc-form-to-conclusion formula))
(prem-avar (car possible-avar))
(cterm (make-cterm concl))
(new-tpinst (if (pvar-cterm-equal? pvar cterm)
tpinst-without-pvar
(append tpinst-without-pvar
(list (list pvar cterm)))))
(new-aconst
(let ((aconst-without-repro-formulas
(make-aconst
name kind uninst-formula new-tpinst)))
(apply
make-aconst
(append (list name kind uninst-formula new-tpinst)
(aconst-to-computed-repro-formulas
aconst-without-repro-formulas)))))
(new-inst-formula (aconst-to-inst-formula new-aconst))
(new-free (formula-to-free new-inst-formula)))
(list prem-avar
(apply mk-proof-in-elim-form
(append
(list (permutative-aconst-proof-to-eta-expansion
(make-proof-in-aconst-form new-aconst)))
(map make-term-in-var-form new-free)
args-left)))))
((and)
(let* ((left (and-form-to-left formula))
(right (and-form-to-right formula))
(cterm-left (make-cterm left))
(cterm-right (make-cterm right))
(new-tpinst-left
(if (pvar-cterm-equal? pvar cterm-left)
tpinst-without-pvar
(append tpinst-without-pvar
(list (list pvar cterm-left)))))
(new-tpinst-right
(if (pvar-cterm-equal? pvar cterm-right)
tpinst-without-pvar
(append tpinst-without-pvar
(list (list pvar cterm-right)))))
(new-aconst-left
(let ((aconst-without-repro-formulas
(make-aconst
name kind uninst-formula new-tpinst-left)))
(apply make-aconst
(append
(list name kind uninst-formula new-tpinst-left)
(aconst-to-computed-repro-formulas
aconst-without-repro-formulas)))))
(new-aconst-right
(let ((aconst-without-repro-formulas
(make-aconst
name kind uninst-formula new-tpinst-right)))
(apply make-aconst
(append
(list name kind uninst-formula new-tpinst-right)
(aconst-to-computed-repro-formulas
aconst-without-repro-formulas)))))
(new-inst-formula-left
(aconst-to-inst-formula new-aconst-left))
(new-free-left (formula-to-free new-inst-formula-left))
(new-inst-formula-right
(aconst-to-inst-formula new-aconst-right))
(new-free-right (formula-to-free new-inst-formula-right)))
(list (apply
mk-proof-in-elim-form
(append
(list (permutative-aconst-proof-to-eta-expansion
(make-proof-in-aconst-form new-aconst-left)))
(map make-term-in-var-form new-free-left)
args-left))
(apply
mk-proof-in-elim-form
(append
(list (permutative-aconst-proof-to-eta-expansion
(make-proof-in-aconst-form new-aconst-right)))
(map make-term-in-var-form new-free-right)
args-right)))))
((all)
(let* ((var (all-form-to-var formula))
(kernel (all-form-to-kernel formula))
(cterm (make-cterm kernel))
(new-tpinst (if (pvar-cterm-equal? pvar cterm)
tpinst-without-pvar
(append tpinst-without-pvar
(list (list pvar cterm)))))
(new-aconst
(let ((aconst-without-repro-formulas
(make-aconst
name kind uninst-formula new-tpinst)))
(apply
make-aconst
(append (list name kind uninst-formula new-tpinst)
(aconst-to-computed-repro-formulas
aconst-without-repro-formulas)))))
(new-inst-formula (aconst-to-inst-formula new-aconst))
(new-free (formula-to-free new-inst-formula)))
(list var
(apply mk-proof-in-elim-form
(append
(list (permutative-aconst-proof-to-eta-expansion
(make-proof-in-aconst-form new-aconst)))
(map make-term-in-var-form new-free)
args-left)))))
((allnc)
(let* ((var (allnc-form-to-var formula))
(kernel (allnc-form-to-kernel formula))
(cterm (make-cterm kernel))
(new-tpinst (if (pvar-cterm-equal? pvar cterm)
tpinst-without-pvar
(append tpinst-without-pvar
(list (list pvar cterm)))))
(new-aconst
(let ((aconst-without-repro-formulas
(make-aconst
name kind uninst-formula new-tpinst)))
(apply
make-aconst
(append (list name kind uninst-formula new-tpinst)
(aconst-to-computed-repro-formulas
aconst-without-repro-formulas)))))
(new-inst-formula (aconst-to-inst-formula new-aconst))
(new-free (formula-to-free new-inst-formula)))
(list var
(apply mk-proof-in-elim-form
(append
(list (permutative-aconst-proof-to-eta-expansion
(make-proof-in-aconst-form new-aconst)))
(map make-term-in-var-form new-free)
args-left))))))))
(apply mk-proof-in-intro-form
(append free vars (list (apply make-intro intro-items))))))
; A permutative redex occurs if the conclusion of a permutative
; assumption constant (example: "Ex-Elim"), applied to parameters and
; all side premises, is the main premise of an elimination. We assume
; that this conclusion is a prime or existential formula, since this
; will be the case when normalize-proof-pi is used in normalize-proof.
; Hence the final elimination must be an elimination axiom for an
; inductively defined predicate or else "Ex-Elim".
(define (permutative-aconst? aconst)
(let ((name (aconst-to-name aconst)))
(or
(string=? "Ex-Elim" name)
(string=? "Exnc-Elim" name)
(string=? "If" name)
(let* ((uninst-formula (aconst-to-uninst-formula aconst))
(final-concl (imp-impnc-all-allnc-form-to-final-conclusion
uninst-formula)))
(and
(predicate-form? final-concl)
(pvar-form? (predicate-form-to-predicate final-concl))
(let ((pvar (predicate-form-to-predicate final-concl)))
(and
(or
(null? (arity-to-types (predicate-to-arity pvar)))
(let* ((tpinst (aconst-to-tpinst aconst))
(info (assoc pvar tpinst)))
(and info
(let* ((cterm (cadr info))
(vars (cterm-to-vars cterm))
(formula (cterm-to-formula cterm)))
(null? (intersection vars (formula-to-free formula)))))))
(let* ((prems (imp-impnc-all-allnc-form-to-premises uninst-formula))
(prems-with-pvar
(list-transform-positive prems
(lambda (x) (member pvar (formula-to-pvars x))))))
(apply
and-op
(append
(list (pair? prems-with-pvar))
(map (lambda (prem)
(let ((prem-final-concl
(imp-impnc-all-allnc-form-to-final-conclusion
prem)))
(and
(predicate-form? prem-final-concl)
(equal? pvar (predicate-form-to-predicate
prem-final-concl))
(let ((prem-prems
(imp-impnc-all-allnc-form-to-premises prem)))
(apply and-op
(map (lambda (prem-prem)
(not (member pvar (formula-to-pvars
prem-prem))))
prem-prems))))))
prems)))))))))))
(define (permutative-redex? proof)
(and (or (proof-in-ex-elim-rule-form? proof)
(proof-in-exnc-elim-rule-form? proof))
(let* ((main-premise (car (proof-to-imp-elim-args proof)))
(op (proof-in-elim-form-to-final-op main-premise)))
(and (proof-in-aconst-form? op)
(permutative-aconst? (proof-in-aconst-form-to-aconst op))))))
; Now we define permutative conversions
; We assume that proof is in long normal form, and every variable
; bound in proof by all-intro or imp-intro is not free elsewhere (to
; avoid renaming after permutation). This is the case for proofs
; obtained by nbe-normalize-proof-without-eta.
; For permutative conversion we use an auxiliary function
; (normalize-proof-pi-aux proof extraction-flag content-flag). The
; extraction-flag indicates whether we are interested in extraction
; only. If so, we can disregard (maximal) parts of the proof without
; computational content. The content-flag indicates whether the
; formula of the proof has computational content. This is for
; efficiency only, since it avoids recomputation. When
; extraction-flag is #f content-flag is irrelevant.
(define (normalize-proof-pi proof)
(normalize-proof-pi-aux proof #f #t))
(define (normalize-proof-pi-for-extraction proof)
(normalize-proof-pi-aux
proof #t (not (formula-of-nulltype? (proof-to-formula proof)))))
(define (normalize-proof-pi-aux proof extraction-flag content-flag)
(if
(and extraction-flag (not content-flag))
proof
(if
(permutative-redex? proof)
(let* ((imp-elim-args (proof-to-imp-elim-args proof))
(main-premise (car imp-elim-args))
(side-premise (cadr imp-elim-args))
(op2 (proof-in-elim-form-to-final-op proof)) ;Ex-Elim or Exnc-Elim
(op1 (proof-in-elim-form-to-final-op main-premise))
(aconst1
(begin
(display (aconst-to-name
(proof-in-aconst-form-to-aconst op1)))
(display "/")
(display (aconst-to-name
(proof-in-aconst-form-to-aconst op2)))
(display " ")
(proof-in-aconst-form-to-aconst op1))) ;permutative aconst
(inst-formula1 (aconst-to-inst-formula aconst1))
(free1 (formula-to-free inst-formula1))
(args1 (proof-in-elim-form-to-args main-premise))
(params1 (list-head args1 (length free1)))
(rest-args1 (list-tail args1 (length free1)))
(end-formula (proof-to-formula proof))
(uninst-formula1 (aconst-to-uninst-formula aconst1))
(var-or-prem-list
(imp-impnc-all-allnc-form-to-vars-and-premises uninst-formula1))
(pvar (predicate-form-to-predicate
(imp-impnc-all-allnc-form-to-final-conclusion
uninst-formula1)))
(tpinst (aconst-to-tpinst aconst1))
(info (assoc pvar tpinst))
(tpinst-without-pvar
(if info
(list-transform-positive tpinst
(lambda (x) (not (equal? (car x) pvar))))
tpinst))
(subst-tpinst-without-pvar
(if (equal? (map make-term-in-var-form free1) params1)
tpinst-without-pvar
(let ((subst1 (map (lambda (x y) (list x y)) free1 params1)))
(map (lambda (x)
(if (pvar? (car x))
(list (car x) (cterm-substitute (cadr x) subst1))
x))
tpinst-without-pvar))))
(cterm (make-cterm end-formula))
(new-tpinst
(if (pvar-cterm-equal? pvar cterm)
subst-tpinst-without-pvar
(append subst-tpinst-without-pvar (list (list pvar cterm)))))
(new-aconst1
(let* ((name (aconst-to-name aconst1))
(kind (aconst-to-kind aconst1))
(aconst-without-repro-formulas
(make-aconst name kind uninst-formula1 new-tpinst)))
(apply make-aconst
(append (list name kind uninst-formula1 new-tpinst)
(aconst-to-computed-repro-formulas
aconst-without-repro-formulas)))))
(new-free1 (formula-to-free (aconst-to-inst-formula new-aconst1)))
(rest-args1-pi
(do ((l1 var-or-prem-list (cdr l1))
(l2 rest-args1 (cdr l2))
(res
'()
(let ((uninst-arg (car l1))
(arg1 (car l2)))
(if
(or (term-form? arg1)
(not (member pvar (formula-to-pvars uninst-arg))))
(cons arg1 res)
(let* ((l (length
(imp-impnc-all-allnc-form-to-vars-and-premises
uninst-arg)))
(side-proof-kernel1
(proof-in-intro-form-to-final-kernel arg1 l))
(new-aconst2
(ex-formula-and-concl-to-ex-elim-aconst
(proof-to-formula side-proof-kernel1)
end-formula))
(new-free2 (formula-to-free
(aconst-to-inst-formula new-aconst2)))
(new-side-proof-kernel1
(apply
mk-proof-in-elim-form
(append
(list (make-proof-in-aconst-form new-aconst2))
(map make-term-in-var-form new-free2)
(list side-proof-kernel1 side-premise))))
(abst-new-side-proof-kernel1
(intro-proof-and-new-kernel-and-depth-to-proof
arg1 new-side-proof-kernel1 l)))
(cons abst-new-side-proof-kernel1 res))))))
((null? l1) (reverse res)))))
(normalize-proof-pi-aux
(apply mk-proof-in-elim-form
(append (list (make-proof-in-aconst-form new-aconst1))
(map make-term-in-var-form new-free1)
rest-args1-pi))
extraction-flag content-flag))
;proof is not a permutative redex:
(case (tag proof)
((proof-in-avar-form proof-in-aconst-form) proof)
((proof-in-imp-intro-form)
(let ((avar (proof-in-imp-intro-form-to-avar proof))
(kernel (proof-in-imp-intro-form-to-kernel proof)))
(make-proof-in-imp-intro-form
avar (normalize-proof-pi-aux kernel extraction-flag content-flag))))
((proof-in-imp-elim-form)
(let ((op (proof-in-imp-elim-form-to-op proof))
(arg (proof-in-imp-elim-form-to-arg proof)))
(make-proof-in-imp-elim-form
(normalize-proof-pi-aux op extraction-flag content-flag)
(normalize-proof-pi-aux
arg extraction-flag
(not (formula-of-nulltype? (proof-to-formula arg)))))))
((proof-in-impnc-intro-form)
(let ((avar (proof-in-impnc-intro-form-to-avar proof))
(kernel (proof-in-impnc-intro-form-to-kernel proof)))
(make-proof-in-impnc-intro-form
avar (normalize-proof-pi-aux kernel extraction-flag content-flag))))
((proof-in-impnc-elim-form)
(let ((op (proof-in-impnc-elim-form-to-op proof))
(arg (proof-in-impnc-elim-form-to-arg proof)))
(make-proof-in-impnc-elim-form
(normalize-proof-pi-aux op extraction-flag content-flag)
(if (not extraction-flag)
(normalize-proof-pi-aux arg #f #t) ;content flag irrelevant here
arg))))
((proof-in-and-intro-form)
(let ((left (proof-in-and-intro-form-to-left proof))
(right (proof-in-and-intro-form-to-right proof)))
(make-proof-in-and-intro-form
(normalize-proof-pi-aux
left extraction-flag
(not (formula-of-nulltype? (proof-to-formula left))))
(normalize-proof-pi-aux
right extraction-flag
(not (formula-of-nulltype? (proof-to-formula right)))))))
((proof-in-and-elim-left-form)
(let ((kernel (proof-in-and-elim-left-form-to-kernel proof)))
(make-proof-in-and-elim-left-form
(normalize-proof-pi-aux kernel extraction-flag #t))))
((proof-in-and-elim-right-form)
(let ((kernel (proof-in-and-elim-right-form-to-kernel proof)))
(make-proof-in-and-elim-right-form
(normalize-proof-pi-aux kernel extraction-flag #t))))
((proof-in-all-intro-form)
(let ((var (proof-in-all-intro-form-to-var proof))
(kernel (proof-in-all-intro-form-to-kernel proof)))
(make-proof-in-all-intro-form
var (normalize-proof-pi-aux kernel extraction-flag content-flag))))
((proof-in-all-elim-form)
(let ((op (proof-in-all-elim-form-to-op proof))
(arg (proof-in-all-elim-form-to-arg proof)))
(make-proof-in-all-elim-form
(normalize-proof-pi-aux op extraction-flag content-flag) arg)))
((proof-in-allnc-intro-form)
(let ((var (proof-in-allnc-intro-form-to-var proof))
(kernel (proof-in-allnc-intro-form-to-kernel proof)))
(make-proof-in-allnc-intro-form
var (normalize-proof-pi-aux kernel extraction-flag content-flag))))
((proof-in-allnc-elim-form)
(let ((op (proof-in-allnc-elim-form-to-op proof))
(arg (proof-in-allnc-elim-form-to-arg proof)))
(make-proof-in-allnc-elim-form
(normalize-proof-pi-aux op extraction-flag content-flag) arg)))
(else (myerror "normalize-proof-pi-aux" "proof tag expected"
(tag proof)))))))
; Test function to check normalize-proof-pi
(define (proof-in-permutative-normal-form? proof)
(null? (proof-to-permutative-redexes proof)))
(define (proof-to-permutative-redexes proof)
(if
(permutative-redex? proof)
(let* ((imp-elim-args (proof-to-imp-elim-args proof))
(main-premise (car imp-elim-args))
(side-premise (cadr imp-elim-args))
(op2 (proof-in-elim-form-to-final-op proof)) ;Ex-Elim or Exnc-Elim
(op1 (proof-in-elim-form-to-final-op main-premise))
(aconst1 (proof-in-aconst-form-to-aconst op1))
(aconst2 (proof-in-aconst-form-to-aconst op2)))
(append (list (string-append (aconst-to-name aconst1) "/"
(aconst-to-name aconst2)))
(proof-to-permutative-redexes main-premise)
(proof-to-permutative-redexes side-premise)))
(case (tag proof)
((proof-in-avar-form proof-in-aconst-form) '())
((proof-in-imp-intro-form)
(let ((kernel (proof-in-imp-intro-form-to-kernel proof)))
(proof-to-permutative-redexes kernel)))
((proof-in-imp-elim-form)
(let ((op (proof-in-imp-elim-form-to-op proof))
(arg (proof-in-imp-elim-form-to-arg proof)))
(append (proof-to-permutative-redexes op)
(proof-to-permutative-redexes arg))))
((proof-in-impnc-intro-form)
(let ((kernel (proof-in-impnc-intro-form-to-kernel proof)))
(proof-to-permutative-redexes kernel)))
((proof-in-impnc-elim-form)
(let ((op (proof-in-impnc-elim-form-to-op proof))
(arg (proof-in-impnc-elim-form-to-arg proof)))
(append (proof-to-permutative-redexes op)
(proof-to-permutative-redexes arg))))
((proof-in-and-intro-form)
(let ((left (proof-in-and-intro-form-to-left proof))
(right (proof-in-and-intro-form-to-right proof)))
(append (proof-to-permutative-redexes left)
(proof-to-permutative-redexes right))))
((proof-in-and-elim-left-form)
(proof-to-permutative-redexes
(proof-in-and-elim-left-form-to-kernel proof)))
((proof-in-and-elim-right-form)
(proof-to-permutative-redexes
(proof-in-and-elim-right-form-to-kernel proof)))
((proof-in-all-intro-form)
(let ((kernel (proof-in-all-intro-form-to-kernel proof)))
(proof-to-permutative-redexes kernel)))
((proof-in-all-elim-form)
(let ((op (proof-in-all-elim-form-to-op proof)))
(proof-to-permutative-redexes op)))
((proof-in-allnc-intro-form)
(let ((kernel (proof-in-allnc-intro-form-to-kernel proof)))
(proof-to-permutative-redexes kernel)))
((proof-in-allnc-elim-form)
(let ((op (proof-in-allnc-elim-form-to-op proof)))
(proof-to-permutative-redexes op)))
(else (myerror "proof-to-permutative-redexes" "proof tag expected"
(tag proof))))))
(define (proof-in-beta-normal-form? proof)
(proof-in-beta-normal-form-aux? proof #f #t))
(define (proof-in-beta-normal-form-for-extraction? proof)
(proof-in-beta-normal-form-aux?
proof #t (not (formula-of-nulltype? (proof-to-formula proof)))))
(define (proof-in-beta-normal-form-aux? proof extraction-flag content-flag)
(if
(and extraction-flag (not content-flag))
#t
(case (tag proof)
((proof-in-avar-form proof-in-aconst-form) #t)
((proof-in-imp-intro-form)
(let ((kernel (proof-in-imp-intro-form-to-kernel proof)))
(proof-in-beta-normal-form-aux? kernel extraction-flag content-flag)))
((proof-in-imp-elim-form)
(let ((op (proof-in-imp-elim-form-to-op proof))
(arg (proof-in-imp-elim-form-to-arg proof)))
(cond
((proof-in-imp-intro-form? op) #f)
((and
(proof-in-imp-elim-form? op)
(let ((op1 (proof-in-imp-elim-form-to-op op)))
(and
(proof-in-aconst-form? op1)
(string=? "Ex-Elim" (aconst-to-name
(proof-in-aconst-form-to-aconst op1)))
(let ((arg1 (proof-in-imp-elim-form-to-arg op)))
(and (proof-in-imp-elim-form? arg1)
(let ((op2 (proof-in-imp-elim-form-to-op arg1)))
(and (proof-in-all-elim-form? op2)
(let ((op3 (proof-in-all-elim-form-to-op op2)))
(and (proof-in-aconst-form? op3)
(string=? "Ex-Intro"
(aconst-to-name
(proof-in-aconst-form-to-aconst
op3))))))))))))
#f)
((and
(proof-in-imp-elim-form? op)
(let ((op1 (proof-in-imp-elim-form-to-op op)))
(and
(proof-in-aconst-form? op1)
(string=? "Exnc-Elim" (aconst-to-name
(proof-in-aconst-form-to-aconst op1)))
(let ((arg1 (proof-in-imp-elim-form-to-arg op)))
(and (proof-in-imp-elim-form? arg1)
(let ((op2 (proof-in-imp-elim-form-to-op arg1)))
(and (proof-in-allnc-elim-form? op2)
(let ((op3 (proof-in-allnc-elim-form-to-op op2)))
(and (proof-in-aconst-form? op3)
(string=? "Exnc-Intro"
(aconst-to-name
(proof-in-aconst-form-to-aconst
op3))))))))))))
#f)
(else (and (proof-in-beta-normal-form-aux?
op extraction-flag content-flag)
(proof-in-beta-normal-form-aux?
arg extraction-flag
(not (formula-of-nulltype? (proof-to-formula arg)))))))))
((proof-in-impnc-intro-form)
(let ((kernel (proof-in-impnc-intro-form-to-kernel proof)))
(proof-in-beta-normal-form-aux? kernel extraction-flag content-flag)))
((proof-in-impnc-elim-form)
(let ((op (proof-in-impnc-elim-form-to-op proof))
(arg (proof-in-impnc-elim-form-to-arg proof)))
(if
(proof-in-impnc-intro-form? op)
#f
(proof-in-beta-normal-form-aux? op extraction-flag content-flag))))
((proof-in-and-intro-form)
(let ((left (proof-in-and-intro-form-to-left proof))
(right (proof-in-and-intro-form-to-right proof)))
(and (proof-in-beta-normal-form-aux?
left extraction-flag
(not (formula-of-nulltype? (proof-to-formula left))))
(proof-in-beta-normal-form-aux?
right extraction-flag
(not (formula-of-nulltype? (proof-to-formula right)))))))
((proof-in-and-elim-left-form)
(let ((kernel (proof-in-and-elim-left-form-to-kernel proof)))
(and (not (proof-in-and-intro-form? kernel))
(proof-in-beta-normal-form-aux?
kernel extraction-flag content-flag))))
((proof-in-and-elim-right-form)
(let ((kernel (proof-in-and-elim-right-form-to-kernel proof)))
(and (not (proof-in-and-intro-form? kernel))
(proof-in-beta-normal-form-aux?
kernel extraction-flag content-flag))))
((proof-in-all-intro-form)
(let ((kernel (proof-in-all-intro-form-to-kernel proof)))
(proof-in-beta-normal-form-aux? kernel extraction-flag content-flag)))
((proof-in-all-elim-form)
(let ((op (proof-in-all-elim-form-to-op proof)))
(and
(not (proof-in-all-intro-form? op))
(proof-in-beta-normal-form-aux? op extraction-flag content-flag))))
((proof-in-allnc-intro-form)
(let ((kernel (proof-in-allnc-intro-form-to-kernel proof)))
(proof-in-beta-normal-form-aux? kernel extraction-flag content-flag)))
((proof-in-allnc-elim-form)
(let ((op (proof-in-allnc-elim-form-to-op proof)))
(and
(not (proof-in-allnc-intro-form? op))
(proof-in-beta-normal-form-aux? op extraction-flag content-flag))))
(else (myerror "proof-in-beta-normal-form-aux?" "proof tag expected"
(tag proof))))))
; Normalization of proofs is made more efficient by allowing to know
; whether one is interested in extraction, and if so, disregard parts
; of the proof without computational content. The extraction-flag
; indicates whether we are interested in extraction only. If so, we
; can disregard (maximal) parts of the proof without computational
; content. The content-flag indicates whether the formula of the
; proof has computational content. This is for efficiency only, since
; it avoids recomputation. When extraction-flag is #f content-flag is
; irrelevant.
(define (nbe-normalize-proof proof)
(nbe-normalize-proof-aux proof #f #t))
(define (nbe-normalize-proof-for-extraction proof)
(nbe-normalize-proof-aux
proof #t (not (formula-of-nulltype? (proof-to-formula proof)))))
(define (nbe-normalize-proof-aux proof extraction-flag content-flag)
(let ((init (normalize-proof-pi-aux
(nbe-normalize-proof-without-eta-aux
(proof-to-proof-with-eta-expanded-permutative-aconsts-aux
proof extraction-flag content-flag)
extraction-flag content-flag)
extraction-flag content-flag)))
(do ((p init (normalize-proof-pi-aux
(nbe-normalize-proof-without-eta-aux
p extraction-flag content-flag)
extraction-flag content-flag)))
((proof-in-beta-normal-form-aux? p extraction-flag content-flag)
(proof-to-eta-nf-aux p extraction-flag content-flag)))))
(define np nbe-normalize-proof)
(define npe nbe-normalize-proof-for-extraction)
; Now proof transformations (Prawitz' simplification, removal of
; predecided avars, removal of predecided if theorems, generalized
; pruning).
; Simplification conversions (Prawitz) make use of the concept of a
; permutative aconst. It is checked whether one side-proof-kernel has
; no free occurrence of any avar bound in this side-proof.
(define (normalize-proof-simp proof)
(case (tag proof)
((proof-in-avar-form proof-in-aconst-form) proof)
((proof-in-imp-intro-form)
(let ((avar (proof-in-imp-intro-form-to-avar proof))
(kernel (proof-in-imp-intro-form-to-kernel proof)))
(make-proof-in-imp-intro-form avar (normalize-proof-simp kernel))))
((proof-in-impnc-intro-form)
(let ((avar (proof-in-impnc-intro-form-to-avar proof))
(kernel (proof-in-impnc-intro-form-to-kernel proof)))
(make-proof-in-impnc-intro-form avar (normalize-proof-simp kernel))))
((proof-in-and-intro-form)
(let ((left (proof-in-and-intro-form-to-left proof))
(right (proof-in-and-intro-form-to-right proof)))
(make-proof-in-and-intro-form (normalize-proof-simp left)
(normalize-proof-simp right))))
((proof-in-and-elim-left-form)
(make-proof-in-and-elim-left-form
(normalize-proof-simp (proof-in-and-elim-left-form-to-kernel proof))))
((proof-in-and-elim-right-form)
(make-proof-in-and-elim-right-form
(normalize-proof-simp (proof-in-and-elim-right-form-to-kernel proof))))
((proof-in-all-intro-form)
(let ((var (proof-in-all-intro-form-to-var proof))
(kernel (proof-in-all-intro-form-to-kernel proof)))
(make-proof-in-all-intro-form var (normalize-proof-simp kernel))))
((proof-in-allnc-intro-form)
(let ((var (proof-in-allnc-intro-form-to-var proof))
(kernel (proof-in-allnc-intro-form-to-kernel proof)))
(make-proof-in-allnc-intro-form var (normalize-proof-simp kernel))))
((proof-in-imp-elim-form
proof-in-impnc-elim-form
proof-in-all-elim-form
proof-in-allnc-elim-form)
(let* ((op (proof-in-elim-form-to-final-op proof))
(args (proof-in-elim-form-to-args proof))
(simp-args (map (lambda (arg)
(if (proof-form? arg)
(normalize-proof-simp arg)
arg))
args)))
(if
(not (proof-in-aconst-form? op))
(apply mk-proof-in-elim-form (cons op simp-args))
(let ((aconst (proof-in-aconst-form-to-aconst op)))
(if
(not (permutative-aconst? aconst))
(apply mk-proof-in-elim-form (cons op simp-args))
(let* ((uninst-formula (aconst-to-uninst-formula aconst))
(var-or-prem-list
(imp-impnc-all-allnc-form-to-vars-and-premises
uninst-formula))
(inst-formula (aconst-to-inst-formula aconst))
(free (formula-to-free inst-formula)))
(if
(< (length args) (length free))
(apply mk-proof-in-elim-form (cons op simp-args))
(let ((params (list-head args (length free)))
(rest-args (list-tail simp-args (length free))))
(if
(< (length rest-args) (length var-or-prem-list))
(apply mk-proof-in-elim-form (cons op simp-args))
(let*
((further-rest-args
(list-tail rest-args (length var-or-prem-list)))
(final-concl
(imp-impnc-all-allnc-form-to-final-conclusion
uninst-formula))
(pvar (predicate-form-to-predicate final-concl))
(prems
(imp-impnc-all-allnc-form-to-premises uninst-formula))
(prems-with-pvar
(list-transform-positive prems
(lambda (x) (member pvar (formula-to-pvars x)))))
(args-for-simplification
(do ((l1 var-or-prem-list (cdr l1))
(l2 rest-args (cdr l2))
(res
'()
(let ((var-or-prem (car l1))
(arg (car l2)))
(if
(or
(var-form? var-or-prem)
(not (member
pvar (formula-to-pvars var-or-prem))))
res
(let*
((prem-var-or-prem-list
(imp-impnc-all-allnc-form-to-vars-and-premises
var-or-prem))
(l (length prem-var-or-prem-list))
(side-proof-kernel
(proof-in-intro-form-to-final-kernel
arg l))
(side-proof-vars
(proof-in-intro-form-to-vars arg l)))
(if (pair?
(intersection-wrt
avar=?
(proof-to-free-avars side-proof-kernel)
side-proof-vars))
res
(cons side-proof-kernel res)))))))
((null? l1) (reverse res)))))
(cond
((null? args-for-simplification)
(apply mk-proof-in-elim-form (cons op simp-args)))
((null? further-rest-args)
(car args-for-simplification))
(else (normalize-proof-simp
(apply mk-proof-in-elim-form
(cons (car args-for-simplification)
further-rest-args)))))))))))))))
(else (myerror "normalize-proof-simp" "proof tag expected"
(tag proof)))))
; proof-to-proof-without-predecided-avars removes dependencies on
; avars, and in this way helps to make normalize-proof-simp useful.
(define (proof-to-proof-without-predecided-avars proof)
(proof-and-context-to-proof-without-predecided-avars proof '()))
(define (proof-and-context-to-proof-without-predecided-avars proof context)
(case (tag proof)
((proof-in-avar-form proof-in-aconst-form) proof)
((proof-in-imp-intro-form)
(let* ((avar (proof-in-imp-intro-form-to-avar proof))
(kernel (proof-in-imp-intro-form-to-kernel proof))
(avars (context-to-avars context))
(previous-avar (do ((l avars (cdr l))
(res #f (if (classical-formula=?
(avar-to-formula (car l))
(avar-to-formula avar))
(car l)
#f)))
((or res (null? l)) res))))
(make-proof-in-imp-intro-form
avar (proof-and-context-to-proof-without-predecided-avars
(if previous-avar
(proof-subst kernel avar (make-proof-in-avar-form
previous-avar))
kernel)
(append context (list avar))))))
((proof-in-imp-elim-form)
(let ((op (proof-in-imp-elim-form-to-op proof))
(arg (proof-in-imp-elim-form-to-arg proof)))
(make-proof-in-imp-elim-form
(proof-and-context-to-proof-without-predecided-avars op context)
(proof-and-context-to-proof-without-predecided-avars arg context))))
((proof-in-impnc-intro-form)
(let* ((avar (proof-in-impnc-intro-form-to-avar proof))
(kernel (proof-in-impnc-intro-form-to-kernel proof))
(avars (context-to-avars context))
(previous-avar (do ((l avars (cdr l))
(res #f (if (classical-formula=?
(avar-to-formula (car l))
(avar-to-formula avar))
(car l)
#f)))
((or res (null? l)) res))))
(make-proof-in-impnc-intro-form
avar (proof-and-context-to-proof-without-predecided-avars
(if previous-avar
(proof-subst kernel avar (make-proof-in-avar-form
previous-avar))
kernel)
(append context (list avar))))))
((proof-in-impnc-elim-form)
(let ((op (proof-in-impnc-elim-form-to-op proof))
(arg (proof-in-impnc-elim-form-to-arg proof)))
(make-proof-in-impnc-elim-form
(proof-and-context-to-proof-without-predecided-avars op context)
(proof-and-context-to-proof-without-predecided-avars arg context))))
((proof-in-and-intro-form)
(let ((left (proof-in-and-intro-form-to-left proof))
(right (proof-in-and-intro-form-to-right proof)))
(make-proof-in-and-intro-form
(proof-and-context-to-proof-without-predecided-avars left context)
(proof-and-context-to-proof-without-predecided-avars right context))))
((proof-in-and-elim-left-form)
(let ((kernel (proof-in-and-elim-left-form-to-kernel proof)))
(make-proof-in-and-elim-left-form
(proof-and-context-to-proof-without-predecided-avars kernel context))))
((proof-in-and-elim-right-form)
(let ((kernel (proof-in-and-elim-right-form-to-kernel proof)))
(make-proof-in-and-elim-right-form
(proof-and-context-to-proof-without-predecided-avars kernel context))))
((proof-in-all-intro-form)
(let ((var (proof-in-all-intro-form-to-var proof))
(kernel (proof-in-all-intro-form-to-kernel proof)))
(make-proof-in-all-intro-form
var (proof-and-context-to-proof-without-predecided-avars
kernel (append context (list var))))))
((proof-in-all-elim-form)
(let ((op (proof-in-all-elim-form-to-op proof))
(arg (proof-in-all-elim-form-to-arg proof)))
(make-proof-in-all-elim-form
(proof-and-context-to-proof-without-predecided-avars op context)
arg)))
((proof-in-allnc-intro-form)
(let ((var (proof-in-allnc-intro-form-to-var proof))
(kernel (proof-in-allnc-intro-form-to-kernel proof)))
(make-proof-in-allnc-intro-form
var (proof-and-context-to-proof-without-predecided-avars
kernel (append context (list var))))))
((proof-in-allnc-elim-form)
(let ((op (proof-in-allnc-elim-form-to-op proof))
(arg (proof-in-allnc-elim-form-to-arg proof)))
(make-proof-in-allnc-elim-form
(proof-and-context-to-proof-without-predecided-avars op context)
arg)))
(else
(myerror "proof-and-context-to-proof-without-predecided-avars"
"unexpected proof tag" (tag proof)))))
; Removal of predecided If's (special for pruning), including those
; with True or False as boolean arguments. negatom-context consists
; of all atomic or negated avars in the present context.
(define (remove-predecided-if-theorems proof)
(remove-predecided-if-theorems-aux proof '()))
(define (remove-predecided-if-theorems-aux proof negatom-context)
(case (tag proof)
((proof-in-avar-form proof-in-aconst-form) proof)
((proof-in-imp-intro-form)
(let* ((avar (proof-in-imp-intro-form-to-avar proof))
(kernel (proof-in-imp-intro-form-to-kernel proof))
(formula (avar-to-formula avar))
(new-negatom-context ;add avar if a (possibly negated) atom
(if (or (atom-form? formula)
(and (imp-form? formula)
(atom-form? (imp-form-to-premise formula))
(formula=? (imp-form-to-conclusion formula)
falsity)))
(cons avar negatom-context)
negatom-context))
(prev (remove-predecided-if-theorems-aux
kernel new-negatom-context)))
(make-proof-in-imp-intro-form avar prev)))
((proof-in-imp-elim-form)
(let* ((final-op (proof-in-elim-form-to-final-op proof))
(args (proof-in-elim-form-to-args proof)))
(if ;If-theorem with exactly 3 non-parameter args
(and
(proof-in-aconst-form? final-op)
(let* ((aconst (proof-in-aconst-form-to-aconst final-op))
(name (aconst-to-name aconst)))
(and
(string=? "If" name)
(let* ((term-args (do ((l args (cdr l))
(res '() (if (term-form? (car l))
(cons (car l) res)
(cons #f res))))
((not (term-form? (car l))) (reverse res))))
(rest-args (list-tail args (length term-args))))
(and (= 2 (length rest-args))
(proof-in-imp-intro-form? (car rest-args))
(proof-in-imp-intro-form? (cadr rest-args)))))))
(let* ((term-args (do ((l args (cdr l))
(res '() (if (term-form? (car l))
(cons (car l) res)
(cons #f res))))
((not (term-form? (car l))) (reverse res))))
(boolean-arg (car (last-pair term-args)))
(rest-args (list-tail args (length term-args))))
(cond
((term=? (make-term-in-const-form true-const) boolean-arg)
(let* ((arg1 (car rest-args))
(avar1 (proof-in-imp-intro-form-to-avar arg1))
(kernel1 (proof-in-imp-intro-form-to-kernel arg1))
(subst-kernel (proof-subst
kernel1 avar1
(make-proof-in-aconst-form truth-aconst))))
(remove-predecided-if-theorems-aux subst-kernel negatom-context)))
((term=? (make-term-in-const-form false-const) boolean-arg)
(let* ((arg2 (cadr rest-args))
(avar2 (proof-in-imp-intro-form-to-avar arg2))
(kernel2 (proof-in-imp-intro-form-to-kernel arg2))
(false-avar (formula-to-new-avar falsity))
(subst-kernel (proof-subst
kernel2 avar2
(make-proof-in-imp-intro-form
false-avar
(make-proof-in-avar-form false-avar)))))
(remove-predecided-if-theorems-aux
subst-kernel negatom-context)))
(else
(let ((proof (negatom-context-and-bterm-to-proof
negatom-context boolean-arg)))
(if ;proof is found
proof
(if ;proof of (atom boolean-arg)
(atom-form? (proof-to-formula proof))
(let* ((arg1 (car rest-args))
(avar1 (proof-in-imp-intro-form-to-avar arg1))
(kernel1 (proof-in-imp-intro-form-to-kernel arg1))
(subst-kernel1 (proof-subst kernel1 avar1 proof)))
(remove-predecided-if-theorems-aux
subst-kernel1 negatom-context))
;or proof of (atom boolean-arg) -> F
(let* ((arg2 (cadr rest-args))
(avar2 (proof-in-imp-intro-form-to-avar arg2))
(kernel2 (proof-in-imp-intro-form-to-kernel arg2))
(subst-kernel2 (proof-subst kernel2 avar2 proof)))
(remove-predecided-if-theorems-aux
subst-kernel2 negatom-context)))
(apply
mk-proof-in-elim-form
(append (list final-op)
term-args
(list (remove-predecided-if-theorems-aux
(car rest-args) negatom-context)
(remove-predecided-if-theorems-aux
(cadr rest-args) negatom-context)))))))))
(let* ((op (proof-in-imp-elim-form-to-op proof))
(arg (proof-in-imp-elim-form-to-arg proof))
(prev1 (remove-predecided-if-theorems-aux
op negatom-context))
(prev2 (remove-predecided-if-theorems-aux
arg negatom-context)))
(make-proof-in-imp-elim-form prev1 prev2)))))
((proof-in-and-intro-form)
(let* ((left (proof-in-and-intro-form-to-left proof))
(right (proof-in-and-intro-form-to-right proof))
(prev1 (remove-predecided-if-theorems-aux left negatom-context))
(prev2 (remove-predecided-if-theorems-aux right negatom-context)))
(make-proof-in-and-intro-form prev1 prev2)))
((proof-in-and-elim-left-form)
(let* ((kernel (proof-in-and-elim-left-form-to-kernel proof))
(prev (remove-predecided-if-theorems-aux kernel negatom-context)))
(make-proof-in-and-elim-left-form prev)))
((proof-in-and-elim-right-form)
(let* ((kernel (proof-in-and-elim-right-form-to-kernel proof))
(prev (remove-predecided-if-theorems-aux kernel negatom-context)))
(make-proof-in-and-elim-right-form prev)))
((proof-in-all-intro-form)
(let* ((var (proof-in-all-intro-form-to-var proof))
(kernel (proof-in-all-intro-form-to-kernel proof))
(prev (remove-predecided-if-theorems-aux kernel negatom-context)))
(make-proof-in-all-intro-form var prev)))
((proof-in-all-elim-form)
(let* ((op (proof-in-all-elim-form-to-op proof))
(arg (proof-in-all-elim-form-to-arg proof))
(prev (remove-predecided-if-theorems-aux op negatom-context)))
(make-proof-in-all-elim-form prev arg)))
((proof-in-allnc-intro-form)
(let* ((var (proof-in-allnc-intro-form-to-var proof))
(kernel (proof-in-allnc-intro-form-to-kernel proof))
(prev (remove-predecided-if-theorems-aux kernel negatom-context)))
(make-proof-in-allnc-intro-form var prev)))
((proof-in-allnc-elim-form)
(let* ((op (proof-in-allnc-elim-form-to-op proof))
(arg (proof-in-allnc-elim-form-to-arg proof))
(prev (remove-predecided-if-theorems-aux op negatom-context)))
(make-proof-in-allnc-elim-form prev arg)))
(else (myerror "remove-predecided-if-theorems-aux"
"not implemented for" (tag proof)))))
; term-to-minuend-and-subtrahends writes the term in the form
; j--i0--i1..--in and returns j and the list (i0 i1 .. in) (the
; minuend and the subtrahends).
(define (term-to-minuend-and-subtrahends term)
(let ((op (term-in-app-form-to-final-op term)))
(if
(and
(term-in-const-form? op)
(string=? (const-to-name (term-in-const-form-to-const op)) "NatMinus"))
(let* ((args (term-in-app-form-to-args term))
(lhs (car args))
(rhs (cadr args))
(prev (term-to-minuend-and-subtrahends lhs))
(minuend (car prev))
(subtrahends (cadr prev)))
(list minuend (append subtrahends (list rhs))))
(list term '()))))
; (pp (car (term-to-minuend-and-subtrahends (pt "j--i1--i2"))))
; (for-each pp (cadr (term-to-minuend-and-subtrahends (pt "j--i1--i2"))))
; Consider avar:i<=j--i0--i1--i2 and subtrahends (i1 i2). Then j--i0
; is the minuend. We construct a proof of i<=j--i0 from avar.
(define (le-minuend-minus-subtrahends-avar-and-subtrahends-to-proof
avar subtrahends)
(if
(null? subtrahends)
(make-proof-in-avar-form avar)
(let* ((init-subtrahend (car subtrahends)) ;not used!
(rest-subtrahends (cdr subtrahends))
(prev (le-minuend-minus-subtrahends-avar-and-subtrahends-to-proof
avar rest-subtrahends))
(formula (proof-to-formula prev))
(kernel (atom-form-to-kernel formula))
(args (term-in-app-form-to-args kernel))
(lhs (car args))
(minuend (cadr args))
(new-minuend (car (term-in-app-form-to-args minuend))))
(mk-proof-in-elim-form
(make-proof-in-aconst-form (theorem-name-to-aconst "NatLeTrans"))
lhs minuend new-minuend
prev
(make-proof-in-aconst-form truth-aconst)))))
; (cdp (le-minuend-minus-subtrahends-avar-and-subtrahends-to-proof
; (formula-to-new-avar (pf "i<=j--i0--i1--i2"))
; (list (pt "i0") (pt "i1") (pt "i2"))))
; negatom-context-and-bterm-to-proof returns either a proof of bterm
; from the positive context or else a proof of the negation of bterm
; from the negative context if it finds one of them, and #f otherwise.
; Because of its usage of term-to-minuend-and-subtrahends and
; le-minuend-minus-subtrahends-avar-and-subtrahends-to-proof it is
; designed for use in the binpack case study, where the boolean terms
; are of the form i<=j--i0--...--in. It would be better if a more
; general decision procedure is used (simplex-algorithm?).
(define (negatom-context-and-bterm-to-proof negatom-context bterm)
(let ((op (term-in-app-form-to-final-op bterm)))
(and
(term-in-const-form? op)
(string=? (const-to-name (term-in-const-form-to-const op)) "NatLe")
(let* ((args (term-in-app-form-to-args bterm))
(lhs (car args))
(rhs (cadr args))
(minuend-and-subtrahends (term-to-minuend-and-subtrahends rhs))
(minuend (car minuend-and-subtrahends))
(subtrahends (cadr minuend-and-subtrahends))
(pos-fitting-context
(list-transform-positive negatom-context
(lambda (avar)
(let ((avar-fla (avar-to-formula avar)))
(and
(atom-form? avar-fla)
(let* ((avar-kernel (atom-form-to-kernel avar-fla))
(avar-op
(term-in-app-form-to-final-op avar-kernel)))
(and
(term-in-const-form? avar-op)
(string=?
(const-to-name (term-in-const-form-to-const avar-op))
"NatLe")
(let* ((avar-args
(term-in-app-form-to-args avar-kernel))
(avar-lhs (car avar-args))
(avar-rhs (cadr avar-args))
(avar-minuend-and-subtrahends
(term-to-minuend-and-subtrahends avar-rhs))
(avar-minuend (car avar-minuend-and-subtrahends))
(avar-subtrahends
(cadr avar-minuend-and-subtrahends)))
(and
(term=? lhs avar-lhs)
(term=? minuend avar-minuend)
(<= (length subtrahends) (length avar-subtrahends))
(apply and-op
(map term=?
subtrahends
(list-head
avar-subtrahends
(length subtrahends)))))))))))))
(neg-fitting-context
(list-transform-positive negatom-context
(lambda (avar)
(let ((avar-fla (avar-to-formula avar)))
(and
(imp-impnc-form? avar-fla)
(formula=? (imp-impnc-form-to-conclusion avar-fla)
falsity)
(atom-form? (imp-impnc-form-to-premise avar-fla))
(let* ((avar-atom (imp-impnc-form-to-premise avar-fla))
(avar-kernel (atom-form-to-kernel avar-atom))
(avar-op
(term-in-app-form-to-final-op avar-kernel)))
(and
(term-in-const-form? avar-op)
(string=?
(const-to-name (term-in-const-form-to-const avar-op))
"NatLe")
(let* ((avar-args
(term-in-app-form-to-args avar-kernel))
(avar-lhs (car avar-args))
(avar-rhs (cadr avar-args))
(avar-minuend-and-subtrahends
(term-to-minuend-and-subtrahends avar-rhs))
(avar-minuend (car avar-minuend-and-subtrahends))
(avar-subtrahends
(cadr avar-minuend-and-subtrahends)))
(and
(term=? lhs avar-lhs)
(term=? minuend avar-minuend)
(<= (length avar-subtrahends) (length subtrahends))
(apply and-op
(map term=?
avar-subtrahends
(list-head
subtrahends
(length avar-subtrahends))))))))))))))
(and
(or (pair? pos-fitting-context) (pair? neg-fitting-context))
(if (pair? pos-fitting-context)
(let* ((avar (car pos-fitting-context))
(avar-fla (avar-to-formula avar))
(avar-kernel (atom-form-to-kernel avar-fla))
(avar-args (term-in-app-form-to-args avar-kernel))
(avar-rhs (cadr avar-args))
(avar-minuend-and-subtrahends
(term-to-minuend-and-subtrahends avar-rhs))
(avar-subtrahends (cadr avar-minuend-and-subtrahends))
(rest-avar-subtrahends
(list-tail avar-subtrahends (length subtrahends))))
(le-minuend-minus-subtrahends-avar-and-subtrahends-to-proof
avar rest-avar-subtrahends))
;else (pair? neg-fitting-context)
(let* ((avar (car neg-fitting-context))
(avar-fla (avar-to-formula avar))
(avar-atom (imp-impnc-form-to-premise avar-fla))
(avar-kernel (atom-form-to-kernel avar-atom))
(avar-args (term-in-app-form-to-args avar-kernel))
(avar-rhs (cadr avar-args))
(avar-minuend-and-subtrahends
(term-to-minuend-and-subtrahends avar-rhs))
(avar-subtrahends (cadr avar-minuend-and-subtrahends))
(rest-subtrahends
(list-tail subtrahends (length avar-subtrahends)))
(bterm-atom (make-atomic-formula bterm))
(bterm-avar (formula-to-new-avar bterm-atom))
(proof-of-avar-prem
(le-minuend-minus-subtrahends-avar-and-subtrahends-to-proof
bterm-avar rest-subtrahends))
(proof-of-falsity
(mk-proof-in-elim-form
(make-proof-in-avar-form avar) proof-of-avar-prem)))
(make-proof-in-imp-intro-form
bterm-avar proof-of-falsity))))))))
; Generalization of Prawitz' simplification: pruning. A problem with
; prune is that is is slow. For efficiency the proof is first turned
; into an acproof, to avoid recomputation of avar-contexts when
; pruning.
(define (prune proof)
(acproof-to-pruned-proof (proof-to-acproof proof)))
(define (acproof-to-pruned-proof acproof)
(let ((formula (proof-to-formula acproof)))
(case (tag acproof)
((proof-in-avar-form proof-in-aconst-form) acproof)
((proof-in-imp-intro-form)
(let* ((avar (proof-in-imp-intro-form-to-avar acproof))
(kernel (proof-in-imp-intro-form-to-kernel acproof))
(proof-of-formula-or-f (prune-aux formula (list avar) kernel)))
(if proof-of-formula-or-f
(acproof-to-pruned-proof proof-of-formula-or-f)
(make-proof-in-imp-intro-form
avar (acproof-to-pruned-proof kernel)))))
((proof-in-imp-elim-form)
(let* ((op (proof-in-imp-elim-form-to-op acproof))
(arg (proof-in-imp-elim-form-to-arg acproof))
(proof-of-formula-or-f1 (prune-aux formula '() op)))
(if
proof-of-formula-or-f1
(acproof-to-pruned-proof proof-of-formula-or-f1)
(let ((proof-of-formula-or-f2 (prune-aux formula '() arg)))
(if
proof-of-formula-or-f2
(acproof-to-pruned-proof proof-of-formula-or-f2)
(make-proof-in-imp-elim-form
(acproof-to-pruned-proof op) (acproof-to-pruned-proof arg)))))))
((proof-in-impnc-intro-form)
(let* ((avar (proof-in-impnc-intro-form-to-avar acproof))
(kernel (proof-in-impnc-intro-form-to-kernel acproof))
(proof-of-formula-or-f (prune-aux formula (list avar) kernel)))
(if proof-of-formula-or-f
(acproof-to-pruned-proof proof-of-formula-or-f)
(make-proof-in-impnc-intro-form
avar (acproof-to-pruned-proof kernel)))))
((proof-in-impnc-elim-form)
(let* ((op (proof-in-impnc-elim-form-to-op acproof))
(arg (proof-in-impnc-elim-form-to-arg acproof))
(proof-of-formula-or-f1 (prune-aux formula '() op)))
(if
proof-of-formula-or-f1
(acproof-to-pruned-proof proof-of-formula-or-f1)
(let ((proof-of-formula-or-f2 (prune-aux formula '() arg)))
(if
proof-of-formula-or-f2
(acproof-to-pruned-proof proof-of-formula-or-f2)
(make-proof-in-impnc-elim-form
(acproof-to-pruned-proof op) (acproof-to-pruned-proof arg)))))))
((proof-in-and-intro-form)
(let* ((left (proof-in-and-intro-form-to-left acproof))
(right (proof-in-and-intro-form-to-right acproof))
(proof-of-formula-or-f1 (prune-aux formula '() left)))
(if
proof-of-formula-or-f1
(acproof-to-pruned-proof proof-of-formula-or-f1)
(let ((proof-of-formula-or-f2 (prune-aux formula '() right)))
(if
proof-of-formula-or-f2
(acproof-to-pruned-proof proof-of-formula-or-f2)
(make-proof-in-and-intro-form
(acproof-to-pruned-proof left)
(acproof-to-pruned-proof right)))))))
((proof-in-and-elim-left-form)
(let* ((kernel (proof-in-and-elim-left-form-to-kernel acproof))
(proof-of-formula-or-f (prune-aux formula '() kernel)))
(if proof-of-formula-or-f
(acproof-to-pruned-proof proof-of-formula-or-f)
(make-proof-in-and-elim-left-form
(acproof-to-pruned-proof kernel)))))
((proof-in-and-elim-right-form)
(let* ((kernel (proof-in-and-elim-right-form-to-kernel acproof))
(proof-of-formula-or-f (prune-aux formula '() kernel)))
(if proof-of-formula-or-f
(acproof-to-pruned-proof proof-of-formula-or-f)
(make-proof-in-and-elim-right-form
(acproof-to-pruned-proof kernel)))))
((proof-in-all-intro-form)
(let* ((var (proof-in-all-intro-form-to-var acproof))
(kernel (proof-in-all-intro-form-to-kernel acproof))
(proof-of-formula-or-f (prune-aux formula '() kernel)))
(if proof-of-formula-or-f
(acproof-to-pruned-proof proof-of-formula-or-f)
(make-proof-in-all-intro-form
var (acproof-to-pruned-proof kernel)))))
((proof-in-all-elim-form)
(let* ((op (proof-in-all-elim-form-to-op acproof))
(arg (proof-in-all-elim-form-to-arg acproof))
(proof-of-formula-or-f (prune-aux formula '() op)))
(if proof-of-formula-or-f
(acproof-to-pruned-proof proof-of-formula-or-f)
(make-proof-in-all-elim-form
(acproof-to-pruned-proof op) arg))))
((proof-in-allnc-intro-form)
(let* ((var (proof-in-allnc-intro-form-to-var acproof))
(kernel (proof-in-allnc-intro-form-to-kernel acproof))
(proof-of-formula-or-f (prune-aux formula '() kernel)))
(if proof-of-formula-or-f
(acproof-to-pruned-proof proof-of-formula-or-f)
(make-proof-in-allnc-intro-form
var (acproof-to-pruned-proof kernel)))))
((proof-in-allnc-elim-form)
(let* ((op (proof-in-allnc-elim-form-to-op acproof))
(arg (proof-in-allnc-elim-form-to-arg acproof))
(proof-of-formula-or-f (prune-aux formula '() op)))
(if proof-of-formula-or-f
(acproof-to-pruned-proof proof-of-formula-or-f)
(make-proof-in-allnc-elim-form
(acproof-to-pruned-proof op) arg))))
(else (myerror "acproof-to-pruned-proof"
"proof tag expected"
(tag proof))))))
; prune-aux returns #f or the shorter acproof of formula
(define (prune-aux formula bound-avars acproof)
(if
(and
(classical-formula=? formula (proof-to-formula acproof))
(null? (intersection-wrt avar=? bound-avars (proof-to-context acproof))))
acproof
(case (tag acproof)
((proof-in-avar-form proof-in-aconst-form) #f)
((proof-in-imp-intro-form)
(let ((avar (proof-in-imp-intro-form-to-avar acproof))
(kernel (proof-in-imp-intro-form-to-kernel acproof)))
(prune-aux formula (adjoin-wrt avar=? avar bound-avars) kernel)))
((proof-in-imp-elim-form)
(let ((op (proof-in-imp-elim-form-to-op acproof))
(arg (proof-in-imp-elim-form-to-arg acproof)))
(or (prune-aux formula bound-avars op)
(prune-aux formula bound-avars arg))))
((proof-in-impnc-intro-form)
(let ((avar (proof-in-impnc-intro-form-to-avar acproof))
(kernel (proof-in-impnc-intro-form-to-kernel acproof)))
(prune-aux formula (adjoin-wrt avar=? avar bound-avars) kernel)))
((proof-in-impnc-elim-form)
(let ((op (proof-in-impnc-elim-form-to-op acproof))
(arg (proof-in-impnc-elim-form-to-arg acproof)))
(or (prune-aux formula bound-avars op)
(prune-aux formula bound-avars arg))))
((proof-in-and-intro-form)
(let ((left (proof-in-and-intro-form-to-left acproof))
(right (proof-in-and-intro-form-to-right acproof)))
(or (prune-aux formula bound-avars left)
(prune-aux formula bound-avars right))))
((proof-in-and-elim-left-form)
(let ((kernel (proof-in-and-elim-left-form-to-kernel acproof)))
(prune-aux formula bound-avars kernel)))
((proof-in-and-elim-right-form)
(let ((kernel (proof-in-and-elim-right-form-to-kernel acproof)))
(prune-aux formula bound-avars kernel)))
((proof-in-all-intro-form)
(let ((kernel (proof-in-all-intro-form-to-kernel acproof)))
(prune-aux formula bound-avars kernel)))
((proof-in-all-elim-form)
(let ((op (proof-in-all-elim-form-to-op acproof)))
(prune-aux formula bound-avars op)))
((proof-in-allnc-intro-form)
(let ((kernel (proof-in-allnc-intro-form-to-kernel acproof)))
(prune-aux formula bound-avars kernel)))
((proof-in-allnc-elim-form)
(let ((op (proof-in-allnc-elim-form-to-op acproof)))
(prune-aux formula bound-avars op)))
(else (myerror "prune-aux" "proof tag expected" (tag acproof))))))
; For tests it might generally be useful to have a level-wise
; decomposition of proofs into subproofs: one level transforms a proof
; lambda us.v Ms into the list [v M1 ... Mn]
(define (proof-in-intro-form-to-final-kernels proof)
(cond
((proof-in-imp-intro-form? proof)
(proof-in-intro-form-to-final-kernels
(proof-in-imp-intro-form-to-kernel proof)))
((proof-in-impnc-intro-form? proof)
(proof-in-intro-form-to-final-kernels
(proof-in-impnc-intro-form-to-kernel proof)))
((proof-in-and-intro-form? proof)
(append (proof-in-intro-form-to-final-kernels
(proof-in-and-intro-form-to-left proof))
(proof-in-intro-form-to-final-kernels
(proof-in-and-intro-form-to-right proof))))
((proof-in-all-intro-form? proof)
(proof-in-intro-form-to-final-kernels
(proof-in-all-intro-form-to-kernel proof)))
((proof-in-allnc-intro-form? proof)
(proof-in-intro-form-to-final-kernels
(proof-in-allnc-intro-form-to-kernel proof)))
(else (list proof))))
(define (proof-in-elim-form-to-final-op-and-args proof)
(case (tag proof)
((proof-in-imp-elim-form)
(append (proof-in-elim-form-to-final-op-and-args
(proof-in-imp-elim-form-to-op proof))
(proof-in-imp-elim-form-to-arg proof)))
((proof-in-impnc-elim-form)
(append (proof-in-elim-form-to-final-op-and-args
(proof-in-impnc-elim-form-to-op proof))
(proof-in-impnc-elim-form-to-arg proof)))
((proof-in-and-elim-left-form)
(append (proof-in-elim-form-to-final-op-and-args
(proof-in-and-elim-left-form-to-kernel proof))
(list 'left)))
((proof-in-and-elim-right-form)
(append (proof-in-elim-form-to-final-op-and-args
(proof-in-and-elim-right-form-to-kernel proof))
(list 'right)))
((proof-in-all-elim-form)
(append (proof-in-elim-form-to-final-op-and-args
(proof-in-all-elim-form-to-op proof))
(proof-in-all-elim-form-to-arg proof)))
((proof-in-allnc-elim-form)
(append (proof-in-elim-form-to-final-op-and-args
(proof-in-allnc-elim-form-to-op proof))
(proof-in-allnc-elim-form-to-arg proof)))
(else (list proof))))
(define (proof-to-parts-of-level-one proof)
(let* ((final-kernels (proof-in-intro-form-to-final-kernels proof))
(lists (map proof-in-elim-form-to-final-op-and-args final-kernels)))
(apply append lists)))
(define (proof-to-parts proof . opt-level)
(if
(null? opt-level)
(proof-to-parts-of-level-one proof)
(let ((l (car opt-level)))
(if (and (integer? l) (not (negative? l)))
(if (zero? l)
(list proof)
(let* ((parts (proof-to-parts-of-level-one proof))
(proofs (list-transform-positive parts
proof-form?)))
(apply append (map (lambda (x) (proof-to-parts x (- l 1)))
proofs))))
(myerror "proof-to-parts" "non-negative integer expected" l)))))
(define (proof-to-proof-parts proof)
(list-transform-positive (proof-to-parts proof)
proof-form?))
(define (proof-to-depth proof)
(if
(or (proof-in-avar-form? proof)
(proof-in-aconst-form? proof))
0
(let* ((final-kernels (proof-in-intro-form-to-final-kernels proof))
(lists (map proof-in-elim-form-to-final-op-and-args final-kernels))
(proofs (list-transform-positive (apply append lists) proof-form?)))
(+ 1 (apply max (map proof-to-depth proofs))))))
; For testing, beta-normalization by hand.
(define (proof-to-one-step-beta-reduct proof)
(case (tag proof)
((proof-in-avar-form proof-in-aconst-form) proof)
((proof-in-imp-intro-form)
(make-proof-in-imp-intro-form
(proof-in-imp-intro-form-to-avar proof)
(proof-to-one-step-beta-reduct
(proof-in-imp-intro-form-to-kernel proof))))
((proof-in-imp-elim-form)
(let* ((op (proof-in-imp-elim-form-to-op proof))
(arg (proof-in-imp-elim-form-to-arg proof)))
(if (proof-in-imp-intro-form? op)
(proof-subst (proof-in-imp-intro-form-to-kernel op)
(proof-in-imp-intro-form-to-avar op)
arg)
(make-proof-in-imp-elim-form
(proof-to-one-step-beta-reduct op)
(proof-to-one-step-beta-reduct arg)))))
((proof-in-impnc-intro-form)
(make-proof-in-impnc-intro-form
(proof-in-impnc-intro-form-to-avar proof)
(proof-to-one-step-beta-reduct
(proof-in-impnc-intro-form-to-kernel proof))))
((proof-in-impnc-elim-form)
(let* ((op (proof-in-impnc-elim-form-to-op proof))
(arg (proof-in-impnc-elim-form-to-arg proof)))
(if (proof-in-impnc-intro-form? op)
(proof-subst (proof-in-impnc-intro-form-to-kernel op)
(proof-in-impnc-intro-form-to-avar op)
arg)
(make-proof-in-impnc-elim-form
(proof-to-one-step-beta-reduct op)
(proof-to-one-step-beta-reduct arg)))))
((proof-in-and-intro-form)
(make-proof-in-and-intro-form
(proof-to-one-step-beta-reduct (proof-in-and-intro-form-to-left proof))
(proof-to-one-step-beta-reduct
(proof-in-and-intro-form-to-right proof))))
((proof-in-and-elim-left-form)
(let ((kernel (proof-in-and-elim-left-form-to-kernel proof)))
(if (proof-in-and-intro-form? kernel)
(proof-in-and-intro-form-to-left kernel)
(make-proof-in-and-elim-left-form
(proof-to-one-step-beta-reduct kernel)))))
((proof-in-and-elim-right-form)
(let ((kernel (proof-in-and-elim-right-form-to-kernel proof)))
(if (proof-in-and-intro-form? kernel)
(proof-in-and-intro-form-to-right kernel)
(make-proof-in-and-elim-right-form
(proof-to-one-step-beta-reduct kernel)))))
((proof-in-all-intro-form)
(make-proof-in-all-intro-form
(proof-in-all-intro-form-to-var proof)
(proof-to-one-step-beta-reduct
(proof-in-all-intro-form-to-kernel proof))))
((proof-in-all-elim-form)
(let* ((op (proof-in-all-elim-form-to-op proof))
(arg (proof-in-all-elim-form-to-arg proof)))
(if (proof-in-all-intro-form? op)
(proof-subst (proof-in-all-intro-form-to-kernel op)
(proof-in-all-intro-form-to-var op)
arg)
(make-proof-in-all-elim-form
(proof-to-one-step-beta-reduct op)
arg))))
((proof-in-allnc-intro-form)
(make-proof-in-allnc-intro-form
(proof-in-allnc-intro-form-to-var proof)
(proof-to-one-step-beta-reduct
(proof-in-allnc-intro-form-to-kernel proof))))
((proof-in-allnc-elim-form)
(let* ((op (proof-in-allnc-elim-form-to-op proof))
(arg (proof-in-allnc-elim-form-to-arg proof)))
(if (proof-in-allnc-intro-form? op)
(proof-subst (proof-in-allnc-intro-form-to-kernel op)
(proof-in-allnc-intro-form-to-var op)
arg)
(make-proof-in-allnc-elim-form
(proof-to-one-step-beta-reduct op)
arg))))
(else (myerror "proof-to-one-step-beta-reduct" "proof tag expected"
(tag proof)))))
(define (proof-to-beta-nf proof)
(if (proof-in-beta-normal-form? proof)
proof
(proof-to-beta-nf (proof-to-one-step-beta-reduct proof))))
(define (proof-to-beta-pi-eta-nf proof)
(proof-to-eta-nf (normalize-proof-pi (proof-to-beta-nf proof))))
(define bpe-np proof-to-beta-pi-eta-nf)
; Useful functions for proofs
(define (proof-to-length proof)
(case (tag proof)
((proof-in-avar-form proof-in-aconst-form) 1)
((proof-in-imp-intro-form)
(+ 1 (proof-to-length (proof-in-imp-intro-form-to-kernel proof))))
((proof-in-imp-elim-form)
(let* ((op (proof-in-imp-elim-form-to-op proof))
(arg (proof-in-imp-elim-form-to-arg proof)))
(+ 1 (proof-to-length op) (proof-to-length arg))))
((proof-in-impnc-intro-form)
(+ 1 (proof-to-length (proof-in-impnc-intro-form-to-kernel proof))))
((proof-in-impnc-elim-form)
(let* ((op (proof-in-impnc-elim-form-to-op proof))
(arg (proof-in-impnc-elim-form-to-arg proof)))
(+ 1 (proof-to-length op) (proof-to-length arg))))
((proof-in-and-intro-form)
(+ 1
(proof-to-length (proof-in-and-intro-form-to-left proof))
(proof-to-length (proof-in-and-intro-form-to-right proof))))
((proof-in-and-elim-left-form)
(let ((kernel (proof-in-and-elim-left-form-to-kernel proof)))
(+ 1 (proof-to-length kernel))))
((proof-in-and-elim-right-form)
(let ((kernel (proof-in-and-elim-right-form-to-kernel proof)))
(+ 1 (proof-to-length kernel))))
((proof-in-all-intro-form)
(+ 1 (proof-to-length (proof-in-all-intro-form-to-kernel proof))))
((proof-in-all-elim-form)
(let* ((op (proof-in-all-elim-form-to-op proof))
(arg (proof-in-all-elim-form-to-arg proof)))
(+ 1 (proof-to-length op) 1)))
((proof-in-allnc-intro-form)
(+ 1 (proof-to-length (proof-in-allnc-intro-form-to-kernel proof))))
((proof-in-allnc-elim-form)
(let* ((op (proof-in-allnc-elim-form-to-op proof))
(arg (proof-in-allnc-elim-form-to-arg proof)))
(+ 1 (proof-to-length op) 1)))
(else (myerror "proof-to-length" "proof tag expected"
(tag proof)))))
; 10-3. Substitution
; ==================
; We define simultaneous substitution for type, object, predicate and
; assumption variables in a proof, via tsubst, subst, psubst and
; asubst. It is assumed that subst only affects those vars whose type
; is not changed by tsubst, psubst only affects those pvars whose
; arity is not changed by tsubst, and that asubst only affects those
; avars whose formula is not changed by tsubst, subst and psubst.
; In the abstraction cases of the recursive definition, the abstracted
; variable (or assumption variable) may need to be renamed. However,
; its type (or formula) can be affected by tsubst (or tsubst, subst
; and psubst). Then the renaming cannot be made part of subst (or
; asubst), because the condition above would be violated. Therefore
; we carry along procedures rename renaming variables and arename for
; assumption variables, which remember the renaming done so far.
; In make-arename classical-formula=? replaced by formula=?
; Reason: classical-formula=? finds that the normal forms are equal.
; But in arename we want syntactic equality, i.e., formula=?
; make-arename returns a procedure renaming assumption variables,
; which remembers the renaming of assumption variables done so far.
(define (make-arename tsubst psubst rename prename)
(let ((assoc-list '()))
(lambda (avar subst)
(let ((info (assoc-wrt avar=? avar assoc-list)))
(if info
(cadr info)
(let* ((formula (avar-to-formula avar))
(new-formula (formula-substitute-aux
formula tsubst subst psubst rename prename)))
(if (formula=? formula new-formula)
avar
(let ((new-avar (formula-to-new-avar new-formula)))
(set! assoc-list (cons (list avar new-avar) assoc-list))
new-avar))))))))
; rename-bound-avars replaces all bound avars by new ones with the
; same name but a new index. Properties: (i) rename-bound-avars
; transforms a proof satisfying the avar convention w.r.t. its free
; avars into a proof satisfying the avar convention completely. (ii)
; In every subproof of the result no free avar occurs (w.r.t. avar=?)
; bound as well. Property (ii) is assumed in proof-substitute-aux.
(define (rename-bound-avars proof)
(rename-bound-avars-aux proof '()))
(define (rename-bound-avars-aux proof alist)
(case (tag proof)
((proof-in-avar-form)
(let* ((avar (proof-in-avar-form-to-avar proof))
(info (assoc-wrt avar-full=? avar alist)))
(if info (cadr info) proof)))
((proof-in-aconst-form) proof)
((proof-in-imp-intro-form)
(let* ((avar (proof-in-imp-intro-form-to-avar proof))
(kernel (proof-in-imp-intro-form-to-kernel proof))
(formula (avar-to-formula avar))
(name (avar-to-name avar))
(new-avar (formula-to-new-avar formula name))
(new-alist (cons (list avar (make-proof-in-avar-form new-avar))
alist)))
(make-proof-in-imp-intro-form
new-avar (rename-bound-avars-aux kernel new-alist))))
((proof-in-imp-elim-form)
(let ((op (proof-in-imp-elim-form-to-op proof))
(arg (proof-in-imp-elim-form-to-arg proof)))
(make-proof-in-imp-elim-form
(rename-bound-avars-aux op alist)
(rename-bound-avars-aux arg alist))))
((proof-in-impnc-intro-form)
(let* ((avar (proof-in-impnc-intro-form-to-avar proof))
(kernel (proof-in-impnc-intro-form-to-kernel proof))
(formula (avar-to-formula avar))
(name (avar-to-name avar))
(new-avar (formula-to-new-avar formula name))
(new-alist (cons (list avar (make-proof-in-avar-form new-avar))
alist)))
(make-proof-in-impnc-intro-form
new-avar (rename-bound-avars-aux kernel new-alist))))
((proof-in-impnc-elim-form)
(let ((op (proof-in-impnc-elim-form-to-op proof))
(arg (proof-in-impnc-elim-form-to-arg proof)))
(make-proof-in-impnc-elim-form
(rename-bound-avars-aux op alist)
(rename-bound-avars-aux arg alist))))
((proof-in-and-intro-form)
(make-proof-in-and-intro-form
(rename-bound-avars-aux (proof-in-and-intro-form-to-left proof) alist)
(rename-bound-avars-aux (proof-in-and-intro-form-to-right proof) alist)))
((proof-in-and-elim-left-form)
(make-proof-in-and-elim-left-form
(rename-bound-avars-aux
(proof-in-and-elim-left-form-to-kernel proof) alist)))
((proof-in-and-elim-right-form)
(make-proof-in-and-elim-right-form
(rename-bound-avars-aux
(proof-in-and-elim-right-form-to-kernel proof) alist)))
((proof-in-all-intro-form)
(let ((var (proof-in-all-intro-form-to-var proof))
(kernel (proof-in-all-intro-form-to-kernel proof)))
(make-proof-in-all-intro-form
var (rename-bound-avars-aux kernel alist))))
((proof-in-all-elim-form)
(let ((op (proof-in-all-elim-form-to-op proof))
(arg (proof-in-all-elim-form-to-arg proof)))
(make-proof-in-all-elim-form
(rename-bound-avars-aux op alist) arg)))
((proof-in-allnc-intro-form)
(let ((var (proof-in-allnc-intro-form-to-var proof))
(kernel (proof-in-allnc-intro-form-to-kernel proof)))
(make-proof-in-allnc-intro-form
var (rename-bound-avars-aux kernel alist))))
((proof-in-allnc-elim-form)
(let ((op (proof-in-allnc-elim-form-to-op proof))
(arg (proof-in-allnc-elim-form-to-arg proof)))
(make-proof-in-allnc-elim-form
(rename-bound-avars-aux op alist) arg)))
(else (myerror "rename-bound-avars-aux" "proof tag expected"
(tag proof)))))
(define (proof-substitute proof topasubst)
(let* ((tsubst-and-subst-and-psubst-and-asubst
(do ((l topasubst (cdr l))
(tsubst '() (if (tvar-form? (caar l))
(cons (car l) tsubst)
tsubst))
(subst '() (if (var-form? (caar l))
(cons (car l) subst)
subst))
(psubst '() (if (pvar-form? (caar l))
(cons (car l) psubst)
psubst))
(asubst '() (if (avar-form? (caar l))
(cons (car l) asubst)
asubst)))
((null? l) (list (reverse tsubst)
(reverse subst)
(reverse psubst)
(reverse asubst)))))
(tsubst (car tsubst-and-subst-and-psubst-and-asubst))
(subst (cadr tsubst-and-subst-and-psubst-and-asubst))
(psubst (caddr tsubst-and-subst-and-psubst-and-asubst))
(asubst (cadddr tsubst-and-subst-and-psubst-and-asubst))
(unfolded-psubst
(map (lambda (x) (let ((pvar (car x))
(cterm (cadr x)))
(list pvar (unfold-cterm cterm))))
psubst))
(rename (make-rename tsubst))
(prename (make-prename tsubst))
(arename (make-arename tsubst unfolded-psubst rename prename))
(tvars (map car tsubst))
(vars (map car subst))
(pvars (map car psubst))
(avars (map car asubst))
(tvars-in-subst-vars
(apply union (map type-to-free (map var-to-type vars))))
(types-in-pvars
(apply union (map arity-to-types (map pvar-to-arity pvars))))
(tvars-in-psubst-pvars
(apply union (map type-to-free types-in-pvars)))
(formulas-in-avars (map avar-to-formula avars))
(subst-formulas-in-avars
(map (lambda (x) (formula-substitute-aux
x tsubst subst psubst rename prename))
formulas-in-avars))
(proof-with-no-free-avar-bound (rename-bound-avars proof)))
(if (pair? (intersection tvars tvars-in-subst-vars))
(myerror "proof-substitute" "one of the type variables"
(map type-to-string tvars)
"is free in the type of one of the variables"
(map var-to-string vars)
"affected by subst"))
(if (pair? (intersection tvars tvars-in-psubst-pvars))
(myerror "proof-substitute" "one of the type variables"
(map type-to-string tvars)
"is free in the arity of one of the predicate variables"
(map pvar-to-string pvars)
"affected by psubst"))
(if (member #f (map (lambda (x y) (classical-formula=? x y))
formulas-in-avars subst-formulas-in-avars))
(myerror "proof-substitute" "one of the assumption variables"
(map avar-to-string avars)
"with formulas"
(map formula-to-string formulas-in-avars)
"is changed by tsubst, subst and/or psubst, yielding formulas"
(map formula-to-string subst-formulas-in-avars)))
(proof-substitute-aux
proof-with-no-free-avar-bound
tsubst subst unfolded-psubst asubst rename prename arename)))
(define (avar-proof-equal? avar proof)
(and (proof-in-avar-form? proof)
(avar=? avar (proof-in-avar-form-to-avar proof))))
(define (proof-subst proof arg val)
(let ((equality?
(cond
((and (tvar? arg) (type? val)) equal?)
((and (var-form? arg) (term-form? val)) var-term-equal?)
((and (pvar? arg) (cterm-form? val)) pvar-cterm-equal?)
((and (avar-form? arg) (proof-form? val)) avar-proof-equal?)
(else (myerror "proof-subst" "unexpected arg" arg "and val" val)))))
(proof-substitute proof (make-subst-wrt equality? arg val))))
; In proof-substitute-aux we always first rename, when an assumption
; variable is encountered. Notice that prename is not really
; necessary as an argument, since we do not have explicit predicate
; quantifiers. However, we need prename for assumption constants, and
; it seems handy to create one for all of them.
; Substitution of a pvar in an aconst can generate new parameters,
; which will be generalized. Hence the result must be applied to
; their varterms. One must treat elim aconsts specially, since their
; uninst-formula has the argument variables of the idpc premise free.
; Therefore substitution is defined for aconsts applied to
; sufficiently many terms only.
(define (proof-substitute-aux proof tsubst subst psubst asubst
rename prename arename)
(case (tag proof)
((proof-in-avar-form)
(let* ((avar (arename (proof-in-avar-form-to-avar proof) subst))
(info (assoc-wrt avar=? avar asubst)))
(if info
(cadr info)
(make-proof-in-avar-form avar))))
((proof-in-aconst-form proof-in-allnc-elim-form)
(let* ((op-and-args (proof-to-final-allnc-elim-op-and-args proof))
(op (car op-and-args))
(args (cdr op-and-args)))
(if
(not (proof-in-aconst-form? op))
(apply mk-proof-in-elim-form
(cons (proof-substitute-aux
op tsubst subst psubst asubst rename prename arename)
(map (lambda (arg)
(term-substitute-aux arg tsubst subst rename))
args)))
(let* ((aconst (proof-in-aconst-form-to-aconst op))
(inst-formula (aconst-to-inst-formula aconst))
(free (formula-to-free inst-formula))
(k (if (string=? (aconst-to-name aconst) "Elim")
(let* ((imp-formulas (aconst-to-repro-formulas aconst))
(imp-formula (car imp-formulas))
(prem (imp-form-to-premise imp-formula))
(args (predicate-form-to-args prem)))
(length args))
0))
(kplusn (length free))
(n (- kplusn k)))
(if
(<= kplusn (length args))
(let* ((elim-args (list-head args k))
(param-and-rest-args (list-tail args k))
(param-args (list-head param-and-rest-args n))
(rest-args (list-tail param-and-rest-args n))
(elim-free (list-head free k))
(param-free (list-tail free k))
(norm-param-subst (make-substitution-wrt var-term-equal?
param-free
param-args))
(new-subst
(compose-substitutions-wrt
(lambda (term sigma)
(term-substitute-aux term tsubst sigma rename))
equal? var-term-equal? norm-param-subst subst))
(new-aconst (aconst-substitute-aux
aconst tsubst new-subst psubst rename prename))
(new-free (formula-to-free
(aconst-to-inst-formula new-aconst))))
(apply
mk-proof-in-elim-form
(cons (make-proof-in-aconst-form new-aconst)
(append
(map (lambda (arg)
(term-substitute-aux arg tsubst subst rename))
elim-args)
(map make-term-in-var-form (list-tail new-free k))
(map (lambda (arg)
(term-substitute-aux arg tsubst subst rename))
rest-args)))))
(myerror "proof-substitute-aux"
"substitution in aconst with allnc elims"
(proof-to-expr proof)
"whose free parameters are"
(map var-to-string free)
"requires at least that many arguments"))))))
((proof-in-imp-intro-form)
(let* ((avar (proof-in-imp-intro-form-to-avar proof))
(kernel (proof-in-imp-intro-form-to-kernel proof))
(new-avar (arename avar subst)))
(make-proof-in-imp-intro-form
new-avar
(proof-substitute-aux
kernel tsubst subst psubst asubst rename prename arename))))
((proof-in-imp-elim-form)
(let ((op (proof-in-imp-elim-form-to-op proof))
(arg (proof-in-imp-elim-form-to-arg proof)))
(make-proof-in-imp-elim-form
(proof-substitute-aux
op tsubst subst psubst asubst rename prename arename)
(proof-substitute-aux
arg tsubst subst psubst asubst rename prename arename))))
((proof-in-impnc-intro-form)
(let* ((avar (proof-in-impnc-intro-form-to-avar proof))
(kernel (proof-in-impnc-intro-form-to-kernel proof))
(new-avar (arename avar subst)))
(make-proof-in-impnc-intro-form
new-avar
(proof-substitute-aux
kernel tsubst subst psubst asubst rename prename arename))))
((proof-in-impnc-elim-form)
(let ((op (proof-in-impnc-elim-form-to-op proof))
(arg (proof-in-impnc-elim-form-to-arg proof)))
(make-proof-in-impnc-elim-form
(proof-substitute-aux
op tsubst subst psubst asubst rename prename arename)
(proof-substitute-aux
arg tsubst subst psubst asubst rename prename arename))))
((proof-in-and-intro-form)
(make-proof-in-and-intro-form
(proof-substitute-aux
(proof-in-and-intro-form-to-left proof)
tsubst subst psubst asubst rename prename arename)
(proof-substitute-aux
(proof-in-and-intro-form-to-right proof)
tsubst subst psubst asubst rename prename arename)))
((proof-in-and-elim-left-form)
(make-proof-in-and-elim-left-form
(proof-substitute-aux
(proof-in-and-elim-left-form-to-kernel proof)
tsubst subst psubst asubst rename prename arename)))
((proof-in-and-elim-right-form)
(make-proof-in-and-elim-right-form
(proof-substitute-aux
(proof-in-and-elim-right-form-to-kernel proof)
tsubst subst psubst asubst rename prename arename)))
((proof-in-all-intro-form)
(let* ((var (rename (proof-in-all-intro-form-to-var proof)))
(kernel (proof-in-all-intro-form-to-kernel proof))
(new-var (var-to-new-var var))
(new-subst (compose-o-substitutions
(make-subst var (make-term-in-var-form new-var))
subst)))
(make-proof-in-all-intro-form
new-var
(proof-substitute-aux
kernel tsubst new-subst psubst asubst rename prename arename))))
((proof-in-all-elim-form)
(let ((op (proof-in-all-elim-form-to-op proof))
(arg (proof-in-all-elim-form-to-arg proof)))
(make-proof-in-all-elim-form
(proof-substitute-aux
op tsubst subst psubst asubst rename prename arename)
(term-substitute-aux arg tsubst subst rename))))
((proof-in-allnc-intro-form)
(let* ((var (rename (proof-in-allnc-intro-form-to-var proof)))
(kernel (proof-in-allnc-intro-form-to-kernel proof))
(new-var (var-to-new-var var))
(new-subst (compose-o-substitutions
(make-subst var (make-term-in-var-form new-var))
subst)))
(make-proof-in-allnc-intro-form
new-var
(proof-substitute-aux
kernel tsubst new-subst psubst asubst rename prename arename))))
(else (myerror "proof-substitute-aux" "proof tag expected" (tag proof)))))
(define (aconst-substitute-aux aconst0 tsubst subst psubst rename prename)
(let* ((uninst-formula0 (aconst-to-uninst-formula aconst0))
(tpinst0 (aconst-to-tpinst aconst0))
(tsubst0 (list-transform-positive tpinst0
(lambda (x) (tvar-form? (car x)))))
(pinst0 (list-transform-positive tpinst0
(lambda (x) (pvar-form? (car x)))))
(repro-formulas0 (aconst-to-repro-formulas aconst0))
(tvars0 (formula-to-tvars uninst-formula0))
(pvars0 (formula-to-pvars uninst-formula0))
(composed-tsubst (compose-t-substitutions tsubst0 tsubst))
(reduced-composed-tsubst (list-transform-positive composed-tsubst
(lambda (x) (member (car x) tvars0))))
(omitted-pvars (set-minus pvars0 (map car pinst0)))
(completed-pinst0
(append pinst0 (map (lambda (x) (list x (predicate-to-cterm x)))
omitted-pvars)))
(composed-pinst (map (lambda (x)
(let ((pvar (car x))
(cterm (cadr x)))
(list pvar (cterm-substitute-aux
cterm tsubst subst psubst
rename prename))))
completed-pinst0))
(reduced-composed-pinst
(list-transform-positive composed-pinst
(lambda (x) (and (not (pvar-cterm-equal? (car x) (cadr x)))
(member (car x) pvars0)))))
(new-repro-formulas ;better: repro-data
(if (string=? "Intro" (aconst-to-name aconst0))
(let* ((i (car repro-formulas0))
(idpredconst (cadr repro-formulas0))
(name (idpredconst-to-name idpredconst))
(types (idpredconst-to-types idpredconst))
(cterms (idpredconst-to-cterms idpredconst))
(new-idpredconst
(make-idpredconst
name
(map (lambda (x) (type-substitute x tsubst)) types)
(map (lambda (x)
(cterm-substitute x (append tsubst psubst)))
cterms))))
(list i new-idpredconst))
(map (lambda (x) (formula-substitute-aux
x tsubst subst psubst rename prename))
repro-formulas0))))
(apply make-aconst
(append (list (aconst-to-name aconst0)
(aconst-to-kind aconst0)
uninst-formula0
(append reduced-composed-tsubst
reduced-composed-pinst))
new-repro-formulas))))
(define (proof-substitute-and-beta0-nf proof subst)
(if
(null? subst)
proof
(case (tag proof)
((proof-in-avar-form)
(let* ((avar (proof-in-avar-form-to-avar proof))
(formula (avar-to-formula avar))
(newavar
(if (intersection (map car subst) (formula-to-free formula))
(make-avar
(formula-substitute-and-beta0-nf
(avar-to-formula avar) subst)
(avar-to-index avar)
(avar-to-name avar))
avar)))
(make-proof-in-avar-form newavar)))
((proof-in-aconst-form) proof)
((proof-in-imp-intro-form)
(let* ((avar (proof-in-imp-intro-form-to-avar proof))
(formula (avar-to-formula avar))
(newavar
(if (intersection (map car subst) (formula-to-free formula))
(make-avar
(formula-substitute-and-beta0-nf formula subst)
(avar-to-index avar)
(avar-to-name avar))
avar))
(kernel (proof-in-imp-intro-form-to-kernel proof)))
(make-proof-in-imp-intro-form newavar
(proof-substitute-and-beta0-nf
kernel subst))))
((proof-in-imp-elim-form)
(make-proof-in-imp-elim-form
(proof-substitute-and-beta0-nf
(proof-in-imp-elim-form-to-op proof) subst)
(proof-substitute-and-beta0-nf
(proof-in-imp-elim-form-to-arg proof) subst)))
((proof-in-impnc-intro-form)
(let* ((avar (proof-in-impnc-intro-form-to-avar proof))
(formula (avar-to-formula avar))
(newavar
(if (intersection (map car subst) (formula-to-free formula))
(make-avar
(formula-substitute-and-beta0-nf formula subst)
(avar-to-index avar)
(avar-to-name avar))
avar))
(kernel (proof-in-impnc-intro-form-to-kernel proof)))
(make-proof-in-impnc-intro-form newavar
(proof-substitute-and-beta0-nf
kernel subst))))
((proof-in-impnc-elim-form)
(make-proof-in-impnc-elim-form
(proof-substitute-and-beta0-nf
(proof-in-impnc-elim-form-to-op proof) subst)
(proof-substitute-and-beta0-nf
(proof-in-impnc-elim-form-to-arg proof) subst)))
((proof-in-and-intro-form)
(make-proof-in-and-intro-form
(proof-substitute-and-beta0-nf
(proof-in-and-intro-form-to-left proof) subst)
(proof-substitute-and-beta0-nf
(proof-in-and-intro-form-to-right proof) subst)))
((proof-in-and-elim-left-form)
(make-proof-in-and-elim-left-form
(proof-substitute-and-beta0-nf
(proof-in-and-elim-left-form-to-kernel proof) subst)))
((proof-in-and-elim-right-form)
(make-proof-in-and-elim-right-form
(proof-substitute-and-beta0-nf
(proof-in-and-elim-right-form-to-kernel proof) subst)))
((proof-in-all-intro-form)
(let* ((var (proof-in-all-intro-form-to-var proof))
(kernel (proof-in-all-intro-form-to-kernel proof))
(vars (map car subst))
(active-vars (intersection vars (proof-to-free proof)))
(active-subst
(do ((l subst (cdr l))
(res '() (if (member (caar l) active-vars)
(cons (car l) res)
res)))
((null? l) (reverse res))))
(active-terms (map cadr active-subst)))
(if (member var (apply union (map term-to-free active-terms)))
(let ((new-var (var-to-new-var var)))
(make-proof-in-all-intro-form
new-var
(proof-substitute-and-beta0-nf
kernel (cons (list var (make-term-in-var-form new-var))
active-subst))))
(make-proof-in-all-intro-form
var (proof-substitute-and-beta0-nf kernel active-subst)))))
((proof-in-all-elim-form)
(make-proof-in-all-elim-form
(proof-substitute-and-beta0-nf
(proof-in-all-elim-form-to-op proof) subst)
(term-substitute-and-beta0-nf
(proof-in-all-elim-form-to-arg proof) subst)))
((proof-in-allnc-intro-form)
(let* ((var (proof-in-allnc-intro-form-to-var proof))
(kernel (proof-in-allnc-intro-form-to-kernel proof))
(vars (map car subst))
(active-vars (intersection vars (proof-to-free proof)))
(active-subst
(do ((l subst (cdr l))
(res '() (if (member (caar l) active-vars)
(cons (car l) res)
res)))
((null? l) (reverse res))))
(active-terms (map cadr active-subst)))
(if (member var (apply union (map term-to-free active-terms)))
(let ((new-var (var-to-new-var var)))
(make-proof-in-allnc-intro-form
new-var
(proof-substitute-and-beta0-nf
kernel (cons (list var (make-term-in-var-form new-var))
active-subst))))
(make-proof-in-allnc-intro-form
var (proof-substitute-and-beta0-nf kernel active-subst)))))
((proof-in-allnc-elim-form)
(make-proof-in-allnc-elim-form
(proof-substitute-and-beta0-nf
(proof-in-allnc-elim-form-to-op proof) subst)
(term-substitute-and-beta0-nf
(proof-in-allnc-elim-form-to-arg proof) subst)))
(else (myerror "proof-substitute-and-beta0-nf" "proof tag expected"
(tag proof))))))
; (expand-theorems proof) expands all theorems recursively.
; (expand-theorems proof name-test?) expands (non-recursively) the theorems
; passing the test by instances of their saved proofs.
(define (expand-theorems proof . opt-name-test)
(case (tag proof)
((proof-in-avar-form) proof)
((proof-in-aconst-form)
(let* ((aconst (proof-in-aconst-form-to-aconst proof))
(name (aconst-to-name aconst))
(kind (aconst-to-kind aconst)))
(cond ((not (eq? 'theorem kind)) proof)
((null? opt-name-test)
(let* ((inst-proof (theorem-aconst-to-inst-proof aconst))
(free (formula-to-free (proof-to-formula inst-proof))))
(expand-theorems
(apply mk-proof-in-nc-intro-form
(append free (list inst-proof))))))
(((car opt-name-test) name)
(let* ((inst-proof (theorem-aconst-to-inst-proof aconst))
(free (formula-to-free (proof-to-formula inst-proof))))
(apply mk-proof-in-nc-intro-form
(append free (list inst-proof)))))
(else proof))))
((proof-in-imp-elim-form)
(let ((op (proof-in-imp-elim-form-to-op proof))
(arg (proof-in-imp-elim-form-to-arg proof)))
(make-proof-in-imp-elim-form
(apply expand-theorems (cons op opt-name-test))
(apply expand-theorems (cons arg opt-name-test)))))
((proof-in-imp-intro-form)
(let ((avar (proof-in-imp-intro-form-to-avar proof))
(kernel (proof-in-imp-intro-form-to-kernel proof)))
(make-proof-in-imp-intro-form
avar (apply expand-theorems (cons kernel opt-name-test)))))
((proof-in-impnc-elim-form)
(let ((op (proof-in-impnc-elim-form-to-op proof))
(arg (proof-in-impnc-elim-form-to-arg proof)))
(make-proof-in-impnc-elim-form
(apply expand-theorems (cons op opt-name-test))
(apply expand-theorems (cons arg opt-name-test)))))
((proof-in-impnc-intro-form)
(let ((avar (proof-in-impnc-intro-form-to-avar proof))
(kernel (proof-in-impnc-intro-form-to-kernel proof)))
(make-proof-in-impnc-intro-form
avar (apply expand-theorems (cons kernel opt-name-test)))))
((proof-in-and-intro-form)
(let ((left (proof-in-and-intro-form-to-left proof))
(right (proof-in-and-intro-form-to-right proof)))
(make-proof-in-and-intro-form
(apply expand-theorems (cons left opt-name-test))
(apply expand-theorems (cons right opt-name-test)))))
((proof-in-and-elim-left-form)
(let ((kernel (proof-in-and-elim-left-form-to-kernel proof)))
(make-proof-in-and-elim-left-form
(apply expand-theorems (cons kernel opt-name-test)))))
((proof-in-and-elim-right-form)
(let ((kernel (proof-in-and-elim-right-form-to-kernel proof)))
(make-proof-in-and-elim-right-form
(apply expand-theorems (cons kernel opt-name-test)))))
((proof-in-all-intro-form)
(let ((var (proof-in-all-intro-form-to-var proof))
(kernel (proof-in-all-intro-form-to-kernel proof)))
(make-proof-in-all-intro-form
var (apply expand-theorems (cons kernel opt-name-test)))))
((proof-in-all-elim-form)
(let ((op (proof-in-all-elim-form-to-op proof))
(arg (proof-in-all-elim-form-to-arg proof)))
(make-proof-in-all-elim-form
(apply expand-theorems (cons op opt-name-test)) arg)))
((proof-in-allnc-intro-form)
(let ((var (proof-in-allnc-intro-form-to-var proof))
(kernel (proof-in-allnc-intro-form-to-kernel proof)))
(make-proof-in-allnc-intro-form
var (apply expand-theorems (cons kernel opt-name-test)))))
((proof-in-allnc-elim-form)
(let ((op (proof-in-allnc-elim-form-to-op proof))
(arg (proof-in-allnc-elim-form-to-arg proof)))
(make-proof-in-allnc-elim-form
(apply expand-theorems (cons op opt-name-test)) arg)))
(else (myerror "expand-theorems" "proof tag expected" (tag proof)))))
(define (expand-thm proof thm-name)
(expand-theorems proof (lambda (name) (string=? name thm-name))))
(define (expand-theorems-with-positive-content proof)
(case (tag proof)
((proof-in-avar-form) proof)
((proof-in-aconst-form)
(let* ((aconst (proof-in-aconst-form-to-aconst proof))
(name (aconst-to-name aconst))
(kind (aconst-to-kind aconst)))
(if (and (eq? 'theorem (aconst-to-kind aconst))
(not (formula-of-nulltypep? (aconst-to-formula aconst))))
(let* ((inst-proof (theorem-aconst-to-inst-proof aconst))
(free (formula-to-free (proof-to-formula inst-proof))))
(expand-theorems-with-positive-content
(apply mk-proof-in-nc-intro-form
(append free (list inst-proof)))))
proof)))
((proof-in-imp-elim-form)
(let ((op (proof-in-imp-elim-form-to-op proof))
(arg (proof-in-imp-elim-form-to-arg proof)))
(make-proof-in-imp-elim-form
(expand-theorems-with-positive-content op)
(expand-theorems-with-positive-content arg))))
((proof-in-imp-intro-form)
(let ((avar (proof-in-imp-intro-form-to-avar proof))
(kernel (proof-in-imp-intro-form-to-kernel proof)))
(make-proof-in-imp-intro-form
avar (expand-theorems-with-positive-content kernel))))
((proof-in-impnc-elim-form)
(let ((op (proof-in-impnc-elim-form-to-op proof))
(arg (proof-in-impnc-elim-form-to-arg proof)))
(make-proof-in-impnc-elim-form
(expand-theorems-with-positive-content op)
(expand-theorems-with-positive-content arg))))
((proof-in-impnc-intro-form)
(let ((avar (proof-in-impnc-intro-form-to-avar proof))
(kernel (proof-in-impnc-intro-form-to-kernel proof)))
(make-proof-in-impnc-intro-form
avar (expand-theorems-with-positive-content kernel))))
((proof-in-and-intro-form)
(let ((left (proof-in-and-intro-form-to-left proof))
(right (proof-in-and-intro-form-to-right proof)))
(make-proof-in-and-intro-form
(expand-theorems-with-positive-content left)
(expand-theorems-with-positive-content right))))
((proof-in-and-elim-left-form)
(let ((kernel (proof-in-and-elim-left-form-to-kernel proof)))
(make-proof-in-and-elim-left-form
(expand-theorems-with-positive-content kernel))))
((proof-in-and-elim-right-form)
(let ((kernel (proof-in-and-elim-right-form-to-kernel proof)))
(make-proof-in-and-elim-right-form
(expand-theorems-with-positive-content kernel))))
((proof-in-all-intro-form)
(let ((var (proof-in-all-intro-form-to-var proof))
(kernel (proof-in-all-intro-form-to-kernel proof)))
(make-proof-in-all-intro-form
var (expand-theorems-with-positive-content kernel))))
((proof-in-all-elim-form)
(let ((op (proof-in-all-elim-form-to-op proof))
(arg (proof-in-all-elim-form-to-arg proof)))
(make-proof-in-all-elim-form
(expand-theorems-with-positive-content op) arg)))
((proof-in-allnc-intro-form)
(let ((var (proof-in-allnc-intro-form-to-var proof))
(kernel (proof-in-allnc-intro-form-to-kernel proof)))
(make-proof-in-allnc-intro-form
var (expand-theorems-with-positive-content kernel))))
((proof-in-allnc-elim-form)
(let ((op (proof-in-allnc-elim-form-to-op proof))
(arg (proof-in-allnc-elim-form-to-arg proof)))
(make-proof-in-allnc-elim-form
(expand-theorems-with-positive-content op) arg)))
(else (myerror "expand-theorems-with-positive-content"
"proof tag expected" (tag proof)))))
; 10-4. Display
; =============
(define (display-proof . opt-proof)
(if (and (null? opt-proof)
(null? PPROOF-STATE))
(myerror
"display-proof: proof argument or proof under construction expected"))
(let ((proof (if (null? opt-proof)
(pproof-state-to-proof)
(car opt-proof))))
(display-proof-aux proof 0)))
; (define (display-proof proof)
; (display-proof-aux proof 0))
(define dp display-proof)
(define (display-normalized-proof . opt-proof)
(if (and (null? opt-proof)
(null? PPROOF-STATE))
(myerror "display-normalized-proof"
"proof argument or proof under construction expected"))
(let ((proof (if (null? opt-proof)
(pproof-state-to-proof)
(car opt-proof))))
(display-proof-aux (nbe-normalize-proof proof) 0)))
(define dnp display-normalized-proof)
(define (display-proof-aux proof n)
(if
COMMENT-FLAG
(case (tag proof)
((proof-in-avar-form)
(display-comment (make-string n #\.))
(dff (proof-to-formula proof)) (display " by assumption ")
(display (avar-to-string (proof-in-avar-form-to-avar proof))) (newline))
((proof-in-aconst-form)
(let ((aconst (proof-in-aconst-form-to-aconst proof)))
(display-comment (make-string n #\.))
(dff (proof-to-formula proof))
(case (aconst-to-kind aconst)
((axiom) (display " by axiom "))
((theorem) (display " by theorem "))
((global-assumption) (display " by global assumption "))
(else (myerror "display-proof-aux" "kind of aconst expected"
(aconst-to-kind aconst))))
(display (aconst-to-name aconst))
(newline)))
((proof-in-imp-intro-form)
(display-proof-aux (proof-in-imp-intro-form-to-kernel proof) (+ n 1))
(display-comment (make-string n #\.))
(dff (proof-to-formula proof)) (display " by imp intro ")
(display (avar-to-string (proof-in-imp-intro-form-to-avar proof)))
(newline))
((proof-in-imp-elim-form)
(display-proof-aux (proof-in-imp-elim-form-to-op proof) (+ n 1))
(display-proof-aux (proof-in-imp-elim-form-to-arg proof) (+ n 1))
(display-comment (make-string n #\.))
(dff (proof-to-formula proof)) (display " by imp elim") (newline))
((proof-in-impnc-intro-form)
(display-proof-aux (proof-in-impnc-intro-form-to-kernel proof) (+ n 1))
(display-comment (make-string n #\.))
(dff (proof-to-formula proof)) (display " by impnc intro ")
(display (avar-to-string (proof-in-impnc-intro-form-to-avar proof)))
(newline))
((proof-in-impnc-elim-form)
(display-proof-aux (proof-in-impnc-elim-form-to-op proof) (+ n 1))
(display-proof-aux (proof-in-impnc-elim-form-to-arg proof) (+ n 1))
(display-comment (make-string n #\.))
(dff (proof-to-formula proof)) (display " by impnc elim") (newline))
((proof-in-and-intro-form)
(display-proof-aux (proof-in-and-intro-form-to-left proof) (+ n 1))
(display-proof-aux (proof-in-and-intro-form-to-right proof) (+ n 1))
(display-comment (make-string n #\.))
(dff (proof-to-formula proof)) (display " by and intro") (newline))
((proof-in-and-elim-left-form)
(display-proof-aux
(proof-in-and-elim-left-form-to-kernel proof) (+ n 1))
(display-comment (make-string n #\.))
(dff (proof-to-formula proof)) (display " by and elim left") (newline))
((proof-in-and-elim-right-form)
(display-proof-aux
(proof-in-and-elim-right-form-to-kernel proof) (+ n 1))
(display-comment (make-string n #\.))
(dff (proof-to-formula proof)) (display " by and elim right") (newline))
((proof-in-all-intro-form)
(display-proof-aux (proof-in-all-intro-form-to-kernel proof) (+ n 1))
(display-comment (make-string n #\.))
(dff (proof-to-formula proof)) (display " by all intro") (newline))
((proof-in-all-elim-form)
(display-proof-aux (proof-in-all-elim-form-to-op proof) (+ n 1))
(display-comment (make-string (+ n 1) #\.))
(display-term (proof-in-all-elim-form-to-arg proof)) (newline)
(display-comment (make-string n #\.))
(dff (proof-to-formula proof)) (display " by all elim") (newline))
((proof-in-allnc-intro-form)
(display-proof-aux (proof-in-allnc-intro-form-to-kernel proof) (+ n 1))
(display-comment (make-string n #\.))
(dff (proof-to-formula proof)) (display " by allnc intro") (newline))
((proof-in-allnc-elim-form)
(display-proof-aux (proof-in-allnc-elim-form-to-op proof) (+ n 1))
(display-comment (make-string (+ n 1) #\.))
(display-term (proof-in-allnc-elim-form-to-arg proof)) (newline)
(display-comment (make-string n #\.))
(dff (proof-to-formula proof)) (display " by allnc elim") (newline))
(else (myerror "display-proof-aux" "proof tag expected" (tag proof))))))
(define (dff formula) (df (fold-formula formula)))
(define (proof-to-pterm proof)
(let* ((genavars (append (proof-to-free-and-bound-avars proof)
(proof-to-aconsts-without-rules proof)))
(vars (map (lambda (x)
(type-to-new-var
(nbe-formula-to-type
(cond
((avar-form? x) (avar-to-formula x))
((aconst-form? x) (aconst-to-formula x))
(else (myerror
"proof-to-pterm" "genavar expected" x))))))
genavars))
(genavar-var-alist (map (lambda (u x) (list u x)) genavars vars))
(var-genavar-alist (map (lambda (x u) (list x u)) vars genavars)))
(proof-and-genavar-var-alist-to-pterm genavar-var-alist proof)))
(define (display-pterm . opt-proof)
(if (and (null? opt-proof)
(null? PPROOF-STATE))
(myerror
"display-pterm: proof argument or proof under construction expected"))
(let ((proof (if (null? opt-proof)
(pproof-state-to-proof)
(car opt-proof))))
(if
COMMENT-FLAG
(term-to-string (proof-to-pterm proof)))))
(define dpt display-pterm)
(define (display-normalized-pterm . opt-proof)
(if (and (null? opt-proof)
(null? PPROOF-STATE))
(myerror "display-normalized-pterm"
"proof argument or proof under construction expected"))
(let ((proof (if (null? opt-proof)
(pproof-state-to-proof)
(car opt-proof))))
(if
COMMENT-FLAG
(term-to-string (proof-to-pterm (nbe-normalize-proof proof))))))
(define dnpt display-normalized-pterm)
(define (display-eterm . opt-proof)
(if (and (null? opt-proof)
(null? PPROOF-STATE))
(myerror
"display-eterm: proof argument or proof under construction expected"))
(let ((proof (if (null? opt-proof)
(pproof-state-to-proof)
(car opt-proof))))
(if
COMMENT-FLAG
(term-to-string (proof-to-extracted-term proof)))))
(define det display-eterm)
(define (display-normalized-eterm . opt-proof)
(if (and (null? opt-proof)
(null? PPROOF-STATE))
(myerror "display-normalized-eterm"
"proof argument or proof under construction expected"))
(let ((proof (if (null? opt-proof)
(pproof-state-to-proof)
(car opt-proof))))
(if
COMMENT-FLAG
(term-to-string (nbe-normalize-term (proof-to-extracted-term proof))))))
(define dnet display-normalized-eterm)
; We also provide a readable type-free lambda expression
(define (proof-to-expr proof)
(case (tag proof)
((proof-in-avar-form)
(let* ((avar (proof-in-avar-form-to-avar proof))
(string (avar-to-string avar)))
(string->symbol string)))
((proof-in-aconst-form)
(let* ((aconst (proof-in-aconst-form-to-aconst proof))
(string (aconst-to-name aconst)))
(string->symbol string)))
((proof-in-imp-intro-form)
(let* ((avar (proof-in-imp-intro-form-to-avar proof))
(kernel (proof-in-imp-intro-form-to-kernel proof))
(string (avar-to-string avar)))
(list 'lambda (list (string->symbol string)) (proof-to-expr kernel))))
((proof-in-imp-elim-form)
(let* ((op (proof-in-imp-elim-form-to-op proof))
(arg (proof-in-imp-elim-form-to-arg proof)))
(list (proof-to-expr op)
(proof-to-expr arg))))
((proof-in-impnc-intro-form)
(let* ((avar (proof-in-impnc-intro-form-to-avar proof))
(kernel (proof-in-impnc-intro-form-to-kernel proof))
(string (avar-to-string avar)))
(list 'lambda (list (string->symbol string)) (proof-to-expr kernel))))
((proof-in-impnc-elim-form)
(let* ((op (proof-in-impnc-elim-form-to-op proof))
(arg (proof-in-impnc-elim-form-to-arg proof)))
(list (proof-to-expr op)
(proof-to-expr arg))))
((proof-in-and-intro-form)
(let* ((left (proof-in-and-intro-form-to-left proof))
(right (proof-in-and-intro-form-to-right proof)))
(list 'cons (proof-to-expr left) (proof-to-expr right))))
((proof-in-and-elim-left-form)
(let ((kernel (proof-in-and-elim-left-form-to-kernel proof)))
(list 'car (proof-to-expr kernel))))
((proof-in-and-elim-right-form)
(let ((kernel (proof-in-and-elim-right-form-to-kernel proof)))
(list 'cdr (proof-to-expr kernel))))
((proof-in-all-intro-form)
(let* ((var (proof-in-all-intro-form-to-var proof))
(kernel (proof-in-all-intro-form-to-kernel proof))
(string (var-to-string var)))
(list 'lambda (list (string->symbol string)) (proof-to-expr kernel))))
((proof-in-all-elim-form)
(let* ((op (proof-in-all-elim-form-to-op proof))
(arg (proof-in-all-elim-form-to-arg proof)))
(list (proof-to-expr op) (term-to-expr arg))))
((proof-in-allnc-intro-form)
(let* ((var (proof-in-allnc-intro-form-to-var proof))
(kernel (proof-in-allnc-intro-form-to-kernel proof))
(string (var-to-string var)))
(list 'lambda (list (string->symbol string)) (proof-to-expr kernel))))
((proof-in-allnc-elim-form)
(let* ((op (proof-in-allnc-elim-form-to-op proof))
(arg (proof-in-allnc-elim-form-to-arg proof)))
(list (proof-to-expr op) (term-to-expr arg))))
(else (myerror "proof-to-expr" "proof tag expected" (tag proof)))))
(define (display-proof-expr . opt-proof)
(if (and (null? opt-proof)
(null? PPROOF-STATE))
(myerror
"display-proof-expr"
"proof argument or proof under construction expected"))
(let* ((proof (if (null? opt-proof)
(pproof-state-to-proof)
(car opt-proof))))
(cond
(COMMENT-FLAG
(proof-to-expr proof)))))
(define dpe display-proof-expr)
(define (display-normalized-proof-expr . opt-proof)
(if (and (null? opt-proof)
(null? PPROOF-STATE))
(myerror
"display-normalized-proof-expr"
" proof argument or proof under construction expected"))
(let ((proof (if (null? opt-proof)
(pproof-state-to-proof)
(car opt-proof))))
(if
COMMENT-FLAG
(proof-to-expr (nbe-normalize-proof proof)))))
(define dnpe display-normalized-proof-expr)
(define (proof-to-expr-with-formulas proof . x)
(let ((f (if (null? x)
fold-formula
(car x))))
(proof-to-expr-with-formulas-aux proof f)))
(define (proof-to-expr-with-formulas-aux proof f)
(if
COMMENT-FLAG
(let* ((aconsts (proof-to-aconsts proof))
(bound-avars (proof-to-bound-avars proof))
(free-avars (proof-to-free-avars proof)))
(for-each
(lambda (aconst)
(display-comment
(aconst-to-name aconst) ": "
(pretty-print-string
(string-length COMMENT-STRING) ;indent
(- pp-width (string-length COMMENT-STRING))
(f (rename-variables (aconst-to-formula aconst)))))
(newline))
aconsts)
(for-each
(lambda (avar)
(display-comment
(avar-to-string avar) ": "
(pretty-print-string
(string-length COMMENT-STRING) ;indent
(- pp-width (string-length COMMENT-STRING))
(f (rename-variables (avar-to-formula avar)))))
(newline))
free-avars)
(for-each
(lambda (avar)
(display-comment
(avar-to-string avar) ": "
(pretty-print-string
(string-length COMMENT-STRING) ;indent
(- pp-width (string-length COMMENT-STRING))
(f (rename-variables (avar-to-formula avar)))))
(newline))
bound-avars)
(proof-to-expr proof))))
(define (proof-to-expr-with-aconsts proof . x)
(let ((f (if (null? x)
fold-formula
(car x))))
(proof-to-expr-with-aconsts-aux proof f)))
(define (proof-to-expr-with-aconsts-aux proof f)
(if
COMMENT-FLAG
(let* ((aconsts (proof-to-aconsts proof)))
(display-comment "Assumption constants:")
(newline)
(for-each
(lambda (aconst)
(display-comment
(aconst-to-name aconst) ": "
(pretty-print-string
(string-length COMMENT-STRING) ;indent
(- pp-width (string-length COMMENT-STRING))
(f (aconst-to-formula aconst))))
(newline))
aconsts)
(proof-to-expr proof))))
; 10-5. Check
; ===========
(define (check-and-display-proof . opt-proof-and-ignore-deco-flag)
(let* ((proofs (list-transform-positive opt-proof-and-ignore-deco-flag
proof-form?))
(rest (list-transform-positive opt-proof-and-ignore-deco-flag
(lambda (item) (not (proof-form? item)))))
(proof (if (pair? proofs)
(car proofs)
(pproof-state-to-proof)))
(ignore-deco-flag (if (pair? rest) (car rest) #f))
(nc-viols (nc-violations proof))
(h-deg-viols (h-deg-violations proof))
(avar-convention-viols (avar-convention-violations proof)))
(check-and-display-proof-aux proof 0 ignore-deco-flag)
(if (pair? nc-viols)
(begin
(comment
"Incorrect proof: nc-intro with computational variable(s)")
(for-each comment (map (lambda (x)
(if (var-form? x)
(var-to-string x)
(avar-to-string x)))
nc-viols))))
(if
(pair? h-deg-viols)
(begin
(comment
"Proof not suitable for extraction. h-deg violations at aconst(s)")
(for-each comment h-deg-viols)))
(if (pair? avar-convention-viols)
(begin
(comment
"Proof does not respect the avar convention.")
(do ((l avar-convention-viols (cdr l)))
((null? l))
(let* ((pair (car l))
(avar1 (car pair))
(avar2 (cadr pair)))
(comment "The same avar with name "
(let ((name (avar-to-name avar1)))
(if (string=? "" name)
DEFAULT-AVAR-NAME
name) )
" and index "
(avar-to-index avar1)
" carries the two different formulas")
(pp (avar-to-formula avar1))
(comment "and")
(pp (avar-to-formula avar2))))))
*the-non-printing-object*))
(define cdp check-and-display-proof)
(define (avar-convention-violations proof)
(duplicates-wrt avar=?
(proof-to-free-and-bound-avars-wrt avar-full=? proof)))
(define CDP-COMMENT-FLAG #t)
(define (check-and-display-proof-aux proof n ignore-deco-flag)
(if
COMMENT-FLAG
(cond
((proof-in-avar-form? proof)
(let ((fla (proof-to-formula proof))
(avar (proof-in-avar-form-to-avar proof)))
(if (not (avar? avar)) (myerror "avar expected" avar))
(let ((avar-fla (avar-to-formula avar)))
(check-formula fla)
(check-formula avar-fla)
(if (not (classical-formula=? fla avar-fla ignore-deco-flag))
(myerror "equal formulas expected" fla avar-fla))
(if CDP-COMMENT-FLAG
(begin
(display-comment (make-string n #\.))
(dff fla) (display " by assumption ")
(display (avar-to-string avar)) (newline))))))
((proof-in-aconst-form? proof)
(let ((fla (proof-to-formula proof))
(aconst (proof-in-aconst-form-to-aconst proof)))
(check-aconst aconst)
(let ((aconst-fla (aconst-to-formula aconst)))
(check-formula fla)
(check-formula aconst-fla)
(if (not (classical-formula=? fla aconst-fla ignore-deco-flag))
(myerror "equal formulas expected" fla aconst-fla))
(if ;check for correct Elim in case of an invariant idpc
(string=? "Elim" (aconst-to-name aconst))
(let* ((kernel (all-allnc-form-to-final-kernel aconst-fla))
(prems (imp-form-to-premises kernel))
(concl (imp-form-to-final-conclusion kernel))
(idpc-fla (if (pair? prems) (car prems)
(myerror "imp premises expected in" kernel)))
(pred (if (predicate-form? idpc-fla)
(predicate-form-to-predicate idpc-fla)
(myerror "predicate formula expected" idpc-fla)))
(idpc-name (if (idpredconst-form? pred)
(idpredconst-to-name pred)
(myerror "idpredconst expected" pred)))
(clauses (idpredconst-name-to-clauses idpc-name)))
(if
(and ;invariant idpc
(null? (idpredconst-name-to-opt-alg-name idpc-name))
;but not one of the special ones
;allowing arbitrary conclusions
;(to be extended to e.g. EvenReal)
(not (member idpc-name '("EqD" "ExU" "AndU")))
;not a uniform one-clause defined idpc
(not (and (= 1 (length clauses))
(predicate-form?
(impnc-form-to-final-conclusion
(allnc-form-to-final-kernel (car clauses))))))
;but with a c.r. conclusion
(not (formula-of-nulltype? concl)))
(myerror "invariant conclusion expected" concl
"in elimination axiom for invariant formula" idpc-fla))))
(if CDP-COMMENT-FLAG
(begin
(display-comment (make-string n #\.))
(dff fla)
(case (aconst-to-kind aconst)
((axiom) (display " by axiom "))
((theorem) (display " by theorem "))
((global-assumption) (display " by global assumption "))
(else (myerror "kind of aconst expected"
(aconst-to-kind aconst))))
(display (aconst-to-name aconst)) (newline))))))
((proof-in-imp-intro-form? proof)
(let ((fla (proof-to-formula proof))
(avar (proof-in-imp-intro-form-to-avar proof))
(kernel (proof-in-imp-intro-form-to-kernel proof)))
(check-and-display-proof-aux kernel (+ n 1) ignore-deco-flag)
(if (not (avar? avar)) (myerror "avar expected" avar))
(let ((avar-fla (avar-to-formula avar))
(kernel-fla (proof-to-formula kernel)))
(check-formula fla)
(if (not (classical-formula=? (make-imp avar-fla kernel-fla)
fla ignore-deco-flag))
(myerror "equal formulas expected"
(make-imp avar-fla kernel-fla) fla))
(if CDP-COMMENT-FLAG
(begin
(display-comment (make-string n #\.))
(dff fla) (display " by imp intro ")
(display (avar-to-string avar)) (newline))))))
((proof-in-imp-elim-form? proof)
(let ((fla (proof-to-formula proof))
(op (proof-in-imp-elim-form-to-op proof))
(arg (proof-in-imp-elim-form-to-arg proof)))
(check-and-display-proof-aux op (+ n 1) ignore-deco-flag)
(check-and-display-proof-aux arg (+ n 1) ignore-deco-flag)
(check-formula fla)
(let ((op-fla (proof-to-formula op))
(arg-fla (proof-to-formula arg)))
(if (not (imp-form? op-fla))
(myerror "imp form expected" op-fla))
(if (not (classical-formula=?
(imp-form-to-conclusion op-fla) fla ignore-deco-flag))
(myerror
"equal formulas expected" (imp-form-to-conclusion op-fla) fla))
(if (not (classical-formula=?
(imp-form-to-premise op-fla) arg-fla ignore-deco-flag))
(myerror
"equal formulas expected" (imp-form-to-premise op-fla) arg-fla))
(if CDP-COMMENT-FLAG
(begin
(display-comment (make-string n #\.))
(dff fla) (display " by imp elim") (newline))))))
((proof-in-impnc-intro-form? proof)
(let* ((fla (proof-to-formula proof))
(avar (proof-in-impnc-intro-form-to-avar proof))
(kernel (proof-in-impnc-intro-form-to-kernel proof))
(cvars (proof-to-cvars kernel)))
(if (and (not (formula-of-nulltype? (proof-to-formula kernel)))
(member-wrt avar=? avar cvars))
(begin (display-comment "warning: impnc-intro with cvar"
(avar-to-string avar))
(newline)))
(check-and-display-proof-aux kernel (+ n 1) ignore-deco-flag)
(if (not (avar? avar)) (myerror "avar expected" avar))
(let ((avar-fla (avar-to-formula avar))
(kernel-fla (proof-to-formula kernel)))
(check-formula fla)
(if (not (classical-formula=? (make-impnc avar-fla kernel-fla)
fla ignore-deco-flag))
(myerror "equal formulas expected"
(make-impnc avar-fla kernel-fla) fla))
(if CDP-COMMENT-FLAG
(begin
(display-comment (make-string n #\.))
(dff fla) (display " by impnc intro ")
(display (avar-to-string avar)) (newline))))))
((proof-in-impnc-elim-form? proof)
(let ((fla (proof-to-formula proof))
(op (proof-in-impnc-elim-form-to-op proof))
(arg (proof-in-impnc-elim-form-to-arg proof)))
(check-and-display-proof-aux op (+ n 1) ignore-deco-flag)
(check-and-display-proof-aux arg (+ n 1) ignore-deco-flag)
(check-formula fla)
(let ((op-fla (proof-to-formula op))
(arg-fla (proof-to-formula arg)))
(if (not (impnc-form? op-fla))
(myerror "impnc form expected" op-fla))
(if (not (classical-formula=?
(impnc-form-to-conclusion op-fla) fla ignore-deco-flag))
(myerror
"equal formulas expected" (impnc-form-to-conclusion op-fla) fla))
(if (not (classical-formula=?
(impnc-form-to-premise op-fla) arg-fla ignore-deco-flag))
(myerror
"equal formulas expected"
(impnc-form-to-premise op-fla) arg-fla))
(if CDP-COMMENT-FLAG
(begin
(display-comment (make-string n #\.))
(dff fla) (display " by impnc elim") (newline))))))
((proof-in-and-intro-form? proof)
(let ((fla (proof-to-formula proof))
(left (proof-in-and-intro-form-to-left proof))
(right (proof-in-and-intro-form-to-right proof)))
(check-and-display-proof-aux left (+ n 1) ignore-deco-flag)
(check-and-display-proof-aux right (+ n 1) ignore-deco-flag)
(check-formula fla)
(let ((left-fla (proof-to-formula left))
(right-fla (proof-to-formula right)))
(if (not (and-form? fla))
(myerror "and form expected" fla))
(if (not (classical-formula=?
left-fla (and-form-to-left fla) ignore-deco-flag))
(myerror
"equal formulas expected" left-fla (and-form-to-left fla)))
(if (not (classical-formula=?
right-fla (and-form-to-right fla) ignore-deco-flag))
(myerror
"equal formulas expected" right-fla (and-form-to-right fla)))
(if CDP-COMMENT-FLAG
(begin
(display-comment (make-string n #\.))
(dff fla) (display " by and intro") (newline))))))
((proof-in-and-elim-left-form? proof)
(let ((fla (proof-to-formula proof))
(kernel (proof-in-and-elim-left-form-to-kernel proof)))
(check-and-display-proof-aux kernel (+ n 1) ignore-deco-flag)
(check-formula fla)
(let ((kernel-fla (proof-to-formula kernel)))
(if (not (and-form? kernel-fla))
(myerror "in and-elim and-form expected" kernel-fla))
(if (not (classical-formula=?
(and-form-to-left kernel-fla) fla ignore-deco-flag))
(myerror "in and-elim formulas do not fit"
(and-form-to-left kernel-fla) fla))
(if CDP-COMMENT-FLAG
(begin
(display-comment (make-string n #\.))
(dff fla) (display " by and elim left") (newline))))))
((proof-in-and-elim-right-form? proof)
(let ((fla (proof-to-formula proof))
(kernel (proof-in-and-elim-right-form-to-kernel proof)))
(check-and-display-proof-aux kernel (+ n 1) ignore-deco-flag)
(check-formula fla)
(let ((kernel-fla (proof-to-formula kernel)))
(if (not (and-form? kernel-fla))
(myerror "in and-elim and-form expected" kernel-fla))
(if (not (classical-formula=?
(and-form-to-right kernel-fla) fla ignore-deco-flag))
(myerror "in and-elim formulas do not fit"
(and-form-to-right kernel-fla) fla))
(if CDP-COMMENT-FLAG
(begin
(display-comment (make-string n #\.))
(dff fla) (display " by and elim right") (newline))))))
((proof-in-all-intro-form? proof)
(let ((fla (proof-to-formula proof))
(var (proof-in-all-intro-form-to-var proof))
(kernel (proof-in-all-intro-form-to-kernel proof)))
(check-and-display-proof-aux kernel (+ n 1) ignore-deco-flag)
(check-formula fla)
(let* ((context (proof-to-context kernel))
(avars (context-to-avars context))
(formulas (map avar-to-formula avars)))
(if
(and
(member var (apply union (map formula-to-free formulas)))
(member var (apply union (map formula-to-free
(map normalize-formula formulas)))))
(myerror "variable condition fails for" var)))
(if (not (all-form? fla))
(myerror "all form expected" fla))
(let ((kernel-fla (proof-to-formula kernel)))
(if (not (classical-formula=?
(make-all var kernel-fla) fla ignore-deco-flag))
(myerror "equal formulas expected"
(make-all var kernel-fla) fla)))
(if CDP-COMMENT-FLAG
(begin
(display-comment (make-string n #\.))
(dff fla) (display " by all intro") (newline)))))
((proof-in-all-elim-form? proof)
(let ((fla (proof-to-formula proof))
(op (proof-in-all-elim-form-to-op proof))
(arg (proof-in-all-elim-form-to-arg proof)))
(check-and-display-proof-aux op (+ n 1) ignore-deco-flag)
(check-formula fla)
(check-term arg)
(let ((op-fla (proof-to-formula op)))
(if (not (all-form? op-fla))
(myerror "all form expected" op-fla))
(if (not (equal? (var-to-type (all-form-to-var op-fla))
(term-to-type arg)))
(myerror "equal types expected of variable"
(all-form-to-var op-fla) "and term" arg))
(if (and (t-deg-one? (var-to-t-deg (all-form-to-var op-fla)))
(not (synt-total? arg)))
(myerror "degrees of totality do not fit for variable"
(all-form-to-var op-fla) "and term" arg))
(let ((var (all-form-to-var op-fla))
(kernel (all-form-to-kernel op-fla)))
(if (and (term-in-var-form? arg)
(equal? var (term-in-var-form-to-var arg)))
(if (not (classical-formula=? fla kernel ignore-deco-flag))
(myerror "equal formulas expected" fla kernel))
(if (not (classical-formula=?
fla (formula-subst kernel var arg) ignore-deco-flag))
(myerror "equal formulas expected"
fla (formula-subst kernel var arg)))))
(if CDP-COMMENT-FLAG
(begin
(display-comment (make-string (+ n 1) #\.))
(display-term arg) (newline)
(display-comment (make-string n #\.))
(dff fla) (display " by all elim") (newline))))))
((proof-in-allnc-intro-form? proof)
(let* ((fla (proof-to-formula proof))
(var (proof-in-allnc-intro-form-to-var proof))
(kernel (proof-in-allnc-intro-form-to-kernel proof))
(context (proof-to-context kernel))
(cvars (proof-to-cvars kernel))
(avars (context-to-avars context))
(formulas (map avar-to-formula avars))
(free (apply union (map formula-to-free formulas))))
(if
(or (and
(member var (apply union (map formula-to-free formulas)))
(member var (apply union (map formula-to-free
(map normalize-formula formulas)))))
(and (not (formula-of-nulltype? (proof-to-formula kernel)))
(member var cvars)))
(begin (display-comment "warning: allnc-intro with cvar"
(var-to-string var))
(newline)))
(check-and-display-proof-aux kernel (+ n 1) ignore-deco-flag)
(check-formula fla)
(if (not (allnc-form? fla))
(myerror "allnc form expected" fla))
(let ((kernel-fla (proof-to-formula kernel)))
(if (not (classical-formula=?
(make-allnc var kernel-fla) fla ignore-deco-flag))
(myerror "equal formulas expected"
(make-allnc var kernel-fla) fla)))
(if CDP-COMMENT-FLAG
(begin
(display-comment (make-string n #\.))
(dff fla) (display " by allnc intro") (newline)))))
((proof-in-allnc-elim-form? proof)
(let ((fla (proof-to-formula proof))
(op (proof-in-allnc-elim-form-to-op proof))
(arg (proof-in-allnc-elim-form-to-arg proof)))
(check-and-display-proof-aux op (+ n 1) ignore-deco-flag)
(check-formula fla)
(check-term arg)
(let ((op-fla (proof-to-formula op)))
(if (not (allnc-form? op-fla))
(myerror "allnc form expected" op-fla))
(if (not (equal? (var-to-type (allnc-form-to-var op-fla))
(term-to-type arg)))
(myerror "equal types expected of variable"
(allnc-form-to-var op-fla) "and term" arg))
(if (and (t-deg-one? (var-to-t-deg (allnc-form-to-var op-fla)))
(not (synt-total? arg)))
(myerror "degrees of totality do not fit for variable"
(allnc-form-to-var op-fla) "and term" arg))
(let ((op-var (allnc-form-to-var op-fla))
(op-kernel (allnc-form-to-kernel op-fla)))
(if (and (term-in-var-form? arg)
(equal? op-var (term-in-var-form-to-var arg)))
(if (not (classical-formula=? fla op-kernel ignore-deco-flag))
(myerror "equal formulas expected" fla op-kernel))
(if (not (classical-formula=?
fla (formula-subst op-kernel op-var arg)
ignore-deco-flag))
(myerror "equal formulas expected"
fla (formula-subst op-kernel op-var arg)))))
(if CDP-COMMENT-FLAG
(begin
(display-comment (make-string (+ n 1) #\.))
(display-term arg) (newline)
(display-comment (make-string n #\.))
(dff fla) (display " by allnc elim") (newline))))))
(else (myerror "proof tag expected"
(tag proof))))))
; 10-6. Classical logic
; =====================
; (proof-of-stab-at formula) generates a proof of ((A -> F) -> F) -> A.
; For F, T one takes the obvious proof, and for other atomic formulas
; the proof using cases on booleans. For all other prime, ex or exnc
; formulas one takes an instance of the global assumption Stab:
; ((Pvar -> F) -> F) -> Pvar.
(define (proof-of-stab-at formula) ;formula must be unfolded
(let ((rename (make-rename empty-subst))
(prename (make-prename empty-subst)))
(proof-of-stab-at-aux formula rename prename)))
(define (proof-of-stab-at-aux formula rename prename)
(case (tag formula)
((atom predicate ex exnc)
(cond
((equal? falsity formula)
; u2:F
; --------u2
; u1:(F -> F) -> F F -> F
; ----------------------------
; F
(let ((u1 (formula-to-new-avar (make-negation (make-negation falsity))))
(u2 (formula-to-new-avar falsity)))
(make-proof-in-imp-intro-form
u1 (make-proof-in-imp-elim-form
(make-proof-in-avar-form u1)
(make-proof-in-imp-intro-form
u2 (make-proof-in-avar-form u2))))))
((equal? truth formula)
(let ((u1 (formula-to-new-avar (make-negation (make-negation truth)))))
(make-proof-in-imp-intro-form
u1 (make-proof-in-aconst-form truth-aconst))))
((atom-form? formula)
(let ((kernel (atom-form-to-kernel formula)))
(if (not (synt-total? kernel))
(myerror "proof-of-stab-at-aux" "total kernel expected" kernel))
(mk-proof-in-elim-form
(make-proof-in-aconst-form
(all-formula-to-cases-aconst
(pf "all boole(((boole -> F) -> F) -> boole)")))
kernel
(make-proof-in-imp-intro-form
(formula-to-new-avar (make-negation (make-negation truth)))
(make-proof-in-aconst-form truth-aconst))
(let ((u1 (formula-to-new-avar
(make-negation (make-negation falsity))))
(u2 (formula-to-new-avar falsity)))
(make-proof-in-imp-intro-form
u1 (make-proof-in-imp-elim-form
(make-proof-in-avar-form u1)
(make-proof-in-imp-intro-form
u2 (make-proof-in-avar-form u2))))))))
(else
(let* ((aconst (global-assumption-name-to-aconst "Stab"))
(stab-formula (aconst-to-uninst-formula aconst))
(pvars (formula-to-pvars stab-formula))
(pvar (if (pair? pvars) (car pvars)
(myerror
"proof-to-stab-at" "stab-formula with pvars expected"
stab-formula)))
(cterm (make-cterm formula))
(psubst (make-subst-wrt pvar-cterm-equal? pvar cterm)))
(proof-substitute-aux
(make-proof-in-aconst-form aconst)
empty-subst empty-subst psubst empty-subst
rename prename
(make-arename empty-subst psubst rename prename))))))
((imp)
; u4:A -> B u2:A
; ----------------
; u3:~B B
; ----------------
; F
; -------- u4
; u1:~~(A -> B) ~(A -> B)
; ------------------------------
; F
; | --- u3
; ~~B -> B ~~B
; -----------------------------
; B
(let* ((prem (imp-form-to-premise formula))
(concl (imp-form-to-conclusion formula))
(u1 (formula-to-new-avar (make-negation (make-negation formula))))
(u2 (formula-to-new-avar prem))
(u3 (formula-to-new-avar (make-negation concl)))
(u4 (formula-to-new-avar formula)))
(mk-proof-in-intro-form
u1 u2 (make-proof-in-imp-elim-form
(proof-of-stab-at-aux concl rename prename)
(make-proof-in-imp-intro-form
u3 (make-proof-in-imp-elim-form
(make-proof-in-avar-form u1)
(make-proof-in-imp-intro-form
u4 (make-proof-in-imp-elim-form
(make-proof-in-avar-form u3)
(make-proof-in-imp-elim-form
(make-proof-in-avar-form u4)
(make-proof-in-avar-form u2))))))))))
((impnc)
; u4:A --> B u2:A
; -----------------
; u3:~B B
; ----------------
; F
; -------- u4
; u1:~~(A --> B) ~(A --> B)
; ------------------------------
; F
; | --- u3
; ~~B -> B ~~B
; -----------------------------
; B
(let* ((prem (impnc-form-to-premise formula))
(concl (impnc-form-to-conclusion formula))
(u1 (formula-to-new-avar (make-negation (make-negation formula))))
(u2 (formula-to-new-avar prem))
(u3 (formula-to-new-avar (make-negation concl)))
(u4 (formula-to-new-avar formula)))
(mk-proof-in-intro-form
u1 u2 (make-proof-in-imp-elim-form
(proof-of-stab-at-aux concl rename prename)
(make-proof-in-imp-intro-form
u3 (make-proof-in-imp-elim-form
(make-proof-in-avar-form u1)
(make-proof-in-imp-intro-form
u4 (make-proof-in-imp-elim-form
(make-proof-in-avar-form u3)
(make-proof-in-impnc-elim-form
(make-proof-in-avar-form u4)
(make-proof-in-avar-form u2))))))))))
((and)
; u3:A&B u3:A&B
; ------ ------
; u2:~A A u2:~B B
; ------------ ------------
; F F
; ------ u3 ------ u3
; u1:~~(A&B) ~(A&B) u1:~~(A&B) ~(A&B)
; ------------------- -------------------
; F F
; | --- u2 | --- u2
; ~~A -> A ~~A ~~B -> B ~~B
; ------------------- -------------------
; A B
; ----------------------------------
; A & B
(let* ((left-conjunct (and-form-to-left formula))
(right-conjunct (and-form-to-right formula))
(u1 (formula-to-new-avar (make-negation (make-negation formula))))
(u2left (formula-to-new-avar (make-negation left-conjunct)))
(u2right (formula-to-new-avar (make-negation right-conjunct)))
(u3 (formula-to-new-avar formula)))
(make-proof-in-imp-intro-form
u1 (make-proof-in-and-intro-form
(make-proof-in-imp-elim-form
(proof-of-stab-at-aux left-conjunct rename prename)
(make-proof-in-imp-intro-form
u2left (make-proof-in-imp-elim-form
(make-proof-in-avar-form u1)
(make-proof-in-imp-intro-form
u3 (make-proof-in-imp-elim-form
(make-proof-in-avar-form u2left)
(make-proof-in-and-elim-left-form
(make-proof-in-avar-form u3)))))))
(make-proof-in-imp-elim-form
(proof-of-stab-at-aux right-conjunct rename prename)
(make-proof-in-imp-intro-form
u2right (make-proof-in-imp-elim-form
(make-proof-in-avar-form u1)
(make-proof-in-imp-intro-form
u3 (make-proof-in-imp-elim-form
(make-proof-in-avar-form u2right)
(make-proof-in-and-elim-right-form
(make-proof-in-avar-form u3)))))))))))
((all)
; u3:all x A x
; --------------
; u2:~A A
; ----------------
; F
; -------- u3
; u1:~~all x A ~all x A
; -----------------------------
; F
; | --- u2
; ~~A -> A ~~A
; -----------------------------
; A
; -------
; all x A
(let* ((var (all-form-to-var formula))
(kernel (all-form-to-kernel formula))
(u1 (formula-to-new-avar (make-negation (make-negation formula))))
(u2 (formula-to-new-avar (make-negation kernel)))
(u3 (formula-to-new-avar formula)))
(mk-proof-in-intro-form
u1 var (make-proof-in-imp-elim-form
(proof-of-stab-at-aux kernel rename prename)
(make-proof-in-imp-intro-form
u2 (make-proof-in-imp-elim-form
(make-proof-in-avar-form u1)
(make-proof-in-imp-intro-form
u3 (make-proof-in-imp-elim-form
(make-proof-in-avar-form u2)
(make-proof-in-all-elim-form
(make-proof-in-avar-form u3)
(make-term-in-var-form var))))))))))
((allnc)
; u3:allnc x A x
; ----------------
; u2:~A A
; ----------------
; F
; ---------- u3
; u1:~~allnc x A ~allnc x A
; ---------------------------------
; F
; | --- u2
; ~~A -> A ~~A
; -----------------------------
; A
; ---------
; allnc x A
(let* ((var (allnc-form-to-var formula))
(kernel (allnc-form-to-kernel formula))
(u1 (formula-to-new-avar (make-negation (make-negation formula))))
(u2 (formula-to-new-avar (make-negation kernel)))
(u3 (formula-to-new-avar formula)))
(mk-proof-in-nc-intro-form
u1 var (make-proof-in-imp-elim-form
(proof-of-stab-at-aux kernel rename prename)
(make-proof-in-imp-intro-form
u2 (make-proof-in-imp-elim-form
(make-proof-in-avar-form u1)
(make-proof-in-imp-intro-form
u3 (make-proof-in-imp-elim-form
(make-proof-in-avar-form u2)
(make-proof-in-allnc-elim-form
(make-proof-in-avar-form u3)
(make-term-in-var-form var))))))))))
(else (myerror "proof-of-stab-at-aux" "formula expected" formula))))
(define (proof-of-stab-log-at formula) ;formula must be unfolded
(let ((rename (make-rename empty-subst))
(prename (make-prename empty-subst)))
(proof-of-stab-log-at-aux formula rename prename)))
(define (proof-of-stab-log-at-aux formula rename prename)
(case (tag formula)
((atom predicate ex exnc)
(cond
((equal? falsity-log formula)
; u2:bot
; ----------u2
; u1:(bot -> bot) -> bot bot -> bot
; --------------------------------------
; bot
(let ((u1 (formula-to-new-avar
(make-negation-log (make-negation-log falsity-log))))
(u2 (formula-to-new-avar falsity-log)))
(make-proof-in-imp-intro-form
u1 (make-proof-in-imp-elim-form
(make-proof-in-avar-form u1)
(make-proof-in-imp-intro-form
u2 (make-proof-in-avar-form u2))))))
((equal? truth formula)
(let ((u1 (formula-to-new-avar
(make-negation-log (make-negation-log truth)))))
(make-proof-in-imp-intro-form
u1 (make-proof-in-aconst-form truth-aconst))))
(else
(let* ((aconst (global-assumption-name-to-aconst "Stab-Log"))
(stab-log-formula (aconst-to-uninst-formula aconst))
(pvars (formula-to-pvars stab-log-formula))
(pvar (if (pair? pvars) (car pvars)
(myerror "proof-to-stab-log-at"
"stab-log-formula with pvars expected"
stab-log-formula)))
(cterm (make-cterm formula))
(psubst (make-subst-wrt pvar-cterm-equal? pvar cterm)))
(proof-substitute-aux
(make-proof-in-aconst-form aconst)
empty-subst empty-subst psubst empty-subst
rename prename
(make-arename empty-subst psubst rename prename))))))
((imp)
; u4:A -> B u2:A
; ----------------
; u3:~B B
; ----------------
; bot
; -------- u4
; u1:~~(A -> B) ~(A -> B)
; ------------------------------
; bot
; | --- u3
; ~~B -> B ~~B
; -----------------------------
; B
(let* ((prem (imp-form-to-premise formula))
(concl (imp-form-to-conclusion formula))
(u1 (formula-to-new-avar
(make-negation-log (make-negation-log formula))))
(u2 (formula-to-new-avar prem))
(u3 (formula-to-new-avar (make-negation-log concl)))
(u4 (formula-to-new-avar formula)))
(mk-proof-in-intro-form
u1 u2 (make-proof-in-imp-elim-form
(proof-of-stab-log-at-aux concl rename prename)
(make-proof-in-imp-intro-form
u3 (make-proof-in-imp-elim-form
(make-proof-in-avar-form u1)
(make-proof-in-imp-intro-form
u4 (make-proof-in-imp-elim-form
(make-proof-in-avar-form u3)
(make-proof-in-imp-elim-form
(make-proof-in-avar-form u4)
(make-proof-in-avar-form u2))))))))))
((impnc)
; u4:A --> B u2:A
; -----------------
; u3:~B B
; ----------------
; bot
; -------- u4
; u1:~~(A --> B) ~(A --> B)
; ------------------------------
; bot
; | --- u3
; ~~B -> B ~~B
; -----------------------------
; B
(let* ((prem (impnc-form-to-premise formula))
(concl (impnc-form-to-conclusion formula))
(u1 (formula-to-new-avar
(make-negation-log (make-negation-log formula))))
(u2 (formula-to-new-avar prem))
(u3 (formula-to-new-avar (make-negation-log concl)))
(u4 (formula-to-new-avar formula)))
(mk-proof-in-intro-form
u1 u2 (make-proof-in-imp-elim-form
(proof-of-stab-log-at-aux concl rename prename)
(make-proof-in-imp-intro-form
u3 (make-proof-in-imp-elim-form
(make-proof-in-avar-form u1)
(make-proof-in-imp-intro-form
u4 (make-proof-in-imp-elim-form
(make-proof-in-avar-form u3)
(make-proof-in-impnc-elim-form
(make-proof-in-avar-form u4)
(make-proof-in-avar-form u2))))))))))
((and)
; u3:A&B u3:A&B
; ------ ------
; u2:~A A u2:~B B
; ------------ ------------
; bot bot
; ------ u3 ------ u3
; u1:~~(A&B) ~(A&B) u1:~~(A&B) ~(A&B)
; ------------------- -------------------
; bot bot
; | --- u2 | --- u2
; ~~A -> A ~~A ~~B -> B ~~B
; ------------------- -------------------
; A B
; ----------------------------------
; A & B
(let* ((left-conjunct (and-form-to-left formula))
(right-conjunct (and-form-to-right formula))
(u1 (formula-to-new-avar
(make-negation-log (make-negation-log formula))))
(u2left (formula-to-new-avar (make-negation-log left-conjunct)))
(u2right (formula-to-new-avar (make-negation-log right-conjunct)))
(u3 (formula-to-new-avar formula)))
(make-proof-in-imp-intro-form
u1 (make-proof-in-and-intro-form
(make-proof-in-imp-elim-form
(proof-of-stab-log-at-aux left-conjunct rename prename)
(make-proof-in-imp-intro-form
u2left (make-proof-in-imp-elim-form
(make-proof-in-avar-form u1)
(make-proof-in-imp-intro-form
u3 (make-proof-in-imp-elim-form
(make-proof-in-avar-form u2left)
(make-proof-in-and-elim-left-form
(make-proof-in-avar-form u3)))))))
(make-proof-in-imp-elim-form
(proof-of-stab-log-at-aux right-conjunct rename prename)
(make-proof-in-imp-intro-form
u2right (make-proof-in-imp-elim-form
(make-proof-in-avar-form u1)
(make-proof-in-imp-intro-form
u3 (make-proof-in-imp-elim-form
(make-proof-in-avar-form u2right)
(make-proof-in-and-elim-right-form
(make-proof-in-avar-form u3)))))))))))
((all)
; u3:all x A x
; --------------
; u2:~A A
; ----------------
; bot
; -------- u3
; u1:~~all x A ~all x A
; -----------------------------
; bot
; | --- u2
; ~~A -> A ~~A
; -----------------------------
; A
; -------
; all x A
(let* ((var (all-form-to-var formula))
(kernel (all-form-to-kernel formula))
(u1 (formula-to-new-avar
(make-negation-log (make-negation-log formula))))
(u2 (formula-to-new-avar (make-negation-log kernel)))
(u3 (formula-to-new-avar formula)))
(mk-proof-in-intro-form
u1 var (make-proof-in-imp-elim-form
(proof-of-stab-log-at-aux kernel rename prename)
(make-proof-in-imp-intro-form
u2 (make-proof-in-imp-elim-form
(make-proof-in-avar-form u1)
(make-proof-in-imp-intro-form
u3 (make-proof-in-imp-elim-form
(make-proof-in-avar-form u2)
(make-proof-in-all-elim-form
(make-proof-in-avar-form u3)
(make-term-in-var-form var))))))))))
((allnc)
; u3:allnc x A x
; ----------------
; u2:~A A
; ----------------
; bot
; ---------- u3
; u1:~~allnc x A ~allnc x A
; -----------------------------
; bot
; | --- u2
; ~~A -> A ~~A
; -----------------------------
; A
; -------
; allnc x A
(let* ((var (allnc-form-to-var formula))
(kernel (allnc-form-to-kernel formula))
(u1 (formula-to-new-avar
(make-negation-log (make-negation-log formula))))
(u2 (formula-to-new-avar (make-negation-log kernel)))
(u3 (formula-to-new-avar formula)))
(mk-proof-in-nc-intro-form
u1 var (make-proof-in-imp-elim-form
(proof-of-stab-log-at-aux kernel rename prename)
(make-proof-in-imp-intro-form
u2 (make-proof-in-imp-elim-form
(make-proof-in-avar-form u1)
(make-proof-in-imp-intro-form
u3 (make-proof-in-imp-elim-form
(make-proof-in-avar-form u2)
(make-proof-in-allnc-elim-form
(make-proof-in-avar-form u3)
(make-term-in-var-form var))))))))))
(else (myerror "proof-of-stab-log-at-aux" "formula expected" formula))))
(define (proof-of-efq-at formula) ;formula must be unfolded
(let ((rename (make-rename empty-subst))
(prename (make-prename empty-subst)))
(proof-of-efq-at-aux formula rename prename)))
(define (proof-of-efq-at-aux formula rename prename)
(case (tag formula)
((atom predicate)
(cond
((equal? falsity formula)
; u1:F
; --------u1
; F -> F
(let ((u1 (formula-to-new-avar falsity)))
(make-proof-in-imp-intro-form
u1 (make-proof-in-avar-form u1))))
((equal? truth formula)
(let ((u1 (formula-to-new-avar falsity)))
(make-proof-in-imp-intro-form
u1 (make-proof-in-aconst-form truth-aconst))))
((atom-form? formula)
(let ((kernel (atom-form-to-kernel formula)))
(if (not (synt-total? kernel))
(myerror "proof-of-efq-at-aux" "total kernel expected" kernel))
(mk-proof-in-elim-form
(make-proof-in-aconst-form
(all-formula-to-cases-aconst
(pf "all boole(F -> boole)")))
kernel
(make-proof-in-imp-intro-form
(formula-to-new-avar falsity)
(make-proof-in-aconst-form truth-aconst))
(let ((u1 (formula-to-new-avar falsity)))
(make-proof-in-imp-intro-form
u1 (make-proof-in-avar-form u1))))))
(else
(let* ((aconst (global-assumption-name-to-aconst "Efq"))
(efq-formula (aconst-to-uninst-formula aconst))
(pvars (formula-to-pvars efq-formula))
(pvar (if (pair? pvars) (car pvars)
(myerror
"proof-to-efq-at" "efq-formula with pvars expected"
efq-formula)))
(cterm (make-cterm formula))
(psubst (make-subst-wrt pvar-cterm-equal? pvar cterm)))
(proof-substitute-aux
(make-proof-in-aconst-form aconst)
empty-subst empty-subst psubst empty-subst
rename prename
(make-arename empty-subst psubst rename prename))))))
((imp)
; |
; F -> B u1:F
; -----------------
; B
(let* ((prem (imp-form-to-premise formula))
(concl (imp-form-to-conclusion formula))
(u1 (formula-to-new-avar falsity))
(u2 (formula-to-new-avar prem)))
(mk-proof-in-intro-form
u1 u2 (make-proof-in-imp-elim-form
(proof-of-efq-at-aux concl rename prename)
(make-proof-in-avar-form u1)))))
((impnc)
; |
; F -> B u1:F
; -----------------
; B
(let* ((prem (impnc-form-to-premise formula))
(concl (impnc-form-to-conclusion formula))
(u1 (formula-to-new-avar falsity))
(u2 (formula-to-new-avar prem)))
(make-proof-in-imp-intro-form
u1 (make-proof-in-impnc-intro-form
u2 (make-proof-in-imp-elim-form
(proof-of-efq-at-aux concl rename prename)
(make-proof-in-avar-form u1))))))
((and)
; | |
; F -> A u1:F F -> B u1:F
; ------------------- ----------------
; A B
; ---------------------------------
; A & B
(let* ((left-conjunct (and-form-to-left formula))
(right-conjunct (and-form-to-right formula))
(u1 (formula-to-new-avar falsity)))
(make-proof-in-imp-intro-form
u1 (make-proof-in-and-intro-form
(make-proof-in-imp-elim-form
(proof-of-efq-at-aux left-conjunct rename prename)
(make-proof-in-avar-form u1))
(make-proof-in-imp-elim-form
(proof-of-efq-at-aux right-conjunct rename prename)
(make-proof-in-avar-form u1))))))
((all)
(let* ((var (all-form-to-var formula))
(kernel (all-form-to-kernel formula))
(u1 (formula-to-new-avar falsity)))
(mk-proof-in-intro-form
u1 var (make-proof-in-imp-elim-form
(proof-of-efq-at-aux kernel rename prename)
(make-proof-in-avar-form u1)))))
((allnc)
(let* ((var (allnc-form-to-var formula))
(kernel (allnc-form-to-kernel formula))
(u1 (formula-to-new-avar falsity)))
(mk-proof-in-intro-form
u1 var (make-proof-in-imp-elim-form
(proof-of-efq-at-aux kernel rename prename)
(make-proof-in-avar-form u1)))))
((ex)
(let* ((var (ex-form-to-var formula))
(kernel (ex-form-to-kernel formula))
(type (var-to-type var))
(inhab (type-to-canonical-inhabitant type))
(inst-kernel (formula-subst kernel var inhab))
(u1 (formula-to-new-avar falsity)))
(make-proof-in-imp-intro-form
u1 (make-proof-in-ex-intro-form
inhab formula
(make-proof-in-imp-elim-form
(proof-of-efq-at-aux inst-kernel rename prename)
(make-proof-in-avar-form u1))))))
((exnc)
(let* ((var (exnc-form-to-var formula))
(kernel (exnc-form-to-kernel formula))
(type (var-to-type var))
(inhab (type-to-canonical-inhabitant type))
(inst-kernel (formula-subst kernel var inhab))
(u1 (formula-to-new-avar falsity)))
(make-proof-in-imp-intro-form
u1 (make-proof-in-exnc-intro-form
inhab formula
(make-proof-in-imp-elim-form
(proof-of-efq-at-aux inst-kernel rename prename)
(make-proof-in-avar-form u1))))))
(else (myerror "proof-of-efq-at-aux" "formula expected" formula))))
(define (proof-of-efq-log-at formula) ;formula must be unfolded
(let ((rename (make-rename empty-subst))
(prename (make-prename empty-subst)))
(proof-of-efq-log-at-aux formula rename prename)))
(define (proof-of-efq-log-at-aux formula rename prename)
(case (tag formula)
((atom predicate ex exnc)
(cond
((equal? falsity-log formula)
; u1:bot
; -----------u1
; bot -> bot
(let ((u1 (formula-to-new-avar falsity-log)))
(make-proof-in-imp-intro-form
u1 (make-proof-in-avar-form u1))))
((equal? truth formula)
(let ((u1 (formula-to-new-avar falsity-log)))
(make-proof-in-imp-intro-form
u1 (make-proof-in-aconst-form truth-aconst))))
(else
(let* ((aconst (global-assumption-name-to-aconst "Efq-Log"))
(efq-log-formula (aconst-to-uninst-formula aconst))
(pvars (formula-to-pvars efq-log-formula))
(pvar (if (pair? pvars) (car (last-pair pvars))
(myerror "proof-to-efq-log-at"
"efq-log-formula with pvars expected"
efq-log-formula)))
(cterm (make-cterm formula))
(psubst (make-subst-wrt pvar-cterm-equal? pvar cterm)))
(proof-substitute-aux
(make-proof-in-aconst-form aconst)
empty-subst empty-subst psubst empty-subst
rename prename
(make-arename empty-subst psubst rename prename))))))
((imp)
; |
; bot -> B u1:bot
; -------------------
; B
(let* ((prem (imp-form-to-premise formula))
(concl (imp-form-to-conclusion formula))
(u1 (formula-to-new-avar falsity-log))
(u2 (formula-to-new-avar prem)))
(mk-proof-in-intro-form
u1 u2 (make-proof-in-imp-elim-form
(proof-of-efq-log-at-aux concl rename prename)
(make-proof-in-avar-form u1)))))
((impnc)
; |
; bot -> B u1:bot
; -------------------
; B
(let* ((prem (impnc-form-to-premise formula))
(concl (impnc-form-to-conclusion formula))
(u1 (formula-to-new-avar falsity-log))
(u2 (formula-to-new-avar prem)))
(make-proof-in-imp-intro-form
u1 (make-proof-in-impnc-intro-form
u2 (make-proof-in-imp-elim-form
(proof-of-efq-log-at-aux concl rename prename)
(make-proof-in-avar-form u1))))))
((and)
; | |
; bot -> A u1:bot bot -> B u1:bot
; ------------------- ------------------
; A B
; ---------------------------------
; A & B
(let* ((left-conjunct (and-form-to-left formula))
(right-conjunct (and-form-to-right formula))
(u1 (formula-to-new-avar falsity-log)))
(make-proof-in-imp-intro-form
u1 (make-proof-in-and-intro-form
(make-proof-in-imp-elim-form
(proof-of-efq-log-at-aux left-conjunct rename prename)
(make-proof-in-avar-form u1))
(make-proof-in-imp-elim-form
(proof-of-efq-log-at-aux right-conjunct rename prename)
(make-proof-in-avar-form u1))))))
((all)
(let* ((var (all-form-to-var formula))
(kernel (all-form-to-kernel formula))
(u1 (formula-to-new-avar falsity-log)))
(mk-proof-in-intro-form
u1 var (make-proof-in-imp-elim-form
(proof-of-efq-log-at-aux kernel rename prename)
(make-proof-in-avar-form u1)))))
((allnc)
(let* ((var (allnc-form-to-var formula))
(kernel (allnc-form-to-kernel formula))
(u1 (formula-to-new-avar falsity-log)))
(mk-proof-in-nc-intro-form
u1 var (make-proof-in-imp-elim-form
(proof-of-efq-log-at-aux kernel rename prename)
(make-proof-in-avar-form u1)))))
(else (myerror "proof-of-efq-log-at-aux" "formula expected" formula))))
(define (formula-to-efq-proof formula) ;formula should be unfolded
(case (tag formula)
((atom predicate) #f)
((imp)
(let ((prem (imp-form-to-premise formula))
(concl (imp-form-to-conclusion formula)))
(if (classical-formula=? prem falsity)
(proof-of-efq-at concl)
(let ((prev (formula-to-efq-proof concl)))
(if prev
(make-proof-in-imp-intro-form
(formula-to-new-avar prem) prev)
#f)))))
((impnc)
(let ((prem (impnc-form-to-premise formula))
(concl (impnc-form-to-conclusion formula)))
(if (classical-formula=? prem falsity)
(proof-of-efq-at concl)
(let ((prev (formula-to-efq-proof concl)))
(if prev
(make-proof-in-impnc-intro-form
(formula-to-new-avar prem) prev)
#f)))))
((and)
(let* ((left (and-form-to-left formula))
(right (and-form-to-right formula))
(prev1 (formula-to-efq-proof left))
(prev2 (formula-to-efq-proof right)))
(if (and prev1 prev2)
(make-proof-in-and-intro-form prev1 prev2)
#f)))
((all)
(let* ((var (all-form-to-var formula))
(kernel (all-form-to-kernel formula))
(prev (formula-to-efq-proof kernel)))
(if prev
(make-proof-in-all-intro-form var prev)
#f)))
((allnc)
(let* ((var (allnc-form-to-var formula))
(kernel (allnc-form-to-kernel formula))
(prev (formula-to-efq-proof kernel)))
(if prev
(make-proof-in-allnc-intro-form var prev)
#f)))
((ex)
(let* ((var (ex-form-to-var formula))
(kernel (ex-form-to-kernel formula))
(prev (formula-to-efq-proof kernel)))
(if prev
(make-proof-in-ex-intro-form var prev)
#f)))
((exnc)
(let* ((var (exnc-form-to-var formula))
(kernel (exnc-form-to-kernel formula))
(prev (formula-to-efq-proof kernel)))
(if prev
(make-proof-in-exnc-intro-form var prev)
#f)))
((exca excl)
(myerror "formula-to-efq-proof" "unfolded formula exprected" formula))
(else (myerror "formula-to-efq-proof" "formula expected" formula))))
(define (reduce-efq-and-stab proof)
(case (tag proof)
((proof-in-avar-form) proof)
((proof-in-aconst-form)
(let* ((aconst (proof-in-aconst-form-to-aconst proof))
(name (aconst-to-name aconst)))
(cond ((string=? name "Stab")
(let* ((formula (unfold-formula (proof-to-formula proof)))
(vars-and-final-kernel
(allnc-form-to-vars-and-final-kernel formula))
(vars (car vars-and-final-kernel))
(kernel (cadr vars-and-final-kernel))
(concl (imp-form-to-conclusion kernel)))
(apply mk-proof-in-nc-intro-form
(append vars (list (proof-of-stab-at concl))))))
((string=? name "Efq")
(let* ((formula (unfold-formula (proof-to-formula proof)))
(vars-and-final-kernel
(allnc-form-to-vars-and-final-kernel formula))
(vars (car vars-and-final-kernel))
(kernel (cadr vars-and-final-kernel))
(concl (imp-form-to-conclusion kernel)))
(apply mk-proof-in-nc-intro-form
(append vars (list (proof-of-efq-at concl))))))
((string=? name "Stab-Log")
(let* ((formula (unfold-formula (proof-to-formula proof)))
(vars-and-final-kernel
(allnc-form-to-vars-and-final-kernel formula))
(vars (car vars-and-final-kernel))
(kernel (cadr vars-and-final-kernel))
(concl (imp-form-to-conclusion kernel)))
(apply mk-proof-in-nc-intro-form
(append vars (list (proof-of-stab-log-at concl))))))
((string=? name "Efq-Log")
(let* ((formula (unfold-formula (proof-to-formula proof)))
(vars-and-final-kernel
(allnc-form-to-vars-and-final-kernel formula))
(vars (car vars-and-final-kernel))
(kernel (cadr vars-and-final-kernel))
(concl (imp-form-to-conclusion kernel)))
(apply mk-proof-in-nc-intro-form
(append vars (list (proof-of-efq-log-at concl))))))
(else proof))))
((proof-in-imp-elim-form)
(let ((op (proof-in-imp-elim-form-to-op proof))
(arg (proof-in-imp-elim-form-to-arg proof)))
(make-proof-in-imp-elim-form
(reduce-efq-and-stab op)
(reduce-efq-and-stab arg))))
((proof-in-imp-intro-form)
(let ((avar (proof-in-imp-intro-form-to-avar proof))
(kernel (proof-in-imp-intro-form-to-kernel proof)))
(make-proof-in-imp-intro-form
avar (reduce-efq-and-stab kernel))))
((proof-in-impnc-elim-form)
(let ((op (proof-in-impnc-elim-form-to-op proof))
(arg (proof-in-impnc-elim-form-to-arg proof)))
(make-proof-in-impnc-elim-form
(reduce-efq-and-stab op)
(reduce-efq-and-stab arg))))
((proof-in-impnc-intro-form)
(let ((avar (proof-in-impnc-intro-form-to-avar proof))
(kernel (proof-in-impnc-intro-form-to-kernel proof)))
(make-proof-in-impnc-intro-form
avar (reduce-efq-and-stab kernel))))
((proof-in-and-intro-form)
(let ((left (proof-in-and-intro-form-to-left proof))
(right (proof-in-and-intro-form-to-right proof)))
(make-proof-in-and-intro-form
(reduce-efq-and-stab left)
(reduce-efq-and-stab right))))
((proof-in-and-elim-left-form)
(let ((kernel (proof-in-and-elim-left-form-to-kernel proof)))
(make-proof-in-and-elim-left-form ;inserted M.S.
(reduce-efq-and-stab kernel))))
((proof-in-and-elim-right-form)
(let ((kernel (proof-in-and-elim-right-form-to-kernel proof)))
(make-proof-in-and-elim-right-form ;inserted M.S.
(reduce-efq-and-stab kernel))))
((proof-in-all-intro-form)
(let ((var (proof-in-all-intro-form-to-var proof))
(kernel (proof-in-all-intro-form-to-kernel proof)))
(make-proof-in-all-intro-form
var (reduce-efq-and-stab kernel))))
((proof-in-all-elim-form)
(let ((op (proof-in-all-elim-form-to-op proof))
(arg (proof-in-all-elim-form-to-arg proof)))
(make-proof-in-all-elim-form (reduce-efq-and-stab op) arg)))
((proof-in-allnc-intro-form)
(let ((var (proof-in-allnc-intro-form-to-var proof))
(kernel (proof-in-allnc-intro-form-to-kernel proof)))
(make-proof-in-allnc-intro-form
var (reduce-efq-and-stab kernel))))
((proof-in-allnc-elim-form)
(let ((op (proof-in-allnc-elim-form-to-op proof))
(arg (proof-in-allnc-elim-form-to-arg proof)))
(make-proof-in-allnc-elim-form (reduce-efq-and-stab op) arg)))
(else (myerror "reduce-efq-and-stab" "proof tag expected"
(tag proof)))))
; We can transform a proof involving classical existential quantifiers
; in another one without, i.e., in minimal logic. The Exc-Intro and
; Exc-Elim theorems are replaced by their proofs, using expand-theorems.
(define (rm-exc proof)
(let ((name-test?
(lambda (string)
(or
(and (<= (string-length "ExcaIntro") (string-length string))
(string=? (substring string 0 (string-length "ExcaIntro"))
"ExcaIntro"))
(and (<= (string-length "ExclIntro") (string-length string))
(string=? (substring string 0 (string-length "ExclIntro"))
"ExclIntro"))
(and (<= (string-length "ExcaElim") (string-length string))
(string=? (substring string 0 (string-length "ExcaElim"))
"ExcaElim"))
(and (<= (string-length "ExclElim") (string-length string))
(string=? (substring string 0 (string-length "ExclElim"))
"ExclElim"))))))
(expand-theorems proof name-test?)))
; We now define the Goedel-Gentzen translation of formulas. We do not
; consider $\exc$, because it is not needed for our purposes of program
; extraction.
(define (formula-to-goedel-gentzen-translation formula)
(case (tag formula)
((atom predicate)
(if (formula=? falsity-log formula)
falsity-log
(mk-neg-log (mk-neg-log formula))))
((imp)
(let* ((prem (imp-form-to-premise formula))
(concl (imp-form-to-conclusion formula))
(prev1 (formula-to-goedel-gentzen-translation prem))
(prev2 (formula-to-goedel-gentzen-translation concl)))
(make-imp prev1 prev2)))
((impnc)
(let* ((prem (impnc-form-to-premise formula))
(concl (impnc-form-to-conclusion formula))
(prev1 (formula-to-goedel-gentzen-translation prem))
(prev2 (formula-to-goedel-gentzen-translation concl)))
(make-impnc prev1 prev2)))
((and)
(let* ((left (and-form-to-left formula))
(right (and-form-to-right formula))
(prev1 (formula-to-goedel-gentzen-translation left))
(prev2 (formula-to-goedel-gentzen-translation right)))
(make-and prev1 prev2)))
((all)
(let* ((var (all-form-to-var formula))
(kernel (all-form-to-kernel formula))
(prev (formula-to-goedel-gentzen-translation kernel)))
(make-all var prev)))
((allnc)
(let* ((var (allnc-form-to-var formula))
(kernel (allnc-form-to-kernel formula))
(prev (formula-to-goedel-gentzen-translation kernel)))
(make-allnc var prev)))
(else
(myerror "formula-to-goedel-gentzen-translation" "unexpected formula"
formula))))
; We introduce a further observation (due to Leivant; see Troelstra and
; van Dalen \cite[Ch.2, Sec.3]{TroelstravanDalen88}) which will be
; useful for program extraction from classical proofs. There it will be
; necessary to actually transform a given classical derivation $\vdash_c
; A$ into a minimal logic derivation $\vdash A^g$. In particular, for
; every assumption constant $C$ used in the given derivation we have to
; provide a derivation of $C^g$. Now for some formulas $S$ -- the
; so-called spreading formulas -- this is immediate, for we can derive
; $S \to S^g$, and hence can use the original assumption constant.
; In order to obtain a derivation of $C^g$ for $C$ an assumption
; constant it suffices to know that its uninstantiated formula $S$ is
; spreading, for then we generally have $\vdash S[\vec{A}^g] \to
; S[\vec{A}]^g$ and hence can use the same assumption constant with a
; different substitution.
; We define spreading, wiping and isolating formulas inductively.
(define (spreading-formula? formula)
(case (tag formula)
((atom predicate) #t)
((imp)
(let* ((prem (imp-form-to-premise formula))
(concl (imp-form-to-conclusion formula)))
(and (isolating-formula? prem)
(spreading-formula? concl))))
((impnc)
(let* ((prem (impnc-form-to-premise formula))
(concl (impnc-form-to-conclusion formula)))
(and (isolating-formula? prem)
(spreading-formula? concl))))
((and)
(let* ((left (and-form-to-left formula))
(right (and-form-to-right formula)))
(and (spreading-formula? left)
(spreading-formula? right))))
((all)
(let ((kernel (all-form-to-kernel formula)))
(spreading-formula? kernel)))
((allnc)
(let ((kernel (allnc-form-to-kernel formula)))
(spreading-formula? kernel)))
(else (myerror "spreading-formula?" "unexpected formula" formula))))
(define (wiping-formula? formula)
(case (tag formula)
((atom predicate)
(or (formula=? falsity-log formula)
(and (predicate-form? formula)
(pvar? (predicate-form-to-predicate formula)))))
((imp)
(let* ((prem (imp-form-to-premise formula))
(concl (imp-form-to-conclusion formula)))
(and (spreading-formula? prem)
(wiping-formula? concl))))
((impnc)
(let* ((prem (impnc-form-to-premise formula))
(concl (impnc-form-to-conclusion formula)))
(and (spreading-formula? prem)
(wiping-formula? concl))))
((and)
(let* ((left (and-form-to-left formula))
(right (and-form-to-right formula)))
(and (wiping-formula? left)
(wiping-formula? right))))
((all)
(let ((kernel (all-form-to-kernel formula)))
(wiping-formula? kernel)))
((allnc)
(let ((kernel (allnc-form-to-kernel formula)))
(wiping-formula? kernel)))
(else (myerror "wiping-formula?" "unexpected formula" formula))))
(define (isolating-formula? formula)
(or (prime-form? formula)
(wiping-formula? formula)
(and (and-form? formula)
(isolating-formula? (and-form-to-left formula))
(isolating-formula? (and-form-to-right formula)))))
; For a spreading formula S we can derive S[A^g] -> S[A]^g.
; opt-psubst consists of some X -> A; the other pvars in S are substituted
; automatically by their Goedel-Gentzen translations.
(define (spreading-formula-to-proof formula . opt-psubst)
(let* ((orig-psubst (if (null? opt-psubst) empty-subst (car opt-psubst)))
(orig-psubst-gg
(map (lambda (item)
(let* ((pvar (car item))
(cterm (cadr item))
(vars (cterm-to-vars cterm))
(formula (cterm-to-formula cterm))
(formula-gg
(formula-to-goedel-gentzen-translation formula)))
(list pvar (apply make-cterm
(append vars (list formula-gg))))))
orig-psubst))
(pvars (remove (predicate-form-to-predicate falsity-log)
(formula-to-pvars formula)))
(extra-pvars (set-minus pvars (map car orig-psubst)))
(extra-psubst-gg
(map (lambda (pvar)
(let* ((arity (pvar-to-arity pvar))
(types (arity-to-types arity))
(vars (map type-to-new-partial-var types))
(varterms (map make-term-in-var-form vars))
(formula (apply make-predicate-formula
(cons pvar varterms)))
(formula-gg (make-negation-log
(make-negation-log formula))))
(list pvar
(apply make-cterm
(append vars (list formula-gg))))))
extra-pvars))
(psubst-gg (append orig-psubst-gg extra-psubst-gg)))
(spreading-formula-to-proof-aux formula orig-psubst psubst-gg)))
; Now use psubst-gg (X -> A^g, Y -> ~~Y) for all (orig) formulas.
(define (spreading-formula-to-proof-aux formula psubst psubst-gg)
(case (tag formula)
((atom predicate)
(if (and (predicate-form? formula)
(pvar? (predicate-form-to-predicate formula)))
(let* ((subst-formula-gg (formula-substitute formula psubst-gg))
(u (formula-to-new-avar subst-formula-gg)))
(make-proof-in-imp-intro-form
u (make-proof-in-avar-form u)))
(let ((u (formula-to-new-avar formula))
(v (formula-to-new-avar (mk-neg-log formula))))
(mk-proof-in-intro-form
u v (make-proof-in-imp-elim-form
(make-proof-in-avar-form v)
(make-proof-in-avar-form u))))))
((imp)
(let* ((subst-formula (formula-substitute formula psubst)) ;I[A] ->S[A]
(gg-subst-formula ;I[A^g] ->S[A^g]
(formula-substitute formula psubst-gg))
(prem (imp-form-to-premise formula))
(subst-prem (imp-form-to-premise subst-formula))
(subst-prem-gg ;I[A]^g
(formula-to-goedel-gentzen-translation subst-prem))
(gg-subst-prem ;I[A^g]
(imp-form-to-premise gg-subst-formula))
(concl (imp-form-to-conclusion formula))
(subst-concl (imp-form-to-conclusion subst-formula))
(subst-concl-gg ;S[A]^g
(formula-to-goedel-gentzen-translation subst-concl))
(gg-subst-concl ;S[A^g]
(imp-form-to-conclusion gg-subst-formula))
(u (formula-to-new-avar gg-subst-formula))
(v (formula-to-new-avar subst-prem-gg))
(w1 (formula-to-new-avar (mk-neg-log subst-concl-gg)))
(w2 (formula-to-new-avar gg-subst-prem)))
(mk-proof-in-intro-form
u v (make-proof-in-imp-elim-form
(proof-of-stab-log-at subst-concl-gg)
(make-proof-in-imp-intro-form
w1 (mk-proof-in-elim-form
(isolating-formula-to-proof-aux prem psubst psubst-gg)
(make-proof-in-avar-form v)
(make-proof-in-imp-intro-form
w2 (make-proof-in-imp-elim-form
(make-proof-in-avar-form w1)
(make-proof-in-imp-elim-form
(spreading-formula-to-proof-aux
concl psubst psubst-gg)
(make-proof-in-imp-elim-form
(make-proof-in-avar-form u)
(make-proof-in-avar-form w2)))))))))))
((impnc)
(let* ((subst-formula (formula-substitute formula psubst)) ;I[A] ->S[A]
(gg-subst-formula ;I[A^g] ->S[A^g]
(formula-substitute formula psubst-gg))
(prem (impnc-form-to-premise formula))
(subst-prem (impnc-form-to-premise subst-formula))
(subst-prem-gg ;I[A]^g
(formula-to-goedel-gentzen-translation subst-prem))
(gg-subst-prem ;I[A^g]
(impnc-form-to-premise gg-subst-formula))
(concl (impnc-form-to-conclusion formula))
(subst-concl (impnc-form-to-conclusion subst-formula))
(subst-concl-gg ;S[A]^g
(formula-to-goedel-gentzen-translation subst-concl))
(gg-subst-concl ;S[A^g]
(impnc-form-to-conclusion gg-subst-formula))
(u (formula-to-new-avar gg-subst-formula))
(v (formula-to-new-avar subst-prem-gg))
(w1 (formula-to-new-avar (mk-neg-log subst-concl-gg)))
(w2 (formula-to-new-avar gg-subst-prem)))
(make-proof-in-imp-intro-form
u (make-proof-in-impnc-intro-form
v (make-proof-in-imp-elim-form
(proof-of-stab-log-at subst-concl-gg)
(make-proof-in-imp-intro-form
w1 (mk-proof-in-elim-form
(isolating-formula-to-proof-aux prem psubst psubst-gg)
(make-proof-in-avar-form v)
(make-proof-in-imp-intro-form
w2 (make-proof-in-imp-elim-form
(make-proof-in-avar-form w1)
(make-proof-in-imp-elim-form
(spreading-formula-to-proof-aux
concl psubst psubst-gg)
(make-proof-in-impnc-elim-form
(make-proof-in-avar-form u)
(make-proof-in-avar-form w2))))))))))))
((and)
(let* ((u (formula-to-new-avar formula))
(left (and-form-to-left formula))
(right (and-form-to-right formula)))
(mk-proof-in-intro-form
u (make-proof-in-and-intro-form
(make-proof-in-imp-elim-form
(spreading-formula-to-proof-aux left psubst psubst-gg)
(make-proof-in-and-elim-left-form
(make-proof-in-avar-form u)))
(make-proof-in-imp-elim-form
(spreading-formula-to-proof-aux right psubst psubst-gg)
(make-proof-in-and-elim-right-form
(make-proof-in-avar-form u)))))))
((all)
(let* ((gg-subst-formula ;(all x S)[A^g]
(formula-substitute formula psubst-gg))
(u (formula-to-new-avar gg-subst-formula))
(var (all-form-to-var formula))
(kernel (all-form-to-kernel formula)))
(make-proof-in-imp-intro-form
u (make-proof-in-all-intro-form
var (make-proof-in-imp-elim-form
(spreading-formula-to-proof-aux kernel psubst psubst-gg)
(make-proof-in-all-elim-form
(make-proof-in-avar-form u)
(make-term-in-var-form var)))))))
((allnc)
(let* ((gg-subst-formula ;(allnc x S)[A^g]
(formula-substitute formula psubst-gg))
(u (formula-to-new-avar gg-subst-formula))
(var (allnc-form-to-var formula))
(kernel (allnc-form-to-kernel formula)))
(make-proof-in-imp-intro-form
u (make-proof-in-allnc-intro-form
var (make-proof-in-imp-elim-form
(spreading-formula-to-proof-aux kernel psubst psubst-gg)
(make-proof-in-allnc-elim-form
(make-proof-in-avar-form u)
(make-term-in-var-form var)))))))
(else (myerror "spreading-formula-to-proof-aux" "unexpected formula"
formula))))
(define (wiping-formula-to-proof formula . opt-psubst)
(let* ((orig-psubst (if (null? opt-psubst) empty-subst (car opt-psubst)))
(orig-psubst-gg
(map (lambda (item)
(let* ((pvar (car item))
(cterm (cadr item))
(vars (cterm-to-vars cterm))
(formula (cterm-to-formula cterm))
(formula-gg
(formula-to-goedel-gentzen-translation formula)))
(list pvar (apply make-cterm
(append vars (list formula-gg))))))
orig-psubst))
(pvars (remove (predicate-form-to-predicate falsity-log)
(formula-to-pvars formula)))
(extra-pvars (set-minus pvars (map car orig-psubst)))
(extra-psubst-gg
(map (lambda (pvar)
(let* ((arity (pvar-to-arity pvar))
(types (arity-to-types arity))
(vars (map type-to-new-partial-var types))
(varterms (map make-term-in-var-form vars))
(formula (apply make-predicate-formula
(cons pvar varterms)))
(formula-gg (make-negation-log
(make-negation-log formula))))
(list pvar
(apply make-cterm
(append vars (list formula-gg))))))
extra-pvars))
(psubst-gg (append orig-psubst-gg extra-psubst-gg)))
(wiping-formula-to-proof-aux formula orig-psubst psubst-gg)))
(define (wiping-formula-to-proof-aux formula psubst psubst-gg)
(case (tag formula)
((atom predicate)
(if (and (predicate-form? formula)
(pvar? (predicate-form-to-predicate formula)))
(let* ((gg-subst-formula (formula-substitute formula psubst-gg))
(u (formula-to-new-avar gg-subst-formula)))
(make-proof-in-imp-intro-form
u (make-proof-in-avar-form u)))
(myerror "wiping-formula-to-proof-aux" "pvar or falsity-log expected"
formula)))
((imp)
(let* ((subst-formula ;S[A] -> W[A]
(formula-substitute formula psubst))
(prem (imp-form-to-premise formula))
(subst-prem (imp-form-to-premise subst-formula))
(subst-prem-gg ;S[A]^g
(formula-to-goedel-gentzen-translation subst-prem))
(gg-subst-prem ;S[A^g]
(formula-substitute prem psubst-gg))
(concl (imp-form-to-conclusion formula))
(subst-concl (imp-form-to-conclusion subst-formula))
(subst-concl-gg ;W[A]^g
(formula-to-goedel-gentzen-translation subst-concl))
(u (formula-to-new-avar (make-imp subst-prem-gg subst-concl-gg)))
(v (formula-to-new-avar gg-subst-prem)))
(mk-proof-in-intro-form
u v (make-proof-in-imp-elim-form
(wiping-formula-to-proof-aux concl psubst psubst-gg)
(make-proof-in-imp-elim-form
(make-proof-in-avar-form u)
(make-proof-in-imp-elim-form
(spreading-formula-to-proof-aux prem psubst psubst-gg)
(make-proof-in-avar-form v)))))))
((impnc)
(let* ((subst-formula ;S[A] -> W[A]
(formula-substitute formula psubst))
(prem (impnc-form-to-premise formula))
(subst-prem (impnc-form-to-premise subst-formula))
(subst-prem-gg ;S[A]^g
(formula-to-goedel-gentzen-translation subst-prem))
(gg-subst-prem ;S[A^g]
(formula-substitute prem psubst-gg))
(concl (impnc-form-to-conclusion formula))
(subst-concl (impnc-form-to-conclusion subst-formula))
(subst-concl-gg ;W[A]^g
(formula-to-goedel-gentzen-translation subst-concl))
(u (formula-to-new-avar (make-impnc subst-prem-gg subst-concl-gg)))
(v (formula-to-new-avar gg-subst-prem)))
(make-proof-in-imp-intro-form
u (make-proof-in-impnc-intro-form
v (make-proof-in-imp-elim-form
(wiping-formula-to-proof-aux concl psubst psubst-gg)
(make-proof-in-impnc-elim-form
(make-proof-in-avar-form u)
(make-proof-in-imp-elim-form
(spreading-formula-to-proof-aux prem psubst psubst-gg)
(make-proof-in-avar-form v))))))))
((and)
(let* ((gg-subst-formula ;(W1 & W2)^g
(formula-substitute formula psubst-gg))
(u (formula-to-new-avar gg-subst-formula))
(left (and-form-to-left formula))
(right (and-form-to-right formula)))
(mk-proof-in-intro-form
u (make-proof-in-and-intro-form
(make-proof-in-imp-elim-form
(wiping-formula-to-proof-aux left psubst psubst-gg)
(make-proof-in-and-elim-left-form
(make-proof-in-avar-form u)))
(make-proof-in-imp-elim-form
(wiping-formula-to-proof-aux right psubst psubst-gg)
(make-proof-in-and-elim-right-form
(make-proof-in-avar-form u)))))))
((all)
(let* ((var (all-form-to-var formula))
(kernel (all-form-to-kernel formula))
(subst-kernel (formula-substitute kernel psubst))
(subst-kernel-gg ;W[A]^g
(formula-to-goedel-gentzen-translation subst-kernel))
(u (formula-to-new-avar (make-all var subst-kernel-gg))))
(make-proof-in-imp-intro-form
u (make-proof-in-all-intro-form
var (make-proof-in-imp-elim-form
(wiping-formula-to-proof-aux kernel psubst psubst-gg)
(make-proof-in-all-elim-form
(make-proof-in-avar-form u)
(make-term-in-var-form var)))))))
((allnc)
(let* ((var (allnc-form-to-var formula))
(kernel (allnc-form-to-kernel formula))
(subst-kernel (formula-substitute kernel psubst))
(subst-kernel-gg ;W[A]^g
(formula-to-goedel-gentzen-translation subst-kernel))
(u (formula-to-new-avar (make-allnc var subst-kernel-gg))))
(make-proof-in-imp-intro-form
u (make-proof-in-allnc-intro-form
var (make-proof-in-imp-elim-form
(wiping-formula-to-proof-aux kernel psubst psubst-gg)
(make-proof-in-allnc-elim-form
(make-proof-in-avar-form u)
(make-term-in-var-form var)))))))
(else (myerror "wiping-formula-to-proof-aux" "unexpected formula"
formula))))
(define (isolating-formula-to-proof formula . opt-psubst)
(let* ((orig-psubst (if (null? opt-psubst) empty-subst (car opt-psubst)))
(orig-psubst-gg
(map (lambda (item)
(let* ((pvar (car item))
(cterm (cadr item))
(vars (cterm-to-vars cterm))
(formula (cterm-to-formula cterm))
(formula-gg
(formula-to-goedel-gentzen-translation formula)))
(list pvar (apply make-cterm
(append vars (list formula-gg))))))
orig-psubst))
(pvars (remove (predicate-form-to-predicate falsity-log)
(formula-to-pvars formula)))
(extra-pvars (set-minus pvars (map car orig-psubst)))
(extra-psubst-gg
(map (lambda (pvar)
(let* ((arity (pvar-to-arity pvar))
(types (arity-to-types arity))
(vars (map type-to-new-partial-var types))
(varterms (map make-term-in-var-form vars))
(formula (apply make-predicate-formula
(cons pvar varterms)))
(formula-gg (make-negation-log
(make-negation-log formula))))
(list pvar
(apply make-cterm
(append vars (list formula-gg))))))
extra-pvars))
(psubst-gg (append orig-psubst-gg extra-psubst-gg)))
(isolating-formula-to-proof-aux formula orig-psubst psubst-gg)))
(define (isolating-formula-to-proof-aux formula psubst psubst-gg)
(cond
((wiping-formula? formula)
(let* ((subst-formula (formula-substitute formula psubst))
(subst-formula-gg ;W[A]^g
(formula-to-goedel-gentzen-translation subst-formula))
(gg-subst-formula ;W[A^g]
(formula-substitute formula psubst-gg))
(u (formula-to-new-avar subst-formula-gg))
(v (formula-to-new-avar (mk-neg-log gg-subst-formula))))
(mk-proof-in-intro-form
u v (make-proof-in-imp-elim-form
(make-proof-in-avar-form v)
(make-proof-in-imp-elim-form
(wiping-formula-to-proof-aux formula psubst psubst-gg)
(make-proof-in-avar-form u))))))
((prime-form? formula)
(let ((u (formula-to-new-avar (mk-neg-log (mk-neg-log formula)))))
(make-proof-in-imp-intro-form
u (make-proof-in-avar-form u))))
((and-form? formula)
(let* ((subst-formula (formula-substitute formula psubst))
(subst-formula-gg ;(I1 & I2)[A]^g
(formula-to-goedel-gentzen-translation subst-formula))
(u (formula-to-new-avar subst-formula-gg))
(left (and-form-to-left formula))
(right (and-form-to-right formula))
(v (formula-to-new-avar (make-negation-log formula)))
(w1 (formula-to-new-avar left))
(w2 (formula-to-new-avar right)))
(mk-proof-in-intro-form
u v (mk-proof-in-elim-form
(isolating-formula-to-proof-aux right psubst psubst-gg)
(make-proof-in-and-elim-right-form
(make-proof-in-avar-form u))
(make-proof-in-imp-intro-form
w2 (mk-proof-in-elim-form
(isolating-formula-to-proof-aux left psubst psubst-gg)
(make-proof-in-and-elim-left-form
(make-proof-in-avar-form u))
(make-proof-in-imp-intro-form
w1 (make-proof-in-imp-elim-form
(make-proof-in-avar-form v)
(make-proof-in-and-intro-form
(make-proof-in-avar-form w1)
(make-proof-in-avar-form w2))))))))))
(else (myerror "isolating-formula-to-proof-aux" "unexpected formula"
formula))))
; Now we can define the Goedel-Gentzen translation.
(define (proof-to-goedel-gentzen-translation proof)
(let ((avar-to-goedel-gentzen-avar
(let ((assoc-list '()))
(lambda (avar)
(let ((info (assoc-wrt avar=? avar assoc-list)))
(if info
(cadr info)
(let ((new-avar (formula-to-new-avar
(formula-to-goedel-gentzen-translation
(avar-to-formula avar)))))
(set! assoc-list (cons (list avar new-avar) assoc-list))
new-avar)))))))
(proof-to-goedel-gentzen-translation-aux
proof avar-to-goedel-gentzen-avar)))
(define (proof-to-goedel-gentzen-translation-aux proof
avar-to-goedel-gentzen-avar)
(case (tag proof)
((proof-in-avar-form)
(let ((avar (proof-in-avar-form-to-avar proof)))
(make-proof-in-avar-form
(avar-to-goedel-gentzen-avar avar))))
((proof-in-aconst-form)
(let* ((aconst (proof-in-aconst-form-to-aconst proof))
(name (aconst-to-name aconst))
(kind (aconst-to-kind aconst))
(uninst-formula (aconst-to-uninst-formula aconst))
(tpinst (aconst-to-tpinst aconst))
(repro-formulas (aconst-to-repro-formulas aconst))
(tsubst (list-transform-positive tpinst
(lambda (x) (tvar-form? (car x)))))
(pinst (list-transform-positive tpinst
(lambda (x) (pvar-form? (car x)))))
(rename (make-rename tsubst))
(prename (make-prename tsubst))
(typeinst-formula
(formula-substitute-aux
uninst-formula tsubst empty-subst empty-subst rename prename))
(psubst (map (lambda (x) (list (prename (car x)) (cadr x)))
pinst))
(inst-formula (formula-substitute typeinst-formula psubst))
(free (formula-to-free inst-formula)))
(cond
((spreading-formula? inst-formula)
(apply
mk-proof-in-nc-intro-form
(append
free
(list (make-proof-in-imp-elim-form
(spreading-formula-to-proof inst-formula)
(apply mk-proof-in-elim-form
(cons proof (map make-term-in-var-form free))))))))
((spreading-formula? uninst-formula)
(let* ((pvars (remove (predicate-form-to-predicate falsity-log)
(formula-to-pvars uninst-formula)))
(extra-pvars (set-minus pvars (map car pinst)))
(extra-psubst-gg
(map (lambda (pvar)
(let* ((arity (pvar-to-arity pvar))
(types (arity-to-types arity))
(vars (map type-to-new-partial-var types))
(varterms (map make-term-in-var-form vars))
(formula (apply make-predicate-formula
(cons pvar varterms)))
(formula-gg (make-negation-log
(make-negation-log formula))))
(list pvar
(apply make-cterm
(append vars (list formula-gg))))))
extra-pvars))
(original-pinst-gg
(map (lambda (item)
(let* ((pvar (car item))
(cterm (cadr item))
(vars (cterm-to-vars cterm))
(formula (cterm-to-formula cterm))
(formula-gg
(formula-to-goedel-gentzen-translation
formula)))
(list pvar (apply make-cterm
(append vars (list formula-gg))))))
pinst))
(tpinst-gg (append tsubst original-pinst-gg extra-psubst-gg))
(subst-aconst
(apply make-aconst
(append (list name kind uninst-formula tpinst-gg)
repro-formulas))))
(apply
mk-proof-in-nc-intro-form
(append
free
(list (make-proof-in-imp-elim-form
(spreading-formula-to-proof typeinst-formula psubst)
(apply mk-proof-in-elim-form
(cons (make-proof-in-aconst-form subst-aconst)
(map make-term-in-var-form free)))))))))
((eq? 'theorem kind)
(proof-to-goedel-gentzen-translation-aux
(theorem-name-to-proof name) avar-to-goedel-gentzen-avar))
(else (myerror "proof-to-goedel-gentzen-translation-aux"
"unexpected aconst of kind" kind "with formula"
formula)))))
((proof-in-imp-intro-form)
(let* ((avar (proof-in-imp-intro-form-to-avar proof))
(u (avar-to-goedel-gentzen-avar avar))
(kernel (proof-in-imp-intro-form-to-kernel proof)))
(make-proof-in-imp-intro-form
u (proof-to-goedel-gentzen-translation-aux
kernel avar-to-goedel-gentzen-avar))))
((proof-in-imp-elim-form)
(let* ((op (proof-in-imp-elim-form-to-op proof))
(arg (proof-in-imp-elim-form-to-arg proof))
(prev-op (proof-to-goedel-gentzen-translation-aux
op avar-to-goedel-gentzen-avar))
(prev-arg (proof-to-goedel-gentzen-translation-aux
arg avar-to-goedel-gentzen-avar)))
(make-proof-in-imp-elim-form prev-op prev-arg)))
((proof-in-impnc-intro-form)
(let* ((avar (proof-in-impnc-intro-form-to-avar proof))
(u (avar-to-goedel-gentzen-avar avar))
(kernel (proof-in-impnc-intro-form-to-kernel proof)))
(make-proof-in-impnc-intro-form
u (proof-to-goedel-gentzen-translation-aux
kernel avar-to-goedel-gentzen-avar))))
((proof-in-impnc-elim-form)
(let* ((op (proof-in-impnc-elim-form-to-op proof))
(arg (proof-in-impnc-elim-form-to-arg proof))
(prev-op (proof-to-goedel-gentzen-translation-aux
op avar-to-goedel-gentzen-avar))
(prev-arg (proof-to-goedel-gentzen-translation-aux
arg avar-to-goedel-gentzen-avar)))
(make-proof-in-impnc-elim-form prev-op prev-arg)))
((proof-in-and-intro-form)
(make-proof-in-and-intro-form
(proof-to-goedel-gentzen-translation-aux
(proof-in-and-intro-form-to-left proof)
avar-to-goedel-gentzen-avar)
(proof-to-goedel-gentzen-translation-aux
(proof-in-and-intro-form-to-right proof)
avar-to-goedel-gentzen-avar)))
((proof-in-and-elim-left-form)
(make-proof-in-and-elim-left-form
(proof-to-goedel-gentzen-translation-aux
(proof-in-and-elim-left-form-to-kernel proof)
avar-to-goedel-gentzen-avar)))
((proof-in-and-elim-right-form)
(make-proof-in-and-elim-right-form
(proof-to-goedel-gentzen-translation-aux
(proof-in-and-elim-right-form-to-kernel proof)
avar-to-goedel-gentzen-avar)))
((proof-in-all-intro-form)
(let* ((var (proof-in-all-intro-form-to-var proof))
(kernel (proof-in-all-intro-form-to-kernel proof)))
(make-proof-in-all-intro-form
var (proof-to-goedel-gentzen-translation-aux
kernel avar-to-goedel-gentzen-avar))))
((proof-in-all-elim-form)
(let ((op (proof-in-all-elim-form-to-op proof))
(arg (proof-in-all-elim-form-to-arg proof)))
(make-proof-in-all-elim-form
(proof-to-goedel-gentzen-translation-aux
op avar-to-goedel-gentzen-avar)
arg)))
((proof-in-allnc-intro-form)
(let* ((var (proof-in-allnc-intro-form-to-var proof))
(kernel (proof-in-allnc-intro-form-to-kernel proof)))
(make-proof-in-allnc-intro-form
var (proof-to-goedel-gentzen-translation-aux
kernel avar-to-goedel-gentzen-avar))))
((proof-in-allnc-elim-form)
(let ((op (proof-in-allnc-elim-form-to-op proof))
(arg (proof-in-allnc-elim-form-to-arg proof)))
(make-proof-in-allnc-elim-form
(proof-to-goedel-gentzen-translation-aux
op avar-to-goedel-gentzen-avar)
arg)))
(else (myerror "proof-to-goedel-gentzen-translation-aux"
"proof tag expected" (tag proof)))))
; Notice that the Goedel-Gentzen double negates every atom, and hence
; may produce triple negations. However, we can systematically replace
; triple negations by single negations.
; For a formula A let A* be the formula obtaind by replacing triple
; negations whenever possible by single negations.
(define (formula-to-formula-without-triple-negations-log formula)
(if ;formula is triple negation
(and (imp-form? formula)
(formula=? falsity-log (imp-form-to-conclusion formula))
(imp-form? (imp-form-to-premise formula))
(formula=? falsity-log (imp-form-to-conclusion
(imp-form-to-premise formula)))
(imp-form? (imp-form-to-premise (imp-form-to-premise formula)))
(formula=? falsity-log (imp-form-to-conclusion
(imp-form-to-premise
(imp-form-to-premise formula)))))
(formula-to-formula-without-triple-negations-log
(imp-form-to-premise (imp-form-to-premise formula)))
(case (tag formula)
((atom predicate) formula)
((imp)
(let* ((prem (imp-form-to-premise formula))
(concl (imp-form-to-conclusion formula))
(prev1 (formula-to-formula-without-triple-negations-log prem))
(prev2 (formula-to-formula-without-triple-negations-log concl)))
(make-imp prev1 prev2)))
((impnc)
(let* ((prem (impnc-form-to-premise formula))
(concl (impnc-form-to-conclusion formula))
(prev1 (formula-to-formula-without-triple-negations-log prem))
(prev2 (formula-to-formula-without-triple-negations-log concl)))
(make-impnc prev1 prev2)))
((and)
(let* ((left (and-form-to-left formula))
(right (and-form-to-right formula))
(prev1 (formula-to-formula-without-triple-negations-log left))
(prev2 (formula-to-formula-without-triple-negations-log right)))
(make-and prev1 prev2)))
((all)
(let* ((var (all-form-to-var formula))
(kernel (all-form-to-kernel formula))
(prev (formula-to-formula-without-triple-negations-log kernel)))
(make-all var prev)))
((allnc)
(let* ((var (allnc-form-to-var formula))
(kernel (allnc-form-to-kernel formula))
(prev (formula-to-formula-without-triple-negations-log kernel)))
(make-allnc var prev)))
(else
(myerror
"formula-to-formula-without-triple-negations-log" "unexpected formula"
formula)))))
; We simultaneously construct derivations of (1) A -> A* and (2) A* -> A
(define (formula-to-rm-triple-negations-log-proof1 formula)
(let ((reduced-formula
(formula-to-formula-without-triple-negations-log formula)))
(case (tag formula)
((atom predicate)
(let ((u (formula-to-new-avar formula)))
(make-proof-in-imp-intro-form
u (make-proof-in-avar-form u))))
((imp)
(let ((prem (imp-form-to-premise formula))
(concl (imp-form-to-conclusion formula))
(u (formula-to-new-avar formula)))
(if ;formula is a triple negation
(and (formula=? falsity-log concl)
(imp-form? prem)
(formula=? falsity-log (imp-form-to-conclusion prem))
(imp-form? (imp-form-to-premise prem))
(formula=? falsity-log (imp-form-to-conclusion
(imp-form-to-premise prem))))
(let ((v (formula-to-new-avar (imp-form-to-premise prem)))
(w (formula-to-new-avar (imp-form-to-premise
(imp-form-to-premise prem)))))
(make-proof-in-imp-intro-form
u (make-proof-in-imp-elim-form
(formula-to-rm-triple-negations-log-proof1
(imp-form-to-premise prem))
(make-proof-in-imp-intro-form
w (make-proof-in-imp-elim-form
(make-proof-in-avar-form u)
(make-proof-in-imp-intro-form
v (make-proof-in-imp-elim-form
(make-proof-in-avar-form v)
(make-proof-in-avar-form w))))))))
(let ((v (formula-to-new-avar
(formula-to-formula-without-triple-negations-log prem))))
(mk-proof-in-intro-form
u v (make-proof-in-imp-elim-form
(formula-to-rm-triple-negations-log-proof1 concl)
(make-proof-in-imp-elim-form
(make-proof-in-avar-form u)
(make-proof-in-imp-elim-form
(formula-to-rm-triple-negations-log-proof2 prem)
(make-proof-in-avar-form v)))))))))
((impnc)
(let ((prem (impnc-form-to-premise formula))
(concl (impnc-form-to-conclusion formula))
(u (formula-to-new-avar formula)))
(if ;formula is a triple negation
(and (formula=? falsity-log concl)
(imp-form? prem)
(formula=? falsity-log (imp-form-to-conclusion prem))
(imp-form? (imp-form-to-premise prem))
(formula=? falsity-log (imp-form-to-conclusion
(imp-form-to-premise prem))))
(let ((v (formula-to-new-avar (imp-form-to-premise prem)))
(w (formula-to-new-avar (imp-form-to-premise
(imp-form-to-premise prem)))))
(make-proof-in-imp-intro-form
u (make-proof-in-imp-elim-form
(formula-to-rm-triple-negations-log-proof1
(imp-form-to-premise prem))
(make-proof-in-imp-intro-form
w (make-proof-in-imp-elim-form
(make-proof-in-avar-form u)
(make-proof-in-imp-intro-form
v (make-proof-in-imp-elim-form
(make-proof-in-avar-form v)
(make-proof-in-avar-form w))))))))
(let ((v (formula-to-new-avar
(formula-to-formula-without-triple-negations-log prem))))
(make-proof-in-imp-intro-form
u (make-proof-in-impnc-intro-form
v (make-proof-in-imp-elim-form
(formula-to-rm-triple-negations-log-proof1 concl)
(make-proof-in-impnc-elim-form
(make-proof-in-avar-form u)
(make-proof-in-imp-elim-form
(formula-to-rm-triple-negations-log-proof2 prem)
(make-proof-in-avar-form v))))))))))
((all)
(let ((var (all-form-to-var formula))
(kernel (all-form-to-kernel formula))
(u (formula-to-new-avar formula)))
(make-proof-in-imp-intro-form
u (make-proof-in-all-intro-form
var (make-proof-in-imp-elim-form
(formula-to-rm-triple-negations-log-proof1 kernel)
(make-proof-in-all-elim-form
(make-proof-in-avar-form u)
(make-term-in-var-form var)))))))
((allnc)
(let ((var (allnc-form-to-var formula))
(kernel (allnc-form-to-kernel formula))
(u (formula-to-new-avar formula)))
(make-proof-in-imp-intro-form
u (make-proof-in-allnc-intro-form
var (make-proof-in-imp-elim-form
(formula-to-rm-triple-negations-log-proof1 kernel)
(make-proof-in-allnc-elim-form
(make-proof-in-avar-form u)
(make-term-in-var-form var)))))))
(else (myerror
"formula-to-rm-triple-negations-log-proof1" "unexpected formula"
formula)))))
(define (formula-to-rm-triple-negations-log-proof2 formula)
(let ((reduced-formula
(formula-to-formula-without-triple-negations-log formula)))
(case (tag formula)
((atom predicate)
(let ((u (formula-to-new-avar formula)))
(make-proof-in-imp-intro-form
u (make-proof-in-avar-form u))))
((imp)
(let ((prem (imp-form-to-premise formula))
(concl (imp-form-to-conclusion formula))
(u (formula-to-new-avar reduced-formula)))
(if ;formula is a triple negation
(and (formula=? falsity-log concl)
(imp-form? prem)
(formula=? falsity-log (imp-form-to-conclusion prem))
(imp-form? (imp-form-to-premise prem))
(formula=? falsity-log (imp-form-to-conclusion
(imp-form-to-premise prem))))
(let ((v (formula-to-new-avar prem)))
(mk-proof-in-intro-form
u v (make-proof-in-imp-elim-form
(make-proof-in-avar-form v)
(make-proof-in-imp-elim-form
(formula-to-rm-triple-negations-log-proof2
(imp-form-to-premise prem))
(make-proof-in-avar-form u)))))
(let ((v (formula-to-new-avar prem)))
(mk-proof-in-intro-form
u v (make-proof-in-imp-elim-form
(formula-to-rm-triple-negations-log-proof2 concl)
(make-proof-in-imp-elim-form
(make-proof-in-avar-form u)
(make-proof-in-imp-elim-form
(formula-to-rm-triple-negations-log-proof1 prem)
(make-proof-in-avar-form v)))))))))
((impnc)
(let ((prem (impnc-form-to-premise formula))
(concl (impnc-form-to-conclusion formula))
(u (formula-to-new-avar reduced-formula)))
(if ;formula is a triple negation
(and (formula=? falsity-log concl)
(imp-form? prem)
(formula=? falsity-log (imp-form-to-conclusion prem))
(imp-form? (imp-form-to-premise prem))
(formula=? falsity-log (imp-form-to-conclusion
(imp-form-to-premise prem))))
(let ((v (formula-to-new-avar prem)))
(mk-proof-in-intro-form
u v (make-proof-in-imp-elim-form
(make-proof-in-avar-form v)
(make-proof-in-imp-elim-form
(formula-to-rm-triple-negations-log-proof2
(imp-form-to-premise prem))
(make-proof-in-avar-form u)))))
(let ((v (formula-to-new-avar prem)))
(make-proof-in-imp-intro-form
u (make-proof-in-impnc-intro-form
v (make-proof-in-imp-elim-form
(formula-to-rm-triple-negations-log-proof2 concl)
(make-proof-in-impnc-elim-form
(make-proof-in-avar-form u)
(make-proof-in-imp-elim-form
(formula-to-rm-triple-negations-log-proof1 prem)
(make-proof-in-avar-form v))))))))))
((all)
(let ((var (all-form-to-var formula))
(kernel (all-form-to-kernel formula))
(u (formula-to-new-avar
(formula-to-formula-without-triple-negations-log formula))))
(make-proof-in-imp-intro-form
u (make-proof-in-all-intro-form
var (make-proof-in-imp-elim-form
(formula-to-rm-triple-negations-log-proof2 kernel)
(make-proof-in-all-elim-form
(make-proof-in-avar-form u)
(make-term-in-var-form var)))))))
((allnc)
(let ((var (allnc-form-to-var formula))
(kernel (allnc-form-to-kernel formula))
(u (formula-to-new-avar
(formula-to-formula-without-triple-negations-log formula))))
(make-proof-in-imp-intro-form
u (make-proof-in-allnc-intro-form
var (make-proof-in-imp-elim-form
(formula-to-rm-triple-negations-log-proof2 kernel)
(make-proof-in-allnc-elim-form
(make-proof-in-avar-form u)
(make-term-in-var-form var)))))))
(else (myerror
"formula-to-rm-triple-negations-log-proof2" "unexpected formula"
formula)))))
; Now we can refine the Goedel-Gentzen translation accordingly.
(define (proof-to-reduced-goedel-gentzen-translation proof)
(let* ((avar-to-goedel-gentzen-avar
(let ((assoc-list '()))
(lambda (avar)
(let ((info (assoc-wrt avar=? avar assoc-list)))
(if info
(cadr info)
(let ((new-avar (formula-to-new-avar
(formula-to-goedel-gentzen-translation
(avar-to-formula avar)))))
(set! assoc-list (cons (list avar new-avar) assoc-list))
new-avar))))))
(proof-gg (proof-to-goedel-gentzen-translation-aux
proof avar-to-goedel-gentzen-avar))
(formula-gg (proof-to-formula proof-gg))
(proof1 ;of formula-gg -> formula-gg*
(formula-to-rm-triple-negations-log-proof1 formula-gg)))
(make-proof-in-imp-elim-form proof1 proof-gg)))
; 10-7. Existence formulas
; ========================
; In case of ex-formulas ex xs1 A1 ... ex xsn An and conclusion B we
; recursively construct a proof of
; ex xs1 A1 -> ... -> ex xsn An -> (all xs1,...,xsn.A1 -> ... -> An -> B) -> B.
; Notice that the free variables zs are not generalized here. We assume
; that B does not contain any variable from xs1 ... xsn free. This is
; checked and - if it does not hold - enforced in a preprocessing step.
(define (ex-formulas-and-concl-to-ex-elim-proof x . rest)
(let* ((ex-formulas (list-head (cons x rest) (length rest)))
(concl (car (last-pair (cons x rest))))
(zs (apply union (map formula-to-free (cons x rest))))
(vars-and-kernel-list
(map ex-form-to-vars-and-final-kernel ex-formulas))
(varss (map car vars-and-kernel-list))
(kernels (map cadr vars-and-kernel-list))
(test (and (pair? ex-formulas)
(or (pair? (apply intersection varss))
(pair? (intersection (apply append varss)
(formula-to-free concl))))))
(new-varss
(if test
(map (lambda (vars) (map var-to-new-var vars)) varss)
varss))
(new-kernels
(if test
(do ((l1 varss (cdr l1))
(l2 kernels (cdr l2))
(l3 new-varss (cdr l3))
(res '() (let* ((vars (car l1))
(kernel (car l2))
(new-vars (car l3))
(subst (map (lambda (x y) (list x y))
vars
(map make-term-in-var-form
new-vars))))
(cons (formula-substitute kernel subst) res))))
((null? l1) (reverse res)))
kernels)))
(ex-formulas-and-concl-to-ex-elim-proof-aux
new-varss new-kernels ex-formulas concl)))
(define (ex-formulas-and-concl-to-ex-elim-proof-aux varss kernels
ex-formulas concl)
(if
(null? kernels)
(let ((u (formula-to-new-avar concl)))
(make-proof-in-imp-intro-form u (make-proof-in-avar-form u)))
(let ((vars (car varss))
(kernel (car kernels)))
(if
(null? vars)
(let* ((prev (ex-formulas-and-concl-to-ex-elim-proof-aux
(cdr varss) (cdr kernels) (cdr ex-formulas) concl))
(u1 (formula-to-new-avar kernel))
(us (map formula-to-new-avar (cdr ex-formulas)))
(flattened-varss (apply append (cdr varss)))
(v (formula-to-new-avar
(apply
mk-all
(append
flattened-varss
(list (apply mk-imp (append kernels (list concl)))))))))
(apply
mk-proof-in-intro-form
(cons
u1 (append
us (cons
v (list
(apply
mk-proof-in-elim-form
(cons
prev (append
(map make-proof-in-avar-form us)
(list
(apply
mk-proof-in-intro-form
(append
flattened-varss
(list
(apply
mk-proof-in-elim-form
(cons
(make-proof-in-avar-form v)
(append
(map make-term-in-var-form
flattened-varss)
(list (make-proof-in-avar-form
u1))))))))))))))))))
(let* ((prev (ex-formulas-and-concl-to-ex-elim-proof-aux
(cons (cdr vars) (cdr varss)) kernels
(cons (ex-form-to-kernel (car ex-formulas))
(cdr ex-formulas)) concl))
(ex-formula (apply mk-ex (append vars (list kernel))))
(zs (union (formula-to-free ex-formula) (formula-to-free concl)))
(aconst-proof
(apply
mk-proof-in-elim-form
(cons
(make-proof-in-aconst-form
(ex-formula-and-concl-to-ex-elim-aconst ex-formula concl))
(map make-term-in-var-form zs))))
(var (car vars))
(u1 (formula-to-new-avar ex-formula))
(us (map formula-to-new-avar (cdr ex-formulas)))
(flattened-varss (apply append varss))
(v (formula-to-new-avar
(apply
mk-all
(append
flattened-varss
(list (apply mk-imp (append kernels (list concl))))))))
(w (formula-to-new-avar
(apply mk-ex (append (cdr vars) (list kernel))))))
(apply
mk-proof-in-intro-form
(cons
u1 (append
us (cons
v (list
(mk-proof-in-elim-form
aconst-proof
(make-proof-in-avar-form u1)
(mk-proof-in-intro-form
var w
(apply
mk-proof-in-elim-form
(cons
prev
(cons
(make-proof-in-avar-form w)
(append
(map make-proof-in-avar-form us)
(list
(make-proof-in-all-elim-form
(make-proof-in-avar-form v)
(make-term-in-var-form var)))))))))))))))))))
; Call a formula E essentially existential, if it can be transformed
; into an existential form. Inductive definition:
; E ::= ex x A | A & E | E & A | decidable -> E (postponed)
; We want to replace an implication with an essentially existential
; premise by a formula with one existential quantifier less.
; Application: search. Given a formula A, reduce it to A* by
; eliminating as many existential quantifiers as possible. Then search
; for a proof of A*. Since a proof of A* -> A can be constructed easily,
; one obtains a proof of A.
(define (formula-to-ex-red-formula formula) ;constructs A* from A
(case (tag formula)
((predicate atom) formula)
((imp)
(let* ((prem (imp-form-to-premise formula))
(concl (imp-form-to-conclusion formula))
(prev-prem (formula-to-ex-red-formula prem))
(prev-concl (formula-to-ex-red-formula concl)))
(if
(ex-form? prev-prem)
(let* ((vars-and-kernel (ex-form-to-vars-and-final-kernel prev-prem))
(vars (car vars-and-kernel))
(kernel (cadr vars-and-kernel)))
(if
(null? (intersection vars (formula-to-free prev-concl)))
(apply mk-all (append vars (list (make-imp kernel prev-concl))))
(let* ((new-vars (map var-to-new-var vars))
(new-varterms (map make-term-in-var-form new-vars))
(subst (map (lambda (x y) (list x y))
vars new-varterms))
(new-kernel (formula-substitute kernel subst)))
(apply mk-all (append new-vars
(list (make-imp new-kernel prev-concl)))))))
(make-imp prev-prem prev-concl))))
((impnc)
(let* ((prem (impnc-form-to-premise formula))
(concl (impnc-form-to-conclusion formula))
(prev-prem (formula-to-ex-red-formula prem))
(prev-concl (formula-to-ex-red-formula concl)))
(if
(ex-form? prev-prem)
(let* ((vars-and-kernel (ex-form-to-vars-and-final-kernel prev-prem))
(vars (car vars-and-kernel))
(kernel (cadr vars-and-kernel)))
(if
(null? (intersection vars (formula-to-free prev-concl)))
(apply mk-all (append vars (list (make-imp kernel prev-concl))))
(let* ((new-vars (map var-to-new-var vars))
(new-varterms (map make-term-in-var-form new-vars))
(subst (map (lambda (x y) (list x y))
vars new-varterms))
(new-kernel (formula-substitute kernel subst)))
(apply mk-all (append new-vars
(list (make-imp new-kernel prev-concl)))))))
(make-impnc prev-prem prev-concl))))
((and)
(let* ((left (and-form-to-left formula))
(right (and-form-to-right formula))
(prev1 (formula-to-ex-red-formula left))
(prev2 (formula-to-ex-red-formula right)))
(if
(or (ex-form? prev1) (ex-form? prev2))
(let* ((vars-and-kernel1 (ex-form-to-vars-and-final-kernel prev1))
(vars1 (car vars-and-kernel1))
(kernel1 (cadr vars-and-kernel1))
(vars-and-kernel2 (ex-form-to-vars-and-final-kernel prev2))
(vars2 (car vars-and-kernel2))
(kernel2 (cadr vars-and-kernel2)))
(if
(and (null? (intersection vars1 (formula-to-free kernel2)))
(null? (intersection vars2 (formula-to-free kernel1)))
(null? (intersection vars1 vars2)))
(apply mk-ex (append vars1 vars2 (list (make-and kernel1 kernel2))))
(let* ((new-vars1 (map var-to-new-var vars1))
(new-varterms1 (map make-term-in-var-form new-vars1))
(subst1 (map (lambda (x y) (list x y))
vars1 new-varterms1))
(new-kernel1 (formula-substitute kernel1 subst1))
(new-vars2 (map var-to-new-var vars2))
(new-varterms2 (map make-term-in-var-form new-vars2))
(subst2 (map (lambda (x y) (list x y))
vars2 new-varterms2))
(new-kernel2 (formula-substitute kernel2 subst2)))
(apply mk-ex
(append new-vars1 new-vars2
(list (make-and new-kernel1 new-kernel2)))))))
(make-and prev1 prev2))))
((all)
(let* ((var (all-form-to-var formula))
(kernel (all-form-to-kernel formula))
(prev (formula-to-ex-red-formula kernel)))
(make-all var prev)))
((allnc)
(let* ((var (allnc-form-to-var formula))
(kernel (allnc-form-to-kernel formula))
(prev (formula-to-ex-red-formula kernel)))
(make-allnc var prev)))
((ex)
(let* ((var (ex-form-to-var formula))
(kernel (ex-form-to-kernel formula))
(prev (formula-to-ex-red-formula kernel)))
(make-ex var prev)))
(else (myerror "formula-to-ex-red-formula" "formula expected")
formula)))
(define (formula-to-proof-of-formula-imp-ex-red-formula formula)
(case (tag formula)
((predicate atom)
(let ((u (formula-to-new-avar formula)))
(make-proof-in-imp-intro-form u (make-proof-in-avar-form u))))
((imp)
(let* ((prem (imp-form-to-premise formula))
(concl (imp-form-to-conclusion formula))
(ex-red-prem (formula-to-ex-red-formula prem))
(ex-red-concl (formula-to-ex-red-formula concl))
(vars-and-kernel (ex-form-to-vars-and-final-kernel ex-red-prem))
(vars (car vars-and-kernel))
(kernel (cadr vars-and-kernel))
(test (null? (intersection vars (formula-to-free ex-red-concl))))
(new-vars (if test vars (map var-to-new-var vars)))
(new-varterms (map make-term-in-var-form new-vars))
(subst (map (lambda (x y) (list x y)) vars new-varterms))
(new-kernel (if test kernel (formula-substitute kernel subst)))
(u1 (formula-to-new-avar new-kernel)) ;A0
(u2 (formula-to-new-avar formula)) ;A -> B
(proof-of-ex-red-prem-to-prem ;A* -> A
(formula-to-proof-of-ex-red-formula-imp-formula prem))
(proof-of-concl-to-ex-red-concl ;B -> B*
(formula-to-proof-of-formula-imp-ex-red-formula concl)))
(apply
mk-proof-in-intro-form
(cons
u2 ;A -> B
(append
new-vars ;xs
(list
u1 ;A0
(make-proof-in-imp-elim-form
proof-of-concl-to-ex-red-concl ;B -> B*
(make-proof-in-imp-elim-form
(make-proof-in-avar-form u2) ;A -> B
(make-proof-in-imp-elim-form
proof-of-ex-red-prem-to-prem ;A* -> A
(apply
mk-proof-in-ex-intro-form
(append
(map make-term-in-var-form new-vars) ;xs
(list ex-red-prem ;A*
(make-proof-in-avar-form u1)))))))))))))
((impnc)
(let* ((prem (impnc-form-to-premise formula))
(concl (impnc-form-to-conclusion formula))
(ex-red-prem (formula-to-ex-red-formula prem))
(ex-red-concl (formula-to-ex-red-formula concl))
(vars-and-kernel (ex-form-to-vars-and-final-kernel ex-red-prem))
(vars (car vars-and-kernel))
(kernel (cadr vars-and-kernel))
(test (null? (intersection vars (formula-to-free ex-red-concl))))
(new-vars (if test vars (map var-to-new-var vars)))
(new-varterms (map make-term-in-var-form new-vars))
(subst (map (lambda (x y) (list x y)) vars new-varterms))
(new-kernel (if test kernel (formula-substitute kernel subst)))
(u1 (formula-to-new-avar new-kernel)) ;A0
(u2 (formula-to-new-avar formula)) ;A --> B
(proof-of-ex-red-prem-to-prem ;A* -> A
(formula-to-proof-of-ex-red-formula-imp-formula prem))
(proof-of-concl-to-ex-red-concl ;B -> B*
(formula-to-proof-of-formula-imp-ex-red-formula concl)))
(apply
mk-proof-in-intro-form
(cons
u2 ;A --> B
(append
new-vars ;xs
(list
u1 ;A0
(make-proof-in-imp-elim-form
proof-of-concl-to-ex-red-concl ;B -> B*
(make-proof-in-impnc-elim-form
(make-proof-in-avar-form u2) ;A --> B
(make-proof-in-imp-elim-form
proof-of-ex-red-prem-to-prem ;A* -> A
(apply
mk-proof-in-ex-intro-form
(append
(map make-term-in-var-form new-vars) ;xs
(list ex-red-prem ;A*
(make-proof-in-avar-form u1)))))))))))))
((and)
(let* ((left (and-form-to-left formula))
(right (and-form-to-right formula))
(ex-red-left (formula-to-ex-red-formula left))
(ex-red-right (formula-to-ex-red-formula right))
(vars-and-kernel1
(ex-form-to-vars-and-final-kernel ex-red-left))
(vars1 (car vars-and-kernel1))
(kernel1 (cadr vars-and-kernel1))
(vars-and-kernel2
(ex-form-to-vars-and-final-kernel ex-red-right))
(vars2 (car vars-and-kernel2))
(kernel2 (cadr vars-and-kernel2))
(test
(and (null? (intersection vars1 (formula-to-free kernel2)))
(null? (intersection vars2 (formula-to-free kernel1)))
(null? (intersection vars1 vars2))))
(new-vars1 (if test vars1 (map var-to-new-var vars1)))
(new-varterms1 (map make-term-in-var-form new-vars1))
(subst1 (map (lambda (x y) (list x y)) vars1 new-varterms1))
(new-kernel1
(if test kernel1 (formula-substitute kernel1 subst1)))
(new-vars2 (if test vars2 (map var-to-new-var vars2)))
(new-varterms2 (map make-term-in-var-form new-vars2))
(subst2 (map (lambda (x y) (list x y)) vars2 new-varterms2))
(new-kernel2
(if test kernel2 (formula-substitute kernel2 subst2)))
(ex-red-formula
(apply mk-ex
(append new-vars1 new-vars2
(list (make-and new-kernel1 new-kernel2)))))
(u1 (formula-to-new-avar new-kernel1)) ;A0
(u2 (formula-to-new-avar new-kernel2)) ;B0
(u3 (formula-to-new-avar formula)) ;A & B
(proof-of-left-to-ex-red-left ;A -> A*
(formula-to-proof-of-formula-imp-ex-red-formula left))
(proof-of-right-to-ex-red-right ;B -> B*
(formula-to-proof-of-formula-imp-ex-red-formula right)))
(cond
((and (ex-form? ex-red-left) (ex-form? ex-red-right))
(make-proof-in-imp-intro-form
u3
(make-proof-in-imp-elim-form
(make-proof-in-imp-elim-form
(ex-formulas-and-concl-to-ex-elim-proof ex-red-left ex-red-formula)
(make-proof-in-imp-elim-form
proof-of-left-to-ex-red-left ;A -> A*
(make-proof-in-and-elim-left-form
(make-proof-in-avar-form u3))))
(apply
mk-proof-in-intro-form
(append
new-vars1
(list
u1 ;A0
(make-proof-in-imp-elim-form
(make-proof-in-imp-elim-form
(ex-formulas-and-concl-to-ex-elim-proof
ex-red-right ex-red-formula)
(make-proof-in-imp-elim-form
proof-of-right-to-ex-red-right ;B -> B*
(make-proof-in-and-elim-right-form
(make-proof-in-avar-form u3))))
(apply
mk-proof-in-intro-form
(append
new-vars2
(list u2 ;B0
(apply
mk-proof-in-ex-intro-form
(append
(map make-term-in-var-form new-vars1)
(map make-term-in-var-form new-vars2)
(list ex-red-formula
(make-proof-in-and-intro-form
(make-proof-in-avar-form u1)
(make-proof-in-avar-form u2)))))))))))))))
((and (not (ex-form? ex-red-left)) (ex-form? ex-red-right))
(make-proof-in-imp-intro-form
u3 ;A & B
(make-proof-in-imp-elim-form
(make-proof-in-imp-elim-form
(ex-formulas-and-concl-to-ex-elim-proof
ex-red-right ex-red-formula)
(make-proof-in-imp-elim-form
proof-of-right-to-ex-red-right ;B -> B*
(make-proof-in-and-elim-right-form
(make-proof-in-avar-form u3))))
(apply
mk-proof-in-intro-form
(append
new-vars2
(list
u2 ;B0
(apply
mk-proof-in-ex-intro-form
(append
(map make-term-in-var-form new-vars2)
(list
ex-red-formula
(make-proof-in-and-intro-form
(make-proof-in-imp-elim-form
proof-of-left-to-ex-red-left ;A -> A*
(make-proof-in-and-elim-left-form
(make-proof-in-avar-form u3)))
(make-proof-in-avar-form u2)))))))))))
((and (ex-form? ex-red-left) (not (ex-form? ex-red-right)))
(make-proof-in-imp-intro-form
u3 ;A & B
(make-proof-in-imp-elim-form
(make-proof-in-imp-elim-form
(ex-formulas-and-concl-to-ex-elim-proof ex-red-left ex-red-formula)
(make-proof-in-imp-elim-form
proof-of-left-to-ex-red-left ;A -> A*
(make-proof-in-and-elim-left-form
(make-proof-in-avar-form u3))))
(apply
mk-proof-in-intro-form
(append
new-vars1
(list
u1 ;A0
(apply
mk-proof-in-ex-intro-form
(append
(map make-term-in-var-form new-vars1)
(list
ex-red-formula
(make-proof-in-and-intro-form
(make-proof-in-avar-form u1)
(make-proof-in-imp-elim-form
proof-of-right-to-ex-red-right ;B -> B*
(make-proof-in-and-elim-right-form
(make-proof-in-avar-form u3)))))))))))))
((and (not (ex-form? ex-red-left)) (not (ex-form? ex-red-right)))
(make-proof-in-imp-intro-form
u3 (make-proof-in-and-intro-form
(make-proof-in-imp-elim-form
proof-of-left-to-ex-red-left ;A -> A*
(make-proof-in-and-elim-left-form
(make-proof-in-avar-form u3)))
(make-proof-in-imp-elim-form
proof-of-right-to-ex-red-right ;B -> B*
(make-proof-in-and-elim-right-form
(make-proof-in-avar-form u3))))))
(else (myerror "formula-to-proof-of-formula-imp-ex-red-formula"
"this cannot happen")))))
((all)
(let* ((var (all-form-to-var formula))
(kernel (all-form-to-kernel formula))
(ex-red-kernel (formula-to-ex-red-formula kernel))
(ex-red-formula (formula-to-ex-red-formula formula))
(u1 (formula-to-new-avar formula)) ;all x A
(proof-of-kernel-to-ex-red-kernel ;A -> A*
(formula-to-proof-of-formula-imp-ex-red-formula kernel)))
(mk-proof-in-intro-form
u1 var (make-proof-in-imp-elim-form
proof-of-kernel-to-ex-red-kernel ;A -> A*
(make-proof-in-all-elim-form
(make-proof-in-avar-form u1)
(make-term-in-var-form var))))))
((allnc)
(let* ((var (allnc-form-to-var formula))
(kernel (allnc-form-to-kernel formula))
(ex-red-kernel (formula-to-ex-red-formula kernel))
(ex-red-formula (formula-to-ex-red-formula formula))
(u1 (formula-to-new-avar formula)) ;allnc x A
(proof-of-kernel-to-ex-red-kernel ;A -> A*
(formula-to-proof-of-formula-imp-ex-red-formula kernel)))
(mk-proof-in-intro-form
u1 var (make-proof-in-imp-elim-form
proof-of-kernel-to-ex-red-kernel ;A -> A*
(make-proof-in-allnc-elim-form
(make-proof-in-avar-form u1)
(make-term-in-var-form var))))))
((ex)
(let* ((var (ex-form-to-var formula))
(kernel (ex-form-to-kernel formula))
(ex-red-kernel (formula-to-ex-red-formula kernel))
(ex-red-formula (formula-to-ex-red-formula formula))
(u1 (formula-to-new-avar kernel)) ;A
(u2 (formula-to-new-avar formula)) ;ex x A
(proof-of-kernel-to-ex-red-kernel ;A -> A*
(formula-to-proof-of-formula-imp-ex-red-formula kernel)))
(make-proof-in-imp-intro-form
u2 (make-proof-in-imp-elim-form
(make-proof-in-imp-elim-form
(ex-formulas-and-concl-to-ex-elim-proof formula ex-red-formula)
(make-proof-in-avar-form u2))
(make-proof-in-all-intro-form
var (make-proof-in-imp-intro-form
u1 (make-proof-in-ex-intro-form
(make-term-in-var-form var)
ex-red-formula
(make-proof-in-imp-elim-form
proof-of-kernel-to-ex-red-kernel ;A -> A*
(make-proof-in-avar-form u1)))))))))
(else (myerror
"formula-to-proof-of-formula-imp-ex-red-formula" "formula expected"
formula))))
(define (formula-to-proof-of-ex-red-formula-imp-formula formula)
(case (tag formula)
((predicate atom)
(let ((u (formula-to-new-avar formula)))
(make-proof-in-imp-intro-form u (make-proof-in-avar-form u))))
((imp)
(let* ((prem (imp-form-to-premise formula))
(concl (imp-form-to-conclusion formula))
(ex-red-prem (formula-to-ex-red-formula prem))
(ex-red-concl (formula-to-ex-red-formula concl))
(ex-red-formula (formula-to-ex-red-formula formula))
(u1 (formula-to-new-avar prem)) ;A
(u2 (formula-to-new-avar ex-red-formula)) ;(A -> B)*
(proof-of-ex-red-concl-to-concl ;B* -> B
(formula-to-proof-of-ex-red-formula-imp-formula concl))
(proof-of-prem-to-ex-red-prem ;A -> A*
(formula-to-proof-of-formula-imp-ex-red-formula prem)))
(if
(ex-form? ex-red-prem)
(make-proof-in-imp-intro-form
u2 ;(A -> B)*
(make-proof-in-imp-intro-form
u1 ;A
(make-proof-in-imp-elim-form
proof-of-ex-red-concl-to-concl ;B* -> B
(make-proof-in-imp-elim-form
(make-proof-in-imp-elim-form
(ex-formulas-and-concl-to-ex-elim-proof ex-red-prem ex-red-concl)
(make-proof-in-imp-elim-form
proof-of-prem-to-ex-red-prem ;A -> A*
(make-proof-in-avar-form u1)))
(make-proof-in-avar-form u2)))))
(make-proof-in-imp-intro-form
u2 ;(A -> B)*
(make-proof-in-imp-intro-form
u1 ;A
(make-proof-in-imp-elim-form
proof-of-ex-red-concl-to-concl ;B* -> B
(make-proof-in-imp-elim-form
(make-proof-in-avar-form u2) ;(A -> B)* = A* -> B*
(make-proof-in-imp-elim-form
proof-of-prem-to-ex-red-prem ;A -> A*
(make-proof-in-avar-form u1)))))))))
((impnc)
(let* ((prem (impnc-form-to-premise formula))
(concl (impnc-form-to-conclusion formula))
(ex-red-prem (formula-to-ex-red-formula prem))
(ex-red-concl (formula-to-ex-red-formula concl))
(ex-red-formula (formula-to-ex-red-formula formula))
(u1 (formula-to-new-avar prem)) ;A
(u2 (formula-to-new-avar ex-red-formula)) ;(A -> B)*
(proof-of-ex-red-concl-to-concl ;B* -> B
(formula-to-proof-of-ex-red-formula-imp-formula concl))
(proof-of-prem-to-ex-red-prem ;A -> A*
(formula-to-proof-of-formula-imp-ex-red-formula prem)))
(if
(ex-form? ex-red-prem)
(make-proof-in-imp-intro-form
u2 ;(A -> B)*
(make-proof-in-impnc-intro-form
u1 ;A
(make-proof-in-imp-elim-form
proof-of-ex-red-concl-to-concl ;B* -> B
(make-proof-in-imp-elim-form
(make-proof-in-imp-elim-form
(ex-formulas-and-concl-to-ex-elim-proof ex-red-prem ex-red-concl)
(make-proof-in-imp-elim-form
proof-of-prem-to-ex-red-prem ;A -> A*
(make-proof-in-avar-form u1)))
(make-proof-in-avar-form u2)))))
(make-proof-in-imp-intro-form
u2 ;(A -> B)*
(make-proof-in-impnc-intro-form
u1 ;A
(make-proof-in-imp-elim-form
proof-of-ex-red-concl-to-concl ;B* -> B
(make-proof-in-impnc-elim-form
(make-proof-in-avar-form u2) ;(A -> B)* = A* -> B*
(make-proof-in-imp-elim-form
proof-of-prem-to-ex-red-prem ;A -> A*
(make-proof-in-avar-form u1)))))))))
((and)
(let* ((left (and-form-to-left formula))
(right (and-form-to-right formula))
(ex-red-left (formula-to-ex-red-formula left))
(ex-red-right (formula-to-ex-red-formula right))
(vars-and-kernel1
(ex-form-to-vars-and-final-kernel ex-red-left))
(vars1 (car vars-and-kernel1))
(kernel1 (cadr vars-and-kernel1))
(vars-and-kernel2
(ex-form-to-vars-and-final-kernel ex-red-right))
(vars2 (car vars-and-kernel2))
(kernel2 (cadr vars-and-kernel2))
(test
(and (null? (intersection vars1 (formula-to-free kernel2)))
(null? (intersection vars2 (formula-to-free kernel1)))
(null? (intersection vars1 vars2))))
(new-vars1 (if test vars1 (map var-to-new-var vars1)))
(new-varterms1 (map make-term-in-var-form new-vars1))
(subst1 (map (lambda (x y) (list x y)) vars1 new-varterms1))
(new-kernel1
(if test kernel1 (formula-substitute kernel1 subst1)))
(new-vars2 (if test vars2 (map var-to-new-var vars2)))
(new-varterms2 (map make-term-in-var-form new-vars2))
(subst2 (map (lambda (x y) (list x y)) vars2 new-varterms2))
(new-kernel2
(if test kernel2 (formula-substitute kernel2 subst2)))
(ex-red-formula
(apply mk-ex
(append new-vars1 new-vars2
(list (make-and new-kernel1 new-kernel2)))))
(u1 (formula-to-new-avar ex-red-formula)) ;(A & B)*
(u2 ;A0 & B0
(formula-to-new-avar (make-and new-kernel1 new-kernel2)))
(proof-of-ex-red-left-to-left ;A* -> A
(formula-to-proof-of-ex-red-formula-imp-formula left))
(proof-of-ex-red-right-to-right ;B* -> B
(formula-to-proof-of-ex-red-formula-imp-formula right)))
(cond
((and (ex-form? ex-red-left) (ex-form? ex-red-right))
(make-proof-in-imp-intro-form
u1
(make-proof-in-imp-elim-form
(make-proof-in-imp-elim-form
(ex-formulas-and-concl-to-ex-elim-proof ex-red-formula formula)
(make-proof-in-avar-form u1))
(apply
mk-proof-in-intro-form
(append
new-vars1 new-vars2
(list
u2 ;A0 & B0
(make-proof-in-and-intro-form
(make-proof-in-imp-elim-form
proof-of-ex-red-left-to-left ;A* -> A
(apply
mk-proof-in-ex-intro-form
(append
(map make-term-in-var-form new-vars1)
(list
ex-red-left
(make-proof-in-and-elim-left-form
(make-proof-in-avar-form u2))))))
(make-proof-in-imp-elim-form
proof-of-ex-red-right-to-right ;B* -> B
(apply
mk-proof-in-ex-intro-form
(append
(map make-term-in-var-form new-vars2)
(list
ex-red-right
(make-proof-in-and-elim-right-form
(make-proof-in-avar-form u2)))))))))))))
((and (not (ex-form? ex-red-left)) (ex-form? ex-red-right))
(make-proof-in-imp-intro-form
u1
(make-proof-in-imp-elim-form
(make-proof-in-imp-elim-form
(ex-formulas-and-concl-to-ex-elim-proof ex-red-formula formula)
(make-proof-in-avar-form u1))
(apply
mk-proof-in-intro-form
(append
new-vars2
(list
u2 ;A* & B0
(make-proof-in-and-intro-form
(make-proof-in-imp-elim-form
proof-of-ex-red-left-to-left ;A* -> A
(make-proof-in-and-elim-left-form
(make-proof-in-avar-form u2)))
(make-proof-in-imp-elim-form
proof-of-ex-red-right-to-right ;B* -> B
(apply
mk-proof-in-ex-intro-form
(append
(map make-term-in-var-form new-vars2)
(list
ex-red-right
(make-proof-in-and-elim-right-form
(make-proof-in-avar-form u2)))))))))))))
((and (ex-form? ex-red-left) (not (ex-form? ex-red-right)))
(make-proof-in-imp-intro-form
u1
(make-proof-in-imp-elim-form
(make-proof-in-imp-elim-form
(ex-formulas-and-concl-to-ex-elim-proof ex-red-formula formula)
(make-proof-in-avar-form u1))
(apply
mk-proof-in-intro-form
(append
new-vars1
(list
u2 ;A0 & B*
(make-proof-in-and-intro-form
(make-proof-in-imp-elim-form
proof-of-ex-red-left-to-left ;A* -> A
(apply
mk-proof-in-ex-intro-form
(append
(map make-term-in-var-form new-vars1)
(list
ex-red-left
(make-proof-in-and-elim-left-form
(make-proof-in-avar-form u2))))))
(make-proof-in-imp-elim-form
proof-of-ex-red-right-to-right ;B* -> B
(make-proof-in-and-elim-right-form
(make-proof-in-avar-form u2))))))))))
((and (not (ex-form? ex-red-left)) (not (ex-form? ex-red-right)))
(make-proof-in-imp-intro-form
u1 (make-proof-in-and-intro-form
(make-proof-in-imp-elim-form
proof-of-ex-red-left-to-left ;A* -> A
(make-proof-in-and-elim-left-form
(make-proof-in-avar-form u1)))
(make-proof-in-imp-elim-form
proof-of-ex-red-right-to-right ;B* -> B
(make-proof-in-and-elim-right-form
(make-proof-in-avar-form u1))))))
(else (myerror "formula-to-proof-of-ex-red-formula-imp-formula"
"this cannot happen")))))
((all)
(let* ((var (all-form-to-var formula))
(kernel (all-form-to-kernel formula))
(ex-red-kernel (formula-to-ex-red-formula kernel))
(ex-red-formula (formula-to-ex-red-formula formula))
(u1 (formula-to-new-avar ex-red-formula)) ;all x A*
(proof-of-ex-red-kernel-to-kernel ;A* -> A
(formula-to-proof-of-ex-red-formula-imp-formula kernel)))
(mk-proof-in-intro-form
u1 var (make-proof-in-imp-elim-form
proof-of-ex-red-kernel-to-kernel ;A* -> A
(make-proof-in-all-elim-form
(make-proof-in-avar-form u1)
(make-term-in-var-form var))))))
((allnc)
(let* ((var (allnc-form-to-var formula))
(kernel (allnc-form-to-kernel formula))
(ex-red-kernel (formula-to-ex-red-formula kernel))
(ex-red-formula (formula-to-ex-red-formula formula))
(u1 (formula-to-new-avar ex-red-formula)) ;allnc x A*
(proof-of-ex-red-kernel-to-kernel ;A* -> A
(formula-to-proof-of-ex-red-formula-imp-formula kernel)))
(mk-proof-in-intro-form
u1 var (make-proof-in-imp-elim-form
proof-of-ex-red-kernel-to-kernel ;A* -> A
(make-proof-in-allnc-elim-form
(make-proof-in-avar-form u1)
(make-term-in-var-form var))))))
((ex)
(let* ((var (ex-form-to-var formula))
(kernel (ex-form-to-kernel formula))
(ex-red-kernel (formula-to-ex-red-formula kernel))
(ex-red-formula (formula-to-ex-red-formula formula))
(u1 (formula-to-new-avar ex-red-kernel)) ;A*
(u2 (formula-to-new-avar ex-red-formula)) ;ex x A*
(proof-of-ex-red-kernel-to-kernel ;A* -> A
(formula-to-proof-of-ex-red-formula-imp-formula kernel)))
(make-proof-in-imp-intro-form
u2 (make-proof-in-imp-elim-form
(make-proof-in-imp-elim-form
(ex-formulas-and-concl-to-ex-elim-proof ex-red-formula formula)
(make-proof-in-avar-form u2))
(make-proof-in-all-intro-form
var (make-proof-in-imp-intro-form
u1 (make-proof-in-ex-intro-form
(make-term-in-var-form var)
formula
(make-proof-in-imp-elim-form
proof-of-ex-red-kernel-to-kernel ;A* -> A
(make-proof-in-avar-form u1)))))))))
(else (myerror
"formula-to-proof-of-ex-red-formula-imp-formula" "formula expected"
formula))))
|