Post Reply 
Little explorations with HP calculators (no Prime)
06-01-2017, 07:44 PM (This post was last modified: 06-01-2017 07:54 PM by Vtile.)
Post: #221
RE: Little explorations with the HP calculators
(06-01-2017 07:00 PM)pier4r Wrote:  I was able only to find this reference:

(09-30-2016 04:36 PM)Guenter Schink Wrote:  2. is already available:
a: @this a volatile comment @
b: @@this is a persistent comment@@

From this thread.

I noticed there and there the usage of "@@" in comments.

I know that "@ it is seen as comment in userRPL until end of line or the next @" but I did not try around the "@@" , is it 'just' persistent (that is, it can be seen on the calculator even after saving the program) or does it also expand on the next line until a closing "@@" is written? (that is, a multiline comment)

(bonus question: I do not remember seeing @@ in the official documentation for the 50g, is it another of my mistakes? )
I think you are now falling to two similar, but not identical language trap! That thread is pure newRPL discussion. NewRPL allows persistent comments with that format, while userRPL do not.

UserRPL is memory optimised in that regard, it cuts the comments out to preserve precious 128kB 2kB of memory(..or what the size were back in the first models using RPL).
Find all posts by this user
Quote this message in a reply
06-01-2017, 10:19 PM (This post was last modified: 06-05-2017 01:54 PM by pier4r.)
Post: #222
RE: Little explorations with the HP calculators
but there are programs shared in the past with "@@" comments before newRPL was a thing.

And I learned the hard way that if I write:
@ this is a comment containing an @ in the middle

I get 'in' 'the' 'middle' on the stack.

So either a string of consecutive "@" is stripped, or "@@" for me would mean "start a comment and stop it immediately".

---
---


Aside from that, I am stuck in a relatively simple, although non standard, probabilistic problem because, well, I am still not good enough. Maybe someone here has an idea.

So I know (or I think I know) the formula to compute the expected value given a probability density (discrete or not).
I wanted to extend it to a new "dice".

The new dice is given by the following procedure:
I roll a dice 5 times in a row and I count the number of double ones that appears. That is , if I get the series 51161 I count 1, because there are only two ones appearing one after another.
If I get 51116 , I count 2 double ones. 5[11]16 and 51[11]6.
Of course something like 41356 has 0 double ones.

So given a dice that returns those "results", I started to make a list of useful combinations:
- 1 is were I expect a one
- x is where I expect 2 to 6
- y is where I expect 1 to 6 , it is an isolated one.

- only one double: 11xxy, 11xyx, x11xy, yx11x, yxx11, xyx11
probability for each series is 5*5*6/6^5 = 5^2/6^4
- two doubles: 111xy x111x yx111
probability 5*6/6^5 for the ones with y and 5^2/6^5 for the one with only x
- two doubles: 11x11
prob 5/6^5
- three doubles: 1111x x1111
prob 5/6^5
- four doubles: 11111
prob: 1/6^5

expected amount of double ones:
6 * 1 * 5^2/6^4 + 2 * 2 * 5/6^4 + 2 * 5^2 / 6^5 + 2 * 5/6^5 + 2 * 3 * 5 / 6^5 + 4 * 1 / 6^5 = 0.14326
All the rest has 0 double ones, so it does not matter in the computation.

Now, since I'm not sure, I also did a program to count for me (see below) but I got:
10 "rolls of this dice" produce an average of 0.1
100 produces 0.11
1000 produces 0.108
10000 produces 0.1092

So it does seem that either my code or my formula above is wrong and I would say my formula is wrong. Any ideas?

edit: I ended up counting overlapping solutions. This guy helped, so my formula above is wrong when I count 11xxy and 11xyx (I count in one place 2-6 and then 1-6, therefore counting overlapping sequences)

My code is right though. Power of computer science for the ones that performs poorly with math.

Code:

