Search in sources :

Example 96 with EvalEngine

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

the class IntervalSym method abs.

public static IExpr abs(final IAST ast) {
    IAST interval = normalize(ast);
    if (interval.isPresent()) {
        IASTAppendable result = F.IntervalAlloc(interval.size());
        EvalEngine engine = EvalEngine.get();
        for (int i = 1; i < interval.size(); i++) {
            IAST list = (IAST) interval.get(i);
            IExpr min = list.arg1();
            IExpr max = list.arg2();
            if (min.isRealResult() && max.isRealResult()) {
                result.append(F.list(mig(min, max, engine), mag(min, max, engine)));
            } else {
                return F.NIL;
            }
        }
        return result;
    }
    return F.NIL;
}
Also used : IASTAppendable(org.matheclipse.core.interfaces.IASTAppendable) EvalEngine(org.matheclipse.core.eval.EvalEngine) IAST(org.matheclipse.core.interfaces.IAST) IExpr(org.matheclipse.core.interfaces.IExpr)

Example 97 with EvalEngine

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

the class IntervalSym method sin.

public static IAST sin(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.Cos(min));
            double dMax = engine.evalDouble(F.Cos(max));
            if (engine.evalLessEqual(difference, S.Pi)) {
                if (dMin >= 0) {
                    if (dMax >= 0) {
                        result.append(index, F.list(F.Sin(min), F.Sin(max)));
                    } else {
                        result.append(index, F.list(F.Min(F.Sin(min), F.Sin(max)), F.C1));
                    }
                } else {
                    if (dMax < 0) {
                        result.append(index, F.list(F.Sin(max), F.Sin(min)));
                    } else {
                        result.append(index, F.list(F.CN1, F.Max(F.Sin(min), F.Sin(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.Sin(min), F.Sin(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.Sin(min), F.Sin(max))));
                    }
                }
            }
        }
        return true;
    });
}
Also used : EvalEngine(org.matheclipse.core.eval.EvalEngine) IAST(org.matheclipse.core.interfaces.IAST)

Example 98 with EvalEngine

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

the class IntervalSym method log.

public static IAST log(final IAST ast) {
    EvalEngine engine = EvalEngine.get();
    return mutableProcessorConditions(ast, (min, max, result, index) -> {
        if (min.isNonNegativeResult() && max.isNonNegativeResult()) {
            min = S.Log.of(engine, min);
            max = S.Log.of(engine, max);
            result.append(index, F.list(min, max));
            return true;
        }
        return false;
    });
}
Also used : EvalEngine(org.matheclipse.core.eval.EvalEngine)

Example 99 with EvalEngine

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

the class IntervalSym method arccot.

public static IExpr arccot(final IAST ast) {
    EvalEngine engine = EvalEngine.get();
    return mutableProcessorConditions(ast, (min, max, result, index) -> {
        if (engine.evalGreaterEqual(min, F.C0) && engine.evalGreaterEqual(max, F.C0)) {
            result.append(F.list(F.ArcCot(min), F.ArcCot(max)));
            return true;
        }
        return false;
    }, (min, max, result, index) -> {
        if (engine.evalLess(min, F.C0) && engine.evalGreaterEqual(max, F.C0)) {
            result.append(F.list(F.CNPiHalf, F.ArcCot(min)));
            result.append(F.list(F.ArcCot(max), F.CPiHalf));
            return true;
        }
        return false;
    }, (min, max, result, index) -> {
        if (engine.evalLess(min, F.C0) && engine.evalLess(max, F.C0)) {
            result.append(F.list(F.ArcCot(min), F.ArcCot(max)));
            return true;
        }
        return false;
    });
}
Also used : EvalEngine(org.matheclipse.core.eval.EvalEngine)

Example 100 with EvalEngine

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

the class RepeatedPattern method matchPatternSequence.

@Override
public boolean matchPatternSequence(final IAST sequence, IPatternMap patternMap, ISymbol optionsPatternHead) {
    final int size = sequence.argSize();
    if (size < fMin || size > fMax) {
        return false;
    }
    EvalEngine engine = EvalEngine.get();
    for (int i = 1; i < sequence.size(); i++) {
        if (!fMatcher.testBlank(sequence.get(i), engine)) {
            return false;
        }
    }
    return true;
}
Also used : EvalEngine(org.matheclipse.core.eval.EvalEngine)

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