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
|
% $Id: ref.tex,v 1.28 2008/01/25 13:30:19 logik Exp $
% was: ea.tex,v 1.68 2001/08/13 12:55:02 schwicht Exp
% \documentclass[11pt,draft,a4paper]{amsbook}
\documentclass[11pt,a4paper]{amsart}
% \documentclass[11pt,a4paper,fleqn]{article}
\usepackage{amsmath,amssymb,amsthm,bussproofs}
% for pdftex
\usepackage[backref]{hyperref}
\allowdisplaybreaks[4]
\parskip 0pt plus 1pt
% \input{preamb}
\theoremstyle{plain}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{claim*}{Claim}
\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}
\newtheorem*{definition*}{Definition}
\newtheorem{example}[theorem]{Example}
\newtheorem*{example*}{Example}
\newtheorem{examples}[theorem]{Examples}
\newtheorem*{examples*}{Examples}
\newtheorem{remark}[theorem]{Remark}
\newtheorem*{remark*}{Remark}
\newtheorem*{acknowledgement*}{Acknowledgement}
\def\qedsymbol{{\ \vbox{\hrule\hbox{%
\vrule height1.3ex\hskip0.8ex\vrule}\hrule}}\par}
% minlog.mac contains the macros for all tex-files of the minlog
% documentation in order to avoid code duplication and different
% notations.
\input{minlog.mac}
% \def\N{\mathbb{N}}
%% Comment out this definition
%% in your main document when preparing the final version
\def\mylabel#1{\label{#1}\marginpar{\tiny #1}}
\makeindex
\title{Minlog reference manual}
% \title{Minimal logic for computable functionals. Minlog reference manual}
\author{}
% \author{Klaus Aehlig, Martin Ruckert and Helmut Schwichtenberg%
% \thanks{Mathematisches Institut der Universit\"at M\"unchen,
% Theresienstra{\ss}e 39, D-80333 M\"unchen, Germany. Phone
% +49 89 2394 4413, Fax +49 89 280 5248,
% e-mail address \texttt{schwicht@rz.mathematik.uni-muenchen.de}}
% \address{Mathematisches Institut der Universit\"at M\"unchen\\
% Theresienstra{\ss}e 39\\
% D-80333 M\"unchen, Germany}
% \email{$\{$aehlig,ruckert,schwicht$\}$@rz.mathematik.uni-muenchen.de}
% \urladdr{http://mathematik.uni-muenchen.de/schwicht}
% \thanks{}
% \keywords{extracted programs}
% \subjclass[2000]{Primary: 02Dxx; Secondary: 02Fxx}
\date{\today}
\begin{document}
% \begin{abstract}
% We define a formal system based on minimal logic and inductively
% defined ground types.% -- Draft of \today
% \end{abstract}
\maketitle
\tableofcontents
\input{acknow}
\section{Introduction}
\mylabel{Intro}
\textsc{Minlog} is intended to reason about computable functionals,
using minimal logic. It is an interactive prover with the following
features.
\begin{itemize}
\item Proofs are treated as first class objects: they can be normalized
and then used for reading off an instance if the proven formula is
existential, or changed for program development by proof
transformation.
\item To keep control over the complexity of extracted programs, we
follow Kreisel's proposal and aim at a theory with a strong language
and weak existence axioms. It should be conservative over (a fragment
of) arithmetic.
\item \textsc{Minlog} is based on minimal rather than classical or
intuitionistic logic. This more general setting makes it possible to
implement program extraction from classical proofs, via a refined
$A$-translation (cf.\ \cite{BergerBuchholzSchwichtenberg02}).
\item Constants are intended to denote computable functionals.
Since their (mathematically correct) domains are the Scott-Ershov
partial continuous functionals, this is the intended range of the
quantifiers.
\item Variables carry (simple) types, with free algebras as base types.
The latter need not be finitary (so we allow e.g.\ countably branching
trees), and can be simultaneously generated. Type parameters (ML
style) are allowed, but we keep the theory predicative and disallow
type quantification.
\item To simplify equational reasoning, the system identifies
terms with the same normal form. A rich collection of rewrite rules
is provided, which can be extended by the user. Decidable predicates
are implemented via boolean valued functions, hence the rewrite
mechanism applies to them as well.
\end{itemize}
We now describe in more details some of these features.
\subsection{Simultaneous free algebras}
A free algebra is given by \emph{constructors}, for instance zero and
successor for the natural numbers. We want to treat other data types
as well, like lists and binary trees. When dealing with inductively
defined sets, it will also be useful to explicitely refer to the
generation tree. Such trees are quite often countably branching, and
hence we allow infinitary free algebras from the outset.
The freeness of the constructors is expressed by requiring that their
ranges are disjoint and that they are injective. Moreover, we view
the free algebra as a domain and require that its bottom element is
not in the range of the constructors. Hence the constructors are
total and non-strict. For the notion of totality cf.\ \cite[Chapter
8.3]{Stoltenberg94}.
In our intended semantics we do not require that every semantic object
is the denotation of a closed term, not even for finitary algebras.
One reason is that for normalization by evaluation (cf.\
\cite{BergerEberlSchwichtenberg03}) we want to allow term families in
our semantics.
% However, if a type $\tau$ is given by a finitary algebra, then we do
% require that every closed term of type $\tau$ whose value is a
% semantic numeral also reduces to the corresponding syntactic numeral;
% this is \textsc{Plotkin}'s adequacy theorem \cite{Plotkin77} (or
% \cite[p.130]{AmadioCurien98}), which holds for a call-by-name
% evaluation strategy.
To make a free algebra into a domain and still have the constructors
injective and with disjoint ranges, we model e.g.\ the natural numbers
as shown in Figure~\ref{F:nat}.
\begin{figure}
% \begin{picture}(168,108)
\begin{picture}(170,120)
\put(48,0){\makebox(0,0){$\bullet$}}
\put(36,0){\makebox(0,0){$\bot$}}
\put(48,0){\line(-1,1){24}}
\put(24,24){\makebox(0,0){$\bullet$}}
\put(12,24){\makebox(0,0){$0$}}
\put(48,0){\line(1,1){24}}
\put(72,24){\makebox(0,0){$\bullet$}}
\put(90,24){\makebox(0,0){$S \bot$}}
\put(72,24){\line(-1,1){24}}
\put(48,48){\makebox(0,0){$\bullet$}}
\put(30,48){\makebox(0,0){$S 0$}}
\put(72,24){\line(1,1){24}}
\put(96,48){\makebox(0,0){$\bullet$}}
\put(120,48){\makebox(0,0){$S(S \bot)$}}
\put(96,48){\line(-1,1){24}}
\put(72,72){\makebox(0,0){$\bullet$}}
\put(48,72){\makebox(0,0){$S(S 0)$}}
\put(96,48){\line(1,1){24}}
\put(120,72){\makebox(0,0){$\bullet$}}
\put(150,72){\makebox(0,0){$S(S(S \bot))$}}
\put(120,72){\line(-1,1){24}}
\put(96,96){\makebox(0,0){$\bullet$}}
\put(66,96){\makebox(0,0){$S(S(S 0))$}}
\put(120,72){\line(1,1){24}}
\put(147,99){\makebox(0,0){.}}
\put(150,102){\makebox(0,0){.}}
\put(153,105){\makebox(0,0){.}}
\put(159,111){\makebox(0,0){$\bullet$}}
\put(181,111){\makebox(0,0){$\infty$}}
\end{picture}
\caption{The domain of natural numbers}
\label{F:nat}
\end{figure}
Notice that for more complex algebras we usually need many more
\inquotes{infinite} elements; this is a consequence of the closure of
domains under suprema. To make dealing with such complex structures
less annoying, we will normally restrict attention to the \emph{total}
elements of a domain, in this case -- as expected -- the elements
labelled $0$, $S 0$, $S(S 0)$ etc.
\subsection{Partial continuous functionals}
As already mentioned, the (mathematically correct) domains of
computable functionals have been identified by Scott and Ershov as the
partial continuous functionals; cf.\ \cite{Stoltenberg94}. Since we
want to deal with computable functionals in our theory, we consider it
as mandatory to accommodate their domains. This is also true if one
is interested in total functionals only; they have to be treated as
particular partial continuous functionals. We will make use of
predicate constants $\Total_{\rho}$ with the total functionals of type
$\rho$ as the intended meaning. To make formal arguments with
quantifiers relativized to total objects more managable, we use a
special sort of variables intended to range over such objects only.
For example, $\texttt{n0}, \texttt{n1}, \texttt{n2}, \dots,
\texttt{m0}, \dots$ range over total natural numbers, and $\verb#n^0#,
\verb#n^1#, \verb#n^2#, \dots$ are general variables. This amounts to
an abbreviation of
\begin{alignat*}{2}
&\forall \hat{x}.\Total_{\rho}(\hat{x}) \to A &\quad\hbox{by}\quad&
\forall x A,\\
&\exists \hat{x}.\Total_{\rho}(\hat{x}) \land A &\quad\hbox{by}\quad&
\exists x A.
\end{alignat*}
\subsection{Primitive recursion, computable functionals}
The elimination constants corresponding to the constructors are called
primitive recursion operators $\rec$. They are described in detail in
Section \ref{Pconst}. In this setup, every closed term reduces to a
numeral.
However, we shall also use constants for rather arbitrary computable
functionals, and axiomatize them according to their intended meaning
by means of rewrite rules. An example is the general fixed point
operator $\fix$, which is axiomatized by $\fix F = F(\fix F)$.
Clearly then it cannot be true any more that every closed term reduces
to a numeral. We may have non-terminating terms, but this just means
that not always it is a good idea to try to normalize a term.
An important consequence of admitting non-terminating terms is that
our notion of proof is not decidable: when checking e.g.\ whether two
terms are equal we may run into a non-terminating computation. But we
still have semi-decidability of proofs, i.e., an algorithm to check
the correctness of a proof that can only give correct results, but may
not terminate. In practice this is sufficient.
To avoid this somewhat unpleasant undecidability phenomenon, we may
also view our proofs as abbreviated forms of full proofs, with certain
equality arguments left implicit. If some information sufficient to
recover the full proof (e.g.\ for each node a bound on the number of
rewrite steps needed to verify it) is stored as part of the proof,
then we retain decidability of proofs.
\subsection{Decidable predicates, axioms for predicates}
As already mentioned, decidable predicates are viewed via boolean
valued functions, hence the rewrite mechanism applies to them as well.
Equality is decidable for finitary algebras only; infinitary algebras
are to be treated similarly to arrow types. For infinitary algebras
(extensional) equality\index{equality} is a predicate constant, with
appropriate axioms. In a finitary algebra equality is a (recursively
defined) program constant. Similarly, existence (or totality) is a
decidable predicate for finitary algebras, and given by predicate
constants $\Total_{\rho}$ for infinitary algebras as well as composed
types. The axioms are listed in Subsection \ref{SS:AxiomConst}
of Section~\ref{S:AssumptionVarConst}.
\subsection{Minimal logic, proof transformation}
For generalities about minimal logic cf.\ \cite{TroelstraSchwichtenberg00}.
A concise description of the theory behind the present implementation
can be found in \inquotes{Minimal Logic for Computable Functions}
which is available on the \textsc{Minlog} page \texttt{www.minlog-system.de}.
\subsection{Comparison with Coq and Isabelle}
\mylabel{SS:Coq} \textsc{Coq} (cf.\ \texttt{coq.inria.fr}) has evolved
from a calculus of constructions defined by \textsc{Huet} \index{Huet}
and \textsc{Coquand}\index{Coquand}. It is a constructive, but
impredicative system based on type theory. More recently it has been
extended by \textsc{Paulin-Mohring}\index{Paulin-Mohring} to also
include inductively defined predicates. Program extraction from
proofs has been implemented by \textsc{Paulin-Mohring},
\textsc{Filliatre}\index{Filliatre} and
\textsc{Letouzey}\index{Letouzey}, in the sense that \textsc{Ocaml}
programs are extracted from proofs.
The \textsc{Isabelle/HOL} system of \textsc{Paulson}\index{Paulson}
and \textsc{Nipkow}\index{Nipkow} has its roots in \textsc{Church}'s
theory of simple types and \textsc{Hilbert}'s Epsilon calculus. It is
an inherently classical system; however, since many proofs in fact use
constructive arguments, in is conceivable that program extraction can
be done there as well. This has been explored by \textsc{Berghofer}
in his thesis \cite{Berghofer03}.
Compared with the \textsc{Minlog} system, the following points are of
interest.
\begin{itemize}
\item The fact that in \textsc{Coq} a formula is just a map into the
type \texttt{Prop} (and in \textsc{Isabelle} into the type
\texttt{bool}) can be used to define such a function by what is called
\indexentry{strong elimination}, say by $f(\true) := A$ and $f(\false)
:= B$ with fixed formulas $A$ and $B$. The problem is that then it is
impossible to assign an ordinary type (say in the sense of
\textsc{ML}) to a proof. It is not clear how this problem for program
extraction can be avoided (in a clean way) for both \textsc{Coq} and
\textsc{Isabelle}. In \textsc{Minlog} it does not exist due to the
separation of terms and formulas.
\item The impredicativity (in the sense of quantification over
predicate variables) built into \textsc{Coq} and \textsc{Isabelle} has
as a consequence that extracted programs need to abstract over type
variables, which is not allowed in program languages of the
\textsc{ML} family. Therefore one can only allow outer universal
quantification over type and predicate variables in proofs to be used
for program extraction; this is done in the \textsc{Minlog} system
from the outset. However, many uses of quantification over predicate
variables (like defining the logical connectives apart from $\to$ and
$\forall$) can be achieved by means of inductively defined predicates.
This feature is available in all three systems.
\item The distinction between properties with and without
computational content seems to be crucial for a reasonable program
extraction environment; this feature is available in all three
systems. However, it also seems to be necessary to distinguish
between universal quantifiers with and without computational content,
as in \textsc{Berger}'s \cite{Berger93a}. At present this feature is
availble in the \textsc{Minlog} system only.
\item \textsc{Coq} has records, whose fields may contain proofs and
may depend on earlier fields. This can be useful, but does not seem
to be really essential. If desired, in \textsc{Minlog} one can use
products for this purpose; however, proof objects have to be
introduced explicitely via assumptions.
\item \textsc{Minlog}'s automated proof search \texttt{search} tool is
based on \textsc{Miller}'s\index{Miller} \cite{Miller91b}; it produces
proofs in minimal logic. In addition, \textsc{Coq} has many strong
tactics, for instance \texttt{Omega} for quantifier free
\textsc{Presburger}\index{Presburger} arithmetic, \texttt{Arith} for
proving simple arithmetic properties and \texttt{Ring} for proving
consequences of the ring axioms. Similar tactics exist in
\textsc{Isabelle}. These tactics tend to produce rather long proofs,
which is due to the fact that equality arguments are carried out
explicitely. This is avoided in \textsc{Minlog} by relativizing every
proof to a set of rewrite rules, and identifyling terms and formulas
with the same normal form w.r.t.\ these rules.
\item In \textsc{Isabelle} as well as in \textsc{Minlog} the extracted
programs are provided as terms within the language, and a soundness
proof can be generated automatically. For \textsc{Coq} (and similarly
for \textsc{Nuprl}) such a feature could at present only be achived by
means of some form of reflection.
\end{itemize}
\section{Types, with simultaneous free algebras as base types}
\mylabel{S:Types}
Generally we consider typed theories only. Types are built from type
variables and type constants by algebra type formation \texttt{(alg
$\rho_1 \dots \rho_n$)}, arrow type formation $\rho \to \sigma$ and
product type formation $\rho \times \sigma$ (and possibly other type
constructors).
We have type constants \texttt{atomic}, \texttt{existential},
\texttt{prop} and \texttt{nulltype}. They will be used to assign
types to formulas. E.g.\ $\forall n\,n=0$ receives the type
$\texttt{nat} \to \texttt{atomic}$, and $\forall n,m \ex k\,n+m=k$
receives the type $\texttt{nat} \to \texttt{nat} \to
\texttt{existential}$. The type \texttt{prop} is used for predicate
variables, e.g.\ $R$ of arity \texttt{nat,nat -> prop}. Types of
formulas will be necessary for normalization by evaluation of proof
terms. The type \texttt{nulltype} will be useful when assigning to a
formula the type of a program to be extracted from a proof of this
formula. Types not involving the types \texttt{atomic},
\texttt{existential}, \texttt{prop} and \texttt{nulltype} are called
object types.
% \subsection{Type variables and constants}
Type variable\index{type variable} names are $\texttt{alpha},
\texttt{beta} \dots$; $\texttt{alpha}$ is provided by default. To
have infinitely many type variables available, we allow appended
indices: $\texttt{alpha}1, \texttt{alpha}2, \texttt{alpha}3 \dots$
will be type variables. The only type constants\index{type constant}
are $\texttt{atomic}, \texttt{existential}, \texttt{prop}$ and
$\texttt{nulltype}$.
\subsection{Generalitites for substitutions, type substitutions}
\mylabel{SS:GenSubst}
Generally, a substitution is a list $((x_1\ t_1) \dots (x_n\ t_n))$ of
lists of length two, with distinct variables $x_i$ and such that for
each $i$, $x_i$ is different from $t_i$. It is understood as
simultaneous substitution. The default equality is \texttt{equal?};
however, in the versions ending with \texttt{-wrt} (for \inquotes{with
respect to}) one can provide special notions of equality. To construct
substitutions we have
\begin{alignat*}{2}
&\texttt{(make-substitution \textsl{args} \textsl{vals})}%
\index{make-substitution@\texttt{make-substitution}}
\\
&\texttt{(make-substitution-wrt \textsl{arg-val-equal?}\ \textsl{args}
\textsl{vals})}%
\index{make-substitution-wrt@\texttt{make-substitution-wrt}}
\\
&\texttt{(make-subst \textsl{arg} \textsl{val})}%
\index{make-subst@\texttt{make-subst}}
\\
&\texttt{(make-subst-wrt \textsl{arg-val-equal?}\ \textsl{arg} \textsl{val})}%
\index{make-subst-wrt@\texttt{make-subst-wrt}}
\\
&\texttt{empty-subst}\index{empty-subst@\texttt{empty-subst}}
\end{alignat*}
Accessing a substitution is done via the usual access operations
for association list: \texttt{assoc} and \texttt{assoc-wrt}.
We also provide
\begin{alignat*}{2}
&\texttt{(restrict-substitution-wrt \textsl{subst} \textsl{test?})}%
\index{restrict-substitution-wrt@\texttt{restrict-substitution-wrt}}
\\
&\texttt{(restrict-substitution-to-args \textsl{subst} \textsl{args})}%
\index{restrict-substitution-to-args@\texttt{restrict-substitution-to-args}}
\\
&\texttt{(substitution-equal?\ \textsl{subst1} \textsl{subst2})}%
\index{substitution-equal?@\texttt{substitution-equal?}}
\\
&\texttt{(substitution-equal-wrt?\ \textsl{arg-equal?}\ \textsl{val-equal?}\
\textsl{subst1} \textsl{subst2})}%
\index{substitution-equal-wrt?@\texttt{substitution-equal-wrt?}}
\\
&\texttt{(subst-item-equal-wrt?\ \textsl{arg-equal?}\ \textsl{val-equal?}\
\textsl{item1} \textsl{item2})}%
\index{subst-item-equal-wrt?@\texttt{subst-item-equal-wrt?}}
\\
&\texttt{(consistent-substitutions-wrt?}
\\
&\qquad\texttt{\textsl{arg-equal?}\
\textsl{val-equal?}\ \textsl{subst1} \textsl{subst2})}%
\index{consistent-substitutions-wrt?@\texttt{consistent-substitutions-wrt?}}
\end{alignat*}
\emph{Composition}\index{composition} $\vartheta \sigma$ of two
substitutions
\begin{align*}
\vartheta &= ((x_1\ s_1) \dots (x_m\ s_m)),
\\
\sigma &= ((y_1\ t_1) \dots (y_n\ t_n))
\end{align*}
is defined as follows. In the list $((x_1\ s_1\sigma) \dots (x_m\
s_m\sigma)\ (y_1\ t_1) \dots (y_n\ t_n))$ remove all bindings $(x_i\
s_i\sigma)$ with $s_i\sigma = x_i$, and also all bindings $(y_j\ t_j)$
with $y_j \in \{x_1, \dots, x_n\}$. It is easy to see that
composition is associative, with the empty substitution as unit.
We provide
\begin{alignat*}{2}
\texttt{(compose-substitutions-wrt}\
&\texttt{\textsl{substitution-proc} \textsl{arg-equal?}}
\\
&\texttt{\textsl{arg-val-equal?}\ \textsl{subst1} \textsl{subst2}})%
\index{compose-substitutions-wrt@\texttt{compose-substitutions-wrt}}
\end{alignat*}
We shall have occasion to use these general substitution procedures
for the following kinds of substitutions
\[
\begin{tabular}{|l|l|l|l|}
\hline
for
&called
&domain equality
&arg-val-equality
\\
\hline
type variables
&\texttt{tsubst}\index{tsubst@\texttt{tsubst}}
&\texttt{equal?}
&\texttt{equal?}
\\
object variables
&\texttt{osubst}\index{osubst@\texttt{osubst}}
&\texttt{equal?}
&\texttt{var-term-equal?}\index{var-term-equal?@\texttt{var-term-equal?}}
\\
predicate variables
&\texttt{psubst}\index{psubst@\texttt{psubst}}
&\texttt{equal?}
&\texttt{pvar-cterm-equal?}%
\index{pvar-cterm-equal?@\texttt{pvar-cterm-equal?}}
\\
assumption variables
&\texttt{asubst}\index{asubst@\texttt{asubst}}
&\texttt{avar=?}\index{avar=?@\texttt{avar=?}}
&\texttt{avar-proof-equal?}%
\index{avar-proof-equal?@\texttt{avar-proof-equal?}}
\\
\hline
\end{tabular}
\]
The following substitutions will make sense for a
\[
\begin{tabular}{|l|l|}
\hline
type
&\texttt{tsubst}
\\
term
&\texttt{tsubst} and \texttt{osubst}
\\
formula
&\texttt{tsubst} and \texttt{osubst} and \texttt{psubst}
\\
proof
&\texttt{tsubst} and \texttt{osubst} and \texttt{psubst} and \texttt{asubst}
\\
\hline
\end{tabular}
\]
In particular, for \indexentry{type substitutions} \texttt{tsubst}
we have
\begin{alignat*}{2}
&\texttt{(type-substitute \textsl{type} \textsl{tsubst})}%
\index{type-substitute@\texttt{type-substitute}}
\\
&\texttt{(type-subst \textsl{type} \textsl{tvar} \textsl{type1})}%
\index{type-subst@\texttt{type-subst}}
\\
&\texttt{(compose-t-substitutions \textsl{tsubst1} \textsl{tsubst2})}%
\index{compose-t-substitutions@\texttt{compose-t-substitutions}}
\end{alignat*}
A display function for type substitutions is
\begin{align*}
&\texttt{(display-t-substitution \textsl{tsubst})}%
\index{display-t-substitution@\texttt{display-t-substitution}}
\end{align*}
\subsection{Simultaneous free algebras as base types}
We allow the formation of inductively generated types $\mu
\vec{\alpha}\,\vec{\kappa}$, where $\vec{\alpha} =
\alpha_1,\dots,\alpha_n$ is a list of distinct type variables, and
$\vec{\kappa}$ is a list of \inquotes{constructor types} whose
argument types contain $\alpha_1,\dots,\alpha_n$ in strictly positive
positions only.
For instance, $\mu\alpha(\alpha, \alpha \to \alpha)$ is the type of
natural numbers; here the list $(\alpha, \alpha \to \alpha)$ stands
for two generation principles: $\alpha$ for \inquotes{there is a
natural number} (the number $0$), and $\alpha \to \alpha$ for
\inquotes{for every natural number there is another one} (its
successor).
Let an infinite supply of \emph{type variables} $\alpha, \beta$ be
given. Let $\vec{\alpha} = (\alpha_j)_{j=1,\dots,m}$ be a list of
distinct type variables. \emph{Types} $\rho, \sigma, \tau, \mu, \nu
\in \Types$ and \emph{constructor types} $\kappa \in
\constrtypes(\vec{\alpha})$ are defined inductively as follows.
\begin{align*}
&\frac{\vec{\rho}, \vec{\sigma}_1, \dots, \vec{\sigma}_n \in \Types}
{\vec{\rho} \to (\vec{\sigma}_1 \to \alpha_{j_1}) \to \dots
\to (\vec{\sigma}_n \to \alpha_{j_n}) \to \alpha_j \in
\constrtypes(\vec{\alpha})} \quad\hbox{($n \ge 0$)}
\\
&\frac{\kappa_1, \dots, \kappa_n \in \constrtypes(\vec{\alpha})}
{(\mu \vec{\alpha}\,(\kappa_1, \dots, \kappa_n))_j \in \Types}
\quad\hbox{($n \ge 1$, $j=1,\dots,m$)}\qquad
\frac{\rho, \sigma \in \Types}{\rho \to \sigma \in \Types}
\end{align*}
Here $\vec{\rho}$ is short for a list $\rho_1,\dots,\rho_k$ ($k\ge 0$)
of types and $\vec{\rho} \to \sigma$ means $\rho_1 \to \dots \to
\rho_k \to \sigma$, associated to the right. We shall use $\mu, \nu$
for types of the form $(\mu \vec{\alpha}\,(\kappa_1, \dots,
\kappa_n))_j$ only, and for types $\vec{\tau}=
(\tau_j)_{j=1,\dots,m}$ and a constructor type $\kappa = \vec{\rho}
\to (\vec{\sigma}_1 \to \alpha_{j_1}) \to \dots \to (\vec{\sigma}_n
\to \alpha_{j_n}) \to \alpha_j \in \constrtypes(\vec{\alpha})$ let
\[
\kappa[\vec{\tau}] :=
\vec{\rho} \to (\vec{\sigma}_1 \to \tau_{j_1}) \to \dots \to
(\vec{\sigma}_n \to \tau_{j_n}) \to \tau_j.
\]
\begin{examples*}
\begin{alignat*}{2}
&\unit &&:= \mu \alpha\,\alpha,
\\
&\boole &&:= \mu \alpha\,(\alpha,\alpha),
\\
&\nat &&:= \mu \alpha\,(\alpha,\alpha \to \alpha),
\\
&\ytensor(\alpha_1)(\alpha_2) &&:=
\mu \alpha. \alpha_1 \to \alpha_2 \to \alpha,
\\
&\ypair(\alpha_1)(\alpha_2) &&:=
\mu \alpha. (\unit \to \alpha_1) \to (\unit \to \alpha_2) \to \unit \to
\alpha,
\\
&\yplus(\alpha_1)(\alpha_2) &&:=
\mu \alpha. (\alpha_1 \to \alpha, \alpha_2 \to \alpha),
\\
&\lst(\alpha_1) &&:= \mu \alpha\,(\alpha,\alpha_1 \to \alpha \to \alpha),
\\
% &\rho \times \sigma &&:= \mu \alpha.\rho \to \sigma \to \alpha,
% \\
% &\rho + \sigma &&:= \mu \alpha\,(\rho \to \alpha, \sigma \to \alpha),
% \\
&(\tree, \tlist) &&:= \mu (\alpha,\beta)\,
(\alpha, \beta \to \alpha, \beta, \alpha \to \beta \to \beta),
\\
&\btree &&:= \mu \alpha\,(\alpha, \alpha \to \alpha \to \alpha),
\\
&\C{O} &&:= \mu \alpha\,
(\alpha, \alpha \to \alpha, (\nat \to \alpha) \to \alpha),
\\
&\C{T}_0 &&:= \nat,
\\
&\C{T}_{n+1} &&:= \mu \alpha\,(\alpha, (\C{T}_n \to \alpha) \to \alpha).
\end{alignat*}
Note that we could have defined our primitive $\rho \times \sigma$ by
$\mu \alpha.\rho \to \sigma \to \alpha$. However, this may lead to
complex terms when it comes to extract programs from proofs.
Therefore we stick to using $\rho \times \sigma$ as a primitive.
\end{examples*}
% \subsection{Types of formulas}
% % We also have ground types \texttt{atomic}, \texttt{existential},
% \texttt{prop} and \texttt{top}; they will be used to assign types to
% formulas. E.g.\ $\forall n\,n=0$ receives the type $\texttt{nat} \to
% \texttt{atomic}$, and $\forall n,m \ex k\,n+m=k$ receives the type
% $\texttt{nat} \to \texttt{nat} \to \texttt{existential}$. (Logical)
% falsity $\bot$\index{falsity!logical} receives the type \texttt{top}.
% The ground type \texttt{prop} is used for predicate variables, e.g.\
% $R$ of arity \texttt{nat,nat -> prop}. Types of formulas will be
% necessary for normalization by evaluation of proof terms. Types not
% involving the ground types \texttt{atomic}, \texttt{existential},
% \texttt{prop} and \texttt{top} are called object types.
To add and remove names for type variables, we use
\begin{align*}
&\texttt{(add-tvar-name \textsl{name1} \dots)}
\index{add-tvar-name@\texttt{add-tvar-name}}
\\
&\texttt{(remove-tvar-name \textsl{name1} \dots)}
\index{remove-tvar-name@\texttt{remove-tvar-name}}
\end{align*}
We need a constructor, accessors and a test for type variables.
\begin{alignat*}{2}
&\texttt{(make-tvar \textsl{index} \textsl{name})}
&\quad& \text{constructor}
\\
&\texttt{(tvar-to-index \textsl{tvar})} && \text{accessor}
\index{tvar-to-index@\texttt{tvar-to-index}}
\\
&\texttt{(tvar-to-name \textsl{tvar})} && \text{accessor}
\index{tvar-to-name@\texttt{tvar-to-name}}
\\
&\texttt{(tvar?\ \textsl{x}).}
\index{tvar?@\texttt{tvar?}}
\end{alignat*}
To generate new type variables we use
\begin{align*}
&\texttt{(new-tvar \textsl{type})}
\index{new-tvar@\texttt{new-tvar}}
\end{align*}
% Ground types are added and removed by
% \begin{align*}
% % &\texttt{(add-ground-type \textsl{symbol} \textsl{symbol1} \dots)}
% \index{add-ground-type@\texttt{add-ground-type}}
% \\
% % &\texttt{(remove-ground-type \textsl{type})}.
% \index{remove-ground-type@\texttt{remove-ground-type}}
% % \end{align*}
% Executing \texttt{(add-ground-type \textsl{symbol} \textsl{symbol1}
% \dots)} causes \texttt{symbol} to be ad\-ded as name for the newly
% created ground type, and the optional symbols \textsl{symbol1} \dots
% to be reserved as names for variables of that type.
To introduce simultaneous free algebras we use
\[
\texttt{add-algebras-with-parameters}
\index{add-algebras-with-parameters@\texttt{add-algebras-with-parameters}},
\quad \hbox{abbreviated
\texttt{add-param-algs}
\index{add-param-algs@\texttt{add-param-algs}}}.
\]
An example is
\begin{verbatim}
(add-param-algs
(list "labtree" "labtlist") 'alg-typeop 2
'("LabLeaf" "alpha1=>labtree")
'("LabBranch" "labtlist=>alpha2=>labtree")
'("LabEmpty" "labtlist")
'("LabTcons" "labtree=>labtlist=>labtlist" pairscheme-op))
\end{verbatim}
This simultaneously introduces the two free algebras \texttt{labtree}
and \texttt{labtlist}, both finitary, whose constructors are
\texttt{LabLeaf}, \texttt{LabBranch}, \texttt{LabEmpty} and
\texttt{LabTcons} (written as an infix pair operator, hence right
associative). The constructors are introduced as
\inquotes{self-evaluating} constants; they play a special role in our
semantics for normalization by evaluation.
In case there are no parameters we use \texttt{add-algs}%
\index{add-algs@\texttt{add-algs}}, and in case there is no
need for a simultaneous definition we use \texttt{add-alg}%
\index{add-alg@\texttt{add-alg}} or \texttt{add-param-alg}%
\index{add-param-alg@\texttt{add-param-alg}}.
For already introduced algebras we need constructors and accessors
\begin{align*}
&\texttt{(make-alg \textsl{name} \textsl{type1} \dots)}
\index{make-alg@\texttt{make-alg}}
\\
&\texttt{(alg-form-to-name \textsl{alg})}
\index{alg-form-to-name@\texttt{alg-form-to-name}}
\\
&\texttt{(alg-form-to-types \textsl{alg})}
\index{alg-form-to-types@\texttt{alg-form-to-types}}
\\
&\texttt{(alg-name-to-simalg-names \textsl{alg-name})}
\index{alg-name-to-simalg-names@\texttt{alg-name-to-simalg-names}}
\\
&\texttt{(alg-name-to-token-types \textsl{alg-name})}
\index{alg-name-to-token-types@\texttt{alg-name-to-token-types}}
\\
&\texttt{(alg-name-to-typed-constr-names \textsl{alg-name})}
\index{alg-name-to-typed-constr-names@\texttt{alg-name-to-typed-constr-names}}
\\
&\texttt{(alg-name-to-tvars \textsl{alg-name})}
\index{alg-name-to-tvars@\texttt{alg-name-to-tvars}}
\\
&\texttt{(alg-name-to-arity \textsl{alg-name})}
\index{alg-name-to-arity@\texttt{alg-name-to-arity}}
\end{align*}
We also provide the tests
\begin{alignat*}{2}
&\texttt{(alg-form?\ \textsl{x})} &\quad& \text{incomplete test}
\index{alg-form?@\texttt{alg-form?}}
\\
&\texttt{(alg?\ \textsl{x})} && \text{complete test}
\index{alg?@\texttt{alg?}}
\\
&\texttt{(finalg?\ \textsl{type})} && \text{incomplete test}
\index{finalg?@\texttt{finalg?}}
\\
&\texttt{(ground-type?\ \textsl{x})} && \text{incomplete test}
\index{ground-type?@\texttt{ground-type?}}
\end{alignat*}
We require that there is at least one nullary constructor in every
free algebra; hence, it has a \inquotes{canonical inhabitant}. For
arbitrary types this need not be the case, but occasionally
(e.g.\ for general logical problems, like to prove the drinker
formula) it is useful. Therefore
\begin{align*}
&\texttt{(make-inhabited \textsl{type} \textsl{term1} \dots)}
\index{make-inhabited@\texttt{make-inhabited}}
\end{align*}
marks the optional term as the canonical inhabitant if it is provided,
and otherwise creates a new constant of that type, which is taken to
be the canonical inhabitant. We also have
\[
\texttt{(type-to-canonical-inhabitant \textsl{type})},
\]
which returns the canonical inhabitant; it is an error to apply this
procedure to a non-inhabited type. We do allow non-inhabited types to
be able to implement some aspects of
\cite{Hofmann99,AehligSchwichtenberg00}
To remove names for algebras we use
\begin{align*}
&\texttt{(remove-alg-name \textsl{name1} \dots)}
\index{remove-alg-name@\texttt{remove-alg-name}}
\end{align*}
\textbf{Examples.}
Standard examples for finitary free algebras are the type \texttt{nat}
of unary natural numbers, and the type \texttt{btree} of binary
trees. The domain $\C{I}_{\texttt{nat}}$ of unary natural
numbers is defined (as in \cite{BergerEberlSchwichtenberg03}) as a
solution to a domain equation.
We always provide the finitary free algebra \texttt{unit} consisting
of exactly one element, and \texttt{boole} of booleans; objects of
the latter type are (cf.\ loc.\ cit.)\ \texttt{true}, \texttt{false} and
families of terms of this type, and in addition the bottom object of
type \texttt{boole}.
Tests:
\begin{align*}
% &\texttt{(alg?\ \textsl{type})%
% \index{alg?@\texttt{alg?}}} \\
% %
% &\texttt{(finalg?\ \textsl{type})%
% \index{finalg?@\texttt{finalg?}}}\\
%
% &\texttt{(ground-type?\ \textsl{type})}
% \index{ground-type?@\texttt{ground-type?}}\\
&\texttt{(arrow-form?\ \textsl{type})}
\index{arrow-form?@\texttt{arrow-form?}}
\\
&\texttt{(star-form?\ \textsl{type})}
\index{star-form?@\texttt{star-form?}}
\\
&\texttt{(object-type?\ \textsl{type})}
\index{object-type?@\texttt{object-type?}}
\end{align*}
We also need constructors and accessors for arrow types
\begin{alignat*}{2}
&\texttt{(make-arrow \textsl{arg-type} \textsl{val-type})}
\index{make-arrow@\texttt{make-arrow}}
&\quad& \text{constructor}
\\
&\texttt{(arrow-form-to-arg-type \textsl{arrow-type})}
\index{arrow-form-to-arg-type@\texttt{arrow-form-to-arg-type}}
&& \text{accessor}
\\
&\texttt{(arrow-form-to-val-type \textsl{arrow-type})}
\index{arrow-form-to-val-type@\texttt{arrow-form-to-val-type}}
&& \text{accessor}
\end{alignat*}
and star types
\begin{alignat*}{2}
&\texttt{(make-star \textsl{type1} \textsl{type2})}
\index{make-star@\texttt{make-star}}
&\quad& \text{constructor}
\\
&\texttt{(star-form-to-left-type \textsl{star-type})}
\index{star-form-to-left-type@\texttt{star-form-to-left-type}}
&& \text{accessor}
\\
&\texttt{(star-form-to-right-type star-type)}
\index{star-form-to-right-type@\texttt{star-form-to-right-type}}
&& \text{accessor.}
\end{alignat*}
For convenience we also have
\begin{alignat*}{2}
&\texttt{(mk-arrow \textsl{type1} \dots\ \textsl{type})}
\index{mk-arrow@\texttt{mk-arrow}}
\\
&\texttt{(arrow-form-to-arg-types \textsl{type} <\textsl{n}>)}
\index{arrow-form-to-arg-types@\texttt{arrow-form-to-arg-types}}
&\quad& \text{all (first $n$) argument types}
\\
&\texttt{(arrow-form-to-final-val-type \textsl{type})}
\index{arrow-form-to-final-val-type@\texttt{arrow-form-to-final-val-type}}
&& \text{type of final value.}
\end{alignat*}
To check and to display a type we have
\begin{align*}
&\texttt{(type?\ \textsl{x})}
\index{type?@\texttt{type?}}
\\
&\texttt{(type-to-string \textsl{type}).}
\index{type-to-string@\texttt{type-to-string}}
\end{align*}
\textbf{Implementation.}
Type variables are implemented as lists:
\[
\texttt{(tvar \textsl{index} \textsl{name})}.
\]
\section{Variables}
\mylabel{Variables}
A variable of an object type is interpreted by a continuous functional
(object) of that type. We use the word \inquotes{variable} and not
\inquotes{program variable}, since continuous functionals are not
necessarily computable. For readable in- and output, and also for
ease in parsing, we may reserve certain strings as names for variables of
a given type, e.g.\ $\texttt{n}, \texttt{m}$ for variables of type
\texttt{nat}. Then also $\texttt{n0}, \texttt{n1}, \texttt{n2}, \dots,
\texttt{m0}, \dots$ can be used for the same purpose.
In most cases we need to argue about existing (i.e.\ total) objects
only. For the notion of totality we have to refer to \cite[Chapter
8.3]{Stoltenberg94}; particularly relevant here is exercise 8.5.7. To
make formal arguments with quantifiers relativized to total objects
more managable, we use a special sort of variables intended to range
over such objects only. For example, $\texttt{n0}, \texttt{n1},
\texttt{n2}, \dots, \texttt{m0}, \dots$ range over total natural
numbers, and $\verb#n^0#, \verb#n^1#, \verb#n^2#, \dots$ are general
variables. We say that the \emph{degree of totality}\index{degree of
totality} for the former is $1$, and for the latter $0$.
% \subsection*{Interface}
% To add and remove names for variables of a given type (e.g.\
$\texttt{n}, \texttt{m}$ for variables of type \texttt{nat}), we use
\begin{align*}
&\texttt{(add-var-name \textsl{name1} \dots\ \textsl{type})}
\index{add-var-name@\texttt{add-var-name}}
\\
&\texttt{(remove-var-name \textsl{name1} \dots\ \textsl{type})}
\index{remove-var-name@\texttt{remove-var-name}}
\\
&\texttt{(default-var-name \textsl{type}).}
\index{default-var-name@\texttt{default-var-name}}
\end{align*}
The first variable name added for any given type becomes the default
variable name. If the system creates new variables of this type, they
will carry that name. For complex types it sometimes is necessary to
talk about variables of a certain type without using a specific name.
In this case one can use the empty string to create a so called
numerated variable (see below). The parser is able to produce this
kind of canonical variables from type expressions.
We need a constructor, accessors and tests for variables.
\begin{alignat*}{2}
&\texttt{(make-var \textsl{type} \textsl{index} \textsl{t-deg} \textsl{name})} &\quad& \text{constructor}
\\
&\texttt{(var-to-type \textsl{var})} && \text{accessor}
\index{var-to-type@\texttt{var-to-type}}
\\
&\texttt{(var-to-index \textsl{var})} && \text{accessor}
\index{var-to-index@\texttt{var-to-index}}
\\
&\texttt{(var-to-t-deg \textsl{var})} && \text{accessor}
\index{var-to-t-deg@\texttt{var-to-t-deg}}
\\
&\texttt{(var-to-name \textsl{var})} && \text{accessor}
\index{var-to-name@\texttt{var-to-name}}
\\
&\texttt{(var-form?\ \textsl{x})} && \text{incomplete test}
\index{var-form?@\texttt{var-form?}}
\\
&\texttt{(var?\ \textsl{x}).} && \text{complete test}
\index{var?@\texttt{var?}}
\end{alignat*}
It is guaranteed that \texttt{equal?} is a valid test for equality of
variables. Moreover, it is guaranteed that parsing a displayed
variable reproduces the variable; the converse need not be the case
(we may want to convert it into some canonical form).
For convenience we have the function
\begin{alignat*}{2}
&\texttt{(mk-var \textsl{type} <\textsl{index}> <\textsl{t-deg}>
<\textsl{name}>).}
\index{mk-var@\texttt{mk-var}}
\end{alignat*}
The type is a required argument; however, the remaining arguments are
optional. The default for the name string is the value returned by
\begin{alignat*}{2}
&\texttt{(default-var-name \textsl{type})}
\index{default-var-name@\texttt{default-var-name}}
\end{alignat*}
If there is no default name, a numerated variable is created. The
default for the totality is \inquotes{total}.
Using the empty string as the name, we can create so called numerated
variables. We further require that we can test whether a given
variable belongs to those special ones, and that from every numerated
variable we can compute its index:
\begin{align*}
&\texttt{(numerated-var?\ \textsl{var})}
\index{numerated-var?@\texttt{numerated-var}}
\\
&\texttt{(numerated-var-to-index \textsl{numerated-var}).}
\index{numerated-var-to-index@\texttt{numerated-var-to-index}}
\end{align*}
It is guaranteed that \texttt{make-var} used with the empty name string
is a bijection
\[
\Types \times \D{N} \times \TDegs \to \NumVars
\]
with inverses \texttt{var-to-type}, \texttt{numerated-var-to-index}
and \texttt{var-to-t-deg}.
% \footnote{Here equality is to be understood as equality for the
% respective \inquotes{types}, e.g.\ the first equation is to be understood as
% % {\tt
% (equal-vars?\
% (type-and-index-to-var
% (var-to-type numerated-var)
% (numerated-var-to-index numerated-var))
% numerated-var)
% }
% % is a truth value for every scheme object {\tt numerated-var} such that
% {\tt (numerated-var?\ numerated-var)} is a truth value.
% }% :
% % \begin{verbatim}
% (type-and-index-to-var
% (var-to-type numerated-var)
% (numerated-var-to-index numerated-var)) = numerated-var
% (var-to-type (type-and-index-to-var type index)) = type
% (numerated-var-to-index
% (type-and-index-to-var type index)) = index
% (numerated-var?\ (type-and-index-to-var type index)) = }t
% \end{verbatim}
Although these functions look like an ad hoc extension of the
interface that is convenient for normalization by evaluation, there is
also a deeper background: these functions can be seen as the
\inquotes{computational content} of the well-known phrase \inquotes{we
assume that there are infinitely many variables of every type}.
Giving a constructive proof for this statement would require to give
infinitely many examples of variables for every type. This of course
can only be done by specifying a function (for every type) that
enumerates these examples. To make the specification finite we
require the examples to be given in a uniform way, i.e.\ by a function
of two arguments. To make sure that all these examples are in fact
different, we would have to require \texttt{make-var} to
be injective. Instead, we require (classically equivalent)
\texttt{make-var} to be a bijection on its image, as
again, this can be turned into a computational statement by requiring
that a witness (i.e.\ an inverse function) is given.
Finally, as often the exact knowledge of infinitely many variables of
every type is not needed we require that, either by using the above
functions or by some other form of definition, functions
\begin{align*}
&\texttt{(type-to-new-var \textsl{type})}
\index{type-to-new-var@\texttt{type-to-new-var}}
\\
&\texttt{(type-to-new-partial-var \textsl{type})}
\index{type-to-new-partial-var@\texttt{type-to-new-partial-var}}
\end{align*}
are defined that return a (total or partial) variable of the requested
type, different from all variables that have ever been returned by any
of the specified functions so far.
Occasionally we may want to create a new variable with the same name
(and degree of totality) as a given one. This is useful e.g.\ for
bound renaming. Therefore we supply
\begin{align*}
&\texttt{(var-to-new-var \textsl{var}).}
\index{var-to-new-var@\texttt{var-to-new-var}}
\end{align*}
\textbf{Implementation.}
Variables are implemented as lists:
\[
\texttt{(var \textsl{type} \textsl{index} \textsl{t-deg} \textsl{name})}.
\]
\section{Constants}
\mylabel{Pconst}
Every constant (or more precisely, object constant) has a type and
denotes a computable (hence continuous) functional of that type. We
have the following three kinds of constants:
\begin{itemize}
\item constructors, kind \texttt{constr},
\item constants with user defined rules (also called program(mable)
constant, or pconst), kind \texttt{pconst},
\item constants whose rules are fixed, kind \texttt{fixed-rules}.
\end{itemize}
The latter are built into the system: recursion operators for
arbitrary algebras, equality and existence operators for finitary
algebras, and existence elimination. They are typed in parametrized
form, with the actual type (or formula) given by a type (or type and
formula) substitution that is also part of the constant. For
instance, equality is typed by $\alpha \to \alpha \to \boole$ and a
type substitution $\alpha \mapsto \rho$. This is done for clarity
(and brevity, e.g.\ for large $\rho$ in the example above), since one
should think of the type of a constant in this way.
For constructors and for constants with fixed rules, by efficiency
reasons we want to keep the object denoted by the constant (as needed
for normalization by evaluation) as part of it. It depends on the
type of the constant, hence must be updated in a given proof whenever
the type changes by a type substitution.
\subsection{Rewrite and computation rules for program constants}
\mylabel{SS:RewCompRules}
For every program constant $c^\rho$ we assume that some rewrite rules
of the form $c\vec{K} \cnv N$ are given, where $\FV(N) \subseteq
\FV(\vec{K})$ and $c\vec{K}$, $N$ have the same type (not necessarily
a ground type). Moreover, for any two rules $c\vec{K} \cnv N$ and
$c\vec{K}' \cnv N'$ we require that $\vec{K}$ and $\vec{K}'$ are of
the same length, called the \emph{arity}\index{arity!of a program
constant} of $c$. The rules are divided into \emph{computation
rules}\index{computation rule} and proper \emph{rewrite
rules}\index{rewrite rule}. They must satisfy the requirements listed
in \cite{BergerEberlSchwichtenberg03}. The idea is that a computation
rule can be understood as a description of a computation in a suitable
\emph{semantical} model, provided the syntactic constructors
correspond to semantic ones in the model, whereas the other rules
describe \emph{syntactic} transformations.
There a more general approach was used: one may enter into components
of products. Then instead of one arity one needs several
\inquotes{type informations} $\vec{\rho} \to \sigma$ with $\vec{\rho}$
a list of types, $0$'s and $1$'s indicating the left or right part of
a product type. For example, if $c$ is of type $\tau \to (\tau \to
\tau \to \tau) \times (\tau \to \tau)$, then the rules $cy0xx \cnv a$
and $cy1 \cnv b$ are admitted, and $c$ comes with the type
informations $(\tau,0,\tau,\tau \to \tau) \to \tau$ and $(\tau,1) \to
(\tau \to \tau)$. -- However, for simplicity we only deal with a
single arity here.
Given a set of rewrite rules, we want to treat some rules - which we
call \indexentry{computation rules} - in a different, more efficient
way. The idea is that a computation rule can be understood as a
description of a computation in a suitable
\indexentry{semantical model}, provided the syntactic constructors
correspond to semantic ones in the model, whereas the other rules
describe \emph{syntactic} transformations.
In order to define what we mean by computation rules, we need the
notion of a \indexentry{constructor pattern}. These are special terms
defined inductively as follows.
\begin{itemize}
\item Every variable is a constructor pattern.
\item If $c$ is a constructor and $P_1,\dots,P_n$ are constructor
patterns (or projection markers 0 or 1), such that $c \vec{P}$ is of
ground type, then $c\vec{P}$ is a constructor pattern.
\end{itemize}
From the given set of rewrite rules we choose a subset $\Comp$
with the following properties.
\begin{itemize}
\item If $c\vec{P} \cnv Q \in \Comp$, then $P_1,\dots,P_n$ are constructor
patterns or projection markers.
\item The rules are left-linear, i.e.\ if $c\vec{P} \cnv Q \in \Comp$,
then every variable in $c\vec{P}$ occurs only once in $c\vec{P}$.
\item The rules are non-overlapping, i.e.~for different rules
$c\vec{K}\cnv M$ and $c\vec{L}\cnv N$ in $\Comp$ the left hand sides
$c\vec{K}$ and $c\vec{L}$ are non-unifiable.
\end{itemize}
We write $c\vec{M} \cnv_{\comp} Q$ to indicate that the rule is in
$\Comp$. All other rules will be called (proper) rewrite rules,
written $c\vec{M} \cnv_{\rew} K$.
In our reduction strategy computation rules will always be applied
first, and since they are non-overlapping, this part of the reduction
is unique. However, since we allowed almost arbitrary rewrite rules,
it may happen that in case no computation rule applies a term may be
rewritten by different rules $\notin \Comp$. In order to obtain a
deterministic procedure we then select the first applicable rewrite rule
(This is a slight simplification of \cite{BergerEberlSchwichtenberg03},
where special functions $\select_c$ were used for this purpose).
\subsection{Recursion over simultaneous free algebras}
\mylabel{SS:RecSFA}
We now explain what we mean by recursion\index{recursion} over
simultaneous free algebras. The inductive structure of the types
$\vec{\mu} = \mu\vec{\alpha}\,\vec{\kappa}$ corresponds to two sorts
of constants. With the \emph{constructors} $\constr_i^{\vec{\mu}}
\colon \kappa_i[\vec{\mu}]$ we can construct elements of a type
$\mu_j$, and with the \emph{recursion operators}\index{recursion
operator} $\rec_{\mu_j}^{\vec{\mu}, \vec{\tau}}$ we can construct
mappings from $\mu_j$ to $\tau_j$ by recursion on the structure of
$\vec{\mu}$. So in \texttt{(Rec arrow-types)},
\texttt{arrow-types} is a list $\mu_1 \to \tau_1, \dots, \mu_k \to
\tau_k$. Here $\mu_1, \dots, \mu_k$ are the algebras defined
simultaneously and $\tau_1, \dots, \tau_k$ are the result types.
For convenience in our later treatment of proofs (when we want to
normalize a proof by (1) translating it into a term, (2) normalizing
this term and (3) translating the normal term back into a proof), we
also allow all-formulas $\forall x_1^{\mu_1} A_1, \dots, \forall
x_k^{\mu_k} A_k$ instead of \texttt{arrow-types}: they are treated as
$\mu_1 \to \tau(A_1)$, \dots, $\mu_k \to \tau(A_k)$ with $\tau(A_j)$
the type of $A_j$.
Recall the definition of types and constructor types in
Section~\ref{S:Types}, and the examples given there. In order to define
the type of the recursion operators w.r.t.\ $\vec{\mu} =
\mu\vec{\alpha}\, \vec{\kappa}$ and result types $\vec{\tau}$, we
first define for
\[
\kappa_i = \vec{\rho} \to (\vec{\sigma}_1 \to \alpha_{j_1}) \to \dots \to
(\vec{\sigma}_n \to \alpha_{j_n}) \to \alpha_j \in
\constrtypes(\vec{\alpha})
\]
the \emph{step type}
\begin{align*}
\ST_i^{\vec{\mu}, \vec{\tau}} := \vec{\rho} \to
&(\vec{\sigma}_1 \to \mu_{j_1}) \to \dots \to
(\vec{\sigma}_n \to \mu_{j_n}) \to
\\
&(\vec{\sigma}_1 \to \tau_{j_1}) \to \dots \to
(\vec{\sigma}_n \to \tau_{j_n}) \to \tau_j.
\end{align*}
Here $\vec{\rho}, (\vec{\sigma}_1 \to \mu_{j_1}), \dots,
(\vec{\sigma}_n \to \mu_{j_n})$ correspond to the \emph{components}
% (or \emph{parameters})
of the object of type $\mu_j$ under
consideration, and $(\vec{\sigma}_1 \to \tau_{j_1}), \dots,
(\vec{\sigma}_n \to \tau_{j_n})$ to the previously defined values.
The recursion operator $\rec_{\mu_j}^{\vec{\mu}, \vec{\tau}}$ has type
\[
\rec_{\mu_j}^{\vec{\mu}, \vec{\tau}} \colon
\ST_1^{\vec{\mu}, \vec{\tau}} \to \dots \to \ST_k^{\vec{\mu}, \vec{\tau}}
\to \mu_j \to \tau_j.
\]
We will often write $\rec_j^{\vec{\mu}, \vec{\tau}}$ for
$\rec_{\mu_j}^{\vec{\mu}, \vec{\tau}}$, and omit the upper indices
$\vec{\mu}, \vec{\tau}$ when they are clear from the context. In case
of a non-simultaneous free algebra, i.e.\ of type $\mu
\alpha\,(\kappa)$, for $\rec_\mu^{\mu, \tau}$ we normally write
$\rec_\mu^\tau$.
A simple example for simultaneous free algebras is
\[
(\tree, \tlist) := \mu (\alpha,\beta)\,
(\alpha, \beta \to \alpha, \beta, \alpha \to \beta \to \beta).
\]
The constructors are
\begin{align*}
&\leaf^{\tree} := \constr_1^{(\tree, \tlist)},
\\
&\branch^{\tlist \to \tree} := \constr_2^{(\tree, \tlist)},
\\
&\empt^{\tlist} := \constr_3^{(\tree, \tlist)},
\\
&\tcons^{\tree \to \tlist \to \tlist} := \constr_4^{(\tree, \tlist)}.
\end{align*}
An example for a recursion constant is
\begin{alignat*}{2}
&\texttt{(const Rec $\delta_1 \to \delta_2 \to \delta_3 \to \delta_4 \to
\tree \to \alpha_1$}
\\
&\qquad \qquad \qquad
\texttt{$(\alpha_1 \mapsto \tau_1, \alpha_2 \mapsto \tau_2)$)}
\index{Rec@\texttt{Rec}}
\\
\intertext{with}
&\delta_1 := \alpha_1,
\\
&\delta_2 := \tlist \to \alpha_2 \to \alpha_1,
\\
&\delta_3 := \alpha_2,
\\
&\delta_4 := \tree \to \tlist \to \alpha_1 \to \alpha_2 \to \alpha_2.
\end{alignat*}
Here the fact that we deal with a simultaneous recursion (over
\texttt{tree} and \texttt{tlist}), and that we define a constant of
type $\tree \to \dots$, can all be inferred from what is given: the
type $\tree \to \dots$ is right there, and for \texttt{tlist} we can
look up the simultaneously defined algebras.
For the external representation (i.e.\ display) we use the shorter
notation
\[
\texttt{(Rec $\tree \to \tau_1$ $\tlist \to \tau_2$)}.
\]
% $$\texttt{(Rec $\tree \to \alpha_1$ $\tlist \to \alpha_2$ $(\alpha_1
% \mapsto \tau_1, \alpha_2 \mapsto \tau_2)$)}.$$
% A simplified version (without the recursive calls) of the recursion
% operator is the following generalized if-then-else operator.
% \begin{alignat*}{2}
% % &\texttt{(const If $\alpha_1 \to \alpha_1 \to \tree \to \alpha_1$
% $(\alpha_1 \mapsto \tau_1)$).}
% \index{If@\texttt{If}}
% % \end{alignat*}
% A shorter notation would be $\texttt{(if-at $\tree \to \tau_1$)}$, but
% again we prefer the more systematic one above.
As already mentioned, it is also possible that the object constant
\texttt{Rec} comes with formulas instead of types, as the assumption
constant \texttt{Ind} below. This is due to our desire not to
duplicate code when normalizing proofs, but rather translate the proof
into a term first, normalize the term and then translate back into a
proof. For the last step we must have the original formulas of the
induction operator available.
To see a concrete example, let us recursively define addition $+
\colon \tree \to \tree \to \tree$ and $\oplus \colon \tlist \to \tree
\to \tlist$. The recursion equations to be satisfied are
\begin{alignat*}{2}
&+\,\leaf &&= \lambda a a,
\\
&+(\branch\,\bs) &&= \lambda a.\branch(\oplus\,\bs\,a),\\[6pt]
&\oplus\,\empt &&= \lambda a\,\empt,
\\
&\oplus(\tcons\,b\,\bs) &&= \lambda a.\tcons(+\,b\,a)(\oplus\,\bs\,a).
\end{alignat*}
We define $+$ and $\oplus$ by means of the recursion operators
$\rec_{\tree}$ and
$\rec_{\tlist}$ with result types
\begin{align*}
\tau_1 &:= \tree \to \tree,
\\
\tau_2 &:= \tree \to \tlist.
\end{align*}
The step terms are
\begin{align*}
M_1 &:= \lambda a a,
\\
M_2 &:= \lambda \bs \lambda g^{\tau_2} \lambda a.\branch(g\,a),
\\
M_3 &:= \lambda a\,\empt,
\\
M_4 &:= \lambda b \lambda \bs \lambda f^{\tau_1} \lambda g^{\tau_2} \lambda a.
\tcons(f\,a)(g\,a).
\end{align*}
Then
\begin{align*}
+ &:= \rec_{\tree} \vec{M} \colon
\tree \to \tree \to \tree,
\\
\oplus &:= \rec_{\tlist} \vec{M} \colon
\tlist \to \tree \to \tlist.
\end{align*}
To explain the \emph{conversion relation}\index{conversion relation},
it will be useful to employ the following notation. Let
$\vec{\mu} = \mu \vec{\alpha}\,\vec{\kappa}$,
\[
\kappa_i = \rho_1 \to \dots \to \rho_m \to
(\vec{\sigma}_1 \to \alpha_{j_1}) \to \dots \to
(\vec{\sigma}_n \to \alpha_{j_n}) \to \alpha_j \in
\constrtypes(\vec{\alpha}),
\]
and consider $\constr_i^{\vec{\mu}} \vec{N}$. Then we write
$\vec{N}^P = N_1^P, \dots, N_m^P$ for the \emph{parameter arguments}
$N_1^{\rho_1}, \dots, N_m^{\rho_m}$ and $\vec{N}^R = N_1^R, \dots,
N_n^R$ for the \emph{recursive arguments} $N_{m+1}^{\vec{\sigma}_1 \to
\mu_{j_1}}, \dots, N_{m+n}^{\vec{\sigma}_n \to \mu_{j_n}}$, and
$n^R$ for the number $n$ of recursive arguments.
We define a \emph{conversion relation} $\cnv_\rho$ between terms of
type $\rho$ by
\begin{align}
(\lambda xM)N &\cnv \subst{M}{x}{N}\label{betaconv}
\\
\lambda x.Mx &\cnv M\quad\hbox{if $x \notin \FV(M)$,
$M$ not an abstraction}\label{etaconv}
\\
(\rec_j^{\vec{\mu}, \vec{\tau}} \vec{M})^{\mu_j \to \tau_j}
(\constr_i^{\vec{\mu}} \vec{N}) &\cnv
M_i \vec{N}
\bigl( (\rec_{j_1}^{\vec{\mu}, \vec{\tau}} \vec{M}) \circ N_1^R\bigr) \dots
\bigl( (\rec_{j_n}^{\vec{\mu}, \vec{\tau}} \vec{M}) \circ N_n^R\bigr)
\label{recconv}
\end{align}
Here we have written $\rec_j^{\vec{\mu}, \vec{\tau}}$ for
$\rec_{\mu_j}^{\vec{\mu}, \vec{\tau}}$, and $\circ$ means composition.
\subsection{Internal representation of constants}
Every object constant has the internal representation
\begin{align*}
\texttt{(const\ }
&\hbox{ \textsl{object-or-arity} \textsl{name} \textsl{uninst-type-or-formula}
\textsl{subst}}
\\
&\hbox{\textsl{t-deg} \textsl{token-type}
\textsl{arrow-types-or-repro-formulas}\texttt{)},}
\end{align*}
where \textsl{subst} may have type, object and assumption variables in
its domain. The type of the constant is the result of carrying out
this substitution in \textsl{uninst-type-or-formula} (if this is a
type; otherwise first substitute and then convert the formula into a
type); free type variables may again occur in this type. Note that a
formula will occur if \textsl{name} is \texttt{Ex-Intro} or
\texttt{Ex-Elim}, and may occur if it is \texttt{Rec}.
Examples for object constants are
\begin{alignat*}{2}
&\texttt{(const Compose $(\alpha {\to} \beta) {\to} (\beta {\to} \gamma) {\to}
\alpha {\to} \gamma$
$(\alpha \mapsto \rho, \beta \mapsto \sigma, \gamma \mapsto \tau)$ \dots)}
\index{Compose@\texttt{Compose}}
\\
&\texttt{(const Eq $\alpha \to \alpha \to \boole$
$(\alpha \mapsto \textsl{finalg})$ \dots)}
\index{Eq@\texttt{Eq}}
\\
&\texttt{(const E $\alpha \to \boole$
$(\alpha \mapsto \textsl{finalg} \dots)$)}
\index{E@\texttt{E}}
\\
&\texttt{(const Ex-Elim $\ex x^\alpha P(x) \to (\forall x^\alpha. P(x)
\to Q) \to Q$}
\\
&\qquad\qquad\qquad\quad \texttt{$(\alpha \mapsto \tau, P^{(\alpha)}
\mapsto \set{z^\tau}{A}, Q \mapsto \set{}{B})$ \dots)}
\index{Ex-Elim@\texttt{Ex-Elim}}
\end{alignat*}
\textsl{object-or-arity} is an object if this object cannot be
changed, e.g.\ by allowing user defined rules for the constant;
otherwise, the associated object needs to be updated whenever a new
rule is added, and we have the arity of those rules instead. The
rules are of crucial importance for the correctness of a proof, and
should not be invisibly buried in the denoted object taken as part of
the constant (hence of any term involving it). Therefore we keep the
rules of a program constant and also its denoted objects (depending on
type substitutions) at a central place, a global variable
\texttt{PROGRAM-CONSTANTS} which assigns to every name of such a
constant the constant itself (with uninstantiated type), the rules
presently chosen for it and also its denoted objects (as association
list with type substitutions as keys). When a new rule has been
added, the new objects for the program constant are computed, and the
new list to be associated with the program constant is written in
\texttt{PROGRAM-CONSTANTS} instead. All information on a program
constant exept its denoted object and its computation and rewrite
rules (i.e.\ its type, degree of totality, arity and token type) is
stable and hence can be kept as part of it. The \emph{token
type}\index{token type} can be either \texttt{const} (i.e.\ constant
written as application) or one of: \texttt{postfix-op},
\texttt{prefix-op}, \texttt{binding-op}, \texttt{add-op},
\texttt{mul-op}, \texttt{rel-op}, \texttt{and-op}, \texttt{or-op},
\texttt{imp-op} and \texttt{pair-op}.
Constructor, accessors and tests for all kinds of constants:
\begin{alignat*}{2}
&\texttt{(make-const \textsl{obj-or-arity} \textsl{name} \textsl{kind}
\textsl{uninst-type} \textsl{tsubst}}
\\
&\quad \texttt{\textsl{t-deg} \textsl{token-type}
. \textsl{arrow-types-or-repro-formulas})}%
\index{make-const@\texttt{make-const}}
% &\quad& \text{constructor}
\\
&\texttt{(const-to-object-or-arity \textsl{const})}%
\index{const-to-object-or-arity@\texttt{const-to-object-or-arity}}
% && \text{accessor}
\\
&\texttt{(const-to-name \textsl{const})}%
\index{const-to-name@\texttt{const-to-name}}
% && \text{accessor}
\\
&\texttt{(const-to-kind \textsl{const})}%
\index{const-to-kind@\texttt{const-to-kind}}
% && \text{accessor}
\\
&\texttt{(const-to-uninst-type \textsl{const})}%
\index{const-to-uninst-type@\texttt{const-to-uninst-type}}
% && \text{accessor}
\\
&\texttt{(const-to-tsubst \textsl{const})}%
\index{const-to-tsubst@\texttt{const-to-tsubst}}
% && \text{accessor}
\\
&\texttt{(const-to-t-deg \textsl{const})}%
\index{const-to-t-deg@\texttt{const-to-t-deg}}
% && \text{accessor}
\\
&\texttt{(const-to-token-type \textsl{const})}%
\index{const-to-token-type@\texttt{const-to-token-type}}
% && \text{accessor}
\\
&\texttt{(const-to-arrow-types-or-repro-formulas \textsl{const})}%
\index{const-to-arrow-types-or-repro-formulas@\texttt{const-to-arrow-types-or{\dots}}}
% && \text{accessor}
\\
&\texttt{(const?\ \textsl{x})}%
\index{const?@\texttt{const?}}
% && \text{test}
\\
&\texttt{(const=?\ \textsl{x} \textsl{y})}
\index{const=?@\texttt{const=?}}
% && \text{test.}
\end{alignat*}
The type substitution \textsl{tsubst} must be restricted to the type
variables in \texttt{uninst-type}.
\texttt{arrow-types-or-repro-formulas} are only present for the
\texttt{Rec} constants. They are needed for the reproduction case.
From these we can define
\begin{alignat*}{2}
&\texttt{(const-to-type \textsl{const})}%
\index{const-to-type@\texttt{const-to-type}}
\\
&\texttt{(const-to-tvars \textsl{const})}%
\index{const-to-tvars@\texttt{const-to-tvars}}
\end{alignat*}
A \emph{constructor}\index{constructor} is a special constant with no
rules. We maintain an association list \texttt{CONSTRUCTORS}
assigning to every name of a constructor an association list
associating with every type substitution (restricted to the type
parameters) the corresponding instance of the constructor. We provide
\begin{alignat*}{2}
&\texttt{(constr-name? \textsl{string})}%
\index{constr-name?@\texttt{constr-name?}}
\\
&\texttt{(constr-name-to-constr \textsl{name} <\textsl{tsubst}>)}%
\index{constr-name-to-constr@\texttt{constr-name-to-constr}}
\\
&\texttt{(constr-name-and-tsubst-to-constr \textsl{name} \textsl{tsubst})}%
\index{constr-name-and-tsubst-to-constr@\texttt{constr-name-and-tsubst{\dots}}},
\end{alignat*}
where in \texttt{(constr-name-to-constr \textsl{name}
<\textsl{tsubst}>)}, \textsl{name} is a string or else of the
form \texttt{(Ex-Intro \textsl{formula})}. If the optional
\textsl{tsubst} is not present, the empty substitution is used.
For given algebras one can display the associated constructors with their
types by calling
\begin{alignat*}{2}
&\texttt{(display-constructors \textsl{alg-name1} \dots)}%
\index{display-constructors@\texttt{display-constructors}}.
\end{alignat*}
We also need procedures recovering information from the string denoting
a program constant (via \texttt{PROGRAM-CONSTANTS}):
\begin{alignat*}{2}
&\texttt{(pconst-name-to-pconst \textsl{name})}%
\index{pconst-name-to-pconst@\texttt{pconst-name-to-pconst}}
\\
&\texttt{(pconst-name-to-comprules \textsl{name})}%
\index{pconst-name-to-comprules@\texttt{pconst-name-to-comprules}}
\\
&\texttt{(pconst-name-to-rewrules \textsl{name})}%
\index{pconst-name-to-rewrules@\texttt{pconst-name-to-rewrules}}
\\
&\texttt{(pconst-name-to-inst-objs \textsl{name})}%
\index{pconst-name-to-inst-objs@\texttt{pconst-name-to-inst-objs}}
\\
&\texttt{(pconst-name-and-tsubst-to-object \textsl{name} \textsl{tsubst})}%
% \index{pconst-name-and-tsubst-to-object@\texttt{pconst-name-and-tsubst-to-object}}
\\
&\texttt{(pconst-name-to-object \textsl{name})}%
\index{pconst-name-to-object@\texttt{pconst-name-to-object}}.
\end{alignat*}
One can display the program constants together with their current
computation and rewrite rules by calling
\begin{alignat*}{2}
&\texttt{(display-program-constants \textsl{name1} \dots)}%
\index{display-program-constants@\texttt{display-program-constants}}.
\end{alignat*}
To add and remove program constants we use
\begin{align*}
&\texttt{(add-program-constant \textsl{name} \textsl{type} <\textsl{rest}>)}
\index{add-program-constant@\texttt{add-program-constant}}
\\
&\texttt{(remove-program-constant \textsl{symbol})};
\index{remove-program-constant@\texttt{remove-program-constant}}
\end{align*}
\textsl{rest} consists of an initial segment of the following list:
\texttt{t-deg} (default $0$), \texttt{token-type} (default
\texttt{const}) and \texttt{arity} (default maximal number of argument
types).
To add and remove computation and rewrite rules we have
\begin{align*}
&\texttt{(add-computation-rule \textsl{lhs} \textsl{rhs})}
\index{add-computation-rule@\texttt{add-computation-rule}}
\\
&\texttt{(add-rewrite-rule \textsl{lhs} \textsl{rhs})}
\index{add-rewrite-rule@\texttt{add-rewrite-rule}}
\\
&\texttt{(remove-computation-rules-for \textsl{lhs})}
\index{remove-computation-rules-for@\texttt{remove-computation-rules-for}}
\\
&\texttt{(remove-rewrite-rules-for \textsl{lhs}).}
\index{remove-rewrite-rules-for@\texttt{remove-rewrite-rules-for}}
\end{align*}
To generate our constants with fixed rules we use
\begin{alignat*}{2}
&\texttt{(finalg-to-=-const \textsl{finalg})}
\index{finalg-to-=-const@\texttt{finalg-to-=-const}}
&\quad& \text{equality}
\\
&\texttt{(finalg-to-e-const \textsl{finalg})}
\index{finalg-to-e-const@\texttt{finalg-to-e-const}}
&& \text{existence}
\\
&\texttt{(arrow-types-to-rec-const .\ \textsl{arrow-types})}
\index{arrow-types-to-rec-const@\texttt{arrow-types-to-rec-const}}
&& \text{recursion}
\\
&\texttt{(ex-formula-and-concl-to-ex-elim-const }
\\
&\texttt{\qquad \textsl{ex-formula}
\textsl{concl})}%
\index{ex-formula-and-concl-to-ex-elim-const@\texttt{ex-for{\dots}-to-ex-elim-const}}
\end{alignat*}
Similarly to \texttt{arrow-types-to-rec-const} we also define the
procedure \texttt{all-formulas-to-rec-const}. It will be used in to
achieve normalization of proofs via translating them in terms.
[Noch einf\"ugen: \texttt{arrow-types-to-cases-const} und zur
Behandlung von Beweisen \texttt{all-formulas-to-cases-const}]
\section{Predicate variables and constants}
\mylabel{S:Psyms}
\subsection{Predicate variables}
\mylabel{SS:PredVars}
A predicate variable of arity\index{arity!of a predicate variable}
$\rho_1, \dots, \rho_n$ is a placeholder for a formula $A$
with distinguished (different) variables $x_1, \dots, x_n$ of types
$\rho_1, \dots, \rho_n$. Such an entity is called a
\indexentry{comprehension term}, written $\set{x_1, \dots, x_n}{A}$.
% We also allow predicate constants
% with a fixed intended meaning (e.g.\ $\bot$\index{bottom}). Predicate
% variables and constants are both called predicate symbols.
Predicate variable names are provided in the form of an association
list, which assigns to the names their arities. By default we have
the predicate variable \texttt{bot}\index{bottom} of arity
\texttt{(arity)}, called (logical) falsity. It is viewed as a
predicate variable rather than a predicate constant, since (when
translating a classical proof into a constructive one) we want to
substitute for \texttt{bot}.
Often we will argue about \emph{Harrop formulas}\index{Harrop formula}
only, i.e.\ formulas without computational content. For convenience
we use a special sort of predicate variables intended to range over
comprehension terms with Harrop formulas only. For example,
$\texttt{P0}, \texttt{P1}, \texttt{P2}, \dots, \texttt{Q0}, \dots$
range over comprehension terms with Harrop formulas, and $\verb#P^0#,
\verb#P^1#, \verb#P^2#, \dots$ are general predicate variables. We
say that \emph{Harrop degree}\index{Harrop degree} for the former is
$1$, and for the latter $0$.
% \subsection*{Interface}
We need constructors and accessors for arities
\begin{align*}
&\texttt{(make-arity \textsl{type1} \dots)}
\index{make-arity@\texttt{make-arity}}
\\
&\texttt{(arity-to-types \textsl{arity})}
\index{arity-to-types@\texttt{arity-to-types}}
\end{align*}
To display an arity we have
\[
\texttt{(arity-to-string \textsl{arity})}
\index{arity-to-string@\texttt{arity-to-string}}
\]
We can test whether a string is a name for a predicate variable, and
if so compute its associated arity:
\begin{align*}
&\texttt{(pvar-name?\ \textsl{string})}
\index{pvar-name?@\texttt{pvar-name?}}
\\
&\texttt{(pvar-name-to-arity \textsl{pvar-name})}
\index{pvar-name-to-arity@\texttt{pvar-name-to-arity}}
\end{align*}
To add and remove names for predicate variables of a given arity
(e.g.\ $\texttt{Q}$ for predicate variables of arity \texttt{nat}), we
use
\begin{align*}
&\texttt{(add-pvar-name \textsl{name1} \dots\ \textsl{arity})}%
\index{add-pvar-name@\texttt{add-pvar-name}}
\\
&\texttt{(remove-pvar-name \textsl{name1} \dots)}%
\index{remove-pvar-name@\texttt{remove-pvar-name}}
\end{align*}
We need a constructor, accessors and tests for predicate variables.
% Note that the arity is not necessary as an argument for
% \texttt{make-pvar}, since it can be read off from
% \texttt{pvar-name}.
\begin{alignat*}{2}
&\texttt{(make-pvar \textsl{arity} \textsl{index} \textsl{h-deg}
\textsl{name})}
\index{make-pvar@\texttt{make-pvar}}
&\quad& \text{constructor}
\\
&\texttt{(pvar-to-arity \textsl{pvar})}
\index{pvar-to-arity@\texttt{pvar-to-arity}}
&& \text{accessor}
\\
&\texttt{(pvar-to-index \textsl{pvar})}
\index{pvar-to-index@\texttt{pvar-to-index}}
&& \text{accessor}
\\
&\texttt{(pvar-to-h-deg \textsl{pvar})}
\index{pvar-to-h-deg@\texttt{pvar-to-h-deg}}
&& \text{accessor}
\\
&\texttt{(pvar-to-name \textsl{pvar})}
\index{pvar-to-name@\texttt{pvar-to-name}}
&& \text{accessor}
\\
&\texttt{(pvar?\ \textsl{x})}
\index{pvar?@\texttt{pvar?}}
\\
&\texttt{(equal-pvars?\ \textsl{pvar1} \textsl{pvar2})}
\index{equal-pvars?@\texttt{equal-pvars?}}
\end{alignat*}
For convenience we have the function
\begin{alignat*}{2}
&\texttt{(mk-pvar \textsl{arity} <\textsl{index}> <\textsl{h-deg}>
<\textsl{name}>)}
\end{alignat*}
The arity is a required argument; the remaining arguments are
optional. The default for \textsl{index} is $-1$, for \textsl{h-deg}
is $1$ (i.e.\ Harrop-formula) and for \textsl{name} it is given by
\texttt{(default-pvar-name \textsl{arity})}.
It is guaranteed that parsing a displayed predicate variable
reproduces the predicate variable; the converse need not be the case
(we may want to convert it into some canonical form).
\subsection{Predicate constants}
\mylabel{SS:PredConsts}
We also allow \emph{predicate constants}\index{predicate constant}.
The general reason for having them is that we need predicates to be
axiomatized, e.g.\ \texttt{Equal} and \texttt{Total} (which are
\emph{not} placeholders for formulas). Prime formulas built from
predicate constants do not give rise to extracted terms, and cannot be
substituted for.
Notice that a predicate constant does not change its name under a type
substitution; this is in contrast to predicate (and other) variables.
Notice also that the parser can infer from the arguments the types
$\rho_1 \dots \rho_n$ to be substituted for the type variables in the
uninstantiated arity of $P$.
% Discarded 01-08-20
% We also allow \indexentry{predicate constants}; they are viewed as
% constants with fixed rules. For equality \texttt{Eq} and existence
% \texttt{Ex} there are such rules (e.g.\ $x=x \cnv T$), but for
% predicate constants intended to be axiomatized there are no such
% rules. The need for predicate constants comes up when e.g.\ an
% inductively defined set is expressed via a formula stating the
% existence of a generation tree; the kernel of this formula is to be
% axiomatized, using the tree constructors. Since predicate constants
% are constants with fixed rules, they do not give rise to extracted
% terms, and cannot be substituted for.
% A predicate constant does not change its name under a type
% substitution; this is in contrast to predicate (and other) variables.
% To enable the parser to infer its type, generally a predicate constant
% is to be displayed in the form $(P \rho_1 \dots \rho_n)$, where
% $\rho_1 \dots \rho_n$ are the types to be substituted for the type
% variables in the uninstantiated type of $P$. However, quite often the
% type substitution can be inferred by the parser from the types of the
% arguments. This is the case e.g.\ for equality and existence, where
% we can parse $x^{\alpha} = x^{\alpha}$ and $E x$ as well as $n^{\nat}
% = n^{\nat}$ and $E n$. This happens quite regularly for all constants
% whose type involves type variables (i.e.\ of token type
% \texttt{constscheme} rather than \texttt{const}).
% \subsection*{Interface}
%
To add and remove names for predicate constants of a given arity, we
use
\begin{align*}
&\texttt{(add-predconst-name \textsl{name1} \dots\ \textsl{arity})}%
\index{add-predconst-name@\texttt{add-predconst-name}}
\\
&\texttt{(remove-predconst-name \textsl{name1} \dots)}%
\index{remove-predconst-name@\texttt{remove-predconst-name}}
\end{align*}
We need a constructor, accessors and tests for predicate constants.
\begin{alignat*}{2}
&\texttt{(make-predconst \textsl{uninst-arity} \textsl{tsubst} \textsl{index}
\textsl{name})}
\index{make-predconst@\texttt{make-predconst}}
&\quad& \text{constructor}
\\
&\texttt{(predconst-to-uninst-arity \textsl{predconst})}
\index{predconst-to-uninst-arity@\texttt{predconst-to-uninst-arity}}
&& \text{accessor}
\\
&\texttt{(predconst-to-tsubst \textsl{predconst})}
\index{predconst-to-tsubst@\texttt{predconst-to-tsubst}}
&& \text{accessor}
\\
&\texttt{(predconst-to-index \textsl{predconst})}
\index{predconst-to-index@\texttt{predconst-to-index}}
&& \text{accessor}
\\
&\texttt{(predconst-to-name \textsl{predconst})}
\index{predconst-to-name@\texttt{predconst-to-name}}
&& \text{accessor}
\\
&\texttt{(predconst?\ \textsl{x})}
\index{predconst?@\texttt{predconst?}}
\end{alignat*}
Moreover we need
\begin{alignat*}{2}
&\texttt{(predconst-name? \textsl{name})}%
\index{predconst-name?@\texttt{predconst-name?}}
\\
&\texttt{(predconst-name-to-arity \textsl{predconst-name})}.%
\index{predconst-name-to-arity@\texttt{predconst-name-to-arity}}
\\
&\texttt{(predconst-to-string \textsl{predconst})}.%
\index{predconst-to-string@\texttt{predconst-to-string}}
\end{alignat*}
\subsection{Inductively defined predicate constants}
\mylabel{SS:IDPredConsts}
As we have seen, type variables allow for a general treatment of
inductively generated types $\mu \vec{\alpha} \,\vec{\kappa}$.
Similarly, we can use predicate variables to inductively generate
predicates $\mu \vec{X} \,\vec{K}$.
More precisely, we allow the formation of inductively generated
predicates $\mu \vec{X} \,\vec{K}$, where $\vec{X} =
(X_j)_{j=1,\dots,N}$ is a list of distinct predicate variables, and
$\vec{K} = (K_i)_{i=1,\dots,k}$ is a list of constructor formulas (or
\inquotes{clauses}\index{clause}) containing $X_1,\dots,X_N$ in
strictly positive positions only.
To introduce inductively defined predicates we use
\[
\texttt{add-ids}\index{add-ids@\texttt{add-ids}}.
\]
An example is
\begin{verbatim}
(add-ids (list (list "Ev" (make-arity (py "nat")) "algEv")
(list "Od" (make-arity (py "nat")) "algOd"))
'("Ev 0" "InitEv")
'("allnc n.Od n -> Ev(n+1)" "GenEv")
'("Od 1" "InitOd")
'("allnc n.Ev n -> Od(n+1)" "GenOd"))
\end{verbatim}
This simultaneously introduces the two inductively defined predicate
constants \texttt{Ev} and \texttt{Od}, by the clauses given. The
presence of an algebra name after the arity (here \texttt{algEv} and
\texttt{algOd}) indicates that this inductively defined predicate
constant is to have computational content. Then all clauses with this
constant in the conclusion must provide a constructor name (here
\texttt{InitEv}, \texttt{GenEv}, \texttt{InitOd}, \texttt{GenOd}). If
the constant is to have no computational content, then all its clauses
must be invariant (under realizability, a.k.a.\ \inquotes{negative}).
Here are some further examples of inductively defined predicates:
\begin{verbatim}
(add-ids
(list (list "Even" (make-arity (py "nat")) "algEven"))
'("Even 0" "InitEven")
'("allnc n.Even n -> Even(n+2)" "GenEven"))
(add-ids
(list (list "Acc" (make-arity (py "nat")) "algAcc"))
'("allnc n.(all m.m<n -> Acc m) -> Acc n" "GenAccSup"))
(add-ids (list (list "OrID" (make-arity) "algOrID"))
'("P^1 -> OrID" "InlOrID")
'("P^2 -> OrID" "InrOrID"))
(add-ids
(list (list "EqID" (make-arity (py "alpha") (py "alpha"))
"algEqID"))
'("allnc x^ EqID x^ x^" "GenEqID"))
(add-ids (list (list "ExID" (make-arity) "algExID"))
'("allnc x^.Q^ x^ -> ExID" "GenExID"))
(add-ids
(list (list "FalsityID" (make-arity) "algFalsityID")))
\end{verbatim}
\section{Terms and objects}
\mylabel{Terms}
Terms are built from (typed) variables and constants by abstraction,
application, pairing, formation of left and right components (i.e.\
projections) and the \texttt{if}-construct.
The \texttt{if}-construct\index{if-construct@\texttt{if}-construct}
distinguishes cases according to the outer constructor form; the
simplest example (for the type \texttt{boole}) is \emph{if-then-else}.
Here we do not want to evaluate all arguments right away, but rather
evaluate the test argument first and depending on the result evaluate
at most one of the other arguments. This phenomenon is well known in
functional languages; e.g.\ in \textsc{Scheme} the
\texttt{if}-construct is called a \emph{special form} as opposed to an
operator. In accordance with this terminology we also call our
\texttt{if}-construct a special form\index{special form}. It will be
given a special treatment in \texttt{nbe-term-to-object}.
Usually it will be the case that every closed term of an sfa ground
type reduces via the computation rules to a constructor term, i.e.\ a
closed term built from constructors only. However, we do not require
this.
% \subsection*{Interface}
We have constructors, accessors and tests for variables
\begin{alignat*}{2}
&\texttt{(make-term-in-var-form var)}
\index{make-term-in-var-form@\texttt{make-term-in-var-form}}
&\quad& \text{constructor}
\\
% &\texttt{(term-in-var-form-to-string \textsl{term})}
% \index{term-in-var-form-to-string@\texttt{term-in-var-form-to-string}}
% && \text{accessor,} \\
&\texttt{(term-in-var-form-to-var \textsl{term})}
\index{term-in-var-form-to-var@\texttt{term-in-var-form-to-var}}
&& \text{accessor,}
\\
&\texttt{(term-in-var-form?\ \textsl{term})}
\index{term-in-var-form?@\texttt{term-in-var-form?}}
&& \text{test,}
\end{alignat*}
for constants
\begin{alignat*}{2}
&\texttt{(make-term-in-const-form \textsl{const})}
\index{make-term-in-const-form@\texttt{make-term-in-const-form}}
&\quad& \text{constructor}
\\
&\texttt{(term-in-const-form-to-const \textsl{term})}
\index{term-in-const-form-to-const@\texttt{term-in-const-form-to-const}}
&& \text{accessor}
\\
&\texttt{(term-in-const-form?\ \textsl{term})}
\index{term-in-const-form?@\texttt{term-in-const-form?}}
&& \text{test,}
\end{alignat*}
for abstractions
\begin{alignat*}{2}
&\texttt{(make-term-in-abst-form \textsl{var} \textsl{term})}
\index{make-term-in-abst-form@\texttt{make-term-in-abst-form}}
&\quad& \text{constructor}
\\
&\texttt{(term-in-abst-form-to-var \textsl{term})}
\index{term-in-abst-form-to-var@\texttt{term-in-abst-form-to-var}}
&& \text{accessor}
\\
&\texttt{(term-in-abst-form-to-kernel \textsl{term})}
\index{term-in-abst-form-to-kernel@\texttt{term-in-abst-form-to-kernel}}
&& \text{accessor}
\\
&\texttt{(term-in-abst-form?\ \textsl{term})}
\index{term-in-abst-form?@\texttt{term-in-abst-form?}}
&& \text{test,}
\end{alignat*}
for applications
\begin{alignat*}{2}
&\texttt{(make-term-in-app-form \textsl{term1} \textsl{term2})}
\index{make-term-in-app-form@\texttt{make-term-in-app-form}}
&\quad& \text{constructor}
\\
&\texttt{(term-in-app-form-to-op \textsl{term})}
\index{term-in-app-form-to-op@\texttt{term-in-app-form-to-op}}
&& \text{accessor}
\\
&\texttt{(term-in-app-form-to-arg \textsl{term})}
\index{term-in-app-form-to-arg@\texttt{term-in-app-form-to-arg}}
&& \text{accessor}
\\
&\texttt{(term-in-app-form?\ \textsl{term})}
\index{term-in-app-form?@\texttt{term-in-app-form?}}
&& \text{test,}
\end{alignat*}
for pairs
\begin{alignat*}{2}
&\texttt{(make-term-in-pair-form \textsl{term1} \textsl{term2})}
\index{make-term-in-pair-form@\texttt{make-term-in-pair-form}}
&\quad& \text{constructor}
\\
&\texttt{(term-in-pair-form-to-left \textsl{term})}
\index{term-in-pair-form-to-left@\texttt{term-in-pair-form-to-left}}
&& \text{accessor}
\\
&\texttt{(term-in-pair-form-to-right \textsl{term})}
\index{term-in-pair-form-to-right@\texttt{term-in-pair-form-to-right}}
&& \text{accessor}
\\
&\texttt{(term-in-pair-form?\ \textsl{term})}
\index{term-in-pair-form?@\texttt{term-in-pair-form?}}
&& \text{test,}
\end{alignat*}
for the left and right component of a pair
\begin{alignat*}{2}
&\texttt{(make-term-in-lcomp-form \textsl{term})}
\index{make-term-in-lcomp-form@\texttt{make-term-in-lcomp-form}}
&\quad& \text{constructor}
\\
&\texttt{(make-term-in-rcomp-form \textsl{term})}
\index{make-term-in-rcomp-form@\texttt{make-term-in-rcomp-form}}
&& \text{constructor}
\\
&\texttt{(term-in-lcomp-form-to-kernel \textsl{term})}
\index{term-in-lcomp-form-to-kernel@\texttt{term-in-lcomp-form-to-kernel}}
&& \text{accessor}
\\
&\texttt{(term-in-rcomp-form-to-kernel \textsl{term})}
\index{term-in-rcomp-form-to-kernel@\texttt{term-in-rcomp-form-to-kernel}}
&& \text{accessor}
\\
&\texttt{(term-in-lcomp-form?\ \textsl{term})}
\index{term-in-lcomp-form?@\texttt{term-in-lcomp-form?}}
&& \text{test}
\\
&\texttt{(term-in-rcomp-form?\ \textsl{term})}
\index{term-in-rcomp-form?@\texttt{term-in-rcomp-form?}}
&& \text{test}
\end{alignat*}
and for \texttt{if}-constructs
\begin{alignat*}{2}
&\texttt{(make-term-in-if-form \textsl{test} \textsl{alts} .\ \textsl{rest})}
\index{make-term-in-if-form@\texttt{make-term-in-if-form}}
&\quad& \text{constructor}
\\
&\texttt{(term-in-if-form-to-test \textsl{term})}
\index{term-in-if-form-to-test@\texttt{term-in-if-form-to-test}}
&& \text{accessor}
\\
&\texttt{(term-in-if-form-to-alts \textsl{term})}
\index{term-in-if-form-to-alts@\texttt{term-in-if-form-to-alts}}
&& \text{accessor}
\\
&\texttt{(term-in-if-form-to-rest \textsl{term})}
\index{term-in-if-form-to-rest@\texttt{term-in-if-form-to-rest}}
&& \text{accessor}
\\
&\texttt{(term-in-if-form?\ \textsl{term})}
\index{term-in-if-form?@\texttt{term-in-if-form?}}
&& \text{test.}
\end{alignat*}
where in \texttt{make-term-in-if-form}, \textsl{rest} is either empty
or an all-formula.
It is convenient to have more general application constructors and
accessors available, where application takes arbitrary many arguments
and works for ordinary application as well as for component formation.
\begin{alignat*}{2}
&\texttt{(mk-term-in-app-form \textsl{term} \textsl{term1} \dots)}
\index{mk-term-in-app-form@\texttt{mk-term-in-app-form}}
&\quad& \text{constructor}
\\
&\texttt{(term-in-app-form-to-final-op \textsl{term})}
\index{term-in-app-form-to-final-op@\texttt{term-in-app-form-to-final-op}}
&& \text{accessor}
\\
&\texttt{(term-in-app-form-to-args \textsl{term})}
\index{term-in-app-form-to-args@\texttt{term-in-app-form-to-args}}
&& \text{accessor,}
\end{alignat*}
Also for abstraction it is convenient to have a more general constructor
taking arbitrary many variables to be abstracted one after the other
\begin{alignat*}{2}
&\texttt{(mk-term-in-abst-form \textsl{var1} \dots\ \textsl{term})}.
\index{mk-term-in-abst-form@\texttt{mk-term-in-abst-form}}
\end{alignat*}
We also allow vector notation for recursion (cf.\ Joachimski and Matthes
\cite{JoachimskiMatthes03}).
Moreover we need
\begin{alignat*}{2}
&\texttt{(term?\ \textsl{x})}
\index{term?@\texttt{term?}}
\\
&\texttt{(term=?\ \textsl{term1} \textsl{term2})}
\index{term=?@\texttt{term=?}}
\\
&\texttt{(terms=?\ \textsl{terms1} \textsl{terms2})}
\index{terms=?@\texttt{terms=?}}
\\
&\texttt{(term-to-type \textsl{term})}
\index{term-to-type@\texttt{term-to-type}}
\\
&\texttt{(term-to-free \textsl{term})}
\index{term-to-free@\texttt{term-to-free}}
\\
&\texttt{(term-to-bound \textsl{term})}
\index{term-to-bound@\texttt{term-to-bound}}
\\
&\texttt{(term-to-t-deg \textsl{term})}
\index{term-to-t-deg@\texttt{term-to-t-deg}}
\\
&\texttt{(synt-total?\ \textsl{term})}
\index{synt-total?@\texttt{synt-total?}}
\\
&\texttt{(term-to-string \textsl{term})}.
\index{term-to-string@\texttt{term-to-string}}
\end{alignat*}
% To take care of arithmetical terms, we use
% \begin{alignat*}{2}
% %
% &\texttt{(mk-+ <terms>)} \\
% &\texttt{(mk-- <terms>)} \\
% &\texttt{(mk-max <terms>)} \\
% &\texttt{(mk-min <terms>)} \\
% &\texttt{(mk-* <terms>)}
% %
% \end{alignat*}
\subsection{Normalization}
We need an operation which transforms a term into its normal form
w.r.t.\ the given computation and rewrite rules. Here we base our
treatment on \emph{normalization by evaluation} introduced in
\cite{BergerSchwichtenberg91a}, and extended to arbitrary computation
and rewrite rules in \cite{BergerEberlSchwichtenberg03}.
For normalization by evaluation we need semantical \emph{objects}.
For an arbitrary ground type every term family of that type is an
object. For an sfa ground type, in addition the constructors have
semantical counterparts. The freeness of the constructors is
expressed by requiring that their ranges are disjoint and that they
are injective. Moreover, we view the free algebra as a domain and
require that its bottom element is not in the range of the
constructors. Hence the constructors are total and non-strict. Then
by applying \texttt{nbe-reflect} followed by \texttt{nbe-reify} we can
normalize every term, where normalization refers to the computation as
well as the rewrite rules.
% \subsection*{Interface}
An object consists of a semantical value and a type.
\begin{alignat*}{2}
&\texttt{(nbe-make-object \textsl{type} \textsl{value})}
\index{nbe-make-object@\texttt{nbe-make-object}}
&\quad& \text{constructor}
\\
&\texttt{(nbe-object-to-type \textsl{object})}
\index{nbe-object-to-type@\texttt{nbe-object-to-type}}
&& \text{accessor}
\\
&\texttt{(nbe-object-to-value \textsl{object})}
\index{nbe-object-to-value@\texttt{nbe-object-to-value}}
&& \text{accessor}
\\
&\texttt{(nbe-object?\ \textsl{x})}
\index{nbe-object?@\texttt{nbe-object?}}
&& \text{test.}
\end{alignat*}
To work with objects, we need
\begin{alignat*}{2}
&\texttt{(nbe-object-apply \textsl{function-obj} \textsl{arg-obj})}
\index{nbe-object-apply@\texttt{nbe-object-apply}}
\end{alignat*}
Again it is convenient to have a more general application operation
available, which takes arbitrary many arguments and works for ordinary
application as well as for component formation. We also need an
operation composing two unary function objects.
\begin{alignat*}{2}
&\texttt{(nbe-object-app \textsl{function-obj} \textsl{arg-obj1} \dots)}
\index{nbe-object-app@\texttt{nbe-object-app}}
\\
&\texttt{(nbe-object-compose \textsl{function-obj1} \textsl{function-obj2})}
\index{nbe-object-compose@\texttt{nbe-object-compose}}
\end{alignat*}
For ground type values we need constructors, accessors and tests. To
make constructors \inquotes{self-evaluating}, a constructor value has
the form
\[
\hbox{\texttt{(constr-value \textsl{name} \textsl{objs}
\textsl{delayed-constr})},}
\]
where \textsl{delayed-constr} is a procedure of zero arguments which
evaluates to this very same constructor. This is necessary to avoid
having a cycle (for nullary constructors, and only for those).
\begin{alignat*}{2}
&\texttt{(nbe-make-constr-value \textsl{name} \textsl{objs})}
\index{nbe-make-constr-value@\texttt{nbe-make-constr-value}}
&\quad& \text{constructor}
\\
&\texttt{(nbe-constr-value-to-name \textsl{value})}
\index{nbe-constr-value-to-name@\texttt{nbe-constr-value-to-name}}
&& \text{accessor} \\
&\texttt{(nbe-constr-value-to-args \textsl{value})}
&& \text{accessor}
\\
&\texttt{(nbe-constr-value-to-constr \textsl{value})}
\index{nbe-constr-value-to-constr@\texttt{nbe-constr-value-to-constr}}
&& \text{accessor}
\\
&\texttt{(nbe-constr-value?\ \textsl{value})}
\index{nbe-constr-value?@\texttt{nbe-constr-value?}}
&& \text{test}
\\
&\texttt{(nbe-fam-value?\ \textsl{value})}
\index{nbe-fam-value?@\texttt{nbe-fam-value?}}
&& \text{test.}
\end{alignat*}
The essential function which \inquotes{animates}\index{animation} the
program constants according to the given computation and rewrite rules
is
\begin{align*}
&\texttt{(nbe-pconst-and-tsubst-and-rules-to-object}
\index{nbe-pconst-and-tsubst-and-rules-to-object@\texttt{nbe-pconst-{\dots}-to-object}}
\\
&\qquad \texttt{\textsl{pconst}\ \textsl{tsubst}\ \textsl{comprules}\
\textsl{rewrules})}
\end{align*}
Using it we can the define an \indexentry{evaluation} function, which
assigns to a term and an environment a semantical object:
\begin{alignat*}{2}
&\texttt{(nbe-term-to-object \textsl{term} \textsl{bindings})}
\index{nbe-term-to-object@\texttt{nbe-term-to-object}}
&\quad& \text{evaluation.}
\end{alignat*}
Here \textsl{bindings} is an association list assigning objects of the
same type to variables. In case a variable is not assigned anything
in \textsl{bindings}, by default we assign the constant term family of
this variable, which always is an object of the correct type.
The interpretation of the program constants requires some auxiliary
functions (cf.\ \cite{BergerEberlSchwichtenberg03}):
\begin{alignat*}{2}
&\texttt{(nbe-constructor-pattern?\ \textsl{term})}
\index{nbe-constructor-pattern?@\texttt{nbe-constructor-pattern?}}
&\quad& \text{test}
\\
&\texttt{(nbe-inst?\ \textsl{constr-pattern} \textsl{obj})}
\index{nbe-inst?@\texttt{nbe-inst?}}
&& \text{test}
\\
&\texttt{(nbe-genargs \textsl{constr-pattern} \textsl{obj})}
\index{nbe-genargs@\texttt{nbe-genargs}}
&& \text{generalized arguments}
\\
% &\texttt{(nbe-select \textsl{pconst} \textsl{term})}
% && \text{selects a rewrite rule} \\
&\texttt{(nbe-extract \textsl{termfam})}
\index{nbe-extract@\texttt{nbe-extract}}
&& \text{extracts a term from a family}
\\
&\texttt{(nbe-match \textsl{pattern} \textsl{term})}
\index{nbe-match@\texttt{nbe-match}}
\end{alignat*}
Then we can define
\begin{alignat*}{2}
&\texttt{(nbe-reify \textsl{object})}
\index{nbe-reify@\texttt{nbe-reify}}
&\quad& \text{reification}
\\
&\texttt{(nbe-reflect \textsl{term})}
\index{nbe-reflect@\texttt{nbe-reflect}}
&& \text{reflection}
\end{alignat*}
and by means of these
\begin{alignat*}{2}
&\texttt{(nbe-normalize-term \textsl{term})}
\index{nbe-normalize-term@\texttt{nbe-normalize-term}}
&\quad& \text{normalization,}
\end{alignat*}
abbreviated \texttt{nt}\index{nt@\texttt{nt}}.
The \texttt{if}-form needs a special treatment. In particular, for a
full normalization of terms (including permutative conversions), we
define a preprocessing step that $\eta$ expands the alternatives of
all \texttt{if}-terms. The result contains \texttt{if}-terms with
ground type alternatives only.
\subsection{Substitution}
Recall the generalities on substitutions in Section~\ref{SS:GenSubst}.
We define simultaneous substitution for type and object variables in a
term, via \texttt{tsubst} and \texttt{subst}. It is assumed that
\texttt{subst} only affects those vars whose type is not changed by
\texttt{tsubst}.
In the abstraction case of the recursive definition, the abstracted
variable may need to be renamed. However, its type can be affected by
\texttt{tsubst}. Then the renaming cannot be made part of
\texttt{subst}, because the condition above would be violated.
Therefore we carry along a procedure renaming variables, which
remembers the renaming of variables done so far.
\begin{alignat*}{2}
&\texttt{(term-substitute \textsl{term} \textsl{tosubst})}%
\index{term-substitute@\texttt{term-substitute}}
\\
&\texttt{(term-subst \textsl{term} \textsl{arg} \textsl{val})}%
\index{term-subst@\texttt{term-subst}}
\\
&\texttt{(compose-o-substitutions \textsl{subst1} \textsl{subst2})}%
\index{compose-o-substitutions@\texttt{compose-o-substitutions}}
\end{alignat*}
The \texttt{o} in \texttt{compose-o-substitutions} indicates that we
substitute for \emph{object} variables. However, since this is the
most common form of substitution, we also write
\texttt{compose-substitutions}%
\index{compose-substitutions@\texttt{compose-substitutions}} instead.
Display functions for substitutions are
\begin{align*}
&\texttt{(display-substitution \textsl{subst})}%
\index{display-substitution@\texttt{display-substitution}}
\\
&\texttt{(substitution-to-string \textsl{subst})}%
\index{substitution-to-string@\texttt{substitution-to-string}}
\end{align*}
\section{Formulas and comprehension terms}
\mylabel{S:Formulas}
A prime formula\index{formula!prime} can have the form
\begin{itemize}
\item \texttt{(atom r)} with a term r of type boole,
\item \texttt{(predicate a r1 ... rn)} with a predicate variable or
constant \texttt{a} and terms \texttt{r1} \dots \texttt{rn}.
\end{itemize}
Formulas are built from prime formulas by
\begin{itemize}
\item implication \texttt{(imp \textsl{formula1} \textsl{formula2})}
\item conjunction \texttt{(and \textsl{formula1} \textsl{formula2})}
\item tensor \texttt{(tensor \textsl{formula1} \textsl{formula2})}
\item all quantification \texttt{(all \textsl{x} \textsl{formula})}
\item existential quantification \texttt{(ex \textsl{x} \textsl{formula})}
\item all quantification \texttt{(allnc \textsl{x} \textsl{formula})}
without computational content
\item existential quantification \texttt{(exnc \textsl{x}
\textsl{formula})} without computational content
\end{itemize}
Moreover we have classical existential quantification in an arithmetical
and a logical form:
\begin{alignat*}{2}
&\texttt{(exca (\textsl{x1}\dots) \textsl{formula})}
\index{exca@\texttt{exca}}
&\quad& \text{arithmetical version}
\\
&\texttt{(excl (\textsl{x1} \dots) \textsl{formula})}
\index{excl@\texttt{excl}}
&& \text{logical version.}
\end{alignat*}
Here we allow that the quantified variable is formed without \verb#^#,
i.e.\ ranges over total objects only.
Formulas can be \emph{unfolded}\index{formula!unfolded} in the sense
that the all classical existential quantifiers are replaced according
to their definiton. Inversely a formula can be
\emph{folded}\index{formula!folded} in the sense that classical
existential quantifiers are introduced wherever possible.
\emph{Comprehension terms}\index{comprehension term} have the form
\texttt{(cterm \textsl{vars} \textsl{formula})}. Note that
\textsl{formula} may contain further free variables.
% \subsection*{Interface}
Tests:
\begin{align*}
&\texttt{(atom-form?\ \textsl{formula})}
\index{atom-form?@\texttt{atom-form?}}
\\
% &\texttt{(pvar-form?\ \textsl{formula})}
% \index{pvar-form?@\texttt{pvar-form?}}
% \\
% &\texttt{(predconst-form?\ \textsl{formula})}
% \index{predconst-form?@\texttt{predconst-form?}}
% \\
&\texttt{(predicate-form?\ \textsl{formula})}
\index{predicate-form?@\texttt{predicate-form?}}
\\
&\texttt{(prime-form?\ \textsl{formula})}
\index{prime-form?@\texttt{prime-form?}}
\\
&\texttt{(imp-form?\ \textsl{formula})}
\index{imp-form?@\texttt{imp-form?}}
\\
&\texttt{(and-form?\ \textsl{formula})}
\index{and-form?@\texttt{and-form?}}
\\
&\texttt{(tensor-form?\ \textsl{formula})}
\index{tensor-form?@\texttt{tensor-form?}}
\\
&\texttt{(all-form?\ \textsl{formula})}
\index{all-form?@\texttt{all-form?}}
\\
&\texttt{(ex-form?\ \textsl{formula})}
\index{ex-form?@\texttt{ex-form?}}
\\
&\texttt{(allnc-form?\ \textsl{formula})}
\index{allnc-form?@\texttt{allnc-form?}}
\\
&\texttt{(exnc-form?\ \textsl{formula})}
\index{exnc-form?@\texttt{exnc-form?}}
\\
&\texttt{(exca-form?\ \textsl{formula})}
\index{exca-form?@\texttt{exca-form?}}
\\
&\texttt{(excl-form?\ \textsl{formula})}
\index{excl-form?@\texttt{excl-form?}}
\end{align*}
and also
\begin{align*}
&\texttt{(quant-prime-form?\ \textsl{formula})}
\index{quant-prime-form?@\texttt{quant-prime-form?}}
\\
&\texttt{(quant-free?\ \textsl{formula}).}
\index{quant-free?@\texttt{quant-free?}}
\end{align*}
We need constructors and accessors for prime formulas
\begin{alignat*}{2}
&\texttt{(make-atomic-formula \textsl{boolean-term})}
\index{make-atomic-formula@\texttt{make-atomic-formula}}
\\
&\texttt{(make-predicate-formula \textsl{predicate} \textsl{term1} \dots)}
\index{make-predicate-formula@\texttt{make-predicate-formula}}
\\
&\texttt{atom-form-to-kernel}
\index{atom-form-to-kernel@\texttt{atom-form-to-kernel}}
\\
&\texttt{predicate-form-to-predicate}
\index{predicate-form-to-predicate@\texttt{predicate-form-to-predicate}}
\\
&\texttt{predicate-form-to-args.}
\index{predicate-form-to-args@\texttt{predicate-form-to-args}}
\end{alignat*}
We also have constructors for special atomic formulas
\begin{alignat*}{2}
&\texttt{(make-eq \textsl{term1} \textsl{term2})}
\index{make-eq@\texttt{make-eq}}
&\quad& \text{constructor for equalities}
\\
&\texttt{(make-= \textsl{term1} \textsl{term2})}
\index{make-=@\texttt{make-=}}
&\quad& \text{constructor for equalities on finalgs}
\\
&\texttt{(make-total \textsl{term})}
\index{make-total@\texttt{make-total}}
&\quad& \text{constructor for totalities}
\\
&\texttt{(make-e \textsl{term})}
\index{make-e@\texttt{make-e}}
&\quad& \text{constructor for existence on finalgs}
\\
&\texttt{truth}
\index{truth@\texttt{truth}}
\\
&\texttt{falsity}
\index{falsity@\texttt{falsity}}
\\
&\texttt{falsity-log.}
\index{falsity-log@\texttt{falsity-log}}
\end{alignat*}
We need constructors and accessors for implications
\begin{alignat*}{2}
&\texttt{(make-imp \textsl{premise} \textsl{conclusion})}
\index{make-imp@\texttt{make-imp}}
&\quad& \text{constructor}
\\
&\texttt{(imp-form-to-premise \textsl{imp-formula})}
\index{imp-form-to-premise@\texttt{imp-form-to-premise}}
&& \text{accessor}
\\
&\texttt{(imp-form-to-conclusion \textsl{imp-formula})}
\index{imp-form-to-conclusion@\texttt{imp-form-to-conclusion}}
&& \text{accessor,}
\end{alignat*}
conjunctions
\begin{alignat*}{2}
&\texttt{(make-and \textsl{formula1} \textsl{formula2})}
\index{make-and@\texttt{make-and}}
&\quad& \text{constructor}
\\
&\texttt{(and-form-to-left \textsl{and-formula})}
\index{and-form-to-left@\texttt{and-form-to-left}}
&& \text{accessor}
\\
&\texttt{(and-form-to-right \textsl{and-formula})}
\index{and-form-to-right@\texttt{and-form-to-right}}
&& \text{accessor,}
\end{alignat*}
tensors
\begin{alignat*}{2}
&\texttt{(make-tensor \textsl{formula1} \textsl{formula2})}
\index{make-tensor@\texttt{make-tensor}}
&\quad& \text{constructor}
\\
&\texttt{(tensor-form-to-left \textsl{tensor-formula})}
\index{tensor-form-to-left@\texttt{tensor-form-to-left}}
&& \text{accessor}
\\
&\texttt{(tensor-form-to-right \textsl{tensor-formula})}
\index{tensor-form-to-right@\texttt{tensor-form-to-right}}
&& \text{accessor,}
\end{alignat*}
universally quantified formulas
\begin{alignat*}{2}
&\texttt{(make-all \textsl{var} \textsl{formula})}
\index{make-all@\texttt{make-all}}
&\quad& \text{constructor}
\\
&\texttt{(all-form-to-var \textsl{all-formula})}
\index{all-form-to-var@\texttt{all-form-to-var}}
&& \text{accessor}
\\
&\texttt{(all-form-to-kernel \textsl{all-formula})}
\index{all-form-to-kernel@\texttt{all-form-to-kernel}}
&& \text{accessor,}
\end{alignat*}
existentially quantified formulas
\begin{alignat*}{2}
&\texttt{(make-ex \textsl{var} \textsl{formula})}
\index{make-ex@\texttt{make-ex}}
&\quad& \text{constructor}
\\
&\texttt{(ex-form-to-var \textsl{ex-formula})}
\index{ex-form-to-var@\texttt{ex-form-to-var}}
&& \text{accessor}
\\
&\texttt{(ex-form-to-kernel \textsl{ex-formula})}
\index{ex-form-to-kernel@\texttt{ex-form-to-kernel}}
&& \text{accessor,}
\end{alignat*}
universally quantified formulas without computational content
\begin{alignat*}{2}
&\texttt{(make-allnc \textsl{var} \textsl{formula})}
\index{make-allnc@\texttt{make-allnc}}
&\quad& \text{constructor}
\\
&\texttt{(allnc-form-to-var \textsl{allnc-formula})}
\index{allnc-form-to-var@\texttt{allnc-form-to-var}}
&& \text{accessor}
\\
&\texttt{(allnc-form-to-kernel \textsl{allnc-formula})}
\index{allnc-form-to-kernel@\texttt{allnc-form-to-kernel}}
&& \text{accessor,}
\end{alignat*}
existentially quantified formulas without computational content
\begin{alignat*}{2}
&\texttt{(make-exnc \textsl{var} \textsl{formula})}
\index{make-exnc@\texttt{make-exnc}}
&\quad& \text{constructor}
\\
&\texttt{(exnc-form-to-var \textsl{exnc-formula})}
\index{exnc-form-to-var@\texttt{exnc-form-to-var}}
&& \text{accessor}
\\
&\texttt{(exnc-form-to-kernel \textsl{exnc-formula})}
\index{exnc-form-to-kernel@\texttt{exnc-form-to-kernel}}
&& \text{accessor,}
\end{alignat*}
existentially quantified formulas in the sense of classical arithmetic
\begin{alignat*}{2}
&\texttt{(make-exca \textsl{var} \textsl{formula})}
\index{make-exca@\texttt{make-exca}}
&\quad& \text{constructor}
\\
&\texttt{(exca-form-to-var \textsl{exca-formula})}
\index{exca-form-to-var@\texttt{exca-form-to-var}}
&& \text{accessor}
\\
&\texttt{(exca-form-to-kernel \textsl{exca-formula})}
\index{exca-form-to-kernel@\texttt{exca-form-to-kernel}}
&& \text{accessor,}
\end{alignat*}
existentially quantified formulas in the sense of classical logic
\begin{alignat*}{2}
&\texttt{(make-excl \textsl{var} \textsl{formula})}
\index{make-excl@\texttt{make-excl}}
&\quad& \text{constructor}
\\
&\texttt{(excl-form-to-var \textsl{excl-formula})}
\index{excl-form-to-var@\texttt{excl-form-to-var}}
&& \text{accessor}
\\
&\texttt{(excl-form-to-kernel \textsl{excl-formula})}
\index{excl-form-to-kernel@\texttt{excl-form-to-kernel}}
&& \text{accessor.}
\end{alignat*}
For convenience we also have as generalized constructors
\begin{alignat*}{2}
&\texttt{(mk-imp \textsl{formula} \textsl{formula1} {\dots})}
\index{mk-imp@\texttt{mk-imp}}
&\quad&\text{implication}
\\
&\texttt{(mk-neg \textsl{formula1} {\dots})}
\index{mk-neg@\texttt{mk-neg}}
&& \text{negation}
\\
&\texttt{(mk-neg-log \textsl{formula1} {\dots})}
\index{mk-neg-log@\texttt{mk-neg-log}}
&& \text{logical negation}
\\
&\texttt{(mk-and \textsl{formula} \textsl{formula1} {\dots})}
\index{mk-and@\texttt{mk-and}}
&& \text{conjunction}
\\
&\texttt{(mk-tensor \textsl{formula} \textsl{formula1}\! {\dots}\!)}
\index{mk-tensor@\texttt{mk-tensor}}
&& \text{tensor}
\\
&\texttt{(mk-all \textsl{var1} {\dots}\ \textsl{formula})}
\index{mk-all@\texttt{mk-all}}
&& \text{all-formula}
\\
&\texttt{(mk-ex \textsl{var1} {\dots}\ \textsl{formula})}
\index{mk-ex@\texttt{mk-ex}}
&& \text{ex-formula}
\\
&\texttt{(mk-allnc \textsl{var1} {\dots}\ \textsl{formula})}
\index{mk-allnc@\texttt{mk-allnc}}
&& \text{allnc-formula}
\\
&\texttt{(mk-exnc \textsl{var1} {\dots}\ \textsl{formula})}
\index{mk-exnc@\texttt{mk-exnc}}
&& \text{exnc-formula}
\\
&\texttt{(mk-exca \textsl{var1} {\dots}\ \textsl{formula})}
\index{mk-exca@\texttt{mk-exca}}
&& \text{classical ex-formula (arithmetical)}
\\
&\texttt{(mk-excl \textsl{var1} {\dots}\ \textsl{formula})}
\index{mk-excl@\texttt{mk-excl}}
&& \text{classical ex-formula (logical)}
\end{alignat*}
and as generalized accessors
\begin{alignat*}{2}
&\texttt{(imp-form-to-premises-and-final-conclusion \textsl{formula})}
\\
%\index{imp-form-to-premises-and-final-conclusion@\texttt{imp-form-to-premises-and-final-conclusion}}\\
&\texttt{(tensor-form-to-parts \textsl{formula})}
\index{tensor-form-to-parts@\texttt{tensor-form-to-parts}}
\\
&\texttt{(all-form-to-vars-and-final-kernel \textsl{formula})}
\index{all-form-to-vars-and-final-kernel@\texttt{all-form-to-vars-and{\dots}}}
\\
&\texttt{(ex-form-to-vars-and-final-kernel \textsl{formula})}
\index{ex-form-to-vars-and-final-kernel@\texttt{ex-form-to-vars-and{\dots}}}
\end{alignat*}
and similarly for \texttt{exca}-forms and \texttt{excl}-forms.
Occasionally it is convenient to have
\begin{alignat*}{2}
&\texttt{(imp-form-to-premises \textsl{formula} <\textsl{n}>)}
\index{imp-form-to-premises@\texttt{imp-form-to-premises}}
&\quad& \text{all (first $n$) premises}
\\
&\texttt{(imp-form-to-final-conclusion \textsl{formula} <\textsl{n}>)}
\index{imp-form-to-final-conclusion@\texttt{imp-form-to-final-conclusion}}
\end{alignat*}
where the latter computes the final conclusion (conclusion after
removing the first $n$ premises) of the formula.
It is also useful to have some general procedures working for
arbitrary quantified formulas. We provide
\begin{alignat*}{2}
&\texttt{(make-quant-formula \textsl{quant} \textsl{var1} \dots\
\textsl{kernel})}
\index{make-quant-formula@\texttt{make-quant-formula}}
&\quad& \text{constructor}
\\
&\texttt{(quant-form-to-quant \textsl{quant-form})}
\index{quant-form-to-quant@\texttt{quant-form-to-quant}}
&& \text{accessor}
\\
&\texttt{(quant-form-to-vars \textsl{quant-form})}
\index{quant-form-to-vars@\texttt{quant-form-to-vars}}
&& \text{accessor}
\\
&\texttt{(quant-form-to-kernel \textsl{quant-form})}
\index{quant-form-to-kernel@\texttt{quant-form-to-kernel}}
&& \text{accessor}
\\
&\texttt{(quant-form?\ \textsl{x})}
\index{quant-form?@\texttt{quant-form?}}
&& \text{test.}
\end{alignat*}
and for convenience also
\[
\texttt{(mk-quant \textsl{quant} \textsl{var1} \dots\
\textsl{formula})\index{mk-quant@\texttt{mk-quant}}.}
\]
To fold and unfold formulas we have
\begin{align*}
&\texttt{(fold-formula \textsl{formula})}
\index{fold-formula@\texttt{fold-formula}}
\\
&\texttt{(unfold-formula \textsl{formula}).}
\index{unfold-formula@\texttt{unfold-formula}}
\end{align*}
To test equality of formulas up to normalization and $\alpha$-equality
we use
\begin{align*}
&\texttt{(classical-formula=?\ \textsl{formula1} \textsl{formula2})}
\index{classical-formula=?@\texttt{classical-formula=?}}
\\
&\texttt{(formula=?\ \textsl{formula1} \textsl{formula2}),}
\index{formula=?@\texttt{formula=?}}
% &\texttt{(formulas=?\\textsl{formulas1} \textsl{formulas2}),}
\end{align*}
where in the first procedure we unfold before comparing.
Morever we need
\begin{align*}
&\texttt{(formula-to-free\ \textsl{formula}),}
\index{formula-to-free@\texttt{formula-to-free}}
\\
&\texttt{(nbe-formula-to-type\ \textsl{formula}),}
\index{nbe-formula-to-type@\texttt{nbe-formula-to-type}}
\\
&\texttt{(formula-to-prime-subformulas\ \textsl{formula}),}
\index{formula-to-prime-subformulas@\texttt{formula-to-prime-subformulas}}
\end{align*}
Constructors, accessors and a test for comprehension terms are
\begin{alignat*}{2}
&\texttt{(make-cterm \textsl{var1} \dots\ \textsl{formula})}
\index{make-cterm@\texttt{make-cterm}}
&\quad& \text{constructor}
\\
&\texttt{(cterm-to-vars \textsl{cterm})}
\index{cterm-to-vars@\texttt{cterm-to-vars}}
&& \text{accessor}
\\
&\texttt{(cterm-to-formula \textsl{cterm})}
\index{cterm-to-formula@\texttt{cterm-to-formula}}
&& \text{accessor}
\\
&\texttt{(cterm?\ \textsl{x})}
\index{cterm?@\texttt{cterm?}}
&& \text{test.}
\end{alignat*}
Moreover we need
\begin{align*}
&\texttt{(cterm-to-free \textsl{cterm})}
\index{cterm-to-free@\texttt{cterm-to-free}}
\\
&\texttt{(cterm=?\ \textsl{x})}
\index{cterm=?@\texttt{cterm=?}}
\\
&\texttt{(classical-cterm=?\ \textsl{x})}
\index{classical-cterm=?@\texttt{classical-cterm=?}}
\\
&\texttt{(fold-cterm \textsl{cterm})}
\index{fold-cterm@\texttt{fold-cterm}}
\\
&\texttt{(unfold-cterm \textsl{cterm}).}
\index{unfold-cterm@\texttt{unfold-cterm}}
\end{align*}
Normalization of formulas is done with
\begin{alignat*}{2}
&\texttt{(normalize-formula \textsl{formula})}
\index{normalize-formula@\texttt{normalize-formula}}
&\quad& \text{normalization,}
\end{alignat*}
abbreviated \texttt{nf}\index{nt@\texttt{nf}}.
To check equality of formulas we use
\begin{alignat*}{2}
&\texttt{(classical-formula=? \textsl{formula1} \textsl{formula2})}
\index{classical-formula=?@\texttt{classical-formula=?}}
\\
&\texttt{(formula=? \textsl{formula1} \textsl{formula2})}
\index{formula=?@\texttt{formula=?}}
\end{alignat*}
where the former unfolds the classical existential quantifiers and
normalizes all subterms in its formulas.
Display functions for formulas and comprehension terms are
\begin{alignat*}{2}
&\texttt{(formula-to-string \textsl{formula})}
\index{formula-to-string@\texttt{formula-to-string}}
\\
&\texttt{(cterm-to-string \textsl{cterm})}.
\index{cterm-to-string@\texttt{cterm-to-string}}
\end{alignat*}
The former is abbreviated \texttt{nf}\index{nf@\texttt{nf}}.
We can define simultaneous substitution for type, object and predicate
variables in a formula, via \texttt{tsubst}, \texttt{subst} and
\texttt{psubst}. It is assumed that \texttt{subst} only affects those
variables whose type is not changed by \texttt{tsubst}, and that
\texttt{psubst} only affects those predicate variables whose arity is
not changed by \texttt{tsubst}.
In the quantifier case of the recursive definition, the abstracted
variable may need to be renamed. However, its type can be affected by
\texttt{tsubst}. Then the renaming cannot be made part of
\texttt{subst}, because then the condition above would be violated.
Therefore we carry along a procedure \texttt{rename}\index{rename}
renaming variables, which remembers the renaming of variables done so
far.
We will also need formula substitution to compute the formula of an
assumption constant. However, there (type and) predicate variables
are (implicitely) considered to be bound. Therefore, we also have to
carry along a procedure
\texttt{prename}\index{prename@\texttt{prename}} renaming predicate
variables, which remembers the renaming of predicate variables done so
far.
\begin{alignat*}{2}
&\texttt{(formula-substitute \textsl{formula} \textsl{topsubst})}%
\index{formula-substitute@\texttt{formula-substitute}}
\\
&\texttt{(formula-subst \textsl{formula} \textsl{arg} \textsl{val})}%
\index{formula-subst@\texttt{formula-subst}}
\\
&\texttt{(cterm-substitute \textsl{cterm} \textsl{topsubst})}%
\index{cterm-substitute@\texttt{cterm-substitute}}
\\
&\texttt{(cterm-subst \textsl{cterm} \textsl{arg} \textsl{val})}%
\index{cterm-subst@\texttt{cterm-subst}}
\end{alignat*}
Display functions for predicate substitutions are
\begin{align*}
&\texttt{(display-p-substitution \textsl{psubst})}%
\index{display-p-substitution@\texttt{display-p-substitution}}
\\
&\texttt{(p-substitution-to-string \textsl{psubst})}%
\index{p-substitution-to-string@\texttt{p-substitution-to-string}}
\end{align*}
\section{Assumption variables and constants}
\mylabel{S:AssumptionVarConst}
\subsection{Assumption variables}
Assumption variables are for proofs what variables are for terms. The
main difference, however, is that assumption variables have formulas
as types, and that formulas may contain free variables. Therefore we
must be careful when substituting terms for variables in assumption
variables. Our solution (as in Matthes' thesis \cite{Matthes98}) is
to consider an assumption variable as a pair of a (typefree)
identifier and a formula, and to take equality of assumption variables
to mean that both components are equal. Rather than using symbols as
identifiers we prefer to use numbers (i.e.\ indices). However,
sometimes it is useful to provide an optional string as name for
display purposes.
% \subsection*{Interface}
We need a constructor, accessors and tests for assumption variables.
\begin{alignat*}{2}
&\texttt{(make-avar \textsl{formula} \textsl{index} \textsl{name})}
\index{make-avar@\texttt{make-avar}}
&\quad& \text{constructor}
\\
&\texttt{(avar-to-formula \textsl{avar})}
\index{avar-to-formula@\texttt{avar-to-formula}}
&& \text{accessor}
\\
&\texttt{(avar-to-index \textsl{avar})}
\index{avar-to-index@\texttt{avar-to-index}}
&& \text{accessor}
\\
&\texttt{(avar-to-name \textsl{avar})}
\index{avar-to-name@\texttt{avar-to-name}}
&& \text{accessor}
\\
&\texttt{(avar?\ \textsl{x})}
\index{avar?@\texttt{avar?}}
&& \text{test}
\\
&\texttt{(avar=?\ \textsl{avar1} \textsl{avar2})}
\index{avar?@\texttt{avar=?}}
&& \text{test.}
\end{alignat*}
For convenience we have the function
\begin{alignat*}{2}
&\texttt{(mk-avar \textsl{formula} <\textsl{index}> <\textsl{name}>)}
\end{alignat*}
The formula is a required argument; however, the remaining arguments
are optional. The default for the name string is \texttt{u}. We also
require that a function
\begin{align*}
&\texttt{(formula-to-new-avar \textsl{formula})}
\end{align*}
is defined that returns an assumption variable of the requested
formula different from all assumption variables that have ever been
returned by any of the specified functions so far.
% \textbf{Implementation.}
% %
% Assumption variables are implemented as lists:
% %
% $$\texttt{(avar \textsl{formula} \textsl{index} \textsl{name})}.$$
% \subsection*{Assumption constants}
% \mylabel{S:Aconst}
An assumption constant appears in a proof, as an axiom, a theorem or a
global assumption. Its formula is given as an
\inquotes{uninstantiated formula}, where only type and predicate
variables can occur freely; these are considered to be bound in the
assumption constant. In the proof the bound type variables are
implicitely instantiated by types, and the bound predicate variables
by comprehension terms (the arity of a comprehension term is the
type-instantiated arity of the corresponding predicate variable).
Since we do not have type and predicate quantification in formulas,
the assumption constant contains these parts left implicit in the
proof: \texttt{tsubst} and \texttt{pinst} (which will become a
\texttt{psubst}, once the arities of predicate variables are
type-instantiated with \texttt{tsubst}).
So we have assumption constants of the following kinds:
\begin{itemize}
\item axioms,
\item theorems, and
\item global assumptions.
\end{itemize}
To normalize a proof we will first translate it into a term, then
normalize the term and finally translate the normal term back into a
proof. To make this work, in case of axioms we pass to the term
appropriate formulas: all-formulas for induction, an existential
formula for existence introduction, and an existential formula
together with a conclusion for existence elimination. During
normalization of the term these formulas are passed along. When the
normal form is reached, we have to translate back into a proof. Then
these formulas are used to reconstruct the axiom in question.
Internally, the formula of an assumption constant is split into an
uninstantiated formula where only type and predicate variables can
occur freely, and a substitution for at most these type and predicate
variables. The formula assumed by the constant is the result of
carrying out this substitution in the uninstantiated formula. Note
that free variables may again occur in the assumed formula. For
example, assumption constants axiomatizing the existential quantifier
will internally have the form
\begin{alignat*}{2}
&\texttt{(aconst Ex-Intro $\forall \hat{x}^\alpha.\hat{P}(\hat{x}) \to
\ex \hat{x}^\alpha \hat{P}(\hat{x})$
$(\alpha \mapsto \tau, \hat{P}^{(\alpha)} \mapsto \set{\hat{z}^\tau}{A})$)}
\index{Ex-Intro@\texttt{Ex-Intro}}
\\
&\texttt{(aconst Ex-Elim $\ex \hat{x}^\alpha \hat{P}(\hat{x}) \to
(\forall \hat{x}^\alpha. \hat{P}(\hat{x})
\to \hat{Q}) \to \hat{Q}$}
\\
&\qquad\qquad\qquad\qquad \texttt{$(\alpha \mapsto \tau, \hat{P}^{(\alpha)}
\mapsto \set{\hat{z}^\tau}{A}, \hat{Q} \mapsto \set{}{B})$)}
\index{Ex-Elim@\texttt{Ex-Elim}}
\end{alignat*}
\textbf{Interface for general assumption constants.}
To avoid duplication of code it is useful to formulate some procedures
generally for arbitrary assumption constants\index{assumption
constant}, i.e.\ for all of the forms listed above.
\begin{alignat*}{2}
&\texttt{(make-aconst \textsl{name} \textsl{kind} \textsl{uninst-formula}
\textsl{tpsubst}}
\\
&\qquad \texttt{\textsl{repro-formula1} \dots)}
\index{make-aconst@\texttt{make-aconst}}
&\quad& \text{constructor}
\\
&\texttt{(aconst-to-name \textsl{aconst})}
\index{aconst-to-name@\texttt{aconst-to-name}}
&& \text{accessor}
\\
&\texttt{(aconst-to-kind \textsl{aconst})}
\index{aconst-to-kind@\texttt{aconst-to-kind}}
&& \text{accessor}
\\
&\texttt{(aconst-to-uninst-formula \textsl{aconst})}
\index{aconst-to-uninst-formula@\texttt{aconst-to-uninst-formula}}
&& \text{accessor}
\\
&\texttt{(aconst-to-tpsubst \textsl{aconst})}
\index{aconst-to-tpsubst@\texttt{aconst-to-tpsubst}}
&& \text{accessor}
\\
&\texttt{(aconst-to-repro-formulas \textsl{aconst})}
\index{aconst-to-repro-formulas@\texttt{aconst-to-repro-formulas}}
&& \text{accessor}
\\
&\texttt{(aconst?\ \textsl{x})}
\index{aconst?@\texttt{aconst?}}
&& \text{test.}
\end{alignat*}
To construct the formula associated with an aconst, it is useful to
separate the instantiated formula from the variables to be
generalized. The latter can be obtained as free variables in
inst-formula. We therefore provide
\begin{alignat*}{2}
&\texttt{(aconst-to-inst-formula \textsl{aconst})}
\index{aconst-to-inst-formula@\texttt{aconst-to-inst-formula}}
\\
&\texttt{(aconst-to-formula \textsl{aconst})}
\index{aconst-to-formula@\texttt{aconst-to-formula}}
\end{alignat*}
We also provide
\begin{alignat*}{2}
&\texttt{(aconst? \textsl{aconst})}
\index{aconst?@\texttt{aconst?}}
\\
&\texttt{(aconst=?\ \textsl{aconst1} \textsl{aconst2})}
\index{aconst=?@\texttt{aconst=?}}
\\
&\texttt{(aconst-without-rules?\ \textsl{aconst})}
\index{aconst-without-rules?@\texttt{aconst-without-rules?}}
\\
&\texttt{(aconst-to-string\ \textsl{aconst})}
\index{aconst-to-string@\texttt{aconst-to-string}}
\end{alignat*}
\subsection{Axiom constants}
\mylabel{SS:AxiomConst}
% \paragraph{Axioms}
% \mylabel{SS:Ax}
We use the natural numbers as a prototypical finitary algebra; recall
Figure~\ref{F:nat}. Assume that $n$, $p$ are variables of type
$\nat$, $\boole$. Let $\Eq$ denote the equality relation in the
model. Recall the domain of type $\boole$, consisting of $\true$,
$\false$ and the bottom element $\bottom$. The boolean valued
functions equality $=_{nat} \colon \nat \to \nat \to \boole$ and
existence (definedness, totality) $e_{nat} \colon \nat \to \boole$
need to be continuous. So we have
\begin{align*}
\eqrel{0}{0} &\Eq \true
\\
\eqrel{0}{S \hat{n}} \Eq \eqrel{S \hat{n}}{0} &\Eq \false
&e(0) &\Eq \true
\\
\eqrel{S \hat{n}_1}{S \hat{n}_2} &\Eq \eqrel{\hat{n}_1}{\hat{n}_2}
&e(S \hat{n}) &\Eq e(\hat{n})
\\
\eqrel{\bottom_{nat}}{\hat{n}} \Eq \eqrel{\hat{n}}{\bottom_{nat}} &\Eq \bottom
&e(\bottom_{\nat}) &\Eq \bottom
\\
\eqrel{\infty_{nat}}{\hat{n}} \Eq \eqrel{\hat{n}}{\infty_{nat}} &\Eq \bottom
&e(\infty_{\nat}) &\Eq \bottom
\end{align*}
Write $T$, $F$ for $\atom(\true)$, $\atom(\false)$, $r=s$ for
$\atom(\eqrel{r}{s})$ and $E(r)$ for $\atom(e(r))$. We stipulate as
axioms
\begin{alignat*}{2}
&T
&\quad&\texttt{Truth-Axiom}\index{Truth-Axiom@\texttt{Truth-Axiom}}
\\[1ex]
&\hat{x} \Eq \hat{x}
&\quad&\text{\texttt{Eq-Refl}\index{Eq-Refl@\texttt{Eq-Refl}}}
\\
&\hat{x}_1 \Eq \hat{x}_2 \to \hat{x}_2 \Eq \hat{x}_1
&\quad&\text{\texttt{Eq-Symm}\index{Eq-Symm@\texttt{Eq-Symm}}}
\\
&\hat{x}_1 \Eq \hat{x}_2 \to \hat{x}_2 \Eq \hat{x}_3 \to
\hat{x}_1 \Eq \hat{x}_3
&\quad&\text{\texttt{Eq-Trans}\index{Eq-Trans@\texttt{Eq-Trans}}}
\\[1ex]
&\forall \hat{x} \hat{f}_1 \hat{x} \Eq \hat{f}_2 \hat{x} \to
\hat{f}_1 \Eq \hat{f}_2
&&\text{\texttt{Eq-Ext}%
\index{Extensionality@\texttt{Extensionality}}}
\\
&\hat{x}_1 \Eq \hat{x}_2 \to \hat{P}(\hat{x}_1) \to \hat{P}(\hat{x}_2)
&\quad&\text{\texttt{Eq-Compat}%
\index{Compatibility@\texttt{Compatibility}}}
% \\[1ex]
% &\hat{n}_1 \Eq \hat{n}_2 \to E(\hat{n}_1) \to E(\hat{n}_2) \to
% \hat{n}_1 = \hat{n}_2
% &&\text{\texttt{Eq-to-=}}\index{Eq-to-=@\texttt{Eq-to-=}}
% \\
% &\hat{n}_1 = \hat{n}_2 \to \hat{n}_1 \Eq \hat{n}_2
% &&\text{\texttt{=-to-Eq}}\index{equals-to-Eq@\texttt{=-to-Eq}}
% \\[1ex]
% &\Total(\hat{n}) \to E(\hat{n})
% &&\text{\texttt{Total-to-E}}\index{Total-to-E@\texttt{Total-to-E}}
% \\
% &E(\hat{n}) \to \Total(\hat{n})
% &&\text{\texttt{E-to-Total}}\index{E-to-Total@\texttt{E-to-Total}}
% \\[1ex]
% &c_1 \vec{\hat{x}}_1 \Eq c_2 \vec{\hat{x}}_2 \to F
% &&\text{\texttt{Constr-Disjoint}}%
% \index{Constr-Disjoint@\texttt{Constr-Disjoint@}}
% \\
% &c \vec{\hat{x}}_1 \Eq c \vec{\hat{x}}_2 \to \hat{x}_{1i} \Eq \hat{x}_{2i}
% &&\text{\texttt{Constr-Inj}}%
% \index{Constr-Inj@\texttt{Constr-Inj@}}
\\[1ex]
&\Total_{\rho \to\sigma}(\hat{f}) \leftrightarrow
\forall \hat{x}.\Total_{\rho}(\hat{x}) \to \Total_{\sigma}(\hat{f} \hat{x})
&&\text{\texttt{Total}}\index{Total@\texttt{Total}}
\\
&\Total_{\rho}(c)
&&\text{\texttt{Constr-Total}}\index{Constr-Total@\texttt{Constr-Total}}
\\
&\Total(c \vec{\hat{x}}) \to \Total(\hat{x}_i)
&&\text{\texttt{Constr-Total-Args}}%
\index{Constr-Total-Args@\texttt{Constr-Total-Args}}
% \\
% &\Total_{\rho}(\bottom) \to F
% &&\text{\texttt{Bottom-not-Total}}%
% \index{Bottom-Not-Total@\texttt{Bottom-Not-Total}}
\\
\intertext{and for every finitary algebra, e.g.\ \texttt{nat}}
&\hat{n}_1 \Eq \hat{n}_2 \to E(\hat{n}_1) \to
\hat{n}_1 = \hat{n}_2
&&\text{\texttt{Eq-to-=-1-nat}\index{Eq-to-=-1-nat@\texttt{Eq-to-=-1-nat}}}
\\
&\hat{n}_1 \Eq \hat{n}_2 \to E(\hat{n}_2) \to
\hat{n}_1 = \hat{n}_2
&&\text{\texttt{Eq-to-=-2-nat}\index{Eq-to-=-2-nat@\texttt{Eq-to-=-2-nat}}}
\\
&\hat{n}_1 = \hat{n}_2 \to \hat{n}_1 \Eq \hat{n}_2
&&\text{\texttt{=-to-Eq-nat}\index{equals-to-Eq-nat@\texttt{=-to-Eq-nat}}}
\\
&\hat{n}_1 = \hat{n}_2 \to E(\hat{n}_1)
&&\text{\texttt{=-to-E-1-nat}\index{equals-to-E-1-nat@\texttt{=-to-E-1-nat}}}
\\
&\hat{n}_1 = \hat{n}_2 \to E(\hat{n}_2)
&&\text{\texttt{=-to-E-2-nat}\index{equals-to-E-2-nat@\texttt{=-to-E-2-nat}}}
\\
&\Total(\hat{n}) \to E(\hat{n})
&&\text{\texttt{Total-to-E-nat}\index{Total-to-E-nat@\texttt{Total-to-E-nat}}}
\\
&E(\hat{n}) \to \Total(\hat{n})
&&\text{\texttt{E-to-Total-nat}\index{E-to-Total-nat@\texttt{E-to-Total-nat}}}
\end{alignat*}
Here $c$ is a constructor. Notice that in $\Total(c \vec{\hat{x}})
\to \Total(\hat{x}_i)$, the type of $(c \vec{\hat{x}})$ need not be a
finitary algebra, and hence $\hat{x}_i$ may have a function type.
% Further notice that $\Total_{\rho}(\bottom) \to F$ is also necessary
% for $\rho$ an infinitary ground type.
\begin{remark*}
$(E(\hat{n}_1) \to \hat{n}_1 = \hat{n}_2) \to (E(\hat{n}_2) \to
\hat{n}_1 = \hat{n}_2) \to \hat{n}_1 \Eq \hat{n}_2$ is \emph{not}
valid in our intended model (see Figure~\ref{F:nat}), since we have
\emph{two} distinct undefined objects $\bottom_{nat}$ and
$\infty_{nat}$.
\end{remark*}
We abbreviate
\begin{alignat*}{2}
&\forall \hat{x}.\Total_{\rho}(\hat{x}) \to A &\quad\hbox{by}\quad&
\forall x A,\\
&\exists \hat{x}.\Total_{\rho}(\hat{x}) \land A &\quad\hbox{by}\quad&
\exists x A.
\end{alignat*}
Formally, these abbreviations appear as axioms
\begin{alignat*}{2}
&\forall x \hat{P}(x) \to
\forall \hat{x}. \Total(\hat{x}) \to \hat{P}(\hat{x})
&\quad&\texttt{All-AllPartial}\index{All-AllPartial@\texttt{All-AllPartial}}
\\
&(\forall \hat{x}. \Total(\hat{x}) \to \hat{P}(\hat{x})) \to
\forall x \hat{P}(x)
&\quad&\texttt{AllPartial-All}\index{AllPartial-All@\texttt{AllPartial-All}}
\\
&\exists x \hat{P}(x) \to
\exists \hat{x}. \Total(\hat{x}) \land \hat{P}(\hat{x})
&\quad&\texttt{Ex-ExPartial}\index{Ex-ExPartial@\texttt{Ex-ExPartial}}
\\
&(\exists \hat{x}. \Total(\hat{x}) \land \hat{P}(\hat{x})) \to
\exists x \hat{P}(x)
&\quad&\texttt{ExPartial-Ex}\index{ExPartial-Ex@\texttt{ExPartial-Ex}}
\\
\intertext{and for every finitary algebra, e.g.\ \texttt{nat}}
&\forall n \hat{P}(n) \to
\forall \hat{n}. E(\hat{n}) \to \hat{P}(\hat{n})
&\quad&\texttt{All-AllPartial-nat}%
\index{All-AllPartial-nat@\texttt{All-AllPartial-nat}}
\\
&(\exists \hat{n}. E(\hat{n}) \land \hat{P}(\hat{n})) \to
\exists n \hat{P}(n)
&\quad&\texttt{ExPartial-Ex-nat}%
\index{ExPartial-Ex-nat@\texttt{ExPartial-Ex-nat}}
\end{alignat*}
Notice that \texttt{AllPartial-All-nat}%
\index{AllPartial-All-nat@\texttt{AllPartial-All-nat},} i.e.\ $(\forall
\hat{n}. E(\hat{n}) \to \hat{P}(\hat{n})) \to \forall n
\hat{P}(n)$ is provable (since $E(n) \cnv T$). Similarly,
\texttt{Ex-ExPartial-nat}%
\index{Ex-ExPartial-nat@\texttt{Ex-ExPartial-nat}}, i.e.\
$\exists n \hat{P}(n) \to
\exists \hat{n}. E(\hat{n}) \land \hat{P}(\hat{n})$ is provable.
Finally we have axioms for the existential quantifier
\begin{alignat*}{2}
&\forall \hat{x}^\alpha.\hat{P}(\hat{x}) \to
\ex \hat{x}^\alpha \hat{P}(\hat{x})
&\quad&\text{\texttt{Ex-Intro}\index{Ex-Intro@\texttt{Ex-Intro}}}
\\
&\ex \hat{x}^\alpha \hat{P}(\hat{x}) \to
(\forall \hat{x}^\alpha. \hat{P}(\hat{x})
\to \hat{Q}) \to \hat{Q}
&\quad&\text{\texttt{Ex-Elim}\index{Ex-Elim@\texttt{Ex-Elim}}}
\end{alignat*}
The assumption constants corresponding to these axioms are
\begin{alignat*}{2}
&\texttt{truth-aconst}\index{truth-aconst@\texttt{truth-aconst}}
&\quad&\text{for \texttt{Truth-Axiom}\index{Truth-Axiom@\texttt{Truth-Axiom}}}
\\[1ex]
&\texttt{eq-refl-aconst}\index{eq-refl-aconst@\texttt{eq-refl-aconst}}
&\quad&\text{for \texttt{Eq-Refl}\index{Eq-Refl@\texttt{Eq-Refl}}}
\\
&\texttt{eq-symm-aconst}\index{eq-symm-aconst@\texttt{eq-symm-aconst}}
&\quad&\text{for \texttt{Eq-Symm}\index{Eq-Symm@\texttt{Eq-Symm}}}
\\
&\texttt{eq-trans-aconst}\index{eq-trans-aconst@\texttt{eq-trans-aconst}}
&\quad&\text{for \texttt{Eq-Trans}\index{Eq-Trans@\texttt{Eq-Trans}}}
\\[1ex]
&\texttt{ext-aconst}\index{ext-aconst@\texttt{ext-aconst}}
&\quad&\text{for \texttt{Eq-Ext}\index{Eq-Ext@\texttt{Eq-Ext}}}
\\
&\texttt{eq-compat-aconst}\index{eq-compat-aconst@\texttt{eq-compat-aconst}}
&\quad&\text{for \texttt{Eq-Compat}\index{Eq-Compat@\texttt{Eq-Compat}}}
\\
&\texttt{total-aconst}\index{total-aconst@\texttt{total-aconst}}
&\quad&\text{for \texttt{Total}\index{Total@\texttt{Total}}}
\\[1ex]
&\texttt{(finalg-to-eq-to-=-1-aconst finalg)}%
\index{finalg-to-eq-to-=-1-aconst@\texttt{finalg-to-eq-to-=-1-aconst}}
&\quad&\text{for \texttt{Eq-to-=-1}\index{Eq-to-=-1@\texttt{Eq-to-=-1}}}
\\
&\texttt{(finalg-to-eq-to-=-2-aconst finalg)}%
\index{finalg-to-eq-to-=-2-aconst@\texttt{finalg-to-eq-to-=-2-aconst}}
&\quad&\text{for \texttt{Eq-to-=-2}\index{Eq-to-=-2@\texttt{Eq-to-=-2}}}
\\
&\texttt{(finalg-to-=-to-eq-aconst finalg)}%
\index{finalg-to-=-to-eq-aconst@\texttt{finalg-to-=-to-eq-aconst}}
&\quad&\text{for \texttt{=-to-Eq}\index{=-to-Eq@\texttt{=-to-Eq}}}
\\
&\texttt{(finalg-to-=-to-e-1-aconst finalg)}%
\index{finalg-to-=-to-e-1-aconst@\texttt{finalg-to-=-to-e-1-aconst}}
&\quad&\text{for \texttt{=-to-E-1}\index{=-to-E-1@\texttt{=-to-E-1}}}
\\
&\texttt{(finalg-to-=-to-e-2-aconst finalg)}%
\index{finalg-to-=-to-e-2-aconst@\texttt{finalg-to-=-to-e-2-aconst}}
&\quad&\text{for \texttt{=-to-E-2}\index{=-to-E-2@\texttt{=-to-E-2}}}
\\
&\texttt{(finalg-to-total-to-e-aconst finalg)}%
\index{finalg-to-total-to-e-aconst@\texttt{finalg-to-total-to-e-aconst}}
&\quad&\text{for \texttt{Total-to-E}\index{Total-to-E@\texttt{Total-to-E}}}
\\
&\texttt{(finalg-to-e-to-total-aconst finalg)}%
\index{finalg-to-e-to-total-aconst@\texttt{finalg-to-e-to-total-aconst}}
&\quad&\text{for \texttt{E-to-Total}\index{E-to-Total@\texttt{E-to-Total}}}
\\[1ex]
&\texttt{all-allpartial-aconst}%
\index{all-allpartial-aconst@\texttt{all-allpartial-aconst}}
&\quad&\text{for \texttt{All-AllPartial}%
\index{All-AllPartial@\texttt{All-AllPartial}}}
\\
&\texttt{allpartial-all-aconst}%
\index{allpartial-all-aconst@\texttt{allpartial-all-aconst}}
&\quad&\text{for \texttt{AllPartial-All}%
\index{AllPartial-All@\texttt{AllPartial-All}}}
\\
&\texttt{ex-expartial-aconst}%
\index{ex-expartial-aconst@\texttt{ex-expartial-aconst}}
&\quad&\text{for \texttt{Ex-ExPartial}%
\index{Ex-ExPartial@\texttt{Ex-ExPartial}}}
\\
&\texttt{expartial-ex-aconst}%
\index{expartial-ex-aconst@\texttt{expartial-ex-aconst}}
&\quad&\text{for \texttt{ExPartial-Ex}%
\index{ExPartial-Ex@\texttt{ExPartial-Ex}}}
\\[1ex]
&\texttt{(finalg-to-all-allpartial-aconst finalg)}%
\index{finalg-to-all-allpartial-aconst@\texttt{finalg-to-all-allpartial-aconst}}
&\quad&\text{for \texttt{All-AllPartial}%
\index{All-AllPartial@\texttt{All-AllPartial}}}
\\
&\texttt{(finalg-to-expartial-ex-aconst finalg)}%
\index{finalg-to-expartial-ex-aconst@\texttt{finalg-to-expartial-ex-aconst}}
&\quad&\text{for \texttt{ExPartial-Ex}%
\index{ExPartial-Ex@\texttt{ExPartial-Ex}}}
\end{alignat*}
% \paragraph{Induction axioms for simultaneous free algebras}
% \mylabel{SS:IndSFA}
We now spell out what precisely we mean by induction\index{induction}
over simultaneous free algebras $\vec{\mu} =
\mu\vec{\alpha}\,\vec{\kappa}$, with goal formulas $\forall
x_j^{\mu_j}\, \hat{P}_j(x_j)$. For the constructor type
\[
\kappa_i = \vec{\rho} \to (\vec{\sigma}_1 \to \alpha_{j_1}) \to \dots \to
(\vec{\sigma}_n \to \alpha_{j_n}) \to \alpha_j \in
\constrtypes(\vec{\alpha})
\]
we have the \emph{step formula}
\begin{align*}
D_i := \forall y_1^{\rho_1},\dots,y_m^{\rho_m},
y_{m+1}^{\vec{\sigma}_1 \to \mu_{j_1}},\dots,
y_{m+n}^{\vec{\sigma}_n \to \mu_{j_n}}.
&\forall \vec{x}^{\vec{\sigma}_1}\,
\hat{P}_{j_1}(y_{m+1}\vec{x}) \to \dots \to
\\
&\forall \vec{x}^{\vec{\sigma}_n}\,
\hat{P}_{j_n}(y_{m+n}\vec{x}) \to
\\
&\hat{P}_j(\constr_i^{\vec{\mu}}(\vec{y})).
\end{align*}
Here $\vec{y} = y_1^{\rho_1},\dots,y_m^{\rho_m},
y_{m+1}^{\vec{\sigma}_1 \to \mu_{j_1}},\dots,
y_{m+n}^{\vec{\sigma}_n \to \mu_{j_n}}$ are the
\emph{components} of the object $\constr_i^{\vec{\mu}}(\vec{y})$
of type $\mu_j$ under consideration, and
\[
\forall \vec{x}^{\vec{\sigma}_1}\,
\hat{P}_{j_1}(y_{m+1}\vec{x}), \dots,
\forall \vec{x}^{\vec{\sigma}_n}\,
\hat{P}_{j_n}(y_{m+n}\vec{x})
\]
are the hypotheses available when proving the induction step. The
induction axiom $\ind_{\mu_j}$\index{Ind@\texttt{Ind}} then
proves the formula
\[
\ind_{\mu_j} \colon
D_1 \to \dots \to D_k \to \forall x_j^{\mu_j}\, \hat{P}_j(x_j).
\]
We will often write $\ind_j$ for $\ind_{\mu_j}$.
An example is
\begin{alignat*}{2}
&E_1 \to E_2 \to E_3 \to E_4 \to \forall x_1^\tree \hat{P}_1(x_1)
\\
\intertext{with}
&E_1 := \hat{P}_1(\leaf),
\\
&E_2 := \forall x^{\tlist}.\hat{P}_2(x) \to \hat{P}_1(\branch(x)),
\\
&E_3 := \hat{P}_2(\empt),
\\
&E_4 := \forall x_1^{\tree},x_2^{\tlist}. \hat{P}_1(x_1) \to
\hat{P}_2(x_2) \to \hat{P}_2(\tcons(x_1,x_2)).
\end{alignat*}
Here the fact that we deal with a simultaneous induction (over
\texttt{tree} and \texttt{tlist}), and that we prove a formula of the
form $\forall x^\tree \dots$, can all be inferred from what is given:
the $\forall x^\tree \dots$ is right there, and for \texttt{tlist} we
can look up the simultaneously defined algebras. -- The internal
representation is
\begin{alignat*}{2}
&\texttt{(aconst Ind $E_1 \to E_2 \to E_3 \to E_4 \to
\forall x_1^\tree \hat{P}_1(x_1)$}
\\
&\qquad \qquad \qquad
\texttt{$(\hat{P}_1 \mapsto \set{x_1^\tree}{A_1},
\hat{P}_2 \mapsto \set{x_2^\tlist}{A_2})$)}
\index{Ind@\texttt{Ind}}
\end{alignat*}
A simplified version (without the recursive calls) of the induction
axiom is the following cases axiom.
\begin{alignat*}{2}
&\texttt{(aconst Cases $E_1 \to E_2 \to
\forall x_1^\tree \hat{P}_1(x_1)$
$(\hat{P}_1 \mapsto \set{x_1^\tree}{A_1})$)}
\index{Cases@\texttt{Cases}}
\\
\intertext{with}
&E_1 := \hat{P}_1(\leaf),
\\
&E_2 := \forall x^{\tlist} \hat{P}_1(\branch(x)).
\end{alignat*}
However, rather than using this as an assumption constant we will --
parallel to the
\texttt{if}-construct\index{if-construct@\texttt{if}-construct} for
terms -- use a
\texttt{cases}-construct\index{cases-construct@\texttt{cases}-construct}
for proofs. This does not change our notion of proof; it is done to
have the \texttt{if}-construct in the extracted programs.
The assumption constants corresponding to these axioms are generated by
\begin{alignat*}{2}
&\texttt{(all-formulas-to-ind-aconst \textsl{all-formula1} \dots)}
\index{all-formulas-to-ind-aconst@\texttt{all-formulas-to-ind-aconst}}
&\quad&\text{for \texttt{Ind}\index{Ind@\texttt{Ind}}}
\\
&\texttt{(all-formula-to-cases-aconst \textsl{all-formula})}
\index{all-formula-to-cases-aconst@\texttt{all-formula-to-cases-aconst}}
&\quad&\text{for \texttt{Cases}\index{Cases@\texttt{Cases}}}
\end{alignat*}
% To deal with equality we need
% \begin{alignat*}{2}
% %
% &\texttt{(refl-at \textsl{finalg})}
% \index{refl-at@\texttt{refl-at}}
% &\quad&\colon x=x\\
% %
% &\texttt{(=-ax-at \textsl{finalg})}
% \index{equal-ax-at@\texttt{=-ax-at}}
% &&\colon x_1 = x_2 \to \hat{P} x_1 \to \hat{P} x_2.
% %
% \end{alignat*}
For the introduction and elimination axioms
\texttt{Ex-Intro}\index{Ex-Intro@\texttt{Ex-Intro}} and
\texttt{Ex-Elim}\index{Ex-Elim@\texttt{Ex-Elim}} for the existential
quantifier we provide
\begin{align*}
&\texttt{(ex-formula-to-ex-intro-aconst ex-formula)}%
\index{ex-formula-to-ex-intro-aconst@\texttt{ex-formula-to-ex-intro-aconst}}
\\
&\texttt{(ex-formula-and-concl-to-ex-elim-aconst ex-formula concl)}%
\index{ex-formula-and-concl-to-ex-elim-const@\texttt{ex-for{\dots}-to-ex-elim-const}}
\end{align*}
and similarly for \texttt{exnc} instead of \texttt{ex}.
To deal with inductively defined predicate constants, we need
additional axioms with names \inquotes{Intro}\index{Intro} and
\inquotes{Elim}\index{Elim}, which can be generated by
\begin{align*}
&\texttt{(number-and-idpredconst-to-intro-aconst i idpc)}%
\index{number-and-idpredconst-to-intro-aconst@\texttt{number-and-idpredconst-to-intro-aconst}}
\\
&\texttt{(imp-formulas-to-elim-aconst imp-formula1\ \dots)};%
\index{imp-formulas-to-elim-aconst@\texttt{imp-formulas-to-elim-aconst}}
\end{align*}
here an \texttt{imp-formula} is expected to have the form $I(\vec{x}) \to A$.
\subsection{Theorems}
\mylabel{SS:Theorems}
A theorem is a special assumption constant.
% A typical example is
% the transitivity of the successor function, with the internal
% representation
% \begin{alignat*}{2}
% %
% &\texttt{(aconst Trans-Suc $\forall k,m,n. k<m \to k<n+1 \to k<n$
% \textsl{empty-subst})}
% \index{Trans-Suc@\texttt{Trans-Suc}}
% %
% \end{alignat*}
Theorems are normally created after successfully completing an
interactive proof. One may also create a theorem from an explicitely
given (closed) proof. The command is
\begin{alignat*}{2}
&\texttt{(add-theorem \textsl{string} .\ \textsl{opt-proof})}%
\index{add-theorem@\texttt{add-theorem}}
&\quad&\text{or \texttt{save}\index{save@\texttt{save}}}
\end{alignat*}
From a theorem name we can access its aconst, its (original) proof and
also its instantiated proof by
\begin{align*}
&\texttt{(theorem-name-to-aconst \textsl{string})}
\index{theorem-name-to-aconst@\texttt{theorem-name-to-aconst}}
\\
&\texttt{(theorem-name-to-proof \textsl{string})}
\index{theorem-name-to-proof@\texttt{theorem-name-to-proof}}
\\
&\texttt{(theorem-name-to-inst-proof \textsl{string})}
\index{theorem-name-to-inst-proof@\texttt{theorem-name-to-inst-proof}}
% \\
% &\texttt{(theorem-name-to-eterm \textsl{string})}
% \index{theorem-name-to-eterm@\texttt{theorem-name-to-eterm}}
\end{align*}
We also provide
\begin{align*}
&\texttt{(remove-theorem \textsl{string1} \dots)}
\index{remove-theorem@\texttt{remove-theorem}}
\\
&\texttt{(display-theorems \textsl{string1} \dots)}
\index{display-theorems@\texttt{display-theorems}}
\end{align*}
% \paragraph{Simple consequences of the axioms}
% \mylabel{SS:ConseqAx}
Initially we provide the following theorems
\begin{alignat*}{2}
&\atom(p) \to p = \true
&\quad&\text{\texttt{Atom-True}\index{Atom-True@\texttt{Atom-True}}}
\\
&(\atom(p) \to F) \to p = \false
&&\text{\texttt{Atom-False}\index{Atom-False@\texttt{Atom-False}}}
\\
&F \to \atom(p)
&&\text{\texttt{Efq-Atom}\index{Efq-Atom@\texttt{Efq-Atom}}}
\\
&((\atom(p) \to F) \to F) \to \atom(p)
&&\text{\texttt{Stab-Atom}\index{Stab-Atom@\texttt{Stab-Atom}}}
\\
\intertext{and for every finitary algebra, e.g.\ \texttt{nat}}
&n=n
&&\text{\texttt{=-Refl-nat}%
\index{equalfinalg-Refl-nat@\texttt{=-Refl-nat}}}
\\
&\hat{n}_1 = \hat{n}_2 \to \hat{n}_2 = \hat{n}_1
&&\text{\texttt{=-Symm-nat}%
\index{equalfinalg-Symm-nat@\texttt{=-Symm-nat}}}%
\\
&\hat{n}_1 = \hat{n}_2 \to \hat{n}_2 = \hat{n}_3 \to \hat{n}_1 = \hat{n}_3
&&\text{\texttt{=-Trans-nat}%
\index{equalfinalg-Trans-nat@\texttt{=-Trans-nat}}}
\end{alignat*}
% \begin{lemma}[\texttt{Atom-True}\index{Atom-True@\texttt{Atom-True}}]
% $\atom(p) \to p = \true$.
% \end{lemma}
\begin{proof}[Proof of \texttt{Atom-True}]
By \texttt{Ind}. In case $\true$ use \texttt{Eq-Compat} with
$\true \Eq \eqrel{\true}{\true}$ to infer
$\atom(\eqrel{\true}{\true})$ (i.e.\ $\true = \true$) from
$\atom(\true)$. In case $\false$ use \texttt{Eq-Compat} with
$\false \Eq \eqrel{\false}{\true}$ to infer
$\atom(\eqrel{\false}{\true})$ (i.e.\ $\false = \true$) from
$\atom(\false)$.
\end{proof}
% \begin{lemma}[\texttt{Atom-False}\index{Atom-False@\texttt{Atom-False}}]
% $(\atom(p) \to F) \to p = \false$.
% \end{lemma}
\begin{proof}[Proof of \texttt{Atom-False}]
Use \texttt{Ind}, and \texttt{Truth-Axiom} in both cases. -- Notice
that the more general $(\atom(\hat{p}) \to F) \to \hat{p} = \false$
does \emph{not} hold with $\bottom$ for $\hat{p}$, since
$\eqrel{\bottom}{\false} \Eq \bottom$.
\end{proof}
% \begin{lemma}[\texttt{Efq-Atom}\index{Efq-Atom@\texttt{Efq-Atom}}]
% $F \to \atom(p)$.
% \end{lemma}
\begin{proof}[Proof of \texttt{Efq-Atom}]
Again by \texttt{Ind}. In case $\true$ use \texttt{Truth-Axiom}, and
the case $\false$ is obvious.
\end{proof}
% We can even prove the following stronger stability lemma, which
% can be seen as establishing the principle of \indexentry{indirect
% proof} (i.e.\ of classical logic) for decidable formulas.
% \begin{lemma}[\texttt{Stab-Atom}\index{Stab-Atom@\texttt{Stab-Atom}}]
% $((\atom(p) \to F) \to F) \to \atom(p)$.
% \end{lemma}
\begin{proof}[Proof of \texttt{Stab-Atom}]
By \texttt{Ind}. In case $\true$ use \texttt{Truth-Axiom}, and the
case $\false$ is obvious.
\end{proof}
\begin{remark*}
Notice that from $\texttt{Efq-Atom}$ one easily obtains $F \to A$ for
every formula $A$ all whose strictly positions occurrences of prime
formulas are of the form $\atom(r)$, by induction on $A$. For all
other formulas we shall make use of the global assumption
$\texttt{Efq} \colon F \to \hat{P}$ (cf.\ Section~\ref{SS:GlobalAss}).
Similarly, Notice that from $\texttt{Stab-Atom}$ one again obtains
$((A \to F) \to F) \to A$ for every formula $A$ all whose strictly
positions occurrences of prime formulas are of the form $\atom(r)$, by
induction on $A$. For all other formulas we shall make use of the
global assumption $\texttt{Stab} \colon ((\hat{P} \to F) \to F) \to
\hat{P}$ (cf.\ Section~\ref{SS:GlobalAss}).
\end{remark*}
% \begin{lemma}[\texttt{Eq-to-=}\index{Eq-to-=@\texttt{Eq-to-=}}]
% $\hat{n}_1 \Eq \hat{n}_2 \to E(\hat{n}_1) \to E(\hat{n}_2) \to
% \hat{n}_1 = \hat{n}_2$.
% \end{lemma}
% \begin{proof}
% By \texttt{Gen-Ind} on $\hat{n}_1$. In case $\bottom$ notice that the
% premise $E(\bottom)$ and the conclusion $\bottom = \hat{n}_2$ are both
% equivalent to $\atom(\bottom)$.
% In case $0$ for $\hat{n}_1$ we distinguish subcases according to the
% constructor form of $\hat{n}_2$. In the subcase $\bottom$ for
% $\hat{n}_2$ we argue as before. In the subcase $0$ for $\hat{n}_2$
% the conclusion $0=0$ follows from $\texttt{Truth-Axiom}$. In the
% subcase $S \hat{n}_2$ for $\hat{n}_2$ from $0 \Eq S \hat{n}_2$ infer
% $F$ by $\texttt{Constr-Disjoint}$ and then $0 = S \hat{n}_2$ from
% $\texttt{Efq-Atom}$.
% In the step case for $\hat{n}_1$ we again distinguish subcases
% according to the constructor form of $\hat{n}_2$. The subcases
% $\bottom$ and $0$ for $\hat{n}_2$ are treated as before. In the
% subcase $S \hat{n}_2$ for $\hat{n}_2$ from $S \hat{n}_1 \Eq S
% \hat{n}_2$ infer $\hat{n}_1 \Eq \hat{n}_2$ by $\texttt{Constr-Inj}$,
% and also from $E(S \hat{n}_i)$ infer $E(\hat{n}_i)$ using $e(S
% \hat{n}) \Eq e(\hat{n})$. Now the IH yields $\hat{n}_1 = \hat{n}_2$,
% hence $S \hat{n}_1 = S \hat{n}_2$, using $\eqrel{S \hat{n}_1}{S
% \hat{n}_2} \Eq \eqrel{\hat{n}_1}{\hat{n}_2}$.
% \end{proof}
% \begin{lemma}[\texttt{=-to-Eq}\index{equals-to-Eq@\texttt{=-to-Eq}}]
% $\hat{n}_1 = \hat{n}_2 \to \hat{n}_1 \Eq \hat{n}_2$.
% \end{lemma}
% \begin{proof}
% By \texttt{Gen-Ind} on $\hat{n}_1$. In case $\bottom$ the premise is
% equivalent to $\atom(\bottom)$. Now use $\texttt{Bottom-to-F}$
% and $\texttt{Efq-Eq}$.
% In case $0$ for $\hat{n}_1$ we distinguish subcases according to the
% constructor form of $\hat{n}_2$. In the subcase $\bottom$ for
% $\hat{n}_2$ we argue as before. In the subcase $0$ for $\hat{n}_2$
% the conclusion $0 \Eq 0$ follows from $\texttt{Eq-Refl}$. In the
% subcase $S \hat{n}_2$ for $\hat{n}_2$ the premise $0 = S \hat{n}_2$ is
% equivalent to $\atom(\bottom)$. Now again use $\texttt{Bottom-to-F}$
% and $\texttt{Efq-Eq}$.
% In the step case for $\hat{n}_1$ we again distinguish subcases
% according to the constructor form of $\hat{n}_2$. The subcases
% $\bottom$ and $0$ for $\hat{n}_2$ are treated as before. In the
% subcase $S \hat{n}_2$ for $\hat{n}_2$ from $S \hat{n}_1 = S \hat{n}_2$
% infer $\hat{n}_1 = \hat{n}_2$ (using $\eqrel{S \hat{n}_1}{S \hat{n}_2}
% \Eq \eqrel{\hat{n}_1}{\hat{n}_2}$). Now the IH yields $\hat{n}_1 \Eq
% \hat{n}_2$, hence $S \hat{n}_1 \Eq S \hat{n}_2$, using
% $\texttt{Eq-Compat}$ and $\texttt{Eq-Refl}$.
% \end{proof}
% \begin{lemma}[\texttt{=-to-E}\index{equals-to-E@\texttt{=-to-E}}]
% $\hat{n}_1 = \hat{n}_2 \to E(\hat{n}_i)$.
% \end{lemma}
% \begin{proof}
% By \texttt{Gen-Ind} on $\hat{n}_1$. In case $\bottom$ the premise is
% equivalent to $\atom(\bottom)$. Now use $\texttt{Bottom-to-F}$
% and $\texttt{Efq-Atom}$.
% In case $0$ for $\hat{n}_1$ we distinguish subcases according to the
% constructor form of $\hat{n}_2$. In the subcase $\bottom$ for
% $\hat{n}_2$ we argue as before. In the subcase $0$ for $\hat{n}_2$
% the conclusion $E(0)$ follows from $\texttt{Atom-True}$. In the
% subcase $S \hat{n}_2$ for $\hat{n}_2$ the premise $0 = S \hat{n}_2$ is
% equivalent to $\atom(\bottom)$. Now again use $\texttt{Bottom-to-F}$
% and $\texttt{Efq-Atom}$.
% In the step case for $\hat{n}_1$ we again distinguish subcases
% according to the constructor form of $\hat{n}_2$. The subcases
% $\bottom$ and $0$ for $\hat{n}_2$ are treated as before. In the
% subcase $S \hat{n}_2$ for $\hat{n}_2$ from $S \hat{n}_1 = S \hat{n}_2$
% infer $\hat{n}_1 = \hat{n}_2$ (using $\eqrel{S \hat{n}_1}{S \hat{n}_2}
% \Eq \eqrel{\hat{n}_1}{\hat{n}_2}$). The IH yields $E(\hat{n}_i)$,
% hence $E(S \hat{n}_i)$, using $e(S \hat{n}_i) \Eq e(\hat{n}_i)$.
% \end{proof}
% \begin{lemma}[\texttt{Total-to-E}\index{Total-to-E@\texttt{Total-to-E}}]
% $\Total(\hat{n}) \to E(\hat{n})$.
% \end{lemma}
% \begin{proof}
% By \texttt{Gen-Ind}. In case $\bottom$ use \texttt{Bottom-not-Total}
% and \texttt{Efq-Atom}, and in case $0$ use $E(0)$. For the step prove
% \[
% (\Total(\hat{n}) \to E(\hat{n})) \to \Total(S \hat{n}) \to E(S
% \hat{n}),
% \]
% using $\Total(S \hat{n}) \to \Total(\hat{n})$, i.e.\
% \texttt{Constr-Total-Args}, and $E(\hat{n}) \to E(S \hat{n})$; the
% latter follows from $e(S \hat{n}) \Eq e(\hat{n})$.
% \end{proof}
% \begin{lemma}[\texttt{E-to-Total}\index{E-to-Total@\texttt{E-to-Total}}]
% $E(\hat{n}) \to \Total(\hat{n})$.
% \end{lemma}
% \begin{proof}
% By \texttt{Gen-Ind}. In case $\bottom$ use $\texttt{Bottom-to-F}
% \colon \atom(\bottom) \to F$ and $\texttt{Efq-Total} \colon
% F \to \Total(\bottom)$, and in case $0$ use $\texttt{Constr-Total}$.
% For the step prove
% \[
% (E(\hat{n}) \to \Total(\hat{n})) \to E(S \hat{n}) \to \Total(S
% \hat{n}),
% \]
% using $E(S \hat{n}) \to E(\hat{n})$ (from $e(S \hat{n}) \Eq
% e(\hat{n})$), and $\Total(\hat{n}) \to \Total(S \hat{n})$; the
% latter follows from $\Total(S)$, i.e.\ $\texttt{Constr-Total}$.
% \end{proof}
% Then one can derive from general induction the form of induction
% one normally wants to apply.
% \begin{lemma}[\texttt{Ind}]
% \mylabel{L:Ind}
% $\hat{P}(0) \to (\forall n.\hat{P}(n) \to \hat{P}(S n)) \to
% \forall n \hat{P}(n)$.
% \end{lemma}
% \begin{proof}%[Proof of \texttt{Ind} for $\nat$]
% By general induction applied to the formula $E(\hat{n}) \to
% \hat{P}(\hat{n})$. In case $\bottom$ use $\texttt{E-to-Total}$ and
% $\texttt{Bottom-not-Total}$ to conclude $E(\bottom) \to F$, and then
% the global assumption $\texttt{Efq} \colon F \to \hat{P}(\bottom)$.
% The case $0$ is clear, and in the step case we need to prove $\forall
% \hat{n}.(E(\hat{n}) \to \hat{P}(\hat{n})) \to E(S \hat{n}) \to
% \hat{P}(S \hat{n})$ from $\forall \hat{n}.E(\hat{n}) \to
% \hat{P}(\hat{n}) \to \hat{P}(S \hat{n})$. This follows from
% $\texttt{Constr-Total-Args}$, yielding $E(S \hat{n}) \to E(\hat{n})$.
% \end{proof}
% \begin{remark}
% Notice that every instance
% \[
% \subst{A}{x}{0} \to (\forall n.\subst{A}{x}{n} \to \subst{A}{x}{S n}) \to
% \forall n \subst{A}{x}{n}
% \]
% of \texttt{Ind} for a formula $A$ without strictly positive
% occurrences of predicate variables can be derived without using the
% global assumption $\texttt{Efq}$.
% \end{remark}
% \begin{lemma}[\texttt{=-Refl-nat}%
% \index{equalfinalg-Refl-nat@\texttt{=-Refl-nat}}]
% $n=n$.
% \end{lemma}
\begin{proof}[Proof of \texttt{=-Refl-nat}]
Use \texttt{Ind}, and \texttt{Truth-Axiom} in both cases. -- Notice
that $\hat{n} = \hat{n}$ does \emph{not} hold, since
$\eqrel{\bottom}{\bottom} \Eq \bottom$.
\end{proof}
% We can also derive easily
% \begin{alignat*}{2}
% %
% &\hat{n}_1 = \hat{n}_2 \to \hat{n}_2 = \hat{n}_1
% &\quad&\text{\texttt{=-Symm-nat}}%
% \index{equalfinalg-Symm-nat@\texttt{=-Symm-nat}}
% \\
% &\hat{n}_1 = \hat{n}_2 \to \hat{n}_2 = \hat{n}_3 \to \hat{n}_1 = \hat{n}_3
% &\quad&\text{\texttt{=-Trans-nat}}%
% \index{equalfinalg-Trans-nat@\texttt{=-Trans-nat}}
% \\[1ex]
% &\hat{n}_1 = \hat{n}_2 \to E(\hat{n}_i)
% \\
% &0 = S \hat{n} \to F
% \\
% &S \hat{n}_1 = S \hat{n}_2 \to \hat{n}_1 = \hat{n}_2
% \\[1ex]
% &E(S \hat{n}) \to E(\hat{n})
% \\
% &E(0)
% \\
% &E(\hat{n}) \to E(S \hat{n})
%
% \end{alignat*}
% The following theorems are proved easily by boolean induction.
% \begin{alignat*}{2}
% %
% &\texttt{(aconst Efq-thm $\forall p. F \to p$ \textsl{empty-subst})}
% \index{Efq-thm@\texttt{Efq-thm}}
% \\
% &\texttt{(aconst Stab-thm $\forall p. ((p \to F) \to F) \to p$
% \textsl{empty-subst})}
% \index{Stab-thm@\texttt{Stab-thm}}
% \\
% &\texttt{(aconst Atomtrue $\forall p. p \to p = \true$
% \textsl{empty-subst})}
% \index{Atomtrue@\texttt{Atomtrue}}
% \\
% &\texttt{(aconst Atomfalse $\forall p. (p \to F) \to p = \false$
% \textsl{empty-subst})}
% \index{Atomfalse@\texttt{Atomfalse}}
% %
% \end{alignat*}
Here are some other examples of theorems; we give the internal
representation as assumption constants, which show how the assumed
formula is split into an uninstantiated formula and a substitution, in
this case a type substitution $\alpha \mapsto \rho$, an object
substitution $f^{\alpha \to \nat} \mapsto g^{\rho \to \nat}$ and a
predicate variable substitution $\hat{P}^{(\alpha)} \mapsto
\set{\hat{z}^\rho}{A}$.
\begin{alignat*}{2}
&\texttt{(aconst Cvind-with-measure-11}
\\
&\qquad \qquad \qquad\texttt{$
\forall f^{\alpha \to \nat}.
\bigl(\forall x^\alpha.\forall y(f(y) {<} f(x) \to \hat{P}(y)) \to
\hat{P}(x) \bigr) \to
\forall x \hat{P}(x)$}
\\
&\qquad \qquad \qquad
\texttt{$(\alpha \mapsto \rho,
f^{\alpha \to \nat} \mapsto g^{\rho \to \nat},
\hat{P}^{(\alpha)} \mapsto \set{\hat{z}^\rho}{A})$).}
\index{Cvind-with-measure-11@\texttt{Cvind-with-measure-11}}
\\
&\texttt{(aconst Minpr-with-measure-l11}
\\
&\qquad \qquad \qquad\texttt{$
\forall f^{\alpha \to \nat}.
\excl x^\alpha \hat{P}(x) \to \excl x.\hat{P}(x) !
\forall y.f(y) {<} f(x) \to \hat{P}(y) \to \bot$}
\\
&\qquad \qquad \qquad
\texttt{$(\alpha \mapsto \rho,
f^{\alpha \to \nat} \mapsto g^{\rho \to \nat},
\hat{P}^{(\alpha)} \mapsto \set{\hat{z}^\rho}{A})$).}
\index{Minpr-with-measure-l11@\texttt{Minpr-with-measure-l11}}
\end{alignat*}
Here $\excl$ is the classical existential quantifier defined by $\excl
x A := \forall x(A \to \bot) \to \bot$ with the logical form of
falsity $\bot$ (as opposed to the arithmetical form $(\texttt{atom}\
\false)$). \texttt{l} indicates \inquotes{logic} (we have used the
logical form of falsity), the first \texttt{1} that we have one
predicate variable $\hat{P}$, and the second that we quantify over just one
variable $x$. Both theorems can easily be generalized to more such
parameters.
When dealing with classical logic it will be useful to have
\begin{alignat*}{2}
&(\hat{P} \to \hat{P}_1) \to
((\hat{P} \to \bot) \to \hat{P}_1) \to \hat{P}_1
&\quad&\text{\texttt{Cases-Log}\index{Cases-Log@\texttt{Cases-Log}}}
\end{alignat*}
The proof uses the global assumption \texttt{Stab-Log} (see below) for
$\hat{P}_1$; hence we cannot extract a term from it.
The assumption constants corresponding to these theorems are
generated by
\begin{alignat*}{2}
&\texttt{(theorem-name-to-aconst \textsl{name})}%
\index{theorem-name-to-aconst@\texttt{theorem-name-to-aconst}}
\end{alignat*}
\subsection{Global assumptions}
\mylabel{SS:GlobalAss}
A global assumption\index{global assumption} is a special assumption
constant. It provides a proposition whose proof does not concern us
pre\-sent\-ly. Global assumptions are added, removed and displayed by
\begin{align*}
&\texttt{(add-global-assumption \textsl{name} \textsl{formula})}
\index{add-global-assumption@\texttt{add-global-assumption}}
\quad \hbox{(abbreviated \texttt{aga}\index{aga@\texttt{aga}})}
\\
&\texttt{(remove-global-assumption \textsl{string1} \dots)}
\index{remove-global-assumption@\texttt{remove-global-assumption}}
\\
&\texttt{(display-global-assumptions \textsl{string1} \dots)}
\index{display-global-assumptions@\texttt{display-global-assumptions}}
\end{align*}
We initially supply global assumptions for ex-falso-quodlibet and
stability, both in logical and arithmetical form (for our two
forms of falsity).
\begin{alignat*}{2}
&\bot \to \hat{P}
&\quad&\text{\texttt{Efq-Log}\index{Efq-Log@\texttt{Efq-Log}}}
\\
&((\hat{P} \to \bot) \to \bot) \to \hat{P}
&\quad&\text{\texttt{Stab-Log}\index{Stab-Log@\texttt{Stab-Log}}}
\\
&F \to \hat{P}
&\quad&\text{\texttt{Efq}\index{Efq@\texttt{Efq}}}
\\
&((\hat{P} \to F) \to F) \to \hat{P}
&\quad&\text{\texttt{Stab}\index{Stab@\texttt{Stab}}}
\end{alignat*}
The assumption constants corresponding to these global assumptions are
generated by
\begin{alignat*}{2}
&\texttt{(global-assumption-name-to-aconst \textsl{name})}%
\index{global-assumption-name-to-aconst@\texttt{global-ass{dots}-name-to-aconst}}
\end{alignat*}
\section{Proofs}
\mylabel{Proof}
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 \emph{context}\index{context}, which is an ordered
list of object and assumption variables.
\subsection{Constructors and accessors}
We have constructors, accessors and tests for assumption variables
\begin{alignat*}{2}
&\texttt{(make-proof-in-avar-form \textsl{avar})}
\index{make-proof-in-avar-form@\texttt{make-proof-in-avar-form}}
&\quad& \text{constructor}
\\
&\texttt{(proof-in-avar-form-to-avar \textsl{proof})}
\index{proof-in-avar-form-to-avar@\texttt{proof-in-avar-form-to-avar}}
&& \text{accessor,}
\\
&\texttt{(proof-in-avar-form?\ \textsl{proof})}
\index{proof-in-avar-form?@\texttt{proof-in-avar-form?}}
&& \text{test,}
\end{alignat*}
for assumption constants
\begin{alignat*}{2}
&\texttt{(make-proof-in-aconst-form \textsl{aconst})}
\index{make-proof-in-aconst-form@\texttt{make-proof-in-aconst-form}}
&\quad& \text{constructor}
\\
&\texttt{(proof-in-aconst-form-to-aconst \textsl{proof})}
\index{proof-in-aconst-form-to-aconst@\texttt{proof-in-aconst-form-to-aconst}}
&& \text{accessor}
\\
&\texttt{(proof-in-aconst-form?\ \textsl{proof})}
\index{proof-in-aconst-form?@\texttt{proof-in-aconst-form?}}
&& \text{test,}
\end{alignat*}
for implication introduction
\begin{alignat*}{2}
&\texttt{(make-proof-in-imp-intro-form \textsl{avar} \textsl{proof})}
\index{make-proof-in-imp-intro-form@\texttt{make-proof-in-imp-intro-form}}
&\quad& \text{constructor}
\\
&\texttt{(proof-in-imp-intro-form-to-avar \textsl{proof})}
\index{proof-in-imp-intro-form-to-avar@\texttt{proof-in-imp-intro-form-to-avar}}
&&\text{accessor}
\\
&\texttt{(proof-in-imp-intro-form-to-kernel \textsl{proof})}
\index{proof-in-imp-intro-form-to-kernel@\texttt{pr{\dots}-imp-intro-form-to-kernel}}
&&\text{accessor}
\\
&\texttt{(proof-in-imp-intro-form?\ \textsl{proof})}
\index{proof-in-imp-intro-form?@\texttt{proof-in-imp-intro-form?}}
&& \text{test,}
\end{alignat*}
for implication elimination
\begin{alignat*}{2}
&\texttt{(make-proof-in-imp-elim-form \textsl{proof1} \textsl{proof2})}
\index{make-proof-in-imp-elim-form@\texttt{make-proof-in-imp-elim-form}}
&\quad& \text{constructor}
\\
&\texttt{(proof-in-imp-elim-form-to-op \textsl{proof})}
\index{proof-in-imp-elim-form-to-op@\texttt{proof-in-imp-elim-form-to-op}}
&& \text{accessor}
\\
&\texttt{(proof-in-imp-elim-form-to-arg \textsl{proof})}
\index{proof-in-imp-elim-form-to-arg@\texttt{proof-in-imp-elim-form-to-arg}}
&& \text{accessor}
\\
&\texttt{(proof-in-imp-elim-form?\ \textsl{proof})}
\index{proof-in-imp-elim-form?@\texttt{proof-in-imp-elim-form?}}
&& \text{test,}
\end{alignat*}
for and introduction
\begin{alignat*}{2}
&\texttt{(make-proof-in-and-intro-form \textsl{proof1} \textsl{proof2})}
\index{make-proof-in-and-intro-form@\texttt{make-proof-in-and-intro-form}}
&\quad& \text{constructor}
\\
&\texttt{(proof-in-and-intro-form-to-left \textsl{proof})}
\index{proof-in-and-intro-form-to-left@\texttt{pr{\dots}and-intro-form-to-left}}
&&\text{accessor}
\\
&\texttt{(proof-in-and-intro-form-to-right \textsl{proof})}
\index{proof-in-and-intro-form-to-right@\texttt{pr{\dots}and-intro-form-to-right}}
&&\text{accessor}
\\
&\texttt{(proof-in-and-intro-form?\ \textsl{proof})}
\index{proof-in-and-intro-form?@\texttt{proof-in-and-intro-form?}}
&& \text{test,}
\end{alignat*}
for and elimination
\begin{alignat*}{2}
&\texttt{(make-proof-in-and-elim-left-form \textsl{proof})}
\index{make-proof-in-and-elim-left-form@\texttt{make-proof-in-and-elim-l{\dots}}}
&\quad& \text{constructor}
\\
&\texttt{(make-proof-in-and-elim-right-form \textsl{proof})}
\index{make-proof-in-and-elim-right-form@\texttt{make-proof-in-and-elim-r{\dots}}}
&& \text{constructor}
\\
&\texttt{(proof-in-and-elim-left-form-to-kernel \textsl{proof})}
\index{proof-in-and-elim-left-form-to-kernel@\texttt{proof-in-and-elim{\dots}}}
&& \text{accessor}
\\
&\texttt{(proof-in-and-elim-right-form-to-kernel \textsl{proof})}
\index{proof-in-and-elim-right-form-to-kernel@\texttt{proof-in-and-elim{\dots}}}
&& \text{accessor}
\\
&\texttt{(proof-in-and-elim-left-form?\ \textsl{proof})}
\index{proof-in-and-elim-left-form?@\texttt{proof-in-and-elim-left-form?}}
&& \text{test}
\\
&\texttt{(proof-in-and-elim-right-form?\ \textsl{proof})}
\index{proof-in-and-elim-right-form?@\texttt{proof-in-and-elim-right-form?}}
&& \text{test,}
\end{alignat*}
for all introduction
\begin{alignat*}{2}
&\texttt{(make-proof-in-all-intro-form \textsl{var} \textsl{proof})}
\index{make-proof-in-all-intro-form@\texttt{make-proof-in-all-intro-form}}
&\quad& \text{constructor}
\\
&\texttt{(proof-in-all-intro-form-to-var \textsl{proof})}
\index{proof-in-all-intro-form-to-var@\texttt{pr{\dots}all-intro-form-to-var}}
&& \text{accessor}
\\
&\texttt{(proof-in-all-intro-form-to-kernel \textsl{proof})}
\index{proof-in-all-intro-form-to-kernel@\texttt{pr{\dots}all-intro-form-to-kernel}}
&& \text{accessor}
\\
&\texttt{(proof-in-all-intro-form?\ \textsl{proof})}
\index{proof-in-all-intro-form?@\texttt{proof-in-all-intro-form?}}
&& \text{test,}
\end{alignat*}
for all elimination
\begin{alignat*}{2}
&\texttt{(make-proof-in-all-elim-form \textsl{proof} \textsl{term})}
\index{make-proof-in-all-elim-form@\texttt{make-proof-in-all-elim-form}}
&\quad& \text{constructor}
\\
&\texttt{(proof-in-all-elim-form-to-op \textsl{proof})}
\index{proof-in-all-elim-form-to-op@\texttt{proof-in-all-elim-form-to-op}}
&& \text{accessor}
\\
&\texttt{(proof-in-all-elim-form-to-arg \textsl{proof})}
\index{proof-in-all-elim-form-to-arg@\texttt{proof-in-all-elim-form-to-arg}}
&& \text{accessor}
\\
&\texttt{(proof-in-all-elim-form?\ \textsl{proof})}
\index{proof-in-all-elim-form?@\texttt{proof-in-all-elim-form?}}
&& \text{test}
\end{alignat*}
and for \texttt{cases}-constructs
\begin{alignat*}{2}
&\texttt{(make-proof-in-cases-form \textsl{test} \textsl{alt1} \dots)}
\index{make-proof-in-cases-form@\texttt{make-proof-in-cases-form}}
&\quad& \text{constructor}
\\
&\texttt{(proof-in-cases-form-to-test \textsl{proof})}
\index{proof-in-cases-form-to-test@\texttt{proof-in-cases-form-to-test}}
&& \text{accessor}
\\
&\texttt{(proof-in-cases-form-to-alts \textsl{proof})}
\index{proof-in-cases-form-to-alts@\texttt{proof-in-cases-form-to-alts}}
&& \text{accessor}
\\
&\texttt{(proof-in-cases-form-to-rest \textsl{proof})}
\index{proof-in-cases-form-to-rest@\texttt{proof-in-cases-form-to-rest}}
&& \text{accessor}
\\
&\texttt{(proof-in-cases-form?\ \textsl{proof})}
\index{proof-in-cases-form?@\texttt{proof-in-cases-form?}}
&& \text{test.}
\end{alignat*}
It is convenient to have more general introduction and elimination
operators that take arbitrary many arguments. The former works for
implication-introduction and all-introduction, and the latter for
implication-elimination, and-elimination and all-elimination.
\begin{alignat*}{2}
&\texttt{(mk-proof-in-intro-form \textsl{x1} \dots\ \textsl{proof})}
\index{mk-proof-in-intro-form@\texttt{mk-proof-in-intro-form}}
\\
&\texttt{(mk-proof-in-elim-form \textsl{proof} \textsl{arg1} \dots)}
\index{mk-proof-in-elim-form@\texttt{mk-proof-in-elim-form}}
\\
&\texttt{(proof-in-intro-form-to-kernel-and-vars \textsl{proof})}
\index{proof-in-intro-form-to-kernel-and-vars@\texttt{proof-in-intro-form-to{\dots}}}
\\
&\texttt{(proof-in-elim-form-to-final-op \textsl{proof})}
\index{proof-in-elim-form-to-final-op@\texttt{pr{\dots}elim-form-to-final-op}}
\\
&\texttt{(proof-in-elim-form-to-args \textsl{proof}).}
\index{proof-in-elim-form-to-args@\texttt{proof-in-elim-form-to-args}}
\end{alignat*}
\texttt{(mk-proof-in-intro-form \textsl{x1} \dots\ \textsl{proof})} is
formed from proof by first abstracting \textsl{x1}, then \textsl{x2}
and so on. Here \textsl{x1}, \textsl{x2} \dots can be assumption or
object variables. We also provide
\begin{alignat*}{2}
&\texttt{(mk-proof-in-and-intro-form \textsl{proof} \textsl{proof1} \dots)}
\index{mk-proof-in-and-intro-form@\texttt{mk-proof-in-and-intro-form}}
\end{alignat*}
In our setup there are axioms rather than rules for the existential
quantifier. However, sometimes it is useful to construct proofs as if
an existence introduction rule would be present; internally then an
existence introduction axiom is used.
\begin{alignat*}{2}
&\texttt{(make-proof-in-ex-intro-form \textsl{term} \textsl{ex-formula}
\textsl{proof-of-inst})}
\index{make-proof-in-ex-intro-form@\texttt{make-proof-in-ex-intro-form}}
\\
&\texttt{(mk-proof-in-ex-intro-form\ .\ }
\\
&\quad\texttt{\textsl{terms-and-ex-formula-and-proof-of-inst})}%
\index{mk-proof-in-ex-intro-form@\texttt{mk-proof-in-ex-intro-form}}
\end{alignat*}
Moreover we need
\begin{alignat*}{2}
&\texttt{(proof?\ \textsl{x})}
\index{proof?@\texttt{proof?}}
\\
&\texttt{(proof=?\ \textsl{proof1} \textsl{proof2})}
\index{proof=?@\texttt{proof=?}}
\\
&\texttt{(proofs=?\ \textsl{proofs1} \textsl{proofs2})}
\index{proofs=?@\texttt{proofs=?}}
\\
&\texttt{(proof-to-formula \textsl{proof})}
\index{proof-to-formula@\texttt{proof-to-formula}}
\\
&\texttt{(proof-to-context \textsl{proof})}
\index{proof-to-context@\texttt{proof-to-context}}
\\
&\texttt{(proof-to-free \textsl{proof})}
\index{proof-to-free@\texttt{proof-to-free}}
\\
&\texttt{(proof-to-free-avars \textsl{proof})}
\index{proof-to-free-avars@\texttt{proof-to-free-avars}}
\\
&\texttt{(proof-to-bound-avars \textsl{proof})}
\index{proof-to-bound-avars@\texttt{proof-to-bound-avars}}
\\
&\texttt{(proof-to-free-and-bound-avars \textsl{proof})}
\index{proof-to-free-and-bound-avars@\texttt{proof-to-free-and-bound-avars}}
\\
&\texttt{(proof-to-aconsts-without-rules \textsl{proof}).}
\index{proof-to-aconsts-without-rules@\texttt{proof-to-aconsts-without-rules}}
\\
&\texttt{(proof-to-aconsts \textsl{proof}).}
\index{proof-to-aconsts@\texttt{proof-to-aconsts}}
\end{alignat*}
To work with contexts we need
\begin{alignat*}{2}
&\texttt{(context-to-vars\ \textsl{context})}
\index{context-to-vars@\texttt{context-to-vars}}
\\
&\texttt{(context-to-avars\ \textsl{context})}
\index{context-to-avars@\texttt{context-to-avars}}
\\
&\texttt{(context=?\ \textsl{context1} \textsl{context2}).}
\index{context=?@\texttt{context=?}}
\end{alignat*}
\subsection{Normalization}
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 variable whose
type comes from the formula of the avar; store this information. Note
that in this construction one also has to create new variables 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 carry along a
procedure \texttt{pvar-to-tvar} which remembers the assignment done so far
(cf.\ \texttt{make-rename}).
Due to our distinction between general variables $\verb#x^0#,
\verb#x^1#, \verb#x^2#, \dots$ and variables $\texttt{x0},
\texttt{x1}, \texttt{x2}, \dots$ intended to range over existing
(i.e.\ total) objects only, $\eta$-conversion of proofs cannot be done
via reduction to $\eta$-conversion of terms. To see this, consider
the proof
\[
\AxiomC{$\forall \hat{x} P \hat{x}$}
\AxiomC{$x$}
\BinaryInfC{$P x$}
\UnaryInfC{$\forall x P x$}
\UnaryInfC{$\forall \hat{x} P \hat{x} \to \forall x P x$}
\DisplayProof
\]
The proof term is $\lambda u \lambda x. u x$. If we $\eta$-normalize
this to $\lambda u u$, the proven formula would be all $\forall
\hat{x} P \hat{x} \to \forall \hat{x} P \hat{x}$. Therefore we split
\texttt{nbe-normalize-proof} into
\texttt{nbe-normalize-proof-without-eta} and \texttt{proof-to-eta-nf}.
Moreover, for a full normalization of proofs (including permutative
conversions) we need a preprocessing step that $\eta$-expands each
ex-elim axiom such that the conclusion is atomic or existential.
% \subsection*{Interface}
We need the following functions.
\begin{alignat*}{2}
&\texttt{(proof-and-genavar-var-alist-to-pterm \textsl{pvar-to-tvar}
\textsl{proof})}
\\
&\texttt{(npterm-and-var-genavar-alist-and-formula-to-proof}
\\
&\quad \texttt{\textsl{npterm} \textsl{var-genavar-alist} \textsl{crit}
\textsl{formula})}
\\
&\texttt{(elim-npterm-and-var-genavar-alist-to-proof}
\\
&\quad \texttt{\textsl{npterm} \textsl{var-genavar-alist} \textsl{crit})}.
\end{alignat*}
Then we can define \texttt{nbe-normalize-proof}%
\index{nbe-normalize-proof@\texttt{nbe-normalize-proof}}, abbreviated
\texttt{np}\index{np@\texttt{np}}.
\subsection{Substitution}
In a proof we can substitute
\begin{itemize}
\item types for type variables (by a type variable substitution
\texttt{tsubst}),
\item terms for variables (by a substitution \texttt{subst}),
\item comprehension terms for predicate variables (by a predicate
variable substitution \texttt{psubst}), and
\item proofs for assumption variables (by a assumption variable
substitution \texttt{asubst}).
\end{itemize}
It is assumed that \texttt{subst} only affects those vars whose type
is not changed by \texttt{tsubst}, \texttt{psubst} only affects those
predicate variables whose arity is not changed by \texttt{tsubst}, and
that \texttt{asubst} only affects those assumtion variabless whose
formula is not changed by \texttt{tsubst}, \texttt{subst} and
\texttt{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 \texttt{tsubst} (or
\texttt{tsubst}, \texttt{subst} and \texttt{psubst}). Then the
renaming cannot be made part of \texttt{subst} (or \texttt{asubst}),
because the condition above would be violated. Therefore we carry
along procedures \texttt{rename} renaming variables and
\texttt{arename} for assumption variables, which remember the renaming
done so far.
All these substitutions can be packed together, as an argument
\texttt{topasubst} for \texttt{proof-substitute}.
\begin{alignat*}{2}
&\texttt{(proof-substitute \textsl{proof} \textsl{topasubst})}
\index{proof-substitute@\texttt{proof-substitute}}
\end{alignat*}
If we want to substitute for a single variable only (which can be a
type-, an object-, a predicate - or an assumption-variable), then
we can use
\begin{alignat*}{2}
&\texttt{(proof-subst \textsl{proof} \textsl{arg} \textsl{val})}
\index{proof-subst@\texttt{proof-subst}}
\end{alignat*}
The procedure \texttt{expand-theorems} expects a proof and a test
whether a string denotes a theorem to be replaced by its proof. The
result is the (normally quite long) proof obtained by replacing the
theorems by their saved proofs.
\begin{alignat*}{2}
&\texttt{(expand-theorems \textsl{proof} \textsl{name-test?})}
\index{expand-theorems@\texttt{expand-theorems}}
\end{alignat*}
\subsection{Display}
There are many ways to display a proof. We normally use
\texttt{display-proof} for a linear representation, showing the
formulas and the rules used. When we in addition want to check the
correctness of the proof, we can use \texttt{check-and-display-proof}.
However, we also provide a readable type-free lambda expression via
\texttt{(proof-to-expr
\textsl{proof})}\index{proof-to-expr@\texttt{proof-to-expr}}.
To display proofs we use the following functions. In case the
optional proof argument is not present, the current proof of an
interactive proof development is taken instead.
\begin{alignat*}{2}
&\texttt{(display-proof\ .\ \textsl{opt-proof})}
\index{display-proof@\texttt{display-proof}}
&\quad& \text{abbreviated \texttt{dp}\index{dp@\texttt{dp}}}
\\
&\texttt{(check-and-display-proof\ .\ \textsl{opt-proof})}
\index{check-and-display-proof@\texttt{check-and-display-proof}}
&\quad& \text{abbreviated \texttt{cdp}\index{dp@\texttt{cdp}}}
\\
&\texttt{(display-pterm\ .\ \textsl{opt-proof})}
\index{display-pterm@\texttt{display-pterm}}
&\quad& \text{abbreviated \texttt{dpt}\index{dpt@\texttt{dpt}}}
\\
&\texttt{(display-proof-expr\ .\ \textsl{opt-proof})}
\index{display-proof-expr@\texttt{display-proof-expr}}
&\quad& \text{abbreviated \texttt{dpe}\index{dpe@\texttt{dpe}}}
\end{alignat*}
We also provide versions which normalize the proof first:
\begin{alignat*}{2}
&\texttt{(display-normalized-proof\ .\ \textsl{opt-proof})}
\index{display-normalized-proof@\texttt{display-normalized-proof}}
&\quad& \text{abbreviated \texttt{dnp}\index{dnp@\texttt{dnp}}}
\\
&\texttt{(display-normalized-pterm\ .\ \textsl{opt-proof})}
\index{display-normalized-pterm@\texttt{display-normalized-pterm}}
&\quad& \text{abbreviated \texttt{dnpt}\index{dnpt@\texttt{dnpt}}}
\\
&\texttt{(display-normalized-proof-expr\ .\ \textsl{opt-proof})}
\index{display-normalized-proof-expr@\texttt{display-normalized-proof-expr}}
&\quad& \text{abbreviated \texttt{dnpe}\index{dnpe@\texttt{dnpe}}}
\end{alignat*}
\subsection{Classical logic}
\texttt{(proof-of-stab-at
\textsl{formula})}\index{proof-of-stab-at@\texttt{proof-of-stab-at}}
generates a proof of $((A \to F) \to F) \to A$. For $F$, $T$ one takes
the obvious proof, and for other atomic formulas the proof using cases
on booleans. For all other prime or existential formulas one takes an
instance of the global assumption \texttt{Stab}: $((\hat{P} \to F) \to
F) \to \hat{P}$. Here the argument \textsl{formula} must be unfolded.
For the logical form of falsity we take \texttt{(proof-of-stab-log-at
\textsl{formula})}\index{proof-of-stab-log-at@\texttt{proof-of-stab-log-at}},
and similary for ex-falso-quodlibet we provide
\begin{alignat*}{2}
&\texttt{(proof-of-efq-at \textsl{formula})}%
\index{proof-of-efq-at@\texttt{proof-of-efq-at}}
\\
&\texttt{(proof-of-efq-log-at \textsl{formula})}%
\index{proof-of-efq-log-at@\texttt{proof-of-efq-log-at}}
\end{alignat*}
Using these functions we can then define \texttt{(reduce-efq-and-stab
\textsl{proof})}\index{reduce-efq-and-stab@\texttt{reduce-efq-and-stab}},
which reduces all instances of stability and ex-falso-quodlibet axioms
in a proof to instances of these global assumptions with prime or
existential formulas, or (if possible) replaces them by their proofs.
With \texttt{rm-exc}\index{rm-exc@\texttt{rm-exc}} 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 \texttt{expand-theorems}.
\section{Interactive theorem proving with partial proofs}
\mylabel{Pproof}
\subsection{Partial proofs}
A partial proof is a proof with holes, i.e.\ special
assumption variables (called goal variables) \texttt{v}, \texttt{v1},
\texttt{v2} \dots whose formulas must be closed. We assume that every
goal variable \texttt{v} has a single occurrence in the proof. We
then select a (not necessarily maximal) subproof \texttt{vx1...xn}
with distinct object or assumption variables \texttt{x1...xn}. Such a
subproof is called a \emph{goal}\index{goal}. When interactively
developing a partial proof, a goal \texttt{vx1...xn} is replaced by
another partial proof, whose context is a subset of \texttt{x1...xn}
(i.e.\ the context of the goal with \texttt{v} removed).
To gain some flexibility when working on our goals, we do not at each
step of an interactive proof development traverse the partial proof
searching for the remaining goals, but rather keep a list of all open
goals together with their numbers as we go along. We maintain a
global variable \texttt{PPROOF-STATE} containing a list of three
elements: (1) \texttt{num-goals}, an alist of entries \texttt{(number
goal drop-info hypname-info)}, (2) \texttt{proof} and (3)
\texttt{maxgoal}, the maximal goal number used.
At each stage of an interactive proof development we have access
to the current proof and the current goal by executing
\begin{alignat*}{2}
&\texttt{(current-proof)}\index{current-proof@\texttt{current-proof}}
\\
&\texttt{(current-goal)}\index{current-goal@\texttt{current-goal}}
\end{alignat*}
\subsection{Interactive theorem proving}
For interactively building proofs we need
\begin{alignat*}{2}
&\texttt{(goal-to-goalvar \textsl{goal})}%
\index{goal-to-goalvar@\texttt{goal-to-goalvar}}
\\
&\texttt{(goal-to-context \textsl{goal})}%
\index{goal-to-context@\texttt{goal-to-context}}
\\
&\texttt{(goal-to-formula \textsl{goal})}%
\index{goal-to-formula@\texttt{goal-to-formula}}
\\
&\texttt{(goal=?\ \textsl{proof} \textsl{goal})}%
\index{goal=?@\texttt{goal=?}}
\\
&\texttt{(goal-subst \textsl{proof} \textsl{goal} \textsl{proof1})}%
\index{goal-subst@\texttt{goal-subst}}
\\
&\texttt{(pproof-state-to-num-goals)}%
% \index{pproof-state-to-num-goals@\texttt{pproof-state-to-num-goals}}
\\
&\texttt{(pproof-state-to-proof)}%
\index{pproof-state-to-proof@\texttt{pproof-state-to-proof}}
\\
&\texttt{(pproof-state-to-formula)}%
\index{pproof-state-to-formula@\texttt{pproof-state-to-formula}}
\\
&\texttt{(display-current-goal)}%
\index{display-current-goal@\texttt{display-current-goal}}
\\
&\texttt{(display-current-goal-with-normalized-formulas)}%
\index{display-current-goal-with-normalized-formulas@\texttt{display-current-goal-with{\dots}}}
\\
% &\texttt{(display-current-proof)}%
% \index{display-current-proof@\texttt{display-current-proof}}
% \\
% &\texttt{(display-current-pterm)}%
% \index{display-current-pterm@\texttt{display-current-pterm}}
% \\
&\texttt{(display-current-pproof-state)}%
\index{display-current-pproof-state@\texttt{display-current-num-goals{\dots}}}
\end{alignat*}
We list some commands for interactively building proofs.
\subsubsection{set-goal} An interactive proof starts with \texttt{(set-goal
\textsl{formula})}\index{set-goal@\texttt{set-goal}}, i.e.\ with
setting a goal. Here \textsl{formula} should be closed; if it is not,
universal quantifiers are inserted automatically.
\subsubsection{normalize-goal} \texttt{(normalize-goal
\textsl{goal})}\index{normalize-goal@\texttt{normalize-goal}}
(abbreviated \texttt{ng}\index{ng@\texttt{ng}}) replaces every formula
in the goal by its normal form.
\subsubsection{assume} With \texttt{(assume \textsl{x1}
\dots)}\index{assume@\texttt{assume}} we can move universally
quantified variables and hypotheses into the context. The variables
must be given names (known to the parser as valid variable names for
the given type), and the hypotheses should be identified by numbers
or strings.
\subsubsection{use} In \texttt{(use \textsl{x}
. \textsl{elab-path-and-terms})}\index{use@\texttt{use}}, \textsl{x} is
\begin{itemize}
\item a number or string identifying a hypothesis form the context,
\item the string \inquotes{Truth-Axiom},
\item the name of a theorem or global assumption. If it is a global
assumption whose final conclusion is a nullary predicate variable
distinct from $\bot$ (e.g.\ \texttt{Efq-Log} or \texttt{Stab-Log}),
this predicate variable is substituted by the goal formula.
\item a closed proof,
\item a formula with free variables from the context, generating a new
goal.
\end{itemize}
The optional \textsl{elab-path-and-terms} is a list consisting of
symbols \texttt{left} or \texttt{right}, giving directions in case the
used formula contains conjunctions, and of terms. The universal
quantifiers of the used formula are instantiated (via
\texttt{pattern-unify}\index{pattern-unify@\texttt{pattern-unify}})
with appropriate terms in case a conclusion has the form of the goal.
The terms provided are substituted for those variables that cannot be
instantiated by pattern unification (e.g.\ using $\forall x.P x \to
\bot$ for the goal $\bot$). For the instantiated premises new goals
are created.
\subsubsection{use-with} This is a more verbose form of \texttt{use}, where
the terms are not inferred via unification, but have to be given
explicitely. Also, for the instantiated premises one can indicate how
they are to come about. So in \texttt{(use-with \textsl{x}
. \textsl{x-list})}\index{use-with@\texttt{use-with}}, \textsl{x} is
as in \texttt{use}, and \textsl{x-list} is a list consisting of
\begin{itemize}
\item a number or string identifying a hypothesis form the context,
\item the name of a theorem or global assumption,
\item a closed proof,
\item the string \inquotes{?} (value of \texttt{DEFAULT-GOAL-NAME}),
generating a new goal,
\item a symbol \texttt{left} or \texttt{right},
\item a term, whose free variables are added to the context,
\item a type, which is substituted for the first type variable,
\item a comprehension term, which is substituted for the first predicate
variable.
\end{itemize}
Notice that new free variables not in the ordered context can be
introduced in \texttt{use-with}. They will be present in the newly
generated goals. The reason is that proofs should be allowed to
contain free variables. This is necessary to allow logic in ground
types where no constant is available (e.g\ to prove $\forall x Px \to
\forall x \neg Px \to \bot$).
Notice also that there are situations where \textsl{use-with} can be
applied but \textsl{use} can not. For an example, consider the goal
$P(S(k+l))$ with the hypothesis $\forall l P(k+l)$ in the context.
Then \textsl{use} cannot find the term $S l$ by matching; however,
applying \textsl{use-with} to the hyposthesis and the term $S l$
succeeds (since $k+S l$ and $S(k+l)$ have the same normal form).
\subsubsection{inst-with} \texttt{inst-with} does for forward chaining the
same as use-with for backward chaining. It replaces the present goal
by a new one, with one additional hypothesis obtained by instantiating
a previous one. Notice that this effect could also be obtained by
cut. In \texttt{(inst-with \textsl{x}
. \textsl{x-list})}\index{inst-with@\texttt{inst-with}}, \textsl{x} is
\begin{itemize}
\item a number or string identifying a hypothesis form the context,
\item the name of a theorem or global assumption,
\item a closed proof,
\item a formula with free variables from the context, generating a new
goal.
\end{itemize}
and \textsl{x-list} is a list consisting of
\begin{itemize}
\item a number or string identifying a hypothesis form the context,
\item the name of a theorem or global assumption,
\item a closed proof,
\item the string \inquotes{?} (value of \texttt{DEFAULT-GOAL-NAME}),
generating a new goal,
\item a symbol \texttt{left} or \texttt{right},
\item a term, whose free variables are added to the context,
\item a type, which is substituted for the first type variable,
\item a comprehension term, which is substituted for the first predicate
variable.
\end{itemize}
\subsubsection{inst-with-to}
\texttt{inst-with-to}\index{inst-with-to@\texttt{inst-with-to}}
expects a string as its last argument, which is used (via
\texttt{name-hyp}) to name the newly introduced instantiated
hypothesis.
\subsubsection{cut} The command \texttt{(cut
\textsl{A})}\index{cut@\texttt{cut}} replaces the goal $B$ by the two
new goals $A$ and $A \to B$.
\subsubsection{strip} To move (all or $n$) universally quantified variables
and hypotheses of the current goal into the context, we uns the
command \texttt{(strip)}\index{strip@\texttt{strip}} or \texttt{(strip
n)}.
\subsubsection{drop} In
\texttt{(drop .\ x-list)}\index{drop@\texttt{drop}}, x-list is a list
of numbers or strings identifying hypotheses from the context. A new
goal is created, which differs from the previous one only in display
aspects: the listed hypotheses are hidden (but still present). If
x-list is empty, all hypotheses are hidden.
\subsubsection{name-hyp} The command
\texttt{name-hyp}\index{name-hyp@\texttt{name-hyp}} expects an index
$i$ and a string. Then a new goal is created, which differs from the
previous one only in display aspects: the string is used to label the
$i$th hypothesis.
\subsubsection{split} The command
\texttt{(split)}\index{split@\texttt{split}}
expects a conjunction $A \land B$ as goal and splits it into the
two new goals $A$ and $B$.
\subsubsection{get} To be able to work on a goal different from that on
top of the goal stack, we have have to move it up using \texttt{(get
\textsl{n})}\index{get@\texttt{get}}.
\subsubsection{undo} With
\texttt{(undo .\ \textsl{n})}\index{undo@\texttt{undo}}, the last $n$
steps of an interactive proof can be made undone. \texttt{(undo)}
has the same effect as \texttt{(undo 1)}.
\subsubsection{ind} \texttt{(ind)}\index{ind@\texttt{ind}} expects a
goal $\forall x^\rho A$ with $\rho$ an algebra. Let $c_1, \dots, c_n$
be the constructors of the algebra $\rho$. Then $n$ new goals
$\forall \vec{x}_i. \subst{A}{x}{x_{1i}} \to \dots \to
\subst{A}{x}{x_{ki}} \to \subst{A}{x}{c_i \vec{x}_i}$ are generated.
\texttt{(ind \textsl{t})} expects a goal $\subst{A}{x}{t}$. It
computes the algebra $\rho$ as type of the term $t$. Then again
$n$ new goals $\forall \vec{x}_i. \subst{A}{x}{x_{1i}} \to \dots \to
\subst{A}{x}{x_{ki}} \to \subst{A}{x}{c_i \vec{x}_i}$ are generated.
\subsubsection{simind} \texttt{(simind \textsl{all-formula1}
\dots)}\index{simind@\texttt{simind}} also expects a goal $\forall
x^\rho A$ with $\rho$ an algebra. Then we have to provide the other
all formulas to be proved simultaneously with the given one.
\subsubsection{intro} \texttt{(intro i .\ terms)}\index{intro@\texttt{intro}}
expects as goal an inductively defined predicate. The $i$-th
introduction axiom for this predicate is applied, via \texttt{use}
(hence \texttt{terms} may have to be provided).
\subsubsection{elim} \texttt{(elim)}\index{elim@\texttt{elim}} expects a
goal $I(\vec{t}) \to \subst{A}{\vec{x}}{\vec{t}}$. Then the
(strengthened) clauses are generated as new goals, via \texttt{use-with}.
\subsubsection{ex-intro} In \texttt{(ex-intro
\textsl{term})}\index{ex-intro@\texttt{ex-intro}}, the user provides a
term to be used for the present (existential) goal.
\texttt{(exnc-intro \textsl{x})}\index{exnc-intro@\texttt{exnc-intro}}
works similarly for the \texttt{exnc}-quanhtifier.
\subsubsection{ex-elim} In \texttt{(ex-elim
\textsl{x})}\index{ex-elim@\texttt{ex-elim}}, \textsl{x} is
\begin{itemize}
\item a number or string identifying an existential hypothesis from
the context,
\item the name of an existential global assumption or theorem,
\item a closed proof on an existential formula,
\item an existential formula with free variables from the context,
genera\-ting a new goal.
\end{itemize}
Let $\ex y A$ be the existential formula identified by \textsl{x}.
The user is then asked to provide a proof for the present goal,
assuming that a $y$ satisfying $A$ is available. \texttt{(exnc-elim
\textsl{x})}\index{exnc-elim@\texttt{exnc-elim}} works similarly for
the \texttt{exnc}-quanhtifier.
\subsubsection{by-assume-with} Suppose we are proving a goal $G$
from an existential hypothesis $ExHyp \colon \ex y A$. Then the
natural way to use this hypothesis is to say \inquotes{by $ExHyp$
assume we have a $y$ satisfying $A$}. Correspondingly we provide
\texttt{(by-assume-with \textsl{x} \textsl{y}
\textsl{u})}\index{by-assume-with@\texttt{by-assume-with}}. Here
\textsl{x} -- as in \texttt{ex-elim} -- identifies an existential
hypothesis, and we assume (i.e.\ add to the context) the variable $y$
and -- with label $u$ -- the kernel $A$. \texttt{(by-assume-with
\textsl{x} \textsl{y} \textsl{u})} is implemented by the sequence
\texttt{(ex-elim \textsl{x})}, \texttt{(assume \textsl{y}
\textsl{u})}, \texttt{(drop \textsl{x})}. \texttt{by-exnc-assume-with}%
\index{by-exnc-assume-with@\texttt{by-exnc-assume-with}}
works similarly for the \texttt{exnc}-quantifier.
\subsubsection{cases} \texttt{(cases)}\index{cases@\texttt{cases}} expects a
goal $\forall x^\rho A$ with $\rho$ an algebra. Assume that $c_1,
\dots, c_n$ are the constructors of the algebra $\rho$. Then $n$ new
(simplified) goals $\forall \vec{x}_i \subst{A}{x}{c_i \vec{x}_i}$ are
generated.
\texttt{(cases \textsl{t})} expects a goal $\subst{A}{x}{t}$. It
computes the algebra $\rho$ as type of the term $t$. Then again $n$
new goals $\forall \vec{x}_i \subst{A}{x}{c_i \vec{x}_i}$ are
generated.
\texttt{(cases \textsl{'auto})} expects an
atomic goal and checks whe\-ther its boolean kernel contains an if-term
whose test is neither an if-term nor contains bound variables. With
the first such test \texttt{(cases \textsl{test})} is called.
\subsubsection{casedist} \texttt{(casedist \textsl{t})} replaces the goal
$A$ containing a boolean term $t$ by two new goals $(\texttt{atom}\ t)
\to \subst{A}{t}{\true}$ and $((\texttt{atom}\ t) \to \false) \to
\subst{A}{t}{\false}$.
\subsubsection{simp}
In \texttt{(simp \textsl{opt-dir} \textsl{x} .
\textsl{elab-path-and-terms})}\index{simp@\texttt{simp}}, the
optional argument \textsl{opt-dir} is either the string
\inquotes{\texttt{<-}} or missing. \textsl{x} is
\begin{itemize}
\item a number or string identifying a hypothesis form the context,
\item the name of a theorem or global assumption,
\item a closed proof,
\item a formula with free variables from the context, generating a new
goal.
\end{itemize}
The optional \textsl{elab-path-and-terms} is a list consisting of
symbols \texttt{left} or \texttt{right}, giving directions in case the
used formula contains conjunctions, and of terms. The universal
quantifiers of the used formula are instantiated with appropriate
terms to match a part of the goal. The terms provided are substituted
for those variables that cannot be inferred. For the instantiated
premises new goals are created. This generates a used formula, which
is to be an atom, a negated atom or $t \approx s$. If it as a
(negated) atom, it is checked whether the kernel or its normal form is
present in the goal. If so, it is replace by \texttt{T} (or
\texttt{F}). If it is an equality $t=s$ or $t \approx s$ with $t$ or
its normal form present in the goal, $t$ is replaced by $s$. In case
\inquotes{\texttt{<-}} exchange $t$ and $s$.
\subsubsection{simp-with} This is a more verbose form of \texttt{simp},
where the terms are not inferred via matching, but have to be given
explicitely. Also, for the instantiated premises one can indicate how
they are to come about. So in \texttt{(simp-with \textsl{opt-dir}
\textsl{x} . \textsl{x-list})}\index{simp-with@\texttt{simp-with}},
\textsl{opt-dir} and \textsl{x} are as in \texttt{simp}, and
\textsl{x-list} is a list consisting of
\begin{itemize}
\item a number or string identifying a hypothesis form the context,
\item the name of a theorem or global assumption,
\item a closed proof,
\item the string \inquotes{?} (value of \texttt{DEFAULT-GOAL-NAME}),
generating a new goal,
\item a symbol \texttt{left} or \texttt{right},
\item a term, whose free variables are added to the context,
\item a type, which is substituted for the first type variable,
\item a comprehension term, which is substituted for the first predicate
variable.
\end{itemize}
% \subsubsection{simp, simpeq} \texttt{(simp x)}\index{simp@\texttt{simp}}
% expects a known fact of the form $r^{\boole}$, $\neg r^{\boole}$ or
% $t=s$. In case $r^{\boole}$ the boolean term $r^{\boole}$ in the goal
% is replaced by $T$, and in case $\neg r^{\boole}$ by $F$. In case
% $t=s$ the goal is written in the form $\subst{A}{x}{t}$. Using
% Compat-Rev $\forall x,y.x=y \to P y \to P x$ with $\set{x}{A}$ for
% $P$, $t$ for $x$ and $s$ for $y$ the goal $\subst{A}{x}{t}$ is
% replaced by $\subst{A}{x}{s}$.
% In \texttt{(simp \textsl{x})}\index{simp@\texttt{simp}}, \textsl{x} is
% \begin{itemize}
% \item a number or string identifying a hypothesis form the context,
% \item the name of a theorem or global assumption, or
% \item a closed proof,
% \end{itemize}
% in each case for $r^{\boole}$, $\neg r^{\boole}$ or $t=s$.
% Similarly, \texttt{(simpeq x)}\index{simpeq@\texttt{simpeq}} needs to
% know $t \approx s$. The goal is written in the form
% $\subst{A}{x}{t}$. Using Eq-Compat-Rev $\forall x,y. x \approx y \to P y
% \to P x$ with $\set{x}{A}$ for $P$, $t$ for $x$ and $s$ for $y$ the
% goal $\subst{A}{x}{t}$ is replaced by $\subst{A}{x}{s}$.
\subsubsection{min-pr} In \texttt{(min-pr \textsl{x} \textsl{measure})}%
\index{min-pr@\texttt{min-pr}}, \textsl{x} is
\begin{itemize}
\item a number or string identifying a classical existential hypothesis
from the context,
\item the name of a classical existential global assumption or theorem,
\item a closed proof on a classical existential formula,
\item a classical existential formula with free variables from the context,
generating a new goal.
\end{itemize}
The result is a new implicational goal, whose premise provides the
(classical) existence of instances with least measure.
\subsubsection{exc-intro} In \texttt{(exc-intro
\textsl{terms})}\index{exc-intro@\texttt{exc-intro}}, the user provides
terms to be used for the present (classical existential) goal.
\subsubsection{exc-elim} In \texttt{(exc-elim
\textsl{x})}\index{exc-elim@\texttt{exc-elim}}, \textsl{x} is
\begin{itemize}
\item a number or string identifying a classical existential hypothesis
from the context,
\item the name of a classical existential global assumption or theorem,
\item a closed proof on a classical existential formula,
\item a classical existential formula with free variables from the context,
generating a new goal.
\end{itemize}
Let $\exca \vec{y} \vec{A}$ or $\excl \vec{y} \vec{A}$ be the
classical existential formula identified by \textsl{x}. The user is
then asked to provide a proof for the present goal, assuming that terms
$\vec{y}$ satisfying $\vec{A}$ are available.
\subsubsection{pair-elim} In
\texttt{(pair-elim)}\index{pair-elim@\texttt{pair-elim}}, a goal
$\forall p P(p)$ is replaced by the new goal $\forall x_1, x_2
P(\pair{x_1}{x_2})$.
\section{Search}
Following \textsc{Miller}\index{Miller} \cite{Miller91b} and
\textsc{Berger}\index{Berger}, we have implemented a proof search
algorithm for minimal logic. To enforce termination, every assumption
can only be used a fixed number of times.
We begin with a short description of the theory involved.
$Q$ always denotes a $\forall \exists \forall$-prefix, say $\forall
\vec{x} \exists \vec{y} \forall \vec{z}$, with distinct variables. We
call $\vec{x}$ the \emph{signature variables}, $\vec{y}$ the
\emph{flexible variables} and $\vec{z}$ the \emph{forbidden variables}
of $Q$, and write $Q_\exists$ for the existential part $\exists
\vec{y}$ of $Q$.
\emph{$Q$-terms}\index{Q-term@$Q$-term} are inductively defined by the
following clauses.
\begin{itemize}
\item If $u$ is a universally quantified variable in $Q$ or a
constant, and $\vec{r}$ are $Q$-terms, then $u \vec{r}$ is a $Q$-term.
\item For any flexible variable $y$ and distinct forbidden variables
$\vec{z}$ from $Q$, $y \vec{z}$ is a $Q$-term.
%$
\item If $r$ is a $Q \forall z$-term, then $\lambda z r$ is a
$Q$-term.
\end{itemize}
Explicitely, $r$ is a $Q$-term iff all its free variables are in $Q$,
and for every subterm $y \vec{r}$ of $r$ with $y$ free in $r$ and flexible
in $Q$, the $\vec{r}$ are distinct variables either $\lambda$-bound in $r$
(such that $y \vec{r}$ is in the scope of this $\lambda$) or else
forbidden in $Q$.
\emph{$Q$-goals}\index{Q-goal@$Q$-goal} and
\emph{$Q$-clauses}\index{Q-clause@$Q$-clause} are simultaneously
defined by
\begin{itemize}
\item If $\vec{r}$ are $Q$-terms, then $P \vec{r}$ is a $Q$-goal as well as a
$Q$-clause.
\item If $D$ is a $Q$-clause and $G$ is a $Q$-goal, then $D \to G$
is a $Q$-goal.
\item If $G$ is a $Q$-goal and $D$ is a $Q$-clause, then $G \to D$
is a $Q$-clause.
\item If $G$ is a $Q\forall x$-goal, then $\forall x G$ is a $Q$-goal.
\item If $\subst{D}{y}{Y \vec{z}}$ is a $\forall \vec{x} \exists \vec{y}, Y
\forall \vec{z}$-clause, then $\forall y D$ is a $\forall \vec{x} \exists \vec{y}
\forall \vec{z}$-clause.
\end{itemize}
Explicitely, a formula $A$ is a \emph{$Q$-goal}\index{Q-goal@$Q$-goal}
iff all its free variables are in $Q$, and for every subterm $y \vec{r}$
of $A$ with $y$ either existentially bound in $A$ (with $y \vec{r}$ in the
scope) or else free in $A$ and flexible in $Q$, the $\vec{r}$ are distinct
variables either $\lambda$- or universally bound in $A$ (such that $y
\vec{r}$ is in the scope) or else free in $A$ and forbidden in $Q$.
A \emph{$Q$-sequent}\index{Q-sequent@$Q$-sequent} has the form $\C{P}
\seqarrow G$, where $\C{P}$ is a list of $Q$-clauses and $G$ is a
$Q$-goal.
A \emph{$Q$-substitution}\index{Q-substitution@$Q$-substitution} is a
substitution of $Q$-terms.
A \emph{unification problem} $\C{U}$ consists of a $\forall
\exists \forall$-prefix $Q$ and a conjunction $C$ of equations between
$Q$-terms of the same type, i.e.\ $\bigland_{i=1}^n r_i = s_i$. We
may assume that each such equation is of the form $\lambda \vec{x} r =
\lambda \vec{x} s$ with the same $\vec{x}$ (which may be empty) and $r, s$ of
ground type.
A \emph{solution} to such a unification problem $\C{U}$ is a
$Q$-substitution $\varphi$ such that for every $i$, $r_i \varphi = s_i
\varphi$ holds (i.e.\ $r_i \varphi$ and $s_i \varphi$ have the same
normal form). We sometimes write $C$ as $\vec{r} = \vec{s}$, and (for
obvious reasons) call it a list of unification pairs.
We work with lists of sequents instead of single sequents; they all
are $Q$-sequents for the same prefix $Q$. One then searches for a
$Q$-substitution $\varphi$ and proofs of the $\varphi$-substituted
sequents.
\texttt{intro-search}\index{intro-search@\texttt{intro-search}} takes
the first sequent and extends $Q$ by all universally quantified
variables $x_1 \dots$. It then calls
\texttt{select}\index{select@\texttt{select}}, which selects (using
\texttt{or}) a fitting clause. If one is found, a new prefix $Q'$
(raising the new flexible variables) is formed, and the $n$ ($\ge 0$)
new goals with their clauses (and also all remaining sequents) are
substituted with $\texttt{star} \circ \rho$, where \texttt{star} is
the \inquotes{rai\-sing} substitution and $\rho$ is the mgu. For this
constellation \texttt{intro-search} is called again. In case of
success, one obtains a $Q'$-substitution $\varphi'$ and proofs of the
$\texttt{star} \circ \rho \circ \varphi'$ -substituted new sequents.
Let $\varphi := (\rho \circ \varphi') {\restriction} Q_\ex$, and take
the first $n$ proofs of these to build a proof of the
$\varphi$-substituted (first) sequent originally considered by
\texttt{intro-search}.
Compared with Miller \cite{Miller91b}, we make use of several
simplifications, optimizations and extensions, in particular the
following.
\begin{itemize}
\item Instead of arbitrarily mixed prefixes we only use those of
the form $\forall \ex \forall$. Nipkow in \cite{Nipkow91} already
had presented a version of Miller's pattern unification algorithm for
such prefixes, and Miller in \cite[Section~9.2]{Miller91b} notes that
in such a situation any two unifiers can be transformed into each
other by a variable renaming substitution. Here we restrict ourselves
to $\forall \ex \forall$-prefixes throughout, i.e.\ in the proof
search algorithm as well.
\item The order of events in the pattern unification algorithm is
changed slightly, by postponing the raising step until it is really
needed. This avoids unnecessary creation of new higher type
variables. -- Already Miller noted in \cite[p.515]{Miller91b} that
such optimizations are possible.
\item The extensions concern the (strong) existential quantifier, which
has been left out in Miller's treatment, and also conjunction. The
latter can be avoided in principle, but of course is a useful thing to
have.
\end{itemize}
% \subsection*{Interface}
\texttt{(search \textsl{m} \textsl{(name1 m1)}
\dots)}\index{search@\texttt{search}} expects for \textsl{m} a default
value for multiplicity (i.e.\ how often assumptions are to be used),
for \textsl{name1} $\dots$
\begin{itemize}
\item numbers of hypotheses from the present context or
\item names for theorems or global assumptions,
\end{itemize}
and for \textsl{m1} \dots multiplicities (positive integers for global
assumptions or theorems). A search is started for a proof of the goal
formula from the given hypotheses with the given multiplicities and in
addition from the other hypotheses (but not any other global
assumptions or theorems) with \textsl{m} or \texttt{mult-default}. To
exclude a hypothesis from being tried, list it with multiplicity $0$.
\section{Computational content of classical proofs}
\mylabel{Classical}
This section is based on \cite{BergerBuchholzSchwichtenberg02}. We
restrict to formulas in the language $\{\bot, \to, \forall \}$ in this
section, and - as in the paper - make use of a special nullary
predicate variable $X$.
A formula is \emph{relevant}\index{formula!relevant} if it
ends with (logical) falsity. \emph{Definite}\index{formula!definite}
and \emph{goal}\index{formula!goal} formulas are defined by a
simultaneous recursion, as in \cite{BergerBuchholzSchwichtenberg02}.
\begin{alignat*}{2}
&\texttt{(atr-relevant?\ \textsl{formula})}%
\index{atr-relevant?@\texttt{atr-relevant?}}
\\
&\texttt{(atr-definite?\ \textsl{formula})}%
\index{atr-definite?@\texttt{atr-definite?}}
\\
&\texttt{(atr-goal?\ \textsl{formula})}%
\index{atr-goal?@\texttt{atr-goal?}}
\end{alignat*}
To implement \cite[Lemma~3.1]{BergerBuchholzSchwichtenberg02}, we need
to construct proofs from formulas:
\begin{alignat*}{2}
&N_D\colon ((D \to \bot) \to X) \to D^X
&\quad&\text{for $D$ relevant}
\\
&M_D\colon D \to D^X
\\
&K_G\colon G \to G^X
&\quad&\text{for $G$ irrelevant}
\\
&H_G\colon G^X \to (G \to X) \to X
\end{alignat*}
This is done by
\begin{alignat*}{2}
&\texttt{(atr-rel-definite-proof \textsl{formula})}%
\index{atr-rel-definite-proof@\texttt{atr-rel-definite-proof}}
\\
&\texttt{(atr-arb-definite-proof \textsl{formula})}%
\index{atr-arb-definite-proof@\texttt{atr-arb-definite-proof}}
\\
&\texttt{(atr-irrel-goal-proof \textsl{formula})}%
\index{atr-irrel-goal-proof@\texttt{atr-irrel-goal-proof}}
\\
&\texttt{(atr-arb-goal-proof \textsl{formula})}%
\index{atr-arb-goal-proof@\texttt{atr-arb-goal-proof}}
\end{alignat*}
Next we need to implement
\cite[Lemma~3.2]{BergerBuchholzSchwichtenberg02}, which says that
for goal formulas $\vec{G} = G_1, \dots, G_n$ we can derive in minimal
logic augmented with a special predicate variable $X$
\[
(\vec{G} \to X) \to \vec{G}^X \to X.
\]
In our implementation this function is called
\begin{alignat*}{2}
&\texttt{(atr-goals-to-x-proof \textsl{goal1} \dots)}%
\index{atr-goals-to-x-proof@\texttt{atr-goals-to-x-proof}}
\end{alignat*}
Finally we implement
\cite[Theorem~3.3]{BergerBuchholzSchwichtenberg02}, which says the
following. Assume that for definite formulas $\vec{D}$ and goal
formulas $\vec{G}$ we can derive in minimal logic
\[
\vec{D} \to (\forall \vec{y}.\vec{G} \to \bot) \to \bot.
\]
Then we can also derive in intuitionistic logic augmented with the
special predicate variable $X$
\[
\vec{D} \to (\forall \vec{y}.\vec{G} \to X) \to X.
\]
In particular, substitution of the formula
\[
\ex \vec{y}.\vec{G} := \ex \vec{y}.G_1 \land \dots \land G_n
\]
for $X$ yields a derivation in intuitionistic logic of
\[
\vec{D} \to \ex \vec{y}.\vec G.
\]
This is done by
\begin{alignat*}{2}
&\texttt{(atr-min-excl-proof-to-x-proof \textsl{min-excl-proof})}%
\index{atr-min-excl-proof-to-x-proof@\texttt{atr-min-excl-proof-to-x-proof}}
\\
&\texttt{(atr-min-excl-proof-to-intuit-ex-proof \textsl{min-excl-proof})}%
\index{atr-min-excl-proof-to-intuit-ex-proof@\texttt{atr-min-\dots-to-intuit-ex-proof}}
\end{alignat*}
See section \ref{S:ExtrTerms} for an interpretation of the symbols of the
extracted terms in Minlog's output.
\section{Extracted terms}
\mylabel{S:ExtrTerms}
We assign to every formula $A$ an object $\tau(A)$ (a type or the
symbol $\texttt{nulltype}$). $\tau(A)$ is intended to be the type of the
program to be extracted from a proof of $A$.
%% To an atomic formula
%% consisting of a predicate variable with arguments we assign a new type
%% variable.
%% \begin{align*}
%% \tau( P\vec{r}) &:= \begin{cases}
%% \texttt{nulltype} &\text{if $P$ is a predicate constant}
%% \\
%% \alpha_P &\text{if $P$ is a predicate variable}
%% \end{cases}
%% \\
%% \tau(A \to B) &:= \begin{cases}
%% \tau(B) &\text{if $\tau(A)=\texttt{nulltype}$}
%% \\
%% \texttt{nulltype} &\text{if $\tau(B)=\texttt{nulltype}$}
%% \\
%% \tau(A) \to \tau(B) &\text{otherwise}\end{cases}
%% \\
%% \tau(A \land B) &:= \begin{cases}
%% \texttt{nulltype} &\text{if $\tau(A) = \tau(B) = \texttt{nulltype}$}
%% \\
%% \tau(B) &\text{if $\tau(A)=\texttt{nulltype}$}
%% \\
%% \tau(A) &\text{if $\tau(B)=\texttt{nulltype}$}
%% \\
%% \tau(A) \times \tau(B) &\text{otherwise}\end{cases}
%% \\
%% \tau(\forall x^\rho A) &:= \begin{cases}
%% \texttt{nulltype} &\text{if $\tau(A)=\texttt{nulltype}$}
%% \\
%% \rho \to \tau(A) &\text{otherwise}\end{cases}
%% \\
%% \tau(\ex x^\rho A) &:= \begin{cases}
%% \rho &\text{if $\tau(A) = \texttt{nulltype}$}
%% \\
%% \rho \times \tau(A) &\text{otherwise}\end{cases}
%% \end{align*}
This is done by
\begin{alignat*}{2}
&\texttt{(formula-to-et-type \textsl{formula})}%
\index{formula-to-et-type@\texttt{formula-to-et-type}}
\end{alignat*}
In \texttt{formula-to-et-type} we assign type variables to the
predicate variables. For to be able to later refer to this
assignment, we use a global variable \texttt{PVAR-TO-TVAR-ALIST},
which memorizes the assigment done so far. Later reference is
necessary, because such type variables will appear in extracted
programs of theorems involving predicate variables, and in a given
development there may be many auxiliary lemmata containing the same
predicate variable. A fixed \texttt{pvar-to-tvar} refers to and
updates \texttt{PVAR-TO-TVAR-ALIST}.
When we want to execute the program, we have to replace the constant
\texttt{cL} corresponding to a lemma \texttt{L} by the extracted
program of its proof, and the constant \texttt{cGA} corresponding to a
global assumption \texttt{GA} by an assumed extracted term to be
provided by the user. This can be achieved by adding computation
rules for \texttt{cL} and \texttt{cGA}. We can be rather flexible
here and enable/block rewriting by using
\texttt{animate}/\texttt{deanimate} as desired. Notice that the type
of the extracted term provided for a \texttt{cGA} must be the
extracted type of the assumed formula. When predicate variables are
present, one must use the type variables assigned to them in
\texttt{PVAR-TO-TVAR-ALIST}.
\begin{alignat*}{2}
&\texttt{(animate \textsl{thm-or-ga-name}\ .\ \textsl{opt-eterm})}
\index{animate@\texttt{animate}}
\\
&\texttt{(deanimate \textsl{thm-or-ga-name})}
\index{deanimate@\texttt{deanimate}}
\end{alignat*}
We can define, for a given derivation $M$ of a formula $A$ with
$\tau(A) \ne \texttt{nulltype}$, its \emph{extracted
term}\index{extracted term} (or \emph{extracted
program}\index{extracted program}) $\et{M}$ of type $\tau(A)$.
%% \begin{align*}
%% \et{u^A} &:= u^{\tau(A)}
%% \\
%% \et{c^A} &:= \text{a term of type $\tau(A)$ (see below)}
%% \\
%% \et{\lambda u^A M} &:= \begin{cases}
%% \et{M} &\text{if $\tau(A)=\texttt{nulltype}$}
%% \\
%% \lambda u^{\tau(A)}\et{M} &\text{otherwise}\end{cases}
%% \\
%% \et{M^{A\to B}N} &:= \begin{cases}
%% \et{M} &\text{if $\tau(A)=\texttt{nulltype}$}
%% \\
%% \et{M}\et{N} &\text{otherwise}\end{cases}
%% \\
%% \et{\pair{M^{A}}{N^{B}}} &:= \begin{cases}
%% \et{N} &\text{if $\tau(A)=\texttt{nulltype}$}
%% \\
%% \et{M} &\text{if $\tau(B)=\texttt{nulltype}$}
%% \\
%% \pair{\et{M}}{\et{N}} &\text{otherwise}\end{cases}
%% \\
%% \et{M^{A \land B} \texttt{left}} &:= \begin{cases}
%% \et{M} &\text{if $\texttt{nulltype} \in \{\tau(A), \tau(B)\}$}
%% \\
%% \et{M} \texttt{left} &\text{otherwise}\end{cases}
%% \\
%% \et{M^{A \land B} \texttt{right}} &:= \begin{cases}
%% \et{M} &\text{if $\texttt{nulltype} \in \{\tau(A), \tau(B)\}$}
%% \\
%% \et{M} \texttt{right} &\text{otherwise}\end{cases}
%% \\
%% \et{\lambda x^\rho M} &:= \lambda x^\rho \et{M}
%% \\
%% \et{Mt} &:= \et{M}t
%% \end{align*}
We also need extracted terms for the axioms. For induction we take
recursion, for the proof-by-cases axiom we take the cases-construct for
terms; for the other axioms the extracted terms are rather clear.
Term extraction is implemented by
\begin{alignat*}{2}
&\texttt{(proof-to-extracted-term \textsl{proof})}%
\index{proof-to-extracted-term@\texttt{proof-to-extracted-term}}
\end{alignat*}
The following table gives the symbols of Minlog's output and the corresponding
notation in the $\lambda$-calculus.
\begin{center}
\begin{tabular}{|l|c|c|}\hline
\textbf{Explanation} & \textbf{Symbol} & \textbf{Minlog's Output} \\ \hline
$\lambda$-abstraction: & $\lambda x. M$ & \texttt{([x]M)}\\ \hline
pair: & $\langle M {\;|\;} N \rangle$ & \texttt{(M@N)} \\ \hline
left element of a pair: & $(M \; 0)$ & \texttt{left M}\\ \hline
right element of a pair: &$(M \; 1)$ & \texttt{right M} \\ \hline
arrow for types: &$\typeTo$ & \texttt{=>} \\ \hline
product for types: &$\times$ & \texttt{@@} \\ \hline
recursion operator: &$\C{R}$ & \texttt{$\C{R}$} \\ \hline
\end{tabular}
\end{center}
It is also possible to give an internal proof of soundness. This can
be done by
\begin{alignat*}{2}
&\texttt{(proof-to-soundness-proof \textsl{proof})}%
\index{proof-to-soundness-proof@\texttt{proof-to-soundness-proof}}
\end{alignat*}
\section{Reading formulas in external form}
\mylabel{Reading} A formula can be produced from an external
representation, for example a string, using the \verb}pt} function.
It has one argument, a string denoting a formula, that is converted to
the internal representation of the formula. For the following
syntactical entities parsing functions are provided:
\begin{alignat*}{2}
&\texttt{(py \textsl{string})}\index{py@\texttt{py}}
&\quad& \hbox{for parsing types}
\\
&\texttt{(pv \textsl{string})}\index{pv@\texttt{pv}}
&\quad& \hbox{for parsing variables}
\\
&\texttt{(pt \textsl{string})}\index{pt@\texttt{pt}}
&\quad& \hbox{for parsing terms}
\\
&\texttt{(pf \textsl{string})}\index{pf@\texttt{pf}}
&\quad& \hbox{for parsing formulas}
\end{alignat*}
The conversion occurs in two steps: lexical analysis and parsing.
\subsection{Lexical analysis\index{lexical analysis}} In this stage the
string is brocken into short sequences, called \emph{tokens}\index{token}.
A token can be one of the following:
\begin{itemize}
\item An alphabetic symbol: A sequence of letters \verb}a}--\verb}z}
and \verb}A}--\verb}Z}. Upper and lower case letters are considered
different.
\item A number: A sequence of digits \verb}0}--\verb}9}
\item A punctuation mark: One of the characters: \verb}(} \verb})}
\verb}[} \verb}]} \verb}.} \verb},} \verb};}
\item A special symbol: A sequence of characters, that are neither letters,
digits, punctuation marks nor white space.
\end{itemize}
For example: \verb}abc}, \verb}ABC} and \verb}A} are alphabetic
symbols, \verb}123}, \verb}0123} and \verb}7} are numbers, \verb}(} is
a punctuation mark, and \verb}<=}, \verb}+}, and \verb}#:-^} are
special symbols.
Tokens are always character sequences of maximal length belonging to
one of the above categories. Therefore \verb}fx} is a single
alphabetic symbol not two and likewise \verb}<+} is a single special
symbol. The sequence \verb}alpha<=(-x+z)}, however, consists of the 8
tokens \verb}alpha}, \verb}<=}, \verb}(}, \verb}-}, \verb}x},
\verb}+}, \verb}z}, and \verb})}. Note that the special symbols
\verb}<=} and \verb}-} are separated by a punctuation mark, and the
alphabetic symbols \verb}x} and \verb}z} are separated by the special
symbol \verb}+}.
If two alphabetic symbols, two special symbols, or two numbers follow
each other they need to be separated by white space (spaces, newlines,
tabs, formfeeds, etc.). Except for a few situations mentioned below,
whitespace has no significance other than separating tokens. It can
be inserted and removed between any two tokens without affecting the
significance of the string.
Every token has a \indexentry{token type}, and a value. The token
type is one of the following: number, var-index, var-name, const,
pvar-name, predconst, type-symbol, pscheme-symbol, postfix-op,
prefix-op, binding-op, add-op, mul-op, rel-op, and-op, or-op, imp-op,
pair-op, if-op, postfix-jct, prefix-jct, and-jct, or-jct, tensor-jct,
imp-jct, quantor, dot, hat, underscore, comma, semicolon, arrow, lpar,
rpar, lbracket, rbracket.
The possible values for a token depend on the token type and are
explained below.
New tokens can be added using the function
\[
\texttt{(add-token \textsl{string} \textsl{token-type} \textsl{value})}.
\]
The inverse is the function
\[
\texttt{(remove-token \textsl{string})}.
\]
A list of all currently defined tokens sorted by token types can be
obtained by the function
\[
\texttt{(display-tokens)}.
\]
\subsection{Parsing}
The second stage, \indexentry{parsing}, extracts structure form the
sequence of tokens.
\emph{Types}. Type-symbols are types; the value of a type-symbol
must be a type. If $\sigma$ and $\tau$ are types, then
$\sigma$\verb};}$\tau$ is a type (pair type) and
$\sigma$\verb}=>}$\tau$ is a type (function type). Parentheses can be
used to indicate proper nesting. For example \verb}boole} is a
predefined type-symbol and hence, \verb}(boole;boole)=>boole} is again a
type. The parentheses in this case are not strictly necessary, since
\verb};} binds stronger than \verb}=>}. Both operators associate to
the right.
\emph{Variables}. Var-names are variables; the value of a var-name
token must be a pair consisting of the type and the name of the
variable (the same name string again! This is not nice and may be
later, we find a way to give the parser access to the string that is
already implicit in the token). For example to add a new boolean
variable called ``flag'', you have to invoke the function
\texttt{(add-token "flag" 'var-name (cons 'boole "flag"))}. This will
enable the parser to recognize ``\verb/flag3/'', ``\verb/flag^/'', or
``\verb/flag^14/'' as well.
Further, types, as defined above, can be used to construct variables.
A variable given by a name or a type can be further modified. If it
is followed by a \verb}^}, a partial variable is constructed. Instead
of the \verb}^} a \verb}_} can be used to specify a total variable.
Total variables are the default and therefore, the \verb}_} can be
omitted.
As another modifier, a number can immediately follow, with no
whitespace in between, the \verb}^} or the \verb}_}, specifying a
specific variable index.
In the case of indexed total variables given by a variable name or a
type symbol, again the \verb}_} can be omitted. The number must then
follow, with no whitespace in between, directly after the variable
name or the type.
Note: This is the only place where whitespace is of any significance
in the input. If the \verb}^}, \verb}_}, type name or variable name
is separated from the following number by whitespace, this number is
no longer considered to be an index for that variable but a numeric
term in its own right.
For example, assuming that \verb}p} is declared as a variable of type
\verb}boole}, we have:
\begin{itemize}
\item \verb}p} a total variable of type boole with name p and no index.
\item \verb}p_} a total variable of type boole with name p and no index.
\item \verb}p^} a partial variable of type boole with name p and no index.
\item \verb}p2} a total variable of type boole with name p and index 2.
\item \verb}p_2} a total variable of type boole with name p and index 2.
\item \verb}p^2} a partial variable of type boole with name p and index 2.
\item \verb}boole} a total anonymous variable of type boole with no index.
\item \verb}boole_} a total anonymous variable of type boole with no index.
\item \verb}boole^} a partial anonymous variable of type boole with no index.
\item \verb}boole_2} a total anonymous variable of type boole with index 2.
\item \verb}boole2} a total anonymous variable of type boole with index 2.
\item \verb}boole^2} a partial anonymous variable of type boole with index 2.
\item \verb}boole 2} a total anonymous variable of type boole applied to
the numeric term 2.
\item \verb}(boole)2} a total anonymous variable of type boole applied
to the numeric term 2.
\item \verb}(boole)_2} a total anonymous variable of type boole with index 2.
\item \verb}boole=>boole^2} a partial anonymous variable of type
function of boole to boole with index 2.
\end{itemize}
\emph{Terms} are built from atomic terms using application and
operators.
An atomic term is one of the following: a constant, a variable, a
number, a conditional, or any other term enclosed in parentheses.
Constants have \verb}const} as token type, and the respective term in
internal form as value. There are also composed constants, so-called
\emph{constant schemata}\index{constant scheme}. A constant schema
has the form of the name of the constant schema (token type
\texttt{constscheme}) followed by a list of types, the whole thing
enclosed in parentheses. There are a few built in constant schemata:
\verb}(Rec <typelist>)}\index{Rec@\texttt{Rec}} is the recursion over
the types given in the type list; \verb}(EQat <type>)} is the equality
for the given type; \verb}(Eat <type>)} is the existence predicate for
the given type. The constant schema \verb}EQat} can also be written
as the relational infix operator \verb}=}; the constant schemata
\verb}Eat} can also be written as the prefix operator \verb}E}.
For a number, the user defined function \verb}make-numeric-term} is
called with the number as argument. The return value of
\verb}make-numeric-term} should be the internal term representation of
the number.
To form a conditional term, the if operator \verb}if} followed by a
list of atomic terms is enclosed in square brackets. Depending on the
constructor of the first term, the selector, a conditional term can be
reduced to one of the remaining terms.
From these atomic terms, compound terms are built not only by
application but also using a variety of operators, that differ in
binding strength and associativity.
Postfix operators (token type \verb}postfix-op}) bind strongest, next
in binding strength are prefix operators (token type
\verb}prefix-op}), next come binding operators (token type
\verb}binding-op}).
A binding operator is followed by a list of variables and finally a
term. There are two more variations of binding operators, that bind
much weaker and are discussed later.
Next, after the binding operators, is plain application.
Juxtaposition of two terms means applying the first term to the
second. Sequences of applications associate to the left. According
to the \indexentry{vector notation} convention the meaning of
application depends on the type of the first term. Two forms of
applications are defined by default: if the type of the first term is
of \verb}arrow-form?} then \verb}make-term-in-app-form} is used; for
the type of a free algebra we use the corresponding form of recursion.
However, there is one exception: if the first term is of type
\verb}boole} application is read as a short-hand for the
\inquotes{if\dots then \dots else} construct (which is a special form)
rather than boolean recursion. The user may use the function
\verb}add-new-application}
\index{add-new-application@\texttt{add-new-application}} to add new
forms of applications. This function takes two arguments, a predicate
for the type of the first argument, and a function taking the two
terms and returning another term intended to be the result of this
form of application. Predicates are tested in the inverse order of
their definition, so more general forms of applications should be
added first.
By default these new forms of application are \emph{not} used for
output; but the user might declare that certain terms should be output
as formal application. \emph{When doing so it is the user's responisbility
to make sure that the syntax used for the output can still be parsed
correctly by the parser!}
To do so the function \texttt{(add-new-application-syntax pred toarg toop)}
can be used, where the first argument has to be a predicate (i.e., a function
mapping terms to \verb}#t} and \verb}#f}) telling whether this special
form of application can be used. If so, the arguments \texttt{toarg} and
\texttt{toop} have to be functions mapping the term to operator and
argument of this ``application'' respectively.
After that, we have binary operators written in infix notation. In
order of decreasing binding strength these are:
\begin{itemize}
\item multiplicative operators, leftassociative, token type \verb}mul-op};
\item additive operators, leftassociative, token type \verb}add-op};
\item relational operators, not associative, token type \verb}rel-op};
\item boolean and operators, leftassociative, token type \verb}and-op};
\item boolean or operators, leftassociative, token type \verb}or-op};
\item boolean implication operators, rightassociative, token type
\verb}imp-op};
\item pairing operators, rightassociative, token type \verb}pair-op}.
\end{itemize}
On the top level, we have two more forms of binding operators, one
using the dot ``\verb}.}'', the other using square brackets
``\verb}[ ]}''. Recall that a binding operator is followed by a list
of variables and a term. This notation can be augmented by a period
``\verb}.}'' following after the variable list and before the term.
In this case the scope of the binding extends as far to the right as
possible. Bindings with the lambda operator can also be specified by
including the list of variables in square brackets. In this case,
again, the scope of the binding extends as far as possible.
Predefined operators are \texttt{E} and \texttt{=} as described above,
the binding operator \texttt{lambda}, and the pairing operator
\verb}@} with two prefix operators \texttt{left} and \texttt{right}
for projection.
The value of an operator token is a function that will obtain the
internal representation of the component terms as arguments and
returns the internal representation of the whole term.
If a term is formed by application, the function
\verb}make-gen-application} is called with two subterms and returns
the compound term. The default here (for terms with an arrow type) is
to make a term in application form. However other rules of
composition might be introduced easily.
\emph{Formulas} are built from atomic formulas using junctors and
quantors.
The simplest atomic formulas are made from terms using the implicit
predicate ``atom''. The semantics of this predicate is well defined
only for terms of type boole. Further, a predicate constant (token
type \verb}predconst}) or a predicate variable (token type
\verb}pvar}) followed by a list of atomic terms is an atomic formula.
Lastly, any formula enclosed in parentheses is considered an atomic
formula.
The composition of formulas using junctors and quantors is very
similar to the composition of terms using operators and binding. So,
first postfix junctors, token type \verb}postfix-jct}, are applied,
next prefix junctors, token type \verb}prefix-jct}, and quantors,
token type \verb}quantor}, in the usual form: quantor, list of
variables, formula. Again, we have a notation using a period after
the list of variables, making the scope of the quantor as large as
possible. Predefined quantors are \texttt{ex}, \texttt{excl},
\texttt{exca}, and \texttt{all}.
The remaining junctors are binary junctors written in infix form. In
order of decreasing binding strength we have:
\begin{itemize}
\item conjunction junctors, leftassociative, token type \verb}and-jct};
\item disjunction junctors, leftassociative, token type \verb}or-jct};
\item tensor junctors, rightassociative, token type \verb}tensor-jct};
\item implication junctors, rightassociative, token type \verb}imp-jct}.
\end{itemize}
Predefined junctors are \verb}&} (and), \verb}!} (tensor), and
\verb}->} (implication).
The value of junctors and quantors is a function that will be called
with the appropriate subformulas, respectively variable lists, to
produce the compound formula in internal form.
\frenchspacing
\bibliography{minlog}
\bibliographystyle{amsplain}
% \bibliographystyle{plain}
\printindex
\end{document}
%%% Local Variables:
%%% mode: latex-math
%%% TeX-master: t
%%% End:
|