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." " 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", "cell_type": "code",
"execution_count": 1, "execution_count": 1,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": []
}
],
"source": [ "source": [
"from notebook_preamble import J, V, define" "[multiple-of mod bool not] inscribe"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "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", "cell_type": "code",
"execution_count": 2, "execution_count": 2,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": []
}
],
"source": [ "source": [
"define('P [3 % not] dupdip 5 % not or')" "[P 3 5 [multiple-of] app2 or popd] inscribe"
] ]
}, },
{ {
@ -45,24 +66,27 @@
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
" • 80 P\n", "[true false false true true]"
" 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"
] ]
} }
], ],
"source": [ "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" " PE1.1 == + [+] dupdip"
] ]
}, },
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"define('PE1.1 + [+] dupdip')"
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": 5,
@ -135,27 +150,33 @@
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "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"
]
} }
], ],
"source": [ "source": [
"V('0 0 3 PE1.1')" "[PE1.1 + [+] dupdip] inscribe"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6, "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": { "metadata": {
"scrolled": false "scrolled": false
}, },
@ -164,84 +185,14 @@
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
" • 0 0 [3 2 1 3 1 2 3] [PE1.1] step\n", "60 15"
" 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"
] ]
} }
], ],
"source": [ "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." "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", "cell_type": "code",
"execution_count": 8, "execution_count": 8,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "name": "stdout",
"text/plain": [ "output_type": "stream",
"990" "text": [
] "66"
}, ]
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
} }
], ],
"source": [ "source": [
"66 * 15" "clear\n",
"\n",
"1000 15 div"
] ]
}, },
{ {
@ -297,76 +227,43 @@
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "name": "stdout",
"text/plain": [ "output_type": "stream",
"10" "text": [
] "990"
}, ]
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
} }
], ],
"source": [ "source": [
"1000 - 990" "15 *"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "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", "cell_type": "code",
"execution_count": 10, "execution_count": 10,
"metadata": {}, "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": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"233168\n" "233168"
] ]
} }
], ],
"source": [ "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", "cell_type": "code",
"execution_count": 13, "execution_count": 11,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "name": "stdout",
"text/plain": [ "output_type": "stream",
"14811" "text": []
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
} }
], ],
"source": [ "source": [
"0b11100111011011" "clear"
] ]
}, },
{ {
"cell_type": "code", "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": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"define('PE1.2 [3 & PE1.1] dupdip 2 >>')" "0 0 14811 PE1.2"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 15, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "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"
]
}
],
"source": [ "source": [
"V('3 3 3702 PE1.2')" "V('3 3 3702 PE1.2')"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 17, "execution_count": null,
"metadata": { "metadata": {
"scrolled": true "scrolled": true
}, },
"outputs": [ "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"
]
}
],
"source": [ "source": [
"V('0 0 14811 7 [PE1.2] times pop')" "V('0 0 14811 7 [PE1.2] times pop')"
] ]
@ -633,7 +350,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 18, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -642,19 +359,11 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 19, "execution_count": null,
"metadata": { "metadata": {
"scrolled": true "scrolled": true
}, },
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"233168\n"
]
}
],
"source": [ "source": [
"J('PE1')" "J('PE1')"
] ]
@ -673,7 +382,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 20, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -689,7 +398,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 21, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -698,19 +407,11 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 22, "execution_count": null,
"metadata": { "metadata": {
"scrolled": true "scrolled": true
}, },
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"233168\n"
]
}
],
"source": [ "source": [
"J('PE1')" "J('PE1')"
] ]
@ -737,7 +438,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 23, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -746,19 +447,11 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 24, "execution_count": null,
"metadata": { "metadata": {
"scrolled": true "scrolled": true
}, },
"outputs": [ "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"
]
}
],
"source": [ "source": [
"J('PE1.terms 21 [x] times')" "J('PE1.terms 21 [x] times')"
] ]
@ -772,17 +465,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 25, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"466\n"
]
}
],
"source": [ "source": [
"J('7 66 * 4 +')" "J('7 66 * 4 +')"
] ]
@ -796,19 +481,11 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 26, "execution_count": null,
"metadata": { "metadata": {
"scrolled": true "scrolled": true
}, },
"outputs": [ "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"
]
}
],
"source": [ "source": [
"J('PE1.terms 466 [x] times pop')" "J('PE1.terms 466 [x] times pop')"
] ]
@ -822,19 +499,11 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 27, "execution_count": null,
"metadata": { "metadata": {
"scrolled": true "scrolled": true
}, },
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"999\n"
]
}
],
"source": [ "source": [
"J('[PE1.terms 466 [x] times pop] run sum')" "J('[PE1.terms 466 [x] times pop] run sum')"
] ]
@ -848,19 +517,11 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 28, "execution_count": null,
"metadata": { "metadata": {
"scrolled": true "scrolled": true
}, },
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"233168\n"
]
}
],
"source": [ "source": [
"J('0 0 PE1.terms 466 [x [PE1.1] dip] times popop')" "J('0 0 PE1.terms 466 [x [PE1.1] dip] times popop')"
] ]
@ -875,17 +536,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 29, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"55\n"
]
}
],
"source": [ "source": [
"J('[10 9 8 7 6 5 4 3 2 1] sum')" "J('[10 9 8 7 6 5 4 3 2 1] sum')"
] ]
@ -912,7 +565,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 30, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -921,24 +574,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 31, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "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"
]
}
],
"source": [ "source": [
"V('10 F')" "V('10 F')"
] ]
@ -963,38 +601,22 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 32, "execution_count": null,
"metadata": { "metadata": {
"scrolled": true "scrolled": true
}, },
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[978 15] [980 12] [981 10] [984 9] [985 6] [987 5] [990 3]]\n"
]
}
],
"source": [ "source": [
"J('[3 5 6 9 10 12 15] reverse [978 980 981 984 985 987 990] zip')" "J('[3 5 6 9 10 12 15] reverse [978 980 981 984 985 987 990] zip')"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 33, "execution_count": null,
"metadata": { "metadata": {
"scrolled": true "scrolled": true
}, },
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"[993 992 991 993 991 992 993]\n"
]
}
],
"source": [ "source": [
"J('[3 5 6 9 10 12 15] reverse [978 980 981 984 985 987 990] zip [sum] map')" "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", "cell_type": "code",
"execution_count": 34, "execution_count": null,
"metadata": { "metadata": {
"scrolled": true "scrolled": true
}, },
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"6945\n"
]
}
],
"source": [ "source": [
"J('[ 3 5 6 9 10 12 15] reverse [978 980 981 984 985 987 990] zip [sum] map sum')" "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", "cell_type": "code",
"execution_count": 35, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"233168\n"
]
}
],
"source": [ "source": [
"J('6945 33 * [993 995 996 999] cons sum')" "J('6945 33 * [993 995 996 999] cons sum')"
] ]
@ -1090,21 +696,14 @@
], ],
"metadata": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "Python 3 (ipykernel)", "display_name": "Joypy",
"language": "python", "language": "",
"name": "python3" "name": "thun"
}, },
"language_info": { "language_info": {
"codemirror_mode": { "file_extension": ".joy",
"name": "ipython", "mimetype": "text/plain",
"version": 3 "name": "Joy"
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.10"
} }
}, },
"nbformat": 4, "nbformat": 4,

View File

@ -1,14 +1,5 @@
{ {
"cells": [ "cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from notebook_preamble import J, V, define"
]
},
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
@ -110,11 +101,17 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 1,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": []
}
],
"source": [ "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", "cell_type": "code",
"execution_count": 3, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"-0.3819660112501051 -2.618033988749895\n"
]
}
],
"source": [ "source": [
"J('3 1 1 quadratic')" "3 1 1 quadratic"
] ]
}, },
{ {
@ -219,21 +208,14 @@
], ],
"metadata": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "Python 3 (ipykernel)", "display_name": "Joypy",
"language": "python", "language": "",
"name": "python3" "name": "thun"
}, },
"language_info": { "language_info": {
"codemirror_mode": { "file_extension": ".joy",
"name": "ipython", "mimetype": "text/plain",
"version": 3 "name": "Joy"
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.10"
} }
}, },
"nbformat": 4, "nbformat": 4,

View File

@ -75,24 +75,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "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"
]
}
],
"source": [ "source": [
"[z-down] trace" "[z-down] trace"
] ]

View File

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

View File

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

View File

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