Why does 0! = x^0?

If you’ve ever taken a class in algebra or statistics, you would probably know from memory that and (for any real number ). But why?

0! as a base case

The factorial 0! is weird.

We can illustrate by determining the number of ways to arrange the elements of an empty set . Since there are no elements, there is only 1 possible set: . We usually use the factorial function when counting the number of permutations of a given set; so, it holds that .

We formally define the factorial of an integer as . But if , where does the 1 come from? One way to think about why is through the concept of it being a base case for a recursive factorial function:

def factorial(x):
  if x == 0:
    return 1
  else:
    return x * factorial (x - 1)

If the definition of factorial was , then the factorial of any number would be equal to 0. So, as notion we can assume that in order to delineate the final term of any given factorial such that it behaves accordingly.

x^0 as a base case

The product is even weirder.

We can’t illustrate as easily as we could with . We’re usually taught that a number raised to an exponent is simply multiplied by itself times. But how do we multiply something times? Isn’t that just the absense of any quantity: 0?

Again, it might easier to think of raising a number as an exponent as a recursive function:

def exponent(x, n):
  if n == 0:
    return 1
  else:
    return x * exponent (x, n - 1)

Given that this function works, since we know since , the exponentiation can be rewritten as . So, we can now think of exponentiation as multiplied by a total of times.

Finally, the exponentiation of makes sense since 1 is being multiplied by a total of times - which is 1! (the exclamation point here is simultaneously a factorial and my excitement).

Working backwards with factorials

Applying the recursive logic above, we can now just take an example to see why this works with factorials. This is easy to see since by definition, . Taking as an example:

And finally,

Now, that deserves an exclamation point.

Working backwards with exponents

Applying similar logic, we can do the same thing for the factorial function. Let’s take my favourite number: 2.

Working backwards, we can also say that , or that . Let’s work with this pattern:

And for the final step,

(there’s no exclamation point for me to make a pun about, but I find the exponent example much cooler because made no sense to me logically)

Why does this matter?

Although this blog post may seem to be about number theory and algebra, the examples of factorial and exponents illustrate the importance of thinking about edge scenarios. Base cases and their respective functionalities are extremely useful in both computer science and mathematics thanks to the elegance of recursive functions.

Just don’t go around throwing (!) all over your algebra!


Search

    Table of Contents