Current task: —

E-028-traced-margin.py

Experiments: E-028 · script updated 08-19-2026

E-028-traced-margin.csv — 429.7 KB, updated 08-19-2026

← prev page 3 of 40 · 500/page · 20000 rows next →
# nmargin_traced_6_40
1002 20020 -164594.580740
1003 20040 -164559.664929
1004 20060 -164524.711564
1005 20080 -164489.720701
1006 20100 -164454.692395
1007 20120 -164419.626705
1008 20140 -164384.523685
1009 20160 -164349.383391
1010 20180 -164314.205880
1011 20200 -164278.991207
1012 20220 -164243.739427
1013 20240 -164208.450596
1014 20260 -164173.124770
1015 20280 -164137.762002
1016 20300 -164102.362349
1017 20320 -164066.925864
1018 20340 -164031.452603
1019 20360 -163995.942621
1020 20380 -163960.395970
1021 20400 -163924.812707
1022 20420 -163889.192884
1023 20440 -163853.536556
1024 20460 -163817.843777
1025 20480 -163782.114600
1026 20500 -163746.349079
1027 20520 -163710.547267
1028 20540 -163674.709218
1029 20560 -163638.834985
1030 20580 -163602.924620
1031 20600 -163566.978177
1032 20620 -163530.995708
1033 20640 -163494.977267
1034 20660 -163458.922904
1035 20680 -163422.832674
1036 20700 -163386.706628
1037 20720 -163350.544818
1038 20740 -163314.347295
1039 20760 -163278.114113
1040 20780 -163241.845323
1041 20800 -163205.540975
1042 20820 -163169.201123
1043 20840 -163132.825816
1044 20860 -163096.415106
1045 20880 -163059.969045
1046 20900 -163023.487682
1047 20920 -162986.971070
1048 20940 -162950.419258
1049 20960 -162913.832297
1050 20980 -162877.210237
1051 21000 -162840.553130
1052 21020 -162803.861025
1053 21040 -162767.133971
1054 21060 -162730.372020
1055 21080 -162693.575220
1056 21100 -162656.743622
1057 21120 -162619.877275
1058 21140 -162582.976228
1059 21160 -162546.040531
1060 21180 -162509.070233
1061 21200 -162472.065383
1062 21220 -162435.026031
1063 21240 -162397.952224
1064 21260 -162360.844011
1065 21280 -162323.701442
1066 21300 -162286.524564
1067 21320 -162249.313426
1068 21340 -162212.068077
1069 21360 -162174.788563
1070 21380 -162137.474934
1071 21400 -162100.127238
1072 21420 -162062.745521
1073 21440 -162025.329832
1074 21460 -161987.880218
1075 21480 -161950.396727
1076 21500 -161912.879406
1077 21520 -161875.328302
1078 21540 -161837.743462
1079 21560 -161800.124933
1080 21580 -161762.472763
1081 21600 -161724.786997
1082 21620 -161687.067682
1083 21640 -161649.314866
1084 21660 -161611.528594
1085 21680 -161573.708912
1086 21700 -161535.855868
1087 21720 -161497.969506
1088 21740 -161460.049873
1089 21760 -161422.097015
1090 21780 -161384.110977
1091 21800 -161346.091806
1092 21820 -161308.039546
1093 21840 -161269.954243
1094 21860 -161231.835943
1095 21880 -161193.684690
1096 21900 -161155.500530
1097 21920 -161117.283508
1098 21940 -161079.033668
1099 21960 -161040.751056
1100 21980 -161002.435715
1101 22000 -160964.087691
1102 22020 -160925.707029
1103 22040 -160887.293771
1104 22060 -160848.847964
1105 22080 -160810.369650
1106 22100 -160771.858874
1107 22120 -160733.315680
1108 22140 -160694.740111
1109 22160 -160656.132212
1110 22180 -160617.492026
1111 22200 -160578.819597
1112 22220 -160540.114967
1113 22240 -160501.378181
1114 22260 -160462.609282
1115 22280 -160423.808312
1116 22300 -160384.975315
1117 22320 -160346.110333
1118 22340 -160307.213410
1119 22360 -160268.284589
1120 22380 -160229.323911
1121 22400 -160190.331419
1122 22420 -160151.307156
1123 22440 -160112.251165
1124 22460 -160073.163486
1125 22480 -160034.044164
1126 22500 -159994.893239
1127 22520 -159955.710753
1128 22540 -159916.496749
1129 22560 -159877.251268
1130 22580 -159837.974351
1131 22600 -159798.666041
1132 22620 -159759.326379
1133 22640 -159719.955406
1134 22660 -159680.553164
1135 22680 -159641.119693
1136 22700 -159601.655035
1137 22720 -159562.159231
1138 22740 -159522.632321
1139 22760 -159483.074347
1140 22780 -159443.485349
1141 22800 -159403.865367
1142 22820 -159364.214443
1143 22840 -159324.532617
1144 22860 -159284.819929
1145 22880 -159245.076420
1146 22900 -159205.302128
1147 22920 -159165.497096
1148 22940 -159125.661362
1149 22960 -159085.794967
1150 22980 -159045.897950
1151 23000 -159005.970351
1152 23020 -158966.012209
1153 23040 -158926.023565
1154 23060 -158886.004457
1155 23080 -158845.954926
1156 23100 -158805.875010
1157 23120 -158765.764748
1158 23140 -158725.624180
1159 23160 -158685.453344
1160 23180 -158645.252280
1161 23200 -158605.021026
1162 23220 -158564.759621
1163 23240 -158524.468104
1164 23260 -158484.146513
1165 23280 -158443.794887
1166 23300 -158403.413265
1167 23320 -158363.001683
1168 23340 -158322.560182
1169 23360 -158282.088798
1170 23380 -158241.587571
1171 23400 -158201.056537
1172 23420 -158160.495736
1173 23440 -158119.905204
1174 23460 -158079.284979
1175 23480 -158038.635100
1176 23500 -157997.955603
1177 23520 -157957.246526
1178 23540 -157916.507906
1179 23560 -157875.739782
1180 23580 -157834.942190
1181 23600 -157794.115166
1182 23620 -157753.258749
1183 23640 -157712.372976
1184 23660 -157671.457882
1185 23680 -157630.513506
1186 23700 -157589.539883
1187 23720 -157548.537051
1188 23740 -157507.505046
1189 23760 -157466.443905
1190 23780 -157425.353663
1191 23800 -157384.234358
1192 23820 -157343.086025
1193 23840 -157301.908701
1194 23860 -157260.702422
1195 23880 -157219.467225
1196 23900 -157178.203144
1197 23920 -157136.910215
1198 23940 -157095.588476
1199 23960 -157054.237961
1200 23980 -157012.858705
1201 24000 -156971.450746
1202 24020 -156930.014117
1203 24040 -156888.548855
1204 24060 -156847.054995
1205 24080 -156805.532572
1206 24100 -156763.981621
1207 24120 -156722.402177
1208 24140 -156680.794276
1209 24160 -156639.157953
1210 24180 -156597.493242
1211 24200 -156555.800178
1212 24220 -156514.078796
1213 24240 -156472.329130
1214 24260 -156430.551216
1215 24280 -156388.745087
1216 24300 -156346.910779
1217 24320 -156305.048325
1218 24340 -156263.157759
1219 24360 -156221.239117
1220 24380 -156179.292433
1221 24400 -156137.317739
1222 24420 -156095.315071
1223 24440 -156053.284462
1224 24460 -156011.225946
1225 24480 -155969.139557
1226 24500 -155927.025329
1227 24520 -155884.883295
1228 24540 -155842.713489
1229 24560 -155800.515945
1230 24580 -155758.290695
1231 24600 -155716.037774
1232 24620 -155673.757214
1233 24640 -155631.449049
1234 24660 -155589.113312
1235 24680 -155546.750036
1236 24700 -155504.359255
1237 24720 -155461.941000
1238 24740 -155419.495305
1239 24760 -155377.022204
1240 24780 -155334.521727
1241 24800 -155291.993909
1242 24820 -155249.438782
1243 24840 -155206.856378
1244 24860 -155164.246730
1245 24880 -155121.609870
1246 24900 -155078.945831
1247 24920 -155036.254645
1248 24940 -154993.536344
1249 24960 -154950.790960
1250 24980 -154908.018526
1251 25000 -154865.219073
1252 25020 -154822.392634
1253 25040 -154779.539240
1254 25060 -154736.658922
1255 25080 -154693.751714
1256 25100 -154650.817646
1257 25120 -154607.856750
1258 25140 -154564.869058
1259 25160 -154521.854601
1260 25180 -154478.813411
1261 25200 -154435.745519
1262 25220 -154392.650956
1263 25240 -154349.529753
1264 25260 -154306.381942
1265 25280 -154263.207554
1266 25300 -154220.006620
1267 25320 -154176.779171
1268 25340 -154133.525237
1269 25360 -154090.244850
1270 25380 -154046.938041
1271 25400 -154003.604839
1272 25420 -153960.245277
1273 25440 -153916.859383
1274 25460 -153873.447190
1275 25480 -153830.008727
1276 25500 -153786.544026
1277 25520 -153743.053115
1278 25540 -153699.536026
1279 25560 -153655.992789
1280 25580 -153612.423433
1281 25600 -153568.827990
1282 25620 -153525.206489
1283 25640 -153481.558960
1284 25660 -153437.885433
1285 25680 -153394.185938
1286 25700 -153350.460505
1287 25720 -153306.709163
1288 25740 -153262.931943
1289 25760 -153219.128874
1290 25780 -153175.299985
1291 25800 -153131.445305
1292 25820 -153087.564866
1293 25840 -153043.658695
1294 25860 -152999.726822
1295 25880 -152955.769277
1296 25900 -152911.786089
1297 25920 -152867.777286
1298 25940 -152823.742899
1299 25960 -152779.682955
1300 25980 -152735.597485
1301 26000 -152691.486516
1302 26020 -152647.350079
1303 26040 -152603.188201
1304 26060 -152559.000911
1305 26080 -152514.788239
1306 26100 -152470.550212
1307 26120 -152426.286860
1308 26140 -152381.998211
1309 26160 -152337.684294
1310 26180 -152293.345136
1311 26200 -152248.980766
1312 26220 -152204.591213
1313 26240 -152160.176505
1314 26260 -152115.736670
1315 26280 -152071.271737
1316 26300 -152026.781732
1317 26320 -151982.266685
1318 26340 -151937.726623
1319 26360 -151893.161575
1320 26380 -151848.571568
1321 26400 -151803.956629
1322 26420 -151759.316788
1323 26440 -151714.652071
1324 26460 -151669.962506
1325 26480 -151625.248121
1326 26500 -151580.508943
1327 26520 -151535.745000
1328 26540 -151490.956319
1329 26560 -151446.142928
1330 26580 -151401.304854
1331 26600 -151356.442124
1332 26620 -151311.554766
1333 26640 -151266.642806
1334 26660 -151221.706272
1335 26680 -151176.745192
1336 26700 -151131.759591
1337 26720 -151086.749497
1338 26740 -151041.714937
1339 26760 -150996.655938
1340 26780 -150951.572526
1341 26800 -150906.464729
1342 26820 -150861.332573
1343 26840 -150816.176084
1344 26860 -150770.995290
1345 26880 -150725.790217
1346 26900 -150680.560891
1347 26920 -150635.307339
1348 26940 -150590.029587
1349 26960 -150544.727662
1350 26980 -150499.401590
1351 27000 -150454.051398
1352 27020 -150408.677111
1353 27040 -150363.278755
1354 27060 -150317.856357
1355 27080 -150272.409943
1356 27100 -150226.939539
1357 27120 -150181.445171
1358 27140 -150135.926864
1359 27160 -150090.384645
1360 27180 -150044.818539
1361 27200 -149999.228573
1362 27220 -149953.614771
1363 27240 -149907.977160
1364 27260 -149862.315766
1365 27280 -149816.630613
1366 27300 -149770.921727
1367 27320 -149725.189134
1368 27340 -149679.432860
1369 27360 -149633.652929
1370 27380 -149587.849367
1371 27400 -149542.022199
1372 27420 -149496.171451
1373 27440 -149450.297147
1374 27460 -149404.399313
1375 27480 -149358.477974
1376 27500 -149312.533156
1377 27520 -149266.564882
1378 27540 -149220.573178
1379 27560 -149174.558069
1380 27580 -149128.519580
1381 27600 -149082.457736
1382 27620 -149036.372561
1383 27640 -148990.264080
1384 27660 -148944.132317
1385 27680 -148897.977299
1386 27700 -148851.799048
1387 27720 -148805.597590
1388 27740 -148759.372949
1389 27760 -148713.125149
1390 27780 -148666.854215
1391 27800 -148620.560172
1392 27820 -148574.243044
1393 27840 -148527.902854
1394 27860 -148481.539627
1395 27880 -148435.153388
1396 27900 -148388.744161
1397 27920 -148342.311968
1398 27940 -148295.856836
1399 27960 -148249.378787
1400 27980 -148202.877846
1401 28000 -148156.354037
1402 28020 -148109.807383
1403 28040 -148063.237908
1404 28060 -148016.645636
1405 28080 -147970.030591
1406 28100 -147923.392797
1407 28120 -147876.732277
1408 28140 -147830.049054
1409 28160 -147783.343154
1410 28180 -147736.614598
1411 28200 -147689.863410
1412 28220 -147643.089614
1413 28240 -147596.293234
1414 28260 -147549.474292
1415 28280 -147502.632813
1416 28300 -147455.768818
1417 28320 -147408.882332
1418 28340 -147361.973378
1419 28360 -147315.041979
1420 28380 -147268.088158
1421 28400 -147221.111937
1422 28420 -147174.113341
1423 28440 -147127.092392
1424 28460 -147080.049112
1425 28480 -147032.983526
1426 28500 -146985.895656
1427 28520 -146938.785524
1428 28540 -146891.653153
1429 28560 -146844.498567
1430 28580 -146797.321787
1431 28600 -146750.122837
1432 28620 -146702.901739
1433 28640 -146655.658516
1434 28660 -146608.393190
1435 28680 -146561.105784
1436 28700 -146513.796319
1437 28720 -146466.464820
1438 28740 -146419.111307
1439 28760 -146371.735804
1440 28780 -146324.338333
1441 28800 -146276.918915
1442 28820 -146229.477573
1443 28840 -146182.014330
1444 28860 -146134.529207
1445 28880 -146087.022227
1446 28900 -146039.493411
1447 28920 -145991.942782
1448 28940 -145944.370362
1449 28960 -145896.776172
1450 28980 -145849.160235
1451 29000 -145801.522571
1452 29020 -145753.863205
1453 29040 -145706.182156
1454 29060 -145658.479446
1455 29080 -145610.755099
1456 29100 -145563.009134
1457 29120 -145515.241574
1458 29140 -145467.452440
1459 29160 -145419.641755
1460 29180 -145371.809538
1461 29200 -145323.955813
1462 29220 -145276.080600
1463 29240 -145228.183921
1464 29260 -145180.265797
1465 29280 -145132.326250
1466 29300 -145084.365300
1467 29320 -145036.382970
1468 29340 -144988.379279
1469 29360 -144940.354251
1470 29380 -144892.307905
1471 29400 -144844.240262
1472 29420 -144796.151345
1473 29440 -144748.041173
1474 29460 -144699.909768
1475 29480 -144651.757152
1476 29500 -144603.583344
1477 29520 -144555.388365
1478 29540 -144507.172238
1479 29560 -144458.934981
1480 29580 -144410.676617
1481 29600 -144362.397166
1482 29620 -144314.096648
1483 29640 -144265.775085
1484 29660 -144217.432497
1485 29680 -144169.068904
1486 29700 -144120.684328
1487 29720 -144072.278788
1488 29740 -144023.852306
1489 29760 -143975.404901
1490 29780 -143926.936594
1491 29800 -143878.447406
1492 29820 -143829.937357
1493 29840 -143781.406467
1494 29860 -143732.854756
1495 29880 -143684.282245
1496 29900 -143635.688955
1497 29920 -143587.074904
1498 29940 -143538.440114
1499 29960 -143489.784604
1500 29980 -143441.108395
1501 30000 -143392.411507

E-028-traced-margin.json — 3.7 KB, updated 08-19-2026

JSON sidecar (click to expand)
{
  "experiment": "E-028",
  "task": "4.5a support: D-056 traced R-bound verification + margin rerun with A=10.5, B0=48 (honest C0 incl. log log term)",
  "script": "research/numerics/scripts/E-028-traced-margin.py",
  "checks": {
    "V_R_traced_bound_holds": {
      "pass": true,
      "points": [
        {
          "sigma": -2.5,
          "t": 10.0,
          "abs_R": 0.5364627998701963,
          "bound": 74.091519822774,
          "holds": true
        },
        {
          "sigma": -2.5,
          "t": 50.0,
          "abs_R": 1.8035543334872959,
          "bound": 89.48805904510499,
          "holds": true
        },
        {
          "sigma": -2.5,
          "t": 100.0,
          "abs_R": 2.726827160278793,
          "bound": 96.56221453948484,
          "holds": true
        },
        {
          "sigma": -2.5,
          "t": 500.0,
          "abs_R": 4.0305314954089475,
          "bound": 113.29530125676315,
          "holds": true
        },
        {
          "sigma": -2.5,
          "t": 1000.0,
          "abs_R": 4.7507714994958565,
          "bound": 120.5524094572705,
          "holds": true
        },
        {
          "sigma": 0.5,
          "t": 10.0,
          "abs_R": 0.232976073221556,
          "bound": 74.091519822774,
          "holds": true
        },
        {
          "sigma": 0.5,
          "t": 50.0,
          "abs_R": 1.0575019981720868,
          "bound": 89.48805904510499,
          "holds": true
        },
        {
          "sigma": 0.5,
          "t": 100.0,
          "abs_R": 1.3861083473172386,
          "bound": 96.56221453948484,
          "holds": true
        },
        {
          "sigma": 0.5,
          "t": 500.0,
          "abs_R": 2.191750394872167,
          "bound": 113.29530125676315,
          "holds": true
        },
        {
          "sigma": 0.5,
          "t": 1000.0,
          "abs_R": 2.535043296015203,
          "bound": 120.5524094572705,
          "holds": true
        },
        {
          "sigma": 2.0,
          "t": 10.0,
          "abs_R": 0.11614405022018243,
          "bound": 74.091519822774,
          "holds": true
        },
        {
          "sigma": 2.0,
          "t": 50.0,
          "abs_R": 0.47282316679931,
          "bound": 89.48805904510499,
          "holds": true
        },
        {
          "sigma": 2.0,
          "t": 100.0,
          "abs_R": 0.13345107201883163,
          "bound": 96.56221453948484,
          "holds": true
        },
        {
          "sigma": 2.0,
          "t": 500.0,
          "abs_R": 0.6914268199229783,
          "bound": 113.29530125676315,
          "holds": true
        },
        {
          "sigma": 2.0,
          "t": 1000.0,
          "abs_R": 0.6591087549534896,
          "bound": 120.5524094572705,
          "holds": true
        }
      ]
    },
    "V5_Z2_certified": {
      "pass": true,
      "partial": 0.5699599927023044,
      "tail": 1.4815510557964273e-05,
      "bound": 0.5699748082128623
    },
    "V2_margin_positive_convex": true
  },
  "key_values": {
    "M0_from_E023": 1.335180201468999,
    "N0_traced_10p5_48": 75451,
    "margin_N0": 2.396310426061973,
    "overlap_factor_vs_MV_5e5": 6.626817404673232,
    "margin_at": {
      "75451": 2.396310426061973,
      "100000": 92785.67601524561,
      "500000": 2006008.571308432,
      "1000000": 4755774.032035855,
      "1000000000": 8921657382.546026,
      "1000000000000": 12395765983564.96,
      "1000000000000000000": 1.9304326196882584e+19,
      "8999999999994000000000001": 2.4579625383799396e+26
    },
    "N1": 8999999999994000000000001
  },
  "elapsed_seconds": 3.7
}

Source code

Python script (click to expand)
"""E-028 — task 4.5a support: D-056 traced R-bound verification + margin rerun.

Components:
  V-R. Verify the traced reference-point R-bound (D-056 Theorem R)
       |R(s)| <= 6.0 log(|t|+2) + 40,  sigma in [-5/2, 3], |t| >= 10
       at sample points sigma in {-2.5, 0.5, 2}, t in {10,50,100,500,1000}
       (R(s) = zeta'/zeta(s) - sum_{|gamma-t|<1} 1/(s-rho), zeta'/zeta
       via the E-021 xi-route at dps 30; zeros from the E-027 cache).
  V5.  Certified Z2 = -zeta'/zeta(2) <= 0.5699: partial sum to 1e4 plus
       tail bound (log N + 1)/N.
  S3'. Margin rerun with the TRACED constants A = 6.0, B0 = 40 (was:
       measured 0.9/1.0, first-estimate 2.0/2.0) and the I_I length fix
       2(sqrt(n)+1). Recompute N0, contiguity to 4e5, convexity grid to
       N1, margin references. M0 = 1.3352 imported from E-023 (S1).

Outputs: research/numerics/data/E-028-traced-margin.csv (+ .json)
"""
import csv as csvmod
import json
import sys
import time
from pathlib import Path

