# Function Converts Even numbers to preceding Odd

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?

-

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

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

-

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

-

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

-

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

-