Why Operators Are Useful

Why Operators Are Useful

Now consider the associative law:

    add(x, add(y, z)) == add(add(x, y), z)    (2)

Equation (2) can be rewritten using operators:

    x + (y + z) == (x + y) + z    (2a)

This is much less confusing than (2), and leads to the observation that the parentheses are redundant, so now we can write

    x + y + z    (3)

without ambiguity (it doesn’t matter whether the + operator binds tighter to the left or to the right). Here’s one more example, about the identity element of addition:

    add(x, 0) == add(0, x) == x    (4)

compare to

    x + 0 == 0 + x == x    (4a)

The general idea here is that once you’ve learned this simple notation, equations written using them are easier to *manipulate* than equations written using functional notation — it is as if our brains grasp the operators using different brain machinery, and this is more efficient. Compare to:

    n * (x + y) == n * x + n * y    (5a)

Notice how this also uses relative operator priorities.

Source: neopythonic.blogspot.com