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 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|improve this question

5 Answers 5

up vote 8 down vote accepted

How about

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

share|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
3  
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. –  T. Bongers 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|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|improve this answer

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

share|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|improve this answer

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.