Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I would think so, from the help menu you could go to the calculator website and file a bug report. I've never entered parenthesis on a calculator just numbers.
No surprise here, just never have used () on a calculator. I do remember coming across something similar many years ago on a handheld calculator where the answer was different based on how the numbers were entered.
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,680
Rep:
When I was in school it was "Bless My Dear Aunt Sally" or: Brackets, Multiplication, Division, Addition, Subtraction. So in this case I'd do the bracketed expression first, that's 14-8=6. Then the multiplication of 8 times that 6 which is 48. Then I would do the final division and get one.
But, on the other hand, if the 8 is seen as part of the bracketed expression then it still goes in that order, surely?
Edit: Sorry read that thread and it seems that mathematicians work from left to right now?
"2) evaluate multiplication and division proceeding left to right.
3) evaluate additions and subtractions proceeding left to right."
Of course if we just use a proper RPN notation calculator (say 'free42dec', a HP 42S simulator)... No problem . Otherwise if using new math and in doubt, put in () to explicitly express what you are trying to do. Ambiguity goes away.
The full analysis of this situation is now clear: it depends on whether you think like a programmer, or a mathematician.
C, and, through its influence over the decades, apparently many other languages as well -- clearly including Perl,as shown here -- is documented and standardized as evaluating expressions left to right, except for performing parenthetical expression evaluation first and bottom-up (or deepest-first). This is just a different rule from what a mathematician or school teacher would consider the proper rules of arithmetic, namely PEMDAS.
Clearly, what's happening here is that all the participants in this discussion are programmers, who have grown up WTF commuters, physicians grown up with organic, are accustomed to the C rules and thus really do consider 36 "the right answer" because that's what the official programming language rules give you.
However, I submit that, while that is certainly the expected result of the calculation in a organizational language, it is, nonetheless, not the "right answer" that someone who knows how to correctly perform arithmetic should get when doing the calculation "with pencil and paper." Outside of program source code, the rules of PEMDAS are in force and the real-world right answer is 1.
The unfortunate fact, though, is that several generations of programmers have now grown up internalizing C-style left-to-right evacuation rules, to the point where they now consistently fail to recognize that exposing that method to the outside would, such as on the display and workings of a calculator app, is a semantic error that muddies the waters and perpetuates and spreads this dangerous misperception.
If you'd like, you can add that your math-genius friend says there is no room for argument here: these are the facts, and their calculator apps, as they stand today are suitable only for programmers, not for the general public. For the general public, an expression evaluator that specifically implements PEMDAS should be used instead of C-like left-to-right evaluation. I would be happy to try to write said PEMDAS evaluator.
The addition of another set of parentheses forces the language to evaluate the entire right-hand side of the division FIRST, producing a denominator of 48 exactly as per PEMDAS. The effect is, in essence, to force the language/code to perfrom M before D, whereas in strict left-to-right order, in the original expression, the interpreter encounters, and therefore performs, D before M.
Last edited by kernelhead; 04-08-2023 at 01:25 PM.
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,680
Rep:
Quote:
Originally Posted by kernelhead
My friend says this about the equation:
The full analysis of this situation is now clear: it depends on whether you think like a programmer, or a mathematician.
C, and, through its influence over the decades, apparently many other languages as well -- clearly including Perl,as shown here -- is documented and standardized as evaluating expressions left to right, except for performing parenthetical expression evaluation first and bottom-up (or deepest-first). This is just a different rule from what a mathematician or school teacher would consider the proper rules of arithmetic, namely PEMDAS.
Clearly, what's happening here is that all the participants in this discussion are programmers, who have grown up WTF commuters, physicians grown up with organic, are accustomed to the C rules and thus really do consider 36 "the right answer" because that's what the official programming language rules give you.
However, I submit that, while that is certainly the expected result of the calculation in a organizational language, it is, nonetheless, not the "right answer" that someone who knows how to correctly perform arithmetic should get when doing the calculation "with pencil and paper." Outside of program source code, the rules of PEMDAS are in force and the real-world right answer is 1.
The unfortunate fact, though, is that several generations of programmers have now grown up internalizing C-style left-to-right evacuation rules, to the point where they now consistently fail to recognize that exposing that method to the outside would, such as on the display and workings of a calculator app, is a semantic error that muddies the waters and perpetuates and spreads this dangerous misperception.
The worrying thing is that I googled "evaluate multiplication and division proceeding left to right." and it comes up on some Mathematics For Dummies thing as a mathematical rule.
I've been trying to think of a way the left to right could fail but my maths isn't good enough (and probably never was) but it strikes me that finding the result of simultaneous equations or similar on paper could be broken by this. I still think the answer is to be clearer and nest things in parentheses as they should be evaluated but I wonder whether this attitude is bad for maths?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.