New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Series expansion of the square root gives wrong result #11407

Open
astholkohtz opened this Issue Jul 18, 2016 · 0 comments

Comments

Projects
None yet
1 participant
@astholkohtz
Copy link

astholkohtz commented Jul 18, 2016

Whenever the constant term on the square root is a sum of 2 or more symbols, the series() function gets the expansion wrong

In [1]: from sympy import *

In [2]: a,b,c,x = symbols('a b c x')

In [3]: sqrt(a+b + c*x).series(x,0,1)
Out[3]: 5*sqrt(a + b)/16 + 15*b/(16*sqrt(a + b)) - 5*b**2*sqrt(a + b)/(16*(a**2 + 2*a*b + b**2)) + b**3*sqrt(a + b)/(16*(a**3 + 3*a**2*b + 3*a*b**2 + b**3)) + 15*a/(16*sqrt(a + b)) - 5*a*b*sqrt(a + b)/(8*(a**2 + 2*a*b + b**2)) + 3*a*b**2*sqrt(a + b)/(16*(a**3 + 3*a**2*b + 3*a*b**2 + b**3)) - 5*a**2*sqrt(a + b)/(16*(a**2 + 2*a*b + b**2)) + 3*a**2*b*sqrt(a + b)/(16*(a**3 + 3*a**2*b + 3*a*b**2 + b**3)) + a**3*sqrt(a + b)/(16*(a**3 + 3*a**2*b + 3*a*b**2 + b**3)) + O(x)

In [4]: sqrt(a+b+c + c*x).series(x,0,1)
Out[4]: 5*sqrt(a + b + c)/16 + 15*c/(16*sqrt(a + b + c)) - 5*c**2*sqrt(a + b + c)/(16*(a**2 + 2*a*b + 2*a*c + b**2 + 2*b*c + c**2)) + c**3*sqrt(a + b + c)/(16*(a**3 + 3*a**2*b + 3*a**2*c + 3*a*b**2 + 6*a*b*c + 3*a*c**2 + b**3 + 3*b**2*c + 3*b*c**2 + c**3)) + 15*b/(16*sqrt(a + b + c)) - 5*b*c*sqrt(a + b + c)/(8*(a**2 + 2*a*b + 2*a*c + b**2 + 2*b*c + c**2)) + 3*b*c**2*sqrt(a + b + c)/(16*(a**3 + 3*a**2*b + 3*a**2*c + 3*a*b**2 + 6*a*b*c + 3*a*c**2 + b**3 + 3*b**2*c + 3*b*c**2 + c**3)) - 5*b**2*sqrt(a + b + c)/(16*(a**2 + 2*a*b + 2*a*c + b**2 + 2*b*c + c**2)) + 3*b**2*c*sqrt(a + b + c)/(16*(a**3 + 3*a**2*b + 3*a**2*c + 3*a*b**2 + 6*a*b*c + 3*a*c**2 + b**3 + 3*b**2*c + 3*b*c**2 + c**3)) + b**3*sqrt(a + b + c)/(16*(a**3 + 3*a**2*b + 3*a**2*c + 3*a*b**2 + 6*a*b*c + 3*a*c**2 + b**3 + 3*b**2*c + 3*b*c**2 + c**3)) + 15*a/(16*sqrt(a + b + c)) - 5*a*c*sqrt(a + b + c)/(8*(a**2 + 2*a*b + 2*a*c + b**2 + 2*b*c + c**2)) + 3*a*c**2*sqrt(a + b + c)/(16*(a**3 + 3*a**2*b + 3*a**2*c + 3*a*b**2 + 6*a*b*c + 3*a*c**2 + b**3 + 3*b**2*c + 3*b*c**2 + c**3)) - 5*a*b*sqrt(a + b + c)/(8*(a**2 + 2*a*b + 2*a*c + b**2 + 2*b*c + c**2)) + 3*a*b*c*sqrt(a + b + c)/(8*(a**3 + 3*a**2*b + 3*a**2*c + 3*a*b**2 + 6*a*b*c + 3*a*c**2 + b**3 + 3*b**2*c + 3*b*c**2 + c**3)) + 3*a*b**2*sqrt(a + b + c)/(16*(a**3 + 3*a**2*b + 3*a**2*c + 3*a*b**2 + 6*a*b*c + 3*a*c**2 + b**3 + 3*b**2*c + 3*b*c**2 + c**3)) - 5*a**2*sqrt(a + b + c)/(16*(a**2 + 2*a*b + 2*a*c + b**2 + 2*b*c + c**2)) + 3*a**2*c*sqrt(a + b + c)/(16*(a**3 + 3*a**2*b + 3*a**2*c + 3*a*b**2 + 6*a*b*c + 3*a*c**2 + b**3 + 3*b**2*c + 3*b*c**2 + c**3)) + 3*a**2*b*sqrt(a + b + c)/(16*(a**3 + 3*a**2*b + 3*a**2*c + 3*a*b**2 + 6*a*b*c + 3*a*c**2 + b**3 + 3*b**2*c + 3*b*c**2 + c**3)) + a**3*sqrt(a + b + c)/(16*(a**3 + 3*a**2*b + 3*a**2*c + 3*a*b**2 + 6*a*b*c + 3*a*c**2 + b**3 + 3*b**2*c + 3*b*c**2 + c**3)) + O(x)

As long as the constant term is only one, series() gives the correct result

In [5]: sqrt(a + c*x).series(x,0,1)
Out[5]: sqrt(a) + O(x)

In [6]: sqrt(a + (a+b)*x).series(x,0,1)
Out[6]: sqrt(a) + O(x)

In [7]: sqrt(a + (a+b+c)*x).series(x,0,1)
Out[7]: sqrt(a) + O(x)

In [8]: sqrt(a + (a+b+c)*x).series(x,0,2)
Out[8]: x*(sqrt(a)/2 + b/(2*sqrt(a)) + c/(2*sqrt(a))) + sqrt(a) + O(x**2)

@astholkohtz astholkohtz changed the title series expansion of the square root gives wrong result Series expansion of the square root gives wrong result Jul 18, 2016

skirpichev added a commit to skirpichev/diofant that referenced this issue Jul 19, 2016

skirpichev added a commit to skirpichev/diofant that referenced this issue Jul 22, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment