Re: Trouble getting loop to break

2007-11-25 Thread Dick Moores
At 01:32 PM 11/20/2007, Fredrik Johansson wrote: On Nov 20, 2007 10:00 PM, Dick Moores [EMAIL PROTECTED] wrote: And also with the amazing Chudnovsky algorithm for pi. See http://python.pastebin.com/f4410f3dc Nice! I'd like to suggest two improvements for speed. First, the Chudnovsky

Re: Trouble getting loop to break

2007-11-25 Thread John Machin
On Nov 25, 7:00 pm, Dick Moores [EMAIL PROTECTED] wrote: At 01:32 PM 11/20/2007, Fredrik Johansson wrote: On Nov 20, 2007 10:00 PM, Dick Moores [EMAIL PROTECTED] wrote: And also with the amazing Chudnovsky algorithm for pi. See http://python.pastebin.com/f4410f3dc Nice! I'd like

Re: Trouble getting loop to break

2007-11-25 Thread Fredrik Johansson
On Nov 25, 2007 9:00 AM, Dick Moores [EMAIL PROTECTED] wrote: Fredrik, I'm afraid I'm just too dumb to see how to use your first suggestion of cached_factorials. Where do I put it and def()? Could you show me, even on-line, what to do? http://py77.python.pastebin.com/f48e4151c You (or

Re: Trouble getting loop to break

2007-11-25 Thread Dick Moores
At 03:26 AM 11/25/2007, Fredrik Johansson wrote: On Nov 25, 2007 9:00 AM, Dick Moores [EMAIL PROTECTED] wrote: Fredrik, I'm afraid I'm just too dumb to see how to use your first suggestion of cached_factorials. Where do I put it and def()? Could you show me, even on-line, what to do?

Re: Trouble getting loop to break

2007-11-25 Thread Fredrik Johansson
On Nov 25, 2007 2:47 PM, Dick Moores [EMAIL PROTECTED] wrote: Wow. your f() is ingenious, Frederik. Thanks very much. Any more tricks up your sleeve? You did say a post or so ago, Further improvements are possible. The next improvement would be to find a recurrence formula for the terms

Re: Trouble getting loop to break

2007-11-20 Thread Dick Moores
At 12:45 AM 11/20/2007, Dennis Lee Bieber wrote: On Mon, 19 Nov 2007 23:41:02 -0800, Dick Moores [EMAIL PROTECTED] declaimed the following in comp.lang.python: a way to get it to break where I want it to, i.e., when the sum equals the limit as closely as the precision allows? if sum

Re: Trouble getting loop to break

2007-11-20 Thread Fredrik Johansson
On Nov 20, 2007 8:41 AM, Dick Moores [EMAIL PROTECTED] wrote: I'm writing a demo of the infinite series x**0/0! + x**1/1! + x**2/2! + x**3/3! + ... = e**x (x is non-negative) It works OK for many x, but for many the loop doesn't break. Is there a way to get it to break where I want it

Re: Trouble getting loop to break

2007-11-20 Thread [EMAIL PROTECTED]
Instead of comparing sum to the known value of e**x, why not test for convergence? I.e., if sum == last_sum: break. Seems like that would be more robust (you don't need to know the answer to computer the answer), since it seems like it should converge. --Nathan Davis On Nov 20, 1:41 am, Dick

Re: Trouble getting loop to break

2007-11-20 Thread Dick Moores
At 03:53 AM 11/20/2007, Fredrik Johansson wrote: On Nov 20, 2007 8:41 AM, Dick Moores [EMAIL PROTECTED] wrote: I'm writing a demo of the infinite series x**0/0! + x**1/1! + x**2/2! + x**3/3! + ... = e**x (x is non-negative) It works OK for many x, but for many the loop doesn't break.

Re: Trouble getting loop to break

2007-11-20 Thread Dick Moores
At 10:42 AM 11/20/2007, [EMAIL PROTECTED] wrote: Instead of comparing sum to the known value of e**x, why not test for convergence? I.e., if sum == last_sum: break. Seems like that would be more robust (you don't need to know the answer to computer the answer), since it seems like it should

Re: Trouble getting loop to break

2007-11-20 Thread Fredrik Johansson
On Nov 20, 2007 10:00 PM, Dick Moores [EMAIL PROTECTED] wrote: And also with the amazing Chudnovsky algorithm for pi. See http://python.pastebin.com/f4410f3dc Nice! I'd like to suggest two improvements for speed. First, the Chudnovsky algorithm uses lots of factorials, and it's rather

Re: Trouble getting loop to break

2007-11-20 Thread Steven D'Aprano
On Tue, 20 Nov 2007 10:42:48 -0800, [EMAIL PROTECTED] wrote: Instead of comparing sum to the known value of e**x, why not test for convergence? I.e., if sum == last_sum: break. Seems like that would be more robust (you don't need to know the answer to computer the answer), since it seems

Trouble getting loop to break

2007-11-19 Thread Dick Moores
I'm writing a demo of the infinite series x**0/0! + x**1/1! + x**2/2! + x**3/3! + ... = e**x (x is non-negative) It works OK for many x, but for many the loop doesn't break. Is there a way to get it to break where I want it to, i.e., when the sum equals the limit as closely as the