Learn R Programming

⚠️There's a newer version (2.1.1) of this package.Take me there.

caracas: Computer algebra in R

Installation

caracas is available on CRAN and can be installed as usual:

install.packages('caracas')

To build and install from Github with vignettes run this command from within R (please install remotes first if not already installed):

# install.packages('remotes')
remotes::install_github("r-cas/caracas", build_vignettes = TRUE)

You can also install the package without vignettes if needed as follows:

remotes::install_github("r-cas/caracas")

Development site

See https://github.com/r-cas/caracas.

Online documentation

See https://r-cas.github.io/caracas/.

Origin of name

The name “caracas” is intended to mean “(inter)face to computer algebra system(s)” - notice that “cara” is Spanish (Castellano to be precise) for “face”.

Code of conduct

Please note that the caracas project is released with a Contributor Code of Conduct (available in CODE_OF_CONDUCT.md). By contributing to this project, you agree to abide by its terms.

Brief introduction

library(caracas)
x <- symbol('x')
eq <- 2*x^2 - x
eq
#> [caracas]:    2    
#>            2⋅x  - x
as.character(eq)
#> [1] "2*x^2 - x"
as_r(eq)
#> expression(2 * x^2 - x)
tex(eq)
#> [1] "2 x^{2} - x"
solve_sys(eq, x)
#> Solution 1:
#>   x =  0 
#> Solution 2:
#>   x =  1/2
der(eq, x)
#> [caracas]: 4⋅x - 1
subs(eq, x, "y")
#> [caracas]:    2    
#>            2⋅y  - y
A <- matrix(c("x", 2, 0, "2*x"), 2, 2)
B <- as_symbol(A)
B
#> [caracas]: ⎡x   0 ⎤
#>            ⎢      ⎥
#>            ⎣2  2⋅x⎦
Binv <- inv(B)
Binv
#> [caracas]: ⎡ 1      ⎤
#>            ⎢ ─    0 ⎥
#>            ⎢ x      ⎥
#>            ⎢        ⎥
#>            ⎢-1    1 ⎥
#>            ⎢───  ───⎥
#>            ⎢  2  2⋅x⎥
#>            ⎣ x      ⎦
tex(Binv)
#> [1] "\\left[\\begin{matrix}\\frac{1}{x} & 0\\\\- \\frac{1}{x^{2}} & \\frac{1}{2 x}\\end{matrix}\\right]"
eigen_val(Binv)
#> [[1]]
#> [[1]]$eigval
#> [caracas]: 1
#>            ─
#>            x
#> 
#> [[1]]$eigmult
#> [1] 1
#> 
#> 
#> [[2]]
#> [[2]]$eigval
#> [caracas]:  1 
#>            ───
#>            2⋅x
#> 
#> [[2]]$eigmult
#> [1] 1

Please find more examples in the other vignettes available at https://r-cas.github.io/caracas/.

Copy Link

Version

Install

install.packages('caracas')

Monthly Downloads

610

Version

1.0.1

License

GPL

Issues

Pull Requests

Stars

Forks

Maintainer

Mikkel Andersen

Last Published

May 21st, 2020

Functions in caracas (1.0.1)

determinant.caracas_symbol

Calculate the Determinant of a Matrix
der

Symbolic differentiation of an expression
expand_log

Expand a logarithmic expression
as_character_matrix

Get matrix as character matrix
solve_sys

Solves a system of non-linear equations
sumf

Sum of a function
as.character.caracas_symbol

Convert symbol to character
[.caracas_symbol

Extract or replace parts of an object
expand

Expand expression
diag<-.caracas_symbol

Replace diagonal
symbol

Create a symbol
intf

Integrate a function
diag.caracas_symbol

Matrix diagonal
diag<-

Replace matrix diagonal
dim.caracas_symbol

Dimensions of a caracas symbol
as_symbol

Convert object to symbol
Ops.caracas_symbol

Math operators
doit

Perform calculations setup previously
Math.caracas_symbol

Math functions
eigen_val

Eigenvalues
%*%.caracas_symbol

Matrix multiplication
der2

Symbolic differentiation of second order of an expression
have_sympy

Check if 'SymPy' is available
sympy_version

Get 'SymPy' version
[<-.caracas_symbol

Extract or replace parts of an object
limf

Limit of a function
eigen_vec

Eigenvectors and eigenvalues
expand_trig

Expand a trigonometric expression
inv

Find inverse of matrix
sum.caracas_symbol

Summation
%*%

Matrix multiplication
simplify

Simplify expression
eval_to_symbol

Create a symbol from a string
t.caracas_symbol

Transpose of matrix
diag

Matrix diagonal
print.caracas_solve_sys_sol

Print solution
print.caracas_symbol

Print symbol
install_sympy

Install 'SymPy'
get_sympy

Access 'SymPy' directly
solve_lin

Solve a linear system of equations
prodf

Product of a function
tex

Export object to TeX
subs

Substitute symbol for value
subs_lst

Substitute symbol for of value given by a list
as_r

Convert caracas object to R