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

PARI and Singular can't handle all polynomial resultants #15061

Closed
rharron mannequin opened this issue Aug 19, 2013 · 23 comments
Closed

PARI and Singular can't handle all polynomial resultants #15061

rharron mannequin opened this issue Aug 19, 2013 · 23 comments

Comments

@rharron
Copy link
Mannequin

rharron mannequin commented Aug 19, 2013

Consider the following:

sage: R.<T> = PowerSeriesRing(QQ)                                                                                                                          
sage: F = R([1,1],2)                                                                                                                                       
sage: F                                                                                                                                                    
1 + T + O(T^2)                                                                                                                                             
sage: RP.<x> = PolynomialRing(R)                                                                                                                           
sage: P = x^2 - F                                                                                                                                                                                                                                                     
sage: P.resultant(P.derivative())
ValueError: series precision must be finite for conversion to pari object.

In particular, sage is incapable of computing the discriminant of this quadratic polynomial! I'll shortly post a patch that catches this error and uses the sylvester matrix instead.

Component: algebra

Keywords: pari, resultant, sylvester matrix

Author: Robert Harron, Peter Bruin

Branch/Commit: 51523b1

Reviewer: Martin von Gagern

Issue created by migration from https://trac.sagemath.org/ticket/15061

@rharron rharron mannequin added this to the sage-6.1 milestone Aug 19, 2013
@rharron rharron mannequin added c: algebra labels Aug 19, 2013
@rharron
Copy link
Mannequin Author

rharron mannequin commented Aug 19, 2013

comment:2

There's something wrong with the patch because of some whitespace issues. I'll fix this soon.

@rharron rharron mannequin added s: needs work and removed s: needs review labels Aug 19, 2013
@rharron
Copy link
Mannequin Author

rharron mannequin commented Aug 19, 2013

@pjbruin
Copy link
Contributor

pjbruin commented Jan 1, 2014

comment:4

I noticed that this problem is also solved by #15601, which implements conversion to PARI for power series with infinite precision by converting them to polynomials.

There are probably other base rings that cannot be converted to PARI, so using sylvester_matrix() as a last resort is probably still useful. It would be good to have another example that still fails after applying #15601.

@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.1, sage-6.2 Jan 30, 2014
@gagern
Copy link
Mannequin

gagern mannequin commented Mar 27, 2014

comment:6

My changes from #16014 comment:2 make P.discriminant() work.

@gagern
Copy link
Mannequin

gagern mannequin commented Apr 17, 2014

comment:7

Replying to @pjbruin:

It would be good to have another example that still fails after applying #15601.

sage: R.<x> = AA[]
sage: (2*x^2 + 3*x + 5).discriminant()
TypeError: no conversion of this ring to a Singular ring defined

Does this help, even though it's singular here and not pari? RIF does the same. I haven't worked out yet which resultants get computed by pari and which by singular.

@pjbruin
Copy link
Contributor

pjbruin commented Apr 21, 2014

comment:8

Replying to @gagern:

Replying to @pjbruin:

It would be good to have another example that still fails after applying #15601.

sage: R.<x> = AA[]
sage: (2*x^2 + 3*x + 5).discriminant()
TypeError: no conversion of this ring to a Singular ring defined

Does this help, even though it's singular here and not pari? RIF does the same. I haven't worked out yet which resultants get computed by pari and which by singular.

This example still fails with the patch applied. There seems to be a different problem here, namely that the class of that polynomial inherits from Polynomial_singular_repr, even though the base field does not have a conversion to Singular. The same error occurs when you replace PowerSeriesRing by LaurentSeriesRing in the original example.

@gagern
Copy link
Mannequin

gagern mannequin commented May 2, 2014

comment:9

Replying to @pjbruin:

There seems to be a different problem here, namely that the class of that polynomial inherits from Polynomial_singular_repr, even though the base field does not have a conversion to Singular.

polynomial_element_generic.Polynomial_generic_field inherits from polynomial_singular_interface.Polynomial_singular_repr. That inheritance was introduced in 35bb3ea from 2007. Unfortunately I can't see what kind of bug this was supposed to fix. It seems like a bad move to me, though, since that class clearly assumes that you can convert to singular without further checks.

@pjbruin
Copy link
Contributor

pjbruin commented May 2, 2014

comment:10

Replying to @gagern:

Replying to @pjbruin:

There seems to be a different problem here, namely that the class of that polynomial inherits from Polynomial_singular_repr, even though the base field does not have a conversion to Singular.

polynomial_element_generic.Polynomial_generic_field inherits from polynomial_singular_interface.Polynomial_singular_repr. That inheritance was introduced in 35bb3ea from 2007.

That commit only changed the order of the superclasses; the inheritance was there before.

Unfortunately I can't see what kind of bug this was supposed to fix. It seems like a bad move to me, though, since that class clearly assumes that you can convert to singular without further checks.

I agree that it is strange for polynomials over arbitrary fields to inherit from that class. An alternative would be to "manually" prescribe this inheritance for polynomials over fields that support conversion to Singular, but that doesn't sound very attractive. Another alternative would be to move resultant() to a more generic polynomial class that first tries to use Singular and uses a generic Python implementation in case that fails.

@gagern
Copy link
Mannequin

