Ask Your Question

Revision history [back]

Roots of monic integer polynomials

Define the ring of polynomials in x with integer coefficients:

sage: Zx = ZZ['x']
sage: x = Zx.gen()

Pick a random monic polynomial of degree 56:

sage: q = Zx.random_element(degree=56)  # not necessarily monic
sage: p = (1 - q[56])*x^56 + q  # now monic by making leading coefficient 1
sage: p
x^56 + 27*x^54 + x^53 + 2*x^52 - 4*x^51 + 6*x^49 - 3*x^48 - 2*x^47
+ 3*x^46 - 3*x^45 + x^43 + x^41 - x^38 + x^36 - 3*x^34 - 2*x^33
+ 14*x^32 - 2*x^31 - x^30 + x^29 + x^28 + x^27 - x^26 - 3*x^25
- 4*x^24 + x^23 - 13*x^20 + x^19 - 3*x^18 - 3*x^16 + x^15 - 21*x^13
+ x^11 + x^10 - 2*x^8 - 2*x^6 + 4*x^5 + 6*x^4 - x^3 + 3*x^2 + x - 2

Get the sorted list of absolute values of its complex roots as balls:

sage: sorted(set(abs(z) for z in p.roots(CBF, multiplicities=False)))
[[0.554320370371923 +/- 5.07e-16], [0.733877688863701 +/- 5.93e-16],
 [0.790151256486441 +/- 2.55e-16], [0.790151256486441 +/- 2.55e-16],
 [0.834175531654164 +/- 4.27e-16], [0.834175531654164 +/- 4.27e-16],
 [0.867259115927234 +/- 5.27e-16], [0.867259115927234 +/- 5.27e-16],
 [0.873281109745667 +/- 5.36e-16], [0.938405173485585 +/- 2.82e-16],
 [0.938405173485585 +/- 2.82e-16], [0.951240193645357 +/- 5.04e-16],
 [0.951240193645357 +/- 5.04e-16], [0.959393543021787 +/- 4.84e-16],
 [0.959393543021787 +/- 4.84e-16], [0.968049174961464 +/- 3.74e-16],
 [0.968049174961464 +/- 3.74e-16], [0.970884838146261 +/- 3.72e-16],
 [0.970884838146261 +/- 3.72e-16], [0.971668448923249 +/- 5.60e-16],
 [0.971668448923249 +/- 5.60e-16], [0.981855232640659 +/- 3.31e-16],
 [0.981855232640659 +/- 3.31e-16], [0.988836704194625 +/- 3.35e-16],
 [0.988836704194625 +/- 3.35e-16], [0.989893894583637 +/- 3.10e-16],
 [0.989893894583637 +/- 3.10e-16], [0.992900145032832 +/- 2.58e-16],
 [0.992900145032832 +/- 2.58e-16], [0.993485276689509 +/- 4.86e-16],
 [0.993485276689509 +/- 4.86e-16], [0.995962550963240 +/- 5.19e-16],
 [0.995962550963240 +/- 5.19e-16], [0.997106820599413 +/- 3.65e-16],
 [0.998272030405643 +/- 5.03e-16], [0.998272030405643 +/- 5.03e-16],
 [0.998888797451878 +/- 3.15e-16], [0.998888797451878 +/- 3.15e-16],
 [1.001077438291740 +/- 2.41e-16], [1.001077438291740 +/- 2.41e-16],
 [1.003483438283551 +/- 3.24e-16], [1.003483438283551 +/- 3.24e-16],
 [1.003920944016440 +/- 5.09e-16], [1.003920944016440 +/- 5.09e-16],
 [1.005628887116308 +/- 5.22e-16], [1.005628887116308 +/- 5.22e-16],
 [1.011338025074980 +/- 5.16e-16], [1.011338025074980 +/- 5.16e-16],
 [1.011575459414411 +/- 3.84e-16], [1.011575459414411 +/- 3.84e-16],
 [1.012926800214650 +/- 5.86e-16], [1.012926800214650 +/- 5.86e-16],
 [1.035073067121418 +/- 3.44e-16], [1.035073067121418 +/- 3.44e-16],
 [5.18922034049960 +/- 2.92e-15], [5.18922034049960 +/- 2.92e-15]]

Roots of monic integer polynomials

Define the ring of polynomials in x with integer coefficients:

sage: Zx = ZZ['x']
sage: x = Zx.gen()

