29
$\begingroup$

I am trying to write the Euclidean algorithm in the following way:

$A = \lfloor A \div B \rfloor \times B + (\text{remainder of}) \: A \div B $

Now is there any symbol I can use to say "remainder of A $\div$ B"? I know that in the C programming language there is the operator % for modulus; is that a valid symbol in maths? Can I write A % B? Or is there some other way?

$\endgroup$
14
  • 4
    $\begingroup$ You can always do $A - (\lfloor A \div B\rfloor \times B)$ $\endgroup$ Commented Dec 21, 2013 at 17:00
  • 15
    $\begingroup$ You can write the remainder as $\ A{\rm\ mod\ }B.$ $\endgroup$ Commented Dec 21, 2013 at 17:01
  • 6
    $\begingroup$ "mod" is pretty standard. $\endgroup$ Commented Dec 21, 2013 at 17:03
  • 1
    $\begingroup$ @ApprenticeHacker mod is overloaded in math. There is use of mod as a binary operator (often in computational conexts) and the more theoretical uses of mod for congruence relations. $\endgroup$ Commented Dec 21, 2013 at 17:05
  • 3
    $\begingroup$ @ApprenticeHacker Ok, I will post an answer. $\endgroup$ Commented Dec 21, 2013 at 17:10

7 Answers 7

44
$\begingroup$

