• Everything on the left hand symbol is divided by everything on the right hand of the symbol.
or
• The operator only deals with the term to its immediate left and right.
Which is correct? I tried to find a specific definition for the usage of the division operator but I couldn't find it.
Direct answer
There is no syntactic definition of what is a mathematical expression, and how to interpret it. For more you can read Syntactic theory of mathematical expressions.
Still the basic convention is the operands of arithmetic operators ($\small + - \times \div$) are limited to the closest term on each side.
- Term: Terms are separated by a + or - sign in an overall expression
If you need to include more, then parentheses must be used to group several parts into a single operand. Examples:
- $\small 2 + 4/2 + 6 = 10$ (standard rule)
- $\small (2+4) / 2 + 6 = 9$ (altering interpretation using parentheses)
Note a term can include functions. Function themselves apply to the next term only: $\small \sin 2 \pi / 3 + 2$ means $\small \sin (\frac 2 3 \pi) + 2$.
This closest term rule makes the use of any precedence order unnecessary in math, contrary to programming languages which heavily rely on it.
I'm providing additional elements in case you're interested.
Lack of syntactic rules for mathematical expressions
Unfortunately math conventions, contrary to what is often assumed, are not so strict, due to history, with discoveries in different countries and mathematicians inventing symbolic representations matching their own cultural environment. Sometimes multiple conventions coexist (e.g. Lagrange vs. Leibniz for differential calculus)
In math there are a lot of details which are not defined, how an expression is interpreted is one, but think of something very simple, the multiplication of two numbers. The formal definition of multiplication in base 10 involves polynomials and convolution, the product of 123 by 345 in base 10 is something like:
- $p_1(10) = 1 \times 10^2 + 2 \times 10^1 + 3 \times 10^0$
- $p_2(10) = 3 \times 10^2 + 4 \times 10^1 + 5 \times 10^0$
- $p_1(10) \times p_2(10) = (p_1 \ast p_2) (10)$
Performing a regular multiplication of the coefficients with single digit products, row indentation and column summation is just a convolution of the two polynomials expressing numbers in base 10.
Order of precedence in programming languages
Some confusion can be introduced by the similarity with programming language operators where operands are distributed to neighboring operators using precedence rules. So even if this is not part of your question, let's provide some details for comparison.
In math, conventions often rely on typography:
- $\small 2^{2+1} + 5 = 13$
In most programming languages the possibility of using superscripts like above doesn't exist, an explicit exponentiation symbol, which can be ^ or ** according to the language syntax, is used, but this prevents to identify where the exponent ends, and only the first value (not even the first term) is used unless parentheses are used:
- $\small 2^{1+6/2} + 1$ is coded
2**(1+6/2) + 1 in Python
There are many cases like this one, the constant use of parentheses is not practical. Syntactic rules, which have no equivalent in math, have been set to associate values to operators by default. Each operator has a precedence level associated to it, and an operands feeds either the left or right neighboring operators according to which has the highest precedence.
Order of precedence in Python:
Level 0: highest precedence allowing to group simple expressions into complex expressions before further parsing takes place.
Level 3: Exponentiation. Higher precedence than arithmetic operators, so 2 ** 1+2 gives 4, not 8.
Level 4: unary minus used to create negative quantities (the binary minus, the subtraction operator, uses the same symbol, but is totally separate).
Level 6: Multiplication and division.
Level 7: Addition and subtraction.
With the rules above 3*(2+4)/-3**2 gives -2.