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;
}
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];
}
Aggregations