Start to convert Newton-Raphson notebook to Joy kernel.
This commit is contained in:
parent
865f06d93d
commit
688f880b9f
|
|
@ -10,15 +10,6 @@
|
||||||
"Cf. [\"Why Functional Programming Matters\" by John Hughes](https://www.cs.kent.ac.uk/people/staff/dat/miranda/whyfp90.pdf)"
|
"Cf. [\"Why Functional Programming Matters\" by John Hughes](https://www.cs.kent.ac.uk/people/staff/dat/miranda/whyfp90.pdf)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": 1,
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [],
|
|
||||||
"source": [
|
|
||||||
"from notebook_preamble import J, V, define"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
|
|
@ -47,15 +38,78 @@
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
" a n over / + 2 /\n",
|
"Starting with $\\frac{(a_i+\\frac{n}{a_i})}{2}$ we can derive the Joy expression to compute it using abstract dummy variables to stand in for actual values. First undivide by two:\n",
|
||||||
" a n a / + 2 /\n",
|
|
||||||
" a n/a + 2 /\n",
|
|
||||||
" a+n/a 2 /\n",
|
|
||||||
" (a+n/a)/2\n",
|
|
||||||
"\n",
|
"\n",
|
||||||
|
"$(a_i+\\frac{n}{a_i})$ `2 /`"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"Then unadd terms:\n",
|
||||||
|
"\n",
|
||||||
|
"$a_i$ $\\frac{n}{a_i}$ `+ 2 /`"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"Undivide again:\n",
|
||||||
|
"\n",
|
||||||
|
"$a_i$ $n$ $a_i$ `/ + 2 /`"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"Finally deduplicate the $a_i$ term:\n",
|
||||||
|
"\n",
|
||||||
|
"$a_i$ $n$ `over / + 2 /`"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"Let's try out this function `over / + 2 /` on an example:"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 14,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
" 5 36 • over / + 2 /\n",
|
||||||
|
"5 36 5 • / + 2 /\n",
|
||||||
|
" 5 7 • + 2 /\n",
|
||||||
|
" 12 • 2 /\n",
|
||||||
|
" 12 2 • /\n",
|
||||||
|
" 6 • \n",
|
||||||
|
"\n",
|
||||||
|
"6"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"clear\n",
|
||||||
|
"\n",
|
||||||
|
"5 36 [over / + 2 /] trace"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
"The function we want has the argument `n` in it:\n",
|
"The function we want has the argument `n` in it:\n",
|
||||||
"\n",
|
"\n",
|
||||||
" F == n over / + 2 /"
|
" n over / + 2 /"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue