Fast Arithmetic Functions¶
- sage.arith.functions.LCM_list(v)¶
Return the LCM of an iterable
v
.Elements of
v
are converted to Sage objects if they aren’t already.This function is used, e.g., by
lcm()
.INPUT:
v
– an iterable
OUTPUT: integer
EXAMPLES:
sage: from sage.arith.functions import LCM_list sage: w = LCM_list([3,9,30]); w 90 sage: type(w) <type 'sage.rings.integer.Integer'>
The inputs are converted to Sage integers:
sage: w = LCM_list([int(3), int(9), int(30)]); w 90 sage: type(w) <type 'sage.rings.integer.Integer'>
- sage.arith.functions.lcm(a, b=None)¶
The least common multiple of a and b, or if a is a list and b is omitted the least common multiple of all elements of a.
Note that LCM is an alias for lcm.
INPUT:
a,b
– two elements of a ring with lcm ora
– a list or tuple of elements of a ring with lcm
OUTPUT:
First, the given elements are coerced into a common parent. Then, their least common multiple in that parent is returned.
EXAMPLES:
sage: lcm(97,100) 9700 sage: LCM(97,100) 9700 sage: LCM(0,2) 0 sage: LCM(-3,-5) 15 sage: LCM([1,2,3,4,5]) 60 sage: v = LCM(range(1,10000)) # *very* fast! sage: len(str(v)) 4349