Search in sources :

Example 1 with EvalEngine

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;
}
Also used : EvalEngine(org.matheclipse.core.eval.EvalEngine) IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST)

Example 2 with EvalEngine

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();
    }
}
Also used : EvalUtilities(org.matheclipse.core.eval.EvalUtilities) EvalEngine(org.matheclipse.core.eval.EvalEngine) Parser(org.matheclipse.parser.client.Parser)

Example 3 with EvalEngine

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();
    }
}
Also used : EvalEngine(org.matheclipse.core.eval.EvalEngine) Parser(org.matheclipse.parser.client.Parser)

Example 4 with EvalEngine

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;
}
Also used : EvalEngine(org.matheclipse.core.eval.EvalEngine) Apint(org.apfloat.Apint)

Example 5 with EvalEngine

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

the class FieldReducedRowEchelonForm method rowReduce.

/**
	 * Create the &quot;reduced row echelon form&quot; 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;
}
Also used : EvalEngine(org.matheclipse.core.eval.EvalEngine) IEvalStepListener(org.matheclipse.core.interfaces.IEvalStepListener) IExpr(org.matheclipse.core.interfaces.IExpr)

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