Post Reply 
HP50g small tips and trick
06-23-2018, 05:02 PM
Post: #41
RE: HP50g small tips and trick
Got it - 'N' STO fixed it.

Also, the list is reversed, sol REVLIST at the end of the code is required.

TC
Find all posts by this user
Quote this message in a reply
06-23-2018, 05:35 PM
Post: #42
RE: HP50g small tips and trick
(06-23-2018 05:02 PM)TomC Wrote:  ...Also, the list is reversed, sol REVLIST at the end of the code is required.

For models that don't have REVLIST, you can also add a SWAP before the "+":

Code:
«
  → N P
  «
    {}
    WHILE
      N
    REPEAT
      N P MOD SWAP +
      N P / FLOOR
      'N' STO
    END
  »
»

On the 49G or later RPL systems, the ListExt library has a single command that also does this: I→BL.
Find all posts by this user
Quote this message in a reply
06-23-2018, 05:43 PM (This post was last modified: 06-23-2018 05:44 PM by pier4r.)
Post: #43
RE: HP50g small tips and trick
(06-23-2018 04:26 PM)rprosperi Wrote:  When you have no idea at all how long a program may run, it's usually best to include a counter to track the number of iterations and when it exceeds some threshold, exit with a diagnostic message, e.g. "Exceeded 10,000 iterations".

Yes that is true. Though I tend to deviate from theory if the task is not critical. (i.e: I am interested in the results but I can wait)

I learned (also through pain) to do sort of canary deployments (principle that is valid mostly everywhere).
Small tests first. Passed? Good.
Then a bit larger. In the meanwhile I collect timings and I see if the predicted runtimes hold varying the input.
Then I let the program crunch large input values.

In my particular case I could predict the next execution time practically with 100% accuracy (and also the number of loops to execute). Only one loop was related to a random pick that in a very remote case could have ended in "sorry no result is there for what you are searching" and then this would have ended in an infinite loop.

I though "well do I make a fail check condition for this? Nah. It won't happen until the input values are really large. By then I will have fixed it". Instead it happened earlier than expected.

Sometimes I have to be remembered of some programming/planning techniques through slightly bitter experiences, to then be motivated to implement them.

Wikis are great, Contribute :)
Find all posts by this user
Quote this message in a reply
06-30-2018, 01:00 PM
Post: #44
RE: HP50g small tips and trick
(06-23-2018 04:50 PM)TomC Wrote:  Not clear to me why this snippet does not work on an HP48.

The 'N near the end causes a syntax error. Is there some subtle difference how the 48 handles recalling the address of a local variable?

I think you just need another single quote around the local variable:

(02-20-2017 09:21 PM)ttw Wrote:  << -> N P <<
{} WHILE N REPEAT
N P MOD +
N P / FLOOR
'N' STO
END >>

HTH
Thomas
Find all posts by this user
Quote this message in a reply
07-04-2018, 02:55 PM
Post: #45
RE: HP50g small tips and trick
Given two integers, the command IDIV2 returns the quotient and the reminder.
Find all posts by this user
Quote this message in a reply
07-04-2018, 04:52 PM
Post: #46
RE: HP50g small tips and trick
(07-04-2018 02:55 PM)Juan14 Wrote:  Given two integers, the command IDIV2 returns the quotient and the reminder.

Astoundingly, IQUOT internally performs IDIV2 DROP, and IREMAINDER internally performs IDIV2 NIP. So getting both the quotient and remainder is actually faster than getting only one or the other.

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
07-04-2018, 05:39 PM
Post: #47
RE: HP50g small tips and trick
(07-04-2018 04:52 PM)Joe Horn Wrote:  
(07-04-2018 02:55 PM)Juan14 Wrote:  Given two integers, the command IDIV2 returns the quotient and the reminder.

Astoundingly, IQUOT internally performs IDIV2 DROP, and IREMAINDER internally performs IDIV2 NIP. So getting both the quotient and remainder is actually faster than getting only one or the other.

Just make sure you don't have system flag -100 set (Step-by-step) before using IDIV2. I was once trying to help someone with a problem and it took a while to figure that one out. Smile
Find all posts by this user
Quote this message in a reply
07-04-2018, 05:56 PM
Post: #48
RE: HP50g small tips and trick
(07-04-2018 04:52 PM)Joe Horn Wrote:  Astoundingly, IQUOT internally performs IDIV2 DROP, and IREMAINDER internally performs IDIV2 NIP. So getting both the quotient and remainder is actually faster than getting only one or the other.

Not very fast though. IDIV2 would be much more useful if it wasn't so slow. Sad
Find all posts by this user
Quote this message in a reply
08-08-2018, 08:44 AM
Post: #49
RE: HP50g small tips and trick
I don't know if this has made it to anywhere I've seen yet, so I thought I'd share it for the newer users among us. Here's an explanation of the code snippet I came up with:

Code:

