27
votes
$\begingroup$

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?

$\endgroup$
22
votes
$\begingroup$

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.

$\endgroup$
19
votes
$\begingroup$

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[[1]], "x"), D.sc)
[1] TRUE
R> 
$\endgroup$
6
votes
$\begingroup$

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

$\endgroup$
1
  • 12
    $\begingroup$ Well the original question was about R though. $\endgroup$ Nov 21 '10 at 18:42

Not the answer you're looking for? Browse other questions tagged or ask your own question.