Still working towards v0.1.1.
The next "patch" bump is almost all docs.
This commit is contained in:
@@ -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')
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
Essays about Programming in Joy
|
||||
===============================
|
||||
|
||||
These essays are adapted from Jupyter notebooks. I hope to have those hosted somewhere where people can view them "live" and interact with them, possibly on MS Azure. For now, Sphinx does such a great job rendering the HTML that I am copying over some notebooks in ReST format and hand-editing them into these documents.
|
||||
|
||||
.. toctree::
|
||||
:glob:
|
||||
:maxdepth: 2
|
||||
@@ -10,4 +12,6 @@ Essays about Programming in Joy
|
||||
Trees
|
||||
Newton-Raphson
|
||||
Quadratic
|
||||
NoUpdates
|
||||
Categorical
|
||||
|
||||
|
||||
Reference in New Issue
Block a user