Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Strange behavior with comment
Replies: 0

 Virgil Stokes Posts: 77 Registered: 3/16/06
Strange behavior with comment
Posted: May 6, 2011 6:34 AM

The following gives an error,

m = 4;
k = 3;
IntegerPartitions[ m, {k}]; (* Get all integer partitions that are exactly of
length k *)
Permutations /@ %; (* Get all permutations of the integer partitions *)
Flatten[%, 1] (* Flatten the list *)
Apply[Multinomial, %, {1}] (* Apply Multinomial to each element of the list % *)
ns = Plus @@ %

Flatten::normal: Nonatomic expression expected at position 1 in Flatten[3,1]. >>

Flatten[3, 1]

However, if I remove the comment from the entry in the line before Flatten, then
it gives the correct results,

m = 4;
k = 3;
IntegerPartitions[m, {k}]; (* Get all integer partitions that are exactly of
length k *)
Permutations /@ %;
Flatten[%, 1] (* Flatten the list *)
Apply[Multinomial, %, {1}] (* Apply Multinomial to each element of the list % *)
ns = Plus @@ %

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

{12, 12, 12}

36

Why does this happen?