Search in sources :

Example 91 with IASTMutable

use of org.matheclipse.core.interfaces.IASTMutable in project symja_android_library by axkr.

the class VisitorExpr method visitAST.

/**
 * @return the cloned <code>IAST</code> with changed evaluated subexpressions, or <code>F.NIL
 *     </code>, if no evaluation is possible
 */
protected IExpr visitAST(IAST ast) {
    int size = ast.size();
    for (int i = 1; i < size; i++) {
        IExpr temp = ast.get(i).accept(this);
        if (temp.isPresent()) {
            // something was evaluated - return a new IAST:
            IASTMutable result = ast.setAtCopy(i++, temp);
            ast.forEach(i, size, (x, j) -> {
                IExpr t = x.accept(this);
                if (t.isPresent()) {
                    result.set(j, t);
                }
            });
            return result;
        }
    }
    return F.NIL;
}
Also used : IExpr(org.matheclipse.core.interfaces.IExpr) IASTMutable(org.matheclipse.core.interfaces.IASTMutable)

Example 92 with IASTMutable

use of org.matheclipse.core.interfaces.IASTMutable in project symja_android_library by axkr.

the class VisitorLevelSpecification method visit.

@Override
public IExpr visit(IASTMutable ast) {
    IASTMutable[] result = new IASTMutable[] { F.NIL };
    if (ast.isPresent()) {
        int[] minDepth = new int[] { 0 };
        try {
            fCurrentLevel++;
            if (fIncludeHeads) {
                final IExpr temp = ast.get(0).accept(this);
                if (temp.isPresent()) {
                    if (!result[0].isPresent()) {
                        result[0] = createResult(ast, temp);
                    }
                    result[0].set(0, temp);
                }
                if (fCurrentDepth < minDepth[0]) {
                    minDepth[0] = fCurrentDepth;
                }
            }
            ast.forEach((x, i) -> {
                final IExpr temp = x.accept(this);
                if (temp.isPresent()) {
                    if (!result[0].isPresent()) {
                        result[0] = createResult(ast, temp);
                    }
                    result[0].set(i, temp);
                }
                if (fCurrentDepth < minDepth[0]) {
                    minDepth[0] = fCurrentDepth;
                }
            });
        } finally {
            fCurrentLevel--;
        }
        fCurrentDepth = --minDepth[0];
        if (isInRange(fCurrentLevel, minDepth[0])) {
            if (!result[0].isPresent()) {
                return fFunction.apply(ast);
            } else {
                IExpr temp = fFunction.apply(result[0]);
                if (temp.isPresent()) {
                    return temp;
                }
            }
        }
    }
    return result[0];
}
Also used : IASTMutable(org.matheclipse.core.interfaces.IASTMutable) IExpr(org.matheclipse.core.interfaces.IExpr)

Aggregations

IASTMutable (org.matheclipse.core.interfaces.IASTMutable)92 IExpr (org.matheclipse.core.interfaces.IExpr)60 IAST (org.matheclipse.core.interfaces.IAST)34 IASTAppendable (org.matheclipse.core.interfaces.IASTAppendable)26 ISymbol (org.matheclipse.core.interfaces.ISymbol)12 IInteger (org.matheclipse.core.interfaces.IInteger)5 Map (java.util.Map)4 IComplex (org.matheclipse.core.interfaces.IComplex)4 IRational (org.matheclipse.core.interfaces.IRational)4 ArrayList (java.util.ArrayList)3 TreeMap (java.util.TreeMap)3 EvalEngine (org.matheclipse.core.eval.EvalEngine)3 JASConversionException (org.matheclipse.core.eval.exception.JASConversionException)3 ValidateException (org.matheclipse.core.eval.exception.ValidateException)3 INumber (org.matheclipse.core.interfaces.INumber)3 IPatternObject (org.matheclipse.core.interfaces.IPatternObject)3 ISparseArray (org.matheclipse.core.interfaces.ISparseArray)3 ASTNode (org.matheclipse.parser.client.ast.ASTNode)3 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)2 AST2Expr (org.matheclipse.core.convert.AST2Expr)2