flat assembler
Message board for the users of flat assembler.

 Index > Heap > + - X ÷ () ^
Author
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....
06 May 2011, 17:37
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 ^^
06 May 2011, 19:43
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 ).

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.
07 May 2011, 17:36
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

But even with correct precedence, you still must remember to evaluate from left to right.
07 May 2011, 20:15
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"?

Our mnemonic was BEDMAS. Pronounced "bed-mass"
Brackets
Exponents
Division
Multiplication
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
07 May 2011, 23:33
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?
07 May 2011, 23:36
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"?
... 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.
16 May 2011, 03:23
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 17279
revolution
neville wrote:
Tyler wrote:
A mnemonic you can use is "PEMDAS." Pronounced "pem-dos."
Why should "das" be pronounced "dos"?

Our mnemonic was BEDMAS. Pronounced "bed-mass"
Brackets
Exponents
Division
Multiplication
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
07 Jun 2011, 11:34
sinsi

Joined: 10 Aug 2007
Posts: 693
sinsi
07 Jun 2011, 11:42
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsCompiler InternalsIDE DevelopmentOS ConstructionNon-x86 architecturesHigh Level LanguagesProgramming Language DesignProjects and IdeasExamples and Tutorials Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou can attach files in this forumYou can download files in this forum