Name: SymEngine.jl
Owner: symengine
Description: Julia wrappers of SymEngine
Created: 2015-06-07 17:41:32.0
Updated: 2018-01-16 11:04:52.0
Pushed: 2017-12-22 15:41:42.0
Size: 131
Language: Julia
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Julia Wrappers for SymEngine, a fast symbolic manipulation library, written in C++.
You can install SymEngine.jl
by giving the following command.
a> Pkg.add("SymEngine")
One can define variables in a few ways. The following three examples are equivalent.
Defining two symbolic variables with the names a
and b
, and assigning them to julia variables with the same name.
a> a=symbols(:a); b=symbols(:b)
a> a,b = symbols("a b")
b)
a> @vars a b
b)
We are going to define an expression using the variables from earlier:
a> ex1 = a + 2(b+2)^2 + 2a + 3(a+1)
+ 3*(1 + a) + 2*(2 + b)^2
One can see that values are grouped, but no expansion is done.
Some times one might want to define a matrix of variables. One can use a matrix comprehension, and string interpolation to create a matrix of variables.
a> W = [symbols("W_$i$j") for i in 1:3, j in 1:4]
Array{SymEngine.Basic,2}:
1 W_12 W_13 W_14
1 W_22 W_23 W_24
1 W_32 W_33 W_34
Now using the matrix we can perform matrix operations:
a> W*[1.0, 2.0, 3.0, 4.0]
ement Array{SymEngine.Basic,1}:
*W_11 + 2.0*W_12 + 3.0*W_13 + 4.0*W_14
*W_21 + 2.0*W_22 + 3.0*W_23 + 4.0*W_24
*W_31 + 2.0*W_32 + 3.0*W_33 + 4.0*W_34
expand
a> expand(a + 2(b+2)^2 + 2a + 3(a+1))
6*a + 8*b + 2*b^2
subs
Performs subsitution.
a> subs(a^2+(b-2)^2, b=>a)
+ (-2 + a)^2
a> subs(a^2+(b-2)^2, b=>2)
a> subs(a^2+(b-2)^2, a=>2)
(-2 + b)^2
a> subs(a^2+(b-2)^2, a^2=>2)
(-2 + b)^2
a> subs(a^2+(b-2)^2, a=>2, b=>3)
diff
Peforms differentiation
a> diff(a + 2(b+2)^2 + 2a + 3(a+1), b)`
+ b)
SymEngine.jl
is licensed under MIT open source license.