Learn R Programming

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

Ryacas

Ryacas is an R interface to the free yacas Computer Algebra System. Ryacas allows one to send R expressions, unprocessed yacas strings and certain other R objects to yacas process from R and get back the result. It also has facilities for manipulating yacas strings and R expressions destined for yacas processing.

It can be used for exact arithmetic, symbolic math, ASCII pretty printing and translating R to TeX.

Install from GitHub

To build and install from github using R 3.3.0 (or later) and the R devtools package 1.11.0 (or later) run this command from within R:

devtools::install_github("mikldk/ryacas")

Online info

For vignettes, overview, pointers to additional information, installation instructions and a sample session see http://mikldk.github.io/ryacas/.

Yacas documentation can be found at http://yacas.readthedocs.org/.

Brief examples

Below we show a few examples. We highly recommend reading the “Getting started” vignette (and the other vignettes) for a more thorough introduction to the package.

Low-level interface

Returning strings with yac_str():

yac_str("x+x+x+x")
#> [1] "4*x"
yac_str("Factor(x^2+x-6)")
#> [1] "(x-2)*(x+3)"
yac_str("D(x) x^2+x-6")
#> [1] "2*x+1"

Returning R expressions with yac_expr():

yac_expr("x+x+x+x")
#> expression(4 * x)
eval(yac_expr("x+x+x+x"), list(x = 4))
#> [1] 16
yac_expr("Factor(x^2+x-6)")
#> expression((x - 2) * (x + 3))
yac_expr("D(x) x^2+x-6")
#> expression(2 * x + 1)

Using functions easier (using magrittr’s pipe, %>%):

"x^2+x-6" %>% y_fn("Factor") %>% yac_str()
#> [1] "(x-2)*(x+3)"
"x^2+x-6" %>% y_fn("D(x)") %>% yac_expr()
#> expression(2 * x + 1)

Solving equations (removes the x== from yacas with the y_rmvars() function):

sol <- yac_str("Solve(x^2+x-6 == 0, x)")
sol
#> [1] "{x==2,x==(-3)}"
sol %>% y_rmvars() %>% yac_str()
#> [1] "{2,-3}"
sol %>% y_rmvars() %>% yac_expr()
#> expression(c(2, -3))
sol %>% y_rmvars() %>% yac_expr() %>% eval()
#> [1]  2 -3

And output in TeX:

"3/4 + Pi/8" %>% y_fn("Simplify") %>% y_fn("TeXForm") %>% yac_str()
#> [1] "\\frac{\\pi  + 6}{8} "

And arbitrary precision (see also the “Arbitrary-precision arithmetic” vignette):

yac_str("N(Pi, 50)")
#> [1] "3.1415926535897932384626433832795028841971693993751058209"

High-level interface

A brief example with a polynomial is:

x <- yac_symbol("x^2+x-6")
x
#> [1] x^2+x-6
y_fn(x, "Factor")
#> [1] (x-2)*(x+3)
x %>% y_fn("Factor")
#> [1] (x-2)*(x+3)
x %>% as_r()
#> expression(x^2 + x - 6)

A small matrix example follows:

A <- outer(0:3, 1:4, "-") + diag(2:5)
a <- 1:4
B <- yac_symbol(A)
B
#> {{ 1, -2, -3, -4},
#>  { 0,  2, -2, -3},
#>  { 1,  0,  3, -2},
#>  { 2,  1,  0,  4}}
b <- yac_symbol(a)
b
#> [1] {1,2,3,4}
y_fn(B, "Transpose")
#> {{ 1,  0,  1,  2},
#>  {-2,  2,  0,  1},
#>  {-3, -2,  3,  0},
#>  {-4, -3, -2,  4}}
y_fn(B, "Inverse")
#> {{   37/202,     3/101,    41/202,    31/101},
#>  {(-17)/101,    30/101,     3/101,     7/101},
#>  {(-19)/202,  (-7)/101,    39/202,  (-5)/101},
#>  { (-5)/101,  (-9)/101, (-11)/101,     8/101}}
y_fn(B, "Trace")
#> [1] 10
B %*% b
#> [1] {-28,-14,2,20}
t(B)
#> {{ 1,  0,  1,  2},
#>  {-2,  2,  0,  1},
#>  {-3, -2,  3,  0},
#>  {-4, -3, -2,  4}}
B[, 2:3]
#> {{-2, -3},
#>  { 2, -2},
#>  { 0,  3},
#>  { 1,  0}}
B %*% solve(B)
#> {{1, 0, 0, 0},
#>  {0, 1, 0, 0},
#>  {0, 0, 1, 0},
#>  {0, 0, 0, 1}}

