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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations