Search in sources :

Example 46 with ISignedNumber

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

the class FractionalPart method evaluate.

@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
    Validate.checkSize(ast, 2);
    IExpr arg1 = ast.arg1();
    ISignedNumber signedNumber = arg1.evalSignedNumber();
    if (signedNumber != null) {
        return signedNumberFractionalPart(signedNumber);
    }
    IExpr negExpr = AbstractFunctionEvaluator.getNormalizedNegativeExpression(arg1);
    if (negExpr.isPresent()) {
        return Negate(FractionalPart(negExpr));
    }
    return F.NIL;
}
Also used : ISignedNumber(org.matheclipse.core.interfaces.ISignedNumber) IExpr(org.matheclipse.core.interfaces.IExpr)

Example 47 with ISignedNumber

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

the class CoefficientList method coefficientList.

/**
	 * Get the coefficient list of a univariate polynomial.
	 * 
	 * @param polynomial
	 * @param variable
	 * @return <code>null</code> if the list couldn't be evaluated.
	 */
public static double[] coefficientList(IExpr polynomial, final ISymbol variable) throws JASConversionException {
    try {
        ExprPolynomialRing ring = new ExprPolynomialRing(F.List(variable));
        ExprPolynomial poly = ring.create(polynomial);
        // PolynomialOld poly = new PolynomialOld(polynomial, (ISymbol) variable);
        // if (!poly.isPolynomial()) {
        // throw new WrongArgumentType(polynomial, "Polynomial expected!");
        // }
        IAST list = poly.coefficientList();
        int degree = list.size() - 2;
        double[] result = new double[degree + 1];
        for (int i = 1; i < list.size(); i++) {
            ISignedNumber temp = list.get(i).evalSignedNumber();
            if (temp != null) {
                result[i - 1] = temp.doubleValue();
            } else {
                return null;
            }
        }
        return result;
    } catch (RuntimeException ex) {
        throw new WrongArgumentType(polynomial, "Polynomial expected!");
    }
}
Also used : ExprPolynomialRing(org.matheclipse.core.polynomials.ExprPolynomialRing) ISignedNumber(org.matheclipse.core.interfaces.ISignedNumber) WrongArgumentType(org.matheclipse.core.eval.exception.WrongArgumentType) IAST(org.matheclipse.core.interfaces.IAST) ExprPolynomial(org.matheclipse.core.polynomials.ExprPolynomial)

Example 48 with ISignedNumber

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

the class HeavisideTheta method evaluate.

@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
    int size = ast.size();
    if (size > 1) {
        for (int i = 1; i < size; i++) {
            IExpr expr = ast.get(i);
            ISignedNumber temp = expr.evalSignedNumber();
            if (temp != null) {
                if (temp.sign() < 0) {
                    return F.C0;
                } else if (temp.sign() > 0) {
                    continue;
                }
            } else {
                if (expr.isNegativeInfinity()) {
                    return F.C0;
                }
                if (expr.isInfinity()) {
                    continue;
                }
            }
            return F.NIL;
        }
    }
    return F.C1;
}
Also used : ISignedNumber(org.matheclipse.core.interfaces.ISignedNumber) IExpr(org.matheclipse.core.interfaces.IExpr)

Example 49 with ISignedNumber

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

the class IntegerPart method evaluate.

@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
    Validate.checkSize(ast, 2);
    try {
        IExpr arg1 = ast.arg1();
        ISignedNumber signedNumber = arg1.evalSignedNumber();
        if (signedNumber != null) {
            return signedNumberIntegerPart(signedNumber);
        }
        if (arg1.isIntegerResult()) {
            return arg1;
        }
        IExpr negExpr = AbstractFunctionEvaluator.getNormalizedNegativeExpression(arg1);
        if (negExpr.isPresent()) {
            return Negate(IntegerPart(negExpr));
        }
    } catch (ArithmeticException ae) {
    // ISignedNumber#floor() or #ceil() may throw ArithmeticException
    }
    return F.NIL;
}
Also used : ISignedNumber(org.matheclipse.core.interfaces.ISignedNumber) IExpr(org.matheclipse.core.interfaces.IExpr)

Aggregations

ISignedNumber (org.matheclipse.core.interfaces.ISignedNumber)49 IExpr (org.matheclipse.core.interfaces.IExpr)31 IAST (org.matheclipse.core.interfaces.IAST)22 ISymbol (org.matheclipse.core.interfaces.ISymbol)10 WrongArgumentType (org.matheclipse.core.eval.exception.WrongArgumentType)7 LinearConstraint (org.hipparchus.optim.linear.LinearConstraint)3 Num (org.matheclipse.core.expression.Num)3 IInteger (org.matheclipse.core.interfaces.IInteger)3 IntegerDistribution (org.hipparchus.distribution.IntegerDistribution)2 RealDistribution (org.hipparchus.distribution.RealDistribution)2 MathIllegalStateException (org.hipparchus.exception.MathIllegalStateException)2 LinearObjectiveFunction (org.hipparchus.optim.linear.LinearObjectiveFunction)2 WrappedException (org.matheclipse.core.eval.exception.WrappedException)2 Options (org.matheclipse.core.eval.util.Options)2 ComplexNum (org.matheclipse.core.expression.ComplexNum)2 IComplex (org.matheclipse.core.interfaces.IComplex)2 IComplexNum (org.matheclipse.core.interfaces.IComplexNum)2 INum (org.matheclipse.core.interfaces.INum)2 IRational (org.matheclipse.core.interfaces.IRational)2 ArrayList (java.util.ArrayList)1