Zero and Negative Exponents
What could or possibly mean? You cannot multiply "zero copies" or "minus three copies" of a number. Yet both have one sensible value, and it is the value that keeps the exponent laws working. This lesson shows where those values come from and where programmers use them.
Follow the pattern
Walk down a list of powers of 2. Each step down the exponent divides by 2:
Continuing the pattern past gives and then fractions. Nothing else would keep the "divide by 2 each step" rule.
The two definitions
For any nonzero number and whole number :
| Rule | Meaning | Examples |
|---|---|---|
| anything (nonzero) to the zero power is 1 | , , | |
| a negative exponent means "one over" | , |
Both follow from the quotient law :
A negative exponent never makes the number negative. is a small positive number. The minus sign in the exponent means "reciprocal", not "negative".
from fractions import Fraction
print("2 ** 0 =", 2 ** 0)
print("2 ** -3 =", 2 ** -3)
print("as a fraction:", Fraction(2) ** -3)
print("10 ** -2 =", 10 ** -2)
print("(2/3) ** -2 =", Fraction(2, 3) ** -2)
print("(-4) ** 0 =", (-4) ** 0)2 ** 0 = 1
2 ** -3 = 0.125
as a fraction: 1/8
10 ** -2 = 0.01
(2/3) ** -2 = 9/4
(-4) ** 0 = 1
Notice that Python returns a float (0.125) for an integer raised to a negative power, because the result is no longer a whole number. Use Fraction when you want the exact .
Note: A fraction to a negative power flips: . So .
What about ?
Zero to a negative power is undefined (, division by zero). The case is a matter of convention. In counting and in most programming languages it is defined as 1, because that makes formulas like polynomials and the binomial theorem work without special cases:
import math
print("0 ** 0 =", 0 ** 0)
print("math.pow(0,0)=", math.pow(0, 0))
try:
print(0 ** -1)
except ZeroDivisionError as e:
print("0 ** -1 ->", type(e).__name__ + ":", e)0 ** 0 = 1
math.pow(0,0)= 1.0
0 ** -1 -> ZeroDivisionError: 0.0 cannot be raised to a negative power
All laws still hold
With these definitions the exponent laws keep working for any integers, positive, zero or negative:
from fractions import Fraction
a = Fraction(3)
for m, n in [(4, -4), (-2, 5), (-1, -2), (0, 6)]:
left = a**m * a**n
right = a**(m + n)
print(f"3^{m} * 3^{n} = {left} 3^({m + n}) = {right}")3^4 * 3^-4 = 1 3^(0) = 1
3^-2 * 3^5 = 27 3^(3) = 27
3^-1 * 3^-2 = 1/27 3^(-3) = 1/27
3^0 * 3^6 = 729 3^(6) = 729
In software
- Metric prefixes are powers of ten with negative exponents: a millisecond is , a microsecond , a nanosecond . Latency dashboards switch between them constantly.
- Binary fractions. Floating-point numbers store values as sums of That is why 0.5 () and 0.375 () are exact in a float but 0.1 is not; see Floating Point.
- Decay and discounting. A learning-rate schedule or an "every step multiply by 0.5" fade is with ; the same value can be written .
- Empty products.
math.prod([])returns 1 for the same reason : multiplying no numbers at all leaves the starting value 1.
Exercises
Exercise 1: Evaluate
Compute , , , and .
Answer
1, , , , 25.
Solution
Exercise 2: Rewrite without negative exponents
Rewrite , , and using only positive exponents.
Answer
, , .
Solution
The negative exponent belongs only to the base right under it. In the 3 is not raised to anything, so only moves to the denominator: . Likewise .
Exercise 3: Simplify
Simplify and give the result as a fraction.
Answer
.
Solution
from fractions import Fraction
print(Fraction(2) ** 5 * Fraction(2) ** -8)1/8
Exercise 4: Time units
A request takes seconds. Write it in milliseconds and in microseconds.
Answer
.
Solution
One millisecond is , so . One microsecond is , so divide by : .
Test yourself
What is ?
- −36
- −12
What is ?
- 1
- 0
- −1
- −12
Which equals ?