@Override public IExpr evaluate(final IAST ast) { Validate.checkRange(ast, 2, 3); IExpr arg = F.evalExpandAll(ast.get(1)); try { if (arg.isTimes() || arg.isPower()) { IExpr[] parts = Apart.getFractionalParts(arg); if (parts != null) { if (parts[0].isPlus() && parts[1].isPlus()) { IAST[] numParts = ((IAST) parts[0]).split(new PolynomialPredicate()); IAST[] denParts = ((IAST) parts[1]).split(new PolynomialPredicate()); IExpr denParts0 = F.eval(denParts[0]); if (!denParts0.equals(F.C1)) { IExpr[] result = Cancel.cancelGCD(numParts[0], denParts0); if (result != null) { return F.Times( result[0], numParts[1], F.Power(F.Times(result[1], denParts[1]), F.CN1)); } } } } } } catch (JASConversionException jce) { if (Config.DEBUG) { jce.printStackTrace(); } } return arg; }
@Override public IExpr evaluate(final IAST ast) { Validate.checkSize(ast, 2); if (ast.get(1).isAST()) { return ast.get(1).replaceRepeated(REPLACE_RULES); } return ast.get(1); }
@Override public IExpr numericEval(final IAST functionList) { Validate.checkSize(functionList, 2); if (functionList.get(1) instanceof Num) { return numericEvalD1((Num) functionList.get(1)); } if (functionList.get(1) instanceof ComplexNum) { return numericEvalDC1((ComplexNum) functionList.get(1)); } return numericEvalArg1(functionList.get(1)); }
public IExpr evaluate(final IAST ast) { Validate.checkSize(ast, 3); if (ast.get(1).isSymbol()) { if (ast.get(2).isAST("Blank")) { IAST blank = (IAST) ast.get(2); if (blank.size() == 1) { return F.$p((ISymbol) ast.get(1)); } if (blank.size() == 2) { return F.$p((ISymbol) ast.get(1), blank.get(1)); } } if (ast.get(2).isPattern()) { IPattern blank = (IPattern) ast.get(2); if (blank.isBlank()) { return F.$p((ISymbol) ast.get(1), blank.getCondition()); } } } return null; }
@Override public IExpr evaluate(final IAST ast) { Validate.checkRange(ast, 3); if (ast.size() == 3 && ast.get(2).isList() && ((IAST) ast.get(2)).size() == 4) { IAST list = (IAST) ast.get(2); if (ast.get(1).isPlus()) { return ((IAST) ast.get(1)).map(Functors.replace1st(F.Sum(F.Null, ast.get(2)))); } if (list.get(1).isSymbol() && list.get(2).isInteger() && list.get(3).isSymbol()) { final ISymbol var = (ISymbol) list.get(1); final IInteger from = (IInteger) list.get(2); final ISymbol to = (ISymbol) list.get(3); if (ast.get(1).isFree(var, true) && ast.get(1).isFree(to, true)) { if (from.equals(F.C1)) { return F.Times(to, ast.get(1)); } if (from.equals(F.C0)) { return F.Times(Plus(to, C1), ast.get(1)); } } else { if (ast.get(1).isTimes()) { // Sum[ Times[a,b,c,...], {var, from, to} ] IAST filterCollector = F.Times(); IAST restCollector = F.Times(); ((IAST) ast.get(1)) .filter( filterCollector, restCollector, new Predicate<IExpr>() { @Override public boolean apply(IExpr input) { return input.isFree(var, true) && input.isFree(to, true); } }); if (filterCollector.size() > 1) { if (restCollector.size() == 2) { filterCollector.add(F.Sum(restCollector.get(1), ast.get(2))); } else { filterCollector.add(F.Sum(restCollector, ast.get(2))); } return filterCollector; } } if (from.equals(F.C0)) { IExpr repl = ast.get(1).replaceAll(F.List(F.Rule(var, F.Slot(F.C1)), F.Rule(to, F.Slot(F.C2)))); if (repl != null) { IExpr temp = MAP_0_N.get(repl); if (temp != null) { return temp.replaceAll(F.Rule(F.Slot(F.C1), to)); } } } } if (from.isPositive()) { return F.Subtract( F.Sum(ast.get(1), F.List(var, C0, to)), F.Sum(ast.get(1), F.List(var, C0, from.minus(F.C1)))); } } } IAST resultList = Plus(); IExpr temp = evaluateTable(ast, resultList, C0); if (temp.equals(resultList)) { return null; } return temp; }
@Override public IExpr evaluate(final IAST ast) { Validate.checkSize(ast, 2); return evaluateArg1(ast.get(1)); }