'=========================================================================== ' Subject: FIND RATIONAL EQUIVALENT Date: 04-14-99 (16:46) ' Author: Donald R. Darden Code: PB ' Origin: oldefoxx@earthlink.net Packet: PB.ABC '=========================================================================== $option cntlbreak DEFDBL A-Z COLOR 15,1 CLS ? ?" RATIONAL.BAS By Donald R. Darden ?" Copyright Nov 11, 1976 (HP25 Calculator version) ?" Copyright September 9, 1991 (IBM Compatable PC version) ?" Offered as FREEWARE April 14, 1999, on the following conditions: ?" a. That embedded algorythm and/or process included are both ?" credited to the author (a little recognition, please). ?" b. That I am informed where and how this proved applicable. ?" c. Any ideas for improvements are shared publicly. ?"======================================================================== ?" The purpose of this program is to determine a rational equivalent of any ?" entered real number (such as 3.141592654...). The program will proceed ?" through a series of approximations, attempting to narrow the range of ?" error until an acceptable limit of error is reached. This process ?" involves approximations based on the relationship between the unresol- ?" ved portion of the whole number and the fractional part that remains." ?"======================================================================== ?" Comment: It is interesting to note that the hint that this algorythm ?" could be derived came during an investigation into the possible integers ?" to approximate PI, which is best achieved by 355/113 which is accurate to ?" six decimal places. It was noted that .25 was 1/4, and 4 is the result of ?" taking the reciprocal (1/.25=4). Also .333333... was 3 after 1/.33333, ?" and a more advanced example of converting .666666... should provide 2/3. ?" The pivotable behavior around the decimal point on taking reciprocals ?" became the key to the algorythm. ?"Press any key to continue..."; sleep do loop while inkey$>"" cls $if 0 I now wonder if there is other pivotable behaviour, say in deducing what the private encryption key might be after decrypting an encrypted message that was created with a public key. Of course that is a far more extreme case. But consider this program that I developed, which is somewhat difficult do describe in mathematical terms, since it involves such unconventional methods, such as using INT and FRAC, partial values, and conditional flow which do not lend themselves to a simple expression. So perhaps our present limitation in trying to find the primes to an encryption process is due more to our inability to conceptualize a method that works with just the tools that we've learned, rather than creating tools that capitalize on the nature of the problem and its inherant one-ness with itself. -- Don Darden $endif DOit: PRINT INPUT "What Number to Rationalize: ", a$ if a$="" then ?"Done!" end end if r0 = VAL(a$) a = INSTR(a$, ".") r9 = LEN(a$) - a IF r9 < 6 THEN r9 = 4 r9 = INT(10 ^ (r9 + 2) + .5) IF r0 = 0 THEN ?"This number cannot be rationalized" GOTO DOit END IF r1 = 1 / r0 r5 = 1 ?"Expression = Value:"; TAB(52); "Amount of Error:" DO r5 = r1 * r5 r2 = 1 / r1 r1 = r2 - INT(r2) IF r1 = 0 THEN r1 = 1 r3 = r2 / r1 r5 = r5 * r3 r4 = INT(r5) r7 = INT(r4 * r0 + .5) r6 = r7 / r4 - r0 r8 = INT(r6 * 100000000) a$ = STR$(r6) a = INSTR(2, a$, "-") IF a THEN a$ = LEFT$(a$, 1) + LEFT$(".00000000000000", VAL(MID$(a$, a + 1))) + MID$(a$, 2, 1) + MID$(a$, 4, a - 5) END IF ?r7; "/"; r4; "="; r7 / r4; TAB(52); a$ LOOP WHILE r8 GOTO DOit