@Help: makes the current foldername usable for the program without the remainder of the PATH
\<<
  PATH @grab the full path to the place the code is called FROM (not the folder the program resides in)
  DUP @needed so we have a copy for GET 
  SIZE @ how large is the list? Leave it on the stack
  GET  @get the SIZEth element of the first PATH, i.e. the last entry in PATH
  \-> FName  @ stick it in a local var for use by the program
  \<< FName .... @ fill your code in here
  \>>
\>>

Now, onto how I used it. A while ago, Gilles59 provided me with some useful programs that I used:

(09-15-2017 08:51 PM)Gilles59 Wrote:  To create, calculate or update automatically the TOTAL for a month, here is an idea :

I added the above snippet to my program so it grabs its own folder name, now I simply call the program from the folder with the totals in, so there's no more changing folders within the program.
Here's how I used it. The TL;DR goes like this; I created a series of folders (JAN..DECEM), with totals for each grocery run inside, some examples are:

Code:

@ Path: { HOME GROCERY GRC2018 AUG }
{ 215.22 43.99 15.00 } AUG07 STO

@ Path: { HOME GROCERY GRC2018 MAY }
{ 237.96 55.27 12.00 2.00 17.00 6.30 } MAY01 STO
{ 274.74 38.00 14.00 8.00} MAY15 STO
{ 283.13 79.60 29.30 8.00 30.90 } MAY29 STO

The requirement I had was that each varname had to have the month name embedded in it somewhere, or it'd simply get ignored by later code. Most of the code below was pulled from the previous post I made.

Code:
@name: 'GRCMonthTotal'
«
  PATH @grab the full path to the current folder
  DUP @needed so we have a copy for GET 
  SIZE @ how large is the PATH list? Push that onto the stack
  GET  @grab the last entry in PATH
  -> Month  @ Create local var with the name of the month
  @ in my example, needs to be one of these: [JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEPT|OCTOB|NOV|DECEM]
  «
   0. 'TOTAL' STO   @ Stick zero into TOTAL, as we're going to add it all up @
   VARS                @ create list of variables in subdir @
S~N  @ turn them all into a list of strings @
1.  @ grab 1 entry from the list (part of how DOLIST works) @
   « IF 
         DUP @ create a duplicate of entry grabbed from list @
         Month S~N @ Turn Month varname into a string @
         POS  @ find its position in the previous string @
      THEN @ dump the test result, it was successful @
         S~N  @ Turn the var string back into a varname @
         EVAL @ Put it on the stack @
         AXL CNRM @ Turn it into an array and add it up @
'TOTAL' STO+  @ add this to TOTAL, removing it and 'TOTAL' from the stack @
      ELSE @ dump the 0 (test result) @
        DROP @ otherwise, ignore this string (remove it from the stack) @
      END » @ rinse, repeat. Pull another list entry until there aren't any more @
   DOLIST @ process each member of the list with the preceding IF-THEN-END @
   TOTAL @grab total, as we're about to display it
   Month -\>TAG @make it displayable, and push the result to the stack
 »
»

Quote:Warning : flag -86 must be set or type once [i]256 ATTACH

(Post 266)

Regards, BrickViking
HP-50g |Casio fx-9750G+ |Casio fx-9750GII (SH4a)
Visit this user's website Find all posts by this user
Quote this message in a reply
08-08-2018, 09:25 AM
Post: #50
RE: HP50g small tips and trick
Hi Brickviking, thanks for your contribution!

May I ask why you convert the sublist in an array? (If I understood the operations of your code)

If I understood correctly you go through the list of variables in a subdirectory. If a variable has an acceptable name, then it should be a list in the form:
{ 274.74 38.00 14.00 8.00 }
then you convert it to a vector with AXL and that is where I am puzzled.
Couldn't you just sum the elements in a list? With \GSLIST or sigmaList (left shift, SYMB [the MTH menu], list, sigmaList)

Wikis are great, Contribute :)
Find all posts by this user
Quote this message in a reply
08-08-2018, 10:08 AM
Post: #51
RE: HP50g small tips and trick
(06-16-2018 08:40 AM)Carsen Wrote:  
(06-15-2018 03:20 PM)Joe Horn Wrote:  Full-Screen Edit Without Losing Your Preferred Header Size

If you prefer normally having a HEADER size of 2 or 1, but would like to use the entire screen while editing programs, the Advanced User's Reference Manual suggests the following.

Wow! I gotta program this right away. This is really cool.

I programmed it into my calculator, but I did something really weird that killed everything in main memory on my calculator. I wasn't a happy camper, as you can imagine, as I'd lost the lot.

However ...
I had remembered—I have no idea why—to save the grocery folder to the SD card about five days ago, so I only had to put in my most recent rewrites from my last post in this thread, and add Tuesday's grocery haul to bring my data up to date. The rest, alas, is history until I restore it from other places (SDCard, online, etc).

So, remember your backups, people.

(Post 267)

Regards, BrickViking
HP-50g |Casio fx-9750G+ |Casio fx-9750GII (SH4a)
Visit this user's website Find all posts by this user
Quote this message in a reply
08-08-2018, 10:21 AM
Post: #52
RE: HP50g small tips and trick
(08-08-2018 09:25 AM)pier4r Wrote:  Hi Brickviking, thanks for your contribution!

