use of org.matheclipse.core.eval.EvalEngine in project symja_android_library by axkr.
the class Functors method rules.
/**
* Create a functor from the given rules. All strings in <code>strRules</code> are parsed in
* internal rules form.
*
* @param strRules array of rules of the form "<code>x->y</code>"
* @return
*/
public static Function<IExpr, IExpr> rules(String[] strRules) {
IASTAppendable astRules = F.ListAlloc(strRules.length);
final EvalEngine engine = EvalEngine.get();
ExprParser parser = new ExprParser(engine);
for (String str : strRules) {
IExpr expr = parser.parse(str);
expr = engine.evaluate(expr);
astRules.append(expr);
}
return rules(astRules, engine);
}
use of org.matheclipse.core.eval.EvalEngine in project symja_android_library by axkr.
the class SerializableTest method testEvalEngine.
public void testEvalEngine() {
try {
EvalEngine engine = EvalEngine.get();
engine.evaluate("x=10");
Context context = engine.getContextPath().getGlobalContext();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(context);
byte[] bArray = baos.toByteArray();
baos.close();
oos.close();
ByteArrayInputStream bais = new ByteArrayInputStream(bArray);
ObjectInputStream ois = new ObjectInputStream(bais);
Context copy = (Context) ois.readObject();
bais.close();
ois.close();
engine.getContextPath().setGlobalContext(copy);
IExpr result = engine.evaluate("x");
assertEquals("10", result.toString());
} catch (ClassNotFoundException cnfe) {
cnfe.printStackTrace();
assertEquals("", cnfe.toString());
} catch (IOException ioe) {
ioe.printStackTrace();
assertEquals("", ioe.toString());
}
}
use of org.matheclipse.core.eval.EvalEngine in project symja_android_library by axkr.
the class PatternMatchingTestCase method checkPriority.
public void checkPriority(String patternString, int 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(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 PatternMatchingTestCase method comparePriority.
public void comparePriority(String patternString1, String patternString2, int result) {
try {
EvalEngine engine = EvalEngine.get();
ASTNode node = fParser.parse(patternString1);
IExpr pat1 = new AST2Expr(false, engine).convert(node);
node = fParser.parse(patternString1);
IExpr pat2 = new AST2Expr(false, engine).convert(node);
PatternMatcher matcher1 = new PatternMatcher(pat1);
PatternMatcher matcher2 = new PatternMatcher(pat2);
assertEquals(matcher1.equivalentTo(matcher2), result);
} catch (Exception e) {
e.printStackTrace();
assertEquals(Integer.MAX_VALUE, result);
}
}
use of org.matheclipse.core.eval.EvalEngine in project symja_android_library by axkr.
the class PatternMatchingTestCase method setUp.
// public void testSlotPatternMatching() {
// checkPattern("b_.* #+c_.*#^2", "#-1*#^2", "");
// checkPattern("b_.* #+c_.*#^2", "#+#^2", "[1, 1]");
// checkPattern("a_. + b_.* #+c_.*#^2", "-1+#+#^2", "[-1, 1, 1]");
// }
/**
* The JUnit setup method
*/
@Override
protected void setUp() {
try {
// setup the evaluation engine (and bind to current thread)
// F.initSymbols();
// EvalEngine.get();
EvalEngine engine = new EvalEngine();
EvalEngine.set(engine);
engine.setSessionID("SpecialTestCase");
engine.setRecursionLimit(256);
engine.setIterationLimit(1024 * 1024);
util = new EvalUtilities(engine, false, false);
// setup a parser for the math expressions
fParser = new Parser();
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations