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

Unable to compute discriminant of a multivariate polynomial over the symbolic ring #39350

Open
2 tasks done
maxale opened this issue Jan 19, 2025 · 5 comments
Open
2 tasks done
Labels

Comments

@maxale
Copy link
Contributor

maxale commented Jan 19, 2025

Steps To Reproduce

We have

sage: K.<a,b,c> = QQ[]
sage: R.<x,y> = K[]
sage: (a*x^2*y^2 + b*x*y + c).discriminant(x)
(b^2 - 4*a*c)*y^2

but

sage: a,b,c = var('a b c')
sage: R.<x,y> = SR[]
sage: (a*x^2*y^2 + b*x*y + c).discriminant(x)
[...]
TypeError: unable to coerce since the denominator is not 1

Expected Behavior

The second example should work similarly to the first one.

Actual Behavior

The produced error looks weird. Why would the simple formula for discriminant care about denominators at first place?

Additional Information

No response

Environment

  • OS: Ubuntu 24.04.1 LTS
  • Sage Version: 10.6.beta1

Checklist

  • I have searched the existing issues for a bug report that matches the one I want to file, without success.
  • I have read the documentation and troubleshoot guide
@maxale maxale added the t: bug label Jan 19, 2025
@DaveWitteMorris
Copy link
Member

DaveWitteMorris commented Jan 23, 2025

SR is not commutative (it's not actually even a ring), so perhaps we should just raise an meaningful exception, instead of trying to compute the discriminant of such a polynomial. However, it does seem like it would be better to give an answer in cases where the discriminant makes sense (and is easy to find).

The definition of the discriminant is a certain determinant, divided by the leading coefficient. This means that division is involved in the calculation, so it's not surprising that a nontrivial denominator arises. Theoretically, the denominator can be cleared by simplifying the fraction, but the code is written for polynomials over a ring, not SR, so I wouldn't expect it to call something like simplify. Anyway, the quotient may be complicated enough that sagemath won't be able to clear the denominator, so I don't know whether it's worth the trouble to add code for this.

There are formulas for the discriminant of low-degree polynomials, but wikipedia says that there are already over 200 terms in the formula for degree 6. So it also may not be worth the trouble to implement these formulas in order to be able to handle small cases.

@maxale
Copy link
Contributor Author

maxale commented Jan 23, 2025

@DaveWitteMorris: I do not quite follow why SR is not commutative and how this is relevant to the current issue. Division does exist in SR and I do not understand why there is a trouble to divide something by something even if the latter something is not 1. Whether or not the resulting expression is simplified is a different issue, and I do not ask here to present it in the most simple form but just in whatever form.

@maxale
Copy link
Contributor Author

maxale commented Jan 23, 2025

Also, discriminant over SR for univariate polynomials works fine:

sage: a,b,c = var('a b c')
sage: R.<x> = SR[]
sage: (a*x^2 + b*x + c).discriminant()
-(a*b^2 - 2*(b^2 - 2*a*c)*a)/a

@DaveWitteMorris
Copy link
Member

A demonstration that SR is not commutative:

sage: a = SR(matrix(ZZ, 2, [0,1,0,0]))
sage: b = SR(matrix(ZZ, 2, [0,0,1,0]))
sage: a in SR, b in SR
(True, True)
sage: a*b
[1 0]
[0 0]
sage: b*a
[0 0]
[0 1]

The last two are not equal, so SR is not commutative.

"Discriminant" is a concept from commutative algebra. I am not aware of any definition of discriminant for polynomials over a noncommutative ring.

The discriminant needs to be in the base ring of the polynomial ring, but the multivariable routine does the calculations in the fraction field of the base ring. In your example, I think it fails to convert the result back into the base ring because the denominator is not 1. That's why being able to do the division is important.

It's not really true that "discriminant over SR for univariate polynomials works fine":

sage: a = SR(matrix(ZZ, 2, [0,1,0,0]))
sage: b = SR(matrix(ZZ, 2, [0,0,1,0]))
sage: (a*x^2 + b*x + SR(1)).discriminant()
...
AttributeError: 'ComplexIntervalField_class_with_category' object has no attribute 'complex_field'

The discriminant of this polynomial does not exist, since the coefficients do not commute.

The documentation may not make this clear, but users should be told that serious calculations with polynomials should be done in a polynomial ring, not the symbolic ring.

@maxale
Copy link
Contributor Author

maxale commented Jan 23, 2025

@DaveWitteMorris: Thanks for clarifying. I agree that discriminant over SR may be not defined in general, but then Sage should either do a better job in recognizing those cases when it is, or consistently refuse computing discriminants over SR with a clear error message. Current behavior is erratic at best.

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

No branches or pull requests

2 participants