[issue2138] Add a factorial function

2010-05-12 Thread Mark Dickinson
Mark Dickinson added the comment: maix: good point. Fixed in revisions r81126 through r81129. -- ___ Python tracker ___ ___ Python-b

[issue2138] Add a factorial function

2008-09-15 Thread maix
maix <[EMAIL PROTECTED]> added the comment: I think the unit test is wrong, or at least not as is intended: You put some numbers in values and shuffle them. But you don't use them but just range(10) for testing. -- nosy: +maix ___ Python tracker <[EM

[issue2138] Add a factorial function

2008-07-16 Thread Georg Brandl
Georg Brandl <[EMAIL PROTECTED]> added the comment: That was fixed by Raymond in 64365. -- nosy: +georg.brandl ___ Python tracker <[EMAIL PROTECTED]> ___ __

[issue2138] Add a factorial function

2008-06-17 Thread Mark Dickinson
Mark Dickinson <[EMAIL PROTECTED]> added the comment: It looks like there's a refcounting bug in the code: if the call to PyNumber_Multiply fails then iobj gets DECREF'd twice. This means that a keyboard interrupt of factorial() can exit the interpreter: Python 2.6a3+ (trunk:64341M, Jun 17 20

[issue2138] Add a factorial function

2008-06-08 Thread Raymond Hettinger
Raymond Hettinger <[EMAIL PROTECTED]> added the comment: Added math.factorial() in r64050. -- resolution: -> accepted status: open -> closed ___ Python tracker <[EMAIL PROTECTED]> ___

[issue2138] Add a factorial function

2008-05-31 Thread Raymond Hettinger
Raymond Hettinger <[EMAIL PROTECTED]> added the comment: I've got in from here. -- assignee: marketdickinson -> rhettinger ___ Python tracker <[EMAIL PROTECTED]> ___ __

[issue2138] Add a factorial function

2008-05-31 Thread Mark Dickinson
Changes by Mark Dickinson <[EMAIL PROTECTED]>: -- assignee: -> marketdickinson ___ Python tracker <[EMAIL PROTECTED]> ___ ___ Python-bu

[issue2138] Add a factorial function

2008-05-31 Thread Mark Dickinson
Mark Dickinson <[EMAIL PROTECTED]> added the comment: Contrary to what I said above, I'm not going to find time for this before the beta. Anyone else want to have a go at producing a patch? A simple implementation would be fine---the algorithm could be tweaked for speed later.

[issue2138] Add a factorial function

2008-05-31 Thread Joshua Uziel
Joshua Uziel <[EMAIL PROTECTED]> added the comment: Or slightly better: from operator import mul def factorial(num): return reduce(mul, range(2, num+1), 1) ___ Python tracker <[EMAIL PROTECTED]> _

[issue2138] Add a factorial function

2008-05-31 Thread Joshua Uziel
Joshua Uziel <[EMAIL PROTECTED]> added the comment: It's a simplified version, but why not something like this: import operator def factorial(num): return reduce(operator.mul, range(1, num+1)) A product() function could also be done similarly. -- nosy: +uzi ___

[issue2138] Add a factorial function

2008-04-03 Thread Terry J. Reedy
Terry J. Reedy <[EMAIL PROTECTED]> added the comment: The fact that other languages have factorial does not in itself impress me. What is the actual use case other than illustrating computational induction (whether by iteration or recursion) and for calculating binomial coefficients? I don't re

[issue2138] Add a factorial function

2008-03-18 Thread Raymond Hettinger
Raymond Hettinger <[EMAIL PROTECTED]> added the comment: I prefer factorial as a method (like Ruby and Smalltalk). Given the usual notation (n!) or pronounciation (n factorial), it is natural to write this as: n.factorial(). Compared to numbits() and isqrt(), a factorial() method is more basi

[issue2138] Add a factorial function

2008-03-18 Thread Mark Dickinson
Mark Dickinson <[EMAIL PROTECTED]> added the comment: I'm not opposed to adding factorial somewhere, and it doesn't seem as though anyone else is actively opposed to factorial either. The problem is working out where best to put it. To my inexperienced eyes, it feels wrong to add it as an int/l

[issue2138] Add a factorial function

2008-03-17 Thread Raymond Hettinger
Raymond Hettinger <[EMAIL PROTECTED]> added the comment: Problems with product(): It is dreadfully inefficient compared to a good implementation of factorial. It has the same name a new itertool with much different functionality. The hyper-generalization takes us further away from the OP's dir

[issue2138] Add a factorial function

2008-03-17 Thread paul rubin
paul rubin <[EMAIL PROTECTED]> added the comment: Rather than factorial how about a product function, so factorial(n) = product(xrange(1,n+1)). I do like the idea of an imath module whether or not it has factorial, and the topic of this rfe has drifted somewhat towards the desirability of such a

[issue2138] Add a factorial function

2008-03-17 Thread Raymond Hettinger
Raymond Hettinger <[EMAIL PROTECTED]> added the comment: Wish I could be at the sprint. I'm back in Los Angeles. My little post will have to suffice. I thought it was a reasonable request and would hate to see it killed because other people piled on other requests that were not reasonable.

[issue2138] Add a factorial function

2008-03-17 Thread Sean Reifschneider
Sean Reifschneider <[EMAIL PROTECTED]> added the comment: Raymond: Can you come into the core sprint and discuss it with the table on the right just as you come in the door of the sprint room? Lian said that was who he discussed it with and they came to the conclusion to reject it. -- n

[issue2138] Add a factorial function

2008-03-17 Thread Raymond Hettinger
Raymond Hettinger <[EMAIL PROTECTED]> added the comment: FWIW, I don't agree with the reasoning on the rejection. Hundreds of calculator layouts and school textbooks suggest that you can have a useful factorial function without having to also add binomials and whatnot. The OP requested a simp

[issue2138] Add a factorial function

2008-03-17 Thread Ilan Schnell
Ilan Schnell <[EMAIL PROTECTED]> added the comment: The factorial function is most likely to be used in context with other combinatorial functions (like binomial coefficients) for these functions an external module seems most appropriate. Most likely people would use a factorial function only fo