avgDoubleOnes
    @ the program seems to work and the idea of the "expected values of ones"
    @ it seems reasonably working.
    \<<
      0 "sumDoubleOnes" DROP
      -1 "lastRandom" DROP
      -1 "newRandom" DROP
      
      \->
      @input
      totalIterations
      
      @local var
      sumDoubleOnes
      lastRandom
      newRandom
      
      \<<
        PUSH
        -3 SF
        -105 SF
        
        1 totalIterations
        START
          @ reset
          -1 'newRandom' STO
          -1 'lastRandom' STO
        
          1 5
          START
            newRandom 'lastRandom' STO
          
            6 RAND * 1 + IP
            'newRandom' STO
            
            IF
              newRandom 1 ==
              newRandom lastRandom ==
              AND
            THEN
              1 'sumDoubleOnes' STO+
            END
          NEXT
        NEXT
        
        sumDoubleOnes totalIterations /
        
        POP
      \>>
    \>>





----
update 2017 06 05
how to execute programs in other directories: http://www.hpmuseum.org/forum/thread-228...l#pid20222

Wikis are great, Contribute :)
Find all posts by this user
Quote this message in a reply
06-13-2017, 09:49 AM (This post was last modified: 06-13-2017 10:00 AM by pier4r.)
Post: #223
RE: Little explorations with the HP calculators
So since some weeks I have two hp 50g. The second is assigned to newRPL (as soon as I get grip with it through the desktop version). I decided today to make use of the second (I see possible double usage with standard rom, so I may get a third 50g just to be sure) so I have two 50g connected via usb to a win XP system.

The conn4x anyway, fails to detect the one that has the Xserver running. Is that normal?

I mean one 50g is visualizing the stack, the other the Xmodem Server , but conn4x just goes in loop (not always).

With one 50g connected I have no problems. Is that normal?

Wikis are great, Contribute :)
Find all posts by this user
Quote this message in a reply
06-15-2017, 01:09 PM (This post was last modified: 06-15-2017 01:30 PM by pier4r.)
Post: #224
RE: Little explorations with the HP calculators
I would like to share a simple program for backup up a directory from home to the SD card.

The examples that I found on this site (search string site:hpmuseum.org sd backup) use heavily the stack - while I like named variables, especially for things that do not have to be fast - and do not use the sdlib included with the sdfiler.

Since I would have liked to see an example with a different layout and I did not find it, I share mine to raise the chances that a reader, for example me in the future, can have another idea.

The program is far from being general, it is just an example how a backup program can be done.

Code:

backupToSd
  @it requires the sdfiler/sdlib library 
  \<<
    "LIFEGDIR" "fileStrDos" DROP
    "" "dateStr" DROP
    "" "timeStr" DROP
    "" "sdDirStr" DROP
    
    \->
    @input 
    
    @local var
    fileStr
    dateStr
    timeStr
    sdDirStr
    \<<
      -42 SF
        @date dd.mm.yyyy
        @time does not need the flag -41
    
      DATE \->STR "." "" SREPL 
      DROP @we don't want to know the number of replacements
      'dateStr' STO
      
      @Now we need to "roll" the data instead of 15062017 we want
      @20170615 further we need to know that we dates with trailing
      @zeroes the tailing zero is lost
      IF
        dateStr SIZE 8 \=/
      THEN
        'dateStr' 0 STO+
      END
      
      dateStr 5 8 SUB @year
      dateStr 3 4 SUB + @month
      dateStr 1 2 SUB + @day
      'dateStr' STO
      
      TIME \->STR "." "" SREPL DROP
      'timeStr' STO
      
      timeStr 1 2 SUB @hours
      timeStr 3 4 SUB @min
      timeStr 5 6 SUB @seconds
      + + @concatenate
      'timeStr' STO
      
      @'fileStr' dateStr STO+
        @we cannot make this now, it cannot be done by the RPL filer
      
      {HOME LIFEG} RCL      
        @put the object in memory 
        @(problem, when the memory does not have enough space to duplicate an object on the stack)
      
      fileStr
      3 \->TAG
      STO @stores it on the sd  
      
      @rename the file on the SD using the library
      fileStr
      'fileStr' dateStr STO+
      'fileStr' timeStr STO+
         @longfilename with all those info
      fileStr
      SDMOVE
      
      @now moving it in the right directory on the sd
      "LIFEGDATABACKUP/B" dateStr + 'sdDirStr' STO
      @sdDirStr SDMKDIR
        @I need to handle the message, luckly the sdlib has also commands that
        @are less strict
      sdDirStr XMKDIR DROP
        @creates the folder, if already existing, it does not fail.
        @this is valid for multiple backups in a day
      
      fileStr
      sdDirStr "/" + fileStr +
      SDMOVE
    \>>
  \>>


