{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "### Jupyter" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "+ Language-independent part of IPython\n", "+ Provides user interfaces (console, notebook)\n", " + browser is UI for notebook server\n", " + convenient cell editing (markdown / code) and evaluation\n", " + notebook provides checkpoint functions in addition to create/save/load\n", " + manage kernel (stop / restart / reconnect)\n", "+ Provides document generators (nbconvert)\n", " + HTML, PDF, markdown, code-only, reStructuredText, LaTeX" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Maxima" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "+ Computer algebra == formal (ignoring content) manipulation of expressions\n", "+ Maxima covers undergraduate math, more or less\n", "+ Started in 1968 as part of Project MAC (\"machine-aided cognition\")\n", "+ Written in Lisp, now open source, active community\n", "+ Standard UI is ASCII-art console (useful, not pretty)\n", "+ I'd like to use Jupyter as a UI to compose math + text documents" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Jupyter architecture" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "+ Client (front end) separated from kernel (back end)\n", "+ Client and kernel talk through sockets provided by ZeroMQ\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Jupyter architecture diagram" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![jupyter architecture diagram](http://jupyter-client.readthedocs.org/en/latest/_images/frontend-kernel.png \"Jupyter architecture diagram\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Messages" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "+ Evaluation:\n", " + Client reads user input, sends string to kernel, e.g.: `\"diff(exp(a*x), x)\"`\n", " + Kernel parses input, calls Maxima function to evaluate, returns result in two forms:\n", " + as the printed form of a Maxima expression\n", " + as LaTeX\n", " + Client chooses an appropriate form to display\n", "+ Plot output:\n", " + Same as evaluation, but result is returned as SVG\n", "+ Maxima-initiated questions (`asksign`):\n", " + Maxima wants to ask user about the sign of some expression\n", " + Kernel sends input prompt to client\n", " + Client prints prompt, reads user input, sends string to kernel\n", " + Kernel passes user input to Maxima\n", " + Maxima completes whatever it was working on before" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Examples" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Formulate an expression" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{0}$}\\frac{d^2}{d\\,x^2}\\,\\left(\\frac{1}{\\sqrt{1-a\\,x^2}+1}\\right)\\]" ], "text/plain": [ " 2\n", " d 1\n", "(%o0) --- (------------------)\n", " 2 2\n", " dx sqrt(1 - a x ) + 1" ], "text/x-maxima": [ "'diff(1/(sqrt(1-a*x^2)+1),x,2)" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "foo : 'diff (1/(1 + sqrt(1 - a*x^2)), x, 2);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Evaluate" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{1}$}\\frac{a}{\\sqrt{1-a\\,x^2}\\,\\left(\\sqrt{1-a\\,x^2}+1\\right)^2}+\\frac{a^2\\,x^2}{\\left(1-a\\,x^2\\right)^{\\frac{3}{2}}\\,\\left(\\sqrt{1-a\\,x^2}+1\\right)^2}+\\frac{2\\,a^2\\,x^2}{\\left(1-a\\,x^2\\right)\\,\\left(\\sqrt{1-a\\,x^2}+1\\right)^3}\\]" ], "text/plain": [ " a\n", "(%o1) ------------------------------------\n", " 2 2 2\n", " sqrt(1 - a x ) (sqrt(1 - a x ) + 1)\n", " 2 2 2 2\n", " a x 2 a x\n", " + ----------------------------------- + --------------------------------\n", " 2 3/2 2 2 2 2 3\n", " (1 - a x ) (sqrt(1 - a x ) + 1) (1 - a x ) (sqrt(1 - a x ) + 1)" ], "text/x-maxima": [ "a/(sqrt(1-a*x^2)*(sqrt(1-a*x^2)+1)^2)+(a^2*x^2)\n", " /((1-a*x^2)^(3/2)*(sqrt(1-a*x^2)+1)^2)\n", " +(2*a^2*x^2)\n", " /((1-a*x^2)*(sqrt(1-a*x^2)+1)^3)" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bar : ev (foo, nouns);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### asksign prompt" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n" ] }, { "name": "stdin", "output_type": "stream", "text": [ "Is k equal to - 1?\n", " y;\n" ] }, { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{2}$}\\log x\\]" ], "text/plain": [ "(%o2) log(x)" ], "text/x-maxima": [ "log(x)" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "integrate (x^k, x);" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n" ] }, { "name": "stdin", "output_type": "stream", "text": [ "Is k equal to - 1?\n", " n;\n" ] }, { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{3}$}\\frac{x^{k+1}}{k+1}\\]" ], "text/plain": [ " k + 1\n", " x\n", "(%o3) ------\n", " k + 1" ], "text/x-maxima": [ "x^(k+1)/(k+1)" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "integrate (x^k, x);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Plot output" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "expt: undefined: 0 to a negative exponent.\n", "expt: undefined: 0 to a negative exponent.\n", "plot2d: expression evaluates to non-numeric value somewhere in plotting range.\n", "plot2d: some values will be clipped.\n" ] }, { "data": { "image/svg+xml": [ "\n", "\n", "\n", "Gnuplot\n", "Produced by GNUPLOT 5.4 patchlevel 9 \n", "\n", "\n", "\n", "\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t \n", "\t \n", "\t\n", "\t\n", "\t \n", "\t \n", "\t\n", "\n", "\n", "\n", "\n", "\t\n", "\n", "\t\n", "\n", "\t\n", "\n", "\t\n", "\t\tx\n", "\t\n", "\n", "\n", "\n", "\tgnuplot_plot_1\n", "\n", "\t\n", "\t\n", "\n", "\t\t\n", "\t\t-10\n", "\t\n", "\n", "\n", "\t\t\n", "\t\t-5\n", "\t\n", "\n", "\n", "\t\t\n", "\t\t 0\n", "\t\n", "\n", "\n", "\t\t\n", "\t\t 5\n", "\t\n", "\n", "\n", "\t\t\n", "\t\t 10\n", "\t\n", "\n", "\n", "\t\t\n", "\t\t-2\n", "\t\n", "\n", "\n", "\t\t\n", "\t\t-1.5\n", "\t\n", "\n", "\n", "\t\t\n", "\t\t-1\n", "\t\n", "\n", "\n", "\t\t\n", "\t\t-0.5\n", "\t\n", "\n", "\n", "\t\t\n", "\t\t 0\n", "\t\n", "\n", "\n", "\t\t\n", "\t\t 0.5\n", "\t\n", "\n", "\n", "\t\t\n", "\t\t 1\n", "\t\n", "\n", "\n", "\t\t\n", "\t\t 1.5\n", "\t\n", "\n", "\n", "\t\t\n", "\t\t 2\n", "\t\n", "\n", "\n", "\n", "\n", "\t\n", "\n", "\t\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\t\n", "\n", "\n", "\n", "\n", "\n" ], "text/plain": [ "/tmp/maxplot.svg" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "plot2d (subst (a = 1, bar), [x, -2, 2], [y, -10, 10], [svg_file, \"maxplot.svg\"],[plot_format, gnuplot])$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Minor features" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "+ Code syntax highlighting\n", " + In browser via CodeMirror\n", " + In HTML output via Pygments\n", " + Maxima-specific stuff is encapsulated in a function which only does some regex matching" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Links" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "+ Jupyter\n", " + [Project home page](http://jupyter.org)\n", " + [List of kernels in other languages](https://github.com/ipython/ipython/wiki/IPython-kernels-for-other-languages)\n", " + [Jupyter client/kernel interface spec](http://jupyter-client.readthedocs.org/en/latest/index.html)\n", "+ Maxima\n", " + [Project home page](http://maxima.sourceforge.net)\n", "+ Maxima-Jupyter\n", " + [Project home page](https://github.com/robert-dodier/maxima-jupyter)\n", " + [Example Maxima-Jupyter notebook](http://nbviewer.ipython.org/github/robert-dodier/maxima-jupyter/blob/master/MaximaJupyterExample.ipynb)\n", "+ About the author\n", " + [Robert Dodier](http://linkedin.com/in/robertdodier)" ] } ], "metadata": { "kernelspec": { "display_name": "Maxima", "language": "maxima", "name": "maxima" }, "language_info": { "codemirror_mode": "maxima", "file_extension": ".mac", "mimetype": "text/x-maxima", "name": "maxima", "pygments_lexer": "maxima", "version": "5.47.0" } }, "nbformat": 4, "nbformat_minor": 4 }