Collaborative collection of useful userRPL snippets

03032018, 03:12 PM
(This post was last modified: 07082021 11:22 AM by pier4r.)
Post: #1




Collaborative collection of useful userRPL snippets
The more I browse this forum or the net for userRPL solutions, the more I think that a library of "generic" programs would help. "generic" between quotes because what is generic may vary from use to user.
I know that ideally there is hpcalc.org, the general software library on this forum, wiki4hp and so on to collect such snippets, but it is also true that I saw this or that snippet always isolated, never a library to collect them in one place. Hence this thread (that may fail, but it is worth trying). Another point of this thread is to solve problems that sounds generic enough to warrant a solution for this library. I saw some interesting questions posted on the facebook group (unfortunately those messages are hard to backup for the moment) that could be a nice input to assemble quick but effective little programs. For example for me generic is a little command that computes the median of a list (or a column of a matrix, and so on). Although many people here will be able to write it on the spot, can often happen that someone wants to do something else and does not want to write first all the helper routines, even if they are small. I already collected a couple of commands by myself, but not much. Those are in the hp calc torrent and I will upload them from time to time to the hpcalc.org and the wiki4hp. The more "doors" through which a person can get to a point, the better. Now what I want to emphasize is that I see often something mentioned like "oh those are just 34 commands, they don't deserve to be in a library". Well in my opinion they do if they may help several users in several programs relieving them to know how to assemble those 34 commands. Furthermore those 34 commands may require some experience with the RPL library of this or that calculator, so they may be not that easy to replicate. They can be also used as examples of what one can do knowing the RPL library. Or they can be used as pointers for other commands that are similar. One could pack them in an utility library and then that is, the library is available to everyone, in one place and hopefully indexed by the common search engines. Thus also the commands similar to those in the 1 minute marvels pdf are highly appreciated. So I put the collected commands here: http://www.wiki4hp.com/doku.php?id=rpl:start or here (when I cannot access wiki4hp) https://app.assembla.com/spaces/various...grams.urpl or here (if assembla closes the free accounts) https://de.osdn.net/users/pier4r/pf/vari...grams.urpl you can go and edit everything (I did not spent a lot of time to organize them, first come the collection). If you have any command to suggest, please do. Already a link to the source code is enough. I will report every addition here in the first post. Changelog Using wiki comments: http://www.wiki4hp.com/doku.php?id=rpl:s...=revisions  20180309. Added weighted and harmonic average of lists, converting examples from the 50g user guide (see page 815 and subsequent ones) . Refactored the order of programs and information. Added the program row vector to column vector, column vector to row vector, list to row vector  2018.03.03. Started the attempt to slowly build a library of useful snippets. Wikis are great, Contribute :) 

03032018, 03:25 PM
(This post was last modified: 03092018 02:01 PM by pier4r.)
Post: #2




RE: Collaborative collection of useful userRPL snippets
So here some questions (rephrased) that I find interesting from the facebook group (see also http://www.hpmuseum.org/forum/thread9679.html )
TODOs  How do you sort a matrix by column (define a sort metric that for you makes sense) or by row?  by extension, any other matrix/vector operations that you find useful not present in the base RPL library? Wikis are great, Contribute :) 

03092018, 11:00 AM
(This post was last modified: 03092018 12:13 PM by pier4r.)
Post: #3




RE: Collaborative collection of useful userRPL snippets
 Added weighted and harmonic average of lists, converting examples from the 50g user guide (see page 815 and subsequent ones) .
 Refactored the order of programs and information. Added the program "row vector to column vector" (page 920 hp50g user manual). Same with column vector to vector and list to vector. http://www.wiki4hp.com/doku.php?id=rpl:start  It is interesting that useful code is spread through the manuals, not only for pre PDF hp models (that is: those that came with the printed manuals). One would presume that with newer models useful code would be written in a way that is easy to copy and paste on the calculator. Instead it is exposed as procedure. The exposition is useful to understand better the algorithm, but it is not immediate to think it as a program. So I am going to randomly check the 50g user guide, then maybe the 50g AUR. If I am not mistaken in the first part of the AUR there may be some useful code as well, like percentiles or something similar. I won't go through the entire AUR though, unless I end up casually on interesting snippets. As usual, contribute! This is the reason the code is on the wiki, so we can all edit it.  Another thought that crossed my mind while testing the snippets was whether such statistical operations on lists, could be way faster when done in sysRPL a la David listExt, or the internal RPL functions are already pretty quick with whatever input size. Wikis are great, Contribute :) 

