Is there a established notation for the remainder of integer division?

For example, I want a function gives zero for non-negative even integers and one for non-negative odd integers. In computer code I would write:

i % 2

But if I want to do something similar in a paper, on Latex, how should I write it? I want to use this as part of a larger expression. Something like:

$$\sum_i 2^{i\%2}$$

but I don't think that is the customary way?

  • $\begingroup$ As an aside, that particular expression could be written as ${\displaystyle \sum_{i}}2^{(1-(-1)^i)/2}$ $\endgroup$
    – Mark S.
    Jan 2 at 19:00

3 Answers 3


I think the three most common notations are:

  • $x \bmod n$
  • $x \operatorname{rem} n$
  • $x \% n$

The first is an abuse of notation and somewhat misleading to people learning the subject, but it is common. The others, IMO, would be readily understood if you state once at the beginning of whatever you're writing what the notation means.

For your specific application you could also use the iverson bracket:

  • $ [i \text{ is odd} ]$

The Iverson bracket is basically the mathematical incarnation of the usual ways to coerce a boolean value to an integer: it gives $0$ when false and $1$ when true.

In the specific formula you write, a possibly more useful alternative is $$ 2^{[i \text{ odd} ]} = 1 + [i \text{ odd} ]$$ since this form is more amenable to doing series manipulations. In fact, the context of series manipulations is the first time I saw extensive use of the Iverson bracket.

  • $\begingroup$ Oh, I'm sure you talking about Knuth's paper, "Two Notes on Notation" $\endgroup$
    – a06e
    Oct 11, 2017 at 14:39
  • $\begingroup$ @becko: Actually I learned it from the text "Concrete Mathematics". Knuth is one of the authors, though. $\endgroup$
    – user14972
    Oct 11, 2017 at 14:41
  • 1
    $\begingroup$ It's not an abuse of notation: the spacing is different from the spacing in the congruence relation. $\endgroup$
    – Bernard
    Oct 11, 2017 at 14:52

Given the integer $x$ and the modulus $n$, it would be standard to write $$ x \mod n. $$ To be a little more precise, if $r$ is the remainder of $x$ after division by $n$ in accordance with the Division Algorithm, we have $$ x \equiv r \mod n. $$

  • $\begingroup$ As part of a larger expression? For instance, $\sum_i 2^{(i \mod 2)}$. There is a wide space there that I can't get rid of. $\endgroup$
    – a06e
    Oct 11, 2017 at 14:29
  • $\begingroup$ You can cheat it and \mathrm{mod} will kill the space. $\endgroup$
    – Randall
    Oct 11, 2017 at 14:30
  • 3
    $\begingroup$ @becko: Use \bmod; it formats like $x \bmod n$. I think the "b" stands for "binary operation". $\endgroup$
    – user14972
    Oct 11, 2017 at 14:32
  • $\begingroup$ Ah, thanks for the tip! $\endgroup$
    – Randall
    Oct 11, 2017 at 14:33

I know the notations

  • $\operatorname{mod}(x,n)$;
  • $x\bmod n$.

Note the latter has a tighter spacing from the spacing in the congruence relation $x\equiv y\mod n$.


You must log in to answer this question.

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