Cleaning up docs.

This commit is contained in:
Simon Forman
2018-06-07 12:37:32 -07:00
parent 956d849c8a
commit 507d045a3d
19 changed files with 921 additions and 658 deletions
+18 -15
View File
@@ -18,15 +18,21 @@ Cf.
:math:`\frac{-b \pm \sqrt{b^2 - 4ac}}{2a}`
Write a straightforward program with variable names.
====================================================
----------------------------------------------------
::
b neg b sqr 4 a c * * - sqrt [+] [-] cleave a 2 * [truediv] cons app2
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``.
Check it.
~~~~~~~~~
Evaluating by hand:
::
b neg b sqr 4 a c * * - sqrt [+] [-] cleave a 2 * [truediv] cons app2
@@ -41,7 +47,11 @@ Check it.
-b -b+sqrt(b^2-4ac) -b-sqrt(b^2-4ac) [2a truediv] app2
-b -b+sqrt(b^2-4ac)/2a -b-sqrt(b^2-4ac)/2a
Codicil
(Eventually well 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.)
Cleanup
~~~~~~~
::
@@ -51,7 +61,7 @@ Codicil
-b+sqrt(b^2-4ac)/2a -b-sqrt(b^2-4ac)/2a
Derive a definition.
====================
--------------------
::
@@ -76,13 +86,13 @@ Derive a definition.
Simplify
~~~~~~~~
--------
We can define a ``pm`` plus-or-minus function:
.. code:: ipython2
::
define('pm == [+] [-] cleave popdd')
pm == [+] [-] cleave popdd
Then ``quadratic`` becomes:
@@ -106,22 +116,15 @@ Define a "native" ``pm`` function.
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.
primitive in Python and add it to the dictionary. (This has been done
already.)
.. code:: ipython2
from joy.library import SimpleFunctionWrapper
from notebook_preamble import D
@SimpleFunctionWrapper
def pm(stack):
a, (b, stack) = stack
p, m, = b + a, b - a
return m, (p, stack)
D['pm'] = pm
The resulting trace is short enough to fit on a page.