7
$\begingroup$

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.

  • 0
    I removed the [logic] tag, as it has nothing to do with this. I sense that something else should added but I am not sure what.2011-05-06
  • 0
    @Asaf, It is logic, (that is missing from) this question.2011-05-06
  • 0
    @quanta: Yes, I see that now. I rolled back to the original tags.2011-05-06
  • 1
    Yes, [Iversonian brackets](http://mathworld.wolfram.com/IversonBracket.html) are fine.2011-05-06
  • 0
    I'm sorry for the confusion, I added the logic tag since $x$ should be $true$ or $false$.2011-05-06
  • 1
    Or if you really have to be "mathematical" (whatever that means), you can adapt "piecewise notation": $$x=\begin{cases}\text{true}&\text{ if }n\text{ odd}\\\text{false}&\text{ if }n\text{ even}\end{cases}$$2011-05-06

5 Answers 5

3

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".

  • 0
    You're completely correct. I actually already have working code. I would just like to write this down in a document about the program, using mathematical notation.2011-05-06
  • 0
    In that case I would use indicator functions, defined over a suitable space of events $\Omega$, for $A\in\Omega$ we have $1[A]=1$ if $A$ is true, and $1[A]=0$ if $A$ is false. So, for example, you could write $x = 1[n\textrm{ is odd}]$. Will edit my answer to reflect this.2011-05-06
14

There's a standard notation $a|b$ that means "a divides b", or more precisely "$\exists c : ac = b$" (in the context of a particular ring). So "n is even" can be written concisely as "$2|n$".

  • 1
    To add to this, $a \not\mid b$ means "a does not divide b", so you could write "n is odd" as $2 \not\mid n$.2015-11-12
13

Define $$x \iff n \text{ is odd}$$

then $x$ is true when $n$ is odd and false when n is even.


This is real mathematics you don't have to turn everything into brackets and 5s and squiggly things that make no sense.

  • 0
    I like your answer better than I like mine, sadly for the comment you added below - most people would never think that.2011-05-06
  • 1
    I think I'll just go ahead with this notation, it would be indeed a little silly to overcomplicate it.2011-05-06
  • 0
    For most people outside of mathematics? Yes. For me, not really... I get that notation can be simple and elegant, most people think it always have to include scary drawings of squids in order to look like a real mathematical notation.2011-05-06
  • 0
    @Asaf, yes there is a very common misconception where people try to "mathematize" by writing it in a very odd way because they might have been told "that's not mathematical" before, when in fact it was! I was trying to point out this misconception.2011-05-06
  • 1
    And I was just trying to agree with what you said. Only for some reason, I did it in a very unclear way.2011-05-06
9

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.

  • 0
    As I've said in the comments... :)2011-05-06
  • 0
    @J.M.: Yes, I wish I'd seen your comment before writing this; then I wouldn't have posted. :-) Shall I delete it now?2011-05-06
  • 0
    No need; it's alright to have it here anyway as an answer (at least I'm not the only one who thinks Iversonian brackets are useful fellows).2011-05-06
  • 0
    @J.M.: Oh yes; I'd say whatever notation choices Knuth is enthusiastic about are usually good ideas. :-)2011-05-06
6

An integer $x$ is odd if and only if $x\equiv 1\pmod 2$, that is the remainder when divided by $2$ is nonzero.

Similarly, an integer $x$ is even if and only if $x\equiv 0\pmod 2$.

Edit: after the small discussion in the comments I have decided to add this -

If you want $x$ to have a truth value of whether or not an integer $n$ is even, then $x=(n\equiv 0\pmod 2)$ is a good way to write that. As the expression $n\equiv 0\pmod 2$ is true if and only if $n$ is even.

  • 0
    Thanks. Would it be correct that one can write down $x = ( n ≡ 1 \pmod 2)$?2011-05-06
  • 1
    Do you want to have a formula which is true when a number is even? If so, in which language? In what context?2011-05-06
  • 0
    Well, I already have the programming code, but I'm trying to write it down using mathematical notation. Basically, I would like to say 'x is true if n is odd and false if n is even.2011-05-06
  • 1
    @pimvdb: Then yes, writing $x= (n\equiv 1\pmod 2)$ is a correct way to say "$x$ is true if and only if $n$ is odd".2011-05-06