Post Reply 
Order of operations - what is 6÷2(1+2) ?
12-21-2020, 11:54 PM
Post: #61
RE: Order of operations - what is 6÷2(1+2) ?
(12-21-2020 08:39 PM)EugeneNine Wrote:  I was always taught that you do the () first (without mention of implied * or not)

So 6÷2(1+2) should simplify to
6÷2(3)
6÷6
1

or distribute:
6÷(2+4)
6÷6
1

notice if you tried without doing the () first the distributive property wouldn't work properly
6÷2*3
3*3
9
or
6÷2+4
3+4
7

So you have to do the () first for the distributive property to work.
But that's only if you multiply (or distribute) the 2 by what's in the parentheses before you do the division.

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
12-22-2020, 12:56 PM
Post: #62
RE: Order of operations - what is 6÷2(1+2) ?
Let's make a deal here: if people get to claim that 6/2(1+2)=1 then I get to say that -2^2=4.
Visit this user's website Find all posts by this user
Quote this message in a reply
12-22-2020, 03:41 PM
Post: #63
RE: Order of operations - what is 6÷2(1+2) ?
(12-22-2020 12:56 PM)Dave Britten Wrote:  Let's make a deal here: if people get to claim that 6/2(1+2)=1 then I get to say that -2^2=4.

Of course it does! That's something we can all agree on. Negation does take priority over powers in all versions of the hierarchies I've seen. (-2)^2 = 4

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
12-22-2020, 08:03 PM (This post was last modified: 12-22-2020 08:05 PM by robve.)
Post: #64
RE: Order of operations - what is 6÷2(1+2) ?
(12-22-2020 03:41 PM)toml_12953 Wrote:  
(12-22-2020 12:56 PM)Dave Britten Wrote:  Let's make a deal here: if people get to claim that 6/2(1+2)=1 then I get to say that -2^2=4.

Of course it does! That's something we can all agree on. Negation does take priority over powers in all versions of the hierarchies I've seen. (-2)^2 = 4

Not so for Python:
>>> -2**2
-4

Yes for Prolog:
?- X is -2^2.
X = 4.

Yes for Unix bc:
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
-2^2
4

Not so for Basic (all Sharp PC and Visual Basic):
-2^2
-4

Yes for Fortran.

Not so for Casio fx-115ES+.

The jury is still out on this one...

"I count on old friends to remain rational"
Visit this user's website Find all posts by this user
Quote this message in a reply
12-22-2020, 10:33 PM
Post: #65
RE: Order of operations - what is 6÷2(1+2) ?
When I went to college, I was fortunate enough to have a professor who was part of the massive layoff from NASA at the end of the Apollo program.

His advice .... hammered into us constantly .... was to NEVER write an equation, a line of code, or make a drawing that required any "assumption" on the part of the reader.

(At NASA, it was observed many times that if you gave someone multiple ways to interpret your equation/design, and one of those ways could cause a massive failure .... that would invariably be the one they chose to use.)

He would frequently write the word "assume" on the chalkboard, and do the standard "Why we never assume." comedic routine.

He also mentioned .... apparently in direct conflict with many current math teachers .... that it doesn't actually cost money (or effort) for each parenthesis you use.

I found his advice invaluable when writing code for real-time data acquisition and control systems, as it seemed/seems every programming language handled equations differently, and indeed the parenthesis became my best friend. Smile

ENTER > =
Find all posts by this user
Quote this message in a reply
12-22-2020, 10:42 PM
Post: #66
RE: Order of operations - what is 6÷2(1+2) ?
Article about Order of arithmetic operations; in particular, the 48/2(9+3) question.

https://math.berkeley.edu/~gbergman/misc...d_ops.html
Find all posts by this user
Quote this message in a reply
12-22-2020, 10:50 PM
Post: #67
RE: Order of operations - what is 6÷2(1+2) ?
(12-22-2020 08:03 PM)robve Wrote:  Yes for Prolog:
?- X is -2^2.
X = 4.

Prolog should return -4 for this, according to its precedence table. (pow higher than unary minus)

Problem is it parsed first number as -2, removed the unary minus.
Forcing it to parse first number as 2, we get the right answer.

B-Prolog Version 8.1, All rights reserved, (C) Afany Software 1994-2014.
| ?- X is -2**2
X = 4
yes
| ?- Two = 2, X is -Two**Two
Two = 2
X = -4
yes

You should not get 2 different answers by replacing Two for 2.
This bug had been fixed in Picat

Picat> X is -2**2
X = -4
yes
Picat> Two = 2, X is -Two**Two
Two = 2
X = -4
yes
Find all posts by this user
Quote this message in a reply
12-22-2020, 11:33 PM
Post: #68
RE: Order of operations - what is 6÷2(1+2) ?
(12-22-2020 10:33 PM)trojdor Wrote:  When I went to college, I was fortunate enough to have a professor who was part of the massive layoff from NASA at the end of the Apollo program.

