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;
}
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);
}
}
}
Aggregations