On 3/26/2013 12:38 PM, Mohamed Rayes wrote:
> 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.
This is very easy to solve. display2d:false makes it come out
llinearly, eg. x^2 looks like "x^2".
A better solution might be to do ?print(....);
in which case the expression is displayed as lisp. e.g. ((mexpt simp) $x 2)
That is, if the Java program is doing anything with the result from
Maxima that
needs parsing etc.
> Also, having java programs call maxima could open new application areas
> where maxima could be used as back-end computing engine.
Using it via a port seems to work. However I truly doubt the utility of
using Java
(compared to Lisp) because the first thing you have to do with any
non-trivial
application is write a program (in Java) to parse the output of
Maxima... either the
1d strings or the lisp version. So you have to write a parser and/or a
"lisp reader".
Neither of these is necessary if you write in Lisp.
Next, assuming you are somehow making sense of symbolic stuff in your Java
program (that is, you aren't just printing it out), the Java program
needs to know
how to construct and take apart the trees that are used to build algebraic
expressions.
These are not necessary if you write in Lisp.
> 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.
Instead, call the lisp function meval on (($diff) ((%sin ) $x) $x 1)
RJF