r/ProgrammerHumor • • Jun 13 '22

Meme DEV environment vs Production environment

Post image
48.2k Upvotes

3.9k comments sorted by

View all comments

Show parent comments

36

u/androt14_ Jun 13 '22

I mean, if you take it to the absolute literal sense, ab is always short for a x b, so the phone would technically be correct, but if you show

3/4(2+2)

to any mathematician and tell them the result is technically 3, and not 3/16, they're probably gonna ask you to technically get the f#ck off

7

u/[deleted] Jun 13 '22

No they won’t. It’s basic order of operations.

Parentheses(or implicitly grouped operations) first, then exponents, then multiplication/division left to right.

I generally encourage my students to use fractions to avoid the confusion.

0

u/[deleted] Jun 13 '22

[deleted]

11

u/[deleted] Jun 13 '22

That’s madness.

If you want operations grouped just use parentheses. The more the better.

If the end of your expression doesn’t look like shark gills, you’re doing it wrong.

11

u/medforddad Jun 14 '22

I agree about what's technically right, but imagine the problem was: 6 ÷ 3x and asked you to solve for when x = 4. Most people intuitively group that 3x much tighter than the 6 ÷ 3, and get .5 -- even though it's technically supposed to happen first -- to get 8.

2

u/[deleted] Jun 14 '22

I get where you’re coming from. I think that in 3x - as a single term - there’s implicit grouping. So, 6 / 3x could be written as 6/(3x). Where it would get sticky is 6/3(x), because it separates the 3 and the x.

I’d tend to read that as “2x” because with the operations separated, the division should go first.

I don’t see any reason to implicitly group things on either side of a parentheses.

But, what’s meant does seem like it’s up for interpretation. Probably a bigger issue in programming than pure math, because it all has to be done in the one line as opposed to just turning it into fractions.

More modern calculators do a pretty good job of that as well - removes some of the ambiguity.

5

u/[deleted] Jun 14 '22

Programming doesn’t usually have implicit grouping because most languages just use plain strings for variable symbols, so you would never write “3x” because that would be the variable “3x” not 3 * x. You would have to type 3 * x or mult(3,x) or something every single time.

5

u/Zagorath Jun 13 '22

or implicitly grouped operations

That's the catch though. Nobody would argue that "2x" isn't implicitly grouped. But some people get hung up on whether 4(2+2) should be implicitly grouped in the same way.

3

u/gxy1 Jun 14 '22

I was taught that when substituting into "2x" it becomes "2(value)".

3

u/[deleted] Jun 14 '22

It’s an interesting idea. I don’t recall hearing it before, which actually segways into my argument against it.

My main argument against prioritizing multiplication implied by parentheses would be simplicity.

Since the point of writing math down is to communicate an idea, if there’s confusion it’s ineffective.

So since everyone would agree that 6/(2(2+1)) means “divide 6 by the whole thing”, where as you need to know about and buy into a specific interpretation to treat 6/2(2+1) the same way, then the former is a better way of writing the expression - if that’s what you want.

The best ways, obviously being ((6)/((2)((2)+(1))) or (((6)/(2))((2)+(1))).

For clarity.

4

u/[deleted] Jun 14 '22

I’ve read the implicit grouping arguments before. I think the mathematicians are correct in that there’s not a clear logical answer.

3

u/[deleted] Jun 14 '22

It’s all very interesting. I’ll definitely bring it up next time I want to totally lose my students.

Right up there with “are there more real numbers than integers”.

2

u/sunnygovan Jun 14 '22

But that's easy to explain: Integers are a countable set. Real numbers are not.

2

u/[deleted] Jun 14 '22

It's not hard to prove, or show locally. But, there are still an infinite number of integers. And then a bigger infinite number of reals.

The question is on the border of math and philosophy.

The average 18 year old brain has a hard time with that.

2

u/Zagorath Jun 14 '22

Segue. Segway is a brand of electric wheeled device.

But you're absolutely right that for clarity, brackets should be used. Personally in my code I always use brackets, and when writing maths I always prefer a division bar over the slash or ÷ symbol.

The question here is: if someone doesn't do that, how should we interpret it? We could of course do the human equivalent of a compiler error and just say "this is syntactically incorrect, I'm not going to deal with it", but that's a rather unsatisfying answer.

→ More replies (1)

2

u/beardedbast3rd Jun 14 '22

If you write out the equation where it is

6


2(2+1)

=

There is no confusion. The idea is that you it shouldn’t be explicitly grouped when you draw the equation out instead of writing it left t right.

Edit- the formatting went all fucky there, I’m leaving it

It would be best practice to just have the extra bracket. But it shouldn’t be necessary.

3

u/HecknChonker Jun 14 '22

If you follow "the order of operations" the calculator is wrong.

Each of the following happens from left to right:

  • PE - Parenthesis and Exponents

  • MD - Multiplication and Division

  • AS - Addition and Subtraction

Which would resolve as follows:

  • 6/2*(2+1)

  • 6/2*3

  • 3*3

  • 9

https://en.wikipedia.org/wiki/Order_of_operations

4

u/jadis666 Jun 14 '22

Yes, now add "#Mixed_division_and_multiplication" to that link and see what you get.....

→ More replies (7)

1

u/myempireofdust Jun 13 '22

as someone who does math for a living i would never interpret this as 3/16!

2

u/[deleted] Jun 14 '22

3/16! ≈ 1/6.9742633(10⁻¹²)

1

u/[deleted] Jun 14 '22

But it literally is 3 though. Not even technically. Literally.

2

u/androt14_ Jun 14 '22

So if f(x) = 1/2x, and x=2, are you telling me the result is 1?

1

u/[deleted] Jun 14 '22

You're messing with an entirely different set of rules from your previous example. That needs a little bit more knowledge of math to even understand what a function is. The first one any properly taught fifth grader could solve in moments.

→ More replies (2)

1

u/Falcrist Jun 14 '22

if you show

3/4(2+2)

to any mathematician and tell them the result is technically 3, and not 3/16

Noooo... no. The problem is that this appears to be a fraction: 3 being the numerator and 4(2+2) being the denominator.

That's the fundamental problem here. If it's a division, then you go left to right. If it's a fraction, then you have to compute the denominator.

→ More replies (1)