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