[Rd] Computer algebra in R - would that be an idea??
Peter Dalgaard
p.dalgaard at biostat.ku.dk
Fri Jul 15 15:25:01 CEST 2005
Rob J Goedman <goedman at mac.com> writes:
> A really simple way to play with R & yacas is by using the examples
> in the subdir
> 'embed' of yacas-1.0.57.
>
> After building yacas (on Mac OS in my case):
>
> > res<-system("~/Projects/yacas-1.0.57/embed/example2", intern=T)
> > res
> [1] "Cos(x);"
>
> or
>
> > res<-system("~/Projects/yacas-1.0.57/embed/example1 'D(x){{Sin
> (x),Cos(x)}, {Sin(2*x),-Cos(x)}}'", intern=T)
> > res
> [1] "Input> D(x){{Sin(x),Cos(x)}, {Sin(2*x),-Cos(x)}}"
> [2] "Output> {{Cos(x),-Sin(x)},{2*Cos(2*x),Sin(x)}};"
>
> or
>
> > system("yacas -pc --execute '[Echo(D(x)Sin(x));Exit();]'")
> Cos(x)
>
> or
>
> > system("echo 'Example()' | yacas_client")
> In> Example()
> Current example : Integrate(x,a,b)Sin(x);
>
> Integrate a function.
>
> Out> Cos(a)-Cos(b)
> In>
> > system("echo 'Type(%)' | yacas_client")
> In> Type(%)
> Out> "-"
> In>
>
> This last example does show the yacas server stays alive between
> calls from R. yacas_client is a script.
> Maybe that approach also works for maxima?
>
> I wonder how difficult it would be to translate expressions back and
> forth from R to yacas in either R
> or C++. And maybe strip 'In>' and 'Out>' like parts.
You could also just do what those examples do and embed the whole
enchillada in R. The slightly bad news is that the yacas_eval
interface is text-based, which means that to handle an R expression
via yacas you're going through a deparse-parse-operate-deparse-parse
sequence. It would be nicer if you could just convert parse trees
between the two languages. The good news is that there's a Lisp route
(see example3), which should make the parser/deparser coding somewhat
easier.
--
O__ ---- Peter Dalgaard Øster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-devel
mailing list