Remainder
In mathematics, the remainder is the amount "left over" after performing some computation. In arithmetic, the remainder is the integer "left over" after dividing one integer by another to produce an integer quotient. In algebra of polynomials, the remainder is the polynomial "left over" after dividing one polynomial by another. The modulo operation is the operation that produces such a remainder when given a dividend and divisor.
Alternatively, a remainder is also what is left after subtracting one number from another, although this is more precisely called the difference. This usage can be found in some elementary textbooks; colloquially it is replaced by the expression "the rest" as in "Give me two dollars back and keep the rest." However, the term "remainder" is still used in this sense when a function is approximated by a series expansion, where the error expression is referred to as the remainder term.
Integer division
Given an integer a and a non-zero integer d, it can be shown that there exist unique integers q and r, such that and. The number q is called the quotient, while r is called the remainder.The remainder, as defined above, is called the least positive remainder or simply the remainder.
In some occasions, it is convenient to carry out the division so that a is as close to an integral multiple of d as possible, that is, we can write
In this case, s is called the least absolute remainder. As with the quotient and remainder, k and s are uniquely determined, except in the case where and. For this exception, we have:
A unique remainder can be obtained in this case by some convention—such as always taking the positive value of s.
Examples
In the division of 43 by 5, we have:so 3 is the least positive remainder. We also have that:
and −2 is the least absolute remainder.
These definitions are also valid if d is negative, for example, in the division of 43 by −5,
and 3 is the least positive remainder, while,
and −2 is the least absolute remainder.
In the division of 42 by 5, we have:
and since 2 < 5/2, 2 is both the least positive remainder and the least absolute remainder.
In these examples, the least absolute remainder is obtained from the least positive remainder by subtracting 5, which is d. This holds in general. When dividing by d, either both remainders are positive and therefore equal, or they have opposite signs. If the positive remainder is r1, and the negative one is r2, then
For floating-point numbers
When a and d are floating-point numbers, with d non-zero, a can be divided by d without remainder, with the quotient being another floating-point number. If the quotient is constrained to being an integer, however, the concept of remainder is still necessary. It can be proved that there exists a unique integer quotient q and a unique floating-point remainder r such that with.Extending the definition of remainder for floating-point numbers, as described above, is not of theoretical importance in mathematics; however, many programming languages implement this definition.
Methods for Finding Remainders
- Long Division: A traditional method for dividing numbers manually, which involves repeated subtraction and digit placement.
- # Write the division problem in the long division format, with the divisor outside the division symbol and the dividend inside.
- # Determine how many times the divisor can go into the first digit or set of digits of the dividend.
- # Divide the selected digits by the divisor and write the quotient above the division symbol.
- # Multiply the quotient by the divisor and write the result underneath the selected digits.
- # Subtract the result from step 4 from the selected digits to find the remainder.
- # If there are more digits in the dividend, bring down the next digit.
- # Repeat steps 2 through 5 until there are no more digits in the dividend to bring down.
- # If the remainder is less than the divisor and there are no more digits to bring down, stop.
- # If there are still digits to bring down but the remainder is not less than the divisor, continue.
- # The final remainder is the result when all digits have been processed and no more digits can be brought down.
- Modular Arithmetic: Utilizing modular arithmetic concepts to calculate remainders efficiently, particularly useful in computer science and cryptography.
- # Start with a dividend and a divisor.
- # Divide the dividend by the divisor.
- # Take the remainder obtained from the division.
- # The remainder is the result of the modular arithmetic operation.
- Remainder Theorem: A mathematical theorem that provides a systematic approach to finding remainders when dividing polynomials.
- # Identify the polynomial P and the linear divisor x-a.
- # Evaluate P, where a is the root of the linear divisor.
- # The value obtained in step 2 is the remainder when P is divided by x-a.
In programming languages
- Pascal chooses the result of the mod operation positive, but does not allow d to be negative or zero. 6.7.2.2
- C99 chooses the remainder with the same sign as the dividend a.
- Perl, Python choose the remainder with the same sign as the divisor d.
- Scheme offer two functions, remainder and modulo – Ada and PL/I have mod and rem, while Fortran has mod and modulo; in each case, the former agrees in sign with the dividend, and the latter with the divisor. Common Lisp and Haskell also have mod and rem, but mod uses the sign of the divisor and rem uses the sign of the dividend.
Polynomial division
where
where "deg" denotes the degree of the polynomial. Moreover, q and r are uniquely determined by these relations.
This differs from the Euclidean division of integers in that, for the integers, the degree condition is replaced by the bounds on the remainder r The similarity between Euclidean division for integers and that for polynomials motivates the search for the most general algebraic setting in which Euclidean division is valid. The rings for which such a theorem exists are called Euclidean domains, but in this generality, uniqueness of the quotient and remainder is not guaranteed.
Polynomial division leads to a result known as the polynomial remainder theorem: If a polynomial f is divided by, the remainder is the constant.