import mpmath as mp
import numpy as np

REPO = Path(__file__).resolve().parents[3]
DATA = REPO / "research" / "numerics" / "data"
E021 = DATA / "E-021-sinf-sf-curve.csv"
E023J = DATA / "E-023-assembly.json"
ZCACHE = DATA / "E-027-zeros-cache.npy"
CSV = DATA / "E-028-traced-margin.csv"
JSON = DATA / "E-028-traced-margin.json"

GAMMA = 0.577215664901532860606512090082402431
C1L = (GAMMA - 1 - np.log(2 * np.pi)) / 2 - GAMMA / 2
A_TR, B0_TR = 10.5, 48.0
T0_PLATT = 3.0e12


def zeta_logder(s):
    sm = mp.mpc(s.real, s.imag)

    def xi_mp(u):
        return 0.5 * u * (u - 1) * mp.pi ** (-u / 2) * mp.gamma(u / 2) \
            * mp.zeta(u)

    xi_log = mp.diff(xi_mp, sm) / xi_mp(sm)
    return complex(xi_log - 1 / sm - 1 / (sm - 1)
                   + mp.mpf(0.5) * mp.log(mp.pi)
                   - mp.mpf(0.5) * mp.digamma(sm / 2))


def check_R_bound(zeros):
    mp.mp.dps = 30
    out = []
    for sigma in (-2.5, 0.5, 2.0):
        for t in (10.0, 50.0, 100.0, 500.0, 1000.0):
            s = complex(sigma, t)
            val = zeta_logder(s)
            near = [g for g in zeros if abs(g - t) < 1.0]
            r = val - sum(1.0 / (s - complex(0.5, g)) for g in near)
            bound = 10.5 * np.log(t + 2) + 48.0
            out.append({"sigma": sigma, "t": t, "abs_R": abs(r),
                        "bound": bound, "holds": bool(abs(r) <= bound)})
    return out


