3
$\begingroup$

I'm trying to generate all integer partitions where the first entry is a fixed number i.e. all young diagrams with first row/column fixed. I'm aware of the function IntegerPartitions[n] and I could generate all partitions of say $n^2$ or less and then only keep the ones with a given first element but I'm wondering if there is a more efficient way to achieve this.

Thanks

$\endgroup$
  • 2
    $\begingroup$ You could subtract the fixed first element from $n$ and then look for integer partitions of what is left. At the end, prepend the fixed first element to all partitions thus found. $\endgroup$ – Roman May 27 at 15:48
  • $\begingroup$ Would you mind writing a code example? I'm not sure I follow $\endgroup$ – Samuel Crew May 27 at 16:46
5
$\begingroup$

Roman's suggestion combined with using the third argument of IntegerPartitions to restrict the result to partitions that involve only numbers below the first number:

ClearAll[f]
f[n_, k_] := Prepend[#, k] & /@ IntegerPartitions[n - k, All, Range[k]]
f[n_, k_, l_] := Prepend[#, k] & /@ IntegerPartitions[n - k, {l - 1}, Range[k]]

f[6, 3]

{{3, 3}, {3, 2, 1}, {3, 1, 1, 1}}

f[6, 3, 3]

{{3, 2, 1}}

f[10, 4]

{{4, 4, 2}, {4, 4, 1, 1}, {4, 3, 3}, {4, 3, 2, 1}, {4, 3, 1, 1, 1}, {4, 2, 2, 2}, {4, 2, 2, 1, 1}, {4, 2, 1, 1, 1, 1}, {4, 1, 1, 1, 1, 1, 1}}

f[10, 4, 3]

{{4, 4, 2}, {4, 3, 3}}

$\endgroup$
  • $\begingroup$ Thanks a lot for your answer. I realised I actually explained the problem a big ambiguously in my post - I was looking for partitions with a fixed first element and a fixed length. I.e inputting 3 should return {3,3,3},{3,3,2},{3,3,1},{3,2,2},{3,2,1},{3,1,1}. But the third argument of InterPartitions is what I was missing to achieve this so thanks! $\endgroup$ – Samuel Crew May 27 at 16:54
  • $\begingroup$ Actually that still doesn't quite do the job. In the example above I'd want something that generates all partitions of 3^3 or less using only 1,2,3 $\endgroup$ – Samuel Crew May 27 at 17:02
  • $\begingroup$ @SamuelCrew, please see the updated version. $\endgroup$ – kglr May 27 at 17:04
  • $\begingroup$ @SamuelCrew, you can use the three-argument form of f as follows: Join @@ (f[#, 3, 3] & /@ Range[3, 9]) gives {{3, 1, 1}, {3, 2, 1}, {3, 3, 1}, {3, 2, 2}, {3, 3, 2}, {3, 3, 3}} $\endgroup$ – kglr May 27 at 17:09
  • $\begingroup$ Thanks for your help! $\endgroup$ – Samuel Crew May 27 at 19:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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