Search in sources :

Example 21 with IFraction

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

the class BigFractionSym method multiply.

@Override
public IRational multiply(IRational parm1) {
    if (parm1.isOne()) {
        return this;
    }
    if (parm1.isZero()) {
        return parm1;
    }
    if (parm1.isMinusOne()) {
        return this.negate();
    }
    if (parm1 instanceof IFraction) {
        return mul((IFraction) parm1);
    }
    IInteger p1 = (IInteger) parm1;
    BigInteger newnum = toBigNumerator().multiply(p1.toBigNumerator());
    return valueOf(newnum, toBigDenominator());
}
Also used : IFraction(org.matheclipse.core.interfaces.IFraction) IInteger(org.matheclipse.core.interfaces.IInteger) BigInteger(java.math.BigInteger)

Example 22 with IFraction

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

the class AbstractArgMultiple method binaryOperator.

@Override
public IExpr binaryOperator(final IExpr o0, final IExpr o1) {
    IExpr result = F.NIL;
    if (o0 instanceof INum) {
        // use specialized methods for numeric mode
        if (o1 instanceof INum) {
            result = e2DblArg((INum) o0, (INum) o1);
        } else if (o1.isInteger()) {
            result = e2DblArg((INum) o0, F.num((IInteger) o1));
        } else if (o1.isFraction()) {
            result = e2DblArg((INum) o0, F.num((IFraction) o1));
        } else if (o1 instanceof IComplexNum) {
            if (o0 instanceof ApfloatNum) {
                result = e2DblComArg(F.complexNum(((ApfloatNum) o0).apfloatValue()), (IComplexNum) o1);
            } else {
                result = e2DblComArg(F.complexNum(((INum) o0).getRealPart()), (IComplexNum) o1);
            }
        }
        if (result.isPresent()) {
            return result;
        }
        return e2ObjArg(o0, o1);
    } else if (o1 instanceof INum) {
        // use specialized methods for numeric mode
        if (o0.isInteger()) {
            result = e2DblArg(F.num((IInteger) o0), (INum) o1);
        } else if (o0.isFraction()) {
            result = e2DblArg(F.num((IFraction) o0), (INum) o1);
        } else if (o0 instanceof IComplexNum) {
            if (o1 instanceof ApfloatNum) {
                result = e2DblComArg((IComplexNum) o0, F.complexNum(((ApfloatNum) o1).apfloatValue()));
            } else {
                result = e2DblComArg((IComplexNum) o0, F.complexNum(((INum) o1).getRealPart()));
            }
        }
        if (result.isPresent()) {
            return result;
        }
        return e2ObjArg(o0, o1);
    }
    if (o0 instanceof IComplexNum) {
        // use specialized methods for complex numeric mode
        if (o1 instanceof INum) {
            result = e2DblComArg((IComplexNum) o0, F.complexNum(((INum) o1).getRealPart()));
        } else if (o1.isInteger()) {
            result = e2DblComArg((IComplexNum) o0, F.complexNum((IInteger) o1));
        } else if (o1.isFraction()) {
            result = e2DblComArg((IComplexNum) o0, F.complexNum((IFraction) o1));
        } else if (o1 instanceof IComplexNum) {
            result = e2DblComArg((IComplexNum) o0, (IComplexNum) o1);
        }
        if (result.isPresent()) {
            return result;
        }
        return e2ObjArg(o0, o1);
    } else if (o1 instanceof IComplexNum) {
        // use specialized methods for complex numeric mode
        if (o0 instanceof INum) {
            result = e2DblComArg(F.complexNum(((INum) o0).getRealPart()), (IComplexNum) o1);
        } else if (o0.isInteger()) {
            result = e2DblComArg(F.complexNum((IInteger) o0), (IComplexNum) o1);
        } else if (o0.isFraction()) {
            result = e2DblComArg(F.complexNum((IFraction) o0), (IComplexNum) o1);
        }
        if (result.isPresent()) {
            return result;
        }
        return e2ObjArg(o0, o1);
    }
    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);
        }
    } else 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);
        }
    } else if (o0 instanceof IComplex) {
        if (o1 instanceof IInteger) {
            return eComIntArg((IComplex) o0, (IInteger) o1);
        }
        if (o1 instanceof IComplex) {
            return e2ComArg((IComplex) o0, (IComplex) o1);
        }
    }
    result = e2ObjArg(o0, o1);
    if (result.isPresent()) {
        return result;
    }
    if (o0 instanceof ISymbol) {
        if (o1 instanceof ISymbol) {
            return e2SymArg((ISymbol) o0, (ISymbol) o1);
        }
    }
    if (o0 instanceof IAST) {
        IAST a0 = (IAST) o0;
        if (o1 instanceof IInteger) {
            return eFunIntArg(a0, (IInteger) o1);
        }
        if (o1 instanceof IAST) {
            return e2FunArg(a0, (IAST) o1);
        }
    }
    return F.NIL;
}
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) ApfloatNum(org.matheclipse.core.expression.ApfloatNum) INum(org.matheclipse.core.interfaces.INum)

Example 23 with IFraction

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

the class AbstractArg2 method binaryOperator.

public IExpr binaryOperator(final IExpr o0, final IExpr o1) {
    IExpr result = F.NIL;
    if (o0.isNumber() && o1.isNumber()) {
        result = e2NumericArg(o0, o1);
        if (result.isPresent()) {
            return result;
        }
    }
    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;
}
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) IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST)

Example 24 with IFraction

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

the class NumberTest method testPower.

public void testPower() {
    IFraction f = FractionSym.valueOf(2, 3);
    assertEquals(f.pow(-2).toString(), "9/4");
    IFraction f0 = FractionSym.valueOf(5, 14);
    assertEquals(f0.pow(2).toString(), "25/196");
}
Also used : IFraction(org.matheclipse.core.interfaces.IFraction)

Example 25 with IFraction

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

the class JASConvert method monomialToExpr.

public boolean monomialToExpr(BigRational coeff, ExpVector exp, IAST monomTimes) {
    if (!coeff.isONE()) {
        IFraction coeffValue = F.fraction(coeff.numerator(), coeff.denominator());
        monomTimes.append(coeffValue);
    }
    return expVectorToExpr(exp, monomTimes);
}
Also used : IFraction(org.matheclipse.core.interfaces.IFraction)

Aggregations

IFraction (org.matheclipse.core.interfaces.IFraction)29 IInteger (org.matheclipse.core.interfaces.IInteger)16 IExpr (org.matheclipse.core.interfaces.IExpr)14 IAST (org.matheclipse.core.interfaces.IAST)11 ISymbol (org.matheclipse.core.interfaces.ISymbol)9 BigInteger (java.math.BigInteger)8 INum (org.matheclipse.core.interfaces.INum)7 IComplex (org.matheclipse.core.interfaces.IComplex)6 IComplexNum (org.matheclipse.core.interfaces.IComplexNum)6 GenPolynomial (edu.jas.poly.GenPolynomial)3 WrongArgumentType (org.matheclipse.core.eval.exception.WrongArgumentType)3 ExpVector (edu.jas.poly.ExpVector)2 BigFraction (org.hipparchus.fraction.BigFraction)2 JASIExpr (org.matheclipse.core.convert.JASIExpr)2 ApfloatNum (org.matheclipse.core.expression.ApfloatNum)2 IRational (org.matheclipse.core.interfaces.IRational)2 BigInteger (edu.jas.arith.BigInteger)1 BigRational (edu.jas.arith.BigRational)1 ModLong (edu.jas.arith.ModLong)1 ApcomplexNum (org.matheclipse.core.expression.ApcomplexNum)1