Search in sources :

Example 1 with ComplexSym

use of org.matheclipse.core.expression.ComplexSym in project symja_android_library by axkr.

the class GaussianInteger method factorize.

public static IAST factorize(BigInteger re, BigInteger im, IExpr num) {
    GaussianInteger g = new GaussianInteger();
    SortedMap<ComplexSym, Integer> complexMap = new TreeMap<ComplexSym, Integer>();
    g.gaussianFactorization2(re, im, complexMap);
    IASTAppendable list = F.ListAlloc(complexMap.size() + 1);
    IExpr factor = F.C1;
    IASTAppendable ast = F.TimesAlloc(complexMap.size());
    for (Map.Entry<ComplexSym, Integer> entry : complexMap.entrySet()) {
        ComplexSym key = entry.getKey();
        int i = entry.getValue();
        if (i == 1) {
            ast.append(key);
        } else {
            IInteger is = F.ZZ(i);
            ast.append(F.Power(key, is));
        }
    }
    factor = F.eval(F.Divide(num, ast));
    if (!factor.isOne()) {
        list.append(F.list(factor, F.C1));
    }
    for (Map.Entry<ComplexSym, Integer> entry : complexMap.entrySet()) {
        ComplexSym key = entry.getKey();
        IInteger is = F.ZZ(entry.getValue());
        list.append(F.list(key, is));
    }
    return list;
}
Also used : BigInteger(java.math.BigInteger) IInteger(org.matheclipse.core.interfaces.IInteger) IASTAppendable(org.matheclipse.core.interfaces.IASTAppendable) ComplexSym(org.matheclipse.core.expression.ComplexSym) IInteger(org.matheclipse.core.interfaces.IInteger) IExpr(org.matheclipse.core.interfaces.IExpr) TreeMap(java.util.TreeMap) TreeMap(java.util.TreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap)

Example 2 with ComplexSym

use of org.matheclipse.core.expression.ComplexSym in project symja_android_library by axkr.

the class GaussianInteger method divideGaussian.

private void divideGaussian(BigInteger real, BigInteger imag, SortedMap<ComplexSym, Integer> complexMap) {
    real = real.abs();
    BigInteger temp;
    BigInteger norm = real.multiply(real).add(imag.multiply(imag));
    BigInteger realNum = ValA.multiply(real).add(ValB.multiply(imag));
    BigInteger imagNum = ValB.multiply(real).subtract(ValA.multiply(imag));
    if (realNum.mod(norm).signum() == 0 && imagNum.mod(norm).signum() == 0) {
        ValA = realNum.divide(norm);
        ValB = imagNum.divide(norm);
        if (real.signum() < 0) {
            real = real.negate();
            if (imag.signum() > 0) {
                temp = imag;
                imag = real;
                real = temp;
            } else {
                imag = imag.negate();
            }
        } else if (imag.signum() < 0) {
            imag = imag.negate();
            temp = imag;
            imag = real;
            real = temp;
        }
        ComplexSym c = ComplexSym.valueOf(F.ZZ(real), F.ZZ(imag));
        Integer value = complexMap.get(c);
        if (value == null) {
            complexMap.put(c, 1);
        } else {
            complexMap.put(c, value + 1);
        }
    }
}
Also used : BigInteger(java.math.BigInteger) IInteger(org.matheclipse.core.interfaces.IInteger) ComplexSym(org.matheclipse.core.expression.ComplexSym) BigInteger(java.math.BigInteger)

Aggregations

BigInteger (java.math.BigInteger)2 ComplexSym (org.matheclipse.core.expression.ComplexSym)2 IInteger (org.matheclipse.core.interfaces.IInteger)2 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 IASTAppendable (org.matheclipse.core.interfaces.IASTAppendable)1 IExpr (org.matheclipse.core.interfaces.IExpr)1