Search in sources :

Example 16 with IComplex

use of org.matheclipse.core.interfaces.IComplex in project symja_android_library by axkr.

the class OutputFormFactory method convertTimesOperator.

private void convertTimesOperator(final Appendable buf, final IAST timesAST, final InfixOperator oper, final int precedence, boolean caller) throws IOException {
    boolean showOperator = true;
    int currPrecedence = oper.getPrecedence();
    if (currPrecedence < precedence) {
        append(buf, "(");
    }
    if (timesAST.size() > 1) {
        IExpr arg1 = timesAST.arg1();
        if (arg1.isReal() && timesAST.size() > 2 && !timesAST.arg2().isNumber()) {
            if (arg1.isMinusOne()) {
                append(buf, fInputForm && (caller == PLUS_CALL) ? " - " : "-");
                showOperator = false;
            } else {
                convertNumber(buf, (ISignedNumber) arg1, Precedence.PLUS, caller);
            }
        } else if (arg1.isComplex() && timesAST.size() > 2) {
            convertComplex(buf, (IComplex) arg1, oper.getPrecedence(), caller);
        } else {
            if (caller == PLUS_CALL) {
                append(buf, fInputForm ? " + " : "+");
            }
            convert(buf, arg1, oper.getPrecedence(), false);
        }
    }
    for (int i = 2; i < timesAST.size(); i++) {
        if (showOperator) {
            append(buf, oper.getOperatorString());
        } else {
            showOperator = true;
        }
        convert(buf, timesAST.get(i), oper.getPrecedence(), false);
    }
    if (currPrecedence < precedence) {
        append(buf, ")");
    }
}
Also used : IComplex(org.matheclipse.core.interfaces.IComplex) IExpr(org.matheclipse.core.interfaces.IExpr)

Example 17 with IComplex

use of org.matheclipse.core.interfaces.IComplex in project symja_android_library by axkr.

the class TeXFormFactory method convertInternal.

private void convertInternal(final StringBuilder buf, final Object o, final int precedence) {
    if (o instanceof IExpr) {
        IExpr expr = (IExpr) o;
        String str = CONSTANT_EXPRS.get(expr);
        if (str != null) {
            buf.append(str);
            return;
        }
    }
    if (o instanceof IAST) {
        final IAST f = ((IAST) o);
        IExpr h = f.head();
        if (h.isSymbol()) {
            final AbstractConverter converter = operTab.get((h));
            if (converter != null) {
                converter.setFactory(this);
                if (converter.convert(buf, f, precedence)) {
                    return;
                }
            }
        }
        convertAST(buf, f, 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 INum) {
        convertDouble(buf, (INum) o, precedence);
        return;
    }
    if (o instanceof IComplexNum) {
        if (o instanceof ApcomplexNum) {
            convertApcomplex(buf, ((ApcomplexNum) o).apcomplexValue(), precedence, NO_PLUS_CALL);
            return;
        }
        convertDoubleComplex(buf, (IComplexNum) o, precedence);
        return;
    }
    if (o instanceof IComplex) {
        convertComplex(buf, (IComplex) o, precedence);
        return;
    }
    if (o instanceof ISymbol) {
        convertSymbol(buf, (ISymbol) o);
        return;
    }
    // if (o instanceof BigFraction) {
    // convertFraction(buf, (BigFraction) o, precedence);
    // return;
    // }
    convertString(buf, o.toString());
}
Also used : IFraction(org.matheclipse.core.interfaces.IFraction) IComplex(org.matheclipse.core.interfaces.IComplex) ISymbol(org.matheclipse.core.interfaces.ISymbol) IInteger(org.matheclipse.core.interfaces.IInteger) IComplexNum(org.matheclipse.core.interfaces.IComplexNum) IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST) ApcomplexNum(org.matheclipse.core.expression.ApcomplexNum) INum(org.matheclipse.core.interfaces.INum)

Example 18 with IComplex

use of org.matheclipse.core.interfaces.IComplex in project symja_android_library by axkr.

the class AbstractFunctionEvaluator method pureImaginaryPart.

private static IExpr pureImaginaryPart(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.setAtCopy(1, ((IComplex) arg1).im());
        }
    }
    return F.NIL;
}
Also used : IComplex(org.matheclipse.core.interfaces.IComplex) IAST(org.matheclipse.core.interfaces.IAST) IExpr(org.matheclipse.core.interfaces.IExpr)

