[issue19237] Proposal : LCM function to complement GCD

2020-02-03 Thread Mark Dickinson


Mark Dickinson  added the comment:

See renewed discussion in #39479, which may lead to math.lcm being added in 3.9.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19237] Proposal : LCM function to complement GCD

2013-10-23 Thread Mark Dickinson

Mark Dickinson added the comment:

I'm going to reject this for the reasons already given above.  It's easy to 
write your own (lightweight, inefficient) lcm and multi-argument gcd if you 
need them.  For more serious work, you probably want to avoid Python's gcd 
anyway---it's horribly inefficient, and there are 3rd party solutions for 
specialised number-theoretic work (e.g., SymPy, SAGE, gmpy2).

--
resolution:  - rejected
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19237
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19237] Proposal : LCM function to complement GCD

2013-10-18 Thread Terry J. Reedy

Terry J. Reedy added the comment:

I am -0 (or more negative) for the same reason. The need for lcm is very rare. 
I think the gcd doc should give the lcm formula, with perhaps an index entry. 
The gcd doc might also mention that gcd is associative: gcd(a,b,c) = 
gcd(gcd(a,b),c).

The math module is nearly all float math. The integer only math.factorial(n) is 
relatively recent. Gcd in in fractions because we do not have an imath module 
and because the only use of gcd in the stdlib is for reducing fractions.

--
nosy: +terry.reedy

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19237
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19237] Proposal : LCM function to complement GCD

2013-10-13 Thread Mark Dickinson

Mark Dickinson added the comment:

To get the boundary cases correct, you need a special case for lcm(0, 0), which 
should be 0.

Did you have any particular use-cases in mind for this?  It may make sense to 
allow multiple arguments:  e.g., lcm(4, 5, 6) - 60.

Overall, I'm -0 on this addition: I don't think it comes up often enough to 
make it worth adding, and when it does come up it's easy to create the lcm from 
the gcd (just as your patch does).

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19237
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19237] Proposal : LCM function to complement GCD

2013-10-13 Thread CliffM

CliffM added the comment:

I've handled a patch, and extended both lcm and gcd to take an arbitrary number 
of arguments -- via functools.reduce, as they are both multiplicative (in the 
first argument).

Also handled the zero case , so lcm(0,0) = 0 = gcd(0,0)

Use-case-wise, I do a reasonable amount of number-theoretic work and lcm and 
gcd are always popping up.  If gcd is defined, it's nice to find lcm too.  

For those less well versed in number-theory, the implementation of lcm is not 
so obvious, and many end up going down a tedious prime factorisation route -- 
if they get that far.

But is it all worth it in the fractions module ?  They should really be in the 
math module.

--
Added file: http://bugs.python.org/file32084/lcm2.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19237
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19237] Proposal : LCM function to complement GCD

2013-10-12 Thread CliffM

New submission from CliffM:

While implementing a Least-Common-Multiple function (LCM), I noticed that 
although python has a Greatest-Common-Divisor (GCD) function in the fractions 
module, the LCM, its counterpart is not there.

I've attached a patch which implements and tests LCM in the fractions module. 

It would really need documentation, but maybe GCD and LCD should be moved to 
the math module first ?

--
components: Extension Modules
files: lcm.patch
keywords: patch
messages: 199624
nosy: CliffM
priority: normal
severity: normal
status: open
title: Proposal : LCM function to complement GCD
type: enhancement
versions: Python 3.4
Added file: http://bugs.python.org/file32068/lcm.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19237
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19237] Proposal : LCM function to complement GCD

2013-10-12 Thread Antoine Pitrou

Changes by Antoine Pitrou pit...@free.fr:


--
nosy: +mark.dickinson

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19237
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19237] Proposal : LCM function to complement GCD

2013-10-12 Thread Antoine Pitrou

Changes by Antoine Pitrou pit...@free.fr:


--
nosy: +tim.peters

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19237
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com