oooh wait wait wait. I've said something totally confusing. My previous two posts apply to rational fractions... for which indeed, the numerator method gives the 'correct' answer ! The issue I raised in my original post is the 'funny' behaviour when you ask for the numerator of something in QQ[x] -- which, come to think of it, is mathematically a little unsound. I just totally assumed this should give the same answer as coercing into the field of rational fractions and then applying numerator(), but it doesn't. You (Robert) assumed something absolutely different.
(Now i still think it would be less surprising is sage acted as i suggested, but i don't have strong feelings about it anymore :) ) so in any case, having realized this, i have found an ugly fix : sage: N= P.parent().fraction_field()(P).numerator() # gives what i want !! always work ! pierre On 1 mar, 20:33, Pierre <[email protected]> wrote: > One further example perhaps, to be more convincing : > > sage: N= (2*x).numerator() > sage: N.prime_divisors() > [2, x] > sage: [valuation(N, p) for p in prime_divisors(N)] # innocent- > looking piece of code > > ... > ArithmeticError: The polynomial, p, must have positive degree. > > I do think the innocent piece of code above ought to work. > > p. > > On 1 mar, 20:25, Pierre <[email protected]> wrote: > > > hmm it's not mathematical, it's just that IMHO n should belong to > > QQ[x], not ZZ[x]. I do see your point though, in that the coefficients > > should be mathematical integers (or "may as well be"). And I do see > > now that it is intentional. > > > Think about it : if i wanted to use your metaphor, over QQ the > > numerator of a fraction ought to be in ZZ, not in NN, even if it is > > positive ! and it should not be in the group {1 ; -1} with two > > elements even if it is equal to 1... I guess i'm trying to say that > > when k= R.fraction_field(), and when x is in k, then x.numerator() > > should be in R. Not in some subset of R. You may well disagree and say > > that we can take a convention for numerators such that they always lie > > in some subset of R, but I don't think it's a good idea. > > > Also think about my nightmare when i ask for the prime divisors of the > > numerator of a fraction, expecting polynomials, and getting things > > like 2 and 3... I know I can use numerator().change_ring(QQ) but then > > my code wouldn't be as general (if I apply 'numerator' to something in > > QQ, i find an element of ZZ which doesn't have a change_ring() > > method... etc). > > > pierre > > > On 1 mar, 19:37, Robert Bradshaw <[email protected]> wrote: > > > > On Mar 1, 2010, at 7:50 AM, Pierre wrote: > > > > > hi all, > > > > > is this a bug or intentional ? > > > > > sage: x= QQ['x'].gen() > > > > sage: n= x.numerator() > > > > sage: x.parent() > > > > Q[x] > > > > sage: n.parent() > > > > Z[x] > > > > > what about this Z popping out of nowhere ? (well...) It's certainly > > > > making my like (a little) more complicated (i have a more involved > > > > example of course, and i proceed to look for prime divisors of the > > > > numerator). > > > > This is just the general definition of numerator and denominator > > > extended from Q to Q[x]. I don't see any other definition of numerator > > > that would make more sense here... > > > > - Robert -- To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
