mIRC Home    About    Download    Register    News    Help

Print Thread
Page 1 of 4 1 2 3 4
#112756 26/02/05 12:53 PM
Joined: Feb 2003
Posts: 2,812
Raccoon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
Fundimental flaw in the order of operations that $calc uses.

When a negative interger is raised to a power without being enclosed in paranthasies, order of operations state that the exponent is calculated first and THEN the negative sign is applied.

$calc(-(2^2)) == -4
$calc((-2)^2) == 4
$calc(-2^2) == 4

The order of operations in -2^2 should be equivilent to -(2^2) and NOT (-2)^2.

Enjoy! smile


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Joined: Sep 2004
Posts: 18
E
Pikka bird
Offline
Pikka bird
E
Joined: Sep 2004
Posts: 18
I see correct the three answers. -2² = 4

Joined: Apr 2003
Posts: 701
K
Hoopy frood
Offline
Hoopy frood
K
Joined: Apr 2003
Posts: 701
$calc(0-2^2) == -4

Unary - is higher than exponent in a lot of programming languages, doesn't seem that strange that mIRC chooses to follow that...

Joined: Sep 2004
Posts: 18
E
Pikka bird
Offline
Pikka bird
E
Joined: Sep 2004
Posts: 18
$calc(-2^2) = -2² = 4
$calc(-2*-2) = -2² = 4

Where it is the error?

Joined: Mar 2004
Posts: 457
D
Fjord artisan
Offline
Fjord artisan
D
Joined: Mar 2004
Posts: 457
according to my casio calculator -2² equals -4. So casio is wrong?

[Edit] above is not meant to sound sarcastic btw, its a serious question

Last edited by Danthemandoo; 26/02/05 09:00 PM.
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
The order of operations does indeed state that exponent precedes subtraction. The negative sign there isn't an operation though (or at least that's how I understand it); it's part of the number, a symbol to denote that this number is negative.

What's more convincing than my speculations though is Microsoft's PowerToy Calc and Google. If you enter the expression "-2^2" in either of them, you get 4.

I searched Google for info on this but I found mixed answers, unfortunately not from reliable scientific sources.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Your calculator has flat batteries maybe smile
Im getting 4 on both my casios (fx602p, fx82super)
What did you type?
[2] [+/-] [X²] result 4
[2] [X²] [+/-] result -4

Any negitive number squared makes a positive number and -2 is a negitive number last time i checked (which was a while ago so maybe they changed the rules of math lately?)

Joined: Feb 2003
Posts: 2,812
Raccoon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
To DaveC:
Quote:
Your calculator has flat batteries maybe
Im getting 4 on both my casios (fx602p, fx82super)

If your Casio calculator is capable of multi-termed equasions, then you should have gotten -4.

To Everyone Else:

According to my TI-85:
According to Javascript:
  • <a href="javascript:alert(-2^2);" target="_blank">javascript:alert(-2^2);</a> <- click
According to MATLAB 6.5:
  • >> -2^2

    ans =

    -4
According to Python 2.3.4:
  • >>> -2^2
    -4
According to "Beginning & Intermediate Algebra (3rd Ed)" by K. Martin-Gay (ISBN 0-13-144442-5)
  • 1.4 Calculator Explorations, Order of Operations (p.30):
    Some calculators follow the order of operations, and others do not. To see whether or not your calculator has the order of operations built in, use your calculator to find 2 + 3 · 4. To do this, press the following sequence of keys: [2] [+] [3] [x] [4] [=] (or [enter]). The correct answer will be 14 because the order of operations is to multiply before we add.


    I'm guessing your Casio does not support order of operations.

    5.1 Exponents (p.288):
    As we reviewed in Section 1.4, an exponent is a shorthand notation for repeated factors. For example, 2 · 2 · 2 · 2 · 2 can be written as 2^5. The expression 2^5 is called an exponential expression. It is also called the fifth power of 2, or we say that 2 is raised to the fifth power. The base of an exponential expression is the repeated factor. The exponent is the number of times that the base is used as a factor.

    Example:
    c. (-4)² = (-4) (-4) = 16
    d. -4² = -(4 · 4) = -16

    Notice how similar -4² is to (-4)² in the example above. The difference between the two is the parentheses. In (-4)², the parentheses tell us that the base, or repeated factor, is -4. In -4², only 4 is the base.

    Helpful Hint:
    Be careful when identifying the base of an exponential expression.
    Pay close attention to the use of parentheses.

    In (-3)² the base is -3. (-3)² = (-3) (-3) = 9
    In -3² the base is 3. -3² = -(3 · 3) = -9
    In 2 · 3² the base is 3. 2 · 3² = 2 · 3 · 3 = 18
I hope this helps clear any confusion. smile

- Raccoon

Last edited by Raccoon; 27/02/05 12:02 AM.
Joined: Mar 2004
Posts: 457
D
Fjord artisan
Offline
Fjord artisan
D
Joined: Mar 2004
Posts: 457
its a fx-83WA according to the top, and i typed:

[(-)] [2] [x²] and it spat out -4

But technically -2² is -2 * -2 which equals 4, but (-2)² is 4..eerr. oh sod it i give up confused i was never any good at maths anyway crazy

Last edited by Danthemandoo; 26/02/05 10:48 PM.
Joined: Feb 2004
Posts: 206
D
Fjord artisan
Offline
Fjord artisan
D
Joined: Feb 2004
Posts: 206
Having read this thread and seeing the various arguments for and against - here is an answer that should finalise this.

