View on GitHub

Ryacas

R to yacas interface

Download this project as a .zip file Download this project as a tar.gz file

Ryacas (github project name ryacas) is an R package that allows R users to access the yacas computer algebra system from within R. It can be used for computer algebra, exact arithmetic, ASCII pretty printing and R to TeX output. R, Ryacas and yacas are all free software packages distributed under the GPL and LGPL, respectively. See here or the package vignette for examples of yacas calculations performed from wihin R. Ryacas is available on CRAN now.

Readers should also note the availability of the rSymPy CRAN project which interfaces to the jython version of the sympy computer algebra system. Also rMathpiper provides an R interface to MathPiper (a modified java version of yacas).

NEWS

In addition to the NEWS items below see the NEWS file that comes with Ryacas. It is more focused on changes in the package itself than the news listed here.

TECHNOLOGY

Ryacas is written in R. It uses a recursive decent R-to-yacas translator and an XML-based OpenMath yacas-to-R translator. Yacas is accessed via a thin C++ wrapper generated by Rcpp.

SOURCE REPOSITORY

The git repository on GitHub (click on View on GitHub button above) contains the source code of Ryacas and generated PDF file for the vignette.

STATUS

Ryacas
The Ryacas package was developed several years ago and development has largely stopped (although a bug fix version was issued Feb 5, 2010) and now effort goes into the rMathpiper and rSymPy projects.
Yacas
Regarding yacas itself (as opposed to Ryacas), the original developer behind yacas appears to have left the yacas project. Just before he left he rewrote yacas in Java. Currently Alberto González Palomo continues to make improvements to the C version yacas although there have been no recent releases.
MathpiperIDE
The java version of yacas was adopted by the MathpiperIDE project in 2008 (which had been called Mathrider at the time and though the name has since been changed) and Ted Kosan has indicated that under the MathpiperIDE/Mathrider project he has forked the java version of yacas and he and Howard "Sherm" Ostrowsky have made 2,700 svn commits (from March 2008 to October 2009) of which about half were for Mathpiper (and the rest for Mathrider). The new name Mathpiper is used to distinguish it from the apparently unmaintained yacas.jar prior to the fork. (The original version of the java version of yacas is available on the yacas site).
Mathpiper
Mathpiper is located at http://mathpiper.googlecode.com. The mathpiper.jar file is located in the mathrider/jars directory in the !MathPiperIDE (formerly Mathrider) distribution which can be found at http://mathrider.org. The javadocs can be found here. One can launch the GUI console like this: java -jar mathpiper.jar One can launch the text console like this: java -cp mathpiper.jar org.mathpiper.ui.text.consoles.Console and one can launch the help application like this: java -cp mathpiper.jar org.mathpiper.ui.gui.help.FunctionTreePanel One significant new feature in Mathpiper is the ability to emit R code using the following command (which puts Mathpiper in a mode such that all code emitted is R): PrettyPrinter("RForm") This new feature was added to Mathpiper version 0.76t .

R INTERFACE

There are 8 interfaces. All of them are built on top of yacas.character:

  1. yacas.character. Pass a raw yacas character string to yacas function. e.g. yacas('x*x')
  2. yacas.expression. Pass an R expression to yacas function. e.g. yacas(expression(x*x))
  3. yacas.function. Pass an R function name which defines a one-line R function. e.g. f <- function(x) x*x; yacas(f)
  4. yacas.formula. Pass an R formula object whose right hand side will be regarded as an expression to pass to yacas.expression. e.g. yacas(~ x*x)
  5. Sym object. These objects are internally yacas strings. They can be combined with arithmetic operators The print method calls yacas. e.g. x <- Sym('x'); x*x
  6. Expr object. These objects are internally R expressions. They can be combined with artithmetic operators. e.g. x <- Exprq(x); x*x
  7. yacmode() which places the session in a mode where one can directly type in yacas commands.

EXAMPLES

Sample session

> library(Ryacas)
> # algebra
> x <- Sym('x')
> (x+1) * (x-1)
expression((x + 1) * (x - 1))
> Simplify("%")
expression(x^2 - 1)
PrettyForm("%")

 2 
x - 1

> # calculus
> Integrate(x+tan(x), x)
expression(x^2/2 - log(cos(x)))
> # exact arithmetic
> yacas('12/24')
expression(1/2)
> # ASCII pretty printing
> exp(-x^2)/(cos(x)+exp(x))
expression(exp(-x^2)/(cos(x) + exp(x)))
> PrettyForm("%")

     /  /  2 \ \   
  Exp\ -\ x  / /   
-------------------
Cos( x ) + Exp( x )

> # matrix - yacas matrices are row-wise
> List(List(1,2),List(x,6))
expression(list(list(1, 2), list(x, 6)))
> PrettyForm("%")

/              \
| ( 1 ) ( 2 )  |
|              |
| ( x ) ( 6 )  |
\              /

> # output TeX
> k <- Sym('k')
> yacas(TeXForm((x+1)^2 + k^3), retclass = 'unquote')
$\left( x + 1\right) ^{2} + k ^{3}$
>

Solving nonlinear equation

> library(Ryacas)
> Asym <- Sym("Asym"); xmid <- Sym("xmid"); scal <- Sym("scal")
> x <- Sym("x"); y <- Sym("y")
> Solve(Asym/(1+exp((xmid-x)/scal))==y, x)
expression(list(x == xmid - log(Asym/y - 1) * scal))

Sample calculus session

> library(Ryacas)
Loading required package: XML
>
> x <- Sym("x")
> h <- Sym("h")
>
> # limit
> Limit(1/(1-x), x, Infinity)
expression(0)
>
> # differentiation
> deriv(x^3, x)
expression(3 * x^2)
>
> # integration: indefinite and definite
> Integrate(x^3, x)
expression(x^4/4)
> Integrate(x^3, x, 0, 1)
expression(1/4)
>
> # mean value
> Limit((cos(x+h)-cos(x))/h, h, 0)
expression(-sin(x))
>
> # min/max
> Solve(deriv(x^2-x, x) == 0, x)
expression(list(x == 1/2))
>
> # continuity
> Limit(sin(x+h^2) - sin(x-h^2), h, 0)
expression(0)

More

Not all the facilities of yacas are built into Ryacas but its easy to add them yourself -- typically with one line of code. For example, here we add an interface to the Ryacas EigenValues function and run an example.

MORE INFORMATION

The R commands

library(Ryacas)
package?Ryacas

will display pointers to the help commands, vignette, home page, demos and THANKS, WISHLIST and NEWS files. These files, including pdf versions of the vignette, can also be found in the Source repository by clicking on the Source tab above.

TEAM

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

Contact Gabor if you need assistance, Rob if its Mac-related or Grzegorz if it's a yacas issue