Collatz (3n+1)

What this is?

A single‑file explainer for the Collatz process a.k.a. the “3n+1 problem”. For a positive integer n, iterate: if n is even, divide by 2; if n is odd, set n ← 3n+1. This page computes trajectories, shows the Answer (stopping time, total stopping time, and peak), the Reason why (definitions and identities), and a Check harness that verifies basic properties (e.g., powers‑of‑two chains and termination for a range), all locally in JavaScript.

Note: The Collatz conjecture (that all n reach 1) is open; here we only check finite ranges.

Answer

Reason why

Transition:

T(n) = { n/2   if n is even;   3n+1   if n is odd }.

For a start value n0 = n, define the trajectory n0, n1, … with nk+1 = T(nk).

  • Total stopping time σ∞(n): least k ≥ 0 with nk = 1 (if it exists).
  • Stopping time σ(n): least k ≥ 0 with nk < n.
  • Peak: max value over the trajectory until 1 (inclusive).

For powers of two, the sequence halves straight to 1, so σ∞(2k) = k and the peak is 2k.

Check (harness)