diff --git a/docs/notebooks/BigInts.ipynb b/docs/notebooks/BigInts.ipynb index 2679892..5cfdfd9 100644 --- a/docs/notebooks/BigInts.ipynb +++ b/docs/notebooks/BigInts.ipynb @@ -21,15 +21,7 @@ "execution_count": 1, "id": "08a49b81", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "2147483648" - ] - } - ], + "outputs": [], "source": [ "1 31 << " ] @@ -47,13 +39,7 @@ "execution_count": 2, "id": "b34d58ef", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [] - } - ], + "outputs": [], "source": [ "unit [base] swoncat inscribe" ] @@ -79,13 +65,7 @@ "execution_count": 3, "id": "35476eac", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [] - } - ], + "outputs": [], "source": [ "[valid_digit [0 >] [base <] &&] inscribe" ] @@ -95,15 +75,7 @@ "execution_count": 4, "id": "02a48806", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "32 true 1232147483648 false" - ] - } - ], + "outputs": [], "source": [ "32 valid_digit 1232147483648 valid_digit" ] @@ -113,13 +85,7 @@ "execution_count": 5, "id": "03a8fe65", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [] - } - ], + "outputs": [], "source": [ "clear" ] @@ -146,15 +112,7 @@ "execution_count": 6, "id": "3fc98ccd", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1797196498 5748904729" - ] - } - ], + "outputs": [], "source": [ "12345678901234567890 base divmod swap" ] @@ -164,15 +122,7 @@ "execution_count": 7, "id": "b838c4cb", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1797196498 1453937433 2" - ] - } - ], + "outputs": [], "source": [ "base divmod swap" ] @@ -182,15 +132,7 @@ "execution_count": 8, "id": "42c9d92d", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1797196498 1453937433 2 0" - ] - } - ], + "outputs": [], "source": [ "base divmod swap" ] @@ -210,15 +152,7 @@ "execution_count": 9, "id": "faaac9d6", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1312754386 1501085485 57659106 105448366 58" - ] - } - ], + "outputs": [], "source": [ "clear 1234567890123456789012345678901234567890\n", "\n", @@ -238,15 +172,7 @@ "execution_count": 10, "id": "2a613f36", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[58 105448366 57659106 1501085485 1312754386]" - ] - } - ], + "outputs": [], "source": [ "clear [1234567890123456789012345678901234567890]\n", "\n", @@ -435,7 +361,7 @@ "id": "c89e6054", "metadata": {}, "source": [ - "#### `to_bigint`" + "#### `to-bigint`" ] }, { @@ -451,7 +377,7 @@ } ], "source": [ - "[to_bigint [!-] [abs digitalize] cleave cons] inscribe" + "[to-bigint [!-] [abs digitalize] cleave cons] inscribe" ] }, { @@ -477,7 +403,7 @@ } ], "source": [ - "clear 1234567890123456789012345678901234567890 to_bigint" + "clear 1234567890123456789012345678901234567890 to-bigint" ] }, { @@ -503,7 +429,7 @@ } ], "source": [ - "clear -1234567890123456789012345678901234567890 to_bigint" + "clear -1234567890123456789012345678901234567890 to-bigint" ] }, { @@ -653,7 +579,7 @@ "id": "7497680b", "metadata": {}, "source": [ - "#### `prep` and `from_bigint'`" + "#### `prep` and `from-bigint'`" ] }, { @@ -672,7 +598,7 @@ ], "source": [ "[prep rest 1 0 rolldown] inscribe\n", - "[from_bigint' [F] step popd] inscribe\n", + "[from-bigint' [F] step popd] inscribe\n", "[F [G] [H] clop popdd] inscribe\n", "[G popop base *] inscribe\n", "[H rolldown * +] inscribe" @@ -695,7 +621,7 @@ "source": [ "clear 1 0 [1312754386 1501085485 57659106 105448366 58]\n", "\n", - "from_bigint'" + "from-bigint'" ] }, { @@ -713,7 +639,7 @@ } ], "source": [ - "to_bigint" + "to-bigint" ] }, { @@ -749,7 +675,7 @@ } ], "source": [ - "from_bigint'" + "from-bigint'" ] }, { @@ -767,7 +693,7 @@ } ], "source": [ - "to_bigint prep from_bigint'" + "to-bigint prep from-bigint'" ] }, { @@ -811,7 +737,7 @@ } ], "source": [ - "to_bigint prep from_bigint'" + "to-bigint prep from-bigint'" ] }, { @@ -837,7 +763,7 @@ } ], "source": [ - "to_bigint" + "to-bigint" ] }, { @@ -863,7 +789,7 @@ } ], "source": [ - "[first] [prep from_bigint'] cleave" + "[first] [prep from-bigint'] cleave" ] }, { @@ -899,9 +825,9 @@ "source": [ "This gives:\n", "\n", - " foo == [first] [prep from_bigint'] cleave\n", + " foo == [first] [prep from-bigint'] cleave\n", " bar == swap [] [neg] branch\n", - " from_bigint == foo bar" + " from-bigint == foo bar" ] }, { @@ -909,7 +835,7 @@ "id": "8bffedec", "metadata": {}, "source": [ - "#### `from_bigint`" + "#### `from-bigint`" ] }, { @@ -926,9 +852,9 @@ ], "source": [ "clear\n", - "[foo [first] [prep from_bigint'] cleave] inscribe\n", + "[foo [first] [prep from-bigint'] cleave] inscribe\n", "[bar swap [neg] [] branch] inscribe\n", - "[from_bigint foo bar] inscribe" + "[from-bigint foo bar] inscribe" ] }, { @@ -946,7 +872,7 @@ } ], "source": [ - "1234567890123456789012345678901234567890 to_bigint from_bigint" + "1234567890123456789012345678901234567890 to-bigint from-bigint" ] }, { @@ -964,7 +890,7 @@ } ], "source": [ - "neg to_bigint from_bigint" + "neg to-bigint from-bigint" ] }, { @@ -992,7 +918,7 @@ "\n", "Let's figure out how to add two lists of digits (we will assume that the signs are the same.) We need to put an inital `false` value for a carry flag, and then there's a `genrec`.\n", "\n", - " initial-carry ≡ false rollup\n", + " initial-carry == false rollup\n", " add-digits' ≡ [P] [THEN] [R0] [R1] genrec\n", " \n", " add-digits ≡ initial-carry add-digits'" @@ -1278,7 +1204,7 @@ "id": "223cee8e", "metadata": {}, "source": [ - "#### `bool_to_int`" + "#### `bool-to-int`" ] }, { @@ -1296,7 +1222,7 @@ "source": [ "clear\n", "\n", - "[bool_to_int [0] [1] branch] inscribe" + "[bool-to-int [0] [1] branch] inscribe" ] }, { @@ -1322,8 +1248,8 @@ } ], "source": [ - "false bool_to_int\n", - "true bool_to_int" + "false bool-to-int\n", + "true bool-to-int" ] }, { @@ -1351,7 +1277,7 @@ "source": [ "clear\n", "\n", - "false 1 2 [bool_to_int] dipd + +" + "false 1 2 [bool-to-int] dipd + +" ] }, { @@ -1371,7 +1297,7 @@ "source": [ "clear\n", "\n", - "true 1 2 [bool_to_int] dipd + +" + "true 1 2 [bool-to-int] dipd + +" ] }, { @@ -1379,7 +1305,7 @@ "id": "89b971c9", "metadata": {}, "source": [ - "So the first part of `F` is `[bool_to_int] dipd + +` to get the total, then we need to do\n", + "So the first part of `F` is `[bool-to-int] dipd + +` to get the total, then we need to do\n", "\n", "`base mod` to get the new digit and `base >=` to get the new carry flag:" ] @@ -1433,7 +1359,7 @@ "source": [ "Put it all together and we have:\n", "\n", - " _add-with-carry0 ≡ [bool_to_int] dipd + +\n", + " _add-with-carry0 ≡ [bool-to-int] dipd + +\n", " _add-with-carry1 ≡ base [mod] [>=] clop\n", "\n", " add-with-carry ≡ _add-with-carry0 _add-with-carry1\n" @@ -1461,7 +1387,7 @@ ], "source": [ "clear\n", - "[_add-with-carry0 [bool_to_int] dipd + +] inscribe\n", + "[_add-with-carry0 [bool-to-int] dipd + +] inscribe\n", "[_add-with-carry1 base [mod] [>=] clop] inscribe\n", "[add-with-carry _add-with-carry0 _add-with-carry1] inscribe" ] @@ -1556,7 +1482,7 @@ }, { "cell_type": "code", - "execution_count": 91, + "execution_count": 57, "id": "b46a62ba", "metadata": {}, "outputs": [ @@ -2257,7 +2183,7 @@ "source": [ "clear\n", "\n", - "123 to_bigint 456 to_bigint" + "123 to-bigint 456 to-bigint" ] }, { @@ -2295,7 +2221,7 @@ "source": [ "clear\n", "\n", - "123 to_bigint 456 to_bigint" + "123 to-bigint 456 to-bigint" ] }, { @@ -2413,7 +2339,7 @@ } ], "source": [ - "base -- to_bigint" + "base -- to-bigint" ] }, { @@ -2436,8 +2362,8 @@ }, { "cell_type": "code", - "execution_count": 95, - "id": "d8832fda", + "execution_count": 90, + "id": "dac1c858", "metadata": {}, "outputs": [ { @@ -2560,7 +2486,7 @@ }, { "cell_type": "markdown", - "id": "fdc6fc09", + "id": "184f6b2e", "metadata": {}, "source": [ "But this doesn't go quite far enough, I think.\n", @@ -2570,7 +2496,7 @@ }, { "cell_type": "markdown", - "id": "94249f95", + "id": "7598e48c", "metadata": {}, "source": [ "I think `R0` will pretty much always do:\n", @@ -2580,7 +2506,7 @@ }, { "cell_type": "markdown", - "id": "ecc190e3", + "id": "b721354e", "metadata": {}, "source": [ "And so it should be refactored further to something like:\n", @@ -2619,7 +2545,7 @@ }, { "cell_type": "markdown", - "id": "c9fd7e21", + "id": "aa6e7586", "metadata": {}, "source": [ "Let's figure out the new form.\n", @@ -2642,7 +2568,7 @@ }, { "cell_type": "markdown", - "id": "64118784", + "id": "0a5e4669", "metadata": {}, "source": [ "Let's not over think it.\n", @@ -2653,7 +2579,7 @@ }, { "cell_type": "markdown", - "id": "90310271", + "id": "9d7aad63", "metadata": {}, "source": [ "With:\n", @@ -2665,7 +2591,7 @@ }, { "cell_type": "code", - "execution_count": 93, + "execution_count": 91, "id": "55f64814", "metadata": {}, "outputs": [ @@ -2681,7 +2607,7 @@ }, { "cell_type": "code", - "execution_count": 91, + "execution_count": 92, "id": "04e2d0d0", "metadata": {}, "outputs": [ @@ -2699,7 +2625,7 @@ }, { "cell_type": "code", - "execution_count": 92, + "execution_count": 93, "id": "a28d9323", "metadata": {}, "outputs": [ @@ -2717,7 +2643,7 @@ }, { "cell_type": "markdown", - "id": "e8433d46", + "id": "004b7aca", "metadata": {}, "source": [ "So to get from \n", @@ -2737,8 +2663,8 @@ }, { "cell_type": "code", - "execution_count": 103, - "id": "77e6c03a", + "execution_count": 94, + "id": "bc16275c", "metadata": {}, "outputs": [ { @@ -2765,8 +2691,8 @@ }, { "cell_type": "code", - "execution_count": 104, - "id": "1119f1e6", + "execution_count": 95, + "id": "c517da7a", "metadata": {}, "outputs": [ { @@ -2783,7 +2709,7 @@ }, { "cell_type": "code", - "execution_count": 105, + "execution_count": 96, "id": "3f482224", "metadata": {}, "outputs": [ @@ -2802,14 +2728,14 @@ { "cell_type": "code", "execution_count": null, - "id": "02bfc247", + "id": "3a504505", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", - "execution_count": 106, + "execution_count": 97, "id": "4b90e664", "metadata": {}, "outputs": [ @@ -2831,7 +2757,7 @@ }, { "cell_type": "markdown", - "id": "089fc71c", + "id": "173bf5b7", "metadata": {}, "source": [ "Compare the above with what we wanted:\n", @@ -2853,15 +2779,15 @@ { "cell_type": "code", "execution_count": null, - "id": "929366cc", + "id": "c816fa4b", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", - "execution_count": 107, - "id": "a3b7e48a", + "execution_count": 98, + "id": "ff88e2c1", "metadata": {}, "outputs": [ { @@ -2885,8 +2811,8 @@ }, { "cell_type": "code", - "execution_count": 108, - "id": "313ce113", + "execution_count": 99, + "id": "941a4426", "metadata": { "scrolled": true }, @@ -2905,8 +2831,8 @@ }, { "cell_type": "code", - "execution_count": 110, - "id": "aca55d10", + "execution_count": 100, + "id": "917600dd", "metadata": {}, "outputs": [ { @@ -2921,19 +2847,10 @@ "[combine-two-lists [add-carry-to-digits] [swap carry] [add-with-carry] build-two-list-combiner] inscribe" ] }, - { - "cell_type": "markdown", - "id": "92a471fa", - "metadata": {}, - "source": [ - " combine-two-lists == build-two-list-combiner [i cons] genrec\n", - " " - ] - }, { "cell_type": "code", - "execution_count": 111, - "id": "0fa2607d", + "execution_count": 101, + "id": "21f6b0e4", "metadata": {}, "outputs": [ { @@ -2953,8 +2870,8 @@ }, { "cell_type": "code", - "execution_count": 112, - "id": "026095a5", + "execution_count": 102, + "id": "4a8819fc", "metadata": {}, "outputs": [ { @@ -2971,8 +2888,8 @@ }, { "cell_type": "code", - "execution_count": 113, - "id": "15974737", + "execution_count": 103, + "id": "5d451c1e", "metadata": {}, "outputs": [ { @@ -2989,8 +2906,8 @@ }, { "cell_type": "code", - "execution_count": 114, - "id": "525bc382", + "execution_count": 104, + "id": "28fefe8a", "metadata": {}, "outputs": [ { @@ -3004,7 +2921,7 @@ "source": [ "clear\n", "\n", - "123456 to_bigint\n", + "123456 to-bigint\n", "\n", "\n", "\n" @@ -3012,7 +2929,7 @@ }, { "cell_type": "code", - "execution_count": 117, + "execution_count": 105, "id": "fa37c40c", "metadata": {}, "outputs": [ @@ -3036,21 +2953,9 @@ "In order to avoid the overhead of rebuilding the whole thing each time we could pre-compute the function and store it in the dictionary." ] }, - { - "cell_type": "markdown", - "id": "5f739deb", - "metadata": {}, - "source": [ - "\n", - " combine-two-lists == build-two-list-combiner [i cons] genrec\n", - " \n", - " build-two-list-combiner == [[[ditch-empty-list] swoncat] dip [pop] swoncat] dip [uncons-two] [dipd] sandwich [[ifte] ccons [P'] swons [P] swap ] dip\n", - " " - ] - }, { "cell_type": "code", - "execution_count": 118, + "execution_count": 106, "id": "850a1421", "metadata": {}, "outputs": [ @@ -3079,8 +2984,8 @@ }, { "cell_type": "code", - "execution_count": 119, - "id": "52bb5921", + "execution_count": 107, + "id": "4b6005fc", "metadata": {}, "outputs": [ { @@ -3097,7 +3002,7 @@ }, { "cell_type": "code", - "execution_count": 120, + "execution_count": 108, "id": "c616033e", "metadata": {}, "outputs": [ @@ -3121,7 +3026,7 @@ }, { "cell_type": "code", - "execution_count": 121, + "execution_count": 109, "id": "1a18ddd7", "metadata": {}, "outputs": [ @@ -3139,7 +3044,7 @@ }, { "cell_type": "code", - "execution_count": 122, + "execution_count": 110, "id": "3c639487", "metadata": {}, "outputs": [ @@ -3157,7 +3062,7 @@ }, { "cell_type": "code", - "execution_count": 123, + "execution_count": 111, "id": "c9222cab", "metadata": {}, "outputs": [ @@ -3175,7 +3080,7 @@ }, { "cell_type": "code", - "execution_count": 124, + "execution_count": 112, "id": "f3bc8d28", "metadata": {}, "outputs": [ @@ -3191,7 +3096,7 @@ }, { "cell_type": "markdown", - "id": "c85d6fe6", + "id": "82b7bf9a", "metadata": {}, "source": [ "#### Demonstrate `add-bigints`" @@ -3199,8 +3104,8 @@ }, { "cell_type": "code", - "execution_count": 125, - "id": "3da6266b", + "execution_count": 113, + "id": "b4a71b70", "metadata": {}, "outputs": [ { @@ -3212,13 +3117,13 @@ } ], "source": [ - "1234 999 [to_bigint] ii " + "1234 999 [to-bigint] ii " ] }, { "cell_type": "code", - "execution_count": 126, - "id": "7d38dbaa", + "execution_count": 114, + "id": "6aba84ae", "metadata": {}, "outputs": [ { @@ -3235,8 +3140,8 @@ }, { "cell_type": "code", - "execution_count": 127, - "id": "e65f7ff9", + "execution_count": 115, + "id": "d5dc4dce", "metadata": {}, "outputs": [ { @@ -3248,13 +3153,13 @@ } ], "source": [ - "from_bigint" + "from-bigint" ] }, { "cell_type": "code", - "execution_count": 128, - "id": "5d385f35", + "execution_count": 116, + "id": "2e9ab2c2", "metadata": {}, "outputs": [ { @@ -3269,10 +3174,26 @@ "1234 999 +" ] }, + { + "cell_type": "code", + "execution_count": 117, + "id": "080d81a3", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [] + } + ], + "source": [ + "clear" + ] + }, { "cell_type": "code", "execution_count": null, - "id": "fb7da91a", + "id": "7b237ca8", "metadata": {}, "outputs": [], "source": [] @@ -3280,7 +3201,7 @@ { "cell_type": "code", "execution_count": null, - "id": "679e9df6", + "id": "46f50f12", "metadata": {}, "outputs": [], "source": [] @@ -3288,7 +3209,7 @@ { "cell_type": "code", "execution_count": null, - "id": "d4d2850a", + "id": "7e035a2c", "metadata": {}, "outputs": [], "source": [] @@ -3296,7 +3217,7 @@ { "cell_type": "code", "execution_count": null, - "id": "c4da9da4", + "id": "f2492e55", "metadata": {}, "outputs": [], "source": [] @@ -3304,7 +3225,7 @@ { "cell_type": "code", "execution_count": null, - "id": "55a37610", + "id": "8dfddc89", "metadata": {}, "outputs": [], "source": [] @@ -3312,15 +3233,7 @@ { "cell_type": "code", "execution_count": null, - "id": "c637a7ea", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "b56cf709", + "id": "7f2bf0e5", "metadata": {}, "outputs": [], "source": [] @@ -3370,7 +3283,7 @@ }, { "cell_type": "code", - "execution_count": 112, + "execution_count": 118, "id": "9c50bd24", "metadata": {}, "outputs": [ @@ -3386,7 +3299,7 @@ }, { "cell_type": "code", - "execution_count": 113, + "execution_count": 119, "id": "4c1dbabd", "metadata": {}, "outputs": [ @@ -3405,7 +3318,7 @@ }, { "cell_type": "code", - "execution_count": 114, + "execution_count": 120, "id": "ef683ade", "metadata": {}, "outputs": [ @@ -3424,7 +3337,7 @@ }, { "cell_type": "code", - "execution_count": 115, + "execution_count": 121, "id": "ff52920a", "metadata": {}, "outputs": [ @@ -3443,7 +3356,7 @@ }, { "cell_type": "code", - "execution_count": 116, + "execution_count": 122, "id": "be946f53", "metadata": {}, "outputs": [ @@ -3469,7 +3382,7 @@ }, { "cell_type": "code", - "execution_count": 117, + "execution_count": 123, "id": "056e3072", "metadata": {}, "outputs": [ @@ -3485,7 +3398,7 @@ }, { "cell_type": "code", - "execution_count": 118, + "execution_count": 124, "id": "02d4e38e", "metadata": {}, "outputs": [ @@ -3503,7 +3416,7 @@ }, { "cell_type": "code", - "execution_count": 119, + "execution_count": 125, "id": "5683eb84", "metadata": {}, "outputs": [ @@ -3527,7 +3440,7 @@ }, { "cell_type": "code", - "execution_count": 120, + "execution_count": 126, "id": "a4e1f728", "metadata": {}, "outputs": [ @@ -3551,7 +3464,7 @@ }, { "cell_type": "code", - "execution_count": 121, + "execution_count": 127, "id": "dc7c151a", "metadata": {}, "outputs": [ @@ -3611,7 +3524,7 @@ }, { "cell_type": "code", - "execution_count": 122, + "execution_count": 128, "id": "50c2669a", "metadata": {}, "outputs": [ @@ -3627,7 +3540,7 @@ }, { "cell_type": "code", - "execution_count": 123, + "execution_count": 129, "id": "1bbf3465", "metadata": {}, "outputs": [ @@ -3647,7 +3560,7 @@ }, { "cell_type": "code", - "execution_count": 124, + "execution_count": 130, "id": "5a9347f6", "metadata": {}, "outputs": [ @@ -3665,7 +3578,7 @@ }, { "cell_type": "code", - "execution_count": 125, + "execution_count": 131, "id": "69b18847", "metadata": {}, "outputs": [ @@ -3682,7 +3595,7 @@ }, { "cell_type": "code", - "execution_count": 126, + "execution_count": 132, "id": "0b29370d", "metadata": {}, "outputs": [ @@ -3702,7 +3615,7 @@ }, { "cell_type": "code", - "execution_count": 127, + "execution_count": 133, "id": "32ce148e", "metadata": {}, "outputs": [ @@ -3722,7 +3635,7 @@ }, { "cell_type": "code", - "execution_count": 128, + "execution_count": 134, "id": "4efc8f76", "metadata": {}, "outputs": [ @@ -3749,7 +3662,7 @@ "\n", "we have three lists. The first is a possibly-empty list of pairs to compare.\n", "\n", - "THe second two are the tails of the original lists.\n", + "The second two are the tails of the original lists.\n", "\n", "if the first list is non-empty then the second list must be empty so the whole function should return true\n", "\n", @@ -3778,7 +3691,7 @@ }, { "cell_type": "code", - "execution_count": 129, + "execution_count": 135, "id": "7d973f7f", "metadata": {}, "outputs": [ @@ -3807,7 +3720,7 @@ }, { "cell_type": "code", - "execution_count": 130, + "execution_count": 136, "id": "9239e0c4", "metadata": {}, "outputs": [ @@ -3836,7 +3749,7 @@ }, { "cell_type": "code", - "execution_count": 131, + "execution_count": 137, "id": "0c58a6e0", "metadata": {}, "outputs": [ @@ -3892,7 +3805,7 @@ }, { "cell_type": "code", - "execution_count": 132, + "execution_count": 138, "id": "7f302157", "metadata": {}, "outputs": [ @@ -3912,7 +3825,7 @@ }, { "cell_type": "code", - "execution_count": 133, + "execution_count": 139, "id": "d25ef02e", "metadata": {}, "outputs": [ @@ -3940,7 +3853,7 @@ }, { "cell_type": "code", - "execution_count": 134, + "execution_count": 140, "id": "06e0ffcb", "metadata": {}, "outputs": [ @@ -3967,7 +3880,7 @@ }, { "cell_type": "code", - "execution_count": 135, + "execution_count": 141, "id": "b2428f49", "metadata": {}, "outputs": [ @@ -3985,7 +3898,7 @@ }, { "cell_type": "code", - "execution_count": 136, + "execution_count": 142, "id": "4ef5f503", "metadata": {}, "outputs": [ @@ -4011,7 +3924,7 @@ }, { "cell_type": "code", - "execution_count": 246, + "execution_count": 143, "id": "7f060f83", "metadata": {}, "outputs": [ @@ -4046,7 +3959,7 @@ }, { "cell_type": "code", - "execution_count": 138, + "execution_count": 144, "id": "8d74a801", "metadata": {}, "outputs": [ @@ -4064,7 +3977,7 @@ }, { "cell_type": "code", - "execution_count": 139, + "execution_count": 145, "id": "0104d2b0", "metadata": {}, "outputs": [ @@ -4072,7 +3985,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "false" + "true" ] } ], @@ -4082,7 +3995,7 @@ }, { "cell_type": "code", - "execution_count": 140, + "execution_count": 146, "id": "4728d141", "metadata": {}, "outputs": [ @@ -4090,7 +4003,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "false" + "true" ] } ], @@ -4100,7 +4013,7 @@ }, { "cell_type": "code", - "execution_count": 141, + "execution_count": 147, "id": "bfb5e62c", "metadata": {}, "outputs": [ @@ -4116,7 +4029,7 @@ }, { "cell_type": "code", - "execution_count": 142, + "execution_count": 148, "id": "7983881c", "metadata": {}, "outputs": [ @@ -4134,7 +4047,7 @@ }, { "cell_type": "code", - "execution_count": 143, + "execution_count": 149, "id": "677757c5", "metadata": {}, "outputs": [ @@ -4142,7 +4055,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "false" + "true" ] } ], @@ -4152,7 +4065,7 @@ }, { "cell_type": "code", - "execution_count": 144, + "execution_count": 150, "id": "5691f813", "metadata": {}, "outputs": [ @@ -4160,7 +4073,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "false" + "true" ] } ], @@ -4178,7 +4091,7 @@ }, { "cell_type": "code", - "execution_count": 145, + "execution_count": 151, "id": "b95fe984", "metadata": {}, "outputs": [ @@ -4207,7 +4120,7 @@ }, { "cell_type": "code", - "execution_count": 146, + "execution_count": 152, "id": "b5ddac15", "metadata": {}, "outputs": [ @@ -4235,7 +4148,7 @@ }, { "cell_type": "code", - "execution_count": 147, + "execution_count": 153, "id": "d4077376", "metadata": {}, "outputs": [ @@ -4255,7 +4168,7 @@ }, { "cell_type": "code", - "execution_count": 148, + "execution_count": 154, "id": "ac840996", "metadata": {}, "outputs": [ @@ -4263,7 +4176,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "false" + "true" ] } ], @@ -4273,7 +4186,7 @@ }, { "cell_type": "code", - "execution_count": 149, + "execution_count": 155, "id": "e7c3b141", "metadata": {}, "outputs": [ @@ -4293,7 +4206,7 @@ }, { "cell_type": "code", - "execution_count": 150, + "execution_count": 156, "id": "95c7308d", "metadata": {}, "outputs": [ @@ -4301,7 +4214,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "true" + "false" ] } ], @@ -4311,7 +4224,7 @@ }, { "cell_type": "code", - "execution_count": 151, + "execution_count": 157, "id": "5e43ba80", "metadata": {}, "outputs": [ @@ -4331,7 +4244,7 @@ }, { "cell_type": "code", - "execution_count": 152, + "execution_count": 158, "id": "20070426", "metadata": {}, "outputs": [ @@ -4339,7 +4252,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "false" + "true" ] } ], @@ -4349,7 +4262,7 @@ }, { "cell_type": "code", - "execution_count": 154, + "execution_count": 159, "id": "c97b0df9", "metadata": {}, "outputs": [ @@ -4365,7 +4278,7 @@ }, { "cell_type": "code", - "execution_count": 155, + "execution_count": 160, "id": "980a1bbf", "metadata": {}, "outputs": [ @@ -4381,27 +4294,9 @@ }, { "cell_type": "code", - "execution_count": 199, + "execution_count": 161, "id": "4f429421", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "false" - ] - } - ], - "source": [ - "clear [3 2 1] [4 5 6] gt-bigint" - ] - }, - { - "cell_type": "code", - "execution_count": 158, - "id": "5a6419ee", - "metadata": {}, "outputs": [ { "name": "stdout", @@ -4412,13 +4307,13 @@ } ], "source": [ - "clear [3 2 1] [4 5 6] swap gt-bigint" + "clear [3 2 1] [4 5 6] gt-bigint" ] }, { "cell_type": "code", - "execution_count": 159, - "id": "cd586291", + "execution_count": 162, + "id": "5a6419ee", "metadata": {}, "outputs": [ { @@ -4429,6 +4324,24 @@ ] } ], + "source": [ + "clear [3 2 1] [4 5 6] swap gt-bigint" + ] + }, + { + "cell_type": "code", + "execution_count": 163, + "id": "cd586291", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "true" + ] + } + ], "source": [ "clear [3 2 1] dup gt-bigint" ] @@ -4443,7 +4356,7 @@ }, { "cell_type": "code", - "execution_count": 160, + "execution_count": 164, "id": "35fb22d2", "metadata": {}, "outputs": [ @@ -4451,7 +4364,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "[3 2 1] [4 5 6]" + "[4 5 6] [3 2 1]" ] } ], @@ -4461,7 +4374,7 @@ }, { "cell_type": "code", - "execution_count": 161, + "execution_count": 165, "id": "36d74e5b", "metadata": {}, "outputs": [ @@ -4469,7 +4382,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "[3 2 1] [4 5 6]" + "[4 5 6] [3 2 1]" ] } ], @@ -4495,7 +4408,7 @@ }, { "cell_type": "code", - "execution_count": 202, + "execution_count": 166, "id": "dd645337", "metadata": {}, "outputs": [ @@ -4512,7 +4425,7 @@ }, { "cell_type": "code", - "execution_count": 203, + "execution_count": 167, "id": "935552d4", "metadata": {}, "outputs": [ @@ -4530,7 +4443,7 @@ }, { "cell_type": "code", - "execution_count": 204, + "execution_count": 168, "id": "05100765", "metadata": {}, "outputs": [ @@ -4538,7 +4451,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "true [3 2 1] [4 5 6]" + "false [4 5 6] [3 2 1]" ] } ], @@ -4548,8 +4461,8 @@ }, { "cell_type": "code", - "execution_count": 134, - "id": "187c0381", + "execution_count": 169, + "id": "7ac873d4", "metadata": {}, "outputs": [ { @@ -4564,7 +4477,7 @@ }, { "cell_type": "markdown", - "id": "1a8a8196", + "id": "7ef0f655", "metadata": {}, "source": [ "### Subtraction, at last...\n", @@ -4584,7 +4497,7 @@ }, { "cell_type": "markdown", - "id": "9751fd65", + "id": "173aa582", "metadata": {}, "source": [ "We want to use `check-gt` here:\n", @@ -4595,7 +4508,7 @@ }, { "cell_type": "markdown", - "id": "df2ae839", + "id": "242e863f", "metadata": {}, "source": [ "It seems we should just flip the sign bit if we swap, eh?\n", @@ -4605,7 +4518,7 @@ }, { "cell_type": "markdown", - "id": "c775c3a4", + "id": "37ed39c6", "metadata": {}, "source": [ "Now we subtract the digits:\n", @@ -4629,14 +4542,14 @@ " [swap sub-carry]\n", " [sub-with-carry]\n", " build-two-list-combiner\n", - " [i cons] genrec\n", + " genrec\n", "\n", "We just need to define the pieces." ] }, { "cell_type": "markdown", - "id": "32eeaf38", + "id": "844210e4", "metadata": {}, "source": [ "#### `sub-with-carry`\n", @@ -4646,14 +4559,14 @@ }, { "cell_type": "markdown", - "id": "3b47df3b", + "id": "3c10e256", "metadata": {}, "source": [ " carry a b sub-with-carry\n", " ------------------------------\n", " (a-b-carry) new-carry\n", "\n", - " _sub-with-carry0 ≡ [bool_to_int] dipd - -\n", + " _sub-with-carry0 ≡ [bool-to-int] dipd - -\n", " _sub-with-carry1 ≡ [base + base mod] [0 <] clop\n", "\n", " sub-with-carry ≡ _sub-with-carry0 _sub-with-carry1\n" @@ -4661,8 +4574,8 @@ }, { "cell_type": "code", - "execution_count": 135, - "id": "880dc3da", + "execution_count": 170, + "id": "c360cc7b", "metadata": {}, "outputs": [ { @@ -4672,15 +4585,15 @@ } ], "source": [ - "[_sub-with-carry0 rolldown bool_to_int [-] ii] inscribe\n", + "[_sub-with-carry0 rolldown bool-to-int [-] ii] inscribe\n", "[_sub-with-carry1 [base + base mod] [0 <] cleave] inscribe\n", "[sub-with-carry _sub-with-carry0 _sub-with-carry1] inscribe" ] }, { "cell_type": "code", - "execution_count": 139, - "id": "bae53ad4", + "execution_count": 171, + "id": "3a84adff", "metadata": { "scrolled": true }, @@ -4699,8 +4612,8 @@ }, { "cell_type": "code", - "execution_count": 140, - "id": "f54d93bc", + "execution_count": 172, + "id": "0dcdc968", "metadata": {}, "outputs": [ { @@ -4717,8 +4630,8 @@ }, { "cell_type": "code", - "execution_count": 141, - "id": "740034d8", + "execution_count": 173, + "id": "2d60492d", "metadata": {}, "outputs": [ { @@ -4746,7 +4659,7 @@ }, { "cell_type": "markdown", - "id": "d29e6193", + "id": "fc4ff7c6", "metadata": {}, "source": [ "That leaves the recursive branch:\n", @@ -4768,7 +4681,7 @@ }, { "cell_type": "markdown", - "id": "d31868ab", + "id": "984f1bf4", "metadata": {}, "source": [ " \n", @@ -4783,7 +4696,7 @@ }, { "cell_type": "markdown", - "id": "5c4404a8", + "id": "845abba7", "metadata": {}, "source": [ "But there's a problem! This winds up subtracting `a` from 0 rather than the other way around:\n", @@ -4793,16 +4706,14 @@ }, { "cell_type": "code", - "execution_count": 147, - "id": "be093900", + "execution_count": 174, + "id": "20c8ad40", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", - "text": [ - "[3 2 1]" - ] + "text": [] } ], "source": [ @@ -4818,7 +4729,7 @@ }, { "cell_type": "markdown", - "id": "253538a4", + "id": "77e427f9", "metadata": {}, "source": [ "Try it out:" @@ -4826,8 +4737,8 @@ }, { "cell_type": "code", - "execution_count": 148, - "id": "ce9f01e2", + "execution_count": 175, + "id": "92201303", "metadata": {}, "outputs": [ { @@ -4846,8 +4757,8 @@ }, { "cell_type": "code", - "execution_count": 160, - "id": "2120af39", + "execution_count": 176, + "id": "1a1d7cdc", "metadata": {}, "outputs": [ { @@ -4866,8 +4777,8 @@ }, { "cell_type": "code", - "execution_count": 161, - "id": "55fc1f59", + "execution_count": 177, + "id": "39ce9c6a", "metadata": {}, "outputs": [ { @@ -4886,8 +4797,8 @@ }, { "cell_type": "code", - "execution_count": 162, - "id": "1db3eaeb", + "execution_count": 178, + "id": "a93e916e", "metadata": {}, "outputs": [ { @@ -4906,8 +4817,8 @@ }, { "cell_type": "code", - "execution_count": 163, - "id": "ededec7b", + "execution_count": 179, + "id": "c2273ff3", "metadata": {}, "outputs": [ { @@ -4922,7 +4833,7 @@ }, { "cell_type": "markdown", - "id": "ffc08bef", + "id": "7c609313", "metadata": {}, "source": [ "But what about those leading zeroes?\n", @@ -4934,8 +4845,8 @@ }, { "cell_type": "code", - "execution_count": 165, - "id": "fe557598", + "execution_count": 180, + "id": "d8c7f7a5", "metadata": {}, "outputs": [ { @@ -4950,32 +4861,8 @@ }, { "cell_type": "code", - "execution_count": null, - "id": "f7275cd6", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "740a5c97", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "9ea8ba1c", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": 164, - "id": "b6c2e9ee", + "execution_count": 181, + "id": "875aaafa", "metadata": {}, "outputs": [ { @@ -4985,20 +4872,80 @@ } ], "source": [ - "[sub-carry-from-digits popd] inscribe" + "[sub-carry-from-digits\n", + " [pop not]\n", + " [popd]\n", + " [_scfd_R0]\n", + " [i cons-but-not-leading-zeroes]\n", + " genrec\n", + "] inscribe" + ] + }, + { + "cell_type": "code", + "execution_count": 182, + "id": "bd2447b6", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [] + } + ], + "source": [ + "[_scfd_R0 uncons 0 swap [sub-with-carry] dip] inscribe" + ] + }, + { + "cell_type": "code", + "execution_count": 183, + "id": "ffaf1fcc", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[9 9]" + ] + } + ], + "source": [ + "clear\n", + "\n", + "true [0 0 1] sub-carry-from-digits" + ] + }, + { + "cell_type": "code", + "execution_count": 184, + "id": "8a2b2165", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [] + } + ], + "source": [ + "clear" ] }, { "cell_type": "markdown", - "id": "32cef119", + "id": "73180c15", "metadata": {}, "source": [ + "#### `sub-carry`\n", + "\n", " sub-carry == pop" ] }, { "cell_type": "code", - "execution_count": 230, + "execution_count": 185, "id": "c22775e9", "metadata": {}, "outputs": [ @@ -5013,16 +4960,16 @@ "[sub-digits initial-carry sub-digits'] inscribe\n", "[sub-digits'\n", " [sub-carry-from-digits]\n", - " [swap sub-carry]\n", + " [swap pop]\n", " [sub-with-carry]\n", " build-two-list-combiner\n", - " \n", + " genrec\n", "] inscribe" ] }, { "cell_type": "code", - "execution_count": 231, + "execution_count": 186, "id": "ac670030", "metadata": {}, "outputs": [ @@ -5030,65 +4977,54 @@ "name": "stdout", "output_type": "stream", "text": [ - "false [3 2 1] [6 5 4] [P] [[P'] [ditch-empty-list sub-carry-from-digits] [pop swap sub-carry] ifte] [uncons-two [sub-with-carry] dipd]" + "true [3 2 1] [6 5 4]" ] } ], "source": [ "clear\n", - "false\n", - "[3 2 1] [6 5 4]\n", - "[sub-carry-from-digits]\n", - " [swap sub-carry]\n", - " [sub-with-carry]\n", - " build-two-list-combiner" + "true [3 2 1] [6 5 4]" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 187, + "id": "c19ff340", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "false false [6 5 4] [3 2 1]" + ] + } + ], + "source": [ + "check-gt initial-carry" + ] + }, + { + "cell_type": "code", + "execution_count": 188, "id": "8fbba815", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "false [3 3 3]" + ] + } + ], "source": [ - "[i cons] genrec\n" + "sub-digits'" ] }, { "cell_type": "code", - "execution_count": null, - "id": "cce0cc68", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "9163ad94", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "d862f5a8", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "976c4d53", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": 212, + "execution_count": 189, "id": "3b05693f", "metadata": {}, "outputs": [ @@ -5096,18 +5032,18 @@ "name": "stdout", "output_type": "stream", "text": [ - "[true 12345] [true 109]" + "[true 5 4 3 2 1] [true 9 0 1]" ] } ], "source": [ "clear\n", - "12345 to_bigint 109 to_bigint" + "12345 to-bigint 109 to-bigint" ] }, { "cell_type": "code", - "execution_count": 213, + "execution_count": 190, "id": "fc69485b", "metadata": {}, "outputs": [ @@ -5115,7 +5051,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "false false [109] [12345] [P] [[[P'] [ditch-empty-list sub-carry-from-digits] [pop swap sub-carry] ifte] uncons-two [sub-with-carry] dipd]" + "[true 6 3 2 2 1]" ] } ], @@ -5123,481 +5059,24 @@ "sub-like-bigints" ] }, - { - "cell_type": "markdown", - "id": "ca954866", - "metadata": {}, - "source": [ - " false false [109] [12345]\n", - " [P]\n", - " [\n", - " [P']\n", - " [ditch-empty-list sub-carry-from-digits]\n", - " [pop swap sub-carry]\n", - " ifte\n", - " ]\n", - " [\n", - " [uncons-two [sub-with-carry] dipd]\n", - " i cons\n", - " ]" - ] - }, { "cell_type": "code", - "execution_count": null, - "id": "45a744b7", - "metadata": {}, - "outputs": [], - "source": [ - "[i cons] genrec" - ] - }, - { - "cell_type": "markdown", - "id": "bc354239", - "metadata": {}, - "source": [ - "- Did I redefine something?\n", - "- Did a definition not make it into the dictionary?\n", - "- Trace in the Notebooks should show a trace even if an exception is encountered.\n" - ] - }, - { - "cell_type": "code", - "execution_count": 215, - "id": "9b2fd2fb", + "execution_count": 191, + "id": "c992d25a", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "\n", - "==== Help on P ====\n", - "\n", - "P ≡ [bool] ii & not\n", - "\n", - "---- end ( P )\n", - "\n", - "\n", - "false false [109] [12345] [P] [[[P'] [ditch-empty-list sub-carry-from-digits] [pop swap sub-carry] ifte] uncons-two [sub-with-carry] dipd]" + "12236" ] } ], "source": [ - "[P] help" + "from-bigint" ] }, - { - "cell_type": "code", - "execution_count": 216, - "id": "3a69a1a2", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "==== Help on P' ====\n", - "\n", - "P' ≡ [bool] ii |\n", - "\n", - "---- end ( P' )\n", - "\n", - "\n", - "false false [109] [12345] [P] [[[P'] [ditch-empty-list sub-carry-from-digits] [pop swap sub-carry] ifte] uncons-two [sub-with-carry] dipd]" - ] - } - ], - "source": [ - "[P'] help" - ] - }, - { - "cell_type": "code", - "execution_count": 224, - "id": "e29a136f", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "false false [109] [12345]" - ] - } - ], - "source": [ - "pop" - ] - }, - { - "cell_type": "code", - "execution_count": 220, - "id": "7499c430", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "false false [109] [12345]" - ] - } - ], - "source": [ - " [109] [12345] " - ] - }, - { - "cell_type": "code", - "execution_count": 225, - "id": "1f38a3a1", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "false false [109] [12345] true" - ] - } - ], - "source": [ - "[P'] nullary\n", - " " - ] - }, - { - "cell_type": "code", - "execution_count": 221, - "id": "31103274", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "false false [109] [12345] [[P'] [ditch-empty-list sub-carry-from-digits] [pop swap sub-carry] ifte]" - ] - } - ], - "source": [ - " [[P'] [ditch-empty-list sub-carry-from-digits] [pop swap sub-carry] ifte]\n", - " " - ] - }, - { - "cell_type": "code", - "execution_count": 221, - "id": "9f3e739d", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "false false [109] [12345] [[P'] [ditch-empty-list sub-carry-from-digits] [pop swap sub-carry] ifte]" - ] - } - ], - "source": [ - " [[P'] [ditch-empty-list sub-carry-from-digits] [pop swap sub-carry] ifte]\n", - " " - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "11639f03", - "metadata": {}, - "outputs": [], - "source": [ - " uncons-two [sub-with-carry] dipd" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "2889ee5e", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "328334db", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "76e3a1ca", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "93d70133", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": 240, - "id": "f2bc1f16", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [] - } - ], - "source": [ - "clear" - ] - }, - { - "cell_type": "code", - "execution_count": 241, - "id": "c404eb99", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "false [3 2 1] [6 5 4] [P] [[P'] [ditch-empty-list sub-carry-from-digits] [pop swap pop] ifte] [uncons-two [sub-with-carry] dipd]" - ] - } - ], - "source": [ - "clear\n", - "false\n", - "[3 2 1] [6 5 4]\n", - "[sub-carry-from-digits]\n", - " [swap pop]\n", - " [sub-with-carry]\n", - " build-two-list-combiner" - ] - }, - { - "cell_type": "code", - "execution_count": 242, - "id": "74502c4c", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[2147483645 2147483644 2147483644]" - ] - } - ], - "source": [ - "[i cons] genrec\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "39a842e5", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": 243, - "id": "ecb3de02", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "false [6 5 4] [3 2 1] [P] [[P'] [ditch-empty-list sub-carry-from-digits] [pop swap pop] ifte] [uncons-two [sub-with-carry] dipd]" - ] - } - ], - "source": [ - "clear\n", - "false\n", - "[3 2 1] [6 5 4] swap\n", - "[sub-carry-from-digits]\n", - " [swap pop]\n", - " [sub-with-carry]\n", - " build-two-list-combiner" - ] - }, - { - "cell_type": "code", - "execution_count": 244, - "id": "0bf21e08", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[3 3 3]" - ] - } - ], - "source": [ - "[i cons] genrec\n" - ] - }, - { - "cell_type": "markdown", - "id": "74054f2f", - "metadata": {}, - "source": [ - "That sure fucking *looks* like it works." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "20462cd5", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": 247, - "id": "2ab1031c", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "true [6 5 4] [3 2 1]" - ] - } - ], - "source": [ - "clear\n", - "false\n", - "[3 2 1] [6 5 4] check-gt" - ] - }, - { - "cell_type": "code", - "execution_count": 248, - "id": "1b908ee7", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "true [6 5 4] [3 2 1] [P] [[P'] [ditch-empty-list sub-carry-from-digits] [pop swap pop] ifte] [uncons-two [sub-with-carry] dipd]" - ] - } - ], - "source": [ - "[sub-carry-from-digits]\n", - " [swap pop]\n", - " [sub-with-carry]\n", - " build-two-list-combiner" - ] - }, - { - "cell_type": "code", - "execution_count": 249, - "id": "e223937e", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[2 3 3]" - ] - } - ], - "source": [ - "[i cons] genrec\n" - ] - }, - { - "cell_type": "code", - "execution_count": 251, - "id": "a5747b29", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "-333" - ] - } - ], - "source": [ - "clear 123 456 -" - ] - }, - { - "cell_type": "markdown", - "id": "64c14e67", - "metadata": {}, - "source": [ - "Almost." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "c9999912", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "29a0586c", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "bb8cb15e", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "6a5b3ace", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "417e2d45", - "metadata": {}, - "outputs": [], - "source": [] - }, { "cell_type": "markdown", "id": "f2b707c1", @@ -5607,11 +5086,11 @@ "\n", " base 2147483648\n", " ditch-empty-list [bool] [popd] [pop] ifte\n", - " bool_to_int [0] [1] branch\n", + " bool-to-int [0] [1] branch\n", " uncons-two [uncons] ii swapd\n", "\n", " add-with-carry _a0 _a1\n", - " _a0 [bool_to_int] dipd + +\n", + " _a0 [bool-to-int] dipd + +\n", " _a1 base [mod] [>=] clop\n", "\n", " add-carry-to-digits [pop not] [popd] [_actd_R0] [i cons] genrec\n", diff --git a/implementations/bigints.joy b/implementations/bigints.joy index 7a92079..27c997b 100644 --- a/implementations/bigints.joy +++ b/implementations/bigints.joy @@ -64,7 +64,7 @@ clear [sub-carry-from-digits [pop not] [popd] [_scfd_R0] [i cons-but-not-leading-zeroes] genrec] inscribe [_scfd_R0 uncons 0 swap [sub-with-carry] dip] inscribe -[cons-but-not-leading-zeroes [[bool] ii | not] [popd] [cons] ifte] +[cons-but-not-leading-zeroes [P'] [cons] [popd] ifte] [sub-with-carry _sub-with-carry0 _sub-with-carry1] [_sub-with-carry0 rolldown bool-to-int [-] ii] @@ -92,6 +92,3 @@ build-two-list-combiner inscribe -true [0 1] sub-carry-from-digits - -