True, but I was assuming he meant trees with nodes and edges, not LISP-y parenthetical ASTs.
Who wouldn’t want to use LISP if given the chance. I probably learned more about thinking about programming working in LISP than any other language.
I really don’t get this argument so maybe you or sbunny can explain it better. There are a set of rules so that any expression is well-defined. What is the issue with having people follow those rules? And so you know, I studied mathematics as a social construct at the University of Exeter so I am very familiar with the concept that the rules of math are agreed to vs manifestations of some Platonic form.
You keep using that word - “rules”.
Such rules don’t actually exist, except in the minds of certain teachers.
They really are conventions and not true rules. Further, as noted previously, there’s no official body to enforce any rules, even if they existed.
Worse, there’s no single set of rules. While we have a set of conventions that are generally followed, the actual convention, the “true” one if such a thing exists at all, is that if an expression is poorly written, the writer of the expression should be asked to clarify and materials edited prior to publishing. Pretending that the order of operations is some kind of ultimate set of rules for writing expressions is overexaggeration. It’s one of the many semi-truths we tell children that they subsequently have to unlearn as they grow up.
The real problem, to the extent it exists, is there’s not traditionally been a good way to format mathematical expressions inline with text, especially when written by hand. The method for writing arithmetic expressions was not designed from scratch, so it has all the idiosyncrasies associated with our imperfect languages - which themselves can contain ambiguities. It’s a problem with the English language handling of arithmetic expressions, basically.
Printed mathematical formatting generally obviates the need for resolving these types of ambiguities by using a superior rendering of text.
Other systems of writing mathematical expressions, such as reverse Polish notation, eliminate the need for elaborate order of operations rules entirely, as they are designed in such a way that such ambiguities cannot arise in the first place. It’s an unfortunate twist of history that nobody thought to introduce such systems in the first place.
Likewise computer science. The difference for programming languages is there is an ultimate arbiter. A programming language’s has definite rules on parsing expressions which is strictly enforced and out of the hands of the user, unlike English.
So you’re saying it is equally valid to say 2+3x4=20 as it is to say 2+3x4=14? Then how can any expression be well-defined? Then how do I know which answer the author intended?
Double post because of 5 min rule
Teachers so not make the rule. The rules have evolved as an agreement by society that “these are the rules of math”. Would you argue that there are no rules in driving simply because they are arbitrary rules agreed to by society?
Not always, C++ has undefined sequence points where functions may be evaluated in any order. If any expression is at all stateful, this can matter. For instance, it can change the behavior of random number generators with a known seed if you generate two or more numbers in a single expression with undefined sequence points, and that behavior may or may not change between platforms, and debug/optimization flags.
Expressions aren’t well defined and you can’t know, depending on the writer. Some notions are stronger than others. Multiplication with an infix operator (*, x, ., etc) binding higher than addition is one such notion that’s extremely common, to the point of almost being universal. Multiplication by juxtaposition after division (e.g. 1/2x) is less well defined, and you may have to ask for clarification. (Though in the case I illustrated it’s likely to be 1/(2x) because otherwise it would likely have been written x/2).
Most importantly, in mathematics there’s usually context. Expressions typically don’t happen in a vacuum. If you’re doing probability and reading something one way makes it integrate/sum to one and one doesn’t, then you know which one it is. If there’s a recurrence relation about the running time of an algorithm, that T(1/2x) is probably one-half of x, rather than 1/(2x), because (1/2)x is a common recurrence for divide and conquer algorithms. This is why we teach students “sanity checks” – to make sure their answers are right, yes, but also to tell what someone means. Usually, only one interpretation will pass the contextual sanity checks.
This kind of reminds me of the well-known (in certain circles) blog post about the pre-rigorous, rigorous, and post-rigorous stages of learning math, that often plague graduate students in math-heavy fields. When people hit the “rigorous” stage they tend to get “compilation errors” in research papers that don’t define everything perfectly, or use ambiguous notation. Once they become more familiar with their subfield, they have sufficient context to easily tell what the writer meant.
But the point is that you can know as long as we have all agreed to abide by the arbitrary rules. And every system has arbitrary rules.
I agree that 1/2x is ambiguous as (1/2)x vs 1/(2x) but that is not the issue in the OP. The issue is some people seem to think that 3+4x5 = 35 is perfectly valid because the OoOps is arbitrary.
The expression you wrote above (2+3x4) is not well defined, and you cannot know the answer the author intended. You can guess, but you might very well be wrong.
The expression is ambiguous. There are conventions for resolving the ambiguity, like doing multiplication/division first, then addition/subtraction. But how do you know the author of the expression followed the convention you expect? You don’t, just like it’s sometimes ambiguous whether an “x” is supposed represent a variable or the multiplication operation.
It’s perfectly valid, it’s just liable to be misunderstood. I certainly don’t think I’d call it wrong, in a technical sense; just wrong in the same way pointing at something with your middle finger in the US is “wrong”.
It’s not a rule with as much power as, say, the peano axioms, where if you mess with them just a little everything breaks down. You just get slightly funny numbers compared to other people. It doesn’t facilitate discussion or understanding, but it’s also not incorrect.
I think this is a little bit of a strong statement. In a Bayesian sense, the existence of conventions gives a prior over the meaning for any expression. As we gain information, our confidence in our interpretation goes up and down. Most adults I’d assume probably were using PEMDAS. College students almost certainly, an artisan welder maybe less certainly. If I was given that a 12 year old wrote it, I’d be very uncertain which way the operators bound. You “can’t be certain” in a pedantic sense, but the conventions give a very, very strong indication of what is meant.
Of course we can resolve the ambiguity by agreeing to abide by arbitrary rules. When and where did we agree to this? If you and I are sitting together in a classroom, we agree by actually agreeing–if you are the teacher, you state what the rules are going to be, and I agree to them. That’s pretty simple, and so any examples you provide in the classroom will follow the convention you state, and if you sometimes write an expression that doesn’t follow your convention your students can pounce on it and tell you that you wrote it wrong, and since you’re the one who taught the convention you’ll have to admit you made a mistake.
But when you wander out into the wild world and someone you never heard of writes an expression you have no way of knowing if they followed the convention you teach in your classroom. Maybe they were taught a different convention in someone else’s classroom. However, much more likely is that they were taught the same convention but they made a mistake and didn’t think it through and so wrote an expression that they thought would have the value they expected, but would only do so if you didn’t follow the order of operation convention you teach in your class.
And this is why relying on everyone being able to parse the expected order of operations convention is a bad idea, because you simply can’t expect it to always work except in highly constrained situations like a particular highschool math class.
In school in Germany, I was taught, “dot before line” - the standard symbols there being “:” for division, and just a dot for multiplication. I don’t remember a mnemonic for parentheses (apparently you were supposed to just fricking remember that that’s what they’re FOR), or exponents. Simple rule: the more complex operation* first, and parentheses trump everything. (*Multiplication being a repeated addition, and exponents repeated multiplication)
This is exactly what I was thinking of, only I forgot to state it explicitly. If you know the author of the expression you can be more or less confident that it follows a particular convention. But if the source is your 12 year old kid, or a grizzled old construction worker, or a hastily scribbled note from your spouse, blithely assuming you can evaluate the expression simply by following PEDMAS is likely to bite you in the ass. It depends on the consequences of interpreting the expression incorrectly of course. Measure twice, cut once, if you’re going to be cutting thousands of dollars of lumber based on some expression, assuming that all you need to do is follow standard order of operation is foolish. If nothing bad could happen if it turns out the author of the expression didn’t correctly follow convention, then go right ahead and assume they did and fix it later if they didn’t.
You’re all wrong, the answer is clearly -5 read right to left…
Which is exactly the theory behind social constructivism. Math and its rules are a social convention and yes there are difference between different societies such as rounding rules, use of milliards, use of commas and periods and it does make for some confusion.
But at the heart of the discussion is if math is a social construct, how does your usage of mathematics allow you to function in the prevailing society? It’s like saying, “Well 65mph is arbitrary so on this freeway I’ll drive 90mph. I mean, they do it in Montana.”
Am I saying there is an absolute Platonic form that determines multiplication is always before addition and that basis left-to-right is always wrong? No I am not. But what I am saying is if THIS society has determined that a certain order is correct then there is an obligation for all to follow it. Just like even if you disagree with an arbitrary speed limit that you had no hand in developing, you still are under a social contract to follow it.
You’ve got an excellent point there. I overlooked the fact that lines of code in a computer program are generally free of contextual clues which the computer would probably ignore anyway. In that situation, it’s certainly important for a programmer to know what rules the computer is following, or at least be aware that parentheses may be required to clear up confusion while debugging a program. But various computer languages have different rules, and the rules might vary even from one compiler to another. So it’s still a good idea for the student to learn the lesson “You need to consider the possibility that your audience might be confused by what you’re trying to say, therefore you should put some effort into clarifying it.” and that lesson still applies when the audience is a computer.
I’ve heard plenty of developers state that they never ever ever rely on the default order of operations in a computer language. You should always write code as if you had no idea what the default was.
As for being obligated to follow the default convention for order of operations, well, that’s fine. But what I’m saying is not that you shouldn’t use that default convention, it’s that if you always expect that every expression, no matter where it’s from, will follow that convention, you’re occasionally going to be unpleasantly surprised.
To use your speed limit analogy, there’s a road nearby where the posted limit is 45 mph. People regularly, every day, zoom down that road at 55 or 60. Do they know the limit is 45? Maybe they do and just ignore it, maybe they don’t. The point is, people ignore that convention all the time. It would be foolhardy of me to drive as if I would never encounter a driver going 55 or 60 on that road, just because I know the posted limit is 45.
The main point is, if you write out an expression like, I don’t know, 6-1X0+2/2, sometimes people are not going to parse that expression using the standard order of operations. If the point of writing that expression is to discover who among your friends and acquaintances on Facebook don’t know how to follow standard order of operations, then writing the expression that way served a valid purpose. If the point was to obtain a number so your plumber could purchase the correct number of fittings for your bathroom remodel, then relying on your plumber to parse the expression correctly using standard order of operations is foolish, and you would have been much smarter to remove potential sources of ambiguity.
It’s equally correct to point out that it’s merely “convention” that 5 refers to this many: |||||
The shape ‘5’ is, after all, simply a convention.
Yet, oddly, no one brings up the supposed ephemeral, arbitrary state when we ask what 5+6 means.
And don’t get me started on the randomness of + meaning the operation of addition!! That’s just completely arbitrary and no “academy” exists that enforces it.
In conclusion, ΦΧΨΩ.
Space on the paper? Depending on how we draw our trees, perhaps we might find ourselves inclined to use slightly more space. Significantly more? I’m not sure, but at any rate, paper’s cheap. Even better, we live in a virtual world now; no need to tie ourselves tightly to the constraints of paper.
Why not? Computers are great at storing trees! Hence why computer scientists spend so much time thinking and talking about trees (and algorithms for manipulating them, and so on).
Hell, it’s already the case that when you write an arithmetic expression in a programming language, the computer ends up storing it internally as a tree. It just wastes time parsing it out of (and you waste time deparsing it into) an “order of operations”-ified linearization first.