# Factorial Calculator

Created by Davide Borchia
Last updated: Jul 09, 2022

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 $n$, simply write down the integers number leading up to $n$, and multiply them:

$n! = 1\cdot2\cdot3\cdot\!.\!.\!.\!\cdot(n\!-\!1)\cdot n$

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

\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... $78$. Let's try to do this by hand:

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

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

\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!$? We call them *trailing zeros, and they are the result of multiplications by $10$, and occasionally by its prime factors $2$ (only when it multiplies $5$), and $5$ (only when it multiplies even numbers). Note that the second condition automatically implies the first one.

Factorials have a nice property with large uses:

\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 $1$, and to do so giving as argument of the same operation the same number minus $1$, and to stop when the number minus $1$ is equal to $1$, you quickly compute the factorial of a number. In pseudocode, this would look like this:

\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!$.

## What is the factorial of 0?

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

$0! = ?$

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

$0! =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 $n$ objects (permutation). If you have five friends, you can create $5!=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 $n$ objects in groups with size $k$ there are:

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

Imagine having $n$ 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=n$:

$\binom{n}{n} = \frac{n!}{n!0!}=1$

It is clear that $0!=1$.

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

\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*}

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 $n$ is defined as the sum of every positive integer leading to $n$. We can (ironically) mark it with a question mark:

$n?\! =\! 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:

\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 $10$ termial numbers are:

$1, 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!)}=\sum_{x=1}^n\ln{(x)}$

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

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

The factor $+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.