Search in sources :

Example 36 with EvalEngine

use of org.matheclipse.core.eval.EvalEngine in project symja_android_library by axkr.

the class AbstractTestCase method setUp.

/**
 * The JUnit setup method
 */
@Override
protected void setUp() {
    try {
        synchronized (fScriptManager) {
            ToggleFeature.COMPILE = true;
            IOInit.init();
            Config.SHORTEN_STRING_LENGTH = 80;
            Config.MAX_AST_SIZE = 20000;
            Config.MAX_MATRIX_DIMENSION_SIZE = 100;
            Config.MAX_BIT_LENGTH = 200000;
            Config.MAX_POLYNOMIAL_DEGREE = 100;
            Config.FILESYSTEM_ENABLED = false;
            fScriptEngine = fScriptManager.getEngineByExtension("m");
            fScriptEngine.put("PRINT_STACKTRACE", Boolean.TRUE);
            fScriptEngine.put("RELAXED_SYNTAX", Boolean.TRUE);
            fScriptEngine.put("DECIMAL_FORMAT", "0.0####");
            fNumericScriptEngine = fScriptManager.getEngineByExtension("m");
            fNumericScriptEngine.put("RELAXED_SYNTAX", Boolean.TRUE);
            F.await();
            EvalEngine engine = (EvalEngine) fScriptEngine.get("EVAL_ENGINE");
            EvalEngine.set(engine);
            engine.init();
            engine.setRecursionLimit(512);
            engine.setIterationLimit(500);
            engine.setOutListDisabled(false, (short) 10);
            EvalEngine numericEngine = (EvalEngine) fScriptEngine.get("EVAL_ENGINE");
            numericEngine.init();
            numericEngine.setRecursionLimit(512);
            numericEngine.setIterationLimit(500);
            numericEngine.setOutListDisabled(false, (short) 10);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : EvalEngine(org.matheclipse.core.eval.EvalEngine) IOException(java.io.IOException)

Example 37 with EvalEngine

use of org.matheclipse.core.eval.EvalEngine in project symja_android_library by axkr.

the class BasicPatternPropertiesTestCase method checkPriority.

public void checkPriority(String patternString, String priority) {
    try {
        EvalEngine engine = EvalEngine.get();
        ASTNode node = fParser.parse(patternString);
        IExpr pat = new AST2Expr(false, engine).convert(node);
        PatternMatcher matcher = new PatternMatcher(pat);
        assertEquals(Integer.toString(matcher.getLHSPriority()), priority);
    } catch (Exception e) {
        e.printStackTrace();
        assertEquals("0", priority);
    }
}
Also used : EvalEngine(org.matheclipse.core.eval.EvalEngine) ASTNode(org.matheclipse.parser.client.ast.ASTNode) IExpr(org.matheclipse.core.interfaces.IExpr) PatternMatcher(org.matheclipse.core.patternmatching.PatternMatcher) AST2Expr(org.matheclipse.core.convert.AST2Expr)

Example 38 with EvalEngine

use of org.matheclipse.core.eval.EvalEngine in project symja_android_library by axkr.

the class AJAXQueryServlet method evalTopLevel.

private static IExpr evalTopLevel(EvalEngine engine, final StringWriter buf, final IExpr parsedExpression) {
    IExpr result;
    EvalEngine[] engineRef = new EvalEngine[] { engine };
    result = ExprEvaluator.evalTopLevel(parsedExpression, engineRef);
    engine = engineRef[0];
    if ((result != null) && !result.equals(S.Null)) {
        OutputFormFactory.get(engine.isRelaxedSyntax()).convert(buf, result);
    }
    return result;
}
Also used : EvalEngine(org.matheclipse.core.eval.EvalEngine) IExpr(org.matheclipse.core.interfaces.IExpr)

Example 39 with EvalEngine

use of org.matheclipse.core.eval.EvalEngine in project symja_android_library by axkr.

the class MathScriptEngine method printResult.

private String printResult(IExpr result, boolean relaxedSyntax) {
    if (result.equals(S.Null)) {
        return "";
    }
    final StringWriter buf = new StringWriter();
    EvalEngine engine = EvalEngine.get();
    OutputFormFactory off;
    if (fDecimalFormat != null) {
        int significantFigures = engine.getSignificantFigures();
        off = OutputFormFactory.get(relaxedSyntax, false, significantFigures - 1, significantFigures + 1);
    } else {
        off = OutputFormFactory.get(relaxedSyntax);
    }
    if (off.convert(buf, result)) {
        // print the result in the console
        return buf.toString();
    }
    if (Config.FUZZ_TESTING) {
        throw new NullPointerException();
    }
    return "ScriptEngine: ERROR-IN-OUTPUTFORM";
}
Also used : StringWriter(java.io.StringWriter) EvalEngine(org.matheclipse.core.eval.EvalEngine) OutputFormFactory(org.matheclipse.core.form.output.OutputFormFactory)

Example 40 with EvalEngine

use of org.matheclipse.core.eval.EvalEngine in project symja_android_library by axkr.

the class MathScriptEngineExample method main.

public static void main(String[] args) {
    ToggleFeature.COMPILE = true;
    Config.SHORTEN_STRING_LENGTH = 80;
    Config.MAX_AST_SIZE = 20000;
    Config.MAX_MATRIX_DIMENSION_SIZE = 100;
    Config.MAX_BIT_LENGTH = 200000;
    Config.MAX_POLYNOMIAL_DEGREE = 100;
    Config.FILESYSTEM_ENABLED = true;
    ScriptEngineManager scriptManager = new ScriptEngineManager();
    ScriptEngine scriptEngine = scriptManager.getEngineByExtension("m");
    scriptEngine.put("PRINT_STACKTRACE", Boolean.TRUE);
    EvalEngine engine = (EvalEngine) scriptEngine.get("EVAL_ENGINE");
    EvalEngine.set(engine);
    try {
        engine.setRecursionLimit(512);
        engine.setIterationLimit(500);
        // the last 10 evaluations are memorized now
        engine.setOutListDisabled(false, (short) 10);
        System.out.println(scriptEngine.eval("D(sin(x),x)"));
        System.out.println(scriptEngine.eval("apart[(x)/(x^2-1)] == 1/(2*(-1+x))+1/(2*(1+x))"));
        System.out.println(scriptEngine.eval("Det[{{1,2},{3,4}}]"));
        System.out.println(scriptEngine.eval("f=10!"));
        System.out.println(scriptEngine.eval("f+f"));
        // the last 10 evaluations are memorized
        System.out.println(scriptEngine.eval("%+5"));
        // the following example will only work, if Maven module 'matheclipse-io' is on the classpath:
        String testIO = // 
        "SemanticImportString(\"Products,Sales,Market_Share\n" + "a,5500,3\n" + "b,12200,4\n" + "c,60000,33\n" + "\")";
        System.out.println(scriptEngine.eval(testIO));
    } catch (ScriptException e) {
        e.printStackTrace();
    }
}
Also used : ScriptException(javax.script.ScriptException) ScriptEngineManager(javax.script.ScriptEngineManager) EvalEngine(org.matheclipse.core.eval.EvalEngine) ScriptEngine(javax.script.ScriptEngine)

Aggregations

EvalEngine (org.matheclipse.core.eval.EvalEngine)131 IExpr (org.matheclipse.core.interfaces.IExpr)71 IAST (org.matheclipse.core.interfaces.IAST)39 IASTAppendable (org.matheclipse.core.interfaces.IASTAppendable)20 ISymbol (org.matheclipse.core.interfaces.ISymbol)20 IOException (java.io.IOException)13 F (org.matheclipse.core.expression.F)12 ExprEvaluator (org.matheclipse.core.eval.ExprEvaluator)11 S (org.matheclipse.core.expression.S)11 IInteger (org.matheclipse.core.interfaces.IInteger)11 ASTNode (org.matheclipse.parser.client.ast.ASTNode)11 LogManager (org.apache.logging.log4j.LogManager)10 Logger (org.apache.logging.log4j.Logger)10 AST2Expr (org.matheclipse.core.convert.AST2Expr)9 ExprParser (org.matheclipse.core.parser.ExprParser)9 IBuiltInSymbol (org.matheclipse.core.interfaces.IBuiltInSymbol)8 MathException (org.matheclipse.parser.client.math.MathException)8 ArrayList (java.util.ArrayList)7 Config (org.matheclipse.core.basic.Config)7 IASTMutable (org.matheclipse.core.interfaces.IASTMutable)7