Calculus How To

Modulo Function

Share on

Calculus Definitions >

The modulo function represents the remainder that results from dividing two different positive numbers. For example, 7 modulo 2 is 1 because the division of 7 by 2 has a quotient of 3, leaving a remainder of 1. Although the modulo function initially seems like an esoteric mathematical function, it does have a few practical applications including identifying odd or even numbers in worksheets, databases, or complex formulas (Bluttman & Aitken, 2018); In programming, the modulo can be used to alternate values in a loop.

Formal Definition of Modulo Function

An arbitrary positive integer, a, can always be written in the following form

a = n * q + r

 

Where:

  • q is the quotient,
  • r is the remainder, and
  • n is an integer.

Within this formal definition, the modulo expression can be solved: (a mod n) = r.

 

Calculating the Modulo

The basic steps are:

Step 1: Set up the equation. Given the expression (a mod n), set up the equation a = n * q + r.

Step 2: Maximize the quotient, q.


Step 3: Solve for the remainder, r.

Step 4: (a mod n) = r.

Example Problems

Problem 1: Find (18 mod 5) using the formal definition of modulo.

Solution:

Step 1: In the context of the formal definition, a = 18 and n = 5. Therefore,

18 = 5 * q + r

 

Step 2: Maximize the quotient. For this equation, q=3.

Step 3: Solve for the remainder:

  • 18 = 5 * 3 + r
  • 18 = 15 + r
  • r = 3

Therefore, (18 mod 5) = 3.

 

Problem 2: Find (17 mod 4) using the formal definition of modulo.

Solution: Within the formal definition of modulo, we identify that a=17 and n=4. Therefore,

17 = 4 * q + r

 

The maximum value for the quotient is q = 4.

Solving for the remainder,

17 = 4 * 4 + r


17 = 16 + r

r = 1

 

Thus, (17 mod 4) = 1.

 

Problem 3: Find (3 mod 1) using the formal definition of modulo.

Solution: From the formal definition of modulo, we have

3 = 1 * q + r

 

In this case, the maximum value of q=3.

3 = 1 * 3 + r

 

Solving for the remainder, r = 0. In fact, any integer modulo 1 is always equal to zero, since q=a.

 

Special Considerations with the Modulo Function

  • The modulo function only accepts positive natural numbers. You cannot evaluate the modulo of a negative number or a fraction.
  • The remainder can only be calculated after the quotient is evaluated correctly. If the quotient is not at its maximum value, then your calculation for the remainder will be incorrect.

References

Bluttman, K. & Aitken, P. Excel Formulas and Functions For Dummies. 2018..

CITE THIS AS:
Stephanie Glen. "Modulo Function" From CalculusHowTo.com: Calculus for the rest of us! https://www.calculushowto.com/modulo-function/
------------------------------------------------------------------------------

Need help with a homework or test question? With Chegg Study, you can get step-by-step solutions to your questions from an expert in the field. Your first 30 minutes with a Chegg tutor is free!

Leave a Reply

Your email address will not be published. Required fields are marked *