Search in sources :

Example 41 with IASTAppendable

use of org.matheclipse.core.interfaces.IASTAppendable in project symja_android_library by axkr.

the class IntervalSym method power.

/**
 * Calculate <code>Interval({lower, upper},...,...) ^ exponent</code>.
 *
 * <p>
 * See: <a href= "https://en.wikipedia.org/wiki/Interval_arithmetic#Elementary_functions">Interval
 * arithmetic - Elementary functions</a>
 *
 * @param baseInterval
 * @param exponent
 * @return
 */
public static IExpr power(final IAST baseInterval, ISignedNumber exponent) {
    IAST interval = normalize(baseInterval);
    if (interval.isPresent()) {
        boolean negative = false;
        if (exponent.isNegative()) {
            negative = true;
            exponent = exponent.negate();
        }
        if (exponent.isOne()) {
            if (negative) {
                return inverse(interval);
            }
            return baseInterval;
        }
        IASTAppendable result = F.IntervalAlloc(baseInterval.size());
        for (int i = 1; i < interval.size(); i++) {
            IAST list = (IAST) interval.get(i);
            if (list.arg1().isNonNegativeResult() && list.arg2().isNonNegativeResult()) {
                result.append(F.list(list.arg1().power(exponent), list.arg2().power(exponent)));
            } else {
                return F.NIL;
            }
        }
        if (negative) {
            return F.Power(result, F.CN1);
        }
        return result;
    }
    return F.NIL;
}
Also used : IASTAppendable(org.matheclipse.core.interfaces.IASTAppendable) IAST(org.matheclipse.core.interfaces.IAST)

Example 42 with IASTAppendable

use of org.matheclipse.core.interfaces.IASTAppendable in project symja_android_library by axkr.

the class IntervalSym method min.

public static IExpr min(final IAST ast) {
    IAST interval = normalize(ast);
    if (interval.isPresent()) {
        IASTAppendable result = F.ast(S.Min, interval.size());
        for (int i = 1; i < interval.size(); i++) {
            IAST list = (IAST) interval.get(i);
            result.append(list.arg1());
        }
        return result;
    }
    return F.NIL;
}
Also used : IASTAppendable(org.matheclipse.core.interfaces.IASTAppendable) IAST(org.matheclipse.core.interfaces.IAST)

Example 43 with IASTAppendable

use of org.matheclipse.core.interfaces.IASTAppendable in project symja_android_library by axkr.

the class IntervalSym method mapSymbol.

/**
 * @param symbol
 * @param ast
 * @return
 */
public static IExpr mapSymbol(ISymbol symbol, final IAST ast) {
    IAST interval = normalize(ast);
    if (interval.isPresent()) {
        IASTAppendable result = F.IntervalAlloc(interval.size());
        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(F.unaryAST1(symbol, min), F.unaryAST1(symbol, max)));
            } else {
                return F.NIL;
            }
        }
        return result;
    }
    return F.NIL;
}
Also used : IASTAppendable(org.matheclipse.core.interfaces.IASTAppendable) IAST(org.matheclipse.core.interfaces.IAST) IExpr(org.matheclipse.core.interfaces.IExpr)

Example 44 with IASTAppendable

use of org.matheclipse.core.interfaces.IASTAppendable in project symja_android_library by axkr.

the class IntervalSym method power.

/**
 * Calculate <code>Interval({lower, upper},...,...) ^ exponent</code>.
 *
 * <p>
 * See: <a href= "https://en.wikipedia.org/wiki/Interval_arithmetic#Elementary_functions">Interval
 * arithmetic - Elementary functions</a>
 *
 * @param baseInterval
 * @param exponent
 * @return
 */
public static IExpr power(final IAST baseInterval, IInteger exponent) {
    IAST interval = normalize(baseInterval);
    if (interval.isPresent()) {
        boolean negative = false;
        if (exponent.isNegative()) {
            negative = true;
            exponent = exponent.negate();
        }
        if (exponent.isOne()) {
            if (negative) {
                return inverse(interval);
            }
            return baseInterval;
        }
        IASTAppendable result = F.IntervalAlloc(baseInterval.size());
        for (int i = 1; i < interval.size(); i++) {
            IAST list = (IAST) interval.get(i);
            if (list.arg1().isRealResult() && list.arg2().isRealResult()) {
                if (exponent.isEven()) {
                    if (list.arg1().isNonNegativeResult()) {
                        result.append(F.list(list.arg1().power(exponent), list.arg2().power(exponent)));
                    } else {
                        if (list.arg2().isNegativeResult()) {
                            result.append(F.list(list.arg2().power(exponent), list.arg1().power(exponent)));
                        } else {
                            result.append(F.list(F.C0, F.Max(list.arg1().power(exponent), list.arg2().power(exponent))));
                        }
                    }
                } else {
                    result.append(F.list(list.arg1().power(exponent), list.arg2().power(exponent)));
                }
            } else {
                return F.NIL;
            }
        }
        if (negative) {
            return F.Power(result, F.CN1);
        }
        return result;
    }
    return F.NIL;
}
Also used : IASTAppendable(org.matheclipse.core.interfaces.IASTAppendable) IAST(org.matheclipse.core.interfaces.IAST)

Example 45 with IASTAppendable

use of org.matheclipse.core.interfaces.IASTAppendable in project symja_android_library by axkr.

the class F method Times.

/**
 * See: <a href=
 * "https://raw.githubusercontent.com/axkr/symja_android_library/master/symja_android_library/doc/functions/Times.md">Times</a>
 */
public static IAST Times(final long num, final IExpr... a) {
    IASTAppendable ast = ast(Times, a.length + 1);
    ast.append(ZZ(num));
    ast.appendAll(a, 0, a.length);
    return ast;
}
Also used : IASTAppendable(org.matheclipse.core.interfaces.IASTAppendable)

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