Notebooks in Sphinx?

Converting the notebooks to ReST with nbconvert, then using sphinx on the
.rst files gives a pretty decent effect, except that the title levels are
off a little.

I need to look into hosting for the notebooks, maybe on MS Azure.  In the
meantime, I prefer the HTML made by Sphinx to the HTML made by nbconvert
directly.  It has index and cross refs and the code blocks scroll
horizontally which is crucial for wide Joy traces.  And Garamond.  God
bless Garamond.

For the Sphinx docs I'm going to edit the notebook ReST files by hand,
diverging from the originals.
This commit is contained in:
Simon Forman
2018-04-26 07:00:36 -07:00
parent aac5a42cab
commit 327548d715
38 changed files with 11708 additions and 28 deletions
+180
View File
@@ -0,0 +1,180 @@
`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
: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
Check it.
~~~~~~~~~
::
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
-b b^2 4 a c * * - sqrt [+] [-] cleave a 2 * [truediv] cons app2
-b b^2 4ac - sqrt [+] [-] cleave a 2 * [truediv] cons app2
-b b^2-4ac sqrt [+] [-] cleave a 2 * [truediv] cons app2
-b sqrt(b^2-4ac) [+] [-] cleave a 2 * [truediv] cons app2
-b -b+sqrt(b^2-4ac) -b-sqrt(b^2-4ac) a 2 * [truediv] cons app2
-b -b+sqrt(b^2-4ac) -b-sqrt(b^2-4ac) 2a [truediv] cons app2
-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
~~~~~~~
::
-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.
====================
::
b neg b sqr 4 a c * * - sqrt [+] [-] cleave a 2 * [truediv] cons app2 roll< pop
b [neg] dupdip sqr 4 a c * * - sqrt [+] [-] cleave a 2 * [truediv] cons app2 roll< pop
b a c [[neg] dupdip sqr 4] dipd * * - sqrt [+] [-] cleave a 2 * [truediv] cons app2 roll< pop
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
define('quadratic == over [[[neg] dupdip sqr 4] dipd * * - sqrt [+] [-] cleave] dip 2 * [truediv] cons app2 roll< pop')
.. code:: ipython2
J('3 1 1 quadratic')
.. parsed-literal::
-0.3819660112501051 -2.618033988749895
Simplify
~~~~~~~~
We can define a ``pm`` plus-or-minus function:
.. code:: ipython2
define('pm == [+] [-] cleave popdd')
Then ``quadratic`` becomes:
.. code:: ipython2
define('quadratic == over [[[neg] dupdip sqr 4] dipd * * - sqrt pm] dip 2 * [truediv] cons app2')
.. code:: ipython2
J('3 1 1 quadratic')
.. parsed-literal::
-0.3819660112501051 -2.618033988749895
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.
.. 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.
.. code:: ipython2
V('3 1 1 quadratic')
.. parsed-literal::
. 3 1 1 quadratic
3 . 1 1 quadratic
3 1 . 1 quadratic
3 1 1 . quadratic
3 1 1 . over [[[neg] dupdip sqr 4] dipd * * - sqrt pm] dip 2 * [truediv] cons app2
3 1 1 1 . [[[neg] dupdip sqr 4] dipd * * - sqrt pm] dip 2 * [truediv] cons app2
3 1 1 1 [[[neg] dupdip sqr 4] dipd * * - sqrt pm] . dip 2 * [truediv] cons app2
3 1 1 . [[neg] dupdip sqr 4] dipd * * - sqrt pm 1 2 * [truediv] cons app2
3 1 1 [[neg] dupdip sqr 4] . dipd * * - sqrt pm 1 2 * [truediv] cons app2
3 . [neg] dupdip sqr 4 1 1 * * - sqrt pm 1 2 * [truediv] cons app2
3 [neg] . dupdip sqr 4 1 1 * * - sqrt pm 1 2 * [truediv] cons app2
3 . neg 3 sqr 4 1 1 * * - sqrt pm 1 2 * [truediv] cons app2
-3 . 3 sqr 4 1 1 * * - sqrt pm 1 2 * [truediv] cons app2
-3 3 . sqr 4 1 1 * * - sqrt pm 1 2 * [truediv] cons app2
-3 3 . dup mul 4 1 1 * * - sqrt pm 1 2 * [truediv] cons app2
-3 3 3 . mul 4 1 1 * * - sqrt pm 1 2 * [truediv] cons app2
-3 9 . 4 1 1 * * - sqrt pm 1 2 * [truediv] cons app2
-3 9 4 . 1 1 * * - sqrt pm 1 2 * [truediv] cons app2
-3 9 4 1 . 1 * * - sqrt pm 1 2 * [truediv] cons app2
-3 9 4 1 1 . * * - sqrt pm 1 2 * [truediv] cons app2
-3 9 4 1 . * - sqrt pm 1 2 * [truediv] cons app2
-3 9 4 . - sqrt pm 1 2 * [truediv] cons app2
-3 5 . sqrt pm 1 2 * [truediv] cons app2
-3 2.23606797749979 . pm 1 2 * [truediv] cons app2
-0.7639320225002102 -5.23606797749979 . 1 2 * [truediv] cons app2
-0.7639320225002102 -5.23606797749979 1 . 2 * [truediv] cons app2
-0.7639320225002102 -5.23606797749979 1 2 . * [truediv] cons app2
-0.7639320225002102 -5.23606797749979 2 . [truediv] cons app2
-0.7639320225002102 -5.23606797749979 2 [truediv] . cons app2
-0.7639320225002102 -5.23606797749979 [2 truediv] . app2
[-0.7639320225002102] [2 truediv] . infra first [-5.23606797749979] [2 truediv] infra first
-0.7639320225002102 . 2 truediv [] swaack first [-5.23606797749979] [2 truediv] infra first
-0.7639320225002102 2 . truediv [] swaack first [-5.23606797749979] [2 truediv] infra first
-0.3819660112501051 . [] swaack first [-5.23606797749979] [2 truediv] infra first
-0.3819660112501051 [] . swaack first [-5.23606797749979] [2 truediv] infra first
[-0.3819660112501051] . first [-5.23606797749979] [2 truediv] infra first
-0.3819660112501051 . [-5.23606797749979] [2 truediv] infra first
-0.3819660112501051 [-5.23606797749979] . [2 truediv] infra first
-0.3819660112501051 [-5.23606797749979] [2 truediv] . infra first
-5.23606797749979 . 2 truediv [-0.3819660112501051] swaack first
-5.23606797749979 2 . truediv [-0.3819660112501051] swaack first
-2.618033988749895 . [-0.3819660112501051] swaack first
-2.618033988749895 [-0.3819660112501051] . swaack first
-0.3819660112501051 [-2.618033988749895] . first
-0.3819660112501051 -2.618033988749895 .