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();
}
}
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);
}
}
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;
}
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";
}
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();
}
}
Aggregations