Subject: Interface for Maxima in the my diploma project
From: Richard Fateman
Date: Mon, 12 Nov 2007 05:31:56 -0800
Because the English is unclear, it is not obvious what the original poster was being asked to do.
If you write another way for someone to write a C program to call Maxima, it would probably not be used by anyone else, and so it would at best be a way for you to learn how to do what other people already have done.
Since almost all Maxima systems run on LIsp systems which are implemented in C, there is nothing much needed for Maxima to call a C program.
So if you insert into Maxima a small C program that is "callMyCprogram()" then you are all set. to interface to C programs. This is probably a 5 line program, but differs in detail depending on which lisp you use.
If you call Maxima from some main() program in C, you must either have a very slender connection (e.g. a socket or stream) or you must initialize a lisp memory system, etc, and then call Maxima subroutines.
Someone "calling Maxima" in any serious manner (other than pasting over another front end) must deal with the issue of what to do with the return value of the Maxima call. This might be a lisp linked list, or perhaps a character string representing an expression or a number.
If it must be a number, then your link to Maxima is of virtually no interest to symbolic computation. You are using this huge (and not necessarily efficient) machine to compute numbers, and avoiding the wonderful possibilities of the rest of it.
So you must deal with expressions or strings. And to do so in any non-trivial way you must parse them. So you must write a parser, in C, for Maxima output.
What a waste of time... the Lisp version is already parsed. Maxima has a parser, but in your C-centric world you would rather write another one than use one is lisp.
In the link-list return case, you must write a simple Lisp system to deal with the linked lists.
Again, why not use the lisp? Just because you know the C language and don't know lisp does not make it sensible for you to write a lisp system in C, unless this is your idea of fun.
The reality is, I think that there are two plausible places for a C interface.
1. Let Maxima call a C library, for example, for numerics, or interface to operating system.
2. Set up a front end that does not understand much about Maxima, except perhaps display, and connect Maxima to it.
Providing a connection from a C library to do something like "factor a polynomial" or "symbolic integration" tends to be pointless because the C library would have to figure out what to do with the answer, as pointed out above.
There are simple C libraries to do well-specified tasks on simple data structures ... e.g. factor a univariate polynomial and leave the coefficients in an array of arrays. Ginac for example.
Ginac "is not a computer algebra system:...
There are also examples of interfaces such as SAGE, TeXmacs, Scientific Workplace, which are supposed to support many different systems through a single front end. The claim is (sort of) that you can use N different systems but only have to learn one. There may be some truth to this, but my experience is that it you are probably not interested in all N systems, but M<N systems. And to use this new interface you must learn one more (i.e. M+1, total), So the savings is hard to realize. Building such an omnibus system can be educational, and there is a long history of this kind of CAS going back at least to the time of Scratchpad at IBM (circa 1970). And if you want to encompass all of mathematics in a single unified program, building such a connecting system seems like a better plan than writing all of this over again -- who wants to write a huge system from scratch? But it is nevertheless problematical. Who is in charge of interrupts? How can you make sense of N d
ocumentation systems? Version control is difficult. etc .
Writing a program with a new mathematical capability might be more useful to the system effort, though perhaps not interesting as a project if you do not know much math, and /or only want to write another GUI.
RJF