03112018, 01:55 PM
Post: #4




RE: Collaborative collection of useful userRPL snippets
 added info about RDM. Added programs exposed in the 50g user guide to transform n lists of equal size in a matrix, using the lists as columns or as rows.
Link, always the same: http://www.wiki4hp.com/doku.php?id=rpl:start&do= As usual, be welcomed to contribute! Programs, or refactoring (if it adds in usability), comments, links, fixes, examples, info, etc... One can also contribute uploading the file from time to time to hpcalc.org (I'll do it too). Wikis are great, Contribute :) 

03182018, 09:02 AM
Post: #5




RE: Collaborative collection of useful userRPL snippets
 Added functions related to random output, like selecting 'N' random numbers without repetition
 many other little changes. See http://www.wiki4hp.com/doku.php?id=rpl:s...=revisions Code: http://www.wiki4hp.com/doku.php?id=rpl:start&do= Suggestions and additions are always welcome. Wikis are great, Contribute :) 

03252018, 03:57 PM
Post: #6




RE: Collaborative collection of useful userRPL snippets
While searching for this and that topic, as I remember I saw some RPL algorithms exposed here related to the topic I am searching, I observed that:
 In this http://www.hpmuseum.org/forum/thread7955.html thread I asked something 23 times, until I finally remember it. (check for the double @@ comments) Damn me. This shows quite a patience from the community.  There are plenty of RPL gems already in this new forum, but either one has a very poignant keyword/sentence, or the chances to find them with a generic keyword/sentence are very low. One has to read through the entire forum to find them. Anyway, added some commands to the collection from Joe Horn and DavidM. As usual, contributions are welcomed. http://www.wiki4hp.com/doku.php?id=rpl:s...=revisions Wikis are great, Contribute :) 

03262018, 01:54 AM
Post: #7




RE: Collaborative collection of useful userRPL snippets
Unless I'm missing the point of the collection, I'd suggest changing the "randInt" entry from
Code: randInt Code: randInt <0ɸ0> Joe 

03262018, 07:58 AM
Post: #8




RE: Collaborative collection of useful userRPL snippets
Done! http://www.wiki4hp.com/doku.php?id=rpl:s...=revisions
Are you not registered on the wiki? You could do it on your own and report the change here if you want. Otherwise people have to wait until I have time to fix/add the suggestion. Wikis are great, Contribute :) 

03262018, 08:32 AM
Post: #9




RE: Collaborative collection of useful userRPL snippets
I just had a quick look and noticed that the angle between vectors snippet is using the arccosine of the dot product. This has some numeric issues. Better is this formula:
\[angle\_between(\,\vec v_1, \vec v_2) = \begin{cases} \pi  2 \, arcsin \frac{\mathopen\vec v_2  \vec v_1\mathclose}{2}, &\quad \vec v_1 \boldsymbol{\cdot} \vec v_2 < 0 \\ 2 \, arcsin \frac{\mathopen\,\vec v_2  \vec v_1\mathclose}{2}, &\quad\text{otherwise.} \\ \end{cases} \] 

03262018, 09:55 AM
Post: #10




RE: Collaborative collection of useful userRPL snippets
Interesting bit Paul! As you can see from the library, I trusted the 50g user guide. I am going to insert your fix when I have time (or you can).
May I ask you to explain also why it is better? For reference. Thanks! Wikis are great, Contribute :) 

03262018, 10:55 AM
(This post was last modified: 03262018 10:57 AM by Paul Dale.)
Post: #11




RE: Collaborative collection of useful userRPL snippets
It comes down to taking an arccosine of a number near to ±1. The result is close to zero but you are also likely to lose up to half the possible digits. Remember that there are more numbers close to zero than any other number in floating point arithmetic and that cosine is very flat when it takes a value of ±1.
For fun, try plotting: \( arccos(1x) \) and \( 2 \, arcsin(\sqrt{\frac{x}{2}}) \) for very small \( x > 0 \). These two are mathematically equivalent. There is also a worse possibility here, where the number rounds to > 1 or < 1 causing an error. 

03272018, 02:58 PM
(This post was last modified: 03272018 03:06 PM by peacecalc.)
Post: #12




