lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> Have you never seen such pictures in your math class?
> https://ecdn.teacherspayteachers.com/thumbitem/Order-of-Operations-Foldable-PEMDAS-by-Math-Doodles-2502453-1539785667/original-2502453-1.jpg

No. This is an English language specific poster. I just found yesterday that such pictures and English language mnemonics like PEDMAS even exist.
If your school is somewhere else, you might have learned "dot before dash": https://als.wikipedia.org/wiki/Punktrechnung_vor_Strichrechnung ... no such poster.
This rule used together with fraction bars and a high discipline when using brackets avoids the need for any "left to right" rule.

> and "division by x" is defined as "multiplying by the inverse of x".
Exactly!
Just like subtraction is defined as adding the inverse element, so - must only be defined as unary operation to get the inverse element.
With this definition you can use "a - b" as a simplified writing convention for "a + (-b)" and use commutativity to prove "a - b - c" = "(a - b) - c" = "(a - c) - b".
This proves that you can work from left to right but also out of order.

It all turns down to "how is the symbol / defined".
Do you define "a/bc" as "a (1/b) c" or "a (1/bc)", respectively "a (b^(-1)) c" or "a (bc)^(-1)"
Instead of / you could do the same with : or ÷  ... I think in practice no one really distinguishes, but the symbol that was available for typesetting was used.

And I already gave historic sources for different usage of /
and another source indicating that this is disputed and not understood consistently when read by different people.

Remember: My point here is "should you use brackets in mixed / * or multiple / expressions, because it will avoid misunderstanding"
--> Definitely yes, because there are definitely people reading this in a different way.




On Thu, Jan 14, 2021 at 3:54 AM Philippe Verdy <verdyp@gmail.com> wrote:


Le jeu. 14 janv. 2021 à 00:57, bel <bel2125@gmail.com> a écrit :
Left-Associativity is only defined for one operator X:   a X b X c = (a X b) X c. This does not define anything for two different operators (* and /).
The problem does not exist for subtraction

No it exists for substraction, exactly like divisions:

a - b - c = (a-b)-c   !=  a-(b-c) = a-b+c =  (a - b) + c

Rewriting the members to use unary negation (or unary inverse) for changing a non-commutative substraction (or division) into a commutative addition (or multiplication) if another thing: you completely change the operation and define another one (negation or inverse).

And if you work with integers or float/doubles in C/C++/Lua/Java/_javascript_, the inverse will generate important rounding differences (or sometimes overflows with unspecified results: commutativity is not true even for the multiplication on integers in C/C++/Lua/Java/_javascript_) on the result, so it's not equivalent at all: in this case the order of operations is important, the type of associatitivity if important, and using reordering/commutativity will bring false results in important cases.

We were ONLY speaking about the use of parentheses to specify the associativity (and order of operations when rounding or overflows can occur due to limited precision).