HP-41 and 42s: AIP with or without sign?
|
06-06-2018, 05:48 PM
Post: #1
|
|||
|
|||
HP-41 and 42s: AIP with or without sign?
The HP-41's Advantage Pac as well as the 42s feature the AIP command (append integer part to Alpha) which appends the integer portion of X to Alpha. That's a nice and really useful command, but I noticed a difference between both implementations:
It looks like the 41's AIP strips the sign of X while the 42s function does not. In other words: with –31,4 in X the '41 appends "31" while the 42s adds "–31" to Alpha. That's at least how V41 and Free42 behave. Since V41 uses the original ROM code I assume this is the way the AIP command in a "real" Advantage Pac behaves. But what about the 42s? Does AIP preserve the sign or not? And if both implementations are different, what could be the reason? Maybe it was the simple insight that keeping the sign generally is a good idea. ;-) BTW, Ángel's Sandmath ROM has an AINT command which preserves the sign of X, and so does ARCLI in the CCD ROM. The Sandmath manual mentions the Advantage Pac's AIP counterpart, but there is no remark regarding this difference between the two. Dieter |
|||
06-06-2018, 06:29 PM
Post: #2
|
|||
|
|||
RE: HP-41 and 42s: AIP with or without sign? | |||
06-06-2018, 06:47 PM
Post: #3
|
|||
|
|||
RE: HP-41 and 42s: AIP with or without sign?
From the Advantage manual :
Quote:AIP: Appends the integer part of the number in the X-register to the contents of the Alpha register. For x<0, AIP appends the absolute value. From the 42s manual : Quote:The AIP function appends the integer part of the number in the X-register to the current contents of the Alpha register. |
|||
06-06-2018, 08:00 PM
Post: #4
|
|||
|
|||
RE: HP-41 and 42s: AIP with or without sign?
Well, at least if they have to be different, making it 'better' or more accurate, is a good reason.
No doubt there were complaints about the Advantage implementation (which was documented correctly, so 1 point for that); if someone wanted to preserve the sign it's a pain to check absolute value and prepend the "-" sign while preserving the stack values prior to AIP, while on the 42S a simple ABS would remove it. --Bob Prosperi |
|||
06-06-2018, 08:22 PM
Post: #5
|
|||
|
|||
RE: HP-41 and 42s: AIP with or without sign?
(06-06-2018 08:00 PM)rprosperi Wrote: if someone wanted to preserve the sign it's a pain to check absolute value and prepend the "-" sign while preserving the stack values prior to AIP, while on the 42S a simple ABS would remove it. Well, it's not that much of a pain even with the Advantage Pac's AIP: X<0? >"–" AIP Doing it the HP-41 way on a 42s while preserving the stack (but not LastX) would require something like this: ABS AIP X<> ST L But anyway, I prefer the 42s implementation. And I wonder if this difference ever has been mentioned somewhere as a possible problem when transferring HP41-code to the 42s. Dieter |
|||
06-06-2018, 08:34 PM
Post: #6
|
|||
|
|||
RE: HP-41 and 42s: AIP with or without sign?
Or if you wish a + in front:
"+" x<0? "-" AIP for example. |
|||
06-06-2018, 08:40 PM
Post: #7
|
|||
|
|||
RE: HP-41 and 42s: AIP with or without sign?
(06-06-2018 08:34 PM)Gene Wrote: Or if you wish a + in front: I assume that in most cases the number is appended to existing text in Alpha, so a nicely formatted output for positive, negative and zero values would have to look like this: X=0? >" " X<0? >"–" X>0? >"+" AIP Note: ">" here is the "append" character. Dieter |
|||
06-06-2018, 09:02 PM
Post: #8
|
|||
|
|||
RE: HP-41 and 42s: AIP with or without sign?
Agreed, or no > append if you want the display to simply start with space, + or -.
|
|||
06-06-2018, 10:42 PM
Post: #9
|
|||
|
|||
RE: HP-41 and 42s: AIP with or without sign?
(06-06-2018 08:40 PM)Dieter Wrote: I assume that in most cases the number is appended to existing text in Alpha, so a nicely formatted output for positive, negative and zero values would have to look like this: Dieter/Gene: You're right, it's simpler and cleaner than I thought! But I agree the 42S behavior is IMHO correct, what I would expect, and no doubt a result of the 42S team agreeing with all of us. --Bob Prosperi |
|||
06-07-2018, 04:43 AM
Post: #10
|
|||
|
|||
RE: HP-41 and 42s: AIP with or without sign?
Just to confirm that ARCLI and AINT do respect the sign. That was intentional; by definition it's the INTEGER number what is appended to ALPHA - not the NATURAL number...
AIP in the Advantage and SandMatrix do not include the sign. This makes more sense if all it's being used for is a matrix element index of course... "To live or die by your own sword one must first learn to wield it aptly." |
|||
06-07-2018, 05:50 AM
Post: #11
|
|||
|
|||
RE: HP-41 and 42s: AIP with or without sign?
(06-07-2018 04:43 AM)Ángel Martin Wrote: Just to confirm that ARCLI and AINT do respect the sign. That was intentional; by definition it's the INTEGER number what is appended to ALPHA - not the NATURAL number... As you perfectly state, in AIP the "I" stands for "Integer" so not including the sign is kind of stupid and shortsighted, even supposing it was meant for indexes. But after seeing some of the extremely stupid things HP did with the HP71B mainframe and its Math ROM, this doesn't surprise me anymore. Assuming it doesn't break anything I'd suggest you correct AIP in the SandMatrix to include the sign, as it should and as expected. Regards. V. . All My Articles & other Materials here: Valentin Albillo's HP Collection |
|||
06-07-2018, 02:32 PM
(This post was last modified: 06-07-2018 02:54 PM by Ángel Martin.)
Post: #12
|
|||
|
|||
RE: HP-41 and 42s: AIP with or without sign?
(06-07-2018 05:50 AM)Valentin Albillo Wrote: Assuming it doesn't break anything I'd suggest you correct AIP in the SandMatrix to include the sign, as it should and as expected. A real walk in the park, stay tuned. BTW something *not* so simple that may arise your fancy:- as you know the Matrix function set in the Advantage can be used to work with Complex matrices, using the well-known method of "Partitioned Matrices", already described in the 15C manuals. In fact the module comes with a CMEDIT driver program that can be used to calculate matrix inverses, and to solve systems of complex equations... however it doesn't calculate the determinants. So here's the task: Write a routine to calculate the determinant of a Complex matrix, using the Matrix functions in the module. Anybody going for it? Is there any example in the Advanced HP-15C Manual perhaps? "To live or die by your own sword one must first learn to wield it aptly." |
|||
06-07-2018, 10:25 PM
Post: #13
|
|||
|
|||
RE: HP-41 and 42s: AIP with or without sign?
.
Hi, Ángel: (06-07-2018 02:32 PM)Ángel Martin Wrote: A real walk in the park, stay tuned. Ok. It must be nice to be able to create and edit microcode routines for the 41, which includes having all the relevant source listings and docs, plus the necessary hardware of course. We had none of it in the early times after the 41C was released by HP and most of us would have given an arm and a leg for those materials back then. Quote:BTW something *not* so simple that may arise your fancy: [...] however it doesn't calculate the determinants. So here's the task: Write a routine to calculate the determinant of a Complex matrix, using the Matrix functions in the module. Not me. Regrettably I have a sizable "To Do" list re HP things, several pages long, and I can't allocate in it the task you suggest with any decent priority, there are too many other tasks which I consider more urgent right now. Sorry. Quote:Is there any example in the Advanced HP-15C Manual perhaps? I don't remember, will look at it after I post this. However, I found this, which might be quite relevant and possibly can be adapted to run using the 41C Advantage ROM: Computing complex determinant in the HP-15C Hope that helps. Regards. V. . All My Articles & other Materials here: Valentin Albillo's HP Collection |
|||
06-08-2018, 01:17 PM
(This post was last modified: 06-08-2018 01:22 PM by Ángel Martin.)
Post: #14
|
|||
|
|||
RE: HP-41 and 42s: AIP with or without sign?
Thanks for the pointers Valentín, I've cheeked the references for leverage but before I found a solid baseline I figured out a better way to do it on my own... (actually it was mentioned in-passing in the articles, albeit it wasn't used in the solutions).
Right now I have a 50-step short FOCAL program that calculates determinants of 2x2 and a 3x3 Complex Matrices. Working on the 4x4 case as we speak... The program uses the 41Z as well, so the "Math Trinity" working in unison for the task. It uses the expressions based on the matrix Trace and integer powers; granted it's a round-about way to skin this cat bu the code efficiency and speed are unbeatable. Unfortunately there's no expression for the general "n" case, I wonder if such a formula would exist at all or if it's just a pipe dream. https://en.wikipedia.org/wiki/Determinant Saludos, Á. "To live or die by your own sword one must first learn to wield it aptly." |
|||
06-08-2018, 03:23 PM
Post: #15
|
|||
|
|||
RE: HP-41 and 42s: AIP with or without sign?
(06-08-2018 01:17 PM)Ángel Martin Wrote: Right now I have a 50-step short FOCAL program that calculates determinants of 2x2 and a 3x3 Complex Matrices. Working on the 4x4 case as we speak... The program uses the 41Z as well, so the "Math Trinity" working in unison for the task. All three modules? Now that would be an interesting program to see (and try!) firsthand. Any chance of posting it for study? ~Mark Remember kids, "In a democracy, you get the government you deserve." |
|||
06-08-2018, 05:17 PM
Post: #16
|
|||
|
|||
RE: HP-41 and 42s: AIP with or without sign?
(06-07-2018 02:32 PM)Ángel Martin Wrote:(06-07-2018 05:50 AM)Valentin Albillo Wrote: Assuming it doesn't break anything I'd suggest you correct AIP in the SandMatrix to include the sign, as it should and as expected. Hm. If you really want to change the current Sandmatrix AIP function I think you better rename it (or complement it with a modified function), e.g. AIPS (append integer part with sign). This avoids confusions with the Advantage Pac's AIP which does not preserve the sign. I wonder if it's a good idea to have different functions with the same name in different ROM modules. What happens if both Sandmatrix and the Advantage Pac are installed and the user calls "AIP"? At the moment at least the results are the same (no sign). If now Sandmatrix gets an AIP with sign support while there also is an AIP without, I can imagine quite a few problems... ;-) So I think AIP should stay as it is and a second version which honors the sign should be added. Maybe you call it AIPS, or why not simply copy AINT from Sandmath? Dieter |
|||
06-08-2018, 10:28 PM
(This post was last modified: 06-08-2018 10:29 PM by rprosperi.)
Post: #17
|
|||
|
|||
RE: HP-41 and 42s: AIP with or without sign?
(06-08-2018 05:17 PM)Dieter Wrote: I wonder if it's a good idea to have different functions with the same name in different ROM modules. What happens if both Sandmatrix and the Advantage Pac are installed and the user calls "AIP"? At the moment at least the results are the same (no sign). If now Sandmatrix gets an AIP with sign support while there also is an AIP without, I can imagine quite a few problems... ;-) If the instruction is in an existing program, it is actually stored as XROM xx,yy and it will run the same one as when the program was first created, regardless of ROM port location. If run manually, it will run the function with matching name in the lower-numbered port. (e.g. if Adv. ROM is in port-2 and Sandmatrix in port-3, the Adv. ROM version will be used). --Bob Prosperi |
|||
06-08-2018, 11:45 PM
Post: #18
|
|||
|
|||
RE: HP-41 and 42s: AIP with or without sign?
(06-08-2018 01:17 PM)Ángel Martin Wrote: Right now I have a 50-step short FOCAL program that calculates determinants of 2x2 and a 3x3 Complex Matrices. Working on the 4x4 case as we speak... [...] It uses the expressions based on the matrix Trace and integer powers; granted it's a round-about way to skin this cat bu the code efficiency and speed are unbeatable. Unfortunately there's no expression for the general "n" case, I wonder if such a formula would exist at all or if it's just a pipe dream. Of course it does exist, the very link you include to the Wikipedia article gives the particular cases for 2x2, 3x3 and 4x4 and also the general formula. However, it gets very unwieldy very soon, beginning with 5x5, and so it ceases to be a feasible solution, the coefficients are difficult to obtain and the number of terms in the summation and the matrix powers required increase very quickly. If I were to do it, I'd use the exact formula for 2x2 (2 multiplications and 1 subtraction), recursive expansion by minors for 3x3 (three 2x2 determinants), 4x4 (four 3x3 determinants = twelve 2x2 determinants ) and 5x5 (five 4x4 determinants = sixty 2x2 determinants) matrices, and LU-decomposition for 6x6 and beyond. There's also the case of computing an exact integer determinant for integer matrices. As this is digressing way too far from the original subject of this thread ("HP-41 and 42s: AIP with or without sign?") I suggest you create a new thread to discuss the subject, if interested, and I'll contribute to it. Best regards and have a nice weekend. V. . All My Articles & other Materials here: Valentin Albillo's HP Collection |
|||
06-08-2018, 11:50 PM
Post: #19
|
|||
|
|||
RE: HP-41 and 42s: AIP with or without sign?
(06-08-2018 05:17 PM)Dieter Wrote: I wonder if it's a good idea to have different functions with the same name in different ROM modules. [...] So I think AIP should stay as it is and a second version which honors the sign should be added. Agreed. That's precisely why I said "Assuming it doesn't break anything [...]". Have a nice weekend. V. . All My Articles & other Materials here: Valentin Albillo's HP Collection |
|||
06-09-2018, 04:33 AM
Post: #20
|
|||
|
|||
RE: HP-41 and 42s: AIP with or without sign?
(06-08-2018 11:45 PM)Valentin Albillo Wrote: Of course it does exist, the very link you include to the Wikipedia article gives the particular cases for 2x2, 3x3 and 4x4 and also the general formula. However, it gets very unwieldy very soon, beginning with 5x5, and so it ceases to be a feasible solution, the coefficients are difficult to obtain and the number of terms in the summation and the matrix powers required increase very quickly. My eyes are quickly approaching the mole-status, my bad of course - and I agree that formula isn't practical at all beyond n=4. Also agree this conversation should be transferred to another thread, coming soon... "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: 4 Guest(s)