List Commands Library for 50g
|
01-28-2019, 11:47 PM
Post: #401
|
|||
|
|||
RE: List Commands Library for 50g
(01-27-2019 10:02 PM)Thomas Okken Wrote: The probability of RAND returning zero is exactly zero. It can't happen. Interestingly enough, this is not the case with neither the HP-11C nor the HP-15C: (10-21-2018 09:03 PM)Thomas Klemm Wrote: Just try this to get 0: |
|||
01-29-2019, 12:16 AM
Post: #402
|
|||
|
|||
RE: List Commands Library for 50g
A quick method to avoid zero (and one which also gives problems) in a pseudo random number generator is to generate uniformly distributed integers over (0,M-1) or (1,M) for some large (prime or power of two or whatever) integer. Then one computed for result X (0<=X<M) the number (2X+1)/2N as either a fraction or a floating point number.
|
|||
01-29-2019, 06:20 PM
Post: #403
|
|||
|
|||
RE: List Commands Library for 50g
(01-27-2019 07:07 PM)pier4r Wrote: About RAND a * b + IP. I used it too at first but it messes up when integers are negative if I am not mistaken. Program has been fixed. Replacing IP with FLOOR is all it took. |
|||
01-29-2019, 07:00 PM
(This post was last modified: 01-29-2019 07:01 PM by pier4r.)
Post: #404
|
|||
|
|||
RE: List Commands Library for 50g
(01-27-2019 06:52 PM)John Keith Wrote: Edited to fix bug that would cause negative values to be off by 1. I am still not convinced. But thanks for the effort! I mean say we have a range of: -5 to 5. When you do RAND a * b + you pick a value, actually, between 0 - eps and -4 - eps (where eps<1). Then you add 5 to it, so one gets mostly positive integers or zero. Am I missing something obvious here? Wikis are great, Contribute :) |
|||
02-01-2019, 08:14 PM
Post: #405
|
|||
|
|||
RE: List Commands Library for 50g
(01-29-2019 07:00 PM)pier4r Wrote: I mean say we have a range of: -5 to 5. When you do RAND a * b + you pick a value, actually, between 0 - eps and -4 - eps (where eps<1). Then you add 5 to it, so one gets mostly positive integers or zero. I don't know, but I just ran the revised program and got a list containing approximately equal numbers of each of the integers from -5 through 5. Try it yourself: run the program with the arguments 1000, -5, 5 then execute LSORT LRPCT on the resulting list to see the stats. |
|||
02-01-2019, 10:42 PM
(This post was last modified: 02-01-2019 10:53 PM by pier4r.)
Post: #406
|
|||
|
|||
RE: List Commands Library for 50g
Ok went debugging your program. I missed some points, not easy to read in the code at glance.
Your 'a' is not the start of the range (intuitively: a is the start and b is the end). Rather a is the size of the range, b is the start of it. Then it is sound yes. edit: added! http://www.wiki4hp.com/doku.php?id=rpl:s...=revisions Wikis are great, Contribute :) |
|||
05-13-2019, 11:36 AM
Post: #407
|
|||
|
|||
RE: List Commands Library for 50g
Hi,
if I found some time, i will try to create a ListExt Library (or a subset) in NewRPL. But I'm afraid about the DOPERM and DOCOMB commands... DavidM, if you read this, what algorithm did you use? |
|||
05-13-2019, 03:43 PM
(This post was last modified: 05-17-2019 02:57 PM by DavidM.)
Post: #408
|
|||
|
|||
RE: List Commands Library for 50g
I ended up spending a lot of time on those, starting down several different algorithmic paths and abandoning ideas at various stages for one reason or another. DOCOMB can be summarized as follows:
Code: create a "mask" that represents the first group of list elements DOPERM is similar, but has an inner loop that steps through each permutation of each combination that is found above. The mask is implemented as a string, with each "character" actually representing a zero-based index of a list element (0-255) for permutations and 0 or 1 for combinations. In order for this approach to perform reasonably, the routines dealing with the mask are all coded in Saturn assembly. There are some RPLish quirks that also had to be dealt with, especially for the user-supplied executable. It has to be "prepped" to convert any references to the special variables (XPRM, XCMB, CRMNT) into locals, since they will default to being globals when the user creates the program. |
|||
05-17-2019, 02:53 PM
(This post was last modified: 05-17-2019 06:03 PM by DavidM.)
Post: #409
|
|||
|
|||
RE: List Commands Library for 50g
Here's a couple illustrative examples of how the masks I described above are used. I'm representing the masks in these examples as a string of numbers separated by spaces for clarity.
Combination Masks Example: a list of 5 items, we want all combinations of 3 Lexicographic stepping for DOCOMB/DOPERM combinations starts with the highest order form and works its way down to the lowest. So the first mask is created with a series of 1s that matches the count of selected elements, followed by 0s for the remainder: 1 1 1 0 0 The mask is then stepped down lexicographically in each iteration of the loop until the lowest order form is found: 1 1 1 0 0 1 1 0 1 0 1 1 0 0 1 ... 0 1 1 0 1 0 1 0 1 1 0 0 1 1 1 The mask for each iteration is applied to the source list such that the resulting selection contains only the elements that correspond to the 1s. So if our source list is: { A B C D E } ...then the resulting combinations that correspond to the iterative masks are: Code: Src List/Mask Resulting Sublist Permutation Masks Example: a list of 4 items The first mask is generated with each index matching its zero-based starting position, and is thus already in the lowest-order form: 0 1 2 3 The mask is then stepped lexicographically upward until the highest order permutation is encountered: 0 1 2 3 0 1 3 2 0 2 1 3 ... 3 1 2 0 3 2 0 1 3 2 1 0 The mask is applied to the source list in a similar fashion to the above description for combinations, but instead of a binary disposition (include/exclude), the mask designates the final positions of each of the source elements in the new list. So if our source list is: { A B C D } ...then the resulting permutation lists that correspond to the designated masks are as follows: Code: Src List/Mask Resulting Permutation Stepping algorithm The heart of all of this is a subroutine I called "NextMask", which takes a mask and a boolean indicating up/down stepping and returns the next mask and a boolean indicating if the new mask is at the high/low extreme. The algorithm is a modified form of this one, with the modifications allowing for up or down stepping. No changes were needed to accommodate combinations and permutations; the exact same algorithm inherently works for both so long as they are formatted as described above. Hope this helps! |
|||
05-17-2019, 09:43 PM
Post: #410
|
|||
|
|||
RE: List Commands Library for 50g | |||
01-18-2021, 06:37 PM
Post: #411
|
|||
|
|||
RE: List Commands Library for 50g | |||
01-18-2021, 10:03 PM
Post: #412
|
|||
|
|||
RE: List Commands Library for 50g
(01-18-2021 06:37 PM)John Keith Wrote: Version 1.3 has been released: ListExt 1.3 Here's a quick rundown of the new commands. Many of the new commands operate identically to GoferLists commands with similar names, but are included in ListExt due to improved performance. Short descriptions of the new commands are listed below, along with the general release notes. As always, complete descriptions and more examples are provided in the documentation that comes with the library. Questions, comments, etc. are always welcome! - David Code: LSCAN - returns a list of results from applying a program with each successive list element given Here's the release notes for this version: Version 1.3.0 January 4, 2021 - Refactored LRMOV to create a subroutine that could be used by other commands - Added checks to the following commands for triggering garbage collection in low memory situations: I→NL NL→I - Small speed improvement for SLST→ - Small speed improvement for LPICK - Negative arguments for LDIST and LSDIV are now allowed; negative indicates quantity of sublists instead of size of each sublist - LSHUF changes - optimized to reduce initial list traversal - reduced subroutine calls during shuffling - SplitMix64 seed now incremented as per standard definition as opposed to using final output of each iteration as the new seed - DOCOMB and DOPERM now accept lists and tagged commands for the user-supplied program to execute - New commands added: LSCAN, LMAP, LXEQ, LDIFF, LINTR, LSUBS, LFILT, LWHL, LDWHL, LTWHL, LCPRD, LTAKE, LDROP, LCOMP, LDLTA, NL→I2 - Updated documentation for new and changed commands |
|||
07-02-2021, 02:52 PM
(This post was last modified: 07-02-2021 04:07 PM by pier4r.)
Post: #413
|
|||
|
|||
RE: List Commands Library for 50g
Awesome a new release! I noticed only now (too little spare time)
Today I had a bit of spare time and I wanted to use LREPL but I noti ed a bit late that it replaces the elements only if there is a match (on the content) and not in the position. What I wanted is something like this: { 1 1 1 1 1 1 1 1 1 1 } @original list { 7 8 } @ positions (rather than matching) { 77 88 } @replacements result: { 1 1 1 1 1 1 77 88 1 1 } I dind't find any similar command in ListExt, am I missing something? Should I do a routine on my own? edit. My solution so far Code:
Wikis are great, Contribute :) |
|||
07-02-2021, 09:41 PM
(This post was last modified: 07-02-2021 09:43 PM by 3298.)
Post: #414
|
|||
|
|||
RE: List Commands Library for 50g
Code: \<< SWAP 2. \<< PUT \>> DOLIST \>> |
|||
07-03-2021, 12:53 AM
Post: #415
|
|||
|
|||
RE: List Commands Library for 50g
(07-02-2021 09:41 PM)3298 Wrote: It works if the SWAP is omitted. Null-tagged ::PUT does not work. <0|ɸ|0> -Joe- |
|||
07-03-2021, 07:55 AM
Post: #416
|
|||
|
|||
RE: List Commands Library for 50g
(07-03-2021 12:53 AM)Joe Horn Wrote: It works if the SWAP is omitted. Null-tagged ::PUT does not work.Oops, apparently I confused the parameter order of PUT with that of UNPICK and ROLLD, where the position parameter is on level 1. Why do they have to be inconsistent like that ... Omitting SWAP is obviously the correct fix here. And bummer about the null-tag. I assume lists won't be accepted as programs either then. Oh well, how about working around this limitation with DTAG? Code: \<< 2. ::PUT DTAG DOLIST \>> |
|||
07-03-2021, 12:44 PM
Post: #417
|
|||
|
|||
RE: List Commands Library for 50g | |||
07-03-2021, 08:23 PM
(This post was last modified: 07-08-2021 11:23 AM by pier4r.)
Post: #418
|
|||
|
|||
RE: List Commands Library for 50g
nice 3298 ! Didn't think of DSUBS (also because I got burned in the past due to debugging difficulties)
added to https://www.hpmuseum.org/forum/thread-10271.html Wikis are great, Contribute :) |
|||
07-04-2021, 06:39 PM
Post: #419
|
|||
|
|||
RE: List Commands Library for 50g
Thanks from me also, 3298.
Here is my variation which allows a single object on level 1 to replace all elements indexed by the list on level2. If level one contains a list, it works just like your program. Code:
For example, if level 1 in Pier4's example is changed to the integer 78, the result will be { 1 1 1 1 1 1 78 78 1 1 }. |
|||
07-04-2022, 05:49 PM
(This post was last modified: 07-04-2022 05:50 PM by pier4r.)
Post: #420
|
|||
|
|||
RE: List Commands Library for 50g
Today while refreshing my PHP (using it on and off, surely less than userRPL), I noticed that there is no similar function like KSORT for PHP arrays (that are like maps). That is, I found no built-in way to say "given an array of integers, order the values, but then please order the other array (containing the indexes) accordingly".
This is how ListExt spoiled me. For reference: https://www.php.net/manual/en/array.sorting.php Wikis are great, Contribute :) |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 5 Guest(s)