Re: [sympy] integration with the square root of a non-negative expressions

2016-02-15 Thread Andrew Corrigan
Oscar,

Thanks again for your response and clarification,


> If you want to do sqrt(P(x)) with P(x) polynomial of degree k then I
> think you can have general solutions for k=1,2,3 and 4 (assuming P(x)
> has no repeated roots). Sympy can do k=1 and should be able to do 2
> with a bit of help. For 3 and 4 you want the elliptic integrals
> although maybe sympy doesn't do them yet.
>
> For k>4 there may be solutions for certain special cases of the
> polynomial coefficients. In general for a polynomial with symbolic
> coefficients I don't think that there exist well-known mathematical
> functions to represent the results.
>

Since ultimately I need to deal with the more general case (arbitrary k),
it sounds like I better try to use numerical integration instead.

-- 
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 sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAFR75vf%2BKBX93ju%3DpbtbPfJ2nv%2BeFURCPHe%2BHQAaLboQjguLuQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [sympy] integration with the square root of a non-negative expressions

2016-02-15 Thread Oscar Benjamin
On 15 February 2016 at 15:01, Andrew Corrigan  wrote:
> Thank you both for your replies.  I'm not sure I follow the discussion to be
> honest as to how it applies to my original problem.  In particular:
>>>
>>> Distilling this down you want to compute the integral of the square
>>> root of a quadratic
>
> I'm not sure that is accurate.

It is for the example you showed :).

>  If you are just referring to that it is
> (foo(xi))**2  + (bar(xi))**2, then yes the expression is quadratic in foo
> and bar.  But in general, foo(xi) and bar(xi) are themselves higher degree
> polynomials of xi (and in higher dimensions other coordinates too).  This is
> a very simple and minimal reproducing example: in this case foo and bar are
> linear polynomials so the whole expression is quadratic.

The example is not minimal. Much of your expression is a red herring
with symbols that are unimportant to people reading on this list. A
minimal example would be something like:

sqrt(ax^2 + bx + c)

> I have expressions
> I need to integrate, where foo(xi) and bar(xi) are higher-order polynomials
> terms of xi.

If you want to do sqrt(P(x)) with P(x) polynomial of degree k then I
think you can have general solutions for k=1,2,3 and 4 (assuming P(x)
has no repeated roots). Sympy can do k=1 and should be able to do 2
with a bit of help. For 3 and 4 you want the elliptic integrals
although maybe sympy doesn't do them yet.

For k>4 there may be solutions for certain special cases of the
polynomial coefficients. In general for a polynomial with symbolic
coefficients I don't think that there exist well-known mathematical
functions to represent the results.

--
Oscar

-- 
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 sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAHVvXxT-s_h6M5AvXPF6mYgXDOD6By1_zXekZ1gynrk3KnGHog%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [sympy] integration with the square root of a non-negative expressions

2016-02-15 Thread Alan Bromborsky
Your are talking about reduction to elliptic integrals -

https://en.wikipedia.org/wiki/Elliptic_integral

I do not think that sympy can currently do this (it would be a great
project)!


On Mon, Feb 15, 2016 at 10:01 AM, Andrew Corrigan  wrote:

> Thank you both for your replies.  I'm not sure I follow the discussion to
> be honest as to how it applies to my original problem.  In particular:
>
>> Distilling this down you want to compute the integral of the square
>>> root of a quadratic
>>
>> I'm not sure that is accurate.  If you are just referring to that it is
> (foo(xi))**2  + (bar(xi))**2, then yes the expression is quadratic in foo
> and bar.  But in general, foo(xi) and bar(xi) are themselves higher degree
> polynomials of xi (and in higher dimensions other coordinates too).  This
> is a very simple and minimal reproducing example: in this case foo and bar
> are linear polynomials so the whole expression is quadratic.  I have
> expressions I need to integrate, where foo(xi) and bar(xi) are higher-order
> polynomials terms of xi.
>
> --
> 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 sympy+unsubscr...@googlegroups.com.
> To post to this group, send email to sympy@googlegroups.com.
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/bfac9248-8d14-49f4-98ce-b934d279b310%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CALOxT-mJeD3QEmajoheg0r1irytHMX-kD0Hc-oYP3izRoNGj-A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [sympy] integration with the square root of a non-negative expressions

2016-02-15 Thread Andrew Corrigan
Thank you both for your replies.  I'm not sure I follow the discussion to 
be honest as to how it applies to my original problem.  In particular: 

> Distilling this down you want to compute the integral of the square
>> root of a quadratic
>
> I'm not sure that is accurate.  If you are just referring to that it is 
(foo(xi))**2  + (bar(xi))**2, then yes the expression is quadratic in foo 
and bar.  But in general, foo(xi) and bar(xi) are themselves higher degree 
polynomials of xi (and in higher dimensions other coordinates too).  This 
is a very simple and minimal reproducing example: in this case foo and bar 
are linear polynomials so the whole expression is quadratic.  I have 
expressions I need to integrate, where foo(xi) and bar(xi) are higher-order 
polynomials terms of xi.

-- 
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 sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/bfac9248-8d14-49f4-98ce-b934d279b310%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [sympy] integration with the square root of a non-negative expressions

2016-02-14 Thread Aaron Meurer
It looks like it can do it if you complete the square manually. So we just
need to have better support for doing this in the algorithm(s).

