1 | initial version |
Sage can call various engines for computing integrals.
The default integration engine Sage calls is Maxima. It gets some integrals wrong, so it's always good to check by computing with several integration engines.
Here is how to tell Sage to ask SymPy, Maxima, Giac, Fricas to compute the integral.
Define the function:
sage: f(t) = (sin(2*t)*sin(t))/(cos(t)+3)
sage: assume(t, 'real')
Integrate (default choice of integration engine):
sage: a_2 = integrate(f(t), t, 0, pi)*2/(2*pi)
sage: a_2
-17
sage: integrate(f, t, 0, pi, algorithm='sympy')
-17*pi + 12*sqrt(2)*pi
sage: integrate(f, t, 0, pi, algorithm='maxima')
-17*pi
sage: integrate(f, t, 0, pi, algorithm='giac')
pi*(12*sqrt(2) - 17)
sage: integrate(f, t, 0, pi, algorithm='fricas')
-17*pi + 12*sqrt(2)*pi
See somewhat longer discussion as part of an answer to a recent question about integration in Sage:
Here is how to get all the results at once as a list:
sage: zz = ['sympy', 'maxima', 'giac', 'fricas']
sage: for z in zz:
....: print(f"{z}:", integrate(f, t, 0, pi, algorithm=z)/pi)
sympy: -(17*pi - 12*sqrt(2)*pi)/pi
maxima: -17
giac: 12*sqrt(2) - 17
fricas: -(17*pi - 12*sqrt(2)*pi)/pi
(Only include FriCAS if it is installed, otherwise an error will be raised instead of displaying the last result.)
To get the results in a list:
sage: zz = ['sympy', 'maxima', 'giac', 'fricas']
sage: aa = [integrate(f, t, 0, pi, algorithm=z) for z in zz]
sage: aa
[-17*pi + 12*sqrt(2)*pi,
-17*pi,
pi*(12*sqrt(2) - 17),
-17*pi + 12*sqrt(2)*pi]
Example on SageCell: