From 80693709d3d07e830d83beb53f71aa1a070d1c3b Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner <inform@tiker.net> Date: Mon, 7 Nov 2011 12:00:02 -0500 Subject: [PATCH] Add gcd_many and lcm. --- pymbolic/algorithm.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pymbolic/algorithm.py b/pymbolic/algorithm.py index 207df9d..95d1b96 100644 --- a/pymbolic/algorithm.py +++ b/pymbolic/algorithm.py @@ -27,6 +27,17 @@ def integer_power(x, n, one=1): def gcd(q, r): return extended_euclidean(q, r)[0] +def gcd_many(*args): + if len(args) == 0: + return 1 + elif len(args) == 1: + return args[0] + else: + return reduce(gcd, args) + +def lcm(q, r): + return abs(q*r)//gcd(q, r) + -- GitLab