01

Why an inverse factorial needs gamma

The factorial is defined only for whole numbers: 4! = 24, 5! = 120. Between those two values there is no integer answer at all. To get a smooth inverse, mathematics extends the factorial to real arguments through the gamma function, with n! = Γ(n + 1).

Extensionn! = Γ(n + 1)  for every real n > −1

Gamma is the unique smooth function that agrees with the factorial at every integer and satisfies Γ(n+1) = n·Γ(n). Inverting it gives a real-valued n for any x ≥ 1.

02

Reading the two answers

The tool reports both the continuous solution and the nearest integer, because which one you want depends on the question.

Continuous versus integer answers
xContinuous nNearest integerThat integer's factorialRelative error
244.00004240%
1004.8926512017%
1205.000051200%
362880010.00001036288000%

When the relative error is large — as it is for x = 100 — no integer factorial matches, and reporting 5 without qualification would be misleading. The warning line says so explicitly.

03

Worked example

For x = 120, the solver finds n = 5.0000 exactly: Γ(6) = 120. The nearest integer is 5 and the relative error is zero.

For x = 100, the solver finds n ≈ 4.8926. That is a legitimate answer to “what number, when factorialised continuously, gives 100?” — but it is not an integer, and the nearest integer's factorial overshoots by about 17%.

04

Where inverse factorials appear

  • Combinatorics — working out how many items a permutation count implies, such as how large a set gives a million orderings.
  • Algorithm analysis — inverting factorial runtime bounds to find the largest input size that fits a time budget.
  • Probability — Stirling's approximation inverted gives quick estimates of n from large factorial expressions.
  • Numerical stability — log-gamma is used instead of gamma for large n, and the inverse is solved in log space for the same reason.
05

Why the gamma function is needed

The factorial is defined only for whole numbers: 5! is 5·4·3·2·1. That definition cannot be extended to 5.5 without a new function, and the gamma function is the standard extension.

The continuous extensionΓ(n) = (n − 1)! for integer n
Γ(z + 1) = z·Γ(z) for all z > 0

The shift by one is a historical annoyance rather than a mathematical necessity. It means Γ(5) = 24, not 120 — the factorial of 5 is Γ(6). Once you know the offset, everything else follows, and the recurrence Γ(z+1) = zΓ(z) is what makes the function smooth between the integers.

This is why an inverse factorial rarely has an exact answer. Only the points where n is a whole number land on a factorial exactly; everywhere else the inverse is a real number between two integers, and the tool reports both the floor and the ceiling so the two readings are visible.

06

Stirling's approximation

For large n the factorial becomes impractical to compute directly, and the gamma function becomes expensive. Stirling's approximation gives the logarithm of the factorial to within a fraction of a percent for n above about 10, which is enough for almost every application.

Stirling, in log formln n! ≈ n·ln n − n + ½·ln(2πn)
How good is the approximation?
nn!Stirling estimateRelative error
5120118.021.65%
103 628 8003 598 6960.83%
202.43 × 10¹⁸2.42 × 10¹⁸0.42%
503.04 × 10⁶⁴3.04 × 10⁶⁴0.17%

The error falls as 1/(12n), so it halves every time n doubles — slow convergence but relentless. In statistical mechanics and information theory, where n is often 10²³, the approximation is exact for all practical purposes.

For an inverse factorial this matters in the other direction: it lets you solve n! = T for large T analytically rather than by search, since ln T ≈ n ln n − n is invertible with the Lambert W function.

?

Frequently asked questions

What is the inverse factorial of 120?

5, because 5! = 120. The tool reports 5.0000 and confirms that 5! equals 120 exactly.

What if the value is not a factorial?

You still get a continuous answer through the gamma function, plus the nearest integer and the relative error so you can judge whether rounding is defensible.

Why is the answer sometimes not a whole number?

Because the factorial only produces a sparse set of values. Most numbers fall between two factorials, so the exact inverse is fractional.

What is the largest value this can handle?

The tool works in log space, so it handles very large inputs. Beyond about 170! the result exceeds double precision, but log-gamma keeps the inverse stable well past that.

Is 0! equal to 1?

Yes, by convention — there is exactly one way to arrange nothing. That is why the domain here starts at 1 rather than 0.