Bayesian Modeling of Collatz Stopping Times: A Probabilistic Machine Learning Perspective Nicolò Bonacorsi, Matteo Bordoni Abstract We study the Collatz total stopping time τ ⁡ ( n ) \tau(n) over n ≤ 10 7 n\leq 10^{7} from a probabilistic machine learning viewpoint. Empirically, τ ⁡ ( n ) \tau(n) is a skewed and heavily overdispersed count with pronounced arithmetic heterogeneity. We develop two complementary models. First, a Bayesian hierarchical Negative Binomial regression (NB2-GLM) predicts τ ⁡ ( n ) \tau(n) from simple covariates ( log ⁡ n \log n and residue class n mod 8 n\bmod 8 ), quantifying uncertainty via posterior and posterior predictive distributions. Second, we propose a mechanistic generative approximation based on the odd-block decomposition: for odd m m , write 3 ​ m + 1 = 2 K ⁡ ( m ) ​ m ′ 3m+1=2^{K(m)}m^{\prime} with m ′ m^{\prime} odd and K ⁡ ( m ) = v 2 ​ ( 3 ​ m + 1 ) ≥ 1 K(m)=v_{2}(3m+1)\geq 1 ; randomizing these block lengths yields a stochastic approximation calibrated via a Dirichlet-multinomial update. On held-out data, the NB2-GLM achieves substantially higher predictive likelihood than the odd-block generators. Conditioning the block-length distribution on m mod 8 m\bmod 8 markedly improves the generator’s distributional fit, indicating that low-order modular structure is a key driver of heterogeneity in τ ⁡ ( n ) \tau(n) . 1 Introduction Let T:\mathbb{N}\to\mathbb{N} be the Collatz map T(n)=\begin{cases}n/2,&n\text{ even},\\ 3n+1,&n\text{ odd},\end{cases} and define the total stopping time \tau(n)=\min\{t\geq 0:\ T^{t}(n)=1\}. The Collatz conjecture asserts \tau(n)<\infty for all n and remains open [ 6 , 10 , 11 , 9 ] . Here we do not attempt to prove the conjecture. Instead we treat n as random and study the induced empirical law of \tau(n) over a large range. Dataset and question. We fix N=10^{7} and compute \tau(n) for all 1\leq n\leq N , yielding \mathcal{D}_{N}=\{(n,\tau(n))\}_{n=1}^{N} . Our goal is predictive and explanatory: which simple probabilistic models can predict and explain the observed distributional shape of \tau(n) and its arithmetic heterogeneity? Two complementary models. We develop: (i) a Bayesian hierarchical Negative Binomial regression treating \tau(n) as an overdispersed count whose conditional mean depends on \log n and n\bmod 8 (Section 3 ); and (ii) a mechanistic generative odd-block model that randomizes the block-lengths K=v_{2}(3m+1) in the accelerated odd-to-odd dynamics (Section 4 ). Section 5 compares predictive performance on held-out data. Further rationale for the regressors and the odd-block heuristics is given in Appendix C . A note on randomness (working likelihood). The map T and the stopping time \tau(n) are deterministic. Throughout, the term “probabilistic model” is used in the standard statistical sense of a working likelihood : we treat n as random (e.g. uniformly sampled from \{1,\dots,N\} in our evaluation), and we model the induced variability of \tau(n) across n by a parametric stochastic family. This provides uncertainty quantification and principled predictive comparisons, without positing physical noise in the Collatz dynamics. 2 Data and exploratory analysis Computing \tau(n) at scale A direct simulation for every n\leq 10^{7} is expensive due to long trajectories. We use dynamic programming: while computing \tau(i) , if the orbit hits some m1.\end{cases} This matches the implementation used to generate the results in Section 5 . Calibrating p_{k} and posterior predictive checks We estimate p_{k} from observed block lengths K_{i}=v_{2}(3m_{i}+1) using a Dirichlet prior, yielding a conjugate Dirichlet posterior [ 8 ] (Appendix E ). In implementation we discretize K on \{1,\dots,K_{\max}\} with K_{\max}=30 by capping K_{\mathrm{cap}}=\min(K,K_{\max}) , so the last category aggregates the tail event \{K\geq K_{\max}\} . We use a symmetric Dirichlet prior with concentration \alpha_{k}=1 for k=1,\dots,K_{\max} . Figure 4 compares empirical frequencies to the geometric reference on a log scale; this directly tests the key modeling assumption. Figure 5 shows posterior uncertainty on (p_{k}) . Figure 7 compares the generated stopping-time distributions to empirical stopping times via a distributional PPC. Figure 4: Empirical block-length distribution \hat{p}_{k} for K=v_{2}(3m+1) (odd m\leq N ) vs. geometric reference 2^{-k} on log- y . This evaluates the “geometric K ” heuristic. Figure 5: Dirichlet posterior for (p_{k}) (log scale) with uncertainty bars, compared to the geometric reference 2^{-k} . Figure 6: Posterior mean of p_{k} conditional on the odd residue class m\bmod 8 (heatmap). This reveals systematic arithmetic dependence beyond an i.i.d. geometric law. Figure 7: PPC overlay: empirical \tau vs. G1 (geometric 2^{-k} ), G2 (global calibrated p_{k} ), and G3 ( p_{k} conditional on m\bmod 8 ). Conditioning reduces the bias in the mean and improves distributional agreement in the bulk. 5 Model comparison: predictive accuracy vs. mechanistic faithfulness Posterior predictive checks are qualitative. To compare the regression and generative approaches on equal footing we use a proper scoring rule [ 4 ] on held-out data: the log predictive score. On a test set \{(n_{i},y_{i})\}_{i=1}^{N_{\mathrm{test}}} with y_{i}=\tau(n_{i}) , define \mathrm{Score}=\sum_{i=1}^{N_{\mathrm{test}}}\log p(y_{i}\mid n_{i},\mathcal{D}_{\mathrm{fit}}). For the NB2-GLM, p(y_{i}\mid n_{i},\mathcal{D}_{\mathrm{fit}}) is obtained by averaging the NB pmf over posterior draws. For the odd-block generator, we estimate a predictive pmf by Monte Carlo simulation: \hat{p}_{i}(y)=\frac{1}{S_{\mathrm{MC}}}\sum_{s=1}^{S_{\mathrm{MC}}}\mathbf{1}\{\tau_{\mathrm{gen}}^{(s)}(n_{i})=y\} and score \sum_{i}\log(\hat{p}_{i}(y_{i})+\varepsilon) with \varepsilon=10^{-12} for numerical stability. We use S_{\mathrm{MC}}=40 Monte Carlo replicates per test point. We emphasize that the generator log score is a Monte Carlo approximation to the ideal log predictive score, since \hat{p}_{i}(y_{i}) is estimated from finitely many replicates. In addition, we report a distributional distance between empirical and predictive CDFs (1-Wasserstein [ 12 ] ) to summarize global shape mismatch. Table 2 provides the reporting format. Model Log score (higher better) W_{1} distance (lower better) NB2-GLM (M3) -272\,911.95 3.199 Odd-block G2 (global p_{k} ) -1\,165\,983.43 17.594 Odd-block G3 ( p_{k}\mid m\bmod 8 ) -1\,079\,086.65 5.434 Table 2: Quantitative comparison on held-out data using a proper log predictive score and a distributional distance. All scores are computed on N_{\mathrm{test}}=50{,}000 held-out pairs, with the generative log scores estimated via S_{\mathrm{MC}}=40 Monte Carlo replicates per test point. Interpretation. Table 2 shows that the hierarchical NB2-GLM achieves by far the best predictive likelihood on the held-out set: its log score is -2.73\times 10^{5} (average -5.46 per observation), compared to -1.17\times 10^{6} for the global odd-block generator G2 and -1.08\times 10^{6} for the conditional generator G3. In other words, the regression model assigns substantially higher probability to the realized stopping times. In terms of distributional fit, the NB2-GLM also attains the smallest W_{1} distance ( W_{1}\approx 3.20 ), with G3 improving markedly over G2 ( W_{1}\approx 5.43 vs. 17.59 ) but still lagging behind the regression. From a purely predictive, proper-score perspective, the NB2-GLM (M3) is therefore the best model among those considered. However, the odd-block generator remains attractive from a mechanistic point of view: it explains heavy tails and heterogeneity through randomized block lengths K=v_{2}(3m+1) and their arithmetic dependence on m\bmod 8 . The conditional variant G3 narrows the gap in predictive performance while preserving this structural interpretation, making it a natural candidate when mechanistic faithfulness is prioritized over raw log score. 6 Discussion Two complementary conclusions emerge. First, a compact hierarchical NB2-GLM with \log n and n\bmod 8 captures much of the predictive structure of \tau(n) , with uncertainty quantification via the posterior and PPC (Figure 3 ). Second, the odd-block decomposition yields a mechanistic generator whose success hinges on accurately modeling the distribution of K=v_{2}(3m+1) and its arithmetic dependence (Figures 4 – 7 ). The conditional variant provides a bridge between the two viewpoints: modular structure that appears as a random effect in regression becomes explicit conditioning information in the generator. Future work includes extending the conditional structure to higher powers of two, incorporating explicit state-dependence in (K_{j}) , and using likelihood-based calibration of the generator to align scoring-rule performance with mechanistic interpretability. Appendix Appendix A Method to construct the dataset A naive implementation of the stopping-time computation is too slow when N is as large as 10^{7} , due to the potentially long trajectories required for some starting values. To obtain a scalable engine, we use Python together with NumPy arrays and Numba’s just-in-time (JIT) compilation [ 7 ] . Numba compiles the core loops to efficient machine code, drastically reducing Python overhead and enabling the computation of \tau(n) for all n\leq N within a standard Colab-like runtime. We also exploit a dynamic-programming shortcut. When computing \tau(i) for a given i , the trajectory (n_{k}) may eventually visit a value m0,\;p\in(0,1). Its pmf is \Pr(Y=y\mid r,p)=\frac{\Gamma(y+r)}{\Gamma(r)\,\Gamma(y+1)}(1-p)^{y}p^{r},\qquad y=0,1,2,\dots, and \mathbb{E}[Y]=r\,\frac{1-p}{p},\qquad\mathrm{Var}(Y)=r\,\frac{1-p}{p^{2}}. D.2 Mean–dispersion (\mu,\alpha) parameterization (NB2) For regression we use the NB2 convention \mathbb{E}[Y\mid\mu,\alpha]=\mu,\qquad\mathrm{Var}(Y\mid\mu,\alpha)=\mu+\alpha\,\mu^{2}, where \alpha>0 controls overdispersion and \alpha\to 0 yields the Poisson limit. The mapping to (r,p) is r=\frac{1}{\alpha},\qquad p=\frac{1}{1+\alpha\mu}. D.3 Implementation note: mapping to PyMC In PyMC, NegativeBinomial(mu=mu, alpha=alpha_PyMC) uses \mathrm{Var}(Y\mid\mu,\alpha_{\mathrm{PyMC}})=\mu+\frac{\mu^{2}}{\alpha_{\mathrm{PyMC}}}. Therefore, to match the NB2 convention above we set \alpha_{\mathrm{PyMC}}=\frac{1}{\alpha}. D.4 Poisson–Gamma mixture view If \Lambda\sim\mathrm{Gamma}(r,c) and Y\mid\Lambda\sim\mathrm{Poisson}(\Lambda) , then Y\sim\mathrm{NB}(r,p) with p=c/(c+1) . In NB2 form, taking r=\alpha^{-1} and c=\alpha^{-1}/\mu recovers \mathrm{Var}(Y)=\mu+\alpha\mu^{2} , interpreting overdispersion as latent rate heterogeneity. Appendix E Dirichlet–multinomial update If K_{1},\dots,K_{m} are i.i.d. categorical with probabilities p_{1},\dots,p_{K_{\max}} and prior p\sim\mathrm{Dir}(\alpha) , the posterior is \mathrm{Dir}(\alpha+c) with c_{k}=\sum_{i=1}^{m}\mathbf{1}\{K_{i}=k\} . Posterior means and variances are \mathbb{E}[p_{k}\mid K_{1:m}]=\frac{\alpha_{k}+c_{k}}{\sum_{j}(\alpha_{j}+c_{j})},\qquad\mathrm{Var}(p_{k}\mid K_{1:m})=\frac{(\alpha_{k}+c_{k})\left(\alpha_{0}+m-(\alpha_{k}+c_{k})\right)}{(\alpha_{0}+m)^{2}(\alpha_{0}+m+1)}, where \alpha_{0}=\sum_{j}\alpha_{j} . Appendix F Log-scale random walk approximation Ignoring the additive +1 term for large states, the odd-block update satisfies M_{j+1}\approx(3/2^{K_{j}})M_{j} , hence in logarithmic scale X_{j+1}\approx X_{j}+\log_{2}3-K_{j},\qquad X_{j}=\log_{2}M_{j}. Even when \mathbb{E}[3/2^{K}]=1 , Jensen’s inequality implies \mathbb{E}[\log_{2}(3/2^{K})]<\log_{2}\mathbb{E}[3/2^{K}]=0 , yielding a negative drift in X_{j} and suggesting absorption at small values is typical. Figure 8: Example trajectory in log scale for n=27 : deterministic Collatz vs. stochastic odd-block approximation.