Re: HP-15C MC Bits o'Pi - My Original Solution & Comments Message #49 Posted by Rodger Rosenbaum on 19 Mar 2007, 6:44 a.m., in response to message #43 by Gerson W. Barbosa
Quote:
Assuming 26 is on the stack, the following returns
{ 0. 2. 2. 1. 2. 1. 0. 0. 1. 0. 2. 1. 2. 2. 0. 2. 2. 1. 2. 0. 2. 1. 1. 1. 0. 1. }
« -> n
« 3. 1. n
FOR n n 1. -
NEXT n ->LIST ^
TAN ATAN DUP ABS 1. >
SWAP DUP 0. < SWAP
-1. > AND 2. * 2.
« +
» DOLIST
»
»
Is there an easier way I missed?
Thanks for the interesting post.
Regards,
Gerson.
What I mean when I say that this program returns the correct ternary digits because of fortuitous circumstances is this:
Your program correctly gives the first 26 digits, but it makes errors for larger numbers of digits. For example, if the procedure of your program is carried with an arbitrary precision arithmetic package using 500 digits of precision, you will find that it makes an error at the 115th digit, and at the 138th digit, etc.
For example, the procedure of your program gives this result using high precision:
{0, 2, 2, 1, 2, 1, 0, 0, 1, 0, 2, 1, 2, 2, 0, 2, 2, 1, 2, 0, 2, 1, 1, 1, 0, 1,
2, 1, 2, 1, 1, 1, 2, 1, 0, 2, 0, 1, 1, 1, 0, 1, 2, 1, 2, 1, 1, 2, 2, 1, 1, 0,
1, 1, 2, 1, 1, 2, 2, 1, 0, 1, 0, 1, 1, 1, 1, 2, 0, 1, 1, 2, 0, 1, 1, 1, 1, 2,
0, 0, 2, 2, 0, 1, 2, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 2, 1, 0, 1, 2, 0, 1,
1, 1, 1, 2, 0, 2, 1, 0, 0, 0, 1, 2, 2, 2, 1, 2, 0, 1, 1, 1, 1, 2, 0, 1, 0, 1,
0, 2, 2, 0, 0, 1, 1, 1, 2, 2, 2, 0, 0, 1, 1, 1, 0, 2, 1, 1, 2, 0, 1, 1, 1, 1,
1, 2, 1, 2, 2, 2, 0, 1, 2, 1, 2, 2, 0, 0, 2, 0, 1, 0, 0, 1, 1, 2, 0, 1,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, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
Can you figure out why?
This shows how simply using numerical results can lead one astray. Just because a formula gives the correct result for the first n digits doesn't mean that it's correct for all n.
|