Yacas

The package contains stripped-down yacas distribution. For the complete yacas source code see https://github.com/grzegorzmazur/yacas/ . For more information on yacas see http://www.yacas.org/ or the documention directly at https://yacas.readthedocs.io/. .


Mikkel Meyer Andersen, mikl at math dot aau dot dk
Rob Goedman, goedman at mac dot com
Gabor Grothendieck, ggrothendieck at gmail dot com
Søren Højsgaard, sorenh at math dot aau dot dk
Ayal Pinkus, apinkus at xs4all dot nl
Grzegorz Mazur, teoretyk at gmail dot com

Copy Link

Version

Install

install.packages('Ryacas')

Monthly Downloads

2,988

Version

1.0.0

License

GPL

Issues

Pull Requests

Stars

Forks

Maintainer

Mikkel Andersen

Last Published

August 29th, 2019

Functions in Ryacas (1.0.0)

Infinity

Legacy function
Subst

Legacy function
Ops.yac_symbol

Math operators
Newton

Legacy function
Set

Legacy function
Solve

Legacy function
%*%

Matrix multiplication
TeXForm

Legacy function
Transpose

Legacy function
Simplify

Legacy function
Limit

Legacy function
Conjugate

Legacy function
Integrate

Legacy function
PrettyPrinter

Legacy function
as_r

Convert yacas object to R
as.language

Legacy function
Math.yac_symbol

Math functions
N

Legacy function
PrettyForm

Legacy function
List

Legacy function
Ryacas-package

R interface to yacas computer algebra package
lower.tri

Lower and upper triangular part of a matrix
as.expression.Sym

Legacy function
Ryacas_options

Legacy function
yac_assign

Assign yacas variable
stripvar

Legacy function
solve.yac_symbol

Solve a system of equations
yac

Run yacas command
deriv

Legacy function
determinant

Legacy function
Taylor

Legacy function
Sym

Legacy function
yac_symbol

Make a yacas symbol
yacas

Legacy function
diag<-

Matrix diagonals
Inverse

Legacy function
y_ls

Legacy function
y_fn

Prepare simple yacas call
diag

Matrix diagonals
InverseTaylor

Legacy function
Pi

Legacy function
%>%

Pipe operator
as_y

Convert R vector/matrix to yacas vector (list) or matrix (list of lists)
as.expression.yacas

Legacy function
root

Legacy function
[.yac_symbol

Extract or replace parts of an object
t

t
dep_msg

Legacy function
yac_expr

Run yacas command returning R expression
syacas

Legacy function
yac_cli

yacas command line interface
[<-.yac_symbol

Extract or replace parts of an object
y_print

Pretty print yacas strings
y_rmvars

Remove/strip variable names
yacas_evaluate

Legacy function
Precision

Legacy function
set_output_width

Set width of yacas output
Ver

Legacy function
as.Sym

Legacy function
get_output_width

Get width of yacas output
getSyms

Legacy function
simplify

Simplify expression
yacmode

Legacy function
tex

Export object to TeX
yac_silent

Run yacas command silently
upper.tri

Lower and upper triangular part of a matrix
yac_str

Run yacas command returning string/character
Expand

Legacy function
Factorial

Legacy function
Expr

Legacy function
Exprq

Legacy function
Factor

Legacy function
I

Legacy function
Clear

Legacy function
Eval

Legacy function
Identity

Legacy function