# How to generate a list of all lists of known objects obeying some constraints

Let PlanePartitions[m_Integer] be a certain list of objects that I'm able to produce for positive integers $m$, concretely the list of all 3d partitions of a given dimension $m$ (so object means a 3d partition).

For a fixed positive integer $n$, I'd like to build a function f[k_] of a positive integer $k$ that gives as output the list of all possible $n$-tuples $\{a_1,..a_n\}$ built out of objects $a_i \in \operatorname{PlanePartitions}[m_i]$ with the constraint that $\sum_{i=1}^n m_i = k$, including the case when some of the $a_i$ are empty objects, $a_i=\emptyset$, contributing $m_i=0$ to the sum, and considering the ordering meaningful, namely a tuple $\{...a_i,a_j...\}$ is distinct from the one with $a_i$ and $a_j$ exchanged if $a_i \neq a_j$.

Any idea how to do that?

Edit1: the function PlanePartitions[m_Integer] is defined in http://mathworld.wolfram.com/PlanePartition.html

Edit2: here's a first attempt, but I'm having some trouble with the empty case.

f[1, k_] := {#} & /@ PlanePartitions[k]
f[n_, k_] := f[n, k] = Flatten[Table[Flatten[Outer[Prepend[#2, #1] &, PlanePartitions[r], f[n - 1, k - r],1,1], 1], {r, 0, k}], 1]


Example: there are three 3d partitions of dimension 2 (call them $a$,$b$,$c$), one of dimension one (call it $W$), and one of dimension zero (the empty one, call it $E$); the desired function, say for $n=2$ and $k=2$, should produce a list of the form f[2]={{E,a},{E,b},{E,c},{a,E},{b,E},{c,E},{W,W}}}

• It's always helpful to provide a concrete, simple example. Feb 7, 2018 at 22:48
• Never use upper-case letters to name a variable—*especially* $N$, as this is a protected function in Mathematica. Also, give code and examples. Feb 7, 2018 at 22:53
• @jj_p: It is very poor style to use any upper-case-initial variable names, such as NN or A. Feb 7, 2018 at 23:00
• Did you try downloading the Mathematica notebook on the mathworld page? It contains a definition of PlanePartitions. Feb 7, 2018 at 23:26
• This is why I asked you to provide a concrete, simple example. Give an example input, and the desired output so that there is no confusion about what you want. Feb 7, 2018 at 23:29

Here is how I would do it:

g[n_,k_] := With[
{
parts = Catenate @ Map[Permutations] @ PadRight[
IntegerPartitions[k, n],
{Automatic, n}
],
tups = PlanePartitions /@ Range[0, k]
},

Catenate @ Map[Tuples[tups[[##]]]&][parts + 1]
]


PlanePartitions[k_] := PlanePartitions[k] = Array[Subsuperscript[a, k, #]&, RandomInteger[{1,4}]]

r1 = f[10,7]; //AbsoluteTiming
r2 = g[10,7]; //AbsoluteTiming

Sort@r1 == Sort@r2


{6.48359, Null}

{1.97131, Null}

True

• My attempt above works, provided one redefines PlanePartitions[0] as {{{ }}}.
– jj_p
Feb 8, 2018 at 4:29