Fixed bug in appN

while updating some Jupyter notebooks with the Joypy kernel.
This commit is contained in:
Simon Forman 2022-09-16 20:49:46 -07:00
parent 3d1dc6232e
commit b2a1f40155
7 changed files with 761 additions and 1707 deletions

File diff suppressed because it is too large Load Diff

View File

@ -11,29 +11,50 @@
" Find the sum of all the multiples of 3 or 5 below 1000."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's create a predicate that returns `True` if a number is a multiple of 3 or 5 and `False` otherwise.\n",
"\n",
"First we write `multiple-of` which take two numbers and return true if the first is a multiple of the second. We use the `mod` operator, convert the remainder to a Boolean value, then invert it to get our answer:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": []
}
],
"source": [
"from notebook_preamble import J, V, define"
"[multiple-of mod bool not] inscribe"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's create a predicate that returns `True` if a number is a multiple of 3 or 5 and `False` otherwise."
"Next we can use that with `app2` to get both Boolean values (for 3 and 5) and the `or` them. (We use `popd` to get rid of the original number):"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": []
}
],
"source": [
"define('P [3 % not] dupdip 5 % not or')"
"[P 3 5 [multiple-of] app2 or popd] inscribe"
]
},
{
@ -45,24 +66,27 @@
"name": "stdout",
"output_type": "stream",
"text": [
" • 80 P\n",
" 80 • P\n",
" 80 • [3 % not] dupdip 5 % not or\n",
"80 [3 % not] • dupdip 5 % not or\n",
" 80 • 3 % not 80 5 % not or\n",
" 80 3 • % not 80 5 % not or\n",
" 2 • not 80 5 % not or\n",
" False • 80 5 % not or\n",
" False 80 • 5 % not or\n",
" False 80 5 • % not or\n",
" False 0 • not or\n",
" False True • or\n",
" True • \n"
"[true false false true true]"
]
}
],
"source": [
"V('80 P')"
"[6 7 8 9 10] [P] map"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": []
}
],
"source": [
"clear"
]
},
{
@ -118,15 +142,6 @@
" PE1.1 == + [+] dupdip"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"define('PE1.1 + [+] dupdip')"
]
},
{
"cell_type": "code",
"execution_count": 5,
@ -135,27 +150,33 @@
{
"name": "stdout",
"output_type": "stream",
"text": [
" • 0 0 3 PE1.1\n",
" 0 • 0 3 PE1.1\n",
" 0 0 • 3 PE1.1\n",
" 0 0 3 • PE1.1\n",
" 0 0 3 • + [+] dupdip\n",
" 0 3 • [+] dupdip\n",
"0 3 [+] • dupdip\n",
" 0 3 • + 3\n",
" 3 • 3\n",
" 3 3 • \n"
]
"text": []
}
],
"source": [
"V('0 0 3 PE1.1')"
"[PE1.1 + [+] dupdip] inscribe"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3 3"
]
}
],
"source": [
"0 0 3 PE1.1"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"scrolled": false
},
@ -164,84 +185,14 @@
"name": "stdout",
"output_type": "stream",
"text": [
" • 0 0 [3 2 1 3 1 2 3] [PE1.1] step\n",
" 0 • 0 [3 2 1 3 1 2 3] [PE1.1] step\n",
" 0 0 • [3 2 1 3 1 2 3] [PE1.1] step\n",
" 0 0 [3 2 1 3 1 2 3] • [PE1.1] step\n",
"0 0 [3 2 1 3 1 2 3] [PE1.1] • step\n",
" 0 0 3 [PE1.1] • i [2 1 3 1 2 3] [PE1.1] step\n",
" 0 0 3 • PE1.1 [2 1 3 1 2 3] [PE1.1] step\n",
" 0 0 3 • + [+] dupdip [2 1 3 1 2 3] [PE1.1] step\n",
" 0 3 • [+] dupdip [2 1 3 1 2 3] [PE1.1] step\n",
" 0 3 [+] • dupdip [2 1 3 1 2 3] [PE1.1] step\n",
" 0 3 • + 3 [2 1 3 1 2 3] [PE1.1] step\n",
" 3 • 3 [2 1 3 1 2 3] [PE1.1] step\n",
" 3 3 • [2 1 3 1 2 3] [PE1.1] step\n",
" 3 3 [2 1 3 1 2 3] • [PE1.1] step\n",
" 3 3 [2 1 3 1 2 3] [PE1.1] • step\n",
" 3 3 2 [PE1.1] • i [1 3 1 2 3] [PE1.1] step\n",
" 3 3 2 • PE1.1 [1 3 1 2 3] [PE1.1] step\n",
" 3 3 2 • + [+] dupdip [1 3 1 2 3] [PE1.1] step\n",
" 3 5 • [+] dupdip [1 3 1 2 3] [PE1.1] step\n",
" 3 5 [+] • dupdip [1 3 1 2 3] [PE1.1] step\n",
" 3 5 • + 5 [1 3 1 2 3] [PE1.1] step\n",
" 8 • 5 [1 3 1 2 3] [PE1.1] step\n",
" 8 5 • [1 3 1 2 3] [PE1.1] step\n",
" 8 5 [1 3 1 2 3] • [PE1.1] step\n",
" 8 5 [1 3 1 2 3] [PE1.1] • step\n",
" 8 5 1 [PE1.1] • i [3 1 2 3] [PE1.1] step\n",
" 8 5 1 • PE1.1 [3 1 2 3] [PE1.1] step\n",
" 8 5 1 • + [+] dupdip [3 1 2 3] [PE1.1] step\n",
" 8 6 • [+] dupdip [3 1 2 3] [PE1.1] step\n",
" 8 6 [+] • dupdip [3 1 2 3] [PE1.1] step\n",
" 8 6 • + 6 [3 1 2 3] [PE1.1] step\n",
" 14 • 6 [3 1 2 3] [PE1.1] step\n",
" 14 6 • [3 1 2 3] [PE1.1] step\n",
" 14 6 [3 1 2 3] • [PE1.1] step\n",
" 14 6 [3 1 2 3] [PE1.1] • step\n",
" 14 6 3 [PE1.1] • i [1 2 3] [PE1.1] step\n",
" 14 6 3 • PE1.1 [1 2 3] [PE1.1] step\n",
" 14 6 3 • + [+] dupdip [1 2 3] [PE1.1] step\n",
" 14 9 • [+] dupdip [1 2 3] [PE1.1] step\n",
" 14 9 [+] • dupdip [1 2 3] [PE1.1] step\n",
" 14 9 • + 9 [1 2 3] [PE1.1] step\n",
" 23 • 9 [1 2 3] [PE1.1] step\n",
" 23 9 • [1 2 3] [PE1.1] step\n",
" 23 9 [1 2 3] • [PE1.1] step\n",
" 23 9 [1 2 3] [PE1.1] • step\n",
" 23 9 1 [PE1.1] • i [2 3] [PE1.1] step\n",
" 23 9 1 • PE1.1 [2 3] [PE1.1] step\n",
" 23 9 1 • + [+] dupdip [2 3] [PE1.1] step\n",
" 23 10 • [+] dupdip [2 3] [PE1.1] step\n",
" 23 10 [+] • dupdip [2 3] [PE1.1] step\n",
" 23 10 • + 10 [2 3] [PE1.1] step\n",
" 33 • 10 [2 3] [PE1.1] step\n",
" 33 10 • [2 3] [PE1.1] step\n",
" 33 10 [2 3] • [PE1.1] step\n",
" 33 10 [2 3] [PE1.1] • step\n",
" 33 10 2 [PE1.1] • i [3] [PE1.1] step\n",
" 33 10 2 • PE1.1 [3] [PE1.1] step\n",
" 33 10 2 • + [+] dupdip [3] [PE1.1] step\n",
" 33 12 • [+] dupdip [3] [PE1.1] step\n",
" 33 12 [+] • dupdip [3] [PE1.1] step\n",
" 33 12 • + 12 [3] [PE1.1] step\n",
" 45 • 12 [3] [PE1.1] step\n",
" 45 12 • [3] [PE1.1] step\n",
" 45 12 [3] • [PE1.1] step\n",
" 45 12 [3] [PE1.1] • step\n",
" 45 12 3 [PE1.1] • i\n",
" 45 12 3 • PE1.1\n",
" 45 12 3 • + [+] dupdip\n",
" 45 15 • [+] dupdip\n",
" 45 15 [+] • dupdip\n",
" 45 15 • + 15\n",
" 60 • 15\n",
" 60 15 • \n"
"60 15"
]
}
],
"source": [
"V('0 0 [3 2 1 3 1 2 3] [PE1.1] step')"
"clear\n",
"\n",
"0 0 [3 2 1 3 1 2 3] [PE1.1] step"
]
},
{
@ -251,44 +202,23 @@
"So one `step` through all seven terms brings the counter to 15 and the total to 60."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"66.66666666666667"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1000 / 15"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"990"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
"name": "stdout",
"output_type": "stream",
"text": [
"66"
]
}
],
"source": [
"66 * 15"
"clear\n",
"\n",
"1000 15 div"
]
},
{
@ -297,76 +227,43 @@
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
"name": "stdout",
"output_type": "stream",
"text": [
"990"
]
}
],
"source": [
"1000 - 990"
"15 *"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
"source": [
"That means we want to run the full list of numbers sixty-six times to get to 990 and then, obviously, the first four numbers 3 2 1 3 to get to 999."
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"9"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"999 - 990"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"That means we want to run the full list of numbers sixty-six times to get to 990 and then the first four numbers 3 2 1 3 to get to 999."
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"define('PE1 0 0 66 [[3 2 1 3 1 2 3] [PE1.1] step] times [3 2 1 3] [PE1.1] step pop')"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"233168\n"
"233168"
]
}
],
"source": [
"J('PE1')"
"clear\n",
"\n",
"[PE1 0 0 66 [[3 2 1 3 1 2 3] [PE1.1] step] times [3 2 1 3] [PE1.1] step pop] inscribe\n",
"\n",
"PE1"
]
},
{
@ -387,239 +284,59 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"14811"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
"name": "stdout",
"output_type": "stream",
"text": []
}
],
"source": [
"0b11100111011011"
"clear"
]
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": []
}
],
"source": [
"[PE1.2 [3 & PE1.1] dupdip 2 >>] inscribe"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"define('PE1.2 [3 & PE1.1] dupdip 2 >>')"
"0 0 14811 PE1.2"
]
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" • 0 0 14811 PE1.2\n",
" 0 • 0 14811 PE1.2\n",
" 0 0 • 14811 PE1.2\n",
" 0 0 14811 • PE1.2\n",
" 0 0 14811 • [3 & PE1.1] dupdip 2 >>\n",
"0 0 14811 [3 & PE1.1] • dupdip 2 >>\n",
" 0 0 14811 • 3 & PE1.1 14811 2 >>\n",
" 0 0 14811 3 • & PE1.1 14811 2 >>\n",
" 0 0 3 • PE1.1 14811 2 >>\n",
" 0 0 3 • + [+] dupdip 14811 2 >>\n",
" 0 3 • [+] dupdip 14811 2 >>\n",
" 0 3 [+] • dupdip 14811 2 >>\n",
" 0 3 • + 3 14811 2 >>\n",
" 3 • 3 14811 2 >>\n",
" 3 3 • 14811 2 >>\n",
" 3 3 14811 • 2 >>\n",
" 3 3 14811 2 • >>\n",
" 3 3 3702 • \n"
]
}
],
"source": [
"V('0 0 14811 PE1.2')"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" • 3 3 3702 PE1.2\n",
" 3 • 3 3702 PE1.2\n",
" 3 3 • 3702 PE1.2\n",
" 3 3 3702 • PE1.2\n",
" 3 3 3702 • [3 & PE1.1] dupdip 2 >>\n",
"3 3 3702 [3 & PE1.1] • dupdip 2 >>\n",
" 3 3 3702 • 3 & PE1.1 3702 2 >>\n",
" 3 3 3702 3 • & PE1.1 3702 2 >>\n",
" 3 3 2 • PE1.1 3702 2 >>\n",
" 3 3 2 • + [+] dupdip 3702 2 >>\n",
" 3 5 • [+] dupdip 3702 2 >>\n",
" 3 5 [+] • dupdip 3702 2 >>\n",
" 3 5 • + 5 3702 2 >>\n",
" 8 • 5 3702 2 >>\n",
" 8 5 • 3702 2 >>\n",
" 8 5 3702 • 2 >>\n",
" 8 5 3702 2 • >>\n",
" 8 5 925 • \n"
]
}
],
"outputs": [],
"source": [
"V('3 3 3702 PE1.2')"
]
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" • 0 0 14811 7 [PE1.2] times pop\n",
" 0 • 0 14811 7 [PE1.2] times pop\n",
" 0 0 • 14811 7 [PE1.2] times pop\n",
" 0 0 14811 • 7 [PE1.2] times pop\n",
" 0 0 14811 7 • [PE1.2] times pop\n",
" 0 0 14811 7 [PE1.2] • times pop\n",
" 0 0 14811 • PE1.2 6 [PE1.2] times pop\n",
" 0 0 14811 • [3 & PE1.1] dupdip 2 >> 6 [PE1.2] times pop\n",
"0 0 14811 [3 & PE1.1] • dupdip 2 >> 6 [PE1.2] times pop\n",
" 0 0 14811 • 3 & PE1.1 14811 2 >> 6 [PE1.2] times pop\n",
" 0 0 14811 3 • & PE1.1 14811 2 >> 6 [PE1.2] times pop\n",
" 0 0 3 • PE1.1 14811 2 >> 6 [PE1.2] times pop\n",
" 0 0 3 • + [+] dupdip 14811 2 >> 6 [PE1.2] times pop\n",
" 0 3 • [+] dupdip 14811 2 >> 6 [PE1.2] times pop\n",
" 0 3 [+] • dupdip 14811 2 >> 6 [PE1.2] times pop\n",
" 0 3 • + 3 14811 2 >> 6 [PE1.2] times pop\n",
" 3 • 3 14811 2 >> 6 [PE1.2] times pop\n",
" 3 3 • 14811 2 >> 6 [PE1.2] times pop\n",
" 3 3 14811 • 2 >> 6 [PE1.2] times pop\n",
" 3 3 14811 2 • >> 6 [PE1.2] times pop\n",
" 3 3 3702 • 6 [PE1.2] times pop\n",
" 3 3 3702 6 • [PE1.2] times pop\n",
" 3 3 3702 6 [PE1.2] • times pop\n",
" 3 3 3702 • PE1.2 5 [PE1.2] times pop\n",
" 3 3 3702 • [3 & PE1.1] dupdip 2 >> 5 [PE1.2] times pop\n",
" 3 3 3702 [3 & PE1.1] • dupdip 2 >> 5 [PE1.2] times pop\n",
" 3 3 3702 • 3 & PE1.1 3702 2 >> 5 [PE1.2] times pop\n",
" 3 3 3702 3 • & PE1.1 3702 2 >> 5 [PE1.2] times pop\n",
" 3 3 2 • PE1.1 3702 2 >> 5 [PE1.2] times pop\n",
" 3 3 2 • + [+] dupdip 3702 2 >> 5 [PE1.2] times pop\n",
" 3 5 • [+] dupdip 3702 2 >> 5 [PE1.2] times pop\n",
" 3 5 [+] • dupdip 3702 2 >> 5 [PE1.2] times pop\n",
" 3 5 • + 5 3702 2 >> 5 [PE1.2] times pop\n",
" 8 • 5 3702 2 >> 5 [PE1.2] times pop\n",
" 8 5 • 3702 2 >> 5 [PE1.2] times pop\n",
" 8 5 3702 • 2 >> 5 [PE1.2] times pop\n",
" 8 5 3702 2 • >> 5 [PE1.2] times pop\n",
" 8 5 925 • 5 [PE1.2] times pop\n",
" 8 5 925 5 • [PE1.2] times pop\n",
" 8 5 925 5 [PE1.2] • times pop\n",
" 8 5 925 • PE1.2 4 [PE1.2] times pop\n",
" 8 5 925 • [3 & PE1.1] dupdip 2 >> 4 [PE1.2] times pop\n",
" 8 5 925 [3 & PE1.1] • dupdip 2 >> 4 [PE1.2] times pop\n",
" 8 5 925 • 3 & PE1.1 925 2 >> 4 [PE1.2] times pop\n",
" 8 5 925 3 • & PE1.1 925 2 >> 4 [PE1.2] times pop\n",
" 8 5 1 • PE1.1 925 2 >> 4 [PE1.2] times pop\n",
" 8 5 1 • + [+] dupdip 925 2 >> 4 [PE1.2] times pop\n",
" 8 6 • [+] dupdip 925 2 >> 4 [PE1.2] times pop\n",
" 8 6 [+] • dupdip 925 2 >> 4 [PE1.2] times pop\n",
" 8 6 • + 6 925 2 >> 4 [PE1.2] times pop\n",
" 14 • 6 925 2 >> 4 [PE1.2] times pop\n",
" 14 6 • 925 2 >> 4 [PE1.2] times pop\n",
" 14 6 925 • 2 >> 4 [PE1.2] times pop\n",
" 14 6 925 2 • >> 4 [PE1.2] times pop\n",
" 14 6 231 • 4 [PE1.2] times pop\n",
" 14 6 231 4 • [PE1.2] times pop\n",
" 14 6 231 4 [PE1.2] • times pop\n",
" 14 6 231 • PE1.2 3 [PE1.2] times pop\n",
" 14 6 231 • [3 & PE1.1] dupdip 2 >> 3 [PE1.2] times pop\n",
" 14 6 231 [3 & PE1.1] • dupdip 2 >> 3 [PE1.2] times pop\n",
" 14 6 231 • 3 & PE1.1 231 2 >> 3 [PE1.2] times pop\n",
" 14 6 231 3 • & PE1.1 231 2 >> 3 [PE1.2] times pop\n",
" 14 6 3 • PE1.1 231 2 >> 3 [PE1.2] times pop\n",
" 14 6 3 • + [+] dupdip 231 2 >> 3 [PE1.2] times pop\n",
" 14 9 • [+] dupdip 231 2 >> 3 [PE1.2] times pop\n",
" 14 9 [+] • dupdip 231 2 >> 3 [PE1.2] times pop\n",
" 14 9 • + 9 231 2 >> 3 [PE1.2] times pop\n",
" 23 • 9 231 2 >> 3 [PE1.2] times pop\n",
" 23 9 • 231 2 >> 3 [PE1.2] times pop\n",
" 23 9 231 • 2 >> 3 [PE1.2] times pop\n",
" 23 9 231 2 • >> 3 [PE1.2] times pop\n",
" 23 9 57 • 3 [PE1.2] times pop\n",
" 23 9 57 3 • [PE1.2] times pop\n",
" 23 9 57 3 [PE1.2] • times pop\n",
" 23 9 57 • PE1.2 2 [PE1.2] times pop\n",
" 23 9 57 • [3 & PE1.1] dupdip 2 >> 2 [PE1.2] times pop\n",
" 23 9 57 [3 & PE1.1] • dupdip 2 >> 2 [PE1.2] times pop\n",
" 23 9 57 • 3 & PE1.1 57 2 >> 2 [PE1.2] times pop\n",
" 23 9 57 3 • & PE1.1 57 2 >> 2 [PE1.2] times pop\n",
" 23 9 1 • PE1.1 57 2 >> 2 [PE1.2] times pop\n",
" 23 9 1 • + [+] dupdip 57 2 >> 2 [PE1.2] times pop\n",
" 23 10 • [+] dupdip 57 2 >> 2 [PE1.2] times pop\n",
" 23 10 [+] • dupdip 57 2 >> 2 [PE1.2] times pop\n",
" 23 10 • + 10 57 2 >> 2 [PE1.2] times pop\n",
" 33 • 10 57 2 >> 2 [PE1.2] times pop\n",
" 33 10 • 57 2 >> 2 [PE1.2] times pop\n",
" 33 10 57 • 2 >> 2 [PE1.2] times pop\n",
" 33 10 57 2 • >> 2 [PE1.2] times pop\n",
" 33 10 14 • 2 [PE1.2] times pop\n",
" 33 10 14 2 • [PE1.2] times pop\n",
" 33 10 14 2 [PE1.2] • times pop\n",
" 33 10 14 • PE1.2 1 [PE1.2] times pop\n",
" 33 10 14 • [3 & PE1.1] dupdip 2 >> 1 [PE1.2] times pop\n",
" 33 10 14 [3 & PE1.1] • dupdip 2 >> 1 [PE1.2] times pop\n",
" 33 10 14 • 3 & PE1.1 14 2 >> 1 [PE1.2] times pop\n",
" 33 10 14 3 • & PE1.1 14 2 >> 1 [PE1.2] times pop\n",
" 33 10 2 • PE1.1 14 2 >> 1 [PE1.2] times pop\n",
" 33 10 2 • + [+] dupdip 14 2 >> 1 [PE1.2] times pop\n",
" 33 12 • [+] dupdip 14 2 >> 1 [PE1.2] times pop\n",
" 33 12 [+] • dupdip 14 2 >> 1 [PE1.2] times pop\n",
" 33 12 • + 12 14 2 >> 1 [PE1.2] times pop\n",
" 45 • 12 14 2 >> 1 [PE1.2] times pop\n",
" 45 12 • 14 2 >> 1 [PE1.2] times pop\n",
" 45 12 14 • 2 >> 1 [PE1.2] times pop\n",
" 45 12 14 2 • >> 1 [PE1.2] times pop\n",
" 45 12 3 • 1 [PE1.2] times pop\n",
" 45 12 3 1 • [PE1.2] times pop\n",
" 45 12 3 1 [PE1.2] • times pop\n",
" 45 12 3 • PE1.2 pop\n",
" 45 12 3 • [3 & PE1.1] dupdip 2 >> pop\n",
" 45 12 3 [3 & PE1.1] • dupdip 2 >> pop\n",
" 45 12 3 • 3 & PE1.1 3 2 >> pop\n",
" 45 12 3 3 • & PE1.1 3 2 >> pop\n",
" 45 12 3 • PE1.1 3 2 >> pop\n",
" 45 12 3 • + [+] dupdip 3 2 >> pop\n",
" 45 15 • [+] dupdip 3 2 >> pop\n",
" 45 15 [+] • dupdip 3 2 >> pop\n",
" 45 15 • + 15 3 2 >> pop\n",
" 60 • 15 3 2 >> pop\n",
" 60 15 • 3 2 >> pop\n",
" 60 15 3 • 2 >> pop\n",
" 60 15 3 2 • >> pop\n",
" 60 15 0 • pop\n",
" 60 15 • \n"
]
}
],
"outputs": [],
"source": [
"V('0 0 14811 7 [PE1.2] times pop')"
]
@ -633,7 +350,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@ -642,19 +359,11 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"233168\n"
]
}
],
"outputs": [],
"source": [
"J('PE1')"
]
@ -673,7 +382,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@ -689,7 +398,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@ -698,19 +407,11 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"233168\n"
]
}
],
"outputs": [],
"source": [
"J('PE1')"
]
@ -737,7 +438,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@ -746,19 +447,11 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 [0 swap [dup [pop 14811] [] branch [3 &] dupdip 2 >>] dip rest cons]\n"
]
}
],
"outputs": [],
"source": [
"J('PE1.terms 21 [x] times')"
]
@ -772,17 +465,9 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"466\n"
]
}
],
"outputs": [],
"source": [
"J('7 66 * 4 +')"
]
@ -796,19 +481,11 @@
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3\n"
]
}
],
"outputs": [],
"source": [
"J('PE1.terms 466 [x] times pop')"
]
@ -822,19 +499,11 @@
},
{
"cell_type": "code",
"execution_count": 27,
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"999\n"
]
}
],
"outputs": [],
"source": [
"J('[PE1.terms 466 [x] times pop] run sum')"
]
@ -848,19 +517,11 @@
},
{
"cell_type": "code",
"execution_count": 28,
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"233168\n"
]
}
],
"outputs": [],
"source": [
"J('0 0 PE1.terms 466 [x [PE1.1] dip] times popop')"
]
@ -875,17 +536,9 @@
},
{
"cell_type": "code",
"execution_count": 29,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"55\n"
]
}
],
"outputs": [],
"source": [
"J('[10 9 8 7 6 5 4 3 2 1] sum')"
]
@ -912,7 +565,7 @@
},
{
"cell_type": "code",
"execution_count": 30,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@ -921,24 +574,9 @@
},
{
"cell_type": "code",
"execution_count": 31,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" • 10 F\n",
" 10 • F\n",
" 10 • dup ++ * 2 floordiv\n",
"10 10 • ++ * 2 floordiv\n",
"10 11 • * 2 floordiv\n",
" 110 • 2 floordiv\n",
"110 2 • floordiv\n",
" 55 • \n"
]
}
],
"outputs": [],
"source": [
"V('10 F')"
]
@ -963,38 +601,22 @@
},
{
"cell_type": "code",
"execution_count": 32,
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[978 15] [980 12] [981 10] [984 9] [985 6] [987 5] [990 3]]\n"
]
}
],
"outputs": [],
"source": [
"J('[3 5 6 9 10 12 15] reverse [978 980 981 984 985 987 990] zip')"
]
},
{
"cell_type": "code",
"execution_count": 33,
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[993 992 991 993 991 992 993]\n"
]
}
],
"outputs": [],
"source": [
"J('[3 5 6 9 10 12 15] reverse [978 980 981 984 985 987 990] zip [sum] map')"
]
@ -1008,19 +630,11 @@
},
{
"cell_type": "code",
"execution_count": 34,
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"6945\n"
]
}
],
"outputs": [],
"source": [
"J('[ 3 5 6 9 10 12 15] reverse [978 980 981 984 985 987 990] zip [sum] map sum')"
]
@ -1038,17 +652,9 @@
},
{
"cell_type": "code",
"execution_count": 35,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"233168\n"
]
}
],
"outputs": [],
"source": [
"J('6945 33 * [993 995 996 999] cons sum')"
]
@ -1090,21 +696,14 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
"display_name": "Joypy",
"language": "",
"name": "thun"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.10"
"file_extension": ".joy",
"mimetype": "text/plain",
"name": "Joy"
}
},
"nbformat": 4,

