[Rd] Computer algebra in R - would that be an idea??
Rob J Goedman
goedman at mac.com
Fri Jul 15 06:39:01 CEST 2005
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.
Rob
On Jul 14, 2005, at 5:21 PM, Søren Højsgaard wrote:
> Perhaps, this is the wrong mailing list, but I've been thinking
> about calling e.g. maxima from R through some kind of wrapper. On
> windows, maxima can be invoked through a file called maxima.bat
> which opens a simple 'dos terminal' in which maxima is running. A
> simple way of interfacing R and maxima would be through a function
> which 'copies' a text string into such a dos terminal with maxima
> running and copies the output back into R. That particular task is
> something which one might want to be able to do with several other
> programs too... A way of doing this would be through the system()
> and/or shell() functions where input and output can be redirected
> to/from the program called, e.g. maxima. The problem is, that system
> ()/shell() will start maxima, execute the submitted code and
> terminate maxima. As I understand it, RDCOMClient provides a way of
> getting a 'handle' on such a program provided that the program is
> written in a specific way - something to do with COM. However, I
> wonder if it would be possible to write a general R function, (e.g.
> called dynamicshell()) which would provide a handle on such an
> application and to which one could send commands and retrieve
> output without shutting the application down. That is, essentially,
> a programatic form of 'copy and paste' in two directions... Is
> there anything in the way R is constructed that prevents that such
> a function could be written, and if so can anyone explain to me why
> and/or point me to a reference explaining why.
>
> Best regards
> Søren
>
> ________________________________
>
> Fra: Simon Blomberg [mailto:Simon.Blomberg at anu.edu.au]
> Sendt: on 13-07-2005 04:42
> Til: Gabor Grothendieck; Søren Højsgaard
> Cc: Duncan Murdoch; r-devel at stat.math.ethz.ch
> Emne: Re: [Rd] Computer algebra in R - would that be an idea??
>
>
>
> Another approach might be to construct a wrapper for Aldor code,
> along the
> lines of .Fortran and .C. Aldor is the extension language for AXIOM
> http://www.aldor.org/, and there is a symbolic algebra library
> available
> for Aldor http://www-sop.inria.fr/cafe/Manuel.Bronstein/algebra, which
> ships with the Aldor compiler. Of course, I am much better at
> thinking up
> these ideas than implementing them myself. :-)
>
> Simon.
>
>
> At 11:36 AM 13/07/2005, Gabor Grothendieck wrote:
>
>> I don't know which free system is best. I have mainly used Yacas
>> but my needs to date have been pretty minimal so I suspect
>> any of them would have worked.
>>
>> Eric's COM solution, once I have it figured out, will likely get me
>> to the next step on Windows. I did some googling around and
>> found this:
>>
>> http://www.koders.com/python/
>> fidDCC1B0FBFABC770277A28835D5FFADC9D25FF54E.aspx
>>
>> which is a python interface to Yacas which may give some ideas
>> on how to interface it to R.
>>
>>
>> On 7/12/05, Søren Højsgaard <Soren.Hojsgaard at agrsci.dk> wrote:
>>
>>> Personally, I like Maxima better than Yacas, but in both cases the
>>>
>> solution (at least a minimal one) should be doable: A small
>> program which
>> pipes R commands into a terminal running Maxima/Yacas and taking the
>> output back into R. I am not much into the technical details, but
>> isn't
>> that what can be done with the COM automatation server on
>> Windows?? (I
>> don't know what the equivalent would be on unix?).
>>
>>> Best regards
>>> Søren
>>>
>>> ________________________________
>>>
>>> Fra: Simon Blomberg [mailto:Simon.Blomberg at anu.edu.au]
>>> Sendt: on 13-07-2005 01:52
>>> Til: Duncan Murdoch; Gabor Grothendieck
>>> Cc: Søren Højsgaard; r-devel at stat.math.ethz.ch
>>> Emne: Re: [Rd] Computer algebra in R - would that be an idea??
>>>
>>>
>>>
>>> I would use such a symbolic math package for R. I have dreamt of an
>>> open-source solution with functionality similar to mathStatica.
>>> http://www.mathstatica.com/ Is yacas the best system to consider?
>>> What
>>> about Maxima http://maxima.sourceforge.net/, which is also GPL,
>>> or maybe
>>> Axiom http://savannah.nongnu.org/projects/axiom, which has a
>>> modified BSD
>>> license?
>>>
>>> Cheers,
>>>
>>> Simon.
>>>
>>> At 01:25 AM 13/07/2005, Duncan Murdoch wrote:
>>>
>>>> On 7/12/2005 10:57 AM, Gabor Grothendieck wrote:
>>>>
>>>>> On 7/12/05, Søren Højsgaard <Soren.Hojsgaard at agrsci.dk> wrote:
>>>>>
>>>>>>> From time to time people request symbolic computations beyond
>>>>>>> what
>>>>>>>
>>>> D() and deriv() etc can provide. A brief look at the internet
>>>> shows that
>>>> there are many more or less developed computer algebra packages
>>>> freely
>>>> available. Therefore, I wondered if it would be an idea to try to
>>>> 'integrate' one of these packages in R, which I guess can be
>>>> done in more
>>>> or less elegant ways... I do not know any of the computer
>>>> algebra people
>>>> around the World, but perhaps some other people from the R-
>>>> community do
>>>> and would be able to/interested in establishing such a
>>>> connection...
>>>>
>>>>>
>>>>>
>>>>> Coincidentally I asked the yacas developer about this just
>>>>> yesterday:
>>>>>
>>>>>
>>>>
>>>>
>> http://sourceforge.net/mailarchive/forum.php?
>> thread_id=7711431&forum_id=2216
>>
>>>>
>>>> It sounds like developing an R package to act as a wrapper would
>>>> be the
>>>> best approach. I didn't see documentation for their API (the
>>>> exports of
>>>> their DLL), but I didn't spend long looking.
>>>>
>>>> Duncan Murdoch
>>>>
>>>> ______________________________________________
>>>> R-devel at r-project.org mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>>
>>>
>>> Simon Blomberg, B.Sc.(Hons.), Ph.D, M.App.Stat.
>>> Centre for Resource and Environmental Studies
>>> The Australian National University
>>> Canberra ACT 0200
>>> Australia
>>> T: +61 2 6125 7800 email: Simon.Blomberg_at_anu.edu.au
>>> F: +61 2 6125 0757
>>> CRICOS Provider # 00120C
>>>
>>>
>>>
>>>
>>>
>>>
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
More information about the R-devel
mailing list