[racket-dev] feature request: gcd, lcm for rationals

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Fri Dec 9 14:04:46 EST 2011

One definition of greatest common divisor in a ring R is:
  d is a greatest common divisor of x and y when:
       i)  d divides both x and y
      ii)  If e is a divisor of both x and y, then d divides e

Now let's consider the ring Q. Since Q is a field, 1 divides all elements.

This implies that 1 is a greatest common divisor of any non-zero x and y.
( ad i) 1 is a divisor of both x and y
  ad ii) 1 is a divisor of e )

It is therefore not obvious that gcd should be extendend as you suggest.
But maybe we can finde another name for the operation?

/Jens Axel


2011/12/7 David Van Horn <dvanhorn at ccs.neu.edu>

> It would be nice if gcd and lcm were extended to rational numbers, which
> seems in-line with Scheme's philosophy (but not standards) on numbers.
>
> (define (gcd-rational . rs)
>  (/ (apply gcd (map numerator rs))
>     (apply lcm (map denominator rs))))
>
> (define (lcm-rational . rs)
>  (/ (abs (apply * rs))
>     (apply gcd-rational rs)))
>
> David
> ______________________________**___________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/**listinfo/dev<http://lists.racket-lang.org/listinfo/dev>
>



-- 
-- 
Jens Axel Søgaard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/dev/archive/attachments/20111209/ddaca5e1/attachment.html>

Posted on the dev mailing list.