I think that the constructor should return the same type for all values of i even when the result is a constant.
It is all too easy to implement functions which behave as you show, when dealing with trivial simple cases: in this case it would be so easy to write at the start of the function "if i==0: return 1" that I would not have been surprised if the legendre(0,x) was int(1)! John On 11 December 2013 12:40, Thierry Dumont <[email protected]> wrote: > Hello, all, > > I am going to manipulate Legendre (P) polynomials. > So I do something like this: > > sage: P.<x>=QQ[] > > sage: #generate de first Lagrange polynomial > sage: s=[legendre_P(i,x) for i in [0..2]] > sage: print s > [1, x, 3/2*x^2 - 1/2] > > sage: #now, look at the parents > sage: s[0].parent() > Integer Ring > sage: s[1].parent() > Univariate Polynomial Ring in x over Rational Field > > Ok, this is correct, and seems nice; but I want to evaluate these > polynomials for different values of x, and you cannot evaluate a member > of "Integer Ring" at say, x=1/21... So I need to compute the parent of > polynomials (which possibly are scalars) in all my functions, make test > and so on.... > > I have found a work-around: > sage: s=[P(legendre_P(i,x)) for i in [0..2]] > > Then, I get: > > sage: s[0].parent() > Univariate Polynomial Ring in x over Rational Field > > Ok, but is there some other way to do this? > > Yours > t. > > -- > You received this message because you are subscribed to the Google Groups > "sage-support" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/sage-support. > For more options, visit https://groups.google.com/groups/opt_out. -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/groups/opt_out.