Other useful topics that I found (but based heavily on stack operations):
- http://www.hpmuseum.org/cgi-sys/cgiwrap/...ead=126574
- http://www.hpmuseum.org/cgi-sys/cgiwrap/...ead=112771

(maybe the comp.sys.hp48 is a better archive for RPL questions , especially reading messages from 2010 or before, sometimes people address that newsgroup . Searching for sd backup)
- ok maybe this program http://page.mi.fu-berlin.de/raut/WR49/Filer6.htm from this page http://page.mi.fu-berlin.de/raut/WR49/index.htm#General may help
- https://groups.google.com/forum/#!search...7AI-5vHWQJ this is the discussion about the sdfiler from TW and Claudio L. themselves.

Wikis are great, Contribute :)
Find all posts by this user
Quote this message in a reply
09-09-2017, 09:21 PM
Post: #225
RE: Little explorations with the HP calculators
New little problem. I could not translate it in a list problem or a string processing problem therefore I post it in this thread that is more of a "catch all!" of my posts.

[Image: Imo5HyRl.jpg]

So there is a park with paths that can be seen as two squares, one in another. The internal square is constructed linking the middle points of the sides of the bigger square.

Alan and Bob start running in the same point (one middle point of the bigger square), only Alan keeps running on the bigger square and Bob on the internal one. Both have the same pace.

Question:

(a) assuming that they have unlimited capacity and they keep running forever, would they meet again in a place while running?

(b) (the question that I wanted to convert in list/string processing . Inspired by the recent posts of Gerald H about sequences) .
Assuming that the bigger square has vertex A, B, C, D and middle points E, F, G, H. IAlan and Bob start Both in the point E.

Alan goes through E, A, B, C, D, A, B, C, D, A, ...
Bob goes through E, F, G, H, E, F, G, H

Every time that Bob reaches a vertex of the square EFGH, is Alan ahead, considering only the current lap of Alan having checkpoints E,F,G or H?

For example, from the start:
entry, Alan, Bob :
0, E, E - same
1, behind, F
2, behind , G
3, behind, H
4, behind, E
5, ahead, F (Alan is near to reach E, while Bob is only at F)
6, behind, G
7, behind, H
8, behind, E
9, ahead, F (Alan is past G)
10, ahead, G (alan is past H)
etc...

Therefore what we want is: given the value N (N > 0), determine if for the entry "N" Alan is ahead of Bob according to the description given above.

Wikis are great, Contribute :)
Find all posts by this user
Quote this message in a reply
09-09-2017, 10:03 PM (This post was last modified: 09-09-2017 10:14 PM by Joe Horn.)
Post: #226
RE: Little explorations with the HP calculators
(09-09-2017 09:21 PM)pier4r Wrote:  (a) assuming that they have unlimited capacity and they keep running forever, would they meet again in a place while running?

If Alan and Bob are mathematical points with no extension, then NO. Let's assume that the outer perimeter is 4. At all 4 midpoints, the distance covered by the outer runner will always be a rational number, and the distance covered by the inner runner will always be an irrational number, and hence never equal. The same logic applies regardless of the actual measurements.

If Alan and Bob are actual physical beings, then YES. If they never speed up, slow down, or veer off course, then bumping into each other is inevitable.

EDIT: The first paragraph is only true in an abstract, non-physical reality. In THIS universe, where everything seems to be made up of discrete quanta, I suppose even infinitely small points would eventually meet as they hop-scotch in contiguous, minuscule jumps (quantum leaps?), rather than moving smoothly and continuously, along their respective paths.

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
09-10-2017, 09:55 AM
Post: #227
RE: Little explorations with the HP calculators
Ok while the other problem is still open (1), a new one.

