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 33 of 40 · 500/page · 20000 rows next →
# nmargin_traced_6_40
16002 320020 1089883.220909
16003 320040 1089981.505804
16004 320060 1090079.791641
16005 320080 1090178.078421
16006 320100 1090276.366142
16007 320120 1090374.654806
16008 320140 1090472.944412
16009 320160 1090571.234960
16010 320180 1090669.526449
16011 320200 1090767.818881
16012 320220 1090866.112254
16013 320240 1090964.406569
16014 320260 1091062.701825
16015 320280 1091160.998023
16016 320300 1091259.295163
16017 320320 1091357.593244
16018 320340 1091455.892266
16019 320360 1091554.192230
16020 320380 1091652.493134
16021 320400 1091750.794980
16022 320420 1091849.097767
16023 320440 1091947.401495
16024 320460 1092045.706164
16025 320480 1092144.011774
16026 320500 1092242.318324
16027 320520 1092340.625815
16028 320540 1092438.934247
16029 320560 1092537.243620
16030 320580 1092635.553933
16031 320600 1092733.865186
16032 320620 1092832.177380
16033 320640 1092930.490514
16034 320660 1093028.804588
16035 320680 1093127.119603
16036 320700 1093225.435557
16037 320720 1093323.752452
16038 320740 1093422.070286
16039 320760 1093520.389060
16040 320780 1093618.708775
16041 320800 1093717.029429
16042 320820 1093815.351022
16043 320840 1093913.673555
16044 320860 1094011.997028
16045 320880 1094110.321440
16046 320900 1094208.646792
16047 320920 1094306.973083
16048 320940 1094405.300313
16049 320960 1094503.628482
16050 320980 1094601.957591
16051 321000 1094700.287639
16052 321020 1094798.618625
16053 321040 1094896.950551
16054 321060 1094995.283415
16055 321080 1095093.617218
16056 321100 1095191.951960
16057 321120 1095290.287640
16058 321140 1095388.624259
16059 321160 1095486.961817
16060 321180 1095585.300312
16061 321200 1095683.639747
16062 321220 1095781.980119
16063 321240 1095880.321430
16064 321260 1095978.663679
16065 321280 1096077.006866
16066 321300 1096175.350991
16067 321320 1096273.696054
16068 321340 1096372.042055
16069 321360 1096470.388993
16070 321380 1096568.736870
16071 321400 1096667.085684
16072 321420 1096765.435436
16073 321440 1096863.786125
16074 321460 1096962.137751
16075 321480 1097060.490315
16076 321500 1097158.843817
16077 321520 1097257.198255
16078 321540 1097355.553631
16079 321560 1097453.909944
16080 321580 1097552.267194
16081 321600 1097650.625381
16082 321620 1097748.984505
16083 321640 1097847.344566
16084 321660 1097945.705563
16085 321680 1098044.067497
16086 321700 1098142.430368
16087 321720 1098240.794176
16088 321740 1098339.158919
16089 321760 1098437.524600
16090 321780 1098535.891216
16091 321800 1098634.258769
16092 321820 1098732.627259
16093 321840 1098830.996684
16094 321860 1098929.367045
16095 321880 1099027.738343
16096 321900 1099126.110576
16097 321920 1099224.483745
16098 321940 1099322.857851
16099 321960 1099421.232891
16100 321980 1099519.608868
16101 322000 1099617.985780
16102 322020 1099716.363628
16103 322040 1099814.742411
16104 322060 1099913.122129
16105 322080 1100011.502783
16106 322100 1100109.884372
16107 322120 1100208.266896
16108 322140 1100306.650356
16109 322160 1100405.034750
16110 322180 1100503.420080
16111 322200 1100601.806344
16112 322220 1100700.193543
16113 322240 1100798.581677
16114 322260 1100896.970746
16115 322280 1100995.360749
16116 322300 1101093.751687
16117 322320 1101192.143560
16118 322340 1101290.536366
16119 322360 1101388.930108
16120 322380 1101487.324783
16121 322400 1101585.720393
16122 322420 1101684.116937
16123 322440 1101782.514415
16124 322460 1101880.912827
16125 322480 1101979.312173
16126 322500 1102077.712453
16127 322520 1102176.113666
16128 322540 1102274.515814
16129 322560 1102372.918895
16130 322580 1102471.322910
16131 322600 1102569.727858
16132 322620 1102668.133740
16133 322640 1102766.540555
16134 322660 1102864.948303
16135 322680 1102963.356985
16136 322700 1103061.766600
16137 322720 1103160.177148
16138 322740 1103258.588630
16139 322760 1103357.001044
16140 322780 1103455.414391
16141 322800 1103553.828671
16142 322820 1103652.243884
16143 322840 1103750.660029
16144 322860 1103849.077107
16145 322880 1103947.495118
16146 322900 1104045.914062
16147 322920 1104144.333937
16148 322940 1104242.754745
16149 322960 1104341.176486
16150 322980 1104439.599159
16151 323000 1104538.022763
16152 323020 1104636.447300
16153 323040 1104734.872769
16154 323060 1104833.299170
16155 323080 1104931.726503
16156 323100 1105030.154768
16157 323120 1105128.583965
16158 323140 1105227.014093
16159 323160 1105325.445153
16160 323180 1105423.877144
16161 323200 1105522.310067
16162 323220 1105620.743921
16163 323240 1105719.178707
16164 323260 1105817.614424
16165 323280 1105916.051072
16166 323300 1106014.488652
16167 323320 1106112.927162
16168 323340 1106211.366604
16169 323360 1106309.806976
16170 323380 1106408.248280
16171 323400 1106506.690514
16172 323420 1106605.133679
16173 323440 1106703.577774
16174 323460 1106802.022800
16175 323480 1106900.468757
16176 323500 1106998.915644
16177 323520 1107097.363462
16178 323540 1107195.812210
16179 323560 1107294.261888
16180 323580 1107392.712497
16181 323600 1107491.164035
16182 323620 1107589.616504
16183 323640 1107688.069903
16184 323660 1107786.524231
16185 323680 1107884.979490
16186 323700 1107983.435678
16187 323720 1108081.892796
16188 323740 1108180.350844
16189 323760 1108278.809821
16190 323780 1108377.269728
16191 323800 1108475.730564
16192 323820 1108574.192329
16193 323840 1108672.655024
16194 323860 1108771.118649
16195 323880 1108869.583202
16196 323900 1108968.048684
16197 323920 1109066.515096
16198 323940 1109164.982437
16199 323960 1109263.450706
16200 323980 1109361.919904
16201 324000 1109460.390031
16202 324020 1109558.861087
16203 324040 1109657.333072
16204 324060 1109755.805985
16205 324080 1109854.279826
16206 324100 1109952.754596
16207 324120 1110051.230294
16208 324140 1110149.706921
16209 324160 1110248.184476
16210 324180 1110346.662959
16211 324200 1110445.142370
16212 324220 1110543.622709
16213 324240 1110642.103977
16214 324260 1110740.586172
16215 324280 1110839.069294
16216 324300 1110937.553345
16217 324320 1111036.038324
16218 324340 1111134.524230
16219 324360 1111233.011063
16220 324380 1111331.498824
16221 324400 1111429.987513
16222 324420 1111528.477128
16223 324440 1111626.967672
16224 324460 1111725.459142
16225 324480 1111823.951539
16226 324500 1111922.444864
16227 324520 1112020.939116
16228 324540 1112119.434294
16229 324560 1112217.930400
16230 324580 1112316.427432
16231 324600 1112414.925391
16232 324620 1112513.424277
16233 324640 1112611.924089
16234 324660 1112710.424828
16235 324680 1112808.926493
16236 324700 1112907.429085
16237 324720 1113005.932603
16238 324740 1113104.437047
16239 324760 1113202.942418
16240 324780 1113301.448715
16241 324800 1113399.955938
16242 324820 1113498.464087
16243 324840 1113596.973161
16244 324860 1113695.483162
16245 324880 1113793.994088
16246 324900 1113892.505941
16247 324920 1113991.018719
16248 324940 1114089.532422
16249 324960 1114188.047051
16250 324980 1114286.562606
16251 325000 1114385.079085
16252 325020 1114483.596491
16253 325040 1114582.114821
16254 325060 1114680.634077
16255 325080 1114779.154258
16256 325100 1114877.675364
16257 325120 1114976.197395
16258 325140 1115074.720350
16259 325160 1115173.244231
16260 325180 1115271.769037
16261 325200 1115370.294767
16262 325220 1115468.821422
16263 325240 1115567.349001
16264 325260 1115665.877505
16265 325280 1115764.406934
16266 325300 1115862.937287
16267 325320 1115961.468564
16268 325340 1116060.000766
16269 325360 1116158.533891
16270 325380 1116257.067941
16271 325400 1116355.602915
16272 325420 1116454.138813
16273 325440 1116552.675635
16274 325460 1116651.213380
16275 325480 1116749.752050
16276 325500 1116848.291643
16277 325520 1116946.832160
16278 325540 1117045.373600
16279 325560 1117143.915964
16280 325580 1117242.459251
16281 325600 1117341.003462
16282 325620 1117439.548596
16283 325640 1117538.094654
16284 325660 1117636.641634
16285 325680 1117735.189538
16286 325700 1117833.738365
16287 325720 1117932.288114
16288 325740 1118030.838787
16289 325760 1118129.390382
16290 325780 1118227.942901
16291 325800 1118326.496342
16292 325820 1118425.050705
16293 325840 1118523.605991
16294 325860 1118622.162200
16295 325880 1118720.719331
16296 325900 1118819.277385
16297 325920 1118917.836361
16298 325940 1119016.396259
16299 325960 1119114.957079
16300 325980 1119213.518822
16301 326000 1119312.081486
16302 326020 1119410.645073
16303 326040 1119509.209581
16304 326060 1119607.775012
16305 326080 1119706.341364
16306 326100 1119804.908637
16307 326120 1119903.476833
16308 326140 1120002.045950
16309 326160 1120100.615988
16310 326180 1120199.186948
16311 326200 1120297.758830
16312 326220 1120396.331632
16313 326240 1120494.905356
16314 326260 1120593.480001
16315 326280 1120692.055567
16316 326300 1120790.632055
16317 326320 1120889.209463
16318 326340 1120987.787792
16319 326360 1121086.367042
16320 326380 1121184.947213
16321 326400 1121283.528304
16322 326420 1121382.110317
16323 326440 1121480.693249
16324 326460 1121579.277103
16325 326480 1121677.861876
16326 326500 1121776.447570
16327 326520 1121875.034185
16328 326540 1121973.621720
16329 326560 1122072.210174
16330 326580 1122170.799549
16331 326600 1122269.389844
16332 326620 1122367.981059
16333 326640 1122466.573194
16334 326660 1122565.166249
16335 326680 1122663.760224
16336 326700 1122762.355118
16337 326720 1122860.950932
16338 326740 1122959.547665
16339 326760 1123058.145318
16340 326780 1123156.743891
16341 326800 1123255.343383
16342 326820 1123353.943794
16343 326840 1123452.545124
16344 326860 1123551.147374
16345 326880 1123649.750543
16346 326900 1123748.354630
16347 326920 1123846.959637
16348 326940 1123945.565563
16349 326960 1124044.172407
16350 326980 1124142.780171
16351 327000 1124241.388853
16352 327020 1124339.998453
16353 327040 1124438.608973
16354 327060 1124537.220411
16355 327080 1124635.832767
16356 327100 1124734.446041
16357 327120 1124833.060234
16358 327140 1124931.675346
16359 327160 1125030.291375
16360 327180 1125128.908323
16361 327200 1125227.526188
16362 327220 1125326.144972
16363 327240 1125424.764673
16364 327260 1125523.385293
16365 327280 1125622.006830
16366 327300 1125720.629285
16367 327320 1125819.252658
16368 327340 1125917.876948
16369 327360 1126016.502155
16370 327380 1126115.128281
16371 327400 1126213.755323
16372 327420 1126312.383283
16373 327440 1126411.012160
16374 327460 1126509.641954
16375 327480 1126608.272666
16376 327500 1126706.904294
16377 327520 1126805.536840
16378 327540 1126904.170302
16379 327560 1127002.804682
16380 327580 1127101.439978
16381 327600 1127200.076191
16382 327620 1127298.713320
16383 327640 1127397.351367
16384 327660 1127495.990329
16385 327680 1127594.630208
16386 327700 1127693.271004
16387 327720 1127791.912716
16388 327740 1127890.555344
16389 327760 1127989.198888
16390 327780 1128087.843349
16391 327800 1128186.488725
16392 327820 1128285.135018
16393 327840 1128383.782226
16394 327860 1128482.430351
16395 327880 1128581.079391
16396 327900 1128679.729347
16397 327920 1128778.380219
16398 327940 1128877.032006
16399 327960 1128975.684709
16400 327980 1129074.338327
16401 328000 1129172.992861
16402 328020 1129271.648310
16403 328040 1129370.304674
16404 328060 1129468.961954
16405 328080 1129567.620148
16406 328100 1129666.279258
16407 328120 1129764.939283
16408 328140 1129863.600223
16409 328160 1129962.262077
16410 328180 1130060.924847
16411 328200 1130159.588531
16412 328220 1130258.253130
16413 328240 1130356.918643
16414 328260 1130455.585071
16415 328280 1130554.252414
16416 328300 1130652.920671
16417 328320 1130751.589842
16418 328340 1130850.259928
16419 328360 1130948.930928
16420 328380 1131047.602842
16421 328400 1131146.275670
16422 328420 1131244.949412
16423 328440 1131343.624068
16424 328460 1131442.299638
16425 328480 1131540.976122
16426 328500 1131639.653520
16427 328520 1131738.331831
16428 328540 1131837.011056
16429 328560 1131935.691195
16430 328580 1132034.372247
16431 328600 1132133.054212
16432 328620 1132231.737091
16433 328640 1132330.420883
16434 328660 1132429.105589
16435 328680 1132527.791207
16436 328700 1132626.477739
16437 328720 1132725.165184
16438 328740 1132823.853541
16439 328760 1132922.542812
16440 328780 1133021.232996
16441 328800 1133119.924092
16442 328820 1133218.616101
16443 328840 1133317.309023
16444 328860 1133416.002857
16445 328880 1133514.697604
16446 328900 1133613.393263
16447 328920 1133712.089835
16448 328940 1133810.787318
16449 328960 1133909.485715
16450 328980 1134008.185023
16451 329000 1134106.885244
16452 329020 1134205.586376
16453 329040 1134304.288421
16454 329060 1134402.991377
16455 329080 1134501.695246
16456 329100 1134600.400026
16457 329120 1134699.105718
16458 329140 1134797.812321
16459 329160 1134896.519837
16460 329180 1134995.228263
16461 329200 1135093.937602
16462 329220 1135192.647851
16463 329240 1135291.359012
16464 329260 1135390.071085
16465 329280 1135488.784068
16466 329300 1135587.497963
16467 329320 1135686.212768
16468 329340 1135784.928485
16469 329360 1135883.645113
16470 329380 1135982.362651
16471 329400 1136081.081101
16472 329420 1136179.800461
16473 329440 1136278.520732
16474 329460 1136377.241913
16475 329480 1136475.964005
16476 329500 1136574.687008
16477 329520 1136673.410921
16478 329540 1136772.135744
16479 329560 1136870.861478
16480 329580 1136969.588121
16481 329600 1137068.315676
16482 329620 1137167.044140
16483 329640 1137265.773514
16484 329660 1137364.503798
16485 329680 1137463.234992
16486 329700 1137561.967096
16487 329720 1137660.700110
16488 329740 1137759.434033
16489 329760 1137858.168866
16490 329780 1137956.904609
16491 329800 1138055.641261
16492 329820 1138154.378822
16493 329840 1138253.117293
16494 329860 1138351.856674
16495 329880 1138450.596963
16496 329900 1138549.338162
16497 329920 1138648.080270
16498 329940 1138746.823287
16499 329960 1138845.567213
16500 329980 1138944.312047
16501 330000 1139043.057791

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