RE: Collaborative collection of useful userRPL snippets
Hello Paul,
why you don't like to use that expression for finding the angle between to vectors? \[ angle between(\vec{v}_1,\vec{v}_2)= arccos\left(\frac{\vec{v}_1 \cdot \vec{v}_2}{\vec{v}_1  \vec{v}_2}\right) \]. It is brutal force... but in RPL it is easy to manage: Code: << \> v1 v2 Sorry I forgot if the angle is greater than 90 degrees (or pi/2) then take 180 degrees minus the result above (or pi  result). Double sorry, I've now understand your display task in your last post. 

03272018, 09:13 PM
Post: #13




RE: Collaborative collection of useful userRPL snippets
As I noted, using arccosine results in a significant loss of accuracy for some input. The alternative formula doesn't.
Pauli 

05132018, 08:40 AM
Post: #14




RE: Collaborative collection of useful userRPL snippets
Although I did not fixed the angle between vector routine yet (I added a link though) the collection is proceeding, very slowly. At this pace it may include what is useful and available __today__ in the public domain  assuming it will be still available  in some 30 years. Any contribution is appreciated. Therefore the code is on a wiki, everyone can go there and edit it leaving a comment for the change.
changelog: http://www.wiki4hp.com/doku.php?id=rpl:s...=revisions Wikis are great, Contribute :) 

11172018, 11:35 PM
Post: #15




RE: Collaborative collection of useful userRPL snippets
http://www.wiki4hp.com/ is at the moment down for me. This would hurt a lot as I assumed it was a stable site (maybe it is just an hiccup, I hope so) to put effort on it over time.
Is it down also for you? Wikis are great, Contribute :) 

11172018, 11:50 PM
Post: #16




RE: Collaborative collection of useful userRPL snippets
(11172018 11:35 PM)pier4r Wrote: http://www.wiki4hp.com/ is at the moment down for me. This would hurt a lot as I assumed it was a stable site (maybe it is just an hiccup, I hope so) to put effort on it over time. Ok for me (in NY, USA) on 181117 at 1849hrs Bob Prosperi 

11182018, 07:02 AM
Post: #17




RE: Collaborative collection of useful userRPL snippets
(11172018 11:35 PM)pier4r Wrote: http://www.wiki4hp.com/ is at the moment down for me. This would hurt a lot as I assumed it was a stable site (maybe it is just an hiccup, I hope so) to put effort on it over time. Also OK for me (Spain, 08:00 AM) V. All My Articles & other Materials here: Valentin Albillo's HP Collection 

11182018, 09:17 PM
Post: #18




RE: Collaborative collection of useful userRPL snippets
Ok works for me again. Still it is a point to ask the admin if we can include every now and then a dump of that wiki as well.
Thanks for your reports! Wikis are great, Contribute :) 

01122019, 09:43 PM
Post: #19




RE: Collaborative collection of useful userRPL snippets
please consider this snippet, for an arbitrary base logarithm:
Code: logyx: LOG SWAP LOG / It uses the fact that logb(x) (log x to base b) is == loga(x) / loga(b), where a is any base. I won't add to the wiki myself, since I don't quite get the syntax, and haven't tried it on my 50g yet, only as the equivalent RPN on my DM42. thanks. Cambridge, UK 41CL/DM41X 12/15C/16C DM15/16 17B/II/II+ 28S 42S/DM42 32SII 48GX 50g 35s WP34S PrimeG2 WP43S/pilot Casio, Rockwell 18R 

01132019, 09:39 AM
Post: #20




RE: Collaborative collection of useful userRPL snippets
(01122019 09:43 PM)cdmackay Wrote: please consider this snippet, for an arbitrary base logarithm: I'd guess that LOG uses LN internally, so to make it just that little bit more accurate and faster I'd probably use: Code: \<< LN SWAP LN / \>> The CORDIC algorithms that I know get you the natural logarithm of a number, not the decimal logarithm. Internally, the machine probably calculates \( \frac {ln(x)} {ln(10)} \) with \( ln(10) \) stored as a constant in ROM. At least that's how my floating point library does it To use this as a programmable function in its own right then use local variables: Code: \<< \> b x \<< x LN b LN / \>> \>> Store it as "LOGBX" and you can invoke it as LOGBX(2,8) for example, which should return 3. Need to analyse the function at some point? Make it an algebraic: Code: \<< \> b x 'LN(x)/LN(b)' \>> If you now want to derive that function, you can (on a 48GX): Code: 'LOGBX(B,X)' 'X' ∂ That gets you: Code: '1/X/LN(B)' 

« Next Oldest  Next Newest »

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