* Bruno Grenet <bruno.gre...@gmail.com> [2014-06-19 09:21:29 +0200]: > Le 17/06/2014 00:01, Julian Rüth a écrit : > >In your case you would add a method _roots_univariate_polynomial to > >sage.rings.integer_ring.IntegerRing_class. > I have the following problem using this strategy of a > _roots_univariate_polynomial method. The new algorithm I add only deals with > a very specific case, namely integer roots of integer sparse polynomials. In > the method _roots_univariate_polynomial of the IntegerRing_class, what I'd > like to do is in some sense to test whether ring=self (that is we want > integer roots) and whether the polynomial is sparse, and if it is not the > case to call back the roots method. Of course, this would create an endless > loop... The other solution is to copy-paste the code of the roots method > corresponding to an integer input polynomial into the new > IntegerRing_class._roots_univariate_polynomial method. Is this second > solution acceptable? My concern is that duplicate code does not seem a very > nice idea ;-). It makes sense that _roots_univariate_polynomial can somehow call the generic implementation. If the code that you would copy is specific to integer polynomials, then it should go into _roots_univariate_polynomial() anyway. Otherwise copying it is not such a nice idea. The easiest solution is probably to modify roots() to look at the return value of _roots_univariate_polynomial(): if it is None, run the generic code, otherwise return whatever _roots_univariate_polynomial() computed.
julian
pgpxSOOhtsrJn.pgp
Description: PGP signature