def certified_Z2(N=10 ** 6):
    """-zeta'/zeta(2) = sum Lambda(n)/n^2; partial sum + tail bound
    (log N + 1)/N. True value 0.569955...; certify <= 0.5700."""
    lam = np.zeros(N + 1)
    sieve = np.zeros(N + 1, dtype=np.int64)
    for p in range(2, N + 1):
        if sieve[p] == 0:
            sieve[p::p] = p
    for n in range(2, N + 1):
        p = sieve[n]
        if p > 0 and abs(p ** round(np.log(n) / np.log(p)) - n) < 0.5:
            lam[n] = np.log(p)
    part = float(np.sum(lam[2:] / np.arange(2, N + 1) ** 2))
    tail = (np.log(N) + 1) / N
    return part, tail, part + tail


def F_count(T):
    return (T / (2 * np.pi)) * np.log(T / (2 * np.pi)) - T / (2 * np.pi) \
        + 7 / 8


def S_bound(T):
    return 0.137 * np.log(T) + 0.443 * np.log(np.log(T)) + 1.588


def C0(t):
    return (F_count(t + 1) - F_count(t)) + S_bound(t + 1) + S_bound(t)


def H_bound(T):
    return 3 * C0(T) ** 2 + A_TR * np.log(T + 2) + B0_TR


