Från: Anders Tiberg Till: Ämne: AFrac Datum: den 1 juni 2001 14:40 AFrac, BFrac and CFrac written by Anders Tiberg. Reducing rational values the best way is to use continued fraction. There is no need to insert numerator and denominator separatly. You can either put a decimal number or an expression into a single value memory. CFrac is a simpler form, you could say the cousin from the country to continued fraction: CFrac :Prompt X :abs(X->Y :1->D :Repeat Y<.01 :D/Y->D :fPart(1/Y->Y :End :Disp XiPart(D :iPart(D This is the smallest and fastest program. The drawback is the preci- sion, since it uses the decimalparts of the terms, it starts to give faulty answers when numerator and denominator reaches 40- to 50 000. BFrac uses continued fraction the conventional way: BFrac :Prompt X :abs(X->Y :fPart(Y->F :0->I :0->dimL L :While I<21 and fPart(Y :I+1->I :1/fPart(Y->Y :Y->L(I :1->D:0->N :For (J,I,1,-1 :D->P :N+DiPart(L(J)->D :P->N :End :If abs (D*F-N)<=E-9 (.000000001) :Then :If .7>fPart(Y :0->Y :End :End :Disp DX:D BFrac has a much better precision than CFrac, it should be safe for values up to a million for numerator and denominator. It can give a correct answer to an expression like 17/191+19/193+23/199. However it's much slower,it runs through its For-loop 231 times during its 21 steps, in a "sweeping the stairs from below"-manner. AFrac uses continued fraction that fits its algorithm from above the expression, counting downwards, only once for every new term, saving time and bytes,with the same good precision as BFrac, wich makes it useful as a subroutene in a program of your own. Questions and/or input, mailto: anders.tiberg@telia.com