In [7]: integrate(sqrt(((x + S(1)/2)**2 + S(3)/4)), x)
Out[7]:
 ⎛2⋅√3⋅(x + 1/2)⎞
   3  3⋅asinh⎜──⎟
  (x + 1/2)   3⋅(x + 1/2)⎝  3   ⎠
─ + ─── + ───
   ____  8
  ╱2╱2
╲╱  4⋅(x + 1/2)  + 34⋅╲╱  4⋅(x + 1/2)  + 3


Aaron Meurer


On Sun, Feb 14, 2016 at 7:46 PM, Oscar Benjamin 
wrote:

> On 14 February 2016 at 15:17, Andrew Corrigan 
> wrote:
> > I'm having trouble computing a definite integral involving the sqrt of a
> > non-negative expression, as implemented below (computing the length of a
> > quadratic line in 2D).  It seems to fail.  I've generally had success
> using
> > sympy for integration, except for when a sqrt is present.
> >
> > If anyone has any advice on how to make this work, I would appreciate it
> > tremendously.  Thanks in advance!
> >
> > from sympy import *
> > x0,x1,x2,y0,y1,y2,xi = symbols('x0 x1 x2 y0 y1 y2 xi', real=True)
> > f_squared = (-4*x0*xi + 3*x0 - 4*x1*xi + x1 + 8*x2*xi - 4*x2)**2 +
> (4*xi*y0
> > + 4*xi*y1 - 8*xi*y2 - 3*y0 - y1 + 4*y2)**2
> > f = sqrt(f_squared)
> > integrate(f, (xi,0,1))
>
> Distilling this down you want to compute the integral of the square
> root of a quadratic. Sympy can do this in some simple cases:
>
> >>> sqrt(1 + x**2).integrate(x)
>  
> ╱  2
> x⋅╲╱  x  + 1asinh(x)
> ─ + 
>   22
>
> However it fails for slightly more complicated cases:
>
> >>> sqrt(1 + x + x**2).integrate(x)
> ⌠
> ⎮
> ⎮   ╱  2
> ⎮ ╲╱  x  + x + 1  dx
> ⌡
>
> This second form can always be reduced to the first by completing the
> square and changing variables. It seems that sympy is currently unable
> to do that though :(
>
> --
> Oscar
>
> --
> 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 sympy+unsubscr...@googlegroups.com.
> To post to this group, send email to sympy@googlegroups.com.
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/CAHVvXxS5ys%2Bkfmz1-ZM3ekadA-gwwQ9e%2BDSGd1P4oXAkcKFn%2BQ%40mail.gmail.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAKgW%3D6LUAp%2BjQgGdbME2jw20fumCU48RKXRRUozkfVRN-1D%2BEA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [sympy] integration with the square root of a non-negative expressions

2016-02-14 Thread Oscar Benjamin
On 14 February 2016 at 15:17, Andrew Corrigan  wrote:
> I'm having trouble computing a definite integral involving the sqrt of a
> non-negative expression, as implemented below (computing the length of a
> quadratic line in 2D).  It seems to fail.  I've generally had success using
> sympy for integration, except for when a sqrt is present.
>
> If anyone has any advice on how to make this work, I would appreciate it
> tremendously.  Thanks in advance!
>
> from sympy import *
> x0,x1,x2,y0,y1,y2,xi = symbols('x0 x1 x2 y0 y1 y2 xi', real=True)
> f_squared = (-4*x0*xi + 3*x0 - 4*x1*xi + x1 + 8*x2*xi - 4*x2)**2 + (4*xi*y0
> + 4*xi*y1 - 8*xi*y2 - 3*y0 - y1 + 4*y2)**2
> f = sqrt(f_squared)
> integrate(f, (xi,0,1))

Distilling this down you want to compute the integral of the square
root of a quadratic. Sympy can do this in some simple cases:

>>> sqrt(1 + x**2).integrate(x)
 
╱  2
x⋅╲╱  x  + 1asinh(x)
─ + 
  22

However it fails for slightly more complicated cases:

>>> sqrt(1 + x + x**2).integrate(x)
⌠
⎮
⎮   ╱  2
⎮ ╲╱  x  + x + 1  dx
⌡

This second form can always be reduced to the first by completing the
square and changing variables. It seems that sympy is currently unable
to do that though :(

--
Oscar

-- 
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 sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAHVvXxS5ys%2Bkfmz1-ZM3ekadA-gwwQ9e%2BDSGd1P4oXAkcKFn%2BQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[sympy] integration with the square root of a non-negative expressions

2016-02-14 Thread Andrew Corrigan
I'm having trouble computing a definite integral involving the sqrt of a 
non-negative expression, as implemented below (computing the length of a 
quadratic line in 2D).  It seems to fail.  I've generally had success using 
sympy for integration, except for when a sqrt is present.

If anyone has any advice on how to make this work, I would appreciate it 
tremendously.  Thanks in advance!

from sympy import *
x0,x1,x2,y0,y1,y2,xi = symbols('x0 x1 x2 y0 y1 y2 xi', real=True)
f_squared = (-4*x0*xi + 3*x0 - 4*x1*xi + x1 + 8*x2*xi - 4*x2)**2 + (4*xi*y0 
+ 4*xi*y1 - 8*xi*y2 - 3*y0 - y1 + 4*y2)**2
f = sqrt(f_squared)
integrate(f, (xi,0,1))





-- 
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 sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/896fa9c6-2073-432e-a38a-9bb609c33e8f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.