Ask Your Question
0

Solving a univariate polynomial after Grobner basis

asked 2024-08-18 07:22:11 +0100

Rowing0914 gravatar image

updated 2024-08-18 08:44:24 +0100

FrédéricC gravatar image

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'
edit retag flag offensive close merge delete

Comments

Homework ?

Hint : roots is a method of symbolic expression (SR) elements. Univariate polynomials are not symbolic expressions ; solving them requires other methods...

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2024-08-18 07:40:51 +0100 )edit

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!

Rowing0914 gravatar imageRowing0914 ( 2024-08-18 09:53:41 +0100 )edit
1

Oh, I think I found the solution!

# Convert the discriminant polynomial to a univariate polynomial by eliminating other variables
univariate_poly = discriminant_poly.univariate_polynomial()
print(univariate_poly)

# Solve the univariate polynomial
univariate_poly.roots()
Rowing0914 gravatar imageRowing0914 ( 2024-08-18 10:27:06 +0100 )edit

this works w/o runtime error!

Rowing0914 gravatar imageRowing0914 ( 2024-08-18 10:27:19 +0100 )edit

@Rowing0914 : you should answer your own question, for future ask.sagemath.org (per)users' sake.

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2024-08-18 12:16:05 +0100 )edit

2 Answers

Sort by » oldest newest most voted
2

answered 2024-08-19 20:05:34 +0100

Emmanuel Charpentier gravatar image

updated 2024-08-20 19:20:13 +0100

An alternate possibility is this atrocity :

sage: discriminant_poly.parent().ideal([x, y,]+[discriminant_poly]).dimension()
0
sage: discriminant_poly.parent().ideal([x, y,]+[discriminant_poly]).variety()
[]
sage: discriminant_poly.parent().ideal([x, y,]+[discriminant_poly]).variety(ring=QQbar)
[{t: 0.4023199380628143?, y: 0, x: 0},
 {t: -0.2011599690314072? - 0.887728937282557?*I, y: 0, x: 0},
 {t: -0.2011599690314072? + 0.887728937282557?*I, y: 0, x: 0},
 {t: -0.8818537645672754? - 0.9177002576216003?*I, y: 0, x: 0},
 {t: -0.8818537645672754? + 0.9177002576216003?*I, y: 0, x: 0},
 {t: 0.006853764567275390? - 0.3927967328421505?*I, y: 0, x: 0},
 {t: 0.006853764567275390? + 0.3927967328421505?*I, y: 0, x: 0}]

EDIT : Note that :

sage: R.ideal(gb).dimension()
0
sage: set(discriminant_poly.univariate_polynomial().roots(multiplicities=False))==set([d[t] for d in R.ideal(gb).variety()])
True
sage: set(discriminant_poly.univariate_polynomial().roots(ring=QQbar, multiplicities=False))==set([d[t] for d in R.ideal(gb).variety(ring=QQbar)])
True

HTH,

edit flag offensive delete link more
1

answered 2024-08-18 16:18:51 +0100

Rowing0914 gravatar image

Here is the complete working code!

# 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]

# Convert the discriminant polynomial to a univariate polynomial by eliminating other variables
univariate_poly = discriminant_poly.univariate_polynomial()
print(univariate_poly)

# Solve the univariate polynomial
univariate_poly.roots()
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2024-08-18 07:22:11 +0100

Seen: 333 times

Last updated: Aug 20