use of org.matheclipse.core.interfaces.IASTMutable in project symja_android_library by axkr.
the class PlusOp method getSum.
/**
* Get the current evaluated result of the summation as a <code>Plus()</code> expression with
* respecting the <code>OneIdentity</code> attribute.
*
* @return
*/
public IExpr getSum() {
if (plusMap == null) {
if (numberValue.isPresent() && !numberValue.isZero()) {
return numberValue;
}
return F.C0;
}
IASTAppendable result = F.PlusAlloc(plusMap.size() + 1);
if (numberValue.isPresent() && !numberValue.isZero()) {
if (numberValue.isComplexInfinity()) {
return numberValue;
}
result.append(numberValue);
}
for (Map.Entry<IExpr, IExpr> element : plusMap.entrySet()) {
final IExpr key = element.getKey();
final IExpr value = element.getValue();
if (value.isOne()) {
if (key.isPlus()) {
result.appendArgs((IAST) key);
} else {
if (key.isTimes()) {
EvalAttributes.sortWithFlags((IASTMutable) key);
}
result.append(key);
}
} else if (key.isTimes()) {
IASTAppendable times = F.TimesAlloc(((IAST) key).size());
times.append(value);
times.appendArgs((IAST) key);
EvalAttributes.sortWithFlags(times);
result.append(times);
} else {
IASTMutable times = F.Times(value, key);
EvalAttributes.sortWithFlags(times);
result.append(times);
}
}
IExpr temp = result.oneIdentity0();
if (temp.isPlus()) {
EvalAttributes.sortWithFlags((IASTMutable) temp);
}
return temp;
}
use of org.matheclipse.core.interfaces.IASTMutable in project symja_android_library by axkr.
the class NumericArrayExpr method normalRecursive.
private static void normalRecursive(long[] longArray, boolean unsigned, IASTMutable list, int[] dimension, int position, int[] index) {
int size = dimension[position];
if (dimension.length - 1 == position) {
for (int i = 1; i <= size; i++) {
IInteger intValue = unsigned ? F.ZZ(UnsignedLong.fromLongBits(longArray[index[0]++]).bigIntegerValue()) : F.ZZ(longArray[index[0]++]);
list.set(i, intValue);
}
return;
}
int size2 = dimension[position + 1];
for (int i = 1; i <= size; i++) {
IASTMutable currentList = F.astMutable(S.List, size2);
list.set(i, currentList);
normalRecursive(longArray, unsigned, currentList, dimension, position + 1, index);
}
}
use of org.matheclipse.core.interfaces.IASTMutable in project symja_android_library by axkr.
the class NumericArrayExpr method normalRecursive.
private static void normalRecursive(short[] shortArray, boolean unsigned, IASTMutable list, int[] dimension, int position, int[] index) {
int size = dimension[position];
if (dimension.length - 1 == position) {
for (int i = 1; i <= size; i++) {
IInteger intValue = unsigned ? F.ZZ(Short.toUnsignedInt(shortArray[index[0]++])) : F.ZZ(shortArray[index[0]++]);
list.set(i, intValue);
}
return;
}
int size2 = dimension[position + 1];
for (int i = 1; i <= size; i++) {
IASTMutable currentList = F.astMutable(S.List, size2);
list.set(i, currentList);
normalRecursive(shortArray, unsigned, currentList, dimension, position + 1, index);
}
}
use of org.matheclipse.core.interfaces.IASTMutable in project symja_android_library by axkr.
the class NumericArrayExpr method normalRecursive.
private static void normalRecursive(float[] floatArray, IASTMutable list, int[] dimension, int position, int[] index) {
int size = dimension[position];
if (dimension.length - 1 == position) {
for (int i = 1; i <= size; i++) {
list.set(i, F.num(floatArray[index[0]++]));
}
return;
}
int size2 = dimension[position + 1];
for (int i = 1; i <= size; i++) {
IASTMutable currentList = F.astMutable(S.List, size2);
list.set(i, currentList);
normalRecursive(floatArray, currentList, dimension, position + 1, index);
}
}
use of org.matheclipse.core.interfaces.IASTMutable in project symja_android_library by axkr.
the class NumericArrayExpr method normalRecursive.
private static void normalRecursive(double[] doubleArray, IASTMutable list, int[] dimension, int position, int[] index) {
int size = dimension[position];
if (dimension.length - 1 == position) {
for (int i = 1; i <= size; i++) {
list.set(i, F.num(doubleArray[index[0]++]));
}
return;
}
int size2 = dimension[position + 1];
for (int i = 1; i <= size; i++) {
IASTMutable currentList = F.astMutable(S.List, size2);
list.set(i, currentList);
normalRecursive(doubleArray, currentList, dimension, position + 1, index);
}
}
Aggregations