Calling Maxima $diff from java



Richard Fateman <fateman <at> eecs.berkeley.edu> writes:

> 
> I find this pretty hard to believe... that all this is necessary.
> Can you achieve your goal by just transmitting  the string to a running 
> maxima,
> 
> "diff(sin(x),x);"
> and getting the answer as a string?
> 
> I would not do what you seem to be doing at all this way. I would just 
> write the
> calling program in lisp, too.   But if you must use Java...
> 
> Perhaps you can load the java program into the lisp, in which case you
> should be able to do almost anything.
> 
> Or if my advice so far is of no use, perhaps this next piece will help.
> The program you want may be sdiff;  I don't know why $diff is not 
> accessible.
> 
> That is   (sdiff '((%sin) $x)  '$x)
> 
> returns ((%cos simp) $x)
> 
> although $diff seems to work ok, in lisp if you call it the right way.
> 
> RJF
> 

Hi Richard,

Calling maxima with "diff(sin(x),x);" would work, but will return
a 2D output string which is very difficult to manipulate or process 
in java program. 

Also, having java programs call maxima could open new application areas 
where maxima could be used as back-end computing engine. Loading java 
program into lisp will be probably work although I did not try it.

As for the example of Diff(sin(x),x) that I posted in my first message the code

Interpreter I = Interpreter.createInstance ();

I.eval ("(require 'asdf)");

I.eval ("(asdf:operate 'asdf:load-op :maxima)");

Package P = Packages.findPackage ("MAXIMA");

Symbol S = P.findAccessibleSymbol ("$DIFF");

Function F = (Function) S.getSymbolFunction ();

does indeed find the function $DIFF, but the statements

LispObject exp = I.eval("'(%SIN) $x)");

LispObject x = I.eval("'$x");

LispObject result = F.execute(exp,p);
 
return 

((%DERIVATIVE SIMP) ((%SIN) $X) $X 1)
instead of 

((%cos simp) $x)?

Thanks for the help.


PS. For those who do not know, Professor Richard J. Fateman is one of the 
major contributors to Macsyma (now maxima) and many of his thesis work has 
been translated into many algorithms used by maxima and other computer algebra
systems.