Symbolic computation in R?

I was wondering if it is possible to do symbolic computation in R?

For example,

I was hoping to get the inverse of a symbolic covariance matrix of 3D Gaussian distribution.

Also can I do symbolic integration and differentiation in R?

Yes. There is the Ryacas package which is hosted on Google Code here. Ryacas has recently been expanded/converted to the rMathpiper package which is hosted here. I have used Ryacas and it is straightforward, but you will need to install Yacas in order for it to work (Yacas does all the heavy lifting; Ryacas is just an R interface to Yacas).

There is also the rSymPy project hosted on Google Code here. I haven't tried this one. The idea is similar, though, link to the sympy CAS which does the symbolic work.

Some things are also in base R --- see help(deriv) or help(D).

A simple example from that help page:

R> trig.exp <- expression(sin(cos(x + y^2)))
R> ( D.sc <- D(trig.exp, "x") )
-(cos(cos(x + y^2)) * sin(x + y^2))
R>      all.equal(D(trig.exp[], "x"), D.sc)
 TRUE
R>

It makes more sense to use a "real" CAS like Maxima.

• Well the original question was about R though. Nov 21 '10 at 18:42