Parity (mathematics) (source code)

= Parity
{disambiguate=mathematics}
{wiki}

= Integer parity
{synonym}

The <parity (mathematics)> of an <integer> records which of two classes it belongs to: an <even number> is divisible by $2$, and an <odd number> is not. <Euclidean division> gives the unique expression
$$
n=2q+r,\qquad q\in\mathbb Z,\quad r\in\{0,1\}.
$$
The <remainder> $r=n\bmod2$ encodes the parity. This applies to <negative numbers> too: $-3=2(-2)+1$ is odd, while $-4=2(-2)$ is even. Zero is an <even number>.

Reduction <modulo> $2$ respects <addition> and <multiplication>, so the <quotient ring> $\mathbb Z/2\mathbb Z$ records parity arithmetic. If $a,b$ have remainders $r,s$, then $a+b$ has remainder $(r+s)\bmod2$, and $ab$ has remainder $rs$. In particular, the <sum> of two <odd integers> is even, whereas their <product> is odd. The relation $-n\equiv n\pmod2$ shows that changing sign preserves parity.