Search in sources :

Example 56 with IASTMutable

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;
}
Also used : IASTAppendable(org.matheclipse.core.interfaces.IASTAppendable) IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST) IASTMutable(org.matheclipse.core.interfaces.IASTMutable) HashMap(java.util.HashMap) Map(java.util.Map)

Example 57 with IASTMutable

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);
    }
}
Also used : IInteger(org.matheclipse.core.interfaces.IInteger) IASTMutable(org.matheclipse.core.interfaces.IASTMutable)

Example 58 with IASTMutable

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);
    }
}
Also used : IInteger(org.matheclipse.core.interfaces.IInteger) IASTMutable(org.matheclipse.core.interfaces.IASTMutable)

Example 59 with IASTMutable

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);
    }
}
Also used : IASTMutable(org.matheclipse.core.interfaces.IASTMutable)

Example 60 with IASTMutable

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);
    }
}
Also used : IASTMutable(org.matheclipse.core.interfaces.IASTMutable)

Aggregations

IASTMutable (org.matheclipse.core.interfaces.IASTMutable)92 IExpr (org.matheclipse.core.interfaces.IExpr)60 IAST (org.matheclipse.core.interfaces.IAST)34 IASTAppendable (org.matheclipse.core.interfaces.IASTAppendable)26 ISymbol (org.matheclipse.core.interfaces.ISymbol)12 IInteger (org.matheclipse.core.interfaces.IInteger)5 Map (java.util.Map)4 IComplex (org.matheclipse.core.interfaces.IComplex)4 IRational (org.matheclipse.core.interfaces.IRational)4 ArrayList (java.util.ArrayList)3 TreeMap (java.util.TreeMap)3 EvalEngine (org.matheclipse.core.eval.EvalEngine)3 JASConversionException (org.matheclipse.core.eval.exception.JASConversionException)3 ValidateException (org.matheclipse.core.eval.exception.ValidateException)3 INumber (org.matheclipse.core.interfaces.INumber)3 IPatternObject (org.matheclipse.core.interfaces.IPatternObject)3 ISparseArray (org.matheclipse.core.interfaces.ISparseArray)3 ASTNode (org.matheclipse.parser.client.ast.ASTNode)3 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)2 AST2Expr (org.matheclipse.core.convert.AST2Expr)2