given 4 different positive integers: a, b, c, d .

Find all the quadruplets where all the terms are smaller than 1000, that satisfy the following identify

(a+b) / (c+d) = (a-b) / (c-d)

(I did not attack it yet).

Bonus: do the same for positive integers: a, b, c, d where there are at least 3 different integers.

Once again, I do not see how those can be list/string challenges, if someone has an idea, he is welcomed!

(note1) or better, I think that getting the information whether Alan is ahead of Bob for the entry N should be not that complicated unless I am mistaken.

Wikis are great, Contribute :)
Find all posts by this user
Quote this message in a reply
09-10-2017, 10:46 AM
Post: #228
RE: Little explorations with the HP calculators
(09-10-2017 09:55 AM)pier4r Wrote:  (a+b) / (c+d) = (a-b) / (c-d)

Don't want to spoil too much of the fun but this is equivalent to a / b = c / d <> 1.
Find all posts by this user
Quote this message in a reply
09-11-2017, 09:21 PM (This post was last modified: 09-11-2017 10:25 PM by Gilles59.)
Post: #229
RE: Little explorations with the HP calculators
(09-10-2017 10:46 AM)AlexFekken Wrote:  Don't want to spoil too much of the fun but this is equivalent to a / b = c / d <> 1.

That's a lot !

HP50G

'(a+b) / (c+d) = (a-b) / (c-d)'
'a' ISOL
->
a=(c.b)/d

That means (if we dont care about 2 same values of a b c d), that the number of quadruplets is the sum of the divisors of c*b for c:1->999, b:1->999

Quick and dirty HP50G + GoferList:

Code:
«
 1 999 FOR c
  1 999 FOR b
   c b * 
   DIVIS  « 1000 < » Filter  @d   
   DUP REVLIST  @ a
   Zip 1. « b +  c +  » DOLIST 
   « Nub SIZE 4. == » Filter  @ a,b,c,d all different
   IF DUP Null THEN DROP ELSE 1. « { a d b c} SWAP = » DOSUBS HALT  END
  NEXT
 NEXT
»

Get ready for ~ 1000000 Shift CONT

ex : { { 'a=2' 'd=7' 'b=14' 'c=1' } { 'a=7' 'd=2' 'b=14' 'c=1' } }
Find all posts by this user
Quote this message in a reply
09-24-2017, 08:17 PM (This post was last modified: 09-24-2017 08:47 PM by pier4r.)
Post: #230
RE: Little explorations with HP calculators (pre Prime)
Sometimes this problems happens to me but finally I decode it. (I asked this already but I was not sure)

in userRPL if I write a comment like this:
@@test
in the program on the calculator 'test' is left .

Does that mean that
@this is a comment until the end of the line
while
@this is a comment until the next at@ while this are program statements
is until the second '@' ?

Does anyone know the proper behavior of how '@' is interpreted in all cases?


edit: I wonder when I will learn all the useful things on the 50g.
If you have the clock on the screen on the 50g, and the 50g is buy in a long computation, the clock won't be updated, giving you an idea for how long the system has been under load.

Wikis are great, Contribute :)
Find all posts by this user
Quote this message in a reply
09-25-2017, 12:12 AM
Post: #231
RE: Little explorations with HP calculators (pre Prime)
(09-24-2017 08:17 PM)pier4r Wrote:  in userRPL if I write a comment like this:
@@test
in the program on the calculator 'test' is left .

Does that mean that
@this is a comment until the end of the line
while
@this is a comment until the next at@ while this are program statements
is until the second '@' ?

Does anyone know the proper behavior of how '@' is interpreted in all cases?

I only know that it starts ignoring at the first @, and stops ignoring after the next @, hence one reason why it's difficult to embed email addresses in a comment. This doesn't hold true for @ inside " or ' though, otherwise we'd be in all sorts of bother.

Others will be able to perhaps quote chapter/verse of applicable manuals.