View File

@ -1,14 +1,5 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from notebook_preamble import J, V, define"
]
},
{
"cell_type": "markdown",
"metadata": {},
@ -110,11 +101,17 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": []
}
],
"source": [
"define('quadratic == over [[[neg] dupdip sqr 4] dipd * * - sqrt pm] dip 2 * [/] cons app2')"
"[quadratic over [[[neg] dupdip sqr 4] dipd * * - sqrt pm] dip 2 * [/] cons app2] inscribe"
]
},
{
@ -126,19 +123,11 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-0.3819660112501051 -2.618033988749895\n"
]
}
],
"outputs": [],
"source": [
"J('3 1 1 quadratic')"
"3 1 1 quadratic"
]
},
{
@ -219,21 +208,14 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
"display_name": "Joypy",
"language": "",
"name": "thun"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.10"
"file_extension": ".joy",
"mimetype": "text/plain",
"name": "Joy"
}
},
"nbformat": 4,

View File

@ -75,24 +75,9 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" [1 [2 [3 4 25 6] 7] 8] • z-down\n",
" [1 [2 [3 4 25 6] 7] 8] • [] swap uncons swap\n",
"[1 [2 [3 4 25 6] 7] 8] [] • swap uncons swap\n",
"[] [1 [2 [3 4 25 6] 7] 8] • uncons swap\n",
"[] 1 [[2 [3 4 25 6] 7] 8] • swap\n",
"[] [[2 [3 4 25 6] 7] 8] 1 • \n",
"\n",
"[] [[2 [3 4 25 6] 7] 8] 1"
]
}
],
"outputs": [],
"source": [
"[z-down] trace"
]

