19
$\begingroup$

I'm trying to solve hard combinatorics that involve complicated factorials with large values.

In a simple case such as $8Pr = 336$, find the value of $r$, it is easy to say it equals to this: $$\frac{8!}{(8-r)!} = 336.$$

Then $(8-r)! = 336$ and by inspection, clearly $8-r = 5$ and $r = 3$.

Now this is all and good and I know an inverse function to a factorial doesn't exist as there is for functions like sin, cos and tan etc. but how would you possibly solve an equation that involves very large values compared to the above problem without the tedious guess and checking for right values.

Edit: For e.g. if you wanted to calculate a problem like this (it's simple I know but a good starting out problem) Let's say 10 colored marbles are placed in a row, what is the minimum number of colors needed to guarantee at least $10000$ different patterns? WITHOUT GUESS AND CHECKING

Any method or explanation is appreciated!

  • 3
    Stirling approximation.2017-01-01
  • 0
    I have seen some literature online about finding the inverse of the Gamma Function. You may consider looking into that.2017-01-01
  • 0
    Do you have a link?2017-01-01
  • 1
    "In a row" would seem to imply that "blue, red, red, red, red, red, red, red, red, red" and "red, blue, red, red, red, red, red, red, red, red" are different patterns. If so, factorials are not applicable. Of course there are _other_ combinatorial problems that involve large factorials to which your question still applies.2017-01-01
  • 0
    Actually you could use factorials for that question, except with identical elements....2017-01-01
  • 0
    http://math.stackexchange.com/questions/18362/is-there-an-inverse-gamma-gamma-1-z-function2017-01-01
  • 1
    FWIW, I posted a Python 2 function that uses Stirling's approximation & the Newton-Raphson method to invert log factorial [here](http://math.stackexchange.com/a/1295561/207316).2017-01-01
  • 0
    For your add-on question, if there are $n$ colors there are $n^{10}$ patterns. We don't need factorials for this, but you want $n^{10} \gt 10^5$ or $10 \log_{10}n \gt 5, \log_{10}n \gt 0.5, n \gt 3.16$, so we need $4$ colors.2017-01-01
  • 0
    @RossMillikan It's $10^4$, not $10^5$.2017-01-01
  • 0
    @TheNumberOne: you are right, I miscounted the zeros. The same approach works. Now we need $\log_{10} n \gt 0.4, n \gt 2.51$, so we need $3$ colors2017-01-01
  • 0
    The answer is actually 4....2017-01-01
  • 0
    Related: https://math.stackexchange.com/questions/1413411/solve-the-factorial-equation-x-c, https://math.stackexchange.com/questions/61755/2017-01-02
  • 0
    @RossMillikan the answer is 42017-01-02
  • 1
    @TripleA, why do you say the answer is $4$? There is nothing wrong in Ross Millikan's analysis for the add-on question as it is stated: $3^{10}=59{,}049\gt10{,}000$. So unless you have some nonstandard definition of what's required for two patterns to be considered "different," the answer is $3$.2017-01-03
  • 0
    @BarryCipra This is an identical elements case. $3^{10}$ doesnt work. The maximum number of ways you can obtain with $3$ colours for e.g. red, blue, yellow is $3$ reds, $3$ blues, $4$ yellows so $\frac{10!}{3!\times3!\times4!}$ which is less than 10000 unfortunately2017-01-03
  • 0
    @BarryCipra What I mean is that let's say for example in the word WOOL, when calculatinG number of ways of ordering the letters we divide by 2! to account for the repeated letter O2017-01-03
  • 1
    @TripleA, ah, I see what you mean now. It would help to edit the add-on question to clarify that the different patterns must all come from a *single* choice of $10$ marbles of various diffferent colors. Both Ross and I interpreted it as meaning that each pattern is simply an assignment of an allowed color to each marble.2017-01-03
  • 0
    @BarryCipra I don't understand how you and Ross interpreted the question but since more than one person has interpreted differently to what I intended, I'm should edit it, except I don't know what to change it to. It would be great if you could do so :)2017-01-03
  • 0
    I don't see anything in the question or the other answers suggesting that there is any restriction on the number of marbles of each color. If you insist that the colors be distributed as evenly as possible, the question is solvable, but it is a different question. Rereading the question, I can see that you are thinking of a particular set of $10$ marbles that you can order in $10^4$ ways and yes you then need four colors so that $2,2,3,3$ of each gives $10!/2!/2!/3!/3!=100800 \gt 10^4$ (even $10^5$)2017-01-03
  • 0
    @RossMillikan There is no restriction but the more you distribute them evenly, the more ways you are going to get. Also, what I'm looking for is a way to solve the question without guessing and checking, for the instance of large numbers lets say $10^{12}$ ways with 50 marbles.2017-01-03

5 Answers 5

14

I just wrote this answer to an old question. Using $a=1$, we get a close inverse for the factorial function: $$ n\sim e\exp\left(\operatorname{W}\left(\frac1{e}\log\left(\frac{n!}{\sqrt{2\pi}}\right)\right)\right)-\frac12\tag{1} $$

  • 1
    And I just commented about it a few minutes ago ! Funny coïcidence !2017-01-01
  • 1
    Just to add a small detail, robjohn's solution is **strictly exact** if we use $$n=\left\lceil e^{W\left(\frac{\log \left(\frac{n!}{\sqrt{2 \pi }}\right)}{e}\right)+1}-\frac{1}{2}\right\rceil$$2017-01-02
  • 1
    @ClaudeLeibovici: if we know that $n$ is an integer. This is also a good inverse for $\Gamma(n+1)$. $$n\sim e\exp\left(\operatorname{W}\left(\frac1{e}\log\left(\frac{\Gamma(n)}{\sqrt{2\pi}}\right)\right)\right)+\frac12$$ is an approximate inverse for $\Gamma(n)$.2017-01-02
  • 0
    It is so beautiful !2017-01-02
9

By Stirling's formula

$$n! \sim \sqrt{2\pi n} \left({\frac{n}{e}}\right)^n $$

So we can given a large $n!$ we can attempt to numerically solve,

$$n!=\sqrt{2\pi x} \left({\frac{x}{e}}\right)^x$$

For $x$ by Newton's method to get an approximate inverse.

The function $\mathbb{N} \to \mathbb{N}$ given by $f(n)=n!$ is increasing. Also,

$$\sqrt{2\pi}n^{n+\frac{1}{2}}e^{-n} \leq n! \leq e n^{n+\frac{1}{2}}e^{-n}$$

So by numerically solving $n!=\sqrt{2\pi}x^{x+\frac{1}{2}}e^{-x}$ and $n!=ex^{x+\frac{1}{2}}e^{-x}$ we can find bounds for $n$.

6

For equations involving large factorials, I find the elementary inequalities $(n/e)^n < n! < (n/e)^{n+1}$ often useful.

Once these have been used, you can use Stirling's approximation.

These can be proved by induction from the elementary inequalities $(1+1/n)^n < e < (1+1/n)^{n+1}$.

  • 2
    So let's say 10 coloured marbles are placed in a row for example, what is the minimum number of colours needed to guarantee atleast 10000 different patterns?2017-01-01
3

Would you be fine with an algorithm instead of a mathematical function?

Solve $nPx = p$ for $x$:

x = 0
while p > 1:
    p /= n
    n--
    x++
return x

Solve $xPr = p$ for $x$:

x = r
while p > 1:
    x++
    p /= x
return x

Solve $x!=y$ for $x$:

x = 1
while y > 1:
    x++
    y /= x
return x

Your example problem can be modeled without the factorial function pretty easily. I'm assuming two marbles with the same color are indistinguishable, that we have at least 10 marbles of each color, and that the order of the marbles matters:

$$ x^{10}\ge10000\\ x\ge10000^{1/10}\approx2.512\\ x=3 $$

-1

The inverse function of $y = x!$ means getting x in terms of $y$ , i.e $x =$ the largest number in factorisation of y as a factorial.(Where factorising as a factorial means you divide $y$ by $2$, then $3$ and so on. You stop when you get $1$) For example let $5040 = x! , x = ?$

Factoring $5040$ as a factorial $5040= 7\times 6\times 5\times 4\times 3\times 2\times 1$ , and $7$ is the largest number of that factorial $\implies x = 7$ In your problem $8!/336 = (8 – r)! , r = ?$

$8!/336 = 120$ , let $(8 – r) = x$ , hence $120 = x! , x = ?$

$120 = 5\times 4\times 3\times 2\times 1$, and the largest number of that factorial $ = x = 5 = (8 – r) \implies r = 3.$

  • 0
    Welcome to MSE. Please try to use MathJax -- it makes your answer more readable and increases the chance being read by other users.2018-12-10