X-Git-Url: https://ginac.de/ginac.git//ginac.git?a=blobdiff_plain;f=ginac%2Futils.cpp;h=6935bcd8e1a71fc93b436efc96b4fb8aa09ea2dd;hb=b16d5b34f40c9dcd6bd4f9e1fdeeb65cb1612db3;hp=c83ca643d109812cbdab7221f819d8780edbed0a;hpb=47ecb72dce5ea9c917d1e1e77863c45a8b2b1bba;p=ginac.git diff --git a/ginac/utils.cpp b/ginac/utils.cpp index c83ca643..6935bcd8 100644 --- a/ginac/utils.cpp +++ b/ginac/utils.cpp @@ -4,7 +4,7 @@ * but not of any interest to the user of the library. */ /* - * GiNaC Copyright (C) 1999-2016 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2019 Johannes Gutenberg University Mainz, Germany * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -53,6 +53,19 @@ unsigned log2(unsigned n) return k; } +/** Compute the multinomial coefficient n!/(p1!*p2!*...*pk!) where + * n = p1+p2+...+pk, i.e. p is a partition of n. + */ +const numeric +multinomial_coefficient(const std::vector & p) +{ + numeric n = 0, d = 1; + for (auto & it : p) { + n = n.add(numeric(it)); + d = d.mul(factorial(numeric(it))); + } + return factorial(n).div(d); +} ////////// // flyweight chest of numbers is initialized here: