The problem with this method is that looking at all combinations
becomes *very* inefficient for Muls with many terms.  For example:

In [41]: %timeit integrate2(diff(x*sqrt(sin(x))), x)
1
2
1
2
1
2
1
2
1 loops, best of 3: 5.2 s per loop

At the end of the day, you'll get even worse performance than the
currently used heurisch, with a much lower success rate.  That isn't
to say that it isn't possible to make it more efficient, though.

For computing symbolic integration by parts, I think some logic in the
ODE module can be used, in particular, the exact ODE solver.  For
example:

In [34]: print dsolve(diff(f(x)*x), simplify=False, hint='1st_exact')
x*f(x) == C1

It's possible to recognize exact equations of any order, though
solvers for them have not been implemented yet.   But in general, if
you are trying to integrate an expression with a symbolic f(x),
converting it to a problem for dsolve() will give you better luck than
integrate() (but of course, we really should "integrate" the two).

Aaron Meurer

On Thu, Jul 12, 2012 at 5:05 PM, pallab <pallabb...@gmail.com> wrote:
> <code>
> from sympy import *
> import itertools as it
> import operator as op
>
> def byparts(expr,x,depth=1):
>     print depth
>     hintarr=[]
>     if expr.is_Mul:
>         for part in it.combinations(expr.args,depth):
>             part=reduce(op.mul,part)
>             rest=simplify(expr/part)
>             part_int=integrate(part,x)
>             #print part_int,rest
>             hint=simplify(part_int*diff(rest,x))
>             integral=rest*part_int
>             hintarr=hintarr+[(hint,integral)]
>
>     hintarr=hintarr+[(x*diff(expr,x),x*expr)]
>     return(dict(hintarr))
>
> def integrate2(expr,x,depth=1):
>     if expr.is_Add:
>         for part in expr.args:
>             rest=simplify(expr-part)
>
>             for depth in range(1,len(part.args)+1):
>                 byparts_dict=byparts(part,x,depth)
>                 #print rest, list(byparts_dict)
>                 if rest in byparts_dict:
>                     return(byparts_dict[rest])
> <\code>
>
>
> On Wednesday, July 11, 2012 1:23:01 PM UTC-4, pallab wrote:
>>
>> simple by parts integral can not be done:
>>
>> integrate(diff(x*f(x),x),x)
>>
>>
>> also can not do simple integral like:
>>
>> integrate(diff(x*sqrt(sin(x)),x),x)
>>
>>
>> best,
>>
>> Pallab
>>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/sympy/-/kqWwCQXDF1YJ.
>
> To post to this group, send email to sympy@googlegroups.com.
> To unsubscribe from this group, send email to
> sympy+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/sympy?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to sympy@googlegroups.com.
To unsubscribe from this group, send email to 
sympy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to