8
$\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.

$\endgroup$
6
  • $\begingroup$ 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. $\endgroup$
    – Asaf Karagila
    May 6, 2011 at 12:53
  • $\begingroup$ @Asaf, It is logic, (that is missing from) this question. $\endgroup$
    – quanta
    May 6, 2011 at 12:55
  • $\begingroup$ @quanta: Yes, I see that now. I rolled back to the original tags. $\endgroup$
    – Asaf Karagila
    May 6, 2011 at 13:01
  • 1
    $\begingroup$ Yes, Iversonian brackets are fine. $\endgroup$ May 6, 2011 at 13:01
  • 1
    $\begingroup$ 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}$$ $\endgroup$ May 6, 2011 at 13:24

5 Answers 5

15
$\begingroup$

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

$\endgroup$
1
  • 1
    $\begingroup$ 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$. $\endgroup$
    – user289310
    Nov 12, 2015 at 0:51
13
$\begingroup$

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.

$\endgroup$
5
  • $\begingroup$ I like your answer better than I like mine, sadly for the comment you added below - most people would never think that. $\endgroup$
    – Asaf Karagila
    May 6, 2011 at 13:04
  • 1
    $\begingroup$ I think I'll just go ahead with this notation, it would be indeed a little silly to overcomplicate it. $\endgroup$
    – pimvdb
    May 6, 2011 at 13:05
  • $\begingroup$ 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. $\endgroup$
    – Asaf Karagila
    May 6, 2011 at 13:11
  • $\begingroup$ @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. $\endgroup$
    – quanta
    May 6, 2011 at 13:13
  • 1
    $\begingroup$ And I was just trying to agree with what you said. Only for some reason, I did it in a very unclear way. $\endgroup$
    – Asaf Karagila
    May 6, 2011 at 13:15
9
$\begingroup$

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.

$\endgroup$
4
  • $\begingroup$ As I've said in the comments... :) $\endgroup$ May 6, 2011 at 13:14
  • $\begingroup$ @J.M.: Yes, I wish I'd seen your comment before writing this; then I wouldn't have posted. :-) Shall I delete it now? $\endgroup$ May 6, 2011 at 16:44
  • $\begingroup$ 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). $\endgroup$ May 6, 2011 at 16:46
  • $\begingroup$ @J.M.: Oh yes; I'd say whatever notation choices Knuth is enthusiastic about are usually good ideas. :-) $\endgroup$ May 6, 2011 at 17:05
7
$\begingroup$

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.

$\endgroup$
4
  • 1
    $\begingroup$ Thanks. Would it be correct that one can write down $x = ( n ≡ 1 \pmod 2)$? $\endgroup$
    – pimvdb
    May 6, 2011 at 12:53
  • 2
    $\begingroup$ Do you want to have a formula which is true when a number is even? If so, in which language? In what context? $\endgroup$
    – Asaf Karagila
    May 6, 2011 at 12:54
  • 1
    $\begingroup$ 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. $\endgroup$
    – pimvdb
    May 6, 2011 at 12:57
  • 2
    $\begingroup$ @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". $\endgroup$
    – Asaf Karagila
    May 6, 2011 at 12:58
3
$\begingroup$

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

$\endgroup$
2
  • $\begingroup$ 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. $\endgroup$
    – pimvdb
    May 6, 2011 at 13:00
  • $\begingroup$ 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. $\endgroup$ May 6, 2011 at 13:08

You must log in to answer this question.

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