def B_bound(n, m0):
    n = np.asarray(n, dtype=np.float64)
    T = np.sqrt(n) + 1.0
    twoN = 2 * (F_count(T) + S_bound(T))
    I3_long = 4 * T * ((2 / 3) * C0(T) + A_TR * np.log(T + 2) + B0_TR)
    I3_short = 40.0 * m0
    I24 = 2 * (np.e ** 4 + 1) * (7 * H_bound(T) + 3.3)
    r = np.sqrt(n)
    # I_I length fix: 2T = 2(sqrt(n)+1)
    logI1 = np.log(2 * (r + 1) * 0.5700) + r / 2 - (2 * r - 2) * np.log(2)
    I1 = np.where(logI1 > -700, np.exp(np.maximum(logI1, -745)), 0.0)
    return twoN + I3_long + I3_short + I24 + I1 + 1.0


def margin(n, m0):
    n = np.asarray(n, dtype=np.float64)
    return 0.5 * n * np.log(n) + C1L * n - 4.0 - B_bound(n, m0) + 1.0


def main() -> int:
    if JSON.exists() and "--force" not in sys.argv:
        print(f"cached: {JSON} (use --force to recompute)")
        return 0
    t0 = time.time()

    m0 = json.loads(E023J.read_text())["key_values"]["M0_use"]
    print(f"M0 imported from E-023: {m0}")

    print("V-R: traced R-bound verification ...", flush=True)
    zeros = np.load(ZCACHE)
    rpts = check_R_bound(zeros)
    vr = all(p["holds"] for p in rpts)
    worst = max(rpts, key=lambda p: p["abs_R"] / p["bound"])
    print(f"  all {len(rpts)} points hold: {vr}; worst ratio "
          f"{worst['abs_R']/worst['bound']:.3f} at "
          f"sigma={worst['sigma']}, t={worst['t']}", flush=True)

    print("V5: certified Z2 ...", flush=True)
    part, tail, z2 = certified_Z2()
    v5 = bool(z2 <= 0.5700)
    print(f"  partial {part:.6f} + tail {tail:.6f} = {z2:.6f} "
          f"<= 0.5700: {v5}", flush=True)

    print("S3': margin rerun with traced constants ...", flush=True)
    ngrid = np.arange(20, 400001)
    marg = margin(ngrid, m0)
    pos = ngrid[(marg > 0) & (np.gradient(marg, ngrid) > 0)]
    N0 = int(pos[0]) if len(pos) else -1
    cont = bool(np.all(marg[ngrid >= N0] > 0)) if N0 > 0 else False
    margN0 = float(marg[ngrid == N0][0]) if N0 > 0 else float("nan")
    print(f"  N0 (traced 6.0/40) = {N0} (contiguous to 4e5: {cont}, "
          f"margin(N0) = {margN0:.1f})", flush=True)

    logn = np.unique(np.logspace(np.log10(max(N0, 20)), np.log10(9e24),
                                 4000).astype(np.float64))
    bmarg = margin(logn, m0)
    conv = bool(np.all(np.diff(bmarg, 2) > -1e-6 * bmarg[:-2].max()))

    N1 = int(3_000_000_000_000 - 1) ** 2
    refs = {int(n): float(margin(n, m0)) for n in
            [N0, 100000, 500000, 10 ** 6, 10 ** 9, 10 ** 12, 10 ** 18,
             N1]}
    for k, v in refs.items():
        print(f"  margin({k:.3e}) = {v:.4e}", flush=True)
    v2 = bool(N0 > 0 and cont and conv and N0 < 500000)
    print(f"  convexity grid: {conv}; N0 < 5e5 (MV coverage): "
          f"{N0 < 500000}", flush=True)

    with open(CSV, "w", newline="") as f:
        w = csvmod.writer(f)
        w.writerow(["n", "margin_traced_6_40"])
        for n in range(20, 400001, 20):
            w.writerow([n, f"{float(margin(n, m0)):.6f}"])

    meta = {
        "experiment": "E-028",
        "task": "4.5a support: D-056 traced R-bound verification + "
                "margin rerun with A=10.5, B0=48 (honest C0 incl. log log term)",
        "script": "research/numerics/scripts/E-028-traced-margin.py",
        "checks": {
            "V_R_traced_bound_holds": {"pass": vr, "points": rpts},
            "V5_Z2_certified": {"pass": v5, "partial": part,
                                "tail": tail, "bound": z2},
            "V2_margin_positive_convex": v2,
        },
        "key_values": {
            "M0_from_E023": m0,
            "N0_traced_10p5_48": N0,
            "margin_N0": margN0,
            "overlap_factor_vs_MV_5e5": 500000 / N0 if N0 > 0 else None,
            "margin_at": {str(k): v for k, v in refs.items()},
            "N1": N1,
        },
        "elapsed_seconds": round(time.time() - t0, 1),
    }
    JSON.write_text(json.dumps(meta, indent=2))
    print(f"  wrote {CSV.name}, {JSON.name}; elapsed "
          f"{meta['elapsed_seconds']}s")
    return 0 if (vr and v5 and v2) else 1


if __name__ == "__main__":
    sys.exit(main())