Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I feel like this is far simpler than I am making it. I am looking for a function $y=f(x)$ such that:
$f(1) = 1$

$f(2) = 1 $

$f(3) = 3 $

$f(4) = 3 $

$f(5) = 5 $

$f(6) = 5$

That is to say, all the evens become the preceding odd number. Does this function exist? If so, what is it? Lastly, how would a mathematician write it?

share|cite|improve this question
up vote 8 down vote accepted

How about

$$f(n) = n + \frac{(-1)^{n + 1} - 1}{2}$$

share|cite|improve this answer
Can you comment a bit on how were you able to recognize this relationship? What did you recognize first that made you realize the function would satisfy the values? – mwjohnson Sep 4 '13 at 5:49
Using things that look like $(-1)^n - 1$ are common for when you want to differentiate even / odd, since it'll be zero for even numbers and a non-zero constant otherwise. The rest of the stuff is just rescaling and adjusting it to be zero for odds. – user61527 Sep 4 '13 at 6:03

$$f(x)=\left\lfloor \frac{x-1}{2}\right\rfloor+\left\lfloor \frac{x+1}{2}\right\rfloor $$

share|cite|improve this answer

Try $$2\left\lfloor\frac{x+1}2\right\rfloor-1$$ which uses the floor function. The floor function is written as $\text{floor}(x)=\lfloor x \rfloor$, and is the greatest integer $n$ with $n\leq x$.

share|cite|improve this answer

Hint: Have you heard of the floor function? A few transformations of that should get you what you want.

share|cite|improve this answer

Consulting OEIS, gives us more:

   a(n) = 2*floor(n/2) + 1.

   G.f.: (1+x+x^2+x^3)/(1-x^2)^2; - Paul Barry, Oct 14 2005

   a(n)=n+[1+(-1)^n]/2, with n>=0 - Paolo P. Lava, May 08 2007

   a(n)=2*a(n-2)-a(n-4); a(0)=1, a(1)=1, a(2)=3, a(3)=3. - Philippe DELEHAM, Nov 03 2008

   a(n)=2*n-a(n-1), with a(0)=1. - Vincenzo Librandi, Nov 13 2010
share|cite|improve this answer

Your Answer


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.