use of org.matheclipse.core.interfaces.IInteger in project symja_android_library by axkr.
the class Series method createSeriesData.
/**
*
* @param function
* the function which should be generated as a power series
* @param x
* the variable
* @param x0
* the point to do the power expansion for
* @param n
* the order of the expansion
* @param step
* @return
*/
private IExpr createSeriesData(final IExpr function, IExpr x, IExpr x0, final int n, IExpr step) {
IInteger nExpr = F.integer(n);
IAST result = F.List();
IAST seriesData = F.SeriesData(x, x0, result, x0, F.Plus(nExpr, step), step);
IExpr derivedFunction = function;
for (int i = 0; i <= n; i++) {
result.append(F.Times(F.Power(F.Factorial(F.integer(i)), F.CN1), F.ReplaceAll(derivedFunction, F.Rule(x, x0))));
derivedFunction = F.D(derivedFunction, x);
}
return seriesData;
}
use of org.matheclipse.core.interfaces.IInteger in project symja_android_library by axkr.
the class RandomInteger method evaluate.
@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
Validate.checkSize(ast, 2);
if (ast.arg1().isInteger()) {
// RandomInteger[100] gives an integer between 0 and 100
BigInteger n = ((IInteger) ast.arg1()).toBigNumerator();
BigInteger r;
do {
r = new BigInteger(n.bitLength(), RANDOM);
} while (r.compareTo(n) >= 0);
return F.integer(r);
}
return F.NIL;
}
use of org.matheclipse.core.interfaces.IInteger 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;
}
use of org.matheclipse.core.interfaces.IInteger in project symja_android_library by axkr.
the class Validate method checkListOfLongs.
/**
* Check the argument, if it's an {@code IAST} of {@code long} values in the range [{@code startValue},
* Long.MAX_VALUE]
*
* @throws WrongArgumentType
*/
public static long[] checkListOfLongs(IExpr arg, long startValue) {
if (arg.isList()) {
IAST list = (IAST) arg;
long[] result = new long[list.size() - 1];
long longValue = 0;
try {
IExpr expr;
for (int i = 1; i < list.size(); i++) {
expr = list.get(i);
// the following may throw an ArithmeticException
if (expr instanceof IInteger) {
longValue = ((IInteger) expr).toLong();
} else if (expr instanceof INum) {
longValue = ((INum) expr).toLong();
}
if (startValue > longValue) {
throw new WrongArgumentType(expr, "Trying to convert the expression into the integer range: " + startValue + " - " + Long.MAX_VALUE);
}
result[i - 1] = longValue;
}
return result;
} catch (ArithmeticException ae) {
//
}
}
throw new WrongArgumentType(arg, "Trying to convert the given list into a list of long numbers: " + arg);
}
use of org.matheclipse.core.interfaces.IInteger 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;
}
Aggregations