Search in sources :

Example 16 with IASTAppendable

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

Example 17 with IASTAppendable

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

Example 18 with IASTAppendable

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;
}
Also used : IASTAppendable(org.matheclipse.core.interfaces.IASTAppendable) IASTMutable(org.matheclipse.core.interfaces.IASTMutable)

Example 19 with IASTAppendable

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);
}
Also used : IBuiltInSymbol(org.matheclipse.core.interfaces.IBuiltInSymbol) ISymbol(org.matheclipse.core.interfaces.ISymbol) IFunctionEvaluator(org.matheclipse.core.eval.interfaces.IFunctionEvaluator) IASTAppendable(org.matheclipse.core.interfaces.IASTAppendable) IPatternObject(org.matheclipse.core.interfaces.IPatternObject) IExpr(org.matheclipse.core.interfaces.IExpr) IASTMutable(org.matheclipse.core.interfaces.IASTMutable) IAST(org.matheclipse.core.interfaces.IAST)

Example 20 with IASTAppendable

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

Aggregations

IASTAppendable (org.matheclipse.core.interfaces.IASTAppendable)363 IExpr (org.matheclipse.core.interfaces.IExpr)219 IAST (org.matheclipse.core.interfaces.IAST)130 ISymbol (org.matheclipse.core.interfaces.ISymbol)36 IASTMutable (org.matheclipse.core.interfaces.IASTMutable)30 IInteger (org.matheclipse.core.interfaces.IInteger)29 Map (java.util.Map)28 EvalEngine (org.matheclipse.core.eval.EvalEngine)20 PrettyPrint (edu.jas.kern.PrettyPrint)13 SortedMap (java.util.SortedMap)13 ArrayList (java.util.ArrayList)12 F (org.matheclipse.core.expression.F)12 BigRational (edu.jas.arith.BigRational)10 LogManager (org.apache.logging.log4j.LogManager)10 Logger (org.apache.logging.log4j.Logger)10 ExpVector (edu.jas.poly.ExpVector)9 HashMap (java.util.HashMap)9 IBuiltInSymbol (org.matheclipse.core.interfaces.IBuiltInSymbol)8 IStringX (org.matheclipse.core.interfaces.IStringX)8 ASTNode (org.matheclipse.parser.client.ast.ASTNode)8