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;
}
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!");
}
}
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;
}
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;
}
Aggregations