(49G) Egyptian Fraction (Random) Programme - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: General Software Library (/forum-13.html) +--- Thread: (49G) Egyptian Fraction (Random) Programme (/thread-3971.html) |
(49G) Egyptian Fraction (Random) Programme - Gerald H - 05-25-2015 02:24 PM The programme EGYRAND takes a fraction expressed as the division of two integers from the stack & returns a random decomposition into Egyptian fractions. eg For entry '77/73' the programme returns :6: { 1 '1/19' '1/464' '1/128715' '1/11833836446' '1/490138897595538851760' } or :5: { 1 '1/19' '1/463' '1/321091' '1/206198539471' } or :5: { 1 '1/19' '1/464' '1/128714' '1/41418105776' } or :5: { 1 '1/20' '1/209' '1/101715' '1/6207463020' } or a different list. Here the programme in a box: Code: :: & again the programme (which depiction do you prefer?) :: CK1&Dispatch BINT10 :: BINT1 Z0_ FPTR2 ^2LAMBIND FPTR2 ^SIMP1ext FPTR2 ^FLAGPROPFRAC FPTR2 ^DUPTYPEZ? ?SKIP :: EXPR>_ SWAPDROP ' x/ EQUAL IT :: Z0_ 3UNROLL FPTR2 ^QDiv ; BEGIN 2GETLAM #1+ 2PUTLAM DUP FPTR2 ^FXNDext SWAP FPTR2 ^DupZIsOne? NOT_WHILE :: FPTR2 ^ZQUOText %RAN %.5 %> ITE Z1_ Z2_ FPTR2 ^RADDext DUP 1GETLAM Z<= IT :: DROP 1GETLAM Z2_ FPTR2 ^RADDext ; DUP1PUTLAM_ Z1_ FPTR2 ^SWAPRDIV DUPUNROT FPTR2 ^QSub ; REPEAT 2DROP ; 2GETLAM {}N 2GETLAM ABND #>$ >TAG ; ; |