generalized arithmethic optimizations