His advice .... hammered into us constantly .... was to NEVER write an equation, a line of code, or make a drawing that required any "assumption" on the part of the reader.

(At NASA, it was observed many times that if you gave someone multiple ways to interpret your equation/design, and one of those ways could cause a massive failure .... that would invariably be the one they chose to use.)

He would frequently write the word "assume" on the chalkboard, and do the standard "Why we never assume." comedic routine.

He also mentioned .... apparently in direct conflict with many current math teachers .... that it doesn't actually cost money (or effort) for each parenthesis you use.

I found his advice invaluable when writing code for real-time data acquisition and control systems, as it seemed/seems every programming language handled equations differently, and indeed the parenthesis became my best friend. Smile

[Image: 110.gif]

Hardware: Hp48S - Hp50g (5x black + 1 blue) - HP39gII - Hp27s - Casio fx-CG50
Find all posts by this user
Quote this message in a reply
12-23-2020, 12:38 AM
Post: #69
RE: Order of operations - what is 6÷2(1+2) ?
(12-22-2020 08:03 PM)robve Wrote:  Not so for Basic (all Sharp PC and Visual Basic):
-2^2
-4

... and the always-forgotten-by-most-MoHPC-members HP-71B BASIC as well.

Matter of fact, if I ever saw a BASIC evaluating -2^2 as 4 I'd get rid of it.

V.

  
All My Articles & other Materials here:  Valentin Albillo's HP Collection
 
Visit this user's website Find all posts by this user
Quote this message in a reply
12-23-2020, 01:46 AM
Post: #70
RE: Order of operations - what is 6÷2(1+2) ?
(12-23-2020 12:38 AM)Valentin Albillo Wrote:  
(12-22-2020 08:03 PM)robve Wrote:  Not so for Basic (all Sharp PC and Visual Basic):
-2^2
-4

... and the always-forgotten-by-most-MoHPC-members HP-71B BASIC as well.

Matter of fact, if I ever saw a BASIC evaluating -2^2 as 4 I'd get rid of it.

V.

The ANSI/ISO committees agree with you. The international Standard for Full BASIC calls for -2^2 to be -4.

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
12-23-2020, 03:14 AM (This post was last modified: 12-23-2020 03:26 AM by robve.)
Post: #71
RE: Order of operations - what is 6÷2(1+2) ?
(12-22-2020 10:50 PM)Albert Chan Wrote:  
(12-22-2020 08:03 PM)robve Wrote:  Yes for Prolog:
?- X is -2^2.
X = 4.

Prolog should return -4 for this, according to its precedence table. (pow higher than unary minus)

Problem is it parsed first number as -2, removed the unary minus.

I agree. Parsers should not consider the - to be part of the number to avoid this flaw.

So it is ridiculously funny to see the following (note the spacing between - and 2):

?- X is -2^2.
X = 4.

?- X is - 2^2.
X = -4.

On the other hand, SWI-Prolog has a reasonably powerful implementation of multi-precision arithmetic with bigint and rationals (bigint/bigint) https://www.swi-prolog.org/pldoc/man?section=arith something I contributed to to this project many years ago and now fully integrated.

"I count on old friends to remain rational"
Visit this user's website Find all posts by this user
Quote this message in a reply
12-23-2020, 07:06 AM
Post: #72
RE: Order of operations - what is 6÷2(1+2) ?
Hello!

The answer is 1, but why?

We must keep in mind that the sequence of operations
is "x" and "÷" and after "-" and "+".

First solve "( )" after, "[ ]" and after "{ }"

For the given expression:

Lets assume this expressiona as
X =6÷2x(1+2)

Soving "( )"

X = 6÷2x(1+2)
X =6÷2x(3)
X = 6÷6
X =1


In RPN:
6
2
1
2
+
x
÷

Solution,
X = 1

Carlos - Brazil
Time Zone: GMT -3
http://area48.com
Visit this user's website Find all posts by this user
Quote this message in a reply
12-23-2020, 09:03 AM
Post: #73
RE: Order of operations - what is 6÷2(1+2) ?
I am finding this whole discussion rather humorous as it all boils down to which convention you are using, like spelling color or colour.

The Prime completely eliminates this issue in Textbook entry by always using a horizontal fraction bar. Problem solved! Everyone is happy!
Every multi-line calculator should do this.


Some have indicated that we use juxtaposition when writing by hand. I encourage my students to avoid using / for division unless there is only one value after it, like 2/3 or 1/x. If a student writes "1/2x", I might interpret it as 1/(2x). But "1/2 x" with a space might be interpreted as (1/2)x. But when you write with pencil and paper, spaces can vary in size. At what point do you switch meanings?

1/2x
1/2 x
1/2 x
1/2 x
1/2 x
1/2 x