(Post 94)

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
09-25-2017, 12:23 AM
Post: #232
RE: Little explorations with HP calculators (pre Prime)
(09-24-2017 08:17 PM)pier4r Wrote:  Sometimes this problems happens to me but finally I decode it. (I asked this already but I was not sure)

in userRPL if I write a comment like this:
@@test
in the program on the calculator 'test' is left .

Does that mean that
@this is a comment until the end of the line
while
@this is a comment until the next at@ while this are program statements
is until the second '@' ?

Does anyone know the proper behavior of how '@' is interpreted in all cases?

From the AUR, p. 1-7:

Creating Programs on a Computer

It is convenient to create programs and other objects on a computer and then load them into the calculator.

If you are creating programs on a computer, you can include “comments” in the computer version of the program.

To include a comment in a program:

 Enclose the comment text between two @ characters. or
 Enclose the comment text between one @ character and the end of the line.

Whenever the calculator processes text entered in the command line — either from keyboard entry or transferred from a computer — it strips away the @ characters and the text they surround. However, @ characters are not affected if they’re inside a string.

I agree, there is always something new to learn about the 50g.

--Bob Prosperi
Find all posts by this user
Quote this message in a reply
10-17-2017, 08:18 AM (This post was last modified: 10-17-2017 01:19 PM by pier4r.)
Post: #233
RE: Little explorations with HP calculators (pre Prime)
Interesting bit (maybe only interesting for me).

As I (maybe) wrote I am using one of my 50g for a long term project named "life gamification". It is nothing else that collecting data from my point of view to evaluate how I perceived my days. I hope to write a little summary about it but the idea is more or less similar to the one mentioned in the following article: https://hackernoon.com/how-data-forced-m...df76064903

So far I collected 132 days of data, mostly in a directory made out of lists of reals (the total size of the directory is 11 KB on the calculator).

What I do after every collected day is a backup, with a rough script that sometimes requires two executions (see below) and is likely not safe after hundreds of executions due to name conflicts.

After several backups done with the method mentioned above, I browse the SD with the SD filer and I rename the backups done, plus I move them in a precise subfolder on the SD card.

Well today, after having some 30+ objects in the root folder of the SD card, the SD filer stopped working. (sd filer: http://www.hpcalc.org/details/6524 + )

I tried a soft reset (on + F3) but nothing. I may have to reinstall the library, I am not sure, but I was not expecting it.

Another bit: already some weeks ago, browsing with the SDfiler the content of the SD, I noticed that sometimes the SD filer was unable to report all the files in a folder 50+ of them (in particular the 'final' folder where I save the backups). Of , say 60 files, only 40 or 50 were listed.


Code:

  bckSafe
  @input: a string (with a date)
  \<<
    @11:18 10.08.2017
    @safe backup as long as the backup using the SDLIB is not foolproof
    @in input one puts a string with the time like "201708201116"
    @then the STO command is going to save the LIFEG directory
    @ (one executes the program within the directory)
    @with the name LGB201708201116
    @but while STO puts the entire name, only the first 8(?) letters
    @are important for it. So often there is a conflict with
    @existing files
    @and we need a workaround.
    
    "" "filenameStr" DROP
    
    \->
    @input
    inputStr
    @local var
    filenameStr
    
    \<<
      @check input
      IF
        inputStr TYPE 2 \=/
      THEN
        "argument as string please"
        DOERR
      END
      
      @save all the variables for later comparisons with the backup
      {HOME LIFEG} EVAL
        @move in the directory
        
      @clean up 'allvars' from the existing list
      @it is needed a "delete" command actually from a list, so it can be safer
      IFERR
        'allListVars' PURGE
      THEN
        "var likely does not exist" DROP
          
        @drop the commands if last argument is enabled.
        IF
          -55 FC?
        THEN
          DROP
        END
      END
        
      5 TVARS  @collect all the lists
      'allListVars' STO
        @global var
        
      
      
      
      inputStr
      @generate a random number with 4 digits
      10000 RAND * IP
      DUP 
      9000 <
        @returns 0 or 1
      1000 * +
        @add 1000 to the number only if that is lower than 9000
      R\->I
        @no trailing points
      \->STR  
      "LGB" + 
        @we have nnnnLGB
        @that can be cleaned later.
      SWAP + 
      @3. \->TAG 
      'filenameStr' STO
        @lesson learned, it seems that tags are not saved in variables
      
      UPDIR 'LIFEG' RCL 
      filenameStr 
      3. \->TAG 
      STO
      
      filenameStr 
      3. \->TAG 
      RCL 
        @check the result after storing.
    \>>
  \>>


edit: after some hours, SDfiler works again (I recalled the sdlib first to see if it had the same problem). Dunno why.

Wikis are great, Contribute :)
Find all posts by this user
Quote this message in a reply
10-17-2017, 01:34 PM (This post was last modified: 10-17-2017 01:46 PM by pier4r.)
Post: #234
RE: Little explorations with HP calculators (pre Prime)
Another topic.

I realized (maybe a little too late) that syntax highlighting helps even with concise languages, especially if I am used to use notepad++ .

Has anyone done a user defined language for userRPL for notepad++? I tried to search it via google but with no useful results.

Of course I decided to do my version since it is not difficult to do (I will include it in the next hp calc torrent ) but if someone has already an advanced work, it would be worth it, I think. Otherwise I will include keywords as soon as I encounter them, so not very quickly.

Wikis are great, Contribute :)
Find all posts by this user
Quote this message in a reply
10-17-2017, 04:46 PM
Post: #235
RE: Little explorations with HP calculators (no Prime)
Some news about the userRPL user defined language for notepad++ (once again, if someone has a more complete version, please let me know).

It helps quite a bit

[Image: 8ubiFiS.png]

[Image: bdMNOCV.png]

note the variables, have to be called lvname to be highlighted.

I hope to adjust it later for newRPL as well, since the newRPL desktop version can import text files. (I will include it also in the next torrent release, then you can give me feedback if you want)

I used it to test a solution to a micro problem that was since long time in my todo list.

One has processes that print on the console and locks. One should define the different processes in a way that they coordinate to print the wanted pattern even if the execution is randomly picking between the two processes.

So the basic is to have the process A and the process B (or 1 and 2) and to print 1,2,1,2,1,2 etc..

This gets more complicated if the pattern to produce is more complicated and there are more processes involved. For the moment, though, I am happy that I was able to find a way to test it on the hp 50g. Below the first working solution.

Of course, from real problem solving - especially if one is not that good like me - new questions arise so I am going to ask the following:

To "pack" a command to be executed I discovered the following method:
"statements" OBJ\->

instead of the more verbose
\<< statements \>>
(note that with a text expander like fastKeys on windows - aText on mac - one could produce \<< \>> quite quickly with shortcuts)

Do you know any other way?

In particular could be possible to pack and entire program in a string or block of some type and then execute it in "pieces" in a proper way?

Code:

  lockSyncPatterns
  \<<
    @2017-10-17 working.
  
    @ During my university time there was a course, about software engineering
    @ (programming with agents) that exposed me to a couple of little problems
    @ to solve mostly with locks or synch mechanisms related to Petri networks. 
    @ This exposure lasted maybe for a couple of hours but it was interesting.
    @ For years I had this in the back of my mind but I never played with them
    @ until I started to collect little problems to challenge my colleagues
    @ in my current company (that has some hundreds of colleagues so it is worth
    @ to try). In reality those little challenegs push me also to find little
    @ problems and solve them.
    
    @ In short those problems can be defined in this way.
    @ One has a certain number of workers that print to the console their name.
    @ Like the worker A print A, the worker B prints B and so on.
    @ Then one has a certain type of locks and define a run rutine (in a while true)
    @ and wants to achieve a certain pattern.
    
    @ Now the problem can have way more difficult variants but the variant choose here is:
    @ there is a default setup before the execution.
    @ the code of workers is defined (note that it is easier if every worker has a different code)
    @ then the workers are executed statement by statement in a random order
    @ simulating context switch (that the 50g does not have)
    @ the pattern nevertheless has to be achieved.
    
    @I'd like to create a little engine that takes different workers,
    @ "exploded" in single commands (would be great if I am able to write entire
    @ programs in one block and then pick the single operations) that then gets
    @evaluated
    
    @note: from a string well defined, OBJ\-> executes the contents
    @ and I wonder how many useful commands I still don't know that could help in this case.
    @ the 50g library is amazing sometimes.
    
    10 "lvIterations" DROP
    10 "lvUflagA" DROP
    20 "lvUflagB" DROP
    {} "lgResultPattern" DROP
      @to store the result between programs
    {
      "lvUflagA lockSyncPatternsBlockForce"
      "lvUflagB lockSyncPatternsBlockForce"
    } "lvInitStatements" DROP
    2 "lvNumJobs" DROP
    @@
    {
      { @jobA
        "1 lockSyncPatternsPrint"
        "lvUflagB lockSyncPatternsRelease"
        "lvUflagA lockSyncPatternsBlock"
      } 
      { @jobB
        "lvUflagB lockSyncPatternsBlock"
        "2 lockSyncPatternsPrint"
        "lvUflagA lockSyncPatternsRelease"
      }
    } "lvJobs" DROP
    @@
    {
      1.
      1.
    } "lvJobsICounters" DROP
    @@
    {
      3.
      3.
    } "lvJobsStatements" DROP
    @@
    0 "lvCurrentJobIndex" DROP
    0 "lvCurrentJobICounter" DROP
    
    \->
    lvIterations
    lvUflagA
    lvUflagB
    \<-lgResultPattern
    lvInitStatements
    lvNumJobs
    lvJobs
    lvJobsICounters
    lvJobsStatements
    lvCurrentJobIndex
    lvCurrentJobICounter
    
    \<<
      @execute first the init global statements
      1 lvInitStatements SIZE
      FOR index
        lvInitStatements index GET
        OBJ\->
        DROP @drop the return code
      NEXT
      
      @execute the jobs (the job themselves are designed for a loop)
      1 lvIterations
      START
        @select randomly a job 
        lvNumJobs RAND * 1 + IP 'lvCurrentJobIndex' STO
        
        @select the current instruction of the job
        lvJobs lvCurrentJobIndex GET @the job
        lvJobsICounters lvCurrentJobIndex GET 
        DUP 'lvCurrentJobICounter' STO @save the IC
        GET @the instruction
        
        @execute the instruction and check whether
        @the counter should be updated
        IF
          OBJ\->
        THEN
          @instruction successful, increase the counter properly
          IF
            lvCurrentJobICounter
            lvJobsStatements lvCurrentJobIndex GET
            <
          THEN
            @increase the counter
            lvJobsICounters lvCurrentJobIndex lvCurrentJobICounter 1 + PUT
            'lvJobsICounters' STO
          ELSE
            @reset the counter
            lvJobsICounters lvCurrentJobIndex 1 PUT
            'lvJobsICounters' STO
          END
        @else the counter stays the same
        END
      NEXT
      
      \<-lgResultPattern
    \>>
  \>>
  
  lockSyncPatternsPrint
  \<<
    @ save the input in the result pattern
    '\<-lgResultPattern'
    SWAP
    STO+
    1 @leave 1 as "operation successful"
  \>>
  
  
  lockSyncPatternsBlock
  \<<
    @input a user flag number
    IF
      DUP FS?
    THEN
      DROP @ drop the input
      0 @return not successful
    ELSE
      SF @set flag
      1 @return successful
    END
  \>>
  
  lockSyncPatternsBlockForce
  \<<
    @input a user flag number
    SF @set flag
    1 @return successful
  \>>
  
  lockSyncPatternsRelease
  \<<
    @input a user flag number
    CF
    1 @return successful
  \>>

Wikis are great, Contribute :)
Find all posts by this user
Quote this message in a reply
10-22-2017, 08:50 AM
Post: #236
RE: Little explorations with HP calculators (no Prime)
Little discovery about SREPL (likely documented somewhere but not in the 50g AUR).

