[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Definition of gcd(A,B)
From: 
John W. Eaton 
Subject: 
Definition of gcd(A,B) 
Date: 
Sat, 19 Jun 1999 12:41:23 0500 (CDT) 
On 18Jun1999, address@hidden <address@hidden> wrote:
 I have a need for a termbyterm GCD, i.e.

 gcd([6 10;12 15],[9 12; 16 20]) == [3 2;4 5]

 The current Octave gcd.m seems to interpret the notation as

 gcd([6 10;12 15],[9 12; 16 20]) == gcd([6 10 12 15 9 12 16 20])

 and therefore returns 1.

 I find this inconvenient and less general, as in the case of the
 termbyterm gcd one could easily get the current behaviour
 by the using the colon operator.

 The "intuitive" definition should to my mind be:

 GCD(X) should be the GCD of the elements in vector X
 GCD(A) should be a vector of GCD's of columns of matrix A
 GCD(A,B,C,...) should be a matrix of GCD's of corresponding
 elements in matrices A,B,C,... which are all scalar or of the
 same shape

 I have written such a GCD, which I give a different name to
 avoid confusion.

 But is the present behaviour of GCD an intentional one, intended
 to preserve compatibility with whatever, or just the result of
 not having thought out what GCD should mean for nonscalar
 arguments?
You would have to ask Kurt Hornik, who wrote it.
I don't know what Matlab did for gcd or lcm when he wrote them. Now,
both gcd and lcm are incompatible, I think. If you can provide
compatible versions, I think that would be good.
Thanks,
jwe

Octave is freely available under the terms of the GNU GPL. To ensure
that development continues, see www.che.wisc.edu/octave/giftform.html
Instructions for unsubscribing: www.che.wisc.edu/octave/archive.html
