Re: [Tutor] Need help with rewriting script to use Decimal module

2007-01-08 Thread Dick Moores
At 06:32 PM 1/7/2007, Terry Carroll wrote: >I may add this algorithm to the cookbook. You should. Dick ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Need help with rewriting script to use Decimal module

2007-01-07 Thread Terry Carroll
On Sun, 7 Jan 2007, Terry Carroll wrote: > ...Say you want to get an approximation of 0.096. Well, a good first > approximation is 1/10. But 1/10 is 0.010 Um, that should be "...is 0.100" ___ Tutor maillist - Tutor@python.org http://mail.pytho

Re: [Tutor] Need help with rewriting script to use Decimal module

2007-01-07 Thread Terry Carroll
On Sat, 6 Jan 2007, Dick Moores wrote: > Well, I have to admit I don't understand your code at all. But I see it > works. A continuing fraction is an expression that looks like this: 1 A + -- 1 B +

Re: [Tutor] Need help with rewriting script to use Decimal module

2007-01-06 Thread Dick Moores
At 10:40 AM 1/6/2007, Dick Moores wrote: >At 11:21 PM 1/4/2007, Terry Carroll wrote: > >On Wed, 3 Jan 2007, Dick Moores wrote: > > > > > Be that as it may, farey() is an amazing program. > > > >Not to beat this subject to death, but the comment at the bottom of > >http://aspn.activestate.com/ASPN/C

Re: [Tutor] Need help with rewriting script to use Decimal module

2007-01-06 Thread Dick Moores
At 11:21 PM 1/4/2007, Terry Carroll wrote: >On Wed, 3 Jan 2007, Dick Moores wrote: > > > Be that as it may, farey() is an amazing program. > >Not to beat this subject to death, but the comment at the bottom of >http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52317 about >continued fractions

Re: [Tutor] Need help with rewriting script to use Decimal module

2007-01-04 Thread Terry Carroll
On Wed, 3 Jan 2007, Dick Moores wrote: > Be that as it may, farey() is an amazing program. Not to beat this subject to death, but the comment at the bottom of http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52317 about continued fractions piqued my interest. I'm no mathematician, but

Re: [Tutor] Need help with rewriting script to use Decimal module

2007-01-04 Thread Dick Moores
At 08:20 AM 1/4/2007, Terry Carroll wrote: >On Wed, 3 Jan 2007, Dick Moores wrote: > > > Terry, I just noticed that farey(0.36, 10) returns (1, 3), a pretty > > big miss, IMO. The correct fraction with smallest error and maximum > > denominator of 10 is 3/8, which I'm proud to say my klunky frac.py

Re: [Tutor] Need help with rewriting script to use Decimal module

2007-01-04 Thread Terry Carroll
On Wed, 3 Jan 2007, Dick Moores wrote: > Terry, I just noticed that farey(0.36, 10) returns (1, 3), a pretty > big miss, IMO. The correct fraction with smallest error and maximum > denominator of 10 is 3/8, which I'm proud to say my klunky frac.py > (

Re: [Tutor] Need help with rewriting script to use Decimal module

2007-01-03 Thread Dick Moores
At 01:17 PM 1/2/2007, Terry Carroll wrote: >On Mon, 1 Jan 2007, Dick Moores wrote: > > > bestFracForMinimumError() is only a small part of a program I wrote > > long ago, called frac.py > >Dick, if your goal is to have a routine to get the fraction with the least >possible error (as opposed to lear

Re: [Tutor] Need help with rewriting script to use Decimal module

2007-01-03 Thread Danny Yoo
>> Dick, if your goal is to have a routine to get the fraction with the least >> possible error (as opposed to learing how to use Decimal), have a look at >> this recipe from the Python Cookbook: >> >> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52317 > > Terry, that is truly ingenio

Re: [Tutor] Need help with rewriting script to use Decimal module

2007-01-03 Thread Terry Carroll
On Wed, 3 Jan 2007, Dick Moores wrote: > At 01:17 PM 1/2/2007, Terry Carroll wrote: > > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52317 > > Terry, that is truly ingenious. Is there an explication anywhere of > exactly how it works? There is in the printed copy of the Python Coo

Re: [Tutor] Need help with rewriting script to use Decimal module

2007-01-03 Thread Dick Moores
At 01:17 PM 1/2/2007, Terry Carroll wrote: >On Mon, 1 Jan 2007, Dick Moores wrote: > > > bestFracForMinimumError() is only a small part of a program I wrote > > long ago, called frac.py > >Dick, if your goal is to have a routine to get the fraction with the least >possible error (as opposed to lear

Re: [Tutor] Need help with rewriting script to use Decimal module

2007-01-03 Thread Dick Moores
At 10:39 AM 1/2/2007, Kent Johnson wrote: >Dick Moores wrote: >>from decimal import Decimal as D >>def bestFracForMinimumError(decimal, minimumError): >> denom = 0 >> while True: >> denom += 1 >> num = round(D(str(decimal)) * D(str(denom))) >> error = abs(str((s

Re: [Tutor] Need help with rewriting script to use Decimal module

2007-01-02 Thread Terry Carroll
On Tue, 2 Jan 2007, Terry Carroll wrote: > Dick, if your goal is to have a routine to get the fraction with the least > possible error (as opposed to learing how to use Decimal), have a look at > this recipe from the Python Cookbook: > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/

Re: [Tutor] Need help with rewriting script to use Decimal module

2007-01-02 Thread Terry Carroll
On Mon, 1 Jan 2007, Dick Moores wrote: > bestFracForMinimumError() is only a small part of a program I wrote > long ago, called frac.py Dick, if your goal is to have a routine to get the fraction with the least possible error (as opposed to learing how to use Decimal), have a look at this rec

Re: [Tutor] Need help with rewriting script to use Decimal module

2007-01-02 Thread Kent Johnson
Dick Moores wrote: > from decimal import Decimal as D > > def bestFracForMinimumError(decimal, minimumError): > denom = 0 > while True: > denom += 1 > num = round(D(str(decimal)) * D(str(denom))) > error = abs(str((str(D(num) / D(str(denom))) - This looks back

Re: [Tutor] Need help with rewriting script to use Decimal module

2007-01-02 Thread Dick Moores
from decimal import Decimal as D def bestFracForMinimumError(decimal, minimumError): denom = 0 while True: denom += 1 num = round(D(str(decimal)) * D(str(denom))) error = abs(str((str(D(num) / D(str(denom))) - D(str(decimal))) / str(D(str(decimal)) * d("100"))

Re: [Tutor] Need help with rewriting script to use Decimal module

2007-01-01 Thread Dick Moores
At 05:37 AM 1/1/2007, Kent Johnson wrote: >Dick Moores wrote: >>bestFracForMinimumError() is only a small part of a program I wrote >>long ago, called frac.py >>(). I'm trying to >>rewrite it so as to get more precision by using the Decimal module, >>

Re: [Tutor] Need help with rewriting script to use Decimal module

2007-01-01 Thread Kent Johnson
Dick Moores wrote: > bestFracForMinimumError() is only a small part of a program I wrote > long ago, called frac.py > (). I'm trying to rewrite > it so as to get more precision by using the Decimal module, but am > getting nowhere. Errors all over the