Skip to content
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

Solutions of cubic equation #21263

Closed
proy87 opened this issue Apr 8, 2021 · 5 comments · Fixed by #21276
Closed

Solutions of cubic equation #21263

proy87 opened this issue Apr 8, 2021 · 5 comments · Fixed by #21276
Labels

Comments

@proy87
Copy link

proy87 commented Apr 8, 2021

roots(x**3+3*x**2+3*x+y*z*t+1,x) gives the roots involving absolute values.
Wolframalpha gives other roots: https://www.wolframalpha.com/input/?i=x%5E3%2B3x%5E2%2B3x%2Babc%2B1%3D0%2C+solve+for+x

@oscarbenjamin
Copy link
Contributor

Are the roots actually different or are they different but equivalent expressions?

@oscarbenjamin
Copy link
Contributor

Looks like Wolfram Alpha uses a "complete the cube" formula i.e.:

x**3 + 3*x**2 + 3*x + 1 = - y*z*t
(x + 1)**3 = -y*z*t

The result from SymPy comes from the general cubic formula which often gives complicated representations.

@oscarbenjamin
Copy link
Contributor

I guess that the strategy for identifying this would be to take the coefficient say a of x**2 i.e.:

x**3 + a*x**2 + b*x + c

Then you can substitute x -> x - a/3 i.e.:

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

In [25]: p = x**3 + a*x**2 + b*x + c

In [26]: p
Out[26]: 
   2              3
a⋅x  + b⋅x + c + x 

In [27]: p.subs(x, x - a/3)
Out[27]: 
           2                              3
  ⎛  a    ⎞      ⎛  a    ⎞       ⎛  a    ⎞ 
a⋅⎜- ─ + x⎟  + b⋅⎜- ─ + x⎟ + c + ⎜- ─ + x⎟ 
  ⎝  3    ⎠      ⎝  3    ⎠       ⎝  3    ⎠ 

In [28]: p.subs(x, x - a/3).expand()
Out[28]: 
   3    2                       
2⋅a    a ⋅x   a⋅b              3
──── - ──── - ─── + b⋅x + c + x 
 27     3      3  

That gives the depressed cubic which may or may not have a linear term. In your example:

In [29]: p = x**3+3*x**2+3*x+y*z*t+1

In [30]: p
Out[30]: 
         3      2          
t⋅y⋅z + x  + 3⋅x  + 3⋅x + 1

In [31]: p.subs(x, x-1).expand()
Out[31]: 
         3
t⋅y⋅z + x 

@proy87
Copy link
Author

proy87 commented Apr 8, 2021

@oscarbenjamin , I don't think that the roots are equaivalent.

skirpichev added a commit to skirpichev/diofant that referenced this issue Apr 9, 2021
skirpichev added a commit to skirpichev/diofant that referenced this issue Apr 9, 2021
skirpichev added a commit to skirpichev/diofant that referenced this issue Apr 9, 2021
@smichr
Copy link
Member

smichr commented Apr 9, 2021

The solutions, when susbtituted into the orginal equation, all simplify to x*y*t/2 - sqrt(x**2*y**2*t**2)/2 which is only zero if any value is 0 or all are positive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants