On Sun, Jan 24, 2010 at 12:08 PM, Mike Hansen <mhan...@gmail.com> wrote:
> Hello,
>
> On Sun, Jan 24, 2010 at 12:02 PM, Stefan Boettner <sboet...@tulane.edu> wrote:
>> I'm working with fraction fields of multivariate polynomials ring with 
>> coefficients in Q. My question is, how do I get cancellation between
>> numerator and denominator coefficients to work?
>>
>> Example:
>>
>> R.<x,y>=PolynomialRing(QQ, 2)
>> F=FractionField(R)
>>
>> f=(x/2)/(y/2)
>
> There isn't really a good way to do this right now.  But, you're
> probably better off using Frac(Z['x,y']):
>
> sage: R = Frac(ZZ['x,y'])
> sage: x,y = R.gens()
> sage: (x/2)/(y/2)
> x/y

Here's a potentially good way to do this right now  :-)

Define this function:

def normalize_denoms(f):
    n, d = f.numerator(), f.denominator()
    a = [vector(x.coefficients()).denominator() for x in [n,d]]
    return (n*a[0])/(d*a[1])


Then:

sage: R.<x,y>=PolynomialRing(QQ, 2)
sage: F=FractionField(R)
sage: f=(x/2)/(3*y/17)
sage: f
1/2*x/(3/17*y)
sage: normalize_denoms(f)
x/(3*y)

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to