Cleaning up docs.
This commit is contained in:
+29
-22
@@ -43,10 +43,19 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Write a straightforward program with variable names.\n",
|
||||
"## Write a straightforward program with variable names.\n",
|
||||
"\n",
|
||||
" b neg b sqr 4 a c * * - sqrt [+] [-] cleave a 2 * [truediv] cons app2\n",
|
||||
"\n",
|
||||
"We use `cleave` to compute the sum and difference and then `app2` to finish computing both roots using a quoted program `[2a truediv]` built with `cons`."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Check it.\n",
|
||||
"Evaluating by hand:\n",
|
||||
"\n",
|
||||
" b neg b sqr 4 a c * * - sqrt [+] [-] cleave a 2 * [truediv] cons app2\n",
|
||||
" -b b sqr 4 a c * * - sqrt [+] [-] cleave a 2 * [truediv] cons app2\n",
|
||||
@@ -59,7 +68,15 @@
|
||||
" -b -b+sqrt(b^2-4ac) -b-sqrt(b^2-4ac) 2a [truediv] cons app2\n",
|
||||
" -b -b+sqrt(b^2-4ac) -b-sqrt(b^2-4ac) [2a truediv] app2\n",
|
||||
" -b -b+sqrt(b^2-4ac)/2a -b-sqrt(b^2-4ac)/2a\n",
|
||||
"### Codicil\n",
|
||||
"\n",
|
||||
"(Eventually we’ll be able to use e.g. Sympy versions of the Joy commands to do this sort of thing symbolically. This is part of what is meant by a “categorical” language.)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Cleanup\n",
|
||||
" -b -b+sqrt(b^2-4ac)/2a -b-sqrt(b^2-4ac)/2a roll< pop\n",
|
||||
" -b+sqrt(b^2-4ac)/2a -b-sqrt(b^2-4ac)/2a -b pop\n",
|
||||
" -b+sqrt(b^2-4ac)/2a -b-sqrt(b^2-4ac)/2a"
|
||||
@@ -69,7 +86,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Derive a definition.\n",
|
||||
"## Derive a definition.\n",
|
||||
"\n",
|
||||
" b neg b sqr 4 a c * * - sqrt [+] [-] cleave a 2 * [truediv] cons app2 roll< pop\n",
|
||||
" b [neg] dupdip sqr 4 a c * * - sqrt [+] [-] cleave a 2 * [truediv] cons app2 roll< pop\n",
|
||||
@@ -108,17 +125,15 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Simplify\n",
|
||||
"## Simplify\n",
|
||||
"We can define a `pm` plus-or-minus function:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"define('pm == [+] [-] cleave popdd')"
|
||||
" pm == [+] [-] cleave popdd"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -130,7 +145,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -139,7 +154,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -159,27 +174,19 @@
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Define a \"native\" `pm` function.\n",
|
||||
"The definition of `pm` above is pretty elegant, but the implementation takes a lot of steps relative to what it's accomplishing. Since we are likely to use `pm` more than once in the future, let's write a primitive in Python and add it to the dictionary."
|
||||
"The definition of `pm` above is pretty elegant, but the implementation takes a lot of steps relative to what it's accomplishing. Since we are likely to use `pm` more than once in the future, let's write a primitive in Python and add it to the dictionary. (This has been done already.)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from joy.library import SimpleFunctionWrapper\n",
|
||||
"from notebook_preamble import D\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"@SimpleFunctionWrapper\n",
|
||||
"def pm(stack):\n",
|
||||
" a, (b, stack) = stack\n",
|
||||
" p, m, = b + a, b - a\n",
|
||||
" return m, (p, stack)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"D['pm'] = pm"
|
||||
" return m, (p, stack)"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -191,7 +198,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user