use of org.matheclipse.core.interfaces.IASTMutable in project symja_android_library by axkr.
the class IntervalSym method normalize.
/**
* The list of intervals are sorted and overlapping intervals are merged.
*
* @param intervalList
* @param engine
* @return <code>F.NIL</code> if the interval could not be normalized
*/
public static IAST normalize(final IAST intervalList, EvalEngine engine) {
try {
IASTAppendable result = intervalList.copyAppendable();
boolean evaled = false;
for (int i = 1; i < intervalList.size(); i++) {
IAST temp = normalizeArgument(intervalList.get(i), engine);
if (temp.isPresent()) {
evaled = true;
result.set(i, temp);
}
}
if (EvalAttributes.sort(result, INTERVAL_COMPARATOR)) {
evaled = true;
}
result.addEvalFlags(IAST.BUILT_IN_EVALED);
if (result.size() > 2) {
int j = 1;
IAST list1 = (IAST) result.arg1();
IExpr min1 = list1.arg1();
IExpr max1 = list1.arg2();
int i = 2;
while (i < result.size()) {
IAST list2 = (IAST) result.get(i);
IExpr min2 = list2.arg1();
IExpr max2 = list2.arg2();
if (min2.lessEqual(max1).isTrue()) {
if (max2.lessEqual(max1).isTrue()) {
evaled = true;
result.remove(i);
} else {
evaled = true;
result.remove(i);
list1 = F.list(min1, max2);
max1 = max2;
}
continue;
}
result.set(j++, list1);
list1 = list2;
min1 = min2;
max1 = max2;
i++;
}
result.set(j, list1);
}
if (evaled) {
return result;
}
if (intervalList instanceof IASTMutable) {
intervalList.addEvalFlags(IAST.BUILT_IN_EVALED);
if (EvalAttributes.sort((IASTMutable) intervalList, INTERVAL_COMPARATOR)) {
return intervalList;
}
}
return F.NIL;
// return intervalList;
} catch (RuntimeException rex) {
LOGGER.log(engine.getLogLevel(), "Interval", rex);
}
return F.NIL;
}
use of org.matheclipse.core.interfaces.IASTMutable in project symja_android_library by axkr.
the class AbstractAST method setPart.
@Override
public IExpr setPart(IExpr value, final int... positions) {
IExpr expr = this;
int size = positions.length;
for (int i = 0; i < size; i++) {
if (!expr.isAST()) {
break;
}
IASTMutable ast = (IASTMutable) expr;
expr = ast.get(positions[i]);
if (i == (size - 1)) {
ast.set(positions[i], value);
return expr;
}
}
return null;
}
use of org.matheclipse.core.interfaces.IASTMutable in project symja_android_library by axkr.
the class ASTAssociation method values.
protected IASTMutable values(IBuiltInSymbol symbol) {
IASTMutable list = copyAST();
list.set(0, symbol);
return list;
}
use of org.matheclipse.core.interfaces.IASTMutable in project symja_android_library by axkr.
the class B3 method setAtCopy.
@Override
public IASTMutable setAtCopy(int i, IExpr expr) {
if (i == 0) {
return new AST3(expr, arg1(), arg2(), arg3());
}
IASTMutable ast = copy();
ast.set(i, expr);
return ast;
}
use of org.matheclipse.core.interfaces.IASTMutable in project symja_android_library by axkr.
the class SparseArrayExpr method patternPositionsList.
/**
* Fill the sparse array by evaluating the rules left-hand-side as a pattern-matching expression.
*
* @param trie the internal trie structure of the sparse array
* @param ruleLHS
* @param ruleRHS
* @param dimension the dimension of the sparse array
* @param arrayRulesList parameter for error message handling
* @param engine
* @return
*/
private static boolean patternPositionsList(final Trie<int[], IExpr> trie, IExpr ruleLHS, IExpr ruleRHS, int[] dimension, IAST arrayRulesList, EvalEngine engine) {
if (dimension == null) {
return false;
}
final int depth = dimension.length;
PatternMatcherAndEvaluator matcher = new PatternMatcherAndEvaluator(ruleLHS, ruleRHS);
if (matcher.isRuleWithoutPatterns()) {
// The left hand side of `2` in `1` doesn't match an int-array of depth `3`.
IOFunctions.printMessage(S.SparseArray, "posr", F.list(arrayRulesList, ruleLHS, F.ZZ(depth)), EvalEngine.get());
return false;
}
IASTMutable positionList = F.constantArray(F.C1, depth);
int[] positionsKey = new int[depth];
IPatternMap patternMap = matcher.getPatternMap();
IExpr[] patternValuesArray = patternMap.copyPattern();
patternPositionsRecursive(trie, dimension, engine, matcher, positionList, 0, positionsKey, patternMap, patternValuesArray);
return true;
}
Aggregations