lua-users home
lua-l archive

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



> Yes, "a/b/c/d" is not a valid complex fraction, so an engineer should not try to interpret it this way.

To come back to the original topic, a recommendation for  "when to put parentheses for code readability", I see three options:

a) have a list of people who are "allowed to interpret" and "not allowed to interpet"
b) always have a table of operator precedence at hand, or even type it in the comment next to the code
c) use parentheses at everything that could be mis-interpreted

I will definitely go for option c)

d) Give everybody a brief Lua programming introduction, where you do not assume these things are obvious

... there might be even better options, of course

> But "a÷b÷c÷d" is well defined, because division and multiplication are executed from left to right, every schoolkid knows it.

After some investigation, I have to disagree.
You might find this article interesting: https://math.berkeley.edu/~gbergman/misc/numbers/ord_ops.html
Apparently I'm not the only one who encountered this ambiguity.

Also (my) algebra books define commutativity, associativity, distributivity ... but never "left to right execution".
I NEVER heard of a left to right execution rule in math (only in programming), not at school, not at university.
I am not aware of any university grade algebra book (for mathematics students ... not programming books) that defines "left to right execution order".
I mean a book on fundamental algebra, not "this is correct because a scientific calculation program calculates it this way" because this would be circular reasoning.
Could you name a reference here?




On Wed, Jan 13, 2021 at 11:48 AM Egor Skriptunoff <egor.skriptunoff@gmail.com> wrote:
On Wed, Jan 13, 2021 at 12:21 PM bel wrote:
Wikipedia (https://en.wikipedia.org/wiki/Fraction#Complex_and_compound_fractions):
"So 5/10/20/40 is not a valid mathematical _expression_, because of multiple possible interpretation."

Yes, "a/b/c/d" is not a valid complex fraction, so an engineer should not try to interpret it this way.
But "a÷b÷c÷d" is well defined, because division and multiplication are executed from left to right, every schoolkid knows it.