The Hylos notebook is not ready for public yet.

This commit is contained in:
Simon Forman
2018-06-08 13:05:59 -07:00
parent f5fe7d9726
commit b98e9f2107
18 changed files with 463 additions and 2825 deletions
+65 -21
View File
@@ -87,17 +87,6 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"define('codireco == cons dip rest cons')\n",
"define('make_generator == [codireco] ccons')\n",
"define('ccons == cons cons')"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"scrolled": true
},
@@ -108,7 +97,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"metadata": {},
"outputs": [
{
@@ -132,7 +121,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 4,
"metadata": {},
"outputs": [
{
@@ -153,11 +142,11 @@
"source": [
"## Finding Consecutive Approximations within a Tolerance\n",
"\n",
"From [\"Why Functional Programming Matters\" by John Hughes](https://www.cs.kent.ac.uk/people/staff/dat/miranda/whyfp90.pdf):\n",
"\n",
"\n",
"> The remainder of a square root finder is a function _within_, which takes a tolerance and a list of approximations and looks down the list for two successive approximations that differ by no more than the given tolerance.\n",
"\n",
"From [\"Why Functional Programming Matters\" by John Hughes](https://www.cs.kent.ac.uk/people/staff/dat/miranda/whyfp90.pdf)\n",
"\n",
"(And note that by “list” he means a lazily-evaluated list.)\n",
"\n",
"Using the _output_ `[a G]` of the above generator for square root approximations, and further assuming that the first term a has been generated already and epsilon ε is handy on the stack...\n",
@@ -189,7 +178,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
@@ -210,7 +199,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
@@ -226,8 +215,8 @@
" a [b G] ε R0 [within] R1\n",
"\n",
"1. Discard a.\n",
"2. Use x combinator to generate next term from G.\n",
"3. Run within with `i` (it is a `primrec` function.)\n",
"2. Use `x` combinator to generate next term from `G`.\n",
"3. Run `within` with `i` (it is a `primrec` function.)\n",
"\n",
"Pretty straightforward:\n",
"\n",
@@ -243,7 +232,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
@@ -264,7 +253,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
@@ -272,6 +261,32 @@
"define('sqrt == gsra within')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Try it out..."
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"6.0\n"
]
}
],
"source": [
"J('36 sqrt')"
]
},
{
"cell_type": "code",
"execution_count": 10,
@@ -291,6 +306,13 @@
"J('23 sqrt')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Check it."
]
},
{
"cell_type": "code",
"execution_count": 11,
@@ -312,6 +334,28 @@
"source": [
"4.795831523312719**2"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"4.795831523312719"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from math import sqrt\n",
"\n",
"sqrt(23)"
]
}
],
"metadata": {