use of org.matheclipse.core.interfaces.IInteger in project symja_android_library by axkr.
the class IntegerExponent method evaluate.
@Override
public IExpr evaluate(IAST ast, EvalEngine engine) {
Validate.checkRange(ast, 2, 3);
IInteger base = F.C10;
if (ast.isAST2()) {
IExpr arg2 = ast.arg2();
if (arg2.isInteger() && ((IInteger) arg2).compareInt(1) > 0) {
base = (IInteger) arg2;
} else {
return F.NIL;
}
}
IExpr arg1 = ast.arg1();
if (arg1.isInteger()) {
return ((IInteger) arg1).exponent(base);
}
return F.NIL;
}
use of org.matheclipse.core.interfaces.IInteger in project symja_android_library by axkr.
the class Limit method powerLimit.
private static IExpr powerLimit(final IAST powerAST, LimitData data) {
// IAST rule = data.getRule();
IExpr arg1 = powerAST.arg1();
IExpr arg2 = powerAST.arg1();
if (powerAST.arg2().equals(data.getSymbol()) && data.getLimitValue().isZero()) {
return F.C1;
}
if (arg1.isTimes() && arg2.isFree(data.getSymbol())) {
IAST isFreeResult = ((IAST) arg1).partitionTimes(Predicates.isFree(data.getSymbol()), F.C1, F.C1, F.List);
if (!isFreeResult.get(2).isOne()) {
return F.Times(F.Power(isFreeResult.get(1), arg2), data.limit(F.Power(isFreeResult.get(2), arg2)));
}
}
if (powerAST.arg2().isNumericFunction()) {
// Limit[a_^exp_,sym->lim] -> Limit[a,sym->lim]^exp
IExpr exp = powerAST.arg2();
// IExpr temp = F.evalQuiet(F.Limit(arg1.arg1(), rule));?
IExpr temp = evalLimitQuiet(powerAST.arg1(), data);
if (temp.isNumericFunction()) {
if (temp.isZero()) {
if (exp.isPositive()) {
// 0 ^ (positve exponent)
return F.C0;
}
if (exp.isNegative()) {
// 0 ^ (negative exponent)
if (exp.isInteger()) {
IInteger n = (IInteger) exp;
if (n.isEven()) {
return F.CInfinity;
}
if (data.getDirection() == DIRECTION_FROM_SMALLER_VALUES) {
return F.CNInfinity;
} else {
data.setDirection(DIRECTION_FROM_LARGER_VALUES);
return F.CInfinity;
}
} else if (exp.isFraction()) {
if (data.getDirection() != DIRECTION_FROM_SMALLER_VALUES) {
data.setDirection(DIRECTION_FROM_LARGER_VALUES);
return F.CInfinity;
}
}
}
return F.NIL;
}
return F.Power(temp, exp);
}
if (exp.isInteger()) {
IInteger n = (IInteger) exp;
if (temp.isInfinity()) {
if (n.isPositive()) {
return temp;
} else if (n.isNegative()) {
return F.C0;
}
return F.NIL;
} else if (temp.isNegativeInfinity()) {
if (n.isPositive()) {
if (n.isEven()) {
return F.CInfinity;
} else {
return F.CNInfinity;
}
} else if (n.isNegative()) {
return F.C0;
}
return F.NIL;
} else if (temp.equals(F.Indeterminate) || temp.isAST(F.Limit)) {
return F.NIL;
}
if (n.isPositive()) {
return F.Power(temp, n);
} else if (n.isNegative() && n.isEven()) {
return F.Power(temp, n);
}
}
}
return F.NIL;
}
use of org.matheclipse.core.interfaces.IInteger in project symja_android_library by axkr.
the class FrobeniusSolve method evaluate.
/** {@inheritDoc} */
@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
Validate.checkRange(ast, 3, 4);
if (ast.arg1().isList()) {
IAST list = ast.getAST(1);
try {
IInteger[][] equations = new IInteger[1][list.size()];
// format looks like: { { 12, 16, 20, 27, 123 } };
for (int i = 1; i < list.size(); i++) {
equations[0][i - 1] = (IInteger) list.get(i);
}
equations[0][list.size() - 1] = (IInteger) ast.arg2();
// all solutions
int numberOfSolutions = -1;
if (ast.size() == 4) {
numberOfSolutions = ((ISignedNumber) ast.arg3()).toInt();
}
FrobeniusSolver solver = new FrobeniusSolver(equations);
IInteger[] solution;
IAST result = F.List();
if (numberOfSolutions < 0) {
while ((solution = solver.take()) != null) {
result.append(Lists.asList(solution));
}
} else {
while ((solution = solver.take()) != null) {
if (--numberOfSolutions < 0) {
break;
}
result.append(Lists.asList(solution));
}
}
return result;
} catch (RuntimeException e) {
if (Config.SHOW_STACKTRACE) {
e.printStackTrace();
}
}
}
return null;
}
use of org.matheclipse.core.interfaces.IInteger in project symja_android_library by axkr.
the class SolutionProviderAbstract method currentRemainders.
@Override
public IInteger[] currentRemainders() {
IInteger[] remainders = new IInteger[coefficients.length];
IInteger factor = currentCounter.subtract(F.C1);
for (int i = 0; i < coefficients.length; ++i) {
remainders[i] = currentRemainder[i].subtract(coefficients[i].multiply(factor));
}
return remainders;
}
use of org.matheclipse.core.interfaces.IInteger in project symja_android_library by axkr.
the class JASIExpr method expr2IExprPoly.
private GenPolynomial<IExpr> expr2IExprPoly(final IExpr exprPoly) throws ArithmeticException, ClassCastException {
if (exprPoly instanceof IAST) {
final IAST ast = (IAST) exprPoly;
GenPolynomial<IExpr> result = fPolyFactory.getZERO();
GenPolynomial<IExpr> p = fPolyFactory.getZERO();
if (ast.isPlus()) {
IExpr expr = ast.arg1();
result = expr2IExprPoly(expr);
for (int i = 2; i < ast.size(); i++) {
expr = ast.get(i);
p = expr2IExprPoly(expr);
result = result.sum(p);
}
return result;
} else if (ast.isTimes()) {
IExpr expr = ast.arg1();
result = expr2IExprPoly(expr);
for (int i = 2; i < ast.size(); i++) {
expr = ast.get(i);
p = expr2IExprPoly(expr);
result = result.multiply(p);
}
return result;
} else if (ast.isPower()) {
final IExpr expr = ast.arg1();
if (expr instanceof ISymbol) {
ExpVector leer = fPolyFactory.evzero;
int ix = leer.indexVar(expr.toString(), fPolyFactory.getVars());
if (ix >= 0) {
int exponent = -1;
try {
exponent = Validate.checkPowerExponent(ast);
} catch (WrongArgumentType e) {
//
}
if (exponent < 0) {
throw new ArithmeticException("JASConvert:expr2Poly - invalid exponent: " + ast.arg2().toString());
}
ExpVector e = ExpVector.create(fVariables.size(), ix, exponent);
return fPolyFactory.getONE().multiply(e);
}
}
} else if (fNumericFunction) {
if (ast.isNumericFunction()) {
return new GenPolynomial<IExpr>(fPolyFactory, ast);
}
}
} else if (exprPoly instanceof ISymbol) {
ExpVector leer = fPolyFactory.evzero;
int ix = leer.indexVar(exprPoly.toString(), fPolyFactory.getVars());
if (ix >= 0) {
ExpVector e = ExpVector.create(fVariables.size(), ix, 1L);
return fPolyFactory.getONE().multiply(e);
}
if (fNumericFunction) {
if (exprPoly.isNumericFunction()) {
return new GenPolynomial<IExpr>(fPolyFactory, exprPoly);
}
throw new ClassCastException(exprPoly.toString());
} else {
return new GenPolynomial<IExpr>(fPolyFactory, exprPoly);
}
} else if (exprPoly instanceof IInteger) {
return new GenPolynomial<IExpr>(fPolyFactory, exprPoly);
} else if (exprPoly instanceof IFraction) {
return new GenPolynomial<IExpr>(fPolyFactory, exprPoly);
}
if (exprPoly.isFree(t -> fVariables.contains(t), true)) {
return new GenPolynomial<IExpr>(fPolyFactory, exprPoly);
} else {
for (int i = 0; i < fVariables.size(); i++) {
if (fVariables.get(i).equals(exprPoly)) {
ExpVector e = ExpVector.create(fVariables.size(), i, 1L);
return fPolyFactory.getONE().multiply(e);
}
}
}
throw new ClassCastException(exprPoly.toString());
}
Aggregations