Usually $\, a\bmod b\,$ denotes an $\rm\color{#c00}{operation}\,$ returning the remainder when dividing $\,a\,$ by $\,b\,$ (by the division algorithm), e.g. $\ a\bmod 2 = 1\,$ means $\,a = 1+2k\,$ for some integer $\,k,\,$ i.e. $\,a\,$ is odd. $ $ $\,a\:\!\%\:\!b\, :=\, a\bmod b\,$ is notation sometimes found in programming languages (see below).

Also $\!\bmod\!$ is used as a ternary $\rm\color{#c00}{relation}$ (vs. above binary operation) in congruence arithmetic: $\ a\equiv b\pmod{\! n}\!\!\!\overset{\rm def\!\!}\iff n\mid a-b,\ $ i.e. $\ n\,$ divides $\,a-b,\ $ i.e. $\ a-b = kn\,$ for some integer $\,k.\,$ Such congruence is an equivalence relation for a fixed modulus $\,n.$

These two denotations of $\!\bmod\!$ are related as follows (cf. proofs here or here)

$$ \begin{align} a\color{#90f}\equiv b\!\!\!\pmod{\!n}&\iff a\bmod n\, \color{#0a0}=\, b\bmod n\\[.3em] \color{#90f}{\text{i.e. $\ $ equivalent}} &\iff \text{$\rm\color{#0a0}{equal}$ normal forms}\end{align}\qquad\qquad$$

so $\,a\bmod n\,$ serves as a normal form or canonical representative for the entire equivalence class $\,[a]_n = a + n\:\!\Bbb Z,\,$ i.e. all integers $\,\equiv a\!\pmod{\!n}\,$ [some authors notate $\,a\!\pmod{\!n} := a+n\Bbb Z\:\!$]. The above arrow means that testing congruence $\rm\color{#90f}{equivalence}$ of integers is same as testing $\rm\color{#0a0}{equality}$ of their normal forms (= remainders $\!\bmod n),\,$ just as we can test equivalence of fractions by testing equality of their least-terms normal forms. Similarly we can view the remainder as a "least terms" rep: it is the least nonnegative integer in the class $[a]_n$ of all integers $\,\equiv a\pmod{\!n}$.

The operational use of mod is often more convenient in computational contexts, whereas the relational use often yields more flexibility in theoretical contexts. The difference amounts to whether it is more convenient to work with general equivalence classes vs. canonical / normal representatives ("reps") thereof. For example, it would be quite cumbersome to state the laws of fraction arithmetic if we required that all fractions are in normal (reduced) form, i.e. in lowest terms. Instead, it proves more convenient to have the flexibility to work with arbitrary equivalent fractions. For example, this allows us to state the fraction addition rule in very simple form by first choosing convenient reps having a common denominator.

Analogously, in modular arithmetic the least positive remainder $\,a\bmod n\,$ may not be the most convenient choice of representative of the equivalence class $\,[a]_n =\, a + n\:\!\Bbb Z.\,$ For example, when performing arithmetic checks using casting out elevens and related methods we exploit that $\ {\rm mod}\ 11\!:\ 10\equiv -1\,\Rightarrow\,10^{\large k}\equiv (-1)^{\large k}\equiv \pm1,\,$ which involves choosing a rep of least magnitude $\,\color{#c00}{\bf -1}\,$ vs. $\,\color{#0a0}{10}\in [10]_{11}\! = \{\ldots,\, -23,-12,\color{#c00}{\bf -1},\color{#0a0}{10},21,\,\ldots\}.\,$ Or, as here we can choose reps that nicely yield an exact quotient for modular fractions, e.g. $\!\bmod 11\!:\,\ 9/13\equiv -2/2\equiv -1.\,$ Hence, analogous to fraction addition, we can choose reps which simplify arithmetic. Using least magnitude reps often simplifies other computations too, e.g. it can halve the number of steps in the Euclidean algorithm. Generally the use of congruence classes (vs. canonical reps) provides much greater flexibility, which may yield great simplifications - not only computationally, but also theoretically. These matters are clarified when one studies quotient rings, which yield (algebraic) structure reifications of the congruence rules (which essentially specify that congruence is an equivalence relation compatible with the ring operations (addition and multiplication), cf. general notion of congruence of an algebraic structure).

Generalization $ $ Similar notation is used in other rings that have an analogous (Euclidean) Division Algorithm, e.g. polynomials with coefficients over a field, e.g. consider the Polynomial Remainder Theorem: $\,f(a) = f(x)\bmod x\!-\!a,\,$ or higher-degree generalization such as $\,f(i) = (f(x)\bmod x^2\!+\!1)\bmod x\!-\!i$.

Beware that some authors omit the parentheses in $\, a\equiv b\pmod{\!n}$ instead writing it as follows $\,a\equiv b\mod n\ $ or $\ a = b\mod n,\ $ using \mod vs. \pmod in $\TeX$. These might easily be confused with $\,a = b\bmod n\,$ i.e. $\,a = (b\bmod n),\,$ so one should keep in mind such possible ambiguities in contexts where both forms of $\!\bmod\!$ are in use. See here for more on this.

Beware that some authors write $\,a\pmod{\!n}\,$ to denote $\,a\bmod n,\,$ while others use it to denote the entire congruence class $\,[a]_n = a+ n\Bbb Z.\,$ Keep in mind that such notation overloading might lead to confusion for beginners, e.g. see here.

% notation for $\!\bmod$ $ $ The name % for a normal form $\!\bmod\!$ operation (as in the C programming language) has not percolated to the mathematical community as far as I can tell. I recall many questions on sci.math regarding the meaning of $\rm\, a\:\!\%\:\! b.\, $ As such, if you use this notation in a mathematical forum then I recommend that you specify its meaning. This would not be necessary for $\!\bmod\!$ since that notation is ubiquitous in mathematics (currently more so for congruence than operator form). Be aware, however, that some mathematicians look down on the operational use of mod in the case when it would be more natural to use the congruence form. Apparently the mathematical Gods do too, since doing so can make some proofs quite more difficult (much more so than the above simple case of fraction addition).

$\endgroup$
16
  • 1
    $\begingroup$ Needed to add, if you wish to use a\%b in LaTeX to denote the remainder, you should write a \mathbin{\%} b or better define it by \renewcommand*{\bmod}{\mathbin{\%}} and then it's a \bmod b. $\endgroup$ Commented Dec 21, 2013 at 22:00
  • 3
    $\begingroup$ The percent operator in 'C'-like languages is a remainder operator not a modulo operator. Why Kernighan and Ritchie made this decision is lost in the mists of time, but it is unfortunate. Here is an article on the difference by one of the world's C# experts: blogs.msdn.com/b/ericlippert/archive/2011/12/05/… $\endgroup$ Commented Dec 22, 2013 at 1:13
  • $\begingroup$ @Pieter It is not clear to me what you mean by a "remainder operator vs. modulo operator". Above I distinguish between mod/remainder as an operation that yields a particular (canonical) choice of an equivalence class, vs. the use of mod as a ternary relation $a\equiv b \pmod R \iff (a,b)\in R.\,$ I do not address any choices having to do with implementation of the remainder operations (or the associated division algorithm). $\endgroup$ Commented Dec 22, 2013 at 16:50
  • 4
    $\begingroup$ @BillDubuque: The % operator in C-like languages does not respect the equivalence classes of a finite ring over the integers under normal multiplication and addition when one or more operands is negative. Forgive me if my terminology is not spot on - it has been almost 4 decades since I last did the algebra rigorously. $\endgroup$ Commented Dec 22, 2013 at 16:54
  • 1
    $\begingroup$ @Sarah Mod denotes the operation. I don't recall every seeing "mod" used a a synonym for "remainder". One should not use "modulus" for the remainder since that denotes the dividend, i.e. for congruences mod $n$ it is $n$ that is the modulus (following Gauss), and this is consistent with more general usage in modules, where the modulus denotes the generator of a principal module, here $(n) = n\Bbb Z$. $\endgroup$ Commented Feb 10, 2016 at 1:05
15
$\begingroup$

It's fine to use $A \% B$ for the remainder of $A$ when divided by $B$, provided that you explain what you are using the percent symbol to mean.

It is fairly common in mathematics to need to introduce a symbol to conveniently express something you're going to use: it is infeasible and undesirable to have standardized notation for absolutely everything.

And since this operator is used infrequently in mathematics, there hasn't been standardized notation for it. $A \bmod B$ is probably the most common notation I've seen for it, although it's mildly abusive and possibly a little confusing, since the $\bmod$ symbol is used in other ways too.

Do not just invent notation without explaining your meaning, though. Doing that is not accepted. Also, you should clearly point out how you're normalizing the remainder: e.g. that you are insisting that it is an integer in the interval $[0, |B| - 1]$.

$\endgroup$
4
  • $\begingroup$ +1. How would I go about explaining the meaning of my notation though? Just a statement in english? Something like "Where A % B denotes the remainder when A is divided by B" ? $\endgroup$ Commented Dec 21, 2013 at 17:25
  • 3
    $\begingroup$ @ApprenticeHacker: I think that should be fine in most contexts -- assuming you say how you're normalizing the remainder. There are actual several choices: e.g. you might pick the representative with smallest absolute value: $5\% 3 = -1$. Or you might pick the remainder to have the same sign as the as the first argument but still smaller in magnitude than the second: $-5 \% 3 = -2$. Or you might choose it to have the same sign as the second argument: $-5 \% 3 = 1$ but $5 \% -3 = -1$. $\endgroup$ Commented Dec 21, 2013 at 17:27
  • $\begingroup$ +1, in particular for it's undesirable. I completely agree. $\endgroup$ Commented Dec 21, 2013 at 18:09
  • 1
    $\begingroup$ +1 for noting that % is a remainder operator in C-like languages, and not a modulo operator. $\endgroup$ Commented Dec 22, 2013 at 1:14
11
$\begingroup$

You can write the remainder, mathematically, as $A\; \text{mod}\; B$, which is fairly well-understood to mean the remainder of $A \div B$.

ADDED: In programming, you are correct, $A\,\%\,B$, in many languages, is the operation that returns the remainder when dividing $A$ by $B$. Within mathematics, % is not an accepted notation for this purpose.

$\endgroup$
3
  • $\begingroup$ +1 thanks for the appendix mentioning the programming part. $\endgroup$ Commented Dec 21, 2013 at 17:13
  • $\begingroup$ You're welcome. I saw I hadn't, at first, answered all of your question! ;-) $\endgroup$ Commented Dec 21, 2013 at 17:14
  • 6
    $\begingroup$ I think it may be a little dangerous to believe that "$A\mod B$" is understood to mean the remainder (not to mention the question about the normalization of the remainder. Better to explain it in the set-up, to avoid misunderstandings. $\endgroup$ Commented Dec 21, 2013 at 22:12
4
$\begingroup$

At some time, the use of "mod" in mathematics was restricted to congruences:

$$a\equiv b \pmod n \iff n \, | \, a - b$$

Thus you have always, when $r$ is the remainder of the division $a/b$:

$$a \equiv r \pmod b$$

However, the notation "$a \;\mathrm{mod}\; b$" is now quite widespread, probably with the help of notations from programming languages (it's written exactly this way in Pascal, for instance). It has also been used in very well known computer science books, like "Concrete Mathematics", where it proved to be very useful in mathematical formulas as well.

$\endgroup$
3
  • $\begingroup$ I think formally you select a canonical element from each congruence class and the mod operation maps an element to the canonical element of its congruence class. For some domains this might require the axiom of choice. $\endgroup$ Commented Dec 21, 2013 at 20:19
  • $\begingroup$ @Tim: Unfortunately, in many computer languages the operator that's commonly referred to as the "mod" operator [often denoted as %] does not each equivalence class to a single canonical element, but will map all but one of the classes to two elements each. For example, in current dialects of C, C++, C#, and Java, even though 4≡1 (mod 3), and -5≡1 mod 3, 4%3 will yield 1 and (-5) mod 3 will yield -2. $\endgroup$ Commented Dec 22, 2013 at 5:11
  • $\begingroup$ @supercat yeah, I am actually aware of that. And I think most often when mathematicians speak of the operation they talk about the canonical projection, and reserve modulo for referring to the equivalence relation. $\endgroup$ Commented Dec 22, 2013 at 12:32
1
$\begingroup$

Many mathematicians consider the$\bmod$symbol not as an operation, but as a way to indicate a relation between two numbers. That is, it makes sense to say $$\color{green}{a\equiv b\pmod{n}},$$ meaning that $a-b$ is a multiple of $n$, but it doesn’t make sense to say $$\color{red}{a\bmod n=b\bmod n},$$ since the symbol doesn’t mean anything on its own. Of course, this isn’t the opinion of everyone, and you’ll very probably be understood if you use this notation, but I’d recommend against it.

Instead, you might define a function for the remainder in your text, and use that. I’ve seen some mathematicians use $$\color{blue}{r_n(a)},$$ for example, but you could use any other similar notation, as long as it’s understandable, and looks good (which arguably isn’t true when using the $a\%b$ notation). Furthermore, in your definition, you can specify what happens in the edge cases, if needed. What is the remainder of a negative number? What about a non-integer? Whatever you want to do in these kinds of cases will depend on your interpretation of what a remainder is, which could not necessarily correspond to the normal usage of the$\bmod$notation.

$\endgroup$
1
$\begingroup$

$\newcommand{\rem}{\operatorname{rem}}$

I am using the notation "$\rem_m$" for the operation of taking the remainder modulo $m$ ($m$ being the modulus). Of course, this operation is not well-defined unless we agree about the unique representatives of the congruence classes modulo $m$:

  1. If we agree that $$ 0\le\rem_mn < |m|, $$ then $$ \rem_45 =\rem_{-4}5 = 1,\qquad \rem_4(-5) =\rem_{-4}(-5) = 3. $$

  2. If we agree that $$ -|m| <\rem_mn\le 0, $$ then $$ \rem_45 =\rem_{-4}5 = -3,\qquad \rem_4(-5) =\rem_{-4}(-5) = -1. $$

  3. If we agree that $$ -|m| < 2\rem_mn\le |m|, $$ then $$ \rem_45 =\rem_{-4}5 = 1,\qquad \rem_4(-5) =\rem_{-4}(-5) = -1. $$

Note that Python programming language mixes two of these choices:

>>> 5 % 4
1
>>> 5 % (-4)
-3

I also use the notation "$\rem_I^{\mathstrut}p$" for the remainder of an element $p$ of a commutative ring $R$ modulo an ideal $I$. If $I$ is generated by a single element $d$, then I write it also as "$\rem_d^{\mathstrut}p$." Of course, a certain set of representatives of the congruence classes of $R$ modulo $I$ must be specified first. In rings of (multivariate) polynomials over a field, any well-order on the monomials that is compatible with the divisibility relation provides a canonical choice of representatives of the congruence classes modulo $I$ (and allows to define Groebner bases of $I$). Then, for example, we have: $$ \rem_{X^2 + 1}X^5 = X. $$

P.S. Sometimes I also use the notation "$\rem_U^{\mathstrut}\mathbf{v}$" for the image of a vector $\mathbf{v}$ under the orthogonal projection onto $U^\perp$.

$\endgroup$
0
$\begingroup$

One can also use the "symmetrical" notation $$ A = \left\lfloor {A/B} \right\rfloor B + \left\{ {A/B} \right\}B $$ where $\left\{ x \right\} = x - \left\lfloor x \right\rfloor $ denotes the fractional part, as adopted in the book Concrete Mathematics, but unfortunately this is not a "standard" notation as well.

$\endgroup$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.