#!/usr/bin/env python3 """0002 -- probe 5: radix layers and the height-contribution. Layer b of the tower: the integers carried through the Ulam spiral but RESIDUED in radix b, with a height contribution D_b(n) = ( s_b(n) - (b-1)/2 * L_b(n) ) / sqrt( L_b(n) ) where L_b(n) = number of base-b digits of n and s_b(n) = digit sum. D_b is a centred digit imbalance: the height coordinate of the "radix-b layer". Verified here: (R1) D_b(n) = 0 exactly iff the base-b digits of n are perfectly balanced; in particular D_b(b^k) = -(b-1)/2 * (k+1)/sqrt(k+1) is the most negative case (all zeros after the leading 1), and D_b(b^k - 1) is the most positive. So the radix layers are NOT independent of the Ulam layer: the pair (D_b, D_{b'}) is a function of the digit expansions and the CRT does not decouple the centred parts. (R2) for coprime b, b' the joint value (n mod b, n mod b') is a bijection onto Z/b x Z/b' (CRT), so the ANGULAR part of the two layers is independent, while the HEIGHT part D_b, D_{b'} is not. (R3) the number of balanced n <= X in radix b is 0 unless a digit-sum target is achievable; count it. """ import json from collections import Counter def digits(n, b): d = [] while n: d.append(n % b); n //= b return d or [0] def D(n, b): d = digits(n, b); L = len(d) return (sum(d) - (b - 1) / 2 * L) / (L ** 0.5) def main(): X = 200000 out = {} for b in (2, 3, 10): vals = [D(n, b) for n in range(1, X)] balanced = sum(1 for v in vals if abs(v) < 1e-12) extreme_neg = min(range(1, X), key=lambda n: D(n, b)) extreme_pos = max(range(1, X), key=lambda n: D(n, b)) out[str(b)] = { "R1_balanced_count": balanced, "R1_balanced_fraction": balanced / (X - 1), "R1_min_D_n": extreme_neg, "R1_min_D": round(D(extreme_neg, b), 6), "R1_max_D_n": extreme_pos, "R1_max_D": round(D(extreme_pos, b), 6), "R1_sample_zeros_of_D": [n for n in range(1, X) if abs(D(n, b)) < 1e-12][:12], "R1_powers_of_b": {f"{b}^{k}": round(D(b**k, b), 6) for k in range(1, 8)}, } # (R2) CRT bijection check for coprime b, b' ok = True for b, bp in ((2, 3), (3, 10), (10, 11), (2, 5)): seen = {} for n in range(b * bp): key = (n % b, n % bp) if key in seen: ok = False seen[key] = n if len(seen) != b * bp: ok = False out["R2_crt_bijection_coprime"] = ok out["R2_statement"] = ("angular (residue) parts of coprime radix layers are " "CRT-independent; the height parts D_b are NOT, because " "D_b depends on the full base-b digit expansion, not on n mod b.") print(json.dumps(out, indent=2)) json.dump(out, open("radix_layer.json", "w"), indent=2) if __name__ == "__main__": main()