use of org.matheclipse.core.eval.EvalEngine in project symja_android_library by axkr.
the class PatternMap method isPatternTest.
public boolean isPatternTest(IExpr expr, IExpr patternTest) {
IExpr temp = substitutePatternOrSymbols(expr);
if (temp == null) {
temp = expr;
}
IAST test = F.unaryAST1(patternTest, null);
EvalEngine engine = EvalEngine.get();
if (temp.isSequence()) {
for (int i = 1; i < ((IAST) temp).size(); i++) {
test.set(1, ((IAST) temp).get(i));
if (!engine.evalTrue(test)) {
return false;
}
}
return true;
}
test.set(1, temp);
if (!engine.evalTrue(test)) {
return false;
}
return true;
}
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
*/
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();
}
}
use of org.matheclipse.core.eval.EvalEngine in project symja_android_library by axkr.
the class BasicPatternPropertiesTestCase method setUp.
/**
* The JUnit setup method
*/
protected void setUp() {
try {
// setup the evaluation engine (and bind to current thread)
// EvalEngine.get();
EvalEngine engine = new EvalEngine();
EvalEngine.set(engine);
engine.setSessionID("BasicPatternPropertiesTestCase");
engine.setRecursionLimit(256);
engine.setIterationLimit(1024 * 1024);
fParser = new Parser();
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.matheclipse.core.eval.EvalEngine in project symja_android_library by axkr.
the class AST2Expr method convert.
/**
* Converts a parsed FunctionNode expression into an IAST expression.
*
* @param functionNode
* the parsed elements which should be added to the <code>IAST</code>
* @param ast
* the empty <code>IAST</code> instance without any elements
* @return the <code>ast</code>with the added elements
* @throws ConversionException
*/
public IAST convert(FunctionNode functionNode, IAST ast) throws ConversionException {
EvalEngine engine = EvalEngine.get();
ast.set(0, convertNode(functionNode.get(0), engine));
for (int i = 1; i < functionNode.size(); i++) {
ast.append(convertNode(functionNode.get(i), engine));
}
return ast;
}
use of org.matheclipse.core.eval.EvalEngine in project symja_android_library by axkr.
the class FieldReducedRowEchelonForm method rowReduce.
/**
* Create the "reduced row echelon form" of a matrix.
*
* See: <a href="http://en.wikipedia.org/wiki/Row_echelon_form">Wikipedia -
* Row echelon form</a>.
*
* @return
*/
private FieldMatrix<IExpr> rowReduce() {
int maxRows = numRows;
RowColIndex pivot = new RowColIndex(0, 0);
int submatrix = 0;
for (int x = 0; x < numCols; x++) {
pivot = new RowColIndex(pivot.row, x);
// The pivot position is at the top.
for (int i = x; i < numCols; i++) {
if (isColumnZeroFromRow(pivot) == false) {
break;
} else {
pivot.col = i;
}
}
// Step 2
// Select a nonzero entry in the pivot column with the highest
// absolute value as a pivot.
pivot = findPivot(pivot);
if (isZero(getCoordinate(pivot))) {
pivot.row++;
if (pivot.row >= maxRows) {
break;
}
continue;
}
// move this row to the top of the submatrix
if (pivot.row != submatrix) {
swapRow(new RowColIndex(submatrix, pivot.col), pivot);
}
// Force pivot to be 1
if (!isOne(getCoordinate(pivot))) {
IExpr scalar = getCoordinate(pivot).inverse();
scaleRow(pivot, scalar);
}
// belowPivot = belowPivot + (Pivot * -belowPivot)
for (int i = pivot.row; i < numRows; i++) {
if (i == pivot.row) {
continue;
}
RowColIndex belowPivot = new RowColIndex(i, pivot.col);
IExpr complement = (getCoordinate(belowPivot).negate().divide(getCoordinate(pivot)));
multiplyAdd(belowPivot, pivot, complement);
}
// above the pivot
for (int i = pivot.row; i >= 0; i--) {
if (i == pivot.row) {
if (!isOne(getCoordinate(pivot))) {
scaleRow(pivot, getCoordinate(pivot).inverse());
}
continue;
}
if (i == pivot.row) {
continue;
}
RowColIndex abovePivot = new RowColIndex(i, pivot.col);
IExpr complement = (getCoordinate(abovePivot).negate().divide(getCoordinate(pivot)));
multiplyAdd(abovePivot, pivot, complement);
}
// are no more nonzero entries.
if ((pivot.row + 1) >= maxRows) {
// {
break;
}
submatrix++;
pivot.row++;
}
EvalEngine engine = EvalEngine.get();
IEvalStepListener listener = engine.getStepListener();
if (listener != null) {
listener.add(Convert.matrix2List(originalMatrix), Convert.matrix2List(rowReducedMatrix), engine.getRecursionCounter(), -1, "ReducedRowEchelonForm");
}
return rowReducedMatrix;
}
Aggregations