< Back to IRCAM Forum

A simple question... LCM and GCF objects in OM?

Hi Everyone,

I suspect there should definitely be a way to find lowest common multiple and greatest common denominator of list elements in OM but for some reason it has escaped me… Please send ideas.

Thanks so much,
Brandon

Hi Brandon,

The name of functions are gcd and lcm.
For applying to list, you might try the syntax like:

(apply #'gcd (list 15 20 25))

=> 5

Bests,
Jialin

1 Like

Hi,

you can patch…

image

1 Like

Thank you both! I was already aware of these lisp functions, is there one that works with decimals?

is there one that works with decimals?

afaik not in the standard Common Lisp. A hairy solution could perhaps be to #'rationalize your numbers, and apply #'gcd or #'lcm to the #'numerators of these ratios?

(Not sure if this makes sense):
bilde

… ooops… meant #'denominator …

The issue, I think, is that it isn’t clear how you want the LCM and GCD to behave for non-integral values (since one normally associates these with the natural numbers). @anders is right that the first step is probably to (mapcar 'rationalize ...) your list of inputs. Can you give an example of what, beyond that, you were trying to achieve?