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 37 of 40 · 500/page · 20000 rows next →
# nmargin_traced_6_40
18002 360020 1288249.990615
18003 360040 1288350.032740
18004 360060 1288450.075684
18005 360080 1288550.119449
18006 360100 1288650.164034
18007 360120 1288750.209439
18008 360140 1288850.255665
18009 360160 1288950.302710
18010 360180 1289050.350575
18011 360200 1289150.399259
18012 360220 1289250.448764
18013 360240 1289350.499088
18014 360260 1289450.550232
18015 360280 1289550.602196
18016 360300 1289650.654979
18017 360320 1289750.708582
18018 360340 1289850.763004
18019 360360 1289950.818246
18020 360380 1290050.874307
18021 360400 1290150.931188
18022 360420 1290250.988887
18023 360440 1290351.047406
18024 360460 1290451.106744
18025 360480 1290551.166901
18026 360500 1290651.227877
18027 360520 1290751.289673
18028 360540 1290851.352287
18029 360560 1290951.415720
18030 360580 1291051.479972
18031 360600 1291151.545042
18032 360620 1291251.610932
18033 360640 1291351.677640
18034 360660 1291451.745166
18035 360680 1291551.813512
18036 360700 1291651.882676
18037 360720 1291751.952658
18038 360740 1291852.023458
18039 360760 1291952.095077
18040 360780 1292052.167515
18041 360800 1292152.240770
18042 360820 1292252.314844
18043 360840 1292352.389736
18044 360860 1292452.465446
18045 360880 1292552.541974
18046 360900 1292652.619320
18047 360920 1292752.697484
18048 360940 1292852.776466
18049 360960 1292952.856266
18050 360980 1293052.936883
18051 361000 1293153.018318
18052 361020 1293253.100571
18053 361040 1293353.183642
18054 361060 1293453.267530
18055 361080 1293553.352235
18056 361100 1293653.437758
18057 361120 1293753.524099
18058 361140 1293853.611256
18059 361160 1293953.699231
18060 361180 1294053.788024
18061 361200 1294153.877633
18062 361220 1294253.968060
18063 361240 1294354.059303
18064 361260 1294454.151364
18065 361280 1294554.244242
18066 361300 1294654.337936
18067 361320 1294754.432448
18068 361340 1294854.527776
18069 361360 1294954.623921
18070 361380 1295054.720883
18071 361400 1295154.818661
18072 361420 1295254.917257
18073 361440 1295355.016668
18074 361460 1295455.116896
18075 361480 1295555.217941
18076 361500 1295655.319802
18077 361520 1295755.422479
18078 361540 1295855.525973
18079 361560 1295955.630282
18080 361580 1296055.735408
18081 361600 1296155.841350
18082 361620 1296255.948109
18083 361640 1296356.055683
18084 361660 1296456.164073
18085 361680 1296556.273279
18086 361700 1296656.383301
18087 361720 1296756.494139
18088 361740 1296856.605792
18089 361760 1296956.718262
18090 361780 1297056.831547
18091 361800 1297156.945647
18092 361820 1297257.060563
18093 361840 1297357.176295
18094 361860 1297457.292842
18095 361880 1297557.410204
18096 361900 1297657.528382
18097 361920 1297757.647375
18098 361940 1297857.767183
18099 361960 1297957.887806
18100 361980 1298058.009245
18101 362000 1298158.131498
18102 362020 1298258.254567
18103 362040 1298358.378450
18104 362060 1298458.503149
18105 362080 1298558.628662
18106 362100 1298658.754990
18107 362120 1298758.882133
18108 362140 1298859.010091
18109 362160 1298959.138863
18110 362180 1299059.268450
18111 362200 1299159.398851
18112 362220 1299259.530067
18113 362240 1299359.662097
18114 362260 1299459.794942
18115 362280 1299559.928601
18116 362300 1299660.063074
18117 362320 1299760.198362
18118 362340 1299860.334464
18119 362360 1299960.471379
18120 362380 1300060.609109
18121 362400 1300160.747653
18122 362420 1300260.887011
18123 362440 1300361.027183
18124 362460 1300461.168169
18125 362480 1300561.309968
18126 362500 1300661.452581
18127 362520 1300761.596008
18128 362540 1300861.740249
18129 362560 1300961.885303
18130 362580 1301062.031170
18131 362600 1301162.177852
18132 362620 1301262.325346
18133 362640 1301362.473654
18134 362660 1301462.622775
18135 362680 1301562.772710
18136 362700 1301662.923458
18137 362720 1301763.075019
18138 362740 1301863.227393
18139 362760 1301963.380580
18140 362780 1302063.534580
18141 362800 1302163.689393
18142 362820 1302263.845019
18143 362840 1302364.001458
18144 362860 1302464.158710
18145 362880 1302564.316775
18146 362900 1302664.475652
18147 362920 1302764.635341
18148 362940 1302864.795844
18149 362960 1302964.957159
18150 362980 1303065.119286
18151 363000 1303165.282226
18152 363020 1303265.445978
18153 363040 1303365.610543
18154 363060 1303465.775920
18155 363080 1303565.942109
18156 363100 1303666.109110
18157 363120 1303766.276924
18158 363140 1303866.445549
18159 363160 1303966.614987
18160 363180 1304066.785236
18161 363200 1304166.956297
18162 363220 1304267.128171
18163 363240 1304367.300856
18164 363260 1304467.474352
18165 363280 1304567.648661
18166 363300 1304667.823781
18167 363320 1304767.999713
18168 363340 1304868.176456
18169 363360 1304968.354011
18170 363380 1305068.532377
18171 363400 1305168.711555
18172 363420 1305268.891544
18173 363440 1305369.072344
18174 363460 1305469.253955
18175 363480 1305569.436378
18176 363500 1305669.619612
18177 363520 1305769.803656
18178 363540 1305869.988512
18179 363560 1305970.174179
18180 363580 1306070.360657
18181 363600 1306170.547945
18182 363620 1306270.736045
18183 363640 1306370.924955
18184 363660 1306471.114676
18185 363680 1306571.305207
18186 363700 1306671.496549
18187 363720 1306771.688702
18188 363740 1306871.881665
18189 363760 1306972.075439
18190 363780 1307072.270023
18191 363800 1307172.465417
18192 363820 1307272.661622
18193 363840 1307372.858637
18194 363860 1307473.056462
18195 363880 1307573.255097
18196 363900 1307673.454542
18197 363920 1307773.654798
18198 363940 1307873.855863
18199 363960 1307974.057738
18200 363980 1308074.260423
18201 364000 1308174.463918
18202 364020 1308274.668223
18203 364040 1308374.873337
18204 364060 1308475.079261
18205 364080 1308575.285995
18206 364100 1308675.493538
18207 364120 1308775.701891
18208 364140 1308875.911053
18209 364160 1308976.121025
18210 364180 1309076.331805
18211 364200 1309176.543396
18212 364220 1309276.755795
18213 364240 1309376.969004
18214 364260 1309477.183022
18215 364280 1309577.397849
18216 364300 1309677.613484
18217 364320 1309777.829929
18218 364340 1309878.047183
18219 364360 1309978.265246
18220 364380 1310078.484117
18221 364400 1310178.703798
18222 364420 1310278.924287
18223 364440 1310379.145585
18224 364460 1310479.367691
18225 364480 1310579.590606
18226 364500 1310679.814329
18227 364520 1310780.038861
18228 364540 1310880.264201
18229 364560 1310980.490350
18230 364580 1311080.717307
18231 364600 1311180.945072
18232 364620 1311281.173646
18233 364640 1311381.403027
18234 364660 1311481.633217
18235 364680 1311581.864215
18236 364700 1311682.096021
18237 364720 1311782.328634
18238 364740 1311882.562056
18239 364760 1311982.796285
18240 364780 1312083.031322
18241 364800 1312183.267167
18242 364820 1312283.503820
18243 364840 1312383.741280
18244 364860 1312483.979548
18245 364880 1312584.218623
18246 364900 1312684.458506
18247 364920 1312784.699196
18248 364940 1312884.940694
18249 364960 1312985.182999
18250 364980 1313085.426111
18251 365000 1313185.670031
18252 365020 1313285.914757
18253 365040 1313386.160291
18254 365060 1313486.406632
18255 365080 1313586.653780
18256 365100 1313686.901734
18257 365120 1313787.150496
18258 365140 1313887.400065
18259 365160 1313987.650440
18260 365180 1314087.901622
18261 365200 1314188.153611
18262 365220 1314288.406406
18263 365240 1314388.660008
18264 365260 1314488.914417
18265 365280 1314589.169632
18266 365300 1314689.425653
18267 365320 1314789.682481
18268 365340 1314889.940115
18269 365360 1314990.198556
18270 365380 1315090.457803
18271 365400 1315190.717855
18272 365420 1315290.978714
18273 365440 1315391.240380
18274 365460 1315491.502851
18275 365480 1315591.766128
18276 365500 1315692.030211
18277 365520 1315792.295100
18278 365540 1315892.560795
18279 365560 1315992.827295
18280 365580 1316093.094601
18281 365600 1316193.362713
18282 365620 1316293.631631
18283 365640 1316393.901354
18284 365660 1316494.171882
18285 365680 1316594.443216
18286 365700 1316694.715356
18287 365720 1316794.988300
18288 365740 1316895.262051
18289 365760 1316995.536606
18290 365780 1317095.811966
18291 365800 1317196.088132
18292 365820 1317296.365103
18293 365840 1317396.642879
18294 365860 1317496.921459
18295 365880 1317597.200845
18296 365900 1317697.481036
18297 365920 1317797.762031
18298 365940 1317898.043832
18299 365960 1317998.326437
18300 365980 1318098.609846
18301 366000 1318198.894061
18302 366020 1318299.179079
18303 366040 1318399.464903
18304 366060 1318499.751531
18305 366080 1318600.038963
18306 366100 1318700.327200
18307 366120 1318800.616241
18308 366140 1318900.906086
18309 366160 1319001.196736
18310 366180 1319101.488189
18311 366200 1319201.780447
18312 366220 1319302.073509
18313 366240 1319402.367375
18314 366260 1319502.662045
18315 366280 1319602.957518
18316 366300 1319703.253796
18317 366320 1319803.550877
18318 366340 1319903.848763
18319 366360 1320004.147451
18320 366380 1320104.446944
18321 366400 1320204.747240
18322 366420 1320305.048340
18323 366440 1320405.350243
18324 366460 1320505.652950
18325 366480 1320605.956460
18326 366500 1320706.260773
18327 366520 1320806.565890
18328 366540 1320906.871810
18329 366560 1321007.178533
18330 366580 1321107.486059
18331 366600 1321207.794388
18332 366620 1321308.103521
18333 366640 1321408.413456
18334 366660 1321508.724194
18335 366680 1321609.035735
18336 366700 1321709.348079
18337 366720 1321809.661226
18338 366740 1321909.975176
18339 366760 1322010.289928
18340 366780 1322110.605483
18341 366800 1322210.921840
18342 366820 1322311.239000
18343 366840 1322411.556962
18344 366860 1322511.875727
18345 366880 1322612.195294
18346 366900 1322712.515664
18347 366920 1322812.836835
18348 366940 1322913.158809
18349 366960 1323013.481585
18350 366980 1323113.805164
18351 367000 1323214.129544
18352 367020 1323314.454726
18353 367040 1323414.780711
18354 367060 1323515.107497
18355 367080 1323615.435085
18356 367100 1323715.763475
18357 367120 1323816.092666
18358 367140 1323916.422660
18359 367160 1324016.753454
18360 367180 1324117.085051
18361 367200 1324217.417449
18362 367220 1324317.750649
18363 367240 1324418.084650
18364 367260 1324518.419452
18365 367280 1324618.755056
18366 367300 1324719.091461
18367 367320 1324819.428667
18368 367340 1324919.766675
18369 367360 1325020.105484
18370 367380 1325120.445093
18371 367400 1325220.785504
18372 367420 1325321.126716
18373 367440 1325421.468729
18374 367460 1325521.811542
18375 367480 1325622.155157
18376 367500 1325722.499572
18377 367520 1325822.844788
18378 367540 1325923.190804
18379 367560 1326023.537622
18380 367580 1326123.885239
18381 367600 1326224.233658
18382 367620 1326324.582876
18383 367640 1326424.932896
18384 367660 1326525.283715
18385 367680 1326625.635335
18386 367700 1326725.987756
18387 367720 1326826.340976
18388 367740 1326926.694997
18389 367760 1327027.049817
18390 367780 1327127.405438
18391 367800 1327227.761859
18392 367820 1327328.119080
18393 367840 1327428.477100
18394 367860 1327528.835921
18395 367880 1327629.195541
18396 367900 1327729.555961
18397 367920 1327829.917181
18398 367940 1327930.279201
18399 367960 1328030.642020
18400 367980 1328131.005639
18401 368000 1328231.370057
18402 368020 1328331.735274
18403 368040 1328432.101291
18404 368060 1328532.468108
18405 368080 1328632.835724
18406 368100 1328733.204138
18407 368120 1328833.573353
18408 368140 1328933.943366
18409 368160 1329034.314178
18410 368180 1329134.685790
18411 368200 1329235.058200
18412 368220 1329335.431410
18413 368240 1329435.805418
18414 368260 1329536.180225
18415 368280 1329636.555831
18416 368300 1329736.932236
18417 368320 1329837.309439
18418 368340 1329937.687441
18419 368360 1330038.066242
18420 368380 1330138.445841
18421 368400 1330238.826238
18422 368420 1330339.207435
18423 368440 1330439.589429
18424 368460 1330539.972222
18425 368480 1330640.355813
18426 368500 1330740.740202
18427 368520 1330841.125390
18428 368540 1330941.511375
18429 368560 1331041.898159
18430 368580 1331142.285741
18431 368600 1331242.674121
18432 368620 1331343.063298
18433 368640 1331443.453274
18434 368660 1331543.844047
18435 368680 1331644.235618
18436 368700 1331744.627987
18437 368720 1331845.021154
18438 368740 1331945.415118
18439 368760 1332045.809880
18440 368780 1332146.205439
18441 368800 1332246.601796
18442 368820 1332346.998950
18443 368840 1332447.396902
18444 368860 1332547.795651
18445 368880 1332648.195197
18446 368900 1332748.595540
18447 368920 1332848.996681
18448 368940 1332949.398618
18449 368960 1333049.801353
18450 368980 1333150.204885
18451 369000 1333250.609214
18452 369020 1333351.014339
18453 369040 1333451.420262
18454 369060 1333551.826981
18455 369080 1333652.234497
18456 369100 1333752.642810
18457 369120 1333853.051919
18458 369140 1333953.461826
18459 369160 1334053.872528
18460 369180 1334154.284027
18461 369200 1334254.696323
18462 369220 1334355.109415
18463 369240 1334455.523303
18464 369260 1334555.937988
18465 369280 1334656.353469
18466 369300 1334756.769746
18467 369320 1334857.186820
18468 369340 1334957.604689
18469 369360 1335058.023355
18470 369380 1335158.442816
18471 369400 1335258.863074
18472 369420 1335359.284127
18473 369440 1335459.705976
18474 369460 1335560.128621
18475 369480 1335660.552062
18476 369500 1335760.976299
18477 369520 1335861.401331
18478 369540 1335961.827159
18479 369560 1336062.253782
18480 369580 1336162.681201
18481 369600 1336263.109415
18482 369620 1336363.538425
18483 369640 1336463.968230
18484 369660 1336564.398830
18485 369680 1336664.830226
18486 369700 1336765.262416
18487 369720 1336865.695402
18488 369740 1336966.129183
18489 369760 1337066.563759
18490 369780 1337166.999130
18491 369800 1337267.435296
18492 369820 1337367.872257
18493 369840 1337468.310013
18494 369860 1337568.748564
18495 369880 1337669.187909
18496 369900 1337769.628049
18497 369920 1337870.068984
18498 369940 1337970.510713
18499 369960 1338070.953237
18500 369980 1338171.396555
18501 370000 1338271.840668

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())