gagern mannequin commented May 2, 2014

comment:11

Replying to @pjbruin:

That commit only changed the order of the superclasses; the inheritance was there before.

Thanks, I missed that fact.

I agree that it is strange for polynomials over arbitrary fields to inherit from that class. An alternative would be to "manually" prescribe this inheritance for polynomials over fields that support conversion to Singular, but that doesn't sound very attractive.

I see how the constructor of PolynomialRing_field checks for singular support and sets the _has_singular property accordingly. We could use that place to change element_class in a suitable way. But if we wanted to handle this using different classes, we'd add one more point to the already dense network of generic vs. special, domain vs. field, sparse vs. dense. Not sure I like that either.

Another alternative would be to move resultant() to a more generic polynomial class that first tries to use Singular and uses a generic Python implementation in case that fails.

Sounds good. As a first step, we could change Polynomial_singular_repr to check self.parent()._has_singular and call super if that isn't set. We could then make sure that Polynomial.resultant falls back to sylvester_matrix if PARI doesn't work. Although I don't know yet for which rings PARI will work. Messy business…

@pjbruin
Copy link
Contributor

pjbruin commented May 3, 2014

comment:12

I think I have found a solution that will solve most of these problems. In this branch:

  • Rob Harron's patch, with minor modifications.
  • Remove lcm() and resultant() from Polynomial_singular_repr. For lcm(), delete the code and move the doctests to the existing MPolynomial_libsingular.lcm(); for resultant(), move the code and doctests to the new MPolynomial_polydict.resultant().
  • In MPolynomial_polydict.resultant(), fall back on Sylvester matrices if the ring has no Singular implementation.
  • Various cosmetic fixes.

@pjbruin
Copy link
Contributor

pjbruin commented May 3, 2014

Author: Robert Harron, Peter Bruin

@pjbruin
Copy link
Contributor

pjbruin commented May 3, 2014

Commit: d1a25de

@pjbruin
Copy link
Contributor

pjbruin commented May 3, 2014

Branch: u/pbruin/15061-resultant

@pjbruin pjbruin changed the title Pari can't handle all polynomial resultants PARI and Singular can't handle all polynomial resultants May 3, 2014
@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 3, 2014

Branch pushed to git repo; I updated commit sha1. New commits:

51523b1Trac 15061: delete an irrelevant doctest

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 3, 2014

Changed commit from d1a25de to 51523b1

@gagern
Copy link
Mannequin

gagern mannequin commented May 3, 2014

comment:14

Judging from the timestamps, your system clock is wrong. Apart from that, I like the code, from what I can tell at first glance. Thanks! Will pull and run tests soon.

@pjbruin
Copy link
Contributor

pjbruin commented May 3, 2014

comment:15

Replying to @gagern:

Judging from the timestamps, your system clock is wrong.

I know, but it is a system that I am not the administrator of.

Apart from that, I like the code, from what I can tell at first glance. Thanks! Will pull and run tests soon.

OK, thanks!

@gagern
Copy link
Mannequin

gagern mannequin commented May 3, 2014

comment:16

Will pull and run tests soon.

All tests in src/sage/rings passed here. And the code still looks sane at second glance. Am I qualified to give this a positive review?

@pjbruin
Copy link
Contributor

pjbruin commented May 3, 2014

comment:17

Replying to @gagern:

All tests in src/sage/rings passed here. And the code still looks sane at second glance. Am I qualified to give this a positive review?

You can probably judge yourself if you have done the things suggested in "Reviewing Patches" in the developer guide. (Note in particular that you are supposed to run all doctests; things can really break in unexpected places.)

@gagern
Copy link
Mannequin

gagern mannequin commented May 4, 2014

comment:18

Replying to @pjbruin:

You can probably judge yourself if you have done the things suggested in "Reviewing Patches" in the developer guide.

  • ./sage -t --all --long: done, no new errors
  • make including documentation: done
  • ./sage -docbuild reference pdf: done
  • ./sage -coverage src/sage/rings/polynomial/*.py{,x}: Diff shows that this now has 6 things less to complain about, and no new ones

I wonder whether the docs for resultant regarding “Implemented using PARI’s polresultant function.” should get adjusted. On the other hand, I doubt that detailing the possible choices of algorithm is worth the effort.

(Note in particular that you are supposed to run all doctests; things can really break in unexpected places.)

Did so, and found #16285 in the process. But that's reproducible without your change, so not your fault.

Shouldn't running the testsuite be handled by patchbot? Or hasn't that been migrated to the git workflow yet?

@gagern
Copy link
Mannequin

gagern mannequin commented May 4, 2014

Reviewer: Martin von Gagern

@gagern gagern mannequin added s: positive review and removed s: needs review labels May 4, 2014
@pjbruin
Copy link
Contributor

pjbruin commented May 5, 2014

comment:19

Replying to @gagern:

Shouldn't running the testsuite be handled by patchbot? Or hasn't that been migrated to the git workflow yet?

It has, but not enough people are running patchbots, and I think there are also some glitches that sometimes prevent it from doing its job.

@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@vbraun
Copy link
Member

vbraun commented May 6, 2014

Changed branch from u/pbruin/15061-resultant to 51523b1

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

No branches or pull requests

2 participants