3
$\begingroup$

In computer programming, I use the mod operation to get the remainder from division, which can be used for many things, such as to check whether a number is even or odd. Is it allowed to use the mod operation in mathematics, or is it only in programming? If so, what is the proper way to write it (do I write something like 3 mod 2 or 3 % 2)? If not, is there a mathematical formula that will get the remainder from division?

$\endgroup$
5
  • 1
    $\begingroup$ $a \equiv b \mod c$, $b$ is the residue. $\endgroup$ Sep 21, 2021 at 14:53
  • 1
    $\begingroup$ The concept of remainder originated from Euclid's division theorem, see division theorem here en.m.wikipedia.org/wiki/Euclidean_division $\endgroup$ Sep 21, 2021 at 14:55
  • 1
    $\begingroup$ @FelixAn I have posted an answer.. does it work well for you? $\endgroup$
    – Spectre
    Sep 21, 2021 at 15:41
  • 1
    $\begingroup$ I have used it recently in this answer. $\endgroup$
    – robjohn
    Sep 22, 2021 at 0:46
  • $\begingroup$ Thanks for all your answers! $\endgroup$
    – Felix An
    Oct 5, 2021 at 18:10

4 Answers 4

7
$\begingroup$

The notation is $$a\equiv b \pmod c $$ which stands for $c$ divides $a-b$

For example $$27\equiv 2\pmod 5$$

It is a mathematical tool which is helpful in solving number theory problems.

For example you may use $ \pmod 5 $ arithmetics to show that every fifth term in the Fibbonaci's sequence,$$1,1,2,3,5,8,13,21,34,55,... $$ is divisble by $5$

The sequence in $\pmod 5$ turns out to be $$1,1,2,3,0,3,3,1,4,0,4,4,3,2,0,2,2,4,1,0,1,1,....$$ We are done!

$\endgroup$
1
  • $\begingroup$ The notation $a\equiv b\pmod{c}$ is not the same as the mod operation in programming (i.e., the remainder after division), which is what the question is asking about. The result of $a\mathbin{\text{mod}}c$ is a number in a specific range, but, for example, $2\equiv 27\pmod{5}$. It is certainly the case that $a\equiv a\mathbin{\text{mod}}c\pmod{c}$, though. In other words, they're asking for standard notation for modular reduction. $\endgroup$ Sep 21, 2021 at 23:33
5
$\begingroup$

I have seen $a\mathbin{\%} b$ in a math textbook to mean the remainder after dividing $a$ by $b$. Knuth in his mathematically heavy tome The Art of Computer Programming went for $a\mathbin{\text{mod}} b$ instead. Generally speaking, so long as you define your notation, you can use whatever notation you want.

For example, the first book specifically defined the remainder to satisfy $0\leq a\mathbin{\%}b <\lvert b\rvert$. There are a number of conventions for the remainder, and this is the "round the quotient toward negative infinity" convention.

In many programming languages, like C, they use a different convention for $\%$. The above convention is what Python uses, however. Other languages, like Haskell, have both mod and rem to be able to use the above convention and the C convention.

$\endgroup$
2
$\begingroup$

It is a mathematical concept originally. You write $$a \equiv b \pmod c$$, here $b$ is the residue. This is related to Euclid's algorithm.

$\endgroup$
3
  • 2
    $\begingroup$ $b$ doesn't have to be the residue using that notation. For example, $5\equiv 7\pmod{2}$. $\endgroup$ Sep 21, 2021 at 15:20
  • $\begingroup$ @KyleMiller don't make the life of a beginner difficult! $\endgroup$ Sep 21, 2021 at 15:22
  • 2
    $\begingroup$ Right -- your answer suggests that this is a drop-in replacement for $\%$, which I think is rather misleading. I first learned modular arithmetic from programming, and it took me a long time to clear out my misconceptions about congruence-modulo-$c$ because of this. $\endgroup$ Sep 21, 2021 at 15:29
1
$\begingroup$

You get the remainder of a division when you write $a \bmod {b} = c$. Here, we use the MathJax command \bmod (meaning binary mod, which simply means taking the remainder. I at first knew nothing about it till a colleague here told me of it while editing an article. When showing congruences (i.e., showing the equivalence in the remainder obtained on dividing two numbers by the same divisor) we use \equiv ( which yields $\equiv$ symbol). An exemplar usage : $3 \equiv 8 \pmod{5}$ (I typed $3 \equiv 8 \pmod{5}$ which automatically yields the $\mod 5$ part in parenthesis). This basically refers to the fact that both numbers belong to the same residue class, which is $\lbrace 3,8,13,\dots\rbrace$ in this case if we take only the positive integers.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .