Cadabra
a field-theory motivated approach to computer algebra

cdb.sympy.solvers

Access to Sympy solver functions.
These are simple wrappers to make Sympy solvers available from Cadabra, using Cadabra expressions. There are some differences in the input and output of these functions with respect to Sympy, mainly to make things more consistent.

dsolve(Ex: equation, Ex: function) -> Ex

Solve a single ordinary differential equation.
Given a single differential equation and a function to be solved for, return the solution. Functions can have implicit dependence on the independent variable, as in the example below, where $f$ depends on $x$ but that dependence is not spelled out again explicitly in the equation.
import sympy
x::Coordinate; f::Depends(x); \partial{#}::PartialDerivative; ex:= \partial_{x x}{f} + \partial_{x}{f} = \sin(x); sol=dsolve(ex, $f$);
\(\displaystyle{}\text{Attached property Coordinate to }x.\)
\(\displaystyle{}\text{Attached property Depends to }f.\)
\(\displaystyle{}\text{Attached property PartialDerivative to }\partial{\#}.\)
\(\displaystyle{}\partial_{x x}{f}+\partial_{x}{f} = \sin{x}\)
\partial_{x x}(f) + \partial_{x}(f) = \sin(x)
\(\displaystyle{}f = C1+C2 \exp\left(-x\right) - \frac{1}{2}\sin{x} - \frac{1}{2}\cos{x}\)
f = C1 + C2 \exp(-x) - 1/2 \sin(x) - 1/2 \cos(x)
substitute(ex, sol);
\(\displaystyle{}\partial_{x x}\left(C1+C2 \exp\left(-x\right) - \frac{1}{2}\sin{x} - \frac{1}{2}\cos{x}\right)+\partial_{x}\left(C1+C2 \exp\left(-x\right) - \frac{1}{2}\sin{x} - \frac{1}{2}\cos{x}\right) = \sin{x}\)
\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)
map_sympy(ex, "simplify");
\(\displaystyle{}\sin{x} = \sin{x}\)
\sin(x) = \sin(x)

linsolve(Ex: equations, Ex: objects) -> Ex

Solve a linear system for unknowns.
Given an expression containing one or more linear equations, and an second expression containing the variables to solve for, determine the solutions. Returns list with one element, which is a list of substitution rules for the variables that have been solved for (the output is a nested list to ensure that it is similar to the output of nonlinsolve).
ex:= x + a = 0; sol=linsolve(ex, $x$);
\(\displaystyle{}x+a = 0\)
x + a = 0
\(\displaystyle{}\left[\left[x \rightarrow -a\right]\right]\)
{{x → -a}}
substitute(ex, sol[0]);
\(\displaystyle{}0 = 0\)
0 = 0
ex:= x + 1 = 0, y + 4/3 x + 2 a = 0; sol=linsolve(ex, $x,y$);
\(\displaystyle{}\left[x+1 = 0, y+\frac{4}{3}x+2a = 0\right]\)
{x + 1 = 0, y + 4/3 x + 2a = 0}
\(\displaystyle{}\left[\left[x \rightarrow -1, y \rightarrow -2a+\frac{4}{3}\right]\right]\)
{{x → -1, y → -2a + 4/3 }}
substitute(ex, sol[0]);
\(\displaystyle{}\left[0 = 0, 0 = 0\right]\)
{0 = 0, 0 = 0}
ex:= x A_{m} C^{m} + b D_{n p} G^{n p} = 0; linsolve(ex, $x$);
\(\displaystyle{}x A_{m} C^{m}+b D_{n p} G^{n p} = 0\)
x A_{m} C^{m} + b D_{n p} G^{n p} = 0
\(\displaystyle{}\left[\left[x \rightarrow -b D_{n p} G^{n p} {\left(A_{m} C^{m}\right)}^{-1}\right]\right]\)
{{x → -b D_{n p} G^{n p} (A_{m} C^{m})**(-1)}}

nonlinsolve

Solve a system of non-linear equations.
Given an expression containing one or more linear equations, and an second expression containing the variables to solve for, determine the solutions. Returns a substitution rule or a list of substitution rules for the variables that have been solved for.
ex:= x**2-1; sol=nonlinsolve(ex, $x$);
\(\displaystyle{}{x}^{2}-1\)
(x)**2-1
\(\displaystyle{}\left[\left[x \rightarrow -1\right], \left[x \rightarrow 1\right]\right]\)
{{x → -1}, {x → 1}}
substitute(ex, sol[0]);
\(\displaystyle{}0\)
0
ex:= x**2 + A_{m} B^{m} = 0; sol=nonlinsolve(ex, $x$);
\(\displaystyle{}{x}^{2}+A_{m} B^{m} = 0\)
(x)**2 + A_{m} B^{m} = 0
\(\displaystyle{}\left[\left[x \rightarrow -\sqrt{-A_{m} B^{m}}\right], \left[x \rightarrow \sqrt{-A_{m} B^{m}}\right]\right]\)
{{x → -(-A_{m} B^{m})**( 1/2 )}, {x → (-A_{m} B^{m})**( 1/2 )}}
ex:= { x**2 - 1 = 0, y**2 - 2 =0 }; nonlinsolve(ex, $x,y$);
\(\displaystyle{}\left[{x}^{2}-1 = 0, {y}^{2}-2 = 0\right]\)
{(x)**2-1 = 0, (y)**2-2 = 0}
\(\displaystyle{}\left[\left[x \rightarrow -1, y \rightarrow -\sqrt{2}\right], \left[x \rightarrow -1, y \rightarrow \sqrt{2}\right], \left[x \rightarrow 1, y \rightarrow -\sqrt{2}\right], \left[x \rightarrow 1, y \rightarrow \sqrt{2}\right]\right]\)
{{x → -1, y → -2**( 1/2 )}, {x → -1, y → 2**( 1/2 )}, {x → 1, y → -2**( 1/2 )}, {x → 1, y → 2**( 1/2 )}}
Copyright © 2001-2019 Kasper Peeters
Questions? info@cadabra.science