collatz-m4m6 Tool Specification Report

Version: 0.2.0  |  Date: 2026-02-07  |  Language: Rust (edition 2021)

1. Overview

A scan and analysis tool based on the m4/m6 pair predicate decomposition of the Collatz-type map \(T(n) = (xn+1)/2^d\). This is an implementation of Algorithm 7.1 from the paper "Pair Predicate Decomposition of the Collatz-type Map \((xn+1)/2^d\) and Structural Closure of \(3n+1\)," providing the following features.

2. Supported Parameters

Parameter \(x\)\(s = \log_2(x-1)\)Reference patternStatus
31 (odd)ref_R=(a[i-1], b[i]), ref_L=(b[i], a[i])Dedicated optimization available
52 (even)ref_R=(b[i-1], b[i]), ref_L=(a[i-1], a[i])Dedicated optimization available
93 (odd)Generic patternGeneric routine
174 (even)Generic patternGeneric routine
33, 65, 129, …5, 6, 7, …Generic patternGeneric routine

Constraint: \(x \geq 3\) and \(x-1\) must be a power of 2.

3. Architecture

3.1 Module Structure

src/
├── lib.rs            # Crate root (public API definitions)
├── main.rs           # CLI entry point
├── gui.rs            # GUI entry point (egui)
├── pair_number.rs    # PairNumber type (m4/m6 bit-pair representation)
├── reference.rs      # Reference patterns (implementation of Table 3.1)
├── scan.rs           # Single-step scan (including GPK classification)
├── postprocess.rs    # Postprocessing (MSB trimming, trailing zero removal, re-pairing)
├── trajectory.rs     # Trajectory tracking / stopping time calculation
└── verify.rs         # Range parallel verification (rayon)

3.2 Data Flow

Input n (BigUint)
    │
    ├─ [Trajectory tracking path] ─── PairNumber conversion → scan::collatz_step → postprocess → record
    │                     (retains m4/m6, GPK sequence, d for each step)
    │
    └─ [Stopping time path] ─── u128 direct arithmetic → BigUint fallback
                          (fast arithmetic without going through PairNumber; GPK computed via bit extraction)

3.3 Dual-Path Design

Trajectory tracking pathStopping time path
PurposeSingle analysis (GUI single tab)Range verification (GUI range tab)
Internal representationPairNumber (Vec<u8> per bit)u128 / BigUint direct arithmetic
GPK acquisitionBy-product of scan function (GPK sequence per pair)Computed directly from bit sequence (statistics only)
Outputn', d, GPK sequence for all stepsStopping time + GPK aggregate statistics
SpeedSlow (detailed data for research)Fast (for bulk verification)

4. Stopping Time Fast Path

4.1 stopping_time_u64_fast

Optimized path for u64 input.

Phase 1: u128 Arithmetic

Phase 2: BigUint Fallback

4.2 stopping_time_with_gpk

Generic path for BigUint input. Same logic as Phase 2.

4.3 Safety Limits

LimitValuePurpose
MAX_PAIR_COUNT10,000 pairsMemory limit for trajectory tracking path
MAX_BIT_LENGTH20,000 bitsBit-length limit for stopping time path
max_stepsConfigurable in GUITruncation for divergent series

5. GPK Statistics

5.1 Classification Rules

For each pair position \(i\), from the 4 bits \((p_r, q_r, p_l, q_l)\) based on the reference pattern:

m6 stage: g_mid = p_r & q_r,  p_mid = p_r ^ q_r
m4 stage: g_out = p_l & q_l,  p_out = p_l ^ q_l
Serial composition: G_i = g_out | (p_out & g_mid)
          P_i = p_out & p_mid
          K_i = otherwise

5.2 Carry Chain Length

Records the maximum length of chains starting from the initial carry \(c=1\) and chains after regeneration by G. Aggregated as a histogram (distance 0–127).

5.3 Measured GPK Distribution (\(n \leq 10^7\), max_steps=500)

\(3n+1\)\(5n+1\)\(17n+1\)
G%38.4136.9137.26
P%28.3225.4525.09
K%33.2637.6437.65
G/K ratio1.150.980.99

6. GUI Specification

6.1 Configuration

6.2 Top Panel

ElementDescription
x =Parameter for \(xn+1\). Only values where \(x-1\) is a power of 2 are accepted
max_steps:Maximum number of iteration steps. Default 10000
Tab switchingSingle analysis / Range analysis / Analysis

6.3 Single Analysis Tab

6.4 Range Analysis Tab

6.5 Analysis Tab

7. Output Files

7.1 Save Location

The output/ folder in the same directory as the exe (created automatically).

7.2 File Naming Convention

gui_trace_{x}n1_{n}[_stopped]_{timestamp}.txt     # Trajectory tracking summary
gui_trace_{x}n1_{n}.csv                            # Trajectory tracking CSV
gui_verify_{x}n1_{start}-{end}[_stopped]_{timestamp}.txt  # Range verification summary

7.3 Summary File Format

# collatz-m4m6 verify
range = [3, 9999999]
x = 5
total_checked = 4999999
all_converged = false
max_stopping_time = 490
max_stopping_time_n = 4580349

# GPK
G = 17746659852
P = 12236187544
K = 18094218711
total_pairs = 48077066107
total_steps = 897149444
G% = 36.9129
P% = 25.4512
K% = 37.6359

# Carry chain histogram
0: 720342
1: 1400349
...

elapsed = 79.0672604s

7.4 CSV Format (Trajectory Tracking)

step,n,d,digits,gpk,G,P,K,max_carry_chain
0,27,0,2,,0,0,0,0
1,41,1,2,PGP,1,2,0,2
...

8. Build

8.1 Prerequisites

8.2 Build Commands

# Use build_gui.ps1
$env:PATH = "C:\msys64\mingw64\bin;C:\Users\ykihi\.cargo\bin;" + $env:PATH
cargo build --release --features gui --bin collatz-gui

8.3 Execution

target\release\collatz-gui.exe

9. Performance Characteristics

9.1 Benchmark (\(n \leq 10^7\), max_steps=500)

\(x\)Timenums/sAvg steps/number
30.49s10,200,0003.5
579s63,300179
171654s3,020456

9.2 Scaling Factors for Speed

  1. Convergence: \(3n+1\) converges for all numbers (average 3.5 steps); \(x \geq 5\) diverges (runs up to max_steps)
  2. Bit growth: Larger \(x\) causes greater numerical growth per step, increasing BigUint arithmetic cost
  3. u128 effective range: The first approximately \(128 / \log_2(x/2)\) steps are processed in u128; thereafter BigUint

9.3 Optimization History

VersionMethod5n+1 (\(n \leq 10^6\)) speed
v0.1PairNumber + BigUint conversion/step46ms/number (92 numbers/5.65s)
v0.2BigUint direct arithmetic + u128 fast path8μs/number (499,999/4s)
Improvement factorApprox. 5,750x

10. Known Limitations

  1. Values of \(x\) where \(x-1\) is not a power of 2 are unsupported: \(x=7, 11, 13\), etc. require multiple addition stages and cannot be handled by the current two-stage structure
  2. Inefficiency of PairNumber representation: Vec<u8> per bit (8x memory overhead). Used only in the trajectory tracking path
  3. GUI log viewer: Only supports .txt files in output/. Direct viewing of CSV files is not yet implemented
  4. Timestamp precision: Simplified calculation that does not account for leap years