How would you solve the equation 2+2X2?

How, precisely?

Yes, which means that an equation which is written ambiguously sucks, since it misses the whole point of equations.

It’s the symbolic representations of the equations that are ambiguous, not the equations. It’s not a problem in application if we just agree to use the same definitions for numbers, operators, variables, and the thing that keeps confusing everybody, PRECEDENCE.

It’s universal among any programming/scripting language out there (Well, okay, I’ll concede there might be a commonly used language out there that doesn’t, but I’ve never seen one), which makes sense when you consider the scientific/engineering community largely follows PEMDAS (I never learned that acronym in school either).

Of course, most programmers will tell you to put parentheses in things just to make it more readable, even if they are redundant by operator precedence.

So if I were coding the thing, I would probably do 2 + (2 * 2) even thought the parentheses aren’t needed, just because it makes it faster and easier for another human to parse. Because every programmer will occasionally screw up operator precedence, whether they are writing or reading the code.

But it isn’t universal among programming/scripting languages; it’s popular, to be sure, but not nearly universal. There are plenty of programming languages in which multiplication does not take higher precedence than addition, or in which they aren’t represented by infix operators in the first place (thus removing the purely notational concept of precedence in the first place).

Exactly. You’ll find the concept of precedence is almost nonexistent in Lisp-based languages (I’m intentionally ignoring parentheses here) because all operators are presented as prefix operators.

Unfortunately, prefix notation is hard to read in general, despite its lack of ambiguity. Teaching prefix notation to students who are accustomed to infix also runs into problems with continuity. If I asked students in a discrete math class to evaluate “+ * 2 2 2” and "* + 2 2 2 ", there would be a number of students who would give the same answer to both, although the first means (2*2) + 2 and the latter means (2 + 2)*2.

Pedant says that the OP contains no equation. It IS an expression.

You could be forgiven for thinking so, since all the “mainstream” industry languages — the ones occupying all the bookshelf space in Borders — use the standard arithmetic precedence rules. But as Indistinguishable and Mr. Gentle note, it’s not universal.

In addition to the examples mentioned, APL and Smalltalk are languages having no operator precedence rules. Expressions are simply evaluated left to right (Smalltalk), or right to left (APL).

And in contrast to prefix languages like Lisp, there are postfix, “stack-based” languages like Postscript and Forth in which operator symbols always follow their arguments.

APL not only has no precedence, order of evaluation is right to left:

2+22 evaluates to 6
2
2+2 evaluates to 8

(yeah, I know - that isn’t the right symbol for “multiply” in APL. Translate.)

I think postfix or prefix is hard to read simply because we didn’t learn it that way in grade school. Quite possibly, people might actually have less trouble with arithmetic and algebra if we had. We certainly wouldn’t have to carry this nonsense about operator precedence around with us. That said, I didn’t learn it that way in grade school any more than anybody else did, and it would take massive retraining for it to be natural. For instance, you would learn the distributive rule as

  • a + b c = + * a b * a c

instead of

a*(b+c) = ab + ac

For what it’s worth, it only took me a few months with an HP calculator (which is basically postfix notation) to be just as comfortable with it, or more so, than with a TI. This is at least partly because the display shows the stack (or at least, the first few levels of it), so you can see directly what’s going on-- I don’t know if it would be as easy on a calculator with a one-line display.

It’s also worth noting that prefix notation is exactly what we are all taught to use for operations by default, only with parentheses and commas dragged into it: f(g(1, x, 3), h(3, j(y, 4))), that sort of thing.

We happen to bless a few particular functions with “irregular forms” such as infix notation for the binary functions of grade school arithmetic. Becoming comfortable with prefix notation is just becoming comfortable with treating arithmetic functions the same as any other one: mult(a, add(b, c)) = add(mult(a, b), mult(a, c)), that sort of thing. Or, using shorter names for these functions: (a, +(b, c)) = +((a, b), *(a, c)). Which, without the unnecessary parentheses and commas, is * a + b c = + * a b * a c, as illustrated before.

[And postfix notation is of course just the same thing in the other direction; alas, even after abandoning infix notation and its precedence woes, there will still rage all the religious wars over whether syntax should start by specifying inputs and end by specifying outputs (as in postfix notation), or start by specifying outputs and end by specifying inputs (as in prefix notation)]

Reported,
Shodan

I’m assuming this zombie was revived by a spammer who was vanished, along with all posts after that. A mode should make a note to that effect, especially because the forum page shows a post from Shodan from 10:11 today 12/14/2017.

Yes, this was revived by a spammer who was wished away to the cornfield. We generally don’t mod note these since the post will drop back off of the forum list once the spammer (and spam reports) are removed from the thread.

You probably viewed the forum list before Shodan’s post report was removed.

If you want to discuss this further, please start a thread in ATMB.

So you’re saying you find the thought of my grandmother’s dandruff sexy, and you wish to give me your car?

Do go on, then.

It’s 6, as other have said, the order of operations is to multiply first.

As of August 2012, it appears Ruminator has decided not to go on.