1
$\begingroup$

I want to create a function PartSet[N_,M_] of two positive integer variables which outputs a list of all pairs of integer partitions for all integers up to $M$ satisfying the two conditions:

  • In a tuple of partitions, they can certainly be partitions of a different integer, but they must have the same length. For example, {{1,3},{3,5}} is a valid pair of a partition of $4$ and $8$, respectively.
  • In either partition of a tuple, no number can appear more than $N+1$ times. For example, when $N=2$ the tuple {{1,2,2,2,2,4},{5,6}} should not appear in the list because in one of the partitions $2$ appears more than $3$ times.

(The only role of the $M$ is just that on a computer, we can't have an infinite list of partitions of arbitrarily big integers, so I'm just going to set $M$ to be big enough for my application, e.g. maybe $30$ or so.)

Can anyone help me out with this?

My schematic idea is as follows. First create a function Part1[M_] which outputs a list of all partitions of integers up to $M$. This must be very simple, but I don't know how to do a union over a variable number of lists! Then make Part2[N_,M_] which outputs the list Part1[M] but where you eliminate from the list any partition where a number is repeated more than $N+1$ times. Of course you can then take the Cartesian product to get my pairs of partitions. And finally, eliminate pairs where the two partitions have different lengths. My biggest obstacle here is removing things from lists based on some possibly complicated conditions.

$\endgroup$

1 Answer 1

2
$\begingroup$

Here is a quick and dirty code that should do what you want:

For an example we choose:

n = 2; m = 8;

Then:

t = IntegerPartitions[m]; (*all partitions*)
t = Sort[t, Length[#1] < Length[#2] &]; (*sort them according to their length*)
t = Select[t, AllTrue[Flatten[(Tally[#])[[All, 2]]], # <= n + 1 &] &]; (*delete partitions with where the same number appears more than n+1 times*)
t = SplitBy[t, Length]; (*assemble partitions with the same length*)
t = Select[t, Length[#] > 1 &]; (*eliminate partitions with only 1 elelemt*)
t = Subsets[#, {2}] & /@ t; (*create all pair of partitions*)
ColumnForm /@ t  (*display the result*)

enter image description here

$\endgroup$
2
  • $\begingroup$ Thanks! That's almost exactly what I'm hoping for. Maybe I was unclear in the OP, but the list should include tuples where the two partitions are possibly of different integers no bigger than $m$. So I believe all I need to do to your code is change the initial t to include all partitions of integers up to $m$. Is there a trivial way of doing this kind of union over a variable number of sets? $\endgroup$
    – Benighted
    Commented May 23, 2022 at 1:11
  • $\begingroup$ Actually, I believe I figured this out. Thanks a lot for your help! $\endgroup$
    – Benighted
    Commented May 23, 2022 at 2:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.