So I've been working on a formula compiler and came across a bug in the order of operations that made
$2 - 2 + 2 = 4$
and have now learned to appreciate order of operations and that subtraction is not commutative.
I found that the same issue occurred with for division, where
$16 / 8 * 2 = 1$
So now I've fixed the issue, and am looking for more test cases.
while I can easily find them of the form
$a ÷ b * c$
where evaluation left-to-right differs from right-to-left, I cannot seem to find an example where
$a * b ÷ c$
is sensitive ltr vs rtl evaluation... likewise for subtraction!
So, I'm starting to suspect that if the operator have the same precedence, then
$a (commutativeop) b (noncommutativeop) c$
is not sensitive to ltr vs rtl, but that
$a (noncommutativeop) b (commutativeop) c$
is.
Have I encountered something fundamental going on here, or am I bad at looking for examples, or is this just a coincidence with division and subtraction?
PS please add appropriate tags
Edit in response to comment.
I misread the question. Original answer below. New discussion, not really an answer to your question. But it may help.
Operator precedence is subtle, and about associativity, not commutativity. The correct mathematical way to think about subtraction is in terms of the additive inverse - that would be the "unary $-$" operator in a computer language. Then $$ a - b + c \quad \text{ is really } \quad a + (-b) + c . $$ Precedence binds the unary $-$ more tightly than $+$. After you've invoked it you have commutative and associative addition.
I think your problem is really about order of operations and hence associativity, not about which operations commute. For example $$ "a\times b-c": (a \times b) -c \ne a \times (b-c) $$ and $$ "a - b \times c": (a - b) \times c \ne a - ( b \times c) $$ It doesn't matter whether the noncommutative subtraction is first or second.