1
$\begingroup$

Suppose you have a sequence such as $5,1,11,5,17,9,23,13,29,17,35 ...$ where a piece wise function can describe the sequence

$5+6(x-1)$ for x is odd, and $1+4(x/2-1)$ for x is even

Is there any way to write a combined formula for all terms in the sequence?

2 Answers 2

4

Often to deal with parity issues like this, we use powers of $-1$.

In particular, say you want a function that takes the value $f(x)$ when $x$ is odd, and $g(x)$ when $x$ is even.

First, $(1 + (-1)^x)/2$ is equal to $1$ when $x$ is even, and $0$ when $x$ is odd.

Second, $(1 - (-1)^x)/2$ is equal to $0$ when $x$is even, and $1$ when $x$ is odd.

So $ f(x) {1 + (-1)^x \over 2} + g(x){1 - (-1)^x \over 2} $ is the function you want. You can rewrite this as $ {(f(x) + g(x)) + (f(x)-g(x))(-1)^x \over 2}. $

  • 0
    Thank you, exactly what I was looking for!2011-11-13
3

You could write something like $f(x) = g(x)+\sin^2(\tfrac\pi2 x)(h(x)-g(x))$ or $f(x) = g(x)+(x-2\left\lfloor\frac x2\right\rfloor)(h(x)-g(x))$ or $f(x) = g(x)+\frac{1-(-1)^x}{2}(h(x)-g(x))$ for $g(x)=1+4(\frac x2-1)=2x-3$ and $h(x)=5+6(x-1)=6x-1$.

But why do you want to do this? Such a formula is much more convoluted and less readable than a definition by case analysis.

  • 1
    The point is to use a periodic function that takes the values zero or one appropriately. :)2011-11-13