Rupert Swarbrick <rswarbrick <at> gmail.com> writes:
>
> Mohamed Rayes <rayes.o.mohamed <at> gmail.com> writes:
> > I have compiled maxima with ABCL as described in
> > http://comments.gmane.org/gmane.lisp.armedbear.devel/2365. I even
> > successfully ran a java program that calls maxima $Factors. The
> > program is listed at the end of this message.
> >
> > I tried calling the $DIFF (as in $DIFF(sin(x),x)) function in the
> > following way:
> >
> > 1- manually translated sin(x) to maxima internal rep: sin(x) ==> ((%sin) $x)
> > 2- calling $Diff:
> >
> > Interpreter I = Interpreter.createInstance ();
> > I.eval ("(require 'asdf)");
> > I.eval ("(asdf:operate 'asdf:load-op :maxima)");
> > Package P = Packages.findPackage ("MAXIMA");
> > LispObject exp = I.eval("'(%SIN) $x)");
> > LispObject x = I.eval("'$x");
> > Symbol S = P.findAccessibleSymbol ("$DIFF");
> > Function F = (Function) S.getSymbolFunction ();
> > LispObject result = F.execute(exp,p);
> >
> > I keep getting the error that $DIFF was not found?
> >
> > Thanks for all the help.
>
> Ah, I see. I haven't used ABCL, but what you've pasted here looks
> plausible (in particular, you've got the case of $DIFF correct in the
> code). Can you post the actual error you're getting? One of us might be
> able to help more.
>
> Once you've got hold of the $DIFF function, I'm also not sure that your
> two "eval" lines are going to work. You see, you haven't told the
> interpreter "I" to change the current package to MAXIMA. As such, I
> think that
>
> LispObject x = I.eval("'$x");
>
> will work by first reading the string "'$x" to the lisp form
>
> (QUOTE CL-USER::$X)
>
> and then evaluating, to get the symbol CL-USER::$X. However, you want
> the symbol MAXIMA::$X. Presumably the Interpreter object has a method to
> change package?
>
> Rupert
>
>
> _______________________________________________
> Maxima mailing list
> Maxima <at> math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>
Hello Rupert.
I tried to find a way to tell the interpreter "I" to switch packages as you
suggested, but to no avail. I am including the complete program here for any one
who would like to kindly help with finding why the program does not return the
desired result.
import org.armedbear.lisp.Function;
import org.armedbear.lisp.Interpreter;
import org.armedbear.lisp.LispObject;
import org.armedbear.lisp.Package;
import org.armedbear.lisp.Packages;
import org.armedbear.lisp.Symbol;
public class ABCL_maxima_Diff_example {
public static void main(String[] args) throws Exception {
Interpreter I = Interpreter.createInstance();
System.out.print("loading Maxima ... ");
I.eval("(require 'asdf)");
I.eval("(asdf:operate 'asdf:load-op :maxima)");
System.out.println("finished.");
Package P = Packages.findPackage("MAXIMA");
Symbol intsym = P.findAccessibleSymbol("$DIFF");
Function F = (Function) intsym.getSymbolFunction();
System.out.print(F.princToString() + " was found ");
LispObject sin_exp = I.eval("'((%SIN) $X)");
LispObject x = I.eval("'$X");
LispObject result = F.execute(sin_exp, x);
System.out.println(x.printObject());
System.out.println(x.princToString());
System.out.println(sin_exp.printObject());
System.out.println(sin_exp.princToString());
System.out.println(result.printObject());
System.out.println(result.princToString());
}
}
The program outputs:
$X
$X
((%SIN) $X)
((%SIN) $X)
((MAXIMA::%DERIVATIVE MAXIMA::SIMP) ((%SIN) $X) $X 1)
((%DERIVATIVE SIMP) ((%SIN) $X) $X 1)
The correct output would be ((%cos simp) $X).
I also tried different variations such as (sdiff '((%sin) $x) '$x) and
meval on (($diff) ((%sin ) $x) $x 1) and did not get the desired result.
Any help with this will be highly appreciated.
Mohamed