Ask Your Question
0

PEMDAS unexpected result

asked 2020-03-05 08:45:50 -0500

I have entered the following expression in sagemath 9.0 on Linux

(3^2 * 4^2)-(8^2 - 3^2)//(6^2-9*8)

and sage gives 146 as the result. Nevertheless, I solved on paper and I get 145.

So my question is Am i doing something wrong with PEMDAS on sagemath?

Thank you in advance.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
2

answered 2020-03-07 10:03:48 -0500

eric_g gravatar image

The behavior you observe is due to the floor division // having a higher precedence than the subtraction operator - but a lower precedence than the negative operator -, see the table of operator precedence. Compare:

sage: a = 8^2 - 3^2; a
55
sage: b = 6^2 - 9*8; b
-36
sage: n(a/b)
-1.52777777777778
sage: a//b
-2
sage: 0 - a//b  # subtraction operator
2
sage: - a//b  # negative operator
1
sage: 0 + (- a//b)  # different from 0 - a//b  
1
edit flag offensive delete link more
0

answered 2020-03-08 15:11:10 -0500

thank you very much.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2020-03-05 08:45:50 -0500

Seen: 28 times

Last updated: Mar 08