# Generating integer partitions with fixed first element

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

• 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. – Roman May 27 at 15:48
• Would you mind writing a code example? I'm not sure I follow – Samuel Crew May 27 at 16:46

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}}

• 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! – Samuel Crew May 27 at 16:54
• 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 – Samuel Crew May 27 at 17:02
• @SamuelCrew, please see the updated version. – kglr May 27 at 17:04
• @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}} – kglr May 27 at 17:09
• Thanks for your help! – Samuel Crew May 27 at 19:37