Search in sources :

Example 26 with IRational

use of org.matheclipse.core.interfaces.IRational 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 27 with IRational

use of org.matheclipse.core.interfaces.IRational 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)

Example 28 with IRational

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

the class PolynomialHomogenization 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 29 with IRational

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

the class PolynomialHomogenization 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)

Example 30 with IRational

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

the class PolynomialHomogenization method replacePower.

private IExpr replacePower(final IExpr exprPoly, ISignedNumber exp) {
    ISymbol symbol = substitutedExpr.get(exprPoly);
    if (symbol != null) {
        IInteger lcm = getLCM(symbol);
        if (lcm.isOne()) {
            lcm = F.C1;
        }
        if (lcm.isOne() && exp.isInteger()) {
            return F.Power(symbol, exp);
        }
        IRational rat = exp.rationalFactor();
        if (rat != null) {
            IInteger intExp = rat.multiply(lcm).numerator();
            int exponent = intExp.toIntDefault();
            if (exponent != Integer.MIN_VALUE) {
                if (exponent == 1) {
                    return symbol;
                }
                return F.Power(symbol, exponent);
            }
        }
        return F.Power(symbol, F.Times(lcm, exp));
    }
    return F.NIL;
}
Also used : ISymbol(org.matheclipse.core.interfaces.ISymbol) IInteger(org.matheclipse.core.interfaces.IInteger) IRational(org.matheclipse.core.interfaces.IRational)

Aggregations

IRational (org.matheclipse.core.interfaces.IRational)30 IExpr (org.matheclipse.core.interfaces.IExpr)17 IInteger (org.matheclipse.core.interfaces.IInteger)11 ISymbol (org.matheclipse.core.interfaces.ISymbol)8 IAST (org.matheclipse.core.interfaces.IAST)6 IComplex (org.matheclipse.core.interfaces.IComplex)6 EvalEngine (org.matheclipse.core.eval.EvalEngine)5 IASTMutable (org.matheclipse.core.interfaces.IASTMutable)5 IFraction (org.matheclipse.core.interfaces.IFraction)4 INum (org.matheclipse.core.interfaces.INum)4 ISignedNumber (org.matheclipse.core.interfaces.ISignedNumber)4 Num (org.matheclipse.core.expression.Num)3 IASTAppendable (org.matheclipse.core.interfaces.IASTAppendable)3 BigRational (edu.jas.arith.BigRational)2 GenPolynomial (edu.jas.poly.GenPolynomial)2 BigInteger (java.math.BigInteger)2 JASIExpr (org.matheclipse.core.convert.JASIExpr)2 ArgumentTypeException (org.matheclipse.core.eval.exception.ArgumentTypeException)2 LimitException (org.matheclipse.core.eval.exception.LimitException)2 Complex (edu.jas.poly.Complex)1