Still working towards v0.1.1.

The next "patch" bump is almost all docs.
This commit is contained in:
Simon Forman
2018-04-27 12:08:46 -07:00
parent 7aa8580ee3
commit aabe19036f
23 changed files with 165 additions and 204 deletions
+20 -18
View File
@@ -3,32 +3,28 @@
`Quadratic formula <https://en.wikipedia.org/wiki/Quadratic_formula>`__
***********************************************************************
.. code:: ipython2
from notebook_preamble import J, V, define
Cf.
`jp-quadratic.html <http://www.kevinalbrecht.com/code/joy-mirror/jp-quadratic.html>`__
::
-b +/- sqrt(b^2 - 4 * a * c)
-----------------------------
2 * a
`The Quadratic formula <https://en.wikipedia.org/wiki/Quadratic_formula>`__
:math:`\frac{-b \pm \sqrt{b^2 - 4ac}}{2a}`
Write a straightforward program with variable names.
====================================================
In
`jp-quadratic.html <http://www.kevinalbrecht.com/code/joy-mirror/jp-quadratic.html>`__
a Joy function for the Quadratic formula is derived (along with one of my favorite combinators ``[i] map``,
which I like to call ``pam``) starting with a version written in Scheme. Here we investigate a different approach.
Write a 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 ("plus-or-minus") 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
-b b sqr 4 a c * * - sqrt [+] [-] cleave a 2 * [truediv] cons app2
@@ -42,13 +38,15 @@ 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 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.)
Cleanup
~~~~~~~
::
-b -b+sqrt(b^2-4ac)/2a -b-sqrt(b^2-4ac)/2a roll< pop
-b+sqrt(b^2-4ac)/2a -b-sqrt(b^2-4ac)/2a -b pop
-b -b+sqrt(b^2-4ac)/2a -b-sqrt(b^2-4ac)/2a roll< pop
-b+sqrt(b^2-4ac)/2a -b-sqrt(b^2-4ac)/2a -b pop
-b+sqrt(b^2-4ac)/2a -b-sqrt(b^2-4ac)/2a
Derive a definition.
@@ -62,6 +60,10 @@ Derive a definition.
b a c a [[[neg] dupdip sqr 4] dipd * * - sqrt [+] [-] cleave] dip 2 * [truediv] cons app2 roll< pop
b a c over [[[neg] dupdip sqr 4] dipd * * - sqrt [+] [-] cleave] dip 2 * [truediv] cons app2 roll< pop
.. code:: ipython2
from notebook_preamble import J, V, define
.. code:: ipython2
define('quadratic == over [[[neg] dupdip sqr 4] dipd * * - sqrt [+] [-] cleave] dip 2 * [truediv] cons app2 roll< pop')