From apinkus at xs4all.nl  Sun Jul 17 17:42:14 2005
From: apinkus at xs4all.nl (Ayal Pinkus)
Date: Sun, 17 Jul 2005 17:42:14 +0200
Subject: [Rd] Computer algebra in R - would that be an idea??
In-Reply-To: <0EE77E17-94B0-4DDD-A064-4BFD20F52638@xs4all.nl>
References: <C83C5E3DEEE97E498B74729A33F6EAEC01AD9A2B@DJFPOST01.djf.agrsci.dk>
	<1121429806.42d7a92eb6678@horde.scannet.dk>
	<17111.46789.226240.355911@stat.math.ethz.ch>
	<a06110400befe1c42c158@203.61.56.151>
	<971536df050716033614fd6e77@mail.gmail.com>
	<a06110401beffa70234a8@[10.1.1.4]>
	<670D7252-4A25-4179-AA28-D6974AE9904A@xs4all.nl>
	<x2zmslk2wl.fsf@turmalin.kubism.ku.dk>
	<0EE77E17-94B0-4DDD-A064-4BFD20F52638@xs4all.nl>
Message-ID: <43DBA23E-FACE-4EC6-A983-2ED0B3B157AF@xs4all.nl>


I forgot one API call, getting a potential error caused through  
evaluating the object.
And I forgot one argument needed for evaluating, the pointer to the  
environment.
Ayal


On Jul 17, 2005, at 5:29 PM, Ayal Pinkus wrote:

>
> Hi,
>
>
>>
>> The thing that I wonder is whether it would be possible to embed  
>> Yacas
>> at a lower level than via the parser. E.g. the Tcl embedding has
>> Tcl_EvalObjEx() and friends, which operate on preparsed Tcl objects.
>> Using this instead of Tcl_Eval() gives some efficiency gain, but more
>> importantly, it avoids the "quoting hell" associated with the
>> construction of the relevant command strings.
>>
>>
>
> Interesting. You are not the first person asking this, actually.
>
> I chose for the C API as it is nice and clean, no name mangling issues
> while switching to a new gcc compiler, and it allows people to use it
> from C also. Back then, I thought all people would want to do is  
> send a
> string and receive one back.
>
>
>
>> Since both R and Yacas are "Lisp under the hood" languages (and Tcl
>> too for that matter), it is a fairly good guess that their parse  
>> trees
>> are similar, and that it would be a fairly simple task to translate
>> back and forth between them. Well, between suitable subsets, at  
>> least.
>> R's parse trees can in principle contain arbitrary R objects, but in
>> this context, we might only need constants, names, operators, and
>> function calls.
>>
>>
>
>
> Very true. The code to chain up the linked list itself would not be  
> very
> little code, but we could iron out an initial API of course. It could
> even
> be through a C interface that returns void*.
>
> Yacas can Already read a Lisp-style representation, to wit:
>
>      In> FromString("(foo(List a b))")LispRead()
>      Out> foo({a,b})
>
> but that would not help you much as you mention you'd like to avoid
> quoting hell.
>
>  From a C perspective, an API could look like this:
>
>      // Creating objects
>      void* yacas_create_atom(char* atom);
>      void* yacas_create_string(char* string);
>      void* yacas_create_number_from_string(char* string);
>      void* yacas_create_number_from_long(long number);
>      void* yacas_create_number_from_double(double number);
>      void* yacas_create_sublist(void* object);
>
>      // Linking linked lists
>      void yacas_link_objects(void* head, void* tail);
>
>      // executing an object
>      void* yacas_execute(void* object);
>
>      // pulling apart an object again
>      void* yacas_get_sublist(void* object);
>      char* yacas_get_atom(void* object);
>      char* yacas_get_string(void* object);
>      int  yacas_object_is_string(void* object);
>      int  yacas_object_is_atom(void* object);
>      int  yacas_object_is_number(void* object);
>      int  yacas_object_is_integer(void* object);
>      long yacas_get_long(void* object);
>      long yacas_get_double(void* object);
>
> Note in the above list you would only really need get_sublist and
> get_atom,
> but using the others might be more efficient.
>
>
>
>> It is probably not quite as easy as it sounds (is it ever?) but it
>> could be worth it anyway. The main thing that it would require is an
>> extended Yacas API which allows you to create Yacas objects from C
>> code.
>>
>>
>
>
> Apart from the above API, which I could create and would not take too
> long,
> there is of course the task of converting, in the sense that the
> semantics
> of R trees will be different from the semantics of the Yacas tree.
>
> The other alternative is OpenMath, but that is just too verbose. I
> don't like
> xml-like schemes myself, as it is a very inefficient way of doing  
> this.
>
> Do you have cvs, and the possibility to compile under Windows?
> Ayal
>
>
>
>     [[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>



[Rd] Computer algebra in R - would that be an idea??
Ayal Pinkus