A novel perspective on the famous \(3n+1\) problem, with an interactive JavaScript simulation demonstrating the Extended Kalman Filter in action.
The Collatz Conjecture posits that for any positive integer \( n \), the sequence defined by the iterative rule \(f(n) = \frac{n}{2}\) if \( n \) is even, or \(f(n) = 3n + 1\) if \( n \) is odd, always reaches 1. Despite its deterministic nature, the sequence’s trajectory is highly unpredictable, resembling chaotic or pseudo-random behavior. The Kalman Filter, a tool for estimating the state of a dynamic system from noisy measurements, can be adapted to model this complexity by treating the Collatz sequence as a non-linear dynamic system with "pseudo-noise" arising from its unpredictable steps.
The EKF works by linearizing the non-linear model at each time step using Jacobians. The filter operates in a two-step cycle: Predict and Update.
Here, \(P\) is the error covariance, and \(F_{k-1}\) is the state transition Jacobian. For the "slow" Collatz step, it is:
\[ F_k = \frac{\partial f}{\partial x} \bigg|_{x=\hat{x}_{k|k}} = \begin{cases} \frac{3n_k}{3n_k+1} & \text{if } n_k \text{ is odd} \\ 1 & \text{if } n_k \text{ is even} \end{cases} \]The process model is \(f(x_k) = \log(\text{Collatz}(e^{x_k}))\), where \(n_k = e^{x_k}\).
For even \(n_k\): \(\text{Collatz}(n_k) = n_k/2\). \[ f(x_k) = \log\left(\frac{e^{x_k}}{2}\right) = x_k - \log(2) \implies F_k = \frac{\partial}{\partial x_k} (x_k - \log(2)) = 1 \]
For odd \(n_k\): \(\text{Collatz}(n_k) = 3n_k + 1\). \[ f(x_k) = \log(3e^{x_k} + 1) \implies F_k = \frac{\partial}{\partial x_k} \log(3e^{x_k} + 1) = \frac{3e^{x_k}}{3e^{x_k} + 1} = \frac{3n_k}{3n_k + 1} \]
For the optimized step, the Jacobian accounts for multiple divisions by 2, computed as \( F_k = \frac{3n_k}{(3n_k + 1) \cdot 2^k} \), where \( k \) is the number of trailing zeros in the binary representation of \( 3n_k + 1 \).
The process noise covariance \(Q_{k-1}\) is a crucial modeling choice. It represents the "unpredictability" we inject. A logical heuristic is to make it larger for the more chaotic odd step:
\[ Q_k = \begin{cases} q_{odd} & \text{if } n_k \text{ is odd} \\ q_{even} & \text{if } n_k \text{ is even} \end{cases} \quad (\text{where } q_{odd} \gg q_{even}) \]In our case, the measurement is \(z_k = \log(n_k)\), the measurement model is \(h(x)=x\), its Jacobian is \(H_k = 1\), and the measurement noise is \(R_k = 0\).
By embedding the Collatz rules within the rigorous mathematical structure of a non-linear Kalman Filter, we can move beyond simple analogy and begin to ask quantitative questions. The filter's iterative prediction-correction cycle aligns perfectly with the step-by-step nature of the Collatz sequence, allowing us to: