The Museum of HP Calculators

HP Forum Archive 20

 Triangle solver for WP34sMessage #1 Posted by fhub on 28 Aug 2011, 10:50 a.m. Here's my next program for the WP34s: a complete triangle solver. :-) Have fun, Franz PS. I've also uploaded my prime-factorization program because someone asked for something like this in an other thread: Edited: 28 Aug 2011, 10:50 a.m.

 Re: Triangle solver for WP34sMessage #2 Posted by Marcus von Cube, Germany on 28 Aug 2011, 11:16 a.m.,in response to message #1 by fhub Thanks Franz! I've had a short look at PF and I assume there is a bug or at least something I do not really understand. Here is the code for discussion: ```/* Prim-Faktor-Zerlegung (Prime Factorization) Input: X:n (positive integer) Output: X:pf1 [R/S] pf2 [R/S] ... [R/S] 0 (L:n) Used: XYZT, IK */ 001 LBL'PF' 002 INT? 003 x<1? 004 RTN 005 STO K 006 2 007 RCL Y 008 [sqrt] 009 IP 010 STO I 011 DROP 012 x>? I 013 SKIP 11 014 [cmplx]ENTER 015 RMDR 016 x=0? 017 SKIP 03 018 DROP 019 NEXTP 020 BACK 08 021 DROP 022 STOP 023 STO/ Y 024 BACK 17 025 DROP 026 STOP 027 CLSTK 028 x[<->] K 029 [times] 030 RTN ``` Line 13 (SKIP 11) seems to skip to line 24 (BACK 17). Maybe I haven't fully understood the algorithm but this looks a bit strange. --- Edit: I'm not good at counting. :-( SKIP takes the number of steps to skip. I was stopping on the 11th step. Skipping more then a few steps may save labels but does not improve readability of the program. Have you considered using the preprocessor features (symbolic labels)? --- I haven't yet looked at the triangle solver. Edited: 28 Aug 2011, 11:28 a.m. after one or more responses were posted

 Re: Triangle solver for WP34sMessage #3 Posted by fhub on 28 Aug 2011, 11:21 a.m.,in response to message #2 by Marcus von Cube, Germany Quote: Line 13 (SKIP 11) seems to skip to line 24 (BACK 17). Maybe I haven't fully understood the algorithm but this looks a bit strange. Count again, Marcus! ;-) In fact it jumps to line 25 ... Edited: 28 Aug 2011, 11:24 a.m.

 Re: Triangle solver for WP34sMessage #4 Posted by Marcus von Cube, Germany on 28 Aug 2011, 11:29 a.m.,in response to message #3 by fhub Shame on me. (See above).

 Re: Triangle solver for WP34sMessage #5 Posted by Lode on 28 Aug 2011, 11:24 a.m.,in response to message #2 by Marcus von Cube, Germany I'm new to the WP34s myself, and never worked with a 41C on which this one is based, but, wouldn't SKIP 11 skip the next 11 lines, and thus end up at 025 DROP?

 Re: Triangle solver for WP34sMessage #6 Posted by fhub on 28 Aug 2011, 11:30 a.m.,in response to message #5 by Lode Quote: I'm new to the WP34s myself, and never worked with a 41C on which this one is based, but, wouldn't SKIP 11 skip the next 11 lines, and thus end up at 025 DROP? Yes, you're right of course. I also don't like the concept of SKIP very much: BACK nn jumps back nn steps, but SKIP nn jumps forward nn+1 steps (skipping nn steps). It's always a bit confusing when writing a program, and I would definitely have prefered a combination BACK/FWD instead of BACK/SKIP.

 Re: Triangle solver for WP34sMessage #7 Posted by Dieter on 28 Aug 2011, 11:46 a.m.,in response to message #6 by fhub This could be overcome by a general relative jump command, similar to those in the '67/97 or 34C (yet only backwards). While BACK nn in fact works like a "jump back nn lines", just as in the mentioned earlier models, SKIP nn in fact means "jump forward nn+1 lines". A relative jump could handle both cases it (and only if) it could handle both positive and negative arguments. This has been discussed earlier regarding the current SDL and SDR commands which also would become much more useful if they were replaced by one common command which was able to handle positive and negative arguments. Pauli explained why this is currently not implemented, but maybe the benefits of a common relative jump command may help finding a solution. ;-) If this is not possible SKIP could be replaced by another command that simply does the same as SKIP nn+1, which might be slightly less confusing. But I could also live without that. ;-) Dieter

 Re: Triangle solver for WP34sMessage #8 Posted by fhub on 28 Aug 2011, 11:52 a.m.,in response to message #7 by Dieter Quote: If this is not possible SKIP could be replaced by another command that simply does the same as SKIP nn+1, which might be slightly less confusing. Yes, that's exactly what I meant with FWD nn (instead of SKIP), jumping nn steps forward (as BACK nn does backward).

 Re: Triangle solver for WP34sMessage #9 Posted by Paul Dale on 28 Aug 2011, 5:41 p.m.,in response to message #6 by fhub Why all the problems with SKIP and BACK? SKIP nn skips the next nn steps. BACK nn goes back nn steps. If we called the SKIP command FWD or FORWARD then it would operate differently but it isn't. It is called SKIP. These commands have a bit of a sordid history. Originally included for internal xrom programming only but they turned out to be a useful way to reduce the step count so they were pushed mainstream. Now that we've lots of program steps in flash they are less relevant but still useful enough to include I think. Finally, if you don't like them just use GTO/LBL instead. Nobody is forcing anyone to use these. They make debugging and altering programs more difficult, they take more keystrokes to enter and they don't necessarily have a speed advantage over LBL. - Pauli

 Re: Triangle solver for WP34sMessage #10 Posted by fhub on 28 Aug 2011, 5:59 p.m.,in response to message #9 by Paul Dale Quote: Finally, if you don't like them just use GTO/LBL instead. 1) I didn't talk to or with _you_ 2) I didn't criticize anything but just expressed my opinion 3) I guess (and hope) that saying one's opinion is still allowed here, isn't it? Franz

 Re: Triangle solver for WP34sMessage #11 Posted by Paul Dale on 28 Aug 2011, 6:20 p.m.,in response to message #10 by fhub Grow up. None of what I said was directed at you, it was a public response in a public forum. - Pauli

 Re: Triangle solver for WP34sMessage #12 Posted by Dieter on 28 Aug 2011, 11:32 a.m.,in response to message #2 by Marcus von Cube, Germany Quote: Line 13 (SKIP 11) seems to skip to line 24 (BACK 17). Maybe I haven't fully understood the algorithm but this looks a bit strange. SKIP 11 means that the next 11 lines are skipped and the program continues with the 12th, i.e. line 13 + 12 = 25. ;-) Dieter

 Re: Triangle solver for WP34sMessage #13 Posted by fhub on 28 Aug 2011, 11:43 a.m.,in response to message #2 by Marcus von Cube, Germany Quote: Skipping more then a few steps may save labels but does not improve readability of the program. Have you considered using the preprocessor features (symbolic labels)? Well, the preprocessor doesn't run here with my old TinyPerl, and I definitely don't want to install a 80MB package for just one little Perl script! (BTW, since you've removed RCLS/STOS A again, also Neil's assembler isn't uptodate anymore - it gives an error message for these 2 commands.) And for 'readability': my triangle program you couldn't even 'read' (i.e. understand) WITH symbolic labels. ;-) Edited: 28 Aug 2011, 11:44 a.m.

 Re: Triangle solver for WP34sMessage #14 Posted by Marcus von Cube, Germany on 28 Aug 2011, 12:07 p.m.,in response to message #13 by fhub Franz, try the .exe version. It does not need Perl to be installed.

 Re: Triangle solver for WP34sMessage #15 Posted by fhub on 28 Aug 2011, 12:11 p.m.,in response to message #14 by Marcus von Cube, Germany Quote: Franz, try the .exe version. It does not need Perl to be installed. I've tried it already: 1) horribly slow 2) creates BIG temporary files in Windows\temp folder and doesn't delete it at the end, so either I have to remove them manually or this folder grows with each run Conclusion: thanks, that's not a tool I would like! ;-)

 Re: Triangle solver for WP34sMessage #16 Posted by Marcus von Cube, Germany on 28 Aug 2011, 12:13 p.m.,in response to message #15 by fhub Quote: I've tried it already: 1) horribly slow Only on the first run. Quote: 2) creates BIG temporary files in Windows\temp folder and doesn't delete it at the end, so either I have to remove them manually or this folder grows with each run That's why it is slow on the first run but not on subsequent executions. Temp should get cleared on a reboot by Windows.

 Re: Triangle solver for WP34sMessage #17 Posted by Neil Hamilton (Ottawa) on 28 Aug 2011, 3:17 p.m.,in response to message #13 by fhub Quote: (BTW, since you've removed RCLS/STOS A again, also Neil's assembler isn't uptodate anymore - it gives an error message for these 2 commands.) I presume you are not using SVN then. I am suspecting that you may be manually downloading the assembler script from the Source Forge website. If so, then you are likely not also copying the wp34s.op table that is there as well (same directory). While the embedded table within the assembler is not updated on every twitch and whim of the rest of the project, the ./trunk/tools/wp34s.op table is essentially (semi)automatically updated during the build process. The assembler searches for the wp34s.op op-code table in the following order: 1) where you said it was using the -op command line switch, 2) the directory you are running the script from, 3) where the script itself is located, and finally, if none of the previous are true, 4) the assembler uses its internal table as a last resort fall-back. When you run the assembler, it will report which table it used -- both its revision number (if known), and its location (something about "internal" if it could find one). It is possible that the assembler reports 2 warnings (not errors!) about duplicate op-codes with regard to STOS A/RCLS A. Regardless, the 2 warnings it reports are harmless and can be ignored -- unless you happen to be trying to use STOS A and/or RCLS A. Depending on which revision of the calculator design you are using, the STOS A and RCLS A instructions may or may not exist. With respect to the EXE versions, they were fully documented to behave as you state (slow -- on the 1st decompression run, and large -- being about 15M footprint). Additionally, the reasons for this were also documented. So no surprises there. None the less, the ability to use "JMP DoThatThingAgain" instead of SKIP 78 or BACK 23 is a large benefit to self-documented, readable code (it will do a better job counting steps than the human as well!). The tool figures out these n+1 issues for SKIP and deals with them accordingly. Furthermore, if the JMP exceeds the dynamic range of the the SKIP/BACK instruction, the PP tool automatically promotes the branch instruction into a GTO instruction (inserting a LBL at the correct spot, only if required).

 Re: Triangle solver for WP34sMessage #18 Posted by fhub on 28 Aug 2011, 3:58 p.m.,in response to message #17 by Neil Hamilton (Ottawa) Quote: I presume you are not using SVN then. I am suspecting that you may be manually downloading the assembler script from the Source Forge website. If so, then you are likely not also copying the wp34s.op table that is there as well (same directory). Well, I'm indeed manually downloading both your assembler script AND the wp34s.op whenever one of them changes. And I know that at the moment (SVN1535) it's working again - but I'm sure not for long time: at least when Pauli awakes again those assembler warnings will reappear ... ;-)

 Re: Triangle solver for WP34sMessage #19 Posted by Neil Hamilton (Ottawa) on 28 Aug 2011, 4:22 p.m.,in response to message #18 by fhub Quote: I know that at the moment (SVN1535) it's working again I would be somewhat surprised if the assembler stopped working. It was (is?) issuing the warning messages about duplicate op-codes because of an internal matter within the design team. But, as far as I am aware, it never produced illegal code or failed to assembler a source file** (at least in the last month or so). If you have a set of files that it is failing against, can you please share the details? When the internal matter regarding STOS A/RCLS A is finalized, the assembler will be updated. Until then, you can safely ignore the warnings. ** Unless you were using the STOS A/RCLS A instruction -- and then it depended on which specific version of the calculator you were using -- and then it simply said you were using an illegal instruction (being STOS A and/or RCLS A).

 Re: Triangle solver for WP34sMessage #20 Posted by fhub on 28 Aug 2011, 4:29 p.m.,in response to message #19 by Neil Hamilton (Ottawa) Quote: If you have a set of files that it is failing against, can you please share the details? So far I didn't have any problems with your assembler - it works perfectly. And of course these STOS/RCLS warnings aren't your fault. Quote: When the internal matter regarding STOS A/RCLS A is finalized, ... Well, this will be a never ending story I'm afraid. ;-)

 Re: Triangle solver for WP34sMessage #21 Posted by Neil Hamilton (Ottawa) on 28 Aug 2011, 5:10 p.m.,in response to message #20 by fhub Quote: And of course these STOS/RCLS warnings aren't your fault I prefer to think of these things as nobody's fault. They are part of an evolving architecture that has some pretty healthy debate happening behind the scenes. (My tool has its share of issues as well. I am just luckier that they have mostly been caught in that behind the scene evolution. Pauli found a bit of a howler in the PP last week. It would not allow 1/x through unmolested -- to keep the theme going -- under certain circumstances.) Quote: Well, this will be a never ending story I'm afraid. ;-) I, and more than a few others, hope not! However, this one will be resolved quite soon -- of that I am confident.

 Re: Triangle solver for WP34sMessage #22 Posted by Patrice on 28 Aug 2011, 3:21 p.m.,in response to message #2 by Marcus von Cube, Germany Hi all, My apologies if already discussed. I understand that labels are just a waste of place and time in a program (at least when it is fully debugged and frozen). But when you edit a program, labels are helpful because you don't have to keep track of the lines inserted or removed to know how far you have to jump. When you remove a label, if not on purpose, you can bet that a GTO or an WEQ will fail soon or late. If the label is not there, you have chances not notice. It is just my opinion, but you can have guessed that I don't like the SKIP and BACK commands with relative jumps, because you have to do maths when the calc can display the useful result directly. In the contest of removing the labels, I would have preferred a JUMP command with an absolute line number (with same range as BACK and SKIP). (or GTOL for a GTO Line programmable) Even better, having 2 more commands: the first one SHRINK, non programmable, would convert the current program with labels to the form without labels (at least the numerical ones from the HP41C point of view). The second one EXPAND, non programmable, doing the reverse, aka reinserting the labels. The EXPANDed form would be (need to renumber the lines): ```001 LBL'PF' 002 INT? 003 x<1? 004 RTN 005 STO K 006 2 LBL 03 007 RCL Y 008 [sqrt] 009 IP 010 STO I 011 DROP LBL 02 012 x>? I 013 GTO 00 014 [cmplx]ENTER 015 RMDR 016 x=0? 017 GTO 01 018 DROP 019 NEXTP 020 GTO 02 LBL 01 021 DROP 022 STOP 023 STO/ Y 024 GTO 03 025 DROP LBL 00 026 STOP 027 CLSTK 028 x[<->] K 029 [times] 030 RTN ``` The SHRINKed form: ```001 LBL'PF' 002 INT? 003 x<1? 004 RTN 005 STO K 006 2 007 RCL Y 008 [sqrt] 009 IP 010 STO I 011 DROP 012 x>? I 013 GTOL 25 014 [cmplx]ENTER 015 RMDR 016 x=0? 017 GTOL 21 018 DROP 019 NEXTP 020 GTOL 12 021 DROP 022 STOP 023 STO/ Y 024 GTOL 7 025 DROP 026 STOP 027 CLSTK 028 x[<->] K 029 [times] 030 RTN ``` Patrice

 Re: Triangle solver for WP34sMessage #23 Posted by Neil Hamilton (Ottawa) on 28 Aug 2011, 3:38 p.m.,in response to message #22 by Patrice Hi Patrice, Have you looked at the off-line preprocessor for the assembler? If not, have a look at chapter 8 of the assembler document.

 Re: Triangle solver for WP34sMessage #24 Posted by Patrice on 28 Aug 2011, 3:54 p.m.,in response to message #23 by Neil Hamilton (Ottawa) Is it an assembler program ? In this case, apologize, I thought it is a 'FOCAL' user program. Patrice

 Re: Triangle solver for WP34sMessage #25 Posted by Marcus von Cube, Germany on 28 Aug 2011, 4:14 p.m.,in response to message #24 by Patrice "Assembler" here is the same what "Focal" is for the 41C. It was Neil's decision to call his perl script neither translator nor compiler but assembler. The "assembly language" is just the keystroke programming model of WP 34S.

 Re: Triangle solver for WP34sMessage #26 Posted by Patrice on 28 Aug 2011, 5:30 p.m.,in response to message #25 by Marcus von Cube, Germany In my 30 years of computer programming experience, I have always heard of "assembler" or "assembly language" as being a more or less readable form of the language of the microprocessor. Using the word "assembler" for the user keystroke programming language is quite unusual for me. Patrice

 Re: Triangle solver for WP34sMessage #27 Posted by Neil Hamilton (Ottawa) on 28 Aug 2011, 4:40 p.m.,in response to message #24 by Patrice Quote: Is it an assembler program ? In this case, apologize, I thought it is a 'FOCAL' user program. Sorry, I have only heard of FOCAL used in the context of the '41. I did not understand your comment until Marcus' note. The assembler will do several things. Firstly, it will disassemble a binary image extracted from the user programmable spaces (ie: key-stroke programmable area) in either the calculator or the emulator. Secondly, it will take an ASCII source (either a previously disassembled one or one you have written using an editor) and create a binary image that can be loaded into the key-stroke programmable sections of either the calculator or the emulator. Recently there was a new addition to the tool chain, that I am calling a preprocessor (or PP), that does some symbolic manipulation of the source. The output of the PP can be fed into the assembler. (The assembler can also be requested to spawn a PP job directly via a command line switch as well.) Your comment about superfluous labels, JUMP instructions, counting, etc. is essentially exactly what the PP does. Again, if you have not had a chance, read the WP34s_Assembler_Disassembler.pdf document in the WP 34S offering. It should answer many questions. Chapter 8 deals specifically with this topic. Regards...

 Re: Triangle solver for WP34sMessage #28 Posted by Patrice on 28 Aug 2011, 6:03 p.m.,in response to message #27 by Neil Hamilton (Ottawa) Quote: Sorry, I have only heard of FOCAL used in the context of the '41. Me too, this is why I writed 'FOCAL', would you have preferred "User Keystroke Programming Language" ? My SHRINK and EXPAND commands were for the real thing, to help programming live. Try to program and debug something without the help of a computer or a sheet of paper and you will see my point about the labels. Quote: WP34s_Assembler_Disassembler.pdf document in the WP 34S offering. It should answer many questions. Chapter 8 deals specifically with this topic. Chapter 8 is named "Help" is it the right one ?

 Re: Triangle solver for WP34sMessage #29 Posted by Neil Hamilton (Ottawa) on 28 Aug 2011, 6:32 p.m.,in response to message #28 by Patrice Quote: Chapter 8 is named "Help" is it the right one ? It is named "Help" in older versions. In the latest it is called "Symbolic Preprocessor". The latest version went online about 2 weeks ago. Look here. I can't help you with the "live" programs. That is not my department. :-)

 Re: Triangle solver for WP34sMessage #30 Posted by fhub on 28 Aug 2011, 3:54 p.m.,in response to message #22 by Patrice Quote: The EXPANDed form would be (need to renumber the lines): ... Hey, what are you doing with my poor little program? That's almost rape ... ;-)

 Re: Triangle solver for WP34sMessage #31 Posted by Patrice on 28 Aug 2011, 3:59 p.m.,in response to message #30 by fhub Yes, I am a serial program raper :)

 Re: Triangle solver for WP34sMessage #32 Posted by fhub on 28 Aug 2011, 4:01 p.m.,in response to message #31 by Patrice Quote: Yes, I am a serial program raper :) Well, better serial than parallel (at least in this case). :-)

 Re: Triangle solver for WP34sMessage #33 Posted by Patrice on 28 Aug 2011, 4:55 p.m.,in response to message #32 by fhub Sometimes, parallel is good too. By the way, do you think the program is read easier with absolute line numbers? Patrice

 Re: Triangle solver for WP34sMessage #34 Posted by fhub on 28 Aug 2011, 5:03 p.m.,in response to message #33 by Patrice Quote: By the way, do you think the program is read easier with absolute line numbers? You mean direct jumps to line numbers? Yes, that would of course be (a bit) easier than all this counting for BACK or SKIP.

 Re: Triangle solver for WP34sMessage #35 Posted by Lode on 28 Aug 2011, 11:21 a.m.,in response to message #1 by fhub I like the PF program, thanks! I like it especially as a learning experience of the WP34s commands.

 Re: Triangle solver for WP34sMessage #36 Posted by Miguel Toro on 29 Aug 2011, 6:08 p.m.,in response to message #1 by fhub Hi, Here is maybe a dumb question: how do you create an instruction like: 048 [alpha]'on:' in your triangle program? I cannot see how I can add a special character like ':' and in this instruction. Thanks, Miguel Edited: 29 Aug 2011, 6:12 p.m.

 Re: Triangle solver for WP34sMessage #37 Posted by fhub on 29 Aug 2011, 6:22 p.m.,in response to message #36 by Miguel Toro Sorry Miguel, but unfortunately I can't answer your question. I'm not entering my programs directly on the emulator, I just write my programs in a texteditor, compile them and load them into the emulator. Franz

 Re: Triangle solver for WP34sMessage #38 Posted by Paul Dale on 29 Aug 2011, 6:29 p.m.,in response to message #36 by Miguel Toro See page 9 of the manual for the alpha to keyboard map. Due to some internal limitations, the various alpha catalogues are not available during the three character alpha entry sequences. This means that you will have to enter the ':' character as a single character alpha. The assembler accepts more than can be entered from the keyboard and the execution engine doesn't care. This applies not only to alpha triples but to labels as well. - Pauli

 Re: Triangle solver for WP34sMessage #39 Posted by Miguel Toro on 29 Aug 2011, 7:26 p.m.,in response to message #38 by Paul Dale Ah, Domage! I thought as much, having read the "interactive.html" document. Thanks you both and regards, Miguel

Go back to the main exhibit hall