Re: [Python-Dev] Rational approximation methods

2008-01-22 Thread Jeffrey Yasskin
On Jan 20, 2008 5:54 PM, Tim Peters [EMAIL PROTECTED] wrote: What would be useful is a method that generates (i.e., a generator in the Python sense) the (continued fraction) convergents to a rational. People wanting specific constraints on a rational approximation (including, but not limited

Re: [Python-Dev] Rational approximation methods

2008-01-21 Thread Paul Moore
On 21/01/2008, Tim Peters [EMAIL PROTECTED] wrote: What would be useful is a method that generates (i.e., a generator in the Python sense) the (continued fraction) convergents to a rational. People wanting specific constraints on a rational approximation (including, but not limited to, the two

Re: [Python-Dev] Rational approximation methods

2008-01-21 Thread Mark Dickinson
On Jan 21, 2008 3:44 AM, Paul Moore [EMAIL PROTECTED] wrote: On 21/01/2008, Tim Peters [EMAIL PROTECTED] wrote: By useful I don't mean lots of people will use it ;-) I mean /some/ people will use it -- a way to generate the sequence of convergents is a fundamental tool that can be used for

Re: [Python-Dev] Rational approximation methods

2008-01-20 Thread Paul Moore
On 19/01/2008, Jeffrey Yasskin [EMAIL PROTECTED] wrote: The first returns the closest rational whose denominator is less than a given integer. [...] The second returns the simplest rational within some distance. Both of these are likely to be of limited use. The most common usage I know of is

Re: [Python-Dev] Rational approximation methods

2008-01-20 Thread Leif Walsh
On 1/20/08, Paul Moore [EMAIL PROTECTED] wrote: Both of these are likely to be of limited use. The most common usage I know of is to make a sensible rational from a float (i.e., a DWIM style conversion 0.1 - 1/10) or to provide readable output. On the other hand, both are subtle to implement,

Re: [Python-Dev] Rational approximation methods

2008-01-20 Thread Tim Peters
What would be useful is a method that generates (i.e., a generator in the Python sense) the (continued fraction) convergents to a rational. People wanting specific constraints on a rational approximation (including, but not limited to, the two you identified) can easily build them on top of such a

[Python-Dev] Rational approximation methods

2008-01-19 Thread Jeffrey Yasskin
In the Rational class that I've recently checked into Python 2.6 (http://bugs.python.org/issue1682), it might be nice to provide a method that, given a particular rational number, returns a nearby number that's nicer in some way. I know of two reasonable behaviors for this operation. Since I don't

Re: [Python-Dev] Rational approximation methods

2008-01-19 Thread Scott David Daniels
Jeffrey Yasskin wrote: The second returns the simplest rational within some distance. For instance, it'll prefer 22/7 over 333/106 if both are close enough. We might call it .simplest_within() for now. This seems useful for converting from float and displaying results to users, where we prefer

Re: [Python-Dev] Rational approximation methods

2008-01-19 Thread Mark Dickinson
On Jan 19, 2008 3:06 PM, Jeffrey Yasskin [EMAIL PROTECTED] wrote: In the Rational class that I've recently checked into Python 2.6 (http://bugs.python.org/issue1682), it might be nice to provide a method that, given a particular rational number, returns a nearby number that's nicer in some