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 35 of 40 · 500/page · 20000 rows next →
# nmargin_traced_6_40
17002 340020 1188627.618380
17003 340040 1188726.812348
17004 340060 1188826.007194
17005 340080 1188925.202916
17006 340100 1189024.399516
17007 340120 1189123.596994
17008 340140 1189222.795348
17009 340160 1189321.994579
17010 340180 1189421.194686
17011 340200 1189520.395671
17012 340220 1189619.597533
17013 340240 1189718.800271
17014 340260 1189818.003886
17015 340280 1189917.208377
17016 340300 1190016.413745
17017 340320 1190115.619989
17018 340340 1190214.827110
17019 340360 1190314.035107
17020 340380 1190413.243980
17021 340400 1190512.453730
17022 340420 1190611.664355
17023 340440 1190710.875857
17024 340460 1190810.088235
17025 340480 1190909.301489
17026 340500 1191008.515619
17027 340520 1191107.730624
17028 340540 1191206.946505
17029 340560 1191306.163263
17030 340580 1191405.380895
17031 340600 1191504.599404
17032 340620 1191603.818787
17033 340640 1191703.039047
17034 340660 1191802.260182
17035 340680 1191901.482192
17036 340700 1192000.705077
17037 340720 1192099.928838
17038 340740 1192199.153474
17039 340760 1192298.378985
17040 340780 1192397.605371
17041 340800 1192496.832632
17042 340820 1192596.060768
17043 340840 1192695.289779
17044 340860 1192794.519665
17045 340880 1192893.750425
17046 340900 1192992.982060
17047 340920 1193092.214570
17048 340940 1193191.447954
17049 340960 1193290.682213
17050 340980 1193389.917347
17051 341000 1193489.153354
17052 341020 1193588.390236
17053 341040 1193687.627993
17054 341060 1193786.866623
17055 341080 1193886.106128
17056 341100 1193985.346507
17057 341120 1194084.587760
17058 341140 1194183.829887
17059 341160 1194283.072887
17060 341180 1194382.316762
17061 341200 1194481.561510
17062 341220 1194580.807133
17063 341240 1194680.053628
17064 341260 1194779.300998
17065 341280 1194878.549241
17066 341300 1194977.798357
17067 341320 1195077.048347
17068 341340 1195176.299210
17069 341360 1195275.550947
17070 341380 1195374.803557
17071 341400 1195474.057040
17072 341420 1195573.311396
17073 341440 1195672.566625
17074 341460 1195771.822727
17075 341480 1195871.079702
17076 341500 1195970.337551
17077 341520 1196069.596271
17078 341540 1196168.855865
17079 341560 1196268.116331
17080 341580 1196367.377670
17081 341600 1196466.639882
17082 341620 1196565.902966
17083 341640 1196665.166923
17084 341660 1196764.431752
17085 341680 1196863.697453
17086 341700 1196962.964027
17087 341720 1197062.231473
17088 341740 1197161.499791
17089 341760 1197260.768981
17090 341780 1197360.039043
17091 341800 1197459.309977
17092 341820 1197558.581783
17093 341840 1197657.854461
17094 341860 1197757.128011
17095 341880 1197856.402432
17096 341900 1197955.677726
17097 341920 1198054.953890
17098 341940 1198154.230927
17099 341960 1198253.508835
17100 341980 1198352.787614
17101 342000 1198452.067265
17102 342020 1198551.347787
17103 342040 1198650.629180
17104 342060 1198749.911445
17105 342080 1198849.194580
17106 342100 1198948.478587
17107 342120 1199047.763465
17108 342140 1199147.049214
17109 342160 1199246.335833
17110 342180 1199345.623324
17111 342200 1199444.911685
17112 342220 1199544.200917
17113 342240 1199643.491020
17114 342260 1199742.781993
17115 342280 1199842.073837
17116 342300 1199941.366551
17117 342320 1200040.660136
17118 342340 1200139.954591
17119 342360 1200239.249917
17120 342380 1200338.546112
17121 342400 1200437.843178
17122 342420 1200537.141114
17123 342440 1200636.439920
17124 342460 1200735.739596
17125 342480 1200835.040142
17126 342500 1200934.341558
17127 342520 1201033.643844
17128 342540 1201132.946999
17129 342560 1201232.251024
17130 342580 1201331.555919
17131 342600 1201430.861684
17132 342620 1201530.168318
17133 342640 1201629.475821
17134 342660 1201728.784194
17135 342680 1201828.093436
17136 342700 1201927.403548
17137 342720 1202026.714528
17138 342740 1202126.026378
17139 342760 1202225.339097
17140 342780 1202324.652685
17141 342800 1202423.967142
17142 342820 1202523.282468
17143 342840 1202622.598663
17144 342860 1202721.915727
17145 342880 1202821.233659
17146 342900 1202920.552460
17147 342920 1203019.872130
17148 342940 1203119.192668
17149 342960 1203218.514075
17150 342980 1203317.836351
17151 343000 1203417.159494
17152 343020 1203516.483506
17153 343040 1203615.808386
17154 343060 1203715.134135
17155 343080 1203814.460752
17156 343100 1203913.788236
17157 343120 1204013.116589
17158 343140 1204112.445810
17159 343160 1204211.775899
17160 343180 1204311.106855
17161 343200 1204410.438680
17162 343220 1204509.771372
17163 343240 1204609.104931
17164 343260 1204708.439359
17165 343280 1204807.774654
17166 343300 1204907.110816
17167 343320 1205006.447846
17168 343340 1205105.785743
17169 343360 1205205.124508
17170 343380 1205304.464140
17171 343400 1205403.804639
17172 343420 1205503.146005
17173 343440 1205602.488238
17174 343460 1205701.831339
17175 343480 1205801.175306
17176 343500 1205900.520140
17177 343520 1205999.865841
17178 343540 1206099.212409
17179 343560 1206198.559844
17180 343580 1206297.908145
17181 343600 1206397.257313
17182 343620 1206496.607347
17183 343640 1206595.958248
17184 343660 1206695.310015
17185 343680 1206794.662649
17186 343700 1206894.016149
17187 343720 1206993.370515
17188 343740 1207092.725748
17189 343760 1207192.081846
17190 343780 1207291.438811
17191 343800 1207390.796642
17192 343820 1207490.155338
17193 343840 1207589.514901
17194 343860 1207688.875329
17195 343880 1207788.236623
17196 343900 1207887.598783
17197 343920 1207986.961809
17198 343940 1208086.325700
17199 343960 1208185.690457
17200 343980 1208285.056079
17201 344000 1208384.422566
17202 344020 1208483.789919
17203 344040 1208583.158138
17204 344060 1208682.527221
17205 344080 1208781.897170
17206 344100 1208881.267984
17207 344120 1208980.639662
17208 344140 1209080.012206
17209 344160 1209179.385615
17210 344180 1209278.759889
17211 344200 1209378.135027
17212 344220 1209477.511031
17213 344240 1209576.887899
17214 344260 1209676.265631
17215 344280 1209775.644229
17216 344300 1209875.023691
17217 344320 1209974.404017
17218 344340 1210073.785208
17219 344360 1210173.167263
17220 344380 1210272.550182
17221 344400 1210371.933966
17222 344420 1210471.318614
17223 344440 1210570.704126
17224 344460 1210670.090502
17225 344480 1210769.477741
17226 344500 1210868.865845
17227 344520 1210968.254813
17228 344540 1211067.644645
17229 344560 1211167.035340
17230 344580 1211266.426900
17231 344600 1211365.819322
17232 344620 1211465.212609
17233 344640 1211564.606759
17234 344660 1211664.001772
17235 344680 1211763.397649
17236 344700 1211862.794389
17237 344720 1211962.191992
17238 344740 1212061.590459
17239 344760 1212160.989789
17240 344780 1212260.389982
17241 344800 1212359.791038
17242 344820 1212459.192957
17243 344840 1212558.595739
17244 344860 1212657.999384
17245 344880 1212757.403892
17246 344900 1212856.809262
17247 344920 1212956.215495
17248 344940 1213055.622591
17249 344960 1213155.030549
17250 344980 1213254.439370
17251 345000 1213353.849054
17252 345020 1213453.259600
17253 345040 1213552.671008
17254 345060 1213652.083278
17255 345080 1213751.496411
17256 345100 1213850.910406
17257 345120 1213950.325263
17258 345140 1214049.740982
17259 345160 1214149.157563
17260 345180 1214248.575006
17261 345200 1214347.993311
17262 345220 1214447.412478
17263 345240 1214546.832506
17264 345260 1214646.253396
17265 345280 1214745.675148
17266 345300 1214845.097761
17267 345320 1214944.521236
17268 345340 1215043.945573
17269 345360 1215143.370771
17270 345380 1215242.796830
17271 345400 1215342.223750
17272 345420 1215441.651532
17273 345440 1215541.080175
17274 345460 1215640.509679
17275 345480 1215739.940044
17276 345500 1215839.371270
17277 345520 1215938.803357
17278 345540 1216038.236305
17279 345560 1216137.670114
17280 345580 1216237.104784
17281 345600 1216336.540314
17282 345620 1216435.976705
17283 345640 1216535.413956
17284 345660 1216634.852068
17285 345680 1216734.291041
17286 345700 1216833.730873
17287 345720 1216933.171567
17288 345740 1217032.613120
17289 345760 1217132.055534
17290 345780 1217231.498808
17291 345800 1217330.942942
17292 345820 1217430.387936
17293 345840 1217529.833791
17294 345860 1217629.280505
17295 345880 1217728.728079
17296 345900 1217828.176512
17297 345920 1217927.625806
17298 345940 1218027.075959
17299 345960 1218126.526972
17300 345980 1218225.978845
17301 346000 1218325.431577
17302 346020 1218424.885169
17303 346040 1218524.339620
17304 346060 1218623.794930
17305 346080 1218723.251100
17306 346100 1218822.708129
17307 346120 1218922.166017
17308 346140 1219021.624764
17309 346160 1219121.084370
17310 346180 1219220.544836
17311 346200 1219320.006160
17312 346220 1219419.468343
17313 346240 1219518.931385
17314 346260 1219618.395286
17315 346280 1219717.860046
17316 346300 1219817.325664
17317 346320 1219916.792141
17318 346340 1220016.259476
17319 346360 1220115.727670
17320 346380 1220215.196722
17321 346400 1220314.666633
17322 346420 1220414.137402
17323 346440 1220513.609029
17324 346460 1220613.081514
17325 346480 1220712.554858
17326 346500 1220812.029059
17327 346520 1220911.504119
17328 346540 1221010.980037
17329 346560 1221110.456812
17330 346580 1221209.934445
17331 346600 1221309.412937
17332 346620 1221408.892285
17333 346640 1221508.372492
17334 346660 1221607.853556
17335 346680 1221707.335478
17336 346700 1221806.818257
17337 346720 1221906.301894
17338 346740 1222005.786388
17339 346760 1222105.271739
17340 346780 1222204.757948
17341 346800 1222304.245013
17342 346820 1222403.732936
17343 346840 1222503.221716
17344 346860 1222602.711354
17345 346880 1222702.201848
17346 346900 1222801.693199
17347 346920 1222901.185406
17348 346940 1223000.678471
17349 346960 1223100.172392
17350 346980 1223199.667170
17351 347000 1223299.162805
17352 347020 1223398.659296
17353 347040 1223498.156644
17354 347060 1223597.654848
17355 347080 1223697.153909
17356 347100 1223796.653826
17357 347120 1223896.154599
17358 347140 1223995.656228
17359 347160 1224095.158714
17360 347180 1224194.662056
17361 347200 1224294.166253
17362 347220 1224393.671307
17363 347240 1224493.177217
17364 347260 1224592.683982
17365 347280 1224692.191604
17366 347300 1224791.700081
17367 347320 1224891.209413
17368 347340 1224990.719602
17369 347360 1225090.230646
17370 347380 1225189.742545
17371 347400 1225289.255300
17372 347420 1225388.768911
17373 347440 1225488.283376
17374 347460 1225587.798697
17375 347480 1225687.314874
17376 347500 1225786.831905
17377 347520 1225886.349792
17378 347540 1225985.868533
17379 347560 1226085.388130
17380 347580 1226184.908581
17381 347600 1226284.429888
17382 347620 1226383.952049
17383 347640 1226483.475065
17384 347660 1226582.998936
17385 347680 1226682.523661
17386 347700 1226782.049241
17387 347720 1226881.575676
17388 347740 1226981.102965
17389 347760 1227080.631108
17390 347780 1227180.160106
17391 347800 1227279.689958
17392 347820 1227379.220665
17393 347840 1227478.752225
17394 347860 1227578.284640
17395 347880 1227677.817909
17396 347900 1227777.352031
17397 347920 1227876.887008
17398 347940 1227976.422839
17399 347960 1228075.959523
17400 347980 1228175.497061
17401 348000 1228275.035453
17402 348020 1228374.574699
17403 348040 1228474.114798
17404 348060 1228573.655751
17405 348080 1228673.197558
17406 348100 1228772.740217
17407 348120 1228872.283731
17408 348140 1228971.828097
17409 348160 1229071.373317
17410 348180 1229170.919390
17411 348200 1229270.466316
17412 348220 1229370.014095
17413 348240 1229469.562727
17414 348260 1229569.112213
17415 348280 1229668.662551
17416 348300 1229768.213742
17417 348320 1229867.765786
17418 348340 1229967.318682
17419 348360 1230066.872431
17420 348380 1230166.427033
17421 348400 1230265.982488
17422 348420 1230365.538795
17423 348440 1230465.095954
17424 348460 1230564.653966
17425 348480 1230664.212830
17426 348500 1230763.772547
17427 348520 1230863.333116
17428 348540 1230962.894536
17429 348560 1231062.456809
17430 348580 1231162.019935
17431 348600 1231261.583912
17432 348620 1231361.148741
17433 348640 1231460.714422
17434 348660 1231560.280954
17435 348680 1231659.848339
17436 348700 1231759.416575
17437 348720 1231858.985663
17438 348740 1231958.555602
17439 348760 1232058.126393
17440 348780 1232157.698036
17441 348800 1232257.270530
17442 348820 1232356.843875
17443 348840 1232456.418072
17444 348860 1232555.993120
17445 348880 1232655.569019
17446 348900 1232755.145769
17447 348920 1232854.723370
17448 348940 1232954.301822
17449 348960 1233053.881126
17450 348980 1233153.461280
17451 349000 1233253.042285
17452 349020 1233352.624141
17453 349040 1233452.206847
17454 349060 1233551.790405
17455 349080 1233651.374812
17456 349100 1233750.960071
17457 349120 1233850.546180
17458 349140 1233950.133139
17459 349160 1234049.720949
17460 349180 1234149.309609
17461 349200 1234248.899120
17462 349220 1234348.489480
17463 349240 1234448.080691
17464 349260 1234547.672752
17465 349280 1234647.265663
17466 349300 1234746.859424
17467 349320 1234846.454035
17468 349340 1234946.049496
17469 349360 1235045.645806
17470 349380 1235145.242967
17471 349400 1235244.840977
17472 349420 1235344.439836
17473 349440 1235444.039546
17474 349460 1235543.640104
17475 349480 1235643.241513
17476 349500 1235742.843770
17477 349520 1235842.446878
17478 349540 1235942.050834
17479 349560 1236041.655640
17480 349580 1236141.261295
17481 349600 1236240.867799
17482 349620 1236340.475152
17483 349640 1236440.083354
17484 349660 1236539.692405
17485 349680 1236639.302305
17486 349700 1236738.913053
17487 349720 1236838.524651
17488 349740 1236938.137097
17489 349760 1237037.750392
17490 349780 1237137.364536
17491 349800 1237236.979528
17492 349820 1237336.595369
17493 349840 1237436.212058
17494 349860 1237535.829596
17495 349880 1237635.447982
17496 349900 1237735.067216
17497 349920 1237834.687298
17498 349940 1237934.308229
17499 349960 1238033.930007
17500 349980 1238133.552634
17501 350000 1238233.176109

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