Search in sources :

Example 91 with EvalEngine

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

the class HMArrayList method mapThreadEvaled.

/**
 * {@inheritDoc}
 */
@Override
public final IASTAppendable mapThreadEvaled(EvalEngine engine, IASTAppendable appendAST, final IAST replacement, int position) {
    // final Function<IExpr, IExpr> function = Functors.replaceArg(replacement,
    // position);
    final Function<IExpr, IExpr> function = x -> {
        IAST a = replacement.setAtCopy(position, x);
        return engine.evaluate(a);
    };
    IExpr temp;
    for (int i = firstIndex + 1; i < lastIndex; i++) {
        temp = function.apply(array[i]);
        if (temp != null) {
            appendAST.append(temp);
        }
    }
    return appendAST;
}
Also used : Arrays(java.util.Arrays) ASTElementLimitExceeded(org.matheclipse.core.eval.exception.ASTElementLimitExceeded) ObjectInputStream(java.io.ObjectInputStream) ObjIntConsumer(java.util.function.ObjIntConsumer) Function(java.util.function.Function) HashSet(java.util.HashSet) RandomAccess(java.util.RandomAccess) BiPredicate(java.util.function.BiPredicate) Map(java.util.Map) ObjectOutputStream(java.io.ObjectOutputStream) IntFunction(java.util.function.IntFunction) EvalEngine(org.matheclipse.core.eval.EvalEngine) IASTAppendable(org.matheclipse.core.interfaces.IASTAppendable) IAST(org.matheclipse.core.interfaces.IAST) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) Config(org.matheclipse.core.basic.Config) IOException(java.io.IOException) ObjIntPredicate(org.matheclipse.core.generic.ObjIntPredicate) ISymbol(org.matheclipse.core.interfaces.ISymbol) Serializable(java.io.Serializable) Consumer(java.util.function.Consumer) List(java.util.List) IASTMutable(org.matheclipse.core.interfaces.IASTMutable) Stream(java.util.stream.Stream) Logger(org.apache.logging.log4j.Logger) IExpr(org.matheclipse.core.interfaces.IExpr) LogManager(org.apache.logging.log4j.LogManager) IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST)

Example 92 with EvalEngine

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

the class IntervalSym method cos.

public static IAST cos(final IAST ast) {
    EvalEngine engine = EvalEngine.get();
    return mutableProcessorConditions(ast, (min, max, result, index) -> {
        IAST difference = F.Subtract(max, min);
        if (engine.evalGreaterEqual(difference, F.C2Pi)) {
            // difference >= 2 * Pi
            result.append(index, F.list(F.CN1, F.C1));
        } else {
            // slope from 1st derivative
            double dMin = engine.evalDouble(F.Sin(min).negate());
            double dMax = engine.evalDouble(F.Sin(max).negate());
            if (engine.evalLessEqual(difference, S.Pi)) {
                if (dMin >= 0) {
                    if (dMax >= 0) {
                        result.append(index, F.list(F.Cos(min), F.Cos(max)));
                    } else {
                        result.append(index, F.list(F.Min(F.Cos(min), F.Cos(max)), F.C1));
                    }
                } else {
                    if (dMax < 0) {
                        result.append(index, F.list(F.Cos(max), F.Cos(min)));
                    } else {
                        result.append(index, F.list(F.CN1, F.Max(F.Cos(min), F.Cos(max))));
                    }
                }
            } else {
                // difference between {Pi, 2*Pi}
                if (dMin >= 0) {
                    if (dMax > 0) {
                        result.append(index, F.list(F.CN1, F.C1));
                    } else {
                        result.append(index, F.list(F.Min(F.Cos(min), F.Cos(max)), F.C1));
                    }
                } else {
                    if (dMax < 0) {
                        result.append(index, F.list(F.CN1, F.C1));
                    } else {
                        result.append(index, F.list(F.CN1, F.Max(F.Cos(min), F.Cos(max))));
                    }
                }
            }
        }
        return true;
    });
}
Also used : EvalEngine(org.matheclipse.core.eval.EvalEngine) IAST(org.matheclipse.core.interfaces.IAST)

Example 93 with EvalEngine

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

the class Symbol method addAttributes.

/**
 * {@inheritDoc}
 */
@Override
public final void addAttributes(final int attributes) {
    fAttributes |= attributes;
    if (isLocked()) {
        throw new RuleCreationError(this);
    }
    EvalEngine engine = EvalEngine.get();
    engine.addModifiedVariable(this);
}
Also used : EvalEngine(org.matheclipse.core.eval.EvalEngine) RuleCreationError(org.matheclipse.core.eval.exception.RuleCreationError)

Example 94 with EvalEngine

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

the class Symbol method clearAttributes.

/**
 * {@inheritDoc}
 */
@Override
public void clearAttributes(final int attributes) {
    fAttributes &= (0xffffffff ^ attributes);
    if (isLocked()) {
        throw new RuleCreationError(this);
    }
    EvalEngine engine = EvalEngine.get();
    engine.addModifiedVariable(this);
}
Also used : EvalEngine(org.matheclipse.core.eval.EvalEngine) RuleCreationError(org.matheclipse.core.eval.exception.RuleCreationError)

Example 95 with EvalEngine

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

the class Symbol method setAttributes.

/**
 * {@inheritDoc}
 */
@Override
public void setAttributes(final int attributes) {
    fAttributes = attributes;
    if (isLocked()) {
        throw new RuleCreationError(this);
    }
    EvalEngine engine = EvalEngine.get();
    engine.addModifiedVariable(this);
}
Also used : EvalEngine(org.matheclipse.core.eval.EvalEngine) RuleCreationError(org.matheclipse.core.eval.exception.RuleCreationError)

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