@Override public void addNonFractionalPart(GenPolynomial<BigRational> genPolynomial) { IExpr temp = F.eval(jas.rationalPoly2Expr(genPolynomial, false)); if (temp.isAST()) { ((IAST) temp).addEvalFlags(IAST.IS_DECOMPOSED_PARTIAL_FRACTION); } result.append(F.Integrate(temp, x)); }
/** * Solve linear ODE. * * @param p * coefficient of degree 1 * @param q * coefficient of degree 0 * @param xVar * variable * @param engine * the evaluation engine * @return <code>F.NIL</code> if the evaluation was not possible */ private IExpr linearODE(IExpr p, IExpr q, IExpr xVar, IExpr C_1, EvalEngine engine) { // integrate p IExpr pInt = engine.evaluate(F.Exp(F.Integrate(p, xVar))); if (q.isZero()) { return engine.evaluate(F.Divide(C_1, pInt)); } else { IExpr qInt = engine.evaluate(F.Plus(C_1, F.Expand(F.Integrate(F.Times(F.CN1, q, pInt), xVar)))); return engine.evaluate(F.Expand(F.Divide(qInt, pInt))); } }
/** * See <a href="http://en.wikipedia.org/wiki/Integration_by_parts">Wikipedia- * Integration by parts</a> * * @param f * @param g * @param symbol * @return */ private static IExpr integrateByParts(IExpr f, IExpr g, ISymbol symbol) { EvalEngine engine = EvalEngine.get(); int limit = engine.getRecursionLimit(); try { if (limit <= 0) { // set recursion limit engine.setRecursionLimit(128); } IExpr fIntegrated = F.eval(F.Integrate(f, symbol)); if (!fIntegrated.isFree(Integrate, true)) { return null; } IExpr gDerived = F.eval(F.D(g, symbol)); return F.eval(F.Plus(F.Times(fIntegrated, g), F.Times(F.CN1, F.Integrate(F.Times(fIntegrated, gDerived), symbol)))); } catch (RecursionLimitExceeded rle) { engine.setRecursionLimit(limit); } finally { engine.setRecursionLimit(limit); } return null; }
engine.setRecursionLimit(Config.INTEGRATE_BY_PARTS_RECURSION_LIMIT); IExpr firstIntegrate = F.eval(F.Integrate(f, x)); if (!firstIntegrate.isFreeAST(Integrate)) { return F.NIL; IExpr second2Integrate = F.eval(F.Integrate(F.Times(gDerived, firstIntegrate), x)); if (!second2Integrate.isFreeAST(Integrate)) { return F.NIL;
IExpr f = engine.evaluate(F.Together(F.Divide(d, n))); if (f.isFree(y)) { u = engine.evaluate(F.Exp(F.Integrate(f, x))); d = F.C0; } else { IExpr g = engine.evaluate(F.Simplify(F.Divide(d.negate(), m))); if (g.isFree(x)) { u = engine.evaluate(F.Exp(F.Integrate(g, y))); d = F.C0; IExpr g = engine.evaluate(F.Integrate(F.Times(u, m), x)); IExpr hp = engine.evaluate(F.Subtract(F.Times(u, n), F.D(g, y))); IExpr h = engine.evaluate(F.Integrate(hp, y)); return F.Equal(engine.evaluate(F.Plus(g, h)), F.CSymbol);
/** * Try using the <code>TrigReduce</code> function to get a <code>Plus(...)</code> expression which could be * integrated. * * @param timesAST * an IAST which is a <code>Times(...)</code> expression * @param arg2 * the symbol to get the indefinite integral for. * @return <code>F.NIL</code> if no trigonometric funtion could be found. */ private static IExpr integrateTimesTrigFunctions(final IAST timesAST, IExpr arg2) { Predicate<IExpr> isTrigFunction = Predicates.isAST(new ISymbol[] { F.Cos, F.Sin }); if (timesAST.has(isTrigFunction, false)) { // use a symbol which is not in the symbols map ISymbol pSymbol = new Symbol("$x$", Context.SYSTEM); IExpr fx = F.eval(F.TrigReduce(timesAST)); if (fx.isPlus()) { // Collect arguments for x // Sin(f_) -> Sin(Collect(f, arg2)) fx = F.eval(F.ReplaceAll(fx, F.List(F.Rule(F.Sin(F.$p(pSymbol)), F.Sin(F.Collect(pSymbol, arg2))), F.Rule(F.Cos(F.$p(pSymbol)), F.Cos(F.Collect(pSymbol, arg2)))))); // Integrate[a_+b_+...,x_] -> Integrate[a,x]+Integrate[b,x]+... return ((IAST) fx).mapThread(F.Integrate(null, arg2), 1); } } return F.NIL; }
fxExpr = F.Plus.of(engine, F.Integrate(F.Times(F.CN1, fxExpr), x), C_1); IExpr yEquation = F.Subtract.of(engine, gyExpr, fxExpr); IExpr result = Eliminate.extractVariable(yEquation, y, engine);
((IAST) temp).addEvalFlags(IAST.IS_DECOMPOSED_PARTIAL_FRACTION); result.add(F.Integrate(temp, x)); temp = Times(B, Plus(Times(Integrate( Power(Plus(c, Times(b, x), Times(a, Power(x, C2))), Plus(C1, Times(CN1, k))), x), Plus(Times(F.integer(-6L), a), Times(C4, a, k)), Power(Plus(CN1, k), CN1), Power(Plus(Times(CN1, Power(b, C2)), Times(C4, a, c)), CN1)), } else { temp = Plus(Times(Integrate(Power(Plus(c, Times(b, x), Times(a, Power(x, C2))), Times(CN1, k)), x), Plus(B, Times(CN1D2, A, Power(a, CN1), b))), Times(CN1D2, A, Power(a, CN1), Power(Plus(CN1, k), CN1), Power(Plus(c, Times(b, x), Times(a, Power(x, C2))), Times(CN1, Plus(CN1, k))))); ((IAST) temp).addEvalFlags(IAST.IS_DECOMPOSED_PARTIAL_FRACTION); result.add(F.Integrate(temp, x));
Times(Integrate( Power(Plus(c, Times(b, x), Times(a, Power(x, C2))), Plus(C1, Times(CN1, k))), x), Plus(Times(F.integer(-6L), a), Times(C4, a, k)), Power(Plus(CN1, k), CN1), Times(Integrate(Power(Plus(c, Times(b, x), Times(a, Power(x, C2))), Times(CN1, k)), x), Plus(B, Times(CN1D2, A, Power(a, CN1), b))), Times(CN1D2, A, Power(a, CN1), Power(Plus(CN1, k), CN1), ((IAST) temp).addEvalFlags(IAST.IS_DECOMPOSED_PARTIAL_FRACTION); result.append(F.Integrate(temp, x));