From 8bedb7746200c2effef7e51db5ef96d6554807db Mon Sep 17 00:00:00 2001 From: Simon Forman Date: Tue, 11 Oct 2022 11:37:38 -0700 Subject: [PATCH] Adding like-sign bigints in Joy. --- docs/notebooks/BigInts.ipynb | 971 +++++++++++++++++---- docs/notebooks/Recursion_Combinators.ipynb | 162 +++- 2 files changed, 964 insertions(+), 169 deletions(-) diff --git a/docs/notebooks/BigInts.ipynb b/docs/notebooks/BigInts.ipynb index 90bddb3..c678efc 100644 --- a/docs/notebooks/BigInts.ipynb +++ b/docs/notebooks/BigInts.ipynb @@ -1,25 +1,24 @@ { "cells": [ { - "cell_type": "code", - "execution_count": 1, - "id": "73967878", + "cell_type": "markdown", + "id": "be337543", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [] - } - ], "source": [ - "[all true swap [&] step] inscribe\n", - "[any false swap [|] step] inscribe" + "# BigInts in Joy\n", + "\n", + "Part of the puzzle is implementing \"bigints\", unbounded integers, by means of Oberon RISC signed 32-bit ints and their operations.\n", + "\n", + "Model bigints as a pair of Boolean for the sign and a list of integers for the digits, to keep things simple let the bool be the first item on a list followed by zero or more int digits. The Least Signifigant digit is at the top or head of the list. The digits shall be confined to the range zero to `pow(2, 31) - 1`\n", + "\n", + "Another way to say that is that our numbers are in base `2147483648` and our \"nine\" is `2147483647` (`0b1111111111111111111111111111111`, 31 ones.)\n", + "\n", + "This lets us use (Oberon RISC) 32-bit signed ints to store our digits." ] }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "id": "b34d58ef", "metadata": {}, "outputs": [ @@ -33,21 +32,9 @@ "[base 2147483648] inscribe" ] }, - { - "cell_type": "markdown", - "id": "9749000b", - "metadata": {}, - "source": [ - "Model bigints as a pair of Boolean for the sign and a list of integers for the digits, to keep things simple let the bool be the first item on a list followed by zero or more int digits. The digits shall be confined to the range zero to `pow(2, 31) - 1`\n", - "\n", - "Another way to say that is that our numbers are in base `2147483648` and our \"nine\" is `2147483647` (`0b1111111111111111111111111111111`, 31 ones.)\n", - "\n", - "This lets us use (Oberon RISC) 32-bit signed ints to store our digits." - ] - }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "id": "35476eac", "metadata": {}, "outputs": [ @@ -63,7 +50,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 3, "id": "02a48806", "metadata": {}, "outputs": [ @@ -81,42 +68,12 @@ ] }, { - "cell_type": "code", - "execution_count": 5, - "id": "1d276daf", + "cell_type": "markdown", + "id": "dea19f43", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "true" - ] - } - ], "source": [ - "clear\n", - "[true 3 2 1]\n", - "rest [valid_digit] map all" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "id": "2454e662", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[true 3 2 1]" - ] - } - ], - "source": [ - "clear\n", - "[true 3 2 1]" + "## Converting to and from Python Integers\n", + "Because we are working with Python Joy right now we can convert ints to bigints and vice versa. THis will be helpful to check our work. Later we can deal with converting to and from strings (which this Joy doesn't have anyway, so it's probably fine to defer.)" ] }, { @@ -124,14 +81,12 @@ "id": "bfed1f25", "metadata": {}, "source": [ - "Because we are working with Python Joy right now we can convert ints to bigints.\n", - "\n", "To get the sign bool we can just use `!-` (\"not negative\")" ] }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 4, "id": "8a60b54b", "metadata": {}, "outputs": [ @@ -150,28 +105,15 @@ }, { "cell_type": "markdown", - "id": "73bfa634", + "id": "9f7b5ab2", "metadata": {}, "source": [ - "To get the list of digits...\n", - "\n", - "```\n", - " @staticmethod\n", - " def digitize(n):\n", - " if n < 0:\n", - " raise ValueError(f'Non-negative only: {n}')\n", - " while n:\n", - " n, digit = divmod(n, 2**31)\n", - " yield OberonInt(digit)\n", - "\n", - "```\n", - "\n", - " [0 >=] [base divmod swap] while" + "To get the list of digits we repeatedly `divmod` the number by our `base`:" ] }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 5, "id": "3fc98ccd", "metadata": {}, "outputs": [ @@ -191,7 +133,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 6, "id": "b838c4cb", "metadata": {}, "outputs": [ @@ -209,15 +151,35 @@ }, { "cell_type": "code", - "execution_count": null, - "id": "4d9d926a", + "execution_count": 7, + "id": "f5dc3799", "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1797196498 1453937433 2 0" + ] + } + ], + "source": [ + "base divmod swap" + ] + }, + { + "cell_type": "markdown", + "id": "73bfa634", + "metadata": {}, + "source": [ + "We keep it up until we get to zero.\n", + "\n", + " [0 >=] [base divmod swap] while" + ] }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 8, "id": "faaac9d6", "metadata": {}, "outputs": [ @@ -236,9 +198,17 @@ " [0 >] [base divmod swap] while pop" ] }, + { + "cell_type": "markdown", + "id": "50c4cf87", + "metadata": {}, + "source": [ + "But we want these numbers in a list. The naive way using `infra` generates them in the reverse order of what we would like." + ] + }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 9, "id": "2a613f36", "metadata": {}, "outputs": [ @@ -254,35 +224,22 @@ "clear\n", "\n", "[1234567890123456789012345678901234567890]\n", - " [ [0 >] [base divmod swap] while pop ]\n", - " infra" + "[ [0 >] [base divmod swap] while pop ]\n", + "infra" ] }, { - "cell_type": "code", - "execution_count": 12, - "id": "e97b149d", + "cell_type": "markdown", + "id": "d4e1877f", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1234567890123456789012345678901234567890 [0 <=] [pop []] [base divmod swap] [i cons]" - ] - } - ], "source": [ - "clear\n", - "\n", - "1234567890123456789012345678901234567890\n", - " [0 <=] [pop []] [base divmod swap] [i cons]" + "Instead we want a simple \"anamorphism\" builds the result list in the order we want LSB->MSB. " ] }, { "cell_type": "code", - "execution_count": 13, - "id": "de4fe588", + "execution_count": 10, + "id": "e97b149d", "metadata": {}, "outputs": [ { @@ -294,12 +251,19 @@ } ], "source": [ + "clear\n", + "\n", + "1234567890123456789012345678901234567890\n", + "[0 <=]\n", + "[pop []]\n", + "[base divmod swap]\n", + "[i cons]\n", "genrec" ] }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 11, "id": "67bb934b", "metadata": {}, "outputs": [ @@ -317,9 +281,17 @@ "0 [0 <=] [pop []] [base divmod swap] [i cons] genrec" ] }, + { + "cell_type": "markdown", + "id": "98c78bfe", + "metadata": {}, + "source": [ + "#### `digitalize`" + ] + }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 12, "id": "227271a9", "metadata": {}, "outputs": [ @@ -337,7 +309,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 13, "id": "b6f77ac6", "metadata": {}, "outputs": [ @@ -365,7 +337,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 14, "id": "246c2a58", "metadata": {}, "outputs": [ @@ -380,12 +352,21 @@ "source": [ "clear\n", "\n", - "1234567890123456789012345678901234567890 [!-] [abs digitalize] cleave cons" + "1234567890123456789012345678901234567890\n", + "[!-] [abs digitalize] cleave cons" + ] + }, + { + "cell_type": "markdown", + "id": "e995ac71", + "metadata": {}, + "source": [ + "#### `to_bigint`" ] }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 15, "id": "5a72ce30", "metadata": {}, "outputs": [ @@ -403,7 +384,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 16, "id": "59514dcd", "metadata": {}, "outputs": [ @@ -423,7 +404,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 17, "id": "f3c19364", "metadata": {}, "outputs": [ @@ -443,7 +424,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 18, "id": "998512c6", "metadata": {}, "outputs": [ @@ -457,6 +438,434 @@ "clear" ] }, + { + "cell_type": "markdown", + "id": "4976cf87", + "metadata": {}, + "source": [ + "### Converting from bigint to Python ints\n", + "\n", + "To convert a bigint into a Python integer we need to keep a \"power\" parameter on the stack, setting it up and discarding it at the end, as well as an accumulator value starting at zero:\n", + "\n", + " prep == rest 1 0 rolldown\n", + "\n", + " [true 3 2 1] rest 1 0 rolldown\n", + " 1 0 [3 2 1]\n", + "\n", + "We will deal with the sign bit later." + ] + }, + { + "cell_type": "markdown", + "id": "e814f934", + "metadata": {}, + "source": [ + "So the problem is to derive:\n", + "\n", + " 1 0 [digits...] [F] step\n", + " -------------------------\n", + " result\n", + "\n", + "Where `F` is:\n", + "\n", + " power acc digit F\n", + " ---------------------------------------\n", + " (power*base) (acc + (power*digit)" + ] + }, + { + "cell_type": "markdown", + "id": "8c3acc24", + "metadata": {}, + "source": [ + "Now this is an interesting function. The first thing I noticed is that it has two results that can be computed independently, suggesting a form like:\n", + "\n", + " F == [G] [H] clop\n", + "\n", + "Then I noticed that `power *` is a sub-function of both `G` and `H`, but let's not overthink it, eh?\n", + "\n", + " G == popop base *\n", + " H == rolldown * +\n", + "\n", + " F == [G] [H] clop popdd\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "4b988095", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2147483648" + ] + } + ], + "source": [ + "clear\n", + "\n", + "1 0 23 popop base *" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "51e79e00", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "23" + ] + } + ], + "source": [ + "clear\n", + "\n", + "1 0 23 rolldown * +" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "1d19061d", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2147483648 23" + ] + } + ], + "source": [ + "clear\n", + "\n", + "1 0 23 [popop base *] [rolldown * +] clop popdd" + ] + }, + { + "cell_type": "markdown", + "id": "9d2d7c33", + "metadata": {}, + "source": [ + "#### `prep` and `from_bigint'`" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "bb5b7bfe", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2147483648 23" + ] + } + ], + "source": [ + "[prep rest 1 0 rolldown] inscribe\n", + "[from_bigint' [F] step popd] inscribe\n", + "[F [G] [H] clop popdd] inscribe\n", + "[G popop base *] inscribe\n", + "[H rolldown * +] inscribe" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "4f7a2a4c", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2147483648 23" + ] + } + ], + "source": [ + "clear\n", + "\n", + "1 0 23 F" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "4fce526f", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1234567890123456789012345678901234567890" + ] + } + ], + "source": [ + "clear\n", + "\n", + "1 0 [1312754386 1501085485 57659106 105448366 58] from_bigint'" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "d20cf6cc", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[true 1312754386 1501085485 57659106 105448366 58]" + ] + } + ], + "source": [ + "to_bigint" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "cd3e41bb", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1 0 [1312754386 1501085485 57659106 105448366 58]" + ] + } + ], + "source": [ + "prep" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "5ab43d77", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1234567890123456789012345678901234567890" + ] + } + ], + "source": [ + "from_bigint'" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "d1fd81d0", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1234567890123456789012345678901234567890" + ] + } + ], + "source": [ + "to_bigint prep from_bigint'" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "id": "6cdb257c", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-1234567890123456789012345678901234567890" + ] + } + ], + "source": [ + "neg" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "id": "e72fdf6c", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1234567890123456789012345678901234567890" + ] + } + ], + "source": [ + "to_bigint prep from_bigint'" + ] + }, + { + "cell_type": "markdown", + "id": "d0947b57", + "metadata": {}, + "source": [ + "What about that sign bit?" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "id": "7f88bea1", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[true 1312754386 1501085485 57659106 105448366 58]" + ] + } + ], + "source": [ + "to_bigint" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "id": "d75da0ab", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "true 1234567890123456789012345678901234567890" + ] + } + ], + "source": [ + "[first] [prep from_bigint'] cleave" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "id": "93356c0d", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-1234567890123456789012345678901234567890" + ] + } + ], + "source": [ + "swap [] [neg] branch" + ] + }, + { + "cell_type": "markdown", + "id": "47f7b425", + "metadata": {}, + "source": [ + " foo == [first] [prep from_bigint'] cleave\n", + " bar == swap [] [neg] branch\n", + " from_bigint == foo bar" + ] + }, + { + "cell_type": "markdown", + "id": "2f940d9c", + "metadata": {}, + "source": [ + "#### `from_bigint`" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "id": "60a3c265", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [] + } + ], + "source": [ + "clear\n", + "[foo [first] [prep from_bigint'] cleave] inscribe\n", + "[bar swap [neg] [] branch] inscribe\n", + "[from_bigint foo bar] inscribe" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "id": "f2f60ef2", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1234567890123456789012345678901234567890" + ] + } + ], + "source": [ + "1234567890123456789012345678901234567890 to_bigint from_bigint" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "id": "fb95c019", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-1234567890123456789012345678901234567890" + ] + } + ], + "source": [ + "neg to_bigint\n", + "\n", + "from_bigint" + ] + }, { "cell_type": "markdown", "id": "0a592c8e", @@ -493,7 +902,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 37, "id": "b2d4f3b2", "metadata": {}, "outputs": [ @@ -519,7 +928,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 38, "id": "d87fa971", "metadata": {}, "outputs": [ @@ -557,7 +966,7 @@ "metadata": {}, "source": [ "### The base cases\n", - "We have to decide between three cases, but because addition we can lump together the first two cases:\n", + "We have to decide between three cases, but because addition is commutative we can lump together the first two cases:\n", "\n", " bool [] [b ...] THEN\n", " bool [a ...] [] THEN\n", @@ -568,7 +977,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 39, "id": "491c0846", "metadata": {}, "outputs": [ @@ -619,7 +1028,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 40, "id": "bd51792f", "metadata": {}, "outputs": [ @@ -636,7 +1045,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 41, "id": "fbf134e2", "metadata": {}, "outputs": [ @@ -654,7 +1063,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 42, "id": "90db3359", "metadata": {}, "outputs": [ @@ -682,7 +1091,7 @@ "\n", " carry [n ...] THEN''\n", "\n", - "This is `add-carry-to-digits` that kicked my ass earlier today. Like I mentioned above, I think it was because I put it in the recursive branch! D'oh!" + "This is `add-carry-to-digits`..." ] }, { @@ -700,9 +1109,17 @@ "(I find it interesting that this function accepts the carry from below the int args but returns it above the result. Hmm...)" ] }, + { + "cell_type": "markdown", + "id": "3c349c8f", + "metadata": {}, + "source": [ + "#### `bool_to_int`" + ] + }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 43, "id": "e86b7b90", "metadata": {}, "outputs": [ @@ -725,7 +1142,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 44, "id": "cd70e18e", "metadata": {}, "outputs": [ @@ -745,7 +1162,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 45, "id": "a27ff9f0", "metadata": {}, "outputs": [ @@ -773,7 +1190,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 46, "id": "74a59ab5", "metadata": {}, "outputs": [ @@ -793,7 +1210,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 47, "id": "3a8f5078", "metadata": {}, "outputs": [ @@ -826,9 +1243,17 @@ " add-with-carry ≡ _add-with-carry0 _add-with-carry1\n" ] }, + { + "cell_type": "markdown", + "id": "642e3b74", + "metadata": {}, + "source": [ + "#### `add-with-carry`" + ] + }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 48, "id": "c05bcd8e", "metadata": {}, "outputs": [ @@ -847,7 +1272,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 49, "id": "03649114", "metadata": {}, "outputs": [ @@ -867,7 +1292,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 50, "id": "9dca0fbc", "metadata": {}, "outputs": [ @@ -887,7 +1312,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 51, "id": "c8f01d7d", "metadata": {}, "outputs": [ @@ -907,7 +1332,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 52, "id": "a1e77990", "metadata": {}, "outputs": [ @@ -927,7 +1352,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 53, "id": "b46a62ba", "metadata": {}, "outputs": [ @@ -1024,9 +1449,17 @@ " _actd_R1 ≡ i cons" ] }, + { + "cell_type": "markdown", + "id": "533e54ab", + "metadata": {}, + "source": [ + "#### `add-carry-to-digits`" + ] + }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 54, "id": "c8f1aa44", "metadata": {}, "outputs": [ @@ -1048,7 +1481,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 55, "id": "1fa115d9", "metadata": {}, "outputs": [ @@ -1068,7 +1501,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 56, "id": "79d9c526", "metadata": {}, "outputs": [ @@ -1088,7 +1521,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 57, "id": "bb030214", "metadata": {}, "outputs": [ @@ -1108,7 +1541,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 58, "id": "5e0a05af", "metadata": {}, "outputs": [ @@ -1128,7 +1561,7 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 59, "id": "7c730d6d", "metadata": {}, "outputs": [ @@ -1159,7 +1592,7 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 60, "id": "5e5ddf74", "metadata": {}, "outputs": [ @@ -1179,7 +1612,7 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 61, "id": "c57d1fb2", "metadata": {}, "outputs": [ @@ -1199,7 +1632,7 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 62, "id": "59b1338c", "metadata": {}, "outputs": [ @@ -1259,7 +1692,7 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 63, "id": "78dec757", "metadata": {}, "outputs": [ @@ -1288,7 +1721,7 @@ }, { "cell_type": "code", - "execution_count": 49, + "execution_count": 64, "id": "5b4bd2fe", "metadata": {}, "outputs": [ @@ -1310,7 +1743,7 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 65, "id": "f284ea19", "metadata": {}, "outputs": [ @@ -1350,9 +1783,17 @@ " R1 ≡ i cons\n" ] }, + { + "cell_type": "markdown", + "id": "ef20a308", + "metadata": {}, + "source": [ + "#### `add-digits`" + ] + }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 66, "id": "8adffacb", "metadata": {}, "outputs": [ @@ -1377,7 +1818,7 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 67, "id": "5b2e5738", "metadata": {}, "outputs": [ @@ -1395,7 +1836,7 @@ }, { "cell_type": "code", - "execution_count": 53, + "execution_count": 68, "id": "cd7ac0b9", "metadata": {}, "outputs": [ @@ -1413,7 +1854,7 @@ }, { "cell_type": "code", - "execution_count": 54, + "execution_count": 69, "id": "50f2e62c", "metadata": {}, "outputs": [ @@ -1431,7 +1872,7 @@ }, { "cell_type": "code", - "execution_count": 55, + "execution_count": 70, "id": "54ca630f", "metadata": {}, "outputs": [ @@ -1449,7 +1890,7 @@ }, { "cell_type": "code", - "execution_count": 56, + "execution_count": 71, "id": "27bb4638", "metadata": {}, "outputs": [ @@ -1467,7 +1908,7 @@ }, { "cell_type": "code", - "execution_count": 57, + "execution_count": 72, "id": "4d2d446a", "metadata": {}, "outputs": [ @@ -1493,7 +1934,7 @@ }, { "cell_type": "code", - "execution_count": 58, + "execution_count": 73, "id": "c187ffff", "metadata": {}, "outputs": [ @@ -1514,7 +1955,211 @@ "id": "c142268c", "metadata": {}, "source": [ - "Bitchin'" + "## `add-bigints`\n", + "\n", + "There is one more thing we have to do to use this: we have to deal with the signs.\n", + "\n", + " add-bigints \n", + " [[first] ii xor not] # are they the same sign?\n", + " [[uncons] dip rest add-digits cons] # add the digits and set the sign.\n", + " [neg-bigint sub-bigints] # adding unlikes is actually subtraction.\n", + " ifte\n", + "\n", + "But we haven't implemented `neg-bigint` or `sub-bigints` yet..." + ] + }, + { + "cell_type": "code", + "execution_count": 74, + "id": "75ca9562", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[true 123] [true 456]" + ] + } + ], + "source": [ + "clear\n", + "\n", + "123 to_bigint 456 to_bigint" + ] + }, + { + "cell_type": "code", + "execution_count": 75, + "id": "e95920cc", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "true" + ] + } + ], + "source": [ + "[first] ii xor not" + ] + }, + { + "cell_type": "code", + "execution_count": 76, + "id": "24f0ab0c", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[true 123] [true 456]" + ] + } + ], + "source": [ + "clear\n", + "\n", + "123 to_bigint 456 to_bigint" + ] + }, + { + "cell_type": "code", + "execution_count": 77, + "id": "7d8cf685", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "true [123] [true 456]" + ] + } + ], + "source": [ + "[uncons] dip" + ] + }, + { + "cell_type": "code", + "execution_count": 78, + "id": "e3f2133d", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "true [123] [456]" + ] + } + ], + "source": [ + "rest " + ] + }, + { + "cell_type": "code", + "execution_count": 79, + "id": "97bc172d", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "true [579]" + ] + } + ], + "source": [ + "add-digits" + ] + }, + { + "cell_type": "code", + "execution_count": 80, + "id": "16f056bc", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[true 579]" + ] + } + ], + "source": [ + " cons" + ] + }, + { + "cell_type": "markdown", + "id": "45839ac3", + "metadata": {}, + "source": [ + "#### `add-bigints`" + ] + }, + { + "cell_type": "code", + "execution_count": 81, + "id": "ca884af6", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[true 579]" + ] + } + ], + "source": [ + "[same-sign [first] ii xor not] inscribe\n", + "[add-like-bigints [uncons] dip rest add-digits cons] inscribe\n", + "[add-bigints [same-sign] [add-like-bigints] [1 0 /] ifte] inscribe" + ] + }, + { + "cell_type": "code", + "execution_count": 82, + "id": "4bebb355", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[true 579] [true 2147483647]" + ] + } + ], + "source": [ + "base -- to_bigint" + ] + }, + { + "cell_type": "code", + "execution_count": 83, + "id": "12a79bb6", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[true 578 1]" + ] + } + ], + "source": [ + "add-bigints" ] }, { @@ -1546,16 +2191,12 @@ " R0 uncons-two [add-with-carry] dipd\n", " P' [bool] ii |\n", " THEN' ditch-empty-list add-carry-to-digits\n", - " ELSE pop swap [] [1 swons] branch\n" + " ELSE pop swap [] [1 swons] branch\n", + "\n", + " same-sign [first] ii xor not\n", + " add-like-bigints [uncons] dip rest add-digits cons\n", + " add-bigints [same-sign] [add-like-bigints] [1 0 /] ifte" ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "84affe68", - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { diff --git a/docs/notebooks/Recursion_Combinators.ipynb b/docs/notebooks/Recursion_Combinators.ipynb index a55f79e..d2fc90d 100644 --- a/docs/notebooks/Recursion_Combinators.ipynb +++ b/docs/notebooks/Recursion_Combinators.ipynb @@ -179,7 +179,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -301,7 +301,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 1, "metadata": {}, "outputs": [ { @@ -316,7 +316,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -331,7 +331,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 5, "metadata": { "scrolled": false }, @@ -340,6 +340,160 @@ "name": "stdout", "output_type": "stream", "text": [ + " 5 • range\n", + " 5 • [0 <=] [] [-- dup] [swons] hylomorphism\n", + " 5 [0 <=] • [] [-- dup] [swons] hylomorphism\n", + " 5 [0 <=] [] • [-- dup] [swons] hylomorphism\n", + " 5 [0 <=] [] [-- dup] • [swons] hylomorphism\n", + " 5 [0 <=] [] [-- dup] [swons] • hylomorphism\n", + " 5 [0 <=] [] [-- dup] [swons] • [unit [pop] swoncat] dipd [dip] swoncat genrec\n", + " 5 [0 <=] [] [-- dup] [swons] [unit [pop] swoncat] • dipd [dip] swoncat genrec\n", + " 5 [0 <=] [] • unit [pop] swoncat [-- dup] [swons] [dip] swoncat genrec\n", + " 5 [0 <=] [[]] • [pop] swoncat [-- dup] [swons] [dip] swoncat genrec\n", + " 5 [0 <=] [[]] [pop] • swoncat [-- dup] [swons] [dip] swoncat genrec\n", + " 5 [0 <=] [[]] [pop] • swap concat [-- dup] [swons] [dip] swoncat genrec\n", + " 5 [0 <=] [pop] [[]] • concat [-- dup] [swons] [dip] swoncat genrec\n", + " 5 [0 <=] [pop []] • [-- dup] [swons] [dip] swoncat genrec\n", + " 5 [0 <=] [pop []] [-- dup] • [swons] [dip] swoncat genrec\n", + " 5 [0 <=] [pop []] [-- dup] [swons] • [dip] swoncat genrec\n", + " 5 [0 <=] [pop []] [-- dup] [swons] [dip] • swoncat genrec\n", + " 5 [0 <=] [pop []] [-- dup] [swons] [dip] • swap concat genrec\n", + " 5 [0 <=] [pop []] [-- dup] [dip] [swons] • concat genrec\n", + " 5 [0 <=] [pop []] [-- dup] [dip swons] • genrec\n", + " 5 [0 <=] [pop []] [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] • ifte\n", + "5 [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] [pop []] [5] [0 <=] • infra first choice i\n", + " 5 • 0 <= [[pop []] [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] 5] swaack first choice i\n", + " 5 0 • <= [[pop []] [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] 5] swaack first choice i\n", + " 5 0 • le [[pop []] [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] 5] swaack first choice i\n", + " false • [[pop []] [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] 5] swaack first choice i\n", + " false [[pop []] [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] 5] • swaack first choice i\n", + " 5 [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] [pop []] [false] • first choice i\n", + " 5 [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] [pop []] false • choice i\n", + " 5 [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] • i\n", + " 5 • -- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons\n", + " 5 • 1 - dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons\n", + " 5 1 • - dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons\n", + " 5 1 • sub dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons\n", + " 4 • dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons\n", + " 4 4 • [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons\n", + " 4 4 [[0 <=] [pop []] [-- dup] [dip swons] genrec] • dip swons\n", + " 4 • [0 <=] [pop []] [-- dup] [dip swons] genrec 4 swons\n", + " 4 [0 <=] • [pop []] [-- dup] [dip swons] genrec 4 swons\n", + " 4 [0 <=] [pop []] • [-- dup] [dip swons] genrec 4 swons\n", + " 4 [0 <=] [pop []] [-- dup] • [dip swons] genrec 4 swons\n", + " 4 [0 <=] [pop []] [-- dup] [dip swons] • genrec 4 swons\n", + " 4 [0 <=] [pop []] [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] • ifte 4 swons\n", + "4 [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] [pop []] [4] [0 <=] • infra first choice i 4 swons\n", + " 4 • 0 <= [[pop []] [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] 4] swaack first choice i 4 swons\n", + " 4 0 • <= [[pop []] [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] 4] swaack first choice i 4 swons\n", + " 4 0 • le [[pop []] [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] 4] swaack first choice i 4 swons\n", + " false • [[pop []] [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] 4] swaack first choice i 4 swons\n", + " false [[pop []] [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] 4] • swaack first choice i 4 swons\n", + " 4 [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] [pop []] [false] • first choice i 4 swons\n", + " 4 [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] [pop []] false • choice i 4 swons\n", + " 4 [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] • i 4 swons\n", + " 4 • -- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons 4 swons\n", + " 4 • 1 - dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons 4 swons\n", + " 4 1 • - dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons 4 swons\n", + " 4 1 • sub dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons 4 swons\n", + " 3 • dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons 4 swons\n", + " 3 3 • [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons 4 swons\n", + " 3 3 [[0 <=] [pop []] [-- dup] [dip swons] genrec] • dip swons 4 swons\n", + " 3 • [0 <=] [pop []] [-- dup] [dip swons] genrec 3 swons 4 swons\n", + " 3 [0 <=] • [pop []] [-- dup] [dip swons] genrec 3 swons 4 swons\n", + " 3 [0 <=] [pop []] • [-- dup] [dip swons] genrec 3 swons 4 swons\n", + " 3 [0 <=] [pop []] [-- dup] • [dip swons] genrec 3 swons 4 swons\n", + " 3 [0 <=] [pop []] [-- dup] [dip swons] • genrec 3 swons 4 swons\n", + " 3 [0 <=] [pop []] [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] • ifte 3 swons 4 swons\n", + "3 [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] [pop []] [3] [0 <=] • infra first choice i 3 swons 4 swons\n", + " 3 • 0 <= [[pop []] [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] 3] swaack first choice i 3 swons 4 swons\n", + " 3 0 • <= [[pop []] [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] 3] swaack first choice i 3 swons 4 swons\n", + " 3 0 • le [[pop []] [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] 3] swaack first choice i 3 swons 4 swons\n", + " false • [[pop []] [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] 3] swaack first choice i 3 swons 4 swons\n", + " false [[pop []] [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] 3] • swaack first choice i 3 swons 4 swons\n", + " 3 [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] [pop []] [false] • first choice i 3 swons 4 swons\n", + " 3 [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] [pop []] false • choice i 3 swons 4 swons\n", + " 3 [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] • i 3 swons 4 swons\n", + " 3 • -- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons 3 swons 4 swons\n", + " 3 • 1 - dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons 3 swons 4 swons\n", + " 3 1 • - dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons 3 swons 4 swons\n", + " 3 1 • sub dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons 3 swons 4 swons\n", + " 2 • dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons 3 swons 4 swons\n", + " 2 2 • [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons 3 swons 4 swons\n", + " 2 2 [[0 <=] [pop []] [-- dup] [dip swons] genrec] • dip swons 3 swons 4 swons\n", + " 2 • [0 <=] [pop []] [-- dup] [dip swons] genrec 2 swons 3 swons 4 swons\n", + " 2 [0 <=] • [pop []] [-- dup] [dip swons] genrec 2 swons 3 swons 4 swons\n", + " 2 [0 <=] [pop []] • [-- dup] [dip swons] genrec 2 swons 3 swons 4 swons\n", + " 2 [0 <=] [pop []] [-- dup] • [dip swons] genrec 2 swons 3 swons 4 swons\n", + " 2 [0 <=] [pop []] [-- dup] [dip swons] • genrec 2 swons 3 swons 4 swons\n", + " 2 [0 <=] [pop []] [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] • ifte 2 swons 3 swons 4 swons\n", + "2 [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] [pop []] [2] [0 <=] • infra first choice i 2 swons 3 swons 4 swons\n", + " 2 • 0 <= [[pop []] [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] 2] swaack first choice i 2 swons 3 swons 4 swons\n", + " 2 0 • <= [[pop []] [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] 2] swaack first choice i 2 swons 3 swons 4 swons\n", + " 2 0 • le [[pop []] [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] 2] swaack first choice i 2 swons 3 swons 4 swons\n", + " false • [[pop []] [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] 2] swaack first choice i 2 swons 3 swons 4 swons\n", + " false [[pop []] [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] 2] • swaack first choice i 2 swons 3 swons 4 swons\n", + " 2 [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] [pop []] [false] • first choice i 2 swons 3 swons 4 swons\n", + " 2 [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] [pop []] false • choice i 2 swons 3 swons 4 swons\n", + " 2 [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] • i 2 swons 3 swons 4 swons\n", + " 2 • -- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons 2 swons 3 swons 4 swons\n", + " 2 • 1 - dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons 2 swons 3 swons 4 swons\n", + " 2 1 • - dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons 2 swons 3 swons 4 swons\n", + " 2 1 • sub dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons 2 swons 3 swons 4 swons\n", + " 1 • dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons 2 swons 3 swons 4 swons\n", + " 1 1 • [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons 2 swons 3 swons 4 swons\n", + " 1 1 [[0 <=] [pop []] [-- dup] [dip swons] genrec] • dip swons 2 swons 3 swons 4 swons\n", + " 1 • [0 <=] [pop []] [-- dup] [dip swons] genrec 1 swons 2 swons 3 swons 4 swons\n", + " 1 [0 <=] • [pop []] [-- dup] [dip swons] genrec 1 swons 2 swons 3 swons 4 swons\n", + " 1 [0 <=] [pop []] • [-- dup] [dip swons] genrec 1 swons 2 swons 3 swons 4 swons\n", + " 1 [0 <=] [pop []] [-- dup] • [dip swons] genrec 1 swons 2 swons 3 swons 4 swons\n", + " 1 [0 <=] [pop []] [-- dup] [dip swons] • genrec 1 swons 2 swons 3 swons 4 swons\n", + " 1 [0 <=] [pop []] [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] • ifte 1 swons 2 swons 3 swons 4 swons\n", + "1 [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] [pop []] [1] [0 <=] • infra first choice i 1 swons 2 swons 3 swons 4 swons\n", + " 1 • 0 <= [[pop []] [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] 1] swaack first choice i 1 swons 2 swons 3 swons 4 swons\n", + " 1 0 • <= [[pop []] [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] 1] swaack first choice i 1 swons 2 swons 3 swons 4 swons\n", + " 1 0 • le [[pop []] [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] 1] swaack first choice i 1 swons 2 swons 3 swons 4 swons\n", + " false • [[pop []] [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] 1] swaack first choice i 1 swons 2 swons 3 swons 4 swons\n", + " false [[pop []] [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] 1] • swaack first choice i 1 swons 2 swons 3 swons 4 swons\n", + " 1 [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] [pop []] [false] • first choice i 1 swons 2 swons 3 swons 4 swons\n", + " 1 [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] [pop []] false • choice i 1 swons 2 swons 3 swons 4 swons\n", + " 1 [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] • i 1 swons 2 swons 3 swons 4 swons\n", + " 1 • -- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons 1 swons 2 swons 3 swons 4 swons\n", + " 1 • 1 - dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons 1 swons 2 swons 3 swons 4 swons\n", + " 1 1 • - dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons 1 swons 2 swons 3 swons 4 swons\n", + " 1 1 • sub dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons 1 swons 2 swons 3 swons 4 swons\n", + " 0 • dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons 1 swons 2 swons 3 swons 4 swons\n", + " 0 0 • [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons 1 swons 2 swons 3 swons 4 swons\n", + " 0 0 [[0 <=] [pop []] [-- dup] [dip swons] genrec] • dip swons 1 swons 2 swons 3 swons 4 swons\n", + " 0 • [0 <=] [pop []] [-- dup] [dip swons] genrec 0 swons 1 swons 2 swons 3 swons 4 swons\n", + " 0 [0 <=] • [pop []] [-- dup] [dip swons] genrec 0 swons 1 swons 2 swons 3 swons 4 swons\n", + " 0 [0 <=] [pop []] • [-- dup] [dip swons] genrec 0 swons 1 swons 2 swons 3 swons 4 swons\n", + " 0 [0 <=] [pop []] [-- dup] • [dip swons] genrec 0 swons 1 swons 2 swons 3 swons 4 swons\n", + " 0 [0 <=] [pop []] [-- dup] [dip swons] • genrec 0 swons 1 swons 2 swons 3 swons 4 swons\n", + " 0 [0 <=] [pop []] [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] • ifte 0 swons 1 swons 2 swons 3 swons 4 swons\n", + "0 [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] [pop []] [0] [0 <=] • infra first choice i 0 swons 1 swons 2 swons 3 swons 4 swons\n", + " 0 • 0 <= [[pop []] [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] 0] swaack first choice i 0 swons 1 swons 2 swons 3 swons 4 swons\n", + " 0 0 • <= [[pop []] [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] 0] swaack first choice i 0 swons 1 swons 2 swons 3 swons 4 swons\n", + " 0 0 • le [[pop []] [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] 0] swaack first choice i 0 swons 1 swons 2 swons 3 swons 4 swons\n", + " true • [[pop []] [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] 0] swaack first choice i 0 swons 1 swons 2 swons 3 swons 4 swons\n", + " true [[pop []] [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] 0] • swaack first choice i 0 swons 1 swons 2 swons 3 swons 4 swons\n", + " 0 [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] [pop []] [true] • first choice i 0 swons 1 swons 2 swons 3 swons 4 swons\n", + " 0 [-- dup [[0 <=] [pop []] [-- dup] [dip swons] genrec] dip swons] [pop []] true • choice i 0 swons 1 swons 2 swons 3 swons 4 swons\n", + " 0 [pop []] • i 0 swons 1 swons 2 swons 3 swons 4 swons\n", + " 0 • pop [] 0 swons 1 swons 2 swons 3 swons 4 swons\n", + " • [] 0 swons 1 swons 2 swons 3 swons 4 swons\n", + " [] • 0 swons 1 swons 2 swons 3 swons 4 swons\n", + " [] 0 • swons 1 swons 2 swons 3 swons 4 swons\n", + " [0] • 1 swons 2 swons 3 swons 4 swons\n", + " [0] 1 • swons 2 swons 3 swons 4 swons\n", + " [1 0] • 2 swons 3 swons 4 swons\n", + " [1 0] 2 • swons 3 swons 4 swons\n", + " [2 1 0] • 3 swons 4 swons\n", + " [2 1 0] 3 • swons 4 swons\n", + " [3 2 1 0] • 4 swons\n", + " [3 2 1 0] 4 • swons\n", + " [4 3 2 1 0] • \n", + "\n", "[4 3 2 1 0]" ] }