Understanding commutativity and associativity for primitive types
Consider the following code:


  a = (b + c) + d
  
  e = c + (b + f)


Using associativity and commutativity, we can improve it to


  t = b + c
  
  a = t + d
  
  e = t + f


This uses one less addition. Since integer addition (ignoring overflow) is guaranteed to be commutative and associative, an optimizing compiler is allowed to use this optimization. The same isn't quite true for floating point addition, which is not associative.