Example 19 with IComplex

use of org.matheclipse.core.interfaces.IComplex in project symja_android_library by axkr.

the class PolynomialHomogenizationNew method replaceTimes.

private IExpr replaceTimes(final IAST ast, final IExpr base, IExpr exp) {
    IExpr first = exp.first();
    if (first.isComplex() && ((IComplex) first).reRational().isZero()) {
        IRational imPart = ((IComplex) first).imRational();
        int exponent = imPart.toIntDefault();
        if (exponent == Integer.MIN_VALUE) {
            return replaceExpression(ast).orElse(ast);
        } else if (exponent > 0) {
            IASTMutable restExponent = ((IAST) exp).setAtCopy(1, F.CI);
            return F.Power(replaceExpression(base.power(restExponent)), exponent);
        }
        return replaceExpression(ast);
    }
    int exponent = first.toIntDefault();
    if (exponent == Integer.MIN_VALUE) {
        return replaceExpression(ast);
    } else if (exponent > 0) {
        IExpr rest = exp.rest().oneIdentity1();
        return F.Power(replaceExpression(base.power(rest)), exponent);
    }
    return replaceExpression(ast).orElse(ast);
}
Also used : IComplex(org.matheclipse.core.interfaces.IComplex) IRational(org.matheclipse.core.interfaces.IRational) IExpr(org.matheclipse.core.interfaces.IExpr) IASTMutable(org.matheclipse.core.interfaces.IASTMutable)

Example 20 with IComplex

use of org.matheclipse.core.interfaces.IComplex in project symja_android_library by axkr.

the class PolynomialHomogenizationNew method determineTimes.

private void determineTimes(final IAST ast, final IExpr base, IAST timesExponent) {
    IExpr first = timesExponent.first();
    if (first.isComplex() && ((IComplex) first).reRational().isZero()) {
        IRational pureImPart = ((IComplex) first).imRational();
        int exponent = pureImPart.toIntDefault();
        if (exponent == Integer.MIN_VALUE) {
            replaceExpressionLCM(ast, F.C1);
            return;
        } else if (exponent > 0) {
            IASTMutable restExponent = timesExponent.setAtCopy(1, F.CI);
            replaceExpressionLCM(base.power(restExponent), F.C1);
            return;
        }
        replaceExpressionLCM(ast, F.C1);
        return;
    }
    int exponent = first.toIntDefault();
    if (exponent == Integer.MIN_VALUE) {
        replaceExpressionLCM(ast, F.C1);
        return;
    } else if (exponent > 0) {
        IExpr rest = timesExponent.rest().oneIdentity1();
        replaceExpressionLCM(base.power(rest), F.C1);
        return;
    }
    replaceExpressionLCM(ast, F.C1);
}
Also used : IComplex(org.matheclipse.core.interfaces.IComplex) IRational(org.matheclipse.core.interfaces.IRational) IExpr(org.matheclipse.core.interfaces.IExpr) IASTMutable(org.matheclipse.core.interfaces.IASTMutable)

Aggregations

IComplex (org.matheclipse.core.interfaces.IComplex)22 IExpr (org.matheclipse.core.interfaces.IExpr)18 IAST (org.matheclipse.core.interfaces.IAST)13 ISymbol (org.matheclipse.core.interfaces.ISymbol)11 IComplexNum (org.matheclipse.core.interfaces.IComplexNum)10 IInteger (org.matheclipse.core.interfaces.IInteger)10 IFraction (org.matheclipse.core.interfaces.IFraction)9 INum (org.matheclipse.core.interfaces.INum)8 IRational (org.matheclipse.core.interfaces.IRational)6 IASTMutable (org.matheclipse.core.interfaces.IASTMutable)4 ISignedNumber (org.matheclipse.core.interfaces.ISignedNumber)4 ApcomplexNum (org.matheclipse.core.expression.ApcomplexNum)3 ApfloatNum (org.matheclipse.core.expression.ApfloatNum)3 JASConversionException (org.matheclipse.core.eval.exception.JASConversionException)2 ComplexNum (org.matheclipse.core.expression.ComplexNum)2 Num (org.matheclipse.core.expression.Num)2 INumber (org.matheclipse.core.interfaces.INumber)2 IPatternObject (org.matheclipse.core.interfaces.IPatternObject)2 InfixOperator (org.matheclipse.parser.client.operator.InfixOperator)2 Operator (org.matheclipse.parser.client.operator.Operator)2