Valentin Albillo's "Boldly Going... Going Back to the roots" now for the HP-41 !
|
04-16-2024, 08:05 AM
(This post was last modified: 04-16-2024 12:02 PM by Vincent Weber.)
Post: #1
|
|||
|
|||
Valentin Albillo's "Boldly Going... Going Back to the roots" now for the HP-41 !
Hi all,
A few months back, I ported Valentin's albillo efficient complex solver (see his article) from the 35S to the 42S and to the 32SII/DM32. Porting it to the 42S was trivial, as both the 35S and the 42S can deal with complex numbers easily (on the stack and in storage registers). Porting it to the 32SII/DM32 was another pair of shoes. Those only have a 2-level complex stack instead of 4, and lack complex registers. So porting the program was more complicated: not only every STO/RCL had to be doubled, but moreover, anything needing more than 2 numbers on the stack (like / followed by +) had to use temporary storage. Porting it to the 41 was even more complicated, since the 41 doesn'have complex numbers at all. Well, you have the Advantage Pack's crude RPN routines, but those use registers, which is a headache when your program also needs a lot of registers ! You could use Angel Martin's awesome MCODE 41Z module, or even the TOULMATH module (which replicated the 15C complex stack in MCODE), but none of these ware available to the user back in the day, so this would be cheating... I found a simple way, reading the software library on this very forum: Jean-Marc Baillard actually wrote his own 2-level stack RPN complex functions (here), with several improvements over the Math/Advantage Pack: - No registers used at all; - Simpler usage; - Complete trigs and hyperbolics. Jean-Marc also wrote his own complex solvers, which work fine. However, they are not as elegantly simple as Valentins's, they require 2 or 3 estimates, or even to compute first and second order derivatives, vs. only one estimate. But this gave me the idea of the port... So, first key-in Jean-Marc's complex stack functions. Hint: rather than your fingers (only the text is provided), copy the text, paste into Free42/Plus42 (pasting is very powerful), and then export it into a 41C-compatible raw file than you can email to yourself ! As for the port itself, here we go. Please note that whenever Valentin used a lettered 35S complex register, I used the corresponding numbered register (e.g. X became 24) for the real part, and then I used registers as needed for the imaginary parts, starting with 01. Registers 07 to 18 are free to use in your own equations programs. Register 00 has to hold the equation program's name in alphanumerical form (use ASTO 00 to store it). The program is called "RZVA" for "Root Z (complex) from Valentin Albillo" Code:
Here is an example function to use. This is the first example from Valentin's article (Z^Z-R=0). The program expects the complex variable to be stored in X (from the 35S), which means register 26 (for the real part) and 01 (for the imaginary part). The constant R has to be stored in registers 9 (real) and 8 (imaginary). Here R = i, so R08 = 1 and R09 =0. Code:
Juste do EQ1 ASTO 00 to store the equation, put 1 and 0 on the stack for the estimate (i), and voilà. This works perfectlly... except for one thing: it is slow as hell !! Basically, take Valentin's timings in his article, they are expressed in seconds, well, take the same numbers expressed in minutes, you'll get an idea on how slow it is. I cheated by accelerating the emulated 41 in i41cx+. Even at max speed, this is still quite slow. The 41 is a slow machine to begin with, the RPN complex routines and constant need for intermediate storage doesn't help either... but if you are patient, now your bare-bones 41 can solve any complex equation ! Comments welcome of cours. Cheers, Vincent |
|||
04-16-2024, 08:19 AM
Post: #2
|
|||
|
|||
RE: Valentin Albillo's "Boldly Going... Going Back to the roots" now for the...
(04-16-2024 08:05 AM)Vincent Weber Wrote: Porting it to the 32SII/DM42 was another pair of shoes. I think you meant 32SII/DM32 here. Greetings, Massimo -+×÷ ↔ left is right and right is wrong |
|||
04-16-2024, 08:21 AM
Post: #3
|
|||
|
|||
RE: Valentin Albillo's "Boldly Going... Going Back to the roots" now for the... | |||
04-17-2024, 10:32 AM
(This post was last modified: 04-17-2024 10:46 AM by Vincent Weber.)
Post: #4
|
|||
|
|||
RE: Valentin Albillo's "Boldly Going... Going Back to the roots" now for the...
I managed to speed up the '41 program with some optimizations, mainly having the complex stack routines stored in HEPAX and all XEQs to them converted into XROMs. Now, in the above example where R=PI, instead of over 3 minutes, the program runs in 1min 40 seconds!
I made a 15C version. While the 15C is a ground-breaking machine with MCODE complex stack routines, it does not do much better: 1min 20 seconds. Maybe because its processor is slower than the 41's by half. In addition, the 15C program is not really simpler nor shorter than the '41 one, because the 15C lacks complex registers, so you have to write 4 steps for each store and recall operation. Furthermore Valentin's original program for the 35S makes heavy use of complex recall arithmetics, not possible on the 15C precisely because of this lack of complex registers. The only real advantage of the 15C is that you have a 4-level stack instead of 2, so intermediate computation storage is not necessary (but this happens only once in the '41 version). So,' 41 and 15C almost on par on this one! |
|||
04-18-2024, 07:22 AM
Post: #5
|
|||
|
|||
RE: Valentin Albillo's "Boldly Going... Going Back to the roots" now for the...
Vincent, nice job indeed. Can you post the link to your HP-42 version of the program? I'd like to try a direct conversion using the 41Z as well...
Cheers, ÁM "To live or die by your own sword one must first learn to wield it aptly." |
|||
04-18-2024, 07:25 AM
Post: #6
|
|||
|
|||
RE: Valentin Albillo's "Boldly Going... Going Back to the roots" now for the...
(04-18-2024 07:22 AM)Ángel Martin Wrote: Vincent, nice job indeed. Can you post the link to your HP-42 version of the program? I'd like to try a direct conversion using the 41Z as well...Hi Angel, You mean the.raw of the 41 version? Or the 42s version? The 42s doesn't need 41Z No doubt that 41Z will outperform everything but the 42 variant... But 41Z was not available in the 80s Cheers |
|||
04-18-2024, 07:26 AM
(This post was last modified: 04-18-2024 07:29 AM by Ángel Martin.)
Post: #7
|
|||
|
|||
RE: Valentin Albillo's "Boldly Going... Going Back to the roots" now for the...
(04-18-2024 07:25 AM)Vincent Weber Wrote: Hi Angel, I mean the HP-42s version, a text listing will work. Thanks "To live or die by your own sword one must first learn to wield it aptly." |
|||
04-18-2024, 07:31 AM
Post: #8
|
|||
|
|||
RE: Valentin Albillo's "Boldly Going... Going Back to the roots" now for the...
I had posted the (Plus42, not 42s) version in this thread:
https://www.hpmuseum.org/forum/thread-21036.html As extra features over the 42S, it only makes use of LSTO, and the equation to be solved is stored as a Plus42 equation rather than a RPN program. |
|||
04-18-2024, 07:09 PM
Post: #9
|
|||
|
|||
RE: Valentin Albillo's "Boldly Going... Going Back to the roots" now for the...
I see, well those pesky equations really get in the way to do a port of the code as-is, I guess it'll be a moot point reinventing the wheel you have already done.
I went back and checked the root-finding sections in the 41Z manual, it's been a while but it offers a couple of decent methods. I'll do a timing comparison to see how they fare compared to yours. Cheers, ÁM "To live or die by your own sword one must first learn to wield it aptly." |
|||
04-18-2024, 07:19 PM
Post: #10
|
|||
|
|||
RE: Valentin Albillo's "Boldly Going... Going Back to the roots" now for the...
The equations at the beginning are actually just cosmetic. They are used only at the end of the program, to check whether the found root's imaginary part is small enough to be ignored, so that the root is displayed as real. You could ignore this part altogether, just display the root when existing the main loop...
|
|||
04-18-2024, 07:30 PM
Post: #11
|
|||
|
|||
RE: Valentin Albillo's "Boldly Going... Going Back to the roots" now for the...
(04-17-2024 10:32 AM)Vincent Weber Wrote: I made a 15C version. While the 15C is a ground-breaking machine with MCODE complex stack routines, it does not do much better: 1min 20 seconds. Maybe because its processor is slower than the 41's by half. Have you compared it to my program in (15C) Halley's Method? Don't forget to remove the PSE-command in line 058. It would be interesting to see your program. |
|||
04-18-2024, 07:44 PM
Post: #12
|
|||
|
|||
RE: Valentin Albillo's "Boldly Going... Going Back to the roots" now for the...
(04-18-2024 07:30 PM)Thomas Klemm Wrote:I will try your program.(04-17-2024 10:32 AM)Vincent Weber Wrote: I made a 15C version. While the 15C is a ground-breaking machine with MCODE complex stack routines, it does not do much better: 1min 20 seconds. Maybe because its processor is slower than the 41's by half. I wrote mine on the go15c precise emulator for Android. It does not allow to export memory, so it is difficult to type it again here. But basically I did the following: -Start with Valentin's 35S program; -Replace lettered registers with numbered ones (e.g X became 4 for the real part and .4 for the imaginary part) -Everywhere you have a STO, replace it with something like: STO 6, Re<>Im, STO .6, Re<>Im -Everywhere you have a RCL, replace it with: RCL .6, Re<>Im, CLX, RCL 6 -Replace the equations at the beginning with RPN code. -Ignore recall arithmetics altogher: RCL* becomes RCL, then * -Ignore the cosmetic ending about considering the a root is real if its imaginary part is very small. Pointless with the 15C display capabilities. Of course this is not optimized compared to a native 15C program! Cheers |
|||
04-18-2024, 08:15 PM
Post: #13
|
|||
|
|||
RE: Valentin Albillo's "Boldly Going... Going Back to the roots" now for the...
(04-18-2024 07:44 PM)Vincent Weber Wrote: I wrote mine on the go15c precise emulator for Android. If you don't mind using this simulator you can just copy and paste the following programs A - E: Code: 001 { 42 21 11 } f LBL A According to its help it "yields performance about 3x the original". Program B took about 18s which means a bit less than 1 minute on the original hardware. |
|||
04-18-2024, 08:34 PM
Post: #14
|
|||
|
|||
RE: Valentin Albillo's "Boldly Going... Going Back to the roots" now for the...
This is a simulator, not an emulator.
You just can't do performances comparisons with the original, it's like comparing apples to oranges. Besides, I usually don't trust simulators, especially when dealing with advanced math features as in the 15C, as I have no ideas of how they were coded. Exceptions include free42/plus42 (outstanding compatibility) and Willy's simulators on ios (high quality). |
|||
04-19-2024, 01:27 AM
Post: #15
|
|||
|
|||
RE: Valentin Albillo's "Boldly Going... Going Back to the roots" now for the...
(04-18-2024 08:15 PM)Thomas Klemm Wrote: If you don't mind using this simulator you can just copy and paste … Nice features, thanks! However, if the steps 014 and 015 below are exchanged the program won’t work as expected. No problem on my HP-15C. Code:
|
|||
04-19-2024, 05:24 AM
Post: #16
|
|||
|
|||
RE: Valentin Albillo's "Boldly Going... Going Back to the roots" now for the...
(04-18-2024 08:34 PM)Vincent Weber Wrote: Besides, I usually don't trust simulators, especially when dealing with advanced math features as in the 15C, as I have no ideas of how they were coded. The code is here on GitHub: jrpn |
|||
04-19-2024, 05:43 AM
Post: #17
|
|||
|
|||
RE: Valentin Albillo's "Boldly Going... Going Back to the roots" now for the...
(04-19-2024 01:27 AM)Gerson W. Barbosa Wrote: However, if the steps 014 and 015 below are exchanged the program won’t work as expected. No problem on my HP-15C. The problem is also present in the GUI: EEX CHS 1 vs. EEX 1 CHS In both cases this should lead to 0.1. The CHS in the first example is ignored. Using Help → Submit Issue (Web) allows to report it. Or you can send Bill a message. |
|||
04-20-2024, 08:08 AM
(This post was last modified: 04-20-2024 08:37 AM by Ángel Martin.)
Post: #18
|
|||
|
|||
RE: Valentin Albillo's "Boldly Going... Going Back to the roots" now for the...
I'm back with some time records.
ZHALL (using Hall's method, one guess) takes about 1'15" on V41 in default speed, or about 3 seconds in TURBO mode. The root found is 1,854105967+J0, for which the function yields -0,000000006+J0 Without a comparison with your program one could argue all we're measuring here is the PC speed, so I prepared the attached RAW file with your code and tried it on V41. Unfortunately the execution never stops, I must be misinterpreting the user instructions? You indicate the program uses {R01, R26} for X but in the LBL EQ1 code it appears R24 is used instead? On the other hand, ZSOLVE (using Newton's method, two guesses) gets into OUT OF RANGE trouble with the example f(z)=z^z - pi, I should look into it next. Cheers, ÁM "To live or die by your own sword one must first learn to wield it aptly." |
|||
04-20-2024, 08:36 AM
Post: #19
|
|||
|
|||
RE: Valentin Albillo's "Boldly Going... Going Back to the roots" now for the...
Angel, can you give me your email? I only have a dead one I think...
|
|||
04-20-2024, 10:34 AM
Post: #20
|
|||
|
|||
RE: Valentin Albillo's "Boldly Going... Going Back to the roots" now for the...
Vincent, I figured out the issue - I wasn't using JMB's routines, oops..
So now I can report the times running RZVA on my system's V41 (face value, not using your HEPAX trick = thus heavily loaded by all the RAM global labels searches) Normal speed: about 4'30" (pretty similar to your reported times) TURBO mode: 5.5 seconds ÁM "To live or die by your own sword one must first learn to wield it aptly." |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 8 Guest(s)