Salut Bruno, Welcome!
> Now comes my question, which is basically: How to introduce this new > code into Sage? Did you already opened a ticket on trac for that? > More specifically, the "roots()" function is defined in > rings/polynomial/polynomial_element.pyx where a selection of algorithm > is made. If I understand correctly, for a polynomial over ZZ (be it > sparse or not), the selection goes through the condition > "K.is_integral_domain()" (line 5799) and then the roots are computing > using "_roots_from_factorization" (line 5809). There, factoring the > input polynomial is (in my cases) hopeless due to its degree. > > What I'd like to do is to branch a new algorithm there. So my more > specific question: Where should the new algorithm go? A solution may be > to have somewhere a specific code for the sparse polynomials over ZZ, > and there put a a function roots(self,multiplicities=True) to avoid > going into the "big" roots function from > rings/polynomial/polynomial_element.pyx. Right now there are several implementation for polynomials with integer coefficients... but only a very generic one is sparse. I guess a first start would be to add your implementation directly in "Polynomial_generic_sparse" in sage/rings/polynomial/polynomial_generic_element.py. There is no much data structure in a polynomial so it will be easy to switch from one place to another. Maybe, somebody might have a better idea here. > I have side questions, which may improve my code (or my tests): > > - S.random_element() for S a sparse_polynomial ring return by defaut a > degree-2 polynomial. For sparse polynomials, wouldn't it make sense to > return a polynomial of "high" degree (to be determined) but with "few" > nonzero monomials? Again, I have a code for that that I can include. It is possible to add extra arguments for random_element. In that case max_degree, density (a number between 0 and 1), distribution would make sense. That can be an independent prerequisite ticket "Improve random generation of sparse polynomial". > - How exactly is stored a Sparse Polynomial? I tried to follow the > "__init__" functions but I was unable to finally understand the real > representation of these objects. I suspect this is a dictionary (or > something approaching) with the keys being the exponents and the values > being the coefficients. In such case, what is the fastest way to access > these elements? Just have a look at the code of polynomial/polynomial_element_generic.py. You see that self.__coeffs is a dictionnary. But the code is rather old and, as far as I know, not much used. > - The algorithm I implemented uses some auxiliary functions that are not > of real interest outside the algorithm. How should I do to avoid this > functions be available for the users? Just do not import them in the global namespace. If they belong to some module in sage/rings/polynomial this is just fine. Vincent -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at http://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.