I am trying to compute this formula in Mathematica:

$$ a = \sum_{n=0}^A P_A^{A-n,n} $$

Where A can be any positive number

The problem is that I am unable to find the symbol for permutations with repetition:

$$ P_n^{n_1,n_2,...,n_m} $$

Note: I know that the result is going to be:

$$ a = \sum_{n=0}^A P_A^{A-n,n} = 2^A $$

But I would like to compute it with the "Permutations with Repetition Symbol"


Let's define a function that calculates the number of permutations with repetitions, according to this definition:

$$Pr^{\ a,\,b,\,c,\,...}_{\ n}=\frac{n!}{a!\ b!\ c!\ ...}\ \ \ \ \ \ n=a+b+c+\ ...$$

pr[a__] := Plus[a]! / Times@@ ({a}!)

Then let's see if your sum evaluates symbolically:

Sum[pr[a - n, n], {n, 0, a}]
(* Out: 2^a*)

Look at that! It works!

A more direct route is built in, as @JM mentioned in comments. The number of permutations with repetitions corresponds to the multinomial coefficient, which is implemented in Mathematica as the Multinomial function:

Multinomial[2, 3, 4] == pr[2, 3, 4]    (* True *)

When called with two non-numerical arguments, Multinomial is evaluated to an equivalent Binomial call:

Multinomial[a, b]                      (* Out: Binomial[a + b, b] *)

With more than two non-numerical arguments it returns unevaluated (whereas pr[a, b, c] returns the definition, i.e. (a + b + c)! / (a! b! c!)).

In your case, @JM showed that your result can be obtained as follows:

Sum[Multinomial[a - n, n], {n, 0, a}]  (* Out: 2^a *)
  • 6
    $\begingroup$ I was hoping the OP would supply the definition, but since you have already done so: Sum[Multinomial[a - n, n], {n, 0, a}]. $\endgroup$
    – J. M.'s torpor
    May 12 '20 at 1:15
  • $\begingroup$ @J.M. Thank you. That's certainly much tidier :-) $\endgroup$
    – MarcoB
    May 12 '20 at 1:23
  • $\begingroup$ So, should I accept MarcoB's answer, or the one of J.M.'s? I think both are great $\endgroup$
    – DieDauphin
    May 12 '20 at 4:47
  • $\begingroup$ @Die If Marco edits his answer to include my observation, then accept his answer. $\endgroup$
    – J. M.'s torpor
    May 12 '20 at 5:57
  • $\begingroup$ @DieDauphin I've added J.M.'s Multinomial approach to my answer. $\endgroup$
    – MarcoB
    May 12 '20 at 15:29

For fun (only):

☺ = 1 ## &[(+##)!, 1 ## & @@ ({##}!)^-1] &;

☺[a, b, c]

enter image description here

  • 2
    $\begingroup$ This is so readable to a non-Mathematica user! (But it is fun! :) $\endgroup$ May 12 '20 at 9:53
  • 1
    $\begingroup$ Hehe. I had to copy it into MMA and unravel it. The 1's got me :-) $\endgroup$
    – MarcoB
    May 12 '20 at 15:10

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.