# PEMDAS unexpected result

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?

edit retag close merge delete

Sort by ยป oldest newest most voted

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

more

thank you very much.

( 2020-03-08 21:11:10 +0100 )edit

@13negro you can accept the answer by clicking the check mark below the answer's score.

This will mark your question as solved.

( 2021-02-11 00:57:54 +0100 )edit