TITLE: 'is odd' / 'is even' notation
QUESTION [7 upvotes]: I would like to write down that $x$ is $true$ if $n$ is odd and $false$ if $n$ is even.
So far I made this up:
$x = ( n - 2⌊\frac{n}{2}⌋ = 1)$
However, I was wondering whether this can be expressed this way at all, and whether there is a general notation that means 'is odd' or 'is even'.
Thanks for any hints on this.

REPLY [9 votes]: I'm not sure what it means to define "x" as being "true" or "false": boolean variables as a data type are not much used in mathematics. If you want 1 or 0, then there is a notation called Iverson bracket, popularized by Knuth (and others) in the book Concrete Mathematics and elsewhere, that uses square brackets for what you want: [P] is the variable that is 1 if P is true and 0 otherwise. Thus you could write any of:

$x = \left[n - 2\lfloor\frac{n}{2}\rfloor = 1\right]$ (almost what you wrote)
$x = \left[ n \equiv 1 \mod 2\right]$ or 
$x = \left[2|n\right]$ or simply,
$x = [n\text{ is odd}]$, which is best. (Even better would be to write "x is 1 if n is odd and 0 otherwise", but presumably you don't want to write that for some reason.)

In some areas especially of probability, they use a notation like $1_{\text{{n is odd}}}$ or whatever, with the condition written as a subscript to 1.

REPLY [3 votes]: It seems as though you're coming at this from a programming perspective, ie you want to write a function boolean isEven(int n) which returns true if n is even and false if it is odd.
The simplest method would be to check the final bit of the binary representation of n. If that bit is a 0 you return true, and if it is a 1 you return false.
Edit (as per comment below): You can use indicator functions defined as $1[A]=1$ if $A$ is true and $1[A]=0$ if $A$ is false, meaning that you might want to write
$$x = 1[n\textrm{ is odd}]$$
or perhaps
$$x := 1[n\textrm{ is odd}]$$
where $:=$ is mathematical notation understood to mean "is defined to be".