SymEngine Quick Start


This vignette contains some basic code snippets for use with the symengine package.

It is currently in progress!

Construct symbolic expressions

Create symbol x from a string.

## (Symbol) x

Parse an expression from a string

## (Pow)    (x + 2*y)^3

Manipulating symbolic expressions

Expand an expression

## (Add)    -42 + 2*x*y + 2*x*z + 2*y*z + x^2 + y^2 + z^2

Substitute variables

## (Add)    -42 + (a + x + x^2)^2

Compute derivatives

## (Mul)    6*cos(y)*(x + 2*sin(y))^2

Solve a polynomial equation

## VecBasic of length 1
## V( -a )

Construct vector and matrix

Construct a vector with c

## VecBasic of length 3
## V( x, x + y, x + y - z )

Construct a vector with Vector

## VecBasic of length 3
## V( x, x + y, x + y + z )

Construct a symbolic matrix with Matrix

## DenseMatrix of dim 2 x 3
## [x_11, x_13, x_12]
## [x_22, x_21, x_23]

Construct a symbolic matrix with rbind

## DenseMatrix of dim 2 x 3
## [x, y, z]
## [-1 + x**2, -1 + y**2, -1 + z**2]

Numerically evaluate symbolic expressions

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