Saturday, October 22, 2022

HP 71B, TI 84 Plus CE: Sum of Egyptian Fractions

HP 71B, TI 84 Plus CE:  Sum of Egyptian Fractions


Introduction 


An Egyptian fraction consists of a sum of unit fractions.  A unit fraction is a fraction with 1 in its numerator and a positive integer in its denominator.   


Today's blog entry will calculate the Egyptian fraction given unit fractions, full simplified.   On tomorrow's entry, we will attempt the reverse process, breaking down an Egyptian fraction into a sum of unit fractions.


N/D = 1/A1 + 1/A2 + 1/A3 + 1/A4 + ....


The Algorithm


Start out with two unit fractions 1/A1 and 1/A2.  


Let N2/D2 = 1/A1 + 1/A2


Then:

N2/D2 = 1/A1 + 1/A2

N2/D2 = (A1 + A2)/(A1*A2)


Let N3/D3 = 1/A3 + N2/D2


Then:  N3/D3 = (A3*N2 + D2)/(N2*D2)


For any general point:


N_x+1/D_x+1 = (N_x * A_x + D_x)/(A_x * D_x)


This allows the user to input as many unit fractions as allowed.  


TI-84 Plus CE Program EGYPTSUM


Disp "EGYPT FRACTION SUM"

"2022-09-03 EWS"

Input "NO. TERMS? ",S

Input "1/A1? ",A

Input "1/A2? ",B

A+B→N

A*B→D

For(I,3,S)

"1/A"+toString(I)+"? "→Str1

Input Str1,A

A*N+D→N

A*D→D

End

gcd(N,D)→G

N/G→N

D/G→D

Disp "NUM= "+toString(N)

Disp "DEC= "+toString(D)

Disp "FRAC="+toString(N/D)


* This assumes your TI-84 Plus CE is at least has the 5.5 operating system.


HP 71B Program EGYPTSUM 


100 DISP "EGYPT FRACTION SUM" @ WAIT .5

105 DESTROY S,A,B,I,N,D,G

110 INPUT "# TERMS? ";S

115 INPUT "1/A1? ";A

120 INPUT "1/A2? ";B

125 N=A+B @ D=A*B

130 IF S=2 THEN 300


200 FOR I=3 TO S:

205 DISP "1/A"&STR$(I)&"?" @ WAIT .5

210 INPUT "1/A? ";A

215 N=A*N+D

220 D=A*D

225 NEXT I


300 A=N @ B=D

305 G=MOD(A,B)

310 A=B @ B=G

315 IF G THEN 305

320 N=N/A @ D=D/A


400 DISP "NUM= ";N

405 DISP "DEN= ";D

410 DISP "FRAC= ";N/D

415 STOP


The 300-325 section calculates the common greatest divisor, based off the "Greatest Common Divisor" program from 119 Practical Programs for the TRS-80 Pocket Computer (see source below).


Examples:


1/2 + 1/6

# TERMS = 2

Result:  2/3 (NUM = 2, DEN = 3)


1/7 + 1/8 + 1/2 

# TERMS = 3

Result:  43/56 (NUM = 43, DEN = 56)


1/9 + 1/5 + 1/15 + 1/8

# TERMS = 4

Result: 181/360 (NUM = 181, DEN = 360)


Source


Craig, John Clark.  119 Practical Programs For The TRS-80 Pocket Computer  TAB Books Inc.  Blue Ridge Summit, PA.  1982 pg. 133



All original content copyright, © 2011-2022.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.