gcd for rational numbers

251 views
Skip to first unread message

Alex Ghitza

unread,
Dec 30, 2008, 6:22:47 AM12/30/08
to sage-...@googlegroups.com
Hi,

I was recently looking at
                  http://trac.sagemath.org/sage_trac/ticket/3214
which pointed out a bug in taking the gcd of a bunch of rational numbers.

I'm not sure we should even be doing this.  Here are some arguments:

1. this behaviour is not documented in gcd??  (it is documented in (1/2).gcd??)

2. according to the (not very useful, I agree) mathematical definition of gcd for QQ (or any field), any nonzero rational number is a gcd of any nonempty set of rational numbers.  the current behaviour singles one out in a way that's (I think) not feasible for other fields of fractions (or other localisations)

3. as far as I can tell, the main use for the current behaviour of gcd is to get the common denominator of some rational numbers.  If I have to do this, I think "I want the common denominator" not "I want the gcd".  This is a one-liner:

lcm([x.denominator() for x in list_of_numbers])

I would be happy to write a function common_denominator() that does this, or (maybe even better) extend the existing denominator() function to accept a list of arguments and return their common denominator.  This could work for any ring where the elements have denominators.

I'd like to know what people think about this, and whether people use the current gcd for rational numbers for other purposes than 3.


Best,
Alex


--
Alex Ghitza -- Lecturer in Mathematics -- The University of Melbourne -- Australia -- http://www.ms.unimelb.edu.au/~aghitza/

John Cremona

unread,
Dec 30, 2008, 7:03:23 AM12/30/08
to sage-...@googlegroups.com
I agree that this functionality should be given a different name so we
can keep gcd for genuine gcds.

Alex, your definition of common denominator is not exactly the same as
the denominator of the gcd. I think a more useful function which
would apply to the field of fractions of any PID would be content(),
i.e. the content of [q_1,q_2,...,q_n] is the unique positive rational
c such that the q_i/c are coprime integers. This is precisely what
gcd() currently gives on a list of rationals. For a list L of
integers, L.content() is just L.gcd(). The content() function can
also apply to things like polynomials.

By the way, sage-nt might have been a better place for this discussion?

John

2008/12/30 Alex Ghitza <agh...@gmail.com>:

Alex Ghitza

unread,
Dec 31, 2008, 3:36:21 AM12/31/08
to sage-...@googlegroups.com
On Tue, Dec 30, 2008 at 11:03 PM, John Cremona <john.c...@gmail.com> wrote:

I agree that this functionality should be given a different name so we
can keep gcd for genuine gcds.

Alex, your definition of common denominator is not exactly the same as
the denominator of the gcd.  I think a more useful function which
would apply to the field of fractions of any PID would be content(),
i.e. the content of [q_1,q_2,...,q_n] is the unique positive rational
c such that the q_i/c are coprime integers.  This is precisely what
gcd() currently gives on a list of rationals.  For a list L of
integers, L.content() is just L.gcd().   The content() function can
also apply to things like polynomials.

Ah yes.  I'm happy with this idea of having a content() function.  I'll try to get that done.
 

By the way, sage-nt might have been a better place for this discussion?

Yes, now that you mention it.  It would have been nice if sage-nt had been advertised more widely when it was formed.  It is only mentioned in passing in the middle of one thread on sage-devel, and once on a trac ticket.  Having it listed on the development page at sagemath.org would be good (I'll email Harald about this).

Best,
Alex
 
Reply all
Reply to author
Forward
0 new messages