Mathematicians needed more than the simple four operations: discover how punctuation entered your homework with our factorial calculator. With this simple tool, you will learn:

  • What is the factorial of a number;
  • How to calculate the factorial of a number;
  • How probabilities and factorials are connected; and
  • The factorial, but for addition.

And there will be space for something more!

What is the factorial of a number?

The factorial of a number is the product of all the integer numbers smaller and equal than the number itself.

Factorials appeared spottily during history, with some references to products of subsequent integers in antiquity, in particular related — more or less indirectly — to the computation of combinations. Only in the 15th century did mathematicians start a more detailed analysis of the operator, with the first tables and analysis of properties.

From then on, the factorial imposed itself as a cornerstone of math, particularly combinatorics. Physics makes extensive use of the operator, particularly in the field of statistical mechanics. For reasons we will discover soon, computer scientists use this operator to explain a particular way of writing code.

At the beginning of the XIX century, the mathematician Kramp introduced the notation of an exclamation mark to denote a factorial, opening the gates to a plethora of bad math jokes!

How to calculate the factorial of a number?

To calculate the factorial of a number nn, simply write down the integers number leading up to nn, and multiply them:

n!=123 ⁣. ⁣. ⁣. ⁣(n ⁣ ⁣1)nn! = 1\cdot2\cdot3\cdot\!.\!.\!.\!\cdot(n\!-\!1)\cdot n

This is pretty easy, right? Let's calculate the first five factorials:

1!=12!=12=23!=123=64!=1234=245!=12345=120\begin{align*} 1! &= 1\\ 2! &= 1\cdot2 = 2\\ 3! &= 1\cdot2\cdot3=6\\ 4!&=1\cdot2\cdot3\cdot4=24\\ 5! &= 1\cdot2\cdot3\cdot4\cdot5=120 \end{align*}

Now let's try to calculate the factorial of... 7878. Let's try to do this by hand:

78!=78777675...=6,0067675...=456,45675...\begin{align*} 78! &= 78\cdot77\cdot76\cdot75...\\ &=6,006\cdot76\cdot75...\\ &=456,456\cdot 75... \end{align*}

Ok, too big. Input 7878 in our... exclamation point calculator! 😉

78! ⁣= ⁣11,324,281,178,206,297,831,457,521,158,732,046,228,731,749,579,488,251,990,048,962,825,668,835,325,234,200,766,245,086,213,177,344,000,000,000,000,000,000\begin{align*} 78!\!&=\!11,324,281,178,206,297,\\ &831,457,521,158,732,046,\\ &228,731,749,579,488,251,\\ &990,048,962,825,668,835,\\ &325,234,200,766,245,086,\\ &213,177,344,000,000,000,\\ &000,000,000 \end{align*}

Damn! This is a huge number. Factorial behave like this, exploding quickly and becoming harder and harder to compute. During calculations is better to keep them not expanded, or only in the measure you need to perform some needed simplifications.

Did you see the long series of zeros at the end of 78!78!? We call them *trailing zeros, and they are the result of multiplications by 1010, and occasionally by its prime factors 22 (only when it multiplies 55), and 55 (only when it multiplies even numbers). Note that the second condition automatically implies the first one.

Factorials have a nice property with large uses:

n!=(n1)!n=(n2)!(n1)n\begin{align*} n! &= (n-1)!\cdot n \\ &= (n-2)!\cdot(n-1)\cdot n \end{align*}

And so on. Apart from being fundamental in physics due to many possible approximations when factorials appear in fractions, this property is appreciated by computer scientists since it is a neat example of recursion.

If you tell your computer to multiply a number by the same number minus 11, and to do so giving as argument of the same operation the same number minus 11, and to stop when the number minus 11 is equal to 11, you quickly compute the factorial of a number. In pseudocode, this would look like this:

function factorial(n):if n==0return 1return n×factorial(n1)\footnotesize \begin{align*} &\textcolor{red}{\text{function}}\ \textcolor{blue}{\text{factorial}}(\text{n}):\\ &\qquad\textcolor{black}{\text{if}}\ \textcolor{black}{\text{n==0}}\\ &\qquad\qquad \textcolor{green}{\text{return}}\ 1\\ &\qquad \textcolor{green}{\text{return}}\ \textcolor{black}{\text{n}\times}\textcolor{blue}{\text{factorial}}(n-1) \end{align*}

