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
Improvements to discriminant computation #16014
Comments
Branch: u/gagern/ticket/16014 |
This comment has been minimized.
This comment has been minimized.
Commit: |
comment:3
What I implemented so far is a case distinction based on the base ring, with the new implementation being used for multivariate polynomials and power series. I implemented the new code in the existing method for now, in part because I wasn't sure whether I should add new methods (e.g. I'm not sure about this whole |
comment:5
This looks good and passes doctests. However, I'm wondering if you couldn't be convinced to adopt John Cremona's proposal on sage-dev to have a separate function
Here is a simple function to compute the universal discriminant: def universal_discriminant(n):
r"""Return the discriminant of the 'universal' univariate polynomial
`a_n x^n + \cdots + a_1 x + a_0` in `\ZZ[a_0, \ldots, a_n][x]`."""
R = PolynomialRing(ZZ, n + 1, 'a')
S = PolynomialRing(R, 'x')
return S(list(R.gens())).discriminant() |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:7
Replying to @pjbruin:
Sure I can be convinced, particularly if two people request something. I've implemented the caching, but not the hardcoding so far. I wonder how small “small” actually should be. Up to 7, things compute fairly quickly so there seems to be little benefit from hardcoding, particularly since we do caching. For higher degrees, computing them for hardcoding takes considerable time, and writing down the hard code will take up quite a lot of space in the source file. Should this really be implemented in Cython code, or should we make some effort to obtain or compute discriminants up to say 10 or so and store them in some kind of persistent data representation instead of source code? I also wonder how public this function should be. I prefer I also have a question regarding my late import. I noticed the Should I add myself as an author of that module, at the beginning of the file? |
comment:8
Replying to @gagern:
Thanks, this looks very good. You're probably right about not hardcoding the polynomials.
Maybe, but I doubt it is very important. If at all, it should be done in a later ticket.
I actually agree completely with the way you did all these things. I wouldn't add anything to
Here, too, I think the way you did it is absolutely fine. In fact one can argue that modules should generally be imported locally in the function that needs it. On the other hand, global imports (including the
If you want; as you will have seen, authors for some other additions/changes are listed, but it is certainly not done in a very systematic way througout Sage. In any case, your changes and authorship will be remembered by the revision control system, and using Could you also fill in your name (i.e. real name, not Trac username) in the "Author" field of this ticket? I will test this and then set it to positive review. |
Reviewer: Peter Bruin |
comment:9
All tests pass and I am happy with the patch as it is. Please add your name and set the ticket to positive review. |
Author: Martin von Gagern |
Changed branch from u/gagern/ticket/16014 to |
Changed commit from |
comment:12
FWIW the segfault in Python was fixed in newer Python versions: http://bugs.python.org/issue5765 For some reason (it seems just developer resources) a version of the patch was never backported to 2.7. I might take a stab at that (and open a separate ticket if so). Note the patch doesn't magically allow unlimited stack depth and one can still blow the stack. But with the default settings it will raise a |
Currently (i.e. on sage 6.1.1), the discriminant computation fails with a segmenttation fault when the coefficients are too complicated. For example:
Apparently the Python interpreter reaches some limit on the depth of the call stack, since it seems to call
symtable_visit_expr
fromPython-2.7.6/Python/symtable.c:1191
over and over and over again. But this ticket here is not about fixing Python. (If you want a ticket for that, feel free to create one and provide a reference here.)Instead, one should observe that the above is only a discriminant of a third degree polynomial. As such, it has an easy and well-known formula for the discriminant. Plugging the complicated coefficients into this easy formula leads to the solution rather quickly (considering the immense size of said solution). So perhaps we should employ this approach in the
discriminant
method.I've discussed this question on sage-support, and will probably continue the discussion. Right now, I'm unsure about when to choose a new method over the existing one. Should it be based on degree, using hardcoded versions of the well-known discriminants for lower degrees? Or should it rather be based on base ring, thus employing a computation over some simple generators instead of the full coefficients if the base ring is a polynomial ring or some other fairly complex object. Here is a code snippet to illustrate the latter idea:
Personally I think I prefer a case distinction based on base ring, or a combination. If we do the case distinction based on base ring, then I'd also value some input as to what rings should make use of this new approach, and how to check for them. For example, I just noticed that #15061 discusses issues with discriminants of polynomials over power series. So I guess those might benefit from this approach as well.
CC: @pjbruin
Component: algebra
Keywords: discriminant
Author: Martin von Gagern
Branch:
1892c84
Reviewer: Peter Bruin
Issue created by migration from https://trac.sagemath.org/ticket/16014
The text was updated successfully, but these errors were encountered: