[Math] Where should concatenation take place in the order of operations

notationrecreational-mathematics

Concatenation being the joining of two integers by their numerals, or, more plainly, just smooshing the numbers together (denoted $a \ || \ b$ .) Examples: $5 \ || \ 2 = 52$, and $20 \ || \ 17 = 2017$.

My question is where do you think concatenation should go in the order of operations? And why?

Or, how would you evaluate $5 \times 1 \ || \ 2 + 4$ ? And why?

  1. $5 \times 1 \ || \ 2 + 4 = (5 \times 1) \ || \ 2 + 4 = 5 \ || \ 2 + 4= 52 + 4 = 56$,
  2. $5 \times 1 \ || \ 2 + 4 = 5 \times (1 \ || \ 2) + 4 = 5 \times 12 + 4= 60 + 4 = 64$.

Edit: I intend on using concatenation in expressions with exponentiation, multiplication/division, and addition/subtraction. No parenthesis, that would be too obvious, since concatenation would probably have to come after parenthesis in the order of operations.

Best Answer

Consider that whenever you write a numeral with more than one digit, that's concatenation, denoted by the empty string, and it always has higher precedence than arithmetic operators. $12+12$ is $24$, not $132$, and $12 \times 12$ is $144$, not $122$. So one argument is that if you're going to give concatenation an alternate symbol, the simplest choice is to keep the precedence the same.

(This is a bit more complicated when multiplication is also denoted by the empty string, in which case for example $3(1+2)$ means $9$, not $33$, and $10x$ means ten times $x$, not $10^{2+\lceil \log_{10}{x} \rceil}+x$. The ambiguity is resolved by making the empty string denote concatenation when both operands are digit strings and multiplication otherwise. But that's not a universal convention, think about those puzzles where you're supposed to solve for the unknown digits, like $10x + y0x = x10$.)

On the other hand it may be more aesthetic to associate precedence with the appearance of the glyph. The double vertical bar I think creates a sense of wide spacing, so it looks like it should be a low precedence operator.

perl has a separate operator for concatenation (.) and it is given a low precedence. Personally I prefer $\cdot$ (\$\cdot\$) to the double vertical bar, and I would prefer it to have a high precedence. But there isn't really one right way to do it. I think it's possible to walk a narrow path and avoid either overusing parentheses or tediously explaining your usage: just use it enough times in a context where there is only one sensible interpretation of the precedence, and an attentive reader can figure it out.