Regardless of everyone's ability or inability to operate their $5 calculator properly (that's an argument for another day!)

-2^2 , as written, is interpreted as (-2) ^ 2. The correct answer is 4.

That is not my opinion, that is fact. Clear as day, no argument. in this case (-2) is a number, just as 2 is.

Any debate on the correctness of it is not a debate of the maths, but of proponents ability to enter equations into their preferred mathematical software, or the ability of the software to interpret that equation.

Of course, if you enter (2^2) , then +/- you are going to get the answer (negative four).

And yes, 0-2^2 will be interpreted as "0 minus two squared", the correct answer will be "negative four". In this case, the "-" indicates "subtract", and the numbers in the equation are 0, 2 and 2.

However, the previous two equations are not equivalent to "-2^2".

The bottom line: there is no bug here.

Cheers, and yours in mathematica,

DK


Darwin_Koala

Junior Brat, In-no-cent(r)(tm) and original source of DK-itis!
Joined: Feb 2004
Posts: 206
D
Fjord artisan
Offline
Fjord artisan
D
Joined: Feb 2004
Posts: 206
Quote:
according to my casio calculator -2² equals -4. So casio is wrong?

[Edit] above is not meant to sound sarcastic btw, its a serious question


Try typing "2+3*4" into your calculator. The correct answer is "14", but the elCheapo calculators (the "$5 ones" in my previous response) will give an answer of "20".

To answer your question, yes, your casio can be wrong.

Having said that the Calculator can be "wrong", it is up to us as users of the tool to be aware of the limitations. In this case, we need to put ()'s in the right places to get the right answers. Of course, the stronger solution is a consumer boycott of cruddy products that don't give right answers!

BTW, some of the software solutions (I can think of a "scientific calculator" in Linux that fits in this category) are just as bad. Usually the simple "2+3*4" test will find them out.

Cheers,

DK

p.s. given that order of operations is usch an important part of maths, why is it so hard for calculator programmers to get such an easy thing right?


Darwin_Koala

Junior Brat, In-no-cent(r)(tm) and original source of DK-itis!
Joined: Feb 2003
Posts: 2,812
Raccoon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
Edited my post above.

Included picture of my TI-85.
Included output from 3 programming languages (Javascript, Python and MATLAB).
Included verbatim source from college algebra book.

Does anyone here have MAPLE they can try this on?

Would someone try debug.print -2^2 in Visual Basic aswell?


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Joined: Feb 2003
Posts: 2,812
Raccoon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
Quote:
Regardless of everyone's ability or inability to operate their $5 calculator properly (that's an argument for another day!)

-2^2 , as written, is interpreted as (-2) ^ 2. The correct answer is 4.

That is not my opinion, that is fact. Clear as day, no argument. in this case (-2) is a number, just as 2 is.

You are incorrect sir.

Please see me after class.


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
Quote:

-2^2 , as written, is interpreted as (-2) ^ 2. The correct answer is 4.


Since when is -2^2 interpreted as (-2)^2 ?
You realize you just stuck in a bracket into the equation..thereby explicitly changing the equation. So if -2^2 were to be interpreted as (-2)^2 then it would have been expressed as (-2)^2. Therefore it's logically impossible for -2^2 to be interpreted as (-2)^2 because then -2^2 would not exist.

You also realize that you must be explicit about your expressions in both computing and mathematics; and if you haven't realized this yet then i (a) don't know how you managed to pass any math tests past gr.6 in your life and (b) don't know how you're able to use a computer properly. You don't tell a computer to perform -2^2 and then say 'Oh but i meant (-2)^2'. According to order of operation rules that EVERY mathematician follows, exponents are second in line after brackets. -2 is 0-2. This is all stuff you learn in basic math courses in the early high school years.

That being said, -2^2 MEANS 0 - 2^2. If you don't agree, then YOU're wrong.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Joined: Oct 2003
Posts: 14
Q
Pikka bird
Offline
Pikka bird
Q
Joined: Oct 2003
Posts: 14
Prelude> -2^2
(-4)


This be Haskell smile

Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
Code:
(19:11:12) &lt;Sais&gt; perl -wle 'print -2**2;'
(19:11:13) &lt;Sais&gt; -4


I wonder how much more proof is needed. I was sold on the theory alone, personally *shrugs*


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Joined: Oct 2003
Posts: 14
Q
Pikka bird
Offline
Pikka bird
Q
Joined: Oct 2003
Posts: 14
prolog:

test(X) :- X is -2^2.

1 ?- test(X).

X = 4

but i would not put my faith in prolog's parser, or math capabilities for that matter.

Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
Code:
Sub Main()
   Console.Out.WriteLine(-2 ^ 2)
End Sub


-4.

"if MS follows a standard..then it has to be worthy of following"


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Quote:
its a fx-83WA :
[(-)] [2] [x²] and it spat out -4

I dont have a (-) button, and if i used the +/i button when its zero it just stays zero, want negate the number.

what do you get if you go [(-)] [2] [x] [x] [=] ?


Sounds like a accountants calculator, no matter what you put in the result well be what he wants out.

Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
Quote:
Unary - is higher than exponent in a lot of programming languages,


So far i haven't seen one language that follows this rule. Maybe someone can try FORTRAN/ Pascal ? ...Java?

unless by 'lots of programming languages' you mean one or two obscure languages, then i have to disagree


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Page 1 of 4 1 2 3 4

Link Copied to Clipboard