May I ask why you convert the sublist in an array? (If I understood the operations of your code)

If I understood correctly you go through the list of variables in a subdirectory. If a variable has an acceptable name, then it should be a list in the form:
{ 274.74 38.00 14.00 8.00 }
then you convert it to a vector with AXL and that is where I am puzzled.
Couldn't you just sum the elements in a list? With \GSLIST or sigmaList (left shift, SYMB [the MTH menu], list, sigmaList)

I stumbled across one "bug" in \GSLIST. I have had on occasion lists that purely have one value, such as {216.30} 'AUG07' STO. \(\sum\)LIST barfs on lists that only have one entry and complains "Invalid Dimension", AXL CNRM steps around this problem nicely.

(Post 268)

Regards, BrickViking
HP-50g |Casio fx-9750G+ |Casio fx-9750GII (SH4a)
Visit this user's website Find all posts by this user
Quote this message in a reply
08-08-2018, 11:18 AM (This post was last modified: 08-08-2018 11:19 AM by pier4r.)
Post: #53
RE: HP50g small tips and trick
(08-08-2018 10:08 AM)brickviking Wrote:  So, remember your backups, people.

(Post 267)

Absolutely! The 50g as serious computing device also for collecting data deserves a bit of housekeeping utilities. Several users every now and them post some backup solutions but unfortunately those gets scattered (if you have one, please post it here: http://www.hpmuseum.org/forum/thread-10271.html ).

I have a backup utility for some folders but thanks to the size of the SDcard and the size of the port0 memory, it wouldn't be bed, as first approach, to backup everything to the SD card. Either through ARCHIVE or simply mass copy and paste (to then order properly on the SD card using the SDFiler).

I strongly suggest a mass copy and paste every now and then. Even better when automated. Then the SDcard content can be recovered even if the 50g doesn't work thanks to the emulators. Whatever is in the internal memory can be lost for good.

(08-08-2018 10:21 AM)brickviking Wrote:  I stumbled across one "bug" in \GSLIST. I have had on occasion lists that purely have one value, such as {216.30} 'AUG07' STO. \(\sum\)LIST barfs on lists that only have one entry and complains "Invalid Dimension", AXL CNRM steps around this problem nicely.

(Post 268)

Yes that bug is a bit annoying. Some suggestions:
- since we are talking about summing of list, one could do:
(a)
inputList 0 + \GSLIST
where 0 + ensures there is an additional neutral element to go around the \GSLIST bug.
Assuming that the list contains at least one element.
(b)
Install listExt http://www.hpmuseum.org/forum/thread-8555.html and use LSUM (oh I love that some good work gets visibility also thanks to small commands that were sometimes deemed unneeded). I strongly suggest ListExt if you are dealing often with lists (and I think it is the case). Plus goferlist if you want to get fancy. How to install a library on the 50g http://www.hpmuseum.org/forum/archive/in...d-971.html (I didn't find a better discussion)

Wikis are great, Contribute :)
Find all posts by this user
Quote this message in a reply
06-16-2022, 08:43 PM
Post: #54
RE: HP50g small tips and trick
(01-11-2017 06:32 PM)Joe Horn Wrote:  
(01-03-2017 08:55 AM)Vtile Wrote:  There is a lots of these poorly documented "shortcuts" (Advanced User Reference have many, but not all of them), here is a few more.

(Press and hold)
[Left shift] & MODE = "System" softmenu
[Left shift] & TOOL = Toggle Complex / Real mode
[Left shift] & VAR = Home
[Right shift] & DownArrow = Show variables with details

There is more.

FYI, all of those are on page G-2 (near the top) in the AUR. If Appendix G really is missing any keyboard shortcuts, I'd love to know, since I wrote the first draft of that appendix and I thought it was complete.

(01-11-2017 01:29 PM)grsbanks Wrote:  Nice one!

I'd been looking for HOME in various menus and had come to the conclusion that I needed to type it manually or fish it out of the catalogue. Much faster this way!
G. Stewart.

That's also on page G-2. The unit conversion shortcut mentioned above is also in Appendix G. Please do check out Appendix G in the AUR. It's loaded with nifty non-obvious keyboard shortcuts.

It's in appendix G of the user guide.
Find all posts by this user
Quote this message in a reply
03-13-2024, 02:34 AM
Post: #55
RE: HP50g small tips and trick
It wasn't obvious to me at first, but CONVERT, REWRITE, NEXT, ->Q (or ->Qpi) will convert a decimal back into an exact rational.

It's really helpful if you are trying to do exact equations but some of your inputs are given as decimals. Most people who ask how to do this on-line are given incorrect answers so if you try to google this, or ask one of those new fancy AI's you won't find the correct function.

Now if I could figure out how to get it to leave radicals into my denominators unless I ask it to rationalize my denominator specifically. Sometimes I want it to remain unrationalized.
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 5 Guest(s)