shikumi 0.1.78

Shikumi (仕組み) — config discovery, hot-reload, and ArcSwap store for Nix-managed desktop apps
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525
10526
10527
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
10539
10540
10541
10542
10543
10544
10545
10546
10547
10548
10549
10550
10551
10552
10553
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565
10566
10567
10568
10569
10570
10571
10572
10573
10574
10575
10576
10577
10578
10579
10580
10581
10582
10583
10584
10585
10586
10587
10588
10589
10590
10591
10592
10593
10594
10595
10596
10597
10598
10599
10600
10601
10602
10603
10604
10605
10606
10607
10608
10609
10610
10611
10612
10613
10614
10615
10616
10617
10618
10619
10620
10621
10622
10623
10624
10625
10626
10627
10628
10629
10630
10631
10632
10633
10634
10635
10636
10637
10638
10639
10640
10641
10642
10643
10644
10645
10646
10647
10648
10649
10650
10651
10652
10653
10654
10655
10656
10657
10658
10659
10660
10661
10662
10663
10664
10665
10666
10667
10668
10669
10670
10671
10672
10673
10674
10675
10676
10677
10678
10679
10680
10681
10682
10683
10684
10685
10686
10687
10688
10689
10690
10691
10692
10693
10694
10695
10696
10697
10698
10699
10700
10701
10702
10703
10704
10705
10706
10707
10708
10709
10710
10711
10712
10713
10714
10715
10716
10717
10718
10719
10720
10721
10722
10723
10724
10725
10726
10727
10728
10729
10730
10731
10732
10733
10734
10735
10736
10737
10738
10739
10740
10741
10742
10743
10744
10745
10746
10747
10748
10749
10750
10751
10752
10753
10754
10755
10756
10757
10758
10759
10760
10761
10762
10763
10764
10765
10766
10767
10768
10769
10770
10771
10772
10773
10774
10775
10776
10777
10778
10779
10780
10781
10782
10783
10784
10785
10786
10787
10788
10789
10790
10791
10792
10793
10794
10795
10796
10797
10798
10799
10800
10801
10802
10803
10804
10805
10806
10807
10808
10809
10810
10811
10812
10813
10814
10815
10816
10817
10818
10819
10820
10821
10822
10823
10824
10825
10826
10827
10828
10829
10830
10831
10832
10833
10834
10835
10836
10837
10838
10839
10840
10841
10842
10843
10844
10845
10846
10847
10848
10849
10850
10851
10852
10853
10854
10855
10856
10857
10858
10859
10860
10861
10862
10863
10864
10865
10866
10867
10868
10869
10870
10871
10872
10873
10874
10875
10876
10877
10878
10879
10880
10881
10882
10883
10884
10885
10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896
10897
10898
10899
10900
10901
10902
10903
10904
10905
10906
10907
10908
10909
10910
10911
10912
10913
10914
10915
10916
10917
10918
10919
10920
10921
10922
10923
10924
10925
10926
10927
10928
10929
10930
10931
10932
10933
10934
10935
10936
10937
10938
10939
10940
10941
10942
10943
10944
10945
10946
10947
10948
10949
10950
10951
10952
10953
10954
10955
10956
10957
10958
10959
10960
10961
10962
10963
10964
10965
10966
10967
10968
10969
10970
10971
10972
10973
10974
10975
10976
10977
10978
10979
10980
10981
10982
10983
10984
10985
10986
10987
10988
10989
10990
10991
10992
10993
10994
10995
10996
10997
10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
11009
11010
11011
11012
11013
11014
11015
11016
11017
11018
11019
11020
11021
11022
11023
11024
11025
11026
11027
11028
11029
11030
11031
11032
11033
11034
11035
11036
11037
11038
11039
11040
11041
11042
11043
11044
11045
11046
11047
11048
11049
11050
11051
11052
11053
11054
11055
11056
11057
11058
11059
11060
11061
11062
11063
11064
11065
11066
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076
11077
11078
11079
11080
11081
11082
11083
11084
11085
11086
11087
11088
11089
11090
11091
11092
11093
11094
11095
11096
11097
11098
11099
11100
11101
11102
11103
11104
11105
11106
11107
11108
11109
11110
11111
11112
11113
11114
11115
11116
11117
11118
11119
11120
11121
11122
11123
11124
11125
11126
11127
11128
11129
11130
11131
11132
11133
11134
11135
11136
11137
11138
11139
11140
11141
11142
11143
11144
11145
11146
11147
11148
11149
11150
11151
11152
11153
11154
11155
11156
11157
11158
11159
11160
11161
11162
11163
11164
11165
11166
11167
11168
11169
11170
11171
11172
11173
11174
11175
11176
11177
11178
11179
11180
11181
11182
11183
11184
11185
11186
11187
11188
11189
11190
11191
11192
11193
11194
11195
11196
11197
11198
11199
11200
11201
11202
11203
11204
11205
11206
11207
11208
11209
11210
11211
11212
11213
11214
11215
11216
11217
11218
11219
11220
11221
11222
11223
11224
11225
11226
11227
11228
11229
11230
11231
11232
11233
11234
11235
11236
11237
11238
11239
11240
11241
11242
11243
11244
11245
11246
11247
11248
11249
11250
11251
11252
11253
11254
11255
11256
11257
11258
11259
11260
11261
11262
11263
11264
11265
11266
11267
11268
11269
11270
11271
11272
11273
11274
11275
11276
11277
11278
11279
11280
11281
11282
11283
11284
11285
11286
11287
11288
11289
11290
11291
11292
11293
11294
11295
11296
11297
11298
11299
11300
11301
11302
11303
11304
11305
11306
11307
11308
11309
11310
11311
11312
11313
11314
11315
11316
11317
11318
11319
11320
11321
11322
11323
11324
11325
11326
11327
11328
11329
11330
11331
11332
11333
11334
11335
11336
11337
11338
11339
11340
11341
11342
11343
11344
11345
11346
11347
11348
11349
11350
11351
11352
11353
11354
11355
11356
11357
11358
11359
11360
11361
11362
11363
11364
11365
11366
11367
11368
11369
11370
11371
11372
11373
11374
11375
11376
11377
11378
11379
11380
11381
11382
11383
11384
11385
11386
11387
11388
11389
11390
11391
11392
11393
11394
11395
11396
11397
11398
11399
11400
11401
11402
11403
11404
11405
11406
11407
11408
11409
11410
11411
11412
11413
11414
11415
11416
11417
11418
11419
11420
11421
11422
11423
11424
11425
11426
11427
11428
11429
11430
11431
11432
11433
11434
11435
11436
11437
11438
11439
11440
11441
11442
11443
11444
11445
11446
11447
11448
11449
11450
11451
11452
11453
11454
11455
11456
11457
11458
11459
11460
11461
11462
11463
11464
11465
11466
11467
11468
11469
11470
11471
11472
11473
11474
11475
11476
11477
11478
11479
11480
11481
11482
11483
11484
11485
11486
11487
11488
11489
11490
11491
11492
11493
11494
11495
11496
11497
11498
11499
11500
11501
11502
11503
11504
11505
11506
11507
11508
11509
11510
11511
11512
11513
11514
11515
11516
11517
11518
11519
11520
11521
11522
11523
11524
11525
11526
11527
11528
11529
11530
11531
11532
11533
11534
11535
11536
11537
11538
11539
11540
11541
11542
11543
11544
11545
11546
11547
11548
11549
11550
11551
11552
11553
11554
11555
11556
11557
11558
11559
11560
11561
11562
11563
11564
11565
11566
11567
11568
11569
11570
11571
11572
11573
11574
11575
11576
11577
11578
11579
11580
11581
11582
11583
11584
11585
11586
11587
11588
11589
11590
11591
11592
11593
11594
11595
11596
11597
11598
11599
11600
11601
11602
11603
11604
11605
11606
11607
11608
11609
11610
11611
11612
11613
11614
11615
11616
11617
11618
11619
11620
11621
11622
11623
11624
11625
11626
11627
11628
11629
11630
11631
11632
11633
11634
11635
11636
11637
11638
11639
11640
11641
11642
11643
11644
11645
11646
11647
11648
11649
11650
11651
11652
11653
11654
11655
11656
11657
11658
11659
11660
11661
11662
11663
11664
11665
11666
11667
11668
11669
11670
11671
11672
11673
11674
11675
11676
11677
11678
11679
11680
11681
11682
11683
11684
11685
11686
11687
11688
11689
11690
11691
11692
11693
11694
11695
11696
11697
11698
11699
11700
11701
11702
11703
11704
11705
11706
11707
11708
11709
11710
11711
11712
11713
11714
11715
11716
11717
11718
11719
11720
11721
11722
11723
11724
11725
11726
11727
11728
11729
11730
11731
11732
11733
11734
11735
11736
11737
11738
11739
11740
11741
11742
11743
11744
11745
11746
11747
11748
11749
11750
11751
11752
11753
11754
11755
11756
11757
11758
11759
11760
11761
11762
11763
11764
11765
11766
11767
11768
11769
11770
11771
11772
11773
11774
11775
11776
11777
11778
11779
11780
11781
11782
11783
11784
11785
11786
11787
11788
11789
11790
11791
11792
11793
11794
11795
11796
11797
11798
11799
11800
11801
11802
11803
11804
11805
11806
11807
11808
11809
11810
11811
11812
11813
11814
11815
11816
11817
11818
11819
11820
11821
11822
11823
11824
11825
11826
11827
11828
11829
11830
11831
11832
11833
11834
11835
11836
11837
11838
11839
11840
11841
11842
11843
11844
11845
11846
11847
11848
11849
11850
11851
11852
11853
11854
11855
11856
11857
11858
11859
11860
11861
11862
11863
11864
11865
11866
11867
11868
11869
11870
11871
11872
11873
11874
11875
11876
11877
11878
11879
11880
11881
11882
11883
11884
11885
11886
11887
11888
11889
11890
11891
11892
11893
11894
11895
11896
11897
11898
11899
11900
11901
11902
11903
11904
11905
11906
11907
11908
11909
11910
11911
11912
11913
11914
11915
11916
11917
11918
11919
11920
11921
11922
11923
11924
11925
11926
11927
11928
11929
11930
11931
11932
11933
11934
11935
11936
11937
11938
11939
11940
11941
11942
11943
11944
11945
11946
11947
11948
11949
11950
11951
11952
11953
11954
11955
11956
11957
11958
11959
11960
11961
11962
11963
11964
11965
11966
11967
11968
11969
11970
11971
11972
11973
11974
11975
11976
11977
11978
11979
11980
11981
11982
11983
11984
11985
11986
11987
11988
11989
11990
11991
11992
11993
11994
11995
11996
11997
11998
11999
12000
12001
12002
12003
12004
12005
12006
12007
12008
12009
12010
12011
12012
12013
12014
12015
12016
12017
12018
12019
12020
12021
12022
12023
12024
12025
12026
12027
12028
12029
12030
12031
12032
12033
12034
12035
12036
12037
12038
12039
12040
12041
12042
12043
12044
12045
12046
12047
12048
12049
12050
12051
12052
12053
12054
12055
12056
12057
12058
12059
12060
12061
12062
12063
12064
12065
12066
12067
12068
12069
12070
12071
12072
12073
12074
12075
12076
12077
12078
12079
12080
12081
12082
12083
12084
12085
12086
12087
12088
12089
12090
12091
12092
12093
12094
12095
12096
12097
12098
12099
12100
12101
12102
12103
12104
12105
12106
12107
12108
12109
12110
12111
12112
12113
12114
12115
12116
12117
12118
12119
12120
12121
12122
12123
12124
12125
12126
12127
12128
12129
12130
12131
12132
12133
12134
12135
12136
12137
12138
12139
12140
12141
12142
12143
12144
12145
12146
12147
12148
12149
12150
12151
12152
12153
12154
12155
12156
12157
12158
12159
12160
12161
12162
12163
12164
12165
12166
12167
12168
12169
12170
12171
12172
12173
12174
12175
12176
12177
12178
12179
12180
12181
12182
12183
12184
12185
12186
12187
12188
12189
12190
12191
12192
12193
12194
12195
12196
12197
12198
12199
12200
12201
12202
12203
12204
12205
12206
12207
12208
12209
12210
12211
12212
12213
12214
12215
12216
12217
12218
12219
12220
12221
12222
12223
12224
12225
12226
12227
12228
12229
12230
12231
12232
12233
12234
12235
12236
12237
12238
12239
12240
12241
12242
12243
12244
12245
12246
12247
12248
12249
12250
12251
12252
12253
12254
12255
12256
12257
12258
12259
12260
12261
12262
12263
12264
12265
12266
12267
12268
12269
12270
12271
12272
12273
12274
12275
12276
12277
12278
12279
12280
12281
12282
12283
12284
12285
12286
12287
12288
12289
12290
12291
12292
12293
12294
12295
12296
12297
12298
12299
12300
12301
12302
12303
12304
12305
12306
12307
12308
12309
12310
12311
12312
12313
12314
12315
12316
12317
12318
12319
12320
12321
12322
12323
12324
12325
12326
12327
12328
12329
12330
12331
12332
12333
12334
12335
12336
12337
12338
12339
12340
12341
12342
12343
12344
12345
12346
12347
12348
12349
12350
12351
12352
12353
12354
12355
12356
12357
12358
12359
12360
12361
12362
12363
12364
12365
12366
12367
12368
12369
12370
12371
12372
12373
12374
12375
12376
12377
12378
12379
12380
12381
12382
12383
12384
12385
12386
12387
12388
12389
12390
12391
12392
12393
12394
12395
12396
12397
12398
12399
12400
12401
12402
12403
12404
12405
12406
12407
12408
12409
12410
12411
12412
12413
12414
12415
12416
12417
12418
12419
12420
12421
12422
12423
12424
12425
12426
12427
12428
12429
12430
12431
12432
12433
12434
12435
12436
12437
12438
12439
12440
12441
12442
12443
12444
12445
12446
12447
12448
12449
12450
12451
12452
12453
12454
12455
12456
12457
12458
12459
12460
12461
12462
12463
12464
12465
12466
12467
12468
12469
12470
12471
12472
12473
12474
12475
12476
12477
12478
12479
12480
12481
12482
12483
12484
12485
12486
12487
12488
12489
12490
12491
12492
12493
12494
12495
12496
12497
12498
12499
12500
12501
12502
12503
12504
12505
12506
12507
12508
12509
12510
12511
12512
12513
12514
12515
12516
12517
12518
12519
12520
12521
12522
12523
12524
12525
12526
12527
12528
12529
12530
12531
12532
12533
12534
12535
12536
12537
12538
12539
12540
12541
12542
12543
12544
12545
12546
12547
12548
12549
12550
12551
12552
12553
12554
12555
12556
12557
12558
12559
12560
12561
12562
12563
12564
12565
12566
12567
12568
12569
12570
12571
12572
12573
12574
12575
12576
12577
12578
12579
12580
12581
12582
12583
12584
12585
12586
12587
12588
12589
12590
12591
12592
12593
12594
12595
12596
12597
12598
12599
12600
12601
12602
12603
12604
12605
12606
12607
12608
12609
12610
12611
12612
12613
12614
12615
12616
12617
12618
12619
12620
12621
12622
12623
12624
12625
12626
12627
12628
12629
12630
12631
12632
12633
12634
12635
12636
12637
12638
12639
12640
12641
12642
12643
12644
12645
12646
12647
12648
12649
12650
12651
12652
12653
12654
12655
12656
12657
12658
12659
12660
12661
12662
12663
12664
12665
12666
12667
12668
12669
12670
12671
12672
12673
12674
12675
12676
12677
12678
12679
12680
12681
12682
12683
12684
12685
12686
12687
12688
12689
12690
12691
12692
12693
12694
12695
12696
12697
12698
12699
12700
12701
12702
12703
12704
12705
12706
12707
12708
12709
12710
12711
12712
12713
12714
12715
12716
12717
12718
12719
12720
12721
12722
12723
12724
12725
12726
12727
12728
12729
12730
12731
12732
12733
12734
12735
12736
12737
12738
12739
12740
12741
12742
12743
12744
12745
12746
12747
12748
12749
12750
12751
12752
12753
12754
12755
12756
12757
12758
12759
12760
12761
12762
12763
12764
12765
12766
12767
12768
12769
12770
12771
12772
12773
12774
12775
12776
12777
12778
12779
12780
12781
12782
12783
12784
12785
12786
12787
12788
12789
12790
12791
12792
12793
12794
12795
12796
12797
12798
12799
12800
12801
12802
12803
12804
12805
12806
12807
12808
12809
12810
12811
12812
12813
12814
12815
12816
12817
12818
12819
12820
12821
12822
12823
12824
12825
12826
12827
12828
12829
12830
12831
12832
12833
12834
12835
12836
12837
12838
12839
12840
12841
12842
12843
12844
12845
12846
12847
12848
12849
12850
12851
12852
12853
12854
12855
12856
12857
12858
12859
12860
12861
12862
12863
12864
12865
12866
12867
12868
12869
12870
12871
12872
12873
12874
12875
12876
12877
12878
12879
12880
12881
12882
12883
12884
12885
12886
12887
12888
12889
12890
12891
12892
12893
12894
12895
12896
12897
12898
12899
12900
12901
12902
12903
12904
12905
12906
12907
12908
12909
12910
12911
12912
12913
12914
12915
12916
12917
12918
12919
12920
12921
12922
12923
12924
12925
12926
12927
12928
12929
12930
12931
12932
12933
12934
12935
12936
12937
12938
12939
12940
12941
12942
12943
12944
12945
12946
12947
12948
12949
12950
12951
12952
12953
12954
12955
12956
12957
12958
12959
12960
12961
12962
12963
12964
12965
12966
12967
12968
12969
12970
12971
12972
12973
12974
12975
12976
12977
12978
12979
12980
12981
12982
12983
12984
12985
12986
12987
12988
12989
12990
12991
12992
12993
12994
12995
12996
12997
12998
12999
13000
13001
13002
13003
13004
13005
13006
13007
13008
13009
13010
13011
13012
13013
13014
13015
13016
13017
13018
13019
13020
13021
13022
13023
13024
13025
13026
13027
13028
13029
13030
13031
13032
13033
13034
13035
13036
13037
13038
13039
13040
13041
13042
13043
13044
13045
13046
13047
13048
13049
13050
13051
13052
13053
13054
13055
13056
13057
13058
13059
13060
13061
13062
13063
13064
13065
13066
13067
13068
13069
13070
13071
13072
13073
13074
13075
13076
13077
13078
13079
13080
13081
13082
13083
13084
13085
13086
13087
13088
13089
13090
13091
13092
13093
13094
13095
13096
13097
13098
13099
13100
13101
13102
13103
13104
13105
13106
13107
13108
13109
13110
13111
13112
13113
13114
13115
13116
13117
13118
13119
13120
13121
13122
13123
13124
13125
13126
13127
13128
13129
13130
13131
13132
13133
13134
13135
13136
13137
13138
13139
13140
13141
13142
13143
13144
13145
13146
13147
13148
13149
13150
13151
13152
13153
13154
13155
13156
13157
13158
13159
13160
13161
13162
13163
13164
13165
13166
13167
13168
13169
13170
13171
13172
13173
13174
13175
13176
13177
13178
13179
13180
13181
13182
13183
13184
13185
13186
13187
13188
13189
13190
13191
13192
13193
13194
13195
13196
13197
13198
13199
13200
13201
13202
13203
13204
13205
13206
13207
13208
13209
13210
13211
13212
13213
13214
13215
13216
13217
13218
13219
13220
13221
13222
13223
13224
13225
13226
13227
13228
13229
13230
13231
13232
13233
13234
13235
13236
13237
13238
13239
13240
13241
13242
13243
13244
13245
13246
13247
13248
13249
13250
13251
13252
13253
13254
13255
13256
13257
13258
13259
13260
13261
13262
13263
13264
13265
13266
13267
13268
13269
13270
13271
13272
13273
13274
13275
13276
13277
13278
13279
13280
13281
13282
13283
13284
13285
13286
13287
13288
13289
13290
13291
13292
13293
13294
13295
13296
13297
13298
13299
13300
13301
13302
13303
13304
13305
13306
13307
13308
13309
13310
13311
13312
13313
13314
13315
13316
13317
13318
13319
13320
13321
13322
13323
13324
13325
13326
13327
13328
13329
13330
13331
13332
13333
13334
13335
13336
13337
13338
13339
13340
13341
13342
13343
13344
13345
13346
13347
13348
13349
13350
13351
13352
13353
13354
13355
13356
13357
13358
13359
13360
13361
13362
13363
13364
13365
13366
13367
13368
13369
13370
13371
13372
13373
13374
13375
13376
13377
13378
13379
13380
13381
13382
13383
13384
13385
13386
13387
13388
13389
13390
13391
13392
13393
13394
13395
13396
13397
13398
13399
13400
13401
13402
13403
13404
13405
13406
13407
13408
13409
13410
13411
13412
13413
13414
13415
13416
13417
13418
13419
13420
13421
13422
13423
13424
13425
13426
13427
13428
13429
13430
13431
13432
13433
13434
13435
13436
13437
13438
13439
13440
13441
13442
13443
13444
13445
13446
13447
13448
13449
13450
13451
13452
13453
13454
13455
13456
13457
13458
13459
13460
13461
13462
13463
13464
13465
13466
13467
13468
13469
13470
13471
13472
13473
13474
13475
13476
13477
13478
13479
13480
13481
13482
13483
13484
13485
13486
13487
13488
13489
13490
13491
13492
13493
13494
13495
13496
13497
13498
13499
13500
13501
13502
13503
13504
13505
13506
13507
13508
13509
13510
13511
13512
13513
13514
13515
13516
13517
13518
13519
13520
13521
13522
13523
13524
13525
13526
13527
13528
13529
13530
13531
13532
13533
13534
13535
13536
13537
13538
13539
13540
13541
13542
13543
13544
13545
13546
13547
13548
13549
13550
13551
13552
13553
13554
13555
13556
13557
13558
13559
13560
13561
13562
13563
13564
13565
13566
13567
13568
13569
13570
13571
13572
13573
13574
13575
13576
13577
13578
13579
13580
13581
13582
13583
13584
13585
13586
13587
13588
13589
13590
13591
13592
13593
13594
13595
13596
13597
13598
13599
13600
13601
13602
13603
13604
13605
13606
13607
13608
13609
13610
13611
13612
13613
13614
13615
13616
13617
13618
13619
13620
13621
13622
13623
13624
13625
13626
13627
13628
13629
13630
13631
13632
13633
13634
13635
13636
13637
13638
13639
13640
13641
13642
13643
13644
13645
13646
13647
13648
13649
13650
13651
13652
13653
13654
13655
13656
13657
13658
13659
13660
13661
13662
13663
13664
13665
13666
13667
13668
13669
13670
13671
13672
13673
13674
13675
13676
13677
13678
13679
13680
13681
13682
13683
13684
13685
13686
13687
13688
13689
13690
13691
13692
13693
13694
13695
13696
13697
13698
13699
13700
13701
13702
13703
13704
13705
13706
13707
13708
13709
13710
13711
13712
13713
13714
13715
13716
13717
13718
13719
13720
13721
13722
13723
13724
13725
13726
13727
13728
13729
13730
13731
13732
13733
13734
13735
13736
13737
13738
13739
13740
13741
13742
13743
13744
13745
13746
13747
13748
13749
13750
13751
13752
13753
13754
13755
13756
13757
13758
13759
13760
13761
13762
13763
13764
13765
13766
13767
13768
13769
13770
13771
13772
13773
13774
13775
13776
13777
13778
13779
13780
13781
13782
13783
13784
13785
13786
13787
13788
13789
13790
13791
13792
13793
13794
13795
13796
13797
13798
13799
13800
13801
13802
13803
13804
13805
13806
13807
13808
13809
13810
13811
13812
13813
13814
13815
13816
13817
13818
13819
13820
13821
13822
13823
13824
13825
13826
13827
13828
13829
13830
13831
13832
13833
13834
13835
13836
13837
13838
13839
13840
13841
13842
13843
13844
13845
13846
13847
13848
13849
13850
13851
13852
13853
13854
13855
13856
13857
13858
13859
13860
13861
13862
13863
13864
13865
13866
13867
13868
13869
13870
13871
13872
13873
13874
13875
13876
13877
13878
13879
13880
13881
13882
13883
13884
13885
13886
13887
13888
13889
13890
13891
13892
13893
13894
13895
13896
13897
13898
13899
13900
13901
13902
13903
13904
13905
13906
13907
13908
13909
13910
13911
13912
13913
13914
13915
13916
13917
13918
13919
13920
13921
13922
13923
13924
13925
13926
13927
13928
13929
13930
13931
13932
13933
13934
13935
13936
13937
13938
13939
13940
13941
13942
13943
13944
13945
13946
13947
13948
13949
13950
13951
13952
13953
13954
13955
13956
13957
13958
13959
13960
13961
13962
13963
13964
13965
13966
13967
13968
13969
13970
13971
13972
13973
13974
13975
13976
13977
13978
13979
13980
13981
13982
13983
13984
13985
13986
13987
13988
13989
13990
13991
13992
13993
13994
13995
13996
13997
13998
13999
14000
14001
14002
14003
14004
14005
14006
14007
14008
14009
14010
14011
14012
14013
14014
14015
14016
14017
14018
14019
14020
14021
14022
14023
14024
14025
14026
14027
14028
14029
14030
14031
14032
14033
14034
14035
14036
14037
14038
14039
14040
14041
14042
14043
14044
14045
14046
14047
14048
14049
14050
14051
14052
14053
14054
14055
14056
14057
14058
14059
14060
14061
14062
14063
14064
14065
14066
14067
14068
14069
14070
14071
14072
14073
14074
14075
14076
14077
14078
14079
14080
14081
14082
14083
14084
14085
14086
14087
14088
14089
14090
14091
14092
14093
14094
14095
14096
14097
14098
14099
14100
14101
14102
14103
14104
14105
14106
14107
14108
14109
14110
14111
14112
14113
14114
14115
14116
14117
14118
14119
14120
14121
14122
14123
14124
14125
14126
14127
14128
14129
14130
14131
14132
14133
14134
14135
14136
14137
14138
14139
14140
14141
14142
14143
14144
14145
14146
14147
14148
14149
14150
14151
14152
14153
14154
14155
14156
14157
14158
14159
14160
14161
14162
14163
14164
14165
14166
14167
14168
14169
14170
14171
14172
14173
14174
14175
14176
14177
14178
14179
14180
14181
14182
14183
14184
14185
14186
14187
14188
14189
14190
14191
14192
14193
14194
14195
14196
14197
14198
14199
14200
14201
14202
14203
14204
14205
14206
14207
14208
14209
14210
14211
14212
14213
14214
14215
14216
14217
14218
14219
14220
14221
14222
14223
14224
14225
14226
14227
14228
14229
14230
14231
14232
14233
14234
14235
14236
14237
14238
14239
14240
14241
14242
14243
14244
14245
14246
14247
14248
14249
14250
14251
14252
14253
14254
14255
14256
14257
14258
14259
14260
14261
14262
14263
14264
14265
14266
14267
14268
14269
14270
14271
14272
14273
14274
14275
14276
14277
14278
14279
14280
14281
14282
14283
14284
14285
14286
14287
14288
14289
14290
14291
14292
14293
14294
14295
14296
14297
14298
14299
14300
14301
14302
14303
14304
14305
14306
14307
14308
14309
14310
14311
14312
14313
14314
14315
14316
14317
14318
14319
14320
14321
14322
14323
14324
14325
14326
14327
14328
14329
14330
14331
14332
14333
14334
14335
14336
14337
14338
14339
14340
14341
14342
14343
14344
14345
14346
14347
14348
14349
14350
14351
14352
14353
14354
14355
14356
14357
14358
14359
14360
14361
14362
14363
14364
14365
14366
14367
14368
14369
14370
14371
14372
14373
14374
14375
14376
14377
14378
14379
14380
14381
14382
14383
14384
14385
14386
14387
14388
14389
14390
14391
14392
14393
14394
14395
14396
14397
14398
14399
14400
14401
14402
14403
14404
14405
14406
14407
14408
14409
14410
14411
14412
14413
14414
14415
14416
14417
14418
14419
14420
14421
14422
14423
14424
14425
14426
14427
14428
14429
14430
14431
14432
14433
14434
14435
14436
14437
14438
14439
14440
14441
14442
14443
14444
14445
14446
14447
14448
14449
14450
14451
14452
14453
14454
14455
14456
14457
14458
14459
14460
14461
14462
14463
14464
14465
14466
14467
14468
14469
14470
14471
14472
14473
14474
14475
14476
14477
14478
14479
14480
14481
14482
14483
14484
14485
14486
14487
14488
14489
14490
14491
14492
14493
14494
14495
14496
14497
14498
14499
14500
14501
14502
14503
14504
14505
14506
14507
14508
14509
14510
14511
14512
14513
14514
14515
14516
14517
14518
14519
14520
14521
14522
14523
14524
14525
14526
14527
14528
14529
14530
14531
14532
14533
14534
14535
14536
14537
14538
14539
14540
14541
14542
14543
14544
14545
14546
14547
14548
14549
14550
14551
14552
14553
14554
14555
14556
14557
14558
14559
14560
14561
14562
14563
14564
14565
14566
14567
14568
14569
14570
14571
14572
14573
14574
14575
14576
14577
14578
14579
14580
14581
14582
14583
14584
14585
14586
14587
14588
14589
14590
14591
14592
14593
14594
14595
14596
14597
14598
14599
14600
14601
14602
14603
14604
14605
14606
14607
14608
14609
14610
14611
14612
14613
14614
14615
14616
14617
14618
14619
14620
14621
14622
14623
14624
14625
14626
14627
14628
14629
14630
14631
14632
14633
14634
14635
14636
14637
14638
14639
14640
14641
14642
14643
14644
14645
14646
14647
14648
14649
14650
14651
14652
14653
14654
14655
14656
14657
14658
14659
14660
14661
14662
14663
14664
14665
14666
14667
14668
14669
14670
14671
14672
14673
14674
14675
14676
14677
14678
14679
14680
14681
14682
14683
14684
14685
14686
14687
14688
14689
14690
14691
14692
14693
14694
14695
14696
14697
14698
14699
14700
14701
14702
14703
14704
14705
14706
14707
14708
14709
14710
14711
14712
14713
14714
14715
14716
14717
14718
14719
14720
14721
14722
14723
14724
14725
14726
14727
14728
14729
14730
14731
14732
14733
14734
14735
14736
14737
14738
14739
14740
14741
14742
14743
14744
14745
14746
14747
14748
14749
14750
14751
14752
14753
14754
14755
14756
14757
14758
14759
14760
14761
14762
14763
14764
14765
14766
14767
14768
14769
14770
14771
14772
14773
14774
14775
14776
14777
14778
14779
14780
14781
14782
14783
14784
14785
14786
14787
14788
14789
14790
14791
14792
14793
14794
14795
14796
14797
14798
14799
14800
14801
14802
14803
14804
14805
14806
14807
14808
14809
14810
14811
14812
14813
14814
14815
14816
14817
14818
14819
14820
14821
14822
14823
14824
14825
14826
14827
14828
14829
14830
14831
14832
14833
14834
14835
14836
14837
14838
14839
14840
14841
14842
14843
14844
14845
14846
14847
14848
14849
14850
14851
14852
14853
14854
14855
14856
14857
14858
14859
14860
14861
14862
14863
14864
14865
14866
14867
14868
14869
14870
14871
14872
14873
14874
14875
14876
14877
14878
14879
14880
14881
14882
14883
14884
14885
14886
14887
14888
14889
14890
14891
14892
14893
14894
14895
14896
14897
14898
14899
14900
14901
14902
14903
14904
14905
14906
14907
14908
14909
14910
14911
14912
14913
14914
14915
14916
14917
14918
14919
14920
14921
14922
14923
14924
14925
14926
14927
14928
14929
14930
14931
14932
14933
14934
14935
14936
14937
14938
14939
14940
14941
14942
14943
14944
14945
14946
14947
14948
14949
14950
14951
14952
14953
14954
14955
14956
14957
14958
14959
14960
14961
14962
14963
14964
14965
14966
14967
14968
14969
14970
14971
14972
14973
14974
14975
14976
14977
14978
14979
14980
14981
14982
14983
14984
14985
14986
14987
14988
14989
14990
14991
14992
14993
14994
14995
14996
14997
14998
14999
15000
15001
15002
15003
15004
15005
15006
15007
15008
15009
15010
15011
15012
15013
15014
15015
15016
15017
15018
15019
15020
15021
15022
15023
15024
15025
15026
15027
15028
15029
15030
15031
15032
15033
15034
15035
15036
15037
15038
15039
15040
15041
15042
15043
15044
15045
15046
15047
15048
15049
15050
15051
15052
15053
15054
15055
15056
15057
15058
15059
15060
15061
15062
15063
15064
15065
15066
15067
15068
15069
15070
15071
15072
15073
15074
15075
15076
15077
15078
15079
15080
15081
15082
15083
15084
15085
15086
15087
15088
15089
15090
15091
15092
15093
15094
15095
15096
15097
15098
15099
15100
15101
15102
15103
15104
15105
15106
15107
15108
15109
15110
15111
15112
15113
15114
15115
15116
15117
15118
15119
15120
15121
15122
15123
15124
15125
15126
15127
15128
15129
15130
15131
15132
15133
15134
15135
15136
15137
15138
15139
15140
15141
15142
15143
15144
15145
15146
15147
15148
15149
15150
15151
15152
15153
15154
15155
15156
15157
15158
15159
15160
15161
15162
15163
15164
15165
15166
15167
15168
15169
15170
15171
15172
15173
15174
15175
15176
15177
15178
15179
15180
15181
15182
15183
15184
15185
15186
15187
15188
15189
15190
15191
15192
15193
15194
15195
15196
15197
15198
15199
15200
15201
15202
15203
15204
15205
15206
15207
15208
15209
15210
15211
15212
15213
15214
15215
15216
15217
15218
15219
15220
15221
15222
15223
15224
15225
15226
15227
15228
15229
15230
15231
15232
15233
15234
15235
15236
15237
15238
15239
15240
15241
15242
15243
15244
15245
15246
15247
15248
15249
15250
15251
15252
15253
15254
15255
15256
15257
15258
15259
15260
15261
15262
15263
15264
15265
15266
15267
15268
15269
15270
15271
15272
15273
15274
15275
15276
15277
15278
15279
15280
15281
15282
15283
15284
15285
15286
15287
15288
15289
15290
15291
15292
15293
15294
15295
15296
15297
15298
15299
15300
15301
15302
15303
15304
15305
15306
15307
15308
15309
15310
15311
15312
15313
15314
15315
15316
15317
15318
15319
15320
15321
15322
15323
15324
15325
15326
15327
15328
15329
15330
15331
15332
15333
15334
15335
15336
15337
15338
15339
15340
15341
15342
15343
15344
15345
15346
15347
15348
15349
15350
15351
15352
15353
15354
15355
15356
15357
15358
15359
15360
15361
15362
15363
15364
15365
15366
15367
15368
15369
15370
15371
15372
15373
15374
15375
15376
15377
15378
15379
15380
15381
15382
15383
15384
15385
15386
15387
15388
15389
15390
15391
15392
15393
15394
15395
15396
15397
15398
15399
15400
15401
15402
15403
15404
15405
15406
15407
15408
15409
15410
15411
15412
15413
15414
15415
15416
15417
15418
15419
15420
15421
15422
15423
15424
15425
15426
15427
15428
15429
15430
15431
15432
15433
15434
15435
15436
15437
15438
15439
15440
15441
15442
15443
15444
15445
15446
15447
15448
15449
15450
15451
15452
15453
15454
15455
15456
15457
15458
15459
15460
15461
15462
15463
15464
15465
15466
15467
15468
15469
15470
15471
15472
15473
15474
15475
15476
15477
15478
15479
15480
15481
15482
15483
15484
15485
15486
15487
15488
15489
15490
15491
15492
15493
15494
15495
15496
15497
15498
15499
15500
15501
15502
15503
15504
15505
15506
15507
15508
15509
15510
15511
15512
15513
15514
15515
15516
15517
15518
15519
15520
15521
15522
15523
15524
15525
15526
15527
15528
15529
15530
15531
15532
15533
15534
15535
15536
15537
15538
15539
15540
15541
15542
15543
15544
15545
15546
15547
15548
15549
15550
15551
15552
15553
15554
15555
15556
15557
15558
15559
15560
15561
15562
15563
15564
15565
15566
15567
15568
15569
15570
15571
15572
15573
15574
15575
15576
15577
15578
15579
15580
15581
15582
15583
15584
15585
15586
15587
15588
15589
15590
15591
15592
15593
15594
15595
15596
15597
15598
15599
15600
15601
15602
15603
15604
15605
15606
15607
15608
15609
15610
15611
15612
15613
15614
15615
15616
15617
15618
15619
15620
15621
15622
15623
15624
15625
15626
15627
15628
15629
15630
15631
15632
15633
15634
15635
15636
15637
15638
15639
15640
15641
15642
15643
15644
15645
15646
15647
15648
15649
15650
15651
15652
15653
15654
15655
15656
15657
15658
15659
15660
15661
15662
15663
15664
15665
15666
15667
15668
15669
15670
15671
15672
15673
15674
15675
15676
15677
15678
15679
15680
15681
15682
15683
15684
15685
15686
15687
15688
15689
15690
15691
15692
15693
15694
15695
15696
15697
15698
15699
15700
15701
15702
15703
15704
15705
15706
15707
15708
15709
15710
15711
15712
15713
15714
15715
15716
15717
15718
15719
15720
15721
15722
15723
15724
15725
15726
15727
15728
15729
15730
15731
15732
15733
15734
15735
15736
15737
15738
15739
15740
15741
15742
15743
15744
15745
15746
15747
15748
15749
15750
15751
15752
15753
15754
15755
15756
15757
15758
15759
15760
15761
15762
15763
15764
15765
15766
15767
15768
15769
15770
15771
15772
15773
15774
15775
15776
15777
15778
15779
15780
15781
15782
15783
15784
15785
15786
15787
15788
15789
15790
15791
15792
15793
15794
15795
15796
15797
15798
15799
15800
15801
15802
15803
15804
15805
15806
15807
15808
15809
15810
15811
15812
15813
15814
15815
15816
15817
15818
15819
15820
15821
15822
15823
15824
15825
15826
15827
15828
15829
15830
15831
15832
15833
15834
15835
15836
15837
15838
15839
15840
15841
15842
15843
15844
15845
15846
15847
15848
15849
15850
15851
15852
15853
15854
15855
15856
15857
15858
15859
15860
15861
15862
15863
15864
15865
15866
15867
15868
15869
15870
15871
15872
15873
15874
15875
15876
15877
15878
15879
15880
15881
15882
15883
15884
15885
15886
15887
15888
15889
15890
15891
15892
15893
15894
15895
15896
15897
15898
15899
15900
15901
15902
15903
15904
15905
15906
15907
15908
15909
15910
15911
15912
15913
15914
15915
15916
15917
15918
15919
15920
15921
15922
15923
15924
15925
15926
15927
15928
15929
15930
15931
15932
15933
15934
15935
15936
15937
15938
15939
15940
15941
15942
15943
15944
15945
15946
15947
15948
15949
15950
15951
15952
15953
15954
15955
15956
15957
15958
15959
15960
15961
15962
15963
15964
15965
15966
15967
15968
15969
15970
15971
15972
15973
15974
15975
15976
15977
15978
15979
15980
15981
15982
15983
15984
15985
15986
15987
15988
15989
15990
15991
15992
15993
15994
15995
15996
15997
15998
15999
16000
16001
16002
16003
16004
16005
16006
16007
16008
16009
16010
16011
16012
16013
16014
16015
16016
16017
16018
16019
16020
16021
16022
16023
16024
16025
16026
16027
16028
16029
16030
16031
16032
16033
16034
16035
16036
16037
16038
16039
16040
16041
16042
16043
16044
16045
16046
16047
16048
16049
16050
16051
16052
16053
16054
16055
16056
16057
16058
16059
16060
16061
16062
16063
16064
16065
16066
16067
16068
16069
16070
16071
16072
16073
16074
16075
16076
16077
16078
16079
16080
16081
16082
16083
16084
16085
16086
16087
16088
16089
16090
16091
16092
16093
16094
16095
16096
16097
16098
16099
16100
16101
16102
16103
16104
16105
16106
16107
16108
16109
16110
16111
16112
16113
16114
16115
16116
16117
16118
16119
16120
16121
16122
16123
16124
16125
16126
16127
16128
16129
16130
16131
16132
16133
16134
16135
16136
16137
16138
16139
16140
16141
16142
16143
16144
16145
16146
16147
16148
16149
16150
16151
16152
16153
16154
16155
16156
16157
16158
16159
16160
16161
16162
16163
16164
16165
16166
16167
16168
16169
16170
16171
16172
16173
16174
16175
16176
16177
16178
16179
16180
16181
16182
16183
16184
16185
16186
16187
16188
16189
16190
16191
16192
16193
16194
16195
16196
16197
16198
16199
16200
16201
16202
16203
16204
16205
16206
16207
16208
16209
16210
16211
16212
16213
16214
16215
16216
16217
16218
16219
16220
16221
16222
16223
16224
16225
16226
16227
16228
16229
16230
16231
16232
16233
16234
16235
16236
16237
16238
16239
16240
16241
16242
16243
16244
16245
16246
16247
16248
16249
16250
16251
16252
16253
16254
16255
16256
16257
16258
16259
16260
16261
16262
16263
16264
16265
16266
16267
16268
16269
16270
16271
16272
16273
16274
16275
16276
16277
16278
16279
16280
16281
16282
16283
16284
16285
16286
16287
16288
16289
16290
16291
16292
16293
16294
16295
16296
16297
16298
16299
16300
16301
16302
16303
16304
16305
16306
16307
16308
16309
16310
16311
16312
16313
16314
16315
16316
16317
16318
16319
16320
16321
16322
16323
16324
16325
16326
16327
16328
16329
16330
16331
16332
16333
16334
16335
16336
16337
16338
16339
16340
16341
16342
16343
16344
16345
16346
16347
16348
16349
16350
16351
16352
16353
16354
16355
16356
16357
16358
16359
16360
16361
16362
16363
16364
16365
16366
16367
16368
16369
16370
16371
16372
16373
16374
16375
16376
16377
16378
16379
16380
16381
16382
16383
16384
16385
16386
16387
16388
16389
16390
16391
16392
16393
16394
16395
16396
16397
16398
16399
16400
16401
16402
16403
16404
16405
16406
16407
16408
16409
16410
16411
16412
16413
16414
16415
16416
16417
16418
16419
16420
16421
16422
16423
16424
16425
16426
16427
16428
16429
16430
16431
16432
16433
16434
16435
16436
16437
16438
16439
16440
16441
16442
16443
16444
16445
16446
16447
16448
16449
16450
16451
16452
16453
16454
16455
16456
16457
16458
16459
16460
16461
16462
16463
16464
16465
16466
16467
16468
16469
16470
16471
16472
16473
16474
16475
16476
16477
16478
16479
16480
16481
16482
16483
16484
16485
16486
16487
16488
16489
16490
16491
16492
16493
16494
16495
16496
16497
16498
16499
16500
16501
16502
16503
16504
16505
16506
16507
16508
16509
16510
16511
16512
16513
16514
16515
16516
16517
16518
16519
16520
16521
16522
16523
16524
16525
16526
16527
16528
16529
16530
16531
16532
16533
16534
16535
16536
16537
16538
16539
16540
16541
16542
16543
16544
16545
16546
16547
16548
16549
16550
16551
16552
16553
16554
16555
16556
16557
16558
16559
16560
16561
16562
16563
16564
16565
16566
16567
16568
16569
16570
16571
16572
16573
16574
16575
16576
16577
16578
16579
16580
16581
16582
16583
16584
16585
16586
16587
16588
16589
16590
16591
16592
16593
16594
16595
16596
16597
16598
16599
16600
16601
16602
16603
16604
16605
16606
16607
16608
16609
16610
16611
16612
16613
16614
16615
16616
16617
16618
16619
16620
16621
16622
16623
16624
16625
16626
16627
16628
16629
16630
16631
16632
16633
16634
16635
16636
16637
16638
16639
16640
16641
16642
16643
16644
16645
16646
16647
16648
16649
16650
16651
16652
16653
16654
16655
16656
16657
16658
16659
16660
16661
16662
16663
16664
16665
16666
16667
16668
16669
16670
16671
16672
16673
16674
16675
16676
16677
16678
16679
16680
16681
16682
16683
16684
16685
16686
16687
16688
16689
16690
16691
16692
16693
16694
16695
16696
16697
16698
16699
16700
16701
16702
16703
16704
16705
16706
16707
16708
16709
16710
16711
16712
16713
16714
16715
16716
16717
16718
16719
16720
16721
16722
16723
16724
16725
16726
16727
16728
16729
16730
16731
16732
16733
16734
16735
16736
16737
16738
16739
16740
16741
16742
16743
16744
16745
16746
16747
16748
16749
16750
16751
16752
16753
16754
16755
16756
16757
16758
16759
16760
16761
16762
16763
16764
16765
16766
16767
16768
16769
16770
16771
16772
16773
16774
16775
16776
16777
16778
16779
16780
16781
16782
16783
16784
16785
16786
16787
16788
16789
16790
16791
16792
16793
16794
16795
16796
16797
16798
16799
16800
16801
16802
16803
16804
16805
16806
16807
16808
16809
16810
16811
16812
16813
16814
16815
16816
16817
16818
16819
16820
16821
16822
16823
16824
16825
16826
16827
16828
16829
16830
16831
16832
16833
16834
16835
16836
16837
16838
16839
16840
16841
16842
16843
16844
16845
16846
16847
16848
16849
16850
16851
16852
16853
16854
16855
16856
16857
16858
16859
16860
16861
16862
16863
16864
16865
16866
16867
16868
16869
16870
16871
16872
16873
16874
16875
16876
16877
16878
16879
16880
16881
16882
16883
16884
16885
16886
16887
16888
16889
16890
16891
16892
16893
16894
16895
16896
16897
16898
16899
16900
16901
16902
16903
16904
16905
16906
16907
16908
16909
16910
16911
16912
16913
16914
16915
16916
16917
16918
16919
16920
16921
16922
16923
16924
16925
16926
16927
16928
16929
16930
16931
16932
16933
16934
16935
16936
16937
16938
16939
16940
16941
16942
16943
16944
16945
16946
16947
16948
16949
16950
16951
16952
16953
16954
16955
16956
16957
16958
16959
16960
16961
16962
16963
16964
16965
16966
16967
16968
16969
16970
16971
16972
16973
16974
16975
16976
16977
16978
16979
16980
16981
16982
16983
16984
16985
16986
16987
16988
16989
16990
16991
16992
16993
16994
16995
16996
16997
16998
16999
17000
17001
17002
17003
17004
17005
17006
17007
17008
17009
17010
17011
17012
17013
17014
17015
17016
17017
17018
17019
17020
17021
17022
17023
17024
17025
17026
17027
17028
17029
17030
17031
17032
17033
17034
17035
17036
17037
17038
17039
17040
17041
17042
17043
17044
17045
17046
17047
17048
17049
17050
17051
17052
17053
17054
17055
17056
17057
17058
17059
17060
17061
17062
17063
17064
17065
17066
17067
17068
17069
17070
17071
17072
17073
17074
17075
17076
17077
17078
17079
17080
17081
17082
17083
17084
17085
17086
17087
17088
17089
17090
17091
17092
17093
17094
17095
17096
17097
17098
17099
17100
17101
17102
17103
17104
17105
17106
17107
17108
17109
17110
17111
17112
17113
17114
17115
17116
17117
17118
17119
17120
17121
17122
17123
17124
17125
17126
17127
17128
17129
17130
17131
17132
17133
17134
17135
17136
17137
17138
17139
17140
17141
17142
17143
17144
17145
17146
17147
17148
17149
17150
17151
17152
17153
17154
17155
17156
17157
17158
17159
17160
17161
17162
17163
17164
17165
17166
17167
17168
17169
17170
17171
17172
17173
17174
17175
17176
17177
17178
17179
17180
17181
17182
17183
17184
17185
17186
17187
17188
17189
17190
17191
17192
17193
17194
17195
17196
17197
17198
17199
17200
17201
17202
17203
17204
17205
17206
17207
17208
17209
17210
17211
17212
17213
17214
17215
17216
17217
17218
17219
17220
17221
17222
17223
17224
17225
17226
17227
17228
17229
17230
17231
17232
17233
17234
17235
17236
17237
17238
17239
17240
17241
17242
17243
17244
17245
17246
17247
17248
17249
17250
17251
17252
17253
17254
17255
17256
17257
17258
17259
17260
17261
17262
17263
17264
17265
17266
17267
17268
17269
17270
17271
17272
17273
17274
17275
17276
17277
17278
17279
17280
17281
17282
17283
17284
17285
17286
17287
17288
17289
17290
17291
17292
17293
17294
17295
17296
17297
17298
17299
17300
17301
17302
17303
17304
17305
17306
17307
17308
17309
17310
17311
17312
17313
17314
17315
17316
17317
17318
17319
17320
17321
17322
17323
17324
17325
17326
17327
17328
17329
17330
17331
17332
17333
17334
17335
17336
17337
17338
17339
17340
17341
17342
17343
17344
17345
17346
17347
17348
17349
17350
17351
17352
17353
17354
17355
17356
17357
17358
17359
17360
17361
17362
17363
17364
17365
17366
17367
17368
17369
17370
17371
17372
17373
17374
17375
17376
17377
17378
17379
17380
17381
17382
17383
17384
17385
17386
17387
17388
17389
17390
17391
17392
17393
17394
17395
17396
17397
17398
17399
17400
17401
17402
17403
17404
17405
17406
17407
17408
17409
17410
17411
17412
17413
17414
17415
17416
17417
17418
17419
17420
17421
17422
17423
17424
17425
17426
17427
17428
17429
17430
17431
17432
17433
17434
17435
17436
17437
17438
17439
17440
17441
17442
17443
17444
17445
17446
17447
17448
17449
17450
17451
17452
17453
17454
17455
17456
17457
17458
17459
17460
17461
17462
17463
17464
17465
17466
17467
17468
17469
17470
17471
17472
17473
17474
17475
17476
17477
17478
17479
17480
17481
17482
17483
17484
17485
17486
17487
17488
17489
17490
17491
17492
17493
17494
17495
17496
17497
17498
17499
17500
17501
17502
17503
17504
17505
17506
17507
17508
17509
17510
17511
17512
17513
17514
17515
17516
17517
17518
17519
17520
17521
17522
17523
17524
17525
17526
17527
17528
17529
17530
17531
17532
17533
17534
17535
17536
17537
17538
17539
17540
17541
17542
17543
17544
17545
17546
17547
17548
17549
17550
17551
17552
17553
17554
17555
17556
17557
17558
17559
17560
17561
17562
17563
17564
17565
17566
17567
17568
17569
17570
17571
17572
17573
17574
17575
17576
17577
17578
17579
17580
17581
17582
17583
17584
17585
17586
17587
17588
17589
17590
17591
17592
17593
17594
17595
17596
17597
17598
17599
17600
17601
17602
17603
17604
17605
17606
17607
17608
17609
17610
17611
17612
17613
17614
17615
17616
17617
17618
17619
17620
17621
17622
17623
17624
17625
17626
17627
17628
17629
17630
17631
17632
17633
17634
17635
17636
17637
17638
17639
17640
17641
17642
17643
17644
17645
17646
17647
17648
17649
17650
17651
17652
17653
17654
17655
17656
17657
17658
17659
17660
17661
17662
17663
17664
17665
17666
17667
17668
17669
17670
17671
17672
17673
17674
17675
17676
17677
17678
17679
17680
17681
17682
17683
17684
17685
17686
17687
17688
17689
17690
17691
17692
17693
17694
17695
17696
17697
17698
17699
17700
17701
17702
17703
17704
17705
17706
17707
17708
17709
17710
17711
17712
17713
17714
17715
17716
17717
17718
17719
17720
17721
17722
17723
17724
17725
17726
17727
17728
17729
17730
17731
17732
17733
17734
17735
17736
17737
17738
17739
17740
17741
17742
17743
17744
17745
17746
17747
17748
17749
17750
17751
17752
17753
17754
17755
17756
17757
17758
17759
17760
17761
17762
17763
17764
17765
17766
17767
17768
17769
17770
17771
17772
17773
17774
17775
17776
17777
17778
17779
17780
17781
17782
17783
17784
17785
17786
17787
17788
17789
17790
17791
17792
17793
17794
17795
17796
17797
17798
17799
17800
17801
17802
17803
17804
17805
17806
17807
17808
17809
17810
17811
17812
17813
17814
17815
17816
17817
17818
17819
17820
17821
17822
17823
17824
17825
17826
17827
17828
17829
17830
17831
17832
17833
17834
17835
17836
17837
17838
17839
17840
17841
17842
17843
17844
17845
17846
17847
17848
17849
17850
17851
17852
17853
17854
17855
17856
17857
17858
17859
17860
17861
17862
17863
17864
17865
17866
17867
17868
17869
17870
17871
17872
17873
17874
17875
17876
17877
17878
17879
17880
17881
17882
17883
17884
17885
17886
17887
17888
17889
17890
17891
17892
17893
17894
17895
17896
17897
17898
17899
17900
17901
17902
17903
17904
17905
17906
17907
17908
17909
17910
17911
17912
17913
17914
17915
17916
17917
17918
17919
17920
17921
17922
17923
17924
17925
17926
17927
17928
17929
17930
17931
17932
17933
17934
17935
17936
17937
17938
17939
17940
17941
17942
17943
17944
17945
17946
17947
17948
17949
17950
17951
17952
17953
17954
17955
17956
17957
17958
17959
17960
17961
17962
17963
17964
17965
17966
17967
17968
17969
17970
17971
17972
17973
17974
17975
17976
17977
17978
17979
17980
17981
17982
17983
17984
17985
17986
17987
17988
17989
17990
17991
17992
17993
17994
17995
17996
17997
17998
17999
18000
18001
18002
18003
18004
18005
18006
18007
18008
18009
18010
18011
18012
18013
18014
18015
18016
18017
18018
18019
18020
18021
18022
18023
18024
18025
18026
18027
18028
18029
18030
18031
18032
18033
18034
18035
18036
18037
18038
18039
18040
18041
18042
18043
18044
18045
18046
18047
18048
18049
18050
18051
18052
18053
18054
18055
18056
18057
18058
18059
18060
18061
18062
18063
18064
18065
18066
18067
18068
18069
18070
18071
18072
18073
18074
18075
18076
18077
18078
18079
18080
18081
18082
18083
18084
18085
18086
18087
18088
18089
18090
18091
18092
18093
18094
18095
18096
18097
18098
18099
18100
18101
18102
18103
18104
18105
18106
18107
18108
18109
18110
18111
18112
18113
18114
18115
18116
18117
18118
18119
18120
18121
18122
18123
18124
18125
18126
18127
18128
18129
18130
18131
18132
18133
18134
18135
18136
18137
18138
18139
18140
18141
18142
18143
18144
18145
18146
18147
18148
18149
18150
18151
18152
18153
18154
18155
18156
18157
18158
18159
18160
18161
18162
18163
18164
18165
18166
18167
18168
18169
18170
18171
18172
18173
18174
18175
18176
18177
18178
18179
18180
18181
18182
18183
18184
18185
18186
18187
18188
18189
18190
18191
18192
18193
18194
18195
18196
18197
18198
18199
18200
18201
18202
18203
18204
18205
18206
18207
18208
18209
18210
18211
18212
18213
18214
18215
18216
18217
18218
18219
18220
18221
18222
18223
18224
18225
18226
18227
18228
18229
18230
18231
18232
18233
18234
18235
18236
18237
18238
18239
18240
18241
18242
18243
18244
18245
18246
18247
18248
18249
18250
18251
18252
18253
18254
18255
18256
18257
18258
18259
18260
18261
18262
18263
18264
18265
18266
18267
18268
18269
18270
18271
18272
18273
18274
18275
18276
18277
18278
18279
18280
18281
18282
18283
18284
18285
18286
18287
18288
18289
18290
18291
18292
18293
18294
18295
18296
18297
18298
18299
18300
18301
18302
18303
18304
18305
18306
18307
18308
18309
18310
18311
18312
18313
18314
18315
18316
18317
18318
18319
18320
18321
18322
18323
18324
18325
18326
18327
18328
18329
18330
18331
18332
18333
18334
18335
18336
18337
18338
18339
18340
18341
18342
18343
18344
18345
18346
18347
18348
18349
18350
18351
18352
18353
18354
18355
18356
18357
18358
18359
18360
18361
18362
18363
18364
18365
18366
18367
18368
18369
18370
18371
18372
18373
18374
18375
18376
18377
18378
18379
18380
18381
18382
18383
18384
18385
18386
18387
18388
18389
18390
18391
18392
18393
18394
18395
18396
18397
18398
18399
18400
18401
18402
18403
18404
18405
18406
18407
18408
18409
18410
18411
18412
18413
18414
18415
18416
18417
18418
18419
18420
18421
18422
18423
18424
18425
18426
18427
18428
18429
18430
18431
18432
18433
18434
18435
18436
18437
18438
18439
18440
18441
18442
18443
18444
18445
18446
18447
18448
18449
18450
18451
18452
18453
18454
18455
18456
18457
18458
18459
18460
18461
18462
18463
18464
18465
18466
18467
18468
18469
18470
18471
18472
18473
18474
18475
18476
18477
18478
18479
18480
18481
18482
18483
18484
18485
18486
18487
18488
18489
18490
18491
18492
18493
18494
18495
18496
18497
18498
18499
18500
18501
18502
18503
18504
18505
18506
18507
18508
18509
18510
18511
18512
18513
18514
18515
18516
18517
18518
18519
18520
18521
18522
18523
18524
18525
18526
18527
18528
18529
18530
18531
18532
18533
18534
18535
18536
18537
18538
18539
18540
18541
18542
18543
18544
18545
18546
18547
18548
18549
18550
18551
18552
18553
18554
18555
18556
18557
18558
18559
18560
18561
18562
18563
18564
18565
18566
18567
18568
18569
18570
18571
18572
18573
18574
18575
18576
18577
18578
18579
18580
18581
18582
18583
18584
18585
18586
18587
18588
18589
18590
18591
18592
18593
18594
18595
18596
18597
18598
18599
18600
18601
18602
18603
18604
18605
18606
18607
18608
18609
18610
18611
18612
18613
18614
18615
18616
18617
18618
18619
18620
18621
18622
18623
18624
18625
18626
18627
18628
18629
18630
18631
18632
18633
18634
18635
18636
18637
18638
18639
18640
18641
18642
18643
18644
18645
18646
18647
18648
18649
18650
18651
18652
18653
18654
18655
18656
18657
18658
18659
18660
18661
18662
18663
18664
18665
18666
18667
18668
18669
18670
18671
18672
18673
18674
18675
18676
18677
18678
18679
18680
18681
18682
18683
18684
18685
18686
18687
18688
18689
18690
18691
18692
18693
18694
18695
18696
18697
18698
18699
18700
18701
18702
18703
18704
18705
18706
18707
18708
18709
18710
18711
18712
18713
18714
18715
18716
18717
18718
18719
18720
18721
18722
18723
18724
18725
18726
18727
18728
18729
18730
18731
18732
18733
18734
18735
18736
18737
18738
18739
18740
18741
18742
18743
18744
18745
18746
18747
18748
18749
18750
18751
18752
18753
18754
18755
18756
18757
18758
18759
18760
18761
18762
18763
18764
18765
18766
18767
18768
18769
18770
18771
18772
18773
18774
18775
18776
18777
18778
18779
18780
18781
18782
18783
18784
18785
18786
18787
18788
18789
18790
18791
18792
18793
18794
18795
18796
18797
18798
18799
18800
18801
18802
18803
18804
18805
18806
18807
18808
18809
18810
18811
18812
18813
18814
18815
18816
18817
18818
18819
18820
18821
18822
18823
18824
18825
18826
18827
18828
18829
18830
18831
18832
18833
18834
18835
18836
18837
18838
18839
18840
18841
18842
18843
18844
18845
18846
18847
18848
18849
18850
18851
18852
18853
18854
18855
18856
18857
18858
18859
18860
18861
18862
18863
18864
18865
18866
18867
18868
18869
18870
18871
18872
18873
18874
18875
18876
18877
18878
18879
18880
18881
18882
18883
18884
18885
18886
18887
18888
18889
18890
18891
18892
18893
18894
18895
18896
18897
18898
18899
18900
18901
18902
18903
18904
18905
18906
18907
18908
18909
18910
18911
18912
18913
18914
18915
18916
18917
18918
18919
18920
18921
18922
18923
18924
18925
18926
18927
18928
18929
18930
18931
18932
18933
18934
18935
18936
18937
18938
18939
18940
18941
18942
18943
18944
18945
18946
18947
18948
18949
18950
18951
18952
18953
18954
18955
18956
18957
18958
18959
18960
18961
18962
18963
18964
18965
18966
18967
18968
18969
18970
18971
18972
18973
18974
18975
18976
18977
18978
18979
18980
18981
18982
18983
18984
18985
18986
18987
18988
18989
18990
18991
18992
18993
18994
18995
18996
18997
18998
18999
19000
19001
19002
19003
19004
19005
19006
19007
19008
19009
19010
19011
19012
19013
19014
19015
19016
19017
19018
19019
19020
19021
19022
19023
19024
19025
19026
19027
19028
19029
19030
19031
19032
19033
19034
19035
19036
19037
19038
19039
19040
19041
19042
19043
19044
19045
19046
19047
19048
19049
19050
19051
19052
19053
19054
19055
19056
19057
19058
19059
19060
19061
19062
19063
19064
19065
19066
19067
19068
19069
19070
19071
19072
19073
19074
19075
19076
19077
19078
19079
19080
19081
19082
19083
19084
19085
19086
19087
19088
19089
19090
19091
19092
19093
19094
19095
19096
19097
19098
19099
19100
19101
19102
19103
19104
19105
19106
19107
19108
19109
19110
19111
19112
19113
19114
19115
19116
19117
19118
19119
19120
19121
19122
19123
19124
19125
19126
19127
19128
19129
19130
19131
19132
19133
19134
19135
19136
19137
19138
19139
19140
19141
19142
19143
19144
19145
19146
19147
19148
19149
19150
19151
19152
19153
19154
19155
19156
19157
19158
19159
19160
19161
19162
19163
19164
19165
19166
19167
19168
19169
19170
19171
19172
19173
19174
19175
19176
19177
19178
19179
19180
19181
19182
19183
19184
19185
19186
19187
19188
19189
19190
19191
19192
19193
19194
19195
19196
19197
19198
19199
19200
19201
19202
19203
19204
19205
19206
19207
19208
19209
19210
19211
19212
19213
19214
19215
19216
19217
19218
19219
19220
19221
19222
19223
19224
19225
19226
19227
19228
19229
19230
19231
19232
19233
19234
19235
19236
19237
19238
19239
19240
19241
19242
19243
19244
19245
19246
19247
19248
19249
19250
19251
19252
19253
19254
19255
19256
19257
19258
19259
19260
19261
19262
19263
19264
19265
19266
19267
19268
19269
19270
19271
19272
19273
19274
19275
19276
19277
19278
19279
19280
19281
19282
19283
19284
19285
19286
19287
19288
19289
19290
19291
19292
19293
19294
19295
19296
19297
19298
19299
19300
19301
19302
19303
19304
19305
19306
19307
19308
19309
19310
19311
19312
19313
19314
19315
19316
19317
19318
19319
19320
19321
19322
19323
19324
19325
19326
19327
19328
19329
19330
19331
19332
19333
19334
19335
19336
19337
19338
19339
19340
19341
19342
19343
19344
19345
19346
19347
19348
19349
19350
19351
19352
19353
19354
19355
19356
19357
19358
19359
19360
19361
19362
19363
19364
19365
19366
19367
19368
19369
19370
19371
19372
19373
19374
19375
19376
19377
19378
19379
19380
19381
19382
19383
19384
19385
19386
19387
19388
19389
19390
19391
19392
19393
19394
19395
19396
19397
19398
19399
19400
19401
19402
19403
19404
19405
19406
19407
19408
19409
19410
19411
19412
19413
19414
19415
19416
19417
19418
19419
19420
19421
19422
19423
19424
19425
19426
19427
19428
19429
19430
19431
19432
19433
19434
19435
19436
19437
19438
19439
19440
19441
19442
19443
19444
19445
19446
19447
19448
19449
19450
19451
19452
19453
19454
19455
19456
19457
19458
19459
19460
19461
19462
19463
19464
19465
19466
19467
19468
19469
19470
19471
19472
19473
19474
19475
19476
19477
19478
19479
19480
19481
19482
19483
19484
19485
19486
19487
19488
19489
19490
19491
19492
19493
19494
19495
19496
19497
19498
19499
19500
19501
19502
19503
19504
19505
19506
19507
19508
19509
19510
19511
19512
19513
19514
19515
19516
19517
19518
19519
19520
19521
19522
19523
19524
19525
19526
19527
19528
19529
19530
19531
19532
19533
19534
19535
19536
19537
19538
19539
19540
19541
19542
19543
19544
19545
19546
19547
19548
19549
19550
19551
19552
19553
19554
19555
19556
19557
19558
19559
19560
19561
19562
19563
19564
19565
19566
19567
19568
19569
19570
19571
19572
19573
19574
19575
19576
19577
19578
19579
19580
19581
19582
19583
19584
19585
19586
19587
19588
19589
19590
19591
19592
19593
19594
19595
19596
19597
19598
19599
19600
19601
19602
19603
19604
19605
19606
19607
19608
19609
19610
19611
19612
19613
19614
19615
19616
19617
19618
19619
19620
19621
19622
19623
19624
19625
19626
19627
19628
19629
19630
19631
19632
19633
19634
19635
19636
19637
19638
19639
19640
19641
19642
19643
19644
19645
19646
19647
19648
19649
19650
19651
19652
19653
19654
19655
19656
19657
19658
19659
19660
19661
19662
19663
19664
19665
19666
19667
19668
19669
19670
19671
19672
19673
19674
19675
19676
19677
19678
19679
19680
19681
19682
19683
19684
19685
19686
19687
19688
19689
19690
19691
19692
19693
19694
19695
19696
19697
19698
19699
19700
19701
19702
19703
19704
19705
19706
19707
19708
19709
19710
19711
19712
19713
19714
19715
19716
19717
19718
19719
19720
19721
19722
19723
19724
19725
19726
19727
19728
19729
19730
19731
19732
19733
19734
19735
19736
19737
19738
19739
19740
19741
19742
19743
19744
19745
19746
19747
19748
19749
19750
19751
19752
19753
19754
19755
19756
19757
19758
19759
19760
19761
19762
19763
19764
19765
19766
19767
19768
19769
19770
19771
19772
19773
19774
19775
19776
19777
19778
19779
19780
19781
19782
19783
19784
19785
19786
19787
19788
19789
19790
19791
19792
19793
19794
19795
19796
19797
19798
19799
19800
19801
19802
19803
19804
19805
19806
19807
19808
19809
19810
19811
19812
19813
19814
19815
19816
19817
19818
19819
19820
19821
19822
19823
19824
19825
19826
19827
19828
19829
19830
19831
19832
19833
19834
19835
19836
19837
19838
19839
19840
19841
19842
19843
19844
19845
19846
19847
19848
19849
19850
19851
19852
19853
19854
19855
19856
19857
19858
19859
19860
19861
19862
19863
19864
19865
19866
19867
19868
19869
19870
19871
19872
19873
19874
19875
19876
19877
19878
19879
19880
19881
19882
19883
19884
19885
19886
19887
19888
19889
19890
19891
19892
19893
19894
19895
19896
19897
19898
19899
19900
19901
19902
19903
19904
19905
19906
19907
19908
19909
19910
19911
19912
19913
19914
19915
19916
19917
19918
19919
19920
19921
19922
19923
19924
19925
19926
19927
19928
19929
19930
19931
19932
19933
19934
19935
19936
19937
19938
19939
19940
19941
19942
19943
19944
19945
19946
19947
19948
19949
19950
19951
19952
19953
19954
19955
19956
19957
19958
19959
19960
19961
19962
19963
19964
19965
19966
19967
19968
19969
19970
19971
19972
19973
19974
19975
19976
19977
19978
19979
19980
19981
19982
19983
19984
19985
19986
19987
19988
19989
19990
19991
19992
19993
19994
19995
19996
19997
19998
19999
20000
20001
20002
20003
20004
20005
20006
20007
20008
20009
20010
20011
20012
20013
20014
20015
20016
20017
20018
20019
20020
20021
20022
20023
20024
20025
20026
20027
20028
20029
20030
20031
20032
20033
20034
20035
20036
20037
20038
20039
20040
20041
20042
20043
20044
20045
20046
20047
20048
20049
20050
20051
20052
20053
20054
20055
20056
20057
20058
20059
20060
20061
20062
20063
20064
20065
20066
20067
20068
20069
20070
20071
20072
20073
20074
20075
20076
20077
20078
20079
20080
20081
20082
20083
20084
20085
20086
20087
20088
20089
20090
20091
20092
20093
20094
20095
20096
20097
20098
20099
20100
20101
20102
20103
20104
20105
20106
20107
20108
20109
20110
20111
20112
20113
20114
20115
20116
20117
20118
20119
20120
20121
20122
20123
20124
20125
20126
20127
20128
20129
20130
20131
20132
20133
20134
20135
20136
20137
20138
20139
20140
20141
20142
20143
20144
20145
20146
20147
20148
20149
20150
20151
20152
20153
20154
20155
20156
20157
20158
20159
20160
20161
20162
20163
20164
20165
20166
20167
20168
20169
20170
20171
20172
20173
20174
20175
20176
20177
20178
20179
20180
20181
20182
20183
20184
20185
20186
20187
20188
20189
20190
20191
20192
20193
20194
20195
20196
20197
20198
20199
20200
20201
20202
20203
20204
20205
20206
20207
20208
20209
20210
20211
20212
20213
20214
20215
20216
20217
20218
20219
20220
20221
20222
20223
20224
20225
20226
20227
20228
20229
20230
20231
20232
20233
20234
20235
20236
20237
20238
20239
20240
20241
20242
20243
20244
20245
20246
20247
20248
20249
20250
20251
20252
20253
20254
20255
20256
20257
20258
20259
20260
20261
20262
20263
20264
20265
20266
20267
20268
20269
20270
20271
20272
20273
20274
20275
20276
20277
20278
20279
20280
20281
20282
20283
20284
20285
20286
20287
20288
20289
20290
20291
20292
20293
20294
20295
20296
20297
20298
20299
20300
20301
20302
20303
20304
20305
20306
20307
20308
20309
20310
20311
20312
20313
20314
20315
20316
20317
20318
20319
20320
20321
20322
20323
20324
20325
20326
20327
20328
20329
20330
20331
20332
20333
20334
20335
20336
20337
20338
20339
20340
20341
20342
20343
20344
20345
20346
20347
20348
20349
20350
20351
20352
20353
20354
20355
20356
20357
20358
20359
20360
20361
20362
20363
20364
20365
20366
20367
20368
20369
20370
20371
20372
20373
20374
20375
20376
20377
20378
20379
20380
20381
20382
20383
20384
20385
20386
20387
20388
20389
20390
20391
20392
20393
20394
20395
20396
20397
20398
20399
20400
20401
20402
20403
20404
20405
20406
20407
20408
20409
20410
20411
20412
20413
20414
20415
20416
20417
20418
20419
20420
20421
20422
20423
20424
20425
20426
20427
20428
20429
20430
20431
20432
20433
20434
20435
20436
20437
20438
20439
20440
20441
20442
20443
20444
20445
20446
20447
20448
20449
20450
20451
20452
20453
20454
20455
20456
20457
20458
20459
20460
20461
20462
20463
20464
20465
20466
20467
20468
20469
20470
20471
20472
20473
20474
20475
20476
20477
20478
20479
20480
20481
20482
20483
20484
20485
20486
20487
20488
20489
20490
20491
20492
20493
20494
20495
20496
20497
20498
20499
20500
20501
20502
20503
20504
20505
20506
20507
20508
20509
20510
20511
20512
20513
20514
20515
20516
20517
20518
20519
20520
20521
20522
20523
20524
20525
20526
20527
20528
20529
20530
20531
20532
20533
20534
20535
20536
20537
20538
20539
20540
20541
20542
20543
20544
20545
20546
20547
20548
20549
20550
20551
20552
20553
20554
20555
20556
20557
20558
20559
20560
20561
20562
20563
20564
20565
20566
20567
20568
20569
20570
20571
20572
20573
20574
20575
20576
20577
20578
20579
20580
20581
20582
20583
20584
20585
20586
20587
20588
20589
20590
20591
20592
20593
20594
20595
20596
20597
20598
20599
20600
20601
20602
20603
20604
20605
20606
20607
20608
20609
20610
20611
20612
20613
20614
20615
20616
20617
20618
20619
20620
20621
20622
20623
20624
20625
20626
20627
20628
20629
20630
20631
20632
20633
20634
20635
20636
20637
20638
20639
20640
20641
20642
20643
20644
20645
20646
20647
20648
20649
20650
20651
20652
20653
20654
20655
20656
20657
20658
20659
20660
20661
20662
20663
20664
20665
20666
20667
20668
20669
20670
20671
20672
20673
20674
20675
20676
20677
20678
20679
20680
20681
20682
20683
20684
20685
20686
20687
20688
20689
20690
20691
20692
20693
20694
20695
20696
20697
20698
20699
20700
20701
20702
20703
20704
20705
20706
20707
20708
20709
20710
20711
20712
20713
20714
20715
20716
20717
20718
20719
20720
20721
20722
20723
20724
20725
20726
20727
20728
20729
20730
20731
20732
20733
20734
20735
20736
20737
20738
20739
20740
20741
20742
20743
20744
20745
20746
20747
20748
20749
20750
20751
20752
20753
20754
20755
20756
20757
20758
20759
20760
20761
20762
20763
20764
20765
20766
20767
20768
20769
20770
20771
20772
20773
20774
20775
20776
20777
20778
20779
20780
20781
20782
20783
20784
20785
20786
20787
20788
20789
20790
20791
20792
20793
20794
20795
20796
20797
20798
20799
20800
20801
20802
20803
20804
20805
20806
20807
20808
20809
20810
20811
20812
20813
20814
20815
20816
20817
20818
20819
20820
20821
20822
20823
20824
20825
20826
20827
20828
20829
20830
20831
20832
20833
20834
20835
20836
20837
20838
20839
20840
20841
20842
20843
20844
20845
20846
20847
20848
20849
20850
20851
20852
20853
20854
20855
20856
20857
20858
20859
20860
20861
20862
20863
20864
20865
20866
20867
20868
20869
20870
20871
20872
20873
20874
20875
20876
20877
20878
20879
20880
20881
20882
20883
20884
20885
20886
20887
20888
20889
20890
20891
20892
20893
20894
20895
20896
20897
20898
20899
20900
20901
20902
20903
20904
20905
20906
20907
20908
20909
20910
20911
20912
20913
20914
20915
20916
20917
20918
20919
20920
20921
20922
20923
20924
20925
20926
20927
20928
20929
20930
20931
20932
20933
20934
20935
20936
20937
20938
20939
20940
20941
20942
20943
20944
20945
20946
20947
20948
20949
20950
20951
20952
20953
20954
20955
20956
20957
20958
20959
20960
20961
20962
20963
20964
20965
20966
20967
20968
20969
20970
20971
20972
20973
20974
20975
20976
20977
20978
20979
20980
20981
20982
20983
20984
20985
20986
20987
20988
20989
20990
20991
20992
20993
20994
20995
20996
20997
20998
20999
21000
21001
21002
21003
21004
21005
21006
21007
21008
21009
21010
21011
21012
21013
21014
21015
21016
21017
21018
21019
21020
21021
21022
21023
21024
21025
21026
21027
21028
21029
21030
21031
21032
21033
21034
21035
21036
21037
21038
21039
21040
21041
21042
21043
21044
21045
21046
21047
21048
21049
21050
21051
21052
21053
21054
21055
21056
21057
21058
21059
21060
21061
21062
21063
21064
21065
21066
21067
21068
21069
21070
21071
21072
21073
21074
21075
21076
21077
21078
21079
21080
21081
21082
21083
21084
21085
21086
21087
21088
21089
21090
21091
21092
21093
21094
21095
21096
21097
21098
21099
21100
21101
21102
21103
21104
21105
21106
21107
21108
21109
21110
21111
21112
21113
21114
21115
21116
21117
21118
21119
21120
21121
21122
21123
21124
21125
21126
21127
21128
21129
21130
21131
21132
21133
21134
21135
21136
21137
21138
21139
21140
21141
21142
21143
21144
21145
21146
21147
21148
21149
21150
21151
21152
21153
21154
21155
21156
21157
21158
21159
21160
21161
21162
21163
21164
21165
21166
21167
21168
21169
21170
21171
21172
21173
21174
21175
21176
21177
21178
21179
21180
21181
21182
21183
21184
21185
21186
21187
21188
21189
21190
21191
21192
21193
21194
21195
21196
21197
21198
21199
21200
21201
21202
21203
21204
21205
21206
21207
21208
21209
21210
21211
21212
21213
21214
21215
21216
21217
21218
21219
21220
21221
21222
21223
21224
21225
21226
21227
21228
21229
21230
21231
21232
21233
21234
21235
21236
21237
21238
21239
21240
21241
21242
21243
21244
21245
21246
21247
21248
21249
21250
21251
21252
21253
21254
21255
21256
21257
21258
21259
21260
21261
21262
21263
21264
21265
21266
21267
21268
21269
21270
21271
21272
21273
21274
21275
21276
21277
21278
21279
21280
21281
21282
21283
21284
21285
21286
21287
21288
21289
21290
21291
21292
21293
21294
21295
21296
21297
21298
21299
21300
21301
21302
21303
21304
21305
21306
21307
21308
21309
21310
21311
21312
21313
21314
21315
21316
21317
21318
21319
21320
21321
21322
21323
21324
21325
21326
21327
21328
21329
21330
21331
21332
21333
21334
21335
21336
21337
21338
21339
21340
21341
21342
21343
21344
21345
21346
21347
21348
21349
21350
21351
21352
21353
21354
21355
21356
21357
21358
21359
21360
21361
21362
21363
21364
21365
21366
21367
21368
21369
21370
21371
21372
21373
21374
21375
21376
21377
21378
21379
21380
21381
21382
21383
21384
21385
21386
21387
21388
21389
21390
21391
21392
21393
21394
21395
21396
21397
21398
21399
21400
21401
21402
21403
21404
21405
21406
21407
21408
21409
21410
21411
21412
21413
21414
21415
21416
21417
21418
21419
21420
21421
21422
21423
21424
21425
21426
21427
21428
21429
21430
21431
21432
21433
21434
21435
21436
21437
21438
21439
21440
21441
21442
21443
21444
21445
21446
21447
21448
21449
21450
21451
21452
21453
21454
21455
21456
21457
21458
21459
21460
21461
21462
21463
21464
21465
21466
21467
21468
21469
21470
21471
21472
21473
21474
21475
21476
21477
21478
21479
21480
21481
21482
21483
21484
21485
21486
21487
21488
21489
21490
21491
21492
21493
21494
21495
21496
21497
21498
21499
21500
21501
21502
21503
21504
21505
21506
21507
21508
21509
21510
21511
21512
21513
21514
21515
21516
21517
21518
21519
21520
21521
21522
21523
21524
21525
21526
21527
21528
21529
21530
21531
21532
21533
21534
21535
21536
21537
21538
21539
21540
21541
21542
21543
21544
21545
21546
21547
21548
21549
21550
21551
21552
21553
21554
21555
21556
21557
21558
21559
21560
21561
21562
21563
21564
21565
21566
21567
21568
21569
21570
21571
21572
21573
21574
21575
21576
21577
21578
21579
21580
21581
21582
21583
21584
21585
21586
21587
21588
21589
21590
21591
21592
21593
21594
21595
21596
21597
21598
21599
21600
21601
21602
21603
21604
21605
21606
21607
21608
21609
21610
21611
21612
21613
21614
21615
21616
21617
21618
21619
21620
21621
21622
21623
21624
21625
21626
21627
21628
21629
21630
21631
21632
21633
21634
21635
21636
21637
21638
21639
21640
21641
21642
21643
21644
21645
21646
21647
21648
21649
21650
21651
21652
21653
21654
21655
21656
21657
21658
21659
21660
21661
21662
21663
21664
21665
21666
21667
21668
21669
21670
21671
21672
21673
21674
21675
21676
21677
21678
21679
21680
21681
21682
21683
21684
21685
21686
21687
21688
21689
21690
21691
21692
21693
21694
21695
21696
21697
21698
21699
21700
21701
21702
21703
21704
21705
21706
21707
21708
21709
21710
21711
21712
21713
21714
21715
21716
21717
21718
21719
21720
21721
21722
21723
21724
21725
21726
21727
21728
21729
21730
21731
21732
21733
21734
21735
21736
21737
21738
21739
21740
21741
21742
21743
21744
21745
21746
21747
21748
21749
21750
21751
21752
21753
21754
21755
21756
21757
21758
21759
21760
21761
21762
21763
21764
21765
21766
21767
21768
21769
21770
21771
21772
21773
21774
21775
21776
21777
21778
21779
21780
21781
21782
21783
21784
21785
21786
21787
21788
21789
21790
21791
21792
21793
21794
21795
21796
21797
21798
21799
21800
21801
21802
21803
21804
21805
21806
21807
21808
21809
21810
21811
21812
21813
21814
21815
21816
21817
21818
21819
21820
21821
21822
21823
21824
21825
21826
21827
21828
21829
21830
21831
21832
21833
21834
21835
21836
21837
21838
21839
21840
21841
21842
21843
21844
21845
21846
21847
21848
21849
21850
21851
21852
21853
21854
21855
21856
21857
21858
21859
21860
21861
21862
21863
21864
21865
21866
21867
21868
21869
21870
21871
21872
21873
21874
21875
21876
21877
21878
21879
21880
21881
21882
21883
21884
21885
21886
21887
21888
21889
21890
21891
21892
21893
21894
21895
21896
21897
21898
21899
21900
21901
21902
21903
21904
21905
21906
21907
21908
21909
21910
21911
21912
21913
21914
21915
21916
21917
21918
21919
21920
21921
21922
21923
21924
21925
21926
21927
21928
21929
21930
21931
21932
21933
21934
21935
21936
21937
21938
21939
21940
21941
21942
21943
21944
21945
21946
21947
21948
21949
21950
21951
21952
21953
21954
21955
21956
21957
21958
21959
21960
21961
21962
21963
21964
21965
21966
21967
21968
21969
21970
21971
21972
21973
21974
21975
21976
21977
21978
21979
21980
21981
21982
21983
21984
21985
21986
21987
21988
21989
21990
21991
21992
21993
21994
21995
21996
21997
21998
21999
22000
22001
22002
22003
22004
22005
22006
22007
22008
22009
22010
22011
22012
22013
22014
22015
22016
22017
22018
22019
22020
22021
22022
22023
22024
22025
22026
22027
22028
22029
22030
22031
22032
22033
22034
22035
22036
22037
22038
22039
22040
22041
22042
22043
22044
22045
22046
22047
22048
22049
22050
22051
22052
22053
22054
22055
22056
22057
22058
22059
22060
22061
22062
22063
22064
22065
22066
22067
22068
22069
22070
22071
22072
22073
22074
22075
22076
22077
22078
22079
22080
22081
22082
22083
22084
22085
22086
22087
22088
22089
22090
22091
22092
22093
22094
22095
22096
22097
22098
22099
22100
22101
22102
22103
22104
22105
22106
22107
22108
22109
22110
22111
22112
22113
22114
22115
22116
22117
22118
22119
22120
22121
22122
22123
22124
22125
22126
22127
22128
22129
22130
22131
22132
22133
22134
22135
22136
22137
22138
22139
22140
22141
22142
22143
22144
22145
22146
22147
22148
22149
22150
22151
22152
22153
22154
22155
22156
22157
22158
22159
22160
22161
22162
22163
22164
22165
22166
22167
22168
22169
22170
22171
22172
22173
22174
22175
22176
22177
22178
22179
22180
22181
22182
22183
22184
22185
22186
22187
22188
22189
22190
22191
22192
22193
22194
22195
22196
22197
22198
22199
22200
22201
22202
22203
22204
22205
22206
22207
22208
22209
22210
22211
22212
22213
22214
22215
22216
22217
22218
22219
22220
22221
22222
22223
22224
22225
22226
22227
22228
22229
22230
22231
22232
22233
22234
22235
22236
22237
22238
22239
22240
22241
22242
22243
22244
22245
22246
22247
22248
22249
22250
22251
22252
22253
22254
22255
22256
22257
22258
22259
22260
22261
22262
22263
22264
22265
22266
22267
22268
22269
22270
22271
22272
22273
22274
22275
22276
22277
22278
22279
22280
22281
22282
22283
22284
22285
22286
22287
22288
22289
22290
22291
22292
22293
22294
22295
22296
22297
22298
22299
22300
22301
22302
22303
22304
22305
22306
22307
22308
22309
22310
22311
22312
22313
22314
22315
22316
22317
22318
22319
22320
22321
22322
22323
22324
22325
22326
22327
22328
22329
22330
22331
22332
22333
22334
22335
22336
22337
22338
22339
22340
22341
22342
22343
22344
22345
22346
22347
22348
22349
22350
22351
22352
22353
22354
22355
22356
22357
22358
22359
22360
22361
22362
22363
22364
22365
22366
22367
22368
22369
22370
22371
22372
22373
22374
22375
22376
22377
22378
22379
22380
22381
22382
22383
22384
22385
22386
22387
22388
22389
22390
22391
22392
22393
22394
22395
22396
22397
22398
22399
22400
22401
22402
22403
22404
22405
22406
22407
22408
22409
22410
22411
22412
22413
22414
22415
22416
22417
22418
22419
22420
22421
22422
22423
22424
22425
22426
22427
22428
22429
22430
22431
22432
22433
22434
22435
22436
22437
22438
22439
22440
22441
22442
22443
22444
22445
22446
22447
22448
22449
22450
22451
22452
22453
22454
22455
22456
22457
22458
22459
22460
22461
22462
22463
22464
22465
22466
22467
22468
22469
22470
22471
22472
22473
22474
22475
22476
22477
22478
22479
22480
22481
22482
22483
22484
22485
22486
22487
22488
22489
22490
22491
22492
22493
22494
22495
22496
22497
22498
22499
22500
22501
22502
22503
22504
22505
22506
22507
22508
22509
22510
22511
22512
22513
22514
22515
22516
22517
22518
22519
22520
22521
22522
22523
22524
22525
22526
22527
22528
22529
22530
22531
22532
22533
22534
22535
22536
22537
22538
22539
22540
22541
22542
22543
22544
22545
22546
22547
22548
22549
22550
22551
22552
22553
22554
22555
22556
22557
22558
22559
22560
22561
22562
22563
22564
22565
22566
22567
22568
22569
22570
22571
22572
22573
22574
22575
22576
22577
22578
22579
22580
22581
22582
22583
22584
22585
22586
22587
22588
22589
22590
22591
22592
22593
22594
22595
22596
22597
22598
22599
22600
22601
22602
22603
22604
22605
22606
22607
22608
22609
22610
22611
22612
22613
22614
22615
22616
22617
22618
22619
22620
22621
22622
22623
22624
22625
22626
22627
22628
22629
22630
22631
22632
22633
22634
22635
22636
22637
22638
22639
22640
22641
22642
22643
22644
22645
22646
22647
22648
22649
22650
22651
22652
22653
22654
22655
22656
22657
22658
22659
22660
22661
22662
22663
22664
22665
22666
22667
22668
22669
22670
22671
22672
22673
22674
22675
22676
22677
22678
22679
22680
22681
22682
22683
22684
22685
22686
22687
22688
22689
22690
22691
22692
22693
22694
22695
22696
22697
22698
22699
22700
22701
22702
22703
22704
22705
22706
22707
22708
22709
22710
22711
22712
22713
22714
22715
22716
22717
22718
22719
22720
22721
22722
22723
22724
22725
22726
22727
22728
22729
22730
22731
22732
22733
22734
22735
22736
22737
22738
22739
22740
22741
22742
22743
22744
22745
22746
22747
22748
22749
22750
22751
22752
22753
22754
22755
22756
22757
22758
22759
22760
22761
22762
22763
22764
22765
22766
22767
22768
22769
22770
22771
22772
22773
22774
22775
22776
22777
22778
22779
22780
22781
22782
22783
22784
22785
22786
22787
22788
22789
22790
22791
22792
22793
22794
22795
22796
22797
22798
22799
22800
22801
22802
22803
22804
22805
22806
22807
22808
22809
22810
22811
22812
22813
22814
22815
22816
22817
22818
22819
22820
22821
22822
22823
22824
22825
22826
22827
22828
22829
22830
22831
22832
22833
22834
22835
22836
22837
22838
22839
22840
22841
22842
22843
22844
22845
22846
22847
22848
22849
22850
22851
22852
22853
22854
22855
22856
22857
22858
22859
22860
22861
22862
22863
22864
22865
22866
22867
22868
22869
22870
22871
22872
22873
22874
22875
22876
22877
22878
22879
22880
22881
22882
22883
22884
22885
22886
22887
22888
22889
22890
22891
22892
22893
22894
22895
22896
22897
22898
22899
22900
22901
22902
22903
22904
22905
22906
22907
22908
22909
22910
22911
22912
22913
22914
22915
22916
22917
22918
22919
22920
22921
22922
22923
22924
22925
22926
22927
22928
22929
22930
22931
22932
22933
22934
22935
22936
22937
22938
22939
22940
22941
22942
22943
22944
22945
22946
22947
22948
22949
22950
22951
22952
22953
22954
22955
22956
22957
22958
22959
22960
22961
22962
22963
22964
22965
22966
22967
22968
22969
22970
22971
22972
22973
22974
22975
22976
22977
22978
22979
22980
22981
22982
22983
22984
22985
22986
22987
22988
22989
22990
22991
22992
22993
22994
22995
22996
22997
22998
22999
23000
23001
23002
23003
23004
23005
23006
23007
23008
23009
23010
23011
23012
23013
23014
23015
23016
23017
23018
23019
23020
23021
23022
23023
23024
23025
23026
23027
23028
23029
23030
23031
23032
23033
23034
23035
23036
23037
23038
23039
23040
23041
23042
23043
23044
23045
23046
23047
23048
23049
23050
23051
23052
23053
23054
23055
23056
23057
23058
23059
23060
23061
23062
23063
23064
23065
23066
23067
23068
23069
23070
23071
23072
23073
23074
23075
23076
23077
23078
23079
23080
23081
23082
23083
23084
23085
23086
23087
23088
23089
23090
23091
23092
23093
23094
23095
23096
23097
23098
23099
23100
23101
23102
23103
23104
23105
23106
23107
23108
23109
23110
23111
23112
23113
23114
23115
23116
23117
23118
23119
23120
23121
23122
23123
23124
23125
23126
23127
23128
23129
23130
23131
23132
23133
23134
23135
23136
23137
23138
23139
23140
23141
23142
23143
23144
23145
23146
23147
23148
23149
23150
23151
23152
23153
23154
23155
23156
23157
23158
23159
23160
23161
23162
23163
23164
23165
23166
23167
23168
23169
23170
23171
23172
23173
23174
23175
23176
23177
23178
23179
23180
23181
23182
23183
23184
23185
23186
23187
23188
23189
23190
23191
23192
23193
23194
23195
23196
23197
23198
23199
23200
23201
23202
23203
23204
23205
23206
23207
23208
23209
23210
23211
23212
23213
23214
23215
23216
23217
23218
23219
23220
23221
23222
23223
23224
23225
23226
23227
23228
23229
23230
23231
23232
23233
23234
23235
23236
23237
23238
23239
23240
23241
23242
23243
23244
23245
23246
23247
23248
23249
23250
23251
23252
23253
23254
23255
23256
23257
23258
23259
23260
23261
23262
23263
23264
23265
23266
23267
23268
23269
23270
23271
23272
23273
23274
23275
23276
23277
23278
23279
23280
23281
23282
23283
23284
23285
23286
23287
23288
23289
23290
23291
23292
23293
23294
23295
23296
23297
23298
23299
23300
23301
23302
23303
23304
23305
23306
23307
23308
23309
23310
23311
23312
23313
23314
23315
23316
23317
23318
23319
23320
23321
23322
23323
23324
23325
23326
23327
23328
23329
23330
23331
23332
23333
23334
23335
23336
23337
23338
23339
23340
23341
23342
23343
23344
23345
23346
23347
23348
23349
23350
23351
23352
23353
23354
23355
23356
23357
23358
23359
23360
23361
23362
23363
23364
23365
23366
23367
23368
23369
23370
23371
23372
23373
23374
23375
23376
23377
23378
23379
23380
23381
23382
23383
23384
23385
23386
23387
23388
23389
23390
23391
23392
23393
23394
23395
23396
23397
23398
23399
23400
23401
23402
23403
23404
23405
23406
23407
23408
23409
23410
23411
23412
23413
23414
23415
23416
23417
23418
23419
23420
23421
23422
23423
23424
23425
23426
23427
23428
23429
23430
23431
23432
23433
23434
23435
23436
23437
23438
23439
23440
23441
23442
23443
23444
23445
23446
23447
23448
23449
23450
23451
23452
23453
23454
23455
23456
23457
23458
23459
23460
23461
23462
23463
23464
23465
23466
23467
23468
23469
23470
23471
23472
23473
23474
23475
23476
23477
23478
23479
23480
23481
23482
23483
23484
23485
23486
23487
23488
23489
23490
23491
23492
23493
23494
23495
23496
23497
23498
23499
23500
23501
23502
23503
23504
23505
23506
23507
23508
23509
23510
23511
23512
23513
23514
23515
23516
23517
23518
23519
23520
23521
23522
23523
23524
23525
23526
23527
23528
23529
23530
23531
23532
23533
23534
23535
23536
23537
23538
23539
23540
23541
23542
23543
23544
23545
23546
23547
23548
23549
23550
23551
23552
23553
23554
23555
23556
23557
23558
23559
23560
23561
23562
23563
23564
23565
23566
23567
23568
23569
23570
23571
23572
23573
23574
23575
23576
23577
23578
23579
23580
23581
23582
23583
23584
23585
23586
23587
23588
23589
23590
23591
23592
23593
23594
23595
23596
23597
23598
23599
23600
23601
23602
23603
23604
23605
23606
23607
23608
23609
23610
23611
23612
23613
23614
23615
23616
23617
23618
23619
23620
23621
23622
23623
23624
23625
23626
23627
23628
23629
23630
23631
23632
23633
23634
23635
23636
23637
23638
23639
23640
23641
23642
23643
23644
23645
23646
23647
23648
23649
23650
23651
23652
23653
23654
23655
23656
23657
23658
23659
23660
23661
23662
23663
23664
23665
23666
23667
23668
23669
23670
23671
23672
23673
23674
23675
23676
23677
23678
23679
23680
23681
23682
23683
23684
23685
23686
23687
23688
23689
23690
23691
23692
23693
23694
23695
23696
23697
23698
23699
23700
23701
23702
23703
23704
23705
23706
23707
23708
23709
23710
23711
23712
23713
23714
23715
23716
23717
23718
23719
23720
23721
23722
23723
23724
23725
23726
23727
23728
23729
23730
23731
23732
23733
23734
23735
23736
23737
23738
23739
23740
23741
23742
23743
23744
23745
23746
23747
23748
23749
23750
23751
23752
23753
23754
23755
23756
23757
23758
23759
23760
23761
23762
23763
23764
23765
23766
23767
23768
23769
23770
23771
23772
23773
23774
23775
23776
23777
23778
23779
23780
23781
23782
23783
23784
23785
23786
23787
23788
23789
23790
23791
23792
23793
23794
23795
23796
23797
23798
23799
23800
23801
23802
23803
23804
23805
23806
23807
23808
23809
23810
23811
23812
23813
23814
23815
23816
23817
23818
23819
23820
23821
23822
23823
23824
23825
23826
23827
23828
23829
23830
23831
23832
23833
23834
23835
23836
23837
23838
23839
23840
23841
23842
23843
23844
23845
23846
23847
23848
23849
23850
23851
23852
23853
23854
23855
23856
23857
23858
23859
23860
23861
23862
23863
23864
23865
23866
23867
23868
23869
23870
23871
23872
23873
23874
23875
23876
23877
23878
23879
23880
23881
23882
23883
23884
23885
23886
23887
23888
23889
23890
23891
23892
23893
23894
23895
23896
23897
23898
23899
23900
23901
23902
23903
23904
23905
23906
23907
23908
23909
23910
23911
23912
23913
23914
23915
23916
23917
23918
23919
23920
23921
23922
23923
23924
23925
23926
23927
23928
23929
23930
23931
23932
23933
23934
23935
23936
23937
23938
23939
23940
23941
23942
23943
23944
23945
23946
23947
23948
23949
23950
23951
23952
23953
23954
23955
23956
23957
23958
23959
23960
23961
23962
23963
23964
23965
23966
23967
23968
23969
23970
23971
23972
23973
23974
23975
23976
23977
23978
23979
23980
23981
23982
23983
23984
23985
23986
23987
23988
23989
23990
23991
23992
23993
23994
23995
23996
23997
23998
23999
24000
24001
24002
24003
24004
24005
24006
24007
24008
24009
24010
24011
24012
24013
24014
24015
24016
24017
24018
24019
24020
24021
24022
24023
24024
24025
24026
24027
24028
24029
24030
24031
24032
24033
24034
24035
24036
24037
24038
24039
24040
24041
24042
24043
24044
24045
24046
24047
24048
24049
24050
24051
24052
24053
24054
24055
24056
24057
24058
24059
24060
24061
24062
24063
24064
24065
24066
24067
24068
24069
24070
24071
24072
24073
24074
24075
24076
24077
24078
24079
24080
24081
24082
24083
24084
24085
24086
24087
24088
24089
24090
24091
24092
24093
24094
24095
24096
24097
24098
24099
24100
24101
24102
24103
24104
24105
24106
24107
24108
24109
24110
24111
24112
24113
24114
24115
24116
24117
24118
24119
24120
24121
24122
24123
24124
24125
24126
24127
24128
24129
24130
24131
24132
24133
24134
24135
24136
24137
24138
24139
24140
24141
24142
24143
24144
24145
24146
24147
24148
24149
24150
24151
24152
24153
24154
24155
24156
24157
24158
24159
24160
24161
24162
24163
24164
24165
24166
24167
24168
24169
24170
24171
24172
24173
24174
24175
24176
24177
24178
24179
24180
24181
24182
24183
24184
24185
24186
24187
24188
24189
24190
24191
24192
24193
24194
24195
24196
24197
24198
24199
24200
24201
24202
24203
24204
24205
24206
24207
24208
24209
24210
24211
24212
24213
24214
24215
24216
24217
24218
24219
24220
24221
24222
24223
24224
24225
24226
24227
24228
24229
24230
24231
24232
24233
24234
24235
24236
24237
24238
24239
24240
24241
24242
24243
24244
24245
24246
24247
24248
24249
24250
24251
24252
24253
24254
24255
24256
24257
24258
24259
24260
24261
24262
24263
24264
24265
24266
24267
24268
24269
24270
24271
24272
24273
24274
24275
24276
24277
24278
24279
24280
24281
24282
24283
24284
24285
24286
24287
24288
24289
24290
24291
24292
24293
24294
24295
24296
24297
24298
24299
24300
24301
24302
24303
24304
24305
24306
24307
24308
24309
24310
24311
24312
24313
24314
24315
24316
24317
24318
24319
24320
24321
24322
24323
24324
24325
24326
24327
24328
24329
24330
24331
24332
24333
24334
24335
24336
24337
24338
24339
24340
24341
24342
24343
24344
24345
24346
24347
24348
24349
24350
24351
24352
24353
24354
24355
24356
24357
24358
24359
24360
24361
24362
24363
24364
24365
24366
24367
24368
24369
24370
24371
24372
24373
24374
24375
24376
24377
24378
24379
24380
24381
24382
24383
24384
24385
24386
24387
24388
24389
24390
24391
24392
24393
24394
24395
24396
24397
24398
24399
24400
24401
24402
24403
24404
24405
24406
24407
24408
24409
24410
24411
24412
24413
24414
24415
24416
24417
24418
24419
24420
24421
24422
24423
24424
24425
24426
24427
24428
24429
24430
24431
24432
24433
24434
24435
24436
24437
24438
24439
24440
24441
24442
24443
24444
24445
24446
24447
24448
24449
24450
24451
24452
24453
24454
24455
24456
24457
24458
24459
24460
24461
24462
24463
24464
24465
24466
24467
24468
24469
24470
24471
24472
24473
24474
24475
24476
24477
24478
24479
24480
24481
24482
24483
24484
24485
24486
24487
24488
24489
24490
24491
24492
24493
24494
24495
24496
24497
24498
24499
24500
24501
24502
24503
24504
24505
24506
24507
24508
24509
24510
24511
24512
24513
24514
24515
24516
24517
24518
24519
24520
24521
24522
24523
24524
24525
24526
24527
24528
24529
24530
24531
24532
24533
24534
24535
24536
24537
24538
24539
24540
24541
24542
24543
24544
24545
24546
24547
24548
24549
24550
24551
24552
24553
24554
24555
24556
24557
24558
24559
24560
24561
24562
24563
24564
24565
24566
24567
24568
24569
24570
24571
24572
24573
24574
24575
24576
24577
24578
24579
24580
24581
24582
24583
24584
24585
24586
24587
24588
24589
24590
24591
24592
24593
24594
24595
24596
24597
24598
24599
24600
24601
24602
24603
24604
24605
24606
24607
24608
24609
24610
24611
24612
24613
24614
24615
24616
24617
24618
24619
24620
24621
24622
24623
24624
24625
24626
24627
24628
24629
24630
24631
24632
24633
24634
24635
24636
24637
24638
24639
24640
24641
24642
24643
24644
24645
24646
24647
24648
24649
24650
24651
24652
24653
24654
24655
24656
24657
24658
24659
24660
24661
24662
24663
24664
24665
24666
24667
24668
24669
24670
24671
24672
24673
24674
24675
24676
24677
24678
24679
24680
24681
24682
24683
24684
24685
24686
24687
24688
24689
24690
24691
24692
24693
24694
24695
24696
24697
24698
24699
24700
24701
24702
24703
24704
24705
24706
24707
24708
24709
24710
24711
24712
24713
24714
24715
24716
24717
24718
24719
24720
24721
24722
24723
24724
24725
24726
24727
24728
24729
24730
24731
24732
24733
24734
24735
24736
24737
24738
24739
24740
24741
24742
24743
24744
24745
24746
24747
24748
24749
24750
24751
24752
24753
24754
24755
24756
24757
24758
24759
24760
24761
24762
24763
24764
24765
24766
24767
24768
24769
24770
24771
24772
24773
24774
24775
24776
24777
24778
24779
24780
24781
24782
24783
24784
24785
24786
24787
24788
24789
24790
24791
24792
24793
24794
24795
24796
24797
24798
24799
24800
24801
24802
24803
24804
24805
24806
24807
24808
24809
24810
24811
24812
24813
24814
24815
24816
24817
24818
24819
24820
24821
24822
24823
24824
24825
24826
24827
24828
24829
24830
24831
24832
24833
24834
24835
24836
24837
24838
24839
24840
24841
24842
24843
24844
24845
24846
24847
24848
24849
24850
24851
24852
24853
24854
24855
24856
24857
24858
24859
24860
24861
24862
24863
24864
24865
24866
24867
24868
24869
24870
24871
24872
24873
24874
24875
24876
24877
24878
24879
24880
24881
24882
24883
24884
24885
24886
24887
24888
24889
24890
24891
24892
24893
24894
24895
24896
24897
24898
24899
24900
24901
24902
24903
24904
24905
24906
24907
24908
24909
24910
24911
24912
24913
24914
24915
24916
24917
24918
24919
24920
24921
24922
24923
24924
24925
24926
24927
24928
24929
24930
24931
24932
24933
24934
24935
24936
24937
24938
24939
24940
24941
24942
24943
24944
24945
24946
24947
24948
24949
24950
24951
24952
24953
24954
24955
24956
24957
24958
24959
24960
24961
24962
24963
24964
24965
24966
24967
24968
24969
24970
24971
24972
24973
24974
24975
24976
24977
24978
24979
24980
24981
24982
24983
24984
24985
24986
24987
24988
24989
24990
24991
24992
24993
24994
24995
24996
24997
24998
24999
25000
25001
25002
25003
25004
25005
25006
25007
25008
25009
25010
25011
25012
25013
25014
25015
25016
25017
25018
25019
25020
25021
25022
25023
25024
25025
25026
25027
25028
25029
25030
25031
25032
25033
25034
25035
25036
25037
25038
25039
25040
25041
25042
25043
25044
25045
25046
25047
25048
25049
25050
25051
25052
25053
25054
25055
25056
25057
25058
25059
25060
25061
25062
25063
25064
25065
25066
25067
25068
25069
25070
25071
25072
25073
25074
25075
25076
25077
25078
25079
25080
25081
25082
25083
25084
25085
25086
25087
25088
25089
25090
25091
25092
25093
25094
25095
25096
25097
25098
25099
25100
25101
25102
25103
25104
25105
25106
25107
25108
25109
25110
25111
25112
25113
25114
25115
25116
25117
25118
25119
25120
25121
25122
25123
25124
25125
25126
25127
25128
25129
25130
25131
25132
25133
25134
25135
25136
25137
25138
25139
25140
25141
25142
25143
25144
25145
25146
25147
25148
25149
25150
25151
25152
25153
25154
25155
25156
25157
25158
25159
25160
25161
25162
25163
25164
25165
25166
25167
25168
25169
25170
25171
25172
25173
25174
25175
25176
25177
25178
25179
25180
25181
25182
25183
25184
25185
25186
25187
25188
25189
25190
25191
25192
25193
25194
25195
25196
25197
25198
25199
25200
25201
25202
25203
25204
25205
25206
25207
25208
25209
25210
25211
25212
25213
25214
25215
25216
25217
25218
25219
25220
25221
25222
25223
25224
25225
25226
25227
25228
25229
25230
25231
25232
25233
25234
25235
25236
25237
25238
25239
25240
25241
25242
25243
25244
25245
25246
25247
25248
25249
25250
25251
25252
25253
25254
25255
25256
25257
25258
25259
25260
25261
25262
25263
25264
25265
25266
25267
25268
25269
25270
25271
25272
25273
25274
25275
25276
25277
25278
25279
25280
25281
25282
25283
25284
25285
25286
25287
25288
25289
25290
25291
25292
25293
25294
25295
25296
25297
25298
25299
25300
25301
25302
25303
25304
25305
25306
25307
25308
25309
25310
25311
25312
25313
25314
25315
25316
25317
25318
25319
25320
25321
25322
25323
25324
25325
25326
25327
25328
25329
25330
25331
25332
25333
25334
25335
25336
25337
25338
25339
25340
25341
25342
25343
25344
25345
25346
25347
25348
25349
25350
25351
25352
25353
25354
25355
25356
25357
25358
25359
25360
25361
25362
25363
25364
25365
25366
25367
25368
25369
25370
25371
25372
25373
25374
25375
25376
25377
25378
25379
25380
25381
25382
25383
25384
25385
25386
25387
25388
25389
25390
25391
25392
25393
25394
25395
25396
25397
25398
25399
25400
25401
25402
25403
25404
25405
25406
25407
25408
25409
25410
25411
25412
25413
25414
25415
25416
25417
25418
25419
25420
25421
25422
25423
25424
25425
25426
25427
25428
25429
25430
25431
25432
25433
25434
25435
25436
25437
25438
25439
25440
25441
25442
25443
25444
25445
25446
25447
25448
25449
25450
25451
25452
25453
25454
25455
25456
25457
25458
25459
25460
25461
25462
25463
25464
25465
25466
25467
25468
25469
25470
25471
25472
25473
25474
25475
25476
25477
25478
25479
25480
25481
25482
25483
25484
25485
25486
25487
25488
25489
25490
25491
25492
25493
25494
25495
25496
25497
25498
25499
25500
25501
25502
25503
25504
25505
25506
25507
25508
25509
25510
25511
25512
25513
25514
25515
25516
25517
25518
25519
25520
25521
25522
25523
25524
25525
25526
25527
25528
25529
25530
25531
25532
25533
25534
25535
25536
25537
25538
25539
25540
25541
25542
25543
25544
25545
25546
25547
25548
25549
25550
25551
25552
25553
25554
25555
25556
25557
25558
25559
25560
25561
25562
25563
25564
25565
25566
25567
25568
25569
25570
25571
25572
25573
25574
25575
25576
25577
25578
25579
25580
25581
25582
25583
25584
25585
25586
25587
25588
25589
25590
25591
25592
25593
25594
25595
25596
25597
25598
25599
25600
25601
25602
25603
25604
25605
25606
25607
25608
25609
25610
25611
25612
25613
25614
25615
25616
25617
25618
25619
25620
25621
25622
25623
25624
25625
25626
25627
25628
25629
25630
25631
25632
25633
25634
25635
25636
25637
25638
25639
25640
25641
25642
25643
25644
25645
25646
25647
25648
25649
25650
25651
25652
25653
25654
25655
25656
25657
25658
25659
25660
25661
25662
25663
25664
25665
25666
25667
25668
25669
25670
25671
25672
25673
25674
25675
25676
25677
25678
25679
25680
25681
25682
25683
25684
25685
25686
25687
25688
25689
25690
25691
25692
25693
25694
25695
25696
25697
25698
25699
25700
25701
25702
25703
25704
25705
25706
25707
25708
25709
25710
25711
25712
25713
25714
25715
25716
25717
25718
25719
25720
25721
25722
25723
25724
25725
25726
25727
25728
25729
25730
25731
25732
25733
25734
25735
25736
25737
25738
25739
25740
25741
25742
25743
25744
25745
25746
25747
25748
25749
25750
25751
25752
25753
25754
25755
25756
25757
25758
25759
25760
25761
25762
25763
25764
25765
25766
25767
25768
25769
25770
25771
25772
25773
25774
25775
25776
25777
25778
25779
25780
25781
25782
25783
25784
25785
25786
25787
25788
25789
25790
25791
25792
25793
25794
25795
25796
25797
25798
25799
25800
25801
25802
25803
25804
25805
25806
25807
25808
25809
25810
25811
25812
25813
25814
25815
25816
25817
25818
25819
25820
25821
25822
25823
25824
25825
25826
25827
25828
25829
25830
25831
25832
25833
25834
25835
25836
25837
25838
25839
25840
25841
25842
25843
25844
25845
25846
25847
25848
25849
25850
25851
25852
25853
25854
25855
25856
25857
25858
25859
25860
25861
25862
25863
25864
25865
25866
25867
25868
25869
25870
25871
25872
25873
25874
25875
25876
25877
25878
25879
25880
25881
25882
25883
25884
25885
25886
25887
25888
25889
25890
25891
25892
25893
25894
25895
25896
25897
25898
25899
25900
25901
25902
25903
25904
25905
25906
25907
25908
25909
25910
25911
25912
25913
25914
25915
25916
25917
25918
25919
25920
25921
25922
25923
25924
25925
25926
25927
25928
25929
25930
25931
25932
25933
25934
25935
25936
25937
25938
25939
25940
25941
25942
25943
25944
25945
25946
25947
25948
25949
25950
25951
25952
25953
25954
25955
25956
25957
25958
25959
25960
25961
25962
25963
25964
25965
25966
25967
25968
25969
25970
25971
25972
25973
25974
25975
25976
25977
25978
25979
25980
25981
25982
25983
25984
25985
25986
25987
25988
25989
25990
25991
25992
25993
25994
25995
25996
25997
25998
25999
26000
26001
26002
26003
26004
26005
26006
26007
26008
26009
26010
26011
26012
26013
26014
26015
26016
26017
26018
26019
26020
26021
26022
26023
26024
26025
26026
26027
26028
26029
26030
26031
26032
26033
26034
26035
26036
26037
26038
26039
26040
26041
26042
26043
26044
26045
26046
26047
26048
26049
26050
26051
26052
26053
26054
26055
26056
26057
26058
26059
26060
26061
26062
26063
26064
26065
26066
26067
26068
26069
26070
26071
26072
26073
26074
26075
26076
26077
26078
26079
26080
26081
26082
26083
26084
26085
26086
26087
26088
26089
26090
26091
26092
26093
26094
26095
26096
26097
26098
26099
26100
26101
26102
26103
26104
26105
26106
26107
26108
26109
26110
26111
26112
26113
26114
26115
26116
26117
26118
26119
26120
26121
26122
26123
26124
26125
26126
26127
26128
26129
26130
26131
26132
26133
26134
26135
26136
26137
26138
26139
26140
26141
26142
26143
26144
26145
26146
26147
26148
26149
26150
26151
26152
26153
26154
26155
26156
26157
26158
26159
26160
26161
26162
26163
26164
26165
26166
26167
26168
26169
26170
26171
26172
26173
26174
26175
26176
26177
26178
26179
26180
26181
26182
26183
26184
26185
26186
26187
26188
26189
26190
26191
26192
26193
26194
26195
26196
26197
26198
26199
26200
26201
26202
26203
26204
26205
26206
26207
26208
26209
26210
26211
26212
26213
26214
26215
26216
26217
26218
26219
26220
26221
26222
26223
26224
26225
26226
26227
26228
26229
26230
26231
26232
26233
26234
26235
26236
26237
26238
26239
26240
26241
26242
26243
26244
26245
26246
26247
26248
26249
26250
26251
26252
26253
26254
26255
26256
26257
26258
26259
26260
26261
26262
26263
26264
26265
26266
26267
26268
26269
26270
26271
26272
26273
26274
26275
26276
26277
26278
26279
26280
26281
26282
26283
26284
26285
26286
26287
26288
26289
26290
26291
26292
26293
26294
26295
26296
26297
26298
26299
26300
26301
26302
26303
26304
26305
26306
26307
26308
26309
26310
26311
26312
26313
26314
26315
26316
26317
26318
26319
26320
26321
26322
26323
26324
26325
26326
26327
26328
26329
26330
26331
26332
26333
26334
26335
26336
26337
26338
26339
26340
26341
26342
26343
26344
26345
26346
26347
26348
26349
26350
26351
26352
26353
26354
26355
26356
26357
26358
26359
26360
26361
26362
26363
26364
26365
26366
26367
26368
26369
26370
26371
26372
26373
26374
26375
26376
26377
26378
26379
26380
26381
26382
26383
26384
26385
26386
26387
26388
26389
26390
26391
26392
26393
26394
26395
26396
26397
26398
26399
26400
26401
26402
26403
26404
26405
26406
26407
26408
26409
26410
26411
26412
26413
26414
26415
26416
26417
26418
26419
26420
26421
26422
26423
26424
26425
26426
26427
26428
26429
26430
26431
26432
26433
26434
26435
26436
26437
26438
26439
26440
26441
26442
26443
26444
26445
26446
26447
26448
26449
26450
26451
26452
26453
26454
26455
26456
26457
26458
26459
26460
26461
26462
26463
26464
26465
26466
26467
26468
26469
26470
26471
26472
26473
26474
26475
26476
26477
26478
26479
26480
26481
26482
26483
26484
26485
26486
26487
26488
26489
26490
26491
26492
26493
26494
26495
26496
26497
26498
26499
26500
26501
26502
26503
26504
26505
26506
26507
26508
26509
26510
26511
26512
26513
26514
26515
26516
26517
26518
26519
26520
26521
26522
26523
26524
26525
26526
26527
26528
26529
26530
26531
26532
26533
26534
26535
26536
26537
26538
26539
26540
26541
26542
26543
26544
26545
26546
26547
26548
26549
26550
26551
26552
26553
26554
26555
26556
26557
26558
26559
26560
26561
26562
26563
26564
26565
26566
26567
26568
26569
26570
26571
26572
26573
26574
26575
26576
26577
26578
26579
26580
26581
26582
26583
26584
26585
26586
26587
26588
26589
26590
26591
26592
26593
26594
26595
26596
26597
26598
26599
26600
26601
26602
26603
26604
26605
26606
26607
26608
26609
26610
26611
26612
26613
26614
26615
26616
26617
26618
26619
26620
26621
26622
26623
26624
26625
26626
26627
26628
26629
26630
26631
26632
26633
26634
26635
26636
26637
26638
26639
26640
26641
26642
26643
26644
26645
26646
26647
26648
26649
26650
26651
26652
26653
26654
26655
26656
26657
26658
26659
26660
26661
26662
26663
26664
26665
26666
26667
26668
26669
26670
26671
26672
26673
26674
26675
26676
26677
26678
26679
26680
26681
26682
26683
26684
26685
26686
26687
26688
26689
26690
26691
26692
26693
26694
26695
26696
26697
26698
26699
26700
26701
26702
26703
26704
26705
26706
26707
26708
26709
26710
26711
26712
26713
26714
26715
26716
26717
26718
26719
26720
26721
26722
26723
26724
26725
26726
26727
26728
26729
26730
26731
26732
26733
26734
26735
26736
26737
26738
26739
26740
26741
26742
26743
26744
26745
26746
26747
26748
26749
26750
26751
26752
26753
26754
26755
26756
26757
26758
26759
26760
26761
26762
26763
26764
26765
26766
26767
26768
26769
26770
26771
26772
26773
26774
26775
26776
26777
26778
26779
26780
26781
26782
26783
26784
26785
26786
26787
26788
26789
26790
26791
26792
26793
26794
26795
26796
26797
26798
26799
26800
26801
26802
26803
26804
26805
26806
26807
26808
26809
26810
26811
26812
26813
26814
26815
26816
26817
26818
26819
26820
26821
26822
26823
26824
26825
26826
26827
26828
26829
26830
26831
26832
26833
26834
26835
26836
26837
26838
26839
26840
26841
26842
26843
26844
26845
26846
26847
26848
26849
26850
26851
26852
26853
26854
26855
26856
26857
26858
26859
26860
26861
26862
26863
26864
26865
26866
26867
26868
26869
26870
26871
26872
26873
26874
26875
26876
26877
26878
26879
26880
26881
26882
26883
26884
26885
26886
26887
26888
26889
26890
26891
26892
26893
26894
26895
26896
26897
26898
26899
26900
26901
26902
26903
26904
26905
26906
26907
26908
26909
26910
26911
26912
26913
26914
26915
26916
26917
26918
26919
26920
26921
26922
26923
26924
26925
26926
26927
26928
26929
26930
26931
26932
26933
26934
26935
26936
26937
26938
26939
26940
26941
26942
26943
26944
26945
26946
26947
26948
26949
26950
26951
26952
26953
26954
26955
26956
26957
26958
26959
26960
26961
26962
26963
26964
26965
26966
26967
26968
26969
26970
26971
26972
26973
26974
26975
26976
26977
26978
26979
26980
26981
26982
26983
26984
26985
26986
26987
26988
26989
26990
26991
26992
26993
26994
26995
26996
26997
26998
26999
27000
27001
27002
27003
27004
27005
27006
27007
27008
27009
27010
27011
27012
27013
27014
27015
27016
27017
27018
27019
27020
27021
27022
27023
27024
27025
27026
27027
27028
27029
27030
27031
27032
27033
27034
27035
27036
27037
27038
27039
27040
27041
27042
27043
27044
27045
27046
27047
27048
27049
27050
27051
27052
27053
27054
27055
27056
27057
27058
27059
27060
27061
27062
27063
27064
27065
27066
27067
27068
27069
27070
27071
27072
27073
27074
27075
27076
27077
27078
27079
27080
27081
27082
27083
27084
27085
27086
27087
27088
27089
27090
27091
27092
27093
27094
27095
27096
27097
27098
27099
27100
27101
27102
27103
27104
27105
27106
27107
27108
27109
27110
27111
27112
27113
27114
27115
27116
27117
27118
27119
27120
27121
27122
27123
27124
27125
27126
27127
27128
27129
27130
27131
27132
27133
27134
27135
27136
27137
27138
27139
27140
27141
27142
27143
27144
27145
27146
27147
27148
27149
27150
27151
27152
27153
27154
27155
27156
27157
27158
27159
27160
27161
27162
27163
27164
27165
27166
27167
27168
27169
27170
27171
27172
27173
27174
27175
27176
27177
27178
27179
27180
27181
27182
27183
27184
27185
27186
27187
27188
27189
27190
27191
27192
27193
27194
27195
27196
27197
27198
27199
27200
27201
27202
27203
27204
27205
27206
27207
27208
27209
27210
27211
27212
27213
27214
27215
27216
27217
27218
27219
27220
27221
27222
27223
27224
27225
27226
27227
27228
27229
27230
27231
27232
27233
27234
27235
27236
27237
27238
27239
27240
27241
27242
27243
27244
27245
27246
27247
27248
27249
27250
27251
27252
27253
27254
27255
27256
27257
27258
27259
27260
27261
27262
27263
27264
27265
27266
27267
27268
27269
27270
27271
27272
27273
27274
27275
27276
27277
27278
27279
27280
27281
27282
27283
27284
27285
27286
27287
27288
27289
27290
27291
27292
27293
27294
27295
27296
27297
27298
27299
27300
27301
27302
27303
27304
27305
27306
27307
27308
27309
27310
27311
27312
27313
27314
27315
27316
27317
27318
27319
27320
27321
27322
27323
27324
27325
27326
27327
27328
27329
27330
27331
27332
27333
27334
27335
27336
27337
27338
27339
27340
27341
27342
27343
27344
27345
27346
27347
27348
27349
27350
27351
27352
27353
27354
27355
27356
27357
27358
27359
27360
27361
27362
27363
27364
27365
27366
27367
27368
27369
27370
27371
27372
27373
27374
27375
27376
27377
27378
27379
27380
27381
27382
27383
27384
27385
27386
27387
27388
27389
27390
27391
27392
27393
27394
27395
27396
27397
27398
27399
27400
27401
27402
27403
27404
27405
27406
27407
27408
27409
27410
27411
27412
27413
27414
27415
27416
27417
27418
27419
27420
27421
27422
27423
27424
27425
27426
27427
27428
27429
27430
27431
27432
27433
27434
27435
27436
27437
27438
27439
27440
27441
27442
27443
27444
27445
27446
27447
27448
27449
27450
27451
27452
27453
27454
27455
27456
27457
27458
27459
27460
27461
27462
27463
27464
27465
27466
27467
27468
27469
27470
27471
27472
27473
27474
27475
27476
27477
27478
27479
27480
27481
27482
27483
27484
27485
27486
27487
27488
27489
27490
27491
27492
27493
27494
27495
27496
27497
27498
27499
27500
27501
27502
27503
27504
27505
27506
27507
27508
27509
27510
27511
27512
27513
27514
27515
27516
27517
27518
27519
27520
27521
27522
27523
27524
27525
27526
27527
27528
27529
27530
27531
27532
27533
27534
27535
27536
27537
27538
27539
27540
27541
27542
27543
27544
27545
27546
27547
27548
27549
27550
27551
27552
27553
27554
27555
27556
27557
27558
27559
27560
27561
27562
27563
27564
27565
27566
27567
27568
27569
27570
27571
27572
27573
27574
27575
27576
27577
27578
27579
27580
27581
27582
27583
27584
27585
27586
27587
27588
27589
27590
27591
27592
27593
27594
27595
27596
27597
27598
27599
27600
27601
27602
27603
27604
27605
27606
27607
27608
27609
27610
27611
27612
27613
27614
27615
27616
27617
27618
27619
27620
27621
27622
27623
27624
27625
27626
27627
27628
27629
27630
27631
27632
27633
27634
27635
27636
27637
27638
27639
27640
27641
27642
27643
27644
27645
27646
27647
27648
27649
27650
27651
27652
27653
27654
27655
27656
27657
27658
27659
27660
27661
27662
27663
27664
27665
27666
27667
27668
27669
27670
27671
27672
27673
27674
27675
27676
27677
27678
27679
27680
27681
27682
27683
27684
27685
27686
27687
27688
27689
27690
27691
27692
27693
27694
27695
27696
27697
27698
27699
27700
27701
27702
27703
27704
27705
27706
27707
27708
27709
27710
27711
27712
27713
27714
27715
27716
27717
27718
27719
27720
27721
27722
27723
27724
27725
27726
27727
27728
27729
27730
27731
27732
27733
27734
27735
27736
27737
27738
27739
27740
27741
27742
27743
27744
27745
27746
27747
27748
27749
27750
27751
27752
27753
27754
27755
27756
27757
27758
27759
27760
27761
27762
27763
27764
27765
27766
27767
27768
27769
27770
27771
27772
27773
27774
27775
27776
27777
27778
27779
27780
27781
27782
27783
27784
27785
27786
27787
27788
27789
27790
27791
27792
27793
27794
27795
27796
27797
27798
27799
27800
27801
27802
27803
27804
27805
27806
27807
27808
27809
27810
27811
27812
27813
27814
27815
27816
27817
27818
27819
27820
27821
27822
27823
27824
27825
27826
27827
27828
27829
27830
27831
27832
27833
27834
27835
27836
27837
27838
27839
27840
27841
27842
27843
27844
27845
27846
27847
27848
27849
27850
27851
27852
27853
27854
27855
27856
27857
27858
27859
27860
27861
27862
27863
27864
27865
27866
27867
27868
27869
27870
27871
27872
27873
27874
27875
27876
27877
27878
27879
27880
27881
27882
27883
27884
27885
27886
27887
27888
27889
27890
27891
27892
27893
27894
27895
27896
27897
27898
27899
27900
27901
27902
27903
27904
27905
27906
27907
27908
27909
27910
27911
27912
27913
27914
27915
27916
27917
27918
27919
27920
27921
27922
27923
27924
27925
27926
27927
27928
27929
27930
27931
27932
27933
27934
27935
27936
27937
27938
27939
27940
27941
27942
27943
27944
27945
27946
27947
27948
27949
27950
27951
27952
27953
27954
27955
27956
27957
27958
27959
27960
27961
27962
27963
27964
27965
27966
27967
27968
27969
27970
27971
27972
27973
27974
27975
27976
27977
27978
27979
27980
27981
27982
27983
27984
27985
27986
27987
27988
27989
27990
27991
27992
27993
27994
27995
27996
27997
27998
27999
28000
28001
28002
28003
28004
28005
28006
28007
28008
28009
28010
28011
28012
28013
28014
28015
28016
28017
28018
28019
28020
28021
28022
28023
28024
28025
28026
28027
28028
28029
28030
28031
28032
28033
28034
28035
28036
28037
28038
28039
28040
28041
28042
28043
28044
28045
28046
28047
28048
28049
28050
28051
28052
28053
28054
28055
28056
28057
28058
28059
28060
28061
28062
28063
28064
28065
28066
28067
28068
28069
28070
28071
28072
28073
28074
28075
28076
28077
28078
28079
28080
28081
28082
28083
28084
28085
28086
28087
28088
28089
28090
28091
28092
28093
28094
28095
28096
28097
28098
28099
28100
28101
28102
28103
28104
28105
28106
28107
28108
28109
28110
28111
28112
28113
28114
28115
28116
28117
28118
28119
28120
28121
28122
28123
28124
28125
28126
28127
28128
28129
28130
28131
28132
28133
28134
28135
28136
28137
28138
28139
28140
28141
28142
28143
28144
28145
28146
28147
28148
28149
28150
28151
28152
28153
28154
28155
28156
28157
28158
28159
28160
28161
28162
28163
28164
28165
28166
28167
28168
28169
28170
28171
28172
28173
28174
28175
28176
28177
28178
28179
28180
28181
28182
28183
28184
28185
28186
28187
28188
28189
28190
28191
28192
28193
28194
28195
28196
28197
28198
28199
28200
28201
28202
28203
28204
28205
28206
28207
28208
28209
28210
28211
28212
28213
28214
28215
28216
28217
28218
28219
28220
28221
28222
28223
28224
28225
28226
28227
28228
28229
28230
28231
28232
28233
28234
28235
28236
28237
28238
28239
28240
28241
28242
28243
28244
28245
28246
28247
28248
28249
28250
28251
28252
28253
28254
28255
28256
28257
28258
28259
28260
28261
28262
28263
28264
28265
28266
28267
28268
28269
28270
28271
28272
28273
28274
28275
28276
28277
28278
28279
28280
28281
28282
28283
28284
28285
28286
28287
28288
28289
28290
28291
28292
28293
28294
28295
28296
28297
28298
28299
28300
28301
28302
28303
28304
28305
28306
28307
28308
28309
28310
28311
28312
28313
28314
28315
28316
28317
28318
28319
28320
28321
28322
28323
28324
28325
28326
28327
28328
28329
28330
28331
28332
28333
28334
28335
28336
28337
28338
28339
28340
28341
28342
28343
28344
28345
28346
28347
28348
28349
28350
28351
28352
28353
28354
28355
28356
28357
28358
28359
28360
28361
28362
28363
28364
28365
28366
28367
28368
28369
28370
28371
28372
28373
28374
28375
28376
28377
28378
28379
28380
28381
28382
28383
28384
28385
28386
28387
28388
28389
28390
28391
28392
28393
28394
28395
28396
28397
28398
28399
28400
28401
28402
28403
28404
28405
28406
28407
28408
28409
28410
28411
28412
28413
28414
28415
28416
28417
28418
28419
28420
28421
28422
28423
28424
28425
28426
28427
28428
28429
28430
28431
28432
28433
28434
28435
28436
28437
28438
28439
28440
28441
28442
28443
28444
28445
28446
28447
28448
28449
28450
28451
28452
28453
28454
28455
28456
28457
28458
28459
28460
28461
28462
28463
28464
28465
28466
28467
28468
28469
28470
28471
28472
28473
28474
28475
28476
28477
28478
28479
28480
28481
28482
28483
28484
28485
28486
28487
28488
28489
28490
28491
28492
28493
28494
28495
28496
28497
28498
28499
28500
28501
28502
28503
28504
28505
28506
28507
28508
28509
28510
28511
28512
28513
28514
28515
28516
28517
28518
28519
28520
28521
28522
28523
28524
28525
28526
28527
28528
28529
28530
28531
28532
28533
28534
28535
28536
28537
28538
28539
28540
28541
28542
28543
28544
28545
28546
28547
28548
28549
28550
28551
28552
28553
28554
28555
28556
28557
28558
28559
28560
28561
28562
28563
28564
28565
28566
28567
28568
28569
28570
28571
28572
28573
28574
28575
28576
28577
28578
28579
28580
28581
28582
28583
28584
28585
28586
28587
28588
28589
28590
28591
28592
28593
28594
28595
28596
28597
28598
28599
28600
28601
28602
28603
28604
28605
28606
28607
28608
28609
28610
28611
28612
28613
28614
28615
28616
28617
28618
28619
28620
28621
28622
28623
28624
28625
28626
28627
28628
28629
28630
28631
28632
28633
28634
28635
28636
28637
28638
28639
28640
28641
28642
28643
28644
28645
28646
28647
28648
28649
28650
28651
28652
28653
28654
28655
28656
28657
28658
28659
28660
28661
28662
28663
28664
28665
28666
28667
28668
28669
28670
28671
28672
28673
28674
28675
28676
28677
28678
28679
28680
28681
28682
28683
28684
28685
28686
28687
28688
28689
28690
28691
28692
28693
28694
28695
28696
28697
28698
28699
28700
28701
28702
28703
28704
28705
28706
28707
28708
28709
28710
28711
28712
28713
28714
28715
28716
28717
28718
28719
28720
28721
28722
28723
28724
28725
28726
28727
28728
28729
28730
28731
28732
28733
28734
28735
28736
28737
28738
28739
28740
28741
28742
28743
28744
28745
28746
28747
28748
28749
28750
28751
28752
28753
28754
28755
28756
28757
28758
28759
28760
28761
28762
28763
28764
28765
28766
28767
28768
28769
28770
28771
28772
28773
28774
28775
28776
28777
28778
28779
28780
28781
28782
28783
28784
28785
28786
28787
28788
28789
28790
28791
28792
28793
28794
28795
28796
28797
28798
28799
28800
28801
28802
28803
28804
28805
28806
28807
28808
28809
28810
28811
28812
28813
28814
28815
28816
28817
28818
28819
28820
28821
28822
28823
28824
28825
28826
28827
28828
28829
28830
28831
28832
28833
28834
28835
28836
28837
28838
28839
28840
28841
28842
28843
28844
28845
28846
28847
28848
28849
28850
28851
28852
28853
28854
28855
28856
28857
28858
28859
28860
28861
28862
28863
28864
28865
28866
28867
28868
28869
28870
28871
28872
28873
28874
28875
28876
28877
28878
28879
28880
28881
28882
28883
28884
28885
28886
28887
28888
28889
28890
28891
28892
28893
28894
28895
28896
28897
28898
28899
28900
28901
28902
28903
28904
28905
28906
28907
28908
28909
28910
28911
28912
28913
28914
28915
28916
28917
28918
28919
28920
28921
28922
28923
28924
28925
28926
28927
28928
28929
28930
28931
28932
28933
28934
28935
28936
28937
28938
28939
28940
28941
28942
28943
28944
28945
28946
28947
28948
28949
28950
28951
28952
28953
28954
28955
28956
28957
28958
28959
28960
28961
28962
28963
28964
28965
28966
28967
28968
28969
28970
28971
28972
28973
28974
28975
28976
28977
28978
28979
28980
28981
28982
28983
28984
28985
28986
28987
28988
28989
28990
28991
28992
28993
28994
28995
28996
28997
28998
28999
29000
29001
29002
29003
29004
29005
29006
29007
29008
29009
29010
29011
29012
29013
29014
29015
29016
29017
29018
29019
29020
29021
29022
29023
29024
29025
29026
29027
29028
29029
29030
29031
29032
29033
29034
29035
29036
29037
29038
29039
29040
29041
29042
29043
29044
29045
29046
29047
29048
29049
29050
29051
29052
29053
29054
29055
29056
29057
29058
29059
29060
29061
29062
29063
29064
29065
29066
29067
29068
29069
29070
29071
29072
29073
29074
29075
29076
29077
29078
29079
29080
29081
29082
29083
29084
29085
29086
29087
29088
29089
29090
29091
29092
29093
29094
29095
29096
29097
29098
29099
29100
29101
29102
29103
29104
29105
29106
29107
29108
29109
29110
29111
29112
29113
29114
29115
29116
29117
29118
29119
29120
29121
29122
29123
29124
29125
29126
29127
29128
29129
29130
29131
29132
29133
29134
29135
29136
29137
29138
29139
29140
29141
29142
29143
29144
29145
29146
29147
29148
29149
29150
29151
29152
29153
29154
29155
29156
29157
29158
29159
29160
29161
29162
29163
29164
29165
29166
29167
29168
29169
29170
29171
29172
29173
29174
29175
29176
29177
29178
29179
29180
29181
29182
29183
29184
29185
29186
29187
29188
29189
29190
29191
29192
29193
29194
29195
29196
29197
29198
29199
29200
29201
29202
29203
29204
29205
29206
29207
29208
29209
29210
29211
29212
29213
29214
29215
29216
29217
29218
29219
29220
29221
29222
29223
29224
29225
29226
29227
29228
29229
29230
29231
29232
29233
29234
29235
29236
29237
29238
29239
29240
29241
29242
29243
29244
29245
29246
29247
29248
29249
29250
29251
29252
29253
29254
29255
29256
29257
29258
29259
29260
29261
29262
29263
29264
29265
29266
29267
29268
29269
29270
29271
29272
29273
29274
29275
29276
29277
29278
29279
29280
29281
29282
29283
29284
29285
29286
29287
29288
29289
29290
29291
29292
29293
29294
29295
29296
29297
29298
29299
29300
29301
29302
29303
29304
29305
29306
29307
29308
29309
29310
29311
29312
29313
29314
29315
29316
29317
29318
29319
29320
29321
29322
29323
29324
29325
29326
29327
29328
29329
29330
29331
29332
29333
29334
29335
29336
29337
29338
29339
29340
29341
29342
29343
29344
29345
29346
29347
29348
29349
29350
29351
29352
29353
29354
29355
29356
29357
29358
29359
29360
29361
29362
29363
29364
29365
29366
29367
29368
29369
29370
29371
29372
29373
29374
29375
29376
29377
29378
29379
29380
29381
29382
29383
29384
29385
29386
29387
29388
29389
29390
29391
29392
29393
29394
29395
29396
29397
29398
29399
29400
29401
29402
29403
29404
29405
29406
29407
29408
29409
29410
29411
29412
29413
29414
29415
29416
29417
29418
29419
29420
29421
29422
29423
29424
29425
29426
29427
29428
29429
29430
29431
29432
29433
29434
29435
29436
29437
29438
29439
29440
29441
29442
29443
29444
29445
29446
29447
29448
29449
29450
29451
29452
29453
29454
29455
29456
29457
29458
29459
29460
29461
29462
29463
29464
29465
29466
29467
29468
29469
29470
29471
29472
29473
29474
29475
29476
29477
29478
29479
29480
29481
29482
29483
29484
29485
29486
29487
29488
29489
29490
29491
29492
29493
29494
29495
29496
29497
29498
29499
29500
29501
29502
29503
29504
29505
29506
29507
29508
29509
29510
29511
29512
29513
29514
29515
29516
29517
29518
29519
29520
29521
29522
29523
29524
29525
29526
29527
29528
29529
29530
29531
29532
29533
29534
29535
29536
29537
29538
29539
29540
29541
29542
29543
29544
29545
29546
29547
29548
29549
29550
29551
29552
29553
29554
29555
29556
29557
29558
29559
29560
29561
29562
29563
29564
29565
29566
29567
29568
29569
29570
29571
29572
29573
29574
29575
29576
29577
29578
29579
29580
29581
29582
29583
29584
29585
29586
29587
29588
29589
29590
29591
29592
29593
29594
29595
29596
29597
29598
29599
29600
29601
29602
29603
29604
29605
29606
29607
29608
29609
29610
29611
29612
29613
29614
29615
29616
29617
29618
29619
29620
29621
29622
29623
29624
29625
29626
29627
29628
29629
29630
29631
29632
29633
29634
29635
29636
29637
29638
29639
29640
29641
29642
29643
29644
29645
29646
29647
29648
29649
29650
29651
29652
29653
29654
29655
29656
29657
29658
29659
29660
29661
29662
29663
29664
29665
29666
29667
29668
29669
29670
29671
29672
29673
29674
29675
29676
29677
29678
29679
29680
29681
29682
29683
29684
29685
29686
29687
29688
29689
29690
29691
29692
29693
29694
29695
29696
29697
29698
29699
29700
29701
29702
29703
29704
29705
29706
29707
29708
29709
29710
29711
29712
29713
29714
29715
29716
29717
29718
29719
29720
29721
29722
29723
29724
29725
29726
29727
29728
29729
29730
29731
29732
29733
29734
29735
29736
29737
29738
29739
29740
29741
29742
29743
29744
29745
29746
29747
29748
29749
29750
29751
29752
29753
29754
29755
29756
29757
29758
29759
29760
29761
29762
29763
29764
29765
29766
29767
29768
29769
29770
29771
29772
29773
29774
29775
29776
29777
29778
29779
29780
29781
29782
29783
29784
29785
29786
29787
29788
29789
29790
29791
29792
29793
29794
29795
29796
29797
29798
29799
29800
29801
29802
29803
29804
29805
29806
29807
29808
29809
29810
29811
29812
29813
29814
29815
29816
29817
29818
29819
29820
29821
29822
29823
29824
29825
29826
29827
29828
29829
29830
29831
29832
29833
29834
29835
29836
29837
29838
29839
29840
29841
29842
29843
29844
29845
29846
29847
29848
29849
29850
29851
29852
29853
29854
29855
29856
29857
29858
29859
29860
29861
29862
29863
29864
29865
29866
29867
29868
29869
29870
29871
29872
29873
29874
29875
29876
29877
29878
29879
29880
29881
29882
29883
29884
29885
29886
29887
29888
29889
29890
29891
29892
29893
29894
29895
29896
29897
29898
29899
29900
29901
29902
29903
29904
29905
29906
29907
29908
29909
29910
29911
29912
29913
29914
29915
29916
29917
29918
29919
29920
29921
29922
29923
29924
29925
29926
29927
29928
29929
29930
29931
29932
29933
29934
29935
29936
29937
29938
29939
29940
29941
29942
29943
29944
29945
29946
29947
29948
29949
29950
29951
29952
29953
29954
29955
29956
29957
29958
29959
29960
29961
29962
29963
29964
29965
29966
29967
29968
29969
29970
29971
29972
29973
29974
29975
29976
29977
29978
29979
29980
29981
29982
29983
29984
29985
29986
29987
29988
29989
29990
29991
29992
29993
29994
29995
29996
29997
29998
29999
30000
30001
30002
30003
30004
30005
30006
30007
30008
30009
30010
30011
30012
30013
30014
30015
30016
30017
30018
30019
30020
30021
30022
30023
30024
30025
30026
30027
30028
30029
30030
30031
30032
30033
30034
30035
30036
30037
30038
30039
30040
30041
30042
30043
30044
30045
30046
30047
30048
30049
30050
30051
30052
30053
30054
30055
30056
30057
30058
30059
30060
30061
30062
30063
30064
30065
30066
30067
30068
30069
30070
30071
30072
30073
30074
30075
30076
30077
30078
30079
30080
30081
30082
30083
30084
30085
30086
30087
30088
30089
30090
30091
30092
30093
30094
30095
30096
30097
30098
30099
30100
30101
30102
30103
30104
30105
30106
30107
30108
30109
30110
30111
30112
30113
30114
30115
30116
30117
30118
30119
30120
30121
30122
30123
30124
30125
30126
30127
30128
30129
30130
30131
30132
30133
30134
30135
30136
30137
30138
30139
30140
30141
30142
30143
30144
30145
30146
30147
30148
30149
30150
30151
30152
30153
30154
30155
30156
30157
30158
30159
30160
30161
30162
30163
30164
30165
30166
30167
30168
30169
30170
30171
30172
30173
30174
30175
30176
30177
30178
30179
30180
30181
30182
30183
30184
30185
30186
30187
30188
30189
30190
30191
30192
30193
30194
30195
30196
30197
30198
30199
30200
30201
30202
30203
30204
30205
30206
30207
30208
30209
30210
30211
30212
30213
30214
30215
30216
30217
30218
30219
30220
30221
30222
30223
30224
30225
30226
30227
30228
30229
30230
30231
30232
30233
30234
30235
30236
30237
30238
30239
30240
30241
30242
30243
30244
30245
30246
30247
30248
30249
30250
30251
30252
30253
30254
30255
30256
30257
30258
30259
30260
30261
30262
30263
30264
30265
30266
30267
30268
30269
30270
30271
30272
30273
30274
30275
30276
30277
30278
30279
30280
30281
30282
30283
30284
30285
30286
30287
30288
30289
30290
30291
30292
30293
30294
30295
30296
30297
30298
30299
30300
30301
30302
30303
30304
30305
30306
30307
30308
30309
30310
30311
30312
30313
30314
30315
30316
30317
30318
30319
30320
30321
30322
30323
30324
30325
30326
30327
30328
30329
30330
30331
30332
30333
30334
30335
30336
30337
30338
30339
30340
30341
30342
30343
30344
30345
30346
30347
30348
30349
30350
30351
30352
30353
30354
30355
30356
30357
30358
30359
30360
30361
30362
30363
30364
30365
30366
30367
30368
30369
30370
30371
30372
30373
30374
30375
30376
30377
30378
30379
30380
30381
30382
30383
30384
30385
30386
30387
30388
30389
30390
30391
30392
30393
30394
30395
30396
30397
30398
30399
30400
30401
30402
30403
30404
30405
30406
30407
30408
30409
30410
30411
30412
30413
30414
30415
30416
30417
30418
30419
30420
30421
30422
30423
30424
30425
30426
30427
30428
30429
30430
30431
30432
30433
30434
30435
30436
30437
30438
30439
30440
30441
30442
30443
30444
30445
30446
30447
30448
30449
30450
30451
30452
30453
30454
30455
30456
30457
30458
30459
30460
30461
30462
30463
30464
30465
30466
30467
30468
30469
30470
30471
30472
30473
30474
30475
30476
30477
30478
30479
30480
30481
30482
30483
30484
30485
30486
30487
30488
30489
30490
30491
30492
30493
30494
30495
30496
30497
30498
30499
30500
30501
30502
30503
30504
30505
30506
30507
30508
30509
30510
30511
30512
30513
30514
30515
30516
30517
30518
30519
30520
30521
30522
30523
30524
30525
30526
30527
30528
30529
30530
30531
30532
30533
30534
30535
30536
30537
30538
30539
30540
30541
30542
30543
30544
30545
30546
30547
30548
30549
30550
30551
30552
30553
30554
30555
30556
30557
30558
30559
30560
30561
30562
30563
30564
30565
30566
30567
30568
30569
30570
30571
30572
30573
30574
30575
30576
30577
30578
30579
30580
30581
30582
30583
30584
30585
30586
30587
30588
30589
30590
30591
30592
30593
30594
30595
30596
30597
30598
30599
30600
30601
30602
30603
30604
30605
30606
30607
30608
30609
30610
30611
30612
30613
30614
30615
30616
30617
30618
30619
30620
30621
30622
30623
30624
30625
30626
30627
30628
30629
30630
30631
30632
30633
30634
30635
30636
30637
30638
30639
30640
30641
30642
30643
30644
30645
30646
30647
30648
30649
30650
30651
30652
30653
30654
30655
30656
30657
30658
30659
30660
30661
30662
30663
30664
30665
30666
30667
30668
30669
30670
30671
30672
30673
30674
30675
30676
30677
30678
30679
30680
30681
30682
30683
30684
30685
30686
30687
30688
30689
30690
30691
30692
30693
30694
30695
30696
30697
30698
30699
30700
30701
30702
30703
30704
30705
30706
30707
30708
30709
30710
30711
30712
30713
30714
30715
30716
30717
30718
30719
30720
30721
30722
30723
30724
30725
30726
30727
30728
30729
30730
30731
30732
30733
30734
30735
30736
30737
30738
30739
30740
30741
30742
30743
30744
30745
30746
30747
30748
30749
30750
30751
30752
30753
30754
30755
30756
30757
30758
30759
30760
30761
30762
30763
30764
30765
30766
30767
30768
30769
30770
30771
30772
30773
30774
30775
30776
30777
30778
30779
30780
30781
30782
30783
30784
30785
30786
30787
30788
30789
30790
30791
30792
30793
30794
30795
30796
30797
30798
30799
30800
30801
30802
30803
30804
30805
30806
30807
30808
30809
30810
30811
30812
30813
30814
30815
30816
30817
30818
30819
30820
30821
30822
30823
30824
30825
30826
30827
30828
30829
30830
30831
30832
30833
30834
30835
30836
30837
30838
30839
30840
30841
30842
30843
30844
30845
30846
30847
30848
30849
30850
30851
30852
30853
30854
30855
30856
30857
30858
30859
30860
30861
30862
30863
30864
30865
30866
30867
30868
30869
30870
30871
30872
30873
30874
30875
30876
30877
30878
30879
30880
30881
30882
30883
30884
30885
30886
30887
30888
30889
30890
30891
30892
30893
30894
30895
30896
30897
30898
30899
30900
30901
30902
30903
30904
30905
30906
30907
30908
30909
30910
30911
30912
30913
30914
30915
30916
30917
30918
30919
30920
30921
30922
30923
30924
30925
30926
30927
30928
30929
30930
30931
30932
30933
30934
30935
30936
30937
30938
30939
30940
30941
30942
30943
30944
30945
30946
30947
30948
30949
30950
30951
30952
30953
30954
30955
30956
30957
30958
30959
30960
30961
30962
30963
30964
30965
30966
30967
30968
30969
30970
30971
30972
30973
30974
30975
30976
30977
30978
30979
30980
30981
30982
30983
30984
30985
30986
30987
30988
30989
30990
30991
30992
30993
30994
30995
30996
30997
30998
30999
31000
31001
31002
31003
31004
31005
31006
31007
31008
31009
31010
31011
31012
31013
31014
31015
31016
31017
31018
31019
31020
31021
31022
31023
31024
31025
31026
31027
31028
31029
31030
31031
31032
31033
31034
31035
31036
31037
31038
31039
31040
31041
31042
31043
31044
31045
31046
31047
31048
31049
31050
31051
31052
31053
31054
31055
31056
31057
31058
31059
31060
31061
31062
31063
31064
31065
31066
31067
31068
31069
31070
31071
31072
31073
31074
31075
31076
31077
31078
31079
31080
31081
31082
31083
31084
31085
31086
31087
31088
31089
31090
31091
31092
31093
31094
31095
31096
31097
31098
31099
31100
31101
31102
31103
31104
31105
31106
31107
31108
31109
31110
31111
31112
31113
31114
31115
31116
31117
31118
31119
31120
31121
31122
31123
31124
31125
31126
31127
31128
31129
31130
31131
31132
31133
31134
31135
31136
31137
31138
31139
31140
31141
31142
31143
31144
31145
31146
31147
31148
31149
31150
31151
31152
31153
31154
31155
31156
31157
31158
31159
31160
31161
31162
31163
31164
31165
31166
31167
31168
31169
31170
31171
31172
31173
31174
31175
31176
31177
31178
31179
31180
31181
31182
31183
31184
31185
31186
31187
31188
31189
31190
31191
31192
31193
31194
31195
31196
31197
31198
31199
31200
31201
31202
31203
31204
31205
31206
31207
31208
31209
31210
31211
31212
31213
31214
31215
31216
31217
31218
31219
31220
31221
31222
31223
31224
31225
31226
31227
31228
31229
31230
31231
31232
31233
31234
31235
31236
31237
31238
31239
31240
31241
31242
31243
31244
31245
31246
31247
31248
31249
31250
31251
31252
31253
31254
31255
31256
31257
31258
31259
31260
31261
31262
31263
31264
31265
31266
31267
31268
31269
31270
31271
31272
31273
31274
31275
31276
31277
31278
31279
31280
31281
31282
31283
31284
31285
31286
31287
31288
31289
31290
31291
31292
31293
31294
31295
31296
31297
31298
31299
31300
31301
31302
31303
31304
31305
31306
31307
31308
31309
31310
31311
31312
31313
31314
31315
31316
31317
31318
31319
31320
31321
31322
31323
31324
31325
31326
31327
31328
31329
31330
31331
31332
31333
31334
31335
31336
31337
31338
31339
31340
31341
31342
31343
31344
31345
31346
31347
31348
31349
31350
31351
31352
31353
31354
31355
31356
31357
31358
31359
31360
31361
31362
31363
31364
31365
31366
31367
31368
31369
31370
31371
31372
31373
31374
31375
31376
31377
31378
31379
31380
31381
31382
31383
31384
31385
31386
31387
31388
31389
31390
31391
31392
31393
31394
31395
31396
31397
31398
31399
31400
31401
31402
31403
31404
31405
31406
31407
31408
31409
31410
31411
31412
31413
31414
31415
31416
31417
31418
31419
31420
31421
31422
31423
31424
31425
31426
31427
31428
31429
31430
31431
31432
31433
31434
31435
31436
31437
31438
31439
31440
31441
31442
31443
31444
31445
31446
31447
31448
31449
31450
31451
31452
31453
31454
31455
31456
31457
31458
31459
31460
31461
31462
31463
31464
31465
31466
31467
31468
31469
31470
31471
31472
31473
31474
31475
31476
31477
31478
31479
31480
31481
31482
31483
31484
31485
31486
31487
31488
31489
31490
31491
31492
31493
31494
31495
31496
31497
31498
31499
31500
31501
31502
31503
31504
31505
31506
31507
31508
31509
31510
31511
31512
31513
31514
31515
31516
31517
31518
31519
31520
31521
31522
31523
31524
31525
31526
31527
31528
31529
31530
31531
31532
31533
31534
31535
31536
31537
31538
31539
31540
31541
31542
31543
31544
31545
31546
31547
31548
31549
31550
31551
31552
31553
31554
31555
31556
31557
31558
31559
31560
31561
31562
31563
31564
31565
31566
31567
31568
31569
31570
31571
31572
31573
31574
31575
31576
31577
31578
31579
31580
31581
31582
31583
31584
31585
31586
31587
31588
31589
31590
31591
31592
31593
31594
31595
31596
31597
31598
31599
31600
31601
31602
31603
31604
31605
31606
31607
31608
31609
31610
31611
31612
31613
31614
31615
31616
31617
31618
31619
31620
31621
31622
31623
31624
31625
31626
31627
31628
31629
31630
31631
31632
31633
31634
31635
31636
31637
31638
31639
31640
31641
31642
31643
31644
31645
31646
31647
31648
31649
31650
31651
31652
31653
31654
31655
31656
31657
31658
31659
31660
31661
31662
31663
31664
31665
31666
31667
31668
31669
31670
31671
31672
31673
31674
31675
31676
31677
31678
31679
31680
31681
31682
31683
31684
31685
31686
31687
31688
31689
31690
31691
31692
31693
31694
31695
31696
31697
31698
31699
31700
31701
31702
31703
31704
31705
31706
31707
31708
31709
31710
31711
31712
31713
31714
31715
31716
31717
31718
31719
31720
31721
31722
31723
31724
31725
31726
31727
31728
31729
31730
31731
31732
31733
31734
31735
31736
31737
31738
31739
31740
31741
31742
31743
31744
31745
31746
31747
31748
31749
31750
31751
31752
31753
31754
31755
31756
31757
31758
31759
31760
31761
31762
31763
31764
31765
31766
31767
31768
31769
31770
31771
31772
31773
31774
31775
31776
31777
31778
31779
31780
31781
31782
31783
31784
31785
31786
31787
31788
31789
31790
31791
31792
31793
31794
31795
31796
31797
31798
31799
31800
31801
31802
31803
31804
31805
31806
31807
31808
31809
31810
31811
31812
31813
31814
31815
31816
31817
31818
31819
31820
31821
31822
31823
31824
31825
31826
31827
31828
31829
31830
31831
31832
31833
31834
31835
31836
31837
31838
31839
31840
31841
31842
31843
31844
31845
31846
31847
31848
31849
31850
31851
31852
31853
31854
31855
31856
31857
31858
31859
31860
31861
31862
31863
31864
31865
31866
31867
31868
31869
31870
31871
31872
31873
31874
31875
31876
31877
31878
31879
31880
31881
31882
31883
31884
31885
31886
31887
31888
31889
31890
31891
31892
31893
31894
31895
31896
31897
31898
31899
31900
31901
31902
31903
31904
31905
31906
31907
31908
31909
31910
31911
31912
31913
31914
31915
31916
31917
31918
31919
31920
31921
31922
31923
31924
31925
31926
31927
31928
31929
31930
31931
31932
31933
31934
31935
31936
31937
31938
31939
31940
31941
31942
31943
31944
31945
31946
31947
31948
31949
31950
31951
31952
31953
31954
31955
31956
31957
31958
31959
31960
31961
31962
31963
31964
31965
31966
31967
31968
31969
31970
31971
31972
31973
31974
31975
31976
31977
31978
31979
31980
31981
31982
31983
31984
31985
31986
31987
31988
31989
31990
31991
31992
31993
31994
31995
31996
31997
31998
31999
32000
32001
32002
32003
32004
32005
32006
32007
32008
32009
32010
32011
32012
32013
32014
32015
32016
32017
32018
32019
32020
32021
32022
32023
32024
32025
32026
32027
32028
32029
32030
32031
32032
32033
32034
32035
32036
32037
32038
32039
32040
32041
32042
32043
32044
32045
32046
32047
32048
32049
32050
32051
32052
32053
32054
32055
32056
32057
32058
32059
32060
32061
32062
32063
32064
32065
32066
32067
32068
32069
32070
32071
32072
32073
32074
32075
32076
32077
32078
32079
32080
32081
32082
32083
32084
32085
32086
32087
32088
32089
32090
32091
32092
32093
32094
32095
32096
32097
32098
32099
32100
32101
32102
32103
32104
32105
32106
32107
32108
32109
32110
32111
32112
32113
32114
32115
32116
32117
32118
32119
32120
32121
32122
32123
32124
32125
32126
32127
32128
32129
32130
32131
32132
32133
32134
32135
32136
32137
32138
32139
32140
32141
32142
32143
32144
32145
32146
32147
32148
32149
32150
32151
32152
32153
32154
32155
32156
32157
32158
32159
32160
32161
32162
32163
32164
32165
32166
32167
32168
32169
32170
32171
32172
32173
32174
32175
32176
32177
32178
32179
32180
32181
32182
32183
32184
32185
32186
32187
32188
32189
32190
32191
32192
32193
32194
32195
32196
32197
32198
32199
32200
32201
32202
32203
32204
32205
32206
32207
32208
32209
32210
32211
32212
32213
32214
32215
32216
32217
32218
32219
32220
32221
32222
32223
32224
32225
32226
32227
32228
32229
32230
32231
32232
32233
32234
32235
32236
32237
32238
32239
32240
32241
32242
32243
32244
32245
32246
32247
32248
32249
32250
32251
32252
32253
32254
32255
32256
32257
32258
32259
32260
32261
32262
32263
32264
32265
32266
32267
32268
32269
32270
32271
32272
32273
32274
32275
32276
32277
32278
32279
32280
32281
32282
32283
32284
32285
32286
32287
32288
32289
32290
32291
32292
32293
32294
32295
32296
32297
32298
32299
32300
32301
32302
32303
32304
32305
32306
32307
32308
32309
32310
32311
32312
32313
32314
32315
32316
32317
32318
32319
32320
32321
32322
32323
32324
32325
32326
32327
32328
32329
32330
32331
32332
32333
32334
32335
32336
32337
32338
32339
32340
32341
32342
32343
32344
32345
32346
32347
32348
32349
32350
32351
32352
32353
32354
32355
32356
32357
32358
32359
32360
32361
32362
32363
32364
32365
32366
32367
32368
32369
32370
32371
32372
32373
32374
32375
32376
32377
32378
32379
32380
32381
32382
32383
32384
32385
32386
32387
32388
32389
32390
32391
32392
32393
32394
32395
32396
32397
32398
32399
32400
32401
32402
32403
32404
32405
32406
32407
32408
32409
32410
32411
32412
32413
32414
32415
32416
32417
32418
32419
32420
32421
32422
32423
32424
32425
32426
32427
32428
32429
32430
32431
32432
32433
32434
32435
32436
32437
32438
32439
32440
32441
32442
32443
32444
32445
32446
32447
32448
32449
32450
32451
32452
32453
32454
32455
32456
32457
32458
32459
32460
32461
32462
32463
32464
32465
32466
32467
32468
32469
32470
32471
32472
32473
32474
32475
32476
32477
32478
32479
32480
32481
32482
32483
32484
32485
32486
32487
32488
32489
32490
32491
32492
32493
32494
32495
32496
32497
32498
32499
32500
32501
32502
32503
32504
32505
32506
32507
32508
32509
32510
32511
32512
32513
32514
32515
32516
32517
32518
32519
32520
32521
32522
32523
32524
32525
32526
32527
32528
32529
32530
32531
32532
32533
32534
32535
32536
32537
32538
32539
32540
32541
32542
32543
32544
32545
32546
32547
32548
32549
32550
32551
32552
32553
32554
32555
32556
32557
32558
32559
32560
32561
32562
32563
32564
32565
32566
32567
32568
32569
32570
32571
32572
32573
32574
32575
32576
32577
32578
32579
32580
32581
32582
32583
32584
32585
32586
32587
32588
32589
32590
32591
32592
32593
32594
32595
32596
32597
32598
32599
32600
32601
32602
32603
32604
32605
32606
32607
32608
32609
32610
32611
32612
32613
32614
32615
32616
32617
32618
32619
32620
32621
32622
32623
32624
32625
32626
32627
32628
32629
32630
32631
32632
32633
32634
32635
32636
32637
32638
32639
32640
32641
32642
32643
32644
32645
32646
32647
32648
32649
32650
32651
32652
32653
32654
32655
32656
32657
32658
32659
32660
32661
32662
32663
32664
32665
32666
32667
32668
32669
32670
32671
32672
32673
32674
32675
32676
32677
32678
32679
32680
32681
32682
32683
32684
32685
32686
32687
32688
32689
32690
32691
32692
32693
32694
32695
32696
32697
32698
32699
32700
32701
32702
32703
32704
32705
32706
32707
32708
32709
32710
32711
32712
32713
32714
32715
32716
32717
32718
32719
32720
32721
32722
32723
32724
32725
32726
32727
32728
32729
32730
32731
32732
32733
32734
32735
32736
32737
32738
32739
32740
32741
32742
32743
32744
32745
32746
32747
32748
32749
32750
32751
32752
32753
32754
32755
32756
32757
32758
32759
32760
32761
32762
32763
32764
32765
32766
32767
32768
32769
32770
32771
32772
32773
32774
32775
32776
32777
32778
32779
32780
32781
32782
32783
32784
32785
32786
32787
32788
32789
32790
32791
32792
32793
32794
32795
32796
32797
32798
32799
32800
32801
32802
32803
32804
32805
32806
32807
32808
32809
32810
32811
32812
32813
32814
32815
32816
32817
32818
32819
32820
32821
32822
32823
32824
32825
32826
32827
32828
32829
32830
32831
32832
32833
32834
32835
32836
32837
32838
32839
32840
32841
32842
32843
32844
32845
32846
32847
32848
32849
32850
32851
32852
32853
32854
32855
32856
32857
32858
32859
32860
32861
32862
32863
32864
32865
32866
32867
32868
32869
32870
32871
32872
32873
32874
32875
32876
32877
32878
32879
32880
32881
32882
32883
32884
32885
32886
32887
32888
32889
32890
32891
32892
32893
32894
32895
32896
32897
32898
32899
32900
32901
32902
32903
32904
32905
32906
32907
32908
32909
32910
32911
32912
32913
32914
32915
32916
32917
32918
32919
32920
32921
32922
32923
32924
32925
32926
32927
32928
32929
32930
32931
32932
32933
32934
32935
32936
32937
32938
32939
32940
32941
32942
32943
32944
32945
32946
32947
32948
32949
32950
32951
32952
32953
32954
32955
32956
32957
32958
32959
32960
32961
32962
32963
32964
32965
32966
32967
32968
32969
32970
32971
32972
32973
32974
32975
32976
32977
32978
32979
32980
32981
32982
32983
32984
32985
32986
32987
32988
32989
32990
32991
32992
32993
32994
32995
32996
32997
32998
32999
33000
33001
33002
33003
33004
33005
33006
33007
33008
33009
33010
33011
33012
33013
33014
33015
33016
33017
33018
33019
33020
33021
33022
33023
33024
33025
33026
33027
33028
33029
33030
33031
33032
33033
33034
33035
33036
33037
33038
33039
33040
33041
33042
33043
33044
33045
33046
33047
33048
33049
33050
33051
33052
33053
33054
33055
33056
33057
33058
33059
33060
33061
33062
33063
33064
33065
33066
33067
33068
33069
33070
33071
33072
33073
33074
33075
33076
33077
33078
33079
33080
33081
33082
33083
33084
33085
33086
33087
33088
33089
33090
33091
33092
33093
33094
33095
33096
33097
33098
33099
33100
33101
33102
33103
33104
33105
33106
33107
33108
33109
33110
33111
33112
33113
33114
33115
33116
33117
33118
33119
33120
33121
33122
33123
33124
33125
33126
33127
33128
33129
33130
33131
33132
33133
33134
33135
33136
33137
33138
33139
33140
33141
33142
33143
33144
33145
33146
33147
33148
33149
33150
33151
33152
33153
33154
33155
33156
33157
33158
33159
33160
33161
33162
33163
33164
33165
33166
33167
33168
33169
33170
33171
33172
33173
33174
33175
33176
33177
33178
33179
33180
33181
33182
33183
33184
33185
33186
33187
33188
33189
33190
33191
33192
33193
33194
33195
33196
33197
33198
33199
33200
33201
33202
33203
33204
33205
33206
33207
33208
33209
33210
33211
33212
33213
33214
33215
33216
33217
33218
33219
33220
33221
33222
33223
33224
33225
33226
33227
33228
33229
33230
33231
33232
33233
33234
33235
33236
33237
33238
33239
33240
33241
33242
33243
33244
33245
33246
33247
33248
33249
33250
33251
33252
33253
33254
33255
33256
33257
33258
33259
33260
33261
33262
33263
33264
33265
33266
33267
33268
33269
33270
33271
33272
33273
33274
33275
33276
33277
33278
33279
33280
33281
33282
33283
33284
33285
33286
33287
33288
33289
33290
33291
33292
33293
33294
33295
33296
33297
33298
33299
33300
33301
33302
33303
33304
33305
33306
33307
33308
33309
33310
33311
33312
33313
33314
33315
33316
33317
33318
33319
33320
33321
33322
33323
33324
33325
33326
33327
33328
33329
33330
33331
33332
33333
33334
33335
33336
33337
33338
33339
33340
33341
33342
33343
33344
33345
33346
33347
33348
33349
33350
33351
33352
33353
33354
33355
33356
33357
33358
33359
33360
33361
33362
33363
33364
33365
33366
33367
33368
33369
33370
33371
33372
33373
33374
33375
33376
33377
33378
33379
33380
33381
33382
33383
33384
33385
33386
33387
33388
33389
33390
33391
33392
33393
33394
33395
33396
33397
33398
33399
33400
33401
33402
33403
33404
33405
33406
33407
33408
33409
33410
33411
33412
33413
33414
33415
33416
33417
33418
33419
33420
33421
33422
33423
33424
33425
33426
33427
33428
33429
33430
33431
33432
33433
33434
33435
33436
33437
33438
33439
33440
33441
33442
33443
33444
33445
33446
33447
33448
33449
33450
33451
33452
33453
33454
33455
33456
33457
33458
33459
33460
33461
33462
33463
33464
33465
33466
33467
33468
33469
33470
33471
33472
33473
33474
33475
33476
33477
33478
33479
33480
33481
33482
33483
33484
33485
33486
33487
33488
33489
33490
33491
33492
33493
33494
33495
33496
33497
33498
33499
33500
33501
33502
33503
33504
33505
33506
33507
33508
33509
33510
33511
33512
33513
33514
33515
33516
33517
33518
33519
33520
33521
33522
33523
33524
33525
33526
33527
33528
33529
33530
33531
33532
33533
33534
33535
33536
33537
33538
33539
33540
33541
33542
33543
33544
33545
33546
33547
33548
33549
33550
33551
33552
33553
33554
33555
33556
33557
33558
33559
33560
33561
33562
33563
33564
33565
33566
33567
33568
33569
33570
33571
33572
33573
33574
33575
33576
33577
33578
33579
33580
33581
33582
33583
33584
33585
33586
33587
33588
33589
33590
33591
33592
33593
33594
33595
33596
33597
33598
33599
33600
33601
33602
33603
33604
33605
33606
33607
33608
33609
33610
33611
33612
33613
33614
33615
33616
33617
33618
33619
33620
33621
33622
33623
33624
33625
33626
33627
33628
33629
33630
33631
33632
33633
33634
33635
33636
33637
33638
33639
33640
33641
33642
33643
33644
33645
33646
33647
33648
33649
33650
33651
33652
33653
33654
33655
33656
33657
33658
33659
33660
33661
33662
33663
33664
33665
33666
33667
33668
33669
33670
33671
33672
33673
33674
33675
33676
33677
33678
33679
33680
33681
33682
33683
33684
33685
33686
33687
33688
33689
33690
33691
33692
33693
33694
33695
33696
33697
33698
33699
33700
33701
33702
33703
33704
33705
33706
33707
33708
33709
33710
33711
33712
33713
33714
33715
33716
33717
33718
33719
33720
33721
33722
33723
33724
33725
33726
33727
33728
33729
33730
33731
33732
33733
33734
33735
33736
33737
33738
33739
33740
33741
33742
33743
33744
33745
33746
33747
33748
33749
33750
33751
33752
33753
33754
33755
33756
33757
33758
33759
33760
33761
33762
33763
33764
33765
33766
33767
33768
33769
33770
33771
33772
33773
33774
33775
33776
33777
33778
33779
33780
33781
33782
33783
33784
33785
33786
33787
33788
33789
33790
33791
33792
33793
33794
33795
33796
33797
33798
33799
33800
33801
33802
33803
33804
33805
33806
33807
33808
33809
33810
33811
33812
33813
33814
33815
33816
33817
33818
33819
33820
33821
33822
33823
33824
33825
33826
33827
33828
33829
33830
33831
33832
33833
33834
33835
33836
33837
33838
33839
33840
33841
33842
33843
33844
33845
33846
33847
33848
33849
33850
33851
33852
33853
33854
33855
33856
33857
33858
33859
33860
33861
33862
33863
33864
33865
33866
33867
33868
33869
33870
33871
33872
33873
33874
33875
33876
33877
33878
33879
33880
33881
33882
33883
33884
33885
33886
33887
33888
33889
33890
33891
33892
33893
33894
33895
33896
33897
33898
33899
33900
33901
33902
33903
33904
33905
33906
33907
33908
33909
33910
33911
33912
33913
33914
33915
33916
33917
33918
33919
33920
33921
33922
33923
33924
33925
33926
33927
33928
33929
33930
33931
33932
33933
33934
33935
33936
33937
33938
33939
33940
33941
33942
33943
33944
33945
33946
33947
33948
33949
33950
33951
33952
33953
33954
33955
33956
33957
33958
33959
33960
33961
33962
33963
33964
33965
33966
33967
33968
33969
33970
33971
33972
33973
33974
33975
33976
33977
33978
33979
33980
33981
33982
33983
33984
33985
33986
33987
33988
33989
33990
33991
33992
33993
33994
33995
33996
33997
33998
33999
34000
34001
34002
34003
34004
34005
34006
34007
34008
34009
34010
34011
34012
34013
34014
34015
34016
34017
34018
34019
34020
34021
34022
34023
34024
34025
34026
34027
34028
34029
34030
34031
34032
34033
34034
34035
34036
34037
34038
34039
34040
34041
34042
34043
34044
34045
34046
34047
34048
34049
34050
34051
34052
34053
34054
34055
34056
34057
34058
34059
34060
34061
34062
34063
34064
34065
34066
34067
34068
34069
34070
34071
34072
34073
34074
34075
34076
34077
34078
34079
34080
34081
34082
34083
34084
34085
34086
34087
34088
34089
34090
34091
34092
34093
34094
34095
34096
34097
34098
34099
34100
34101
34102
34103
34104
34105
34106
34107
34108
34109
34110
34111
34112
34113
34114
34115
34116
34117
34118
34119
34120
34121
34122
34123
34124
34125
34126
34127
34128
34129
34130
34131
34132
34133
34134
34135
34136
34137
34138
34139
34140
34141
34142
34143
34144
34145
34146
34147
34148
34149
34150
34151
34152
34153
34154
34155
34156
34157
34158
34159
34160
34161
34162
34163
34164
34165
34166
34167
34168
34169
34170
34171
34172
34173
34174
34175
34176
34177
34178
34179
34180
34181
34182
34183
34184
34185
34186
34187
34188
34189
34190
34191
34192
34193
34194
34195
34196
34197
34198
34199
34200
34201
34202
34203
34204
34205
34206
34207
34208
34209
34210
34211
34212
34213
34214
34215
34216
34217
34218
34219
34220
34221
34222
34223
34224
34225
34226
34227
34228
34229
34230
34231
34232
34233
34234
34235
34236
34237
34238
34239
34240
34241
34242
34243
34244
34245
34246
34247
34248
34249
34250
34251
34252
34253
34254
34255
34256
34257
34258
34259
34260
34261
34262
34263
34264
34265
34266
34267
34268
34269
34270
34271
34272
34273
34274
34275
34276
34277
34278
34279
34280
34281
34282
34283
34284
34285
34286
34287
34288
34289
34290
34291
34292
34293
34294
34295
34296
34297
34298
34299
34300
34301
34302
34303
34304
34305
34306
34307
34308
34309
34310
34311
34312
34313
34314
34315
34316
34317
34318
34319
34320
34321
34322
34323
34324
34325
34326
34327
34328
34329
34330
34331
34332
34333
34334
34335
34336
34337
34338
34339
34340
34341
34342
34343
34344
34345
34346
34347
34348
34349
34350
34351
34352
34353
34354
34355
34356
34357
34358
34359
34360
34361
34362
34363
34364
34365
34366
34367
34368
34369
34370
34371
34372
34373
34374
34375
34376
34377
34378
34379
34380
34381
34382
34383
34384
34385
34386
34387
34388
34389
34390
34391
34392
34393
34394
34395
34396
34397
34398
34399
34400
34401
34402
34403
34404
34405
34406
34407
34408
34409
34410
34411
34412
34413
34414
34415
34416
34417
34418
34419
34420
34421
34422
34423
34424
34425
34426
34427
34428
34429
34430
34431
34432
34433
34434
34435
34436
34437
34438
34439
34440
34441
34442
34443
34444
34445
34446
34447
34448
34449
34450
34451
34452
34453
34454
34455
34456
34457
34458
34459
34460
34461
34462
34463
34464
34465
34466
34467
34468
34469
34470
34471
34472
34473
34474
34475
34476
34477
34478
34479
34480
34481
34482
34483
34484
34485
34486
34487
34488
34489
34490
34491
34492
34493
34494
34495
34496
34497
34498
34499
34500
34501
34502
34503
34504
34505
34506
34507
34508
34509
34510
34511
34512
34513
34514
34515
34516
34517
34518
34519
34520
34521
34522
34523
34524
34525
34526
34527
34528
34529
34530
34531
34532
34533
34534
34535
34536
34537
34538
34539
34540
34541
34542
34543
34544
34545
34546
34547
34548
34549
34550
34551
34552
34553
34554
34555
34556
34557
34558
34559
34560
34561
34562
34563
34564
34565
34566
34567
34568
34569
34570
34571
34572
34573
34574
34575
34576
34577
34578
34579
34580
34581
34582
34583
34584
34585
34586
34587
34588
34589
34590
34591
34592
34593
34594
34595
34596
34597
34598
34599
34600
34601
34602
34603
34604
34605
34606
34607
34608
34609
34610
34611
34612
34613
34614
34615
34616
34617
34618
34619
34620
34621
34622
34623
34624
34625
34626
34627
34628
34629
34630
34631
34632
34633
34634
34635
34636
34637
34638
34639
34640
34641
34642
34643
34644
34645
34646
34647
34648
34649
34650
34651
34652
34653
34654
34655
34656
34657
34658
34659
34660
34661
34662
34663
34664
34665
34666
34667
34668
34669
34670
34671
34672
34673
34674
34675
34676
34677
34678
34679
34680
34681
34682
34683
34684
34685
34686
34687
34688
34689
34690
34691
34692
34693
34694
34695
34696
34697
34698
34699
34700
34701
34702
34703
34704
34705
34706
34707
34708
34709
34710
34711
34712
34713
34714
34715
34716
34717
34718
34719
34720
34721
34722
34723
34724
34725
34726
34727
34728
34729
34730
34731
34732
34733
34734
34735
34736
34737
34738
34739
34740
34741
34742
34743
34744
34745
34746
34747
34748
34749
34750
34751
34752
34753
34754
34755
34756
34757
34758
34759
34760
34761
34762
34763
34764
34765
34766
34767
34768
34769
34770
34771
34772
34773
34774
34775
34776
34777
34778
34779
34780
34781
34782
34783
34784
34785
34786
34787
34788
34789
34790
34791
34792
34793
34794
34795
34796
34797
34798
34799
34800
34801
34802
34803
34804
34805
34806
34807
34808
34809
34810
34811
34812
34813
34814
34815
34816
34817
34818
34819
34820
34821
34822
34823
34824
34825
34826
34827
34828
34829
34830
34831
34832
34833
34834
34835
34836
34837
34838
34839
34840
34841
34842
34843
34844
34845
34846
34847
34848
34849
34850
34851
34852
34853
34854
34855
34856
34857
34858
34859
34860
34861
34862
34863
34864
34865
34866
34867
34868
34869
34870
34871
34872
34873
34874
34875
34876
34877
34878
34879
34880
34881
34882
34883
34884
34885
34886
34887
34888
34889
34890
34891
34892
34893
34894
34895
34896
34897
34898
34899
34900
34901
34902
34903
34904
34905
34906
34907
34908
34909
34910
34911
34912
34913
34914
34915
34916
34917
34918
34919
34920
34921
34922
34923
34924
34925
34926
34927
34928
34929
34930
34931
34932
34933
34934
34935
34936
34937
34938
34939
34940
34941
34942
34943
34944
34945
34946
34947
34948
34949
34950
34951
34952
34953
34954
34955
34956
34957
34958
34959
34960
34961
34962
34963
34964
34965
34966
34967
34968
34969
34970
34971
34972
34973
34974
34975
34976
34977
34978
34979
34980
34981
34982
34983
34984
34985
34986
34987
34988
34989
34990
34991
34992
34993
34994
34995
34996
34997
34998
34999
35000
35001
35002
35003
35004
35005
35006
35007
35008
35009
35010
35011
35012
35013
35014
35015
35016
35017
35018
35019
35020
35021
35022
35023
35024
35025
35026
35027
35028
35029
35030
35031
35032
35033
35034
35035
35036
35037
35038
35039
35040
35041
35042
35043
35044
35045
35046
35047
35048
35049
35050
35051
35052
35053
35054
35055
35056
35057
35058
35059
35060
35061
35062
35063
35064
35065
35066
35067
35068
35069
35070
35071
35072
35073
35074
35075
35076
35077
35078
35079
35080
35081
35082
35083
35084
35085
35086
35087
35088
35089
35090
35091
35092
35093
35094
35095
35096
35097
35098
35099
35100
35101
35102
35103
35104
35105
35106
35107
35108
35109
35110
35111
35112
35113
35114
35115
35116
35117
35118
35119
35120
35121
35122
35123
35124
35125
35126
35127
35128
35129
35130
35131
35132
35133
35134
35135
35136
35137
35138
35139
35140
35141
35142
35143
35144
35145
35146
35147
35148
35149
35150
35151
35152
35153
35154
35155
35156
35157
35158
35159
35160
35161
35162
35163
35164
35165
35166
35167
35168
35169
35170
35171
35172
35173
35174
35175
35176
35177
35178
35179
35180
35181
35182
35183
35184
35185
35186
35187
35188
35189
35190
35191
35192
35193
35194
35195
35196
35197
35198
35199
35200
35201
35202
35203
35204
35205
35206
35207
35208
35209
35210
35211
35212
35213
35214
35215
35216
35217
35218
35219
35220
35221
35222
35223
35224
35225
35226
35227
35228
35229
35230
35231
35232
35233
35234
35235
35236
35237
35238
35239
35240
35241
35242
35243
35244
35245
35246
35247
35248
35249
35250
35251
35252
35253
35254
35255
35256
35257
35258
35259
35260
35261
35262
35263
35264
35265
35266
35267
35268
35269
35270
35271
35272
35273
35274
35275
35276
35277
35278
35279
35280
35281
35282
35283
35284
35285
35286
35287
35288
35289
35290
35291
35292
35293
35294
35295
35296
35297
35298
35299
35300
35301
35302
35303
35304
35305
35306
35307
35308
35309
35310
35311
35312
35313
35314
35315
35316
35317
35318
35319
35320
35321
35322
35323
35324
35325
35326
35327
35328
35329
35330
35331
35332
35333
35334
35335
35336
35337
35338
35339
35340
35341
35342
35343
35344
35345
35346
35347
35348
35349
35350
35351
35352
35353
35354
35355
35356
35357
35358
35359
35360
35361
35362
35363
35364
35365
35366
35367
35368
35369
35370
35371
35372
35373
35374
35375
35376
35377
35378
35379
35380
35381
35382
35383
35384
35385
35386
35387
35388
35389
35390
35391
35392
35393
35394
35395
35396
35397
35398
35399
35400
35401
35402
35403
35404
35405
35406
35407
35408
35409
35410
35411
35412
35413
35414
35415
35416
35417
35418
35419
35420
35421
35422
35423
35424
35425
35426
35427
35428
35429
35430
35431
35432
35433
35434
35435
35436
35437
35438
35439
35440
35441
35442
35443
35444
35445
35446
35447
35448
35449
35450
35451
35452
35453
35454
35455
35456
35457
35458
35459
35460
35461
35462
35463
35464
35465
35466
35467
35468
35469
35470
35471
35472
35473
35474
35475
35476
35477
35478
35479
35480
35481
35482
35483
35484
35485
35486
35487
35488
35489
35490
35491
35492
35493
35494
35495
35496
35497
35498
35499
35500
35501
35502
35503
35504
35505
35506
35507
35508
35509
35510
35511
35512
35513
35514
35515
35516
35517
35518
35519
35520
35521
35522
35523
35524
35525
35526
35527
35528
35529
35530
35531
35532
35533
35534
35535
35536
35537
35538
35539
35540
35541
35542
35543
35544
35545
35546
35547
35548
35549
35550
35551
35552
35553
35554
35555
35556
35557
35558
35559
35560
35561
35562
35563
35564
35565
35566
35567
35568
35569
35570
35571
35572
35573
35574
35575
35576
35577
35578
35579
35580
35581
35582
35583
35584
35585
35586
35587
35588
35589
35590
35591
35592
35593
35594
35595
35596
35597
35598
35599
35600
35601
35602
35603
35604
35605
35606
35607
35608
35609
35610
35611
35612
35613
35614
35615
35616
35617
35618
35619
35620
35621
35622
35623
35624
35625
35626
35627
35628
35629
35630
35631
35632
35633
35634
35635
35636
35637
35638
35639
35640
35641
35642
35643
35644
35645
35646
35647
35648
35649
35650
35651
35652
35653
35654
35655
35656
35657
35658
35659
35660
35661
35662
35663
35664
35665
35666
35667
35668
35669
35670
35671
35672
35673
35674
35675
35676
35677
35678
35679
35680
35681
35682
35683
35684
35685
35686
35687
35688
35689
35690
35691
35692
35693
35694
35695
35696
35697
35698
35699
35700
35701
35702
35703
35704
35705
35706
35707
35708
35709
35710
35711
35712
35713
35714
35715
35716
35717
35718
35719
35720
35721
35722
35723
35724
35725
35726
35727
35728
35729
35730
35731
35732
35733
35734
35735
35736
35737
35738
35739
35740
35741
35742
35743
35744
35745
35746
35747
35748
35749
35750
35751
35752
35753
35754
35755
35756
35757
35758
35759
35760
35761
35762
35763
35764
35765
35766
35767
35768
35769
35770
35771
35772
35773
35774
35775
35776
35777
35778
35779
35780
35781
35782
35783
35784
35785
35786
35787
35788
35789
35790
35791
35792
35793
35794
35795
35796
35797
35798
35799
35800
35801
35802
35803
35804
35805
35806
35807
35808
35809
35810
35811
35812
35813
35814
35815
35816
35817
35818
35819
35820
35821
35822
35823
35824
35825
35826
35827
35828
35829
35830
35831
35832
35833
35834
35835
35836
35837
35838
35839
35840
35841
35842
35843
35844
35845
35846
35847
35848
35849
35850
35851
35852
35853
35854
35855
35856
35857
35858
35859
35860
35861
35862
35863
35864
35865
35866
35867
35868
35869
35870
35871
35872
35873
35874
35875
35876
35877
35878
35879
35880
35881
35882
35883
35884
35885
35886
35887
35888
35889
35890
35891
35892
35893
35894
35895
35896
35897
35898
35899
35900
35901
35902
35903
35904
35905
35906
35907
35908
35909
35910
35911
35912
35913
35914
35915
35916
35917
35918
35919
35920
35921
35922
35923
35924
35925
35926
35927
35928
35929
35930
35931
35932
35933
35934
35935
35936
35937
35938
35939
35940
35941
35942
35943
35944
35945
35946
35947
35948
35949
35950
35951
35952
35953
35954
35955
35956
35957
35958
35959
35960
35961
35962
35963
35964
35965
35966
35967
35968
35969
35970
35971
35972
35973
35974
35975
35976
35977
35978
35979
35980
35981
35982
35983
35984
35985
35986
35987
35988
35989
35990
35991
35992
35993
35994
35995
35996
35997
35998
35999
36000
36001
36002
36003
36004
36005
36006
36007
36008
36009
36010
36011
36012
36013
36014
36015
36016
36017
36018
36019
36020
36021
36022
36023
36024
36025
36026
36027
36028
36029
36030
36031
36032
36033
36034
36035
36036
36037
36038
36039
36040
36041
36042
36043
36044
36045
36046
36047
36048
36049
36050
36051
36052
36053
36054
36055
36056
36057
36058
36059
36060
36061
36062
36063
36064
36065
36066
36067
36068
36069
36070
36071
36072
36073
36074
36075
36076
36077
36078
36079
36080
36081
36082
36083
36084
36085
36086
36087
36088
36089
36090
36091
36092
36093
36094
36095
36096
36097
36098
36099
36100
36101
36102
36103
36104
36105
36106
36107
36108
36109
36110
36111
36112
36113
36114
36115
36116
36117
36118
36119
36120
36121
36122
36123
36124
36125
36126
36127
36128
36129
36130
36131
36132
36133
36134
36135
36136
36137
36138
36139
36140
36141
36142
36143
36144
36145
36146
36147
36148
36149
36150
36151
36152
36153
36154
36155
36156
36157
36158
36159
36160
36161
36162
36163
36164
36165
36166
36167
36168
36169
36170
36171
36172
36173
36174
36175
36176
36177
36178
36179
36180
36181
36182
36183
36184
36185
36186
36187
36188
36189
36190
36191
36192
36193
36194
36195
36196
36197
36198
36199
36200
36201
36202
36203
36204
36205
36206
36207
36208
36209
36210
36211
36212
36213
36214
36215
36216
36217
36218
36219
36220
36221
36222
36223
36224
36225
36226
36227
36228
36229
36230
36231
36232
36233
36234
36235
36236
36237
36238
36239
36240
36241
36242
36243
36244
36245
36246
36247
36248
36249
36250
36251
36252
36253
36254
36255
36256
36257
36258
36259
36260
36261
36262
36263
36264
36265
36266
36267
36268
36269
36270
36271
36272
36273
36274
36275
36276
36277
36278
36279
36280
36281
36282
36283
36284
36285
36286
36287
36288
36289
36290
36291
36292
36293
36294
36295
36296
36297
36298
36299
36300
36301
36302
36303
36304
36305
36306
36307
36308
36309
36310
36311
36312
36313
36314
36315
36316
36317
36318
36319
36320
36321
36322
36323
36324
36325
36326
36327
36328
36329
36330
36331
36332
36333
36334
36335
36336
36337
36338
36339
36340
36341
36342
36343
36344
36345
36346
36347
36348
36349
36350
36351
36352
36353
36354
36355
36356
36357
36358
36359
36360
36361
36362
36363
36364
36365
36366
36367
36368
36369
36370
36371
36372
36373
36374
36375
36376
36377
36378
36379
36380
36381
36382
36383
36384
36385
36386
36387
36388
36389
36390
36391
36392
36393
36394
36395
36396
36397
36398
36399
36400
36401
36402
36403
36404
36405
36406
36407
36408
36409
36410
36411
36412
36413
36414
36415
36416
36417
36418
36419
36420
36421
36422
36423
36424
36425
36426
36427
36428
36429
36430
36431
36432
36433
36434
36435
36436
36437
36438
36439
36440
36441
36442
36443
36444
36445
36446
36447
36448
36449
36450
36451
36452
36453
36454
36455
36456
36457
36458
36459
36460
36461
36462
36463
36464
36465
36466
36467
36468
36469
36470
36471
36472
36473
36474
36475
36476
36477
36478
36479
36480
36481
36482
36483
36484
36485
36486
36487
36488
36489
36490
36491
36492
36493
36494
36495
36496
36497
36498
36499
36500
36501
36502
36503
36504
36505
36506
36507
36508
36509
36510
36511
36512
36513
36514
36515
36516
36517
36518
36519
36520
36521
36522
36523
36524
36525
36526
36527
36528
36529
36530
36531
36532
36533
36534
36535
36536
36537
36538
36539
36540
36541
36542
36543
36544
36545
36546
36547
36548
36549
36550
36551
36552
36553
36554
36555
36556
36557
36558
36559
36560
36561
36562
36563
36564
36565
36566
36567
36568
36569
36570
36571
36572
36573
36574
36575
36576
36577
36578
36579
36580
36581
36582
36583
36584
36585
36586
36587
36588
36589
36590
36591
36592
36593
36594
36595
36596
36597
36598
36599
36600
36601
36602
36603
36604
36605
36606
36607
36608
36609
36610
36611
36612
36613
36614
36615
36616
36617
36618
36619
36620
36621
36622
36623
36624
36625
36626
36627
36628
36629
36630
36631
36632
36633
36634
36635
36636
36637
36638
36639
36640
36641
36642
36643
36644
36645
36646
36647
36648
36649
36650
36651
36652
36653
36654
36655
36656
36657
36658
36659
36660
36661
36662
36663
36664
36665
36666
36667
36668
36669
36670
36671
36672
36673
36674
36675
36676
36677
36678
36679
36680
36681
36682
36683
36684
36685
36686
36687
36688
36689
36690
36691
36692
36693
36694
36695
36696
36697
36698
36699
36700
36701
36702
36703
36704
36705
36706
36707
36708
36709
36710
36711
36712
36713
36714
36715
36716
36717
36718
36719
36720
36721
36722
36723
36724
36725
36726
36727
36728
36729
36730
36731
36732
36733
36734
36735
36736
36737
36738
36739
36740
36741
36742
36743
36744
36745
36746
36747
36748
36749
36750
36751
36752
36753
36754
36755
36756
36757
36758
36759
36760
36761
36762
36763
36764
36765
36766
36767
36768
36769
36770
36771
36772
36773
36774
36775
36776
36777
36778
36779
36780
36781
36782
36783
36784
36785
36786
36787
36788
36789
36790
36791
36792
36793
36794
36795
36796
36797
36798
36799
36800
36801
36802
36803
36804
36805
36806
36807
36808
36809
36810
36811
36812
36813
36814
36815
36816
36817
36818
36819
36820
36821
36822
36823
36824
36825
36826
36827
36828
36829
36830
36831
36832
36833
36834
36835
36836
36837
36838
36839
36840
36841
36842
36843
36844
36845
36846
36847
36848
36849
36850
36851
36852
36853
36854
36855
36856
36857
36858
36859
36860
36861
36862
36863
36864
36865
36866
36867
36868
36869
36870
36871
36872
36873
36874
36875
36876
36877
36878
36879
36880
36881
36882
36883
36884
36885
36886
36887
36888
36889
36890
36891
36892
36893
36894
36895
36896
36897
36898
36899
36900
36901
36902
36903
36904
36905
36906
36907
36908
36909
36910
36911
36912
36913
36914
36915
36916
36917
36918
36919
36920
36921
36922
36923
36924
36925
36926
36927
36928
36929
36930
36931
36932
36933
36934
36935
36936
36937
36938
36939
36940
36941
36942
36943
36944
36945
36946
36947
36948
36949
36950
36951
36952
36953
36954
36955
36956
36957
36958
36959
36960
36961
36962
36963
36964
36965
36966
36967
36968
36969
36970
36971
36972
36973
36974
36975
36976
36977
36978
36979
36980
36981
36982
36983
36984
36985
36986
36987
36988
36989
36990
36991
36992
36993
36994
36995
36996
36997
36998
36999
37000
37001
37002
37003
37004
37005
37006
37007
37008
37009
37010
37011
37012
37013
37014
37015
37016
37017
37018
37019
37020
37021
37022
37023
37024
37025
37026
37027
37028
37029
37030
37031
37032
37033
37034
37035
37036
37037
37038
37039
37040
37041
37042
37043
37044
37045
37046
37047
37048
37049
37050
37051
37052
37053
37054
37055
37056
37057
37058
37059
37060
37061
37062
37063
37064
37065
37066
37067
37068
37069
37070
37071
37072
37073
37074
37075
37076
37077
37078
37079
37080
37081
37082
37083
37084
37085
37086
37087
37088
37089
37090
37091
37092
37093
37094
37095
37096
37097
37098
37099
37100
37101
37102
37103
37104
37105
37106
37107
37108
37109
37110
37111
37112
37113
37114
37115
37116
37117
37118
37119
37120
37121
37122
37123
37124
37125
37126
37127
37128
37129
37130
37131
37132
37133
37134
37135
37136
37137
37138
37139
37140
37141
37142
37143
37144
37145
37146
37147
37148
37149
37150
37151
37152
37153
37154
37155
37156
37157
37158
37159
37160
37161
37162
37163
37164
37165
37166
37167
37168
37169
37170
37171
37172
37173
37174
37175
37176
37177
37178
37179
37180
37181
37182
37183
37184
37185
37186
37187
37188
37189
37190
37191
37192
37193
37194
37195
37196
37197
37198
37199
37200
37201
37202
37203
37204
37205
37206
37207
37208
37209
37210
37211
37212
37213
37214
37215
37216
37217
37218
37219
37220
37221
37222
37223
37224
37225
37226
37227
37228
37229
37230
37231
37232
37233
37234
37235
37236
37237
37238
37239
37240
37241
37242
37243
37244
37245
37246
37247
37248
37249
37250
37251
37252
37253
37254
37255
37256
37257
37258
37259
37260
37261
37262
37263
37264
37265
37266
37267
37268
37269
37270
37271
37272
37273
37274
37275
37276
37277
37278
37279
37280
37281
37282
37283
37284
37285
37286
37287
37288
37289
37290
37291
37292
37293
37294
37295
37296
37297
37298
37299
37300
37301
37302
37303
37304
37305
37306
37307
37308
37309
37310
37311
37312
37313
37314
37315
37316
37317
37318
37319
37320
37321
37322
37323
37324
37325
37326
37327
37328
37329
37330
37331
37332
37333
37334
37335
37336
37337
37338
37339
37340
37341
37342
37343
37344
37345
37346
37347
37348
37349
37350
37351
37352
37353
37354
37355
37356
37357
37358
37359
37360
37361
37362
37363
37364
37365
37366
37367
37368
37369
37370
37371
37372
37373
37374
37375
37376
37377
37378
37379
37380
37381
37382
37383
37384
37385
37386
37387
37388
37389
37390
37391
37392
37393
37394
37395
37396
37397
37398
37399
37400
37401
37402
37403
37404
37405
37406
37407
37408
37409
37410
37411
37412
37413
37414
37415
37416
37417
37418
37419
37420
37421
37422
37423
37424
37425
37426
37427
37428
37429
37430
37431
37432
37433
37434
37435
37436
37437
37438
37439
37440
37441
37442
37443
37444
37445
37446
37447
37448
37449
37450
37451
37452
37453
37454
37455
37456
37457
37458
37459
37460
37461
37462
37463
37464
37465
37466
37467
37468
37469
37470
37471
37472
37473
37474
37475
37476
37477
37478
37479
37480
37481
37482
37483
37484
37485
37486
37487
37488
37489
37490
37491
37492
37493
37494
37495
37496
37497
37498
37499
37500
37501
37502
37503
37504
37505
37506
37507
37508
37509
37510
37511
37512
37513
37514
37515
37516
37517
37518
37519
37520
37521
37522
37523
37524
37525
37526
37527
37528
37529
37530
37531
37532
37533
37534
37535
37536
37537
37538
37539
37540
37541
37542
37543
37544
37545
37546
37547
37548
37549
37550
37551
37552
37553
37554
37555
37556
37557
37558
37559
37560
37561
37562
37563
37564
37565
37566
37567
37568
37569
37570
37571
37572
37573
37574
37575
37576
37577
37578
37579
37580
37581
37582
37583
37584
37585
37586
37587
37588
37589
37590
37591
37592
37593
37594
37595
37596
37597
37598
37599
37600
37601
37602
37603
37604
37605
37606
37607
37608
37609
37610
37611
37612
37613
37614
37615
37616
37617
37618
37619
37620
37621
37622
37623
37624
37625
37626
37627
37628
37629
37630
37631
37632
37633
37634
37635
37636
37637
37638
37639
37640
37641
37642
37643
37644
37645
37646
37647
37648
37649
37650
37651
37652
37653
37654
37655
37656
37657
37658
37659
37660
37661
37662
37663
37664
37665
37666
37667
37668
37669
37670
37671
37672
37673
37674
37675
37676
37677
37678
37679
37680
37681
37682
37683
37684
37685
37686
37687
37688
37689
37690
37691
37692
37693
37694
37695
37696
37697
37698
37699
37700
37701
37702
37703
37704
37705
37706
37707
37708
37709
37710
37711
37712
37713
37714
37715
37716
37717
37718
37719
37720
37721
37722
37723
37724
37725
37726
37727
37728
37729
37730
37731
37732
37733
37734
37735
37736
37737
37738
37739
37740
37741
37742
37743
37744
37745
37746
37747
37748
37749
37750
37751
37752
37753
37754
37755
37756
37757
37758
37759
37760
37761
37762
37763
37764
37765
37766
37767
37768
37769
37770
37771
37772
37773
37774
37775
37776
37777
37778
37779
37780
37781
37782
37783
37784
37785
37786
37787
37788
37789
37790
37791
37792
37793
37794
37795
37796
37797
37798
37799
37800
37801
37802
37803
37804
37805
37806
37807
37808
37809
37810
37811
37812
37813
37814
37815
37816
37817
37818
37819
37820
37821
37822
37823
37824
37825
37826
37827
37828
37829
37830
37831
37832
37833
37834
37835
37836
37837
37838
37839
37840
37841
37842
37843
37844
37845
37846
37847
37848
37849
37850
37851
37852
37853
37854
37855
37856
37857
37858
37859
37860
37861
37862
37863
37864
37865
37866
37867
37868
37869
37870
37871
37872
37873
37874
37875
37876
37877
37878
37879
37880
37881
37882
37883
37884
37885
37886
37887
37888
37889
37890
37891
37892
37893
37894
37895
37896
37897
37898
37899
37900
37901
37902
37903
37904
37905
37906
37907
37908
37909
37910
37911
37912
37913
37914
37915
37916
37917
37918
37919
37920
37921
37922
37923
37924
37925
37926
37927
37928
37929
37930
37931
37932
37933
37934
37935
37936
37937
37938
37939
37940
37941
37942
37943
37944
37945
37946
37947
37948
37949
37950
37951
37952
37953
37954
37955
37956
37957
37958
37959
37960
37961
37962
37963
37964
37965
37966
37967
37968
37969
37970
37971
37972
37973
37974
37975
37976
37977
37978
37979
37980
37981
37982
37983
37984
37985
37986
37987
37988
37989
37990
37991
37992
37993
37994
37995
37996
37997
37998
37999
38000
38001
38002
38003
38004
38005
38006
38007
38008
38009
38010
38011
38012
38013
38014
38015
38016
38017
38018
38019
38020
38021
38022
38023
38024
38025
38026
38027
38028
38029
38030
38031
38032
38033
38034
38035
38036
38037
38038
38039
38040
38041
38042
38043
38044
38045
38046
38047
38048
38049
38050
38051
38052
38053
38054
38055
38056
38057
38058
38059
38060
38061
38062
38063
38064
38065
38066
38067
38068
38069
38070
38071
38072
38073
38074
38075
38076
38077
38078
38079
38080
38081
38082
38083
38084
38085
38086
38087
38088
38089
38090
38091
38092
38093
38094
38095
38096
38097
38098
38099
38100
38101
38102
38103
38104
38105
38106
38107
38108
38109
38110
38111
38112
38113
38114
38115
38116
38117
38118
38119
38120
38121
38122
38123
38124
38125
38126
38127
38128
38129
38130
38131
38132
38133
38134
38135
38136
38137
38138
38139
38140
38141
38142
38143
38144
38145
38146
38147
38148
38149
38150
38151
38152
38153
38154
38155
38156
38157
38158
38159
38160
38161
38162
38163
38164
38165
38166
38167
38168
38169
38170
38171
38172
38173
38174
38175
38176
38177
38178
38179
38180
//! Closed-axis and product-cube discipline traits — close the
//! `const ALL: &'static [Self]` enumeration discipline (axis-level) and
//! the realizability surface (cube-level) across the typescape
//! primitive set under two trait interfaces.
//!
//! Every closed-axis primitive on the typescape primitive set — the
//! nine `#[non_exhaustive]` enums [`crate::Format`],
//! [`crate::FormatProvenance`], [`crate::ConfigSourceKind`],
//! [`crate::FigmentSourceKind`], [`crate::ShikumiErrorKind`],
//! [`crate::FieldPathLocalization`], [`crate::AttributionRule`],
//! [`crate::AttributionConfidence`], [`crate::AttributionAxis`] — and
//! the four product-cube structs [`crate::FormatCoordinates`],
//! [`crate::AttributionCoordinates`],
//! [`crate::ErrorLocalizationCoordinates`],
//! [`crate::AttributionSourceKindCoordinates`] expose a closed
//! `Self::ALL: &'static [Self]` slice enumerating every value, in
//! declaration order, with cardinality pinned at the type level. The
//! [`ClosedAxis`] trait closes that discipline structurally: a tenth
//! axis primitive landing on the typescape primitive set is required by
//! the compiler to provide `const ALL` once it
//! `impl ClosedAxis for NewAxis { … }`, and the generic helpers
//! [`axis_iter`] / [`axis_cardinality`] are inherited at the impl
//! declaration without re-writing the per-axis
//! `<Axis>::ALL.iter().copied()` / `<Axis>::ALL.len()` pattern at every
//! consumer (98+ inlined `::ALL.iter().copied()` sites and 378+ inlined
//! `<Axis>::ALL` references across the crate today).
//!
//! Every product cube additionally exposes a
//! `fn is_realizable(self) -> bool` membership predicate over the subset
//! of cells some recognized typescape value occupies, with the
//! realizable cells partitioning `ALL` into the recognized image and
//! the cross-axis consistency-violation complement. The
//! [`ProductCube`]: [`ClosedAxis`] sub-trait closes that discipline
//! structurally on top of the axis-level discipline: a fifth product
//! cube landing on the typescape (e.g. a future
//! `(figment_source_kind × axis × confidence)` cube refining the
//! source-axis attribution rule space, or a `(format × name_style)`
//! cube refining the discovery axis) is required by the compiler to
//! provide `is_realizable` once it `impl ProductCube for NewCube { … }`
//! — the discipline becomes structural rather than
//! convention-by-naming.
//!
//! Generic helpers [`realizable_iter`] / [`unrealizable_iter`] /
//! [`realizable_count`] / [`unrealizable_count`] consolidate the
//! per-cube `ALL.iter().copied().filter(|c| c.is_realizable())` /
//! `… filter(|c| !c.is_realizable()).count()` patterns that appeared
//! at three sites per cube in the per-cube test suites
//! (12 inlined filters across the four cubes today). Consumers route
//! through the generic helper with the cube type as a turbofish
//! parameter instead of re-deriving the filter inline.

use std::hash::Hash;

/// Closed discipline trait every typescape closed-axis primitive and
/// every typescape product cube satisfies.
///
/// A closed axis is any `Copy + Eq + Hash + 'static` type — typically a
/// `#[non_exhaustive]` enum or a struct over closed-enum fields — that
/// exposes a closed `Self::ALL: &'static [Self]` slice enumerating
/// every value, in declaration order. The slice cardinality is pinned
/// at the type level (the variant count for an enum, the Cartesian
/// product of the constituent axis cardinalities for a product cube).
///
/// Implementors today: the nine closed-enum axis primitives on the
/// typescape primitive set ([`crate::Format`],
/// [`crate::FormatProvenance`], [`crate::ConfigSourceKind`],
/// [`crate::FigmentSourceKind`], [`crate::ShikumiErrorKind`],
/// [`crate::FieldPathLocalization`], [`crate::AttributionRule`],
/// [`crate::AttributionConfidence`], [`crate::AttributionAxis`]) plus
/// the four product cubes ([`crate::FormatCoordinates`],
/// [`crate::AttributionCoordinates`],
/// [`crate::ErrorLocalizationCoordinates`],
/// [`crate::AttributionSourceKindCoordinates`]). All thirteen plug
/// into [`axis_iter`] / [`axis_cardinality`] uniformly.
///
/// The trait bounds (`Copy + Eq + Hash + 'static`) match the hand-
/// disciplined `derive`-set on every existing implementor
/// (`Debug, Clone, Copy, PartialEq, Eq, Hash` on each closed enum;
/// the same set plus `#[non_exhaustive]` on each cube struct), so the
/// abstraction is zero-overhead: generic helpers re-use the same
/// `Copy`-by-value receiver pattern as the per-axis inherent methods.
///
/// `Sized` is implied by the `'static` bound; the `'static` bound is
/// required by `const ALL: &'static [Self]`. The trait is intentionally
/// not object-safe (`const` items) — consumers route generically over
/// the axis type parameter, not over `dyn ClosedAxis` trait objects.
pub trait ClosedAxis: Copy + Eq + Hash + 'static {
    /// Every value of the closed-axis primitive (or every cell of the
    /// product cube), in declaration order over the inherent
    /// `Self::ALL` constant.
    ///
    /// Mirror of the inherent `Self::ALL` constant every implementor
    /// already exposes. The trait re-export lets generic helpers
    /// ([`axis_iter`], [`axis_cardinality`], [`realizable_iter`],
    /// [`realizable_count`], future cube-cover dashboards) reach the
    /// constant without naming the concrete axis type — the per-axis
    /// `*_trait_all_matches_inherent_all` tests pin the two slices to
    /// the same contents pointwise.
    const ALL: &'static [Self];
}

/// Iterate every value of a [`ClosedAxis`] — `A::ALL.iter().copied()`
/// collapsed to one named helper.
///
/// Consolidates the `A::ALL.iter().copied()` pattern that appears at
/// 98+ sites across the crate (per-axis cover/partition tests,
/// cube-coverage loops, dashboard initializers, attestation manifest
/// builders). Generic in the axis type so the helper is inherited
/// uniformly across the closed-axis discipline.
pub fn axis_iter<A: ClosedAxis>() -> impl Iterator<Item = A> {
    A::ALL.iter().copied()
}

/// Cardinality of a [`ClosedAxis`] — `A::ALL.len()` collapsed to one
/// named helper.
///
/// Today's axis cardinalities — 4 ([`crate::Format`]),
/// 2 ([`crate::FormatProvenance`]), 3 ([`crate::ConfigSourceKind`]),
/// 3 ([`crate::FigmentSourceKind`]), 6 ([`crate::ShikumiErrorKind`]),
/// 3 ([`crate::FieldPathLocalization`]), 5 ([`crate::AttributionRule`]),
/// 2 ([`crate::AttributionConfidence`]),
/// 2 ([`crate::AttributionAxis`]) — and today's cube cardinalities — 8
/// ([`crate::FormatCoordinates`]), 12 ([`crate::AttributionCoordinates`]),
/// 18 ([`crate::ErrorLocalizationCoordinates`]),
/// 9 ([`crate::AttributionSourceKindCoordinates`]) — reachable as one
/// method call across all thirteen implementors uniformly.
#[must_use]
pub fn axis_cardinality<A: ClosedAxis>() -> usize {
    A::ALL.len()
}

/// Structural ordinal of a [`ClosedAxis`] value — the position of
/// `value` in `A::ALL`, in declaration order.
///
/// Dual of [`axis_iter`]: where [`axis_iter`] is the forward map
/// `ordinal → value` (`A::ALL[i] = value`), [`axis_ordinal`] is the
/// inverse `value → ordinal` (`A::ALL.iter().position(value)`). The two
/// directions close a structural bijection between every
/// [`ClosedAxis`] implementor and the prefix `0..axis_cardinality::<A>()`
/// of the natural numbers — a stable, deterministic embedding of every
/// typescape primitive into a dense integer range.
///
/// **Totality** — the [`ClosedAxis`] discipline pins that `A::ALL`
/// enumerates every value of the axis in declaration order, so every
/// `value: A` has a unique position in the slice. The helper returns
/// `usize` (not `Option<usize>`) because the discipline guarantees
/// totality; a `None` return would witness a discipline violation
/// (`A::ALL` missing a value the type system says exists). The
/// fallback `unreachable!` exists only to satisfy the compiler — it
/// would fire if a future `impl ClosedAxis` lied about `ALL`, in
/// which case the per-axis `axis_ordinal_round_trips_*` invariant
/// would also fail at the trait-uniform test site.
///
/// **Injectivity** — `A::ALL` carries no duplicates (every existing
/// implementor's per-axis `*_all_has_no_duplicates` test pins this
/// pointwise, and the trait-uniform
/// [`tests::axis_ordinal_injective_for_every_closed_axis_implementor`]
/// re-states it once across all 13 implementors), so distinct values
/// land at distinct positions. The ordinal is a structural injection
/// `A → ℕ` whose image equals `0..axis_cardinality::<A>()` as a set —
/// the canonical dense embedding of the axis.
///
/// **Round-trip law** — `A::ALL[axis_ordinal(v)] == v` for every
/// `v: A`, and dually `axis_ordinal(A::ALL[i]) == i` for every
/// `i < axis_cardinality::<A>()`. Both directions pinned by the
/// trait-uniform tests reaching every implementor.
///
/// **Consumers** — dense bitsets / arrays sized by
/// [`axis_cardinality::<A>()`][axis_cardinality] index through the
/// ordinal without a `HashMap<A, usize>` per call site; canonical
/// attestation manifests (THEORY.md §III.1.8 module manifests, §V.3
/// three-pillar attestation) hash typescape cells in stable
/// declaration order pinned by the ordinal; future cube-cover
/// dashboards order rows by the ordinal of each axis cell instead of
/// re-deriving the position lookup inline.
///
/// # Panics
///
/// Panics — via `unreachable!` — only if a `ClosedAxis` implementor
/// violates the discipline by omitting a reachable value from
/// `Self::ALL`. The trait-uniform `axis_ordinal_round_trips_*` tests
/// would fail at the same site; in practice this branch is unreachable
/// for any well-formed implementor.
#[must_use]
pub fn axis_ordinal<A: ClosedAxis>(value: A) -> usize {
    match A::ALL.iter().position(|&v| v == value) {
        Some(i) => i,
        None => unreachable!(
            "ClosedAxis::ALL must contain every value of the axis (discipline violation: \
             `Self::ALL` omitted a reachable value)",
        ),
    }
}

/// Structural ordinal lookup for a [`ClosedAxis`] — the value at
/// position `ordinal` in `A::ALL`, or [`None`] if the index is
/// out-of-range.
///
/// Safe forward dual of [`axis_ordinal`]: where [`axis_ordinal`] is
/// the total inverse `value → ordinal` over the closed axis, [`axis_at`]
/// is the partial forward `ordinal → Option<value>` over `usize`,
/// returning [`Some`] exactly on the prefix `0..axis_cardinality::<A>()`
/// and [`None`] outside it.
///
/// The pair ([`axis_ordinal`], [`axis_at`]) closes the bijection
/// between every [`ClosedAxis`] implementor and the natural-number
/// prefix `0..axis_cardinality::<A>()` in both directions, with
/// out-of-range indices reported as [`None`] rather than panicking on
/// the slice index. Where [`axis_iter`] streams `A::ALL` in
/// declaration order (the total forward map keyed implicitly by
/// position), [`axis_at`] is the same map keyed explicitly by a
/// caller-provided index — a content-addressable lookup that hands
/// the `ordinal` axis to the caller without re-deriving
/// `A::ALL.get(ordinal).copied()` at every consumer.
///
/// **Bijection laws** — pinned by trait-uniform tests reaching every
/// implementor pointwise:
///
/// 1. **Round-trip from the value side** —
///    `axis_at::<A>(axis_ordinal::<A>(v)) == Some(v)` for every
///    `v: A`. The ordinal-then-lookup composition is the identity on
///    `A`.
/// 2. **Round-trip from the ordinal side** —
///    `axis_at::<A>(i).map(axis_ordinal::<A>) == Some(i)` for every
///    `i < axis_cardinality::<A>()`. The lookup-then-ordinal
///    composition is the identity on the in-range prefix.
/// 3. **Partiality on out-of-range** —
///    `axis_at::<A>(i).is_none()` for every
///    `i >= axis_cardinality::<A>()`. The forward map is total over
///    the prefix and undefined outside it; the [`Option`] return
///    surfaces the partiality at the type level instead of by
///    convention.
///
/// **Consumers** — deserializing attestation manifests
/// (THEORY.md §III.1.8 module manifests, §V.3 three-pillar
/// attestation) that carry typescape cells by stable declaration
/// ordinal recover the typed value via [`axis_at`] without an
/// `A::ALL.get(i).copied()` inline at every loader site. Dense
/// arrays sized by [`axis_cardinality::<A>()`][axis_cardinality]
/// look up the typed value at a given position safely. Future
/// cube-cover dashboards that render rows keyed by ordinal index
/// recover the row's typescape cell through one named helper rather
/// than re-deriving the slice-`get` per renderer.
#[must_use]
pub fn axis_at<A: ClosedAxis>(ordinal: usize) -> Option<A> {
    A::ALL.get(ordinal).copied()
}

/// Dense, declaration-ordered per-cell observation tally over a
/// [`ClosedAxis`] — the typed histogram every fleet observer reaches for
/// when bucketing observations by axis cell.
///
/// The histogram's value space is sized by
/// [`axis_cardinality::<A>()`][axis_cardinality]: one [`usize`] slot per
/// axis cell, laid out in declaration order over [`ClosedAxis::ALL`]
/// (i.e. indexed by [`axis_ordinal`]). Every observation increments
/// exactly one slot through [`Self::observe`] (or [`Self::from_iter`] in
/// bulk).
///
/// **Why one typed primitive.** The per-axis observation-mix histogram
/// is named as a use case in seventeen-plus doc-strings across the crate
/// — `crate::ConfigDiff::render_unified`'s per-kind summary on the
/// diff-cell axis ([`crate::DiffLineKind`]; "this rebuild added 12,
/// removed 4"), per-backend telemetry on
/// [`crate::SecretBackendKind`], per-class reload-trigger counts on
/// [`crate::WatchEventClass`], per-kind reload-failure buckets on
/// [`crate::ShikumiErrorKind`], per-confidence attribution mix on
/// [`crate::AttributionConfidence`], attestation manifests recording the
/// per-axis cardinality mix of resolved values — yet no typed lift
/// existed. Every observer re-derived the count loop inline as
/// `items.iter().filter(|x| x.kind() == k).count()` per cell, or
/// `items.iter().fold(HashMap::new(), |mut m, x| { *m.entry(x).or_insert(0) += 1; m })`
/// with the indeterminate ordering and one-allocation-per-key overhead a
/// `HashMap` brings. The lift names the (closed-axis × iterable
/// observations → per-cell counts) projection at one site, indexed by
/// [`axis_ordinal`] so the dense layout agrees with [`axis_iter`] /
/// [`axis_at`] pointwise.
///
/// **Type-level axis tagging.** The [`std::marker::PhantomData<A>`] slot
/// keeps the histogram parameterized by axis at the type level: a
/// `AxisHistogram<DiffLineKind>` cannot be passed where an
/// `AxisHistogram<WatchEventClass>` is expected. Cross-axis confusion
/// (rendering a diff-kind histogram through a reload-event renderer, or
/// vice versa) is structurally impossible — the compiler catches the
/// swap at the call site rather than silently mis-attributing counts.
///
/// **Algebraic structure.** The histogram is a free commutative monoid
/// over the axis cells under pointwise addition: [`Self::empty`] is the
/// identity, [`Self::merge`] is the binary operation. Both are pinned by
/// the trait-uniform invariant tests reaching every [`ClosedAxis`]
/// implementor uniformly.
///
/// **Hashable identity.** [`Eq`] is paired with [`std::hash::Hash`] so
/// `AxisHistogram<A>` is the canonical Rust [`(Eq, Hash)`][std::hash::Hash]
/// idiom-peer pair — usable as a [`std::collections::HashSet`] element
/// or a [`std::collections::HashMap`] key without an interposing
/// hand-rolled wrapper. A fleet aggregator deduping per-host observation
/// mixes (`HashSet<AxisHistogram<DiffLineKind>>` collapsing two hosts
/// that landed the same rebuild summary into one bucket), a memoization
/// table keyed on the configuration shape that produced an outcome
/// (`HashMap<AxisHistogram<ConfigSourceKind>, ResolveCost>`), or a
/// regression-bucket histogram-of-histograms tallying how often each
/// distinct observation mix recurred (`AxisHistogram<…>` as the
/// `HashMap` key on a per-window collapse step) all reach the
/// collection-key surface without per-call-site wrapper types or a
/// `BTreeMap` fallback whose `Ord` requirement would force a total
/// ordering the underlying free-commutative-monoid structure has no
/// canonical pick for. The derived hash inherits the
/// [`Vec<usize>`][Vec] hash on the counts vector, which agrees with
/// [`Eq`] pointwise by construction; two histograms that compare equal
/// hash equally on every axis, pinned by the trait-uniform
/// `axis_histogram_equal_implies_same_hash_*` law in [`tests`].
///
/// **Implementor coverage.** Generic over the [`ClosedAxis`] trait
/// bound, so every closed-axis primitive on the typescape (the twenty
/// closed-enum kinds plus the five product cubes — twenty-five
/// implementors uniformly) inherits the histogram primitive at no
/// per-axis cost. Trait-uniform laws reach every implementor through
/// `for_each_closed_axis_implementor!` in [`tests`].
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct AxisHistogram<A: ClosedAxis> {
    counts: Vec<usize>,
    _marker: std::marker::PhantomData<A>,
}

impl<A: ClosedAxis> Default for AxisHistogram<A> {
    fn default() -> Self {
        Self::empty()
    }
}

/// The **closed modal/antimodal classification** of an [`AxisHistogram`]
/// on the `(strict / tied) × (modal / antimodal)` two-axis multiplicity
/// surface, with the empty boundary lifted to its own variant.
///
/// Returned by [`AxisHistogram::modality_class`]; pattern-matched
/// exhaustively at every dashboard / attestation manifest / alarm-routing
/// site that previously composed the four named boolean predicates
/// ([`AxisHistogram::is_strictly_modally_unique`],
/// [`AxisHistogram::is_modally_tied`],
/// [`AxisHistogram::is_strictly_antimodally_unique`],
/// [`AxisHistogram::is_antimodally_tied`]) into a 4- or 5-way `if` ladder
/// over the four predicates. The enum closes that boolean algebra at one
/// named variant per classifier corner, plus the empty-histogram boundary
/// as the fifth variant — the compiler enforces exhaustiveness at every
/// match site, so a future renderer landing on the typescape *cannot*
/// silently drop the empty-boundary or any classifier-corner branch.
///
/// **Five variants, structurally exhaustive over the multiplicity
/// surface.** Every histogram's [`AxisHistogram::modality_degree`] pair
/// `(peak_mult, trough_mult)` falls into exactly one variant; the
/// classification is total and disjoint by construction:
///
/// | `modality_degree()`        | `ModalityClass` variant                          | Modal axis        | Antimodal axis    |
/// |----------------------------|--------------------------------------------------|-------------------|-------------------|
/// | `(0, 0)`                   | [`Self::Empty`]                                  | (n/a)             | (n/a)             |
/// | `(1, 1)`                   | [`Self::StrictModalStrictAntimodal`]             | strictly unique   | strictly unique   |
/// | `(k, 1)` with `k >= 2`     | [`Self::TiedModalStrictAntimodal`]               | tied (`k`-way)    | strictly unique   |
/// | `(1, l)` with `l >= 2`     | [`Self::StrictModalTiedAntimodal`]               | strictly unique   | tied (`l`-way)    |
/// | `(k, l)` with `k, l >= 2`  | [`Self::TiedModalTiedAntimodal`]                 | tied (`k`-way)    | tied (`l`-way)    |
///
/// The variants are named on the *defining axis-pair shape*
/// `({Strict|Tied}Modal{Strict|Tied}Antimodal)` rather than on the
/// example shapes that fire them (e.g. "uniform-count" or "skewed") so
/// the variant identity stays stable under future shape-classifier
/// additions: a `is_balanced` or `is_skewed` predicate landing on the
/// histogram surface refines the *predicates*, not the variant identity
/// of the closed multiplicity classification.
///
/// **Peer-bound to the boolean primitives.** The enum carries inherent
/// `const` predicates [`Self::is_empty`], [`Self::is_modally_tied`], and
/// [`Self::is_antimodally_tied`] — the enum-level peers of the
/// histogram-surface predicates of the same name — so consumers holding
/// a `ModalityClass` value (e.g. a cached classification on a per-window
/// summary struct) read off the modal/antimodal axis booleans without
/// re-routing through the originating histogram. The peer-equivalence
/// laws (`hist.modality_class().is_modally_tied() == hist.is_modally_tied()`
/// and the antimodal twin) are pinned trait-uniformly across every
/// [`ClosedAxis`] implementor.
///
/// **Closed-axis primitive trait.** The enum carries [`Copy`] (no
/// allocation, fits in a `u8` discriminant), [`Eq`] + [`Hash`] (usable
/// as a [`std::collections::HashMap`] key for per-classifier-corner
/// rollup counters, e.g. a fleet-wide
/// `HashMap<ModalityClass, usize>` tallying how many reload windows
/// landed in each classifier corner), [`Ord`] + [`PartialOrd`] (usable
/// as a [`std::collections::BTreeMap`] key for deterministic
/// classifier-corner rollup emission — declaration-order total order
/// matches [`Self::ALL`] position pointwise, pinned by
/// [`tests::modality_class_ord_matches_all_declaration_order`]; the
/// idiom-peer of the same [`Ord`] + [`PartialOrd`] derive on
/// [`SupportBoundaryDistance`] and [`SupportMagnitudeDirection`]), and
/// `Debug` (operator-facing summary line emission). It is *not* a
/// [`ClosedAxis`] itself — that would imply an
/// [`AxisHistogram<ModalityClass>`] surface, which is well-typed but
/// semantically inverted (counting how many histograms land in each
/// class is a meta-observation, not a substrate observation); the
/// [`ClosedAxis`] trait stays gated on substrate-observation axes.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)]
pub enum ModalityClass {
    /// The **empty-histogram boundary** — `modality_degree() == (0, 0)`.
    ///
    /// The histogram has no observed cells; the modal and antimodal
    /// level sets are both empty. Below both branches of the
    /// strict/tied modal partition *and* the strict/tied antimodal
    /// partition: every named boolean ([`AxisHistogram::is_strictly_modally_unique`],
    /// [`AxisHistogram::is_modally_tied`],
    /// [`AxisHistogram::is_strictly_antimodally_unique`],
    /// [`AxisHistogram::is_antimodally_tied`]) reads `false` on this
    /// variant. Lifted to its own variant rather than folded into one
    /// of the four classifier corners so the empty boundary is a typed
    /// witness every dashboard / attestation / alarm site can branch on
    /// directly, without a separate [`AxisHistogram::is_empty`]
    /// pre-check at every match site.
    Empty,
    /// **Both extremes uniquely held** — `modality_degree() == (1, 1)`.
    ///
    /// The dominant cell stands alone at the peak count, the recessive
    /// cell stands alone at the trough count, and neither
    /// declaration-order tie-break (in [`AxisHistogram::dominant_cell`]
    /// nor [`AxisHistogram::recessive_cell`]) is exercised. Includes
    /// every singleton-support histogram (where peak and trough
    /// coincide on the lone observed cell) and every strictly-skewed
    /// non-uniform shape whose peak and trough are both uniquely held.
    StrictModalStrictAntimodal,
    /// **Peak shared, trough uniquely held** —
    /// `modality_degree() == (k, 1)` with `k >= 2`.
    ///
    /// The modal level set has `k >= 2` members (the
    /// [`AxisHistogram::dominant_cell`] declaration-order tie-break
    /// *is* exercised), but the trough is uniquely held by a single
    /// recessive cell. Fires on shapes with a heavy multi-cell plateau
    /// at the peak and one strictly-rarer tail cell.
    TiedModalStrictAntimodal,
    /// **Peak uniquely held, trough shared** —
    /// `modality_degree() == (1, l)` with `l >= 2`.
    ///
    /// The dominant cell stands alone at the peak, but the antimodal
    /// level set has `l >= 2` members (the
    /// [`AxisHistogram::recessive_cell`] declaration-order tie-break
    /// *is* exercised). Fires on shapes with a single dominant cell
    /// and a multi-cell flat trough.
    StrictModalTiedAntimodal,
    /// **Both extremes shared** —
    /// `modality_degree() == (k, l)` with `k >= 2` and `l >= 2`.
    ///
    /// Both tie-breaks are exercised: the modal level set has `k >= 2`
    /// members and the antimodal level set has `l >= 2` members. The
    /// canonical example is every **uniform-count multi-cell** shape
    /// (every observed cell shares the same count, so peak and trough
    /// collapse onto the same level set of size `distinct_cells()`) —
    /// including every uniform axis-cover on an axis with cardinality
    /// `>= 2`. Also covers non-uniform shapes carrying both a
    /// multi-cell peak plateau and a multi-cell trough plateau.
    TiedModalTiedAntimodal,
}

impl ModalityClass {
    /// Every [`ModalityClass`] variant, in declaration order:
    /// `Empty`, `StrictModalStrictAntimodal`, `TiedModalStrictAntimodal`,
    /// `StrictModalTiedAntimodal`, `TiedModalTiedAntimodal`.
    ///
    /// Lets a per-classifier-corner rollup table iterate the variants
    /// uniformly (`for class in ModalityClass::ALL { … }`) without
    /// re-deriving the 5-entry list at the call site. Peer to the
    /// [`PartitionFace::ALL`] convention on the sibling typed primitive.
    /// Length 5 — pinned by [`tests::modality_class_all_has_five_entries`].
    pub const ALL: &'static [Self] = &[
        Self::Empty,
        Self::StrictModalStrictAntimodal,
        Self::TiedModalStrictAntimodal,
        Self::StrictModalTiedAntimodal,
        Self::TiedModalTiedAntimodal,
    ];

    /// `true` exactly on [`Self::Empty`] — the enum-level peer of
    /// [`AxisHistogram::is_empty`] projected from the variant tag.
    ///
    /// On every histogram `h`,
    /// `h.modality_class().is_empty() == h.is_empty()`, pinned
    /// trait-uniformly across every [`ClosedAxis`] implementor by
    /// [`tests::axis_histogram_modality_class_is_empty_agrees_with_histogram_is_empty_for_every_closed_axis_implementor`].
    /// Lets a consumer holding a cached `ModalityClass` value (e.g. on a
    /// per-window summary struct) branch on the empty boundary without
    /// re-routing through the originating histogram.
    #[must_use]
    pub const fn is_empty(self) -> bool {
        matches!(self, Self::Empty)
    }

    /// `true` exactly when the modal axis is tied — the two variants
    /// [`Self::TiedModalStrictAntimodal`] and
    /// [`Self::TiedModalTiedAntimodal`]. The enum-level peer of
    /// [`AxisHistogram::is_modally_tied`] projected from the variant
    /// tag.
    ///
    /// On every histogram `h`,
    /// `h.modality_class().is_modally_tied() == h.is_modally_tied()`,
    /// pinned trait-uniformly across every [`ClosedAxis`] implementor
    /// by
    /// [`tests::axis_histogram_modality_class_is_modally_tied_agrees_with_histogram_is_modally_tied_for_every_closed_axis_implementor`].
    /// `false` on [`Self::Empty`] (matching
    /// [`AxisHistogram::is_modally_tied`] returning `false` on the
    /// empty histogram).
    #[must_use]
    pub const fn is_modally_tied(self) -> bool {
        matches!(
            self,
            Self::TiedModalStrictAntimodal | Self::TiedModalTiedAntimodal
        )
    }

    /// `true` exactly when the antimodal axis is tied — the two
    /// variants [`Self::StrictModalTiedAntimodal`] and
    /// [`Self::TiedModalTiedAntimodal`]. The enum-level peer of
    /// [`AxisHistogram::is_antimodally_tied`] projected from the
    /// variant tag.
    ///
    /// On every histogram `h`,
    /// `h.modality_class().is_antimodally_tied() == h.is_antimodally_tied()`,
    /// pinned trait-uniformly across every [`ClosedAxis`] implementor
    /// by
    /// [`tests::axis_histogram_modality_class_is_antimodally_tied_agrees_with_histogram_is_antimodally_tied_for_every_closed_axis_implementor`].
    /// `false` on [`Self::Empty`] (matching
    /// [`AxisHistogram::is_antimodally_tied`] returning `false` on the
    /// empty histogram).
    #[must_use]
    pub const fn is_antimodally_tied(self) -> bool {
        matches!(
            self,
            Self::StrictModalTiedAntimodal | Self::TiedModalTiedAntimodal
        )
    }

    /// `true` exactly when the modal axis is *strictly unique* — the
    /// two variants [`Self::StrictModalStrictAntimodal`] and
    /// [`Self::StrictModalTiedAntimodal`]. The enum-level peer of
    /// [`AxisHistogram::is_strictly_modally_unique`] projected from
    /// the variant tag.
    ///
    /// On every histogram `h`,
    /// `h.modality_class().is_strictly_modally_unique() == h.is_strictly_modally_unique()`,
    /// pinned trait-uniformly across every [`ClosedAxis`] implementor
    /// by
    /// [`tests::axis_histogram_modality_class_is_strictly_modally_unique_agrees_with_histogram_is_strictly_modally_unique_for_every_closed_axis_implementor`].
    /// `false` on [`Self::Empty`] (matching
    /// [`AxisHistogram::is_strictly_modally_unique`] returning `false`
    /// on the empty histogram — the modal level set is empty, not
    /// singleton).
    ///
    /// **Closes the modal-axis boolean partition pair** —
    /// `(is_strictly_modally_unique, is_modally_tied)` on
    /// [`ModalityClass`] now mirrors the same pair on
    /// [`AxisHistogram`]: every non-empty variant lands on exactly one
    /// of the two predicates, and the empty variant reads `false` on
    /// both (the empty-boundary convention shared with the histogram
    /// surface). A consumer holding a cached [`ModalityClass`] branches
    /// on either side of the modal-axis partition without re-routing
    /// through the originating histogram.
    #[must_use]
    pub const fn is_strictly_modally_unique(self) -> bool {
        matches!(
            self,
            Self::StrictModalStrictAntimodal | Self::StrictModalTiedAntimodal
        )
    }

    /// `true` exactly when the antimodal axis is *strictly unique* —
    /// the two variants [`Self::StrictModalStrictAntimodal`] and
    /// [`Self::TiedModalStrictAntimodal`]. The enum-level peer of
    /// [`AxisHistogram::is_strictly_antimodally_unique`] projected
    /// from the variant tag.
    ///
    /// On every histogram `h`,
    /// `h.modality_class().is_strictly_antimodally_unique() == h.is_strictly_antimodally_unique()`,
    /// pinned trait-uniformly across every [`ClosedAxis`] implementor
    /// by
    /// [`tests::axis_histogram_modality_class_is_strictly_antimodally_unique_agrees_with_histogram_is_strictly_antimodally_unique_for_every_closed_axis_implementor`].
    /// `false` on [`Self::Empty`] (matching
    /// [`AxisHistogram::is_strictly_antimodally_unique`] returning
    /// `false` on the empty histogram — the antimodal level set is
    /// empty, not singleton). Orthogonal-axis peer to
    /// [`Self::is_strictly_modally_unique`].
    ///
    /// **Closes the antimodal-axis boolean partition pair** —
    /// `(is_strictly_antimodally_unique, is_antimodally_tied)` on
    /// [`ModalityClass`] now mirrors the same pair on
    /// [`AxisHistogram`]: every non-empty variant lands on exactly one
    /// of the two predicates, and the empty variant reads `false` on
    /// both. Together with the modal-axis pair above, the four
    /// `(modal-strict | modal-tied) × (antimodal-strict | antimodal-tied)`
    /// boolean reads pattern-match the four non-empty classifier
    /// corners at one paired projection on the variant tag.
    #[must_use]
    pub const fn is_strictly_antimodally_unique(self) -> bool {
        matches!(
            self,
            Self::StrictModalStrictAntimodal | Self::TiedModalStrictAntimodal
        )
    }

    /// `true` exactly on [`Self::StrictModalStrictAntimodal`] — the
    /// single variant where the modal *and* antimodal axes are both
    /// strictly unique. The "no tie-break exercised on either axis"
    /// diagonal corner of the
    /// `(modal-strict | modal-tied) × (antimodal-strict | antimodal-tied)`
    /// 2×2 classifier partition.
    ///
    /// Pointwise equal to
    /// `self.is_strictly_modally_unique() && self.is_strictly_antimodally_unique()`,
    /// pinned by
    /// [`tests::modality_class_is_doubly_strict_unique_equals_strict_modal_and_strict_antimodal_conjunction`].
    /// `false` on [`Self::Empty`] (matching the empty-boundary
    /// convention every per-axis named boolean carries: the empty
    /// histogram surfaces `false` on every strict-unique / tied read).
    /// Disjoint from [`Self::is_doubly_tied`] —
    /// [`tests::modality_class_is_doubly_strict_unique_and_is_doubly_tied_are_disjoint`]
    /// pins that the two diagonal-corner predicates never fire on the
    /// same variant.
    ///
    /// **Closes the diagonal-corner (`doubly_strict`, `doubly_tied`)
    /// projection pair** — together with [`Self::is_doubly_tied`], the
    /// two booleans name the two variants where the modal and
    /// antimodal classifications *agree*
    /// ([`Self::StrictModalStrictAntimodal`] and
    /// [`Self::TiedModalTiedAntimodal`]) at one `const` projection on
    /// the variant tag, peering with the four orthogonal-axis
    /// predicates ([`Self::is_strictly_modally_unique`],
    /// [`Self::is_modally_tied`],
    /// [`Self::is_strictly_antimodally_unique`],
    /// [`Self::is_antimodally_tied`]) that close the per-axis
    /// partition pairs. A consumer holding a cached [`ModalityClass`]
    /// branching on the "tie-break exercised on neither axis?"
    /// question now reads one `const` projection rather than the
    /// conjunction of two per-axis predicates.
    #[must_use]
    pub const fn is_doubly_strict_unique(self) -> bool {
        matches!(self, Self::StrictModalStrictAntimodal)
    }

    /// `true` exactly on [`Self::TiedModalTiedAntimodal`] — the single
    /// variant where the modal *and* antimodal axes are both tied. The
    /// "both tie-breaks exercised" diagonal corner of the
    /// `(modal-strict | modal-tied) × (antimodal-strict | antimodal-tied)`
    /// 2×2 classifier partition; the orthogonal-corner peer of
    /// [`Self::is_doubly_strict_unique`].
    ///
    /// Pointwise equal to
    /// `self.is_modally_tied() && self.is_antimodally_tied()`, pinned
    /// by
    /// [`tests::modality_class_is_doubly_tied_equals_modal_tied_and_antimodal_tied_conjunction`].
    /// `false` on [`Self::Empty`] (matching the empty-boundary
    /// convention shared with the histogram surface — the empty
    /// histogram surfaces `false` on every per-axis tied read, so the
    /// conjunction reads `false` as well). Disjoint from
    /// [`Self::is_doubly_strict_unique`] —
    /// [`tests::modality_class_is_doubly_strict_unique_and_is_doubly_tied_are_disjoint`]
    /// pins that the two diagonal-corner predicates never fire on the
    /// same variant.
    ///
    /// Fires uniformly on every uniform-count multi-cell histogram
    /// shape (every observed cell shares the same count, so the modal
    /// and antimodal level sets coincide on the support of size
    /// `distinct_cells() >= 2`) — including every uniform axis cover
    /// on an axis with cardinality `>= 2`, lockstep with the
    /// `axis_histogram_modality_class_uniform_count_non_empty_lands_in_both_tied_or_both_strict`
    /// uniform-count collapse law on the histogram-side surface. A
    /// consumer monitoring "is the rolling window in the
    /// fully-degenerate uniform-plateau corner?" now reads one `const`
    /// projection on the cached class without re-routing through
    /// [`AxisHistogram::is_uniform_count`] or the conjunction of the
    /// two per-axis tied reads.
    #[must_use]
    pub const fn is_doubly_tied(self) -> bool {
        matches!(self, Self::TiedModalTiedAntimodal)
    }

    /// `true` exactly on [`Self::TiedModalStrictAntimodal`] — the
    /// single variant where the modal axis is tied while the antimodal
    /// axis is strictly unique. The "only the modal tie-break is
    /// exercised" off-diagonal corner of the
    /// `(modal-strict | modal-tied) × (antimodal-strict | antimodal-tied)`
    /// 2×2 classifier partition.
    ///
    /// Pointwise equal to
    /// `self.is_modally_tied() && self.is_strictly_antimodally_unique()`,
    /// pinned by
    /// [`tests::modality_class_is_only_modally_tied_equals_modal_tied_and_antimodal_strict_conjunction`].
    /// `false` on [`Self::Empty`] (matching the empty-boundary
    /// convention every per-axis named boolean carries: the empty
    /// histogram surfaces `false` on every per-axis tied / strict-unique
    /// read, so the conjunction reads `false` as well). Disjoint from
    /// the other three single-variant corner predicates
    /// ([`Self::is_doubly_strict_unique`], [`Self::is_doubly_tied`],
    /// [`Self::is_only_antimodally_tied`]) —
    /// [`tests::modality_class_four_corner_predicates_are_pairwise_disjoint`]
    /// pins the full 4-way pairwise-disjointness law.
    ///
    /// **Closes the off-diagonal-corner
    /// (`only_modally_tied`, `only_antimodally_tied`) projection pair**
    /// — together with [`Self::is_only_antimodally_tied`], the two
    /// booleans name the two variants where the modal and antimodal
    /// classifications *disagree*
    /// ([`Self::TiedModalStrictAntimodal`] and
    /// [`Self::StrictModalTiedAntimodal`]) at one `const` projection on
    /// the variant tag, peering with the diagonal-corner pair
    /// ([`Self::is_doubly_strict_unique`], [`Self::is_doubly_tied`])
    /// that names the two agreement-corner variants. Together the four
    /// single-variant predicates name every non-empty classifier corner
    /// — a consumer holding a cached [`ModalityClass`] branching on the
    /// "only the modal axis exercises its tie-break?" question now
    /// reads one `const` projection rather than the conjunction of two
    /// per-axis predicates, or `matches!` on the variant tag.
    #[must_use]
    pub const fn is_only_modally_tied(self) -> bool {
        matches!(self, Self::TiedModalStrictAntimodal)
    }

    /// `true` exactly on [`Self::StrictModalTiedAntimodal`] — the
    /// single variant where the antimodal axis is tied while the modal
    /// axis is strictly unique. The "only the antimodal tie-break is
    /// exercised" off-diagonal corner of the
    /// `(modal-strict | modal-tied) × (antimodal-strict | antimodal-tied)`
    /// 2×2 classifier partition; the orthogonal off-diagonal peer of
    /// [`Self::is_only_modally_tied`].
    ///
    /// Pointwise equal to
    /// `self.is_antimodally_tied() && self.is_strictly_modally_unique()`,
    /// pinned by
    /// [`tests::modality_class_is_only_antimodally_tied_equals_antimodal_tied_and_modal_strict_conjunction`].
    /// `false` on [`Self::Empty`] (matching the empty-boundary
    /// convention shared with the histogram surface — the empty
    /// histogram surfaces `false` on every per-axis read, so the
    /// conjunction reads `false` as well). Disjoint from the other
    /// three single-variant corner predicates
    /// ([`Self::is_doubly_strict_unique`], [`Self::is_doubly_tied`],
    /// [`Self::is_only_modally_tied`]) —
    /// [`tests::modality_class_four_corner_predicates_are_pairwise_disjoint`]
    /// pins the full 4-way pairwise-disjointness law.
    ///
    /// Together with [`Self::is_only_modally_tied`],
    /// [`Self::is_doubly_strict_unique`], and [`Self::is_doubly_tied`],
    /// **closes the four single-variant corner projections** — on every
    /// non-empty variant exactly one of the four predicates fires,
    /// pinned by
    /// [`tests::modality_class_four_corner_predicates_partition_non_empty_variants`].
    /// The empty boundary remains the single variant where all four
    /// read `false`. A consumer branching on the four non-empty
    /// corners now reads four parallel single-variant projections rather
    /// than re-routing through `match` on the variant tag or
    /// re-deriving conjunctions of the per-axis predicates at the call
    /// site.
    #[must_use]
    pub const fn is_only_antimodally_tied(self) -> bool {
        matches!(self, Self::StrictModalTiedAntimodal)
    }

    /// Canonical operator-facing lowercase kebab-case name of the
    /// variant — `"empty"`, `"strict-modal-strict-antimodal"`,
    /// `"tied-modal-strict-antimodal"`, `"strict-modal-tied-antimodal"`,
    /// or `"tied-modal-tied-antimodal"`.
    ///
    /// Single source of truth for the variant-tag canonical-name surface
    /// on [`ModalityClass`]. The five names follow the canonical
    /// `(strict|tied)-modal-(strict|tied)-antimodal` shape verbatim
    /// matching the variant identifier (the empty-boundary variant
    /// collapses to the bare `"empty"` keyword), so a renderer reading
    /// the classifier-corner key sees the same modal/antimodal axis
    /// structure the variant identifier exposes.
    ///
    /// Idiom-peer of [`PartitionFace::as_str`] on the sibling typed
    /// variant-tag primitive (the partition-face projection of
    /// [`PartitionOrdinal`]) — both surface the canonical-name surface
    /// at one inherent `const` projection, returning `&'static str` so
    /// the rendering path is allocation-free. Where [`PartitionFace`]
    /// additionally satisfies [`ClosedAxisLabel`] through its
    /// [`ClosedAxis`] impl, [`ModalityClass`] stays off the
    /// [`ClosedAxis`] trait surface (an
    /// [`AxisHistogram<ModalityClass>`] is well-typed but semantically
    /// inverted — the substrate-observation invariant gates
    /// [`ClosedAxis`] on substrate axes only) and surfaces the
    /// canonical-name discipline through the inherent
    /// (`as_str`, `from_canonical_str`, `Display`, `FromStr`)
    /// quartet rather than the trait.
    ///
    /// **Round-trip law** —
    /// `ModalityClass::from_canonical_str(v.as_str()) == Some(v)` for
    /// every `v: ModalityClass`. Pinned by
    /// [`tests::modality_class_as_str_round_trips_via_from_canonical_str`].
    /// Composes with the case-insensitivity law below: the lowercase
    /// rendered label parses back regardless of the input casing on the
    /// parse side.
    ///
    /// **Distinctness** — `a.as_str() != b.as_str()` for distinct
    /// `a, b: ModalityClass`. The labels inject into the canonical-name
    /// space; a duplicated label would collapse two classifier corners
    /// onto one rollup key. Pinned by
    /// [`tests::modality_class_as_str_labels_pairwise_distinct`].
    ///
    /// **Non-emptiness** — `!v.as_str().is_empty()` for every variant.
    /// Composes with the empty-parse-rejection law on
    /// [`Self::from_canonical_str`]: no canonical label is empty, so
    /// the parse rejects `""` by construction. Pinned by
    /// [`tests::modality_class_as_str_labels_nonempty`].
    ///
    /// **Consumers** — a fleet-wide per-classifier-corner rollup table
    /// keyed by canonical name (`HashMap<String, usize>` on a
    /// structured-log emitter that can't carry typed enum keys, a YAML
    /// attestation manifest field carrying the corner the window landed
    /// in, a dashboard column header) reads the variant's stable
    /// canonical name through one inherent call without re-deriving
    /// the 5-arm `match` at every emitter. The
    /// `axis_histogram_modality_class_classifies_all_five_corners_on_diff_line_kind`
    /// behavioral pin and the
    /// `axis_histogram_modality_class_total_classification_partitions_every_shape`
    /// total-partition witness on the histogram-side surface compose
    /// with this label projection: the five labels partition the
    /// canonical-name image of [`Self::ALL`] pointwise.
    #[must_use]
    pub const fn as_str(self) -> &'static str {
        match self {
            Self::Empty => "empty",
            Self::StrictModalStrictAntimodal => "strict-modal-strict-antimodal",
            Self::TiedModalStrictAntimodal => "tied-modal-strict-antimodal",
            Self::StrictModalTiedAntimodal => "strict-modal-tied-antimodal",
            Self::TiedModalTiedAntimodal => "tied-modal-tied-antimodal",
        }
    }

    /// Case-insensitive ASCII parse of the canonical name produced by
    /// [`Self::as_str`]. Returns [`None`] for any other input.
    ///
    /// Linear scan of [`Self::ALL`] matching pointwise via
    /// [`str::eq_ignore_ascii_case`] — structural in the same shape as
    /// the default [`ClosedAxisLabel::from_canonical_str`] impl, so the
    /// (`as_str`, `from_canonical_str`) pair on [`ModalityClass`]
    /// behaves indistinguishably from the trait pair on every
    /// [`ClosedAxisLabel`] implementor at the consumer call site (a
    /// future refactor lifting the variant-tag surface onto the trait
    /// — gated on the substrate-observation invariant relaxation — is
    /// pure trait-impl plumbing, not a semantic change). [`Option`]
    /// rather than [`Result`] because the no-canonical-label case is
    /// the only failure mode at this surface; the typed
    /// [`ParseModalityClassError`] error type is reserved for the
    /// [`FromStr`][std::str::FromStr] impl below where the
    /// [`std::error::Error`] bound forces a typed error.
    ///
    /// **Round-trip law** —
    /// `ModalityClass::from_canonical_str(v.as_str()) == Some(v)` for
    /// every `v: ModalityClass`. The pin sits on the [`Self::as_str`]
    /// doc; the law holds by construction over [`Self::ALL`].
    ///
    /// **Case insensitivity** —
    /// `ModalityClass::from_canonical_str(v.as_str().to_ascii_uppercase())
    /// == Some(v)` for every variant. Pinned by
    /// [`tests::modality_class_from_canonical_str_is_case_insensitive`].
    ///
    /// **Empty-string rejection** —
    /// `ModalityClass::from_canonical_str("") == None`. Composes with
    /// the non-emptiness law on [`Self::as_str`]: no canonical label
    /// is empty, so the parse rejects the empty string structurally.
    /// Pinned by
    /// [`tests::modality_class_from_canonical_str_rejects_empty_string`].
    #[must_use]
    pub fn from_canonical_str(s: &str) -> Option<Self> {
        Self::ALL
            .iter()
            .copied()
            .find(|v| v.as_str().eq_ignore_ascii_case(s))
    }
}

impl std::fmt::Display for ModalityClass {
    /// Operator-facing rendering of the variant tag — delegates to
    /// [`ModalityClass::as_str`] pointwise.
    ///
    /// Closes the canonical Rust stdlib
    /// (`Debug`, `Display`) duality on the variant-tag surface every
    /// stdlib-style closed enum carries: where `Debug` (derived above)
    /// renders the Rust identifier (`StrictModalStrictAntimodal`),
    /// `Display` renders the canonical operator-facing label
    /// (`strict-modal-strict-antimodal`). Lockstep with the
    /// idiom-peer pair on [`PartitionFace`] on the sibling
    /// variant-tag projection.
    ///
    /// **Round-trip with [`FromStr`][std::str::FromStr]** —
    /// `v.to_string().parse::<ModalityClass>().unwrap() == v` for every
    /// `v: ModalityClass`. Pinned by
    /// [`tests::modality_class_from_str_round_trips_through_display`].
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(self.as_str())
    }
}

/// Typed parse failure of [`<ModalityClass as
/// std::str::FromStr>::from_str`] — the offending input was not a
/// canonical name on the [`ModalityClass`] surface.
///
/// The five-variant classifier carries a small closed label set
/// (`"empty"`, `"strict-modal-strict-antimodal"`,
/// `"tied-modal-strict-antimodal"`, `"strict-modal-tied-antimodal"`,
/// `"tied-modal-tied-antimodal"`), so the parser's single rejection
/// mode is "input did not match any canonical name". This struct
/// carries the offending substring verbatim in the `label` field so a
/// downstream consumer can localize the failure to the surrounding
/// context (a YAML attestation manifest field, a structured-log
/// classifier key, a CLI argument).
///
/// `#[non_exhaustive]` to pin variant-addition forward-compatibility:
/// a future stricter parse rule (e.g. an `EmptyInput` distinguished
/// from `UnknownLabel`, a `CaseViolation` on a stricter-case parse
/// path) lands as a new variant without a SemVer-major bump. Mirrors
/// the same discipline as [`ParseAxisHistogramError`] on the
/// histogram-side parse surface.
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct ParseModalityClassError {
    /// The offending input substring, verbatim. Carries the casing the
    /// caller passed; the parse is case-insensitive on the canonical
    /// label set, so this string is whatever the caller's source
    /// emitted (an upstream serializer, an operator-typed CLI argument,
    /// a config-file field value).
    pub label: String,
}

impl std::fmt::Display for ParseModalityClassError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "unknown modality class label {:?}", self.label)
    }
}

impl std::error::Error for ParseModalityClassError {}

impl std::str::FromStr for ModalityClass {
    type Err = ParseModalityClassError;

    /// Operator-facing parse of the variant tag from the canonical
    /// label [`ModalityClass::as_str`] emits — the canonical Rust
    /// stdlib [`FromStr`][std::str::FromStr] idiom-peer of the
    /// [`Display`][std::fmt::Display] impl on the variant-tag surface.
    /// Closes the (`Display`, `FromStr`) round-trip pair every
    /// operator-facing typescape primitive carries — peer to the same
    /// pair on [`AxisHistogram`] (cce9769 / adc2450) on the histogram
    /// surface, and structurally identical to the
    /// (`as_str`, `from_canonical_str`) inherent pair above. Delegates
    /// to [`ModalityClass::from_canonical_str`] for the
    /// case-insensitive lookup, lifting the [`Option<Self>`] failure
    /// to a typed [`ParseModalityClassError`] so the
    /// [`std::error::Error`] bound is satisfied at consumer sites
    /// requiring `Result<_, Box<dyn Error>>` (`eyre::Result<_>`,
    /// structured-log error fields, deserialization error chaining).
    ///
    /// **Round-trip law** —
    /// `v.to_string().parse::<ModalityClass>().unwrap() == v` for every
    /// `v: ModalityClass`. Pinned by
    /// [`tests::modality_class_from_str_round_trips_through_display`].
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Self::from_canonical_str(s).ok_or_else(|| ParseModalityClassError {
            label: s.to_owned(),
        })
    }
}

impl serde::Serialize for ModalityClass {
    /// Serialize the variant tag as the canonical operator-facing
    /// kebab-case label [`Self::as_str`] emits — the same scalar the
    /// [`Display`][std::fmt::Display] impl writes. Routes through
    /// [`serde::Serializer::collect_str`] so the serialized
    /// representation is exactly `format!("{self}")` with no
    /// intermediate allocation on serializers that accept a streaming
    /// source (YAML, JSON, TOML emitters lower the scalar straight
    /// from the `&'static str` returned by [`Self::as_str`]).
    ///
    /// Closes the canonical (`Serialize`, `Deserialize`) serde
    /// idiom-peer of the (`Display`, `FromStr`) stdlib pair on the
    /// variant-tag surface — peer of the same lift on
    /// [`AxisHistogram`] (commit 2311303) on the histogram surface,
    /// and idiom-peer of the implicit lift on every
    /// [`crate::Format`]/[`crate::ShikumiErrorKind`]/[`crate::ConfigSourceKind`]/
    /// [`crate::FigmentSourceKind`] surface that carries
    /// `#[serde(rename_all = "kebab-case")]` on the enum derive.
    /// [`ModalityClass`] stays *off* the
    /// `#[serde(rename_all)]`-derive path so the canonical-name
    /// surface stays gated on the single inherent
    /// [`Self::as_str`] projection: a future variant-name refactor
    /// touches one site (the `match` in [`Self::as_str`]) rather than
    /// a derive attribute *and* its consumers — same forcing function
    /// the (`Display`, `FromStr`) pair already pins.
    ///
    /// **Round-trip law** — for every `v: ModalityClass`,
    /// `serde_yaml::from_str::<ModalityClass>(&serde_yaml::to_string(&v)?)? == v`
    /// and the same on `serde_json`. Pinned by
    /// [`tests::modality_class_serde_yaml_round_trips_over_every_variant`]
    /// and the `serde_json` peer test.
    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        serializer.collect_str(self)
    }
}

impl<'de> serde::Deserialize<'de> for ModalityClass {
    /// Deserialize the variant tag from the canonical operator-facing
    /// kebab-case label [`Self::as_str`] emits — the operator-facing
    /// scalar form the variant-tag surface carries on the
    /// (`Display`, `FromStr`) round-trip pair, lifted to the serde
    /// surface via [`serde::Deserializer::deserialize_str`] with a
    /// visitor whose `visit_str` lowers to
    /// [`<Self as std::str::FromStr>::from_str`] and routes any
    /// [`ParseModalityClassError`] through
    /// [`serde::de::Error::custom`].
    ///
    /// **Case insensitivity inherits from [`FromStr`]** — an
    /// operator-authored manifest field carrying the uppercase or
    /// mixed-case form of a canonical label parses on the serde side
    /// without a per-emitter case-fold, because the deserialize path
    /// lowers through [`Self::from_canonical_str`] which compares via
    /// [`str::eq_ignore_ascii_case`]. Pinned by
    /// [`tests::modality_class_serde_yaml_is_case_insensitive`].
    ///
    /// **Unknown-label rejection carries the offending label
    /// verbatim** — a manifest field carrying an unknown classifier
    /// corner name surfaces at the serde error site with the offending
    /// substring verbatim in the rendered message, lifted through
    /// [`ParseModalityClassError::label`] and the typed
    /// [`Display`][std::fmt::Display] impl on the parse error. Pinned
    /// by
    /// [`tests::modality_class_serde_yaml_unknown_label_error_carries_label_verbatim`].
    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        struct ModalityClassVisitor;

        impl serde::de::Visitor<'_> for ModalityClassVisitor {
            type Value = ModalityClass;

            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
                f.write_str(
                    "a canonical ModalityClass kebab-case label \
                     (`empty`, `strict-modal-strict-antimodal`, \
                     `tied-modal-strict-antimodal`, \
                     `strict-modal-tied-antimodal`, \
                     `tied-modal-tied-antimodal`)",
                )
            }

            fn visit_str<E: serde::de::Error>(self, v: &str) -> Result<Self::Value, E> {
                v.parse::<ModalityClass>().map_err(E::custom)
            }
        }

        deserializer.deserialize_str(ModalityClassVisitor)
    }
}

/// The **support-cardinality classification** of an [`AxisHistogram`]
/// on the `(observed, unobserved)` cell-partition surface — the
/// five-corner exhaustive partition of the support-cardinality
/// interval `[0, axis_cardinality::<A>()]`.
///
/// Returned by [`AxisHistogram::support_cardinality_class`];
/// pattern-matched exhaustively at every dashboard / attestation
/// manifest / alarm-routing site that previously composed the five
/// named boolean predicates ([`AxisHistogram::is_empty`],
/// [`AxisHistogram::has_singular_support`],
/// [`AxisHistogram::has_strict_partial_cover`],
/// [`AxisHistogram::has_singular_gap`],
/// [`AxisHistogram::is_full_cover`]) into a five-way `if` ladder. The
/// enum closes that boolean algebra at one named variant per corner,
/// so the compiler enforces exhaustiveness at every match site — a
/// future renderer landing on the typescape *cannot* silently drop
/// any of the five corners.
///
/// **Five variants, structurally exhaustive over the
/// support-cardinality interval.** Every histogram's
/// [`AxisHistogram::distinct_cells`] count `s` against the
/// [`axis_cardinality::<A>()`] bound `n` falls into exactly one
/// variant; the classification is total by construction. The
/// branching priority ([`Self::Empty`], [`Self::FullCover`],
/// [`Self::SingularSupport`], [`Self::SingularGap`],
/// [`Self::StrictPartialCover`]) makes the classification a
/// strict partition on cardinality-`>= 3` axes and reads off the
/// dominant boundary corner on the degenerate cardinality-`<= 2`
/// axes (cardinality 2 where the singular boundaries collapse onto
/// support 1 — the classification lands on [`Self::SingularSupport`]
/// by the bottom-boundary-first priority).
///
/// **Peer-bound to the boolean primitives.** The enum carries five
/// inherent `const` predicates ([`Self::is_empty`],
/// [`Self::is_singular_support`], [`Self::is_strict_partial_cover`],
/// [`Self::is_singular_gap`], [`Self::is_full_cover`]) — the
/// enum-level peers of the histogram-surface predicates of the same
/// name — so consumers holding a [`SupportCardinalityClass`] value
/// (e.g. a cached classification on a per-window summary struct)
/// read off the corner booleans without re-routing through the
/// originating histogram. The peer-equivalence laws on
/// [`Self::is_empty`] and [`Self::is_full_cover`] hold uniformly
/// across every [`ClosedAxis`] implementor; the three singular /
/// strict-partial peer laws hold uniformly on cardinality-`>= 3`
/// axes where the support-cardinality scalar is a strict five-cell
/// partition.
///
/// **Closed-axis primitive trait.** The enum carries [`Copy`] (no
/// allocation, fits in a `u8` discriminant), [`Eq`] + [`Hash`] (usable
/// as a [`std::collections::HashMap`] key for per-corner rollup
/// counters, e.g. a fleet-wide
/// `HashMap<SupportCardinalityClass, usize>` tallying how many
/// reload windows landed in each support-cardinality corner),
/// [`Ord`] + [`PartialOrd`] (usable as a
/// [`std::collections::BTreeMap`] key for deterministic per-corner
/// rollup emission — the declaration-order total order is monotone in
/// `distinct_cells()` over the five corners
/// (`Empty` < `SingularSupport` < `StrictPartialCover` <
/// `SingularGap` < `FullCover`) and matches [`Self::ALL`] position
/// pointwise, pinned by
/// [`tests::support_cardinality_class_ord_matches_all_declaration_order`];
/// the idiom-peer of the same [`Ord`] + [`PartialOrd`] derive on
/// [`SupportBoundaryDistance`] and [`SupportMagnitudeDirection`]), and
/// [`Debug`] (operator-facing summary line emission). Like
/// [`ModalityClass`], it is *not* a [`ClosedAxis`] itself — the
/// substrate-observation invariant gates [`ClosedAxis`] on
/// substrate-observation axes only.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)]
pub enum SupportCardinalityClass {
    /// **No observed cells** — `distinct_cells() == 0`. The
    /// empty-histogram boundary. Lifts [`AxisHistogram::is_empty`]
    /// to the typed variant tag.
    Empty,
    /// **Exactly one observed cell** —
    /// `distinct_cells() == 1`. The bottom singular boundary of the
    /// support-cardinality interval. Lifts
    /// [`AxisHistogram::has_singular_support`] to the typed variant
    /// tag. On a cardinality-2 axis the bottom and top singular
    /// boundaries coincide; the classification lands on
    /// [`Self::SingularSupport`] there by the bottom-boundary-first
    /// branching priority.
    SingularSupport,
    /// **At least two observed cells *and* at least two unobserved
    /// cells** — `2 <= distinct_cells() <= axis_cardinality::<A>() - 2`.
    /// The strict interior of the support-cardinality interval,
    /// strictly between the two singular boundaries. Lifts
    /// [`AxisHistogram::has_strict_partial_cover`] to the typed
    /// variant tag. Only reachable on cardinality-`>= 4` axes; the
    /// variant reads vacuously absent on cardinality-`<= 3` axes.
    StrictPartialCover,
    /// **Exactly one unobserved cell** —
    /// `distinct_cells() == axis_cardinality::<A>() - 1`. The top
    /// singular boundary of the support-cardinality interval. Lifts
    /// [`AxisHistogram::has_singular_gap`] to the typed variant
    /// tag. Only reachable on cardinality-`>= 3` axes; collapses
    /// onto [`Self::SingularSupport`] on cardinality 2 (where the
    /// bottom-boundary-first priority wins) and is unreachable on
    /// cardinality `<= 1`.
    SingularGap,
    /// **Every cell observed** —
    /// `distinct_cells() == axis_cardinality::<A>()`. The full-cover
    /// boundary. Lifts [`AxisHistogram::is_full_cover`] to the typed
    /// variant tag.
    FullCover,
}

impl SupportCardinalityClass {
    /// Every [`SupportCardinalityClass`] variant, in declaration
    /// order: `Empty`, `SingularSupport`, `StrictPartialCover`,
    /// `SingularGap`, `FullCover`. Peer to
    /// [`ModalityClass::ALL`] on the sibling typed classifier.
    /// Length 5 — pinned by
    /// [`tests::support_cardinality_class_all_has_five_entries`].
    pub const ALL: &'static [Self] = &[
        Self::Empty,
        Self::SingularSupport,
        Self::StrictPartialCover,
        Self::SingularGap,
        Self::FullCover,
    ];

    /// `true` exactly on [`Self::Empty`] — the enum-level peer of
    /// [`AxisHistogram::is_empty`] projected from the variant tag.
    #[must_use]
    pub const fn is_empty(self) -> bool {
        matches!(self, Self::Empty)
    }

    /// `true` exactly on [`Self::SingularSupport`] — the enum-level
    /// peer of [`AxisHistogram::has_singular_support`] projected
    /// from the variant tag. Agrees with the histogram-surface
    /// predicate pointwise on cardinality-`>= 3` axes; on
    /// cardinality 2, the histogram-surface predicate also reads
    /// `true` on [`Self::SingularGap`] (the cardinality-2
    /// dual-singular collapse).
    #[must_use]
    pub const fn is_singular_support(self) -> bool {
        matches!(self, Self::SingularSupport)
    }

    /// `true` exactly on [`Self::StrictPartialCover`] — the
    /// enum-level peer of [`AxisHistogram::has_strict_partial_cover`]
    /// projected from the variant tag. Agrees with the
    /// histogram-surface predicate pointwise on every axis.
    #[must_use]
    pub const fn is_strict_partial_cover(self) -> bool {
        matches!(self, Self::StrictPartialCover)
    }

    /// `true` exactly on [`Self::SingularGap`] — the enum-level
    /// peer of [`AxisHistogram::has_singular_gap`] projected from
    /// the variant tag. Agrees with the histogram-surface predicate
    /// pointwise on cardinality-`>= 3` axes; on cardinality 2, the
    /// histogram-surface predicate also reads `true` on
    /// [`Self::SingularSupport`] (the cardinality-2 dual-singular
    /// collapse).
    #[must_use]
    pub const fn is_singular_gap(self) -> bool {
        matches!(self, Self::SingularGap)
    }

    /// `true` exactly on [`Self::FullCover`] — the enum-level peer
    /// of [`AxisHistogram::is_full_cover`] projected from the
    /// variant tag.
    #[must_use]
    pub const fn is_full_cover(self) -> bool {
        matches!(self, Self::FullCover)
    }

    /// `true` exactly on the three middle variants
    /// ([`Self::SingularSupport`], [`Self::StrictPartialCover`],
    /// [`Self::SingularGap`]) — the **partial-cover compound
    /// predicate** on the typed-class surface. The enum-level peer
    /// of [`AxisHistogram::has_partial_cover`]: lifts the
    /// "some but not all observed" middle leg of the support-
    /// cardinality five-corner partition to one `const` projection
    /// on the variant tag.
    ///
    /// Pointwise equal to four documented surface forms — each
    /// names the same compound differently:
    /// - `!self.is_empty() && !self.is_full_cover()` (the
    ///   complement-of-boundaries form on the named single-variant
    ///   peers).
    /// - `self.is_singular_support() || self.is_strict_partial_cover()
    ///   || self.is_singular_gap()` (the union-of-middle-variants
    ///   form on the three named single-variant peers).
    /// - `matches!(self, Self::SingularSupport | Self::StrictPartialCover
    ///   | Self::SingularGap)` (the structural variant-tag form).
    /// - The class-side projection of
    ///   [`AxisHistogram::has_partial_cover`]:
    ///   `hist.has_partial_cover() ==
    ///    hist.support_cardinality_class().is_partial_cover()` —
    ///   the cross-surface bridge law pinned trait-uniformly across
    ///   every [`ClosedAxis`] implementor.
    ///
    /// Before this lift, every consumer holding a cached
    /// [`SupportCardinalityClass`] (e.g. on a per-window summary
    /// struct stored alongside the originating
    /// [`AxisHistogram`]) and asking the "neither blank nor
    /// exhaustive" question routed through the disjunction of the
    /// three middle predicates, the conjunction of the two negated
    /// boundary predicates, or a re-derived match on the variant
    /// tag — and the original
    /// [`AxisHistogram::has_partial_cover`] histogram-surface peer
    /// was unreachable on the cached class without re-routing
    /// through the originating histogram. The lift names the
    /// middle leg directly at one `const` projection on the class
    /// surface, and the (`is_empty`, `is_partial_cover`,
    /// `is_full_cover`) trichotomy becomes a structural partition
    /// on the typed-class surface peering with the histogram-side
    /// (`is_empty`, `has_partial_cover`, `is_full_cover`)
    /// trichotomy that
    /// [`tests::axis_histogram_coverage_trichotomy_partitions_every_histogram_for_every_closed_axis_implementor`]
    /// already pins.
    ///
    /// **Companion invariants** with [`Self::is_empty`],
    /// [`Self::is_full_cover`], [`Self::is_singular_support`],
    /// [`Self::is_strict_partial_cover`], and
    /// [`Self::is_singular_gap`]:
    /// - `is_partial_cover() ⇔ !is_empty() && !is_full_cover()` —
    ///   the defining equivalence on the two-corner boundary
    ///   complement (pinned by
    ///   [`tests::support_cardinality_class_is_partial_cover_equals_not_empty_and_not_full_cover`]).
    /// - `is_partial_cover() ⇔ is_singular_support()
    ///    || is_strict_partial_cover() || is_singular_gap()` —
    ///   the union-of-middle-variants form on the three named
    ///   single-variant peers (pinned by
    ///   [`tests::support_cardinality_class_is_partial_cover_equals_three_middle_variant_disjunction`]).
    /// - `(is_empty, is_partial_cover, is_full_cover)` is a strict
    ///   partition on every variant: pairwise disjoint *and*
    ///   jointly exhaustive. Stated as
    ///   `u8::from(is_empty()) + u8::from(is_partial_cover()) + u8::from(is_full_cover()) == 1`
    ///   — exactly one corner fires uniformly across the five
    ///   variants (pinned by
    ///   [`tests::support_cardinality_class_trichotomy_partitions_every_variant`]).
    ///   The class-side peer of the histogram-side trichotomy
    ///   already pinned on every implementor by
    ///   [`tests::axis_histogram_coverage_trichotomy_partitions_every_histogram_for_every_closed_axis_implementor`].
    /// - Implication chain over the three middle variants:
    ///   `is_singular_support() ⇒ is_partial_cover()`,
    ///   `is_strict_partial_cover() ⇒ is_partial_cover()`, and
    ///   `is_singular_gap() ⇒ is_partial_cover()` (pinned by
    ///   [`tests::support_cardinality_class_three_middle_variant_predicates_imply_is_partial_cover`]).
    ///
    /// **Cross-surface bridge law** —
    /// `hist.has_partial_cover() ==
    ///  hist.support_cardinality_class().is_partial_cover()` for
    /// every `hist: AxisHistogram<A>` on every [`ClosedAxis`]
    /// implementor, pinned trait-uniformly through the
    /// `for_each_closed_axis_implementor!` macro by
    /// [`tests::axis_histogram_support_cardinality_class_is_partial_cover_agrees_with_histogram_has_partial_cover_for_every_closed_axis_implementor`].
    /// The bridge closes the (class, histogram) duality on the
    /// partial-cover middle leg — peer to the
    /// `is_empty` / `is_full_cover` bridges already pinned on the
    /// two boundary corners.
    ///
    /// **Empty-boundary convention** — reads `false` on
    /// [`Self::Empty`] (matching the same convention every
    /// histogram-surface boundary predicate carries on the empty
    /// histogram: the empty histogram surfaces `false` on the
    /// histogram-side `has_partial_cover` peer pointwise).
    ///
    /// **Full-cover convention** — reads `false` on
    /// [`Self::FullCover`] (matching the same convention: the
    /// full-cover histogram surfaces `false` on the histogram-side
    /// `has_partial_cover` peer pointwise).
    #[must_use]
    pub const fn is_partial_cover(self) -> bool {
        matches!(
            self,
            Self::SingularSupport | Self::StrictPartialCover | Self::SingularGap,
        )
    }

    /// `true` exactly on the two boundary corners ([`Self::Empty`]
    /// and [`Self::FullCover`]) — the **boundary compound predicate**
    /// on the typed-class surface. The structural dual of
    /// [`Self::is_partial_cover`]: lifts the *"neither some-but-not-all
    /// observed"* compound — i.e. the *"observation universe is either
    /// fully blank or fully exhaustive"* compound — to one `const`
    /// projection on the variant tag.
    ///
    /// Pointwise equal to three documented surface forms — each
    /// names the same compound differently:
    /// - `self.is_empty() || self.is_full_cover()` (the
    ///   union-of-boundary-variants form on the two named single-
    ///   variant peers).
    /// - `!self.is_partial_cover()` (the strict-complement form on
    ///   the named middle compound — `is_boundary` and
    ///   `is_partial_cover` form a strict bipartition of the five-
    ///   corner surface).
    /// - `matches!(self, Self::Empty | Self::FullCover)` (the
    ///   structural variant-tag form).
    ///
    /// Before this lift, every consumer holding a cached
    /// [`SupportCardinalityClass`] (e.g. on a per-window summary
    /// struct stored alongside the originating
    /// [`AxisHistogram`]) and asking the "fully blank or fully
    /// exhaustive" question routed through the disjunction of the
    /// two boundary predicates, the negation of the middle compound,
    /// or a re-derived match on the variant tag. The lift names the
    /// boundary leg directly at one `const` projection on the class
    /// surface, completing the (`is_boundary`, `is_partial_cover`)
    /// **strict bipartition** of the five-corner support-cardinality
    /// surface — every variant lands in exactly one of the two
    /// compounds.
    ///
    /// **Companion invariants** with [`Self::is_empty`],
    /// [`Self::is_full_cover`], and [`Self::is_partial_cover`]:
    /// - `is_boundary() ⇔ is_empty() || is_full_cover()` — the
    ///   defining equivalence on the two-corner boundary union
    ///   (pinned by
    ///   [`tests::support_cardinality_class_is_boundary_equals_is_empty_or_is_full_cover`]).
    /// - `is_boundary() ⇔ !is_partial_cover()` — the strict-
    ///   complement equivalence on the middle compound (pinned by
    ///   [`tests::support_cardinality_class_is_boundary_equals_complement_of_is_partial_cover`]).
    /// - `(is_boundary, is_partial_cover)` is a strict bipartition
    ///   on every variant: pairwise disjoint *and* jointly
    ///   exhaustive. Stated as
    ///   `u8::from(is_boundary()) + u8::from(is_partial_cover()) == 1`
    ///   — exactly one compound fires uniformly across the five
    ///   variants (pinned by
    ///   [`tests::support_cardinality_class_is_boundary_and_is_partial_cover_form_strict_bipartition`]).
    /// - Implication chain over the two boundary single-variant
    ///   predicates: `is_empty() ⇒ is_boundary()` and
    ///   `is_full_cover() ⇒ is_boundary()` (pinned by
    ///   [`tests::support_cardinality_class_two_boundary_variant_predicates_imply_is_boundary`]).
    ///
    /// **Cross-surface bridge law** —
    /// `(hist.is_empty() || hist.is_full_cover()) ==
    ///  hist.support_cardinality_class().is_boundary()` for every
    /// `hist: AxisHistogram<A>` on every [`ClosedAxis`] implementor,
    /// pinned trait-uniformly through the
    /// `for_each_closed_axis_implementor!` macro by
    /// [`tests::axis_histogram_support_cardinality_class_is_boundary_agrees_with_histogram_is_empty_or_is_full_cover_for_every_closed_axis_implementor`].
    /// The bridge closes the (class, histogram) duality on the
    /// boundary leg — peer to the `is_partial_cover` bridge already
    /// pinned on the middle leg, and the
    /// `(is_empty, is_partial_cover, is_full_cover)` trichotomy
    /// already pinned on the histogram surface.
    #[must_use]
    pub const fn is_boundary(self) -> bool {
        matches!(self, Self::Empty | Self::FullCover)
    }

    /// `true` exactly on the two singular corners
    /// ([`Self::SingularSupport`] and [`Self::SingularGap`]) — the
    /// **singular compound predicate** on the typed-class surface.
    /// Names the *"exactly-one-cell-off-boundary"* compound — the
    /// pair of class variants whose support cardinality lies
    /// exactly one cell away from a boundary corner (support 1, one
    /// cell off [`Self::Empty`]; support `axis_cardinality - 1`,
    /// one cell off [`Self::FullCover`]).
    ///
    /// Pointwise equal to three documented surface forms — each
    /// names the same compound differently:
    /// - `self.is_singular_support() || self.is_singular_gap()` (the
    ///   union-of-singular-variants form on the two named single-
    ///   variant peers).
    /// - `self.is_partial_cover() && !self.is_strict_partial_cover()`
    ///   (the partial-cover-minus-strict-interior form: the singular
    ///   compound is exactly the partial-cover middle leg with the
    ///   strict-interior `StrictPartialCover` variant excised).
    /// - `matches!(self, Self::SingularSupport | Self::SingularGap)`
    ///   (the structural variant-tag form).
    ///
    /// Before this lift, every consumer holding a cached
    /// [`SupportCardinalityClass`] (e.g. on a per-window summary
    /// struct stored alongside the originating
    /// [`AxisHistogram`]) and asking the "did the chain land
    /// exactly one cell off the boundary?" question routed through
    /// the disjunction of the two singular predicates, the
    /// difference of two named compounds, or a re-derived match on
    /// the variant tag. The lift names the
    /// *exactly-one-cell-off-boundary* compound directly at one
    /// `const` projection on the class surface, closing the
    /// (`is_boundary`, `is_singular`, `is_strict_partial_cover`)
    /// **strict ternary partition** of the five-corner support-
    /// cardinality surface — every variant lands in exactly one of
    /// the three compounds:
    /// - `is_boundary`: `Empty | FullCover` (the two extremal
    ///   corners — distance 0 from boundary).
    /// - `is_singular`: `SingularSupport | SingularGap` (the two
    ///   near-boundary cells — distance 1 from boundary).
    /// - `is_strict_partial_cover`: `StrictPartialCover` (the strict
    ///   interior — distance >= 2 from each boundary on
    ///   cardinality-`>= 4` axes).
    ///
    /// The ternary partition strictly refines the
    /// (`is_boundary`, `is_partial_cover`) bipartition: `is_partial_cover`
    /// decomposes into `is_singular ∪ is_strict_partial_cover`.
    ///
    /// **Companion invariants** with [`Self::is_boundary`],
    /// [`Self::is_partial_cover`], [`Self::is_singular_support`],
    /// [`Self::is_singular_gap`], and [`Self::is_strict_partial_cover`]:
    /// - `is_singular() ⇔ is_singular_support() || is_singular_gap()`
    ///   — the defining equivalence on the union of the two named
    ///   single-variant peers (pinned by
    ///   [`tests::support_cardinality_class_is_singular_equals_singular_support_or_singular_gap`]).
    /// - `is_singular()` ⇒ `is_partial_cover()` — every singular
    ///   variant lands in the partial-cover middle leg (the
    ///   ternary partition refines the bipartition; pinned by
    ///   [`tests::support_cardinality_class_is_singular_implies_is_partial_cover`]).
    /// - `is_singular()` ⇒ `!is_boundary()` — the two singular
    ///   cells are strictly off the boundary corners (pinned by
    ///   [`tests::support_cardinality_class_is_singular_implies_not_is_boundary`]).
    /// - `(is_boundary, is_singular, is_strict_partial_cover)` is a
    ///   strict ternary partition on every variant: pairwise
    ///   disjoint *and* jointly exhaustive. Stated as the sum
    ///   `u8::from(is_boundary()) + u8::from(is_singular()) + u8::from(is_strict_partial_cover()) == 1`
    ///   — exactly one compound fires uniformly across the five
    ///   variants (pinned by
    ///   [`tests::support_cardinality_class_is_boundary_is_singular_is_strict_partial_cover_form_strict_ternary_partition`]).
    /// - Implication chain over the two singular single-variant
    ///   predicates: `is_singular_support() ⇒ is_singular()` and
    ///   `is_singular_gap() ⇒ is_singular()` (pinned by
    ///   [`tests::support_cardinality_class_two_singular_variant_predicates_imply_is_singular`]).
    ///
    /// **Cross-surface bridge law** —
    /// `(hist.has_singular_support() || hist.has_singular_gap()) ==
    ///  hist.support_cardinality_class().is_singular()` for every
    /// `hist: AxisHistogram<A>` on every [`ClosedAxis`] implementor,
    /// pinned trait-uniformly through the
    /// `for_each_closed_axis_implementor!` macro by
    /// [`tests::axis_histogram_support_cardinality_class_is_singular_agrees_with_histogram_has_singular_support_or_has_singular_gap_for_every_closed_axis_implementor`].
    /// The bridge closes the (class, histogram) duality on the
    /// singular near-boundary leg — peer to the `is_boundary` /
    /// `is_partial_cover` bridges already pinned trait-uniformly.
    ///
    /// **Cardinality-2 collapse.** On cardinality-2 axes (e.g.
    /// [`crate::PartitionFace`], [`crate::SecretRefShape`]) the two
    /// singular boundaries [`Self::SingularSupport`] (support 1) and
    /// [`Self::SingularGap`] (support `axis_cardinality - 1` = 1)
    /// share the same support cardinality; the projection
    /// [`AxisHistogram::support_cardinality_class`] lands on
    /// [`Self::SingularSupport`] by the bottom-boundary-first
    /// priority, and `is_singular()` reads `true` on that variant.
    /// The histogram-side disjunction
    /// `has_singular_support() || has_singular_gap()` also reads
    /// `true` (both predicates fire under the dual-singular
    /// collapse), so the cross-surface bridge holds pointwise on
    /// cardinality-2 axes by construction.
    #[must_use]
    pub const fn is_singular(self) -> bool {
        matches!(self, Self::SingularSupport | Self::SingularGap)
    }

    /// `true` exactly on the two low-support corners ([`Self::Empty`]
    /// and [`Self::SingularSupport`]) — the **low-support compound
    /// predicate** on the typed-class surface. Names the *"support
    /// magnitude at most one cell"* compound — the pair of class
    /// variants whose support cardinality lies at the bottom of the
    /// support-cardinality interval (support 0 on [`Self::Empty`];
    /// support 1 on [`Self::SingularSupport`]).
    ///
    /// Pointwise equal to three documented surface forms — each
    /// names the same compound differently:
    /// - `self.is_empty() || self.is_singular_support()` (the
    ///   union-of-low-variants form on the two named single-variant
    ///   peers).
    /// - `matches!(self, Self::Empty | Self::SingularSupport)` (the
    ///   structural variant-tag form).
    /// - The bottom half of the (`is_boundary`, `is_singular`)
    ///   decomposition: `is_low_support` is the variant-tag pair that
    ///   the (`boundary` ∩ bottom-corner, `singular` ∩ bottom-corner)
    ///   pair fuses into when projected by support magnitude.
    ///
    /// Closes the (`is_low_support`, `is_strict_partial_cover`,
    /// `is_high_support`) **strict ternary partition** of the five-
    /// corner support-cardinality surface by support magnitude
    /// direction — every variant lands in exactly one of the three
    /// compounds:
    /// - `is_low_support`: `Empty | SingularSupport` (support 0 or 1
    ///   — the bottom of the support-cardinality interval).
    /// - `is_strict_partial_cover`: `StrictPartialCover` (support
    ///   2..=`axis_cardinality - 2` — the strict interior on
    ///   cardinality-`>= 4` axes).
    /// - `is_high_support`: `SingularGap | FullCover` (support
    ///   `axis_cardinality - 1` or `axis_cardinality` — the top of
    ///   the support-cardinality interval).
    ///
    /// This second strict ternary partition is **orthogonal** to the
    /// (`is_boundary`, `is_singular`, `is_strict_partial_cover`)
    /// ternary partition by distance from boundary — both share the
    /// `is_strict_partial_cover` middle leg but split the four
    /// non-interior corners on different axes:
    /// - distance partition: bottom-pair `{Empty, FullCover}`,
    ///   middle-pair `{SingularSupport, SingularGap}`.
    /// - magnitude partition: bottom-pair `{Empty, SingularSupport}`,
    ///   top-pair `{SingularGap, FullCover}`.
    ///
    /// The two partitions cross to recover the four named single-
    /// variant peers on the non-interior corners:
    /// `is_low_support ∩ is_boundary = is_empty`,
    /// `is_low_support ∩ is_singular = is_singular_support`,
    /// `is_high_support ∩ is_singular = is_singular_gap`,
    /// `is_high_support ∩ is_boundary = is_full_cover`.
    ///
    /// **Companion invariants** with [`Self::is_high_support`],
    /// [`Self::is_strict_partial_cover`], [`Self::is_empty`], and
    /// [`Self::is_singular_support`]:
    /// - `is_low_support() ⇔ is_empty() || is_singular_support()` —
    ///   the defining equivalence on the union of the two named
    ///   single-variant peers (pinned by
    ///   [`tests::support_cardinality_class_is_low_support_equals_empty_or_singular_support`]).
    /// - `is_low_support()` and `is_high_support()` are disjoint —
    ///   no variant fires both (pinned by
    ///   [`tests::support_cardinality_class_is_low_support_and_is_high_support_are_disjoint`]).
    /// - `(is_low_support, is_strict_partial_cover, is_high_support)`
    ///   is a strict ternary partition on every variant: pairwise
    ///   disjoint *and* jointly exhaustive. Stated as
    ///   `u8::from(is_low_support()) + u8::from(is_strict_partial_cover()) + u8::from(is_high_support()) == 1`
    ///   — exactly one compound fires uniformly across the five
    ///   variants (pinned by
    ///   [`tests::support_cardinality_class_is_low_support_is_strict_partial_cover_is_high_support_form_strict_ternary_partition`]).
    /// - Implication chain over the two low single-variant
    ///   predicates: `is_empty() ⇒ is_low_support()` and
    ///   `is_singular_support() ⇒ is_low_support()` (pinned by
    ///   [`tests::support_cardinality_class_two_low_variant_predicates_imply_is_low_support`]).
    ///
    /// **Cross-surface bridge law** —
    /// `(hist.is_empty() || hist.has_singular_support()) ==
    ///  hist.support_cardinality_class().is_low_support()` for every
    /// `hist: AxisHistogram<A>` on every [`ClosedAxis`] implementor,
    /// pinned trait-uniformly through the
    /// `for_each_closed_axis_implementor!` macro by
    /// [`tests::axis_histogram_support_cardinality_class_is_low_support_agrees_with_histogram_is_empty_or_has_singular_support_for_every_closed_axis_implementor`].
    /// The bridge closes the (class, histogram) duality on the
    /// magnitude-direction ternary partition's bottom leg — peer to
    /// the `is_boundary` / `is_singular` / `is_partial_cover` bridges
    /// already pinned on the distance-from-boundary partition's three
    /// legs, and to the [`Self::is_high_support`] bridge pinned on the
    /// magnitude partition's mirror top leg.
    ///
    /// **Cardinality-2 collapse.** On cardinality-2 axes (e.g.
    /// [`crate::PartitionFace`], [`crate::SecretRefShape`]) the
    /// histogram-side disjunction `is_empty() || has_singular_support()`
    /// reads `true` on the empty histogram (`is_empty()` fires) and on
    /// every singleton histogram (`has_singular_support()` fires under
    /// the dual-singular collapse where the lone observed cell also
    /// witnesses the lone unobserved cell). The class-side
    /// projection lands the empty histogram on [`Self::Empty`] and the
    /// singleton on [`Self::SingularSupport`] (bottom-boundary-first
    /// priority resolves the cardinality-2 collapse), and
    /// `is_low_support()` reads `true` on both variants. The bridge
    /// therefore holds pointwise on cardinality-2 axes by construction
    /// — the dual-singular collapse is benign on the bottom leg
    /// because `has_singular_support()` already absorbs the collapse.
    #[must_use]
    pub const fn is_low_support(self) -> bool {
        matches!(self, Self::Empty | Self::SingularSupport)
    }

    /// `true` exactly on the two high-support corners
    /// ([`Self::SingularGap`] and [`Self::FullCover`]) — the **high-
    /// support compound predicate** on the typed-class surface. The
    /// mirror peer of [`Self::is_low_support`] across the
    /// [`Self::StrictPartialCover`] middle leg: names the *"support
    /// magnitude at least `axis_cardinality - 1`"* compound — the
    /// pair of class variants whose support cardinality lies at the
    /// top of the support-cardinality interval (support
    /// `axis_cardinality - 1` on [`Self::SingularGap`]; support
    /// `axis_cardinality` on [`Self::FullCover`]).
    ///
    /// Pointwise equal to three documented surface forms — each
    /// names the same compound differently:
    /// - `self.is_singular_gap() || self.is_full_cover()` (the
    ///   union-of-high-variants form on the two named single-variant
    ///   peers).
    /// - `matches!(self, Self::SingularGap | Self::FullCover)` (the
    ///   structural variant-tag form).
    /// - The top half of the (`is_boundary`, `is_singular`)
    ///   decomposition: `is_high_support` is the variant-tag pair
    ///   that the (`boundary` ∩ top-corner, `singular` ∩ top-corner)
    ///   pair fuses into when projected by support magnitude.
    ///
    /// Closes the (`is_low_support`, `is_strict_partial_cover`,
    /// `is_high_support`) **strict ternary partition** of the five-
    /// corner support-cardinality surface by support magnitude
    /// direction — see [`Self::is_low_support`] for the full
    /// orthogonal-partition account.
    ///
    /// **Companion invariants** with [`Self::is_low_support`],
    /// [`Self::is_strict_partial_cover`], [`Self::is_singular_gap`],
    /// and [`Self::is_full_cover`]:
    /// - `is_high_support() ⇔ is_singular_gap() || is_full_cover()`
    ///   — the defining equivalence on the union of the two named
    ///   single-variant peers (pinned by
    ///   [`tests::support_cardinality_class_is_high_support_equals_singular_gap_or_full_cover`]).
    /// - `is_low_support()` and `is_high_support()` are disjoint —
    ///   no variant fires both (pinned by
    ///   [`tests::support_cardinality_class_is_low_support_and_is_high_support_are_disjoint`]).
    /// - `(is_low_support, is_strict_partial_cover, is_high_support)`
    ///   is a strict ternary partition on every variant: pairwise
    ///   disjoint *and* jointly exhaustive (pinned by
    ///   [`tests::support_cardinality_class_is_low_support_is_strict_partial_cover_is_high_support_form_strict_ternary_partition`]).
    /// - Implication chain over the two high single-variant
    ///   predicates: `is_singular_gap() ⇒ is_high_support()` and
    ///   `is_full_cover() ⇒ is_high_support()` (pinned by
    ///   [`tests::support_cardinality_class_two_high_variant_predicates_imply_is_high_support`]).
    ///
    /// **Cross-surface bridge law** —
    /// `(hist.is_full_cover() || (hist.has_singular_gap() && !hist.has_singular_support())) ==
    ///  hist.support_cardinality_class().is_high_support()` for every
    /// `hist: AxisHistogram<A>` on every [`ClosedAxis`] implementor,
    /// pinned trait-uniformly through the
    /// `for_each_closed_axis_implementor!` macro by
    /// [`tests::axis_histogram_support_cardinality_class_is_high_support_agrees_with_histogram_is_full_cover_or_strict_singular_gap_for_every_closed_axis_implementor`].
    /// The bridge closes the (class, histogram) duality on the
    /// magnitude-direction ternary partition's top leg — mirror peer
    /// of the [`Self::is_low_support`] bridge across the
    /// [`Self::StrictPartialCover`] middle leg.
    ///
    /// **Cardinality-2 collapse — strict-singular-gap form.** On
    /// cardinality-2 axes (e.g. [`crate::PartitionFace`],
    /// [`crate::SecretRefShape`]) the histogram-side predicate
    /// `has_singular_gap()` fires spuriously on every singleton
    /// histogram (the lone unobserved cell witnesses the singular gap
    /// while the lone observed cell witnesses the singular support
    /// simultaneously — the dual-singular collapse). The class-side
    /// projection lands every cardinality-2 singleton on
    /// [`Self::SingularSupport`] (bottom-boundary-first priority),
    /// where `is_high_support()` reads `false`. The bridge therefore
    /// excises the collapse by requiring *strict* singular gap on the
    /// histogram side: `has_singular_gap() && !has_singular_support()`
    /// rules out the cardinality-2 singleton case (where both
    /// histogram-side predicates fire), and the bridge holds
    /// pointwise on cardinality-2 axes by construction. On
    /// cardinality-`>= 3` axes the two histogram-side predicates are
    /// disjoint by construction (a histogram cannot simultaneously
    /// have exactly one observed cell and exactly one unobserved cell
    /// when the axis has ≥ 3 cells), so the `!has_singular_support()`
    /// clause is vacuous and the bridge reduces pointwise to
    /// `is_full_cover() || has_singular_gap()` on those axes — the
    /// expected mirror peer of the `is_low_support` bridge.
    #[must_use]
    pub const fn is_high_support(self) -> bool {
        matches!(self, Self::SingularGap | Self::FullCover)
    }

    /// Project this variant onto its **distance-from-boundary** leg of
    /// the strict ternary partition (`is_boundary`, `is_singular`,
    /// `is_strict_partial_cover`) — the typed three-bucket lift of the
    /// (`is_boundary`, `is_singular`, `is_strict_partial_cover`) leg-
    /// predicate trio on [`Self`] to a single closed enum whose
    /// exhaustiveness is checked by the compiler at every `match` site.
    ///
    /// Variant-tag mapping (closed and exhaustive over the five
    /// [`Self`] variants):
    /// - [`Self::Empty`] / [`Self::FullCover`] →
    ///   [`SupportBoundaryDistance::Boundary`] (the two boundary
    ///   corners — distance 0 from the support-cardinality boundary).
    /// - [`Self::SingularSupport`] / [`Self::SingularGap`] →
    ///   [`SupportBoundaryDistance::Singular`] (the two singular near-
    ///   boundary corners — distance 1 from the boundary).
    /// - [`Self::StrictPartialCover`] →
    ///   [`SupportBoundaryDistance::StrictInterior`] (the strict
    ///   interior — distance `>= 2` from each boundary, only
    ///   reachable on cardinality-`>= 4` axes).
    ///
    /// **Leg-predicate bridge laws** — for every variant `c`:
    /// - `c.support_boundary_distance().is_boundary() == c.is_boundary()`,
    /// - `c.support_boundary_distance().is_singular() == c.is_singular()`,
    /// - `c.support_boundary_distance().is_strict_interior() ==
    ///    c.is_strict_partial_cover()`.
    ///
    /// All three pinned pointwise across [`Self::ALL`] by
    /// [`tests::support_cardinality_class_support_boundary_distance_pointwise_matches_leg_predicates`].
    ///
    /// Before this lift, every consumer dispatching on the
    /// distance-from-boundary ternary held a [`Self`] value and either
    /// wrote a three-way `if` ladder over the three leg predicates
    /// (`if c.is_boundary() { … } else if c.is_singular() { … } else { … }`
    /// — three method calls, ordering matters, a future fourth leg
    /// would silently drop), or open-coded the same three-way `match`
    /// on the five variants (`Empty | FullCover => …, SingularSupport
    /// | SingularGap => …, StrictPartialCover => …` — five variants
    /// per arm, every match site re-derives the partition manually).
    /// Collapsed to one inherent call returning a closed three-variant
    /// enum whose exhaustiveness the compiler enforces at every
    /// `match` site — a future renderer landing on the typescape and
    /// dispatching on the distance-from-boundary partition cannot
    /// silently drop a leg.
    ///
    /// Peer to the existing leg-predicate trio on the same scalar; the
    /// magnitude-direction partition (`is_low_support`,
    /// `is_strict_partial_cover`, `is_high_support`) is the orthogonal
    /// ternary on the same surface and will admit the same kind of
    /// typed projection in a future lift.
    #[must_use]
    pub const fn support_boundary_distance(self) -> SupportBoundaryDistance {
        match self {
            Self::Empty | Self::FullCover => SupportBoundaryDistance::Boundary,
            Self::SingularSupport | Self::SingularGap => SupportBoundaryDistance::Singular,
            Self::StrictPartialCover => SupportBoundaryDistance::StrictInterior,
        }
    }

    /// Project this variant onto its **support-magnitude direction** leg
    /// of the strict ternary partition (`is_low_support`,
    /// `is_strict_partial_cover`, `is_high_support`) — the typed three-
    /// bucket lift of the (`is_low_support`, `is_strict_partial_cover`,
    /// `is_high_support`) leg-predicate trio on [`Self`] to a single
    /// closed enum whose exhaustiveness is checked by the compiler at
    /// every `match` site. The mirror peer of
    /// [`Self::support_boundary_distance`] across the
    /// [`Self::StrictPartialCover`] middle leg: both projections share
    /// the strict-interior bucket but split the four non-interior
    /// corners on orthogonal axes.
    ///
    /// Variant-tag mapping (closed and exhaustive over the five
    /// [`Self`] variants):
    /// - [`Self::Empty`] / [`Self::SingularSupport`] →
    ///   [`SupportMagnitudeDirection::Low`] (support magnitude at most
    ///   one cell — the bottom of the support-cardinality interval).
    /// - [`Self::StrictPartialCover`] →
    ///   [`SupportMagnitudeDirection::StrictInterior`] (the strict
    ///   interior — support 2..=`axis_cardinality - 2`, only reachable
    ///   on cardinality-`>= 4` axes; the shared middle leg with
    ///   [`Self::support_boundary_distance`]).
    /// - [`Self::SingularGap`] / [`Self::FullCover`] →
    ///   [`SupportMagnitudeDirection::High`] (support magnitude at
    ///   least `axis_cardinality - 1` — the top of the support-
    ///   cardinality interval).
    ///
    /// **Leg-predicate bridge laws** — for every variant `c`:
    /// - `c.support_magnitude_direction().is_low() == c.is_low_support()`,
    /// - `c.support_magnitude_direction().is_strict_interior() ==
    ///    c.is_strict_partial_cover()`,
    /// - `c.support_magnitude_direction().is_high() == c.is_high_support()`.
    ///
    /// All three pinned pointwise across [`Self::ALL`] by
    /// [`tests::support_cardinality_class_support_magnitude_direction_pointwise_matches_leg_predicates`].
    ///
    /// Peer to [`Self::support_boundary_distance`] on the same scalar —
    /// the typescape now carries two orthogonal typed-bucket projections
    /// of [`Self`] in lockstep, both sharing the strict-interior middle
    /// leg ([`Self::StrictPartialCover`]) and splitting the four non-
    /// interior corners on orthogonal axes (distance from boundary vs.
    /// support magnitude direction).
    #[must_use]
    pub const fn support_magnitude_direction(self) -> SupportMagnitudeDirection {
        match self {
            Self::Empty | Self::SingularSupport => SupportMagnitudeDirection::Low,
            Self::StrictPartialCover => SupportMagnitudeDirection::StrictInterior,
            Self::SingularGap | Self::FullCover => SupportMagnitudeDirection::High,
        }
    }

    /// Canonical operator-facing kebab-case label for the variant
    /// tag — `"empty"`, `"singular-support"`,
    /// `"strict-partial-cover"`, `"singular-gap"`, `"full-cover"`.
    /// Idiom-peer of [`ModalityClass::as_str`] on the sibling typed
    /// classifier.
    ///
    /// **Round-trip law** —
    /// `SupportCardinalityClass::from_canonical_str(v.as_str()) ==
    /// Some(v)` for every `v: SupportCardinalityClass`. Pinned by
    /// [`tests::support_cardinality_class_as_str_round_trips_via_from_canonical_str`].
    #[must_use]
    pub const fn as_str(self) -> &'static str {
        match self {
            Self::Empty => "empty",
            Self::SingularSupport => "singular-support",
            Self::StrictPartialCover => "strict-partial-cover",
            Self::SingularGap => "singular-gap",
            Self::FullCover => "full-cover",
        }
    }

    /// Case-insensitive ASCII parse of the canonical name produced
    /// by [`Self::as_str`]. Returns [`None`] for any other input.
    /// Idiom-peer of [`ModalityClass::from_canonical_str`].
    #[must_use]
    pub fn from_canonical_str(s: &str) -> Option<Self> {
        Self::ALL
            .iter()
            .copied()
            .find(|v| v.as_str().eq_ignore_ascii_case(s))
    }
}

impl std::fmt::Display for SupportCardinalityClass {
    /// Operator-facing rendering — delegates to
    /// [`SupportCardinalityClass::as_str`] pointwise. Closes the
    /// canonical `(Debug, Display)` duality every stdlib-style closed
    /// enum carries; idiom-peer of the same impl on
    /// [`ModalityClass`].
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(self.as_str())
    }
}

/// Typed parse failure of
/// [`<SupportCardinalityClass as std::str::FromStr>::from_str`] —
/// the offending input was not a canonical name on the
/// [`SupportCardinalityClass`] surface. Carries the offending
/// substring verbatim in the `label` field. Idiom-peer of
/// [`ParseModalityClassError`] on the sibling typed classifier.
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct ParseSupportCardinalityClassError {
    /// The offending input substring, verbatim.
    pub label: String,
}

impl std::fmt::Display for ParseSupportCardinalityClassError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(
            f,
            "unknown support cardinality class label {:?}",
            self.label
        )
    }
}

impl std::error::Error for ParseSupportCardinalityClassError {}

impl std::str::FromStr for SupportCardinalityClass {
    type Err = ParseSupportCardinalityClassError;

    /// Parse the variant tag from the canonical kebab-case label
    /// [`SupportCardinalityClass::as_str`] emits — the
    /// [`FromStr`][std::str::FromStr] idiom-peer of the
    /// [`Display`][std::fmt::Display] impl. Idiom-peer of the same
    /// pair on [`ModalityClass`].
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Self::from_canonical_str(s).ok_or_else(|| ParseSupportCardinalityClassError {
            label: s.to_owned(),
        })
    }
}

impl serde::Serialize for SupportCardinalityClass {
    /// Serialize the variant tag as the canonical kebab-case label
    /// [`Self::as_str`] emits. Closes the
    /// `(Serialize, Deserialize)` serde idiom-peer of the
    /// `(Display, FromStr)` stdlib pair on the variant-tag surface;
    /// idiom-peer of the same lift on [`ModalityClass`].
    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        serializer.collect_str(self)
    }
}

impl<'de> serde::Deserialize<'de> for SupportCardinalityClass {
    /// Deserialize the variant tag from the canonical kebab-case
    /// label [`Self::as_str`] emits via
    /// [`serde::Deserializer::deserialize_str`] lowering to
    /// [`<Self as std::str::FromStr>::from_str`]. Idiom-peer of the
    /// same impl on [`ModalityClass`].
    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        struct SupportCardinalityClassVisitor;

        impl serde::de::Visitor<'_> for SupportCardinalityClassVisitor {
            type Value = SupportCardinalityClass;

            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
                f.write_str(
                    "a canonical SupportCardinalityClass kebab-case label \
                     (`empty`, `singular-support`, `strict-partial-cover`, \
                     `singular-gap`, `full-cover`)",
                )
            }

            fn visit_str<E: serde::de::Error>(self, v: &str) -> Result<Self::Value, E> {
                v.parse::<SupportCardinalityClass>().map_err(E::custom)
            }
        }

        deserializer.deserialize_str(SupportCardinalityClassVisitor)
    }
}

/// Typed three-bucket projection of the support-cardinality scalar by
/// **distance from the support-cardinality boundary** — the closed
/// enum lift of the (`is_boundary`, `is_singular`,
/// `is_strict_partial_cover`) strict ternary partition on
/// [`SupportCardinalityClass`]. Each of the five class variants lands
/// in exactly one bucket; the compiler enforces exhaustiveness at
/// every `match` site on the ternary.
///
/// Bucket mapping (closed and exhaustive over the five
/// [`SupportCardinalityClass`] variants):
/// - [`Self::Boundary`] — both boundary corners
///   ([`SupportCardinalityClass::Empty`],
///   [`SupportCardinalityClass::FullCover`]). Distance 0 from a
///   boundary.
/// - [`Self::Singular`] — both singular near-boundary corners
///   ([`SupportCardinalityClass::SingularSupport`],
///   [`SupportCardinalityClass::SingularGap`]). Distance 1 from a
///   boundary.
/// - [`Self::StrictInterior`] — the strict interior
///   ([`SupportCardinalityClass::StrictPartialCover`]). Distance
///   `>= 2` from each boundary, only reachable on cardinality-`>= 4`
///   axes.
///
/// Peer to [`SupportCardinalityClass`] on the same scalar — the
/// typed-class surface carries the five-corner classifier
/// ([`SupportCardinalityClass`]), the typed-bucket surface carries
/// the three-leg classifier ([`Self`]). The forward projection
/// [`SupportCardinalityClass::support_boundary_distance`] is closed
/// and exhaustive; its histogram-side peer
/// [`AxisHistogram::support_boundary_distance`] routes through the
/// existing [`AxisHistogram::support_cardinality_class`] projection.
///
/// The orthogonal magnitude-direction ternary partition
/// (`is_low_support`, `is_strict_partial_cover`, `is_high_support`)
/// is named at the leg-predicate level on
/// [`SupportCardinalityClass`] but has no typed-enum projection yet;
/// the same lift is the natural next compounding move.
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, Ord, PartialOrd)]
pub enum SupportBoundaryDistance {
    /// The two boundary corners of the support-cardinality interval —
    /// [`SupportCardinalityClass::Empty`] and
    /// [`SupportCardinalityClass::FullCover`]. Distance 0 from the
    /// boundary. Lifts the
    /// [`SupportCardinalityClass::is_boundary`] leg predicate to the
    /// typed variant tag.
    Boundary,
    /// The two singular near-boundary corners of the support-
    /// cardinality interval —
    /// [`SupportCardinalityClass::SingularSupport`] and
    /// [`SupportCardinalityClass::SingularGap`]. Distance 1 from the
    /// boundary. Lifts the [`SupportCardinalityClass::is_singular`]
    /// leg predicate to the typed variant tag.
    Singular,
    /// The strict interior of the support-cardinality interval —
    /// [`SupportCardinalityClass::StrictPartialCover`]. Distance
    /// `>= 2` from each boundary. Only reachable on cardinality-`>= 4`
    /// axes; vacuously absent on cardinality-`<= 3` axes. Lifts the
    /// [`SupportCardinalityClass::is_strict_partial_cover`] leg
    /// predicate to the typed variant tag.
    StrictInterior,
}

impl SupportBoundaryDistance {
    /// Every [`SupportBoundaryDistance`] variant, in declaration order:
    /// `Boundary`, `Singular`, `StrictInterior`. Length 3 — pinned by
    /// [`tests::support_boundary_distance_all_has_three_entries`].
    /// Idiom-peer of [`SupportCardinalityClass::ALL`] and
    /// [`ModalityClass::ALL`] on the sibling typed classifiers.
    pub const ALL: &'static [Self] = &[Self::Boundary, Self::Singular, Self::StrictInterior];

    /// `true` exactly on [`Self::Boundary`] — the typed-bucket peer of
    /// [`SupportCardinalityClass::is_boundary`] projected from the
    /// variant tag.
    #[must_use]
    pub const fn is_boundary(self) -> bool {
        matches!(self, Self::Boundary)
    }

    /// `true` exactly on [`Self::Singular`] — the typed-bucket peer of
    /// [`SupportCardinalityClass::is_singular`] projected from the
    /// variant tag.
    #[must_use]
    pub const fn is_singular(self) -> bool {
        matches!(self, Self::Singular)
    }

    /// `true` exactly on [`Self::StrictInterior`] — the typed-bucket
    /// peer of [`SupportCardinalityClass::is_strict_partial_cover`]
    /// projected from the variant tag. Named `is_strict_interior` on
    /// the typed-bucket surface (the bucket-level reading of the
    /// distance-from-boundary axis); the class-side leg predicate
    /// keeps its `is_strict_partial_cover` name since it sits on the
    /// single-variant peer of [`SupportCardinalityClass::StrictPartialCover`].
    #[must_use]
    pub const fn is_strict_interior(self) -> bool {
        matches!(self, Self::StrictInterior)
    }

    /// Canonical operator-facing kebab-case label for the variant
    /// tag — `"boundary"`, `"singular"`, `"strict-interior"`.
    /// Idiom-peer of [`SupportCardinalityClass::as_str`] and
    /// [`ModalityClass::as_str`] on the sibling typed classifiers.
    ///
    /// **Round-trip law** —
    /// `SupportBoundaryDistance::from_canonical_str(v.as_str()) ==
    /// Some(v)` for every `v: SupportBoundaryDistance`. Pinned by
    /// [`tests::support_boundary_distance_as_str_round_trips_via_from_canonical_str`].
    #[must_use]
    pub const fn as_str(self) -> &'static str {
        match self {
            Self::Boundary => "boundary",
            Self::Singular => "singular",
            Self::StrictInterior => "strict-interior",
        }
    }

    /// Case-insensitive ASCII parse of the canonical name produced
    /// by [`Self::as_str`]. Returns [`None`] for any other input.
    /// Idiom-peer of [`SupportCardinalityClass::from_canonical_str`]
    /// and [`ModalityClass::from_canonical_str`].
    #[must_use]
    pub fn from_canonical_str(s: &str) -> Option<Self> {
        Self::ALL
            .iter()
            .copied()
            .find(|v| v.as_str().eq_ignore_ascii_case(s))
    }
}

impl std::fmt::Display for SupportBoundaryDistance {
    /// Operator-facing rendering — delegates to
    /// [`SupportBoundaryDistance::as_str`] pointwise. Closes the
    /// canonical `(Debug, Display)` duality every stdlib-style closed
    /// enum carries; idiom-peer of the same impl on
    /// [`SupportCardinalityClass`] and [`ModalityClass`].
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(self.as_str())
    }
}

/// Typed parse failure of
/// [`<SupportBoundaryDistance as std::str::FromStr>::from_str`] —
/// the offending input was not a canonical name on the
/// [`SupportBoundaryDistance`] surface. Carries the offending
/// substring verbatim in the `label` field. Idiom-peer of
/// [`ParseSupportCardinalityClassError`] and
/// [`ParseModalityClassError`] on the sibling typed classifiers.
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct ParseSupportBoundaryDistanceError {
    /// The offending input substring, verbatim.
    pub label: String,
}

impl std::fmt::Display for ParseSupportBoundaryDistanceError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(
            f,
            "unknown support boundary distance label {:?}",
            self.label
        )
    }
}

impl std::error::Error for ParseSupportBoundaryDistanceError {}

impl std::str::FromStr for SupportBoundaryDistance {
    type Err = ParseSupportBoundaryDistanceError;

    /// Parse the variant tag from the canonical kebab-case label
    /// [`SupportBoundaryDistance::as_str`] emits — the
    /// [`FromStr`][std::str::FromStr] idiom-peer of the
    /// [`Display`][std::fmt::Display] impl. Idiom-peer of the same
    /// pair on [`SupportCardinalityClass`] and [`ModalityClass`].
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Self::from_canonical_str(s).ok_or_else(|| ParseSupportBoundaryDistanceError {
            label: s.to_owned(),
        })
    }
}

impl serde::Serialize for SupportBoundaryDistance {
    /// Serialize the variant tag as the canonical kebab-case label
    /// [`Self::as_str`] emits. Closes the
    /// `(Serialize, Deserialize)` serde idiom-peer of the
    /// `(Display, FromStr)` stdlib pair on the variant-tag surface;
    /// idiom-peer of the same lift on [`SupportCardinalityClass`]
    /// and [`ModalityClass`].
    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        serializer.collect_str(self)
    }
}

impl<'de> serde::Deserialize<'de> for SupportBoundaryDistance {
    /// Deserialize the variant tag from the canonical kebab-case
    /// label [`Self::as_str`] emits via
    /// [`serde::Deserializer::deserialize_str`] lowering to
    /// [`<Self as std::str::FromStr>::from_str`]. Idiom-peer of the
    /// same impl on [`SupportCardinalityClass`] and [`ModalityClass`].
    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        struct SupportBoundaryDistanceVisitor;

        impl serde::de::Visitor<'_> for SupportBoundaryDistanceVisitor {
            type Value = SupportBoundaryDistance;

            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
                f.write_str(
                    "a canonical SupportBoundaryDistance kebab-case label \
                     (`boundary`, `singular`, `strict-interior`)",
                )
            }

            fn visit_str<E: serde::de::Error>(self, v: &str) -> Result<Self::Value, E> {
                v.parse::<SupportBoundaryDistance>().map_err(E::custom)
            }
        }

        deserializer.deserialize_str(SupportBoundaryDistanceVisitor)
    }
}

/// Typed three-bucket projection of the support-cardinality scalar by
/// **support-magnitude direction** — the closed enum lift of the
/// (`is_low_support`, `is_strict_partial_cover`, `is_high_support`)
/// strict ternary partition on [`SupportCardinalityClass`]. The mirror
/// peer of [`SupportBoundaryDistance`] across the
/// [`SupportCardinalityClass::StrictPartialCover`] middle leg: both
/// ternaries share the strict-interior middle bucket but split the four
/// non-interior corners on orthogonal axes.
///
/// Bucket mapping (closed and exhaustive over the five
/// [`SupportCardinalityClass`] variants):
/// - [`Self::Low`] — the two low-support corners
///   ([`SupportCardinalityClass::Empty`],
///   [`SupportCardinalityClass::SingularSupport`]). Support magnitude
///   at most one cell — the bottom of the support-cardinality interval.
/// - [`Self::StrictInterior`] — the strict interior
///   ([`SupportCardinalityClass::StrictPartialCover`]). Support 2..=
///   `axis_cardinality - 2`, only reachable on cardinality-`>= 4` axes.
/// - [`Self::High`] — the two high-support corners
///   ([`SupportCardinalityClass::SingularGap`],
///   [`SupportCardinalityClass::FullCover`]). Support magnitude at
///   least `axis_cardinality - 1` — the top of the support-cardinality
///   interval.
///
/// **Orthogonality with [`SupportBoundaryDistance`].** Both ternaries
/// share the [`Self::StrictInterior`] / [`SupportBoundaryDistance::StrictInterior`]
/// middle leg (the [`SupportCardinalityClass::StrictPartialCover`]
/// single-variant peer), but split the four non-interior corners
/// orthogonally:
/// - distance partition: bottom-pair `{Empty, FullCover}` (boundary),
///   middle-pair `{SingularSupport, SingularGap}` (singular).
/// - magnitude partition: bottom-pair `{Empty, SingularSupport}` (low),
///   top-pair `{SingularGap, FullCover}` (high).
///
/// The two ternaries cross to recover the four named single-variant
/// peers on the non-interior corners: `Low ∩ Boundary = Empty`,
/// `Low ∩ Singular = SingularSupport`, `High ∩ Singular = SingularGap`,
/// `High ∩ Boundary = FullCover`.
///
/// Peer to [`SupportCardinalityClass`] on the same scalar — the
/// typed-class surface carries the five-corner classifier
/// ([`SupportCardinalityClass`]), the typed-bucket surface carries two
/// orthogonal three-leg classifiers ([`SupportBoundaryDistance`] over
/// the distance-from-boundary axis, [`Self`] over the support-magnitude
/// axis). The forward projection
/// [`SupportCardinalityClass::support_magnitude_direction`] is closed
/// and exhaustive; its histogram-side peer
/// [`AxisHistogram::support_magnitude_direction`] routes through the
/// existing [`AxisHistogram::support_cardinality_class`] projection,
/// mirroring the routing of [`AxisHistogram::support_boundary_distance`].
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, Ord, PartialOrd)]
pub enum SupportMagnitudeDirection {
    /// The two low-support corners of the support-cardinality interval —
    /// [`SupportCardinalityClass::Empty`] and
    /// [`SupportCardinalityClass::SingularSupport`]. Support magnitude
    /// at most one cell. Lifts the
    /// [`SupportCardinalityClass::is_low_support`] leg predicate to the
    /// typed variant tag.
    Low,
    /// The strict interior of the support-cardinality interval —
    /// [`SupportCardinalityClass::StrictPartialCover`]. Support
    /// 2..=`axis_cardinality - 2`. Only reachable on cardinality-`>= 4`
    /// axes; vacuously absent on cardinality-`<= 3` axes. Lifts the
    /// [`SupportCardinalityClass::is_strict_partial_cover`] leg
    /// predicate to the typed variant tag. The shared middle leg with
    /// [`SupportBoundaryDistance::StrictInterior`].
    StrictInterior,
    /// The two high-support corners of the support-cardinality
    /// interval — [`SupportCardinalityClass::SingularGap`] and
    /// [`SupportCardinalityClass::FullCover`]. Support magnitude at
    /// least `axis_cardinality - 1`. Lifts the
    /// [`SupportCardinalityClass::is_high_support`] leg predicate to
    /// the typed variant tag.
    High,
}

impl SupportMagnitudeDirection {
    /// Every [`SupportMagnitudeDirection`] variant, in declaration
    /// order: `Low`, `StrictInterior`, `High`. Length 3 — pinned by
    /// [`tests::support_magnitude_direction_all_has_three_entries`].
    /// Idiom-peer of [`SupportBoundaryDistance::ALL`] on the sibling
    /// typed-bucket classifier.
    pub const ALL: &'static [Self] = &[Self::Low, Self::StrictInterior, Self::High];

    /// `true` exactly on [`Self::Low`] — the typed-bucket peer of
    /// [`SupportCardinalityClass::is_low_support`] projected from the
    /// variant tag. Named `is_low` on the typed-bucket surface (the
    /// bucket-level reading of the support-magnitude axis); the
    /// class-side leg predicate keeps its `is_low_support` name since
    /// it sits on the two-variant low-corner pair.
    #[must_use]
    pub const fn is_low(self) -> bool {
        matches!(self, Self::Low)
    }

    /// `true` exactly on [`Self::StrictInterior`] — the typed-bucket
    /// peer of [`SupportCardinalityClass::is_strict_partial_cover`]
    /// projected from the variant tag. The shared middle leg with
    /// [`SupportBoundaryDistance::is_strict_interior`].
    #[must_use]
    pub const fn is_strict_interior(self) -> bool {
        matches!(self, Self::StrictInterior)
    }

    /// `true` exactly on [`Self::High`] — the typed-bucket peer of
    /// [`SupportCardinalityClass::is_high_support`] projected from the
    /// variant tag. Mirror peer of [`Self::is_low`] across the
    /// [`Self::StrictInterior`] middle leg.
    #[must_use]
    pub const fn is_high(self) -> bool {
        matches!(self, Self::High)
    }

    /// Canonical operator-facing kebab-case label per variant:
    /// `"low"`, `"strict-interior"`, `"high"`. Stable across releases —
    /// every log line, CLI rendering, and config file label keys on
    /// these strings at one site. The
    /// [`Self::from_canonical_str`] inverse closes the round-trip law
    /// `SupportMagnitudeDirection::from_canonical_str(v.as_str()) ==
    /// Some(v)` for every `v: SupportMagnitudeDirection`. Pinned by
    /// [`tests::support_magnitude_direction_as_str_round_trips_via_from_canonical_str`].
    /// Idiom-peer of [`SupportBoundaryDistance::as_str`] on the sibling
    /// typed-bucket classifier and [`SupportCardinalityClass::as_str`] /
    /// [`ModalityClass::as_str`] on the typed-class classifiers.
    #[must_use]
    pub const fn as_str(self) -> &'static str {
        match self {
            Self::Low => "low",
            Self::StrictInterior => "strict-interior",
            Self::High => "high",
        }
    }

    /// Case-insensitive ASCII parse of the canonical name produced
    /// by [`Self::as_str`]. Returns [`None`] for any other input.
    /// Idiom-peer of [`SupportBoundaryDistance::from_canonical_str`]
    /// on the sibling typed-bucket classifier and
    /// [`SupportCardinalityClass::from_canonical_str`] /
    /// [`ModalityClass::from_canonical_str`] on the typed-class
    /// classifiers.
    #[must_use]
    pub fn from_canonical_str(s: &str) -> Option<Self> {
        Self::ALL
            .iter()
            .copied()
            .find(|v| v.as_str().eq_ignore_ascii_case(s))
    }
}

impl std::fmt::Display for SupportMagnitudeDirection {
    /// Operator-facing rendering — delegates to
    /// [`SupportMagnitudeDirection::as_str`] pointwise. Closes the
    /// canonical `(Debug, Display)` duality every stdlib-style closed
    /// enum carries; idiom-peer of the same impl on
    /// [`SupportBoundaryDistance`], [`SupportCardinalityClass`], and
    /// [`ModalityClass`].
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(self.as_str())
    }
}

/// Typed parse failure of
/// [`<SupportMagnitudeDirection as std::str::FromStr>::from_str`] —
/// the offending input was not a canonical name on the
/// [`SupportMagnitudeDirection`] surface. Carries the offending
/// substring verbatim in the `label` field. Idiom-peer of
/// [`ParseSupportBoundaryDistanceError`] on the sibling typed-bucket
/// classifier and [`ParseSupportCardinalityClassError`] /
/// [`ParseModalityClassError`] on the typed-class classifiers.
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct ParseSupportMagnitudeDirectionError {
    /// The offending input substring, verbatim.
    pub label: String,
}

impl std::fmt::Display for ParseSupportMagnitudeDirectionError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(
            f,
            "unknown support magnitude direction label {:?}",
            self.label
        )
    }
}

impl std::error::Error for ParseSupportMagnitudeDirectionError {}

impl std::str::FromStr for SupportMagnitudeDirection {
    type Err = ParseSupportMagnitudeDirectionError;

    /// Parse the variant tag from the canonical kebab-case label
    /// [`SupportMagnitudeDirection::as_str`] emits — the
    /// [`FromStr`][std::str::FromStr] idiom-peer of the
    /// [`Display`][std::fmt::Display] impl. Idiom-peer of the same
    /// pair on [`SupportBoundaryDistance`],
    /// [`SupportCardinalityClass`], and [`ModalityClass`].
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Self::from_canonical_str(s).ok_or_else(|| ParseSupportMagnitudeDirectionError {
            label: s.to_owned(),
        })
    }
}

impl serde::Serialize for SupportMagnitudeDirection {
    /// Serialize the variant tag as the canonical kebab-case label
    /// [`Self::as_str`] emits. Closes the
    /// `(Serialize, Deserialize)` serde idiom-peer of the
    /// `(Display, FromStr)` stdlib pair on the variant-tag surface;
    /// idiom-peer of the same lift on [`SupportBoundaryDistance`],
    /// [`SupportCardinalityClass`], and [`ModalityClass`].
    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        serializer.collect_str(self)
    }
}

impl<'de> serde::Deserialize<'de> for SupportMagnitudeDirection {
    /// Deserialize the variant tag from the canonical kebab-case
    /// label [`Self::as_str`] emits via
    /// [`serde::Deserializer::deserialize_str`] lowering to
    /// [`<Self as std::str::FromStr>::from_str`]. Idiom-peer of the
    /// same impl on [`SupportBoundaryDistance`],
    /// [`SupportCardinalityClass`], and [`ModalityClass`].
    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        struct SupportMagnitudeDirectionVisitor;

        impl serde::de::Visitor<'_> for SupportMagnitudeDirectionVisitor {
            type Value = SupportMagnitudeDirection;

            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
                f.write_str(
                    "a canonical SupportMagnitudeDirection kebab-case label \
                     (`low`, `strict-interior`, `high`)",
                )
            }

            fn visit_str<E: serde::de::Error>(self, v: &str) -> Result<Self::Value, E> {
                v.parse::<SupportMagnitudeDirection>().map_err(E::custom)
            }
        }

        deserializer.deserialize_str(SupportMagnitudeDirectionVisitor)
    }
}

impl<A: ClosedAxis> AxisHistogram<A> {
    /// The all-zero histogram — every cell at zero, [`Self::total`] = 0,
    /// [`Self::is_empty`] = `true`. The monoid identity under
    /// [`Self::merge`].
    #[must_use]
    pub fn empty() -> Self {
        Self {
            counts: vec![0usize; axis_cardinality::<A>()],
            _marker: std::marker::PhantomData,
        }
    }

    /// Record one observation: bump the cell at `value` by one.
    pub fn observe(&mut self, value: A) {
        self.counts[axis_ordinal(value)] += 1;
    }

    /// Reset every cell to zero in place — the canonical Rust stdlib
    /// `clear()` idiom-peer of [`Vec::clear`], [`String::clear`],
    /// [`std::collections::HashMap::clear`],
    /// [`std::collections::HashSet::clear`],
    /// [`std::collections::BTreeMap::clear`], and
    /// [`std::collections::BTreeSet::clear`] on the in-place-reset
    /// surface. Closes the ([`Self::empty`], [`Self::clear`])
    /// constructor-vs-in-place-reset pair every stdlib collection
    /// carries: where [`Self::empty`] / [`Self::default`] allocate a
    /// fresh `axis_cardinality::<A>()`-sized counts vector at the
    /// [`Default`] surface, [`Self::clear`] zeroes the existing counts
    /// vector in place without reallocating the backing
    /// [`Vec<usize>`][Vec].
    ///
    /// Pointwise equivalent to `*self = AxisHistogram::empty()` (the
    /// reassigning form) on the post-state, but **does not realloc**
    /// the backing counts vector — the natural in-place reset on the
    /// rolling-window observatory surface: an aggregator carrying
    /// observations across a rolling window calls `tally.clear()`
    /// between windows to reset the cell counts to zero without
    /// allocating a fresh `vec![0; axis_cardinality::<A>()]` on every
    /// window tick, peer of the
    /// `for (_, c) in tally.iter_mut() { *c = 0; }` open-coded
    /// per-cell zero loop (which traverses every cell explicitly) and
    /// of the `*tally = AxisHistogram::empty()` reassignment (which
    /// drops the existing backing store and allocates a new one).
    /// Before this lift, every consumer reaching the in-place reset
    /// surface picked one of those two forms with varying call-site
    /// verbosity and allocation behavior. The lift names the
    /// projection at one site at the canonical stdlib `clear()`
    /// surface, lowers through [`<[usize]>::fill`][slice::fill] (the
    /// stdlib's own zero-the-slice primitive), and the consumer
    /// reaches the no-realloc post-state through one method call.
    ///
    /// **Post-conditions.**
    /// - [`Self::is_empty`] is `true` after the call.
    /// - [`Self::total`] reads `0`.
    /// - [`Self::distinct_cells`] reads `0`.
    /// - [`Self::unobserved_cells`] reads
    ///   [`axis_cardinality::<A>()`][axis_cardinality].
    /// - [`Self::nonzero`] / [`Self::observed`] are empty iterators.
    /// - [`Self::unobserved`] iterates the full axis (pointwise equal
    ///   to [`axis_iter::<A>()`][axis_iter]).
    /// - `self == AxisHistogram::default()` — pointwise equality with
    ///   the monoid identity.
    ///
    /// **Idempotence** — `hist.clear(); hist.clear()` is pointwise
    /// equal to `hist.clear()`. Clearing an already-empty histogram
    /// leaves it unchanged.
    ///
    /// **Reassignment equivalence** — `let mut a = hist.clone();
    /// a.clear();` is pointwise equal to `let a = AxisHistogram::<A>::
    /// empty();`. The (`clear`, `*self = ::empty()`) duality on the
    /// in-place vs. reassigning reset surface — both yield the monoid
    /// identity at the value level; `clear` retains the existing
    /// backing-store capacity.
    ///
    /// **Length invariance** — the backing counts vector retains its
    /// `axis_cardinality::<A>()` length (every cell still exists at
    /// zero), only the cell values are overwritten. Peer to
    /// [`Vec::clear`]'s capacity-preservation invariant, lifted to the
    /// fixed-length closed-axis surface.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor inherits the
    /// projection at no per-axis cost. The four trait-uniform laws
    /// pinned in [`tests`] hold across the implementor set
    /// (`axis_histogram_clear_is_empty_after_*`,
    /// `axis_histogram_clear_equals_default_*`,
    /// `axis_histogram_clear_is_idempotent_*`,
    /// `axis_histogram_clear_on_empty_is_identity_*`).
    pub fn clear(&mut self) {
        self.counts.fill(0);
    }

    /// Number of observations recorded on `value`. Defined on every
    /// axis cell (returns zero for cells no observation landed on);
    /// total over the axis space without an out-of-range case.
    ///
    /// The inherent-method surface of the per-cell count lookup; the
    /// canonical Rust [`Index`][std::ops::Index] operator surface
    /// (`hist[value]`) is the stdlib idiom-peer — `Self::count(value)`
    /// equals `hist[value]` pointwise by construction (both lower
    /// through the same `self.counts[axis_ordinal(value)]` access).
    #[must_use]
    pub fn count(&self, value: A) -> usize {
        self.counts[axis_ordinal(value)]
    }

    /// Sum of every cell — the total number of observations recorded.
    /// Equal to the length of the input iterator passed to
    /// [`Self::from_iter`] or to [`axis_histogram`]; pinned by the
    /// trait-uniform `axis_histogram_total_equals_input_length_*` law
    /// in [`tests`].
    #[must_use]
    pub fn total(&self) -> usize {
        self.counts.iter().sum()
    }

    /// `true` when every cell is zero — equivalent to
    /// `self.total() == 0`.
    #[must_use]
    pub fn is_empty(&self) -> bool {
        self.counts.iter().all(|&c| c == 0)
    }

    /// Iterate every `(axis-value, count)` pair in declaration order
    /// over [`ClosedAxis::ALL`]. Length equals
    /// [`axis_cardinality::<A>()`][axis_cardinality] regardless of how
    /// many cells are nonzero — the iteration covers the full axis,
    /// not just observed cells. The ordering agrees with
    /// [`axis_iter::<A>()`][axis_iter] pointwise.
    pub fn iter(&self) -> impl Iterator<Item = (A, usize)> + '_ {
        axis_iter::<A>()
            .enumerate()
            .map(|(i, v)| (v, self.counts[i]))
    }

    /// Iterate every `(axis-value, &mut count)` pair in declaration order
    /// over [`ClosedAxis::ALL`] — the canonical Rust stdlib `iter_mut()`
    /// idiom-peer of [`Self::iter`] on the in-place-mutation surface. Every
    /// stdlib collection that exposes a borrowing iterator exposes its
    /// mutable counterpart at this name ([`slice::iter_mut`],
    /// [`Vec::iter_mut`], [`std::collections::HashMap::iter_mut`],
    /// [`std::collections::BTreeMap::iter_mut`]); the [`AxisHistogram`] now
    /// joins that peerage on the closed-axis cell-iteration surface.
    /// Returns the concrete [`AxisHistogramIterMut`] type so the iterator
    /// nameably implements [`Iterator`], [`ExactSizeIterator`],
    /// [`std::iter::FusedIterator`], and [`DoubleEndedIterator`] —
    /// the same trait surface as [`AxisHistogramIter`] minus [`Clone`]
    /// (mutable iterators cannot be cloned without violating aliasing —
    /// the canonical stdlib convention).
    ///
    /// **Item shape.** `(A, &mut usize)` — the cell by value (cells are
    /// [`Copy`] by the [`ClosedAxis`] super-bound) and a mutable reference
    /// to the underlying count slot. Consumers can read and assign through
    /// the mutable reference (`for (_, c) in hist.iter_mut() { *c *= 2; }`
    /// for in-place per-cell mutation; `for (cell, c) in hist.iter_mut() {
    /// *c = remap(cell, *c); }` for a per-cell remap that depends on
    /// the cell identity), reaching the cellwise-mutation surface
    /// directly without an interposing rebuild through
    /// [`FromIterator<(A, usize)>`] or a repeated [`Self::observe`] loop.
    ///
    /// **Length law.** The iterator yields exactly
    /// [`axis_cardinality::<A>()`][axis_cardinality] pairs — the full
    /// axis, not just the observed support. Zero-count cells appear with
    /// `&mut 0` so a remap stepping a zero cell to a positive count
    /// (e.g. a per-cell prior `*c = remap(cell, *c).max(1)`) is reachable
    /// without a re-allocation. [`ExactSizeIterator::len`] reads off the
    /// cardinality without consuming the iterator.
    ///
    /// **Declaration-order law.** The iteration order agrees with
    /// [`axis_iter::<A>()`][axis_iter] pointwise — dropping the count
    /// from the pair sequence yields the same cell sequence. Peer to the
    /// declaration-order law on [`Self::iter`] / [`IntoIterator for
    /// &Self`][IntoIterator].
    ///
    /// **Visibility-under-[`Self::iter`] law.** Mutations applied through
    /// [`Self::iter_mut`] are reflected by the next [`Self::iter`] read:
    /// for every `f: (A, usize) -> usize`, `for (cell, c) in hist
    /// .iter_mut() { *c = f(cell, *c); }` followed by
    /// `hist.iter().collect::<Vec<_>>()` yields the same pair sequence as
    /// the open-coded `(filter, observe)`-rebuild form
    /// `let mut next = AxisHistogram::empty(); for (cell, c) in
    /// hist.iter() { for _ in 0..f(cell, c) { next.observe(cell); } }`
    /// on every `f` that lifts cleanly. The (`iter_mut`, `iter`) duality
    /// on the borrowed-collection surface.
    ///
    /// **Idiom-peer of [`IntoIterator for &mut Self`][IntoIterator].**
    /// The mutable-iteration surface carries two equivalent entry shapes
    /// — `hist.iter_mut()` (inherent named method, idiom-peer of
    /// [`Self::iter`]) and `for pair in &mut hist { … }` (borrowed-
    /// collection idiom, idiom-peer of `for pair in &hist`). Both lower
    /// to the same [`AxisHistogramIterMut`] type by construction.
    ///
    /// **Why this lift.** Before this surface, every consumer reaching
    /// the cellwise-mutation projection (a fleet-wide aggregator
    /// applying a per-cell decay factor before merging into the
    /// fleet cell — `for (cell, c) in hist.iter_mut() { *c = decay(cell,
    /// *c); }` — a future per-cell normalization step dividing each
    /// count by the histogram's total in place — `let t = hist.total();
    /// for (_, c) in hist.iter_mut() { *c /= t.max(1); }` — a custom
    /// per-cell saturating arithmetic that the [`Self::merge`] /
    /// [`std::ops::MulAssign`] surfaces don't carry uniformly) had to
    /// either rebuild the histogram through
    /// [`FromIterator<(A, usize)>`] (an `O(axis_cardinality)`
    /// reallocation for what is in-place arithmetic) or open-code the
    /// projection through the inherent `counts` field that lives behind
    /// `pub(self)` visibility — the lift names the projection at one
    /// site at the canonical stdlib `iter_mut()` surface.
    ///
    /// **Mutability is the only difference vs [`Self::iter`].** All
    /// other laws on [`Self::iter`] (length equals
    /// [`axis_cardinality`], declaration order matches
    /// [`axis_iter`], total equals the sum of yielded counts) hold on
    /// [`Self::iter_mut`] pointwise — the two surfaces walk the same
    /// counts vector, differing only on the (read-only, read-write)
    /// ownership polarity.
    pub fn iter_mut(&mut self) -> AxisHistogramIterMut<'_, A> {
        AxisHistogramIterMut {
            counts: self.counts.iter_mut().enumerate(),
            _marker: std::marker::PhantomData,
        }
    }

    /// Iterate only the nonzero `(axis-value, count)` pairs in
    /// declaration order — the complement of the zero-cells. Useful
    /// for rendering compact operator-facing summaries that skip
    /// unobserved categories (a CLI `config-diff` summary listing
    /// `"added: 12, removed: 4"` without the `context: 53` cell, a
    /// structured-log field listing only the error classes that fired
    /// in the last reload window). Pointwise prefix of [`Self::iter`]
    /// filtered by `count > 0`.
    pub fn nonzero(&self) -> impl Iterator<Item = (A, usize)> + '_ {
        self.iter().filter(|&(_, c)| c > 0)
    }

    /// Iterate the axis cells that received at least one observation
    /// — the histogram's *observed support* — in declaration order
    /// over [`ClosedAxis::ALL`]. The cells for which
    /// `self.count(v) > 0`.
    ///
    /// The cell-only form of [`Self::nonzero`] — same support,
    /// observation counts dropped from the item shape — and the
    /// structural dual of [`Self::unobserved`] over the closed axis:
    /// every cell of [`ClosedAxis::ALL`] lies in exactly one of
    /// [`Self::observed`] and [`Self::unobserved`], and the closed
    /// axis partitions into the two without remainder. Closes the
    /// (observed, unobserved) partition at the *cell-only* iterator
    /// surface, peer to the named-scalar partition
    /// (`distinct_cells + unobserved_cells == axis_cardinality::<A>()`)
    /// the histogram already carries.
    ///
    /// The natural typed primitive for diagnostic dumps, dashboards,
    /// and attestation manifests asking *"which kinds did this
    /// window observe?"* without consuming the per-cell counts: the
    /// observed layer kinds in a chain's
    /// [`crate::ConfigSourceChain::layer_kind_histogram`] (the
    /// "which layer kinds appeared this rebuild?" diagnostic), the
    /// realized file formats in
    /// [`crate::ConfigSourceChain::file_format_histogram`] (the
    /// "which formats did this chain see?" coverage cell), the fired
    /// error classes in a per-window
    /// `AxisHistogram<crate::ShikumiErrorKind>` (the "which kinds of
    /// reload failure fired this hour?" attestation), the present
    /// diff-line classes in
    /// [`crate::ConfigDiff::kind_histogram`] (the "which diff
    /// classes appeared this rebuild?" attestation). Before this
    /// lift, every such consumer re-derived the projection inline as
    /// one of three forms — `hist.nonzero().map(|(v, _)| v)` (the
    /// dropped-count form on the typed pair-iterator),
    /// `hist.iter().filter(|&(_, c)| c > 0).map(|(v, _)| v)` (the
    /// open-coded scan over the full axis), or
    /// `axis_iter::<A>().filter(|&v| hist.count(v) > 0)` (the
    /// count-lookup form, which makes one indexed read per cell
    /// against the histogram's counts vector) — each consumer
    /// picking one of the three with varying call-site verbosity
    /// (destructure-and-drop on the dropped-count form, two-stage
    /// filter+map on the open-coded form, axis-iteration plus
    /// per-cell count lookup on the count-lookup form). The lift
    /// names the projection at one site.
    ///
    /// **Counts are positive, omitted from the item shape** — the
    /// iterator yields just `A` (the cell), not `(A, usize)`. The
    /// symmetric peer of [`Self::unobserved`]: where `unobserved`
    /// drops the (uniformly-zero) count, `observed` drops the
    /// (varying-positive) count. When the count carries information
    /// the call site needs (rendering a `"added: 12, removed: 4"`
    /// summary), [`Self::nonzero`] yields the `(cell, count)` pair
    /// directly; when only the cell-set matters
    /// (`hist.observed().collect::<HashSet<_>>()` for set
    /// comparisons, `for cell in hist.observed()` for per-cell
    /// rendering that already knows the count is positive),
    /// `observed` reads cleanly without a `let (v, _) = …`
    /// destructure.
    ///
    /// **Empty-histogram convention** — the empty histogram has no
    /// observed cells, so [`Self::observed`] is empty (the dual of
    /// the empty-histogram convention on [`Self::unobserved`], which
    /// iterates the full axis). The full-cover histogram (every cell
    /// observed at least once) is the dual boundary: [`Self::observed`]
    /// iterates the full axis (pointwise equal to
    /// [`axis_iter::<A>()`][axis_iter]) and [`Self::unobserved`] is
    /// empty. The two boundaries pin the partition's tight witnesses.
    ///
    /// **Companion invariants** with [`Self::nonzero`],
    /// [`Self::unobserved`], [`Self::distinct_cells`], and
    /// [`Self::unobserved_cells`]:
    /// - `observed().count() == distinct_cells()` always — the
    ///   cell-only iterator's length is the support cardinality, the
    ///   named scalar peer.
    /// - The cell-set yielded by [`Self::observed`] equals the
    ///   cell-set yielded by `nonzero().map(|(v, _)| v)` — the
    ///   dropped-count equivalence on the pair-iterator surface.
    /// - The cell-set yielded by [`Self::observed`] is disjoint from
    ///   the cell-set yielded by [`Self::unobserved`], and their
    ///   union (in declaration order, [`Self::observed`] then
    ///   [`Self::unobserved`] interleaved by declaration order) is
    ///   the full axis — the typed (observed, unobserved) cell-only
    ///   partition over [`ClosedAxis::ALL`].
    /// - `observed().next().is_none()` ⇔ [`Self::is_empty`] —
    ///   the empty-iterator predicate reads the empty-histogram
    ///   boundary.
    /// - `observed().next().is_none()` is `false` and the iterator
    ///   yields [`axis_iter::<A>()`][axis_iter] ⇔ [`Self::is_full_cover`]
    ///   — the full-axis-iterator predicate reads the full-cover
    ///   boundary.
    ///
    /// **Monotonicity under [`Self::merge`]** — merging never
    /// shrinks the support: every cell observed in either side is
    /// observed in the merge, so the merged cell-set is the *union*
    /// of the two sides' cell-sets. The cell-only peer of the
    /// monotone-support law on [`Self::distinct_cells`] (the scalar
    /// surface) and the monotone-non-increase law on
    /// [`Self::unobserved`] (the dual-side iterator).
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor inherits the
    /// projection at no per-axis cost. The three trait-uniform laws
    /// pinned in [`tests`] hold across the implementor set
    /// (`axis_histogram_observed_empty_is_empty_*`,
    /// `axis_histogram_observed_axis_cover_is_full_axis_*`,
    /// `axis_histogram_observed_singleton_is_just_observed_cell_*`).
    pub fn observed(&self) -> impl Iterator<Item = A> + '_ {
        self.iter().filter(|&(_, c)| c > 0).map(|(v, _)| v)
    }

    /// Iterate the axis cells that received no observations — the
    /// structural complement of [`Self::nonzero`] over the closed
    /// axis, in declaration order over [`ClosedAxis::ALL`]. The cells
    /// for which `self.count(v) == 0`.
    ///
    /// The **"coverage gap"** projection on the histogram — the
    /// natural typed primitive for diagnostic dumps, attestation
    /// manifests, and dashboards asking *"which kinds were never
    /// observed in this window?"*: the unfired error classes in a
    /// per-window `AxisHistogram<crate::ShikumiErrorKind>` (the
    /// "we never saw a Parse error this reload" attestation), the
    /// unused file formats in a chain's
    /// [`crate::ConfigSourceChain::file_format_histogram`] (the
    /// "this chain never realized a `.lisp` layer" coverage gap),
    /// the layer kinds the chain never produced in
    /// [`crate::ConfigSourceChain::layer_kind_histogram`] (the
    /// "no Env layer this rebuild" diagnostic), the diff-line
    /// classes absent from a window in
    /// [`crate::ConfigDiff::kind_histogram`] (the "no Removed
    /// lines in this rebuild" attestation). Before this lift, every
    /// such consumer re-derived the projection inline as
    /// `hist.iter().filter(|&(_, c)| c == 0).map(|(v, _)| v)` at
    /// every site, with the (zero-count → unobserved) filter open-
    /// coded at each call site. The lift names the projection at
    /// one site.
    ///
    /// **Structural complement of [`Self::nonzero`]** — every cell
    /// of the closed axis lies in exactly one of the two iterators:
    /// `nonzero().count() + unobserved().count() ==
    /// axis_cardinality::<A>()`, and the cell-set yielded by
    /// `nonzero().map(|(v, _)| v)` is disjoint from the cell-set
    /// yielded by `unobserved()`. The (observed, unobserved)
    /// partition closes the histogram's support boundary at the
    /// surface: `Self::nonzero` reads the *support* (the multiset's
    /// observed kinds), `Self::unobserved` reads the *coverage gap*
    /// (the unobserved kinds), and the closed axis partitions into
    /// the two without remainder. Pinned uniformly by
    /// [`tests::axis_histogram_unobserved_and_nonzero_partition_axis_for_every_closed_axis_implementor`].
    ///
    /// **Counts are zero, omitted from the item shape** — the
    /// iterator yields just `A` (the cell), not `(A, usize)`: every
    /// yielded cell has count zero by definition, so the count
    /// carries no information and an unconditional `(v, 0)` pair
    /// would noise the call sites (`for missing in hist.unobserved()`
    /// reads cleanly without a `let (m, _) = …` destructure). The
    /// asymmetry with [`Self::nonzero`] is intentional: the
    /// observed-cells iterator carries counts because they vary; the
    /// unobserved-cells iterator drops them because they don't.
    ///
    /// **Empty-histogram convention** — the empty histogram has
    /// every cell unobserved, so [`Self::unobserved`] iterates the
    /// full axis (pointwise equal to [`axis_iter::<A>()`][axis_iter])
    /// and [`Self::nonzero`] is empty. The full-cover histogram (every
    /// cell observed at least once) is the dual boundary:
    /// [`Self::unobserved`] is empty and [`Self::nonzero`] iterates
    /// the full axis. The two boundaries pin the partition's tight
    /// witnesses.
    ///
    /// **Companion invariant** with [`Self::distinct_cells`] and
    /// [`axis_cardinality`]:
    /// - `unobserved().count() == axis_cardinality::<A>() -
    ///   distinct_cells()` — the coverage-gap size reads off the
    ///   support cardinality through subtraction from the axis size.
    /// - `unobserved().next().is_none()` ⇔ `distinct_cells() ==
    ///   axis_cardinality::<A>()` — the full-cover predicate (every
    ///   cell observed at least once) reaches the same boolean as the
    ///   support-equals-axis-cardinality equality.
    /// - `unobserved().count() == axis_cardinality::<A>()` ⇔
    ///   [`Self::is_empty`] — the empty-histogram boundary, peer to
    ///   `distinct_cells() == 0 ⇔ is_empty()`.
    ///
    /// **Monotonicity under [`Self::merge`]** — merging never grows
    /// the coverage gap: every cell observed in either side is
    /// observed in the merge, so
    /// `merge(self, other).unobserved().count() <=
    /// self.unobserved().count().min(other.unobserved().count())`.
    /// The dual of the monotone-support law on [`Self::distinct_cells`]
    /// (merging never shrinks the support).
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor (the twenty
    /// closed-enum axis primitives plus the five product cubes —
    /// twenty-five today, reached uniformly through
    /// `for_each_closed_axis_implementor!` in [`tests`]) inherits
    /// the projection at no per-axis cost. The four trait-uniform
    /// laws pinned in [`tests`] hold across the implementor set
    /// (`axis_histogram_unobserved_empty_is_full_axis_*`,
    /// `axis_histogram_unobserved_axis_cover_is_empty_*`,
    /// `axis_histogram_unobserved_singleton_omits_observed_cell_*`,
    /// `axis_histogram_unobserved_and_nonzero_partition_axis_*`).
    pub fn unobserved(&self) -> impl Iterator<Item = A> + '_ {
        self.iter().filter(|&(_, c)| c == 0).map(|(v, _)| v)
    }

    /// Number of distinct axis cells that received at least one
    /// observation — the **support cardinality** of the histogram.
    /// Equivalent to `self.nonzero().count()`; the structural
    /// cardinality peer to [`Self::total`].
    ///
    /// Where [`Self::total`] sums observation counts (the *size*
    /// aggregate over the multiset of observations),
    /// `distinct_cells` counts the cells that received any
    /// observation (the *support* of the multiset — the cardinality
    /// of the underlying set of observed cells). Together they form
    /// the natural pair of scalar projections every typed histogram
    /// carries: `total` reads "how many observations", `distinct_cells`
    /// reads "how many *kinds* of observation", `dominant_cell` reads
    /// "*which* kind dominates". Before this lift, every consumer
    /// asking "did the chain see at least N distinct kinds?" re-derived
    /// the projection inline as `hist.iter().filter(|&(_, c)| c > 0).count()`
    /// or `hist.nonzero().count()`; the lift names the projection at
    /// one site so a future consumer's coverage check, attestation
    /// manifest support count, or diagnostic "N of M kinds observed"
    /// summary reads off one method call.
    ///
    /// **Structural bounds.** The return value is always in the
    /// interval `[0, axis_cardinality::<A>()]`. Tight at both ends:
    /// the empty histogram reads `0`, the uniform axis-cover
    /// histogram reads `axis_cardinality::<A>()`. The projection
    /// connects the histogram surface to the typescape's structural
    /// axis size — `distinct_cells == axis_cardinality::<A>()` is the
    /// "*every* cell observed" coverage predicate, reachable as a
    /// single equality.
    ///
    /// **Companion invariants.**
    /// - `distinct_cells() == 0` ⇔ [`Self::is_empty`] is `true`
    ///   (peer to the empty-histogram boundary equivalence
    ///   [`Self::dominant_cell`] carries).
    /// - `distinct_cells() <= total()` always: each distinct cell
    ///   contributes at least one observation, so the support is
    ///   bounded by the multiset's size.
    /// - `distinct_cells() == total()` iff every observed cell
    ///   appears exactly once — the "uniform-singleton" shape.
    /// - `distinct_cells() <= axis_cardinality::<A>()` always: the
    ///   support is bounded by the axis size.
    /// - `merge(self, other).distinct_cells() >=
    ///   self.distinct_cells().max(other.distinct_cells())`: the
    ///   support is monotone under [`Self::merge`] — merging never
    ///   shrinks the set of observed cells.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor inherits the
    /// projection at no per-axis cost. The three trait-uniform laws
    /// pinned in [`tests`] hold across the implementor set
    /// (`axis_histogram_distinct_cells_empty_is_zero_*`,
    /// `axis_histogram_distinct_cells_singleton_is_one_*`,
    /// `axis_histogram_distinct_cells_axis_cover_equals_cardinality_*`).
    #[must_use]
    pub fn distinct_cells(&self) -> usize {
        self.counts.iter().filter(|&&c| c > 0).count()
    }

    /// Number of axis cells that received no observations — the
    /// **coverage-gap cardinality** of the histogram. The scalar peer of
    /// the [`Self::unobserved`] iterator on the count side and the
    /// structural complement of [`Self::distinct_cells`] over the closed
    /// axis: every cell of [`ClosedAxis::ALL`] lies in exactly one of
    /// the (observed, unobserved) sub-axes, and the two scalar counts
    /// partition the axis without remainder
    /// (`distinct_cells() + unobserved_cells() == axis_cardinality::<A>()`).
    ///
    /// The natural typed primitive for diagnostic dumps, coverage
    /// dashboards, and attestation manifests asking *"how many axis
    /// kinds were missing from this observation window?"*: the unfired
    /// error-class count in a per-window
    /// `AxisHistogram<crate::ShikumiErrorKind>` (the "N of M error
    /// classes never fired this reload" attestation), the unused
    /// file-format count in a chain's
    /// [`crate::ConfigSourceChain::file_format_histogram`] (the
    /// "N formats unused in this chain" coverage cell), the absent
    /// layer-kind count in a chain's
    /// [`crate::ConfigSourceChain::layer_kind_histogram`] (the "N layer
    /// kinds the chain never produced" diagnostic — the natural pair to
    /// the "M layer kinds observed" cell on the same row), the absent
    /// diff-line class count in
    /// [`crate::ConfigDiff::kind_histogram`] (the "N diff classes absent
    /// from this rebuild" attestation). Before this lift, every such
    /// consumer re-derived the projection inline as
    /// `hist.unobserved().count()` — which walked the histogram through
    /// the `iter().filter(|&(_, c)| c == 0).map(|(v, _)| v)` chain plus
    /// the trailing `.count()` (a five-stage iterator adaptor when a
    /// single-pass `.filter(|&&c| c == 0).count()` over the raw counts
    /// vector reads the same scalar). The lift names the projection at
    /// one site, consumers route through one method call, and the
    /// (observed, unobserved) cardinality partition becomes a typed
    /// equality between two named scalars rather than one named scalar
    /// against a generic helper.
    ///
    /// **Underflow-safe by construction.** The pointwise equivalent
    /// derivation `axis_cardinality::<A>() - distinct_cells()` is
    /// guaranteed non-negative on every histogram (the support is
    /// bounded above by the axis size — pinned by the
    /// `distinct_cells <= axis_cardinality` invariant on
    /// [`Self::distinct_cells`]), so the subtraction never wraps. The
    /// named scalar surfaces the bound; consumers do not re-prove
    /// monotonicity at the call site.
    ///
    /// **Structural bounds.** The return value is always in the
    /// interval `[0, axis_cardinality::<A>()]`. Tight at both ends: the
    /// uniform axis-cover histogram reads `0` (every cell observed, no
    /// gap), the empty histogram reads `axis_cardinality::<A>()`
    /// (every cell unobserved, the full gap). The projection connects
    /// the histogram surface to the typescape's structural axis size —
    /// `unobserved_cells == 0` is the "*every* cell observed" coverage
    /// predicate, reachable as a single equality.
    ///
    /// **Companion invariants.**
    /// - `unobserved_cells() == axis_cardinality::<A>() - distinct_cells()`
    ///   always: the coverage-gap cardinality reads off the support
    ///   cardinality through one subtraction from the axis size. The
    ///   (observed, unobserved) cardinality partition.
    /// - `unobserved_cells() == axis_cardinality::<A>()` ⇔
    ///   [`Self::is_empty`] is `true` (peer to `distinct_cells() == 0 ⇔
    ///   is_empty()` on the dual side of the partition).
    /// - `unobserved_cells() == 0` ⇔ `distinct_cells() ==
    ///   axis_cardinality::<A>()` — the full-cover predicate (every
    ///   cell observed at least once), peer to
    ///   `unobserved().next().is_none()` on the iterator side.
    /// - `unobserved_cells() == self.unobserved().count()` always:
    ///   pointwise equal to the iterator's length, lifting the
    ///   five-stage `iter().filter().map().filter().count()` chain to a
    ///   single-pass count on the raw counts vector.
    /// - `merge(self, other).unobserved_cells() <=
    ///   self.unobserved_cells().min(other.unobserved_cells())`: the
    ///   coverage gap is *monotone-decreasing* under [`Self::merge`] —
    ///   merging never grows the gap (every cell observed in either
    ///   side is observed in the merge, so the unobserved set is the
    ///   intersection of the two sides' unobserved sets). The dual of
    ///   the monotone-growth law on [`Self::distinct_cells`].
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor (the twenty
    /// closed-enum axis primitives plus the five product cubes —
    /// twenty-five today, reached uniformly through
    /// `for_each_closed_axis_implementor!` in [`tests`]) inherits the
    /// projection at no per-axis cost. The three trait-uniform laws
    /// pinned in [`tests`] hold across the implementor set
    /// (`axis_histogram_unobserved_cells_empty_equals_cardinality_*`,
    /// `axis_histogram_unobserved_cells_singleton_is_cardinality_minus_one_*`,
    /// `axis_histogram_unobserved_cells_axis_cover_is_zero_*`).
    ///
    /// Peer to [`Self::total`] (the *sum* over every cell),
    /// [`Self::distinct_cells`] (the *observed-cells cardinality* —
    /// dual side of the partition), [`Self::peak_count`] (the *modal*
    /// count scalar), [`Self::trough_count`] (the *rarest-observed*
    /// count scalar), and [`Self::spread`] (the *observed-distribution
    /// skew* scalar): the scalar surface of the histogram now carries
    /// the natural sextuple of
    /// `(how many observations, how many kinds, how many gaps, how many
    /// on the peak, how many on the trough, how much spread)`
    /// projections — every operator-facing summary reads off one method
    /// call each, and the *full-cover* predicate (`unobserved_cells()
    /// == 0`) reads off a single equality on the closed scalar surface.
    #[must_use]
    pub fn unobserved_cells(&self) -> usize {
        self.counts.iter().filter(|&&c| c == 0).count()
    }

    /// `true` exactly when every cell of the closed axis received at
    /// least one observation — the **full-cover predicate** on the
    /// histogram surface. The typed peer of [`Self::is_empty`] on the
    /// *dual* side of the (observed, unobserved) partition: where
    /// `is_empty` reads "no cell observed", `is_full_cover` reads
    /// "every cell observed".
    ///
    /// Pointwise equivalent to three documented surface predicates:
    /// - `self.unobserved_cells() == 0` (coverage gap is empty),
    /// - `self.distinct_cells() == axis_cardinality::<A>()` (support
    ///   equals the axis),
    /// - `self.unobserved().next().is_none()` (the unobserved iterator
    ///   is empty).
    ///
    /// Before this lift, every consumer asking "does this observation
    /// window cover every kind?" re-derived the predicate inline as
    /// one of three forms — and the three forms drifted in subtle
    /// ways: `distinct_cells() == axis_cardinality::<A>()` requires
    /// importing [`axis_cardinality`] and naming the axis through a
    /// turbofish at every call site; `unobserved().next().is_none()`
    /// allocates an iterator just to check emptiness; `unobserved_cells()
    /// == 0` reads naturally but still names the *coverage-gap* surface
    /// to ask the *full-cover* question. The lift names the predicate
    /// directly at one site — the typed boolean every coverage-
    /// dashboard cell, attestation manifest, and "axis fully exercised"
    /// gate reads off as a single method call.
    ///
    /// The natural typed primitive for diagnostic dumps, coverage
    /// dashboards, and attestation manifests asking *"did this window
    /// exercise every kind?"*: the "every error class fired at least
    /// once this reload window" attestation on a per-window
    /// `AxisHistogram<crate::ShikumiErrorKind>`, the "every recognized
    /// file format appeared at least once in the chain" coverage gate
    /// on [`crate::ConfigSourceChain::file_format_histogram`], the
    /// "every layer kind produced at least one entry" diagnostic on
    /// [`crate::ConfigSourceChain::layer_kind_histogram`], the "every
    /// diff-line class observed in this rebuild" attestation on
    /// [`crate::ConfigDiff::kind_histogram`].
    ///
    /// **Closes the (`is_empty`, `is_full_cover`) boolean partition** on
    /// the histogram surface — the dual-boundary pair of typed
    /// predicates over the (observed, unobserved) partition. The two
    /// boundaries are *not* mutually exclusive on a zero-cardinality
    /// axis (both hold vacuously when `axis_cardinality::<A>() == 0`,
    /// since the empty axis has no cells to observe); they are
    /// mutually exclusive on every implementor today (every closed-axis
    /// primitive in the typescape carries `axis_cardinality >= 2`).
    /// The partition closes the histogram's *coverage* surface as
    /// `is_empty` closed the *observation* surface: a per-window
    /// "did the chain see anything?" reads off `is_empty`, a
    /// "did the chain see everything?" reads off `is_full_cover`,
    /// neither needs to know the axis size.
    ///
    /// **Empty-histogram convention** — returns `false` on every
    /// non-zero-cardinality axis (the empty histogram has the full
    /// coverage gap, so the predicate fails uniformly). On a
    /// zero-cardinality axis (none in the typescape today, but
    /// structurally permitted by [`ClosedAxis`]) the empty histogram
    /// reads `true` (vacuous full cover — no cells to miss).
    ///
    /// **Full-cover-from-singleton convention** — returns `true`
    /// from a single observation exactly when the axis carries only
    /// one cell (`axis_cardinality::<A>() == 1`). On axes with
    /// cardinality `>= 2` (every implementor today), a singleton
    /// observation leaves at least `axis_cardinality - 1 >= 1` cells
    /// in the gap, so the predicate fails.
    ///
    /// **Companion invariants** with [`Self::is_empty`],
    /// [`Self::distinct_cells`], [`Self::unobserved_cells`], and
    /// [`Self::unobserved`]:
    /// - `is_full_cover() == (unobserved_cells() == 0)` always.
    /// - `is_full_cover() == (distinct_cells() == axis_cardinality::<A>())`
    ///   always — the dual-side surfacing of the same boolean across the
    ///   (observed, unobserved) partition.
    /// - `is_full_cover() == self.unobserved().next().is_none()`
    ///   always — the iterator-emptiness equivalent of the gap-size-zero
    ///   form, without the iterator allocation.
    /// - `is_full_cover() && is_empty()` iff `axis_cardinality::<A>() == 0`
    ///   — the degenerate-axis double-boundary.
    /// - `merge(self, other).is_full_cover() >= self.is_full_cover() ||
    ///   other.is_full_cover()` (boolean monotone-OR): merging cannot
    ///   *un*-cover a cell, so if either side reads full cover so does
    ///   the merge. The peer to the monotone-coverage law on
    ///   [`Self::unobserved`] / monotone-non-increase law on
    ///   [`Self::unobserved_cells`].
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor (the twenty-six
    /// closed-enum axis primitives plus the five product cubes —
    /// thirty-one today, reached uniformly through
    /// `for_each_closed_axis_implementor!` in [`tests`]) inherits the
    /// projection at no per-axis cost. The three trait-uniform laws
    /// pinned in [`tests`] hold across the implementor set
    /// (`axis_histogram_is_full_cover_empty_iff_axis_is_empty_*`,
    /// `axis_histogram_is_full_cover_singleton_iff_cardinality_is_one_*`,
    /// `axis_histogram_is_full_cover_on_axis_cover_*`).
    ///
    /// Peer to [`Self::is_empty`] (the *no-observation* boolean
    /// boundary): `(is_empty, is_full_cover)` reads off the histogram's
    /// observation-coverage boundary as a typed pair, with `is_empty`
    /// at the "nothing observed" end and `is_full_cover` at the
    /// "everything observed at least once" end. The dual-boolean pair
    /// closes the coverage-state surface of the histogram in a single
    /// `(bool, bool)` projection.
    #[must_use]
    pub fn is_full_cover(&self) -> bool {
        self.counts.iter().all(|&c| c > 0)
    }

    /// The first axis cell (in declaration order over [`ClosedAxis::ALL`])
    /// whose observation count equals the maximum count over the
    /// histogram; `None` when no cell carries any observation
    /// (i.e. [`Self::is_empty`] is `true`).
    ///
    /// The "argmax" / "modal cell" projection on the histogram — the
    /// natural typed primitive for diagnostic dumps, dashboards, and
    /// attestation manifests asking *"which cell dominates this
    /// observation window?"*: the dominant layer kind in a chain's
    /// [`crate::ConfigSourceChain::layer_kind_histogram`], the most
    /// common file format in
    /// [`crate::ConfigSourceChain::file_format_histogram`], the
    /// dominant diff-line class in
    /// [`crate::ConfigDiff::kind_histogram`] for a "rebuild summary"
    /// line, the most common reload-failure kind in a per-window
    /// `AxisHistogram<crate::ShikumiErrorKind>`. Before this lift, every
    /// such consumer re-derived the loop inline as
    /// `hist.iter().filter(|&(_, c)| c > 0).max_by_key(|&(_, c)| c).map(|(v, _)| v)`
    /// — and the inline `max_by_key` form silently returned the *last*
    /// tied cell rather than the first (per
    /// [`Iterator::max_by_key`]'s contract), so two consumers reading
    /// "the dominant cell" off the same histogram could disagree under
    /// ties unless every one carefully reversed the comparison. The
    /// lift names the projection at one site with a documented
    /// tie-breaking rule.
    ///
    /// **Tie-breaking is deterministic by declaration order.** When
    /// multiple cells share the maximum count, the cell earliest in
    /// [`ClosedAxis::ALL`] wins — pointwise consistent with the order
    /// [`Self::iter`] yields. The same histogram observed under
    /// different observation orders therefore yields the same
    /// dominant cell: observation order does not leak through the
    /// projection.
    ///
    /// **Empty-histogram convention.** Returns `None` exactly when
    /// [`Self::is_empty`] is `true`. A histogram with even a single
    /// observation always has a dominant cell (the observed one). A
    /// histogram whose every cell observes the same nonzero count
    /// returns `Some(first cell)` — the unique cell in declaration
    /// order with the maximum.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor (the twenty
    /// closed-enum axis primitives plus the five product cubes —
    /// twenty-five today, reached uniformly through
    /// `for_each_closed_axis_implementor!` in [`tests`]) inherits the
    /// projection at no per-axis cost. The three trait-uniform laws
    /// pinned in [`tests`] hold across the implementor set
    /// (`axis_histogram_dominant_cell_empty_is_none_*`,
    /// `axis_histogram_dominant_cell_singleton_picks_observed_*`,
    /// `axis_histogram_dominant_cell_axis_cover_picks_first_*`).
    ///
    /// Peer to [`Self::total`] (the *aggregate* over every cell) and
    /// [`Self::nonzero`] (the *subset* of cells with observations):
    /// `Self::total` reads the scalar sum, `Self::nonzero` reads the
    /// subset, `Self::dominant_cell` reads the modal cell — the three
    /// natural aggregate projections of a typed histogram.
    #[must_use]
    pub fn dominant_cell(&self) -> Option<A> {
        let mut iter = self.iter().filter(|&(_, c)| c > 0);
        let first = iter.next()?;
        Some(
            iter.fold(
                first,
                |best, current| {
                    if current.1 > best.1 { current } else { best }
                },
            )
            .0,
        )
    }

    /// The first axis cell (in declaration order over [`ClosedAxis::ALL`])
    /// whose observation count equals the minimum *positive* count over
    /// the histogram; `None` when no cell carries any observation
    /// (i.e. [`Self::is_empty`] is `true`).
    ///
    /// The "argmin" / "rarest observed cell" projection on the
    /// histogram — the structural dual of [`Self::dominant_cell`] on
    /// the *minority* side. The natural typed primitive for diagnostic
    /// dumps and dashboards asking *"which cell is the rarest in this
    /// observation window?"*: the rarest observed layer kind in a
    /// chain's [`crate::ConfigSourceChain::layer_kind_histogram`] (a
    /// reload that fires once with a single Defaults entry on an
    /// otherwise File-dominated chain), the least common file format
    /// in [`crate::ConfigSourceChain::file_format_histogram`] (a single
    /// `.lisp` layer among many `.yaml`), the rarest reload-failure
    /// kind in a per-window `AxisHistogram<crate::ShikumiErrorKind>`
    /// (the outlier classification on a stream dominated by `Parse`
    /// errors). Before this lift, every such consumer re-derived the
    /// loop inline as
    /// `hist.iter().filter(|&(_,c)|c>0).min_by_key(|&(_,c)|c).map(|(v,_)|v)`
    /// — and the inline `min_by_key` form silently returns the *first*
    /// tied cell (per [`Iterator::min_by_key`]'s contract, which
    /// reverses [`Iterator::max_by_key`]'s "last on ties" behavior), so
    /// the open-coded argmin and the open-coded argmax in
    /// [`Self::dominant_cell`] disagreed on which tied cell to pick.
    /// The pair of lifts pins one consistent tie-breaking rule across
    /// both projections.
    ///
    /// **Zero cells are excluded from the search.** The argmin is taken
    /// over the histogram's *support* (the set of observed cells), not
    /// over the full axis. Zero-count cells are trivially the minimum
    /// over the full axis and would shadow the rarest *observed* kind;
    /// excluding them surfaces the rarest cell some observation
    /// actually fell on — the question the rendering, diagnostic, and
    /// dashboard sites ask. This matches [`Self::dominant_cell`]'s
    /// symmetry on the maximum side: both projections operate over the
    /// nonzero support, so the empty-histogram convention is identical
    /// (both return `None`) and the singleton case is identical (both
    /// return the observed cell).
    ///
    /// **Tie-breaking is deterministic by declaration order.** When
    /// multiple observed cells share the minimum count, the cell
    /// earliest in [`ClosedAxis::ALL`] wins — pointwise consistent
    /// with [`Self::dominant_cell`]'s tie-breaking rule and the order
    /// [`Self::iter`] yields. The same histogram observed under
    /// different observation orders therefore yields the same
    /// recessive cell: observation order does not leak through the
    /// projection.
    ///
    /// **Empty-histogram convention.** Returns `None` exactly when
    /// [`Self::is_empty`] is `true`. A histogram with even a single
    /// observation always has a recessive cell (the observed one). A
    /// histogram whose every cell observes the same nonzero count
    /// returns `Some(first cell)` — the unique cell in declaration
    /// order with the minimum positive count, identical to the
    /// dominant cell on a uniform histogram. Pinned by
    /// [`tests::axis_histogram_dominant_and_recessive_agree_on_uniform_axis_cover_for_every_implementor`].
    ///
    /// **Companion invariants** with [`Self::dominant_cell`] and
    /// [`Self::distinct_cells`]:
    /// - `recessive_cell().is_some() == dominant_cell().is_some()`:
    ///   both projections are defined on the same support
    ///   (`!is_empty()`).
    /// - `dominant_cell() == recessive_cell()` whenever
    ///   `distinct_cells() == 1` (a single observed cell is both the
    ///   maximum and the minimum) — the singleton-support law.
    /// - `count(recessive_cell().unwrap()) <= count(dominant_cell().unwrap())`
    ///   whenever the histogram is non-empty: the rarest cell's count
    ///   is bounded above by the dominant cell's count.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor (the twenty
    /// closed-enum axis primitives plus the five product cubes —
    /// twenty-five today, reached uniformly through
    /// `for_each_closed_axis_implementor!` in [`tests`]) inherits the
    /// projection at no per-axis cost. The three trait-uniform laws
    /// pinned in [`tests`] hold across the implementor set
    /// (`axis_histogram_recessive_cell_empty_is_none_*`,
    /// `axis_histogram_recessive_cell_singleton_picks_observed_*`,
    /// `axis_histogram_recessive_cell_axis_cover_picks_first_*`).
    ///
    /// Peer to [`Self::dominant_cell`] (the *modal* cell on the maximum
    /// side) and [`Self::distinct_cells`] (the *count* of observed
    /// cells): the histogram surface now carries the natural triple of
    /// "*which* cell" / "*which other* cell" / "*how many* cells"
    /// projections over the observed support.
    #[must_use]
    pub fn recessive_cell(&self) -> Option<A> {
        let mut iter = self.iter().filter(|&(_, c)| c > 0);
        let first = iter.next()?;
        Some(
            iter.fold(
                first,
                |best, current| {
                    if current.1 < best.1 { current } else { best }
                },
            )
            .0,
        )
    }

    /// The maximum observation count across every cell of the closed
    /// axis — the **height of the histogram's peak**. Returns `0` exactly
    /// when [`Self::is_empty`] is `true`; otherwise returns the count
    /// carried by [`Self::dominant_cell`] (and pointwise equal to it).
    ///
    /// The "scalar peer" of [`Self::dominant_cell`] on the count side —
    /// the natural typed primitive for diagnostic dumps, dashboards, and
    /// attestation manifests asking *"how many observations did the
    /// dominant cell collect?"*: the dominant-format observation count in
    /// a chain's [`crate::ConfigSourceChain::file_format_histogram`]
    /// (the "47 of 53 layers were `.yaml`" headline number), the
    /// dominant-error count in a per-window
    /// `AxisHistogram<crate::ShikumiErrorKind>` (the "12 of 14 reload
    /// failures were Parse this window" alarm-threshold input), the
    /// peak-layer-kind count in a chain's
    /// [`crate::ConfigSourceChain::layer_kind_histogram`] (the operator
    /// table's "the chain's heaviest layer kind fired N times" cell).
    /// Before this lift, every such consumer re-derived the projection
    /// inline as `hist.dominant_cell().map_or(0, |c| hist.count(c))` —
    /// which walked the histogram *twice* (once to argmax, once to read
    /// the count back through the [`Self::count`] indexing). The lift
    /// names the scalar at one site with a single pass over the counts
    /// vector.
    ///
    /// **Empty-histogram convention** — returns `0` (not `Option<usize>`)
    /// matching the [`Self::total`] and [`Self::distinct_cells`] empty
    /// conventions; the scalar peer triple `(total, distinct_cells,
    /// peak_count)` is therefore uniformly `(0, 0, 0)` on the empty
    /// histogram. The dual-form `dominant_cell` carries `Option<A>`
    /// because the *cell* is undefined when no observation has landed;
    /// the *count* is well-defined as zero on the empty cells of the
    /// vector. The asymmetry is intentional: every scalar projection
    /// reads zero on empty; every cell projection reads `None`.
    ///
    /// **Closes the (cell, count) modal pair** with [`Self::dominant_cell`]:
    /// `(dominant_cell(), peak_count())` reads off the histogram's peak
    /// as a typed `(Option<A>, usize)` pair. When [`Self::dominant_cell`]
    /// is `Some(v)`, `self.count(v) == self.peak_count()` (the dominant
    /// cell's count equals the maximum). When [`Self::dominant_cell`] is
    /// `None`, `peak_count() == 0` and the pair witnesses the
    /// empty-histogram boundary uniformly.
    ///
    /// **Companion invariants** with [`Self::total`],
    /// [`Self::distinct_cells`], [`Self::dominant_cell`], and
    /// [`Self::recessive_cell`]:
    /// - `peak_count() == 0` ⇔ [`Self::is_empty`] is `true`
    ///   (peer to the empty-histogram boundary [`Self::distinct_cells`]
    ///   and [`Self::dominant_cell`] both carry).
    /// - `peak_count() <= total()` always: the peak is bounded above by
    ///   the multiset's size (every cell contributes at most every
    ///   observation, and the others contribute zero — equality holds
    ///   when [`Self::distinct_cells`] is `1`).
    /// - `peak_count() == total()` iff `distinct_cells() <= 1`: a single
    ///   observed cell carries every observation, so the peak equals
    ///   the total. Distinct = 0 (empty) reads 0 == 0; distinct = 1
    ///   reads N == N; distinct >= 2 reads peak < total strictly.
    /// - `peak_count() >= recessive_count` whenever the histogram is
    ///   non-empty, where `recessive_count =
    ///   count(recessive_cell().unwrap())`: the dominant count bounds
    ///   the rarest-observed count above (peer to the
    ///   `count(recessive_cell) <= count(dominant_cell)` invariant on
    ///   [`Self::recessive_cell`]).
    /// - `merge(self, other).peak_count() >=
    ///   self.peak_count().max(other.peak_count())`: the peak is
    ///   monotone under [`Self::merge`] — merging adds counts pointwise,
    ///   and adding non-negative deltas to the larger side's peak cell
    ///   cannot shrink it. The peer to the monotone-support law on
    ///   [`Self::distinct_cells`] and the monotone-coverage law on
    ///   [`Self::unobserved`].
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor (the twenty
    /// closed-enum axis primitives plus the five product cubes —
    /// twenty-five today, reached uniformly through
    /// `for_each_closed_axis_implementor!` in [`tests`]) inherits the
    /// projection at no per-axis cost. The three trait-uniform laws
    /// pinned in [`tests`] hold across the implementor set
    /// (`axis_histogram_peak_count_empty_is_zero_*`,
    /// `axis_histogram_peak_count_singleton_is_one_*`,
    /// `axis_histogram_peak_count_axis_cover_is_one_*`).
    ///
    /// Peer to [`Self::total`] (the *sum* over every cell) and
    /// [`Self::distinct_cells`] (the *support cardinality*): the scalar
    /// surface of the histogram now carries the natural triple of
    /// `(how many observations, how many kinds, how many on the peak)`
    /// projections — every operator-facing summary reads off one method
    /// call each.
    #[must_use]
    pub fn peak_count(&self) -> usize {
        self.counts.iter().copied().max().unwrap_or(0)
    }

    /// The **modal observation** — the `(cell, count)` pair at the
    /// histogram's peak. `None` when [`Self::is_empty`] is `true`;
    /// otherwise `Some((cell, count))` where `cell ==
    /// dominant_cell().unwrap()` and `count == peak_count()`. Closes
    /// the *fused* form of the `(dominant_cell, peak_count)` modal
    /// pair the histogram surface previously carried as two coordinated
    /// reads of shape `(Option<A>, usize)`.
    ///
    /// The natural typed primitive for diagnostic dumps, dashboards,
    /// and attestation manifests that need *both* the modal cell and
    /// its observation count in the same diagnostic — the dashboard
    /// line reading `"format: yaml (×47)"` from a chain's
    /// [`crate::ConfigSourceChain::file_format_histogram`], the
    /// alarm-threshold check `"if modal error class fires ≥ 12
    /// times"` against a per-window
    /// `AxisHistogram<crate::ShikumiErrorKind>`, the structured-log
    /// field `{kind, count}` recording the dominant diff-line class
    /// from [`crate::ConfigDiff::kind_histogram`]. Before this lift,
    /// every such consumer paired two method calls —
    /// `(hist.dominant_cell(), hist.peak_count())` — yielding the
    /// awkward `(Option<A>, usize)` shape where the `usize` carries no
    /// structural signal about the empty case (it reads `0` on empty
    /// by the `peak_count` empty convention, but the consumer has to
    /// check the `Option<A>` separately to know whether the `0`
    /// reflects "no observations" or "one observation on cell K" — the
    /// latter never happens since a single observation always reads
    /// `peak_count >= 1`, but the type system does not enforce that).
    /// The lift collapses the pair into the natural `Option<(A,
    /// usize)>` shape with one discriminant at the empty boundary, one
    /// method call, and one single-pass scan over the counts vector
    /// (the same fold [`Self::dominant_cell`] runs, but returning the
    /// pair instead of stripping the count).
    ///
    /// **Tie-breaking** — pointwise inherits the
    /// [`Self::dominant_cell`] declaration-order tie-break: when
    /// multiple cells share the peak count, the cell earliest in
    /// [`ClosedAxis::ALL`] wins. The fused pair therefore reads
    /// identically to the open-coded
    /// `dominant_cell().map(|c| (c, peak_count()))` form on every
    /// histogram — the lift adds no semantic, only structural
    /// composition.
    ///
    /// **Companion invariants** with [`Self::dominant_cell`],
    /// [`Self::peak_count`], and [`Self::is_empty`]:
    /// - `dominant_observation().map(|(c, _)| c) == dominant_cell()`
    ///   always — the cell projection of the fused pair equals
    ///   [`Self::dominant_cell`] pointwise on every histogram (both
    ///   sides agree on the empty case at `None == None` and on the
    ///   non-empty case at `Some(first-max) == Some(first-max)`).
    /// - `dominant_observation().map_or(0, |(_, n)| n) ==
    ///   peak_count()` always — the count projection of the fused
    ///   pair equals [`Self::peak_count`] pointwise on every
    ///   histogram (empty: `None.map_or(0, …) == 0 == peak_count`;
    ///   non-empty: `Some(peak).map_or(0, …) == peak == peak_count`).
    /// - `dominant_observation().is_none() ⇔ is_empty()` —
    ///   one-discriminant empty boundary on the fused pair.
    /// - When non-empty, the pair's count equals
    ///   `self.count(self.dominant_observation().unwrap().0)` — the
    ///   peak-count consistency law.
    /// - The merge composition
    ///   `merge(self, other).dominant_observation().map_or(0, |(_, n)| n) >= self.peak_count().max(other.peak_count())`
    ///   pins monotonicity under [`Self::merge`] (inherited from
    ///   [`Self::peak_count`]).
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor (the twenty
    /// closed-enum axis primitives plus the five product cubes —
    /// twenty-five today, reached uniformly through
    /// `for_each_closed_axis_implementor!` in [`tests`]) inherits the
    /// projection at no per-axis cost. The three trait-uniform laws
    /// pinned in [`tests`] hold across the implementor set
    /// (`axis_histogram_dominant_observation_empty_is_none_*`,
    /// `axis_histogram_dominant_observation_singleton_picks_observed_pair_*`,
    /// `axis_histogram_dominant_observation_axis_cover_picks_first_pair_*`).
    ///
    /// Peer to [`Self::dominant_cell`] (the *cell* projection of the
    /// modal pair) and [`Self::peak_count`] (the *count* projection of
    /// the modal pair): the histogram surface now carries the (cell,
    /// count, pair) triple on the peak side — every consumer that
    /// needs either side reads the named projection, every consumer
    /// that needs both sides reads the fused pair at one method call.
    #[must_use]
    pub fn dominant_observation(&self) -> Option<(A, usize)> {
        let mut iter = self.iter().filter(|&(_, c)| c > 0);
        let first = iter.next()?;
        Some(iter.fold(
            first,
            |best, current| {
                if current.1 > best.1 { current } else { best }
            },
        ))
    }

    /// The **cardinality of the modal level set** — the number of axis
    /// cells whose observation count equals the histogram's peak. Returns
    /// `0` exactly when [`Self::is_empty`] is `true`; otherwise returns
    /// the count of cells `c` with `count(c) == peak_count() > 0`.
    ///
    /// The "how many cells share the peak" scalar projection on the
    /// histogram surface — the *cardinality peer* of [`Self::dominant_cell`]
    /// (which picks one tied cell by declaration order) and the
    /// *multiplicity peer* of [`Self::peak_count`] (which reads the
    /// shared count itself). Closes the modal-side projection triple
    /// `(dominant_cell, peak_count, peak_multiplicity)` — *"which cell
    /// (one), what count (one), how many cells (k)"* — every consumer-
    /// facing summary now reads each projection at one method call.
    ///
    /// The natural typed primitive for diagnostic dumps, dashboards,
    /// attestation manifests, and outlier classifiers asking *"is the
    /// dominant cell unique, or is the peak shared?"*: the *unique-modal*
    /// classifier on a per-window `AxisHistogram<crate::ShikumiErrorKind>`
    /// (the "Parse fired 12× alone" vs "Parse and Io fired 12× each"
    /// diagnostic), the *tie-detector* on a chain's
    /// [`crate::ConfigSourceChain::file_format_histogram`] (the "is one
    /// format strictly dominant, or are two tied at the top?" gate), the
    /// *modality-degree* attestation on
    /// [`crate::ConfigSourceChain::layer_kind_histogram`] (the "the
    /// chain's heaviest layer kind fired uniquely / k-way-tied" cell on
    /// the operator table). Before this lift, every such consumer
    /// re-derived the projection inline as
    /// `hist.iter().filter(|&(_, c)| c > 0 && c == hist.peak_count()).count()`
    /// — a two-pass scan (one to find the peak, one to count ties at
    /// it), with the silent re-derivation of [`Self::peak_count`] at
    /// every call site and the implicit dependence on the
    /// `count > 0` guard to exclude zero-count cells (which would
    /// otherwise be trivially tied with `peak_count()` on the empty
    /// histogram, since `peak_count() == 0` would shadow every cell as a
    /// false-positive tie). The lift collapses the projection to one
    /// method call with a single-pass `O(axis_cardinality)` scan that
    /// tracks the running max and reset-on-rise count in one fold,
    /// excluding zero-count cells by construction (the first nonzero
    /// count promotes the count past `0`, after which `c > max`
    /// resets and `c == max && c > 0` increments).
    ///
    /// **Empty-histogram convention** — returns `0` (not `Option<usize>`)
    /// matching the [`Self::peak_count`], [`Self::trough_count`],
    /// [`Self::total`], [`Self::distinct_cells`], and [`Self::spread`]
    /// empty conventions; the scalar peer sextuple
    /// `(total, distinct_cells, peak_count, trough_count, spread,
    /// peak_multiplicity)` is uniformly `(0, 0, 0, 0, 0, 0)` on the
    /// empty histogram. The dual-form [`Self::dominant_cell`] carries
    /// `Option<A>` because the *cell* is undefined when no observation
    /// has landed; every scalar projection on the histogram reads `0` on
    /// empty.
    ///
    /// **Unique-modal predicate.** `peak_multiplicity() == 1` is the
    /// typed *strictly-dominant* predicate on the histogram surface:
    /// the dominant cell stands alone at the peak (no tie). Pointwise
    /// equivalent to the open-coded `hist.iter().filter(|&(_, c)|
    /// c > 0 && c == hist.peak_count()).count() == 1` form, but
    /// surfaced as a named scalar that future predicates and gates
    /// route through. The contrapositive `peak_multiplicity() >= 2` is
    /// the *tied-modal* predicate — the declaration-order tie-break in
    /// [`Self::dominant_cell`] is actually exercised exactly when this
    /// fires.
    ///
    /// **Companion invariants** with [`Self::peak_count`],
    /// [`Self::dominant_cell`], [`Self::distinct_cells`],
    /// [`Self::is_empty`], and [`Self::is_uniform_count`]:
    /// - `peak_multiplicity() == 0` ⇔ [`Self::is_empty`] is `true`
    ///   (peer to the empty-histogram boundary [`Self::peak_count`] and
    ///   [`Self::distinct_cells`] both carry).
    /// - `peak_multiplicity() <= distinct_cells()` always: the modal
    ///   level set is a subset of the observed support, so its
    ///   cardinality is bounded above by the support cardinality.
    ///   Equality holds iff [`Self::is_uniform_count`] is `true`
    ///   (every observed cell is at the same count, so every observed
    ///   cell is in the modal level set).
    /// - `peak_multiplicity() >= 1` whenever the histogram is
    ///   non-empty: the dominant cell witnesses one member of the
    ///   modal level set, so the count is at least `1`.
    /// - `is_uniform_count() ⇒ peak_multiplicity() == distinct_cells()`
    ///   — on a uniformly-observed-count histogram, every observed
    ///   cell sits at the shared peak. Pointwise equivalent to
    ///   `distinct_cells() == 1` whenever
    ///   `has_singular_support()` is true.
    /// - `has_singular_support() ⇒ peak_multiplicity() == 1` — a
    ///   single observed cell is the only member of the modal level
    ///   set on that histogram.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor inherits the
    /// projection at no per-axis cost. The three trait-uniform laws
    /// pinned in [`tests`] hold across the implementor set
    /// (`axis_histogram_peak_multiplicity_empty_is_zero_*`,
    /// `axis_histogram_peak_multiplicity_singleton_is_one_*`,
    /// `axis_histogram_peak_multiplicity_axis_cover_is_axis_cardinality_*`).
    ///
    /// Peer to [`Self::dominant_cell`] (the *cell* projection picking
    /// one tied member), [`Self::peak_count`] (the *count* shared by
    /// the modal level set), and [`Self::dominant_observation`] (the
    /// fused `(cell, count)` pair): the histogram's modal surface now
    /// carries the (cell, count, fused-pair, multiplicity) quadruple —
    /// every operator-facing summary reads the named projection it
    /// needs at one method call each, and the *tie-detector*
    /// `peak_multiplicity() >= 2` predicate reads off as a single
    /// scalar comparison.
    #[must_use]
    pub fn peak_multiplicity(&self) -> usize {
        let mut max = 0usize;
        let mut multiplicity = 0usize;
        for &c in &self.counts {
            if c > max {
                max = c;
                multiplicity = 1;
            } else if c == max && c > 0 {
                multiplicity += 1;
            }
        }
        multiplicity
    }

    /// The minimum observation count across the histogram's *observed*
    /// support — the **height of the histogram's trough**. Returns `0`
    /// exactly when [`Self::is_empty`] is `true`; otherwise returns the
    /// count carried by [`Self::recessive_cell`] (and pointwise equal to
    /// it).
    ///
    /// The "scalar peer" of [`Self::recessive_cell`] on the count side —
    /// the structural dual of [`Self::peak_count`] on the *minority*
    /// side. The natural typed primitive for diagnostic dumps,
    /// dashboards, and attestation manifests asking *"how many
    /// observations did the rarest observed cell collect?"*: the
    /// rarest-format observation count in a chain's
    /// [`crate::ConfigSourceChain::file_format_histogram`] (the "the
    /// chain's least-used file format fired N times" cell), the
    /// rarest-error count in a per-window
    /// `AxisHistogram<crate::ShikumiErrorKind>` (the floor of the
    /// observed error-class distribution), the trough-layer-kind count
    /// in a chain's [`crate::ConfigSourceChain::layer_kind_histogram`]
    /// (the operator table's "the chain's lightest layer kind fired N
    /// times" cell). Before this lift, every such consumer re-derived
    /// the projection inline as
    /// `hist.recessive_cell().map_or(0, |c| hist.count(c))` — which
    /// walked the histogram *twice* (once to argmin over the support,
    /// once to read the count back through the [`Self::count`]
    /// indexing). The lift names the scalar at one site with a single
    /// pass over the counts vector.
    ///
    /// **Zero cells are excluded from the search.** The minimum is
    /// taken over the histogram's *support* (the set of observed cells),
    /// not over the full axis. Zero-count cells are trivially the
    /// minimum over the full axis and would shadow the rarest-observed
    /// count; excluding them surfaces the count of the rarest cell some
    /// observation actually fell on — the question the rendering,
    /// diagnostic, and dashboard sites ask. This matches
    /// [`Self::recessive_cell`]'s zero-cell-exclusion rule pointwise so
    /// the `(recessive_cell(), trough_count())` pair reads off the
    /// histogram's trough consistently with [`Self::peak_count`] /
    /// [`Self::dominant_cell`] reading the peak.
    ///
    /// **Empty-histogram convention** — returns `0` (not
    /// `Option<usize>`) matching the [`Self::total`],
    /// [`Self::distinct_cells`], and [`Self::peak_count`] empty
    /// conventions; the scalar peer quadruple `(total, distinct_cells,
    /// peak_count, trough_count)` is therefore uniformly `(0, 0, 0, 0)`
    /// on the empty histogram. The dual-form [`Self::recessive_cell`]
    /// carries `Option<A>` because the *cell* is undefined when no
    /// observation has landed; the *count* is well-defined as zero on
    /// the empty cells of the vector. The asymmetry is intentional and
    /// pointwise consistent with the `(peak_count, dominant_cell)` pair.
    ///
    /// **Closes the (cell, count) modal pair** with
    /// [`Self::recessive_cell`]:
    /// `(recessive_cell(), trough_count())` reads off the histogram's
    /// trough as a typed `(Option<A>, usize)` pair, pointwise dual to
    /// `(dominant_cell(), peak_count())` reading the peak. When
    /// [`Self::recessive_cell`] is `Some(v)`,
    /// `self.count(v) == self.trough_count()` (the recessive cell's
    /// count equals the minimum-over-support). When
    /// [`Self::recessive_cell`] is `None`, `trough_count() == 0` and
    /// the pair witnesses the empty-histogram boundary uniformly.
    ///
    /// **Companion invariants** with [`Self::total`],
    /// [`Self::distinct_cells`], [`Self::peak_count`],
    /// [`Self::dominant_cell`], and [`Self::recessive_cell`]:
    /// - `trough_count() == 0` ⇔ [`Self::is_empty`] is `true`
    ///   (peer to the empty-histogram boundary [`Self::peak_count`],
    ///   [`Self::distinct_cells`], and [`Self::dominant_cell`] all
    ///   carry).
    /// - `trough_count() <= peak_count()` always: the trough is bounded
    ///   above by the peak (the minimum over a non-empty support is
    ///   bounded above by the maximum over the same support). Equality
    ///   holds iff every observed cell carries the same count (the
    ///   *uniform-observed-count* shape — every singleton-support
    ///   histogram, every uniform axis-cover histogram, every
    ///   `k`-cell histogram observed `k` times each-once).
    /// - `trough_count() >= 1` whenever the histogram is non-empty:
    ///   every observed cell carries at least one observation by
    ///   construction, so the minimum over the support is at least
    ///   one. The peer to the `peak_count() >= 1` non-emptiness floor.
    /// - The merge behavior is *non-monotonic* (in deliberate contrast
    ///   to [`Self::peak_count`]'s strict monotonicity under
    ///   [`Self::merge`]): merging two histograms can either grow the
    ///   trough (when the supports coincide, every cell's count grows
    ///   and so does the minimum) or shrink it (when one side observes
    ///   a cell the other does not, the new cell enters the merged
    ///   support carrying that side's count and can pull the merged
    ///   trough below either side's). The empty-identity law still
    ///   holds: `merge(self, empty).trough_count() == self.trough_count()`.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor (the twenty
    /// closed-enum axis primitives plus the five product cubes —
    /// twenty-five today, reached uniformly through
    /// `for_each_closed_axis_implementor!` in [`tests`]) inherits the
    /// projection at no per-axis cost. The three trait-uniform laws
    /// pinned in [`tests`] hold across the implementor set
    /// (`axis_histogram_trough_count_empty_is_zero_*`,
    /// `axis_histogram_trough_count_singleton_is_one_*`,
    /// `axis_histogram_trough_count_axis_cover_is_one_*`).
    ///
    /// Peer to [`Self::total`] (the *sum* over every cell),
    /// [`Self::distinct_cells`] (the *support cardinality*), and
    /// [`Self::peak_count`] (the *modal-count scalar* on the majority
    /// side): the scalar surface of the histogram now carries the
    /// natural quadruple of
    /// `(how many observations, how many kinds, how many on the peak,
    /// how many on the trough)` projections — every operator-facing
    /// summary reads off one method call each, and the *spread* of the
    /// observed distribution (`peak_count - trough_count`) reads off a
    /// single subtraction on the closed scalar surface.
    #[must_use]
    pub fn trough_count(&self) -> usize {
        self.counts
            .iter()
            .copied()
            .filter(|&c| c > 0)
            .min()
            .unwrap_or(0)
    }

    /// The **recessive observation** — the `(cell, count)` pair at the
    /// histogram's trough. `None` when [`Self::is_empty`] is `true`;
    /// otherwise `Some((cell, count))` where `cell ==
    /// recessive_cell().unwrap()` and `count == trough_count()`. Closes
    /// the *fused* form of the `(recessive_cell, trough_count)` minority
    /// pair the histogram surface previously carried as two coordinated
    /// reads of shape `(Option<A>, usize)`, dual to the
    /// [`Self::dominant_observation`] fusion on the majority side.
    ///
    /// The natural typed primitive for diagnostic dumps, dashboards,
    /// and attestation manifests that need *both* the rarest-observed
    /// cell and its observation count in the same diagnostic — the
    /// dashboard line reading `"rarest format: lisp (×1)"` from a
    /// chain's [`crate::ConfigSourceChain::file_format_histogram`], the
    /// `"trough error class: Io (×1) — heavy-tail tip"` summary against
    /// a per-window `AxisHistogram<crate::ShikumiErrorKind>`, the
    /// structured-log field `{rarest_kind, count}` recording the
    /// trough diff-line class from
    /// [`crate::ConfigDiff::kind_histogram`]. Before this lift, every
    /// such consumer paired two method calls —
    /// `(hist.recessive_cell(), hist.trough_count())` — yielding the
    /// awkward `(Option<A>, usize)` shape where the `usize` carries no
    /// structural signal about the empty case (it reads `0` on empty
    /// by the `trough_count` empty convention, but the consumer has to
    /// check the `Option<A>` separately to know whether the `0`
    /// reflects "no observations" or some cell at count zero — the
    /// latter never happens since `trough_count` searches the positive
    /// support, so a non-empty histogram always reads `trough_count >=
    /// 1`, but the type system does not enforce that). The lift
    /// collapses the pair into the natural `Option<(A, usize)>` shape
    /// with one discriminant at the empty boundary, one method call,
    /// and one single-pass scan over the counts vector (the same fold
    /// [`Self::recessive_cell`] runs, but returning the pair instead
    /// of stripping the count).
    ///
    /// **Tie-breaking** — pointwise inherits the
    /// [`Self::recessive_cell`] declaration-order tie-break: when
    /// multiple cells share the trough count, the cell earliest in
    /// [`ClosedAxis::ALL`] wins. The fused pair therefore reads
    /// identically to the open-coded
    /// `recessive_cell().map(|c| (c, trough_count()))` form on every
    /// histogram — the lift adds no semantic, only structural
    /// composition.
    ///
    /// **Companion invariants** with [`Self::recessive_cell`],
    /// [`Self::trough_count`], and [`Self::is_empty`]:
    /// - `recessive_observation().map(|(c, _)| c) == recessive_cell()`
    ///   always — the cell projection of the fused pair equals
    ///   [`Self::recessive_cell`] pointwise on every histogram (both
    ///   sides agree on the empty case at `None == None` and on the
    ///   non-empty case at `Some(first-min) == Some(first-min)`).
    /// - `recessive_observation().map_or(0, |(_, n)| n) ==
    ///   trough_count()` always — the count projection of the fused
    ///   pair equals [`Self::trough_count`] pointwise on every
    ///   histogram (empty: `None.map_or(0, …) == 0 == trough_count`;
    ///   non-empty: `Some(trough).map_or(0, …) == trough == trough_count`).
    /// - `recessive_observation().is_none() ⇔ is_empty()` —
    ///   one-discriminant empty boundary on the fused pair.
    /// - When non-empty, the pair's count equals
    ///   `self.count(self.recessive_observation().unwrap().0)` — the
    ///   trough-count consistency law.
    /// - When non-empty, the pair's count is at least `1` — the
    ///   recessive-count floor (every observed cell carries at least
    ///   one observation by construction, inherited from
    ///   [`Self::trough_count`]).
    /// - `recessive_observation().map_or(0, |(_, n)| n) <= dominant_observation().map_or(0, |(_, n)| n)`
    ///   always — the trough-count is bounded above by the peak-count
    ///   on every histogram, lifted to the fused-pair surface from
    ///   the `trough_count <= peak_count` invariant.
    /// - The merge composition is *non-monotonic* in count (in
    ///   deliberate contrast to [`Self::dominant_observation`]'s
    ///   count-monotonicity under [`Self::merge`]): merging can either
    ///   grow the trough (overlapping supports) or shrink it (disjoint
    ///   supports introduce a new low-count cell). The empty-identity
    ///   law still holds:
    ///   `merge(self, empty).recessive_observation() ==
    ///   self.recessive_observation()`.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor (the twenty
    /// closed-enum axis primitives plus the five product cubes —
    /// twenty-five today, reached uniformly through
    /// `for_each_closed_axis_implementor!` in [`tests`]) inherits the
    /// projection at no per-axis cost. The three trait-uniform laws
    /// pinned in [`tests`] hold across the implementor set
    /// (`axis_histogram_recessive_observation_empty_is_none_*`,
    /// `axis_histogram_recessive_observation_singleton_picks_observed_pair_*`,
    /// `axis_histogram_recessive_observation_axis_cover_picks_first_pair_*`).
    ///
    /// Peer to [`Self::recessive_cell`] (the *cell* projection of the
    /// minority pair) and [`Self::trough_count`] (the *count*
    /// projection of the minority pair): the histogram surface now
    /// carries the (cell, count, pair) triple on both the peak and
    /// trough sides — every consumer that needs either side reads the
    /// named projection, every consumer that needs both sides reads
    /// the fused pair at one method call. The
    /// `(dominant_observation, recessive_observation)` lattice on the
    /// fused-pair surface mirrors the
    /// `(dominant_cell, recessive_cell)` lattice on the cell surface
    /// and the `(peak_count, trough_count)` lattice on the scalar
    /// surface.
    #[must_use]
    pub fn recessive_observation(&self) -> Option<(A, usize)> {
        let mut iter = self.iter().filter(|&(_, c)| c > 0);
        let first = iter.next()?;
        Some(iter.fold(
            first,
            |best, current| {
                if current.1 < best.1 { current } else { best }
            },
        ))
    }

    /// The **cardinality of the antimodal level set** — the number of
    /// axis cells whose observation count equals the histogram's trough.
    /// Returns `0` exactly when [`Self::is_empty`] is `true`; otherwise
    /// returns the count of cells `c` with `count(c) == trough_count() >
    /// 0`.
    ///
    /// The "how many cells share the trough" scalar projection on the
    /// histogram surface — the *cardinality peer* of
    /// [`Self::recessive_cell`] (which picks one tied cell by declaration
    /// order) and the *multiplicity peer* of [`Self::trough_count`]
    /// (which reads the shared count itself). Closes the trough-side
    /// projection quadruple `(recessive_cell, trough_count,
    /// recessive_observation, trough_multiplicity)` — *"which cell
    /// (one), what count (one), fused pair (one), how many cells (k)"* —
    /// every consumer-facing summary now reads each projection at one
    /// method call. Structural dual of [`Self::peak_multiplicity`] on
    /// the majority side: body is the same single-pass argmin fold over
    /// `iter().filter(c > 0)` (running min reset-on-fall, increment-on-
    /// tie) — pointwise the antimodal-side answer to the "how many cells
    /// share the extreme observation count?" question the majority side
    /// names through [`Self::peak_multiplicity`].
    ///
    /// The natural typed primitive for diagnostic dumps, dashboards,
    /// attestation manifests, and outlier classifiers asking *"is the
    /// recessive cell unique, or is the trough shared?"*: the
    /// *unique-trough* classifier on a per-window
    /// `AxisHistogram<crate::ShikumiErrorKind>` (the "rarest Io fired
    /// once alone" vs "Io and Parse both fired once each as the trough"
    /// diagnostic), the *tie-detector* on a chain's
    /// [`crate::ConfigSourceChain::file_format_histogram`] (the "is one
    /// format strictly rarest, or are two tied at the bottom?" gate),
    /// the *antimodality-degree* attestation on
    /// [`crate::ConfigSourceChain::layer_kind_histogram`] (the "the
    /// chain's lightest layer kind fired uniquely / k-way-tied" cell on
    /// the operator table). Before this lift, every such consumer
    /// re-derived the projection inline as
    /// `hist.iter().filter(|&(_, c)| c > 0 && c == hist.trough_count()).count()`
    /// — a two-pass scan (one to find the trough, one to count ties at
    /// it), with the silent re-derivation of [`Self::trough_count`] at
    /// every call site and the implicit dependence on the
    /// `count > 0` guard to exclude zero-count cells (which would
    /// otherwise be trivially tied with `trough_count()` on the empty
    /// histogram, since `trough_count() == 0` would shadow every cell as
    /// a false-positive tie — the same `c > 0` guard load-bearing on
    /// the modal side through [`Self::peak_multiplicity`]). The lift
    /// collapses the projection to one method call with a single-pass
    /// `O(axis_cardinality)` scan that tracks the running min and
    /// reset-on-fall count in one fold, excluding zero-count cells by
    /// construction (`c == 0` skip, `c < min` reset, `c == min`
    /// increment, with `min` initialized to `usize::MAX` so the first
    /// positive count promotes the running min off the sentinel).
    ///
    /// **Empty-histogram convention** — returns `0` (not `Option<usize>`)
    /// matching the [`Self::peak_count`], [`Self::trough_count`],
    /// [`Self::total`], [`Self::distinct_cells`], [`Self::spread`], and
    /// [`Self::peak_multiplicity`] empty conventions; the scalar peer
    /// septuple `(total, distinct_cells, peak_count, trough_count,
    /// spread, peak_multiplicity, trough_multiplicity)` is uniformly
    /// `(0, 0, 0, 0, 0, 0, 0)` on the empty histogram. The dual-form
    /// [`Self::recessive_cell`] carries `Option<A>` because the *cell*
    /// is undefined when no observation has landed; every scalar
    /// projection on the histogram reads `0` on empty.
    ///
    /// **Unique-trough predicate.** `trough_multiplicity() == 1` is the
    /// typed *strictly-recessive* predicate on the histogram surface:
    /// the recessive cell stands alone at the trough (no tie). Pointwise
    /// equivalent to the open-coded `hist.iter().filter(|&(_, c)|
    /// c > 0 && c == hist.trough_count()).count() == 1` form, but
    /// surfaced as a named scalar that future predicates and gates
    /// route through. The contrapositive `trough_multiplicity() >= 2`
    /// is the *tied-trough* predicate — the declaration-order tie-break
    /// in [`Self::recessive_cell`] is actually exercised exactly when
    /// this fires, peer to the [`Self::peak_multiplicity`] tie-detector
    /// on the modal side.
    ///
    /// **Companion invariants** with [`Self::trough_count`],
    /// [`Self::recessive_cell`], [`Self::distinct_cells`],
    /// [`Self::is_empty`], [`Self::is_uniform_count`], and
    /// [`Self::peak_multiplicity`]:
    /// - `trough_multiplicity() == 0` ⇔ [`Self::is_empty`] is `true`
    ///   (peer to the empty-histogram boundary [`Self::trough_count`],
    ///   [`Self::peak_multiplicity`], and [`Self::distinct_cells`] all
    ///   carry).
    /// - `trough_multiplicity() <= distinct_cells()` always: the
    ///   antimodal level set is a subset of the observed support, so
    ///   its cardinality is bounded above by the support cardinality.
    ///   Equality holds iff [`Self::is_uniform_count`] is `true` (every
    ///   observed cell is at the same count, so every observed cell is
    ///   in the antimodal level set — and simultaneously in the modal
    ///   level set, since peak and trough coincide).
    /// - `trough_multiplicity() >= 1` whenever the histogram is
    ///   non-empty: the recessive cell witnesses one member of the
    ///   antimodal level set, so the count is at least `1`.
    /// - `is_uniform_count() ⇒ trough_multiplicity() ==
    ///   peak_multiplicity() == distinct_cells()` — on a uniformly-
    ///   observed-count histogram, every observed cell sits at the
    ///   shared peak *and* the shared trough (the peak and trough
    ///   coincide), so both multiplicities collapse to the support
    ///   cardinality. The structural equality between the modal and
    ///   antimodal level sets on the uniform-count shape.
    /// - `has_singular_support() ⇒ trough_multiplicity() == 1` — a
    ///   single observed cell is the only member of the antimodal
    ///   level set on that histogram (and simultaneously the only
    ///   member of the modal level set).
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor inherits the
    /// projection at no per-axis cost. The three trait-uniform laws
    /// pinned in [`tests`] hold across the implementor set
    /// (`axis_histogram_trough_multiplicity_empty_is_zero_*`,
    /// `axis_histogram_trough_multiplicity_singleton_is_one_*`,
    /// `axis_histogram_trough_multiplicity_axis_cover_is_axis_cardinality_*`).
    ///
    /// Peer to [`Self::recessive_cell`] (the *cell* projection picking
    /// one tied member), [`Self::trough_count`] (the *count* shared by
    /// the antimodal level set), and [`Self::recessive_observation`]
    /// (the fused `(cell, count)` pair): the histogram's trough surface
    /// now carries the (cell, count, fused-pair, multiplicity)
    /// quadruple — every operator-facing summary reads the named
    /// projection it needs at one method call each, and the
    /// *tie-detector* `trough_multiplicity() >= 2` predicate reads off
    /// as a single scalar comparison. Closes the
    /// `(peak_multiplicity, trough_multiplicity)` modality-degree pair
    /// on the multiplicity surface, the bilateral peer of the
    /// `(peak_count, trough_count)` extremal-count pair on the scalar
    /// surface and the `(dominant_cell, recessive_cell)` extremal-cell
    /// pair on the cell surface.
    #[must_use]
    pub fn trough_multiplicity(&self) -> usize {
        let mut min = usize::MAX;
        let mut multiplicity = 0usize;
        for &c in &self.counts {
            if c == 0 {
                continue;
            }
            if c < min {
                min = c;
                multiplicity = 1;
            } else if c == min {
                multiplicity += 1;
            }
        }
        multiplicity
    }

    /// The **modality-degree pair** — the fused
    /// `(peak_multiplicity, trough_multiplicity)` projection on the
    /// histogram's multiplicity surface. Returns `(0, 0)` exactly when
    /// [`Self::is_empty`] is `true`; otherwise returns the cardinality
    /// of the modal level set in `.0` and the cardinality of the
    /// antimodal level set in `.1`.
    ///
    /// Closes the multiplicity-surface fusion the same way
    /// [`Self::dominant_observation`] and [`Self::recessive_observation`]
    /// close the (cell, count) fusion on the modal and antimodal cell
    /// surfaces. Where [`Self::peak_multiplicity`] reads *"how many
    /// cells share the peak?"* and [`Self::trough_multiplicity`] reads
    /// *"how many cells share the trough?"*, `modality_degree` reads the
    /// fused pair in a **single pass** over the contiguous counts
    /// vector — half the work of two independent
    /// `O(axis_cardinality)` scans — and names the joint projection at
    /// one site so a future *modality summary* dashboard line, a
    /// *modality-degree* attestation cell, or a *peer-tied* gate reads
    /// off one method call rather than two.
    ///
    /// The natural typed primitive for the modality-summary surface
    /// every operator-facing rebuild line, structured-diagnostic
    /// legend, and attestation manifest carries: the per-window
    /// `AxisHistogram<crate::ShikumiErrorKind>` reload-summary line
    /// (`"3 of 6 error classes fired at the peak (Parse / Io / Watch
    /// at 12× each); 1 class fired at the trough (Extract at 1×) —
    /// modality_degree = (3, 1)"`), the chain-shape summary on
    /// [`crate::ConfigSourceChain::file_format_histogram`] (`"2 formats
    /// share the chain peak, 1 sits at the trough"`), the
    /// `AxisHistogram<crate::DiffLineKind>` rebuild-summary
    /// (`"modality_degree = (2, 1) — added and removed tied at the
    /// peak, context the rarest"`). Before this lift, every consumer
    /// asking the joint *"how multiply tied are both extremes?"*
    /// question routed through two method calls (`peak_multiplicity()`
    /// and `trough_multiplicity()`), each doing a full single-pass
    /// scan over the counts vector — `O(2 · axis_cardinality)`
    /// pointwise. The fused projection collapses the work to one pass
    /// that tracks the running max + reset-on-rise modal multiplicity
    /// and the running min (initialized to `usize::MAX` so the first
    /// positive count promotes the sentinel) + reset-on-fall
    /// antimodal multiplicity simultaneously, excluding zero-count
    /// cells by construction so the empty boundary reads `(0, 0)`
    /// uniformly.
    ///
    /// **Empty-histogram convention** — returns `(0, 0)`, matching
    /// the [`Self::peak_multiplicity`] and [`Self::trough_multiplicity`]
    /// empty conventions pointwise. The fused scalar peer reads `(0, 0)`
    /// on every histogram on which `is_empty()` reads `true`, and
    /// strictly `(k, l)` with `k >= 1` and `l >= 1` on every non-empty
    /// histogram.
    ///
    /// **Definitional equivalence.** For every histogram `h`,
    /// `h.modality_degree() == (h.peak_multiplicity(), h.trough_multiplicity())`
    /// pointwise. The named primitive is *behaviorally indistinguishable*
    /// from the open-coded two-call pair on every input — the lift is
    /// pure efficiency + naming, with no semantic surface change.
    /// Pinned by the trait-uniform
    /// `axis_histogram_modality_degree_equals_open_coded_peak_trough_multiplicity_pair_*`
    /// law across every [`ClosedAxis`] implementor.
    ///
    /// **Modality classifier.** The fused pair lifts the *"how tied is
    /// the distribution at both extremes?"* question to a single
    /// scalar-pair read every operator-facing dashboard and
    /// attestation manifest routes through:
    /// - `(1, 1)` — *strictly unimodal, strictly anti-unimodal*: both
    ///   the dominant and recessive cells stand alone (the
    ///   declaration-order tie-break in [`Self::dominant_cell`] and
    ///   [`Self::recessive_cell`] is not exercised on either side).
    /// - `(k, 1)` with `k >= 2` — *modally tied, anti-unimodal*: the
    ///   peak is shared by `k` cells, but the trough is uniquely held.
    /// - `(1, l)` with `l >= 2` — *strictly unimodal, antimodally tied*:
    ///   the peak is uniquely held, but the trough is shared by `l`
    ///   cells.
    /// - `(k, k)` with `k == distinct_cells()` — *modal/antimodal
    ///   coincidence*: every observed cell sits at both the peak and
    ///   the trough simultaneously, the [`Self::is_uniform_count`]
    ///   shape — peak and trough collapse to the same value.
    ///
    /// **Companion invariants** with [`Self::peak_multiplicity`],
    /// [`Self::trough_multiplicity`], [`Self::distinct_cells`],
    /// [`Self::is_empty`], and [`Self::is_uniform_count`]:
    /// - `modality_degree() == (0, 0)` ⇔ [`Self::is_empty`] is `true`
    ///   (peer to the empty-histogram boundary equivalence both
    ///   underlying multiplicities carry).
    /// - `modality_degree().0 <= distinct_cells()` and
    ///   `modality_degree().1 <= distinct_cells()` always (both level
    ///   sets are subsets of the observed support).
    /// - `is_uniform_count() ⇒ modality_degree().0 ==
    ///   modality_degree().1 == distinct_cells()` — on a
    ///   uniformly-observed-count histogram, both level sets coincide
    ///   with the support; the peak and the trough collapse to the
    ///   same value, so every observed cell is in both level sets.
    /// - `has_singular_support() ⇒ modality_degree() == (1, 1)` — a
    ///   single observed cell is the only member of both level sets.
    /// - Both components are `>= 1` whenever the histogram is non-empty.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor inherits the
    /// projection at no per-axis cost. The four trait-uniform laws
    /// pinned in [`tests`] hold across the implementor set
    /// (`axis_histogram_modality_degree_empty_is_zero_pair_*`,
    /// `axis_histogram_modality_degree_singleton_is_one_pair_*`,
    /// `axis_histogram_modality_degree_axis_cover_is_axis_cardinality_pair_*`,
    /// `axis_histogram_modality_degree_equals_open_coded_peak_trough_multiplicity_pair_*`).
    ///
    /// Peer to [`Self::dominant_observation`] (the fused modal `(cell,
    /// count)` pair) and [`Self::recessive_observation`] (the fused
    /// antimodal `(cell, count)` pair): the histogram's modality
    /// surface now carries three fused projection pairs — modal
    /// `(cell, count)`, antimodal `(cell, count)`, and modal/antimodal
    /// `(multiplicity, multiplicity)` — every operator-facing summary
    /// reads the joint pair it needs at one method call each, and the
    /// *modality summary* dashboard line collapses to a single
    /// scalar-pair read on the closed multiplicity surface.
    #[must_use]
    pub fn modality_degree(&self) -> (usize, usize) {
        let mut max = 0usize;
        let mut peak_mult = 0usize;
        let mut min = usize::MAX;
        let mut trough_mult = 0usize;
        for &c in &self.counts {
            if c == 0 {
                continue;
            }
            if c > max {
                max = c;
                peak_mult = 1;
            } else if c == max {
                peak_mult += 1;
            }
            if c < min {
                min = c;
                trough_mult = 1;
            } else if c == min {
                trough_mult += 1;
            }
        }
        (peak_mult, trough_mult)
    }

    /// `true` exactly when the histogram's *modal* level set has
    /// cardinality one — exactly one observed cell sits at the peak.
    /// The **strict modal uniqueness** predicate on the histogram's
    /// multiplicity surface: the typed boolean witness for the question
    /// *"is the dominant cell uniquely held, or is the
    /// [`Self::dominant_cell`] declaration-order tie-break being
    /// exercised?"*
    ///
    /// Pointwise equivalent to two surface forms that previously had no
    /// single named boolean — `self.peak_multiplicity() == 1` (the
    /// multiplicity-scalar equality form, the canonical open-coded
    /// expression of the predicate), and `self.modality_degree().0 == 1`
    /// (the modality-pair projection-equality form, reading the modal
    /// component of the fused pair). Both forms do a full single-pass
    /// scan of the contiguous counts vector before the equality check;
    /// the named predicate carries the *same* single-pass scan body
    /// without changing asymptotic cost, but lifts the predicate to a
    /// named boolean every operator-facing summary, attestation
    /// manifest, and dashboard cell reads off at one method call.
    ///
    /// The natural typed primitive for the *"is there one dominant
    /// kind, or are several tied?"* question every reload-window
    /// diagnostic, attestation manifest, and dashboard cell asks: the
    /// `AxisHistogram<crate::ShikumiErrorKind>` reload-summary line
    /// (`"strictly modally unique: Parse alone at 12×"` vs.
    /// `"modally tied: Parse / Io / Watch tied at 12× each"` —
    /// reading the alarm-routing branch off one predicate instead of
    /// composing `peak_multiplicity() == 1`), the
    /// [`crate::ConfigSourceChain::file_format_histogram`] gate
    /// (`"file-format chain has a strictly unique dominant format"`
    /// — the input to a "the chain is unambiguously YAML / TOML / Nix"
    /// classifier), the `AxisHistogram<crate::DiffLineKind>` rebuild-
    /// summary (`"diff is strictly modally unique on the added line"`
    /// vs. a balanced added/removed window).
    ///
    /// **The modal/antimodal-uniqueness boolean pair.** Peer to
    /// [`Self::is_strictly_antimodally_unique`] (the antimodal-side
    /// uniqueness predicate, `trough_multiplicity() == 1`): the
    /// histogram's multiplicity-uniqueness boolean surface now carries
    /// the natural pair
    /// `(is_strictly_modally_unique, is_strictly_antimodally_unique)` —
    /// "is the peak uniquely held?", "is the trough uniquely held?" —
    /// each independently checkable, and together they pattern-match
    /// the four corners of the modality classifier at one paired
    /// boolean read on the closed multiplicity surface.
    ///
    /// **Empty-histogram convention** — returns `false`: the empty
    /// histogram has no observed cells, so the modal level set is empty
    /// (cardinality `0`, not `1`). The empty boundary is uniformly
    /// `(0, 0)` on [`Self::modality_degree`], so neither side of the
    /// uniqueness pair fires on the empty histogram. Symmetric with
    /// [`Self::has_singular_support`] returning `false` on empty.
    ///
    /// **Singleton-observation convention** — every singleton-support
    /// histogram has [`Self::modality_degree`] `(1, 1)`, so
    /// `is_strictly_modally_unique` reads `true` uniformly on every
    /// singleton across every implementor (the minimal-non-empty
    /// boundary witness).
    ///
    /// **Axis-cover convention** — observing every cell exactly once
    /// raises the modal multiplicity to `axis_cardinality::<A>()`, so
    /// `is_strictly_modally_unique` reads `true` iff
    /// `axis_cardinality::<A>() == 1` (no implementor today carries
    /// cardinality 1, so uniform axis-cover reads `false` uniformly
    /// across the implementor set). Stated as the conditional law so
    /// the witness is uniform across the implementor set without
    /// case-splitting on cardinality at the test site.
    ///
    /// **Companion invariants** with [`Self::peak_multiplicity`],
    /// [`Self::modality_degree`], [`Self::dominant_cell`],
    /// [`Self::dominant_observation`], [`Self::is_empty`],
    /// [`Self::has_singular_support`], and [`Self::is_uniform_count`]:
    /// - `is_strictly_modally_unique() ⇔ peak_multiplicity() == 1` —
    ///   the defining equivalence on the multiplicity scalar peer.
    /// - `is_strictly_modally_unique() ⇔ modality_degree().0 == 1` —
    ///   the modal-component form on the fused pair.
    /// - `is_empty() ⇒ !is_strictly_modally_unique()` — the empty
    ///   histogram has no modal cell, so the uniqueness predicate
    ///   never fires there. The contrapositive
    ///   `is_strictly_modally_unique() ⇒ !is_empty()` reads off the
    ///   non-emptiness witness for the *strictly unique modal cell*
    ///   side of the histogram.
    /// - `has_singular_support() ⇒ is_strictly_modally_unique()` — a
    ///   single observed cell is the only member of the modal level
    ///   set, vacuously uniquely held. The converse fails on every
    ///   strict-peak shape with two or more observed cells.
    /// - `is_uniform_count() ∧ !is_empty() ⇒
    ///   is_strictly_modally_unique() ⇔ has_singular_support()` —
    ///   when every observed cell shares the same count, the modal
    ///   level set equals the support, so the uniqueness predicate
    ///   collapses to the singular-support predicate. On a uniform
    ///   axis-cover with cardinality `>= 2`, both read `false`.
    /// - When `is_strictly_modally_unique()` reads `true`,
    ///   `dominant_observation()` is `Some((c, n))` for some unique
    ///   cell `c` carrying the peak count `n`, and the
    ///   declaration-order tie-break in [`Self::dominant_cell`] is
    ///   *not* exercised — the dominant cell is the only member of
    ///   the modal level set. The boolean lifts the "is the tie-break
    ///   exercised?" question off the histogram surface at one
    ///   method call.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor (the twenty
    /// closed-enum axis primitives plus the five product cubes —
    /// twenty-five today, reached uniformly through
    /// `for_each_closed_axis_implementor!` in [`tests`]) inherits the
    /// predicate at no per-axis cost. The trait-uniform laws pinned in
    /// [`tests`] hold across the implementor set
    /// (`axis_histogram_is_strictly_modally_unique_empty_is_false_*`,
    /// `axis_histogram_is_strictly_modally_unique_singleton_is_true_*`,
    /// `axis_histogram_is_strictly_modally_unique_axis_cover_iff_cardinality_is_one_*`,
    /// `axis_histogram_is_strictly_modally_unique_equals_open_coded_peak_multiplicity_eq_one_*`).
    ///
    /// Peer to [`Self::is_empty`], [`Self::is_uniform_count`],
    /// [`Self::has_singular_support`], and [`Self::is_full_cover`] on
    /// the histogram's named-boolean predicate surface: the surface
    /// now carries the *modal-uniqueness* boolean alongside the
    /// support-cardinality and uniform-count predicates, and the
    /// future `ModalityClass` classifier discriminating the four
    /// corners of [`Self::modality_degree`] reads its modal axis off
    /// this named predicate.
    #[must_use]
    pub fn is_strictly_modally_unique(&self) -> bool {
        self.peak_multiplicity() == 1
    }

    /// `true` exactly when the histogram's *antimodal* level set has
    /// cardinality one — exactly one observed cell sits at the trough.
    /// The **strict antimodal uniqueness** predicate on the histogram's
    /// multiplicity surface: the typed boolean witness for the question
    /// *"is the recessive cell uniquely held, or is the
    /// [`Self::recessive_cell`] declaration-order tie-break being
    /// exercised?"*
    ///
    /// Pointwise equivalent to two surface forms that previously had no
    /// single named boolean — `self.trough_multiplicity() == 1` (the
    /// multiplicity-scalar equality form, the canonical open-coded
    /// expression of the predicate), and `self.modality_degree().1 == 1`
    /// (the modality-pair projection-equality form, reading the antimodal
    /// component of the fused pair). Both forms do a full single-pass
    /// scan of the contiguous counts vector before the equality check;
    /// the named predicate carries the *same* single-pass scan body
    /// without changing asymptotic cost, but lifts the predicate to a
    /// named boolean every operator-facing summary, attestation
    /// manifest, and dashboard cell reads off at one method call.
    ///
    /// The natural typed primitive for the *"is there one solitary
    /// rarest kind, or are several tied at the trough?"* question every
    /// reload-window diagnostic, attestation manifest, and dashboard
    /// cell asks: the `AxisHistogram<crate::ShikumiErrorKind>`
    /// reload-summary line (`"strictly antimodally unique: Extract
    /// alone at 1×"` vs. `"antimodally tied: Extract / Watch tied at 1×
    /// each"` — reading the rare-kind-alarm branch off one predicate
    /// instead of composing `trough_multiplicity() == 1`), the
    /// [`crate::ConfigSourceChain::file_format_histogram`] gate (`"chain
    /// has a strictly unique rarest format"` — the input to a "one
    /// format is uniquely under-represented" classifier), the
    /// `AxisHistogram<crate::DiffLineKind>` rebuild-summary (`"diff has
    /// a strictly unique rarest line kind"` vs. a balanced rare side).
    ///
    /// **The modal/antimodal-uniqueness boolean pair closed.** Peer to
    /// [`Self::is_strictly_modally_unique`] (the modal-side uniqueness
    /// predicate, `peak_multiplicity() == 1`): the histogram's
    /// multiplicity-uniqueness boolean surface now carries the natural
    /// pair `(is_strictly_modally_unique, is_strictly_antimodally_unique)` —
    /// "is the peak uniquely held?", "is the trough uniquely held?" —
    /// each independently checkable, and together they pattern-match
    /// the four corners of the modality classifier at one paired
    /// boolean read on the closed multiplicity surface. The four
    /// classifier corners
    /// `(is_strictly_modally_unique, is_strictly_antimodally_unique)`:
    /// - `(true, true)` — strictly unimodal *and* strictly anti-unimodal:
    ///   the peak and the trough are each uniquely held, neither
    ///   declaration-order tie-break is exercised.
    /// - `(false, true)` — modally tied, antimodally unique: the peak is
    ///   shared, only the trough is solo.
    /// - `(true, false)` — modally unique, antimodally tied: the peak is
    ///   solo, the trough is shared.
    /// - `(false, false)` — both extremes tied: either the empty
    ///   histogram (vacuously, both are `false`) or a multi-cell shape
    ///   where neither extreme stands alone (including every
    ///   uniformly-observed-count shape with
    ///   `distinct_cells() >= 2`, on which the modal and antimodal
    ///   level sets coincide with the support).
    ///
    /// **Empty-histogram convention** — returns `false`: the empty
    /// histogram has no observed cells, so the antimodal level set is
    /// empty (cardinality `0`, not `1`). The empty boundary is uniformly
    /// `(0, 0)` on [`Self::modality_degree`], so neither side of the
    /// uniqueness pair fires on the empty histogram. Symmetric with
    /// [`Self::is_strictly_modally_unique`] and
    /// [`Self::has_singular_support`] both reading `false` on empty.
    ///
    /// **Singleton-observation convention** — every singleton-support
    /// histogram has [`Self::modality_degree`] `(1, 1)`, so
    /// `is_strictly_antimodally_unique` reads `true` uniformly on every
    /// singleton across every implementor (the minimal-non-empty
    /// boundary witness, peer to the same convention on
    /// [`Self::is_strictly_modally_unique`]).
    ///
    /// **Axis-cover convention** — observing every cell exactly once
    /// raises the antimodal multiplicity to `axis_cardinality::<A>()`,
    /// so `is_strictly_antimodally_unique` reads `true` iff
    /// `axis_cardinality::<A>() == 1` (no implementor today carries
    /// cardinality 1, so uniform axis-cover reads `false` uniformly
    /// across the implementor set). Stated as the conditional law so
    /// the witness is uniform across the implementor set without
    /// case-splitting on cardinality at the test site. Peer to the
    /// identical convention on [`Self::is_strictly_modally_unique`].
    ///
    /// **Companion invariants** with [`Self::trough_multiplicity`],
    /// [`Self::modality_degree`], [`Self::recessive_cell`],
    /// [`Self::recessive_observation`], [`Self::is_empty`],
    /// [`Self::has_singular_support`], [`Self::is_uniform_count`], and
    /// [`Self::is_strictly_modally_unique`]:
    /// - `is_strictly_antimodally_unique() ⇔ trough_multiplicity() == 1` —
    ///   the defining equivalence on the multiplicity scalar peer.
    /// - `is_strictly_antimodally_unique() ⇔ modality_degree().1 == 1` —
    ///   the antimodal-component form on the fused pair.
    /// - `is_empty() ⇒ !is_strictly_antimodally_unique()` — the empty
    ///   histogram has no antimodal cell, so the uniqueness predicate
    ///   never fires there. The contrapositive
    ///   `is_strictly_antimodally_unique() ⇒ !is_empty()` reads off the
    ///   non-emptiness witness for the *strictly unique antimodal cell*
    ///   side of the histogram.
    /// - `has_singular_support() ⇒ is_strictly_antimodally_unique()` — a
    ///   single observed cell is the only member of the antimodal level
    ///   set, vacuously uniquely held. The converse fails on every
    ///   strict-trough shape with two or more observed cells.
    /// - `is_uniform_count() ∧ !is_empty() ⇒
    ///   is_strictly_antimodally_unique() ⇔ has_singular_support()` —
    ///   when every observed cell shares the same count, the antimodal
    ///   level set equals the support, so the uniqueness predicate
    ///   collapses to the singular-support predicate. On a uniform
    ///   axis-cover with cardinality `>= 2`, both read `false`.
    /// - `is_uniform_count() ∧ !is_empty() ⇒
    ///   is_strictly_antimodally_unique() ⇔ is_strictly_modally_unique()` —
    ///   on the uniform-count shape, both level sets coincide with the
    ///   support, so the two uniqueness predicates collapse to the same
    ///   `has_singular_support()` value, peer-bound off the
    ///   `dominant_cell() == recessive_cell()` collapse.
    /// - When `is_strictly_antimodally_unique()` reads `true`,
    ///   `recessive_observation()` is `Some((c, n))` for some unique
    ///   cell `c` carrying the trough count `n`, and the
    ///   declaration-order tie-break in [`Self::recessive_cell`] is
    ///   *not* exercised — the recessive cell is the only member of the
    ///   antimodal level set. The boolean lifts the "is the tie-break
    ///   exercised?" question off the histogram surface at one method
    ///   call.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor (the twenty
    /// closed-enum axis primitives plus the five product cubes —
    /// twenty-five today, reached uniformly through
    /// `for_each_closed_axis_implementor!` in [`tests`]) inherits the
    /// predicate at no per-axis cost. The trait-uniform laws pinned in
    /// [`tests`] hold across the implementor set
    /// (`axis_histogram_is_strictly_antimodally_unique_empty_is_false_*`,
    /// `axis_histogram_is_strictly_antimodally_unique_singleton_is_true_*`,
    /// `axis_histogram_is_strictly_antimodally_unique_axis_cover_iff_cardinality_is_one_*`,
    /// `axis_histogram_is_strictly_antimodally_unique_equals_open_coded_trough_multiplicity_eq_one_*`).
    ///
    /// Peer to [`Self::is_empty`], [`Self::is_uniform_count`],
    /// [`Self::has_singular_support`], [`Self::is_full_cover`], and
    /// [`Self::is_strictly_modally_unique`] on the histogram's
    /// named-boolean predicate surface: the surface now carries the
    /// *modal-uniqueness* and *antimodal-uniqueness* boolean pair, and
    /// the future `ModalityClass` classifier discriminating the four
    /// corners of [`Self::modality_degree`] reads its antimodal axis off
    /// this named predicate.
    #[must_use]
    pub fn is_strictly_antimodally_unique(&self) -> bool {
        self.trough_multiplicity() == 1
    }

    /// `true` exactly when the histogram's *modal* level set has
    /// cardinality two or more — at least two observed cells sit at the
    /// peak. The **modal tie-break** predicate on the histogram's
    /// multiplicity surface: the typed boolean witness for the question
    /// *"is the [`Self::dominant_cell`] declaration-order tie-break
    /// actually being exercised on this window, or is the modal cell
    /// uniquely held?"*
    ///
    /// Pointwise equivalent to two surface forms that previously had no
    /// single named boolean — `self.peak_multiplicity() >= 2` (the
    /// multiplicity-scalar inequality form, the canonical open-coded
    /// expression of the predicate), and `self.modality_degree().0 >= 2`
    /// (the modality-pair projection-inequality form, reading the modal
    /// component of the fused pair). Both forms do a full single-pass
    /// scan of the contiguous counts vector before the comparison; the
    /// named predicate carries the *same* single-pass scan body without
    /// changing asymptotic cost, but lifts the predicate to a named
    /// boolean every operator-facing summary, attestation manifest, and
    /// dashboard cell reads off at one method call.
    ///
    /// The natural typed primitive for the *"is the tie-break being
    /// exercised on the dominant kind right now?"* question every
    /// reload-window diagnostic, attestation manifest, and dashboard
    /// cell asks: the `AxisHistogram<crate::ShikumiErrorKind>` reload-
    /// summary line (`"modally tied: Parse / Io / Watch tied at 12×
    /// each — declaration-order tie-break exercised, Parse declared
    /// first"` vs. the strict-modal `"Parse alone at 12×"` line —
    /// reading the tie-break-disclosure branch off one predicate
    /// instead of composing `peak_multiplicity() >= 2`), the
    /// [`crate::ConfigSourceChain::file_format_histogram`] gate (`"file-
    /// format chain has a tied dominant format — picking by declaration
    /// order"` — the input to the operator-facing "which format wins
    /// the chain?" disclosure), the `AxisHistogram<crate::DiffLineKind>`
    /// rebuild-summary (`"diff is modally tied across Added / Removed
    /// — neither side dominates"` vs. a strictly-modal one-sided
    /// diff).
    ///
    /// **The strict / tied modal partition on the non-empty side.** Peer
    /// to [`Self::is_strictly_modally_unique`] (the modal-uniqueness
    /// predicate, `peak_multiplicity() == 1`): on every *non-empty*
    /// histogram the two predicates strictly partition the modal axis
    /// (exactly one fires), exposing the "is the peak uniquely held or
    /// shared?" question as a closed two-way classification. The four
    /// possibilities on the closed modal-multiplicity surface:
    ///
    /// |                              | `is_strictly_modally_unique` | `is_modally_tied` |
    /// |------------------------------|------------------------------|-------------------|
    /// | empty histogram              | `false`                      | `false`           |
    /// | non-empty, peak uniquely held| `true`                       | `false`           |
    /// | non-empty, peak shared       | `false`                      | `true`            |
    /// | (impossible)                 | `true`                       | `true`            |
    ///
    /// On every non-empty histogram, `is_modally_tied() ==
    /// !is_strictly_modally_unique()` (the inequality `>= 2` is the
    /// strict complement of the equality `== 1` on the strictly-
    /// positive `peak_multiplicity` value). On the empty histogram
    /// (`peak_multiplicity == 0`), *both* read `false` — the empty
    /// boundary is below both branches of the modal classification,
    /// peer to [`Self::is_strictly_modally_unique`] and
    /// [`Self::has_singular_support`] reading `false` on empty.
    ///
    /// **Empty-histogram convention** — returns `false`: the empty
    /// histogram has [`Self::peak_multiplicity`] `0`, so the inequality
    /// `0 >= 2` fails. Symmetric with [`Self::is_strictly_modally_unique`]
    /// reading `false` on empty, so the modal-classification pair
    /// `(is_strictly_modally_unique, is_modally_tied)` reads
    /// `(false, false)` uniformly on the empty histogram across every
    /// implementor.
    ///
    /// **Singleton-observation convention** — every singleton-support
    /// histogram has [`Self::peak_multiplicity`] `1` (the lone observed
    /// cell stands alone at its own peak), so `is_modally_tied` reads
    /// `false` uniformly on every singleton across every implementor
    /// (the modal cell is uniquely held by construction — no tie-break
    /// to exercise).
    ///
    /// **Axis-cover convention** — observing every cell exactly once
    /// raises [`Self::peak_multiplicity`] to `axis_cardinality::<A>()`,
    /// so `is_modally_tied` reads `true` iff
    /// `axis_cardinality::<A>() >= 2`. Every closed-axis implementor on
    /// the typescape today carries `axis_cardinality >= 2`, so the
    /// uniform axis-cover reads `true` uniformly across the implementor
    /// set — peer to the identical convention on
    /// [`Self::is_strictly_modally_unique`] which reads `false` there.
    /// Stated as the conditional law so the witness is uniform across
    /// the implementor set without case-splitting on cardinality at the
    /// test site.
    ///
    /// **Companion invariants** with [`Self::peak_multiplicity`],
    /// [`Self::modality_degree`], [`Self::dominant_cell`],
    /// [`Self::dominant_observation`], [`Self::is_empty`],
    /// [`Self::has_singular_support`], [`Self::is_uniform_count`], and
    /// [`Self::is_strictly_modally_unique`]:
    /// - `is_modally_tied() ⇔ peak_multiplicity() >= 2` — the defining
    ///   equivalence on the multiplicity scalar peer.
    /// - `is_modally_tied() ⇔ modality_degree().0 >= 2` — the modal-
    ///   component form on the fused pair.
    /// - `is_modally_tied() ⇒ !is_empty()` — the empty histogram has
    ///   no modal cell, so the tie predicate never fires there. Reads
    ///   off a one-step non-emptiness witness on the tied-modal side
    ///   of the histogram, peer to the non-emptiness witness on the
    ///   strictly-modally-unique side.
    /// - `!is_empty() ⇒ is_modally_tied() ⇔ !is_strictly_modally_unique()` —
    ///   the strict modal partition on every non-empty histogram: the
    ///   peak is either uniquely held or shared, never both. On the
    ///   empty histogram both predicates read `false`, so the
    ///   equivalence does *not* extend to the empty boundary
    ///   (`is_modally_tied()` is `false`, `!is_strictly_modally_unique()`
    ///   is `true`).
    /// - `has_singular_support() ⇒ !is_modally_tied()` — a single
    ///   observed cell is the only member of the modal level set, so
    ///   the tie predicate never fires on a singleton-support
    ///   histogram. The contrapositive `is_modally_tied() ⇒
    ///   !has_singular_support()` reads off a one-step multi-cell-
    ///   support witness on the tied-modal side: a fired tie predicate
    ///   means at least two observed cells.
    /// - `is_uniform_count() ∧ !is_empty() ⇒ is_modally_tied() ⇔
    ///   !has_singular_support()` — when every observed cell shares the
    ///   same count, the modal level set equals the support, so the
    ///   tie predicate collapses to the multi-cell-support predicate.
    ///   On a singleton-support uniform shape both read `false`; on
    ///   every multi-cell uniform shape (including every uniform axis-
    ///   cover with cardinality `>= 2`) both read `true`.
    /// - When `is_modally_tied()` reads `true`,
    ///   `dominant_observation()` is `Some((c, n))` for some `c` that
    ///   is the *first* of two or more cells tied at count `n`, and the
    ///   declaration-order tie-break in [`Self::dominant_cell`] *is*
    ///   exercised — the dominant cell is *one of* `peak_multiplicity()`
    ///   members of the modal level set rather than the sole inhabitant.
    ///   The boolean lifts the "is the tie-break exercised?" question
    ///   off the histogram surface at one method call, on the modal
    ///   side.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor (the twenty
    /// closed-enum axis primitives plus the five product cubes —
    /// twenty-five today, reached uniformly through
    /// `for_each_closed_axis_implementor!` in [`tests`]) inherits the
    /// predicate at no per-axis cost. The trait-uniform laws pinned in
    /// [`tests`] hold across the implementor set
    /// (`axis_histogram_is_modally_tied_empty_is_false_*`,
    /// `axis_histogram_is_modally_tied_singleton_is_false_*`,
    /// `axis_histogram_is_modally_tied_axis_cover_iff_cardinality_at_least_two_*`,
    /// `axis_histogram_is_modally_tied_equals_open_coded_peak_multiplicity_ge_two_*`).
    ///
    /// Peer to [`Self::is_empty`], [`Self::is_uniform_count`],
    /// [`Self::has_singular_support`], [`Self::is_full_cover`],
    /// [`Self::is_strictly_modally_unique`], and
    /// [`Self::is_strictly_antimodally_unique`] on the histogram's
    /// named-boolean predicate surface: the surface now carries the
    /// *strict modal partition* boolean pair
    /// `(is_strictly_modally_unique, is_modally_tied)` — "is the peak
    /// uniquely held?", "is the peak shared?" — at one named-boolean
    /// pair on the non-empty side. The natural next compounding move
    /// on this surface is the antimodal-side peer `is_antimodally_tied`
    /// reading `trough_multiplicity() >= 2`, closing the
    /// `(is_strictly_antimodally_unique, is_antimodally_tied)` strict
    /// antimodal partition pair.
    #[must_use]
    pub fn is_modally_tied(&self) -> bool {
        self.peak_multiplicity() >= 2
    }

    /// `true` exactly when the histogram's *antimodal* level set has
    /// cardinality two or more — at least two observed cells sit at the
    /// trough. The **antimodal tie-break** predicate on the histogram's
    /// multiplicity surface: the typed boolean witness for the question
    /// *"is the [`Self::recessive_cell`] declaration-order tie-break
    /// actually being exercised on this window, or is the rarest cell
    /// uniquely held?"*
    ///
    /// Pointwise equivalent to two surface forms that previously had no
    /// single named boolean — `self.trough_multiplicity() >= 2` (the
    /// multiplicity-scalar inequality form, the canonical open-coded
    /// expression of the predicate), and `self.modality_degree().1 >= 2`
    /// (the modality-pair projection-inequality form, reading the
    /// antimodal component of the fused pair). Both forms do a full
    /// single-pass scan of the contiguous counts vector before the
    /// comparison; the named predicate carries the *same* single-pass
    /// scan body without changing asymptotic cost, but lifts the
    /// predicate to a named boolean every operator-facing summary,
    /// attestation manifest, and dashboard cell reads off at one method
    /// call.
    ///
    /// The natural typed primitive for the *"is the tie-break being
    /// exercised on the rarest kind right now?"* question every reload-
    /// window diagnostic, attestation manifest, and dashboard cell asks:
    /// the `AxisHistogram<crate::ShikumiErrorKind>` reload-summary line
    /// (`"antimodally tied: Extract / Watch / Io tied at 1× each —
    /// declaration-order tie-break exercised, Extract declared first"`
    /// vs. the strict-antimodal `"Extract alone at 1×"` line — reading
    /// the rare-side-tie-break-disclosure branch off one predicate
    /// instead of composing `trough_multiplicity() >= 2`), the
    /// [`crate::ConfigSourceChain::file_format_histogram`] gate (`"chain
    /// has a tied rarest format — picking by declaration order"` — the
    /// input to the operator-facing "which format is the chain's
    /// uniquely-rarest?" disclosure), the
    /// `AxisHistogram<crate::DiffLineKind>` rebuild-summary (`"diff is
    /// antimodally tied across Removed / Context — neither side is the
    /// solo rarest"` vs. a strictly-antimodal one-rarest diff).
    ///
    /// **The strict / tied antimodal partition on the non-empty side.**
    /// Peer to [`Self::is_strictly_antimodally_unique`] (the antimodal-
    /// uniqueness predicate, `trough_multiplicity() == 1`): on every
    /// *non-empty* histogram the two predicates strictly partition the
    /// antimodal axis (exactly one fires), exposing the "is the trough
    /// uniquely held or shared?" question as a closed two-way
    /// classification. The four possibilities on the closed antimodal-
    /// multiplicity surface:
    ///
    /// |                                | `is_strictly_antimodally_unique` | `is_antimodally_tied` |
    /// |--------------------------------|----------------------------------|-----------------------|
    /// | empty histogram                | `false`                          | `false`               |
    /// | non-empty, trough uniquely held| `true`                           | `false`               |
    /// | non-empty, trough shared       | `false`                          | `true`                |
    /// | (impossible)                   | `true`                           | `true`                |
    ///
    /// On every non-empty histogram, `is_antimodally_tied() ==
    /// !is_strictly_antimodally_unique()` (the inequality `>= 2` is the
    /// strict complement of the equality `== 1` on the strictly-positive
    /// `trough_multiplicity` value). On the empty histogram
    /// (`trough_multiplicity == 0`), *both* read `false` — the empty
    /// boundary is below both branches of the antimodal classification,
    /// peer to [`Self::is_strictly_antimodally_unique`] and
    /// [`Self::has_singular_support`] reading `false` on empty.
    ///
    /// **Empty-histogram convention** — returns `false`: the empty
    /// histogram has [`Self::trough_multiplicity`] `0`, so the
    /// inequality `0 >= 2` fails. Symmetric with
    /// [`Self::is_strictly_antimodally_unique`] reading `false` on empty,
    /// so the antimodal-classification pair
    /// `(is_strictly_antimodally_unique, is_antimodally_tied)` reads
    /// `(false, false)` uniformly on the empty histogram across every
    /// implementor.
    ///
    /// **Singleton-observation convention** — every singleton-support
    /// histogram has [`Self::trough_multiplicity`] `1` (the lone observed
    /// cell stands alone at its own trough — peak and trough coincide),
    /// so `is_antimodally_tied` reads `false` uniformly on every
    /// singleton across every implementor (the antimodal cell is
    /// uniquely held by construction — no tie-break to exercise).
    ///
    /// **Axis-cover convention** — observing every cell exactly once
    /// raises [`Self::trough_multiplicity`] to `axis_cardinality::<A>()`
    /// (every cell sits at the same uniform count, so the trough level
    /// set equals the support), so `is_antimodally_tied` reads `true`
    /// iff `axis_cardinality::<A>() >= 2`. Every closed-axis implementor
    /// on the typescape today carries `axis_cardinality >= 2`, so the
    /// uniform axis-cover reads `true` uniformly across the implementor
    /// set — peer to the identical convention on
    /// [`Self::is_modally_tied`], and complementary to
    /// [`Self::is_strictly_antimodally_unique`] which reads `false`
    /// there. Stated as the conditional law so the witness is uniform
    /// across the implementor set without case-splitting on cardinality
    /// at the test site.
    ///
    /// **Companion invariants** with [`Self::trough_multiplicity`],
    /// [`Self::modality_degree`], [`Self::recessive_cell`],
    /// [`Self::recessive_observation`], [`Self::is_empty`],
    /// [`Self::has_singular_support`], [`Self::is_uniform_count`],
    /// [`Self::is_strictly_antimodally_unique`], and
    /// [`Self::is_modally_tied`]:
    /// - `is_antimodally_tied() ⇔ trough_multiplicity() >= 2` — the
    ///   defining equivalence on the multiplicity scalar peer.
    /// - `is_antimodally_tied() ⇔ modality_degree().1 >= 2` — the
    ///   antimodal-component form on the fused pair.
    /// - `is_antimodally_tied() ⇒ !is_empty()` — the empty histogram has
    ///   no antimodal cell, so the tie predicate never fires there.
    ///   Reads off a one-step non-emptiness witness on the tied-
    ///   antimodal side of the histogram, peer to the non-emptiness
    ///   witness on the strictly-antimodally-unique side.
    /// - `!is_empty() ⇒ is_antimodally_tied() ⇔ !is_strictly_antimodally_unique()` —
    ///   the strict antimodal partition on every non-empty histogram:
    ///   the trough is either uniquely held or shared, never both. On
    ///   the empty histogram both predicates read `false`, so the
    ///   equivalence does *not* extend to the empty boundary
    ///   (`is_antimodally_tied()` is `false`,
    ///   `!is_strictly_antimodally_unique()` is `true`).
    /// - `has_singular_support() ⇒ !is_antimodally_tied()` — a single
    ///   observed cell is the only member of the antimodal level set, so
    ///   the tie predicate never fires on a singleton-support histogram.
    ///   The contrapositive `is_antimodally_tied() ⇒
    ///   !has_singular_support()` reads off a one-step multi-cell-
    ///   support witness on the tied-antimodal side: a fired tie
    ///   predicate means at least two observed cells.
    /// - `is_uniform_count() ∧ !is_empty() ⇒ is_antimodally_tied() ⇔
    ///   !has_singular_support()` — when every observed cell shares the
    ///   same count, the antimodal level set equals the support, so the
    ///   tie predicate collapses to the multi-cell-support predicate.
    ///   On a singleton-support uniform shape both read `false`; on
    ///   every multi-cell uniform shape (including every uniform axis-
    ///   cover with cardinality `>= 2`) both read `true`.
    /// - `is_uniform_count() ∧ !is_empty() ⇒ is_antimodally_tied() ⇔
    ///   is_modally_tied()` — on the uniform-count shape, both level
    ///   sets coincide with the support, so the two tie predicates
    ///   collapse to the same `!has_singular_support()` value, peer-
    ///   bound off the `dominant_cell() == recessive_cell()` collapse.
    /// - When `is_antimodally_tied()` reads `true`,
    ///   `recessive_observation()` is `Some((c, n))` for some `c` that
    ///   is the *first* of two or more cells tied at count `n`, and the
    ///   declaration-order tie-break in [`Self::recessive_cell`] *is*
    ///   exercised — the recessive cell is *one of*
    ///   `trough_multiplicity()` members of the antimodal level set
    ///   rather than the sole inhabitant. The boolean lifts the "is the
    ///   tie-break exercised?" question off the histogram surface at one
    ///   method call, on the antimodal side.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor (the twenty
    /// closed-enum axis primitives plus the five product cubes —
    /// twenty-five today, reached uniformly through
    /// `for_each_closed_axis_implementor!` in [`tests`]) inherits the
    /// predicate at no per-axis cost. The trait-uniform laws pinned in
    /// [`tests`] hold across the implementor set
    /// (`axis_histogram_is_antimodally_tied_empty_is_false_*`,
    /// `axis_histogram_is_antimodally_tied_singleton_is_false_*`,
    /// `axis_histogram_is_antimodally_tied_axis_cover_iff_cardinality_at_least_two_*`,
    /// `axis_histogram_is_antimodally_tied_equals_open_coded_trough_multiplicity_ge_two_*`).
    ///
    /// Peer to [`Self::is_empty`], [`Self::is_uniform_count`],
    /// [`Self::has_singular_support`], [`Self::is_full_cover`],
    /// [`Self::is_strictly_modally_unique`],
    /// [`Self::is_strictly_antimodally_unique`], and
    /// [`Self::is_modally_tied`] on the histogram's named-boolean
    /// predicate surface: the surface now carries the *strict antimodal
    /// partition* boolean pair
    /// `(is_strictly_antimodally_unique, is_antimodally_tied)` — "is the
    /// trough uniquely held?", "is the trough shared?" — at one named-
    /// boolean pair on the non-empty side. Together with the modal-side
    /// peer `(is_strictly_modally_unique, is_modally_tied)`, the
    /// histogram's named-boolean classification surface now closes the
    /// full four-primitive multiplicity boolean algebra on the modal /
    /// antimodal × strict / tied two-axis classification —
    /// `(is_strictly_modally_unique, is_modally_tied,
    /// is_strictly_antimodally_unique, is_antimodally_tied)` — so every
    /// classifier corner of [`Self::modality_degree`] reads off at one
    /// named-boolean read on each axis. The natural next compounding
    /// move on this closed boolean surface is the unified `ModalityClass`
    /// enum discriminating the four classifier corners with the empty
    /// boundary lifted to its own variant — reading its modal axis off
    /// [`Self::is_modally_tied`] and its antimodal axis off
    /// `is_antimodally_tied`.
    #[must_use]
    pub fn is_antimodally_tied(&self) -> bool {
        self.trough_multiplicity() >= 2
    }

    /// The **closed modal/antimodal classification** of the histogram on
    /// the [`ModalityClass`] enum surface — the typed witness fusing
    /// the four named boolean predicates
    /// ([`Self::is_strictly_modally_unique`], [`Self::is_modally_tied`],
    /// [`Self::is_strictly_antimodally_unique`],
    /// [`Self::is_antimodally_tied`]) into one exhaustive five-variant
    /// pattern-match every dashboard / attestation manifest / alarm-
    /// routing site previously composed inline as a `if` ladder over
    /// the four predicates.
    ///
    /// Pointwise equivalent to the open-coded form
    ///
    /// ```text
    /// match self.modality_degree() {
    ///     (0, 0)                   => ModalityClass::Empty,
    ///     (1, 1)                   => ModalityClass::StrictModalStrictAntimodal,
    ///     (_, 1)                   => ModalityClass::TiedModalStrictAntimodal,
    ///     (1, _)                   => ModalityClass::StrictModalTiedAntimodal,
    ///     _                        => ModalityClass::TiedModalTiedAntimodal,
    /// }
    /// ```
    ///
    /// every consumer asking *"which of the five corners of the
    /// strict/tied × modal/antimodal classifier does this window fall
    /// into?"* previously had to either (a) compose two of the four
    /// named booleans into a non-exhaustive 4-way `if` ladder (silently
    /// dropping the empty-boundary branch in many call sites because
    /// the booleans all read `false` on empty, leaking the boundary
    /// into the wrong fall-through arm), or (b) re-derive the modality
    /// pair inline and match on it (re-implementing the (1, 1), (k, 1),
    /// (1, l), (k, l) cases at every call site). The named projection
    /// closes both gaps: the empty boundary is its own typed variant
    /// (no fall-through silent drop), and the classifier corners share
    /// a single match site (no re-derivation drift).
    ///
    /// The natural typed primitive for the modality-classifier surface
    /// every operator-facing rebuild line, structured-diagnostic
    /// legend, and per-window summary struct carries: the
    /// `AxisHistogram<crate::ShikumiErrorKind>` reload-window summary
    /// (`"modality_class = StrictModalTiedAntimodal — Parse alone at
    /// 12×, Watch / Io / Extract tied at 1× each"` — one named
    /// classifier-corner emission rather than the four-line boolean
    /// dump), the chain-shape rollup on
    /// [`crate::ConfigSourceChain::file_format_histogram`]
    /// (`"modality_class = TiedModalTiedAntimodal — chain is uniformly
    /// distributed across formats"`), the
    /// `AxisHistogram<crate::DiffLineKind>` rebuild-summary
    /// (`"modality_class = TiedModalStrictAntimodal — Added / Removed
    /// tied at the peak, Context the rarest"`). A per-classifier-corner
    /// rollup counter (e.g. a fleet-wide
    /// `HashMap<ModalityClass, usize>` tallying how many reload windows
    /// landed in each corner over a deployment window) reaches the
    /// closed-classification map-key surface at one call site,
    /// inheriting the [`Eq`] + [`Hash`] + [`Copy`] guarantees on
    /// [`ModalityClass`] without an interposing hand-rolled
    /// classification key.
    ///
    /// **Exhaustiveness witness.** The returned [`ModalityClass`] is
    /// exhaustively pattern-matchable across its five variants — the
    /// compiler enforces that every match site enumerates all five
    /// corners (or uses an explicit `_` wildcard with intent). A future
    /// renderer landing on the typescape *cannot* silently drop the
    /// empty-boundary branch or any classifier corner, peer to the
    /// structural exhaustiveness on every other closed-enum primitive
    /// in the typescape.
    ///
    /// **Single-pass cost.** The body delegates to
    /// [`Self::modality_degree`], which is itself a single-pass
    /// argmax/argmin fused scan over the contiguous counts vector
    /// (`O(axis_cardinality)`), then a 5-arm `match` on the resulting
    /// `(usize, usize)` pair (`O(1)`). The lift is pure naming +
    /// exhaustiveness pinning, not algorithmic — the named projection
    /// carries the *same* single-pass scan body as the open-coded
    /// 4-call form `(is_strictly_modally_unique, is_modally_tied,
    /// is_strictly_antimodally_unique, is_antimodally_tied)` collapsed
    /// into one method call.
    ///
    /// **Empty-histogram convention** — returns [`ModalityClass::Empty`]
    /// uniformly on every implementor's empty histogram. The empty
    /// boundary lifts to its own typed variant rather than folding into
    /// one of the four classifier corners; every named boolean
    /// ([`Self::is_strictly_modally_unique`], [`Self::is_modally_tied`],
    /// [`Self::is_strictly_antimodally_unique`],
    /// [`Self::is_antimodally_tied`]) reads `false` on the empty
    /// histogram, so the [`ModalityClass::is_empty`] projection is the
    /// unique typed witness for the boundary without a separate
    /// [`Self::is_empty`] pre-check at the match site.
    ///
    /// **Singleton-observation convention** — every singleton-support
    /// histogram has [`Self::modality_degree`] `(1, 1)`, so
    /// `modality_class` reads [`ModalityClass::StrictModalStrictAntimodal`]
    /// uniformly on every singleton across every implementor — the
    /// minimal-non-empty boundary witness for the both-extremes-uniquely-
    /// held corner.
    ///
    /// **Axis-cover convention** — observing every cell exactly once
    /// raises both [`Self::peak_multiplicity`] and
    /// [`Self::trough_multiplicity`] to `axis_cardinality::<A>()`, so
    /// `modality_class` reads [`ModalityClass::TiedModalTiedAntimodal`]
    /// iff `axis_cardinality::<A>() >= 2`. Every closed-axis
    /// implementor on the typescape today carries
    /// `axis_cardinality >= 2`, so the uniform axis-cover reads the
    /// both-tied variant uniformly across the implementor set. Stated
    /// as the conditional law so the witness is uniform across the
    /// implementor set without case-splitting on cardinality at the
    /// test site.
    ///
    /// **Peer-projection law.** On every histogram `h`, the variant
    /// returned by `h.modality_class()` agrees with the histogram-
    /// surface boolean predicates pointwise:
    /// - `h.modality_class().is_empty() ⇔ h.is_empty()`,
    /// - `h.modality_class().is_modally_tied() ⇔ h.is_modally_tied()`,
    /// - `h.modality_class().is_antimodally_tied() ⇔ h.is_antimodally_tied()`.
    ///
    /// The closed enum-surface predicates ([`ModalityClass::is_empty`],
    /// [`ModalityClass::is_modally_tied`],
    /// [`ModalityClass::is_antimodally_tied`]) are the projections of
    /// the histogram-surface predicates of the same name, lifted onto
    /// the typed variant tag — a consumer holding a cached
    /// `ModalityClass` value reads off the modal / antimodal / empty
    /// boundary booleans without re-routing through the originating
    /// histogram. Pinned trait-uniformly across every [`ClosedAxis`]
    /// implementor.
    ///
    /// **Companion invariants** with [`Self::modality_degree`],
    /// [`Self::peak_multiplicity`], [`Self::trough_multiplicity`],
    /// [`Self::is_empty`], [`Self::is_uniform_count`], and
    /// [`Self::has_singular_support`]:
    /// - `modality_class() == ModalityClass::Empty ⇔ is_empty()` —
    ///   the empty-boundary witness is unique.
    /// - `modality_class() == ModalityClass::StrictModalStrictAntimodal
    ///   ⇔ modality_degree() == (1, 1)` — both extremes uniquely
    ///   held.
    /// - `modality_class() == ModalityClass::TiedModalStrictAntimodal
    ///   ⇔ modality_degree().0 >= 2 ∧ modality_degree().1 == 1`.
    /// - `modality_class() == ModalityClass::StrictModalTiedAntimodal
    ///   ⇔ modality_degree().0 == 1 ∧ modality_degree().1 >= 2`.
    /// - `modality_class() == ModalityClass::TiedModalTiedAntimodal
    ///   ⇔ modality_degree().0 >= 2 ∧ modality_degree().1 >= 2`.
    /// - `has_singular_support() ⇒ modality_class() ==
    ///   ModalityClass::StrictModalStrictAntimodal` — a single
    ///   observed cell sits alone at both extremes.
    /// - `is_uniform_count() ∧ !is_empty() ⇒ modality_class() ∈
    ///   { StrictModalStrictAntimodal, TiedModalTiedAntimodal }` —
    ///   when every observed cell shares the same count, peak and
    ///   trough coincide on the support, so the modal and antimodal
    ///   tie booleans collapse to the same value (`!has_singular_support()`).
    ///   A uniform singleton fires [`ModalityClass::StrictModalStrictAntimodal`];
    ///   every uniform-count multi-cell shape fires
    ///   [`ModalityClass::TiedModalTiedAntimodal`] — peer to the
    ///   identical-axis collapse law on
    ///   [`Self::is_antimodally_tied`] and [`Self::is_modally_tied`]
    ///   under uniform count.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor (the twenty
    /// closed-enum axis primitives plus the five product cubes —
    /// twenty-five today, reached uniformly through
    /// `for_each_closed_axis_implementor!` in [`tests`]) inherits the
    /// projection at no per-axis cost. The seven trait-uniform laws
    /// pinned in [`tests`] hold across the implementor set
    /// (`axis_histogram_modality_class_empty_is_empty_variant_*`,
    /// `axis_histogram_modality_class_singleton_is_strict_modal_strict_antimodal_*`,
    /// `axis_histogram_modality_class_axis_cover_is_tied_modal_tied_antimodal_iff_cardinality_at_least_two_*`,
    /// `axis_histogram_modality_class_equals_open_coded_modality_degree_match_*`,
    /// `axis_histogram_modality_class_is_empty_agrees_with_histogram_is_empty_*`,
    /// `axis_histogram_modality_class_is_modally_tied_agrees_with_histogram_is_modally_tied_*`,
    /// `axis_histogram_modality_class_is_antimodally_tied_agrees_with_histogram_is_antimodally_tied_*`).
    ///
    /// Peer to [`Self::modality_degree`] (the fused scalar-pair
    /// projection of the multiplicities) on the histogram's named
    /// classification surface: the histogram now carries the scalar-
    /// pair `(peak_mult, trough_mult)` projection alongside the closed-
    /// enum [`ModalityClass`] projection, with the named-boolean
    /// surface (`is_strictly_modally_unique`, `is_modally_tied`,
    /// `is_strictly_antimodally_unique`, `is_antimodally_tied`) sitting
    /// between them as the four-primitive boolean algebra both
    /// projections close. Every operator-facing summary reads the
    /// projection it needs at one method call — scalar pair, named
    /// boolean, or closed classifier corner — without re-derivation
    /// drift.
    #[must_use]
    pub fn modality_class(&self) -> ModalityClass {
        match self.modality_degree() {
            (0, 0) => ModalityClass::Empty,
            (1, 1) => ModalityClass::StrictModalStrictAntimodal,
            (_, 1) => ModalityClass::TiedModalStrictAntimodal,
            (1, _) => ModalityClass::StrictModalTiedAntimodal,
            _ => ModalityClass::TiedModalTiedAntimodal,
        }
    }

    /// The **observed-distribution spread** — the difference between the
    /// maximum and minimum observation counts over the histogram's
    /// observed support. Equal to
    /// `self.peak_count() - self.trough_count()` by construction; named
    /// at the trait level so consumers reading off the
    /// observed-distribution skew route through one scalar projection
    /// rather than re-deriving the (peak, trough) subtraction at every
    /// diagnostic / dashboard / alarm site.
    ///
    /// The natural typed primitive for the *balanced-vs-skewed* question
    /// every operator-facing summary asks of an observation window:
    /// *"how unevenly distributed are the observations across the
    /// observed kinds?"*: the spread of an
    /// `AxisHistogram<crate::ShikumiErrorKind>` reload-window error
    /// distribution ("dominant Parse fired 12×, rarest Io fired 1×,
    /// spread = 11" — the natural input to an outlier-threshold
    /// classifier), the spread of a
    /// [`crate::ConfigSourceChain::file_format_histogram`] (the chain's
    /// "is one format dominating the chain or are they balanced?"
    /// summary line), the spread of a
    /// [`crate::ConfigDiff::kind_histogram`] (the diff's "is this
    /// rebuild adding/removing in roughly equal numbers or strongly
    /// skewed?" diagnostic). Before this lift, every consumer asking
    /// "what is the spread of this observation window?" re-derived the
    /// projection inline as
    /// `hist.peak_count() - hist.trough_count()` — two method calls
    /// plus a subtraction at every site, with the silent-underflow risk
    /// every consumer has to reason about independently
    /// (`peak_count >= trough_count` is a structural invariant of the
    /// histogram but not of the inline subtraction surface).
    ///
    /// **Underflow-safe by construction.** The subtraction
    /// `peak_count() - trough_count()` is guaranteed non-negative
    /// (`peak_count >= trough_count` holds structurally on every
    /// histogram — both equal 0 on the empty histogram, both are the
    /// same positive count on a uniform-observed-count histogram,
    /// otherwise `peak_count > trough_count`). The named scalar
    /// surfaces the bound; consumers do not need to re-prove
    /// monotonicity at the call site.
    ///
    /// **Empty-histogram convention** — returns `0`, matching the
    /// [`Self::total`], [`Self::distinct_cells`], [`Self::peak_count`],
    /// and [`Self::trough_count`] empty conventions. The scalar peer
    /// quintuple
    /// `(total, distinct_cells, peak_count, trough_count, spread)` is
    /// therefore uniformly `(0, 0, 0, 0, 0)` on the empty histogram.
    ///
    /// **Structural-skew predicate.** `spread() == 0` is the typed
    /// *uniformly-observed-count* predicate on the histogram surface:
    /// every observed cell carries the same count. The predicate holds
    /// on three distinct shapes — the empty histogram (vacuously: no
    /// observed cells); every singleton-support histogram (only one
    /// observed cell, trivially balanced); every histogram whose
    /// support is observed at a uniform count, including the
    /// k-cell-observed-k-times-each-once shape and every uniform
    /// axis-cover histogram. The predicate is pointwise equivalent to
    /// `dominant_cell() == recessive_cell()` on every non-empty
    /// histogram — `spread()` lifts the same predicate from the
    /// `(cell, cell)` pair on the modal-pair surface to the scalar
    /// surface, so a future "balanced-distribution" diagnostic reads
    /// off a single equality `hist.spread() == 0` instead of routing
    /// through both cell-form projections and an `Option<A>` equality.
    ///
    /// **Companion invariants** with [`Self::total`],
    /// [`Self::distinct_cells`], [`Self::peak_count`], and
    /// [`Self::trough_count`]:
    /// - `spread() == 0` ⇔ every observed cell carries the same count
    ///   (the *uniformly-observed-count* shape — including the empty
    ///   histogram, every singleton-support histogram, every uniform
    ///   axis-cover histogram).
    /// - `spread() <= peak_count()` always: the trough is non-negative,
    ///   so the subtraction is bounded above by the minuend. Equality
    ///   holds iff the trough is zero — i.e. on the empty histogram.
    /// - `spread() <= total()` always: composition of
    ///   `peak_count <= total` with `trough_count >= 0`.
    /// - The merge behavior is *non-monotonic*: merging two histograms
    ///   can either grow the spread (when one side carries a heavy
    ///   tail the other lacks, the merged peak grows faster than the
    ///   merged trough) or shrink it (when merging an empty-support
    ///   addition restores the trough to a value closer to the peak).
    ///   The empty-identity law holds: `merge(self, empty).spread() ==
    ///   self.spread()`.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor (the twenty
    /// closed-enum axis primitives plus the five product cubes —
    /// twenty-five today, reached uniformly through
    /// `for_each_closed_axis_implementor!` in [`tests`]) inherits the
    /// projection at no per-axis cost. The three trait-uniform laws
    /// pinned in [`tests`] hold across the implementor set
    /// (`axis_histogram_spread_empty_is_zero_*`,
    /// `axis_histogram_spread_singleton_is_zero_*`,
    /// `axis_histogram_spread_axis_cover_is_zero_*`).
    ///
    /// Peer to [`Self::total`] (the *sum* over every cell),
    /// [`Self::distinct_cells`] (the *support cardinality*),
    /// [`Self::peak_count`] (the *modal* count scalar), and
    /// [`Self::trough_count`] (the *rarest-observed* count scalar): the
    /// scalar surface of the histogram now carries the natural
    /// quintuple of
    /// `(how many observations, how many kinds, how many on the peak,
    /// how many on the trough, how much spread)` projections — every
    /// operator-facing summary reads off one method call each, and the
    /// *balanced-distribution* predicate (`spread() == 0`) reads off a
    /// single equality on the closed scalar surface.
    #[must_use]
    pub fn spread(&self) -> usize {
        self.peak_count() - self.trough_count()
    }

    /// `true` exactly when every observed cell of the closed axis carries
    /// the same observation count — the **uniformly-observed-count
    /// predicate** on the histogram surface. The typed peer of
    /// `spread() == 0` on the boolean surface, lifting the same
    /// structural-skew boundary from the scalar surface to a named
    /// predicate.
    ///
    /// Pointwise equivalent to three documented surface predicates:
    /// - `self.spread() == 0` (the scalar-form: peak equals trough,
    ///   collapsed to one equality on the difference),
    /// - `self.peak_count() == self.trough_count()` (the defining form
    ///   on the underlying scalar pair),
    /// - `self.dominant_cell() == self.recessive_cell()` (the modal-pair
    ///   form, peering through `Option<A>` equality — both sides agree
    ///   on the empty histogram with `(None, None)` and on every
    ///   non-empty uniform shape with `(Some(first), Some(first))`).
    ///
    /// Before this lift, every consumer asking *"are the observations
    /// distributed uniformly across the observed kinds?"* re-derived the
    /// predicate inline as one of those three forms — and the three
    /// forms drifted in subtle ways: `peak_count() == trough_count()`
    /// reads through two method calls and a `usize` equality but says
    /// nothing structurally about *what* is being equated;
    /// `spread() == 0` is concise but routes through a subtraction whose
    /// underflow safety relies on the structural `peak >= trough`
    /// invariant on [`Self::spread`]; `dominant_cell() == recessive_cell()`
    /// peers through `Option<A>` equality across two argmax/argmin walks
    /// of the histogram. The lift names the predicate directly at one
    /// site with a single-pass scan over the raw counts vector — the
    /// typed boolean every operator-facing "is this window balanced?"
    /// check, attestation manifest "every observed kind fired equally"
    /// gate, and dashboard "uniform-distribution" cell reads off as a
    /// single method call.
    ///
    /// The natural typed primitive for diagnostic dumps, dashboards, and
    /// attestation manifests asking *"are the observations balanced
    /// across the observed kinds?"*: the "every error class that fired
    /// did so the same number of times" attestation on a per-window
    /// `AxisHistogram<crate::ShikumiErrorKind>`, the "no file format
    /// dominated the chain" balanced-distribution gate on
    /// [`crate::ConfigSourceChain::file_format_histogram`], the "every
    /// observed layer kind contributed equally" diagnostic on
    /// [`crate::ConfigSourceChain::layer_kind_histogram`], the "no diff
    /// class dominated the rebuild" attestation on
    /// [`crate::ConfigDiff::kind_histogram`].
    ///
    /// **Empty-histogram convention** — returns `true` vacuously: the
    /// empty histogram has no observed cells, so the universal "every
    /// observed cell carries the same count" reads `true` over the
    /// empty support. Matches `spread() == 0` on the empty case
    /// (`peak = trough = 0`) and `dominant_cell() == recessive_cell()`
    /// (`None == None`). The empty histogram is therefore on the
    /// `true` side of both the `(is_empty, is_uniform_count)` and the
    /// `(is_full_cover, is_uniform_count)` corners — the only
    /// histogram on which `is_empty` and `is_uniform_count` both
    /// fire.
    ///
    /// **Singleton-support convention** — returns `true` on every
    /// histogram whose observed support is a single cell (trivially
    /// balanced: the one observed cell's count is both the peak and
    /// the trough). Includes every histogram built from
    /// `std::iter::once(v)` and every histogram built from N
    /// observations of the same cell.
    ///
    /// **Uniform axis-cover convention** — returns `true` on every
    /// histogram where every cell received the same count, including
    /// the k-cell-observed-k-times-each-once shape and the uniform
    /// axis-cover histogram (every cell at 1). The simultaneous
    /// witness for `(is_full_cover, is_uniform_count) == (true, true)`
    /// — every kind observed at least once, and every kind observed
    /// equally.
    ///
    /// **Companion invariants** with [`Self::spread`],
    /// [`Self::peak_count`], [`Self::trough_count`],
    /// [`Self::dominant_cell`], [`Self::recessive_cell`], and
    /// [`Self::is_empty`]:
    /// - `is_uniform_count() == (spread() == 0)` always — the defining
    ///   equivalence on the scalar-spread surface.
    /// - `is_uniform_count() == (peak_count() == trough_count())`
    ///   always — the structural form on the underlying scalar pair.
    /// - `is_uniform_count() == (dominant_cell() == recessive_cell())`
    ///   always — the modal-pair form, pointwise equal on both
    ///   branches (empty: both reduce to `None == None`; non-empty
    ///   uniform: both reduce to `Some(first cell) == Some(first cell)`;
    ///   non-empty skewed: both reduce to `false`).
    /// - `is_empty() ⇒ is_uniform_count()` — vacuous uniformity on
    ///   the empty histogram. Contrapositively, `!is_uniform_count() ⇒
    ///   !is_empty()` (a skewed histogram has at least two distinct
    ///   counts, both positive, so the support is non-empty).
    /// - `distinct_cells() <= 1 ⇒ is_uniform_count()` — every
    ///   histogram with support size 0 or 1 is uniform by construction
    ///   (empty: no cells to compare; singleton: one cell trivially
    ///   equals itself). Contrapositively, `!is_uniform_count() ⇒
    ///   distinct_cells() >= 2` (a skewed histogram observes at least
    ///   two distinct cells with differing counts).
    /// - Merge behavior is *non-monotonic* (peer to
    ///   [`Self::trough_count`] and [`Self::spread`]): merging two
    ///   uniform-count histograms can produce a non-uniform merge (when
    ///   the supports differ — the merged cells carry the sum, the
    ///   unmerged cells carry only one side's count), and merging two
    ///   non-uniform histograms can produce a uniform merge (when the
    ///   heavy and light tails cancel pointwise). The empty-identity
    ///   law still holds:
    ///   `merge(self, empty).is_uniform_count() == self.is_uniform_count()`.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor (the twenty-six
    /// closed-enum axis primitives plus the five product cubes —
    /// thirty-one today, reached uniformly through
    /// `for_each_closed_axis_implementor!` in [`tests`]) inherits the
    /// predicate at no per-axis cost. The three trait-uniform laws
    /// pinned in [`tests`] hold across the implementor set
    /// (`axis_histogram_is_uniform_count_empty_is_true_*`,
    /// `axis_histogram_is_uniform_count_singleton_is_true_*`,
    /// `axis_histogram_is_uniform_count_axis_cover_is_true_*`).
    ///
    /// Peer to [`Self::is_empty`] (the *no-observation* boolean
    /// boundary on the coverage axis) and [`Self::is_full_cover`] (the
    /// *complete-observation* boolean boundary on the coverage axis):
    /// `is_uniform_count` adds the boolean boundary on the *shape*
    /// axis. The histogram's boolean surface now carries the natural
    /// triple `(is_empty, is_full_cover, is_uniform_count)` — "did the
    /// chain see anything?", "did the chain see everything?", "did
    /// the chain see them all equally?" — each a single method call,
    /// each independently checkable, and together they classify every
    /// histogram into the eight cells of the boolean cube (with a few
    /// cells structurally empty on the cardinality-≥2 implementor set:
    /// e.g. `is_empty ∧ is_full_cover` requires cardinality 0, never
    /// realized today; every other corner has a witness on every
    /// cardinality-≥2 axis).
    #[must_use]
    pub fn is_uniform_count(&self) -> bool {
        let mut nonzero = self.counts.iter().copied().filter(|&c| c > 0);
        match nonzero.next() {
            None => true,
            Some(first) => nonzero.all(|c| c == first),
        }
    }

    /// `true` exactly when the histogram's *support* has cardinality
    /// one — exactly one axis cell received any observation. The
    /// **singular-support predicate** on the histogram surface: the
    /// typed boolean witness for the question "did this observation
    /// window collapse onto a single kind?"
    ///
    /// Pointwise equivalent to three documented surface predicates
    /// that previously had no single named boolean —
    /// `self.distinct_cells() == 1` (the support-cardinality form on
    /// the named scalar), `self.nonzero().count() == 1` (the
    /// iterator-length form, which walks the same closed-axis
    /// filter), and `self.peak_count() == self.total() && !self.is_empty()`
    /// (the monoid-collapse form: a single observed cell carries every
    /// observation, so its peak count equals the total) — collapsed to
    /// one method call with a single-pass scan that short-circuits on
    /// the second nonzero cell (the early-exit form bounds the cost
    /// at two nonzero cells visited rather than walking the entire
    /// counts vector to count them).
    ///
    /// **The support-cardinality boundary triple.** Peer to
    /// [`Self::is_empty`] (support cardinality `0` — *no* cell
    /// observed) and [`Self::is_full_cover`] (support cardinality
    /// `axis_cardinality::<A>()` — *every* cell observed). The
    /// boolean surface now carries the natural triple
    /// `(is_empty, has_singular_support, is_full_cover)` on the
    /// support-cardinality boundary — "did the chain see *nothing*?",
    /// "did the chain collapse onto *one* kind?", "did the chain see
    /// *every* kind?" — each independently checkable in one method
    /// call. The three predicates are pairwise disjoint on every
    /// `ClosedAxis` implementor with `axis_cardinality::<A>() >= 2`
    /// (the entire implementor set today): `is_empty ⇒
    /// !has_singular_support ∧ !is_full_cover` (support 0 ≠ 1,
    /// 0 ≠ axis_cardinality), `has_singular_support ⇒ !is_empty ∧
    /// !is_full_cover` (support 1 ≠ 0, 1 ≠ axis_cardinality on
    /// cardinality ≥ 2), and `is_full_cover ⇒ !is_empty ∧
    /// !has_singular_support` (support axis_cardinality ≠ 0,
    /// axis_cardinality ≠ 1 on cardinality ≥ 2).
    ///
    /// **Empty-histogram convention** — returns `false`: the empty
    /// histogram has support cardinality `0`, not `1`. The named
    /// boundary `is_empty` carries that case; `has_singular_support`
    /// reads the *one observed cell* case strictly.
    ///
    /// **Singleton-observation convention** — every singleton
    /// observation lands the support cardinality at exactly `1`, so
    /// `has_singular_support` reads `true` uniformly on every
    /// singleton across every implementor. The minimal-nonempty
    /// boundary witness.
    ///
    /// **Axis-cover convention** — observing every cell exactly once
    /// raises the support cardinality to `axis_cardinality::<A>()`,
    /// so `has_singular_support` reads `true` iff
    /// `axis_cardinality::<A>() == 1` (no implementor today carries
    /// cardinality 1, so axis-cover reads `false` uniformly across
    /// the implementor set). Stated as the conditional law so the
    /// witness is uniform across the implementor set without case-
    /// splitting on cardinality at the test site.
    ///
    /// **Companion invariants** with [`Self::is_empty`],
    /// [`Self::is_full_cover`], [`Self::distinct_cells`],
    /// [`Self::total`], [`Self::peak_count`],
    /// [`Self::dominant_cell`], [`Self::recessive_cell`], and
    /// [`Self::is_uniform_count`]:
    /// - `has_singular_support() ⇔ distinct_cells() == 1` — the
    ///   defining equivalence on the named scalar peer; reading
    ///   "the support carries exactly one observed kind" off one
    ///   named boolean instead of an equality against an `usize`
    ///   on the support-cardinality scalar.
    /// - `has_singular_support() ⇔ (peak_count() == total() &&
    ///   !is_empty())` — the monoidal-collapse form: a single
    ///   observed cell carries every observation, so its peak count
    ///   equals the total; the non-empty side excludes the
    ///   `(0, 0)` degenerate equality the empty histogram carries.
    /// - `has_singular_support() ⇒ dominant_cell() ==
    ///   recessive_cell() && dominant_cell().is_some()` — when
    ///   support is singular, the modal pair collapses to the one
    ///   observed cell on both sides (the converse fails: on
    ///   uniform axis-cover, both sides pick the first cell by
    ///   tie-break but support is not singular).
    /// - `has_singular_support() ⇒ is_uniform_count()` — a single
    ///   observed cell is vacuously uniform-counted (only one count
    ///   in the support to compare to itself); the converse fails
    ///   on every uniform-multi-cell shape (the empty histogram,
    ///   uniform axis-cover, every k-cell-observed-k-times-each-once
    ///   shape) so the implication is one-way.
    /// - `(is_empty, has_singular_support, is_full_cover)` is
    ///   pairwise disjoint on every implementor with cardinality
    ///   ≥ 2 (the entire implementor set today) — at most one of
    ///   the three reads `true` on any histogram, witnessed by the
    ///   `(false, false, false)` partial-coverage corner reading
    ///   none of them and every other typed branch reading exactly
    ///   one.
    /// - The merge behavior is *non-monotonic*: merging two
    ///   singular-support histograms can produce a non-singular
    ///   merge (when the supports differ — the merged histogram
    ///   has support cardinality `2`), and merging two non-
    ///   singular histograms can produce a singular merge only
    ///   when both sides are empty (vacuously). The
    ///   empty-identity law holds:
    ///   `merge(self, empty).has_singular_support() ==
    ///   self.has_singular_support()`.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor (the twenty
    /// closed-enum axis primitives plus the five product cubes —
    /// twenty-five today, reached uniformly through
    /// `for_each_closed_axis_implementor!` in [`tests`]) inherits
    /// the projection at no per-axis cost. The three trait-uniform
    /// laws pinned in [`tests`] hold across the implementor set
    /// (`axis_histogram_has_singular_support_empty_is_false_*`,
    /// `axis_histogram_has_singular_support_singleton_is_true_*`,
    /// `axis_histogram_has_singular_support_axis_cover_iff_cardinality_is_one_*`).
    #[must_use]
    pub fn has_singular_support(&self) -> bool {
        let mut nonzero = self.counts.iter().filter(|&&c| c > 0);
        nonzero.next().is_some() && nonzero.next().is_none()
    }

    /// `true` exactly when the histogram has at least one observed cell
    /// *and* at least one unobserved cell — the **partial-cover
    /// predicate** on the histogram surface. The "neither empty nor
    /// full" middle leg that closes the
    /// `(is_empty, has_partial_cover, is_full_cover)` coverage
    /// trichotomy.
    ///
    /// Pointwise equivalent to four documented surface predicates that
    /// previously had no single named boolean —
    /// `!self.is_empty() && !self.is_full_cover()` (the structural
    /// conjunction-of-negations form, the defining shape), `0 <
    /// self.distinct_cells() && self.distinct_cells() <
    /// axis_cardinality::<A>()` (the support-cardinality
    /// strict-interval form on the named scalar peer), `0 <
    /// self.unobserved_cells() && self.unobserved_cells() <
    /// axis_cardinality::<A>()` (the coverage-gap strict-interval form
    /// on the complementary scalar), and `self.observed().next().is_some()
    /// && self.unobserved().next().is_some()` (the dual-iterator
    /// non-emptiness form, which allocates both iterators just to
    /// check their non-emptiness) — collapsed to one method call with
    /// a single-pass scan that short-circuits once it has witnessed
    /// both a zero count and a nonzero count (the early-exit form
    /// bounds the cost at one zero-witness plus one nonzero-witness
    /// rather than two full walks of the counts vector or both
    /// iterator allocations).
    ///
    /// **The coverage-cardinality boundary triple.** Peer to
    /// [`Self::is_empty`] (support cardinality `0` — *no* cell
    /// observed) and [`Self::is_full_cover`] (support cardinality
    /// `axis_cardinality::<A>()` — *every* cell observed). The
    /// boolean surface now carries the natural triple
    /// `(is_empty, has_partial_cover, is_full_cover)` on the coverage
    /// boundary — "did the chain see *nothing*?", "did the chain see
    /// *some* but not *all*?", "did the chain see *everything*?" —
    /// each independently checkable in one method call. The three
    /// predicates form a strict partition on every implementor with
    /// `axis_cardinality::<A>() >= 1`: exactly one fires on any
    /// histogram (the partition cells are pairwise disjoint and
    /// jointly exhaustive). On a zero-cardinality axis (none in the
    /// typescape today, but structurally permitted by [`ClosedAxis`]),
    /// `is_empty` and `is_full_cover` both read `true` vacuously and
    /// `has_partial_cover` reads `false` — the degenerate-axis
    /// double-boundary the existing [`Self::is_full_cover`] doc
    /// already names.
    ///
    /// **Empty-histogram convention** — returns `false` on every
    /// implementor: no cell observed, so the "at least one observed"
    /// half of the conjunction fails uniformly. The named boundary
    /// `is_empty` carries that case; `has_partial_cover` reads the
    /// strict "between" case only.
    ///
    /// **Full-cover convention** — returns `false` on every
    /// implementor: every cell observed, so the "at least one
    /// unobserved" half of the conjunction fails uniformly. The named
    /// boundary `is_full_cover` carries that case.
    ///
    /// **Singleton-observation convention** — every singleton
    /// observation lands the support cardinality at exactly `1`. On
    /// every implementor with `axis_cardinality::<A>() >= 2` (every
    /// implementor today), `has_partial_cover` reads `true` uniformly
    /// on singletons (one observed, the rest unobserved). On a
    /// hypothetical cardinality-1 axis, the singleton is the
    /// full-cover witness and `has_partial_cover` reads `false` — the
    /// witness for the "structural-empty cell of the trichotomy on
    /// cardinality 1" boundary.
    ///
    /// **Companion invariants** with [`Self::is_empty`],
    /// [`Self::is_full_cover`], [`Self::distinct_cells`],
    /// [`Self::unobserved_cells`], [`Self::has_singular_support`], and
    /// [`Self::merge`]:
    /// - `has_partial_cover() ⇔ !is_empty() && !is_full_cover()` —
    ///   the defining equivalence on the boolean-boundary pair.
    /// - `has_partial_cover() ⇔ 0 < distinct_cells() && distinct_cells() <
    ///   axis_cardinality::<A>()` — the support-cardinality
    ///   strict-interval form on the named scalar peer.
    /// - `has_partial_cover() ⇔ 0 < unobserved_cells() &&
    ///   unobserved_cells() < axis_cardinality::<A>()` — the
    ///   coverage-gap form on the complementary scalar peer.
    /// - `(is_empty, has_partial_cover, is_full_cover)` is a strict
    ///   partition on every implementor with cardinality ≥ 1: pairwise
    ///   disjoint *and* jointly exhaustive. Stated as
    ///   `u8::from(is_empty()) + u8::from(has_partial_cover()) + u8::from(is_full_cover()) == 1`
    ///   — exactly one corner fires uniformly across the implementor
    ///   set. The peer to the [`Self::has_singular_support`] companion
    ///   "(false, false, false) partial-coverage corner" invariant: the
    ///   `has_partial_cover` lift names that corner directly.
    /// - `has_singular_support() ⇒ has_partial_cover()` on every
    ///   implementor with `axis_cardinality::<A>() >= 2` (the entire
    ///   implementor set today): support `1` is strictly between `0`
    ///   and cardinality. The converse fails on every multi-cell
    ///   non-full-cover shape (e.g. observing two cells on a
    ///   cardinality-3 axis).
    /// - Merge behavior is *monotone-OR over the boundary corners
    ///   only*: `merge(self, other).is_full_cover() >= self.is_full_cover()
    ///   || other.is_full_cover()` already pins the full-cover monotone
    ///   law on [`Self::is_full_cover`]; for the partial-cover middle
    ///   leg the behavior is *non-monotonic* — merging two partial
    ///   covers can produce a partial cover (when the union of
    ///   supports is still strictly partial) or a full cover (when
    ///   the union exhausts the axis), and merging a partial cover
    ///   with an empty cover preserves partial-cover. The
    ///   empty-identity law holds:
    ///   `merge(self, empty).has_partial_cover() ==
    ///   self.has_partial_cover()`.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor (the twenty-six
    /// closed-enum axis primitives plus the five product cubes —
    /// thirty-one today, reached uniformly through
    /// `for_each_closed_axis_implementor!` in [`tests`]) inherits the
    /// predicate at no per-axis cost. The three trait-uniform laws
    /// pinned in [`tests`] hold across the implementor set
    /// (`axis_histogram_has_partial_cover_empty_is_false_*`,
    /// `axis_histogram_has_partial_cover_singleton_iff_cardinality_at_least_two_*`,
    /// `axis_histogram_has_partial_cover_axis_cover_is_false_*`), plus
    /// the coverage-trichotomy partition law
    /// `axis_histogram_coverage_trichotomy_partitions_every_histogram_*`
    /// that pins the (`is_empty`, `has_partial_cover`, `is_full_cover`)
    /// boolean exactly-one-fires law across every implementor on every
    /// histogram in the implementor's canonical shape set (empty,
    /// singleton, axis-cover).
    ///
    /// **The partial-cover middle leg.** Where the existing
    /// [`Self::is_empty`] reads the "nothing observed" corner and
    /// [`Self::is_full_cover`] reads the "everything observed" corner,
    /// `has_partial_cover` reads the "some but not all observed"
    /// corner — the structural middle that closes the coverage
    /// trichotomy. Before this lift, every consumer asking *"did this
    /// window see some kinds but not all?"* re-derived the predicate
    /// inline as `!hist.is_empty() && !hist.is_full_cover()` (two
    /// method calls, a negation, and a conjunction across two named
    /// boundaries), as `0 < hist.distinct_cells() && hist.distinct_cells()
    /// < axis_cardinality::<C>()` (importing [`axis_cardinality`] and
    /// turbofish-naming the axis), or as `hist.observed().next().is_some()
    /// && hist.unobserved().next().is_some()` (allocating both
    /// iterators). The lift names the middle leg directly at one site —
    /// the typed boolean every "coverage-progress" diagnostic, partial-
    /// cover attestation, and "neither blank nor exhaustive" dashboard
    /// cell reads off as a single method call, and the coverage-
    /// trichotomy partition becomes a pinned structural law over every
    /// implementor.
    #[must_use]
    pub fn has_partial_cover(&self) -> bool {
        let mut saw_zero = false;
        let mut saw_nonzero = false;
        for &c in &self.counts {
            if c == 0 {
                saw_zero = true;
            } else {
                saw_nonzero = true;
            }
            if saw_zero && saw_nonzero {
                return true;
            }
        }
        false
    }

    /// `true` exactly when the histogram has *exactly one unobserved
    /// cell* — the **singular-gap predicate** on the histogram surface.
    /// The structural dual of [`Self::has_singular_support`] on the
    /// `(observed, unobserved)` cellwise partition: where the support
    /// side names the support-cardinality-`1` corner (one observed,
    /// the rest unobserved), the gap side names the unobserved-
    /// cardinality-`1` corner (one unobserved, the rest observed) —
    /// "did the chain see all but one kind?".
    ///
    /// Pointwise equivalent to two documented surface predicates the
    /// support-cardinality scalar surface already exposes —
    /// `self.unobserved_cells() == 1` (the unobserved-side defining
    /// equivalence on the named scalar peer) and
    /// `self.distinct_cells() == axis_cardinality::<A>() - 1` on the
    /// support side via the
    /// `distinct_cells + unobserved_cells == axis_cardinality`
    /// partition invariant (the equation closes on every implementor
    /// today, so the two forms read off the same boolean). Collapsed
    /// to one method call with a single-pass scan that short-circuits
    /// on the second zero (the early-exit form bounds the cost at one
    /// zero-witness plus one second-zero-witness rather than a full
    /// walk of the counts vector or an allocation of the
    /// [`Self::unobserved`] iterator just to count its prefix).
    ///
    /// **Empty-histogram convention** — the empty histogram has every
    /// cell unobserved, so the unobserved-cardinality reads
    /// `axis_cardinality::<A>()`. `has_singular_gap` reads `true` iff
    /// `axis_cardinality::<A>() == 1` (no implementor today carries
    /// cardinality 1, so empty reads `false` uniformly across the
    /// implementor set). Stated as the conditional law so the witness
    /// is uniform across the implementor set without case-splitting on
    /// cardinality at the test site. The dual-boundary witness of
    /// `has_singular_support`'s axis-cover convention on the opposite
    /// end of the support-cardinality interval.
    ///
    /// **Full-cover convention** — observing every cell exactly once
    /// drives the unobserved-cardinality to `0`, so `has_singular_gap`
    /// reads `false` uniformly on every implementor. The named
    /// boundary [`Self::is_full_cover`] carries that case;
    /// `has_singular_gap` reads the *one-cell-missing* case strictly.
    ///
    /// **Singleton-observation convention** — every singleton
    /// observation lands the support cardinality at exactly `1`, so
    /// the unobserved-cardinality reads `axis_cardinality::<A>() - 1`.
    /// On a cardinality-`2` axis (the smallest non-trivial case),
    /// `axis_cardinality - 1 == 1` exactly, so `has_singular_gap` reads
    /// `true` uniformly on every singleton; on cardinality ≥ `3` it
    /// reads `false` uniformly. Stated as the conditional law
    /// `singleton.has_singular_gap() == (axis_cardinality::<A>() == 2)`
    /// so the witness is uniform across the implementor set without
    /// case-splitting on cardinality at the test site.
    ///
    /// **Cardinality-2 coincidence with `has_singular_support`** — on
    /// every implementor with `axis_cardinality::<A>() == 2`,
    /// `has_singular_gap()` and [`Self::has_singular_support`] read
    /// the *same* boolean pointwise: one observed cell *is* one
    /// unobserved cell when the axis carries exactly two cells. On
    /// cardinality ≥ `3` the two are disjoint at every histogram
    /// (support `1` ≠ `axis_cardinality - 1 ≥ 2`). The cardinality-`2`
    /// coincidence is the structural witness for the dual-boundary
    /// collapse on the smallest non-trivial axis (pinned on
    /// [`PartitionFace`] in [`tests`]); the cardinality-`3`
    /// disjointness is pinned on [`DiffLineKind`] in [`tests`].
    ///
    /// **Companion invariants** with [`Self::is_empty`],
    /// [`Self::is_full_cover`], [`Self::has_partial_cover`],
    /// [`Self::has_singular_support`], [`Self::distinct_cells`], and
    /// [`Self::unobserved_cells`]:
    /// - `has_singular_gap() ⇔ unobserved_cells() == 1` — the
    ///   defining equivalence on the unobserved-cardinality scalar
    ///   peer; reading "the support carries exactly one missing kind"
    ///   off one named boolean instead of an equality against a
    ///   `usize` on the unobserved-cardinality scalar.
    /// - `has_singular_gap() ⇔ distinct_cells() == axis_cardinality::<A>() - 1`
    ///   on every implementor with `axis_cardinality::<A>() >= 1` — the
    ///   support-side dual form via the
    ///   `distinct_cells + unobserved_cells == axis_cardinality`
    ///   partition invariant. Peer of the
    ///   `has_singular_support() ⇔ distinct_cells() == 1` equivalence
    ///   on the opposite end of the support-cardinality interval:
    ///   `has_singular_support` reads support cardinality `1`,
    ///   `has_singular_gap` reads support cardinality `axis_cardinality - 1`.
    /// - `has_singular_gap() ⇒ has_partial_cover()` on every
    ///   implementor with `axis_cardinality::<A>() >= 2`: one
    ///   unobserved cell means at least one observed
    ///   (cardinality `- 1 >= 1`) and at least one unobserved, so the
    ///   histogram sits strictly between empty and full cover. Peer
    ///   of `has_singular_support() ⇒ has_partial_cover()` on the
    ///   opposite end of the support-cardinality interval — both
    ///   singular boundaries land on the partial-cover middle leg of
    ///   the `(is_empty, has_partial_cover, is_full_cover)`
    ///   trichotomy.
    /// - `has_singular_gap() ⇒ !is_full_cover()` always: full cover
    ///   has zero unobserved cells, singular gap has exactly one.
    /// - `has_singular_gap() ∧ is_empty()` ⇒ `axis_cardinality::<A>() == 1`
    ///   — on every implementor with `axis_cardinality::<A>() >= 2`
    ///   (every implementor today), `has_singular_gap()` and
    ///   `is_empty()` are disjoint: empty has every cell unobserved
    ///   (cardinality, not `1`), so the conjunction reads `false`
    ///   uniformly.
    /// - `has_singular_gap() ⇔ has_singular_support()` on every
    ///   implementor with `axis_cardinality::<A>() == 2` — the
    ///   structural cardinality-`2` coincidence: one observed cell
    ///   coincides pointwise with one unobserved cell on the smallest
    ///   non-trivial axis. On cardinality ≥ `3` the two are
    ///   pointwise disjoint.
    /// - The merge behavior is *non-monotonic*: merging two
    ///   singular-gap histograms whose missing cells differ fills
    ///   both gaps and lands the merge at full cover (loses singular
    ///   gap); merging two singular-gap histograms whose missing cells
    ///   coincide preserves the singular gap; merging a singular-gap
    ///   histogram with an empty histogram preserves the singular gap
    ///   (empty-identity law:
    ///   `merge(self, empty).has_singular_gap() == self.has_singular_gap()`).
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor (the twenty
    /// closed-enum axis primitives plus the five product cubes —
    /// twenty-five today, reached uniformly through
    /// `for_each_closed_axis_implementor!` in [`tests`]) inherits the
    /// predicate at no per-axis cost. The three trait-uniform laws
    /// pinned in [`tests`] hold across the implementor set
    /// (`axis_histogram_has_singular_gap_empty_iff_cardinality_is_one_*`,
    /// `axis_histogram_has_singular_gap_singleton_iff_cardinality_is_two_*`,
    /// `axis_histogram_has_singular_gap_axis_cover_is_false_*`).
    ///
    /// **The dual-singular pair on the support-cardinality interval.**
    /// Before this lift, every consumer asking *"is the chain one cell
    /// short of full coverage?"* re-derived the predicate inline as
    /// `hist.unobserved_cells() == 1` (an equality against a `usize`
    /// on the unobserved-cardinality scalar peer), as
    /// `hist.distinct_cells() == axis_cardinality::<C>() - 1` (importing
    /// [`axis_cardinality`], turbofish-naming the axis, and writing the
    /// `- 1` arithmetic at the call site), or as
    /// `hist.unobserved().count() == 1` (allocating the [`Self::unobserved`]
    /// iterator just to count its prefix). The lift names the dual
    /// boundary directly at one site — the typed boolean every "almost-
    /// covered", "one kind missing", "single-gap attestation" dashboard
    /// cell reads off as a single method call, and the dual-singular
    /// pair `(has_singular_support, has_singular_gap)` on the support-
    /// cardinality interval becomes a typed pair pinned by the
    /// cardinality-`2` coincidence and cardinality-`3` disjointness
    /// laws across every closed-axis implementor.
    #[must_use]
    pub fn has_singular_gap(&self) -> bool {
        let mut zeros = self.counts.iter().filter(|&&c| c == 0);
        zeros.next().is_some() && zeros.next().is_none()
    }

    /// `true` exactly when the histogram's support sits *strictly between*
    /// the two singular-cardinality boundaries — at least *two* observed
    /// cells *and* at least *two* unobserved cells. The
    /// **strict-partial-cover predicate** on the histogram surface: the
    /// interior of the
    /// `(is_empty, has_singular_support, has_strict_partial_cover,
    /// has_singular_gap, is_full_cover)` 5-corner partition of the
    /// support-cardinality scalar, sitting strictly inside the
    /// `has_partial_cover` middle leg of the coarser coverage trichotomy.
    ///
    /// Pointwise equivalent to four documented surface predicates that
    /// previously had no single named boolean —
    /// `self.has_partial_cover() && !self.has_singular_support() &&
    /// !self.has_singular_gap()` (the structural conjunction form on the
    /// existing named-boundary triad), `1 < self.distinct_cells() &&
    /// self.distinct_cells() + 1 < axis_cardinality::<A>()` (the
    /// support-cardinality strict-interval form on the named scalar peer
    /// with both singular boundaries excluded), `1 < self.unobserved_cells()
    /// && self.unobserved_cells() + 1 < axis_cardinality::<A>()` (the
    /// gap-cardinality strict-interval form on the complementary scalar
    /// peer), and `self.nonzero().nth(1).is_some() &&
    /// self.unobserved().nth(1).is_some()` (the dual-iterator
    /// at-least-two-of-each form, which allocates both iterators just to
    /// peek their second elements) — collapsed to one method call with a
    /// single-pass scan that short-circuits once it has witnessed both *two*
    /// zero counts and *two* nonzero counts (the early-exit form bounds
    /// the cost at four witness cells rather than two full walks of the
    /// counts vector or two iterator allocations).
    ///
    /// **The 5-corner support-cardinality partition.** The boolean surface
    /// on the support-cardinality scalar now carries the strict 5-corner
    /// partition
    /// `(is_empty, has_singular_support, has_strict_partial_cover,
    /// has_singular_gap, is_full_cover)` — "did the chain see *nothing*?",
    /// "did the chain see *exactly one* kind?", "did the chain see *some
    /// but not the singular boundaries*?", "did the chain see *all but
    /// one* kind?", "did the chain see *every* kind?" — each
    /// independently checkable in one method call. On every implementor
    /// with `axis_cardinality::<A>() >= 3` (every cardinality-3+
    /// implementor on the typescape today) the five corners are pairwise
    /// disjoint *and* jointly exhaustive: exactly one fires on any
    /// histogram. On cardinality `2` the two singular corners coincide
    /// (the cardinality-`2` collapse already pinned on
    /// [`Self::has_singular_gap`]); on cardinality `1` the empty and
    /// full-cover corners coincide; on cardinality `0` (no implementor
    /// today, but structurally permitted by [`ClosedAxis`]) every corner
    /// collapses onto empty / full-cover. The strict-interior corner
    /// `has_strict_partial_cover` is the boundary-free middle of the
    /// partition — every "neither blank, nor singularly-observed, nor
    /// singularly-missing, nor exhausted" diagnostic, attestation, or
    /// dashboard cell branches on this corner directly.
    ///
    /// **Empty-histogram convention** — returns `false` on every
    /// implementor: no cell observed, so the "at least two observed" half
    /// of the conjunction fails uniformly. The named boundary
    /// [`Self::is_empty`] carries that case.
    ///
    /// **Full-cover convention** — returns `false` on every implementor:
    /// every cell observed, so the "at least two unobserved" half of the
    /// conjunction fails uniformly. The named boundary
    /// [`Self::is_full_cover`] carries that case.
    ///
    /// **Singleton-observation convention** — every singleton observation
    /// lands the support cardinality at exactly `1`, so the "at least two
    /// observed" half fails uniformly. The named boundary
    /// [`Self::has_singular_support`] carries that case;
    /// `has_strict_partial_cover` reads `false` on every singleton across
    /// every implementor.
    ///
    /// **Cardinality-conditional reachability.** The strict interior of
    /// the support-cardinality scalar is reachable only on
    /// `axis_cardinality::<A>() >= 4` axes: on cardinality `0`, `1`, `2`,
    /// or `3`, the support values `[0, axis_cardinality]` reach only the
    /// four named boundary corners (the singular boundaries collide with
    /// each other on cardinality `2` and sit adjacent at supports `1` and
    /// `cardinality - 1 == 2` on cardinality `3`), so the
    /// `[2, axis_cardinality - 2]` strict interior is empty as a set of
    /// support cardinalities. On every implementor with cardinality `>= 4`
    /// the strict interior carries witnesses — e.g. on [`Format`]
    /// (cardinality 4) the strict interior fires at support cardinality
    /// exactly `2`; on [`crate::AttributionRule`] (cardinality 5) at
    /// supports `2` and `3`; on [`crate::ShikumiErrorKind`] (cardinality
    /// 6) at supports `2`, `3`, and `4`.
    ///
    /// **Companion invariants** with [`Self::is_empty`],
    /// [`Self::is_full_cover`], [`Self::has_partial_cover`],
    /// [`Self::has_singular_support`], [`Self::has_singular_gap`],
    /// [`Self::distinct_cells`], [`Self::unobserved_cells`], and
    /// [`Self::merge`]:
    /// - `has_strict_partial_cover() ⇔ has_partial_cover() &&
    ///   !has_singular_support() && !has_singular_gap()` — the defining
    ///   equivalence on the existing named-boundary triad: the strict
    ///   interior is exactly the partial-cover middle leg minus its two
    ///   singular-cardinality corners.
    /// - `has_strict_partial_cover() ⇔ 1 < distinct_cells() &&
    ///   distinct_cells() + 1 < axis_cardinality::<A>()` — the
    ///   support-cardinality strict-interval form on the named scalar
    ///   peer with *both* singular boundaries excluded. Peer of
    ///   `has_partial_cover() ⇔ 0 < distinct_cells() && distinct_cells()
    ///   < axis_cardinality::<A>()` on the coarser middle leg of the
    ///   coverage trichotomy.
    /// - `has_strict_partial_cover() ⇔ 1 < unobserved_cells() &&
    ///   unobserved_cells() + 1 < axis_cardinality::<A>()` — the
    ///   gap-cardinality strict-interval form via the
    ///   `distinct_cells + unobserved_cells == axis_cardinality`
    ///   partition invariant.
    /// - `has_strict_partial_cover() ⇒ has_partial_cover()` always:
    ///   the strict interior sits inside the partial-cover middle leg.
    ///   The converse fails at both singular corners — the two singular
    ///   boundaries `has_singular_support` and `has_singular_gap` carry
    ///   the cells of the partial-cover middle leg that
    ///   `has_strict_partial_cover` excludes.
    /// - `(has_singular_support, has_strict_partial_cover,
    ///   has_singular_gap)` is pairwise disjoint on every implementor
    ///   with `axis_cardinality::<A>() >= 3`: distinct support
    ///   cardinalities (1, `[2, cardinality - 2]`, `cardinality - 1`)
    ///   never overlap. Together with the two boundary corners, the five
    ///   predicates partition every histogram on every cardinality-`>= 3`
    ///   axis.
    /// - The merge behavior is *non-monotonic*: merging two
    ///   strict-interior histograms can produce a strict-interior merge
    ///   (when the union of supports stays strictly between the singular
    ///   boundaries), a singular-gap merge (when the union covers all
    ///   but one cell), or a full-cover merge (when the union exhausts
    ///   the axis); merging two non-strict-interior histograms can
    ///   produce a strict-interior merge when the union grows past the
    ///   singular-support corner without reaching the singular-gap
    ///   corner. The empty-identity law holds:
    ///   `merge(self, empty).has_strict_partial_cover() ==
    ///   self.has_strict_partial_cover()`.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor (the twenty
    /// closed-enum axis primitives plus the five product cubes — twenty-
    /// five today, reached uniformly through
    /// `for_each_closed_axis_implementor!` in [`tests`]) inherits the
    /// predicate at no per-axis cost. The three trait-uniform laws pinned
    /// in [`tests`] hold across the implementor set
    /// (`axis_histogram_has_strict_partial_cover_empty_is_false_*`,
    /// `axis_histogram_has_strict_partial_cover_singleton_is_false_*`,
    /// `axis_histogram_has_strict_partial_cover_axis_cover_is_false_*`).
    ///
    /// **The boundary-free interior of the support-cardinality scalar.**
    /// Where [`Self::has_partial_cover`] reads the *coarse* "neither
    /// empty nor full" middle leg of the (`is_empty`,
    /// `has_partial_cover`, `is_full_cover`) coverage trichotomy,
    /// `has_strict_partial_cover` reads the *strict* interior of the
    /// support-cardinality interval — the partial-cover middle leg with
    /// both singular-cardinality corners (`has_singular_support` and
    /// `has_singular_gap`) excluded. Before this lift, every consumer
    /// asking *"is the chain in the interior of the support-cardinality
    /// scalar — neither on a singular boundary nor on a coverage
    /// boundary?"* re-derived the predicate inline as
    /// `hist.has_partial_cover() && !hist.has_singular_support() &&
    /// !hist.has_singular_gap()` (three method calls and two negations
    /// across three named predicates), as `1 < hist.distinct_cells() &&
    /// hist.distinct_cells() + 1 < axis_cardinality::<C>()` (importing
    /// [`axis_cardinality`], turbofish-naming the axis, and writing the
    /// `+ 1 <` strict-bound arithmetic at the call site), or as
    /// `hist.nonzero().nth(1).is_some() && hist.unobserved().nth(1).is_some()`
    /// (allocating both iterators just to peek at their second elements).
    /// The lift names the strict interior directly at one site — the
    /// typed boolean every "support is in the interior of the
    /// `[2, cardinality - 2]` range" attestation reads off as a single
    /// method call, and the 5-corner support-cardinality strict partition
    /// (`is_empty`, `has_singular_support`, `has_strict_partial_cover`,
    /// `has_singular_gap`, `is_full_cover`) becomes a pinned structural
    /// law on every cardinality-`>= 3` implementor.
    #[must_use]
    pub fn has_strict_partial_cover(&self) -> bool {
        let mut zeros: u8 = 0;
        let mut nonzeros: u8 = 0;
        for &c in &self.counts {
            if c == 0 {
                zeros = zeros.saturating_add(1);
            } else {
                nonzeros = nonzeros.saturating_add(1);
            }
            if zeros >= 2 && nonzeros >= 2 {
                return true;
            }
        }
        false
    }

    /// `true` exactly when the histogram's support sits at the bottom of
    /// the support-cardinality interval — at most one observed cell. The
    /// **low-support predicate** on the histogram surface: the
    /// histogram-side peer of
    /// [`SupportCardinalityClass::is_low_support`], naming the bottom
    /// leg of the
    /// (`has_low_support`, `has_strict_partial_cover`, `has_high_support`)
    /// magnitude-direction ternary partition of the 5-corner
    /// support-cardinality scalar.
    ///
    /// Pointwise equivalent to three documented surface forms — each
    /// names the same compound differently:
    /// - `self.is_empty() || self.has_singular_support()` (the
    ///   union-of-low-boundaries form on the two named histogram-side
    ///   peers — the canonical disjunction).
    /// - `self.distinct_cells() <= 1` (the support-cardinality
    ///   scalar form on the named scalar peer — the "support magnitude
    ///   at most one" form).
    /// - The class-side projection of
    ///   [`SupportCardinalityClass::is_low_support`]:
    ///   `hist.has_low_support() ==
    ///    hist.support_cardinality_class().is_low_support()` — the
    ///   cross-surface bridge law pinned trait-uniformly across every
    ///   [`ClosedAxis`] implementor.
    ///
    /// Collapsed to one method call with a single-pass scan that
    /// short-circuits on the second nonzero count (the early-exit form
    /// bounds the cost at two nonzero-witness cells rather than two full
    /// walks of the counts vector across the
    /// `is_empty` + `has_singular_support` disjunction, or a separate
    /// pass through [`Self::distinct_cells`] to read off the scalar
    /// inequality).
    ///
    /// **Empty-histogram convention** — reads `true` on every implementor:
    /// no cell observed, so the "at most one observed" predicate holds
    /// vacuously. The named boundary [`Self::is_empty`] carries that
    /// case via the union-of-low-boundaries form.
    ///
    /// **Singleton-observation convention** — reads `true` uniformly on
    /// every singleton across every implementor: a singleton has exactly
    /// one observed cell. The named boundary
    /// [`Self::has_singular_support`] carries that case.
    ///
    /// **Axis-cover convention** — reads `true` iff
    /// `axis_cardinality::<A>() <= 1` (no implementor today carries
    /// cardinality `<= 1`, so axis-cover reads `false` uniformly across
    /// the implementor set).
    ///
    /// **Companion invariants** with [`Self::is_empty`],
    /// [`Self::has_singular_support`], [`Self::has_strict_partial_cover`],
    /// [`Self::has_high_support`], [`Self::distinct_cells`], and
    /// [`Self::support_cardinality_class`]:
    /// - `has_low_support() ⇔ is_empty() || has_singular_support()` —
    ///   the defining union-of-low-boundaries equivalence on the two
    ///   named histogram-side peers (pinned by
    ///   [`tests::axis_histogram_has_low_support_equals_is_empty_or_has_singular_support`]).
    /// - `has_low_support() ⇔ distinct_cells() <= 1` — the
    ///   support-cardinality scalar form on the named scalar peer
    ///   (pinned by
    ///   [`tests::axis_histogram_has_low_support_equals_distinct_cells_at_most_one`]).
    /// - `(has_low_support, has_strict_partial_cover, has_high_support)`
    ///   is a strict ternary partition on every implementor with
    ///   `axis_cardinality::<A>() >= 2`: pairwise disjoint *and* jointly
    ///   exhaustive. Stated as
    ///   `u8::from(has_low_support()) + u8::from(has_strict_partial_cover()) + u8::from(has_high_support()) == 1`
    ///   — exactly one fires on any histogram (pinned by
    ///   [`tests::axis_histogram_has_low_support_has_strict_partial_cover_has_high_support_form_strict_ternary_partition_for_every_closed_axis_implementor`]).
    /// - `has_low_support()` and `has_high_support()` are disjoint on
    ///   every implementor with `axis_cardinality::<A>() >= 2`:
    ///   distinct support magnitudes (`<= 1` vs. `>= cardinality - 1`
    ///   with cardinality `>= 2` excluding the singleton) never overlap
    ///   (pinned by
    ///   [`tests::axis_histogram_has_low_support_and_has_high_support_are_disjoint_for_every_closed_axis_implementor`]).
    /// - `is_empty() ⇒ has_low_support()` and
    ///   `has_singular_support() ⇒ has_low_support()` — the implication
    ///   chain over the two boundary peers (pinned by
    ///   [`tests::axis_histogram_two_low_boundary_predicates_imply_has_low_support_for_every_closed_axis_implementor`]).
    ///
    /// **Cross-surface bridge law** —
    /// `hist.has_low_support() ==
    ///  hist.support_cardinality_class().is_low_support()` for every
    /// `hist: AxisHistogram<A>` on every [`ClosedAxis`] implementor,
    /// pinned trait-uniformly through the
    /// `for_each_closed_axis_implementor!` macro by
    /// [`tests::axis_histogram_has_low_support_agrees_with_class_is_low_support_for_every_closed_axis_implementor`].
    /// The bridge closes the (histogram, class) duality on the
    /// magnitude-direction ternary partition's bottom leg from the
    /// histogram side — peer to the
    /// [`SupportCardinalityClass::is_low_support`] bridge already
    /// pinned from the class side via the disjunction
    /// `is_empty() || has_singular_support()`. The two surfaces now
    /// carry one named boolean each on the bottom leg, pinned end-to-
    /// end.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor inherits the
    /// predicate at no per-axis cost.
    #[must_use]
    pub fn has_low_support(&self) -> bool {
        let mut nonzeros: u8 = 0;
        for &c in &self.counts {
            if c > 0 {
                nonzeros = nonzeros.saturating_add(1);
                if nonzeros >= 2 {
                    return false;
                }
            }
        }
        true
    }

    /// `true` exactly when the histogram's support sits at the top of
    /// the support-cardinality interval — at most one unobserved cell,
    /// excising the cardinality-2 dual-singular-collapse case where the
    /// singleton coincides with the cardinality-1 unobserved-cell shape.
    /// The **high-support predicate** on the histogram surface: the
    /// histogram-side peer of
    /// [`SupportCardinalityClass::is_high_support`], naming the top leg
    /// of the
    /// (`has_low_support`, `has_strict_partial_cover`, `has_high_support`)
    /// magnitude-direction ternary partition of the 5-corner support-
    /// cardinality scalar.
    ///
    /// Pointwise equivalent to three documented surface forms — each
    /// names the same compound differently:
    /// - `self.is_full_cover() || (self.has_singular_gap() && !self.has_singular_support())`
    ///   (the strict-singular-gap-or-full-cover form on three named
    ///   histogram-side peers — the canonical disjunction with the
    ///   cardinality-2 collapse excised via the
    ///   `!has_singular_support()` clause).
    /// - `self.distinct_cells() + 1 >= axis_cardinality::<A>() && self.distinct_cells() >= 2`
    ///   (the support-cardinality scalar form on the named scalar peer
    ///   — "support magnitude at least `cardinality - 1`" with the
    ///   cardinality-2 singleton excised via the
    ///   `distinct_cells() >= 2` clause).
    /// - The class-side projection of
    ///   [`SupportCardinalityClass::is_high_support`]:
    ///   `hist.has_high_support() ==
    ///    hist.support_cardinality_class().is_high_support()` — the
    ///   cross-surface bridge law pinned trait-uniformly across every
    ///   [`ClosedAxis`] implementor.
    ///
    /// Collapsed to one method call with a single-pass scan that short-
    /// circuits on the second *zero* count (the early-exit form bounds
    /// the cost at two zero-witness cells rather than three method
    /// calls and two negations across the
    /// `is_full_cover` + `has_singular_gap` + `has_singular_support`
    /// strict-singular-gap form).
    ///
    /// **Empty-histogram convention** — reads `false` on every
    /// implementor with `axis_cardinality::<A>() >= 2`: every cell
    /// unobserved means `unobserved_cells() == axis_cardinality::<A>()`,
    /// not `<= 1`. The named boundary [`Self::is_empty`] carries the
    /// empty case via the disjoint [`Self::has_low_support`] peer on
    /// the opposite end of the magnitude interval.
    ///
    /// **Singleton-observation convention** — reads `true` iff
    /// `axis_cardinality::<A>() == 1` (no implementor today carries
    /// cardinality `1`, so singleton reads `false` uniformly across the
    /// implementor set). The `!has_singular_support()` clause in the
    /// disjunction form excises every cardinality-2 singleton — where
    /// the histogram-side `has_singular_gap()` predicate fires
    /// spuriously under the dual-singular collapse — and lands the
    /// shape on `has_low_support` (the singleton always sits at the
    /// bottom of the magnitude interval, not the top).
    ///
    /// **Axis-cover convention** — reads `true` uniformly on every
    /// implementor: observing every cell exactly once is
    /// [`Self::is_full_cover`], which fires `has_high_support` via the
    /// `is_full_cover()` disjunct on the bridge.
    ///
    /// **Companion invariants** with [`Self::is_full_cover`],
    /// [`Self::has_singular_gap`], [`Self::has_singular_support`],
    /// [`Self::has_strict_partial_cover`], [`Self::has_low_support`],
    /// [`Self::distinct_cells`], and [`Self::support_cardinality_class`]:
    /// - `has_high_support() ⇔ is_full_cover()
    ///   || (has_singular_gap() && !has_singular_support())` — the
    ///   defining strict-singular-gap-or-full-cover equivalence on
    ///   three named histogram-side peers (pinned by
    ///   [`tests::axis_histogram_has_high_support_equals_full_cover_or_strict_singular_gap`]).
    /// - `(has_low_support, has_strict_partial_cover, has_high_support)`
    ///   is a strict ternary partition on every implementor with
    ///   `axis_cardinality::<A>() >= 2` (pinned by
    ///   [`tests::axis_histogram_has_low_support_has_strict_partial_cover_has_high_support_form_strict_ternary_partition_for_every_closed_axis_implementor`]).
    /// - `is_full_cover() ⇒ has_high_support()` — the implication
    ///   chain over the full-cover top peer (pinned by
    ///   [`tests::axis_histogram_full_cover_implies_has_high_support_for_every_closed_axis_implementor`]).
    ///
    /// **Cross-surface bridge law** —
    /// `hist.has_high_support() ==
    ///  hist.support_cardinality_class().is_high_support()` for every
    /// `hist: AxisHistogram<A>` on every [`ClosedAxis`] implementor,
    /// pinned trait-uniformly through the
    /// `for_each_closed_axis_implementor!` macro by
    /// [`tests::axis_histogram_has_high_support_agrees_with_class_is_high_support_for_every_closed_axis_implementor`].
    /// The bridge closes the (histogram, class) duality on the
    /// magnitude-direction ternary partition's top leg from the
    /// histogram side — peer to the
    /// [`SupportCardinalityClass::is_high_support`] bridge already
    /// pinned from the class side via the strict-singular-gap
    /// disjunction.
    ///
    /// **Cardinality-2 collapse — bottom-boundary-first.** On
    /// cardinality-2 axes (e.g. [`crate::PartitionFace`],
    /// [`crate::SecretRefShape`]) every singleton histogram has exactly
    /// one observed cell *and* exactly one unobserved cell —
    /// [`Self::has_singular_support`] and [`Self::has_singular_gap`]
    /// both fire pointwise. The class-side projection
    /// [`Self::support_cardinality_class`] resolves the collision via
    /// bottom-boundary-first priority (the shape lands on
    /// [`SupportCardinalityClass::SingularSupport`], where
    /// [`SupportCardinalityClass::is_high_support`] reads `false`).
    /// `has_high_support` matches that resolution by requiring *strict*
    /// singular gap: the `!has_singular_support()` clause rules out
    /// every cardinality-2 singleton, and the bridge holds pointwise
    /// on cardinality-2 axes by construction.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor inherits the
    /// predicate at no per-axis cost.
    #[must_use]
    pub fn has_high_support(&self) -> bool {
        let mut zeros: u8 = 0;
        let mut nonzeros: u8 = 0;
        for &c in &self.counts {
            if c == 0 {
                zeros = zeros.saturating_add(1);
                if zeros >= 2 {
                    return false;
                }
            } else {
                nonzeros = nonzeros.saturating_add(1);
            }
        }
        // Loop ended with zeros <= 1. zeros == 0 → full cover (high).
        // zeros == 1 → exactly one unobserved cell. On cardinality-2
        // axes that's the dual-singular-collapse singleton (nonzeros
        // == 1) — excised here. On cardinality-`>= 3` axes nonzeros
        // is `cardinality - 1 >= 2`, so the shape lands on
        // SingularGap (high).
        zeros == 0 || nonzeros >= 2
    }

    /// `true` exactly when the histogram sits on a **coverage boundary**
    /// — either no cell observed ([`Self::is_empty`]) or every cell
    /// observed ([`Self::is_full_cover`]). The **boundary predicate** on
    /// the histogram surface: the histogram-side peer of
    /// [`SupportCardinalityClass::is_boundary`], naming the boundary
    /// leg of the (`is_boundary`, `is_singular`, `is_strict_partial_cover`)
    /// distance-from-boundary ternary partition of the 5-corner
    /// support-cardinality scalar, *and* the bipartition leg of the
    /// (`has_boundary`, `has_partial_cover`) strict bipartition of the
    /// histogram surface — the union-of-extremes complement of the
    /// `has_partial_cover` middle leg.
    ///
    /// Pointwise equivalent to three documented surface forms — each
    /// names the same compound differently:
    /// - `self.is_empty() || self.is_full_cover()` (the
    ///   union-of-coverage-boundaries form on the two named histogram-
    ///   side peers — the canonical disjunction).
    /// - `!self.has_partial_cover()` (the strict-complement form on
    ///   the named middle compound — `has_boundary` and
    ///   `has_partial_cover` form a strict bipartition of the histogram
    ///   surface, peer to the class-side
    ///   (`is_boundary`, `is_partial_cover`) bipartition already pinned
    ///   on [`SupportCardinalityClass`]).
    /// - The class-side projection of
    ///   [`SupportCardinalityClass::is_boundary`]:
    ///   `hist.has_boundary() ==
    ///    hist.support_cardinality_class().is_boundary()` — the
    ///   cross-surface bridge law pinned trait-uniformly across every
    ///   [`ClosedAxis`] implementor.
    ///
    /// Collapsed to one method call with a single-pass scan that
    /// short-circuits the *moment* a zero count *and* a nonzero count
    /// have both been witnessed (the early-exit form bounds the cost at
    /// two witness cells — one zero, one nonzero — rather than two full
    /// walks of the counts vector across the
    /// `is_empty` + `is_full_cover` disjunction or a structural
    /// re-derivation of `has_partial_cover` followed by a negation).
    /// Structural dual of [`Self::has_partial_cover`], whose early-exit
    /// returns `true` on the same witness pair: `has_boundary` and
    /// `has_partial_cover` short-circuit on exactly the same condition,
    /// returning opposite booleans — the strict bipartition holds by
    /// construction at the scan level.
    ///
    /// **Empty-histogram convention** — reads `true` on every implementor:
    /// no cell observed means [`Self::is_empty`] reads `true`, which
    /// fires `has_boundary` via the `is_empty()` disjunct on the bridge.
    /// The named boundary [`Self::is_empty`] carries the empty case.
    ///
    /// **Axis-cover convention** — reads `true` uniformly on every
    /// implementor: observing every cell exactly once is
    /// [`Self::is_full_cover`], which fires `has_boundary` via the
    /// `is_full_cover()` disjunct on the bridge.
    ///
    /// **Singleton-observation convention** — reads `true` iff
    /// `axis_cardinality::<A>() == 1` (no implementor today carries
    /// cardinality `1`, so singleton reads `false` uniformly across the
    /// implementor set). A singleton has exactly one observed cell, so
    /// on cardinality `>= 2` it lands in `has_partial_cover` (some-
    /// but-not-all), strictly off both boundaries.
    ///
    /// **Companion invariants** with [`Self::is_empty`],
    /// [`Self::is_full_cover`], [`Self::has_partial_cover`],
    /// [`Self::distinct_cells`], and [`Self::support_cardinality_class`]:
    /// - `has_boundary() ⇔ is_empty() || is_full_cover()` — the
    ///   defining union-of-coverage-boundaries equivalence on the two
    ///   named histogram-side peers (pinned by
    ///   [`tests::axis_histogram_has_boundary_equals_is_empty_or_is_full_cover`]).
    /// - `has_boundary() ⇔ !has_partial_cover()` — the strict-
    ///   complement equivalence on the named middle compound (pinned by
    ///   [`tests::axis_histogram_has_boundary_equals_complement_of_has_partial_cover`]).
    /// - `(has_boundary, has_partial_cover)` is a strict bipartition on
    ///   every implementor: pairwise disjoint *and* jointly exhaustive.
    ///   Stated as
    ///   `u8::from(has_boundary()) + u8::from(has_partial_cover()) == 1`
    ///   — exactly one compound fires on any histogram (pinned by
    ///   [`tests::axis_histogram_has_boundary_and_has_partial_cover_form_strict_bipartition_for_every_closed_axis_implementor`]).
    ///   The histogram-side peer of the class-side bipartition already
    ///   pinned on [`SupportCardinalityClass`] by
    ///   [`tests::support_cardinality_class_is_boundary_and_is_partial_cover_form_strict_bipartition`].
    /// - Implication chain over the two boundary peers:
    ///   `is_empty() ⇒ has_boundary()` and
    ///   `is_full_cover() ⇒ has_boundary()` (pinned by
    ///   [`tests::axis_histogram_two_coverage_boundary_predicates_imply_has_boundary_for_every_closed_axis_implementor`]).
    ///
    /// **Cross-surface bridge law** —
    /// `hist.has_boundary() ==
    ///  hist.support_cardinality_class().is_boundary()` for every
    /// `hist: AxisHistogram<A>` on every [`ClosedAxis`] implementor,
    /// pinned trait-uniformly through the
    /// `for_each_closed_axis_implementor!` macro by
    /// [`tests::axis_histogram_has_boundary_agrees_with_class_is_boundary_for_every_closed_axis_implementor`].
    /// The bridge closes the (histogram, class) duality on the
    /// boundary leg from the histogram side — peer to the
    /// [`SupportCardinalityClass::is_boundary`] bridge already pinned
    /// from the class side via the verbose
    /// `is_empty() || is_full_cover()` disjunction. The two surfaces
    /// now carry one named boolean each on the boundary leg, pinned
    /// end-to-end.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor (the closed-
    /// enum axis primitives plus the product cubes, reached uniformly
    /// through `for_each_closed_axis_implementor!` in [`tests`])
    /// inherits the predicate at no per-axis cost.
    #[must_use]
    pub fn has_boundary(&self) -> bool {
        let mut saw_zero = false;
        let mut saw_nonzero = false;
        for &c in &self.counts {
            if c == 0 {
                saw_zero = true;
            } else {
                saw_nonzero = true;
            }
            if saw_zero && saw_nonzero {
                return false;
            }
        }
        true
    }

    /// `true` exactly when the histogram sits on a **singular
    /// near-boundary** — either exactly one cell observed
    /// ([`Self::has_singular_support`]) or exactly one cell unobserved
    /// ([`Self::has_singular_gap`]). The **singular predicate** on the
    /// histogram surface: the histogram-side peer of
    /// [`SupportCardinalityClass::is_singular`], naming the
    /// *exactly-one-cell-off-boundary* leg of the
    /// (`has_boundary`, `has_singular`, `has_strict_partial_cover`)
    /// distance-from-boundary ternary partition of the 5-corner support-
    /// cardinality scalar on the histogram surface. The middle leg
    /// `has_partial_cover` of the coarser (`has_boundary`,
    /// `has_partial_cover`) bipartition decomposes through this lift as
    /// `has_partial_cover == has_singular ∪ has_strict_partial_cover` —
    /// the *one-cell-off-boundary* refinement of the strict-interior leg.
    ///
    /// Pointwise equivalent to four documented surface forms — each
    /// names the same compound differently:
    /// - `self.has_singular_support() || self.has_singular_gap()` (the
    ///   union-of-singular-boundaries form on the two named histogram-
    ///   side peers — the canonical disjunction).
    /// - `self.has_partial_cover() && !self.has_strict_partial_cover()`
    ///   (the partial-cover-minus-strict-interior form: the singular
    ///   compound is exactly the partial-cover middle leg with the
    ///   strict-interior `has_strict_partial_cover` predicate excised).
    /// - The class-side projection of
    ///   [`SupportCardinalityClass::is_singular`]:
    ///   `hist.has_singular() ==
    ///    hist.support_cardinality_class().is_singular()` — the
    ///   cross-surface bridge law pinned trait-uniformly across every
    ///   [`ClosedAxis`] implementor.
    /// - `self.distinct_cells() == 1 || self.unobserved_cells() == 1`
    ///   (the dual-scalar equality form on the two named cardinality
    ///   peers — exactly one observed *or* exactly one unobserved cell,
    ///   on the `distinct_cells + unobserved_cells == axis_cardinality`
    ///   partition invariant).
    ///
    /// Collapsed to one method call with a single-pass scan that
    /// short-circuits the *moment* both a *second* zero count *and* a
    /// *second* nonzero count have been witnessed (the early-exit form
    /// bounds the cost at four witness cells — two zeros and two
    /// nonzeros — rather than two full walks of the counts vector
    /// across the `has_singular_support` + `has_singular_gap`
    /// disjunction or a structural re-derivation of `has_partial_cover`
    /// followed by `!has_strict_partial_cover()`). Structural dual of
    /// [`Self::has_strict_partial_cover`], whose early-exit returns
    /// `true` on the same witness pair: `has_singular` and
    /// `has_strict_partial_cover` short-circuit on exactly the same
    /// condition with opposite branches — once two zeros and two
    /// nonzeros are seen, the strict-interior corner of the partial-
    /// cover middle leg is locked in and the singular pair is excluded.
    ///
    /// **Empty-histogram convention** — reads `false` on every
    /// implementor with `axis_cardinality::<A>() >= 2` (every
    /// implementor today): empty has every cell unobserved (zeros =
    /// cardinality, nonzeros = 0), so neither `has_singular_support`
    /// (nonzeros == 1) nor `has_singular_gap` (zeros == 1) fires. The
    /// named boundary [`Self::is_empty`] carries the empty case via the
    /// peer compound [`Self::has_boundary`].
    ///
    /// **Axis-cover convention** — reads `false` uniformly on every
    /// implementor with `axis_cardinality::<A>() >= 2`: observing every
    /// cell exactly once is [`Self::is_full_cover`] (zeros = 0,
    /// nonzeros = cardinality), so neither singular boundary fires. The
    /// named boundary [`Self::is_full_cover`] carries the axis-cover
    /// case via the peer compound [`Self::has_boundary`].
    ///
    /// **Singleton-observation convention** — reads `true` uniformly on
    /// every implementor with `axis_cardinality::<A>() >= 2`. A
    /// singleton has nonzeros == 1, so `has_singular_support` fires; on
    /// cardinality-2 the same shape also has zeros == 1 (the dual-
    /// singular collapse pinned by
    /// `axis_histogram_has_singular_gap_equals_has_singular_support_on_cardinality_two`),
    /// so `has_singular_gap` fires too and the disjunction holds via
    /// either disjunct.
    ///
    /// **Companion invariants** with [`Self::has_singular_support`],
    /// [`Self::has_singular_gap`], [`Self::has_partial_cover`],
    /// [`Self::has_strict_partial_cover`], [`Self::has_boundary`], and
    /// [`Self::support_cardinality_class`]:
    /// - `has_singular() ⇔ has_singular_support() || has_singular_gap()`
    ///   — the defining union-of-singular-boundaries equivalence on the
    ///   two named histogram-side peers (pinned by
    ///   [`tests::axis_histogram_has_singular_equals_has_singular_support_or_has_singular_gap`]).
    /// - `has_singular() ⇔ has_partial_cover() &&
    ///   !has_strict_partial_cover()` — the partial-cover-minus-strict-
    ///   interior form on the named middle compound and its strict-
    ///   interior refinement (pinned by
    ///   [`tests::axis_histogram_has_singular_equals_has_partial_cover_and_not_has_strict_partial_cover`]).
    /// - `has_singular() ⇒ has_partial_cover()` always: every singular
    ///   shape lands in the partial-cover middle leg of the coarser
    ///   (`has_boundary`, `has_partial_cover`) bipartition — the
    ///   ternary partition refines the bipartition (pinned by
    ///   [`tests::axis_histogram_has_singular_implies_has_partial_cover_for_every_closed_axis_implementor`]).
    /// - `has_singular() ⇒ !has_boundary()` always on every implementor
    ///   with `axis_cardinality::<A>() >= 2`: the two singular near-
    ///   boundary corners sit strictly off the coverage boundaries
    ///   (pinned by
    ///   [`tests::axis_histogram_has_singular_implies_not_has_boundary_for_every_closed_axis_implementor`]).
    /// - `(has_boundary, has_singular, has_strict_partial_cover)` is a
    ///   strict ternary partition on every implementor with
    ///   `axis_cardinality::<A>() >= 2`: pairwise disjoint *and*
    ///   jointly exhaustive. Stated as
    ///   `u8::from(has_boundary()) + u8::from(has_singular()) + u8::from(has_strict_partial_cover()) == 1`
    ///   — exactly one compound fires on any histogram (pinned by
    ///   [`tests::axis_histogram_has_boundary_has_singular_has_strict_partial_cover_form_strict_ternary_partition_for_every_closed_axis_implementor`]).
    ///   The histogram-side peer of the class-side ternary partition
    ///   already pinned on [`SupportCardinalityClass`] by
    ///   [`tests::support_cardinality_class_is_boundary_is_singular_is_strict_partial_cover_form_strict_ternary_partition`].
    /// - Implication chain over the two singular peers:
    ///   `has_singular_support() ⇒ has_singular()` and
    ///   `has_singular_gap() ⇒ has_singular()` (pinned by
    ///   [`tests::axis_histogram_two_singular_boundary_predicates_imply_has_singular_for_every_closed_axis_implementor`]).
    ///
    /// **Cross-surface bridge law** —
    /// `hist.has_singular() ==
    ///  hist.support_cardinality_class().is_singular()` for every
    /// `hist: AxisHistogram<A>` on every [`ClosedAxis`] implementor,
    /// pinned trait-uniformly through the
    /// `for_each_closed_axis_implementor!` macro by
    /// [`tests::axis_histogram_has_singular_agrees_with_class_is_singular_for_every_closed_axis_implementor`].
    /// The bridge closes the (histogram, class) duality on the
    /// singular near-boundary leg from the histogram side — peer to the
    /// [`SupportCardinalityClass::is_singular`] bridge already pinned
    /// from the class side via the verbose
    /// `has_singular_support() || has_singular_gap()` disjunction (the
    /// existing `axis_histogram_support_cardinality_class_is_singular_agrees_with_histogram_has_singular_support_or_has_singular_gap_for_every_closed_axis_implementor`
    /// pin). The two surfaces now carry one named boolean each on the
    /// singular near-boundary leg, pinned end-to-end. With this lift,
    /// the (histogram, class) duality on the distance-from-boundary
    /// ternary partition closes on every leg: `has_boundary` /
    /// `is_boundary` on the boundary corner, `has_singular` /
    /// `is_singular` on the singular near-boundary corner, and
    /// `has_strict_partial_cover` / `is_strict_partial_cover` on the
    /// strict-interior corner.
    ///
    /// **Cardinality-2 dual-singular collapse.** On cardinality-2 axes
    /// (e.g. [`crate::PartitionFace`], [`crate::SecretRefShape`]) the
    /// two singular boundaries [`Self::has_singular_support`] (nonzeros
    /// == 1) and [`Self::has_singular_gap`] (zeros == 1) fire on the
    /// same shape (the singleton has one observed cell *and* one
    /// unobserved cell). `has_singular` reads `true` on the singleton
    /// via either disjunct of the union form, and the cross-surface
    /// bridge holds pointwise: the class-side projection lands on
    /// [`SupportCardinalityClass::SingularSupport`] by the bottom-
    /// boundary-first branching priority, and
    /// [`SupportCardinalityClass::is_singular`] reads `true` on that
    /// variant.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor (the closed-
    /// enum axis primitives plus the product cubes, reached uniformly
    /// through `for_each_closed_axis_implementor!` in [`tests`])
    /// inherits the predicate at no per-axis cost.
    #[must_use]
    pub fn has_singular(&self) -> bool {
        let mut zeros: u8 = 0;
        let mut nonzeros: u8 = 0;
        for &c in &self.counts {
            if c == 0 {
                zeros = zeros.saturating_add(1);
            } else {
                nonzeros = nonzeros.saturating_add(1);
            }
            if zeros >= 2 && nonzeros >= 2 {
                return false;
            }
        }
        zeros == 1 || nonzeros == 1
    }

    /// The **support-cardinality corner** of the histogram on the
    /// five-cell partition of the `[0, axis_cardinality::<A>()]`
    /// support-cardinality interval — the typed closed-classifier
    /// projection of the five boolean primitives ([`Self::is_empty`],
    /// [`Self::has_singular_support`],
    /// [`Self::has_strict_partial_cover`],
    /// [`Self::has_singular_gap`], [`Self::is_full_cover`]) onto a
    /// single named variant tag.
    ///
    /// Before this lift, every consumer asking "which corner of the
    /// support-cardinality interval did this window land in?" composed
    /// the five boolean reads into a five-way `if` ladder
    /// (`if hist.is_empty() { … } else if hist.has_singular_support() { … }
    ///  else if hist.has_strict_partial_cover() { … }
    ///  else if hist.has_singular_gap() { … }
    ///  else { … }`) — five method calls per shape, manually ordered
    /// to disambiguate the cardinality-2 collapse where
    /// `has_singular_support` and `has_singular_gap` both fire on the
    /// same shape, and silently dropping a corner if a future branch
    /// was added without updating every site. Collapsed to one
    /// inherent call returning a closed enum whose variants are
    /// disjoint by construction, with the cardinality-2 disambiguation
    /// baked into the branching priority (bottom-boundary-first: a
    /// shape that fires both `has_singular_support` and
    /// `has_singular_gap` lands on [`SupportCardinalityClass::SingularSupport`]).
    /// The compiler enforces exhaustiveness at every `match` site, so
    /// a future renderer landing on the typescape cannot silently
    /// drop a corner.
    ///
    /// **Five-corner partition on cardinality-`>= 3` axes.** The
    /// returned variant is the unique
    /// [`SupportCardinalityClass`] whose enum-level predicate (e.g.
    /// [`SupportCardinalityClass::is_singular_support`]) agrees with
    /// the corresponding histogram-surface boolean predicate on
    /// every cardinality-`>= 3` axis. On cardinality-2 axes
    /// (`PartitionFace`, `SecretRefShape`) the histogram-surface
    /// `has_singular_support` and `has_singular_gap` predicates both
    /// fire on the support-1 shape (the cardinality-2 dual-singular
    /// collapse pinned by the existing
    /// `axis_histogram_has_singular_gap_equals_has_singular_support_on_cardinality_two`
    /// law); the projection lands on
    /// [`SupportCardinalityClass::SingularSupport`] by the
    /// bottom-boundary-first branching priority. The peer-projection
    /// laws on [`SupportCardinalityClass::is_empty`] and
    /// [`SupportCardinalityClass::is_full_cover`] hold uniformly
    /// across every implementor regardless of cardinality.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor inherits the
    /// projection at no per-axis cost. Empty histograms land on
    /// [`SupportCardinalityClass::Empty`] uniformly; singleton
    /// histograms land on [`SupportCardinalityClass::SingularSupport`]
    /// uniformly; uniform axis-cover histograms land on
    /// [`SupportCardinalityClass::FullCover`] uniformly.
    ///
    /// Peer to [`Self::modality_class`] on the modal/antimodal
    /// surface — the histogram now carries two closed-classifier
    /// projections in lockstep: [`Self::modality_class`] over the
    /// modal/antimodal multiplicity surface and
    /// [`Self::support_cardinality_class`] over the support-
    /// cardinality interval.
    #[must_use]
    pub fn support_cardinality_class(&self) -> SupportCardinalityClass {
        let support = self.distinct_cells();
        let cardinality = axis_cardinality::<A>();
        if support == 0 {
            SupportCardinalityClass::Empty
        } else if support == cardinality {
            SupportCardinalityClass::FullCover
        } else if support == 1 {
            SupportCardinalityClass::SingularSupport
        } else if support + 1 == cardinality {
            SupportCardinalityClass::SingularGap
        } else {
            SupportCardinalityClass::StrictPartialCover
        }
    }

    /// The **distance-from-boundary bucket** of the histogram on the
    /// three-cell partition of the [`SupportCardinalityClass`]
    /// surface — the typed three-bucket projection peer of the three
    /// histogram-side leg predicates [`Self::has_boundary`],
    /// [`Self::has_singular`], [`Self::has_strict_partial_cover`].
    ///
    /// Routes through the existing [`Self::support_cardinality_class`]
    /// projection and the class-side
    /// [`SupportCardinalityClass::support_boundary_distance`] variant-
    /// tag projection — the bucket the histogram lands in is exactly
    /// the bucket of its support-cardinality class. Equivalent to
    /// three documented surface forms — each names the same bucket
    /// differently:
    /// - `self.support_cardinality_class().support_boundary_distance()`
    ///   (the chained projection through the existing class surface —
    ///   the definitional form).
    /// - A three-way `match` on
    ///   `(has_boundary(), has_singular(), has_strict_partial_cover())`
    ///   (the histogram-side leg-predicate form: exactly one of the
    ///   three booleans fires on every shape by the strict ternary
    ///   partition law).
    /// - A three-way `match` on the five histogram-side primitives
    ///   `(is_empty(), has_singular_support(), has_strict_partial_cover(),
    ///   has_singular_gap(), is_full_cover())` (the histogram-side
    ///   leaf form — five method calls and the cardinality-2 collapse
    ///   to disambiguate).
    ///
    /// **Bucket-predicate bridge laws** — for every histogram `h` on
    /// every [`ClosedAxis`] implementor:
    /// - `h.support_boundary_distance().is_boundary() == h.has_boundary()`,
    /// - `h.support_boundary_distance().is_singular() == h.has_singular()`,
    /// - `h.support_boundary_distance().is_strict_interior() ==
    ///    h.has_strict_partial_cover()`.
    ///
    /// All three pinned trait-uniformly through
    /// `for_each_closed_axis_implementor!` by the
    /// `axis_histogram_support_boundary_distance_*_agrees_with_*`
    /// tests below — composing the class-side leg-predicate bridges
    /// already pinned by
    /// [`tests::axis_histogram_has_boundary_agrees_with_class_is_boundary_for_every_closed_axis_implementor`],
    /// [`tests::axis_histogram_has_singular_agrees_with_class_is_singular_for_every_closed_axis_implementor`],
    /// and the existing `has_strict_partial_cover` bridge with the
    /// class-side variant-tag projection
    /// [`SupportCardinalityClass::support_boundary_distance`].
    ///
    /// Before this lift, every consumer dispatching on the
    /// distance-from-boundary ternary held an [`AxisHistogram`] value
    /// and either composed the three histogram-side leg predicates
    /// (`if hist.has_boundary() { … } else if hist.has_singular() { … }
    /// else { … }` — three method calls with implicit ordering on a
    /// strict partition), routed through `support_cardinality_class()`
    /// and dispatched on the five-variant class (five-arm `match`,
    /// fused arms per bucket), or open-coded a five-way scan over
    /// `(is_empty, has_singular_support, has_strict_partial_cover,
    /// has_singular_gap, is_full_cover)` with the cardinality-2
    /// collapse to disambiguate. Collapsed to one inherent call
    /// returning a closed three-variant enum whose exhaustiveness
    /// the compiler enforces at every `match` site.
    ///
    /// Peer to [`Self::support_cardinality_class`] on the same
    /// support-cardinality scalar — the histogram now carries two
    /// closed-classifier projections on the support-cardinality
    /// dimension in lockstep: [`Self::support_cardinality_class`]
    /// over the five-corner surface and [`Self::support_boundary_distance`]
    /// over the three-bucket distance-from-boundary surface.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor inherits the
    /// projection at no per-axis cost.
    #[must_use]
    pub fn support_boundary_distance(&self) -> SupportBoundaryDistance {
        self.support_cardinality_class().support_boundary_distance()
    }

    /// The **support-magnitude direction bucket** of the histogram on
    /// the three-cell partition of the [`SupportCardinalityClass`]
    /// surface — the typed three-bucket projection peer of the three
    /// histogram-side leg predicates [`Self::has_low_support`],
    /// [`Self::has_strict_partial_cover`], [`Self::has_high_support`].
    /// The mirror peer of [`Self::support_boundary_distance`] across
    /// the [`SupportCardinalityClass::StrictPartialCover`] middle leg.
    ///
    /// Routes through the existing [`Self::support_cardinality_class`]
    /// projection and the class-side
    /// [`SupportCardinalityClass::support_magnitude_direction`] variant-
    /// tag projection — the bucket the histogram lands in is exactly
    /// the bucket of its support-cardinality class. Equivalent to three
    /// documented surface forms — each names the same bucket
    /// differently:
    /// - `self.support_cardinality_class().support_magnitude_direction()`
    ///   (the chained projection through the existing class surface —
    ///   the definitional form).
    /// - A three-way `match` on
    ///   `(has_low_support(), has_strict_partial_cover(), has_high_support())`
    ///   (the histogram-side leg-predicate form: exactly one of the
    ///   three booleans fires on every shape with
    ///   `axis_cardinality::<A>() >= 2` by the strict ternary partition
    ///   law).
    /// - A five-way `match` on the histogram-side leaf primitives
    ///   `(is_empty(), has_singular_support(), has_strict_partial_cover(),
    ///   has_singular_gap(), is_full_cover())` (the leaf form — five
    ///   method calls with the cardinality-2 collapse to disambiguate).
    ///
    /// **Bucket-predicate bridge laws** — for every histogram `h` on
    /// every [`ClosedAxis`] implementor:
    /// - `h.support_magnitude_direction().is_low() == h.has_low_support()`,
    /// - `h.support_magnitude_direction().is_strict_interior() ==
    ///    h.has_strict_partial_cover()`,
    /// - `h.support_magnitude_direction().is_high() == h.has_high_support()`.
    ///
    /// All three pinned trait-uniformly through
    /// `for_each_closed_axis_implementor!` by the
    /// `axis_histogram_support_magnitude_direction_*_agrees_with_*`
    /// tests below — composing the class-side leg-predicate bridges
    /// already pinned by
    /// [`tests::axis_histogram_has_low_support_agrees_with_class_is_low_support_for_every_closed_axis_implementor`],
    /// [`tests::axis_histogram_has_high_support_agrees_with_class_is_high_support_for_every_closed_axis_implementor`],
    /// and the existing `has_strict_partial_cover` bridge with the
    /// class-side variant-tag projection
    /// [`SupportCardinalityClass::support_magnitude_direction`].
    ///
    /// Peer to [`Self::support_boundary_distance`] on the same support-
    /// cardinality scalar — the histogram now carries three closed-
    /// classifier projections on the support-cardinality dimension in
    /// lockstep: [`Self::support_cardinality_class`] over the five-
    /// corner surface, [`Self::support_boundary_distance`] over the
    /// three-bucket distance-from-boundary surface, and
    /// [`Self::support_magnitude_direction`] over the orthogonal three-
    /// bucket support-magnitude direction surface (both ternaries share
    /// the strict-interior middle leg).
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor inherits the
    /// projection at no per-axis cost.
    #[must_use]
    pub fn support_magnitude_direction(&self) -> SupportMagnitudeDirection {
        self.support_cardinality_class()
            .support_magnitude_direction()
    }

    /// Pointwise sum with `other` — the monoid operation. Every cell
    /// becomes `self.count(v) + other.count(v)`. Commutative,
    /// associative, identity at [`Self::empty`]. The natural shape for
    /// merging histograms across thread boundaries / observation
    /// windows / sub-batches before rendering a fleet-wide summary.
    ///
    /// Implemented in terms of [`std::ops::AddAssign`]: take ownership
    /// of `self`, fold `other` in through `+=`, return the accumulator.
    /// The canonical Rust idiom — `merge` and `AddAssign` are peers,
    /// and lowering `merge` through `+=` keeps the per-cell fold loop
    /// at exactly one site (the [`AddAssign<&Self>`] impl below). The
    /// owned-by-value, returning-`Self` shape stays unchanged for every
    /// existing caller (the [`Sum`] impls' `fold` step routes through
    /// `AxisHistogram::merge` by name; the lift is purely internal).
    #[must_use]
    pub fn merge(mut self, other: &Self) -> Self {
        self += other;
        self
    }

    /// Cellwise maximum of `self` and `other` — the join (∪) on the
    /// pointwise dominance lattice. Every cell becomes
    /// [`std::cmp::max`]`(self.count(v), other.count(v))`. The natural
    /// shape for "envelope across windows" / "worst-case per-cell
    /// observation across the fleet" projections: stack rolling-window
    /// histograms through this lift and the resulting histogram reads
    /// off the high-water mark per cell, not the cellwise sum.
    ///
    /// The lattice peer of [`Self::pointwise_min`] (the meet, ∩) — the
    /// histogram surface carries a bounded distributive lattice
    /// `(AxisHistogram, pointwise_max, pointwise_min)` with bottom
    /// [`Self::empty`] (so `empty.pointwise_max(&hist) == hist` and
    /// `empty.pointwise_min(&hist) == empty`), peer to the lattice
    /// algebra `(meet, join, leq)` pleme-io's compliance dimension
    /// runs on (THEORY.md §III.3). The lattice algebra complements the
    /// additive monoid quartet `(Add, AddAssign, Sub, SubAssign)` on
    /// the same histogram type — addition stacks observations, the
    /// lattice operations take the cellwise envelope.
    ///
    /// Before this lift, every consumer reaching the cellwise-max
    /// projection — a per-window observatory recording the high-water
    /// mark of [`crate::WatchEventClass`] observations across a
    /// rolling-window batch, a fleet aggregator reporting the
    /// worst-case per-host [`crate::ShikumiErrorKind`] cell instead of
    /// the cellwise sum (the latter conflates "one host failed many
    /// times" with "many hosts each failed once"), a per-tier
    /// observatory taking the upper envelope of
    /// [`crate::ConfigSourceKind`] observations across tiers without
    /// summing them — reached the projection through one of two forms:
    /// the open-coded per-cell loop
    /// `for (slot, &c) in hist.counts.iter_mut().zip(other.counts.iter())
    /// { *slot = (*slot).max(c); }` (requires `pub(crate)` access to
    /// the counts vector or a private helper) or the rebuild-from-iter
    /// form
    /// `AxisHistogram::from_iter(axis_iter::<A>().map(|v| (v,
    /// hist.count(v).max(other.count(v)))))` (an
    /// `O(axis_cardinality)` reallocation for what is in-place
    /// arithmetic). Collapsed to one method call with a single-pass
    /// `O(axis_cardinality)` scan over the existing counts vector.
    ///
    /// **Empty-identity law** (`empty` is the bottom): `empty
    /// .pointwise_max(&hist) == hist` and `hist.pointwise_max(&empty)
    /// == hist`. The (empty, max) identity on the lattice join — peer
    /// to the (empty, +) identity on the additive monoid: every cell
    /// of `empty` is zero, so the cellwise max never lowers any cell
    /// of `hist`.
    ///
    /// **Idempotent law**: `hist.pointwise_max(&hist) == hist`. The
    /// canonical lattice law — every cell is its own max with itself.
    /// Peer to the (`Mul × 1`, `MulAssign × 1`) identity on the scalar
    /// action; the lattice surface carries no scalar-action analog (no
    /// non-trivial absorber on the join side except `usize::MAX`,
    /// which sits outside the natural-number histogram algebra).
    ///
    /// **Commutativity law**: `a.pointwise_max(&b) ==
    /// b.pointwise_max(&a)` on the resulting histogram. The canonical
    /// commutative-lattice law — peer to the (`+=`, commutative)
    /// monoid law from [`AddAssign<&Self>`].
    ///
    /// **Absorption law with [`Self::pointwise_min`]**: `a
    /// .pointwise_max(&a.clone().pointwise_min(&b)) == a`. The
    /// canonical distributive-lattice absorption law — the histogram
    /// surface satisfies the lattice axioms uniformly across every
    /// closed axis.
    ///
    /// **Cell-level relation**: every cell `v` of `joined =
    /// a.pointwise_max(&b)` satisfies `joined.count(v) ==
    /// a.count(v).max(b.count(v))`. The defining property of the
    /// cellwise lattice — peer to the cellwise-`+`/cellwise-`∸` laws
    /// on `Add`/`Sub`.
    ///
    /// **Pointwise dominance**: `a.pointwise_max(&b).count(v) >=
    /// a.count(v)` for every cell `v`, and symmetrically `>= b
    /// .count(v)`. The join is the supremum on the pointwise order.
    ///
    /// **Total-growth bound**: `a.pointwise_max(&b).total() >=
    /// std::cmp::max(a.total(), b.total())` and `a.pointwise_max(&b)
    /// .total() <= a.total() + b.total()`. The join total sits between
    /// the per-side maximum and the cellwise sum; pinned by the lattice
    /// identity `pointwise_max + pointwise_min = a + b` on the totals.
    ///
    /// **Lattice / additive identity**: the cellwise expression
    /// `a.clone().pointwise_max(&b) + &a.clone().pointwise_min(&b)` is
    /// pointwise equal to `a + &b`. The canonical max-min/addition
    /// identity `max(x, y) + min(x, y) == x + y` lifted cellwise —
    /// pins the lattice algebra and the additive monoid agree on the
    /// per-cell decomposition.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor inherits the
    /// projection at no per-axis cost. The trait-uniform laws pinned
    /// in [`tests`] hold across the implementor set
    /// (`axis_histogram_pointwise_max_empty_rhs_is_identity_*`,
    /// `axis_histogram_pointwise_max_idempotent_*`,
    /// `axis_histogram_pointwise_max_is_commutative_*`,
    /// `axis_histogram_pointwise_max_cell_level_*`,
    /// `axis_histogram_pointwise_max_dominates_both_sides_*`,
    /// `axis_histogram_pointwise_max_plus_min_equals_add_*`).
    #[must_use]
    pub fn pointwise_max(mut self, other: &Self) -> Self {
        self |= other;
        self
    }

    /// Cellwise minimum of `self` and `other` — the meet (∩) on the
    /// pointwise dominance lattice. Every cell becomes
    /// [`std::cmp::min`]`(self.count(v), other.count(v))`. The natural
    /// shape for "common observation floor across windows" /
    /// "intersection-multiset across hosts" projections: stack
    /// rolling-window histograms through this lift and the resulting
    /// histogram reads off the per-cell floor — the count every window
    /// at least observed — not the cellwise sum.
    ///
    /// The lattice peer of [`Self::pointwise_max`] (the join, ∪) — the
    /// histogram surface carries a bounded distributive lattice
    /// `(AxisHistogram, pointwise_max, pointwise_min)` with bottom
    /// [`Self::empty`], peer to the lattice algebra
    /// `(meet, join, leq)` pleme-io's compliance dimension runs on
    /// (THEORY.md §III.3). The meet is the dual of the join on the
    /// lattice: where `pointwise_max` reports the high-water mark per
    /// cell, `pointwise_min` reports the low-water mark.
    ///
    /// Before this lift, every consumer reaching the cellwise-min
    /// projection — a fleet aggregator reporting the "every host has
    /// at least N of this kind" floor on [`crate::ShikumiErrorKind`]
    /// without conflating "one host failed many times" with "many
    /// hosts each failed once", a per-window observatory taking the
    /// floor across windows so a "consistent observation baseline"
    /// reads off, a multiset-intersection projection asking *"what
    /// observations are common to both histograms?"* — reached the
    /// projection through one of two forms: the open-coded per-cell
    /// loop or the rebuild-from-iter form. Collapsed to one method
    /// call with a single-pass `O(axis_cardinality)` scan over the
    /// existing counts vector.
    ///
    /// **Empty-absorbing law** (`empty` is the bottom): `empty
    /// .pointwise_min(&hist) == empty` and `hist.pointwise_min(&empty)
    /// == empty`. The (empty, min) absorbing law on the lattice meet —
    /// peer to the (empty, ∸) absorbing law on the left-empty side of
    /// the monus monoid: every cell of `empty` is zero, so the
    /// cellwise min collapses every cell to zero.
    ///
    /// **Idempotent law**: `hist.pointwise_min(&hist) == hist`. The
    /// canonical lattice law — every cell is its own min with itself.
    ///
    /// **Commutativity law**: `a.pointwise_min(&b) ==
    /// b.pointwise_min(&a)` on the resulting histogram.
    ///
    /// **Absorption law with [`Self::pointwise_max`]**: `a
    /// .pointwise_min(&a.clone().pointwise_max(&b)) == a`. The
    /// canonical distributive-lattice absorption law.
    ///
    /// **Cell-level relation**: every cell `v` of `met =
    /// a.pointwise_min(&b)` satisfies `met.count(v) ==
    /// a.count(v).min(b.count(v))`.
    ///
    /// **Pointwise dominance**: `a.pointwise_min(&b).count(v) <=
    /// a.count(v)` for every cell `v`, and symmetrically `<= b
    /// .count(v)`. The meet is the infimum on the pointwise order.
    ///
    /// **Total-shrink bound**: `a.pointwise_min(&b).total() <=
    /// std::cmp::min(a.total(), b.total())`. The meet total never
    /// exceeds the per-side minimum — sum of cellwise mins is bounded
    /// above by each side's total.
    ///
    /// **Lattice / additive identity**: `a.clone().pointwise_max(&b) +
    /// &a.clone().pointwise_min(&b) == a.clone() + &b` pointwise.
    /// Pinned together with the [`Self::pointwise_max`] lift through
    /// [`tests::axis_histogram_pointwise_max_plus_min_equals_add_for_every_closed_axis_implementor`].
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor inherits the
    /// projection at no per-axis cost. The trait-uniform laws pinned
    /// in [`tests`] hold across the implementor set
    /// (`axis_histogram_pointwise_min_empty_rhs_is_empty_*`,
    /// `axis_histogram_pointwise_min_idempotent_*`,
    /// `axis_histogram_pointwise_min_is_commutative_*`,
    /// `axis_histogram_pointwise_min_cell_level_*`,
    /// `axis_histogram_pointwise_min_dominated_by_both_sides_*`,
    /// `axis_histogram_pointwise_min_absorbed_by_pointwise_max_*`).
    ///
    /// Lowered through [`BitAndAssign<&Self>`][std::ops::BitAndAssign]:
    /// take ownership of `self`, fold `other` in through `&=`, return
    /// the accumulator. The per-cell `min` loop lives at exactly one
    /// site (the borrowed-RHS-[`BitAndAssign`] impl); this method and
    /// the operator-surface peers ([`BitAnd`], [`BitAnd<&Self>`],
    /// [`BitAndAssign<Self>`]) are pointwise equal by construction.
    #[must_use]
    pub fn pointwise_min(mut self, other: &Self) -> Self {
        self &= other;
        self
    }

    /// Pointwise dominance ≤: `true` when every cell of `self` is
    /// `<=` the corresponding cell of `other`. The partial-order
    /// relation `leq` from THEORY.md §III.3 lifted onto the per-cell
    /// observation count — the underlying order the
    /// [`Self::pointwise_max`] / [`Self::pointwise_min`] lattice
    /// algebra is built on. `a.is_dominated_by(&b)` reads
    /// "`a` is pointwise weaker than `b`" / "every cell of `a` is at
    /// most the corresponding cell of `b`" / "`a` sits below `b` on
    /// the lattice".
    ///
    /// The boolean-projection idiom-peer of the lattice op pair: the
    /// (max, min) lattice operations on the histogram surface project
    /// the cellwise lattice through `Self`, and `is_dominated_by`
    /// projects the underlying partial order through `bool`. Together
    /// `(pointwise_max, pointwise_min, is_dominated_by)` closes the
    /// `(join, meet, leq)` triple from §III.3 on the same histogram
    /// surface.
    ///
    /// Before this lift, every consumer reaching the pointwise-≤
    /// predicate — a fleet aggregator asking *"is every host's per-
    /// kind error tally at most the rolling baseline?"*, a per-window
    /// observatory asking *"did this window's observation profile stay
    /// under the previous high-water mark?"*, a regression detector
    /// asking *"is the post-change histogram dominated by the pre-
    /// change envelope?"* — reached the projection through one of two
    /// forms: the open-coded per-cell loop or the round-trip through
    /// `a.clone().pointwise_max(&b) == b`. Collapsed to one method call
    /// with a single-pass `O(axis_cardinality)` short-circuiting scan
    /// over the existing counts vector.
    ///
    /// **Reflexivity**: `hist.is_dominated_by(&hist)` for every `hist`.
    /// The canonical partial-order reflexivity law — every cell is its
    /// own `<=` with itself.
    ///
    /// **Empty is the bottom**: `empty.is_dominated_by(&hist)` for
    /// every `hist`. Every cell of `empty` is zero, so the cellwise
    /// `<=` reads `true` on every ordinal. Peer to the (empty, max)
    /// identity / (empty, min) absorbing laws on the lattice.
    ///
    /// **Antisymmetry**: `a.is_dominated_by(&b) &&
    /// b.is_dominated_by(&a) ⇒ a == b`. The canonical partial-order
    /// antisymmetry law — pointwise `<=` in both directions collapses
    /// to pointwise equality, which the `Eq` derive picks up cell by
    /// cell.
    ///
    /// **Transitivity**: `a.is_dominated_by(&b) &&
    /// b.is_dominated_by(&c) ⇒ a.is_dominated_by(&c)`. The canonical
    /// partial-order transitivity law lifted from the cellwise `<=`.
    ///
    /// **Dual relation**: `a.is_dominated_by(&b) ==
    /// b.dominates(&a)`. The two predicates are perfect duals — peer
    /// to the (max, min) lattice-op duality.
    ///
    /// **Join characterization**: `a.is_dominated_by(&b) ==
    /// (a.clone().pointwise_max(&b) == b)`. The canonical "≤ iff
    /// `a ∨ b = b`" lattice law — pins the partial order is the one
    /// the join is built on.
    ///
    /// **Meet characterization**: `a.is_dominated_by(&b) ==
    /// (a.clone().pointwise_min(&b) == a)`. The canonical "≤ iff
    /// `a ∧ b = a`" lattice law — the dual of the join
    /// characterization on the meet side.
    ///
    /// **Total bound implication**: `a.is_dominated_by(&b) ⇒ a.total()
    /// <= b.total()`. Pointwise `<=` implies the cellwise sum is
    /// bounded above. The converse is *not* an iff — equal totals can
    /// occur on lattice-incomparable histograms (e.g., on a 2-cell
    /// axis, `(2, 0)` and `(0, 2)` both have total 2 but neither
    /// dominates the other).
    ///
    /// **Partiality**: the order is *partial*, not total — two
    /// histograms can be incomparable (`!a.is_dominated_by(&b) &&
    /// !b.is_dominated_by(&a)`) when one cell is strictly larger on
    /// each side. This matches §III.3's `leq` partial order on the
    /// compliance lattice (two baselines can be incomparable when each
    /// requires controls the other doesn't).
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor inherits the
    /// projection at no per-axis cost. The trait-uniform laws pinned
    /// in [`tests`] hold across the implementor set
    /// (`axis_histogram_is_dominated_by_reflexive_*`,
    /// `axis_histogram_empty_is_dominated_by_every_*`,
    /// `axis_histogram_is_dominated_by_antisymmetric_*`,
    /// `axis_histogram_is_dominated_by_transitive_*`,
    /// `axis_histogram_dominates_is_dual_of_is_dominated_by_*`,
    /// `axis_histogram_is_dominated_by_join_characterization_*`,
    /// `axis_histogram_is_dominated_by_meet_characterization_*`,
    /// `axis_histogram_is_dominated_by_total_bound_*`).
    #[must_use]
    pub fn is_dominated_by(&self, other: &Self) -> bool {
        self.counts
            .iter()
            .zip(other.counts.iter())
            .all(|(lhs, rhs)| lhs <= rhs)
    }

    /// Pointwise dominance ≥: `true` when every cell of `self` is
    /// `>=` the corresponding cell of `other`. The dual of
    /// [`Self::is_dominated_by`] — perfect peer on the partial-order
    /// surface. `a.dominates(&b)` reads "`a` is pointwise stronger
    /// than `b`" / "every cell of `a` is at least the corresponding
    /// cell of `b`" / "`a` sits above `b` on the lattice".
    ///
    /// Holds pointwise equal to `b.is_dominated_by(&a)`; pinned by
    /// the trait-uniform dual-relation law
    /// (`axis_histogram_dominates_is_dual_of_is_dominated_by_*`).
    ///
    /// **Reflexivity**: `hist.dominates(&hist)` for every `hist`.
    ///
    /// **Empty is the bottom (dual)**: `hist.dominates(&empty)` for
    /// every `hist`. Every cell of `empty` is zero, so the cellwise
    /// `>=` reads `true` on every ordinal — the dual peer of
    /// [`Self::is_dominated_by`]'s "empty is the bottom" law.
    ///
    /// **Join characterization (dual)**: `a.dominates(&b) ==
    /// (a.clone().pointwise_max(&b) == a)`.
    ///
    /// **Meet characterization (dual)**: `a.dominates(&b) ==
    /// (a.clone().pointwise_min(&b) == b)`.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor inherits the
    /// projection at no per-axis cost. Pinned together with
    /// [`Self::is_dominated_by`] through the trait-uniform laws in
    /// [`tests`].
    #[must_use]
    pub fn dominates(&self, other: &Self) -> bool {
        self.counts
            .iter()
            .zip(other.counts.iter())
            .all(|(lhs, rhs)| lhs >= rhs)
    }

    /// Strict pointwise dominance `<`: `true` when every cell of `self`
    /// is `<=` the corresponding cell of `other` *and* at least one
    /// cell is strictly `<`. The canonical strict-partial-order lift of
    /// [`Self::is_dominated_by`] — peer to `<` next to `<=` on
    /// [`std::cmp::PartialOrd`]. `a.is_strictly_dominated_by(&b)` reads
    /// "`a` is pointwise weaker than `b` *and* they differ on at least
    /// one cell" / "`a` sits strictly below `b` on the lattice" /
    /// "every cell of `a` is `<=` and the relation is somewhere
    /// strict".
    ///
    /// Closes the partial-order operator quartet `(≤, ≥, <, >)` at the
    /// boolean surface — [`Self::is_dominated_by`] / [`Self::dominates`]
    /// carry the non-strict pair, and `is_strictly_dominated_by` /
    /// [`Self::strictly_dominates`] carry the strict pair. Single-pass
    /// `O(axis_cardinality)` short-circuiting scan: returns `false` on
    /// the first cell where `self > other`, tracks whether any cell was
    /// strictly less, and reads off `any_strict` at end.
    ///
    /// Before this lift, every consumer reaching the strict-dominance
    /// predicate — a regression detector asking *"is the post-change
    /// histogram strictly under the pre-change envelope (≤ everywhere
    /// AND strictly < somewhere)?"*, a per-window observatory asking
    /// *"did this window strictly improve on the rolling baseline?"*, a
    /// fleet aggregator asking *"is every host's per-kind error tally
    /// strictly under the rolling baseline (every cell ≤, at least one
    /// strictly lower)?"* — reached the projection through the
    /// composite form `a.is_dominated_by(&b) && a != b` (which walks the
    /// counts vector twice — once for the dominance scan, once for the
    /// equality scan). Collapsed to one method call with a single-pass
    /// scan.
    ///
    /// **Irreflexivity**: `!hist.is_strictly_dominated_by(&hist)` for
    /// every `hist`. The canonical strict-partial-order irreflexivity
    /// law — every cell is its own `==` with itself, so no cell is
    /// strictly less. The boundary law that distinguishes a strict
    /// partial order from the reflexive `≤`.
    ///
    /// **Empty is the strict bottom**:
    /// `empty.is_strictly_dominated_by(&hist)` for every non-empty
    /// `hist`. Empty is `≤` every histogram (the [`Self::is_dominated_by`]
    /// law) and not equal to any non-empty histogram, so the strict
    /// version reads `true` on every non-empty target. On the empty
    /// target it reads `false` (`empty` is not strictly less than
    /// itself).
    ///
    /// **Asymmetry**: `a.is_strictly_dominated_by(&b) ⇒
    /// !b.is_strictly_dominated_by(&a)`. The canonical strict-partial-
    /// order asymmetry law — `a < b` and `b < a` cannot both hold.
    /// Stronger than the antisymmetry law on the non-strict surface
    /// (which allows the reflexive case).
    ///
    /// **Transitivity**: `a.is_strictly_dominated_by(&b) &&
    /// b.is_strictly_dominated_by(&c) ⇒ a.is_strictly_dominated_by(&c)`.
    /// The canonical strict-partial-order transitivity law lifted from
    /// the cellwise `<`.
    ///
    /// **Dual relation**: `a.strictly_dominates(&b) ==
    /// b.is_strictly_dominated_by(&a)`. The two predicates are perfect
    /// duals — peer to the `is_dominated_by` / `dominates` duality on
    /// the non-strict surface.
    ///
    /// **Decomposition** (`<=` plus inequality): `a
    /// .is_strictly_dominated_by(&b) == (a.is_dominated_by(&b) && a !=
    /// b)`. The canonical strict / non-strict bridge — `<` is `≤` with
    /// the equal-case excluded. Pins the strict predicate is the one
    /// the non-strict predicate is built on.
    ///
    /// **Strict total bound implication**:
    /// `a.is_strictly_dominated_by(&b) ⇒ a.total() < b.total()`. Strict
    /// pointwise `<` is strict-sum-monotone — every cell is `≤` and at
    /// least one is strictly `<`, so the per-cell `<` on the strict
    /// cell contributes a strict inequality to the cellwise sum.
    /// Stronger than the non-strict total bound on
    /// [`Self::is_dominated_by`] (which only carries `≤` on the totals).
    ///
    /// **Partiality**: the strict order is *partial*, not total — two
    /// histograms can be strictly-incomparable (`!a
    /// .is_strictly_dominated_by(&b) && !b.is_strictly_dominated_by(&a)
    /// && a != b`) when one cell is strictly larger on each side. The
    /// (2, 1, 0) / (1, 2, 0) [`DiffLineKind`] witnesses on the non-
    /// strict surface remain incomparable on the strict surface too.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor inherits the
    /// projection at no per-axis cost. The trait-uniform laws pinned in
    /// [`tests`] hold across the implementor set
    /// (`axis_histogram_is_strictly_dominated_by_irreflexive_*`,
    /// `axis_histogram_empty_is_strictly_dominated_by_nonempty_*`,
    /// `axis_histogram_is_strictly_dominated_by_asymmetric_*`,
    /// `axis_histogram_is_strictly_dominated_by_transitive_*`,
    /// `axis_histogram_strictly_dominates_is_dual_of_is_strictly_dominated_by_*`,
    /// `axis_histogram_is_strictly_dominated_by_decomposition_*`,
    /// `axis_histogram_is_strictly_dominated_by_strict_total_bound_*`).
    #[must_use]
    pub fn is_strictly_dominated_by(&self, other: &Self) -> bool {
        let mut any_strict = false;
        for (lhs, rhs) in self.counts.iter().zip(other.counts.iter()) {
            if lhs > rhs {
                return false;
            }
            if lhs < rhs {
                any_strict = true;
            }
        }
        any_strict
    }

    /// Strict pointwise dominance `>`: `true` when every cell of `self`
    /// is `>=` the corresponding cell of `other` *and* at least one
    /// cell is strictly `>`. The dual of [`Self::is_strictly_dominated_by`]
    /// — perfect peer on the strict-partial-order surface.
    /// `a.strictly_dominates(&b)` reads "`a` is pointwise stronger than
    /// `b` *and* they differ on at least one cell" / "`a` sits strictly
    /// above `b` on the lattice".
    ///
    /// Holds pointwise equal to `b.is_strictly_dominated_by(&a)`; pinned
    /// by the trait-uniform dual-relation law
    /// (`axis_histogram_strictly_dominates_is_dual_of_is_strictly_dominated_by_*`).
    ///
    /// **Irreflexivity**: `!hist.strictly_dominates(&hist)` for every
    /// `hist`.
    ///
    /// **Empty is the strict bottom (dual)**:
    /// `hist.strictly_dominates(&empty)` for every non-empty `hist` and
    /// `!empty.strictly_dominates(&empty)`.
    ///
    /// **Decomposition** (dual): `a.strictly_dominates(&b) ==
    /// (a.dominates(&b) && a != b)`.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor inherits the
    /// projection at no per-axis cost. Pinned together with
    /// [`Self::is_strictly_dominated_by`] through the trait-uniform laws
    /// in [`tests`].
    #[must_use]
    pub fn strictly_dominates(&self, other: &Self) -> bool {
        let mut any_strict = false;
        for (lhs, rhs) in self.counts.iter().zip(other.counts.iter()) {
            if lhs < rhs {
                return false;
            }
            if lhs > rhs {
                any_strict = true;
            }
        }
        any_strict
    }

    /// Multiset disjointness: `true` when no cell has a positive count
    /// in both `self` and `other` — the canonical set-theoretic
    /// disjointness predicate lifted onto the histogram surface. The
    /// boolean-projection idiom-peer of [`Self::pointwise_min`] at its
    /// bottom: `a.is_disjoint_from(&b)` reads "the supports of `a` and
    /// `b` share no cell" / "the lattice meet `a ∧ b` collapses to
    /// [`Self::empty`]" / "no observation appears in both histograms".
    ///
    /// The canonical Rust stdlib idiom-peer of
    /// [`std::collections::HashSet::is_disjoint`] /
    /// [`std::collections::BTreeSet::is_disjoint`] on the
    /// support-set projection. Together with [`Self::intersects`] the
    /// histogram surface now carries the set-theoretic
    /// (disjoint, meets) predicate pair next to the partial-order
    /// (≤, ≥, <, >) quartet and the lattice (∧, ∨) pair — every
    /// canonical relational projection on the same histogram type.
    ///
    /// Before this lift, every consumer reaching the disjointness
    /// projection — a fleet aggregator asking *"do these two windows'
    /// per-kind error tallies share any failure cell?"*, a per-channel
    /// observatory asking *"are the supports of these two rolling
    /// histograms structurally disjoint (one window had only failures
    /// of one class, the other had only failures of a different
    /// class)?"*, a multiset-intersection guard asking *"is the
    /// [`Self::pointwise_min`] meet of these two empty?"* — reached
    /// the projection through one of two forms: the open-coded per-cell
    /// loop or the rebuild-through-meet form
    /// `a.clone().pointwise_min(&b).is_empty()` (allocates a fresh
    /// counts vector through [`Clone`], walks it through
    /// [`Self::pointwise_min`], then walks it again through
    /// [`Self::is_empty`]). Collapsed to one method call with a
    /// single-pass `O(axis_cardinality)` short-circuiting scan that
    /// returns `false` on the first cell where both sides have nonzero
    /// count — no allocation.
    ///
    /// **Symmetry**: `a.is_disjoint_from(&b) == b.is_disjoint_from(&a)`.
    /// Disjointness is a symmetric relation — the cellwise predicate
    /// `lhs == 0 || rhs == 0` is symmetric in its two arguments. Peer
    /// to the symmetry of [`std::collections::HashSet::is_disjoint`].
    ///
    /// **Empty is disjoint from everything**:
    /// `empty.is_disjoint_from(&hist) == true` for every `hist`. Every
    /// cell of `empty` is zero, so the cellwise `lhs == 0 || rhs == 0`
    /// reads `true` on every ordinal — vacuously satisfied. By
    /// symmetry, `hist.is_disjoint_from(&empty) == true` too. Peer to
    /// the empty-bottom laws on the lattice ((empty, max) identity /
    /// (empty, min) absorbing) and to the empty-bottom law on the
    /// partial order (empty is dominated by every histogram).
    ///
    /// **Self-disjoint iff empty**: `hist.is_disjoint_from(&hist) ==
    /// hist.is_empty()`. Disjointness with itself reduces to
    /// emptiness — a non-empty histogram has at least one cell with a
    /// positive count, and that cell witnesses non-disjointness on the
    /// reflexive pair. The boundary law that pins the disjointness
    /// predicate at the self-pair, and the unique self-disjoint
    /// histogram is the empty one.
    ///
    /// **Dual relation with [`Self::intersects`]**: `a.intersects(&b)
    /// == !a.is_disjoint_from(&b)`. The two predicates are perfect
    /// boolean duals — peer to the (is_disjoint, !is_disjoint) duality
    /// on stdlib sets.
    ///
    /// **Meet characterization** (the lattice-bridge law):
    /// `a.is_disjoint_from(&b) == a.clone().pointwise_min(&b)
    /// .is_empty()`. The canonical "disjoint iff `a ∧ b = ⊥`" lattice
    /// law on the histogram surface — pins the disjointness predicate
    /// is the one the lattice meet's bottom projection is built on.
    /// Peer to the join / meet characterizations of [`Self::is_dominated_by`].
    ///
    /// **Join-equals-add on disjoint pairs**: `a.is_disjoint_from(&b)
    /// ⇒ a.clone().pointwise_max(&b) == &a + &b`. On disjoint pairs
    /// the lattice join collapses to the additive sum — where one side
    /// is zero the other contributes everything, so the cellwise max
    /// equals the cellwise sum on every cell. Peer to the
    /// (max + min == add) law on the lattice; on disjoint pairs `min`
    /// reads `empty` so the law specializes to `max == add`.
    ///
    /// **Dominance preservation**: `a.is_disjoint_from(&b) && c
    /// .is_dominated_by(&a) ⇒ c.is_disjoint_from(&b)`. Disjointness is
    /// closed under sub-histograms: any histogram pointwise `≤` a
    /// histogram disjoint from `b` is itself disjoint from `b`. Peer
    /// to the subset-monotonicity of disjointness on stdlib sets.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor inherits the
    /// projection at no per-axis cost. The trait-uniform laws pinned
    /// in [`tests`] hold across the implementor set
    /// (`axis_histogram_is_disjoint_from_symmetric_*`,
    /// `axis_histogram_empty_is_disjoint_from_every_*`,
    /// `axis_histogram_self_disjoint_iff_empty_*`,
    /// `axis_histogram_intersects_is_dual_of_is_disjoint_from_*`,
    /// `axis_histogram_is_disjoint_from_meet_characterization_*`,
    /// `axis_histogram_is_disjoint_from_dominance_preservation_*`).
    #[must_use]
    pub fn is_disjoint_from(&self, other: &Self) -> bool {
        self.counts
            .iter()
            .zip(other.counts.iter())
            .all(|(&lhs, &rhs)| lhs == 0 || rhs == 0)
    }

    /// Multiset overlap: `true` when at least one cell has a positive
    /// count in both `self` and `other` — the boolean dual of
    /// [`Self::is_disjoint_from`] on the same lattice-meet projection.
    /// `a.intersects(&b)` reads "the supports of `a` and `b` share at
    /// least one cell" / "the lattice meet `a ∧ b` is non-empty" /
    /// "some observation appears in both histograms". Perfect peer to
    /// [`Self::is_disjoint_from`] on the support-set projection — by
    /// construction `a.intersects(&b) == !a.is_disjoint_from(&b)`,
    /// pinned by the dual-relation law
    /// (`axis_histogram_intersects_is_dual_of_is_disjoint_from_*`).
    ///
    /// Single-pass `O(axis_cardinality)` short-circuiting scan:
    /// returns `true` on the first cell where both sides have nonzero
    /// count. No allocation.
    ///
    /// **Empty intersects nothing**: `empty.intersects(&hist) == false`
    /// for every `hist`. Every cell of `empty` is zero, so no cell
    /// can witness mutual positivity — vacuously refuted. By
    /// symmetry, `hist.intersects(&empty) == false` too.
    ///
    /// **Self-intersects iff non-empty**: `hist.intersects(&hist) ==
    /// !hist.is_empty()`. The dual of [`Self::is_disjoint_from`]'s
    /// self-disjoint-iff-empty law.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor inherits the
    /// projection at no per-axis cost. Pinned together with
    /// [`Self::is_disjoint_from`] through the trait-uniform laws in
    /// [`tests`].
    #[must_use]
    pub fn intersects(&self, other: &Self) -> bool {
        self.counts
            .iter()
            .zip(other.counts.iter())
            .any(|(&lhs, &rhs)| lhs > 0 && rhs > 0)
    }

    /// Cellwise absolute difference of `self` and `other` — the
    /// symmetric-difference (△) on the histogram surface. Every cell
    /// becomes `|self.count(v) - other.count(v)|`, the unsigned
    /// magnitude of the per-cell gap between the two histograms. The
    /// canonical Rust idiom-peer of
    /// [`std::collections::HashSet::symmetric_difference`] /
    /// [`std::collections::BTreeSet::symmetric_difference`] lifted
    /// onto the multiset surface, complementary to
    /// [`Self::pointwise_max`] (the join, ∪),
    /// [`Self::pointwise_min`] (the meet, ∩), and
    /// [`std::ops::Sub`] (the saturating difference, ∖) on the same
    /// histogram. The four together close the canonical set-theoretic
    /// operator quartet `(∪, ∩, ∖, △)` at the histogram surface.
    ///
    /// Before this lift, every consumer reaching the cellwise-absolute-
    /// difference projection — a fleet aggregator asking *"what is the
    /// per-`ShikumiErrorKind` gap between today's window and yesterday's
    /// window?"* on `AxisHistogram<crate::ShikumiErrorKind>`, a per-
    /// channel observatory computing the L1 / Manhattan distance
    /// between two rolling histograms (`a.symmetric_difference(&b)
    /// .total()` is the canonical L1 metric on multisets), a
    /// regression detector reporting the per-cell delta between a
    /// pre-change envelope and a post-change envelope without
    /// distinguishing the direction of change — reached the
    /// projection through one of three forms: the open-coded per-cell
    /// loop with the absolute-difference branch, the lattice-bridge
    /// form `a.clone().pointwise_max(&b) - a.clone().pointwise_min(&b)`
    /// (allocates two intermediate histograms, walks the counts vector
    /// three times — twice to write the join and meet, once to fold
    /// the meet back through saturating subtraction), or the sum-of-
    /// directed-differences form
    /// `(a.clone() - &b) + &(b.clone() - &a)` (allocates two
    /// intermediate histograms, exploits the disjoint-supports
    /// identity that `(a - b)` and `(b - a)` are always disjoint, so
    /// their join equals their sum on every input). Collapsed to one
    /// method call with a single-pass `O(axis_cardinality)` scan over
    /// the existing counts vector that writes `|slot - delta|` in
    /// place — no allocation.
    ///
    /// **Symmetry**: `a.symmetric_difference(&b)` is pointwise equal
    /// to `b.symmetric_difference(&a)`. The cellwise absolute-
    /// difference `|lhs - rhs|` is symmetric in its two arguments —
    /// the perfect peer of the symmetry of
    /// [`std::collections::HashSet::symmetric_difference`].
    ///
    /// **Self-cancellation**: `hist.clone().symmetric_difference(&hist)
    /// == AxisHistogram::empty()`. Every cell of the reflexive pair
    /// has `|c - c| == 0`, so the symmetric difference collapses to
    /// the bottom of the lattice on every reflexive input. The
    /// canonical boundary law on the symmetric-difference monoid:
    /// every histogram is its own inverse under `△`, which is
    /// exactly the structure that makes `(AxisHistogram, △, empty)`
    /// a commutative group of exponent 2 on the support-set
    /// projection (and a commutative monoid on the multiset
    /// magnitude).
    ///
    /// **Empty is the identity**: `hist.clone().symmetric_difference
    /// (&AxisHistogram::empty()) == hist` and `AxisHistogram::empty()
    /// .symmetric_difference(&hist) == hist`. Every cell of `empty`
    /// is zero, so `|c - 0| == c` and `|0 - c| == c` reduce to the
    /// original count — the empty histogram is the two-sided identity
    /// of the symmetric-difference monoid, exactly as
    /// `HashSet::new()` is the two-sided identity of stdlib set
    /// symmetric difference.
    ///
    /// **Lattice-bridge identity**: `a.clone().symmetric_difference
    /// (&b) == a.clone().pointwise_max(&b) - &a.clone()
    /// .pointwise_min(&b)`. The canonical "△ = ∪ ∖ ∩" identity on
    /// every cell: `|lhs - rhs| == max(lhs, rhs) - min(lhs, rhs)`.
    /// Pins the symmetric difference is the gap between the join and
    /// the meet of the same pair on every cell.
    ///
    /// **Add-bridge identity**: `a.clone().symmetric_difference(&b) +
    /// &(a.clone().pointwise_min(&b) * 2) == &a + &b`. The
    /// `(max - min) + 2 * min == max + min` identity, with `max + min
    /// == a + b` (the join-plus-meet equals add law on the lattice)
    /// — pins the symmetric difference is the additive complement of
    /// twice the meet against the additive sum.
    ///
    /// **Disjoint-pair specialization**: `a.is_disjoint_from(&b) ⇒
    /// a.clone().symmetric_difference(&b) == &a + &b`. On disjoint
    /// pairs the meet collapses to empty, so the lattice-bridge
    /// identity reduces to `△ == ∪ - 0 == ∪`, and the
    /// join-equals-add law on disjoint pairs further reduces this to
    /// `△ == +`. The canonical specialization of the symmetric-
    /// difference monoid to the partition-of-supports case.
    ///
    /// **Dominance specialization**: `a.is_dominated_by(&b) ⇒
    /// a.clone().symmetric_difference(&b) == b.clone() - &a` (and by
    /// symmetry, also `== b.clone().symmetric_difference(&a)`). When
    /// every cell of `a` is `<=` the corresponding cell of `b`, the
    /// cellwise absolute difference reduces to the directed (saturating)
    /// difference `b - a` on every cell. The canonical specialization
    /// of the symmetric-difference operator to the comparable-pair
    /// case on the partial-order surface.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor inherits the
    /// projection at no per-axis cost. The trait-uniform laws pinned
    /// in [`tests`] hold across the implementor set
    /// (`axis_histogram_symmetric_difference_is_symmetric_*`,
    /// `axis_histogram_symmetric_difference_self_cancels_to_empty_*`,
    /// `axis_histogram_symmetric_difference_empty_is_identity_*`,
    /// `axis_histogram_symmetric_difference_lattice_bridge_*`,
    /// `axis_histogram_symmetric_difference_add_bridge_*`,
    /// `axis_histogram_symmetric_difference_disjoint_equals_add_*`,
    /// `axis_histogram_symmetric_difference_dominance_specializes_to_sub_*`).
    #[must_use]
    pub fn symmetric_difference(mut self, other: &Self) -> Self {
        self ^= other;
        self
    }
}

impl<A: ClosedAxis> FromIterator<A> for AxisHistogram<A> {
    /// Build a histogram by recording every observation in `iter`. The
    /// canonical entry point — every consumer that wants a per-cell
    /// tally from a stream of axis values pipes the stream through
    /// [`Iterator::collect`] into [`AxisHistogram`]. Equivalent to
    /// [`axis_histogram`] applied to the same iterator.
    ///
    /// Implemented in terms of [`Extend::extend`]: build the identity
    /// (the all-zero histogram via [`Self::empty`]), then fold every
    /// observation in `iter` into it through the [`Extend`] surface.
    /// The canonical Rust idiom — `FromIterator` and `Extend` are peers,
    /// and `from_iter` lowers to `default + extend` so the per-observation
    /// loop lives at one site (the [`Extend`] impl below) and both
    /// surfaces stay in lockstep without duplication.
    fn from_iter<I: IntoIterator<Item = A>>(iter: I) -> Self {
        let mut hist = Self::empty();
        hist.extend(iter);
        hist
    }
}

impl<A: ClosedAxis> Extend<A> for AxisHistogram<A> {
    /// Fold every observation in `iter` into the histogram in place —
    /// the canonical Rust idiom peer of [`FromIterator`] on the
    /// already-allocated histogram surface.
    ///
    /// Before this lift, every consumer with a pre-existing histogram
    /// (an observatory accumulator carrying observations across a
    /// rolling window, a fleet-wide aggregator folding sub-batches as
    /// they arrive, a dashboard buffering observations until a render
    /// tick fires, a streaming attestation chain extending the
    /// `AxisHistogram<crate::ShikumiErrorKind>` cell with the next
    /// reload window's failures) reached the (extend-with-iterator)
    /// projection through one of three forms — the open-coded
    /// `for v in iter { hist.observe(v); }` per-observation loop, the
    /// `iter.into_iter().for_each(|v| hist.observe(v));` callback form
    /// (same loop, different call-site shape), or the build-and-merge
    /// `let other: AxisHistogram<A> = iter.collect(); hist =
    /// hist.merge(&other);` form (which allocates an intermediate
    /// histogram and walks the counts vector twice — once to write the
    /// intermediate, once to fold it back) — collapsed to one trait-
    /// method call with a single-pass scan that bumps every observed
    /// cell directly on the existing counts vector. The lift names the
    /// (existing-histogram, iterable observations → in-place fold)
    /// projection at one site.
    ///
    /// **Empty-identity law** — `hist.extend(std::iter::empty())` leaves
    /// the histogram unchanged. The vacuous fold on the [`Extend`]
    /// monoid surface, peer to the [`Self::merge`] empty-identity law
    /// (`hist.merge(&AxisHistogram::empty()) == hist`).
    ///
    /// **Equivalence with [`Self::merge`] on the empty starting point**
    /// — for every iterator `iter` and every histogram `hist`:
    /// `let mut a = hist.clone(); a.extend(iter.clone()); a` is pointwise
    /// equal to `hist.clone().merge(&iter.collect::<AxisHistogram<A>>())`.
    /// The (extend, merge) duality on the monoid: extending in place is
    /// the in-place form of merging with the collected histogram, and
    /// starting from the empty histogram makes the equivalence read
    /// `extend = FromIterator` pointwise — the canonical lowering the
    /// [`FromIterator`] impl uses internally.
    ///
    /// **Equivalence with the [`Self::observe`] loop** — pointwise
    /// equal to `for v in iter { hist.observe(v); }` on every iterator,
    /// by definition. The trait method names the loop at one site so
    /// consumers no longer re-derive it inline.
    ///
    /// **Cell-level accounting** — every cell observed in `iter` has
    /// its count incremented by the number of times `iter` yielded
    /// that cell; every other cell is left unchanged. The total grows
    /// by exactly the input iterator's length:
    /// `before.total() + iter.into_iter().count() == after.total()`,
    /// peer to the [`Self::total`] / [`Self::merge`] additivity law.
    ///
    /// **Concatenation associativity** — extending with `iter_a` then
    /// `iter_b` produces the same histogram as extending with
    /// `iter_a.chain(iter_b)`. The (extend, ⊕) homomorphism over
    /// iterator concatenation.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor inherits the
    /// projection at no per-axis cost. The trait-uniform laws pinned in
    /// [`tests`] hold across the implementor set
    /// (`axis_histogram_extend_empty_input_is_identity_*`,
    /// `axis_histogram_extend_starting_empty_equals_from_iter_*`,
    /// `axis_histogram_extend_grows_total_by_input_length_*`,
    /// `axis_histogram_extend_chained_equals_two_step_extend_*`).
    fn extend<I: IntoIterator<Item = A>>(&mut self, iter: I) {
        for value in iter {
            self.observe(value);
        }
    }
}

impl<A: ClosedAxis> From<A> for AxisHistogram<A> {
    /// Lift one axis cell into the singleton histogram that observes
    /// it exactly once — the canonical Rust idiom-peer of stdlib's
    /// blanket scalar-into-collection conversions
    /// (`impl From<T> for Vec<T>` semantically, the singleton
    /// `BinaryHeap::from`/`HashSet::from` shapes). The 0-arg analog of
    /// [`Self::empty`] on the (cell → histogram) constructor surface.
    ///
    /// Before this lift, every consumer building a one-observation
    /// histogram (a test fixture pinning the singleton-dominant-cell
    /// law on a specific cell, an attestation manifest recording
    /// "this window saw exactly this one cell", a sliding-window
    /// observatory seeding the next window with the first observation
    /// in isolation, a CLI `config-diff` initializing the running
    /// tally with the first diff line as it walks the stream) wrote
    /// `std::iter::once(value).collect::<AxisHistogram<A>>()` or
    /// `let mut h = AxisHistogram::empty(); h.observe(value); h` —
    /// two distinct re-derivations of the singleton constructor that
    /// drift apart when one site or the other gains a structural
    /// invariant the other lacks. The lift names the (cell → singleton
    /// histogram) projection at one site so `value.into()` and
    /// `AxisHistogram::from(value)` are both available on the natural
    /// stdlib idiom surface.
    ///
    /// **Singleton law** — `AxisHistogram::from(value)` is pointwise
    /// equal to `std::iter::once(value).collect::<AxisHistogram<A>>()`:
    /// `count(value, hist) == 1`, every other cell at 0, `total() == 1`,
    /// [`Self::is_empty`] = `false`, [`Self::dominant_cell`] =
    /// `Some(value)`. Peer to the trait-uniform
    /// `assert_singleton_histogram_pins_observed_cell` and
    /// `assert_dominant_cell_singleton_picks_observed_cell` laws in
    /// [`tests`] — the singleton constructor those laws walk uniformly
    /// is now nameable as `From::from` rather than as the open-coded
    /// `iter::once(_).collect()` lowering.
    ///
    /// **Cell-coverage symmetry** — for every cell `c` of the axis,
    /// `AxisHistogram::from(c)` produces a histogram with exactly that
    /// cell observed once; iterating over `axis_iter::<A>().map(From::from)`
    /// produces the dense sequence of every per-cell singleton
    /// histogram on the axis in declaration order — the natural
    /// generator the trait-uniform singleton laws walk underneath.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor inherits the
    /// constructor at no per-axis cost. Pinned across the implementor
    /// set by the trait-uniform
    /// `axis_histogram_from_cell_equals_iter_once_collect_*` law in
    /// [`tests`].
    fn from(value: A) -> Self {
        let mut hist = Self::empty();
        hist.observe(value);
        hist
    }
}

impl<A: ClosedAxis, const N: usize> From<[A; N]> for AxisHistogram<A> {
    /// Build a histogram from a fixed-size array of axis cells — the
    /// canonical Rust stdlib array-as-collection constructor idiom-peer
    /// of [`Vec::from`][Vec], [`std::collections::HashSet::from`],
    /// [`std::collections::BTreeSet::from`],
    /// [`std::collections::VecDeque::from`], and
    /// [`std::collections::BinaryHeap::from`] on the `[T; N]` input
    /// surface. The const-generic-N partner of the
    /// [`FromIterator<A>`] entry surface, hoisted to the stdlib
    /// array-literal call site so `AxisHistogram::from([Added, Removed,
    /// Added])` reads at the same idiom rung as `Vec::from([1, 2, 3])`
    /// and `HashSet::from([Added, Removed])`.
    ///
    /// Before this lift, every consumer reaching the
    /// (array-literal → histogram) projection (a test fixture pinning
    /// a small handful of observations as the trial input for a
    /// downstream invariant, an attestation manifest hard-coding the
    /// expected post-reload `AxisHistogram<crate::WatchEventClass>`
    /// cell for a known-good baseline, a CLI golden-output check
    /// hard-coding the diff-line cell mix for a regression-pinned
    /// fixture, a documentation example reaching for the smallest
    /// readable lift from a literal observation list to a histogram)
    /// reached one of three open-coded forms — the
    /// `[Added, Removed, Added].into_iter().collect::<AxisHistogram<_>>()`
    /// post-collect form (which forces an explicit turbofish at every
    /// site because the call-site shape doesn't constrain the
    /// collected type), the
    /// `[Added, Removed, Added].iter().copied().collect()` borrowed-
    /// then-copied lowering (which adds a `.copied()` step purely to
    /// route through the borrowed-input [`FromIterator<&A>`] surface),
    /// or the longhand `{ let mut h = AxisHistogram::empty();
    /// h.observe(Added); h.observe(Removed); h.observe(Added); h }`
    /// per-cell observation expansion — three distinct re-derivations
    /// of the array-input constructor that drift apart when one site or
    /// the other gains a structural invariant the other lacks.
    /// Collapsed to one trait-method call routed through the existing
    /// [`FromIterator<A>`] impl, so the per-cell `observe` loop lives
    /// at exactly one site (the [`Extend<A>`] impl above) underneath
    /// every array-input constructor surface.
    ///
    /// **Equivalence with [`FromIterator<A>`]** — for every fixed-size
    /// array `arr: [A; N]`: `AxisHistogram::from(arr)` is pointwise
    /// equal to `arr.into_iter().collect::<AxisHistogram<A>>()`. The
    /// array-input constructor / iterator-input constructor duality on
    /// the (raw-observation) entry surface — the array-literal call
    /// site lowers to the same per-cell observation fold the
    /// [`FromIterator<A>`] impl drives, so the two constructors
    /// cannot drift apart by construction.
    ///
    /// **Empty-array identity law** — `AxisHistogram::from([])` is
    /// pointwise equal to [`AxisHistogram::empty`]. The vacuous fold on
    /// the array-input constructor surface, peer to the
    /// [`Extend<A>`] empty-identity law and to the
    /// [`FromIterator<A>`] empty-input identity. The zero-length
    /// array literal lowers to the monoid identity at the constructor
    /// rung.
    ///
    /// **Singleton-array law** — `AxisHistogram::from([cell])` is
    /// pointwise equal to `AxisHistogram::from(cell)` (the
    /// [`From<A>`] singleton constructor above) and to
    /// `std::iter::once(cell).collect::<AxisHistogram<A>>()`. The
    /// arity-1 array literal joins the singleton-constructor pin
    /// (`From<A>`, `Into`, `iter::once(_).collect()`,
    /// `{ empty + observe }`) as a fourth pointwise-equal lowering of
    /// the same one-observation projection.
    ///
    /// **Total-equals-length law** — for every array `arr: [A; N]`:
    /// `AxisHistogram::from(arr).total() == N`. The array's compile-
    /// time-known length determines the resulting total exactly, peer
    /// of the [`FromIterator<A>`] total-equals-input-length law on the
    /// runtime-length iterator surface.
    ///
    /// **Cell-additive on repeated cells** — when the array contains
    /// the same cell `k` times, the resulting histogram reads `k` at
    /// that cell. The natural composition the histogram's monoid
    /// `(usize, +, 0)` per cell carries, peer of the [`FromIterator<A>`]
    /// repeated-cell additivity.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor inherits the
    /// constructor at no per-axis cost. Pinned across the implementor
    /// set by the trait-uniform
    /// `axis_histogram_from_cell_array_equals_from_iter_collect_*` and
    /// `axis_histogram_from_empty_array_equals_empty_*` laws in
    /// [`tests`].
    fn from(values: [A; N]) -> Self {
        values.into_iter().collect()
    }
}

impl<A: ClosedAxis> FromIterator<(A, usize)> for AxisHistogram<A> {
    /// Build a histogram by absorbing every `(cell, count)` pair in `iter`
    /// — the canonical Rust idiom-peer of [`HashMap::from_iter`][std::collections::HashMap]
    /// / [`BTreeMap::from_iter`][std::collections::BTreeMap] on the
    /// pre-aggregated pair-input surface. Where [`FromIterator<A>`]
    /// builds from a stream of *raw observations* (one bump per yielded
    /// item), this impl builds from a stream of *pre-counted pairs*
    /// (one `+= count` per yielded pair) — the natural entry point when
    /// the histogram's data lives in a serialized, snapshotted, or
    /// pre-aggregated form rather than as a stream of fresh
    /// observations.
    ///
    /// Lowers through [`Extend<(A, usize)>::extend`]: build the
    /// identity ([`Self::empty`]), then fold every pair in `iter`
    /// through the [`Extend`] surface. The
    /// `FromIterator` / `Extend` peerage mirrors the
    /// [`FromIterator<A>`] / [`Extend<A>`] pair on the raw-observation
    /// surface so the per-pair fold loop lives at one site (the
    /// [`Extend<(A, usize)>`] impl below) and both surfaces stay in
    /// lockstep without duplication.
    ///
    /// **Cell-additive on repeated cells** — when the iterator yields
    /// the same cell twice as `(cell, n1)` then `(cell, n2)`, the
    /// resulting histogram reads `n1 + n2` at that cell, peer of the
    /// `HashMap::extend` "last-wins" semantics inverted for an
    /// additive monoid (the histogram's natural monoid is
    /// `(usize, +, 0)` per cell, not `(usize, last, undef)`).
    fn from_iter<I: IntoIterator<Item = (A, usize)>>(iter: I) -> Self {
        let mut hist = Self::empty();
        hist.extend(iter);
        hist
    }
}

impl<A: ClosedAxis> Extend<(A, usize)> for AxisHistogram<A> {
    /// Fold every `(cell, count)` pair in `iter` into the histogram in
    /// place by adding `count` to the cell at `cell` — the canonical
    /// Rust idiom-peer of [`HashMap::extend`][std::collections::HashMap]
    /// / [`BTreeMap::extend`][std::collections::BTreeMap] on the
    /// pre-aggregated pair-input surface, complementary to
    /// [`Extend<A>::extend`] on the raw-observation surface.
    ///
    /// Before this lift, every consumer with a pre-aggregated
    /// `(cell, count)` stream (an attestation manifest's
    /// `[{kind: "added", count: 12}, {kind: "removed", count: 4}]`
    /// deserialized into a `Vec<(DiffLineKind, usize)>`, a checkpoint
    /// snapshot restoring the per-cell counts from a serialized
    /// `Vec<(A, usize)>`, a config-loaded mapping carrying the
    /// per-axis tallies from a YAML/TOML/Lisp source, a streaming
    /// aggregator folding pre-aggregated sub-batches across windows
    /// without re-expanding to individual observations) reached the
    /// (pre-aggregated pairs → histogram) projection through one of
    /// two open-coded forms — the per-pair `for (c, n) in pairs {
    /// for _ in 0..n { hist.observe(c); } }` re-expansion loop (which
    /// reproduces every individual observation and is O(total),
    /// linear in the total observation count rather than the
    /// distinct-cell count) or the per-pair `for (c, n) in pairs {
    /// *hist.counts_mut_or_whatever()[axis_ordinal(c)] += n; }` form
    /// (which requires reaching the private counts vector). Collapsed
    /// to one trait-method call with a single-pass O(distinct cells)
    /// scan that bumps every named cell directly on the existing
    /// counts vector. The lift names the (existing-histogram,
    /// iterable pre-counted pairs → in-place fold) projection at one
    /// site.
    ///
    /// **Empty-identity law** — `hist.extend(std::iter::empty::<(A, usize)>())`
    /// leaves the histogram unchanged. The vacuous fold on the pair-
    /// input [`Extend`] surface, peer to the raw-observation
    /// [`Extend<A>`] empty-identity law and to the
    /// [`Self::merge`] empty-identity law.
    ///
    /// **Zero-count law** — `hist.extend(iter::once((cell, 0)))` leaves
    /// the histogram unchanged at every cell. A pair with count zero
    /// is the additive identity on its cell; the per-pair fold loop
    /// adds zero without bumping the counts vector.
    ///
    /// **Cell-additive on repeated cells** — when the iterator yields
    /// the same cell twice as `(cell, n1)` then `(cell, n2)`, the
    /// post-extend cell reads `before + n1 + n2`. The pair-input
    /// surface is *additive*, not last-wins — the natural monoid on
    /// per-cell counts is `(usize, +, 0)`, and the [`Extend`] impl
    /// folds through it. This is the salient asymmetry with
    /// [`HashMap::extend`] (which carries last-wins semantics on
    /// repeated keys): the histogram's per-cell algebra is additive
    /// because that's the algebra observations compose under, so
    /// the pair-input surface inherits the same composition.
    ///
    /// **Equivalence with the [`Self::observe`] expansion loop** —
    /// pointwise equal to `for (c, n) in iter { for _ in 0..n {
    /// hist.observe(c); } }` on every iterator, by definition. The
    /// trait method names the loop at one site and replaces the
    /// O(total) expansion with an O(distinct cells) single-pass
    /// scan; consumers no longer re-derive either form inline.
    ///
    /// **Equivalence with [`Self::merge`] on the empty starting
    /// point** — for every iterator `iter` and every histogram
    /// `hist`: `let mut a = hist.clone(); a.extend(iter.clone()); a`
    /// is pointwise equal to `hist.clone().merge(&iter.collect::<AxisHistogram<A>>())`.
    /// The (extend, merge) duality on the pair-input surface mirrors
    /// the same duality on the raw-observation surface.
    ///
    /// **Total-additivity law** — extending grows the total by exactly
    /// the sum of every yielded pair's count: `before.total() +
    /// iter.into_iter().map(|(_, n)| n).sum::<usize>() == after.total()`,
    /// peer of the [`Extend<A>`] additivity law (`before.total() +
    /// input.len() == after.total()`) on the raw-observation
    /// surface — both lower to the same scalar additivity on the
    /// [`Self::total`] projection.
    fn extend<I: IntoIterator<Item = (A, usize)>>(&mut self, iter: I) {
        for (cell, count) in iter {
            self.counts[axis_ordinal(cell)] += count;
        }
    }
}

impl<A: ClosedAxis, const N: usize> From<[(A, usize); N]> for AxisHistogram<A> {
    /// Build a histogram from a fixed-size array of pre-counted
    /// `(cell, count)` pairs — the canonical Rust stdlib
    /// pair-input-array constructor idiom-peer of
    /// [`HashMap::from`][std::collections::HashMap] /
    /// [`BTreeMap::from`][std::collections::BTreeMap] on the
    /// `[(K, V); N]` input surface. The const-generic-N partner of
    /// the [`FromIterator<(A, usize)>`] entry surface, hoisted to
    /// the stdlib array-literal call site so
    /// `AxisHistogram::from([(Added, 12), (Removed, 4)])` reads at
    /// the same idiom rung as
    /// `HashMap::from([("a", 1), ("b", 2)])` and
    /// `BTreeMap::from([("a", 1), ("b", 2)])`.
    ///
    /// Before this lift, every consumer reaching the
    /// (pre-counted pair-array → histogram) projection (an
    /// attestation manifest hard-coding the expected per-cell
    /// counts as a baseline `[(DiffLineKind::Added, 12),
    /// (DiffLineKind::Removed, 4)]`, a checkpoint-restoration test
    /// pinning a snapshotted observation tally, a CLI golden-output
    /// fixture pre-counted from a known input set, a documentation
    /// example reaching for the smallest readable lift from a
    /// `(cell, count)` literal to a histogram) reached one of three
    /// open-coded forms — the
    /// `[(Added, 12), (Removed, 4)].into_iter().collect::<AxisHistogram<_>>()`
    /// post-collect form (which forces an explicit turbofish at
    /// every site because the call-site shape doesn't constrain the
    /// collected type), the per-pair `let mut h = AxisHistogram::empty();
    /// h.extend([(Added, 12), (Removed, 4)]); h` two-step form, or
    /// the longhand per-cell `{ let mut h = AxisHistogram::empty();
    /// for _ in 0..12 { h.observe(Added); } for _ in 0..4 {
    /// h.observe(Removed); } h }` per-observation expansion (which
    /// is O(total) rather than O(distinct cells)). Collapsed to one
    /// trait-method call routed through the existing
    /// [`FromIterator<(A, usize)>`] impl, so the per-pair fold loop
    /// lives at exactly one site (the [`Extend<(A, usize)>`] impl
    /// above) underneath every pair-input constructor surface.
    ///
    /// **Equivalence with [`FromIterator<(A, usize)>`]** — for every
    /// fixed-size array `arr: [(A, usize); N]`:
    /// `AxisHistogram::from(arr)` is pointwise equal to
    /// `arr.into_iter().collect::<AxisHistogram<A>>()`. The
    /// pair-input array constructor / pair-input iterator
    /// constructor duality on the (pre-counted-pair) entry surface
    /// — the pair-array literal lowers to the same per-pair
    /// `+= count` fold the [`FromIterator<(A, usize)>`] impl
    /// drives, so the two constructors cannot drift apart by
    /// construction.
    ///
    /// **Empty-array identity law** — `AxisHistogram::from([])`
    /// disambiguated to `AxisHistogram::<A>::from([] as [(A, usize); 0])`
    /// is pointwise equal to [`AxisHistogram::empty`]. The vacuous
    /// fold on the pair-input array constructor surface, peer to
    /// the [`Extend<(A, usize)>`] empty-identity law and to the
    /// [`FromIterator<(A, usize)>`] empty-input identity. The zero-
    /// length pair array lowers to the monoid identity at the
    /// constructor rung — and lands on the same all-zero state as
    /// the raw-observation empty array `AxisHistogram::from([] as [A; 0])`.
    ///
    /// **Zero-count pair law** — `AxisHistogram::from([(cell, 0)])`
    /// is pointwise equal to [`AxisHistogram::empty`] for every
    /// cell. A pair with count zero is the additive identity on its
    /// cell; the per-pair fold adds zero without bumping the counts
    /// vector. Peer of the [`Extend<(A, usize)>`] zero-count law.
    ///
    /// **Singleton-pair-one law** — `AxisHistogram::from([(cell, 1)])`
    /// is pointwise equal to `AxisHistogram::from([cell])`,
    /// `AxisHistogram::from(cell)`, and
    /// `std::iter::once(cell).collect::<AxisHistogram<A>>()`. The
    /// arity-1 pair-array literal at count 1 joins the singleton-
    /// constructor pin as a fifth pointwise-equal lowering of the
    /// same one-observation projection — bridging the
    /// raw-observation entry surface to the pre-counted-pair entry
    /// surface at the singleton boundary.
    ///
    /// **Cell-additive on repeated cells** — when the array contains
    /// the same cell `k` times as `(cell, n_1), …, (cell, n_k)`,
    /// the resulting histogram reads `n_1 + … + n_k` at that cell.
    /// The natural composition the histogram's monoid
    /// `(usize, +, 0)` per cell carries, peer of the
    /// [`FromIterator<(A, usize)>`] repeated-cell additivity and
    /// of the raw-observation array form's repeated-cell additivity.
    /// The salient asymmetry with [`HashMap::from`] survives at the
    /// array rung: the histogram's per-cell algebra is additive,
    /// not last-wins, because the pair-input surface inherits the
    /// algebra observations compose under.
    ///
    /// **Total-equals-pair-sum law** — for every array
    /// `arr: [(A, usize); N]`:
    /// `AxisHistogram::from(arr).total() ==
    /// arr.iter().map(|(_, n)| n).sum::<usize>()`. The array's
    /// compile-time-known pair set determines the resulting total
    /// exactly as the sum of pair counts, peer of the
    /// [`From<[A; N]>`] `total == N` law on the raw-observation
    /// surface — both lower to the same scalar additivity on the
    /// [`Self::total`] projection.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor inherits the
    /// constructor at no per-axis cost. Pinned across the
    /// implementor set by the trait-uniform
    /// `axis_histogram_from_pair_array_equals_from_iter_collect_*`,
    /// `axis_histogram_from_singleton_pair_one_equals_singleton_cell_*`,
    /// and `axis_histogram_from_zero_count_pair_equals_empty_*` laws
    /// in [`tests`].
    fn from(values: [(A, usize); N]) -> Self {
        values.into_iter().collect()
    }
}

impl<'a, A: ClosedAxis> FromIterator<&'a A> for AxisHistogram<A> {
    /// Build a histogram by recording every borrowed observation in `iter`
    /// — the canonical Rust stdlib borrowed-input
    /// [`FromIterator<&T>`][FromIterator] idiom-peer of the owned-input
    /// [`FromIterator<A>`] impl above. The reference form every stdlib
    /// collection that supports a [`Copy`] item exposes alongside the
    /// owned form (`impl<'a, T: 'a + Copy> FromIterator<&'a T> for Vec<T>`,
    /// `impl<'a, T: 'a + Copy> FromIterator<&'a T> for VecDeque<T>`,
    /// `impl<'a, T: 'a + Copy + Ord> FromIterator<&'a T> for BTreeSet<T>`)
    /// so call sites reaching the histogram through `slice.iter().collect()`
    /// or `vec.iter().collect()` (a `&[A]` borrowed from an upstream
    /// observation buffer, a `Vec<A>` owned by an attestation manifest, a
    /// `BTreeSet<A>` iterated by reference for an order-preserving fold)
    /// work without an interposing `.copied()` adaptor — the
    /// [`ClosedAxis`] super-trait already requires [`Copy`], so the
    /// borrowed item is dereferenced and observed at one site without a
    /// per-element clone at the call site.
    ///
    /// Lowers through [`Extend<&'a A>::extend`]: build the identity
    /// ([`Self::empty`]), then fold every borrowed observation in `iter`
    /// through the borrowed-[`Extend`] surface. The
    /// (`FromIterator<&'a A>`, `Extend<&'a A>`) peerage mirrors the
    /// (`FromIterator<A>`, `Extend<A>`) pair on the owned-observation
    /// surface so the per-observation fold loop lives at one site (the
    /// [`Extend<&'a A>`] impl below) and both borrowed surfaces stay in
    /// lockstep without duplication.
    ///
    /// **Equivalence with the owned-input [`FromIterator<A>`] impl** —
    /// pointwise equal to `iter.copied().collect::<AxisHistogram<A>>()`
    /// on every iterator, but without the per-element `.copied()`
    /// adaptor the owned form would require. The (`FromIterator<A>`,
    /// `FromIterator<&'a A>`) idiom-peer pair: same construction, two
    /// call-site shapes, both anchored at the same `default + extend`
    /// lowering underneath. Peer of the
    /// (`Sum<Self>`, `Sum<&Self>`) idiom-peer pair on the dual
    /// reduction-side of the monoid.
    fn from_iter<I: IntoIterator<Item = &'a A>>(iter: I) -> Self {
        let mut hist = Self::empty();
        hist.extend(iter);
        hist
    }
}

impl<'a, A: ClosedAxis> Extend<&'a A> for AxisHistogram<A> {
    /// Fold every borrowed observation in `iter` into the histogram in
    /// place — the canonical Rust stdlib borrowed-input
    /// [`Extend<&T>`][Extend] idiom-peer of the owned-input [`Extend<A>`]
    /// impl above. The reference form every stdlib collection that
    /// supports a [`Copy`] item exposes alongside the owned form
    /// (`impl<'a, T: 'a + Copy> Extend<&'a T> for Vec<T>`, etc.) so call
    /// sites reaching the in-place fold through
    /// `hist.extend(slice.iter())` or `hist.extend(&vec)` (an observatory
    /// folding a borrowed sub-batch without consuming it, a fleet-wide
    /// aggregator absorbing a `&[A]` lent by an upstream collector) work
    /// without an interposing `.copied()` adaptor.
    ///
    /// **Equivalence with the owned-input [`Extend<A>`] impl** —
    /// pointwise equal to `hist.extend(iter.copied())` on every iterator,
    /// by definition. The borrowed-extend lowers to dereferencing each
    /// item and folding through the inherent [`Self::observe`] step the
    /// owned-extend uses; the [`ClosedAxis`] super-trait's [`Copy`] bound
    /// makes the dereference a value copy with no allocation.
    ///
    /// **Empty-identity law** — `hist.extend(std::iter::empty::<&A>())`
    /// leaves the histogram unchanged. The vacuous fold on the
    /// borrowed-[`Extend`] surface, peer of the owned-[`Extend<A>`]
    /// empty-identity law.
    fn extend<I: IntoIterator<Item = &'a A>>(&mut self, iter: I) {
        for &value in iter {
            self.observe(value);
        }
    }
}

/// Borrowing iterator over the `(axis-value, count)` pairs of an
/// [`AxisHistogram`], yielded in declaration order over [`ClosedAxis::ALL`].
///
/// The concrete return type of
/// [`<&AxisHistogram<A> as IntoIterator>::into_iter`][IntoIterator] and the
/// canonical Rust idiom-peer of [`std::slice::Iter`] /
/// [`std::collections::hash_map::Iter`] — every stdlib collection exposes a
/// named borrowing iterator (not an `impl Iterator` return) so consumers can
/// store the iterator in a `let`-bound variable that names the concrete type,
/// pass it through a generic boundary that needs to spell out the
/// `IntoIter`-associated type, or implement an extension trait that adds a
/// method on the borrowing iterator without reaching through an unnameable
/// `impl Iterator` surface. The borrowed pair shape carries the cell by value
/// (`A: Copy` is enforced by the [`ClosedAxis`] super-bound) and the count
/// by value (`usize` is `Copy`), so no lifetime appears in [`Self::Item`] —
/// the only lifetime is the one tying the iterator to the underlying
/// histogram's counts vector.
///
/// Implements [`Iterator`], [`ExactSizeIterator`] (the length is exactly
/// [`axis_cardinality::<A>()`][axis_cardinality], pinned at the type level),
/// [`std::iter::FusedIterator`] (the underlying [`std::slice::Iter`] is
/// fused), and [`DoubleEndedIterator`] (consumers reaching for `.rev()`,
/// `.next_back()`, or `.rfold(...)` get the dual-end iteration the
/// declaration-order pair surface naturally carries).
#[derive(Debug, Clone)]
pub struct AxisHistogramIter<'a, A: ClosedAxis> {
    counts: std::iter::Enumerate<std::slice::Iter<'a, usize>>,
    _marker: std::marker::PhantomData<A>,
}

impl<A: ClosedAxis> Iterator for AxisHistogramIter<'_, A> {
    type Item = (A, usize);
    fn next(&mut self) -> Option<Self::Item> {
        self.counts.next().map(|(i, &c)| (A::ALL[i], c))
    }
    fn size_hint(&self) -> (usize, Option<usize>) {
        self.counts.size_hint()
    }
}

impl<A: ClosedAxis> ExactSizeIterator for AxisHistogramIter<'_, A> {}
impl<A: ClosedAxis> std::iter::FusedIterator for AxisHistogramIter<'_, A> {}
impl<A: ClosedAxis> DoubleEndedIterator for AxisHistogramIter<'_, A> {
    fn next_back(&mut self) -> Option<Self::Item> {
        self.counts.next_back().map(|(i, &c)| (A::ALL[i], c))
    }
}

/// Consuming iterator over the `(axis-value, count)` pairs of an
/// [`AxisHistogram`], yielded in declaration order over [`ClosedAxis::ALL`].
///
/// The concrete return type of
/// [`<AxisHistogram<A> as IntoIterator>::into_iter`][IntoIterator] and the
/// canonical Rust idiom-peer of [`std::vec::IntoIter`] /
/// [`std::collections::hash_map::IntoIter`] — every stdlib collection exposes
/// a named consuming iterator alongside the named borrowing iterator.
/// Implements the same trait surface as [`AxisHistogramIter`]
/// ([`Iterator`], [`ExactSizeIterator`], [`std::iter::FusedIterator`],
/// [`DoubleEndedIterator`]).
#[derive(Debug, Clone)]
pub struct AxisHistogramIntoIter<A: ClosedAxis> {
    counts: std::iter::Enumerate<std::vec::IntoIter<usize>>,
    _marker: std::marker::PhantomData<A>,
}

impl<A: ClosedAxis> Iterator for AxisHistogramIntoIter<A> {
    type Item = (A, usize);
    fn next(&mut self) -> Option<Self::Item> {
        self.counts.next().map(|(i, c)| (A::ALL[i], c))
    }
    fn size_hint(&self) -> (usize, Option<usize>) {
        self.counts.size_hint()
    }
}

impl<A: ClosedAxis> ExactSizeIterator for AxisHistogramIntoIter<A> {}
impl<A: ClosedAxis> std::iter::FusedIterator for AxisHistogramIntoIter<A> {}
impl<A: ClosedAxis> DoubleEndedIterator for AxisHistogramIntoIter<A> {
    fn next_back(&mut self) -> Option<Self::Item> {
        self.counts.next_back().map(|(i, c)| (A::ALL[i], c))
    }
}

impl<'a, A: ClosedAxis> IntoIterator for &'a AxisHistogram<A> {
    type Item = (A, usize);
    type IntoIter = AxisHistogramIter<'a, A>;

    /// Iterate every `(axis-value, count)` pair of the borrowed histogram in
    /// declaration order — the canonical Rust [`IntoIterator`] idiom on
    /// `&AxisHistogram<A>`, peer of [`FromIterator<A>`] on the same type.
    /// Lets consumers reach the dense per-cell pair surface through the
    /// borrowed-collection idiom `for pair in &hist { … }` without naming
    /// [`AxisHistogram::iter`] explicitly — the same surface every stdlib
    /// collection exposes (`for x in &vec`, `for (k, v) in &map`).
    ///
    /// **Equivalence with [`AxisHistogram::iter`]** — pointwise equal to
    /// `hist.iter().collect::<Vec<_>>()` on every histogram, by
    /// construction. The (`IntoIterator`, `iter`) duality on the
    /// borrowed-collection surface; the two are alternate spellings of the
    /// same per-cell scan over [`ClosedAxis::ALL`].
    ///
    /// **Length law** — yields exactly
    /// [`axis_cardinality::<A>()`][axis_cardinality] pairs, regardless of
    /// how many cells are nonzero (the iteration covers the full axis, not
    /// just the support). [`ExactSizeIterator::len`] reads off the
    /// cardinality without consuming the iterator.
    fn into_iter(self) -> Self::IntoIter {
        AxisHistogramIter {
            counts: self.counts.iter().enumerate(),
            _marker: std::marker::PhantomData,
        }
    }
}

impl<A: ClosedAxis> IntoIterator for AxisHistogram<A> {
    type Item = (A, usize);
    type IntoIter = AxisHistogramIntoIter<A>;

    /// Consume the histogram and iterate every `(axis-value, count)` pair in
    /// declaration order — the canonical Rust [`IntoIterator`] idiom on the
    /// owned-collection surface, peer of the borrowed
    /// [`IntoIterator for &AxisHistogram<A>`][IntoIterator]. Yields the same
    /// pair sequence as the borrowed form (pointwise equal); the asymmetry
    /// is only at the call site (consume vs borrow).
    ///
    /// **Equivalence with [`AxisHistogram::iter`]** — pointwise equal to
    /// `hist.iter().collect::<Vec<_>>()` on every histogram, by
    /// construction (the count vector is walked once in either direction).
    ///
    /// **Length law** — yields exactly
    /// [`axis_cardinality::<A>()`][axis_cardinality] pairs, the same as the
    /// borrowed form.
    fn into_iter(self) -> Self::IntoIter {
        AxisHistogramIntoIter {
            counts: self.counts.into_iter().enumerate(),
            _marker: std::marker::PhantomData,
        }
    }
}

/// Mutable borrowing iterator over the `(axis-value, &mut count)` pairs of an
/// [`AxisHistogram`], yielded in declaration order over [`ClosedAxis::ALL`].
///
/// The concrete return type of
/// [`<&mut AxisHistogram<A> as IntoIterator>::into_iter`][IntoIterator] and
/// [`AxisHistogram::iter_mut`] — the canonical Rust idiom-peer of
/// [`std::slice::IterMut`] / [`std::collections::hash_map::IterMut`] /
/// [`std::collections::btree_map::IterMut`] every stdlib collection exposes
/// alongside its read-only borrowing iterator. The borrowed pair shape carries
/// the cell by value (`A: Copy` is enforced by the [`ClosedAxis`] super-bound)
/// and the count by mutable reference (`&mut usize`), so consumers can read
/// and assign through the second tuple slot in one pass (`for (cell, c) in
/// hist.iter_mut() { *c = remap(cell, *c); }` is the canonical call shape).
///
/// Implements [`Iterator`], [`ExactSizeIterator`] (the length is exactly
/// [`axis_cardinality::<A>()`][axis_cardinality], pinned at the type level),
/// [`std::iter::FusedIterator`] (the underlying [`std::slice::IterMut`] is
/// fused), and [`DoubleEndedIterator`] (consumers reaching for `.rev()`,
/// `.next_back()`, or `.rfold(...)` get the dual-end iteration the
/// declaration-order pair surface naturally carries) — the same trait surface
/// as [`AxisHistogramIter`] minus [`Clone`]. Mutable iterators in the Rust
/// stdlib are not [`Clone`] (cloning would expose two `&mut` aliases to the
/// same slot, violating Rust's aliasing rule); [`AxisHistogramIterMut`]
/// follows that convention.
#[derive(Debug)]
pub struct AxisHistogramIterMut<'a, A: ClosedAxis> {
    counts: std::iter::Enumerate<std::slice::IterMut<'a, usize>>,
    _marker: std::marker::PhantomData<A>,
}

impl<'a, A: ClosedAxis> Iterator for AxisHistogramIterMut<'a, A> {
    type Item = (A, &'a mut usize);
    fn next(&mut self) -> Option<Self::Item> {
        self.counts.next().map(|(i, c)| (A::ALL[i], c))
    }
    fn size_hint(&self) -> (usize, Option<usize>) {
        self.counts.size_hint()
    }
}

impl<A: ClosedAxis> ExactSizeIterator for AxisHistogramIterMut<'_, A> {}
impl<A: ClosedAxis> std::iter::FusedIterator for AxisHistogramIterMut<'_, A> {}
impl<A: ClosedAxis> DoubleEndedIterator for AxisHistogramIterMut<'_, A> {
    fn next_back(&mut self) -> Option<Self::Item> {
        self.counts.next_back().map(|(i, c)| (A::ALL[i], c))
    }
}

impl<'a, A: ClosedAxis> IntoIterator for &'a mut AxisHistogram<A> {
    type Item = (A, &'a mut usize);
    type IntoIter = AxisHistogramIterMut<'a, A>;

    /// Iterate every `(axis-value, &mut count)` pair of the mutably borrowed
    /// histogram in declaration order — the canonical Rust [`IntoIterator`]
    /// idiom on `&mut AxisHistogram<A>`, peer of [`IntoIterator for
    /// &AxisHistogram<A>`][IntoIterator] on the read-only borrowing surface.
    /// Lets consumers reach the cellwise-mutation surface through the
    /// borrowed-collection idiom `for pair in &mut hist { … }` without naming
    /// [`AxisHistogram::iter_mut`] explicitly — the same surface every stdlib
    /// collection exposes (`for x in &mut vec`, `for (k, v) in &mut map`).
    ///
    /// **Equivalence with [`AxisHistogram::iter_mut`]** — pointwise equal to
    /// `hist.iter_mut().collect::<Vec<_>>()` on every histogram, by
    /// construction (both lower to the same
    /// [`std::slice::IterMut`]-driven [`AxisHistogramIterMut`] type over the
    /// counts vector). The (`IntoIterator`, `iter_mut`) duality on the
    /// mutably-borrowed-collection surface; the two are alternate spellings
    /// of the same per-cell mutable scan over [`ClosedAxis::ALL`].
    ///
    /// **Length law** — yields exactly
    /// [`axis_cardinality::<A>()`][axis_cardinality] pairs, regardless of how
    /// many cells are nonzero (the iteration covers the full axis, not just
    /// the support). [`ExactSizeIterator::len`] reads off the cardinality
    /// without consuming the iterator.
    fn into_iter(self) -> Self::IntoIter {
        AxisHistogramIterMut {
            counts: self.counts.iter_mut().enumerate(),
            _marker: std::marker::PhantomData,
        }
    }
}

impl<A: ClosedAxis> std::iter::Sum<AxisHistogram<A>> for AxisHistogram<A> {
    /// Reduce an iterator of histograms by pointwise sum — the canonical
    /// Rust [`Sum`][std::iter::Sum] trait idiom for the monoid
    /// `(AxisHistogram, merge, empty)`. Every consumer folding a sequence
    /// of sub-histograms into one aggregate (a fleet-wide accumulator
    /// folding per-thread tallies before rendering a dashboard tick, a
    /// rolling-window aggregator summing the last N reload windows'
    /// `AxisHistogram<crate::ShikumiErrorKind>` into the hour cell, a
    /// per-fleet observatory summing per-host
    /// `AxisHistogram<crate::WatchEventClass>` into the fleet cell) reaches
    /// the reduction through `iter.sum()` — the same trait surface every
    /// stdlib numeric monoid uses.
    ///
    /// Lowered through [`Iterator::fold`] anchored at [`Self::empty`] (the
    /// monoid identity) and stepped by [`Self::merge`] (the monoid binary
    /// operation). The canonical Rust monoid-`Sum` pattern: identity at
    /// `fold`'s seed, binary op at `fold`'s step.
    ///
    /// **Equivalence with the explicit fold** — pointwise equal to
    /// `iter.fold(AxisHistogram::empty(), |acc, h| acc.merge(&h))` on every
    /// iterator, by definition. The trait method names the reduction at
    /// one site so consumers no longer re-derive the fold inline.
    ///
    /// **Empty-iterator law** — the empty iterator sums to the empty
    /// histogram (the monoid identity at the `fold` seed, untouched).
    ///
    /// **Singleton law** — `std::iter::once(h).sum()` is pointwise equal to
    /// `h` (the seed merged with a single value is that value, via the
    /// empty-identity law on [`Self::merge`]).
    ///
    /// **Additivity on [`Self::total`]** — the summed histogram's total
    /// equals the sum of the components' totals, peer to the
    /// `merge`-additivity law on `total`.
    ///
    /// Trait-uniform laws reach every [`ClosedAxis`] implementor through
    /// `for_each_closed_axis_implementor!` in [`tests`]
    /// (`axis_histogram_sum_of_empty_iter_is_empty_*`,
    /// `axis_histogram_sum_of_singleton_iter_equals_inner_*`,
    /// `axis_histogram_sum_grows_total_additively_*`,
    /// `axis_histogram_sum_owned_equals_explicit_fold_*`).
    fn sum<I: IntoIterator<Item = AxisHistogram<A>>>(iter: I) -> Self {
        iter.into_iter().fold(Self::empty(), |acc, h| acc.merge(&h))
    }
}

impl<'a, A: ClosedAxis> std::iter::Sum<&'a AxisHistogram<A>> for AxisHistogram<A> {
    /// Reduce an iterator of histogram references by pointwise sum — the
    /// canonical Rust [`Sum`][std::iter::Sum] trait idiom on the
    /// borrowed-element side, peer to the owned-element [`Sum`] impl above.
    /// The reference form every stdlib numeric monoid exposes alongside the
    /// owned form (`impl Sum<&'a u32> for u32`, etc.) so call sites
    /// reaching the reduction through `slice.iter().sum()` or
    /// `vec.iter().sum()` work without an interposing `.cloned()` /
    /// `.copied()` adaptor — the histogram is folded into the accumulator
    /// by reference at every step.
    ///
    /// Lowered through [`Iterator::fold`] anchored at [`Self::empty`] (the
    /// monoid identity) and stepped by [`Self::merge`] taking the borrowed
    /// element directly (no `.clone()` at the call site of the merge step).
    ///
    /// **Equivalence with the owned-element [`Sum`] impl** — pointwise
    /// equal to `slice.iter().cloned().sum::<AxisHistogram<A>>()` on every
    /// slice, but without the per-element clone the owned form would
    /// require. The (Sum<Owned>, Sum<&Owned>) idiom-peer pair: same
    /// reduction, two call-site shapes, both anchored at the same
    /// identity-and-merge fold underneath.
    ///
    /// Trait-uniform laws reach every [`ClosedAxis`] implementor through
    /// `for_each_closed_axis_implementor!` in [`tests`]
    /// (`axis_histogram_sum_of_refs_equals_sum_of_owned_*`).
    fn sum<I: IntoIterator<Item = &'a AxisHistogram<A>>>(iter: I) -> Self {
        iter.into_iter().fold(Self::empty(), AxisHistogram::merge)
    }
}

impl<A: ClosedAxis> std::ops::AddAssign<&AxisHistogram<A>> for AxisHistogram<A> {
    /// Fold `other` into `self` in place by pointwise sum — the canonical
    /// Rust [`AddAssign`][std::ops::AddAssign] trait idiom for the monoid
    /// `(AxisHistogram, merge, empty)` on the borrowed-right-hand-side
    /// surface. The peer of [`Self::merge`] on the in-place fold form,
    /// and the primitive site that carries the per-cell fold loop —
    /// every other monoid-operator surface on this type
    /// ([`AddAssign<Self>`], [`Add<Self>`], [`Add<&Self>`], and
    /// [`Self::merge`] itself) lowers through this impl so the per-cell
    /// loop lives at exactly one site.
    ///
    /// Before this lift, every consumer reaching the in-place
    /// pointwise-sum projection (an observatory accumulator folding a
    /// just-collected sub-batch into the rolling-window aggregate, a
    /// fleet-wide dashboard folding a per-host
    /// `AxisHistogram<crate::WatchEventClass>` cell into the fleet cell
    /// at every render tick, a per-tier observatory accumulating
    /// per-tier `AxisHistogram<crate::ConfigSourceKind>` cells into the
    /// cross-tier aggregate) reached it through one of three forms — the
    /// rebind-through-`merge` form `hist = hist.merge(&other);` (the
    /// most common, allocates no extra histogram but forces a rebind at
    /// every call site), the open-coded per-cell loop form
    /// `for (slot, c) in hist.counts.iter_mut().zip(other.counts.iter())
    /// { *slot += c; }` (the loop the [`merge`][Self::merge] impl used to
    /// carry inline, requires `pub(crate)` access to the counts vector
    /// or a private helper), or the build-and-merge form
    /// `hist = hist.merge(&other.clone());` (which clones the right-hand
    /// side unnecessarily). The lift names the (existing-histogram,
    /// borrowed-histogram → in-place fold) projection at one site,
    /// consumers route through `hist += &other;` uniformly, and the
    /// per-cell loop lives at exactly one site (this impl) underneath
    /// every monoid-operator entry surface.
    ///
    /// **Equivalence with [`Self::merge`]** — for every pair `(self,
    /// other)`: `let mut a = self.clone(); a += other; a` is pointwise
    /// equal to `self.clone().merge(other)`. The (`AddAssign`, `merge`)
    /// duality on the monoid: extending in place is the in-place form
    /// of the owned-merge surface. The [`merge`][Self::merge] impl itself
    /// lowers through this method so the equivalence is by construction.
    ///
    /// **Empty-right-hand-side identity** — `hist += &empty` leaves
    /// `hist` unchanged. The vacuous fold on the [`AddAssign`] surface,
    /// peer to the [`Self::merge`] empty-identity law.
    ///
    /// **Commutativity on the monoid operation** (not on the call site):
    /// `let mut a = x.clone(); a += &y;` and
    /// `let mut b = y.clone(); b += &x;` are pointwise equal, by the
    /// commutativity of cellwise `+`. The call sites differ in which
    /// histogram is mutated; the resulting histogram does not.
    ///
    /// **Cell-level accounting** — every cell `v` has its count
    /// incremented by `other.count(v)`; the total grows by exactly
    /// `other.total()`. Peer to the [`Self::total`] / [`Self::merge`]
    /// additivity law.
    ///
    /// **Concatenation associativity** — `a += &b; a += &c;` produces
    /// the same histogram as `a += &b.clone().merge(&c);`. The
    /// (`+=`, ⊕) homomorphism over histogram concatenation, peer to
    /// the (extend, ⊕) homomorphism on [`Extend::extend`].
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor inherits the
    /// projection at no per-axis cost. The trait-uniform laws pinned in
    /// [`tests`] hold across the implementor set
    /// (`axis_histogram_add_assign_ref_empty_rhs_is_identity_*`,
    /// `axis_histogram_add_assign_ref_equals_merge_*`,
    /// `axis_histogram_add_assign_ref_grows_total_additively_*`,
    /// `axis_histogram_add_assign_ref_is_commutative_*`).
    fn add_assign(&mut self, other: &AxisHistogram<A>) {
        for (slot, &delta) in self.counts.iter_mut().zip(other.counts.iter()) {
            *slot += delta;
        }
    }
}

impl<A: ClosedAxis> std::ops::AddAssign<AxisHistogram<A>> for AxisHistogram<A> {
    /// Fold `other` into `self` in place — the owned-right-hand-side
    /// peer of [`AddAssign<&Self>`]. Delegates directly to the borrowed
    /// form (the right-hand side is read once, by reference, then
    /// dropped); the per-cell fold loop lives at one site (the
    /// borrowed-RHS impl).
    fn add_assign(&mut self, other: AxisHistogram<A>) {
        *self += &other;
    }
}

impl<A: ClosedAxis> std::ops::Add<&AxisHistogram<A>> for AxisHistogram<A> {
    type Output = AxisHistogram<A>;

    /// Pointwise sum of `self` and `other` — the canonical Rust
    /// [`Add`][std::ops::Add] trait idiom for the monoid
    /// `(AxisHistogram, merge, empty)` on the borrowed-right-hand-side
    /// surface. The natural infix-operator peer of [`Self::merge`] — the
    /// same shape consumers reach for when they want the `+` operator
    /// on histograms (`a + &b` instead of `a.merge(&b)`).
    ///
    /// Lowered through [`AddAssign<&Self>`]: take ownership of `self`,
    /// fold `other` in through `+=`, return the accumulator. Pointwise
    /// equal to [`Self::merge`] on every call site, by construction
    /// (both lower through `+=` underneath). Trait-uniform laws pinned
    /// in [`tests`] (`axis_histogram_add_ref_equals_merge_*`,
    /// `axis_histogram_add_ref_is_commutative_*`).
    fn add(mut self, other: &AxisHistogram<A>) -> Self::Output {
        self += other;
        self
    }
}

impl<A: ClosedAxis> std::ops::Add<AxisHistogram<A>> for AxisHistogram<A> {
    type Output = AxisHistogram<A>;

    /// Pointwise sum of `self` and `other` — the owned-right-hand-side
    /// peer of [`Add<&Self>`]. Delegates to the borrowed form so the
    /// fold loop lives at exactly one site (the [`AddAssign<&Self>`]
    /// impl). Pointwise equal to [`Self::merge`] on every call site.
    fn add(mut self, other: AxisHistogram<A>) -> Self::Output {
        self += &other;
        self
    }
}

impl<A: ClosedAxis> std::ops::SubAssign<&AxisHistogram<A>> for AxisHistogram<A> {
    /// Saturating pointwise subtraction of `other` from `self` in place —
    /// the canonical Rust [`SubAssign`][std::ops::SubAssign] trait idiom
    /// for the natural-number monus operation `(AxisHistogram, ∸, empty)`
    /// on the borrowed-right-hand-side surface. The dual of
    /// [`AddAssign<&Self>`] on the additive monoid: per-cell
    /// [`usize::saturating_sub`] lifted cellwise across [`ClosedAxis::ALL`].
    /// The primitive site that carries the per-cell saturating-subtraction
    /// loop — every other subtraction-operator surface on this type
    /// ([`SubAssign<Self>`], [`Sub<Self>`], [`Sub<&Self>`]) lowers
    /// through this impl so the per-cell loop lives at exactly one site.
    ///
    /// Saturation is the canonical choice for natural-number-valued
    /// histograms: counts are [`usize`], so an unsaturated subtraction
    /// would underflow (debug-panic, release-wrap) on any cell where
    /// `other.count(v) > self.count(v)`. Saturating at zero gives the
    /// monus semiring `(ℕ, +, ∸)` the histogram is naturally typed in,
    /// the same algebra Rust's stdlib exposes through
    /// [`usize::saturating_sub`] / [`Saturating<u*>::sub`] /
    /// [`Duration::saturating_sub`]. Closes the additive operator
    /// quartet `(Add, AddAssign, Sub, SubAssign)` on the
    /// [`AxisHistogram`] surface, peer to the additive quartet every
    /// stdlib numeric monoid carries.
    ///
    /// Before this lift, every consumer reaching the (cellwise saturating
    /// subtract) projection — a fleet aggregator removing a per-host
    /// `AxisHistogram<crate::WatchEventClass>` cell when the host leaves
    /// the fleet so the fleet histogram retains only the surviving
    /// hosts' observations, a per-window observatory backing out a
    /// just-rolled-off window from a rolling-window aggregate so the
    /// window-of-N projection slides forward by one without re-folding
    /// N windows from scratch, a per-tier observatory backing out a
    /// retired tier's `AxisHistogram<crate::ConfigSourceKind>` cell from
    /// a cross-tier rollup, a delta-projection asking *"what's left of
    /// `a` after subtracting `b`'s contribution?"* on a per-window
    /// `AxisHistogram<crate::ShikumiErrorKind>` cell — reached it through
    /// one of two forms: the open-coded per-cell loop
    /// `for (slot, &c) in hist.counts.iter_mut().zip(other.counts.iter())
    /// { *slot = slot.saturating_sub(c); }` (requires `pub(crate)` access
    /// to the counts vector or a private helper) or the rebuild-from-iter
    /// form
    /// `AxisHistogram::from_iter(hist.iter().map(|(v, c)| (v,
    /// c.saturating_sub(other.count(v)))))` (an
    /// O(axis_cardinality) reallocation for what is in-place
    /// arithmetic). Collapsed to one trait-method call with a single-pass
    /// O(axis_cardinality) scan over the existing counts vector.
    ///
    /// **Empty-right-hand-side identity** — `hist -= &empty` leaves
    /// `hist` unchanged. The vacuous fold on the [`SubAssign`] surface,
    /// peer to the [`AddAssign`] empty-RHS-identity law on the dual side
    /// of the monus monoid.
    ///
    /// **Self-subtraction absorbing law** — `let mut a = hist.clone();
    /// a -= &hist` zeros every cell of `a`, pointwise equal to
    /// [`AxisHistogram::empty`]. The monus self-cancellation law: every
    /// natural number minus itself is zero. Peer to the
    /// [`MulAssign<usize>`] zero-factor absorbing law on the
    /// scalar-action surface.
    ///
    /// **Saturation-at-zero law** — `hist -= &larger` (every cell of
    /// `larger` ≥ every cell of `hist`) yields a histogram pointwise
    /// equal to [`AxisHistogram::empty`]; no cell underflows below
    /// zero. The defining property of natural-number monus, peer to the
    /// stdlib's [`usize::saturating_sub`] saturation contract.
    ///
    /// **Round-trip with [`AddAssign`]** — `let mut a = lhs.clone();
    /// a += &rhs; a -= &rhs;` is pointwise equal to `lhs`, provided no
    /// cell of `lhs + &rhs` overflows. The (`+=`, `-=`) inverse-pair
    /// law on the monus monoid wherever the addition stays within
    /// [`usize::MAX`], peer to the stdlib's
    /// `(a + b).saturating_sub(b) == a` round-trip on the natural
    /// numbers. Pinned by
    /// [`tests::axis_histogram_sub_assign_ref_is_inverse_of_add_assign_ref_for_every_closed_axis_implementor`].
    ///
    /// **Cell-level saturation** — every cell `v` satisfies
    /// `after.count(v) == before.count(v).saturating_sub(other.count(v))`.
    /// Peer to the [`AddAssign`] cell-additivity law on the dual side of
    /// the monus monoid.
    ///
    /// **Total-shrinking law** — `hist -= &other` shrinks
    /// `hist.total()` by exactly the sum of per-cell saturated deltas:
    /// `before.total() - after.total() == Σ_v min(before.count(v),
    /// other.count(v))`. The total never grows under subtraction, and
    /// the shrink amount is bounded above by `other.total()` (with
    /// equality iff every cell satisfies `other.count(v) ≤
    /// before.count(v)`).
    ///
    /// **Non-commutativity** — unlike [`AddAssign`], saturating
    /// subtraction is not commutative on the resulting histogram:
    /// `a -= &b` and `b -= &a` produce different histograms in general
    /// (the monus is the cellwise positive part of `a - b`, the dual
    /// reads off `b - a`). Documented explicitly here as a contrast with
    /// the [`AddAssign`] commutativity law.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor inherits the
    /// projection at no per-axis cost. The trait-uniform laws pinned in
    /// [`tests`] hold across the implementor set
    /// (`axis_histogram_sub_assign_ref_empty_rhs_is_identity_*`,
    /// `axis_histogram_sub_assign_ref_self_yields_empty_*`,
    /// `axis_histogram_sub_assign_ref_saturates_at_zero_*`,
    /// `axis_histogram_sub_assign_ref_is_inverse_of_add_assign_ref_*`,
    /// `axis_histogram_sub_assign_ref_cell_level_saturates_*`,
    /// `axis_histogram_sub_owned_equals_sub_ref_*`).
    fn sub_assign(&mut self, other: &AxisHistogram<A>) {
        for (slot, &delta) in self.counts.iter_mut().zip(other.counts.iter()) {
            *slot = slot.saturating_sub(delta);
        }
    }
}

impl<A: ClosedAxis> std::ops::SubAssign<AxisHistogram<A>> for AxisHistogram<A> {
    /// Saturating pointwise subtraction of `other` from `self` in place
    /// — the owned-right-hand-side peer of [`SubAssign<&Self>`]. Delegates
    /// to the borrowed form (the right-hand side is read once, by
    /// reference, then dropped); the per-cell saturating-subtraction loop
    /// lives at exactly one site (the borrowed-RHS impl).
    fn sub_assign(&mut self, other: AxisHistogram<A>) {
        *self -= &other;
    }
}

impl<A: ClosedAxis> std::ops::Sub<&AxisHistogram<A>> for AxisHistogram<A> {
    type Output = AxisHistogram<A>;

    /// Saturating pointwise difference of `self` and `other` — the
    /// canonical Rust [`Sub`][std::ops::Sub] trait idiom for the
    /// natural-number monus operation on the borrowed-right-hand-side
    /// surface. The natural infix-operator peer of
    /// [`SubAssign<&Self>`] — the same shape consumers reach for when
    /// they want the `-` operator on histograms (`a - &b` for the
    /// cellwise saturating difference).
    ///
    /// Lowered through [`SubAssign<&Self>`]: take ownership of `self`,
    /// fold `other` out through `-=`, return the accumulator. Pointwise
    /// equal to [`SubAssign<&Self>`] on every call site, by construction
    /// (both lower through `-=` underneath). Trait-uniform laws pinned
    /// in [`tests`]
    /// (`axis_histogram_sub_owned_equals_sub_ref_*`).
    fn sub(mut self, other: &AxisHistogram<A>) -> Self::Output {
        self -= other;
        self
    }
}

impl<A: ClosedAxis> std::ops::Sub<AxisHistogram<A>> for AxisHistogram<A> {
    type Output = AxisHistogram<A>;

    /// Saturating pointwise difference of `self` and `other` — the
    /// owned-right-hand-side peer of [`Sub<&Self>`]. Delegates to the
    /// borrowed form so the saturating-subtraction loop lives at exactly
    /// one site (the [`SubAssign<&Self>`] impl). Pointwise equal to
    /// [`SubAssign<&Self>`] on every call site.
    fn sub(mut self, other: AxisHistogram<A>) -> Self::Output {
        self -= &other;
        self
    }
}

impl<A: ClosedAxis> std::ops::BitXorAssign<&AxisHistogram<A>> for AxisHistogram<A> {
    /// Cellwise absolute-difference of `self` and `other` in place — the
    /// canonical Rust [`BitXorAssign`][std::ops::BitXorAssign] trait idiom
    /// for the symmetric-difference (△) operation on the multiset
    /// surface, the in-place peer of [`Self::symmetric_difference`] and
    /// the operator-surface lift of the same per-cell
    /// [`usize::abs_diff`] loop. The primitive site that carries the
    /// per-cell loop — every other symmetric-difference surface on this
    /// type ([`BitXorAssign<Self>`], [`BitXor<Self>`], [`BitXor<&Self>`],
    /// and [`Self::symmetric_difference`] itself) lowers through this
    /// impl so the per-cell `abs_diff` loop lives at exactly one site.
    ///
    /// Promotes the (∪, ∩, ∖, △) set-theoretic operator quartet onto
    /// the stdlib bit-operator surface: the multiset peer of
    /// [`std::collections::HashSet::bitxor_assign`] /
    /// [`std::collections::BTreeSet::bitxor_assign`] (the `^=` on stdlib
    /// sets), with [`AxisHistogram::pointwise_max`] (∪),
    /// [`AxisHistogram::pointwise_min`] (∩), [`std::ops::Sub`] (∖) on
    /// the inherent / arithmetic-operator side and [`Self::bitxor`] (△)
    /// on the bit-operator side. Closes the missing operator-surface arm
    /// of the symmetric-difference quartet established by the inherent
    /// method.
    ///
    /// Before this lift, every consumer reaching the cellwise-absolute-
    /// difference projection on the in-place surface — an L1 / Manhattan-
    /// distance accumulator folding a just-observed window's gap-against-
    /// baseline into a rolling absolute-deviation aggregate, a fleet
    /// observatory backing the regression-detector's `|today - yesterday|`
    /// projection on a per-host `AxisHistogram<crate::ShikumiErrorKind>`
    /// cell, a per-tier observatory computing the cellwise multiset gap
    /// between two tier-snapshots without distinguishing direction —
    /// reached the projection through the consume-and-rebind
    /// `hist = hist.symmetric_difference(&other);` form (the only inherent
    /// shape, which forces a rebind at every call site even when the
    /// histogram lives behind a mutable binding). Collapsed onto the
    /// stdlib bit-operator-assign surface so call sites read `hist ^=
    /// &other;` — the canonical Rust idiom every reader already knows
    /// from [`HashSet::bitxor_assign`].
    ///
    /// **Equivalence with [`Self::symmetric_difference`]** — for every
    /// pair `(self, other)`: `let mut a = self.clone(); a ^= other; a`
    /// is pointwise equal to `self.clone().symmetric_difference(other)`.
    /// The (`BitXorAssign`, `symmetric_difference`) duality on the
    /// symmetric-difference operator: extending in place is the in-place
    /// form of the owned-symmetric-difference surface. The
    /// [`symmetric_difference`][Self::symmetric_difference] impl itself
    /// lowers through this method so the equivalence is by construction.
    ///
    /// **Symmetry on the monoid operation** (not on the call site):
    /// `let mut a = x.clone(); a ^= &y;` and
    /// `let mut b = y.clone(); b ^= &x;` are pointwise equal, by the
    /// symmetry of cellwise [`usize::abs_diff`]. The call sites differ
    /// in which histogram is mutated; the resulting histogram does not.
    /// Peer to the [`AddAssign`][std::ops::AddAssign] commutativity law
    /// on the additive monoid.
    ///
    /// **Empty-right-hand-side identity** — `hist ^= &empty` leaves
    /// `hist` unchanged. Every cell of `empty` is zero, so `|c - 0| ==
    /// c` reduces to the original count on every ordinal. Peer to the
    /// [`AddAssign`][std::ops::AddAssign] empty-RHS-identity law on the
    /// additive monoid and to the [`HashSet`][std::collections::HashSet]
    /// empty-RHS-identity law on the stdlib set surface.
    ///
    /// **Self-cancellation absorbing law** — `let mut a = hist.clone();
    /// a ^= &hist` zeros every cell of `a`, pointwise equal to
    /// [`AxisHistogram::empty`]. The exponent-2 self-inverse law on the
    /// symmetric-difference monoid: every histogram is its own inverse
    /// under `^=`, which is exactly the structure that makes
    /// `(AxisHistogram, ^=, empty)` a commutative group of exponent 2
    /// on the support-set projection. Peer to the [`SubAssign`][std::ops::SubAssign]
    /// self-subtraction absorbing law on the monus monoid.
    ///
    /// **Cell-level absolute-difference** — every cell `v` satisfies
    /// `after.count(v) == before.count(v).abs_diff(other.count(v))`.
    /// Peer to the [`AddAssign`][std::ops::AddAssign] cell-additivity
    /// law and the [`SubAssign`][std::ops::SubAssign] cell-saturation
    /// law on the additive / monus monoids.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor inherits the
    /// projection at no per-axis cost. The trait-uniform laws pinned in
    /// [`tests`] hold across the implementor set
    /// (`axis_histogram_bitxor_assign_ref_equals_symmetric_difference_*`,
    /// `axis_histogram_bitxor_assign_ref_empty_rhs_is_identity_*`,
    /// `axis_histogram_bitxor_assign_ref_self_yields_empty_*`,
    /// `axis_histogram_bitxor_assign_ref_is_symmetric_*`,
    /// `axis_histogram_bitxor_assign_ref_cell_level_abs_diff_*`,
    /// `axis_histogram_bitxor_owned_equals_bitxor_ref_*`,
    /// `axis_histogram_bitxor_assign_owned_equals_bitxor_assign_ref_*`).
    fn bitxor_assign(&mut self, other: &AxisHistogram<A>) {
        for (slot, &delta) in self.counts.iter_mut().zip(other.counts.iter()) {
            *slot = (*slot).abs_diff(delta);
        }
    }
}

impl<A: ClosedAxis> std::ops::BitXorAssign<AxisHistogram<A>> for AxisHistogram<A> {
    /// Cellwise absolute-difference of `self` and `other` in place — the
    /// owned-right-hand-side peer of [`BitXorAssign<&Self>`]. Delegates
    /// to the borrowed form (the right-hand side is read once, by
    /// reference, then dropped); the per-cell `abs_diff` loop lives at
    /// exactly one site (the borrowed-RHS impl).
    fn bitxor_assign(&mut self, other: AxisHistogram<A>) {
        *self ^= &other;
    }
}

impl<A: ClosedAxis> std::ops::BitXor<&AxisHistogram<A>> for AxisHistogram<A> {
    type Output = AxisHistogram<A>;

    /// Cellwise absolute-difference of `self` and `other` — the
    /// canonical Rust [`BitXor`][std::ops::BitXor] trait idiom for the
    /// symmetric-difference (△) operation on the multiset surface, on
    /// the borrowed-right-hand-side surface. The natural infix-operator
    /// peer of [`Self::symmetric_difference`] — the same shape consumers
    /// reach for when they want the `^` operator on histograms (`a ^ &b`
    /// instead of `a.symmetric_difference(&b)`).
    ///
    /// Lowered through [`BitXorAssign<&Self>`]: take ownership of
    /// `self`, fold `other` in through `^=`, return the accumulator.
    /// Pointwise equal to [`Self::symmetric_difference`] on every call
    /// site, by construction (both lower through `^=` underneath). Peer
    /// to [`std::collections::HashSet::bitxor`] /
    /// [`std::collections::BTreeSet::bitxor`] on the stdlib set surface.
    /// Trait-uniform laws pinned in [`tests`]
    /// (`axis_histogram_bitxor_ref_equals_symmetric_difference_*`,
    /// `axis_histogram_bitxor_owned_equals_bitxor_ref_*`).
    fn bitxor(mut self, other: &AxisHistogram<A>) -> Self::Output {
        self ^= other;
        self
    }
}

impl<A: ClosedAxis> std::ops::BitXor<AxisHistogram<A>> for AxisHistogram<A> {
    type Output = AxisHistogram<A>;

    /// Cellwise absolute-difference of `self` and `other` — the
    /// owned-right-hand-side peer of [`BitXor<&Self>`]. Delegates to the
    /// borrowed form so the per-cell `abs_diff` loop lives at exactly
    /// one site (the [`BitXorAssign<&Self>`] impl). Pointwise equal to
    /// [`Self::symmetric_difference`] on every call site.
    fn bitxor(mut self, other: AxisHistogram<A>) -> Self::Output {
        self ^= &other;
        self
    }
}

impl<A: ClosedAxis> std::ops::BitOrAssign<&AxisHistogram<A>> for AxisHistogram<A> {
    /// Cellwise maximum of `self` and `other` in place — the canonical
    /// Rust [`BitOrAssign`][std::ops::BitOrAssign] trait idiom for the
    /// lattice-join (∪) operation on the multiset surface, the in-place
    /// peer of [`Self::pointwise_max`] and the operator-surface lift of
    /// the same per-cell [`Ord::max`] loop. The primitive site that
    /// carries the per-cell loop — every other join surface on this
    /// type ([`BitOrAssign<Self>`], [`BitOr<Self>`], [`BitOr<&Self>`],
    /// and [`Self::pointwise_max`] itself) lowers through this impl so
    /// the per-cell `max` loop lives at exactly one site.
    ///
    /// Promotes the (∪, ∩, ∖, △) set-theoretic operator quartet onto
    /// the stdlib bit-operator surface on the lattice-join arm: the
    /// multiset peer of [`std::collections::HashSet::bitor_assign`] /
    /// [`std::collections::BTreeSet::bitor_assign`] (the `|=` on stdlib
    /// sets), pairing with [`std::ops::BitXorAssign`] (△) on the
    /// symmetric-difference arm and [`std::ops::SubAssign`] (∖) on the
    /// arithmetic monus arm. Closes the join arm of the operator-surface
    /// quartet established by the inherent [`Self::pointwise_max`].
    ///
    /// Before this lift, every consumer reaching the cellwise-max
    /// projection on the in-place surface — a fleet aggregator folding
    /// the next host's per-kind error tally into a rolling high-water
    /// mark on [`crate::ShikumiErrorKind`] without losing the maximum
    /// any single host hit, a per-window observatory maintaining the
    /// running peak observation profile, a regression-detector
    /// envelope computing the pointwise upper bound across snapshots —
    /// reached the projection through the consume-and-rebind
    /// `hist = hist.pointwise_max(&other);` form (the only inherent
    /// shape, which forces a rebind at every call site even when the
    /// histogram lives behind a mutable binding). Collapsed onto the
    /// stdlib bit-operator-assign surface so call sites read `hist |=
    /// &other;` — the canonical Rust idiom every reader already knows
    /// from [`HashSet::bitor_assign`].
    ///
    /// **Equivalence with [`Self::pointwise_max`]** — for every pair
    /// `(self, other)`: `let mut a = self.clone(); a |= other; a` is
    /// pointwise equal to `self.clone().pointwise_max(other)`. The
    /// (`BitOrAssign`, `pointwise_max`) duality on the lattice-join
    /// operator: extending in place is the in-place form of the
    /// owned-join surface. The [`pointwise_max`][Self::pointwise_max]
    /// impl itself lowers through this method so the equivalence is by
    /// construction.
    ///
    /// **Commutativity on the monoid operation** (not on the call site):
    /// `let mut a = x.clone(); a |= &y;` and
    /// `let mut b = y.clone(); b |= &x;` are pointwise equal, by the
    /// commutativity of cellwise [`Ord::max`]. The call sites differ in
    /// which histogram is mutated; the resulting histogram does not.
    /// Peer to the [`BitXorAssign`][std::ops::BitXorAssign] symmetry
    /// law on the symmetric-difference monoid and the
    /// [`AddAssign`][std::ops::AddAssign] commutativity law on the
    /// additive monoid.
    ///
    /// **Empty-right-hand-side identity** — `hist |= &empty` leaves
    /// `hist` unchanged. Every cell of `empty` is zero, so `max(c, 0)
    /// == c` reduces to the original count on every ordinal. The
    /// (empty, max) identity law on the join — `empty` is the bottom
    /// of the lattice. Peer to the [`AddAssign`][std::ops::AddAssign]
    /// and [`BitXorAssign`][std::ops::BitXorAssign] empty-RHS-identity
    /// laws.
    ///
    /// **Idempotent self-join** — `let mut a = hist.clone(); a |= &hist`
    /// leaves `a` pointwise equal to `hist`. The canonical lattice
    /// idempotence law on the join — every cell is its own max with
    /// itself. Peer to the [`BitXorAssign`][std::ops::BitXorAssign]
    /// self-cancellation absorbing law on the symmetric-difference
    /// monoid (which yields `empty` instead — the join is the lattice
    /// idempotent dual of the symmetric-difference involutory).
    ///
    /// **Cell-level max** — every cell `v` satisfies
    /// `after.count(v) == before.count(v).max(other.count(v))`. Peer to
    /// the [`AddAssign`][std::ops::AddAssign] cell-additivity, the
    /// [`SubAssign`][std::ops::SubAssign] cell-saturation, and the
    /// [`BitXorAssign`][std::ops::BitXorAssign] cell-`abs_diff` laws on
    /// the additive / monus / symmetric-difference monoids.
    ///
    /// **Dominance under join** — after `self |= &other`, both
    /// `original_self.is_dominated_by(&self)` and
    /// `other.is_dominated_by(&self)` hold. The defining lattice law
    /// that the join is the least upper bound on the dominance partial
    /// order [`Self::is_dominated_by`].
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor inherits the
    /// projection at no per-axis cost. The trait-uniform laws pinned in
    /// [`tests`] hold across the implementor set
    /// (`axis_histogram_bitor_assign_ref_equals_pointwise_max_*`,
    /// `axis_histogram_bitor_assign_ref_empty_rhs_is_identity_*`,
    /// `axis_histogram_bitor_assign_ref_self_is_identity_*`,
    /// `axis_histogram_bitor_assign_ref_is_commutative_*`,
    /// `axis_histogram_bitor_assign_ref_cell_level_max_*`,
    /// `axis_histogram_bitor_assign_ref_dominates_both_sides_*`,
    /// `axis_histogram_bitor_owned_equals_bitor_ref_*`,
    /// `axis_histogram_bitor_assign_owned_equals_bitor_assign_ref_*`).
    fn bitor_assign(&mut self, other: &AxisHistogram<A>) {
        for (slot, &delta) in self.counts.iter_mut().zip(other.counts.iter()) {
            if delta > *slot {
                *slot = delta;
            }
        }
    }
}

impl<A: ClosedAxis> std::ops::BitOrAssign<AxisHistogram<A>> for AxisHistogram<A> {
    /// Cellwise maximum of `self` and `other` in place — the
    /// owned-right-hand-side peer of [`BitOrAssign<&Self>`]. Delegates
    /// to the borrowed form (the right-hand side is read once, by
    /// reference, then dropped); the per-cell `max` loop lives at
    /// exactly one site (the borrowed-RHS impl).
    fn bitor_assign(&mut self, other: AxisHistogram<A>) {
        *self |= &other;
    }
}

impl<A: ClosedAxis> std::ops::BitOr<&AxisHistogram<A>> for AxisHistogram<A> {
    type Output = AxisHistogram<A>;

    /// Cellwise maximum of `self` and `other` — the canonical Rust
    /// [`BitOr`][std::ops::BitOr] trait idiom for the lattice-join (∪)
    /// operation on the multiset surface, on the borrowed-right-hand-
    /// side surface. The natural infix-operator peer of
    /// [`Self::pointwise_max`] — the same shape consumers reach for
    /// when they want the `|` operator on histograms (`a | &b` instead
    /// of `a.pointwise_max(&b)`).
    ///
    /// Lowered through [`BitOrAssign<&Self>`]: take ownership of
    /// `self`, fold `other` in through `|=`, return the accumulator.
    /// Pointwise equal to [`Self::pointwise_max`] on every call site,
    /// by construction (both lower through `|=` underneath). Peer to
    /// [`std::collections::HashSet::bitor`] /
    /// [`std::collections::BTreeSet::bitor`] on the stdlib set surface.
    /// Trait-uniform laws pinned in [`tests`]
    /// (`axis_histogram_bitor_ref_equals_pointwise_max_*`,
    /// `axis_histogram_bitor_owned_equals_bitor_ref_*`).
    fn bitor(mut self, other: &AxisHistogram<A>) -> Self::Output {
        self |= other;
        self
    }
}

impl<A: ClosedAxis> std::ops::BitOr<AxisHistogram<A>> for AxisHistogram<A> {
    type Output = AxisHistogram<A>;

    /// Cellwise maximum of `self` and `other` — the owned-right-hand-
    /// side peer of [`BitOr<&Self>`]. Delegates to the borrowed form so
    /// the per-cell `max` loop lives at exactly one site (the
    /// [`BitOrAssign<&Self>`] impl). Pointwise equal to
    /// [`Self::pointwise_max`] on every call site.
    fn bitor(mut self, other: AxisHistogram<A>) -> Self::Output {
        self |= &other;
        self
    }
}

impl<A: ClosedAxis> std::ops::BitAndAssign<&AxisHistogram<A>> for AxisHistogram<A> {
    /// Cellwise minimum of `self` and `other` in place — the canonical
    /// Rust [`BitAndAssign`][std::ops::BitAndAssign] trait idiom for
    /// the lattice-meet (∩) operation on the multiset surface, the
    /// in-place peer of [`Self::pointwise_min`] and the operator-surface
    /// lift of the same per-cell [`Ord::min`] loop. The primitive site
    /// that carries the per-cell loop — every other meet surface on
    /// this type ([`BitAndAssign<Self>`], [`BitAnd<Self>`],
    /// [`BitAnd<&Self>`], and [`Self::pointwise_min`] itself) lowers
    /// through this impl so the per-cell `min` loop lives at exactly
    /// one site.
    ///
    /// Closes the meet arm of the (∪, ∩, ∖, △) set-theoretic operator
    /// quartet on the stdlib bit-operator surface: the multiset peer of
    /// [`std::collections::HashSet::bitand_assign`] /
    /// [`std::collections::BTreeSet::bitand_assign`] (the `&=` on
    /// stdlib sets), the lattice dual of [`std::ops::BitOrAssign`] (∪)
    /// on the join arm, pairing with [`std::ops::BitXorAssign`] (△) on
    /// the symmetric-difference arm and [`std::ops::SubAssign`] (∖) on
    /// the arithmetic monus arm. Before this lift,
    /// [`Self::pointwise_min`] was the only entry to the meet — the
    /// consume-and-rebind shape forced a rebind at every call site even
    /// when the histogram lived behind a mutable binding.
    ///
    /// Before this lift, every consumer reaching the cellwise-min
    /// projection on the in-place surface — a fleet aggregator
    /// maintaining the rolling low-water mark on
    /// [`crate::ShikumiErrorKind`] (the per-kind floor every host at
    /// least hit, the common-failure baseline across the fleet), a
    /// per-window observatory carrying the running observation floor
    /// across windows (the count every window at least observed), a
    /// multiset-intersection projection asking *"what observations are
    /// common to every histogram in this stream?"* on a rolling fold —
    /// reached the projection through the consume-and-rebind
    /// `hist = hist.pointwise_min(&other);` form. Collapsed onto the
    /// stdlib bit-operator-assign surface so call sites read `hist &=
    /// &other;` — the canonical Rust idiom every reader already knows
    /// from [`HashSet::bitand_assign`].
    ///
    /// **Equivalence with [`Self::pointwise_min`]** — for every pair
    /// `(self, other)`: `let mut a = self.clone(); a &= other; a` is
    /// pointwise equal to `self.clone().pointwise_min(other)`. The
    /// (`BitAndAssign`, `pointwise_min`) duality on the lattice-meet
    /// operator: intersecting in place is the in-place form of the
    /// owned-meet surface. The [`pointwise_min`][Self::pointwise_min]
    /// impl itself lowers through this method so the equivalence is by
    /// construction.
    ///
    /// **Commutativity on the monoid operation** (not on the call site):
    /// `let mut a = x.clone(); a &= &y;` and
    /// `let mut b = y.clone(); b &= &x;` are pointwise equal, by the
    /// commutativity of cellwise [`Ord::min`]. The call sites differ in
    /// which histogram is mutated; the resulting histogram does not.
    /// Peer to the [`BitOrAssign`][std::ops::BitOrAssign] commutativity
    /// law on the lattice-join monoid and the
    /// [`AddAssign`][std::ops::AddAssign] commutativity law on the
    /// additive monoid.
    ///
    /// **Empty-right-hand-side absorbing** — `hist &= &empty` zeros
    /// every cell of `hist`. Every cell of `empty` is zero, so `min(c,
    /// 0) == 0` reduces every cell to zero. The (empty, min) absorbing
    /// law on the meet — `empty` is the bottom of the lattice, dual to
    /// the (empty, max) identity law on the
    /// [`BitOrAssign`][std::ops::BitOrAssign] join side: where `empty`
    /// is the right-identity on the join, it is the right-absorber on
    /// the meet.
    ///
    /// **Idempotent self-meet** — `let mut a = hist.clone(); a &= &hist`
    /// leaves `a` pointwise equal to `hist`. The canonical lattice
    /// idempotence law on the meet — every cell is its own min with
    /// itself. Peer to the [`BitOrAssign`][std::ops::BitOrAssign]
    /// self-idempotence on the join (which also leaves the histogram
    /// unchanged — the lattice has both join-idempotence and
    /// meet-idempotence as the defining lattice laws).
    ///
    /// **Cell-level min** — every cell `v` satisfies
    /// `after.count(v) == before.count(v).min(other.count(v))`. Peer
    /// to the [`BitOrAssign`][std::ops::BitOrAssign] cell-level max,
    /// the [`AddAssign`][std::ops::AddAssign] cell-additivity, the
    /// [`SubAssign`][std::ops::SubAssign] cell-saturation, and the
    /// [`BitXorAssign`][std::ops::BitXorAssign] cell-`abs_diff` laws on
    /// the join / additive / monus / symmetric-difference monoids.
    ///
    /// **Dominance under meet** — after `self &= &other`, both
    /// `self.is_dominated_by(&original_self)` and
    /// `self.is_dominated_by(&other)` hold. The defining lattice law
    /// that the meet is the greatest lower bound on the dominance
    /// partial order [`Self::is_dominated_by`] — dual to the
    /// [`BitOrAssign`][std::ops::BitOrAssign] join-is-least-upper-bound
    /// law.
    ///
    /// **Lattice / additive decomposition** — for every pair `(a, b)`:
    /// `(a.clone() | &b) + &(a.clone() & &b) == a + &b` pointwise. The
    /// canonical max-min/addition identity `max(x, y) + min(x, y) ==
    /// x + y` reads off on the operator surface; pinned together with
    /// the [`BitOrAssign`][std::ops::BitOrAssign] lift through the
    /// trait-uniform laws.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor inherits the
    /// projection at no per-axis cost. The trait-uniform laws pinned in
    /// [`tests`] hold across the implementor set
    /// (`axis_histogram_bitand_assign_ref_equals_pointwise_min_*`,
    /// `axis_histogram_bitand_assign_ref_empty_rhs_is_empty_*`,
    /// `axis_histogram_bitand_assign_ref_self_is_identity_*`,
    /// `axis_histogram_bitand_assign_ref_is_commutative_*`,
    /// `axis_histogram_bitand_assign_ref_cell_level_min_*`,
    /// `axis_histogram_bitand_assign_ref_dominated_by_both_sides_*`,
    /// `axis_histogram_bitor_plus_bitand_equals_add_*`,
    /// `axis_histogram_bitand_owned_equals_bitand_ref_*`,
    /// `axis_histogram_bitand_assign_owned_equals_bitand_assign_ref_*`).
    fn bitand_assign(&mut self, other: &AxisHistogram<A>) {
        for (slot, &delta) in self.counts.iter_mut().zip(other.counts.iter()) {
            if delta < *slot {
                *slot = delta;
            }
        }
    }
}

impl<A: ClosedAxis> std::ops::BitAndAssign<AxisHistogram<A>> for AxisHistogram<A> {
    /// Cellwise minimum of `self` and `other` in place — the
    /// owned-right-hand-side peer of [`BitAndAssign<&Self>`]. Delegates
    /// to the borrowed form (the right-hand side is read once, by
    /// reference, then dropped); the per-cell `min` loop lives at
    /// exactly one site (the borrowed-RHS impl).
    fn bitand_assign(&mut self, other: AxisHistogram<A>) {
        *self &= &other;
    }
}

impl<A: ClosedAxis> std::ops::BitAnd<&AxisHistogram<A>> for AxisHistogram<A> {
    type Output = AxisHistogram<A>;

    /// Cellwise minimum of `self` and `other` — the canonical Rust
    /// [`BitAnd`][std::ops::BitAnd] trait idiom for the lattice-meet
    /// (∩) operation on the multiset surface, on the borrowed-right-
    /// hand-side surface. The natural infix-operator peer of
    /// [`Self::pointwise_min`] — the same shape consumers reach for
    /// when they want the `&` operator on histograms (`a & &b` instead
    /// of `a.pointwise_min(&b)`).
    ///
    /// Lowered through [`BitAndAssign<&Self>`]: take ownership of
    /// `self`, fold `other` in through `&=`, return the accumulator.
    /// Pointwise equal to [`Self::pointwise_min`] on every call site,
    /// by construction (both lower through `&=` underneath). Peer to
    /// [`std::collections::HashSet::bitand`] /
    /// [`std::collections::BTreeSet::bitand`] on the stdlib set surface.
    /// Trait-uniform laws pinned in [`tests`]
    /// (`axis_histogram_bitand_ref_equals_pointwise_min_*`,
    /// `axis_histogram_bitand_owned_equals_bitand_ref_*`).
    fn bitand(mut self, other: &AxisHistogram<A>) -> Self::Output {
        self &= other;
        self
    }
}

impl<A: ClosedAxis> std::ops::BitAnd<AxisHistogram<A>> for AxisHistogram<A> {
    type Output = AxisHistogram<A>;

    /// Cellwise minimum of `self` and `other` — the owned-right-hand-
    /// side peer of [`BitAnd<&Self>`]. Delegates to the borrowed form so
    /// the per-cell `min` loop lives at exactly one site (the
    /// [`BitAndAssign<&Self>`] impl). Pointwise equal to
    /// [`Self::pointwise_min`] on every call site.
    fn bitand(mut self, other: AxisHistogram<A>) -> Self::Output {
        self &= &other;
        self
    }
}

impl<A: ClosedAxis> std::ops::MulAssign<usize> for AxisHistogram<A> {
    /// Scale every cell in place by `factor` — the canonical Rust
    /// [`MulAssign`][std::ops::MulAssign] trait idiom for the scalar
    /// action of `(usize, *, 1)` on the additive monoid
    /// `(AxisHistogram, +, empty)`. Promotes the additive monoid
    /// quartet ([`Add<Self>`][std::ops::Add],
    /// [`Add<&Self>`][std::ops::Add],
    /// [`AddAssign<Self>`][std::ops::AddAssign],
    /// [`AddAssign<&Self>`][std::ops::AddAssign]) to a commutative
    /// monoid with [`usize`]-action — a free `(usize, +, *)`-semimodule
    /// indexed by [`ClosedAxis::ALL`]. The primitive site that carries
    /// the per-cell scalar-multiplication loop; every other
    /// scalar-action surface on this type ([`Mul<usize>`]) lowers
    /// through this impl so the per-cell loop lives at exactly one
    /// site.
    ///
    /// Before this lift, every consumer reaching the (scale every cell
    /// by N) projection (a fleet-wide aggregator weighting a per-host
    /// `AxisHistogram<crate::WatchEventClass>` cell by the host's
    /// reload-count multiplier before folding into the fleet cell, a
    /// per-tier observatory amplifying a per-tier
    /// `AxisHistogram<crate::ConfigSourceKind>` cell by a tier-weighting
    /// factor in a weighted cross-tier rollup, a rolling-window
    /// projection asking *"what if we observed this window N times in
    /// a row?"* on a per-window
    /// `AxisHistogram<crate::ShikumiErrorKind>` cell, a `(cell, weight)`
    /// table reduction folding a uniform multiplier through a histogram
    /// before rendering a weighted-coverage attestation) reached it
    /// through one of two forms — the open-coded per-cell loop
    /// `for (c, n) in hist.iter() { for _ in 0..n*factor {
    /// scaled.observe(c); } }` (which re-expands every individual
    /// observation `total * factor` times, O(total*factor)) or the
    /// repeated-`+=`-by-self form `for _ in 0..factor { acc += &hist; }`
    /// (which walks the counts vector `factor` times and is O(factor *
    /// axis_cardinality)). Collapsed to one trait-method call with a
    /// single-pass O(axis_cardinality) scan that multiplies every cell
    /// directly on the existing counts vector. The lift names the
    /// (existing-histogram, scalar factor → in-place scale) projection
    /// at one site, consumers route through `hist *= factor;`
    /// uniformly, and the per-cell loop lives at exactly one site (this
    /// impl) underneath every scalar-action operator entry surface.
    ///
    /// **Zero-factor absorbing law** — `hist *= 0` zeros every cell of
    /// the histogram, equal pointwise to [`AxisHistogram::empty`]. The
    /// absorbing element of the scalar monoid `(usize, *, 1)` zeros the
    /// counts vector; the resulting histogram has [`Self::total`] =
    /// `0`, [`Self::is_empty`] = `true`, [`Self::distinct_cells`] =
    /// `0`, [`Self::unobserved_cells`] =
    /// [`axis_cardinality::<A>()`][axis_cardinality]. Peer to the
    /// [`AddAssign`][std::ops::AddAssign] empty-RHS-identity law on the
    /// dual side of the monoid.
    ///
    /// **One-factor identity law** — `hist *= 1` leaves the histogram
    /// unchanged. The identity element of the scalar monoid
    /// `(usize, *, 1)` preserves the counts vector pointwise; the
    /// resulting histogram is pointwise equal to the input.
    ///
    /// **Total-scaling law** — `hist *= factor` scales the total by
    /// exactly `factor`: `before.total() * factor == after.total()`,
    /// peer to the [`AddAssign`] additivity law (`before.total() +
    /// rhs.total() == after.total()`) on the dual side of the monoid.
    /// The two scalar surfaces of the histogram now carry a complete
    /// monoid-with-scalar-action algebra at the [`Self::total`]
    /// projection.
    ///
    /// **Cell-level scaling** — every cell `v` is multiplied by
    /// `factor`: `before.count(v) * factor == after.count(v)`. Peer to
    /// the [`AddAssign`] cell-additivity law on the dual side of the
    /// monoid.
    ///
    /// **Support preservation under non-zero factor** — `hist *=
    /// factor` with `factor > 0` preserves the support: the set of
    /// observed cells is unchanged (`before.distinct_cells() ==
    /// after.distinct_cells()`, `before.observed().collect::<HashSet<_>>()
    /// == after.observed().collect::<HashSet<_>>()`). Multiplying a
    /// zero count by a non-zero factor stays zero; multiplying a
    /// positive count by a positive factor stays positive. Only the
    /// zero-factor case collapses the support (to the empty set, per
    /// the absorbing law).
    ///
    /// **Distributivity over [`AddAssign`]** — scaling distributes
    /// over the additive monoid: `let mut a = lhs.clone(); a += &rhs;
    /// a *= factor; a` is pointwise equal to `let mut a = lhs.clone();
    /// a *= factor; let mut b = rhs.clone(); b *= factor; a += &b; a`.
    /// The canonical semimodule distributivity law — scaling commutes
    /// with cellwise addition because each cell carries the same
    /// `(usize, +, *)` distributive law. Pinned by
    /// [`tests::axis_histogram_mul_assign_distributes_over_add_assign_for_every_closed_axis_implementor`].
    ///
    /// **Equivalence with repeated `+=`** — `hist *= factor` is
    /// pointwise equal to summing `factor` copies of the input:
    /// `let mut acc = AxisHistogram::empty(); for _ in 0..factor {
    /// acc += &hist; } acc` reads the same histogram. The
    /// scalar-action / repeated-addition equivalence — the natural
    /// lowering of "scale by N" through "add N times" on the dual
    /// side of the monoid.
    ///
    /// **Overflow behavior** — inherits the underlying [`usize`]
    /// arithmetic: debug builds panic on overflow, release builds wrap
    /// silently. Consistent with the [`AddAssign`] impl (which carries
    /// the same `usize`-arithmetic-inherited overflow contract).
    /// Trait-uniform fleet aggregators reaching saturating /
    /// checked-multiplication semantics layer the projection at the
    /// call site; the primitive site names the natural cellwise `*=`.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor inherits the
    /// projection at no per-axis cost. The trait-uniform laws pinned
    /// in [`tests`] hold across the implementor set
    /// (`axis_histogram_mul_assign_zero_factor_zeros_histogram_*`,
    /// `axis_histogram_mul_assign_one_factor_is_identity_*`,
    /// `axis_histogram_mul_assign_scales_total_*`,
    /// `axis_histogram_mul_assign_scales_cells_*`,
    /// `axis_histogram_mul_assign_distributes_over_add_assign_*`,
    /// `axis_histogram_mul_assign_equals_repeated_add_assign_*`).
    fn mul_assign(&mut self, factor: usize) {
        for slot in &mut self.counts {
            *slot *= factor;
        }
    }
}

impl<A: ClosedAxis> std::ops::Mul<usize> for AxisHistogram<A> {
    type Output = AxisHistogram<A>;

    /// Pointwise scale of `self` by `factor` — the canonical Rust
    /// [`Mul`][std::ops::Mul] trait idiom for the scalar action of
    /// `(usize, *, 1)` on the additive monoid `(AxisHistogram, +,
    /// empty)`. The natural infix-operator peer of [`MulAssign<usize>`]
    /// — the same shape consumers reach for when they want the `*`
    /// operator on histograms (`a * 3` instead of `let mut a = a; a *=
    /// 3; a`), and the canonical Rust scalar-action operator-surface
    /// peer of [`Duration::mul`][std::time::Duration] /
    /// [`Duration::MulAssign`][std::time::Duration] on the duration
    /// side of the typescape.
    ///
    /// Lowered through [`MulAssign<usize>`]: take ownership of `self`,
    /// scale every cell through `*=`, return the accumulator. Pointwise
    /// equal to `MulAssign<usize>` on every call site, by construction
    /// (both lower through `*=` underneath). The per-cell scalar-
    /// multiplication loop lives at exactly one site (the
    /// [`MulAssign<usize>`] impl above).
    ///
    /// **Equivalence with [`MulAssign<usize>`]** — for every `(self,
    /// factor)`: `self.clone() * factor` is pointwise equal to
    /// `let mut a = self.clone(); a *= factor; a`. The (`Mul`,
    /// `MulAssign`) duality on the scalar-action surface, peer to the
    /// (`Add`, `AddAssign`) duality on the additive monoid surface.
    /// Pinned by
    /// [`tests::axis_histogram_mul_equals_mul_assign_for_every_closed_axis_implementor`].
    ///
    /// **Zero-factor absorbing law** — `hist * 0` equals
    /// [`AxisHistogram::empty`] pointwise. Inherits the absorbing law
    /// from [`MulAssign<usize>`].
    ///
    /// **One-factor identity law** — `hist * 1` is pointwise equal to
    /// `hist`. Inherits the identity law from [`MulAssign<usize>`].
    ///
    /// **Distributivity over [`Add`][std::ops::Add]** — scaling
    /// distributes over the additive monoid on the infix-operator
    /// surface: `(a + &b) * n` is pointwise equal to `a * n + &(b *
    /// n)`. Peer to the [`MulAssign`]-distributes-over-[`AddAssign`]
    /// law on the in-place surface. Pinned by
    /// [`tests::axis_histogram_mul_distributes_over_add_for_diff_line_kind`].
    ///
    /// Trait-uniform laws reach every [`ClosedAxis`] implementor
    /// through `for_each_closed_axis_implementor!` in [`tests`]
    /// (`axis_histogram_mul_equals_mul_assign_*`,
    /// `axis_histogram_mul_zero_factor_yields_empty_*`,
    /// `axis_histogram_mul_one_factor_is_identity_*`).
    fn mul(mut self, factor: usize) -> Self::Output {
        self *= factor;
        self
    }
}

impl<A: ClosedAxis> std::ops::DivAssign<usize> for AxisHistogram<A> {
    /// Truncating per-cell division in place by `divisor` — the
    /// canonical Rust [`DivAssign`][std::ops::DivAssign] trait idiom
    /// for the truncating-integer-division scalar peer of
    /// [`MulAssign<usize>`][std::ops::MulAssign] on the additive monoid
    /// `(AxisHistogram, +, empty)`. Closes the canonical
    /// `(Mul, MulAssign, Div, DivAssign)` scalar-action operator
    /// quartet every primitive that carries a [`usize`]-action on a
    /// numeric surface exposes: [`std::time::Duration`] carries both
    /// `Duration * u32` / `*=` and `Duration / u32` / `/=` for exactly
    /// the same reason — the multiplicative pair on one side, the
    /// truncating-division pair on the other. The primitive site that
    /// carries the per-cell scalar-division loop; the [`Div<usize>`]
    /// surface below lowers through this impl so the per-cell loop
    /// lives at exactly one site.
    ///
    /// **Semantics — truncating integer division.** Each cell `c` is
    /// replaced by `c / divisor` under stdlib [`usize`]-arithmetic
    /// (truncating toward zero, since both operands are non-negative).
    /// The operation is **not** distributive over [`AddAssign`]
    /// pointwise — `(a + &b) / n` may disagree with `a / n + &(b / n)`
    /// when cells cross a divisor boundary (`(1 + 2) / 2 = 1` but
    /// `1 / 2 + 2 / 2 = 0 + 1 = 1` agrees here, while `(1 + 1) / 2 = 1`
    /// disagrees with `1 / 2 + 1 / 2 = 0 + 0 = 0`). The trait-uniform
    /// laws below carry only the laws that hold under truncation; the
    /// distributivity story lives on the [`MulAssign<usize>`] side of
    /// the operator pair where it is exact.
    ///
    /// **One-divisor identity law** — `hist /= 1` leaves the histogram
    /// unchanged. The identity element of the scalar monoid
    /// `(usize, *, 1)` preserves the counts vector pointwise on the
    /// truncating-division surface (every cell `c` satisfies
    /// `c / 1 == c`). Peer to the one-factor identity law on the
    /// [`MulAssign<usize>`] surface.
    ///
    /// **Cell-level truncating-division law** — every cell `v` has its
    /// count replaced by the truncating division
    /// `before.count(v) / divisor`: `(hist /= divisor); hist.count(v)`
    /// reads `before.count(v) / divisor` for every cell. Peer to the
    /// cell-level scaling law on [`MulAssign<usize>`] (which reads
    /// `before.count(v) * factor`) on the truncating-division surface.
    ///
    /// **Mul-Div round-trip law on non-zero factor** — `hist *= factor;
    /// hist /= factor;` recovers `hist` pointwise when `factor > 0` and
    /// no per-cell multiplication overflowed: every cell `c` satisfies
    /// `(c * factor) / factor == c` under [`usize`] arithmetic for
    /// `factor > 0`. The canonical mul-then-div round-trip identity on
    /// the scalar-action surface; the truncating-division step recovers
    /// the original count because the multiplication is exact (no
    /// fractional remainder to lose). Pinned by the trait-uniform test
    /// `axis_histogram_div_assign_inverts_mul_assign_on_uniform_cover_for_every_closed_axis_implementor`.
    ///
    /// **Total under truncation** — the resulting total is bounded
    /// above by `before.total() / divisor` and bounded below by the sum
    /// of per-cell truncating divisions; the inequality is exact only
    /// when no cell crosses a divisor boundary. Pinned concretely on
    /// [`DiffLineKind`] by the
    /// `axis_histogram_div_witnessed_on_non_trivial_cells_for_diff_line_kind`
    /// test.
    ///
    /// # Panics
    ///
    /// Panics on `divisor == 0`, inherited from the stdlib
    /// `usize::div(0)` panic at every cell (the underlying `/=`
    /// operation panics on the first cell). Consistent with the
    /// [`MulAssign`] impl, which inherits the same overflow contract
    /// from [`usize`] arithmetic: overflow / divide-by-zero semantics
    /// are inherited from the cell type, not re-derived on the
    /// histogram surface.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor inherits the
    /// projection at no per-axis cost. The trait-uniform laws pinned
    /// in [`tests`] hold across the implementor set
    /// (`axis_histogram_div_assign_one_divisor_is_identity_*`,
    /// `axis_histogram_div_assign_scales_cells_by_truncating_division_*`,
    /// `axis_histogram_div_assign_inverts_mul_assign_on_uniform_cover_*`).
    fn div_assign(&mut self, divisor: usize) {
        for slot in &mut self.counts {
            *slot /= divisor;
        }
    }
}

impl<A: ClosedAxis> std::ops::Div<usize> for AxisHistogram<A> {
    type Output = AxisHistogram<A>;

    /// Truncating per-cell division of `self` by `divisor` — the
    /// canonical Rust [`Div`][std::ops::Div] trait idiom and the
    /// natural infix-operator peer of
    /// [`DivAssign<usize>`][std::ops::DivAssign]. Lowered through
    /// [`DivAssign<usize>`]: take ownership of `self`, divide every
    /// cell through `/=`, return the accumulator. Pointwise equal to
    /// `DivAssign<usize>` on every call site, by construction (both
    /// lower through `/=` underneath). The per-cell scalar-division
    /// loop lives at exactly one site (the [`DivAssign<usize>`] impl
    /// above).
    ///
    /// Closes the canonical Rust `(Mul, MulAssign, Div, DivAssign)`
    /// scalar-action operator quartet every primitive that carries a
    /// [`usize`]-action on a numeric surface exposes
    /// ([`std::time::Duration`] carries the same quartet for the same
    /// reason — the multiplicative pair on one side, the
    /// truncating-division pair on the other). Every shikumi consumer
    /// reaching the per-cell truncating-division surface (a
    /// rolling-window observatory averaging
    /// `AxisHistogram<crate::WatchEventClass>` cells across `N`
    /// windows by `summed / N` to read off the per-window mean, a
    /// fleet aggregator normalizing
    /// `AxisHistogram<crate::ConfigSourceKind>` cells against a host
    /// count via `fleet_hist / host_count` for per-host cell shares, a
    /// per-tier observatory de-amplifying a previously-weighted
    /// `AxisHistogram<crate::ShikumiErrorKind>` cell by the same
    /// weighting factor) now routes through `hist / divisor` uniformly
    /// instead of the open-coded per-cell map
    /// `for (c, n) in hist.iter() { for _ in 0..(n / divisor) {
    /// dst.observe(c); } }` or the rebuild-via-`FromIterator<(A,
    /// usize)>` form `hist.iter().map(|(c, n)| (c, n /
    /// divisor)).collect()`.
    ///
    /// **Equivalence with [`DivAssign<usize>`]** — for every `(self,
    /// divisor)` with `divisor > 0`: `self.clone() / divisor` is
    /// pointwise equal to `let mut a = self.clone(); a /= divisor; a`.
    /// The (`Div`, `DivAssign`) duality on the scalar-action surface,
    /// peer to the (`Mul`, `MulAssign`) duality on the multiplicative
    /// side and the (`Add`, `AddAssign`) duality on the additive
    /// monoid surface. Pinned by
    /// [`tests::axis_histogram_div_equals_div_assign_for_every_closed_axis_implementor`].
    ///
    /// **One-divisor identity law** — `hist / 1` is pointwise equal
    /// to `hist`. Inherits the identity law from
    /// [`DivAssign<usize>`].
    ///
    /// **Mul-Div round-trip law on non-zero factor** — `(hist *
    /// factor) / factor == hist` when `factor > 0` and no per-cell
    /// multiplication overflowed. Inherits from
    /// [`DivAssign<usize>`].
    ///
    /// # Panics
    ///
    /// Panics on `divisor == 0`. Inherits the panic contract from
    /// [`DivAssign<usize>`].
    ///
    /// Trait-uniform laws reach every [`ClosedAxis`] implementor
    /// through `for_each_closed_axis_implementor!` in [`tests`]
    /// (`axis_histogram_div_equals_div_assign_*`,
    /// `axis_histogram_div_one_divisor_is_identity_*`).
    fn div(mut self, divisor: usize) -> Self::Output {
        self /= divisor;
        self
    }
}

impl<A: ClosedAxis> std::ops::RemAssign<usize> for AxisHistogram<A> {
    /// Truncating per-cell remainder in place by `divisor` — the
    /// canonical Rust [`RemAssign`][std::ops::RemAssign] trait idiom
    /// for the Euclidean-remainder peer of
    /// [`DivAssign<usize>`][std::ops::DivAssign] on the additive monoid
    /// `(AxisHistogram, +, empty)`. Closes the canonical
    /// `(Mul, MulAssign, Div, DivAssign, Rem, RemAssign)` integer-
    /// arithmetic operator sextet every primitive that carries a
    /// [`usize`]-action on a numeric surface exposes ([`usize`],
    /// [`u32`], [`i32`], …): the multiplicative pair, the truncating-
    /// division pair, and the Euclidean-remainder pair compose into one
    /// integer-arithmetic operator surface. The primitive site that
    /// carries the per-cell scalar-remainder loop; the [`Rem<usize>`]
    /// surface below lowers through this impl so the per-cell loop
    /// lives at exactly one site.
    ///
    /// **Semantics — Euclidean remainder.** Each cell `c` is replaced
    /// by `c % divisor` under stdlib [`usize`]-arithmetic. Cells with
    /// `c < divisor` are preserved; cells with `c >= divisor` lose the
    /// `(c / divisor) * divisor` multiple and retain the
    /// `c - (c / divisor) * divisor` remainder.
    ///
    /// **One-divisor zero law** — `hist %= 1` zeros every cell of the
    /// histogram, equal pointwise to [`AxisHistogram::empty`]. The
    /// identity element of the scalar monoid `(usize, *, 1)` is the
    /// absorbing element of the remainder monoid `(usize, %, _)`:
    /// every cell `c` satisfies `c % 1 == 0`. Peer to the zero-factor
    /// absorbing law on the [`MulAssign<usize>`] surface and dual to
    /// the one-divisor identity law on the [`DivAssign<usize>`]
    /// surface.
    ///
    /// **Cell-level remainder law** — every cell `v` has its count
    /// replaced by the stdlib usize Euclidean-remainder
    /// `before.count(v) % divisor`: `(hist %= divisor); hist.count(v)`
    /// reads `before.count(v) % divisor` for every cell. Peer to the
    /// cell-level truncating-division law on [`DivAssign<usize>`] and
    /// the cell-level scaling law on [`MulAssign<usize>`].
    ///
    /// **Div-Rem identity law** — `(hist / divisor) * divisor + (hist %
    /// divisor) == hist` for `divisor > 0`. The canonical defining
    /// equation of the Euclidean-division pair lifted from the cell
    /// type to the histogram surface: every cell `c` satisfies
    /// `(c / divisor) * divisor + (c % divisor) == c` under [`usize`]
    /// arithmetic, and the lift through the additive monoid agrees
    /// pointwise. Pinned by the trait-uniform test
    /// `axis_histogram_rem_assign_completes_div_rem_identity_for_every_closed_axis_implementor`.
    ///
    /// **Remainder bound** — every cell `v` satisfies
    /// `(hist %= divisor).count(v) < divisor` for `divisor > 0`. The
    /// canonical Euclidean-remainder bound lifted pointwise. Pinned by
    /// the trait-uniform test
    /// `axis_histogram_rem_assign_bounds_cells_below_divisor_for_every_closed_axis_implementor`.
    ///
    /// # Panics
    ///
    /// Panics on `divisor == 0`, inherited from the stdlib
    /// `usize::rem(0)` panic at every cell (the underlying `%=`
    /// operation panics on the first cell). Consistent with the
    /// [`DivAssign<usize>`] impl, which inherits the same overflow
    /// contract from [`usize`] arithmetic: overflow / divide-by-zero
    /// semantics are inherited from the cell type, not re-derived on
    /// the histogram surface.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor inherits the
    /// projection at no per-axis cost. The trait-uniform laws pinned
    /// in [`tests`] hold across the implementor set
    /// (`axis_histogram_rem_assign_one_divisor_zeros_histogram_*`,
    /// `axis_histogram_rem_assign_scales_cells_by_remainder_*`,
    /// `axis_histogram_rem_assign_completes_div_rem_identity_*`,
    /// `axis_histogram_rem_assign_bounds_cells_below_divisor_*`).
    fn rem_assign(&mut self, divisor: usize) {
        for slot in &mut self.counts {
            *slot %= divisor;
        }
    }
}

impl<A: ClosedAxis> std::ops::Rem<usize> for AxisHistogram<A> {
    type Output = AxisHistogram<A>;

    /// Truncating per-cell remainder of `self` by `divisor` — the
    /// canonical Rust [`Rem`][std::ops::Rem] trait idiom and the
    /// natural infix-operator peer of
    /// [`RemAssign<usize>`][std::ops::RemAssign]. Lowered through
    /// [`RemAssign<usize>`]: take ownership of `self`, reduce every
    /// cell through `%=`, return the accumulator. Pointwise equal to
    /// `RemAssign<usize>` on every call site, by construction (both
    /// lower through `%=` underneath). The per-cell scalar-remainder
    /// loop lives at exactly one site (the [`RemAssign<usize>`] impl
    /// above).
    ///
    /// Closes the canonical Rust `(Mul, MulAssign, Div, DivAssign,
    /// Rem, RemAssign)` integer-arithmetic operator sextet every
    /// primitive that carries a [`usize`]-action on a numeric surface
    /// exposes (the same sextet [`usize`], [`u32`], [`i32`] carry at
    /// the cell level — multiplicative pair, truncating-division pair,
    /// Euclidean-remainder pair). Every shikumi consumer reaching the
    /// per-cell remainder surface (a fleet aggregator computing
    /// `hist - (hist / window) * window` to read off the
    /// rolling-window residual across an
    /// `AxisHistogram<crate::ConfigSourceKind>` cell, a per-tier
    /// observatory partitioning an
    /// `AxisHistogram<crate::WatchEventClass>` cell into bucket-
    /// multiples and bucket-residuals against a per-tier bucket size)
    /// now routes through `hist % divisor` uniformly instead of the
    /// open-coded `hist - (hist.clone() / divisor) * divisor` rebuild
    /// or the per-cell-map form
    /// `hist.iter().map(|(c, n)| (c, n % divisor)).collect()`.
    ///
    /// **Equivalence with [`RemAssign<usize>`]** — for every `(self,
    /// divisor)` with `divisor > 0`: `self.clone() % divisor` is
    /// pointwise equal to `let mut a = self.clone(); a %= divisor;
    /// a`. The (`Rem`, `RemAssign`) duality on the Euclidean-remainder
    /// surface, peer to the (`Div`, `DivAssign`) duality on the
    /// truncating-division side and the (`Mul`, `MulAssign`) duality
    /// on the multiplicative side. Pinned by
    /// [`tests::axis_histogram_rem_equals_rem_assign_for_every_closed_axis_implementor`].
    ///
    /// **One-divisor zero law** — `hist % 1` is pointwise equal to
    /// [`AxisHistogram::empty`]. Inherits the absorbing law from
    /// [`RemAssign<usize>`].
    ///
    /// **Div-Rem identity law** — `(hist / divisor) * divisor + (hist
    /// % divisor) == hist` for `divisor > 0`. Inherits from
    /// [`RemAssign<usize>`].
    ///
    /// # Panics
    ///
    /// Panics on `divisor == 0`. Inherits the panic contract from
    /// [`RemAssign<usize>`].
    ///
    /// Trait-uniform laws reach every [`ClosedAxis`] implementor
    /// through `for_each_closed_axis_implementor!` in [`tests`]
    /// (`axis_histogram_rem_equals_rem_assign_*`,
    /// `axis_histogram_rem_one_divisor_zeros_histogram_*`).
    fn rem(mut self, divisor: usize) -> Self::Output {
        self %= divisor;
        self
    }
}

impl<A: ClosedAxis> std::ops::Mul<AxisHistogram<A>> for usize {
    type Output = AxisHistogram<A>;

    /// Left-scalar peer of [`Mul<usize> for AxisHistogram<A>`][Mul] —
    /// `n * hist` reads the same histogram as `hist * n`. Closes the
    /// canonical Rust commutative-scalar-multiplication operator pair
    /// every primitive that carries a [`usize`]-action on a numeric
    /// surface exposes ([`std::time::Duration`] carries both
    /// `Duration * u32` and `u32 * Duration` for the same reason, peer
    /// to the right-scalar / left-scalar pair on the `(usize, +, *)`
    /// semiring acting on the additive monoid `(AxisHistogram, +,
    /// empty)`). The left-scalar entry surface delegates to the
    /// right-scalar form so the per-cell scalar-multiplication loop
    /// lives at exactly one site (the [`MulAssign<usize>`][MulAssign]
    /// impl above); no per-cell traversal lives on this surface.
    ///
    /// Before this lift, every consumer wanting the left-scalar shape
    /// (a fleet aggregator reading `weight * host_hist` to match the
    /// natural English shape *"weight times the host's histogram"*; a
    /// dashboard column reading `multiplier * counts` to mirror the
    /// algebraic-textbook left-side scalar; a per-row weighted-mean
    /// projection on a `Vec<(usize, AxisHistogram<A>)>` folding
    /// through `acc += weight * hist` where the left-scalar reads in
    /// declaration order) had to rewrite to the right-scalar form
    /// `hist * weight` against the natural shape of the call site, or
    /// open-code a `let scaled = hist.clone() * weight; scaled` rebind
    /// against a non-mutable receiver. The lift names the projection
    /// at one site, consumers route through `n * hist` uniformly, and
    /// the per-cell loop lives at exactly one site underneath every
    /// scalar-action operator entry surface (right-scalar `*`,
    /// left-scalar `*`, in-place `*=`).
    ///
    /// **Commutativity law** — `n * hist` is pointwise equal to
    /// `hist * n` for every `(n, hist)`. The canonical
    /// commutative-scalar-multiplication identity on a [`usize`]-action
    /// surface; pinned by the trait-uniform test
    /// `axis_histogram_mul_left_factor_equals_mul_right_factor_for_every_closed_axis_implementor`
    /// in [`tests`]. Inherits every law the right-scalar surface
    /// carries — the zero-factor absorbing law (`0 * hist == empty`),
    /// the one-factor identity law (`1 * hist == hist`), the
    /// total-scaling law (`(n * hist).total() == n * hist.total()`),
    /// the cell-level scaling law
    /// (`(n * hist).count(v) == n * hist.count(v)`), the support
    /// preservation under non-zero factor, the distributivity over the
    /// additive monoid (`n * (a + &b) == n * a + &(n * b)`), and the
    /// equivalence with repeated `+=` — by the commutativity
    /// equivalence at one site.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor inherits the
    /// projection at no per-axis cost. The trait-uniform commutativity
    /// law pinned in [`tests`] holds across the implementor set
    /// (`axis_histogram_mul_left_factor_equals_mul_right_factor_*`).
    ///
    /// [Mul]: std::ops::Mul
    /// [MulAssign]: std::ops::MulAssign
    fn mul(self, hist: AxisHistogram<A>) -> Self::Output {
        hist * self
    }
}

impl<A: ClosedAxis> std::ops::Mul<&AxisHistogram<A>> for usize {
    type Output = AxisHistogram<A>;

    /// Borrowed-RHS peer of [`Mul<AxisHistogram<A>> for usize`][Mul] —
    /// `n * &hist` reads the same histogram as `n * hist.clone()` but
    /// keeps the caller's ownership of `hist`. Closes the canonical
    /// Rust (owned-RHS, borrowed-RHS) idiom-peer pair on the
    /// left-scalar entry surface, mirroring the
    /// [`Add<AxisHistogram<A>>`][Add] / [`Add<&AxisHistogram<A>>`][Add]
    /// pair on the additive monoid: same projection, two RHS-ownership
    /// shapes, both lowering through the right-scalar
    /// [`Mul<usize> for AxisHistogram<A>`][Mul] form at one site (which
    /// itself lowers through [`MulAssign<usize>`][MulAssign] — the
    /// single primitive site that carries the per-cell loop). The
    /// borrowed-RHS entry surface delegates through one clone to the
    /// owned-RHS left-scalar form so the four scalar-action entry
    /// surfaces on the `*` operator surface — right-scalar `hist * n`,
    /// in-place `hist *= n`, left-scalar `n * hist`, and now
    /// borrowed-RHS left-scalar `n * &hist` — all route through
    /// exactly one per-cell traversal site.
    ///
    /// Before this lift, every consumer wanting the left-scalar shape
    /// against a borrowed histogram (a fleet aggregator reading
    /// `weight * &host_hist` over a `&BTreeMap<HostId,
    /// AxisHistogram<A>>` it does not own; a per-tier observatory
    /// reading `multiplier * &cached_hist` against an
    /// [`arc_swap::Guard`]-loaded snapshot it must not consume; a
    /// rolling-window aggregator reading `weight * &windows[i]`
    /// against an indexed slice of histograms it iterates non-
    /// destructively) had to rewrite to one of three forms — the
    /// hand-applied clone form `weight * cached_hist.clone()` (which
    /// duplicates the clone at every call site); the right-scalar
    /// borrowed-receiver rewrite `cached_hist.clone() * weight`
    /// (which abandons the natural left-scalar shape against the
    /// natural English / textbook reading); the open-coded
    /// per-cell `let mut acc = AxisHistogram::empty(); for (c, n) in
    /// cached_hist.iter() { for _ in 0..weight * n { acc.observe(c); }
    /// }` rebuild (which re-expands every observation through repeated
    /// `observe`, O(weight · total)). The lift names the projection at
    /// one site, consumers route through `n * &hist` uniformly, and
    /// the per-cell loop lives at exactly one site (the
    /// [`MulAssign<usize>`][MulAssign] impl) underneath every
    /// scalar-action entry surface (right-scalar `hist * n`,
    /// in-place `hist *= n`, left-scalar `n * hist`, borrowed-RHS
    /// left-scalar `n * &hist`).
    ///
    /// **Borrowed-owned RHS agreement law** — `n * &hist` is pointwise
    /// equal to `n * hist.clone()` for every `(n, hist)`. The
    /// canonical (owned-RHS, borrowed-RHS) idiom-peer agreement on a
    /// [`usize`]-action surface; pinned by the trait-uniform test
    /// `axis_histogram_mul_left_factor_borrowed_equals_owned_for_every_closed_axis_implementor`
    /// in [`tests`]. Inherits every law the owned-RHS left-scalar
    /// surface carries — the commutativity equivalence mediated
    /// through right-scalar `hist * n`, the zero-factor absorbing
    /// law (`0 * &hist == empty`), the one-factor identity law
    /// (`1 * &hist == hist.clone()`), the total-scaling law
    /// (`(n * &hist).total() == n * hist.total()`), the cell-level
    /// scaling law (`(n * &hist).count(v) == n * hist.count(v)`),
    /// the distributivity over the additive monoid
    /// (`n * &(a + &b) == n * &a + &(n * &b)`), and the equivalence
    /// with repeated `+=` — by the borrowed-owned agreement at one
    /// site.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor inherits the
    /// projection at no per-axis cost. The trait-uniform borrowed-
    /// owned RHS agreement law pinned in [`tests`] holds across the
    /// implementor set
    /// (`axis_histogram_mul_left_factor_borrowed_equals_owned_*`).
    ///
    /// [Mul]: std::ops::Mul
    /// [MulAssign]: std::ops::MulAssign
    /// [Add]: std::ops::Add
    fn mul(self, hist: &AxisHistogram<A>) -> Self::Output {
        self * hist.clone()
    }
}

impl<A: ClosedAxis> std::ops::Mul<usize> for &AxisHistogram<A> {
    type Output = AxisHistogram<A>;

    /// Borrowed-receiver peer of [`Mul<usize> for AxisHistogram<A>`][Mul] —
    /// `&hist * n` reads the same histogram as `hist.clone() * n` but
    /// keeps the caller's ownership of `hist`. Closes the canonical
    /// Rust (owned-receiver, borrowed-receiver) idiom-peer pair on the
    /// right-scalar entry surface, the symmetric peer of the
    /// (owned-RHS, borrowed-RHS) pair the left-scalar surface carries
    /// at [`Mul<AxisHistogram<A>> for usize`][LeftMul] /
    /// [`Mul<&AxisHistogram<A>> for usize`][LeftMulRef]. The four
    /// corners of the scalar-multiplication ownership matrix —
    /// `hist * n`, `&hist * n`, `n * hist`, `n * &hist` — now all
    /// route through the in-place [`MulAssign<usize>`][MulAssign]
    /// primitive at exactly one site; the per-cell scalar-multiplication
    /// loop lives at one site underneath every entry surface
    /// (right-scalar owned, right-scalar borrowed, left-scalar owned,
    /// left-scalar borrowed, in-place).
    ///
    /// Before this lift, every consumer wanting the right-scalar shape
    /// against a borrowed histogram (a per-tier observatory reading
    /// `&cached_hist * multiplier` against an [`arc_swap::Guard`]-loaded
    /// snapshot it must not consume; a rolling-window aggregator
    /// reading `&windows[i] * weight` against an indexed slice of
    /// histograms it iterates non-destructively; a fleet aggregator
    /// reading `&host_hist * weight` over a `&BTreeMap<HostId,
    /// AxisHistogram<A>>` it does not own) had to rewrite to one of
    /// three forms — the hand-applied clone form `cached_hist.clone() *
    /// multiplier` (which duplicates the clone at every call site);
    /// the left-scalar borrowed-RHS rewrite `multiplier * &cached_hist`
    /// (which inverts the natural English / textbook reading "the
    /// histogram times the weight" the right-scalar surface expresses);
    /// the open-coded per-cell rebuild over the cell iterator (which
    /// re-expands every observation through repeated `observe`,
    /// O(weight · total)). The lift names the projection at one site,
    /// consumers route through `&hist * n` uniformly, and the per-cell
    /// loop lives at exactly one site (the [`MulAssign<usize>`][MulAssign]
    /// impl) underneath every scalar-action entry surface.
    ///
    /// **Borrowed-owned receiver agreement law** — `&hist * n` is
    /// pointwise equal to `hist.clone() * n` for every `(hist, n)`. The
    /// canonical (owned-receiver, borrowed-receiver) idiom-peer
    /// agreement on a [`usize`]-action surface; the symmetric peer of
    /// the (owned-RHS, borrowed-RHS) agreement
    /// `n * &hist == n * hist.clone()` on the left-scalar surface.
    /// Pinned by the trait-uniform test
    /// `axis_histogram_mul_right_factor_borrowed_equals_owned_for_every_closed_axis_implementor`
    /// in [`tests`]. Inherits every law the owned-receiver right-scalar
    /// surface carries — the (`Mul`, `MulAssign`) equivalence
    /// (`(&hist * n).clone() == { let mut a = hist.clone(); a *= n; a }`),
    /// the zero-factor absorbing law (`&hist * 0 == empty`), the
    /// one-factor identity law (`&hist * 1 == hist.clone()`), the
    /// total-scaling law (`(&hist * n).total() == hist.total() * n`),
    /// the cell-level scaling law
    /// (`(&hist * n).count(v) == hist.count(v) * n`), the
    /// distributivity over the additive monoid
    /// (`&(a + &b) * n == &a * n + &(&b * n)`), and the equivalence
    /// with repeated `+=` — by the borrowed-owned agreement at one
    /// site.
    ///
    /// **Symmetric commutativity peer** — `&hist * n` is pointwise
    /// equal to `n * &hist` for every `(hist, n)`, by the commutativity
    /// law on the right-scalar surface composed with the borrowed-
    /// receiver agreement. The borrowed-receiver pair (`&hist * n`,
    /// `n * &hist`) reads the same histogram, just as the owned-
    /// receiver pair (`hist * n`, `n * hist`) does on the owned side.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor inherits the
    /// projection at no per-axis cost. The trait-uniform borrowed-
    /// owned receiver agreement law pinned in [`tests`] holds across
    /// the implementor set
    /// (`axis_histogram_mul_right_factor_borrowed_equals_owned_*`).
    ///
    /// [Mul]: std::ops::Mul
    /// [MulAssign]: std::ops::MulAssign
    /// [LeftMul]: std::ops::Mul
    /// [LeftMulRef]: std::ops::Mul
    fn mul(self, factor: usize) -> Self::Output {
        self.clone() * factor
    }
}

impl<A: ClosedAxis> std::ops::Div<usize> for &AxisHistogram<A> {
    type Output = AxisHistogram<A>;

    /// Borrowed-receiver peer of [`Div<usize> for AxisHistogram<A>`][Div]
    /// — `&hist / divisor` reads the same histogram as `hist.clone() /
    /// divisor` but keeps the caller's ownership of `hist`. Closes the
    /// canonical Rust (owned-receiver, borrowed-receiver) idiom-peer
    /// pair on the truncating-division entry surface, the
    /// truncating-division dual of the same pair on the
    /// scalar-multiplication surface ([`Mul<usize> for
    /// AxisHistogram<A>`][Mul] / [`Mul<usize> for
    /// &AxisHistogram<A>`][MulRef]). The two corners of the
    /// truncating-division receiver-ownership matrix — `hist / divisor`,
    /// `&hist / divisor` — now both route through the in-place
    /// [`DivAssign<usize>`][DivAssign] primitive at exactly one site;
    /// the per-cell truncating-division loop lives at one site
    /// underneath every entry surface (owned-receiver, borrowed-
    /// receiver, in-place).
    ///
    /// Before this lift, every consumer wanting the truncating-division
    /// shape against a borrowed histogram (a rolling-window observatory
    /// averaging `&cached_hist / N` against an
    /// [`arc_swap::Guard`]-loaded snapshot it must not consume; a fleet
    /// aggregator normalizing `&host_hist / host_count` over a
    /// `&BTreeMap<HostId, AxisHistogram<A>>` it does not own; a
    /// per-tier observatory de-amplifying `&weighted_hist / weight`
    /// against an indexed slice of histograms it iterates non-
    /// destructively) had to rewrite to the hand-applied clone form
    /// `cached_hist.clone() / N` (which duplicates the clone at every
    /// call site) or the open-coded per-cell map
    /// `cached_hist.iter().map(|(c, n)| (c, n / N)).collect()` (which
    /// re-expands every observation through repeated `observe`,
    /// O(divisor · total)). The lift names the projection at one site,
    /// consumers route through `&hist / divisor` uniformly, and the
    /// per-cell loop lives at exactly one site (the
    /// [`DivAssign<usize>`][DivAssign] impl) underneath every
    /// truncating-division entry surface.
    ///
    /// **Borrowed-owned receiver agreement law** — `&hist / divisor`
    /// is pointwise equal to `hist.clone() / divisor` for every
    /// `(hist, divisor)` with `divisor > 0`. The canonical
    /// (owned-receiver, borrowed-receiver) idiom-peer agreement on a
    /// [`usize`]-action surface; the truncating-division dual of the
    /// borrowed-owned receiver agreement
    /// `&hist * n == hist.clone() * n` on the multiplicative side.
    /// Pinned by the trait-uniform test
    /// `axis_histogram_div_right_divisor_borrowed_equals_owned_for_every_closed_axis_implementor`
    /// in [`tests`]. Inherits every law the owned-receiver
    /// truncating-division surface carries — the (`Div`, `DivAssign`)
    /// equivalence
    /// (`(&hist / divisor).clone() == { let mut a = hist.clone(); a /= divisor; a }`),
    /// the one-divisor identity law (`&hist / 1 == hist.clone()`), the
    /// Mul-Div round-trip law on a non-zero factor with no overflow
    /// (`&(hist * factor) / factor == hist` when `factor > 0`), and
    /// the cell-level truncating-division law
    /// (`(&hist / divisor).count(v) == hist.count(v) / divisor`) — by
    /// the borrowed-owned agreement at one site.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor inherits the
    /// projection at no per-axis cost. The trait-uniform borrowed-
    /// owned receiver agreement law pinned in [`tests`] holds across
    /// the implementor set
    /// (`axis_histogram_div_right_divisor_borrowed_equals_owned_*`).
    ///
    /// # Panics
    ///
    /// Panics on `divisor == 0`. Inherits the panic contract from
    /// [`DivAssign<usize>`][DivAssign].
    ///
    /// [Div]: std::ops::Div
    /// [DivAssign]: std::ops::DivAssign
    /// [Mul]: std::ops::Mul
    /// [MulRef]: std::ops::Mul
    fn div(self, divisor: usize) -> Self::Output {
        self.clone() / divisor
    }
}

impl<A: ClosedAxis> std::ops::Rem<usize> for &AxisHistogram<A> {
    type Output = AxisHistogram<A>;

    /// Borrowed-receiver peer of [`Rem<usize> for AxisHistogram<A>`][Rem]
    /// — `&hist % divisor` reads the same histogram as `hist.clone() %
    /// divisor` but keeps the caller's ownership of `hist`. Closes the
    /// canonical Rust (owned-receiver, borrowed-receiver) idiom-peer
    /// pair on the Euclidean-remainder entry surface, the
    /// Euclidean-remainder dual of the same pair on the
    /// truncating-division surface ([`Div<usize> for
    /// AxisHistogram<A>`][Div] / [`Div<usize> for
    /// &AxisHistogram<A>`][DivRef]) and the same pair on the
    /// scalar-multiplication surface ([`Mul<usize> for
    /// AxisHistogram<A>`][Mul] / [`Mul<usize> for
    /// &AxisHistogram<A>`][MulRef]). The two corners of the
    /// Euclidean-remainder receiver-ownership matrix — `hist %
    /// divisor`, `&hist % divisor` — now both route through the
    /// in-place [`RemAssign<usize>`][RemAssign] primitive at exactly
    /// one site; the per-cell Euclidean-remainder loop lives at one
    /// site underneath every entry surface (owned-receiver,
    /// borrowed-receiver, in-place). Completes the canonical Rust
    /// `(Mul, MulAssign, Div, DivAssign, Rem, RemAssign)`
    /// integer-arithmetic operator sextet on the borrowed-receiver
    /// side: every primitive `usize`-action surface (`*=`, `*`, `/=`,
    /// `/`, `%=`, `%`) carries the borrowed-receiver peer for the two
    /// fallible-divisor entries (`/`, `%`) that the prior runs had
    /// closed on the multiplicative side.
    ///
    /// Before this lift, every consumer wanting the Euclidean-remainder
    /// shape against a borrowed histogram (a rolling-window observatory
    /// reading `&cached_hist % window` against an
    /// [`arc_swap::Guard`]-loaded snapshot it must not consume to read
    /// off the per-cell windowed residual; a fleet aggregator reading
    /// `&host_hist % bucket` over a `&BTreeMap<HostId,
    /// AxisHistogram<A>>` it does not own to read off the per-cell
    /// per-bucket residual; a per-tier observatory de-amplifying
    /// `&weighted_hist % weight` against an indexed slice of histograms
    /// it iterates non-destructively to read off the per-cell
    /// quantization residual) had to rewrite to the hand-applied clone
    /// form `cached_hist.clone() % window` (which duplicates the clone
    /// at every call site) or the open-coded subtractive rebuild
    /// `cached_hist - &(cached_hist.clone() / window * window)` (which
    /// re-expands the div-rem identity at every call site, allocating
    /// two intermediate histograms per cell). The lift names the
    /// projection at one site, consumers route through `&hist %
    /// divisor` uniformly, and the per-cell loop lives at exactly one
    /// site (the [`RemAssign<usize>`][RemAssign] impl) underneath every
    /// Euclidean-remainder entry surface.
    ///
    /// **Borrowed-owned receiver agreement law** — `&hist % divisor` is
    /// pointwise equal to `hist.clone() % divisor` for every `(hist,
    /// divisor)` with `divisor > 0`. The canonical (owned-receiver,
    /// borrowed-receiver) idiom-peer agreement on a [`usize`]-action
    /// surface; the Euclidean-remainder dual of the borrowed-owned
    /// receiver agreement `&hist / divisor == hist.clone() / divisor`
    /// on the truncating-division side and `&hist * n == hist.clone() *
    /// n` on the multiplicative side. Pinned by the trait-uniform test
    /// `axis_histogram_rem_right_divisor_borrowed_equals_owned_for_every_closed_axis_implementor`
    /// in [`tests`]. Inherits every law the owned-receiver
    /// Euclidean-remainder surface carries — the (`Rem`, `RemAssign`)
    /// equivalence
    /// (`(&hist % divisor).clone() == { let mut a = hist.clone(); a %= divisor; a }`),
    /// the one-divisor zero law (`&hist % 1 == empty`), the div-rem
    /// identity (`(&hist / divisor) * divisor + (&hist % divisor) ==
    /// hist` for `divisor > 0`), the remainder-bound law
    /// (`(&hist % divisor).count(v) < divisor` for every cell), and the
    /// cell-level Euclidean-remainder law
    /// (`(&hist % divisor).count(v) == hist.count(v) % divisor`) — by
    /// the borrowed-owned agreement at one site.
    ///
    /// Trait-uniform: every [`ClosedAxis`] implementor inherits the
    /// projection at no per-axis cost. The trait-uniform borrowed-
    /// owned receiver agreement law pinned in [`tests`] holds across
    /// the implementor set
    /// (`axis_histogram_rem_right_divisor_borrowed_equals_owned_*`).
    ///
    /// # Panics
    ///
    /// Panics on `divisor == 0`. Inherits the panic contract from
    /// [`RemAssign<usize>`][RemAssign].
    ///
    /// [Rem]: std::ops::Rem
    /// [RemAssign]: std::ops::RemAssign
    /// [Div]: std::ops::Div
    /// [DivRef]: std::ops::Div
    /// [Mul]: std::ops::Mul
    /// [MulRef]: std::ops::Mul
    fn rem(self, divisor: usize) -> Self::Output {
        self.clone() % divisor
    }
}

impl<A: ClosedAxis> std::ops::Index<A> for AxisHistogram<A> {
    type Output = usize;

    /// Per-cell count read through the canonical Rust
    /// [`Index`][std::ops::Index] operator — `hist[value]` returns
    /// `&self.count(value)` by reference into the underlying counts
    /// vector at `axis_ordinal(value)`. The natural stdlib operator-
    /// surface peer of [`Self::count`] on the inherent method surface:
    /// `vec[i]` ↔ `*vec.get(i).unwrap()`, `map[&k]` ↔ `*map.get(&k).unwrap()`,
    /// `hist[cell]` ↔ `hist.count(cell)`. Every stdlib collection that
    /// supports lookup by key carries the [`Index`] surface (`Vec<T>:
    /// Index<usize>`, `[T]: Index<usize>`, `HashMap<K, V>: Index<&K>`,
    /// `BTreeMap<K, V>: Index<&K>`); the [`AxisHistogram`] now joins
    /// that peerage on the [`ClosedAxis`] cell-lookup axis.
    ///
    /// The `A` argument is taken by value (not by reference) because
    /// every [`ClosedAxis`] cell is [`Copy`] — the trait bound names
    /// the cell type as a primitive on the typescape, so the call-site
    /// shape stays `hist[Added]` (operator-surface idiom every Rust
    /// programmer already knows) rather than `hist[&Added]`. Total over
    /// the axis space: defined on every cell, no out-of-range case, no
    /// panic path beyond the inherent [`usize`] indexing into the
    /// `axis_cardinality::<A>()`-sized counts vector (which is itself
    /// statically bounded by [`ClosedAxis::ALL`]).
    fn index(&self, value: A) -> &usize {
        &self.counts[axis_ordinal(value)]
    }
}

impl<A: ClosedAxis> std::ops::IndexMut<A> for AxisHistogram<A> {
    /// Per-cell mutable count handle through the canonical Rust
    /// [`IndexMut`][std::ops::IndexMut] operator — `hist[value]` on the
    /// left of an assignment, or as the receiver of a compound
    /// assignment (`+=`, `-=`, `*=`, …), returns
    /// `&mut self.counts[axis_ordinal(value)]`. The mutating peer of
    /// [`Index<A>`][std::ops::Index] above: where `Index` reads a cell
    /// count through `hist[cell]`, `IndexMut` writes one through
    /// `hist[cell] = n;` or compound-assigns one through `hist[cell] +=
    /// 1;`. The pair `(Index, IndexMut)` is the canonical Rust stdlib
    /// collection-lookup operator quartet — every stdlib collection that
    /// supports indexed read also supports indexed mutation at the same
    /// operator surface ([`Vec<T>`][Vec]: `Index<usize>` + `IndexMut<usize>`,
    /// [`slice`][prim@slice]: same, [`std::collections::HashMap<K, V>`]:
    /// `Index<&K>` + `IndexMut<&K>`, [`std::collections::BTreeMap<K, V>`]:
    /// same); the [`AxisHistogram`] now joins that peerage on the
    /// [`ClosedAxis`] cell-mutation axis.
    ///
    /// Before this lift, every consumer reaching the cellwise-mutation
    /// surface (a fleet aggregator resetting a single
    /// [`crate::ShikumiErrorKind`] cell to a watermark, a per-window
    /// observatory bumping a [`crate::WatchEventClass`] cell after a
    /// late observation arrived, a backfill projection assigning a
    /// known historical count to a single cell before folding the
    /// rolling window forward) reached the cell either through the
    /// per-call-site [`Self::observe`] loop (one observation at a time)
    /// or through a [`FromIterator<(A, usize)>`] rebuild over the full
    /// axis cover (which throws away every other cell). The
    /// [`IndexMut`] surface now exposes the single-cell mutation form
    /// every Rust reader already knows from [`Vec`] /
    /// [`HashMap`][std::collections::HashMap]: `hist[cell] = n;`,
    /// `hist[cell] += 1;`, `hist[cell] -= 1;`, `hist[cell] *= 2;`.
    ///
    /// **Operator-to-inherent bridge** — assigning through the operator
    /// surface and reading through [`Self::count`] / the [`Index`]
    /// operator surface agree pointwise: after `hist[cell] = n;` the
    /// read `hist.count(cell) == n` and `hist[cell] == n` hold. The
    /// canonical stdlib write-then-read round-trip every reader expects.
    ///
    /// **`+= 1` is observation** — `hist[cell] += 1;` is pointwise
    /// equivalent to `hist.observe(cell);` (the inherent observation
    /// method that motivates the histogram surface). The
    /// (`IndexMut`, `observe`) duality the [`Index`] /
    /// [`Self::count`] pair has on the read side.
    ///
    /// **`= 0` zeroes one cell** — `hist[cell] = 0;` zeros exactly the
    /// `cell` slot and leaves every other slot pointwise unchanged.
    /// The single-cell-reset peer of [`Self::empty`] (which zeros every
    /// cell); the cell-local form of the (empty, identity) law on the
    /// additive monoid.
    ///
    /// **`*= 2` doubles one cell** — `hist[cell] *= 2;` is pointwise
    /// equivalent to folding every cell through `hist *= 2`'s
    /// [`MulAssign<usize>`][std::ops::MulAssign] surface restricted to
    /// the `cell` slot. The cell-local form of the scalar-action law
    /// on the [`MulAssign<usize>`][std::ops::MulAssign] operator surface
    /// (each cell mutated independently re-enacts the global scalar
    /// action).
    ///
    /// The `A` argument is taken by value (not by reference) because
    /// every [`ClosedAxis`] cell is [`Copy`], matching the [`Index<A>`]
    /// peer above so the call-site shape stays `hist[Added] = 5;`
    /// (operator-surface idiom every Rust programmer already knows)
    /// rather than `hist[&Added] = 5;`. Total over the axis space:
    /// defined on every cell, no out-of-range case, no panic path
    /// beyond the inherent [`usize`] indexing into the
    /// `axis_cardinality::<A>()`-sized counts vector (which is itself
    /// statically bounded by [`ClosedAxis::ALL`]).
    ///
    /// Trait-uniform laws reach every [`ClosedAxis`] implementor through
    /// `for_each_closed_axis_implementor!` in [`tests`]
    /// (`axis_histogram_index_mut_write_round_trips_through_index_*`,
    /// `axis_histogram_index_mut_add_assign_equals_observe_*`,
    /// `axis_histogram_index_mut_zero_resets_single_cell_*`,
    /// `axis_histogram_index_mut_mul_assign_matches_mul_assign_usize_*`).
    fn index_mut(&mut self, value: A) -> &mut usize {
        &mut self.counts[axis_ordinal(value)]
    }
}

impl<A: ClosedAxis> std::cmp::PartialOrd for AxisHistogram<A> {
    /// Pointwise lattice partial order lifted to the canonical Rust
    /// stdlib [`PartialOrd`][std::cmp::PartialOrd] trait surface — the
    /// natural-language `<`, `<=`, `>`, `>=` operators on
    /// [`AxisHistogram`] read off the same partial-dominance order that
    /// [`Self::is_dominated_by`] / [`Self::dominates`] /
    /// [`Self::is_strictly_dominated_by`] / [`Self::strictly_dominates`]
    /// expose as inherent methods. Single-pass `O(axis_cardinality)`
    /// short-circuiting scan: tracks whether any cell has been seen
    /// strictly less and whether any cell has been seen strictly
    /// greater, returns [`None`] (incomparable) on the first cell where
    /// the two flags would coexist, and reads off
    /// [`Less`][std::cmp::Ordering::Less] /
    /// [`Equal`][std::cmp::Ordering::Equal] /
    /// [`Greater`][std::cmp::Ordering::Greater] at end from the two
    /// flags.
    ///
    /// **Why a manual impl (not derive).** The struct derives
    /// [`PartialEq`], [`Eq`], [`Hash`][std::hash::Hash] but
    /// **deliberately not** [`PartialOrd`][std::cmp::PartialOrd] — the
    /// derive would induce the [`Vec<usize>`][Vec]'s default
    /// **lexicographic** order on the underlying counts vector, which
    /// is *total* (always picks a side on every pair) and disagrees
    /// with the lattice partial order [`Self::is_dominated_by`] is
    /// built on. The pointwise dominance order is *partial* — two
    /// histograms can be lattice-incomparable when one cell is strictly
    /// larger on each side. Pinning the manual lift on the lattice
    /// order rather than the lexicographic derive is what closes the
    /// stdlib operator surface in a way that agrees with every
    /// inherent dominance method — the trait-uniform bridges in
    /// [`tests`] pin the agreement uniformly across every
    /// [`ClosedAxis`] implementor.
    ///
    /// **Operator-to-inherent bridge** — the four stdlib operators map
    /// onto the four inherent dominance methods pointwise:
    /// - `a <= b` ⇔ `a.is_dominated_by(&b)`
    /// - `a >= b` ⇔ `a.dominates(&b)`
    /// - `a < b` ⇔ `a.is_strictly_dominated_by(&b)`
    /// - `a > b` ⇔ `a.strictly_dominates(&b)`
    ///
    /// Pinned across every implementor through
    /// [`tests::axis_histogram_partial_cmp_matches_dominance_quartet_for_every_closed_axis_implementor`].
    ///
    /// **Partial-cmp-to-inherent bridge** — the return value matches
    /// the dominance method that holds:
    /// - `a.partial_cmp(&b) == Some(Equal)` ⇔ `a == b`
    /// - `a.partial_cmp(&b) == Some(Less)` ⇔
    ///   `a.is_strictly_dominated_by(&b)`
    /// - `a.partial_cmp(&b) == Some(Greater)` ⇔
    ///   `a.strictly_dominates(&b)`
    /// - `a.partial_cmp(&b) == None` ⇔
    ///   `!a.is_dominated_by(&b) && !b.is_dominated_by(&a)`
    ///
    /// The [`None`] case is the *partial* case the derive would
    /// collapse — pins the lift carries the partiality of the
    /// underlying lattice order through the [`Option`] return.
    ///
    /// **Consistency with [`PartialEq`]**: `a == b` ⇒
    /// `a.partial_cmp(&b) == Some(Equal)`. Every cell equal means
    /// neither `saw_less` nor `saw_greater` flips, so the end-of-scan
    /// match returns
    /// [`Some(Equal)`][std::cmp::Ordering::Equal] — the canonical
    /// stdlib consistency contract between
    /// [`PartialEq`] and [`PartialOrd`][std::cmp::PartialOrd].
    ///
    /// **Why no [`Ord`][std::cmp::Ord]**: the histogram surface is a
    /// genuine partial order (the partiality witness is the
    /// `(2, 1, 0)` / `(1, 2, 0)` pair on [`crate::DiffLineKind`] —
    /// neither side dominates the other yet both have equal totals),
    /// so the [`Ord`] trait — which requires total order — is
    /// structurally inappropriate. The stdlib precedent is
    /// [`f32`] / [`f64`]: both implement
    /// [`PartialOrd`][std::cmp::PartialOrd] (with [`None`] for NaN
    /// comparisons) but not [`Ord`].
    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
        use std::cmp::Ordering;
        let mut ord = Ordering::Equal;
        for (lhs, rhs) in self.counts.iter().zip(other.counts.iter()) {
            match (ord, lhs.cmp(rhs)) {
                (Ordering::Equal, cell) => ord = cell,
                (Ordering::Less, Ordering::Greater) | (Ordering::Greater, Ordering::Less) => {
                    return None;
                }
                _ => {}
            }
        }
        Some(ord)
    }
}

impl<A: ClosedAxisLabel> std::fmt::Display for AxisHistogram<A> {
    /// Operator-facing per-cell emission of the histogram —
    /// `"label₁=count₁, label₂=count₂, …, labelₙ=countₙ"` in declaration
    /// order over [`ClosedAxis::ALL`], with `labelᵢ` taken from
    /// [`ClosedAxisLabel::as_str`]. The canonical Rust stdlib
    /// [`Display`][std::fmt::Display] idiom-peer of the derived
    /// [`Debug`][std::fmt::Debug] impl on the [`AxisHistogram`] surface —
    /// where [`Debug`] reaches the structural form
    /// (`AxisHistogram { counts: [1, 2, 0], _marker: PhantomData }`,
    /// which exposes the backing-vec ordinal — useful for diagnostics,
    /// useless to an operator who reads axis cells by their canonical
    /// label), [`Display`] reaches the *labeled* per-cell form every
    /// attestation manifest, structured-log field, and CLI dump emits.
    /// Closes the canonical (`Debug`, `Display`) trait pair on the
    /// [`AxisHistogram`] surface every stdlib collection-like type
    /// carries — peer to the same pair on numeric monoid types
    /// ([`std::time::Duration`], [`std::num::Wrapping`], etc.) where
    /// `Debug` exposes the structural form and `Display` exposes the
    /// canonical operator-facing form.
    ///
    /// The natural typed primitive for operator-facing emission of a
    /// histogram — a tracing field `tracing::info!(hist = %tally, …)`
    /// rendering the per-cell distribution into a single structured-log
    /// field without re-deriving the `(cell, count)` join at the call
    /// site, an attestation manifest YAML field `chain_shape: "defaults=1,
    /// env=0, file=2"` carrying the chain-shape histogram as a single
    /// scalar string (round-trippable through
    /// [`axis_from_label`]/[`AxisHistogram::observe`] over the comma-split
    /// pairs without naming `axis_iter` at the loader), a CLI
    /// `config-show --histogram` line `removed=2, added=5, context=37`
    /// emitting the diff-shape histogram per file rebuild without a
    /// per-axis hand-rolled formatter. Before this lift, every such
    /// consumer reached the operator-facing emission through one of three
    /// forms: an open-coded `hist.iter().map(|(v, c)|
    /// format!("{}={}", v.as_str(), c)).collect::<Vec<_>>().join(", ")`
    /// (a two-allocation per-call site rebuild — one [`String`] per
    /// cell, one [`Vec`] over them), a custom `Display`-emitting newtype
    /// wrapper at each consumer site that re-derived the (cell, count)
    /// join (the wrapper-per-consumer pattern), or an inlined
    /// `for`-loop with a manual leading-separator flag (the open-coded
    /// `is_first` discipline rebuilt at every site). The lift names the
    /// projection at one site, single-pass through the [`std::fmt::Write`]
    /// surface, with no intermediate [`String`] / [`Vec`] allocation.
    ///
    /// **Format.** `axis_cardinality::<A>()` pairs of `<label>=<count>`
    /// separated by `", "`, in declaration order over [`ClosedAxis::ALL`],
    /// with `<label>` taken verbatim from [`ClosedAxisLabel::as_str`].
    /// Zero-count cells are emitted alongside positive-count cells; the
    /// emission walks the *full* axis, not just the observed support
    /// (peer to the length law on [`AxisHistogram::iter`]). The empty
    /// histogram emits every cell at zero (`"defaults=0, env=0, file=0"`
    /// on the [`crate::ConfigSourceKind`] axis), not the empty string —
    /// the operator distinguishes "empty observation window" from "axis
    /// has no cells" by reading the `=0` cells, and the round-trip law
    /// below depends on every cell appearing in the emission.
    ///
    /// **Round-trip law** —
    /// `axis_from_label::<A>(label_substring) == Some(cell)` for every
    /// `<label>=<count>` pair emitted on every histogram. The
    /// operator-facing emission round-trips through
    /// [`ClosedAxisLabel::from_canonical_str`] on the label side; a
    /// loader recovers the typed `(cell, count)` pairs by splitting the
    /// emitted string on `", "`, splitting each pair on `'='`, parsing
    /// the label via [`axis_from_label`], and parsing the count as
    /// [`usize`]. Pinned uniformly across every [`ClosedAxisLabel`]
    /// implementor by
    /// [`tests::axis_histogram_display_labels_round_trip_through_axis_from_label_for_every_closed_axis_label_implementor`].
    ///
    /// **Length law** — the emission contains exactly
    /// `axis_cardinality::<A>() - 1` separator substrings (`", "`), one
    /// per gap between adjacent pairs. Pinned uniformly across every
    /// [`ClosedAxisLabel`] implementor by
    /// [`tests::axis_histogram_display_emits_axis_cardinality_pairs_for_every_closed_axis_label_implementor`].
    ///
    /// **Empty-histogram law** — the empty histogram emits every cell
    /// with `=0` (every pair's count substring reads `"0"`). Pinned
    /// uniformly across every [`ClosedAxisLabel`] implementor by
    /// [`tests::axis_histogram_display_empty_emits_zero_for_every_cell_for_every_closed_axis_label_implementor`].
    ///
    /// **Total law** — summing the per-cell counts parsed off the
    /// emission yields [`AxisHistogram::total`]. The operator-facing
    /// emission preserves the total observation count by construction
    /// (every cell contributes its count, no cell drops). Pinned
    /// concretely on [`crate::DiffLineKind`] by
    /// [`tests::axis_histogram_display_total_matches_inherent_for_diff_line_kind`].
    ///
    /// **Trait-bound asymmetry with [`Debug`]/[`Hash`]/[`PartialOrd`]** —
    /// every other trait derived or impl'd on [`AxisHistogram`]
    /// ([`Debug`], [`Clone`], [`PartialEq`], [`Eq`], [`Hash`],
    /// [`PartialOrd`], [`Default`]) reaches every [`ClosedAxis`]
    /// implementor uniformly, since their bounds carry no labeling
    /// requirement. [`Display`] is the one operator surface that needs
    /// the *canonical-name* projection [`ClosedAxisLabel::as_str`]
    /// carries, so the impl is gated on the labeled-axis sub-trait
    /// [`ClosedAxisLabel`]. Every closed-enum axis primitive on the
    /// typescape (the twenty [`ClosedAxisLabel`] implementors enumerated
    /// by [`for_each_closed_axis_label_implementor`] in [`tests`])
    /// inherits the [`Display`] impl through that bound; the product
    /// cube axes ([`crate::FormatCoordinates`],
    /// [`crate::AttributionCoordinates`],
    /// [`crate::ErrorLocalizationCoordinates`],
    /// [`crate::AttributionSourceKindCoordinates`],
    /// [`crate::AttributionNameKindCoordinates`]) do not — they carry no
    /// canonical operator-facing label today, and reaching a cube-cell
    /// label through a joint `(axis-name, cell-label)` projection is a
    /// separate lift.
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let mut first = true;
        for (cell, count) in self.iter() {
            if !first {
                f.write_str(", ")?;
            }
            first = false;
            write!(f, "{}={}", cell.as_str(), count)?;
        }
        Ok(())
    }
}

/// Typed parse-failure mode of [`<AxisHistogram<A> as
/// FromStr>::from_str`][std::str::FromStr] on the labeled-axis
/// histogram surface — one variant per structurally distinct rejection
/// reason the parser can surface, each carrying the offending
/// substring verbatim so a caller can localize the failure without
/// re-derived bookkeeping at the call site.
///
/// **Why a structured enum, not [`String`] / [`crate::ShikumiError`]**:
/// the parser has four distinct rejection reasons (missing `=`,
/// unknown label, invalid count, duplicate label), each load-bearing
/// on a different downstream branch (a CLI surfaces a localized
/// underline pointing at the offending pair, a structured-log emitter
/// keys an alert by error variant, a deserialization fallback retries
/// only on the recoverable `UnknownLabel` case). Collapsing all four
/// into one stringly-typed [`crate::ShikumiError::Parse`] would lose
/// the downstream branch axis at the type level — peer of the
/// load-bearing structuring [`crate::ShikumiErrorKind`] carries on
/// [`crate::ShikumiError`].
///
/// **Trait surface.** Implements [`Debug`][std::fmt::Debug] (derive),
/// [`Clone`] (derive — every variant's payload is [`String`]),
/// [`PartialEq`] / [`Eq`] (derive — supports test-equality assertions
/// without an `assert_matches!` macro), [`Display`][std::fmt::Display]
/// (operator-facing one-line rendering of the failure), and
/// [`std::error::Error`] (canonical Rust error trait surface —
/// satisfies the `Result<_, Box<dyn Error>>` and `eyre::Result<_>`
/// bounds every downstream consumer expects). `#[non_exhaustive]` to
/// pin variant-addition forward-compatibility — a future parser
/// rejection mode (e.g. an `EmptyCount`, a `LabelCaseViolation` on a
/// stricter-case axis) lands as a new variant without a SemVer-major
/// bump.
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum ParseAxisHistogramError {
    /// A `<label>=<count>` pair was missing the `=` separator. The
    /// `pair` field carries the offending substring verbatim (the
    /// comma-split token before the missing `=`) so a caller can
    /// localize the failure to the surrounding context.
    MissingEquals {
        /// The offending pair substring, verbatim.
        pair: String,
    },
    /// A label substring did not match any canonical name on the axis
    /// — [`ClosedAxisLabel::from_canonical_str`] returned [`None`]. The
    /// `label` field carries the offending substring verbatim.
    UnknownLabel {
        /// The offending label substring, verbatim.
        label: String,
    },
    /// A count substring did not parse as [`usize`] —
    /// [`str::parse::<usize>`][str::parse] failed. The `label` field
    /// carries the cell whose count failed to parse; the `count` field
    /// carries the offending count substring verbatim.
    InvalidCount {
        /// The label whose count failed to parse.
        label: String,
        /// The offending count substring, verbatim.
        count: String,
    },
    /// A label appeared more than once in the input. The `label` field
    /// carries the duplicated canonical name. The parser rejects rather
    /// than silently overwriting because two different counts on the
    /// same cell name a load-bearing ambiguity the caller resolves
    /// upstream.
    DuplicateLabel {
        /// The duplicated canonical label.
        label: String,
    },
}

impl std::fmt::Display for ParseAxisHistogramError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::MissingEquals { pair } => {
                write!(f, "missing '=' separator in pair {pair:?}")
            }
            Self::UnknownLabel { label } => {
                write!(f, "unknown axis label {label:?}")
            }
            Self::InvalidCount { label, count } => {
                write!(
                    f,
                    "invalid count {count:?} for label {label:?} (expected usize)"
                )
            }
            Self::DuplicateLabel { label } => {
                write!(f, "duplicate label {label:?}")
            }
        }
    }
}

impl std::error::Error for ParseAxisHistogramError {}

impl<A: ClosedAxisLabel> std::str::FromStr for AxisHistogram<A> {
    type Err = ParseAxisHistogramError;

    /// Operator-facing parse of the histogram from the
    /// `"label₁=count₁, label₂=count₂, …, labelₙ=countₙ"` form
    /// emitted by [`<AxisHistogram<A> as Display>::fmt`][std::fmt::Display]
    /// — the canonical Rust stdlib [`FromStr`][std::str::FromStr]
    /// idiom-peer of the [`Display`][std::fmt::Display] impl on the
    /// [`AxisHistogram`] surface. Closes the canonical
    /// (`Display`, `FromStr`) round-trip pair every stdlib serializable
    /// type carries — peer to the same pair on numeric monoid types
    /// ([`std::time::Duration`] only carries a custom inherent parser
    /// for its richer alias surface, but every primitive numeric type
    /// closes the pair), on [`std::net::IpAddr`], on [`std::net::SocketAddr`],
    /// and on every `Uuid` / `Url` / similar serializable type in the
    /// surrounding ecosystem.
    ///
    /// **Round-trip law** — for every `h: AxisHistogram<A>`,
    /// `format!("{h}").parse::<AxisHistogram<A>>() == Ok(h)`. The
    /// canonical stdlib [`(Display, FromStr)`][std::fmt::Display]
    /// round-trip discipline pinned by construction on the
    /// labeled-axis sub-surface. Pinned uniformly across every
    /// [`ClosedAxisLabel`] implementor by
    /// [`tests::axis_histogram_display_from_str_round_trip_for_every_closed_axis_label_implementor`].
    ///
    /// **Acceptance shape.** Accepts the comma-separated `<label>=<count>`
    /// form Display emits, in any order over the axis labels (the parser
    /// does not require declaration-order arrival — a caller building
    /// the input by hand or a permuted serializer's output both parse).
    /// Labels are matched case-insensitively over ASCII via
    /// [`ClosedAxisLabel::from_canonical_str`] (the same case-folding
    /// the trait's `from_canonical_str` carries). The empty input
    /// string parses to [`AxisHistogram::empty`] — the natural identity
    /// case, peer of the empty-histogram emission law on Display.
    /// Missing labels default to count `0` on the produced histogram
    /// so a caller can elide zero-cells on the input side without
    /// losing the round-trip law.
    ///
    /// **Rejection shape.** Four structurally distinct rejection
    /// reasons, each surfaced as a [`ParseAxisHistogramError`]
    /// variant carrying the offending substring verbatim:
    /// - [`ParseAxisHistogramError::MissingEquals`] — a pair lacked
    ///   the `=` separator.
    /// - [`ParseAxisHistogramError::UnknownLabel`] — a label did not
    ///   match any canonical name on the axis.
    /// - [`ParseAxisHistogramError::InvalidCount`] — a count substring
    ///   did not parse as [`usize`].
    /// - [`ParseAxisHistogramError::DuplicateLabel`] — a label appeared
    ///   more than once.
    ///
    /// **Order-invariance law** — for every permutation `π` of the
    /// pair sequence on a Display emission, `format!("{h}").parse::<
    /// AxisHistogram<A>>() == permute(format!("{h}"), π).parse::<
    /// AxisHistogram<A>>()`. The parser accumulates into a per-ordinal
    /// counts slot indexed by [`axis_ordinal`], so the input order
    /// only governs the iteration order, not the produced histogram.
    /// Pinned concretely on [`crate::DiffLineKind`] by
    /// [`tests::axis_histogram_from_str_is_order_invariant_for_diff_line_kind`].
    ///
    /// **Missing-labels-default-to-zero law** — for every subset
    /// `S ⊆ ClosedAxis::ALL` and every count assignment over `S`,
    /// the parsed histogram reads zero on every cell outside `S`. The
    /// elided-cell convenience peers the empty-input identity law:
    /// the parser distinguishes "this cell appeared with `=0`" from
    /// "this cell was elided" by producing the same zero count on
    /// either input. Pinned concretely on [`crate::DiffLineKind`] by
    /// [`tests::axis_histogram_from_str_missing_labels_default_to_zero_for_diff_line_kind`].
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        let mut hist = Self::empty();
        if s.is_empty() {
            return Ok(hist);
        }
        let cardinality = axis_cardinality::<A>();
        let mut seen = vec![false; cardinality];
        for pair in s.split(", ") {
            let (label, count) =
                pair.split_once('=')
                    .ok_or_else(|| ParseAxisHistogramError::MissingEquals {
                        pair: pair.to_owned(),
                    })?;
            let cell = <A as ClosedAxisLabel>::from_canonical_str(label).ok_or_else(|| {
                ParseAxisHistogramError::UnknownLabel {
                    label: label.to_owned(),
                }
            })?;
            let count: usize =
                count
                    .parse()
                    .map_err(|_| ParseAxisHistogramError::InvalidCount {
                        label: label.to_owned(),
                        count: count.to_owned(),
                    })?;
            let ordinal = axis_ordinal(cell);
            if seen[ordinal] {
                return Err(ParseAxisHistogramError::DuplicateLabel {
                    label: label.to_owned(),
                });
            }
            seen[ordinal] = true;
            hist.counts[ordinal] = count;
        }
        Ok(hist)
    }
}

impl<A: ClosedAxisLabel> serde::Serialize for AxisHistogram<A> {
    /// Serialize the histogram as the comma-separated
    /// `"<label₁>=<count₁>, …, <labelₙ>=<countₙ>"` string the
    /// [`Display`][std::fmt::Display] impl emits — the operator-facing
    /// scalar form the same `(Display, FromStr)` pair on the
    /// labeled-axis sub-surface (the pair landed in cce9769 and
    /// adc2450) carries on the round-trip law `parse(display(h)) ==
    /// Ok(h)`. Closes the canonical
    /// (`Serialize`, `Deserialize`) serde idiom-peer of the
    /// (`Display`, `FromStr`) stdlib pair every operator-facing
    /// serializable typescape primitive in shikumi (`Format`,
    /// `ShikumiErrorKind`, `ConfigSourceKind`, …) carries via
    /// `#[serde(rename_all = "kebab-case")]` on the enum surface.
    ///
    /// Routes through [`serde::Serializer::collect_str`] so the
    /// serialized representation is exactly `format!("{self}")` with
    /// no intermediate allocation on serializers that accept a
    /// streaming source — the YAML/JSON/TOML emitter sees one scalar
    /// string, the round-trip with [`Self::deserialize`] is the same
    /// bijection [`<Self as std::str::FromStr>::from_str`] already
    /// closes.
    ///
    /// **Round-trip law** — for every `h: AxisHistogram<A>`,
    /// `serde_yaml::from_str::<AxisHistogram<A>>(
    /// &serde_yaml::to_string(&h)?)? == h` and the same on
    /// `serde_json` — the canonical serde round-trip discipline pinned
    /// by construction on the labeled-axis sub-surface, peer of the
    /// `(Display, FromStr)` round-trip already pinned on the same
    /// surface. Pinned uniformly across every [`ClosedAxisLabel`]
    /// implementor by
    /// [`tests::axis_histogram_serde_yaml_round_trip_for_every_closed_axis_label_implementor`]
    /// and the `serde_json` peer test.
    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        serializer.collect_str(self)
    }
}

impl<'de, A: ClosedAxisLabel> serde::Deserialize<'de> for AxisHistogram<A> {
    /// Deserialize the histogram from the comma-separated
    /// `"<label>=<count>"` scalar string the
    /// [`Serialize`][serde::Serialize] impl emits and the
    /// [`FromStr`][std::str::FromStr] impl accepts — the operator-facing
    /// scalar form the labeled-axis sub-surface carries on the
    /// `(Display, FromStr)` round-trip pair, lifted to the serde
    /// surface via [`serde::Deserializer::deserialize_str`] with a
    /// visitor whose `visit_str` lowers to
    /// [`<Self as std::str::FromStr>::from_str`] and routes any
    /// [`ParseAxisHistogramError`] through
    /// [`serde::de::Error::custom`].
    ///
    /// The accept surface inherits the four-variant rejection shape of
    /// the [`FromStr`][std::str::FromStr] impl: a manifest field
    /// carrying an unknown label, a missing `=`, an invalid count, or
    /// a duplicated label surfaces at the serde error site with the
    /// offending substring verbatim — the same operator-facing
    /// localization the [`ParseAxisHistogramError`] [`Display`][std::fmt::Display]
    /// impl carries. The accept surface also inherits the
    /// missing-labels-default-to-zero law and the order-invariance law
    /// — an operator can elide zero-cells (`diff_shape: "added=5"`)
    /// or permute the pair sequence (`diff_shape: "context=3,
    /// added=2, removed=1"`) and recover the same typed histogram.
    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        struct AxisHistogramVisitor<A: ClosedAxisLabel>(std::marker::PhantomData<fn() -> A>);

        impl<A: ClosedAxisLabel> serde::de::Visitor<'_> for AxisHistogramVisitor<A> {
            type Value = AxisHistogram<A>;

            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
                write!(
                    f,
                    "a comma-separated `<label>=<count>` histogram string for axis {}",
                    std::any::type_name::<A>(),
                )
            }

            fn visit_str<E: serde::de::Error>(self, v: &str) -> Result<Self::Value, E> {
                v.parse::<AxisHistogram<A>>().map_err(E::custom)
            }
        }

        deserializer.deserialize_str(AxisHistogramVisitor::<A>(std::marker::PhantomData))
    }
}

/// Lift an iterator of axis observations into a typed
/// [`AxisHistogram<A>`] — the dense per-cell tally over
/// [`ClosedAxis::ALL`].
///
/// Generic over the [`ClosedAxis`] trait bound so the helper is
/// inherited uniformly across every implementor: a CLI `config-diff`
/// summary tallying added/removed/context lines on
/// [`crate::DiffLineKind`], a structured-diagnostic legend bucketing
/// reload failures by [`crate::ShikumiErrorKind`], a dashboard
/// initializing a per-axis counter from a snapshot of observations on
/// [`crate::SecretBackendKind`], an attestation manifest recording the
/// per-axis observation-mix histogram on
/// [`crate::WatchEventClass`] — each previously re-derived the
/// (filter, count) loop inline at every observation site. The lift
/// names the (closed-axis × iterable observations → per-cell counts)
/// projection at one site.
///
/// Convenience wrapper over `iter.into_iter().collect::<AxisHistogram<A>>()`
/// — same shape, named for symmetry with [`axis_iter`] / [`axis_at`] /
/// [`axis_ordinal`] / [`axis_cardinality`] on the closed-axis
/// generic-helper surface.
#[must_use]
pub fn axis_histogram<A: ClosedAxis, I: IntoIterator<Item = A>>(items: I) -> AxisHistogram<A> {
    items.into_iter().collect()
}

/// Closed labeling discipline trait — adds the canonical operator-facing
/// string label on top of [`ClosedAxis`].
///
/// Every typescape primitive that carries a canonical operator-facing
/// name (the string an operator types on the CLI, reads in a log line,
/// keys a dashboard column by) implements this trait. The trait is a
/// strict refinement of [`ClosedAxis`]: implementors close both the
/// `Self::ALL` enumeration discipline and the `(label → value)` /
/// `(value → label)` discipline through one trait, with the round-trip
/// law structural rather than per-primitive convention.
///
/// Implementors today: [`PartitionFace`] (the variant-tag projection of
/// [`PartitionOrdinal`]), [`crate::ConfigTierKind`] (the variant-tag
/// projection of [`crate::ConfigTier`]), [`crate::Format`] (the
/// operator-facing config file format axis — yaml/toml/lisp/nix),
/// [`crate::FormatProvenance`] (which provider class loads the format
/// — figment-builtin/shikumi-built), [`crate::ConfigSourceKind`] (the
/// kind axis of the resolved figment layer — defaults/env/file),
/// [`crate::FigmentSourceKind`] (the kind axis of the underlying
/// [`figment::Source`] — file/code/custom),
/// [`crate::AttributionConfidence`] (the equality-vs-uniqueness
/// confidence class of the resolver attribution — exact/fallback),
/// [`crate::AttributionAxis`] (the `figment::Metadata` field that
/// drove the resolver attribution — metadata-source/metadata-name),
/// [`crate::ShikumiErrorKind`] (the data-free discriminant of
/// [`crate::ShikumiError`] — not-found/parse/watch/io/figment/extract),
/// [`crate::FieldPathLocalization`] (the tri-state
/// figment-field-path localization axis of a [`crate::ShikumiError`]
/// — localized/figment-unlocalized/not-applicable), and
/// [`crate::AttributionRule`] (the closed five-rule resolver dispatch
/// axis —
/// file-by-source/file-by-metadata-name/env-by-prefix/env-by-uniqueness/defaults-by-code-uniqueness).
/// The eleven primitives share the same shape —
/// `#[non_exhaustive] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]`,
/// [`ClosedAxis`] over `Self::ALL`, operator-facing lowercase or
/// kebab-case canonical name — and the trait closes the labeling
/// discipline across all eleven uniformly. Every axis of every product
/// cube on the typescape now labels through the trait: both axes of
/// the 18-cell [`crate::ErrorLocalizationCoordinates`] cube
/// (`ShikumiErrorKind` × `FieldPathLocalization`), every axis of the
/// 12-cell [`crate::AttributionCoordinates`] cube
/// (`AttributionAxis` × `ConfigSourceKind` × `AttributionConfidence`),
/// both axes of the 9-cell [`crate::AttributionSourceKindCoordinates`]
/// cube (`FigmentSourceKind` × `ConfigSourceKind`), and both axes of
/// the 8-cell [`crate::FormatCoordinates`] cube
/// (`Format` × `FormatProvenance`) — every cell of every cube is
/// nameable through the trait without re-deriving a string mapping at
/// any cube-renderer site. The canonical implementor list lives in the
/// `for_each_closed_axis_label_implementor!` callback macro
/// (`cube::tests`) so every trait-uniform invariant test reaches the
/// implementor set by macro expansion rather than by repeated inline
/// listing.
///
/// **Round-trip law** — for every `v: Self`,
/// `Self::from_canonical_str(v.as_str()) == Some(v)`. Pinned by the
/// trait-uniform [`tests::closed_axis_label_round_trips_for_every_implementor`]
/// test, which reaches every implementor through the
/// [`for_each_closed_axis_label_implementor`] macro.
///
/// **Case insensitivity** — for every `v: Self`,
/// `Self::from_canonical_str(v.as_str().to_ascii_uppercase()) == Some(v)`.
/// The default [`Self::from_canonical_str`] uses
/// [`str::eq_ignore_ascii_case`], so the law is structural in the
/// default impl; implementors that override [`from_canonical_str`]
/// (none today) re-state the law via the same trait-uniform test.
///
/// **Distinctness** — `a.as_str() != b.as_str()` for `a != b: Self`.
/// The labels are an injection from the axis into the canonical-name
/// space; a duplicated label would collapse two variants to one parse
/// result. Pinned by
/// [`tests::closed_axis_label_as_str_distinct_for_every_implementor`].
///
/// **Non-emptiness** — `!v.as_str().is_empty()` for every `v: Self`.
/// The empty string is reserved for "missing label" at the consumer
/// boundary (e.g. an unset env var, an unfilled struct field) and must
/// never collide with a canonical name. Pinned by
/// [`tests::closed_axis_label_as_str_nonempty_for_every_implementor`].
///
/// **Empty parse** — `Self::from_canonical_str("") == None` for every
/// implementor. Composes with non-emptiness: the empty string can never
/// be a canonical label, so the parse rejects it uniformly. Pinned by
/// [`tests::closed_axis_label_rejects_empty_string_for_every_implementor`].
///
/// Future implementors (lift sites): with the
/// [`crate::AttributionRule`] lift landing, every closed-axis
/// primitive the typescape recognizes today labels through the trait,
/// and every axis of every product cube
/// ([`crate::FormatCoordinates`], [`crate::AttributionCoordinates`],
/// [`crate::ErrorLocalizationCoordinates`],
/// [`crate::AttributionSourceKindCoordinates`]) labels through the
/// trait on every axis. A future closed-axis primitive (a new
/// resolver-side discriminant, a new error-side discriminant, a new
/// figment-side classification) picks up the round-trip law + every
/// trait-uniform invariant test by adding one
/// `impl ClosedAxisLabel for X { fn as_str(self) -> &'static str { … } }`
/// declaration plus one arm to [`for_each_closed_axis_label_implementor`].
/// The default [`Self::from_canonical_str`] suffices on every
/// canonical-name-only parse; primitives that accept aliases (e.g.
/// [`crate::Format`]'s [`std::str::FromStr`] impl which accepts
/// `"yml"`/`"lsp"`/`"el"`) keep their richer [`std::str::FromStr`] in
/// addition to the canonical-only trait parse.
pub trait ClosedAxisLabel: ClosedAxis {
    /// Canonical operator-facing lowercase name of the axis value.
    ///
    /// The single source of truth for the value's string label —
    /// renderers, log formatters, structured-diagnostic legends, CLI
    /// help text, and parse helpers all route through this one method.
    /// `&'static str` so the label is allocation-free at every call
    /// site; no heap allocations for the rendering path.
    ///
    /// Implementors typically return a lowercase ASCII string matching
    /// the operator-facing convention (the same form an operator would
    /// type into an env var or CLI flag); [`Self::from_canonical_str`]
    /// is case-insensitive over ASCII, so the rendering vs. parsing
    /// asymmetry stays on the parse side only.
    fn as_str(self) -> &'static str;

    /// Case-insensitive ASCII parse of the canonical name produced by
    /// [`Self::as_str`]. Returns [`None`] for any other input.
    ///
    /// The default impl is a linear scan of [`ClosedAxis::ALL`] matching
    /// pointwise via [`str::eq_ignore_ascii_case`]. The implementation
    /// is structural: adding a variant only extends [`Self::as_str`];
    /// the parse picks the new variant up automatically through
    /// [`ClosedAxis::ALL`]. Implementors override only when the parse
    /// surface diverges from the rendering surface (e.g. when the
    /// canonical name has aliases on the parse side — none of the
    /// trait's current implementors do).
    ///
    /// `from_canonical_str` returns [`Option`] rather than implementing
    /// [`std::str::FromStr`] (which would force a `Result<_, Err>` shape
    /// and an error-type ceremony for the no-error case where "not a
    /// canonical name" is the only failure mode the caller cares about).
    /// Primitives that need a [`std::str::FromStr`] impl with a typed
    /// error (e.g. [`crate::Format`]) keep their inherent impl in
    /// addition; the trait parse stays focused on the round-trip-with-
    /// [`as_str`][Self::as_str] case.
    ///
    /// **Round-trip law** —
    /// `Self::from_canonical_str(v.as_str()) == Some(v)` for every
    /// `v: Self`. Pinned by
    /// [`tests::closed_axis_label_round_trips_for_every_implementor`].
    /// The default impl satisfies the law by construction over the
    /// [`ClosedAxis`] discipline.
    fn from_canonical_str(s: &str) -> Option<Self> {
        Self::ALL
            .iter()
            .copied()
            .find(|v| v.as_str().eq_ignore_ascii_case(s))
    }
}

/// Canonical operator-facing label of a [`ClosedAxisLabel`] value —
/// [`ClosedAxisLabel::as_str`] reached as a free function generic over
/// the axis type.
///
/// Mirror of [`realizable_count`]/[`axis_cardinality`]: the trait method
/// reached through a named helper so generic code routes over the label
/// surface without naming the [`ClosedAxisLabel`] trait at the call site.
/// Where [`axis_label`] resolves a typed axis value to its canonical
/// name, [`axis_from_label`] is its partial inverse over the
/// canonical-name space; the pair closes the label bijection on the
/// recognized-name image the same way [`axis_ordinal`]/[`axis_at`] close
/// the ordinal bijection on the natural-number prefix.
///
/// **Agreement** — `axis_label(v) == v.as_str()` for every `v: L`,
/// pinned by the trait-uniform
/// [`tests::axis_label_free_fn_matches_trait_as_str_for_every_implementor`]
/// across every [`ClosedAxisLabel`] implementor. The free function adds
/// no behavior; it only relocates the call to a generic, trait-name-free
/// site.
///
/// **Consumers** — structured-diagnostic legends, log formatters, and
/// cube-cover dashboards that already route over a `ClosedAxis` /
/// `ProductCube` type parameter via [`axis_iter`] / [`realizable_iter`]
/// name the same cell's canonical label through [`axis_label`] without
/// adding a `where L: ClosedAxisLabel` import of the trait method into
/// the call site — the label join stays at the free-function layer with
/// the rest of the typescape vocabulary.
#[must_use]
pub fn axis_label<L: ClosedAxisLabel>(value: L) -> &'static str {
    value.as_str()
}

/// Parse a [`ClosedAxisLabel`] value from its canonical operator-facing
/// label — [`ClosedAxisLabel::from_canonical_str`] reached as a free
/// function generic over the axis type.
///
/// Partial inverse of [`axis_label`] over the canonical-name space:
/// returns [`Some`] exactly on a case-insensitive match against some
/// `v.as_str()`, [`None`] on every other input (including the empty
/// string — no canonical label is empty). Stands to [`axis_label`] as
/// [`axis_at`] stands to [`axis_ordinal`]: the safe, partial direction of
/// the bijection surfaced as a free function so deserializers of
/// attestation manifests (THEORY.md §III.1.8 module manifests, §V.3
/// three-pillar attestation) that carry typescape cells by canonical
/// name recover the typed value without naming the [`ClosedAxisLabel`]
/// trait at the loader site.
///
/// **Agreement** — `axis_from_label::<L>(s) == L::from_canonical_str(s)`
/// for every `s`, pinned by the trait-uniform
/// [`tests::axis_from_label_free_fn_matches_trait_for_every_implementor`].
///
/// **Round-trip law** — `axis_from_label::<L>(axis_label(v)) == Some(v)`
/// for every `v: L` — the free-function form of the
/// [`ClosedAxisLabel`] round-trip law, pinned by
/// [`tests::axis_label_free_fn_round_trips_for_every_implementor`].
#[must_use]
pub fn axis_from_label<L: ClosedAxisLabel>(s: &str) -> Option<L> {
    L::from_canonical_str(s)
}

/// Closed discipline trait every typescape product cube satisfies — a
/// refinement of [`ClosedAxis`] that additionally pins the
/// realizability predicate over the recognized-image cells.
///
/// A product cube is a `Copy + Eq + Hash + #[non_exhaustive]` struct
/// whose fields are typescape axis primitives (each itself a closed
/// `#[non_exhaustive]` enum with its own `::ALL` constant via
/// [`ClosedAxis`]), enumerating every cell of the structural Cartesian
/// product over the axis constituent enums.
///
/// Implementors:
///
/// - [`crate::FormatCoordinates`] —
///   `Format × FormatProvenance` (4 × 2 = 8 cells, 4 realizable).
/// - [`crate::AttributionCoordinates`] —
///   `AttributionAxis × ConfigSourceKind × AttributionConfidence`
///   (2 × 3 × 2 = 12 cells, 5 realizable).
/// - [`crate::ErrorLocalizationCoordinates`] —
///   `ShikumiErrorKind × FieldPathLocalization` (6 × 3 = 18 cells,
///   8 realizable).
/// - [`crate::AttributionSourceKindCoordinates`] —
///   `FigmentSourceKind × ConfigSourceKind` (3 × 3 = 9 cells,
///   2 realizable).
///
/// The trait is intentionally not object-safe (`Self`-by-value method)
/// — consumers route generically over the cube type parameter, not
/// over `dyn ProductCube` trait objects.
pub trait ProductCube: ClosedAxis {
    /// Realizability predicate: `true` exactly on the cells some
    /// recognized typescape value occupies, `false` on the cross-axis
    /// consistency-violation complement.
    ///
    /// Mirror of the inherent `Self::is_realizable` method every
    /// implementor already exposes. The trait re-export lets generic
    /// helpers (`realizable_iter`, `unrealizable_iter`,
    /// `realizable_count`, `unrealizable_count`) reach the predicate
    /// without naming the concrete cube type — the per-cube
    /// `inherent_is_realizable_matches_trait_is_realizable` tests pin
    /// the two methods to the same image pointwise.
    fn is_realizable(self) -> bool;
}

/// Iterate the realizable cells of a [`ProductCube`] —
/// `C::ALL.iter().copied().filter(|c| c.is_realizable())` collapsed to
/// one named helper.
///
/// Consolidates the per-cube `ALL.iter().copied().filter(|c|
/// c.is_realizable())` pattern that appeared at the
/// `*_is_realizable_image_equals_*` test site on each cube. Generic in
/// the cube type so a future fifth cube inherits the helper at the
/// `impl ProductCube` declaration.
pub fn realizable_iter<C: ProductCube>() -> impl Iterator<Item = C> {
    C::ALL.iter().copied().filter(|c| c.is_realizable())
}

/// Iterate the unrealizable cells of a [`ProductCube`] —
/// `C::ALL.iter().copied().filter(|c| !c.is_realizable())` collapsed
/// to one named helper.
///
/// Consolidates the per-cube `ALL.iter().copied().filter(|c|
/// !c.is_realizable())` pattern that appeared at the
/// `*_unrealizable_cells_have_no_inverse` test site on each cube.
/// Generic in the cube type so a future fifth cube inherits the helper
/// at the `impl ProductCube` declaration.
pub fn unrealizable_iter<C: ProductCube>() -> impl Iterator<Item = C> {
    C::ALL.iter().copied().filter(|c| !c.is_realizable())
}

/// Count the realizable cells of a [`ProductCube`].
///
/// Today's image cardinalities — 4 (`FormatCoordinates`), 5
/// (`AttributionCoordinates`), 8 (`ErrorLocalizationCoordinates`), 2
/// (`AttributionSourceKindCoordinates`) — reachable as one method call
/// without re-deriving the count from the partial inverse or the
/// inherent `is_realizable` filter inline. Future variant additions on
/// any constituent axis enum extend the count in lockstep with the
/// realizable image.
#[must_use]
pub fn realizable_count<C: ProductCube>() -> usize {
    realizable_iter::<C>().count()
}

/// Count the unrealizable cells of a [`ProductCube`] —
/// `C::ALL.len() - realizable_count::<C>()` collapsed to one named
/// helper.
///
/// Today's complement cardinalities — 4 (`FormatCoordinates`), 7
/// (`AttributionCoordinates`), 10 (`ErrorLocalizationCoordinates`), 7
/// (`AttributionSourceKindCoordinates`) — reachable as one method call
/// without re-deriving the count from the cube-cardinality-minus-image
/// formula inline.
#[must_use]
pub fn unrealizable_count<C: ProductCube>() -> usize {
    unrealizable_iter::<C>().count()
}

/// Dense ordinal of a [`ProductCube`] cell over the realizable surface
/// — the position of `cell` in [`realizable_iter::<C>()`], or [`None`]
/// on the cross-axis consistency-violation complement.
///
/// Cube-level dense embedding analog of [`axis_ordinal`]: where
/// [`axis_ordinal`] is the total inverse `value → ordinal` over the
/// closed axis with image `0..axis_cardinality::<A>()`, [`realizable_ordinal`]
/// is the partial inverse `cell → Option<ordinal>` over the cube with
/// image `0..realizable_count::<C>()` on realizable cells and [`None`]
/// on the unrealizable complement. The realizable surface is the
/// recognized-image half of the cube — the cells some typescape value
/// occupies — and the dense ordinal indexes that half in
/// declaration order over the underlying [`ClosedAxis::ALL`] slice,
/// skipping the interleaved unrealizable cells.
///
/// Concretely, [`crate::FormatCoordinates::ALL`] lays its 8 cells in
/// lex order over (`format × provenance`); the 4 realizable cells sit
/// at full-cube indices 0, 2, 5, 7 (the ones where
/// `provenance == format.provenance()`). [`axis_ordinal`] returns 0,
/// 2, 5, 7 on those cells (the position in `FormatCoordinates::ALL`);
/// [`realizable_ordinal`] returns 0, 1, 2, 3 (the dense position in
/// `realizable_iter::<FormatCoordinates>()`). The two ordinals differ
/// whenever the realizable cells are interleaved with unrealizable
/// ones in `C::ALL` — i.e. on every cube whose `is_realizable`
/// surface is not a prefix of `C::ALL`.
///
/// **Partiality on the value side** —
/// `realizable_ordinal::<C>(cell).is_some() == ProductCube::is_realizable(cell)`,
/// pinned by [`tests::realizable_ordinal_some_iff_is_realizable`].
/// The dense ordinal is defined exactly on the realizable surface;
/// unrealizable cells return [`None`] uniformly.
///
/// **Image equals the realizable prefix** — the ordinal image over
/// the realizable surface equals `0..realizable_count::<C>()` as a
/// set, pinned by
/// [`tests::realizable_ordinal_image_equals_realizable_prefix`]. The
/// embedding is a dense injection onto the natural-number prefix,
/// with the prefix length equal to the realizable-cell count.
///
/// **Round-trip with [`realizable_at`]** —
/// `realizable_at::<C>(realizable_ordinal::<C>(cell).unwrap()) == Some(cell)`
/// for every realizable cell, pinned by
/// [`tests::realizable_round_trips_cell_side`]. The pair
/// ([`realizable_ordinal`], [`realizable_at`]) closes the partial
/// bijection between the realizable surface and the natural-number
/// prefix `0..realizable_count::<C>()`.
///
/// **Consumers** — future cube-cover dashboards that order rows by
/// the dense ordinal over the realizable surface (instead of by the
/// full-cube ordinal that interleaves the unrealizable complement)
/// reach the position through one helper; attestation manifests
/// (THEORY.md §III.1.8 module manifests, §V.3 three-pillar
/// attestation) that hash the realizable surface in stable dense
/// declaration order index through the dense ordinal without an
/// inline `realizable_iter::<C>().position(|c| c == cell)` per
/// hasher; dense arrays sized by
/// [`realizable_count::<C>()`][realizable_count] (one slot per
/// realizable cell, rather than `axis_cardinality::<C>()` slots that
/// waste one per unrealizable cell) index through the dense ordinal.
#[must_use]
pub fn realizable_ordinal<C: ProductCube>(cell: C) -> Option<usize> {
    realizable_iter::<C>().position(|c| c == cell)
}

/// Dense ordinal lookup over the realizable surface of a
/// [`ProductCube`] — the realizable cell at position `ordinal` in
/// [`realizable_iter::<C>()`], or [`None`] if the index is
/// out-of-range.
///
/// Safe forward dual of [`realizable_ordinal`]: where
/// [`realizable_ordinal`] is the partial inverse `cell → Option<ordinal>`
/// over the cube (`Some` exactly on the realizable surface,
/// [`None`] on the unrealizable complement), [`realizable_at`] is the
/// partial forward `ordinal → Option<cell>` over `usize`, returning
/// [`Some`] exactly on the prefix `0..realizable_count::<C>()` and
/// [`None`] outside it. The pair ([`realizable_ordinal`],
/// [`realizable_at`]) closes the bijection between the realizable
/// surface and the natural-number prefix in both directions, the
/// cube-level analog of the ([`axis_ordinal`], [`axis_at`]) pair
/// over the closed axis.
///
/// **Bijection laws** — pinned by trait-uniform tests reaching every
/// implementor pointwise:
///
/// 1. **Round-trip from the cell side** —
///    `realizable_at::<C>(realizable_ordinal::<C>(cell).unwrap()) == Some(cell)`
///    for every realizable `cell: C`. The ordinal-then-lookup
///    composition is the identity on the realizable surface.
/// 2. **Round-trip from the ordinal side** —
///    `realizable_at::<C>(i).and_then(realizable_ordinal::<C>) == Some(i)`
///    for every `i < realizable_count::<C>()`. The lookup-then-ordinal
///    composition is the identity on the in-range prefix.
/// 3. **Partiality on out-of-range** —
///    `realizable_at::<C>(i).is_none()` for every
///    `i >= realizable_count::<C>()`. The forward map is total over
///    the prefix and undefined outside it; the [`Option`] return
///    surfaces the partiality at the type level instead of by
///    convention.
/// 4. **Image is realizable** —
///    `realizable_at::<C>(i).map(ProductCube::is_realizable) == Some(true)`
///    for every in-range `i`. The forward map lands on the
///    realizable surface by construction.
///
/// **Consumers** — deserializing attestation manifests
/// (THEORY.md §III.1.8 module manifests, §V.3 three-pillar
/// attestation) that carry realizable cells by stable dense
/// declaration ordinal recover the typed cell via [`realizable_at`]
/// without a `realizable_iter::<C>().nth(i)` inline at every loader
/// site. Dense arrays sized by [`realizable_count::<C>()`][realizable_count]
/// (one slot per realizable cell, indexed by dense ordinal) look up
/// the typed cell at a given position safely. Future cube-cover
/// dashboards that render rows keyed by dense ordinal index recover
/// the row's typescape cell through one named helper rather than
/// re-deriving the iterator-`nth` per renderer.
#[must_use]
pub fn realizable_at<C: ProductCube>(ordinal: usize) -> Option<C> {
    realizable_iter::<C>().nth(ordinal)
}

/// Dense ordinal of a [`ProductCube`] cell over the unrealizable
/// complement — the position of `cell` in [`unrealizable_iter::<C>()`],
/// or [`None`] on the recognized-image realizable surface.
///
/// Symmetric dual of [`realizable_ordinal`]: where
/// [`realizable_ordinal`] is the partial inverse
/// `cell → Option<ordinal>` over the cube with image
/// `0..realizable_count::<C>()` on realizable cells and [`None`] on the
/// unrealizable complement, [`unrealizable_ordinal`] is the same
/// partial inverse over the opposite half of the cube — `Some(ordinal)`
/// with image `0..unrealizable_count::<C>()` on the cross-axis
/// consistency-violation cells and [`None`] on the realizable surface.
/// The unrealizable surface is the complement of the recognized image —
/// the cells no typescape value occupies — and the dense ordinal indexes
/// that half in declaration order over the underlying [`ClosedAxis::ALL`]
/// slice, skipping the interleaved realizable cells.
///
/// Concretely, [`crate::FormatCoordinates::ALL`] lays its 8 cells in
/// lex order over (`format × provenance`); the 4 unrealizable cells sit
/// at full-cube indices 1, 3, 4, 6 (the ones where
/// `provenance != format.provenance()`). [`axis_ordinal`] returns 1, 3,
/// 4, 6 on those cells (the position in `FormatCoordinates::ALL`);
/// [`unrealizable_ordinal`] returns 0, 1, 2, 3 (the dense position in
/// `unrealizable_iter::<FormatCoordinates>()`).
///
/// **Partiality on the value side** —
/// `unrealizable_ordinal::<C>(cell).is_some() == !ProductCube::is_realizable(cell)`,
/// pinned by [`tests::unrealizable_ordinal_some_iff_not_is_realizable`].
/// The dense ordinal is defined exactly on the unrealizable complement;
/// realizable cells return [`None`] uniformly. Together with
/// [`realizable_ordinal`], the two ordinals partition the cube cleanly:
/// every cell has exactly one defined ordinal (either dense-realizable
/// or dense-unrealizable, never both), pinned by
/// [`tests::realizable_and_unrealizable_ordinals_partition_cube`].
///
/// **Image equals the unrealizable prefix** — the ordinal image over
/// the unrealizable complement equals `0..unrealizable_count::<C>()`
/// as a set, pinned by
/// [`tests::unrealizable_ordinal_image_equals_unrealizable_prefix`].
/// The embedding is a dense injection onto the natural-number prefix.
///
/// **Round-trip with [`unrealizable_at`]** —
/// `unrealizable_at::<C>(unrealizable_ordinal::<C>(cell).unwrap()) == Some(cell)`
/// for every unrealizable cell, pinned by
/// [`tests::unrealizable_round_trips_cell_side`]. The pair
/// ([`unrealizable_ordinal`], [`unrealizable_at`]) closes the partial
/// bijection between the unrealizable complement and the natural-number
/// prefix `0..unrealizable_count::<C>()`, mirroring the realizable-half
/// bijection on the cube's opposite face.
///
/// **Consumers** — error-path messaging that reports cross-axis
/// consistency violations by stable dense violation-ordinal (e.g.
/// "consistency violation #N of M for cube C") indexes through the
/// ordinal without an inline
/// `unrealizable_iter::<C>().position(|c| c == cell)` per call site;
/// dense observability counters sized by
/// [`unrealizable_count::<C>()`][unrealizable_count] (one slot per
/// consistency-violation cell, rather than [`axis_cardinality::<C>()`][axis_cardinality]
/// slots that waste one per realizable cell) index through the dense
/// ordinal; future cube-cover dashboards that render the complement
/// half symmetrically with the realizable half reach the position
/// through one helper rather than re-deriving the iterator-`position`
/// per renderer.
#[must_use]
pub fn unrealizable_ordinal<C: ProductCube>(cell: C) -> Option<usize> {
    unrealizable_iter::<C>().position(|c| c == cell)
}

/// Dense ordinal lookup over the unrealizable complement of a
/// [`ProductCube`] — the unrealizable cell at position `ordinal` in
/// [`unrealizable_iter::<C>()`], or [`None`] if the index is
/// out-of-range.
///
/// Safe forward dual of [`unrealizable_ordinal`] and symmetric dual of
/// [`realizable_at`]: where [`unrealizable_ordinal`] is the partial
/// inverse `cell → Option<ordinal>` over the cube (`Some` exactly on
/// the unrealizable complement, [`None`] on the realizable surface),
/// [`unrealizable_at`] is the partial forward
/// `ordinal → Option<cell>` over `usize`, returning [`Some`] exactly
/// on the prefix `0..unrealizable_count::<C>()` and [`None`] outside
/// it. The pair ([`unrealizable_ordinal`], [`unrealizable_at`]) closes
/// the bijection between the unrealizable complement and the
/// natural-number prefix in both directions, mirroring the
/// ([`realizable_ordinal`], [`realizable_at`]) pair on the cube's
/// opposite face. Together the two pairs close the cube's surface
/// algebra symmetrically: every full-cube cell has exactly one defined
/// dense ordinal (realizable or unrealizable, never both), and every
/// in-range dense ordinal on either side lands on a cell of the
/// matching realizability.
///
/// **Bijection laws** — pinned by trait-uniform tests reaching every
/// implementor pointwise:
///
/// 1. **Round-trip from the cell side** —
///    `unrealizable_at::<C>(unrealizable_ordinal::<C>(cell).unwrap()) == Some(cell)`
///    for every unrealizable `cell: C`. The ordinal-then-lookup
///    composition is the identity on the unrealizable complement.
/// 2. **Round-trip from the ordinal side** —
///    `unrealizable_at::<C>(i).and_then(unrealizable_ordinal::<C>) == Some(i)`
///    for every `i < unrealizable_count::<C>()`. The
///    lookup-then-ordinal composition is the identity on the in-range
///    prefix.
/// 3. **Partiality on out-of-range** —
///    `unrealizable_at::<C>(i).is_none()` for every
///    `i >= unrealizable_count::<C>()`. The forward map is total over
///    the prefix and undefined outside it; the [`Option`] return
///    surfaces the partiality at the type level instead of by
///    convention.
/// 4. **Image is unrealizable** —
///    `unrealizable_at::<C>(i).map(ProductCube::is_realizable) == Some(false)`
///    for every in-range `i`. The forward map lands on the
///    unrealizable complement by construction — the dual of the
///    realizable-image invariant on [`realizable_at`].
///
/// **Consumers** — error-path messaging that decodes a captured
/// dense violation-ordinal back into the typed
/// `(axis, layer_kind, confidence)` (or analogous) cell — e.g. a
/// reload-failure observability slot stamped with the dense ordinal
/// of the consistency violation hit — recovers the typed cell via
/// [`unrealizable_at`] without an
/// `unrealizable_iter::<C>().nth(i)` inline at every decoder site.
/// Dense observability arrays sized by
/// [`unrealizable_count::<C>()`][unrealizable_count] (one slot per
/// violation cell, indexed by dense ordinal) look up the typed cell at
/// a given position safely.
#[must_use]
pub fn unrealizable_at<C: ProductCube>(ordinal: usize) -> Option<C> {
    unrealizable_iter::<C>().nth(ordinal)
}

/// Typed witness of which half of a [`ProductCube`] a cell occupies —
/// the recognized-image realizable surface or the cross-axis
/// consistency-violation unrealizable complement. The variant tag of
/// [`PartitionOrdinal`] lifted into its own closed-axis typescape
/// primitive.
///
/// Two variants, in declaration order:
///
/// - [`PartitionFace::Realizable`] — the cube's recognized-image half;
///   `ProductCube::is_realizable(cell) == true`.
/// - [`PartitionFace::Unrealizable`] — the cube's cross-axis
///   consistency-violation complement;
///   `ProductCube::is_realizable(cell) == false`.
///
/// [`PartitionOrdinal`] carries a [`PartitionFace`] tag plus a dense
/// inner ordinal on that face; [`PartitionOrdinal::face`] projects the
/// tag without unpacking the inner ordinal. A consumer that only needs
/// "which half does this cell sit on?" — a face-keyed observability
/// counter, a manifest field discriminating recognized cells from
/// consistency-violation cells without addressing the specific cell —
/// carries a [`PartitionFace`] (one byte, [`Copy`]) rather than the
/// full [`PartitionOrdinal`] (the variant tag plus the dense
/// inner-ordinal `usize`) at every slot. The tag is in lockstep with
/// the cube's [`ProductCube::is_realizable`] predicate pointwise —
/// pinned by [`tests::partition_ordinal_face_agrees_with_is_realizable`]
/// over every cell of every cube via [`for_each_product_cube`].
///
/// [`PartitionFace`] is itself a [`ClosedAxis`] primitive (the tenth on
/// the typescape) — exposes `Self::ALL = &[Realizable, Unrealizable]`
/// and inherits the [`axis_iter`], [`axis_cardinality`], [`axis_ordinal`],
/// [`axis_at`] generic helpers at the trait-impl declaration. A
/// face-keyed dashboard row iterates the two faces uniformly through
/// [`axis_iter::<PartitionFace>()`][axis_iter] rather than re-deriving
/// `[Realizable, Unrealizable]` inline at every renderer.
///
/// **Stdlib idiom quintet.** Carries the `(Display, FromStr, Serialize,
/// Deserialize)` quartet rooted on the `(as_str, from_canonical_str)`
/// canonical-name pair, plus [`Ord`] + [`PartialOrd`] in
/// declaration-order (`Realizable < Unrealizable`). Idiom-peer of the
/// same quintet on the four typed-class / typed-bucket cube classifiers
/// ([`ModalityClass`], [`SupportCardinalityClass`],
/// [`SupportBoundaryDistance`], [`SupportMagnitudeDirection`]) — each of
/// which carries `(Display, FromStr, Serialize, Deserialize, Ord,
/// PartialOrd)` rooted on its own `(as_str, from_canonical_str)` pair.
/// A face emitted into a YAML attestation manifest, a JSON observability
/// payload, or a structured-log scalar field serializes natively through
/// the serde impls — no consumer-side fallback to
/// `axis_label::<PartitionFace>(face)` at the renderer. A
/// `BTreeMap<PartitionFace, T>` rollup keyed on the face axis emits in
/// declaration order (`Realizable` first) under the [`Ord`] derive
/// without naming a comparator.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)]
pub enum PartitionFace {
    /// The cube's recognized-image realizable surface — cells some
    /// typescape value occupies. Matches
    /// [`ProductCube::is_realizable`] returning `true`.
    Realizable,
    /// The cube's cross-axis consistency-violation complement — cells
    /// no typescape value occupies. Matches
    /// [`ProductCube::is_realizable`] returning `false`.
    Unrealizable,
}

impl PartitionFace {
    /// Every [`PartitionFace`] value, in declaration order.
    ///
    /// Mirror of the [`ClosedAxis::ALL`] trait constant; consumers
    /// reach the same slice through either path. Length 2 — pinned by
    /// [`tests::partition_face_all_has_two_entries`] and by the
    /// [`for_each_closed_axis_primitive`] macro cardinality checksum.
    pub const ALL: &'static [Self] = &[Self::Realizable, Self::Unrealizable];

    /// `true` exactly on [`PartitionFace::Realizable`].
    ///
    /// The face-level dual of [`ProductCube::is_realizable`]: where
    /// the cube method classifies a cell on a specific cube, this
    /// method classifies the face tag itself, regardless of which cube
    /// the face was produced from. Pinned in lockstep with the cube
    /// predicate by
    /// [`tests::partition_ordinal_face_agrees_with_is_realizable`].
    #[must_use]
    pub const fn is_realizable(self) -> bool {
        matches!(self, Self::Realizable)
    }

    /// Canonical operator-facing lowercase name of the face —
    /// `"realizable"` or `"unrealizable"`.
    ///
    /// The single source of truth for the face-label strings on the
    /// [`PartitionFace`] axis. Inherent mirror of the [`ClosedAxisLabel`]
    /// trait method; the trait impl delegates here so both routes (the
    /// inherent `face.as_str()` and the trait-generic
    /// `<PartitionFace as ClosedAxisLabel>::as_str(face)`) return the
    /// same `&'static str` pointwise — pinned by
    /// [`tests::closed_axis_label_round_trips_for_every_implementor`]
    /// over the [`ClosedAxisLabel::from_canonical_str`] round-trip law.
    ///
    /// Used by face-keyed dashboard headers, structured-log fields
    /// recording which half of a [`ProductCube`] a captured cell sits
    /// on, and operator-facing CLI emissions of
    /// `partition_face_iter` rendering output without inlining the two
    /// strings `"realizable"`/`"unrealizable"` at each renderer.
    #[must_use]
    pub const fn as_str(self) -> &'static str {
        match self {
            Self::Realizable => "realizable",
            Self::Unrealizable => "unrealizable",
        }
    }
}

impl std::fmt::Display for PartitionFace {
    /// Operator-facing rendering of the face tag — delegates to
    /// [`PartitionFace::as_str`] pointwise.
    ///
    /// Closes the canonical Rust stdlib (`Debug`, `Display`) duality
    /// every stdlib-style closed enum carries: where `Debug` (derived
    /// above) renders the Rust identifier (`Realizable` /
    /// `Unrealizable`), `Display` renders the canonical operator-facing
    /// label (`realizable` / `unrealizable`). Idiom-peer of the same
    /// `Display` impl on the four typed-cube-classifier surfaces
    /// ([`ModalityClass`], [`SupportCardinalityClass`],
    /// [`SupportBoundaryDistance`], [`SupportMagnitudeDirection`]).
    ///
    /// **Round-trip with [`FromStr`][std::str::FromStr]** —
    /// `v.to_string().parse::<PartitionFace>().unwrap() == v` for every
    /// `v: PartitionFace`. Pinned by
    /// [`tests::partition_face_from_str_round_trips_through_display`].
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(self.as_str())
    }
}

/// Typed parse failure of [`<PartitionFace as
/// std::str::FromStr>::from_str`] — the offending input was not a
/// canonical name on the [`PartitionFace`] surface.
///
/// The two-variant face axis carries a small closed label set
/// (`"realizable"`, `"unrealizable"`), so the parser's single rejection
/// mode is "input did not match any canonical name". This struct
/// carries the offending substring verbatim in the `label` field so a
/// downstream consumer can localize the failure to the surrounding
/// context (a YAML attestation manifest field, a structured-log
/// face-keyed scalar, a CLI argument).
///
/// `#[non_exhaustive]` so a future stricter parse rule (e.g. an
/// `EmptyInput` distinguished from `UnknownLabel`) lands as a new
/// variant without a SemVer-major bump. Idiom-peer of
/// [`ParseModalityClassError`], [`ParseSupportCardinalityClassError`],
/// [`ParseSupportBoundaryDistanceError`], and
/// [`ParseSupportMagnitudeDirectionError`] on the four
/// typed-cube-classifier surfaces.
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct ParsePartitionFaceError {
    /// The offending input substring, verbatim.
    pub label: String,
}

impl std::fmt::Display for ParsePartitionFaceError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "unknown partition face label {:?}", self.label)
    }
}

impl std::error::Error for ParsePartitionFaceError {}

impl std::str::FromStr for PartitionFace {
    type Err = ParsePartitionFaceError;

    /// Parse the face tag from the canonical lowercase label
    /// [`PartitionFace::as_str`] emits — the canonical Rust stdlib
    /// [`FromStr`][std::str::FromStr] idiom-peer of the
    /// [`Display`][std::fmt::Display] impl. Delegates to
    /// [`<Self as ClosedAxisLabel>::from_canonical_str`] for the
    /// case-insensitive lookup, lifting the [`Option<Self>`] failure
    /// to a typed [`ParsePartitionFaceError`] so the
    /// [`std::error::Error`] bound is satisfied at consumer sites
    /// requiring `Result<_, Box<dyn Error>>` (`eyre::Result<_>`,
    /// structured-log error fields, deserialization error chaining).
    ///
    /// **Round-trip law** —
    /// `v.to_string().parse::<PartitionFace>().unwrap() == v` for every
    /// `v: PartitionFace`. Pinned by
    /// [`tests::partition_face_from_str_round_trips_through_display`].
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        <Self as ClosedAxisLabel>::from_canonical_str(s).ok_or_else(|| ParsePartitionFaceError {
            label: s.to_owned(),
        })
    }
}

impl serde::Serialize for PartitionFace {
    /// Serialize the face tag as the canonical operator-facing
    /// lowercase label [`Self::as_str`] emits — the same scalar the
    /// [`Display`][std::fmt::Display] impl writes. Routes through
    /// [`serde::Serializer::collect_str`] so the serialized
    /// representation is exactly `format!("{self}")` with no
    /// intermediate allocation.
    ///
    /// Closes the canonical (`Serialize`, `Deserialize`) serde
    /// idiom-peer of the (`Display`, `FromStr`) stdlib pair on the
    /// face-tag surface — idiom-peer of the same lift on the four
    /// typed-cube-classifier surfaces. A face emitted into a YAML
    /// attestation manifest field, a JSON observability payload, or
    /// any consumer struct holding a `PartitionFace` field under
    /// `#[derive(Serialize, Deserialize)]` round-trips through the
    /// canonical label without a consumer-side rename helper.
    ///
    /// **Round-trip law** — for every `v: PartitionFace`,
    /// `serde_yaml::from_str::<PartitionFace>(&serde_yaml::to_string(&v)?)? == v`
    /// and the same on `serde_json`. Pinned by
    /// [`tests::partition_face_serde_yaml_round_trips_over_every_variant`]
    /// and the `serde_json` peer test.
    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        serializer.collect_str(self)
    }
}

impl<'de> serde::Deserialize<'de> for PartitionFace {
    /// Deserialize the face tag from the canonical operator-facing
    /// lowercase label [`Self::as_str`] emits via
    /// [`serde::Deserializer::deserialize_str`] with a visitor whose
    /// `visit_str` lowers to [`<Self as std::str::FromStr>::from_str`]
    /// and routes any [`ParsePartitionFaceError`] through
    /// [`serde::de::Error::custom`].
    ///
    /// **Case insensitivity inherits from [`FromStr`]** — an
    /// operator-authored manifest field carrying the uppercase or
    /// mixed-case form of a canonical label parses on the serde side
    /// without a per-emitter case-fold, because the deserialize path
    /// lowers through [`ClosedAxisLabel::from_canonical_str`] which
    /// compares via [`str::eq_ignore_ascii_case`]. Pinned by
    /// [`tests::partition_face_serde_yaml_is_case_insensitive`].
    ///
    /// **Unknown-label rejection carries the offending label
    /// verbatim** — a manifest field carrying an unknown face name
    /// surfaces at the serde error site with the offending substring
    /// verbatim in the rendered message, lifted through
    /// [`ParsePartitionFaceError::label`] and the typed
    /// [`Display`][std::fmt::Display] impl on the parse error. Pinned
    /// by
    /// [`tests::partition_face_serde_yaml_unknown_label_error_carries_label_verbatim`].
    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        struct PartitionFaceVisitor;

        impl serde::de::Visitor<'_> for PartitionFaceVisitor {
            type Value = PartitionFace;

            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
                f.write_str(
                    "a canonical PartitionFace lowercase label \
                     (`realizable`, `unrealizable`)",
                )
            }

            fn visit_str<E: serde::de::Error>(self, v: &str) -> Result<Self::Value, E> {
                v.parse::<PartitionFace>().map_err(E::custom)
            }
        }

        deserializer.deserialize_str(PartitionFaceVisitor)
    }
}

impl ClosedAxis for PartitionFace {
    const ALL: &'static [Self] = Self::ALL;
}

impl ClosedAxisLabel for PartitionFace {
    fn as_str(self) -> &'static str {
        Self::as_str(self)
    }
}

/// Typed witness of which half of a [`ProductCube`] a cell occupies,
/// carrying the dense ordinal on that half.
///
/// Every cell of every [`ProductCube`] falls into exactly one variant —
/// `Realizable(i)` with `i < realizable_count::<C>()` on the recognized
/// surface, or `Unrealizable(i)` with `i < unrealizable_count::<C>()`
/// on the cross-axis consistency-violation complement. The two halves
/// are XOR-complementary (pinned by
/// [`tests::realizable_and_unrealizable_ordinals_partition_cube`]), so
/// the enum is a typed encoding of that partition: one value per cell,
/// no ambiguity about which face the dense ordinal addresses.
///
/// This is the cube-level disjoint-union counterpart of [`axis_ordinal`]
/// — where [`axis_ordinal`] returns one dense `usize` over the full
/// cube `ALL` slice (interleaving realizable and unrealizable cells),
/// `PartitionOrdinal` returns a typed variant tagged with which face
/// the cell sits on, plus the dense ordinal restricted to that face
/// only. The encoding wastes no slot on the opposite half: a future
/// observability counter sized by [`realizable_count::<C>()`][realizable_count]
/// or [`unrealizable_count::<C>()`][unrealizable_count] picks the
/// correct dimension via the variant tag at runtime, without separate
/// dense-half encoders at every call site.
///
/// Built and decoded uniformly across every [`ProductCube`] implementor
/// through [`partition_ordinal`] and [`at_partition_ordinal`]; a fifth
/// product cube landing on the typescape inherits both helpers at the
/// `impl ProductCube` declaration without re-deriving the
/// `if is_realizable(cell) { Realizable(...) } else { Unrealizable(...) }`
/// branch at every call site.
///
/// **Trait surface** — alongside the canonical
/// `Debug + Clone + Copy + PartialEq + Eq + Hash` set, the derive
/// also includes [`Ord`] + [`PartialOrd`], lifting the
/// declaration-order total order on [`PartitionFace`] (`Realizable <
/// Unrealizable`, pinned by
/// [`tests::partition_face_ord_matches_declaration_order`]) and the
/// numeric total order on the inner dense ordinal into one
/// lexicographic total order on the full disjoint-union encoding.
/// Rust's derived [`Ord`] on a tuple-variant enum compares the
/// variant tag first (so every `Realizable(_)` lands strictly less
/// than every `Unrealizable(_)`, regardless of the inner ordinal)
/// and falls through to the inner-`usize` comparison on matching
/// variants — face-major, inner-ordinal-minor. This matches
/// `a.face().cmp(&b.face()).then(a.face_ordinal().cmp(&b.face_ordinal()))`
/// pointwise, pinned by
/// [`tests::partition_ordinal_ord_matches_face_then_face_ordinal`],
/// closing the canonical lexicographic-on-`(face, face_ordinal)`
/// reading of the typed-partition surface.
///
/// **Consumers** — a
/// `BTreeMap<PartitionOrdinal, MetricRollup>` keyed on the typed
/// cell address now emits rows in face-major, dense-ordinal-minor
/// order deterministically across releases (every realizable cell
/// before every unrealizable cell, each face traversed in
/// `realizable_at` / `unrealizable_at` dense-prefix order),
/// matching the canonical realizable-then-unrealizable rendering
/// the rest of the cube surfaces emit through
/// `realizable_iter().chain(unrealizable_iter())`. A
/// `Vec<PartitionOrdinal>` `.sort()`-ed for stable JSON / YAML
/// emission lands at the same order without naming a comparator —
/// idiom-peer of the same [`Ord`] derive on [`PartitionFace`] and on
/// the four typed-cube-classifier surfaces ([`ModalityClass`],
/// [`SupportCardinalityClass`], [`SupportBoundaryDistance`],
/// [`SupportMagnitudeDirection`]).
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)]
pub enum PartitionOrdinal {
    /// Cell sits on the recognized-image realizable surface; carries
    /// the dense ordinal in the prefix `0..realizable_count::<C>()`.
    Realizable(usize),
    /// Cell sits on the cross-axis consistency-violation unrealizable
    /// complement; carries the dense ordinal in the prefix
    /// `0..unrealizable_count::<C>()`.
    Unrealizable(usize),
}

impl PartitionOrdinal {
    /// Project the variant tag of a [`PartitionOrdinal`] into the
    /// typed [`PartitionFace`] primitive — `Realizable(_) → Realizable`,
    /// `Unrealizable(_) → Unrealizable`.
    ///
    /// One named projection of the two-arm `match` that was previously
    /// inlined at every consumer that needed only the face tag without
    /// the dense inner ordinal. Total over [`PartitionOrdinal`]: every
    /// value lands on exactly one [`PartitionFace`] (no [`Option`]
    /// wrapper). Pinned in lockstep with
    /// [`ProductCube::is_realizable`] over every cell of every cube by
    /// [`tests::partition_ordinal_face_agrees_with_is_realizable`].
    ///
    /// **Consumers** — a face-keyed observability counter
    /// (`HashMap<PartitionFace, usize>`) records the face of a captured
    /// cube cell through one call; a manifest field that distinguishes
    /// the realizable image from the consistency-violation complement
    /// at the face level (without addressing the specific cell)
    /// carries one [`PartitionFace`] byte rather than the full
    /// [`PartitionOrdinal`] (variant tag + dense inner ordinal).
    #[must_use]
    pub const fn face(self) -> PartitionFace {
        match self {
            Self::Realizable(_) => PartitionFace::Realizable,
            Self::Unrealizable(_) => PartitionFace::Unrealizable,
        }
    }

    /// Project the inner dense ordinal of a [`PartitionOrdinal`] —
    /// `Realizable(i) → i`, `Unrealizable(i) → i`.
    ///
    /// One named projection of the two-arm `match` that was previously
    /// inlined at every consumer that needed only the dense inner
    /// ordinal without the face tag. The returned `usize` lies in
    /// `0..realizable_count::<C>()` on a [`PartitionFace::Realizable`]
    /// face and `0..unrealizable_count::<C>()` on a
    /// [`PartitionFace::Unrealizable`] face — the face is implicit in
    /// the variant the projection forgets. Consumers that carry the
    /// face tag separately (e.g. as a [`PartitionFace`]-keyed
    /// dashboard column) reach the inner ordinal through this
    /// projection without re-pattern-matching.
    #[must_use]
    pub const fn face_ordinal(self) -> usize {
        match self {
            Self::Realizable(i) | Self::Unrealizable(i) => i,
        }
    }
}

impl std::fmt::Display for PartitionOrdinal {
    /// Operator-facing rendering of the typed partition address as
    /// `<face>:<face_ordinal>` — concatenates the canonical lowercase
    /// face label from [`PartitionFace::as_str`] (the same scalar the
    /// [`Display`][std::fmt::Display] impl on [`PartitionFace`] writes)
    /// with a `:` separator and the dense inner ordinal rendered through
    /// `usize`'s built-in [`Display`][std::fmt::Display]. The two halves
    /// of the typed disjoint-union encoding round-trip through one
    /// scalar without two manifest fields.
    ///
    /// Closes the canonical Rust stdlib (`Debug`, `Display`) duality on
    /// the typed cube-cell-address surface: where `Debug` (derived
    /// above) renders the Rust constructor (`Realizable(42)` /
    /// `Unrealizable(7)`), `Display` renders the canonical
    /// operator-facing form (`realizable:42` / `unrealizable:7`). The
    /// colon separator is unambiguous because the canonical face labels
    /// `realizable` / `unrealizable` are pure lowercase ASCII letters
    /// (no colon, no digits), so the leftmost colon cleanly splits the
    /// face label from the dense ordinal. Idiom-peer of the same
    /// (`Display`, `FromStr`) lift on [`PartitionFace`] and on the four
    /// typed-cube-classifier surfaces ([`ModalityClass`],
    /// [`SupportCardinalityClass`], [`SupportBoundaryDistance`],
    /// [`SupportMagnitudeDirection`]), now extended onto the
    /// disjoint-union encoding that pairs the face tag with the dense
    /// inner ordinal.
    ///
    /// **Round-trip with [`FromStr`][std::str::FromStr]** —
    /// `v.to_string().parse::<PartitionOrdinal>().unwrap() == v` for
    /// every `v: PartitionOrdinal` (over every variant tag and every
    /// representable `usize` ordinal, including the boundary `0` and
    /// `usize::MAX`). Pinned by
    /// [`tests::partition_ordinal_from_str_round_trips_through_display`].
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}:{}", self.face().as_str(), self.face_ordinal())
    }
}

/// Typed parse failure of [`<PartitionOrdinal as
/// std::str::FromStr>::from_str`] — the offending input was not a
/// canonical `<face>:<face_ordinal>` address on the [`PartitionOrdinal`]
/// surface.
///
/// The disjoint-union encoding carries two halves at the scalar level
/// (the face label and the dense inner ordinal), so the parser's
/// rejection modes split into three: the input carried no `:` separator
/// at all, the face half did not match a canonical [`PartitionFace`]
/// name, or the ordinal half did not parse as a `usize`. Each variant
/// carries the offending substring verbatim so a downstream consumer
/// can localize the failure to the surrounding context (a YAML
/// attestation manifest field carrying a cube cell address, a
/// structured-log address-keyed scalar, a CLI argument). The malformed
/// ordinal variant additionally carries the underlying
/// [`std::num::ParseIntError`] so the standard-library numeric parse
/// diagnostic threads through to the error message without
/// re-stringification.
///
/// `#[non_exhaustive]` so a future stricter parse rule (e.g. an
/// `EmptyInput` distinguished from `MissingSeparator`) lands as a new
/// variant without a SemVer-major bump. Idiom-peer of
/// [`ParsePartitionFaceError`] on the variant-tag projection — but
/// promoted from a single-field struct to a three-variant enum because
/// the parse surface carries two halves rather than one canonical
/// label.
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum ParsePartitionOrdinalError {
    /// The input carried no `:` separator. The full offending input is
    /// preserved verbatim so the operator-facing error names what was
    /// actually received.
    MissingSeparator {
        /// The offending input substring, verbatim.
        input: String,
    },
    /// The face-label half (before the `:`) did not match a canonical
    /// [`PartitionFace`] name. The offending substring is preserved
    /// verbatim.
    UnknownFace {
        /// The offending face-label substring, verbatim.
        label: String,
    },
    /// The ordinal half (after the `:`) did not parse as a `usize`. The
    /// offending substring is preserved verbatim and the underlying
    /// [`std::num::ParseIntError`] threads through `source` so the
    /// standard-library numeric diagnostic surfaces without
    /// re-stringification.
    MalformedOrdinal {
        /// The offending ordinal substring, verbatim.
        ordinal: String,
        /// The underlying numeric parse error from
        /// [`<usize as std::str::FromStr>::from_str`].
        source: std::num::ParseIntError,
    },
}

impl std::fmt::Display for ParsePartitionOrdinalError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::MissingSeparator { input } => {
                write!(f, "PartitionOrdinal input missing `:` separator: {input:?}",)
            }
            Self::UnknownFace { label } => {
                write!(f, "unknown partition face label {label:?}")
            }
            Self::MalformedOrdinal { ordinal, source } => write!(
                f,
                "malformed PartitionOrdinal face_ordinal {ordinal:?}: {source}",
            ),
        }
    }
}

impl std::error::Error for ParsePartitionOrdinalError {
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
        match self {
            Self::MalformedOrdinal { source, .. } => Some(source),
            Self::MissingSeparator { .. } | Self::UnknownFace { .. } => None,
        }
    }
}

impl std::str::FromStr for PartitionOrdinal {
    type Err = ParsePartitionOrdinalError;

    /// Parse a typed partition address from the canonical
    /// `<face>:<face_ordinal>` form [`Display`][std::fmt::Display]
    /// emits — the canonical Rust stdlib
    /// [`FromStr`][std::str::FromStr] idiom-peer of the
    /// [`Display`][std::fmt::Display] impl. Splits on the leftmost `:`
    /// (the canonical face labels are pure lowercase ASCII letters, so
    /// no colon appears inside the face half), delegates the face half
    /// to [`<PartitionFace as std::str::FromStr>::from_str`] (which
    /// itself lowers through the case-insensitive
    /// [`ClosedAxisLabel::from_canonical_str`] route), and the ordinal
    /// half to [`<usize as std::str::FromStr>::from_str`]. Failures lift
    /// to typed [`ParsePartitionOrdinalError`] variants so the
    /// [`std::error::Error`] bound is satisfied at consumer sites
    /// requiring `Result<_, Box<dyn Error>>` (`eyre::Result<_>`,
    /// structured-log error fields, deserialization error chaining).
    ///
    /// **Round-trip law** —
    /// `v.to_string().parse::<PartitionOrdinal>().unwrap() == v` for
    /// every `v: PartitionOrdinal` over every variant tag and every
    /// representable `usize` ordinal. Pinned by
    /// [`tests::partition_ordinal_from_str_round_trips_through_display`].
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        let (face_str, ordinal_str) =
            s.split_once(':')
                .ok_or_else(|| ParsePartitionOrdinalError::MissingSeparator {
                    input: s.to_owned(),
                })?;
        let face = face_str
            .parse::<PartitionFace>()
            .map_err(|e| ParsePartitionOrdinalError::UnknownFace { label: e.label })?;
        let face_ordinal = ordinal_str.parse::<usize>().map_err(|source| {
            ParsePartitionOrdinalError::MalformedOrdinal {
                ordinal: ordinal_str.to_owned(),
                source,
            }
        })?;
        Ok(match face {
            PartitionFace::Realizable => Self::Realizable(face_ordinal),
            PartitionFace::Unrealizable => Self::Unrealizable(face_ordinal),
        })
    }
}

impl serde::Serialize for PartitionOrdinal {
    /// Serialize the typed partition address as the canonical
    /// `<face>:<face_ordinal>` scalar the
    /// [`Display`][std::fmt::Display] impl writes. Routes through
    /// [`serde::Serializer::collect_str`] so the serialized
    /// representation is exactly `format!("{self}")` with no
    /// intermediate allocation.
    ///
    /// Closes the canonical (`Serialize`, `Deserialize`) serde
    /// idiom-peer of the (`Display`, `FromStr`) stdlib pair on the
    /// typed cube-cell-address surface — idiom-peer of the same lift
    /// on [`PartitionFace`] and on the four typed-cube-classifier
    /// surfaces. A partition address emitted into a YAML attestation
    /// manifest field, a JSON observability payload, or any consumer
    /// struct holding a `PartitionOrdinal` field under
    /// `#[derive(Serialize, Deserialize)]` round-trips through the
    /// canonical scalar without a consumer-side helper combining the
    /// face label and the dense inner ordinal at the renderer.
    ///
    /// **Round-trip law** — for every `v: PartitionOrdinal`,
    /// `serde_yaml::from_str::<PartitionOrdinal>(&serde_yaml::to_string(&v)?)? == v`
    /// and the same on `serde_json`. Pinned by
    /// [`tests::partition_ordinal_serde_yaml_round_trips_over_sample`]
    /// and the `serde_json` peer test.
    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        serializer.collect_str(self)
    }
}

impl<'de> serde::Deserialize<'de> for PartitionOrdinal {
    /// Deserialize the typed partition address from the canonical
    /// `<face>:<face_ordinal>` scalar via
    /// [`serde::Deserializer::deserialize_str`] with a visitor whose
    /// `visit_str` lowers to
    /// [`<Self as std::str::FromStr>::from_str`] and routes any
    /// [`ParsePartitionOrdinalError`] through
    /// [`serde::de::Error::custom`].
    ///
    /// **Case insensitivity on the face half inherits from
    /// [`FromStr`]** — an operator-authored manifest field carrying the
    /// uppercase or mixed-case form of a face label parses on the
    /// serde side without a per-emitter case-fold, because the
    /// deserialize path lowers through
    /// [`<PartitionFace as std::str::FromStr>::from_str`] which in turn
    /// lowers through [`ClosedAxisLabel::from_canonical_str`] which
    /// compares via [`str::eq_ignore_ascii_case`]. Pinned by
    /// [`tests::partition_ordinal_serde_yaml_face_is_case_insensitive`].
    ///
    /// **Three rejection modes carry the offending substring
    /// verbatim** — a manifest field carrying a malformed address
    /// surfaces at the serde error site with either the missing-
    /// separator input, the unknown face label, or the malformed
    /// ordinal substring verbatim in the rendered message, lifted
    /// through [`ParsePartitionOrdinalError`] and the typed
    /// [`Display`][std::fmt::Display] impl on the parse error.
    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        struct PartitionOrdinalVisitor;

        impl serde::de::Visitor<'_> for PartitionOrdinalVisitor {
            type Value = PartitionOrdinal;

            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
                f.write_str(
                    "a canonical PartitionOrdinal `<face>:<face_ordinal>` scalar \
                     (e.g. `realizable:42`, `unrealizable:7`)",
                )
            }

            fn visit_str<E: serde::de::Error>(self, v: &str) -> Result<Self::Value, E> {
                v.parse::<PartitionOrdinal>().map_err(E::custom)
            }
        }

        deserializer.deserialize_str(PartitionOrdinalVisitor)
    }
}

/// Typed partition ordinal of a [`ProductCube`] cell — fuses
/// ([`realizable_ordinal`], [`unrealizable_ordinal`]) into one total
/// helper returning a [`PartitionOrdinal`] variant tagged with which
/// face of the cube the cell sits on.
///
/// Total over `C::ALL`: every cell of every product cube has a defined
/// partition ordinal (no [`Option`] wrapper at the return type), because
/// the XOR-complementary partition discipline pins that exactly one of
/// [`realizable_ordinal`] / [`unrealizable_ordinal`] returns [`Some`]
/// on every cell. The variant tag distinguishes the two faces; the
/// inner `usize` is the dense ordinal restricted to that face.
///
/// **Variant agreement** — pinned by
/// [`tests::partition_ordinal_variant_agrees_with_is_realizable`]:
/// `partition_ordinal::<C>(cell)` returns
/// [`PartitionOrdinal::Realizable`] exactly on realizable cells and
/// [`PartitionOrdinal::Unrealizable`] exactly on unrealizable cells.
///
/// **Inner ordinal agreement** — pinned by
/// [`tests::partition_ordinal_inner_matches_dense_ordinal`]: the
/// inner `usize` on each variant equals the corresponding dense ordinal
/// from [`realizable_ordinal`] or [`unrealizable_ordinal`] pointwise.
///
/// **Round-trip with [`at_partition_ordinal`]** — pinned by
/// [`tests::partition_ordinal_round_trips_cell_side`]:
/// `at_partition_ordinal::<C>(partition_ordinal::<C>(cell)) == Some(cell)`
/// for every cell of every cube — the cube-level dual of the
/// ([`axis_ordinal`], [`axis_at`]) round-trip, but on the typed
/// disjoint-union encoding rather than the interleaved full-cube
/// ordinal.
///
/// **Consumers** — a future single-slot observability counter or
/// error-path field carrying "the cube cell address" stores one
/// [`PartitionOrdinal`] value instead of two separate
/// `Option<usize>` fields (one per face). Decoders take the typed
/// enum and produce the cell through one named helper. Manifest
/// serializers (THEORY.md §III.1.8 module manifests, §V.3
/// three-pillar attestation) that distinguish the realizable image
/// from the consistency-violation complement at the address level
/// carry the variant tag and the dense ordinal in lockstep without
/// re-deriving the predicate.
///
/// # Panics
///
/// Panics — via `.expect(...)` on the inner dense-ordinal lookup —
/// only if a [`ProductCube`] implementor violates the discipline by
/// returning `is_realizable(cell) == true` for a cell on which
/// [`realizable_ordinal`] returns [`None`], or dually
/// `is_realizable(cell) == false` for a cell on which
/// [`unrealizable_ordinal`] returns [`None`]. The XOR-complementary
/// partition discipline pins that exactly one of the two dense
/// ordinals is [`Some`] on every cell, and the variant agreement
/// invariant ([`tests::partition_ordinal_variant_agrees_with_is_realizable`])
/// pins that the predicate-driven branch selects the side that
/// returns [`Some`]; in practice both branches are reachable only
/// when the implementor lies about `is_realizable`, which the
/// trait-uniform tests would catch at the same site.
#[must_use]
pub fn partition_ordinal<C: ProductCube>(cell: C) -> PartitionOrdinal {
    if ProductCube::is_realizable(cell) {
        PartitionOrdinal::Realizable(
            realizable_ordinal::<C>(cell).expect(
                "ProductCube discipline: is_realizable(cell) => realizable_ordinal is Some",
            ),
        )
    } else {
        PartitionOrdinal::Unrealizable(
            unrealizable_ordinal::<C>(cell).expect(
                "ProductCube discipline: !is_realizable(cell) => unrealizable_ordinal is Some",
            ),
        )
    }
}

/// Decode a [`PartitionOrdinal`] into the cell it addresses on a
/// [`ProductCube`] — fuses ([`realizable_at`], [`unrealizable_at`])
/// into one helper routed by the variant tag.
///
/// Safe forward dual of [`partition_ordinal`]: where
/// [`partition_ordinal`] is the total inverse `cell → PartitionOrdinal`
/// over the cube, [`at_partition_ordinal`] is the partial forward
/// `PartitionOrdinal → Option<cell>` over the typed disjoint-union
/// encoding, returning [`Some`] exactly when the inner `usize` falls
/// in-range on the face the variant tag selects and [`None`] when the
/// inner `usize` exceeds the face's count.
///
/// **Bijection laws** — pinned by trait-uniform tests reaching every
/// implementor pointwise:
///
/// 1. **Round-trip from the cell side** —
///    `at_partition_ordinal::<C>(partition_ordinal::<C>(cell)) == Some(cell)`
///    for every cell of every cube. The
///    `partition_ordinal`-then-`at_partition_ordinal` composition is
///    the identity on `C::ALL`.
/// 2. **Round-trip from the partition-ordinal side** —
///    `at_partition_ordinal::<C>(p).map(partition_ordinal::<C>) == Some(p)`
///    for every in-range `p: PartitionOrdinal`. The
///    `at_partition_ordinal`-then-`partition_ordinal` composition is
///    the identity on the in-range domain.
/// 3. **Partiality on out-of-range** —
///    `at_partition_ordinal::<C>(PartitionOrdinal::Realizable(i)).is_none()`
///    for `i >= realizable_count::<C>()` and dually
///    `at_partition_ordinal::<C>(PartitionOrdinal::Unrealizable(i)).is_none()`
///    for `i >= unrealizable_count::<C>()`. The forward map is defined
///    over each variant's restricted prefix and undefined outside it.
/// 4. **Image realizability matches the variant tag** —
///    `at_partition_ordinal::<C>(PartitionOrdinal::Realizable(i)).map(is_realizable) == Some(true)`
///    for in-range `i`, and dually for [`PartitionOrdinal::Unrealizable`]
///    with `Some(false)`. The forward map's variant tag and the
///    cell's realizability are in lockstep.
///
/// **Consumers** — manifest decoders, error-path consumers, and
/// observability dashboards recover the typed cell from a
/// [`PartitionOrdinal`] address through one named helper rather than
/// branching on the variant and calling [`realizable_at`] /
/// [`unrealizable_at`] inline at every site.
#[must_use]
pub fn at_partition_ordinal<C: ProductCube>(p: PartitionOrdinal) -> Option<C> {
    match p {
        PartitionOrdinal::Realizable(i) => realizable_at::<C>(i),
        PartitionOrdinal::Unrealizable(i) => unrealizable_at::<C>(i),
    }
}

/// Closed discipline trait for the [`ProductCube`] subset whose
/// forward map from the recognized-image type into the cube is
/// injective, so the cube carries a partial inverse back into the
/// image: `invert(cell) = Some(image)` exactly on the realizable
/// cells, `None` on the cross-axis consistency-violation complement.
///
/// Two cubes satisfy this sub-discipline today:
///
/// - [`crate::FormatCoordinates`] —
///   [`crate::FormatCoordinates::format_or_none`] is the partial
///   inverse of [`crate::Format::format_coordinates`].
/// - [`crate::AttributionCoordinates`] —
///   [`crate::AttributionRule::from_coordinates`] is the partial
///   inverse of [`crate::AttributionRule::coordinates`].
///
/// The other two cubes on the typescape primitive set —
/// [`crate::ErrorLocalizationCoordinates`] and
/// [`crate::AttributionSourceKindCoordinates`] — carry an
/// `is_realizable` predicate but no partial inverse: their forward
/// maps are non-injective or their realizable image is not in
/// one-to-one correspondence with a single typescape value (the error-
/// localization image collapses many `(kind, localization)` pairs onto
/// the same `(kind, observable-failure)` observation, and the
/// source-axis-kind image collapses pairs of source-axis rules onto
/// the same `(figment_source_kind, layer_kind)` joint cell only when
/// the rule space stays at its current two-element source-axis
/// subset).
///
/// The trait binds [`Self::Image`] to the recognized-image type
/// — itself a [`ClosedAxis`] on the typescape primitive set
/// (`Format` for [`crate::FormatCoordinates`], `AttributionRule` for
/// [`crate::AttributionCoordinates`]) — so generic helpers
/// ([`realizable_images`], [`forward_iter`]) can iterate the image
/// without naming the concrete cube type, and generic bijection tests
/// reach `Self::Image::ALL` through the [`ClosedAxis`] discipline the
/// image type already satisfies. `Debug` is added so generic
/// invariant helpers can `assert_eq!` against image values without
/// per-implementor harness boilerplate.
///
/// Two structural invariants — pinned by trait-uniform tests reaching
/// every implementor pointwise:
///
/// 1. **`invert`-realizability agreement** —
///    `cell.invert().is_some() == ProductCube::is_realizable(cell)`,
///    pinned by [`tests::partial_inverse_some_iff_is_realizable`].
/// 2. **`forward`-`invert` bijection on the recognized half** —
///    `Self::forward(image).invert() == Some(image)` for every
///    `image: Self::Image`, and dually
///    `forward(invert(cell).unwrap()) == cell` for every realizable
///    cell; pinned by the round-trip helpers in the test module.
///    Equivalently, the forward image of `Self::Image::ALL` under
///    [`Self::forward`] equals `realizable_iter::<Self>()` as a set,
///    pinned by
///    [`tests::forward_image_of_image_all_equals_realizable_iter`].
///
/// A third (or fourth) implementor landing — a future
/// `(figment_source_kind × axis × confidence)` refinement cube with a
/// bijection to a source-axis rule subset, or a `(format ×
/// name_style)` discovery refinement cube with a bijection to a typed
/// discovery-key envelope — picks up both invariants and the generic
/// helpers ([`realizable_images`], [`forward_iter`]) at the
/// `impl PartialInverseCube` declaration, with the invariants enforced
/// by the same trait-uniform tests reaching every implementor pointwise.
pub trait PartialInverseCube: ProductCube {
    /// The recognized-image type — the typescape value the partial
    /// inverse re-hydrates on realizable cells (`Format` for
    /// [`crate::FormatCoordinates`], `AttributionRule` for
    /// [`crate::AttributionCoordinates`]).
    ///
    /// Bound to [`ClosedAxis`] so the image is itself a typescape
    /// primitive — generic helpers reach `Self::Image::ALL` through
    /// the same trait discipline the cube does, and the bijection
    /// invariant (forward image of `Image::ALL` equals realizable
    /// cells) is stated in trait-uniform language. `Debug` is added so
    /// generic invariant tests can `assert_eq!` against image values
    /// without per-implementor harness boilerplate.
    type Image: ClosedAxis + std::fmt::Debug;

    /// Partial inverse: `Some(image)` for realizable cells, `None`
    /// for the cross-axis consistency-violation complement.
    ///
    /// Mirror of the inherent partial-inverse method every implementor
    /// already exposes
    /// ([`crate::FormatCoordinates::format_or_none`],
    /// [`crate::AttributionRule::from_coordinates`]). The trait
    /// re-export lets generic helpers ([`realizable_images`]) reach
    /// the inverse without naming the concrete cube or image type.
    fn invert(self) -> Option<Self::Image>;

    /// Forward (total) map from [`Self::Image`] into the cube — the
    /// dual of [`Self::invert`] on the recognized half. Mirror of the
    /// inherent image→cube method every implementor already exposes
    /// ([`crate::Format::format_coordinates`],
    /// [`crate::AttributionRule::coordinates`]).
    ///
    /// Total over `Self::Image`: every image lands on a realizable
    /// cell of the cube (pinned by the per-implementor
    /// `*_forward_always_lands_on_realizable_cell` tests). The pair
    /// (`forward`, `invert`) closes the bijection discipline on the
    /// recognized half of the cube — `invert(forward(image)) ==
    /// Some(image)` for every image, and dually
    /// `forward(invert(cell).unwrap()) == cell` for every realizable
    /// cell; both round-trip laws are pinned by trait-uniform tests
    /// reaching each implementor pointwise.
    ///
    /// One named entry point for the image→cube morphism, regardless
    /// of how the implementor names the inherent method. Before this
    /// lift, generic code that wanted the forward map had to name the
    /// concrete inherent method (`Format::format_coordinates`,
    /// `AttributionRule::coordinates`); the trait re-export lets the
    /// [`forward_iter`] generic helper and the bijection invariant
    /// tests dispatch over the cube type parameter alone.
    fn forward(image: Self::Image) -> Self;
}

/// Iterate the realized images of a [`PartialInverseCube`] — the
/// `Some` outputs of [`PartialInverseCube::invert`] over [`ClosedAxis::ALL`],
/// in cube-declaration order.
///
/// Generic in the cube type so a future
/// [`PartialInverseCube`] implementor inherits the helper at its
/// `impl PartialInverseCube` declaration. The output cardinality
/// equals [`realizable_count::<C>()`][realizable_count] by the
/// `invert().is_some() == is_realizable()` invariant the trait pins.
pub fn realizable_images<C: PartialInverseCube>() -> impl Iterator<Item = C::Image> {
    C::ALL
        .iter()
        .copied()
        .filter_map(PartialInverseCube::invert)
}

/// Iterate the forward image of every image under
/// [`PartialInverseCube::forward`] — `C::Image::ALL.iter().copied()
/// .map(C::forward)` collapsed to one named helper.
///
/// The output is a length-`Image::ALL.len()` sequence of realizable
/// cells (the forward map is total over the image space and lands on
/// realizable cells, pinned per implementor by
/// `*_forward_always_lands_on_realizable_cell`). As a set the output
/// equals `realizable_iter::<C>()`, pinned generically by
/// [`tests::forward_image_of_image_all_equals_realizable_iter`].
///
/// Generic in the cube type so a future [`PartialInverseCube`]
/// implementor inherits the helper at its `impl PartialInverseCube`
/// declaration. Consolidates the inline
/// `Image::ALL.iter().copied().map(Image::<inherent_forward>)`
/// pattern that appeared at the `*_realizable_image_equals_*_image`
/// test site on each cube (two such inline `.map` sites today; future
/// cubes pick up the helper at the trait impl rather than re-deriving
/// the map inline).
pub fn forward_iter<C: PartialInverseCube>() -> impl Iterator<Item = C> {
    <C::Image as ClosedAxis>::ALL
        .iter()
        .copied()
        .map(C::forward)
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::{
        AttributionAxis, AttributionConfidence, AttributionCoordinates,
        AttributionNameKindCoordinates, AttributionRule, AttributionSourceKindCoordinates,
        ConfigSourceKind, ConfigTierKind, DiffLineKind, EnvMetadataTagKind,
        ErrorLocalizationCoordinates, FieldPathLocalization, FigmentNameTagKind, FigmentSourceKind,
        Format, FormatCoordinates, FormatProvenance, SecretBackendKind, SecretRefShape,
        ShikumiErrorKind, WatchEventClass,
        secret_client::{SecretClientKind, SecretErrorKind, SecretOperation},
    };

    // ---- Implementor-list macros ----
    //
    // The shikumi typescape has one declared, stable set of
    // [`ClosedAxis`] implementors today — nine closed-enum axis
    // primitives ([`Format`], [`FormatProvenance`], [`ConfigSourceKind`],
    // [`FigmentSourceKind`], [`ShikumiErrorKind`],
    // [`FieldPathLocalization`], [`AttributionRule`],
    // [`AttributionConfidence`], [`AttributionAxis`]) and four product
    // cubes ([`FormatCoordinates`], [`AttributionCoordinates`],
    // [`ErrorLocalizationCoordinates`], [`AttributionSourceKindCoordinates`]).
    // Two of the cubes additionally satisfy [`PartialInverseCube`]
    // ([`FormatCoordinates`], [`AttributionCoordinates`]).
    //
    // These three lists previously appeared inlined at every
    // trait-uniform `for every implementor` test site (more than ten
    // sites today across the `axis_iter`, `axis_cardinality`,
    // `axis_ordinal`, `axis_at`, `realizable_*`, and `forward_*`
    // helpers); each duplicated list had to be manually kept in
    // lockstep with the typescape's implementor set, so a tenth axis
    // primitive or fifth cube landing meant editing every site by
    // hand. Lifting them into three callback macros — one per
    // trait-implementor set — keeps the lists at one site each:
    // a future axis primitive lands as one new arm in
    // [`for_each_closed_axis_primitive`], picks up every trait-uniform
    // invariant test by macro expansion, and the per-test inline
    // listing disappears. The macros expand at every call site to the
    // same `cb!(TypeName);` sequence the inline listings carried, so
    // the runtime behavior is identical and the compiler still type-
    // checks each expanded `assert_*::<TypeName>()` call against the
    // trait bound.
    //
    // The macros are deliberately scoped to the test module —
    // implementor-list discipline is a test-time concern (no runtime
    // code dispatches over the list since [`ClosedAxis`] is not
    // object-safe). The `for_each_closed_axis_implementor` superset
    // macro composes the two ClosedAxis-implementor sets (nine
    // primitive enums + four cubes) so a "reach every implementor"
    // test can list one macro call instead of two.

    /// Invokes `$cb!(TypeName)` for each [`ClosedAxis`] axis-primitive
    /// enum — the fifteen closed-enum axis primitives the typescape
    /// recognizes today, in declaration order. [`PartitionFace`],
    /// [`ConfigTierKind`], [`WatchEventClass`], [`FigmentNameTagKind`],
    /// [`SecretBackendKind`], and [`SecretRefShape`] sit at the tail as
    /// the six non-cube-axis primitives (the first a variant-tag
    /// projection of [`PartitionOrdinal`], the second of
    /// [`crate::ConfigTier`], the third the reload-relevance
    /// classification of a raw [`notify::Event`] kind, the fourth the
    /// `'static` discriminant of [`crate::FigmentNameTag`] on the
    /// figment-`Metadata::name` axis — the symmetric peer of
    /// [`FigmentSourceKind`] on the figment-`Source` axis, the fifth
    /// the `'static` discriminant of [`crate::secret::SecretBackend`]
    /// on the secret-resolution backend axis — peer of
    /// [`ConfigSourceKind`] / [`FigmentNameTagKind`] /
    /// [`FigmentSourceKind`] on their respective discriminant axes, the
    /// sixth the shared (whole-reference × extracted-field) variant-tag
    /// projection over the untagged-enum `*Ref` pair
    /// `(crate::secret::SopsRef, crate::secret::VaultRef)` — the first
    /// cross-type closed-axis primitive on the typescape, naming the
    /// extraction-shape equivalence between the two `*Ref` enums at the
    /// type level rather than in the dispatch table only); the leading
    /// nine are the per-axis-of-the-cube primitives.
    macro_rules! for_each_closed_axis_primitive {
        ($cb:ident) => {
            $cb!(Format);
            $cb!(FormatProvenance);
            $cb!(ConfigSourceKind);
            $cb!(FigmentSourceKind);
            $cb!(ShikumiErrorKind);
            $cb!(FieldPathLocalization);
            $cb!(AttributionRule);
            $cb!(AttributionConfidence);
            $cb!(AttributionAxis);
            $cb!(PartitionFace);
            $cb!(ConfigTierKind);
            $cb!(WatchEventClass);
            $cb!(FigmentNameTagKind);
            $cb!(EnvMetadataTagKind);
            $cb!(SecretBackendKind);
            $cb!(SecretRefShape);
            $cb!(SecretOperation);
            $cb!(SecretErrorKind);
            $cb!(SecretClientKind);
            $cb!(DiffLineKind);
        };
    }

    /// Invokes `$cb!(TypeName)` for each [`ProductCube`] implementor —
    /// the five product cubes the typescape recognizes today, in
    /// declaration order. [`AttributionNameKindCoordinates`] sits at
    /// the tail as the symmetric peer of
    /// [`AttributionSourceKindCoordinates`] on the figment-
    /// `Metadata::name` axis.
    macro_rules! for_each_product_cube {
        ($cb:ident) => {
            $cb!(FormatCoordinates);
            $cb!(AttributionCoordinates);
            $cb!(ErrorLocalizationCoordinates);
            $cb!(AttributionSourceKindCoordinates);
            $cb!(AttributionNameKindCoordinates);
        };
    }

    /// Invokes `$cb!(TypeName)` for each [`PartialInverseCube`]
    /// implementor — the two cubes whose forward map carries an
    /// inverse on the recognized half, in declaration order.
    macro_rules! for_each_partial_inverse_cube {
        ($cb:ident) => {
            $cb!(FormatCoordinates);
            $cb!(AttributionCoordinates);
        };
    }

    /// Invokes `$cb!(TypeName)` for each [`ClosedAxis`] implementor —
    /// the nine axis primitives plus the four product cubes, thirteen
    /// in total, in declaration order. Composes
    /// [`for_each_closed_axis_primitive`] with [`for_each_product_cube`].
    macro_rules! for_each_closed_axis_implementor {
        ($cb:ident) => {
            for_each_closed_axis_primitive!($cb);
            for_each_product_cube!($cb);
        };
    }

    /// Invokes `$cb!(TypeName)` for each [`ClosedAxisLabel`]
    /// implementor — the twelve closed-axis primitives that carry a
    /// canonical operator-facing string label today
    /// ([`PartitionFace`], [`ConfigTierKind`], [`Format`],
    /// [`FormatProvenance`], [`ConfigSourceKind`],
    /// [`FigmentSourceKind`], [`AttributionConfidence`],
    /// [`AttributionAxis`], [`crate::ShikumiErrorKind`],
    /// [`crate::FieldPathLocalization`], [`crate::AttributionRule`],
    /// [`WatchEventClass`]), in declaration order. The two variant-tag
    /// projections sit at the head ([`PartitionFace`] of
    /// [`PartitionOrdinal`], [`ConfigTierKind`] of
    /// [`crate::ConfigTier`]); the nine cube-axis primitives ([`Format`],
    /// operator-facing config file format; [`FormatProvenance`], which
    /// provider class loads the format; [`ConfigSourceKind`], the kind
    /// axis of the resolved figment layer; [`FigmentSourceKind`], the
    /// kind axis of the underlying `figment::Source`;
    /// [`AttributionConfidence`], the equality-vs-uniqueness
    /// confidence class of the resolver attribution;
    /// [`AttributionAxis`], which `figment::Metadata` field drove the
    /// resolver attribution; [`crate::ShikumiErrorKind`], the data-free
    /// discriminant of [`crate::ShikumiError`];
    /// [`crate::FieldPathLocalization`], the tri-state
    /// figment-field-path localization axis of a
    /// [`crate::ShikumiError`]; [`crate::AttributionRule`], the closed
    /// five-rule resolver dispatch axis) close the labeling discipline
    /// on their respective axes through the trait. [`WatchEventClass`]
    /// sits at the tail as the watcher-side reload-relevance
    /// classification — the third non-cube-axis primitive after the
    /// two variant-tag projections, lifting the hot-reload trigger
    /// predicate to one labeled closed three-way partition. With the
    /// [`crate::AttributionRule`] lift, every axis of every product
    /// cube on the typescape now labels through the trait: both axes
    /// of the 18-cell [`crate::ErrorLocalizationCoordinates`] cube,
    /// every axis of the 12-cell [`crate::AttributionCoordinates`]
    /// cube, both axes of the 9-cell
    /// [`crate::AttributionSourceKindCoordinates`] cube, and both axes
    /// of the 8-cell [`crate::FormatCoordinates`] cube — every cell
    /// of every cube is nameable through the trait without re-deriving
    /// a string mapping at any cube-renderer site.
    ///
    /// A thirteenth [`ClosedAxisLabel`] implementor landing on the
    /// typescape (a future closed-axis primitive — a new resolver-side
    /// discriminant, a new error-side discriminant, a new figment-side
    /// classification, a new watcher-side classification) extends the
    /// macro in lockstep with the `impl ClosedAxisLabel` declaration;
    /// the pin in
    /// [`tests::for_each_closed_axis_label_implementor_macro_covers_twelve_implementors`]
    /// catches the discipline violation before silent dropouts at the
    /// five trait-uniform `closed_axis_label_*` test sites below.
    macro_rules! for_each_closed_axis_label_implementor {
        ($cb:ident) => {
            $cb!(PartitionFace);
            $cb!(ConfigTierKind);
            $cb!(Format);
            $cb!(FormatProvenance);
            $cb!(ConfigSourceKind);
            $cb!(FigmentSourceKind);
            $cb!(AttributionConfidence);
            $cb!(AttributionAxis);
            $cb!(ShikumiErrorKind);
            $cb!(FieldPathLocalization);
            $cb!(AttributionRule);
            $cb!(WatchEventClass);
            $cb!(FigmentNameTagKind);
            $cb!(EnvMetadataTagKind);
            $cb!(SecretBackendKind);
            $cb!(SecretRefShape);
            $cb!(SecretOperation);
            $cb!(SecretErrorKind);
            $cb!(SecretClientKind);
            $cb!(DiffLineKind);
        };
    }

    // ---- Trait re-exports match inherent constants/methods pointwise ----

    fn assert_trait_matches_inherent<A>(inherent_all: &[A])
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The trait ALL is the same slice (by content, in the same
        // order) as the inherent ALL — pointwise equality across the
        // whole axis. Reaches every ClosedAxis implementor uniformly:
        // the nine closed-enum axis primitives and the four product
        // cubes.
        assert_eq!(
            <A as ClosedAxis>::ALL.len(),
            inherent_all.len(),
            "trait ALL cardinality must equal inherent ALL cardinality",
        );
        for (i, (trait_cell, inherent_cell)) in <A as ClosedAxis>::ALL
            .iter()
            .zip(inherent_all.iter())
            .enumerate()
        {
            assert_eq!(
                trait_cell, inherent_cell,
                "trait ALL[{i}] must equal inherent ALL[{i}]",
            );
        }
    }

    fn assert_trait_is_realizable_matches_inherent<C>(
        inherent_all: &[C],
        inherent_is_realizable: fn(C) -> bool,
    ) where
        C: ProductCube + std::fmt::Debug,
    {
        // For every cell of the cube, the trait method and the inherent
        // method agree pointwise. Pins that the trait impl forwards to
        // the inherent method without silently flipping the predicate
        // or losing an arm.
        for cell in inherent_all.iter().copied() {
            assert_eq!(
                ProductCube::is_realizable(cell),
                inherent_is_realizable(cell),
                "cell {cell:?}: trait is_realizable must equal inherent is_realizable",
            );
        }
    }

    #[test]
    fn format_coordinates_trait_all_matches_inherent_all() {
        assert_trait_matches_inherent::<FormatCoordinates>(FormatCoordinates::ALL);
    }

    #[test]
    fn attribution_coordinates_trait_all_matches_inherent_all() {
        assert_trait_matches_inherent::<AttributionCoordinates>(AttributionCoordinates::ALL);
    }

    #[test]
    fn error_localization_coordinates_trait_all_matches_inherent_all() {
        assert_trait_matches_inherent::<ErrorLocalizationCoordinates>(
            ErrorLocalizationCoordinates::ALL,
        );
    }

    #[test]
    fn attribution_source_kind_coordinates_trait_all_matches_inherent_all() {
        assert_trait_matches_inherent::<AttributionSourceKindCoordinates>(
            AttributionSourceKindCoordinates::ALL,
        );
    }

    #[test]
    fn format_coordinates_trait_is_realizable_matches_inherent() {
        assert_trait_is_realizable_matches_inherent::<FormatCoordinates>(
            FormatCoordinates::ALL,
            FormatCoordinates::is_realizable,
        );
    }

    #[test]
    fn attribution_coordinates_trait_is_realizable_matches_inherent() {
        assert_trait_is_realizable_matches_inherent::<AttributionCoordinates>(
            AttributionCoordinates::ALL,
            AttributionCoordinates::is_realizable,
        );
    }

    #[test]
    fn error_localization_coordinates_trait_is_realizable_matches_inherent() {
        assert_trait_is_realizable_matches_inherent::<ErrorLocalizationCoordinates>(
            ErrorLocalizationCoordinates::ALL,
            ErrorLocalizationCoordinates::is_realizable,
        );
    }

    #[test]
    fn attribution_source_kind_coordinates_trait_is_realizable_matches_inherent() {
        assert_trait_is_realizable_matches_inherent::<AttributionSourceKindCoordinates>(
            AttributionSourceKindCoordinates::ALL,
            AttributionSourceKindCoordinates::is_realizable,
        );
    }

    // ---- Generic helpers cover ALL exactly once ----

    fn assert_realizable_partitions_all<C>(inherent_all: &[C])
    where
        C: ProductCube + std::fmt::Debug,
    {
        // realizable_iter and unrealizable_iter together cover ALL
        // exactly once, in the same order ALL is laid out. The
        // partition is total (every cell is one or the other) and
        // disjoint (no cell is both).
        let realizable: Vec<C> = realizable_iter::<C>().collect();
        let unrealizable: Vec<C> = unrealizable_iter::<C>().collect();
        assert_eq!(
            realizable.len() + unrealizable.len(),
            inherent_all.len(),
            "realizable + unrealizable cardinalities must sum to ALL cardinality",
        );
        for cell in &realizable {
            assert!(
                ProductCube::is_realizable(*cell),
                "cell {cell:?} in realizable_iter must satisfy is_realizable",
            );
            assert!(
                !unrealizable.contains(cell),
                "cell {cell:?} must not appear in both partitions",
            );
        }
        for cell in &unrealizable {
            assert!(
                !ProductCube::is_realizable(*cell),
                "cell {cell:?} in unrealizable_iter must not satisfy is_realizable",
            );
        }
    }

    #[test]
    fn format_coordinates_generic_realizable_partitions_all() {
        assert_realizable_partitions_all::<FormatCoordinates>(FormatCoordinates::ALL);
    }

    #[test]
    fn attribution_coordinates_generic_realizable_partitions_all() {
        assert_realizable_partitions_all::<AttributionCoordinates>(AttributionCoordinates::ALL);
    }

    #[test]
    fn error_localization_coordinates_generic_realizable_partitions_all() {
        assert_realizable_partitions_all::<ErrorLocalizationCoordinates>(
            ErrorLocalizationCoordinates::ALL,
        );
    }

    #[test]
    fn attribution_source_kind_coordinates_generic_realizable_partitions_all() {
        assert_realizable_partitions_all::<AttributionSourceKindCoordinates>(
            AttributionSourceKindCoordinates::ALL,
        );
    }

    // ---- Generic count helpers pin today's image cardinalities ----

    #[test]
    fn format_coordinates_generic_realizable_count_is_four() {
        assert_eq!(realizable_count::<FormatCoordinates>(), 4);
        assert_eq!(unrealizable_count::<FormatCoordinates>(), 4);
        assert_eq!(
            realizable_count::<FormatCoordinates>() + unrealizable_count::<FormatCoordinates>(),
            FormatCoordinates::ALL.len(),
        );
    }

    #[test]
    fn attribution_coordinates_generic_realizable_count_is_five() {
        assert_eq!(realizable_count::<AttributionCoordinates>(), 5);
        assert_eq!(unrealizable_count::<AttributionCoordinates>(), 7);
        assert_eq!(
            realizable_count::<AttributionCoordinates>()
                + unrealizable_count::<AttributionCoordinates>(),
            AttributionCoordinates::ALL.len(),
        );
    }

    #[test]
    fn error_localization_coordinates_generic_realizable_count_is_eight() {
        assert_eq!(realizable_count::<ErrorLocalizationCoordinates>(), 8);
        assert_eq!(unrealizable_count::<ErrorLocalizationCoordinates>(), 10);
        assert_eq!(
            realizable_count::<ErrorLocalizationCoordinates>()
                + unrealizable_count::<ErrorLocalizationCoordinates>(),
            ErrorLocalizationCoordinates::ALL.len(),
        );
    }

    #[test]
    fn attribution_source_kind_coordinates_generic_realizable_count_is_two() {
        assert_eq!(realizable_count::<AttributionSourceKindCoordinates>(), 2);
        assert_eq!(unrealizable_count::<AttributionSourceKindCoordinates>(), 7);
        assert_eq!(
            realizable_count::<AttributionSourceKindCoordinates>()
                + unrealizable_count::<AttributionSourceKindCoordinates>(),
            AttributionSourceKindCoordinates::ALL.len(),
        );
    }

    // ---- All four cubes plug into the trait uniformly ----

    #[test]
    fn all_four_product_cubes_have_nonempty_all() {
        // Trivially-true sanity check that reaches into each cube
        // through the trait ALL — pins that all four impls compile and
        // are linked into the binary. A fifth cube landing without an
        // `impl ProductCube` arm would not be reached here, but the
        // trait bound on the future generic consumer would fail to
        // compile, which is the structural enforcement of the
        // discipline.
        assert!(!<FormatCoordinates as ClosedAxis>::ALL.is_empty());
        assert!(!<AttributionCoordinates as ClosedAxis>::ALL.is_empty());
        assert!(!<ErrorLocalizationCoordinates as ClosedAxis>::ALL.is_empty());
        assert!(!<AttributionSourceKindCoordinates as ClosedAxis>::ALL.is_empty());
    }

    // ---- PartialInverseCube invariants ----
    //
    // The trait invariant — `cell.invert().is_some() ==
    // ProductCube::is_realizable(cell)` for every cell of every
    // implementor — is asserted by one trait-uniform helper reaching
    // each implementor pointwise. A third (or fourth) implementor
    // landing picks up the invariant test by adding one call to the
    // helper, not by re-deriving the loop body inline.

    fn assert_partial_inverse_some_iff_is_realizable<C>()
    where
        C: PartialInverseCube + std::fmt::Debug,
    {
        for cell in <C as ClosedAxis>::ALL.iter().copied() {
            assert_eq!(
                cell.invert().is_some(),
                ProductCube::is_realizable(cell),
                "cell {cell:?}: invert().is_some() must equal is_realizable()",
            );
        }
    }

    #[test]
    fn format_coordinates_partial_inverse_some_iff_is_realizable() {
        assert_partial_inverse_some_iff_is_realizable::<FormatCoordinates>();
    }

    #[test]
    fn attribution_coordinates_partial_inverse_some_iff_is_realizable() {
        assert_partial_inverse_some_iff_is_realizable::<AttributionCoordinates>();
    }

    #[test]
    fn format_coordinates_realizable_images_cardinality_matches_realizable_count() {
        // The generic realizable_images iterator has the same
        // cardinality as the realizable-cell count — proven by the
        // trait invariant invert().is_some() == is_realizable() that
        // assert_partial_inverse_some_iff_is_realizable pins.
        assert_eq!(
            realizable_images::<FormatCoordinates>().count(),
            realizable_count::<FormatCoordinates>(),
        );
    }

    #[test]
    fn attribution_coordinates_realizable_images_cardinality_matches_realizable_count() {
        assert_eq!(
            realizable_images::<AttributionCoordinates>().count(),
            realizable_count::<AttributionCoordinates>(),
        );
    }

    fn assert_realizable_images_equals_image_all<C>()
    where
        C: PartialInverseCube + std::fmt::Debug,
    {
        // For an injective forward map (each implementor's inherent
        // `Image::<forward>` is injective on `Image::ALL`), the
        // realizable-images iterator produces every image exactly
        // once. Pins that the partial inverse covers Image::ALL
        // pointwise — generic over the cube type so today's two
        // PartialInverseCube implementors and any future implementor
        // share one helper instead of duplicating the body per cube.
        use std::collections::HashSet;
        let images: HashSet<C::Image> = realizable_images::<C>().collect();
        let expected: HashSet<C::Image> = <C::Image as ClosedAxis>::ALL.iter().copied().collect();
        assert_eq!(
            images, expected,
            "realizable_images must equal Image::ALL as a set",
        );
    }

    #[test]
    fn format_coordinates_realizable_images_equals_format_all() {
        assert_realizable_images_equals_image_all::<FormatCoordinates>();
    }

    #[test]
    fn attribution_coordinates_realizable_images_equals_rule_all() {
        assert_realizable_images_equals_image_all::<AttributionCoordinates>();
    }

    // ---- ClosedAxis invariants reach all thirteen implementors ----
    //
    // The nine closed-enum axis primitives plus the four product cubes
    // plug into the same trait. One trait-uniform helper, one
    // generic-helper agreement check, and one cardinality check pin
    // the discipline pointwise on every implementor.

    fn assert_axis_iter_matches_trait_all<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // axis_iter::<A>() is the named lift of A::ALL.iter().copied();
        // pin the two produce the same sequence in the same order. The
        // helper consolidates the 98+ inline `::ALL.iter().copied()`
        // sites the crate carries across cover / partition / cube-
        // coverage tests.
        let iter_collected: Vec<A> = axis_iter::<A>().collect();
        let all_collected: Vec<A> = <A as ClosedAxis>::ALL.to_vec();
        assert_eq!(
            iter_collected.len(),
            all_collected.len(),
            "axis_iter cardinality must equal trait ALL cardinality",
        );
        for (i, (from_iter, from_all)) in
            iter_collected.iter().zip(all_collected.iter()).enumerate()
        {
            assert_eq!(
                from_iter, from_all,
                "axis_iter[{i}] must equal trait ALL[{i}]",
            );
        }
    }

    fn assert_axis_cardinality_matches_trait_all<A>(expected: usize)
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // axis_cardinality::<A>() is the named lift of A::ALL.len();
        // pin agreement with the trait constant slice length and with
        // the today-pinned variant count so a future variant landing
        // (a tenth typescape axis primitive variant on any of the nine
        // enums, or a fifth cell axis on any of the four cubes) moves
        // the expected count in lockstep.
        assert_eq!(
            axis_cardinality::<A>(),
            <A as ClosedAxis>::ALL.len(),
            "axis_cardinality must equal trait ALL slice length",
        );
        assert_eq!(
            axis_cardinality::<A>(),
            expected,
            "axis_cardinality must equal today's pinned variant count",
        );
    }

    // ---- The nine closed-enum axis primitives ----

    #[test]
    fn format_trait_all_matches_inherent_all() {
        assert_trait_matches_inherent::<Format>(Format::ALL);
    }

    #[test]
    fn format_provenance_trait_all_matches_inherent_all() {
        assert_trait_matches_inherent::<FormatProvenance>(FormatProvenance::ALL);
    }

    #[test]
    fn config_source_kind_trait_all_matches_inherent_all() {
        assert_trait_matches_inherent::<ConfigSourceKind>(ConfigSourceKind::ALL);
    }

    #[test]
    fn figment_source_kind_trait_all_matches_inherent_all() {
        assert_trait_matches_inherent::<FigmentSourceKind>(FigmentSourceKind::ALL);
    }

    #[test]
    fn shikumi_error_kind_trait_all_matches_inherent_all() {
        assert_trait_matches_inherent::<ShikumiErrorKind>(ShikumiErrorKind::ALL);
    }

    #[test]
    fn field_path_localization_trait_all_matches_inherent_all() {
        assert_trait_matches_inherent::<FieldPathLocalization>(FieldPathLocalization::ALL);
    }

    #[test]
    fn attribution_rule_trait_all_matches_inherent_all() {
        assert_trait_matches_inherent::<AttributionRule>(AttributionRule::ALL);
    }

    #[test]
    fn attribution_confidence_trait_all_matches_inherent_all() {
        assert_trait_matches_inherent::<AttributionConfidence>(AttributionConfidence::ALL);
    }

    #[test]
    fn attribution_axis_trait_all_matches_inherent_all() {
        assert_trait_matches_inherent::<AttributionAxis>(AttributionAxis::ALL);
    }

    #[test]
    fn partition_face_trait_all_matches_inherent_all() {
        // PartitionFace is the tenth closed-axis primitive — the
        // variant-tag projection of `PartitionOrdinal`. The trait
        // `ALL` slice is the inherent `ALL` slice (pointwise equal,
        // same declaration order: Realizable, Unrealizable). A future
        // variant landing on `PartitionFace` extends both slices in
        // lockstep, but no expansion is anticipated: the two-element
        // {realizable, unrealizable} partition is structural to
        // `ProductCube::is_realizable`.
        assert_trait_matches_inherent::<PartitionFace>(PartitionFace::ALL);
    }

    #[test]
    fn watch_event_class_trait_all_matches_inherent_all() {
        // `WatchEventClass` is the twelfth closed-axis primitive — the
        // reload-relevance classification of a raw `notify::Event`
        // kind, lifted by `crate::watcher` into the typescape primitive
        // set. The trait `ALL` slice is the inherent `ALL` slice
        // (pointwise equal, same declaration order: `Reload`,
        // `Removed`, `Ignored`). A future variant landing on
        // `WatchEventClass` (e.g. a `Quiesced` class for a debounced
        // window with no triggers) extends both slices in lockstep.
        // Pins that the trait-uniform invariant suite reaching every
        // `for_each_closed_axis_*` macro arm now reaches the
        // watcher-side classification on the same proof harness as
        // every other axis primitive on the typescape.
        assert_trait_matches_inherent::<WatchEventClass>(WatchEventClass::ALL);
    }

    #[test]
    fn figment_name_tag_kind_trait_all_matches_inherent_all() {
        // `FigmentNameTagKind` is the thirteenth closed-axis primitive
        // — the `'static` discriminant of `crate::FigmentNameTag` on
        // figment's `Metadata::name` axis, the symmetric peer of
        // `FigmentSourceKind` on the `Metadata::source` axis. The
        // trait `ALL` slice is the inherent `ALL` slice (pointwise
        // equal, same declaration order: `Format`, `Env`). A future
        // variant landing on `FigmentNameTagKind` (e.g. a hypothetical
        // `Url` kind in lockstep with a `FigmentNameTag::Url` if
        // figment's name axis grows one) extends both slices in
        // lockstep. Pins that the trait-uniform invariant suite
        // reaching every `for_each_closed_axis_*` macro arm now
        // reaches the figment-name-axis kind classification on the
        // same proof harness as the figment-Source-axis kind and
        // every other axis primitive on the typescape.
        assert_trait_matches_inherent::<FigmentNameTagKind>(FigmentNameTagKind::ALL);
    }

    // ---- axis_iter agrees with trait ALL for every implementor ----

    #[test]
    fn axis_iter_matches_trait_all_for_every_closed_enum_axis() {
        macro_rules! check {
            ($ty:ident) => {
                assert_axis_iter_matches_trait_all::<$ty>();
            };
        }
        for_each_closed_axis_primitive!(check);
    }

    #[test]
    fn axis_iter_matches_trait_all_for_every_product_cube() {
        macro_rules! check {
            ($ty:ident) => {
                assert_axis_iter_matches_trait_all::<$ty>();
            };
        }
        for_each_product_cube!(check);
    }

    // ---- axis_cardinality pins today's variant / cell counts ----

    #[test]
    fn axis_cardinality_pins_todays_counts_across_twenty_implementors() {
        // Twenty closed-enum axis primitives. A new variant landing
        // on any of these enums extends the expected count in
        // lockstep.
        assert_axis_cardinality_matches_trait_all::<Format>(4);
        assert_axis_cardinality_matches_trait_all::<FormatProvenance>(2);
        assert_axis_cardinality_matches_trait_all::<ConfigSourceKind>(3);
        assert_axis_cardinality_matches_trait_all::<FigmentSourceKind>(3);
        assert_axis_cardinality_matches_trait_all::<ShikumiErrorKind>(6);
        assert_axis_cardinality_matches_trait_all::<FieldPathLocalization>(3);
        assert_axis_cardinality_matches_trait_all::<AttributionRule>(5);
        assert_axis_cardinality_matches_trait_all::<AttributionConfidence>(2);
        assert_axis_cardinality_matches_trait_all::<AttributionAxis>(2);
        assert_axis_cardinality_matches_trait_all::<PartitionFace>(2);
        assert_axis_cardinality_matches_trait_all::<ConfigTierKind>(4);
        assert_axis_cardinality_matches_trait_all::<WatchEventClass>(3);
        assert_axis_cardinality_matches_trait_all::<FigmentNameTagKind>(2);
        assert_axis_cardinality_matches_trait_all::<EnvMetadataTagKind>(2);
        assert_axis_cardinality_matches_trait_all::<DiffLineKind>(3);
        // Five product cubes. A new cell-axis landing on any cube
        // extends the expected count by the product of the new axis's
        // cardinality with the cube's prior cardinality.
        assert_axis_cardinality_matches_trait_all::<FormatCoordinates>(8);
        assert_axis_cardinality_matches_trait_all::<AttributionCoordinates>(12);
        assert_axis_cardinality_matches_trait_all::<ErrorLocalizationCoordinates>(18);
        assert_axis_cardinality_matches_trait_all::<AttributionSourceKindCoordinates>(9);
        assert_axis_cardinality_matches_trait_all::<AttributionNameKindCoordinates>(6);
    }

    // ---- axis_ordinal closes the dense-embedding round-trip ----
    //
    // `axis_ordinal::<A>(v)` is the dual of `axis_iter::<A>()`:
    // iteration yields `A::ALL[i]`; ordinal recovers `i` from the value.
    // Two trait-uniform invariants reach every implementor pointwise:
    //
    //   (a) round-trip — `A::ALL[axis_ordinal(v)] == v` for every
    //       `v: A`, and dually `axis_ordinal(A::ALL[i]) == i` for every
    //       `i < axis_cardinality::<A>()`;
    //   (b) injectivity — distinct values land at distinct ordinals,
    //       equivalently the ordinal image equals
    //       `0..axis_cardinality::<A>()` as a set (no duplicates in
    //       `A::ALL`).
    //
    // A tenth axis primitive or fifth product cube landing picks up
    // both invariants by adding one line to each helper-bundle test.

    fn assert_axis_ordinal_round_trips<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Forward law: `A::ALL[axis_ordinal(v)] == v` for every
        // `v: A`. Iterates A::ALL once, recomputes the ordinal of
        // each value, and re-indexes A::ALL with it.
        for (i, value) in A::ALL.iter().copied().enumerate() {
            let ordinal = axis_ordinal::<A>(value);
            assert_eq!(
                ordinal, i,
                "axis_ordinal(A::ALL[{i}]) must equal {i}; got {ordinal}",
            );
            assert_eq!(
                A::ALL[ordinal],
                value,
                "A::ALL[axis_ordinal(v)] must equal v for v = A::ALL[{i}]",
            );
        }
    }

    fn assert_axis_ordinal_injective<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Injectivity: distinct values land at distinct ordinals.
        // Equivalently, the ordinal image over A::ALL equals
        // `0..axis_cardinality::<A>()` as a set — the canonical dense
        // embedding of the axis into the natural-number prefix. Pins
        // the no-duplicates discipline on A::ALL uniformly across all
        // implementors at one site (replaces the per-axis
        // `*_all_has_no_duplicates` invariant at the trait level
        // without removing the per-axis tests).
        use std::collections::HashSet;
        let ordinals: HashSet<usize> = axis_iter::<A>().map(axis_ordinal::<A>).collect();
        let expected: HashSet<usize> = (0..axis_cardinality::<A>()).collect();
        assert_eq!(
            ordinals, expected,
            "axis_ordinal image over A::ALL must equal 0..axis_cardinality::<A>() as a set",
        );
    }

    #[test]
    fn axis_ordinal_round_trips_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_axis_ordinal_round_trips::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_ordinal_injective_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_axis_ordinal_injective::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_ordinal_pins_first_and_last_positions_for_every_implementor() {
        // For every ClosedAxis implementor, the first value of
        // `A::ALL` lands at ordinal 0 and the last lands at
        // `axis_cardinality::<A>() - 1`. Pins the endpoints of the
        // dense embedding so a future re-ordering of `::ALL` (the
        // declaration-order discipline) is caught at the
        // first/last call site, not only by the round-trip law.
        fn assert_endpoints<A: ClosedAxis>() {
            let n = axis_cardinality::<A>();
            assert!(n > 0, "ClosedAxis::ALL must be non-empty");
            assert_eq!(axis_ordinal::<A>(A::ALL[0]), 0);
            assert_eq!(axis_ordinal::<A>(A::ALL[n - 1]), n - 1);
        }
        macro_rules! check {
            ($ty:ident) => {
                assert_endpoints::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    // ---- axis_at closes the safe forward direction of the
    // ---- (axis_ordinal, axis_at) bijection ----
    //
    // `axis_at::<A>(i)` is the safe forward dual of `axis_ordinal::<A>`:
    // where `axis_ordinal` is the total inverse `value → ordinal` over
    // the closed axis, `axis_at` is the partial forward
    // `ordinal → Option<value>` over `usize`, returning `Some` on the
    // prefix `0..axis_cardinality::<A>()` and `None` outside it. Three
    // trait-uniform invariants reach every implementor pointwise:
    //
    //   (a) round-trip from the value side —
    //       `axis_at(axis_ordinal(v)) == Some(v)` for every `v: A`;
    //   (b) round-trip from the ordinal side —
    //       `axis_at(i).map(axis_ordinal) == Some(i)` for every
    //       `i < axis_cardinality::<A>()`;
    //   (c) partiality on out-of-range —
    //       `axis_at(i).is_none()` for every
    //       `i >= axis_cardinality::<A>()`.
    //
    // Together (a)+(b)+(c) state the bijection between every
    // ClosedAxis implementor and the prefix `0..axis_cardinality::<A>()`
    // of the natural numbers, with the partiality at the OOB boundary
    // surfaced at the type level via the `Option` return rather than
    // by `A::ALL[i]` panicking on the slice index. A tenth axis
    // primitive or fifth product cube landing picks up all three
    // invariants by adding one line to each helper-bundle test.

    fn assert_axis_at_round_trips_value_side<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // For every value of A, ordinal-then-lookup recovers the value.
        // The composition `axis_at ∘ axis_ordinal` is the identity on A.
        for value in axis_iter::<A>() {
            let ordinal = axis_ordinal::<A>(value);
            assert_eq!(
                axis_at::<A>(ordinal),
                Some(value),
                "axis_at(axis_ordinal({value:?})) must equal Some({value:?})",
            );
        }
    }

    fn assert_axis_at_round_trips_ordinal_side<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // For every in-range ordinal, lookup-then-ordinal recovers the
        // ordinal. The composition `axis_ordinal ∘ axis_at` is the
        // identity on the prefix `0..axis_cardinality::<A>()`.
        for i in 0..axis_cardinality::<A>() {
            let recovered = axis_at::<A>(i).map(axis_ordinal::<A>);
            assert_eq!(
                recovered,
                Some(i),
                "axis_at({i}).map(axis_ordinal) must equal Some({i}) for in-range ordinal",
            );
        }
    }

    fn assert_axis_at_none_on_out_of_range<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // For every out-of-range ordinal, the forward map returns None.
        // Pins the partiality boundary: axis_at is defined exactly on
        // the prefix `0..axis_cardinality::<A>()`. Checks the immediate
        // boundary (n, n+1) plus a comfortable margin (n+7) and the
        // `usize::MAX` extreme to catch any silent saturation.
        let n = axis_cardinality::<A>();
        for i in [n, n + 1, n + 7, usize::MAX] {
            assert!(
                axis_at::<A>(i).is_none(),
                "axis_at({i}) must be None for ordinal >= axis_cardinality (n = {n})",
            );
        }
    }

    #[test]
    fn axis_at_round_trips_value_side_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_axis_at_round_trips_value_side::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_at_round_trips_ordinal_side_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_axis_at_round_trips_ordinal_side::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_at_returns_none_on_out_of_range_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_axis_at_none_on_out_of_range::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_at_agrees_with_axis_iter_pointwise_for_every_implementor() {
        // `axis_at::<A>(i)` and the `i`-th element of `axis_iter::<A>()`
        // must agree pointwise. Pins that `axis_at` indexes through the
        // same declaration-order surface that `axis_iter` streams; a
        // future re-ordering of `::ALL` would fail here as well as in
        // the round-trip tests, but at the per-position site rather
        // than only at the bijection level.
        fn assert_pointwise<A>()
        where
            A: ClosedAxis + std::fmt::Debug,
        {
            for (i, from_iter) in axis_iter::<A>().enumerate() {
                assert_eq!(
                    axis_at::<A>(i),
                    Some(from_iter),
                    "axis_at({i}) must equal Some(axis_iter[{i}]) = Some({from_iter:?})",
                );
            }
        }
        macro_rules! check {
            ($ty:ident) => {
                assert_pointwise::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_iter_for_product_cube_agrees_with_realizable_plus_unrealizable() {
        // For any ProductCube, axis_iter::<C>() is the disjoint union
        // of realizable_iter::<C>() and unrealizable_iter::<C>() in the
        // declaration-order interleaving the underlying ClosedAxis::ALL
        // pins. The realizability filter cuts ALL into the two halves,
        // and axis_iter recovers the whole.
        fn assert_axis_iter_recovers_partition<C>()
        where
            C: ProductCube + std::fmt::Debug,
        {
            use std::collections::HashSet;
            let whole: HashSet<C> = axis_iter::<C>().collect();
            let realizable: HashSet<C> = realizable_iter::<C>().collect();
            let unrealizable: HashSet<C> = unrealizable_iter::<C>().collect();
            assert!(
                realizable.is_disjoint(&unrealizable),
                "realizable and unrealizable halves must be disjoint",
            );
            let recovered: HashSet<C> = realizable.union(&unrealizable).copied().collect();
            assert_eq!(
                whole, recovered,
                "axis_iter must equal realizable ∪ unrealizable as a set",
            );
        }
        macro_rules! check {
            ($ty:ident) => {
                assert_axis_iter_recovers_partition::<$ty>();
            };
        }
        for_each_product_cube!(check);
    }

    // ---- realizable_ordinal / realizable_at close the dense bijection
    // ---- between the realizable surface and 0..realizable_count ----
    //
    // The pair (realizable_ordinal, realizable_at) is the cube-level
    // analog of (axis_ordinal, axis_at): a dense embedding of the
    // recognized-image half of the cube into the natural-number prefix
    // `0..realizable_count::<C>()`. Where (axis_ordinal, axis_at) close
    // the total/partial bijection between every ClosedAxis implementor
    // and `0..axis_cardinality::<A>()`, the cube-level pair closes the
    // partial/partial bijection between the realizable surface and
    // `0..realizable_count::<C>()`, with the unrealizable complement
    // returning None on both sides. Four trait-uniform invariants reach
    // every implementor pointwise:
    //
    //   (a) realizable_ordinal partiality —
    //       `realizable_ordinal(cell).is_some() == is_realizable(cell)`;
    //   (b) realizable_at partiality —
    //       `realizable_at(i).is_some() == (i < realizable_count)`;
    //   (c) round-trip — `realizable_at(realizable_ordinal(c).unwrap()) == Some(c)`
    //       for every realizable cell, and dually
    //       `realizable_at(i).and_then(realizable_ordinal) == Some(i)`
    //       for every in-range ordinal;
    //   (d) image realizability — every `realizable_at(i)` for in-range
    //       `i` returns Some(cell) with is_realizable(cell) true.
    //
    // A fifth product cube landing picks up all four invariants by
    // adding one line to each helper-bundle test.

    fn assert_realizable_ordinal_some_iff_is_realizable<C>()
    where
        C: ProductCube + std::fmt::Debug,
    {
        // For every cell of the cube, the dense ordinal is Some exactly
        // when the cell is realizable. The ordinal is defined precisely
        // on the realizable surface; the unrealizable complement
        // uniformly returns None. Equivalent to `is_realizable` at the
        // partiality boundary — pins that the dense embedding's domain
        // equals the realizable surface, not a different subset.
        for cell in axis_iter::<C>() {
            assert_eq!(
                realizable_ordinal::<C>(cell).is_some(),
                ProductCube::is_realizable(cell),
                "cell {cell:?}: realizable_ordinal(...).is_some() must equal is_realizable(...)",
            );
        }
    }

    fn assert_realizable_at_some_iff_in_realizable_prefix<C>()
    where
        C: ProductCube + std::fmt::Debug,
    {
        // For every in-range ordinal `i < realizable_count::<C>()`, the
        // dense lookup returns Some; for every out-of-range ordinal, it
        // returns None. The boundary check exercises the immediate
        // boundary (`n`, `n+1`), a comfortable margin (`n+7`), and the
        // `usize::MAX` extreme to catch any silent saturation. Pins
        // that the dense embedding's image equals `0..realizable_count`
        // and that the Option return surfaces the partiality cleanly.
        let n = realizable_count::<C>();
        for i in 0..n {
            assert!(
                realizable_at::<C>(i).is_some(),
                "realizable_at({i}) must be Some for in-range ordinal (n = {n})",
            );
        }
        for i in [n, n + 1, n + 7, usize::MAX] {
            assert!(
                realizable_at::<C>(i).is_none(),
                "realizable_at({i}) must be None for ordinal >= realizable_count (n = {n})",
            );
        }
    }

    fn assert_realizable_round_trips_cell_side<C>()
    where
        C: ProductCube + std::fmt::Debug,
    {
        // For every realizable cell `c`, ordinal-then-lookup recovers
        // the cell: `realizable_at(realizable_ordinal(c).unwrap()) ==
        // Some(c)`. The composition `realizable_at ∘ realizable_ordinal`
        // is the identity on the realizable surface — the cube-level
        // analog of `axis_at ∘ axis_ordinal` being the identity on A.
        for cell in realizable_iter::<C>() {
            let ordinal = realizable_ordinal::<C>(cell)
                .expect("realizable_iter must yield only ordinal-Some cells");
            assert_eq!(
                realizable_at::<C>(ordinal),
                Some(cell),
                "realizable_at(realizable_ordinal({cell:?}).unwrap()) must equal Some({cell:?})",
            );
        }
    }

    fn assert_realizable_round_trips_ordinal_side<C>()
    where
        C: ProductCube + std::fmt::Debug,
    {
        // For every in-range ordinal `i < realizable_count::<C>()`,
        // lookup-then-ordinal recovers the ordinal: `realizable_at(i)
        // .and_then(realizable_ordinal) == Some(i)`. The composition
        // `realizable_ordinal ∘ realizable_at` is the identity on the
        // in-range prefix — the cube-level analog of `axis_ordinal ∘
        // axis_at` being the identity on `0..axis_cardinality::<A>()`.
        for i in 0..realizable_count::<C>() {
            let recovered = realizable_at::<C>(i).and_then(realizable_ordinal::<C>);
            assert_eq!(
                recovered,
                Some(i),
                "realizable_at({i}).and_then(realizable_ordinal) must equal Some({i})",
            );
        }
    }

    fn assert_realizable_at_image_is_realizable<C>()
    where
        C: ProductCube + std::fmt::Debug,
    {
        // For every in-range ordinal `i`, the dense lookup lands on a
        // realizable cell: `realizable_at(i).map(is_realizable) ==
        // Some(true)`. Pins that the forward map's image is the
        // realizable surface, not the full cube `ALL`. Stated separately
        // from the partiality invariant so a future helper change that
        // accidentally exposes unrealizable cells in the in-range
        // prefix would fail here as well as in the round-trip law.
        for i in 0..realizable_count::<C>() {
            let cell = realizable_at::<C>(i)
                .expect("in-range realizable_at must yield Some by partiality invariant");
            assert!(
                ProductCube::is_realizable(cell),
                "realizable_at({i}) = {cell:?} must satisfy is_realizable",
            );
        }
    }

    fn assert_realizable_ordinal_image_equals_realizable_prefix<C>()
    where
        C: ProductCube + std::fmt::Debug,
    {
        // The ordinal image over the realizable surface equals
        // `0..realizable_count::<C>()` as a set. Equivalent to the
        // injectivity statement: distinct realizable cells land at
        // distinct ordinals, and the dense embedding is a bijection
        // (not merely an injection) onto the prefix. Pins that
        // `realizable_iter::<C>()` carries no duplicates — the cube-
        // level dual of the no-duplicates invariant on `A::ALL`.
        use std::collections::HashSet;
        let ordinals: HashSet<usize> = realizable_iter::<C>()
            .map(|c| {
                realizable_ordinal::<C>(c)
                    .expect("realizable_iter must yield only ordinal-Some cells")
            })
            .collect();
        let expected: HashSet<usize> = (0..realizable_count::<C>()).collect();
        assert_eq!(
            ordinals, expected,
            "realizable_ordinal image over realizable_iter must equal 0..realizable_count as a set",
        );
    }

    #[test]
    fn realizable_ordinal_some_iff_is_realizable() {
        macro_rules! check {
            ($ty:ident) => {
                assert_realizable_ordinal_some_iff_is_realizable::<$ty>();
            };
        }
        for_each_product_cube!(check);
    }

    #[test]
    fn realizable_at_some_iff_in_realizable_prefix() {
        macro_rules! check {
            ($ty:ident) => {
                assert_realizable_at_some_iff_in_realizable_prefix::<$ty>();
            };
        }
        for_each_product_cube!(check);
    }

    #[test]
    fn realizable_round_trips_cell_side() {
        macro_rules! check {
            ($ty:ident) => {
                assert_realizable_round_trips_cell_side::<$ty>();
            };
        }
        for_each_product_cube!(check);
    }

    #[test]
    fn realizable_round_trips_ordinal_side() {
        macro_rules! check {
            ($ty:ident) => {
                assert_realizable_round_trips_ordinal_side::<$ty>();
            };
        }
        for_each_product_cube!(check);
    }

    #[test]
    fn realizable_at_image_is_realizable() {
        macro_rules! check {
            ($ty:ident) => {
                assert_realizable_at_image_is_realizable::<$ty>();
            };
        }
        for_each_product_cube!(check);
    }

    #[test]
    fn realizable_ordinal_image_equals_realizable_prefix() {
        macro_rules! check {
            ($ty:ident) => {
                assert_realizable_ordinal_image_equals_realizable_prefix::<$ty>();
            };
        }
        for_each_product_cube!(check);
    }

    #[test]
    fn realizable_ordinal_pins_format_coordinates_dense_ordinals() {
        // FormatCoordinates::ALL lays the 8 cells in lex order over
        // (format × provenance); the 4 realizable cells sit at full-cube
        // indices 0, 2, 5, 7 (where `provenance == format.provenance()`).
        // axis_ordinal returns those positions in the full-cube slice;
        // realizable_ordinal returns the dense positions 0, 1, 2, 3 in
        // realizable_iter, skipping the interleaved unrealizable cells.
        // The two ordinals differ on cells whose realizable surface is
        // not a prefix of `C::ALL` — pinning that here so a future
        // re-ordering of `FormatCoordinates::ALL` or change to
        // `is_realizable` is caught at the concrete-position level, not
        // only at the abstract bijection level.
        use crate::{FormatCoordinates, FormatProvenance};
        let yaml_figment = FormatCoordinates {
            format: Format::Yaml,
            provenance: FormatProvenance::FigmentBuiltin,
        };
        let toml_figment = FormatCoordinates {
            format: Format::Toml,
            provenance: FormatProvenance::FigmentBuiltin,
        };
        let lisp_shikumi = FormatCoordinates {
            format: Format::Lisp,
            provenance: FormatProvenance::ShikumiBuilt,
        };
        let nix_shikumi = FormatCoordinates {
            format: Format::Nix,
            provenance: FormatProvenance::ShikumiBuilt,
        };
        assert_eq!(
            realizable_ordinal::<FormatCoordinates>(yaml_figment),
            Some(0)
        );
        assert_eq!(
            realizable_ordinal::<FormatCoordinates>(toml_figment),
            Some(1)
        );
        assert_eq!(
            realizable_ordinal::<FormatCoordinates>(lisp_shikumi),
            Some(2)
        );
        assert_eq!(
            realizable_ordinal::<FormatCoordinates>(nix_shikumi),
            Some(3)
        );
        // axis_ordinal pins the full-cube positions on the same cells;
        // the gap (0,2,5,7) versus the dense ordinals (0,1,2,3) is
        // exactly the interleaving the dense embedding collapses.
        assert_eq!(axis_ordinal::<FormatCoordinates>(yaml_figment), 0);
        assert_eq!(axis_ordinal::<FormatCoordinates>(toml_figment), 2);
        assert_eq!(axis_ordinal::<FormatCoordinates>(lisp_shikumi), 5);
        assert_eq!(axis_ordinal::<FormatCoordinates>(nix_shikumi), 7);
        // Unrealizable cells return None on the dense ordinal — pinned
        // for one mid-cube unrealizable cell as a concrete witness.
        let yaml_shikumi = FormatCoordinates {
            format: Format::Yaml,
            provenance: FormatProvenance::ShikumiBuilt,
        };
        assert_eq!(realizable_ordinal::<FormatCoordinates>(yaml_shikumi), None);
        // The full-cube ordinal stays defined on the unrealizable
        // cell (it is in `ALL`), surfacing the partiality difference
        // between axis_ordinal (total over `ALL`) and realizable_ordinal
        // (partial over the realizable surface).
        assert_eq!(axis_ordinal::<FormatCoordinates>(yaml_shikumi), 1);
    }

    // ---- unrealizable_ordinal / unrealizable_at close the dense
    // ---- bijection between the unrealizable complement and
    // ---- 0..unrealizable_count ----
    //
    // The pair (unrealizable_ordinal, unrealizable_at) is the symmetric
    // dual of (realizable_ordinal, realizable_at) on the cube's opposite
    // face — a dense embedding of the consistency-violation complement
    // into the natural-number prefix `0..unrealizable_count::<C>()`.
    // Together the two pairs partition the cube cleanly: every
    // full-cube cell has exactly one defined dense ordinal (realizable
    // or unrealizable, never both), and every in-range dense ordinal
    // on either side lands on a cell of the matching realizability.
    // Four trait-uniform invariants reach every implementor pointwise:
    //
    //   (a) unrealizable_ordinal partiality —
    //       `unrealizable_ordinal(cell).is_some() == !is_realizable(cell)`;
    //   (b) unrealizable_at partiality —
    //       `unrealizable_at(i).is_some() == (i < unrealizable_count)`;
    //   (c) round-trip — `unrealizable_at(unrealizable_ordinal(c).unwrap()) == Some(c)`
    //       for every unrealizable cell, and dually
    //       `unrealizable_at(i).and_then(unrealizable_ordinal) == Some(i)`
    //       for every in-range ordinal;
    //   (d) image unrealizability — every `unrealizable_at(i)` for
    //       in-range `i` returns Some(cell) with is_realizable(cell)
    //       false.
    //
    // A fifth product cube landing picks up all four invariants by
    // adding one line to each helper-bundle test through the
    // `for_each_product_cube!` macro.

    fn assert_unrealizable_ordinal_some_iff_not_is_realizable<C>()
    where
        C: ProductCube + std::fmt::Debug,
    {
        // For every cell of the cube, the dense unrealizable ordinal is
        // Some exactly when the cell is NOT realizable. The ordinal is
        // defined precisely on the unrealizable complement; the
        // realizable surface uniformly returns None. The Boolean dual
        // of `realizable_ordinal_some_iff_is_realizable` — pins that
        // the dense embedding's domain equals the unrealizable
        // complement, not a different subset.
        for cell in axis_iter::<C>() {
            assert_eq!(
                unrealizable_ordinal::<C>(cell).is_some(),
                !ProductCube::is_realizable(cell),
                "cell {cell:?}: unrealizable_ordinal(...).is_some() must equal !is_realizable(...)",
            );
        }
    }

    fn assert_unrealizable_at_some_iff_in_unrealizable_prefix<C>()
    where
        C: ProductCube + std::fmt::Debug,
    {
        // For every in-range ordinal `i < unrealizable_count::<C>()`,
        // the dense lookup returns Some; for every out-of-range
        // ordinal, it returns None. The boundary check exercises the
        // immediate boundary (`n`, `n+1`), a comfortable margin
        // (`n+7`), and the `usize::MAX` extreme to catch any silent
        // saturation — mirrors `realizable_at_some_iff_in_realizable_prefix`
        // on the opposite face of the cube.
        let n = unrealizable_count::<C>();
        for i in 0..n {
            assert!(
                unrealizable_at::<C>(i).is_some(),
                "unrealizable_at({i}) must be Some for in-range ordinal (n = {n})",
            );
        }
        for i in [n, n + 1, n + 7, usize::MAX] {
            assert!(
                unrealizable_at::<C>(i).is_none(),
                "unrealizable_at({i}) must be None for ordinal >= unrealizable_count (n = {n})",
            );
        }
    }

    fn assert_unrealizable_round_trips_cell_side<C>()
    where
        C: ProductCube + std::fmt::Debug,
    {
        // For every unrealizable cell `c`, ordinal-then-lookup recovers
        // the cell: `unrealizable_at(unrealizable_ordinal(c).unwrap())
        // == Some(c)`. The composition `unrealizable_at ∘
        // unrealizable_ordinal` is the identity on the unrealizable
        // complement — the symmetric dual of `realizable_at ∘
        // realizable_ordinal` being the identity on the realizable
        // surface.
        for cell in unrealizable_iter::<C>() {
            let ordinal = unrealizable_ordinal::<C>(cell)
                .expect("unrealizable_iter must yield only ordinal-Some cells");
            assert_eq!(
                unrealizable_at::<C>(ordinal),
                Some(cell),
                "unrealizable_at(unrealizable_ordinal({cell:?}).unwrap()) must equal Some({cell:?})",
            );
        }
    }

    fn assert_unrealizable_round_trips_ordinal_side<C>()
    where
        C: ProductCube + std::fmt::Debug,
    {
        // For every in-range ordinal `i < unrealizable_count::<C>()`,
        // lookup-then-ordinal recovers the ordinal:
        // `unrealizable_at(i).and_then(unrealizable_ordinal) ==
        // Some(i)`. The composition `unrealizable_ordinal ∘
        // unrealizable_at` is the identity on the in-range prefix —
        // the symmetric dual of `realizable_ordinal ∘ realizable_at`
        // being the identity on `0..realizable_count::<C>()`.
        for i in 0..unrealizable_count::<C>() {
            let recovered = unrealizable_at::<C>(i).and_then(unrealizable_ordinal::<C>);
            assert_eq!(
                recovered,
                Some(i),
                "unrealizable_at({i}).and_then(unrealizable_ordinal) must equal Some({i})",
            );
        }
    }

    fn assert_unrealizable_at_image_is_unrealizable<C>()
    where
        C: ProductCube + std::fmt::Debug,
    {
        // For every in-range ordinal `i`, the dense lookup lands on an
        // unrealizable cell: `unrealizable_at(i).map(is_realizable) ==
        // Some(false)`. Pins that the forward map's image is the
        // unrealizable complement, not the full cube `ALL`. The
        // Boolean dual of `realizable_at_image_is_realizable` — stated
        // separately from the partiality invariant so a future helper
        // change that accidentally exposes realizable cells in the
        // in-range prefix would fail here as well as in the round-trip
        // law.
        for i in 0..unrealizable_count::<C>() {
            let cell = unrealizable_at::<C>(i)
                .expect("in-range unrealizable_at must yield Some by partiality invariant");
            assert!(
                !ProductCube::is_realizable(cell),
                "unrealizable_at({i}) = {cell:?} must NOT satisfy is_realizable",
            );
        }
    }

    fn assert_unrealizable_ordinal_image_equals_unrealizable_prefix<C>()
    where
        C: ProductCube + std::fmt::Debug,
    {
        // The ordinal image over the unrealizable complement equals
        // `0..unrealizable_count::<C>()` as a set. Equivalent to the
        // injectivity statement: distinct unrealizable cells land at
        // distinct ordinals, and the dense embedding is a bijection
        // (not merely an injection) onto the prefix. Pins that
        // `unrealizable_iter::<C>()` carries no duplicates — the cube-
        // level dual of the no-duplicates invariant on `A::ALL` and
        // the symmetric dual of `realizable_ordinal_image_equals_realizable_prefix`
        // on the opposite face.
        use std::collections::HashSet;
        let ordinals: HashSet<usize> = unrealizable_iter::<C>()
            .map(|c| {
                unrealizable_ordinal::<C>(c)
                    .expect("unrealizable_iter must yield only ordinal-Some cells")
            })
            .collect();
        let expected: HashSet<usize> = (0..unrealizable_count::<C>()).collect();
        assert_eq!(
            ordinals, expected,
            "unrealizable_ordinal image over unrealizable_iter must equal 0..unrealizable_count as a set",
        );
    }

    #[test]
    fn unrealizable_ordinal_some_iff_not_is_realizable() {
        macro_rules! check {
            ($ty:ident) => {
                assert_unrealizable_ordinal_some_iff_not_is_realizable::<$ty>();
            };
        }
        for_each_product_cube!(check);
    }

    #[test]
    fn unrealizable_at_some_iff_in_unrealizable_prefix() {
        macro_rules! check {
            ($ty:ident) => {
                assert_unrealizable_at_some_iff_in_unrealizable_prefix::<$ty>();
            };
        }
        for_each_product_cube!(check);
    }

    #[test]
    fn unrealizable_round_trips_cell_side() {
        macro_rules! check {
            ($ty:ident) => {
                assert_unrealizable_round_trips_cell_side::<$ty>();
            };
        }
        for_each_product_cube!(check);
    }

    #[test]
    fn unrealizable_round_trips_ordinal_side() {
        macro_rules! check {
            ($ty:ident) => {
                assert_unrealizable_round_trips_ordinal_side::<$ty>();
            };
        }
        for_each_product_cube!(check);
    }

    #[test]
    fn unrealizable_at_image_is_unrealizable() {
        macro_rules! check {
            ($ty:ident) => {
                assert_unrealizable_at_image_is_unrealizable::<$ty>();
            };
        }
        for_each_product_cube!(check);
    }

    #[test]
    fn unrealizable_ordinal_image_equals_unrealizable_prefix() {
        macro_rules! check {
            ($ty:ident) => {
                assert_unrealizable_ordinal_image_equals_unrealizable_prefix::<$ty>();
            };
        }
        for_each_product_cube!(check);
    }

    #[test]
    fn realizable_and_unrealizable_ordinals_partition_cube() {
        // The two dense-ordinal pairs (realizable_ordinal, realizable_at)
        // and (unrealizable_ordinal, unrealizable_at) close the cube's
        // surface algebra symmetrically: every full-cube cell has
        // exactly one defined dense ordinal — `realizable_ordinal` is
        // Some on the realizable surface and None on the unrealizable
        // complement, while `unrealizable_ordinal` is None on the
        // realizable surface and Some on the unrealizable complement.
        // The two `Option<usize>` values are XOR-complementary on every
        // cell of every cube. Pins the symmetric-partition discipline
        // at the per-cell level — a future helper change that flipped
        // either ordinal's partiality or that double-counted any cell
        // would fail here as well as in the per-half tests.
        fn assert_xor_complementary<C>()
        where
            C: ProductCube + std::fmt::Debug,
        {
            for cell in axis_iter::<C>() {
                let r = realizable_ordinal::<C>(cell).is_some();
                let u = unrealizable_ordinal::<C>(cell).is_some();
                assert!(
                    r ^ u,
                    "cell {cell:?}: exactly one of realizable_ordinal / unrealizable_ordinal \
                     must be Some (got realizable={r}, unrealizable={u})",
                );
            }
        }
        macro_rules! check {
            ($ty:ident) => {
                assert_xor_complementary::<$ty>();
            };
        }
        for_each_product_cube!(check);
    }

    #[test]
    fn unrealizable_ordinal_pins_format_coordinates_dense_ordinals() {
        // FormatCoordinates::ALL lays the 8 cells in lex order over
        // (format × provenance); the 4 unrealizable cells sit at
        // full-cube indices 1, 3, 4, 6 (the ones where
        // `provenance != format.provenance()`).
        // axis_ordinal returns those positions in the full-cube slice;
        // unrealizable_ordinal returns the dense positions 0, 1, 2, 3
        // in unrealizable_iter, skipping the interleaved realizable
        // cells. Symmetric concrete-position pin to the realizable
        // counterpart above — caught at the per-position level if a
        // future re-ordering of `FormatCoordinates::ALL` or change to
        // `is_realizable` shifts the unrealizable interleaving.
        use crate::{FormatCoordinates, FormatProvenance};
        let yaml_shikumi = FormatCoordinates {
            format: Format::Yaml,
            provenance: FormatProvenance::ShikumiBuilt,
        };
        let toml_shikumi = FormatCoordinates {
            format: Format::Toml,
            provenance: FormatProvenance::ShikumiBuilt,
        };
        let lisp_figment = FormatCoordinates {
            format: Format::Lisp,
            provenance: FormatProvenance::FigmentBuiltin,
        };
        let nix_figment = FormatCoordinates {
            format: Format::Nix,
            provenance: FormatProvenance::FigmentBuiltin,
        };
        assert_eq!(
            unrealizable_ordinal::<FormatCoordinates>(yaml_shikumi),
            Some(0),
        );
        assert_eq!(
            unrealizable_ordinal::<FormatCoordinates>(toml_shikumi),
            Some(1),
        );
        assert_eq!(
            unrealizable_ordinal::<FormatCoordinates>(lisp_figment),
            Some(2),
        );
        assert_eq!(
            unrealizable_ordinal::<FormatCoordinates>(nix_figment),
            Some(3),
        );
        // axis_ordinal pins the full-cube positions on the same cells;
        // the gap (1,3,4,6) versus the dense unrealizable ordinals
        // (0,1,2,3) is exactly the interleaving the dense embedding
        // collapses on the opposite face.
        assert_eq!(axis_ordinal::<FormatCoordinates>(yaml_shikumi), 1);
        assert_eq!(axis_ordinal::<FormatCoordinates>(toml_shikumi), 3);
        assert_eq!(axis_ordinal::<FormatCoordinates>(lisp_figment), 4);
        assert_eq!(axis_ordinal::<FormatCoordinates>(nix_figment), 6);
        // Realizable cells return None on the unrealizable ordinal —
        // pinned for one mid-cube realizable cell as the symmetric
        // dual of the realizable-side partiality witness.
        let yaml_figment = FormatCoordinates {
            format: Format::Yaml,
            provenance: FormatProvenance::FigmentBuiltin,
        };
        assert_eq!(
            unrealizable_ordinal::<FormatCoordinates>(yaml_figment),
            None,
        );
    }

    // ---- PartitionOrdinal fuses (realizable_ordinal, unrealizable_ordinal)
    // ---- into a single typed witness over the cube's full surface ----
    //
    // The pair (partition_ordinal, at_partition_ordinal) is the typed-
    // disjoint-union counterpart to (axis_ordinal, axis_at): where the
    // axis-level pair carries one dense `usize` over the full cube
    // `ALL` slice (interleaving realizable and unrealizable cells),
    // PartitionOrdinal carries a typed variant tag plus the dense
    // ordinal restricted to the variant's face. Every cell of every
    // cube has a defined PartitionOrdinal (totality), the variant
    // agrees with is_realizable pointwise (variant agreement), and
    // the inner usize equals the corresponding dense-half ordinal
    // pointwise (inner agreement). Four trait-uniform invariants reach
    // every implementor pointwise:
    //
    //   (a) variant agreement — `partition_ordinal(cell)` is
    //       Realizable(_) iff is_realizable(cell);
    //   (b) inner-ordinal agreement — the inner usize on each variant
    //       equals the corresponding realizable_/unrealizable_ordinal
    //       pointwise;
    //   (c) round-trip from the cell side —
    //       at_partition_ordinal(partition_ordinal(cell)) == Some(cell)
    //       for every cell of the cube;
    //   (d) round-trip from the partition-ordinal side —
    //       at_partition_ordinal(p).map(partition_ordinal) == Some(p)
    //       for every in-range p (Realizable(i) with i < realizable_count
    //       or Unrealizable(i) with i < unrealizable_count), plus the
    //       partiality boundary (out-of-range p returns None on the
    //       forward map).
    //
    // A fifth product cube landing picks up all four invariants by
    // adding one line to each helper-bundle test through the
    // `for_each_product_cube!` macro.

    fn assert_partition_ordinal_variant_agrees_with_is_realizable<C>()
    where
        C: ProductCube + std::fmt::Debug,
    {
        // For every cell, the PartitionOrdinal variant agrees with the
        // realizability predicate: Realizable iff is_realizable, dually
        // Unrealizable iff !is_realizable. Pins the typed-partition
        // discipline: the variant tag and the predicate are in lockstep
        // pointwise, no cell can be tagged with the wrong face.
        for cell in axis_iter::<C>() {
            match partition_ordinal::<C>(cell) {
                PartitionOrdinal::Realizable(_) => assert!(
                    ProductCube::is_realizable(cell),
                    "cell {cell:?}: partition_ordinal returned Realizable but is_realizable is false",
                ),
                PartitionOrdinal::Unrealizable(_) => assert!(
                    !ProductCube::is_realizable(cell),
                    "cell {cell:?}: partition_ordinal returned Unrealizable but is_realizable is true",
                ),
            }
        }
    }

    fn assert_partition_ordinal_inner_matches_dense_ordinal<C>()
    where
        C: ProductCube + std::fmt::Debug,
    {
        // For every cell, the inner usize on each PartitionOrdinal
        // variant equals the corresponding dense-half ordinal pointwise.
        // Pins that the fused helper produces the same number the
        // dense-half helpers do — no silent off-by-one or face-swap
        // between the constituent ordinals and the merged encoding.
        for cell in axis_iter::<C>() {
            match partition_ordinal::<C>(cell) {
                PartitionOrdinal::Realizable(i) => assert_eq!(
                    Some(i),
                    realizable_ordinal::<C>(cell),
                    "cell {cell:?}: PartitionOrdinal::Realizable({i}) must equal realizable_ordinal",
                ),
                PartitionOrdinal::Unrealizable(i) => assert_eq!(
                    Some(i),
                    unrealizable_ordinal::<C>(cell),
                    "cell {cell:?}: PartitionOrdinal::Unrealizable({i}) must equal unrealizable_ordinal",
                ),
            }
        }
    }

    fn assert_partition_ordinal_round_trips_cell_side<C>()
    where
        C: ProductCube + std::fmt::Debug,
    {
        // For every cell of the cube, partition_ordinal-then-
        // at_partition_ordinal recovers the cell. The composition
        // `at_partition_ordinal ∘ partition_ordinal` is the identity on
        // `C::ALL` — the typed-disjoint-union analog of `axis_at ∘
        // axis_ordinal` being the identity on A. Reaches every cell of
        // every cube (not just the realizable surface or the
        // unrealizable complement separately, but the full cube
        // uniformly), so a fifth cube landing inherits totality with
        // one line in `for_each_product_cube!`.
        for cell in axis_iter::<C>() {
            let p = partition_ordinal::<C>(cell);
            assert_eq!(
                at_partition_ordinal::<C>(p),
                Some(cell),
                "cell {cell:?}: at_partition_ordinal(partition_ordinal(cell)) must equal Some(cell)",
            );
        }
    }

    fn assert_partition_ordinal_round_trips_ordinal_side<C>()
    where
        C: ProductCube + std::fmt::Debug,
    {
        // For every in-range PartitionOrdinal, at_partition_ordinal-
        // then-partition_ordinal recovers the partition ordinal. The
        // composition `partition_ordinal ∘ at_partition_ordinal` is the
        // identity on the in-range domain — covering Realizable(i) with
        // i < realizable_count AND Unrealizable(i) with i <
        // unrealizable_count, exercising both faces of the bijection at
        // one site. Out-of-range partition ordinals are checked
        // separately in the partiality test.
        for i in 0..realizable_count::<C>() {
            let p = PartitionOrdinal::Realizable(i);
            let recovered = at_partition_ordinal::<C>(p).map(partition_ordinal::<C>);
            assert_eq!(
                recovered,
                Some(p),
                "at_partition_ordinal(Realizable({i})).map(partition_ordinal) must equal Some(Realizable({i}))",
            );
        }
        for i in 0..unrealizable_count::<C>() {
            let p = PartitionOrdinal::Unrealizable(i);
            let recovered = at_partition_ordinal::<C>(p).map(partition_ordinal::<C>);
            assert_eq!(
                recovered,
                Some(p),
                "at_partition_ordinal(Unrealizable({i})).map(partition_ordinal) must equal Some(Unrealizable({i}))",
            );
        }
    }

    fn assert_at_partition_ordinal_none_on_out_of_range<C>()
    where
        C: ProductCube + std::fmt::Debug,
    {
        // For every out-of-range PartitionOrdinal (Realizable(i) with
        // i >= realizable_count, or Unrealizable(i) with i >=
        // unrealizable_count), the forward map returns None. The
        // boundary check exercises the immediate boundary (n, n+1), a
        // comfortable margin (n+7), and the `usize::MAX` extreme to
        // catch any silent saturation on either face. Pins that the
        // forward map is defined precisely on each variant's restricted
        // prefix and the Option return surfaces the partiality at the
        // type level rather than by convention.
        let nr = realizable_count::<C>();
        for i in [nr, nr + 1, nr + 7, usize::MAX] {
            assert!(
                at_partition_ordinal::<C>(PartitionOrdinal::Realizable(i)).is_none(),
                "at_partition_ordinal(Realizable({i})) must be None for ordinal >= realizable_count (n = {nr})",
            );
        }
        let nu = unrealizable_count::<C>();
        for i in [nu, nu + 1, nu + 7, usize::MAX] {
            assert!(
                at_partition_ordinal::<C>(PartitionOrdinal::Unrealizable(i)).is_none(),
                "at_partition_ordinal(Unrealizable({i})) must be None for ordinal >= unrealizable_count (n = {nu})",
            );
        }
    }

    fn assert_at_partition_ordinal_image_matches_variant_tag<C>()
    where
        C: ProductCube + std::fmt::Debug,
    {
        // For every in-range PartitionOrdinal, the cell the forward map
        // lands on has realizability matching the variant tag:
        // Realizable(i) lands on an is_realizable=true cell;
        // Unrealizable(i) lands on an is_realizable=false cell. Pins
        // that the variant tag and the cell's realizability are in
        // lockstep — the typed-partition encoding cannot smuggle an
        // unrealizable cell behind a Realizable tag, nor vice versa.
        for i in 0..realizable_count::<C>() {
            let cell = at_partition_ordinal::<C>(PartitionOrdinal::Realizable(i))
                .expect("in-range Realizable(i) must yield Some by partiality invariant");
            assert!(
                ProductCube::is_realizable(cell),
                "at_partition_ordinal(Realizable({i})) = {cell:?} must satisfy is_realizable",
            );
        }
        for i in 0..unrealizable_count::<C>() {
            let cell = at_partition_ordinal::<C>(PartitionOrdinal::Unrealizable(i))
                .expect("in-range Unrealizable(i) must yield Some by partiality invariant");
            assert!(
                !ProductCube::is_realizable(cell),
                "at_partition_ordinal(Unrealizable({i})) = {cell:?} must NOT satisfy is_realizable",
            );
        }
    }

    #[test]
    fn partition_ordinal_variant_agrees_with_is_realizable() {
        macro_rules! check {
            ($ty:ident) => {
                assert_partition_ordinal_variant_agrees_with_is_realizable::<$ty>();
            };
        }
        for_each_product_cube!(check);
    }

    #[test]
    fn partition_ordinal_inner_matches_dense_ordinal() {
        macro_rules! check {
            ($ty:ident) => {
                assert_partition_ordinal_inner_matches_dense_ordinal::<$ty>();
            };
        }
        for_each_product_cube!(check);
    }

    #[test]
    fn partition_ordinal_round_trips_cell_side() {
        macro_rules! check {
            ($ty:ident) => {
                assert_partition_ordinal_round_trips_cell_side::<$ty>();
            };
        }
        for_each_product_cube!(check);
    }

    #[test]
    fn partition_ordinal_round_trips_ordinal_side() {
        macro_rules! check {
            ($ty:ident) => {
                assert_partition_ordinal_round_trips_ordinal_side::<$ty>();
            };
        }
        for_each_product_cube!(check);
    }

    #[test]
    fn at_partition_ordinal_none_on_out_of_range() {
        macro_rules! check {
            ($ty:ident) => {
                assert_at_partition_ordinal_none_on_out_of_range::<$ty>();
            };
        }
        for_each_product_cube!(check);
    }

    #[test]
    fn at_partition_ordinal_image_matches_variant_tag() {
        macro_rules! check {
            ($ty:ident) => {
                assert_at_partition_ordinal_image_matches_variant_tag::<$ty>();
            };
        }
        for_each_product_cube!(check);
    }

    #[test]
    fn partition_ordinal_pins_format_coordinates_dense_ordinals() {
        // Concrete-position pin on FormatCoordinates: the 8 cells of
        // ALL split into 4 realizable (at full-cube ordinals 0, 2, 5,
        // 7; dense realizable ordinals 0, 1, 2, 3) and 4 unrealizable
        // (at full-cube ordinals 1, 3, 4, 6; dense unrealizable
        // ordinals 0, 1, 2, 3). The PartitionOrdinal encoding pins
        // each cell's variant tag and dense ordinal in one helper —
        // the symmetric concrete-position pin to the realizable and
        // unrealizable counterparts above, but on the merged typed-
        // disjoint-union encoding rather than the per-face Option<usize>
        // halves.
        use crate::{FormatCoordinates, FormatProvenance};
        let yaml_figment = FormatCoordinates {
            format: Format::Yaml,
            provenance: FormatProvenance::FigmentBuiltin,
        };
        let yaml_shikumi = FormatCoordinates {
            format: Format::Yaml,
            provenance: FormatProvenance::ShikumiBuilt,
        };
        let nix_shikumi = FormatCoordinates {
            format: Format::Nix,
            provenance: FormatProvenance::ShikumiBuilt,
        };
        let nix_figment = FormatCoordinates {
            format: Format::Nix,
            provenance: FormatProvenance::FigmentBuiltin,
        };
        // Realizable side — variant tag matches is_realizable.
        assert_eq!(
            partition_ordinal::<FormatCoordinates>(yaml_figment),
            PartitionOrdinal::Realizable(0),
        );
        assert_eq!(
            partition_ordinal::<FormatCoordinates>(nix_shikumi),
            PartitionOrdinal::Realizable(3),
        );
        // Unrealizable side — variant tag matches !is_realizable.
        assert_eq!(
            partition_ordinal::<FormatCoordinates>(yaml_shikumi),
            PartitionOrdinal::Unrealizable(0),
        );
        assert_eq!(
            partition_ordinal::<FormatCoordinates>(nix_figment),
            PartitionOrdinal::Unrealizable(3),
        );
        // Round-trip witness on one cell from each face.
        assert_eq!(
            at_partition_ordinal::<FormatCoordinates>(PartitionOrdinal::Realizable(0)),
            Some(yaml_figment),
        );
        assert_eq!(
            at_partition_ordinal::<FormatCoordinates>(PartitionOrdinal::Unrealizable(3)),
            Some(nix_figment),
        );
    }

    #[test]
    fn partition_ordinal_ord_matches_face_then_face_ordinal() {
        // The derived Ord on PartitionOrdinal is lexicographic on
        // (face, face_ordinal): Rust compares the variant tag first (so
        // every Realizable(_) is strictly less than every Unrealizable(_)
        // regardless of inner ordinal) and falls through to the inner
        // usize on matching variants. Three legs pin this:
        //
        //   (a) Within-face monotonicity — Realizable(i) < Realizable(j)
        //       iff i < j; dually for Unrealizable. Each face's dense
        //       prefix sorts ascending under the derived Ord.
        //   (b) Cross-face dominance — every Realizable(_) lands strictly
        //       less than every Unrealizable(_), regardless of how the
        //       inner ordinals compare. The Realizable-then-Unrealizable
        //       block layout the rest of the cube surfaces emit through
        //       `realizable_iter().chain(unrealizable_iter())` matches the
        //       Ord block layout pointwise.
        //   (c) Lexicographic agreement with the (face, face_ordinal)
        //       projection — `a.cmp(&b) ==
        //       a.face().cmp(&b.face()).then(a.face_ordinal().cmp(
        //       &b.face_ordinal()))` over a representative sample
        //       crossing both faces. Pins the closed-form reading of the
        //       derive: PartitionOrdinal::Ord IS the lexicographic order
        //       on (PartitionFace::Ord, usize::Ord), no hidden tiebreak.
        //
        // A silent variant reorder on PartitionOrdinal (which would
        // invert the cross-face dominance and break every BTreeMap<
        // PartitionOrdinal, T> rollup's emission order downstream)
        // fails leg (b) first. A future addition of a hidden tiebreak
        // field on either variant (which would break the lexicographic
        // reading and surprise consumers reading the derive as
        // (face, face_ordinal) lex) fails leg (c) first. Idiom-peer of
        // `partition_face_ord_matches_declaration_order` on the
        // variant-tag projection and the four
        // `*_class_ord_matches_all_declaration_order` pins on the
        // typed-cube classifiers.
        use std::cmp::Ordering;
        let sample = [
            PartitionOrdinal::Realizable(0),
            PartitionOrdinal::Realizable(1),
            PartitionOrdinal::Realizable(usize::MAX),
            PartitionOrdinal::Unrealizable(0),
            PartitionOrdinal::Unrealizable(1),
            PartitionOrdinal::Unrealizable(usize::MAX),
        ];

        // Leg (a) — within-face monotonicity on each face.
        assert!(PartitionOrdinal::Realizable(0) < PartitionOrdinal::Realizable(1));
        assert!(PartitionOrdinal::Realizable(1) < PartitionOrdinal::Realizable(usize::MAX));
        assert!(PartitionOrdinal::Unrealizable(0) < PartitionOrdinal::Unrealizable(1));
        assert!(PartitionOrdinal::Unrealizable(1) < PartitionOrdinal::Unrealizable(usize::MAX));

        // Leg (b) — cross-face dominance, including the adversarial
        // case where the Realizable side carries the largest possible
        // inner ordinal and the Unrealizable side carries the smallest.
        // The variant tag dominates the inner ordinal pointwise.
        assert!(PartitionOrdinal::Realizable(usize::MAX) < PartitionOrdinal::Unrealizable(0));
        assert!(PartitionOrdinal::Realizable(0) < PartitionOrdinal::Unrealizable(0));
        assert!(PartitionOrdinal::Realizable(0) < PartitionOrdinal::Unrealizable(usize::MAX));

        // Leg (c) — lexicographic agreement with `(face, face_ordinal)`
        // over every ordered pair in the sample. Covers the within-face
        // Equal/Less/Greater and the cross-face Less/Greater modes at
        // one site.
        for a in sample {
            for b in sample {
                let lex = a
                    .face()
                    .cmp(&b.face())
                    .then(a.face_ordinal().cmp(&b.face_ordinal()));
                assert_eq!(
                    a.cmp(&b),
                    lex,
                    "PartitionOrdinal Ord must equal (face, face_ordinal) lex: \
                     {a:?} vs {b:?} got {:?} expected {lex:?}",
                    a.cmp(&b),
                );
                // Reflexivity sanity check on the diagonal.
                if a == b {
                    assert_eq!(a.cmp(&b), Ordering::Equal);
                }
            }
        }

        // Block-layout cross-check — sorting the sample under the
        // derived Ord yields the canonical realizable-block-then-
        // unrealizable-block sequence, each block in dense-ordinal
        // order. Closes the BTreeMap<PartitionOrdinal, _> emission-
        // order story the rustdoc on PartitionOrdinal states.
        let mut sorted = sample;
        sorted.sort();
        assert_eq!(sorted, sample);
    }

    // ---- PartitionFace algebra and PartitionOrdinal projections ----
    //
    // `PartitionFace` is the tenth closed-axis primitive — the
    // variant-tag projection of `PartitionOrdinal`. Three invariants
    // pin its algebra:
    //
    //   (a) `PartitionFace::ALL = [Realizable, Unrealizable]` (two
    //       entries, in declaration order; mirrored by the trait `ALL`
    //       via the `partition_face_trait_all_matches_inherent_all`
    //       test above);
    //   (b) `PartitionFace::is_realizable` matches the variant pointwise
    //       on the two-element axis;
    //   (c) trait-uniform over every cube: for every cell,
    //       `partition_ordinal::<C>(cell).face().is_realizable() ==
    //       ProductCube::is_realizable(cell)`. The face tag and the
    //       cube predicate are in lockstep on every cell of every
    //       cube — pinned by the helper through `for_each_product_cube!`.
    //
    // `PartitionOrdinal::face_ordinal` is the dual projection: forgets
    // the face tag, recovers the inner dense ordinal. A round-trip
    // invariant — `PartitionOrdinal::Realizable(i).face_ordinal() == i`
    // and dually for `Unrealizable` — is pinned by the synthetic
    // round-trip helper across every in-range dense ordinal on every
    // face of every cube via `for_each_product_cube!`.

    #[test]
    fn partition_face_all_has_two_entries() {
        // Pin the typescape's tenth axis primitive's cardinality at
        // two: Realizable + Unrealizable, in declaration order. A
        // third face landing (which is not anticipated — the
        // partition is XOR-complementary by construction) would
        // require extending `PartitionOrdinal` with a matching variant
        // and `ProductCube::is_realizable` from `bool` to a ternary
        // predicate, both of which are structural changes that fail
        // this assertion first.
        assert_eq!(PartitionFace::ALL.len(), 2);
        assert_eq!(PartitionFace::ALL[0], PartitionFace::Realizable);
        assert_eq!(PartitionFace::ALL[1], PartitionFace::Unrealizable);
    }

    #[test]
    fn partition_face_is_realizable_matches_variant() {
        // `PartitionFace::is_realizable` returns `true` exactly on
        // `Realizable`. The face-level predicate decouples "which half"
        // from "which cube" — a consumer that carries a face tag
        // without the cube type parameter classifies it through this
        // method without re-pattern-matching.
        assert!(PartitionFace::Realizable.is_realizable());
        assert!(!PartitionFace::Unrealizable.is_realizable());
    }

    fn assert_partition_ordinal_face_agrees_with_is_realizable<C>()
    where
        C: ProductCube + std::fmt::Debug,
    {
        // The face tag projected from `partition_ordinal(cell)` is in
        // lockstep with `ProductCube::is_realizable(cell)` on every
        // cell of every cube. The cube predicate, the variant tag, and
        // `PartitionFace::is_realizable` are three readings of the same
        // bit — pinned pointwise here through one trait-uniform
        // helper.
        for cell in <C as ClosedAxis>::ALL.iter().copied() {
            let face = partition_ordinal::<C>(cell).face();
            assert_eq!(
                face.is_realizable(),
                ProductCube::is_realizable(cell),
                "cell {cell:?}: partition_ordinal(cell).face().is_realizable() must equal \
                 ProductCube::is_realizable(cell)",
            );
            // Face tag and variant agree at the construction level:
            // realizable cells produce a `Realizable` tag, unrealizable
            // cells produce an `Unrealizable` tag.
            let expected = if ProductCube::is_realizable(cell) {
                PartitionFace::Realizable
            } else {
                PartitionFace::Unrealizable
            };
            assert_eq!(
                face, expected,
                "cell {cell:?}: face tag must match is_realizable-derived expected face",
            );
        }
    }

    #[test]
    fn partition_ordinal_face_agrees_with_is_realizable() {
        macro_rules! check {
            ($ty:ident) => {
                assert_partition_ordinal_face_agrees_with_is_realizable::<$ty>();
            };
        }
        for_each_product_cube!(check);
    }

    fn assert_partition_ordinal_face_ordinal_round_trips<C>()
    where
        C: ProductCube + std::fmt::Debug,
    {
        // Round-trip on the dense-ordinal projection: for every
        // in-range dense ordinal on each face, the synthetic
        // `PartitionOrdinal` recovers the same dense ordinal through
        // `face_ordinal`. The face-tag projection forgets the inner
        // ordinal; the face-ordinal projection forgets the face tag;
        // together they are the two halves of the typed disjoint-union
        // encoding.
        for i in 0..realizable_count::<C>() {
            let p = PartitionOrdinal::Realizable(i);
            assert_eq!(
                p.face(),
                PartitionFace::Realizable,
                "Realizable({i}): face must be Realizable",
            );
            assert_eq!(
                p.face_ordinal(),
                i,
                "Realizable({i}): face_ordinal must be {i}"
            );
        }
        for i in 0..unrealizable_count::<C>() {
            let p = PartitionOrdinal::Unrealizable(i);
            assert_eq!(
                p.face(),
                PartitionFace::Unrealizable,
                "Unrealizable({i}): face must be Unrealizable",
            );
            assert_eq!(
                p.face_ordinal(),
                i,
                "Unrealizable({i}): face_ordinal must be {i}",
            );
        }
    }

    #[test]
    fn partition_ordinal_face_ordinal_round_trips_across_every_cube() {
        macro_rules! check {
            ($ty:ident) => {
                assert_partition_ordinal_face_ordinal_round_trips::<$ty>();
            };
        }
        for_each_product_cube!(check);
    }

    fn assert_partition_ordinal_recomposes_from_face_and_ordinal<C>()
    where
        C: ProductCube + std::fmt::Debug,
    {
        // For every cell of every cube, the typed-disjoint-union
        // encoding (`partition_ordinal(cell)`) is reconstructible from
        // its two projections (`face` and `face_ordinal`). The two
        // projections form a faithful encoding: no information loss
        // when the face tag and the dense inner ordinal are carried
        // separately, then recombined through the matching variant
        // constructor.
        for cell in <C as ClosedAxis>::ALL.iter().copied() {
            let p = partition_ordinal::<C>(cell);
            let face = p.face();
            let ordinal = p.face_ordinal();
            let recombined = match face {
                PartitionFace::Realizable => PartitionOrdinal::Realizable(ordinal),
                PartitionFace::Unrealizable => PartitionOrdinal::Unrealizable(ordinal),
            };
            assert_eq!(
                recombined, p,
                "cell {cell:?}: recombining (face, face_ordinal) must equal partition_ordinal(cell)",
            );
        }
    }

    #[test]
    fn partition_ordinal_recomposes_from_face_and_ordinal_across_every_cube() {
        macro_rules! check {
            ($ty:ident) => {
                assert_partition_ordinal_recomposes_from_face_and_ordinal::<$ty>();
            };
        }
        for_each_product_cube!(check);
    }

    // ---- PartialInverseCube forward/invert bijection invariants ----
    //
    // The (forward, invert) pair closes a bijection on the recognized
    // half of the cube. Three trait-uniform invariants reach every
    // implementor pointwise:
    //
    //   (a) forward always lands on a realizable cell;
    //   (b) invert(forward(image)) == Some(image) for every image
    //       (round-trip from the image side);
    //   (c) forward(invert(cell).unwrap()) == cell for every realizable
    //       cell (round-trip from the cube side).
    //
    // Equivalently, the forward image of `Image::ALL` under `forward`
    // equals `realizable_iter::<Self>()` as a set — pinned by
    // `forward_image_of_image_all_equals_realizable_iter`. A third
    // PartialInverseCube implementor picks up all three invariants by
    // adding one call to each helper at the trait-uniform site.

    fn assert_forward_always_lands_on_realizable<C>()
    where
        C: PartialInverseCube + std::fmt::Debug,
    {
        for image in <C::Image as ClosedAxis>::ALL.iter().copied() {
            let cell = C::forward(image);
            assert!(
                ProductCube::is_realizable(cell),
                "image {image:?}: forward must land on a realizable cell of the cube",
            );
        }
    }

    fn assert_round_trip_invert_after_forward<C>()
    where
        C: PartialInverseCube + std::fmt::Debug,
    {
        for image in <C::Image as ClosedAxis>::ALL.iter().copied() {
            let recovered = C::forward(image).invert();
            assert_eq!(
                recovered,
                Some(image),
                "image {image:?}: invert(forward(image)) must equal Some(image)",
            );
        }
    }

    fn assert_round_trip_forward_after_invert<C>()
    where
        C: PartialInverseCube + std::fmt::Debug,
    {
        for cell in realizable_iter::<C>() {
            let image = cell
                .invert()
                .expect("realizable_iter must yield only invert-Some cells");
            let recovered = C::forward(image);
            assert_eq!(
                recovered, cell,
                "cell {cell:?}: forward(invert(cell).unwrap()) must equal cell",
            );
        }
    }

    #[test]
    fn format_coordinates_forward_always_lands_on_realizable_cell() {
        assert_forward_always_lands_on_realizable::<FormatCoordinates>();
    }

    #[test]
    fn attribution_coordinates_forward_always_lands_on_realizable_cell() {
        assert_forward_always_lands_on_realizable::<AttributionCoordinates>();
    }

    #[test]
    fn format_coordinates_round_trip_invert_after_forward() {
        assert_round_trip_invert_after_forward::<FormatCoordinates>();
    }

    #[test]
    fn attribution_coordinates_round_trip_invert_after_forward() {
        assert_round_trip_invert_after_forward::<AttributionCoordinates>();
    }

    #[test]
    fn format_coordinates_round_trip_forward_after_invert() {
        assert_round_trip_forward_after_invert::<FormatCoordinates>();
    }

    #[test]
    fn attribution_coordinates_round_trip_forward_after_invert() {
        assert_round_trip_forward_after_invert::<AttributionCoordinates>();
    }

    #[test]
    fn forward_image_of_image_all_equals_realizable_iter() {
        // Pin that for any PartialInverseCube implementor, the forward
        // image of Image::ALL under `forward` equals `realizable_iter`
        // as a set. This is the trait-uniform statement of the
        // bijection on the recognized half: forward is total onto the
        // realizable cells, and invert is total onto the image. The
        // helper reaches both today's implementors at once; a third
        // implementor picks it up with one new call.
        fn assert_forward_image_equals_realizable<C>()
        where
            C: PartialInverseCube + std::fmt::Debug,
        {
            use std::collections::HashSet;
            let from_forward: HashSet<C> = forward_iter::<C>().collect();
            let from_realizable: HashSet<C> = realizable_iter::<C>().collect();
            assert_eq!(
                from_forward, from_realizable,
                "forward_iter must equal realizable_iter as a set",
            );
        }
        macro_rules! check {
            ($ty:ident) => {
                assert_forward_image_equals_realizable::<$ty>();
            };
        }
        for_each_partial_inverse_cube!(check);
    }

    #[test]
    fn forward_iter_cardinality_equals_image_all_cardinality() {
        // forward_iter::<C>() iterates Image::ALL once with no filter,
        // so its length equals the image axis cardinality. By the
        // bijection invariant, that also equals realizable_count::<C>().
        // Two readings of the same number pinned in lockstep across
        // every implementor.
        fn assert_cardinalities_agree<C: PartialInverseCube>() {
            assert_eq!(
                forward_iter::<C>().count(),
                axis_cardinality::<<C as PartialInverseCube>::Image>(),
            );
            assert_eq!(forward_iter::<C>().count(), realizable_count::<C>());
        }
        macro_rules! check {
            ($ty:ident) => {
                assert_cardinalities_agree::<$ty>();
            };
        }
        for_each_partial_inverse_cube!(check);
    }

    // ---- Implementor-list macro cardinalities ----
    //
    // The three implementor-list macros (`for_each_closed_axis_primitive`,
    // `for_each_product_cube`, `for_each_partial_inverse_cube`) are the
    // single source of truth for the trait-implementor sets in the
    // `for every implementor` tests. Pin today's cardinality on each
    // macro so a future axis primitive or product cube landing forces
    // the macro arm in lockstep — a `for_each_*` invocation that
    // doesn't include a newly-added implementor will fail the
    // cardinality check here, surfacing the discipline violation
    // before any silent dropouts at the trait-uniform test sites.

    #[test]
    fn for_each_closed_axis_primitive_macro_covers_twenty_axes() {
        // Pin that the macro expands to exactly twenty arms — the
        // nineteen pre-existing axis primitives plus
        // [`crate::DiffLineKind`], the `'static` closed three-way
        // classification over the [`crate::DiffLine`] variant space —
        // the removed/added/context peer of [`WatchEventClass`] on the
        // diff-cell axis of [`crate::ConfigDiff`]. A twenty-first axis
        // primitive landing extends the macro in lockstep with the
        // `impl ClosedAxis` declaration; this assertion fails until
        // the macro arm lands.
        let mut count = 0usize;
        macro_rules! tally {
            ($ty:ident) => {
                count += 1;
            };
        }
        for_each_closed_axis_primitive!(tally);
        assert_eq!(
            count, 20,
            "for_each_closed_axis_primitive! must expand to twenty arms",
        );
    }

    #[test]
    fn for_each_product_cube_macro_covers_five_cubes() {
        // Pin that the macro expands to exactly five arms — the five
        // product cubes the typescape recognizes today
        // ([`FormatCoordinates`], [`AttributionCoordinates`],
        // [`ErrorLocalizationCoordinates`],
        // [`AttributionSourceKindCoordinates`],
        // [`AttributionNameKindCoordinates`]). A sixth cube landing
        // extends the macro in lockstep with the `impl ProductCube`
        // declaration; this assertion fails until the macro arm lands.
        let mut count = 0usize;
        macro_rules! tally {
            ($ty:ident) => {
                count += 1;
            };
        }
        for_each_product_cube!(tally);
        assert_eq!(count, 5, "for_each_product_cube! must expand to five arms");
    }

    #[test]
    fn for_each_partial_inverse_cube_macro_covers_two_cubes() {
        // Pin that the macro expands to exactly two arms — the two
        // cubes whose forward map carries an inverse on the recognized
        // half. A third PartialInverseCube implementor landing extends
        // the macro in lockstep with the `impl PartialInverseCube`
        // declaration; this assertion fails until the macro arm lands.
        let mut count = 0usize;
        macro_rules! tally {
            ($ty:ident) => {
                count += 1;
            };
        }
        for_each_partial_inverse_cube!(tally);
        assert_eq!(
            count, 2,
            "for_each_partial_inverse_cube! must expand to two arms",
        );
    }

    #[test]
    fn for_each_closed_axis_implementor_macro_covers_twenty_five_types() {
        // Pin that the superset macro expands to exactly twenty-five
        // arms — the twenty axis primitives plus the five product
        // cubes. A twenty-first axis primitive OR a sixth cube landing
        // extends the composed macro in lockstep through one of its
        // two component macros; this assertion fails until the arm
        // lands.
        let mut count = 0usize;
        macro_rules! tally {
            ($ty:ident) => {
                count += 1;
            };
        }
        for_each_closed_axis_implementor!(tally);
        assert_eq!(
            count, 25,
            "for_each_closed_axis_implementor! must expand to twenty-five arms (20 axes + 5 cubes)",
        );
    }

    #[test]
    fn for_each_closed_axis_implementor_expands_to_distinct_closed_axis_types() {
        // Pin that every type the macro yields satisfies the trait
        // bound it advertises (ClosedAxis) and that the expansion
        // produces no duplicates. Distinctness is pinned via
        // axis_cardinality summed across the implementors — the sum
        // matches the today-pinned 79 only when the macro emits each
        // implementor exactly once. A duplicated arm would
        // double-count one cardinality; a missing arm would
        // under-count. The sum is a checksum over the macro's image.
        fn axis_card<A: ClosedAxis>() -> usize {
            axis_cardinality::<A>()
        }
        let mut total = 0usize;
        macro_rules! add {
            ($ty:ident) => {
                total += axis_card::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(add);
        // 20-axis sum: Format=4, FormatProvenance=2, ConfigSourceKind=3,
        // FigmentSourceKind=3, ShikumiErrorKind=6, FieldPathLocalization=3,
        // AttributionRule=5, AttributionConfidence=2, AttributionAxis=2,
        // PartitionFace=2, ConfigTierKind=4, WatchEventClass=3,
        // FigmentNameTagKind=2, EnvMetadataTagKind=2, SecretBackendKind=8,
        // SecretRefShape=2, SecretOperation=6, SecretErrorKind=5,
        // SecretClientKind=7, DiffLineKind=3 → 74.
        // 5-cube sum: FormatCoordinates=8, AttributionCoordinates=12,
        // ErrorLocalizationCoordinates=18, AttributionSourceKindCoordinates=9,
        // AttributionNameKindCoordinates=6 → 53. Grand total 74+53 = 127.
        assert_eq!(
            total, 127,
            "macro must emit each implementor exactly once \
             (today's axis_cardinality checksum is 127)",
        );
    }

    // ---- ClosedAxisLabel — trait-uniform invariants over every implementor ----
    //
    // The five invariants the labeling discipline pins (round-trip law,
    // case insensitivity, distinctness, non-emptiness, empty-string
    // rejection) each appear once below, with the per-implementor loop
    // dispatched through `for_each_closed_axis_label_implementor!`. A
    // third [`ClosedAxisLabel`] implementor landing extends every
    // invariant in lockstep by adding one arm to the macro — no
    // per-test edits required.

    fn assert_round_trips_through_canonical_str<L>()
    where
        L: ClosedAxisLabel + std::fmt::Debug,
    {
        // Round-trip law: `L::from_canonical_str(v.as_str()) == Some(v)`
        // for every `v: L`. The default `from_canonical_str` impl
        // satisfies this by construction over `ClosedAxis::ALL`;
        // implementors that override `from_canonical_str` are still
        // pinned here. Iterates `L::ALL` (every value of the axis) and
        // re-parses the rendered label, asserting the parse recovers
        // the original value pointwise.
        for value in L::ALL.iter().copied() {
            let rendered = value.as_str();
            let parsed = <L as ClosedAxisLabel>::from_canonical_str(rendered);
            assert_eq!(
                parsed,
                Some(value),
                "round-trip failed for {value:?}: as_str={rendered:?} did not parse back to Some({value:?})",
            );
        }
    }

    fn assert_round_trips_case_insensitively<L>()
    where
        L: ClosedAxisLabel + std::fmt::Debug,
    {
        // Case-insensitivity law: the rendered label uppercased parses
        // back to the same value. The default `from_canonical_str` uses
        // `eq_ignore_ascii_case`, so the law is structural on the
        // default impl; the pin re-states it once across every
        // implementor so override impls (none today) still satisfy it.
        for value in L::ALL.iter().copied() {
            let rendered_upper = value.as_str().to_ascii_uppercase();
            let parsed = <L as ClosedAxisLabel>::from_canonical_str(&rendered_upper);
            assert_eq!(
                parsed,
                Some(value),
                "case-insensitive round-trip failed for {value:?}: uppercase {rendered_upper:?} did not parse back",
            );
        }
    }

    fn assert_labels_pairwise_distinct<L>()
    where
        L: ClosedAxisLabel + std::fmt::Debug,
    {
        // Distinctness law: `a.as_str() != b.as_str()` for `a != b: L`.
        // Pinned via a quadratic walk over `L::ALL × L::ALL` —
        // cardinalities are tiny (≤6 today), so the quadratic cost is
        // negligible.
        let labels: Vec<(L, &'static str)> =
            L::ALL.iter().copied().map(|v| (v, v.as_str())).collect();
        for (i, (a, label_a)) in labels.iter().enumerate() {
            for (b, label_b) in labels.iter().skip(i + 1) {
                assert_ne!(
                    label_a, label_b,
                    "distinct values {a:?} and {b:?} must have distinct labels (both produced {label_a:?})",
                );
            }
        }
    }

    fn assert_labels_nonempty<L>()
    where
        L: ClosedAxisLabel + std::fmt::Debug,
    {
        // Non-emptiness law: `!v.as_str().is_empty()` for every `v: L`.
        // Composes with the empty-parse-rejection law: the empty
        // string can never collide with a canonical label.
        for value in L::ALL.iter().copied() {
            let rendered = value.as_str();
            assert!(
                !rendered.is_empty(),
                "as_str must never return empty for {value:?}",
            );
        }
    }

    fn assert_rejects_empty_string<L>()
    where
        L: ClosedAxisLabel + std::fmt::Debug,
    {
        // Empty-parse-rejection law: `L::from_canonical_str("") == None`
        // for every implementor. Composes with non-emptiness above:
        // because no canonical label is empty, the parse rejects "" by
        // construction. The pin holds the trait default impl honest
        // (and any override) at one site.
        assert_eq!(
            <L as ClosedAxisLabel>::from_canonical_str(""),
            None,
            "from_canonical_str(\"\") must be None",
        );
    }

    #[test]
    fn closed_axis_label_round_trips_for_every_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_round_trips_through_canonical_str::<$ty>();
            };
        }
        for_each_closed_axis_label_implementor!(check);
    }

    #[test]
    fn closed_axis_label_round_trips_case_insensitively_for_every_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_round_trips_case_insensitively::<$ty>();
            };
        }
        for_each_closed_axis_label_implementor!(check);
    }

    #[test]
    fn closed_axis_label_as_str_distinct_for_every_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_labels_pairwise_distinct::<$ty>();
            };
        }
        for_each_closed_axis_label_implementor!(check);
    }

    #[test]
    fn closed_axis_label_as_str_nonempty_for_every_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_labels_nonempty::<$ty>();
            };
        }
        for_each_closed_axis_label_implementor!(check);
    }

    #[test]
    fn closed_axis_label_rejects_empty_string_for_every_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_rejects_empty_string::<$ty>();
            };
        }
        for_each_closed_axis_label_implementor!(check);
    }

    #[test]
    fn for_each_closed_axis_label_implementor_macro_covers_twenty_implementors() {
        // Pin that the macro expands to exactly twenty arms — the
        // nineteen pre-existing [`ClosedAxisLabel`] implementors plus
        // [`crate::DiffLineKind`], the removed/added/context classification
        // over the [`crate::DiffLine`] variant space (labels
        // `"removed"` / `"added"` / `"context"`). A twenty-first
        // implementor landing extends the macro in lockstep with the
        // `impl ClosedAxisLabel` declaration; this assertion fails
        // until the macro arm lands.
        let mut count = 0usize;
        macro_rules! tally {
            ($ty:ident) => {
                count += 1;
            };
        }
        for_each_closed_axis_label_implementor!(tally);
        assert_eq!(
            count, 20,
            "for_each_closed_axis_label_implementor! must expand to twenty arms",
        );
    }

    #[test]
    fn for_each_closed_axis_label_implementor_expands_to_distinct_label_axes() {
        // Pin that every type the macro yields satisfies the trait
        // bound it advertises (ClosedAxisLabel) and that the expansion
        // produces no duplicates. Distinctness is pinned via the same
        // axis_cardinality checksum pattern used for the superset
        // ClosedAxis macro:
        // PartitionFace=2 + ConfigTierKind=4 + Format=4 + FormatProvenance=2
        // + ConfigSourceKind=3 + FigmentSourceKind=3 + AttributionConfidence=2
        // + AttributionAxis=2 + ShikumiErrorKind=6 + FieldPathLocalization=3
        // + AttributionRule=5 + WatchEventClass=3 = 39. A duplicated
        // arm would double-count one cardinality; a missing arm would
        // under-count.
        fn axis_card<L: ClosedAxisLabel>() -> usize {
            axis_cardinality::<L>()
        }
        let mut total = 0usize;
        macro_rules! add {
            ($ty:ident) => {
                total += axis_card::<$ty>();
            };
        }
        for_each_closed_axis_label_implementor!(add);
        assert_eq!(
            total, 74,
            "macro must emit each ClosedAxisLabel implementor exactly once \
             (today's axis_cardinality checksum is 74: \
             PartitionFace=2 + ConfigTierKind=4 + Format=4 + FormatProvenance=2 \
             + ConfigSourceKind=3 + FigmentSourceKind=3 + AttributionConfidence=2 \
             + AttributionAxis=2 + ShikumiErrorKind=6 + FieldPathLocalization=3 \
             + AttributionRule=5 + WatchEventClass=3 + FigmentNameTagKind=2 \
             + EnvMetadataTagKind=2 + SecretBackendKind=8 + SecretRefShape=2 \
             + SecretOperation=6 + SecretErrorKind=5 + SecretClientKind=7 \
             + DiffLineKind=3)",
        );
    }

    #[test]
    fn partition_face_as_str_yields_canonical_lowercase_names() {
        // Concrete-position pin on PartitionFace::as_str: the two
        // canonical labels at one site. The trait-uniform round-trip
        // test above pins the labels equal pairwise under
        // from_canonical_str, but this test pins the literal string
        // values themselves so a future rename (e.g. capitalizing
        // "Realizable") would fail here before drifting through the
        // round-trip law.
        assert_eq!(PartitionFace::Realizable.as_str(), "realizable");
        assert_eq!(PartitionFace::Unrealizable.as_str(), "unrealizable");
    }

    #[test]
    fn partition_face_display_matches_as_str_for_every_variant() {
        // Display delegates to as_str pointwise — closes the canonical
        // (Debug, Display) duality on the face-tag surface. Idiom-peer
        // of the same pin on the four typed-cube classifiers.
        for &v in PartitionFace::ALL {
            assert_eq!(
                format!("{v}"),
                v.as_str(),
                "Display must equal as_str for {v:?}",
            );
        }
    }

    #[test]
    fn partition_face_from_str_round_trips_through_display() {
        // Display / FromStr round-trip identity over every variant —
        // the canonical stdlib stable-string pair on the face axis.
        for &v in PartitionFace::ALL {
            let rendered = v.to_string();
            let parsed: PartitionFace = rendered.parse().unwrap();
            assert_eq!(parsed, v, "Display / FromStr round-trip for {v:?}");
        }
    }

    #[test]
    fn partition_face_from_str_is_case_insensitive() {
        // Uppercase canonical labels parse back to the same face via
        // the case-insensitive ClosedAxisLabel::from_canonical_str
        // route the FromStr impl delegates through.
        for &v in PartitionFace::ALL {
            let parsed: PartitionFace = v
                .as_str()
                .to_ascii_uppercase()
                .parse()
                .unwrap_or_else(|e| panic!("uppercase parse for {v:?} failed: {e}"));
            assert_eq!(parsed, v, "case-insensitive parse must recover {v:?}");
        }
    }

    #[test]
    fn partition_face_from_str_rejects_unknown_label_with_label_verbatim() {
        // Unknown labels surface verbatim through both
        // ParsePartitionFaceError::label and the typed Display impl —
        // the operator-facing error message names the offending input.
        let sentinel = "__shikumi_unknown_partition_face_sentinel__";
        match sentinel.parse::<PartitionFace>() {
            Err(e) => {
                assert_eq!(e.label, sentinel);
                let rendered = format!("{e}");
                assert!(
                    rendered.contains(sentinel),
                    "Display impl must carry the unknown sentinel verbatim, got: {rendered}",
                );
            }
            Ok(other) => panic!("unknown label must reject, got {other:?}"),
        }
    }

    #[test]
    fn partition_face_from_str_rejects_empty_string() {
        // The empty string is not a canonical face label.
        assert!("".parse::<PartitionFace>().is_err());
    }

    #[test]
    fn partition_face_serde_yaml_round_trips_over_every_variant() {
        // Serialize then deserialize on every variant — the typed face
        // tag survives the YAML scalar round-trip via the canonical
        // label, no consumer-side rename helper at the renderer.
        for &v in PartitionFace::ALL {
            let yaml = serde_yaml::to_string(&v).unwrap();
            let parsed: PartitionFace = serde_yaml::from_str(&yaml)
                .unwrap_or_else(|e| panic!("YAML round-trip for {v:?} failed: {e}"));
            assert_eq!(
                parsed, v,
                "serde YAML round-trip must be identity for {v:?}"
            );
        }
    }

    #[test]
    fn partition_face_serde_json_round_trips_over_every_variant() {
        // JSON emission is the quoted canonical label; the round-trip
        // is identity over every variant. Pins the natural projection
        // an observability payload reaches when carrying a PartitionFace
        // field through #[derive(Serialize, Deserialize)].
        for &v in PartitionFace::ALL {
            let json = serde_json::to_string(&v).unwrap();
            assert_eq!(
                json,
                format!("\"{}\"", v.as_str()),
                "JSON emission for {v:?} must be the quoted canonical label",
            );
            let parsed: PartitionFace = serde_json::from_str(&json).unwrap_or_else(|e| {
                panic!("JSON round-trip for {v:?} failed: {e}\n  json: {json}")
            });
            assert_eq!(
                parsed, v,
                "serde JSON round-trip must be identity for {v:?}"
            );
        }
    }

    #[test]
    fn partition_face_serde_yaml_is_case_insensitive() {
        // Uppercase YAML scalars parse back to the same face via the
        // case-insensitive deserialize path lowering through FromStr.
        for &v in PartitionFace::ALL {
            let upper = v.as_str().to_ascii_uppercase();
            let yaml = format!("\"{upper}\"\n");
            let parsed: PartitionFace = serde_yaml::from_str(&yaml).unwrap_or_else(|e| {
                panic!("uppercase YAML scalar for {v:?} must deserialize: {e}\n  yaml: {yaml:?}")
            });
            assert_eq!(parsed, v);
        }
    }

    #[test]
    fn partition_face_serde_yaml_unknown_label_error_carries_label_verbatim() {
        // The deserialize error surface carries the offending label
        // verbatim through the typed parse error's Display impl,
        // routed via serde::de::Error::custom.
        let sentinel = "__shikumi_unknown_partition_face_sentinel__";
        let yaml = format!("\"{sentinel}\"\n");
        let result: Result<PartitionFace, _> = serde_yaml::from_str(&yaml);
        match result {
            Err(e) => {
                let rendered = format!("{e}");
                assert!(
                    rendered.contains(sentinel),
                    "serde YAML error must carry the unknown sentinel verbatim, got: {rendered}",
                );
            }
            Ok(other) => panic!("YAML carrying unknown label must reject, got {other:?}"),
        }
    }

    #[test]
    fn partition_face_ord_matches_declaration_order() {
        // Realizable < Unrealizable under the derived Ord — the
        // declaration-order total order is monotone in the
        // PartitionFace::ALL position. A BTreeMap<PartitionFace, T>
        // keyed on the face axis emits rows in this order
        // deterministically; pinned here so a silent variant reorder
        // (which would invert the rollup order on every consumer) fails
        // this assertion first. Idiom-peer of the four
        // `*_class_ord_matches_all_declaration_order` pins on the
        // typed-cube classifiers.
        assert!(PartitionFace::Realizable < PartitionFace::Unrealizable);
        for window in PartitionFace::ALL.windows(2) {
            assert!(
                window[0] < window[1],
                "Ord must be strictly monotone in PartitionFace::ALL position: \
                 {:?} < {:?} failed",
                window[0],
                window[1],
            );
        }
    }

    // ---- PartitionOrdinal Display / FromStr / serde round-trips ----
    //
    // The typed disjoint-union encoding carries the canonical
    // `<face>:<face_ordinal>` scalar form on the wire. The tests below
    // pin the round-trip law at the (Display, FromStr) layer and at the
    // (Serialize, Deserialize) layer, plus the three rejection modes
    // (missing `:` separator, unknown face label, malformed ordinal)
    // carry the offending substring verbatim through the typed parse
    // error. Idiom-peer of the `partition_face_*` tests above on the
    // variant-tag projection — lifted onto the disjoint-union encoding
    // that pairs the face with the dense inner ordinal.

    fn partition_ordinal_sample() -> [PartitionOrdinal; 8] {
        // Representative coverage: both faces, the boundary ordinals
        // (`0` and `usize::MAX`), plus an interior pair pinning the
        // generic case the round-trip law must survive on every cell.
        [
            PartitionOrdinal::Realizable(0),
            PartitionOrdinal::Realizable(1),
            PartitionOrdinal::Realizable(42),
            PartitionOrdinal::Realizable(usize::MAX),
            PartitionOrdinal::Unrealizable(0),
            PartitionOrdinal::Unrealizable(1),
            PartitionOrdinal::Unrealizable(7),
            PartitionOrdinal::Unrealizable(usize::MAX),
        ]
    }

    #[test]
    fn partition_ordinal_display_renders_canonical_face_colon_ordinal() {
        // Concrete-position pin on Display: the canonical scalar form
        // is the face label from PartitionFace::as_str + `:` + the
        // dense inner ordinal rendered through usize::Display. A future
        // change of separator (e.g. to `/`) or face label rendering
        // would fail here before drifting through the round-trip law.
        assert_eq!(
            format!("{}", PartitionOrdinal::Realizable(0)),
            "realizable:0",
        );
        assert_eq!(
            format!("{}", PartitionOrdinal::Realizable(42)),
            "realizable:42",
        );
        assert_eq!(
            format!("{}", PartitionOrdinal::Unrealizable(0)),
            "unrealizable:0",
        );
        assert_eq!(
            format!("{}", PartitionOrdinal::Unrealizable(7)),
            "unrealizable:7",
        );
    }

    #[test]
    fn partition_ordinal_display_matches_face_and_face_ordinal_for_every_sample() {
        // Display recomposes from the two named projections —
        // `format!("{}:{}", v.face().as_str(), v.face_ordinal())` is
        // the canonical reading at one site. A future drift between
        // Display and the projections (e.g. Display caching the face
        // label separately and falling out of step on a rename) fails
        // this pin first.
        for v in partition_ordinal_sample() {
            assert_eq!(
                format!("{v}"),
                format!("{}:{}", v.face().as_str(), v.face_ordinal()),
                "Display must equal `<face>:<face_ordinal>` for {v:?}",
            );
        }
    }

    #[test]
    fn partition_ordinal_from_str_round_trips_through_display() {
        // Display / FromStr round-trip identity over the representative
        // sample covering both faces and the boundary ordinals. Closes
        // the canonical stdlib stable-string pair on the typed
        // partition-address surface.
        for v in partition_ordinal_sample() {
            let rendered = v.to_string();
            let parsed: PartitionOrdinal = rendered.parse().unwrap_or_else(|e| {
                panic!("FromStr round-trip for {v:?} failed: {e}\n  rendered: {rendered:?}")
            });
            assert_eq!(parsed, v, "Display / FromStr round-trip for {v:?}");
        }
    }

    #[test]
    fn partition_ordinal_from_str_face_half_is_case_insensitive() {
        // The face half of `<face>:<face_ordinal>` lowers through
        // `<PartitionFace as FromStr>::from_str`, which inherits the
        // case-insensitive ClosedAxisLabel::from_canonical_str route.
        // Uppercase / mixed-case face labels parse back to the same
        // address without a per-emitter case-fold.
        for v in partition_ordinal_sample() {
            let face_upper = v.face().as_str().to_ascii_uppercase();
            let upper = format!("{face_upper}:{}", v.face_ordinal());
            let parsed: PartitionOrdinal = upper
                .parse()
                .unwrap_or_else(|e| panic!("uppercase parse for {v:?} failed: {e}"));
            assert_eq!(
                parsed, v,
                "case-insensitive face half must recover {v:?} (from {upper:?})",
            );
        }
    }

    #[test]
    fn partition_ordinal_from_str_rejects_missing_separator() {
        // The `:` separator is mandatory: a scalar that omits it lifts
        // to ParsePartitionOrdinalError::MissingSeparator, carrying the
        // offending input verbatim through both the structured field
        // and the typed Display impl.
        let sentinel = "realizable42";
        match sentinel.parse::<PartitionOrdinal>() {
            Err(ParsePartitionOrdinalError::MissingSeparator { input }) => {
                assert_eq!(input, sentinel);
                let rendered = format!(
                    "{}",
                    ParsePartitionOrdinalError::MissingSeparator {
                        input: input.clone(),
                    },
                );
                assert!(
                    rendered.contains(sentinel),
                    "Display impl must carry the offending input verbatim, got: {rendered}",
                );
            }
            other => {
                panic!("missing-separator input must reject as MissingSeparator, got {other:?}")
            }
        }
    }

    #[test]
    fn partition_ordinal_from_str_rejects_unknown_face_with_label_verbatim() {
        // An unknown face half lifts to
        // ParsePartitionOrdinalError::UnknownFace through the
        // delegated `<PartitionFace as FromStr>::from_str`, carrying
        // the offending substring verbatim.
        let sentinel_face = "__shikumi_unknown_partition_face_sentinel__";
        let input = format!("{sentinel_face}:42");
        match input.parse::<PartitionOrdinal>() {
            Err(ParsePartitionOrdinalError::UnknownFace { label }) => {
                assert_eq!(label, sentinel_face);
                let rendered = format!(
                    "{}",
                    ParsePartitionOrdinalError::UnknownFace {
                        label: label.clone(),
                    },
                );
                assert!(
                    rendered.contains(sentinel_face),
                    "Display impl must carry the unknown face label verbatim, got: {rendered}",
                );
            }
            other => panic!("unknown face label must reject as UnknownFace, got {other:?}"),
        }
    }

    #[test]
    fn partition_ordinal_from_str_rejects_malformed_ordinal_with_substring_and_source() {
        // A malformed ordinal half lifts to
        // ParsePartitionOrdinalError::MalformedOrdinal, carrying the
        // offending substring verbatim AND threading the underlying
        // std::num::ParseIntError through Error::source so the
        // standard-library numeric diagnostic surfaces without
        // re-stringification.
        use std::error::Error as _;
        let sentinel_ord = "not_a_number";
        let input = format!("realizable:{sentinel_ord}");
        match input.parse::<PartitionOrdinal>() {
            Err(e @ ParsePartitionOrdinalError::MalformedOrdinal { .. }) => {
                if let ParsePartitionOrdinalError::MalformedOrdinal { ordinal, .. } = &e {
                    assert_eq!(ordinal, sentinel_ord);
                }
                let rendered = format!("{e}");
                assert!(
                    rendered.contains(sentinel_ord),
                    "Display impl must carry the malformed ordinal verbatim, got: {rendered}",
                );
                // Error::source threads the underlying ParseIntError
                // through, satisfying the std::error::Error chain at
                // consumer sites that walk `e.source()` for the root.
                assert!(
                    e.source().is_some(),
                    "MalformedOrdinal must thread ParseIntError through Error::source",
                );
            }
            other => panic!("malformed ordinal must reject as MalformedOrdinal, got {other:?}",),
        }
    }

    #[test]
    fn partition_ordinal_from_str_rejects_empty_string() {
        // The empty string has no `:` separator, so it lands on
        // MissingSeparator with the empty input verbatim.
        match "".parse::<PartitionOrdinal>() {
            Err(ParsePartitionOrdinalError::MissingSeparator { input }) => {
                assert_eq!(input, "");
            }
            other => panic!("empty string must reject as MissingSeparator, got {other:?}"),
        }
    }

    #[test]
    fn partition_ordinal_from_str_uses_leftmost_colon_only() {
        // The canonical face labels are pure lowercase ASCII letters
        // (no colon), so the leftmost `:` cleanly splits the face from
        // the ordinal. A second `:` (e.g. inside an ordinal-side
        // substring) is forwarded into the ordinal-parse path, which
        // rejects it as a malformed ordinal — not as a missing
        // separator. Pins `split_once(':')` semantics so a future
        // change to a stricter `split(':').exactly_two()` discipline
        // would surface here as a parse-mode shift.
        let input = "realizable:1:2";
        match input.parse::<PartitionOrdinal>() {
            Err(ParsePartitionOrdinalError::MalformedOrdinal { ordinal, .. }) => {
                assert_eq!(ordinal, "1:2");
            }
            other => panic!(
                "leftmost-`:`-only split must forward the rest into the ordinal half, got {other:?}",
            ),
        }
    }

    #[test]
    fn partition_ordinal_serde_yaml_round_trips_over_sample() {
        // Serialize then deserialize on the representative sample —
        // the typed partition address survives the YAML scalar
        // round-trip via the canonical `<face>:<face_ordinal>` form, no
        // consumer-side helper combining the two halves at the
        // renderer.
        for v in partition_ordinal_sample() {
            let yaml = serde_yaml::to_string(&v).unwrap();
            let parsed: PartitionOrdinal = serde_yaml::from_str(&yaml).unwrap_or_else(|e| {
                panic!("YAML round-trip for {v:?} failed: {e}\n  yaml: {yaml:?}")
            });
            assert_eq!(
                parsed, v,
                "serde YAML round-trip must be identity for {v:?}",
            );
        }
    }

    #[test]
    fn partition_ordinal_serde_json_round_trips_over_sample() {
        // JSON emission is the quoted canonical `<face>:<face_ordinal>`
        // scalar; the round-trip is identity over the sample. Pins
        // the natural projection an observability payload reaches when
        // carrying a PartitionOrdinal field through
        // #[derive(Serialize, Deserialize)].
        for v in partition_ordinal_sample() {
            let json = serde_json::to_string(&v).unwrap();
            assert_eq!(
                json,
                format!("\"{v}\""),
                "JSON emission for {v:?} must be the quoted canonical scalar",
            );
            let parsed: PartitionOrdinal = serde_json::from_str(&json).unwrap_or_else(|e| {
                panic!("JSON round-trip for {v:?} failed: {e}\n  json: {json}")
            });
            assert_eq!(
                parsed, v,
                "serde JSON round-trip must be identity for {v:?}",
            );
        }
    }

    #[test]
    fn partition_ordinal_serde_yaml_face_is_case_insensitive() {
        // Uppercase / mixed-case face halves in YAML scalars parse
        // back to the same address via the case-insensitive
        // deserialize path lowering through FromStr.
        for v in partition_ordinal_sample() {
            let face_upper = v.face().as_str().to_ascii_uppercase();
            let yaml = format!("\"{face_upper}:{}\"\n", v.face_ordinal());
            let parsed: PartitionOrdinal = serde_yaml::from_str(&yaml).unwrap_or_else(|e| {
                panic!("uppercase YAML scalar for {v:?} must deserialize: {e}\n  yaml: {yaml:?}")
            });
            assert_eq!(parsed, v);
        }
    }

    #[test]
    fn partition_ordinal_serde_yaml_unknown_face_error_carries_label_verbatim() {
        // A malformed face half surfaces through the serde error site
        // with the offending substring verbatim, routed via
        // serde::de::Error::custom on top of
        // ParsePartitionOrdinalError::UnknownFace's typed Display
        // impl.
        let sentinel = "__shikumi_unknown_partition_face_sentinel__";
        let yaml = format!("\"{sentinel}:42\"\n");
        let result: Result<PartitionOrdinal, _> = serde_yaml::from_str(&yaml);
        match result {
            Err(e) => {
                let rendered = format!("{e}");
                assert!(
                    rendered.contains(sentinel),
                    "serde YAML error must carry the unknown face label verbatim, got: {rendered}",
                );
            }
            Ok(other) => panic!("YAML carrying unknown face must reject, got {other:?}"),
        }
    }

    #[test]
    fn partition_ordinal_serde_yaml_malformed_ordinal_error_carries_substring_verbatim() {
        // A malformed ordinal half surfaces through the serde error
        // site with the offending substring verbatim, routed via
        // serde::de::Error::custom on top of
        // ParsePartitionOrdinalError::MalformedOrdinal's typed Display
        // impl.
        let sentinel = "not_a_number";
        let yaml = format!("\"realizable:{sentinel}\"\n");
        let result: Result<PartitionOrdinal, _> = serde_yaml::from_str(&yaml);
        match result {
            Err(e) => {
                let rendered = format!("{e}");
                assert!(
                    rendered.contains(sentinel),
                    "serde YAML error must carry the malformed ordinal verbatim, got: {rendered}",
                );
            }
            Ok(other) => panic!("YAML carrying malformed ordinal must reject, got {other:?}"),
        }
    }

    // ---- axis_label / axis_from_label — free-fn mirrors of the
    // ClosedAxisLabel trait methods ----
    //
    // The two free functions add no behavior over the trait methods; the
    // tests below pin that they agree with the trait methods pointwise
    // (so a future divergence is caught at one site) and re-state the
    // round-trip law at the free-function layer. Each test dispatches
    // through `for_each_closed_axis_label_implementor!`, so a future
    // implementor inherits all three by adding one macro arm.

    fn assert_axis_label_free_fn_matches_trait<L>()
    where
        L: ClosedAxisLabel + std::fmt::Debug,
    {
        // `axis_label(v) == v.as_str()` for every `v: L`.
        for value in L::ALL.iter().copied() {
            assert_eq!(
                axis_label(value),
                value.as_str(),
                "axis_label free fn must agree with ClosedAxisLabel::as_str for {value:?}",
            );
        }
    }

    fn assert_axis_from_label_free_fn_matches_trait<L>()
    where
        L: ClosedAxisLabel + std::fmt::Debug,
    {
        // `axis_from_label::<L>(s) == L::from_canonical_str(s)` over the
        // canonical labels, their uppercase form (the case-insensitive
        // path), and two guaranteed-miss probes (the empty string and a
        // sentinel that no canonical label can equal).
        for value in L::ALL.iter().copied() {
            let rendered = value.as_str();
            assert_eq!(
                axis_from_label::<L>(rendered),
                <L as ClosedAxisLabel>::from_canonical_str(rendered),
                "axis_from_label must agree with from_canonical_str on {rendered:?}",
            );
            let upper = rendered.to_ascii_uppercase();
            assert_eq!(
                axis_from_label::<L>(&upper),
                <L as ClosedAxisLabel>::from_canonical_str(&upper),
                "axis_from_label must agree with from_canonical_str on {upper:?}",
            );
        }
        for probe in ["", "\u{0}not-a-canonical-label\u{0}"] {
            assert_eq!(
                axis_from_label::<L>(probe),
                <L as ClosedAxisLabel>::from_canonical_str(probe),
                "axis_from_label must agree with from_canonical_str on non-label {probe:?}",
            );
        }
    }

    fn assert_axis_label_free_fn_round_trips<L>()
    where
        L: ClosedAxisLabel + std::fmt::Debug,
    {
        // Free-function form of the round-trip law:
        // `axis_from_label(axis_label(v)) == Some(v)`.
        for value in L::ALL.iter().copied() {
            assert_eq!(
                axis_from_label::<L>(axis_label(value)),
                Some(value),
                "free-fn round-trip failed for {value:?}",
            );
        }
    }

    #[test]
    fn axis_label_free_fn_matches_trait_as_str_for_every_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_axis_label_free_fn_matches_trait::<$ty>();
            };
        }
        for_each_closed_axis_label_implementor!(check);
    }

    #[test]
    fn axis_from_label_free_fn_matches_trait_for_every_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_axis_from_label_free_fn_matches_trait::<$ty>();
            };
        }
        for_each_closed_axis_label_implementor!(check);
    }

    #[test]
    fn axis_label_free_fn_round_trips_for_every_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_axis_label_free_fn_round_trips::<$ty>();
            };
        }
        for_each_closed_axis_label_implementor!(check);
    }

    // ---- AxisHistogram trait-uniform invariants ----
    //
    // Reach every [`ClosedAxis`] implementor — the twenty axis primitives
    // and the five product cubes — through
    // [`for_each_closed_axis_implementor`] so the per-axis histogram
    // primitive's laws hold uniformly without per-axis test duplication.

    fn assert_empty_histogram_is_zero_on_every_cell<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        let hist = AxisHistogram::<A>::empty();
        assert_eq!(
            hist.total(),
            0,
            "empty histogram total must be 0 for axis {}",
            std::any::type_name::<A>(),
        );
        assert!(
            hist.is_empty(),
            "empty histogram is_empty must be true for axis {}",
            std::any::type_name::<A>(),
        );
        for value in axis_iter::<A>() {
            assert_eq!(
                hist.count(value),
                0,
                "empty histogram count must be 0 for cell {value:?} on axis {}",
                std::any::type_name::<A>(),
            );
        }
        assert_eq!(
            hist.nonzero().count(),
            0,
            "empty histogram must have no nonzero cells on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_singleton_histogram_pins_observed_cell<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // For every cell of the axis: a histogram built from one
        // observation of that cell has count=1 on it and count=0
        // elsewhere; total=1, is_empty=false.
        for observed in axis_iter::<A>() {
            let hist: AxisHistogram<A> = std::iter::once(observed).collect();
            assert_eq!(hist.total(), 1, "singleton total must equal 1");
            assert!(!hist.is_empty(), "singleton must not be empty");
            for cell in axis_iter::<A>() {
                let expected = usize::from(cell == observed);
                assert_eq!(
                    hist.count(cell),
                    expected,
                    "singleton on {observed:?}: count({cell:?}) must be {expected}",
                );
            }
            let nonzero: Vec<(A, usize)> = hist.nonzero().collect();
            assert_eq!(nonzero, vec![(observed, 1)], "singleton nonzero set");
        }
    }

    fn assert_from_cell_equals_iter_once_collect<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The (cell → singleton histogram) constructor law: for every
        // cell of the axis, `AxisHistogram::from(cell)` and
        // `value.into()` produce a histogram pointwise equal to the
        // open-coded `std::iter::once(cell).collect()` form that the
        // singleton-histogram law above walks. The two singleton
        // constructors cannot drift apart by construction — pinned
        // uniformly across every closed-axis implementor so a future
        // axis primitive inherits the equivalence at no per-axis cost.
        for observed in axis_iter::<A>() {
            let via_from: AxisHistogram<A> = AxisHistogram::from(observed);
            let via_into: AxisHistogram<A> = observed.into();
            let via_iter_once: AxisHistogram<A> = std::iter::once(observed).collect();
            assert_eq!(
                via_from,
                via_iter_once,
                "AxisHistogram::from(cell) must equal iter::once(cell).collect() on {observed:?} \
                 for axis {}",
                std::any::type_name::<A>(),
            );
            assert_eq!(
                via_into,
                via_iter_once,
                "Into::into for cell must equal iter::once(cell).collect() on {observed:?} \
                 for axis {}",
                std::any::type_name::<A>(),
            );
            assert_eq!(
                via_from.total(),
                1,
                "From-built singleton total must equal 1 on axis {}",
                std::any::type_name::<A>(),
            );
            assert_eq!(
                via_from.count(observed),
                1,
                "From-built singleton must observe the lifted cell on {observed:?}",
            );
            assert_eq!(
                via_from.dominant_cell(),
                Some(observed),
                "From-built singleton dominant_cell must be the lifted cell on {observed:?}",
            );
        }
    }

    fn assert_from_empty_array_equals_empty<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The (zero-length array → histogram) constructor law:
        // `AxisHistogram::from([] as [A; 0])` reads the same all-zero
        // state as `AxisHistogram::empty()` and as `Default::default()`
        // on every axis. The vacuous fold on the array-input
        // constructor surface — the empty-array literal lowers to the
        // monoid identity at the `From<[A; N]>` constructor rung, peer
        // of the `FromIterator<A>` empty-input identity
        // (`iter::empty().collect()`) and of the `Extend<A>` empty-
        // input identity (`hist.extend(iter::empty())`).
        //
        // The element-type ascription (`[] as [A; 0]`) disambiguates
        // the empty array from the peer `From<[(A, usize); 0]>`
        // pair-array constructor — both impls accept an arity-0 array
        // literal, and the bare `[]` is ambiguous between them. The
        // ascription pins the raw-observation surface explicitly; the
        // pair-input peer carries its own empty-pair-array identity
        // test below.
        let via_from: AxisHistogram<A> = AxisHistogram::from([] as [A; 0]);
        let via_empty: AxisHistogram<A> = AxisHistogram::empty();
        let via_default: AxisHistogram<A> = AxisHistogram::default();
        assert_eq!(
            via_from,
            via_empty,
            "AxisHistogram::from([] as [A; 0]) must equal AxisHistogram::empty() on axis {}",
            std::any::type_name::<A>(),
        );
        assert_eq!(
            via_from,
            via_default,
            "AxisHistogram::from([] as [A; 0]) must equal AxisHistogram::default() on axis {}",
            std::any::type_name::<A>(),
        );
        assert_eq!(
            via_from.total(),
            0,
            "AxisHistogram::from([] as [A; 0]).total() must equal 0 on axis {}",
            std::any::type_name::<A>(),
        );
        assert!(
            via_from.is_empty(),
            "AxisHistogram::from([] as [A; 0]) must be is_empty on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_from_cell_array_equals_from_iter_collect<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The (array-literal → histogram) constructor law: for every
        // cell of the axis, the arity-1 array literal
        // `AxisHistogram::from([cell])` reads the same histogram as the
        // singleton `From<A>` constructor (`AxisHistogram::from(cell)`),
        // as `iter::once(cell).collect()`, and as the open-coded
        // `empty + observe` lowering. Pinned uniformly across every
        // closed-axis implementor so a future axis primitive inherits
        // the equivalence at no per-axis cost. The arity-1 array form
        // is the universally-available array shape — every closed axis
        // has at least one cell — so the trait-uniform law lives at the
        // singleton-array rung; higher-arity arrays are pinned
        // concretely on a specific axis below.
        for observed in axis_iter::<A>() {
            let via_from_array: AxisHistogram<A> = AxisHistogram::from([observed]);
            let via_from_cell: AxisHistogram<A> = AxisHistogram::from(observed);
            let via_iter_once: AxisHistogram<A> = std::iter::once(observed).collect();
            let via_into_iter_collect: AxisHistogram<A> = [observed].into_iter().collect();
            assert_eq!(
                via_from_array,
                via_from_cell,
                "AxisHistogram::from([cell]) must equal AxisHistogram::from(cell) on {observed:?} \
                 for axis {}",
                std::any::type_name::<A>(),
            );
            assert_eq!(
                via_from_array,
                via_iter_once,
                "AxisHistogram::from([cell]) must equal iter::once(cell).collect() on {observed:?} \
                 for axis {}",
                std::any::type_name::<A>(),
            );
            assert_eq!(
                via_from_array,
                via_into_iter_collect,
                "AxisHistogram::from([cell]) must equal [cell].into_iter().collect() on \
                 {observed:?} for axis {}",
                std::any::type_name::<A>(),
            );
            assert_eq!(
                via_from_array.total(),
                1,
                "AxisHistogram::from([cell]).total() must equal 1 on axis {}",
                std::any::type_name::<A>(),
            );
            assert_eq!(
                via_from_array.count(observed),
                1,
                "AxisHistogram::from([cell]) must observe the lifted cell on {observed:?}",
            );
        }
    }

    fn assert_all_observed_once_yields_uniform_histogram<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Observing every cell exactly once yields a histogram with
        // every cell at 1 and total = cardinality.
        let hist: AxisHistogram<A> = axis_iter::<A>().collect();
        assert_eq!(
            hist.total(),
            axis_cardinality::<A>(),
            "axis-cover histogram total must equal axis_cardinality on {}",
            std::any::type_name::<A>(),
        );
        for cell in axis_iter::<A>() {
            assert_eq!(hist.count(cell), 1, "every cell must be 1 in axis-cover");
        }
        assert_eq!(
            hist.nonzero().count(),
            axis_cardinality::<A>(),
            "every cell nonzero in axis-cover",
        );
    }

    fn assert_iter_matches_axis_iter_pointwise<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // `iter()` is the dense axis_iter sequence joined with the
        // per-cell counts; the value-side projection equals
        // axis_iter::<A>() pointwise.
        let hist = AxisHistogram::<A>::empty();
        let values_via_hist: Vec<A> = hist.iter().map(|(v, _)| v).collect();
        let values_via_axis: Vec<A> = axis_iter::<A>().collect();
        assert_eq!(
            values_via_hist,
            values_via_axis,
            "AxisHistogram::iter value sequence must equal axis_iter on {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_total_equals_input_length<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The free-function `axis_histogram` constructor: total over the
        // resulting histogram equals the input iterator length pointwise.
        // Pinned over a synthetic input that observes every cell twice
        // (length 2*cardinality) to cover the bulk-observation path.
        let input: Vec<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        let expected = input.len();
        let hist = axis_histogram(input);
        assert_eq!(
            hist.total(),
            expected,
            "axis_histogram total must equal input length on {}",
            std::any::type_name::<A>(),
        );
        for cell in axis_iter::<A>() {
            assert_eq!(hist.count(cell), 2, "every cell observed twice");
        }
    }

    fn assert_merge_is_pointwise_sum<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Merge law: count(a, lhs.merge(rhs)) == count(a, lhs) + count(a, rhs)
        // for every cell. Identity at empty:
        // lhs.merge(empty) == lhs (cell-wise).
        let lhs: AxisHistogram<A> = axis_iter::<A>().collect();
        let rhs: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        let merged = lhs.clone().merge(&rhs);
        for cell in axis_iter::<A>() {
            assert_eq!(
                merged.count(cell),
                lhs.count(cell) + rhs.count(cell),
                "merge must be pointwise sum on {cell:?} for axis {}",
                std::any::type_name::<A>(),
            );
        }
        assert_eq!(
            merged.total(),
            lhs.total() + rhs.total(),
            "merged total equals sum of totals on {}",
            std::any::type_name::<A>(),
        );
        let id_right = lhs.clone().merge(&AxisHistogram::<A>::empty());
        assert_eq!(
            id_right,
            lhs,
            "empty is right identity under merge on {}",
            std::any::type_name::<A>(),
        );
        let id_left = AxisHistogram::<A>::empty().merge(&lhs);
        assert_eq!(
            id_left,
            lhs,
            "empty is left identity under merge on {}",
            std::any::type_name::<A>(),
        );
    }

    #[test]
    fn axis_histogram_empty_is_zero_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_empty_histogram_is_zero_on_every_cell::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_singleton_pins_observed_cell_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_singleton_histogram_pins_observed_cell::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_from_cell_equals_iter_once_collect_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_from_cell_equals_iter_once_collect::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_from_empty_array_equals_empty_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_from_empty_array_equals_empty::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_from_cell_array_equals_from_iter_collect_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_from_cell_array_equals_from_iter_collect::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_axis_cover_is_uniform_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_all_observed_once_yields_uniform_histogram::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_iter_matches_axis_iter_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_iter_matches_axis_iter_pointwise::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_total_equals_input_length_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_total_equals_input_length::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_merge_is_monoid_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_merge_is_pointwise_sum::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_default_equals_empty() {
        // `Default::default()` and `AxisHistogram::empty()` produce
        // pointwise-equal histograms — the all-zero state on the
        // identity slot of the monoid.
        let via_default: AxisHistogram<DiffLineKind> = AxisHistogram::default();
        let via_empty: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
        assert_eq!(via_default, via_empty);
    }

    #[test]
    fn axis_histogram_free_fn_equals_collect_for_diff_line_kind() {
        // `axis_histogram(iter)` and `iter.collect::<AxisHistogram<_>>()`
        // produce pointwise-equal histograms. Pinned concretely on
        // [`DiffLineKind`] so the implementation contract is named at
        // one site (the trait-uniform laws above cover every axis).
        let input = [
            DiffLineKind::Removed,
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Context,
        ];
        let via_fn = axis_histogram::<DiffLineKind, _>(input.iter().copied());
        let via_collect: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
        assert_eq!(via_fn, via_collect);
        assert_eq!(via_fn.count(DiffLineKind::Removed), 1);
        assert_eq!(via_fn.count(DiffLineKind::Added), 2);
        assert_eq!(via_fn.count(DiffLineKind::Context), 1);
        assert_eq!(via_fn.total(), 4);
    }

    #[test]
    fn axis_histogram_from_cell_constructs_singleton_for_diff_line_kind() {
        // Concrete pin of the `From<A>` singleton constructor on
        // [`DiffLineKind`]: lifting a single cell through `From`/`Into`
        // matches the `iter::once + collect` and `empty + observe`
        // lowerings pointwise. Names the singleton-constructor
        // contract at one site explicitly so the surface shape
        // (`value.into()`, `AxisHistogram::from(value)`,
        // `iter::once(value).collect()`,
        // `{ let mut h = empty(); h.observe(value); h }`) is readable
        // as four pointwise-equal lowerings of the same projection.
        let via_from = AxisHistogram::from(DiffLineKind::Added);
        let via_into: AxisHistogram<DiffLineKind> = DiffLineKind::Added.into();
        let via_iter_once: AxisHistogram<DiffLineKind> =
            std::iter::once(DiffLineKind::Added).collect();
        let via_observe = {
            let mut h: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
            h.observe(DiffLineKind::Added);
            h
        };
        assert_eq!(via_from, via_into);
        assert_eq!(via_from, via_iter_once);
        assert_eq!(via_from, via_observe);
        assert_eq!(via_from.count(DiffLineKind::Added), 1);
        assert_eq!(via_from.count(DiffLineKind::Removed), 0);
        assert_eq!(via_from.count(DiffLineKind::Context), 0);
        assert_eq!(via_from.total(), 1);
        assert!(!via_from.is_empty());
        assert_eq!(via_from.dominant_cell(), Some(DiffLineKind::Added));
    }

    #[test]
    fn axis_histogram_from_cell_array_constructs_pointwise_histogram_for_diff_line_kind() {
        // Concrete pin of the `From<[A; N]>` array constructor on
        // [`DiffLineKind`] at arity 3 — the trait-uniform law above
        // covers the arity-1 (singleton-array) rung uniformly across
        // every closed axis; this test pins the higher-arity
        // multi-cell semantics at one site so the constructor's
        // cell-additive behavior (the same cell appearing twice in the
        // literal contributes +2 to that cell) is readable on a
        // concrete axis. The array literal lowers to the same per-cell
        // observation fold the `FromIterator<A>` impl drives, so the
        // four canonical surfaces (`AxisHistogram::from([...])`,
        // `[...].into()`, `[...].into_iter().collect()`, the
        // open-coded `empty + observe + observe + observe` form) are
        // pinned here as four pointwise-equal lowerings of the same
        // (array-literal → histogram) projection.
        let via_from = AxisHistogram::from([
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
        ]);
        let via_into: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
        ]
        .into();
        let via_into_iter_collect: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
        ]
        .into_iter()
        .collect();
        let via_observe = {
            let mut h: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
            h.observe(DiffLineKind::Added);
            h.observe(DiffLineKind::Added);
            h.observe(DiffLineKind::Removed);
            h
        };
        assert_eq!(via_from, via_into);
        assert_eq!(via_from, via_into_iter_collect);
        assert_eq!(via_from, via_observe);
        assert_eq!(via_from.count(DiffLineKind::Added), 2);
        assert_eq!(via_from.count(DiffLineKind::Removed), 1);
        assert_eq!(via_from.count(DiffLineKind::Context), 0);
        assert_eq!(via_from.total(), 3);
        assert!(!via_from.is_empty());
        assert_eq!(via_from.dominant_cell(), Some(DiffLineKind::Added));
    }

    #[test]
    fn axis_histogram_from_empty_array_equals_empty_for_diff_line_kind() {
        // Concrete pin of the empty-array identity on [`DiffLineKind`]:
        // `AxisHistogram::from([] as [DiffLineKind; 0])` reads the
        // same all-zero state as `AxisHistogram::empty()` and as
        // `Default::default()`. The zero-length array literal lowers
        // to the monoid identity at the constructor rung. The
        // element-type ascription disambiguates from the peer
        // `From<[(A, usize); 0]>` empty pair-array constructor.
        // Trait-uniform partner pinned across every closed-axis
        // implementor by
        // `axis_histogram_from_empty_array_equals_empty_for_every_closed_axis_implementor`.
        let via_from: AxisHistogram<DiffLineKind> = AxisHistogram::from([] as [DiffLineKind; 0]);
        let via_empty: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
        let via_default: AxisHistogram<DiffLineKind> = AxisHistogram::default();
        assert_eq!(via_from, via_empty);
        assert_eq!(via_from, via_default);
        assert_eq!(via_from.total(), 0);
        assert!(via_from.is_empty());
        assert_eq!(via_from.count(DiffLineKind::Added), 0);
        assert_eq!(via_from.count(DiffLineKind::Removed), 0);
        assert_eq!(via_from.count(DiffLineKind::Context), 0);
    }

    #[test]
    fn axis_histogram_observe_bumps_only_target_cell() {
        // The single-observation primitive: observe(v) increments
        // count(v) by 1, leaves every other cell unchanged. Composes
        // with merge / FromIterator / axis_histogram as the atomic
        // operation underneath each.
        let mut hist: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
        hist.observe(DiffLineKind::Added);
        assert_eq!(hist.count(DiffLineKind::Added), 1);
        assert_eq!(hist.count(DiffLineKind::Removed), 0);
        assert_eq!(hist.count(DiffLineKind::Context), 0);
        hist.observe(DiffLineKind::Added);
        assert_eq!(hist.count(DiffLineKind::Added), 2);
        hist.observe(DiffLineKind::Removed);
        assert_eq!(hist.count(DiffLineKind::Added), 2);
        assert_eq!(hist.count(DiffLineKind::Removed), 1);
        assert_eq!(hist.total(), 3);
    }

    #[test]
    fn axis_histogram_indexes_through_axis_ordinal() {
        // Pin the layout invariant: `hist.count(cell)` reads through
        // `axis_ordinal(cell)` on the internal Vec. Pinned via the
        // axis-cover construction, which lays one count at every
        // ordinal in `0..axis_cardinality::<DiffLineKind>()`.
        let hist: AxisHistogram<DiffLineKind> = axis_iter::<DiffLineKind>().collect();
        for cell in axis_iter::<DiffLineKind>() {
            let ordinal = axis_ordinal::<DiffLineKind>(cell);
            assert!(
                ordinal < axis_cardinality::<DiffLineKind>(),
                "ordinal must be in-range for {cell:?}",
            );
            assert_eq!(hist.count(cell), 1, "cell {cell:?} count must equal 1");
        }
    }

    // ---- AxisHistogram::extend trait-uniform laws ----
    //
    // Four trait-uniform laws reach every [`ClosedAxis`] implementor
    // through [`for_each_closed_axis_implementor`] so the per-axis
    // `Extend<A>` projection's contract holds uniformly without per-axis
    // test duplication: extending with an empty iterator is identity;
    // extending the empty histogram is `FromIterator`; extending grows
    // the total by exactly the input length; extending with two
    // iterators in sequence equals extending with their concatenation.
    // The four laws close the (extend, FromIterator) idiom-peer
    // equivalence at the trait surface, the (extend, observe) loop
    // equivalence at the per-cell surface, the (extend, total)
    // additivity, and the (extend, ⊕) homomorphism over iterator
    // concatenation — every consumer reaching the in-place fold
    // through one trait method instead of an open-coded
    // `for v in iter { hist.observe(v); }` loop, an
    // `iter.into_iter().for_each(|v| hist.observe(v));` callback, or a
    // `let other: AxisHistogram<A> = iter.collect(); hist =
    // hist.merge(&other);` build-and-merge intermediary.

    fn assert_extend_empty_input_is_identity<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Extending any histogram with an empty iterator leaves it
        // unchanged — the vacuous fold on the [`Extend`] monoid
        // surface, peer to the [`AxisHistogram::merge`] empty-identity
        // law. Pinned over the empty starting histogram (the identity
        // slot) and the axis-cover starting histogram (a non-trivial
        // shape with every cell observed) so the law is witnessed at
        // both ends of the coverage axis.
        let mut empty = AxisHistogram::<A>::empty();
        empty.extend(std::iter::empty::<A>());
        assert_eq!(
            empty,
            AxisHistogram::<A>::empty(),
            "extend(empty) on empty must be identity on axis {}",
            std::any::type_name::<A>(),
        );

        let cover_pre: AxisHistogram<A> = axis_iter::<A>().collect();
        let mut cover_post = cover_pre.clone();
        cover_post.extend(std::iter::empty::<A>());
        assert_eq!(
            cover_post,
            cover_pre,
            "extend(empty) on axis-cover must be identity on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_extend_starting_empty_equals_from_iter<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The canonical lowering: starting from the empty histogram,
        // extending with an iterator yields the same histogram as
        // collecting that iterator through [`FromIterator`]. The
        // (FromIterator, Extend) idiom-peer equivalence that justifies
        // the [`FromIterator`] impl delegating to [`Extend`]. Pinned
        // over the axis-cover input (every cell observed once) so the
        // equivalence covers every ordinal in the counts vector.
        let mut via_extend = AxisHistogram::<A>::empty();
        via_extend.extend(axis_iter::<A>());
        let via_from_iter: AxisHistogram<A> = axis_iter::<A>().collect();
        assert_eq!(
            via_extend,
            via_from_iter,
            "extend(axis_iter) on empty must equal axis_iter.collect() on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_extend_grows_total_by_input_length<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The additivity law on the [`Self::total`] scalar surface:
        // extending grows the total by exactly the number of items the
        // iterator yields. Pinned over a non-empty starting histogram
        // (the axis-cover, total = cardinality) extended with another
        // axis-cover (input length = cardinality) so the post-extend
        // total equals 2 * cardinality — the additivity reads off the
        // counts.
        let mut hist: AxisHistogram<A> = axis_iter::<A>().collect();
        let before = hist.total();
        let input: Vec<A> = axis_iter::<A>().collect();
        let input_len = input.len();
        hist.extend(input);
        assert_eq!(
            hist.total(),
            before + input_len,
            "extend must grow total by input length on axis {}",
            std::any::type_name::<A>(),
        );
        for cell in axis_iter::<A>() {
            assert_eq!(
                hist.count(cell),
                2,
                "cell {cell:?} must read 2 after axis-cover extended by axis-cover on {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_extend_chained_equals_two_step_extend<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The (extend, ⊕) homomorphism over iterator concatenation:
        // extending with `iter_a` then `iter_b` produces the same
        // histogram as extending with `iter_a.chain(iter_b)`. Pinned
        // over two disjoint axis-iter halves of the closed axis (the
        // empty iterator paired with the axis-cover when the axis has
        // cardinality < 2; otherwise a split at the midpoint) so the
        // chain covers every cell at least once across cardinalities.
        let all: Vec<A> = axis_iter::<A>().collect();
        let mid = all.len() / 2;
        let head: Vec<A> = all[..mid].to_vec();
        let tail: Vec<A> = all[mid..].to_vec();

        let mut two_step = AxisHistogram::<A>::empty();
        two_step.extend(head.iter().copied());
        two_step.extend(tail.iter().copied());

        let mut chained = AxisHistogram::<A>::empty();
        chained.extend(head.iter().copied().chain(tail.iter().copied()));

        assert_eq!(
            two_step,
            chained,
            "two-step extend must equal chained extend on axis {}",
            std::any::type_name::<A>(),
        );
    }

    #[test]
    fn axis_histogram_extend_empty_input_is_identity_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_extend_empty_input_is_identity::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_extend_starting_empty_equals_from_iter_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_extend_starting_empty_equals_from_iter::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_extend_grows_total_by_input_length_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_extend_grows_total_by_input_length::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_extend_chained_equals_two_step_extend_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_extend_chained_equals_two_step_extend::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_extend_equals_observe_loop_for_diff_line_kind() {
        // The (extend, observe) loop-equivalence on the per-cell
        // surface: `hist.extend(iter)` is pointwise equal to
        // `for v in iter { hist.observe(v); }` on every iterator. The
        // lift names the open-coded loop at one site so consumers no
        // longer re-derive it inline. Pinned concretely on
        // [`DiffLineKind`] across four canonical observation-mix
        // shapes (empty, singleton, two-of-three, axis-cover-plus-
        // repetition) so the equivalence holds at every shape in the
        // histogram's coverage axis.
        let inputs: [&[DiffLineKind]; 4] = [
            &[],
            &[DiffLineKind::Added],
            &[
                DiffLineKind::Added,
                DiffLineKind::Removed,
                DiffLineKind::Added,
            ],
            &[
                DiffLineKind::Context,
                DiffLineKind::Added,
                DiffLineKind::Removed,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
        ];
        for input in inputs {
            let mut via_extend: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
            via_extend.extend(input.iter().copied());

            let mut via_loop: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
            for &v in input {
                via_loop.observe(v);
            }

            assert_eq!(
                via_extend,
                via_loop,
                "extend must equal observe-loop on input of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_extend_equals_merge_of_collected_for_diff_line_kind() {
        // The (extend, merge) duality on the monoid: extending in
        // place is the in-place form of merging with the collected
        // histogram. Pinned concretely on [`DiffLineKind`] across a
        // non-trivial starting histogram (an existing observation
        // window) and a non-trivial extension stream (the next
        // observation batch) — the canonical shape an observatory or
        // fleet-wide aggregator reaches through every window boundary.
        let prior = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Context,
        ];
        let next = [
            DiffLineKind::Removed,
            DiffLineKind::Added,
            DiffLineKind::Removed,
        ];

        let mut via_extend: AxisHistogram<DiffLineKind> = prior.iter().copied().collect();
        via_extend.extend(next.iter().copied());

        let prior_hist: AxisHistogram<DiffLineKind> = prior.iter().copied().collect();
        let next_hist: AxisHistogram<DiffLineKind> = next.iter().copied().collect();
        let via_merge = prior_hist.merge(&next_hist);

        assert_eq!(via_extend, via_merge);
        // Cell-level accounting on the resulting histogram.
        assert_eq!(via_extend.count(DiffLineKind::Added), 3);
        assert_eq!(via_extend.count(DiffLineKind::Removed), 2);
        assert_eq!(via_extend.count(DiffLineKind::Context), 1);
        assert_eq!(via_extend.total(), 6);
    }

    #[test]
    fn axis_histogram_from_iter_lowers_to_extend_for_diff_line_kind() {
        // The canonical Rust idiom: `FromIterator::from_iter` is
        // pointwise equal to `let mut h = Default::default();
        // h.extend(iter); h` — the lowering the [`FromIterator`] impl
        // uses internally. Pinned concretely on [`DiffLineKind`] so a
        // future regression in either side (e.g. a `FromIterator` impl
        // that drifts away from the `default + extend` shape, or an
        // `Extend` impl that loses an observation through a fold edge
        // case) surfaces here at one named site.
        let input = [
            DiffLineKind::Removed,
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Context,
            DiffLineKind::Added,
        ];

        let via_from_iter: AxisHistogram<DiffLineKind> = input.iter().copied().collect();

        let mut via_default_extend: AxisHistogram<DiffLineKind> = AxisHistogram::default();
        via_default_extend.extend(input.iter().copied());

        assert_eq!(via_from_iter, via_default_extend);
    }

    // ---- AxisHistogram borrowed-observation FromIterator / Extend trait-uniform laws ----
    //
    // Three trait-uniform laws reach every [`ClosedAxis`] implementor through
    // [`for_each_closed_axis_implementor`] so the per-axis borrowed-observation
    // [`FromIterator<&A>`] / [`Extend<&A>`] projection's contract holds
    // uniformly without per-axis test duplication: extending with an empty
    // borrowed iterator is identity; the borrowed and owned input surfaces
    // produce the same histogram (the canonical (owned, borrowed) idiom-peer
    // equivalence — peer of the (`Sum<Self>`, `Sum<&Self>`) reduction-side
    // pair on the dual side of the monoid); borrowed `FromIterator` lowers
    // to `default + borrowed-extend` on the borrowed surface (the canonical
    // Rust lowering the impl uses internally). The three laws close the
    // borrowed-input duality on the raw-observation surface at the trait
    // peerage every stdlib [`Copy`]-item collection carries
    // (`Vec<T>: FromIterator<&T> where T: Copy`, etc.).

    fn assert_ref_extend_empty_input_is_identity<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Extending any histogram with an empty borrowed iterator leaves
        // it unchanged — the vacuous fold on the borrowed-[`Extend`]
        // surface, peer of the owned-[`Extend<A>`] empty-identity law.
        // Pinned over the empty starting histogram (the identity slot)
        // and the axis-cover starting histogram (a non-trivial shape
        // with every cell observed) so the law is witnessed at both
        // ends of the coverage axis.
        let mut empty = AxisHistogram::<A>::empty();
        empty.extend(std::iter::empty::<&A>());
        assert_eq!(
            empty,
            AxisHistogram::<A>::empty(),
            "ref-extend(empty) on empty must be identity on axis {}",
            std::any::type_name::<A>(),
        );

        let cover_pre: AxisHistogram<A> = axis_iter::<A>().collect();
        let mut cover_post = cover_pre.clone();
        cover_post.extend(std::iter::empty::<&A>());
        assert_eq!(
            cover_post,
            cover_pre,
            "ref-extend(empty) on axis-cover must be identity on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_ref_from_iter_equals_owned_from_iter<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The (`FromIterator<A>`, `FromIterator<&A>`) idiom-peer
        // equivalence on the input-side of the monoid: collecting a
        // borrowed-item iterator yields the same histogram as collecting
        // a value-item iterator (i.e. cloning the borrowed items through
        // the owned `FromIterator`). The canonical Rust borrowed/owned
        // `FromIterator` peer pair on a single observation surface,
        // mirror of the (`Sum<Self>`, `Sum<&Self>`) duality on the dual
        // reduction side. Pinned over the axis-cover input so every cell
        // carries an observation and the equivalence reads off every
        // ordinal in the counts vector.
        let cover: Vec<A> = axis_iter::<A>().collect();
        let via_refs: AxisHistogram<A> = cover.iter().collect();
        let via_owned: AxisHistogram<A> = cover.iter().copied().collect();
        assert_eq!(
            via_refs,
            via_owned,
            "FromIterator<&A> via cover.iter() must equal FromIterator<A> via cover.iter().copied() on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_ref_from_iter_lowers_to_default_plus_ref_extend<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The canonical Rust lowering on the borrowed surface:
        // `iter.collect::<AxisHistogram<A>>()` for a borrowed-item
        // iterator is pointwise equal to `let mut h =
        // AxisHistogram::default(); h.extend(iter); h` — the lowering
        // the borrowed-[`FromIterator`] impl uses internally. Pinned
        // over the axis-cover input so the lowering is witnessed
        // against a non-trivial cell distribution.
        let cover: Vec<A> = axis_iter::<A>().collect();
        let via_from_iter: AxisHistogram<A> = cover.iter().collect();
        let mut via_default_extend: AxisHistogram<A> = AxisHistogram::default();
        via_default_extend.extend(cover.iter());
        assert_eq!(
            via_from_iter,
            via_default_extend,
            "FromIterator<&A>::from_iter must equal default + Extend<&A>::extend on axis {}",
            std::any::type_name::<A>(),
        );
    }

    #[test]
    fn axis_histogram_ref_extend_empty_input_is_identity_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_ref_extend_empty_input_is_identity::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_ref_from_iter_equals_owned_from_iter_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_ref_from_iter_equals_owned_from_iter::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_ref_from_iter_lowers_to_default_plus_ref_extend_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_ref_from_iter_lowers_to_default_plus_ref_extend::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_ref_from_iter_drops_copied_adaptor_for_diff_line_kind() {
        // The canonical Rust call-site shape on the borrowed surface:
        // `slice.iter().collect::<AxisHistogram<A>>()` reads the same
        // histogram as `slice.iter().copied().collect()` — the
        // borrowed-input [`FromIterator<&A>`] impl drops the interposing
        // `.copied()` adaptor consumers used to write at every borrowed
        // call site. Pinned concretely on [`DiffLineKind`] across a non-
        // trivial observation mix so the equivalence reads off the per-
        // cell counts on the call-site shape consumers reach.
        let observations = [
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Added,
            DiffLineKind::Context,
            DiffLineKind::Added,
        ];

        let via_refs: AxisHistogram<DiffLineKind> = observations.iter().collect();
        let via_copied: AxisHistogram<DiffLineKind> = observations.iter().copied().collect();
        assert_eq!(via_refs, via_copied);

        // Cell-level accounting on the resulting histogram.
        assert_eq!(via_refs.count(DiffLineKind::Added), 3);
        assert_eq!(via_refs.count(DiffLineKind::Removed), 1);
        assert_eq!(via_refs.count(DiffLineKind::Context), 1);
        assert_eq!(via_refs.total(), 5);

        // The borrowed-[`Extend`] surface drops the same adaptor on the
        // in-place fold side: `hist.extend(slice.iter())` reads the
        // same post-extend histogram as `hist.extend(slice.iter().copied())`.
        let mut via_ref_extend: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
        via_ref_extend.extend(observations.iter());
        let mut via_copied_extend: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
        via_copied_extend.extend(observations.iter().copied());
        assert_eq!(via_ref_extend, via_copied_extend);
        assert_eq!(via_ref_extend, via_refs);
    }

    // ---- AxisHistogram pair-input FromIterator / Extend trait-uniform laws ----
    //
    // Four trait-uniform laws reach every [`ClosedAxis`] implementor through
    // [`for_each_closed_axis_implementor`] so the per-axis
    // `Extend<(A, usize)>` / `FromIterator<(A, usize)>` projection's
    // contract holds uniformly without per-axis test duplication:
    // extending with an empty pair iterator is identity; extending with a
    // zero-count pair on any cell is identity; the pair-input surface is
    // *additive* on repeated cells (the salient asymmetry with
    // [`HashMap::extend`]'s last-wins semantics); pair-input
    // [`FromIterator`] lowers to `default + extend` on the pair surface.
    // The four laws close the (pair-input extend, raw-observation extend)
    // duality at the trait surface, the additive-monoid promise on
    // per-cell counts, and the canonical [`HashMap`] / [`BTreeMap`]
    // pair-input [`FromIterator`] idiom-peer on the histogram surface.

    fn assert_pair_extend_empty_input_is_identity<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Extending any histogram with an empty pair iterator leaves it
        // unchanged — the vacuous fold on the pair-input [`Extend`]
        // surface, peer of the raw-observation [`Extend<A>`] empty-
        // identity law. Pinned over the empty starting histogram (the
        // identity slot) and the axis-cover starting histogram (a non-
        // trivial shape with every cell observed) so the law is
        // witnessed at both ends of the coverage axis.
        let mut empty = AxisHistogram::<A>::empty();
        empty.extend(std::iter::empty::<(A, usize)>());
        assert_eq!(
            empty,
            AxisHistogram::<A>::empty(),
            "pair-extend(empty) on empty must be identity on axis {}",
            std::any::type_name::<A>(),
        );

        let cover_pre: AxisHistogram<A> = axis_iter::<A>().collect();
        let mut cover_post = cover_pre.clone();
        cover_post.extend(std::iter::empty::<(A, usize)>());
        assert_eq!(
            cover_post,
            cover_pre,
            "pair-extend(empty) on axis-cover must be identity on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_pair_extend_zero_count_pair_is_identity<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // A pair with count zero is the additive identity on its cell:
        // `hist.extend(once((cell, 0)))` leaves every cell unchanged.
        // The per-cell zero-element law on the additive `(usize, +, 0)`
        // monoid the pair-input surface folds through. Pinned over
        // every cell of the axis on a non-empty starting histogram
        // (the axis-cover) so the identity reads off at every ordinal.
        let cover_pre: AxisHistogram<A> = axis_iter::<A>().collect();
        for cell in axis_iter::<A>() {
            let mut hist = cover_pre.clone();
            hist.extend(std::iter::once((cell, 0usize)));
            assert_eq!(
                hist,
                cover_pre,
                "pair-extend((cell, 0)) must be identity on cell {cell:?} of axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_pair_extend_is_additive_on_repeated_cells<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The pair-input surface is *additive* on repeated cells —
        // the salient asymmetry with [`HashMap::extend`]'s last-wins
        // semantics. When the iterator yields `(cell, n1)` then
        // `(cell, n2)` on the same cell, the post-extend cell reads
        // `before + n1 + n2`, not `n2`. Pinned over every cell of
        // the axis on the empty starting histogram so the additive
        // law reads off at every ordinal without contamination from
        // a pre-existing count.
        for cell in axis_iter::<A>() {
            let mut hist = AxisHistogram::<A>::empty();
            hist.extend([(cell, 3usize), (cell, 4usize)]);
            assert_eq!(
                hist.count(cell),
                7,
                "pair-extend must be additive (3 + 4 = 7) on cell {cell:?} of axis {}",
                std::any::type_name::<A>(),
            );
            assert_eq!(
                hist.total(),
                7,
                "pair-extend total must equal sum of pair counts on cell {cell:?} of axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_pair_from_iter_lowers_to_pair_extend<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The canonical Rust lowering: pair-input
        // `FromIterator::from_iter` is pointwise equal to `let mut h =
        // Default::default(); h.extend(iter); h` on the pair surface.
        // Mirror of the raw-observation
        // `axis_histogram_from_iter_lowers_to_extend_*` pin lifted to
        // the pair-input surface. Pinned over the axis-cover-as-pairs
        // input `[(cell, 1), …]` so every cell receives a pair and the
        // equivalence covers every ordinal.
        let pairs: Vec<(A, usize)> = axis_iter::<A>().map(|c| (c, 1usize)).collect();

        let via_from_iter: AxisHistogram<A> = pairs.iter().copied().collect();
        let mut via_default_extend = AxisHistogram::<A>::default();
        via_default_extend.extend(pairs.iter().copied());

        assert_eq!(
            via_from_iter,
            via_default_extend,
            "pair-input FromIterator must lower to default + pair-input Extend on axis {}",
            std::any::type_name::<A>(),
        );
    }

    #[test]
    fn axis_histogram_pair_extend_empty_input_is_identity_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_pair_extend_empty_input_is_identity::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_pair_extend_zero_count_pair_is_identity_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_pair_extend_zero_count_pair_is_identity::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_pair_extend_is_additive_on_repeated_cells_for_every_closed_axis_implementor()
    {
        macro_rules! check {
            ($ty:ident) => {
                assert_pair_extend_is_additive_on_repeated_cells::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_pair_from_iter_lowers_to_pair_extend_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_pair_from_iter_lowers_to_pair_extend::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_pair_from_iter_equals_observe_expansion_for_diff_line_kind() {
        // The pair-input [`FromIterator`] expansion-equivalence on the
        // per-cell surface: collecting `[(cell, n), …]` into an
        // [`AxisHistogram`] is pointwise equal to collecting the
        // expanded raw-observation stream `iter::repeat(cell).take(n)`
        // chained across pairs. The lift replaces the O(total)
        // re-expansion every consumer used to open-code with an
        // O(distinct cells) single-pass scan; this pin reads the
        // equivalence at one named site on [`DiffLineKind`] over a
        // non-trivial pair mix so a future regression on either side
        // surfaces here.
        let pairs: [(DiffLineKind, usize); 3] = [
            (DiffLineKind::Added, 12),
            (DiffLineKind::Removed, 4),
            (DiffLineKind::Context, 53),
        ];

        let via_pairs: AxisHistogram<DiffLineKind> = pairs.iter().copied().collect();

        let via_expansion: AxisHistogram<DiffLineKind> = pairs
            .iter()
            .copied()
            .flat_map(|(c, n)| std::iter::repeat_n(c, n))
            .collect();

        assert_eq!(via_pairs, via_expansion);
        assert_eq!(via_pairs.count(DiffLineKind::Added), 12);
        assert_eq!(via_pairs.count(DiffLineKind::Removed), 4);
        assert_eq!(via_pairs.count(DiffLineKind::Context), 53);
        assert_eq!(via_pairs.total(), 69);
    }

    #[test]
    fn axis_histogram_pair_extend_round_trips_through_iter_for_diff_line_kind() {
        // The canonical (pair-input Extend, iter) round-trip on the
        // histogram surface — peer of the
        // `HashMap::from_iter(map.iter())` / `BTreeMap::from_iter(map.iter())`
        // round-trip every stdlib pair-keyed collection carries.
        // Folding `hist.iter()` (the [`AxisHistogram::iter`] pair
        // surface, yielding `(A, usize)` pairs over the full axis)
        // into an empty histogram through pair-input
        // [`FromIterator`] recovers the original histogram pointwise.
        // The natural snapshot / restore round-trip: serialize the
        // histogram by collecting its pairs into a `Vec<(A, usize)>`
        // (a YAML attestation manifest cell, a checkpoint snapshot
        // entry, an RPC response payload), then restore it on the
        // receiving side by collecting those pairs back. Pinned
        // concretely on [`DiffLineKind`] over a non-trivial cell
        // distribution so every ordinal carries a positive count and
        // the round-trip reads off every cell.
        let prior: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Context,
            DiffLineKind::Added,
            DiffLineKind::Context,
        ]
        .into_iter()
        .collect();

        let pairs: Vec<(DiffLineKind, usize)> = prior.iter().collect();
        let restored: AxisHistogram<DiffLineKind> = pairs.into_iter().collect();

        assert_eq!(prior, restored);
    }

    // ---- AxisHistogram::From<[(A, usize); N]> trait-uniform laws ----
    //
    // Three trait-uniform laws reach every [`ClosedAxis`] implementor through
    // [`for_each_closed_axis_implementor`] so the per-axis pair-input array
    // constructor's contract holds uniformly without per-axis test
    // duplication: the empty pair-array reads the empty histogram (vacuous
    // fold at the constructor rung); a singleton pair `[(cell, 1)]` reads
    // the same histogram as the singleton-cell constructor `from(cell)` and
    // as the iter-once collect (bridging the raw-observation and pre-counted-
    // pair entry surfaces at the singleton boundary); a zero-count pair
    // `[(cell, 0)]` reads the empty histogram on every cell (the additive
    // identity at the pair rung). The three laws close the `From<[A; N]>` /
    // `From<[(A, usize); N]>` peerage at the trait surface, peer of the
    // existing `From<[A; N]>` / `From<A>` / `FromIterator` / `Extend`
    // constructor peerage.

    fn assert_from_empty_pair_array_equals_empty<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The zero-length pair-array constructor law: the empty pair
        // literal `[]` typed as `[(A, usize); 0]` lowers to the same
        // all-zero state as `AxisHistogram::empty()` and as
        // `Default::default()`. Vacuous fold on the pair-input array
        // surface, peer of the `From<[A; N]>` empty-array identity law
        // on the raw-observation surface and of the `Extend<(A, usize)>`
        // empty-input identity law on the pair-input fold surface.
        let via_from: AxisHistogram<A> = AxisHistogram::from([] as [(A, usize); 0]);
        let via_empty: AxisHistogram<A> = AxisHistogram::empty();
        let via_default: AxisHistogram<A> = AxisHistogram::default();
        assert_eq!(
            via_from,
            via_empty,
            "AxisHistogram::from([] as [(A, usize); 0]) must equal AxisHistogram::empty() on axis {}",
            std::any::type_name::<A>(),
        );
        assert_eq!(
            via_from,
            via_default,
            "AxisHistogram::from([] as [(A, usize); 0]) must equal AxisHistogram::default() on axis {}",
            std::any::type_name::<A>(),
        );
        assert_eq!(
            via_from.total(),
            0,
            "AxisHistogram::from([] as [(A, usize); 0]).total() must equal 0 on axis {}",
            std::any::type_name::<A>(),
        );
        assert!(
            via_from.is_empty(),
            "AxisHistogram::from([] as [(A, usize); 0]) must be is_empty on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_from_singleton_pair_one_equals_singleton_cell<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The singleton-pair-one bridging law: for every cell of the
        // axis, the arity-1 pair-array literal `[(cell, 1)]` at count 1
        // reads the same histogram as the singleton-cell constructor
        // `AxisHistogram::from(cell)`, as the arity-1 raw-observation
        // array `AxisHistogram::from([cell])`, as
        // `iter::once(cell).collect()`, and as the open-coded `empty +
        // observe(cell)` lowering. The pair-input entry surface meets
        // the raw-observation entry surface at the singleton boundary —
        // five pointwise-equal lowerings of the same one-observation
        // projection across both entry surfaces. Pinned uniformly across
        // every closed-axis implementor so a future axis primitive
        // inherits the bridging law at no per-axis cost.
        for observed in axis_iter::<A>() {
            let via_pair_array: AxisHistogram<A> = AxisHistogram::from([(observed, 1usize)]);
            let via_cell: AxisHistogram<A> = AxisHistogram::from(observed);
            let via_cell_array: AxisHistogram<A> = AxisHistogram::from([observed]);
            let via_iter_once: AxisHistogram<A> = std::iter::once(observed).collect();
            assert_eq!(
                via_pair_array,
                via_cell,
                "AxisHistogram::from([(cell, 1)]) must equal AxisHistogram::from(cell) \
                 on {observed:?} for axis {}",
                std::any::type_name::<A>(),
            );
            assert_eq!(
                via_pair_array,
                via_cell_array,
                "AxisHistogram::from([(cell, 1)]) must equal AxisHistogram::from([cell]) \
                 on {observed:?} for axis {}",
                std::any::type_name::<A>(),
            );
            assert_eq!(
                via_pair_array,
                via_iter_once,
                "AxisHistogram::from([(cell, 1)]) must equal iter::once(cell).collect() \
                 on {observed:?} for axis {}",
                std::any::type_name::<A>(),
            );
            assert_eq!(
                via_pair_array.total(),
                1,
                "AxisHistogram::from([(cell, 1)]).total() must equal 1 on axis {}",
                std::any::type_name::<A>(),
            );
            assert_eq!(
                via_pair_array.count(observed),
                1,
                "AxisHistogram::from([(cell, 1)]) must observe the lifted cell on {observed:?}",
            );
        }
    }

    fn assert_from_zero_count_pair_equals_empty<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The zero-count pair-array constructor law: for every cell of
        // the axis, the arity-1 pair-array literal `[(cell, 0)]` reads
        // the same all-zero state as `AxisHistogram::empty()`. A pair
        // with count zero is the additive identity on its cell at the
        // constructor rung, peer of the `Extend<(A, usize)>` zero-count
        // law on the in-place fold surface. Pinned over every cell of
        // the axis so the identity reads off at every ordinal.
        let via_empty: AxisHistogram<A> = AxisHistogram::empty();
        for observed in axis_iter::<A>() {
            let via_zero_pair: AxisHistogram<A> = AxisHistogram::from([(observed, 0usize)]);
            assert_eq!(
                via_zero_pair,
                via_empty,
                "AxisHistogram::from([(cell, 0)]) must equal AxisHistogram::empty() \
                 on {observed:?} for axis {}",
                std::any::type_name::<A>(),
            );
            assert_eq!(
                via_zero_pair.total(),
                0,
                "AxisHistogram::from([(cell, 0)]).total() must equal 0 on {observed:?} \
                 for axis {}",
                std::any::type_name::<A>(),
            );
            assert!(
                via_zero_pair.is_empty(),
                "AxisHistogram::from([(cell, 0)]) must be is_empty on {observed:?} \
                 for axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    #[test]
    fn axis_histogram_from_empty_pair_array_equals_empty_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_from_empty_pair_array_equals_empty::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_from_singleton_pair_one_equals_singleton_cell_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_from_singleton_pair_one_equals_singleton_cell::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_from_zero_count_pair_equals_empty_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_from_zero_count_pair_equals_empty::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_from_pair_array_constructs_pointwise_histogram_for_diff_line_kind() {
        // Concrete pin of the `From<[(A, usize); N]>` pair-input array
        // constructor on [`DiffLineKind`] at arity 3 — the trait-
        // uniform laws above cover the arity-0 (empty), arity-1 at
        // count 1 (singleton-bridge), and arity-1 at count 0 (zero-
        // count) rungs uniformly across every closed axis; this test
        // pins the higher-arity multi-cell semantics at one site so the
        // constructor's per-pair `+= count` behavior is readable on a
        // concrete axis. The pair-array literal lowers to the same
        // per-pair fold the [`FromIterator<(A, usize)>`] impl drives,
        // so the four canonical surfaces (`AxisHistogram::from([(c, n), …])`,
        // `[(c, n), …].into()`, `[(c, n), …].into_iter().collect()`,
        // the open-coded `let mut h = empty(); h.extend([(c, n), …]); h`
        // form) are pinned here as four pointwise-equal lowerings of
        // the same (pair-array → histogram) projection.
        let via_from = AxisHistogram::from([
            (DiffLineKind::Added, 12),
            (DiffLineKind::Removed, 4),
            (DiffLineKind::Context, 53),
        ]);
        let via_into: AxisHistogram<DiffLineKind> = [
            (DiffLineKind::Added, 12),
            (DiffLineKind::Removed, 4),
            (DiffLineKind::Context, 53),
        ]
        .into();
        let via_into_iter_collect: AxisHistogram<DiffLineKind> = [
            (DiffLineKind::Added, 12),
            (DiffLineKind::Removed, 4),
            (DiffLineKind::Context, 53),
        ]
        .into_iter()
        .collect();
        let via_extend = {
            let mut h: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
            h.extend([
                (DiffLineKind::Added, 12),
                (DiffLineKind::Removed, 4),
                (DiffLineKind::Context, 53),
            ]);
            h
        };
        assert_eq!(via_from, via_into);
        assert_eq!(via_from, via_into_iter_collect);
        assert_eq!(via_from, via_extend);
        assert_eq!(via_from.count(DiffLineKind::Added), 12);
        assert_eq!(via_from.count(DiffLineKind::Removed), 4);
        assert_eq!(via_from.count(DiffLineKind::Context), 53);
        assert_eq!(via_from.total(), 69);
        assert!(!via_from.is_empty());
        assert_eq!(via_from.dominant_cell(), Some(DiffLineKind::Context));
    }

    #[test]
    fn axis_histogram_from_pair_array_is_additive_on_repeated_cells_for_diff_line_kind() {
        // Concrete pin of the pair-input array constructor's cell-
        // additive behavior on [`DiffLineKind`]: when the literal
        // contains the same cell multiple times as `(cell, n1), …,
        // (cell, nk)`, the resulting histogram reads `n1 + … + nk` at
        // that cell — the natural composition the histogram's monoid
        // `(usize, +, 0)` per cell carries, salient asymmetry with
        // [`HashMap::from`]'s last-wins semantics. Pinned over a mix
        // of repeated and unique cells so both the additive and the
        // single-entry rungs read off the concrete histogram.
        let via_from = AxisHistogram::from([
            (DiffLineKind::Added, 2),
            (DiffLineKind::Added, 3),
            (DiffLineKind::Added, 5),
            (DiffLineKind::Removed, 1),
        ]);
        // Cell-additive: 2 + 3 + 5 == 10 on Added.
        assert_eq!(via_from.count(DiffLineKind::Added), 10);
        assert_eq!(via_from.count(DiffLineKind::Removed), 1);
        assert_eq!(via_from.count(DiffLineKind::Context), 0);
        // Total-equals-pair-sum law: 2 + 3 + 5 + 1 == 11.
        assert_eq!(via_from.total(), 11);
        assert_eq!(via_from.dominant_cell(), Some(DiffLineKind::Added));
    }

    #[test]
    fn axis_histogram_from_pair_array_equals_observe_expansion_for_diff_line_kind() {
        // The pair-input array constructor expansion-equivalence on
        // the per-cell surface: building from `[(cell, n), …]` is
        // pointwise equal to building from the expanded raw-
        // observation stream `iter::repeat(cell).take(n)` chained
        // across pairs. The lift replaces the O(total) re-expansion
        // every consumer used to open-code with an O(distinct cells)
        // single-pass fold at the constructor rung; this pin reads
        // the equivalence at one named site over a non-trivial pair
        // mix so a future regression on either side surfaces here.
        let pairs: [(DiffLineKind, usize); 3] = [
            (DiffLineKind::Added, 12),
            (DiffLineKind::Removed, 4),
            (DiffLineKind::Context, 53),
        ];

        let via_from_array = AxisHistogram::from(pairs);

        let via_expansion: AxisHistogram<DiffLineKind> = pairs
            .iter()
            .copied()
            .flat_map(|(c, n)| std::iter::repeat_n(c, n))
            .collect();

        assert_eq!(via_from_array, via_expansion);
    }

    // ---- AxisHistogram IntoIterator (&Self / Self) trait-uniform laws ----
    //
    // Five trait-uniform laws reach every [`ClosedAxis`] implementor through
    // [`for_each_closed_axis_implementor`] so the per-axis [`IntoIterator`]
    // projection's contract holds uniformly without per-axis test
    // duplication: borrowed [`IntoIterator`] equals [`AxisHistogram::iter`]
    // pointwise; owned [`IntoIterator`] equals the borrowed form pointwise;
    // the iterator's length equals [`axis_cardinality::<A>()`][axis_cardinality]
    // ([`ExactSizeIterator`]); the iterator round-trips through
    // [`DoubleEndedIterator::next_back`] / [`Iterator::rev`]; the iterator
    // yields the cells in declaration order over [`ClosedAxis::ALL`].
    //
    // Together with the existing [`FromIterator<A>`] / [`Extend<A>`] / [`Sum`]
    // / [`Add`] / [`AddAssign`] impl test sites, this closes the canonical
    // Rust collection-iteration trait surface on [`AxisHistogram`] at the
    // same trait peerage every stdlib collection carries
    // ([`std::vec::Vec`], [`std::collections::HashMap`],
    // [`std::collections::BTreeMap`], …): [`FromIterator`] in /
    // [`IntoIterator`] out, with named iterator types
    // ([`AxisHistogramIter`] borrowed, [`AxisHistogramIntoIter`] owned)
    // alongside the [`AxisHistogram::iter`] inherent.

    fn assert_into_iter_ref_equals_iter<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Pointwise equality between the two surfaces every stdlib
        // collection carries: `(&hist).into_iter().collect()` equals
        // `hist.iter().collect()`, by construction (both walk the counts
        // vector in declaration order zipped with `A::ALL`). Pinned over a
        // double-axis-cover histogram so every cell carries a positive
        // count and the per-pair equality reads off every ordinal.
        let hist: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        let via_iter: Vec<(A, usize)> = hist.iter().collect();
        let via_into_iter: Vec<(A, usize)> = (&hist).into_iter().collect();
        assert_eq!(
            via_iter,
            via_into_iter,
            "IntoIterator<&Self> must equal iter() pointwise on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_into_iter_owned_equals_iter<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Pointwise equality between the consuming and borrowing surfaces:
        // `hist.into_iter().collect()` equals `hist.iter().collect()` on
        // every histogram. The two walk the counts vector at different
        // ownership polarities (the consuming form owns the vector
        // directly through `std::vec::IntoIter`; the borrowing form holds
        // a `std::slice::Iter` reference) and yield the same `(A, usize)`
        // pair sequence by construction.
        let hist: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        let via_iter: Vec<(A, usize)> = hist.iter().collect();
        let via_into_iter: Vec<(A, usize)> = hist.into_iter().collect();
        assert_eq!(
            via_iter,
            via_into_iter,
            "IntoIterator<Self> must equal iter() pointwise on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_into_iter_ref_length_equals_axis_cardinality<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The [`ExactSizeIterator`] contract on the borrowing iterator:
        // the iterator's `len()` equals [`axis_cardinality::<A>()`] before
        // any element is consumed (the full-axis scan, not just the
        // support). Pinned on the empty histogram so the count is
        // independent of any observation (the axis-cover form below pins
        // the orthogonal observation-independence direction).
        let hist = AxisHistogram::<A>::empty();
        let iter = (&hist).into_iter();
        assert_eq!(
            iter.len(),
            axis_cardinality::<A>(),
            "IntoIterator<&Self>::len must equal axis_cardinality on axis {}",
            std::any::type_name::<A>(),
        );
        let collected: Vec<(A, usize)> = (&hist).into_iter().collect();
        assert_eq!(
            collected.len(),
            axis_cardinality::<A>(),
            "IntoIterator<&Self> must yield axis_cardinality pairs on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_into_iter_ref_yields_cells_in_declaration_order<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The declaration-order contract: dropping the counts from the
        // pair sequence yields the same cell sequence as
        // [`axis_iter::<A>()`][axis_iter] pointwise. The (`IntoIterator`,
        // `axis_iter`) alignment on the cell-only axis: the histogram's
        // iteration order is the axis's declaration order, period.
        let hist: AxisHistogram<A> = axis_iter::<A>().collect();
        let cells: Vec<A> = (&hist).into_iter().map(|(v, _)| v).collect();
        let expected: Vec<A> = axis_iter::<A>().collect();
        assert_eq!(
            cells,
            expected,
            "IntoIterator<&Self> cells must agree with axis_iter on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_into_iter_ref_double_ended_round_trips<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The [`DoubleEndedIterator`] contract: collecting through `.rev()`
        // and reversing the result recovers the forward sequence pointwise
        // (the two ends agree). Pins that `next_back` reads the same
        // `(A, usize)` pair the forward iteration would read at the
        // corresponding position from the tail.
        let hist: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        let forward: Vec<(A, usize)> = (&hist).into_iter().collect();
        let mut backward: Vec<(A, usize)> = (&hist).into_iter().rev().collect();
        backward.reverse();
        assert_eq!(
            forward,
            backward,
            "IntoIterator<&Self>::rev must round-trip pointwise on axis {}",
            std::any::type_name::<A>(),
        );
    }

    #[test]
    fn axis_histogram_into_iter_ref_equals_iter_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_into_iter_ref_equals_iter::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_into_iter_owned_equals_iter_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_into_iter_owned_equals_iter::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_into_iter_ref_length_equals_axis_cardinality_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_into_iter_ref_length_equals_axis_cardinality::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_into_iter_ref_yields_cells_in_declaration_order_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_into_iter_ref_yields_cells_in_declaration_order::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_into_iter_ref_double_ended_round_trips_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_into_iter_ref_double_ended_round_trips::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_for_loop_ref_yields_pairs_for_diff_line_kind() {
        // Concrete pin at the canonical Rust call-site shape — the
        // `for pair in &hist { … }` borrowed-collection idiom every stdlib
        // collection consumer reaches for. Pinned on a non-trivial
        // observation mix on [`DiffLineKind`] so the per-cell counts are
        // visible at the call site and a future regression in the
        // [`IntoIterator`] impl (e.g. one that drops a cell, scrambles
        // declaration order, or yields the wrong pair shape) surfaces
        // here at one named site.
        let hist: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
        ]
        .into_iter()
        .collect();

        let mut pairs: Vec<(DiffLineKind, usize)> = Vec::new();
        for pair in &hist {
            pairs.push(pair);
        }

        // The borrowed [`IntoIterator`] surface yields the same pair
        // sequence as the [`AxisHistogram::iter`] inherent — by
        // construction (both walk the counts vector in declaration order).
        let via_iter: Vec<(DiffLineKind, usize)> = hist.iter().collect();
        assert_eq!(pairs, via_iter);

        // Cell-level accounting on the pair sequence: declaration order
        // is [Removed, Added, Context]; the histogram has Added=2,
        // Removed=1, Context=0.
        assert_eq!(
            pairs,
            vec![
                (DiffLineKind::Removed, 1),
                (DiffLineKind::Added, 2),
                (DiffLineKind::Context, 0),
            ],
        );
    }

    #[test]
    fn axis_histogram_owned_into_iter_yields_pairs_for_diff_line_kind() {
        // Concrete pin on the consuming [`IntoIterator`] surface — the
        // `hist.into_iter().collect()` idiom every stdlib collection
        // consumer reaches for when the histogram is no longer needed
        // after the iteration. The owned form moves the counts vector
        // into `std::vec::IntoIter` (no per-element clone, no `&hist`
        // borrow held for the duration of the loop).
        let hist: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Context,
            DiffLineKind::Added,
            DiffLineKind::Added,
        ]
        .into_iter()
        .collect();
        let snapshot: Vec<(DiffLineKind, usize)> = hist.iter().collect();

        let consumed: Vec<(DiffLineKind, usize)> = hist.into_iter().collect();
        assert_eq!(consumed, snapshot);
        assert_eq!(
            consumed,
            vec![
                (DiffLineKind::Removed, 0),
                (DiffLineKind::Added, 2),
                (DiffLineKind::Context, 1),
            ],
        );
    }

    // ---- AxisHistogram::iter_mut + IntoIterator<&mut Self> trait-uniform laws ----
    //
    // Six trait-uniform laws reach every [`ClosedAxis`] implementor through
    // [`for_each_closed_axis_implementor`] so the canonical Rust stdlib
    // `iter_mut()` / `IntoIterator for &mut Self` mutable-iteration surface
    // is pinned uniformly across every axis-cube primitive without per-axis
    // test duplication: the `iter_mut` length equals
    // [`axis_cardinality::<A>()`]; the yielded cell sequence agrees with
    // [`axis_iter`] pointwise; per-cell zero-out through the mutable
    // reference yields the empty histogram; per-cell doubling through
    // `*c *= 2` agrees with [`std::ops::MulAssign<usize>::mul_assign`] by
    // factor 2 on every cell; [`DoubleEndedIterator`] round-trips
    // (collect-then-reverse equals forward); the `for pair in &mut hist`
    // borrowed-collection idiom (`IntoIterator for &mut Self`) is
    // pointwise-equivalent to [`AxisHistogram::iter_mut`] on every
    // histogram.

    fn assert_iter_mut_length_equals_axis_cardinality<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The [`ExactSizeIterator`] contract on the mutable borrowing
        // iterator: the iterator's `len()` equals
        // [`axis_cardinality::<A>()`] before any element is consumed (the
        // full-axis scan, not just the support). Pinned on the empty
        // histogram so the count is independent of any observation —
        // the iteration covers the full axis, including the zero-count
        // cells whose `&mut 0` slots a per-cell remap can write to.
        let mut hist = AxisHistogram::<A>::empty();
        let len = hist.iter_mut().len();
        assert_eq!(
            len,
            axis_cardinality::<A>(),
            "iter_mut::len must equal axis_cardinality on axis {}",
            std::any::type_name::<A>(),
        );
        let collected: Vec<(A, &mut usize)> = hist.iter_mut().collect();
        assert_eq!(
            collected.len(),
            axis_cardinality::<A>(),
            "iter_mut must yield axis_cardinality pairs on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_iter_mut_yields_cells_in_declaration_order<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The declaration-order contract on the mutable surface: dropping
        // the count-slot from the pair sequence yields the same cell
        // sequence as [`axis_iter::<A>()`][axis_iter] pointwise. The
        // (`iter_mut`, `axis_iter`) alignment on the cell-only axis:
        // the histogram's mutable iteration order is the axis's
        // declaration order, period — peer to the same law on
        // [`AxisHistogram::iter`].
        let mut hist: AxisHistogram<A> = axis_iter::<A>().collect();
        let cells: Vec<A> = hist.iter_mut().map(|(v, _)| v).collect();
        let expected: Vec<A> = axis_iter::<A>().collect();
        assert_eq!(
            cells,
            expected,
            "iter_mut cells must agree with axis_iter on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_iter_mut_zero_assignment_equals_empty<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The in-place mutation contract on the mutable surface: writing
        // `0` through every yielded `&mut usize` slot zeros every cell of
        // the histogram pointwise, leaving a histogram equal to
        // [`AxisHistogram::empty`]. The canonical assignment-through-
        // `iter_mut` idiom every stdlib mutable-iterator consumer reaches
        // for (`for c in vec.iter_mut() { *c = 0; }` for a slice; the same
        // shape on the per-cell count slot here).
        let mut hist: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        hist.iter_mut().for_each(|(_, c)| *c = 0);
        assert_eq!(
            hist,
            AxisHistogram::<A>::empty(),
            "iter_mut zero-assignment must yield empty on axis {}",
            std::any::type_name::<A>(),
        );
        assert!(
            hist.is_empty(),
            "iter_mut zero-assignment must satisfy is_empty on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_iter_mut_double_equals_mul_assign_two<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The cellwise-mutation equivalence with the scalar-action
        // surface: writing `*c *= 2` through every yielded `&mut usize`
        // slot agrees with [`std::ops::MulAssign<usize>::mul_assign`] by
        // factor 2 on every cell, pointwise. Pins that the mutable
        // iteration surface lowers through the same `self.counts` vector
        // the in-place scalar-action surface lowers through — the two
        // routes to the same arithmetic agree by construction.
        let mut via_iter_mut: AxisHistogram<A> = axis_iter::<A>().collect();
        let mut via_mul_assign = via_iter_mut.clone();
        via_iter_mut.iter_mut().for_each(|(_, c)| *c *= 2);
        via_mul_assign *= 2usize;
        assert_eq!(
            via_iter_mut,
            via_mul_assign,
            "iter_mut *= 2 must equal MulAssign<usize> by 2 on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_iter_mut_double_ended_round_trips<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The [`DoubleEndedIterator`] contract on the mutable surface:
        // dropping the mutable slot and collecting through `.rev()` then
        // reversing the result recovers the forward cell sequence
        // pointwise (the two ends agree on cell identity). Pins that
        // `next_back` reads the same `A` cell the forward iteration
        // would read at the corresponding position from the tail —
        // peer to the same law on [`AxisHistogramIter`] /
        // [`AxisHistogramIntoIter`].
        let mut hist: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        let forward: Vec<A> = hist.iter_mut().map(|(v, _)| v).collect();
        let mut backward: Vec<A> = {
            let mut iter = hist.iter_mut();
            let mut buf = Vec::new();
            while let Some((v, _)) = iter.next_back() {
                buf.push(v);
            }
            buf
        };
        backward.reverse();
        assert_eq!(
            forward,
            backward,
            "iter_mut next_back must round-trip pointwise on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_into_iter_mut_equals_iter_mut<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Pointwise equality between the two entry shapes every stdlib
        // collection carries on the mutable side: `(&mut hist)
        // .into_iter()` collects the same cell sequence as
        // `hist.iter_mut()`. The (`IntoIterator<&mut Self>`, `iter_mut`)
        // duality on the mutably-borrowed-collection surface; the two
        // are alternate spellings of the same per-cell mutable scan over
        // [`ClosedAxis::ALL`]. Compared on the cell axis only because
        // the mutable slots can't be aliased — collecting the count
        // values once on each side and comparing them, peer to the
        // `(IntoIterator<&Self>, iter)` duality test above.
        let mut via_iter_mut: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        let mut via_into_iter_mut = via_iter_mut.clone();
        let via_iter_mut_pairs: Vec<(A, usize)> = via_iter_mut
            .iter_mut()
            .map(|(cell, c)| (cell, *c))
            .collect();
        let via_into_iter_mut_pairs: Vec<(A, usize)> = (&mut via_into_iter_mut)
            .into_iter()
            .map(|(cell, c)| (cell, *c))
            .collect();
        assert_eq!(
            via_iter_mut_pairs,
            via_into_iter_mut_pairs,
            "IntoIterator<&mut Self> must equal iter_mut pointwise on axis {}",
            std::any::type_name::<A>(),
        );
    }

    #[test]
    fn axis_histogram_iter_mut_length_equals_axis_cardinality_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_iter_mut_length_equals_axis_cardinality::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_iter_mut_yields_cells_in_declaration_order_for_every_closed_axis_implementor()
    {
        macro_rules! check {
            ($ty:ident) => {
                assert_iter_mut_yields_cells_in_declaration_order::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_iter_mut_zero_assignment_equals_empty_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_iter_mut_zero_assignment_equals_empty::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_iter_mut_double_equals_mul_assign_two_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_iter_mut_double_equals_mul_assign_two::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_iter_mut_double_ended_round_trips_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_iter_mut_double_ended_round_trips::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_into_iter_mut_equals_iter_mut_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_into_iter_mut_equals_iter_mut::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_iter_mut_per_cell_remap_for_diff_line_kind() {
        // Concrete pin on the cellwise-mutation surface the `iter_mut`
        // lift opens — a *per-cell* remap that depends on the cell
        // identity, the projection the uniform-scalar [`MulAssign<usize>`]
        // surface explicitly cannot reach (which multiplies every cell
        // by the same factor). The canonical call-site shape: walk the
        // histogram once, apply a per-cell factor to each `&mut usize`
        // slot in place, no rebuild through [`FromIterator<(A, usize)>`].
        // The factor table here weights Added by 3 (a downstream fan-out
        // amplifier), Removed by 5 (a quarantine cost), Context by 0 (a
        // dropped-from-summary projection) — three distinct factors,
        // unreachable through any uniform scalar-action surface.
        let mut hist: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Context,
            DiffLineKind::Context,
            DiffLineKind::Context,
        ]
        .into_iter()
        .collect();

        // Snapshot the pre-remap counts so the per-cell factor application
        // pins both the before and after sides of the equality (no hidden
        // dependence on a re-computed pre-state).
        let before = hist.clone();
        assert_eq!(before.count(DiffLineKind::Added), 2);
        assert_eq!(before.count(DiffLineKind::Removed), 1);
        assert_eq!(before.count(DiffLineKind::Context), 3);

        // The per-cell remap walks the histogram once through
        // [`iter_mut`], reading the cell identity and writing the new
        // count through the `&mut usize` slot in place.
        hist.iter_mut().for_each(|(cell, c)| {
            let factor = match cell {
                DiffLineKind::Added => 3,
                DiffLineKind::Removed => 5,
                DiffLineKind::Context => 0,
            };
            *c *= factor;
        });

        // Post-remap counts: Added = 2 * 3 = 6, Removed = 1 * 5 = 5,
        // Context = 3 * 0 = 0 (the dropped cell). The total is the sum.
        assert_eq!(hist.count(DiffLineKind::Added), 6);
        assert_eq!(hist.count(DiffLineKind::Removed), 5);
        assert_eq!(hist.count(DiffLineKind::Context), 0);
        assert_eq!(hist.total(), 11);

        // Support cardinality drops from 3 (all three cells observed
        // pre-remap) to 2 (Context dropped to zero post-remap) — the
        // per-cell zero-factor cell collapses the support, the per-cell
        // analog of the [`MulAssign<usize>`] zero-factor absorbing law on
        // the uniform-scalar surface but localized to one cell rather
        // than every cell.
        assert_eq!(before.distinct_cells(), 3);
        assert_eq!(hist.distinct_cells(), 2);
    }

    #[test]
    fn axis_histogram_iter_mut_for_loop_for_diff_line_kind() {
        // Concrete pin at the canonical Rust call-site shape — the
        // `for pair in &mut hist { … }` borrowed-collection idiom every
        // stdlib mutable-iteration consumer reaches for, peer to the
        // `for pair in &hist` shape pinned on the borrowing
        // [`IntoIterator`] surface above. Pins that the
        // [`IntoIterator<&mut Self>`] impl lowers to the same per-cell
        // mutable scan as the inherent [`iter_mut`] surface, reaching
        // the same `(A, &mut usize)` item shape and the same
        // declaration order over [`ClosedAxis::ALL`].
        let mut hist: AxisHistogram<DiffLineKind> = [DiffLineKind::Added, DiffLineKind::Removed]
            .into_iter()
            .collect();

        // Bump every cell by one through the `for pair in &mut hist`
        // shape — the canonical Rust borrowed-collection mutable idiom.
        // The full-axis iteration touches every cell (including
        // Context's zero count), so post-loop every cell carries
        // pre-count + 1.
        for (_, c) in &mut hist {
            *c += 1;
        }

        assert_eq!(hist.count(DiffLineKind::Added), 2);
        assert_eq!(hist.count(DiffLineKind::Removed), 2);
        assert_eq!(hist.count(DiffLineKind::Context), 1);
        assert_eq!(hist.total(), 5);

        // Cell-set agreement: after the +=1 pass every cell is observed
        // (the +1 lifts Context's zero count into the support). The
        // (`for pair in &mut hist`, `iter_mut`) duality is pointwise
        // equal — both walk the counts vector in declaration order.
        assert_eq!(hist.distinct_cells(), axis_cardinality::<DiffLineKind>());
        assert!(hist.is_full_cover());
    }

    // ---- AxisHistogram::Index<A> trait-uniform laws ----
    //
    // Four trait-uniform laws reach every [`ClosedAxis`] implementor through
    // [`for_each_closed_axis_implementor`] so the per-axis [`Index`]
    // projection's contract holds uniformly without per-axis test
    // duplication: the empty histogram reads zero on every cell; indexing
    // equals the [`AxisHistogram::count`] inherent peer on every cell;
    // observing a cell increments its indexed read by exactly one; the
    // total scalar equals the sum of indexed reads over the axis cover.

    fn assert_index_empty_is_zero<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The empty-histogram boundary on the [`Index`] surface — every
        // cell reads zero through `hist[cell]`, peer to the
        // `assert_empty_histogram_is_zero_on_every_cell` law on the
        // inherent [`AxisHistogram::count`] surface.
        let hist = AxisHistogram::<A>::empty();
        for value in axis_iter::<A>() {
            assert_eq!(
                hist[value],
                0,
                "empty histogram hist[{value:?}] must be 0 on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_index_equals_count<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Pointwise equality between the operator surface ([`Index`]) and
        // the inherent surface ([`AxisHistogram::count`]) on every cell:
        // `hist[cell] == hist.count(cell)`. Pinned over a non-trivial
        // observation mix (axis-cover repeated twice, so every cell
        // carries a positive count and the equality reads off every
        // ordinal).
        let hist: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for value in axis_iter::<A>() {
            assert_eq!(
                hist[value],
                hist.count(value),
                "hist[{value:?}] must equal hist.count({value:?}) on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_index_after_observe_increments<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Observing a cell once increments the indexed read on that cell
        // by exactly one (and leaves every other cell's indexed read
        // unchanged). The observation/index-surface peer of the
        // count-side invariant `observe(v); count(v) == prev + 1`.
        for observed in axis_iter::<A>() {
            let mut hist: AxisHistogram<A> = axis_iter::<A>().collect();
            let snapshot: Vec<usize> = axis_iter::<A>().map(|v| hist[v]).collect();
            hist.observe(observed);
            for (i, cell) in axis_iter::<A>().enumerate() {
                let expected = snapshot[i] + usize::from(cell == observed);
                assert_eq!(
                    hist[cell],
                    expected,
                    "after observing {observed:?}: hist[{cell:?}] must be {expected} on axis {}",
                    std::any::type_name::<A>(),
                );
            }
        }
    }

    fn assert_index_sum_over_axis_equals_total<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Summing the indexed reads over the full axis cover equals
        // [`AxisHistogram::total`] — the (lookup-surface, scalar-surface)
        // peer law on the [`Index`] surface, structurally equivalent to
        // the `total = sum(counts)` invariant the inherent surface
        // already carries.
        let hist: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        let sum_via_index: usize = axis_iter::<A>().map(|v| hist[v]).sum();
        assert_eq!(
            sum_via_index,
            hist.total(),
            "sum of hist[v] over axis_iter must equal hist.total() on axis {}",
            std::any::type_name::<A>(),
        );
    }

    #[test]
    fn axis_histogram_index_empty_is_zero_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_index_empty_is_zero::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_index_equals_count_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_index_equals_count::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_index_after_observe_increments_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_index_after_observe_increments::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_index_sum_over_axis_equals_total_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_index_sum_over_axis_equals_total::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_index_reads_per_cell_counts_for_diff_line_kind() {
        // Concrete pin at the canonical Rust call-site shape on the
        // operator surface — `hist[cell]` reads the per-cell count
        // directly, peer of `vec[i]` / `map[&k]` / `slice[i]` on the
        // stdlib collection-lookup surface. Pinned on a non-trivial
        // observation mix on [`DiffLineKind`] so the per-cell counts
        // read off at named call sites and a future regression in the
        // [`Index`] impl (e.g. one that mis-orders the underlying
        // counts vector, returns the wrong slot, or panics on a valid
        // cell) surfaces here.
        let hist: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
        ]
        .into_iter()
        .collect();

        // Per-cell counts read through the operator surface — the
        // canonical stdlib-collection-lookup idiom.
        assert_eq!(hist[DiffLineKind::Added], 2);
        assert_eq!(hist[DiffLineKind::Removed], 1);
        assert_eq!(hist[DiffLineKind::Context], 0);

        // (Index, count) pointwise equivalence on every cell — the
        // operator-surface ↔ inherent-method peerage at the named
        // call site.
        for cell in axis_iter::<DiffLineKind>() {
            assert_eq!(hist[cell], hist.count(cell));
        }

        // Summing indexed reads over the axis cover equals total —
        // the lookup-surface ↔ scalar-surface peerage at the named
        // call site (3 = 2 + 1 + 0).
        let total_via_index: usize = axis_iter::<DiffLineKind>().map(|v| hist[v]).sum();
        assert_eq!(total_via_index, hist.total());
        assert_eq!(total_via_index, 3);
    }

    #[test]
    fn axis_histogram_index_pairs_with_into_iter_for_diff_line_kind() {
        // Concrete pin at the (Index, IntoIterator) duality the stdlib
        // collection surface carries: every pair `(cell, count)` from
        // `&hist` agrees with the indexed read `hist[cell]` at every
        // step. The canonical stdlib-collection round-trip:
        // `for (k, v) in &map { assert_eq!(map[&k], v); }` peer on the
        // [`AxisHistogram`] surface.
        let hist: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Context,
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Removed,
            DiffLineKind::Removed,
        ]
        .into_iter()
        .collect();

        for (cell, count) in &hist {
            assert_eq!(
                hist[cell], count,
                "Index/IntoIterator duality must hold on {cell:?}",
            );
        }

        // The exact per-cell counts at named call sites.
        assert_eq!(hist[DiffLineKind::Removed], 3);
        assert_eq!(hist[DiffLineKind::Added], 2);
        assert_eq!(hist[DiffLineKind::Context], 1);
    }

    // ---- AxisHistogram::IndexMut (operator-surface mutation) trait-uniform laws ----
    //
    // Four trait-uniform laws reach every [`ClosedAxis`] implementor through
    // [`for_each_closed_axis_implementor`] so the per-axis [`IndexMut`]
    // projection's contract holds uniformly without per-axis test duplication:
    // writing through `hist[cell] = n;` round-trips through the [`Index`]
    // read on the same cell; `hist[cell] += 1;` agrees pointwise with
    // [`Self::observe`]; `hist[cell] = 0;` zeroes exactly the targeted cell
    // and leaves every other cell unchanged; `hist[cell] *= 2;` on every
    // cell agrees pointwise with the global [`MulAssign<usize>`][std::ops::MulAssign]
    // scalar action on the histogram.

    fn assert_index_mut_write_round_trips_through_index<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The canonical write-then-read round-trip on every cell:
        // after `hist[cell] = n;` both the operator surface
        // (`hist[cell]`) and the inherent surface ([`Self::count`])
        // observe `n` on that cell. Pinned over the full axis cover
        // (every cell hit at least once) and a non-trivial per-cell
        // mix (`ordinal + 1`) so cells don't accidentally collide on
        // the same count.
        let mut hist = AxisHistogram::<A>::empty();
        for (i, cell) in axis_iter::<A>().enumerate() {
            hist[cell] = i + 1;
        }
        for (i, cell) in axis_iter::<A>().enumerate() {
            assert_eq!(
                hist[cell],
                i + 1,
                "IndexMut write must round-trip through Index on cell {cell:?} on axis {}",
                std::any::type_name::<A>(),
            );
            assert_eq!(
                hist.count(cell),
                i + 1,
                "IndexMut write must round-trip through count() on cell {cell:?} on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_index_mut_add_assign_equals_observe<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The (`IndexMut`, `observe`) duality: `hist[cell] += 1;`
        // through the operator surface is pointwise equivalent to
        // `hist.observe(cell);` through the inherent observation
        // method. Pinned by replaying the same observation stream
        // through both surfaces and asserting cellwise equality on
        // every cell of the axis. The operator-surface peer of the
        // (`Index`, `count`) read-side duality.
        let observations: Vec<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        let mut via_observe = AxisHistogram::<A>::empty();
        let mut via_index_mut = AxisHistogram::<A>::empty();
        for v in &observations {
            via_observe.observe(*v);
            via_index_mut[*v] += 1;
        }
        for cell in axis_iter::<A>() {
            assert_eq!(
                via_index_mut[cell],
                via_observe[cell],
                "`hist[cell] += 1` must agree with `hist.observe(cell)` on cell {cell:?} on axis {}",
                std::any::type_name::<A>(),
            );
        }
        assert_eq!(
            via_index_mut,
            via_observe,
            "`hist[cell] += 1` must equal `hist.observe(cell)` histogram-wise on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_index_mut_zero_resets_single_cell<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Cell-local reset law: `hist[cell] = 0;` zeroes exactly the
        // targeted cell and leaves every other cell pointwise unchanged.
        // The single-cell peer of [`Self::empty`] (which zeros every
        // cell). Pinned by walking every cell as the reset target and
        // asserting (target zero, others unchanged) at every step.
        for target in axis_iter::<A>() {
            let base: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
            let mut hist = base.clone();
            hist[target] = 0;
            for cell in axis_iter::<A>() {
                let expected = if cell == target { 0 } else { base[cell] };
                assert_eq!(
                    hist[cell],
                    expected,
                    "`hist[{target:?}] = 0` must leave cell {cell:?} at {expected} on axis {}",
                    std::any::type_name::<A>(),
                );
            }
        }
    }

    fn assert_index_mut_mul_assign_matches_mul_assign_usize<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The cell-local form of the scalar-action law: doubling every
        // cell through the operator surface (`for v in axis_iter() {
        // hist[v] *= 2; }`) agrees pointwise with the global
        // [`MulAssign<usize>`][std::ops::MulAssign] surface
        // (`hist *= 2;`). The (`IndexMut`, `MulAssign<usize>`)
        // peerage on the operator surface — cell-local doubling
        // re-enacts global doubling cell by cell.
        let base: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        let mut via_cellwise = base.clone();
        for v in axis_iter::<A>() {
            via_cellwise[v] *= 2;
        }
        let mut via_global = base.clone();
        via_global *= 2;
        assert_eq!(
            via_cellwise,
            via_global,
            "cellwise doubling through IndexMut must agree with `hist *= 2` on axis {}",
            std::any::type_name::<A>(),
        );
    }

    #[test]
    fn axis_histogram_index_mut_write_round_trips_through_index_for_every_closed_axis_implementor()
    {
        macro_rules! check {
            ($ty:ident) => {
                assert_index_mut_write_round_trips_through_index::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_index_mut_add_assign_equals_observe_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_index_mut_add_assign_equals_observe::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_index_mut_zero_resets_single_cell_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_index_mut_zero_resets_single_cell::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_index_mut_mul_assign_matches_mul_assign_usize_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_index_mut_mul_assign_matches_mul_assign_usize::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_index_mut_supports_compound_assignments_for_diff_line_kind() {
        // Concrete pin at the canonical Rust call-site shapes on the
        // operator-surface mutation form — `hist[cell] = n;`,
        // `hist[cell] += k;`, `hist[cell] -= k;`, `hist[cell] *= k;`.
        // Every shape every Rust reader already knows from `Vec` /
        // `HashMap` reads off on the [`AxisHistogram`] surface.
        let mut hist = AxisHistogram::<DiffLineKind>::empty();

        // Plain assignment seeds the cells at named call sites.
        hist[DiffLineKind::Added] = 5;
        hist[DiffLineKind::Removed] = 3;
        hist[DiffLineKind::Context] = 1;
        assert_eq!(hist[DiffLineKind::Added], 5);
        assert_eq!(hist[DiffLineKind::Removed], 3);
        assert_eq!(hist[DiffLineKind::Context], 1);
        assert_eq!(hist.total(), 9);

        // `+=` on the operator surface compounds with prior writes.
        hist[DiffLineKind::Added] += 2;
        assert_eq!(hist[DiffLineKind::Added], 7);

        // `-=` on the operator surface removes counts at the cell —
        // the in-place inverse of `+=` on the cell-local surface.
        hist[DiffLineKind::Removed] -= 1;
        assert_eq!(hist[DiffLineKind::Removed], 2);

        // `*=` on the operator surface scales a single cell — the
        // cell-local form of the global `MulAssign<usize>` action.
        hist[DiffLineKind::Context] *= 4;
        assert_eq!(hist[DiffLineKind::Context], 4);

        // `= 0` resets exactly the targeted cell; the other cells
        // retain their prior counts.
        hist[DiffLineKind::Added] = 0;
        assert_eq!(hist[DiffLineKind::Added], 0);
        assert_eq!(hist[DiffLineKind::Removed], 2);
        assert_eq!(hist[DiffLineKind::Context], 4);

        // The total reads off the per-cell post-state through the
        // operator surface — every cell's contribution is the value
        // visible at `hist[cell]`.
        assert_eq!(hist.total(), 6);
    }

    // ---- AxisHistogram::sum (Sum<Self> / Sum<&Self>) trait-uniform laws ----
    //
    // Five trait-uniform laws reach every [`ClosedAxis`] implementor through
    // [`for_each_closed_axis_implementor`] so the per-axis [`Sum`] projection's
    // contract holds uniformly without per-axis test duplication: summing the
    // empty iterator is the monoid identity; summing a singleton iterator
    // recovers the element; summing grows the total additively; summing by
    // reference equals summing by value; summing equals the explicit
    // `fold(empty, merge)` the [`Sum`] impl lowers to.

    fn assert_sum_of_empty_iter_is_empty<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The empty-iterator law: `iter.sum()` on the empty iterator yields
        // the monoid identity (the empty histogram, the `fold` seed
        // untouched). Pinned on both `Sum<Self>` and `Sum<&Self>` so the
        // identity holds on both impls.
        let owned: AxisHistogram<A> = std::iter::empty::<AxisHistogram<A>>().sum();
        assert_eq!(
            owned,
            AxisHistogram::<A>::empty(),
            "Sum<Self> of empty iter must equal empty on axis {}",
            std::any::type_name::<A>(),
        );
        let pile: Vec<AxisHistogram<A>> = Vec::new();
        let via_refs: AxisHistogram<A> = pile.iter().sum();
        assert_eq!(
            via_refs,
            AxisHistogram::<A>::empty(),
            "Sum<&Self> of empty iter must equal empty on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_sum_of_singleton_iter_equals_inner<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The singleton law: summing a one-element iterator recovers the
        // element pointwise (the empty seed merged with the element is the
        // element, via the empty-identity law on `merge`). Pinned over the
        // axis-cover histogram so every cell carries a positive count and
        // the equality reads off every ordinal.
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        let owned: AxisHistogram<A> = std::iter::once(cover.clone()).sum();
        assert_eq!(
            owned,
            cover,
            "Sum<Self> of singleton must equal inner on axis {}",
            std::any::type_name::<A>(),
        );
        let pile = [cover.clone()];
        let via_refs: AxisHistogram<A> = pile.iter().sum();
        assert_eq!(
            via_refs,
            cover,
            "Sum<&Self> of singleton must equal inner on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_sum_grows_total_additively<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The additivity law on the [`Self::total`] scalar surface: the
        // summed histogram's total equals the sum of the components'
        // totals, peer to the `merge`-additivity law on `total`. Pinned
        // over three non-trivial components (the axis-cover, the
        // axis-cover-twice, and the empty) so the sum has a non-trivial
        // structure and the empty component witnesses the identity slot
        // inside the reduction.
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        let cover_twice: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        let empty = AxisHistogram::<A>::empty();
        let components = [cover.clone(), cover_twice.clone(), empty.clone()];
        let expected_total = cover.total() + cover_twice.total() + empty.total();

        let owned: AxisHistogram<A> = components.iter().cloned().sum();
        assert_eq!(
            owned.total(),
            expected_total,
            "Sum<Self> total must equal sum of component totals on axis {}",
            std::any::type_name::<A>(),
        );

        let via_refs: AxisHistogram<A> = components.iter().sum();
        assert_eq!(
            via_refs.total(),
            expected_total,
            "Sum<&Self> total must equal sum of component totals on axis {}",
            std::any::type_name::<A>(),
        );

        // Pointwise cell-level additivity: every cell of the summed
        // histogram equals the sum of the components' counts on that cell.
        for cell in axis_iter::<A>() {
            let expected_cell = cover.count(cell) + cover_twice.count(cell) + empty.count(cell);
            assert_eq!(
                via_refs.count(cell),
                expected_cell,
                "Sum<&Self> cell {cell:?} must equal sum of component counts on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_sum_of_refs_equals_sum_of_owned<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The (Sum<Self>, Sum<&Self>) idiom-peer equivalence: summing by
        // reference yields the same histogram as summing by value (i.e.
        // cloning the elements through the owned `Sum`). The canonical
        // Rust borrowed/owned `Sum` peer pair on a single monoid surface.
        // Pinned over the axis-cover and the singleton-on-the-first-cell
        // components so the equivalence covers a non-trivial cell-set.
        let mut components = vec![axis_iter::<A>().collect::<AxisHistogram<A>>()];
        if let Some(first) = axis_iter::<A>().next() {
            let mut single = AxisHistogram::<A>::empty();
            single.observe(first);
            components.push(single);
        }
        components.push(AxisHistogram::<A>::empty());

        let via_owned: AxisHistogram<A> = components.iter().cloned().sum();
        let via_refs: AxisHistogram<A> = components.iter().sum();
        assert_eq!(
            via_owned,
            via_refs,
            "Sum<Self> via cloned must equal Sum<&Self> on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_sum_owned_equals_explicit_fold<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The (Sum, fold) lowering equivalence: `iter.sum()` is pointwise
        // equal to `iter.fold(empty(), |acc, h| acc.merge(&h))` on every
        // iterator — the explicit lowering the [`Sum`] impl uses. A future
        // regression in the impl (e.g. one that loses the seed or
        // mis-orders the fold step) surfaces against this law uniformly.
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        let cover_twice: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        let components = [cover, cover_twice, AxisHistogram::<A>::empty()];

        let via_sum: AxisHistogram<A> = components.iter().cloned().sum();
        let via_fold: AxisHistogram<A> = components
            .iter()
            .cloned()
            .fold(AxisHistogram::<A>::empty(), |acc, h| acc.merge(&h));
        assert_eq!(
            via_sum,
            via_fold,
            "Sum<Self> must equal explicit fold(empty, merge) on axis {}",
            std::any::type_name::<A>(),
        );

        let via_sum_refs: AxisHistogram<A> = components.iter().sum();
        let via_fold_refs: AxisHistogram<A> = components
            .iter()
            .fold(AxisHistogram::<A>::empty(), AxisHistogram::merge);
        assert_eq!(
            via_sum_refs,
            via_fold_refs,
            "Sum<&Self> must equal explicit fold(empty, merge) on axis {}",
            std::any::type_name::<A>(),
        );
    }

    #[test]
    fn axis_histogram_sum_of_empty_iter_is_empty_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_sum_of_empty_iter_is_empty::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_sum_of_singleton_iter_equals_inner_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_sum_of_singleton_iter_equals_inner::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_sum_grows_total_additively_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_sum_grows_total_additively::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_sum_of_refs_equals_sum_of_owned_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_sum_of_refs_equals_sum_of_owned::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_sum_owned_equals_explicit_fold_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_sum_owned_equals_explicit_fold::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_sum_equals_fleet_aggregate_for_diff_line_kind() {
        // The (Sum, fleet-aggregate) equivalence on the canonical fleet-
        // aggregator pattern: collect per-window histograms, sum them via
        // `iter.sum()` — the result is pointwise equal to the histogram
        // built from the concatenation of every window's observations.
        // Pinned concretely on [`DiffLineKind`] across three non-trivial
        // windows so the equivalence covers a non-trivial cell distribution.
        let window_a: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
        ]
        .into_iter()
        .collect();
        let window_b: AxisHistogram<DiffLineKind> = [DiffLineKind::Context, DiffLineKind::Removed]
            .into_iter()
            .collect();
        let window_c: AxisHistogram<DiffLineKind> = std::iter::once(DiffLineKind::Added).collect();
        let windows = [window_a, window_b, window_c];

        let via_sum_refs: AxisHistogram<DiffLineKind> = windows.iter().sum();
        let via_sum_owned: AxisHistogram<DiffLineKind> = windows.iter().cloned().sum();

        // Added: 3 (2 from a, 0 from b, 1 from c); Removed: 2; Context: 1.
        assert_eq!(via_sum_refs.count(DiffLineKind::Added), 3);
        assert_eq!(via_sum_refs.count(DiffLineKind::Removed), 2);
        assert_eq!(via_sum_refs.count(DiffLineKind::Context), 1);
        assert_eq!(via_sum_refs.total(), 6);
        assert_eq!(via_sum_owned, via_sum_refs);
    }

    #[test]
    fn axis_histogram_sum_lowers_to_fold_for_diff_line_kind() {
        // Pin the canonical Rust lowering at a named site: `iter.sum()`
        // equals `iter.fold(empty(), |acc, h| acc.merge(&h))` on every
        // iterator, by definition. A future regression in the [`Sum`] impl
        // (e.g. one that drifts away from the `(empty seed, merge step)`
        // shape) surfaces against this pin.
        let inputs: [&[DiffLineKind]; 4] = [
            &[],
            &[DiffLineKind::Added],
            &[
                DiffLineKind::Added,
                DiffLineKind::Removed,
                DiffLineKind::Added,
            ],
            &[
                DiffLineKind::Context,
                DiffLineKind::Added,
                DiffLineKind::Removed,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
        ];
        let windows: Vec<AxisHistogram<DiffLineKind>> = inputs
            .iter()
            .map(|input| input.iter().copied().collect())
            .collect();

        let via_sum: AxisHistogram<DiffLineKind> = windows.iter().cloned().sum();
        let via_fold: AxisHistogram<DiffLineKind> = windows
            .iter()
            .cloned()
            .fold(AxisHistogram::empty(), |acc, h| acc.merge(&h));
        assert_eq!(via_sum, via_fold);

        let via_sum_refs: AxisHistogram<DiffLineKind> = windows.iter().sum();
        let via_fold_refs: AxisHistogram<DiffLineKind> = windows
            .iter()
            .fold(AxisHistogram::empty(), AxisHistogram::merge);
        assert_eq!(via_sum_refs, via_fold_refs);
    }

    // ---- AxisHistogram::{Add, AddAssign} operator-trait laws ----
    //
    // Six trait-uniform laws reach every [`ClosedAxis`] implementor through
    // [`for_each_closed_axis_implementor`] so the per-axis monoid-operator
    // projection's contract holds uniformly without per-axis test
    // duplication: `+= &empty` is identity; `+= &other` equals `merge`;
    // `+ &other` equals `merge`; `+=` is commutative on the resulting
    // histogram; `+=` grows the total additively; the owned and borrowed
    // operator surfaces produce the same histogram (the (Add<Self>,
    // Add<&Self>) / (AddAssign<Self>, AddAssign<&Self>) idiom-peer
    // equivalences).
    //
    // Together with the existing [`Sum`] laws above and the
    // [`Self::merge`] laws below, this closes the canonical Rust
    // monoid-operator trait surface — `Add<Self>`, `Add<&Self>`,
    // `AddAssign<Self>`, `AddAssign<&Self>`, `Sum<Self>`, `Sum<&Self>` —
    // on [`AxisHistogram`], at the same trait peerage every stdlib
    // numeric monoid carries (`u8..u128`, `i8..i128`, `f32`, `f64`,
    // `Duration`, `Wrapping<T>`, etc.).

    fn assert_add_assign_ref_empty_rhs_is_identity<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The empty-right-hand-side identity law on [`AddAssign<&Self>`]:
        // `hist += &empty` leaves the histogram unchanged. Peer to the
        // [`Self::merge`] empty-identity law on the in-place operator
        // surface. Pinned over the axis-cover histogram so every cell
        // carries a positive count and the equality reads off every
        // ordinal.
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        let mut acc = cover.clone();
        acc += &AxisHistogram::<A>::empty();
        assert_eq!(
            acc,
            cover,
            "hist += &empty must leave hist unchanged on axis {}",
            std::any::type_name::<A>(),
        );
        // The dual: starting from empty, `empty += &cover` reads off the
        // cover histogram pointwise — the right-empty / left-empty pair
        // closes the identity at both call sites.
        let mut empty = AxisHistogram::<A>::empty();
        empty += &cover;
        assert_eq!(
            empty,
            cover,
            "empty += &hist must equal hist on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_add_assign_ref_equals_merge<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The (AddAssign, merge) equivalence on the borrowed-RHS form:
        // `let mut a = lhs.clone(); a += &rhs; a` is pointwise equal to
        // `lhs.clone().merge(&rhs)`. The [`merge`][Self::merge] impl
        // lowers through `+=` so the equivalence is by construction; the
        // law pins the contract uniformly so a future regression in
        // either site (e.g. an inlined per-cell loop drifting out of
        // sync with the `+=` impl) surfaces against the law.
        let lhs: AxisHistogram<A> = axis_iter::<A>().collect();
        let rhs: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();

        let mut via_add_assign = lhs.clone();
        via_add_assign += &rhs;
        let via_merge = lhs.clone().merge(&rhs);
        assert_eq!(
            via_add_assign,
            via_merge,
            "AddAssign<&Self> must equal merge on axis {}",
            std::any::type_name::<A>(),
        );

        // The owned-RHS peer: same equivalence on `AddAssign<Self>`.
        let mut via_add_assign_owned = lhs.clone();
        via_add_assign_owned += rhs.clone();
        assert_eq!(
            via_add_assign_owned,
            via_merge,
            "AddAssign<Self> must equal merge on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_add_ref_equals_merge<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The (Add, merge) equivalence on the borrowed-RHS form:
        // `lhs + &rhs` is pointwise equal to `lhs.merge(&rhs)` on every
        // pair. The infix-operator peer of the in-place law above.
        let lhs: AxisHistogram<A> = axis_iter::<A>().collect();
        let rhs: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();

        let via_add = lhs.clone() + &rhs;
        let via_merge = lhs.clone().merge(&rhs);
        assert_eq!(
            via_add,
            via_merge,
            "Add<&Self> must equal merge on axis {}",
            std::any::type_name::<A>(),
        );

        // The owned-RHS peer: same equivalence on `Add<Self>`.
        let via_add_owned = lhs.clone() + rhs.clone();
        assert_eq!(
            via_add_owned,
            via_merge,
            "Add<Self> must equal merge on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_add_assign_ref_is_commutative<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Commutativity on the resulting histogram (not on the call
        // site): the in-place fold of `y` into `x` produces the same
        // histogram as the in-place fold of `x` into `y`, by the
        // commutativity of cellwise `+`. The call sites differ in which
        // histogram is mutated; the resulting histogram does not.
        // Pinned over two non-trivial histograms (the axis-cover and the
        // singleton-on-the-first-cell) so the equivalence covers a
        // non-trivial cell distribution.
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        let single = if let Some(first) = axis_iter::<A>().next() {
            let mut h = AxisHistogram::<A>::empty();
            h.observe(first);
            h
        } else {
            // No-op on the empty closed axis (no implementor today, but
            // the law is vacuous in that corner).
            return;
        };

        let mut a = cover.clone();
        a += &single;
        let mut b = single.clone();
        b += &cover;
        assert_eq!(
            a,
            b,
            "AddAssign<&Self> must produce the same histogram regardless of \
             which side is mutated on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_add_assign_ref_grows_total_additively<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The additivity law on the [`Self::total`] scalar surface:
        // `a += &b` grows `a.total()` by exactly `b.total()`, peer to
        // the `merge`-additivity law on `total`. Pinned over two non-
        // trivial histograms so the law witnesses a non-zero delta.
        let lhs: AxisHistogram<A> = axis_iter::<A>().collect();
        let rhs: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        let lhs_total_before = lhs.total();
        let rhs_total = rhs.total();

        let mut acc = lhs.clone();
        acc += &rhs;
        assert_eq!(
            acc.total(),
            lhs_total_before + rhs_total,
            "AddAssign<&Self> must grow total by rhs.total() on axis {}",
            std::any::type_name::<A>(),
        );

        // Pointwise cell-level additivity: every cell of the summed
        // histogram equals the sum of the components' counts on that cell.
        for cell in axis_iter::<A>() {
            assert_eq!(
                acc.count(cell),
                lhs.count(cell) + rhs.count(cell),
                "AddAssign<&Self> cell {cell:?} must equal lhs + rhs on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_add_owned_equals_add_ref<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The (Add<Self>, Add<&Self>) / (AddAssign<Self>, AddAssign<&Self>)
        // idiom-peer equivalences: the owned-RHS surface produces the
        // same histogram as the borrowed-RHS surface on every call site.
        // The canonical Rust owned/borrowed operator peer pair —
        // `impl Add<Self>` and `impl Add<&Self>` returning equal output
        // — every stdlib numeric monoid exposes (`u32 + &u32 == u32 +
        // u32`, etc.).
        let lhs: AxisHistogram<A> = axis_iter::<A>().collect();
        let rhs: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();

        let via_add_ref = lhs.clone() + &rhs;
        let via_add_owned = lhs.clone() + rhs.clone();
        assert_eq!(
            via_add_ref,
            via_add_owned,
            "Add<&Self> must equal Add<Self> on axis {}",
            std::any::type_name::<A>(),
        );

        let mut via_assign_ref = lhs.clone();
        via_assign_ref += &rhs;
        let mut via_assign_owned = lhs.clone();
        via_assign_owned += rhs.clone();
        assert_eq!(
            via_assign_ref,
            via_assign_owned,
            "AddAssign<&Self> must equal AddAssign<Self> on axis {}",
            std::any::type_name::<A>(),
        );
    }

    #[test]
    fn axis_histogram_add_assign_ref_empty_rhs_is_identity_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_add_assign_ref_empty_rhs_is_identity::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_add_assign_ref_equals_merge_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_add_assign_ref_equals_merge::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_add_ref_equals_merge_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_add_ref_equals_merge::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_add_assign_ref_is_commutative_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_add_assign_ref_is_commutative::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_add_assign_ref_grows_total_additively_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_add_assign_ref_grows_total_additively::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_add_owned_equals_add_ref_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_add_owned_equals_add_ref::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_add_assign_equals_fleet_aggregate_for_diff_line_kind() {
        // The canonical fleet-aggregator pattern on the in-place
        // operator surface: collect per-window histograms, fold them
        // into an accumulator via `acc += &window;` — the result is
        // pointwise equal to the histogram built from the
        // concatenation of every window's observations, and pointwise
        // equal to `windows.iter().sum()`. Pinned concretely on
        // [`DiffLineKind`] across three non-trivial windows so the
        // equivalence covers a non-trivial cell distribution.
        let window_a: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
        ]
        .into_iter()
        .collect();
        let window_b: AxisHistogram<DiffLineKind> = [DiffLineKind::Context, DiffLineKind::Removed]
            .into_iter()
            .collect();
        let window_c: AxisHistogram<DiffLineKind> = std::iter::once(DiffLineKind::Added).collect();
        let windows = [window_a.clone(), window_b.clone(), window_c.clone()];

        let mut via_add_assign: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
        for window in &windows {
            via_add_assign += window;
        }
        let via_sum: AxisHistogram<DiffLineKind> = windows.iter().sum();
        assert_eq!(via_add_assign, via_sum);

        // Added: 3 (2 from a, 0 from b, 1 from c); Removed: 2; Context: 1.
        assert_eq!(via_add_assign.count(DiffLineKind::Added), 3);
        assert_eq!(via_add_assign.count(DiffLineKind::Removed), 2);
        assert_eq!(via_add_assign.count(DiffLineKind::Context), 1);
        assert_eq!(via_add_assign.total(), 6);
    }

    #[test]
    fn axis_histogram_add_chain_equals_merge_chain_for_diff_line_kind() {
        // The infix-operator chain `a + &b + &c` is pointwise equal to
        // `a.merge(&b).merge(&c)` on the merge chain — the (Add, merge)
        // equivalence composed across multiple right-hand sides. Pinned
        // concretely on [`DiffLineKind`] across three windows so the
        // equivalence covers a non-trivial cell distribution and the
        // associativity-via-`+` form reads off at the call site.
        let a: AxisHistogram<DiffLineKind> = [DiffLineKind::Added].into_iter().collect();
        let b: AxisHistogram<DiffLineKind> = [DiffLineKind::Added, DiffLineKind::Removed]
            .into_iter()
            .collect();
        let c: AxisHistogram<DiffLineKind> = std::iter::once(DiffLineKind::Context).collect();

        let via_add = a.clone() + &b + &c;
        let via_merge = a.clone().merge(&b).merge(&c);
        assert_eq!(via_add, via_merge);

        assert_eq!(via_add.count(DiffLineKind::Added), 2);
        assert_eq!(via_add.count(DiffLineKind::Removed), 1);
        assert_eq!(via_add.count(DiffLineKind::Context), 1);
        assert_eq!(via_add.total(), 4);
    }

    // ---- AxisHistogram saturating-subtraction trait-uniform laws ----
    //
    // The (Sub<Self>, Sub<&Self>, SubAssign<Self>, SubAssign<&Self>)
    // saturating-subtraction operator quartet closes the additive
    // operator quartet on the AxisHistogram surface: the
    // (Add, AddAssign) quartet for the cellwise sum and the
    // (Sub, SubAssign) quartet for the cellwise saturating difference,
    // pin one consistent natural-number monus algebra `(ℕ, +, ∸)` on
    // the histogram. The trait-uniform laws below pin the saturation
    // contract uniformly across every [`ClosedAxis`] implementor:
    // empty-RHS is identity; self-subtraction collapses to empty;
    // saturation at zero (subtracting a larger histogram bottoms out
    // at empty, no underflow); the round-trip with [`AddAssign`]
    // (`a += &b; a -= &b;` recovers `a` when no cell overflows on the
    // intermediate sum); per-cell saturation matches
    // [`usize::saturating_sub`] cell by cell; the (Sub, SubAssign)
    // owned/borrowed surfaces agree on the resulting histogram.

    fn assert_sub_assign_ref_empty_rhs_is_identity<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The empty-right-hand-side identity law on [`SubAssign<&Self>`]:
        // `hist -= &empty` leaves the histogram unchanged. Peer to the
        // [`AddAssign`] empty-RHS-identity law on the dual side of the
        // monus monoid. Pinned over the axis-cover histogram so every
        // cell carries a positive count and the equality reads off every
        // ordinal.
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        let mut acc = cover.clone();
        acc -= &AxisHistogram::<A>::empty();
        assert_eq!(
            acc,
            cover,
            "hist -= &empty must leave hist unchanged on axis {}",
            std::any::type_name::<A>(),
        );
        // The dual: subtracting any histogram from empty saturates to
        // empty. The (empty, ∸) absorbing law on the left-empty side —
        // there is no "below zero" cell for the difference to land in.
        let mut empty = AxisHistogram::<A>::empty();
        empty -= &cover;
        assert_eq!(
            empty,
            AxisHistogram::<A>::empty(),
            "empty -= &hist must remain empty on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_sub_assign_ref_self_yields_empty<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The self-subtraction absorbing law on [`SubAssign<&Self>`]:
        // `let mut a = hist.clone(); a -= &hist;` zeros every cell of
        // `a`, pointwise equal to [`AxisHistogram::empty`]. The monus
        // self-cancellation law — every natural number minus itself is
        // zero. Pinned over the axis-cover histogram so every cell
        // starts positive and the collapse-to-zero reads off every
        // ordinal.
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        let mut acc = cover.clone();
        acc -= &cover;
        assert_eq!(
            acc,
            AxisHistogram::<A>::empty(),
            "hist -= &hist must equal AxisHistogram::empty() on axis {}",
            std::any::type_name::<A>(),
        );
        assert_eq!(
            acc.total(),
            0,
            "hist -= &hist must zero the total on axis {}",
            std::any::type_name::<A>(),
        );
        assert!(
            acc.is_empty(),
            "hist -= &hist must satisfy is_empty on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_sub_assign_ref_saturates_at_zero<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The saturation-at-zero law on [`SubAssign<&Self>`]: subtracting
        // a histogram whose every cell dominates `self`'s cell bottoms
        // out at empty without underflow. Pinned by subtracting a
        // doubled axis-cover (every cell = 2) from a single axis-cover
        // (every cell = 1) — every cell saturates at zero, no debug-
        // panic, no release-wrap.
        let single: AxisHistogram<A> = axis_iter::<A>().collect();
        let double: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        let mut acc = single.clone();
        acc -= &double;
        assert_eq!(
            acc,
            AxisHistogram::<A>::empty(),
            "small -= &large must saturate to empty on axis {}",
            std::any::type_name::<A>(),
        );
        // Every cell is exactly zero — peer to the per-cell saturation
        // contract on [`usize::saturating_sub`].
        for cell in axis_iter::<A>() {
            assert_eq!(
                acc.count(cell),
                0,
                "saturated sub cell {cell:?} must be 0 on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_sub_assign_ref_is_inverse_of_add_assign_ref<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The (AddAssign, SubAssign) round-trip law on the borrowed-RHS
        // form: `let mut a = lhs.clone(); a += &rhs; a -= &rhs;` is
        // pointwise equal to `lhs`, provided no cell of the
        // intermediate sum overflows. The (+=, -=) inverse-pair law on
        // the monus monoid wherever the addition stays within
        // [`usize::MAX`] — pins the fleet-aggregator round-trip "fold
        // in host then back it out" projection. Pinned over the
        // axis-cover and a doubled cover so the round-trip exercises a
        // non-trivial cell distribution on both sides.
        let lhs: AxisHistogram<A> = axis_iter::<A>().collect();
        let rhs: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        let mut round = lhs.clone();
        round += &rhs;
        round -= &rhs;
        assert_eq!(
            round,
            lhs,
            "AddAssign-then-SubAssign on the same rhs must recover lhs on axis {}",
            std::any::type_name::<A>(),
        );
        // The dual order also recovers `lhs` whenever the SubAssign
        // does not saturate (here every cell of `rhs ≥ 0` ≤ every cell
        // of `lhs + rhs`, so the round-trip lands on `lhs` regardless
        // of order).
        let mut round_other = lhs.clone();
        round_other += &rhs;
        let mut also = round_other.clone();
        also -= &rhs;
        assert_eq!(
            also,
            lhs,
            "round-trip (any order) must recover lhs on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_sub_assign_ref_cell_level_saturates<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The cell-level saturation contract: every cell `v` of
        // `after = before -= &other` satisfies `after.count(v) ==
        // before.count(v).saturating_sub(other.count(v))`. Pinned by
        // subtracting a doubled-cover (cell = 2 everywhere) from a
        // triple-cover (cell = 3 everywhere) — every cell saturates at
        // exactly 1 (the [`usize::saturating_sub`] result on every
        // ordinal), and the total shrinks by exactly the sum of
        // per-cell saturated deltas.
        let triple: AxisHistogram<A> = axis_iter::<A>()
            .chain(axis_iter::<A>())
            .chain(axis_iter::<A>())
            .collect();
        let double: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        let mut acc = triple.clone();
        acc -= &double;
        for cell in axis_iter::<A>() {
            let expected = triple.count(cell).saturating_sub(double.count(cell));
            assert_eq!(
                acc.count(cell),
                expected,
                "cell {cell:?} must equal saturating_sub on axis {}",
                std::any::type_name::<A>(),
            );
        }
        // Total-shrinking law: the total never grows under subtraction,
        // and the shrink amount is bounded above by `other.total()`.
        assert!(
            acc.total() <= triple.total(),
            "total must not grow under SubAssign on axis {}",
            std::any::type_name::<A>(),
        );
        assert_eq!(
            triple.total() - acc.total(),
            double.total(),
            "total shrink must equal rhs.total() when no cell saturates on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_sub_owned_equals_sub_ref<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The (Sub<Self>, Sub<&Self>) / (SubAssign<Self>,
        // SubAssign<&Self>) idiom-peer equivalences: the owned-RHS
        // surface produces the same histogram as the borrowed-RHS
        // surface on every call site. The canonical Rust owned/borrowed
        // operator peer pair — `impl Sub<Self>` and `impl Sub<&Self>`
        // returning equal output — every stdlib numeric type exposes.
        let lhs: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        let rhs: AxisHistogram<A> = axis_iter::<A>().collect();

        let via_sub_ref = lhs.clone() - &rhs;
        let via_sub_owned = lhs.clone() - rhs.clone();
        assert_eq!(
            via_sub_ref,
            via_sub_owned,
            "Sub<&Self> must equal Sub<Self> on axis {}",
            std::any::type_name::<A>(),
        );

        let mut via_assign_ref = lhs.clone();
        via_assign_ref -= &rhs;
        let mut via_assign_owned = lhs.clone();
        via_assign_owned -= rhs.clone();
        assert_eq!(
            via_assign_ref,
            via_assign_owned,
            "SubAssign<&Self> must equal SubAssign<Self> on axis {}",
            std::any::type_name::<A>(),
        );
        // The (Sub, SubAssign) duality on the operator surface: the
        // infix-operator form agrees with the in-place form, peer to
        // the (Add, AddAssign) duality already pinned.
        assert_eq!(
            via_sub_ref,
            via_assign_ref,
            "Sub<&Self> must equal SubAssign<&Self>-then-return on axis {}",
            std::any::type_name::<A>(),
        );
    }

    #[test]
    fn axis_histogram_sub_assign_ref_empty_rhs_is_identity_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_sub_assign_ref_empty_rhs_is_identity::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_sub_assign_ref_self_yields_empty_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_sub_assign_ref_self_yields_empty::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_sub_assign_ref_saturates_at_zero_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_sub_assign_ref_saturates_at_zero::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_sub_assign_ref_is_inverse_of_add_assign_ref_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_sub_assign_ref_is_inverse_of_add_assign_ref::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_sub_assign_ref_cell_level_saturates_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_sub_assign_ref_cell_level_saturates::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_sub_owned_equals_sub_ref_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_sub_owned_equals_sub_ref::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_sub_assign_host_leaves_fleet_round_trip_for_diff_line_kind() {
        // The canonical fleet-aggregator round-trip on the subtraction
        // operator surface: a per-host histogram folded into the fleet
        // via `fleet += &host` is backed out by `fleet -= &host` so the
        // fleet histogram retains only the surviving hosts' observations.
        // Pinned concretely on [`DiffLineKind`] across three hosts so
        // the back-out covers a non-trivial cell distribution.
        let host_a: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
        ]
        .into_iter()
        .collect();
        let host_b: AxisHistogram<DiffLineKind> = [DiffLineKind::Context, DiffLineKind::Removed]
            .into_iter()
            .collect();
        let host_c: AxisHistogram<DiffLineKind> = std::iter::once(DiffLineKind::Added).collect();

        let mut fleet: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
        fleet += &host_a;
        fleet += &host_b;
        fleet += &host_c;

        // host_b leaves the fleet — the fleet shrinks to host_a + host_c.
        fleet -= &host_b;

        let expected: AxisHistogram<DiffLineKind> = host_a.clone() + &host_c;
        assert_eq!(fleet, expected);

        // host_a is the (2, 1, 0); host_c is (1, 0, 0); together
        // (Added: 3, Removed: 1, Context: 0).
        assert_eq!(fleet.count(DiffLineKind::Added), 3);
        assert_eq!(fleet.count(DiffLineKind::Removed), 1);
        assert_eq!(fleet.count(DiffLineKind::Context), 0);
        assert_eq!(fleet.total(), 4);
    }

    #[test]
    fn axis_histogram_sub_assign_saturates_per_cell_for_diff_line_kind() {
        // Concrete pin on the per-cell saturation contract: a histogram
        // with one cell smaller than the right-hand side saturates that
        // cell at zero while the other cells subtract normally. Pinned
        // on [`DiffLineKind`] where Removed: 1 - 3 saturates at 0 while
        // Added: 5 - 2 reads 3 and Context: 0 - 1 saturates at 0.
        let lhs: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
        ]
        .into_iter()
        .collect();
        let rhs: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Removed,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ]
        .into_iter()
        .collect();

        let mut diff = lhs.clone();
        diff -= &rhs;

        // Added: 5 - 2 = 3; Removed: 1 - 3 saturates at 0;
        // Context: 0 - 1 saturates at 0.
        assert_eq!(diff.count(DiffLineKind::Added), 3);
        assert_eq!(diff.count(DiffLineKind::Removed), 0);
        assert_eq!(diff.count(DiffLineKind::Context), 0);
        assert_eq!(diff.total(), 3);

        // Pin the per-cell relation to `usize::saturating_sub` explicitly.
        for &cell in DiffLineKind::ALL {
            assert_eq!(
                diff.count(cell),
                lhs.count(cell).saturating_sub(rhs.count(cell)),
            );
        }

        // Non-commutativity: `rhs - &lhs` reads off a different
        // histogram (the dual cellwise positive part).
        let mut reverse = rhs.clone();
        reverse -= &lhs;
        // Added: 2 - 5 = 0; Removed: 3 - 1 = 2; Context: 1 - 0 = 1.
        assert_eq!(reverse.count(DiffLineKind::Added), 0);
        assert_eq!(reverse.count(DiffLineKind::Removed), 2);
        assert_eq!(reverse.count(DiffLineKind::Context), 1);
        assert_ne!(diff, reverse);
    }

    // ---- AxisHistogram cellwise-lattice trait-uniform laws ----
    //
    // The (pointwise_max, pointwise_min) lattice surface lifts the
    // bounded distributive lattice `(meet, join, leq)` from THEORY.md
    // §III.3 onto the per-cell observation count, peer to the lattice
    // algebra pleme-io's compliance dimension already runs on. The
    // trait-uniform laws below pin the lattice axioms uniformly across
    // every [`ClosedAxis`] implementor: `empty` is the bottom (identity
    // for max, absorbing for min); both ops are idempotent and
    // commutative; the cell-level relation matches
    // [`std::cmp::max`] / [`std::cmp::min`] cell by cell; the absorption
    // law on the (max, min) pair holds (the canonical distributive-
    // lattice law); the lattice / additive identity
    // `pointwise_max + pointwise_min == a + b` reads off pointwise (the
    // cellwise `max(x,y) + min(x,y) = x + y` law); pointwise dominance
    // bounds (`max >= each side`, `min <= each side`) hold on every
    // cell. The lattice surface complements the additive monoid quartet
    // `(Add, AddAssign, Sub, SubAssign)` already pinned: addition
    // stacks observations, the lattice operations take the cellwise
    // envelope (max) or floor (min).

    fn assert_pointwise_max_empty_rhs_is_identity<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // `empty` is the bottom on the lattice join: `hist
        // .pointwise_max(&empty) == hist` and `empty.pointwise_max(&hist)
        // == hist`. Every cell of `empty` is zero, so the cellwise max
        // never lowers any cell of `hist`. Peer to the [`AddAssign`]
        // empty-RHS-identity law on the dual side of the additive
        // monoid. Pinned over the axis-cover histogram so every cell
        // carries a positive count and the equality reads off every
        // ordinal.
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        let joined_right = cover.clone().pointwise_max(&AxisHistogram::<A>::empty());
        assert_eq!(
            joined_right,
            cover,
            "hist.pointwise_max(&empty) must equal hist on axis {}",
            std::any::type_name::<A>(),
        );
        let joined_left = AxisHistogram::<A>::empty().pointwise_max(&cover);
        assert_eq!(
            joined_left,
            cover,
            "empty.pointwise_max(&hist) must equal hist on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_pointwise_min_empty_rhs_is_empty<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // `empty` is the bottom on the lattice meet (absorbing): `hist
        // .pointwise_min(&empty) == empty` and `empty.pointwise_min(&hist)
        // == empty`. Every cell of `empty` is zero, so the cellwise min
        // collapses every cell to zero. Peer to the [`SubAssign`]
        // (empty, ∸) absorbing law on the left-empty side of the monus
        // monoid. Pinned over the axis-cover histogram so every cell
        // starts positive and the collapse-to-zero reads off every
        // ordinal.
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        let met_right = cover.clone().pointwise_min(&AxisHistogram::<A>::empty());
        assert_eq!(
            met_right,
            AxisHistogram::<A>::empty(),
            "hist.pointwise_min(&empty) must equal empty on axis {}",
            std::any::type_name::<A>(),
        );
        let met_left = AxisHistogram::<A>::empty().pointwise_min(&cover);
        assert_eq!(
            met_left,
            AxisHistogram::<A>::empty(),
            "empty.pointwise_min(&hist) must equal empty on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_pointwise_max_and_min_idempotent<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The canonical lattice idempotence laws: `hist
        // .pointwise_max(&hist) == hist` and `hist.pointwise_min(&hist)
        // == hist`. Every cell is its own max/min with itself. Pinned
        // over the doubled axis-cover so every cell carries a positive
        // count > 1 (the count distribution is non-trivial across
        // ordinals).
        let cover: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        let joined = cover.clone().pointwise_max(&cover);
        assert_eq!(
            joined,
            cover,
            "hist.pointwise_max(&hist) must equal hist on axis {}",
            std::any::type_name::<A>(),
        );
        let met = cover.clone().pointwise_min(&cover);
        assert_eq!(
            met,
            cover,
            "hist.pointwise_min(&hist) must equal hist on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_pointwise_max_and_min_are_commutative<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The canonical lattice commutativity laws: `a.pointwise_max(&b)
        // == b.pointwise_max(&a)` and `a.pointwise_min(&b) ==
        // b.pointwise_min(&a)` on the resulting histogram. Peer to the
        // commutativity of cellwise `+` from the [`AddAssign`] surface.
        // Pinned over the axis-cover (every cell = 1) and a doubled
        // first-cell (so the count distribution differs cell by cell).
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        let skewed = if let Some(first) = axis_iter::<A>().next() {
            let mut h: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
            h.observe(first);
            h
        } else {
            return;
        };

        let lhs_max = cover.clone().pointwise_max(&skewed);
        let rhs_max = skewed.clone().pointwise_max(&cover);
        assert_eq!(
            lhs_max,
            rhs_max,
            "pointwise_max must be commutative on axis {}",
            std::any::type_name::<A>(),
        );

        let lhs_min = cover.clone().pointwise_min(&skewed);
        let rhs_min = skewed.clone().pointwise_min(&cover);
        assert_eq!(
            lhs_min,
            rhs_min,
            "pointwise_min must be commutative on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_pointwise_max_and_min_cell_level<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The cell-level relation: every cell `v` of `joined =
        // a.pointwise_max(&b)` satisfies `joined.count(v) ==
        // a.count(v).max(b.count(v))`, and the dual on
        // `pointwise_min`. The defining property of the cellwise
        // lattice — peer to the cellwise-`+` law on `AddAssign` and the
        // cellwise-`saturating_sub` law on `SubAssign`. Pinned over the
        // axis-cover (every cell = 1) and a doubled cover (every cell =
        // 2) — the max reads `2` on every cell, the min reads `1`.
        let single: AxisHistogram<A> = axis_iter::<A>().collect();
        let double: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();

        let joined = single.clone().pointwise_max(&double);
        let met = single.clone().pointwise_min(&double);
        for cell in axis_iter::<A>() {
            assert_eq!(
                joined.count(cell),
                single.count(cell).max(double.count(cell)),
                "pointwise_max cell {cell:?} must equal max on axis {}",
                std::any::type_name::<A>(),
            );
            assert_eq!(
                met.count(cell),
                single.count(cell).min(double.count(cell)),
                "pointwise_min cell {cell:?} must equal min on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_pointwise_max_dominates_and_min_dominated<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The pointwise dominance bounds: every cell of `pointwise_max(a,
        // b)` is `>=` the corresponding cell of `a` and of `b` (the
        // join is the supremum on the pointwise order), and every cell
        // of `pointwise_min(a, b)` is `<=` the corresponding cell of
        // `a` and of `b` (the meet is the infimum). Pinned over the
        // axis-cover and a doubled cover so the bounds witness non-
        // trivial inequalities cell by cell.
        let single: AxisHistogram<A> = axis_iter::<A>().collect();
        let double: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();

        let joined = single.clone().pointwise_max(&double);
        let met = single.clone().pointwise_min(&double);
        for cell in axis_iter::<A>() {
            assert!(
                joined.count(cell) >= single.count(cell)
                    && joined.count(cell) >= double.count(cell),
                "pointwise_max cell {cell:?} must dominate both sides on axis {}",
                std::any::type_name::<A>(),
            );
            assert!(
                met.count(cell) <= single.count(cell) && met.count(cell) <= double.count(cell),
                "pointwise_min cell {cell:?} must be dominated by both sides on axis {}",
                std::any::type_name::<A>(),
            );
        }
        // Total bounds derived from the cellwise dominance: max total
        // never shrinks below either side's total, min total never
        // exceeds either side's total.
        assert!(
            joined.total() >= single.total() && joined.total() >= double.total(),
            "pointwise_max total must dominate both sides on axis {}",
            std::any::type_name::<A>(),
        );
        assert!(
            met.total() <= single.total() && met.total() <= double.total(),
            "pointwise_min total must be dominated by both sides on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_pointwise_max_plus_min_equals_add<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The lattice / additive identity `max(x, y) + min(x, y) = x +
        // y` lifted cellwise: `a.pointwise_max(&b) + &a.pointwise_min(&b)
        // == a + &b` pointwise. The canonical decomposition tying the
        // (max, min) lattice to the (`+`) additive monoid — pins the
        // two algebras on the same histogram surface agree on the per-
        // cell decomposition. Pinned over the axis-cover and a doubled
        // cover so the equality witnesses a non-trivial cell
        // distribution.
        let lhs: AxisHistogram<A> = axis_iter::<A>().collect();
        let rhs: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();

        let joined = lhs.clone().pointwise_max(&rhs);
        let met = lhs.clone().pointwise_min(&rhs);
        let lattice_sum = joined.clone() + &met;
        let additive_sum = lhs.clone() + &rhs;
        assert_eq!(
            lattice_sum,
            additive_sum,
            "pointwise_max + pointwise_min must equal a + b on axis {}",
            std::any::type_name::<A>(),
        );
        // The peer identity on the totals: total(max) + total(min) =
        // total(a) + total(b).
        assert_eq!(
            joined.total() + met.total(),
            lhs.total() + rhs.total(),
            "pointwise_max.total + pointwise_min.total must equal a.total + b.total on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_pointwise_max_and_min_absorb<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The canonical distributive-lattice absorption laws: `a
        // .pointwise_max(&a.pointwise_min(&b)) == a` and `a
        // .pointwise_min(&a.pointwise_max(&b)) == a`. The histogram
        // surface satisfies the lattice axioms uniformly across every
        // closed axis. Pinned over the axis-cover and a doubled cover
        // so the absorption witnesses a non-trivial cell distribution.
        let a: AxisHistogram<A> = axis_iter::<A>().collect();
        let b: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();

        let absorbed_max = a.clone().pointwise_max(&a.clone().pointwise_min(&b));
        assert_eq!(
            absorbed_max,
            a,
            "a ∨ (a ∧ b) must equal a on axis {}",
            std::any::type_name::<A>(),
        );
        let absorbed_min = a.clone().pointwise_min(&a.clone().pointwise_max(&b));
        assert_eq!(
            absorbed_min,
            a,
            "a ∧ (a ∨ b) must equal a on axis {}",
            std::any::type_name::<A>(),
        );
    }

    #[test]
    fn axis_histogram_pointwise_max_empty_rhs_is_identity_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_pointwise_max_empty_rhs_is_identity::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_pointwise_min_empty_rhs_is_empty_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_pointwise_min_empty_rhs_is_empty::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_pointwise_max_and_min_idempotent_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_pointwise_max_and_min_idempotent::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_pointwise_max_and_min_are_commutative_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_pointwise_max_and_min_are_commutative::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_pointwise_max_and_min_cell_level_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_pointwise_max_and_min_cell_level::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_pointwise_max_dominates_and_min_dominated_for_every_closed_axis_implementor()
    {
        macro_rules! check {
            ($ty:ident) => {
                assert_pointwise_max_dominates_and_min_dominated::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_pointwise_max_plus_min_equals_add_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_pointwise_max_plus_min_equals_add::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_pointwise_max_and_min_absorb_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_pointwise_max_and_min_absorb::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_pointwise_max_per_cell_envelope_for_diff_line_kind() {
        // Concrete pin: a per-window observatory takes the cellwise
        // envelope across three windows so the resulting histogram
        // reads off the high-water mark per cell, not the cellwise
        // sum. The (Added: max(2, 0, 1) = 2, Removed: max(1, 1, 0) = 1,
        // Context: max(0, 1, 0) = 1) distribution is the envelope; the
        // cellwise sum (Added: 3, Removed: 2, Context: 1) reads
        // differently — pinning the difference between addition and
        // join on the histogram surface.
        let window_a: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
        ]
        .into_iter()
        .collect();
        let window_b: AxisHistogram<DiffLineKind> = [DiffLineKind::Context, DiffLineKind::Removed]
            .into_iter()
            .collect();
        let window_c: AxisHistogram<DiffLineKind> = std::iter::once(DiffLineKind::Added).collect();

        let envelope = window_a
            .clone()
            .pointwise_max(&window_b)
            .pointwise_max(&window_c);
        // Cellwise max across windows reads the high-water mark.
        assert_eq!(envelope.count(DiffLineKind::Added), 2);
        assert_eq!(envelope.count(DiffLineKind::Removed), 1);
        assert_eq!(envelope.count(DiffLineKind::Context), 1);
        assert_eq!(envelope.total(), 4);

        // The cellwise-sum projection differs: addition stacks
        // observations rather than taking the envelope.
        let stacked = window_a.clone() + &window_b + &window_c;
        assert_eq!(stacked.count(DiffLineKind::Added), 3);
        assert_eq!(stacked.count(DiffLineKind::Removed), 2);
        assert_eq!(stacked.count(DiffLineKind::Context), 1);
        assert_ne!(envelope, stacked);
    }

    #[test]
    fn axis_histogram_pointwise_min_per_cell_floor_for_diff_line_kind() {
        // Concrete pin on the cellwise floor / multiset-intersection
        // projection: the per-cell minimum across two histograms reads
        // off the count common to both — the (Added: min(5, 2) = 2,
        // Removed: min(1, 3) = 1, Context: min(0, 1) = 0)
        // distribution. The (max + min == a + b) lattice / additive
        // identity also reads off concretely:
        // max + min = (5,3,1) + (2,1,0) = (7,4,1) = (5,1,0) + (2,3,1) = a + b.
        let a: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
        ]
        .into_iter()
        .collect();
        let b: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Removed,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ]
        .into_iter()
        .collect();

        let floor = a.clone().pointwise_min(&b);
        // Cellwise min reads the common floor across both histograms.
        assert_eq!(floor.count(DiffLineKind::Added), 2);
        assert_eq!(floor.count(DiffLineKind::Removed), 1);
        assert_eq!(floor.count(DiffLineKind::Context), 0);
        assert_eq!(floor.total(), 3);

        let envelope = a.clone().pointwise_max(&b);
        assert_eq!(envelope.count(DiffLineKind::Added), 5);
        assert_eq!(envelope.count(DiffLineKind::Removed), 3);
        assert_eq!(envelope.count(DiffLineKind::Context), 1);
        assert_eq!(envelope.total(), 9);

        // The lattice / additive identity reads off concretely on the
        // (max + min == a + b) decomposition.
        let lattice_sum = envelope.clone() + &floor;
        let additive_sum = a.clone() + &b;
        assert_eq!(lattice_sum, additive_sum);
        assert_eq!(lattice_sum.total(), a.total() + b.total());
    }

    // ---- AxisHistogram pointwise-dominance partial-order laws ----
    //
    // The `(is_dominated_by, dominates)` predicate pair projects the
    // `leq` partial order from THEORY.md §III.3 onto the per-cell
    // observation count — the boolean idiom-peer of the
    // (pointwise_max, pointwise_min) lattice ops. Together
    // `(pointwise_max, pointwise_min, is_dominated_by)` closes the
    // `(join, meet, leq)` triple from §III.3 on the histogram surface.
    // The trait-uniform laws below pin the partial-order axioms
    // uniformly across every [`ClosedAxis`] implementor: reflexivity
    // (every histogram dominates itself); empty is the bottom (the
    // monoid identity sits at the lattice bottom); antisymmetry (two
    // histograms each dominating the other are equal); transitivity
    // (the relation chains pointwise); dual relation (`a.dominates(&b)
    // iff b.is_dominated_by(&a)`); join / meet characterizations of ≤
    // (the canonical lattice ↔ partial-order bridges); and the total
    // bound implication (pointwise ≤ implies the per-side total is
    // bounded above). The partial-order surface complements the
    // (pointwise_max, pointwise_min) lattice ops on the same
    // histogram surface — together they close `(join, meet, leq)`.

    fn assert_is_dominated_by_reflexive<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The canonical partial-order reflexivity law on the pointwise
        // dominance order: every histogram is `<=` itself cellwise, so
        // `hist.is_dominated_by(&hist)` reads `true` on every
        // implementor. The dual predicate `dominates` is reflexive on
        // the same shape. Pinned over the axis-cover histogram so
        // every cell carries a positive count and the per-cell
        // reflexivity reads off every ordinal — not the vacuous
        // empty-vs-empty case.
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        assert!(
            cover.is_dominated_by(&cover),
            "hist.is_dominated_by(&hist) must read true on axis {}",
            std::any::type_name::<A>(),
        );
        assert!(
            cover.dominates(&cover),
            "hist.dominates(&hist) must read true on axis {}",
            std::any::type_name::<A>(),
        );
        // The empty histogram is trivially self-dominated — the
        // identity sits at every partial-order endpoint.
        let empty: AxisHistogram<A> = AxisHistogram::empty();
        assert!(
            empty.is_dominated_by(&empty),
            "empty.is_dominated_by(&empty) must read true on axis {}",
            std::any::type_name::<A>(),
        );
        assert!(
            empty.dominates(&empty),
            "empty.dominates(&empty) must read true on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_empty_is_dominated_by_every<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Empty is the bottom on the pointwise dominance order: every
        // cell of `empty` is zero, so the cellwise `<=` reads `true`
        // on every ordinal against any histogram. Peer to the (empty,
        // max) identity / (empty, min) absorbing laws on the lattice —
        // pins the monoid identity sits at the bottom of the partial
        // order. Pinned over the axis-cover histogram so the relation
        // reads off the non-vacuous case where every cell is strictly
        // positive on the dominator side.
        let empty: AxisHistogram<A> = AxisHistogram::empty();
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        assert!(
            empty.is_dominated_by(&cover),
            "empty.is_dominated_by(&cover) must read true on axis {}",
            std::any::type_name::<A>(),
        );
        assert!(
            cover.dominates(&empty),
            "cover.dominates(&empty) must read true on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_is_dominated_by_antisymmetric<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The canonical partial-order antisymmetry law: `a
        // .is_dominated_by(&b) && b.is_dominated_by(&a) ⇒ a == b`.
        // Pointwise `<=` in both directions collapses to pointwise
        // equality, which the `Eq` derive picks up cell by cell. The
        // load-bearing law that distinguishes a partial order from
        // a pre-order. Pinned over two distinct constructions of the
        // axis-cover histogram so both directions of the implication
        // read off the same equality.
        let lhs: AxisHistogram<A> = axis_iter::<A>().collect();
        let rhs: AxisHistogram<A> = axis_iter::<A>().collect();
        assert!(lhs.is_dominated_by(&rhs));
        assert!(rhs.is_dominated_by(&lhs));
        assert_eq!(
            lhs,
            rhs,
            "antisymmetry: mutual dominance must imply equality on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_is_dominated_by_transitive<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The canonical partial-order transitivity law: `a
        // .is_dominated_by(&b) && b.is_dominated_by(&c) ⇒
        // a.is_dominated_by(&c)`. Lifted from the cellwise `<=`
        // transitivity. Pinned over the strict chain (empty ≤ cover
        // ≤ doubled cover) so every cell of the chain witnesses a
        // strict inequality on at least one ordinal and transitivity
        // reads off non-vacuously.
        let bottom: AxisHistogram<A> = AxisHistogram::empty();
        let middle: AxisHistogram<A> = axis_iter::<A>().collect();
        let top: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();

        assert!(bottom.is_dominated_by(&middle));
        assert!(middle.is_dominated_by(&top));
        assert!(
            bottom.is_dominated_by(&top),
            "transitivity: empty ≤ cover ≤ doubled cover must imply empty ≤ doubled cover on axis {}",
            std::any::type_name::<A>(),
        );
        // The dual chain on `dominates` reads off symmetrically.
        assert!(top.dominates(&middle));
        assert!(middle.dominates(&bottom));
        assert!(
            top.dominates(&bottom),
            "transitivity: doubled cover ≥ cover ≥ empty must imply doubled cover ≥ empty on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_dominates_is_dual_of_is_dominated_by<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The dual-relation law on the predicate pair:
        // `a.dominates(&b) == b.is_dominated_by(&a)` pointwise. Peer
        // to the (max, min) lattice-op duality. Pinned across the
        // bottom / middle / top chain so the dual relation reads off
        // on every pair of the chain (true on the dominated side,
        // mirrored on the dominator side).
        let bottom: AxisHistogram<A> = AxisHistogram::empty();
        let middle: AxisHistogram<A> = axis_iter::<A>().collect();
        let top: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for (lhs, rhs) in [
            (&bottom, &middle),
            (&bottom, &top),
            (&middle, &top),
            (&middle, &bottom),
            (&top, &bottom),
            (&top, &middle),
            (&middle, &middle),
        ] {
            assert_eq!(
                lhs.dominates(rhs),
                rhs.is_dominated_by(lhs),
                "dual: a.dominates(&b) must equal b.is_dominated_by(&a) on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_is_dominated_by_join_characterization<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The canonical "≤ iff `a ∨ b = b`" lattice law: `a
        // .is_dominated_by(&b) == (a.clone().pointwise_max(&b) == b)`.
        // Pins the partial order is the one the join is built on.
        // Pinned across the bottom / middle / top chain — the
        // characterization holds on every ordered pair (forward), and
        // on the equal-pair (vacuous). On the reversed pair (where
        // `is_dominated_by` reads `false`), the join is not equal to
        // the would-be-larger side — the characterization holds in the
        // negative direction too.
        let bottom: AxisHistogram<A> = AxisHistogram::empty();
        let middle: AxisHistogram<A> = axis_iter::<A>().collect();
        let top: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for (lhs, rhs) in [
            (&bottom, &middle),
            (&bottom, &top),
            (&middle, &top),
            (&middle, &middle),
            (&middle, &bottom),
            (&top, &middle),
        ] {
            let dominated = lhs.is_dominated_by(rhs);
            let joined = lhs.clone().pointwise_max(rhs);
            assert_eq!(
                dominated,
                joined == *rhs,
                "join characterization: a.is_dominated_by(&b) must equal (a ∨ b == b) on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_is_dominated_by_meet_characterization<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The canonical "≤ iff `a ∧ b = a`" lattice law (dual to the
        // join characterization on the meet side): `a
        // .is_dominated_by(&b) == (a.clone().pointwise_min(&b) == a)`.
        // Together with the join characterization, pins the partial
        // order is the one *both* lattice ops are built on. Pinned
        // across the same chain so the characterization reads off the
        // forward direction on the ordered pairs, the equal-pair
        // (vacuous), and the negative direction on the reversed pairs.
        let bottom: AxisHistogram<A> = AxisHistogram::empty();
        let middle: AxisHistogram<A> = axis_iter::<A>().collect();
        let top: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for (lhs, rhs) in [
            (&bottom, &middle),
            (&bottom, &top),
            (&middle, &top),
            (&middle, &middle),
            (&middle, &bottom),
            (&top, &middle),
        ] {
            let dominated = lhs.is_dominated_by(rhs);
            let met = lhs.clone().pointwise_min(rhs);
            assert_eq!(
                dominated,
                met == *lhs,
                "meet characterization: a.is_dominated_by(&b) must equal (a ∧ b == a) on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_is_dominated_by_implies_total_bound<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The total bound implication: `a.is_dominated_by(&b) ⇒
        // a.total() <= b.total()`. Pointwise `<=` is sum-monotone, so
        // the cellwise sum is bounded above by the dominator side.
        // The converse is *not* an iff — equal totals can occur on
        // lattice-incomparable histograms — but the forward direction
        // is a load-bearing bound on the per-side totals. Pinned
        // across the bottom / middle / top chain so the bound reads
        // off non-vacuously on the strict-chain pairs.
        let bottom: AxisHistogram<A> = AxisHistogram::empty();
        let middle: AxisHistogram<A> = axis_iter::<A>().collect();
        let top: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for (lhs, rhs) in [(&bottom, &middle), (&bottom, &top), (&middle, &top)] {
            assert!(lhs.is_dominated_by(rhs));
            assert!(
                lhs.total() <= rhs.total(),
                "total bound: a.is_dominated_by(&b) must imply a.total() <= b.total() on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    #[test]
    fn axis_histogram_is_dominated_by_reflexive_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_is_dominated_by_reflexive::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_empty_is_dominated_by_every_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_empty_is_dominated_by_every::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_is_dominated_by_antisymmetric_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_is_dominated_by_antisymmetric::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_is_dominated_by_transitive_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_is_dominated_by_transitive::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_dominates_is_dual_of_is_dominated_by_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_dominates_is_dual_of_is_dominated_by::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_is_dominated_by_join_characterization_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_is_dominated_by_join_characterization::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_is_dominated_by_meet_characterization_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_is_dominated_by_meet_characterization::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_is_dominated_by_total_bound_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_is_dominated_by_implies_total_bound::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_is_dominated_by_partial_order_is_partial_for_diff_line_kind() {
        // Concrete pin on the partiality of the pointwise dominance
        // order: two histograms can be lattice-incomparable when one
        // cell is strictly larger on each side. The (2, 1, 0) and
        // (1, 2, 0) shapes on [`DiffLineKind`] witness incomparability
        // — neither dominates the other, yet both have total 3. This
        // distinguishes the partial order on the histogram surface
        // from the total order [`Vec`]'s default lexicographic
        // `PartialOrd` would induce (lexicographic would always pick a
        // side); pins the histogram order is the lattice's partial
        // order from §III.3, not a lexicographic total order.
        //
        // [`DiffLineKind::ALL`] declaration order is
        // `[Removed, Added, Context]`.
        let lhs: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
        ]
        .into_iter()
        .collect();
        let rhs: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Removed,
            DiffLineKind::Removed,
            DiffLineKind::Added,
        ]
        .into_iter()
        .collect();

        // Per-cell distributions for the witnesses:
        // lhs: Removed=1, Added=2, Context=0; total=3.
        // rhs: Removed=2, Added=1, Context=0; total=3.
        assert_eq!(lhs.count(DiffLineKind::Removed), 1);
        assert_eq!(lhs.count(DiffLineKind::Added), 2);
        assert_eq!(lhs.count(DiffLineKind::Context), 0);
        assert_eq!(rhs.count(DiffLineKind::Removed), 2);
        assert_eq!(rhs.count(DiffLineKind::Added), 1);
        assert_eq!(rhs.count(DiffLineKind::Context), 0);
        assert_eq!(lhs.total(), rhs.total());

        // Incomparability: lhs has more `Added` than rhs, but rhs has
        // more `Removed` than lhs — neither side dominates the other.
        assert!(!lhs.is_dominated_by(&rhs));
        assert!(!rhs.is_dominated_by(&lhs));
        assert!(!lhs.dominates(&rhs));
        assert!(!rhs.dominates(&lhs));

        // The (join, meet) lattice ops are still defined on
        // incomparable pairs: the join lifts each cell to the
        // per-side maximum, the meet floors each cell to the per-
        // side minimum. The join sits strictly above both sides; the
        // meet sits strictly below.
        let join = lhs.clone().pointwise_max(&rhs);
        let meet = lhs.clone().pointwise_min(&rhs);
        assert_eq!(join.count(DiffLineKind::Removed), 2);
        assert_eq!(join.count(DiffLineKind::Added), 2);
        assert_eq!(join.count(DiffLineKind::Context), 0);
        assert_eq!(meet.count(DiffLineKind::Removed), 1);
        assert_eq!(meet.count(DiffLineKind::Added), 1);
        assert_eq!(meet.count(DiffLineKind::Context), 0);
        assert!(lhs.is_dominated_by(&join));
        assert!(rhs.is_dominated_by(&join));
        assert!(meet.is_dominated_by(&lhs));
        assert!(meet.is_dominated_by(&rhs));

        // The lattice / additive identity reads off concretely on the
        // incomparable pair too: max + min = (2,2,0) + (1,1,0) =
        // (3,3,0) = lhs + rhs.
        assert_eq!(join.clone() + &meet, lhs.clone() + &rhs);
    }

    // ---- AxisHistogram strict-partial-order trait-uniform laws ----
    //
    // The `(is_strictly_dominated_by, strictly_dominates)` pair lifts
    // the strict `<` and `>` from the partial-order surface — peer to
    // `<` next to `<=` on [`std::cmp::PartialOrd`]. Together with
    // `(is_dominated_by, dominates)`, the histogram surface carries the
    // partial-order operator quartet `(≤, ≥, <, >)` at the boolean
    // surface. The trait-uniform laws below pin the strict-partial-
    // order axioms uniformly across every [`ClosedAxis`] implementor:
    // irreflexivity (no histogram is strictly less than itself); empty
    // is the strict bottom (empty < every non-empty histogram, but not
    // < itself); asymmetry (mutual strict-dominance is impossible);
    // transitivity (the strict relation chains pointwise); dual relation
    // (`a.strictly_dominates(&b) iff b.is_strictly_dominated_by(&a)`);
    // decomposition (`a < b iff a ≤ b && a != b` — the canonical strict
    // / non-strict bridge); and the strict total bound (strict pointwise
    // `<` implies strict total `<`, stronger than the non-strict total
    // bound on [`Self::is_dominated_by`]).

    fn assert_is_strictly_dominated_by_irreflexive<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The canonical strict-partial-order irreflexivity law: every
        // histogram is `==` itself cellwise, so no cell is strictly
        // less, so `hist.is_strictly_dominated_by(&hist)` reads `false`
        // on every implementor. The dual predicate `strictly_dominates`
        // is irreflexive on the same shape. The boundary law that
        // distinguishes a strict partial order from the reflexive `≤`.
        // Pinned over both the empty and axis-cover histograms so the
        // irreflexivity reads off on both the lattice bottom and the
        // single-observation envelope.
        let empty: AxisHistogram<A> = AxisHistogram::empty();
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        assert!(
            !empty.is_strictly_dominated_by(&empty),
            "empty.is_strictly_dominated_by(&empty) must read false on axis {}",
            std::any::type_name::<A>(),
        );
        assert!(
            !empty.strictly_dominates(&empty),
            "empty.strictly_dominates(&empty) must read false on axis {}",
            std::any::type_name::<A>(),
        );
        assert!(
            !cover.is_strictly_dominated_by(&cover),
            "cover.is_strictly_dominated_by(&cover) must read false on axis {}",
            std::any::type_name::<A>(),
        );
        assert!(
            !cover.strictly_dominates(&cover),
            "cover.strictly_dominates(&cover) must read false on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_empty_is_strictly_dominated_by_nonempty<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Empty is the strict bottom on the pointwise dominance order:
        // `empty.is_strictly_dominated_by(&hist)` reads `true` for every
        // non-empty `hist` — empty is `≤` every histogram (the
        // [`Self::is_dominated_by`] law) and unequal to any non-empty
        // histogram, so the strict version reads `true` non-vacuously.
        // The dual `hist.strictly_dominates(&empty)` reads `true`
        // symmetrically on every non-empty `hist`. Pinned over the axis-
        // cover histogram (every cell strictly positive) so the relation
        // reads off on the non-vacuous case.
        let empty: AxisHistogram<A> = AxisHistogram::empty();
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        assert!(
            empty.is_strictly_dominated_by(&cover),
            "empty.is_strictly_dominated_by(&cover) must read true on axis {}",
            std::any::type_name::<A>(),
        );
        assert!(
            cover.strictly_dominates(&empty),
            "cover.strictly_dominates(&empty) must read true on axis {}",
            std::any::type_name::<A>(),
        );
        // Reverse direction reads `false` — the strict order excludes
        // the equal-case so the dominator side is not strictly below
        // the bottom.
        assert!(
            !cover.is_strictly_dominated_by(&empty),
            "cover.is_strictly_dominated_by(&empty) must read false on axis {}",
            std::any::type_name::<A>(),
        );
        assert!(
            !empty.strictly_dominates(&cover),
            "empty.strictly_dominates(&cover) must read false on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_is_strictly_dominated_by_asymmetric<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The canonical strict-partial-order asymmetry law: `a
        // .is_strictly_dominated_by(&b) ⇒ !b.is_strictly_dominated_by(&a)`.
        // Stronger than the antisymmetry law on the non-strict surface
        // (which allows the reflexive case) — the strict surface
        // forbids both directions. Pinned over the strict chain (empty
        // < cover < doubled cover) so the asymmetry reads off
        // non-vacuously on the strict-chain pairs.
        let bottom: AxisHistogram<A> = AxisHistogram::empty();
        let middle: AxisHistogram<A> = axis_iter::<A>().collect();
        let top: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for (lhs, rhs) in [(&bottom, &middle), (&bottom, &top), (&middle, &top)] {
            assert!(lhs.is_strictly_dominated_by(rhs));
            assert!(
                !rhs.is_strictly_dominated_by(lhs),
                "asymmetry: a.is_strictly_dominated_by(&b) must imply !b.is_strictly_dominated_by(&a) on axis {}",
                std::any::type_name::<A>(),
            );
            // Dual asymmetry: the `strictly_dominates` side reads off
            // symmetrically.
            assert!(rhs.strictly_dominates(lhs));
            assert!(
                !lhs.strictly_dominates(rhs),
                "asymmetry (dual): b.strictly_dominates(&a) must imply !a.strictly_dominates(&b) on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_is_strictly_dominated_by_transitive<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The canonical strict-partial-order transitivity law: `a
        // .is_strictly_dominated_by(&b) && b.is_strictly_dominated_by(&c)
        // ⇒ a.is_strictly_dominated_by(&c)`. Lifted from the cellwise
        // `<` transitivity. Pinned over the strict chain (empty <
        // cover < doubled cover) so every cell of the chain witnesses
        // a strict inequality on at least one ordinal and transitivity
        // reads off non-vacuously.
        let bottom: AxisHistogram<A> = AxisHistogram::empty();
        let middle: AxisHistogram<A> = axis_iter::<A>().collect();
        let top: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();

        assert!(bottom.is_strictly_dominated_by(&middle));
        assert!(middle.is_strictly_dominated_by(&top));
        assert!(
            bottom.is_strictly_dominated_by(&top),
            "transitivity: empty < cover < doubled cover must imply empty < doubled cover on axis {}",
            std::any::type_name::<A>(),
        );
        // The dual chain on `strictly_dominates` reads off
        // symmetrically.
        assert!(top.strictly_dominates(&middle));
        assert!(middle.strictly_dominates(&bottom));
        assert!(
            top.strictly_dominates(&bottom),
            "transitivity: doubled cover > cover > empty must imply doubled cover > empty on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_strictly_dominates_is_dual_of_is_strictly_dominated_by<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The dual-relation law on the strict-predicate pair:
        // `a.strictly_dominates(&b) == b.is_strictly_dominated_by(&a)`
        // pointwise. Peer to the (is_dominated_by, dominates) dual
        // relation on the non-strict surface. Pinned across the bottom
        // / middle / top chain plus the reversed pairs so the dual
        // relation reads off on every pair (true on the strict side,
        // false on the equal and reversed pairs).
        let bottom: AxisHistogram<A> = AxisHistogram::empty();
        let middle: AxisHistogram<A> = axis_iter::<A>().collect();
        let top: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for (lhs, rhs) in [
            (&bottom, &middle),
            (&bottom, &top),
            (&middle, &top),
            (&middle, &bottom),
            (&top, &bottom),
            (&top, &middle),
            (&middle, &middle),
        ] {
            assert_eq!(
                lhs.strictly_dominates(rhs),
                rhs.is_strictly_dominated_by(lhs),
                "dual: a.strictly_dominates(&b) must equal b.is_strictly_dominated_by(&a) on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_is_strictly_dominated_by_decomposition<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The canonical strict / non-strict bridge: `a
        // .is_strictly_dominated_by(&b) == (a.is_dominated_by(&b) && a
        // != b)`. Pins the strict predicate is `≤` with the equal-case
        // excluded — the strict predicate is the one the non-strict
        // predicate is built on. Pinned across the bottom / middle /
        // top chain plus the reversed and equal pairs so the
        // decomposition reads off on the strict pairs (true on both
        // sides), the equal pair (the strict side reads false because
        // `a == b`, even though `a ≤ b` reads true), and the reversed
        // pairs (both sides read false).
        let bottom: AxisHistogram<A> = AxisHistogram::empty();
        let middle: AxisHistogram<A> = axis_iter::<A>().collect();
        let top: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for (lhs, rhs) in [
            (&bottom, &middle),
            (&bottom, &top),
            (&middle, &top),
            (&middle, &middle),
            (&middle, &bottom),
            (&top, &middle),
        ] {
            let strict = lhs.is_strictly_dominated_by(rhs);
            let composite = lhs.is_dominated_by(rhs) && lhs != rhs;
            assert_eq!(
                strict,
                composite,
                "decomposition: a.is_strictly_dominated_by(&b) must equal (a.is_dominated_by(&b) && a != b) on axis {}",
                std::any::type_name::<A>(),
            );
            // Dual decomposition reads off symmetrically on the
            // `strictly_dominates` side.
            let strict_dual = lhs.strictly_dominates(rhs);
            let composite_dual = lhs.dominates(rhs) && lhs != rhs;
            assert_eq!(
                strict_dual,
                composite_dual,
                "decomposition (dual): a.strictly_dominates(&b) must equal (a.dominates(&b) && a != b) on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_is_strictly_dominated_by_implies_strict_total_bound<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The strict total bound implication: `a
        // .is_strictly_dominated_by(&b) ⇒ a.total() < b.total()`.
        // Strict pointwise `<` is strict-sum-monotone — every cell is
        // `≤` and at least one is strictly `<`, so the per-cell `<` on
        // the strict cell contributes a strict inequality to the
        // cellwise sum. Stronger than the non-strict total bound on
        // [`Self::is_dominated_by`] (which only carries `≤` on the
        // totals; equal totals can occur on lattice-incomparable
        // histograms). Pinned across the strict chain (empty < cover <
        // doubled cover) so the strict bound reads off non-vacuously.
        let bottom: AxisHistogram<A> = AxisHistogram::empty();
        let middle: AxisHistogram<A> = axis_iter::<A>().collect();
        let top: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for (lhs, rhs) in [(&bottom, &middle), (&bottom, &top), (&middle, &top)] {
            assert!(lhs.is_strictly_dominated_by(rhs));
            assert!(
                lhs.total() < rhs.total(),
                "strict total bound: a.is_strictly_dominated_by(&b) must imply a.total() < b.total() on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    #[test]
    fn axis_histogram_is_strictly_dominated_by_irreflexive_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_is_strictly_dominated_by_irreflexive::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_empty_is_strictly_dominated_by_nonempty_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_empty_is_strictly_dominated_by_nonempty::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_is_strictly_dominated_by_asymmetric_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_is_strictly_dominated_by_asymmetric::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_is_strictly_dominated_by_transitive_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_is_strictly_dominated_by_transitive::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_strictly_dominates_is_dual_of_is_strictly_dominated_by_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_strictly_dominates_is_dual_of_is_strictly_dominated_by::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_is_strictly_dominated_by_decomposition_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_is_strictly_dominated_by_decomposition::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_is_strictly_dominated_by_strict_total_bound_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_is_strictly_dominated_by_implies_strict_total_bound::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_is_strictly_dominated_by_partial_order_is_partial_for_diff_line_kind() {
        // Concrete pin on the partiality of the strict pointwise
        // dominance order: the (2, 1, 0) and (1, 2, 0) shapes on
        // [`DiffLineKind`] — the same incomparable pair the non-strict
        // partiality witness uses — also witness strict-incomparability.
        // Neither side strictly dominates the other, even though both
        // have identical totals. Pins the strict partial order inherits
        // the partiality of the underlying non-strict order: the same
        // incomparable pair on `(≤, ≥)` remains incomparable on
        // `(<, >)`.
        let lhs: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
        ]
        .into_iter()
        .collect();
        let rhs: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Removed,
            DiffLineKind::Removed,
            DiffLineKind::Added,
        ]
        .into_iter()
        .collect();

        // Strict-incomparability inherited from the non-strict surface:
        // neither side is `≤` the other, so neither side is `<` the
        // other either.
        assert!(!lhs.is_strictly_dominated_by(&rhs));
        assert!(!rhs.is_strictly_dominated_by(&lhs));
        assert!(!lhs.strictly_dominates(&rhs));
        assert!(!rhs.strictly_dominates(&lhs));

        // The strict partial order reads off non-vacuously against the
        // lattice envelopes: `lhs` and `rhs` are both strictly below
        // their join (the join is strictly above each side because each
        // side has at least one cell where the join is strictly
        // greater), and the meet is strictly below both sides
        // symmetrically.
        let join = lhs.clone().pointwise_max(&rhs);
        let meet = lhs.clone().pointwise_min(&rhs);
        assert!(lhs.is_strictly_dominated_by(&join));
        assert!(rhs.is_strictly_dominated_by(&join));
        assert!(meet.is_strictly_dominated_by(&lhs));
        assert!(meet.is_strictly_dominated_by(&rhs));
        assert!(join.strictly_dominates(&lhs));
        assert!(join.strictly_dominates(&rhs));
        assert!(lhs.strictly_dominates(&meet));
        assert!(rhs.strictly_dominates(&meet));

        // The strict total bound reads off concretely on the strict
        // pairs against the lattice envelopes: meet.total()=2 <
        // lhs.total()=3, lhs.total()=3 < join.total()=4. The strict
        // total bound is strict — `<` on the totals, not just `<=`.
        assert!(meet.total() < lhs.total());
        assert!(meet.total() < rhs.total());
        assert!(lhs.total() < join.total());
        assert!(rhs.total() < join.total());
    }

    // ---- AxisHistogram PartialOrd stdlib-trait bridge laws ----
    //
    // The `impl PartialOrd for AxisHistogram<A>` lifts the inherent
    // pointwise-dominance quartet (is_dominated_by, dominates,
    // is_strictly_dominated_by, strictly_dominates) onto the canonical
    // Rust stdlib operator surface (`<=`, `>=`, `<`, `>`) and the
    // `partial_cmp` return value (`Option<Ordering>`). The trait-uniform
    // laws below pin the lift's contract uniformly across every
    // [`ClosedAxis`] implementor: reflexivity at `Equal` (every
    // histogram compares equal to itself through the trait surface);
    // empty is the lattice bottom (`empty.partial_cmp(&nonempty) ==
    // Some(Less)` and dually); the operator-to-inherent bridge (every
    // stdlib operator agrees with its inherent peer pointwise); the
    // partial-cmp-to-inherent bridge (`Some(Less)` iff
    // `is_strictly_dominated_by`, `Some(Greater)` iff
    // `strictly_dominates`, `Some(Equal)` iff `==`); antisymmetry on
    // ordered pairs (`Some(Less)` flips to `Some(Greater)` under
    // argument swap). Together with the inherent dominance laws these
    // pin the manual PartialOrd impl agrees with the lattice order on
    // every axis, not the lexicographic [`Vec`] derive — the
    // load-bearing distinction the concrete pin on [`DiffLineKind`]
    // witnesses non-vacuously.

    fn assert_partial_cmp_reflexive_equal<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        use std::cmp::Ordering;
        // The canonical PartialOrd reflexivity-at-Equal law: every
        // histogram compares to itself as Some(Equal) through the
        // stdlib trait surface, agreeing with the PartialEq reflexivity
        // (a == a). Pinned over both the empty and axis-cover
        // histograms so the reflexivity reads off on the lattice bottom
        // and the single-observation envelope. Two distinct (but
        // structurally equal) constructions on each side so the
        // operator-surface reflexivity peer reads off the cellwise
        // comparison rather than a same-binding tautology.
        let empty_lhs: AxisHistogram<A> = AxisHistogram::empty();
        let empty_rhs: AxisHistogram<A> = AxisHistogram::empty();
        let cover_lhs: AxisHistogram<A> = axis_iter::<A>().collect();
        let cover_rhs: AxisHistogram<A> = axis_iter::<A>().collect();
        assert_eq!(
            empty_lhs.partial_cmp(&empty_rhs),
            Some(Ordering::Equal),
            "empty.partial_cmp(&empty) must be Some(Equal) on axis {}",
            std::any::type_name::<A>(),
        );
        assert_eq!(
            cover_lhs.partial_cmp(&cover_rhs),
            Some(Ordering::Equal),
            "cover.partial_cmp(&cover) must be Some(Equal) on axis {}",
            std::any::type_name::<A>(),
        );
        // Operator-surface reflexivity peer: `<=` and `>=` read off the
        // reflexive case on every histogram, evaluated across two
        // distinct bindings so the comparison is not a same-binding
        // tautology.
        assert!(empty_lhs <= empty_rhs);
        assert!(empty_lhs >= empty_rhs);
        assert!(cover_lhs <= cover_rhs);
        assert!(cover_lhs >= cover_rhs);
    }

    fn assert_partial_cmp_empty_is_lattice_bottom<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        use std::cmp::Ordering;
        // Empty is the lattice bottom through the stdlib trait surface:
        // `empty.partial_cmp(&cover) == Some(Less)` (strictly less on
        // every axis with at least one cell; the axis-cover construction
        // populates every cell with count `1`), and dually
        // `cover.partial_cmp(&empty) == Some(Greater)`. Peer to the
        // empty-bottom laws on the inherent dominance surface
        // (`empty.is_strictly_dominated_by(&cover)` and
        // `cover.strictly_dominates(&empty)`).
        let empty: AxisHistogram<A> = AxisHistogram::empty();
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        assert_eq!(
            empty.partial_cmp(&cover),
            Some(Ordering::Less),
            "empty.partial_cmp(&cover) must be Some(Less) on axis {}",
            std::any::type_name::<A>(),
        );
        assert_eq!(
            cover.partial_cmp(&empty),
            Some(Ordering::Greater),
            "cover.partial_cmp(&empty) must be Some(Greater) on axis {}",
            std::any::type_name::<A>(),
        );
        // Operator-surface bottom peer: `empty < cover` and `cover >
        // empty` read off the strict bottom relation on every axis.
        assert!(empty < cover);
        assert!(cover > empty);
        assert!(empty <= cover);
        assert!(cover >= empty);
    }

    fn assert_partial_cmp_matches_dominance_quartet<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The canonical operator-to-inherent bridge: every stdlib
        // PartialOrd operator agrees pointwise with its inherent
        // dominance peer across the bottom / middle / top chain. The
        // four-way correspondence:
        // - `a <= b` ⇔ `a.is_dominated_by(&b)`
        // - `a >= b` ⇔ `a.dominates(&b)`
        // - `a < b`  ⇔ `a.is_strictly_dominated_by(&b)`
        // - `a > b`  ⇔ `a.strictly_dominates(&b)`
        // Pins the manual PartialOrd impl agrees with the lattice order
        // the inherent methods are built on — the load-bearing
        // correctness condition that the lift carries the right
        // semantics (not the Vec lexicographic order the derive would
        // have given).
        let bottom: AxisHistogram<A> = AxisHistogram::empty();
        let middle: AxisHistogram<A> = axis_iter::<A>().collect();
        let top: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for (lhs, rhs) in [
            (&bottom, &bottom),
            (&bottom, &middle),
            (&bottom, &top),
            (&middle, &bottom),
            (&middle, &middle),
            (&middle, &top),
            (&top, &bottom),
            (&top, &middle),
            (&top, &top),
        ] {
            assert_eq!(
                lhs <= rhs,
                lhs.is_dominated_by(rhs),
                "`<=` operator must match is_dominated_by on axis {}",
                std::any::type_name::<A>(),
            );
            assert_eq!(
                lhs >= rhs,
                lhs.dominates(rhs),
                "`>=` operator must match dominates on axis {}",
                std::any::type_name::<A>(),
            );
            assert_eq!(
                lhs < rhs,
                lhs.is_strictly_dominated_by(rhs),
                "`<` operator must match is_strictly_dominated_by on axis {}",
                std::any::type_name::<A>(),
            );
            assert_eq!(
                lhs > rhs,
                lhs.strictly_dominates(rhs),
                "`>` operator must match strictly_dominates on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_partial_cmp_return_matches_inherent<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        use std::cmp::Ordering;
        // The partial-cmp-return-to-inherent bridge: the four-way
        // discriminator on `Option<Ordering>` agrees with the inherent
        // strict-dominance / equality / incomparability classification.
        // - `Some(Equal)`   ⇔ `a == b`
        // - `Some(Less)`    ⇔ `a.is_strictly_dominated_by(&b)`
        // - `Some(Greater)` ⇔ `a.strictly_dominates(&b)`
        // - `None`          ⇔ `!a.is_dominated_by(&b) && !b.is_dominated_by(&a)`
        // Pinned across the same chain so every triplet of related
        // histograms exercises every arm of the discriminator.
        let bottom: AxisHistogram<A> = AxisHistogram::empty();
        let middle: AxisHistogram<A> = axis_iter::<A>().collect();
        let top: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for (lhs, rhs) in [
            (&bottom, &bottom),
            (&bottom, &middle),
            (&middle, &top),
            (&top, &bottom),
            (&middle, &middle),
        ] {
            match lhs.partial_cmp(rhs) {
                Some(Ordering::Equal) => assert_eq!(
                    lhs,
                    rhs,
                    "Some(Equal) must witness equality on axis {}",
                    std::any::type_name::<A>(),
                ),
                Some(Ordering::Less) => assert!(
                    lhs.is_strictly_dominated_by(rhs),
                    "Some(Less) must witness is_strictly_dominated_by on axis {}",
                    std::any::type_name::<A>(),
                ),
                Some(Ordering::Greater) => assert!(
                    lhs.strictly_dominates(rhs),
                    "Some(Greater) must witness strictly_dominates on axis {}",
                    std::any::type_name::<A>(),
                ),
                None => {
                    assert!(!lhs.is_dominated_by(rhs));
                    assert!(!rhs.is_dominated_by(lhs));
                }
            }
        }
    }

    fn assert_partial_cmp_antisymmetric_on_ordered_pairs<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        use std::cmp::Ordering;
        // The canonical PartialOrd antisymmetry law on ordered pairs:
        // swapping the arguments inverts the Ordering. `Some(Less)`
        // flips to `Some(Greater)`, `Some(Equal)` is its own dual,
        // `Some(Greater)` flips to `Some(Less)`. Pinned across the
        // bottom / middle / top chain so the antisymmetry reads off on
        // every ordered pair.
        let bottom: AxisHistogram<A> = AxisHistogram::empty();
        let middle: AxisHistogram<A> = axis_iter::<A>().collect();
        let top: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for (lhs, rhs) in [
            (&bottom, &middle),
            (&bottom, &top),
            (&middle, &top),
            (&middle, &middle),
        ] {
            let forward = lhs.partial_cmp(rhs);
            let reverse = rhs.partial_cmp(lhs);
            let expected = forward.map(Ordering::reverse);
            assert_eq!(
                reverse,
                expected,
                "antisymmetry: rhs.partial_cmp(&lhs) must equal forward.reverse() on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    #[test]
    fn axis_histogram_partial_cmp_reflexive_equal_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_partial_cmp_reflexive_equal::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_partial_cmp_empty_is_lattice_bottom_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_partial_cmp_empty_is_lattice_bottom::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_partial_cmp_matches_dominance_quartet_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_partial_cmp_matches_dominance_quartet::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_partial_cmp_return_matches_inherent_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_partial_cmp_return_matches_inherent::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_partial_cmp_antisymmetric_on_ordered_pairs_for_every_closed_axis_implementor()
    {
        macro_rules! check {
            ($ty:ident) => {
                assert_partial_cmp_antisymmetric_on_ordered_pairs::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_partial_cmp_incomparable_returns_none_for_diff_line_kind() {
        // Concrete pin on the load-bearing distinction between the
        // manual PartialOrd impl on the lattice partial order and the
        // [`Vec`] derive's lexicographic total order: the (2, 1, 0)
        // and (1, 2, 0) shapes on [`DiffLineKind`] — the same
        // incomparable pair the non-strict / strict partiality
        // witnesses use — return `None` through the stdlib trait
        // surface. The Vec derive would have returned `Some(Less)` or
        // `Some(Greater)` (lexicographic always picks a side); the
        // manual lift carries the partiality of the underlying lattice
        // order through the `Option` return. Pins the stdlib operator
        // surface agrees with the lattice partial order on every axis,
        // not the structural Vec lexicographic order — the
        // load-bearing correctness condition the manual impl is built
        // for.
        //
        // [`DiffLineKind::ALL`] declaration order is
        // `[Removed, Added, Context]`.
        let lhs: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
        ]
        .into_iter()
        .collect();
        let rhs: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Removed,
            DiffLineKind::Removed,
            DiffLineKind::Added,
        ]
        .into_iter()
        .collect();

        // Per-cell distributions for the witnesses:
        // lhs: Removed=1, Added=2, Context=0.
        // rhs: Removed=2, Added=1, Context=0.
        // Neither side dominates the other — both `<=` reads false on
        // at least one cell, so the partial_cmp scan sees both a Less
        // and a Greater on different cells and short-circuits to None.
        assert_eq!(
            lhs.partial_cmp(&rhs),
            None,
            "incomparable lhs/rhs must partial_cmp to None",
        );
        assert_eq!(
            rhs.partial_cmp(&lhs),
            None,
            "incomparable rhs/lhs must partial_cmp to None",
        );

        // Concrete bridge to the inherent dominance quartet: the
        // operator-side incomparability matches the inherent-side
        // incomparability pointwise.
        assert!(!lhs.is_dominated_by(&rhs));
        assert!(!rhs.is_dominated_by(&lhs));
        assert!(!lhs.is_strictly_dominated_by(&rhs));
        assert!(!rhs.is_strictly_dominated_by(&lhs));
        assert!(!lhs.dominates(&rhs));
        assert!(!rhs.dominates(&lhs));
        assert!(!lhs.strictly_dominates(&rhs));
        assert!(!rhs.strictly_dominates(&lhs));

        // The lattice envelopes resolve under the stdlib operator
        // surface: each side is strictly less than the join and the
        // meet is strictly less than each side — pins partial_cmp
        // resolves to Some(Less) / Some(Greater) on the comparable
        // pairs that bracket the incomparable pair.
        let join = lhs.clone().pointwise_max(&rhs);
        let meet = lhs.clone().pointwise_min(&rhs);
        assert!(lhs < join);
        assert!(rhs < join);
        assert!(meet < lhs);
        assert!(meet < rhs);
        assert!(join > lhs);
        assert!(join > rhs);
        assert!(lhs > meet);
        assert!(rhs > meet);
    }

    // ---- AxisHistogram disjointness trait-uniform laws ----
    //
    // The (is_disjoint_from, intersects) predicate pair closes the
    // canonical set-theoretic disjointness projection on the histogram
    // surface — peer to (`HashSet::is_disjoint`, `!HashSet::is_disjoint`)
    // on stdlib sets and to the lattice meet's bottom projection
    // (`a.is_disjoint_from(&b) ⟺ a.pointwise_min(&b).is_empty()`). The
    // trait-uniform laws below pin the disjointness predicate's
    // contract uniformly across every [`ClosedAxis`] implementor:
    // symmetry (disjointness is a symmetric relation); empty is
    // disjoint from every histogram (the canonical vacuous-disjointness
    // law); self-disjoint iff empty (the boundary law on the reflexive
    // pair); dual relation with [`AxisHistogram::intersects`] (perfect
    // boolean duality); meet characterization (the lattice-bridge law
    // pinning disjointness to the meet's bottom); dominance
    // preservation (sub-histograms inherit disjointness).

    fn assert_is_disjoint_from_symmetric<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The canonical symmetry law on the disjointness predicate:
        // `a.is_disjoint_from(&b) == b.is_disjoint_from(&a)`. The
        // cellwise predicate `lhs == 0 || rhs == 0` is symmetric in its
        // two arguments, so the lift inherits the symmetry. Peer to
        // the symmetry of [`std::collections::HashSet::is_disjoint`].
        // Pinned across the (empty, empty), (empty, cover), (cover,
        // empty), and (cover, cover) pairs so the symmetry reads off
        // on both the true (vacuous-disjoint) and false
        // (self-intersecting) sides.
        let empty: AxisHistogram<A> = AxisHistogram::empty();
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        for (lhs, rhs) in [
            (&empty, &empty),
            (&empty, &cover),
            (&cover, &empty),
            (&cover, &cover),
        ] {
            assert_eq!(
                lhs.is_disjoint_from(rhs),
                rhs.is_disjoint_from(lhs),
                "symmetry: a.is_disjoint_from(&b) must equal b.is_disjoint_from(&a) on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_empty_is_disjoint_from_every<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Empty is disjoint from every histogram: every cell of
        // `empty` is zero, so the cellwise `lhs == 0 || rhs == 0`
        // predicate reads `true` on every ordinal — vacuously
        // satisfied. Pinned over the (empty, empty), (empty, cover),
        // and (empty, doubled cover) pairs so the vacuous-disjointness
        // reads off on both the empty self-pair and the non-vacuous
        // counterparty pairs. Also reads off on the symmetric side by
        // the symmetry law.
        let empty: AxisHistogram<A> = AxisHistogram::empty();
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        let doubled: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for rhs in [&empty, &cover, &doubled] {
            assert!(
                empty.is_disjoint_from(rhs),
                "empty.is_disjoint_from(&hist) must read true on axis {}",
                std::any::type_name::<A>(),
            );
            assert!(
                rhs.is_disjoint_from(&empty),
                "hist.is_disjoint_from(&empty) must read true on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_self_disjoint_iff_empty<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The boundary law on the reflexive pair:
        // `hist.is_disjoint_from(&hist) == hist.is_empty()`. A
        // histogram has at least one positive cell iff it is non-
        // empty; that cell witnesses non-disjointness on the
        // reflexive pair. The unique self-disjoint histogram is the
        // empty one. Pinned over (empty, cover, doubled cover) so the
        // boundary reads off on both the true case (empty self-pair)
        // and the false case (non-empty self-pairs).
        let empty: AxisHistogram<A> = AxisHistogram::empty();
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        let doubled: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for hist in [&empty, &cover, &doubled] {
            assert_eq!(
                hist.is_disjoint_from(hist),
                hist.is_empty(),
                "self-disjoint iff empty: hist.is_disjoint_from(&hist) must equal hist.is_empty() on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_intersects_is_dual_of_is_disjoint_from<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The perfect boolean dual law on the disjointness pair:
        // `a.intersects(&b) == !a.is_disjoint_from(&b)`. By
        // construction the two predicates negate each other on every
        // input pair — `intersects` reads `true` iff at least one cell
        // is mutually positive, which is the exact negation of
        // `is_disjoint_from`. Pinned across the (empty, empty),
        // (empty, cover), (cover, empty), and (cover, cover) pairs so
        // the dual reads off on both the disjoint and the
        // intersecting cases.
        let empty: AxisHistogram<A> = AxisHistogram::empty();
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        for (lhs, rhs) in [
            (&empty, &empty),
            (&empty, &cover),
            (&cover, &empty),
            (&cover, &cover),
        ] {
            assert_eq!(
                lhs.intersects(rhs),
                !lhs.is_disjoint_from(rhs),
                "dual: a.intersects(&b) must equal !a.is_disjoint_from(&b) on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_is_disjoint_from_meet_characterization<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The canonical lattice-bridge law: `a.is_disjoint_from(&b) ==
        // a.clone().pointwise_min(&b).is_empty()`. Pins the
        // disjointness predicate is the one the lattice meet's bottom
        // projection is built on. Peer to the join / meet
        // characterizations of [`AxisHistogram::is_dominated_by`].
        // Pinned across the (empty, empty), (empty, cover), (cover,
        // empty), and (cover, cover) pairs so the bridge reads off on
        // both the true side (empty meet → disjoint) and the false
        // side (non-empty meet on the cover self-pair → intersecting).
        let empty: AxisHistogram<A> = AxisHistogram::empty();
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        for (lhs, rhs) in [
            (&empty, &empty),
            (&empty, &cover),
            (&cover, &empty),
            (&cover, &cover),
        ] {
            let predicate = lhs.is_disjoint_from(rhs);
            let meet_empty = lhs.clone().pointwise_min(rhs).is_empty();
            assert_eq!(
                predicate,
                meet_empty,
                "meet characterization: a.is_disjoint_from(&b) must equal a.pointwise_min(&b).is_empty() on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_is_disjoint_from_dominance_preservation<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The dominance-preservation law: `a.is_disjoint_from(&b) && c
        // .is_dominated_by(&a) ⇒ c.is_disjoint_from(&b)`. Disjointness
        // is closed under sub-histograms — any histogram pointwise `≤`
        // a histogram disjoint from `b` is itself disjoint from `b`.
        // Peer to the subset-monotonicity of disjointness on stdlib
        // sets. Pinned with `a = empty` (disjoint from every `b`) and
        // `c = empty` (dominated by every `a`, including empty) so the
        // preservation reads off on the trait-uniform witness pair
        // available on every closed axis.
        let empty: AxisHistogram<A> = AxisHistogram::empty();
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        let doubled: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for b in [&empty, &cover, &doubled] {
            assert!(empty.is_disjoint_from(b));
            // `empty.is_dominated_by(&empty)` and `empty
            // .is_disjoint_from(b)` ⇒ `empty.is_disjoint_from(b)`. The
            // dominance preservation reads off on every counterparty.
            assert!(empty.is_dominated_by(&empty));
            assert!(
                empty.is_disjoint_from(b),
                "dominance preservation: empty <= empty and empty.is_disjoint_from(b) must imply empty.is_disjoint_from(b) on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    #[test]
    fn axis_histogram_is_disjoint_from_symmetric_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_is_disjoint_from_symmetric::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_empty_is_disjoint_from_every_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_empty_is_disjoint_from_every::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_self_disjoint_iff_empty_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_self_disjoint_iff_empty::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_intersects_is_dual_of_is_disjoint_from_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_intersects_is_dual_of_is_disjoint_from::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_is_disjoint_from_meet_characterization_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_is_disjoint_from_meet_characterization::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_is_disjoint_from_dominance_preservation_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_is_disjoint_from_dominance_preservation::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_is_disjoint_from_witnessed_on_disjoint_supports_for_diff_line_kind() {
        // Concrete pin on the disjointness predicate against
        // [`DiffLineKind`] — the three-cell axis (Added, Removed,
        // Context) lets the disjointness predicate read off
        // non-vacuously on two non-empty histograms with structurally
        // disjoint supports. `added_only` has counts (3, 0, 0);
        // `removed_only` has counts (0, 2, 0). No cell is mutually
        // positive, so the predicate reads `true` on both directions
        // (symmetry), and the dual `intersects` reads `false`. The
        // lattice meet `added_only ∧ removed_only` collapses to
        // [`AxisHistogram::empty`] (the meet characterization), and
        // the lattice join collapses to the additive sum
        // `added_only + removed_only` (the join-equals-add law on
        // disjoint pairs). A non-disjoint witness pair pins the false
        // side: `mixed` carries (1, 1, 0) and intersects both
        // `added_only` (on the Added cell) and `removed_only` (on the
        // Removed cell).
        let added_only: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Added,
        ]
        .into_iter()
        .collect();
        let removed_only: AxisHistogram<DiffLineKind> =
            [DiffLineKind::Removed, DiffLineKind::Removed]
                .into_iter()
                .collect();
        let mixed: AxisHistogram<DiffLineKind> = [DiffLineKind::Added, DiffLineKind::Removed]
            .into_iter()
            .collect();

        // Both sides non-empty, but the supports are structurally
        // disjoint — the predicate reads `true` non-vacuously on both
        // directions, and the dual reads `false`.
        assert!(added_only.is_disjoint_from(&removed_only));
        assert!(removed_only.is_disjoint_from(&added_only));
        assert!(!added_only.intersects(&removed_only));
        assert!(!removed_only.intersects(&added_only));
        assert!(!added_only.is_empty());
        assert!(!removed_only.is_empty());

        // Non-disjoint witness pair: `mixed` shares the Added cell
        // with `added_only` and the Removed cell with `removed_only`.
        // The predicate reads `false`, the dual reads `true`, on both
        // directions.
        assert!(!added_only.is_disjoint_from(&mixed));
        assert!(!mixed.is_disjoint_from(&added_only));
        assert!(added_only.intersects(&mixed));
        assert!(mixed.intersects(&added_only));
        assert!(!removed_only.is_disjoint_from(&mixed));
        assert!(!mixed.is_disjoint_from(&removed_only));
        assert!(removed_only.intersects(&mixed));
        assert!(mixed.intersects(&removed_only));

        // Meet characterization reads off concretely: the meet of
        // disjoint pairs collapses to empty, and the meet of
        // intersecting pairs is non-empty.
        let disjoint_meet = added_only.clone().pointwise_min(&removed_only);
        let intersecting_meet = added_only.clone().pointwise_min(&mixed);
        assert!(disjoint_meet.is_empty());
        assert!(!intersecting_meet.is_empty());
        assert_eq!(
            disjoint_meet,
            AxisHistogram::<DiffLineKind>::empty(),
            "disjoint meet must equal empty"
        );
        assert_eq!(intersecting_meet.count(DiffLineKind::Added), 1);
        assert_eq!(intersecting_meet.count(DiffLineKind::Removed), 0);

        // Join-equals-add law on disjoint pairs: on the disjoint pair
        // `(added_only, removed_only)` the lattice join collapses to
        // the additive sum — every cell is the max of one zero and one
        // positive count, which equals the sum.
        let disjoint_join = added_only.clone().pointwise_max(&removed_only);
        let disjoint_sum = added_only.clone() + &removed_only;
        assert_eq!(
            disjoint_join, disjoint_sum,
            "join-equals-add on disjoint pairs: pointwise_max must equal Add on the disjoint pair"
        );
        // The join carries the union of supports — counts (3, 2, 0).
        assert_eq!(disjoint_join.count(DiffLineKind::Added), 3);
        assert_eq!(disjoint_join.count(DiffLineKind::Removed), 2);
        assert_eq!(disjoint_join.count(DiffLineKind::Context), 0);
        assert_eq!(disjoint_join.total(), 5);
    }

    // ---- AxisHistogram symmetric-difference trait-uniform laws ----
    //
    // The [`AxisHistogram::symmetric_difference`] lift closes the
    // canonical set-theoretic operator quartet `(∪, ∩, ∖, △)` at the
    // histogram surface — peer to
    // (`HashSet::union`, `HashSet::intersection`, `HashSet::difference`,
    // `HashSet::symmetric_difference`) on stdlib sets, with
    // [`AxisHistogram::pointwise_max`] / [`AxisHistogram::pointwise_min`] /
    // [`std::ops::Sub`] / [`AxisHistogram::symmetric_difference`]
    // carrying the quartet on the multiset side. The trait-uniform laws
    // below pin the symmetric-difference operator's contract uniformly
    // across every [`ClosedAxis`] implementor: symmetry (the cellwise
    // absolute difference is symmetric); self-cancellation (every
    // histogram is its own inverse — `(AxisHistogram, △, empty)` is a
    // commutative monoid with exponent-2 self-inverses on the support-
    // set projection); empty is the two-sided identity (the empty
    // histogram is the canonical identity element of the symmetric-
    // difference monoid); the lattice-bridge identity (`△ = ∪ ∖ ∩`
    // cellwise); the add-bridge identity (`△ + 2·∩ = +`); the
    // disjoint-pair specialization (`△ = +` on disjoint inputs); and
    // the dominance specialization (`△ = ∖` on comparable pairs on
    // the partial-order surface).

    fn assert_symmetric_difference_is_symmetric<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The canonical symmetry law on the symmetric-difference
        // operator: `a.symmetric_difference(&b) ==
        // b.symmetric_difference(&a)` pointwise. The cellwise
        // absolute-difference `|lhs - rhs|` is symmetric in its two
        // arguments, so the lift inherits the symmetry. Peer to the
        // symmetry of [`std::collections::HashSet::symmetric_difference`].
        // Pinned across the (empty, empty), (empty, cover), (cover,
        // empty), and (cover, doubled) pairs so the symmetry reads off
        // on both the vacuous (empty result) and non-vacuous sides.
        let empty: AxisHistogram<A> = AxisHistogram::empty();
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        let doubled: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for (lhs, rhs) in [
            (&empty, &empty),
            (&empty, &cover),
            (&cover, &empty),
            (&cover, &doubled),
            (&doubled, &cover),
        ] {
            assert_eq!(
                lhs.clone().symmetric_difference(rhs),
                rhs.clone().symmetric_difference(lhs),
                "symmetry: a.symmetric_difference(&b) must equal b.symmetric_difference(&a) on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_symmetric_difference_self_cancels_to_empty<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The canonical self-cancellation law on the symmetric-
        // difference monoid: `hist.clone().symmetric_difference(&hist)
        // == AxisHistogram::empty()`. Every cell of the reflexive pair
        // has `|c - c| == 0`, so the symmetric difference collapses to
        // the bottom of the lattice on every reflexive input. The
        // boundary law that makes every histogram its own inverse
        // under `△`. Pinned over (empty, cover, doubled) so the
        // boundary reads off on both the empty self-pair (vacuous
        // empty) and non-empty self-pairs (collapse-to-empty).
        let empty: AxisHistogram<A> = AxisHistogram::empty();
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        let doubled: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for hist in [&empty, &cover, &doubled] {
            assert_eq!(
                hist.clone().symmetric_difference(hist),
                AxisHistogram::<A>::empty(),
                "self-cancellation: hist.symmetric_difference(&hist) must equal AxisHistogram::empty() on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_symmetric_difference_empty_is_identity<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The canonical two-sided-identity law on the symmetric-
        // difference monoid: `hist.clone().symmetric_difference(&empty)
        // == hist` and `empty.symmetric_difference(&hist) == hist`.
        // Every cell of `empty` is zero, so `|c - 0| == c` and `|0 - c|
        // == c` reduce to the original count on every ordinal — the
        // empty histogram is the two-sided identity of the symmetric-
        // difference monoid, exactly as `HashSet::new()` is the two-
        // sided identity of stdlib set symmetric difference. Pinned
        // over (empty, cover, doubled) so the identity reads off on
        // both the empty input (vacuous) and the non-empty inputs.
        let empty: AxisHistogram<A> = AxisHistogram::empty();
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        let doubled: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for hist in [&empty, &cover, &doubled] {
            assert_eq!(
                hist.clone().symmetric_difference(&empty),
                hist.clone(),
                "right identity: hist.symmetric_difference(&empty) must equal hist on axis {}",
                std::any::type_name::<A>(),
            );
            assert_eq!(
                empty.clone().symmetric_difference(hist),
                hist.clone(),
                "left identity: empty.symmetric_difference(&hist) must equal hist on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_symmetric_difference_lattice_bridge<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The canonical "△ = ∪ ∖ ∩" lattice-bridge identity:
        // `a.symmetric_difference(&b) == a.pointwise_max(&b) -
        // a.pointwise_min(&b)` on every input pair. Pins the symmetric
        // difference is the gap between the join and the meet of the
        // same pair on every cell — every cell satisfies `|lhs - rhs|
        // == max(lhs, rhs) - min(lhs, rhs)`. Pinned across (empty,
        // empty), (empty, cover), (cover, empty), and (cover, doubled)
        // so the bridge reads off on both the vacuous (empty bridge) and
        // non-vacuous sides.
        let empty: AxisHistogram<A> = AxisHistogram::empty();
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        let doubled: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for (lhs, rhs) in [
            (&empty, &empty),
            (&empty, &cover),
            (&cover, &empty),
            (&cover, &doubled),
            (&doubled, &cover),
        ] {
            let sym_diff = lhs.clone().symmetric_difference(rhs);
            let join = lhs.clone().pointwise_max(rhs);
            let meet = lhs.clone().pointwise_min(rhs);
            let bridge = join - &meet;
            assert_eq!(
                sym_diff,
                bridge,
                "lattice bridge: a.symmetric_difference(&b) must equal a.pointwise_max(&b) - a.pointwise_min(&b) on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_symmetric_difference_add_bridge<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The canonical add-bridge identity: `a.symmetric_difference(&b)
        // + 2 * a.pointwise_min(&b) == a + b`. The
        // `(max - min) + 2 * min == max + min` identity, with the
        // `(max + min == add)` lattice-additive identity (pinned at
        // `axis_histogram_pointwise_max_plus_min_equals_add_*`)
        // composing the two halves: the symmetric difference plus
        // twice the meet recovers the additive sum on every input
        // pair. Pinned across (empty, empty), (empty, cover), (cover,
        // empty), and (cover, doubled).
        let empty: AxisHistogram<A> = AxisHistogram::empty();
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        let doubled: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for (lhs, rhs) in [
            (&empty, &empty),
            (&empty, &cover),
            (&cover, &empty),
            (&cover, &doubled),
            (&doubled, &cover),
        ] {
            let sym_diff = lhs.clone().symmetric_difference(rhs);
            let meet = lhs.clone().pointwise_min(rhs);
            let twice_meet = meet * 2;
            let recovered = sym_diff + &twice_meet;
            let sum = lhs.clone() + rhs;
            assert_eq!(
                recovered,
                sum,
                "add bridge: a.symmetric_difference(&b) + 2 * a.pointwise_min(&b) must equal a + b on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_symmetric_difference_disjoint_equals_add<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The disjoint-pair specialization: `a.is_disjoint_from(&b) ⇒
        // a.symmetric_difference(&b) == a + b`. On disjoint pairs the
        // meet collapses to empty (by the meet characterization of
        // disjointness), so the lattice-bridge identity reduces to
        // `△ == ∪ - 0 == ∪`, and the join-equals-add law on disjoint
        // pairs further reduces this to `△ == +`. Pinned on the
        // trait-uniform disjoint witness pair (empty, cover): empty is
        // disjoint from every histogram, including cover, so the
        // specialization reads off non-vacuously on every axis. Also
        // pinned on (empty, empty) for the vacuous (both-empty) case
        // where the specialization reads `empty == empty`.
        let empty: AxisHistogram<A> = AxisHistogram::empty();
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        for (lhs, rhs) in [(&empty, &empty), (&empty, &cover), (&cover, &empty)] {
            assert!(
                lhs.is_disjoint_from(rhs),
                "witness pair must be disjoint on axis {}",
                std::any::type_name::<A>(),
            );
            let sym_diff = lhs.clone().symmetric_difference(rhs);
            let sum = lhs.clone() + rhs;
            assert_eq!(
                sym_diff,
                sum,
                "disjoint specialization: a.is_disjoint_from(&b) ⇒ a.symmetric_difference(&b) must equal a + b on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_symmetric_difference_dominance_specializes_to_sub<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The dominance specialization on the comparable-pair surface:
        // `a.is_dominated_by(&b) ⇒ a.symmetric_difference(&b) ==
        // b - a` (and by symmetry, also `== b.symmetric_difference(&a)`).
        // When every cell of `a` is `<=` the corresponding cell of `b`,
        // the cellwise absolute difference `|a - b|` reduces to the
        // directed (saturating) difference `b - a` on every cell.
        // Pinned on the trait-uniform comparable witness pair (empty,
        // cover): empty is dominated by every histogram on the lattice
        // (the bottom), so the specialization reads off non-vacuously
        // on every axis as `cover.symmetric_difference(&empty) ==
        // cover - empty == cover`.
        let empty: AxisHistogram<A> = AxisHistogram::empty();
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        let doubled: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for (lhs, rhs) in [(&empty, &cover), (&empty, &doubled), (&cover, &doubled)] {
            assert!(
                lhs.is_dominated_by(rhs),
                "witness pair must be comparable on axis {}",
                std::any::type_name::<A>(),
            );
            let sym_diff = lhs.clone().symmetric_difference(rhs);
            let directed = rhs.clone() - lhs;
            assert_eq!(
                sym_diff,
                directed,
                "dominance specialization: a.is_dominated_by(&b) ⇒ a.symmetric_difference(&b) must equal b - a on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    #[test]
    fn axis_histogram_symmetric_difference_is_symmetric_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_symmetric_difference_is_symmetric::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_symmetric_difference_self_cancels_to_empty_for_every_closed_axis_implementor()
    {
        macro_rules! check {
            ($ty:ident) => {
                assert_symmetric_difference_self_cancels_to_empty::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_symmetric_difference_empty_is_identity_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_symmetric_difference_empty_is_identity::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_symmetric_difference_lattice_bridge_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_symmetric_difference_lattice_bridge::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_symmetric_difference_add_bridge_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_symmetric_difference_add_bridge::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_symmetric_difference_disjoint_equals_add_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_symmetric_difference_disjoint_equals_add::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_symmetric_difference_dominance_specializes_to_sub_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_symmetric_difference_dominance_specializes_to_sub::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_symmetric_difference_witnessed_on_partial_overlap_for_diff_line_kind() {
        // Concrete pin on the symmetric-difference operator against
        // [`DiffLineKind`] — the three-cell axis (Added, Removed,
        // Context) lets the per-cell absolute difference read off non-
        // vacuously on a partially-overlapping pair. `lhs` carries
        // counts (5, 2, 0); `rhs` carries (1, 4, 3). The symmetric
        // difference reads (|5-1|, |2-4|, |0-3|) = (4, 2, 3) — every
        // cell carries the unsigned magnitude of the per-cell gap
        // regardless of sign. The lattice bridge reads off concretely:
        // join = (5, 4, 3), meet = (1, 2, 0), join - meet = (4, 2, 3) ==
        // sym_diff. The add bridge reads off concretely: meet * 2 =
        // (2, 4, 0), sym_diff + meet * 2 = (6, 6, 3) == lhs + rhs.
        // The total reads `lhs.symmetric_difference(&rhs).total() == 9`,
        // the L1 / Manhattan distance between the two histograms.
        let lhs: AxisHistogram<DiffLineKind> =
            [(DiffLineKind::Added, 5), (DiffLineKind::Removed, 2)]
                .into_iter()
                .collect();
        let rhs: AxisHistogram<DiffLineKind> = [
            (DiffLineKind::Added, 1),
            (DiffLineKind::Removed, 4),
            (DiffLineKind::Context, 3),
        ]
        .into_iter()
        .collect();

        let sym_diff = lhs.clone().symmetric_difference(&rhs);
        assert_eq!(sym_diff.count(DiffLineKind::Added), 4);
        assert_eq!(sym_diff.count(DiffLineKind::Removed), 2);
        assert_eq!(sym_diff.count(DiffLineKind::Context), 3);
        assert_eq!(sym_diff.total(), 9);

        // Symmetry: swapping the arguments yields the same histogram.
        let sym_diff_rev = rhs.clone().symmetric_difference(&lhs);
        assert_eq!(sym_diff, sym_diff_rev);

        // Lattice bridge: `△ = ∪ - ∩` cellwise.
        let join = lhs.clone().pointwise_max(&rhs);
        let meet = lhs.clone().pointwise_min(&rhs);
        assert_eq!(join.count(DiffLineKind::Added), 5);
        assert_eq!(join.count(DiffLineKind::Removed), 4);
        assert_eq!(join.count(DiffLineKind::Context), 3);
        assert_eq!(meet.count(DiffLineKind::Added), 1);
        assert_eq!(meet.count(DiffLineKind::Removed), 2);
        assert_eq!(meet.count(DiffLineKind::Context), 0);
        let bridge = join.clone() - &meet;
        assert_eq!(bridge, sym_diff);

        // Add bridge: `△ + 2·∩ == +`.
        let twice_meet = meet.clone() * 2;
        let recovered = sym_diff.clone() + &twice_meet;
        let sum = lhs.clone() + &rhs;
        assert_eq!(recovered, sum);
        assert_eq!(sum.count(DiffLineKind::Added), 6);
        assert_eq!(sum.count(DiffLineKind::Removed), 6);
        assert_eq!(sum.count(DiffLineKind::Context), 3);

        // Dominance specialization: `meet` is dominated by both `lhs`
        // and `rhs`, so the symmetric difference against either
        // collapses to the directed saturating difference.
        assert!(meet.is_dominated_by(&lhs));
        assert!(meet.is_dominated_by(&rhs));
        let meet_sym_lhs = meet.clone().symmetric_difference(&lhs);
        let meet_sub_lhs = lhs.clone() - &meet;
        assert_eq!(meet_sym_lhs, meet_sub_lhs);
        let meet_sym_rhs = meet.clone().symmetric_difference(&rhs);
        let meet_sub_rhs = rhs.clone() - &meet;
        assert_eq!(meet_sym_rhs, meet_sub_rhs);
    }

    // ---- AxisHistogram BitXor / BitXorAssign operator-surface laws ----
    //
    // The (BitXor, BitXorAssign) quartet (× owned/borrowed RHS) lifts
    // the inherent [`AxisHistogram::symmetric_difference`] onto the
    // stdlib bit-operator surface — the canonical `^` / `^=` idiom
    // every stdlib set carries
    // ([`std::collections::HashSet::bitxor`] /
    // [`std::collections::BTreeSet::bitxor`]) lifted onto the multiset
    // (count-valued) surface. Closes the missing operator-surface arm
    // of the set-theoretic operator quartet `(∪, ∩, ∖, △)`: the
    // arithmetic ∖ arm was already on the operator surface through
    // [`std::ops::Sub`]; the △ arm now joins it on the bit-operator
    // surface through [`std::ops::BitXor`], so the lift gives the
    // multiset a uniform "every set-theoretic operator has an operator
    // surface" property at the [`ClosedAxis`] typescape. The
    // trait-uniform laws below pin the operator quartet's contract
    // uniformly across every [`ClosedAxis`] implementor: equivalence
    // with the inherent method (the operator lift carries the same
    // per-cell `abs_diff` loop the inherent method is built on);
    // symmetry, self-cancellation, empty-RHS identity, and cell-level
    // absolute-difference lifted from the inherent method's
    // trait-uniform laws; and the (owned, borrowed) RHS equivalence on
    // both the [`BitXor`] and [`BitXorAssign`] surfaces (so the
    // per-cell loop lives at exactly one site — the
    // borrowed-RHS-[`BitXorAssign`] impl).

    fn assert_bitxor_assign_ref_equals_symmetric_difference<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The canonical operator-to-inherent bridge on `^=`: every
        // `BitXorAssign<&Self>` call agrees pointwise with the inherent
        // `symmetric_difference` on the same arguments. Pins the
        // operator-surface lift carries the same per-cell `abs_diff`
        // semantics the inherent method is built on — the load-bearing
        // correctness condition for the (`BitXorAssign`,
        // `symmetric_difference`) duality.
        let empty: AxisHistogram<A> = AxisHistogram::empty();
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        let doubled: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for (lhs, rhs) in [
            (&empty, &empty),
            (&empty, &cover),
            (&cover, &empty),
            (&cover, &doubled),
            (&doubled, &cover),
        ] {
            let mut via_op = lhs.clone();
            via_op ^= rhs;
            let via_method = lhs.clone().symmetric_difference(rhs);
            assert_eq!(
                via_op,
                via_method,
                "bitxor_assign ref must equal symmetric_difference on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_bitxor_assign_ref_empty_rhs_is_identity<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The empty-RHS identity law on `^=`: `hist ^= &empty` leaves
        // `hist` unchanged. Every cell of `empty` is zero, so the
        // per-cell `abs_diff` reduces to the original count on every
        // ordinal. Peer to the `AddAssign` empty-RHS-identity law on
        // the additive monoid.
        let empty: AxisHistogram<A> = AxisHistogram::empty();
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        let doubled: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for hist in [&empty, &cover, &doubled] {
            let mut applied = hist.clone();
            applied ^= &empty;
            assert_eq!(
                applied,
                hist.clone(),
                "hist ^= &empty must leave hist unchanged on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_bitxor_assign_ref_self_yields_empty<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The self-cancellation absorbing law on `^=`: `let mut a =
        // hist.clone(); a ^= &hist` zeros every cell of `a`, pointwise
        // equal to `AxisHistogram::empty()`. The exponent-2 self-inverse
        // law on the symmetric-difference monoid carries through the
        // operator surface — every histogram is its own inverse under
        // `^=`. Peer to the `SubAssign` self-subtraction absorbing law
        // on the monus monoid.
        let empty: AxisHistogram<A> = AxisHistogram::empty();
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        let doubled: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for hist in [&empty, &cover, &doubled] {
            let mut applied = hist.clone();
            applied ^= hist;
            assert_eq!(
                applied,
                AxisHistogram::<A>::empty(),
                "hist ^= &hist must equal AxisHistogram::empty() on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_bitxor_assign_ref_is_symmetric<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The symmetry law on `^=`: `let mut a = x.clone(); a ^= &y;`
        // and `let mut b = y.clone(); b ^= &x;` are pointwise equal,
        // by the symmetry of cellwise `usize::abs_diff`. The call
        // sites differ in which histogram is mutated; the resulting
        // histogram does not. Peer to the inherent
        // `symmetric_difference`-is-symmetric law on the borrowed-RHS
        // surface.
        let empty: AxisHistogram<A> = AxisHistogram::empty();
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        let doubled: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for (lhs, rhs) in [
            (&empty, &empty),
            (&empty, &cover),
            (&cover, &empty),
            (&cover, &doubled),
            (&doubled, &cover),
        ] {
            let mut from_lhs = lhs.clone();
            from_lhs ^= rhs;
            let mut from_rhs = rhs.clone();
            from_rhs ^= lhs;
            assert_eq!(
                from_lhs,
                from_rhs,
                "bitxor_assign symmetry: lhs ^= &rhs must equal rhs ^= &lhs on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_bitxor_assign_ref_cell_level_abs_diff<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The cell-level absolute-difference law on `^=`: every cell
        // `v` satisfies `after.count(v) ==
        // before.count(v).abs_diff(other.count(v))`. Peer to the
        // `AddAssign` cell-additivity law and the `SubAssign`
        // cell-saturation law on the additive / monus monoids. Pinned
        // over the (axis-cover, doubled) pair so every cell carries a
        // positive count on both sides and the `abs_diff` reads off
        // every ordinal independently.
        let before: AxisHistogram<A> = axis_iter::<A>().collect();
        let other: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        let mut after = before.clone();
        after ^= &other;
        for cell in axis_iter::<A>() {
            assert_eq!(
                after.count(cell),
                before.count(cell).abs_diff(other.count(cell)),
                "hist ^= &other cell {cell:?} must equal before.count.abs_diff(other.count) on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_bitxor_owned_equals_bitxor_ref<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The (owned, borrowed) RHS equivalence on `^`: `lhs ^ rhs`
        // produces the same histogram as `lhs ^ &rhs`. Pins the
        // owned-RHS impl delegates to the borrowed form so the
        // per-cell `abs_diff` loop lives at exactly one site (the
        // borrowed-RHS-`BitXorAssign` impl). Peer to the
        // `axis_histogram_sub_owned_equals_sub_ref_*` law on the
        // subtraction operator surface.
        let empty: AxisHistogram<A> = AxisHistogram::empty();
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        let doubled: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for (lhs, rhs) in [
            (&empty, &empty),
            (&empty, &cover),
            (&cover, &empty),
            (&cover, &doubled),
            (&doubled, &cover),
        ] {
            let via_owned = lhs.clone() ^ rhs.clone();
            let via_ref = lhs.clone() ^ rhs;
            assert_eq!(
                via_owned,
                via_ref,
                "lhs ^ rhs must equal lhs ^ &rhs on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_bitxor_assign_owned_equals_bitxor_assign_ref<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The (owned, borrowed) RHS equivalence on `^=`: `let mut a =
        // lhs.clone(); a ^= rhs.clone();` produces the same histogram
        // as `let mut a = lhs.clone(); a ^= &rhs;`. Pins the owned-RHS
        // `BitXorAssign` impl delegates to the borrowed form so the
        // per-cell `abs_diff` loop lives at exactly one site (the
        // borrowed-RHS-`BitXorAssign` impl). Peer to the
        // `axis_histogram_sub_assign_owned_equals_sub_assign_ref` family
        // on the subtraction operator surface.
        let empty: AxisHistogram<A> = AxisHistogram::empty();
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        let doubled: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for (lhs, rhs) in [
            (&empty, &empty),
            (&empty, &cover),
            (&cover, &empty),
            (&cover, &doubled),
            (&doubled, &cover),
        ] {
            let mut via_owned = lhs.clone();
            via_owned ^= rhs.clone();
            let mut via_ref = lhs.clone();
            via_ref ^= rhs;
            assert_eq!(
                via_owned,
                via_ref,
                "(a ^= rhs) must equal (a ^= &rhs) on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    #[test]
    fn axis_histogram_bitxor_assign_ref_equals_symmetric_difference_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_bitxor_assign_ref_equals_symmetric_difference::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_bitxor_assign_ref_empty_rhs_is_identity_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_bitxor_assign_ref_empty_rhs_is_identity::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_bitxor_assign_ref_self_yields_empty_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_bitxor_assign_ref_self_yields_empty::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_bitxor_assign_ref_is_symmetric_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_bitxor_assign_ref_is_symmetric::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_bitxor_assign_ref_cell_level_abs_diff_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_bitxor_assign_ref_cell_level_abs_diff::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_bitxor_owned_equals_bitxor_ref_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_bitxor_owned_equals_bitxor_ref::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_bitxor_assign_owned_equals_bitxor_assign_ref_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_bitxor_assign_owned_equals_bitxor_assign_ref::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_bitxor_witnessed_on_partial_overlap_for_diff_line_kind() {
        // Concrete pin on the `^` operator surface against
        // [`DiffLineKind`] — the three-cell axis (Added, Removed,
        // Context) lets the per-cell absolute difference read off non-
        // vacuously on a partially-overlapping pair. `lhs` carries
        // counts (5, 2, 0); `rhs` carries (1, 4, 3). `lhs ^ &rhs`
        // reads (|5-1|, |2-4|, |0-3|) = (4, 2, 3) — every cell carries
        // the unsigned magnitude of the per-cell gap regardless of
        // sign. Mirrors the
        // `axis_histogram_symmetric_difference_witnessed_on_partial_overlap_for_diff_line_kind`
        // pin on the inherent-method side; reads it off again on the
        // operator-surface side to pin the lift is the same function.
        let lhs: AxisHistogram<DiffLineKind> =
            [(DiffLineKind::Added, 5), (DiffLineKind::Removed, 2)]
                .into_iter()
                .collect();
        let rhs: AxisHistogram<DiffLineKind> = [
            (DiffLineKind::Added, 1),
            (DiffLineKind::Removed, 4),
            (DiffLineKind::Context, 3),
        ]
        .into_iter()
        .collect();

        let via_op = lhs.clone() ^ &rhs;
        assert_eq!(via_op.count(DiffLineKind::Added), 4);
        assert_eq!(via_op.count(DiffLineKind::Removed), 2);
        assert_eq!(via_op.count(DiffLineKind::Context), 3);
        assert_eq!(via_op.total(), 9);

        // Operator-to-inherent equivalence at the concrete pin: `lhs ^
        // &rhs` is pointwise equal to `lhs.symmetric_difference(&rhs)`.
        let via_method = lhs.clone().symmetric_difference(&rhs);
        assert_eq!(via_op, via_method);

        // Symmetry on the operator surface: `lhs ^ &rhs == rhs ^ &lhs`.
        let via_op_rev = rhs.clone() ^ &lhs;
        assert_eq!(via_op, via_op_rev);

        // Self-cancellation on the operator surface: `lhs ^ &lhs ==
        // empty`.
        let self_canceled = lhs.clone() ^ &lhs;
        assert_eq!(self_canceled, AxisHistogram::<DiffLineKind>::empty());

        // `^=` agrees with `^` on the same input.
        let mut via_assign = lhs.clone();
        via_assign ^= &rhs;
        assert_eq!(via_assign, via_op);
    }

    // ---- AxisHistogram::BitOr / BitOrAssign trait-uniform laws ----
    //
    // The (`BitOr`, `BitOrAssign`)-on-`AxisHistogram` impls promote the
    // lattice-join (∪) arm of the (∪, ∩, ∖, △) set-theoretic operator
    // quartet onto the stdlib bit-operator surface — the multiset peer
    // of [`HashSet::bitor`] / [`HashSet::bitor_assign`]
    // (`|` / `|=` on stdlib sets). The arithmetic ∖ arm sits on the
    // operator surface through [`std::ops::Sub`] (saturating); the △
    // arm sits on the bit-operator surface through [`std::ops::BitXor`]
    // (the cellwise `abs_diff`); the ∪ arm now joins them on the
    // bit-operator surface through [`std::ops::BitOr`] (the cellwise
    // `max`). Before this lift, [`Self::pointwise_max`] was the only
    // entry to the join — the consume-and-rebind shape forced a rebind
    // at every call site even when the histogram lived behind a
    // mutable binding. The trait-uniform laws below pin the operator
    // quartet's join arm uniformly across every [`ClosedAxis`]
    // implementor: equivalence with the inherent method (the operator
    // lift carries the same per-cell `max` loop the inherent method is
    // built on); commutativity, self-idempotence, empty-RHS identity,
    // and cell-level max lifted from the inherent method's
    // trait-uniform laws; the dominance-under-join law (`|=` produces
    // an upper bound on both sides under [`Self::is_dominated_by`] —
    // the defining lattice-join property on the dominance partial
    // order); and the (owned, borrowed) RHS equivalence on both the
    // [`BitOr`] and [`BitOrAssign`] surfaces (so the per-cell loop
    // lives at exactly one site — the borrowed-RHS-[`BitOrAssign`]
    // impl).

    fn assert_bitor_assign_ref_equals_pointwise_max<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The canonical operator-to-inherent bridge on `|=`: every
        // `BitOrAssign<&Self>` call agrees pointwise with the inherent
        // `pointwise_max` on the same arguments. Pins the operator-
        // surface lift carries the same per-cell `max` semantics the
        // inherent method is built on — the load-bearing correctness
        // condition for the (`BitOrAssign`, `pointwise_max`) duality.
        let empty: AxisHistogram<A> = AxisHistogram::empty();
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        let doubled: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for (lhs, rhs) in [
            (&empty, &empty),
            (&empty, &cover),
            (&cover, &empty),
            (&cover, &doubled),
            (&doubled, &cover),
        ] {
            let mut via_op = lhs.clone();
            via_op |= rhs;
            let via_method = lhs.clone().pointwise_max(rhs);
            assert_eq!(
                via_op,
                via_method,
                "bitor_assign ref must equal pointwise_max on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_bitor_assign_ref_empty_rhs_is_identity<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The empty-RHS identity law on `|=`: `hist |= &empty` leaves
        // `hist` unchanged. Every cell of `empty` is zero, so the
        // per-cell `max` reduces to the original count on every
        // ordinal — `empty` is the bottom of the lattice. Peer to the
        // `AddAssign` and `BitXorAssign` empty-RHS-identity laws on
        // the additive / symmetric-difference monoids.
        let empty: AxisHistogram<A> = AxisHistogram::empty();
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        let doubled: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for hist in [&empty, &cover, &doubled] {
            let mut applied = hist.clone();
            applied |= &empty;
            assert_eq!(
                applied,
                hist.clone(),
                "hist |= &empty must leave hist unchanged on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_bitor_assign_ref_self_is_identity<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The idempotence law on `|=`: `let mut a = hist.clone(); a |=
        // &hist` leaves `a` pointwise equal to `hist`. The canonical
        // lattice idempotence law on the join — every cell is its own
        // max with itself. Dual peer to the `BitXorAssign`
        // self-cancellation absorbing law on the symmetric-difference
        // monoid (which yields `empty` instead — the join is the
        // lattice idempotent counterpart of the symmetric-difference
        // involutory).
        let empty: AxisHistogram<A> = AxisHistogram::empty();
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        let doubled: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for hist in [&empty, &cover, &doubled] {
            let mut applied = hist.clone();
            applied |= hist;
            assert_eq!(
                applied,
                hist.clone(),
                "hist |= &hist must equal hist on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_bitor_assign_ref_is_commutative<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The commutativity law on `|=`: `let mut a = x.clone(); a |=
        // &y;` and `let mut b = y.clone(); b |= &x;` are pointwise
        // equal, by the commutativity of cellwise `Ord::max`. The call
        // sites differ in which histogram is mutated; the resulting
        // histogram does not. Peer to the inherent
        // `pointwise_max`-is-commutative law on the borrowed-RHS
        // surface and the `BitXorAssign`-is-symmetric law on the
        // symmetric-difference operator surface.
        let empty: AxisHistogram<A> = AxisHistogram::empty();
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        let doubled: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for (lhs, rhs) in [
            (&empty, &empty),
            (&empty, &cover),
            (&cover, &empty),
            (&cover, &doubled),
            (&doubled, &cover),
        ] {
            let mut from_lhs = lhs.clone();
            from_lhs |= rhs;
            let mut from_rhs = rhs.clone();
            from_rhs |= lhs;
            assert_eq!(
                from_lhs,
                from_rhs,
                "bitor_assign commutativity: lhs |= &rhs must equal rhs |= &lhs on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_bitor_assign_ref_cell_level_max<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The cell-level max law on `|=`: every cell `v` satisfies
        // `after.count(v) == before.count(v).max(other.count(v))`. Peer
        // to the `AddAssign` cell-additivity, `SubAssign`
        // cell-saturation, and `BitXorAssign` cell-`abs_diff` laws on
        // the additive / monus / symmetric-difference monoids. Pinned
        // over the (axis-cover, doubled) pair so every cell carries a
        // positive count on both sides and the `max` reads off every
        // ordinal independently.
        let before: AxisHistogram<A> = axis_iter::<A>().collect();
        let other: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        let mut after = before.clone();
        after |= &other;
        for cell in axis_iter::<A>() {
            assert_eq!(
                after.count(cell),
                before.count(cell).max(other.count(cell)),
                "hist |= &other cell {cell:?} must equal before.count.max(other.count) on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_bitor_assign_ref_dominates_both_sides<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The lattice-join law on `|=`: after `self |= &other`, both
        // the original `self` and `other` are pointwise dominated by
        // the resulting histogram (the join is the least upper bound
        // on the dominance partial order [`Self::is_dominated_by`]).
        // Reaches the (∪, ≤) lattice property the operator surface
        // names on the same trait-uniform pin.
        let empty: AxisHistogram<A> = AxisHistogram::empty();
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        let doubled: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for (lhs, rhs) in [
            (&empty, &empty),
            (&empty, &cover),
            (&cover, &empty),
            (&cover, &doubled),
            (&doubled, &cover),
        ] {
            let mut joined = lhs.clone();
            joined |= rhs;
            assert!(
                lhs.is_dominated_by(&joined),
                "lhs |= &rhs must dominate lhs on axis {}",
                std::any::type_name::<A>(),
            );
            assert!(
                rhs.is_dominated_by(&joined),
                "lhs |= &rhs must dominate rhs on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_bitor_owned_equals_bitor_ref<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The (owned, borrowed) RHS equivalence on `|`: `lhs | rhs`
        // produces the same histogram as `lhs | &rhs`. Pins the
        // owned-RHS impl delegates to the borrowed form so the per-cell
        // `max` loop lives at exactly one site (the
        // borrowed-RHS-`BitOrAssign` impl). Peer to the
        // `axis_histogram_bitxor_owned_equals_bitxor_ref_*` law on the
        // symmetric-difference operator surface.
        let empty: AxisHistogram<A> = AxisHistogram::empty();
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        let doubled: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for (lhs, rhs) in [
            (&empty, &empty),
            (&empty, &cover),
            (&cover, &empty),
            (&cover, &doubled),
            (&doubled, &cover),
        ] {
            let via_owned = lhs.clone() | rhs.clone();
            let via_ref = lhs.clone() | rhs;
            assert_eq!(
                via_owned,
                via_ref,
                "lhs | rhs must equal lhs | &rhs on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_bitor_assign_owned_equals_bitor_assign_ref<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The (owned, borrowed) RHS equivalence on `|=`: `let mut a =
        // lhs.clone(); a |= rhs.clone();` produces the same histogram
        // as `let mut a = lhs.clone(); a |= &rhs;`. Pins the owned-RHS
        // `BitOrAssign` impl delegates to the borrowed form so the
        // per-cell `max` loop lives at exactly one site (the
        // borrowed-RHS-`BitOrAssign` impl). Peer to the
        // `axis_histogram_bitxor_assign_owned_equals_bitxor_assign_ref`
        // family on the symmetric-difference operator surface.
        let empty: AxisHistogram<A> = AxisHistogram::empty();
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        let doubled: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for (lhs, rhs) in [
            (&empty, &empty),
            (&empty, &cover),
            (&cover, &empty),
            (&cover, &doubled),
            (&doubled, &cover),
        ] {
            let mut via_owned = lhs.clone();
            via_owned |= rhs.clone();
            let mut via_ref = lhs.clone();
            via_ref |= rhs;
            assert_eq!(
                via_owned,
                via_ref,
                "(a |= rhs) must equal (a |= &rhs) on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    #[test]
    fn axis_histogram_bitor_assign_ref_equals_pointwise_max_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_bitor_assign_ref_equals_pointwise_max::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_bitor_assign_ref_empty_rhs_is_identity_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_bitor_assign_ref_empty_rhs_is_identity::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_bitor_assign_ref_self_is_identity_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_bitor_assign_ref_self_is_identity::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_bitor_assign_ref_is_commutative_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_bitor_assign_ref_is_commutative::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_bitor_assign_ref_cell_level_max_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_bitor_assign_ref_cell_level_max::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_bitor_assign_ref_dominates_both_sides_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_bitor_assign_ref_dominates_both_sides::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_bitor_owned_equals_bitor_ref_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_bitor_owned_equals_bitor_ref::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_bitor_assign_owned_equals_bitor_assign_ref_for_every_closed_axis_implementor()
    {
        macro_rules! check {
            ($ty:ident) => {
                assert_bitor_assign_owned_equals_bitor_assign_ref::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_bitor_witnessed_on_partial_overlap_for_diff_line_kind() {
        // Concrete pin on the `|` operator surface against
        // [`DiffLineKind`] — the three-cell axis (Added, Removed,
        // Context) lets the per-cell max read off non-vacuously on a
        // partially-overlapping pair. `lhs` carries counts (5, 2, 0);
        // `rhs` carries (1, 4, 3). `lhs | &rhs` reads (max(5,1),
        // max(2,4), max(0,3)) = (5, 4, 3) — every cell carries the
        // per-cell upper bound regardless of which side dominates.
        // Mirrors the `axis_histogram_pointwise_max_per_cell_envelope`
        // pin on the inherent-method side; reads it off again on the
        // operator-surface side to pin the lift is the same function.
        let lhs: AxisHistogram<DiffLineKind> =
            [(DiffLineKind::Added, 5), (DiffLineKind::Removed, 2)]
                .into_iter()
                .collect();
        let rhs: AxisHistogram<DiffLineKind> = [
            (DiffLineKind::Added, 1),
            (DiffLineKind::Removed, 4),
            (DiffLineKind::Context, 3),
        ]
        .into_iter()
        .collect();

        let via_op = lhs.clone() | &rhs;
        assert_eq!(via_op.count(DiffLineKind::Added), 5);
        assert_eq!(via_op.count(DiffLineKind::Removed), 4);
        assert_eq!(via_op.count(DiffLineKind::Context), 3);
        assert_eq!(via_op.total(), 12);

        // Operator-to-inherent equivalence at the concrete pin: `lhs |
        // &rhs` is pointwise equal to `lhs.pointwise_max(&rhs)`.
        let via_method = lhs.clone().pointwise_max(&rhs);
        assert_eq!(via_op, via_method);

        // Commutativity on the operator surface: `lhs | &rhs == rhs |
        // &lhs`.
        let via_op_rev = rhs.clone() | &lhs;
        assert_eq!(via_op, via_op_rev);

        // Idempotence on the operator surface: `lhs | &lhs == lhs`.
        let self_joined = lhs.clone() | &lhs;
        assert_eq!(self_joined, lhs);

        // `|=` agrees with `|` on the same input.
        let mut via_assign = lhs.clone();
        via_assign |= &rhs;
        assert_eq!(via_assign, via_op);

        // Dominance under join at the concrete pin: both lhs and rhs
        // are pointwise dominated by the join.
        assert!(lhs.is_dominated_by(&via_op));
        assert!(rhs.is_dominated_by(&via_op));
    }

    // ---- AxisHistogram::BitAnd / BitAndAssign trait-uniform laws ----
    //
    // The (`BitAnd`, `BitAndAssign`)-on-`AxisHistogram` impls promote
    // the lattice-meet (∩) arm of the (∪, ∩, ∖, △) set-theoretic
    // operator quartet onto the stdlib bit-operator surface — the
    // multiset peer of [`HashSet::bitand`] / [`HashSet::bitand_assign`]
    // (`&` / `&=` on stdlib sets), the lattice dual of the
    // [`BitOr`] / [`BitOrAssign`] lift on the join arm. With the meet
    // arm landed, the operator quartet is closed on the bit-operator
    // surface: ∪ through `|`, ∩ through `&`, △ through `^`, ∖ through
    // the saturating `-`. Before this lift, [`Self::pointwise_min`] was
    // the only entry to the meet — the consume-and-rebind shape forced
    // a rebind at every call site even when the histogram lived behind
    // a mutable binding. The trait-uniform laws below pin the operator
    // quartet's meet arm uniformly across every [`ClosedAxis`]
    // implementor: equivalence with the inherent method (the operator
    // lift carries the same per-cell `min` loop the inherent method is
    // built on); commutativity, self-idempotence, empty-RHS absorbing,
    // and cell-level min lifted from the inherent method's
    // trait-uniform laws; the dominated-by-under-meet law (`&=`
    // produces a lower bound on both sides under
    // [`Self::is_dominated_by`] — the defining lattice-meet property on
    // the dominance partial order); the join-meet additive
    // decomposition `(a | &b) + &(a & &b) == a + &b` on the operator
    // surface (the canonical `max + min == sum` identity lifted
    // cellwise — pins the lattice algebra and the additive monoid
    // agree on the per-cell decomposition through the operator surface,
    // not just the inherent method); and the (owned, borrowed) RHS
    // equivalence on both the [`BitAnd`] and [`BitAndAssign`] surfaces
    // (so the per-cell loop lives at exactly one site — the
    // borrowed-RHS-[`BitAndAssign`] impl).

    fn assert_bitand_assign_ref_equals_pointwise_min<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The canonical operator-to-inherent bridge on `&=`: every
        // `BitAndAssign<&Self>` call agrees pointwise with the inherent
        // `pointwise_min` on the same arguments. Pins the operator-
        // surface lift carries the same per-cell `min` semantics the
        // inherent method is built on — the load-bearing correctness
        // condition for the (`BitAndAssign`, `pointwise_min`) duality.
        let empty: AxisHistogram<A> = AxisHistogram::empty();
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        let doubled: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for (lhs, rhs) in [
            (&empty, &empty),
            (&empty, &cover),
            (&cover, &empty),
            (&cover, &doubled),
            (&doubled, &cover),
        ] {
            let mut via_op = lhs.clone();
            via_op &= rhs;
            let via_method = lhs.clone().pointwise_min(rhs);
            assert_eq!(
                via_op,
                via_method,
                "bitand_assign ref must equal pointwise_min on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_bitand_assign_ref_empty_rhs_is_empty<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The empty-RHS absorbing law on `&=`: `hist &= &empty` zeros
        // every cell of `hist`. Every cell of `empty` is zero, so the
        // per-cell `min` reduces every cell to zero on every ordinal —
        // `empty` is the bottom of the lattice, dual to the (empty,
        // max) identity law on the join (`|=`) side. Peer to the (empty,
        // ∸) absorbing law on the left-empty side of the monus monoid.
        let empty: AxisHistogram<A> = AxisHistogram::empty();
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        let doubled: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for hist in [&empty, &cover, &doubled] {
            let mut applied = hist.clone();
            applied &= &empty;
            assert_eq!(
                applied,
                empty,
                "hist &= &empty must zero hist on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_bitand_assign_ref_self_is_identity<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The idempotence law on `&=`: `let mut a = hist.clone(); a &=
        // &hist` leaves `a` pointwise equal to `hist`. The canonical
        // lattice idempotence law on the meet — every cell is its own
        // min with itself. Peer to the `BitOrAssign` self-idempotence
        // on the join (which also leaves the histogram unchanged — the
        // lattice has both join-idempotence and meet-idempotence as
        // the defining lattice laws).
        let empty: AxisHistogram<A> = AxisHistogram::empty();
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        let doubled: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for hist in [&empty, &cover, &doubled] {
            let mut applied = hist.clone();
            applied &= hist;
            assert_eq!(
                applied,
                hist.clone(),
                "hist &= &hist must equal hist on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_bitand_assign_ref_is_commutative<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The commutativity law on `&=`: `let mut a = x.clone(); a &=
        // &y;` and `let mut b = y.clone(); b &= &x;` are pointwise
        // equal, by the commutativity of cellwise `Ord::min`. The call
        // sites differ in which histogram is mutated; the resulting
        // histogram does not. Peer to the inherent
        // `pointwise_min`-is-commutative law on the borrowed-RHS
        // surface and the `BitOrAssign`-is-commutative law on the
        // lattice-join operator surface.
        let empty: AxisHistogram<A> = AxisHistogram::empty();
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        let doubled: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for (lhs, rhs) in [
            (&empty, &empty),
            (&empty, &cover),
            (&cover, &empty),
            (&cover, &doubled),
            (&doubled, &cover),
        ] {
            let mut from_lhs = lhs.clone();
            from_lhs &= rhs;
            let mut from_rhs = rhs.clone();
            from_rhs &= lhs;
            assert_eq!(
                from_lhs,
                from_rhs,
                "bitand_assign commutativity: lhs &= &rhs must equal rhs &= &lhs on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_bitand_assign_ref_cell_level_min<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The cell-level min law on `&=`: every cell `v` satisfies
        // `after.count(v) == before.count(v).min(other.count(v))`. Peer
        // to the `BitOrAssign` cell-level max, the `AddAssign`
        // cell-additivity, the `SubAssign` cell-saturation, and the
        // `BitXorAssign` cell-`abs_diff` laws on the join / additive /
        // monus / symmetric-difference monoids. Pinned over the
        // (axis-cover, doubled) pair so every cell carries a positive
        // count on both sides and the `min` reads off every ordinal
        // independently.
        let before: AxisHistogram<A> = axis_iter::<A>().collect();
        let other: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        let mut after = before.clone();
        after &= &other;
        for cell in axis_iter::<A>() {
            assert_eq!(
                after.count(cell),
                before.count(cell).min(other.count(cell)),
                "hist &= &other cell {cell:?} must equal before.count.min(other.count) on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_bitand_assign_ref_dominated_by_both_sides<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The lattice-meet law on `&=`: after `self &= &other`, the
        // resulting histogram is pointwise dominated by both the
        // original `self` and `other` (the meet is the greatest lower
        // bound on the dominance partial order
        // [`Self::is_dominated_by`]). Reaches the (∩, ≤) lattice
        // property the operator surface names on the same trait-uniform
        // pin — dual to the `BitOrAssign` join-is-least-upper-bound
        // law.
        let empty: AxisHistogram<A> = AxisHistogram::empty();
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        let doubled: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for (lhs, rhs) in [
            (&empty, &empty),
            (&empty, &cover),
            (&cover, &empty),
            (&cover, &doubled),
            (&doubled, &cover),
        ] {
            let mut met = lhs.clone();
            met &= rhs;
            assert!(
                met.is_dominated_by(lhs),
                "lhs &= &rhs must be dominated by lhs on axis {}",
                std::any::type_name::<A>(),
            );
            assert!(
                met.is_dominated_by(rhs),
                "lhs &= &rhs must be dominated by rhs on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_bitor_plus_bitand_equals_add<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The lattice / additive decomposition law on the operator
        // surface: for every pair `(a, b)`, `(a | &b) + &(a & &b)` is
        // pointwise equal to `a + &b`. The canonical `max(x, y) +
        // min(x, y) == x + y` identity lifted cellwise — pins the
        // lattice algebra and the additive monoid agree on the per-cell
        // decomposition through the operator surface, not just the
        // inherent-method side
        // (`axis_histogram_pointwise_max_plus_min_equals_add_*`). Pinned
        // over the (axis-cover, doubled) pair so every cell carries a
        // positive count on both sides and the decomposition reads off
        // every ordinal non-vacuously.
        let a: AxisHistogram<A> = axis_iter::<A>().collect();
        let b: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        let join = a.clone() | &b;
        let meet = a.clone() & &b;
        let lhs = join + &meet;
        let rhs = a + &b;
        assert_eq!(
            lhs,
            rhs,
            "(a | &b) + &(a & &b) must equal a + &b on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_bitand_owned_equals_bitand_ref<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The (owned, borrowed) RHS equivalence on `&`: `lhs & rhs`
        // produces the same histogram as `lhs & &rhs`. Pins the
        // owned-RHS impl delegates to the borrowed form so the per-cell
        // `min` loop lives at exactly one site (the
        // borrowed-RHS-`BitAndAssign` impl). Peer to the
        // `axis_histogram_bitor_owned_equals_bitor_ref_*` law on the
        // lattice-join operator surface.
        let empty: AxisHistogram<A> = AxisHistogram::empty();
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        let doubled: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for (lhs, rhs) in [
            (&empty, &empty),
            (&empty, &cover),
            (&cover, &empty),
            (&cover, &doubled),
            (&doubled, &cover),
        ] {
            let via_owned = lhs.clone() & rhs.clone();
            let via_ref = lhs.clone() & rhs;
            assert_eq!(
                via_owned,
                via_ref,
                "lhs & rhs must equal lhs & &rhs on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_bitand_assign_owned_equals_bitand_assign_ref<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The (owned, borrowed) RHS equivalence on `&=`: `let mut a =
        // lhs.clone(); a &= rhs.clone();` produces the same histogram
        // as `let mut a = lhs.clone(); a &= &rhs;`. Pins the owned-RHS
        // `BitAndAssign` impl delegates to the borrowed form so the
        // per-cell `min` loop lives at exactly one site (the
        // borrowed-RHS-`BitAndAssign` impl). Peer to the
        // `axis_histogram_bitor_assign_owned_equals_bitor_assign_ref`
        // family on the lattice-join operator surface.
        let empty: AxisHistogram<A> = AxisHistogram::empty();
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        let doubled: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for (lhs, rhs) in [
            (&empty, &empty),
            (&empty, &cover),
            (&cover, &empty),
            (&cover, &doubled),
            (&doubled, &cover),
        ] {
            let mut via_owned = lhs.clone();
            via_owned &= rhs.clone();
            let mut via_ref = lhs.clone();
            via_ref &= rhs;
            assert_eq!(
                via_owned,
                via_ref,
                "(a &= rhs) must equal (a &= &rhs) on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    #[test]
    fn axis_histogram_bitand_assign_ref_equals_pointwise_min_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_bitand_assign_ref_equals_pointwise_min::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_bitand_assign_ref_empty_rhs_is_empty_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_bitand_assign_ref_empty_rhs_is_empty::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_bitand_assign_ref_self_is_identity_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_bitand_assign_ref_self_is_identity::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_bitand_assign_ref_is_commutative_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_bitand_assign_ref_is_commutative::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_bitand_assign_ref_cell_level_min_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_bitand_assign_ref_cell_level_min::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_bitand_assign_ref_dominated_by_both_sides_for_every_closed_axis_implementor()
    {
        macro_rules! check {
            ($ty:ident) => {
                assert_bitand_assign_ref_dominated_by_both_sides::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_bitor_plus_bitand_equals_add_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_bitor_plus_bitand_equals_add::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_bitand_owned_equals_bitand_ref_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_bitand_owned_equals_bitand_ref::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_bitand_assign_owned_equals_bitand_assign_ref_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_bitand_assign_owned_equals_bitand_assign_ref::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_bitand_witnessed_on_partial_overlap_for_diff_line_kind() {
        // Concrete pin on the `&` operator surface against
        // [`DiffLineKind`] — the three-cell axis (Added, Removed,
        // Context) lets the per-cell min read off non-vacuously on a
        // partially-overlapping pair. `lhs` carries counts (5, 2, 0);
        // `rhs` carries (1, 4, 3). `lhs & &rhs` reads (min(5,1),
        // min(2,4), min(0,3)) = (1, 2, 0) — every cell carries the
        // per-cell lower bound regardless of which side dominates.
        // Mirrors the `axis_histogram_pointwise_min_per_cell_floor`
        // pin on the inherent-method side; reads it off again on the
        // operator-surface side to pin the lift is the same function.
        let lhs: AxisHistogram<DiffLineKind> =
            [(DiffLineKind::Added, 5), (DiffLineKind::Removed, 2)]
                .into_iter()
                .collect();
        let rhs: AxisHistogram<DiffLineKind> = [
            (DiffLineKind::Added, 1),
            (DiffLineKind::Removed, 4),
            (DiffLineKind::Context, 3),
        ]
        .into_iter()
        .collect();

        let via_op = lhs.clone() & &rhs;
        assert_eq!(via_op.count(DiffLineKind::Added), 1);
        assert_eq!(via_op.count(DiffLineKind::Removed), 2);
        assert_eq!(via_op.count(DiffLineKind::Context), 0);
        assert_eq!(via_op.total(), 3);

        // Operator-to-inherent equivalence at the concrete pin: `lhs &
        // &rhs` is pointwise equal to `lhs.pointwise_min(&rhs)`.
        let via_method = lhs.clone().pointwise_min(&rhs);
        assert_eq!(via_op, via_method);

        // Commutativity on the operator surface: `lhs & &rhs == rhs &
        // &lhs`.
        let via_op_rev = rhs.clone() & &lhs;
        assert_eq!(via_op, via_op_rev);

        // Idempotence on the operator surface: `lhs & &lhs == lhs`.
        let self_met = lhs.clone() & &lhs;
        assert_eq!(self_met, lhs);

        // Empty-absorbing on the operator surface: `lhs & &empty ==
        // empty`.
        let empty = AxisHistogram::<DiffLineKind>::empty();
        let absorbed = lhs.clone() & &empty;
        assert_eq!(absorbed, empty);

        // `&=` agrees with `&` on the same input.
        let mut via_assign = lhs.clone();
        via_assign &= &rhs;
        assert_eq!(via_assign, via_op);

        // Dominance under meet at the concrete pin: the meet is
        // pointwise dominated by both lhs and rhs.
        assert!(via_op.is_dominated_by(&lhs));
        assert!(via_op.is_dominated_by(&rhs));

        // Lattice / additive decomposition at the concrete pin: `(lhs
        // | &rhs) + &(lhs & &rhs) == lhs + &rhs`. The canonical
        // max + min == sum identity reads off through the operator
        // surface, not just the inherent method.
        let join = lhs.clone() | &rhs;
        let sum_decomp = join + &via_op;
        let sum_direct = lhs.clone() + &rhs;
        assert_eq!(sum_decomp, sum_direct);
    }

    // ---- AxisHistogram scalar-action trait-uniform laws ----
    //
    // The (Mul<usize>, MulAssign<usize>) scalar-action surface promotes
    // the additive monoid quartet (Add/AddAssign × owned/borrowed) to a
    // commutative monoid with usize-action — a free
    // `(usize, +, *)`-semimodule indexed by the closed axis. The
    // trait-uniform laws below pin the scalar action's contract
    // uniformly across every [`ClosedAxis`] implementor: zero-factor
    // absorbs (collapses every cell to zero, pointwise equal to
    // [`AxisHistogram::empty`]); one-factor is the identity (preserves
    // the counts vector); the (Mul, MulAssign) operator pair agrees
    // pointwise; scaling distributes over [`AddAssign`] (the canonical
    // semimodule distributivity law); scaling is pointwise equal to
    // repeated `+=`-by-self (the scalar-action / repeated-addition
    // equivalence on the dual side of the monoid).

    fn assert_mul_assign_zero_factor_zeros_histogram<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The zero-factor absorbing law on `MulAssign<usize>`: `hist
        // *= 0` zeros every cell of the histogram, pointwise equal to
        // `AxisHistogram::empty()`. Pinned over the axis-cover
        // histogram so every cell carries a positive count and the
        // collapse-to-zero reads off every ordinal.
        let mut cover: AxisHistogram<A> = axis_iter::<A>().collect();
        cover *= 0;
        assert_eq!(
            cover,
            AxisHistogram::<A>::empty(),
            "hist *= 0 must equal AxisHistogram::empty() on axis {}",
            std::any::type_name::<A>(),
        );
        assert_eq!(
            cover.total(),
            0,
            "hist *= 0 must zero the total on axis {}",
            std::any::type_name::<A>(),
        );
        assert!(
            cover.is_empty(),
            "hist *= 0 must satisfy is_empty on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_mul_assign_one_factor_is_identity<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The one-factor identity law on `MulAssign<usize>`: `hist *=
        // 1` leaves the histogram unchanged. The identity element of
        // the scalar monoid `(usize, *, 1)` preserves the counts
        // vector pointwise. Pinned over the axis-cover histogram so
        // every cell carries a positive count and the equality reads
        // off every ordinal.
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        let mut scaled = cover.clone();
        scaled *= 1;
        assert_eq!(
            scaled,
            cover,
            "hist *= 1 must leave hist unchanged on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_mul_assign_scales_total<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The total-scaling law on `MulAssign<usize>`: `hist *=
        // factor` multiplies `hist.total()` by exactly `factor`. The
        // scalar peer of the [`AddAssign`] additivity law on the dual
        // side of the monoid. Pinned at factors 0, 1, 2, 5 so the
        // identity and absorbing boundaries plus two non-trivial
        // multipliers witness the contract.
        let cover: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        let total_before = cover.total();
        for factor in [0usize, 1, 2, 5] {
            let mut scaled = cover.clone();
            scaled *= factor;
            assert_eq!(
                scaled.total(),
                total_before * factor,
                "hist *= {factor} must scale total by {factor} on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_mul_assign_scales_cells<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The cell-level scaling law on `MulAssign<usize>`: every cell
        // `v` has its count multiplied by `factor`. Pinned at factor
        // 3 over the (axis-cover + once-more) histogram so every cell
        // carries a non-trivial pre-scale count and the multiplication
        // reads off every ordinal independently.
        let pre: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        let factor = 3usize;
        let mut scaled = pre.clone();
        scaled *= factor;
        for cell in axis_iter::<A>() {
            assert_eq!(
                scaled.count(cell),
                pre.count(cell) * factor,
                "hist *= {factor} cell {cell:?} must equal pre.count * {factor} on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_mul_assign_distributes_over_add_assign<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The semimodule distributivity law: scaling distributes over
        // the additive monoid. `(a + &b) * n` is pointwise equal to
        // `a * n + &(b * n)` — each cell carries the `(usize, +, *)`
        // distributive law, and the histogram inherits it pointwise.
        // Pinned over two non-trivial histograms at factor 4 so the
        // equality reads off a non-trivial cell distribution and a
        // factor that is neither the identity nor the absorbing
        // element.
        let lhs: AxisHistogram<A> = axis_iter::<A>().collect();
        let rhs: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        let factor = 4usize;

        let mut via_scale_after = lhs.clone();
        via_scale_after += &rhs;
        via_scale_after *= factor;

        let mut via_scale_first_lhs = lhs.clone();
        via_scale_first_lhs *= factor;
        let mut via_scale_first_rhs = rhs.clone();
        via_scale_first_rhs *= factor;
        via_scale_first_lhs += &via_scale_first_rhs;

        assert_eq!(
            via_scale_after,
            via_scale_first_lhs,
            "(a + &b) * n must equal a * n + &(b * n) on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_mul_assign_equals_repeated_add_assign<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The scalar-action / repeated-addition equivalence on the
        // dual side of the monoid: `hist *= factor` reads the same
        // histogram as `factor` rounds of `+= &hist` against an empty
        // accumulator. Pinned at factor 3 over the axis-cover
        // histogram so the equivalence covers a non-trivial cell
        // distribution and a non-identity / non-absorbing factor.
        let hist: AxisHistogram<A> = axis_iter::<A>().collect();
        let factor = 3usize;

        let mut via_mul = hist.clone();
        via_mul *= factor;

        let mut via_repeated_add: AxisHistogram<A> = AxisHistogram::empty();
        for _ in 0..factor {
            via_repeated_add += &hist;
        }

        assert_eq!(
            via_mul,
            via_repeated_add,
            "hist *= {factor} must equal {factor} rounds of += &hist on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_mul_equals_mul_assign<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The (Mul, MulAssign) idiom-peer equivalence on the scalar-
        // action surface: `hist * factor` reads the same histogram as
        // `let mut a = hist.clone(); a *= factor; a`. The canonical
        // Rust owned/in-place operator peer pair — `impl Mul<usize>`
        // and `impl MulAssign<usize>` agreeing pointwise — every stdlib
        // scalar-action operator-surface exposes (`Duration * u32 ==`
        // a `Duration` whose internal `*=` step is the same fold).
        // Pinned at factors 0, 1, 2, 5 so the identity, absorbing, and
        // two non-trivial multipliers witness the equivalence.
        let hist: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for factor in [0usize, 1, 2, 5] {
            let via_mul = hist.clone() * factor;
            let mut via_mul_assign = hist.clone();
            via_mul_assign *= factor;
            assert_eq!(
                via_mul,
                via_mul_assign,
                "hist * {factor} must equal `let mut a = hist; a *= {factor}; a` on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    #[test]
    fn axis_histogram_mul_assign_zero_factor_zeros_histogram_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_mul_assign_zero_factor_zeros_histogram::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_mul_assign_one_factor_is_identity_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_mul_assign_one_factor_is_identity::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_mul_assign_scales_total_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_mul_assign_scales_total::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_mul_assign_scales_cells_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_mul_assign_scales_cells::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_mul_assign_distributes_over_add_assign_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_mul_assign_distributes_over_add_assign::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_mul_assign_equals_repeated_add_assign_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_mul_assign_equals_repeated_add_assign::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_mul_equals_mul_assign_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_mul_equals_mul_assign::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_mul_distributes_over_add_for_diff_line_kind() {
        // The semimodule distributivity law on the infix-operator
        // surface: `(a + &b) * n` is pointwise equal to `a * n + &(b *
        // n)`. The (Mul, MulAssign, Add, AddAssign) operator surfaces
        // compose through one consistent distributive law. Pinned
        // concretely on [`DiffLineKind`] across two non-trivial
        // histograms and a non-identity / non-absorbing factor so the
        // distributivity reads off a non-trivial cell distribution.
        let a: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
        ]
        .into_iter()
        .collect();
        let b: AxisHistogram<DiffLineKind> = [DiffLineKind::Removed, DiffLineKind::Context]
            .into_iter()
            .collect();
        let factor = 3usize;

        let via_scale_after = (a.clone() + &b) * factor;
        let via_scale_first = a.clone() * factor + &(b.clone() * factor);

        assert_eq!(via_scale_after, via_scale_first);

        // Concrete cell counts: a + b yields (Added: 2, Removed: 2,
        // Context: 1); scaled by 3 yields (6, 6, 3).
        assert_eq!(via_scale_after.count(DiffLineKind::Added), 6);
        assert_eq!(via_scale_after.count(DiffLineKind::Removed), 6);
        assert_eq!(via_scale_after.count(DiffLineKind::Context), 3);
        assert_eq!(via_scale_after.total(), 15);
    }

    #[test]
    fn axis_histogram_mul_equals_fleet_aggregate_for_diff_line_kind() {
        // The canonical weighted-rollup pattern on the scalar-action
        // operator surface: a per-host histogram weighted by its host
        // multiplier folds into the fleet cell via `acc += &(host *
        // weight)`. Pinned concretely on [`DiffLineKind`] across two
        // hosts with distinct weights so the per-host scaling reads
        // off a non-trivial cell distribution and the weighted-sum
        // matches the equivalent repeated-`+=`-by-host expansion.
        let host_a: AxisHistogram<DiffLineKind> = [DiffLineKind::Added, DiffLineKind::Removed]
            .into_iter()
            .collect();
        let host_b: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Context,
            DiffLineKind::Context,
            DiffLineKind::Added,
        ]
        .into_iter()
        .collect();

        let weight_a = 2usize;
        let weight_b = 3usize;

        let via_scaled_add = host_a.clone() * weight_a + &(host_b.clone() * weight_b);

        let mut via_repeated: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
        for _ in 0..weight_a {
            via_repeated += &host_a;
        }
        for _ in 0..weight_b {
            via_repeated += &host_b;
        }

        assert_eq!(via_scaled_add, via_repeated);

        // Concrete: a * 2 yields (Added: 2, Removed: 2, Context: 0);
        // b * 3 yields (Added: 3, Removed: 0, Context: 6); sum yields
        // (Added: 5, Removed: 2, Context: 6).
        assert_eq!(via_scaled_add.count(DiffLineKind::Added), 5);
        assert_eq!(via_scaled_add.count(DiffLineKind::Removed), 2);
        assert_eq!(via_scaled_add.count(DiffLineKind::Context), 6);
        assert_eq!(via_scaled_add.total(), 13);
    }

    fn assert_mul_left_factor_equals_mul_right_factor<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The commutative-scalar-multiplication law on the `*`
        // operator surface: `n * hist` is pointwise equal to `hist *
        // n`. The canonical std-`Duration` peer (`u32 * Duration ==
        // Duration * u32`) lifted to the `AxisHistogram<A>` surface —
        // the left-scalar entry delegates to the right-scalar form so
        // the per-cell `*=` loop lives at exactly one site. Pinned at
        // factors 0, 1, 2, 5 so the absorbing, identity, and two
        // non-trivial multipliers witness the commutativity uniformly
        // across every closed-axis implementor.
        let hist: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for factor in [0usize, 1, 2, 5] {
            let via_left = factor * hist.clone();
            let via_right = hist.clone() * factor;
            assert_eq!(
                via_left,
                via_right,
                "{factor} * hist must equal hist * {factor} on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    #[test]
    fn axis_histogram_mul_left_factor_equals_mul_right_factor_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_mul_left_factor_equals_mul_right_factor::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_mul_left_factor_distributes_over_add_for_diff_line_kind() {
        // The semimodule distributivity law on the left-scalar
        // operator surface: `n * (a + &b)` is pointwise equal to `n *
        // a + &(n * b)`. The (right-scalar, left-scalar) pair of `*`
        // surfaces composes through one consistent distributive law,
        // peer to the right-scalar
        // `axis_histogram_mul_distributes_over_add_for_diff_line_kind`
        // pin on the same algebraic surface. Pinned concretely on
        // [`DiffLineKind`] across two non-trivial histograms and a
        // non-identity / non-absorbing factor so the distributivity
        // reads off a non-trivial cell distribution from the
        // left-scalar entry surface.
        let a: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
        ]
        .into_iter()
        .collect();
        let b: AxisHistogram<DiffLineKind> = [DiffLineKind::Removed, DiffLineKind::Context]
            .into_iter()
            .collect();
        let factor = 3usize;

        let via_scale_after = factor * (a.clone() + &b);
        let via_scale_first = factor * a.clone() + &(factor * b.clone());

        assert_eq!(via_scale_after, via_scale_first);

        // Concrete cell counts: a + b yields (Added: 2, Removed: 2,
        // Context: 1); scaled left by 3 yields (6, 6, 3).
        assert_eq!(via_scale_after.count(DiffLineKind::Added), 6);
        assert_eq!(via_scale_after.count(DiffLineKind::Removed), 6);
        assert_eq!(via_scale_after.count(DiffLineKind::Context), 3);
        assert_eq!(via_scale_after.total(), 15);
    }

    fn assert_mul_left_factor_borrowed_equals_owned<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The (owned-RHS, borrowed-RHS) idiom-peer agreement law on
        // the left-scalar `*` operator surface: `n * &hist` is
        // pointwise equal to `n * hist.clone()`. The canonical
        // (`Mul<Owned> for usize`, `Mul<&Owned> for usize`) idiom-peer
        // pair on the left-scalar surface, mirroring the (`Add<Self>`,
        // `Add<&Self>`) pair on the additive monoid — same projection,
        // two RHS-ownership shapes, both lowering through the
        // right-scalar `Mul<usize> for AxisHistogram<A>` form at one
        // site so the per-cell `*=` loop lives at one site underneath
        // every left-scalar entry. Pinned at factors 0, 1, 2, 5 so the
        // absorbing, identity, and two non-trivial multipliers witness
        // the borrowed-owned agreement uniformly across every closed-
        // axis implementor.
        let hist: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for factor in [0usize, 1, 2, 5] {
            let via_borrowed = factor * &hist;
            let via_owned = factor * hist.clone();
            assert_eq!(
                via_borrowed,
                via_owned,
                "{factor} * &hist must equal {factor} * hist.clone() on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    #[test]
    fn axis_histogram_mul_left_factor_borrowed_equals_owned_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_mul_left_factor_borrowed_equals_owned::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_mul_left_factor_borrowed_distributes_over_add_for_diff_line_kind() {
        // The semimodule distributivity law on the borrowed-RHS
        // left-scalar operator surface: `n * &(a + &b)` is pointwise
        // equal to `n * &a + &(n * &b)`. The (right-scalar, left-
        // scalar-owned, left-scalar-borrowed) triple of `*` surfaces
        // composes through one consistent distributive law, peer to
        // the `axis_histogram_mul_left_factor_distributes_over_add_for_diff_line_kind`
        // pin on the owned-RHS left-scalar side and the right-scalar
        // `axis_histogram_mul_distributes_over_add_for_diff_line_kind`
        // pin on the same algebraic surface. Pinned concretely on
        // [`DiffLineKind`] across two non-trivial histograms and a
        // non-identity / non-absorbing factor so the distributivity
        // reads off a non-trivial cell distribution from the borrowed-
        // RHS left-scalar entry surface, with `a` and `b` retained
        // intact across the projection (the borrowed-RHS form's
        // ownership contract).
        let a: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
        ]
        .into_iter()
        .collect();
        let b: AxisHistogram<DiffLineKind> = [DiffLineKind::Removed, DiffLineKind::Context]
            .into_iter()
            .collect();
        let factor = 3usize;

        let sum_ab = a.clone() + &b;
        let via_scale_after = factor * &sum_ab;
        let via_scale_first = factor * &a + &(factor * &b);

        assert_eq!(via_scale_after, via_scale_first);

        // Borrowed-RHS contract: `a` and `b` survive the projection
        // intact (the original counts read back through their owned
        // surfaces after the borrowed-RHS scalar action).
        assert_eq!(a.count(DiffLineKind::Added), 2);
        assert_eq!(a.count(DiffLineKind::Removed), 1);
        assert_eq!(b.count(DiffLineKind::Removed), 1);
        assert_eq!(b.count(DiffLineKind::Context), 1);

        // Concrete cell counts: a + b yields (Added: 2, Removed: 2,
        // Context: 1); scaled left by 3 yields (6, 6, 3).
        assert_eq!(via_scale_after.count(DiffLineKind::Added), 6);
        assert_eq!(via_scale_after.count(DiffLineKind::Removed), 6);
        assert_eq!(via_scale_after.count(DiffLineKind::Context), 3);
        assert_eq!(via_scale_after.total(), 15);
    }

    fn assert_mul_right_factor_borrowed_equals_owned<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The (owned-receiver, borrowed-receiver) idiom-peer agreement
        // law on the right-scalar `*` operator surface: `&hist * n` is
        // pointwise equal to `hist.clone() * n`. The symmetric peer of
        // the (`Mul<Owned> for usize`, `Mul<&Owned> for usize`)
        // borrowed-RHS agreement on the left-scalar surface — same
        // projection, two receiver-ownership shapes, both lowering
        // through the in-place `MulAssign<usize>` form at one site so
        // the per-cell `*=` loop lives at one site underneath every
        // right-scalar entry. Pinned at factors 0, 1, 2, 5 so the
        // absorbing, identity, and two non-trivial multipliers witness
        // the borrowed-owned agreement uniformly across every closed-
        // axis implementor.
        let hist: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for factor in [0usize, 1, 2, 5] {
            let via_borrowed = &hist * factor;
            let via_owned = hist.clone() * factor;
            assert_eq!(
                via_borrowed,
                via_owned,
                "&hist * {factor} must equal hist.clone() * {factor} on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    #[test]
    fn axis_histogram_mul_right_factor_borrowed_equals_owned_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_mul_right_factor_borrowed_equals_owned::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    fn assert_mul_right_factor_borrowed_equals_left_factor_borrowed<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The symmetric commutativity-peer law on the borrowed-
        // receiver surfaces: `&hist * n` is pointwise equal to
        // `n * &hist`. The borrowed-side peer of the owned-receiver
        // commutativity law `hist * n == n * hist` — same projection
        // routed through the borrowed entries on both sides, both
        // lowering through one per-cell `*=` traversal underneath. The
        // four entry surfaces (`hist * n`, `&hist * n`, `n * hist`,
        // `n * &hist`) now agree pointwise at the operator-surface
        // level. Pinned at factors 0, 1, 2, 5 so the absorbing,
        // identity, and two non-trivial multipliers witness the
        // borrowed-side commutativity uniformly across every closed-
        // axis implementor.
        let hist: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for factor in [0usize, 1, 2, 5] {
            let via_right = &hist * factor;
            let via_left = factor * &hist;
            assert_eq!(
                via_right,
                via_left,
                "&hist * {factor} must equal {factor} * &hist on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    #[test]
    fn axis_histogram_mul_right_factor_borrowed_equals_left_factor_borrowed_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_mul_right_factor_borrowed_equals_left_factor_borrowed::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_mul_right_factor_borrowed_distributes_over_add_for_diff_line_kind() {
        // The semimodule distributivity law on the borrowed-receiver
        // right-scalar operator surface: `&(a + &b) * n` is pointwise
        // equal to `&a * n + &(&b * n)`. The (right-scalar-owned,
        // right-scalar-borrowed) pair of `*` surfaces composes through
        // one consistent distributive law, peer to the
        // `axis_histogram_mul_distributes_over_add_for_diff_line_kind`
        // pin on the owned-receiver right-scalar side and the
        // `axis_histogram_mul_left_factor_borrowed_distributes_over_add_for_diff_line_kind`
        // pin on the borrowed-RHS left-scalar surface. Pinned
        // concretely on [`DiffLineKind`] across two non-trivial
        // histograms and a non-identity / non-absorbing factor so the
        // distributivity reads off a non-trivial cell distribution
        // from the borrowed-receiver right-scalar entry, with `a` and
        // `b` retained intact across the projection (the borrowed-
        // receiver form's ownership contract).
        let a: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
        ]
        .into_iter()
        .collect();
        let b: AxisHistogram<DiffLineKind> = [DiffLineKind::Removed, DiffLineKind::Context]
            .into_iter()
            .collect();
        let factor = 3usize;

        let sum_ab = a.clone() + &b;
        let via_scale_after = &sum_ab * factor;
        let via_scale_first = &a * factor + &(&b * factor);

        assert_eq!(via_scale_after, via_scale_first);

        // Borrowed-receiver contract: `a` and `b` survive the
        // projection intact (the original counts read back through
        // their owned surfaces after the borrowed-receiver scalar
        // action).
        assert_eq!(a.count(DiffLineKind::Added), 2);
        assert_eq!(a.count(DiffLineKind::Removed), 1);
        assert_eq!(b.count(DiffLineKind::Removed), 1);
        assert_eq!(b.count(DiffLineKind::Context), 1);

        // Concrete cell counts: a + b yields (Added: 2, Removed: 2,
        // Context: 1); scaled right by 3 yields (6, 6, 3).
        assert_eq!(via_scale_after.count(DiffLineKind::Added), 6);
        assert_eq!(via_scale_after.count(DiffLineKind::Removed), 6);
        assert_eq!(via_scale_after.count(DiffLineKind::Context), 3);
        assert_eq!(via_scale_after.total(), 15);
    }

    // ---- AxisHistogram truncating-division trait-uniform laws ----
    //
    // The (Div<usize>, DivAssign<usize>) scalar-action surface closes
    // the canonical Rust `(Mul, MulAssign, Div, DivAssign)` operator
    // quartet every primitive that carries a `usize`-action on a
    // numeric surface exposes (peer of `std::time::Duration` carrying
    // both `Duration * u32` / `*=` and `Duration / u32` / `/=`). The
    // trait-uniform laws below pin the truncating-division surface's
    // contract uniformly across every [`ClosedAxis`] implementor:
    // the one-divisor identity (preserves the counts vector); cell-
    // level truncating division (every cell `c` becomes `c /
    // divisor`); the (Div, DivAssign) operator pair agrees pointwise;
    // mul-then-div round-trips on a non-zero factor with no overflow
    // (the canonical exact-multiplication / exact-truncating-division
    // recovery identity).

    fn assert_div_assign_one_divisor_is_identity<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The one-divisor identity law on `DivAssign<usize>`: `hist /=
        // 1` leaves the histogram unchanged. The identity element of
        // the scalar monoid `(usize, *, 1)` preserves the counts
        // vector pointwise on the truncating-division surface. Pinned
        // over the (axis-cover + once-more) histogram so every cell
        // carries a positive count and the equality reads off every
        // ordinal.
        let cover: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        let mut divided = cover.clone();
        divided /= 1;
        assert_eq!(
            divided,
            cover,
            "hist /= 1 must leave hist unchanged on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_div_assign_scales_cells_by_truncating_division<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The cell-level truncating-division law on `DivAssign<usize>`:
        // every cell `v` has its count replaced by the stdlib usize
        // truncating-division `before.count(v) / divisor`. Pinned at
        // divisor 3 over the (axis-cover ×7)-then-trim histogram so
        // every cell carries a count of 7 pre-division and lands at
        // 7 / 3 = 2 post-division (a non-trivial truncation that
        // reads off every ordinal independently).
        let mut pre = AxisHistogram::<A>::empty();
        for _ in 0..7 {
            pre += &axis_iter::<A>().collect::<AxisHistogram<A>>();
        }
        let divisor = 3usize;
        let mut divided = pre.clone();
        divided /= divisor;
        for cell in axis_iter::<A>() {
            assert_eq!(
                divided.count(cell),
                pre.count(cell) / divisor,
                "hist /= {divisor} cell {cell:?} must equal pre.count / {divisor} on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_div_assign_inverts_mul_assign_on_uniform_cover<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The mul-then-div round-trip law on the scalar-action
        // surface: `hist *= factor; hist /= factor;` recovers `hist`
        // pointwise when `factor > 0` and no per-cell multiplication
        // overflowed. Every cell `c` satisfies `(c * factor) / factor
        // == c` under usize arithmetic for `factor > 0` (the
        // multiplication is exact; the truncating-division step has
        // no fractional remainder to lose). Pinned at factors 1, 2,
        // 5, 11 over the axis-cover histogram so the round-trip reads
        // off the identity factor plus three non-trivial multipliers
        // uniformly.
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        for factor in [1usize, 2, 5, 11] {
            let mut round_trip = cover.clone();
            round_trip *= factor;
            round_trip /= factor;
            assert_eq!(
                round_trip,
                cover,
                "(hist *= {factor}; hist /= {factor}) must recover hist on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_div_equals_div_assign<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The (Div, DivAssign) idiom-peer equivalence on the
        // truncating-division surface: `hist / divisor` reads the same
        // histogram as `let mut a = hist.clone(); a /= divisor; a`.
        // The canonical Rust owned/in-place operator peer pair —
        // `impl Div<usize>` and `impl DivAssign<usize>` agreeing
        // pointwise — every stdlib truncating-division operator
        // surface exposes (`Duration / u32 ==` a `Duration` whose
        // internal `/=` step is the same fold). Pinned at divisors 1,
        // 2, 5, 11 so the identity divisor and three non-trivial
        // divisors witness the equivalence.
        let hist: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for divisor in [1usize, 2, 5, 11] {
            let via_div = hist.clone() / divisor;
            let mut via_div_assign = hist.clone();
            via_div_assign /= divisor;
            assert_eq!(
                via_div,
                via_div_assign,
                "hist / {divisor} must equal `let mut a = hist; a /= {divisor}; a` on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    #[test]
    fn axis_histogram_div_assign_one_divisor_is_identity_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_div_assign_one_divisor_is_identity::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_div_assign_scales_cells_by_truncating_division_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_div_assign_scales_cells_by_truncating_division::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_div_assign_inverts_mul_assign_on_uniform_cover_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_div_assign_inverts_mul_assign_on_uniform_cover::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_div_equals_div_assign_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_div_equals_div_assign::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_div_witnessed_on_non_trivial_cells_for_diff_line_kind() {
        // The truncating-integer-division surface on the `/` operator
        // against [`DiffLineKind`] — the three-cell axis (Added,
        // Removed, Context) lets the per-cell truncation read off
        // non-vacuously across a mixed-remainder pre-state. `pre`
        // carries counts (Added: 7, Removed: 5, Context: 4); `pre / 2`
        // reads (Added: 3, Removed: 2, Context: 2) — every cell
        // independently truncates toward zero under usize arithmetic.
        // Mirrors the `axis_histogram_mul_distributes_over_add_for_diff_line_kind`
        // pin on the multiplicative side; reads it off again on the
        // truncating-division side to pin the dual scalar surface
        // through one concrete cell distribution.
        let pre: AxisHistogram<DiffLineKind> = [
            (DiffLineKind::Added, 7usize),
            (DiffLineKind::Removed, 5),
            (DiffLineKind::Context, 4),
        ]
        .into_iter()
        .collect();
        let divisor = 2usize;

        let via_op = pre.clone() / divisor;
        assert_eq!(via_op.count(DiffLineKind::Added), 3);
        assert_eq!(via_op.count(DiffLineKind::Removed), 2);
        assert_eq!(via_op.count(DiffLineKind::Context), 2);
        assert_eq!(via_op.total(), 7);

        // (Div, DivAssign) operator-peer agreement at the concrete
        // pin: `hist / divisor` reads the same histogram as the
        // in-place `/=` form.
        let mut via_assign = pre.clone();
        via_assign /= divisor;
        assert_eq!(via_op, via_assign);

        // One-divisor identity at the concrete pin: `hist / 1 ==
        // hist`.
        assert_eq!(pre.clone() / 1, pre);

        // Mul-Div round-trip on a non-zero factor at the concrete
        // pin: `(hist * factor) / factor == hist` when no per-cell
        // multiplication overflows. Witnessed at factor 4 against the
        // pre-state, which scales to (Added: 28, Removed: 20,
        // Context: 16) and divides back to the input exactly.
        let factor = 4usize;
        let round_trip = (pre.clone() * factor) / factor;
        assert_eq!(round_trip, pre);

        // Inverse-order composition: `(hist / divisor) * divisor`
        // recovers the pre-state only when every cell is exactly
        // divisible — at divisor 2 against (7, 5, 4), only Context
        // (4) survives the round-trip; Added (7) and Removed (5)
        // lose their odd remainder. Pinned to read off the truncation
        // semantics through the operator surface (not just through
        // the inherent-method side): `(7 / 2) * 2 = 6`, `(5 / 2) * 2
        // = 4`, `(4 / 2) * 2 = 4`.
        let lossy = (pre.clone() / divisor) * divisor;
        assert_eq!(lossy.count(DiffLineKind::Added), 6);
        assert_eq!(lossy.count(DiffLineKind::Removed), 4);
        assert_eq!(lossy.count(DiffLineKind::Context), 4);
        assert_ne!(lossy, pre);
    }

    fn assert_div_right_divisor_borrowed_equals_owned<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The (owned-receiver, borrowed-receiver) idiom-peer agreement
        // law on the truncating-division `/` operator surface: `&hist
        // / divisor` is pointwise equal to `hist.clone() / divisor`.
        // The truncating-division dual of the `&hist * n ==
        // hist.clone() * n` borrowed-owned receiver agreement law on
        // the multiplicative side — same projection, two receiver-
        // ownership shapes, both lowering through the in-place
        // `DivAssign<usize>` form at one site so the per-cell `/=`
        // loop lives at one site underneath every truncating-division
        // entry. Pinned at divisors 1, 2, 5, 11 so the identity and
        // three non-trivial divisors witness the borrowed-owned
        // agreement uniformly across every closed-axis implementor.
        let hist: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for divisor in [1usize, 2, 5, 11] {
            let via_borrowed = &hist / divisor;
            let via_owned = hist.clone() / divisor;
            assert_eq!(
                via_borrowed,
                via_owned,
                "&hist / {divisor} must equal hist.clone() / {divisor} on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    #[test]
    fn axis_histogram_div_right_divisor_borrowed_equals_owned_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_div_right_divisor_borrowed_equals_owned::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_div_right_divisor_borrowed_witnessed_on_non_trivial_cells_for_diff_line_kind()
    {
        // The borrowed-receiver truncating-division surface on the `/`
        // operator against [`DiffLineKind`] — the dual of
        // `axis_histogram_div_witnessed_on_non_trivial_cells_for_diff_line_kind`
        // on the borrowed-receiver entry, peer to
        // `axis_histogram_mul_right_factor_borrowed_distributes_over_add_for_diff_line_kind`
        // on the borrowed-receiver scalar-multiplication side. `pre`
        // carries counts (Added: 7, Removed: 5, Context: 4); `&pre /
        // 2` reads (Added: 3, Removed: 2, Context: 2) — every cell
        // independently truncates toward zero under usize arithmetic
        // through the borrowed-receiver entry, with `pre` retained
        // intact across the projection (the borrowed-receiver form's
        // ownership contract).
        let pre: AxisHistogram<DiffLineKind> = [
            (DiffLineKind::Added, 7usize),
            (DiffLineKind::Removed, 5),
            (DiffLineKind::Context, 4),
        ]
        .into_iter()
        .collect();
        let divisor = 2usize;

        let via_borrowed = &pre / divisor;
        assert_eq!(via_borrowed.count(DiffLineKind::Added), 3);
        assert_eq!(via_borrowed.count(DiffLineKind::Removed), 2);
        assert_eq!(via_borrowed.count(DiffLineKind::Context), 2);
        assert_eq!(via_borrowed.total(), 7);

        // Borrowed-receiver contract: `pre` survives the projection
        // intact (the original counts read back through their owned
        // surface after the borrowed-receiver truncating division).
        assert_eq!(pre.count(DiffLineKind::Added), 7);
        assert_eq!(pre.count(DiffLineKind::Removed), 5);
        assert_eq!(pre.count(DiffLineKind::Context), 4);
        assert_eq!(pre.total(), 16);

        // (owned-receiver, borrowed-receiver) idiom-peer agreement at
        // the concrete pin: `&pre / divisor` reads the same histogram
        // as `pre.clone() / divisor`.
        assert_eq!(via_borrowed, pre.clone() / divisor);

        // One-divisor identity at the concrete pin on the borrowed-
        // receiver entry: `&pre / 1 == pre.clone()`.
        assert_eq!(&pre / 1, pre);
    }

    // ---- AxisHistogram Euclidean-remainder trait-uniform laws ----
    //
    // The (Rem<usize>, RemAssign<usize>) scalar-action surface closes
    // the canonical Rust `(Mul, MulAssign, Div, DivAssign, Rem,
    // RemAssign)` integer-arithmetic operator sextet every primitive
    // that carries a `usize`-action on a numeric surface exposes (the
    // same sextet `usize`, `u32`, `i32` carry at the cell level). The
    // trait-uniform laws below pin the Euclidean-remainder surface's
    // contract uniformly across every [`ClosedAxis`] implementor: the
    // one-divisor zero law (every cell `c % 1 == 0`); cell-level
    // Euclidean remainder (every cell `c` becomes `c % divisor`); the
    // (Rem, RemAssign) operator pair agrees pointwise; the div-rem
    // identity `(hist / d) * d + (hist % d) == hist` (the canonical
    // defining equation of the Euclidean-division pair); the
    // remainder-bound law (`(hist % d).count(v) < d` for every cell).

    fn assert_rem_assign_one_divisor_zeros_histogram<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The one-divisor zero law on `RemAssign<usize>`: `hist %= 1`
        // zeros every cell of the histogram. The identity element of
        // the scalar monoid `(usize, *, 1)` is the absorbing element
        // of the remainder monoid `(usize, %, _)`: every cell `c`
        // satisfies `c % 1 == 0`. Pinned over the (axis-cover +
        // once-more) histogram so every cell carries a positive count
        // pre-rem and the equality reads off every ordinal.
        let cover: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        let mut reduced = cover;
        reduced %= 1;
        assert_eq!(
            reduced,
            AxisHistogram::<A>::empty(),
            "hist %= 1 must zero every cell on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_rem_assign_scales_cells_by_remainder<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The cell-level Euclidean-remainder law on `RemAssign<usize>`:
        // every cell `v` has its count replaced by the stdlib usize
        // remainder `before.count(v) % divisor`. Pinned at divisor 3
        // over the (axis-cover ×7)-then-trim histogram so every cell
        // carries a count of 7 pre-rem and lands at 7 % 3 = 1 post-rem
        // (a non-trivial remainder that reads off every ordinal
        // independently).
        let mut pre = AxisHistogram::<A>::empty();
        for _ in 0..7 {
            pre += &axis_iter::<A>().collect::<AxisHistogram<A>>();
        }
        let divisor = 3usize;
        let mut reduced = pre.clone();
        reduced %= divisor;
        for cell in axis_iter::<A>() {
            assert_eq!(
                reduced.count(cell),
                pre.count(cell) % divisor,
                "hist %= {divisor} cell {cell:?} must equal pre.count % {divisor} on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_rem_assign_completes_div_rem_identity<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The div-rem identity law on the Euclidean-division pair:
        // `(hist / divisor) * divisor + (hist % divisor) == hist` for
        // `divisor > 0`. The canonical defining equation of the
        // Euclidean-division pair lifted from the cell type to the
        // histogram surface: every cell `c` satisfies `(c / divisor) *
        // divisor + (c % divisor) == c` under usize arithmetic, and
        // the lift through the additive monoid agrees pointwise.
        // Pinned at divisors 2, 3, 5, 11 over the (axis-cover ×7)
        // histogram so every cell carries a count of 7 pre-decomposition
        // and the identity reads across both even and odd divisors
        // independently.
        let mut pre = AxisHistogram::<A>::empty();
        for _ in 0..7 {
            pre += &axis_iter::<A>().collect::<AxisHistogram<A>>();
        }
        for divisor in [2usize, 3, 5, 11] {
            let recomposed = (pre.clone() / divisor) * divisor + &(pre.clone() % divisor);
            assert_eq!(
                recomposed,
                pre,
                "(hist / {divisor}) * {divisor} + (hist % {divisor}) must equal hist on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_rem_assign_bounds_cells_below_divisor<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The remainder-bound law on `RemAssign<usize>`: every cell
        // `(hist %= divisor).count(v) < divisor` for `divisor > 0`.
        // The canonical Euclidean-remainder bound lifted pointwise.
        // Pinned at divisors 2, 3, 5, 11 over the (axis-cover ×7)
        // histogram so the bound reads across both small and large
        // remainder ranges.
        let mut pre = AxisHistogram::<A>::empty();
        for _ in 0..7 {
            pre += &axis_iter::<A>().collect::<AxisHistogram<A>>();
        }
        for divisor in [2usize, 3, 5, 11] {
            let mut reduced = pre.clone();
            reduced %= divisor;
            for cell in axis_iter::<A>() {
                assert!(
                    reduced.count(cell) < divisor,
                    "hist %= {divisor} cell {cell:?} count {} must be < {divisor} on axis {}",
                    reduced.count(cell),
                    std::any::type_name::<A>(),
                );
            }
        }
    }

    fn assert_rem_equals_rem_assign<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The (Rem, RemAssign) idiom-peer equivalence on the
        // Euclidean-remainder surface: `hist % divisor` reads the same
        // histogram as `let mut a = hist.clone(); a %= divisor; a`.
        // The canonical Rust owned/in-place operator peer pair —
        // `impl Rem<usize>` and `impl RemAssign<usize>` agreeing
        // pointwise — every stdlib Euclidean-remainder operator
        // surface exposes (`usize % usize ==` a `usize` whose internal
        // `%=` step is the same fold). Pinned at divisors 2, 3, 5, 11
        // so the small-divisor and larger-divisor cases both witness
        // the equivalence.
        let hist: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for divisor in [2usize, 3, 5, 11] {
            let via_rem = hist.clone() % divisor;
            let mut via_rem_assign = hist.clone();
            via_rem_assign %= divisor;
            assert_eq!(
                via_rem,
                via_rem_assign,
                "hist % {divisor} must equal `let mut a = hist; a %= {divisor}; a` on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    #[test]
    fn axis_histogram_rem_assign_one_divisor_zeros_histogram_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_rem_assign_one_divisor_zeros_histogram::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_rem_assign_scales_cells_by_remainder_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_rem_assign_scales_cells_by_remainder::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_rem_assign_completes_div_rem_identity_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_rem_assign_completes_div_rem_identity::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_rem_assign_bounds_cells_below_divisor_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_rem_assign_bounds_cells_below_divisor::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_rem_equals_rem_assign_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_rem_equals_rem_assign::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_rem_witnessed_on_non_trivial_cells_for_diff_line_kind() {
        // The Euclidean-remainder surface on the `%` operator against
        // [`DiffLineKind`] — the three-cell axis (Added, Removed,
        // Context) lets the per-cell remainder read off non-vacuously
        // across a mixed-remainder pre-state. `pre` carries counts
        // (Added: 7, Removed: 5, Context: 4); `pre % 2` reads
        // (Added: 1, Removed: 1, Context: 0) — every cell independently
        // reduces under usize Euclidean-remainder arithmetic. Mirrors
        // the `axis_histogram_div_witnessed_on_non_trivial_cells_for_diff_line_kind`
        // pin on the truncating-division side; reads it off again on
        // the Euclidean-remainder side to pin the dual scalar surface
        // through one concrete cell distribution.
        let pre: AxisHistogram<DiffLineKind> = [
            (DiffLineKind::Added, 7usize),
            (DiffLineKind::Removed, 5),
            (DiffLineKind::Context, 4),
        ]
        .into_iter()
        .collect();
        let divisor = 2usize;

        let via_op = pre.clone() % divisor;
        assert_eq!(via_op.count(DiffLineKind::Added), 1);
        assert_eq!(via_op.count(DiffLineKind::Removed), 1);
        assert_eq!(via_op.count(DiffLineKind::Context), 0);
        assert_eq!(via_op.total(), 2);

        // (Rem, RemAssign) operator-peer agreement at the concrete
        // pin: `hist % divisor` reads the same histogram as the
        // in-place `%=` form.
        let mut via_assign = pre.clone();
        via_assign %= divisor;
        assert_eq!(via_op, via_assign);

        // One-divisor zero law at the concrete pin: `hist % 1` is
        // pointwise equal to the empty histogram.
        let one_divisor = std::hint::black_box(1usize);
        assert_eq!(
            pre.clone() % one_divisor,
            AxisHistogram::<DiffLineKind>::empty()
        );

        // Div-Rem identity at the concrete pin:
        // `(pre / 2) * 2 + (pre % 2) == pre` reads (6 + 1, 4 + 1,
        // 4 + 0) = (7, 5, 4) — the canonical Euclidean-division
        // decomposition recovers the pre-state pointwise.
        let div_part = (pre.clone() / divisor) * divisor;
        let rem_part = pre.clone() % divisor;
        let recomposed = div_part + &rem_part;
        assert_eq!(recomposed, pre);

        // Remainder bound at the concrete pin: every cell of
        // `pre % 2` carries a count strictly less than 2.
        for cell in axis_iter::<DiffLineKind>() {
            assert!(via_op.count(cell) < divisor);
        }
    }

    fn assert_rem_right_divisor_borrowed_equals_owned<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The (owned-receiver, borrowed-receiver) idiom-peer agreement
        // law on the Euclidean-remainder `%` operator surface: `&hist %
        // divisor` is pointwise equal to `hist.clone() % divisor`. The
        // Euclidean-remainder dual of the `&hist / divisor ==
        // hist.clone() / divisor` borrowed-owned receiver agreement law
        // on the truncating-division side and the `&hist * n ==
        // hist.clone() * n` borrowed-owned receiver agreement law on
        // the multiplicative side — same projection, two receiver-
        // ownership shapes, both lowering through the in-place
        // `RemAssign<usize>` form at one site so the per-cell `%=` loop
        // lives at one site underneath every Euclidean-remainder entry.
        // Pinned at divisors 1, 2, 5, 11 so the zero-divisor identity
        // (`% 1` zeros every cell) and three non-trivial divisors
        // witness the borrowed-owned agreement uniformly across every
        // closed-axis implementor.
        let hist: AxisHistogram<A> = axis_iter::<A>().chain(axis_iter::<A>()).collect();
        for divisor in [1usize, 2, 5, 11] {
            let via_borrowed = &hist % divisor;
            let via_owned = hist.clone() % divisor;
            assert_eq!(
                via_borrowed,
                via_owned,
                "&hist % {divisor} must equal hist.clone() % {divisor} on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    #[test]
    fn axis_histogram_rem_right_divisor_borrowed_equals_owned_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_rem_right_divisor_borrowed_equals_owned::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_rem_right_divisor_borrowed_witnessed_on_non_trivial_cells_for_diff_line_kind()
    {
        // The borrowed-receiver Euclidean-remainder surface on the `%`
        // operator against [`DiffLineKind`] — the dual of
        // `axis_histogram_rem_witnessed_on_non_trivial_cells_for_diff_line_kind`
        // on the borrowed-receiver entry, peer to
        // `axis_histogram_div_right_divisor_borrowed_witnessed_on_non_trivial_cells_for_diff_line_kind`
        // on the borrowed-receiver truncating-division side. `pre`
        // carries counts (Added: 7, Removed: 5, Context: 4); `&pre % 2`
        // reads (Added: 1, Removed: 1, Context: 0) — every cell
        // independently reduces under usize Euclidean-remainder
        // arithmetic through the borrowed-receiver entry, with `pre`
        // retained intact across the projection (the borrowed-receiver
        // form's ownership contract).
        let pre: AxisHistogram<DiffLineKind> = [
            (DiffLineKind::Added, 7usize),
            (DiffLineKind::Removed, 5),
            (DiffLineKind::Context, 4),
        ]
        .into_iter()
        .collect();
        let divisor = 2usize;

        let via_borrowed = &pre % divisor;
        assert_eq!(via_borrowed.count(DiffLineKind::Added), 1);
        assert_eq!(via_borrowed.count(DiffLineKind::Removed), 1);
        assert_eq!(via_borrowed.count(DiffLineKind::Context), 0);
        assert_eq!(via_borrowed.total(), 2);

        // Borrowed-receiver contract: `pre` survives the projection
        // intact (the original counts read back through their owned
        // surface after the borrowed-receiver Euclidean-remainder).
        assert_eq!(pre.count(DiffLineKind::Added), 7);
        assert_eq!(pre.count(DiffLineKind::Removed), 5);
        assert_eq!(pre.count(DiffLineKind::Context), 4);
        assert_eq!(pre.total(), 16);

        // (owned-receiver, borrowed-receiver) idiom-peer agreement at
        // the concrete pin: `&pre % divisor` reads the same histogram
        // as `pre.clone() % divisor`.
        assert_eq!(via_borrowed, pre.clone() % divisor);

        // One-divisor zero law at the concrete pin on the borrowed-
        // receiver entry: `&pre % 1` is pointwise equal to the empty
        // histogram. Uses `black_box` to pin the constant against
        // const-folding so the panic-free divisor traversal is
        // observably exercised.
        let one_divisor = std::hint::black_box(1usize);
        assert_eq!(&pre % one_divisor, AxisHistogram::<DiffLineKind>::empty());

        // Div-Rem identity at the concrete pin through the borrowed-
        // receiver entry on both sides:
        // `(&pre / 2) * 2 + (&pre % 2) == pre` recovers the pre-state
        // pointwise. Reads off the canonical Euclidean-division
        // decomposition through the borrowed-receiver Div and Rem
        // surfaces composed.
        let div_part = (&pre / divisor) * divisor;
        let rem_part = &pre % divisor;
        let recomposed = div_part + &rem_part;
        assert_eq!(recomposed, pre);

        // Remainder bound at the concrete pin through the borrowed-
        // receiver entry: every cell of `&pre % 2` carries a count
        // strictly less than 2.
        for cell in axis_iter::<DiffLineKind>() {
            assert!(via_borrowed.count(cell) < divisor);
        }
    }

    // ---- AxisHistogram::dominant_cell trait-uniform laws ----
    //
    // Three trait-uniform laws reach every [`ClosedAxis`] implementor
    // through [`for_each_closed_axis_implementor`] so the per-axis
    // dominant_cell projection's contract holds uniformly without
    // per-axis test duplication: empty → None; singleton → Some(K) on
    // every cell K; uniform axis-cover → Some(first cell in
    // declaration order). Concrete tie-breaking and merge-interaction
    // pins follow below on [`DiffLineKind`].

    fn assert_dominant_cell_empty_is_none<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        let hist = AxisHistogram::<A>::empty();
        assert_eq!(
            hist.dominant_cell(),
            None,
            "empty histogram dominant_cell must be None on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_dominant_cell_singleton_picks_observed_cell<A>()
    where
        A: ClosedAxis + std::fmt::Debug + PartialEq,
    {
        // For every cell of the axis: a histogram built from one
        // observation of that cell has dominant_cell = Some(cell).
        // Pins the (singleton → unique-max) law uniformly: every
        // closed-axis implementor's `dominant_cell` recovers the
        // observed cell from a one-observation history.
        for observed in axis_iter::<A>() {
            let hist: AxisHistogram<A> = std::iter::once(observed).collect();
            assert_eq!(
                hist.dominant_cell(),
                Some(observed),
                "singleton dominant_cell must equal the observed cell {observed:?} \
                 on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_dominant_cell_axis_cover_picks_first_cell<A>()
    where
        A: ClosedAxis + std::fmt::Debug + PartialEq,
    {
        // Observing every cell exactly once produces a uniform
        // histogram (every cell at 1, count maximum tied across the
        // axis); `dominant_cell` must return the first cell in
        // declaration order — the documented tie-breaking rule.
        // Pinned uniformly: every closed-axis implementor's
        // declaration-order tie-breaking lands at the head of
        // [`ClosedAxis::ALL`].
        let hist: AxisHistogram<A> = axis_iter::<A>().collect();
        let first = axis_iter::<A>().next().expect(
            "every ClosedAxis implementor has at least one variant per the ClosedAxis contract",
        );
        assert_eq!(
            hist.dominant_cell(),
            Some(first),
            "uniform axis-cover histogram dominant_cell must be the first cell \
             in declaration order on axis {}",
            std::any::type_name::<A>(),
        );
    }

    #[test]
    fn axis_histogram_dominant_cell_empty_is_none_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_dominant_cell_empty_is_none::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_dominant_cell_singleton_picks_observed_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_dominant_cell_singleton_picks_observed_cell::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_dominant_cell_axis_cover_picks_first_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_dominant_cell_axis_cover_picks_first_cell::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_dominant_cell_returns_strict_max_when_unique() {
        // Concrete pin on the unique-maximum case: observing Added
        // twice and Removed / Context once each yields the strict max
        // at Added. The cell returned must be the unique-max cell
        // regardless of declaration order.
        let input = [
            DiffLineKind::Removed,
            DiffLineKind::Added,
            DiffLineKind::Context,
            DiffLineKind::Added,
        ];
        let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
        assert_eq!(hist.count(DiffLineKind::Added), 2);
        assert_eq!(hist.count(DiffLineKind::Removed), 1);
        assert_eq!(hist.count(DiffLineKind::Context), 1);
        assert_eq!(hist.dominant_cell(), Some(DiffLineKind::Added));
    }

    #[test]
    fn axis_histogram_dominant_cell_breaks_ties_in_declaration_order() {
        // Concrete pin on the tie-breaking rule: when multiple cells
        // share the maximum count, the first in [`ClosedAxis::ALL`]
        // declaration order wins. [`DiffLineKind::ALL`] starts with
        // [`DiffLineKind::Context`]; observing every cell once at the
        // same count must return [`DiffLineKind::Context`] regardless
        // of observation order. Pinned by varying observation order
        // (Added, Removed, Context vs Context, Removed, Added) and
        // asserting the result is invariant — observation order does
        // not leak through the projection.
        let first = DiffLineKind::ALL[0];
        let by_observation_order_a: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ]
        .into_iter()
        .collect();
        let by_observation_order_b: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Context,
            DiffLineKind::Removed,
            DiffLineKind::Added,
        ]
        .into_iter()
        .collect();
        assert_eq!(by_observation_order_a, by_observation_order_b);
        assert_eq!(by_observation_order_a.dominant_cell(), Some(first));
        assert_eq!(by_observation_order_b.dominant_cell(), Some(first));
    }

    #[test]
    fn axis_histogram_dominant_cell_after_merge_reflects_combined_counts() {
        // The (merge, dominant_cell) composition: dominant_cell on a
        // merged histogram reflects the pointwise-summed counts, not
        // either side's individual maximum. Pinned by constructing two
        // histograms with disagreeing maxima (lhs dominant at Added,
        // rhs dominant at Removed with a heavier tail), so the merge's
        // dominant cell is Removed even though Added is the lhs max.
        let lhs: AxisHistogram<DiffLineKind> = [DiffLineKind::Added, DiffLineKind::Added]
            .into_iter()
            .collect();
        let rhs: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Removed,
            DiffLineKind::Removed,
            DiffLineKind::Removed,
        ]
        .into_iter()
        .collect();
        assert_eq!(lhs.dominant_cell(), Some(DiffLineKind::Added));
        assert_eq!(rhs.dominant_cell(), Some(DiffLineKind::Removed));
        let merged = lhs.merge(&rhs);
        assert_eq!(merged.count(DiffLineKind::Added), 2);
        assert_eq!(merged.count(DiffLineKind::Removed), 3);
        assert_eq!(merged.dominant_cell(), Some(DiffLineKind::Removed));
    }

    #[test]
    fn axis_histogram_dominant_cell_iff_is_empty_is_false() {
        // Boundary pin: dominant_cell is Some iff is_empty is false.
        // Equivalence holds across both directions — an observation
        // history of any length yields Some, an empty history yields
        // None. Pinned concretely so the boundary discipline is named
        // at one site; the trait-uniform empty law above pins the
        // None direction across every implementor.
        let empty: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
        assert!(empty.is_empty());
        assert_eq!(empty.dominant_cell(), None);

        let singleton: AxisHistogram<DiffLineKind> =
            std::iter::once(DiffLineKind::Context).collect();
        assert!(!singleton.is_empty());
        assert!(singleton.dominant_cell().is_some());
    }

    // ---- AxisHistogram::distinct_cells trait-uniform laws ----
    //
    // Three trait-uniform laws reach every [`ClosedAxis`] implementor
    // through [`for_each_closed_axis_implementor`] so the per-axis
    // distinct_cells projection's contract holds uniformly without
    // per-axis test duplication: empty → 0; singleton → 1 on every
    // cell K; uniform axis-cover → axis_cardinality::<A>(). Concrete
    // bound and merge-interaction pins follow below on
    // [`DiffLineKind`].

    fn assert_distinct_cells_empty_is_zero<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        let hist = AxisHistogram::<A>::empty();
        assert_eq!(
            hist.distinct_cells(),
            0,
            "empty histogram distinct_cells must be 0 on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_distinct_cells_singleton_is_one<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // For every cell of the axis: a histogram built from one
        // observation of that cell has exactly one observed cell —
        // the singleton support law uniformly across implementors.
        for observed in axis_iter::<A>() {
            let hist: AxisHistogram<A> = std::iter::once(observed).collect();
            assert_eq!(
                hist.distinct_cells(),
                1,
                "singleton distinct_cells must equal 1 \
                 for observed cell {observed:?} on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_distinct_cells_axis_cover_equals_cardinality<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Observing every cell exactly once produces a uniform
        // histogram; distinct_cells must equal the axis cardinality —
        // the maximum-coverage law. Pinned uniformly across every
        // closed-axis implementor.
        let hist: AxisHistogram<A> = axis_iter::<A>().collect();
        assert_eq!(
            hist.distinct_cells(),
            axis_cardinality::<A>(),
            "axis-cover histogram distinct_cells must equal \
             axis_cardinality on {}",
            std::any::type_name::<A>(),
        );
    }

    #[test]
    fn axis_histogram_distinct_cells_empty_is_zero_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_distinct_cells_empty_is_zero::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_distinct_cells_singleton_is_one_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_distinct_cells_singleton_is_one::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_distinct_cells_axis_cover_equals_cardinality_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_distinct_cells_axis_cover_equals_cardinality::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_distinct_cells_equals_nonzero_count() {
        // The lift's defining equivalence: distinct_cells reads the
        // same scalar as the open-coded nonzero().count() pattern the
        // test laws and consumer-side coverage checks re-derive.
        // Pinned pointwise across the canonical observation-mix shapes
        // (empty, singleton, two-cell uneven, three-cell uniform,
        // two-of-three with one heavy) so a future regression in
        // either side surfaces here.
        let inputs: [&[DiffLineKind]; 5] = [
            &[],
            &[DiffLineKind::Added],
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
            &[
                DiffLineKind::Context,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
        ];
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            assert_eq!(
                hist.distinct_cells(),
                hist.nonzero().count(),
                "distinct_cells must equal nonzero().count() on input of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_distinct_cells_is_bounded_above_by_total_and_axis_cardinality() {
        // Structural-bound pin: distinct_cells ∈ [0, total] ∩
        // [0, axis_cardinality::<A>()]. Each distinct cell contributes
        // at least one observation, so the support is bounded above
        // by the multiset size; the support is also bounded by the
        // axis size. Pinned over four observation shapes (empty,
        // singleton, axis-cover, heavy-tail mix) so both bounds get a
        // tight witness (empty: 0 == 0, singleton: 1 <= 1, axis-cover:
        // 3 == 3, heavy-tail: 2 <= 5).
        let inputs: [&[DiffLineKind]; 4] = [
            &[],
            &[DiffLineKind::Removed],
            &[
                DiffLineKind::Context,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
        ];
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            let support = hist.distinct_cells();
            assert!(
                support <= hist.total(),
                "distinct_cells {support} must be <= total {} on input of length {}",
                hist.total(),
                input.len(),
            );
            assert!(
                support <= axis_cardinality::<DiffLineKind>(),
                "distinct_cells {support} must be <= axis_cardinality {} on input of length {}",
                axis_cardinality::<DiffLineKind>(),
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_distinct_cells_equals_total_iff_every_observation_is_unique() {
        // Equality case of the bound: distinct_cells == total iff
        // every observed cell appears exactly once. The "uniform-
        // singleton" shape — every nonzero count is 1. Pinned by two
        // witnesses on each side of the equality, so a future
        // regression in the predicate surfaces at the boundary.
        // Equality witnesses (every observed cell appears once):
        let unique_a: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
        let unique_b: AxisHistogram<DiffLineKind> =
            std::iter::once(DiffLineKind::Context).collect();
        let unique_c: AxisHistogram<DiffLineKind> = axis_iter::<DiffLineKind>().collect();
        for hist in [&unique_a, &unique_b, &unique_c] {
            assert_eq!(
                hist.distinct_cells(),
                hist.total(),
                "uniform-singleton histogram must satisfy distinct_cells == total",
            );
        }
        // Strict-inequality witnesses (some observed cell has count > 1):
        let dup_a: AxisHistogram<DiffLineKind> = [DiffLineKind::Added, DiffLineKind::Added]
            .into_iter()
            .collect();
        let dup_b: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Context,
            DiffLineKind::Context,
            DiffLineKind::Added,
        ]
        .into_iter()
        .collect();
        for hist in [&dup_a, &dup_b] {
            assert!(
                hist.distinct_cells() < hist.total(),
                "duplicated-observation histogram must satisfy distinct_cells < total",
            );
        }
    }

    #[test]
    fn axis_histogram_distinct_cells_iff_is_empty_is_zero() {
        // Boundary pin: distinct_cells == 0 iff is_empty is true.
        // Equivalence holds across both directions — an empty
        // history reads 0, a non-empty history reads at least 1.
        // Peer to the same boundary equivalence dominant_cell carries
        // on the Some/None side.
        let empty: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
        assert!(empty.is_empty());
        assert_eq!(empty.distinct_cells(), 0);

        let singleton: AxisHistogram<DiffLineKind> =
            std::iter::once(DiffLineKind::Removed).collect();
        assert!(!singleton.is_empty());
        assert!(singleton.distinct_cells() >= 1);
    }

    #[test]
    fn axis_histogram_distinct_cells_after_merge_is_monotone_and_equals_support_union() {
        // The (merge, distinct_cells) composition: the support of a
        // merged histogram equals the union of either side's support
        // (set-theoretic union of observed-cell sets), so the
        // distinct_cells is at least each side's, and equal to the
        // union cardinality. Pinned with disjoint-support, overlapping-
        // support, and identity (empty-rhs) shapes so the merge
        // monotonicity gets a tight witness at each boundary.
        let added_only: AxisHistogram<DiffLineKind> = [DiffLineKind::Added, DiffLineKind::Added]
            .into_iter()
            .collect();
        let removed_only: AxisHistogram<DiffLineKind> =
            std::iter::once(DiffLineKind::Removed).collect();
        let context_and_added: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Context,
            DiffLineKind::Added,
            DiffLineKind::Added,
        ]
        .into_iter()
        .collect();
        let empty_hist: AxisHistogram<DiffLineKind> = AxisHistogram::empty();

        // Disjoint supports: union is the sum of distinct counts.
        let disjoint = added_only.clone().merge(&removed_only);
        assert_eq!(disjoint.distinct_cells(), 2);
        assert!(disjoint.distinct_cells() >= added_only.distinct_cells());
        assert!(disjoint.distinct_cells() >= removed_only.distinct_cells());

        // Overlapping supports: union is strictly less than sum on the
        // shared cell (Added appears in both).
        let overlap = added_only.clone().merge(&context_and_added);
        assert_eq!(overlap.distinct_cells(), 2); // {Added, Context}, not 3
        assert!(overlap.distinct_cells() >= added_only.distinct_cells());
        assert!(overlap.distinct_cells() >= context_and_added.distinct_cells());

        // Identity (empty-rhs): merge leaves the support unchanged.
        let with_empty = added_only.clone().merge(&empty_hist);
        assert_eq!(with_empty.distinct_cells(), added_only.distinct_cells());
    }

    #[test]
    fn axis_histogram_dominant_cell_equals_open_coded_first_max_loop() {
        // The lift collapses the inline scan
        // `iter().filter(|&(_,c)|c>0).fold(first, |best,cur| if cur.1>best.1 {cur} else {best})`
        // pattern the consumers re-derived per observation site. Pin
        // pointwise equivalence over the typed `DiffLineKind` cells
        // across the four canonical observation-mix shapes (empty,
        // unique-max, tied-max, three-way uniform) so a future
        // regression in either side surfaces here.
        let inputs: [&[DiffLineKind]; 4] = [
            &[],
            &[
                DiffLineKind::Added,
                DiffLineKind::Removed,
                DiffLineKind::Added,
            ],
            &[DiffLineKind::Added, DiffLineKind::Removed],
            &[
                DiffLineKind::Context,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
        ];
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            let manual = {
                let mut iter = hist.iter().filter(|&(_, c)| c > 0);
                iter.next().map(|first| {
                    iter.fold(
                        first,
                        |best, current| {
                            if current.1 > best.1 { current } else { best }
                        },
                    )
                    .0
                })
            };
            assert_eq!(
                hist.dominant_cell(),
                manual,
                "dominant_cell must equal the open-coded first-max scan over input \
                 of length {}",
                input.len(),
            );
        }
    }

    // ---- AxisHistogram::recessive_cell trait-uniform laws ----
    //
    // Three trait-uniform laws reach every [`ClosedAxis`] implementor
    // through [`for_each_closed_axis_implementor`] so the per-axis
    // recessive_cell projection's contract holds uniformly without
    // per-axis test duplication: empty → None; singleton → Some(K) on
    // every cell K (identical to dominant_cell on the singleton case);
    // uniform axis-cover → Some(first cell in declaration order)
    // (identical to dominant_cell on a tied histogram). Concrete
    // tie-breaking and merge-interaction pins follow below on
    // [`DiffLineKind`].

    fn assert_recessive_cell_empty_is_none<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        let hist = AxisHistogram::<A>::empty();
        assert_eq!(
            hist.recessive_cell(),
            None,
            "empty histogram recessive_cell must be None on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_recessive_cell_singleton_picks_observed_cell<A>()
    where
        A: ClosedAxis + std::fmt::Debug + PartialEq,
    {
        // For every cell of the axis: a histogram built from one
        // observation of that cell has recessive_cell = Some(cell).
        // Pins the (singleton → unique-min) law uniformly. Identical
        // to the dominant_cell case on a singleton: the rarest and
        // the dominant cell coincide when only one cell is observed.
        for observed in axis_iter::<A>() {
            let hist: AxisHistogram<A> = std::iter::once(observed).collect();
            assert_eq!(
                hist.recessive_cell(),
                Some(observed),
                "singleton recessive_cell must equal the observed cell {observed:?} \
                 on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_recessive_cell_axis_cover_picks_first_cell<A>()
    where
        A: ClosedAxis + std::fmt::Debug + PartialEq,
    {
        // Observing every cell exactly once produces a uniform
        // histogram (every cell at 1, count minimum tied across the
        // axis); `recessive_cell` must return the first cell in
        // declaration order — the documented tie-breaking rule, same
        // as `dominant_cell` on the same input. Pinned uniformly:
        // every closed-axis implementor's declaration-order
        // tie-breaking lands at the head of [`ClosedAxis::ALL`] on
        // *both* the maximum and the minimum side, so the two
        // projections agree on every tied-uniform input.
        let hist: AxisHistogram<A> = axis_iter::<A>().collect();
        let first = axis_iter::<A>().next().expect(
            "every ClosedAxis implementor has at least one variant per the ClosedAxis contract",
        );
        assert_eq!(
            hist.recessive_cell(),
            Some(first),
            "uniform axis-cover histogram recessive_cell must be the first cell \
             in declaration order on axis {}",
            std::any::type_name::<A>(),
        );
    }

    #[test]
    fn axis_histogram_recessive_cell_empty_is_none_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_recessive_cell_empty_is_none::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_recessive_cell_singleton_picks_observed_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_recessive_cell_singleton_picks_observed_cell::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_recessive_cell_axis_cover_picks_first_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_recessive_cell_axis_cover_picks_first_cell::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_dominant_and_recessive_agree_on_uniform_axis_cover_for_every_implementor() {
        // Joint pin: on a uniform axis-cover histogram (every cell
        // observed once), `dominant_cell` and `recessive_cell` must
        // return the same cell — the first in declaration order.
        // The two projections coincide whenever every observed cell
        // shares the same count; the uniform axis-cover is the
        // tightest witness of that equality. Reaches every
        // closed-axis implementor uniformly so the
        // dominant-equals-recessive-on-uniform discipline is named
        // structurally rather than per-axis.
        fn assert_agree<A>()
        where
            A: ClosedAxis + std::fmt::Debug + PartialEq,
        {
            let hist: AxisHistogram<A> = axis_iter::<A>().collect();
            assert_eq!(
                hist.dominant_cell(),
                hist.recessive_cell(),
                "uniform axis-cover histogram must satisfy dominant_cell == \
                 recessive_cell on axis {}",
                std::any::type_name::<A>(),
            );
        }
        macro_rules! check {
            ($ty:ident) => {
                assert_agree::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_recessive_cell_returns_strict_min_when_unique() {
        // Concrete pin on the unique-minimum case: observing Added
        // twice and Removed three times yields the strict positive
        // min at Added. The cell returned must be the unique-min cell
        // regardless of declaration order. (Context is zero, so it
        // does not enter the argmin — zero cells are excluded from
        // the search, as documented on `recessive_cell`.)
        let input = [
            DiffLineKind::Removed,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Added,
            DiffLineKind::Removed,
        ];
        let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
        assert_eq!(hist.count(DiffLineKind::Added), 2);
        assert_eq!(hist.count(DiffLineKind::Removed), 3);
        assert_eq!(hist.count(DiffLineKind::Context), 0);
        assert_eq!(hist.recessive_cell(), Some(DiffLineKind::Added));
    }

    #[test]
    fn axis_histogram_recessive_cell_breaks_ties_in_declaration_order() {
        // Concrete pin on the tie-breaking rule: when multiple
        // observed cells share the minimum count, the first in
        // [`ClosedAxis::ALL`] declaration order wins. [`DiffLineKind::ALL`]
        // starts with [`DiffLineKind::Context`]; observing every cell
        // once at the same count must return [`DiffLineKind::Context`]
        // regardless of observation order — identical to
        // [`Self::dominant_cell`]'s tie-breaking on the same input.
        // Pinned by varying observation order (Added, Removed,
        // Context vs Context, Removed, Added) and asserting the
        // result is invariant — observation order does not leak
        // through the projection.
        let first = DiffLineKind::ALL[0];
        let by_observation_order_a: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ]
        .into_iter()
        .collect();
        let by_observation_order_b: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Context,
            DiffLineKind::Removed,
            DiffLineKind::Added,
        ]
        .into_iter()
        .collect();
        assert_eq!(by_observation_order_a, by_observation_order_b);
        assert_eq!(by_observation_order_a.recessive_cell(), Some(first));
        assert_eq!(by_observation_order_b.recessive_cell(), Some(first));
    }

    #[test]
    fn axis_histogram_recessive_cell_excludes_zero_cells() {
        // Boundary pin: `recessive_cell` searches the positive
        // support only — zero-count cells are not eligible. A
        // histogram with Added = 2 and every other cell at 0 returns
        // Some(Added), not Some(Context) (the first cell in
        // declaration order, which is at count 0 and thus excluded).
        // The pin distinguishes `recessive_cell` from a
        // "argmin-over-all-cells" reading that would silently treat
        // unobserved cells as the minimum.
        let input = [DiffLineKind::Added, DiffLineKind::Added];
        let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
        assert_eq!(hist.count(DiffLineKind::Context), 0);
        assert_eq!(hist.count(DiffLineKind::Removed), 0);
        assert_eq!(hist.count(DiffLineKind::Added), 2);
        assert_eq!(hist.recessive_cell(), Some(DiffLineKind::Added));
    }

    #[test]
    fn axis_histogram_recessive_cell_after_merge_reflects_combined_counts() {
        // The (merge, recessive_cell) composition: recessive_cell on
        // a merged histogram reflects the pointwise-summed counts,
        // not either side's individual minimum. Pinned by
        // constructing two histograms with disagreeing minima — the
        // merge's recessive cell follows the combined counts, not
        // either side's rarest cell in isolation.
        //
        // `DiffLineKind::ALL` declaration order is
        // `[Removed, Added, Context]` (per
        // `diff_line_kind_all_declaration_order_is_removed_added_context`
        // in `src/tiered.rs`); witness shapes are constructed
        // accordingly.
        let lhs: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Removed,
            DiffLineKind::Removed,
            DiffLineKind::Added,
        ]
        .into_iter()
        .collect();
        // lhs counts: Removed=2, Added=1, Context=0 →
        //   recessive = Added (strict min positive = 1, unique).
        let rhs: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Context,
        ]
        .into_iter()
        .collect();
        // rhs counts: Removed=0, Added=2, Context=1 →
        //   recessive = Context (strict min positive = 1, unique).
        assert_eq!(lhs.recessive_cell(), Some(DiffLineKind::Added));
        assert_eq!(rhs.recessive_cell(), Some(DiffLineKind::Context));
        let merged = lhs.merge(&rhs);
        assert_eq!(merged.count(DiffLineKind::Removed), 2);
        assert_eq!(merged.count(DiffLineKind::Added), 3);
        assert_eq!(merged.count(DiffLineKind::Context), 1);
        // merged: Removed=2, Added=3, Context=1 →
        //   recessive = Context (strict min positive = 1, unique).
        // The merge takes the rhs's Context cell as the global
        // recessive even though lhs's recessive was Added — the
        // projection depends on the combined counts, not on either
        // side's individual recessive in isolation.
        assert_eq!(merged.recessive_cell(), Some(DiffLineKind::Context));
    }

    #[test]
    fn axis_histogram_recessive_cell_iff_is_empty_is_false() {
        // Boundary pin: recessive_cell is Some iff is_empty is false
        // — identical companion to the dominant_cell boundary law.
        // The two projections are defined on the same support, so
        // their Some/None alignment is structural.
        let empty: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
        assert!(empty.is_empty());
        assert_eq!(empty.recessive_cell(), None);
        assert_eq!(empty.dominant_cell(), None);

        let singleton: AxisHistogram<DiffLineKind> =
            std::iter::once(DiffLineKind::Context).collect();
        assert!(!singleton.is_empty());
        assert!(singleton.recessive_cell().is_some());
        assert!(singleton.dominant_cell().is_some());
    }

    #[test]
    fn axis_histogram_recessive_count_bounded_above_by_dominant_count() {
        // Companion-bound pin: the rarest cell's count is bounded
        // above by the dominant cell's count on every non-empty
        // histogram. Pinned over four observation-mix shapes
        // (singleton, strict skew, three-way uniform, two-way tie)
        // so the bound gets tight witnesses at the equality
        // boundaries (singleton: 1 == 1, uniform: 1 == 1) and at the
        // strict-inequality boundaries (skew: rare < dominant).
        let inputs: [&[DiffLineKind]; 4] = [
            &[DiffLineKind::Added],
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
            &[
                DiffLineKind::Context,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
                DiffLineKind::Removed,
            ],
        ];
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            let rare = hist
                .recessive_cell()
                .expect("non-empty histogram must have a recessive cell");
            let dom = hist
                .dominant_cell()
                .expect("non-empty histogram must have a dominant cell");
            assert!(
                hist.count(rare) <= hist.count(dom),
                "recessive count {} must be <= dominant count {} on input of length {}",
                hist.count(rare),
                hist.count(dom),
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_recessive_cell_equals_open_coded_first_min_loop() {
        // The lift collapses the inline scan
        // `iter().filter(|&(_,c)|c>0).fold(first, |best,cur| if cur.1<best.1 {cur} else {best})`
        // pattern an open-coded argmin consumer would re-derive per
        // observation site. Pin pointwise equivalence over the typed
        // `DiffLineKind` cells across the four canonical
        // observation-mix shapes (empty, unique-min, tied-min,
        // three-way uniform) so a future regression in either side
        // surfaces here.
        let inputs: [&[DiffLineKind]; 4] = [
            &[],
            &[
                DiffLineKind::Added,
                DiffLineKind::Removed,
                DiffLineKind::Added,
            ],
            &[DiffLineKind::Added, DiffLineKind::Removed],
            &[
                DiffLineKind::Context,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
        ];
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            let manual = {
                let mut iter = hist.iter().filter(|&(_, c)| c > 0);
                iter.next().map(|first| {
                    iter.fold(
                        first,
                        |best, current| {
                            if current.1 < best.1 { current } else { best }
                        },
                    )
                    .0
                })
            };
            assert_eq!(
                hist.recessive_cell(),
                manual,
                "recessive_cell must equal the open-coded first-min scan over input \
                 of length {}",
                input.len(),
            );
        }
    }

    // ---- AxisHistogram::unobserved closes the (observed, unobserved)
    // ---- partition over the closed axis ----
    //
    // [`AxisHistogram::unobserved`] is the structural complement of
    // [`AxisHistogram::nonzero`] over the closed axis: every cell of
    // the axis lies in exactly one of the two iterators. Four trait-
    // uniform laws reach every `ClosedAxis` implementor pointwise:
    //
    //   (a) empty histogram → unobserved iterates the full axis;
    //   (b) uniform axis-cover histogram → unobserved is empty;
    //   (c) singleton histogram → unobserved omits exactly the
    //       observed cell;
    //   (d) partition law — for every histogram and every implementor,
    //       `unobserved().count() + nonzero().count() ==
    //        axis_cardinality::<A>()`, and the two cell-sets are
    //       disjoint.

    fn assert_unobserved_empty_is_full_axis<A>()
    where
        A: ClosedAxis + std::fmt::Debug + PartialEq,
    {
        // The empty histogram observes no cell; every cell of the axis
        // is unobserved. The iterator yields the full axis in
        // declaration order, pointwise equal to `axis_iter::<A>()`.
        let hist: AxisHistogram<A> = AxisHistogram::empty();
        let unobserved: Vec<A> = hist.unobserved().collect();
        let full_axis: Vec<A> = axis_iter::<A>().collect();
        assert_eq!(
            unobserved,
            full_axis,
            "empty histogram unobserved must iterate the full axis on {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_unobserved_axis_cover_is_empty<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Observing every cell exactly once produces a uniform
        // axis-cover histogram (every cell at 1, support is the full
        // axis); `unobserved` is empty — the dual boundary of the
        // empty-histogram convention. The full-cover histogram has
        // no coverage gap.
        let hist: AxisHistogram<A> = axis_iter::<A>().collect();
        assert_eq!(
            hist.unobserved().count(),
            0,
            "uniform axis-cover histogram unobserved must be empty on {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_unobserved_singleton_omits_observed_cell<A>()
    where
        A: ClosedAxis + std::fmt::Debug + PartialEq,
    {
        // A singleton-support histogram (one cell observed) has the
        // full axis minus the observed cell as its coverage gap. Pin
        // pointwise across every cell of every axis: the unobserved
        // iterator yields `axis_iter::<A>()` with the observed cell
        // removed, in declaration order.
        for observed in axis_iter::<A>() {
            let hist: AxisHistogram<A> = std::iter::once(observed).collect();
            let unobserved: Vec<A> = hist.unobserved().collect();
            let expected: Vec<A> = axis_iter::<A>().filter(|&v| v != observed).collect();
            assert_eq!(
                unobserved,
                expected,
                "singleton histogram unobserved must omit exactly the observed cell {observed:?} \
                 on axis {}",
                std::any::type_name::<A>(),
            );
            // Companion bound on the cardinality of the gap.
            assert_eq!(
                hist.unobserved().count(),
                axis_cardinality::<A>() - 1,
                "singleton histogram unobserved cardinality must equal axis_cardinality - 1 on {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_unobserved_and_nonzero_partition_axis<A>()
    where
        A: ClosedAxis + std::fmt::Debug + std::hash::Hash + Eq,
    {
        // Partition law: every cell of the axis lies in exactly one of
        // `unobserved()` and `observed()`. Witnessed at three boundary
        // shapes — empty (gap = full axis), singleton (support =
        // {first}, gap = axis - {first}), uniform axis-cover (support
        // = full axis, gap = empty) — so the partition holds at both
        // extremes (full gap, no gap) and at a generic proper-subset
        // support.
        use std::collections::HashSet;
        let first = axis_iter::<A>()
            .next()
            .expect("ClosedAxis::ALL is non-empty by trait contract");
        let histograms: [AxisHistogram<A>; 3] = [
            AxisHistogram::empty(),
            std::iter::once(first).collect(),
            axis_iter::<A>().collect(),
        ];
        let n = axis_cardinality::<A>();
        for hist in histograms {
            let observed: HashSet<A> = hist.observed().collect();
            let unobserved: HashSet<A> = hist.unobserved().collect();
            // Cardinality partition: |observed| + |unobserved| = n.
            assert_eq!(
                observed.len() + unobserved.len(),
                n,
                "observed.len() + unobserved.len() must equal axis_cardinality on {}",
                std::any::type_name::<A>(),
            );
            // Disjointness: observed ∩ unobserved = ∅.
            assert!(
                observed.is_disjoint(&unobserved),
                "observed and unobserved cell-sets must be disjoint on {}",
                std::any::type_name::<A>(),
            );
            // Cover: observed ∪ unobserved = axis.
            let full_axis: HashSet<A> = axis_iter::<A>().collect();
            let union: HashSet<A> = observed.union(&unobserved).copied().collect();
            assert_eq!(
                union,
                full_axis,
                "observed ∪ unobserved must equal the full axis on {}",
                std::any::type_name::<A>(),
            );
        }
    }

    #[test]
    fn axis_histogram_unobserved_empty_is_full_axis_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_unobserved_empty_is_full_axis::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_unobserved_axis_cover_is_empty_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_unobserved_axis_cover_is_empty::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_unobserved_singleton_omits_observed_cell_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_unobserved_singleton_omits_observed_cell::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_unobserved_and_nonzero_partition_axis_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_unobserved_and_nonzero_partition_axis::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_unobserved_equals_open_coded_filter_zero_loop() {
        // The lift collapses the inline scan
        // `iter().filter(|&(_, c)| c == 0).map(|(v, _)| v)` an open-
        // coded coverage-gap consumer would re-derive per observation
        // site. Pin pointwise equivalence over the typed
        // `DiffLineKind` cells across four canonical observation-mix
        // shapes (empty, singleton, two-of-three, axis-cover) so a
        // future regression in either side surfaces here.
        let inputs: [&[DiffLineKind]; 4] = [
            &[],
            &[DiffLineKind::Added],
            &[
                DiffLineKind::Added,
                DiffLineKind::Removed,
                DiffLineKind::Added,
            ],
            &[
                DiffLineKind::Context,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
        ];
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            let actual: Vec<DiffLineKind> = hist.unobserved().collect();
            let manual: Vec<DiffLineKind> = hist
                .iter()
                .filter(|&(_, c)| c == 0)
                .map(|(v, _)| v)
                .collect();
            assert_eq!(
                actual,
                manual,
                "unobserved must equal the open-coded filter-zero scan over input \
                 of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_unobserved_complements_nonzero_pointwise() {
        // Concrete pin of the (observed, unobserved) partition on
        // `DiffLineKind`: nonzero cells and unobserved cells partition
        // the axis. Pinned at three shapes — empty (gap = full axis),
        // a strict-subset support (Added only, gap = Removed + Context),
        // and the axis-cover (gap = ∅) — so the partition is witnessed
        // at both boundaries and at a generic proper subset.
        use std::collections::HashSet;
        let cases: [(&[DiffLineKind], usize); 3] = [
            (&[], 0),
            (&[DiffLineKind::Added, DiffLineKind::Added], 1),
            (
                &[
                    DiffLineKind::Added,
                    DiffLineKind::Removed,
                    DiffLineKind::Context,
                ],
                3,
            ),
        ];
        for (input, expected_support) in cases {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            let observed: HashSet<DiffLineKind> = hist.observed().collect();
            let unobserved: HashSet<DiffLineKind> = hist.unobserved().collect();
            assert_eq!(observed.len(), expected_support);
            assert_eq!(observed.len() + unobserved.len(), DiffLineKind::ALL.len());
            assert!(observed.is_disjoint(&unobserved));
            let union: HashSet<DiffLineKind> = observed.union(&unobserved).copied().collect();
            let full_axis: HashSet<DiffLineKind> = DiffLineKind::ALL.iter().copied().collect();
            assert_eq!(union, full_axis);
        }
    }

    #[test]
    fn axis_histogram_unobserved_count_equals_cardinality_minus_distinct() {
        // Companion-invariant pin: `unobserved().count() ==
        // axis_cardinality::<A>() - distinct_cells()`. The coverage-
        // gap size reads off the support cardinality through one
        // subtraction from the axis size. Pinned across the same four
        // shapes the trait-uniform laws witness on (empty, singleton,
        // partial, full-cover) so the equality holds at every
        // distinct-cells value in the histogram's range.
        let inputs: [&[DiffLineKind]; 4] = [
            &[],
            &[DiffLineKind::Added],
            &[DiffLineKind::Added, DiffLineKind::Removed],
            &[
                DiffLineKind::Context,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
        ];
        let n = axis_cardinality::<DiffLineKind>();
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            assert_eq!(
                hist.unobserved().count(),
                n - hist.distinct_cells(),
                "unobserved count must equal axis_cardinality - distinct_cells on input \
                 of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_unobserved_after_merge_shrinks_monotonically() {
        // The (merge, unobserved) composition: merging never grows the
        // coverage gap. The unobserved set of a merged histogram is
        // the *intersection* of the two sides' unobserved sets — a cell
        // is unobserved in the merge iff it is unobserved in both
        // sides. Pinned by constructing two histograms whose supports
        // partially overlap and asserting the merge's unobserved set
        // equals the set intersection.
        //
        // `DiffLineKind::ALL` declaration order is
        // `[Removed, Added, Context]`.
        use std::collections::HashSet;
        let lhs: AxisHistogram<DiffLineKind> = [DiffLineKind::Removed, DiffLineKind::Added]
            .into_iter()
            .collect();
        // lhs support: {Removed, Added}; unobserved: {Context}.
        let rhs: AxisHistogram<DiffLineKind> = [DiffLineKind::Added, DiffLineKind::Context]
            .into_iter()
            .collect();
        // rhs support: {Added, Context}; unobserved: {Removed}.
        let lhs_gap: HashSet<DiffLineKind> = lhs.unobserved().collect();
        let rhs_gap: HashSet<DiffLineKind> = rhs.unobserved().collect();
        let lhs_gap_count = lhs.unobserved().count();
        let rhs_gap_count = rhs.unobserved().count();
        assert_eq!(lhs_gap, HashSet::from([DiffLineKind::Context]));
        assert_eq!(rhs_gap, HashSet::from([DiffLineKind::Removed]));
        let merged = lhs.merge(&rhs);
        let merged_gap: HashSet<DiffLineKind> = merged.unobserved().collect();
        // Intersection of {Context} and {Removed} is empty: the merge
        // covers every cell, so unobserved is empty.
        let expected: HashSet<DiffLineKind> = lhs_gap.intersection(&rhs_gap).copied().collect();
        assert_eq!(merged_gap, expected);
        assert!(merged_gap.is_empty());
        // Monotonicity bound: merged gap size <= min of side gap sizes.
        assert!(merged.unobserved().count() <= lhs_gap_count);
        assert!(merged.unobserved().count() <= rhs_gap_count);
    }

    // ---- AxisHistogram::observed closes the (observed, unobserved)
    // ---- cell-only iterator partition over the closed axis ----
    //
    // [`AxisHistogram::observed`] is the cell-only form of
    // [`AxisHistogram::nonzero`] (same support, observation counts
    // dropped) and the structural dual of [`AxisHistogram::unobserved`]
    // over the closed axis: every cell lies in exactly one of the two
    // iterators. Three trait-uniform laws reach every `ClosedAxis`
    // implementor pointwise:
    //
    //   (a) empty histogram → observed is empty (the dual of the
    //       empty-histogram convention on `unobserved`);
    //   (b) uniform axis-cover histogram → observed iterates the full
    //       axis (the dual of axis_cover_is_empty on `unobserved`);
    //   (c) singleton histogram → observed yields exactly the
    //       observed cell (the dual of singleton_omits_observed_cell
    //       on `unobserved`).

    fn assert_observed_empty_is_empty<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The empty histogram observes no cell; the observed iterator
        // is empty — the dual of the empty-histogram convention on
        // `unobserved` (which iterates the full axis on the empty
        // histogram).
        let hist: AxisHistogram<A> = AxisHistogram::empty();
        assert_eq!(
            hist.observed().count(),
            0,
            "empty histogram observed must be empty on {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_observed_axis_cover_is_full_axis<A>()
    where
        A: ClosedAxis + std::fmt::Debug + PartialEq,
    {
        // Observing every cell exactly once produces a uniform
        // axis-cover histogram (every cell at 1, support is the full
        // axis); `observed` iterates the full axis in declaration
        // order, pointwise equal to `axis_iter::<A>()` — the dual
        // boundary of the empty-histogram convention.
        let hist: AxisHistogram<A> = axis_iter::<A>().collect();
        let observed: Vec<A> = hist.observed().collect();
        let full_axis: Vec<A> = axis_iter::<A>().collect();
        assert_eq!(
            observed,
            full_axis,
            "uniform axis-cover histogram observed must iterate the full axis on {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_observed_singleton_is_just_observed_cell<A>()
    where
        A: ClosedAxis + std::fmt::Debug + PartialEq,
    {
        // A singleton-support histogram (one cell observed) has
        // exactly that cell as its observed support. Pin pointwise
        // across every cell of every axis: the observed iterator
        // yields a single-element sequence containing the observed
        // cell — the dual of the singleton omission law on
        // `unobserved` (which omits exactly that cell).
        for observed_cell in axis_iter::<A>() {
            let hist: AxisHistogram<A> = std::iter::once(observed_cell).collect();
            let observed: Vec<A> = hist.observed().collect();
            assert_eq!(
                observed,
                vec![observed_cell],
                "singleton histogram observed must yield exactly the observed cell \
                 {observed_cell:?} on axis {}",
                std::any::type_name::<A>(),
            );
            // Companion bound on the cardinality of the support.
            assert_eq!(
                hist.observed().count(),
                1,
                "singleton histogram observed cardinality must equal 1 on {}",
                std::any::type_name::<A>(),
            );
        }
    }

    #[test]
    fn axis_histogram_observed_empty_is_empty_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_observed_empty_is_empty::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_observed_axis_cover_is_full_axis_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_observed_axis_cover_is_full_axis::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_observed_singleton_is_just_observed_cell_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_observed_singleton_is_just_observed_cell::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_observed_equals_nonzero_cell_projection_pointwise() {
        // The lift's defining equivalence on the pair-iterator
        // surface: `observed()` yields the same cell-sequence as
        // `nonzero().map(|(v, _)| v)` — the dropped-count form — on
        // every histogram. Pin pointwise (in declaration order, not
        // just as a set) across four canonical observation-mix
        // shapes (empty, singleton, two-of-three, axis-cover) so a
        // future regression in either side surfaces here.
        let inputs: [&[DiffLineKind]; 4] = [
            &[],
            &[DiffLineKind::Added],
            &[
                DiffLineKind::Added,
                DiffLineKind::Removed,
                DiffLineKind::Added,
            ],
            &[
                DiffLineKind::Context,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
        ];
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            let actual: Vec<DiffLineKind> = hist.observed().collect();
            let manual: Vec<DiffLineKind> = hist.nonzero().map(|(v, _)| v).collect();
            assert_eq!(
                actual,
                manual,
                "observed must equal the cell projection of nonzero over input \
                 of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_observed_equals_open_coded_filter_positive_loop() {
        // The lift also collapses the open-coded scan
        // `iter().filter(|&(_, c)| c > 0).map(|(v, _)| v)` that
        // consumers re-derived inline at every observation site. Pin
        // pointwise equivalence over the typed `DiffLineKind` cells
        // across the same four canonical shapes so a future
        // regression in either form surfaces here.
        let inputs: [&[DiffLineKind]; 4] = [
            &[],
            &[DiffLineKind::Added],
            &[
                DiffLineKind::Added,
                DiffLineKind::Removed,
                DiffLineKind::Added,
            ],
            &[
                DiffLineKind::Context,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
        ];
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            let actual: Vec<DiffLineKind> = hist.observed().collect();
            let manual: Vec<DiffLineKind> = hist
                .iter()
                .filter(|&(_, c)| c > 0)
                .map(|(v, _)| v)
                .collect();
            assert_eq!(
                actual,
                manual,
                "observed must equal the open-coded filter-positive scan over input \
                 of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_observed_count_equals_distinct_cells() {
        // Companion-invariant pin: `observed().count() ==
        // distinct_cells()`. The cell-only iterator's length is the
        // named support-cardinality scalar — the natural peer of
        // `unobserved().count() == unobserved_cells()`. Pinned across
        // the same four canonical shapes the trait-uniform laws
        // witness on (empty, singleton, partial, full-cover) so the
        // equality holds at every support-cardinality value in the
        // histogram's range.
        let inputs: [&[DiffLineKind]; 4] = [
            &[],
            &[DiffLineKind::Added],
            &[DiffLineKind::Added, DiffLineKind::Removed],
            &[
                DiffLineKind::Context,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
        ];
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            assert_eq!(
                hist.observed().count(),
                hist.distinct_cells(),
                "observed count must equal distinct_cells on input of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_observed_partitions_axis_with_unobserved_pointwise() {
        // Concrete pin of the (observed, unobserved) cell-only
        // partition on `DiffLineKind`: the two iterators' cell-sets
        // are disjoint and their union is the full axis. Pinned at
        // three shapes — empty (observed = ∅, gap = full axis), a
        // strict-subset support (Added only, observed = {Added},
        // gap = {Removed, Context}), and the axis-cover (observed =
        // full axis, gap = ∅) — so the partition is witnessed at
        // both boundaries and at a generic proper subset.
        use std::collections::HashSet;
        let cases: [(&[DiffLineKind], usize); 3] = [
            (&[], 0),
            (&[DiffLineKind::Added, DiffLineKind::Added], 1),
            (
                &[
                    DiffLineKind::Added,
                    DiffLineKind::Removed,
                    DiffLineKind::Context,
                ],
                3,
            ),
        ];
        for (input, expected_support) in cases {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            let observed: HashSet<DiffLineKind> = hist.observed().collect();
            let unobserved: HashSet<DiffLineKind> = hist.unobserved().collect();
            assert_eq!(observed.len(), expected_support);
            assert_eq!(observed.len() + unobserved.len(), DiffLineKind::ALL.len());
            assert!(observed.is_disjoint(&unobserved));
            let union: HashSet<DiffLineKind> = observed.union(&unobserved).copied().collect();
            let full_axis: HashSet<DiffLineKind> = DiffLineKind::ALL.iter().copied().collect();
            assert_eq!(union, full_axis);
        }
    }

    #[test]
    fn axis_histogram_observed_yields_cells_in_declaration_order() {
        // Order pin: the iterator yields cells in declaration order
        // over [`ClosedAxis::ALL`], pointwise consistent with the
        // order [`AxisHistogram::iter`] / [`AxisHistogram::nonzero`]
        // yield (and the dual of [`AxisHistogram::unobserved`]'s
        // declaration-order convention). Observation order does not
        // leak through the projection: the same support observed
        // under different observation orders yields the same observed
        // cell-sequence.
        //
        // `DiffLineKind::ALL` declaration order is
        // `[Removed, Added, Context]`. Two observation orders of the
        // same multi-cell support must yield the same observed
        // sequence in declaration order.
        let order_a: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Context,
            DiffLineKind::Added,
            DiffLineKind::Removed,
        ]
        .into_iter()
        .collect();
        let order_b: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Removed,
            DiffLineKind::Context,
            DiffLineKind::Added,
        ]
        .into_iter()
        .collect();
        let seq_a: Vec<DiffLineKind> = order_a.observed().collect();
        let seq_b: Vec<DiffLineKind> = order_b.observed().collect();
        assert_eq!(seq_a, seq_b);
        assert_eq!(
            seq_a,
            vec![
                DiffLineKind::Removed,
                DiffLineKind::Added,
                DiffLineKind::Context,
            ],
        );
    }

    #[test]
    fn axis_histogram_observed_after_merge_grows_monotonically() {
        // The (merge, observed) composition: merging never shrinks
        // the support. The observed set of a merged histogram is the
        // *union* of the two sides' observed sets — a cell is
        // observed in the merge iff it is observed in at least one
        // side. The cell-only peer of the monotone-support law on
        // `distinct_cells` (the scalar surface) and the monotone-
        // non-increase law on `unobserved` (the dual-side iterator).
        //
        // `DiffLineKind::ALL` declaration order is
        // `[Removed, Added, Context]`.
        use std::collections::HashSet;
        let lhs: AxisHistogram<DiffLineKind> = [DiffLineKind::Removed, DiffLineKind::Added]
            .into_iter()
            .collect();
        // lhs support: {Removed, Added}.
        let rhs: AxisHistogram<DiffLineKind> = [DiffLineKind::Added, DiffLineKind::Context]
            .into_iter()
            .collect();
        // rhs support: {Added, Context}.
        let lhs_support: HashSet<DiffLineKind> = lhs.observed().collect();
        let rhs_support: HashSet<DiffLineKind> = rhs.observed().collect();
        let lhs_support_count = lhs.observed().count();
        let rhs_support_count = rhs.observed().count();
        assert_eq!(
            lhs_support,
            HashSet::from([DiffLineKind::Removed, DiffLineKind::Added]),
        );
        assert_eq!(
            rhs_support,
            HashSet::from([DiffLineKind::Added, DiffLineKind::Context]),
        );
        let merged = lhs.merge(&rhs);
        let merged_support: HashSet<DiffLineKind> = merged.observed().collect();
        // Union of {Removed, Added} and {Added, Context} is the full
        // axis: the merge covers every cell, so observed iterates
        // the full axis.
        let expected: HashSet<DiffLineKind> = lhs_support.union(&rhs_support).copied().collect();
        assert_eq!(merged_support, expected);
        let full_axis: HashSet<DiffLineKind> = DiffLineKind::ALL.iter().copied().collect();
        assert_eq!(merged_support, full_axis);
        // Monotonicity bound: merged support size >= max of side support sizes.
        assert!(merged.observed().count() >= lhs_support_count);
        assert!(merged.observed().count() >= rhs_support_count);
    }

    // ---- AxisHistogram::peak_count trait-uniform laws ----
    //
    // Three trait-uniform laws reach every [`ClosedAxis`] implementor
    // through [`for_each_closed_axis_implementor`] so the per-axis
    // peak_count projection's contract holds uniformly without
    // per-axis test duplication: empty → 0; singleton → 1 on every
    // cell K; uniform axis-cover → 1 (every cell observed exactly
    // once, so the maximum count is 1). Concrete merge-monotonicity
    // and (cell, count) pairing pins follow below on [`DiffLineKind`].

    fn assert_peak_count_empty_is_zero<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        let hist = AxisHistogram::<A>::empty();
        assert_eq!(
            hist.peak_count(),
            0,
            "empty histogram peak_count must be 0 on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_peak_count_singleton_is_one<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // For every cell of the axis: a histogram built from one
        // observation of that cell has peak count exactly 1 —
        // the singleton-support peak law uniformly across implementors.
        for observed in axis_iter::<A>() {
            let hist: AxisHistogram<A> = std::iter::once(observed).collect();
            assert_eq!(
                hist.peak_count(),
                1,
                "singleton peak_count must equal 1 \
                 for observed cell {observed:?} on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_peak_count_axis_cover_is_one<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Observing every cell exactly once produces a uniform
        // histogram; the maximum cell count is 1 — the uniform-axis-
        // cover peak law. Peer to the uniform-axis-cover law on
        // `dominant_cell` (which picks the first cell on ties): here
        // the *count* at that cell is 1, pinned uniformly across every
        // closed-axis implementor.
        let hist: AxisHistogram<A> = axis_iter::<A>().collect();
        assert_eq!(
            hist.peak_count(),
            1,
            "uniform axis-cover histogram peak_count must equal 1 on {}",
            std::any::type_name::<A>(),
        );
    }

    #[test]
    fn axis_histogram_peak_count_empty_is_zero_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_peak_count_empty_is_zero::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_peak_count_singleton_is_one_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_peak_count_singleton_is_one::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_peak_count_axis_cover_is_one_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_peak_count_axis_cover_is_one::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_peak_count_equals_dominant_cell_count_when_non_empty() {
        // The lift's defining pairing law: on every non-empty histogram
        // the scalar `peak_count` equals the count carried by the
        // dominant cell (i.e. `count(dominant_cell().unwrap())`). Pin
        // pointwise equivalence over the typed `DiffLineKind` cells
        // across four canonical observation-mix shapes (singleton,
        // unique-max, tied-max, three-way uniform) so a future
        // regression in either side surfaces here. The empty boundary
        // is pinned separately by the trait-uniform empty-is-zero law
        // above and the dedicated `peak_count_iff_is_empty_is_zero`
        // test below.
        let inputs: [&[DiffLineKind]; 4] = [
            &[DiffLineKind::Added],
            &[
                DiffLineKind::Added,
                DiffLineKind::Removed,
                DiffLineKind::Added,
            ],
            &[DiffLineKind::Added, DiffLineKind::Removed],
            &[
                DiffLineKind::Context,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
        ];
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            let dominant = hist
                .dominant_cell()
                .expect("non-empty histogram has a dominant cell");
            assert_eq!(
                hist.peak_count(),
                hist.count(dominant),
                "peak_count must equal count(dominant_cell()) on non-empty input \
                 of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_peak_count_iff_is_empty_is_zero() {
        // Boundary pin: peak_count == 0 iff is_empty is true.
        // Equivalence holds across both directions — an empty history
        // reads 0, a non-empty history reads at least 1. Peer to the
        // same boundary equivalence distinct_cells and dominant_cell
        // both carry.
        let empty: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
        assert!(empty.is_empty());
        assert_eq!(empty.peak_count(), 0);

        let singleton: AxisHistogram<DiffLineKind> =
            std::iter::once(DiffLineKind::Removed).collect();
        assert!(!singleton.is_empty());
        assert!(singleton.peak_count() >= 1);
    }

    #[test]
    fn axis_histogram_peak_count_is_bounded_above_by_total() {
        // Structural-bound pin: peak_count ∈ [0, total] on every
        // histogram, with equality iff distinct_cells <= 1. Pinned
        // over four observation shapes (empty, singleton,
        // single-cell-multi-observation, multi-cell) so both the bound
        // and the equality case get tight witnesses.
        let single_cell_two_observations: &[DiffLineKind] =
            &[DiffLineKind::Added, DiffLineKind::Added];
        let multi_cell: &[DiffLineKind] = &[
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
        ];
        let inputs: [&[DiffLineKind]; 4] = [
            &[],
            &[DiffLineKind::Removed],
            single_cell_two_observations,
            multi_cell,
        ];
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            assert!(
                hist.peak_count() <= hist.total(),
                "peak_count {} must be <= total {} on input of length {}",
                hist.peak_count(),
                hist.total(),
                input.len(),
            );
            if hist.distinct_cells() <= 1 {
                assert_eq!(
                    hist.peak_count(),
                    hist.total(),
                    "peak_count must equal total when distinct_cells <= 1 \
                     on input of length {}",
                    input.len(),
                );
            } else {
                assert!(
                    hist.peak_count() < hist.total(),
                    "peak_count must be strictly less than total when \
                     distinct_cells >= 2 on input of length {}",
                    input.len(),
                );
            }
        }
    }

    #[test]
    fn axis_histogram_peak_count_after_merge_is_monotone() {
        // The (merge, peak_count) composition: merging never shrinks
        // the peak. Adding non-negative deltas pointwise to the side
        // with the higher peak cannot lower its count; on every cell
        // the merge's count is the sum of the sides' counts, and the
        // maximum of pointwise sums is at least each side's maximum
        // pointwise. Pinned with disjoint-support, overlapping-support
        // (where the merge's peak strictly grows), and identity
        // (empty-rhs) shapes so the monotonicity gets a tight witness
        // at each boundary.
        let added_two: AxisHistogram<DiffLineKind> = [DiffLineKind::Added, DiffLineKind::Added]
            .into_iter()
            .collect();
        let removed_one: AxisHistogram<DiffLineKind> =
            std::iter::once(DiffLineKind::Removed).collect();
        let context_and_added_two: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Context,
            DiffLineKind::Added,
            DiffLineKind::Added,
        ]
        .into_iter()
        .collect();
        let empty_hist: AxisHistogram<DiffLineKind> = AxisHistogram::empty();

        // Disjoint supports: peak equals the larger side's peak
        // (Added's two beats Removed's one).
        let disjoint = added_two.clone().merge(&removed_one);
        assert_eq!(disjoint.peak_count(), 2);
        assert!(disjoint.peak_count() >= added_two.peak_count());
        assert!(disjoint.peak_count() >= removed_one.peak_count());

        // Overlapping supports: the shared Added cell grows from
        // (2, 2) → 4, so the merge's peak strictly grows past each
        // side's peak.
        let overlap = added_two.clone().merge(&context_and_added_two);
        assert_eq!(overlap.peak_count(), 4);
        assert!(overlap.peak_count() >= added_two.peak_count());
        assert!(overlap.peak_count() >= context_and_added_two.peak_count());

        // Identity (empty-rhs): merge leaves the peak unchanged.
        let with_empty = added_two.clone().merge(&empty_hist);
        assert_eq!(with_empty.peak_count(), added_two.peak_count());
    }

    // ---- AxisHistogram::dominant_observation trait-uniform laws ----
    //
    // Three trait-uniform laws reach every [`ClosedAxis`] implementor
    // through [`for_each_closed_axis_implementor`] so the per-axis
    // dominant_observation fused-pair projection's contract holds
    // uniformly without per-axis test duplication: empty → None;
    // singleton → Some((K, 1)) on every cell K; uniform axis-cover →
    // Some((first cell, 1)) — the modal pair recovered uniformly
    // through the declaration-order tie-break inherited from
    // `dominant_cell`. Concrete projection-agreement and merge-
    // monotonicity pins follow below on [`DiffLineKind`].

    fn assert_dominant_observation_empty_is_none<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        let hist = AxisHistogram::<A>::empty();
        assert_eq!(
            hist.dominant_observation(),
            None,
            "empty histogram dominant_observation must be None on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_dominant_observation_singleton_picks_observed_pair<A>()
    where
        A: ClosedAxis + std::fmt::Debug + PartialEq,
    {
        // For every cell of the axis: a histogram built from one
        // observation of that cell has dominant_observation =
        // Some((cell, 1)) — the fused (cell, count) pair recovered
        // uniformly from a one-observation history.
        for observed in axis_iter::<A>() {
            let hist: AxisHistogram<A> = std::iter::once(observed).collect();
            assert_eq!(
                hist.dominant_observation(),
                Some((observed, 1)),
                "singleton dominant_observation must equal Some(({observed:?}, 1)) \
                 on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_dominant_observation_axis_cover_picks_first_pair<A>()
    where
        A: ClosedAxis + std::fmt::Debug + PartialEq,
    {
        // Observing every cell exactly once produces a uniform
        // histogram (every cell at 1, modal count tied across the
        // axis); dominant_observation must return Some((first cell, 1))
        // — the declaration-order tie-break inherited from
        // `dominant_cell` on the cell projection, paired with the
        // tie-broken peak count of 1 on the count projection. Pinned
        // uniformly across every closed-axis implementor.
        let hist: AxisHistogram<A> = axis_iter::<A>().collect();
        let first = axis_iter::<A>().next().expect(
            "every ClosedAxis implementor has at least one variant per the ClosedAxis contract",
        );
        assert_eq!(
            hist.dominant_observation(),
            Some((first, 1)),
            "uniform axis-cover histogram dominant_observation must be \
             Some((first cell in declaration order, 1)) on axis {}",
            std::any::type_name::<A>(),
        );
    }

    #[test]
    fn axis_histogram_dominant_observation_empty_is_none_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_dominant_observation_empty_is_none::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_dominant_observation_singleton_picks_observed_pair_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_dominant_observation_singleton_picks_observed_pair::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_dominant_observation_axis_cover_picks_first_pair_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_dominant_observation_axis_cover_picks_first_pair::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_dominant_observation_cell_projection_equals_dominant_cell() {
        // The fused-pair → cell projection agreement law:
        // dominant_observation().map(|(c, _)| c) == dominant_cell()
        // pointwise on every histogram. Pin across the canonical
        // observation-mix shapes (empty, singleton, unique-max,
        // tied-max, three-way uniform) so a future regression in
        // either side (e.g. tie-break drifting between `dominant_cell`
        // and `dominant_observation`) surfaces here. The empty case
        // collapses both sides to `None == None`; the non-empty cases
        // pin the first-max declaration-order tie-break across both
        // primitives.
        let inputs: [&[DiffLineKind]; 5] = [
            &[],
            &[DiffLineKind::Removed],
            &[
                DiffLineKind::Removed,
                DiffLineKind::Added,
                DiffLineKind::Added,
            ],
            &[DiffLineKind::Added, DiffLineKind::Removed],
            &[
                DiffLineKind::Context,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
        ];
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            assert_eq!(
                hist.dominant_observation().map(|(c, _)| c),
                hist.dominant_cell(),
                "dominant_observation cell projection must equal dominant_cell on \
                 input of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_dominant_observation_count_projection_equals_peak_count() {
        // The fused-pair → count projection agreement law:
        // dominant_observation().map_or(0, |(_, n)| n) == peak_count()
        // pointwise on every histogram. The empty boundary collapses
        // `None.map_or(0, …) == 0 == peak_count` (vacuous agreement);
        // non-empty histograms collapse `Some(peak).map_or(0, …) ==
        // peak == peak_count` (defining agreement). Pin across the
        // canonical observation-mix shapes so a future regression in
        // either side (e.g. dominant_observation drifting from the
        // peak count by counting the wrong cell) surfaces here.
        let inputs: [&[DiffLineKind]; 5] = [
            &[],
            &[DiffLineKind::Removed],
            &[
                DiffLineKind::Removed,
                DiffLineKind::Added,
                DiffLineKind::Added,
            ],
            &[DiffLineKind::Added, DiffLineKind::Removed],
            &[
                DiffLineKind::Context,
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
        ];
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            assert_eq!(
                hist.dominant_observation().map_or(0, |(_, n)| n),
                hist.peak_count(),
                "dominant_observation count projection must equal peak_count on \
                 input of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_dominant_observation_fused_pair_agrees_with_open_coded_paired_form() {
        // The fused-pair lift's defining equivalence: when non-empty,
        // dominant_observation() == Some((dominant_cell().unwrap(),
        // peak_count())). The empty case is the one-discriminant
        // boundary where the fused pair carries `None` instead of the
        // awkward `(None, 0)` pair the open-coded form yields. Pin
        // across the canonical observation-mix shapes — and pin the
        // empty-case boundary separately on the `is_none()` form so
        // both branches of the discriminant get a witness.
        let empty: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
        assert!(empty.dominant_observation().is_none());
        assert!(empty.is_empty());

        let inputs: [&[DiffLineKind]; 4] = [
            &[DiffLineKind::Added],
            &[
                DiffLineKind::Added,
                DiffLineKind::Removed,
                DiffLineKind::Added,
            ],
            &[DiffLineKind::Added, DiffLineKind::Removed],
            &[
                DiffLineKind::Context,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
        ];
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            let open_coded = hist.dominant_cell().map(|c| (c, hist.peak_count()));
            assert_eq!(
                hist.dominant_observation(),
                open_coded,
                "dominant_observation must equal the open-coded \
                 dominant_cell().map(|c| (c, peak_count())) form on input of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_dominant_observation_count_equals_count_of_pair_cell() {
        // The peak-count consistency law: on every non-empty
        // histogram, the count in the fused pair equals
        // `self.count(pair.0)` (the pair's cell, looked up through the
        // count indexer). Confirms the fused pair is internally
        // consistent — the count carried by the pair really is the
        // count of the cell the pair names, not some other cell's
        // count. Empty case pinned separately on `is_none()`.
        let inputs: [&[DiffLineKind]; 4] = [
            &[DiffLineKind::Added],
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
            &[DiffLineKind::Added, DiffLineKind::Removed],
            &[
                DiffLineKind::Context,
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
        ];
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            let (cell, count) = hist
                .dominant_observation()
                .expect("non-empty histogram always has a dominant observation");
            assert_eq!(
                hist.count(cell),
                count,
                "dominant_observation pair count must equal count(pair.cell) on \
                 input of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_dominant_observation_after_merge_count_is_monotone() {
        // The (merge, dominant_observation) composition: the modal
        // pair's count projection is monotone under `merge` (inherited
        // from peak_count's monotonicity). Pin with disjoint-support,
        // overlapping-support (where the merge's modal count strictly
        // grows on the shared cell), and identity (empty-rhs) shapes
        // so the monotonicity gets a witness at each boundary. The
        // *cell* projection is not strictly monotone (it can shift to
        // a different cell when a previously-trailing cell overtakes
        // the leader through merge), so the count projection is
        // pinned alone here.
        let added_two: AxisHistogram<DiffLineKind> = [DiffLineKind::Added, DiffLineKind::Added]
            .into_iter()
            .collect();
        let removed_one: AxisHistogram<DiffLineKind> =
            std::iter::once(DiffLineKind::Removed).collect();
        let added_three_context_one: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Context,
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Added,
        ]
        .into_iter()
        .collect();
        let empty_hist: AxisHistogram<DiffLineKind> = AxisHistogram::empty();

        // Disjoint supports: merge's modal count equals max of either side.
        let disjoint = added_two.clone().merge(&removed_one);
        let (_, dcount) = disjoint.dominant_observation().expect("non-empty merge");
        assert!(dcount >= added_two.peak_count());
        assert!(dcount >= removed_one.peak_count());

        // Overlapping supports: Added's two + Added's three → 5,
        // strictly past each side's modal count.
        let overlap = added_two.clone().merge(&added_three_context_one);
        let (overlap_cell, overlap_count) =
            overlap.dominant_observation().expect("non-empty merge");
        assert_eq!(overlap_cell, DiffLineKind::Added);
        assert_eq!(overlap_count, 5);
        assert!(overlap_count >= added_two.peak_count());
        assert!(overlap_count >= added_three_context_one.peak_count());

        // Identity (empty-rhs): merge leaves the modal pair unchanged
        // (the lhs's pair survives the empty-rhs merge intact).
        let with_empty = added_two.clone().merge(&empty_hist);
        assert_eq!(
            with_empty.dominant_observation(),
            added_two.dominant_observation(),
        );
    }

    // ---- AxisHistogram::peak_multiplicity trait-uniform laws ----
    //
    // Three trait-uniform laws reach every [`ClosedAxis`] implementor
    // through [`for_each_closed_axis_implementor`] so the per-axis
    // peak_multiplicity projection's contract holds uniformly without
    // per-axis test duplication: empty → 0 (no peak, no level set);
    // singleton → 1 on every cell K (one observed cell stands alone at
    // its own peak); uniform axis-cover → axis_cardinality::<A>()
    // (every cell observed exactly once, every cell tied at the shared
    // peak of 1 — the modal level set covers the entire axis).
    // Concrete strict-modal, tied-modal, defining-equivalence,
    // distinct-cells-bound, and merge-interaction pins follow below on
    // [`DiffLineKind`].

    fn assert_peak_multiplicity_empty_is_zero<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        let hist = AxisHistogram::<A>::empty();
        assert_eq!(
            hist.peak_multiplicity(),
            0,
            "empty histogram peak_multiplicity must be 0 on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_peak_multiplicity_singleton_is_one<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // For every cell of the axis: a histogram built from one
        // observation of that cell has peak_multiplicity = 1 — exactly
        // one cell sits at the peak (the observed cell itself, count 1).
        // The singleton-support modality boundary uniformly across every
        // closed-axis implementor.
        for observed in axis_iter::<A>() {
            let hist: AxisHistogram<A> = std::iter::once(observed).collect();
            assert_eq!(
                hist.peak_multiplicity(),
                1,
                "singleton peak_multiplicity must equal 1 \
                 for observed cell {observed:?} on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_peak_multiplicity_axis_cover_is_axis_cardinality<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Observing every cell exactly once produces a uniform
        // histogram; every cell sits at the shared peak of 1, so the
        // modal level set covers the entire axis: peak_multiplicity ==
        // axis_cardinality::<A>(). The structural witness for the
        // `is_uniform_count ⇒ peak_multiplicity == distinct_cells`
        // companion law at the maximum-coverage shape (where
        // distinct_cells equals axis_cardinality). Pinned uniformly
        // across every closed-axis implementor.
        let hist: AxisHistogram<A> = axis_iter::<A>().collect();
        assert_eq!(
            hist.peak_multiplicity(),
            axis_cardinality::<A>(),
            "uniform axis-cover histogram peak_multiplicity must equal \
             axis_cardinality {} on axis {}",
            axis_cardinality::<A>(),
            std::any::type_name::<A>(),
        );
    }

    #[test]
    fn axis_histogram_peak_multiplicity_empty_is_zero_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_peak_multiplicity_empty_is_zero::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_peak_multiplicity_singleton_is_one_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_peak_multiplicity_singleton_is_one::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_peak_multiplicity_axis_cover_is_axis_cardinality_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_peak_multiplicity_axis_cover_is_axis_cardinality::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_peak_multiplicity_equals_open_coded_modal_level_set_count() {
        // The defining equivalence: peak_multiplicity() equals the
        // open-coded `iter().filter(|&(_, c)| c > 0 && c ==
        // peak_count()).count()` form pointwise on every histogram. Pin
        // across the canonical observation-mix shapes (empty, singleton,
        // unique-max, tied-max, three-way uniform) so a future
        // regression in either side surfaces here. The `c > 0` guard
        // matters at the empty boundary: without it the filter would
        // sweep every zero-count cell into the modal level set on the
        // empty histogram (where peak_count is 0), so the open-coded
        // form would diverge from the named scalar's `0` reading.
        let inputs: [&[DiffLineKind]; 5] = [
            &[],
            &[DiffLineKind::Added],
            &[DiffLineKind::Added, DiffLineKind::Added],
            &[DiffLineKind::Added, DiffLineKind::Removed],
            &[
                DiffLineKind::Added,
                DiffLineKind::Removed,
                DiffLineKind::Context,
            ],
        ];
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            let peak = hist.peak_count();
            let open_coded = hist.iter().filter(|&(_, c)| c > 0 && c == peak).count();
            assert_eq!(
                hist.peak_multiplicity(),
                open_coded,
                "peak_multiplicity must equal open-coded modal-level-set count \
                 on input of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_peak_multiplicity_distinguishes_strict_modal_from_tied_modal() {
        // The unique-modal / tied-modal classifier law: a strictly
        // dominant histogram reads peak_multiplicity == 1 (the
        // dominant cell stands alone at the peak — the declaration-
        // order tie-break is not exercised), and a tied-modal
        // histogram reads peak_multiplicity >= 2 (the tie-break is
        // exercised). Pinned on a strict-modal shape (one cell heavier
        // than the others), a two-way tied-modal shape (two cells at
        // the same peak), and a three-way tied-modal shape (the
        // uniform-axis-cover over three cells).
        let strict_modal: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
        ]
        .into_iter()
        .collect();
        assert_eq!(strict_modal.peak_multiplicity(), 1);

        let two_way_tied: AxisHistogram<DiffLineKind> =
            [DiffLineKind::Added, DiffLineKind::Removed]
                .into_iter()
                .collect();
        assert_eq!(two_way_tied.peak_multiplicity(), 2);

        let three_way_tied: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ]
        .into_iter()
        .collect();
        assert_eq!(three_way_tied.peak_multiplicity(), 3);
    }

    #[test]
    fn axis_histogram_peak_multiplicity_is_bounded_above_by_distinct_cells() {
        // The structural-bound law: the modal level set is a subset of
        // the observed support, so its cardinality is bounded above by
        // distinct_cells. Equality holds iff is_uniform_count is true.
        // Pinned across the canonical shapes (empty, singleton,
        // strict-modal, tied-modal-equal-to-support, tied-modal-strict-
        // subset-of-support) so both the bound and the equality case
        // get tight witnesses.
        let strict_subset: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ]
        .into_iter()
        .collect();
        let uniform_two_cell: AxisHistogram<DiffLineKind> =
            [DiffLineKind::Added, DiffLineKind::Removed]
                .into_iter()
                .collect();
        let inputs: [&[DiffLineKind]; 5] = [
            &[],
            &[DiffLineKind::Added],
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
            &[DiffLineKind::Added, DiffLineKind::Removed],
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
                DiffLineKind::Context,
            ],
        ];
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            assert!(
                hist.peak_multiplicity() <= hist.distinct_cells(),
                "peak_multiplicity {} must be <= distinct_cells {} on input of length {}",
                hist.peak_multiplicity(),
                hist.distinct_cells(),
                input.len(),
            );
            if hist.is_uniform_count() {
                assert_eq!(
                    hist.peak_multiplicity(),
                    hist.distinct_cells(),
                    "peak_multiplicity must equal distinct_cells on uniform-count \
                     histogram (input of length {})",
                    input.len(),
                );
            }
        }
        // Direct pin on the strict-subset shape: distinct_cells = 3,
        // peak_multiplicity = 1 (Added strictly dominates).
        assert_eq!(strict_subset.distinct_cells(), 3);
        assert_eq!(strict_subset.peak_multiplicity(), 1);
        // Direct pin on the uniform-two-cell shape: distinct_cells = 2,
        // peak_multiplicity = 2 (every observed cell tied at 1).
        assert_eq!(uniform_two_cell.distinct_cells(), 2);
        assert_eq!(uniform_two_cell.peak_multiplicity(), 2);
    }

    #[test]
    fn axis_histogram_peak_multiplicity_is_zero_iff_is_empty() {
        // Boundary pin: peak_multiplicity == 0 iff is_empty is true.
        // The companion-invariant peer to the same boundary equivalence
        // peak_count and distinct_cells both carry — every scalar
        // projection on the histogram surface uses `0` as its
        // empty-witness, and every non-empty histogram contributes at
        // least one cell to the modal level set.
        let empty: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
        assert!(empty.is_empty());
        assert_eq!(empty.peak_multiplicity(), 0);

        let singleton: AxisHistogram<DiffLineKind> =
            std::iter::once(DiffLineKind::Removed).collect();
        assert!(!singleton.is_empty());
        assert!(singleton.peak_multiplicity() >= 1);
    }

    // ---- AxisHistogram::trough_count trait-uniform laws ----
    //
    // Three trait-uniform laws reach every [`ClosedAxis`] implementor
    // through [`for_each_closed_axis_implementor`] so the per-axis
    // trough_count projection's contract holds uniformly without
    // per-axis test duplication: empty → 0; singleton → 1 on every
    // cell; uniform axis-cover → 1 (every cell observed exactly once,
    // so the minimum over the support equals 1). Concrete (cell, count)
    // pairing, structural bound, and merge non-monotonicity pins
    // follow below on [`DiffLineKind`].

    fn assert_trough_count_empty_is_zero<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        let hist = AxisHistogram::<A>::empty();
        assert_eq!(
            hist.trough_count(),
            0,
            "empty histogram trough_count must be 0 on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_trough_count_singleton_is_one<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // For every cell of the axis: a histogram built from one
        // observation of that cell has trough count exactly 1 — the
        // singleton-support trough law uniformly across implementors.
        // Pointwise equal to `peak_count` on the singleton support
        // (every singleton is uniform, so peak and trough agree).
        for observed in axis_iter::<A>() {
            let hist: AxisHistogram<A> = std::iter::once(observed).collect();
            assert_eq!(
                hist.trough_count(),
                1,
                "singleton trough_count must equal 1 \
                 for observed cell {observed:?} on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_trough_count_axis_cover_is_one<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Observing every cell exactly once produces a uniform
        // histogram; the minimum cell count over the support is 1 —
        // the uniform-axis-cover trough law. Peer to the
        // uniform-axis-cover law on `peak_count` (which also reads 1
        // on the same input): the (peak, trough) pair agrees pointwise
        // on every uniform histogram, pinned uniformly across every
        // closed-axis implementor.
        let hist: AxisHistogram<A> = axis_iter::<A>().collect();
        assert_eq!(
            hist.trough_count(),
            1,
            "uniform axis-cover histogram trough_count must equal 1 on {}",
            std::any::type_name::<A>(),
        );
    }

    #[test]
    fn axis_histogram_trough_count_empty_is_zero_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_trough_count_empty_is_zero::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_trough_count_singleton_is_one_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_trough_count_singleton_is_one::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_trough_count_axis_cover_is_one_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_trough_count_axis_cover_is_one::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_trough_count_equals_recessive_cell_count_when_non_empty() {
        // The lift's defining pairing law: on every non-empty histogram
        // the scalar `trough_count` equals the count carried by the
        // recessive cell (i.e. `count(recessive_cell().unwrap())`). The
        // structural dual of the
        // `peak_count == count(dominant_cell())` law on the majority
        // side. Pin pointwise equivalence over typed `DiffLineKind`
        // cells across four canonical observation-mix shapes
        // (singleton, unique-min, tied-min, three-way uniform) so a
        // future regression in either side surfaces here. The empty
        // boundary is pinned separately by the trait-uniform
        // empty-is-zero law above and the dedicated
        // `trough_count_iff_is_empty_is_zero` test below.
        let inputs: [&[DiffLineKind]; 4] = [
            &[DiffLineKind::Added],
            &[
                DiffLineKind::Added,
                DiffLineKind::Removed,
                DiffLineKind::Added,
            ],
            &[DiffLineKind::Added, DiffLineKind::Removed],
            &[
                DiffLineKind::Context,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
        ];
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            let recessive = hist
                .recessive_cell()
                .expect("non-empty histogram has a recessive cell");
            assert_eq!(
                hist.trough_count(),
                hist.count(recessive),
                "trough_count must equal count(recessive_cell()) on non-empty input \
                 of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_trough_count_iff_is_empty_is_zero() {
        // Boundary pin: trough_count == 0 iff is_empty is true.
        // Equivalence holds across both directions — an empty history
        // reads 0, a non-empty history reads at least 1 (every observed
        // cell carries at least one observation by construction). Peer
        // to the same boundary equivalence peak_count, distinct_cells,
        // and dominant_cell all carry.
        let empty: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
        assert!(empty.is_empty());
        assert_eq!(empty.trough_count(), 0);

        let singleton: AxisHistogram<DiffLineKind> =
            std::iter::once(DiffLineKind::Removed).collect();
        assert!(!singleton.is_empty());
        assert!(singleton.trough_count() >= 1);
    }

    #[test]
    fn axis_histogram_trough_count_is_bounded_above_by_peak_count() {
        // Structural-bound pin: trough_count ∈ [0, peak_count] on every
        // histogram, with equality iff every observed cell carries the
        // same count (the *uniform-observed-count* shape). Pinned over
        // five observation shapes — empty (0 == 0); singleton
        // (uniform, trough == peak == 1); single-cell-multi-observation
        // (uniform-support, trough == peak == 2); k-cell uniform
        // (axis-cover by hand, trough == peak == 1); skew (strict
        // inequality witness, trough == 1 < peak == 2) — so both the
        // bound and the equality case get tight witnesses across the
        // boundary spectrum.
        let single_cell_two_observations: &[DiffLineKind] =
            &[DiffLineKind::Added, DiffLineKind::Added];
        let two_cell_uniform: &[DiffLineKind] = &[DiffLineKind::Added, DiffLineKind::Removed];
        let skew: &[DiffLineKind] = &[
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
        ];
        let inputs: [&[DiffLineKind]; 5] = [
            &[],
            &[DiffLineKind::Removed],
            single_cell_two_observations,
            two_cell_uniform,
            skew,
        ];
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            assert!(
                hist.trough_count() <= hist.peak_count(),
                "trough_count {} must be <= peak_count {} on input of length {}",
                hist.trough_count(),
                hist.peak_count(),
                input.len(),
            );
            // Equality case — every observed cell carries the same count.
            let observed_counts: Vec<usize> = hist.nonzero().map(|(_, count)| count).collect();
            let uniform = observed_counts
                .first()
                .is_some_and(|&first| observed_counts.iter().all(|&c| c == first));
            if uniform || hist.is_empty() {
                assert_eq!(
                    hist.trough_count(),
                    hist.peak_count(),
                    "trough_count must equal peak_count when observed counts \
                     are uniform on input of length {}",
                    input.len(),
                );
            } else {
                assert!(
                    hist.trough_count() < hist.peak_count(),
                    "trough_count must be strictly less than peak_count when \
                     observed counts are non-uniform on input of length {}",
                    input.len(),
                );
            }
        }
    }

    #[test]
    fn axis_histogram_trough_count_after_merge_is_non_monotonic() {
        // The (merge, trough_count) composition: in deliberate contrast
        // to peak_count's strict monotonicity under merge, trough_count
        // can either *grow* (when the supports coincide, every observed
        // cell's count grows so does the minimum) or *shrink* (when one
        // side observes a cell the other does not, the new cell enters
        // the merged support carrying that side's count and can pull
        // the merged trough below either side's). The empty-identity
        // law still holds. Pinned with overlapping-support (grow),
        // disjoint-support (shrink-or-equal), and identity (empty-rhs)
        // shapes so each branch of the non-monotonic behavior gets a
        // tight witness.
        let added_two: AxisHistogram<DiffLineKind> = [DiffLineKind::Added, DiffLineKind::Added]
            .into_iter()
            .collect();
        let added_three: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Added,
        ]
        .into_iter()
        .collect();
        let removed_one: AxisHistogram<DiffLineKind> =
            std::iter::once(DiffLineKind::Removed).collect();
        let empty_hist: AxisHistogram<DiffLineKind> = AxisHistogram::empty();

        // Overlapping (identical) supports {Added}: trough grows from
        // (2, 3) → 5, strictly past each side's trough.
        let overlap = added_two.clone().merge(&added_three);
        assert_eq!(overlap.trough_count(), 5);
        assert!(overlap.trough_count() > added_two.trough_count());
        assert!(overlap.trough_count() > added_three.trough_count());

        // Disjoint supports {Added:2} and {Removed:1}: the merged
        // support {Added:2, Removed:1} pulls the merged trough down to
        // 1 — strictly below the higher side's trough (2). Witnesses
        // the *shrink* branch of non-monotonicity.
        let disjoint = added_two.clone().merge(&removed_one);
        assert_eq!(disjoint.trough_count(), 1);
        assert!(disjoint.trough_count() < added_two.trough_count());
        assert_eq!(disjoint.trough_count(), removed_one.trough_count());

        // Identity (empty-rhs): merge leaves the trough unchanged.
        let with_empty = added_two.clone().merge(&empty_hist);
        assert_eq!(with_empty.trough_count(), added_two.trough_count());
    }

    // ---- AxisHistogram::recessive_observation trait-uniform laws ----
    //
    // Three trait-uniform laws reach every [`ClosedAxis`] implementor
    // through [`for_each_closed_axis_implementor`] so the per-axis
    // recessive_observation fused-pair projection's contract holds
    // uniformly without per-axis test duplication: empty → None;
    // singleton → Some((K, 1)) on every cell K; uniform axis-cover →
    // Some((first cell, 1)) — the minority pair recovered uniformly
    // through the declaration-order tie-break inherited from
    // `recessive_cell`. Concrete projection-agreement, fused-form
    // equivalence, internal-consistency, peak-bound, and merge non-
    // monotonicity pins follow below on [`DiffLineKind`].

    fn assert_recessive_observation_empty_is_none<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        let hist = AxisHistogram::<A>::empty();
        assert_eq!(
            hist.recessive_observation(),
            None,
            "empty histogram recessive_observation must be None on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_recessive_observation_singleton_picks_observed_pair<A>()
    where
        A: ClosedAxis + std::fmt::Debug + PartialEq,
    {
        // For every cell of the axis: a histogram built from one
        // observation of that cell has recessive_observation =
        // Some((cell, 1)) — the fused (cell, count) pair recovered
        // uniformly from a one-observation history (the support is
        // a singleton {cell}, so the trough coincides with the peak
        // on the same cell).
        for observed in axis_iter::<A>() {
            let hist: AxisHistogram<A> = std::iter::once(observed).collect();
            assert_eq!(
                hist.recessive_observation(),
                Some((observed, 1)),
                "singleton recessive_observation must equal Some(({observed:?}, 1)) \
                 on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_recessive_observation_axis_cover_picks_first_pair<A>()
    where
        A: ClosedAxis + std::fmt::Debug + PartialEq,
    {
        // Observing every cell exactly once produces a uniform
        // histogram (every cell at 1, trough count tied across the
        // axis); recessive_observation must return Some((first cell,
        // 1)) — the declaration-order tie-break inherited from
        // `recessive_cell` on the cell projection, paired with the
        // tie-broken trough count of 1 on the count projection. Pinned
        // uniformly across every closed-axis implementor.
        let hist: AxisHistogram<A> = axis_iter::<A>().collect();
        let first = axis_iter::<A>().next().expect(
            "every ClosedAxis implementor has at least one variant per the ClosedAxis contract",
        );
        assert_eq!(
            hist.recessive_observation(),
            Some((first, 1)),
            "uniform axis-cover histogram recessive_observation must be \
             Some((first cell in declaration order, 1)) on axis {}",
            std::any::type_name::<A>(),
        );
    }

    #[test]
    fn axis_histogram_recessive_observation_empty_is_none_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_recessive_observation_empty_is_none::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_recessive_observation_singleton_picks_observed_pair_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_recessive_observation_singleton_picks_observed_pair::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_recessive_observation_axis_cover_picks_first_pair_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_recessive_observation_axis_cover_picks_first_pair::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_recessive_observation_cell_projection_equals_recessive_cell() {
        // The fused-pair → cell projection agreement law:
        // recessive_observation().map(|(c, _)| c) == recessive_cell()
        // pointwise on every histogram. Pin across the canonical
        // observation-mix shapes (empty, singleton, unique-min,
        // tied-min, three-way uniform) so a future regression in
        // either side (e.g. tie-break drifting between `recessive_cell`
        // and `recessive_observation`) surfaces here. The empty case
        // collapses both sides to `None == None`; the non-empty cases
        // pin the first-min declaration-order tie-break across both
        // primitives.
        let inputs: [&[DiffLineKind]; 5] = [
            &[],
            &[DiffLineKind::Removed],
            &[
                DiffLineKind::Removed,
                DiffLineKind::Added,
                DiffLineKind::Added,
            ],
            &[DiffLineKind::Added, DiffLineKind::Removed],
            &[
                DiffLineKind::Context,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
        ];
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            assert_eq!(
                hist.recessive_observation().map(|(c, _)| c),
                hist.recessive_cell(),
                "recessive_observation cell projection must equal recessive_cell on \
                 input of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_recessive_observation_count_projection_equals_trough_count() {
        // The fused-pair → count projection agreement law:
        // recessive_observation().map_or(0, |(_, n)| n) == trough_count()
        // pointwise on every histogram. The empty boundary collapses
        // `None.map_or(0, …) == 0 == trough_count` (vacuous agreement);
        // non-empty histograms collapse `Some(trough).map_or(0, …) ==
        // trough == trough_count` (defining agreement). Pin across the
        // canonical observation-mix shapes so a future regression in
        // either side (e.g. recessive_observation drifting from the
        // trough count by counting the wrong cell) surfaces here.
        let inputs: [&[DiffLineKind]; 5] = [
            &[],
            &[DiffLineKind::Removed],
            &[
                DiffLineKind::Removed,
                DiffLineKind::Added,
                DiffLineKind::Added,
            ],
            &[DiffLineKind::Added, DiffLineKind::Removed],
            &[
                DiffLineKind::Context,
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
        ];
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            assert_eq!(
                hist.recessive_observation().map_or(0, |(_, n)| n),
                hist.trough_count(),
                "recessive_observation count projection must equal trough_count on \
                 input of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_recessive_observation_fused_pair_agrees_with_open_coded_paired_form() {
        // The fused-pair lift's defining equivalence: when non-empty,
        // recessive_observation() == Some((recessive_cell().unwrap(),
        // trough_count())). The empty case is the one-discriminant
        // boundary where the fused pair carries `None` instead of the
        // awkward `(None, 0)` pair the open-coded form yields. Pin
        // across the canonical observation-mix shapes — and pin the
        // empty-case boundary separately on the `is_none()` form so
        // both branches of the discriminant get a witness.
        let empty: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
        assert!(empty.recessive_observation().is_none());
        assert!(empty.is_empty());

        let inputs: [&[DiffLineKind]; 4] = [
            &[DiffLineKind::Added],
            &[
                DiffLineKind::Added,
                DiffLineKind::Removed,
                DiffLineKind::Added,
            ],
            &[DiffLineKind::Added, DiffLineKind::Removed],
            &[
                DiffLineKind::Context,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
        ];
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            let open_coded = hist.recessive_cell().map(|c| (c, hist.trough_count()));
            assert_eq!(
                hist.recessive_observation(),
                open_coded,
                "recessive_observation must equal the open-coded \
                 recessive_cell().map(|c| (c, trough_count())) form on input of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_recessive_observation_count_equals_count_of_pair_cell() {
        // The trough-count consistency law: on every non-empty
        // histogram, the count in the fused pair equals
        // `self.count(pair.0)` (the pair's cell, looked up through the
        // count indexer). Confirms the fused pair is internally
        // consistent — the count carried by the pair really is the
        // count of the cell the pair names, not some other cell's
        // count. Empty case pinned separately on `is_none()`.
        let inputs: [&[DiffLineKind]; 4] = [
            &[DiffLineKind::Added],
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
            &[DiffLineKind::Added, DiffLineKind::Removed],
            &[
                DiffLineKind::Context,
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
        ];
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            let (cell, count) = hist
                .recessive_observation()
                .expect("non-empty histogram always has a recessive observation");
            assert_eq!(
                hist.count(cell),
                count,
                "recessive_observation pair count must equal count(pair.cell) on \
                 input of length {}",
                input.len(),
            );
            // Recessive-count floor: every non-empty histogram has a
            // recessive count of at least 1.
            assert!(
                count >= 1,
                "recessive_observation pair count must be >= 1 on non-empty input \
                 of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_recessive_observation_count_is_bounded_above_by_dominant_observation_count() {
        // The (recessive, dominant)-pair structural-bound law on the
        // fused-pair surface: the trough-count component of
        // recessive_observation is bounded above by the peak-count
        // component of dominant_observation on every histogram — the
        // fused-pair lift of the `trough_count <= peak_count` invariant
        // every consumer reads on the scalar surface. Pin across the
        // canonical observation-mix shapes (empty, singleton, uniform,
        // strict-skew) so both branches of the bound (equality on the
        // uniform-observed-count shapes, strict inequality on the
        // skewed shapes) get a witness.
        let inputs: [&[DiffLineKind]; 5] = [
            &[],
            &[DiffLineKind::Added],
            &[DiffLineKind::Added, DiffLineKind::Added],
            &[DiffLineKind::Added, DiffLineKind::Removed],
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
        ];
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            let recessive_n = hist.recessive_observation().map_or(0, |(_, n)| n);
            let dominant_n = hist.dominant_observation().map_or(0, |(_, n)| n);
            assert!(
                recessive_n <= dominant_n,
                "recessive_observation count {recessive_n} must be <= \
                 dominant_observation count {dominant_n} on input of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_recessive_observation_after_merge_count_is_non_monotonic() {
        // The (merge, recessive_observation) composition: in
        // deliberate contrast to dominant_observation's strict
        // count-monotonicity under `merge`, the recessive_observation's
        // count projection is *non-monotonic* (inherited from
        // trough_count's non-monotonicity). Pin with overlapping-
        // support (grow), disjoint-support (shrink-or-equal), and
        // identity (empty-rhs) shapes so each branch of the non-
        // monotonic behavior gets a tight witness, plus the
        // empty-identity law on the full fused-pair shape.
        let added_two: AxisHistogram<DiffLineKind> = [DiffLineKind::Added, DiffLineKind::Added]
            .into_iter()
            .collect();
        let added_three: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Added,
        ]
        .into_iter()
        .collect();
        let removed_one: AxisHistogram<DiffLineKind> =
            std::iter::once(DiffLineKind::Removed).collect();
        let empty_hist: AxisHistogram<DiffLineKind> = AxisHistogram::empty();

        // Overlapping (identical) supports {Added}: trough grows from
        // (2, 3) → 5, strictly past each side's recessive count.
        let overlap = added_two.clone().merge(&added_three);
        let (overlap_cell, overlap_count) =
            overlap.recessive_observation().expect("non-empty merge");
        assert_eq!(overlap_cell, DiffLineKind::Added);
        assert_eq!(overlap_count, 5);
        assert!(overlap_count > added_two.recessive_observation().map_or(0, |(_, n)| n));
        assert!(overlap_count > added_three.recessive_observation().map_or(0, |(_, n)| n));

        // Disjoint supports {Added:2} and {Removed:1}: the merged
        // support {Added:2, Removed:1} pulls the merged trough down to
        // 1 — strictly below the higher side's recessive count (2).
        let disjoint = added_two.clone().merge(&removed_one);
        let (_, disjoint_count) = disjoint.recessive_observation().expect("non-empty merge");
        assert_eq!(disjoint_count, 1);
        assert!(disjoint_count < added_two.recessive_observation().map_or(0, |(_, n)| n));

        // Identity (empty-rhs): merge leaves the recessive
        // observation pair unchanged on the full fused-pair shape (the
        // lhs's pair survives the empty-rhs merge intact).
        let with_empty = added_two.clone().merge(&empty_hist);
        assert_eq!(
            with_empty.recessive_observation(),
            added_two.recessive_observation(),
        );
    }

    // ---- AxisHistogram::trough_multiplicity trait-uniform laws ----
    //
    // Three trait-uniform laws reach every [`ClosedAxis`] implementor
    // through [`for_each_closed_axis_implementor`] so the per-axis
    // trough_multiplicity projection's contract holds uniformly without
    // per-axis test duplication: empty → 0 (no trough, no level set);
    // singleton → 1 on every cell K (one observed cell stands alone at
    // its own trough); uniform axis-cover → axis_cardinality::<A>()
    // (every cell observed exactly once, peak and trough coincide at
    // the shared count of 1 — the antimodal level set covers the entire
    // axis). Concrete strict-trough, tied-trough, defining-equivalence,
    // distinct-cells-bound, and modal-trough-coincidence pins follow
    // below on [`DiffLineKind`].

    fn assert_trough_multiplicity_empty_is_zero<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        let hist = AxisHistogram::<A>::empty();
        assert_eq!(
            hist.trough_multiplicity(),
            0,
            "empty histogram trough_multiplicity must be 0 on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_trough_multiplicity_singleton_is_one<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // For every cell of the axis: a histogram built from one
        // observation of that cell has trough_multiplicity = 1 —
        // exactly one cell sits at the trough (the observed cell
        // itself, count 1; every other cell carries count 0 and is
        // excluded from the antimodal level set by the `c > 0` guard).
        // The singleton-support antimodality boundary uniformly across
        // every closed-axis implementor.
        for observed in axis_iter::<A>() {
            let hist: AxisHistogram<A> = std::iter::once(observed).collect();
            assert_eq!(
                hist.trough_multiplicity(),
                1,
                "singleton trough_multiplicity must equal 1 \
                 for observed cell {observed:?} on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_trough_multiplicity_axis_cover_is_axis_cardinality<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Observing every cell exactly once produces a uniform
        // histogram; peak and trough coincide at the shared count of 1,
        // so every cell sits in the antimodal level set and the
        // antimodal level set covers the entire axis:
        // trough_multiplicity == axis_cardinality::<A>(). The
        // structural witness for the `is_uniform_count ⇒
        // trough_multiplicity == distinct_cells` companion law at the
        // maximum-coverage shape (where distinct_cells equals
        // axis_cardinality), and the modal/antimodal coincidence on
        // every uniform-count histogram (peak_multiplicity and
        // trough_multiplicity both read off the same value). Pinned
        // uniformly across every closed-axis implementor.
        let hist: AxisHistogram<A> = axis_iter::<A>().collect();
        assert_eq!(
            hist.trough_multiplicity(),
            axis_cardinality::<A>(),
            "uniform axis-cover histogram trough_multiplicity must equal \
             axis_cardinality {} on axis {}",
            axis_cardinality::<A>(),
            std::any::type_name::<A>(),
        );
    }

    #[test]
    fn axis_histogram_trough_multiplicity_empty_is_zero_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_trough_multiplicity_empty_is_zero::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_trough_multiplicity_singleton_is_one_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_trough_multiplicity_singleton_is_one::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_trough_multiplicity_axis_cover_is_axis_cardinality_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_trough_multiplicity_axis_cover_is_axis_cardinality::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_trough_multiplicity_equals_open_coded_antimodal_level_set_count() {
        // The defining equivalence: trough_multiplicity() equals the
        // open-coded `iter().filter(|&(_, c)| c > 0 && c ==
        // trough_count()).count()` form pointwise on every histogram.
        // Pin across the canonical observation-mix shapes (empty,
        // singleton, unique-min, tied-min, three-way uniform) so a
        // future regression in either side surfaces here. The `c > 0`
        // guard matters at the empty boundary: without it the filter
        // would sweep every zero-count cell into the antimodal level
        // set on the empty histogram (where trough_count is 0), so the
        // open-coded form would diverge from the named scalar's `0`
        // reading — the same load-bearing guard
        // [`Self::peak_multiplicity`] depends on at the empty boundary.
        let inputs: [&[DiffLineKind]; 5] = [
            &[],
            &[DiffLineKind::Added],
            &[DiffLineKind::Added, DiffLineKind::Added],
            &[DiffLineKind::Added, DiffLineKind::Removed],
            &[
                DiffLineKind::Added,
                DiffLineKind::Removed,
                DiffLineKind::Context,
            ],
        ];
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            let trough = hist.trough_count();
            let open_coded = hist.iter().filter(|&(_, c)| c > 0 && c == trough).count();
            assert_eq!(
                hist.trough_multiplicity(),
                open_coded,
                "trough_multiplicity must equal open-coded antimodal-level-set count \
                 on input of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_trough_multiplicity_distinguishes_strict_trough_from_tied_trough() {
        // The unique-trough / tied-trough classifier law: a strictly
        // recessive histogram reads trough_multiplicity == 1 (the
        // recessive cell stands alone at the trough — the declaration-
        // order tie-break is not exercised), and a tied-trough
        // histogram reads trough_multiplicity >= 2 (the tie-break is
        // exercised). Pinned on a strict-trough shape (one cell
        // lighter than the others), a two-way tied-trough shape (two
        // cells at the same trough), and a three-way tied-trough
        // shape (the uniform-axis-cover over three cells, where peak
        // and trough coincide).
        let strict_trough: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
        ]
        .into_iter()
        .collect();
        assert_eq!(strict_trough.trough_multiplicity(), 1);

        let two_way_tied: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ]
        .into_iter()
        .collect();
        assert_eq!(two_way_tied.trough_multiplicity(), 2);

        let three_way_tied: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ]
        .into_iter()
        .collect();
        assert_eq!(three_way_tied.trough_multiplicity(), 3);
    }

    #[test]
    fn axis_histogram_trough_multiplicity_is_bounded_above_by_distinct_cells() {
        // The structural-bound law: the antimodal level set is a
        // subset of the observed support, so its cardinality is
        // bounded above by distinct_cells. Equality holds iff
        // is_uniform_count is true (peak and trough coincide, so
        // every observed cell is in the antimodal level set). Pinned
        // across the canonical shapes (empty, singleton, strict-trough,
        // tied-trough-equal-to-support, tied-trough-strict-subset-of-
        // support) so both the bound and the equality case get tight
        // witnesses.
        let strict_subset: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ]
        .into_iter()
        .collect();
        let uniform_two_cell: AxisHistogram<DiffLineKind> =
            [DiffLineKind::Added, DiffLineKind::Removed]
                .into_iter()
                .collect();
        let inputs: [&[DiffLineKind]; 5] = [
            &[],
            &[DiffLineKind::Added],
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
            &[DiffLineKind::Added, DiffLineKind::Removed],
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
                DiffLineKind::Context,
            ],
        ];
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            assert!(
                hist.trough_multiplicity() <= hist.distinct_cells(),
                "trough_multiplicity {} must be <= distinct_cells {} on input of length {}",
                hist.trough_multiplicity(),
                hist.distinct_cells(),
                input.len(),
            );
            if hist.is_uniform_count() {
                assert_eq!(
                    hist.trough_multiplicity(),
                    hist.distinct_cells(),
                    "trough_multiplicity must equal distinct_cells on uniform-count \
                     histogram (input of length {})",
                    input.len(),
                );
                // On uniform-count histograms, peak and trough
                // coincide on the count surface, so the multiplicity
                // surface collapses to a single value too: the modal
                // and antimodal level sets are the same set.
                assert_eq!(
                    hist.trough_multiplicity(),
                    hist.peak_multiplicity(),
                    "trough_multiplicity must equal peak_multiplicity on \
                     uniform-count histogram (input of length {})",
                    input.len(),
                );
            }
        }
        // Direct pin on the strict-subset shape: distinct_cells = 3
        // (Removed: 1, Added: 2, Context: 1), trough_multiplicity = 2
        // — Removed and Context tie at count 1, strictly below Added
        // at 2 — so the antimodal level set is a strict subset of the
        // observed support (2 < 3); the strict-trough (singleton
        // antimodal level set) witness lives on the
        // (Added, Added, Removed) shape inside the loop above.
        assert_eq!(strict_subset.distinct_cells(), 3);
        assert_eq!(strict_subset.trough_multiplicity(), 2);
        // Direct pin on the uniform-two-cell shape: distinct_cells = 2,
        // trough_multiplicity = 2 (every observed cell tied at 1 — peak
        // and trough coincide).
        assert_eq!(uniform_two_cell.distinct_cells(), 2);
        assert_eq!(uniform_two_cell.trough_multiplicity(), 2);
    }

    #[test]
    fn axis_histogram_trough_multiplicity_is_zero_iff_is_empty() {
        // Boundary pin: trough_multiplicity == 0 iff is_empty is true.
        // The companion-invariant peer to the same boundary equivalence
        // trough_count, peak_multiplicity, and distinct_cells all carry
        // — every scalar projection on the histogram surface uses `0`
        // as its empty-witness, and every non-empty histogram
        // contributes at least one cell to the antimodal level set.
        let empty: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
        assert!(empty.is_empty());
        assert_eq!(empty.trough_multiplicity(), 0);

        let singleton: AxisHistogram<DiffLineKind> =
            std::iter::once(DiffLineKind::Removed).collect();
        assert!(!singleton.is_empty());
        assert!(singleton.trough_multiplicity() >= 1);
    }

    // ---- AxisHistogram::spread trait-uniform laws ----
    //
    // Three trait-uniform laws reach every [`ClosedAxis`] implementor
    // through [`for_each_closed_axis_implementor`] so the per-axis
    // `spread` projection's contract holds uniformly without per-axis
    // test duplication: empty → 0; singleton → 0 on every cell K
    // (one observed cell with count 1, trivially balanced); uniform
    // axis-cover → 0 (every cell at one, perfectly balanced).
    // Concrete strict-skew, defining-equivalence, bound, and merge-
    // interaction pins follow below on [`DiffLineKind`].

    fn assert_spread_empty_is_zero<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        let hist = AxisHistogram::<A>::empty();
        assert_eq!(
            hist.spread(),
            0,
            "empty histogram spread must be 0 on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_spread_singleton_is_zero<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // For every cell of the axis: a histogram built from one
        // observation of that cell has spread = 0 — the
        // singleton-support case is trivially balanced (one observed
        // cell at count 1, peak = trough = 1, spread = 0). Pinned
        // uniformly across every closed-axis implementor.
        for observed in axis_iter::<A>() {
            let hist: AxisHistogram<A> = std::iter::once(observed).collect();
            assert_eq!(
                hist.spread(),
                0,
                "singleton spread must be 0 for observed cell {observed:?} on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_spread_axis_cover_is_zero<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Observing every cell exactly once produces a uniform
        // histogram (every cell at 1, peak = trough = 1, spread = 0)
        // — the structural "every observed kind fired the same number
        // of times" boundary at the maximum-coverage shape. Pinned
        // uniformly across every closed-axis implementor.
        let hist: AxisHistogram<A> = axis_iter::<A>().collect();
        assert_eq!(
            hist.spread(),
            0,
            "axis-cover histogram spread must be 0 on axis {}",
            std::any::type_name::<A>(),
        );
    }

    #[test]
    fn axis_histogram_spread_empty_is_zero_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_spread_empty_is_zero::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_spread_singleton_is_zero_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_spread_singleton_is_zero::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_spread_axis_cover_is_zero_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_spread_axis_cover_is_zero::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_spread_equals_peak_minus_trough() {
        // The lift's defining equivalence: spread reads the same
        // scalar as the open-coded `peak_count - trough_count`
        // subtraction every consumer re-derived inline. Pinned
        // pointwise across the canonical observation-mix shapes
        // (empty, singleton, uniform-tied, strict-skew, heavy-tail)
        // so a future regression in either side surfaces here.
        let inputs: [&[DiffLineKind]; 5] = [
            &[],
            &[DiffLineKind::Added],
            &[
                DiffLineKind::Context,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
        ];
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            assert_eq!(
                hist.spread(),
                hist.peak_count() - hist.trough_count(),
                "spread must equal peak_count - trough_count on input of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_spread_zero_iff_uniformly_observed_count() {
        // The structural-skew predicate: spread == 0 iff every
        // observed cell carries the same count — the "uniformly-
        // observed-count" shape. Pinned at both sides of the
        // equivalence across the boundary shapes:
        //   - empty (vacuously uniform — no observed cells),
        //   - singleton (one observed cell, trivially balanced),
        //   - uniform axis-cover (every cell at one),
        //   - k-cell-observed-k-times-each-once (multiple observed
        //     cells at the same count — the non-trivial balanced
        //     shape),
        //   - strict-skew (two cells, one observed twice and one
        //     once — the canonical skew witness),
        //   - heavy-tail (one dominant cell with multiple, one
        //     rarest observed at one — strong skew).
        let empty: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
        assert_eq!(empty.spread(), 0);

        let singleton: AxisHistogram<DiffLineKind> = std::iter::once(DiffLineKind::Added).collect();
        assert_eq!(singleton.spread(), 0);

        let axis_cover: AxisHistogram<DiffLineKind> = axis_iter::<DiffLineKind>().collect();
        assert_eq!(axis_cover.spread(), 0);

        let two_each: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Removed,
        ]
        .into_iter()
        .collect();
        assert_eq!(two_each.spread(), 0);

        let skewed: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
        ]
        .into_iter()
        .collect();
        assert!(skewed.spread() > 0);
        assert_eq!(skewed.spread(), 1);

        let heavy_tail: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
        ]
        .into_iter()
        .collect();
        assert!(heavy_tail.spread() > 0);
        assert_eq!(heavy_tail.spread(), 3);
    }

    #[test]
    fn axis_histogram_spread_agrees_with_dominant_recessive_cell_equality() {
        // The cross-projection coincidence law: on every non-empty
        // histogram, `spread() == 0` iff `dominant_cell() ==
        // recessive_cell()` — the scalar surface lifts the same
        // "uniformly-observed-count" predicate the modal-pair surface
        // carries on the `(Option<A>, Option<A>)` form. Pinned at
        // three boundary shapes (singleton, uniform axis-cover, and a
        // strict-skew shape) so the two surfaces agree across every
        // branch of the predicate.
        let singleton: AxisHistogram<DiffLineKind> =
            std::iter::once(DiffLineKind::Removed).collect();
        assert_eq!(
            singleton.spread() == 0,
            singleton.dominant_cell() == singleton.recessive_cell(),
        );

        let uniform: AxisHistogram<DiffLineKind> = axis_iter::<DiffLineKind>().collect();
        assert_eq!(
            uniform.spread() == 0,
            uniform.dominant_cell() == uniform.recessive_cell(),
        );

        let skewed: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
        ]
        .into_iter()
        .collect();
        assert_eq!(
            skewed.spread() == 0,
            skewed.dominant_cell() == skewed.recessive_cell(),
        );
    }

    #[test]
    fn axis_histogram_spread_is_bounded_above_by_peak_count_and_total() {
        // Structural-bound pin: spread <= peak_count <= total, both
        // bounds via the non-negative trough subtraction. Pinned at
        // four shapes (empty, singleton, balanced, strict-skew) so
        // both bounds get a tight witness. Equality with peak_count
        // holds exactly when trough_count == 0 — i.e. on the empty
        // histogram, the sole shape with trough_count == 0.
        let inputs: [&[DiffLineKind]; 4] = [
            &[],
            &[DiffLineKind::Added],
            &[
                DiffLineKind::Added,
                DiffLineKind::Removed,
                DiffLineKind::Context,
            ],
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
        ];
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            assert!(
                hist.spread() <= hist.peak_count(),
                "spread {} must be <= peak_count {} on input of length {}",
                hist.spread(),
                hist.peak_count(),
                input.len(),
            );
            assert!(
                hist.spread() <= hist.total(),
                "spread {} must be <= total {} on input of length {}",
                hist.spread(),
                hist.total(),
                input.len(),
            );
            assert_eq!(
                hist.spread() == hist.peak_count(),
                hist.trough_count() == 0,
                "spread == peak_count iff trough_count == 0 on input of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_spread_after_merge_is_non_monotonic() {
        // The (merge, spread) composition: in deliberate contrast to
        // peak_count's strict monotonicity under merge, spread can
        // either *grow* (when one side carries a heavy tail the
        // other lacks, the merged peak grows faster than the merged
        // trough) or *shrink* (when merging two strict-skew sides
        // restores a uniformly-observed-count merge). The
        // empty-identity law still holds. Pinned with grow,
        // shrink-or-equal, and identity (empty-rhs) shapes so each
        // branch of the non-monotonic behavior gets a tight witness.
        let added_two: AxisHistogram<DiffLineKind> = [DiffLineKind::Added, DiffLineKind::Added]
            .into_iter()
            .collect();
        let added_two_removed_one: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
        ]
        .into_iter()
        .collect();
        let removed_two: AxisHistogram<DiffLineKind> =
            [DiffLineKind::Removed, DiffLineKind::Removed]
                .into_iter()
                .collect();
        let empty_hist: AxisHistogram<DiffLineKind> = AxisHistogram::empty();

        // Grow branch: merging a balanced {Added:2} with a skewed
        // {Added:2, Removed:1} grows the spread strictly past either
        // side. lhs spread = 0 (balanced singleton-support), rhs
        // spread = 1 (Added:2 vs Removed:1), merged = {Added:4,
        // Removed:1} with peak 4, trough 1, spread 3 — strictly
        // greater than each side.
        let grow = added_two.clone().merge(&added_two_removed_one);
        assert_eq!(grow.spread(), 3);
        assert!(grow.spread() > added_two.spread());
        assert!(grow.spread() > added_two_removed_one.spread());

        // Shrink branch: merging two strict-skew supports
        // {Added:2, Removed:1} and {Removed:2, ???} — pick the
        // canonical witness: lhs {Added:2, Removed:1} (spread 1)
        // with rhs {Removed:2, Added:1} (spread 1) merges to
        // {Added:3, Removed:3} with peak 3, trough 3, spread 0 —
        // strictly *below* each side's spread. The non-monotonic
        // shrink branch.
        let added_two_removed_one_b: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Removed,
            DiffLineKind::Removed,
            DiffLineKind::Added,
        ]
        .into_iter()
        .collect();
        let shrink = added_two_removed_one
            .clone()
            .merge(&added_two_removed_one_b);
        assert_eq!(shrink.spread(), 0);
        assert!(shrink.spread() < added_two_removed_one.spread());
        assert!(shrink.spread() < added_two_removed_one_b.spread());

        // Equal-or-bracketed branch: merging two disjoint singleton-
        // support sides produces a balanced merge — spread stays at
        // 0. (Witnesses the identity boundary where spread agrees on
        // both sides and the merge.)
        let two_singletons = added_two.clone().merge(&removed_two);
        assert_eq!(two_singletons.spread(), 0);
        assert_eq!(two_singletons.spread(), added_two.spread());

        // Identity (empty-rhs): merge leaves the spread unchanged.
        let with_empty = added_two_removed_one.clone().merge(&empty_hist);
        assert_eq!(with_empty.spread(), added_two_removed_one.spread());
    }

    // ---- AxisHistogram::unobserved_cells trait-uniform laws ----
    //
    // Three trait-uniform laws reach every [`ClosedAxis`] implementor
    // through [`for_each_closed_axis_implementor`] so the per-axis
    // unobserved_cells projection's contract holds uniformly without
    // per-axis test duplication: empty → axis_cardinality (every cell
    // unobserved, the full gap); singleton → axis_cardinality - 1 on
    // every cell K (exactly the observed cell drops out of the gap);
    // axis-cover → 0 (every cell observed, no gap). Concrete defining-
    // equivalence, partition-law, structural-bound, boundary-equivalence,
    // and merge-monotonicity pins follow below on [`DiffLineKind`].

    fn assert_unobserved_cells_empty_equals_cardinality<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        let hist = AxisHistogram::<A>::empty();
        assert_eq!(
            hist.unobserved_cells(),
            axis_cardinality::<A>(),
            "empty histogram unobserved_cells must equal axis_cardinality on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_unobserved_cells_singleton_is_cardinality_minus_one<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // For every cell of the axis: a histogram built from one
        // observation of that cell has exactly one observed cell — the
        // observed cell drops out of the gap, leaving the gap at
        // `axis_cardinality - 1`. Pinned uniformly across every
        // closed-axis implementor.
        let n = axis_cardinality::<A>();
        for observed in axis_iter::<A>() {
            let hist: AxisHistogram<A> = std::iter::once(observed).collect();
            assert_eq!(
                hist.unobserved_cells(),
                n - 1,
                "singleton unobserved_cells must equal axis_cardinality - 1 \
                 for observed cell {observed:?} on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_unobserved_cells_axis_cover_is_zero<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Observing every cell exactly once produces a uniform
        // axis-cover histogram (every cell observed at least once,
        // support is the full axis); the coverage gap is empty — the
        // dual boundary of the empty-histogram convention. The
        // full-cover histogram has no unobserved cells.
        let hist: AxisHistogram<A> = axis_iter::<A>().collect();
        assert_eq!(
            hist.unobserved_cells(),
            0,
            "axis-cover histogram unobserved_cells must be 0 on axis {}",
            std::any::type_name::<A>(),
        );
    }

    #[test]
    fn axis_histogram_unobserved_cells_empty_equals_cardinality_for_every_closed_axis_implementor()
    {
        macro_rules! check {
            ($ty:ident) => {
                assert_unobserved_cells_empty_equals_cardinality::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_unobserved_cells_singleton_is_cardinality_minus_one_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_unobserved_cells_singleton_is_cardinality_minus_one::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_unobserved_cells_axis_cover_is_zero_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_unobserved_cells_axis_cover_is_zero::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_unobserved_cells_equals_unobserved_iterator_count() {
        // The lift's defining equivalence: unobserved_cells reads the
        // same scalar as the open-coded `unobserved().count()` chain
        // every consumer re-derived inline. Pinned pointwise across the
        // canonical observation-mix shapes (empty, singleton, partial,
        // full-cover, heavy-tail mix) so a future regression in either
        // side surfaces here.
        let inputs: [&[DiffLineKind]; 5] = [
            &[],
            &[DiffLineKind::Added],
            &[DiffLineKind::Added, DiffLineKind::Removed],
            &[
                DiffLineKind::Context,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
        ];
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            assert_eq!(
                hist.unobserved_cells(),
                hist.unobserved().count(),
                "unobserved_cells must equal unobserved().count() on input of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_distinct_cells_plus_unobserved_cells_equals_cardinality() {
        // The (observed, unobserved) cardinality partition: every cell
        // of the closed axis lies in exactly one of the two scalar
        // counts, so their sum reads off the axis size at every
        // histogram. The scalar-level peer to the
        // `nonzero ⊔ unobserved = axis` set-level partition pinned on
        // [`AxisHistogram::unobserved`]. Pinned across the same
        // observation-mix shapes the trait-uniform laws witness on
        // (empty, singleton, partial, full-cover, heavy-tail) so the
        // equality holds at every distinct-cells value in the
        // histogram's range.
        let inputs: [&[DiffLineKind]; 5] = [
            &[],
            &[DiffLineKind::Added],
            &[DiffLineKind::Added, DiffLineKind::Removed],
            &[
                DiffLineKind::Context,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
        ];
        let n = axis_cardinality::<DiffLineKind>();
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            assert_eq!(
                hist.distinct_cells() + hist.unobserved_cells(),
                n,
                "distinct_cells + unobserved_cells must equal axis_cardinality \
                 on input of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_unobserved_cells_equals_cardinality_minus_distinct_cells() {
        // The structural-complement derivation: unobserved_cells reads
        // off the support cardinality through one subtraction from the
        // axis size — pointwise equivalent to the underflow-safe form
        // `axis_cardinality - distinct_cells`. Pinned across the same
        // boundary shapes the partition law witnesses on so the
        // subtraction is exercised at every support-size in the
        // histogram's range.
        let inputs: [&[DiffLineKind]; 4] = [
            &[],
            &[DiffLineKind::Added],
            &[DiffLineKind::Added, DiffLineKind::Removed],
            &[
                DiffLineKind::Context,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
        ];
        let n = axis_cardinality::<DiffLineKind>();
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            assert_eq!(
                hist.unobserved_cells(),
                n - hist.distinct_cells(),
                "unobserved_cells must equal axis_cardinality - distinct_cells \
                 on input of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_unobserved_cells_is_bounded_above_by_axis_cardinality() {
        // Structural-bound pin: unobserved_cells ∈ [0,
        // axis_cardinality::<A>()]. Tight at both ends — the empty
        // histogram reads N (every cell unobserved, full gap), the
        // axis-cover histogram reads 0 (no gap). Pinned over four
        // observation shapes (empty, singleton, axis-cover, heavy-tail
        // mix) so both bounds get a tight witness.
        let inputs: [&[DiffLineKind]; 4] = [
            &[],
            &[DiffLineKind::Removed],
            &[
                DiffLineKind::Context,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
        ];
        let n = axis_cardinality::<DiffLineKind>();
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            let gap = hist.unobserved_cells();
            assert!(
                gap <= n,
                "unobserved_cells {gap} must be <= axis_cardinality {n} \
                 on input of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_unobserved_cells_full_cover_iff_distinct_equals_cardinality() {
        // The full-cover predicate at the scalar surface: every cell
        // observed iff the coverage gap is empty. Pinned at both sides
        // of the equivalence — full-cover witnesses (gap == 0,
        // distinct == cardinality) and proper-subset witnesses (gap > 0,
        // distinct < cardinality) — so the predicate holds at every
        // branch.
        let n = axis_cardinality::<DiffLineKind>();
        // Full-cover witness: every cell observed.
        let full_cover: AxisHistogram<DiffLineKind> = axis_iter::<DiffLineKind>().collect();
        assert_eq!(full_cover.unobserved_cells(), 0);
        assert_eq!(full_cover.distinct_cells(), n);
        assert_eq!(
            full_cover.unobserved_cells() == 0,
            full_cover.distinct_cells() == n,
        );
        // Proper-subset witness: only some cells observed.
        let partial: AxisHistogram<DiffLineKind> = std::iter::once(DiffLineKind::Added).collect();
        assert!(partial.unobserved_cells() > 0);
        assert!(partial.distinct_cells() < n);
        assert_eq!(
            partial.unobserved_cells() == 0,
            partial.distinct_cells() == n,
        );
    }

    #[test]
    fn axis_histogram_unobserved_cells_iff_is_empty_equals_cardinality() {
        // Boundary pin: unobserved_cells == axis_cardinality iff
        // is_empty is true. Equivalence holds across both directions —
        // an empty history reads N (every cell unobserved), a non-empty
        // history reads at most N - 1. Peer to the same boundary
        // equivalence distinct_cells / dominant_cell carry on the dual
        // side of the partition.
        let n = axis_cardinality::<DiffLineKind>();
        let empty: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
        assert!(empty.is_empty());
        assert_eq!(empty.unobserved_cells(), n);

        let singleton: AxisHistogram<DiffLineKind> =
            std::iter::once(DiffLineKind::Removed).collect();
        assert!(!singleton.is_empty());
        assert!(singleton.unobserved_cells() <= n - 1);
    }

    #[test]
    fn axis_histogram_unobserved_cells_after_merge_is_monotone_decreasing() {
        // The (merge, unobserved_cells) composition: the coverage gap
        // of a merged histogram is the *intersection* of the two sides'
        // gaps (a cell is unobserved in the merge iff unobserved in
        // both sides), so the merged gap size is at most each side's.
        // Pinned with disjoint-support, overlapping-support, and
        // identity (empty-rhs) shapes so the merge monotone-decreasing
        // law gets a tight witness at each boundary.
        //
        // `DiffLineKind::ALL` declaration order is
        // `[Removed, Added, Context]` (axis_cardinality = 3).
        let lhs: AxisHistogram<DiffLineKind> = [DiffLineKind::Removed, DiffLineKind::Added]
            .into_iter()
            .collect();
        // lhs: support {Removed, Added}; gap = 1 ({Context}).
        let rhs: AxisHistogram<DiffLineKind> = [DiffLineKind::Added, DiffLineKind::Context]
            .into_iter()
            .collect();
        // rhs: support {Added, Context}; gap = 1 ({Removed}).
        let empty_hist: AxisHistogram<DiffLineKind> = AxisHistogram::empty();

        // Overlapping-support: the merge covers every cell, so the gap
        // collapses to 0 — strictly below each side's gap.
        let merged = lhs.clone().merge(&rhs);
        assert_eq!(merged.unobserved_cells(), 0);
        assert!(merged.unobserved_cells() <= lhs.unobserved_cells());
        assert!(merged.unobserved_cells() <= rhs.unobserved_cells());

        // Disjoint singleton supports: the gap shrinks from
        // axis_cardinality - 1 = 2 on each side to 1 on the merge.
        let solo_added: AxisHistogram<DiffLineKind> =
            std::iter::once(DiffLineKind::Added).collect();
        let solo_context: AxisHistogram<DiffLineKind> =
            std::iter::once(DiffLineKind::Context).collect();
        let disjoint = solo_added.clone().merge(&solo_context);
        assert_eq!(disjoint.unobserved_cells(), 1);
        assert!(disjoint.unobserved_cells() <= solo_added.unobserved_cells());
        assert!(disjoint.unobserved_cells() <= solo_context.unobserved_cells());

        // Identity (empty-rhs): merge leaves the gap unchanged.
        let with_empty = lhs.clone().merge(&empty_hist);
        assert_eq!(with_empty.unobserved_cells(), lhs.unobserved_cells());
    }

    // ---- AxisHistogram::is_full_cover trait-uniform laws ----
    //
    // Three trait-uniform laws reach every [`ClosedAxis`] implementor
    // through [`for_each_closed_axis_implementor`] so the predicate's
    // contract holds uniformly without per-axis test duplication:
    // axis-cover → always true (observing every cell once fills the
    // gap); empty → false on every cardinality >= 1 axis (the full gap
    // is present); singleton → true iff cardinality == 1 (the single
    // cell is the entire axis). Concrete cross-equivalence pins, the
    // boolean monotone-OR merge law, and the `(is_empty,
    // is_full_cover)` partition follow below on [`DiffLineKind`].

    fn assert_is_full_cover_on_axis_cover<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Observing every cell exactly once produces a uniform
        // axis-cover histogram (every cell observed at least once);
        // the predicate reads `true` at every implementor. The "full
        // cover" boundary witness.
        let hist: AxisHistogram<A> = axis_iter::<A>().collect();
        assert!(
            hist.is_full_cover(),
            "axis-cover histogram must read is_full_cover on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_is_full_cover_empty_iff_axis_is_empty<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The empty histogram has the full coverage gap, so the
        // predicate fails on every non-zero-cardinality axis (every
        // closed-axis implementor today carries cardinality >= 2).
        // The degenerate zero-cardinality axis would read `true`
        // vacuously, so the law is stated as an equivalence with
        // `axis_cardinality::<A>() == 0` — uniform across the
        // implementor set without case-splitting on the cardinality.
        let hist = AxisHistogram::<A>::empty();
        assert_eq!(
            hist.is_full_cover(),
            axis_cardinality::<A>() == 0,
            "empty histogram is_full_cover must equal (axis_cardinality == 0) \
             on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_is_full_cover_singleton_iff_cardinality_is_one<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // For every cell of the axis: a histogram built from one
        // observation of that cell has exactly one observed cell.
        // The predicate reads `true` iff that one observed cell is
        // the entire axis — i.e. iff `axis_cardinality::<A>() == 1`.
        // On axes with cardinality >= 2 (every implementor today),
        // the singleton leaves at least one cell in the gap, so the
        // predicate fails.
        let n = axis_cardinality::<A>();
        for observed in axis_iter::<A>() {
            let hist: AxisHistogram<A> = std::iter::once(observed).collect();
            assert_eq!(
                hist.is_full_cover(),
                n == 1,
                "singleton is_full_cover must equal (axis_cardinality == 1) \
                 for observed cell {observed:?} on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    #[test]
    fn axis_histogram_is_full_cover_on_axis_cover_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_is_full_cover_on_axis_cover::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_is_full_cover_empty_iff_axis_is_empty_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_is_full_cover_empty_iff_axis_is_empty::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_is_full_cover_singleton_iff_cardinality_is_one_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_is_full_cover_singleton_iff_cardinality_is_one::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_is_full_cover_equals_unobserved_cells_zero() {
        // The defining equivalence: `is_full_cover` reads the same
        // boolean as the open-coded `unobserved_cells() == 0` form
        // every consumer re-derived inline. Pinned pointwise across
        // the canonical observation-mix shapes (empty, singleton,
        // partial, full-cover, heavy-tail mix) so a future regression
        // in either side surfaces here.
        let inputs: [&[DiffLineKind]; 5] = [
            &[],
            &[DiffLineKind::Added],
            &[DiffLineKind::Added, DiffLineKind::Removed],
            &[
                DiffLineKind::Context,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
        ];
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            assert_eq!(
                hist.is_full_cover(),
                hist.unobserved_cells() == 0,
                "is_full_cover must equal (unobserved_cells == 0) \
                 on input of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_is_full_cover_equals_distinct_equals_cardinality() {
        // The dual-side surfacing of the same boolean across the
        // (observed, unobserved) partition: `is_full_cover` reads the
        // same boolean as the `distinct_cells == axis_cardinality`
        // form on the observed-cells side, pointwise equal to the
        // `unobserved_cells == 0` form on the unobserved-cells side.
        // Pinned across the same observation-mix shapes so both
        // partition sides surface the predicate at every distinct-
        // cells value in the histogram's range.
        let inputs: [&[DiffLineKind]; 5] = [
            &[],
            &[DiffLineKind::Added],
            &[DiffLineKind::Added, DiffLineKind::Removed],
            &[
                DiffLineKind::Context,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
        ];
        let n = axis_cardinality::<DiffLineKind>();
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            assert_eq!(
                hist.is_full_cover(),
                hist.distinct_cells() == n,
                "is_full_cover must equal (distinct_cells == axis_cardinality) \
                 on input of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_is_full_cover_equals_unobserved_iterator_is_empty() {
        // The iterator-emptiness equivalence: `is_full_cover` reads the
        // same boolean as the `unobserved().next().is_none()` form
        // without the iterator allocation. Pinned across the canonical
        // observation-mix shapes so the predicate-as-emptiness form
        // is exercised at every coverage-gap state in the histogram's
        // range.
        let inputs: [&[DiffLineKind]; 4] = [
            &[],
            &[DiffLineKind::Added],
            &[DiffLineKind::Added, DiffLineKind::Removed],
            &[
                DiffLineKind::Context,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
        ];
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            assert_eq!(
                hist.is_full_cover(),
                hist.unobserved().next().is_none(),
                "is_full_cover must equal unobserved().next().is_none() \
                 on input of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_is_empty_and_is_full_cover_are_disjoint_on_nonempty_axis() {
        // The `(is_empty, is_full_cover)` boolean partition closes the
        // histogram's coverage-state surface. On every closed-axis
        // implementor today (every axis carries cardinality >= 2), the
        // two predicates are mutually exclusive: `is_empty` fires
        // exactly on the all-zero histogram, `is_full_cover` fires
        // exactly when every cell carries >= 1, and the two cases
        // disagree on every cell. Pinned on `DiffLineKind`
        // (cardinality 3) with both witnesses tight: empty reads
        // `(true, false)`, axis-cover reads `(false, true)`, and the
        // partial-support shape reads `(false, false)` (neither
        // boundary holds in the middle of the coverage state space).
        let empty: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
        assert!(empty.is_empty());
        assert!(!empty.is_full_cover());

        let full_cover: AxisHistogram<DiffLineKind> = axis_iter::<DiffLineKind>().collect();
        assert!(!full_cover.is_empty());
        assert!(full_cover.is_full_cover());

        let partial: AxisHistogram<DiffLineKind> = std::iter::once(DiffLineKind::Added).collect();
        assert!(!partial.is_empty());
        assert!(!partial.is_full_cover());
    }

    #[test]
    fn axis_histogram_is_full_cover_after_merge_is_boolean_monotone() {
        // The (merge, is_full_cover) composition: merging cannot
        // *un*-cover a cell (every cell observed in either side is
        // observed in the merge, so the merged gap is the intersection
        // of the two sides' gaps), so if either side reads full cover
        // so does the merge — the boolean monotone-OR law. The peer
        // to the monotone-non-increase law on
        // [`AxisHistogram::unobserved_cells`] / the monotone-coverage
        // law on [`AxisHistogram::unobserved`]. Pinned with
        // disjoint-support, overlapping-support, and identity
        // (empty-rhs) shapes so the boolean monotonicity gets a
        // tight witness at each boundary.
        //
        // `DiffLineKind::ALL` declaration order is
        // `[Removed, Added, Context]` (axis_cardinality = 3).
        let lhs: AxisHistogram<DiffLineKind> = [DiffLineKind::Removed, DiffLineKind::Added]
            .into_iter()
            .collect();
        // lhs: support {Removed, Added}; is_full_cover = false.
        let rhs: AxisHistogram<DiffLineKind> = [DiffLineKind::Added, DiffLineKind::Context]
            .into_iter()
            .collect();
        // rhs: support {Added, Context}; is_full_cover = false.

        // Overlapping-support: the merge covers every cell, so
        // is_full_cover transitions false → true. Boolean monotone
        // holds (true >= false || false on the OR side).
        let merged = lhs.clone().merge(&rhs);
        assert!(merged.is_full_cover());
        assert!(merged.is_full_cover() >= (lhs.is_full_cover() || rhs.is_full_cover()));

        // Disjoint singleton supports: the merge has two observed
        // cells out of three — is_full_cover stays false on every
        // surface. Boolean monotone holds vacuously (false >= false
        // || false).
        let solo_added: AxisHistogram<DiffLineKind> =
            std::iter::once(DiffLineKind::Added).collect();
        let solo_context: AxisHistogram<DiffLineKind> =
            std::iter::once(DiffLineKind::Context).collect();
        let disjoint = solo_added.clone().merge(&solo_context);
        assert!(!disjoint.is_full_cover());
        assert!(
            disjoint.is_full_cover()
                >= (solo_added.is_full_cover() || solo_context.is_full_cover())
        );

        // Identity (empty-rhs): merge leaves is_full_cover unchanged.
        // Boolean monotone holds with equality on every full-cover
        // input side and on every non-full-cover input side.
        let full_cover: AxisHistogram<DiffLineKind> = axis_iter::<DiffLineKind>().collect();
        let empty_hist: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
        let full_cover_with_empty = full_cover.clone().merge(&empty_hist);
        assert!(full_cover_with_empty.is_full_cover());
        assert_eq!(
            full_cover_with_empty.is_full_cover(),
            full_cover.is_full_cover()
        );

        let lhs_with_empty = lhs.clone().merge(&empty_hist);
        assert_eq!(lhs_with_empty.is_full_cover(), lhs.is_full_cover());
    }

    // ---- AxisHistogram::is_uniform_count trait-uniform laws ----
    //
    // Three trait-uniform laws reach every [`ClosedAxis`] implementor
    // through [`for_each_closed_axis_implementor`] so the predicate's
    // contract holds uniformly without per-axis test duplication:
    // empty → true (vacuous uniformity — no observed cells to
    // disagree); singleton → true on every cell (one observed cell is
    // trivially balanced, peak = trough = 1); uniform axis-cover →
    // true on every implementor (every cell at count 1, peak = trough
    // = 1). Concrete defining-equivalence pins on the three forms
    // (spread == 0, peak == trough, dominant == recessive), the
    // strict-skew witness, the merge non-monotonicity pin, and the
    // (is_empty, is_full_cover, is_uniform_count) boolean-triple
    // boundary witness follow below on [`DiffLineKind`].

    fn assert_is_uniform_count_empty_is_true<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The empty histogram has no observed cells, so the universal
        // "every observed cell carries the same count" reads `true`
        // vacuously. Matches `spread() == 0` on the empty case
        // (`peak = trough = 0`) and `dominant_cell() ==
        // recessive_cell()` (`None == None`). The vacuous-uniformity
        // boundary witness.
        let hist = AxisHistogram::<A>::empty();
        assert!(
            hist.is_uniform_count(),
            "empty histogram is_uniform_count must be true on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_is_uniform_count_singleton_is_true<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // For every cell of the axis: a histogram built from one
        // observation of that cell has one observed cell at count 1
        // (peak = trough = 1), so the predicate fires uniformly. The
        // singleton-support balanced-distribution witness.
        for observed in axis_iter::<A>() {
            let hist: AxisHistogram<A> = std::iter::once(observed).collect();
            assert!(
                hist.is_uniform_count(),
                "singleton is_uniform_count must be true for observed cell \
                 {observed:?} on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_is_uniform_count_axis_cover_is_true<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Observing every cell exactly once produces a uniform
        // axis-cover histogram (every cell at 1, peak = trough = 1) —
        // the structural "every observed kind fired the same number
        // of times" boundary at the maximum-coverage shape. The
        // simultaneous (is_full_cover, is_uniform_count) = (true,
        // true) witness on every implementor.
        let hist: AxisHistogram<A> = axis_iter::<A>().collect();
        assert!(
            hist.is_uniform_count(),
            "axis-cover histogram is_uniform_count must be true on axis {}",
            std::any::type_name::<A>(),
        );
    }

    #[test]
    fn axis_histogram_is_uniform_count_empty_is_true_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_is_uniform_count_empty_is_true::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_is_uniform_count_singleton_is_true_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_is_uniform_count_singleton_is_true::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_is_uniform_count_axis_cover_is_true_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_is_uniform_count_axis_cover_is_true::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_is_uniform_count_equals_spread_is_zero() {
        // The defining equivalence: `is_uniform_count` reads the same
        // boolean as the open-coded `spread() == 0` form every consumer
        // re-derived inline. Pinned pointwise across the canonical
        // observation-mix shapes (empty, singleton, uniform-tied,
        // strict-skew, heavy-tail) so a future regression in either
        // side surfaces here.
        let inputs: [&[DiffLineKind]; 5] = [
            &[],
            &[DiffLineKind::Added],
            &[DiffLineKind::Added, DiffLineKind::Removed],
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
        ];
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            assert_eq!(
                hist.is_uniform_count(),
                hist.spread() == 0,
                "is_uniform_count must equal (spread == 0) on input of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_is_uniform_count_equals_peak_equals_trough() {
        // The structural form on the underlying scalar pair:
        // `is_uniform_count` reads the same boolean as the
        // `peak_count() == trough_count()` defining equality. Pinned
        // across the canonical observation-mix shapes so the equality
        // holds at every distinct `(peak, trough)` pair the histogram
        // surface ranges over.
        let inputs: [&[DiffLineKind]; 5] = [
            &[],
            &[DiffLineKind::Added],
            &[
                DiffLineKind::Removed,
                DiffLineKind::Added,
                DiffLineKind::Context,
            ],
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
        ];
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            assert_eq!(
                hist.is_uniform_count(),
                hist.peak_count() == hist.trough_count(),
                "is_uniform_count must equal (peak_count == trough_count) \
                 on input of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_is_uniform_count_equals_dominant_equals_recessive() {
        // The modal-pair form: `is_uniform_count` reads the same
        // boolean as `dominant_cell() == recessive_cell()` across
        // both branches — the empty histogram (both reduce to `None
        // == None`, both `true`), the singleton-support histogram
        // (both reduce to `Some(observed) == Some(observed)`, both
        // `true`), the uniform axis-cover histogram (both reduce to
        // `Some(first cell) == Some(first cell)`, both `true`), and
        // every strict-skew histogram (both reduce to `false`).
        // Pinned across the same observation-mix shapes so the modal-
        // pair / boolean equivalence is exercised at every branch.
        let inputs: [&[DiffLineKind]; 5] = [
            &[],
            &[DiffLineKind::Added],
            &[
                DiffLineKind::Removed,
                DiffLineKind::Added,
                DiffLineKind::Context,
            ],
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
            &[
                DiffLineKind::Removed,
                DiffLineKind::Removed,
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Context,
            ],
        ];
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            assert_eq!(
                hist.is_uniform_count(),
                hist.dominant_cell() == hist.recessive_cell(),
                "is_uniform_count must equal (dominant_cell == recessive_cell) \
                 on input of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_is_uniform_count_witnesses_strict_skew_is_false() {
        // The complementary witness: strict-skew shapes (heavy-tail,
        // binary-skew, multi-level-skew) read `false` — peak strictly
        // exceeds trough on the observed support, so the predicate
        // fails. Pinned at three distinct skew shapes so the `false`
        // branch is exercised at every distinct skew amount the
        // histogram's spread can carry on `DiffLineKind` (cardinality
        // 3 — spread can range from 0 to total - 1 in principle).
        //
        // Binary-skew: two distinct cells at counts (2, 1) → spread 1.
        let binary_skew: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
        ]
        .into_iter()
        .collect();
        assert!(!binary_skew.is_uniform_count());
        assert_eq!(binary_skew.spread(), 1);

        // Heavy-tail: three distinct cells at counts (3, 1, 1) →
        // spread 2 (peak Added at 3, trough Removed/Context at 1).
        // The middle of the spread range — the recessive cells are
        // tied at the floor, the peak rises strictly above.
        let heavy_tail: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ]
        .into_iter()
        .collect();
        assert!(!heavy_tail.is_uniform_count());
        assert_eq!(heavy_tail.spread(), 2);

        // Strict-three-level skew: three distinct cells at counts
        // (4, 2, 1) — every observed cell carries a distinct count,
        // spread 3. The maximum-skew shape on a fully-supported
        // DiffLineKind histogram.
        let three_level: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ]
        .into_iter()
        .collect();
        assert!(!three_level.is_uniform_count());
        assert_eq!(three_level.spread(), 3);
    }

    #[test]
    fn axis_histogram_is_empty_is_full_cover_is_uniform_count_triple_classifies_canonical_shapes() {
        // The `(is_empty, is_full_cover, is_uniform_count)` boolean
        // triple closes the histogram's coverage-and-shape surface in
        // one projection. On `DiffLineKind` (cardinality 3, every
        // implementor today carries cardinality >= 2, so the
        // `(true, true, *)` corner is structurally empty), the four
        // canonical shapes pin distinct triples:
        //   - empty            → (true,  false, true ) — nothing
        //                        observed, vacuous uniformity.
        //   - singleton        → (false, false, true ) — one cell
        //                        observed, trivially balanced.
        //   - partial-skew     → (false, false, false) — two cells
        //                        observed, distinct counts.
        //   - axis-cover       → (false, true,  true ) — every cell
        //                        observed at one, perfectly uniform.
        //   - partial-uniform  → (false, false, true ) — two cells
        //                        observed at the same count.
        //   - full-cover-skew  → (false, true,  false) — every cell
        //                        observed, distinct counts.
        // Six of the eight `(bool, bool, bool)` corners get a witness
        // (the two `(true, *, *)` corners with non-vacuous coverage
        // are structurally impossible on cardinality >= 1 axes).
        let empty: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
        assert_eq!(
            (
                empty.is_empty(),
                empty.is_full_cover(),
                empty.is_uniform_count(),
            ),
            (true, false, true),
        );

        let singleton: AxisHistogram<DiffLineKind> = std::iter::once(DiffLineKind::Added).collect();
        assert_eq!(
            (
                singleton.is_empty(),
                singleton.is_full_cover(),
                singleton.is_uniform_count(),
            ),
            (false, false, true),
        );

        let partial_skew: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
        ]
        .into_iter()
        .collect();
        assert_eq!(
            (
                partial_skew.is_empty(),
                partial_skew.is_full_cover(),
                partial_skew.is_uniform_count(),
            ),
            (false, false, false),
        );

        let axis_cover: AxisHistogram<DiffLineKind> = axis_iter::<DiffLineKind>().collect();
        assert_eq!(
            (
                axis_cover.is_empty(),
                axis_cover.is_full_cover(),
                axis_cover.is_uniform_count(),
            ),
            (false, true, true),
        );

        let partial_uniform: AxisHistogram<DiffLineKind> =
            [DiffLineKind::Added, DiffLineKind::Removed]
                .into_iter()
                .collect();
        assert_eq!(
            (
                partial_uniform.is_empty(),
                partial_uniform.is_full_cover(),
                partial_uniform.is_uniform_count(),
            ),
            (false, false, true),
        );

        let full_cover_skew: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ]
        .into_iter()
        .collect();
        assert_eq!(
            (
                full_cover_skew.is_empty(),
                full_cover_skew.is_full_cover(),
                full_cover_skew.is_uniform_count(),
            ),
            (false, true, false),
        );
    }

    #[test]
    fn axis_histogram_is_uniform_count_after_merge_is_non_monotone() {
        // The merge behavior on `is_uniform_count` is *non-monotonic*
        // (peer to the non-monotonic behavior on
        // [`AxisHistogram::trough_count`] and
        // [`AxisHistogram::spread`]): merging two uniform-count
        // histograms can produce a non-uniform merge (when the
        // supports differ — the merged cells gain count, the
        // unmerged cells keep one side's count), and merging two
        // non-uniform histograms can produce a uniform merge (when
        // the heavy and light tails cancel pointwise). Pinned with
        // three witnesses spanning the merge surface, plus the
        // empty-identity law.
        //
        // `DiffLineKind::ALL` declaration order is
        // `[Removed, Added, Context]` (axis_cardinality = 3).

        // Witness 1: uniform-singleton ⊕ uniform-singleton on disjoint
        // supports → uniform binary support (both at count 1).
        // Both sides uniform (singleton), merge stays uniform.
        let solo_added: AxisHistogram<DiffLineKind> =
            std::iter::once(DiffLineKind::Added).collect();
        let solo_removed: AxisHistogram<DiffLineKind> =
            std::iter::once(DiffLineKind::Removed).collect();
        let merged_uniform = solo_added.clone().merge(&solo_removed);
        assert!(merged_uniform.is_uniform_count());
        assert!(solo_added.is_uniform_count() && solo_removed.is_uniform_count());

        // Witness 2: uniform-pair (Added: 2) ⊕ uniform-singleton
        // (Removed: 1) → counts (Removed: 1, Added: 2) — non-uniform
        // merge from two uniform sides. Demonstrates uniform-but-
        // unequal-counts breaks under merge with disjoint single
        // support.
        let added_twice: AxisHistogram<DiffLineKind> = [DiffLineKind::Added, DiffLineKind::Added]
            .into_iter()
            .collect();
        assert!(added_twice.is_uniform_count());
        let mixed = added_twice.clone().merge(&solo_removed);
        assert!(!mixed.is_uniform_count());

        // Witness 3: non-uniform ⊕ non-uniform → uniform. lhs has
        // (Added: 2, Removed: 1), rhs has (Added: 1, Removed: 2);
        // both skewed, but the heavy-tail cancels pointwise so the
        // merge is (Added: 3, Removed: 3) — uniform binary support.
        let lhs_skew: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
        ]
        .into_iter()
        .collect();
        let rhs_skew: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Removed,
        ]
        .into_iter()
        .collect();
        assert!(!lhs_skew.is_uniform_count());
        assert!(!rhs_skew.is_uniform_count());
        let cancelled = lhs_skew.clone().merge(&rhs_skew);
        assert!(cancelled.is_uniform_count());

        // Empty-identity law: merging with the empty histogram leaves
        // `is_uniform_count` unchanged on every input. Pinned with
        // both a uniform-side input and a non-uniform-side input.
        let empty_hist: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
        let uniform_with_empty = added_twice.clone().merge(&empty_hist);
        assert_eq!(
            uniform_with_empty.is_uniform_count(),
            added_twice.is_uniform_count(),
        );
        let skew_with_empty = lhs_skew.clone().merge(&empty_hist);
        assert_eq!(
            skew_with_empty.is_uniform_count(),
            lhs_skew.is_uniform_count(),
        );
    }

    // -- has_singular_support: trait-uniform laws ------------------
    //
    // Three trait-uniform helpers reach every `ClosedAxis`
    // implementor via `for_each_closed_axis_implementor!`. The empty,
    // singleton, and axis-cover branches of the support-cardinality
    // boundary triple are pinned at the trait level so the predicate's
    // contract holds uniformly across the implementor set without per-
    // axis test duplication. Concrete pins on the defining
    // equivalence, the monoid-collapse equivalence, the
    // (is_empty, has_singular_support, is_full_cover) pairwise-
    // disjoint partition, the `has_singular_support ⇒ is_uniform_count`
    // one-way implication, and the merge non-monotonicity follow
    // below on [`DiffLineKind`].

    fn assert_has_singular_support_empty_is_false<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The empty histogram has support cardinality `0`, not `1`,
        // so the singular-support predicate reads `false`. The
        // [`AxisHistogram::is_empty`] boundary carries the zero-
        // support case; `has_singular_support` reads the
        // one-observed-cell case strictly. The zero-support boundary
        // witness on the (is_empty, has_singular_support,
        // is_full_cover) pairwise-disjoint partition.
        let hist = AxisHistogram::<A>::empty();
        assert!(
            !hist.has_singular_support(),
            "empty histogram has_singular_support must be false on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_has_singular_support_singleton_is_true<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // For every cell of the axis: a histogram built from one
        // observation of that cell has exactly one observed cell, so
        // the singular-support predicate reads `true`. The minimal-
        // nonempty boundary witness — every singleton observation
        // lands exactly on the support-cardinality-1 corner of the
        // (is_empty, has_singular_support, is_full_cover) partition.
        for observed in axis_iter::<A>() {
            let hist: AxisHistogram<A> = std::iter::once(observed).collect();
            assert!(
                hist.has_singular_support(),
                "singleton has_singular_support must be true for observed cell \
                 {observed:?} on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_has_singular_support_axis_cover_iff_cardinality_is_one<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Observing every cell exactly once raises the support
        // cardinality to `axis_cardinality::<A>()`, so the singular-
        // support predicate reads `true` iff the axis carries
        // exactly one cell. Stated as an equivalence so the law is
        // uniform across the implementor set (every closed-axis
        // primitive in the typescape today carries
        // `axis_cardinality >= 2`, so axis-cover reads `false`
        // uniformly) without case-splitting on cardinality at the
        // test site. The dual-boundary witness on the (is_empty,
        // has_singular_support, is_full_cover) partition: axis-cover
        // sits at the is_full_cover corner on every cardinality-≥ 2
        // implementor, disjoint from has_singular_support.
        let hist: AxisHistogram<A> = axis_iter::<A>().collect();
        assert_eq!(
            hist.has_singular_support(),
            axis_cardinality::<A>() == 1,
            "axis-cover has_singular_support must equal (axis_cardinality == 1) \
             on axis {}",
            std::any::type_name::<A>(),
        );
    }

    #[test]
    fn axis_histogram_has_singular_support_empty_is_false_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_has_singular_support_empty_is_false::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_has_singular_support_singleton_is_true_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_has_singular_support_singleton_is_true::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_has_singular_support_axis_cover_iff_cardinality_is_one_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_has_singular_support_axis_cover_iff_cardinality_is_one::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_has_singular_support_equals_distinct_cells_is_one() {
        // The defining equivalence: `has_singular_support` reads the
        // same boolean as the open-coded `distinct_cells() == 1` form
        // every consumer would otherwise re-derive inline. Pinned
        // pointwise across the canonical observation-mix shapes
        // (empty, singleton, singleton-multi-observation, partial-
        // skew, partial-uniform, axis-cover) so a future regression
        // in either side surfaces here.
        let inputs: [&[DiffLineKind]; 6] = [
            &[],
            &[DiffLineKind::Added],
            &[DiffLineKind::Added, DiffLineKind::Added],
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
            &[DiffLineKind::Added, DiffLineKind::Removed],
            &[
                DiffLineKind::Added,
                DiffLineKind::Removed,
                DiffLineKind::Context,
            ],
        ];
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            assert_eq!(
                hist.has_singular_support(),
                hist.distinct_cells() == 1,
                "has_singular_support must equal (distinct_cells == 1) \
                 on input of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_has_singular_support_equals_peak_equals_total_on_nonempty() {
        // The monoid-collapse equivalence: a single observed cell
        // carries every observation, so its peak count equals the
        // total — `peak_count() == total() && !is_empty()` reads the
        // same boolean as `has_singular_support()`. The non-empty
        // side excludes the `(0, 0)` degenerate equality the empty
        // histogram carries (where peak == total == 0 trivially but
        // support is empty, not singular). Pinned across the same
        // observation-mix shapes so the monoid-collapse equivalence
        // is exercised at every branch.
        let inputs: [&[DiffLineKind]; 6] = [
            &[],
            &[DiffLineKind::Added],
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Added,
            ],
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
            &[DiffLineKind::Added, DiffLineKind::Removed],
            &[
                DiffLineKind::Added,
                DiffLineKind::Removed,
                DiffLineKind::Context,
            ],
        ];
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            assert_eq!(
                hist.has_singular_support(),
                hist.peak_count() == hist.total() && !hist.is_empty(),
                "has_singular_support must equal (peak_count == total && !is_empty) \
                 on input of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_support_cardinality_boundary_triple_is_pairwise_disjoint() {
        // The `(is_empty, has_singular_support, is_full_cover)`
        // boolean triple closes the histogram's support-cardinality
        // boundary surface in one projection: support cardinality 0
        // (`is_empty`), support cardinality 1 (`has_singular_support`),
        // and support cardinality `axis_cardinality::<A>()`
        // (`is_full_cover`) — three disjoint corners on the support
        // sigma-algebra. On every cardinality-≥ 2 implementor (the
        // entire implementor set today), at most one of the three
        // reads `true` on any histogram. Pinned at four typed
        // branches:
        //   - empty            → (true,  false, false) — the support-0
        //                        corner.
        //   - singleton        → (false, true,  false) — the support-1
        //                        corner.
        //   - axis-cover       → (false, false, true ) — the support-N
        //                        corner.
        //   - partial-multi    → (false, false, false) — none of the
        //                        boundary corners (support strictly
        //                        between 1 and N).
        // The four boundary-corner shapes pin the triple at every
        // distinct support-cardinality boundary reachable on
        // `DiffLineKind` (cardinality 3); the partial-multi shape
        // sits in the (false, false, false) interior.
        let empty: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
        assert_eq!(
            (
                empty.is_empty(),
                empty.has_singular_support(),
                empty.is_full_cover(),
            ),
            (true, false, false),
        );

        let singleton: AxisHistogram<DiffLineKind> = std::iter::once(DiffLineKind::Added).collect();
        assert_eq!(
            (
                singleton.is_empty(),
                singleton.has_singular_support(),
                singleton.is_full_cover(),
            ),
            (false, true, false),
        );

        let axis_cover: AxisHistogram<DiffLineKind> = axis_iter::<DiffLineKind>().collect();
        assert_eq!(
            (
                axis_cover.is_empty(),
                axis_cover.has_singular_support(),
                axis_cover.is_full_cover(),
            ),
            (false, false, true),
        );

        let partial_multi: AxisHistogram<DiffLineKind> =
            [DiffLineKind::Added, DiffLineKind::Removed]
                .into_iter()
                .collect();
        assert_eq!(
            (
                partial_multi.is_empty(),
                partial_multi.has_singular_support(),
                partial_multi.is_full_cover(),
            ),
            (false, false, false),
        );

        // Pairwise-disjoint check: on every shape above, at most one
        // of the three predicates reads `true`. The boolean
        // arithmetic encodes pairwise disjointness as
        // `a & b == false ∧ a & c == false ∧ b & c == false`.
        for hist in [&empty, &singleton, &axis_cover, &partial_multi] {
            let e = hist.is_empty();
            let s = hist.has_singular_support();
            let f = hist.is_full_cover();
            assert!(
                !(e && s),
                "is_empty and has_singular_support must be disjoint",
            );
            assert!(!(e && f), "is_empty and is_full_cover must be disjoint",);
            assert!(
                !(s && f),
                "has_singular_support and is_full_cover must be disjoint \
                 on cardinality-≥ 2 implementors",
            );
        }
    }

    #[test]
    fn axis_histogram_has_singular_support_implies_is_uniform_count() {
        // The one-way implication: a single observed cell is
        // vacuously uniform-counted (only one count in the support
        // to compare to itself), so `has_singular_support ⇒
        // is_uniform_count`. The converse fails on every uniform-
        // multi-cell shape (the empty histogram reads
        // `is_uniform_count = true` but `has_singular_support =
        // false`; uniform axis-cover reads
        // `is_uniform_count = true` but
        // `has_singular_support = false` on cardinality-≥ 2 axes;
        // every k-cell-observed-k-times-each-once shape reads
        // `is_uniform_count = true` but
        // `has_singular_support = false`), so the implication is
        // strictly one-way. Pinned at three singular-support
        // witnesses (singleton, multi-observation-single-cell, and
        // heavy-singleton — all read `has_singular_support = true`
        // and `is_uniform_count = true`) and three counterexamples
        // to the converse (empty, uniform-pair, uniform-axis-cover —
        // all read `is_uniform_count = true` but
        // `has_singular_support = false`).

        // Singular-support side: implication holds.
        let solo: AxisHistogram<DiffLineKind> = std::iter::once(DiffLineKind::Added).collect();
        assert!(solo.has_singular_support());
        assert!(solo.is_uniform_count());

        let many_solo: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Added,
        ]
        .into_iter()
        .collect();
        assert!(many_solo.has_singular_support());
        assert!(many_solo.is_uniform_count());

        let heavy_solo: AxisHistogram<DiffLineKind> =
            std::iter::repeat_n(DiffLineKind::Removed, 7).collect();
        assert!(heavy_solo.has_singular_support());
        assert!(heavy_solo.is_uniform_count());

        // Converse-fails side: `is_uniform_count` holds but
        // `has_singular_support` does not on every uniform-multi-cell
        // shape.
        let empty: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
        assert!(empty.is_uniform_count());
        assert!(!empty.has_singular_support());

        let uniform_pair: AxisHistogram<DiffLineKind> =
            [DiffLineKind::Added, DiffLineKind::Removed]
                .into_iter()
                .collect();
        assert!(uniform_pair.is_uniform_count());
        assert!(!uniform_pair.has_singular_support());

        let axis_cover: AxisHistogram<DiffLineKind> = axis_iter::<DiffLineKind>().collect();
        assert!(axis_cover.is_uniform_count());
        assert!(!axis_cover.has_singular_support());
    }

    #[test]
    fn axis_histogram_has_singular_support_after_merge_is_non_monotone() {
        // The merge behavior on `has_singular_support` is *non-
        // monotonic*: merging two singular-support histograms can
        // produce a non-singular merge (when the supports differ —
        // the merged histogram has support cardinality 2), and
        // merging two non-singular histograms cannot produce a
        // singular merge unless both sides are empty (vacuously).
        // Pinned with three witnesses spanning the merge surface,
        // plus the empty-identity law.
        //
        // `DiffLineKind::ALL` declaration order is
        // `[Removed, Added, Context]` (axis_cardinality = 3).

        // Witness 1: singular ⊕ singular on disjoint supports →
        // non-singular merge (support cardinality grows from 1 to 2).
        let solo_added: AxisHistogram<DiffLineKind> =
            std::iter::once(DiffLineKind::Added).collect();
        let solo_removed: AxisHistogram<DiffLineKind> =
            std::iter::once(DiffLineKind::Removed).collect();
        assert!(solo_added.has_singular_support());
        assert!(solo_removed.has_singular_support());
        let merged_pair = solo_added.clone().merge(&solo_removed);
        assert!(!merged_pair.has_singular_support());

        // Witness 2: singular ⊕ singular on coincident supports →
        // singular merge (counts add but support stays at the same
        // single cell). The monotone case on the singular-support
        // boundary.
        let more_added: AxisHistogram<DiffLineKind> =
            std::iter::repeat_n(DiffLineKind::Added, 4).collect();
        assert!(more_added.has_singular_support());
        let merged_same = solo_added.clone().merge(&more_added);
        assert!(merged_same.has_singular_support());

        // Witness 3: non-singular ⊕ non-singular → non-singular.
        // Merging never shrinks the support, so two histograms with
        // distinct observed kinds yield a merge with at least the
        // union of supports.
        let mixed_lhs: AxisHistogram<DiffLineKind> = [DiffLineKind::Added, DiffLineKind::Removed]
            .into_iter()
            .collect();
        let mixed_rhs: AxisHistogram<DiffLineKind> = [DiffLineKind::Removed, DiffLineKind::Context]
            .into_iter()
            .collect();
        assert!(!mixed_lhs.has_singular_support());
        assert!(!mixed_rhs.has_singular_support());
        let merged_full = mixed_lhs.clone().merge(&mixed_rhs);
        assert!(!merged_full.has_singular_support());

        // Empty-identity law: merging with the empty histogram
        // leaves `has_singular_support` unchanged on every input.
        // Pinned with both a singular-support input and a
        // non-singular-support input.
        let empty_hist: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
        let singular_with_empty = solo_added.clone().merge(&empty_hist);
        assert_eq!(
            singular_with_empty.has_singular_support(),
            solo_added.has_singular_support(),
        );
        let mixed_with_empty = mixed_lhs.clone().merge(&empty_hist);
        assert_eq!(
            mixed_with_empty.has_singular_support(),
            mixed_lhs.has_singular_support(),
        );
    }

    // ---- AxisHistogram::has_partial_cover trait-uniform laws ----
    //
    // Three trait-uniform laws reach every [`ClosedAxis`] implementor
    // through [`for_each_closed_axis_implementor`] so the partial-cover
    // predicate's contract holds uniformly without per-axis test
    // duplication: empty → false; singleton → true iff axis
    // cardinality ≥ 2; uniform axis-cover → false. The
    // coverage-trichotomy partition law (exactly one of
    // `(is_empty, has_partial_cover, is_full_cover)` fires on every
    // implementor on every canonical shape) reaches the same
    // implementor set as a fourth trait-uniform pin. Concrete pins on
    // the defining equivalence, the support-cardinality strict-
    // interval equivalence, the implication-from-singular-support, and
    // the merge non-monotonicity follow below on [`DiffLineKind`].

    fn assert_has_partial_cover_empty_is_false<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The empty histogram has support cardinality `0`, not strictly
        // between `0` and `axis_cardinality::<A>()`, so the partial-
        // cover predicate reads `false`. The named boundary
        // [`AxisHistogram::is_empty`] carries that corner; the
        // partial-cover middle leg reads `true` only on the strict
        // "some-but-not-all" interior of the trichotomy.
        let hist = AxisHistogram::<A>::empty();
        assert!(
            !hist.has_partial_cover(),
            "empty histogram has_partial_cover must be false on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_has_partial_cover_singleton_iff_cardinality_at_least_two<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // For every cell of the axis: a histogram built from one
        // observation lands the support cardinality at exactly `1`.
        // On every implementor with `axis_cardinality::<A>() >= 2`
        // (every implementor today), `1` is strictly between `0` and
        // `axis_cardinality::<A>()`, so the predicate reads `true`
        // uniformly. On a hypothetical cardinality-1 axis (none in the
        // typescape today, but structurally permitted by
        // [`ClosedAxis`]), the singleton coincides with the
        // full-cover witness and reads `false`. Stated as the
        // conditional law so the witness is uniform across the
        // implementor set without case-splitting on cardinality at the
        // test site.
        for observed in axis_iter::<A>() {
            let hist: AxisHistogram<A> = std::iter::once(observed).collect();
            assert_eq!(
                hist.has_partial_cover(),
                axis_cardinality::<A>() >= 2,
                "singleton has_partial_cover must equal (axis_cardinality >= 2) \
                 for observed cell {observed:?} on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_has_partial_cover_axis_cover_is_false<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Observing every cell exactly once raises the support
        // cardinality to `axis_cardinality::<A>()` — the structural
        // full-cover witness on every implementor. The partial-cover
        // predicate fails uniformly: the "at least one unobserved"
        // half of the conjunction is empty on full cover. Closes the
        // full-cover boundary corner on the (is_empty,
        // has_partial_cover, is_full_cover) trichotomy: axis-cover
        // sits at the is_full_cover corner, disjoint from
        // has_partial_cover.
        let hist: AxisHistogram<A> = axis_iter::<A>().collect();
        assert!(
            !hist.has_partial_cover(),
            "uniform axis-cover has_partial_cover must be false on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_coverage_trichotomy_partitions_every_canonical_shape<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The `(is_empty, has_partial_cover, is_full_cover)` boolean
        // triple is a *strict partition* — pairwise disjoint *and*
        // jointly exhaustive — on every cardinality-≥ 1 implementor.
        // Encoded as the arithmetic invariant `is_empty + partial +
        // is_full_cover == 1`: exactly one corner fires on every
        // histogram. Pinned on three canonical shapes — empty,
        // singleton, axis-cover — across every implementor through
        // [`for_each_closed_axis_implementor`]. Concrete `partial-
        // multi` interior witnesses (cardinality-≥ 2 only) follow
        // below on [`DiffLineKind`].
        let empty = AxisHistogram::<A>::empty();
        let singleton: AxisHistogram<A> = axis_iter::<A>()
            .next()
            .map(|v| std::iter::once(v).collect())
            .expect("every ClosedAxis implementor has at least one variant");
        let axis_cover: AxisHistogram<A> = axis_iter::<A>().collect();
        for hist in [&empty, &singleton, &axis_cover] {
            let e = u8::from(hist.is_empty());
            let p = u8::from(hist.has_partial_cover());
            let f = u8::from(hist.is_full_cover());
            assert_eq!(
                e + p + f,
                1,
                "(is_empty, has_partial_cover, is_full_cover) must be a strict \
                 partition (exactly one corner fires) on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    #[test]
    fn axis_histogram_has_partial_cover_empty_is_false_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_has_partial_cover_empty_is_false::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_has_partial_cover_singleton_iff_cardinality_at_least_two_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_has_partial_cover_singleton_iff_cardinality_at_least_two::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_has_partial_cover_axis_cover_is_false_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_has_partial_cover_axis_cover_is_false::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_coverage_trichotomy_partitions_every_histogram_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_coverage_trichotomy_partitions_every_canonical_shape::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_has_partial_cover_equals_not_empty_and_not_full_cover() {
        // The defining equivalence: `has_partial_cover` reads the same
        // boolean as the open-coded `!is_empty() && !is_full_cover()`
        // form every consumer would otherwise re-derive inline. Pinned
        // pointwise across the canonical observation-mix shapes
        // (empty, singleton, multi-observation-single-cell, partial-
        // skew, partial-uniform, axis-cover) so a future regression in
        // either side surfaces here.
        let inputs: [&[DiffLineKind]; 6] = [
            &[],
            &[DiffLineKind::Added],
            &[DiffLineKind::Added, DiffLineKind::Added],
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
            &[DiffLineKind::Added, DiffLineKind::Removed],
            &[
                DiffLineKind::Added,
                DiffLineKind::Removed,
                DiffLineKind::Context,
            ],
        ];
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            assert_eq!(
                hist.has_partial_cover(),
                !hist.is_empty() && !hist.is_full_cover(),
                "has_partial_cover must equal (!is_empty && !is_full_cover) \
                 on input of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_has_partial_cover_equals_distinct_cells_strict_interval() {
        // The support-cardinality strict-interval form: `has_partial_cover`
        // reads the same boolean as `0 < distinct_cells() &&
        // distinct_cells() < axis_cardinality::<A>()`. Pins the
        // structural form on the named scalar peer: the strict open
        // interval `(0, axis_cardinality::<A>())` of distinct-cell
        // counts is exactly the partial-cover interior of the
        // trichotomy. Pinned pointwise across the same observation-mix
        // shapes so the support-cardinality form is exercised at every
        // branch.
        let cardinality = axis_cardinality::<DiffLineKind>();
        let inputs: [&[DiffLineKind]; 6] = [
            &[],
            &[DiffLineKind::Added],
            &[DiffLineKind::Added, DiffLineKind::Added],
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
            &[DiffLineKind::Added, DiffLineKind::Removed],
            &[
                DiffLineKind::Added,
                DiffLineKind::Removed,
                DiffLineKind::Context,
            ],
        ];
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            let distinct = hist.distinct_cells();
            assert_eq!(
                hist.has_partial_cover(),
                0 < distinct && distinct < cardinality,
                "has_partial_cover must equal (0 < distinct_cells < axis_cardinality) \
                 on input of length {}; distinct={}, cardinality={}",
                input.len(),
                distinct,
                cardinality,
            );
        }
    }

    #[test]
    fn axis_histogram_coverage_trichotomy_partition_on_diff_line_kind() {
        // The strict-partition law over the
        // (is_empty, has_partial_cover, is_full_cover) triple, pinned
        // at every distinct boundary corner reachable on
        // `DiffLineKind` (cardinality 3): empty → (true, false, false),
        // singleton → (false, true, false), axis-cover →
        // (false, false, true), partial-multi (two observed cells out
        // of three) → (false, true, false) — the interior witness on
        // the partial-cover middle leg. On every shape, exactly one
        // corner of the trichotomy fires; the
        // `is_empty + has_partial_cover + is_full_cover == 1`
        // arithmetic invariant pins the strict-partition law at one
        // site (peer to the
        // `support_cardinality_boundary_triple_is_pairwise_disjoint`
        // pin above, which closes only the disjoint half of the
        // partition over the singular-support boundary).
        let empty: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
        assert_eq!(
            (
                empty.is_empty(),
                empty.has_partial_cover(),
                empty.is_full_cover(),
            ),
            (true, false, false),
        );

        let singleton: AxisHistogram<DiffLineKind> = std::iter::once(DiffLineKind::Added).collect();
        assert_eq!(
            (
                singleton.is_empty(),
                singleton.has_partial_cover(),
                singleton.is_full_cover(),
            ),
            (false, true, false),
        );

        let partial_multi: AxisHistogram<DiffLineKind> =
            [DiffLineKind::Added, DiffLineKind::Removed]
                .into_iter()
                .collect();
        assert_eq!(
            (
                partial_multi.is_empty(),
                partial_multi.has_partial_cover(),
                partial_multi.is_full_cover(),
            ),
            (false, true, false),
        );

        let axis_cover: AxisHistogram<DiffLineKind> = axis_iter::<DiffLineKind>().collect();
        assert_eq!(
            (
                axis_cover.is_empty(),
                axis_cover.has_partial_cover(),
                axis_cover.is_full_cover(),
            ),
            (false, false, true),
        );

        for hist in [&empty, &singleton, &partial_multi, &axis_cover] {
            let e = u8::from(hist.is_empty());
            let p = u8::from(hist.has_partial_cover());
            let f = u8::from(hist.is_full_cover());
            assert_eq!(
                e + p + f,
                1,
                "(is_empty, has_partial_cover, is_full_cover) strict-partition \
                 invariant must hold (exactly one corner fires)",
            );
        }
    }

    #[test]
    fn axis_histogram_has_singular_support_implies_has_partial_cover_on_cardinality_at_least_two() {
        // The implication law: `has_singular_support ⇒ has_partial_cover`
        // on every implementor with `axis_cardinality::<A>() >= 2`
        // (every implementor today). Support cardinality `1` is
        // strictly between `0` and `axis_cardinality::<A>()` whenever
        // the axis carries at least 2 cells, so the singular-support
        // corner sits on the partial-cover middle leg of the
        // trichotomy. The converse fails on every multi-cell
        // non-full-cover shape (observing two cells on `DiffLineKind`
        // reads `has_singular_support = false` but
        // `has_partial_cover = true`). Pinned at the implication side
        // (singleton, multi-observation-single-cell — both read
        // singular and partial) and at the converse-fails side
        // (partial-multi — reads partial but not singular).
        let solo: AxisHistogram<DiffLineKind> = std::iter::once(DiffLineKind::Added).collect();
        assert!(solo.has_singular_support());
        assert!(solo.has_partial_cover());

        let many_solo: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Added,
        ]
        .into_iter()
        .collect();
        assert!(many_solo.has_singular_support());
        assert!(many_solo.has_partial_cover());

        let partial_multi: AxisHistogram<DiffLineKind> =
            [DiffLineKind::Added, DiffLineKind::Removed]
                .into_iter()
                .collect();
        assert!(!partial_multi.has_singular_support());
        assert!(partial_multi.has_partial_cover());
    }

    #[test]
    fn axis_histogram_has_partial_cover_after_merge_is_non_monotone() {
        // The merge behavior on `has_partial_cover` is *non-monotonic*
        // on the middle leg: merging two partial-cover histograms can
        // produce a partial-cover merge (when the union of supports
        // stays strictly partial) or a full-cover merge (when the
        // union exhausts the axis), and merging an empty histogram
        // with a partial-cover histogram preserves partial-cover (the
        // empty-identity law). Pinned with three witnesses spanning
        // the merge surface, plus the empty-identity law.
        //
        // `DiffLineKind::ALL` declaration order is
        // `[Removed, Added, Context]` (axis_cardinality = 3).

        // Witness 1: partial ⊕ partial on overlapping supports →
        // partial merge (union of supports stays strictly partial:
        // {Added} ∪ {Added, Removed} = {Added, Removed}, still
        // partial on a cardinality-3 axis).
        let only_added: AxisHistogram<DiffLineKind> =
            std::iter::once(DiffLineKind::Added).collect();
        let added_and_removed: AxisHistogram<DiffLineKind> =
            [DiffLineKind::Added, DiffLineKind::Removed]
                .into_iter()
                .collect();
        assert!(only_added.has_partial_cover());
        assert!(added_and_removed.has_partial_cover());
        let merged_partial = only_added.clone().merge(&added_and_removed);
        assert!(merged_partial.has_partial_cover());

        // Witness 2: partial ⊕ partial on disjoint supports whose
        // union covers the axis → full-cover merge (loses partial-
        // cover on the middle leg).
        let removed_added: AxisHistogram<DiffLineKind> =
            [DiffLineKind::Removed, DiffLineKind::Added]
                .into_iter()
                .collect();
        let only_context: AxisHistogram<DiffLineKind> =
            std::iter::once(DiffLineKind::Context).collect();
        assert!(removed_added.has_partial_cover());
        assert!(only_context.has_partial_cover());
        let merged_full = removed_added.clone().merge(&only_context);
        assert!(!merged_full.has_partial_cover());
        assert!(merged_full.is_full_cover());

        // Witness 3: empty ⊕ empty → empty merge (still on the
        // is_empty corner, not on the partial-cover middle leg).
        let empty_hist: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
        let merged_empty = empty_hist.clone().merge(&empty_hist);
        assert!(!merged_empty.has_partial_cover());
        assert!(merged_empty.is_empty());

        // Empty-identity law: merging with the empty histogram leaves
        // `has_partial_cover` unchanged on every input. Pinned with a
        // partial-cover input and an empty input.
        let partial_with_empty = only_added.clone().merge(&empty_hist);
        assert_eq!(
            partial_with_empty.has_partial_cover(),
            only_added.has_partial_cover(),
        );
        let empty_with_empty = empty_hist.clone().merge(&empty_hist);
        assert_eq!(
            empty_with_empty.has_partial_cover(),
            empty_hist.has_partial_cover(),
        );
    }

    // ---- AxisHistogram::has_singular_gap trait-uniform laws ----
    //
    // Three trait-uniform laws reach every [`ClosedAxis`] implementor
    // through [`for_each_closed_axis_implementor`] so the singular-gap
    // predicate's contract holds uniformly without per-axis test
    // duplication: empty → true iff axis cardinality == 1; singleton →
    // true iff axis cardinality == 2; uniform axis-cover → false.
    // Concrete pins on the defining equivalence (against the
    // [`AxisHistogram::unobserved_cells`] named scalar peer), the
    // support-side dual form (`distinct_cells == axis_cardinality - 1`),
    // the cardinality-≥ 3 disjointness law with
    // [`AxisHistogram::has_singular_support`] (on [`DiffLineKind`]), the
    // cardinality-2 coincidence law with
    // [`AxisHistogram::has_singular_support`] (on [`PartitionFace`]), the
    // implication into [`AxisHistogram::has_partial_cover`] on the
    // partial-cover middle leg of the coverage trichotomy, and the
    // merge non-monotonicity follow below.

    fn assert_has_singular_gap_empty_iff_cardinality_is_one<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The empty histogram has every cell unobserved, so its
        // unobserved-cardinality reads `axis_cardinality::<A>()`. The
        // singular-gap predicate fires iff that reads `1` — i.e. iff
        // the axis carries exactly one cell. Stated as the conditional
        // law so the witness is uniform across the implementor set
        // (every closed-axis primitive in the typescape today carries
        // `axis_cardinality >= 2`, so empty reads `false` uniformly)
        // without case-splitting on cardinality at the test site. The
        // dual-boundary witness of `has_singular_support_axis_cover_iff_cardinality_is_one`
        // on the opposite end of the support-cardinality interval.
        let hist = AxisHistogram::<A>::empty();
        assert_eq!(
            hist.has_singular_gap(),
            axis_cardinality::<A>() == 1,
            "empty histogram has_singular_gap must equal (axis_cardinality == 1) \
             on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_has_singular_gap_singleton_iff_cardinality_is_two<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // For every cell of the axis: a histogram built from one
        // observation of that cell lands distinct_cells at exactly `1`,
        // so the unobserved-cardinality reads `axis_cardinality::<A>() - 1`.
        // The singular-gap predicate fires iff that reads `1` — i.e.
        // iff the axis carries exactly two cells. Stated as the
        // conditional law so the witness is uniform across the
        // implementor set without case-splitting on cardinality at the
        // test site. Every cardinality-2 closed-axis primitive
        // (e.g. `PartitionFace`, `SecretRefShape`) reads `true` on
        // every singleton; every cardinality-≥ 3 primitive reads
        // `false` uniformly.
        for observed in axis_iter::<A>() {
            let hist: AxisHistogram<A> = std::iter::once(observed).collect();
            assert_eq!(
                hist.has_singular_gap(),
                axis_cardinality::<A>() == 2,
                "singleton has_singular_gap must equal (axis_cardinality == 2) \
                 for observed cell {observed:?} on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_has_singular_gap_axis_cover_is_false<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Observing every cell exactly once drives the unobserved-
        // cardinality to `0`, so the singular-gap predicate reads
        // `false` uniformly on every implementor (the structural
        // full-cover witness). Closes the full-cover boundary corner
        // on the singular-gap surface: axis-cover sits at the
        // `is_full_cover` corner, disjoint from `has_singular_gap`.
        // Peer of `has_partial_cover_axis_cover_is_false` on the dual-
        // singular side of the support-cardinality interval.
        let hist: AxisHistogram<A> = axis_iter::<A>().collect();
        assert!(
            !hist.has_singular_gap(),
            "uniform axis-cover has_singular_gap must be false on axis {}",
            std::any::type_name::<A>(),
        );
    }

    #[test]
    fn axis_histogram_has_singular_gap_empty_iff_cardinality_is_one_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_has_singular_gap_empty_iff_cardinality_is_one::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_has_singular_gap_singleton_iff_cardinality_is_two_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_has_singular_gap_singleton_iff_cardinality_is_two::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_has_singular_gap_axis_cover_is_false_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_has_singular_gap_axis_cover_is_false::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_has_singular_gap_equals_unobserved_cells_is_one() {
        // The defining equivalence: `has_singular_gap` reads the same
        // boolean as the open-coded `unobserved_cells() == 1` form
        // every consumer would otherwise re-derive inline. Pinned
        // pointwise across the canonical observation-mix shapes (empty,
        // singleton, singleton-multi-observation, partial-skew, partial-
        // uniform, axis-cover) so a future regression in either side
        // surfaces here. Peer of
        // `axis_histogram_has_singular_support_equals_distinct_cells_is_one`
        // on the unobserved-cardinality scalar.
        let inputs: [&[DiffLineKind]; 6] = [
            &[],
            &[DiffLineKind::Added],
            &[DiffLineKind::Added, DiffLineKind::Added],
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
            &[DiffLineKind::Added, DiffLineKind::Removed],
            &[
                DiffLineKind::Added,
                DiffLineKind::Removed,
                DiffLineKind::Context,
            ],
        ];
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            assert_eq!(
                hist.has_singular_gap(),
                hist.unobserved_cells() == 1,
                "has_singular_gap must equal (unobserved_cells == 1) \
                 on input of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_has_singular_gap_equals_distinct_cells_is_one_less_than_cardinality() {
        // The support-side dual form: `has_singular_gap` reads the same
        // boolean as `distinct_cells() == axis_cardinality::<A>() - 1`
        // via the `distinct_cells + unobserved_cells == axis_cardinality`
        // partition invariant. Pins the dual structural form on the
        // support-cardinality scalar peer: support cardinality `cardinality
        // - 1` is exactly the singular-gap corner of the support
        // interval. Peer of
        // `axis_histogram_has_singular_support_equals_distinct_cells_is_one`
        // on the opposite end of the support-cardinality interval.
        let cardinality = axis_cardinality::<DiffLineKind>();
        let inputs: [&[DiffLineKind]; 6] = [
            &[],
            &[DiffLineKind::Added],
            &[DiffLineKind::Added, DiffLineKind::Added],
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
            &[DiffLineKind::Added, DiffLineKind::Removed],
            &[
                DiffLineKind::Added,
                DiffLineKind::Removed,
                DiffLineKind::Context,
            ],
        ];
        for input in inputs {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            let distinct = hist.distinct_cells();
            assert_eq!(
                hist.has_singular_gap(),
                distinct + 1 == cardinality,
                "has_singular_gap must equal (distinct_cells + 1 == axis_cardinality) \
                 on input of length {}; distinct={}, cardinality={}",
                input.len(),
                distinct,
                cardinality,
            );
        }
    }

    #[test]
    fn axis_histogram_has_singular_gap_and_has_singular_support_disjoint_on_cardinality_three() {
        // On every implementor with `axis_cardinality >= 3` (DiffLineKind
        // is the smallest cardinality-3 axis on the typescape, with
        // cardinality 3), `has_singular_support` (distinct_cells == 1)
        // and `has_singular_gap` (distinct_cells == cardinality - 1
        // == 2) are pointwise disjoint: their support-cardinality
        // witnesses are 1 and 2 respectively, never equal. Pinned at
        // every distinct support-cardinality witness reachable on
        // DiffLineKind (empty, singleton, two-cell, three-cell axis-
        // cover): the conjunction `support && gap` reads `false`
        // uniformly. The structural disjointness witness on the
        // smallest-cardinality-3 implementor.
        let empty: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
        let singleton: AxisHistogram<DiffLineKind> = std::iter::once(DiffLineKind::Added).collect();
        let two_cell: AxisHistogram<DiffLineKind> = [DiffLineKind::Added, DiffLineKind::Removed]
            .into_iter()
            .collect();
        let axis_cover: AxisHistogram<DiffLineKind> = axis_iter::<DiffLineKind>().collect();
        for hist in [&empty, &singleton, &two_cell, &axis_cover] {
            assert!(
                !(hist.has_singular_support() && hist.has_singular_gap()),
                "has_singular_support and has_singular_gap must be pointwise \
                 disjoint on cardinality-3 axes (distinct_cells={})",
                hist.distinct_cells(),
            );
        }
        // The two-cell shape is the unique singular-gap witness on
        // DiffLineKind: one cell unobserved (Context), two observed.
        // Pinned alongside the disjointness law so the cardinality-3
        // dual-singular partition is exercised at its only interior
        // witness.
        assert!(!two_cell.has_singular_support());
        assert!(two_cell.has_singular_gap());
        // Singleton is the unique singular-support witness on
        // DiffLineKind: one observed, two unobserved.
        assert!(singleton.has_singular_support());
        assert!(!singleton.has_singular_gap());
    }

    #[test]
    fn axis_histogram_has_singular_gap_equals_has_singular_support_on_cardinality_two() {
        // On every implementor with `axis_cardinality == 2`
        // (PartitionFace and SecretRefShape today), `has_singular_gap`
        // and `has_singular_support` read the *same* boolean pointwise:
        // one observed cell *is* one unobserved cell when the axis
        // carries exactly two cells (support 1 == cardinality - 1 == 1
        // on cardinality 2). The structural cardinality-2 coincidence
        // witness on the dual-boundary collapse. Pinned at every
        // canonical shape reachable on `PartitionFace`: empty,
        // singleton on each face, axis-cover. The two predicates agree
        // pointwise on every shape.
        let empty: AxisHistogram<PartitionFace> = AxisHistogram::empty();
        let realizable_only: AxisHistogram<PartitionFace> =
            std::iter::once(PartitionFace::Realizable).collect();
        let unrealizable_only: AxisHistogram<PartitionFace> =
            std::iter::once(PartitionFace::Unrealizable).collect();
        let axis_cover: AxisHistogram<PartitionFace> = axis_iter::<PartitionFace>().collect();
        for hist in [&empty, &realizable_only, &unrealizable_only, &axis_cover] {
            assert_eq!(
                hist.has_singular_gap(),
                hist.has_singular_support(),
                "has_singular_gap and has_singular_support must coincide \
                 pointwise on cardinality-2 axes (distinct_cells={})",
                hist.distinct_cells(),
            );
        }
        // Each singleton on a cardinality-2 axis sits on both singular
        // corners simultaneously (support 1 == cardinality - 1 == 1):
        // pinned as the dual-singular collapse witness.
        assert!(realizable_only.has_singular_support());
        assert!(realizable_only.has_singular_gap());
        assert!(unrealizable_only.has_singular_support());
        assert!(unrealizable_only.has_singular_gap());
    }

    #[test]
    fn axis_histogram_has_singular_gap_implies_has_partial_cover_on_cardinality_at_least_two() {
        // The implication law: `has_singular_gap ⇒ has_partial_cover`
        // on every implementor with `axis_cardinality::<A>() >= 2`
        // (every implementor today). One unobserved cell means at
        // least one observed (cardinality - 1 >= 1) and at least one
        // unobserved, so the singular-gap corner sits on the partial-
        // cover middle leg of the
        // `(is_empty, has_partial_cover, is_full_cover)` trichotomy.
        // Peer of
        // `axis_histogram_has_singular_support_implies_has_partial_cover_on_cardinality_at_least_two`
        // on the opposite end of the support-cardinality interval —
        // both singular boundaries land on the partial-cover middle
        // leg. Pinned at the implication side (two-cell partial on
        // DiffLineKind, both singletons on PartitionFace) and at the
        // converse-fails side (partial-skew with two distinct observed
        // cells on DiffLineKind reads partial but not singular-gap).
        let two_cell: AxisHistogram<DiffLineKind> = [DiffLineKind::Added, DiffLineKind::Removed]
            .into_iter()
            .collect();
        assert!(two_cell.has_singular_gap());
        assert!(two_cell.has_partial_cover());

        let realizable_only: AxisHistogram<PartitionFace> =
            std::iter::once(PartitionFace::Realizable).collect();
        assert!(realizable_only.has_singular_gap());
        assert!(realizable_only.has_partial_cover());

        // Converse-fails witness on DiffLineKind: the singleton has
        // partial cover but two unobserved cells (not 1), so reads
        // singular-gap = false.
        let singleton: AxisHistogram<DiffLineKind> = std::iter::once(DiffLineKind::Added).collect();
        assert!(singleton.has_partial_cover());
        assert!(!singleton.has_singular_gap());
    }

    #[test]
    fn axis_histogram_has_singular_gap_after_merge_is_non_monotone() {
        // The merge behavior on `has_singular_gap` is *non-monotonic*:
        // merging two singular-gap histograms whose missing cells
        // *differ* fills both gaps and lands the merge at full cover
        // (loses singular gap); merging two singular-gap histograms
        // whose missing cells *coincide* preserves the singular gap;
        // merging an empty histogram with a singular-gap histogram
        // preserves the singular gap (the empty-identity law). Pinned
        // with three witnesses spanning the merge surface, plus the
        // empty-identity law.
        //
        // `DiffLineKind::ALL` declaration order is
        // `[Removed, Added, Context]` (axis_cardinality = 3). Each
        // two-cell shape sits on the singular-gap corner (one cell
        // missing).

        // Witness 1: gap ⊕ gap on coinciding missing cells →
        // singular-gap merge preserved (both miss Context, the union
        // of supports is still {Removed, Added}, still one cell short).
        let missing_context_a: AxisHistogram<DiffLineKind> =
            [DiffLineKind::Removed, DiffLineKind::Added]
                .into_iter()
                .collect();
        let missing_context_b: AxisHistogram<DiffLineKind> =
            [DiffLineKind::Added, DiffLineKind::Removed]
                .into_iter()
                .collect();
        assert!(missing_context_a.has_singular_gap());
        assert!(missing_context_b.has_singular_gap());
        let merged_coinciding = missing_context_a.clone().merge(&missing_context_b);
        assert!(merged_coinciding.has_singular_gap());

        // Witness 2: gap ⊕ gap on differing missing cells →
        // full-cover merge (one misses Context, the other misses
        // Removed; their union is the full axis).
        let missing_removed: AxisHistogram<DiffLineKind> =
            [DiffLineKind::Added, DiffLineKind::Context]
                .into_iter()
                .collect();
        assert!(missing_context_a.has_singular_gap());
        assert!(missing_removed.has_singular_gap());
        let merged_differing = missing_context_a.clone().merge(&missing_removed);
        assert!(!merged_differing.has_singular_gap());
        assert!(merged_differing.is_full_cover());

        // Witness 3: empty ⊕ empty → empty merge (still on the
        // is_empty corner, not on the singular-gap boundary —
        // unobserved cells == axis_cardinality, not 1).
        let empty_hist: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
        let merged_empty = empty_hist.clone().merge(&empty_hist);
        assert!(!merged_empty.has_singular_gap());
        assert!(merged_empty.is_empty());

        // Empty-identity law: merging with the empty histogram leaves
        // `has_singular_gap` unchanged on every input. Pinned with a
        // singular-gap input and an empty input.
        let gap_with_empty = missing_context_a.clone().merge(&empty_hist);
        assert_eq!(
            gap_with_empty.has_singular_gap(),
            missing_context_a.has_singular_gap(),
        );
        let empty_with_empty = empty_hist.clone().merge(&empty_hist);
        assert_eq!(
            empty_with_empty.has_singular_gap(),
            empty_hist.has_singular_gap(),
        );
    }

    // ---- AxisHistogram::has_strict_partial_cover trait-uniform laws ----
    //
    // Three trait-uniform laws reach every [`ClosedAxis`] implementor
    // through [`for_each_closed_axis_implementor`] so the
    // strict-partial-cover predicate's contract holds uniformly without
    // per-axis test duplication: empty → false, singleton → false, axis-
    // cover → false. Concrete pins on the defining structural form
    // (against the existing named-boundary triad on [`Format`]
    // cardinality 4), the support-cardinality strict-interval form
    // (against `1 < distinct_cells && distinct_cells + 1 < cardinality`
    // on [`ShikumiErrorKind`] cardinality 6), the cardinality-`<= 3`
    // vacuity laws (`DiffLineKind` and `PartitionFace` — both read
    // `false` uniformly across every canonical shape because the
    // `[2, cardinality - 2]` strict interval is empty as a set of
    // support cardinalities), the implication into
    // [`AxisHistogram::has_partial_cover`] on the partial-cover middle
    // leg, the pairwise disjointness with the two singular boundaries on
    // cardinality `>= 3`, the support-cardinality 5-corner partition pin
    // on [`ShikumiErrorKind`], and the merge non-monotonicity follow
    // below.

    fn assert_has_strict_partial_cover_empty_is_false<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The empty histogram has zero observed cells, so the "at least
        // two observed" half of the conjunction fails uniformly. The
        // named boundary `is_empty` carries that case; the strict
        // interior reads `false` uniformly across the implementor set
        // independently of cardinality.
        let hist = AxisHistogram::<A>::empty();
        assert!(
            !hist.has_strict_partial_cover(),
            "empty histogram has_strict_partial_cover must be false on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_has_strict_partial_cover_singleton_is_false<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Every singleton observation lands the support cardinality at
        // exactly `1`, so the "at least two observed" half of the
        // conjunction fails uniformly. The named boundary
        // `has_singular_support` carries that case; the strict interior
        // reads `false` uniformly across the implementor set on every
        // singleton independently of cardinality.
        for observed in axis_iter::<A>() {
            let hist: AxisHistogram<A> = std::iter::once(observed).collect();
            assert!(
                !hist.has_strict_partial_cover(),
                "singleton has_strict_partial_cover must be false \
                 for observed cell {observed:?} on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_has_strict_partial_cover_axis_cover_is_false<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Observing every cell exactly once drives the unobserved-
        // cardinality to `0`, so the "at least two unobserved" half of
        // the conjunction fails uniformly. The named boundary
        // `is_full_cover` carries that case; the strict interior reads
        // `false` uniformly across the implementor set independently of
        // cardinality. Peer of `has_partial_cover_axis_cover_is_false`
        // and `has_singular_gap_axis_cover_is_false` on the full-cover
        // boundary corner of the support-cardinality scalar.
        let hist: AxisHistogram<A> = axis_iter::<A>().collect();
        assert!(
            !hist.has_strict_partial_cover(),
            "uniform axis-cover has_strict_partial_cover must be false on axis {}",
            std::any::type_name::<A>(),
        );
    }

    #[test]
    fn axis_histogram_has_strict_partial_cover_empty_is_false_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_has_strict_partial_cover_empty_is_false::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_has_strict_partial_cover_singleton_is_false_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_has_strict_partial_cover_singleton_is_false::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_has_strict_partial_cover_axis_cover_is_false_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_has_strict_partial_cover_axis_cover_is_false::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_has_strict_partial_cover_equals_has_partial_cover_and_not_singular_boundaries()
     {
        // The defining structural form: `has_strict_partial_cover` reads
        // the same boolean as the open-coded
        // `has_partial_cover() && !has_singular_support() && !has_singular_gap()`
        // form every consumer would otherwise re-derive inline across
        // three named predicates and two negations. Pinned pointwise
        // across the canonical observation-mix shapes on [`Format`]
        // (cardinality 4 — the smallest implementor on the typescape
        // today where the strict interior carries a witness; the strict
        // interval `[2, 2]` of support cardinalities reaches one cell,
        // exactly at support cardinality `2`). The five reachable
        // shapes on Format are empty (support 0), singleton (support 1),
        // two-cell (support 2 — the unique strict-interior witness on
        // cardinality 4), three-cell (support 3 == cardinality - 1 —
        // singular-gap), and axis-cover (support 4 — full-cover).
        let inputs: [&[Format]; 5] = [
            &[],
            &[Format::Yaml],
            &[Format::Yaml, Format::Toml],
            &[Format::Yaml, Format::Toml, Format::Lisp],
            &[Format::Yaml, Format::Toml, Format::Lisp, Format::Nix],
        ];
        for input in inputs {
            let hist: AxisHistogram<Format> = input.iter().copied().collect();
            assert_eq!(
                hist.has_strict_partial_cover(),
                hist.has_partial_cover()
                    && !hist.has_singular_support()
                    && !hist.has_singular_gap(),
                "has_strict_partial_cover must equal \
                 (has_partial_cover && !has_singular_support && !has_singular_gap) \
                 on input of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_has_strict_partial_cover_equals_distinct_cells_strict_interior() {
        // The support-cardinality strict-interval form on the named
        // scalar peer: `has_strict_partial_cover` reads the same boolean
        // as `1 < distinct_cells() && distinct_cells() + 1 <
        // axis_cardinality::<A>()` — the strict open interval
        // `(1, axis_cardinality::<A>() - 1)` of distinct-cell counts is
        // exactly the strict interior of the support-cardinality scalar.
        // Pinned on [`ShikumiErrorKind`] (cardinality 6) so the strict
        // interior is exercised at multiple distinct support values
        // (2, 3, 4) rather than the cardinality-4 single-witness case.
        // Peer of `axis_histogram_has_partial_cover_equals_distinct_cells_strict_interval`
        // on the coarser middle leg of the coverage trichotomy.
        let cardinality = axis_cardinality::<ShikumiErrorKind>();
        let inputs: [&[ShikumiErrorKind]; 7] = [
            &[],
            &[ShikumiErrorKind::NotFound],
            &[ShikumiErrorKind::NotFound, ShikumiErrorKind::Parse],
            &[
                ShikumiErrorKind::NotFound,
                ShikumiErrorKind::Parse,
                ShikumiErrorKind::Watch,
            ],
            &[
                ShikumiErrorKind::NotFound,
                ShikumiErrorKind::Parse,
                ShikumiErrorKind::Watch,
                ShikumiErrorKind::Io,
            ],
            &[
                ShikumiErrorKind::NotFound,
                ShikumiErrorKind::Parse,
                ShikumiErrorKind::Watch,
                ShikumiErrorKind::Io,
                ShikumiErrorKind::Figment,
            ],
            &[
                ShikumiErrorKind::NotFound,
                ShikumiErrorKind::Parse,
                ShikumiErrorKind::Watch,
                ShikumiErrorKind::Io,
                ShikumiErrorKind::Figment,
                ShikumiErrorKind::Extract,
            ],
        ];
        for input in inputs {
            let hist: AxisHistogram<ShikumiErrorKind> = input.iter().copied().collect();
            let distinct = hist.distinct_cells();
            assert_eq!(
                hist.has_strict_partial_cover(),
                1 < distinct && distinct + 1 < cardinality,
                "has_strict_partial_cover must equal \
                 (1 < distinct_cells && distinct_cells + 1 < axis_cardinality) \
                 on input of length {}; distinct={}, cardinality={}",
                input.len(),
                distinct,
                cardinality,
            );
        }
    }

    #[test]
    fn axis_histogram_has_strict_partial_cover_vacuous_on_cardinality_three() {
        // On every cardinality-3 axis (DiffLineKind today), the
        // `[2, cardinality - 2] == [2, 1]` strict interval of support
        // cardinalities is empty as a set: the two singular boundaries
        // sit adjacent at supports `1` and `cardinality - 1 == 2`, with
        // no room for a strict interior. So `has_strict_partial_cover`
        // reads `false` uniformly on every reachable shape, independently
        // of the histogram content. Pinned at every distinct shape on
        // DiffLineKind (empty, singleton, two-cell partial = singular-
        // gap on cardinality 3, axis-cover) so the cardinality-3 vacuity
        // law is exercised at every reachable support value.
        let empty: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
        let singleton: AxisHistogram<DiffLineKind> = std::iter::once(DiffLineKind::Added).collect();
        let two_cell: AxisHistogram<DiffLineKind> = [DiffLineKind::Added, DiffLineKind::Removed]
            .into_iter()
            .collect();
        let axis_cover: AxisHistogram<DiffLineKind> = axis_iter::<DiffLineKind>().collect();
        for hist in [&empty, &singleton, &two_cell, &axis_cover] {
            assert!(
                !hist.has_strict_partial_cover(),
                "has_strict_partial_cover must be false uniformly on cardinality-3 \
                 axes (distinct_cells={})",
                hist.distinct_cells(),
            );
        }
    }

    #[test]
    fn axis_histogram_has_strict_partial_cover_vacuous_on_cardinality_two() {
        // On every cardinality-2 axis (PartitionFace and SecretRefShape
        // today), the `[2, cardinality - 2] == [2, 0]` strict interval is
        // empty as a set: there is no room between the two boundary
        // corners. So `has_strict_partial_cover` reads `false` uniformly
        // on every reachable shape independently of the histogram
        // content. Pinned at every distinct shape on PartitionFace
        // (empty, two singletons sitting on both singular boundaries
        // simultaneously per the cardinality-2 collapse, axis-cover) so
        // the cardinality-2 vacuity law is exercised at every reachable
        // support value.
        let empty: AxisHistogram<PartitionFace> = AxisHistogram::empty();
        let realizable_only: AxisHistogram<PartitionFace> =
            std::iter::once(PartitionFace::Realizable).collect();
        let unrealizable_only: AxisHistogram<PartitionFace> =
            std::iter::once(PartitionFace::Unrealizable).collect();
        let axis_cover: AxisHistogram<PartitionFace> = axis_iter::<PartitionFace>().collect();
        for hist in [&empty, &realizable_only, &unrealizable_only, &axis_cover] {
            assert!(
                !hist.has_strict_partial_cover(),
                "has_strict_partial_cover must be false uniformly on cardinality-2 \
                 axes (distinct_cells={})",
                hist.distinct_cells(),
            );
        }
    }

    #[test]
    fn axis_histogram_has_strict_partial_cover_implies_has_partial_cover() {
        // The implication law: `has_strict_partial_cover ⇒
        // has_partial_cover` always. The strict interior sits inside the
        // partial-cover middle leg of the coverage trichotomy by
        // construction. The converse fails at both singular corners — the
        // singleton on Format reads `has_partial_cover = true` but
        // `has_strict_partial_cover = false` (sits on the singular-
        // support boundary). Pinned on Format with one interior witness
        // (the implication side) and two boundary witnesses (the
        // converse-fails sides, singular-support and singular-gap).
        let two_cell: AxisHistogram<Format> = [Format::Yaml, Format::Toml].into_iter().collect();
        assert!(two_cell.has_strict_partial_cover());
        assert!(two_cell.has_partial_cover());

        let singleton: AxisHistogram<Format> = std::iter::once(Format::Yaml).collect();
        assert!(!singleton.has_strict_partial_cover());
        assert!(singleton.has_partial_cover());

        let three_cell: AxisHistogram<Format> = [Format::Yaml, Format::Toml, Format::Lisp]
            .into_iter()
            .collect();
        assert!(!three_cell.has_strict_partial_cover());
        assert!(three_cell.has_partial_cover());
    }

    #[test]
    fn axis_histogram_has_strict_partial_cover_disjoint_from_singular_boundaries() {
        // The pairwise disjointness law on the singular-cardinality
        // boundary triple: `(has_singular_support, has_strict_partial_cover,
        // has_singular_gap)` is pairwise disjoint on every implementor
        // with `axis_cardinality::<A>() >= 3`. The three predicates fire
        // on support cardinalities `1`, `[2, cardinality - 2]`, and
        // `cardinality - 1` respectively — three non-overlapping
        // intervals. Pinned on [`ShikumiErrorKind`] (cardinality 6) at
        // every reachable support cardinality (0 through 6).
        let inputs: [&[ShikumiErrorKind]; 7] = [
            &[],
            &[ShikumiErrorKind::NotFound],
            &[ShikumiErrorKind::NotFound, ShikumiErrorKind::Parse],
            &[
                ShikumiErrorKind::NotFound,
                ShikumiErrorKind::Parse,
                ShikumiErrorKind::Watch,
            ],
            &[
                ShikumiErrorKind::NotFound,
                ShikumiErrorKind::Parse,
                ShikumiErrorKind::Watch,
                ShikumiErrorKind::Io,
            ],
            &[
                ShikumiErrorKind::NotFound,
                ShikumiErrorKind::Parse,
                ShikumiErrorKind::Watch,
                ShikumiErrorKind::Io,
                ShikumiErrorKind::Figment,
            ],
            &[
                ShikumiErrorKind::NotFound,
                ShikumiErrorKind::Parse,
                ShikumiErrorKind::Watch,
                ShikumiErrorKind::Io,
                ShikumiErrorKind::Figment,
                ShikumiErrorKind::Extract,
            ],
        ];
        for input in inputs {
            let hist: AxisHistogram<ShikumiErrorKind> = input.iter().copied().collect();
            let support = u8::from(hist.has_singular_support());
            let interior = u8::from(hist.has_strict_partial_cover());
            let gap = u8::from(hist.has_singular_gap());
            assert!(
                support + interior + gap <= 1,
                "(has_singular_support, has_strict_partial_cover, has_singular_gap) \
                 must be pairwise disjoint on cardinality-≥ 3 axes \
                 (support+interior+gap = {} on input of length {})",
                support + interior + gap,
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_support_cardinality_five_corner_partition_on_shikumi_error_kind() {
        // The strict 5-corner partition law over
        // `(is_empty, has_singular_support, has_strict_partial_cover,
        // has_singular_gap, is_full_cover)`, pinned at every distinct
        // support cardinality reachable on [`ShikumiErrorKind`]
        // (cardinality 6): support 0 → empty, support 1 → singular-
        // support, supports 2/3/4 → strict-interior, support 5 →
        // singular-gap, support 6 → full-cover. On every shape, exactly
        // one corner fires; the `e + s + i + g + f == 1` arithmetic
        // invariant pins the strict-partition law at one site (peer to
        // the `coverage_trichotomy_partitions_every_histogram` pin on the
        // coarser 3-corner trichotomy). The pin closes the
        // support-cardinality scalar surface as a 5-cell strict partition
        // on cardinality-≥ 3 axes.
        let shapes: [&[ShikumiErrorKind]; 7] = [
            &[],
            &[ShikumiErrorKind::NotFound],
            &[ShikumiErrorKind::NotFound, ShikumiErrorKind::Parse],
            &[
                ShikumiErrorKind::NotFound,
                ShikumiErrorKind::Parse,
                ShikumiErrorKind::Watch,
            ],
            &[
                ShikumiErrorKind::NotFound,
                ShikumiErrorKind::Parse,
                ShikumiErrorKind::Watch,
                ShikumiErrorKind::Io,
            ],
            &[
                ShikumiErrorKind::NotFound,
                ShikumiErrorKind::Parse,
                ShikumiErrorKind::Watch,
                ShikumiErrorKind::Io,
                ShikumiErrorKind::Figment,
            ],
            &[
                ShikumiErrorKind::NotFound,
                ShikumiErrorKind::Parse,
                ShikumiErrorKind::Watch,
                ShikumiErrorKind::Io,
                ShikumiErrorKind::Figment,
                ShikumiErrorKind::Extract,
            ],
        ];
        for shape in shapes {
            let hist: AxisHistogram<ShikumiErrorKind> = shape.iter().copied().collect();
            let empty = u8::from(hist.is_empty());
            let support = u8::from(hist.has_singular_support());
            let interior = u8::from(hist.has_strict_partial_cover());
            let gap = u8::from(hist.has_singular_gap());
            let full = u8::from(hist.is_full_cover());
            assert_eq!(
                empty + support + interior + gap + full,
                1,
                "(is_empty, has_singular_support, has_strict_partial_cover, \
                 has_singular_gap, is_full_cover) must be a strict partition \
                 (exactly one corner fires) on shape of length {}; \
                 (empty,support,interior,gap,full) = ({},{},{},{},{})",
                shape.len(),
                empty,
                support,
                interior,
                gap,
                full,
            );
        }
    }

    #[test]
    fn axis_histogram_has_strict_partial_cover_after_merge_is_non_monotone() {
        // The merge behavior on `has_strict_partial_cover` is
        // *non-monotonic*: merging two strict-interior histograms can
        // produce a strict-interior merge (when the union of supports
        // stays strictly between the singular boundaries), a singular-
        // gap merge (when the union covers all but one cell), or a
        // full-cover merge (when the union exhausts the axis); merging
        // an empty histogram with a strict-interior histogram preserves
        // strict-interior (the empty-identity law). Pinned with three
        // witnesses spanning the merge surface on [`ShikumiErrorKind`]
        // (cardinality 6, where the strict interior reaches supports 2,
        // 3, and 4), plus the empty-identity law.

        // Witness 1: strict-interior ⊕ strict-interior on overlapping
        // supports → strict-interior merge (union of supports stays in
        // the `[2, 4]` strict interval on cardinality 6).
        let two_cell: AxisHistogram<ShikumiErrorKind> =
            [ShikumiErrorKind::NotFound, ShikumiErrorKind::Parse]
                .into_iter()
                .collect();
        let two_cell_overlap: AxisHistogram<ShikumiErrorKind> =
            [ShikumiErrorKind::Parse, ShikumiErrorKind::Watch]
                .into_iter()
                .collect();
        assert!(two_cell.has_strict_partial_cover());
        assert!(two_cell_overlap.has_strict_partial_cover());
        let merged_strict = two_cell.clone().merge(&two_cell_overlap);
        assert!(merged_strict.has_strict_partial_cover());

        // Witness 2: strict-interior ⊕ strict-interior on disjoint
        // supports whose union reaches `cardinality - 1` → singular-gap
        // merge (loses the strict interior on the singular-gap
        // boundary). Two two-cell shapes with disjoint supports of size
        // 2 each whose union has size 4 — still strict interior — then
        // adding another cell to reach support 5 = singular-gap.
        let four_cell: AxisHistogram<ShikumiErrorKind> = [
            ShikumiErrorKind::NotFound,
            ShikumiErrorKind::Parse,
            ShikumiErrorKind::Watch,
            ShikumiErrorKind::Io,
        ]
        .into_iter()
        .collect();
        let one_cell: AxisHistogram<ShikumiErrorKind> =
            std::iter::once(ShikumiErrorKind::Figment).collect();
        assert!(four_cell.has_strict_partial_cover());
        let merged_gap = four_cell.clone().merge(&one_cell);
        assert!(!merged_gap.has_strict_partial_cover());
        assert!(merged_gap.has_singular_gap());

        // Witness 3: strict-interior ⊕ disjoint cover → full-cover
        // merge (loses the strict interior on the full-cover boundary).
        let three_cell: AxisHistogram<ShikumiErrorKind> = [
            ShikumiErrorKind::NotFound,
            ShikumiErrorKind::Parse,
            ShikumiErrorKind::Watch,
        ]
        .into_iter()
        .collect();
        let other_three_cell: AxisHistogram<ShikumiErrorKind> = [
            ShikumiErrorKind::Io,
            ShikumiErrorKind::Figment,
            ShikumiErrorKind::Extract,
        ]
        .into_iter()
        .collect();
        assert!(three_cell.has_strict_partial_cover());
        assert!(other_three_cell.has_strict_partial_cover());
        let merged_full = three_cell.clone().merge(&other_three_cell);
        assert!(!merged_full.has_strict_partial_cover());
        assert!(merged_full.is_full_cover());

        // Empty-identity law: merging with the empty histogram leaves
        // `has_strict_partial_cover` unchanged on every input. Pinned
        // with a strict-interior input and an empty input.
        let empty_hist: AxisHistogram<ShikumiErrorKind> = AxisHistogram::empty();
        let strict_with_empty = two_cell.clone().merge(&empty_hist);
        assert_eq!(
            strict_with_empty.has_strict_partial_cover(),
            two_cell.has_strict_partial_cover(),
        );
        let empty_with_empty = empty_hist.clone().merge(&empty_hist);
        assert_eq!(
            empty_with_empty.has_strict_partial_cover(),
            empty_hist.has_strict_partial_cover(),
        );
    }

    // ---- AxisHistogram::Hash trait-uniform laws ----
    //
    // [`std::hash::Hash`] is the canonical Rust idiom-peer of [`Eq`];
    // every stdlib collection-key type that exposes one exposes the
    // other (`HashMap` / `HashSet` require `K: Eq + Hash`), and the
    // (Eq ⇒ same hash) contract is the load-bearing invariant that
    // lets the hash-keyed collections perform correctly. The four
    // trait-uniform laws below pin the [`Hash`] derive's contract
    // uniformly across every [`ClosedAxis`] implementor: equal
    // histograms hash to the same `u64` under the same [`Hasher`]
    // state; two independently constructed empty histograms hash
    // identically; cloning preserves the hash pointwise; and a
    // histogram round-tripped through [`HashSet::contains`] is
    // recovered by its own hash (the canonical (Eq, Hash) consistency
    // pin every stdlib hash-keyed collection assumes).

    fn hash_of<T: std::hash::Hash>(value: &T) -> u64 {
        use std::hash::{DefaultHasher, Hasher};
        let mut hasher = DefaultHasher::new();
        value.hash(&mut hasher);
        hasher.finish()
    }

    fn assert_hash_equal_implies_same_hash<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The (Eq ⇒ same hash) contract on the `Hash` derive: two
        // histograms that compare equal must hash equally under the
        // same `Hasher` state. The load-bearing invariant every
        // stdlib hash-keyed collection assumes. Pinned over two
        // independently constructed axis-cover histograms (built by
        // distinct iterator chains) so the same-value / same-hash
        // pairing reads off without aliasing the input vectors.
        let lhs: AxisHistogram<A> = axis_iter::<A>().collect();
        let rhs: AxisHistogram<A> = axis_iter::<A>().collect();
        assert_eq!(
            lhs,
            rhs,
            "two axis-cover histograms must compare equal on axis {}",
            std::any::type_name::<A>(),
        );
        assert_eq!(
            hash_of(&lhs),
            hash_of(&rhs),
            "Eq histograms must hash equally on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_hash_empty_is_consistent<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The empty-histogram self-consistency law on the `Hash`
        // derive: two independently constructed
        // [`AxisHistogram::empty`] instances hash identically, and
        // the [`Default`] surface (which lowers to `empty`) reaches
        // the same hash. Pinned so the monoid identity carries a
        // stable hash value across every implementor.
        let via_empty = AxisHistogram::<A>::empty();
        let via_empty_again = AxisHistogram::<A>::empty();
        let via_default = AxisHistogram::<A>::default();
        assert_eq!(
            hash_of(&via_empty),
            hash_of(&via_empty_again),
            "AxisHistogram::empty must hash consistently on axis {}",
            std::any::type_name::<A>(),
        );
        assert_eq!(
            hash_of(&via_empty),
            hash_of(&via_default),
            "AxisHistogram::default must hash like ::empty on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_hash_clone_preserves_hash<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The clone-preserves-hash law on the `Hash` derive: cloning
        // a histogram yields a value that hashes identically to its
        // source. The `Clone` / `Hash` idiom-peer the stdlib's
        // hash-keyed collections lean on (a key inserted by value can
        // be looked up by a clone of itself). Pinned over the
        // axis-cover histogram so every cell carries a positive count
        // and the equality reads off a non-trivial counts vector.
        let original: AxisHistogram<A> = axis_iter::<A>().collect();
        let cloned = original.clone();
        assert_eq!(
            hash_of(&original),
            hash_of(&cloned),
            "clone must preserve hash on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_hash_hashset_roundtrip<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The end-to-end [`HashSet`] round-trip on the `Hash` derive:
        // inserting a histogram into a [`std::collections::HashSet`]
        // and then querying for an independently constructed equal
        // value returns `true`. This pins the (Eq, Hash) consistency
        // through the stdlib hash-keyed collection — not just the
        // raw `Hasher` surface — so the `HashSet<AxisHistogram<A>>`
        // call-site shape on the consumer side reads off correctly
        // for every implementor.
        use std::collections::HashSet;
        let inserted: AxisHistogram<A> = axis_iter::<A>().collect();
        let probe: AxisHistogram<A> = axis_iter::<A>().collect();
        let mut set: HashSet<AxisHistogram<A>> = HashSet::new();
        set.insert(inserted);
        assert!(
            set.contains(&probe),
            "HashSet must recognize an equal histogram by hash on axis {}",
            std::any::type_name::<A>(),
        );
        // Inserting a clone of the probe leaves the set unchanged
        // (deduplication is the canonical `HashSet` invariant — only
        // possible when (Eq, Hash) agree).
        let len_before = set.len();
        set.insert(probe);
        assert_eq!(
            set.len(),
            len_before,
            "HashSet must dedup equal histograms on axis {}",
            std::any::type_name::<A>(),
        );
    }

    #[test]
    fn axis_histogram_equal_implies_same_hash_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_hash_equal_implies_same_hash::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_empty_hashes_consistently_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_hash_empty_is_consistent::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_clone_preserves_hash_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_hash_clone_preserves_hash::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_hashset_roundtrip_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_hash_hashset_roundtrip::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_hashmap_keys_dedup_observation_mixes_for_diff_line_kind() {
        // Concrete pin on the canonical fleet-aggregator call-site
        // shape: a `HashMap<AxisHistogram<DiffLineKind>, usize>`
        // tallies how often each distinct observation mix recurred
        // across a per-window collapse step. Two hosts that landed
        // the same rebuild summary collapse into one bucket; a third
        // host with a different summary lives in a second bucket.
        // Pinned on [`DiffLineKind`] so the per-cell counts read off
        // and the (Eq, Hash) consistency through the stdlib
        // hash-keyed collection is visible at the call site.
        use std::collections::HashMap;

        let host_a: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
        ]
        .into_iter()
        .collect();
        let host_b: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
        ]
        .into_iter()
        .collect();
        let host_c: AxisHistogram<DiffLineKind> = std::iter::once(DiffLineKind::Context).collect();

        // host_a and host_b are pointwise equal — they collapse into
        // one bucket; host_c is distinct.
        assert_eq!(host_a, host_b);
        assert_ne!(host_a, host_c);

        let mut tally: HashMap<AxisHistogram<DiffLineKind>, usize> = HashMap::new();
        for hist in [host_a.clone(), host_b.clone(), host_c.clone()] {
            *tally.entry(hist).or_insert(0) += 1;
        }

        assert_eq!(
            tally.len(),
            2,
            "two distinct observation mixes — two buckets"
        );
        assert_eq!(
            tally.get(&host_a).copied(),
            Some(2),
            "host_a and host_b dedup to one key bucketing both hosts",
        );
        assert_eq!(
            tally.get(&host_c).copied(),
            Some(1),
            "host_c lands in its own bucket",
        );
    }

    // ---- AxisHistogram::clear (in-place reset) trait-uniform laws ----
    //
    // Four trait-uniform laws reach every [`ClosedAxis`] implementor through
    // [`for_each_closed_axis_implementor`] so the per-axis [`AxisHistogram::clear`]
    // projection's contract holds uniformly without per-axis test duplication:
    // `clear` reaches the empty-histogram boundary on every axis cover;
    // `clear` lands pointwise equal to the [`Default`] / [`Self::empty`]
    // monoid identity; `clear` is idempotent under repeated application;
    // `clear` on the already-empty histogram is the identity.

    fn assert_clear_is_empty_after<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The empty-histogram boundary law: after `hist.clear()`, every
        // empty-side predicate reads `true` / zero on the same call site.
        // Pinned over the axis-cover histogram (every cell carries a
        // positive count before the reset) so the boundary transition is
        // visible on every ordinal.
        let mut hist: AxisHistogram<A> = axis_iter::<A>().collect();
        assert!(
            !hist.is_empty(),
            "axis-cover histogram must be non-empty before clear on axis {}",
            std::any::type_name::<A>(),
        );
        hist.clear();
        assert!(
            hist.is_empty(),
            "clear must reach is_empty on axis {}",
            std::any::type_name::<A>(),
        );
        assert_eq!(
            hist.total(),
            0,
            "clear must zero total on axis {}",
            std::any::type_name::<A>(),
        );
        assert_eq!(
            hist.distinct_cells(),
            0,
            "clear must zero distinct_cells on axis {}",
            std::any::type_name::<A>(),
        );
        assert_eq!(
            hist.unobserved_cells(),
            axis_cardinality::<A>(),
            "clear must lift unobserved_cells to axis_cardinality on axis {}",
            std::any::type_name::<A>(),
        );
        for cell in axis_iter::<A>() {
            assert_eq!(
                hist[cell],
                0,
                "clear must zero cell {cell:?} on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_clear_equals_default<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The monoid-identity equivalence law: `clear` lands on the same
        // value as the [`Default`] / [`Self::empty`] constructor — both
        // surfaces reach the all-zero histogram, the in-place form via
        // `clear` and the constructor form via `default`. Pinned over the
        // axis-cover histogram so the pre-state is non-trivial.
        let mut via_clear: AxisHistogram<A> = axis_iter::<A>().collect();
        via_clear.clear();
        assert_eq!(
            via_clear,
            AxisHistogram::<A>::default(),
            "clear must equal Default on axis {}",
            std::any::type_name::<A>(),
        );
        assert_eq!(
            via_clear,
            AxisHistogram::<A>::empty(),
            "clear must equal empty() on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_clear_is_idempotent<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The idempotence law on the in-place-reset surface: a second
        // `clear` after a first one leaves the histogram pointwise
        // unchanged. The fixed-point property every stdlib `clear`
        // carries (the zero state is a fixed point of the operator).
        let mut hist: AxisHistogram<A> = axis_iter::<A>().collect();
        hist.clear();
        let after_one = hist.clone();
        hist.clear();
        assert_eq!(
            hist,
            after_one,
            "clear must be idempotent on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_clear_on_empty_is_identity<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The empty-input identity law on the in-place-reset surface:
        // clearing the already-empty histogram leaves it pointwise
        // unchanged. Peer of the empty-identity law on [`Self::merge`]
        // (`hist.merge(&AxisHistogram::empty()) == hist`) and the
        // empty-iterator law on [`Extend<A>::extend`] — the operator
        // is the identity on the monoid identity.
        let mut hist = AxisHistogram::<A>::empty();
        let before = hist.clone();
        hist.clear();
        assert_eq!(
            hist,
            before,
            "clear on empty must be identity on axis {}",
            std::any::type_name::<A>(),
        );
    }

    #[test]
    fn axis_histogram_clear_is_empty_after_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_clear_is_empty_after::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_clear_equals_default_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_clear_equals_default::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_clear_is_idempotent_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_clear_is_idempotent::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_clear_on_empty_is_identity_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_clear_on_empty_is_identity::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_clear_preserves_backing_capacity_for_diff_line_kind() {
        // Concrete pin on the in-place-reset surface at the rolling-
        // window observatory call-site shape: a per-window
        // `AxisHistogram<DiffLineKind>` tally that absorbs observations
        // through the window, then resets to zero between windows
        // without reallocating. The `Vec::clear`-style capacity-
        // preservation invariant — pinned on a concrete axis so the
        // post-state reads off in named cells, and the backing-store
        // length stays at [`axis_cardinality`] across the reset.
        let mut window: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ]
        .into_iter()
        .collect();

        assert_eq!(window[DiffLineKind::Added], 2);
        assert_eq!(window[DiffLineKind::Removed], 1);
        assert_eq!(window[DiffLineKind::Context], 1);
        assert_eq!(window.total(), 4);

        window.clear();

        // Every named cell reads zero through the operator surface; the
        // typed-empty-histogram boundary is reached.
        assert_eq!(window[DiffLineKind::Added], 0);
        assert_eq!(window[DiffLineKind::Removed], 0);
        assert_eq!(window[DiffLineKind::Context], 0);
        assert_eq!(window.total(), 0);
        assert!(window.is_empty());
        assert_eq!(window, AxisHistogram::<DiffLineKind>::empty());

        // The reset window absorbs the next batch without per-cell
        // re-initialization — the same backing store reads off the new
        // observations directly.
        window.observe(DiffLineKind::Removed);
        window.observe(DiffLineKind::Removed);
        assert_eq!(window[DiffLineKind::Removed], 2);
        assert_eq!(window[DiffLineKind::Added], 0);
        assert_eq!(window.total(), 2);

        // Iterating the reset histogram still walks every cell of the
        // closed axis (length invariance) — `clear` zeroes values,
        // never length.
        let mut fresh = AxisHistogram::<DiffLineKind>::empty();
        fresh.observe(DiffLineKind::Removed);
        fresh.observe(DiffLineKind::Removed);
        assert_eq!(
            window.iter().count(),
            fresh.iter().count(),
            "clear preserves iterator length over the closed axis",
        );
        assert_eq!(
            window, fresh,
            "post-clear absorb reaches the same value as a fresh observe sequence",
        );
    }

    // ---- AxisHistogram::fmt::Display (operator-facing emission) laws ----
    //
    // Four laws reach every [`ClosedAxisLabel`] implementor through
    // [`for_each_closed_axis_label_implementor`] so the per-axis
    // [`Display`] projection's contract holds uniformly without per-axis
    // test duplication: the emission carries exactly
    // [`axis_cardinality::<A>() - 1`] separator substrings; every label
    // substring round-trips through [`axis_from_label`]; the empty
    // histogram emits every cell at `=0`; the labels in the emission
    // appear in declaration order over [`ClosedAxis::ALL`].

    fn assert_display_emits_axis_cardinality_pairs<A>()
    where
        A: ClosedAxisLabel + std::fmt::Debug,
    {
        // The length law on the operator-facing emission: the emitted
        // string contains exactly `axis_cardinality::<A>() - 1` `", "`
        // separator substrings, regardless of the per-cell counts. Pinned
        // over the axis-cover histogram (every cell positive) so a stray
        // `is_first` flag flip would surface as either an extra leading
        // separator or a dropped pair.
        let hist: AxisHistogram<A> = axis_iter::<A>().collect();
        let s = format!("{hist}");
        let cardinality = axis_cardinality::<A>();
        let expected_separators = cardinality.saturating_sub(1);
        let observed_separators = s.matches(", ").count();
        assert_eq!(
            observed_separators,
            expected_separators,
            "axis {} display must carry exactly axis_cardinality - 1 separators (got {observed_separators} in {s:?})",
            std::any::type_name::<A>(),
        );
        // The `=` separator inside each pair appears exactly once per
        // axis cell — `axis_cardinality::<A>()` total occurrences across
        // the emission.
        assert_eq!(
            s.matches('=').count(),
            cardinality,
            "axis {} display must carry exactly axis_cardinality '=' separators (one per cell)",
            std::any::type_name::<A>(),
        );
    }

    fn assert_display_labels_round_trip_through_axis_from_label<A>()
    where
        A: ClosedAxisLabel + std::fmt::Debug,
    {
        // The round-trip law on the operator-facing emission: every
        // `<label>=<count>` pair's label substring parses back to the
        // emitting cell via [`axis_from_label`]. The (Display,
        // axis_from_label) duality on the labeled-axis surface — the
        // emission is the round-trippable form a loader can recover the
        // typed `(cell, count)` pairs from without a custom parser.
        // Pinned over an axis where every cell carries a distinct
        // positive count so the round-trip also recovers count integrity.
        let mut hist = AxisHistogram::<A>::empty();
        for (i, cell) in axis_iter::<A>().enumerate() {
            for _ in 0..=i {
                hist.observe(cell);
            }
        }
        let s = format!("{hist}");
        let parsed: Vec<(A, usize)> = s
            .split(", ")
            .map(|pair| {
                let (label, count) = pair.split_once('=').unwrap_or_else(|| {
                    panic!(
                        "axis {} display pair {pair:?} missing '=' separator",
                        std::any::type_name::<A>(),
                    )
                });
                let cell = axis_from_label::<A>(label).unwrap_or_else(|| {
                    panic!(
                        "axis {} display label {label:?} must parse through axis_from_label",
                        std::any::type_name::<A>(),
                    )
                });
                let count: usize = count.parse().unwrap_or_else(|e| {
                    panic!(
                        "axis {} display count {count:?} must parse as usize: {e}",
                        std::any::type_name::<A>(),
                    )
                });
                (cell, count)
            })
            .collect();
        let original: Vec<(A, usize)> = hist.iter().collect();
        assert_eq!(
            parsed,
            original,
            "axis {} display must round-trip through axis_from_label + usize::parse",
            std::any::type_name::<A>(),
        );
    }

    fn assert_display_empty_emits_zero_for_every_cell<A>()
    where
        A: ClosedAxisLabel + std::fmt::Debug,
    {
        // The empty-histogram emission law: every cell appears in the
        // emission with `=0`. The operator distinguishes "empty
        // observation window" from "axis has no cells" by reading the
        // emitted `=0` cells — the empty string would lose that
        // distinction. Peer of the length law on [`AxisHistogram::iter`]:
        // the iter walks the full axis on the empty histogram, the
        // Display emission emits every cell of that walk.
        let hist = AxisHistogram::<A>::empty();
        let s = format!("{hist}");
        for cell in axis_iter::<A>() {
            let expected = format!("{}=0", cell.as_str());
            assert!(
                s.contains(&expected),
                "axis {} empty display must contain {expected:?} (got {s:?})",
                std::any::type_name::<A>(),
            );
        }
        // Exactly `axis_cardinality::<A>()` `=0` substrings on the empty
        // histogram — every cell is zero, no cell is dropped.
        assert_eq!(
            s.matches("=0").count(),
            axis_cardinality::<A>(),
            "axis {} empty display must carry one =0 per cell",
            std::any::type_name::<A>(),
        );
    }

    fn assert_display_labels_appear_in_declaration_order<A>()
    where
        A: ClosedAxisLabel + std::fmt::Debug,
    {
        // The declaration-order law on the operator-facing emission: the
        // labels appear in the emission in the same order they appear in
        // [`ClosedAxis::ALL`]. Pinned by scanning for each successive
        // cell's label and asserting that the byte offset is
        // monotonically non-decreasing across the iteration. Peer of the
        // declaration-order law on [`AxisHistogram::iter`] — the
        // emission is the labeled-rendering of that walk.
        let hist: AxisHistogram<A> = axis_iter::<A>().collect();
        let s = format!("{hist}");
        let mut prev_end = 0usize;
        for cell in axis_iter::<A>() {
            let label = cell.as_str();
            let offset = s[prev_end..].find(label).unwrap_or_else(|| {
                panic!(
                    "axis {} display must contain label {label:?} after offset {prev_end}",
                    std::any::type_name::<A>(),
                )
            });
            prev_end += offset + label.len();
        }
    }

    #[test]
    fn axis_histogram_display_emits_axis_cardinality_pairs_for_every_closed_axis_label_implementor()
    {
        macro_rules! check {
            ($ty:ident) => {
                assert_display_emits_axis_cardinality_pairs::<$ty>();
            };
        }
        for_each_closed_axis_label_implementor!(check);
    }

    #[test]
    fn axis_histogram_display_labels_round_trip_through_axis_from_label_for_every_closed_axis_label_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_display_labels_round_trip_through_axis_from_label::<$ty>();
            };
        }
        for_each_closed_axis_label_implementor!(check);
    }

    #[test]
    fn axis_histogram_display_empty_emits_zero_for_every_cell_for_every_closed_axis_label_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_display_empty_emits_zero_for_every_cell::<$ty>();
            };
        }
        for_each_closed_axis_label_implementor!(check);
    }

    #[test]
    fn axis_histogram_display_labels_appear_in_declaration_order_for_every_closed_axis_label_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_display_labels_appear_in_declaration_order::<$ty>();
            };
        }
        for_each_closed_axis_label_implementor!(check);
    }

    #[test]
    fn axis_histogram_display_for_diff_line_kind() {
        // Concrete pin on the operator-facing emission at a
        // representative call-site shape: a per-rebuild diff-shape
        // histogram emitted as a single structured-log field carrying
        // the (removed, added, context) distribution. Pins the format
        // literally so a future drift (label-case change, separator
        // tweak, ordering flip) surfaces at the concrete-axis assertion
        // before propagating through the trait-uniform laws above.
        //
        // [`DiffLineKind::ALL`] declaration order is
        // `[Removed, Added, Context]`.
        let hist: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Context,
            DiffLineKind::Context,
            DiffLineKind::Context,
        ]
        .into_iter()
        .collect();

        assert_eq!(format!("{hist}"), "removed=1, added=2, context=3");

        // The empty histogram emits every cell at zero, never the empty
        // string — the operator distinguishes "no observations" from
        // "no axis cells" by reading the `=0` cells.
        let empty = AxisHistogram::<DiffLineKind>::empty();
        assert_eq!(format!("{empty}"), "removed=0, added=0, context=0");

        // Singleton observation reaches the singleton-cell emission with
        // the other cells visibly at zero.
        let singleton = AxisHistogram::<DiffLineKind>::from(DiffLineKind::Added);
        assert_eq!(format!("{singleton}"), "removed=0, added=1, context=0");
    }

    #[test]
    fn axis_histogram_display_total_matches_inherent_for_diff_line_kind() {
        // The total law on the operator-facing emission: summing the
        // per-cell counts parsed off the emission yields the inherent
        // [`AxisHistogram::total`]. Pins the emission preserves the
        // total observation count by construction — every cell
        // contributes its count, no cell drops.
        let hist: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Context,
            DiffLineKind::Context,
            DiffLineKind::Context,
        ]
        .into_iter()
        .collect();
        let s = format!("{hist}");
        let parsed_total: usize = s
            .split(", ")
            .map(|pair| {
                let (_, c) = pair.split_once('=').expect("pair must contain '='");
                c.parse::<usize>().expect("count must parse")
            })
            .sum();
        assert_eq!(
            parsed_total,
            hist.total(),
            "display must preserve total observation count",
        );
    }

    // ---- AxisHistogram FromStr (parse-back) trait-uniform laws ----
    //
    // The canonical Rust stdlib `(Display, FromStr)` round-trip pair on
    // the labeled-axis histogram surface. Pins the parser's
    // round-trip law, accept-Display-output law, missing-cells-default-
    // to-zero law, order-invariance law, empty-input-identity law, and
    // the four typed rejection modes uniformly across every
    // `ClosedAxisLabel` implementor through
    // `for_each_closed_axis_label_implementor!`. The concrete pins on
    // `DiffLineKind` literal-format the parser's accept and reject
    // surfaces so a future drift surfaces at the concrete-axis assertion
    // before propagating through the trait-uniform laws.

    fn assert_display_from_str_round_trip<A>()
    where
        A: ClosedAxisLabel + std::fmt::Debug,
    {
        // The canonical stdlib `(Display, FromStr)` round-trip law on
        // the labeled-axis histogram surface: every histogram parses
        // back through its Display emission to a histogram equal to
        // itself. Pinned over a per-cell-distinct-count histogram so
        // the round-trip also recovers count integrity, not just the
        // axis-cover.
        let mut hist = AxisHistogram::<A>::empty();
        for (i, cell) in axis_iter::<A>().enumerate() {
            for _ in 0..=i {
                hist.observe(cell);
            }
        }
        let s = format!("{hist}");
        let parsed: AxisHistogram<A> = s.parse().unwrap_or_else(|e| {
            panic!(
                "axis {} display must parse back through FromStr: {e}",
                std::any::type_name::<A>(),
            )
        });
        assert_eq!(
            parsed,
            hist,
            "axis {} (Display, FromStr) round-trip must be identity",
            std::any::type_name::<A>(),
        );
    }

    fn assert_from_str_empty_is_empty_histogram<A>()
    where
        A: ClosedAxisLabel + std::fmt::Debug,
    {
        // The empty-input identity law on the parser: the empty input
        // string parses to the empty histogram (every cell at zero).
        // Peer of the empty-histogram emission law on Display — the
        // operator can elide the per-cell zero-emission entirely on the
        // input side without losing the round-trip.
        let parsed: AxisHistogram<A> = "".parse().unwrap_or_else(|e| {
            panic!(
                "axis {} empty input must parse to empty histogram: {e}",
                std::any::type_name::<A>(),
            )
        });
        assert_eq!(
            parsed,
            AxisHistogram::<A>::empty(),
            "axis {} empty input must parse to AxisHistogram::empty",
            std::any::type_name::<A>(),
        );
        assert!(
            parsed.is_empty(),
            "axis {} empty-input parsed histogram must satisfy is_empty",
            std::any::type_name::<A>(),
        );
    }

    fn assert_from_str_empty_display_round_trips_to_empty<A>()
    where
        A: ClosedAxisLabel + std::fmt::Debug,
    {
        // The empty-histogram `(Display, FromStr)` round-trip: the
        // empty histogram's Display emission (every cell at `=0`)
        // parses back to the empty histogram. Pins the round-trip law
        // on the identity element of the histogram monoid.
        let empty = AxisHistogram::<A>::empty();
        let s = format!("{empty}");
        let parsed: AxisHistogram<A> = s.parse().unwrap_or_else(|e| {
            panic!(
                "axis {} empty Display must parse back: {e}",
                std::any::type_name::<A>(),
            )
        });
        assert_eq!(
            parsed,
            empty,
            "axis {} empty Display ↔ FromStr round-trip must be identity",
            std::any::type_name::<A>(),
        );
    }

    fn assert_from_str_rejects_unknown_label<A>()
    where
        A: ClosedAxisLabel + std::fmt::Debug,
    {
        // The unknown-label rejection mode: a label substring that does
        // not match any canonical name on the axis surfaces as
        // `ParseAxisHistogramError::UnknownLabel { label }` carrying the
        // offending substring verbatim. Pinned with a sentinel label
        // (`"__shikumi_unknown_label_sentinel__"`) chosen so it cannot
        // collide with any canonical name (every canonical name on the
        // typescape today is lowercase ASCII without underscores
        // matching the sentinel pattern).
        let sentinel = "__shikumi_unknown_label_sentinel__";
        let input = format!("{sentinel}=1");
        let result: Result<AxisHistogram<A>, ParseAxisHistogramError> = input.parse();
        match result {
            Err(ParseAxisHistogramError::UnknownLabel { label }) => {
                assert_eq!(
                    label,
                    sentinel,
                    "axis {} unknown-label error must carry the offending substring verbatim",
                    std::any::type_name::<A>(),
                );
            }
            other => panic!(
                "axis {} must reject unknown label with UnknownLabel variant, got {other:?}",
                std::any::type_name::<A>(),
            ),
        }
    }

    fn assert_from_str_rejects_missing_equals<A>()
    where
        A: ClosedAxisLabel + std::fmt::Debug,
    {
        // The missing-equals rejection mode: a pair without `=`
        // surfaces as `ParseAxisHistogramError::MissingEquals { pair }`
        // carrying the offending substring verbatim. Pinned with the
        // first axis cell's canonical label as the pair body (a valid
        // label but no `=count` suffix).
        let first_cell = axis_iter::<A>()
            .next()
            .expect("axis must have at least one cell");
        let input = first_cell.as_str().to_owned();
        let result: Result<AxisHistogram<A>, ParseAxisHistogramError> = input.parse();
        match result {
            Err(ParseAxisHistogramError::MissingEquals { pair }) => {
                assert_eq!(
                    pair,
                    input,
                    "axis {} missing-equals error must carry the offending pair verbatim",
                    std::any::type_name::<A>(),
                );
            }
            other => panic!(
                "axis {} must reject missing '=' with MissingEquals variant, got {other:?}",
                std::any::type_name::<A>(),
            ),
        }
    }

    fn assert_from_str_rejects_invalid_count<A>()
    where
        A: ClosedAxisLabel + std::fmt::Debug,
    {
        // The invalid-count rejection mode: a count substring that
        // does not parse as `usize` surfaces as
        // `ParseAxisHistogramError::InvalidCount { label, count }`
        // carrying both the offending count substring and the label
        // it was attached to. Pinned with the first axis cell's
        // canonical label paired with a non-numeric count `"oops"`.
        let first_cell = axis_iter::<A>()
            .next()
            .expect("axis must have at least one cell");
        let label = first_cell.as_str();
        let input = format!("{label}=oops");
        let result: Result<AxisHistogram<A>, ParseAxisHistogramError> = input.parse();
        match result {
            Err(ParseAxisHistogramError::InvalidCount { label: l, count: c }) => {
                assert_eq!(
                    l,
                    label,
                    "axis {} invalid-count error must carry the offending label verbatim",
                    std::any::type_name::<A>(),
                );
                assert_eq!(
                    c,
                    "oops",
                    "axis {} invalid-count error must carry the offending count verbatim",
                    std::any::type_name::<A>(),
                );
            }
            other => panic!(
                "axis {} must reject invalid count with InvalidCount variant, got {other:?}",
                std::any::type_name::<A>(),
            ),
        }
    }

    fn assert_serde_yaml_round_trip<A>()
    where
        A: ClosedAxisLabel + std::fmt::Debug,
    {
        // The canonical serde YAML `(Serialize, Deserialize)` round-trip
        // law on the labeled-axis histogram surface: every histogram
        // serializes to a YAML scalar that deserializes back to a
        // histogram equal to itself. Lowers through the same
        // `(Display, FromStr)` pair the round-trip law above pins, so
        // the serde idiom-peer inherits the round-trip discipline by
        // construction. Pinned over a per-cell-distinct-count histogram
        // so the round-trip also recovers count integrity, not just the
        // axis-cover.
        let mut hist = AxisHistogram::<A>::empty();
        for (i, cell) in axis_iter::<A>().enumerate() {
            for _ in 0..=i {
                hist.observe(cell);
            }
        }
        let yaml = serde_yaml::to_string(&hist).unwrap_or_else(|e| {
            panic!(
                "axis {} must serialize to YAML: {e}",
                std::any::type_name::<A>(),
            )
        });
        let parsed: AxisHistogram<A> = serde_yaml::from_str(&yaml).unwrap_or_else(|e| {
            panic!(
                "axis {} YAML emission must deserialize back: {e}\n  yaml: {yaml:?}",
                std::any::type_name::<A>(),
            )
        });
        assert_eq!(
            parsed,
            hist,
            "axis {} (Serialize, Deserialize) YAML round-trip must be identity",
            std::any::type_name::<A>(),
        );
    }

    fn assert_serde_json_round_trip<A>()
    where
        A: ClosedAxisLabel + std::fmt::Debug,
    {
        // Peer of [`assert_serde_yaml_round_trip`] on the JSON
        // serializer — the same round-trip law lowered through the
        // serde `(Serialize, Deserialize)` pair on every
        // [`ClosedAxisLabel`] implementor, this time over a
        // `serde_json` round-trip. JSON emits the scalar as a quoted
        // string; YAML may emit it as a plain or quoted scalar
        // depending on its escape rules. Both serializers route
        // through `serialize_str` / `deserialize_str` so the round-trip
        // is the same bijection the labeled-axis sub-surface already
        // carries on `(Display, FromStr)`.
        let mut hist = AxisHistogram::<A>::empty();
        for (i, cell) in axis_iter::<A>().enumerate() {
            for _ in 0..=i {
                hist.observe(cell);
            }
        }
        let json = serde_json::to_string(&hist).unwrap_or_else(|e| {
            panic!(
                "axis {} must serialize to JSON: {e}",
                std::any::type_name::<A>(),
            )
        });
        let parsed: AxisHistogram<A> = serde_json::from_str(&json).unwrap_or_else(|e| {
            panic!(
                "axis {} JSON emission must deserialize back: {e}\n  json: {json}",
                std::any::type_name::<A>(),
            )
        });
        assert_eq!(
            parsed,
            hist,
            "axis {} (Serialize, Deserialize) JSON round-trip must be identity",
            std::any::type_name::<A>(),
        );
    }

    fn assert_serde_yaml_empty_round_trip<A>()
    where
        A: ClosedAxisLabel + std::fmt::Debug,
    {
        // The empty-histogram serde round-trip: the empty histogram
        // serializes and deserializes back to the empty histogram —
        // peer of the empty-histogram `(Display, FromStr)` round-trip
        // law pinned by [`assert_from_str_empty_display_round_trips_to_empty`].
        // Pins the round-trip law on the identity element of the
        // histogram monoid under the serde surface.
        let empty = AxisHistogram::<A>::empty();
        let yaml = serde_yaml::to_string(&empty).unwrap_or_else(|e| {
            panic!(
                "axis {} empty must serialize to YAML: {e}",
                std::any::type_name::<A>(),
            )
        });
        let parsed: AxisHistogram<A> = serde_yaml::from_str(&yaml).unwrap_or_else(|e| {
            panic!(
                "axis {} empty YAML emission must deserialize back: {e}\n  yaml: {yaml:?}",
                std::any::type_name::<A>(),
            )
        });
        assert_eq!(
            parsed,
            empty,
            "axis {} empty (Serialize, Deserialize) YAML round-trip must be identity",
            std::any::type_name::<A>(),
        );
    }

    fn assert_serde_yaml_rejects_unknown_label<A>()
    where
        A: ClosedAxisLabel + std::fmt::Debug,
    {
        // The unknown-label rejection mode is inherited by the
        // [`Deserialize`] impl from [`FromStr`]: a YAML scalar carrying
        // a sentinel label that does not match any canonical name on
        // the axis surfaces as a `serde_yaml::Error` whose
        // `Display`-rendering carries the offending substring verbatim
        // through [`ParseAxisHistogramError::UnknownLabel`]'s
        // operator-facing rendering — the same one-line error a
        // [`FromStr`] consumer would see, lifted onto the serde error
        // site without losing the verbatim-label discipline.
        let sentinel = "__shikumi_unknown_label_sentinel__";
        let yaml = format!("\"{sentinel}=1\"\n");
        let result: Result<AxisHistogram<A>, _> = serde_yaml::from_str(&yaml);
        match result {
            Err(e) => {
                let rendered = format!("{e}");
                assert!(
                    rendered.contains(sentinel),
                    "axis {} serde YAML error must carry the unknown sentinel verbatim, got: {rendered}",
                    std::any::type_name::<A>(),
                );
            }
            Ok(other) => panic!(
                "axis {} YAML carrying unknown label must reject, got {other:?}",
                std::any::type_name::<A>(),
            ),
        }
    }

    #[test]
    fn axis_histogram_display_from_str_round_trip_for_every_closed_axis_label_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_display_from_str_round_trip::<$ty>();
            };
        }
        for_each_closed_axis_label_implementor!(check);
    }

    #[test]
    fn axis_histogram_from_str_empty_is_empty_histogram_for_every_closed_axis_label_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_from_str_empty_is_empty_histogram::<$ty>();
            };
        }
        for_each_closed_axis_label_implementor!(check);
    }

    #[test]
    fn axis_histogram_from_str_empty_display_round_trips_to_empty_for_every_closed_axis_label_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_from_str_empty_display_round_trips_to_empty::<$ty>();
            };
        }
        for_each_closed_axis_label_implementor!(check);
    }

    #[test]
    fn axis_histogram_from_str_rejects_unknown_label_for_every_closed_axis_label_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_from_str_rejects_unknown_label::<$ty>();
            };
        }
        for_each_closed_axis_label_implementor!(check);
    }

    #[test]
    fn axis_histogram_from_str_rejects_missing_equals_for_every_closed_axis_label_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_from_str_rejects_missing_equals::<$ty>();
            };
        }
        for_each_closed_axis_label_implementor!(check);
    }

    #[test]
    fn axis_histogram_from_str_rejects_invalid_count_for_every_closed_axis_label_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_from_str_rejects_invalid_count::<$ty>();
            };
        }
        for_each_closed_axis_label_implementor!(check);
    }

    #[test]
    fn axis_histogram_from_str_for_diff_line_kind() {
        // Concrete literal pin on the parser's accept surface for a
        // representative call-site shape — a per-rebuild diff-shape
        // histogram parsed from an operator-supplied attestation
        // manifest field. Pins the format literally so a future drift
        // (case-folding tweak, separator change, default-zero behavior
        // change) surfaces at the concrete-axis assertion before
        // propagating through the trait-uniform laws above.
        //
        // [`DiffLineKind::ALL`] declaration order is
        // `[Removed, Added, Context]`.

        // Round-trip the literal Display emission.
        let parsed: AxisHistogram<DiffLineKind> = "removed=1, added=2, context=3".parse().unwrap();
        let mut expected = AxisHistogram::<DiffLineKind>::empty();
        for _ in 0..1 {
            expected.observe(DiffLineKind::Removed);
        }
        for _ in 0..2 {
            expected.observe(DiffLineKind::Added);
        }
        for _ in 0..3 {
            expected.observe(DiffLineKind::Context);
        }
        assert_eq!(parsed, expected);
        // The round-trip closes both directions: parsed.to_string() ==
        // the input we just parsed from.
        assert_eq!(format!("{parsed}"), "removed=1, added=2, context=3");

        // Empty input parses to the empty histogram.
        let empty: AxisHistogram<DiffLineKind> = "".parse().unwrap();
        assert_eq!(empty, AxisHistogram::<DiffLineKind>::empty());

        // The empty-histogram Display emission round-trips to the empty
        // histogram on this concrete axis.
        let from_zero_emission: AxisHistogram<DiffLineKind> =
            "removed=0, added=0, context=0".parse().unwrap();
        assert_eq!(from_zero_emission, AxisHistogram::<DiffLineKind>::empty());

        // Case-insensitive labels (the trait's `from_canonical_str` is
        // case-insensitive ASCII).
        let case_folded: AxisHistogram<DiffLineKind> =
            "REMOVED=1, Added=2, ConTeXt=3".parse().unwrap();
        assert_eq!(case_folded, expected);
    }

    #[test]
    fn axis_histogram_from_str_is_order_invariant_for_diff_line_kind() {
        // The order-invariance law on the parser: a permuted Display
        // emission parses to the same histogram. The parser
        // accumulates into per-ordinal slots indexed by `axis_ordinal`,
        // so the input order only governs the iteration order, not
        // the produced histogram.
        let canonical: AxisHistogram<DiffLineKind> =
            "removed=1, added=2, context=3".parse().unwrap();
        let permuted_a: AxisHistogram<DiffLineKind> =
            "added=2, context=3, removed=1".parse().unwrap();
        let permuted_b: AxisHistogram<DiffLineKind> =
            "context=3, removed=1, added=2".parse().unwrap();
        assert_eq!(canonical, permuted_a);
        assert_eq!(canonical, permuted_b);
    }

    #[test]
    fn axis_histogram_from_str_missing_labels_default_to_zero_for_diff_line_kind() {
        // The missing-labels-default-to-zero law on the parser: a
        // subset input (some cells elided) produces a histogram with
        // zero on every elided cell. The (elided, =0) duality on the
        // input side.
        let singleton: AxisHistogram<DiffLineKind> = "added=5".parse().unwrap();
        let mut expected = AxisHistogram::<DiffLineKind>::empty();
        for _ in 0..5 {
            expected.observe(DiffLineKind::Added);
        }
        assert_eq!(singleton, expected);
        assert_eq!(singleton.count(DiffLineKind::Removed), 0);
        assert_eq!(singleton.count(DiffLineKind::Context), 0);

        // An (elided cell, explicit =0 cell) pair on the same axis
        // produces the same histogram — pins the duality from the
        // other direction.
        let with_explicit_zero: AxisHistogram<DiffLineKind> =
            "removed=0, added=5, context=0".parse().unwrap();
        assert_eq!(singleton, with_explicit_zero);
    }

    #[test]
    fn axis_histogram_from_str_rejects_duplicate_label_for_diff_line_kind() {
        // The duplicate-label rejection mode: a label appearing more
        // than once in the input surfaces as
        // `ParseAxisHistogramError::DuplicateLabel { label }` carrying
        // the duplicated canonical name verbatim. Two different
        // counts on the same cell name a load-bearing ambiguity the
        // caller resolves upstream — the parser does not silently
        // overwrite or sum.
        let result: Result<AxisHistogram<DiffLineKind>, _> = "added=1, added=2".parse();
        match result {
            Err(ParseAxisHistogramError::DuplicateLabel { label }) => {
                assert_eq!(label, "added");
            }
            other => panic!("must reject duplicate label, got {other:?}"),
        }

        // Case-folding does not change the duplicate-label detection:
        // the parser routes through `axis_ordinal`, not through the
        // raw label substring, so `Added` and `added` collide on the
        // same ordinal and the second occurrence surfaces as a
        // duplicate. The error carries the *second* occurrence's
        // verbatim label (the parser short-circuits on the first
        // duplicate).
        let result: Result<AxisHistogram<DiffLineKind>, _> = "added=1, Added=2".parse();
        match result {
            Err(ParseAxisHistogramError::DuplicateLabel { label }) => {
                assert_eq!(label, "Added");
            }
            other => panic!("must reject case-folded duplicate, got {other:?}"),
        }
    }

    #[test]
    fn parse_axis_histogram_error_display_renders_each_variant() {
        // The operator-facing `Display` on `ParseAxisHistogramError`
        // renders each variant's payload at one site, so a caller
        // formatting the error into a CLI line or a structured-log
        // field reaches a one-line operator-facing rendering without
        // re-deriving the per-variant match.
        let missing = ParseAxisHistogramError::MissingEquals {
            pair: "addedone".to_owned(),
        };
        assert_eq!(
            format!("{missing}"),
            "missing '=' separator in pair \"addedone\"",
        );

        let unknown = ParseAxisHistogramError::UnknownLabel {
            label: "bogus".to_owned(),
        };
        assert_eq!(format!("{unknown}"), "unknown axis label \"bogus\"");

        let invalid = ParseAxisHistogramError::InvalidCount {
            label: "added".to_owned(),
            count: "oops".to_owned(),
        };
        assert_eq!(
            format!("{invalid}"),
            "invalid count \"oops\" for label \"added\" (expected usize)",
        );

        let duplicate = ParseAxisHistogramError::DuplicateLabel {
            label: "added".to_owned(),
        };
        assert_eq!(format!("{duplicate}"), "duplicate label \"added\"");
    }

    #[test]
    fn axis_histogram_serde_yaml_round_trip_for_every_closed_axis_label_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_serde_yaml_round_trip::<$ty>();
            };
        }
        for_each_closed_axis_label_implementor!(check);
    }

    #[test]
    fn axis_histogram_serde_json_round_trip_for_every_closed_axis_label_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_serde_json_round_trip::<$ty>();
            };
        }
        for_each_closed_axis_label_implementor!(check);
    }

    #[test]
    fn axis_histogram_serde_yaml_empty_round_trip_for_every_closed_axis_label_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_serde_yaml_empty_round_trip::<$ty>();
            };
        }
        for_each_closed_axis_label_implementor!(check);
    }

    #[test]
    fn axis_histogram_serde_yaml_rejects_unknown_label_for_every_closed_axis_label_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_serde_yaml_rejects_unknown_label::<$ty>();
            };
        }
        for_each_closed_axis_label_implementor!(check);
    }

    #[test]
    fn axis_histogram_serde_yaml_for_diff_line_kind() {
        // Concrete YAML pin on the serde surface for a representative
        // call-site shape — a per-rebuild diff-shape histogram round-
        // tripped through `serde_yaml` to recover the typed
        // `AxisHistogram<DiffLineKind>` from an operator-supplied
        // attestation manifest field. Pins the literal scalar
        // representation so a future drift in the
        // (Serialize, Deserialize) lowering (a switch from
        // `serialize_str` to a map representation, an emission-format
        // change, a default-zero behavior change on the deserialize
        // side) surfaces at the concrete-axis assertion before
        // propagating through the trait-uniform laws above.
        let mut hist = AxisHistogram::<DiffLineKind>::empty();
        for _ in 0..1 {
            hist.observe(DiffLineKind::Removed);
        }
        for _ in 0..2 {
            hist.observe(DiffLineKind::Added);
        }
        for _ in 0..3 {
            hist.observe(DiffLineKind::Context);
        }

        // The serde emission is exactly the `Display` emission lifted
        // to a YAML scalar — the same `"removed=1, added=2,
        // context=3"` string the `(Display, FromStr)` pair carries.
        // `serde_yaml` may emit the scalar in single-quoted form due
        // to the `=` character; the round-trip law does not depend on
        // the quoting style.
        let yaml = serde_yaml::to_string(&hist).unwrap();
        assert!(
            yaml.contains("removed=1, added=2, context=3"),
            "YAML emission must contain the canonical Display form, got: {yaml}",
        );

        // Round-trip the literal YAML emission back through deserialize.
        let parsed: AxisHistogram<DiffLineKind> = serde_yaml::from_str(&yaml).unwrap();
        assert_eq!(parsed, hist);

        // The accept surface inherits the `(FromStr)` order-invariance
        // and missing-labels-default-to-zero laws on the serde side:
        // an operator-authored YAML manifest can elide zero-cells and
        // permute the pairs.
        let elided: AxisHistogram<DiffLineKind> = serde_yaml::from_str("\"added=5\"\n").unwrap();
        let mut expected_elided = AxisHistogram::<DiffLineKind>::empty();
        for _ in 0..5 {
            expected_elided.observe(DiffLineKind::Added);
        }
        assert_eq!(elided, expected_elided);

        let permuted: AxisHistogram<DiffLineKind> =
            serde_yaml::from_str("\"context=3, removed=1, added=2\"\n").unwrap();
        assert_eq!(permuted, hist);

        // The empty histogram round-trips on YAML.
        let empty = AxisHistogram::<DiffLineKind>::empty();
        let yaml_empty = serde_yaml::to_string(&empty).unwrap();
        let parsed_empty: AxisHistogram<DiffLineKind> = serde_yaml::from_str(&yaml_empty).unwrap();
        assert_eq!(parsed_empty, empty);
    }

    #[test]
    fn axis_histogram_serde_json_for_diff_line_kind() {
        // Peer of `axis_histogram_serde_yaml_for_diff_line_kind` on
        // JSON — the same round-trip lowered through
        // `serde_json::{to_string, from_str}`. JSON emits the scalar
        // as an explicit quoted string, which makes the literal
        // emission shape predictable.
        let mut hist = AxisHistogram::<DiffLineKind>::empty();
        for _ in 0..1 {
            hist.observe(DiffLineKind::Removed);
        }
        for _ in 0..2 {
            hist.observe(DiffLineKind::Added);
        }
        for _ in 0..3 {
            hist.observe(DiffLineKind::Context);
        }

        // JSON emits the histogram as one quoted string scalar.
        let json = serde_json::to_string(&hist).unwrap();
        assert_eq!(json, "\"removed=1, added=2, context=3\"");

        // Round-trip the literal JSON emission back through deserialize.
        let parsed: AxisHistogram<DiffLineKind> = serde_json::from_str(&json).unwrap();
        assert_eq!(parsed, hist);

        // The accept surface inherits the same laws as the YAML peer.
        let elided: AxisHistogram<DiffLineKind> = serde_json::from_str("\"added=5\"").unwrap();
        let mut expected_elided = AxisHistogram::<DiffLineKind>::empty();
        for _ in 0..5 {
            expected_elided.observe(DiffLineKind::Added);
        }
        assert_eq!(elided, expected_elided);
    }

    #[test]
    fn axis_histogram_serde_yaml_unknown_label_error_carries_label_verbatim_for_diff_line_kind() {
        // Concrete pin on the unknown-label rejection mode lifted to
        // the serde error site: a YAML scalar carrying an unknown
        // label surfaces as a `serde_yaml::Error` whose Display
        // rendering carries the offending substring verbatim through
        // the `ParseAxisHistogramError::UnknownLabel` Display
        // rendering routed through `serde::de::Error::custom`. The
        // rendered error string must contain both the offending label
        // substring and the operator-facing rejection phrase
        // (`"unknown axis label"`) the
        // `ParseAxisHistogramError::Display` impl emits.
        let result: Result<AxisHistogram<DiffLineKind>, _> = serde_yaml::from_str("\"bogus=1\"\n");
        let rendered = match result {
            Err(e) => format!("{e}"),
            Ok(other) => panic!("must reject unknown label, got {other:?}"),
        };
        assert!(
            rendered.contains("unknown axis label"),
            "serde error must carry the operator-facing rejection phrase, got: {rendered}",
        );
        assert!(
            rendered.contains("bogus"),
            "serde error must carry the offending label verbatim, got: {rendered}",
        );
    }

    // ---- AxisHistogram::modality_degree trait-uniform laws ----
    //
    // Four trait-uniform laws reach every [`ClosedAxis`] implementor
    // through [`for_each_closed_axis_implementor`] so the per-axis
    // modality_degree projection's contract holds uniformly without
    // per-axis test duplication: empty → (0, 0); singleton → (1, 1);
    // uniform axis-cover → (axis_cardinality, axis_cardinality); and
    // the defining equivalence with the open-coded
    // `(peak_multiplicity(), trough_multiplicity())` pair. Concrete
    // shape pins on the four modality classifier corners follow on
    // [`DiffLineKind`].

    fn assert_modality_degree_empty_is_zero_pair<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        let hist = AxisHistogram::<A>::empty();
        assert_eq!(
            hist.modality_degree(),
            (0, 0),
            "empty histogram modality_degree must be (0, 0) on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_modality_degree_singleton_is_one_pair<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // For every cell of the axis: a histogram built from one
        // observation of that cell has modality_degree = (1, 1). The
        // support has one member, both modal and antimodal level sets
        // are exactly that singleton. Pins the singleton law uniformly
        // across every implementor.
        for observed in axis_iter::<A>() {
            let hist: AxisHistogram<A> = std::iter::once(observed).collect();
            assert_eq!(
                hist.modality_degree(),
                (1, 1),
                "singleton modality_degree must be (1, 1) for observed cell {observed:?} \
                 on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_modality_degree_axis_cover_is_axis_cardinality_pair<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Observing every cell exactly once produces a uniform
        // histogram (every cell at 1, peak == trough == 1); both modal
        // and antimodal level sets equal the entire axis, so
        // modality_degree == (axis_cardinality, axis_cardinality).
        // Pinned uniformly: every closed-axis implementor's uniform
        // axis-cover witnesses the modal/antimodal coincidence on the
        // full support.
        let hist: AxisHistogram<A> = axis_iter::<A>().collect();
        let n = axis_cardinality::<A>();
        assert_eq!(
            hist.modality_degree(),
            (n, n),
            "uniform axis-cover histogram modality_degree must be (n, n) where \
             n = axis_cardinality on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_modality_degree_equals_open_coded_peak_trough_multiplicity_pair<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Defining-equivalence law: modality_degree() is pointwise
        // equal to (peak_multiplicity(), trough_multiplicity()) on
        // every histogram shape — empty, singleton, full axis cover,
        // and (where the axis has at least two variants) a strict
        // two-cell sub-cover with unequal counts that exercises both
        // tied-trough (one) and unique-peak (one) branches. Reached
        // across every implementor through the macro.
        let empty = AxisHistogram::<A>::empty();
        assert_eq!(
            empty.modality_degree(),
            (empty.peak_multiplicity(), empty.trough_multiplicity()),
            "modality_degree must equal the (peak_multiplicity, trough_multiplicity) \
             pair on empty histogram for axis {}",
            std::any::type_name::<A>(),
        );

        for observed in axis_iter::<A>() {
            let singleton: AxisHistogram<A> = std::iter::once(observed).collect();
            assert_eq!(
                singleton.modality_degree(),
                (
                    singleton.peak_multiplicity(),
                    singleton.trough_multiplicity(),
                ),
                "modality_degree must equal the (peak_multiplicity, trough_multiplicity) \
                 pair on singleton {observed:?} for axis {}",
                std::any::type_name::<A>(),
            );
        }

        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        assert_eq!(
            cover.modality_degree(),
            (cover.peak_multiplicity(), cover.trough_multiplicity()),
            "modality_degree must equal the (peak_multiplicity, trough_multiplicity) \
             pair on uniform axis-cover for axis {}",
            std::any::type_name::<A>(),
        );

        // Skewed shape: bump the first cell twice past the second cell
        // (when the axis has at least two variants) to drive a strict
        // peak/trough split. On a singleton axis, the loop body
        // collapses to the singleton case above.
        let mut variants = axis_iter::<A>();
        if let (Some(first), Some(second)) = (variants.next(), variants.next()) {
            let mut skewed = AxisHistogram::<A>::empty();
            skewed.observe(first);
            skewed.observe(first);
            skewed.observe(second);
            assert_eq!(
                skewed.modality_degree(),
                (skewed.peak_multiplicity(), skewed.trough_multiplicity()),
                "modality_degree must equal the (peak_multiplicity, trough_multiplicity) \
                 pair on a strict-peak/strict-trough skewed shape ({first:?} ×2, \
                 {second:?} ×1) for axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    #[test]
    fn axis_histogram_modality_degree_empty_is_zero_pair_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_modality_degree_empty_is_zero_pair::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_modality_degree_singleton_is_one_pair_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_modality_degree_singleton_is_one_pair::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_modality_degree_axis_cover_is_axis_cardinality_pair_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_modality_degree_axis_cover_is_axis_cardinality_pair::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_modality_degree_equals_open_coded_peak_trough_multiplicity_pair_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_modality_degree_equals_open_coded_peak_trough_multiplicity_pair::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_modality_degree_classifies_strictly_unimodal_anti_unimodal_corner() {
        // Modality classifier corner (1, 1): both peak and trough are
        // uniquely held — strictly unimodal and strictly anti-unimodal.
        // The declaration-order tie-break in dominant_cell /
        // recessive_cell is not exercised on either side. Witness:
        // Added ×3, Removed ×2, Context ×1 — three distinct counts,
        // each at exactly one cell, so peak (3) is uniquely at Added
        // and trough (1) is uniquely at Context.
        let input = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ];
        let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
        assert_eq!(hist.count(DiffLineKind::Added), 3);
        assert_eq!(hist.count(DiffLineKind::Removed), 2);
        assert_eq!(hist.count(DiffLineKind::Context), 1);
        assert_eq!(hist.modality_degree(), (1, 1));
    }

    #[test]
    fn axis_histogram_modality_degree_classifies_modally_tied_anti_unimodal_corner() {
        // Modality classifier corner (k, 1) with k >= 2: the peak is
        // shared, the trough is uniquely held. Witness: Added ×2,
        // Removed ×2, Context ×1 — peak (2) tied between Added and
        // Removed, trough (1) uniquely at Context.
        let input = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ];
        let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
        assert_eq!(hist.modality_degree(), (2, 1));
    }

    #[test]
    fn axis_histogram_modality_degree_classifies_strictly_unimodal_antimodally_tied_corner() {
        // Modality classifier corner (1, l) with l >= 2: the peak is
        // uniquely held, the trough is shared. Witness: Added ×3,
        // Removed ×1, Context ×1 — peak (3) uniquely at Added, trough
        // (1) tied between Removed and Context.
        let input = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ];
        let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
        assert_eq!(hist.modality_degree(), (1, 2));
    }

    #[test]
    fn axis_histogram_modality_degree_classifies_modal_antimodal_coincidence_corner() {
        // Modality classifier corner (k, k) with k == distinct_cells():
        // modal/antimodal coincidence — every observed cell sits at
        // both peak and trough, the is_uniform_count shape. Two
        // witnesses: the full uniform axis-cover (3 distinct, each ×1)
        // and a strict sub-cover uniform (2 distinct, each ×2).
        let axis_cover: AxisHistogram<DiffLineKind> = axis_iter::<DiffLineKind>().collect();
        assert!(axis_cover.is_uniform_count());
        let (peak_mult, trough_mult) = axis_cover.modality_degree();
        assert_eq!(peak_mult, trough_mult);
        assert_eq!(peak_mult, axis_cover.distinct_cells());

        let sub_cover_uniform: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Removed,
        ]
        .into_iter()
        .collect();
        assert!(sub_cover_uniform.is_uniform_count());
        assert_eq!(sub_cover_uniform.modality_degree(), (2, 2));
        assert_eq!(
            sub_cover_uniform.modality_degree().0,
            sub_cover_uniform.distinct_cells(),
        );
    }

    #[test]
    fn axis_histogram_modality_degree_observation_order_invariant() {
        // The fused projection is invariant under observation order:
        // permuting the input stream cannot change the modality degree
        // (since the histogram itself is order-invariant). Pinned
        // concretely across three permutations of the same multiset.
        let multiset_a = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ];
        let multiset_b = [
            DiffLineKind::Context,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Added,
        ];
        let multiset_c = [
            DiffLineKind::Removed,
            DiffLineKind::Added,
            DiffLineKind::Context,
            DiffLineKind::Added,
        ];
        let a: AxisHistogram<DiffLineKind> = multiset_a.iter().copied().collect();
        let b: AxisHistogram<DiffLineKind> = multiset_b.iter().copied().collect();
        let c: AxisHistogram<DiffLineKind> = multiset_c.iter().copied().collect();
        assert_eq!(a, b);
        assert_eq!(b, c);
        assert_eq!(a.modality_degree(), b.modality_degree());
        assert_eq!(b.modality_degree(), c.modality_degree());
        assert_eq!(a.modality_degree(), (1, 2));
    }

    #[test]
    fn axis_histogram_modality_degree_after_merge_reflects_combined_counts() {
        // The (merge, modality_degree) composition: the merge of two
        // histograms can transform the modality classifier — Pin a
        // shape where lhs reads (1, 1) at counts (2, 1) on Added and
        // Removed, rhs reads (1, 1) at counts (2, 1) on Context and
        // Added; the merge reads (2, 1) at counts Added×3, Context×2,
        // Removed×1 — Added now strictly dominant, Context the unique
        // middle, Removed the unique trough. Wait — let me recompute:
        // counts are Added=2+1=3, Removed=1+0=1, Context=0+2=2. Peak=3
        // at Added (multiplicity 1), trough=1 at Removed (multiplicity
        // 1). So merged modality_degree = (1, 1) — strictly unimodal
        // both sides. The composition pin: even though neither side
        // alone is strictly unimodal, the merged shape is.
        let lhs: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
        ]
        .into_iter()
        .collect();
        let rhs: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Context,
            DiffLineKind::Context,
            DiffLineKind::Added,
        ]
        .into_iter()
        .collect();
        let merged = lhs.merge(&rhs);
        assert_eq!(merged.count(DiffLineKind::Added), 3);
        assert_eq!(merged.count(DiffLineKind::Context), 2);
        assert_eq!(merged.count(DiffLineKind::Removed), 1);
        assert_eq!(merged.modality_degree(), (1, 1));
    }

    #[test]
    fn axis_histogram_modality_degree_components_bounded_above_by_distinct_cells() {
        // Structural bound: both components are subsets of the
        // observed support, so each is bounded above by
        // distinct_cells. Pin across four shapes (empty, singleton,
        // strict skew, uniform sub-cover).
        let cases: [&[DiffLineKind]; 4] = [
            &[],
            &[DiffLineKind::Context],
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
                DiffLineKind::Removed,
            ],
        ];
        for input in cases {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            let (peak_mult, trough_mult) = hist.modality_degree();
            let support = hist.distinct_cells();
            assert!(
                peak_mult <= support,
                "peak_mult {peak_mult} must be <= distinct_cells {support} on input \
                 of length {}",
                input.len(),
            );
            assert!(
                trough_mult <= support,
                "trough_mult {trough_mult} must be <= distinct_cells {support} on input \
                 of length {}",
                input.len(),
            );
        }
    }

    // ---- AxisHistogram::is_strictly_modally_unique trait-uniform laws ----
    //
    // Four trait-uniform laws reach every [`ClosedAxis`] implementor
    // through [`for_each_closed_axis_implementor`] so the per-axis
    // modal-uniqueness predicate's contract holds uniformly without
    // per-axis test duplication: empty → false; singleton → true;
    // uniform axis-cover → (axis_cardinality == 1); and the defining
    // equivalence with the open-coded `peak_multiplicity() == 1` form.
    // Concrete pins on the multiplicity-classifier shapes, the
    // (has_singular_support ⇒ is_strictly_modally_unique) implication,
    // and the (modality_degree().0 == 1) projection-equality form
    // follow below on [`DiffLineKind`].

    fn assert_is_strictly_modally_unique_empty_is_false<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The empty histogram has peak_multiplicity 0, not 1, so the
        // modal-uniqueness predicate reads false. Empty-boundary peer
        // to [`AxisHistogram::has_singular_support`] also reading
        // false on the empty histogram — the multiplicity-uniqueness
        // boolean surface inherits the empty-boundary convention from
        // [`AxisHistogram::modality_degree`] reading (0, 0).
        let hist = AxisHistogram::<A>::empty();
        assert!(
            !hist.is_strictly_modally_unique(),
            "empty histogram is_strictly_modally_unique must be false on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_is_strictly_modally_unique_singleton_is_true<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // For every cell of the axis: a histogram built from one
        // observation of that cell has peak_multiplicity 1, so the
        // modal-uniqueness predicate reads true uniformly across
        // every implementor. The minimal-nonempty boundary witness on
        // the (is_empty, is_strictly_modally_unique) pair.
        for observed in axis_iter::<A>() {
            let hist: AxisHistogram<A> = std::iter::once(observed).collect();
            assert!(
                hist.is_strictly_modally_unique(),
                "singleton is_strictly_modally_unique must be true for observed cell \
                 {observed:?} on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_is_strictly_modally_unique_axis_cover_iff_cardinality_is_one<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Observing every cell exactly once raises peak_multiplicity
        // to `axis_cardinality::<A>()`, so the modal-uniqueness
        // predicate reads true iff the axis carries exactly one cell.
        // Stated as an equivalence so the law is uniform across the
        // implementor set (every closed-axis primitive in the
        // typescape today carries `axis_cardinality >= 2`, so axis-
        // cover reads false uniformly) without case-splitting on
        // cardinality at the test site.
        let hist: AxisHistogram<A> = axis_iter::<A>().collect();
        assert_eq!(
            hist.is_strictly_modally_unique(),
            axis_cardinality::<A>() == 1,
            "axis-cover is_strictly_modally_unique must equal (axis_cardinality == 1) \
             on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_is_strictly_modally_unique_equals_open_coded_peak_multiplicity_eq_one<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Defining-equivalence law: is_strictly_modally_unique() is
        // pointwise equal to (peak_multiplicity() == 1) on every
        // histogram shape — empty, singleton, full axis cover, and
        // (where the axis has at least two variants) a strict skew
        // that exercises the unique-peak branch. Reached across every
        // implementor through the macro.
        let empty = AxisHistogram::<A>::empty();
        assert_eq!(
            empty.is_strictly_modally_unique(),
            empty.peak_multiplicity() == 1,
            "is_strictly_modally_unique must equal (peak_multiplicity == 1) on empty \
             histogram for axis {}",
            std::any::type_name::<A>(),
        );

        for observed in axis_iter::<A>() {
            let singleton: AxisHistogram<A> = std::iter::once(observed).collect();
            assert_eq!(
                singleton.is_strictly_modally_unique(),
                singleton.peak_multiplicity() == 1,
                "is_strictly_modally_unique must equal (peak_multiplicity == 1) on \
                 singleton {observed:?} for axis {}",
                std::any::type_name::<A>(),
            );
        }

        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        assert_eq!(
            cover.is_strictly_modally_unique(),
            cover.peak_multiplicity() == 1,
            "is_strictly_modally_unique must equal (peak_multiplicity == 1) on uniform \
             axis-cover for axis {}",
            std::any::type_name::<A>(),
        );

        // Skewed shape: bump the first cell twice past the second
        // cell (when the axis has at least two variants) to drive a
        // strictly unique peak at the first cell. On a singleton
        // axis, the loop body collapses to the singleton case above.
        let mut variants = axis_iter::<A>();
        if let (Some(first), Some(second)) = (variants.next(), variants.next()) {
            let mut skewed = AxisHistogram::<A>::empty();
            skewed.observe(first);
            skewed.observe(first);
            skewed.observe(second);
            assert_eq!(
                skewed.is_strictly_modally_unique(),
                skewed.peak_multiplicity() == 1,
                "is_strictly_modally_unique must equal (peak_multiplicity == 1) on a \
                 strict-peak skewed shape ({first:?} x2, {second:?} x1) for axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    #[test]
    fn axis_histogram_is_strictly_modally_unique_empty_is_false_for_every_closed_axis_implementor()
    {
        macro_rules! check {
            ($ty:ident) => {
                assert_is_strictly_modally_unique_empty_is_false::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_is_strictly_modally_unique_singleton_is_true_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_is_strictly_modally_unique_singleton_is_true::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_is_strictly_modally_unique_axis_cover_iff_cardinality_is_one_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_is_strictly_modally_unique_axis_cover_iff_cardinality_is_one::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_is_strictly_modally_unique_equals_open_coded_peak_multiplicity_eq_one_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_is_strictly_modally_unique_equals_open_coded_peak_multiplicity_eq_one::<$ty>(
                );
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_is_strictly_modally_unique_reads_modal_component_of_modality_degree() {
        // Projection-equality form: the predicate reads the modal
        // component of the fused (peak, trough) pair from
        // `modality_degree`. Pin pointwise across the four classifier
        // corners — strictly unimodal-anti-unimodal (1, 1), modally
        // tied-anti-unimodal (k, 1) with k >= 2, strictly unimodal-
        // antimodally tied (1, l) with l >= 2, and modal/antimodal
        // coincidence on a uniform sub-cover (k, k) — so the form
        // holds when the peak is uniquely held (corners 1 and 3 fire
        // the predicate true) and when it is tied (corners 2 and 4
        // read false). All on [`DiffLineKind`].
        let unique_peak_unique_trough = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ];
        let h1: AxisHistogram<DiffLineKind> = unique_peak_unique_trough.iter().copied().collect();
        assert_eq!(h1.modality_degree(), (1, 1));
        assert!(h1.is_strictly_modally_unique());
        assert_eq!(h1.is_strictly_modally_unique(), h1.modality_degree().0 == 1);

        let tied_peak_unique_trough = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ];
        let h2: AxisHistogram<DiffLineKind> = tied_peak_unique_trough.iter().copied().collect();
        assert_eq!(h2.modality_degree(), (2, 1));
        assert!(!h2.is_strictly_modally_unique());
        assert_eq!(h2.is_strictly_modally_unique(), h2.modality_degree().0 == 1);

        let unique_peak_tied_trough = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ];
        let h3: AxisHistogram<DiffLineKind> = unique_peak_tied_trough.iter().copied().collect();
        assert_eq!(h3.modality_degree(), (1, 2));
        assert!(h3.is_strictly_modally_unique());
        assert_eq!(h3.is_strictly_modally_unique(), h3.modality_degree().0 == 1);

        let uniform_sub_cover = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Removed,
        ];
        let h4: AxisHistogram<DiffLineKind> = uniform_sub_cover.iter().copied().collect();
        assert_eq!(h4.modality_degree(), (2, 2));
        assert!(!h4.is_strictly_modally_unique());
        assert_eq!(h4.is_strictly_modally_unique(), h4.modality_degree().0 == 1);
    }

    #[test]
    fn axis_histogram_has_singular_support_implies_is_strictly_modally_unique() {
        // The one-way implication on the singular-support boundary: a
        // single observed cell is the only member of the modal level
        // set, vacuously uniquely held. The converse fails on every
        // strict-peak shape with two or more observed cells (pinned
        // by the unique-peak-tied-trough shape below).
        for observed in [
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ] {
            let hist: AxisHistogram<DiffLineKind> = std::iter::once(observed).collect();
            assert!(hist.has_singular_support());
            assert!(hist.is_strictly_modally_unique());
        }

        // Converse counter-example: strict-peak two-cell shape has a
        // uniquely held peak but support cardinality 2, witnessing
        // the one-way direction of the implication.
        let two_cell = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
        ];
        let hist: AxisHistogram<DiffLineKind> = two_cell.iter().copied().collect();
        assert!(!hist.has_singular_support());
        assert!(hist.is_strictly_modally_unique());
    }

    #[test]
    fn axis_histogram_is_strictly_modally_unique_witnesses_non_empty_when_true() {
        // Contrapositive of (is_empty ⇒ !is_strictly_modally_unique):
        // whenever the modal-uniqueness predicate fires, the
        // histogram is non-empty. The boolean lifts a one-step
        // non-emptiness witness on the strictly-unique-modal-cell
        // side of the histogram.
        let cases: [&[DiffLineKind]; 3] = [
            &[DiffLineKind::Context],
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
                DiffLineKind::Context,
            ],
        ];
        for input in cases {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            assert!(hist.is_strictly_modally_unique());
            assert!(!hist.is_empty());
        }

        // The empty histogram itself: predicate reads false, peer to
        // the modality_degree (0, 0) empty-boundary convention.
        let empty: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
        assert!(empty.is_empty());
        assert!(!empty.is_strictly_modally_unique());
    }

    #[test]
    fn axis_histogram_is_strictly_modally_unique_under_uniform_count_collapses_to_singular_support()
    {
        // Conditional collapse law: when every observed cell shares
        // the same count, the modal level set equals the support, so
        // the uniqueness predicate collapses to the singular-support
        // predicate on the non-empty side. Pinned on three uniform-
        // count shapes (singleton-multi-observation, two-cell uniform
        // sub-cover, full axis cover) — only the singleton shape
        // fires both predicates true; the multi-cell uniform shapes
        // fire both false.
        let singleton_multi = [DiffLineKind::Added, DiffLineKind::Added];
        let h_singleton: AxisHistogram<DiffLineKind> = singleton_multi.iter().copied().collect();
        assert!(h_singleton.is_uniform_count());
        assert!(!h_singleton.is_empty());
        assert_eq!(
            h_singleton.is_strictly_modally_unique(),
            h_singleton.has_singular_support(),
        );
        assert!(h_singleton.is_strictly_modally_unique());

        let two_cell_uniform = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Removed,
        ];
        let h_two: AxisHistogram<DiffLineKind> = two_cell_uniform.iter().copied().collect();
        assert!(h_two.is_uniform_count());
        assert!(!h_two.is_empty());
        assert_eq!(
            h_two.is_strictly_modally_unique(),
            h_two.has_singular_support(),
        );
        assert!(!h_two.is_strictly_modally_unique());

        let cover: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ]
        .into_iter()
        .collect();
        assert!(cover.is_uniform_count());
        assert!(!cover.is_empty());
        assert_eq!(
            cover.is_strictly_modally_unique(),
            cover.has_singular_support(),
        );
        assert!(!cover.is_strictly_modally_unique());
    }

    // ---- AxisHistogram::is_strictly_antimodally_unique trait-uniform laws ----
    //
    // Four trait-uniform laws reach every [`ClosedAxis`] implementor
    // through [`for_each_closed_axis_implementor`] so the per-axis
    // antimodal-uniqueness predicate's contract holds uniformly without
    // per-axis test duplication: empty → false; singleton → true;
    // uniform axis-cover → (axis_cardinality == 1); and the defining
    // equivalence with the open-coded `trough_multiplicity() == 1` form.
    // Concrete pins on the multiplicity-classifier shapes, the
    // (has_singular_support ⇒ is_strictly_antimodally_unique)
    // implication, the (modality_degree().1 == 1) projection-equality
    // form, and the uniform-count collapse to
    // `is_strictly_modally_unique` follow below on [`DiffLineKind`].

    fn assert_is_strictly_antimodally_unique_empty_is_false<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The empty histogram has trough_multiplicity 0, not 1, so the
        // antimodal-uniqueness predicate reads false. Empty-boundary
        // peer to [`AxisHistogram::is_strictly_modally_unique`] also
        // reading false on the empty histogram — the multiplicity-
        // uniqueness boolean *pair* inherits the empty-boundary
        // convention from [`AxisHistogram::modality_degree`] reading
        // (0, 0) at one site.
        let hist = AxisHistogram::<A>::empty();
        assert!(
            !hist.is_strictly_antimodally_unique(),
            "empty histogram is_strictly_antimodally_unique must be false on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_is_strictly_antimodally_unique_singleton_is_true<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // For every cell of the axis: a histogram built from one
        // observation of that cell has trough_multiplicity 1, so the
        // antimodal-uniqueness predicate reads true uniformly across
        // every implementor. The minimal-nonempty boundary witness on
        // the (is_empty, is_strictly_antimodally_unique) pair, peer to
        // the identical convention on
        // [`AxisHistogram::is_strictly_modally_unique`] so the
        // uniqueness pair reads `(true, true)` uniformly on every
        // singleton.
        for observed in axis_iter::<A>() {
            let hist: AxisHistogram<A> = std::iter::once(observed).collect();
            assert!(
                hist.is_strictly_antimodally_unique(),
                "singleton is_strictly_antimodally_unique must be true for observed cell \
                 {observed:?} on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_is_strictly_antimodally_unique_axis_cover_iff_cardinality_is_one<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Observing every cell exactly once raises trough_multiplicity
        // to `axis_cardinality::<A>()`, so the antimodal-uniqueness
        // predicate reads true iff the axis carries exactly one cell.
        // Stated as an equivalence so the law is uniform across the
        // implementor set (every closed-axis primitive in the
        // typescape today carries `axis_cardinality >= 2`, so axis-
        // cover reads false uniformly) without case-splitting on
        // cardinality at the test site. Peer to the identical law on
        // [`AxisHistogram::is_strictly_modally_unique`].
        let hist: AxisHistogram<A> = axis_iter::<A>().collect();
        assert_eq!(
            hist.is_strictly_antimodally_unique(),
            axis_cardinality::<A>() == 1,
            "axis-cover is_strictly_antimodally_unique must equal (axis_cardinality == 1) \
             on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_is_strictly_antimodally_unique_equals_open_coded_trough_multiplicity_eq_one<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Defining-equivalence law: is_strictly_antimodally_unique()
        // is pointwise equal to (trough_multiplicity() == 1) on every
        // histogram shape — empty, singleton, full axis cover, and
        // (where the axis has at least two variants) a strict-trough
        // skew that exercises the unique-trough branch. Reached
        // across every implementor through the macro.
        let empty = AxisHistogram::<A>::empty();
        assert_eq!(
            empty.is_strictly_antimodally_unique(),
            empty.trough_multiplicity() == 1,
            "is_strictly_antimodally_unique must equal (trough_multiplicity == 1) on empty \
             histogram for axis {}",
            std::any::type_name::<A>(),
        );

        for observed in axis_iter::<A>() {
            let singleton: AxisHistogram<A> = std::iter::once(observed).collect();
            assert_eq!(
                singleton.is_strictly_antimodally_unique(),
                singleton.trough_multiplicity() == 1,
                "is_strictly_antimodally_unique must equal (trough_multiplicity == 1) on \
                 singleton {observed:?} for axis {}",
                std::any::type_name::<A>(),
            );
        }

        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        assert_eq!(
            cover.is_strictly_antimodally_unique(),
            cover.trough_multiplicity() == 1,
            "is_strictly_antimodally_unique must equal (trough_multiplicity == 1) on uniform \
             axis-cover for axis {}",
            std::any::type_name::<A>(),
        );

        // Skewed shape: observe the first cell twice and the second
        // cell once (when the axis has at least two variants) to drive
        // a strictly unique trough at the second cell. On a singleton
        // axis, the loop body collapses to the singleton case above.
        let mut variants = axis_iter::<A>();
        if let (Some(first), Some(second)) = (variants.next(), variants.next()) {
            let mut skewed = AxisHistogram::<A>::empty();
            skewed.observe(first);
            skewed.observe(first);
            skewed.observe(second);
            assert_eq!(
                skewed.is_strictly_antimodally_unique(),
                skewed.trough_multiplicity() == 1,
                "is_strictly_antimodally_unique must equal (trough_multiplicity == 1) on a \
                 strict-trough skewed shape ({first:?} x2, {second:?} x1) for axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    #[test]
    fn axis_histogram_is_strictly_antimodally_unique_empty_is_false_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_is_strictly_antimodally_unique_empty_is_false::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_is_strictly_antimodally_unique_singleton_is_true_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_is_strictly_antimodally_unique_singleton_is_true::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_is_strictly_antimodally_unique_axis_cover_iff_cardinality_is_one_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_is_strictly_antimodally_unique_axis_cover_iff_cardinality_is_one::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_is_strictly_antimodally_unique_equals_open_coded_trough_multiplicity_eq_one_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_is_strictly_antimodally_unique_equals_open_coded_trough_multiplicity_eq_one::<
                    $ty,
                >();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_is_strictly_antimodally_unique_reads_antimodal_component_of_modality_degree()
    {
        // Projection-equality form: the predicate reads the antimodal
        // component of the fused (peak, trough) pair from
        // `modality_degree`. Pin pointwise across the four classifier
        // corners — strictly unimodal-anti-unimodal (1, 1), modally
        // tied-anti-unimodal (k, 1) with k >= 2, strictly unimodal-
        // antimodally tied (1, l) with l >= 2, and modal/antimodal
        // coincidence on a uniform sub-cover (k, k) — so the form
        // holds when the trough is uniquely held (corners 1 and 2 fire
        // the predicate true) and when it is tied (corners 3 and 4
        // read false). All on [`DiffLineKind`].
        let unique_peak_unique_trough = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ];
        let h1: AxisHistogram<DiffLineKind> = unique_peak_unique_trough.iter().copied().collect();
        assert_eq!(h1.modality_degree(), (1, 1));
        assert!(h1.is_strictly_antimodally_unique());
        assert_eq!(
            h1.is_strictly_antimodally_unique(),
            h1.modality_degree().1 == 1,
        );

        let tied_peak_unique_trough = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ];
        let h2: AxisHistogram<DiffLineKind> = tied_peak_unique_trough.iter().copied().collect();
        assert_eq!(h2.modality_degree(), (2, 1));
        assert!(h2.is_strictly_antimodally_unique());
        assert_eq!(
            h2.is_strictly_antimodally_unique(),
            h2.modality_degree().1 == 1,
        );

        let unique_peak_tied_trough = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ];
        let h3: AxisHistogram<DiffLineKind> = unique_peak_tied_trough.iter().copied().collect();
        assert_eq!(h3.modality_degree(), (1, 2));
        assert!(!h3.is_strictly_antimodally_unique());
        assert_eq!(
            h3.is_strictly_antimodally_unique(),
            h3.modality_degree().1 == 1,
        );

        let uniform_sub_cover = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Removed,
        ];
        let h4: AxisHistogram<DiffLineKind> = uniform_sub_cover.iter().copied().collect();
        assert_eq!(h4.modality_degree(), (2, 2));
        assert!(!h4.is_strictly_antimodally_unique());
        assert_eq!(
            h4.is_strictly_antimodally_unique(),
            h4.modality_degree().1 == 1,
        );
    }

    #[test]
    fn axis_histogram_has_singular_support_implies_is_strictly_antimodally_unique() {
        // The one-way implication on the singular-support boundary: a
        // single observed cell is the only member of the antimodal
        // level set, vacuously uniquely held. The converse fails on
        // every strict-trough shape with two or more observed cells
        // (pinned by the unique-peak-unique-trough two-cell shape
        // below).
        for observed in [
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ] {
            let hist: AxisHistogram<DiffLineKind> = std::iter::once(observed).collect();
            assert!(hist.has_singular_support());
            assert!(hist.is_strictly_antimodally_unique());
        }

        // Converse counter-example: strict-trough two-cell shape has a
        // uniquely held trough but support cardinality 2, witnessing
        // the one-way direction of the implication.
        let two_cell = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
        ];
        let hist: AxisHistogram<DiffLineKind> = two_cell.iter().copied().collect();
        assert!(!hist.has_singular_support());
        assert!(hist.is_strictly_antimodally_unique());
    }

    #[test]
    fn axis_histogram_is_strictly_antimodally_unique_witnesses_non_empty_when_true() {
        // Contrapositive of (is_empty ⇒
        // !is_strictly_antimodally_unique): whenever the antimodal-
        // uniqueness predicate fires, the histogram is non-empty. The
        // boolean lifts a one-step non-emptiness witness on the
        // strictly-unique-antimodal-cell side of the histogram.
        let cases: [&[DiffLineKind]; 3] = [
            &[DiffLineKind::Context],
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
                DiffLineKind::Removed,
                DiffLineKind::Context,
            ],
        ];
        for input in cases {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            assert!(hist.is_strictly_antimodally_unique());
            assert!(!hist.is_empty());
        }

        // The empty histogram itself: predicate reads false, peer to
        // the modality_degree (0, 0) empty-boundary convention.
        let empty: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
        assert!(empty.is_empty());
        assert!(!empty.is_strictly_antimodally_unique());
    }

    #[test]
    fn axis_histogram_is_strictly_antimodally_unique_under_uniform_count_collapses_to_singular_support()
     {
        // Conditional collapse law: when every observed cell shares
        // the same count, the antimodal level set equals the support,
        // so the uniqueness predicate collapses to the singular-
        // support predicate on the non-empty side. Pinned on three
        // uniform-count shapes (singleton-multi-observation, two-cell
        // uniform sub-cover, full axis cover) — only the singleton
        // shape fires both predicates true; the multi-cell uniform
        // shapes fire both false.
        let singleton_multi = [DiffLineKind::Added, DiffLineKind::Added];
        let h_singleton: AxisHistogram<DiffLineKind> = singleton_multi.iter().copied().collect();
        assert!(h_singleton.is_uniform_count());
        assert!(!h_singleton.is_empty());
        assert_eq!(
            h_singleton.is_strictly_antimodally_unique(),
            h_singleton.has_singular_support(),
        );
        assert!(h_singleton.is_strictly_antimodally_unique());

        let two_cell_uniform = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Removed,
        ];
        let h_two: AxisHistogram<DiffLineKind> = two_cell_uniform.iter().copied().collect();
        assert!(h_two.is_uniform_count());
        assert!(!h_two.is_empty());
        assert_eq!(
            h_two.is_strictly_antimodally_unique(),
            h_two.has_singular_support(),
        );
        assert!(!h_two.is_strictly_antimodally_unique());

        let cover: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ]
        .into_iter()
        .collect();
        assert!(cover.is_uniform_count());
        assert!(!cover.is_empty());
        assert_eq!(
            cover.is_strictly_antimodally_unique(),
            cover.has_singular_support(),
        );
        assert!(!cover.is_strictly_antimodally_unique());
    }

    #[test]
    fn axis_histogram_uniqueness_pair_collapses_on_uniform_count_non_empty() {
        // On every non-empty uniformly-observed-count histogram, the
        // modal and antimodal level sets coincide with the observed
        // support, so the two uniqueness predicates collapse to the
        // same `has_singular_support()` value — both `true` on every
        // singleton-support shape, both `false` on every multi-cell
        // uniform shape. Pins the boolean-pair equality
        // `is_strictly_modally_unique == is_strictly_antimodally_unique`
        // off the
        // `dominant_cell() == recessive_cell()` collapse already
        // documented on the uniform-count surface.
        let singleton_multi = [DiffLineKind::Removed, DiffLineKind::Removed];
        let h_singleton: AxisHistogram<DiffLineKind> = singleton_multi.iter().copied().collect();
        assert!(h_singleton.is_uniform_count());
        assert!(!h_singleton.is_empty());
        assert_eq!(
            h_singleton.is_strictly_modally_unique(),
            h_singleton.is_strictly_antimodally_unique(),
        );
        assert!(h_singleton.is_strictly_modally_unique());
        assert!(h_singleton.is_strictly_antimodally_unique());

        let two_cell_uniform = [DiffLineKind::Added, DiffLineKind::Removed];
        let h_two: AxisHistogram<DiffLineKind> = two_cell_uniform.iter().copied().collect();
        assert!(h_two.is_uniform_count());
        assert!(!h_two.is_empty());
        assert_eq!(
            h_two.is_strictly_modally_unique(),
            h_two.is_strictly_antimodally_unique(),
        );
        assert!(!h_two.is_strictly_modally_unique());
        assert!(!h_two.is_strictly_antimodally_unique());

        let cover: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ]
        .into_iter()
        .collect();
        assert!(cover.is_uniform_count());
        assert!(!cover.is_empty());
        assert_eq!(
            cover.is_strictly_modally_unique(),
            cover.is_strictly_antimodally_unique(),
        );
        assert!(!cover.is_strictly_modally_unique());
        assert!(!cover.is_strictly_antimodally_unique());
    }

    // ---- AxisHistogram::is_modally_tied trait-uniform laws ----
    //
    // Four trait-uniform laws reach every [`ClosedAxis`] implementor
    // through [`for_each_closed_axis_implementor`] so the per-axis
    // modal-tie predicate's contract holds uniformly without per-axis
    // test duplication: empty → false; singleton → false; uniform axis-
    // cover → (axis_cardinality >= 2); and the defining equivalence
    // with the open-coded `peak_multiplicity() >= 2` form. Concrete
    // projection-equality, partition-with-strict-uniqueness, non-
    // emptiness witness, and uniform-count collapse pins follow below
    // on [`DiffLineKind`].

    fn assert_is_modally_tied_empty_is_false<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The empty histogram has peak_multiplicity 0 (the inequality
        // `0 >= 2` fails), so the modal-tie predicate reads false.
        // Empty-boundary peer to
        // [`AxisHistogram::is_strictly_modally_unique`] also reading
        // false on the empty histogram — the modal-classification
        // boolean *pair* `(is_strictly_modally_unique, is_modally_tied)`
        // reads (false, false) uniformly on the empty boundary at one
        // site, inherited from
        // [`AxisHistogram::peak_multiplicity`] reading 0.
        let hist = AxisHistogram::<A>::empty();
        assert!(
            !hist.is_modally_tied(),
            "empty histogram is_modally_tied must be false on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_is_modally_tied_singleton_is_false<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // For every cell of the axis: a histogram built from one
        // observation of that cell has peak_multiplicity 1 (the lone
        // observed cell stands alone at its own peak), so the modal-
        // tie predicate reads false uniformly across every
        // implementor. The minimal-nonempty boundary witness for the
        // strict modal partition: on every singleton the peak is
        // uniquely held, so the tie-break is structurally not
        // exercised. Peer to the identical convention on
        // [`AxisHistogram::is_strictly_modally_unique`] reading true
        // on every singleton, so the modal-classification pair reads
        // (true, false) uniformly on every singleton.
        for observed in axis_iter::<A>() {
            let hist: AxisHistogram<A> = std::iter::once(observed).collect();
            assert!(
                !hist.is_modally_tied(),
                "singleton is_modally_tied must be false for observed cell \
                 {observed:?} on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_is_modally_tied_axis_cover_iff_cardinality_at_least_two<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Observing every cell exactly once raises peak_multiplicity
        // to `axis_cardinality::<A>()`, so the modal-tie predicate
        // reads true iff the axis carries two or more cells. Stated as
        // an equivalence so the law is uniform across the implementor
        // set (every closed-axis primitive in the typescape today
        // carries `axis_cardinality >= 2`, so axis-cover reads true
        // uniformly) without case-splitting on cardinality at the
        // test site. Peer to the dual law on
        // [`AxisHistogram::is_strictly_modally_unique`] which reads
        // true iff `axis_cardinality::<A>() == 1` — the two laws
        // together pin the strict-modal partition on the axis-cover
        // shape across every implementor.
        let hist: AxisHistogram<A> = axis_iter::<A>().collect();
        assert_eq!(
            hist.is_modally_tied(),
            axis_cardinality::<A>() >= 2,
            "axis-cover is_modally_tied must equal (axis_cardinality >= 2) \
             on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_is_modally_tied_equals_open_coded_peak_multiplicity_ge_two<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Defining-equivalence law: is_modally_tied() is pointwise
        // equal to (peak_multiplicity() >= 2) on every histogram shape —
        // empty, singleton, full axis cover, and (where the axis has
        // at least two variants) a tied-modal sub-cover that
        // exercises the shared-peak branch. Reached across every
        // implementor through the macro.
        let empty = AxisHistogram::<A>::empty();
        assert_eq!(
            empty.is_modally_tied(),
            empty.peak_multiplicity() >= 2,
            "is_modally_tied must equal (peak_multiplicity >= 2) on empty \
             histogram for axis {}",
            std::any::type_name::<A>(),
        );

        for observed in axis_iter::<A>() {
            let singleton: AxisHistogram<A> = std::iter::once(observed).collect();
            assert_eq!(
                singleton.is_modally_tied(),
                singleton.peak_multiplicity() >= 2,
                "is_modally_tied must equal (peak_multiplicity >= 2) on \
                 singleton {observed:?} for axis {}",
                std::any::type_name::<A>(),
            );
        }

        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        assert_eq!(
            cover.is_modally_tied(),
            cover.peak_multiplicity() >= 2,
            "is_modally_tied must equal (peak_multiplicity >= 2) on uniform \
             axis-cover for axis {}",
            std::any::type_name::<A>(),
        );

        // Tied sub-cover: observe the first two cells once each (when
        // the axis has at least two variants) to drive a shared peak
        // at multiplicity 2. On a singleton axis, the loop body
        // collapses to the singleton case above.
        let mut variants = axis_iter::<A>();
        if let (Some(first), Some(second)) = (variants.next(), variants.next()) {
            let mut tied = AxisHistogram::<A>::empty();
            tied.observe(first);
            tied.observe(second);
            assert_eq!(
                tied.is_modally_tied(),
                tied.peak_multiplicity() >= 2,
                "is_modally_tied must equal (peak_multiplicity >= 2) on a \
                 tied-modal sub-cover ({first:?} x1, {second:?} x1) for axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    #[test]
    fn axis_histogram_is_modally_tied_empty_is_false_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_is_modally_tied_empty_is_false::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_is_modally_tied_singleton_is_false_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_is_modally_tied_singleton_is_false::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_is_modally_tied_axis_cover_iff_cardinality_at_least_two_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_is_modally_tied_axis_cover_iff_cardinality_at_least_two::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_is_modally_tied_equals_open_coded_peak_multiplicity_ge_two_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_is_modally_tied_equals_open_coded_peak_multiplicity_ge_two::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_is_modally_tied_reads_modal_component_of_modality_degree() {
        // Projection-equality form: the predicate reads the modal
        // component of the fused (peak, trough) pair from
        // `modality_degree`. Pin pointwise across the four classifier
        // corners — strictly unimodal-anti-unimodal (1, 1), modally
        // tied-anti-unimodal (k, 1) with k >= 2, strictly unimodal-
        // antimodally tied (1, l) with l >= 2, and modal/antimodal
        // coincidence on a uniform sub-cover (k, k) — so the form
        // holds when the peak is shared (corners 2 and 4 fire the
        // predicate true) and when it is uniquely held (corners 1 and
        // 3 read false). All on [`DiffLineKind`].
        let unique_peak_unique_trough = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ];
        let h1: AxisHistogram<DiffLineKind> = unique_peak_unique_trough.iter().copied().collect();
        assert_eq!(h1.modality_degree(), (1, 1));
        assert!(!h1.is_modally_tied());
        assert_eq!(h1.is_modally_tied(), h1.modality_degree().0 >= 2);

        let tied_peak_unique_trough = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ];
        let h2: AxisHistogram<DiffLineKind> = tied_peak_unique_trough.iter().copied().collect();
        assert_eq!(h2.modality_degree(), (2, 1));
        assert!(h2.is_modally_tied());
        assert_eq!(h2.is_modally_tied(), h2.modality_degree().0 >= 2);

        let unique_peak_tied_trough = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ];
        let h3: AxisHistogram<DiffLineKind> = unique_peak_tied_trough.iter().copied().collect();
        assert_eq!(h3.modality_degree(), (1, 2));
        assert!(!h3.is_modally_tied());
        assert_eq!(h3.is_modally_tied(), h3.modality_degree().0 >= 2);

        let uniform_sub_cover = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Removed,
        ];
        let h4: AxisHistogram<DiffLineKind> = uniform_sub_cover.iter().copied().collect();
        assert_eq!(h4.modality_degree(), (2, 2));
        assert!(h4.is_modally_tied());
        assert_eq!(h4.is_modally_tied(), h4.modality_degree().0 >= 2);
    }

    #[test]
    fn axis_histogram_is_modally_tied_strictly_partitions_modal_axis_on_non_empty() {
        // The strict-modal partition law: on every non-empty
        // histogram, exactly one of (is_strictly_modally_unique,
        // is_modally_tied) fires — the peak is either uniquely held or
        // shared, never both, and never neither. The non-empty XOR
        // pinned across the canonical modal shapes (singleton-multi-
        // observation, strict-peak two-cell, tied-peak two-cell,
        // three-way tied). The empty boundary breaks the equivalence:
        // both predicates read false there.
        let cases: [&[DiffLineKind]; 4] = [
            // singleton-multi-observation: peak_multiplicity == 1
            &[DiffLineKind::Added, DiffLineKind::Added],
            // strict-peak two-cell: peak_multiplicity == 1
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
            // tied-peak two-cell: peak_multiplicity == 2
            &[DiffLineKind::Added, DiffLineKind::Removed],
            // three-way uniform: peak_multiplicity == 3
            &[
                DiffLineKind::Added,
                DiffLineKind::Removed,
                DiffLineKind::Context,
            ],
        ];
        for input in cases {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            assert!(!hist.is_empty());
            assert_ne!(
                hist.is_strictly_modally_unique(),
                hist.is_modally_tied(),
                "non-empty histogram must fire exactly one of \
                 (is_strictly_modally_unique, is_modally_tied) on input of length {}",
                input.len(),
            );
            assert_eq!(
                hist.is_modally_tied(),
                !hist.is_strictly_modally_unique(),
                "is_modally_tied must equal !is_strictly_modally_unique on \
                 non-empty input of length {}",
                input.len(),
            );
        }

        // The empty histogram boundary: both predicates read false,
        // breaking the XOR equivalence — the strict partition holds
        // only on the non-empty side of the histogram surface.
        let empty: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
        assert!(empty.is_empty());
        assert!(!empty.is_strictly_modally_unique());
        assert!(!empty.is_modally_tied());
    }

    #[test]
    fn axis_histogram_is_modally_tied_witnesses_non_empty_when_true() {
        // Contrapositive of (is_empty ⇒ !is_modally_tied): whenever
        // the modal-tie predicate fires, the histogram is non-empty.
        // The boolean lifts a one-step non-emptiness witness on the
        // tied-modal side, peer to the same witness on the strictly-
        // modally-unique side.
        let cases: [&[DiffLineKind]; 3] = [
            &[DiffLineKind::Added, DiffLineKind::Removed],
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
                DiffLineKind::Removed,
            ],
            &[
                DiffLineKind::Added,
                DiffLineKind::Removed,
                DiffLineKind::Context,
            ],
        ];
        for input in cases {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            assert!(hist.is_modally_tied());
            assert!(!hist.is_empty());
        }

        // The empty histogram itself: predicate reads false, peer to
        // the peak_multiplicity (0) empty-boundary convention.
        let empty: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
        assert!(empty.is_empty());
        assert!(!empty.is_modally_tied());
    }

    #[test]
    fn axis_histogram_has_singular_support_implies_not_is_modally_tied() {
        // The one-way implication on the singular-support boundary: a
        // single observed cell is the only member of the modal level
        // set, so the tie predicate never fires on a singleton-
        // support histogram. The contrapositive (is_modally_tied ⇒
        // !has_singular_support) lifts a one-step multi-cell-support
        // witness off the tied-modal side: a fired tie predicate
        // means at least two observed cells.
        for observed in [
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ] {
            let hist: AxisHistogram<DiffLineKind> = std::iter::once(observed).collect();
            assert!(hist.has_singular_support());
            assert!(!hist.is_modally_tied());
        }

        // Tied-modal two-cell shape witnesses the contrapositive:
        // is_modally_tied is true, has_singular_support is false.
        let two_cell_tied: AxisHistogram<DiffLineKind> =
            [DiffLineKind::Added, DiffLineKind::Removed]
                .into_iter()
                .collect();
        assert!(two_cell_tied.is_modally_tied());
        assert!(!two_cell_tied.has_singular_support());
    }

    #[test]
    fn axis_histogram_is_modally_tied_under_uniform_count_collapses_to_multi_cell_support() {
        // Conditional collapse law: when every observed cell shares
        // the same count, the modal level set equals the support, so
        // the tie predicate collapses to (!has_singular_support()) on
        // the non-empty side. Pinned on three uniform-count shapes
        // (singleton-multi-observation, two-cell uniform sub-cover,
        // full axis cover) — only the singleton shape fires both
        // predicates false; the multi-cell uniform shapes fire both
        // true.
        let singleton_multi = [DiffLineKind::Added, DiffLineKind::Added];
        let h_singleton: AxisHistogram<DiffLineKind> = singleton_multi.iter().copied().collect();
        assert!(h_singleton.is_uniform_count());
        assert!(!h_singleton.is_empty());
        assert_eq!(
            h_singleton.is_modally_tied(),
            !h_singleton.has_singular_support(),
        );
        assert!(!h_singleton.is_modally_tied());

        let two_cell_uniform = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Removed,
        ];
        let h_two: AxisHistogram<DiffLineKind> = two_cell_uniform.iter().copied().collect();
        assert!(h_two.is_uniform_count());
        assert!(!h_two.is_empty());
        assert_eq!(h_two.is_modally_tied(), !h_two.has_singular_support(),);
        assert!(h_two.is_modally_tied());

        let cover: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ]
        .into_iter()
        .collect();
        assert!(cover.is_uniform_count());
        assert!(!cover.is_empty());
        assert_eq!(cover.is_modally_tied(), !cover.has_singular_support(),);
        assert!(cover.is_modally_tied());
    }

    // ---- AxisHistogram::is_antimodally_tied trait-uniform laws ----
    //
    // Four trait-uniform laws reach every [`ClosedAxis`] implementor
    // through [`for_each_closed_axis_implementor`] so the per-axis
    // antimodal-tie predicate's contract holds uniformly without per-
    // axis test duplication: empty → false; singleton → false; uniform
    // axis-cover → (axis_cardinality >= 2); and the defining
    // equivalence with the open-coded `trough_multiplicity() >= 2`
    // form. Concrete projection-equality, partition-with-strict-
    // uniqueness, non-emptiness witness, has_singular_support
    // implication, and uniform-count collapse pins follow below on
    // [`DiffLineKind`].

    fn assert_is_antimodally_tied_empty_is_false<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The empty histogram has trough_multiplicity 0 (the inequality
        // `0 >= 2` fails), so the antimodal-tie predicate reads false.
        // Empty-boundary peer to
        // [`AxisHistogram::is_strictly_antimodally_unique`] also reading
        // false on the empty histogram — the antimodal-classification
        // boolean *pair* `(is_strictly_antimodally_unique,
        // is_antimodally_tied)` reads (false, false) uniformly on the
        // empty boundary at one site, inherited from
        // [`AxisHistogram::trough_multiplicity`] reading 0.
        let hist = AxisHistogram::<A>::empty();
        assert!(
            !hist.is_antimodally_tied(),
            "empty histogram is_antimodally_tied must be false on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_is_antimodally_tied_singleton_is_false<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // For every cell of the axis: a histogram built from one
        // observation of that cell has trough_multiplicity 1 (the lone
        // observed cell stands alone at its own trough — peak and
        // trough coincide on a singleton-support shape), so the
        // antimodal-tie predicate reads false uniformly across every
        // implementor. The minimal-nonempty boundary witness for the
        // strict antimodal partition: on every singleton the trough is
        // uniquely held, so the tie-break is structurally not
        // exercised. Peer to the identical convention on
        // [`AxisHistogram::is_strictly_antimodally_unique`] reading
        // true on every singleton, so the antimodal-classification
        // pair reads (true, false) uniformly on every singleton.
        for observed in axis_iter::<A>() {
            let hist: AxisHistogram<A> = std::iter::once(observed).collect();
            assert!(
                !hist.is_antimodally_tied(),
                "singleton is_antimodally_tied must be false for observed cell \
                 {observed:?} on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_is_antimodally_tied_axis_cover_iff_cardinality_at_least_two<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Observing every cell exactly once raises trough_multiplicity
        // to `axis_cardinality::<A>()` (every cell sits at the same
        // uniform count, so the trough level set equals the support),
        // so the antimodal-tie predicate reads true iff the axis
        // carries two or more cells. Stated as an equivalence so the
        // law is uniform across the implementor set (every closed-axis
        // primitive in the typescape today carries
        // `axis_cardinality >= 2`, so axis-cover reads true uniformly)
        // without case-splitting on cardinality at the test site. Peer
        // to the dual law on
        // [`AxisHistogram::is_strictly_antimodally_unique`] which reads
        // true iff `axis_cardinality::<A>() == 1` — the two laws
        // together pin the strict-antimodal partition on the axis-
        // cover shape across every implementor.
        let hist: AxisHistogram<A> = axis_iter::<A>().collect();
        assert_eq!(
            hist.is_antimodally_tied(),
            axis_cardinality::<A>() >= 2,
            "axis-cover is_antimodally_tied must equal (axis_cardinality >= 2) \
             on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_is_antimodally_tied_equals_open_coded_trough_multiplicity_ge_two<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Defining-equivalence law: is_antimodally_tied() is pointwise
        // equal to (trough_multiplicity() >= 2) on every histogram
        // shape — empty, singleton, full axis cover, and (where the
        // axis has at least two variants) a tied-antimodal sub-cover
        // that exercises the shared-trough branch. Reached across
        // every implementor through the macro.
        let empty = AxisHistogram::<A>::empty();
        assert_eq!(
            empty.is_antimodally_tied(),
            empty.trough_multiplicity() >= 2,
            "is_antimodally_tied must equal (trough_multiplicity >= 2) on empty \
             histogram for axis {}",
            std::any::type_name::<A>(),
        );

        for observed in axis_iter::<A>() {
            let singleton: AxisHistogram<A> = std::iter::once(observed).collect();
            assert_eq!(
                singleton.is_antimodally_tied(),
                singleton.trough_multiplicity() >= 2,
                "is_antimodally_tied must equal (trough_multiplicity >= 2) on \
                 singleton {observed:?} for axis {}",
                std::any::type_name::<A>(),
            );
        }

        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        assert_eq!(
            cover.is_antimodally_tied(),
            cover.trough_multiplicity() >= 2,
            "is_antimodally_tied must equal (trough_multiplicity >= 2) on uniform \
             axis-cover for axis {}",
            std::any::type_name::<A>(),
        );

        // Tied antimodal sub-cover: observe the first two cells once
        // each (when the axis has at least two variants) to drive a
        // shared trough at multiplicity 2 — both cells sit at count 1,
        // which is also the peak count, so peak and trough coincide
        // and trough_multiplicity reads 2. On a singleton axis, the
        // loop body collapses to the singleton case above.
        let mut variants = axis_iter::<A>();
        if let (Some(first), Some(second)) = (variants.next(), variants.next()) {
            let mut tied = AxisHistogram::<A>::empty();
            tied.observe(first);
            tied.observe(second);
            assert_eq!(
                tied.is_antimodally_tied(),
                tied.trough_multiplicity() >= 2,
                "is_antimodally_tied must equal (trough_multiplicity >= 2) on a \
                 tied-antimodal sub-cover ({first:?} x1, {second:?} x1) for axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    #[test]
    fn axis_histogram_is_antimodally_tied_empty_is_false_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_is_antimodally_tied_empty_is_false::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_is_antimodally_tied_singleton_is_false_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_is_antimodally_tied_singleton_is_false::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_is_antimodally_tied_axis_cover_iff_cardinality_at_least_two_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_is_antimodally_tied_axis_cover_iff_cardinality_at_least_two::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_is_antimodally_tied_equals_open_coded_trough_multiplicity_ge_two_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_is_antimodally_tied_equals_open_coded_trough_multiplicity_ge_two::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_is_antimodally_tied_reads_antimodal_component_of_modality_degree() {
        // Projection-equality form: the predicate reads the antimodal
        // component of the fused (peak, trough) pair from
        // `modality_degree`. Pin pointwise across the four classifier
        // corners — strictly unimodal-anti-unimodal (1, 1), modally
        // tied-anti-unimodal (k, 1) with k >= 2, strictly unimodal-
        // antimodally tied (1, l) with l >= 2, and modal/antimodal
        // coincidence on a uniform sub-cover (k, k) — so the form
        // holds when the trough is shared (corners 3 and 4 fire the
        // predicate true) and when it is uniquely held (corners 1 and
        // 2 read false). All on [`DiffLineKind`].
        let unique_peak_unique_trough = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ];
        let h1: AxisHistogram<DiffLineKind> = unique_peak_unique_trough.iter().copied().collect();
        assert_eq!(h1.modality_degree(), (1, 1));
        assert!(!h1.is_antimodally_tied());
        assert_eq!(h1.is_antimodally_tied(), h1.modality_degree().1 >= 2);

        let tied_peak_unique_trough = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ];
        let h2: AxisHistogram<DiffLineKind> = tied_peak_unique_trough.iter().copied().collect();
        assert_eq!(h2.modality_degree(), (2, 1));
        assert!(!h2.is_antimodally_tied());
        assert_eq!(h2.is_antimodally_tied(), h2.modality_degree().1 >= 2);

        let unique_peak_tied_trough = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ];
        let h3: AxisHistogram<DiffLineKind> = unique_peak_tied_trough.iter().copied().collect();
        assert_eq!(h3.modality_degree(), (1, 2));
        assert!(h3.is_antimodally_tied());
        assert_eq!(h3.is_antimodally_tied(), h3.modality_degree().1 >= 2);

        let uniform_sub_cover = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Removed,
        ];
        let h4: AxisHistogram<DiffLineKind> = uniform_sub_cover.iter().copied().collect();
        assert_eq!(h4.modality_degree(), (2, 2));
        assert!(h4.is_antimodally_tied());
        assert_eq!(h4.is_antimodally_tied(), h4.modality_degree().1 >= 2);
    }

    #[test]
    fn axis_histogram_is_antimodally_tied_strictly_partitions_antimodal_axis_on_non_empty() {
        // The strict-antimodal partition law: on every non-empty
        // histogram, exactly one of (is_strictly_antimodally_unique,
        // is_antimodally_tied) fires — the trough is either uniquely
        // held or shared, never both, and never neither. The non-empty
        // XOR pinned across the canonical antimodal shapes (singleton-
        // multi-observation, strict-trough two-cell, tied-trough two-
        // cell, three-way tied). The empty boundary breaks the
        // equivalence: both predicates read false there.
        let cases: [&[DiffLineKind]; 4] = [
            // singleton-multi-observation: trough_multiplicity == 1
            &[DiffLineKind::Added, DiffLineKind::Added],
            // strict-trough two-cell: trough_multiplicity == 1
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
            ],
            // tied-trough two-cell: trough_multiplicity == 2
            &[DiffLineKind::Added, DiffLineKind::Removed],
            // three-way uniform: trough_multiplicity == 3
            &[
                DiffLineKind::Added,
                DiffLineKind::Removed,
                DiffLineKind::Context,
            ],
        ];
        for input in cases {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            assert!(!hist.is_empty());
            assert_ne!(
                hist.is_strictly_antimodally_unique(),
                hist.is_antimodally_tied(),
                "non-empty histogram must fire exactly one of \
                 (is_strictly_antimodally_unique, is_antimodally_tied) on input of length {}",
                input.len(),
            );
            assert_eq!(
                hist.is_antimodally_tied(),
                !hist.is_strictly_antimodally_unique(),
                "is_antimodally_tied must equal !is_strictly_antimodally_unique on \
                 non-empty input of length {}",
                input.len(),
            );
        }

        // The empty histogram boundary: both predicates read false,
        // breaking the XOR equivalence — the strict partition holds
        // only on the non-empty side of the histogram surface.
        let empty: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
        assert!(empty.is_empty());
        assert!(!empty.is_strictly_antimodally_unique());
        assert!(!empty.is_antimodally_tied());
    }

    #[test]
    fn axis_histogram_is_antimodally_tied_witnesses_non_empty_when_true() {
        // Contrapositive of (is_empty ⇒ !is_antimodally_tied):
        // whenever the antimodal-tie predicate fires, the histogram is
        // non-empty. The boolean lifts a one-step non-emptiness witness
        // on the tied-antimodal side, peer to the same witness on the
        // strictly-antimodally-unique side.
        let cases: [&[DiffLineKind]; 3] = [
            &[DiffLineKind::Added, DiffLineKind::Removed],
            &[
                DiffLineKind::Added,
                DiffLineKind::Added,
                DiffLineKind::Removed,
                DiffLineKind::Removed,
            ],
            &[
                DiffLineKind::Added,
                DiffLineKind::Removed,
                DiffLineKind::Context,
            ],
        ];
        for input in cases {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            assert!(hist.is_antimodally_tied());
            assert!(!hist.is_empty());
        }

        // The empty histogram itself: predicate reads false, peer to
        // the trough_multiplicity (0) empty-boundary convention.
        let empty: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
        assert!(empty.is_empty());
        assert!(!empty.is_antimodally_tied());
    }

    #[test]
    fn axis_histogram_has_singular_support_implies_not_is_antimodally_tied() {
        // The one-way implication on the singular-support boundary: a
        // single observed cell is the only member of the antimodal
        // level set, so the tie predicate never fires on a singleton-
        // support histogram. The contrapositive (is_antimodally_tied ⇒
        // !has_singular_support) lifts a one-step multi-cell-support
        // witness off the tied-antimodal side: a fired tie predicate
        // means at least two observed cells.
        for observed in [
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ] {
            let hist: AxisHistogram<DiffLineKind> = std::iter::once(observed).collect();
            assert!(hist.has_singular_support());
            assert!(!hist.is_antimodally_tied());
        }

        // Tied-antimodal two-cell shape witnesses the contrapositive:
        // is_antimodally_tied is true, has_singular_support is false.
        let two_cell_tied: AxisHistogram<DiffLineKind> =
            [DiffLineKind::Added, DiffLineKind::Removed]
                .into_iter()
                .collect();
        assert!(two_cell_tied.is_antimodally_tied());
        assert!(!two_cell_tied.has_singular_support());
    }

    #[test]
    fn axis_histogram_is_antimodally_tied_under_uniform_count_collapses_to_multi_cell_support() {
        // Conditional collapse law: when every observed cell shares
        // the same count, the antimodal level set equals the support,
        // so the tie predicate collapses to (!has_singular_support())
        // on the non-empty side. Pinned on three uniform-count shapes
        // (singleton-multi-observation, two-cell uniform sub-cover,
        // full axis cover) — only the singleton shape fires both
        // predicates false; the multi-cell uniform shapes fire both
        // true. Peer to the identical collapse law on
        // [`AxisHistogram::is_modally_tied`]; under uniform-count
        // shapes the two tie predicates coincide because peak and
        // trough collapse to the same uniform count.
        let singleton_multi = [DiffLineKind::Added, DiffLineKind::Added];
        let h_singleton: AxisHistogram<DiffLineKind> = singleton_multi.iter().copied().collect();
        assert!(h_singleton.is_uniform_count());
        assert!(!h_singleton.is_empty());
        assert_eq!(
            h_singleton.is_antimodally_tied(),
            !h_singleton.has_singular_support(),
        );
        assert!(!h_singleton.is_antimodally_tied());

        let two_cell_uniform = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Removed,
        ];
        let h_two: AxisHistogram<DiffLineKind> = two_cell_uniform.iter().copied().collect();
        assert!(h_two.is_uniform_count());
        assert!(!h_two.is_empty());
        assert_eq!(h_two.is_antimodally_tied(), !h_two.has_singular_support(),);
        assert!(h_two.is_antimodally_tied());

        let cover: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ]
        .into_iter()
        .collect();
        assert!(cover.is_uniform_count());
        assert!(!cover.is_empty());
        assert_eq!(cover.is_antimodally_tied(), !cover.has_singular_support(),);
        assert!(cover.is_antimodally_tied());
    }

    #[test]
    fn axis_histogram_is_antimodally_tied_coincides_with_is_modally_tied_under_uniform_count() {
        // Uniform-count collapse between the two tie predicates: when
        // every observed cell shares the same count, peak and trough
        // coincide and the modal and antimodal level sets both equal
        // the support — so is_antimodally_tied and is_modally_tied
        // collapse to the same boolean (`!has_singular_support()` on
        // the non-empty side). Pinned on the same three uniform-count
        // shapes as the standalone collapse law, plus the empty
        // boundary where both read false (their (false, false) reading
        // is inherited from the (trough, peak)_multiplicity (0, 0)
        // empty convention rather than the uniform-count collapse).
        // Sharpens the closed multiplicity boolean algebra: the four
        // named primitives (is_strictly_modally_unique,
        // is_modally_tied, is_strictly_antimodally_unique,
        // is_antimodally_tied) reduce on uniform-count shapes to one
        // pair-of-booleans answer (modal == antimodal), making the
        // future ModalityClass enum's uniform-count branch trivially
        // one-axis.
        let empty: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
        assert_eq!(empty.is_modally_tied(), empty.is_antimodally_tied());

        let singleton_multi: AxisHistogram<DiffLineKind> =
            [DiffLineKind::Added, DiffLineKind::Added]
                .iter()
                .copied()
                .collect();
        assert!(singleton_multi.is_uniform_count());
        assert_eq!(
            singleton_multi.is_modally_tied(),
            singleton_multi.is_antimodally_tied(),
        );

        let two_cell_uniform: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Removed,
        ]
        .iter()
        .copied()
        .collect();
        assert!(two_cell_uniform.is_uniform_count());
        assert_eq!(
            two_cell_uniform.is_modally_tied(),
            two_cell_uniform.is_antimodally_tied(),
        );

        let cover: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ]
        .into_iter()
        .collect();
        assert!(cover.is_uniform_count());
        assert_eq!(cover.is_modally_tied(), cover.is_antimodally_tied());
    }

    #[test]
    fn modality_class_all_has_five_entries() {
        // The five-variant closed multiplicity classification
        // (Empty, StrictModalStrictAntimodal, TiedModalStrictAntimodal,
        // StrictModalTiedAntimodal, TiedModalTiedAntimodal) — pinned by
        // a length-5 invariant on ModalityClass::ALL. Lockstep with the
        // discriminant exhaustiveness law below: a sixth corner landing
        // on the typescape extends both the variant set and the ALL
        // slice in one commit, and this pin catches the discipline
        // violation before silent dropouts at every classifier-corner
        // rollup site.
        assert_eq!(ModalityClass::ALL.len(), 5);
        assert_eq!(
            ModalityClass::ALL,
            &[
                ModalityClass::Empty,
                ModalityClass::StrictModalStrictAntimodal,
                ModalityClass::TiedModalStrictAntimodal,
                ModalityClass::StrictModalTiedAntimodal,
                ModalityClass::TiedModalTiedAntimodal,
            ],
        );
    }

    #[test]
    fn modality_class_all_entries_are_pairwise_distinct() {
        // Disjoint-variant invariant on the closed enum surface — every
        // pair of distinct variants compares unequal. Pinned at the
        // enum surface so a future merge of two variants (or an
        // accidental duplicate variant tag) caught at one site rather
        // than through downstream test failures on the
        // modality_class equivalence laws.
        for (i, &a) in ModalityClass::ALL.iter().enumerate() {
            for (j, &b) in ModalityClass::ALL.iter().enumerate() {
                if i == j {
                    assert_eq!(a, b, "variant must equal itself at index {i}");
                } else {
                    assert_ne!(a, b, "variants at indices {i} and {j} must differ");
                }
            }
        }
    }

    #[test]
    fn modality_class_is_empty_fires_exactly_on_empty_variant() {
        // The Self::is_empty const projection on ModalityClass fires
        // exactly on Self::Empty and nowhere else — the empty boundary
        // is the unique typed witness on the variant tag. Lockstep with
        // the histogram-side trait-uniform agreement law below.
        for &class in ModalityClass::ALL {
            assert_eq!(
                class.is_empty(),
                matches!(class, ModalityClass::Empty),
                "is_empty must fire iff variant == Empty for class {class:?}",
            );
        }
    }

    #[test]
    fn modality_class_is_modally_tied_fires_exactly_on_tied_modal_variants() {
        // The Self::is_modally_tied const projection fires exactly on
        // TiedModalStrictAntimodal and TiedModalTiedAntimodal — the
        // two variants whose modal axis is tied. Pinned across every
        // variant so a future rename of either tied-modal variant or
        // accidental addition of a sixth tied-modal corner is caught
        // at one site.
        for &class in ModalityClass::ALL {
            let expected = matches!(
                class,
                ModalityClass::TiedModalStrictAntimodal | ModalityClass::TiedModalTiedAntimodal,
            );
            assert_eq!(
                class.is_modally_tied(),
                expected,
                "is_modally_tied projection on class {class:?}",
            );
        }
    }

    #[test]
    fn modality_class_is_antimodally_tied_fires_exactly_on_tied_antimodal_variants() {
        // The Self::is_antimodally_tied const projection fires exactly
        // on StrictModalTiedAntimodal and TiedModalTiedAntimodal — the
        // two variants whose antimodal axis is tied. Pinned across
        // every variant; orthogonal axis-pair to the modal-side law.
        for &class in ModalityClass::ALL {
            let expected = matches!(
                class,
                ModalityClass::StrictModalTiedAntimodal | ModalityClass::TiedModalTiedAntimodal,
            );
            assert_eq!(
                class.is_antimodally_tied(),
                expected,
                "is_antimodally_tied projection on class {class:?}",
            );
        }
    }

    #[test]
    fn modality_class_is_strictly_modally_unique_fires_exactly_on_strict_modal_variants() {
        // The Self::is_strictly_modally_unique const projection fires
        // exactly on StrictModalStrictAntimodal and
        // StrictModalTiedAntimodal — the two variants whose modal axis
        // is strictly unique. The empty variant reads false (the
        // empty-boundary convention shared with the histogram
        // surface). Closes the modal-axis (strict-unique, tied)
        // partition pair on the variant tag.
        for &class in ModalityClass::ALL {
            let expected = matches!(
                class,
                ModalityClass::StrictModalStrictAntimodal | ModalityClass::StrictModalTiedAntimodal,
            );
            assert_eq!(
                class.is_strictly_modally_unique(),
                expected,
                "is_strictly_modally_unique projection on class {class:?}",
            );
        }
    }

    #[test]
    fn modality_class_is_strictly_antimodally_unique_fires_exactly_on_strict_antimodal_variants() {
        // The Self::is_strictly_antimodally_unique const projection
        // fires exactly on StrictModalStrictAntimodal and
        // TiedModalStrictAntimodal — the two variants whose antimodal
        // axis is strictly unique. The empty variant reads false.
        // Orthogonal-axis peer to the modal-side law above; closes
        // the antimodal-axis (strict-unique, tied) partition pair on
        // the variant tag.
        for &class in ModalityClass::ALL {
            let expected = matches!(
                class,
                ModalityClass::StrictModalStrictAntimodal | ModalityClass::TiedModalStrictAntimodal,
            );
            assert_eq!(
                class.is_strictly_antimodally_unique(),
                expected,
                "is_strictly_antimodally_unique projection on class {class:?}",
            );
        }
    }

    #[test]
    fn modality_class_strict_and_tied_modal_predicates_partition_non_empty_variants() {
        // On every non-empty variant, exactly one of the modal-axis
        // predicates fires — `is_strictly_modally_unique` XOR
        // `is_modally_tied`. The empty variant reads `false` on both
        // (the empty-boundary convention). Pins the partition law at
        // one site so a future rename of either side that drifts the
        // predicate boundaries breaks here.
        for &class in ModalityClass::ALL {
            let strict = class.is_strictly_modally_unique();
            let tied = class.is_modally_tied();
            if matches!(class, ModalityClass::Empty) {
                assert!(
                    !strict && !tied,
                    "Empty must read false on both modal predicates (got strict={strict}, tied={tied})",
                );
            } else {
                assert!(
                    strict ^ tied,
                    "non-empty class {class:?} must land on exactly one modal predicate \
                     (got strict={strict}, tied={tied})",
                );
            }
        }
    }

    #[test]
    fn modality_class_strict_and_tied_antimodal_predicates_partition_non_empty_variants() {
        // Orthogonal peer of the modal-axis partition law above. On
        // every non-empty variant, exactly one of the antimodal-axis
        // predicates fires — `is_strictly_antimodally_unique` XOR
        // `is_antimodally_tied`. The empty variant reads `false` on
        // both.
        for &class in ModalityClass::ALL {
            let strict = class.is_strictly_antimodally_unique();
            let tied = class.is_antimodally_tied();
            if matches!(class, ModalityClass::Empty) {
                assert!(
                    !strict && !tied,
                    "Empty must read false on both antimodal predicates (got strict={strict}, tied={tied})",
                );
            } else {
                assert!(
                    strict ^ tied,
                    "non-empty class {class:?} must land on exactly one antimodal predicate \
                     (got strict={strict}, tied={tied})",
                );
            }
        }
    }

    #[test]
    fn modality_class_is_doubly_strict_unique_fires_exactly_on_strict_modal_strict_antimodal() {
        // The Self::is_doubly_strict_unique const projection fires
        // exactly on the single StrictModalStrictAntimodal variant —
        // the diagonal corner of the 2×2 partition where neither
        // tie-break is exercised. Every other variant (including the
        // empty boundary) reads false. The single-variant matches!()
        // is the canonical "no tie-break exercised on either axis"
        // boolean projected from the variant tag at one const call.
        for &class in ModalityClass::ALL {
            let expected = matches!(class, ModalityClass::StrictModalStrictAntimodal);
            assert_eq!(
                class.is_doubly_strict_unique(),
                expected,
                "is_doubly_strict_unique projection on class {class:?}",
            );
        }
    }

    #[test]
    fn modality_class_is_doubly_tied_fires_exactly_on_tied_modal_tied_antimodal() {
        // The Self::is_doubly_tied const projection fires exactly on
        // the single TiedModalTiedAntimodal variant — the diagonal
        // corner of the 2×2 partition where both tie-breaks are
        // exercised (the canonical uniform-count multi-cell shape's
        // landing corner). Every other variant (including the empty
        // boundary) reads false. Orthogonal-corner peer of
        // is_doubly_strict_unique.
        for &class in ModalityClass::ALL {
            let expected = matches!(class, ModalityClass::TiedModalTiedAntimodal);
            assert_eq!(
                class.is_doubly_tied(),
                expected,
                "is_doubly_tied projection on class {class:?}",
            );
        }
    }

    #[test]
    fn modality_class_is_doubly_strict_unique_equals_strict_modal_and_strict_antimodal_conjunction()
    {
        // Defining-equivalence law: is_doubly_strict_unique() reads
        // pointwise the same as the conjunction of the two per-axis
        // strict-unique predicates across every variant of
        // ModalityClass::ALL — empty, the four non-empty corners, and
        // (forward-compatibly under #[non_exhaustive]) every future
        // variant. Pins the diagonal-corner projection at the per-axis
        // conjunction it collapses.
        for &class in ModalityClass::ALL {
            let conj = class.is_strictly_modally_unique() && class.is_strictly_antimodally_unique();
            assert_eq!(
                class.is_doubly_strict_unique(),
                conj,
                "is_doubly_strict_unique must equal the per-axis strict-unique conjunction \
                 on class {class:?}",
            );
        }
    }

    #[test]
    fn modality_class_is_doubly_tied_equals_modal_tied_and_antimodal_tied_conjunction() {
        // Defining-equivalence law: is_doubly_tied() reads pointwise
        // the same as the conjunction of the two per-axis tied
        // predicates across every variant. Orthogonal-corner peer of
        // the doubly-strict-unique equivalence law above.
        for &class in ModalityClass::ALL {
            let conj = class.is_modally_tied() && class.is_antimodally_tied();
            assert_eq!(
                class.is_doubly_tied(),
                conj,
                "is_doubly_tied must equal the per-axis tied conjunction on class {class:?}",
            );
        }
    }

    #[test]
    fn modality_class_is_doubly_strict_unique_and_is_doubly_tied_are_disjoint() {
        // Disjointness law: the two diagonal-corner predicates never
        // fire on the same variant — by construction each matches a
        // single-element disjoint subset of ModalityClass::ALL
        // (StrictModalStrictAntimodal vs. TiedModalTiedAntimodal). The
        // remaining three variants (Empty, TiedModalStrictAntimodal,
        // StrictModalTiedAntimodal) read false on both. Pinning the
        // disjointness at one site so a future rename of either side
        // that drifts the predicate boundaries breaks here rather than
        // silently double-counting a classifier corner in a rollup.
        for &class in ModalityClass::ALL {
            let strict = class.is_doubly_strict_unique();
            let tied = class.is_doubly_tied();
            assert!(
                !(strict && tied),
                "doubly-strict-unique and doubly-tied must be disjoint \
                 (got strict={strict}, tied={tied}) on class {class:?}",
            );
        }
    }

    #[test]
    fn modality_class_is_only_modally_tied_fires_exactly_on_tied_modal_strict_antimodal() {
        // The Self::is_only_modally_tied const projection fires exactly
        // on the single TiedModalStrictAntimodal variant — the off-
        // diagonal corner of the 2×2 partition where only the modal
        // axis tie-break is exercised (the antimodal axis remains
        // strictly unique). Every other variant (including the empty
        // boundary, the orthogonal off-diagonal corner, and both
        // diagonal corners) reads false. The single-variant matches!()
        // is the canonical "only the modal tie-break is exercised"
        // boolean projected from the variant tag at one const call.
        for &class in ModalityClass::ALL {
            let expected = matches!(class, ModalityClass::TiedModalStrictAntimodal);
            assert_eq!(
                class.is_only_modally_tied(),
                expected,
                "is_only_modally_tied projection on class {class:?}",
            );
        }
    }

    #[test]
    fn modality_class_is_only_antimodally_tied_fires_exactly_on_strict_modal_tied_antimodal() {
        // The Self::is_only_antimodally_tied const projection fires
        // exactly on the single StrictModalTiedAntimodal variant — the
        // orthogonal off-diagonal corner of the 2×2 partition where
        // only the antimodal axis tie-break is exercised (the modal
        // axis remains strictly unique). Every other variant (including
        // the empty boundary, the orthogonal off-diagonal corner, and
        // both diagonal corners) reads false. Orthogonal-corner peer of
        // is_only_modally_tied.
        for &class in ModalityClass::ALL {
            let expected = matches!(class, ModalityClass::StrictModalTiedAntimodal);
            assert_eq!(
                class.is_only_antimodally_tied(),
                expected,
                "is_only_antimodally_tied projection on class {class:?}",
            );
        }
    }

    #[test]
    fn modality_class_is_only_modally_tied_equals_modal_tied_and_antimodal_strict_conjunction() {
        // Defining-equivalence law: is_only_modally_tied() reads
        // pointwise the same as the conjunction of the modal-tied and
        // antimodal-strict per-axis predicates across every variant of
        // ModalityClass::ALL — empty, the four non-empty corners, and
        // (forward-compatibly under #[non_exhaustive]) every future
        // variant. Pins the off-diagonal-corner projection at the
        // per-axis conjunction it collapses.
        for &class in ModalityClass::ALL {
            let conj = class.is_modally_tied() && class.is_strictly_antimodally_unique();
            assert_eq!(
                class.is_only_modally_tied(),
                conj,
                "is_only_modally_tied must equal the (modal-tied, antimodal-strict) \
                 conjunction on class {class:?}",
            );
        }
    }

    #[test]
    fn modality_class_is_only_antimodally_tied_equals_antimodal_tied_and_modal_strict_conjunction()
    {
        // Defining-equivalence law: is_only_antimodally_tied() reads
        // pointwise the same as the conjunction of the antimodal-tied
        // and modal-strict per-axis predicates across every variant.
        // Orthogonal off-diagonal peer of the only-modally-tied
        // equivalence law above.
        for &class in ModalityClass::ALL {
            let conj = class.is_antimodally_tied() && class.is_strictly_modally_unique();
            assert_eq!(
                class.is_only_antimodally_tied(),
                conj,
                "is_only_antimodally_tied must equal the (antimodal-tied, modal-strict) \
                 conjunction on class {class:?}",
            );
        }
    }

    #[test]
    fn modality_class_four_corner_predicates_are_pairwise_disjoint() {
        // Pairwise-disjointness law: the four single-variant corner
        // projections (is_doubly_strict_unique, is_doubly_tied,
        // is_only_modally_tied, is_only_antimodally_tied) match
        // disjoint single-element subsets of ModalityClass::ALL, so on
        // every variant at most one fires. Pinning the full 4-way
        // pairwise-disjointness at one site so a future rename of any
        // pair that drifts the predicate boundaries breaks here rather
        // than silently double-counting a classifier corner in a
        // rollup. Extends
        // modality_class_is_doubly_strict_unique_and_is_doubly_tied_are_disjoint
        // from the 2-way diagonal-pair case to the full 4-corner
        // partition.
        for &class in ModalityClass::ALL {
            let predicates = [
                ("is_doubly_strict_unique", class.is_doubly_strict_unique()),
                ("is_doubly_tied", class.is_doubly_tied()),
                ("is_only_modally_tied", class.is_only_modally_tied()),
                ("is_only_antimodally_tied", class.is_only_antimodally_tied()),
            ];
            for (i, (lhs_name, lhs)) in predicates.iter().enumerate() {
                for (rhs_name, rhs) in predicates.iter().skip(i + 1) {
                    assert!(
                        !(*lhs && *rhs),
                        "{lhs_name} and {rhs_name} must be disjoint \
                         (got lhs={lhs}, rhs={rhs}) on class {class:?}",
                    );
                }
            }
        }
    }

    #[test]
    fn modality_class_four_corner_predicates_partition_non_empty_variants() {
        // Totality law: on every non-empty variant exactly one of the
        // four single-variant corner predicates fires; on the empty
        // boundary all four read false. Together with the pairwise-
        // disjointness law above, the four predicates form a true
        // partition of the four non-empty corners of the 2×2
        // classifier — the empty boundary remains the single off-
        // partition variant carrying the shared "false on every per-
        // axis named boolean" convention. A consumer rolling up the
        // four corners can now count each non-empty histogram exactly
        // once across the four parallel const reads without re-routing
        // through match on the variant tag.
        for &class in ModalityClass::ALL {
            let fires = u32::from(class.is_doubly_strict_unique())
                + u32::from(class.is_doubly_tied())
                + u32::from(class.is_only_modally_tied())
                + u32::from(class.is_only_antimodally_tied());
            let expected = u32::from(!class.is_empty());
            assert_eq!(
                fires, expected,
                "exactly one corner predicate must fire on every non-empty variant \
                 (got fires={fires}) on class {class:?}",
            );
        }
    }

    fn assert_modality_class_empty_is_empty_variant<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The empty histogram boundary lifts to the typed
        // ModalityClass::Empty variant uniformly across every
        // implementor, inherited from modality_degree returning
        // (0, 0) on every implementor's empty histogram.
        let hist = AxisHistogram::<A>::empty();
        assert_eq!(
            hist.modality_class(),
            ModalityClass::Empty,
            "empty histogram modality_class must be Empty on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_modality_class_singleton_is_strict_modal_strict_antimodal<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Every singleton-support histogram has modality_degree (1, 1)
        // (the lone observed cell stands alone at both peak and
        // trough), so modality_class reads
        // StrictModalStrictAntimodal uniformly across every
        // implementor — the minimal-non-empty boundary witness for the
        // both-extremes-uniquely-held corner.
        for observed in axis_iter::<A>() {
            let hist: AxisHistogram<A> = std::iter::once(observed).collect();
            assert_eq!(
                hist.modality_class(),
                ModalityClass::StrictModalStrictAntimodal,
                "singleton modality_class for observed cell {observed:?} on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_modality_class_axis_cover_is_tied_modal_tied_antimodal_iff_cardinality_at_least_two<
        A,
    >()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Observing every cell exactly once raises both
        // peak_multiplicity and trough_multiplicity to
        // axis_cardinality::<A>(); modality_class reads
        // TiedModalTiedAntimodal iff the axis carries two or more
        // cells, and StrictModalStrictAntimodal iff the axis carries
        // exactly one cell. Stated as an equivalence so the law is
        // uniform across the implementor set without case-splitting
        // on cardinality at the test site — every closed-axis
        // primitive on the typescape today carries
        // axis_cardinality >= 2, so the law reads
        // TiedModalTiedAntimodal uniformly across the implementor set.
        let hist: AxisHistogram<A> = axis_iter::<A>().collect();
        let expected = if axis_cardinality::<A>() >= 2 {
            ModalityClass::TiedModalTiedAntimodal
        } else {
            ModalityClass::StrictModalStrictAntimodal
        };
        assert_eq!(
            hist.modality_class(),
            expected,
            "axis-cover modality_class on axis {} (cardinality {})",
            std::any::type_name::<A>(),
            axis_cardinality::<A>(),
        );
    }

    fn assert_modality_class_equals_open_coded_modality_degree_match<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Defining-equivalence law: modality_class() is pointwise the
        // five-arm match on modality_degree() the named projection
        // collapses, across every histogram shape — empty, singleton,
        // full axis cover. Reached across every implementor through
        // the macro.
        let shapes: [AxisHistogram<A>; 3] = [
            AxisHistogram::<A>::empty(),
            std::iter::once(axis_iter::<A>().next().expect("non-empty axis"))
                .collect::<AxisHistogram<A>>(),
            axis_iter::<A>().collect::<AxisHistogram<A>>(),
        ];
        for hist in &shapes {
            let expected = match hist.modality_degree() {
                (0, 0) => ModalityClass::Empty,
                (1, 1) => ModalityClass::StrictModalStrictAntimodal,
                (_, 1) => ModalityClass::TiedModalStrictAntimodal,
                (1, _) => ModalityClass::StrictModalTiedAntimodal,
                _ => ModalityClass::TiedModalTiedAntimodal,
            };
            assert_eq!(
                hist.modality_class(),
                expected,
                "modality_class must equal open-coded modality_degree match \
                 on axis {} with degree {:?}",
                std::any::type_name::<A>(),
                hist.modality_degree(),
            );
        }
    }

    fn assert_modality_class_is_empty_agrees_with_histogram_is_empty<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The peer-projection law on the empty boundary:
        // hist.modality_class().is_empty() == hist.is_empty() on every
        // histogram shape. The enum-surface projection lifts the
        // histogram-surface empty-boundary predicate onto the variant
        // tag without re-routing through the originating histogram.
        let empty = AxisHistogram::<A>::empty();
        assert_eq!(
            empty.modality_class().is_empty(),
            empty.is_empty(),
            "modality_class.is_empty must equal histogram.is_empty on empty \
             histogram for axis {}",
            std::any::type_name::<A>(),
        );

        for observed in axis_iter::<A>() {
            let singleton: AxisHistogram<A> = std::iter::once(observed).collect();
            assert_eq!(
                singleton.modality_class().is_empty(),
                singleton.is_empty(),
                "modality_class.is_empty must equal histogram.is_empty on \
                 singleton {observed:?} for axis {}",
                std::any::type_name::<A>(),
            );
        }

        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        assert_eq!(
            cover.modality_class().is_empty(),
            cover.is_empty(),
            "modality_class.is_empty must equal histogram.is_empty on uniform \
             axis-cover for axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_modality_class_is_modally_tied_agrees_with_histogram_is_modally_tied<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Peer-projection on the modal axis:
        // hist.modality_class().is_modally_tied() ==
        // hist.is_modally_tied() on every histogram shape. The closed-
        // enum projection lifts the histogram-surface modal-tie
        // predicate onto the variant tag pointwise.
        let empty = AxisHistogram::<A>::empty();
        assert_eq!(
            empty.modality_class().is_modally_tied(),
            empty.is_modally_tied(),
            "modally_tied agreement on empty histogram for axis {}",
            std::any::type_name::<A>(),
        );

        for observed in axis_iter::<A>() {
            let singleton: AxisHistogram<A> = std::iter::once(observed).collect();
            assert_eq!(
                singleton.modality_class().is_modally_tied(),
                singleton.is_modally_tied(),
                "modally_tied agreement on singleton {observed:?} for axis {}",
                std::any::type_name::<A>(),
            );
        }

        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        assert_eq!(
            cover.modality_class().is_modally_tied(),
            cover.is_modally_tied(),
            "modally_tied agreement on uniform axis-cover for axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_modality_class_is_antimodally_tied_agrees_with_histogram_is_antimodally_tied<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Peer-projection on the antimodal axis:
        // hist.modality_class().is_antimodally_tied() ==
        // hist.is_antimodally_tied() on every histogram shape.
        // Orthogonal-axis peer to the modal-side law above.
        let empty = AxisHistogram::<A>::empty();
        assert_eq!(
            empty.modality_class().is_antimodally_tied(),
            empty.is_antimodally_tied(),
            "antimodally_tied agreement on empty histogram for axis {}",
            std::any::type_name::<A>(),
        );

        for observed in axis_iter::<A>() {
            let singleton: AxisHistogram<A> = std::iter::once(observed).collect();
            assert_eq!(
                singleton.modality_class().is_antimodally_tied(),
                singleton.is_antimodally_tied(),
                "antimodally_tied agreement on singleton {observed:?} for axis {}",
                std::any::type_name::<A>(),
            );
        }

        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        assert_eq!(
            cover.modality_class().is_antimodally_tied(),
            cover.is_antimodally_tied(),
            "antimodally_tied agreement on uniform axis-cover for axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_modality_class_is_strictly_modally_unique_agrees_with_histogram_is_strictly_modally_unique<
        A,
    >()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Peer-projection on the modal-uniqueness axis:
        // hist.modality_class().is_strictly_modally_unique() ==
        // hist.is_strictly_modally_unique() on every histogram shape.
        // Closes the (strict-unique, tied) modal-axis partition pair
        // on the variant-tag projection.
        let empty = AxisHistogram::<A>::empty();
        assert_eq!(
            empty.modality_class().is_strictly_modally_unique(),
            empty.is_strictly_modally_unique(),
            "strictly_modally_unique agreement on empty histogram for axis {}",
            std::any::type_name::<A>(),
        );

        for observed in axis_iter::<A>() {
            let singleton: AxisHistogram<A> = std::iter::once(observed).collect();
            assert_eq!(
                singleton.modality_class().is_strictly_modally_unique(),
                singleton.is_strictly_modally_unique(),
                "strictly_modally_unique agreement on singleton {observed:?} for axis {}",
                std::any::type_name::<A>(),
            );
        }

        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        assert_eq!(
            cover.modality_class().is_strictly_modally_unique(),
            cover.is_strictly_modally_unique(),
            "strictly_modally_unique agreement on uniform axis-cover for axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_modality_class_is_strictly_antimodally_unique_agrees_with_histogram_is_strictly_antimodally_unique<
        A,
    >()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Peer-projection on the antimodal-uniqueness axis:
        // hist.modality_class().is_strictly_antimodally_unique() ==
        // hist.is_strictly_antimodally_unique() on every histogram
        // shape. Orthogonal-axis peer to the modal-uniqueness law
        // above; closes the (strict-unique, tied) antimodal-axis
        // partition pair on the variant-tag projection.
        let empty = AxisHistogram::<A>::empty();
        assert_eq!(
            empty.modality_class().is_strictly_antimodally_unique(),
            empty.is_strictly_antimodally_unique(),
            "strictly_antimodally_unique agreement on empty histogram for axis {}",
            std::any::type_name::<A>(),
        );

        for observed in axis_iter::<A>() {
            let singleton: AxisHistogram<A> = std::iter::once(observed).collect();
            assert_eq!(
                singleton.modality_class().is_strictly_antimodally_unique(),
                singleton.is_strictly_antimodally_unique(),
                "strictly_antimodally_unique agreement on singleton {observed:?} for axis {}",
                std::any::type_name::<A>(),
            );
        }

        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        assert_eq!(
            cover.modality_class().is_strictly_antimodally_unique(),
            cover.is_strictly_antimodally_unique(),
            "strictly_antimodally_unique agreement on uniform axis-cover for axis {}",
            std::any::type_name::<A>(),
        );
    }

    #[test]
    fn axis_histogram_modality_class_empty_is_empty_variant_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_modality_class_empty_is_empty_variant::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_modality_class_singleton_is_strict_modal_strict_antimodal_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_modality_class_singleton_is_strict_modal_strict_antimodal::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_modality_class_axis_cover_is_tied_modal_tied_antimodal_iff_cardinality_at_least_two_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_modality_class_axis_cover_is_tied_modal_tied_antimodal_iff_cardinality_at_least_two::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_modality_class_equals_open_coded_modality_degree_match_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_modality_class_equals_open_coded_modality_degree_match::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_modality_class_is_empty_agrees_with_histogram_is_empty_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_modality_class_is_empty_agrees_with_histogram_is_empty::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_modality_class_is_modally_tied_agrees_with_histogram_is_modally_tied_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_modality_class_is_modally_tied_agrees_with_histogram_is_modally_tied::<$ty>(
                );
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_modality_class_is_antimodally_tied_agrees_with_histogram_is_antimodally_tied_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_modality_class_is_antimodally_tied_agrees_with_histogram_is_antimodally_tied::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_modality_class_is_strictly_modally_unique_agrees_with_histogram_is_strictly_modally_unique_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_modality_class_is_strictly_modally_unique_agrees_with_histogram_is_strictly_modally_unique::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_modality_class_is_strictly_antimodally_unique_agrees_with_histogram_is_strictly_antimodally_unique_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_modality_class_is_strictly_antimodally_unique_agrees_with_histogram_is_strictly_antimodally_unique::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_modality_class_classifies_all_five_corners_on_diff_line_kind() {
        // Behavioral pin: each of the five ModalityClass variants is
        // hit by at least one canonical DiffLineKind shape — the
        // empty boundary, the (1, 1) corner via a strictly-skewed
        // shape, the (k, 1) corner via a tied-peak shape, the (1, l)
        // corner via a tied-trough shape, and the (k, l) corner via a
        // uniform sub-cover. Co-located with the four classifier-corner
        // tests on modality_degree (lines 25832-25917) so the variants
        // and the underlying scalar-pair corners stay in lockstep
        // across future shape additions.
        let empty: AxisHistogram<DiffLineKind> = AxisHistogram::empty();
        assert_eq!(empty.modality_class(), ModalityClass::Empty);

        // (1, 1): three-of-Added, two-of-Removed, one-of-Context —
        // peak = Added (unique at 3), trough = Context (unique at 1).
        let strict_strict: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ]
        .iter()
        .copied()
        .collect();
        assert_eq!(strict_strict.modality_degree(), (1, 1));
        assert_eq!(
            strict_strict.modality_class(),
            ModalityClass::StrictModalStrictAntimodal,
        );

        // (k, 1): two-of-Added, two-of-Removed, one-of-Context —
        // peak shared by Added/Removed (k=2), trough = Context (l=1).
        let tied_strict: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ]
        .iter()
        .copied()
        .collect();
        assert_eq!(tied_strict.modality_degree(), (2, 1));
        assert_eq!(
            tied_strict.modality_class(),
            ModalityClass::TiedModalStrictAntimodal,
        );

        // (1, l): three-of-Added, one-of-Removed, one-of-Context —
        // peak = Added (k=1), trough shared by Removed/Context (l=2).
        let strict_tied: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ]
        .iter()
        .copied()
        .collect();
        assert_eq!(strict_tied.modality_degree(), (1, 2));
        assert_eq!(
            strict_tied.modality_class(),
            ModalityClass::StrictModalTiedAntimodal,
        );

        // (k, l): two-of-Added, two-of-Removed — uniform sub-cover
        // collapses peak and trough onto the same level set; (k, l) =
        // (2, 2).
        let tied_tied: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Removed,
        ]
        .iter()
        .copied()
        .collect();
        assert_eq!(tied_tied.modality_degree(), (2, 2));
        assert_eq!(
            tied_tied.modality_class(),
            ModalityClass::TiedModalTiedAntimodal,
        );
    }

    #[test]
    fn axis_histogram_modality_class_uniform_count_non_empty_lands_in_both_tied_or_both_strict() {
        // Uniform-count collapse on the closed enum surface: when
        // every observed cell shares the same count, peak and trough
        // coincide on the support, so modality_class lands in one of
        // two variants — StrictModalStrictAntimodal on the singleton
        // shape (where peak and trough collapse onto the lone cell),
        // or TiedModalTiedAntimodal on every multi-cell uniform-count
        // shape (where both level sets equal the support). Lockstep
        // with the existing uniform-count collapse laws on
        // is_modally_tied and is_antimodally_tied — the closed-enum
        // surface reads the same boundary at one classifier-corner
        // emission rather than two named-boolean reads.
        let singleton_multi: AxisHistogram<DiffLineKind> =
            [DiffLineKind::Added, DiffLineKind::Added]
                .iter()
                .copied()
                .collect();
        assert!(singleton_multi.is_uniform_count());
        assert!(singleton_multi.has_singular_support());
        assert_eq!(
            singleton_multi.modality_class(),
            ModalityClass::StrictModalStrictAntimodal,
        );

        let two_cell_uniform: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Removed,
        ]
        .iter()
        .copied()
        .collect();
        assert!(two_cell_uniform.is_uniform_count());
        assert!(!two_cell_uniform.has_singular_support());
        assert_eq!(
            two_cell_uniform.modality_class(),
            ModalityClass::TiedModalTiedAntimodal,
        );

        let cover: AxisHistogram<DiffLineKind> = [
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ]
        .into_iter()
        .collect();
        assert!(cover.is_uniform_count());
        assert!(!cover.has_singular_support());
        assert_eq!(
            cover.modality_class(),
            ModalityClass::TiedModalTiedAntimodal
        );
    }

    #[test]
    fn axis_histogram_modality_class_total_classification_partitions_every_shape() {
        // Total/disjoint witness on the closed enum: every histogram
        // shape lands in exactly one of the five variants — the
        // classification is a partition over the histogram surface,
        // not a multi-class tagging. Pinned across the six canonical
        // shape representatives (empty, singleton, strict/strict,
        // tied/strict, strict/tied, tied/tied) on DiffLineKind, each
        // landing in its named corner and never any other. The
        // five-variant exhaustiveness check (every variant must be
        // hit by some test shape) is pinned by the classifies_all_five_corners
        // test above; this law adds the disjointness side.
        let representatives: [(&[DiffLineKind], ModalityClass); 6] = [
            (&[], ModalityClass::Empty),
            (
                &[DiffLineKind::Added],
                ModalityClass::StrictModalStrictAntimodal,
            ),
            (
                &[
                    DiffLineKind::Added,
                    DiffLineKind::Added,
                    DiffLineKind::Added,
                    DiffLineKind::Removed,
                    DiffLineKind::Removed,
                    DiffLineKind::Context,
                ],
                ModalityClass::StrictModalStrictAntimodal,
            ),
            (
                &[
                    DiffLineKind::Added,
                    DiffLineKind::Added,
                    DiffLineKind::Removed,
                    DiffLineKind::Removed,
                    DiffLineKind::Context,
                ],
                ModalityClass::TiedModalStrictAntimodal,
            ),
            (
                &[
                    DiffLineKind::Added,
                    DiffLineKind::Added,
                    DiffLineKind::Added,
                    DiffLineKind::Removed,
                    DiffLineKind::Context,
                ],
                ModalityClass::StrictModalTiedAntimodal,
            ),
            (
                &[
                    DiffLineKind::Added,
                    DiffLineKind::Added,
                    DiffLineKind::Removed,
                    DiffLineKind::Removed,
                ],
                ModalityClass::TiedModalTiedAntimodal,
            ),
        ];
        for (input, expected) in representatives {
            let hist: AxisHistogram<DiffLineKind> = input.iter().copied().collect();
            let actual = hist.modality_class();
            assert_eq!(
                actual, expected,
                "shape {input:?} must classify as {expected:?}, got {actual:?}",
            );
            for &other in ModalityClass::ALL {
                if other != expected {
                    assert_ne!(
                        actual, other,
                        "shape {input:?} must NOT classify as {other:?}",
                    );
                }
            }
        }
    }

    #[test]
    fn axis_histogram_modality_class_observation_order_invariant() {
        // The classification is invariant under observation order on
        // the multiset of inputs (because modality_degree is, because
        // peak_multiplicity and trough_multiplicity are, because the
        // underlying contiguous counts vector is invariant under
        // observation order). Pinned by collecting the same multiset
        // in two orders and asserting equal classifications. Peer to
        // the identical invariant on modality_degree
        // (axis_histogram_modality_degree_observation_order_invariant).
        let multiset_a = [
            DiffLineKind::Added,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Context,
        ];
        let multiset_b = [
            DiffLineKind::Context,
            DiffLineKind::Added,
            DiffLineKind::Removed,
            DiffLineKind::Added,
        ];
        let hist_a: AxisHistogram<DiffLineKind> = multiset_a.iter().copied().collect();
        let hist_b: AxisHistogram<DiffLineKind> = multiset_b.iter().copied().collect();
        assert_eq!(hist_a.modality_degree(), hist_b.modality_degree());
        assert_eq!(hist_a.modality_class(), hist_b.modality_class());
    }

    #[test]
    fn modality_class_as_str_pins_canonical_kebab_case_labels() {
        // Pin the canonical name of every variant verbatim — the five
        // labels form the operator-facing surface every downstream
        // serializer/deserializer keys on, so a typo or a rename here
        // breaks every consumer at one site. Lockstep with the
        // round-trip / case-insensitivity / distinctness laws below.
        assert_eq!(ModalityClass::Empty.as_str(), "empty");
        assert_eq!(
            ModalityClass::StrictModalStrictAntimodal.as_str(),
            "strict-modal-strict-antimodal",
        );
        assert_eq!(
            ModalityClass::TiedModalStrictAntimodal.as_str(),
            "tied-modal-strict-antimodal",
        );
        assert_eq!(
            ModalityClass::StrictModalTiedAntimodal.as_str(),
            "strict-modal-tied-antimodal",
        );
        assert_eq!(
            ModalityClass::TiedModalTiedAntimodal.as_str(),
            "tied-modal-tied-antimodal",
        );
    }

    #[test]
    fn modality_class_as_str_round_trips_via_from_canonical_str() {
        // Round-trip law: ModalityClass::from_canonical_str(v.as_str())
        // == Some(v) for every v: ModalityClass. The inherent pair
        // mirrors the trait pair on ClosedAxisLabel structurally; the
        // law holds by construction over Self::ALL.
        for &v in ModalityClass::ALL {
            let rendered = v.as_str();
            let parsed = ModalityClass::from_canonical_str(rendered);
            assert_eq!(
                parsed,
                Some(v),
                "round-trip failed for {v:?}: as_str={rendered:?} did not parse back",
            );
        }
    }

    #[test]
    fn modality_class_from_canonical_str_is_case_insensitive() {
        // Case-insensitivity law: the rendered label uppercased parses
        // back to the same variant. The inherent from_canonical_str
        // uses eq_ignore_ascii_case, so the law is structural; this
        // pin re-states it once on the ModalityClass surface so a
        // future implementation tightening that drops the case-fold
        // breaks here rather than at the consumer.
        for &v in ModalityClass::ALL {
            let upper = v.as_str().to_ascii_uppercase();
            assert_eq!(
                ModalityClass::from_canonical_str(&upper),
                Some(v),
                "case-insensitive round-trip failed for {v:?}: uppercase {upper:?} did not parse back",
            );
            let mut mixed = String::with_capacity(upper.len());
            for (i, c) in v.as_str().chars().enumerate() {
                if i % 2 == 0 {
                    mixed.extend(c.to_uppercase());
                } else {
                    mixed.push(c);
                }
            }
            assert_eq!(
                ModalityClass::from_canonical_str(&mixed),
                Some(v),
                "mixed-case round-trip failed for {v:?}: {mixed:?} did not parse back",
            );
        }
    }

    #[test]
    fn modality_class_as_str_labels_pairwise_distinct() {
        // Distinctness law: a.as_str() != b.as_str() for a != b:
        // ModalityClass. The labels are an injection from the variant
        // tag into the canonical-name space; a duplicated label would
        // collapse two classifier corners onto the same parse result
        // and silently break the round-trip law on at least one
        // variant. Quadratic walk over the five-entry ALL slice — the
        // cost is fixed and negligible.
        let labels: Vec<(ModalityClass, &'static str)> = ModalityClass::ALL
            .iter()
            .copied()
            .map(|v| (v, v.as_str()))
            .collect();
        for (i, (a, label_a)) in labels.iter().enumerate() {
            for (b, label_b) in labels.iter().skip(i + 1) {
                assert_ne!(
                    label_a, label_b,
                    "distinct variants {a:?} and {b:?} must have distinct labels (both {label_a:?})",
                );
            }
        }
    }

    #[test]
    fn modality_class_as_str_labels_nonempty() {
        // Non-emptiness law: every variant's canonical label is a
        // non-empty string. Composes with the empty-string rejection
        // law on from_canonical_str — no canonical label can be empty,
        // so the parse rejects "" by construction.
        for &v in ModalityClass::ALL {
            assert!(
                !v.as_str().is_empty(),
                "as_str must never return empty for variant {v:?}",
            );
        }
    }

    #[test]
    fn modality_class_from_canonical_str_rejects_empty_string() {
        // Empty-parse-rejection law: from_canonical_str("") == None.
        // Composes with the non-emptiness law above — because no
        // canonical label is empty, the parse rejects "" structurally.
        // The pin holds the inherent parse honest at one site so a
        // future override accidentally accepting "" breaks here.
        assert_eq!(ModalityClass::from_canonical_str(""), None);
    }

    #[test]
    fn modality_class_from_canonical_str_rejects_unknown_labels() {
        // The parse rejects any input not matching some variant's
        // canonical name. Pinned across several near-misses
        // (snake_case identifier, partial match dropping an axis
        // state, off-by-one kebab segment, surrounding whitespace,
        // trailing newline, arbitrary non-label) so a regression that
        // silently maps unknown inputs to some default is caught here.
        // The PascalCase variant identifier "Empty" / single-word
        // labels parse case-insensitively via the inherent fold
        // (eq_ignore_ascii_case) — case is not part of the canonical
        // discipline, so those forms succeed and are not exercised
        // here.
        for unknown in [
            "StrictModalStrictAntimodal", // PascalCase multi-word: rejected by kebab separator.
            "strict_modal_strict_antimodal", // snake_case multi-word: rejected by kebab separator.
            "strict-modal-antimodal",     // partial -- missing axis state.
            "tied-modal",                 // partial -- single axis.
            "kebab-other-thing",          // unrelated kebab token.
            " empty ",                    // surrounding whitespace.
            "empty\n",                    // trailing newline.
            "tied-modal-tied-antimodal-x", // suffix beyond canonical name.
            "x-tied-modal-tied-antimodal", // prefix beyond canonical name.
        ] {
            assert_eq!(
                ModalityClass::from_canonical_str(unknown),
                None,
                "unknown input {unknown:?} must not parse to any variant",
            );
        }
    }

    #[test]
    fn modality_class_display_delegates_to_as_str() {
        // Display delegates to as_str pointwise — the rendered string
        // is exactly the canonical label, no surrounding ceremony.
        // Pinned across every variant so an accidental Display override
        // (e.g. emitting Debug or adding a wrapper) is caught here.
        for &v in ModalityClass::ALL {
            assert_eq!(
                format!("{v}"),
                v.as_str(),
                "Display must render canonical label for {v:?}",
            );
        }
    }

    #[test]
    fn modality_class_from_str_round_trips_through_display() {
        // (Display, FromStr) round-trip pair on the variant-tag surface
        // — the canonical Rust stdlib duality every operator-facing
        // serializable typescape primitive carries. Pinned across every
        // variant via str::parse on the Display-rendered string.
        for &v in ModalityClass::ALL {
            let rendered = v.to_string();
            let parsed: ModalityClass = rendered
                .parse()
                .expect("Display output must parse via FromStr");
            assert_eq!(
                parsed, v,
                "round-trip via (Display, FromStr) failed for {v:?}",
            );
        }
    }

    #[test]
    fn modality_class_from_str_is_case_insensitive() {
        // The FromStr impl inherits case-insensitivity from
        // from_canonical_str. Pinned at the consumer-facing
        // str::parse surface across every variant.
        for &v in ModalityClass::ALL {
            let upper = v.as_str().to_ascii_uppercase();
            let parsed: ModalityClass = upper
                .parse()
                .expect("uppercase label must parse via FromStr");
            assert_eq!(parsed, v, "uppercase FromStr round-trip failed for {v:?}",);
        }
    }

    #[test]
    fn modality_class_from_str_reports_unknown_label_verbatim() {
        // The FromStr error carries the offending input verbatim in
        // the `label` field so a downstream consumer can localize the
        // failure to the surrounding context (a YAML attestation
        // manifest field, a structured-log field value, a CLI
        // argument). Pinned across two distinct unknown labels so a
        // regression that returns a constant placeholder rather than
        // the offending input breaks here.
        for unknown in ["totally-unknown", "EmptyKebabViolation"] {
            let err = unknown
                .parse::<ModalityClass>()
                .expect_err("unknown label must error");
            assert_eq!(
                err.label, unknown,
                "ParseModalityClassError must carry offending label verbatim",
            );
            // The Display impl mentions the offending label so the
            // operator-facing error message localizes the failure.
            let rendered = err.to_string();
            assert!(
                rendered.contains(unknown),
                "Display of ParseModalityClassError must mention offending label {unknown:?}, got {rendered:?}",
            );
        }
    }

    #[test]
    fn modality_class_parse_error_satisfies_std_error_trait() {
        // The ParseModalityClassError satisfies std::error::Error so
        // a `Result<_, Box<dyn Error>>` or `eyre::Result<_>` consumer
        // can chain the error through the canonical Rust error
        // surface. Pinned by upcasting to `&dyn std::error::Error`
        // through a type-checked binding; a regression that drops the
        // `impl Error for …` declaration fails compilation here.
        let err = "totally-unknown"
            .parse::<ModalityClass>()
            .expect_err("unknown label must error");
        let as_error: &dyn std::error::Error = &err;
        // `source()` returns None (no underlying cause), and `to_string`
        // produces the Display rendering through the `Error: Display`
        // supertrait bound.
        assert!(as_error.source().is_none());
        assert_eq!(as_error.to_string(), err.to_string());
    }

    #[test]
    fn modality_class_as_str_image_equals_for_each_classifier_corner_set() {
        // The five canonical labels exhaust the as_str image of
        // ModalityClass::ALL — total/disjoint witness over the label
        // image. Pinned as a HashSet equality between the canonical
        // five-label image and the as_str projection of ALL: a future
        // variant addition that forgets to extend as_str produces a
        // duplicate or missing label and breaks this assertion at one
        // site.
        use std::collections::HashSet;
        let image: HashSet<&'static str> = ModalityClass::ALL
            .iter()
            .copied()
            .map(ModalityClass::as_str)
            .collect();
        let expected: HashSet<&'static str> = [
            "empty",
            "strict-modal-strict-antimodal",
            "tied-modal-strict-antimodal",
            "strict-modal-tied-antimodal",
            "tied-modal-tied-antimodal",
        ]
        .into_iter()
        .collect();
        assert_eq!(
            image, expected,
            "as_str image must equal the canonical five-label set",
        );
        assert_eq!(image.len(), ModalityClass::ALL.len());
    }

    #[test]
    fn modality_class_serde_yaml_round_trips_over_every_variant() {
        // Canonical serde YAML (Serialize, Deserialize) round-trip law
        // on the variant-tag surface — every variant serializes to a
        // YAML scalar that deserializes back to itself. Lowers through
        // the same (Display, FromStr) pair the round-trip law on
        // ModalityClass already pins, so the serde idiom-peer inherits
        // the round-trip discipline by construction. Pinned across
        // every variant of ModalityClass::ALL so a future serialize
        // override that drifts from the canonical-label projection
        // breaks here at one site rather than at every emitter.
        for &v in ModalityClass::ALL {
            let yaml = serde_yaml::to_string(&v)
                .unwrap_or_else(|e| panic!("must serialize {v:?} to YAML: {e}"));
            let parsed: ModalityClass = serde_yaml::from_str(&yaml).unwrap_or_else(|e| {
                panic!("YAML emission for {v:?} must deserialize back: {e}\n  yaml: {yaml:?}")
            });
            assert_eq!(
                parsed, v,
                "serde YAML round-trip must be identity for {v:?}"
            );
        }
    }

    #[test]
    fn modality_class_serde_json_round_trips_over_every_variant() {
        // Peer of the YAML round-trip on the JSON serializer — JSON
        // emits the scalar as a quoted string, which makes the literal
        // emission shape predictable across every variant. The
        // round-trip lowers through the same (Display, FromStr)
        // bijection the YAML peer carries.
        for &v in ModalityClass::ALL {
            let json = serde_json::to_string(&v)
                .unwrap_or_else(|e| panic!("must serialize {v:?} to JSON: {e}"));
            // JSON emits the variant tag as a single quoted string
            // wrapping the canonical label verbatim. Pin the literal
            // shape so a future drift in the lowering (a switch from
            // serialize_str to a struct/map representation) surfaces
            // here at the concrete-variant assertion.
            assert_eq!(
                json,
                format!("\"{}\"", v.as_str()),
                "JSON emission for {v:?} must be the quoted canonical label",
            );
            let parsed: ModalityClass = serde_json::from_str(&json).unwrap_or_else(|e| {
                panic!("JSON emission for {v:?} must deserialize back: {e}\n  json: {json}")
            });
            assert_eq!(
                parsed, v,
                "serde JSON round-trip must be identity for {v:?}"
            );
        }
    }

    #[test]
    fn modality_class_serde_yaml_is_case_insensitive() {
        // The Deserialize impl inherits case-insensitivity from FromStr
        // (through from_canonical_str's str::eq_ignore_ascii_case). A
        // YAML scalar carrying the uppercase form of a canonical label
        // parses to the same variant. Pinned across every variant so a
        // regression that adds a stricter-case deserialize path breaks
        // here at one site.
        for &v in ModalityClass::ALL {
            let upper = v.as_str().to_ascii_uppercase();
            let yaml = format!("\"{upper}\"\n");
            let parsed: ModalityClass = serde_yaml::from_str(&yaml).unwrap_or_else(|e| {
                panic!("uppercase YAML scalar for {v:?} must deserialize: {e}\n  yaml: {yaml:?}")
            });
            assert_eq!(
                parsed, v,
                "uppercase serde YAML round-trip must recover {v:?}",
            );
        }
    }

    #[test]
    fn modality_class_serde_yaml_unknown_label_error_carries_label_verbatim() {
        // The unknown-label rejection mode lifted to the serde error
        // site: a YAML scalar carrying a sentinel that does not match
        // any canonical name surfaces as a serde_yaml::Error whose
        // Display rendering carries the offending substring verbatim
        // through the ParseModalityClassError Display impl routed
        // through serde::de::Error::custom. Pinned so a future
        // refactor of the deserialize-error path that drops the
        // verbatim-label discipline breaks here at one site.
        let sentinel = "__shikumi_unknown_modality_class_sentinel__";
        let yaml = format!("\"{sentinel}\"\n");
        let result: Result<ModalityClass, _> = serde_yaml::from_str(&yaml);
        match result {
            Err(e) => {
                let rendered = format!("{e}");
                assert!(
                    rendered.contains(sentinel),
                    "serde YAML error must carry the unknown sentinel verbatim, got: {rendered}",
                );
            }
            Ok(other) => panic!("YAML carrying unknown label must reject, got {other:?}"),
        }
    }

    #[test]
    fn modality_class_serde_yaml_emits_canonical_label_substring_for_every_variant() {
        // Concrete YAML pin on the serde emission shape: every variant
        // serializes to a YAML scalar that contains the canonical
        // as_str label as a substring. The exact quoting style is
        // left to serde_yaml (kebab-case scalars carrying `-` may
        // emit unquoted or single-quoted depending on the emitter
        // path), but the canonical label must appear verbatim. A
        // future drift in the lowering (a switch from serialize_str
        // to a tagged map representation, an emission-format change
        // that re-cases the label) surfaces here at one site across
        // every variant.
        for &v in ModalityClass::ALL {
            let yaml = serde_yaml::to_string(&v).unwrap();
            assert!(
                yaml.contains(v.as_str()),
                "YAML emission for {v:?} must contain canonical label {:?}, got: {yaml:?}",
                v.as_str(),
            );
        }
    }

    // ---- SupportCardinalityClass surface ---------------------------------

    #[test]
    fn support_cardinality_class_all_has_five_entries() {
        // Five-cell partition of the support-cardinality interval —
        // Empty / SingularSupport / StrictPartialCover / SingularGap
        // / FullCover. Peer to ModalityClass::ALL on the sibling
        // typed classifier.
        assert_eq!(SupportCardinalityClass::ALL.len(), 5);
    }

    #[test]
    fn support_cardinality_class_all_entries_are_pairwise_distinct() {
        for (i, a) in SupportCardinalityClass::ALL.iter().enumerate() {
            for (j, b) in SupportCardinalityClass::ALL.iter().enumerate() {
                if i != j {
                    assert_ne!(a, b, "ALL[{i}] = {a:?} must differ from ALL[{j}] = {b:?}",);
                }
            }
        }
    }

    #[test]
    fn support_cardinality_class_corner_predicates_partition_every_variant() {
        // Each variant fires exactly one of the five corner predicates,
        // so the boolean-projection vector is a singleton across ALL.
        for &class in SupportCardinalityClass::ALL {
            let fires = u32::from(class.is_empty())
                + u32::from(class.is_singular_support())
                + u32::from(class.is_strict_partial_cover())
                + u32::from(class.is_singular_gap())
                + u32::from(class.is_full_cover());
            assert_eq!(
                fires, 1,
                "exactly one corner predicate must fire on every variant \
                 (got fires={fires}) on class {class:?}",
            );
        }
    }

    #[test]
    fn support_cardinality_class_is_partial_cover_fires_on_three_middle_variants() {
        // Behavioral pin on the variant-tag projection — the
        // compound predicate fires on exactly the three middle
        // variants (SingularSupport, StrictPartialCover, SingularGap)
        // and reads `false` on both boundary corners (Empty,
        // FullCover). The "three middle, two boundaries" partition
        // of the five-corner surface.
        assert!(!SupportCardinalityClass::Empty.is_partial_cover());
        assert!(SupportCardinalityClass::SingularSupport.is_partial_cover());
        assert!(SupportCardinalityClass::StrictPartialCover.is_partial_cover());
        assert!(SupportCardinalityClass::SingularGap.is_partial_cover());
        assert!(!SupportCardinalityClass::FullCover.is_partial_cover());
    }

    #[test]
    fn support_cardinality_class_is_partial_cover_equals_not_empty_and_not_full_cover() {
        // Defining equivalence on the two-corner boundary
        // complement: `is_partial_cover() == !is_empty() &&
        // !is_full_cover()` for every variant. Pins the boundary
        // form of the compound predicate.
        for &class in SupportCardinalityClass::ALL {
            assert_eq!(
                class.is_partial_cover(),
                !class.is_empty() && !class.is_full_cover(),
                "is_partial_cover must equal the not-empty-and-not-full-cover \
                 boundary-complement form on {class:?}",
            );
        }
    }

    #[test]
    fn support_cardinality_class_is_partial_cover_equals_three_middle_variant_disjunction() {
        // Union-of-middle-variants form: `is_partial_cover() ==
        // is_singular_support() || is_strict_partial_cover() ||
        // is_singular_gap()` for every variant. Pins the
        // disjunction form on the three named single-variant peers.
        for &class in SupportCardinalityClass::ALL {
            assert_eq!(
                class.is_partial_cover(),
                class.is_singular_support()
                    || class.is_strict_partial_cover()
                    || class.is_singular_gap(),
                "is_partial_cover must equal the three-middle-variant disjunction \
                 form on {class:?}",
            );
        }
    }

    #[test]
    fn support_cardinality_class_trichotomy_partitions_every_variant() {
        // Coverage-trichotomy partition law on the typed-class
        // surface: `(is_empty, is_partial_cover, is_full_cover)` is
        // a strict partition — exactly one of the three corners
        // fires on every variant. The class-side peer of the
        // histogram-side trichotomy already pinned across every
        // ClosedAxis implementor by
        // axis_histogram_coverage_trichotomy_partitions_every_histogram_for_every_closed_axis_implementor.
        for &class in SupportCardinalityClass::ALL {
            let fires = u32::from(class.is_empty())
                + u32::from(class.is_partial_cover())
                + u32::from(class.is_full_cover());
            assert_eq!(
                fires, 1,
                "exactly one of (is_empty, is_partial_cover, is_full_cover) \
                 must fire on every variant (got fires={fires}) on class {class:?}",
            );
        }
    }

    #[test]
    fn support_cardinality_class_three_middle_variant_predicates_imply_is_partial_cover() {
        // Implication chain: each of the three middle single-
        // variant predicates implies the compound `is_partial_cover`.
        // The structural witness of the union-of-middle-variants
        // form on each implicant.
        for &class in SupportCardinalityClass::ALL {
            if class.is_singular_support() {
                assert!(
                    class.is_partial_cover(),
                    "is_singular_support must imply is_partial_cover on {class:?}",
                );
            }
            if class.is_strict_partial_cover() {
                assert!(
                    class.is_partial_cover(),
                    "is_strict_partial_cover must imply is_partial_cover on {class:?}",
                );
            }
            if class.is_singular_gap() {
                assert!(
                    class.is_partial_cover(),
                    "is_singular_gap must imply is_partial_cover on {class:?}",
                );
            }
        }
    }

    #[test]
    fn support_cardinality_class_is_boundary_fires_on_two_corner_variants() {
        // Behavioral pin on the variant-tag projection — the
        // compound predicate fires on exactly the two boundary
        // corners (Empty, FullCover) and reads `false` on all three
        // middle variants (SingularSupport, StrictPartialCover,
        // SingularGap). The structural dual of the "three middle,
        // two boundaries" partition `is_partial_cover` carries.
        assert!(SupportCardinalityClass::Empty.is_boundary());
        assert!(!SupportCardinalityClass::SingularSupport.is_boundary());
        assert!(!SupportCardinalityClass::StrictPartialCover.is_boundary());
        assert!(!SupportCardinalityClass::SingularGap.is_boundary());
        assert!(SupportCardinalityClass::FullCover.is_boundary());
    }

    #[test]
    fn support_cardinality_class_is_boundary_equals_is_empty_or_is_full_cover() {
        // Defining equivalence on the two-corner boundary union:
        // `is_boundary() == is_empty() || is_full_cover()` for every
        // variant. Pins the union-of-boundary-variants form on the
        // two named single-variant peers.
        for &class in SupportCardinalityClass::ALL {
            assert_eq!(
                class.is_boundary(),
                class.is_empty() || class.is_full_cover(),
                "is_boundary must equal the is_empty-or-is_full_cover \
                 boundary-union form on {class:?}",
            );
        }
    }

    #[test]
    fn support_cardinality_class_is_boundary_equals_complement_of_is_partial_cover() {
        // Strict-complement equivalence on the middle compound:
        // `is_boundary() == !is_partial_cover()` for every variant.
        // Pins the dual relationship — the (is_boundary,
        // is_partial_cover) pair is the strict negation pair on the
        // five-corner surface.
        for &class in SupportCardinalityClass::ALL {
            assert_eq!(
                class.is_boundary(),
                !class.is_partial_cover(),
                "is_boundary must equal !is_partial_cover on {class:?}",
            );
        }
    }

    #[test]
    fn support_cardinality_class_is_boundary_and_is_partial_cover_form_strict_bipartition() {
        // Strict-bipartition law on the typed-class surface:
        // `(is_boundary, is_partial_cover)` is a strict bipartition —
        // exactly one of the two compounds fires on every variant.
        // The structural dual of the `(is_empty, is_partial_cover,
        // is_full_cover)` trichotomy already pinned: where the
        // trichotomy separates the three named corners, the
        // bipartition fuses the two boundary corners into one
        // compound and the three middle corners into the other.
        for &class in SupportCardinalityClass::ALL {
            let fires = u32::from(class.is_boundary()) + u32::from(class.is_partial_cover());
            assert_eq!(
                fires, 1,
                "exactly one of (is_boundary, is_partial_cover) must fire on every \
                 variant (got fires={fires}) on class {class:?}",
            );
        }
    }

    #[test]
    fn support_cardinality_class_two_boundary_variant_predicates_imply_is_boundary() {
        // Implication chain: each of the two boundary single-
        // variant predicates implies the compound `is_boundary`. The
        // structural witness of the union-of-boundary-variants form
        // on each implicant — peer to the implication chain over the
        // three middle variants pinned on `is_partial_cover`.
        for &class in SupportCardinalityClass::ALL {
            if class.is_empty() {
                assert!(
                    class.is_boundary(),
                    "is_empty must imply is_boundary on {class:?}",
                );
            }
            if class.is_full_cover() {
                assert!(
                    class.is_boundary(),
                    "is_full_cover must imply is_boundary on {class:?}",
                );
            }
        }
    }

    #[test]
    fn support_cardinality_class_is_singular_fires_on_two_near_boundary_variants() {
        // Behavioral pin on the variant-tag projection — the
        // compound predicate fires on exactly the two singular
        // near-boundary corners (SingularSupport, SingularGap) and
        // reads `false` on all three other variants (Empty,
        // StrictPartialCover, FullCover). The cells at distance 1
        // from the boundary on the support-cardinality interval.
        assert!(!SupportCardinalityClass::Empty.is_singular());
        assert!(SupportCardinalityClass::SingularSupport.is_singular());
        assert!(!SupportCardinalityClass::StrictPartialCover.is_singular());
        assert!(SupportCardinalityClass::SingularGap.is_singular());
        assert!(!SupportCardinalityClass::FullCover.is_singular());
    }

    #[test]
    fn support_cardinality_class_is_singular_equals_singular_support_or_singular_gap() {
        // Defining equivalence on the union of the two named
        // single-variant peers: `is_singular() ==
        // is_singular_support() || is_singular_gap()` for every
        // variant. Pins the union-of-singular-variants form.
        for &class in SupportCardinalityClass::ALL {
            assert_eq!(
                class.is_singular(),
                class.is_singular_support() || class.is_singular_gap(),
                "is_singular must equal is_singular_support || is_singular_gap on {class:?}",
            );
        }
    }

    #[test]
    fn support_cardinality_class_is_singular_implies_is_partial_cover() {
        // The ternary partition refines the bipartition:
        // `is_singular()` ⇒ `is_partial_cover()` on every variant.
        // Every singular cell lands in the partial-cover middle leg
        // (`is_partial_cover = is_singular ∪ is_strict_partial_cover`).
        for &class in SupportCardinalityClass::ALL {
            if class.is_singular() {
                assert!(
                    class.is_partial_cover(),
                    "is_singular must imply is_partial_cover on {class:?}",
                );
            }
        }
    }

    #[test]
    fn support_cardinality_class_is_singular_implies_not_is_boundary() {
        // The two singular cells lie strictly off the boundary
        // corners: `is_singular()` ⇒ `!is_boundary()` on every
        // variant. The ternary partition is disjoint on the
        // (boundary, singular) pair.
        for &class in SupportCardinalityClass::ALL {
            if class.is_singular() {
                assert!(
                    !class.is_boundary(),
                    "is_singular must imply !is_boundary on {class:?}",
                );
            }
        }
    }

    #[test]
    fn support_cardinality_class_is_boundary_is_singular_is_strict_partial_cover_form_strict_ternary_partition()
     {
        // Strict-ternary-partition law on the typed-class surface:
        // `(is_boundary, is_singular, is_strict_partial_cover)` is a
        // strict partition — exactly one of the three compounds fires
        // on every variant. The structural refinement of the
        // (`is_boundary`, `is_partial_cover`) bipartition: the
        // middle leg `is_partial_cover` decomposes into
        // `is_singular ∪ is_strict_partial_cover`, splitting the
        // three middle variants by distance from boundary.
        for &class in SupportCardinalityClass::ALL {
            let fires = u32::from(class.is_boundary())
                + u32::from(class.is_singular())
                + u32::from(class.is_strict_partial_cover());
            assert_eq!(
                fires, 1,
                "exactly one of (is_boundary, is_singular, is_strict_partial_cover) must fire \
                 on every variant (got fires={fires}) on class {class:?}",
            );
        }
    }

    #[test]
    fn support_cardinality_class_two_singular_variant_predicates_imply_is_singular() {
        // Implication chain: each of the two singular single-variant
        // predicates implies the compound `is_singular`. The
        // structural witness of the union-of-singular-variants form
        // on each implicant — peer to the implication chain over the
        // two boundary variants pinned on `is_boundary`.
        for &class in SupportCardinalityClass::ALL {
            if class.is_singular_support() {
                assert!(
                    class.is_singular(),
                    "is_singular_support must imply is_singular on {class:?}",
                );
            }
            if class.is_singular_gap() {
                assert!(
                    class.is_singular(),
                    "is_singular_gap must imply is_singular on {class:?}",
                );
            }
        }
    }

    #[test]
    fn support_cardinality_class_is_low_support_fires_on_two_low_variants() {
        // Behavioral pin on the variant-tag projection — the
        // compound predicate fires on exactly the two low-support
        // corners (Empty, SingularSupport) and reads `false` on all
        // three other variants (StrictPartialCover, SingularGap,
        // FullCover). The cells at support magnitude 0 or 1 — the
        // bottom of the support-cardinality interval.
        assert!(SupportCardinalityClass::Empty.is_low_support());
        assert!(SupportCardinalityClass::SingularSupport.is_low_support());
        assert!(!SupportCardinalityClass::StrictPartialCover.is_low_support());
        assert!(!SupportCardinalityClass::SingularGap.is_low_support());
        assert!(!SupportCardinalityClass::FullCover.is_low_support());
    }

    #[test]
    fn support_cardinality_class_is_high_support_fires_on_two_high_variants() {
        // Behavioral pin on the variant-tag projection — the
        // compound predicate fires on exactly the two high-support
        // corners (SingularGap, FullCover) and reads `false` on all
        // three other variants (Empty, SingularSupport,
        // StrictPartialCover). The cells at support magnitude
        // `axis_cardinality - 1` or `axis_cardinality` — the top of
        // the support-cardinality interval.
        assert!(!SupportCardinalityClass::Empty.is_high_support());
        assert!(!SupportCardinalityClass::SingularSupport.is_high_support());
        assert!(!SupportCardinalityClass::StrictPartialCover.is_high_support());
        assert!(SupportCardinalityClass::SingularGap.is_high_support());
        assert!(SupportCardinalityClass::FullCover.is_high_support());
    }

    #[test]
    fn support_cardinality_class_is_low_support_equals_empty_or_singular_support() {
        // Defining equivalence on the union of the two named
        // single-variant peers: `is_low_support() == is_empty()
        // || is_singular_support()` for every variant. Pins the
        // union-of-low-variants form.
        for &class in SupportCardinalityClass::ALL {
            assert_eq!(
                class.is_low_support(),
                class.is_empty() || class.is_singular_support(),
                "is_low_support must equal is_empty || is_singular_support on {class:?}",
            );
        }
    }

    #[test]
    fn support_cardinality_class_is_high_support_equals_singular_gap_or_full_cover() {
        // Defining equivalence on the union of the two named
        // single-variant peers: `is_high_support() == is_singular_gap()
        // || is_full_cover()` for every variant. Pins the
        // union-of-high-variants form — the mirror peer of the
        // low-support defining equivalence across the
        // StrictPartialCover middle leg.
        for &class in SupportCardinalityClass::ALL {
            assert_eq!(
                class.is_high_support(),
                class.is_singular_gap() || class.is_full_cover(),
                "is_high_support must equal is_singular_gap || is_full_cover on {class:?}",
            );
        }
    }

    #[test]
    fn support_cardinality_class_is_low_support_and_is_high_support_are_disjoint() {
        // Disjointness law: the two magnitude-direction compound
        // predicates never fire on the same variant. The bottom and
        // top halves of the support-cardinality interval are
        // strictly separated by the StrictPartialCover middle leg.
        for &class in SupportCardinalityClass::ALL {
            assert!(
                !(class.is_low_support() && class.is_high_support()),
                "is_low_support and is_high_support must be disjoint on {class:?}",
            );
        }
    }

    #[test]
    fn support_cardinality_class_is_low_support_is_strict_partial_cover_is_high_support_form_strict_ternary_partition()
     {
        // Strict-ternary-partition law on the typed-class surface:
        // `(is_low_support, is_strict_partial_cover, is_high_support)`
        // is a strict partition — exactly one of the three compounds
        // fires on every variant. The second strict ternary partition
        // of the five-corner support-cardinality surface, *orthogonal*
        // to the (`is_boundary`, `is_singular`, `is_strict_partial_cover`)
        // ternary partition by distance from boundary: both partitions
        // share the StrictPartialCover middle leg but split the four
        // non-interior corners on different axes (distance partition:
        // {Empty, FullCover} / {SingularSupport, SingularGap};
        // magnitude partition: {Empty, SingularSupport} / {SingularGap,
        // FullCover}).
        for &class in SupportCardinalityClass::ALL {
            let fires = u32::from(class.is_low_support())
                + u32::from(class.is_strict_partial_cover())
                + u32::from(class.is_high_support());
            assert_eq!(
                fires, 1,
                "exactly one of (is_low_support, is_strict_partial_cover, is_high_support) must \
                 fire on every variant (got fires={fires}) on class {class:?}",
            );
        }
    }

    #[test]
    fn support_cardinality_class_two_low_variant_predicates_imply_is_low_support() {
        // Implication chain: each of the two low single-variant
        // predicates implies the compound `is_low_support`. The
        // structural witness of the union-of-low-variants form on
        // each implicant — peer to the implication chain over the
        // two boundary variants pinned on `is_boundary` and the two
        // singular variants pinned on `is_singular`.
        for &class in SupportCardinalityClass::ALL {
            if class.is_empty() {
                assert!(
                    class.is_low_support(),
                    "is_empty must imply is_low_support on {class:?}",
                );
            }
            if class.is_singular_support() {
                assert!(
                    class.is_low_support(),
                    "is_singular_support must imply is_low_support on {class:?}",
                );
            }
        }
    }

    #[test]
    fn support_cardinality_class_two_high_variant_predicates_imply_is_high_support() {
        // Implication chain: each of the two high single-variant
        // predicates implies the compound `is_high_support`. The
        // structural witness of the union-of-high-variants form on
        // each implicant — the mirror peer of the low-support
        // implication chain across the StrictPartialCover middle leg.
        for &class in SupportCardinalityClass::ALL {
            if class.is_singular_gap() {
                assert!(
                    class.is_high_support(),
                    "is_singular_gap must imply is_high_support on {class:?}",
                );
            }
            if class.is_full_cover() {
                assert!(
                    class.is_high_support(),
                    "is_full_cover must imply is_high_support on {class:?}",
                );
            }
        }
    }

    #[test]
    fn support_cardinality_class_is_low_support_decomposes_distance_partition_bottom_corners() {
        // Cross-partition factorization law on the two non-interior
        // bottom corners: `is_low_support ∩ is_boundary = is_empty`
        // and `is_low_support ∩ is_singular = is_singular_support`.
        // Pins the structural recovery of the two named single-
        // variant peers as intersections of the two orthogonal
        // ternary partitions on the bottom side.
        for &class in SupportCardinalityClass::ALL {
            assert_eq!(
                class.is_low_support() && class.is_boundary(),
                class.is_empty(),
                "is_low_support && is_boundary must equal is_empty on {class:?}",
            );
            assert_eq!(
                class.is_low_support() && class.is_singular(),
                class.is_singular_support(),
                "is_low_support && is_singular must equal is_singular_support on {class:?}",
            );
        }
    }

    #[test]
    fn support_cardinality_class_is_high_support_decomposes_distance_partition_top_corners() {
        // Mirror peer of the bottom-corner factorization law:
        // `is_high_support ∩ is_boundary = is_full_cover` and
        // `is_high_support ∩ is_singular = is_singular_gap`. Pins
        // the structural recovery of the two named single-variant
        // peers on the top side.
        for &class in SupportCardinalityClass::ALL {
            assert_eq!(
                class.is_high_support() && class.is_boundary(),
                class.is_full_cover(),
                "is_high_support && is_boundary must equal is_full_cover on {class:?}",
            );
            assert_eq!(
                class.is_high_support() && class.is_singular(),
                class.is_singular_gap(),
                "is_high_support && is_singular must equal is_singular_gap on {class:?}",
            );
        }
    }

    #[test]
    fn support_cardinality_class_as_str_round_trips_via_from_canonical_str() {
        for &v in SupportCardinalityClass::ALL {
            assert_eq!(
                SupportCardinalityClass::from_canonical_str(v.as_str()),
                Some(v),
                "as_str / from_canonical_str round-trip for {v:?}",
            );
        }
    }

    #[test]
    fn support_cardinality_class_as_str_labels_pairwise_distinct() {
        for (i, a) in SupportCardinalityClass::ALL.iter().enumerate() {
            for (j, b) in SupportCardinalityClass::ALL.iter().enumerate() {
                if i != j {
                    assert_ne!(
                        a.as_str(),
                        b.as_str(),
                        "as_str must distinguish ALL[{i}] = {a:?} from ALL[{j}] = {b:?}",
                    );
                }
            }
        }
    }

    #[test]
    fn support_cardinality_class_as_str_labels_nonempty() {
        for &v in SupportCardinalityClass::ALL {
            assert!(
                !v.as_str().is_empty(),
                "as_str label must be nonempty for {v:?}",
            );
        }
    }

    #[test]
    fn support_cardinality_class_from_canonical_str_is_case_insensitive() {
        for &v in SupportCardinalityClass::ALL {
            assert_eq!(
                SupportCardinalityClass::from_canonical_str(&v.as_str().to_ascii_uppercase()),
                Some(v),
                "case-insensitive parse must recover {v:?}",
            );
        }
    }

    #[test]
    fn support_cardinality_class_from_canonical_str_rejects_empty_string() {
        assert_eq!(SupportCardinalityClass::from_canonical_str(""), None);
    }

    #[test]
    fn support_cardinality_class_from_str_round_trips_through_display() {
        for &v in SupportCardinalityClass::ALL {
            let rendered = v.to_string();
            let parsed: SupportCardinalityClass = rendered.parse().unwrap();
            assert_eq!(parsed, v, "Display / FromStr round-trip for {v:?}");
        }
    }

    #[test]
    fn support_cardinality_class_from_str_rejects_unknown_label_with_label_verbatim() {
        let sentinel = "__shikumi_unknown_support_cardinality_class_sentinel__";
        match sentinel.parse::<SupportCardinalityClass>() {
            Err(e) => {
                assert_eq!(e.label, sentinel);
                let rendered = format!("{e}");
                assert!(
                    rendered.contains(sentinel),
                    "Display impl must carry the unknown sentinel verbatim, got: {rendered}",
                );
            }
            Ok(other) => panic!("unknown label must reject, got {other:?}"),
        }
    }

    #[test]
    fn support_cardinality_class_serde_yaml_round_trips_over_every_variant() {
        for &v in SupportCardinalityClass::ALL {
            let yaml = serde_yaml::to_string(&v).unwrap();
            let parsed: SupportCardinalityClass = serde_yaml::from_str(&yaml)
                .unwrap_or_else(|e| panic!("YAML round-trip for {v:?} failed: {e}"));
            assert_eq!(
                parsed, v,
                "serde YAML round-trip must be identity for {v:?}"
            );
        }
    }

    #[test]
    fn support_cardinality_class_serde_json_round_trips_over_every_variant() {
        for &v in SupportCardinalityClass::ALL {
            let json = serde_json::to_string(&v).unwrap();
            assert_eq!(
                json,
                format!("\"{}\"", v.as_str()),
                "JSON emission for {v:?} must be the quoted canonical label",
            );
            let parsed: SupportCardinalityClass = serde_json::from_str(&json).unwrap_or_else(|e| {
                panic!("JSON emission for {v:?} must deserialize back: {e}\n  json: {json}")
            });
            assert_eq!(
                parsed, v,
                "serde JSON round-trip must be identity for {v:?}"
            );
        }
    }

    #[test]
    fn support_cardinality_class_serde_yaml_is_case_insensitive() {
        for &v in SupportCardinalityClass::ALL {
            let upper = v.as_str().to_ascii_uppercase();
            let yaml = format!("\"{upper}\"\n");
            let parsed: SupportCardinalityClass = serde_yaml::from_str(&yaml).unwrap_or_else(|e| {
                panic!("uppercase YAML scalar for {v:?} must deserialize: {e}\n  yaml: {yaml:?}")
            });
            assert_eq!(parsed, v);
        }
    }

    #[test]
    fn support_cardinality_class_serde_yaml_unknown_label_error_carries_label_verbatim() {
        let sentinel = "__shikumi_unknown_support_cardinality_class_sentinel__";
        let yaml = format!("\"{sentinel}\"\n");
        let result: Result<SupportCardinalityClass, _> = serde_yaml::from_str(&yaml);
        match result {
            Err(e) => {
                let rendered = format!("{e}");
                assert!(
                    rendered.contains(sentinel),
                    "serde YAML error must carry the unknown sentinel verbatim, got: {rendered}",
                );
            }
            Ok(other) => panic!("YAML carrying unknown label must reject, got {other:?}"),
        }
    }

    fn assert_support_cardinality_class_empty_is_empty_variant<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Empty histogram lifts to SupportCardinalityClass::Empty
        // uniformly across every implementor.
        let hist = AxisHistogram::<A>::empty();
        assert_eq!(
            hist.support_cardinality_class(),
            SupportCardinalityClass::Empty,
            "empty support_cardinality_class must be Empty on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_support_cardinality_class_singleton_is_singular_support<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Every singleton has distinct_cells() == 1, which on a
        // cardinality-2 axis ALSO satisfies support + 1 == cardinality
        // — the bottom-boundary-first branching priority lands on
        // SingularSupport. On cardinality-1 axes (none in the
        // typescape today) the singleton would be the full cover —
        // but no such axis exists, so this law holds uniformly.
        for observed in axis_iter::<A>() {
            let hist: AxisHistogram<A> = std::iter::once(observed).collect();
            let class = hist.support_cardinality_class();
            // On any cardinality-1 axis the singleton is the full
            // cover; otherwise it's singular support.
            let expected = if axis_cardinality::<A>() == 1 {
                SupportCardinalityClass::FullCover
            } else {
                SupportCardinalityClass::SingularSupport
            };
            assert_eq!(
                class,
                expected,
                "singleton support_cardinality_class for {observed:?} on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_support_cardinality_class_axis_cover_is_full_cover<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Observing every cell exactly once raises distinct_cells()
        // to axis_cardinality::<A>(), so the class reads FullCover
        // uniformly.
        let hist: AxisHistogram<A> = axis_iter::<A>().collect();
        assert_eq!(
            hist.support_cardinality_class(),
            SupportCardinalityClass::FullCover,
            "axis-cover support_cardinality_class on axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_support_cardinality_class_is_empty_agrees_with_histogram_is_empty<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Peer-projection on the empty boundary:
        // hist.support_cardinality_class().is_empty() ==
        // hist.is_empty() — unconditional, holds across every
        // implementor regardless of cardinality.
        let empty = AxisHistogram::<A>::empty();
        assert_eq!(
            empty.support_cardinality_class().is_empty(),
            empty.is_empty(),
        );

        for observed in axis_iter::<A>() {
            let singleton: AxisHistogram<A> = std::iter::once(observed).collect();
            assert_eq!(
                singleton.support_cardinality_class().is_empty(),
                singleton.is_empty(),
                "support_cardinality_class.is_empty must equal is_empty on \
                 singleton {observed:?} for axis {}",
                std::any::type_name::<A>(),
            );
        }

        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        assert_eq!(
            cover.support_cardinality_class().is_empty(),
            cover.is_empty(),
            "support_cardinality_class.is_empty must equal is_empty on \
             axis-cover for axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_support_cardinality_class_is_full_cover_agrees_with_histogram_is_full_cover<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Peer-projection on the full-cover boundary:
        // hist.support_cardinality_class().is_full_cover() ==
        // hist.is_full_cover() — unconditional, holds across every
        // implementor regardless of cardinality.
        let empty = AxisHistogram::<A>::empty();
        assert_eq!(
            empty.support_cardinality_class().is_full_cover(),
            empty.is_full_cover(),
        );

        for observed in axis_iter::<A>() {
            let singleton: AxisHistogram<A> = std::iter::once(observed).collect();
            assert_eq!(
                singleton.support_cardinality_class().is_full_cover(),
                singleton.is_full_cover(),
                "support_cardinality_class.is_full_cover must equal is_full_cover on \
                 singleton {observed:?} for axis {}",
                std::any::type_name::<A>(),
            );
        }

        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        assert_eq!(
            cover.support_cardinality_class().is_full_cover(),
            cover.is_full_cover(),
            "support_cardinality_class.is_full_cover must equal is_full_cover on \
             axis-cover for axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_support_cardinality_class_is_boundary_agrees_with_histogram_is_empty_or_is_full_cover<
        A,
    >()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Cross-surface bridge on the boundary compound:
        // hist.support_cardinality_class().is_boundary() ==
        // hist.is_empty() || hist.is_full_cover() — unconditional,
        // holds across every implementor regardless of cardinality.
        // Pins the class-side compound to the histogram-side
        // disjunction pointwise on every canonical observation shape
        // (empty, every singleton, axis-cover). Peer to the
        // `is_partial_cover` bridge pinned trait-uniformly below.
        let empty = AxisHistogram::<A>::empty();
        assert_eq!(
            empty.support_cardinality_class().is_boundary(),
            empty.is_empty() || empty.is_full_cover(),
            "support_cardinality_class.is_boundary must equal is_empty || is_full_cover on \
             empty for axis {}",
            std::any::type_name::<A>(),
        );

        for observed in axis_iter::<A>() {
            let singleton: AxisHistogram<A> = std::iter::once(observed).collect();
            assert_eq!(
                singleton.support_cardinality_class().is_boundary(),
                singleton.is_empty() || singleton.is_full_cover(),
                "support_cardinality_class.is_boundary must equal is_empty || is_full_cover on \
                 singleton {observed:?} for axis {}",
                std::any::type_name::<A>(),
            );
        }

        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        assert_eq!(
            cover.support_cardinality_class().is_boundary(),
            cover.is_empty() || cover.is_full_cover(),
            "support_cardinality_class.is_boundary must equal is_empty || is_full_cover on \
             axis-cover for axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_support_cardinality_class_is_singular_agrees_with_histogram_has_singular_support_or_has_singular_gap<
        A,
    >()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Cross-surface bridge on the singular near-boundary leg:
        // hist.support_cardinality_class().is_singular() ==
        // hist.has_singular_support() || hist.has_singular_gap() —
        // unconditional, holds across every implementor regardless
        // of cardinality. On cardinality-2 axes both histogram-side
        // predicates fire under the dual-singular collapse and the
        // class-side projection lands on SingularSupport (priority
        // bottom-boundary-first), so the bridge holds pointwise on
        // those axes too. Pins the class-side compound to the
        // histogram-side disjunction pointwise on every canonical
        // observation shape (empty, every singleton, axis-cover).
        let empty = AxisHistogram::<A>::empty();
        assert_eq!(
            empty.support_cardinality_class().is_singular(),
            empty.has_singular_support() || empty.has_singular_gap(),
            "support_cardinality_class.is_singular must equal \
             has_singular_support || has_singular_gap on empty for axis {}",
            std::any::type_name::<A>(),
        );

        for observed in axis_iter::<A>() {
            let singleton: AxisHistogram<A> = std::iter::once(observed).collect();
            assert_eq!(
                singleton.support_cardinality_class().is_singular(),
                singleton.has_singular_support() || singleton.has_singular_gap(),
                "support_cardinality_class.is_singular must equal \
                 has_singular_support || has_singular_gap on singleton {observed:?} for axis {}",
                std::any::type_name::<A>(),
            );
        }

        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        assert_eq!(
            cover.support_cardinality_class().is_singular(),
            cover.has_singular_support() || cover.has_singular_gap(),
            "support_cardinality_class.is_singular must equal \
             has_singular_support || has_singular_gap on axis-cover for axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_support_cardinality_class_is_low_support_agrees_with_histogram_is_empty_or_has_singular_support<
        A,
    >()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Cross-surface bridge on the magnitude-direction ternary
        // partition's bottom leg:
        // hist.support_cardinality_class().is_low_support() ==
        // hist.is_empty() || hist.has_singular_support() —
        // unconditional, holds across every implementor regardless of
        // cardinality. On cardinality-2 axes `has_singular_support`
        // already absorbs the dual-singular collapse (it fires on
        // singletons), and the class-side projection lands singletons
        // on SingularSupport (priority bottom-boundary-first), so the
        // bridge holds pointwise on those axes too. Pins the
        // class-side compound to the histogram-side disjunction
        // pointwise on every canonical observation shape (empty,
        // every singleton, axis-cover).
        let empty = AxisHistogram::<A>::empty();
        assert_eq!(
            empty.support_cardinality_class().is_low_support(),
            empty.is_empty() || empty.has_singular_support(),
            "support_cardinality_class.is_low_support must equal \
             is_empty || has_singular_support on empty for axis {}",
            std::any::type_name::<A>(),
        );

        for observed in axis_iter::<A>() {
            let singleton: AxisHistogram<A> = std::iter::once(observed).collect();
            assert_eq!(
                singleton.support_cardinality_class().is_low_support(),
                singleton.is_empty() || singleton.has_singular_support(),
                "support_cardinality_class.is_low_support must equal \
                 is_empty || has_singular_support on singleton {observed:?} for axis {}",
                std::any::type_name::<A>(),
            );
        }

        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        assert_eq!(
            cover.support_cardinality_class().is_low_support(),
            cover.is_empty() || cover.has_singular_support(),
            "support_cardinality_class.is_low_support must equal \
             is_empty || has_singular_support on axis-cover for axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_support_cardinality_class_is_high_support_agrees_with_histogram_is_full_cover_or_strict_singular_gap<
        A,
    >()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Cross-surface bridge on the magnitude-direction ternary
        // partition's top leg:
        // hist.support_cardinality_class().is_high_support() ==
        // hist.is_full_cover()
        //     || (hist.has_singular_gap() && !hist.has_singular_support())
        // — unconditional, holds across every implementor regardless
        // of cardinality. The `!has_singular_support()` clause excises
        // the cardinality-2 dual-singular collapse case where the
        // histogram-side `has_singular_gap` predicate fires spuriously
        // on singletons (while the class-side projection lands them
        // on SingularSupport, not in the high set). On cardinality-`>= 3`
        // axes the two histogram-side singular predicates are disjoint
        // by construction, so the bridge reduces pointwise to
        // `is_full_cover() || has_singular_gap()` — the expected
        // mirror peer of the `is_low_support` bridge. Pins the
        // class-side compound to the histogram-side disjunction
        // pointwise on every canonical observation shape (empty,
        // every singleton, axis-cover).
        let empty = AxisHistogram::<A>::empty();
        assert_eq!(
            empty.support_cardinality_class().is_high_support(),
            empty.is_full_cover() || (empty.has_singular_gap() && !empty.has_singular_support()),
            "support_cardinality_class.is_high_support must equal \
             is_full_cover || (has_singular_gap && !has_singular_support) on empty for axis {}",
            std::any::type_name::<A>(),
        );

        for observed in axis_iter::<A>() {
            let singleton: AxisHistogram<A> = std::iter::once(observed).collect();
            assert_eq!(
                singleton.support_cardinality_class().is_high_support(),
                singleton.is_full_cover()
                    || (singleton.has_singular_gap() && !singleton.has_singular_support()),
                "support_cardinality_class.is_high_support must equal \
                 is_full_cover || (has_singular_gap && !has_singular_support) on singleton \
                 {observed:?} for axis {}",
                std::any::type_name::<A>(),
            );
        }

        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        assert_eq!(
            cover.support_cardinality_class().is_high_support(),
            cover.is_full_cover() || (cover.has_singular_gap() && !cover.has_singular_support()),
            "support_cardinality_class.is_high_support must equal \
             is_full_cover || (has_singular_gap && !has_singular_support) on axis-cover for axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_support_cardinality_class_is_partial_cover_agrees_with_histogram_has_partial_cover<
        A,
    >()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Cross-surface bridge on the partial-cover middle leg:
        // hist.support_cardinality_class().is_partial_cover() ==
        // hist.has_partial_cover() — unconditional, holds across
        // every implementor regardless of cardinality. Pins the
        // class-side peer to the histogram-side method pointwise on
        // every canonical observation shape (empty, every singleton,
        // axis-cover).
        let empty = AxisHistogram::<A>::empty();
        assert_eq!(
            empty.support_cardinality_class().is_partial_cover(),
            empty.has_partial_cover(),
            "support_cardinality_class.is_partial_cover must equal has_partial_cover on \
             empty for axis {}",
            std::any::type_name::<A>(),
        );

        for observed in axis_iter::<A>() {
            let singleton: AxisHistogram<A> = std::iter::once(observed).collect();
            assert_eq!(
                singleton.support_cardinality_class().is_partial_cover(),
                singleton.has_partial_cover(),
                "support_cardinality_class.is_partial_cover must equal has_partial_cover on \
                 singleton {observed:?} for axis {}",
                std::any::type_name::<A>(),
            );
        }

        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        assert_eq!(
            cover.support_cardinality_class().is_partial_cover(),
            cover.has_partial_cover(),
            "support_cardinality_class.is_partial_cover must equal has_partial_cover on \
             axis-cover for axis {}",
            std::any::type_name::<A>(),
        );
    }

    #[test]
    fn axis_histogram_support_cardinality_class_empty_is_empty_variant_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_support_cardinality_class_empty_is_empty_variant::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_support_cardinality_class_singleton_is_singular_support_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_support_cardinality_class_singleton_is_singular_support::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_support_cardinality_class_axis_cover_is_full_cover_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_support_cardinality_class_axis_cover_is_full_cover::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_support_cardinality_class_is_empty_agrees_with_histogram_is_empty_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_support_cardinality_class_is_empty_agrees_with_histogram_is_empty::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_support_cardinality_class_is_full_cover_agrees_with_histogram_is_full_cover_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_support_cardinality_class_is_full_cover_agrees_with_histogram_is_full_cover::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_support_cardinality_class_is_partial_cover_agrees_with_histogram_has_partial_cover_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_support_cardinality_class_is_partial_cover_agrees_with_histogram_has_partial_cover::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_support_cardinality_class_is_boundary_agrees_with_histogram_is_empty_or_is_full_cover_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_support_cardinality_class_is_boundary_agrees_with_histogram_is_empty_or_is_full_cover::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_support_cardinality_class_is_singular_agrees_with_histogram_has_singular_support_or_has_singular_gap_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_support_cardinality_class_is_singular_agrees_with_histogram_has_singular_support_or_has_singular_gap::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_support_cardinality_class_is_low_support_agrees_with_histogram_is_empty_or_has_singular_support_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_support_cardinality_class_is_low_support_agrees_with_histogram_is_empty_or_has_singular_support::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_support_cardinality_class_is_high_support_agrees_with_histogram_is_full_cover_or_strict_singular_gap_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_support_cardinality_class_is_high_support_agrees_with_histogram_is_full_cover_or_strict_singular_gap::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    fn assert_has_low_support_agrees_with_class_is_low_support<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Cross-surface bridge (histogram side):
        // hist.has_low_support() ==
        // hist.support_cardinality_class().is_low_support() —
        // unconditional, holds across every implementor regardless of
        // cardinality. The two surfaces carry one named boolean each on
        // the magnitude partition's bottom leg.
        let empty = AxisHistogram::<A>::empty();
        assert_eq!(
            empty.has_low_support(),
            empty.support_cardinality_class().is_low_support(),
            "has_low_support must equal support_cardinality_class().is_low_support() \
             on empty for axis {}",
            std::any::type_name::<A>(),
        );

        for observed in axis_iter::<A>() {
            let singleton: AxisHistogram<A> = std::iter::once(observed).collect();
            assert_eq!(
                singleton.has_low_support(),
                singleton.support_cardinality_class().is_low_support(),
                "has_low_support must equal support_cardinality_class().is_low_support() \
                 on singleton {observed:?} for axis {}",
                std::any::type_name::<A>(),
            );
        }

        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        assert_eq!(
            cover.has_low_support(),
            cover.support_cardinality_class().is_low_support(),
            "has_low_support must equal support_cardinality_class().is_low_support() \
             on axis-cover for axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_has_high_support_agrees_with_class_is_high_support<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Cross-surface bridge (histogram side):
        // hist.has_high_support() ==
        // hist.support_cardinality_class().is_high_support() —
        // unconditional. On cardinality-2 axes the bridge holds by
        // construction: the strict-singular-gap formulation of
        // has_high_support excises the dual-singular collapse case
        // (singleton on cardinality 2), where the class-side
        // projection lands on SingularSupport (bottom-boundary-first
        // priority) and is_high_support reads false.
        let empty = AxisHistogram::<A>::empty();
        assert_eq!(
            empty.has_high_support(),
            empty.support_cardinality_class().is_high_support(),
            "has_high_support must equal support_cardinality_class().is_high_support() \
             on empty for axis {}",
            std::any::type_name::<A>(),
        );

        for observed in axis_iter::<A>() {
            let singleton: AxisHistogram<A> = std::iter::once(observed).collect();
            assert_eq!(
                singleton.has_high_support(),
                singleton.support_cardinality_class().is_high_support(),
                "has_high_support must equal support_cardinality_class().is_high_support() \
                 on singleton {observed:?} for axis {}",
                std::any::type_name::<A>(),
            );
        }

        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        assert_eq!(
            cover.has_high_support(),
            cover.support_cardinality_class().is_high_support(),
            "has_high_support must equal support_cardinality_class().is_high_support() \
             on axis-cover for axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_has_low_support_and_has_high_support_are_disjoint<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // On every cardinality-`>= 2` implementor (every implementor
        // today), `has_low_support` and `has_high_support` are
        // pointwise disjoint — no shape lands in both legs of the
        // magnitude partition. The strict-singular-gap formulation of
        // `has_high_support` excises the cardinality-2 singleton case
        // (where the raw "unobserved <= 1" form would otherwise
        // overlap "distinct <= 1") and lands the singleton on
        // `has_low_support` only.
        let empty = AxisHistogram::<A>::empty();
        assert!(
            !(empty.has_low_support() && empty.has_high_support()),
            "has_low_support and has_high_support must be disjoint \
             on empty for axis {}",
            std::any::type_name::<A>(),
        );

        for observed in axis_iter::<A>() {
            let singleton: AxisHistogram<A> = std::iter::once(observed).collect();
            assert!(
                !(singleton.has_low_support() && singleton.has_high_support()),
                "has_low_support and has_high_support must be disjoint \
                 on singleton {observed:?} for axis {}",
                std::any::type_name::<A>(),
            );
        }

        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        assert!(
            !(cover.has_low_support() && cover.has_high_support()),
            "has_low_support and has_high_support must be disjoint \
             on axis-cover for axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_has_low_support_has_strict_partial_cover_has_high_support_form_strict_ternary_partition<
        A,
    >()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Stronger than disjointness: the three histogram-side
        // magnitude legs form a strict ternary partition on every
        // implementor with cardinality `>= 2` — exactly one of the
        // three predicates fires on any histogram. Mirrors the
        // class-side strict ternary partition pinned by
        // `support_cardinality_class_is_low_support_is_strict_partial_cover_is_high_support_form_strict_ternary_partition`.
        let check = |hist: &AxisHistogram<A>, label: &str| {
            let sum = u8::from(hist.has_low_support())
                + u8::from(hist.has_strict_partial_cover())
                + u8::from(hist.has_high_support());
            assert_eq!(
                sum,
                1,
                "(has_low_support, has_strict_partial_cover, has_high_support) must \
                 sum to 1 on {label} for axis {} (got {sum})",
                std::any::type_name::<A>(),
            );
        };

        check(&AxisHistogram::<A>::empty(), "empty");

        for observed in axis_iter::<A>() {
            let singleton: AxisHistogram<A> = std::iter::once(observed).collect();
            let label = format!("singleton {observed:?}");
            check(&singleton, &label);
        }

        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        check(&cover, "axis-cover");
    }

    fn assert_two_low_boundary_predicates_imply_has_low_support<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Implication chain over the two low boundary peers:
        // is_empty() => has_low_support() and
        // has_singular_support() => has_low_support().
        let empty = AxisHistogram::<A>::empty();
        if empty.is_empty() {
            assert!(
                empty.has_low_support(),
                "is_empty must imply has_low_support on empty for axis {}",
                std::any::type_name::<A>(),
            );
        }
        for observed in axis_iter::<A>() {
            let singleton: AxisHistogram<A> = std::iter::once(observed).collect();
            if singleton.has_singular_support() {
                assert!(
                    singleton.has_low_support(),
                    "has_singular_support must imply has_low_support on singleton \
                     {observed:?} for axis {}",
                    std::any::type_name::<A>(),
                );
            }
        }
    }

    fn assert_full_cover_implies_has_high_support<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Implication chain over the full-cover top peer:
        // is_full_cover() => has_high_support().
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        if cover.is_full_cover() {
            assert!(
                cover.has_high_support(),
                "is_full_cover must imply has_high_support on axis-cover for axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    #[test]
    fn axis_histogram_has_low_support_agrees_with_class_is_low_support_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_has_low_support_agrees_with_class_is_low_support::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_has_high_support_agrees_with_class_is_high_support_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_has_high_support_agrees_with_class_is_high_support::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_has_low_support_and_has_high_support_are_disjoint_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_has_low_support_and_has_high_support_are_disjoint::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_has_low_support_has_strict_partial_cover_has_high_support_form_strict_ternary_partition_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_has_low_support_has_strict_partial_cover_has_high_support_form_strict_ternary_partition::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_two_low_boundary_predicates_imply_has_low_support_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_two_low_boundary_predicates_imply_has_low_support::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_full_cover_implies_has_high_support_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_full_cover_implies_has_high_support::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    fn assert_has_boundary_agrees_with_class_is_boundary<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Cross-surface bridge (histogram side):
        // hist.has_boundary() ==
        // hist.support_cardinality_class().is_boundary() —
        // unconditional, holds across every implementor regardless of
        // cardinality. The two surfaces carry one named boolean each on
        // the boundary leg of the (is_boundary, is_singular,
        // is_strict_partial_cover) distance-from-boundary ternary
        // partition.
        let empty = AxisHistogram::<A>::empty();
        assert_eq!(
            empty.has_boundary(),
            empty.support_cardinality_class().is_boundary(),
            "has_boundary must equal support_cardinality_class().is_boundary() \
             on empty for axis {}",
            std::any::type_name::<A>(),
        );

        for observed in axis_iter::<A>() {
            let singleton: AxisHistogram<A> = std::iter::once(observed).collect();
            assert_eq!(
                singleton.has_boundary(),
                singleton.support_cardinality_class().is_boundary(),
                "has_boundary must equal support_cardinality_class().is_boundary() \
                 on singleton {observed:?} for axis {}",
                std::any::type_name::<A>(),
            );
        }

        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        assert_eq!(
            cover.has_boundary(),
            cover.support_cardinality_class().is_boundary(),
            "has_boundary must equal support_cardinality_class().is_boundary() \
             on axis-cover for axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_has_boundary_and_has_partial_cover_form_strict_bipartition<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The histogram-side strict bipartition: exactly one of
        // has_boundary() and has_partial_cover() fires on any shape.
        // Mirrors the class-side bipartition pinned by
        // `support_cardinality_class_is_boundary_and_is_partial_cover_form_strict_bipartition`.
        // Stronger than disjointness — names the joint-exhaustiveness
        // law on the histogram surface directly.
        let check = |hist: &AxisHistogram<A>, label: &str| {
            let sum = u8::from(hist.has_boundary()) + u8::from(hist.has_partial_cover());
            assert_eq!(
                sum,
                1,
                "(has_boundary, has_partial_cover) must sum to 1 on {label} for axis {} \
                 (got {sum})",
                std::any::type_name::<A>(),
            );
        };

        check(&AxisHistogram::<A>::empty(), "empty");

        for observed in axis_iter::<A>() {
            let singleton: AxisHistogram<A> = std::iter::once(observed).collect();
            let label = format!("singleton {observed:?}");
            check(&singleton, &label);
        }

        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        check(&cover, "axis-cover");
    }

    fn assert_two_coverage_boundary_predicates_imply_has_boundary<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Implication chain over the two coverage-boundary peers:
        // is_empty() => has_boundary() and is_full_cover() => has_boundary().
        let empty = AxisHistogram::<A>::empty();
        if empty.is_empty() {
            assert!(
                empty.has_boundary(),
                "is_empty must imply has_boundary on empty for axis {}",
                std::any::type_name::<A>(),
            );
        }
        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        if cover.is_full_cover() {
            assert!(
                cover.has_boundary(),
                "is_full_cover must imply has_boundary on axis-cover for axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    fn assert_has_singular_agrees_with_class_is_singular<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Cross-surface bridge (histogram side):
        // hist.has_singular() ==
        // hist.support_cardinality_class().is_singular() —
        // unconditional, holds across every implementor regardless of
        // cardinality (every implementor today carries cardinality >= 2,
        // so the empty / axis-cover / singleton shapes pin the bridge
        // directly; the cardinality-2 dual-singular collapse leaves the
        // bridge intact because the class-side projection lands the
        // singleton on SingularSupport and is_singular reads true on
        // that variant). The two surfaces carry one named boolean each
        // on the singular near-boundary leg of the
        // (has_boundary, has_singular, has_strict_partial_cover)
        // distance-from-boundary ternary partition.
        let empty = AxisHistogram::<A>::empty();
        assert_eq!(
            empty.has_singular(),
            empty.support_cardinality_class().is_singular(),
            "has_singular must equal support_cardinality_class().is_singular() \
             on empty for axis {}",
            std::any::type_name::<A>(),
        );

        for observed in axis_iter::<A>() {
            let singleton: AxisHistogram<A> = std::iter::once(observed).collect();
            assert_eq!(
                singleton.has_singular(),
                singleton.support_cardinality_class().is_singular(),
                "has_singular must equal support_cardinality_class().is_singular() \
                 on singleton {observed:?} for axis {}",
                std::any::type_name::<A>(),
            );
        }

        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        assert_eq!(
            cover.has_singular(),
            cover.support_cardinality_class().is_singular(),
            "has_singular must equal support_cardinality_class().is_singular() \
             on axis-cover for axis {}",
            std::any::type_name::<A>(),
        );
    }

    fn assert_has_boundary_has_singular_has_strict_partial_cover_form_strict_ternary_partition<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The histogram-side strict ternary partition: exactly one of
        // has_boundary(), has_singular(), and has_strict_partial_cover()
        // fires on any shape. Mirrors the class-side ternary partition
        // pinned by
        // `support_cardinality_class_is_boundary_is_singular_is_strict_partial_cover_form_strict_ternary_partition`.
        // Strictly refines the (has_boundary, has_partial_cover)
        // bipartition: the middle leg decomposes into
        // has_singular ∪ has_strict_partial_cover.
        let check = |hist: &AxisHistogram<A>, label: &str| {
            let sum = u8::from(hist.has_boundary())
                + u8::from(hist.has_singular())
                + u8::from(hist.has_strict_partial_cover());
            assert_eq!(
                sum,
                1,
                "(has_boundary, has_singular, has_strict_partial_cover) must sum to 1 on \
                 {label} for axis {} (got {sum})",
                std::any::type_name::<A>(),
            );
        };

        check(&AxisHistogram::<A>::empty(), "empty");

        for observed in axis_iter::<A>() {
            let singleton: AxisHistogram<A> = std::iter::once(observed).collect();
            let label = format!("singleton {observed:?}");
            check(&singleton, &label);
        }

        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        check(&cover, "axis-cover");
    }

    fn assert_two_singular_boundary_predicates_imply_has_singular<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Implication chain over the two singular-boundary peers:
        // has_singular_support() => has_singular() and
        // has_singular_gap() => has_singular() on every canonical
        // shape. Peer of `assert_two_coverage_boundary_predicates_imply_has_boundary`
        // on the singular near-boundary leg.
        let check = |hist: &AxisHistogram<A>, label: &str| {
            if hist.has_singular_support() {
                assert!(
                    hist.has_singular(),
                    "has_singular_support must imply has_singular on {label} for axis {}",
                    std::any::type_name::<A>(),
                );
            }
            if hist.has_singular_gap() {
                assert!(
                    hist.has_singular(),
                    "has_singular_gap must imply has_singular on {label} for axis {}",
                    std::any::type_name::<A>(),
                );
            }
        };

        check(&AxisHistogram::<A>::empty(), "empty");

        for observed in axis_iter::<A>() {
            let singleton: AxisHistogram<A> = std::iter::once(observed).collect();
            let label = format!("singleton {observed:?}");
            check(&singleton, &label);
        }

        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        check(&cover, "axis-cover");
    }

    fn assert_has_singular_implies_has_partial_cover<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The ternary partition refines the bipartition:
        // has_singular() => has_partial_cover() on every canonical
        // shape. Every singular near-boundary shape lands in the
        // partial-cover middle leg of the
        // (has_boundary, has_partial_cover) bipartition. Peer of the
        // class-side implication pinned by
        // `support_cardinality_class_is_singular_implies_is_partial_cover`.
        let check = |hist: &AxisHistogram<A>, label: &str| {
            if hist.has_singular() {
                assert!(
                    hist.has_partial_cover(),
                    "has_singular must imply has_partial_cover on {label} for axis {}",
                    std::any::type_name::<A>(),
                );
            }
        };

        check(&AxisHistogram::<A>::empty(), "empty");

        for observed in axis_iter::<A>() {
            let singleton: AxisHistogram<A> = std::iter::once(observed).collect();
            let label = format!("singleton {observed:?}");
            check(&singleton, &label);
        }

        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        check(&cover, "axis-cover");
    }

    fn assert_has_singular_implies_not_has_boundary<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // The ternary partition is disjoint on the
        // (has_boundary, has_singular) pair: has_singular() =>
        // !has_boundary() on every canonical shape (every implementor
        // today carries axis_cardinality >= 2, so the two singular
        // corners sit strictly off the coverage boundaries). Peer of
        // the class-side disjointness pinned by
        // `support_cardinality_class_is_singular_implies_not_is_boundary`.
        let check = |hist: &AxisHistogram<A>, label: &str| {
            if hist.has_singular() {
                assert!(
                    !hist.has_boundary(),
                    "has_singular must imply !has_boundary on {label} for axis {}",
                    std::any::type_name::<A>(),
                );
            }
        };

        check(&AxisHistogram::<A>::empty(), "empty");

        for observed in axis_iter::<A>() {
            let singleton: AxisHistogram<A> = std::iter::once(observed).collect();
            let label = format!("singleton {observed:?}");
            check(&singleton, &label);
        }

        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        check(&cover, "axis-cover");
    }

    #[test]
    fn axis_histogram_has_boundary_agrees_with_class_is_boundary_for_every_closed_axis_implementor()
    {
        macro_rules! check {
            ($ty:ident) => {
                assert_has_boundary_agrees_with_class_is_boundary::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_has_boundary_and_has_partial_cover_form_strict_bipartition_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_has_boundary_and_has_partial_cover_form_strict_bipartition::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_two_coverage_boundary_predicates_imply_has_boundary_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_two_coverage_boundary_predicates_imply_has_boundary::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_has_boundary_equals_is_empty_or_is_full_cover() {
        // The defining union-of-coverage-boundaries equivalence on the
        // two named histogram-side peers. Pinned pointwise across the
        // canonical observation-mix shapes on [`ShikumiErrorKind`]
        // (cardinality 6 — the strict interior is well-exercised here).
        type A = ShikumiErrorKind;
        let cells: Vec<A> = axis_iter::<A>().collect();
        let inputs: Vec<Vec<A>> = vec![
            vec![],
            vec![cells[0]],
            vec![cells[0], cells[1]],
            vec![cells[0], cells[1], cells[2]],
            vec![cells[0], cells[1], cells[2], cells[3]],
            vec![cells[0], cells[1], cells[2], cells[3], cells[4]],
            cells.clone(),
        ];
        for input in &inputs {
            let hist: AxisHistogram<A> = input.iter().copied().collect();
            assert_eq!(
                hist.has_boundary(),
                hist.is_empty() || hist.is_full_cover(),
                "has_boundary must equal (is_empty || is_full_cover) on input of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_has_boundary_equals_complement_of_has_partial_cover() {
        // The strict-complement equivalence on the named middle compound:
        // has_boundary and has_partial_cover form a strict bipartition,
        // so has_boundary reads the negation of has_partial_cover
        // pointwise. Pinned on [`ShikumiErrorKind`] (cardinality 6) so
        // every support cardinality 0..=6 is exercised.
        type A = ShikumiErrorKind;
        let cells: Vec<A> = axis_iter::<A>().collect();
        let inputs: Vec<Vec<A>> = vec![
            vec![],
            vec![cells[0]],
            vec![cells[0], cells[1]],
            vec![cells[0], cells[1], cells[2]],
            vec![cells[0], cells[1], cells[2], cells[3]],
            vec![cells[0], cells[1], cells[2], cells[3], cells[4]],
            cells.clone(),
        ];
        for input in &inputs {
            let hist: AxisHistogram<A> = input.iter().copied().collect();
            assert_eq!(
                hist.has_boundary(),
                !hist.has_partial_cover(),
                "has_boundary must equal !has_partial_cover on input of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_has_singular_agrees_with_class_is_singular_for_every_closed_axis_implementor()
    {
        macro_rules! check {
            ($ty:ident) => {
                assert_has_singular_agrees_with_class_is_singular::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_has_boundary_has_singular_has_strict_partial_cover_form_strict_ternary_partition_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_has_boundary_has_singular_has_strict_partial_cover_form_strict_ternary_partition::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_two_singular_boundary_predicates_imply_has_singular_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_two_singular_boundary_predicates_imply_has_singular::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_has_singular_implies_has_partial_cover_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_has_singular_implies_has_partial_cover::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_has_singular_implies_not_has_boundary_for_every_closed_axis_implementor() {
        macro_rules! check {
            ($ty:ident) => {
                assert_has_singular_implies_not_has_boundary::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_has_singular_equals_has_singular_support_or_has_singular_gap() {
        // The defining union-of-singular-boundaries equivalence on the
        // two named histogram-side peers. Pinned pointwise across the
        // canonical observation-mix shapes on [`ShikumiErrorKind`]
        // (cardinality 6 — the strict interior is well-exercised here).
        type A = ShikumiErrorKind;
        let cells: Vec<A> = axis_iter::<A>().collect();
        let inputs: Vec<Vec<A>> = vec![
            vec![],
            vec![cells[0]],
            vec![cells[0], cells[1]],
            vec![cells[0], cells[1], cells[2]],
            vec![cells[0], cells[1], cells[2], cells[3]],
            vec![cells[0], cells[1], cells[2], cells[3], cells[4]],
            cells.clone(),
        ];
        for input in &inputs {
            let hist: AxisHistogram<A> = input.iter().copied().collect();
            assert_eq!(
                hist.has_singular(),
                hist.has_singular_support() || hist.has_singular_gap(),
                "has_singular must equal (has_singular_support || has_singular_gap) on input \
                 of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_has_singular_equals_has_partial_cover_and_not_has_strict_partial_cover() {
        // The partial-cover-minus-strict-interior equivalence: the
        // singular compound is exactly the partial-cover middle leg
        // with the strict-interior `has_strict_partial_cover` predicate
        // excised. Pinned pointwise on [`ShikumiErrorKind`] (cardinality
        // 6) so every support cardinality 0..=6 is exercised — the
        // strict interior fires at supports 2, 3, 4 and the singular
        // boundaries at supports 1 and 5.
        type A = ShikumiErrorKind;
        let cells: Vec<A> = axis_iter::<A>().collect();
        let inputs: Vec<Vec<A>> = vec![
            vec![],
            vec![cells[0]],
            vec![cells[0], cells[1]],
            vec![cells[0], cells[1], cells[2]],
            vec![cells[0], cells[1], cells[2], cells[3]],
            vec![cells[0], cells[1], cells[2], cells[3], cells[4]],
            cells.clone(),
        ];
        for input in &inputs {
            let hist: AxisHistogram<A> = input.iter().copied().collect();
            assert_eq!(
                hist.has_singular(),
                hist.has_partial_cover() && !hist.has_strict_partial_cover(),
                "has_singular must equal (has_partial_cover && !has_strict_partial_cover) \
                 on input of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_has_low_support_equals_is_empty_or_has_singular_support() {
        // The defining union-of-low-boundaries equivalence on the two
        // named histogram-side peers. Pinned pointwise across the
        // canonical observation-mix shapes on [`ShikumiErrorKind`]
        // (cardinality 6 — the strict interior is well-exercised here).
        type A = ShikumiErrorKind;
        let cells: Vec<A> = axis_iter::<A>().collect();
        let inputs: Vec<Vec<A>> = vec![
            vec![],
            vec![cells[0]],
            vec![cells[0], cells[1]],
            vec![cells[0], cells[1], cells[2]],
            vec![cells[0], cells[1], cells[2], cells[3]],
            vec![cells[0], cells[1], cells[2], cells[3], cells[4]],
            cells.clone(),
        ];
        for input in &inputs {
            let hist: AxisHistogram<A> = input.iter().copied().collect();
            assert_eq!(
                hist.has_low_support(),
                hist.is_empty() || hist.has_singular_support(),
                "has_low_support must equal (is_empty || has_singular_support) on input of \
                 length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_has_low_support_equals_distinct_cells_at_most_one() {
        // The support-cardinality scalar form: has_low_support reads
        // the same boolean as `distinct_cells() <= 1`. Pinned on
        // ShikumiErrorKind (cardinality 6) so all support values
        // 0..=6 are exercised.
        type A = ShikumiErrorKind;
        let cells: Vec<A> = axis_iter::<A>().collect();
        let inputs: Vec<Vec<A>> = vec![
            vec![],
            vec![cells[0]],
            vec![cells[0], cells[1]],
            vec![cells[0], cells[1], cells[2]],
            vec![cells[0], cells[1], cells[2], cells[3]],
            vec![cells[0], cells[1], cells[2], cells[3], cells[4]],
            cells.clone(),
        ];
        for input in &inputs {
            let hist: AxisHistogram<A> = input.iter().copied().collect();
            assert_eq!(
                hist.has_low_support(),
                hist.distinct_cells() <= 1,
                "has_low_support must equal (distinct_cells <= 1) on input of length {}; \
                 distinct={}",
                input.len(),
                hist.distinct_cells(),
            );
        }
    }

    #[test]
    fn axis_histogram_has_high_support_equals_full_cover_or_strict_singular_gap() {
        // The defining strict-singular-gap-or-full-cover equivalence
        // on three named histogram-side peers, with the cardinality-2
        // dual-singular collapse excised by the
        // `!has_singular_support()` clause. Pinned pointwise on
        // [`ShikumiErrorKind`] (cardinality 6).
        type A = ShikumiErrorKind;
        let cells: Vec<A> = axis_iter::<A>().collect();
        let inputs: Vec<Vec<A>> = vec![
            vec![],
            vec![cells[0]],
            vec![cells[0], cells[1]],
            vec![cells[0], cells[1], cells[2]],
            vec![cells[0], cells[1], cells[2], cells[3]],
            vec![cells[0], cells[1], cells[2], cells[3], cells[4]],
            cells.clone(),
        ];
        for input in &inputs {
            let hist: AxisHistogram<A> = input.iter().copied().collect();
            assert_eq!(
                hist.has_high_support(),
                hist.is_full_cover() || (hist.has_singular_gap() && !hist.has_singular_support()),
                "has_high_support must equal \
                 (is_full_cover || (has_singular_gap && !has_singular_support)) \
                 on input of length {}",
                input.len(),
            );
        }
    }

    #[test]
    fn axis_histogram_has_high_support_on_cardinality_two_axis_excludes_singleton() {
        // On a cardinality-2 axis (PartitionFace), every singleton has
        // exactly one observed cell AND exactly one unobserved cell —
        // has_singular_support and has_singular_gap both fire. The
        // strict-singular-gap formulation excises the collapse and
        // lands the singleton on has_low_support (not has_high_support).
        type A = PartitionFace;
        for observed in axis_iter::<A>() {
            let singleton: AxisHistogram<A> = std::iter::once(observed).collect();
            assert!(
                singleton.has_singular_support(),
                "cardinality-2 singleton must fire has_singular_support",
            );
            assert!(
                singleton.has_singular_gap(),
                "cardinality-2 singleton must fire has_singular_gap (dual-singular collapse)",
            );
            assert!(
                singleton.has_low_support(),
                "cardinality-2 singleton must land on has_low_support",
            );
            assert!(
                !singleton.has_high_support(),
                "cardinality-2 singleton must NOT fire has_high_support \
                 (the strict-singular-gap clause excises the collapse)",
            );
        }
    }

    #[test]
    fn axis_histogram_has_high_support_on_cardinality_three_axis_fires_on_singular_gap() {
        // On a cardinality-3 axis (DiffLineKind), the singular boundaries
        // are disjoint: a support-2 shape fires has_singular_gap but not
        // has_singular_support, so has_high_support reads true.
        type A = DiffLineKind;
        let cells: Vec<A> = axis_iter::<A>().collect();
        let support_two: AxisHistogram<A> = [cells[0], cells[1]].iter().copied().collect();
        assert!(
            !support_two.has_singular_support(),
            "support-2 on cardinality 3 must NOT fire has_singular_support",
        );
        assert!(
            support_two.has_singular_gap(),
            "support-2 on cardinality 3 must fire has_singular_gap",
        );
        assert!(
            !support_two.has_low_support(),
            "support-2 on cardinality 3 must NOT fire has_low_support",
        );
        assert!(
            support_two.has_high_support(),
            "support-2 on cardinality 3 must fire has_high_support",
        );
    }

    #[test]
    fn axis_histogram_support_cardinality_class_classifies_all_five_corners_on_shikumi_error_kind()
    {
        // Behavioral pin on a cardinality-6 axis where the strict
        // 5-cell partition holds (cardinality >= 3 is sufficient,
        // cardinality >= 4 is required for StrictPartialCover to be
        // reachable). Each of the five variants is hit by at least
        // one canonical shape.
        type A = ShikumiErrorKind;

        let empty: AxisHistogram<A> = AxisHistogram::empty();
        assert_eq!(
            empty.support_cardinality_class(),
            SupportCardinalityClass::Empty,
        );

        // Distinct cells, in declaration order.
        let cells: Vec<A> = axis_iter::<A>().collect();
        assert!(cells.len() >= 5, "test requires a cardinality-5+ axis");

        let singleton: AxisHistogram<A> = std::iter::once(cells[0]).collect();
        assert_eq!(
            singleton.support_cardinality_class(),
            SupportCardinalityClass::SingularSupport,
        );

        // Strict partial cover: observe two distinct cells (support
        // 2 on a cardinality-6 axis; both singular boundaries
        // missed).
        let strict: AxisHistogram<A> = [cells[0], cells[1]].iter().copied().collect();
        assert_eq!(
            strict.support_cardinality_class(),
            SupportCardinalityClass::StrictPartialCover,
        );

        // Singular gap: observe every cell except the last.
        let singular_gap: AxisHistogram<A> = cells[..cells.len() - 1].iter().copied().collect();
        assert_eq!(
            singular_gap.support_cardinality_class(),
            SupportCardinalityClass::SingularGap,
        );

        // Full cover: observe every cell.
        let full: AxisHistogram<A> = cells.iter().copied().collect();
        assert_eq!(
            full.support_cardinality_class(),
            SupportCardinalityClass::FullCover,
        );
    }

    #[test]
    fn axis_histogram_support_cardinality_class_equals_open_coded_branch_match_on_shikumi_error_kind()
     {
        // Defining-equivalence law: the projection collapses the
        // five-arm boolean ladder on the underlying support-
        // cardinality scalar (the (is_empty, has_singular_support,
        // has_strict_partial_cover, has_singular_gap, is_full_cover)
        // 5-corner partition pinned by
        // axis_histogram_support_cardinality_five_corner_partition_on_shikumi_error_kind).
        // Pinned across every reachable support cardinality on a
        // cardinality-6 axis where the partition is strict.
        type A = ShikumiErrorKind;
        let cells: Vec<A> = axis_iter::<A>().collect();
        let n = cells.len();
        for s in 0..=n {
            let hist: AxisHistogram<A> = cells[..s].iter().copied().collect();
            let class = hist.support_cardinality_class();
            let expected = if hist.is_empty() {
                SupportCardinalityClass::Empty
            } else if hist.is_full_cover() {
                SupportCardinalityClass::FullCover
            } else if hist.has_singular_support() {
                SupportCardinalityClass::SingularSupport
            } else if hist.has_singular_gap() {
                SupportCardinalityClass::SingularGap
            } else {
                SupportCardinalityClass::StrictPartialCover
            };
            assert_eq!(
                class,
                expected,
                "support_cardinality_class disagrees with open-coded ladder \
                 at support {s} on axis {}",
                std::any::type_name::<A>(),
            );
        }
    }

    #[test]
    fn axis_histogram_support_cardinality_class_cardinality_two_singleton_lands_on_singular_support()
     {
        // Cardinality-2 collapse witness: on PartitionFace
        // (cardinality 2) the support-1 shape fires both
        // has_singular_support and has_singular_gap (the dual-
        // singular collapse). The branching priority lands on
        // SingularSupport. Symmetrically witnessed on SecretRefShape
        // (the other cardinality-2 axis).
        for face in axis_iter::<PartitionFace>() {
            let hist: AxisHistogram<PartitionFace> = std::iter::once(face).collect();
            assert!(hist.has_singular_support());
            assert!(hist.has_singular_gap());
            assert_eq!(
                hist.support_cardinality_class(),
                SupportCardinalityClass::SingularSupport,
            );
        }
        for shape in axis_iter::<SecretRefShape>() {
            let hist: AxisHistogram<SecretRefShape> = std::iter::once(shape).collect();
            assert!(hist.has_singular_support());
            assert!(hist.has_singular_gap());
            assert_eq!(
                hist.support_cardinality_class(),
                SupportCardinalityClass::SingularSupport,
            );
        }
    }

    #[test]
    fn support_boundary_distance_all_has_three_entries() {
        // Three-bucket partition of the distance-from-boundary leg of
        // the (`is_boundary`, `is_singular`, `is_strict_partial_cover`)
        // ternary on `SupportCardinalityClass`. Idiom-peer of
        // `SupportCardinalityClass::ALL` (length 5) and
        // `ModalityClass::ALL` (length 5) on the sibling typed
        // classifiers; this one is strictly smaller because the
        // five-corner surface partitions into three buckets.
        assert_eq!(SupportBoundaryDistance::ALL.len(), 3);
    }

    #[test]
    fn support_boundary_distance_all_entries_are_pairwise_distinct() {
        for (i, a) in SupportBoundaryDistance::ALL.iter().enumerate() {
            for (j, b) in SupportBoundaryDistance::ALL.iter().enumerate() {
                if i != j {
                    assert_ne!(a, b, "ALL[{i}] = {a:?} must differ from ALL[{j}] = {b:?}",);
                }
            }
        }
    }

    #[test]
    fn support_boundary_distance_corner_predicates_partition_every_variant() {
        // Each variant fires exactly one of the three bucket predicates.
        // Stronger than disjointness — names the joint-exhaustiveness
        // law on the typed-bucket surface directly. Peer of
        // `support_cardinality_class_corner_predicates_partition_every_variant`
        // on the sibling typed classifier (where five predicates partition
        // five variants); here three predicates partition three variants
        // by construction.
        for &bucket in SupportBoundaryDistance::ALL {
            let fires = u32::from(bucket.is_boundary())
                + u32::from(bucket.is_singular())
                + u32::from(bucket.is_strict_interior());
            assert_eq!(
                fires, 1,
                "exactly one bucket predicate must fire on every variant \
                 (got fires={fires}) on bucket {bucket:?}",
            );
        }
    }

    #[test]
    fn support_boundary_distance_is_boundary_fires_exactly_on_boundary_variant() {
        assert!(SupportBoundaryDistance::Boundary.is_boundary());
        assert!(!SupportBoundaryDistance::Singular.is_boundary());
        assert!(!SupportBoundaryDistance::StrictInterior.is_boundary());
    }

    #[test]
    fn support_boundary_distance_is_singular_fires_exactly_on_singular_variant() {
        assert!(!SupportBoundaryDistance::Boundary.is_singular());
        assert!(SupportBoundaryDistance::Singular.is_singular());
        assert!(!SupportBoundaryDistance::StrictInterior.is_singular());
    }

    #[test]
    fn support_boundary_distance_is_strict_interior_fires_exactly_on_strict_interior_variant() {
        assert!(!SupportBoundaryDistance::Boundary.is_strict_interior());
        assert!(!SupportBoundaryDistance::Singular.is_strict_interior());
        assert!(SupportBoundaryDistance::StrictInterior.is_strict_interior());
    }

    #[test]
    fn support_boundary_distance_as_str_round_trips_via_from_canonical_str() {
        // Idiom-peer of
        // `support_cardinality_class_as_str_round_trips_via_from_canonical_str`
        // and `modality_class_as_str_round_trips_via_from_canonical_str`
        // on the sibling typed classifiers.
        for &v in SupportBoundaryDistance::ALL {
            assert_eq!(
                SupportBoundaryDistance::from_canonical_str(v.as_str()),
                Some(v),
                "as_str / from_canonical_str round-trip for {v:?}",
            );
        }
    }

    #[test]
    fn support_boundary_distance_as_str_labels_pairwise_distinct() {
        for (i, a) in SupportBoundaryDistance::ALL.iter().enumerate() {
            for (j, b) in SupportBoundaryDistance::ALL.iter().enumerate() {
                if i != j {
                    assert_ne!(
                        a.as_str(),
                        b.as_str(),
                        "as_str must distinguish ALL[{i}] = {a:?} from ALL[{j}] = {b:?}",
                    );
                }
            }
        }
    }

    #[test]
    fn support_boundary_distance_as_str_labels_nonempty() {
        for &v in SupportBoundaryDistance::ALL {
            assert!(
                !v.as_str().is_empty(),
                "as_str label must be nonempty for {v:?}",
            );
        }
    }

    #[test]
    fn support_boundary_distance_from_canonical_str_is_case_insensitive() {
        for &v in SupportBoundaryDistance::ALL {
            assert_eq!(
                SupportBoundaryDistance::from_canonical_str(&v.as_str().to_ascii_uppercase()),
                Some(v),
                "case-insensitive parse must recover {v:?}",
            );
        }
    }

    #[test]
    fn support_boundary_distance_from_canonical_str_rejects_empty_string() {
        assert_eq!(SupportBoundaryDistance::from_canonical_str(""), None);
    }

    #[test]
    fn support_boundary_distance_from_str_round_trips_through_display() {
        for &v in SupportBoundaryDistance::ALL {
            let rendered = v.to_string();
            let parsed: SupportBoundaryDistance = rendered.parse().unwrap();
            assert_eq!(parsed, v, "Display / FromStr round-trip for {v:?}");
        }
    }

    #[test]
    fn support_boundary_distance_from_str_rejects_unknown_label_with_label_verbatim() {
        let sentinel = "__shikumi_unknown_support_boundary_distance_sentinel__";
        match sentinel.parse::<SupportBoundaryDistance>() {
            Err(e) => {
                assert_eq!(e.label, sentinel);
                let rendered = format!("{e}");
                assert!(
                    rendered.contains(sentinel),
                    "Display impl must carry the unknown sentinel verbatim, got: {rendered}",
                );
            }
            Ok(other) => panic!("unknown label must reject, got {other:?}"),
        }
    }

    #[test]
    fn support_boundary_distance_serde_yaml_round_trips_over_every_variant() {
        for &v in SupportBoundaryDistance::ALL {
            let yaml = serde_yaml::to_string(&v).unwrap();
            let parsed: SupportBoundaryDistance = serde_yaml::from_str(&yaml)
                .unwrap_or_else(|e| panic!("YAML round-trip for {v:?} failed: {e}"));
            assert_eq!(
                parsed, v,
                "serde YAML round-trip must be identity for {v:?}"
            );
        }
    }

    #[test]
    fn support_boundary_distance_serde_json_round_trips_over_every_variant() {
        for &v in SupportBoundaryDistance::ALL {
            let json = serde_json::to_string(&v).unwrap();
            assert_eq!(
                json,
                format!("\"{}\"", v.as_str()),
                "JSON emission for {v:?} must be the quoted canonical label",
            );
            let parsed: SupportBoundaryDistance = serde_json::from_str(&json).unwrap_or_else(|e| {
                panic!("JSON emission for {v:?} must deserialize back: {e}\n  json: {json}")
            });
            assert_eq!(
                parsed, v,
                "serde JSON round-trip must be identity for {v:?}"
            );
        }
    }

    #[test]
    fn support_boundary_distance_serde_yaml_is_case_insensitive() {
        for &v in SupportBoundaryDistance::ALL {
            let upper = v.as_str().to_ascii_uppercase();
            let yaml = format!("\"{upper}\"\n");
            let parsed: SupportBoundaryDistance = serde_yaml::from_str(&yaml).unwrap_or_else(|e| {
                panic!("uppercase YAML scalar for {v:?} must deserialize: {e}\n  yaml: {yaml:?}")
            });
            assert_eq!(parsed, v);
        }
    }

    #[test]
    fn support_boundary_distance_serde_yaml_unknown_label_error_carries_label_verbatim() {
        let sentinel = "__shikumi_unknown_support_boundary_distance_sentinel__";
        let yaml = format!("\"{sentinel}\"\n");
        let result: Result<SupportBoundaryDistance, _> = serde_yaml::from_str(&yaml);
        match result {
            Err(e) => {
                let rendered = format!("{e}");
                assert!(
                    rendered.contains(sentinel),
                    "serde YAML error must carry the unknown sentinel verbatim, got: {rendered}",
                );
            }
            Ok(other) => panic!("YAML carrying unknown label must reject, got {other:?}"),
        }
    }

    #[test]
    fn support_cardinality_class_support_boundary_distance_lands_on_expected_bucket_per_variant() {
        // Behavioral pin on the variant-tag projection — the five
        // class variants map onto the three buckets per the
        // documented closed mapping (Empty | FullCover → Boundary,
        // SingularSupport | SingularGap → Singular,
        // StrictPartialCover → StrictInterior).
        assert_eq!(
            SupportCardinalityClass::Empty.support_boundary_distance(),
            SupportBoundaryDistance::Boundary,
        );
        assert_eq!(
            SupportCardinalityClass::SingularSupport.support_boundary_distance(),
            SupportBoundaryDistance::Singular,
        );
        assert_eq!(
            SupportCardinalityClass::StrictPartialCover.support_boundary_distance(),
            SupportBoundaryDistance::StrictInterior,
        );
        assert_eq!(
            SupportCardinalityClass::SingularGap.support_boundary_distance(),
            SupportBoundaryDistance::Singular,
        );
        assert_eq!(
            SupportCardinalityClass::FullCover.support_boundary_distance(),
            SupportBoundaryDistance::Boundary,
        );
    }

    #[test]
    fn support_cardinality_class_support_boundary_distance_pointwise_matches_leg_predicates() {
        // Bucket-predicate bridge laws: for every variant the typed-
        // bucket projection's three predicates agree pointwise with
        // the class-side leg predicates on the same scalar.
        for &class in SupportCardinalityClass::ALL {
            let bucket = class.support_boundary_distance();
            assert_eq!(
                bucket.is_boundary(),
                class.is_boundary(),
                "support_boundary_distance().is_boundary must equal \
                 is_boundary on class {class:?}",
            );
            assert_eq!(
                bucket.is_singular(),
                class.is_singular(),
                "support_boundary_distance().is_singular must equal \
                 is_singular on class {class:?}",
            );
            assert_eq!(
                bucket.is_strict_interior(),
                class.is_strict_partial_cover(),
                "support_boundary_distance().is_strict_interior must equal \
                 is_strict_partial_cover on class {class:?}",
            );
        }
    }

    fn assert_support_boundary_distance_agrees_with_class_projection<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Histogram-side projection definitional law:
        // hist.support_boundary_distance() ==
        // hist.support_cardinality_class().support_boundary_distance()
        // for every canonical shape. The histogram-side projection
        // routes through the existing class-side variant-tag
        // projection by construction — the two paths must agree.
        let check = |hist: &AxisHistogram<A>, label: &str| {
            assert_eq!(
                hist.support_boundary_distance(),
                hist.support_cardinality_class().support_boundary_distance(),
                "support_boundary_distance must equal \
                 support_cardinality_class().support_boundary_distance() on {label} \
                 for axis {}",
                std::any::type_name::<A>(),
            );
        };

        check(&AxisHistogram::<A>::empty(), "empty");

        for observed in axis_iter::<A>() {
            let singleton: AxisHistogram<A> = std::iter::once(observed).collect();
            let label = format!("singleton {observed:?}");
            check(&singleton, &label);
        }

        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        check(&cover, "axis-cover");
    }

    fn assert_support_boundary_distance_is_boundary_agrees_with_has_boundary<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Bucket-predicate bridge (boundary leg):
        // hist.support_boundary_distance().is_boundary() ==
        // hist.has_boundary() pointwise. Composes the class-side
        // bridge `has_boundary == support_cardinality_class().is_boundary()`
        // (pinned by
        // `axis_histogram_has_boundary_agrees_with_class_is_boundary_for_every_closed_axis_implementor`)
        // with the class-side bucket-predicate law
        // `support_boundary_distance().is_boundary() == is_boundary`
        // on `SupportCardinalityClass` (pinned by
        // `support_cardinality_class_support_boundary_distance_pointwise_matches_leg_predicates`).
        let check = |hist: &AxisHistogram<A>, label: &str| {
            assert_eq!(
                hist.support_boundary_distance().is_boundary(),
                hist.has_boundary(),
                "support_boundary_distance().is_boundary must equal has_boundary on \
                 {label} for axis {}",
                std::any::type_name::<A>(),
            );
        };

        check(&AxisHistogram::<A>::empty(), "empty");

        for observed in axis_iter::<A>() {
            let singleton: AxisHistogram<A> = std::iter::once(observed).collect();
            let label = format!("singleton {observed:?}");
            check(&singleton, &label);
        }

        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        check(&cover, "axis-cover");
    }

    fn assert_support_boundary_distance_is_singular_agrees_with_has_singular<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Bucket-predicate bridge (singular leg):
        // hist.support_boundary_distance().is_singular() ==
        // hist.has_singular() pointwise. The bridge holds across
        // cardinality-2 axes by the same dual-singular collapse
        // routing already pinned for `has_singular` against
        // `support_cardinality_class().is_singular()`.
        let check = |hist: &AxisHistogram<A>, label: &str| {
            assert_eq!(
                hist.support_boundary_distance().is_singular(),
                hist.has_singular(),
                "support_boundary_distance().is_singular must equal has_singular on \
                 {label} for axis {}",
                std::any::type_name::<A>(),
            );
        };

        check(&AxisHistogram::<A>::empty(), "empty");

        for observed in axis_iter::<A>() {
            let singleton: AxisHistogram<A> = std::iter::once(observed).collect();
            let label = format!("singleton {observed:?}");
            check(&singleton, &label);
        }

        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        check(&cover, "axis-cover");
    }

    fn assert_support_boundary_distance_is_strict_interior_agrees_with_has_strict_partial_cover<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Bucket-predicate bridge (strict-interior leg):
        // hist.support_boundary_distance().is_strict_interior() ==
        // hist.has_strict_partial_cover() pointwise. The
        // strict-interior bucket on the typed-bucket surface is the
        // single-variant peer of `StrictPartialCover` on the class
        // surface; the bridge reduces to the class-side leg-predicate
        // bridge by construction.
        let check = |hist: &AxisHistogram<A>, label: &str| {
            assert_eq!(
                hist.support_boundary_distance().is_strict_interior(),
                hist.has_strict_partial_cover(),
                "support_boundary_distance().is_strict_interior must equal \
                 has_strict_partial_cover on {label} for axis {}",
                std::any::type_name::<A>(),
            );
        };

        check(&AxisHistogram::<A>::empty(), "empty");

        for observed in axis_iter::<A>() {
            let singleton: AxisHistogram<A> = std::iter::once(observed).collect();
            let label = format!("singleton {observed:?}");
            check(&singleton, &label);
        }

        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        check(&cover, "axis-cover");
    }

    #[test]
    fn axis_histogram_support_boundary_distance_agrees_with_class_projection_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_support_boundary_distance_agrees_with_class_projection::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_support_boundary_distance_is_boundary_agrees_with_has_boundary_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_support_boundary_distance_is_boundary_agrees_with_has_boundary::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_support_boundary_distance_is_singular_agrees_with_has_singular_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_support_boundary_distance_is_singular_agrees_with_has_singular::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_support_boundary_distance_is_strict_interior_agrees_with_has_strict_partial_cover_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_support_boundary_distance_is_strict_interior_agrees_with_has_strict_partial_cover::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn support_magnitude_direction_all_has_three_entries() {
        // Three-bucket partition of the support-magnitude-direction leg
        // of the (`is_low_support`, `is_strict_partial_cover`,
        // `is_high_support`) ternary on `SupportCardinalityClass`.
        // Idiom-peer of `SupportBoundaryDistance::ALL` (length 3) on
        // the sibling typed-bucket classifier; the orthogonal three-
        // bucket projection of the same five-corner surface across the
        // shared strict-interior middle leg.
        assert_eq!(SupportMagnitudeDirection::ALL.len(), 3);
    }

    #[test]
    fn support_magnitude_direction_all_entries_are_pairwise_distinct() {
        for (i, a) in SupportMagnitudeDirection::ALL.iter().enumerate() {
            for (j, b) in SupportMagnitudeDirection::ALL.iter().enumerate() {
                if i != j {
                    assert_ne!(a, b, "ALL[{i}] = {a:?} must differ from ALL[{j}] = {b:?}",);
                }
            }
        }
    }

    #[test]
    fn support_magnitude_direction_bucket_predicates_partition_every_variant() {
        // Each variant fires exactly one of the three bucket predicates.
        // Stronger than disjointness — names the joint-exhaustiveness
        // law on the typed-bucket surface directly. Peer of
        // `support_boundary_distance_corner_predicates_partition_every_variant`
        // on the sibling typed-bucket classifier.
        for &bucket in SupportMagnitudeDirection::ALL {
            let fires = u32::from(bucket.is_low())
                + u32::from(bucket.is_strict_interior())
                + u32::from(bucket.is_high());
            assert_eq!(
                fires, 1,
                "exactly one bucket predicate must fire on every variant \
                 (got fires={fires}) on bucket {bucket:?}",
            );
        }
    }

    #[test]
    fn support_magnitude_direction_is_low_fires_exactly_on_low_variant() {
        assert!(SupportMagnitudeDirection::Low.is_low());
        assert!(!SupportMagnitudeDirection::StrictInterior.is_low());
        assert!(!SupportMagnitudeDirection::High.is_low());
    }

    #[test]
    fn support_magnitude_direction_is_strict_interior_fires_exactly_on_strict_interior_variant() {
        assert!(!SupportMagnitudeDirection::Low.is_strict_interior());
        assert!(SupportMagnitudeDirection::StrictInterior.is_strict_interior());
        assert!(!SupportMagnitudeDirection::High.is_strict_interior());
    }

    #[test]
    fn support_magnitude_direction_is_high_fires_exactly_on_high_variant() {
        assert!(!SupportMagnitudeDirection::Low.is_high());
        assert!(!SupportMagnitudeDirection::StrictInterior.is_high());
        assert!(SupportMagnitudeDirection::High.is_high());
    }

    #[test]
    fn support_magnitude_direction_as_str_round_trips_via_from_canonical_str() {
        // Idiom-peer of
        // `support_boundary_distance_as_str_round_trips_via_from_canonical_str`
        // on the sibling typed-bucket classifier and
        // `support_cardinality_class_as_str_round_trips_via_from_canonical_str` /
        // `modality_class_as_str_round_trips_via_from_canonical_str`
        // on the typed-class classifiers.
        for &v in SupportMagnitudeDirection::ALL {
            assert_eq!(
                SupportMagnitudeDirection::from_canonical_str(v.as_str()),
                Some(v),
                "as_str / from_canonical_str round-trip for {v:?}",
            );
        }
    }

    #[test]
    fn support_magnitude_direction_as_str_labels_pairwise_distinct() {
        for (i, a) in SupportMagnitudeDirection::ALL.iter().enumerate() {
            for (j, b) in SupportMagnitudeDirection::ALL.iter().enumerate() {
                if i != j {
                    assert_ne!(
                        a.as_str(),
                        b.as_str(),
                        "as_str must distinguish ALL[{i}] = {a:?} from ALL[{j}] = {b:?}",
                    );
                }
            }
        }
    }

    #[test]
    fn support_magnitude_direction_as_str_labels_nonempty() {
        for &v in SupportMagnitudeDirection::ALL {
            assert!(
                !v.as_str().is_empty(),
                "as_str label must be nonempty for {v:?}",
            );
        }
    }

    #[test]
    fn support_magnitude_direction_from_canonical_str_is_case_insensitive() {
        for &v in SupportMagnitudeDirection::ALL {
            assert_eq!(
                SupportMagnitudeDirection::from_canonical_str(&v.as_str().to_ascii_uppercase()),
                Some(v),
                "case-insensitive parse must recover {v:?}",
            );
        }
    }

    #[test]
    fn support_magnitude_direction_from_canonical_str_rejects_empty_string() {
        assert_eq!(SupportMagnitudeDirection::from_canonical_str(""), None);
    }

    #[test]
    fn support_magnitude_direction_from_str_round_trips_through_display() {
        for &v in SupportMagnitudeDirection::ALL {
            let rendered = v.to_string();
            let parsed: SupportMagnitudeDirection = rendered.parse().unwrap();
            assert_eq!(parsed, v, "Display / FromStr round-trip for {v:?}");
        }
    }

    #[test]
    fn support_magnitude_direction_from_str_rejects_unknown_label_with_label_verbatim() {
        let sentinel = "__shikumi_unknown_support_magnitude_direction_sentinel__";
        match sentinel.parse::<SupportMagnitudeDirection>() {
            Err(e) => {
                assert_eq!(e.label, sentinel);
                let rendered = format!("{e}");
                assert!(
                    rendered.contains(sentinel),
                    "Display impl must carry the unknown sentinel verbatim, got: {rendered}",
                );
            }
            Ok(other) => panic!("unknown label must reject, got {other:?}"),
        }
    }

    #[test]
    fn support_magnitude_direction_serde_yaml_round_trips_over_every_variant() {
        for &v in SupportMagnitudeDirection::ALL {
            let yaml = serde_yaml::to_string(&v).unwrap();
            let parsed: SupportMagnitudeDirection = serde_yaml::from_str(&yaml)
                .unwrap_or_else(|e| panic!("YAML round-trip for {v:?} failed: {e}"));
            assert_eq!(
                parsed, v,
                "serde YAML round-trip must be identity for {v:?}"
            );
        }
    }

    #[test]
    fn support_magnitude_direction_serde_json_round_trips_over_every_variant() {
        for &v in SupportMagnitudeDirection::ALL {
            let json = serde_json::to_string(&v).unwrap();
            assert_eq!(
                json,
                format!("\"{}\"", v.as_str()),
                "JSON emission for {v:?} must be the quoted canonical label",
            );
            let parsed: SupportMagnitudeDirection =
                serde_json::from_str(&json).unwrap_or_else(|e| {
                    panic!("JSON emission for {v:?} must deserialize back: {e}\n  json: {json}")
                });
            assert_eq!(
                parsed, v,
                "serde JSON round-trip must be identity for {v:?}"
            );
        }
    }

    #[test]
    fn support_magnitude_direction_serde_yaml_is_case_insensitive() {
        for &v in SupportMagnitudeDirection::ALL {
            let upper = v.as_str().to_ascii_uppercase();
            let yaml = format!("\"{upper}\"\n");
            let parsed: SupportMagnitudeDirection =
                serde_yaml::from_str(&yaml).unwrap_or_else(|e| {
                    panic!(
                        "uppercase YAML scalar for {v:?} must deserialize: {e}\n  yaml: {yaml:?}"
                    )
                });
            assert_eq!(parsed, v);
        }
    }

    #[test]
    fn support_magnitude_direction_serde_yaml_unknown_label_error_carries_label_verbatim() {
        let sentinel = "__shikumi_unknown_support_magnitude_direction_sentinel__";
        let yaml = format!("\"{sentinel}\"\n");
        let result: Result<SupportMagnitudeDirection, _> = serde_yaml::from_str(&yaml);
        match result {
            Err(e) => {
                let rendered = format!("{e}");
                assert!(
                    rendered.contains(sentinel),
                    "serde YAML error must carry the unknown sentinel verbatim, got: {rendered}",
                );
            }
            Ok(other) => panic!("YAML carrying unknown label must reject, got {other:?}"),
        }
    }

    #[test]
    fn support_cardinality_class_support_magnitude_direction_lands_on_expected_bucket_per_variant()
    {
        // Behavioral pin on the variant-tag projection — the five class
        // variants map onto the three buckets per the documented closed
        // mapping (Empty | SingularSupport → Low, StrictPartialCover →
        // StrictInterior, SingularGap | FullCover → High). Mirror of
        // `support_cardinality_class_support_boundary_distance_lands_on_expected_bucket_per_variant`
        // across the shared StrictPartialCover middle leg.
        assert_eq!(
            SupportCardinalityClass::Empty.support_magnitude_direction(),
            SupportMagnitudeDirection::Low,
        );
        assert_eq!(
            SupportCardinalityClass::SingularSupport.support_magnitude_direction(),
            SupportMagnitudeDirection::Low,
        );
        assert_eq!(
            SupportCardinalityClass::StrictPartialCover.support_magnitude_direction(),
            SupportMagnitudeDirection::StrictInterior,
        );
        assert_eq!(
            SupportCardinalityClass::SingularGap.support_magnitude_direction(),
            SupportMagnitudeDirection::High,
        );
        assert_eq!(
            SupportCardinalityClass::FullCover.support_magnitude_direction(),
            SupportMagnitudeDirection::High,
        );
    }

    #[test]
    fn support_cardinality_class_support_magnitude_direction_pointwise_matches_leg_predicates() {
        // Bucket-predicate bridge laws: for every variant the typed-
        // bucket projection's three predicates agree pointwise with
        // the class-side leg predicates on the same scalar. Mirror of
        // `support_cardinality_class_support_boundary_distance_pointwise_matches_leg_predicates`
        // on the orthogonal ternary.
        for &class in SupportCardinalityClass::ALL {
            let bucket = class.support_magnitude_direction();
            assert_eq!(
                bucket.is_low(),
                class.is_low_support(),
                "support_magnitude_direction().is_low must equal \
                 is_low_support on class {class:?}",
            );
            assert_eq!(
                bucket.is_strict_interior(),
                class.is_strict_partial_cover(),
                "support_magnitude_direction().is_strict_interior must equal \
                 is_strict_partial_cover on class {class:?}",
            );
            assert_eq!(
                bucket.is_high(),
                class.is_high_support(),
                "support_magnitude_direction().is_high must equal \
                 is_high_support on class {class:?}",
            );
        }
    }

    #[test]
    fn support_cardinality_class_support_magnitude_direction_strict_interior_leg_matches_support_boundary_distance_strict_interior_leg()
     {
        // Cross-classifier shared-middle-leg law: the two orthogonal
        // typed-bucket projections of the support-cardinality scalar
        // agree on the strict-interior middle leg pointwise across
        // every class variant. Pins that the shared middle leg is
        // exactly the `StrictPartialCover` single-variant peer on both
        // typed-bucket surfaces.
        for &class in SupportCardinalityClass::ALL {
            assert_eq!(
                class.support_magnitude_direction().is_strict_interior(),
                class.support_boundary_distance().is_strict_interior(),
                "the two typed-bucket projections must agree on the \
                 strict-interior middle leg on class {class:?}",
            );
        }
    }

    fn assert_support_magnitude_direction_agrees_with_class_projection<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Histogram-side projection definitional law:
        // hist.support_magnitude_direction() ==
        // hist.support_cardinality_class().support_magnitude_direction()
        // for every canonical shape. The histogram-side projection
        // routes through the existing class-side variant-tag
        // projection by construction — the two paths must agree.
        let check = |hist: &AxisHistogram<A>, label: &str| {
            assert_eq!(
                hist.support_magnitude_direction(),
                hist.support_cardinality_class()
                    .support_magnitude_direction(),
                "support_magnitude_direction must equal \
                 support_cardinality_class().support_magnitude_direction() on {label} \
                 for axis {}",
                std::any::type_name::<A>(),
            );
        };

        check(&AxisHistogram::<A>::empty(), "empty");

        for observed in axis_iter::<A>() {
            let singleton: AxisHistogram<A> = std::iter::once(observed).collect();
            let label = format!("singleton {observed:?}");
            check(&singleton, &label);
        }

        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        check(&cover, "axis-cover");
    }

    fn assert_support_magnitude_direction_is_low_agrees_with_has_low_support<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Bucket-predicate bridge (low leg):
        // hist.support_magnitude_direction().is_low() ==
        // hist.has_low_support() pointwise. Composes the class-side
        // bridge `has_low_support == support_cardinality_class().is_low_support()`
        // (pinned by
        // `axis_histogram_has_low_support_agrees_with_class_is_low_support_for_every_closed_axis_implementor`)
        // with the class-side bucket-predicate law
        // `support_magnitude_direction().is_low() == is_low_support`
        // on `SupportCardinalityClass` (pinned by
        // `support_cardinality_class_support_magnitude_direction_pointwise_matches_leg_predicates`).
        let check = |hist: &AxisHistogram<A>, label: &str| {
            assert_eq!(
                hist.support_magnitude_direction().is_low(),
                hist.has_low_support(),
                "support_magnitude_direction().is_low must equal has_low_support on \
                 {label} for axis {}",
                std::any::type_name::<A>(),
            );
        };

        check(&AxisHistogram::<A>::empty(), "empty");

        for observed in axis_iter::<A>() {
            let singleton: AxisHistogram<A> = std::iter::once(observed).collect();
            let label = format!("singleton {observed:?}");
            check(&singleton, &label);
        }

        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        check(&cover, "axis-cover");
    }

    fn assert_support_magnitude_direction_is_strict_interior_agrees_with_has_strict_partial_cover<
        A,
    >()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Bucket-predicate bridge (strict-interior leg, the leg shared
        // with `support_boundary_distance`): on every canonical shape,
        // both typed-bucket projections agree on the strict-interior
        // bucket and equal the histogram-side `has_strict_partial_cover`
        // predicate. Mirror peer of the
        // `support_boundary_distance().is_strict_interior() ==
        // has_strict_partial_cover()` bridge on the sibling typed-
        // bucket classifier.
        let check = |hist: &AxisHistogram<A>, label: &str| {
            assert_eq!(
                hist.support_magnitude_direction().is_strict_interior(),
                hist.has_strict_partial_cover(),
                "support_magnitude_direction().is_strict_interior must equal \
                 has_strict_partial_cover on {label} for axis {}",
                std::any::type_name::<A>(),
            );
        };

        check(&AxisHistogram::<A>::empty(), "empty");

        for observed in axis_iter::<A>() {
            let singleton: AxisHistogram<A> = std::iter::once(observed).collect();
            let label = format!("singleton {observed:?}");
            check(&singleton, &label);
        }

        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        check(&cover, "axis-cover");
    }

    fn assert_support_magnitude_direction_is_high_agrees_with_has_high_support<A>()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Bucket-predicate bridge (high leg):
        // hist.support_magnitude_direction().is_high() ==
        // hist.has_high_support() pointwise. The bridge holds across
        // cardinality-2 axes by the same dual-singular collapse
        // routing already pinned for `has_high_support` against
        // `support_cardinality_class().is_high_support()` (the
        // `!has_singular_support()` clause excises the collapse on the
        // histogram side; the class-side projection's bottom-boundary-
        // first priority lands the cardinality-2 singleton on
        // `SingularSupport` where `is_high_support` reads `false`).
        let check = |hist: &AxisHistogram<A>, label: &str| {
            assert_eq!(
                hist.support_magnitude_direction().is_high(),
                hist.has_high_support(),
                "support_magnitude_direction().is_high must equal has_high_support on \
                 {label} for axis {}",
                std::any::type_name::<A>(),
            );
        };

        check(&AxisHistogram::<A>::empty(), "empty");

        for observed in axis_iter::<A>() {
            let singleton: AxisHistogram<A> = std::iter::once(observed).collect();
            let label = format!("singleton {observed:?}");
            check(&singleton, &label);
        }

        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        check(&cover, "axis-cover");
    }

    fn assert_support_magnitude_direction_strict_interior_leg_matches_support_boundary_distance_strict_interior_leg<
        A,
    >()
    where
        A: ClosedAxis + std::fmt::Debug,
    {
        // Cross-classifier shared-middle-leg law on the histogram
        // surface: the two orthogonal typed-bucket projections agree
        // on the strict-interior middle leg pointwise on every
        // canonical shape. The histogram-side peer of the class-side
        // shared-middle-leg law pinned by
        // `support_cardinality_class_support_magnitude_direction_strict_interior_leg_matches_support_boundary_distance_strict_interior_leg`.
        let check = |hist: &AxisHistogram<A>, label: &str| {
            assert_eq!(
                hist.support_magnitude_direction().is_strict_interior(),
                hist.support_boundary_distance().is_strict_interior(),
                "the two histogram-side typed-bucket projections must \
                 agree on the strict-interior middle leg on {label} for axis {}",
                std::any::type_name::<A>(),
            );
        };

        check(&AxisHistogram::<A>::empty(), "empty");

        for observed in axis_iter::<A>() {
            let singleton: AxisHistogram<A> = std::iter::once(observed).collect();
            let label = format!("singleton {observed:?}");
            check(&singleton, &label);
        }

        let cover: AxisHistogram<A> = axis_iter::<A>().collect();
        check(&cover, "axis-cover");
    }

    #[test]
    fn axis_histogram_support_magnitude_direction_agrees_with_class_projection_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_support_magnitude_direction_agrees_with_class_projection::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_support_magnitude_direction_is_low_agrees_with_has_low_support_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_support_magnitude_direction_is_low_agrees_with_has_low_support::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_support_magnitude_direction_is_strict_interior_agrees_with_has_strict_partial_cover_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_support_magnitude_direction_is_strict_interior_agrees_with_has_strict_partial_cover::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_support_magnitude_direction_is_high_agrees_with_has_high_support_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_support_magnitude_direction_is_high_agrees_with_has_high_support::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    #[test]
    fn axis_histogram_support_magnitude_direction_strict_interior_leg_matches_support_boundary_distance_strict_interior_leg_for_every_closed_axis_implementor()
     {
        macro_rules! check {
            ($ty:ident) => {
                assert_support_magnitude_direction_strict_interior_leg_matches_support_boundary_distance_strict_interior_leg::<$ty>();
            };
        }
        for_each_closed_axis_implementor!(check);
    }

    // ---- Typed-classifier Ord-matches-ALL-declaration-order discipline ----
    //
    // The four typed classifiers on the [`AxisHistogram`] surface
    // ([`ModalityClass`], [`SupportCardinalityClass`],
    // [`SupportBoundaryDistance`], [`SupportMagnitudeDirection`]) all
    // carry `#[derive(Ord, PartialOrd)]`. The derive lowers the total
    // order to lexicographic comparison of the variant discriminants,
    // which for a fieldless `pub enum` matches declaration order
    // pointwise — the same order their `Self::ALL` slices enumerate.
    // The assertion is implicit in the derive's semantics; the pin
    // names it explicitly so a future contributor reordering variants
    // (silently flipping the `Ord` surface that downstream
    // `BTreeMap<Classifier, T>` keys observe) is caught at the
    // typed-classifier level rather than at a downstream rollup
    // dashboard.
    //
    // Idiom-peer of the
    // `support_*_all_entries_are_pairwise_distinct` pins above on the
    // same four typed classifiers — the `Eq` pairwise-distinct
    // invariant is the [`PartialEq`] analog of this [`Ord`]
    // strict-monotone invariant; both flow from the same
    // `ALL`-enumerates-every-variant-once discipline.
    fn assert_ord_matches_all_declaration_order<T>(all: &[T])
    where
        T: Ord + Copy + std::fmt::Debug,
    {
        // Every adjacent pair is strictly ordered, which by transitivity
        // pins the full strict-monotone chain over `ALL`.
        for window in all.windows(2) {
            assert!(
                window[0] < window[1],
                "ALL must be strictly increasing under Ord: \
                 got {:?} >= {:?} at adjacent positions",
                window[0],
                window[1],
            );
        }
    }

    #[test]
    fn modality_class_ord_matches_all_declaration_order() {
        assert_ord_matches_all_declaration_order(ModalityClass::ALL);
    }

    #[test]
    fn support_cardinality_class_ord_matches_all_declaration_order() {
        assert_ord_matches_all_declaration_order(SupportCardinalityClass::ALL);
    }

    #[test]
    fn support_boundary_distance_ord_matches_all_declaration_order() {
        assert_ord_matches_all_declaration_order(SupportBoundaryDistance::ALL);
    }

    #[test]
    fn support_magnitude_direction_ord_matches_all_declaration_order() {
        assert_ord_matches_all_declaration_order(SupportMagnitudeDirection::ALL);
    }
}