{ "cell_id" : 10165666682519261461, "cells" : [ { "cell_id" : 15790243487325388783, "cell_origin" : "client", "cell_type" : "latex", "cells" : [ { "cell_id" : 117344227491248367, "cell_origin" : "client", "cell_type" : "latex_view", "source" : "\\package{cdb.sympy.solvers}{Access to Sympy solver functions.}\n\nThese are simple wrappers to make Sympy solvers available from Cadabra, using\nCadabra expressions. There are some differences in the input and output of these\nfunctions with respect to Sympy, mainly to make things more consistent." } ], "hidden" : true, "source" : "\\package{cdb.sympy.solvers}{Access to Sympy solver functions.}\n\nThese are simple wrappers to make Sympy solvers available from Cadabra, using\nCadabra expressions. There are some differences in the input and output of these\nfunctions with respect to Sympy, mainly to make things more consistent." }, { "cell_id" : 18194547037908567614, "cell_origin" : "client", "cell_type" : "latex", "cells" : [ { "cell_id" : 11537546742094706282, "cell_origin" : "client", "cell_type" : "latex_view", "source" : "\\algorithm{dsolve(Ex: equation(s), Ex: function(s)) -> Ex}{Solve (system of) ordinary differential equation(s).}\n\nGiven a single differential equation or a system of differential equations, return the solution. The second argument\nis optional; if not given, \\algo{dsolve} will try to figure out the unknown(s). Functions can\nhave implicit dependence on the independent variable, as in the example below, where $f$ depends on $x$\nbut that dependence is not spelled out again explicitly in the equation.\n\nNote that since this is backed by \\verb|sympy.dsolve|, and the latter is rather buggy for systems\nof differential equations, do not expect miracles in that case." } ], "hidden" : true, "source" : "\\algorithm{dsolve(Ex: equation(s), Ex: function(s)) -> Ex}{Solve (system of) ordinary differential equation(s).}\n\nGiven a single differential equation or a system of differential equations, return the solution. The second argument\nis optional; if not given, \\algo{dsolve} will try to figure out the unknown(s). Functions can\nhave implicit dependence on the independent variable, as in the example below, where $f$ depends on $x$\nbut that dependence is not spelled out again explicitly in the equation.\n\nNote that since this is backed by \\verb|sympy.dsolve|, and the latter is rather buggy for systems\nof differential equations, do not expect miracles in that case." }, { "cell_id" : 8589228160107610297, "cell_origin" : "client", "cell_type" : "input", "source" : "import sympy" }, { "cell_id" : 11180798987284830538, "cell_origin" : "client", "cell_type" : "input", "source" : "def dsolve(ex, obj=None):\n # FIXME: If ex is a list, convert to an Ex when it is pulled\n # into an expression like below!\n ret = $@(ex)$\n sb = SympyBridge(ret)\n if obj is None:\n sb.from_sympy( str(sympy.dsolve( sb.to_sympy() )) )\n else:\n sbo = SympyBridge(obj)\n sb.from_sympy( str(sympy.dsolve( sb.to_sympy(), sbo.to_sympy() )) )\n return ret" }, { "cell_id" : 497397197071890198, "cell_origin" : "client", "cell_type" : "input", "cells" : [ { "cell_id" : 6863992350555418024, "cell_origin" : "server", "cell_type" : "latex_view", "source" : "\\begin{dmath*}{}\\text{Attached property Coordinate to~}x.\\end{dmath*}" }, { "cell_id" : 10562191967384710242, "cell_origin" : "server", "cell_type" : "latex_view", "source" : "\\begin{dmath*}{}\\text{Attached property Depends to~}\\left[f,~\\discretionary{}{}{} g\\right].\\end{dmath*}" }, { "cell_id" : 11732611173091862574, "cell_origin" : "server", "cell_type" : "latex_view", "source" : "\\begin{dmath*}{}\\text{Attached property PartialDerivative to~}\\partial{\\#}.\\end{dmath*}" }, { "cell_id" : 10831718817873196420, "cell_origin" : "server", "cell_type" : "latex_view", "cells" : [ { "cell_id" : 5766379168331550748, "cell_origin" : "server", "cell_type" : "input_form", "source" : "\\partial_{x x}(f) + \\partial_{x}(f) = \\sin(x)" } ], "source" : "\\begin{dmath*}{}\\partial_{x x}{f}+\\partial_{x}{f} = \\sin{x}\\end{dmath*}" }, { "cell_id" : 10616129735868799064, "cell_origin" : "server", "cell_type" : "latex_view", "cells" : [ { "cell_id" : 11302012449967486688, "cell_origin" : "server", "cell_type" : "input_form", "source" : "f = C1 + C2 \\exp(-x) - 1/2 \\sin(x) - 1/2 \\cos(x)" } ], "source" : "\\begin{dmath*}{}f = {C_{1}}+{C_{2}} \\exp\\left(-x\\right) - \\frac{1}{2}\\sin{x} - \\frac{1}{2}\\cos{x}\\end{dmath*}" } ], "ignore_on_import" : true, "source" : "x::Coordinate;\n{f,g}::Depends(x);\n\\partial{#}::PartialDerivative;\nex:= \\partial_{x x}{f} + \\partial_{x}{f} = \\sin(x);\nsol=dsolve(ex, $f$);" }, { "cell_id" : 4985987136595864320, "cell_origin" : "client", "cell_type" : "input", "cells" : [ { "cell_id" : 5122370839036334987, "cell_origin" : "server", "cell_type" : "latex_view", "cells" : [ { "cell_id" : 10154623303091810019, "cell_origin" : "server", "cell_type" : "input_form", "source" : "\\partial_{x x}((C1 + C2 \\exp(-x) - 1/2 \\sin(x) - 1/2 \\cos(x))) + \\partial_{x}((C1 + C2 \\exp(-x) - 1/2 \\sin(x) - 1/2 \\cos(x))) = \\sin(x)" } ], "source" : "\\begin{dmath*}{}\\partial_{x x}\\left({C_{1}}+{C_{2}} \\exp\\left(-x\\right) - \\frac{1}{2}\\sin{x} - \\frac{1}{2}\\cos{x}\\right)+\\partial_{x}\\left({C_{1}}+{C_{2}} \\exp\\left(-x\\right) - \\frac{1}{2}\\sin{x} - \\frac{1}{2}\\cos{x}\\right) = \\sin{x}\\end{dmath*}" } ], "ignore_on_import" : true, "source" : "substitute(ex, sol);" }, { "cell_id" : 6058106723051096452, "cell_origin" : "client", "cell_type" : "input", "cells" : [ { "cell_id" : 14718428334297182831, "cell_origin" : "server", "cell_type" : "latex_view", "cells" : [ { "cell_id" : 1244430831207562474, "cell_origin" : "server", "cell_type" : "input_form", "source" : "\\sin(x) = \\sin(x)" } ], "source" : "\\begin{dmath*}{}\\sin{x} = \\sin{x}\\end{dmath*}" } ], "ignore_on_import" : true, "source" : "map_sympy(ex, \"simplify\");" }, { "cell_id" : 9955417298432415316, "cell_origin" : "client", "cell_type" : "input", "cells" : [ { "cell_id" : 9858352583374092380, "cell_origin" : "server", "cell_type" : "latex_view", "cells" : [ { "cell_id" : 10916084760399125194, "cell_origin" : "server", "cell_type" : "input_form", "source" : "{\\partial_{x}(f) = f g \\sin(x), \\partial_{x}(g) = (g)**2 \\sin(x)}" } ], "source" : "\\begin{dmath*}{}\\left[\\partial_{x}{f} = f g \\sin{x},~\\discretionary{}{}{} \\partial_{x}{g} = {g}^{2} \\sin{x}\\right]\\end{dmath*}" } ], "ignore_on_import" : true, "source" : "st:= { \\partial_{x}{f} = f g \\sin(x), \\partial_{x}{g} = g**2 \\sin(x) };" }, { "cell_id" : 17502079193295596278, "cell_origin" : "client", "cell_type" : "input", "cells" : [ { "cell_id" : 12011168151334637101, "cell_origin" : "server", "cell_type" : "latex_view", "cells" : [ { "cell_id" : 12563072646580660894, "cell_origin" : "server", "cell_type" : "input_form", "source" : "{f = -\\exp(C1) (C2 \\exp(C1)-\\cos(x))**(-1), g = -(C1-\\cos(x))**(-1)}" } ], "source" : "\\begin{dmath*}{}\\left[f = -\\exp\\left({C_{1}}\\right) {\\left({C_{2}} \\exp\\left({C_{1}}\\right)-\\cos{x}\\right)}^{-1},~\\discretionary{}{}{} g = -{\\left({C_{1}}-\\cos{x}\\right)}^{-1}\\right]\\end{dmath*}" } ], "ignore_on_import" : true, "source" : "dsolve(st);" }, { "cell_id" : 11970634058257249996, "cell_origin" : "client", "cell_type" : "latex", "cells" : [ { "cell_id" : 5416491856389503593, "cell_origin" : "client", "cell_type" : "latex_view", "source" : "\\algorithm{linsolve(Ex: equations, Ex: objects) -> Ex}{Solve a linear system for unknowns.}\n\nGiven an expression containing one or more linear equations, and an second expression containing\nthe variables to solve for, determine the solutions. Returns list with one element, which is a\nlist of substitution rules for the variables that have been solved for (the output is a nested\nlist to ensure that it is similar to the output of \\algo{nonlinsolve})." } ], "hidden" : true, "source" : "\\algorithm{linsolve(Ex: equations, Ex: objects) -> Ex}{Solve a linear system for unknowns.}\n\nGiven an expression containing one or more linear equations, and an second expression containing\nthe variables to solve for, determine the solutions. Returns list with one element, which is a\nlist of substitution rules for the variables that have been solved for (the output is a nested\nlist to ensure that it is similar to the output of \\algo{nonlinsolve})." }, { "cell_id" : 17888835071658719091, "cell_origin" : "client", "cell_type" : "input", "source" : "def linsolve(exs, objs):\n ret = $@(exs)$\n obl = $@(objs)$\n if ret.head()!=r\"\\comma\":\n ret = $\\comma{ @(ret) }$\n if obl.head()!=r\"\\comma\":\n obl = $\\comma{ @(obl) }$\n sb = SympyBridge(ret)\n sb.from_sympy( str(sympy.linsolve( sb.to_sympy(), obl._sympy_())) )\n # The result is a list of solutions. Turn this into a list of\n # rules. Newer sympy versions return a FiniteSet, convert this too.\n if ret.head()==r\"FiniteSet\":\n if len(ret)==1:\n ret = ret[0]\n if ret.head()!=r\"\\comma\":\n ret = $ \\comma{ \\comma{ @(objs) -> @(ret) } } $\n else:\n nret = $\\comma{}$\n for i in range(len(ret)):\n tmpv=objs[i]\n tmps=ret[i]\n nret.top().append_child($ @(tmpv) -> @(tmps) $)\n ret=$ \\comma{ @(nret) }$\n return ret" }, { "cell_id" : 3825114940942753284, "cell_origin" : "client", "cell_type" : "input", "cells" : [ { "cell_id" : 17684186442141873626, "cell_origin" : "server", "cell_type" : "latex_view", "cells" : [ { "cell_id" : 4404526061878169939, "cell_origin" : "server", "cell_type" : "input_form", "source" : "x + a = 0" } ], "source" : "\\begin{dmath*}{}x+a = 0\\end{dmath*}" }, { "cell_id" : 2281777726973566284, "cell_origin" : "server", "cell_type" : "latex_view", "cells" : [ { "cell_id" : 6778385591079348200, "cell_origin" : "server", "cell_type" : "input_form", "source" : "{{x -> -a}}" } ], "source" : "\\begin{dmath*}{}\\left[\\left[x \\rightarrow -a\\right]\\right]\\end{dmath*}" } ], "ignore_on_import" : true, "source" : "ex:= x + a = 0;\nsol=linsolve(ex, $x$);" }, { "cell_id" : 6176825001521917917, "cell_origin" : "client", "cell_type" : "input", "cells" : [ { "cell_id" : 12706873865336504437, "cell_origin" : "server", "cell_type" : "latex_view", "cells" : [ { "cell_id" : 9262839215028602238, "cell_origin" : "server", "cell_type" : "input_form", "source" : "0 = 0" } ], "source" : "\\begin{dmath*}{}0 = 0\\end{dmath*}" } ], "ignore_on_import" : true, "source" : "substitute(ex, sol[0]);" }, { "cell_id" : 9426120572392451421, "cell_origin" : "client", "cell_type" : "input", "cells" : [ { "cell_id" : 500347979227619731, "cell_origin" : "server", "cell_type" : "latex_view", "cells" : [ { "cell_id" : 10996120923985229610, "cell_origin" : "server", "cell_type" : "input_form", "source" : "{x + 1 = 0, y + 4/3 x + 2a = 0}" } ], "source" : "\\begin{dmath*}{}\\left[x+1 = 0,~\\discretionary{}{}{} y+\\frac{4}{3}x+2a = 0\\right]\\end{dmath*}" }, { "cell_id" : 3698530452774611163, "cell_origin" : "server", "cell_type" : "latex_view", "cells" : [ { "cell_id" : 9979128880312623907, "cell_origin" : "server", "cell_type" : "input_form", "source" : "{{x -> -1, y -> 4/3 -2a}}" } ], "source" : "\\begin{dmath*}{}\\left[\\left[x \\rightarrow -1,~\\discretionary{}{}{} y \\rightarrow \\frac{4}{3}-2a\\right]\\right]\\end{dmath*}" } ], "ignore_on_import" : true, "source" : "ex:= x + 1 = 0, y + 4/3 x + 2 a = 0;\nsol=linsolve(ex, $x,y$);" }, { "cell_id" : 16125223527973836266, "cell_origin" : "client", "cell_type" : "input", "cells" : [ { "cell_id" : 761592485475846311, "cell_origin" : "server", "cell_type" : "latex_view", "cells" : [ { "cell_id" : 5576083838072958682, "cell_origin" : "server", "cell_type" : "input_form", "source" : "{0 = 0, 0 = 0}" } ], "source" : "\\begin{dmath*}{}\\left[0 = 0,~\\discretionary{}{}{} 0 = 0\\right]\\end{dmath*}" } ], "ignore_on_import" : true, "source" : "substitute(ex, sol[0]);" }, { "cell_id" : 10231998506255394040, "cell_origin" : "client", "cell_type" : "input", "cells" : [ { "cell_id" : 5465144330139214481, "cell_origin" : "server", "cell_type" : "latex_view", "cells" : [ { "cell_id" : 13932574290516155813, "cell_origin" : "server", "cell_type" : "input_form", "source" : "x A_{m} C^{m} + b D_{n p} G^{n p} = 0" } ], "source" : "\\begin{dmath*}{}x A_{m} C^{m}+b D_{n p} G^{n p} = 0\\end{dmath*}" }, { "cell_id" : 4663387022186441696, "cell_origin" : "server", "cell_type" : "latex_view", "cells" : [ { "cell_id" : 13913668299812041980, "cell_origin" : "server", "cell_type" : "input_form", "source" : "{{x -> -b D_{n p} G^{n p} (A_{m} C^{m})**(-1)}}" } ], "source" : "\\begin{dmath*}{}\\left[\\left[x \\rightarrow -b D_{n p} G^{n p} {\\left(A_{m} C^{m}\\right)}^{-1}\\right]\\right]\\end{dmath*}" } ], "ignore_on_import" : true, "source" : "ex:= x A_{m} C^{m} + b D_{n p} G^{n p} = 0;\nlinsolve(ex, $x$);" }, { "cell_id" : 15662243220303454349, "cell_origin" : "client", "cell_type" : "latex", "cells" : [ { "cell_id" : 17001975289188242795, "cell_origin" : "client", "cell_type" : "latex_view", "source" : "\\algorithm{nonlinsolve}{Solve a system of non-linear equations.}\n\nGiven an expression containing one or more linear equations, and an second expression containing\nthe variables to solve for, determine the solutions. Returns a substitution rule or a list of\nsubstitution rules for the variables that have been solved for." } ], "hidden" : true, "source" : "\\algorithm{nonlinsolve}{Solve a system of non-linear equations.}\n\nGiven an expression containing one or more linear equations, and an second expression containing\nthe variables to solve for, determine the solutions. Returns a list of substitution rules for the \nvariables that have been solved for." }, { "cell_id" : 911768519859269492, "cell_origin" : "client", "cell_type" : "input", "source" : "from sympy.solvers.solveset import nonlinsolve as sympy_nonlinsolve\n\ndef nonlinsolve(exs, objs):\n ret = $@(exs)$\n obl = $@(objs)$\n if ret.head()!=r\"\\comma\":\n ret = $\\comma{ @(ret) }$\n if obl.head()!=r\"\\comma\":\n obl = $\\comma{ @(obl) }$\n sb = SympyBridge(ret)\n sb.from_sympy( str(sympy_nonlinsolve( sb.to_sympy(), objs._sympy_())) )\n # The result is a list of solutions. Turn this into a list of\n # rules.\n if len(obl)==1:\n nret = $\\comma{}$\n for i in range(len(ret)):\n tmps=ret[i]\n nret.top().append_child($ \\comma{ @(objs) -> @(tmps) } $)\n ret=nret\n else:\n nret = $\\comma{}$\n for i in range(len(ret)):\n tsol=$\\comma{}$\n for v in range(len(objs)):\n tmpv=objs[v]\n tmps=ret[i][v]\n tsol.top().append_child($ @(tmpv) -> @(tmps) $)\n nret.top().append_child(tsol)\n ret=nret\n return ret" }, { "cell_id" : 4737965800086152437, "cell_origin" : "client", "cell_type" : "input", "cells" : [ { "cell_id" : 16555365248775170640, "cell_origin" : "server", "cell_type" : "latex_view", "cells" : [ { "cell_id" : 10644160256284117944, "cell_origin" : "server", "cell_type" : "input_form", "source" : "(x)**2-1" } ], "source" : "\\begin{dmath*}{}{x}^{2}-1\\end{dmath*}" }, { "cell_id" : 1059215072305134686, "cell_origin" : "server", "cell_type" : "latex_view", "cells" : [ { "cell_id" : 14582863886186273190, "cell_origin" : "server", "cell_type" : "input_form", "source" : "{{x -> -1}, {x -> 1}}" } ], "source" : "\\begin{dmath*}{}\\left[\\left[x \\rightarrow -1\\right],~\\discretionary{}{}{} \\left[x \\rightarrow 1\\right]\\right]\\end{dmath*}" } ], "ignore_on_import" : true, "source" : "ex:= x**2-1;\nsol=nonlinsolve(ex, $x$);" }, { "cell_id" : 9068678982032793579, "cell_origin" : "client", "cell_type" : "input", "cells" : [ { "cell_id" : 4590196860440311052, "cell_origin" : "server", "cell_type" : "latex_view", "cells" : [ { "cell_id" : 13778551354595748251, "cell_origin" : "server", "cell_type" : "input_form", "source" : "0" } ], "source" : "\\begin{dmath*}{}0\\end{dmath*}" } ], "ignore_on_import" : true, "source" : "substitute(ex, sol[0])\nsimplify(ex);" }, { "cell_id" : 14972222131526038404, "cell_origin" : "client", "cell_type" : "input", "cells" : [ { "cell_id" : 4754303203788766540, "cell_origin" : "server", "cell_type" : "latex_view", "cells" : [ { "cell_id" : 11268591135457253334, "cell_origin" : "server", "cell_type" : "input_form", "source" : "(x)**2 + A_{m} B^{m} = 0" } ], "source" : "\\begin{dmath*}{}{x}^{2}+A_{m} B^{m} = 0\\end{dmath*}" }, { "cell_id" : 7968612786110043934, "cell_origin" : "server", "cell_type" : "latex_view", "cells" : [ { "cell_id" : 3824539599541410927, "cell_origin" : "server", "cell_type" : "input_form", "source" : "{{x -> (-A_{m} B^{m})**( 1/2 )}, {x -> -(-A_{m} B^{m})**( 1/2 )}}" } ], "source" : "\\begin{dmath*}{}\\left[\\left[x \\rightarrow \\sqrt{-A_{m} B^{m}}\\right],~\\discretionary{}{}{} \\left[x \\rightarrow -\\sqrt{-A_{m} B^{m}}\\right]\\right]\\end{dmath*}" } ], "ignore_on_import" : true, "source" : "ex:= x**2 + A_{m} B^{m} = 0;\nsol=nonlinsolve(ex, $x$);" }, { "cell_id" : 3008341142464299938, "cell_origin" : "client", "cell_type" : "input", "cells" : [ { "cell_id" : 1003857805012697149, "cell_origin" : "server", "cell_type" : "latex_view", "cells" : [ { "cell_id" : 10720680898706651968, "cell_origin" : "server", "cell_type" : "input_form", "source" : "{(x)**2-1 = 0, (y)**2-2 = 0}" } ], "source" : "\\begin{dmath*}{}\\left[{x}^{2}-1 = 0,~\\discretionary{}{}{} {y}^{2}-2 = 0\\right]\\end{dmath*}" }, { "cell_id" : 14808995519385684650, "cell_origin" : "server", "cell_type" : "latex_view", "cells" : [ { "cell_id" : 9752353090132479368, "cell_origin" : "server", "cell_type" : "input_form", "source" : "{{x -> -1, y -> 2**( 1/2 )}, {x -> 1, y -> 2**( 1/2 )}, {x -> -1, y -> -2**( 1/2 )}, {x -> 1, y -> -2**( 1/2 )}}" } ], "source" : "\\begin{dmath*}{}\\left[\\left[x \\rightarrow -1,~\\discretionary{}{}{} y \\rightarrow \\sqrt{2}\\right],~\\discretionary{}{}{} \\left[x \\rightarrow 1,~\\discretionary{}{}{} y \\rightarrow \\sqrt{2}\\right],~\\discretionary{}{}{} \\left[x \\rightarrow -1,~\\discretionary{}{}{} y \\rightarrow -\\sqrt{2}\\right],~\\discretionary{}{}{} \\left[x \\rightarrow 1,~\\discretionary{}{}{} y \\rightarrow -\\sqrt{2}\\right]\\right]\\end{dmath*}" } ], "ignore_on_import" : true, "source" : "ex:= { x**2 - 1 = 0, y**2 - 2 =0 }; \nnonlinsolve(ex, $x,y$);" }, { "cell_id" : 6913007854354215623, "cell_origin" : "client", "cell_type" : "input", "source" : "" } ], "description" : "Cadabra JSON notebook format", "version" : 1 }