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 39 of 40 · 500/page · 20000 rows next →
# nmargin_traced_6_40
19002 380020 1388693.198219
19003 380040 1388794.034916
19004 380060 1388894.872382
19005 380080 1388995.710619
19006 380100 1389096.549625
19007 380120 1389197.389401
19008 380140 1389298.229947
19009 380160 1389399.071262
19010 380180 1389499.913347
19011 380200 1389600.756201
19012 380220 1389701.599825
19013 380240 1389802.444219
19014 380260 1389903.289381
19015 380280 1390004.135314
19016 380300 1390104.982015
19017 380320 1390205.829486
19018 380340 1390306.677726
19019 380360 1390407.526735
19020 380380 1390508.376513
19021 380400 1390609.227061
19022 380420 1390710.078377
19023 380440 1390810.930462
19024 380460 1390911.783317
19025 380480 1391012.636940
19026 380500 1391113.491332
19027 380520 1391214.346493
19028 380540 1391315.202422
19029 380560 1391416.059120
19030 380580 1391516.916587
19031 380600 1391617.774823
19032 380620 1391718.633827
19033 380640 1391819.493599
19034 380660 1391920.354141
19035 380680 1392021.215450
19036 380700 1392122.077528
19037 380720 1392222.940374
19038 380740 1392323.803988
19039 380760 1392424.668371
19040 380780 1392525.533522
19041 380800 1392626.399441
19042 380820 1392727.266128
19043 380840 1392828.133583
19044 380860 1392929.001806
19045 380880 1393029.870797
19046 380900 1393130.740556
19047 380920 1393231.611082
19048 380940 1393332.482377
19049 380960 1393433.354439
19050 380980 1393534.227269
19051 381000 1393635.100867
19052 381020 1393735.975232
19053 381040 1393836.850365
19054 381060 1393937.726265
19055 381080 1394038.602933
19056 381100 1394139.480368
19057 381120 1394240.358571
19058 381140 1394341.237541
19059 381160 1394442.117278
19060 381180 1394542.997783
19061 381200 1394643.879054
19062 381220 1394744.761093
19063 381240 1394845.643899
19064 381260 1394946.527472
19065 381280 1395047.411812
19066 381300 1395148.296919
19067 381320 1395249.182793
19068 381340 1395350.069433
19069 381360 1395450.956841
19070 381380 1395551.845015
19071 381400 1395652.733956
19072 381420 1395753.623664
19073 381440 1395854.514138
19074 381460 1395955.405379
19075 381480 1396056.297386
19076 381500 1396157.190160
19077 381520 1396258.083700
19078 381540 1396358.978007
19079 381560 1396459.873080
19080 381580 1396560.768919
19081 381600 1396661.665525
19082 381620 1396762.562897
19083 381640 1396863.461034
19084 381660 1396964.359938
19085 381680 1397065.259608
19086 381700 1397166.160045
19087 381720 1397267.061247
19088 381740 1397367.963215
19089 381760 1397468.865948
19090 381780 1397569.769448
19091 381800 1397670.673714
19092 381820 1397771.578745
19093 381840 1397872.484542
19094 381860 1397973.391104
19095 381880 1398074.298432
19096 381900 1398175.206526
19097 381920 1398276.115385
19098 381940 1398377.025010
19099 381960 1398477.935400
19100 381980 1398578.846555
19101 382000 1398679.758476
19102 382020 1398780.671161
19103 382040 1398881.584613
19104 382060 1398982.498829
19105 382080 1399083.413810
19106 382100 1399184.329557
19107 382120 1399285.246068
19108 382140 1399386.163345
19109 382160 1399487.081386
19110 382180 1399588.000193
19111 382200 1399688.919764
19112 382220 1399789.840100
19113 382240 1399890.761201
19114 382260 1399991.683066
19115 382280 1400092.605696
19116 382300 1400193.529091
19117 382320 1400294.453250
19118 382340 1400395.378174
19119 382360 1400496.303862
19120 382380 1400597.230315
19121 382400 1400698.157532
19122 382420 1400799.085513
19123 382440 1400900.014259
19124 382460 1401000.943768
19125 382480 1401101.874042
19126 382500 1401202.805081
19127 382520 1401303.736883
19128 382540 1401404.669449
19129 382560 1401505.602780
19130 382580 1401606.536874
19131 382600 1401707.471732
19132 382620 1401808.407354
19133 382640 1401909.343740
19134 382660 1402010.280890
19135 382680 1402111.218803
19136 382700 1402212.157480
19137 382720 1402313.096921
19138 382740 1402414.037125
19139 382760 1402514.978092
19140 382780 1402615.919824
19141 382800 1402716.862318
19142 382820 1402817.805576
19143 382840 1402918.749598
19144 382860 1403019.694383
19145 382880 1403120.639931
19146 382900 1403221.586242
19147 382920 1403322.533316
19148 382940 1403423.481154
19149 382960 1403524.429754
19150 382980 1403625.379118
19151 383000 1403726.329244
19152 383020 1403827.280134
19153 383040 1403928.231786
19154 383060 1404029.184201
19155 383080 1404130.137379
19156 383100 1404231.091320
19157 383120 1404332.046023
19158 383140 1404433.001489
19159 383160 1404533.957718
19160 383180 1404634.914709
19161 383200 1404735.872463
19162 383220 1404836.830979
19163 383240 1404937.790257
19164 383260 1405038.750298
19165 383280 1405139.711101
19166 383300 1405240.672667
19167 383320 1405341.634995
19168 383340 1405442.598085
19169 383360 1405543.561937
19170 383380 1405644.526551
19171 383400 1405745.491927
19172 383420 1405846.458065
19173 383440 1405947.424966
19174 383460 1406048.392628
19175 383480 1406149.361052
19176 383500 1406250.330237
19177 383520 1406351.300185
19178 383540 1406452.270894
19179 383560 1406553.242365
19180 383580 1406654.214597
19181 383600 1406755.187591
19182 383620 1406856.161347
19183 383640 1406957.135864
19184 383660 1407058.111143
19185 383680 1407159.087183
19186 383700 1407260.063984
19187 383720 1407361.041547
19188 383740 1407462.019870
19189 383760 1407562.998955
19190 383780 1407663.978802
19191 383800 1407764.959409
19192 383820 1407865.940777
19193 383840 1407966.922907
19194 383860 1408067.905797
19195 383880 1408168.889448
19196 383900 1408269.873861
19197 383920 1408370.859034
19198 383940 1408471.844968
19199 383960 1408572.831662
19200 383980 1408673.819117
19201 384000 1408774.807333
19202 384020 1408875.796310
19203 384040 1408976.786047
19204 384060 1409077.776544
19205 384080 1409178.767803
19206 384100 1409279.759821
19207 384120 1409380.752600
19208 384140 1409481.746139
19209 384160 1409582.740439
19210 384180 1409683.735498
19211 384200 1409784.731318
19212 384220 1409885.727898
19213 384240 1409986.725238
19214 384260 1410087.723338
19215 384280 1410188.722199
19216 384300 1410289.721819
19217 384320 1410390.722199
19218 384340 1410491.723339
19219 384360 1410592.725238
19220 384380 1410693.727898
19221 384400 1410794.731317
19222 384420 1410895.735496
19223 384440 1410996.740435
19224 384460 1411097.746133
19225 384480 1411198.752590
19226 384500 1411299.759808
19227 384520 1411400.767784
19228 384540 1411501.776520
19229 384560 1411602.786016
19230 384580 1411703.796270
19231 384600 1411804.807284
19232 384620 1411905.819057
19233 384640 1412006.831590
19234 384660 1412107.844881
19235 384680 1412208.858932
19236 384700 1412309.873741
19237 384720 1412410.889310
19238 384740 1412511.905637
19239 384760 1412612.922724
19240 384780 1412713.940569
19241 384800 1412814.959173
19242 384820 1412915.978536
19243 384840 1413016.998657
19244 384860 1413118.019537
19245 384880 1413219.041176
19246 384900 1413320.063574
19247 384920 1413421.086730
19248 384940 1413522.110644
19249 384960 1413623.135317
19250 384980 1413724.160748
19251 385000 1413825.186937
19252 385020 1413926.213885
19253 385040 1414027.241591
19254 385060 1414128.270056
19255 385080 1414229.299278
19256 385100 1414330.329259
19257 385120 1414431.359997
19258 385140 1414532.391494
19259 385160 1414633.423749
19260 385180 1414734.456761
19261 385200 1414835.490532
19262 385220 1414936.525060
19263 385240 1415037.560346
19264 385260 1415138.596390
19265 385280 1415239.633191
19266 385300 1415340.670750
19267 385320 1415441.709067
19268 385340 1415542.748141
19269 385360 1415643.787973
19270 385380 1415744.828563
19271 385400 1415845.869909
19272 385420 1415946.912013
19273 385440 1416047.954875
19274 385460 1416148.998494
19275 385480 1416250.042870
19276 385500 1416351.088003
19277 385520 1416452.133893
19278 385540 1416553.180540
19279 385560 1416654.227945
19280 385580 1416755.276106
19281 385600 1416856.325025
19282 385620 1416957.374700
19283 385640 1417058.425132
19284 385660 1417159.476321
19285 385680 1417260.528267
19286 385700 1417361.580970
19287 385720 1417462.634429
19288 385740 1417563.688645
19289 385760 1417664.743617
19290 385780 1417765.799346
19291 385800 1417866.855832
19292 385820 1417967.913074
19293 385840 1418068.971072
19294 385860 1418170.029827
19295 385880 1418271.089338
19296 385900 1418372.149605
19297 385920 1418473.210629
19298 385940 1418574.272409
19299 385960 1418675.334945
19300 385980 1418776.398237
19301 386000 1418877.462285
19302 386020 1418978.527089
19303 386040 1419079.592649
19304 386060 1419180.658965
19305 386080 1419281.726037
19306 386100 1419382.793864
19307 386120 1419483.862448
19308 386140 1419584.931787
19309 386160 1419686.001881
19310 386180 1419787.072732
19311 386200 1419888.144338
19312 386220 1419989.216699
19313 386240 1420090.289816
19314 386260 1420191.363689
19315 386280 1420292.438317
19316 386300 1420393.513700
19317 386320 1420494.589839
19318 386340 1420595.666733
19319 386360 1420696.744382
19320 386380 1420797.822786
19321 386400 1420898.901945
19322 386420 1420999.981860
19323 386440 1421101.062529
19324 386460 1421202.143954
19325 386480 1421303.226133
19326 386500 1421404.309068
19327 386520 1421505.392757
19328 386540 1421606.477201
19329 386560 1421707.562400
19330 386580 1421808.648353
19331 386600 1421909.735061
19332 386620 1422010.822524
19333 386640 1422111.910742
19334 386660 1422212.999713
19335 386680 1422314.089440
19336 386700 1422415.179921
19337 386720 1422516.271156
19338 386740 1422617.363146
19339 386760 1422718.455890
19340 386780 1422819.549388
19341 386800 1422920.643640
19342 386820 1423021.738647
19343 386840 1423122.834408
19344 386860 1423223.930923
19345 386880 1423325.028191
19346 386900 1423426.126214
19347 386920 1423527.224991
19348 386940 1423628.324522
19349 386960 1423729.424806
19350 386980 1423830.525845
19351 387000 1423931.627637
19352 387020 1424032.730183
19353 387040 1424133.833482
19354 387060 1424234.937535
19355 387080 1424336.042342
19356 387100 1424437.147902
19357 387120 1424538.254216
19358 387140 1424639.361283
19359 387160 1424740.469104
19360 387180 1424841.577678
19361 387200 1424942.687005
19362 387220 1425043.797086
19363 387240 1425144.907919
19364 387260 1425246.019506
19365 387280 1425347.131846
19366 387300 1425448.244939
19367 387320 1425549.358786
19368 387340 1425650.473385
19369 387360 1425751.588737
19370 387380 1425852.704842
19371 387400 1425953.821700
19372 387420 1426054.939310
19373 387440 1426156.057674
19374 387460 1426257.176790
19375 387480 1426358.296659
19376 387500 1426459.417280
19377 387520 1426560.538654
19378 387540 1426661.660781
19379 387560 1426762.783660
19380 387580 1426863.907291
19381 387600 1426965.031675
19382 387620 1427066.156812
19383 387640 1427167.282700
19384 387660 1427268.409341
19385 387680 1427369.536734
19386 387700 1427470.664879
19387 387720 1427571.793777
19388 387740 1427672.923426
19389 387760 1427774.053828
19390 387780 1427875.184981
19391 387800 1427976.316886
19392 387820 1428077.449544
19393 387840 1428178.582953
19394 387860 1428279.717114
19395 387880 1428380.852027
19396 387900 1428481.987691
19397 387920 1428583.124107
19398 387940 1428684.261275
19399 387960 1428785.399195
19400 387980 1428886.537865
19401 388000 1428987.677288
19402 388020 1429088.817462
19403 388040 1429189.958387
19404 388060 1429291.100064
19405 388080 1429392.242492
19406 388100 1429493.385671
19407 388120 1429594.529601
19408 388140 1429695.674283
19409 388160 1429796.819715
19410 388180 1429897.965899
19411 388200 1429999.112834
19412 388220 1430100.260520
19413 388240 1430201.408957
19414 388260 1430302.558145
19415 388280 1430403.708083
19416 388300 1430504.858773
19417 388320 1430606.010213
19418 388340 1430707.162404
19419 388360 1430808.315345
19420 388380 1430909.469037
19421 388400 1431010.623480
19422 388420 1431111.778674
19423 388440 1431212.934617
19424 388460 1431314.091312
19425 388480 1431415.248756
19426 388500 1431516.406952
19427 388520 1431617.565897
19428 388540 1431718.725593
19429 388560 1431819.886039
19430 388580 1431921.047235
19431 388600 1432022.209181
19432 388620 1432123.371877
19433 388640 1432224.535324
19434 388660 1432325.699520
19435 388680 1432426.864466
19436 388700 1432528.030163
19437 388720 1432629.196609
19438 388740 1432730.363805
19439 388760 1432831.531750
19440 388780 1432932.700446
19441 388800 1433033.869891
19442 388820 1433135.040086
19443 388840 1433236.211030
19444 388860 1433337.382724
19445 388880 1433438.555168
19446 388900 1433539.728360
19447 388920 1433640.902303
19448 388940 1433742.076994
19449 388960 1433843.252436
19450 388980 1433944.428626
19451 389000 1434045.605565
19452 389020 1434146.783254
19453 389040 1434247.961692
19454 389060 1434349.140879
19455 389080 1434450.320815
19456 389100 1434551.501500
19457 389120 1434652.682934
19458 389140 1434753.865117
19459 389160 1434855.048049
19460 389180 1434956.231730
19461 389200 1435057.416159
19462 389220 1435158.601337
19463 389240 1435259.787264
19464 389260 1435360.973940
19465 389280 1435462.161364
19466 389300 1435563.349537
19467 389320 1435664.538458
19468 389340 1435765.728128
19469 389360 1435866.918546
19470 389380 1435968.109712
19471 389400 1436069.301627
19472 389420 1436170.494291
19473 389440 1436271.687702
19474 389460 1436372.881862
19475 389480 1436474.076769
19476 389500 1436575.272425
19477 389520 1436676.468829
19478 389540 1436777.665981
19479 389560 1436878.863881
19480 389580 1436980.062529
19481 389600 1437081.261925
19482 389620 1437182.462069
19483 389640 1437283.662960
19484 389660 1437384.864599
19485 389680 1437486.066986
19486 389700 1437587.270121
19487 389720 1437688.474003
19488 389740 1437789.678633
19489 389760 1437890.884010
19490 389780 1437992.090135
19491 389800 1438093.297007
19492 389820 1438194.504627
19493 389840 1438295.712994
19494 389860 1438396.922108
19495 389880 1438498.131970
19496 389900 1438599.342579
19497 389920 1438700.553935
19498 389940 1438801.766038
19499 389960 1438902.978888
19500 389980 1439004.192485
19501 390000 1439105.406829

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