Menu

#4267 gcd is not working on lists

None
not-a-bug
nobody
gcd (13)
5
2024-02-28
2024-02-28
Jimis Hol
No

gcd, contrary to lcm that work both on list and simple arguments, does not work on lists.

(%i1)   A:[10,6];
(A) [10,6]
(%i2)   gcd(A);
(wxMaxima is configured not to show long expressions - which would be slow)
 -- an error. To debug this try: debugmode(true);

But

(%i3)   gcd(10,6);
(%o3)   2

is ok.

I expected to work just as lcm do

(%i5)   lcm(10,6);lcm([10,6]);
(%o4)   30
(%o5)   30

I count not find any way, by apply or map lamda etc, to convert list to arguments so as to make gcd to work on lists.

Discussion

  • Barton Willis

    Barton Willis - 2024-02-28

    Here is one way to find the gcd of the members of a list:

    apply('gcd,[10,6]);
    2
    

    In the user documentation for gcd and lcm, I don't see any mention of calling either function on a list. So I'd say that this bug report of is more of a feature request to (i) expand the user documentation for lcm and (ii) allow gcd to be called on a list.

     
  • Jimis Hol

    Jimis Hol - 2024-02-28

    Yes indeed. in that sense looks like a feature request. Also thank you for the single quote. Because of the working apply(min,[10,6]) I did not think to add the quote before gcd.

     
  • Raymond Toy

    Raymond Toy - 2024-02-28

    Heh. I was surprised to see that gcd needed single quote. If you leave it off, you get something like spmod(10,6). Then I remembered that gcd also names a variable whose default value is spmod.

    I think the documentation could be improved so that the functions gcd and the variable gcd had different entries. Now you have to get to the second paragraph after a long first paragraph to find out abou the variable.

     
  • Stavros Macrakis

    There's nothing in the doc suggesting that gcd([4,6,8])will work. I'm surprised that lcm allows it.

    It's good practice to always quote a function to avoid surprises.

    I'm surprised that Barton didn't mention the nicer way (which he introduced) of making a 2-argument function into an n-argument one, xreduce (also rreduce and lreduce if you want to control how it associates).

    Closing as not a bug.

     
  • Stavros Macrakis

    • status: open --> not-a-bug
     

Log in to post a comment.