Apply sum and difference rules (#521)