HP15C (& LE!) 111111 MiniChallenge ORIGINAL SOLUTION & COMMENTS Message #29 Posted by Valentin Albillo on 14 Nov 2011, 8:12 a.m., in response to message #1 by Valentin Albillo
Hi, all:
Thanks for your interest in my HP15C (&LE!) Minichallenge, I'm glad many of you enjoyed it and produced a number of correct solutions, some of which virtually duplicated my original one, as well as producing solutions for other models. That's the spirit of these challenges and minichallenges and I thank you for joining in.
As for my original solution, this is it:
01 LBL A
02 EEX
03 6
04 CHS
05 STO I
06 I
07 GSB E
08 Re<>Im
09 CF 8
10 RCL/ I
11 RTN
which is 11 steps and meets all 5 requirements. I prefer to use h=1E6 instead of smaller values and I think that CF 8 must be included lest you'll leave the machine in complex mode, which would be utterly unexpected to the user as both the input and the output are assumed and expected to be real.
Partially relaxing condition (1), i.e., supressing LBL and RTN, would save two steps, while relaxing condition (4), i.e., prestoring 1E6 in a register, would save three additional steps, leaving the grand total at a mere 6 steps or so. An additional step could be saved by supressing CF 8 but as stated above, I think this would seriously detract from the usability.
As for the register used to store the constant, I prefer using permanent register RI instead of R0 or R1 (also permanent) though, as the constant is less than one, the best solution is using register RAN#, which frees RI for indexing purposes and R0R1 for general use or matrix operations. However, as there's no RCL\ RAN# instruction this means an additional step to perform the division.
Finally, I knew that for X arguments near 0 accuracy would get worse and so require extra steps to cater for that case, thus this is why I included the exception at condition (5) in order to keep it short and sweet. After all, this was intended as a Minichallenge, not a fullfledged article on numerical derivation complete with industrialstrength code ! ... :D
When I was busy concocting this minichallenge, I first implemented it for the HP71B, where the code is as simple as
IMPT(FNF((X,H)))/H
where FNF is the userdefined function f(x) and H is a suitably small constat (1E7, say). I conducted some experiments to see which H would be best, for instance:
10 DEF FNF(X)=5*COS(10*X)+((X2)*X6)*X+10
20 DEF FND(X)=50*SIN(10*X)+3*X*X4*X6
30 FOR I=1 TO 9 @ H=10^(I) @ DISP I;IMPT(FNF((1,H)))/H,FND(1) @ NEXT I
>RUN
1 24.9567129442 20.2010555444
2 20.24631331 20.2010555444
3 20.2015078976 20.2010555444
4 20.201060068 20.2010555444
5 20.2010555897 20.2010555444
6 20.2010555449 20.2010555444
7 20.2010555444 20.2010555444 << H=1E7 first nails the exact derivative
8 20.2010555444 20.2010555444
9 20.2010555444 20.2010555444
and in virtually all cases H = 1E7 was optimal (except for X near 0, of course, where a smaller H is needed). For the HP15C, which only carries 10 (13) digits instead of 12 (15), H=1E6 does the trick.
That's all. I've got (hopefully) interesting ideas for some dozen challenges and minichallenges as well as for another dozen fullfledged articles but regrettably next to no or very little time to write them down & post them hera, and actually no suitable place to publish the long articles so it might be a while till I make another lengthy contribution ... :(
Thanks again for your interest and best regards from V.
