use of org.matheclipse.core.interfaces.IComplex in project symja_android_library by axkr.
the class AbstractArg12 method binaryOperator.
public IExpr binaryOperator(final IExpr o0, final IExpr o1) {
IExpr result = F.NIL;
if (o0 instanceof ApcomplexNum) {
if (o1.isNumber()) {
result = e2ApcomplexArg((ApcomplexNum) o0, ((INumber) o1).apcomplexNumValue(((ApcomplexNum) o0).precision()));
}
if (result.isPresent()) {
return result;
}
return e2ObjArg(o0, o1);
} else if (o1 instanceof ApcomplexNum) {
if (o0.isNumber()) {
result = e2ApcomplexArg(((INumber) o0).apcomplexNumValue(((ApcomplexNum) o1).precision()), (ApcomplexNum) o1);
}
if (result.isPresent()) {
return result;
}
return e2ObjArg(o0, o1);
} else if (o0 instanceof ComplexNum) {
if (o1.isNumber()) {
result = e2DblComArg((ComplexNum) o0, ((INumber) o1).complexNumValue());
}
if (result.isPresent()) {
return result;
}
return e2ObjArg(o0, o1);
} else if (o1 instanceof ComplexNum) {
if (o0.isNumber()) {
result = e2DblComArg(((INumber) o0).complexNumValue(), (ComplexNum) o1);
}
if (result.isPresent()) {
return result;
}
return e2ObjArg(o0, o1);
}
if (o0 instanceof ApfloatNum) {
if (o1.isSignedNumber()) {
result = e2ApfloatArg((ApfloatNum) o0, ((ISignedNumber) o1).apfloatNumValue(((ApfloatNum) o0).precision()));
}
if (result.isPresent()) {
return result;
}
return e2ObjArg(o0, o1);
} else if (o1 instanceof ApfloatNum) {
if (o0.isSignedNumber()) {
result = e2ApfloatArg(((ISignedNumber) o0).apfloatNumValue(((ApfloatNum) o1).precision()), (ApfloatNum) o1);
}
if (result.isPresent()) {
return result;
}
return e2ObjArg(o0, o1);
} else if (o0 instanceof Num) {
if (o1.isSignedNumber()) {
result = e2DblArg((Num) o0, ((ISignedNumber) o1).numValue());
}
if (result.isPresent()) {
return result;
}
return e2ObjArg(o0, o1);
} else if (o1 instanceof Num) {
if (o0.isSignedNumber()) {
result = e2DblArg(((ISignedNumber) o0).numValue(), (Num) o1);
}
if (result.isPresent()) {
return result;
}
return e2ObjArg(o0, o1);
}
result = e2ObjArg(o0, o1);
if (result.isPresent()) {
return result;
}
if (o0 instanceof IInteger) {
if (o1 instanceof IInteger) {
return e2IntArg((IInteger) o0, (IInteger) o1);
}
if (o1 instanceof IFraction) {
return e2FraArg(F.fraction((IInteger) o0, F.C1), (IFraction) o1);
}
if (o1 instanceof IComplex) {
return e2ComArg(F.complex((IInteger) o0, F.C0), (IComplex) o1);
}
return F.NIL;
}
if (o0 instanceof IFraction) {
if (o1 instanceof IInteger) {
return e2FraArg((IFraction) o0, F.fraction((IInteger) o1, F.C1));
}
if (o1 instanceof IFraction) {
return e2FraArg((IFraction) o0, (IFraction) o1);
}
if (o1 instanceof IComplex) {
return e2ComArg(F.complex((IFraction) o0), (IComplex) o1);
}
return F.NIL;
}
if (o0 instanceof IComplex) {
if (o1 instanceof IInteger) {
return eComIntArg((IComplex) o0, (IInteger) o1);
}
if (o1 instanceof IFraction) {
return eComFraArg((IComplex) o0, (IFraction) o1);
}
if (o1 instanceof IComplex) {
return e2ComArg((IComplex) o0, (IComplex) o1);
}
}
if (o0 instanceof ISymbol) {
if (o1 instanceof ISymbol) {
return e2SymArg((ISymbol) o0, (ISymbol) o1);
}
}
if (o0 instanceof IAST) {
if (o1 instanceof IInteger) {
return eFunIntArg((IAST) o0, (IInteger) o1);
}
if (o1 instanceof IAST) {
return e2FunArg((IAST) o0, (IAST) o1);
}
}
return F.NIL;
}
use of org.matheclipse.core.interfaces.IComplex in project symja_android_library by axkr.
the class MathMLContentFormFactory method convert.
public void convert(final StringBuffer buf, final IExpr o, final int precedence) {
if (o instanceof IAST) {
final IAST f = ((IAST) o);
// System.out.println(f.getHeader().toString());
// IConverter converter = (IConverter)
// operTab.get(f.getHeader().toString());
// if (converter == null) {
// converter = reflection(f.getHeader().toString());
// if (converter == null || (converter.convert(buf, f, 0) == false))
// {
// convertHeadList(buf, f);
// }
// } else {
// if (converter.convert(buf, f, precedence) == false) {
// convertHeadList(buf, f);
// }
// }
IAST ast = f;
IAST temp;
if (f.topHead().hasFlatAttribute()) {
// associative
if ((temp = EvalAttributes.flatten(f)).isPresent()) {
ast = temp;
}
}
IExpr h = ast.head();
if (h.isSymbol()) {
IConverter converter = reflection(((ISymbol) h).getSymbolName());
if (converter != null) {
StringBuffer sb = new StringBuffer();
if (converter.convert(sb, ast, precedence)) {
buf.append(sb);
return;
}
}
}
convertAST(buf, ast);
return;
}
if (o instanceof INum) {
convertDouble(buf, (INum) o, precedence);
return;
}
if (o instanceof IComplexNum) {
convertDoubleComplex(buf, (IComplexNum) o, precedence);
return;
}
if (o instanceof IInteger) {
convertInteger(buf, (IInteger) o, precedence);
return;
}
if (o instanceof IFraction) {
convertFraction(buf, (IFraction) o, precedence);
return;
}
if (o instanceof IComplex) {
convertComplex(buf, (IComplex) o, precedence);
return;
}
if (o instanceof ISymbol) {
convertSymbol(buf, (ISymbol) o);
return;
}
convertString(buf, o.toString());
}
use of org.matheclipse.core.interfaces.IComplex in project symja_android_library by axkr.
the class MathMLFormFactory method convert.
public void convert(final StringBuffer buf, final IExpr o, final int precedence) {
String str = CONSTANT_EXPRS.get(o);
if (str != null) {
buf.append(str);
return;
}
if (o instanceof IAST) {
final IAST f = ((IAST) o);
IAST ast = f;
IAST temp;
if (f.topHead().hasFlatAttribute()) {
// associative
if ((temp = EvalAttributes.flatten(f)).isPresent()) {
ast = temp;
}
}
IExpr h = ast.head();
if (h.isSymbol()) {
IConverter converter = reflection(((ISymbol) h).getSymbolName());
if (converter != null) {
StringBuffer sb = new StringBuffer();
if (converter.convert(sb, ast, precedence)) {
buf.append(sb);
return;
}
}
}
convertAST(buf, ast);
return;
}
if (o instanceof INum) {
convertDouble(buf, (INum) o, precedence);
return;
}
if (o instanceof IComplexNum) {
convertDoubleComplex(buf, (IComplexNum) o, precedence);
return;
}
if (o instanceof IInteger) {
convertInteger(buf, (IInteger) o, precedence);
return;
}
if (o instanceof IFraction) {
convertFraction(buf, (IFraction) o, precedence);
return;
}
if (o instanceof IComplex) {
convertComplex(buf, (IComplex) o, precedence);
return;
}
if (o instanceof ISymbol) {
convertSymbol(buf, (ISymbol) o);
return;
}
convertString(buf, o.toString());
}
use of org.matheclipse.core.interfaces.IComplex in project symja_android_library by axkr.
the class ComplexSym method pow.
@Override
public IComplex pow(final int parm1) {
int temp = parm1;
if ((parm1 == 0) && fReal.isZero() && fImaginary.isZero()) {
throw new java.lang.ArithmeticException();
}
if (parm1 == 1) {
return this;
}
IComplex res = ONE;
if (parm1 < 0) {
temp *= -1;
for (int i = 0; i < temp; i++) {
res = res.multiply(this);
}
final IRational d = res.getRealPart().multiply(res.getRealPart()).add(res.getImaginaryPart().multiply(res.getImaginaryPart()));
return ComplexSym.valueOf(res.getRealPart().divideBy(d), res.getImaginaryPart().negate().divideBy(d));
}
for (int i = 0; i < temp; i++) {
res = res.multiply(this);
}
return res;
}
use of org.matheclipse.core.interfaces.IComplex in project symja_android_library by axkr.
the class AbstractFunctionEvaluator method getPureImaginaryPart.
/**
* Check if <code>expr</code> is a pure imaginary number without a real
* part.
*
* @param expr
* @return <code>null</code>, if <code>expr</code> is not a pure imaginary
* number.
*/
public static IExpr getPureImaginaryPart(final IExpr expr) {
if (expr.isComplex() && ((IComplex) expr).re().isZero()) {
IComplex compl = (IComplex) expr;
return compl.im();
}
if (expr.isTimes()) {
IAST times = ((IAST) expr);
IExpr arg1 = times.arg1();
if (arg1.isComplex() && ((IComplex) arg1).re().isZero()) {
return times.setAtClone(1, ((IComplex) arg1).im());
}
}
return F.NIL;
}
Aggregations