View File

@ -1,12 +1,16 @@
import sys
from ipykernel.kernelbase import Kernel
from joy.library import default_defs, initialize, inscribe
from joy.joy import run
from joy.utils.stack import stack_to_string
from joy.utils.pretty_print import trace
from simplejoy import (
default_defs,
initialize,
inscribe,
run,
stack_to_string,
)
#from joy.utils.pretty_print import trace
inscribe(trace)
#inscribe(trace)
class FileFaker:
@ -35,13 +39,13 @@ class JoyKernel(Kernel):
implementation = 'Joypy'
implementation_version = '1.0'
language = 'Joy'
language_version = '0.1'
language_version = '0.5'
language_info = {
'name': 'Joy',
'mimetype': 'text/plain',
'file_extension': '.joy',
}
banner = "Echo kernel - as useful as a parrot"
banner = "Joy kernel"
def __init__(self, *a, **b):
self.D = initialize()

View File

@ -115,7 +115,7 @@ anamorphism ≡ [pop []] swap [dip swons] genrec
app1 grba infrst
app2 [grba swap grba swap] dip [infrst] cons ii
app3 3 appN
appN [grabN] codi map disenstacken
appN [grabN] codi map reverse disenstacken
at drop first
@ -307,9 +307,9 @@ def joy(stack, expression, dictionary):
'''
expr = push_quote(expression) # We keep a stack-of-stacks, see below.
while expr:
print(
f'{stack_to_string(stack)}{expr_to_string(expr)}'
)
## print(
## f'{stack_to_string(stack)} • {expr_to_string(expr)}'
## )
term, expr = next_term(expr)
if isinstance(term, Symbol):
try:
@ -2226,12 +2226,16 @@ def times(stack, expr, dictionary):
return stack, expr, dictionary
def default_defs(dictionary):
Def.load_definitions(__doc__.splitlines(), dictionary)
if __name__ == '__main__':
import sys
J = interp if '-q' in sys.argv else repl
dictionary = initialize()
Def.load_definitions(__doc__.splitlines(), dictionary)
default_defs(dictionary)
try:
stack = J(dictionary=dictionary)
except SystemExit:

View File

@ -11,7 +11,7 @@ anamorphism [pop []] swap [dip swons] genrec
app1 grba infrst
app2 [grba swap grba swap] dip [infrst] cons ii
app3 3 appN
appN [grabN] codi map disenstacken
appN [grabN] codi map reverse disenstacken
at drop first
average [sum] [size] cleave /
b [i] dip i