All integrate() hanging is due to heurisch(), which means that none of
the other algorithms could do the integral. There is some hope that
when the matrices and the new polys are reworked by Mateusz that
heurisch will become faster, but ultimately, I would like to
completely replace it with better algorithms.

The risch algorithm can handle trigonometric functions, but they are
not implemented yet.  However, it can integrate exponentials, so if
you first do .rewrite(exp) to convert it to complex exponentials, it
will integrate instantly. In this case, rewriting back to sin and
simplifying gives a nice answer. In general, it doesn't, though, so we
still need to work on that.

In [6]: integrate((sin(pi*(x - S(1)/2))**2).rewrite(exp),
x).rewrite(cos).simplify()
Out[6]:
2⋅π⋅x + sin(2⋅π⋅x)
──────────────────
       4⋅π

Another option that is really easy, even if you don't know anything
about the Risch algorithm, is to extend David Li's new
manualintegrate, which just integrates the function as you would by
hand. In this case, the way you integrate sin**2 or cos**2 is to first
rewrite them using the double angle formula. So you should add this
rule to manualintegrate.py.  The other benefit of this is that rules
in manual integrate translate directly to step-by-step integration
like at https://github.com/sympy/sympy_gamma/pull/11 (see for example
http://sympy-gamma-li.appspot.com/input/?i=integrate%28x*exp%28x%29%2C+x%29).

Aaron Meurer

On Tue, Apr 30, 2013 at 4:43 PM, Ondřej Čertík <[email protected]> wrote:
> Hi,
>
> Today I needed to do some 3d integral, and it hangs [1], but I managed
> to isolate the problem
> to this very simple example:
>
> integrate(sin(pi*(x - S(1)/2))**2, x)
>
> The correct solution is not complicated [2]. Any ideas how to fix this
> simple problem?
> It will probably also fix the more difficult and messy 3D integral
> from [1], but even if it doesn't, it'd be nice to be able to do this
> simple integral anyway.
>
> Thanks,
> Ondrej
>
>
> [1] http://code.google.com/p/sympy/issues/detail?id=3793
> [2] 
> http://www.wolframalpha.com/input/?i=integrate%28sin%28pi*%28x+-+1%2F2%29%29**2%2C+x%29
>
> --
> You received this message because you are subscribed to the Google Groups 
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/sympy?hl=en-US.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to