{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Interacting with Symata\n", "\n", "### Note: this notebook requires the development version of `Symata`. Switch to the development version with `Pkg.checkout(\"Symata\")`. Switch back to the latest version with `Pkg.free(\"Symata\")`\n", "\n", "## Output\n", "\n", "### Three output styles\n", "\n", "Symata runs in either the ipython (Jupyter) notebook or the Julia REPL (or even in a dumb terminal). In the Julia REPL two output styles are available, `Plain` and `Unicode`. In the notebook, a third style, called `IJulia`, is available. The notebook starts with the `IJulia` style." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "using Symata; isymata() # load the package and enter Symata mode" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/latex": [ "$$ \\int_{0}^{\\infty}f \\! \\left( \\mathbb{i} + x \\right) \\, \\mathbb{d}x $$" ], "text/plain": [ "L\"$$ \\int_{0}^{\\infty}f \\! \\left( \\mathbb{i} + x \\right) \\, \\mathbb{d}x $$\"" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Integrate(f(x+I),[x,0,Infinity]) # input is interpreted as Symata code" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here is the same thing in `Plain` style" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "Integrate(f(I + x),[x,0,Infinity])" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "OutputStyle(Plain), Out(2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In `Unicode` style, some of the symbols are pretty printed." ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "Integrate(f(𝕚 + x),[x,0,∞])" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "OutputStyle(Unicode), Out(2)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "Γ(a)" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Assume(a, Positive), Integrate(E^(-x) * x^(a-1), [x,0,Infinity])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In `Plain` style" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "Gamma(a)" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "OutputStyle(Plain), Out(5)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And back to `IJulia` style" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/latex": [ "$$ \\Gamma \\! \\left( a \\right) $$" ], "text/plain": [ "L\"$$ \\Gamma \\! \\left( a \\right) $$\"" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "OutputStyle(IJulia), Out(5)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Plain output style\n", "\n", "`Plain` style output is closest to the internal form of the expression. It can be copied and pasted as input. (This is also true of `Unicode` style)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "x^3 + 3(x^2)*y + 3x*(y^2) + y^3" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "OutputStyle(Plain),Expand((x+y)^3)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "Plus(Power(x,3),Times(3,Power(x,2),y),Times(3,x,Power(y,2)),Power(y,3))" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "FullForm(Out(8)) # Internal form of the previous output" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "x^3 + 3(x^2)*y + 3x*(y^2) + y^3" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Plus(Power(x,3),Times(3,Power(x,2),y),Times(3,x,Power(y,2)),Power(y,3)) # This is also valid input" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Compare this to `IJulia` output style which cannot in general be copied as input." ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [], "source": [ "OutputStyle(IJulia);" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/latex": [ "$$ \\int_{0}^{\\infty}g \\! \\left( x \\right) \\, \\mathbb{d}x $$" ], "text/plain": [ "L\"$$ \\int_{0}^{\\infty}g \\! \\left( x \\right) \\, \\mathbb{d}x $$\"" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Integrate(g(x), [x,0,Infinity])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This is what we get by cutting and pasting from the typset integral in Out[12]: ∫∞0g(x)𝕕x. Not valid input. But, you can still refer to the output cell:" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/latex": [ "$$ 1 $$" ], "text/plain": [ "L\"$$ 1 $$\"" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "( g(x_) := Exp(-x), Out(12) )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In `Plain` style, you can make the output more compact or less compact like this:" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "x^3 + 3(x^2) * y + 3x * (y^2) + y^3" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(OutputStyle(Plain), CompactOutput(False), Out(10))" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "x^3 + 3(x^2)*y + 3x*(y^2) + y^3" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "CompactOutput(True), Out(10)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### IJulia output style\n", "\n", "Here are some examples of formatting with `IJulia` output style" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/latex": [ "$$ \\frac{\\frac{1}{2} + a^{b}}{x + y} $$" ], "text/plain": [ "L\"$$ \\frac{\\frac{1}{2} + a^{b}}{x + y} $$\"" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "OutputStyle(IJulia), (1/2 + a^b)/(x+y) " ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/latex": [ "$$ \\sum _{\\substack{i=0 \\\\ j=1}}^{\\infty,n}h \\! \\left( i,j \\right) + \\sum _{\\substack{i=0 \\\\ j=0}}^{\\infty}g \\! \\left( i,j \\right) $$" ], "text/plain": [ "L\"$$ \\sum _{\\substack{i=0 \\\\ j=1}}^{\\infty,n}h \\! \\left( i,j \\right) + \\sum _{\\substack{i=0 \\\\ j=0}}^{\\infty}g \\! \\left( i,j \\right) $$\"" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Sum(g(i,j), [i,0,Infinity], [j,0,Infinity]) + Sum(h(i,j), [i,0,Infinity], [j,1,n])" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "collapsed": false, "scrolled": true }, "outputs": [ { "data": { "text/latex": [ "$$ \\int_{0}^{1} \\mathbb{d}x\\int_{0}^{1} \\mathbb{d}y \\, g \\! \\left( x,y \\right) $$" ], "text/plain": [ "L\"$$ \\int_{0}^{1} \\mathbb{d}x\\int_{0}^{1} \\mathbb{d}y \\, g \\! \\left( x,y \\right) $$\"" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Integrate(g(x,y), [x,0,1], [y,0,1])" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/latex": [ "$$ \\left( a \\, \\text{<} \\, b \\right) \\, \\text{&&} \\, \\left( b \\, \\text{<} \\, \\frac{c}{d} \\right) $$" ], "text/plain": [ "L\"$$ \\left( a \\, \\text{<} \\, b \\right) \\, \\text{&&} \\, \\left( b \\, \\text{<} \\, \\frac{c}{d} \\right) $$\"" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a < b < c/d" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Input\n", "\n", "### Unicode input\n", "\n", "\n", "Unicode input is inherited from Julia and the ipython/Jupyter notebook. In both the REPL and the notebook, you can enter a $\\LaTeX$ macro and hit `TAB` to convert it to a symbol. For instance, `\\alpha[TAB]` gives α. You can also copy/paste unicode symbols into the notebook.\n", "\n", "A few symbols, such as π, are intepreted as builtin Symata symbols.\n" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "collapsed": true }, "outputs": [], "source": [ "OutputStyle(Plain);" ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "[I + a + E + Pi,I + a + E + Pi]" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "[π + 𝕖 + 𝕚 + a, Pi + E + I + a] # \\pi + \\Bbbe + \\Bbbi" ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "collapsed": false }, "outputs": [], "source": [ "OutputStyle(Unicode);" ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "[𝕚 + a + 𝕖 + π,𝕚 + a + 𝕖 + π]" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "[π + 𝕖 + 𝕚 + a, Pi + E + I + a]" ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "collapsed": false }, "outputs": [], "source": [ "OutputStyle(IJulia);" ] }, { "cell_type": "code", "execution_count": 25, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/latex": [ "$$ [\\mathbb{i} + a + \\mathbb{e} + \\pi ,\\mathbb{i} + a + \\mathbb{e} + \\pi ] $$" ], "text/plain": [ "L\"$$ [\\mathbb{i} + a + \\mathbb{e} + \\pi ,\\mathbb{i} + a + \\mathbb{e} + \\pi ] $$\"" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "[π + 𝕖 + 𝕚 + a, Pi + E + I + a]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`Pi` and π, etc. refer to the same symbol." ] }, { "cell_type": "code", "execution_count": 26, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/latex": [ "$$ [\\text{True},\\text{True},\\text{True},\\text{True},\\text{True}] $$" ], "text/plain": [ "L\"$$ [\\text{True},\\text{True},\\text{True},\\text{True},\\text{True}] $$\"" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "[Pi == π, E == 𝕖, I == 𝕚, EulerGamma == γ, Gamma == Γ]" ] }, { "cell_type": "code", "execution_count": 27, "metadata": { "collapsed": false, "scrolled": false }, "outputs": [ { "data": { "text/latex": [ "$$ [-1,-1] $$" ], "text/plain": [ "L\"$$ [-1,-1] $$\"" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Cos([Pi, π])" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "### TAB completion\n", "\n", "In `Symata`, in both the command line REPL and `IJulia`, you can use TAB completion to complete built-in symbols, in the same way that you do in `Julia`. In `IJulia`, typing `Shift-TAB` when the cursor is at the end of a built-in symbol displays a pop-up with the doc string, if available.\n", "\n", "You can get the same doc string (and the corresponding `sympy` document) by typing `?` followed by the symbol." ] }, { "cell_type": "code", "execution_count": 28, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/markdown": [ "```\n", "OutputStyle(Plain)\n", "```\n", "\n", "print plain 1d text output.\n", "\n", "```\n", "OutputStyle(Unicode)\n", "```\n", "\n", "print 1d text output with pretty unicode characters.\n", "\n", "```\n", "OutputStyle(IJulia)\n", "```\n", "\n", "in IJulia, print in typeset mathematics style using latex.\n", "\n", "```\n", "OutputStyle()\n", "```\n", "\n", "return the current output style.\n", "\n", "`Plain` and `Unicode` give output that is valid `Symata` input for the same expression.\n" ], "text/plain": [ "```\n", "OutputStyle(Plain)\n", "```\n", "\n", "print plain 1d text output.\n", "\n", "```\n", "OutputStyle(Unicode)\n", "```\n", "\n", "print 1d text output with pretty unicode characters.\n", "\n", "```\n", "OutputStyle(IJulia)\n", "```\n", "\n", "in IJulia, print in typeset mathematics style using latex.\n", "\n", "```\n", "OutputStyle()\n", "```\n", "\n", "return the current output style.\n", "\n", "`Plain` and `Unicode` give output that is valid `Symata` input for the same expression.\n" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "Help( OutputStyle)\n", "\n", "See also CompactOutput.\n", "\n", " Attributes(OutputStyle) = [Protected]\n" ] } ], "source": [ "? OutputStyle" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Julia 0.6.0-dev", "language": "julia", "name": "julia-0.6" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "0.6.0" } }, "nbformat": 4, "nbformat_minor": 1 }