Datasets:
File size: 340,602 Bytes
b96a768 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 7555 7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 7801 7802 7803 7804 7805 7806 7807 7808 7809 7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 7863 7864 7865 7866 7867 7868 7869 7870 7871 7872 7873 7874 7875 7876 7877 7878 7879 7880 7881 7882 7883 7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 7895 7896 7897 7898 7899 7900 7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 7921 7922 7923 7924 7925 7926 7927 7928 7929 7930 7931 7932 7933 7934 7935 7936 7937 7938 7939 7940 7941 7942 7943 7944 7945 7946 | function_signature,docstring,test_cases,problem_spec_nl,problem_spec_formal_ground_truth,problem_spec_formal_generated,isomorphism_theorem,isomorphism_proof,implementation_signature,implementation,test_cases_lean,correctness_theorem,correctness_proof,helper_definitions,isomorphism_helper_lemmas,correctness_helper_lemmas
"def has_close_elements(numbers: List[float], threshold: float) -> bool","Check if in given list of numbers, are any two numbers closer to each other than given threshold.","[{""input"": [[1.0, 2.0, 3.0], 0.5], ""expected_output"": false}, {""input"": [[1.0, 2.8, 3.0, 4.0, 5.0, 2.0], 0.3], ""expected_output"": true}]","def has_close_elements(numbers: List[float], threshold: float) -> bool
""""""Check if in given list of numbers, are any two numbers closer to each other than given threshold.""""""","def problem_spec
-- function signature
(impl: List Rat β Rat β Bool)
-- inputs
(numbers: List Rat)
(threshold: Rat) :=
-- spec
let numbers_within_threshold :=
(β i j, i < numbers.length β§ j < numbers.length β§
i β j β§ |numbers.get! i - numbers.get! j| < threshold);
let spec (res: Bool) :=
numbers.length > 1 β
if res then numbers_within_threshold else Β¬numbers_within_threshold;
-- program terminates
β result, impl numbers threshold = result β§
-- return value satisfies spec
spec result
-- if result then spec else Β¬spec","def generated_spec
-- function signature
(impl: List Rat β Rat β Bool)
-- inputs
(numbers: List Rat)
(threshold: Rat) : Prop :=","theorem spec_isomorphism:
β impl,
(β numbers threshold, problem_spec impl numbers threshold) β
(β numbers threshold, generated_spec impl numbers threshold) :=",sorry,def implementation (numbers: List Rat) (threshold: Rat) : Bool :=,"match numbers with
| [] => false
| (x::xs) => (xs.any (fun y => (|x - y| < threshold))) || implementation xs threshold","#test implementation ([1, 2, 3]: List Rat) 0.5 = false
#test implementation ([1, 2.8, 3, 4, 5, 2]: List Rat) 0.3 = true","theorem correctness
(numbers: List Rat)
(threshold: Rat)
: problem_spec implementation numbers threshold :=","by
unfold problem_spec
let result := implementation numbers threshold
use result
simp [result]
induction numbers
simp [implementation]
rename_i head tail ih
simp at *
by_cases result = false
rename_i h_result_false
simp [result] at h_result_false
simp [h_result_false]
simp [implementation] at h_result_false
have h_tail_impl_false := And.right h_result_false
have h_head_in_threshold := And.left h_result_false
simp [h_tail_impl_false] at ih
by_cases h_1_lt_tail: 1 < tail.length
have h_0_lt_tail_len : 0 < tail.length := by linarith
simp [h_0_lt_tail_len, h_1_lt_tail]
simp [h_1_lt_tail] at ih
intros i h_i j h_j h_i_neq_j
by_cases i = 0
rename_i h_i_eq_0
simp [h_i_eq_0]
simp [h_i_eq_0] at h_i_neq_j
have h_0_lt_j : 0 < j := by
contrapose! h_i_neq_j
linarith
let j' := j - 1
have h_j'_tail : (head::tail)[j' + 1]! = tail[j']! := by
rw [List.getElem!_cons_succ]
have h_j'_j : j' + 1 = j := by
simp [j']
rw [Nat.sub_add_cancel h_0_lt_j]
rw [βh_j'_j]
simp [h_j'_tail]
have h_j'_lt_tail_len : j' < tail.length := by
linarith
simp [h_j'_lt_tail_len]
apply h_head_in_threshold
simp
rename_i h_i_neq_0
have h_0_lt_i : 0 < i := by
contrapose! h_i_neq_0
linarith
let i' := i - 1
have h_i'_tail : (head::tail)[i' + 1]! = tail[i']! := by
rw [List.getElem!_cons_succ]
have h_i'_i : i' + 1 = i := by
simp [i']
rw [Nat.sub_add_cancel h_0_lt_i]
rw [βh_i'_i]
simp [h_i'_tail]
have h_i'_lt_tail_len : i' < tail.length := by
linarith
simp [h_i'_lt_tail_len]
by_cases 0 < j
rename_i h_0_lt_j
let j' := j - 1
have h_j'_tail : (head::tail)[j' + 1]! = tail[j']! := by
rw [List.getElem!_cons_succ]
have h_j'_j : j' + 1 = j := by
simp [j']
rw [Nat.sub_add_cancel h_0_lt_j]
rw [βh_j'_j]
simp [h_j'_tail]
have h_j'_lt_tail_len : j' < tail.length := by
linarith
simp [h_j'_lt_tail_len]
have h_i'_neq_j' : i' β j' := by
contrapose! h_i_neq_j
linarith
have h_final := ih i'
simp [h_i'_lt_tail_len] at h_final
have h_final' := h_final j' h_j'_lt_tail_len
simp [h_i'_neq_j'] at h_final'
simp [h_j'_lt_tail_len] at h_final'
assumption
rename_i h_j_le_0
have h_j_eq_0 : j = 0 := by
linarith
simp [h_j_eq_0]
have h_head_minus_tail : tail[i'] - head = -(head - tail[i']) := by
simp
rw [h_head_minus_tail]
have h_head_minus_tail_lt_threshold : |-(head - tail[i'])| = |head - tail[i']| := by
rw [abs_neg]
rw [h_head_minus_tail_lt_threshold]
apply h_head_in_threshold
simp
have h_tl_eq_0 : tail.length β€ 1 := by
linarith
by_cases tail.length = 1
rename_i h_tl_eq_1
simp [h_tl_eq_1]
intros i h_i j h_j h_i_neq_j
by_cases i = 0
rename_i h_i_eq_0
simp [h_i_eq_0]
by_cases j = 0
rename_i h_j_eq_0
rw [h_j_eq_0] at h_i_neq_j
contradiction
by_cases j = 1
rename_i h_j_eq_1
simp [h_j_eq_1]
simp [h_tl_eq_1]
apply h_head_in_threshold
simp
rename_i h_j_neq_1 h_j_neq_0
have h_0_lt_j : 0 < j := by
contrapose! h_j_neq_0
simp at h_j_neq_0
contradiction
have h_1_lt_j : 1 < j := by
contrapose! h_j_neq_1
have h_j_eq_1' : j = 1 := by
linarith
contradiction
linarith
rename_i h_i_neq_0
by_cases i = 1
rename_i h_i_eq_1
simp [h_i_eq_1]
simp [h_tl_eq_1]
by_cases j = 0
rename_i h_j_eq_0
simp [h_j_eq_0]
have h_head_minus_tail : tail[0] - head = -(head - tail[0]) := by
simp
rw [h_head_minus_tail]
rw [abs_neg]
apply h_head_in_threshold
simp
by_cases j = 1
rename_i h_j_neq_0 h_j_eq_1
rw [h_j_eq_1] at h_i_neq_j
contradiction
rename_i h_j_neq_1 h_j_neq_0
have h_0_lt_j : 0 < j := by
contrapose! h_j_neq_0
simp at h_j_neq_0
contradiction
have h_1_lt_j : 1 < j := by
contrapose! h_j_neq_1
have h_j_eq_1' : j = 1 := by
linarith
contradiction
linarith
rename_i h_i_neq_1
have h_0_lt_i : 0 < i := by
contrapose! h_i_neq_1
simp at h_i_neq_1
contradiction
have h_1_lt_i : 1 < i := by
contrapose! h_i_neq_0
have h_i_eq_1' : i = 1 := by
linarith
contradiction
linarith
rename_i h_tl_neq_1
rw [Nat.le_one_iff_eq_zero_or_eq_one] at h_tl_eq_0
by_cases tail.length = 0
rename_i h_tl_eq_0
simp [h_tl_eq_0]
rename_i h_tl_neq_0
cases h_tl_eq_0
contradiction
contradiction
-- case when tail has two elements that are close to each other
rename_i h_result_true
simp at h_result_true
simp [result] at h_result_true
simp [h_result_true]
simp [implementation] at h_result_true
by_cases h_0_lt_tail_len : 0 < tail.length
rw [List.exists_mem_iff_getElem] at h_result_true
simp [h_0_lt_tail_len]
cases h_result_true
use 0
simp
rename_i h_head_in_threshold
obtain β¨ j, h_j_lt_len, h_j_in_threshold β© := h_head_in_threshold
use j + 1
simp [h_j_lt_len]
assumption
rename_i h_tail_has_close_elements
simp [h_tail_has_close_elements] at ih
by_cases h_1_lt_tail : 1 < tail.length
simp [h_1_lt_tail] at ih
obtain β¨ i, h_i_lt_tail_len, h_i_in_threshold β© := ih
use i + 1
have h_i_lt_tail_len' : i + 1 < tail.length + 1 := by linarith
simp [h_i_lt_tail_len']
obtain β¨ j, h_j_lt_tail_len, h_i_neq_j, h_j_in_threshold β© := h_i_in_threshold
use j + 1
simp [h_j_lt_tail_len]
simp [h_i_neq_j]
simp [h_i_lt_tail_len, h_j_lt_tail_len] at h_j_in_threshold
assumption
use 0
simp
use 1
simp
unfold implementation at h_tail_has_close_elements
by_cases h_1_tail: tail.length = 0
have h_tail_empty := List.eq_nil_of_length_eq_zero h_1_tail
simp [h_tail_empty] at h_tail_has_close_elements
simp at h_1_lt_tail
have h_0_lt_tail_len : tail.length = 1 := by linarith
have h_tail_singleton: β x, tail = [x] := by
rw [List.length_eq_one] at h_0_lt_tail_len
assumption
obtain β¨ x, h_tail_singleton β© := h_tail_singleton
simp [h_0_lt_tail_len]
simp [h_tail_singleton]
try (simp [h_tail_singleton] at h_tail_has_close_elements)
unfold implementation at h_tail_has_close_elements
simp at h_tail_has_close_elements
simp at h_0_lt_tail_len
have h_tail_ln_eq_0 : tail.length = 0 := by
rw [h_0_lt_tail_len]
simp
simp [h_tail_ln_eq_0]",,,
def separate_paren_groups(paren_string: str) -> List[str],"Input to this function is a string containing multiple groups of nested parentheses. Your goal is to
separate those group into separate strings and return the list of those.
Separate groups are balanced (each open brace is properly closed) and not nested within each other
Ignore any spaces in the input string.
","[{""input"": ""( ) (( )) (( )( ))"", ""expected_output"": [""()"", ""(())"", ""(()())""]}]","def separate_paren_groups(paren_string: str) -> List[str]
""""""Input to this function is a string containing multiple groups of nested parentheses. Your goal is to
separate those group into separate strings and return the list of those.
Separate groups are balanced (each open brace is properly closed) and not nested within each other
Ignore any spaces in the input string.
""""""","def problem_spec
-- function signature
(impl: String β List String)
-- inputs
(paren_string: String) :=
-- spec
let paren_string_filtered := (paren_string.toList.filter (fun c => c == '(' β¨ c == ')')).asString;
let forward_spec (result_list: List String) :=
-- every substring of the input string
-- that is a balanced paren group is in
-- the result list
β i j, j < paren_string_filtered.length β i β€ j β
let substr_ij := (paren_string_filtered.take (j + 1)).drop i;
balanced_paren_non_computable substr_ij '(' ')' β
count_paren_groups substr_ij = 1 β
substr_ij β result_list;
let backward_spec (result_list: List String) :=
-- every string in the result list is a
-- balanced paren group and is a substring
-- of the input string i.e. there is no
-- extra substring in the result list
-- that is not from the input string
β str, str β result_list β
paren_string_filtered.containsSubstr str = true β§
balanced_paren_non_computable str '(' ')' β§
count_paren_groups str = 1;
let spec (result_list: List String) :=
forward_spec result_list β§ backward_spec result_list;
-- program terminates
β result, impl paren_string = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: String β List String)
-- inputs
(paren_string: String) : Prop :=","theorem spec_isomorphism:
β impl,
(β paren_string, problem_spec impl paren_string) β
(β paren_string, generated_spec impl paren_string) :=",sorry,def implementation (paren_string: String) : List String :=,"-- remove space or any other characters that are not '(' or ')'
let filtered := paren_string.toList.filter (fun c => c == '(' β¨ c == ')');
-- auxiliary recursive function:
let rec aux (cs : List Char) (cur : List Char) (balance : Int) (acc : List String) : List String :=
match cs with
| [] => acc.reverse -- when finished, return accumulated groups in original order
| c::rest =>
let new_cur := cur ++ [c]
let new_balance:= if c = '(' then
balance + 1
else
balance - 1
if new_balance = 0 then
let group := new_cur.asString
aux rest [] 0 (group :: acc)
else
aux rest new_cur new_balance acc;
aux filtered [] 0 []","#test implementation ""( ) (( )) (( )( ))"" = [""()"", ""(())"", ""(()())""]","theorem correctness
(paren_string: String)
: problem_spec implementation paren_string :=","by
unfold problem_spec
let result := implementation paren_string
use result
simp [result]
sorry","/--
name: string_is_paren_balanced_helper
use: |
Helper function to check if a string is balanced with respect to parentheses.
problems:
- 1
- 6
- 132
sample_problems:
- 0
-/
def string_is_paren_balanced_helper
(paren_string: String) (num_open: Int): Bool
:=
-- Recursively check if the string is balanced
if paren_string.isEmpty then
num_open = 0
else
let c := paren_string.get! 0
if c == '(' then
string_is_paren_balanced_helper (paren_string.drop 1) (num_open + 1)
else if c == ')' then
string_is_paren_balanced_helper (paren_string.drop 1) (num_open - 1)
else
string_is_paren_balanced_helper (paren_string.drop 1) num_open
termination_by paren_string.length
decreasing_by
all_goals
{
rename_i h_non_empty_string
rw [String.drop_eq, String.length]
simp
rw [String.isEmpty_iff] at h_non_empty_string
by_cases h_paren_nil : paren_string.length β€ 0
rw [Nat.le_zero_eq] at h_paren_nil
rw [βstring_eq_iff_data_eq] at h_non_empty_string
have h_temp : """".data = [] := by simp
rw [h_temp] at h_non_empty_string
rw [String.length] at h_paren_nil
rw [List.length_eq_zero] at h_paren_nil
contradiction
have h_temp : paren_string.length > 0 := by linarith
assumption
}
/--
name: string_is_paren_balanced
use: |
Function to check if a string is balanced with respect to parentheses.
problems:
- 1
- 6
- 132
sample_problems:
- 0
-/
def string_is_paren_balanced
(paren_string: String): Bool
:=
string_is_paren_balanced_helper paren_string 0
/--
name: count_paren_groups_helper
use: |
Helper to count the number of groups of parentheses in a string.
problems:
- 1
-/
def count_paren_groups_helper
(paren_string: String) (num_open: Int) (num_groups: Nat): Nat :=
-- Recursively count the number of paren groups
if paren_string.isEmpty then
num_groups
else
let c := paren_string.get! 0
if c == '(' then
count_paren_groups_helper (paren_string.drop 1) (num_open + 1) num_groups
else if c == ')' then
let new_num_groups :=
if num_open == 1 then num_groups + 1 else num_groups
count_paren_groups_helper (paren_string.drop 1) (num_open - 1) new_num_groups
else
count_paren_groups_helper (paren_string.drop 1) num_open num_groups
termination_by paren_string.length
decreasing_by
all_goals
{
rename_i h_non_empty_string
rw [String.drop_eq, String.length]
simp
rw [String.isEmpty_iff] at h_non_empty_string
by_cases h_paren_nil : paren_string.length β€ 0
rw [Nat.le_zero_eq] at h_paren_nil
rw [βstring_eq_iff_data_eq] at h_non_empty_string
have h_temp : """".data = [] := by simp
rw [h_temp] at h_non_empty_string
rw [String.length] at h_paren_nil
rw [List.length_eq_zero] at h_paren_nil
contradiction
have h_temp : paren_string.length > 0 := by linarith
assumption
}
/--
name: count_paren_groups
use: |
Function to count the number of groups of parentheses in a string.
problems:
- 1
-/
def count_paren_groups
(paren_string: String): Nat :=
count_paren_groups_helper paren_string 0 0",,
def truncate_number(number: float) -> float,"Given a positive floating point number, it can be decomposed into
and integer part (largest integer smaller than given number) and decimals
(leftover part always smaller than 1).
","[{""input"": 3.5, ""expected_output"": 0.5}]","def truncate_number(number: float) -> float
""""""Given a positive floating point number, it can be decomposed into
and integer part (largest integer smaller than given number) and decimals
(leftover part always smaller than 1).
""""""","def problem_spec
-- function signature
(impl: Rat β Rat)
-- inputs
(number: Rat) :=
-- spec
let spec (res) :=
0 β€ res β§
res < 1 β§
number.floor + res = number;
number > 0 β
-- program terminates
(β result, impl number = result β§
-- return value satisfies spec
spec result)","def generated_spec
-- function signature
(impl: Rat β Rat)
-- inputs
(number: Rat) : Prop :=","theorem spec_isomorphism:
β impl,
(β number, problem_spec impl number) β
(β number, generated_spec impl number) :=",sorry,def implementation (number: Rat) : Rat :=,number - number.floor,#test implementation 3.5 = 0.5,"theorem correctness
(number: Rat)
: problem_spec implementation number :=","by
unfold problem_spec
let result := implementation number
simp [result]
simp [implementation]
have h1: β x: Rat, x.floor β€ x := by
intro x
rw [βRat.le_floor]
intro npos
apply And.intro
apply h1
have h2 := h1 number
sorry",,,
def below_zero(operations: List[int]) -> bool,"You're given a list of deposit and withdrawal operations on a bank account that starts with
zero balance. Your task is to detect if at any point the balance of account fallls below zero, and
at that point function should return True. Otherwise it should return False.
","[{""input"": [1, 2, 3], ""expected_output"": false}, {""input"": [1, 2, -4, 5], ""expected_output"": true}]","def below_zero(operations: List[int]) -> bool
""""""You're given a list of deposit and withdrawal operations on a bank account that starts with
zero balance. Your task is to detect if at any point the balance of account fallls below zero, and
at that point function should return True. Otherwise it should return False.
""""""","def problem_spec
-- function signature
(impl: List Int β Bool)
-- inputs
(operations: List Int) :=
-- spec
let below_zero_condition := β i, i β€ operations.length β§
(operations.take i).sum < 0;
let spec (result: Bool) :=
if result then below_zero_condition else Β¬below_zero_condition;
-- program terminates
β result, impl operations = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: List Int β Bool)
-- inputs
(operations: List Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β operations, problem_spec impl operations) β
(β operations, generated_spec impl operations) :=",sorry,def implementation (operations: List Int) : Bool :=,"let rec check (ops : List Int) (acc : Int) : Bool :=
match ops with
| [] => false
| op :: ops' =>
let new_acc := acc + op
if new_acc < 0 then true else check ops' new_acc
check operations 0","#test implementation [1, 2, 3] = false
#test implementation [1, 2, -4, 5] = true","theorem correctness
(operations: List Int)
: problem_spec implementation operations
:=","by
-- sometimes we have to create a temporary variable to use in the proof
unfold problem_spec
let result := implementation operations
use result
simp [result]
simp [implementation]
-- induction at this point will not work
-- because the induction hypothesis is not strong enough
-- we need to prove a stronger inductive hypothesis
have h_harder_inductive_hypothesis_true:
β h, β ops,
implementation.check ops h = true β
β i, i β€ ops.length β§ h + (ops.take i).sum < 0 := by
intros h ops h_check
induction' ops generalizing h
simp [implementation.check] at h_check
rename_i head tail ih
simp [implementation.check] at h_check
by_cases h_head_lt_0 : h + head < 0
use 1
simp
assumption
simp at h_head_lt_0
cases h_check
linarith
rename_i h_tail_sum_gt_0
specialize ih (h + head)
simp [h_tail_sum_gt_0] at ih
obtain β¨i, h_i_lt_tail_len, h_tail_sum_lt_0β© := ih
use i + 1
simp [h_i_lt_tail_len]
linarith
by_cases h_if_pos: (implementation.check operations 0 = true)
simp [h_if_pos]
obtain β¨i, h_i_lt_tail_len, h_tail_sum_lt_0β© := h_harder_inductive_hypothesis_true 0 operations h_if_pos
simp at h_tail_sum_lt_0
use i
have h_harder_inductive_hypothesis_false:
β h, β ops, h β₯ 0 β
implementation.check ops h = false β
β i, i β€ ops.length β h + (ops.take i).sum β₯ 0 := by
intros h ops h_ge_0 h_check
induction' ops generalizing h
intros i h_i_lt_tail_len
simp [implementation.check] at h_check
simp
linarith
rename_i head tail ih
simp [implementation.check] at h_check
by_cases h_head_lt_0 : h + head < 0
simp at h_head_lt_0
cases h_check
linarith
simp at h_head_lt_0
apply And.right at h_check
specialize ih (h + head)
simp at ih
simp [h_head_lt_0, h_check] at ih
intros i h_i_lt_tail_len
simp at h_i_lt_tail_len
simp
specialize ih (i - 1)
by_cases h_i_1_lt_i: 1 β€ i
let i' := i - 1
have h_i'_lt_tail_len: i = i' + 1 := by
simp [i']
rw [Nat.sub_add_cancel]
linarith
simp [h_i'_lt_tail_len]
rw [βInt.add_assoc]
have h_i_minus_1_lt_tail_len: i - 1 β€ tail.length := by
linarith
simp [h_i_minus_1_lt_tail_len] at ih
simp [i']
assumption
simp at h_i_1_lt_i
simp [h_i_1_lt_i] at ih
simp [h_i_1_lt_i]
linarith
simp at h_if_pos
simp [h_if_pos]
have h_harder' := h_harder_inductive_hypothesis_false 0 operations
simp at h_harder'
simp [h_if_pos] at h_harder'
intros i h_i_lt_tail_len
apply h_harder'
assumption",,,
def mean_absolute_deviation(numbers: List[float]) -> float,"For a given list of input numbers, calculate Mean Absolute Deviation
around the mean of this dataset.
Mean Absolute Deviation is the average absolute difference between each
element and a centerpoint (mean in this case):
MAD = average | x - x_mean |
","[{""input"": [1.0, 2.0, 3.0, 4.0], ""expected_output"": 1.0}]","def mean_absolute_deviation(numbers: List[float]) -> float
""""""For a given list of input numbers, calculate Mean Absolute Deviation
around the mean of this dataset.
Mean Absolute Deviation is the average absolute difference between each
element and a centerpoint (mean in this case):
MAD = average | x - x_mean |
""""""","def problem_spec
-- function signature
(implementation: List Rat β Rat)
-- inputs
(numbers: List Rat) :=
-- spec
let spec (result: Rat):=
0 < numbers.length β
0 β€ result β§
result * numbers.length * numbers.length =
(numbers.map (fun x => |x * numbers.length - numbers.sum|)).sum;
-- program terminates
β result, implementation numbers = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(implementation: List Rat β Rat)
-- inputs
(numbers: List Rat) : Prop :=","theorem spec_isomorphism:
β implementation,
(β numbers, problem_spec implementation numbers) β
(β numbers, generated_spec implementation numbers) :=",sorry,def implementation (numbers: List Rat) : Rat :=,"if numbers.length = 0 then 1.0
else
let mean := numbers.sum / numbers.length;
let abs_diffs := numbers.map (fun x => |x - mean|);
abs_diffs.sum / abs_diffs.length","#test implementation [1.0, 2.0, 3.0, 4.0] = 1.0","theorem correctness
(numbers: List Rat)
: problem_spec implementation numbers
:=","by
-- sometimes we have to create a temporary variable to use in the proof
unfold problem_spec
let result := implementation numbers
use result
simp [result]
simp [implementation]
by_cases (numbers.length = 0)
rename_i h
simp [h]
rename_i h
simp at h
have h1: 0 < numbers.length := by
by_contra
rename_i h2
simp at h2
contradiction
simp [h1]
simp [h]
sorry",,,
"def intersperse(numbers: List[int], delimeter: int) -> List[int]","Insert a number 'delimeter' between every two consecutive elements of input list `numbers'
","[{""input"": [[], 4], ""expected_output"": []}, {""input"": [[1, 2, 3], 4], ""expected_output"": [1, 4, 2, 4, 3]}]","def intersperse(numbers: List[int], delimeter: int) -> List[int]
""""""Insert a number 'delimeter' between every two consecutive elements of input list `numbers'
""""""","def problem_spec
-- function signature
(implementation: List Int β Int β List Int)
-- inputs
(numbers: List Int)
(delimeter: Int) :=
-- spec
let spec (result: List Int) :=
(result.length = 0 β§ result = numbers) β¨
(result.length = 2 β§ numbers.length = 1 β§
result[0]! = numbers[0]! β§ result[1]! = delimeter) β¨
(result.length = 2 * numbers.length - 1 β§
β i, i < numbers.length β
result[2 * i]! = numbers[i]! β§
(0 < 2*i - 1 β result[2 * i - 1]! = delimeter));
-- program termination
β result, implementation numbers delimeter = result β§
spec result","def generated_spec
-- function signature
(implementation: List Int β Int β List Int)
-- inputs
(numbers: List Int)
(delimeter: Int) : Prop :=","theorem spec_isomorphism:
β implementation,
(β numbers delimeter, problem_spec implementation numbers delimeter) β
(β numbers delimeter, generated_spec implementation numbers delimeter) :=",sorry,def implementation (numbers: List Int) (delimeter: Int) : List Int :=,numbers.intersperse delimeter,"#test implementation [1, 2, 3] 4 = [1, 4, 2, 4, 3]
#test implementation [] 4 = []
#test implementation [1] 4 = [1]","theorem correctness
(numbers: List Int)
(delimeter: Int)
: problem_spec implementation numbers delimeter
:=","by
unfold problem_spec
let result := implementation numbers delimeter
use result
simp [result]
sorry",,,
def parse_nested_parens(paren_string: str) -> List[int],"Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
For each of the group, output the deepest level of nesting of parentheses.
E.g. (()()) has maximum two levels of nesting while ((())) has three.
","[{""input"": ""(()()) ((())) () ((())()())"", ""expected_output"": [2, 3, 1, 3]}]","def parse_nested_parens(paren_string: str) -> List[int]
""""""Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
For each of the group, output the deepest level of nesting of parentheses.
E.g. (()()) has maximum two levels of nesting while ((())) has three.
""""""","def problem_spec
-- function signature
(implementation: String β List Int)
-- inputs
(paren_string: String)
:=
-- spec
let spec (result: List Int) :=
let paren_space_split := paren_string.split (fun x => x = ' ');
result.length = paren_space_split.length β§
β i, i < result.length β
let group := paren_space_split[i]!;
balanced_paren_non_computable group '(' ')' β
0 < result[i]! β§ count_max_paren_depth group = result[i]!.toNat;
-- program termination
β result, implementation paren_string = result β§
spec result","def generated_spec
-- function signature
(implementation: String β List Int)
-- inputs
(paren_string: String) : Prop :=","theorem spec_isomorphism:
β implementation,
(β paren_string, problem_spec implementation paren_string) β
(β paren_string, generated_spec implementation paren_string) :=",sorry,def implementation (paren_string: String) : List Int :=,(paren_string.split (fun x => x = ' ')).map (fun x => count_max_paren_depth x),"#test implementation ""(()()) ((())) () ((())()())"" = [2, 3, 1, 3]","theorem correctness
(paren_string: String)
: problem_spec implementation paren_string
:=","by
unfold problem_spec
let result := implementation paren_string
use result
simp [result]
sorry","/--
name: string_is_paren_balanced_helper
use: |
Helper function to check if a string is balanced with respect to parentheses.
problems:
- 1
- 6
- 132
sample_problems:
- 0
-/
def string_is_paren_balanced_helper
(paren_string: String) (num_open: Int): Bool
:=
-- Recursively check if the string is balanced
if paren_string.isEmpty then
num_open = 0
else
let c := paren_string.get! 0
if c == '(' then
string_is_paren_balanced_helper (paren_string.drop 1) (num_open + 1)
else if c == ')' then
string_is_paren_balanced_helper (paren_string.drop 1) (num_open - 1)
else
string_is_paren_balanced_helper (paren_string.drop 1) num_open
termination_by paren_string.length
decreasing_by
all_goals
{
rename_i h_non_empty_string
rw [String.drop_eq, String.length]
simp
rw [String.isEmpty_iff] at h_non_empty_string
by_cases h_paren_nil : paren_string.length β€ 0
rw [Nat.le_zero_eq] at h_paren_nil
rw [βstring_eq_iff_data_eq] at h_non_empty_string
have h_temp : """".data = [] := by simp
rw [h_temp] at h_non_empty_string
rw [String.length] at h_paren_nil
rw [List.length_eq_zero] at h_paren_nil
contradiction
have h_temp : paren_string.length > 0 := by linarith
assumption
}
/--
name: string_is_paren_balanced
use: |
Function to check if a string is balanced with respect to parentheses.
problems:
- 1
- 6
- 132
sample_problems:
- 0
-/
def string_is_paren_balanced
(paren_string: String): Bool
:=
string_is_paren_balanced_helper paren_string 0
/--
name: count_max_paren_depth_helper
use: |
Helper to count the maximum depth of parentheses in a string.
problems:
- 6
- 132
-/
def count_max_paren_depth_helper
(paren_string: String) (num_open: Int) (max_depth: Nat): Nat :=
-- Recursively count the maximum depth of parentheses
if paren_string.isEmpty then
max_depth
else
let c := paren_string.get! 0
if c == '(' then
let new_num_open := num_open + 1
count_max_paren_depth_helper (paren_string.drop 1) (new_num_open) (max_depth.max new_num_open.toNat)
else if c == ')' then
count_max_paren_depth_helper (paren_string.drop 1) (num_open - 1) max_depth
else
count_max_paren_depth_helper (paren_string.drop 1) num_open max_depth
termination_by paren_string.length
decreasing_by
all_goals
{
rename_i h_non_empty_string
rw [String.drop_eq, String.length]
simp
rw [String.isEmpty_iff] at h_non_empty_string
by_cases h_paren_nil : paren_string.length β€ 0
rw [Nat.le_zero_eq] at h_paren_nil
rw [βstring_eq_iff_data_eq] at h_non_empty_string
have h_temp : """".data = [] := by simp
rw [h_temp] at h_non_empty_string
rw [String.length] at h_paren_nil
rw [List.length_eq_zero] at h_paren_nil
contradiction
have h_temp : paren_string.length > 0 := by linarith
assumption
}
/--
name: count_max_paren_depth
use: |
Function to count the maximum depth of parentheses in a string.
problems:
- 6
- 132
-/
def count_max_paren_depth
(paren_string: String): Nat :=
count_max_paren_depth_helper paren_string 0 0",,
"def filter_by_substring(strings: List[str], substring: str) -> List[str]","Filter an input list of strings only for ones that contain given substring
","[{""input"": [[], ""a""], ""expected_output"": []}, {""input"": [[""abc"", ""bacd"", ""cde"", ""array""], ""a""], ""expected_output"": [""abc"", ""bacd"", ""array""]}]","def filter_by_substring(strings: List[str], substring: str) -> List[str]
""""""Filter an input list of strings only for ones that contain given substring
""""""","def problem_spec
-- function signature
(implementation: List String β String β List String)
-- inputs
(strings: List String)
(substring: String)
:=
-- spec
let spec (result: List String) :=
(β i, i < result.length β result[i]!.containsSubstr substring β
β j, j < strings.length β§ strings[j]!.containsSubstr substring β strings[j]! β result β
β j, j < result.length β result.count result[j]! = strings.count result[j]!);
-- program termination
β result, implementation strings substring = result β§
spec result","def generated_spec
-- function signature
(implementation: List String β String β List String)
-- inputs
(strings: List String)
(substring: String) : Prop :=","theorem spec_isomorphism:
β implementation,
(β strings substring, problem_spec implementation strings substring) β
(β strings substring, generated_spec implementation strings substring) :=",sorry,def implementation (strings: List String) (substring: String): List String :=,strings.filter (fun x => x.containsSubstr substring),"#test implementation [] ""a"" = []
#test implementation [""abc"", ""bacd"", ""cde"", ""array""] ""a"" = [""abc"", ""bacd"", ""array""]","theorem correctness
(strings: List String)
(substring: String)
: problem_spec implementation strings substring
:=","by
unfold problem_spec
let result := implementation strings substring
use result
simp [result]
sorry",,,
"def sum_product(numbers: List[int]) -> Tuple[int, int]","For a given list of integers, return a tuple consisting of a sum and a product of all the integers in a list.
Empty sum should be equal to 0 and empty product should be equal to 1.
","[{""input"": [], ""expected_output"": ""(0, 1)""}, {""input"": [1, 2, 3, 4], ""expected_output"": ""(10, 24)""}]","def sum_product(numbers: List[int]) -> Tuple[int, int]
""""""For a given list of integers, return a tuple consisting of a sum and a product of all the integers in a list.
Empty sum should be equal to 0 and empty product should be equal to 1.
""""""","def problem_spec
-- function signature
(implementation: List Int β (Int Γ Int))
-- inputs
(numbers: List Int) :=
-- spec
let spec (result: (Int Γ Int)) :=
let (sum, prod) := result;
(numbers = [] β sum = 0 β§ prod = 1) β§
(numbers β [] β
(let (sum_tail, prod_tail) := implementation numbers.tail;
sum - sum_tail = numbers[0]! β§
sum_tail * prod_tail + prod = sum * prod_tail));
-- program termination
β result, implementation numbers = result β§
spec result","def generated_spec
-- function signature
(implementation: List Int β (Int Γ Int))
-- inputs
(numbers: List Int) : Prop :=","theorem spec_isomorphism:
β implementation,
(β numbers, problem_spec implementation numbers) β
(β numbers, generated_spec implementation numbers) :=",sorry,def implementation (numbers: List Int) : (Int Γ Int) :=,"(numbers.sum, numbers.prod)","#test implementation [] = (0, 1)
#test implementation [1, 2, 3, 4] = (10, 24)","theorem correctness
(numbers: List Int)
: problem_spec implementation numbers
:=","by
unfold problem_spec
let result := implementation numbers
use result
simp [result]
simp [implementation]
sorry",,,
"def sum_product(numbers: List[int]) -> Tuple[int, int]","From a given list of integers, generate a list of rolling maximum element found until given moment
in the sequence.
","[{""input"": [1, 2, 3, 2, 3, 4, 2], ""expected_output"": [1, 2, 3, 3, 3, 4, 4]}]","def sum_product(numbers: List[int]) -> Tuple[int, int]
""""""From a given list of integers, generate a list of rolling maximum element found until given moment
in the sequence.
""""""","def problem_spec
-- function signature
(implementation: List Int β List Int)
-- inputs
(numbers: List Int) :=
-- spec
let spec (result: List Int) :=
result.length = numbers.length β§
β i, i < numbers.length β
(result[i]! β numbers.take (i + 1) β§
β j, j β€ i β numbers[j]! β€ result[i]!);
-- program termination
β result, implementation numbers = result β§
spec result","def generated_spec
-- function signature
(implementation: List Int β List Int)
-- inputs
(numbers: List Int) : Prop :=","theorem spec_isomorphism:
β implementation,
(β numbers, problem_spec implementation numbers) β
(β numbers, generated_spec implementation numbers) :=",sorry,def implementation (numbers: List Int) : List Int :=,"let rec rolling_max (numbers: List Int) (results: List Int) (acc: Int) : List Int :=
match numbers with
| [] => results
| n :: ns =>
let new_acc := max acc n
let new_results := results ++ [new_acc]
rolling_max ns new_results new_acc
rolling_max numbers [] 0","#test implementation [1, 2, 3, 2, 3, 4, 2] = [1, 2, 3, 3, 3, 4, 4]","theorem correctness
(numbers: List Int)
: problem_spec implementation numbers
:=","by
unfold problem_spec
let result := implementation numbers
use result
simp [result]
simp [implementation]
apply And.intro
induction numbers
simp
simp [implementation.rolling_max]
rename_i head tail ih
unfold implementation.rolling_max
simp
-- At this point we will have to
-- strengthen the induction hypothesis
-- to prove the correctness of the implementation
sorry
sorry",,,
def make_palindrome(string: str) -> str,"Find the shortest palindrome that begins with a supplied string.
Algorithm idea is simple:
- Find the longest postfix of supplied string that is a palindrome.
- Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.
","[{""input"": """", ""expected_output"": """"}, {""input"": ""cat"", ""expected_output"": ""catac""}, {""input"": ""cata"", ""expected_output"": ""catac""}]","def make_palindrome(string: str) -> str
""""""Find the shortest palindrome that begins with a supplied string.
Algorithm idea is simple:
- Find the longest postfix of supplied string that is a palindrome.
- Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.
""""""","def problem_spec
-- function signature
(implementation: String β String)
-- inputs
(string: String) :=
-- spec
let spec (result: String) :=
is_palindrome result β§
result.length β₯ string.length β§
string.isPrefixOf result β§
-- comprehensive check that the result is the shortest palindrome
(β (possible_palindrome: String),
string.isPrefixOf possible_palindrome β
is_palindrome possible_palindrome β
result.length β€ possible_palindrome.length);
-- program termination
β result, implementation string = result β§
spec result","def generated_spec
-- function signature
(implementation: String β String)
-- inputs
(string: String) : Prop :=","theorem spec_isomorphism:
β implementation,
(β string, problem_spec implementation string) β
(β string, generated_spec implementation string) :=",sorry,def implementation (string: String) : String :=,sorry,"-- #test implementation """" = """"
-- #test implementation ""cat"" = ""catac""
-- #test implementation ""cata"" = ""catac""","theorem correctness
(s: String)
: problem_spec implementation s
:=","by
unfold problem_spec
let result := implementation s
use result
simp [result]
sorry","/--
name: is_palindrome
use: |
Helper to check if a string is a palindrome.
problems:
- 10
- 48
-/
def is_palindrome
(s: String): Bool :=
s = s.toList.reverse.asString",,
"def string_xor(a: str, b: str) -> str","Input are two strings a and b consisting only of 1s and 0s.
Perform binary XOR on these inputs and return result also as a string.
","[{""input"": [""010"", ""110""], ""expected_output"": ""100""}]","def string_xor(a: str, b: str) -> str
""""""Input are two strings a and b consisting only of 1s and 0s.
Perform binary XOR on these inputs and return result also as a string.
""""""","def problem_spec
-- function signature
(implementation: String β String β String)
-- inputs
(a b: String) :=
-- spec
let spec (result: String) :=
a.all (fun c => c = '0' β¨ c = '1') β
b.all (fun c => c = '0' β¨ c = '1') β
a.length = b.length β
result.length = a.length β§
result.all (fun c => c = '0' β¨ c = '1') β§
(β i, i < a.length β
let i_pos := String.Pos.mk i;
(a.get i_pos = b.get i_pos β result.get i_pos = '0') β§
(a.get i_pos β b.get i_pos β result.get i_pos = '1'));
-- program termination
β result, implementation a b = result β§
spec result","def generated_spec
-- function signature
(implementation: String β String β String)
-- inputs
(a b: String) : Prop :=","theorem spec_isomorphism:
β implementation,
(β a b, problem_spec implementation a b) β
(β a b, generated_spec implementation a b) :=",sorry,def implementation (a b: String) : String :=,sorry,"-- #test implementation ""010"" ""110"" = ""100""","theorem correctness
(a b: String)
: problem_spec implementation a b
:=","by
unfold problem_spec
let result := implementation a b
use result
simp [result]
sorry",,,
def longest(strings: List[str]) -> Optional[str],"Out of list of strings, return the longest one. Return the first one in case of multiple
strings of the same length. Return None in case the input list is empty.
","[{""input"": [], ""expected_output"": ""None""}, {""input"": [""a"", ""b"", ""c""], ""expected_output"": ""a""}, {""input"": [""a"", ""bb"", ""ccc""], ""expected_output"": ""ccc""}]","def longest(strings: List[str]) -> Optional[str]
""""""Out of list of strings, return the longest one. Return the first one in case of multiple
strings of the same length. Return None in case the input list is empty.
""""""","def problem_spec
-- function signature
(implementation: List String β Option String)
-- inputs
(strings: List String) :=
-- spec
let spec (result: Option String) :=
(result = none β strings.length = 0) β¨
(β longest, result = some longest β§
longest β strings β§
β s, s β strings β s.length β€ longest.length β
(β i, i < strings.length β§
strings[i]! = longest β§ β j < i, strings[j]!.length < longest.length));
-- program termination
β result, implementation strings = result β§
spec result","def generated_spec
-- function signature
(implementation: List String β Option String)
-- inputs
(strings: List String) : Prop :=","theorem spec_isomorphism:
β implementation,
(β strings, problem_spec implementation strings) β
(β strings, generated_spec implementation strings) :=",sorry,def implementation (strings: List String) : Option String :=,"if strings = [] then none
else
let longest := (strings.map (Ξ» s => s.length)).maximum.get!
(strings.find? (Ξ» s => s.length = longest)).get!","#test implementation [""a"", ""b"", ""c""] = some ""a""
#test implementation [""a"", ""bb"", ""ccc""] = some ""ccc""
#test implementation [] = none","theorem correctness
(strings: List String)
: problem_spec implementation strings
:=","by
unfold problem_spec
let result := implementation strings
use result
simp [result]
sorry",,,
"def greatest_common_divisor(a: int, b: int) -> int","Return a greatest common divisor of two integers a and b
","[{""input"": [25, 15], ""expected_output"": 5}, {""input"": [3, 5], ""expected_output"": 1}]","def greatest_common_divisor(a: int, b: int) -> int
""""""Return a greatest common divisor of two integers a and b
""""""","def problem_spec
-- function signature
(implementation: Int β Int β Int)
-- inputs
(a b: Int) :=
-- spec
let spec (result: Int) :=
(result β£ a) β§
(result β£ b) β§
(β (d': Int),
(d' > 0) β (d' β£ a) β (d' β£ b) β
d' β€ result);
-- program termination
β result, implementation a b = result β§
spec result","def generated_spec
-- function signature
(implementation: Int β Int β Int)
-- inputs
(a b: Int) : Prop :=","theorem spec_isomorphism:
β implementation,
(β a b, problem_spec implementation a b) β
(β a b, generated_spec implementation a b) :=",sorry,def implementation (a b: Int) : Int :=,(Int.gcd a b),"#test implementation 25 15 = 5
#test implementation 3 5 = 1","theorem correctness
(a b: Int)
: problem_spec implementation a b
:=","by
unfold problem_spec
let result := implementation a b
use result
simp [result]
sorry",,,
def all_prefixes(string: str) -> List[str],"Return list of all prefixes from shortest to longest of the input string
","[{""input"": ""abc"", ""expected_output"": [""a"", ""ab"", ""abc""]}]","def all_prefixes(string: str) -> List[str]
""""""Return list of all prefixes from shortest to longest of the input string
""""""","def problem_spec
-- function signature
(implementation: String β List String)
-- inputs
(string: String) :=
-- spec
let spec (result: List String) :=
result.length = string.length β§
β i, i < result.length β
result[i]! = string.take (i + 1);
-- program termination
β result, implementation string = result β§
spec result","def generated_spec
-- function signature
(implementation: String β List String)
-- inputs
(string: String) : Prop :=","theorem spec_isomorphism:
β implementation,
(β string, problem_spec implementation string) β
(β string, generated_spec implementation string) :=",sorry,def implementation (string: String) : List String :=,"let rec aux (chars: List Char) (result: List String) (i: Nat) :=
if i < chars.length then
aux chars (result ++ [(chars.take (i + 1)).asString]) (i + 1)
else
result;
aux string.toList [] 0","#test implementation ""abc"" = [""a"", ""ab"", ""abc""]","theorem correctness
(string: String)
: problem_spec implementation string
:=","by
unfold problem_spec
let result := implementation string
use result
simp [result]
sorry",,,
def string_sequence(n: int) -> str,"Return a string containing space-delimited numbers starting from 0 upto n inclusive.
","[{""input"": 0, ""expected_output"": ""0""}, {""input"": 5, ""expected_output"": ""0 1 2 3 4 5""}]","def string_sequence(n: int) -> str
""""""Return a string containing space-delimited numbers starting from 0 upto n inclusive.
""""""","def problem_spec
-- function signature
(implementation: Nat β String)
-- inputs
(n: Nat) :=
-- spec
let spec (result: String) :=
let result_nums := result.splitOn "" "";
result_nums.length = n + 1 β§
β i, i < n + 1 β result_nums[i]! = i.repr;
-- program termination
β result, implementation n = result β§
spec result","def generated_spec
-- function signature
(implementation: Nat β String)
-- inputs
(n: Nat) : Prop :=","theorem spec_isomorphism:
β implementation,
(β n, problem_spec implementation n) β
(β n, generated_spec implementation n) :=",sorry,def implementation (n: Nat) : String :=,"(String.join (List.map (fun i => String.append i.repr "" "") (List.range n))).append (n.repr)","#test implementation 0 = ""0""
#test implementation 5 = ""0 1 2 3 4 5""","theorem correctness
(n: Nat)
: problem_spec implementation n
:=","by
unfold problem_spec
let result := implementation n
use result
simp [result]
sorry",,,
def count_distinct_characters(string: str) -> int,"Given a string, find out how many distinct characters (regardless of case) does it consist of
","[{""input"": ""xyzXYZ"", ""expected_output"": 3}, {""input"": ""Jerry"", ""expected_output"": 4}]","def count_distinct_characters(string: str) -> int
""""""Given a string, find out how many distinct characters (regardless of case) does it consist of
""""""","def problem_spec
-- function signature
(implementation: String β Nat)
-- inputs
(string: String) :=
-- spec
let spec (result: Nat) :=
let string_idx := {i: Nat | i < string.length}.toFinset
let characters := string_idx.image (fun i => string.toList.get! i)
let lowercase_characters := characters.image (fun c => c.toLower)
result = lowercase_characters.card;
-- program termination
β result, implementation string = result β§
spec result","def generated_spec
-- function signature
(implementation: String β Nat)
-- inputs
(string: String) : Prop :=","theorem spec_isomorphism:
β implementation,
(β string, problem_spec implementation string) β
(β string, generated_spec implementation string) :=",sorry,def implementation (string: String) : Nat :=,"let char_set := string.toLower.toList.toFinset
char_set.card","#test implementation ""xyzXYZ"" = 3
#test implementation ""Jerry"" = 4","theorem correctness
(string: String)
: problem_spec implementation string
:=","by
unfold problem_spec
let result := implementation string
use result
simp [result]
simp [implementation]
rcases string with β¨dataβ©
induction data
simp
have h1: """".toLower = """" := by
unfold String.toLower
unfold Char.toLower
unfold String.map
unfold String.mapAux
simp
intros
contradiction
simp [h1]
rename_i head tail ih
unfold String.toLower
rw [String.map_eq]
simp
sorry",,,
def parse_music(music_string: str) -> List[int],"Input to this function is a string representing musical notes in a special ASCII format.
Your task is to parse this string and return list of integers corresponding to how many beats does each
not last.
Here is a legend:
'o' - whole note, lasts four beats
'o|' - half note, lasts two beats
'.|' - quater note, lasts one beat
","[{""input"": ""o o| .| o| o| .| .| .| .| o o"", ""expected_output"": [4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4]}]","def parse_music(music_string: str) -> List[int]
""""""Input to this function is a string representing musical notes in a special ASCII format.
Your task is to parse this string and return list of integers corresponding to how many beats does each
not last.
Here is a legend:
'o' - whole note, lasts four beats
'o|' - half note, lasts two beats
'.|' - quater note, lasts one beat
""""""","def problem_spec
-- function signature
(implementation: String β List Nat)
-- inputs
(string: String) :=
-- spec
let not_map := fun
| ""o"" => 4
| ""o|"" => 2
| "".|"" => 1
| _ => 0;
let spec (result: List Nat) :=
let space_split := string.splitOn "" "";
space_split.length = result.length β§
β i < result.length, not_map (space_split.get! i) = result.get! i;
-- program termination
β result, implementation string = result β§
spec result","def generated_spec
-- function signature
(implementation: String β List Nat)
-- inputs
(string: String) : Prop :=","theorem spec_isomorphism:
β implementation,
(β string, problem_spec implementation string) β
(β string, generated_spec implementation string) :=",sorry,def implementation (string: String) : List Nat :=,"(string.splitOn "" "").map (fun
| ""o"" => 4
| ""o|"" => 2
| "".|"" => 1
| _ => 0)","#test implementation ""o o| .| o| o| .| .| .| .| o o"" = [4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4]","theorem correctness
(string: String)
: problem_spec implementation string
:=","by
unfold problem_spec
let result := implementation string
use result
simp [result]
simp [implementation]
intro i
by_cases h_i_lt_len: (i < (string.splitOn "" "").length)
simp [h_i_lt_len]
simp [h_i_lt_len]",,,
"def how_many_times(string: str, substring: str) -> int","Find how many times a given substring can be found in the original string. Count overlaping cases.
","[{""input"": ["""", ""a""], ""expected_output"": 0}, {""input"": [""aaa"", ""a""], ""expected_output"": 3}, {""input"": [""aaaa"", ""aa""], ""expected_output"": 3}]","def how_many_times(string: str, substring: str) -> int
""""""Find how many times a given substring can be found in the original string. Count overlaping cases.
""""""","def problem_spec
-- function signature
(implementation: String β String β Nat)
-- inputs
(string substring: String) :=
-- spec
let spec (result: Nat) :=
(string.length < substring.length β result = 0)
β§
(string.length = substring.length β
((string = substring β result = 1) β§
(substring β string β result = 0)))
β§
(substring.length < string.length β
let subtring_start_idx := {i: Nat | i β€ string.length - substring.length};
let substring_occurrences := {i β subtring_start_idx | (string.take (i + substring.length)).drop i = substring };
result = substring_occurrences.toFinset.card);
-- program termination
β result, implementation string substring = result β§
spec result","def generated_spec
-- function signature
(implementation: String β String β Nat)
-- inputs
(string substring: String) : Prop :=","theorem spec_isomorphism:
β implementation,
(β string substring, problem_spec implementation string substring) β
(β string substring, generated_spec implementation string substring) :=",sorry,def implementation (string: String) (substring: String) : Nat :=,(string.findAllSubstr substring).size,"#test implementation ""aaa"" ""a"" = 3
#test implementation ""aaaa"" ""aa"" = 3
#test implementation """" ""a"" = 0
#test implementation ""a"" """" = 1
#test implementation ""a"" ""a"" = 1","theorem correctness
(string: String)
(substring: String)
: problem_spec implementation string substring
:=","by
unfold problem_spec
let result := implementation string substring
use result
simp [result]
sorry",,,
def sort_numbers(numbers: str) -> str,"Input is a space-delimited string of numberals from 'zero' to 'nine'.
Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'.
Return the string with numbers sorted from smallest to largest
","[{""input"": ""three one five"", ""expected_output"": ""one three five""}]","def sort_numbers(numbers: str) -> str
""""""Input is a space-delimited string of numberals from 'zero' to 'nine'.
Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'.
Return the string with numbers sorted from smallest to largest
""""""","def problem_spec
-- function signature
(implementation: String β String)
-- inputs
(numbers: String) :=
-- spec
let word_to_number_map : String β Int := fun word =>
match word with
| ""zero"" => 0
| ""one"" => 1
| ""two"" => 2
| ""three"" => 3
| ""four"" => 4
| ""five"" => 5
| ""six"" => 6
| ""seven"" => 7
| ""eight"" => 8
| ""nine"" => 9
| _ => -1;
let is_sorted_asc : List Int β Bool := fun numbers =>
let rec is_sorted_asc_helper : List Int β Bool β Bool := fun numbers is_sorted =>
match numbers with
| [] => is_sorted
| [x] => is_sorted
| x::y::rest => if x <= y then is_sorted_asc_helper (y::rest) true else false;
is_sorted_asc_helper numbers false;
let spec (result: String) :=
let result_split := result.splitOn "" "";
let numbers_split := numbers.splitOn "" "";
let result_mapped_to_numbers := result_split.map word_to_number_map;
let numbers_as_str_mapped_to_numbers := numbers_split.map word_to_number_map;
Β¬ -1 β numbers_as_str_mapped_to_numbers β
result_split.length = numbers_split.length β§
(β n, n β numbers_as_str_mapped_to_numbers β
β m, m β result_mapped_to_numbers) β§
(β n, n β result_mapped_to_numbers β
β m, m β numbers_as_str_mapped_to_numbers) β§
(β n, numbers_as_str_mapped_to_numbers.count n = result_mapped_to_numbers.count n) β§
is_sorted_asc result_mapped_to_numbers = true;
-- program termination
β result, implementation numbers = result β§
spec result","def generated_spec
-- function signature
(implementation: String β String)
-- inputs
(numbers: String) : Prop :=","theorem spec_isomorphism:
β implementation,
(β numbers, problem_spec implementation numbers) β
(β numbers, generated_spec implementation numbers) :=",sorry,def implementation (numbers: String) : String :=,"let word_to_number_map : String β Int := fun word =>
match word with
| ""zero"" => 0
| ""one"" => 1
| ""two"" => 2
| ""three"" => 3
| ""four"" => 4
| ""five"" => 5
| ""six"" => 6
| ""seven"" => 7
| ""eight"" => 8
| ""nine"" => 9
| _ => -1;
let number_to_word_map : Int β String := fun number =>
match number with
| 0 => ""zero""
| 1 => ""one""
| 2 => ""two""
| 3 => ""three""
| 4 => ""four""
| 5 => ""five""
| 6 => ""six""
| 7 => ""seven""
| 8 => ""eight""
| 9 => ""nine""
| _ => ""invalid"";
let numbers_split := numbers.splitOn "" "";
let numbers_mapped_to_numbers := numbers_split.map word_to_number_map;
let sorted_numbers := numbers_mapped_to_numbers.mergeSort;
let sorted_numbers_mapped_to_words := sorted_numbers.map number_to_word_map;
let join: List String β String := fun words =>
let head := words.get! 0;
let tail := words.drop 1;
tail.foldl (fun acc word => acc ++ "" "" ++ word) head;
join sorted_numbers_mapped_to_words","#test implementation ""three one five"" = ""one three five""","theorem correctness
(numbers: String)
: problem_spec implementation numbers
:=","by
unfold problem_spec
let result := implementation numbers
use result
simp [result]
sorry",,,
"def find_closest_elements(numbers: List[float]) -> Tuple[float, float]","From a supplied list of numbers (of length at least two) select and return two that are the closest to each
other and return them in order (smaller number, larger number).
","[{""input"": [1.0, 2.0, 3.0, 4.0, 5.0, 2.2], ""expected_output"": ""(2.0, 2.2)""}, {""input"": [1.0, 2.0, 3.0, 4.0, 5.0, 2.0], ""expected_output"": ""(2.0, 2.0)""}]","def find_closest_elements(numbers: List[float]) -> Tuple[float, float]
""""""From a supplied list of numbers (of length at least two) select and return two that are the closest to each
other and return them in order (smaller number, larger number).
""""""","def problem_spec
-- function signature
(implementation: List Rat β (Rat Γ Rat))
-- inputs
(numbers: List Rat) :=
-- spec
let spec (result: (Rat Γ Rat)) :=
2 β€ numbers.length β
(let (smaller, larger) := result;
let abs_diff := |larger - smaller|;
smaller β€ larger β§
smaller β numbers β§
larger β numbers β§
(β x y, x β numbers β y β numbers β abs_diff β€ |x - y|) β§
(smaller = larger β 1 β€ (numbers.filter (fun z => z = smaller)).length));
-- program termination
β result, implementation numbers = result β§
spec result","def generated_spec
-- function signature
(implementation: List Rat β (Rat Γ Rat))
-- inputs
(numbers: List Rat) : Prop :=","theorem spec_isomorphism:
β implementation,
(β numbers, problem_spec implementation numbers) β
(β numbers, generated_spec implementation numbers) :=",sorry,def implementation (numbers: List Rat): (Rat Γ Rat) :=,"let n := numbers.length;
let sorted_numbers := numbers.mergeSort;
let min_diff := sorted_numbers.get! 1 - sorted_numbers.get! 0;
let min_pair := (sorted_numbers.get! 0, sorted_numbers.get! 1);
let rec loop (i: Nat) (min_diff: Rat) (min_pair: (Rat Γ Rat)): (Rat Γ Rat) :=
if i < n - 1 then
let diff := sorted_numbers.get! (i + 1) - sorted_numbers.get! i;
if diff < min_diff then
loop (i + 1) diff (sorted_numbers.get! i, sorted_numbers.get! (i + 1))
else
loop (i + 1) min_diff min_pair
else
min_pair;
loop 1 min_diff min_pair","#test implementation [1.0, 2.0, 3.0, 4.0, 5.0, 2.2] = (2.0, 2.2)
#test implementation [1.0, 2.0, 3.0, 4.0, 5.0, 2.0] = (2.0, 2.0)","theorem correctness
(numbers: List Rat)
: problem_spec implementation numbers
:=","by
unfold problem_spec
let result := implementation numbers
use result
simp [result]
sorry",,,
def rescale_to_unit(numbers: List[float]) -> List[float],"Given list of numbers (of at least two elements), apply a linear transform to that list,
such that the smallest number will become 0 and the largest will become 1
","[{""input"": [1.0, 2.0, 3.0, 4.0, 5.0], ""expected_output"": [0.0, 0.25, 0.5, 0.75, 1.0]}]","def rescale_to_unit(numbers: List[float]) -> List[float]
""""""Given list of numbers (of at least two elements), apply a linear transform to that list,
such that the smallest number will become 0 and the largest will become 1
""""""","def problem_spec
-- function signature
(implementation: List Rat β List Rat)
-- inputs
(numbers: List Rat) :=
-- spec
let spec (result: List Rat) :=
2 β€ numbers.length β
let min_elem := numbers.min?.get!;
let max_elem := numbers.max?.get!;
let range := max_elem - min_elem;
result.length = numbers.length β§
β i, i < numbers.length β
(min_elem β max_elem β
result[i]! = (numbers[i]! - min_elem) / range) β§
(min_elem = max_elem β
result[i]! = 0);
-- program termination
β result, implementation numbers = result β§
spec result","def generated_spec
-- function signature
(implementation: List Rat β List Rat)
-- inputs
(numbers: List Rat) : Prop :=","theorem spec_isomorphism:
β implementation,
(β numbers, problem_spec implementation numbers) β
(β numbers, generated_spec implementation numbers) :=",sorry,def implementation (numbers: List Rat): List Rat :=,sorry,"-- #test implementation [1.0, 2.0, 3.0, 4.0, 5.0] = [0.0, 0.25, 0.5, 0.75, 1.0]","theorem correctness
(numbers: List Rat)
: problem_spec implementation numbers
:=","by
unfold problem_spec
let result := implementation numbers
use result
simp [result]
sorry",,,
def strlen(string: str) -> int,"Return length of given string
","[{""input"": """", ""expected_output"": 0}, {""input"": ""abc"", ""expected_output"": 3}]","def strlen(string: str) -> int
""""""Return length of given string
""""""","def problem_spec
-- function signature
(implementation: String β Nat)
-- inputs
(string: String) :=
-- spec
let spec (result: Nat) :=
-- every character in the string is counted once
result = 0 β string.isEmpty β§
(0 < result β result - 1 = implementation (string.drop 1))
-- program termination
β result, implementation string = result β§
spec result","def generated_spec
-- function signature
(implementation: String β Nat)
-- inputs
(string: String) : Prop :=","theorem spec_isomorphism:
β implementation,
(β string, problem_spec implementation string) β
(β string, generated_spec implementation string) :=",sorry,def implementation (string: String): Nat :=,string.length,"#test implementation """" = 0
#test implementation ""abc"" = 3","theorem correctness
(string: String)
: problem_spec implementation string
:=","by
unfold problem_spec
let result := implementation string
use result
simp [result]
sorry",,,
def largest_divisor(n: int) -> int,"For a given number n, find the largest number that divides n evenly, smaller than n
","[{""input"": 15, ""expected_output"": 5}]","def largest_divisor(n: int) -> int
""""""For a given number n, find the largest number that divides n evenly, smaller than n
""""""","def problem_spec
-- function signature
(implementation: Nat β Nat)
-- inputs
(n: Nat) :=
-- spec
let spec (result: Nat) :=
0 < n β 0 < result β result β£ n β β x, x β£ n β x β n β x β€ result;
-- program termination
β result, implementation n = result β§
spec result","def generated_spec
-- function signature
(implementation: Nat β Nat)
-- inputs
(n: Nat) : Prop :=","theorem spec_isomorphism:
β implementation,
(β n, problem_spec implementation n) β
(β n, generated_spec implementation n) :=",sorry,def implementation (n: Nat) : Nat :=,"let possible_divisors := (List.range (n / 2 + 1)).drop 1
let reversed_possible_divisors := List.reverse possible_divisors;
Id.run do
for i in reversed_possible_divisors do
if n % i = 0 then
return i
return 1",#test implementation 15 = 5,"theorem correctness
(n: Nat)
: problem_spec implementation n
:=","by
unfold problem_spec
let result := implementation n
use result
simp [result]
sorry",,,
def factorize(n: int) -> List[int],"Return list of prime factors of given integer in the order from smallest to largest.
Each of the factors should be listed number of times corresponding to how many times it appeares in factorization.
Input number should be equal to the product of all factors
","[{""input"": 8, ""expected_output"": [2, 2, 2]}, {""input"": 25, ""expected_output"": [5, 5]}, {""input"": 70, ""expected_output"": [2, 5, 7]}]","def factorize(n: int) -> List[int]
""""""Return list of prime factors of given integer in the order from smallest to largest.
Each of the factors should be listed number of times corresponding to how many times it appeares in factorization.
Input number should be equal to the product of all factors
""""""","def problem_spec
-- function signature
(implementation: Nat β List Nat)
-- inputs
(n: Nat) :=
-- spec
let spec (result: List Nat) :=
2 β€ n β
(result.prod = n β§
List.Sorted Nat.le result β§
result.all (Ξ» i => n % i = 0 β§ Nat.Prime i));
-- program termination
β result, implementation n = result β§
spec result","def generated_spec
-- function signature
(implementation: Nat β List Nat)
-- inputs
(n: Nat) : Prop :=","theorem spec_isomorphism:
β implementation,
(β n, problem_spec implementation n) β
(β n, generated_spec implementation n) :=",sorry,def implementation (n: Nat) : List Nat :=,"Id.run do
let mut result := []
for num in List.range' 2 n.sqrt do
let mut n' := n
while n' % num = 0 do
n' := n' / num
result := result ++ [num]
result","#test implementation 8 = [2, 2, 2]
#test implementation 25 = [5, 5]
#test implementation 70 = [2, 5, 7]","theorem correctness
(n: Nat)
: problem_spec implementation n
:=","by
unfold problem_spec
let result := implementation n
use result
simp [result]
simp [implementation, Id.run]
unfold List.foldl
intro h_2_lt_n
sorry",,,
def remove_duplicates(numbers: List[int]) -> List[int],"From a list of integers, remove all elements that occur more than once.
Keep order of elements left the same as in the input.
","[{""input"": [1, 2, 3, 2, 4], ""expected_output"": [1, 3, 4]}]","def remove_duplicates(numbers: List[int]) -> List[int]
""""""From a list of integers, remove all elements that occur more than once.
Keep order of elements left the same as in the input.
""""""","def problem_spec
-- function signature
(implementation: List Int β List Int)
-- inputs
(numbers: List Int) :=
-- spec
let spec (result: List Int) :=
(β i: Int, i β result β numbers.count i = 1) β§
(β i: Int, i β numbers β numbers.count i = 1 β i β result) β§
(β i j : Nat, i < result.length β j < result.length β i < j β
β ip jp : Nat, ip < jp β§ result[i]! = numbers[ip]! β§ result[j]! = numbers[jp]!)
-- program termination
β result, implementation numbers = result β§
spec result","def generated_spec
-- function signature
(implementation: List Int β List Int)
-- inputs
(numbers: List Int) : Prop :=","theorem spec_isomorphism:
β implementation,
(β numbers, problem_spec implementation numbers) β
(β numbers, generated_spec implementation numbers) :=",sorry,def implementation (numbers: List Int) : List Int :=,"Id.run do
let mut result := []
for number in numbers do
if numbers.count number = 1 then
result := result ++ [number]
return result","#test implementation [1, 2, 3, 2, 4] = [1, 3, 4]","theorem correctness
(numbers: List Int)
: problem_spec implementation numbers
:=","by
unfold problem_spec
let result := implementation numbers
use result
simp [result]
sorry",,,
def flip_case(string: str) -> str,"For a given string, flip lowercase characters to uppercase and uppercase to lowercase.
","[{""input"": ""Hello"", ""expected_output"": ""hELLO""}]","def flip_case(string: str) -> str
""""""For a given string, flip lowercase characters to uppercase and uppercase to lowercase.
""""""","def problem_spec
-- function signature
(implementation: String β String)
-- inputs
(string: String) :=
-- spec
let spec (result: String) :=
let chars_in_result := result.toList;
let chars_in_string := string.toList;
chars_in_result.length = string.length β§
(β i, i < chars_in_result.length β
let c := chars_in_result.get! i;
let c' := chars_in_string.get! i;
(c.isUpper β c'.isLower) β§
(c.isLower β c'.isUpper) β§
((Β¬ c.isUpper β§ Β¬ c.isLower) β c = c')
);
-- program termination
β result, implementation string = result β§
spec result","def generated_spec
-- function signature
(implementation: String β String)
-- inputs
(string: String) : Prop :=","theorem spec_isomorphism:
β implementation,
(β string, problem_spec implementation string) β
(β string, generated_spec implementation string) :=",sorry,def implementation (string: String) : String :=,string.map (Ξ» c => if c.isUpper then c.toLower else c.toUpper),"#test implementation ""Hello"" = ""hELLO""","theorem correctness
(string: String)
: problem_spec implementation string
:=","by
unfold problem_spec
let result := implementation string
use result
simp [result]
sorry",,,
def concatenate(strings: List[str]) -> str,"Concatenate list of strings into a single string
","[{""input"": [], ""expected_output"": """"}, {""input"": [""a"", ""b"", ""c""], ""expected_output"": ""abc""}]","def concatenate(strings: List[str]) -> str
""""""Concatenate list of strings into a single string
""""""","def problem_spec
-- function signature
(implementation: List String β String)
-- inputs
(strings: List String) :=
-- spec
let spec (result: String) :=
let result_chars := result.toList;
result_chars.length = (strings.map (Ξ» s => s.length)).sum β§
β i, i < strings.length β
(let string_in_result := strings.get! i;
let end_idx := ((strings.take (i + 1)).map (Ξ» s => s.length)).sum;
let start_idx := end_idx - string_in_result.length;
let corresponding_string_in_result := ((result_chars.take end_idx).drop start_idx).asString;
corresponding_string_in_result = string_in_result);
-- program termination
β result, implementation strings = result β§
spec result","def generated_spec
-- function signature
(implementation: List String β String)
-- inputs
(strings: List String) : Prop :=","theorem spec_isomorphism:
β implementation,
(β strings, problem_spec implementation strings) β
(β strings, generated_spec implementation strings) :=",sorry,def implementation (strings: List String) : String :=,String.join strings,"#test implementation [] = """"
#test implementation [""a"", ""b"", ""c""] = ""abc""","theorem correctness
(strings: List String)
: problem_spec implementation strings
:=","by
unfold problem_spec
let result := implementation strings
use result
simp [result]
apply And.intro
simp [implementation]
repeat sorry",,,
"def filter_by_prefix(strings: List[str], prefix: str) -> List[str]","Filter an input list of strings only for ones that start with a given prefix.
","[{""input"": [[], ""a""], ""expected_output"": []}, {""input"": [[""abc"", ""bcd"", ""cde"", ""array""], ""a""], ""expected_output"": [""abc"", ""array""]}]","def filter_by_prefix(strings: List[str], prefix: str) -> List[str]
""""""Filter an input list of strings only for ones that start with a given prefix.
""""""","def problem_spec
-- function signature
(implementation: List String β String β List String)
-- inputs
(strings: List String)
(pref: String) :=
-- spec
let spec (result: List String) :=
result.all (Ξ» s => s.startsWith pref) β§
result.all (Ξ» s => s β strings) β§
strings.all (Ξ» s => s.startsWith pref β s β result) β§
β s : String, s β result β result.count s = strings.count s;
-- program termination
β result, implementation strings pref = result β§
spec result","def generated_spec
-- function signature
(implementation: List String β String β List String)
-- inputs
(strings: List String)
(pref: String) : Prop :=","theorem spec_isomorphism:
β implementation,
(β strings pref, problem_spec implementation strings pref) β
(β strings pref, generated_spec implementation strings pref) :=",sorry,def implementation (strings: List String) (pref: String) : List String :=,strings.filter (Ξ» s => s.startsWith pref),"#test implementation [] ""a"" = []
#test implementation [""abc"", ""bcd"", ""cde"", ""array""] ""a"" = [""abc"", ""array""]","theorem correctness
(strings: List String)
(pref: String)
: problem_spec implementation strings pref
:=","by
unfold problem_spec
let result := implementation strings pref
use result
simp [result]
repeat sorry",,,
def get_positive(l: list),"Return only positive numbers in the list.
","[{""input"": [-1, 2, -4, 5, 6], ""expected_output"": [2, 5, 6]}, {""input"": [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10], ""expected_output"": [5, 3, 2, 3, 9, 123, 1]}]","def get_positive(l: list)
""""""Return only positive numbers in the list.
""""""","def problem_spec
-- function signature
(implementation: List Int β List Int)
-- inputs
(numbers: List Int) :=
-- spec
let spec (result: List Int) :=
result.all (Ξ» x => x > 0 β§ x β numbers) β§
numbers.all (Ξ» x => x > 0 β x β result) β§
result.all (Ξ» x => result.count x = numbers.count x);
-- program termination
β result,
implementation numbers = result β§
spec result","def generated_spec
-- function signature
(implementation: List Int β List Int)
-- inputs
(numbers: List Int) : Prop :=","theorem spec_isomorphism:
β implementation,
(β numbers, problem_spec implementation numbers) β
(β numbers, generated_spec implementation numbers) :=",sorry,def implementation (numbers: List Int): List Int :=,numbers.filter (Ξ» x => x > 0),"#test implementation [(-1), 2, (-4), 5, 6] = [2, 5, 6]
#test implementation [5, 3, (-5), 2, (-3), 3, 9, 0, 123, 1, (-10)] = [5, 3, 2, 3, 9, 123, 1]","theorem correctness
(numbers: List Int)
: problem_spec implementation numbers
:=","by
unfold problem_spec
let result := implementation numbers
use result
simp [result]
repeat sorry",,,
def is_prime(n),"Return true if a given number is prime, and false otherwise.
","[{""input"": 6, ""output"": false}, {""input"": 101, ""output"": true}, {""input"": 11, ""output"": true}, {""input"": 13441, ""output"": true}, {""input"": 61, ""output"": true}, {""input"": 4, ""output"": false}, {""input"": 1, ""output"": false}]","def is_prime(n)
""""""Return true if a given number is prime, and false otherwise.
""""""","def problem_spec
-- function signature
(implementation: Nat β Bool)
-- inputs
(n: Nat) :=
-- spec
let spec (result: Bool) :=
result β Β¬ (β k, 2 β€ k β§ k < n β§ n % k = 0);
-- program termination
β result,
implementation n = result β§
spec result","def generated_spec
-- function signature
(implementation: Nat β Bool)
-- inputs
(n: Nat) : Prop :=","theorem spec_isomorphism:
β implementation,
(β n, problem_spec implementation n) β
(β n, generated_spec implementation n) :=",sorry,def implementation (n: Nat): Bool :=,Nat.Prime n,"#test implementation 6 = false
#test implementation 101 = true
#test implementation 11 = true
#test implementation 13441 = true
#test implementation 61 = true
#test implementation 4 = false
#test implementation 1 = false","theorem correctness
(n: Nat)
: problem_spec implementation n
:=","by
unfold problem_spec
let result := implementation n
use result
simp [result]
simp [implementation]
sorry",,,
def find_zero(xs: list),"xs are coefficients of a polynomial.
find_zero find x such that poly(x) = 0.
find_zero returns only only zero point, even if there are many.
Moreover, find_zero only takes list xs having even number of coefficients
and largest non zero coefficient as it guarantees a solution.
Note(George): This problem has been modified from the original HumanEval spec because of Real is not a computable type, but a zero does not necessarily exist over the rationals.
","[{""input"": [1, 2], ""output"": -0.5}, {""input"": [-6, 11, -6, 1], ""output"": 1.0}]","def find_zero(xs: list)
""""""xs are coefficients of a polynomial.
find_zero find x such that poly(x) = 0.
find_zero returns only only zero point, even if there are many.
Moreover, find_zero only takes list xs having even number of coefficients
and largest non zero coefficient as it guarantees a solution.
Note(George): This problem has been modified from the original HumanEval spec because of Real is not a computable type, but a zero does not necessarily exist over the rationals.
""""""","def problem_spec
-- function signature
(implementation: List Rat β Rat)
-- inputs
(xs: List Rat) :=
-- spec
let spec (result: Rat) :=
let eps := (1: Rat) / 1000000;
xs.length β₯ 1 β xs.length % 2 = 0 β
β poly : Polynomial Rat,
poly.degree = some (xs.length - 1) β
(β i, i β€ xs.length - 1 β poly.coeff i = xs.get! i) β
|poly.eval result| β€ eps;
-- program termination
β result,
implementation xs = result β§
spec result","def generated_spec
-- function signature
(implementation: List Rat β Rat)
-- inputs
(xs: List Rat) : Prop :=","theorem spec_isomorphism:
β implementation,
(β xs, problem_spec implementation xs) β
(β xs, generated_spec implementation xs) :=",sorry,def implementation (xs: List Rat) : Rat :=,"let rec poly (xs: List Rat) (x: Rat) := xs.reverse.foldl (Ξ» acc a => acc * x + a) 0;
let rec poly' (xs: List Rat) (x: Rat) := (xs.drop 1).reverse.foldl (Ξ» acc a => acc * x + a) 0;
let rec eps := (1: Rat) / 1000000;
let rec find_zero (xs: List Rat) (guess: Rat) (fuel: Nat) :=
let eval := poly xs guess;
let eval' := poly' xs guess;
if eval β€ eps β¨ fuel = 0 then (guess, fuel)
else
let guess' := (eval' * guess - eval) / eval';
find_zero xs guess' (fuel - 1);
(find_zero xs 1.0 1000000).1
-- Note: The above implementation can fail to converge in some cases. For example,
-- on the test case [-6, 11, -6, 1] as the derivative of the polynomial
-- can be zero at if the guess is 0. In such cases, the implementation will not
-- converge. The implementation can be improved by using a better guess.","#test implementation [1, 2] = -0.5
#test implementation [-6, 11, -6, 1] = 1.0","theorem correctness
(xs: List Rat)
: problem_spec implementation xs
:=","by
unfold problem_spec
let result := implementation xs
use result
simp [result]
intros h1 h2 poly h3 h4
repeat sorry",,,
def sort_third(l: list),"This function takes a list l and returns a list l' such that
l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal
to the values of the corresponding indicies of l, but sorted.
","[{""input"": [1, 2, 3], ""output"": [1, 2, 3]}, {""input"": [5, 6, 3, 4, 8, 9, 2], ""output"": [2, 6, 3, 4, 8, 9, 5]}]","def sort_third(l: list)
""""""This function takes a list l and returns a list l' such that
l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal
to the values of the corresponding indicies of l, but sorted.
""""""","def problem_spec
-- function signature
(implementation: List Int β List Int)
-- inputs
(l: List Int) :=
-- spec
let spec (result: List Int) :=
l.length = result.length β§
let every_third_idx := (List.range l.length).filter (Ξ» i => i % 3 = 0);
let every_third_val_in_result := every_third_idx.map (Ξ» i => result.get! i);
let every_third_val := every_third_idx.map (Ξ» i => l.get! i);
(β i, i < l.length β (i % 3 β 0 β l.get! i = result.get! i)) β§
List.Sorted Int.le every_third_val_in_result β§
every_third_val.all (Ξ» x => every_third_val_in_result.count x = every_third_val.count x);
-- program termination
β result, implementation l = result β§
spec result","def generated_spec
-- function signature
(implementation: List Int β List Int)
-- inputs
(l: List Int) : Prop :=","theorem spec_isomorphism:
β implementation,
(β l, problem_spec implementation l) β
(β l, generated_spec implementation l) :=",sorry,def implementation (l: List Int) : List Int :=,"let every_third_idx := (List.range l.length).filter (Ξ» i => i % 3 = 0);
let every_third_val := every_third_idx.map (Ξ» i => l.get! i);
let every_third_val_sorted := List.mergeSort every_third_val;
let result := l.mapIdx (Ξ» i v =>
if i % 3 = 0 then every_third_val_sorted.get! (i / 3)
else v);
result","#test implementation [1, 2, 3] = [1, 2, 3]
#test implementation [5, 6, 3, 4, 8, 9, 2] = [2, 6, 3, 4, 8, 9, 5]","theorem correctness
(l: List Int)
: problem_spec implementation l
:=","by
unfold problem_spec
let result := implementation l
use result
simp [result]
repeat sorry",,,
def unique(l: list),"Return sorted unique elements in a list.
","[{""input"": [5, 3, 5, 2, 3, 3, 9, 0, 123], ""output"": [0, 2, 3, 5, 9, 123]}]","def unique(l: list)
""""""Return sorted unique elements in a list.
""""""","def problem_spec
-- function signature
(implementation: List Int β List Int)
-- inputs
(l: List Int) :=
-- spec
let spec (result: List Int) :=
(β x, x β result β x β l β§ result.count x = 1) β§
List.Sorted Int.le result
-- program termination
β result,
implementation l = result β§
spec result","def generated_spec
-- function signature
(implementation: List Int β List Int)
-- inputs
(l: List Int) : Prop :=","theorem spec_isomorphism:
β implementation,
(β l, problem_spec implementation l) β
(β l, generated_spec implementation l) :=",sorry,def implementation (l: List Int) : List Int :=,l.eraseDup.mergeSort,"#test implementation [5, 3, 5, 2, 3, 3, 9, 0, 123] = [0, 2, 3, 5, 9, 123]","theorem correctness
(l: List Int)
: problem_spec implementation l
:=","by
unfold problem_spec
let result := implementation l
use result
simp [result]
simp [implementation]
apply And.intro
intro x
apply Iff.intro
intro h
apply And.intro
repeat sorry",,,
def max_element(l: list),"Return maximum element in the list.
","[{""input"": [1, 2, 3], ""output"": 3}, {""input"": [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10], ""output"": 123}]","def max_element(l: list)
""""""Return maximum element in the list.
""""""","def problem_spec
-- function signature
(implementation: List Int β Int)
-- inputs
(l: List Int) :=
-- spec
let spec (result: Int) :=
l.length > 0 β
((β i, i < l.length β l.get! i β€ result) β§
(β i, i < l.length β§ l.get! i = result));
-- program termination
β result, implementation l = result β§
spec result","def generated_spec
-- function signature
(implementation: List Int β Int)
-- inputs
(l: List Int) : Prop :=","theorem spec_isomorphism:
β implementation,
(β l, problem_spec implementation l) β
(β l, generated_spec implementation l) :=",sorry,def implementation (l: List Int) : Int :=,"match List.maximum l with
| none => panic! ""empty list""
| some x => x","#test implementation [1, 2, 3] = 3
#test implementation [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10] = 123","theorem correctness
(l: List Int)
: problem_spec implementation l
:=","by
unfold problem_spec
let result := implementation l
use result
simp [result]
simp [implementation]
by_cases h_l_not_nil: l β []
have h_max_not_none := List.maximum_ne_bot_of_ne_nil h_l_not_nil
intro h_len_gt_zero
apply And.intro
have h_l_max : β r, l.maximum = some r := by
have h_l_max' : l.maximum β none := h_max_not_none
rw [Option.ne_none_iff_exists] at h_l_max'
obtain β¨r, h_l_maxβ© := h_l_max'
use r
simp [h_l_max]
obtain β¨r, h_l_max β© := h_l_max
simp [h_l_max]
induction l
intro i h_i_lt_len
simp
simp at h_len_gt_zero
rename_i head tail ih
rw [List.maximum_cons] at h_l_max
by_cases h_tail_nil: tail = []
simp [h_tail_nil] at *
have h_head_eq_r : head = r := by
simp [WithBot.some] at h_l_max
rw [Option.some_inj] at h_l_max
exact h_l_max
rw [h_head_eq_r]
simp [h_tail_nil] at ih
have h_0_lt_len: 0 < tail.length :=
List.length_pos_of_ne_nil h_tail_nil
simp [h_0_lt_len] at ih
repeat sorry",,,
def fizz_buzz(n: int),"Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.
","[{""input"": 50, ""output"": 0}, {""input"": 78, ""output"": 2}, {""input"": 79, ""output"": 3}]","def fizz_buzz(n: int)
""""""Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.
""""""","def problem_spec
-- function signature
(implementation: Nat β Nat)
-- inputs
(n: Nat) :=
-- spec
let spec (result: Nat) :=
(n = 0 β result = 0) β§
(0 < n β result = implementation (n - 1) β
(n % 11 β 0 β§ n % 13 β 0) β¨ n.repr.count '7' = 0) β§
(0 < n β result β implementation (n - 1) β
(n % 11 = 0 β¨ n % 13 = 0) β§
result - implementation (n - 1) = n.repr.count '7')
-- program termination
β result, implementation n = result β§
spec result","def generated_spec
-- function signature
(implementation: Nat β Nat)
-- inputs
(n: Nat) : Prop :=","theorem spec_isomorphism:
β implementation,
(β n, problem_spec implementation n) β
(β n, generated_spec implementation n) :=",sorry,def implementation (n: Nat) : Nat :=,"let all_numbers_lt_n := {x | x < n};
let multiples_of_11_or_13 := all_numbers_lt_n β© {x | x % 11 = 0 β¨ x % 13 = 0};
let possible_multiple_with_7 := multiples_of_11_or_13 β© {x | x.repr.contains '7'};
possible_multiple_with_7.toFinset.sum (Ξ» x => x.repr.count '7')","#test implementation 50 = 0
#test implementation 78 = 2
#test implementation 79 = 3","theorem correctness
(n: Nat)
: problem_spec implementation n
:=","by
unfold problem_spec
let result := implementation n
use result
simp [result]
simp [implementation]
sorry",,,
def sort_even(l: list),"This function takes a list l and returns a list l' such that
l' is identical to l in the odd indicies, while its values at the even indicies are equal
to the values of the even indicies of l, but sorted.
","[{""input"": [1, 2, 3], ""output"": [1, 2, 3]}, {""input"": [5, 6, 3, 4], ""output"": [3, 6, 5, 4]}]","def sort_even(l: list)
""""""This function takes a list l and returns a list l' such that
l' is identical to l in the odd indicies, while its values at the even indicies are equal
to the values of the even indicies of l, but sorted.
""""""","def problem_spec
-- function signature
(implementation: List Int β List Int)
-- inputs
(l: List Int) :=
-- spec
let spec (result: List Int) :=
l.length = result.length β§
let even_idx := (List.range l.length).filter (Ξ» i => i % 2 = 0);
let even_val_in_result := even_idx.map (Ξ» i => result.get! i);
let even_val := even_idx.map (Ξ» i => l.get! i);
(β i, i < l.length β (i % 2 β 0 β l.get! i = result.get! i)) β§
List.Sorted Int.le even_val_in_result β§
even_val.all (Ξ» x => even_val_in_result.count x = even_val.count x);
-- program termination
β result, implementation l = result β§
spec result","def generated_spec
-- function signature
(implementation: List Int β List Int)
-- inputs
(l: List Int) : Prop :=","theorem spec_isomorphism:
β implementation,
(β l, problem_spec implementation l) β
(β l, generated_spec implementation l) :=",sorry,def implementation (l: List Int) : List Int :=,"let even_idx := (List.range l.length).filter (Ξ» i => i % 2 = 0);
let even_val := even_idx.map (Ξ» i => l.get! i);
let even_val_sorted := List.mergeSort even_val;
let result := l.mapIdx (Ξ» i v =>
if i % 2 = 0 then even_val_sorted.get! (i / 2)
else v);
result","#test implementation [1, 2, 3] = [1, 2, 3]
#test implementation [5, 6, 3, 4] = [3, 6, 5, 4]","theorem correctness
(l: List Int)
: problem_spec implementation l
:=","by
unfold problem_spec
let result := implementation l
use result
simp [result]
sorry",,,
def encode_cyclic(s: str) -> str,"Returns an encoded string by cycling each group of three consecutive characters.
Specifically, each group of exactly three characters 'abc' is transformed to 'bca'.
Groups of fewer than three characters at the end of the string remain unchanged.
","[{""input"": ""abcdef"", ""expected_output"": ""bcaefd""}, {""input"": ""abcde"", ""expected_output"": ""bcade""}, {""input"": ""ab"", ""expected_output"": ""ab""}]","def encode_cyclic(s: str) -> str
""""""Returns an encoded string by cycling each group of three consecutive characters.
Specifically, each group of exactly three characters 'abc' is transformed to 'bca'.
Groups of fewer than three characters at the end of the string remain unchanged.
""""""","def problem_spec
(impl: String β String)
(s: String) :=
let n := s.length;
let extract (chars: List Char) (start_index: β) (end_index: β) :=
(chars.drop start_index).take (end_index - start_index + 1);
let spec (result: String) :=
let encoded_chars := result.toList;
let original_chars := s.toList;
encoded_chars.length = n β§
(β i : β, i * 3 + 3 β€ n β
extract encoded_chars (i * 3) (i * 3 + 2) =
[original_chars.get! (i * 3 + 1), original_chars.get! (i * 3 + 2), original_chars.get! (i * 3)]) β§
(n % 3 β 0 β extract encoded_chars (n - n % 3) (n - 1) =
extract original_chars (n - n % 3) (n - 1));
-- program termination
β result,
impl s = result β§
spec result","def generated_spec
-- function signature
(impl: String β String)
-- inputs
(s: String) : Prop :=","theorem spec_isomorphism:
β impl,
(β s, problem_spec impl s) β
(β s, generated_spec impl s) :=",sorry,def implementation (s: String) : String :=,sorry,"-- #test implementation ""abcdef"" = ""bcaefd""
-- #test implementation ""abcde"" = ""bcade""
-- #test implementation ""ab"" = ""ab""","theorem correctness
(s: String)
: problem_spec implementation s :=","by
unfold problem_spec
let result := implementation s
use result
simp [result]
sorry",,,
def prime_fib(n: int),"prime_fib returns n-th prime Fibonacci number.
Note(George): A proof of this problem requires the resolution of the open conjecture: there are infinitely many prime Fibonacci numbers.
","[{""input"": 1, ""output"": 2}, {""input"": 2, ""output"": 3}, {""input"": 3, ""output"": 5}, {""input"": 4, ""output"": 13}, {""input"": 5, ""output"": 89}]","def prime_fib(n: int)
""""""prime_fib returns n-th prime Fibonacci number.
Note(George): A proof of this problem requires the resolution of the open conjecture: there are infinitely many prime Fibonacci numbers.
""""""","def problem_spec
-- function signature
(implementation: Nat β Nat)
-- inputs
(n: Nat) :=
-- spec
let spec (result: Nat) :=
n > 0 β
(β i, Nat.fib i = result β§ Nat.Prime result β§
(β! S : Finset Nat, S.card = n - 1 β§
(β y β S, (β k, y = Nat.fib k) β§ y < result β§ Nat.Prime y))
)
-- program termination
β result, implementation n = result β§
spec result","def generated_spec
-- function signature
(implementation: Nat β Nat)
-- inputs
(n: Nat) : Prop :=","theorem spec_isomorphism:
β implementation,
(β n, problem_spec implementation n) β
(β n, generated_spec implementation n) :=",sorry,def implementation (n: Nat) : Nat :=,"let rec fib_prime (n: Nat) (i: Nat) : Nat :=
if Nat.Prime (Nat.fib i) then
if n = 1 β¨ n = 0
then Nat.fib i
else fib_prime (n - 1) (i + 1)
else fib_prime n (i + 1)
termination_by n
decreasing_by
-- Really hard to prove termination here
sorry
sorry
fib_prime n 0","-- NOTE we changed to #eval! instead of #test
-- because we can't use #test for implementation
-- without a proof of termination
#eval! implementation 1 = 2
#eval! implementation 2 = 3
#eval! implementation 3 = 5
#eval! implementation 4 = 13
#eval! implementation 5 = 89","theorem correctness
(n: Nat)
: problem_spec implementation n
:=","by
unfold problem_spec
let result := implementation n
use result
simp [result]
repeat sorry",,,
def triples_sum_to_zero(numbers: List[int]) -> Bool,"triples_sum_to_zero takes a list of integers as an input.
it returns True if there are three distinct elements in the list that
sum to zero, and False otherwise.
","[{""input"": [1, 3, 5, 0], ""expected_output"": false}, {""input"": [1, 3, -2, 1], ""expected_output"": true}]","def triples_sum_to_zero(numbers: List[int]) -> Bool
""""""triples_sum_to_zero takes a list of integers as an input.
it returns True if there are three distinct elements in the list that
sum to zero, and False otherwise.
""""""","def problem_spec
-- function signature
(implementation: List Int β Bool)
-- inputs
(numbers: List Int) :=
let sum_i_j_k (i j k: Nat) : Bool :=
numbers[i]! + numbers[j]! + numbers[k]! = 0;
let exists_zero := 3 β€ numbers.length β§ (β i j k, i β j β§ i β k β§ j β k β§
i < numbers.length β§ j < numbers.length β§ k < numbers.length β§
sum_i_j_k i j k)
-- spec
let spec (result: Bool) :=
result β exists_zero
-- -- program termination
β result, implementation numbers = result β§
spec result
--","def generated_spec
-- function signature
(impl: List Int β Bool)
-- inputs
(x: List Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β x, problem_spec impl x) β
(β x, generated_spec impl x) :=",sorry,def implementation (numbers: List Int) : Bool :=,sorry,"-- #test implementation [1, 3, 5, 0] = false
-- #test implementation [1, 3, -2, 1] = true
-- #test implementation [1, 2, 3, 7] = false
-- #test implementation [2, 4, -5, 3, 9, 7] = true
-- #test implementation [1] = false","theorem correctness
(numbers : List Int)
: problem_spec implementation numbers
:=","by
unfold problem_spec
let result := implementation numbers
use result
simp [result]
sorry",,,
def car_race_collision(x: Nat) -> Nat,"Imagine a road that's a perfectly straight infinitely long line.
n cars are driving left to right; simultaneously, a different set of n cars
are driving right to left. The two sets of cars start out being very far from
each other. All cars move in the same speed. Two cars are said to collide
when a car that's moving left to right hits a car that's moving right to left.
However, the cars are infinitely sturdy and strong; as a result, they continue moving
in their trajectory as if they did not collide.
This function outputs the number of such collisions.
","[{""input"": 0, ""expected_output"": 0}, {""input"": 5, ""expected_output"": 25}]","def car_race_collision(x: Nat) -> Nat
""""""Imagine a road that's a perfectly straight infinitely long line.
n cars are driving left to right; simultaneously, a different set of n cars
are driving right to left. The two sets of cars start out being very far from
each other. All cars move in the same speed. Two cars are said to collide
when a car that's moving left to right hits a car that's moving right to left.
However, the cars are infinitely sturdy and strong; as a result, they continue moving
in their trajectory as if they did not collide.
This function outputs the number of such collisions.
""""""","def problem_spec
-- function signature
(implementation: Nat β Nat)
-- inputs
(x : Nat) :=
-- spec
let spec (result: Nat) :=
β x_list : List Nat, x_list.length = x β§ x_list.all (fun i => i = x)
β§ x_list.sum = result
-- -- program termination
β result, implementation x = result β§
spec result
--","def generated_spec
-- function signature
(impl: Nat β Nat)
-- inputs
(x: Nat) : Prop :=","theorem spec_isomorphism:
β impl,
(β x, problem_spec impl x) β
(β x, generated_spec impl x) :=",sorry,def implementation (x : Nat) : Nat :=,sorry,"-- #test implementation 0 = 0
-- #test implementation 5 = 25","theorem correctness
(x : Nat)
: problem_spec implementation x
:=","by
unfold problem_spec
let result := implementation x
use result
simp [result]
sorry",,,
def incr_list(numbers: List[Int]) -> List[Int],"incr_list takes a list of integers as input and returns a new list
where each element is incremented by 1.
","[{""input"": [], ""expected_output"": []}, {""input"": [1, 3, -2, 1], ""expected_output"": [2, 4, -1, 2]}]","def incr_list(numbers: List[Int]) -> List[Int]
""""""incr_list takes a list of integers as input and returns a new list
where each element is incremented by 1.
""""""","def problem_spec
-- function signature
(implementation: List Int β List Int)
-- inputs
(numbers: List Int) :=
-- spec
let spec (result: List Int) :=
(result.length = numbers.length) β§
β i, i < numbers.length β
result[i]! = numbers[i]! + 1
-- -- program termination
β result, implementation numbers = result β§
spec result
--","def generated_spec
-- function signature
(impl: List Int β List Int)
-- inputs
(x: List Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β x, problem_spec impl x) β
(β x, generated_spec impl x) :=",sorry,def implementation (numbers: List Int) : List Int :=,sorry,"-- #test implementation [1, 2, 3] = [2, 3, 4]
-- #test implementation [5, 3, 5, 2, 3, 3, 9, 0, 123] = [6, 4, 6, 3, 4, 4, 10, 1, 124]","theorem correctness
(numbers : List Int)
: problem_spec implementation numbers
:=","by
unfold problem_spec
let result := implementation numbers
use result
simp [result]
sorry",,,
def pairs_sum_to_zero(numbers: List[int]) -> Bool,"pairs_sum_to_zero takes a list of integers as an input.
it returns True if there are two distinct elements in the list that
sum to zero, and False otherwise.
","[{""input"": [1, 3, 5, 0], ""expected_output"": false}, {""input"": [1, 3, -2, 1], ""expected_output"": false}, {""input"": [1], ""expected_output"": false}, {""input"": [2, 4, -5, 3, 5, 7], ""expected_output"": true}]","def pairs_sum_to_zero(numbers: List[int]) -> Bool
""""""pairs_sum_to_zero takes a list of integers as an input.
it returns True if there are two distinct elements in the list that
sum to zero, and False otherwise.
""""""","def problem_spec
-- function signature
(implementation: List Int β Bool)
-- inputs
(numbers: List Int) :=
let sum_i_j (i j: Nat) : Bool :=
numbers[i]! + numbers[j]! = 0;
let exists_zero := 2 β€ numbers.length β§ (β i j, i β j β§
i < numbers.length β§ j < numbers.length β§
sum_i_j i j)
-- spec
let spec (result: Bool) :=
result β exists_zero
-- -- program termination
β result, implementation numbers = result β§
spec result
--","def generated_spec
-- function signature
(impl: List Int β Bool)
-- inputs
(x: List Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β x, problem_spec impl x) β
(β x, generated_spec impl x) :=",sorry,def implementation (numbers: List Int) : Bool :=,sorry,"-- #test implementation [1, 3, 5, 0] = false
-- #test implementation [1, 3, -2, 1] = false
-- #test implementation [1, 2, 3, 7] = false
-- #test implementation [2, 4, -5, 3, 5, 7] = true
-- #test implementation [1] = false","theorem correctness
(numbers : List Int)
: problem_spec implementation numbers
:=","by
unfold problem_spec
let result := implementation numbers
use result
simp [result]
sorry",,,
"def change_base(x: Nat, base: Nat) -> String","Change numerical base of input number x to base.
return string representation after the conversion.
base numbers are less than 10.
","[{""input"": ""(8, 3)"", ""expected_output"": ""22""}, {""input"": ""(8, 2)"", ""expected_output"": ""1000""}, {""input"": ""(7, 2)"", ""expected_output"": ""111""}]","def change_base(x: Nat, base: Nat) -> String
""""""Change numerical base of input number x to base.
return string representation after the conversion.
base numbers are less than 10.
""""""","def problem_spec
-- function signature
(implementation: Nat β Nat -> String)
-- inputs
(x base: Nat) :=
-- spec
let spec (result: String) :=
let result_array := result.toList.map (fun c => c.toNat - '0'.toNat);
let pow_array := (List.range result_array.length).map (fun i => base^(result_array.length - i - 1) * result_array[i]!);
let pow_sum := pow_array.sum;
(0 < base β§ base β€ 10) β§
(β i, i < result_array.length β
result_array[i]! < base β§ 0 β€ result_array[i]! β
pow_sum = x);
-- program termination
β result, implementation x base = result β§
spec result","def generated_spec
-- function signature
(impl: Nat β Nat β String)
-- inputs
(x base: Nat) : Prop :=","theorem spec_isomorphism:
β impl,
(β x y, problem_spec impl x y) β
(β x y, generated_spec impl x y) :=",sorry,def implementation (x base: Nat) : String :=,sorry,"-- #test implementation 8 3 = '22'
-- #test implementation 8 2 = '1000'
-- #test implementation 7 2 = '111'","theorem correctness
(x base : Nat)
: problem_spec implementation x base
:=","by
unfold problem_spec
let result := implementation x base
use result
simp [result]
sorry",,,
"def triangle_area(a: float, h: float) -> float","Given length of a side and high return area for a triangle.
","[{""input"": ""(5, 3)"", ""expected_output"": 7.5}, {""input"": ""(8, 2)"", ""expected_output"": 8.0}]","def triangle_area(a: float, h: float) -> float
""""""Given length of a side and high return area for a triangle.
""""""","def problem_spec
-- function signature
(implementation: Rat β Rat -> Rat)
-- inputs
(a h: Rat) :=
-- spec
let spec (result: Rat) :=
a = 0 β result = 0 β§
(a β 0 β (2 * result) / a = h);
-- -- program termination
β result, implementation a h = result β§
spec result
--","def generated_spec
-- function signature
(impl: Rat β Rat β Rat)
-- inputs
(a h: Rat) : Prop :=","theorem spec_isomorphism:
β impl,
(β x y, problem_spec impl x y) β
(β x y, generated_spec impl x y) :=",sorry,def implementation (a h: Rat) : Rat :=,0.5 * a * h,"-- #test implementation 5 3 = 7.5
-- #test implementation 8 2 = 8.0","theorem correctness
(a h : Rat)
: problem_spec implementation a h
:=","by
unfold problem_spec
let result := implementation a h
use result
simp [result]
sorry",,,
def fib4(n: int),"The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
fib4(0) -> 0
fib4(1) -> 0
fib4(2) -> 2
fib4(3) -> 0
fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4).
Please write a function to efficiently compute the n-th element of the fib4 number sequence. Do not use recursion.
","[{""input"": 5, ""output"": 4}, {""input"": 6, ""output"": 8}, {""input"": 7, ""output"": 14}]","def fib4(n: int)
""""""The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
fib4(0) -> 0
fib4(1) -> 0
fib4(2) -> 2
fib4(3) -> 0
fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4).
Please write a function to efficiently compute the n-th element of the fib4 number sequence. Do not use recursion.
""""""","def problem_spec
-- function signature
(impl: Nat β Nat)
-- inputs
(n: Nat) :=
-- spec
let spec (result: Nat) :=
fibonacci_non_computable_4 n result
-- program terminates
β result, impl n = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: Nat β Nat)
-- inputs
(x: Nat) : Prop :=","theorem spec_isomorphism:
β impl,
(β x, problem_spec impl x) β
(β x, generated_spec impl x) :=",sorry,def implementation (n: Nat) : Nat :=,sorry,"-- #test implementation 5 = 4
-- #test implementation 6 = 8
-- #test implementation 7 = 14","theorem correctness
(n: Nat)
: problem_spec implementation n
:=","by
unfold problem_spec
let result := implementation n
use result
simp [result]
repeat sorry","/--
name: fibonacci_non_computable_4
use: |
Non-computable definition to check if a number is a Fibonacci number such that
fib(n) = fib(n - 1) + fib(n - 2) + fib(n - 3) + fib(n - 4).
problems:
- 46
-/
inductive fibonacci_non_computable_4 : β β β β Prop
| base0 : fibonacci_non_computable_4 0 0
| base1 : fibonacci_non_computable_4 1 0
| base2 : fibonacci_non_computable_4 2 2
| base3 : fibonacci_non_computable_4 3 0
| step : β n fβ fβ fβ fβ, fibonacci_non_computable_4 n fβ β
fibonacci_non_computable_4 (n + 1) fβ β
fibonacci_non_computable_4 (n + 2) fβ β
fibonacci_non_computable_4 (n + 3) fβ β
fibonacci_non_computable_4 (n + 4) (fβ + fβ + fβ + fβ)",,
def median(numbers: List[float]) -> float,"Return median of elements in the list l
","[{""input"": [3, 1, 2, 4, 5], ""output"": 3}, {""input"": [-10, 4, 6, 1000, 10, 20], ""output"": 15.0}]","def median(numbers: List[float]) -> float
""""""Return median of elements in the list l
""""""","def problem_spec
-- function signature
(implementation: List Rat β Rat)
-- inputs
(numbers: List Rat) :=
-- spec
let spec (result: Rat) :=
0 < numbers.length β
let less_eq := (numbers.filter (fun x => x β€ result));
let more_eq := (numbers.filter (fun x => result β€ x));
let max_more_eq := more_eq.max?;
let min_less_eq := less_eq.min?;
let less_eq_count := less_eq.length;
let more_eq_count := more_eq.length;
let eq_count := (numbers.filter (fun x => x = result)).length;
(less_eq_count + more_eq_count - eq_count = numbers.length β
numbers.length β€ 2 * less_eq_count β
numbers.length β€ 2 * more_eq_count) β§
((numbers.length % 2 = 1 β
result β numbers) β§
(numbers.length % 2 = 0 β max_more_eq.isSome β§
min_less_eq.isSome β§
2 * result = max_more_eq.get! + min_less_eq.get!));
-- program termination
β result, implementation numbers = result β§
spec result","def generated_spec
-- function signature
(impl: List Rat β Rat)
-- inputs
(x: List Rat) : Prop :=","theorem spec_isomorphism:
β impl,
(β x, problem_spec impl x) β
(β x, generated_spec impl x) :=",sorry,def implementation (numbers: List Rat) : Rat :=,sorry,"-- #test implementation [3, 1, 2, 4, 5] = 3
-- #test implementation [-10, 4, 6, 1000, 10, 20] = 15.0","theorem correctness
(numbers: List Rat)
: problem_spec implementation numbers
:=","by
unfold problem_spec
let result := implementation numbers
use result
simp [result]
repeat sorry",,,
def is_palindrome(string: str) -> Bool,"Checks if given string is a palindrome
","[{""input"": """", ""expected_output"": true}, {""input"": ""aba"", ""expected_output"": true}, {""input"": ""aaaaa"", ""expected_output"": ""True""}, {""input"": ""zbcd"", ""expected_output"": ""False""}]","def is_palindrome(string: str) -> Bool
""""""Checks if given string is a palindrome
""""""","def problem_spec
-- function signature
(implementation: String β Bool)
-- inputs
(string: String) :=
-- spec
let spec (result: Bool) :=
result β is_palindrome string
-- program termination
β result, implementation string = result β§
spec result","def generated_spec
-- function signature
(impl: String β Bool)
-- inputs
(x: String) : Prop :=","theorem spec_isomorphism:
β impl,
(β x, problem_spec impl x) β
(β x, generated_spec impl x) :=",sorry,def implementation (string: String) : Bool :=,sorry,"-- #test implementation """" = true
-- #test implementation ""aba"" = true
-- #test implementation ""aaaaa"" = true
-- #test implementation ""zbcd"" = false","theorem correctness
(s: String)
: problem_spec implementation s
:=","by
unfold problem_spec
let result := implementation s
use result
simp [result]
sorry","/--
name: is_palindrome
use: |
Helper to check if a string is a palindrome.
problems:
- 10
- 48
-/
def is_palindrome
(s: String): Bool :=
s = s.toList.reverse.asString",,
"def modp(n: Nat, p: Nat) -> Nat","Return 2^n modulo p (be aware of numerics).
","[{""input"": [3, 5], ""expected_output"": 3}, {""input"": [1101, 101], ""expected_output"": 2}, {""input"": [0, 101], ""expected_output"": 0}, {""input"": [100, 101], ""expected_output"": 1}]","def modp(n: Nat, p: Nat) -> Nat
""""""Return 2^n modulo p (be aware of numerics).
""""""","def problem_spec
-- function signature
(implementation: Nat β Nat β Nat)
-- inputs
(n p: Nat) :=
-- spec
let spec (result: Nat) :=
0 < p β§
result < p β§
(β k : Nat, p * k + result = Nat.pow 2 n)
-- program termination
β result, implementation n p = result β§
spec result","def generated_spec
-- function signature
(impl: Nat β Nat β Nat)
-- inputs
(n p: Nat) : Prop :=","theorem spec_isomorphism:
β impl,
(β x y, problem_spec impl x y) β
(β x y, generated_spec impl x y) :=",sorry,def implementation (n p: Nat) : Nat :=,sorry,"-- #test implementation 3 5 = 3
-- #test implementation 1101 101 = 2
-- #test implementation 0 101 = 1
-- #test implementation 3 11 = 8
-- #test implementation 100 101 = 1","theorem correctness
(n p: Nat)
: problem_spec implementation n p
:=","by
unfold problem_spec
let result := implementation n p
use result
simp [result]
sorry",,,
def encode_shift(s: String) -> String,"returns encoded string by shifting every character by 5 in the alphabet.
","[{""input"": ""abc"", ""expected_output"": ""fgh""}, {""input"": ""xyz"", ""expected_output"": ""cde""}, {""input"": ""aaa"", ""expected_output"": ""fff""}]","def encode_shift(s: String) -> String
""""""returns encoded string by shifting every character by 5 in the alphabet.
""""""","def problem_spec
-- function signature
(implementation: String β String)
-- inputs
(s : String) :=
let isAlphabetic (string: String) : Bool :=
β i, i < string.length β
let c := string.get! β¨iβ©;
('a'.toNat β€ c.toNat β§ c.toNat β€ 'z'.toNat) β¨
('A'.toNat β€ c.toNat β§ c.toNat β€ 'Z'.toNat)
-- spec
let spec (result: String) :=
isAlphabetic result β§ isAlphabetic s β§
result.length = s.length β§
β k : Nat, k < 26 β§
β i : Nat, i < s.length β
((s.get! β¨iβ©).toNat + k) % 26 = (result.get! β¨iβ©).toNat
β k = 5
-- program termination
β result, implementation s = result β§
spec result","def generated_spec
-- function signature
(impl: String β String)
-- inputs
(s: String) : Prop :=","theorem spec_isomorphism:
β impl,
(β x, problem_spec impl x) β
(β x, generated_spec impl x) :=",sorry,def implementation (s: String) : String :=,sorry,"-- #test implementation ""abc"" = ""fgh""
-- #test implementation ""xyz"" = ""cde""
-- #test implementation ""aaa"" = ""fff""","theorem correctness
(s: String)
: problem_spec implementation s
:=","by
unfold problem_spec
let result := implementation s
use result
simp [result]
sorry",,,
def remove_vowels(string: str) -> string,"remove_vowels is a function that takes string and returns string without vowels.
","[{""input"": """", ""expected_output"": """"}, {""input"": ""abcdef\nghijklm"", ""expected_output"": ""bcdf\nghjklm""}, {""input"": ""abcdef"", ""expected_output"": ""bcdf""}, {""input"": ""aaaaa"", ""expected_output"": """"}, {""input"": ""aaBAA"", ""expected_output"": ""B""}]","def remove_vowels(string: str) -> string
""""""remove_vowels is a function that takes string and returns string without vowels.
""""""","def problem_spec
-- function signature
(implementation: String β String)
-- inputs
(string: String) :=
let is_consonant (c: Char): Bool :=
let vowels := ""aeiouAEIOU""
not (vowels.contains c);
-- spec
let spec (result: String) :=
result.all (Ξ» c => is_consonant c) β§ result.length β€ string.length β§
β c, result.contains c β string.contains c β§
β c , string.contains c β§ is_consonant c β (result.contains c);
-- program termination
β result, implementation string = result β§
spec result","def generated_spec
-- function signature
(impl: String β String)
-- inputs
(string : String) : Prop :=","theorem spec_isomorphism:
β impl,
(β string, problem_spec impl string) β
(β string, generated_spec impl string) :=",sorry,def implementation (string: String) : String :=,sorry,"-- #test implementation """" = """"
-- #test implementation ""cat"" = ""catac""
-- #test implementation ""cata"" = ""catac""","theorem correctness
(s: String)
: problem_spec implementation s
:=","by
unfold problem_spec
let result := implementation s
use result
simp [result]
sorry",,,
"def below_threshold(numbers: List[Int], threshold: Int) -> bool","Return True if all numbers in the list l are below threshold t, and False otherwise.","[{""input"": [[1, 2, 4, 10], 100], ""expected_output"": true}, {""input"": [[1, 20, 4, 10], 5], ""expected_output"": false}]","def below_threshold(numbers: List[Int], threshold: Int) -> bool
""""""Return True if all numbers in the list l are below threshold t, and False otherwise.""""""","def problem_spec
-- function signature
(impl: List Int β Int β Bool)
-- inputs
(numbers: List Int)
(threshold: Int) :=
-- spec
let numbers_below_threshold :=
β i, i < numbers.length β numbers[i]! < threshold;
let spec (res: Bool) :=
(numbers.length = 0 β res) β§
(res β numbers_below_threshold)
-- program terminates
β result, impl numbers threshold = result β§
-- return value satisfies spec
spec result
-- if result then spec else Β¬spec","def generated_spec
-- function signature
(impl: List Int β Int β Bool)
-- inputs
(numbers : List Int)
(threshold : Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β numbers threshold, problem_spec impl numbers threshold) β
(β numbers threshold, generated_spec impl numbers threshold) :=",sorry,def implementation (numbers: List Int) (threshold: Int) : Bool :=,sorry,"-- #test implementation ([1, 2, 4, 10]: List Int) 100 = true
-- #test implementation ([1, 20, 4, 10]: List Int) 5 = false","theorem correctness
(numbers: List Int)
(threshold: Int)
: problem_spec implementation numbers threshold :=","by
unfold problem_spec
let result := implementation numbers threshold
use result
simp [result]
sorry",,,
"def add(x: Int, y: Int) -> Int",Add two numbers x and y,"[{""input"": [2, 3], ""expected_output"": 5}, {""input"": [5, 7], ""expected_output"": 12}]","def add(x: Int, y: Int) -> Int
""""""Add two numbers x and y""""""","def problem_spec
-- function signature
(impl: Int β Int β Int)
-- inputs
(x y: Int) :=
-- spec
let spec (res: Int) :=
res - x - y = 0
-- program terminates
β result, impl x y = result β§
-- return value satisfies spec
spec result
-- if result then spec else Β¬spec","def generated_spec
-- function signature
(impl: Int β Int β Int)
-- inputs
(x y: Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β x y, problem_spec impl x y) β
(β x y, generated_spec impl x y) :=",sorry,def implementation (x y: Int) : Int :=,sorry,"-- #test implementation 2 3 = 5
-- #test implementation 5 7 = 12","theorem correctness
(x y: Int)
: problem_spec implementation x y :=","by
unfold problem_spec
let result := implementation x y
use result
simp [result]
sorry",,,
"def same_chars(s0: string, s1: string) -> Bool",Check if two words have the same characters.,"[{""input"": [""eabcdzzzz"", ""dddzzzzzzzddeddabc""], ""expected_output"": true}, {""input"": [""eabcd"", ""dddddddabc""], ""expected_output"": false}]","def same_chars(s0: string, s1: string) -> Bool
""""""Check if two words have the same characters.""""""","def problem_spec
-- function signature
(impl: String β String β Bool)
-- inputs
(s0 s1: String) :=
-- spec
let spec (res: Bool) :=
res β (β c : Char, c β s0.toList β c β s1.toList)
-- program terminates
β result, impl s0 s1 = result β§
-- return value satisfies spec
spec result
-- if result then spec else Β¬spec","def generated_spec
-- function signature
(impl: String β String β Bool)
-- inputs
(s0 s1: String) : Prop :=","theorem spec_isomorphism:
β impl,
(β s0 s1, problem_spec impl s0 s1) β
(β s0 s1, generated_spec impl s0 s1) :=",sorry,def implementation (s0 s1: String) : Bool :=,sorry,"-- #test implementation 'eabcdzzzz' 'dddzzzzzzzddeddabc' = true
-- #test implementation 'abcd' 'dddddddabc' = true
-- #test implementation 'dddddddabc' 'abcd' = true
-- #test implementation 'eabcd' 'dddddddabc' = false
-- #test implementation 'abcd' 'dddddddabce' = false
-- #test implementation 'eabcdzzzz' 'dddzzzzzzzddddabc' = false","theorem correctness
(s0 s1: String)
: problem_spec implementation s0 s1 :=","by
unfold problem_spec
let result := implementation s0 s1
use result
simp [result]
sorry",,,
def fib(n: int) -> int,"Return n-th Fibonacci number.
","[{""input"": 10, ""expected_output"": 55}, {""input"": 1, ""expected_output"": 1}, {""input"": 8, ""expected_output"": 21}]","def fib(n: int) -> int
""""""Return n-th Fibonacci number.
""""""","def problem_spec
-- function signature
(implementation: Nat β Nat)
-- inputs
(n: Nat) :=
-- spec
let spec (result: Nat) :=
fibonacci_non_computable n result
-- program termination
β result, implementation n = result β§
spec result","def generated_spec
-- function signature
(impl: Nat β Nat)
-- inputs
(x : Nat) : Prop :=","theorem spec_isomorphism:
β impl,
(β n, problem_spec impl n) β
(β n, generated_spec impl n) :=",sorry,def implementation (n: Nat) : Nat :=,sorry,"-- #test implementation 10 = 55
-- #test implementation 1 = 1
-- #test implementation 8 = 21","theorem correctness
(n: Nat)
: problem_spec implementation n
:=","by
unfold problem_spec
let result := implementation n
use result
simp [result]
repeat sorry","/--
name: fibonacci_non_computable
use: |
Non-computable definition to check if a number is a Fibonacci number.
problems:
- 55
sample_problems:
- 3
-/
inductive fibonacci_non_computable : β β β β Prop
| base0 : fibonacci_non_computable 0 0
| base1 : fibonacci_non_computable 1 1
| step : β n fβ fβ, fibonacci_non_computable n fβ β
fibonacci_non_computable (n + 1) fβ β
fibonacci_non_computable (n + 2) (fβ + fβ)",,
def correct_bracketing(brackets: str) -> Bool,"brackets is a string of ""<"" and "">"".
return True if every opening bracket has a corresponding closing bracket, i.e., (each open bracket is properly closed)
","[{""input"": ""<"", ""expected_output"": false}, {""input"": ""<>"", ""expected_output"": true}, {""input"": ""<<><>>"", ""expected_output"": true}, {""input"": ""><<>"", ""expected_output"": false}]","def correct_bracketing(brackets: str) -> Bool
""""""brackets is a string of ""<"" and "">"".
return True if every opening bracket has a corresponding closing bracket, i.e., (each open bracket is properly closed)
""""""","def problem_spec
-- function signature
(impl: String β Bool)
-- inputs
(brackets: String) :=
-- spec
let spec (result: Bool) :=
brackets.data.all (fun c => c = '<' β¨ c = '>') β
(result β balanced_paren_non_computable brackets '<' '>')
-- program terminates
β result, impl brackets = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: String β Bool)
-- inputs
(brackets : String) : Prop :=","theorem spec_isomorphism:
β impl,
(β brackets, problem_spec impl brackets) β
(β brackets, generated_spec impl brackets) :=",sorry,def implementation (brackets: String) : Bool :=,sorry,"-- #test implementation ""<"" = false
-- #test implementation ""<>"" = true
-- #test implementation ""<<><>>"" = true
-- #test implementation ""><<>"" = false","theorem correctness
(brackets: String)
: problem_spec implementation brackets :=","by
unfold problem_spec
let result := implementation brackets
use result
simp [result]
sorry",,,
def monotonic(numbers: List[int]) -> Bool,"Return True if list elements are monotonically increasing or decreasing.
","[{""input"": [1, 2, 4, 20], ""expected_output"": true}, {""input"": [1, 20, 4, 10], ""expected_output"": false}, {""input"": [4, 1, 0, -10], ""expected_output"": true}]","def monotonic(numbers: List[int]) -> Bool
""""""Return True if list elements are monotonically increasing or decreasing.
""""""","def problem_spec
-- function signature
(implementation: List Int β Bool)
-- inputs
(numbers: List Int) :=
let non_ordered := β i j,
i < numbers.length - 1 β§
j < numbers.length - 1 β§
(numbers[i]! < numbers[i+1]!) β§
(numbers[j+1]! < numbers[j]!);
-- spec
let spec (result: Bool) :=
1 < numbers.length β
result β Β¬non_ordered;
-- program termination
β result, implementation numbers = result β§
spec result","def generated_spec
-- function signature
(impl: List Int β Bool)
-- inputs
(numbers : List Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β numbers, problem_spec impl numbers) β
(β numbers, generated_spec impl numbers) :=",sorry,def implementation (numbers: List Int) : Bool :=,sorry,"-- #test implementation [1, 2, 4, 20] = true
-- #test implementation [1, 20, 4, 10] = false
-- #test implementation [4, 1, 0, -10] = true","theorem correctness
(numbers: List Int)
: problem_spec implementation numbers
:=","by
unfold problem_spec
let result := implementation numbers
use result
simp [result]
sorry",,,
"def common(l1: List[Int], l2: List[Int]) -> List[Int]","Return sorted unique common elements for two lists.
","[{""input"": [[1, 4, 3, 34, 653, 2, 5], [5, 7, 1, 5, 9, 653, 121]], ""expected_output"": [1, 5, 653]}, {""input"": [[5, 3, 2, 8], [3, 2]], ""expected_output"": [2, 3]}]","def common(l1: List[Int], l2: List[Int]) -> List[Int]
""""""Return sorted unique common elements for two lists.
""""""","def problem_spec
-- function signature
(implementation: List Int β List Int β List Int)
-- inputs
(l1 l2: List Int) :=
let is_unique (result: List Int) :=
β i j, i < result.length β j < result.length β
i β j β result[i]! β result[j]!;
let is_sorted (result: List Int) :=
β i, i < result.length - 1 β
result[i]! β€ result[i + 1]!;
-- spec
let spec (result: List Int) :=
is_unique result β§
is_sorted result β§
(β i : Int, i β result β i β l1 β§ i β l2)
-- program termination
β result, implementation l1 l2 = result β§
spec result","def generated_spec
-- function signature
(impl: List Int β List Int β List Int)
-- inputs
(x y: List Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β x y, problem_spec impl x y) β
(β x y, generated_spec impl x y) :=",sorry,def implementation (l1 l2: List Int) : List Int :=,sorry,"-- #test implementation [1, 4, 3, 34, 653, 2, 5] [5, 7, 1, 5, 9, 653, 121] = [1, 5, 653]
-- #test implementation [5, 3, 2, 8] [3, 2] = [2, 3]","theorem correctness
(l1 l2: List Int)
: problem_spec implementation l1 l2
:=","by
unfold problem_spec
let result := implementation l1 l2
use result
simp [result]
sorry",,,
def largest_prime_factor(n: Nat) -> Nat,"Return the largest prime factor of n. Assume n > 1 and is not a prime.
","[{""input"": 13195, ""expected_output"": 29}, {""input"": 2048, ""expected_output"": 2}]","def largest_prime_factor(n: Nat) -> Nat
""""""Return the largest prime factor of n. Assume n > 1 and is not a prime.
""""""","def problem_spec
-- function signature
(implementation: Nat β Nat)
-- inputs
(n: Nat) :=
-- spec
let spec (result: Nat) :=
1 < n β§ Β¬ Nat.Prime n β
(Nat.Prime result β§ result β£ n β§
β i, i < n β§ i β£ n β§ Nat.Prime i β i β€ result);
-- program termination
β result, implementation n = result β§
spec result","def generated_spec
-- function signature
(impl: Nat β Nat)
-- inputs
(x : Nat) : Prop :=","theorem spec_isomorphism:
β impl,
(β x, problem_spec impl x) β
(β x, generated_spec impl x) :=",sorry,def implementation (n: Nat) : Nat :=,sorry,"-- #test implementation 13195 = 29
-- #test implementation 2048 = 2","theorem correctness
(n: Nat)
: problem_spec implementation n
:=","by
unfold problem_spec
let result := implementation n
use result
simp [result]
sorry",,,
def sum_to_n(n: Nat) -> Nat,"sum_to_n is a function that sums numbers from 1 to n.
","[{""input"": 30, ""expected_output"": 465}, {""input"": 100, ""expected_output"": 4950}]","def sum_to_n(n: Nat) -> Nat
""""""sum_to_n is a function that sums numbers from 1 to n.
""""""","def problem_spec
-- function signature
(implementation: Nat β Nat)
-- inputs
(n : Nat) :=
-- spec
let spec (result: Nat) :=
0 < n β
(result = 1 β n = 1) β§
(β i, implementation (i + 1) - (implementation i) = i + 1)
-- program termination
β result, implementation n = result β§
spec result","def generated_spec
-- function signature
(impl: Nat β Nat)
-- inputs
(n : Nat) : Prop :=","theorem spec_isomorphism:
β impl,
(β n, problem_spec impl n) β
(β n, generated_spec impl n) :=",sorry,def implementation (n: Nat) : Nat :=,sorry,"-- #test implementation 30 = 465
-- #test implementation 100 = 5050
-- #test implementation 5 = 15
-- #test implementation 10 = 55
-- #test implementation 1 = 1","theorem correctness
(n: Nat)
: problem_spec implementation n
:=","by
unfold problem_spec
let result := implementation n
use result
simp [result]
sorry",,,
def correct_bracketing(brackets: str) -> Bool,"brackets is a string of ""("" and "")"".
return True if every opening bracket has a corresponding closing bracket.
","[{""input"": ""("", ""expected_output"": false}, {""input"": ""()"", ""expected_output"": true}, {""input"": ""(()())"", ""expected_output"": true}, {""input"": "")(()"", ""expected_output"": false}]","def correct_bracketing(brackets: str) -> Bool
""""""brackets is a string of ""("" and "")"".
return True if every opening bracket has a corresponding closing bracket.
""""""","def problem_spec
-- function signature
(impl: String β Bool)
-- inputs
(brackets: String) :=
-- spec
let spec (result: Bool) :=
brackets.data.all (fun c => c = '(' β¨ c = ')') β
(result β balanced_paren_non_computable brackets '(' ')')
-- program terminates
β result, impl brackets = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: String β Bool)
-- inputs
(x : String) : Prop :=","theorem spec_isomorphism:
β impl,
(β x, problem_spec impl x) β
(β x, generated_spec impl x) :=",sorry,def implementation (paren_string: String) : Bool :=,sorry,"-- #test implementation ""("" = false
-- #test implementation ""()"" = true
-- #test implementation ""(()())"" = true
-- #test implementation "")(()"" = false","theorem correctness
(brackets: String)
: problem_spec implementation brackets :=","by
unfold problem_spec
let result := implementation brackets
use result
simp [result]
sorry",,,
def derivative(xs: List Int) -> List Int,"xs represent coefficients of a polynomial.
xs[0] + xs[1] * x + xs[2] * x^2 + ....
Return derivative of this polynomial in the same form.
","[{""input"": [3, 1, 2, 4, 5], ""expected_output"": [1, 4, 12, 20]}, {""input"": [1, 2, 3], ""expected_output"": [2, 6]}]","def derivative(xs: List Int) -> List Int
""""""xs represent coefficients of a polynomial.
xs[0] + xs[1] * x + xs[2] * x^2 + ....
Return derivative of this polynomial in the same form.
""""""","def problem_spec
-- function signature
(impl: List Int β List Int)
-- inputs
(xs: List Int) :=
-- spec
let spec (result: List Int) :=
result.length = xs.length - 1 β§
result = (check_derivative xs.reverse).reverse
-- program terminates
β result, impl xs = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: List Int β List Int)
-- inputs
(xs : List Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β xs, problem_spec impl xs) β
(β xs, generated_spec impl xs) :=",sorry,def implementation (xs: List Int) : List Int :=,sorry,"-- #test implementation [3, 1, 2, 4, 5] : List Int = [1, 4, 12, 20]
-- #test implementation [1, 2, 3] : List Int = [2, 6]","theorem correctness
(xs: List Int)
: problem_spec implementation xs :=","by
unfold problem_spec
let result := implementation xs
use result
simp [result]
sorry",,,
def fibfib(n: int),"The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
fibfib(0) == 0
fibfib(1) == 0
fibfib(2) == 1
fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3).
Please write a function to efficiently compute the n-th element of the fibfib number sequence.
","[{""input"": 1, ""output"": 0}, {""input"": 5, ""output"": 4}, {""input"": 8, ""output"": 24}]","def fibfib(n: int)
""""""The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
fibfib(0) == 0
fibfib(1) == 0
fibfib(2) == 1
fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3).
Please write a function to efficiently compute the n-th element of the fibfib number sequence.
""""""","def problem_spec
-- function signature
(implementation: Nat β Nat)
-- inputs
(n: Nat) :=
-- spec
let spec (result: Nat) :=
fibonacci_non_computable_3 n result
-- program termination
β result, implementation n = result β§
spec result","def generated_spec
-- function signature
(impl: Nat β Nat)
-- inputs
(x : Nat) : Prop :=","theorem spec_isomorphism:
β impl,
(β x, problem_spec impl x) β
(β x, generated_spec impl x) :=",sorry,def implementation (n: Nat) : Nat :=,sorry,"-- #test implementation 1 = 0
-- #test implementation 5 = 4
-- #test implementation 8 = 24","theorem correctness
(n: Nat)
: problem_spec implementation n
:=","by
unfold problem_spec
let result := implementation n
use result
simp [result]
repeat sorry","/--
name: fibonacci_non_computable_3
use: |
Non-computable definition to check if a number is a Fibonacci number such that
fib(n) = fib(n - 1) + fib(n - 2) + fib(n - 3).
problems:
- 63
-/
inductive fibonacci_non_computable_3 : β β β β Prop
| base0 : fibonacci_non_computable_3 0 0
| base1 : fibonacci_non_computable_3 1 0
| base2 : fibonacci_non_computable_3 2 1
| step : β n fβ fβ fβ, fibonacci_non_computable_3 n fβ β
fibonacci_non_computable_3 (n + 1) fβ β
fibonacci_non_computable_3 (n + 2) fβ β
fibonacci_non_computable_3 (n + 3) (fβ + fβ + fβ)",,
def remove_vowels(string: str) -> Nat,"Write a function vowels_count which takes a string representing
a word as input and returns the number of vowels in the string.
Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a
vowel, but only when it is at the end of the given word.
","[{""input"": ""abcde"", ""expected_output"": 2}, {""input"": ""ACEDY"", ""expected_output"": 3}]","def remove_vowels(string: str) -> Nat
""""""Write a function vowels_count which takes a string representing
a word as input and returns the number of vowels in the string.
Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a
vowel, but only when it is at the end of the given word.
""""""","def problem_spec
-- function signature
(implementation: String β Nat)
-- inputs
(string: String) :=
let isVowel (c : Char) :=
let vowels := ""aeiouAEIOU""
vowels.contains c
let isY (c : Char) := c = 'y' β¨ c = 'Y'
-- spec
let spec (result: Nat) :=
string.data.all (fun c => c.isAlpha) β
if string.length = 1 then
result = if isVowel string.data[0]! β¨ isY string.data[0]! then 1 else 0
else
result = (if isVowel string.data[0]! then 1 else 0) + implementation (string.drop 1);
-- program termination
β result, implementation string = result β§
spec result","def generated_spec
-- function signature
(impl: String β Nat)
-- inputs
(x : String) : Prop :=","theorem spec_isomorphism:
β impl,
(β x, problem_spec impl x) β
(β x, generated_spec impl x) :=",sorry,def implementation (string: String) : Nat :=,sorry,"-- #test implementation ""abcde"" = 2
-- #test implementation ""ACEDY"" = 3","theorem correctness
(s: String)
: problem_spec implementation s
:=","by
unfold problem_spec
let result := implementation s
use result
simp [result]
sorry",,,
"def circular_shift(x: Int, shift: Int) -> String","Circular shift the digits of the integer x, shift the digits right by shift
and return the result as a string.
If shift > number of digits, return digits reversed.
","[{""input"": [12, 1], ""expected_output"": 21}, {""input"": [12, 2], ""expected_output"": 12}]","def circular_shift(x: Int, shift: Int) -> String
""""""Circular shift the digits of the integer x, shift the digits right by shift
and return the result as a string.
If shift > number of digits, return digits reversed.
""""""","def problem_spec
-- function signature
(implementation: Nat β Nat β String)
-- inputs
(x shift: Nat) :=
let isReverse (s: String) : Bool :=
let n := s.length;
β i, i < n / 2 β s.get! β¨iβ© = s.get! β¨n - 1 - iβ©;
-- spec
let spec (result: String) :=
let x_str := Nat.repr x;
result.length = x_str.length β§
(x_str.length < shift β isReverse x_str) β§
(shift β€ x_str.length β
x_str.take shift = result.drop (x_str.length - shift) β§
x_str.drop shift = result.take (x_str.length - shift));
-- program termination
β result, implementation x shift = result β§
spec result","def generated_spec
-- function signature
(impl: Nat β Nat β String)
-- inputs
(x y: Nat) : Prop :=","theorem spec_isomorphism:
β impl,
(β x y, problem_spec impl x y) β
(β x y, generated_spec impl x y) :=",sorry,def implementation (x shift: Nat) : String :=,sorry,"-- #test implementation (12 : Int) (1 : Int) = ""21""
-- #test implementation (12 : Int) (2 : Int) = ""12""","theorem correctness
(x shift: Nat)
: problem_spec implementation x shift
:=","by
unfold problem_spec
let result := implementation x shift
use result
simp [result]
sorry",,,
def digitSum(string: str) -> Nat,"Write a function that takes a string as input and returns the sum of the upper characters only'
ASCII codes.
","[{""input"": """", ""expected_output"": 0}, {""input"": ""abAB"", ""expected_output"": 131}, {""input"": ""helloE"", ""expected_output"": 69}]","def digitSum(string: str) -> Nat
""""""Write a function that takes a string as input and returns the sum of the upper characters only'
ASCII codes.
""""""","def problem_spec
-- function signature
(implementation: String β Nat)
-- inputs
(string: String) :=
let isUpper (c : Char) :=
65 β€ c.toNat β§ c.toNat β€ 90
-- spec
let spec (result: Nat) :=
if string.length = 1 then
result = if isUpper string.data[0]! then string.data[0]!.toNat else 0
else
result = (if isUpper string.data[0]! then string.data[0]!.toNat else 0) + implementation (string.drop 1);
-- program termination
β result, implementation string = result β§
spec result","def generated_spec
-- function signature
(impl: String β Nat)
-- inputs
(x: String) : Prop :=","theorem spec_isomorphism:
β impl,
(β x, problem_spec impl x) β
(β x, generated_spec impl x) :=",sorry,def implementation (string: String) : Nat :=,sorry,"-- #test implementation """" = 0
-- #test implementation ""abAB"" = 131
-- #test implementation ""abcCd"" = 67
-- #test implementation ""helloE"" = 69
-- #test implementation ""woArBld"" = 131
-- #test implementation ""aAaaaXa"" = 153","theorem correctness
(s: String)
: problem_spec implementation s
:=","by
unfold problem_spec
let result := implementation s
use result
simp [result]
sorry",,,
"def fruit_distribution(string: str, Nat n) -> Nat","In this task, you will be given a string that represents a number of apples and oranges
that are distributed in a basket of fruit this basket contains
apples, oranges, and mango fruits. Given the string that represents the total number of
the oranges and apples and an integer that represent the total number of the fruits
in the basket return the number of the mango fruits in the basket.
","[{""input"": [""5 apples and 6 oranges"", 19], ""expected_output"": 8}, {""input"": [""0 apples and 1 oranges"", 3], ""expected_output"": 2}, {""input"": [""2 apples and 3 oranges"", 100], ""expected_output"": 95}, {""input"": [""100 apples and 1 oranges"", 120], ""expected_output"": 19}]","def fruit_distribution(string: str, Nat n) -> Nat
""""""In this task, you will be given a string that represents a number of apples and oranges
that are distributed in a basket of fruit this basket contains
apples, oranges, and mango fruits. Given the string that represents the total number of
the oranges and apples and an integer that represent the total number of the fruits
in the basket return the number of the mango fruits in the basket.
""""""","def problem_spec
-- function signature
(implementation: String β Nat β Nat)
-- inputs
(string: String)
(n : Nat) :=
-- spec
let spec (result: Nat) :=
β x y : Nat, x + y = n - result
β§ (String.join [x.repr, "" apples and "", y.repr, "" oranges""] = string)
-- program termination
β result, implementation string n = result β§
spec result","def generated_spec
-- function signature
(impl: String β Nat β Nat)
-- inputs
(x: String) (y: Nat) : Prop :=","theorem spec_isomorphism:
β impl,
(β x y, problem_spec impl x y) β
(β x y, generated_spec impl x y) :=",sorry,def implementation (string: String) (n: Nat) : Nat :=,sorry,"-- #test implementation ""5 apples and 6 oranges"" 19 = 8
-- #test implementation ""0 apples and 1 oranges"" 3 = 2
-- #test implementation ""2 apples and 3 oranges"" 100 = 95
-- #test implementation ""100 apples and 1 oranges"" 120 = 19","theorem correctness
(s: String) (n : Nat)
: problem_spec implementation s n
:=","by
unfold problem_spec
let result := implementation s n
use result
simp [result]
sorry",,,
def pluck(numbers: List[Int]) -> List[Int],"Given an array representing a branch of a tree that has non-negative integer nodes
your task is to pluck one of the nodes and return it.
The plucked node should be the node with the smallest even value.
If multiple nodes with the same smallest even value are found return the node that has smallest index.
The plucked node should be returned in a list, [ smallest_value, its index ],
If there are no even values or the given array is empty, return [].
","[{""input"": [4, 2, 3], ""expected_output"": [2, 1]}, {""input"": [1, 2, 3], ""expected_output"": [2, 1]}, {""input"": [], ""expected_output"": []}, {""input"": [5, 0, 3, 0, 4, 2], ""expected_output"": [0, 1]}]","def pluck(numbers: List[Int]) -> List[Int]
""""""Given an array representing a branch of a tree that has non-negative integer nodes
your task is to pluck one of the nodes and return it.
The plucked node should be the node with the smallest even value.
If multiple nodes with the same smallest even value are found return the node that has smallest index.
The plucked node should be returned in a list, [ smallest_value, its index ],
If there are no even values or the given array is empty, return [].
""""""","def problem_spec
-- function signature
(implementation: List Nat β List Nat)
-- inputs
(numbers: List Nat) :=
-- spec
let spec (result: List Nat) :=
(result.length = 0 β β i, i < numbers.length β numbers[i]! % 2 = 1) β§
(result.length = 2 β β i, i < numbers.length β§
numbers[i]! % 2 = 0 β§
result[0]! = numbers[i]! β§
result[1]! = i β§
(β j, j < numbers.length β j < i β (numbers[j]! % 2 = 1 β¨ numbers[i]! < numbers[j]!)) β§
(β k, k < numbers.length β numbers[k]! % 2 = 0 β numbers[i]! β€ numbers[k]!));
-- program termination
β result, implementation numbers = result β§
spec result","def generated_spec
-- function signature
(impl: List Nat β List Nat)
-- inputs
(x: List Nat) : Prop :=","theorem spec_isomorphism:
β impl,
(β x, problem_spec impl x) β
(β x, generated_spec impl x) :=",sorry,def implementation (numbers: List Nat) : List Nat :=,sorry,"-- #test implementation [4, 2, 3] = [2, 1]
-- #test implementation [1, 2, 3] = [2, 1]
-- #test implementation [] = []
-- #test implementation [5, 0, 3, 0, 4, 2] = [0, 1]
--","theorem correctness
(numbers: List Nat)
: problem_spec implementation numbers
:=","by
unfold problem_spec
let result := implementation numbers
use result
simp [result]
sorry",,,
def search(numbers: List[int]) -> int,"You are given a non-empty list of positive integers. Return the greatest integer that is greater than
zero, and has a frequency greater than or equal to the value of the integer itself.
The frequency of an integer is the number of times it appears in the list.
If no such a value exist, return -1.
","[{""input"": [4, 1, 2, 2, 3, 1], ""expected_output"": 2}, {""input"": [1, 2, 2, 3, 3, 3, 4, 4, 4], ""expected_output"": 3}, {""input"": [5, 5, 4, 4, 4], ""expected_output"": -1}]","def search(numbers: List[int]) -> int
""""""You are given a non-empty list of positive integers. Return the greatest integer that is greater than
zero, and has a frequency greater than or equal to the value of the integer itself.
The frequency of an integer is the number of times it appears in the list.
If no such a value exist, return -1.
""""""","def problem_spec
-- function signature
(implementation: List Int β Int)
-- inputs
(numbers: List Int) :=
-- spec
let spec (result: Int) :=
0 < numbers.length β§ numbers.all (fun n => 0 < n) β
(result β -1 β β i : Nat, i < numbers.length β§
numbers[i]! = result β§ numbers[i]! > 0 β§
numbers[i]! β€ (numbers.filter (fun x => x = numbers[i]!)).length β§
(Β¬β j : Nat, j < numbers.length β§
numbers[i]! < numbers[j]! β§ numbers[j]! β€ numbers.count numbers[j]!));
-- program termination
β result, implementation numbers = result β§
spec result","def generated_spec
-- function signature
(impl: List Int β Int)
-- inputs
(x: List Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β x, problem_spec impl x) β
(β x, generated_spec impl x) :=",sorry,def implementation (numbers: List Int) : (Int) :=,sorry,"-- #test implementation [4, 1, 2, 2, 3, 1] = 2
-- #test implementation [1, 2, 2, 3, 3, 4, 4, 4] = 3
-- #test implementation [5, 5, 4, 4, 4] = -1","theorem correctness
(numbers: List Int)
: problem_spec implementation numbers
:=","by
unfold problem_spec
let result := implementation numbers
use result
simp [result]
sorry",,,
def strange_sort_list(lst: List[int]) -> List[int],"Given list of integers, return list in strange order.
Strange sorting is when you start with the minimum value,
then the maximum of the remaining integers, then the minimum and so on.
","[{""input"": [1, 2, 3, 4], ""expected_output"": [1, 4, 2, 3]}, {""input"": [5, 5, 5, 5], ""expected_output"": [5, 5, 5, 5]}, {""input"": [], ""expected_output"": []}]","def strange_sort_list(lst: List[int]) -> List[int]
""""""Given list of integers, return list in strange order.
Strange sorting is when you start with the minimum value,
then the maximum of the remaining integers, then the minimum and so on.
""""""","def problem_spec
-- function signature
(implementation: List Int β List Int)
-- inputs
(lst: List Int) :=
-- spec
let spec (result: List Int) :=
let sorted_lst := lst.mergeSort;
(List.Perm lst result)
β§ (forall i, (0 <= i β§ i < lst.length β§ i % 2 = 0) β result[i]! = sorted_lst[i / 2]!)
β§ (forall i, (0 <= i β§ i < lst.length β§ i % 2 = 1) β result[i]! = sorted_lst[lst.length - (i-1)/2 - 1]!)
-- program termination
β result, implementation lst = result β§ spec result","def generated_spec
-- function signature
(impl: List Int β List Int)
-- inputs
(lst: List Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β lst, problem_spec impl lst) β
(β lst, generated_spec impl lst) :=",sorry,def implementation (lst: List Int): List Int :=,sorry,"-- #test implementation [1, 2, 3, 4] = [1, 4, 2, 3]
-- #test implementation [5, 6, 7, 8, 9] = [5, 9, 6, 8, 7]
-- #test implementation [1, 2, 3, 4, 5] = [1, 5, 2, 4, 3]
-- #test implementation [5, 6, 7, 8, 9, 1] = [1, 9, 5, 8, 6, 7]
-- #test implementation [5, 5, 5, 5] = [5, 5, 5, 5]
-- #test implementation [] = []
-- #test implementation [1,2,3,4,5,6,7,8] = [1, 8, 2, 7, 3, 6, 4, 5]
-- #test implementation [0,2,2,2,5,5,-5,-5] = [-5, 5, -5, 5, 0, 2, 2, 2]
-- #test implementation [111111] = [111111]","theorem correctness
(lst: List Int)
: problem_spec implementation lst
:=","by
sorry",,,
"def triangle_area(a: float, b: float, c: float) -> float","Given the lengths of the three sides of a triangle. Return the area of the triangle rounded to 2 decimal points
if the three sides form a valid triangle. Otherwise return -1. Three sides make a valid triangle when the sum of
any two sides is greater than the third side.
","[{""input"": ""(3, 4, 5)"", ""expected_output"": 6}, {""input"": ""(1, 2, 10)"", ""expected_output"": -1}]","def triangle_area(a: float, b: float, c: float) -> float
""""""Given the lengths of the three sides of a triangle. Return the area of the triangle rounded to 2 decimal points
if the three sides form a valid triangle. Otherwise return -1. Three sides make a valid triangle when the sum of
any two sides is greater than the third side.
""""""","def problem_spec
-- function signature
(implementation: Rat β Rat β Rat β Rat)
-- inputs
(a: Rat) (b: Rat) (c: Rat) :=
-- spec
let spec (result : Rat) :=
let is_valid_triangle :=
(a + b > c) β§ (a + c > b) β§ (b + c > a);
let s :=
(a + b + c) / 2;
if is_valid_triangle then
|result^2 - (s * (s-a) * (s-b) * (s-c))| β€ ((1: Rat)/10000)
else
result = -1
-- program termination
β result, implementation a b c = result β§
spec result","def generated_spec
-- function signature
(impl: Rat β Rat β Rat β Rat)
-- inputs
(a: Rat) (b: Rat) (c: Rat) : Prop :=","theorem spec_isomorphism:
β impl,
(β a b c, problem_spec impl a b c) β
(β a b c, generated_spec impl a b c) :=",sorry,def implementation (a: Rat) (b: Rat) (c: Rat): Rat :=,sorry,"-- #test implementation 3 4 5 = 6.00
-- #test implementation 1 2 10 = -1
-- #test implementation 4 8 5 = 8.18
-- #test implementation 2 2 2 = 1.73
-- #test implementation 1 2 3 = -1
-- #test implementation 10 5 7 = 16.25
-- #test implementation 2 6 3 = -1
-- #test implementation 1 1 1 = 0.43
-- #test implementation 2 2 10 = -1","theorem correctness
(a: Rat) (b: Rat) (c: Rat)
: problem_spec implementation a b c
:=","by
sorry",,,
"def will_it_fly(q: List[int], w: int) -> bool","Write a function that returns True if the object q will fly, and False otherwise.
The object q will fly if it's balanced (it is a palindromic list) and the sum of its elements is
less than or equal the maximum possible weight w.
","[{""input"": ""([1, 2], 5)"", ""expected_output"": false}, {""input"": ""([3, 2, 3], 1)"", ""expected_output"": false}, {""input"": ""([3, 2, 3], 9)"", ""expected_output"": true}, {""input"": ""([3], 5)"", ""expected_output"": true}]","def will_it_fly(q: List[int], w: int) -> bool
""""""Write a function that returns True if the object q will fly, and False otherwise.
The object q will fly if it's balanced (it is a palindromic list) and the sum of its elements is
less than or equal the maximum possible weight w.
""""""","def problem_spec
-- function signature
(implementation: List Int β Int β Bool)
-- inputs
(q: List Int) (w: Int) :=
-- spec
let spec (result : Bool) :=
(result β (List.Palindrome q)) β§
(result β (List.sum q β€ w)) β§
(Β¬(List.Palindrome q) β Β¬ result) β§
(Β¬(List.sum q β€ w) β Β¬ result)
-- program termination
β result, implementation q w = result β§
spec result","def generated_spec
-- function signature
(impl: List Int β Int β Bool)
-- inputs
(q: List Int) (w: Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β q w, problem_spec impl q w) β
(β q w, generated_spec impl q w) :=",sorry,def implementation (q: List Int) (w: Int) : Bool :=,(List.Palindrome q) β§ (List.sum q β€ w),"-- #test implementation [3, 2, 3] 9 = True
-- #test implementation [1, 2] 5 = False
-- #test implementation [3] 5 = True
-- #test implementation [3, 2, 3] 1 = False
-- #test implementation [1, 2, 3] 6 = False
-- #test implementation [5] 5 = True","theorem correctness
(q: List Int) (w: Int)
: problem_spec implementation q w
:=","by
unfold problem_spec
let result := implementation q w
use result
simp [result]
simp [implementation]
apply And.intro
intro h_is_palindrome h_q_sum
assumption
apply And.intro
intro h_palindrome
simp [h_palindrome]
intro h_q_sum h_palindrome
assumption",,,
def smallest_change(arr: List[int]) -> int,"Given an array arr of integers, find the minimum number of elements that
need to be changed to make the array palindromic. A palindromic array is an array that
is read the same backwards and forwards. In one change, you can change one element to any other element.
","[{""input"": [1, 2, 3, 5, 4, 7, 9, 6], ""expected_output"": 4}, {""input"": [1, 2, 3, 4, 3, 2, 2], ""expected_output"": 1}, {""input"": [1, 2, 3, 2, 1], ""expected_output"": 0}]","def smallest_change(arr: List[int]) -> int
""""""Given an array arr of integers, find the minimum number of elements that
need to be changed to make the array palindromic. A palindromic array is an array that
is read the same backwards and forwards. In one change, you can change one element to any other element.
""""""","def problem_spec
-- function signature
(implementation: List Int β Int)
-- inputs
(arr: List Int) :=
-- spec
let spec (result : Int) :=
let swaps_done (arr1: List Int) (arr2: List Int) :=
((List.finRange (arr1.length)).filter (fun idx => arr1[idx]? β arr2[idx]?)).length/2
β palin_perm, (List.Perm arr palin_perm) β§ (List.Palindrome palin_perm) β
result β€ (swaps_done arr palin_perm)
-- program termination
β result, implementation arr = result β§
spec result","def generated_spec
-- function signature
(impl: List Int β Int)
-- inputs
(arr: List Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β arr, problem_spec impl arr) β
(β arr, generated_spec impl arr) :=",sorry,def implementation (arr: List Int) : Int :=,((List.finRange (arr.length/2)).filter (fun i => arr[i]? != arr[arr.length - 1 - i]?)).length,"-- #test implementation [1,2,3,5,4,7,9,6] = 4
-- #test implementation [1, 2, 3, 4, 3, 2, 2] = 1
-- #test implementation [1, 4, 2] = 1
-- #test implementation [1, 4, 4, 2] = 1
-- #test implementation [1, 2, 3, 2, 1] = 0
-- #test implementation [3, 1, 1, 3] = 0
-- #test implementation [1] = 0
-- #test implementation [0, 1] = 1","theorem correctness
(arr: List Int)
: problem_spec implementation arr
:=","by
sorry",,,
"def total_match(lst1: List[str], lst2: List[str]) -> List[str]","Write a function that accepts two lists of strings and returns the list that has
total number of chars in the all strings of the list less than the other list.
If the two lists have the same number of chars, return the first list.
","[{""input"": ""([], [])"", ""expected_output"": []}, {""input"": ""(['hi', 'admin'], ['hI', 'Hi'])"", ""expected_output"": [""hI"", ""Hi""]}, {""input"": ""(['hi', 'admin'], ['hi', 'hi', 'admin', 'project'])"", ""expected_output"": [""hi"", ""admin""]}, {""input"": ""(['hi', 'admin'], ['hI', 'hi', 'hi'])"", ""expected_output"": [""hI"", ""hi"", ""hi""]}, {""input"": ""(['4'], ['1', '2', '3', '4', '5'])"", ""expected_output"": [""4""]}]","def total_match(lst1: List[str], lst2: List[str]) -> List[str]
""""""Write a function that accepts two lists of strings and returns the list that has
total number of chars in the all strings of the list less than the other list.
If the two lists have the same number of chars, return the first list.
""""""","def problem_spec
-- function signature
(implementation: List String β List String β List String)
-- inputs
(lst1: List String) (lst2: List String) :=
let sum_chars (xs: List String) : Int :=
xs.foldl (Ξ» acc a => acc + a.length) 0;
-- spec
let spec (result : List String) :=
((result = lst1) β¨ (result = lst2))
β§
(sum_chars result β€ sum_chars lst1)
β§
(sum_chars result β€ sum_chars lst2)
β§
((sum_chars lst1 = sum_chars lst2) β (result = lst1))
-- program termination
β result, implementation lst1 lst2 = result β§
spec result","def generated_spec
-- function signature
(impl: List String β List String β List String)
-- inputs
(lst1: List String) (lst2: List String) : Prop :=","theorem spec_isomorphism:
β impl,
(β lst1 lst2, problem_spec impl lst1 lst2) β
(β lst1 lst2, generated_spec impl lst1 lst2) :=",sorry,def implementation (lst1: List String) (lst2: List String) : List String :=,sorry,"-- #test implementation [] [] = []
-- #test implementation [""hi"", ""admin""] [""hi"", ""hi""] = [""hi"", ""hi""]
-- #test implementation [""hi"", ""admin""] [""hi"", ""hi"", ""admin"", ""project""] = [""hi"", ""admin""]
-- #test implementation [""4""] [""1"", ""2"", ""3"", ""4"", ""5""] = [""4""]
-- #test implementation [""hi"", ""admin""] [""hI"", ""Hi""] = [""hI"", ""Hi""]
-- #test implementation [""hi"", ""admin""] [""hI"", ""hi"", ""hi""] = [""hI"", ""hi"", ""hi""]
-- #test implementation [""hi"", ""admin""] [""hI"", ""hi"", ""hii""] = [""hi"", ""admin""]
-- #test implementation [] [""this""] = []
-- #test implementation [""this""] [] == []","theorem correctness
(lst1: List String) (lst2: List String)
: problem_spec implementation lst1 lst2
:=","by
sorry",,,
def is_multiply_prime(a: int) -> bool,"Write a function that returns true if the given number is the multiplication of 3 prime numbers
and false otherwise. Knowing that (a) is less then 100.
","[{""input"": 30, ""expected_output"": true}]","def is_multiply_prime(a: int) -> bool
""""""Write a function that returns true if the given number is the multiplication of 3 prime numbers
and false otherwise. Knowing that (a) is less then 100.
""""""","def problem_spec
-- function signature
(implementation: Int β Bool)
-- inputs
(a: Int) :=
-- spec
let spec (result: Bool) :=
(a < 100) β
result β exists a' b c, (Nat.Prime a') β§ (Nat.Prime b) β§ (Nat.Prime c) β§ (a == a'*b*c)
-- program termination
β result, implementation a = result β§
spec result","def generated_spec
-- function signature
(impl: Int β Bool)
-- inputs
(a: Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β a, problem_spec impl a) β
(β a, generated_spec impl a) :=",sorry,def implementation (a: Int) : Bool :=,sorry,"-- #test implementation 5 = False
-- #test implementation 30 = True
-- #test implementation 8 = True
-- #test implementation 10 = False
-- #test implementation 125 = True
-- #test implementation (3 * 5 * 7) = True
-- #test implementation (3 * 6 * 7) = False
-- #test implementation (9 * 9 * 9) = False
-- #test implementation (11 * 9 * 9) = False
-- #test implementation (11*13*7) = True","theorem correctness
(a: Int)
: problem_spec implementation a
:=","by
sorry",,,
"def is_simple_power(x: int, n: int) -> bool","Your task is to write a function that returns true if a number x is a simple
power of n and false in other cases. x is a simple power of n if n**int=x
","[{""input"": ""(1, 4)"", ""expected_output"": true}, {""input"": ""(2, 2)"", ""expected_output"": true}, {""input"": ""(8, 2)"", ""expected_output"": true}, {""input"": ""(3, 2)"", ""expected_output"": false}, {""input"": ""(3, 1)"", ""expected_output"": false}, {""input"": ""(5, 3)"", ""expected_output"": false}]","def is_simple_power(x: int, n: int) -> bool
""""""Your task is to write a function that returns true if a number x is a simple
power of n and false in other cases. x is a simple power of n if n**int=x
""""""","def problem_spec
-- function signature
(implementation: Int β Int β Bool)
-- inputs
(x: Int) (n: Int) :=
-- spec
let spec (result: Bool) :=
result β exists k: Nat, x = n^k
-- program termination
β result, implementation x n = result β§
spec result","def generated_spec
-- function signature
(impl: Int β Int β Bool)
-- inputs
(x: Int) (n: Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β x n, problem_spec impl x n) β
(β x n, generated_spec impl x n) :=",sorry,def implementation (x: Int) (n: Int) : Bool :=,sorry,"-- #test implementation 16 2 = True
-- #test implementation 143214 16 = False
-- #test implementation 4 2 = True
-- #test implementation 9 3 = True
-- #test implementation 16 4 = True
-- #test implementation 24 2 = False
-- #test implementation 128 4 = False
-- #test implementation 12 6 = False
-- #test implementation 1 1 = True
-- #test implementation 1 12 = True","theorem correctness
(x: Int) (n: Int)
: problem_spec implementation x n
:=","by
sorry",,,
def iscube(a: int) -> bool,"Write a function that takes an integer a and returns True if this integer is a cube of some integer number.
Note: you may assume the input is always valid.
","[{""input"": 1, ""expected_output"": true}, {""input"": 2, ""expected_output"": false}, {""input"": -1, ""expected_output"": true}, {""input"": 64, ""expected_output"": true}, {""input"": 0, ""expected_output"": true}, {""input"": 180, ""expected_output"": false}]","def iscube(a: int) -> bool
""""""Write a function that takes an integer a and returns True if this integer is a cube of some integer number.
Note: you may assume the input is always valid.
""""""","def problem_spec
-- function signature
(implementation: Int β Bool)
-- inputs
(a: Int) :=
-- spec
let spec (result: Bool) :=
result β exists n: Int, a = n^3
-- program termination
β result, implementation a = result β§
spec result","def generated_spec
-- function signature
(impl: Int β Bool)
-- inputs
(a: Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β a, problem_spec impl a) β
(β a, generated_spec impl a) :=",sorry,def implementation (a: Int) : Bool :=,sorry,"-- #test implementation 1 = True
-- #test implementation 2 = False
-- #test implementation -1 = True
-- #test implementation 64 = True
-- #test implementation 180 = False
-- #test implementation 1000 = True
-- #test implementation 0 = True
-- #test implementation 1729 = False","theorem correctness
(a: Int)
: problem_spec implementation a
:=","by
sorry",,,
def hex_key(num: string) -> int,"You have been tasked to write a function that receives
a hexadecimal number as a string and counts the number of hexadecimal
digits that are primes (prime number, or a prime, is a natural number
greater than 1 that is not a product of two smaller natural numbers).
Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
Prime numbers are 2, 3, 5, 7, 11, 13, 17,...
So you have to determine a number of the following digits: 2, 3, 5, 7,
B (=decimal 11), D (=decimal 13).
Note: you may assume the input is always correct or empty string,
and symbols A,B,C,D,E,F are always uppercase.
","[{""input"": ""AB"", ""expected_output"": 1}, {""input"": ""1077E"", ""expected_output"": 2}, {""input"": ""ABED1A33"", ""expected_output"": 4}, {""input"": ""123456789ABCDEF0"", ""expected_output"": 6}, {""input"": ""2020"", ""expected_output"": 2}]","def hex_key(num: string) -> int
""""""You have been tasked to write a function that receives
a hexadecimal number as a string and counts the number of hexadecimal
digits that are primes (prime number, or a prime, is a natural number
greater than 1 that is not a product of two smaller natural numbers).
Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
Prime numbers are 2, 3, 5, 7, 11, 13, 17,...
So you have to determine a number of the following digits: 2, 3, 5, 7,
B (=decimal 11), D (=decimal 13).
Note: you may assume the input is always correct or empty string,
and symbols A,B,C,D,E,F are always uppercase.
""""""","def problem_spec
-- function signature
(implementation: String β Int)
-- inputs
(num: String) :=
-- spec
let spec (result: Int) :=
let num_val (ch : Char) :=
if ch.isDigit then
(ch.toNat - '0'.toNat)
else if ch.isUpper then
((ch.toNat - 'A'.toNat) + 10)
else 0;
0 < num.length β
(
let char_val := num_val num.toList[0]!;
(Nat.Prime char_val β
(1 < num.length β result = char_val + implementation (num.drop 1)) β§
(1 = num.length β result = char_val)) β§
(Β¬Nat.Prime char_val β
(1 < num.length β result = implementation (num.drop 1)) β§
(1 = num.length β result = 0))
)
-- program termination
β result, implementation num = result β§
spec result","def generated_spec
-- function signature
(impl: String β Int)
-- inputs
(num: String) : Prop :=","theorem spec_isomorphism:
β impl,
(β num, problem_spec impl num) β
(β num, generated_spec impl num) :=",sorry,def implementation (num: String) : Int :=,"let IsPrimeHexDigit (c: Char): Int :=
if c = '2' β¨ c = '3' β¨ c = '5' β¨ c = '7' β¨ c = 'B' β¨ c = 'D' then 1 else 0;
num.foldl (Ξ» acc a => acc + (IsPrimeHexDigit a)) 0","-- #test implementation ""AB"" = 1
-- #test implementation ""1077E"" = 2
-- #test implementation ""ABED1A33"" = 4
-- #test implementation ""2020"" = 2
-- #test implementation ""123456789ABCDEF0"" = 6
-- #test implementation ""112233445566778899AABBCCDDEEFF00"" = 12
-- #test implementation """" = 0","theorem correctness
(num: String)
: problem_spec implementation num
:=","by
sorry",,,
def decimal_to_binary(decimal: nat) -> string,"You will be given a number in decimal form and your task is to convert it to
binary format. The function should return a string, with each character representing a binary
number. Each character in the string will be '0' or '1'.
There will be an extra couple of characters 'db' at the beginning and at the end of the string.
The extra characters are there to help with the format.
","[{""input"": 15, ""expected_output"": ""db1111db""}, {""input"": 32, ""expected_output"": ""db100000db""}]","def decimal_to_binary(decimal: nat) -> string
""""""You will be given a number in decimal form and your task is to convert it to
binary format. The function should return a string, with each character representing a binary
number. Each character in the string will be '0' or '1'.
There will be an extra couple of characters 'db' at the beginning and at the end of the string.
The extra characters are there to help with the format.
""""""","def problem_spec
-- function signature
(implementation: Nat β String)
-- inputs
(decimal: Nat) :=
-- spec
let spec (result: String) :=
4 < result.length β§
result.drop (result.length - 2) = ""db"" β§
result.take 2 = ""db"" β§
let resultTrimmed := (result.toList.drop 2).dropLast.dropLast.map (fun c => c.toNat - '0'.toNat)
decimal = Nat.ofDigits 2 resultTrimmed.reverse
-- program termination
β result, implementation decimal = result β§
spec result","def generated_spec
-- function signature
(impl: Nat β String)
-- inputs
(decimal: Nat) : Prop :=","theorem spec_isomorphism:
β impl,
(β decimal, problem_spec impl decimal) β
(β decimal, generated_spec impl decimal) :=",sorry,def implementation (decimal: Nat) : String :=,"""db"" ++ (Nat.toDigits 2 decimal).asString ++ ""db""","-- #test implementation 0 = ""db0db""
-- #test implementation 32 = ""db100000db""
-- #test implementation 103 = ""db1100111db""
-- #test implementation 15 = ""db1111db""","theorem correctness
(decimal: Nat)
: problem_spec implementation decimal
:=","by
sorry",,,
def is_happy(s: str) -> bool,"You are given a string s.
Your task is to check if the string is happy or not.
A string is happy if its length is at least 3 and every 3 consecutive letters are distinct
","[{""input"": ""a"", ""output"": false}, {""input"": ""aa"", ""output"": false}, {""input"": ""abcd"", ""output"": true}, {""input"": ""aabb"", ""output"": false}, {""input"": ""adb"", ""output"": true}]","def is_happy(s: str) -> bool
""""""You are given a string s.
Your task is to check if the string is happy or not.
A string is happy if its length is at least 3 and every 3 consecutive letters are distinct
""""""","def problem_spec
-- function signature
(implementation: String β Bool)
-- inputs
(s: String) :=
-- spec
let spec (result : Bool) :=
result β
(3 β€ s.length) β§
Β¬ (β i j, i < j β§ j < s.length β§ j - i β€ 2 β§ s.data.get! i = s.data.get! j)
-- program termination
β result,
implementation s = result β§
spec result","def generated_spec
-- function signature
(impl: String β Bool)
-- inputs
(s: String) : Prop :=","theorem spec_isomorphism:
β impl,
(β s, problem_spec impl s) β
(β s, generated_spec impl s) :=",sorry,def implementation (s: String) : Bool :=,sorry,"-- #test implementation ""a"" = False
-- #test implementation ""aa"" = False
-- #test implementation ""abcd"" = True
-- #test implementation ""aabb"" = False
-- #test implementation ""adb"" = True","theorem correctness
(s: String)
: problem_spec implementation s
:=","by
sorry",,,
def numerical_letter_grade(grades: list[float]) -> list[str],"It is the last week of the semester and the teacher has to give the grades
to students. The teacher has been making her own algorithm for grading.
The only problem is, she has lost the code she used for grading.
She has given you a list of GPAs for some students and you have to write
a function that can output a list of letter grades using the following table:
GPA | Letter grade
4.0 A+
> 3.7 A
> 3.3 A-
> 3.0 B+
> 2.7 B
> 2.3 B-
> 2.0 C+
> 1.7 C
> 1.3 C-
> 1.0 D+
> 0.7 D
> 0.0 D-
0.0 E
Note: I have included a hypothesis that Float is hashable, not sure if this will mess up proving attempts but we can modify it if so. Reviewer: please think if there's a better way.
Example:
grade_equation([4.0, 3, 1.7, 2, 3.5]) ==> ['A+', 'B', 'C-', 'C', 'A-']
","[{""input"": [4.0, 3, 1.7, 2, 3.5], ""output"": [""A+"", ""B"", ""C-"", ""C"", ""A-""]}]","def numerical_letter_grade(grades: list[float]) -> list[str]
""""""It is the last week of the semester and the teacher has to give the grades
to students. The teacher has been making her own algorithm for grading.
The only problem is, she has lost the code she used for grading.
She has given you a list of GPAs for some students and you have to write
a function that can output a list of letter grades using the following table:
GPA | Letter grade
4.0 A+
> 3.7 A
> 3.3 A-
> 3.0 B+
> 2.7 B
> 2.3 B-
> 2.0 C+
> 1.7 C
> 1.3 C-
> 1.0 D+
> 0.7 D
> 0.0 D-
0.0 E
Note: I have included a hypothesis that Float is hashable, not sure if this will mess up proving attempts but we can modify it if so. Reviewer: please think if there's a better way.
Example:
grade_equation([4.0, 3, 1.7, 2, 3.5]) ==> ['A+', 'B', 'C-', 'C', 'A-']
""""""","def problem_spec
-- function signature
(implementation: List Float β List String)
-- inputs
(grades: List Float) :=
-- spec
let grade_dict : List (Float Γ String) :=
[
(4.0, ""A+""),
(3.7, ""A""),
(3.3, ""A-""),
(3.0, ""B+""),
(2.7, ""B""),
(2.3, ""B-""),
(2.0, ""C+""),
(1.7, ""C""),
(1.3, ""C-""),
(1.0, ""D+""),
(0.7, ""D""),
(0.0, ""D-"")
]
let spec (result : List String) :=
grades.all (fun grade => 0.0 β€ grade β§ grade β€ 4.0) β§
result.length = grades.length β§
β i, i < grades.length β
let number_grade := grades[i]!
let number_grade_keys := grade_dict.map (fun (g, _) => g)
if 0.0 < number_grade then
β i : Nat, i < number_grade_keys.length β§
number_grade_keys[i]! β€ number_grade β§
(β k' : Nat, k' < number_grade_keys.length β number_grade_keys[k']! β€ number_grade β number_grade_keys[k']! β€ number_grade_keys[i]!) β§
result[i]! = (grade_dict[i]!).snd
else
result[i]! = ""E""
-- program termination
β result,
implementation grades = result β§
spec result","def generated_spec
-- function signature
(impl: List Float β List String)
-- inputs
(grades: List Float) : Prop :=","theorem spec_isomorphism:
β impl,
(β grades, problem_spec impl grades) β
(β grades, generated_spec impl grades) :=",sorry,def implementation (grades: List Float) : List String :=,sorry,"-- #test implementation [4.0, 3, 1.7, 2, 3.5] = ['A+', 'B', 'C-', 'C', 'A-']","theorem correctness
(grades: List Float)
: problem_spec implementation grades
:=","by
sorry",,,
def prime_length(s: str) -> bool,"Write a function that takes a string and returns True if the string
length is a prime number or False otherwise
","[{""input"": ""Hello"", ""output"": true}, {""input"": ""abcdcba"", ""output"": true}, {""input"": ""kittens"", ""output"": true}, {""input"": ""orange"", ""output"": false}]","def prime_length(s: str) -> bool
""""""Write a function that takes a string and returns True if the string
length is a prime number or False otherwise
""""""","def problem_spec
-- function signature
(implementation: String β Bool)
-- inputs
(s: String) :=
-- spec
let spec (result : Bool) :=
let is_prime (n: Nat) : Prop :=
Β¬ (β k, 2 β€ k β§ k < n β§ n % k = 0);
result β is_prime s.length
-- program termination
β result,
implementation s = result β§
spec result","def generated_spec
-- function signature
(impl: String β Bool)
-- inputs
(s: String) : Prop :=","theorem spec_isomorphism:
β impl,
(β s, problem_spec impl s) β
(β s, generated_spec impl s) :=",sorry,def implementation (s: String) : Bool :=,Nat.Prime s.length,"-- #test implementation ""Hello"" = True
-- #test implementation ""abcdcba"" = True
-- #test implementation ""kittens"" = True
-- #test implementation ""orange"" = False","theorem correctness
(s: String)
: problem_spec implementation s
:=","by
unfold problem_spec
let result := implementation s
use result
simp [result]
simp [implementation]
apply Iff.intro
intro h_is_prime
simp [Nat.prime_def] at h_is_prime
intro x h_2_le_x h_x_lt_s_len
have h_p' := h_is_prime.2 x
by_contra h_s_len_mod_x
have h_x_dvd_s_len: x β£ s.length := by
apply Nat.dvd_of_mod_eq_zero
exact h_s_len_mod_x
simp [h_x_dvd_s_len] at h_p'
have h_x_eq_s_len_false: Β¬ (x = s.length) := by
linarith
simp [h_x_eq_s_len_false] at h_p'
have h_x_ne_1: Β¬ (x = 1) := by
linarith
simp [h_x_ne_1] at h_p'
sorry",,,
def starts_one_ends(n: int) -> int,"Given a positive integer n, return the count of the numbers of n-digit
positive integers that start or end with 1.
Note: For reviewer, I believe this is the most straightforward spec, and I am relying on Set cardianlity not being computable in general. The point of this problem is really to privide a formula.
Note: But I guess a program that goes through each number and adds 1 will be the same as a program that computes in O(1) under this view.
","[{""input"": 1, ""output"": 1}, {""input"": 2, ""output"": 18}]","def starts_one_ends(n: int) -> int
""""""Given a positive integer n, return the count of the numbers of n-digit
positive integers that start or end with 1.
Note: For reviewer, I believe this is the most straightforward spec, and I am relying on Set cardianlity not being computable in general. The point of this problem is really to privide a formula.
Note: But I guess a program that goes through each number and adds 1 will be the same as a program that computes in O(1) under this view.
""""""","def problem_spec
-- function signature
(implementation: Nat β Nat)
-- inputs
(n: Nat) :=
-- spec
let spec (result : Nat) :=
0 < n β
result = {k : β | 10 ^ (n - 1) β€ k β§ k < 10 ^ n β§ (k.repr.front = '1' β¨ k.repr.back = '1')}.ncard
-- program termination
β result,
implementation n = result β§
spec result","def generated_spec
-- function signature
(impl: Nat β Nat)
-- inputs
(n: Nat) : Prop :=","theorem spec_isomorphism:
β impl,
(β n, problem_spec impl n) β
(β n, generated_spec impl n) :=",sorry,def implementation (n: Nat) : Nat :=,sorry,"-- #test implementation 1 = 1
-- #test implementation 2 = 18","theorem correctness
(n: Nat)
: problem_spec implementation n
:=","by
sorry",,,
def solve(n: int) -> str,"Given a positive integer N, return the total sum of its digits in binary.
","[{""input"": 1000, ""output"": ""1""}, {""input"": 150, ""output"": ""110""}, {""input"": 147, ""output"": ""1100""}]","def solve(n: int) -> str
""""""Given a positive integer N, return the total sum of its digits in binary.
""""""","def problem_spec
-- function signature
(implementation: Nat β String)
-- inputs
(n: Nat) :=
-- spec
let spec (result : String) :=
0 < n β
result.all (fun c => c = '0' β¨ c = '1') β
Nat.ofDigits 2 (result.data.map (fun c => if c = '0' then 0 else 1)).reverse = (Nat.digits 10 n).sum
-- program termination
β result,
implementation n = result β§
spec result","def generated_spec
-- function signature
(impl: Nat β String)
-- inputs
(n: Nat) : Prop :=","theorem spec_isomorphism:
β impl,
(β n, problem_spec impl n) β
(β n, generated_spec impl n) :=",sorry,def implementation (n: Nat) : String :=,sorry,"-- #test implementation 1000 = ""1""
-- #test implementation 150 = ""110""
-- #test implementation 147 = ""1100""","theorem correctness
(n: Nat)
: problem_spec implementation n
:=","by
sorry",,,
def solve(n: list[int]) -> int,"Given a non-empty list of integers lst, add the even elements that are at odd indices.
","[{""input"": [4, 2, 6, 7], ""output"": 2}]","def solve(n: list[int]) -> int
""""""Given a non-empty list of integers lst, add the even elements that are at odd indices.
""""""","def problem_spec
-- function signature
(implementation: List Int β Int)
-- inputs
(lst: List Int) :=
-- spec
let spec (result : Int) :=
lst.length = 0 β result = 0 β§
lst.length > 0 β
if lst.length > 1 then
result = (if Even lst[1]! then lst[1]! else 0) + implementation (lst.drop 2)
else
result = (if Even lst[1]! then lst[1]! else 0)
-- program termination
β result,
implementation lst = result β§
spec result","def generated_spec
-- function signature
(impl: List Int β Int)
-- inputs
(lst: List Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β lst, problem_spec impl lst) β
(β lst, generated_spec impl lst) :=",sorry,def implementation (lst: List Int) : Int :=,sorry,"-- #test implementation [4, 2, 6, 7] = 2","theorem correctness
(lst: List Int)
: problem_spec implementation lst
:=","by
sorry",,,
def anti_shuffle(s : str) -> str,"""""""
Write a function that takes a string and returns an ordered version of it.
Ordered version of string, is a string where all words (separated by space)
are replaced by a new word where all the characters arranged in
ascending order based on ascii value.
Note: You should keep the order of words and blank spaces in the sentence.
","[{""input"": ""Hi"", ""output"": ""Hi""}, {""input"": ""hello"", ""output"": ""ehllo""}, {""input"": ""Hello World!!!"", ""output"": ""Hello !!!Wdlor""}]","def anti_shuffle(s : str) -> str
""""""""""""
Write a function that takes a string and returns an ordered version of it.
Ordered version of string, is a string where all words (separated by space)
are replaced by a new word where all the characters arranged in
ascending order based on ascii value.
Note: You should keep the order of words and blank spaces in the sentence.
""""""","def problem_spec
-- function signature
(implementation: String β String)
-- inputs
(s: String) :=
-- spec
let spec (result : String) :=
result.length = s.length β§
let words := result.split (fun c => c = ' ');
let s_words := s.split (fun c => c = ' ');
s_words.length = words.length β§
β i, i < words.length β
words[i]!.length = s_words[i]!.length β§
((β j, j < words[i]!.length β
(words[i]!.data[j]! β s_words[i]!.data β§
s_words[i]!.data[j]! β words[i]!.data β§
words[i]!.data.count (words[i]!.data[j]!) = s_words[i]!.data.count (s_words[i]!.data[j]!))) β§
List.Sorted Nat.le (words[i]!.data.map (fun c => c.val.toNat)))
-- program termination
β result,
implementation s = result β§
spec result","def generated_spec
-- function signature
(impl: String β String)
-- inputs
(s: String) : Prop :=","theorem spec_isomorphism:
β impl,
(β s, problem_spec impl s) β
(β s, generated_spec impl s) :=",sorry,def implementation (s: String) : String :=,sorry,"-- #test implementation ""Hi"" = ""Hi""
-- #test implementation ""hello"" = ""ehllo""
-- #test implementation ""Hello World!!!"" = ""Hello !!!Wdlor""","theorem correctness
(s: String)
: problem_spec implementation s
:=","by
sorry",,,
"def get_coords_sorted(lst : list(list(int)), x : int) -> list((int, int))","You are given a 2 dimensional data, as a nested lists,
which is similar to matrix, however, unlike matrices,
each row may contain a different number of columns.
Given lst, and integer x, find integers x in the list,
and return list of tuples, [(x1, y1), (x2, y2) ...] such that
each tuple is a coordinate - (row, columns), starting with 0.
Sort coordinates initially by rows in ascending order.
Also, sort coordinates of the row by columns in descending order.
","[{""input"": [[[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 1, 6], [1, 2, 3, 4, 5, 1]], 1], ""output"": [""(0"", ""0)"", ""(1"", ""4)"", ""(1"", ""0)"", ""(2"", ""5)"", ""(2"", ""0)""]}, {""input"": [[], 1], ""output"": []}, {""input"": [[[], [1], [1, 2, 3]], 3], ""output"": [""(2"", ""2)""]}]","def get_coords_sorted(lst : list(list(int)), x : int) -> list((int, int))
""""""You are given a 2 dimensional data, as a nested lists,
which is similar to matrix, however, unlike matrices,
each row may contain a different number of columns.
Given lst, and integer x, find integers x in the list,
and return list of tuples, [(x1, y1), (x2, y2) ...] such that
each tuple is a coordinate - (row, columns), starting with 0.
Sort coordinates initially by rows in ascending order.
Also, sort coordinates of the row by columns in descending order.
""""""","def problem_spec
-- function signature
(implementation: List (List Int) β Int β List (Nat Γ Nat))
-- inputs
(lst: List (List Int))
(x: Int) :=
-- spec
let spec (result : List (Nat Γ Nat)) :=
(β i, i < result.length β
let (row, col) := result[i]!
row < lst.length β§
col < lst[row]!.length β§
(lst[row]!)[col]! = x) β§
(βα΅ (i < lst.length) (j < lst[i]!.length),
(lst[i]!)[j]! = x β (i, j) β result) β§
(result.map (fun (r, c) => r)).Sorted Nat.le β§
(β i < result.length,
let (row, col) := result[i]!
((result.filter (fun (r, c) => r = row)).map (fun (r, c) => c)).Sorted (fun a b => a β₯ b))
-- program termination
β result,
implementation lst x = result β§
spec result","def generated_spec
-- function signature
(impl: List (List Int) β Int β List (Nat Γ Nat))
-- inputs
(lst: List (List Int))
(x: Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β lst x, problem_spec impl lst x) β
(β lst x, generated_spec impl lst x) :=",sorry,def implementation (lst: List (List Int)) (x: Int) : List (Nat Γ Nat) :=,sorry,"-- #test implementation ""Hi"" = ""Hi""
-- #test implementation ""hello"" = ""ehllo""
-- #test implementation ""Hello World!!!"" = ""Hello !!!Wdlor""","theorem correctness
(lst: List (List Int))
(x: Int)
: problem_spec implementation lst x
:=","by
sorry",,,
def sort_array(lst : list(int)) -> list(int),"""""""
Given an array of non-negative integers, return a copy of the given array after sorting,
you will sort the given array in ascending order if the sum( first index value, last index value) is odd,
or sort it in descending order if the sum( first index value, last index value) is even.
Note(George): I have elected to ignore the copy part.
","[{""input"": [], ""output"": []}, {""input"": [5], ""output"": [5]}, {""input"": [2, 4, 3, 0, 1, 5], ""output"": [0, 1, 2, 3, 4, 5]}, {""input"": [2, 4, 3, 0, 1, 5, 6], ""output"": [6, 5, 4, 3, 2, 1, 0]}]","def sort_array(lst : list(int)) -> list(int)
""""""""""""
Given an array of non-negative integers, return a copy of the given array after sorting,
you will sort the given array in ascending order if the sum( first index value, last index value) is odd,
or sort it in descending order if the sum( first index value, last index value) is even.
Note(George): I have elected to ignore the copy part.
""""""","def problem_spec
-- function signature
(implementation: List Nat β List Nat)
-- inputs
(lst: List Nat) :=
-- spec
let spec (result : List Nat) :=
lst.length > 0 β
result.length = lst.length β§
(β i, i < result.length β
result[i]! β lst β§
lst[i]! β result β§
result.count (lst[i]!) = lst.count (lst[i]!)) β§
(lst.head! + lst.getLast!) β‘ 1 [MOD 2] β
result.Sorted Nat.le β§
(lst.head! + lst.getLast!) β‘ 0 [MOD 2] β
result.Sorted (fun a b => a β₯ b)
-- program termination
β result,
implementation lst = result β§
spec result","def generated_spec
-- function signature
(impl: List Nat β List Nat)
-- inputs
(lst: List Nat) : Prop :=","theorem spec_isomorphism:
β impl,
(β lst, problem_spec impl lst) β
(β lst, generated_spec impl lst) :=",sorry,def implementation (lst: List Nat) : List Nat :=,sorry,"-- #test implementation [] = []
-- #test implementation [5] = [5]
-- #test implementation [2, 4, 3, 0, 1, 5] = [0, 1, 2, 3, 4, 5]
-- #test implementation [2, 4, 3, 0, 1, 5, 6] = [6, 5, 4, 3, 2, 1, 0]","theorem correctness
(lst: List Nat)
: problem_spec implementation lst
:=","by
sorry",,,
def encrypt(str : str) -> str,"Create a function encrypt that takes a string as an argument and
returns a string encrypted with the alphabet being rotated.
The alphabet should be rotated in a manner such that the letters
shift down by two multiplied to two places.
","[{""input"": ""hi"", ""output"": ""lm""}, {""input"": ""asdfghjkl"", ""output"": ""ewhjklnop""}, {""input"": ""gf"", ""output"": ""kj""}, {""input"": ""et"", ""output"": ""ix""}]","def encrypt(str : str) -> str
""""""Create a function encrypt that takes a string as an argument and
returns a string encrypted with the alphabet being rotated.
The alphabet should be rotated in a manner such that the letters
shift down by two multiplied to two places.
""""""","def problem_spec
-- function signature
(implementation: String β String)
-- inputs
(str: String) :=
-- spec
let spec (result : String) :=
result.data.all (fun c => c.isLower) β
result.length = str.length β§
(β i, i < str.length β
let c := str.data[i]!
let c' := result.data[i]!
((c'.toNat - 97) + 2 * 2) % 26 = (c.toNat - 97))
-- program termination
β result,
implementation str = result β§
spec result","def generated_spec
-- function signature
(impl: String β String)
-- inputs
(str: String) : Prop :=","theorem spec_isomorphism:
β impl,
(β str, problem_spec impl str) β
(β str, generated_spec impl str) :=",sorry,def implementation (str: String) : String :=,sorry,"-- #test implementation ""hi"" = ""lm""
-- #test implementation ""asdfghjkl"" = ""ewhjklnop""
-- #test implementation ""gf"" = ""kj""
-- #test implementation ""et"" = ""ix""","theorem correctness
(str: String)
: problem_spec implementation str
:=","by
sorry",,,
def next_smallest(lst: List[int]) -> Optional[int],"You are given a list of integers.
Write a function next_smallest() that returns the 2nd smallest element of the list.
Return None if there is no such element.
TODO(George): Remove this when being reviewed
The spec is defined as: if result is none there is no second smallest element, which
exists in a finite list iff there are at least two distinct elements in the list.
If result is some x, then x is the second smallest element of the list, the spec
obtains the sublist of elements smaller than the result, and checks that this
sublist does not contain two distinct elements (they are all the same).
","[{""input"": [1, 2, 3, 4, 5], ""output"": 2}, {""input"": [5, 1, 4, 3, 2], ""output"": 2}, {""input"": [], ""output"": ""None""}, {""input"": [1, 1], ""output"": ""None""}]","def next_smallest(lst: List[int]) -> Optional[int]
""""""You are given a list of integers.
Write a function next_smallest() that returns the 2nd smallest element of the list.
Return None if there is no such element.
TODO(George): Remove this when being reviewed
The spec is defined as: if result is none there is no second smallest element, which
exists in a finite list iff there are at least two distinct elements in the list.
If result is some x, then x is the second smallest element of the list, the spec
obtains the sublist of elements smaller than the result, and checks that this
sublist does not contain two distinct elements (they are all the same).
""""""","def problem_spec
-- function signature
(implementation: List Int β Option Int)
-- inputs
(lst: List Int) :=
-- spec
let spec (result : Option Int) :=
match result with
| none => Β¬ (β i j, i < lst.length β§ j < lst.length β§ i β j β§ lst.get! i < lst.get! j)
| some result =>
let smaller_els := lst.filter (Β· < result);
0 < smaller_els.length β§
smaller_els.all (Ξ» x => x = smaller_els.get! 0);
-- program termination
β result,
implementation lst = result β§
spec result","def generated_spec
-- function signature
(impl: List Int β Option Int)
-- inputs
(lst: List Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β lst, problem_spec impl lst) β
(β lst, generated_spec impl lst) :=",sorry,def implementation (lst: List Int) : Option Int :=,sorry,"-- #test implementation [1, 2, 3, 4, 5] = some 2
-- #test implementation [5, 1, 4, 3, 2] = some 2
-- #test implementation [] = none
-- #test implementation [1, 1] = none","theorem correctness
(lst: List Int)
: problem_spec implementation lst
:=","by
sorry",,,
def is_bored(s: str) -> int,"You'll be given a string of words, and your task is to count the number
of boredoms. A boredom is a sentence that starts with the word ""I"".
Sentences are delimited by '.', '?' or '!'.
","[{""input"": ""Hello world"", ""expected_output"": 0}, {""input"": ""The sky is blue. The sun is shining. I love this weather"", ""expected_output"": 1}]","def is_bored(s: str) -> int
""""""You'll be given a string of words, and your task is to count the number
of boredoms. A boredom is a sentence that starts with the word ""I"".
Sentences are delimited by '.', '?' or '!'.
""""""","def problem_spec
-- function signature
(implementation: String β Nat)
-- inputs
(s: String) :=
-- spec
let spec (result : Nat) :=
let is_sentence_is_boredom (s: String) : Bool :=
(s.startsWith ""I "" β¨ s.startsWith "" I"") β§ '.' β s.data β§ '?' β s.data β§ '!' β s.data
match s.data.findIdx? (Ξ» c => c = '.' β¨ c = '?' β¨ c = '!') with
| some i =>
let j := i + 1;
let substring := s.drop j;
result = (if is_sentence_is_boredom substring then 1 else 0) + implementation substring
| none =>
result = if is_sentence_is_boredom s then 1 else 0
-- program termination
β result,
implementation s = result β§
spec result","def generated_spec
-- function signature
(impl: String β Nat)
-- inputs
(s: String) : Prop :=","theorem spec_isomorphism:
β impl,
(β s, problem_spec impl s) β
(β s, generated_spec impl s) :=",sorry,def implementation (s: String) : Nat :=,sorry,"-- #test implementation ""Hello world"" = 0
-- #test implementation ""The sky is blue. The sun is shining. I love this weather"" = 1","theorem correctness
(s: String)
: problem_spec implementation s
:=","by
sorry",,,
"def any_int(a: float, b: float, c: float) -> bool","Create a function that takes 3 numbers.
Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.
Returns false in any other cases.
","[{""input"": [5, 2, 7], ""expected_output"": true}, {""input"": [3, 2, 2], ""expected_output"": false}, {""input"": [3, -2, 1], ""expected_output"": true}, {""input"": [3.6, -2.2, 2], ""expected_output"": false}]","def any_int(a: float, b: float, c: float) -> bool
""""""Create a function that takes 3 numbers.
Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.
Returns false in any other cases.
""""""","def problem_spec
-- function signature
(implementation: Rat β Rat β Rat β Bool)
-- inputs
(a: Rat) (b: Rat) (c: Rat) :=
-- spec
let spec (result : Bool) :=
let nums := [a, b, c];
result = true β β i j k : β, {i, j, k} β ({0, 1, 2} : Set β) β§ i β j β§ j β k β§ k β i β§ (nums[i]! + nums[j]! = nums[k]!) β§ a.den = 1 β§ a.den = b.den β§ a.den = c.den
-- program termination
β result,
implementation a b c = result β§
spec result","def generated_spec
-- function signature
(impl: Rat β Rat β Rat β Bool)
-- inputs
(a: Rat) (b: Rat) (c: Rat) : Prop :=","theorem spec_isomorphism:
β impl,
(β a b c, problem_spec impl a b c) β
(β a b c, generated_spec impl a b c) :=",sorry,def implementation (a: Rat) (b: Rat) (c: Rat) : Bool :=,sorry,"-- #test implementation 5 2 7 = true
-- #test implementation 3 2 2 = false
-- #test implementation 3 (-2) 1 = true
-- #test implementation 3.6 (-2.2) 2 = false","theorem correctness
(a: Rat) (b: Rat) (c: Rat)
: problem_spec implementation a b c
:=","by
sorry",,,
def encode(s : str) -> str,"Write a function that takes a message, and encodes in such a
way that it swaps case of all letters, replaces all vowels in
the message with the letter that appears 2 places ahead of that
vowel in the english alphabet.
Assume only letters.
","[{""input"": ""test"", ""expected_output"": ""TGST""}, {""input"": ""This is a message"", ""expected_output"": ""tHKS KS C MGSSCGG""}]","def encode(s : str) -> str
""""""Write a function that takes a message, and encodes in such a
way that it swaps case of all letters, replaces all vowels in
the message with the letter that appears 2 places ahead of that
vowel in the english alphabet.
Assume only letters.
""""""","def problem_spec
-- function signature
(implementation: String β String)
-- inputs
(s: String) :=
-- spec
let spec (result : String) :=
s.data.all (Ξ» c => c.isAlpha) β
result.length = s.length β§
(β i, i < s.length β
let c := s.data.get! i;
let c' := result.data.get! i;
match c with
| 'a' | 'e' | 'i' | 'o' | 'u' | 'A' | 'E' | 'I' | 'O' | 'U' =>
c.isUpper β c'.val = c.toLower.val + 2 β§
c.isLower β c'.val = c.toUpper.val + 2
| _ =>
c.isUpper β c' = c.toLower β§
c.isLower β c' = c.toUpper)
-- program termination
β result,
implementation s = result β§
spec result","def generated_spec
-- function signature
(impl: String β String)
-- inputs
(s: String) : Prop :=","theorem spec_isomorphism:
β impl,
(β s, problem_spec impl s) β
(β s, generated_spec impl s) :=",sorry,def implementation (s: String) : String :=,sorry,"-- #test implementation ""test"" = ""TGST""
-- #test implementation ""This is a message"" = ""tHKS KS C MGSSCGG""","theorem correctness
(s: String)
: problem_spec implementation s
:=","by
sorry",,,
def sum_largest_prime(lst : list[int]) -> int,"You are given a list of integers.
You need to find the largest prime value and return the sum of its digits.
Note(George): Modified to use List of nats because all examples are nats.
","[{""input"": [0, 3, 2, 1, 3, 5, 7, 4, 5, 5, 5, 2, 181, 32, 4, 32, 3, 2, 32, 324, 4, 3], ""expected_output"": 10}, {""input"": [1, 0, 1, 8, 2, 4597, 2, 1, 3, 40, 1, 2, 1, 2, 4, 2, 5, 1], ""expected_output"": 25}, {""input"": [1, 3, 1, 32, 5107, 34, 83278, 109, 163, 23, 2323, 32, 30, 1, 9, 3], ""expected_output"": 13}, {""input"": [0, 724, 32, 71, 99, 32, 6, 0, 5, 91, 83, 0, 5, 6], ""expected_output"": 11}, {""input"": [0, 81, 12, 3, 1, 21], ""expected_output"": 3}, {""input"": [0, 8, 1, 2, 1, 7], ""expected_output"": 7}]","def sum_largest_prime(lst : list[int]) -> int
""""""You are given a list of integers.
You need to find the largest prime value and return the sum of its digits.
Note(George): Modified to use List of nats because all examples are nats.
""""""","def problem_spec
-- function signature
(implementation: List Nat β Nat)
-- inputs
(lst: List Nat) :=
-- spec
let spec (result : Nat) :=
lst.any (fun num => Nat.Prime num) β
result > 0 β§ β i, i < lst.length β§ Prime (lst.get! i) β§
(β j, j < lst.length β§ Prime (lst.get! j) β lst.get! i β€ lst.get! j) β§
result = (Nat.digits 10 (lst.get! i)).sum
-- program termination
β result,
implementation lst = result β§
spec result","def generated_spec
-- function signature
(impl: List Nat β Nat)
-- inputs
(lst: List Nat) : Prop :=","theorem spec_isomorphism:
β impl,
(β lst, problem_spec impl lst) β
(β lst, generated_spec impl lst) :=",sorry,def implementation (lst: List Nat) : Nat :=,sorry,"-- #test implementation [0,3,2,1,3,5,7,4,5,5,5,2,181,32,4,32,3,2,32,324,4,3] = 10
-- #test implementation [1,0,1,8,2,4597,2,1,3,40,1,2,1,2,4,2,5,1] = 25
-- #test implementation [1,3,1,32,5107,34,83278,109,163,23,2323,32,30,1,9,3] = 13
-- #test implementation [0,724,32,71,99,32,6,0,5,91,83,0,5,6] = 11
-- #test implementation [0,81,12,3,1,21] = 3
-- #test implementation [0,8,1,2,1,7] = 7","theorem correctness
(lst: List Nat)
: problem_spec implementation lst
:=","by
sorry",,,
"def check_dict_case(s : dict[str, str]) -> bool","Given a dictionary, return True if all keys are strings in lower
case or all keys are strings in upper case, else return False.
The function should return False is the given dictionary is empty.
Note(George): Modified the problem to use strings only for both keys and values.
","[{""input"": {""a"": ""apple"", ""b"": ""banana""}, ""expected_output"": true}, {""input"": {""a"": ""apple"", ""A"": ""banana"", ""B"": ""banana""}, ""expected_output"": false}, {""input"": {""a"": ""apple"", ""b"": ""banana""}, ""expected_output"": false}, {""input"": {""Name"": ""John"", ""Age"": ""36"", ""City"": ""Houston""}, ""expected_output"": false}, {""input"": {""STATE"": ""NC"", ""ZIP"": ""12345""}, ""expected_output"": true}]","def check_dict_case(s : dict[str, str]) -> bool
""""""Given a dictionary, return True if all keys are strings in lower
case or all keys are strings in upper case, else return False.
The function should return False is the given dictionary is empty.
Note(George): Modified the problem to use strings only for both keys and values.
""""""","def problem_spec
-- function signature
(implementation: Std.HashMap String String β Bool)
-- inputs
(D: Std.HashMap String String) :=
-- spec
let spec (result : Bool) :=
match D.isEmpty with
| true => result = false
| false =>
let keys := D.keys
let all_lower := keys.all (fun s => s.toLower = s)
let all_upper := keys.all (fun s => s.toUpper = s)
result = true β all_lower || all_upper
-- program termination
β result,
implementation D = result β§
spec result","def generated_spec
-- function signature
(impl: Std.HashMap String String β Bool)
-- inputs
(D: Std.HashMap String String) : Prop :=","theorem spec_isomorphism:
β impl,
(β D, problem_spec impl D) β
(β D, generated_spec impl D) :=",sorry,def implementation (D: Std.HashMap String String) : Bool :=,sorry,"-- #test implementation (Std.HashMap.ofList [(""a"", ""apple""), (""b"", ""banana"")]) = true
-- #test implementation (Std.HashMap.ofList [(""a"", ""apple""), (""A"", ""banana""), (""B"", ""banana"")]) = false
-- #test implementation (Std.HashMap.ofList [(""a"", ""apple""), (""b"", ""banana""), (""a"", ""apple"")]) = false
-- #test implementation (Std.HashMap.ofList [(""Name"", ""John""), (""Age"", ""36""), (""City"", ""Houston"")]) = false
-- #test implementation (Std.HashMap.ofList [(""STATE"", ""NC""), (""ZIP"", ""12345"")]) = true","theorem correctness
(D: Std.HashMap String String)
: problem_spec implementation D
:=","by
sorry",,,
def count_up_to(n : int) -> list[int],"Implement a function that takes an non-negative integer and returns an array of the first n
integers that are prime numbers and less than n.
","[{""input"": 5, ""expected_output"": [2, 3]}, {""input"": 11, ""expected_output"": [2, 3, 5, 7]}, {""input"": 0, ""expected_output"": []}, {""input"": 20, ""expected_output"": [2, 3, 5, 7, 11, 13, 17, 19]}, {""input"": 1, ""expected_output"": []}, {""input"": 18, ""expected_output"": [2, 3, 5, 7, 11, 13, 17]}]","def count_up_to(n : int) -> list[int]
""""""Implement a function that takes an non-negative integer and returns an array of the first n
integers that are prime numbers and less than n.
""""""","def problem_spec
-- function signature
(implementation: Nat β List Nat)
-- inputs
(n: Nat) :=
-- spec
let spec (result : List Nat) :=
match n with
| 0 => result = []
| n => n > 0 β (β i, i < result.length β (Nat.Prime (result.get! i)) β§ (result.get! i) < n) β§
(β i : Nat, i < n β Nat.Prime i β i β result)
-- program termination
β result,
implementation n = result β§
spec result","def generated_spec
-- function signature
(impl: Nat β List Nat)
-- inputs
(n: Nat) : Prop :=","theorem spec_isomorphism:
β impl,
(β n, problem_spec impl n) β
(β n, generated_spec impl n) :=",sorry,def implementation (n: Nat) : List Nat :=,sorry,"-- #test implementation 5 = [2,3]
-- #test implementation 11 = [2,3,5,7]
-- #test implementation 0 = []
-- #test implementation 20 = [2,3,5,7,11,13,17,19]
-- #test implementation 1 = []
-- #test implementation 18 = [2,3,5,7,11,13,17]","theorem correctness
(n: Nat)
: problem_spec implementation n
:=","by
sorry",,,
"def multiply(a : Int, b : Int) -> Int","Complete the function that takes two integers and returns
the product of their unit digits.
Assume the input is always valid.
-- Note(George): I'm finding it hard to not leak the implementation here, so I opted to make the spec more convoluted.
","[{""input"": ""148, 412"", ""expected_output"": 16}, {""input"": ""19, 28"", ""expected_output"": 72}, {""input"": ""2020, 1851"", ""expected_output"": 0}, {""input"": ""14, -15"", ""expected_output"": 20}]","def multiply(a : Int, b : Int) -> Int
""""""Complete the function that takes two integers and returns
the product of their unit digits.
Assume the input is always valid.
-- Note(George): I'm finding it hard to not leak the implementation here, so I opted to make the spec more convoluted.
""""""","def problem_spec
-- function signature
(implementation: Int β Int β Int)
-- inputs
(a b: Int) :=
-- spec
let spec (result : Int) :=
|result| β€ 81 β§
result % 10 = (a * b) % 10 β§
((b%10) β 0 β (result % (b%10) = 0 β§ (result/ (b%10)) % 100 = (a%10))) β§
((a%10) β 0 β (result % (a%10) = 0 β§ (result/ (a%10)) % 100 = (b%10))) β§
((a%10 = 0) β¨ (b%10 = 0) β result = 0)
-- program termination
β result,
implementation a b = result β§
spec result","def generated_spec
-- function signature
(impl: Int β Int β Int)
-- inputs
(a b: Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β a b, problem_spec impl a b) β
(β a b, generated_spec impl a b) :=",sorry,def implementation (a b: Int) : Int :=,sorry,"-- #test implementation 148 412 = 16
-- #test implementation 19 28 = 72
-- #test implementation 2020 1851 = 0
-- #test implementation 14 -15 = 20","theorem correctness
(a b: Int)
: problem_spec implementation a b
:=","by
sorry",,,
def count_upper(s : String) -> Int,"Given a string s, count the number of uppercase vowels in even indices.
-- Note(George): I also feel like this one is hard to not leak, I tried a trick about keeping implementation for a recursive call in the spec. Let me know if this doesn't work..
","[{""input"": ""aBCdEf"", ""expected_output"": 1}, {""input"": ""abcdefg"", ""expected_output"": 0}, {""input"": ""dBBE"", ""expected_output"": 0}]","def count_upper(s : String) -> Int
""""""Given a string s, count the number of uppercase vowels in even indices.
-- Note(George): I also feel like this one is hard to not leak, I tried a trick about keeping implementation for a recursive call in the spec. Let me know if this doesn't work..
""""""","def problem_spec
-- function signature
(implementation: String β Int)
-- inputs
(s: String) :=
-- spec
let uppercase_vowels := ['A', 'E', 'I', 'O', 'U']
let spec (result : Int) :=
let chars := s.toList
(result = 0 β β i, i < chars.length β chars[i]! β uppercase_vowels) β§
(1 < chars.length β
(result - 1 = implementation (chars.drop 2).toString β chars[0]! β uppercase_vowels) β¨
(result = implementation (chars.drop 2).toString β chars[0]! β uppercase_vowels)
)
-- program termination
β result,
implementation s = result β§
spec result","def generated_spec
-- function signature
(impl: String β Int)
-- inputs
(s: String) : Prop :=","theorem spec_isomorphism:
β impl,
(β s, problem_spec impl s) β
(β s, generated_spec impl s) :=",sorry,def implementation (s: String) : Int :=,sorry,"-- #test implementation ""aBCdEf"" = 1
-- #test implementation ""abcdefg"" = 0
-- #test implementation ""dBBE"" = 0","theorem correctness
(s: String)
: problem_spec implementation s
:=","by
sorry",,,
def closest_integer(s : String) -> Option Int,"Create a function that takes a value (string) representing a number
and returns the closest integer to it. If the number is equidistant
from two integers, round it away from zero.
","[{""input"": ""10"", ""expected_output"": 10}, {""input"": ""15.3"", ""expected_output"": 15}]","def closest_integer(s : String) -> Option Int
""""""Create a function that takes a value (string) representing a number
and returns the closest integer to it. If the number is equidistant
from two integers, round it away from zero.
""""""","def problem_spec
-- function signature
(implementation: String β Option Int)
-- inputs
(s: String) :=
-- spec
let numeric_characters := [""-"", ""0"", ""1"", ""2"", ""3"", ""4"", ""5"", ""6"", ""7"", ""8"", ""9"", "".""]
let is_valid_string :=
s.length > 0 β§
s.count (""."".get! 0) β€ 1 β§
s.count (""-"".get! 0) β€ 1 β§
s.data.all (fun c => numeric_characters.contains (String.mk [c])) β§
(s.count (""-"".get! 0) = 1 β s.data.head! = '-')
let spec (result : Option Int) := match result with
| some result =>
is_valid_string β§
let parts := s.split (fun c => c = '.')
(parts.length = 1 β result = s.toInt!) β§
(parts.length = 2 β
let integer_part := parts.get! 0
let is_negative := s.data.head! = '-'
|((integer_part.toInt! - result) : β)| β€ 0.5 β§
(is_negative β |((integer_part.toInt! - result) : β)| = 0.5 β integer_part.toInt? < result) β§
(Β¬is_negative β |((integer_part.toInt! - result) : β)| = 0.5 β integer_part.toInt? > result)
)
| none => Β¬ is_valid_string
-- program termination
β result,
implementation s = result β§
spec result","def generated_spec
-- function signature
(impl: String β Option Int)
-- inputs
(s: String) : Prop :=","theorem spec_isomorphism:
β impl,
(β s, problem_spec impl s) β
(β s, generated_spec impl s) :=",sorry,def implementation (s: String) : Option Int :=,sorry,"-- #test implementation ""10"" = some 10
-- #test implementation ""15.3"" = some 15","theorem correctness
(s: String)
: problem_spec implementation s
:=","by
sorry",,,
def make_a_pile(n: int) -> List[int],"Given a positive integer n, you have to make a pile of n levels of stones.
The first level has n stones.
The number of stones in the next level is:
- the next odd number if n is odd.
- the next even number if n is even.
Return the number of stones in each level in a list, where element at index
i represents the number of stones in the level (i+1).
","[{""input"": 3, ""expected_output"": [3, 5, 7]}]","def make_a_pile(n: int) -> List[int]
""""""Given a positive integer n, you have to make a pile of n levels of stones.
The first level has n stones.
The number of stones in the next level is:
- the next odd number if n is odd.
- the next even number if n is even.
Return the number of stones in each level in a list, where element at index
i represents the number of stones in the level (i+1).
""""""","def problem_spec
-- function signature
(implementation: Int β List Int)
-- inputs
(n: Int) :=
-- spec
let spec (result: List Int) :=
result.length = n β§
(forall i: Nat, (1 <= i β§ i < n) β (result[i]! = result[i-1]! + 2)) β§
result[0]! = n
-- program termination
β result, implementation n = result β§
spec result","def generated_spec
-- function signature
(impl: Int β List Int)
-- inputs
(n: Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β n, problem_spec impl n) β
(β n, generated_spec impl n) :=",sorry,def implementation (n: Int) : List Int :=,sorry,"-- #test implementation 3 = [3, 5, 7]
-- #test implementation 4 = [4,6,8,10]
-- #test implementation 5 = [5, 7, 9, 11, 13]
-- #test implementation 6 = [6, 8, 10, 12, 14, 16]
-- #test implementation 8 = [8, 10, 12, 14, 16, 18, 20, 22]","theorem correctness
(n: Int)
: problem_spec implementation n
:=","by
sorry",,,
def words_string(s: string) -> List[string],"You will be given a string of words separated by commas or spaces. Your task is
to split the string into words and return an array of the words.
","[{""input"": ""Hi, my name is John"", ""expected_output"": [""Hi"", ""my"", ""name"", ""is"", ""John""]}, {""input"": ""One, two, three, four, five, six"", ""expected_output"": [""One"", ""two"", ""three"", ""four"", ""five"", ""six""]}]","def words_string(s: string) -> List[string]
""""""You will be given a string of words separated by commas or spaces. Your task is
to split the string into words and return an array of the words.
""""""","def problem_spec
-- function signature
(implementation: String β List String)
-- inputs
(s: String) :=
-- spec
let spec (result: List String) :=
let chars := s.toList;
let first := s.takeWhile (fun c => c β ',' β§ c β ' ');
(result = [] β (β x β chars, x = ' ' β¨ x = ',') β¨ s = """") β§
(result β [] β result = [first] ++ (implementation (s.drop (first.length + 1))))
-- program termination
β result, implementation s = result β§
spec result","def generated_spec
-- function signature
(impl: String β List String)
-- inputs
(s: String) : Prop :=","theorem spec_isomorphism:
β impl,
(β s, problem_spec impl s) β
(β s, generated_spec impl s) :=",sorry,def implementation (s: String) : List String :=,"List.map (fun s => (s.toList.filter (fun c => c != ',')).asString) ((s.splitOn).filter (fun s => s != """" β§ s != "",""))","-- #test implementation ""Hi, my name is John"" = [""Hi"", ""my"", ""name"", ""is"", ""John""]
-- #test implementation ""One, two, three, four, five, six"" = [""One"", ""two"", ""three"", ""four"", ""five"", ""six""]
-- #test implementation ""Hi, my name"" = [""Hi"", ""my"", ""name""]
-- #test implementation ""One,, two, three, four, five, six,"" = [""One"", ""two"", ""three"", ""four"", ""five"", ""six""]
-- #test implementation """" = []
-- #test implementation ""ahmed , gamal"" = [""ahmed"", ""gamal""]","theorem correctness
(s: String)
: problem_spec implementation s
:=","by
sorry",,,
"def choose_num(x: int, y: int) -> int","This function takes two positive numbers x and y and returns the
biggest even integer number that is in the range [x, y] inclusive. If
there's no such number, then the function should return -1.
","[{""input"": ""(12, 15)"", ""expected_output"": 14}, {""input"": ""(13, 12)"", ""expected_output"": -1}]","def choose_num(x: int, y: int) -> int
""""""This function takes two positive numbers x and y and returns the
biggest even integer number that is in the range [x, y] inclusive. If
there's no such number, then the function should return -1.
""""""","def problem_spec
-- function signature
(implementation: Int β Int β Int)
-- inputs
(x: Int) (y: Int) :=
-- spec
let spec (result: Int) :=
(result = -1 β¨ (x β€ result β§ result β€ y β§ Even result)) β§
(result = -1 β¨ (forall i: Int, (x β€ i β§ i β€ y β§ Even i) β result β₯ i)) β§
(result = -1 β (x > y β¨ (x == y β§ Odd x β§ Odd y)))
-- program termination
β result, implementation x y = result β§
spec result","def generated_spec
-- function signature
(impl: Int β Int β Int)
-- inputs
(x: Int) (y: Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β x y, problem_spec impl x y) β
(β x y, generated_spec impl x y) :=",sorry,def implementation (x: Int) (y: Int) : Int :=,sorry,"-- #test implementation 12 15 = 14
-- #test implementation 13 12 = -1
-- #test implementation 33 12354 = 12354
-- #test implementation 5234 5233 = -1
-- #test implementation 6 29 = 28
-- #test implementation 27 10 = (-1)
-- #test implementation 7 7 = -1
-- #test implementation 546 546 = 546","theorem correctness
(x: Int) (y: Int)
: problem_spec implementation x y
:=","by
sorry",,,
"def rounded_avg(n: nat, m: nat) -> Option[string]","You are given two positive integers n and m, and your task is to compute the
average of the integers from n through m (including n and m).
Round the answer to the nearest integer and convert that to binary.
If n is greater than m, return none.
","[{""input"": ""(1, 5)"", ""expected_output"": ""0b11""}, {""input"": ""(7, 5)"", ""expected_output"": ""None""}, {""input"": ""(10, 20)"", ""expected_output"": ""0b1111""}, {""input"": ""(20, 33)"", ""expected_output"": ""0b11010""}]","def rounded_avg(n: nat, m: nat) -> Option[string]
""""""You are given two positive integers n and m, and your task is to compute the
average of the integers from n through m (including n and m).
Round the answer to the nearest integer and convert that to binary.
If n is greater than m, return none.
""""""","def problem_spec
-- function signature
(implementation: Nat β Nat β Option String)
-- inputs
(n: Nat) (m: Nat) :=
-- spec
let spec (result: Option String) :=
(n > m β result.isNone) β§
(n β€ m β result.isSome) β§
(n β€ m β
(result.isSome β§
let val := Option.getD result """";
let xs := List.Ico n (m+1);
let avg := xs.sum / xs.length;
(val.take 2 = ""0b"") β§
(Nat.ofDigits 2 ((val.drop 2).toList.map (fun c => c.toNat - '0'.toNat)).reverse = avg)))
-- program termination
β result, implementation n m = result β§
spec result","def generated_spec
-- function signature
(impl: Nat β Nat β Option String)
-- inputs
(n: Nat) (m: Nat) : Prop :=","theorem spec_isomorphism:
β impl,
(β n m, problem_spec impl n m) β
(β n m, generated_spec impl n m) :=",sorry,def implementation (n: Nat) (m: Nat) : Option String :=,"if n > m then
none
else
let xs := List.Ico n (m+1);
let avg := xs.sum / xs.length;
some (""0b"" ++ (Nat.toDigits 2 avg).asString)","-- #test implementation 1 5 = some ""0b11""
-- #test implementation 7 13 = some ""0b1010""
-- #test implementation 964 977 = some ""0b1111001010""
-- #test implementation 996 997 = some ""0b1111100100""
-- #test implementation 185 546 = some ""0b101101110""
-- #test implementation 362 496 = some ""0b110101101""
-- #test implementation 350 902 = some ""0b1001110010""
-- #test implementation 197 233 = some ""0b11010111""
-- #test implementation 7 5 = none
-- #test implementation 5 1 = none
-- #test implementation 5 5 = some ""0b101""","theorem correctness
(n: Nat) (m: Nat)
: problem_spec implementation n m
:=","by
sorry",,,
def unique_digits(x: List[nat]) -> List[nat],"Given a list of positive integers x. return a sorted list of all
elements that hasn't any even digit.
Note: Returned list should be sorted in increasing order.
","[{""input"": [15, 33, 1422, 1], ""expected_output"": [1, 15, 33]}, {""input"": [152, 323, 1422, 10], ""expected_output"": []}]","def unique_digits(x: List[nat]) -> List[nat]
""""""Given a list of positive integers x. return a sorted list of all
elements that hasn't any even digit.
Note: Returned list should be sorted in increasing order.
""""""","def problem_spec
-- function signature
(implementation: List Nat β List Nat)
-- inputs
(x: List Nat) :=
-- spec
let spec (result: List Nat) :=
let has_even_digits(i: Nat): Bool :=
(List.filter (fun d => Even d) (Nat.digits 10 i)).length > 0;
(List.Sorted Nat.le result) β§
(forall i, i β result β (i β x β§ !(has_even_digits i)))
-- program termination
β result, implementation x = result β§
spec result","def generated_spec
-- function signature
(impl: List Nat β List Nat)
-- inputs
(x: List Nat) : Prop :=","theorem spec_isomorphism:
β impl,
(β x, problem_spec impl x) β
(β x, generated_spec impl x) :=",sorry,def implementation (x: List Nat) : List Nat :=,sorry,"-- #test implementation [15, 33, 1422, 1] = [1, 15, 33]
-- #test implementation [152, 323, 1422, 10] = []
-- #test implementation [12345, 2033, 111, 151] = [111, 151]
-- #test implementation [135, 103, 31] = [31, 135]","theorem correctness
(x: List Nat)
: problem_spec implementation x
:=","by
sorry",,,
def by_length(arr: List[int]) -> List[string],"Given an array of integers, sort the integers that are between 1 and 9 inclusive,
reverse the resulting array, and then replace each digit by its corresponding name from
""One"", ""Two"", ""Three"", ""Four"", ""Five"", ""Six"", ""Seven"", ""Eight"", ""Nine"".
","[{""input"": [2, 1, 1, 4, 5, 8, 2, 3], ""expected_output"": [""Eight"", ""Five"", ""Four"", ""Three"", ""Two"", ""Two"", ""One"", ""One""]}, {""input"": [], ""expected_output"": []}, {""input"": [1, -1, 55], ""expected_output"": [""One""]}]","def by_length(arr: List[int]) -> List[string]
""""""Given an array of integers, sort the integers that are between 1 and 9 inclusive,
reverse the resulting array, and then replace each digit by its corresponding name from
""One"", ""Two"", ""Three"", ""Four"", ""Five"", ""Six"", ""Seven"", ""Eight"", ""Nine"".
""""""","def problem_spec
-- function signature
(implementation: List Int β List String)
-- inputs
(arr: List Int) :=
-- spec
let spec (result: List String) :=
let digits: List String := [""One"", ""Two"", ""Three"", ""Four"", ""Five"", ""Six"", ""Seven"", ""Eight"", ""Nine""];
(forall s: String, (s β result β s β digits)) β§
(arr.length β₯ result.length) β§
(forall x: Nat, ((x: Int) β arr β§ 1 β€ x β§ x β€ 9) β (digits[x-1]! β result)) β§
(List.Sorted Int.le (List.map (fun (s: String) => (List.indexOf s digits) + 1) result).reverse)
-- program termination
β result, implementation arr = result β§
spec result","def generated_spec
-- function signature
(impl: List Int β List String)
-- inputs
(arr: List Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β arr, problem_spec impl arr) β
(β arr, generated_spec impl arr) :=",sorry,def implementation (arr: List Int) : List String :=,sorry,"-- #test implementation [2, 1, 1, 4, 5, 8, 2, 3] = [""Eight"", ""Five"", ""Four"", ""Three"", ""Two"", ""Two"", ""One"", ""One""]
-- #test implementation [] = []
-- #test implementation [1, -1 , 55] = [""One""]
-- #test implementation [1, -1, 3, 2] = [""Three"", ""Two"", ""One""]
-- #test implementation [9, 4, 8] = [""Nine"", ""Eight"", ""Four""]","theorem correctness
(arr: List Int)
: problem_spec implementation arr
:=","by
sorry",,,
def f(n: int) -> List[int],"Implement the function f that takes n as a parameter,
and returns a list of size n, such that the value of the element at index i is the factorial of i if i is even
or the sum of numbers from 1 to i otherwise.
i starts from 1.
the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).
","[{""input"": 5, ""expected_output"": [1, 2, 6, 24, 15]}]","def f(n: int) -> List[int]
""""""Implement the function f that takes n as a parameter,
and returns a list of size n, such that the value of the element at index i is the factorial of i if i is even
or the sum of numbers from 1 to i otherwise.
i starts from 1.
the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).
""""""","def problem_spec
-- function signature
(implementation: Int β List Int)
-- inputs
(n: Int) :=
-- spec
let spec (result: List Int) :=
(result.length = n) β§
(forall i: Nat, (1 β€ i β§ i β€ n β§ Even i) β (result[i-1]! = Nat.factorial i)) β§
(forall i: Nat, (1 β€ i β§ i β€ n β§ Odd i) β (result[i-1]! = (List.range (i+1)).sum))
-- program termination
β result, implementation n = result β§
spec result","def generated_spec
-- function signature
(impl: Int β List Int)
-- inputs
(n: Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β n, problem_spec impl n) β
(β n, generated_spec impl n) :=",sorry,def implementation (n: Int) : List Int :=,sorry,"-- #test implementation 5 = [1, 2, 6, 24, 15]
-- #test implementation 7 = [1, 2, 6, 24, 15, 720, 28]
-- #test implementation 1 = [1]
-- #test implementation 3 = [1, 2, 6]","theorem correctness
(n: Int)
: problem_spec implementation n
:=","by
sorry",,,
"def even_odd_palindrome(n: nat) -> (nat, nat)","Given a positive integer n, return a tuple that has the number of even and odd
integer palindromes that fall within the range(1, n), inclusive.
","[{""input"": 3, ""expected_output"": ""(1, 2)""}, {""input"": 12, ""expected_output"": ""(4, 6)""}]","def even_odd_palindrome(n: nat) -> (nat, nat)
""""""Given a positive integer n, return a tuple that has the number of even and odd
integer palindromes that fall within the range(1, n), inclusive.
""""""","def problem_spec
-- function signature
(implementation: Nat β Nat Γ Nat)
-- inputs
(n: Nat) :=
-- spec
let spec (result: Nat Γ Nat) :=
let is_palindrome (k: Nat): Prop :=
List.Palindrome (Nat.digits 10 k);
let even_palindrome (k: Nat): Prop :=
(Even k) β§ (is_palindrome k);
let odd_palindrome (k: Nat): Prop :=
(Odd k) β§ (is_palindrome k);
n > 0 β
(1 < n β
let impl_n_minus_1 := implementation (n - 1);
((even_palindrome n) β result.1 = 1 + impl_n_minus_1.1) β§
((odd_palindrome n) β result.2 = 1 + impl_n_minus_1.2) β§
(Β¬ (odd_palindrome n) β result.2 = impl_n_minus_1.2) β§
(Β¬ (even_palindrome n) β result.1 = impl_n_minus_1.1))
β§
(n = 1 β (result.1 = 0) β§ (result.2 = 1));
-- program termination
β result, implementation n = result β§
spec result","def generated_spec
-- function signature
(impl: Nat β Nat Γ Nat)
-- inputs
(n: Nat) : Prop :=","theorem spec_isomorphism:
β impl,
(β n, problem_spec impl n) β
(β n, generated_spec impl n) :=",sorry,def implementation (n: Nat) : Nat Γ Nat :=,sorry,"-- #test implementation 123 = (8, 13)
-- #test implementation 12 = (4, 6)
-- #test implementation 3 = (1, 2)
-- #test implementation 63 = (6, 8)
-- #test implementation 25 = (5, 6)
-- #test implementation 19 = (4, 6)
-- #test implementation 9 = (4, 5)","theorem correctness
(n: Nat)
: problem_spec implementation n
:=","by
sorry",,,
def count_nums(arr: List[int]) -> int,"Write a function count_nums which takes an array of integers and returns
the number of elements which has a sum of digits > 0.
If a number is negative, then its first signed digit will be negative:
e.g. -123 has signed digits -1, 2, and 3.
","[{""input"": [], ""expected_output"": 0}, {""input"": [-1, 11, -11], ""expected_output"": 1}, {""input"": [1, 1, 2], ""expected_output"": 3}]","def count_nums(arr: List[int]) -> int
""""""Write a function count_nums which takes an array of integers and returns
the number of elements which has a sum of digits > 0.
If a number is negative, then its first signed digit will be negative:
e.g. -123 has signed digits -1, 2, and 3.
""""""","def problem_spec
-- function signature
(implementation: List Int β Int)
-- inputs
(arr: List Int) :=
-- spec
let spec (result: Int) :=
let dig_sum (x: Int): Int :=
let digs := x.natAbs.digits 10;
if x >= 0 then
(List.map (fun t => (t: Int)) digs).sum
else
(List.map (fun t => (t: Int)) (digs.drop 1)).sum - (digs[0]! : Int);
(arr = [] β result = 0) β§
(arr β [] β 0 < (dig_sum arr[0]!) β result = 1 + implementation (arr.drop 1)) β§
(arr β [] β (dig_sum arr[0]!) β€ 0 β result = implementation (arr.drop 1));
-- program termination
β result, implementation arr = result β§
spec result","def generated_spec
-- function signature
(impl: List Int β Int)
-- inputs
(arr: List Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β arr, problem_spec impl arr) β
(β arr, generated_spec impl arr) :=",sorry,def implementation (arr: List Int) : Int :=,"let signed_digits(x: Int): List Int :=
let x': Nat := Int.natAbs x;
let xs: List Nat := Nat.digits 10 x';
if x >= 0 then
xs
else
(-Int.ofNat (xs[0]!)) :: xs.tail;
((List.map (fun (x: Int) => (signed_digits x).sum) arr).filter (fun (x: Int) => x > 0)).length","-- #test implementation [] = 0
-- #test implementation [-1, -2, 0] = 0
-- #test implementation [1, 1, 2, -2, 3, 4, 5] = 6
-- #test implementation [1, 6, 9, -6, 0, 1, 5] = 5
-- #test implementation [1, 100, 98, -7, 1, -1] = 4
-- #test implementation [12, 23, 34, -45, -56, 0] = 5
-- #test implementation [-0, 1^0] = 1
-- #test implementation [1] = 1","theorem correctness
(arr: List Int)
: problem_spec implementation arr
:=","by
sorry",,,
def move_one_ball(arr: List[int]) -> bool,"We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The
numbers in the array will be randomly ordered. Your task is to determine if
it is possible to get an array sorted in non-decreasing order by performing
the following operation on the given array:
You are allowed to perform right shift operation any number of times.
One right shift operation means shifting all elements of the array by one
position in the right direction. The last element of the array will be moved to
the starting position in the array i.e. 0th index.
If it is possible to obtain the sorted array by performing the above operation
then return True else return False.
If the given array is empty then return True.
Note: The given list is guaranteed to have unique elements.
","[{""input"": [3, 4, 5, 1, 2], ""expected_output"": true}, {""input"": [3, 5, 4, 1, 2], ""expected_output"": false}]","def move_one_ball(arr: List[int]) -> bool
""""""We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The
numbers in the array will be randomly ordered. Your task is to determine if
it is possible to get an array sorted in non-decreasing order by performing
the following operation on the given array:
You are allowed to perform right shift operation any number of times.
One right shift operation means shifting all elements of the array by one
position in the right direction. The last element of the array will be moved to
the starting position in the array i.e. 0th index.
If it is possible to obtain the sorted array by performing the above operation
then return True else return False.
If the given array is empty then return True.
Note: The given list is guaranteed to have unique elements.
""""""","def problem_spec
-- function signature
(implementation: List Int β Bool)
-- inputs
(arr: List Int) :=
let is_shifted (xs: List Int) (ys: List Int) (i: Nat) :=
(xs.length = ys.length) β§
(0 <= i) β§
(i < xs.length) β§
(forall j, (0 <= j β§ j < ys.length) β (ys[j]! = xs[(j-i) % xs.length]!))
-- spec
let spec (result: Bool) :=
((arr = []) β (result = True)) β§
result β (exists i, exists arr_shifted, (is_shifted arr arr_shifted i) β§ (List.Sorted Int.le arr_shifted))
-- program termination
β result, implementation arr = result β§
spec result","def generated_spec
-- function signature
(impl: List Int β Bool)
-- inputs
(arr: List Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β arr, problem_spec impl arr) β
(β arr, generated_spec impl arr) :=",sorry,def implementation (arr: List Int) : Bool :=,sorry,"-- #test implementation [3, 4, 5, 1, 2] = True
-- #test implementation [3, 5, 10, 1, 2] = True
-- #test implementation [4, 3, 1, 2] = False
-- #test implementation [3, 5, 4, 1, 2] = False
-- #test implementation [] = True","theorem correctness
(arr: List Int)
: problem_spec implementation arr
:=","by
sorry",,,
"def exchange(lst1: list[int], lst2: list[int]) -> str","In this problem, you will implement a function that takes two lists of numbers,
and determines whether it is possible to perform an exchange of elements
between them to make lst1 a list of only even numbers.
There is no limit on the number of exchanged elements between lst1 and lst2.
If it is possible to exchange elements between the lst1 and lst2 to make
all the elements of lst1 to be even, return ""YES"".
Otherwise, return ""NO"". It is assumed that the input lists will be non-empty.
","[{""input"": ""([1, 2, 3, 4], [1, 2, 3, 4])"", ""expected_output"": ""YES""}, {""input"": ""([1, 2, 3, 4], [1, 5, 3, 4])"", ""expected_output"": ""NO""}]","def exchange(lst1: list[int], lst2: list[int]) -> str
""""""In this problem, you will implement a function that takes two lists of numbers,
and determines whether it is possible to perform an exchange of elements
between them to make lst1 a list of only even numbers.
There is no limit on the number of exchanged elements between lst1 and lst2.
If it is possible to exchange elements between the lst1 and lst2 to make
all the elements of lst1 to be even, return ""YES"".
Otherwise, return ""NO"". It is assumed that the input lists will be non-empty.
""""""","def problem_spec
-- function signature
(implementation: List Int β List Int β String)
-- inputs
(lst1: List Int)
(lst2: List Int) :=
-- spec
let spec (result : String) :=
lst1 β [] β lst2 β [] β
let bool_result := β exchange: List (Nat Γ Nat),
let lst1_idxs := exchange.map (fun (a, b) => a)
let lst2_idxs := exchange.map (fun (a, b) => b)
lst1_idxs.all (fun i => i < lst1.length) β§
lst2_idxs.all (fun i => i < lst2.length) β§
lst1_idxs.Nodup β§
lst2_idxs.Nodup β§
β i, i < lst1.length β
(i β lst1_idxs β Even (lst1.get! i)) β§
(i β lst1_idxs β
-- find the (a, b) in exchange where a = i
let i_idx := (lst1_idxs.indexesOf i).head!
Even (lst2.get! (lst2_idxs.get! i_idx)))
(bool_result β result = ""YES"") β§
(result = ""NO"" β Β¬ bool_result) β§
(result β ""YES"" β§ result β ""NO"" β False)
-- program termination
β result,
implementation lst1 lst2 = result β§
spec result","def generated_spec
-- function signature
(impl: List Int β List Int β String)
-- inputs
(lst1: List Int)
(lst2: List Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β lst1 lst2, problem_spec impl lst1 lst2) β
(β lst1 lst2, generated_spec impl lst1 lst2) :=",sorry,def implementation (lst1: List Int) (lst2: List Int) : String :=,sorry,"-- #test implementation ([1, 2, 3, 4], [1, 2, 3, 4]) = ""YES""
-- #test implementation ([1, 2, 3, 4], [1, 5, 3, 4]) = ""NO""","theorem correctness
(lst1: List Int)
(lst2: List Int)
: problem_spec implementation lst1 lst2
:=","by
sorry",,,
"def histogram(s : str) -> Dict[str, int]","Given a string representing a space separated lowercase letters, return a dictionary
of the letter with the most repetition and containing the corresponding count.
If several letters have the same occurrence, return all of them.
-- Note(George): I believe the equality extensionality for HashMaps makes this spec true.
","[{""input"": ""a b c"", ""expected_output"": {""a"": 1, ""b"": 1, ""c"": 1}}, {""input"": ""a b b a"", ""expected_output"": {""a"": 2, ""b"": 2}}, {""input"": ""a b c a b"", ""expected_output"": {""a"": 2, ""b"": 2}}, {""input"": ""b b b b a"", ""expected_output"": {""b"": 4}}, {""input"": """", ""expected_output"": {}}]","def histogram(s : str) -> Dict[str, int]
""""""Given a string representing a space separated lowercase letters, return a dictionary
of the letter with the most repetition and containing the corresponding count.
If several letters have the same occurrence, return all of them.
-- Note(George): I believe the equality extensionality for HashMaps makes this spec true.
""""""","def problem_spec
-- function signature
(implementation: String β Std.HashMap Char Nat)
-- inputs
(s: String) :=
-- spec
let spec (result : Std.HashMap Char Nat) :=
let chars := s.splitOn "" ""
chars.all (fun c => c.length = 1) β§ s.all (fun c => c.isLower β¨ c = ' ') β
β key β result.keys,
(key.isLower β§
key β s.data β§
result.get! key = s.count key) β§
(β char β s.data, char.isLower β
((β char2 β s.data, char2.isLower β§ char2 β char β§
s.count char < s.count char2) β char β result.keys))
-- program termination
β result,
implementation s = result β§
spec result","def generated_spec
-- function signature
(impl: String β Std.HashMap Char Nat)
-- inputs
(s: String) : Prop :=","theorem spec_isomorphism:
β impl,
(β s, problem_spec impl s) β
(β s, generated_spec impl s) :=",sorry,def implementation (s: String) : Std.HashMap Char Nat :=,sorry,"-- #test implementation 'a b c' = {'a': 1, 'b': 1, 'c': 1}
-- #test implementation 'a b b a' = {'a': 2, 'b': 2}
-- #test implementation 'a b c a b' = {'a': 2, 'b': 2}
-- #test implementation 'b b b b a' = {'b': 4}
-- #test implementation '' = {}","theorem correctness
(s: String)
: problem_spec implementation s
:=","by
sorry",,,
"def reverse_delete(s : str, c : str) -> (str, bool)","We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c
then check if the result string is palindrome.
A string is called palindrome if it reads the same backward as forward.
You should return a tuple containing the result string and True/False for the check.
-- Note: We assume the deletions preserve the order of the remaining characters.
","[{""input"": [""abcde"", ""ae""], ""expected_output"": ""(\""bcd\"", False)""}, {""input"": [""abcdef"", ""b""], ""expected_output"": ""(\""acdef\"", False)""}, {""input"": [""abcdedcba"", ""ab""], ""expected_output"": ""('cdedc', True)""}]","def reverse_delete(s : str, c : str) -> (str, bool)
""""""We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c
then check if the result string is palindrome.
A string is called palindrome if it reads the same backward as forward.
You should return a tuple containing the result string and True/False for the check.
-- Note: We assume the deletions preserve the order of the remaining characters.
""""""","def problem_spec
-- function signature
(implementation: String β String β (String Γ Bool))
-- inputs
(s: String)
(c: String) :=
-- spec
let spec (result : String Γ Bool) :=
let (result_str, result_bool) := result
result_bool = (List.Palindrome result_str.data) β§
(c.data.length = 0 β result_str = s) β§
(c.data.length > 0 β
result_str =
(implementation
(String.join ((s.data.filter (fun x => x β c.data.head!)).map (fun c => String.mk [c])))
(c.drop 1)).fst)
-- program termination
β result,
implementation s c = result β§
spec result","def generated_spec
-- function signature
(impl: String β String β (String Γ Bool))
-- inputs
(s: String)
(c: String) : Prop :=","theorem spec_isomorphism:
β impl,
(β s c, problem_spec impl s c) β
(β s c, generated_spec impl s c) :=",sorry,def implementation (s: String) (c: String) : String Γ Bool :=,sorry,"-- #test implementation ""abcde"" ""ae"" = (""bcd"", False)
-- #test implementation ""abcdef"" ""b"" = (""acdef"", False)
-- #test implementation ""abcdedcba"" ""ab"" = (""cdedc"", True)","theorem correctness
(s c: String)
: problem_spec implementation s c
:=","by
sorry",,,
def odd_count(lst : list[str]) -> list[str],"Given a list of strings, where each string consists of only digits, return a list.
Each element i of the output should be ""the number of odd elements in the
string i of the input."" where all the i's should be replaced by the number
of odd digits in the i'th string of the input.
Note(George): Found it hard to not leak the implementation, so I opted for a recursive statement.
","[{""input"": [""1234567""], ""expected_output"": [""the number of odd elements 4n the str4ng 4 of the 4nput.""]}, {""input"": [""3"", ""11111111""], ""expected_output"": [""the number of odd elements 1n the str1ng 1 of the 1nput."", ""the number of odd elements 8n the str8ng 8 of the 8nput.""]}]","def odd_count(lst : list[str]) -> list[str]
""""""Given a list of strings, where each string consists of only digits, return a list.
Each element i of the output should be ""the number of odd elements in the
string i of the input."" where all the i's should be replaced by the number
of odd digits in the i'th string of the input.
Note(George): Found it hard to not leak the implementation, so I opted for a recursive statement.
""""""","def problem_spec
-- function signature
(implementation: List String β List String)
-- inputs
(lst: List String) :=
-- spec
let spec (result : List String) :=
lst.all (fun s => s.data.all (fun c => c.isDigit)) β
(result.length = 0 β lst.length = 0) β§
(result.length > 0 β
let num_odd_digits := (lst.head!.data.filter (fun c => c.isDigit β§ c.toNat % 2 = 1)).length
result.head! = ""the number of odd elements "" ++ num_odd_digits.repr ++ ""n the str"" ++ num_odd_digits.repr ++ ""ng "" ++ num_odd_digits.repr ++ "" of the "" ++ num_odd_digits.repr ++ ""nput.""
β§ result.tail! = implementation lst.tail!)
-- program termination
β result,
implementation lst = result β§
spec result","def generated_spec
-- function signature
(impl: List String β List String)
-- inputs
(lst: List String) : Prop :=","theorem spec_isomorphism:
β impl,
(β lst, problem_spec impl lst) β
(β lst, generated_spec impl lst) :=",sorry,def implementation (lst: List String) : List String :=,sorry,"-- #test implementation ['1234567'] = [""the number of odd elements 4n the str4ng 4 of the 4nput.""]
-- #test implementation ['3',""11111111""] = [""the number of odd elements 1n the str1ng 1 of the 1nput."",
-- ""the number of odd elements 8n the str8ng 8 of the 8nput.""]","theorem correctness
(lst: List String)
: problem_spec implementation lst
:=","by
sorry",,,
def minSubArraySum(nums : list[int]) -> int,"Given an array of integers nums, find the minimum sum of any non-empty sub-array
of nums.
","[{""input"": [2, 3, 4, 1, 2, 4], ""expected_output"": 1}, {""input"": [-1, -2, -3], ""expected_output"": -6}]","def minSubArraySum(nums : list[int]) -> int
""""""Given an array of integers nums, find the minimum sum of any non-empty sub-array
of nums.
""""""","def problem_spec
-- function signature
(implementation: List Int β Int)
-- inputs
(nums: List Int) :=
-- spec
let spec (result : Int) :=
(β subarray β nums.sublists,
subarray.length > 0 β
result β€ subarray.sum) β§
(β subarray β nums.sublists,
subarray.length > 0 β§
result = subarray.sum)
-- program termination
β result,
implementation nums = result β§
spec result","def generated_spec
-- function signature
(impl: List Int β Int)
-- inputs
(nums: List Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β nums, problem_spec impl nums) β
(β nums, generated_spec impl nums) :=",sorry,def implementation (nums: List Int) : Int :=,sorry,"-- #test implementation [2, 3, 4, 1, 2, 4] = 1
-- #test implementation [-1, -2, -3] = -6","theorem correctness
(nums: List Int)
: problem_spec implementation nums
:=","by
sorry",,,
"def max_fill_count(grid : list[list[int]], capacity : int) -> int","You are given a rectangular grid of wells. Each row represents a single well,
and each 1 in a row represents a single unit of water.
Each well has a corresponding bucket that can be used to extract water from it,
and all buckets have the same capacity.
Your task is to use the buckets to empty the wells.
Output the number of times you need to lower the buckets.
Constraints:
* all wells have the same length
* 1 <= grid.length <= 10^2
* 1 <= grid[:,1].length <= 10^2
* grid[i][j] -> 0 | 1
* 1 <= capacity <= 10
","[{""input"": ""([[0,0,1,0], [0,1,0,0], [1,1,1,1]], 1)"", ""expected_output"": 6}, {""input"": ""([[0,0,1,1], [0,0,0,0], [1,1,1,1], [0,1,1,1]], 2)"", ""expected_output"": 5}, {""input"": ""([[0,0,0], [0,0,0]], 5)"", ""expected_output"": 0}]","def max_fill_count(grid : list[list[int]], capacity : int) -> int
""""""You are given a rectangular grid of wells. Each row represents a single well,
and each 1 in a row represents a single unit of water.
Each well has a corresponding bucket that can be used to extract water from it,
and all buckets have the same capacity.
Your task is to use the buckets to empty the wells.
Output the number of times you need to lower the buckets.
Constraints:
* all wells have the same length
* 1 <= grid.length <= 10^2
* 1 <= grid[:,1].length <= 10^2
* grid[i][j] -> 0 | 1
* 1 <= capacity <= 10
""""""","def problem_spec
-- function signature
(implementation: List (List Nat) β Nat β Nat)
-- inputs
(grid: List (List Nat))
(capacity: Nat) :=
-- spec
let spec (result : Nat) :=
(grid.all (fun row => row.all (fun cell => cell = 0 β¨ cell = 1))) β
(β len : Nat, grid.all (fun row => row.length = len)) β
(result = 0 β grid.length = 0) β§
(grid.length > 0 β
let well_water_count := grid.head!.sum;
result - (well_water_count / capacity) - (if well_water_count % capacity > 0 then 1 else 0) = implementation grid.tail! capacity)
-- program termination
β result,
implementation grid capacity = result β§
spec result","def generated_spec
-- function signature
(impl: List (List Nat) β Nat β Nat)
-- inputs
(grid: List (List Nat))
(capacity: Nat) : Prop :=","theorem spec_isomorphism:
β impl,
(β grid capacity, problem_spec impl grid capacity) β
(β grid capacity, generated_spec impl grid capacity) :=",sorry,def implementation (grid: List (List Nat)) (capacity: Nat) : Nat :=,sorry,"-- #test implementation [[0,0,1,0], [0,1,0,0], [1,1,1,1]] 1 = 6
-- #test implementation [[0,0,1,1], [0,0,0,0], [1,1,1,1], [0,1,1,1]] 2 = 5
-- #test implementation [[0,0,0], [0,0,0]] 5 = 0","theorem correctness
(grid: List (List Nat))
(capacity: Nat)
: problem_spec implementation grid capacity
:=","by
sorry",,,
"def max_fill_count(grid : list[list[int]], capacity : int) -> int","Please write a function that sorts an array of non-negative integers according to
number of ones in their binary representation in ascending order.
For similar number of ones, sort based on decimal value.
","[{""input"": [1, 5, 2, 3, 4], ""expected_output"": [1, 2, 3, 4, 5]}, {""input"": [1, 0, 2, 3, 4], ""expected_output"": [0, 1, 2, 3, 4]}]","def max_fill_count(grid : list[list[int]], capacity : int) -> int
""""""Please write a function that sorts an array of non-negative integers according to
number of ones in their binary representation in ascending order.
For similar number of ones, sort based on decimal value.
""""""","def problem_spec
-- function signature
(implementation: List Nat β List Nat)
-- inputs
(lst: List Nat) :=
-- spec
let spec (result : List Nat) :=
β x : Nat, lst.count x = result.count x β§
result.length = lst.length β§
(β i j : Nat, i < j β j < result.length β
Nat.digits 2 (result.get! i) < Nat.digits 2 (result.get! j) β¨
(Nat.digits 2 (result.get! i) = Nat.digits 2 (result.get! j) β§ result.get! i < result.get! j))
-- program termination
β result,
implementation lst = result β§
spec result","def generated_spec
-- function signature
(impl: List Nat β List Nat)
-- inputs
(lst: List Nat) : Prop :=","theorem spec_isomorphism:
β impl,
(β lst, problem_spec impl lst) β
(β lst, generated_spec impl lst) :=",sorry,def implementation (lst: List Nat) : List Nat :=,sorry,"-- #test implementation [1, 5, 2, 3, 4] = [1, 2, 3, 4, 5]
-- #test implementation [1, 0, 2, 3, 4] = [0, 1, 2, 3, 4]","theorem correctness
(lst: List Nat)
: problem_spec implementation lst
:=","by
sorry",,,
"def select_words(s : str, n : int) -> list[str]","Given a string s and a natural number n, you have been tasked to implement
a function that returns a list of all words from string s that contain exactly
n consonants, in order these words appear in the string s.
If the string s is empty then the function should return an empty list.
Note: you may assume the input string contains only letters and spaces.
","[{""input"": ""(\""Mary had a little lamb\"", 4)"", ""expected_output"": [""little""]}, {""input"": ""(\""Mary had a little lamb\"", 3)"", ""expected_output"": [""Mary"", ""lamb""]}, {""input"": ""(\""simple white space\"", 2)"", ""expected_output"": []}, {""input"": ""(\""Hello world\"", 4)"", ""expected_output"": [""world""]}, {""input"": ""(\""Uncle sam\"", 3)"", ""expected_output"": [""Uncle""]}]","def select_words(s : str, n : int) -> list[str]
""""""Given a string s and a natural number n, you have been tasked to implement
a function that returns a list of all words from string s that contain exactly
n consonants, in order these words appear in the string s.
If the string s is empty then the function should return an empty list.
Note: you may assume the input string contains only letters and spaces.
""""""","def problem_spec
-- function signature
(implementation: String β Nat β List String)
-- inputs
(s: String)
(n: Nat) :=
-- spec
let spec (result : List String) :=
let is_consonant (c: Char) :=
c β ['a', 'e', 'i', 'o', 'u'] β§
c β ['A', 'E', 'I', 'O', 'U'] β§
c.isAlpha
s.all (fun c => c = ' ' β¨ c.isAlpha) β
let words := s.splitOn "" ""
(result = [] β (s.length = 0 β¨ words.all (fun word => (word.data.filter (fun c => is_consonant c)).length β n))) β§
(result.length > 0 β
let first_word := result[0]!
first_word β words β§
(first_word.data.filter (fun c => is_consonant c)).length = n β§
let first_word_idx := words.indexOf first_word
(β i, i < first_word_idx β
(words[i]!.data.filter (fun c => is_consonant c)).length β n) β§
result.tail! =
implementation ((words.drop (first_word_idx + 1)).foldl (fun acc word => acc ++ "" "" ++ word) """") n
)
-- program termination
β result,
implementation s n = result β§
spec result","def generated_spec
-- function signature
(impl: String β Nat β List String)
-- inputs
(s: String)
(n: Nat) : Prop :=","theorem spec_isomorphism:
β impl,
(β s n, problem_spec impl s n) β
(β s n, generated_spec impl s n) :=",sorry,def implementation (s: String) (n: Nat) : List String :=,sorry,"-- #test implementation ""Mary had a little lamb"" 4 = [""little""]
-- #test implementation ""Mary had a little lamb"" 3 = [""Mary"", ""lamb""]
-- #test implementation ""simple white space"" 2 = []
-- #test implementation ""Hello world"" 4 = [""world""]
-- #test implementation ""Uncle sam"" 3 = [""Uncle""]","theorem correctness
(s: String)
(n: Nat)
: problem_spec implementation s n
:=","by
sorry",,,
def get_closest_vowel(s : str) -> str,"You are given a word. Your task is to find the closest vowel that stands between
two consonants from the right side of the word (case sensitive).
Vowels in the beginning and ending doesn't count. Return empty string if you didn't
find any vowel met the above condition.
You may assume that the given string contains English letter only.
Note: The ""closest"" is interpreted as the closest to the end of the word, not the closest to the consonants.
","[{""input"": ""yogurt"", ""expected_output"": ""u""}, {""input"": ""FULL"", ""expected_output"": ""U""}, {""input"": ""quick"", ""expected_output"": ""i""}, {""input"": ""ab"", ""expected_output"": """"}]","def get_closest_vowel(s : str) -> str
""""""You are given a word. Your task is to find the closest vowel that stands between
two consonants from the right side of the word (case sensitive).
Vowels in the beginning and ending doesn't count. Return empty string if you didn't
find any vowel met the above condition.
You may assume that the given string contains English letter only.
Note: The ""closest"" is interpreted as the closest to the end of the word, not the closest to the consonants.
""""""","def problem_spec
-- function signature
(implementation: String β String)
-- inputs
(s: String) :=
-- spec
let spec (result : String) :=
s.data.all (fun c => c.isAlpha) β
let is_consonant (c: Char) :=
c β ['a', 'e', 'i', 'o', 'u'] β§
c β ['A', 'E', 'I', 'O', 'U'] β§
c.isAlpha
(result = """" β Β¬ β (i j k : Nat), i < j β§ j < k β§ k < s.length β§ is_consonant s.data[i]! β§ Β¬ is_consonant s.data[j]! β§ is_consonant s.data[k]!) β§
(result β """" β
result.length = 1 β§
result.data[0]! β s.data β§
Β¬ is_consonant result.data[0]! β§
β (i j k : Nat),
i < j β§ j < k β§ k < s.length β§
is_consonant s.data[i]! β§ Β¬ is_consonant s.data[j]! β§ is_consonant s.data[k]! β§
result.data[0]! = s.data[j]! β§
(β (i' j' k' : Nat),
i' < j' β§ j' < k' β§ k' < s.length β§ is_consonant s.data[i']! β§ Β¬ is_consonant s.data[j']! β§ is_consonant s.data[k']! β
j' β€ j)
)
-- program termination
β result,
implementation s = result β§
spec result","def generated_spec
-- function signature
(impl: String β String)
-- inputs
(s: String) : Prop :=","theorem spec_isomorphism:
β impl,
(β s, problem_spec impl s) β
(β s, generated_spec impl s) :=",sorry,def implementation (s: String) : String :=,sorry,"-- #test implementation ""yogurt"" = ""u""
-- #test implementation ""FULL"" = ""U""
-- #test implementation ""quick"" = ""i""
-- #test implementation ""ab"" = """"","theorem correctness
(s: String)
: problem_spec implementation s
:=","by
sorry",,,
def match_parens(l : list[str]) -> str,"You are given a list of two strings, both strings consist of open
parentheses '(' or close parentheses ')' only.
Your job is to check if it is possible to concatenate the two strings in
some order, that the resulting string will be good.
A string S is considered to be good if and only if all parentheses in S
are balanced. For example: the string '(())()' is good, while the string
'())' is not.
Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.
","[{""input"": [""()("", "")""], ""expected_output"": ""Yes""}, {""input"": ["")"", "")""], ""expected_output"": ""No""}]","def match_parens(l : list[str]) -> str
""""""You are given a list of two strings, both strings consist of open
parentheses '(' or close parentheses ')' only.
Your job is to check if it is possible to concatenate the two strings in
some order, that the resulting string will be good.
A string S is considered to be good if and only if all parentheses in S
are balanced. For example: the string '(())()' is good, while the string
'())' is not.
Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.
""""""","def problem_spec
-- function signature
(implementation: List String β String)
-- inputs
(l: List String) :=
-- spec
let spec (result : String) :=
l.length = 2 β
l[0]!.all (fun c => c = '(' β¨ c = ')') β
l[1]!.all (fun c => c = '(' β¨ c = ')') β
let res := (balanced_paren_non_computable (l[0]! ++ l[1]!) '(' ')' β¨
balanced_paren_non_computable (l[1]! ++ l[0]!) '(' ')')
(res β result = ""Yes"") β§
(Β¬ res β result = ""No"")
-- program termination
β result,
implementation l = result β§
spec result","def generated_spec
-- function signature
(impl: List String β String)
-- inputs
(l: List String) : Prop :=","theorem spec_isomorphism:
β impl,
(β l, problem_spec impl l) β
(β l, generated_spec impl l) :=",sorry,def implementation (l: List String) : String :=,sorry,"-- #test implementation ['()(', ')'] = ""Yes""
-- #test implementation [')', ')'] = ""No""","theorem correctness
(l: List String)
: problem_spec implementation l
:=","by
sorry",,,
"def maximum(arr: List[int], k: int) -> List[int]","Given an array arr of integers and a positive integer k, return a sorted list of length
k with the maximum k numbers in arr.
Note:
1. The length of the array will be in the range of [1, 1000].
2. The elements in the array will be in the range of [-1000, 1000].
3. 0 <= k <= len(arr)
","[{""input"": [[2, 4, 3, 1], 3], ""expected_output"": [2, 3, 4]}, {""input"": [[2, 4, 3, 1], 0], ""expected_output"": []}]","def maximum(arr: List[int], k: int) -> List[int]
""""""Given an array arr of integers and a positive integer k, return a sorted list of length
k with the maximum k numbers in arr.
Note:
1. The length of the array will be in the range of [1, 1000].
2. The elements in the array will be in the range of [-1000, 1000].
3. 0 <= k <= len(arr)
""""""","def problem_spec
-- function signature
(impl: List Int β Int β List Int)
-- inputs
(arr: List Int)
(k: Int) :=
-- spec
let spec (result: List Int) :=
1 β€ arr.length β arr.length β€ 1000 β arr.all (fun x => -1000 β€ x β§ x β€ 1000) β 0 β€ k β k β€ arr.length β
result.length = k β§
result.Sorted (Β· β€ Β·) β§
β x β result, x β arr β§
let result_reversed := result.reverse; -- reverse to get last element
match result_reversed with
| [] => k = 0
| max :: remaining_reversed =>
arr.max? = some max β§
impl (arr.erase max) (k-1) = (remaining_reversed.reverse)
-- program terminates
β result, impl arr k = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: List Int β Int β List Int)
-- inputs
(arr: List Int)
(k: Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β arr k, problem_spec impl arr k) β
(β arr k, generated_spec impl arr k) :=",sorry,def implementation (arr: List Int) (k: Int) : List Int :=,sorry,"-- #test implementation [2, 4, 3, 1] 3 = [2, 3, 4]
-- #test implementation [2, 4, 3, 1] 0 = []","theorem correctness
(arr: List Int)
(k: Int)
: problem_spec implementation arr k :=",sorry,,,
def solution(lst: List[int]) -> int,"Given a non-empty list of integers, return the sum of all of the odd elements that
are in even positions.
","[{""input"": [5, 8, 7, 1], ""expected_output"": 12}, {""input"": [3, 3, 3, 3, 3], ""expected_output"": 9}, {""input"": [30, 13, 24, 321], ""expected_output"": 0}]","def solution(lst: List[int]) -> int
""""""Given a non-empty list of integers, return the sum of all of the odd elements that
are in even positions.
""""""","def problem_spec
-- function signature
(impl: List Int β Int)
-- inputs
(lst: List Int) :=
-- spec
let spec (result : Int) :=
lst β [] β β i, i < lst.length β§ i % 2 = 0 β
(lst.length = 1 β impl lst = 0) β§
(i + 1 < lst.length β
(lst[i + 1]! % 2 = 1 β
impl (lst.drop i) = lst[i + 1]! + (if i + 2 < lst.length then impl (lst.drop (i+2)) else 0)) β§
(lst[i + 1]! % 2 = 0 β
impl (lst.drop i) = if i + 2 < lst.length then impl (lst.drop (i+2)) else 0)
)
-- program terminates
β result, impl lst = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: List Int β Int)
-- inputs
(lst: List Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β lst, problem_spec impl lst) β
(β lst, generated_spec impl lst) :=",sorry,def implementation (lst: List Int) : Int :=,sorry,"-- #test implementation ([5, 8, 7, 1]: List Int) = 12
-- #test implementation ([3, 3, 3, 3, 3]: List Int) = 9
-- #test implementation ([30, 13, 24, 321]: List Int) = 0","theorem correctness
(lst: List Int)
: problem_spec implementation lst :=",sorry,,,
"def add_elements(arr: List[int], k: int) -> int","Given a non-empty array of integers arr and an integer k, return
the sum of the elements with at most two digits from the first k elements of arr.
Constraints:
1. 1 <= len(arr) <= 100
2. 1 <= k <= len(arr)
","[{""input"": [[111, 21, 3, 4000, 5, 6, 7, 8, 9], 4], ""expected_output"": 24}]","def add_elements(arr: List[int], k: int) -> int
""""""Given a non-empty array of integers arr and an integer k, return
the sum of the elements with at most two digits from the first k elements of arr.
Constraints:
1. 1 <= len(arr) <= 100
2. 1 <= k <= len(arr)
""""""","def problem_spec
-- function signature
(impl: List Int β Nat β Int)
-- inputs
(arr: List Int)
(k: Nat) :=
-- spec
let spec (result: Int) :=
1 β€ arr.length β arr.length β€ 100 β 1 β€ k β k β€ arr.length β
((β i, 0 β€ i β§ i < k β Β¬(arr[i]! β€ 99 β§ -99 β€ arr[i]!)) β result = 0) β§
β i, i < k
β§ arr[i]! β€ 99 β§ -99 β€ arr[i]!
β§ result = arr[i]! + (if i = 0 then 0 else impl arr i)
β§ β i', i < i' β§ i' < k β Β¬(arr[i']! β€ 99 β§ -99 β€ arr[i']!)
-- program termination
β result, impl arr k = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: List Int β Nat β Int)
-- inputs
(arr: List Int)
(k: Nat) : Prop :=","theorem spec_isomorphism:
β impl,
(β arr k, problem_spec impl arr k) β
(β arr k, generated_spec impl arr k) :=",sorry,def implementation (arr: List Int) (k: Nat) : Int :=,sorry,"-- #test implementation ([111, 21, 3, 4000, 5, 6, 7, 8, 9]: List Int) 4 = 24","theorem correctness
(arr: List Int)
(k: Nat)
: problem_spec implementation arr k :=",sorry,,,
def get_odd_collatz (n: int) -> List[int],"Given a positive integer n, return a sorted list that has the odd numbers in collatz sequence.
The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined
as follows: start with any positive integer n. Then each term is obtained from the
previous term as follows: if the previous term is even, the next term is one half of
the previous term. If the previous term is odd, the next term is 3 times the previous
term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.
Note:
1. Collatz(1) is [1].
2. returned list sorted in increasing order.
","[{""input"": 5, ""expected_output"": [1, 5]}]","def get_odd_collatz (n: int) -> List[int]
""""""Given a positive integer n, return a sorted list that has the odd numbers in collatz sequence.
The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined
as follows: start with any positive integer n. Then each term is obtained from the
previous term as follows: if the previous term is even, the next term is one half of
the previous term. If the previous term is odd, the next term is 3 times the previous
term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.
Note:
1. Collatz(1) is [1].
2. returned list sorted in increasing order.
""""""","def problem_spec
-- function signature
(impl: Nat β List Nat)
-- inputs
(n: Nat) :=
-- spec
let spec (result: List Nat) :=
n > 0 β
result.Sorted (Β· < Β·) β§
β m, m β result β Odd m β§ collatz_reachable n m -- m is reachable from starting point n
-- program termination
β result, impl n = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: Nat β List Nat)
-- inputs
(n: Nat) : Prop :=","theorem spec_isomorphism:
β impl,
(β n, problem_spec impl n) β
(β n, generated_spec impl n) :=",sorry,def implementation (n: Nat) : List Nat :=,sorry,"-- #test implementation 5 = [1, 5]","theorem correctness
(n: Nat)
: problem_spec implementation n :=",sorry,"/--
name: collatz_reachable
use: |
Helper to check if a natural number m is reachable in the Collatz sequence starting at n.
problems:
- 123
-/
def collatz_reachable (n m : Nat) : Prop :=
β k, Nat.iterate (fun x => if x % 2 = 0 then x / 2 else x * 3 + 1) k n = m",,
def valid_date(date: str) -> Bool,"You have to write a function which validates a given date string and
returns True if the date is valid otherwise False.
The date is valid if all of the following rules are satisfied:
1. The date string is not empty.
2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.
3. The months should not be less than 1 or higher than 12.
4. The date should be in the format: mm-dd-yyyy
","[{""input"": ""03-11-2000"", ""expected_output"": true}, {""input"": ""15-01-2012"", ""expected_output"": false}, {""input"": ""04-0-2040"", ""expected_output"": false}, {""input"": ""06-04-2020"", ""expected_output"": true}, {""input"": ""06/04/2020"", ""expected_output"": false}]","def valid_date(date: str) -> Bool
""""""You have to write a function which validates a given date string and
returns True if the date is valid otherwise False.
The date is valid if all of the following rules are satisfied:
1. The date string is not empty.
2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.
3. The months should not be less than 1 or higher than 12.
4. The date should be in the format: mm-dd-yyyy
""""""","def problem_spec
-- function signature
(impl: String β Bool)
-- inputs
(date: String) :=
-- spec
let spec (result: Bool) :=
result = true β
β m1 m2 sep1 d1 d2 sep2 y1 y2 y3 y4 : Char,
date = String.mk [m1, m2, sep1, d1, d2, sep2, y1, y2, y3, y4] β§
sep1 = '-' β§ sep2 = '-' β§
[m1, m2, d1, d2, y1, y2, y3, y4].all Char.isDigit β§
let month := (String.mk [m1, m2]).toNat!;
let day := (String.mk [d1, d2]).toNat!;
1 β€ month β§ month β€ 12 β§
(month β ({4, 6, 9, 11}: List Nat) β 1 β€ day β§ day β€ 30) β§
(month β ({1, 3, 5, 7, 8, 10, 12}: List Nat) β 1 β€ day β§ day β€ 31) β§
(month β ({2}: List Nat) β 1 β€ day β§ day β€ 29)
-- program terminates
β result, impl date = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: String β Bool)
-- inputs
(date: String) : Prop :=","theorem spec_isomorphism:
β impl,
(β date, problem_spec impl date) β
(β date, generated_spec impl date) :=",sorry,def implementation (date: String) : Bool :=,sorry,"-- #test implementation ""03-11-2000"" = true
-- #test implementation ""15-01-2012"" = false
-- #test implementation ""04-0-2040"" = false
-- #test implementation ""06-04-2020"" = true
-- #test implementation ""06/04/2020"" = false","theorem correctness
(date: String)
: problem_spec implementation date :=",sorry,,,
"def minPath(grid, k)","Given a grid with N rows and N columns (N >= 2) and a positive integer k,
each cell of the grid contains a value. Every integer in the range [1, N * N]
inclusive appears exactly once on the cells of the grid.
You have to find the minimum path of length k in the grid. You can start
from any cell, and in each step you can move to any of the neighbor cells,
in other words, you can go to cells which share an edge with you current
cell.
Please note that a path of length k means visiting exactly k cells (not
necessarily distinct).
You CANNOT go off the grid.
A path A (of length k) is considered less than a path B (of length k) if
after making the ordered lists of the values on the cells that A and B go
through (let's call them lst_A and lst_B), lst_A is lexicographically less
than lst_B, in other words, there exist an integer index i (1 <= i <= k)
such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have
lst_A[j] = lst_B[j].
It is guaranteed that the answer is unique.
Return an ordered list of the values on the cells that the minimum path go through.
","[{""input"": [[[1, 2, 3], [4, 5, 6], [7, 8, 9]], 3], ""expected_output"": [1, 2, 3]}, {""input"": [[5, 9, 3], [4, 1, 6], [7, 8, 2], 1], ""expected_output"": [1]}]","def minPath(grid, k)
""""""Given a grid with N rows and N columns (N >= 2) and a positive integer k,
each cell of the grid contains a value. Every integer in the range [1, N * N]
inclusive appears exactly once on the cells of the grid.
You have to find the minimum path of length k in the grid. You can start
from any cell, and in each step you can move to any of the neighbor cells,
in other words, you can go to cells which share an edge with you current
cell.
Please note that a path of length k means visiting exactly k cells (not
necessarily distinct).
You CANNOT go off the grid.
A path A (of length k) is considered less than a path B (of length k) if
after making the ordered lists of the values on the cells that A and B go
through (let's call them lst_A and lst_B), lst_A is lexicographically less
than lst_B, in other words, there exist an integer index i (1 <= i <= k)
such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have
lst_A[j] = lst_B[j].
It is guaranteed that the answer is unique.
Return an ordered list of the values on the cells that the minimum path go through.
""""""","def problem_spec
-- function signature
(impl: List (List Nat) β Nat β List Nat)
-- inputs
(grid: List (List Nat))
(k: Nat) :=
-- spec
let lexographically_less (a b: List Nat) : Prop :=
a.length = b.length β§ a.length = k β§
(β i, i < k β§ a.get! i < b.get! i β§
(β j, j < i β a.get! j = b.get! j));
let rec is_valid_path (k': Nat) (path: List Nat) (grid: List (List Nat)) : Prop :=
let n := grid.length;
path.length = k' β
(β i j,
(i < n β§ j < n β§ path.get! 0 = (grid.get! i).get! j) β§
(1 < path.length β
( β i' j', i' < n β§ j' < n β§
(path.get! 1 = (grid.get! i').get! j') β§
((abs ((i: Int) - (i': Int)) = 1 β§ j = j') β¨
(abs ((j: Int) - (j': Int)) = 1 β§ i = i'))) β§
(is_valid_path (k' - 1) (path.drop 1) grid))
);
let spec (result: List Nat) :=
let n := grid.length;
(β i, i < n β (grid.get! i).length = n) β
(β i j, i < n β j < n β ((grid.get! i).get! j) β [1, n^2]) β
is_valid_path k result grid β§ (β path, is_valid_path k path grid β lexographically_less result path);
-- program terminates
β result, impl grid k = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: List (List Nat) β Nat β List Nat)
-- inputs
(grid: List (List Nat))
(k: Nat): Prop :=","theorem spec_isomorphism:
β impl,
(β grid k, problem_spec impl grid k) β
(β grid k, generated_spec impl grid k) :=",sorry,def implementation (grid: List (List Nat)) (k: Nat) : List Nat :=,sorry,"-- #test implementation [[1,2,3], [4,5,6], [7,8,9]] 3 = [1,2,3]
-- #test implementation [[5,9,3], [4,1,6], [7,8,2]] 1 = [1]","theorem correctness
(grid: List (List Nat))
(k: Nat)
: problem_spec implementation grid k :=",sorry,,,
def is_sorted(lst: List[int]) -> Bool,"Given a list of numbers, return whether or not they are sorted
in ascending order. If list has more than 1 duplicate of the same
number, return False. Assume no negative numbers and only integers.
","[{""input"": [5], ""expected_output"": true}, {""input"": [1, 2, 3, 4, 5], ""expected_output"": true}, {""input"": [1, 3, 2, 4, 5], ""expected_output"": false}, {""input"": [1, 2, 3, 4, 5, 6], ""expected_outupt"": true}, {""input"": [1, 2, 3, 4, 5, 6, 7], ""expected_output"": true}, {""input"": [1, 3, 2, 4, 5, 6, 7], ""expected_output"": false}, {""input"": [1, 2, 2, 3, 3, 4], ""expected_output"": true}, {""input"": [1, 2, 2, 2, 3, 4], ""expected_output"": false}]","def is_sorted(lst: List[int]) -> Bool
""""""Given a list of numbers, return whether or not they are sorted
in ascending order. If list has more than 1 duplicate of the same
number, return False. Assume no negative numbers and only integers.
""""""","def problem_spec
-- function signature
(impl: List Int β Bool)
-- inputs
(lst: List Int) :=
-- spec
let sorted_ascending := lst.Sorted (Β· β€ Β·);
let ms := Multiset.ofList lst;
let multiple_duplicates := β i, i β lst β§ 2 < ms.count i;
let spec (res: Bool) :=
res β sorted_ascending β§
res β Β¬multiple_duplicates β§
multiple_duplicates β Β¬res β§
Β¬sorted_ascending β Β¬res;
-- program terminates
β result, impl lst = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: List Int β Bool)
-- inputs
(lst: List Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β lst, problem_spec impl lst) β
(β lst, generated_spec impl lst) :=",sorry,def implementation (lst: List Int) : Bool :=,sorry,"-- #test implementation [5] = true
-- #test implementation [1, 2, 3, 4, 5] = true
-- #test implementation [1, 3, 2, 4, 5] = false
-- #test implementation [1, 2, 3, 4, 5, 6] = true
-- #test implementation [1, 2, 3, 4, 5, 6, 7] = true
-- #test implementation [1, 3, 2, 4, 5, 6, 7] = false
-- #test implementation [1, 2, 2, 3, 3, 4] = true
-- #test implementation [1, 2, 2, 2, 3, 4] = false","theorem correctness
(lst: List Int)
: problem_spec implementation lst :=",sorry,,,
"def intersection(interval1: Tuple[Int, Int], interval2: Tuple[Int, Int]) -> str","You are given two intervals,
where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).
The given intervals are closed which means that the interval (start, end)
includes both start and end.
For each given interval, it is assumed that its start is less or equal its end.
Your task is to determine whether the length of intersection of these two
intervals is a prime number.
Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)
which its length is 1, which not a prime number.
If the length of the intersection is a prime number, return ""YES"",
otherwise, return ""NO"".
If the two intervals don't intersect, return ""NO"".
","[{""input"": [""(1"", ""2)"", ""(2"", ""3)""], ""expected_output"": ""NO""}, {""input"": [""(-1"", ""1)"", ""(0"", ""4)""], ""expected_output"": ""NO""}, {""input"": [""(-3"", ""-1)"", ""(-5"", ""5)""], ""expected_output"": ""YES""}]","def intersection(interval1: Tuple[Int, Int], interval2: Tuple[Int, Int]) -> str
""""""You are given two intervals,
where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).
The given intervals are closed which means that the interval (start, end)
includes both start and end.
For each given interval, it is assumed that its start is less or equal its end.
Your task is to determine whether the length of intersection of these two
intervals is a prime number.
Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)
which its length is 1, which not a prime number.
If the length of the intersection is a prime number, return ""YES"",
otherwise, return ""NO"".
If the two intervals don't intersect, return ""NO"".
""""""","def problem_spec
-- function signature
(impl: Int Γ Int β Int Γ Int β String)
-- inputs
(interval1: Int Γ Int)
(interval2: Int Γ Int) :=
-- spec
let spec (result: String) :=
let (s1, e1) := interval1;
let (s2, e2) := interval2;
s1 β€ e1 β s2 β€ e2 β
let intersectionStart := max s1 s2;
let intersectionEnd := min e1 e2;
let hasIntersection := intersectionStart β€ intersectionEnd;
let isPrime := Nat.Prime (intersectionEnd - intersectionStart).toNat;
(result = ""YES"" β hasIntersection β§ isPrime) β§
(result = ""NO"" β Β¬hasIntersection β¨ Β¬isPrime) β§
(result = ""YES"" β¨ result = ""NO"")
-- program terminates
β result, impl interval1 interval2 = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: Int Γ Int β Int Γ Int β String)
-- inputs
(interval1: Int Γ Int)
(interval2: Int Γ Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β interval1 interval2, problem_spec impl interval1 interval2) β
(β interval1 interval2, generated_spec impl interval1 interval2) :=",sorry,def implementation (interval1: Int Γ Int) (interval2: Int Γ Int) : String :=,sorry,"-- #test implementation (1, 2) (2, 3) = ""NO""
-- #test implementation (-1, 1) (0, 4) = ""NO""
-- #test implementation (-3, -1) (-5, 5) = ""YES""","theorem correctness
(interval1: Int Γ Int)
(interval2: Int Γ Int)
: problem_spec implementation interval1 interval2 :=",sorry,,,
def prod_signs(arr: List[int]) -> Optional[int],"You are given an array arr of integers and you need to return
sum of magnitudes of integers multiplied by product of all signs
of each number in the array, represented by 1, -1 or 0.
Note: return None for empty arr.
","[{""input"": [1, 2, 2, -4], ""expected_output"": -9}, {""input"": [0, 1], ""expected_output"": 0}, {""input"": [], ""expected_output"": ""None""}]","def prod_signs(arr: List[int]) -> Optional[int]
""""""You are given an array arr of integers and you need to return
sum of magnitudes of integers multiplied by product of all signs
of each number in the array, represented by 1, -1 or 0.
Note: return None for empty arr.
""""""","def problem_spec
-- function signature
(impl: List Int β Option Int)
-- inputs
(arr: List Int) :=
-- spec
let spec (result: Option Int) :=
match result with
| none => arr = []
| some result =>
let magnitude_sum := (arr.map (fun x => Int.ofNat x.natAbs)).sum;
let neg_count_odd := (arr.filter (fun x => x < 0)).length % 2 = 1;
let has_zero := 0 β arr;
(result < 0 β (neg_count_odd β§ Β¬has_zero)
β§ result = magnitude_sum * -1) β§
(0 < result β (Β¬neg_count_odd β§ Β¬has_zero)
β§ result = magnitude_sum) β§
(result = 0 β has_zero)
-- program terminates
β result, impl arr = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: List Int β Option Int)
-- inputs
(arr: List Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β arr, problem_spec impl arr) β
(β arr, generated_spec impl arr) :=",sorry,def implementation (arr: List Int) : Option Int :=,sorry,"-- #test implementation ([1, 2, 2, -4]: List Int) = (-9: Int)
-- #test implementation ([0, 1]: List Int) = (0: Int)
-- #test implementation ([]: List Int) = none","theorem correctness
(arr: List Int)
: problem_spec implementation arr :=",sorry,,,
def split_words(txt),"Given a string of words, return a list of words split on whitespace, if no whitespaces exists in the text you
should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
","[{""input"": ""Hello world!"", ""expected_output"": [""Hello"", ""world!""]}, {""input"": ""Hello,world!"", ""expected_output"": [""Hello"", ""world!""]}, {""input"": ""abcdef"", ""expected_output"": 3}]","def split_words(txt)
""""""Given a string of words, return a list of words split on whitespace, if no whitespaces exists in the text you
should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
""""""","def problem_spec
-- function signature
-- return a tuple of Option (List String) and Option Nat
(impl: String β Option (List String) Γ Option Nat)
-- inputs
(text: String) :=
-- spec
let spec (result: Option (List String) Γ Option Nat) :=
-- both cannot be None
let words := result.fst;
let ord := result.snd;
0 < text.length β
Β¬ (words = none β§ ord = none) β§
(words = none β β ch, ch β text.toList β (ch = ',' β¨ ch = ' ')) β§
(β num, ord = some num β (text.get! 0).toNat = num) β§
(β lst, words = some lst β β i, i < lst.length β
let str := lst.get! i;
text.containsSubstr str) β§
(β lst, words = some lst β
let first := text.takeWhile (fun c => c β ',' β§ c β ' ');
let nextImpl := impl (text.drop (first.length + 1));
let nextWords := nextImpl.fst;
(β nextLst, nextWords = some nextLst β§
lst = [first] ++ nextLst))
-- program terminates
β result, impl text = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: String β Option (List String) Γ Option Nat)
-- inputs
(text: String) : Prop :=","theorem spec_isomorphism:
β impl,
(β text, problem_spec impl text) β
(β text, generated_spec impl text) :=",sorry,def implementation (text: String) : Option (List String) Γ Option Nat :=,sorry,"-- #test implementation ""Hello world!"" = (some [""Hello"", ""world!""], none)
-- #test implementation ""Hello,world!"" = (some [""Hello"", ""world!""], none)
-- #test implementation ""abcdef"" = (none, some 3)","theorem correctness
(text: String)
: problem_spec implementation text :=",sorry,,,
def tri(n: int) -> List[int],"Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in
the last couple centuries. However, what people don't know is Tribonacci sequence.
Tribonacci sequence is defined by the recurrence:
tri(1) = 3
tri(n) = 1 + n / 2, if n is even.
tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.
For example:
tri(2) = 1 + (2 / 2) = 2
tri(4) = 3
tri(3) = tri(2) + tri(1) + tri(4)
= 2 + 3 + 3 = 8
You are given a non-negative integer number n, you have to a return a list of the
first n + 1 numbers of the Tribonacci sequence.
","[{""input"": 3, ""expected_output"": [1, 3, 2, 8]}]","def tri(n: int) -> List[int]
""""""Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in
the last couple centuries. However, what people don't know is Tribonacci sequence.
Tribonacci sequence is defined by the recurrence:
tri(1) = 3
tri(n) = 1 + n / 2, if n is even.
tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.
For example:
tri(2) = 1 + (2 / 2) = 2
tri(4) = 3
tri(3) = tri(2) + tri(1) + tri(4)
= 2 + 3 + 3 = 8
You are given a non-negative integer number n, you have to a return a list of the
first n + 1 numbers of the Tribonacci sequence.
""""""","def problem_spec
-- function signature
(impl: Nat β List Int)
-- inputs
(n: Nat) :=
-- spec
let spec (result: List Int) :=
0 < result.length β§
result.length = n β§
let i := result.length-1;
(i = 0 β result[0]! = 1) β§ -- base case
(i = 1 β result[1]! = 3) β§
(2 β€ i β§ i % 2 = 0 β result[i]! = 1 + i / 2) β§
(2 β€ i β§ i % 2 = 1 β result[i]! = result[i-2]! + result[i-1]! + (1 + (i+1) / 2)) β§
if i = 0 then true else result.take i = impl (i-1)
-- program termination
β result, impl n = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: Nat β List Int)
-- inputs
(n: Nat) : Prop :=","theorem spec_isomorphism:
β impl,
(β n, problem_spec impl n) β
(β n, generated_spec impl n) :=",sorry,def implementation (n: Nat) : List Int:=,sorry,"-- #test implementation 3 = [1, 3, 2, 8]","theorem correctness
(n: Nat)
: problem_spec implementation n :=",sorry,,,
def digits(n: int) -> int,"Given a positive integer n, return the product of the odd digits.
Return 0 if all digits are even.
","[{""input"": 1, ""expected_output"": 1}, {""input"": 4, ""expected_output"": 0}, {""input"": 235, ""expected_output"": 15}]","def digits(n: int) -> int
""""""Given a positive integer n, return the product of the odd digits.
Return 0 if all digits are even.
""""""","def problem_spec
-- function signature
(impl: Nat β Nat)
-- inputs
(n: Nat) :=
-- spec
let spec (result: Nat) :=
0 < n β
(n < 10 β (n % 2 = 1 β result = n) β§ (n % 2 = 0 β result = 0)) β§
(10 β€ n β
let digit := n % 10;
let rest := n / 10;
(digit % 2 = 1 β
if (Nat.toDigits 10 rest).all (fun x => Even (x.toNat - '0'.toNat))
then impl rest = 0 β§ result = digit
else
result = impl rest * digit)
β§
(digit % 2 = 0 β
result = impl rest))
-- program termination
β result, impl n = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: Nat β Nat)
-- inputs
(n: Nat) : Prop :=","theorem spec_isomorphism:
β impl,
(β n, problem_spec impl n) β
(β n, generated_spec impl n) :=",sorry,def implementation (n: Nat) : Nat :=,sorry,"-- #test implementation 1 = 1
-- #test implementation 4 = 0
-- #test implementation 235 = 15","theorem correctness
(n: Nat)
: problem_spec implementation n :=",sorry,,,
def is_nested(string: str) -> Bool,"Create a function that takes a string as input which contains only parentheses.
The function should return True if and only if there is a valid subsequence of parentheses
where at least one parenthesis in the subsequence is nested.
","[{""input"": ""(())"", ""expected_output"": true}, {""input"": ""()))))))((((()"", ""expected_output"": false}, {""input"": ""()()"", ""expected_output"": false}, {""input"": ""()"", ""expected_output"": false}, {""input"": ""(()())"", ""expected_output"": true}, {""input"": ""(())(("", ""expected_output"": true}]","def is_nested(string: str) -> Bool
""""""Create a function that takes a string as input which contains only parentheses.
The function should return True if and only if there is a valid subsequence of parentheses
where at least one parenthesis in the subsequence is nested.
""""""","def problem_spec
-- function signature
(impl: String β Bool)
-- inputs
(string: String) :=
-- spec
let spec (result: Bool) :=
string.toList.all (fun x => x = '(' β¨ x = ')') β
result = true β
β x : String,
is_subsequence x.toList string.toList β§
balanced_paren_non_computable x '(' ')' β§
2 β€ count_max_paren_depth x
-- program termination
β result, impl string = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: String β Bool)
-- inputs
(lst: String) : Prop :=","theorem spec_isomorphism:
β impl,
(β string, problem_spec impl string) β
(β string, generated_spec impl string) :=",sorry,def implementation (lst: String) : Bool :=,sorry,"-- #test implementation ""(())"" = true
-- #test implementation ""()))))))((((()"" = false
-- #test implementation ""()()"" = false
-- #test implementation ""()"" = false
-- #test implementation ""(()())"" = true
-- #test implementation ""(())(("" = true","theorem correctness
(string: String)
: problem_spec implementation string :=",sorry,"/--
name: string_is_paren_balanced_helper
use: |
Helper function to check if a string is balanced with respect to parentheses.
problems:
- 1
- 6
- 132
sample_problems:
- 0
-/
def string_is_paren_balanced_helper
(paren_string: String) (num_open: Int): Bool
:=
-- Recursively check if the string is balanced
if paren_string.isEmpty then
num_open = 0
else
let c := paren_string.get! 0
if c == '(' then
string_is_paren_balanced_helper (paren_string.drop 1) (num_open + 1)
else if c == ')' then
string_is_paren_balanced_helper (paren_string.drop 1) (num_open - 1)
else
string_is_paren_balanced_helper (paren_string.drop 1) num_open
termination_by paren_string.length
decreasing_by
all_goals
{
rename_i h_non_empty_string
rw [String.drop_eq, String.length]
simp
rw [String.isEmpty_iff] at h_non_empty_string
by_cases h_paren_nil : paren_string.length β€ 0
rw [Nat.le_zero_eq] at h_paren_nil
rw [βstring_eq_iff_data_eq] at h_non_empty_string
have h_temp : """".data = [] := by simp
rw [h_temp] at h_non_empty_string
rw [String.length] at h_paren_nil
rw [List.length_eq_zero] at h_paren_nil
contradiction
have h_temp : paren_string.length > 0 := by linarith
assumption
}
/--
name: string_is_paren_balanced
use: |
Function to check if a string is balanced with respect to parentheses.
problems:
- 1
- 6
- 132
sample_problems:
- 0
-/
def string_is_paren_balanced
(paren_string: String): Bool
:=
string_is_paren_balanced_helper paren_string 0
/--
name: count_max_paren_depth_helper
use: |
Helper to count the maximum depth of parentheses in a string.
problems:
- 6
- 132
-/
def count_max_paren_depth_helper
(paren_string: String) (num_open: Int) (max_depth: Nat): Nat :=
-- Recursively count the maximum depth of parentheses
if paren_string.isEmpty then
max_depth
else
let c := paren_string.get! 0
if c == '(' then
let new_num_open := num_open + 1
count_max_paren_depth_helper (paren_string.drop 1) (new_num_open) (max_depth.max new_num_open.toNat)
else if c == ')' then
count_max_paren_depth_helper (paren_string.drop 1) (num_open - 1) max_depth
else
count_max_paren_depth_helper (paren_string.drop 1) num_open max_depth
termination_by paren_string.length
decreasing_by
all_goals
{
rename_i h_non_empty_string
rw [String.drop_eq, String.length]
simp
rw [String.isEmpty_iff] at h_non_empty_string
by_cases h_paren_nil : paren_string.length β€ 0
rw [Nat.le_zero_eq] at h_paren_nil
rw [βstring_eq_iff_data_eq] at h_non_empty_string
have h_temp : """".data = [] := by simp
rw [h_temp] at h_non_empty_string
rw [String.length] at h_paren_nil
rw [List.length_eq_zero] at h_paren_nil
contradiction
have h_temp : paren_string.length > 0 := by linarith
assumption
}
/--
name: count_max_paren_depth
use: |
Function to count the maximum depth of parentheses in a string.
problems:
- 6
- 132
-/
def count_max_paren_depth
(paren_string: String): Nat :=
count_max_paren_depth_helper paren_string 0 0
/--
name: is_subsequence
use: |
Helper to check if List Char xs is a subsequence of List Char ys.
problems:
- 132
-/
def is_subsequence (xs ys : List Char) : Bool :=
match xs, ys with
| [], _ => true
| _, [] => false
| x::xs', y::ys' =>
if x = y then is_subsequence xs' ys' else is_subsequence xs ys'",,
def sum_squares(lst: List[float]) -> int,"You are given a list of numbers.
You need to return the sum of squared numbers in the given list,
round each element in the list to the upper int(Ceiling) first.
","[{""input"": [1, 2, 3], ""expected_output"": 14}, {""input"": [1, 4, 9], ""expected_output"": 98}, {""input"": [1, 3, 5, 7], ""expected_output"": 84}, {""input"": [1.4, 4.2, 0], ""expected_output"": 29}, {""input"": [-2.4, 1, 1], ""expected_output"": 6}]","def sum_squares(lst: List[float]) -> int
""""""You are given a list of numbers.
You need to return the sum of squared numbers in the given list,
round each element in the list to the upper int(Ceiling) first.
""""""","def problem_spec
-- function signature
(impl: List Rat β Int)
-- inputs
(lst: List Rat) :=
-- spec
let spec (result: Int) :=
(lst = [] β result = 0) β§
(lst != [] β 0 β€ result - lst[0]!.ceil^2 β§ (impl (lst.drop 1) = (result - lst[0]!.ceil^2)))
-- program termination
β result, impl lst = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: List Rat β Int)
-- inputs
(lst: List Rat) : Prop :=","theorem spec_isomorphism:
β impl,
(β lst, problem_spec impl lst) β
(β lst, generated_spec impl lst) :=",sorry,def implementation (lst: List Rat) : Int :=,sorry,"-- #test implementation [1, 2, 3] = 14
-- #test implementation [1, 4, 9] = 98
-- #test implementation [1, 3, 5, 7] = 84
-- #test implementation [1.4, 4.2, 0] = 29
-- #test implementation [-2.4, 1, 1] = 6","theorem correctness
(lst: List Rat)
: problem_spec implementation lst :=",sorry,,,
def check_if_last_char_is_a_letter(txt: str) -> Bool,"Create a function that returns True if the last character
of a given string is an alphabetical character and is not
a part of a word, and False otherwise.
Note: ""word"" is a group of characters separated by space.
","[{""input"": ""apple pie"", ""expected_output"": false}, {""input"": ""apple pi e"", ""expected_output"": true}, {""input"": ""apple pi e "", ""expected_output"": false}, {""input"": """", ""expected_output"": false}]","def check_if_last_char_is_a_letter(txt: str) -> Bool
""""""Create a function that returns True if the last character
of a given string is an alphabetical character and is not
a part of a word, and False otherwise.
Note: ""word"" is a group of characters separated by space.
""""""","def problem_spec
-- function signature
(impl: String β Bool)
-- inputs
(txt: String) :=
-- spec
let spec (result: Bool) :=
let words := txt.splitOn "" "";
match words with
| [] => result = False
| [last_word] => (result β last_word.length = 1 β§ (let diff := (last_word.get 0).toLower.toNat - 'a'.toNat; 0 β€ diff β§ diff β€ 25))
| head::tail => result β (let tail_txt := String.join tail; impl tail_txt);
-- program terminates
β result, impl txt = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: String β Bool)
-- inputs
(txt: String) : Prop :=","theorem spec_isomorphism:
β impl,
(β txt, problem_spec impl txt) β
(β txt, generated_spec impl txt) :=",sorry,def implementation (txt: String) : Bool :=,sorry,"-- #test implementation ""apple pie"" = false
-- #test implementation ""apple pi e"" = true
-- #test implementation ""apple pi e "" = false
-- #test implementation """" = false","theorem correctness
(txt: String)
: problem_spec implementation txt :=",sorry,,,
def can_arrange(arr: List[int]) -> int,"Create a function which returns the largest index of an element which
is not greater than or equal to the element immediately preceding it. If
no such element exists then return -1. The given array will not contain
duplicate values.
","[{""input"": [1, 2, 4, 3, 5], ""expected_output"": 3}, {""input"": [1, 2, 3], ""expected_output"": -1}]","def can_arrange(arr: List[int]) -> int
""""""Create a function which returns the largest index of an element which
is not greater than or equal to the element immediately preceding it. If
no such element exists then return -1. The given array will not contain
duplicate values.
""""""","def problem_spec
-- function signature
(impl: List Int β Int)
-- inputs
(arr: List Int) :=
-- spec
let spec (result: Int) :=
Β¬arr.any (fun x => 1 < arr.count x) β
(arr.length = 0 β¨ arr.length = 1 β result = -1) β§
(1 < arr.length β
let last := arr.length-1;
let i := if arr[last]! < arr[last-1]! then Int.ofNat last else -1;
result = max (impl (arr.take last)) i);
-- program termination
β result, impl arr = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: List Int β Int)
-- inputs
(arr: List Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β arr, problem_spec impl arr) β
(β arr, generated_spec impl arr) :=",sorry,def implementation (arr: List Int) : Int :=,sorry,"-- #test implementation [1, 2, 4, 3, 5] = 3
-- #test implementation [1, 2, 3] = -1","theorem correctness
(arr: List Int)
: problem_spec implementation arr :=",sorry,,,
"def largest_smallest_integers(lst: List[int]) -> Tuple[ Optional[Int], Optional[Int] ]","Create a function that returns a tuple (a, b), where 'a' is
the largest of negative integers, and 'b' is the smallest
of positive integers in a list.
If there is no negative or positive integers, return them as None.
","[{""input"": [2, 4, 1, 3, 5, 7], ""expected_output"": ""(None, 1)""}, {""input"": [], ""expected_output"": ""(None, None)""}, {""input"": [0], ""expected_output"": ""(None, None)""}]","def largest_smallest_integers(lst: List[int]) -> Tuple[ Optional[Int], Optional[Int] ]
""""""Create a function that returns a tuple (a, b), where 'a' is
the largest of negative integers, and 'b' is the smallest
of positive integers in a list.
If there is no negative or positive integers, return them as None.
""""""","def problem_spec
-- function signature
(impl: List Int β Option Int Γ Option Int)
-- inputs
(lst: List Int) :=
-- spec
let spec (result: Option Int Γ Option Int) :=
let (a, b) := result;
(match a with
| none => Β¬(β i, i β lst β§ i < 0)
| some a => a < 0 β§ a β lst β§ β i, i β lst β§ i < 0 β i β€ a) β§
(match b with
| none => Β¬(β i, i β lst β§ 0 < i)
| some b => 0 < b β§ b β lst β§ β i, i β lst β§ 0 < i β b β€ i)
-- program termination
β result, impl lst = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: List Int β Option Int Γ Option Int)
-- inputs
(lst: List Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β lst, problem_spec impl lst) β
(β lst, generated_spec impl lst) :=",sorry,def implementation (lst: List Int) : (Option Int Γ Option Int) :=,sorry,"-- #test implementation [2, 4, 1, 3, 5, 7] = (none, some 1)
-- #test implementation [] = (none, none)
-- #test implementation [0] = (none, none)","theorem correctness
(lst: List Int)
: problem_spec implementation lst :=",sorry,,,
def is_equal_to_sum_even(n: int) -> Bool,"Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers
","[{""input"": 4, ""expected_output"": false}, {""input"": 6, ""expected_output"": false}, {""input"": 8, ""expected_output"": true}]","def is_equal_to_sum_even(n: int) -> Bool
""""""Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers
""""""","def problem_spec
-- function signature
(impl: Int β Bool)
-- inputs
(n: Int) :=
-- spec
let spec (result: Bool) :=
let sum_exists := β a b c d : Nat,
Even a β§
Even b β§
Even c β§
Even d β§
(a + b + c + d = n);
result = true β sum_exists
-- program termination
β result, impl n = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: Int β Bool)
-- inputs
(n: Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β n, problem_spec impl n) β
(β n, generated_spec impl n) :=",sorry,def implementation (n: Int) : Bool :=,sorry,"-- #test implementation 4 = false
-- #test implementation 6 = false
-- #test implementation 8 = true","theorem correctness
(n: Int)
: problem_spec implementation n :=",sorry,,,
def special_factorial(n: int) -> int,"The Brazilian factorial is defined as:
brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!
where n > 0. Please write a function that computes the Brazilian factorial.
","[{""input"": 4, ""expected_output"": 288}]","def special_factorial(n: int) -> int
""""""The Brazilian factorial is defined as:
brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!
where n > 0. Please write a function that computes the Brazilian factorial.
""""""","def problem_spec
-- function signature
(impl: Nat β Nat)
-- inputs
(n: Nat) :=
-- spec
let spec (result: Nat) :=
let factorial := Nat.factorial n;
(0 < n β result / factorial = impl (n - 1)) β§
(n = 0 β result = 1);
-- program termination
β result, impl n = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: Nat β Nat)
-- inputs
(n: Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β n, problem_spec impl n) β
(β n, generated_spec impl n) :=",sorry,def implementation (n: Nat) : Nat :=,sorry,-- #test implementation 4 = 288,"theorem correctness
(n: Nat)
: problem_spec implementation n :=",sorry,,,
def fix_spaces(text: str) -> str,"Given a string text, replace all spaces in it with underscores,
and if a string has more than 2 consecutive spaces,
then replace all consecutive spaces with -
","[{""input"": ""Example"", ""expected_output"": ""Example""}, {""input"": ""Example 1"", ""expected_output"": ""Example_1""}, {""input"": "" Example 2"", ""expected_output"": ""_Example_2""}, {""input"": "" Example 3"", ""expected_output"": ""_Example-3""}]","def fix_spaces(text: str) -> str
""""""Given a string text, replace all spaces in it with underscores,
and if a string has more than 2 consecutive spaces,
then replace all consecutive spaces with -
""""""","def problem_spec
-- function signature
(impl: String β String)
-- inputs
(text: String) :=
-- spec
let spec (result: String) :=
(result = """" β text = """") β§
(result β """" β (
(β pref s, text = pref ++ s
β§ pref.length = 1
β§ pref β "" ""
β§ result = pref ++ impl s)
β¨
(β pref s : String, text = pref ++ s β§ pref β """" β§ (β ch, ch β pref.toList β ch = ' ')
β§ let k := pref.length;
(k β€ 2 β result = (String.replicate k '_') ++ (impl (text.drop k)))
β§ (2 < k β result = ""-"" ++ (impl (text.drop k)))) )
)
-- program termination
β result, impl text = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: String β String)
-- inputs
(text: String) : Prop :=","theorem spec_isomorphism:
β impl,
(β text, problem_spec impl text) β
(β text, generated_spec impl text) :=",sorry,def implementation (text: String) : String :=,sorry,"-- #test implementation ""Example"" = ""Example""
-- #test implementation ""Example 1"" = ""Example_1""
-- #test implementation "" Example 2"" = ""_Example_2""
-- #test implementation "" Example 3"" = ""_Example-3""","theorem correctness
(text: String)
: problem_spec implementation text :=",sorry,,,
def file_name_check(file_name: str) -> str,"Create a function which takes a string representing a file's name, and returns
'Yes' if the the file's name is valid, and returns 'No' otherwise.
A file's name is considered to be valid if and only if all the following conditions
are met:
- There should not be more than three digits ('0'-'9') in the file's name.
- The file's name contains exactly one dot '.'
- The substring before the dot should not be empty, and it starts with a letter from
the latin alphapet ('a'-'z' and 'A'-'Z').
- The substring after the dot should be one of these: ['txt', 'exe', 'dll']
","[{""input"": ""example.txt"", ""expected_output"": ""Yes""}, {""input"": ""1example.dll"", ""expected_output"": ""No""}]","def file_name_check(file_name: str) -> str
""""""Create a function which takes a string representing a file's name, and returns
'Yes' if the the file's name is valid, and returns 'No' otherwise.
A file's name is considered to be valid if and only if all the following conditions
are met:
- There should not be more than three digits ('0'-'9') in the file's name.
- The file's name contains exactly one dot '.'
- The substring before the dot should not be empty, and it starts with a letter from
the latin alphapet ('a'-'z' and 'A'-'Z').
- The substring after the dot should be one of these: ['txt', 'exe', 'dll']
""""""","def problem_spec
-- function signature
(impl: String β String)
-- inputs
(file_name : String) :=
-- spec
let spec (result: String) :=
let valid := (file_name.toList.filter Char.isDigit).length β€ 3 β§
(file_name.toList.filter (Β· = '.')).length = 1 β§
β before after : String,
file_name = before ++ ""."" ++ after β§
before != """" β§
Char.isAlpha (before.get! 0) β§
(after = ""txt"" β¨ after = ""exe"" β¨ after = ""dll"")
(result = ""Yes"" β valid) β§
(result = ""No"" β Β¬valid)
-- program termination
β result, impl file_name = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: String β String)
-- inputs
(file_name: String) : Prop :=","theorem spec_isomorphism:
β impl,
(β file_name, problem_spec impl file_name) β
(β file_name, generated_spec impl file_name) :=",sorry,def implementation (file_name : String) : String :=,sorry,"-- #test implementation ""example.txt"" = ""Yes""
-- #test implementation ""1example.dll"" = ""No""","theorem correctness
(file_name : String)
: problem_spec implementation file_name :=",sorry,,,
def sum_squares(lst: List[int]) -> int,"This function will take a list of integers. For all entries in the list, the function shall square the integer entry if its index is a
multiple of 3 and will cube the integer entry if its index is a multiple of 4 and not a multiple of 3. The function will not
change the entries in the list whose indexes are not a multiple of 3 or 4. The function shall then return the sum of all entries.
","[{""input"": [1, 2, 3], ""expected_output"": 6}, {""input"": [], ""expected_output"": 0}, {""input"": [-1, -5, 2, -1, -5], ""expected_output"": -126}]","def sum_squares(lst: List[int]) -> int
""""""This function will take a list of integers. For all entries in the list, the function shall square the integer entry if its index is a
multiple of 3 and will cube the integer entry if its index is a multiple of 4 and not a multiple of 3. The function will not
change the entries in the list whose indexes are not a multiple of 3 or 4. The function shall then return the sum of all entries.
""""""","def problem_spec
-- function signature
(impl: List Int β Int)
-- inputs
(lst : List Int) :=
-- spec
let spec (result : Int) :=
let last := lst.length-1;
(lst = [] β result = 0) β§
(lst β [] β§ last % 3 = 0 β result = lst[last]! ^ 2 + impl (lst.take last)) β§
(lst β [] β§ last % 4 = 0 β§ last % 3 != 0 β result = lst[last]! ^ 3 + impl (lst.take last)) β§
(lst β [] β§ last % 3 != 0 β§ last % 4 != 0 β result = lst[last]! + impl (lst.take last))
-- program termination
β result, impl lst = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: List Int β Int)
-- inputs
(lst : List Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β lst, problem_spec impl lst) β
(β lst, generated_spec impl lst) :=",sorry,def implementation (lst : List Int) : Int :=,sorry,"-- #test implementation [1, 2, 3] = 6
-- #test implementation [] = 0
-- #test implementation [-1, -5, 2, -1, -5] = -126","theorem correctness
(lst : List Int)
: problem_spec implementation lst :=",sorry,,,
def words_in_sentence(sentence: str) -> str,"You are given a string representing a sentence,
the sentence contains some words separated by a space,
and you have to return a string that contains the words from the original sentence,
whose lengths are prime numbers,
the order of the words in the new string should be the same as the original one.
Constraints:
* 1 <= len(sentence) <= 100
* sentence contains only letters
","[{""input"": ""This is a test"", ""expected_output"": ""is""}, {""input"": ""lets go for swimming"", ""expected_output"": ""go for""}]","def words_in_sentence(sentence: str) -> str
""""""You are given a string representing a sentence,
the sentence contains some words separated by a space,
and you have to return a string that contains the words from the original sentence,
whose lengths are prime numbers,
the order of the words in the new string should be the same as the original one.
Constraints:
* 1 <= len(sentence) <= 100
* sentence contains only letters
""""""","def problem_spec
-- function signature
(impl: String β String)
-- inputs
(sentence: String) :=
-- spec
let spec (result: String) :=
let words := sentence.splitOn;
let result_words := result.splitOn;
1 β€ sentence.length β sentence.length β€ 100 β
sentence.all (fun x => Char.isAlpha x) β
result_words.length β€ words.length β§
(β word β result_words, word β words β§ Nat.Prime word.length) β§
match result_words with
| [] => β word β words, Β¬(Nat.Prime word.length)
| head :: tail => if Nat.Prime head.length β§ head = words[0]! then String.join tail = impl (String.join (words.drop 1))
else result = impl (String.join (words.drop 1))
-- program termination
β result, impl sentence = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: String β String)
-- inputs
(sentence: String) : Prop :=","theorem spec_isomorphism:
β impl,
(β sentence, problem_spec impl sentence) β
(β sentence, generated_spec impl sentence) :=",sorry,def implementation (sentence : String) : String :=,sorry,"-- #test implementation ""This is a test"" = ""is""
-- #test implementation ""lets go for swimming"" = ""go for""","theorem correctness
(sentence : String)
: problem_spec implementation sentence :=",sorry,,,
"def simplify(x: str, n: str) -> Bool","Your task is to implement a function that will simplify the expression
x * n. The function returns True if x * n evaluates to a whole number and False
otherwise. Both x and n, are string representation of a fraction, and have the following format,
<numerator>/<denominator> where both numerator and denominator are positive whole numbers.
You can assume that x, and n are valid fractions, and do not have zero as denominator.
","[{""input"": [""1/5"", ""5/1""], ""expected_output"": true}, {""input"": [""1/6"", ""2/1""], ""expected_output"": false}, {""input"": [""7/10"", ""10/2""], ""expected_output"": false}]","def simplify(x: str, n: str) -> Bool
""""""Your task is to implement a function that will simplify the expression
x * n. The function returns True if x * n evaluates to a whole number and False
otherwise. Both x and n, are string representation of a fraction, and have the following format,
<numerator>/<denominator> where both numerator and denominator are positive whole numbers.
You can assume that x, and n are valid fractions, and do not have zero as denominator.
""""""","def problem_spec
-- function signature
(impl: String β String β Bool)
-- inputs
(x: String) (n: String) :=
-- spec
let spec (result: Bool) :=
let fx := x.splitOn ""/"";
let fn := n.splitOn ""/"";
fx.length = 2 β fn.length = 2 β
fx.all String.isNat β fn.all String.isNat β
let p1 := fx[0]!.toNat!;
let q1 := fx[1]!.toNat!;
let p2 := fn[0]!.toNat!;
let q2 := fn[1]!.toNat!;
q1 β 0 β q2 β 0 β
(result β (β k, k * p1 * p2 = q1 * q2))
-- program termination
β result, impl x n = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: String β String β Bool)
-- inputs
(x: String) (n: String) : Prop :=","theorem spec_isomorphism:
β impl,
(β x n, problem_spec impl x n) β
(β x n, generated_spec impl x n) :=",sorry,def implementation (x: String) (n: String) : Bool :=,sorry,"-- #test implementation ""1/5"" ""5/1"" = True
-- #test implementation ""1/6"" ""2/1"" = False
-- #test implementation ""7/10"" ""10/2"" = False","theorem correctness
(x: String) (n: String)
: problem_spec implementation x n :=",sorry,,,
def order_by_points(nums: List[int]) -> List[int],"Write a function which sorts the given list of integers
in ascending order according to the sum of their digits.
Note: if there are several items with similar sum of their digits,
order them based on their index in original list.
","[{""input"": [1, 11, -1, -11, -12], ""expected_output"": [-1, -11, 1, -12, 11]}, {""input"": [], ""expected_output"": []}]","def order_by_points(nums: List[int]) -> List[int]
""""""Write a function which sorts the given list of integers
in ascending order according to the sum of their digits.
Note: if there are several items with similar sum of their digits,
order them based on their index in original list.
""""""","def problem_spec
-- function signature
(impl: List Int β List Int)
-- inputs
(nums: List Int) :=
-- spec
let spec (result: List Int) :=
List.Perm nums result β§
match result with
| [] => nums = []
| head::tail =>
let head_sum := digit_sum head;
(β num β nums,
let sum := digit_sum num;
sum > head_sum β¨
(sum = head_sum β§ nums.indexOf num β₯ nums.indexOf head))
β§ impl (nums.erase head) = tail
-- program termination
β result, impl nums = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: List Int β List Int)
-- inputs
(nums: List Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β nums, problem_spec impl nums) β
(β nums, generated_spec impl nums) :=",sorry,def implementation (nums: List Int) : List Int :=,sorry,"-- #test implementation [1, 11, -1, -11, -12] = [-1, -11, 1, -12, 11]
-- #test implementation [] = []","theorem correctness
(nums: List Int)
: problem_spec implementation nums :=",sorry,"/--
name: digit_sum
use: |
Helper to sum the digits of a number. If the number is negative, the
negative sign is treated as part of the first digit.
problems:
- 145
-/
def digit_sum (n : Int) : Int :=
let ds := (toString n.natAbs).toList.map fun c => c.toNat - Char.toNat '0'
match ds with
| [] => 0
| d :: ds' =>
let tail := ds'.foldl (Β· + Β·) 0
if n < 0 then Int.ofNat tail - Int.ofNat d
else Int.ofNat (d + tail)",,
def specialFilter(nums: List[int]) -> int,"Write a function that takes an array of numbers as input and returns
the number of elements in the array that are greater than 10 and both
first and last digits of a number are odd (1, 3, 5, 7, 9).
","[{""input"": [15, -73, 14, -15], ""expected_output"": 1}, {""input"": [33, -2, -3, 45, 21, 109], ""expected_output"": 2}]","def specialFilter(nums: List[int]) -> int
""""""Write a function that takes an array of numbers as input and returns
the number of elements in the array that are greater than 10 and both
first and last digits of a number are odd (1, 3, 5, 7, 9).
""""""","def problem_spec
-- function signature
(impl: List Int β Int)
-- inputs
(nums: List Int) :=
-- spec
let spec (result: Int) :=
match nums with
| [] => result = 0
| head::tail =>
let first_digit := (toString head.natAbs).toList[0]!.toNat - Char.toNat '0';
let last_digit := head % 10;
let valid := head > 10 β§ Odd first_digit β§ Odd last_digit
if valid then result = 1 + impl tail else result = impl tail
-- program termination
β result, impl nums = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: List Int β Int)
-- inputs
(nums: List Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β nums, problem_spec impl nums) β
(β nums, generated_spec impl nums) :=",sorry,def implementation (nums: List Int) : Int :=,sorry,"-- #test implementation [15, -73, 14, -15] = 1
-- #test implementation [33, -2, -3, 45, 21, 109] = 2","theorem correctness
(nums: List Int)
: problem_spec implementation nums :=",sorry,,,
def get_max_triples(n: int) -> int,"You are given a positive integer n. You have to create an integer array a of length n.
For each i (1 β€ i β€ n), the value of a[i] = i * i - i + 1.
Return the number of triples (a[i], a[j], a[k]) of a where i < j < k,
and a[i] + a[j] + a[k] is a multiple of 3.
","[{""input"": 5, ""expected_output"": 1}]","def get_max_triples(n: int) -> int
""""""You are given a positive integer n. You have to create an integer array a of length n.
For each i (1 β€ i β€ n), the value of a[i] = i * i - i + 1.
Return the number of triples (a[i], a[j], a[k]) of a where i < j < k,
and a[i] + a[j] + a[k] is a multiple of 3.
""""""","def problem_spec
-- function signature
(impl: Nat β Nat)
-- inputs
(n: Nat) :=
-- spec
let spec (result: Nat) :=
β (S : Finset (Nat Γ Nat Γ Nat)), S.card = result β§
β (triple: Nat Γ Nat Γ Nat),
let (i, j, k) := triple;
let a_i := i * i - i + 1;
let a_j := j * j - j + 1;
let a_k := k * k - k + 1;
(1 β€ i β§ i < j β§ j < k β§ k β€ n β§
(a_i + a_j + a_k) % 3 = 0)
β triple β S
-- program termination
β result, impl n = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: Nat β Nat)
-- inputs
(nums: Nat) : Prop :=","theorem spec_isomorphism:
β impl,
(β n, problem_spec impl n) β
(β n, generated_spec impl n) :=",sorry,def implementation (n: Nat) : Nat :=,sorry,-- #test implementation 5 = 1,"theorem correctness
(n: Nat)
: problem_spec implementation n :=",sorry,,,
"def bf(planet1: str, planet2: str) -> List[str]","There are eight planets in our solar system: the closest to the Sun
is Mercury, the next one is Venus, then Earth, Mars, Jupiter, Saturn,
Uranus, Neptune.
Write a function that takes two planet names as strings planet1 and planet2.
The function should return a tuple containing all planets whose orbits are
located between the orbit of planet1 and the orbit of planet2, sorted by
the proximity to the sun.
The function should return an empty tuple if planet1 or planet2
are not correct planet names.
","[{""input"": ""(\""Jupiter\"", \""Neptune\"")"", ""expected_output"": ""(\""Saturn\"", \""Uranus\"")""}, {""input"": ""(\""Earth\"", \""Mercury\"")"", ""expected_output"": ""(\""Venus\"")""}, {""input"": ""(\""Mercury\"", \""Uranus\"")"", ""expected_output"": ""(\""Venus\"", \""Earth\"", \""Mars\"", \""Jupiter\"", \""Saturn\"")""}]","def bf(planet1: str, planet2: str) -> List[str]
""""""There are eight planets in our solar system: the closest to the Sun
is Mercury, the next one is Venus, then Earth, Mars, Jupiter, Saturn,
Uranus, Neptune.
Write a function that takes two planet names as strings planet1 and planet2.
The function should return a tuple containing all planets whose orbits are
located between the orbit of planet1 and the orbit of planet2, sorted by
the proximity to the sun.
The function should return an empty tuple if planet1 or planet2
are not correct planet names.
""""""","def problem_spec
-- function signature
(impl: String β String β List String)
-- inputs
(planet1: String)
(planet2: String) :=
-- spec
let spec (result: List String) :=
let planets := [""Mercury"", ""Venus"", ""Earth"", ""Mars"", ""Jupiter"", ""Saturn"", ""Uranus"", ""Neptune""];
if planet1 β planets β¨ planet2 β planets then
result = []
else
let index1 := planets.indexOf planet1;
let index2 := planets.indexOf planet2;
let minIdx := if index1 < index2 then index1 else index2;
let maxIdx := if index1 < index2 then index2 else index1;
(β str β result, str β planets) β§
(β planet β planets, planet β result β
planets.indexOf planet < maxIdx β§
minIdx < planets.indexOf planet) β§
result.Sorted (fun a b => planets.indexOf a < planets.indexOf b)
-- program termination
β result, impl planet1 planet2 = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: String β String β List String)
-- inputs
(planet1: String)
(planet2: String) : Prop :=","theorem spec_isomorphism:
β impl,
(β planet1 planet2, problem_spec impl planet1 planet2) β
(β planet1 planet2, generated_spec impl planet1 planet2) :=",sorry,def implementation (planet1: String) (planet2: String) : List String :=,sorry,"-- #test implementation ""Jupiter"" ""Neptune"" = [""Saturn"", ""Uranus""]
-- #test implementation ""Earth"" ""Mercury"" = [""Venus""]
-- #test implementation ""Mercury"" ""Uranus"" = [""Venus"", ""Earth"", ""Mars"", ""Jupiter"", ""Saturn""]","theorem correctness
(planet1: String)
(planet2: String)
: problem_spec implementation planet1 planet2 :=",sorry,,,
def sorted_list_sum(lst: List[str]) -> List[str],"Write a function that accepts a list of strings as a parameter,
deletes the strings that have odd lengths from it,
and returns the resulted list with a sorted order,
The list is always a list of strings and never an array of numbers,
and it may contain duplicates.
The order of the list should be ascending by length of each word, and you
should return the list sorted by that rule.
If two words have the same length, sort the list alphabetically.
The function should return a list of strings in sorted order.
You may assume that all words will have the same length.
","[{""input"": [""aa"", ""a"", ""aaa""], ""output"": [""aa""]}, {""input"": [""ab"", ""a"", ""aaa"", ""cd""], ""output"": [""ab"", ""cd""]}]","def sorted_list_sum(lst: List[str]) -> List[str]
""""""Write a function that accepts a list of strings as a parameter,
deletes the strings that have odd lengths from it,
and returns the resulted list with a sorted order,
The list is always a list of strings and never an array of numbers,
and it may contain duplicates.
The order of the list should be ascending by length of each word, and you
should return the list sorted by that rule.
If two words have the same length, sort the list alphabetically.
The function should return a list of strings in sorted order.
You may assume that all words will have the same length.
""""""","def problem_spec
-- function signature
(impl: List String β List String)
-- inputs
(lst: List String) :=
-- spec
let spec (result: List String) :=
match result with
| [] => β str β lst, Odd str.length
| head::tail =>
Even head.length β§
(β str β lst,
Odd str.length β¨
str.length > head.length β¨
str.length = head.length β§ str β₯ head)
β§ impl (lst.erase head) = tail
-- program termination
β result, impl lst = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: List String β List String)
-- inputs
(lst: List String) : Prop :=","theorem spec_isomorphism:
β impl,
(β lst, problem_spec impl lst) β
(β lst, generated_spec impl lst) :=",sorry,def implementation (lst: List String) : List String :=,sorry,"-- #test implementation [""aa"", ""a"", ""aaa""] = [""aa""]
-- #test implementation [""ab"", ""a"", ""aaa"", ""cd""] = [""ab"", ""cd""]","theorem correctness
(lst: List String)
: problem_spec implementation lst :=",sorry,,,
"def x_or_y(int n, int x, int y) -> int","A simple program which should return the value of x if n is
a prime number and should return the value of y otherwise.
","[{""input"": [7, 34, 12], ""expected_output"": 34}, {""input"": [15, 8, 5], ""expected_output"": 5}]","def x_or_y(int n, int x, int y) -> int
""""""A simple program which should return the value of x if n is
a prime number and should return the value of y otherwise.
""""""","def problem_spec
-- function signature
(impl: Int β Int β Int β Int)
-- inputs
(n x y: Int) :=
-- spec
let spec (result: Int) :=
(result = x β Nat.Prime n.toNat) β§
(result = y β (Β¬ Nat.Prime n.toNat β¨ n β€ 1))
-- program terminates
β result, impl n x y = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: Int β Int β Int β Int)
-- inputs
(n x y: Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β n x y, problem_spec impl n x y) β
(β n x y, generated_spec impl n x y) :=",sorry,def implementation (n x y: Int) : Int :=,sorry,"-- #test implementation 7 34 12 = 34
-- #test implementation 15 8 5 = 5","theorem correctness
(n x y: Int)
: problem_spec implementation n x y :=",sorry,,,
def double_the_difference(numbers: List[float]) -> Int,"Given a list of numbers, return the sum of squares of the numbers
in the list that are odd. Ignore numbers that are negative or not integers.
","[{""input"": [1, 3, 2, 0], ""expected_output"": 10}, {""input"": [""-1. -2"", 0], ""expected_output"": 0}, {""input"": [9, -2], ""expected_output"": 81}, {""input"": [0], ""expected_output"": 0}]","def double_the_difference(numbers: List[float]) -> Int
""""""Given a list of numbers, return the sum of squares of the numbers
in the list that are odd. Ignore numbers that are negative or not integers.
""""""","def problem_spec
-- function signature
(impl: List Rat β Int)
-- inputs
(numbers: List Rat) :=
let isEven (n : Rat) := n % 2 = 0;
let isNegative (n : Rat) := n < 0;
let isNotInteger (n : Rat) := Β¬ n.isInt;
-- spec
let spec (result: Int) :=
0 < numbers.length β
0 β€ result β§
if numbers.length = 1
then result = if (isEven numbers[0]! β¨ isNegative numbers[0]! β¨ isNotInteger numbers[0]!) then (0 : Int) else numbers[0]!.floor ^ 2
else result = if (isEven numbers[0]! β¨ isNegative numbers[0]! β¨ isNotInteger numbers[0]!) then (0 : Int) else numbers[0]!.floor ^ 2 + impl numbers.tail
-- program terminates
β result, impl numbers = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: List Rat β Int)
-- inputs
(numbers: List Rat) : Prop :=","theorem spec_isomorphism:
β impl,
(β numbers, problem_spec impl numbers) β
(β numbers, generated_spec impl numbers) :=",sorry,def implementation (numbers: List Rat) : Int :=,sorry,"-- #test implementation ([1, 3, 2, 0]: List Rat) = (10: Int)
-- #test implementation ([-1, -2, 0]: List Int) = (0: Int)
-- #test implementation ([9, -2]: List Int) = 81
-- #test implementation ([0]: List Int) = 0","theorem correctness
(numbers: List Rat)
: problem_spec implementation numbers :=",sorry,,,
"def compare(scores: List float, guesses: List float) -> List [float]","I think we all remember that feeling when the result of some long-awaited
event is finally known. The feelings and thoughts you have at that moment are
definitely worth noting down and comparing.
Your task is to determine if a person correctly guessed the results of a number of matches.
You are given two arrays of scores and guesses of equal length, where each index shows a match.
Return an array of the same length denoting how far off each guess was. If they have guessed correctly,
the value is 0, and if not, the value is the absolute difference between the guess and the score.
Note: to reviewer, the reason for not using |.| to get the absolute value is to avoid leaking the implementation.
","[{""input"": [[1, 2, 3, 4, 5, 1], [1, 2, 3, 4, 2, -2]], ""expected_output"": [0, 0, 0, 0, 3, 3]}, {""input"": [[0, 5, 0, 0, 0, 4], [4, 1, 1, 0, 0, -2]], ""expected_output"": [4, 4, 1, 0, 0, 6]}]","def compare(scores: List float, guesses: List float) -> List [float]
""""""I think we all remember that feeling when the result of some long-awaited
event is finally known. The feelings and thoughts you have at that moment are
definitely worth noting down and comparing.
Your task is to determine if a person correctly guessed the results of a number of matches.
You are given two arrays of scores and guesses of equal length, where each index shows a match.
Return an array of the same length denoting how far off each guess was. If they have guessed correctly,
the value is 0, and if not, the value is the absolute difference between the guess and the score.
Note: to reviewer, the reason for not using |.| to get the absolute value is to avoid leaking the implementation.
""""""","def problem_spec
-- function signature
(impl: List Rat β List Rat β List Rat)
-- inputs
(scores guesses: List Rat) :=
-- spec
let spec (result: List Rat) :=
result.length = scores.length β§
scores.length = guesses.length β§
β i, i < scores.length β
if scores[i]! > guesses[i]! then result[i]! + guesses[i]! = scores[i]!
else result[i]! + scores[i]! = guesses[i]!
-- program terminates
β result, impl scores guesses = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: List Rat β List Rat β List Rat)
-- inputs
(scores guesses: List Rat) : Prop :=","theorem spec_isomorphism:
β impl,
(β scores guesses, problem_spec impl scores guesses) β
(β scores guesses, generated_spec impl scores guesses) :=",sorry,def implementation (scores guesses: List Rat) : List Rat :=,sorry,"-- #test implementation [1,2,3,4,5,1] [1,2,3,4,2,-2] = [0,0,0,0,3,3]
-- #test implementation [0,5,0,0,0,4] [4,1,1,0,0,-2] = [4,4,1,0,0,6]","theorem correctness
(scores guesses: List Rat)
: problem_spec implementation scores guesses :=",sorry,,,
"def Strongest_Extension(class_name: String, extensions: List[String]) -> String","You will be given the name of a class (a string) and a list of extensions.
The extensions are to be used to load additional classes to the class. The
strength of the extension is as follows: Let CAP be the number of the uppercase
letters in the extension's name, and let SM be the number of lowercase letters
in the extension's name, the strength is given by the fraction CAP - SM.
You should find the strongest extension and return a string in this
format: ClassName.StrongestExtensionName.
If there are two or more extensions with the same strength, you should
choose the one that comes first in the list.
For example, if you are given ""Slices"" as the class and a list of the
extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should
return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension
(its strength is -1).
","[{""input"": [""my_class"", [""AA"", ""Be"", ""CC""]], ""expected_output"": ""my_class.AA""}]","def Strongest_Extension(class_name: String, extensions: List[String]) -> String
""""""You will be given the name of a class (a string) and a list of extensions.
The extensions are to be used to load additional classes to the class. The
strength of the extension is as follows: Let CAP be the number of the uppercase
letters in the extension's name, and let SM be the number of lowercase letters
in the extension's name, the strength is given by the fraction CAP - SM.
You should find the strongest extension and return a string in this
format: ClassName.StrongestExtensionName.
If there are two or more extensions with the same strength, you should
choose the one that comes first in the list.
For example, if you are given ""Slices"" as the class and a list of the
extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should
return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension
(its strength is -1).
""""""","def problem_spec
-- function signature
(impl: String β List String β String)
-- inputs
(class_name: String)
(extensions: List String) :=
let strength (extension: String) :=
let cap := (extension.toList.filter (fun c => c.isUpper)).length;
let sm := (extension.toList.filter (fun c => c.isLower)).length;
cap - sm;
-- spec
let spec (result: String) :=
let last_pos := result.revPosOf '.';
0 < extensions.length β§ extensions.all (fun x => 0 < x.length) β§ 0 < class_name.length β
0 < result.length β§
last_pos.isSome β§
let class_name' := result.take (last_pos.get!).byteIdx;
let extension_name := result.drop ((last_pos.get!).byteIdx + 1);
class_name' = class_name β§
extension_name β extensions β§
let strength_of_extensions := extensions.map (fun ext => strength ext);
β j : Nat, j < extensions.length β§
extensions[j]! = extension_name β§
(β i : Nat, i < j β strength_of_extensions[i]! < strength_of_extensions[j]!)
β§ strength_of_extensions[j]! = strength_of_extensions.max?.get!;
-- program terminates
β result, impl class_name extensions = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: String β List String β String)
-- inputs
(class_name: String)
(extensions: List String) : Prop :=","theorem spec_isomorphism:
β impl,
(β class_name extensions, problem_spec impl class_name extensions) β
(β class_name extensions, generated_spec impl class_name extensions) :=",sorry,def implementation (class_name: String) (extensions: List String) : String :=,sorry,"-- #test implementation 'my_class', ['AA', 'Be', 'CC'] = 'my_class.AA'","theorem correctness
(class_name: String)
(extensions: List String)
: problem_spec implementation class_name extensions :=",sorry,,,
"def cycpattern_check(String a, String b) -> Bool","You are given 2 words. You need to return True if the second word or any of its rotations is a substring in the first word, else False
","[{""input"": [""abcd"", ""abd""], ""expected_output"": false}, {""input"": [""hello"", ""ell""], ""expected_output"": true}, {""input"": [""whassup"", ""psus""], ""expected_output"": false}, {""input"": [""abab"", ""baa""], ""expected_output"": true}, {""input"": [""efef"", ""eeff""], ""expected_output"": false}, {""input"": [""himenss"", ""simen""], ""expected_output"": true}]","def cycpattern_check(String a, String b) -> Bool
""""""You are given 2 words. You need to return True if the second word or any of its rotations is a substring in the first word, else False
""""""","def problem_spec
-- function signature
(impl: String β String β Bool)
-- inputs
(a b: String) :=
-- spec
let spec (result: Bool) :=
(b.length = 0 β result) β§
(0 < b.length β
result β ((b.length β€ a.length) β§
(β i : Nat, i < b.length β§
let b_rotation := b.drop i ++ b.take i;
a.containsSubstr b_rotation)));
-- program terminates
β result, impl a b = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: String β String β Bool)
-- inputs
(a b: String) : Prop :=","theorem spec_isomorphism:
β impl,
(β a b, problem_spec impl a b) β
(β a b, generated_spec impl a b) :=",sorry,def implementation (a b: String) : Bool :=,sorry,"-- #test implementation ""abcd"" ""abd"" = False
-- #test implementation ""hello"" ""ell"" = True
-- #test implementation ""whassup"" ""psus"" = False
-- #test implementation ""abab"" ""baa"" = True
-- #test implementation ""efef"" ""eeff"" = False
-- #test implementation ""himenss"" ""simen"" = True","theorem correctness
(a b: String)
: problem_spec implementation a b :=",sorry,,,
"def even_odd_count(num: int) -> Tuple[int, int]","Given an integer. return a tuple that has the number of even and odd digits respectively.
","[{""input"": -12, ""expected_output"": [1, 1]}, {""input"": 123, ""expected_output"": [1, 2]}]","def even_odd_count(num: int) -> Tuple[int, int]
""""""Given an integer. return a tuple that has the number of even and odd digits respectively.
""""""","def problem_spec
-- function signature
(impl: Int β Int Γ Int)
-- inputs
(num: Int) :=
-- spec
let spec (result: Int Γ Int) :=
let (even_count, odd_count) := result;
let numAbs := |num|.toNat;
let numBy10 := numAbs/10;
let (even_count', odd_count') := impl numBy10;
(result = impl numAbs) β§
(0 β€ num β (Even num β 1 + even_count' = even_count) β§ (Odd num β even_count' = even_count)) β§
(0 β€ num β (Odd num β 1 + odd_count' = odd_count) β§ (Even num β odd_count' = odd_count));
-- program terminates
β result, impl num = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: Int β Int Γ Int)
-- inputs
(num: Int) : Prop :=","theorem spec_isomorphism:
β impl,
(β num, problem_spec impl num) β
(β num, generated_spec impl num) :=",sorry,def implementation (num: Int) : Int Γ Int :=,sorry,"-- #test implementation -12 = (1, 1)
-- #test implementation 123 = (1, 2)","theorem correctness
(num: Int)
: problem_spec implementation num :=",sorry,,,
def int_to_mini_roman(num: Nat) -> String,"Given a positive integer, obtain its roman numeral equivalent as a string,
and return it in lowercase.
Restrictions: 1 <= num <= 1000
","[{""input"": 19, ""expected_output"": ""xix""}, {""input"": 152, ""expected_output"": ""clii""}, {""input"": 426, ""expected_output"": ""cdxxvi""}]","def int_to_mini_roman(num: Nat) -> String
""""""Given a positive integer, obtain its roman numeral equivalent as a string,
and return it in lowercase.
Restrictions: 1 <= num <= 1000
""""""","def problem_spec
-- function signature
(impl: Nat β String)
-- inputs
(num: Nat) :=
-- spec
let spec (result: String) :=
1 β€ num β§ num β€ 1000 β§ (result.data.all (fun c => c.isLower)) β
isValidRoman result β§ romanToDecimal result = num
-- program terminates
β result, impl num = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: Nat β String)
-- inputs
(num: Nat) : Prop :=","theorem spec_isomorphism:
β impl,
(β num, problem_spec impl num) β
(β num, generated_spec impl num) :=",sorry,def implementation (num: Nat) : String :=,sorry,"-- #test implementation 19 = ""xix""
-- #test implementation 152 = ""clii""
-- #test implementation 426 = ""cdxxvi""","theorem correctness
(num: Nat)
: problem_spec implementation num :=",sorry,"/--
name: romanCharToValue
use: |
Map from valid characters and their values
problems:
- 156
sample_problems: []
-/
def romanCharToValue : Char β Nat
| 'i' => 1
| 'v' => 5
| 'x' => 10
| 'l' => 50
| 'c' => 100
| 'd' => 500
| 'm' => 1000
| _ => 0
/--
name: validSubtractivePairs
use: |
Legal subtractive pairs: first char can precede second for subtraction (in roman numerals)
problems:
- 156
sample_problems: []
-/
def validSubtractivePairs : List (Char Γ Char) :=
[('i', 'v'), ('i', 'x'), ('x', 'l'), ('x', 'c'), ('c', 'd'), ('c', 'm')]
/--
name: maxRepetitions
use: |
Max allowed repetitions for each character (in roman numerals)
problems:
- 156
sample_problems: []
-/
def maxRepetitions : Char β Nat
| 'i' | 'x' | 'c' | 'm' => 3
| 'v' | 'l' | 'd' => 1
| _ => 0
/--
name: countRepetitions
use: |
Helper to count consecutive repetitions (in roman numerals)
problems:
- 156
sample_problems: []
-/
def countRepetitions : List Char β Char β Nat β Nat
| [], _, n => n
| (h :: t), c, n => if h = c then countRepetitions t c (n + 1) else n
/--
name: validRepetition
use: |
Helper to validate proper use of repetitions (in roman numerals)
problems:
- 156
sample_problems: []
-/
partial def validRepetition : List Char β Bool
| [] => true
| c :: rest =>
let max := maxRepetitions c
let count := countRepetitions rest c 1
count β€ max β§ validRepetition (rest.drop (count - 1))
/--
name: validSubtractiveOrder
use: |
Helper to validate legal subtractive combinations (in roman numerals)
problems:
- 156
sample_problems: []
-/
def validSubtractiveOrder : List Char β Bool
| [] | [_] => true
| c1 :: c2 :: rest =>
match romanCharToValue c1, romanCharToValue c2 with
| v1, v2 =>
if v1 < v2 then
-- check if c1 and c2 form a legal subtractive pair
(c1, c2) β validSubtractivePairs β§ validSubtractiveOrder rest
else if v1 = 0 β¨ v2 = 0 then
false
else
validSubtractiveOrder (c2 :: rest)
/--
name: isValidRoman
use: |
Function to check if a string is a roman numeral
problems:
- 156
sample_problems: []
-/
def isValidRoman (s : String) : Bool :=
s.data.all (Ξ» c => romanCharToValue c β 0) β§
validRepetition s.data β§
validSubtractiveOrder s.data
/--
name: romanToDecimalAux
use: |
Helper to convert list of roman characters to decimal
problems:
- 156
sample_problems: []
-/
def romanToDecimalAux : List Char β Nat
| [] => 0
| c1 :: c2 :: rest =>
let val1 := romanCharToValue c1
let val2 := romanCharToValue c2
if val1 < val2 then
-- subtractive notation
(val2 - val1) + romanToDecimalAux rest
else
val1 + romanToDecimalAux (c2 :: rest)
| [c] => romanCharToValue c
/--
name: romanToDecimalAux
use: |
Function to convert a valid lowercase Roman numeral string to Nat
problems:
- 156
sample_problems: []
-/
def romanToDecimal (s : String) : Nat :=
romanToDecimalAux s.data",,
"def right_angle_triangle(a: Nat, b: Nat, c: Nat) -> Bool","Given the lengths of the three sides of a triangle. Return True if the three
sides form a right-angled triangle, False otherwise.
A right-angled triangle is a triangle in which one angle is right angle or
90 degree.
","[{""input"": [3, 4, 5], ""expected_output"": true}, {""input"": [1, 2, 3], ""expected_output"": false}]","def right_angle_triangle(a: Nat, b: Nat, c: Nat) -> Bool
""""""Given the lengths of the three sides of a triangle. Return True if the three
sides form a right-angled triangle, False otherwise.
A right-angled triangle is a triangle in which one angle is right angle or
90 degree.
""""""","def problem_spec
-- function signature
(impl: Nat β Nat β Nat β Bool)
-- inputs
(a b c: Nat) :=
-- spec
let spec (result: Bool) :=
result β
0 < a β§ 0 < b β§ 0 < c β§
((a * a + b * b = c * c) β¨
(a * a + c * c = b * b) β¨
(b * b + c * c = a * a))
-- program terminates
β result, impl a b c = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: Nat β Nat β Nat β Bool)
-- inputs
(a b c: Nat) : Prop :=","theorem spec_isomorphism:
β impl,
(β a b c, problem_spec impl a b c) β
(β a b c, generated_spec impl a b c) :=",sorry,def implementation (a b c: Nat) : Bool :=,sorry,"-- #test implementation ([1, 2, 2, -4]: List Int) = (-9: Int)
-- #test implementation ([0, 1]: List Int) = (0: Int)
-- #test implementation ([]: List Int) = none","theorem correctness
(a b c: Nat)
: problem_spec implementation a b c :=",sorry,,,
def find_max(words: List String) -> String,"Write a function that accepts a list of strings.
The list contains different words. Return the word with maximum number
of unique characters. If multiple strings have maximum number of unique
characters, return the one which comes first in lexicographical order.
","[{""input"": [""name"", ""of"", ""string""], ""expected_output"": ""string""}, {""input"": [""name"", ""enam"", ""game""], ""expected_output"": ""enam""}, {""input"": [""aaaaaaa"", ""bb"", ""cc""], ""expected_output"": ""aaaaaaa""}]","def find_max(words: List String) -> String
""""""Write a function that accepts a list of strings.
The list contains different words. Return the word with maximum number
of unique characters. If multiple strings have maximum number of unique
characters, return the one which comes first in lexicographical order.
""""""","def problem_spec
-- function signature
(impl: List String β String)
-- inputs
(words: List String) :=
let unique_chars (string: String) :=
let string_idx := {i: Nat | i < string.length}.toFinset;
let characters := string_idx.image (fun i => string.toList.get! i);
characters.card;
-- spec
let spec (result: String) :=
(result = """" β words.length = 0) β§
(words.length != 0 β result β words β§
let unique_chars_list := words.map unique_chars;
let max_unique_chars := unique_chars_list.max?.get!;
unique_chars result = max_unique_chars β§
β i : Nat, i < words.length β
unique_chars_list[i]! = max_unique_chars β
result β€ words[i]!);
-- program terminates
β result, impl words = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: List String β String)
-- inputs
(words: List String) : Prop :=","theorem spec_isomorphism:
β impl,
(β words, problem_spec impl words) β
(β words, generated_spec impl words) :=",sorry,def implementation (words: List String) : String :=,sorry,"-- #test implementation [""name"", ""of"", ""string""]= ""string""
-- #test implementation [""name"", ""enam"", ""game""] = ""enam""
-- #test implementation [""aaaaaaa"", ""bb"" ,""cc""] = ""aaaaaaa""","theorem correctness
(words: List String)
: problem_spec implementation words :=",sorry,,,
"def eat(number: Nat, need: Nat, remaining: Nat) -> List Nat","You're a hungry rabbit, and you already have eaten a certain number of carrots,
but now you need to eat more carrots to complete the day's meals.
you should return an array of [ total number of eaten carrots after your meals,
the number of carrots left after your meals ]
if there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry.
Variables:
@number : integer
the number of carrots that you have eaten.
@need : integer
the number of carrots that you need to eat.
@remaining : integer
the number of remaining carrots thet exist in stock
Constrain:
* 0 <= number <= 1000
* 0 <= need <= 1000
* 0 <= remaining <= 1000
","[{""input"": [5, 6, 10], ""expected_output"": [11, 4]}, {""input"": [4, 8, 9], ""expected_output"": [12, 1]}, {""input"": [1, 10, 10], ""expected_output"": [11, 0]}, {""input"": [2, 11, 5], ""expected_output"": [7, 0]}]","def eat(number: Nat, need: Nat, remaining: Nat) -> List Nat
""""""You're a hungry rabbit, and you already have eaten a certain number of carrots,
but now you need to eat more carrots to complete the day's meals.
you should return an array of [ total number of eaten carrots after your meals,
the number of carrots left after your meals ]
if there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry.
Variables:
@number : integer
the number of carrots that you have eaten.
@need : integer
the number of carrots that you need to eat.
@remaining : integer
the number of remaining carrots thet exist in stock
Constrain:
* 0 <= number <= 1000
* 0 <= need <= 1000
* 0 <= remaining <= 1000
""""""","def problem_spec
-- function signature
(impl: Nat β Nat β Nat β List Nat)
-- inputs
(number need remaining: Nat) :=
-- spec
let spec (result: List Nat) :=
number β€ 1000 β need β€ 1000 β remaining β€ 1000 β
result.length = 2 β§
(need β€ remaining β result[0]! - need = number β§
need = remaining - result[1]!) β§
(remaining < need β result[0]! - remaining = number β§
result[1]! = 0);
-- program terminates
β result, impl number need remaining = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: Nat β Nat β Nat β List Nat)
-- inputs
(a b c : Nat) : Prop :=","theorem spec_isomorphism:
β impl,
(β a b c, problem_spec impl a b c) β
(β a b c, generated_spec impl a b c) :=",sorry,def implementation (a b c: Nat) : List Nat :=,sorry,"-- #test implementation 5 6 10 = [11, 4]
-- #test implementation 4 8 9 = [12, 1]
-- #test implementation 1 10 10 = [11, 0]
-- #test implementation 2 11 5 = [7, 0]","theorem correctness
(a b c: Nat)
: problem_spec implementation a b c :=",sorry,,,
"def do_algebra(operator: List String, operand: List Nat) -> Int","Given two lists operator, and operand. The first list has basic algebra operations, and
the second list is a list of integers. Use the two given lists to build the algebric
expression and return the evaluation of this expression.
The basic algebra operations:
Addition ( + )
Subtraction ( - )
Multiplication ( * )
Floor division ( // )
Exponentiation ( ** )
Note:
The length of operator list is equal to the length of operand list minus one.
Operand is a list of of non-negative integers.
Operator list has at least one operator, and operand list has at least two operands.
","[{""input"": [[""+"", ""*"", ""-""], [2, 3, 4, 5]], ""expected_output"": 9}]","def do_algebra(operator: List String, operand: List Nat) -> Int
""""""Given two lists operator, and operand. The first list has basic algebra operations, and
the second list is a list of integers. Use the two given lists to build the algebric
expression and return the evaluation of this expression.
The basic algebra operations:
Addition ( + )
Subtraction ( - )
Multiplication ( * )
Floor division ( // )
Exponentiation ( ** )
Note:
The length of operator list is equal to the length of operand list minus one.
Operand is a list of of non-negative integers.
Operator list has at least one operator, and operand list has at least two operands.
""""""","def problem_spec
-- function signature
(impl: List String β List Nat β Int)
-- inputs
(operator : List String)
(operand : List Nat) :=
-- spec
let spec (result: Int) :=
operator.length = operand.length - 1 β§ 0 < operator.length β§ operand.all (fun n => 0 β€ n) β
let inline_tokens : List String := mergeAlternately operand operator
evalArith_precedence inline_tokens result
-- program terminates
β result, impl operator operand = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: List String β List Nat β Int)
-- inputs
(operator : List String)
(operand : List Nat) : Prop :=","theorem spec_isomorphism:
β impl,
(β operator operand, problem_spec impl operator operand) β
(β operator operand, generated_spec impl operator operand) :=",sorry,def implementation (operator: List String) (operand : List Nat) : Int :=,sorry,"-- #test implementation ['+', '*', '-'] [2,3,4,5] = 9","theorem correctness
(operator : List String) (operand : List Nat)
: problem_spec implementation operator operand :=",sorry,"/--
name: mergeAlternately
use: |
Helper Methods to mergeAlternately a list of strings
problems:
- 160
sample_problems: []
-/
def mergeAlternately : List Nat β List String β List String
| [], [] => []
| [], y :: ys => y :: mergeAlternately [] ys
| x :: xs, [] => x.repr :: mergeAlternately xs []
| x :: xs, y :: ys => x.repr :: y :: mergeAlternately xs ys
/--
name: applyOp
use: |
Helper method to apply operations on two integers
problems:
- 160
sample_problems: []
-/
def applyOp (x y : Int) : String β Option Int
| ""+"" => some (x + y)
| ""-"" => some (x - y)
| ""*"" => some (x * y)
| ""//"" => if y == 0 then none else some (x / y)
| ""**"" =>
if x < 0 then none
else some (Int.ofNat ((Int.toNat x) ^ (Int.toNat y)))
| _ => none
/--
name: evalArith_pass
use: |
Noncomputable relational spec for a single step evaluation (any op, ignoring precedence).
problems:
- 160
sample_problems: []
-/
inductive evalArith_pass : List String β Int β Prop
| num {s : String} {n : Nat} (h : s.toNat! = n) :
evalArith_pass [s] (Int.ofNat n)
| binOp {ts1 ts2 : List String} {op : String} {r1 r2 r : Int}
(h1 : evalArith_pass ts1 r1)
(h2 : evalArith_pass ts2 r2)
(hop : applyOp r1 r2 op = some r) :
evalArith_pass (ts1 ++ op :: ts2) r
/--
name: evalArith_exp
use: |
Relational spec for exponentiation (highest precedence).
problems:
- 160
sample_problems: []
-/
inductive evalArith_exp : List String β Int β Prop
| of_pass {ts r} (h : evalArith_pass ts r) : evalArith_exp ts r
| step {ts1 ts2 r1 r2 r} (h1 : evalArith_exp ts1 r1) (h2 : evalArith_exp ts2 r2)
(hop : applyOp r1 r2 ""**"" = some r) :
evalArith_exp (ts1 ++ ""**"" :: ts2) r
/--
name: evalArith_mul
use: |
Relational spec for multiplication/division (middle precedence).
problems:
- 160
sample_problems: []
-/
inductive evalArith_mul : List String β Int β Prop
| of_exp {ts r} (h : evalArith_exp ts r) : evalArith_mul ts r
| step {ts1 ts2 r1 r2 r} (h1 : evalArith_mul ts1 r1) (h2 : evalArith_mul ts2 r2)
(hop : applyOp r1 r2 ""*"" = some r β¨ applyOp r1 r2 ""//"" = some r) :
evalArith_mul (ts1 ++ ""*"" :: ts2) r
/--
name: evalArith_mul
use: |
Relational spec for addition/subtraction (lowest precedence).
problems:
- 160
sample_problems: []
-/
inductive evalArith_add : List String β Int β Prop
| of_mul {ts r} (h : evalArith_mul ts r) : evalArith_add ts r
| step {ts1 ts2 r1 r2 r} (h1 : evalArith_add ts1 r1) (h2 : evalArith_add ts2 r2)
(hop : applyOp r1 r2 ""+"" = some r β¨ applyOp r1 r2 ""-"" = some r) :
evalArith_add (ts1 ++ ""+"" :: ts2) r
/--
name: evalArith_mul
use: |
Main function to evaluate an expression
problems:
- 160
sample_problems: []
-/
def evalArith_precedence (ts : List String) (r : Int) : Prop :=
evalArith_add ts r",,
def solve(string : String) -> String,"You are given a string s.
if s[i] is a letter, reverse its case from lower to upper or vise versa,
otherwise keep it as it is.
If the string contains no letters, reverse the string.
The function should return the resulted string.
","[{""input"": ""1234"", ""expected_output"": ""4321""}, {""input"": ""ab"", ""expected_output"": ""AB""}, {""input"": ""#a@C"", ""expected_output"": ""#A@c""}]","def solve(string : String) -> String
""""""You are given a string s.
if s[i] is a letter, reverse its case from lower to upper or vise versa,
otherwise keep it as it is.
If the string contains no letters, reverse the string.
The function should return the resulted string.
""""""","def problem_spec
-- function signature
(impl: String β String)
-- inputs
(string : String) :=
-- spec
let spec (result: String) :=
result.length = string.length β§
let hasNoAlphabet := string.all (Ξ» c => not (c.isAlpha));
(hasNoAlphabet β
result.toList = string.toList.reverse) β§
(hasNoAlphabet = false β
β i, i < string.length β
let c := string.get! β¨iβ©;
(c.isAlpha β ((c.isLower β c.toUpper = result.get! β¨iβ©) β¨
(c.isUpper β c.toLower = result.get! β¨iβ©))) β§
(Β¬ c.isAlpha β c = result.get! β¨iβ©))
-- program terminates
β result, impl string = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: String β String)
-- inputs
(s : String) : Prop :=","theorem spec_isomorphism:
β impl,
(β s, problem_spec impl s) β
(β s, generated_spec impl s) :=",sorry,def implementation (s: String) : String :=,sorry,"-- #test implementation ""1234"" = ""4321""
-- #test implementation ""ab"" = ""AB""
-- #test implementation ""#a@C"" = ""#A@c""","theorem correctness
(s: String)
: problem_spec implementation s :=",sorry,,,
"def generate_integers(a : Nat, b : Nat) -> List Nat","Given two positive integers a and b, return the even digits between a
and b, in ascending order.
","[{""input"": [2, 8], ""expected_output"": [2, 4, 6, 8]}, {""input"": [8, 2], ""expected_output"": [2, 4, 6, 8]}, {""input"": [10, 14], ""expected_output"": [10, 12, 14]}]","def generate_integers(a : Nat, b : Nat) -> List Nat
""""""Given two positive integers a and b, return the even digits between a
and b, in ascending order.
""""""","def problem_spec
-- function signature
(impl: Nat β Nat β List Nat)
-- inputs
(a b : Nat) :=
let isAscendingBy2 (r : List Nat) :=
β i, i < r.length - 1 β r[i+1]! - r[i]! = 2
-- spec
let spec (result: List Nat) :=
result.all (fun n => n % 2 = 0) β§ isAscendingBy2 result β§
1 < result.length β§
let min_a_b := min a b;
let max_a_b := max a b;
if min_a_b = max_a_b β§ (min_a_b % 2 = 1)
then result = []
else ((result[0]! = if 2 β£ min_a_b then min_a_b else (min_a_b + 1)) β§
(result[result.length-1]! = if 2 β£ max_a_b then max_a_b else max_a_b - 1))
-- program terminates
β result, impl a b = result β§
-- return value satisfies spec
spec result","def generated_spec
-- function signature
(impl: Nat β Nat β List Nat)
-- inputs
(a b : Nat) : Prop :=","theorem spec_isomorphism:
β impl,
(β a b, problem_spec impl a b) β
(β a b, generated_spec impl a b) :=",sorry,def implementation (a b: Nat) : List Nat :=,sorry,"-- #test implementation 2 8 = [2, 4, 6, 8]
-- #test implementation 8 2 = [2, 4, 6, 8]
-- #test implementation 10 14 = [10, 12, 14]","theorem correctness
(a b: Nat)
: problem_spec implementation a b :=",sorry,,,
|