Interpretation of multi-exponent x^y^z ($x^{y^z}$ or ${x^y}^z$)

90 Views Asked by At

Is there any generally accepted or written rule specifying the interpretation of a multi-exponent expression written in this simple style (by user, no latex): x^y^z?

It leads to different results on different engines: e.g. 5^2^3 can be interpreted as:

  • $5^{2^3}$ $5^{2^3}$ = 390625
  • or as ${5^2}^3$ ${5^2}^3$ = 15625 (see that interpreted notation on Math StackExchange seems almost the same)

Interpretation examples:

Interpretation of Google, WolframAlpha, Bing, Yahoo is right associative: $x^{y^z}$

Interpretation of Windows Calculator / Samsung Calculator / Mac Spotlight is the second one (left associative): ${x^y}^z$ (equals to $x^{y \cdot z}$)

On my CASIO fx-85ES calculator when I click [num] [pow] [num] [pow] [num] result is the first one: $x^{y^z}$

Now I see on Math StackExchange that if I write $x^y^z$ it will raise an error "Double exponent: use braces to clarify". enter image description here However I do not know any other latex validator which will raise an error like this.

My observation so far shows that most search engines choose the first way $x^{y^z}$ and most calculator apps choose the second way as sequential interpreting from left to right $x^{y^z}$.

3

There are 3 best solutions below

0
On BEST ANSWER

According to Wikipedia Operator associativity page: "...for an exponentiation operator (if present) [source] and Knuth's up-arrow operators there is no general agreement."

There is a list of implementations (right- vs left-associative) across computer languages, available in the source that Wikipedia mentions.

Comparative table:

| Interpreter           |   | Expon. assoc.     |
|-----------------------|---|-------------------|
| Bash                  |   | Right-associative |
| Python                |   | Right-associative |
| Ruby                  |   | Right-associative |
| C++                   | ! | Left-associative  |
| -- Search engines: -------------------------- |
| Google, Bing, Yahoo   |   | Right-associative |
| WolframAlpha          |   | Right-associative |
| -- Spreadsheets: ---------------------------- |
| MS Excel              | ! | Left-associative  |
| Google Sheets         | ! | Right-associative |
| -- Other: ----------------------------------- |
| Matlab                | ! | Left-associative  |
| Windows, Samsung Calc.| ! | Left-associative  |
| Mac Spotlight         | ! | Left-associative  |
| Hand-held calculators | ! | Varies            |
                 ! means be careful

x^y^z can be also written as $x\uparrow y\uparrow z$. In both cases, the interpretation is ambiguous.

Because we can rewrite the statement after left-assoc. interpretation ${x^y}^z$ as $x^{y \cdot z}$ we can assume that this behavior is not what a regular user wants because he can write directly $x^{y \cdot z}$. From this point of view, it seems that right-associative approach is "better". I do not say more correct because we have no general rule/agreement for that.

There is also a mnemonics called PEMDAS/BEDMAS/BODMAS/BIDMAS (depends in countries). It calls us we should solve Brackets > Orders (e.g. powers, square roots) > Division > Multiplication > Addition > Subtraction. According to this mnemonics we should proceed from top to down for powers (right-association).

Negation vs exponentiation

There is also one more important problem you can face in this context: variable negation or exponentiation first? [source]

  • Negation first: $-2^2$ = 4
  • Exponentiation first: $-2^2$ = -4

Comparative table:

| Interpreter           |   | Neg. or Expon. first |
|-----------------------|---|----------------------|
| Bash                  | ! | Negation             |
| Python                |   | Exponentiation       |
| Ruby                  |   | Exponentiation       |
| -- Search engines: ----------------------------- |
| Google, Bing, Yahoo   |   | Exponentiation       |
| WolframAlpha          |   | Exponentiation       |
| -- Spreadsheets: ------------------------------- |
| MS Excel              | ! | Negation             |
| Google Sheets         | ! | Negation             |
| -- Other: -------------------------------------- |
| Matlab                |   | Exponentiation       |
| Hand-held calculators | ! | Varies               |
                 ! means be careful

Conclusion

However it seems that the right-associative approach has more logical bases, we do not have any official rule that says it is right/wrong approach.

So since you know that a definition of the notation is missing, you should always use braces (as StackExchange parser also recommends) to avoid unexpected results.

2
On

Well, exponentiation is right associative, i.e., $x\uparrow y\uparrow z$ means $x\uparrow (y\uparrow z)$, which equals $x^{(y^z)}$.

0
On

Notice that

$$(x^y)^z$$ is equivalent to $x^{yz}$ so there would be little point writing

$$x^{y^z}$$ which would have that meaning.