Skip to content

Factorial ​

The product of the positive integers up to n, written n!.

✓ checked against that system · ! checked, with disagreements (hover a chip)WikipediaFactorialMathWorldFactorialWikidataQ120976Encyclopedia of MathematicsFactorialnLabfactorialBritannicatopic/factorialDLMF5.2FungrimFactorial✓Fungrim entryOEISA000142Wolfram LanguageFactorial!mathlib4Nat.factorialRosetta CodeFactorial
Factorial(n)n!n!, the product of the integers from 1 to n.
SageMathenumeratio_factorial(n)SymPyfactorial(n)mpmathfactorial(n)Oscarfactorial(ZZ(n))Juliafactorial(ZZ(n))Rustfactorial(n)
Typed signatures
TypePackageApplies
(complex | infinity) -> numbercompute-enginealways
(complex | infinity) -> numbernumber-theoryreplaces compute-enginealways

Domain: Combinatorics

Details
  • 0!=10! = 1 by convention, the empty product.
  • Recurrence: n!=n (n−1)!n! = n\,(n-1)!.
  • Extends to non-integers via the Gamma function, n!=Γ(n+1)n! = \Gamma(n+1), so half-integer factorials involve π\sqrt{\pi}.
  • Grows faster than any exponential; Stirling's approximation n!∼2πn (n/e)nn! \sim \sqrt{2\pi n}\,(n/e)^n describes the asymptotics.
  • compute-engine returns ComplexInfinity at negative integers, the poles of Gamma, rather than leaving the expression unevaluated.

Plot

ComplexPlot
real slice

Examples

Basic #
live ↗
In5!5!Out120120
live ↗
In6!6!Out720720

The empty product is 1 by convention

live ↗
In0!0!Out11
live ↗
In10!10!Out3 628 8003\,628\,800

Threads element-wise over a list

live ↗
In[1,2,3,4]!\bigl\lbrack1, 2, 3, 4\bigr\rbrack!Out[1,2,6,24]\bigl\lbrack1, 2, 6, 24\bigr\rbrack
Scope #

n!(n−1)!\frac{n!}{(n-1)!} simplifies to nn under Simplify; plain evaluation leaves the ratio as it stands

live ↗
InSimplify(n!(n−1)!)\mathrm{Simplify}(\frac{n!}{(n-1)!})Outnn

Real arguments evaluate as Γ(n+1)\Gamma(n+1)

live ↗
In3.5!3.5!Out11.631 728 396 567 45711.631\,728\,396\,567\,457

Negative non-integers are defined too: (−2.5)!=Γ(−1.5)(-2.5)! = \Gamma(-1.5)

live ↗
In(−2.5)!(-2.5)!Out2.363 271 801 207 3532.363\,271\,801\,207\,353

Complex arguments: (1+i)!=Γ(2+i)(1+i)! = \Gamma(2+i)

live ↗
In(1+i)!(1+i)!Out(1+i)!(1+i)!

(−12)!=Γ ⁣(12)=π\left(-\frac12\right)! = \Gamma\!\left(\frac12\right) = \sqrt{\pi}, kept exact (the float comes from N)

live ↗
In(−12)!(-\frac{1}{2})!Out(−12)!(-\frac{1}{2})!

∞!=∞\infty! = \infty

live ↗
In∞!∞!Out∞∞
Applications #

The number of ways to arrange 8 distinct books on a shelf

live ↗
In8!8!Out40 32040\,320
Properties #

Recurrence: n!=n (n−1)!n! = n\,(n-1)!

live ↗
In5!=5×4!5!=5×4!OutTrue\mathrm{True}

Extends to non-integers via the Gamma function: (12)!=Γ ⁣(32)=π2\left(\frac12\right)! = \Gamma\!\left(\frac32\right) = \frac{\sqrt{\pi}}{2}

live ↗
In(12)!(\frac{1}{2})!Out(12)!(\frac{1}{2})!

n!=Γ(n+1)n! = \Gamma(n+1). See Gamma

live ↗
In5!=Γ(6)5!=Γ(6)OutTrue\mathrm{True}

The reciprocals sum to ee: ∑k≥01k!=e\sum_{k \ge 0} \frac{1}{k!} = e

live ↗
In∑k=0∞1k!\sum_{k=0}^{∞}\frac{1}{k!}Outee
live ↗
In∑k=02(((k+2)!)2((2−k)!)2)/(k!)4\sum_{k=0}^2(\frac{((k+2)!)^2}{((2-k)!)^2})/(k!)^4Out7373

Known value · Wolfram MathematicalFunctionData, Factorial, Apéry's numbers

live ↗
In∑k=03(((k+3)!)2((3−k)!)2)/(k!)4\sum_{k=0}^3(\frac{((k+3)!)^2}{((3-k)!)^2})/(k!)^4Out1 4451\,445

Known value · Wolfram MathematicalFunctionData, Factorial, Apéry's numbers

Possible issues #

Negative integers are poles of the Gamma function, so this returns ComplexInfinity rather than staying unevaluated

live ↗
In(−1)!(-1)!Out∞~\tilde∞
Neat examples #

Factorials grow fast: 20!20! already exceeds 2×10182 \times 10^{18}

live ↗
In20!20!Out2 432 902 008 176 640 0002\,432\,902\,008\,176\,640\,000

30!30! has 33 digits and ends in seven zeros

live ↗
In30!30!Out265 252 859 812 191 058 636 308 480 000 000265\,252\,859\,812\,191\,058\,636\,308\,480\,000\,000
About
Examples21
Checked againstWolfram Language 19 agree2 differSageMath 19 agree1 differ1 errorSymPy 20 agree1 errormpmath 16 agree1 errormathlib4 7 agree3 errorOscar 8 agree7 errorJulia 10 agree7 errorRust 10 agree5 error
CrosswalkWikipediaMathWorldWikidataEncyclopedia of MathematicsnLabBritannicaDLMFFungrimFungrim entry ×42OEISWolfram LanguageSageMathSymPympmathmathlib4OscarJuliaRustRosetta Code

Implementation

mappedwolframpackages/oracle/src/mappings.ts
mappedsympypackages/oracle/src/mappings.ts
mappedsagepackages/oracle/src/mappings.ts
mappedoscarpackages/oracle/src/mappings.ts
mappedjuliapackages/oracle/src/mappings.ts
mappedmathlib4packages/oracle/src/mappings.ts
mappedrustpackages/oracle/src/mappings.ts
mappedmpmathpackages/oracle/src/mappings.ts

See also: Binomial, Factorial2, Subfactorial, Pochhammer