Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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.

share|improve this question
    
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. –  Asaf Karagila May 6 '11 at 12:53
    
@Asaf, It is logic, (that is missing from) this question. –  quanta May 6 '11 at 12:55
    
@quanta: Yes, I see that now. I rolled back to the original tags. –  Asaf Karagila May 6 '11 at 13:01
1  
Yes, Iversonian brackets are fine. –  J. M. May 6 '11 at 13:01
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}$$ –  J. M. May 6 '11 at 13:24
show 1 more comment

5 Answers

up vote 10 down vote accepted

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.

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

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

share|improve this answer
add comment

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.

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

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.

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

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

share|improve this answer
    
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. –  pimvdb May 6 '11 at 13:00
    
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. –  Chris Taylor May 6 '11 at 13:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.