On Fri, May 4, 2012 at 11:47 AM, Aaron Meurer <[email protected]> wrote:
> We do have the multinomial_coefficients() function.  Is that the same
> thing as what you want?

from sympy.functions.combinatorial.factorials
binomial(9, 3) -> 84

from sympy.ntheory import binomial_coefficients
binomial_coefficients(9) ->
{(0, 9): 1, (1, 8): 9, (2, 7): 36, (3, 6): 84, (4, 5): 126, (5, 4):
126, (6, 3): 84, (7, 2): 36, (8, 1): 9, (9, 0): 1}

multinomial_coefficients is the same, returning the dictionary; there
isn't a binomial equivalent that just returns a single coefficient.

I think multinomial could work like this:

```
>>> def multinomial(*expos):
...  n = sum(expos)
...  k = len(expos)
...  return multinomial_coefficients(k, n)[expos]
...
>>> multinomial_coefficients(3,8)
{(0, 5, 3): 56, (4, 2, 2): 420, (0, 3, 5): 56, (1, 1, 6): 56, (3, 1, 4): 280, (4
, 4, 0): 70, (0, 4, 4): 70, (0, 1, 7): 8, (1, 0, 7): 8, (6, 2, 0): 28, (3, 4, 1)
: 280, (1, 2, 5): 168, (1, 7, 0): 8, (1, 4, 3): 280, (6, 0, 2): 28, (4, 3, 1): 2
80, (3, 3, 2): 560, (8, 0, 0): 1, (2, 4, 2): 420, (3, 2, 3): 560, (7, 1, 0): 8,
(6, 1, 1): 56, (2, 2, 4): 420, (5, 1, 2): 168, (0, 8, 0): 1, (0, 2, 6): 28, (0,
6, 2): 28, (3, 0, 5): 56, (7, 0, 1): 8, (2, 5, 1): 168, (0, 0, 8): 1, (2, 0, 6):
 28, (2, 6, 0): 28, (5, 0, 3): 56, (2, 1, 5): 168, (1, 6, 1): 56, (4, 1, 3): 280
, (3, 5, 0): 56, (5, 3, 0): 56, (4, 0, 4): 70, (1, 3, 4): 280, (0, 7, 1): 8, (1,
 5, 2): 168, (2, 3, 3): 560, (5, 2, 1): 168}
>>> multinomial(0,5,3) # first one in dict above
56
>>> multinomial(5,2,1) # last one in dict above
168
>>> multinomial(1,1,2,3) # coefficient of a*b*c**2*d**3 in (a+b+c+d)**7
420
>>> multinomial(3,6) # coeff of a**3*b**6 in (a+b)**9
84
>>> binomial(9,3)
84
```

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to