axkr / symja_android_library

:coffee: Symja - computer algebra language & symbolic math library. A collection of popular algorithms implemented in pure Java.
https://matheclipse.org/
GNU General Public License v3.0
375 stars 84 forks source link

Expression not evaluated in script engine #187

Closed rjolly closed 4 years ago

rjolly commented 4 years ago

Trying to evaluate expressions with the JSR223 scripting engine (org.matheclipse.script.engine.MathScriptEngine), I get unevaluated results:

D[Sin[x],x] = Sin'[x]

Det[{{1,2},{3,4}}] = Det[{{1,2},{3,4}}]

Apart[(x)/(x^2-1)] = Apart[x/(-1+x^2)]

Formerly, what I was having is:

D[Sin[x],x] = Cos[x]

Det[{{1,2},{3,4}}] = -2

Apart[(x)/(x^2-1)] = 1/2(x+1)^(-1)+1/2(x-1)^(-1)

Any idea what is going wrong ?

(using the latest release symja_java8-2020-03-18.zip)

axkr commented 4 years ago

For the MMA syntax and that download you probably have to set the configuration flag PARSER_USE_LOWERCASE_SYMBOLS:

  Config.PARSER_USE_LOWERCASE_SYMBOLS = false;

the latest GIT sources are restructured, so there you have to set

  FEConfig.PARSER_USE_LOWERCASE_SYMBOLS = false;

Example:

import org.matheclipse.core.basic.Config;
import org.matheclipse.core.eval.EvalEngine;
import org.matheclipse.core.expression.F;
import org.matheclipse.core.interfaces.IExpr;
import org.matheclipse.parser.client.FEConfig;
import org.matheclipse.script.engine.MathScriptEngine;

public class MathScriptEngineExample {
    public static void main(String[] args) {
        Config.FILESYSTEM_ENABLED = true;
        FEConfig.PARSER_USE_LOWERCASE_SYMBOLS = false;
        EvalEngine engine = new EvalEngine();
        MathScriptEngine scriptEngine = new MathScriptEngine(engine);// fScriptManager.getEngineByExtension("m");
        scriptEngine.put("RELAXED_SYNTAX", Boolean.FALSE);
        try {
            // EvalEngine.set(engine);
            // engine.init();
            // engine.setRecursionLimit(256);
            // engine.setIterationLimit(500);
            System.out.println(scriptEngine.eval("D[Sin[x],x]"));

            System.out.println(scriptEngine.eval("Det[{{1,2},{3,4}}]"));

        } catch (Exception rex) {
            rex.printStackTrace();
        }
    }
}
rjolly commented 4 years ago

Thank you. I am just going to edit my sample : https://meditorworld.appspot.com/matheclipse.txt (departing from the engine default config is not easy for me, as my app accepts many plugable engines like jython etc.) One more question : do you plan to release matheclipse-core in maven central at some point ? Thanks

axkr commented 4 years ago

As far as I now for Maven Central all dependencies also have to be on a central repository? That's not the case at the moment. I also have to copy all patched versions of third party libs which are used in my own namespace.

FAQ and common mistakes:

I think a separate issue (from some Maven experts?) should outline all steps which are necessary to create release on Maven Central.

rjolly commented 4 years ago

Yes, all the dependencies have to be on maven central too. Too bad it's not the case ! I was asking, because my software "linoleum" uses it as its install system (like android market, but for normal Java, sort of) so if something is not on it, then it can't be installed (at least with the default mechanism). Are every dependencies mandatory for the core interpreter ? Can't it be modularized further ? Would it be possible to have the maintainers of the dependencies to integrate your patches ? Nothing urgent/important, it's just that it would integrate nicely with my math software.