How about adding rational fraction to Python?

Steve Holden steve at holdenweb.com
Sun Feb 24 12:46:23 EST 2008


Lie wrote:
> On Feb 18, 1:25 pm, Carl Banks <pavlovevide... at gmail.com> wrote:
>> On Feb 17, 1:45 pm, Lie <Lie.1... at gmail.com> wrote:
>>
>>>> Any iteration with repeated divisions and additions can thus run the
>>>> denominators up.  This sort of calculation is pretty common (examples:
>>>> compound interest, numerical integration).
>>> Wrong. Addition and subtraction would only grow the denominator up to
>>> a certain limit
>> I said repeated additions and divisions.
> 
> Repeated Addition and subtraction can't make fractions grow
> infinitely, only multiplication and division could.
> 
On what basis is this claim made?

(n1/d1) + (n2/d2) = ((n1*d2) + (n2*d1)) / (d1*d2)

If d1 and d2 are mutually prime (have no common factors) then it is 
impossible to reduce the resulting fraction further in the general case 
(where n1 = n2 = 1, for example).

>> Anyways, addition and subtraction can increase the denominator a lot
>> if for some reason you are inputing numbers with many different
>> denominators.
> 
> Up to a certain limit. After you reached the limit, the fraction would
> always be simplifyable.
> 
Where does this magical "limit" appear from?

> If the input numerator and denominator have a defined limit, repeated
> addition and subtraction to another fraction will also have a defined
> limit.

Well I suppose is you limit the input denominators to n then you have a 
guarantee that the output denominators won't exceed n!, but that seems 
like a pretty poor guarantee to me.

Am I wrong here? You seem to be putting out unsupportable assertions. 
Please justify them or stop making them.

regards
  Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC              http://www.holdenweb.com/




More information about the Python-list mailing list