flat assembler
Message board for the users of flat assembler.

Index > Heap > + - X ÷ () ^

Author
Thread Post new topic Reply to topic
sleepsleep



Joined: 05 Oct 2006
Posts: 8902
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 334455
sleepsleep
so, we set formula on which to do when we face a maths question...

but, since it is human who set it, which mean, a RULE we set on our own.

6÷2(1+2)

so, be it 1 or 9

and BOTH should be true imo....

hmm, it is important to know which one should be first and second, but it is we, the human who set this rule, the number itself doesn't got such rule....
Post 06 May 2011, 17:37
View user's profile Send private message Reply with quote
Enko



Joined: 03 Apr 2007
Posts: 678
Location: Mar del Plata
Enko
this might result interesting for you:
http://warnet.ws/news/43895

If both is true, then mathematic become ambiguos. And the utility is lost becouse it wouldn't be "universal"

It similar to the right side driver in England or Japan. Say you are in Germany or Spain driving your car and start thinking...... hey man, in England they drive the other way... BOTH SHOULD BE TRUE. So to prove your point, you start driving the other path, as result, collision with a big big truck resulting in your death.

it´s just a representation, if it surves your needs, its valid, when the math are no long util, then its time to rethink it; starting this way a new paradigm.

Who knows, perhaps in the future, the precedense of the delimiters will no longer be as we know it ^^
Post 06 May 2011, 19:43
View user's profile Send private message Reply with quote
MHajduk



Joined: 30 Mar 2006
Posts: 6034
Location: Poland
MHajduk
Math never is "ambiguous" while your formulas may be - that's why we are using parentheses (or denote expressions using RPN). Math is a some kind of dictatorship of rules which lead us from the axioms and definitions of objects to theorems, from simplicity to complexity. But math by no means is a "religion", it's a language of the mind, ordered way to express our thoughts (similar with music which is a language of the heart; both languages are hardly comparable but vitally important to us Wink).

The rules of evaluation of expressions may be sketched as follows:
  • you need to evaluate expressions in parentheses first, from innermost to outermost,
  • if you are evaluating an expression without parentheses you have to remember about priority of operators (^ goes before * and /, * and / go before + and -). Expression with the operators of the same priority are evaluated from left to right.
The reason of the operators' priority is the way they were defined:
  • ^ was defined using * :
    Code:
    a^b = a * a * ... * a
          \______  _____/
                 \/
                 b    

  • / was defined using * : a/b = a* b^(-1), where b^(-1) is a reciprocal of b
  • * was defined using + :
    Code:
    a*b = a + a + ... + a
          \______  _____/
                 \/
                 b    

  • - was defined using + : a - b = a + (-b), where -b is an additive inverse of b
You have to "unwind" such operators as ^, * and /, so they come first.

The reason of the evaluation from left to right is that division and subtraction aren't associative and order of the arguments is important for the result. Obviously, it's an effect of the definition of these operations. Excluding some special cases, we have for most a, b and c following inequalities:

(a - b) - c ≠ a - (b - c)
(a / b) / c ≠ a / (b / c)

More detailed information you may find in any textbook of analysis.
Post 07 May 2011, 17:36
View user's profile Send private message Visit poster's website Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler
A mnemonic you can use is "PEMDAS." Pronounced "pem-dos."

Parentheses
Exponents
Multiplication and Division
Addition and Subtraction

But even with correct precedence, you still must remember to evaluate from left to right.
Post 07 May 2011, 20:15
View user's profile Send private message Reply with quote
neville



Joined: 13 Jul 2008
Posts: 507
Location: New Zealand
neville
Tyler wrote:
A mnemonic you can use is "PEMDAS." Pronounced "pem-dos."
Why should "das" be pronounced "dos"? Razz

Our mnemonic was BEDMAS. Pronounced "bed-mass" Wink
Brackets
Exponents
Division
Multiplication
Addition
Subtraction

Anyhow, the "mathematically correct" answer for sleepsleep's expression is 9.
If he wanted it to be 1 it has to be 6÷(2(1+2)). No ambiguity!

_________________
FAMOS - the first memory operating system
Post 07 May 2011, 23:33
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4237
Location: 2018
edfed
these kind of "ambiguity" is a typical mistake of the beginner.

who never had this problem at school when it was time to calculate the result of some advanced equation?
Post 07 May 2011, 23:36
View user's profile Send private message Visit poster's website Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler
neville wrote:
Tyler wrote:
A mnemonic you can use is "PEMDAS." Pronounced "pem-dos."
Why should "das" be pronounced "dos"? Razz
... because "pem - dass" just sounds weird and takes more effort to say. It may be a dialect thing. Here, the "a" in ass is more annunciated than the "ah" in "dos." (We also pronounce the "o," in the case of DOS as an "ah.") And yes, they actually link the mnemonic to MS-DOS.

BEDMAS would be better, but we don't use brackets nor consider the word as a synonym for parentheses. Here, [] are brackets and () are parentheses.
Post 16 May 2011, 03:23
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
neville wrote:
Tyler wrote:
A mnemonic you can use is "PEMDAS." Pronounced "pem-dos."
Why should "das" be pronounced "dos"? Razz

Our mnemonic was BEDMAS. Pronounced "bed-mass" Wink
Brackets
Exponents
Division
Multiplication
Addition
Subtraction
However this misses one important step: Order. And it incorrectly assigns division before multiplication and addition before subtraction.

More correctly:
Brackets
Order (i.e left to right parsing)
Exponents
Division/Multiplication
Addition/Subtraction
Post 07 Jun 2011, 11:34
View user's profile Send private message Visit poster's website Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 693
Location: Adelaide
sinsi
Post 07 Jun 2011, 11:42
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.