Therefore, I avoid using / except for the unambiguous cases.


Even the symbol can be problematic. I had one former engineer tell me that he would say that
a + b ÷ c + d = a + (b ÷ c) + d
but
a + b / c + d = (a + b) / (c + d)
because he took the / to be a text replacement of the horizontal fraction bar.
Find all posts by this user
Quote this message in a reply
12-23-2020, 09:19 AM
Post: #74
RE: Order of operations - what is 6÷2(1+2) ?
(12-22-2020 03:41 PM)toml_12953 Wrote:  
(12-22-2020 12:56 PM)Dave Britten Wrote:  Let's make a deal here: if people get to claim that 6/2(1+2)=1 then I get to say that -2^2=4.
Of course it does! That's something we can all agree on. Negation does take priority over powers in all versions of the hierarchies I've seen. (-2)^2 = 4

At first I thought you were being facetious, but now I'm not sure. Smile

If -2^2 = (-2)^2 = 4
then would \(e^{-x^2}\) be \(e^{(-x)^2}\) ?
If so, then you'd have to write the bell-curve equation written as \(e^{-(x^2)}\) which I've never seen done.
Find all posts by this user
Quote this message in a reply
12-23-2020, 10:41 AM
Post: #75
RE: Order of operations - what is 6÷2(1+2) ?
(12-23-2020 09:19 AM)Wes Loewer Wrote:  
(12-22-2020 03:41 PM)toml_12953 Wrote:  Of course it does! That's something we can all agree on. Negation does take priority over powers in all versions of the hierarchies I've seen. (-2)^2 = 4

At first I thought you were being facetious, but now I'm not sure. Smile

If -2^2 = (-2)^2 = 4
then would \(e^{-x^2}\) be \(e^{(-x)^2}\) ?
If so, then you'd have to write the bell-curve equation written as \(e^{-(x^2)}\) which I've never seen done.

I really was on the fence but since I'm a BASIC programmer, I use the Standard BASIC convention of -2^2 = -(2^2) = -4.

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
12-23-2020, 03:25 PM (This post was last modified: 12-23-2020 03:26 PM by Thomas Radtke.)
Post: #76
RE: Order of operations - what is 6÷2(1+2) ?
-2^2=x

->

x+2^2=0

->

x=-(2^2)=-4

IAW:

-x^2 is comfortable way to write 0-x^2
Find all posts by this user
Quote this message in a reply
12-24-2020, 08:31 AM
Post: #77
RE: Order of operations - what is 6÷2(1+2) ?
(12-23-2020 03:25 PM)Thomas Radtke Wrote:  -2^2=x

->

x+2^2=0

This is only true if -2^2 is interpreted as -(2^2). If it is interpreted as (-2)^2 then your second line should be:

x - (-2^2) = 0

And this is just as ambiguous as the first line Big Grin

There are only 10 types of people in this world. Those who understand binary and those who don't.
Find all posts by this user
Quote this message in a reply
12-30-2020, 05:41 PM
Post: #78
RE: Order of operations - what is 6÷2(1+2) ?
(12-23-2020 03:14 AM)robve Wrote:  Parsers should not consider the - to be part of the number to avoid this flaw.

So it is ridiculously funny to see the following (note the spacing between - and 2):

?- X is -2^2.
X = 4.

?- X is - 2^2.
X = -4.

You are right.

I peeked at Lua 5.4 source code, llex.c, llex()
read_numeral() only allowed to convert non-negative numbers.

Code:
case '-': {  /* '-' or '--' (comment) */
  next(ls);
  if (ls->current != '-') return '-';
  /* else is a comment */
  ...
}
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9': {
  return read_numeral(ls, seminfo);
}
Find all posts by this user
Quote this message in a reply
01-04-2021, 04:16 AM
Post: #79
RE: Order of operations - what is 6÷2(1+2) ?
-2^2 on the 41CV evaluates to 4
Find all posts by this user
Quote this message in a reply
01-04-2021, 04:26 AM
Post: #80
RE: Order of operations - what is 6÷2(1+2) ?
(01-04-2021 04:16 AM)WrongWay Wrote:  -2^2 on the 41CV evaluates to 4

No, that's not correct.

You have interpreted the algebraic equation shown there to be (-2) ^ 2 and you entered it as
2
CHS
ENTER
2
Y^X

which is not what is written, and that's what this entire discussion is about. If an equation is written in an ambiguous manner, the results are meaningless.

The above equation could also mean - (2^2) which would be -4; most systems that state the orders of precedence put exponentiation at a higher priority than unary negation, so the way I wrote at the start of this sentence would be the correct way to process it.

If the equation is ambiguous and precedence rules are not provided, a 'correct' answer is not possible, and it probably means someone is trying to lure you in to a conversation like this one. Smile

--Bob Prosperi
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: