Subtraction algorithm