RobinHankin / partitions

R package for integer partitions
9 stars 5 forks source link

Add `first...()`, `next...()` and `islast...()` for `setparts()` and `multinomial()` #34

Open jassler opened 1 year ago

jassler commented 1 year ago

I saw that for most partition enumeration functions, there is an equivalent next...() function.

Matrix function first function next function is last function
parts() firstpart() nextpart() islastpart()
diffparts() firstdiffpart() nextdiffpart() islastdiffpart()
restrictedparts() firstrestrictedpart() nextrestrictedpart() islastrestrictedpart()
blockparts() firstblockpart() nextblockpart() islastblockpart()
compositions() firstcomposition() nextcomposition() islastcomposition()
setparts()
multinomial()

Is it possible to add these generative functions for setparts() and multinomial() as well?

jassler commented 1 year ago

Additionaly, without knowing too much about these algorithms, is it possible to generate them in reverse order? I.e., introduce lastpart(), prevpart() and isfirstpart() functions, for example.

RobinHankin commented 1 year ago

jassler, you make some excellent suggestions. The short answer is that I am not sure whether they are easy or even possible to implement. Do you have a use-case I could think about? The package isn't under active development right now, but I do work on it occasionally.

Best wishes, Robin

jassler commented 1 year ago

Hey, thanks for your reply! I am working on my package socialranking and tried to work on a way to generate all possible total preorders given a set of elements (I'm using a combination of compositions() and multinomial(), see here if you're interested).

At around ~21 elements, compositions() becomes too unwieldy. Granted - in my context it's also way too unpractical to use. But, if there's a way to keep it light using something like nextcomposition(), I'd love to offer the light option as well :)

jassler commented 1 year ago

Ah, and for the reverse part, I have the following example from the function I linked to:

#' # (ab ~ a ~ b)
#' # (ab ~ a) > b
#' # (ab ~ b) > a
#' # (a ~ b) > ab
#' # ab > (a ~ b)
#' # a > (ab ~ b)
#' # b > (ab ~ a)
#' # ab > a > b
#' # ab > b > a
#' # a > ab > b
#' # b > ab > a
#' # a > b > ab
#' # b > a > ab

I offer the option to start with linear orders, which is basically just reversing the partitions, or, reversing the order of multinomial(). This should produce the following.

#' # ab > a > b
#' # ab > b > a
#' # a > ab > b
#' # b > ab > a
#' # a > b > ab
#' # b > a > ab
#' # ab > (a ~ b)
#' # a > (ab ~ b)
#' # b > (ab ~ a)
#' # (ab ~ a) > b
#' # (ab ~ b) > a
#' # (a ~ b) > ab
#' # (ab ~ a ~ b)