# pow

Learn how to use the exponentiation (^) operator in Notion formulas.
The power (^) operator (also known as the exponentiation operator) allows you to raise a number to a higher power.
1
number[base] ^ number[exponent]
2
pow(number[base], number[exponent])
In technical terms, it raises the first operand to the power of the second operand.
In Notion, the ^ operator has a higher operator precedence than the unaryPlus and unaryMinus operators, and has right-to-left associativity.
You can also use the function version, pow().

## Example Formulas

1
3 ^ 4 // Output: 81
2
3
pow(4,3) // Output: 64
4
5
2 ^ 2 ^ 3 // Output: 256 - evaluates as 2 ^ (2 ^ 3)
• $x^0 = 1$
• $(x^a)^b = x^{ab}$
• $x^{a^b} = x^{(a^b)}$
(not all languages respect this, but Notion does)
• $x^a * y^a = (xy)^a$
• $x^a / y^a = (x/y)^a$
• $x^a * x^b = x^{a+b}$
• $x^a / x^b = x^{a-b}$

### Exponent Associativity

In Notion, the ^ operator has right-to-left associativity, which means that x ^ y ^ z is evaluated as x ^ (y ^ z).
1
4 ^ 3 ^ 2 == 262,144
2
3
4 ^ (3 ^ 2) == 4 ^ 9 == 262,144
4
5
(4 ^ 3) ^ 2 == 64 ^ 2 == 4,096
6
7
// Here's that last one according to the (x^a)^b == x^(ab) "Power Rule":
8
9
(4 ^ 3) ^ 2 == 4 ^ (3*2) == 4 ^ 6 = 4,096
Not every programming and scripting language uses right-to-left associativity for serial exponentiation. Here's a write-up comparing the methods for many popular languages. Even though standard mathematical notation has the "Tower Rule", where
$x^{a^b} = x^{(a^b)}$
(aka: "Work top-down"), the computer science community has not come to a strong consensus on whether x^y^z should be interpreted in the same way.

### Working with Unary Operators

Good to know: Don't want to memorize these precedence rules? Just use parentheses () to make the order of your operations explicit.
In Notion, the unaryPlus operator converts strings and Booleans to numbers, while the unaryMinus operator inverts the sign of its operand.
When combining these operators with the ^ operator in Notion, it's useful to understand the following rules:
1. 1.
The ^ operator has a higher operator precedence than the unary operators. This is opposite to JavaScript's operator precedence! (Though in JavaScript this is irrelevant, because the language doesn't allow for ambiguous unary operator usage in exponentiation).
2. 2.
Notion is smart and will allow for unaryPlus type conversion on the exponent, but will wrap the conversion operation in () automatically.
3. 3.
Notion will not allow for automatic unaryPlus type conversion on the base number - e.g. +"8"^2 will throw a type mismatch error.
4. 4.
If you write a negative exponent into a formula, Notion parses it as a true negative value instead of a unaryMinus (-) operator appended to a number. Your formula will also be re-written to x ^ (-2) so the exponent is explicitly defined as negative.
5. 5.
When using unaryMinus on a base number, Notion will parse it as -(x^y), not (-x)^y. Note that this can result in mathematically incorrect answers depending on your use case - see Negative Base Numbers below.
1
-2 ^ 2 // Output: -4 - Notion parses this as -(2^2)
2
3
4 ^ -2 // Re-written to 4 ^ (-2), outputs 0.0625
4
4 ^ -(2) // Re-written to 4 ^ (-2), outputs 0.0625
5
4 ^ -(-2) // Re-written to 4 ^ (-(-2)), outputs 16
6
7
+"8" ^ 2 // Type mismatch error
8
9
(+"8") ^ 2 // Output: 64
10
11
8 ^ +"-2" // Re-written to 8 ^ (+"-2"), outputs 0.015625
12
13
2 ^ +false// Re-written to 2 ^ (+false), outputs 1

### Negative Base Numbers

If you type -2^4 directly into Notion's formula box, you'll get an output of -16. Assuming you're intending to pass the actual base number -2, this answer is incorrect! The true answer is 16.
Remember that exponentiation is just repeated multiplication of the base number. Therefore:
1
-2^4 == (-2)(-2)(-2)(-2) == (4)(-2)(-2) == (-8)(-2) == 16
So why does -2^4 return -16 in a Notion formula?
This happens because when you type - directly into a Notion formula, you're using the unaryMinus operator. If you type -2, you're not simply typing a negative number into your formula. Rather, you're creating an expression equivalent to -(2).
This distinction is important because exponentiation (^) has a higher operator precedence in Notion than unaryMinus, as noted above.
This means that typing -2^4 is equivalent to -(2^4)!
If your intention is to express a negative base number, you'll need to type (-2)^4 instead.
Negative base numbers passed via a property (e.g. prop("num")) will be evaluated correctly, since they're actually passing a negative value, rather than adding a hard-coded unaryMinus (-) operator to your formula.
1
-2^4 // Output: -16 - Notion parses this as -(2^4)
2
3
(-2)^4 // Output 16 - Notion parses this as (-2)^4
4
5
prop("num") == -2
6
prop("num")^4 // Output: 16 - Notion parses this as (-2)^4
Note: This convention does not apply to all programming and scripting languages. For example, in Microsoft Excel, the formula =-2^4 evaluates to 16, as does =A1^4 where the value of A1 is 2.

## Example Database

The table below shows exponentiation at work in a Notion database.

### "Power" Property Formula:

1
prop("Base") ^ prop("Exponent")
Instead of using hard-coded numbers, I’ve called in each property using the prop() function.