public static boolean polynomialQ(final IExpr polnomialExpr, final IAST variables) { try { IExpr expr = F.evalExpandAll(polnomialExpr); ASTRange r = new ASTRange(variables, 1); JASConvert<IExpr> jas = new JASConvert<IExpr>(r.toList(), new ExprRingFactory()); return jas.expr2IExprJAS(expr) != null; } catch (JASConversionException e) { // exception will be thrown if the expression is not a JAS polynomial } return false; }
public boolean apply(IAST ast) { return ast.args().compareAdjacent(new IsLEOrdered<IExpr>()); }
if (ast.size() > 3) { return ast.range(2).foldLeft(new BinaryEval(F.D), fx); return ((IAST) fx).args().map(F.List(), Functors.replace1st(ast)); if (xList.size() == 2 && xList.get(1).isList()) { IAST subList = (IAST) xList.get(1); return subList.args().mapLeft(F.List(), new BinaryEval(F.D), fx); } else if (xList.size() == 3 && xList.get(2).isInteger()) { n = Validate.checkIntType(xList, 2, 1); return listArg1.args().map(F.Plus(), new BinaryBindIth1st(listArg1, F.D(F.Null, ast.get(2)))); } else if ((header == F.Power) && (listArg1.size() == 3)) { if (listArg1.get(2).isNumber()) {
@Override public IExpr evaluate(final IAST ast) { Validate.checkSize(ast, 3); if (!ast.get(1).isAtom() && !ast.get(2).isAtom()) { final IAST result = F.List(); ((IAST) ast.get(1)).args().intersection(result, ((IAST) ast.get(2)).args()); return result.args().sort(ExprComparator.CONS); } return null; }
@Override public IExpr evaluate(final IAST functionList) { if (functionList.size() != 3) { return null; } if (!functionList.get(1).isAtom() && !functionList.get(2).isAtom()) { final IAST result = F.List(); ((IAST) functionList.get(1)).args().complement(result, ((IAST) functionList.get(2)).args()); return result.args().sort(ExprComparator.CONS); } return null; } }
/** * {@inheritDoc} */ public ASTRange args() { return new ASTRange(this, 1); }
public static IAST select(final IAST ast, final IExpr head, final int resultLimit) { return ast.args().filter(ast.copyHead(), Predicates.isTrue(head), resultLimit); }
private IAST expandTimesPlus(final IAST plusAST0, final IAST plusAST1) { // (a+b)*(c+d) -> a*c+a*d+b*c+b*d final IAST pList = Plus(); for (int i = 1; i < plusAST0.size(); i++) { plusAST1.args().map(pList, Functors.replace2nd(Times(plusAST0.get(i), F.Null))); } return pList; }
@Override public IExpr evaluate(final IAST ast) { Validate.checkRange(ast, 3); if (ast.args().any(AtomQ.CONST)) { return null; } final IAST result = F.List(); for (int i = 1; i < ast.size(); i++) { result.addAll((IAST) ast.get(i)); } return result; } }
public static IExpr evaluateNestList(final IAST ast) { try { if (ast.get(3).isAST()) { final IAST list = (IAST) ast.get(3); return list.args().foldLeft(new BinaryMap(F.ast(ast.get(1))), ast.get(2)); } } catch (final ArithmeticException e) { } return null; }
return ast.range(2).foldRight(new BinaryEval(F.Integrate), fx);
/** * Get the range of elements [start..end[ of the AST * * @return */ public ASTRange range(final int start, final int end) { return new ASTRange(this, start, end); }
@Override public IExpr evaluate(final IAST ast) { Validate.checkSize(ast, 2); ExprVariables eVar = new ExprVariables(ast.get(1)); if (!eVar.isSize(1)) { throw new WrongArgumentType(ast, ast.get(1), 1, "Factorization only implemented for univariate polynomials"); } try { IExpr expr = F.evalExpandAll(ast.get(1)); ASTRange r = new ASTRange(eVar.getVarList(), 1); List<IExpr> varList = r.toList(); // if (ast.size() == 3) { // return factorWithOption(ast, expr, varList, true); // } return factorList(expr, varList, true); } catch (JASConversionException jce) { // toInt() conversion failed if (Config.DEBUG) { jce.printStackTrace(); } } return null; }
/** * Get the range of elements [start..sizeOfAST[ of the AST * * @return */ public ASTRange range(final int start) { return new ASTRange(this, start, size()); }
@Override public IExpr evaluate(final IAST ast) { if (ast.size() != 2 && ast.size() != 3) { return null; } ExprVariables eVar = new ExprVariables(ast.get(1)); // if (!eVar.isSize(1)) { // throw new WrongArgumentType(ast, ast.get(1), 1, // "Factorization only implemented for univariate polynomials"); // } try { IExpr expr = F.evalExpandAll(ast.get(1)); ASTRange r = new ASTRange(eVar.getVarList(), 1); List<IExpr> varList = r.toList(); if (ast.size() == 3) { return factorWithOption(ast, expr, varList, false); } return factor(expr, varList, false); } catch (JASConversionException e) { if (Config.DEBUG) { e.printStackTrace(); } } return null; }
/** * Get the range of elements [0..sizeOfAST[ of the AST * * @return */ public ASTRange range() { return new ASTRange(this, 0, size()); }
@Override public IExpr evaluate(final IAST ast) { Validate.checkRange(ast, 2, 3); ExprVariables eVar = new ExprVariables(ast.get(1)); if (!eVar.isSize(1)) { throw new WrongArgumentType(ast, ast.get(1), 1, "Factorization only implemented for univariate polynomials"); } try { IExpr expr = F.evalExpandAll(ast.get(1)); ASTRange r = new ASTRange(eVar.getVarList(), 1); List<IExpr> varList = r.toList(); if (ast.size() == 3) { return factorWithOption(ast, expr, varList, true); } return factor(expr, varList, true); } catch (JASConversionException jce) { // toInt() conversion failed if (Config.DEBUG) { jce.printStackTrace(); } } return null; }