Understanding commutativity and associativity for primitive types In Elements of Programming Interviews, authors talk about a tip for understanding how to use primitive types (int, double, etc).


  Be aware that commutativity and associativity can be used to perform operations in parallel and reorder operations.


I'm having trouble even imagining what these means in the context of bits. For anyone who better grasps what this means, could you explain it and flesh it out with some examples?
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.