SREPL returns
L2: string with replacements done
L1: number of substitutions

L1 in output is not mentioned by the AUR.

Practical example.

From list in RPL to array for javascript (using highcharts.js for plotting, recommended!):
Code:

gpConvertListToJsArray
  \<<
    @input a list
    @transform in string
    \->STR
    @replace the string opening and closing with squared brackets
    "{" "[" SREPL DROP
    "}" "]" SREPL DROP
    
    @replace the "." of the real numbers with no decimals
    "." "," SREPL
    DROP @drop the number of replacements
  \>>

Wikis are great, Contribute :)
Find all posts by this user
Quote this message in a reply
10-22-2017, 01:52 PM
Post: #237
RE: Little explorations with HP calculators (no Prime)
(10-22-2017 08:50 AM)pier4r Wrote:  Little discovery about SREPL (likely documented somewhere but not in the 50g AUR).

SREPL returns
L2: string with replacements done
L1: number of substitutions

L1 in output is not mentioned by the AUR.

This is an error in the AUR. I don't know of anywhere it is correctly documented.
Find all posts by this user
Quote this message in a reply
10-22-2017, 03:51 PM (This post was last modified: 10-22-2017 08:42 PM by pier4r.)
Post: #238
RE: Little explorations with HP calculators (no Prime)
Thanks John!

Another tip. While playing around with large lists (1000 elements) I noticed that ADD was not that fast.

So quick test ADD vs DOLIST:
1000 elements (repeated only once)
ADD ~ 5 seconds
DOLIST ~ 5.6 seconds

Code:

gpTestAddDOLIST
  \<<
    @as usual, the more on does, the more one may notice.
    @damn me that I forget this or I don't appreciate it.
    
    @So playing around on the 50g (first and foremost one needs to
    @check part of the commands for an algorithm manually)
    @I observed that ADD is not that fast. Surely
    @multiplying a list by a scalar is quick, but adding two lists
    @ (admittedly of 1000 elements) was not that quick.
    @ So I wonder if Add is faster than DOlist or not.
    @first list
    100 RAND * IP 1000 NDUPN \->LIST
    @second list
    100 RAND * IP 1000 NDUPN \->LIST
    
    @add
    \<<
      DUP2 ADD
    \>>
    TEVAL
    
    @DOLIST
    \<<
      @due to the things on the stack. Some picks
      @Eh, named variables are more easier to manage
      @and resilient to changes
      PICK3 @ second list
      5 PICK @first list
      2
      \<< + \>>
      DOLIST
    \>>
    TEVAL
  \>>

edit:
Another info
generating 1000 values in a list with the SIN function takes time.
if, after every value, one stores it in a list with STO+
it takes around 600 seconds.

Wikis are great, Contribute :)
Find all posts by this user
Quote this message in a reply
10-22-2017, 08:30 PM
Post: #239
RE: Little explorations with HP calculators (no Prime)
(10-22-2017 01:52 PM)John Keith Wrote:  
(10-22-2017 08:50 AM)pier4r Wrote:  Little discovery about SREPL (likely documented somewhere but not in the 50g AUR).

...

This is an error in the AUR. I don't know of anywhere it is correctly documented.

Speaking of the AUR for the 50g/49g+/48gII, is there a list of errata/omissions since the document was last published? If so, is this omission mentioned on that errata?

(Post 120)

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
10-22-2017, 11:05 PM
Post: #240
RE: Little explorations with HP calculators (no Prime)
(10-22-2017 03:51 PM)pier4r Wrote:  generating 1000 values in a list with the SIN function takes time.
if, after every value, one stores it in a list with STO+
it takes around 600 seconds.

Adding elements to a list one by one is very inefficient and causes a lot of garbage collection. It is much faster to accumulate the elements on the stack, then combine them into a list like so:

Code:
\<< 1. 1000. FOR j j SIN
             NEXT 1000. \->LIST
\>>

which takes about 12.2 seconds on my 50g.
Find all posts by this user
Quote this message in a reply
Post Reply 




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