TITLE: Is it possible to describe the Collatz function in one formula?
QUESTION [37 upvotes]: This is related to Collatz sequence, which is that
$$C(n) = \begin{cases} n/2 &\text{if } n \equiv 0 \pmod{2}\\ 3n+1 & \text{if } n\equiv 1 \pmod{2} .\end{cases}$$
Is it possible to describe the Collatz function in one formula? (without modular conditions)

REPLY [2 votes]: Let f be the iteration function for every even number and g for every uneven number.
\begin{align}
f(n) = \frac{n}{2}
\end{align}
\begin{align}
g(n) = 3n + 1
\end{align}
It is possible to use the right equation for the right number by using a sine function with a period of 2. This way, even numbers get iterated by f and uneven numbers by g. Let c be the sine function.
\begin{align}
c(n) = a\cdot cos(\frac{2\pi}{d}\cdot n) + b
\end{align}
, where
\begin{align}
d = 2
\end{align}
and a is the difference between both functions divided by 2.
\begin{align}
a = \frac{f(n)-g(n)}{2}
\end{align}
'b' is the average of both functions.
\begin{align}
b = \frac{f(n)+g(n)}{2}
\end{align}
Now, time to rewrite c.
\begin{align}
c(n) = \frac{f(n)-g(n)}{2}\cdot cos(\pi n) + \frac{f(n)+g(n)}{2}
\end{align}