Solving a univariate polynomial after Grobner basis
I'm working on a simple exercise of homotopy continuation in sage maths as follows.
# Import necessary modules
from sage.all import *
# Define the polynomial ring
R.<x, y, t> = PolynomialRing(QQ, order='lex')
# Define the target system and start system as polynomials
f = [x^2 + 4*y^2 - 4, 2*y^2 - x] # target system
g = [x^2 - 1, y^2 - 1] # start system
# Define the homotopy
h = [t*fi + (1-t)*gi for fi, gi in zip(f, g)]
# Expand the homotopy
eh = [expand(hi) for hi in h]
# Compute the Jacobian matrix
jh = matrix([[diff(ehi, xi) for xi in [x, y]] for ehi in eh])
# Discriminant system: homotopy equations + determinant of the Jacobian matrix
sys = eh + [jh.det()]
# Convert the system to polynomials in the polynomial ring
sys_polynomials = [R(equation) for equation in sys]
# Compute the Groebner basis with lexicographic ordering
I = Ideal(sys_polynomials)
gb = I.groebner_basis()
# Extract the discriminant polynomial
discriminant_poly = gb[-1]
# Solve discriminant_poly
discriminant_poly.roots()
My question
I'm getting the following error. could someone tell me how to solve this polynomial using a SageMaths function?
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In [1], line 34
31 discriminant_poly = gb[-Integer(1)]
33 # Solve discriminant_poly
---> 34 discriminant_poly.roots()
File /home/sc_serv/sage/src/sage/structure/element.pyx:489, in sage.structure.element.Element.__getattr__()
487 AttributeError: 'LeftZeroSemigroup_with_category.element_class' object has no attribute 'blah_blah'...
488 """
--> 489 return self.getattr_from_category(name)
490
491 cdef getattr_from_category(self, name) noexcept:
File /home/sc_serv/sage/src/sage/structure/element.pyx:502, in sage.structure.element.Element.getattr_from_category()
500 else:
501 cls = P._abstract_element_class
--> 502 return getattr_from_other_class(self, cls, name)
503
504 def __dir__(self):
File /home/sc_serv/sage/src/sage/cpython/getattr.pyx:362, in sage.cpython.getattr.getattr_from_other_class()
360 dummy_error_message.cls = type(self)
361 dummy_error_message.name = name
--> 362 raise AttributeError(dummy_error_message)
363 attribute = <object>attr
364 # Check for a descriptor (__get__ in Python)
AttributeError: 'sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular' object has no attribute 'roots'
Homework ?
Hint :
roots
is a method of symbolic expression (SR) elements. Univariate polynomials are not symbolic expressions ; solving them requires other methods...Sorry, I should have mentioned this earlier. I'm self-studying numerical algebraic geometry and am fairly new to this domain. So, googling by the error didn't lead to a fruitful finding... If you could describe how to implement
other methods
, I would greatly appreciate it!Oh, I think I found the solution!
this works w/o runtime error!
@Rowing0914 : you should answer your own question, for future
ask.sagemath.org
(per)users' sake.