In [1]:
using Symata # load Symata and enter symata mode
In [2]:
OutputStyle(JupyterForm)
Out[2]:
In [3]:
ex = (x-y)*(z-y) + Sqrt((x-y)*(z-y))
Out[3]:
Cse(expr) recursively replaces subexpressions that occur more than once in expr with names. The transformed expression is returned with a list of rules that can be used to recover expr.
In [4]:
Cse(ex)
Out[4]:
Applying in order the replacement rules in the second list to the expression in the first list results in the original expression.
To apply the rules, we will use Splat, which works like this,
In [5]:
f(a,b,Splat([c,d]))
Out[5]:
and Fold, which works like this,
In [6]:
Fold(f, [x,a,b,c])
Out[6]:
Apply the replacement rules like this,
In [7]:
Fold(ReplaceAll, Splat(Cse(ex)))[1]
Out[7]:
Check that the reconstructed expression is equal to the original expression.
In [8]:
Fold(ReplaceAll, Splat(Cse(ex)))[1] == ex
Out[8]:
In [9]:
ClearAll(ex)
Together rewrites rational expressions as a single fraction.
In [10]:
Together(1/x + 1/y + 1/z)
Out[10]:
In [11]:
Together(1/(x*y) + 1/y^2)
Out[11]:
In [12]:
Together(1/(1 + 1/x) + 1/(1 + 1/y))
Out[12]:
By default, Together only works at the topmost level.
In [13]:
Together(Exp(1/x + 1/y))
Out[13]:
Together is applied at all levels if the option Deep is true.
In [14]:
Together(Exp(1/x + 1/y), Deep => True)
Out[14]:
Apart gives the partial fraction decomposition of a rational expression
In [15]:
Apart(y/(x + 2)/(x + 1), x)
Out[15]:
If the denominator has non-rational roots, the option Full => True must be given.
In [16]:
Apart(y/(x^2 + x + 1), x, Full=>True)
Out[16]:
In [17]:
Collect(a*x^2 + b*x^2 + a*x - b*x + c, x)
Out[17]:
Collect coefficients of an expression.
In [18]:
Collect(a*x*Log(x) + (b+a)*(x*Log(x)), x*Log(x))
Out[18]:
In [19]:
VersionInfo()
In [20]:
InputForm(Now())
Out[20]:
VersionInfo()
symata version 0.3.0-dev.7 julia version 0.6.0-dev.435 python version 2.7.12 sympy version 1.0
Now() 2016−11−28T22:34:33.713