use of org.matheclipse.core.interfaces.IASTAppendable in project symja_android_library by axkr.
the class AST3 method copyAppendable.
@Override
public IASTAppendable copyAppendable(int additionalCapacity) {
IASTAppendable result = F.ast(arg0, additionalCapacity + 3);
result.append(arg1);
result.append(arg2);
result.append(arg3);
return result;
}
use of org.matheclipse.core.interfaces.IASTAppendable in project symja_android_library by axkr.
the class B1 method copyAppendable.
@Override
public IASTAppendable copyAppendable(int additionalCapacity) {
IASTAppendable result = F.ast(head(), additionalCapacity + 1);
result.append(arg1);
return result;
}
use of org.matheclipse.core.interfaces.IASTAppendable in project symja_android_library by axkr.
the class ASTRealVector method setAtCopy.
@Override
public IASTMutable setAtCopy(int i, IExpr expr) {
if (expr instanceof Num) {
IASTMutable ast = copy();
ast.set(i, expr);
return ast;
}
IASTAppendable ast = copyAppendable();
ast.set(i, expr);
return ast;
}
use of org.matheclipse.core.interfaces.IASTAppendable in project symja_android_library by axkr.
the class EvalEngine method evalSetAttributesRecursive.
private IExpr evalSetAttributesRecursive(IAST ast, boolean noEvaluation, boolean evalNumericFunction, int level) {
// final ISymbol symbol = ast.topHead();
IExpr head = ast.head();
if (!(head instanceof IPatternObject) && !noEvaluation) {
IExpr headResult = head.evaluate(this);
if (headResult.isPresent()) {
ast = ast.apply(headResult);
head = headResult;
}
}
ISymbol symbol = head.topHead();
if (head.isSymbol()) {
symbol = (ISymbol) head;
}
if (symbol.isBuiltInSymbol()) {
// call so that attributes may be set in
// AbstractFunctionEvaluator#setUp() method
((IBuiltInSymbol) symbol).getEvaluator();
}
int headID = ast.headID();
if (headID >= 0) {
if (headID == ID.Blank || headID == ID.BlankSequence || headID == ID.BlankNullSequence || headID == ID.Pattern || headID == ID.Optional || headID == ID.OptionsPattern || headID == ID.Repeated || headID == ID.RepeatedNull) {
return ((IFunctionEvaluator) ((IBuiltInSymbol) ast.head()).getEvaluator()).evaluate(ast, this);
}
}
final int attributes = symbol.getAttributes();
IASTMutable resultList = F.NIL;
if ((ISymbol.HOLDALL & attributes) != ISymbol.HOLDALL) {
final int astSize = ast.size();
if ((ISymbol.HOLDFIRST & attributes) == ISymbol.NOATTRIBUTE) {
// the HoldFirst attribute isn't set here
if (astSize > 1) {
IExpr expr = ast.arg1();
if (expr.isAST()) {
resultList = evalSetAttributeArg(ast, 1, (IAST) expr, resultList, noEvaluation, level);
} else if (!(expr instanceof IPatternObject) && !noEvaluation) {
IExpr temp = expr.evaluate(this);
if (temp.isPresent()) {
resultList = ast.setAtCopy(1, temp);
}
}
}
}
if (astSize > 2) {
if ((ISymbol.HOLDREST & attributes) == ISymbol.NOATTRIBUTE) {
// the HoldRest attribute isn't set here
for (int i = 2; i < astSize; i++) {
IExpr expr = ast.get(i);
if (expr.isAST()) {
resultList = evalSetAttributeArg(ast, i, (IAST) expr, resultList, noEvaluation, level);
} else if (!(expr instanceof IPatternObject) && !noEvaluation) {
IExpr temp = expr.evaluate(this);
if (temp.isPresent()) {
if (resultList.isPresent()) {
resultList.set(i, temp);
} else {
resultList = ast.setAtCopy(i, temp);
}
}
}
}
}
}
if (evalNumericFunction && ((ISymbol.HOLDALL & attributes) == ISymbol.NOATTRIBUTE)) {
IAST f = resultList.orElse(ast);
if (f.isNumericFunction(true)) {
IExpr temp = evalLoop(f);
if (temp.isPresent()) {
return temp;
}
}
}
}
if (resultList.isPresent()) {
if (resultList.size() > 2) {
if (ISymbol.hasFlatAttribute(attributes)) {
// associative
IASTAppendable result;
if ((result = EvalAttributes.flattenDeep(resultList)).isPresent()) {
return evalSetOrderless(result, attributes, noEvaluation, level);
}
}
IExpr expr = evalSetOrderless(resultList, attributes, noEvaluation, level);
if (expr.isPresent()) {
return expr;
}
}
return resultList;
}
if ((ast.getEvalFlags() & IAST.IS_FLATTENED_OR_SORTED_MASK) != 0x0000) {
// already flattened or sorted
return ast;
}
if (ISymbol.hasFlatAttribute(attributes)) {
// associative
IASTAppendable result;
if ((result = EvalAttributes.flattenDeep(ast)).isPresent()) {
return evalSetOrderless(result, attributes, noEvaluation, level);
}
}
return evalSetOrderless(ast, attributes, noEvaluation, level);
}
use of org.matheclipse.core.interfaces.IASTAppendable in project symja_android_library by axkr.
the class EvalEngine method addEvaluatedTraceStep.
/**
* Add a single step to the currently defined trace stack and evaluate the <code>rewrittenExpr
* </code> expression.
*
* @param inputExpr the input expression
* @param rewrittenExpr the rewritten expression
* @param list
* @return
*/
public IExpr addEvaluatedTraceStep(IExpr inputExpr, IExpr rewrittenExpr, IExpr... list) {
if (fTraceStack != null) {
IASTAppendable listOfHints = F.ast(S.List, list.length + 1);
listOfHints.appendAll(list, 0, list.length);
fTraceStack.add(inputExpr, rewrittenExpr, getRecursionCounter(), -1, listOfHints);
IExpr evaluatedResult = evaluate(rewrittenExpr);
listOfHints.append(evaluatedResult);
return evaluatedResult;
}
return evaluate(rewrittenExpr);
}
Aggregations