Where should concatenation take place in the order of operations?

1.8k Views Asked by At

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.

3

There are 3 best solutions below

2
On

In the video The 10958 Problem by Numberphile, Parker uses concatenations to solve the problem. As he does this, he treats concatinations as after multiplication and division, but before addition and subtraction. So I believe the Order of Operations would be PEMDCAS.

However, concatenations are not really well used, so it really wouldn't go into the order of operations properly :D

1
On

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.

6
On

It is quite rare to use concatenation in the same expression with multiplication or addition. I would just shoot anybody who wrote $5 \times 1||2+4$ and if they survived offer them a lifetime supply of parentheses. My real answer is that there is no convention because concatenation is a recreational operation while addition and multiplication are real mathematical operations. Anything you do with concatenation is dependent on the base you are operating in, and real math doesn't do that.

I enjoy puzzles that involve the digits of numbers, but in a sense that is not mathematics.