The function obviously returns n!n!.

What is the factorial of 0?

The factorial of 00 is tricky. Take the definition of factorial, and apply it to this number:

0!=?0! = ?

Yes, it's kinda broken. We use the following convention:

0!=10! =1

In the next section, we will see why it makes sense!

Applications of the factorial formula

The factorial formula has a neat interpretation as the number of possible ways to arrange a set of nn objects (permutation). If you have five friends, you can create 5!=1205!=120 possible "queues" with them.

Factorials have a fundamental role in the definitions of combinations, too: the binomial coefficient defines how many ways to arrange nn objects in groups with size kk there are:

(nk)=n!k!(nk)!\binom{n}{k}=\frac{n!}{k!(n-k)!}

Imagine having nn objects. How many ways to choose all of them are there? One, of course: you simply pick all the objects together. Let's call the binomial coefficient in our help, with k=nk=n:

(nn)=n!n!0!=1\binom{n}{n} = \frac{n!}{n!0!}=1

It is clear that 0!=10!=1.

Factorials often appear in power series, as in the one for the exponential function:

ex=1+x1+x22+x36+...=i=0xii!\begin{align*} e^x&= 1+\frac{x}{1}+\frac{x^2}{2}+\frac{x^3}{6}+...\\ &=\sum_{i=0}^\infty \frac{x^i}{i!} \end{align*}

Factorial, but for addition

What about addition? Can't we define an operator similar to the factorial but for the sum of subsequent numbers, and not multiplication?

The answer is yes: it also got an unofficial name by the famous computer scientist Donald Knuth. The termial operator applied to a number nn is defined as the sum of every positive integer leading to nn. We can (ironically) mark it with a question mark:

n? ⁣= ⁣1+2+3+ ⁣. ⁣. ⁣. ⁣+(n ⁣ ⁣1)+nn?\! =\! 1+2+3+\!.\!.\!.\!+(n\!-\!1)+n

The termial of a number doesn't have as many applications as the factorial. However, a similar concept surfaces when talking of triangular numbers: the succession of those particular numbers (numbers you can fit in an equilateral triangle) follow the terminal:

T1=1T2=1+2=3T3=1+2+3=6T4=1+2+3+4=10T5=1+2+3+4+5=15\begin{align*} T_1 &= 1\\ T_2 &= 1+2 = 3\\ T_3 &= 1+2+3=6\\ T_4&=1+2+3+4=10\\ T_5 &= 1+2+3+4+5=15 \end{align*}

The first 1010 termial numbers are:

1,3,6,10,15,21,28,36,45,551, 3, 6, 10, 15, 21, 28, 36, 45, 55

How to calculate the factorial of a number without going crazy: the Stirling's approximation

Calculating the factorial using discrete integer numbers can be tedious, and the resulting function is hard to plot — and even to imagine. Stirling, a Scottish mathematician, published his finding on the relationship between the logarithm and the factorial operator in 1730. Using the property of logarithms, we can write:

ln(n!)=x=1nln(x)\ln{(n!)}=\sum_{x=1}^n\ln{(x)}

Taking the limit of the sum (the integral), we write the approximate result:

ln(n!)1nln(x)dx=nln(n)n+1\begin{align*} \ln{(n!)} &≈ \int_{1}^n \ln{(x)}dx \\ &= n\cdot \ln{(n)} -n+1 \end{align*}

The factor +1+1 can be neglected for big numbers. You just discovered a life-saving approximation for many physicist!

On the other hand, we use logarithms, e.g., to convert sound intensity to decibels. We have a dedicated tool for that topic so be sure to check it!

Davide Borchia
n
factorial
People also viewed…

Cylinder volume

Use this cylinder volume calculator to find the volume of a solid or a hollow cylinder.

Probability

Use this probability calculator to investigate the odds of different outcomes occurring based on the probabilities of two events.

Schwarzschild radius

Discover the fundamental of black hole physics with our Schwarzschild radius calculator.
main background