"""Job 4291 depth 6: aggregate gate4291b.out (idx g7..g23 g29) and check it against the depth-5 run gate4291.out (levels 7..23 must agree class by class: the level-23 value there is scan==runs, here it is the full fold build).""" import json, math from collections import Counter A = {int(l.split()[0]): tuple(map(int, l.split()[1:])) for l in open('gate4291.out')} B = {int(l.split()[0]): tuple(map(int, l.split()[1:])) for l in open('gate4291b.out')} true = B.pop(-1); A.pop(-1); N = len(B) f5 = Counter(g[:6] for g in B.values()); f6 = Counter(B.values()) split = Counter() kids = {} for g in f6: kids.setdefault(g[:6], set()).add(g) for k in f5: split[len(kids[k])] += 1 out = {'instrument': 'gate4291.c -DDEPTH6 + agg4291b.py', 'dihedral_classes': N, 'levels': [7, 11, 13, 17, 19, 23, 29], 'levels_7_to_23_equal_depth5_run': all(A[i] == B[i][:6] for i in B), 'distinct_gamma_prefix_depth5': len(f5), 'distinct_gamma_prefix_depth6': len(f6), 'largest_fibre_depth6': max(f6.values()), 'singletons_depth6': sum(1 for v in f6.values() if v == 1), 'fibre_size_histogram_depth6': dict(sorted(Counter(f6.values()).items())), 'depth5_fibres_split_into_k_depth6_fibres': dict(sorted(split.items())), 'nonsingleton_depth5_fibres_unsplit_at_29': sum(1 for k in f5 if f5[k] > 1 and len(kids[k]) == 1), 'gate_values_level29': dict(sorted(Counter(g[6] for g in B.values()).items())), 'true_T7_trajectory': list(true), 'classes_sharing_true_trajectory_depth6': f6[true], 'true_G29_equals_ladder_258': true[6] == 258, 'separates_all_45150': len(f6) == N, 'coincident_pairs_by_depth': {d - 1: sum(v * (v - 1) // 2 for v in Counter(g[:d] for g in B.values()).values()) for d in range(1, 8)}, 'log2_states': {'depth6_lower_bound': round(math.log2(len(f6)), 3), 'word_classes': round(math.log2(N), 3)}} reps = [l.split() for l in open('reps4291.txt')][1:] f4 = {} for i, g in B.items(): f4.setdefault(g[:5], []).append(i) out['pairs_equal_levels_19_to_29'] = [{'gamma': list(B[m[0]]), 'words': [' '.join(reps[i]) for i in m], 'idx': m} for k, m in sorted(f4.items()) if len(m) > 1 and len({B[i] for i in m}) == 1] print(json.dumps(out, indent=1))