use of org.matheclipse.core.interfaces.IASTAppendable in project symja_android_library by axkr.
the class AbstractAST method opposite.
/**
* {@inheritDoc}
*/
@Override
public IExpr opposite() {
final int lhsOrdinal = (head() instanceof IBuiltInSymbol) ? ((IBuiltInSymbol) head()).ordinal() : -1;
if (lhsOrdinal > 0) {
if (isTimes()) {
IExpr arg1 = arg1();
if (arg1.isNumber()) {
if (arg1.isMinusOne()) {
if (size() == 3) {
return arg2();
}
return rest();
}
return setAtCopy(1, ((INumber) arg1).negate());
}
IASTAppendable timesAST = copyAppendable();
timesAST.append(1, F.CN1);
return timesAST;
}
if (isNegativeInfinity()) {
return F.CInfinity;
}
if (isInfinity()) {
return F.CNInfinity;
}
if (isPlus()) {
return map(x -> x.negate(), 1);
}
}
return F.Times(F.CN1, this);
// return F.eval(F.Times(F.CN1, this));
}
use of org.matheclipse.core.interfaces.IASTAppendable in project symja_android_library by axkr.
the class AbstractAST method partition.
/**
* {@inheritDoc}
*/
@Override
public final IAST partition(ISymbol operator, Predicate<? super IExpr> predicate, IExpr init1, IExpr init2, ISymbol combiner, ISymbol action) {
if (head().equals(operator)) {
IASTAppendable result = F.ast(action, 3);
final int size = size();
int newSize = size / 2;
if (newSize <= 4) {
newSize = 5;
} else {
newSize += 4;
}
IASTAppendable yesAST = F.ast(combiner, newSize);
IASTAppendable noAST = F.ast(combiner, newSize);
forEach(size, x -> {
if (predicate.test(x)) {
yesAST.append(x);
} else {
noAST.append(x);
}
});
if (yesAST.size() > 1) {
result.append(F.eval(yesAST));
} else {
result.append(init1);
}
if (noAST.size() > 1) {
result.append(F.eval(noAST));
} else {
result.append(init2);
}
return result;
}
return F.NIL;
}
use of org.matheclipse.core.interfaces.IASTAppendable in project symja_android_library by axkr.
the class AbstractAST method removeAtClone.
/**
* {@inheritDoc}
*/
@Override
public final IASTAppendable removeAtClone(int position) {
IASTAppendable ast = copyAppendable();
ast.remove(position);
return ast;
}
use of org.matheclipse.core.interfaces.IASTAppendable in project symja_android_library by axkr.
the class AbstractAST method extractConditionalExpression.
/**
* {@inheritDoc}
*/
@Override
public IExpr extractConditionalExpression(boolean isUnaryConditionalExpression) {
if (isUnaryConditionalExpression) {
// mergeConditionalExpression
IAST conditionalExpr = (IAST) arg1();
IASTMutable copy = copy();
copy.set(1, conditionalExpr.arg1());
return conditionalExpr.setAtCopy(1, copy);
}
int indx = indexOf(x -> x.isConditionalExpression());
if (indx > 0) {
IAST conditionalExpr = (IAST) get(indx);
IASTAppendable andExpr = F.And();
IASTMutable copy = copy();
copy.set(indx, conditionalExpr.arg1());
andExpr.append(conditionalExpr.arg2());
indx++;
for (int i = indx; i < copy.size(); i++) {
IExpr x = copy.get(i);
if (x.isConditionalExpression()) {
conditionalExpr = (IAST) x;
copy.set(i, conditionalExpr.arg1());
andExpr.append(conditionalExpr.arg2());
}
}
IASTMutable mergedResult = conditionalExpr.setAtCopy(1, copy);
mergedResult.set(2, andExpr);
return mergedResult;
}
return F.NIL;
}
use of org.matheclipse.core.interfaces.IASTAppendable in project symja_android_library by axkr.
the class AbstractAST method apply.
@Override
public IAST apply(final IExpr head, final int start, final int end) {
final IASTAppendable ast = F.ast(head, end - start);
ast.appendArgs(start, end, i -> get(i));
// }
return ast;
}
Aggregations