Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Partial answer : Fricas output seems to have interleaved "\n" characters garbling the interpretation of the returned strings. The workaround is to somehow obtain Frcas' expression as a string and feed it back to SR. The following horror happens to work :

sage: SR(fricas("unparse(integrate(%s,x)::InputForm)"%foo).sage())
1/60*(12*D*b^2*d^5*x^5 - 15*(D*b^2*c*d^4 - (2*D*a*b + C*b^2)*d^5)*x^4 + 20*(D*b^2*c^2*d^3 - (2*D*a*b + C*b^2)*c*d^4 + (D*a^2 + 2*C*a*b + B*b^2)*d^5)*x^3 - 30*(D*b^2*c^3*d^2 - (2*D*a*b + C*b^2)*c^2*d^3 + (D*a^2 + 2*C*a*b + B*b^2)*c*d^4 - (C*a^2 + 2*B*a*b + A*b^2)*d^5)*x^2 + 60*(D*b^2*c^4*d - (2*D*a*b + C*b^2)*c^3*d^2 + (D*a^2 + 2*C*a*b + B*b^2)*c^2*d^3 - (C*a^2 + 2*B*a*b + A*b^2)*c*d^4 + (B*a^2 + 2*A*a*b)*d^5)*x - 60*(D*b^2*c^5 - A*a^2*d^5 - (2*D*a*b + C*b^2)*c^4*d + (D*a^2 + 2*C*a*b + B*b^2)*c^3*d^2 - (C*a^2 + 2*B*a*b + A*b^2)*c^2*d^3 + (B*a^2 + 2*A*a*b)*c*d^4)*log(d*x + c))/d^6

but only because This result's input format in Fricas is parseable by Sagemath as a `Symbolic Expression' ; pure happenstance...

It turns out that this expression (a rational fracion with a 42 terms numerator, better seen after expand()sion...) differentiates back to the original integrand:

sage: bar=SR(fricas("unparse(integrate(%s,x)::InputForm)"%foo).sage())
sage: bool(bar.diff(x)==foo)
True

I intend to explore this further before filing a ticket : this recent thread on Fricas' mailing list gives me some hope of filing a useful report, rather than a rant...

HTH,

Note : : the first part of this answer is partly misleading. see the "IMPORTANT EDIT" below for the real explanation...

Partial answer : Fricas output seems to have interleaved "\n" characters garbling the interpretation of the returned strings. The workaround is to somehow obtain Frcas' expression as a string and feed it back to SR. The following horror happens to work :

sage: SR(fricas("unparse(integrate(%s,x)::InputForm)"%foo).sage())
1/60*(12*D*b^2*d^5*x^5 - 15*(D*b^2*c*d^4 - (2*D*a*b + C*b^2)*d^5)*x^4 + 20*(D*b^2*c^2*d^3 - (2*D*a*b + C*b^2)*c*d^4 + (D*a^2 + 2*C*a*b + B*b^2)*d^5)*x^3 - 30*(D*b^2*c^3*d^2 - (2*D*a*b + C*b^2)*c^2*d^3 + (D*a^2 + 2*C*a*b + B*b^2)*c*d^4 - (C*a^2 + 2*B*a*b + A*b^2)*d^5)*x^2 + 60*(D*b^2*c^4*d - (2*D*a*b + C*b^2)*c^3*d^2 + (D*a^2 + 2*C*a*b + B*b^2)*c^2*d^3 - (C*a^2 + 2*B*a*b + A*b^2)*c*d^4 + (B*a^2 + 2*A*a*b)*d^5)*x - 60*(D*b^2*c^5 - A*a^2*d^5 - (2*D*a*b + C*b^2)*c^4*d + (D*a^2 + 2*C*a*b + B*b^2)*c^3*d^2 - (C*a^2 + 2*B*a*b + A*b^2)*c^2*d^3 + (B*a^2 + 2*A*a*b)*c*d^4)*log(d*x + c))/d^6

but only because This result's input format in Fricas is parseable by Sagemath as a `Symbolic Expression' ; pure happenstance...

It turns out that this expression (a rational fracion with a 42 terms numerator, better seen after expand()sion...) differentiates back to the original integrand:

sage: bar=SR(fricas("unparse(integrate(%s,x)::InputForm)"%foo).sage())
sage: bool(bar.diff(x)==foo)
True

I intend to explore this further before filing a ticket : this recent thread on Fricas' mailing list gives me some hope of filing a useful report, rather than a rant...

HTH,

IMPORTANT EDIT :

It's much simpler (and much more difficult to fix) than that ! Contemplate :

sage: var('x d b c a D C A B')
(x, d, b, c, a, D, C, A, B)
sage: foo = (b*x + a)^2*(D*x^3 + C*x^2 + B*x + A)/(d*x + c)
sage: integrate(foo, x, algorithm="fricas")
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

Bandwidth savings : Snip...

TypeError: unsupported operand parent(s) for *: 'Integer Ring' and '<class 'function'>'
sage: var("capitalD")
capitalD
sage: integrate(foo.subs({D:capitalD}), x, algorithm="fricas")
1/60*(12*b^2*capitalD*d^5*x^5 - 15*(b^2*c*capitalD*d^4 - (C*b^2 + 2*a*b*capitalD)*d^5)*x^4 + 20*(b^2*c^2*capitalD*d^3 + (2*C*a*b + B*b^2 + a^2*capitalD)*d^5 - (C*b^2*c + 2*a*b*c*capitalD)*d^4)*x^3 - 30*(b^2*c^3*capitalD*d^2 - (C*a^2 + 2*B*a*b + A*b^2)*d^5 + (a^2*c*capitalD + (2*C*a*b + B*b^2)*c)*d^4 - (C*b^2*c^2 + 2*a*b*c^2*capitalD)*d^3)*x^2 + 60*(b^2*c^4*capitalD*d - (C*a^2 + 2*B*a*b + A*b^2)*c*d^4 + (B*a^2 + 2*A*a*b)*d^5 + (a^2*c^2*capitalD + (2*C*a*b + B*b^2)*c^2)*d^3 - (C*b^2*c^3 + 2*a*b*c^3*capitalD)*d^2)*x - 60*(b^2*c^5*capitalD - A*a^2*d^5 - (C*a^2 + 2*B*a*b + A*b^2)*c^2*d^3 + (B*a^2 + 2*A*a*b)*c*d^4 + (a^2*c^3*capitalD + (2*C*a*b + B*b^2)*c^3)*d^2 - (C*b^2*c^4 + 2*a*b*c^4*capitalD)*d)*log(d*x + c))/d^6

The cherry on the pie :

sage: bool(integrate(foo.subs({D:capitalD}), x, algorithm="fricas").diff(x).subs({capitalD:D})==foo)
True

The use of the variable D shadows the Fricas function D, which is not a problem for Fricas, but is not known to the fricas._sage_() method, which uses hardcoded equivalences for categorizing syntactic trees' atoms.

This one will be difficult to solve, but can at least be correctly filed : this is now Trac#31849.

The occurrence of "\n" characters in SR(fricas("unparse(integrate(%s,x)::InputForm)"%foo).sage()) may be happenstance. It was misleading...