symengine is a R package for symbolic computation.
SymEngine library is a standalone fast symbolic manipulation library written in C++. It allows computation over mathematical expressions in a way which is similar to the traditional manual computations of mathematicians and scientists. The R interface of the library tries to provide a user-friendly way to do symbolic computation in R and can be integrated into other packages to help solve related tasks. The design of the package is somehow similar to the SymPy package in Python. Unlike some other computer algebra systems, it does not invent its own language or domain specific language but uses R language to manipulate the symbolic expressions.
symengine uses the S4 dispatch system extensively to differentiate between calculation
over normal R objects and symengine objects. For example, the semantics of
expr <- Symbol("x"); sin(expr) is different from the
sin used over normal R numbers.
Basic is simply a S4 class holding a pointer representing a symbolic expression
Basic objects have the same S4 class but can have different
C-level representations which can be accessed via
Basic(~ 1/2) will have "Rational" type and
Basic(1/2) will have
Basic object will also have a list of associated sub-components
which can be accessed via
get_args(). For example,
(expr <- S("x") * 3L * S("a"))
will have type "Mul", and
as.list(get_args(expr)) will show the three factors of
Basic object can be constructed via
VecBasic and DenseMatrix are S4 classes representing a symbolic vector or matrix.
They can be constructed with
cbind(). For example the following code will construct a 2x3 matrix.
The following functions are expected to work naturally with VecBasic and DenseMatrix classes.
[[<- for subsetting and assignment.
%*% for matrix multiplication
solve(a, b): solve
a %*% x = b where
a is a square DenseMatrix and
b is a VecBasic/DenseMatrix.
solve(a): find the inverse of
a is a square DenseMatrix.
solve(a, b): solve system of linear equations represented by
a (VecBasic) with
regards to symbols in
Further, the R functions that work on Basic objects (e.g.
sin) are expected work
on VecBasic and DenseMatrix objects as well in a vectorized manner.
The following is a (incomplete) list of functions that are expected to work with
symengine objects. Note that these functions can also be used inside a formula or
R language objects and passed to S or Basic or Vector to construct symengine
objects. For example
S(~ sin(x) + 1) and
S(quote(sin(x) + 1)).
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.