Pick a random monic polynomial of degree 56:

sage: q = Zx.random_element(degree=56)  # not necessarily monic
sage: p = (1 - q[56])*x^56 + q  # now monic by making leading coefficient 1
sage: p
x^56 + 27*x^54 + x^53 + 2*x^52 - 4*x^51 + 6*x^49 - 3*x^48 - 2*x^47
+ 3*x^46 - 3*x^45 + x^43 + x^41 - x^38 + x^36 - 3*x^34 - 2*x^33
+ 14*x^32 - 2*x^31 - x^30 + x^29 + x^28 + x^27 - x^26 - 3*x^25
- 4*x^24 + x^23 - 13*x^20 + x^19 - 3*x^18 - 3*x^16 + x^15 - 21*x^13
+ x^11 + x^10 - 2*x^8 - 2*x^6 + 4*x^5 + 6*x^4 - x^3 + 3*x^2 + x - 2

Get Compute the sorted list of absolute values of its complex roots as complex balls:

sage: sorted(set(abs(z) rr = p.roots(CBF, multiplicities=False)
sage: len(rr)
56

Take absolute values, excluding those with negative imaginary part so as to take only one per pair of conjugate non-real roots, and sort:

sage: arr = sorted(abs(r) for z r in p.roots(CBF, multiplicities=False)))
[[0.554320370371923 +/- 5.07e-16], [0.733877688863701 +/- 5.93e-16],
 [0.790151256486441 rr if r.imag() >= 0)
sage: len(arr)
26
sage: arr
[[0.790151256486441 +/- 2.55e-16], [0.790151256486441 +/- 2.55e-16],
 [0.834175531654164 +/- 4.27e-16], [0.834175531654164 +/- 4.27e-16],
 [0.867259115927234 +/- 5.27e-16], [0.867259115927234 +/- 5.27e-16],
 [0.873281109745667 +/- 5.36e-16], [0.938405173485585 +/- 2.82e-16],
 [0.938405173485585 +/- 2.82e-16], [0.951240193645357 +/- 5.04e-16],
 [0.951240193645357 +/- 5.04e-16], [0.959393543021787 +/- 4.84e-16],
 [0.959393543021787 +/- 4.84e-16], [0.968049174961464 +/- 3.74e-16],
 [0.968049174961464 +/- 3.74e-16], [0.970884838146261 +/- 3.72e-16],
 [0.970884838146261 +/- 3.72e-16], [0.971668448923249 +/- 5.60e-16],
 [0.971668448923249 +/- 5.60e-16], [0.981855232640659 +/- 3.31e-16],
 [0.981855232640659 +/- 3.31e-16], [0.988836704194625 +/- 3.35e-16],
 [0.988836704194625 +/- 3.35e-16], [0.989893894583637 +/- 3.10e-16],
 [0.989893894583637 +/- 3.10e-16], [0.992900145032832 +/- 2.58e-16],
 [0.992900145032832 +/- 2.58e-16], [0.993485276689509 +/- 4.86e-16],
 [0.993485276689509 +/- 4.86e-16], [0.995962550963240 +/- 5.19e-16],
 [0.995962550963240 +/- 5.19e-16], [0.997106820599413 +/- 3.65e-16],
 [0.998272030405643 +/- 5.03e-16], [0.998272030405643 +/- 5.03e-16],
 [0.998888797451878 +/- 3.15e-16], [0.998888797451878 +/- 3.15e-16],
 [1.001077438291740 +/- 2.41e-16], [1.001077438291740 +/- 2.41e-16],
 [1.003483438283551 +/- 3.24e-16], [1.003483438283551 +/- 3.24e-16],
 [1.003920944016440 +/- 5.09e-16], [1.003920944016440 +/- 5.09e-16],
 [1.005628887116308 +/- 5.22e-16], [1.005628887116308 +/- 5.22e-16],
 [1.011338025074980 +/- 5.16e-16], [1.011338025074980 +/- 5.16e-16],
 [1.011575459414411 +/- 3.84e-16], [1.011575459414411 +/- 3.84e-16],
 [1.012926800214650 +/- 5.86e-16], [1.012926800214650 +/- 5.86e-16],
 [1.035073067121418 +/- 3.44e-16], [1.035073067121418 +/- 3.44e-16],
 [5.18922034049960 +/- 2.92e-15], [5.18922034049960 +/- 2.92e-15]]