Generalization of $n$ mod $2 = \dfrac{1-(-1)^n}{2}$

111 Views Asked by At

I had this idea that

$n$ mod $2 = \dfrac{1-(-1)^n}{2}$ for $n \in \mathbb{N}$.

Are there any generalizations for this? For example for $n$ mod $3$ etc.? I would prefer some answers containing basic arithmetic operations, although the use of analytic functions is also accepted.

2

There are 2 best solutions below

2
On BEST ANSWER

The basic ingredient is to find $k$ independent functions that have $k$ as a period. In your example, $f_0(n) = 1$ and $f_1(n) = (-1)^n$ both have $1$ as a period, and they are linearly independent, thus you can solve the system of equations

$$ a \cdot 1 + b \cdot (-1)^0 = 0 \qquad \qquad a \cdot 1 + b \cdot(-1)^1 = 1 $$

for the coefficients to get $a=1/2$ and $b=-1/2$, and that gives you the formula you have.

Where might you find three independent functions with period $3$? You might choose

$$ f_0(n) = 1 \qquad \qquad f_1(n) = \cos \frac{2\pi n}{3} \qquad \qquad f_2(n) = \sin \frac{2 \pi n}{3} $$

I think it's more traditional to instead let $\zeta_k$ be a be a primitive complex $k$-th root of unity, and to take $f_j(n) = \zeta_k^{jn}$. I'm pretty sure you can write down an explicit formula for the coefficients that works for all $k$, although I haven't tried working it out.

It turns out any sufficiently nice periodic function can be represented as a linear combination (or infinite sum, depending on the setting) of sines and cosines, or equivalently, as powers of a root of unity. For further reading on this sort of topic, you might want to look into the "discrete Fourier transform", or maybe the "discrete cosine transform". (or even just "Fourier transform" if you're interested in greater generality)

2
On

To give an alternate approach to Hurkyl's answer. If you let $\zeta$ be a primitive $n$-th root of unity, the function $$f_n(x)=\sum_{i=0}^{n-1} i\frac{(\zeta^x-\zeta^0)...(\zeta^x-\zeta^{i-1})(\zeta^x-\zeta^{i+1})...(\zeta^x-\zeta^{n-1})}{(\zeta^i-\zeta^0)...(\zeta^i-\zeta^{i+1})(\zeta^i-\zeta^{i+1})...(\zeta^i-\zeta^{n-1})}.$$

Gives you $f_n(k) = (k\mod n)$, for all integers $k$.

As an example, if we let $n = 2$ we get

$$f_2(x)=0\frac{(-1)^x-(-1)^1}{(-1)^{0}-(-1)^1}+1\frac{(-1)^x-(-1)^0}{(-1)^1-(-1)^0}=0+\frac{1-(-1)^x}{2}$$ which is identical to the formula you have.

Essentially what we did here is found a polynomial $p_n$, using the Lagrange Interpolation Formula, where $p_n(\zeta^k)=k$ for all $0 \leq k < n$. Then we let $f_n(x)=p_n(\zeta^x)$.