• 1 Post
  • 10 Comments
Joined 1 year ago
cake
Cake day: February 19th, 2024

help-circle








  • Except it does matter. I left some examples for another post with multiplication and division, I’ll give you some addition and subtraction to see order matter with those operations as well.

    Let’s take:
    1 + 2 - 3 + 4

    Addition first:
    (1 + 2) - (3 + 4)
    3 - 7 = -4

    Subtraction first:
    1 + (2 - 3) + 4
    1 + (-1) + 4 = 4

    Right to left:
    1 + (2 - (3 + 4))
    1 + (2 - 7)
    1 + (-5) = -4

    Left to right:
    ((1 + 2) - 3) + 4
    (3 - 3) + 4 = 4

    Edit: You can argue that, for example, the addition first could be (1 + 2) + (-3 + 4) in which case it does end up as 4, but in my opinion that’s another ambiguous case.


  • So let’s try out some different prioritization systems.

    Left to right:

    (((6 * 4) / 2) * 3) / 9
    ((24 / 2) * 3) / 9
    (12 * 3) / 9
    36 / 9 = 4
    

    Right to left:

    6 * (4 / (2 * (3 / 9)))  
    6 * (4 / (2 * 0.333...))  
    6 * (4 / 0.666...)  
    6 * 6 = 36
    

    Multiplication first:

    (6 * 4) / (2 * 3) / 9  
    24 / 6 / 9
    

    Here the path divides again, we can do the left division or right division first.

    Left first: 
    (24 / 6) / 9  
    4 / 9 = 0.444...
    
    Right side first:  
    24 / (6 / 9)  
    24 / 0.666... = 36
    

    And finally division first:

    6 * (4 / 2) * (3 / 9)  
    6 * 2 * 0.333...  
    12 * 0.333.. = 4 
    

    It’s ambiguous which one of these is correct. Hence the best method we have for “correct” is left to right.