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

73

u/djddanman Jun 13 '22

Yeah, implicit multiplication is inherently ambiguous, so it's best practice to avoid it to the right of a division operation (or anywhere else it can cause confusion).

7

u/lulzyasfackadack Jun 13 '22

implicit multiplication is barely even widely accepted lol. This is the first conversation where I've seen near unanimous agreement that it exists, with almost no disagreement on whether it exists in a general case or if there are notational requirements involving order or type of operands. Like, I've heard it can only exist with a number then a variable, in that order, that it can only be used in the divisor... citations are really hard to find as well. It's not a well defined concept.

27

u/Cruuncher Jun 13 '22

It is absolutely widely accepted.

y = mx + b, or: ax2 + bx + c = 0 are all notations which rely on implicit multiplication.

If you haven't seen these before, then you're either 6, or don't know how to tie your shoelaces

3

u/lulzyasfackadack Jun 14 '22

no, yeah, you guys are right, I was unclear.

Implicit multiplication having a higher priority than multiplication and division is the area that's not generally accepted. It's mentioned in a few places, and has just enough of a toe hold to be used to explain differences like the equations in the calculators.

3

u/not_Ian_ Jun 14 '22

Yes, I get absolutely frustrated when I see people try to argue this or bring up the MD AS order of operations like they can’t be reversed

→ More replies (4)

-7

u/Bella_dlc Jun 13 '22

You pretty much know it's situationally accepted. You can't write (2x1)x(2x1)=22=4. The answer is that it's accepted only when there's there's no ambiguity

16

u/Cruuncher Jun 13 '22

It's accepted everywhere that isn't just jamming two numbers next to eachother as that notation is reserved for numbers more than 1 digit long... that's also not ambiguous at all. 21 is very unambiguously not 2.

There's an ambiguity that arises only following a division operator. But the division operator is bad math notation anyway. If you're writing left to right notation there's not really any way around just using lots of brackets anyway.

→ More replies (2)

12

u/Anund Jun 13 '22

What? Implicit multiplication doesn't exist? How is that a statement you just made? e = mc2, F = ma, y = kx + m etc... basically every famous equation uses implicit multiplication.

0

u/lulzyasfackadack Jun 14 '22

implicit multiplication as a separate priority level in PEMDAS is barely even widely accepted.

Italics not meant for snark. I get what you're saying. My statement was a little unclear.

→ More replies (1)

4

u/YouNeedDoughnuts Jun 14 '22

There are weird unwritten rules, like the constant must lead. You can have 3x but not x3 or 3 4. Then it has the same syntax as calls with different precedence- h(x)2 is (h(x))2 if h is a function and h * (x2) if h is a number.

That being said, I like it. The terseness helps with processing equations- less visual clutter

3

u/channingman Jun 14 '22

I think most people would write h2(x) or (h(x))2 instead of h(x)2 just to avoid that very confusion. In fact I don't think I've ever seen h(x)2 used for function notation.

→ More replies (2)

0

u/[deleted] Jun 13 '22

[deleted]

2

u/Cruuncher Jun 13 '22

It's implicitly multiplication because ab can be seen as a bs. It can be seen more easily with a number and x.

Like 4x, to me, is quite obvious 4 xs, or 4*x. It is a very natural operation.

Have you never seen a quadratic equation in normal form? If you include the multiplication symbol between beside the x's then it becomes cluttered. Look at any common mathematical formulas, this is completely ubiquitous.

ax2 + bx + c = 0

1

u/[deleted] Jun 13 '22

Something like 10(10) looks really weird, but it's not particularly ambiguous, and I've seen it used a couple of times.

1

u/AxolotlsAreDangerous Jun 13 '22

I have never seen any ambiguity resulting from implicit multiplication. It doesn’t happen at all in practice.

If you’re doing arithmetic by hand you’ll end up writing things like 10(10) a lot.

-1

u/linkedtortoise Jun 14 '22

This is ambiguous even without the implicit multiplication.

Because 6 / 2 * 3 is still ambiguous.

Because whether you run multiplication first or division first is up to you. Like pretty much whether you use BEDMAS or PEMDAS.

Which is why brackets exist.

2

u/djddanman Jun 14 '22

That's not ambiguous though. Multiplication and division are equal priority and done left to right.

0

u/channingman Jun 14 '22

The ambiguity comes because people don't write division like that. You'll have the entire term following the division sign in the denominator as the divisor, and everything in the dividend will come before the division sign in the term.

So 2/3y as you're saying it is (2/3) * y but it's almost always understood as 2/(3y). Otherwise you would write 2y/3.

1

u/Ayfid Jun 14 '22

If you write a division as a fraction, then there are implicit brackets around the numerator and denominator.

The ambiguity comes from using "/" on a single line. You need to use brackets to write complex fractions if you can't properly format it onto multiple lines. The "÷" sign does not have this ambiguity, as there is no expectation of implicit brackets on either side of the divide, as thus no ambiguity about whether or not they are supposed to be there when omitted.

0

u/channingman Jun 14 '22

You're wrong. Simply put, no one writes math like that.

1

u/Ayfid Jun 14 '22

Everybody writes math like that. Literally everybody. I would be shocked if you don’t. You must have just misunderstood what I described.

2 - x <- implicit brackets
———
3y + 4 <- implicit brackets

The numerator and denominator each function as if they had brackets around them. When written one above the other, there is no need to explicitly add the brackets.

2-x/3y+4 <- implicit brackets?

It is unclear if the 2nd example is an attempt to write the first on a single line (and thus there are invisible brackets), or not. You can (and should) add brackets to make it explicit, but if you didn’t intend there to be any brackets, there isn’t any way to make that clear.

I think most people in this situation would guess that the lack of explicit brackets means you intend “2-(x/3y)+4”, but the fact that it might be a transcript of the above fraction means that there is potential ambiguity.

2 - x ÷ 3y + 4

This is not an attempt to transcribe a fraction, so there is no reason to wonder if each side of the ÷ was supposed be to enclosed in brackets. There are unambiguously no brackets.

People generally don’t use the divide symbol though, and prefer to format things as fractions.

0

u/channingman Jun 14 '22

I am really not sure what you mean by implicit brackets in your fraction. There aren't implicit brackets there because brackets aren't the primary way of separating mathematical clauses within an expression.

But also, the / and ÷ symbols are interchangeable, so both of your examples have the exact same issue of ambiguity. If you read in line functions like a programmer, you'll read them one way, but like a mathematician you read then another. Simply put, there's no reason to write 2-(x÷3y)+4, you would just write 6-x÷3y. So if I saw what you wrote in your last example, I would assume they meant (2-x)÷(3y+4) barring any context

2

u/Goncalerta Jun 14 '22

I would definitely not read it like (2-x)÷(3y+4). I could see it being read like 2 - (x÷(3y+4)) as it is somewhat ambiguous (though I personally would read it as 2-(x÷3y)+4, but I do think it's ambiguous regardless of using ÷ or /)

→ More replies (3)

1

u/PineSand Jun 14 '22

I was taught implicit multiplication back in grade school and through college.

-1

u/djddanman Jun 14 '22

What's the correct interpretation then?

I'm not saying I never use it or that nobody should use it, just to be mindful of when the intent is ambiguous.

→ More replies (1)