0

The given polynomial is

p = Poly(x**3-x**2-2*x+1, x) # and a root as radical expression:
rt = 1/3 + (-7/2 - 21*sqrt(3)*I/2)**(1/3)/3 + (-7/2 + 21*sqrt(3)*I/2)**(1/3)/3 

substituting the root into the polynomial gives (simplified):

expr = 7*(-1 - 3*sqrt(3)*I)**(2/3)*(-1 + 3*sqrt(3)*I)**(1/3)/18 - \
7*2**(2/3)*(-7 + 21*sqrt(3)*I)**(1/3)/18 - \
7*2**(2/3)*(-7 - 21*sqrt(3)*I)**(1/3)/18 + \
7*(-1 - 3*sqrt(3)*I)**(1/3)*(-1 + 3*sqrt(3)*I)**(2/3)/18

but there is no way to make python show that this expression is zero:

expr == 0 # False

But :

expr.evalf()  # gives -0.e-131 - 0.e-132*I
  • I think you'd have to test if the expression is smaller than a threshold you define – user8408080 Mar 11 '21 at 10:22
  • 1
    Check this: [How to make sympy simplify a radical expression equaling zero](https://stackoverflow.com/questions/62745153/how-to-make-sympy-simplify-a-radical-expression-equaling-zero) – Alex Sveshnikov Mar 11 '21 at 10:26
  • verifying the minimal polynomial gives _x, this is the minimal polynomial of zero, so the problem is solved, moreover the minimal polynomial of the root gives the given polynomial so that's also OK. – Marc Bogaerts Mar 11 '21 at 11:48

2 Answers2

0

The issue here is floating point precision. A lot of the operations in your equation are going to be just a little off, especially for 2/3 or 1/3 which have infinte decimals. This is explained in answers such as this one How to avoid floating point errors?. To avoid the issue either truncate the result to within a specific number of decimal points maybe using round?

round(float_num, num_of_decimals)

And then evaluate whether that equals zero.

You may be tempted to kick the can down the road and use Decimal which has a higher precision but I doubt you'll get a flat zero even using that, some of those operations just don't yield numbers with a finite number of decimals so some quantity will be lost somewhere and you'll end up with a result very close to zero but not really it.

Do you need 131 or 132 decimal point precision for it to be zero?

vencaslac
  • 2,727
  • 1
  • 18
  • 29
0

There is a function minpoly to compute the minimal polynomial of an algebraic expression:

In [71]: rt = S(1)/3 + (-S(7)/2 - 21*sqrt(3)*I/2)**(S(1)/3)/3 + (-S(7)/2 + 21*sqrt(3)*I/2)**(S(1)/3)/3

In [72]: rt
Out[72]: 
        _______________       _______________
       ╱   7   21⋅√3⋅ⅈ       ╱   7   21⋅√3⋅ⅈ 
    3 ╱  - ─ - ───────    3 ╱  - ─ + ─────── 
1   ╲╱     2      2       ╲╱     2      2    
─ + ─────────────────── + ───────────────────
3            3                     3         

In [73]: minpoly(rt)
Out[73]: 
 3    2          
x  - x  - 2⋅x + 1

That shows that this is a root of the polynomial that you showed. In general of r is a root of a polynomial p then minpoly(r) is a polynomial that divides p.

We can also use minpoly to prove that the expression after substituting the root into the polynomial is zero:

In [74]: p = x**3-x**2-2*x+1

In [75]: p.subs(x, rt)
Out[75]: 
                                                                           2                                                  3 
          _______________   ⎛        _______________       _______________⎞    ⎛        _______________       _______________⎞  
         ╱   7   21⋅√3⋅ⅈ    ⎜       ╱   7   21⋅√3⋅ⅈ       ╱   7   21⋅√3⋅ⅈ ⎟    ⎜       ╱   7   21⋅√3⋅ⅈ       ╱   7   21⋅√3⋅ⅈ ⎟  
    2⋅3 ╱  - ─ + ───────    ⎜    3 ╱  - ─ - ───────    3 ╱  - ─ + ─────── ⎟    ⎜    3 ╱  - ─ - ───────    3 ╱  - ─ + ─────── ⎟  
1     ╲╱     2      2       ⎜1   ╲╱     2      2       ╲╱     2      2    ⎟    ⎜1   ╲╱     2      2       ╲╱     2      2    ⎟  
─ - ───────────────────── - ⎜─ + ─────────────────── + ───────────────────⎟  + ⎜─ + ─────────────────── + ───────────────────⎟  
3             3             ⎝3            3                     3         ⎠    ⎝3            3                     3         ⎠  

                       
        _______________
       ╱   7   21⋅√3⋅ⅈ 
  2⋅3 ╱  - ─ - ─────── 
    ╲╱     2      2    
- ─────────────────────
            3          

In [76]: minpoly(p.subs(x, rt))
Out[76]: x

Here the minimal polynomial is x whose only root is zero.

https://en.wikipedia.org/wiki/Minimal_polynomial_(field_theory) https://docs.sympy.org/latest/modules/polys/reference.html#sympy.polys.numberfields.minpoly

Oscar Benjamin
  • 12,649
  • 1
  • 12
  • 14
  • I already found out this answer (see my comment to Alex) but for the reading public this answer should be marked as accepted. – Marc Bogaerts Mar 11 '21 at 18:42