List Commands Library for 50g

01282019, 11:47 PM
Post: #401




RE: List Commands Library for 50g
(01272019 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 HP11C nor the HP15C: (10212018 09:03 PM)Thomas Klemm Wrote: Just try this to get 0: 

01292019, 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,M1) 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.


01292019, 06:20 PM
Post: #403




RE: List Commands Library for 50g
(01272019 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. 

01292019, 07:00 PM
(This post was last modified: 01292019 07:01 PM by pier4r.)
Post: #404




RE: List Commands Library for 50g
(01272019 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 :) 

02012019, 08:14 PM
Post: #405




RE: List Commands Library for 50g
(01292019 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. 

02012019, 10:42 PM
(This post was last modified: 02012019 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 :) 

05132019, 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? 

05132019, 03:43 PM
(This post was last modified: 05172019 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 zerobased index of a list element (0255) 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 usersupplied 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. 

05172019, 02:53 PM
(This post was last modified: 05172019 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 zerobased starting position, and is thus already in the lowestorder 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! 

05172019, 09:43 PM
Post: #410




RE: List Commands Library for 50g  
« Next Oldest  Next Newest »

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