Computer Arithmetic: Logic, Calculation and Rewriting