This vignette contains some basic code snippets for use with the symengine
package.
It is currently in progress!
x
from a string.<- Symbol("x")
x x
## (Symbol) x
<- S("(x + 2*y)^3")
expr expr
## (Pow) (x + 2*y)^3
use_vars(x, y, z, .quiet = TRUE)
<- (x + y + z) ^ 2L - 42L
expr expand(expr)
## (Add) -42 + 2*x*y + 2*x*z + 2*y*z + x^2 + y^2 + z^2
<- (x + y + z) ^ 2L - 42L
expr <- subs(expr, z, S("a"))
expr <- subs(expr, y, x^2L)
expr expr
## (Add) -42 + (a + x + x^2)^2
use_vars(x, y, .quiet = TRUE)
<- (x + 2L*sin(y))^3L
expr D(expr, y)
## (Mul) 6*cos(y)*(x + 2*sin(y))^2
<- Symbol("a")
a <- x^2L + 2L*a*x + a^2L
poly solve(poly, x)
## VecBasic of length 1
## V( -a )
c
use_vars(x, y, z, .quiet = TRUE)
<- c(x, x + y, x + y - z)
vec vec
## VecBasic of length 3
## V( x, x + y, x + y - z )
Vector
<- list(x, x + y, x + y + z)
lst Vector(lst)
## VecBasic of length 3
## V( x, x + y, x + y + z )
Matrix
<- paste0("x_", rep(1:2, 3), rep(1:3, 2))
nms Matrix(nms, nrow = 2)
## DenseMatrix of dim 2 x 3
## [x_11, x_13, x_12]
## [x_22, x_21, x_23]
rbind
<- Vector(x, y, z)
vec rbind(vec, vec^2L-1L)
## DenseMatrix of dim 2 x 3
## [x, y, z]
## [-1 + x**2, -1 + y**2, -1 + z**2]
<- x^y + exp(x)
expr <- as.function(expr)
func func(x = 1:10, y = 2)
## [1] 3.718282 11.389056 29.085537 70.598150 173.413159
## [6] 439.428793 1145.633158 3044.957987 8184.083928 22126.465795
<- options(symengine.latex = TRUE, symengine.latex.center = TRUE) old_options
use_vars(x, y, .quiet = TRUE)
sqrt(x + y)
\[ \sqrt{x + y} \]
options(old_options)