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 27 of 40 · 500/page · 20000 rows next →
# nmargin_traced_6_40
13002 260020 799621.906718
13003 260040 799716.998947
13004 260060 799812.092384
13005 260080 799907.187027
13006 260100 800002.282876
13007 260120 800097.379932
13008 260140 800192.478194
13009 260160 800287.577662
13010 260180 800382.678336
13011 260200 800477.780216
13012 260220 800572.883302
13013 260240 800667.987593
13014 260260 800763.093090
13015 260280 800858.199793
13016 260300 800953.307701
13017 260320 801048.416814
13018 260340 801143.527132
13019 260360 801238.638655
13020 260380 801333.751383
13021 260400 801428.865316
13022 260420 801523.980453
13023 260440 801619.096795
13024 260460 801714.214342
13025 260480 801809.333093
13026 260500 801904.453048
13027 260520 801999.574207
13028 260540 802094.696570
13029 260560 802189.820137
13030 260580 802284.944908
13031 260600 802380.070882
13032 260620 802475.198060
13033 260640 802570.326442
13034 260660 802665.456027
13035 260680 802760.586815
13036 260700 802855.718806
13037 260720 802950.852000
13038 260740 803045.986398
13039 260760 803141.121997
13040 260780 803236.258800
13041 260800 803331.396805
13042 260820 803426.536013
13043 260840 803521.676423
13044 260860 803616.818035
13045 260880 803711.960849
13046 260900 803807.104866
13047 260920 803902.250084
13048 260940 803997.396504
13049 260960 804092.544125
13050 260980 804187.692949
13051 261000 804282.842973
13052 261020 804377.994200
13053 261040 804473.146627
13054 261060 804568.300255
13055 261080 804663.455085
13056 261100 804758.611115
13057 261120 804853.768346
13058 261140 804948.926778
13059 261160 805044.086411
13060 261180 805139.247244
13061 261200 805234.409277
13062 261220 805329.572510
13063 261240 805424.736944
13064 261260 805519.902578
13065 261280 805615.069411
13066 261300 805710.237445
13067 261320 805805.406678
13068 261340 805900.577110
13069 261360 805995.748742
13070 261380 806090.921574
13071 261400 806186.095605
13072 261420 806281.270835
13073 261440 806376.447264
13074 261460 806471.624891
13075 261480 806566.803718
13076 261500 806661.983744
13077 261520 806757.164968
13078 261540 806852.347390
13079 261560 806947.531011
13080 261580 807042.715830
13081 261600 807137.901847
13082 261620 807233.089063
13083 261640 807328.277476
13084 261660 807423.467087
13085 261680 807518.657896
13086 261700 807613.849902
13087 261720 807709.043106
13088 261740 807804.237507
13089 261760 807899.433106
13090 261780 807994.629902
13091 261800 808089.827894
13092 261820 808185.027084
13093 261840 808280.227471
13094 261860 808375.429054
13095 261880 808470.631834
13096 261900 808565.835810
13097 261920 808661.040983
13098 261940 808756.247352
13099 261960 808851.454918
13100 261980 808946.663679
13101 262000 809041.873636
13102 262020 809137.084790
13103 262040 809232.297138
13104 262060 809327.510683
13105 262080 809422.725423
13106 262100 809517.941359
13107 262120 809613.158489
13108 262140 809708.376815
13109 262160 809803.596337
13110 262180 809898.817053
13111 262200 809994.038964
13112 262220 810089.262069
13113 262240 810184.486370
13114 262260 810279.711865
13115 262280 810374.938554
13116 262300 810470.166438
13117 262320 810565.395515
13118 262340 810660.625787
13119 262360 810755.857253
13120 262380 810851.089913
13121 262400 810946.323767
13122 262420 811041.558814
13123 262440 811136.795055
13124 262460 811232.032489
13125 262480 811327.271117
13126 262500 811422.510938
13127 262520 811517.751952
13128 262540 811612.994159
13129 262560 811708.237559
13130 262580 811803.482152
13131 262600 811898.727937
13132 262620 811993.974915
13133 262640 812089.223085
13134 262660 812184.472448
13135 262680 812279.723003
13136 262700 812374.974751
13137 262720 812470.227690
13138 262740 812565.481821
13139 262760 812660.737144
13140 262780 812755.993659
13141 262800 812851.251365
13142 262820 812946.510263
13143 262840 813041.770352
13144 262860 813137.031632
13145 262880 813232.294104
13146 262900 813327.557767
13147 262920 813422.822620
13148 262940 813518.088665
13149 262960 813613.355900
13150 262980 813708.624326
13151 263000 813803.893942
13152 263020 813899.164749
13153 263040 813994.436746
13154 263060 814089.709933
13155 263080 814184.984310
13156 263100 814280.259877
13157 263120 814375.536634
13158 263140 814470.814581
13159 263160 814566.093718
13160 263180 814661.374044
13161 263200 814756.655559
13162 263220 814851.938264
13163 263240 814947.222158
13164 263260 815042.507241
13165 263280 815137.793513
13166 263300 815233.080974
13167 263320 815328.369624
13168 263340 815423.659462
13169 263360 815518.950489
13170 263380 815614.242705
13171 263400 815709.536109
13172 263420 815804.830701
13173 263440 815900.126481
13174 263460 815995.423449
13175 263480 816090.721605
13176 263500 816186.020949
13177 263520 816281.321481
13178 263540 816376.623200
13179 263560 816471.926106
13180 263580 816567.230200
13181 263600 816662.535482
13182 263620 816757.841950
13183 263640 816853.149606
13184 263660 816948.458448
13185 263680 817043.768477
13186 263700 817139.079694
13187 263720 817234.392096
13188 263740 817329.705685
13189 263760 817425.020461
13190 263780 817520.336423
13191 263800 817615.653571
13192 263820 817710.971905
13193 263840 817806.291425
13194 263860 817901.612131
13195 263880 817996.934022
13196 263900 818092.257100
13197 263920 818187.581363
13198 263940 818282.906811
13199 263960 818378.233445
13200 263980 818473.561263
13201 264000 818568.890267
13202 264020 818664.220456
13203 264040 818759.551830
13204 264060 818854.884389
13205 264080 818950.218132
13206 264100 819045.553060
13207 264120 819140.889172
13208 264140 819236.226469
13209 264160 819331.564950
13210 264180 819426.904615
13211 264200 819522.245464
13212 264220 819617.587497
13213 264240 819712.930714
13214 264260 819808.275115
13215 264280 819903.620699
13216 264300 819998.967467
13217 264320 820094.315418
13218 264340 820189.664552
13219 264360 820285.014870
13220 264380 820380.366370
13221 264400 820475.719054
13222 264420 820571.072920
13223 264440 820666.427970
13224 264460 820761.784201
13225 264480 820857.141616
13226 264500 820952.500213
13227 264520 821047.859992
13228 264540 821143.220953
13229 264560 821238.583096
13230 264580 821333.946422
13231 264600 821429.310929
13232 264620 821524.676618
13233 264640 821620.043489
13234 264660 821715.411541
13235 264680 821810.780775
13236 264700 821906.151190
13237 264720 822001.522786
13238 264740 822096.895564
13239 264760 822192.269523
13240 264780 822287.644662
13241 264800 822383.020982
13242 264820 822478.398483
13243 264840 822573.777165
13244 264860 822669.157027
13245 264880 822764.538070
13246 264900 822859.920292
13247 264920 822955.303695
13248 264940 823050.688279
13249 264960 823146.074042
13250 264980 823241.460984
13251 265000 823336.849107
13252 265020 823432.238409
13253 265040 823527.628891
13254 265060 823623.020552
13255 265080 823718.413393
13256 265100 823813.807413
13257 265120 823909.202612
13258 265140 824004.598990
13259 265160 824099.996546
13260 265180 824195.395282
13261 265200 824290.795196
13262 265220 824386.196289
13263 265240 824481.598561
13264 265260 824577.002010
13265 265280 824672.406638
13266 265300 824767.812444
13267 265320 824863.219429
13268 265340 824958.627591
13269 265360 825054.036931
13270 265380 825149.447448
13271 265400 825244.859144
13272 265420 825340.272016
13273 265440 825435.686067
13274 265460 825531.101294
13275 265480 825626.517699
13276 265500 825721.935281
13277 265520 825817.354040
13278 265540 825912.773975
13279 265560 826008.195088
13280 265580 826103.617377
13281 265600 826199.040842
13282 265620 826294.465485
13283 265640 826389.891303
13284 265660 826485.318298
13285 265680 826580.746469
13286 265700 826676.175816
13287 265720 826771.606338
13288 265740 826867.038037
13289 265760 826962.470911
13290 265780 827057.904961
13291 265800 827153.340187
13292 265820 827248.776588
13293 265840 827344.214164
13294 265860 827439.652915
13295 265880 827535.092842
13296 265900 827630.533943
13297 265920 827725.976219
13298 265940 827821.419670
13299 265960 827916.864296
13300 265980 828012.310096
13301 266000 828107.757071
13302 266020 828203.205220
13303 266040 828298.654543
13304 266060 828394.105040
13305 266080 828489.556711
13306 266100 828585.009557
13307 266120 828680.463576
13308 266140 828775.918768
13309 266160 828871.375135
13310 266180 828966.832675
13311 266200 829062.291388
13312 266220 829157.751274
13313 266240 829253.212334
13314 266260 829348.674567
13315 266280 829444.137972
13316 266300 829539.602551
13317 266320 829635.068302
13318 266340 829730.535226
13319 266360 829826.003323
13320 266380 829921.472592
13321 266400 830016.943033
13322 266420 830112.414646
13323 266440 830207.887432
13324 266460 830303.361390
13325 266480 830398.836519
13326 266500 830494.312821
13327 266520 830589.790294
13328 266540 830685.268938
13329 266560 830780.748754
13330 266580 830876.229742
13331 266600 830971.711901
13332 266620 831067.195231
13333 266640 831162.679732
13334 266660 831258.165403
13335 266680 831353.652246
13336 266700 831449.140260
13337 266720 831544.629444
13338 266740 831640.119799
13339 266760 831735.611324
13340 266780 831831.104019
13341 266800 831926.597885
13342 266820 832022.092921
13343 266840 832117.589127
13344 266860 832213.086503
13345 266880 832308.585048
13346 266900 832404.084764
13347 266920 832499.585648
13348 266940 832595.087703
13349 266960 832690.590927
13350 266980 832786.095320
13351 267000 832881.600882
13352 267020 832977.107613
13353 267040 833072.615513
13354 267060 833168.124582
13355 267080 833263.634820
13356 267100 833359.146227
13357 267120 833454.658802
13358 267140 833550.172545
13359 267160 833645.687457
13360 267180 833741.203537
13361 267200 833836.720785
13362 267220 833932.239202
13363 267240 834027.758786
13364 267260 834123.279538
13365 267280 834218.801457
13366 267300 834314.324545
13367 267320 834409.848799
13368 267340 834505.374222
13369 267360 834600.900811
13370 267380 834696.428568
13371 267400 834791.957491
13372 267420 834887.487582
13373 267440 834983.018840
13374 267460 835078.551264
13375 267480 835174.084855
13376 267500 835269.619612
13377 267520 835365.155536
13378 267540 835460.692627
13379 267560 835556.230883
13380 267580 835651.770306
13381 267600 835747.310895
13382 267620 835842.852650
13383 267640 835938.395570
13384 267660 836033.939656
13385 267680 836129.484908
13386 267700 836225.031326
13387 267720 836320.578908
13388 267740 836416.127657
13389 267760 836511.677570
13390 267780 836607.228648
13391 267800 836702.780892
13392 267820 836798.334300
13393 267840 836893.888873
13394 267860 836989.444611
13395 267880 837085.001513
13396 267900 837180.559580
13397 267920 837276.118811
13398 267940 837371.679207
13399 267960 837467.240766
13400 267980 837562.803490
13401 268000 837658.367377
13402 268020 837753.932429
13403 268040 837849.498644
13404 268060 837945.066023
13405 268080 838040.634565
13406 268100 838136.204271
13407 268120 838231.775140
13408 268140 838327.347173
13409 268160 838422.920368
13410 268180 838518.494727
13411 268200 838614.070248
13412 268220 838709.646932
13413 268240 838805.224779
13414 268260 838900.803789
13415 268280 838996.383961
13416 268300 839091.965295
13417 268320 839187.547792
13418 268340 839283.131451
13419 268360 839378.716272
13420 268380 839474.302255
13421 268400 839569.889400
13422 268420 839665.477707
13423 268440 839761.067175
13424 268460 839856.657805
13425 268480 839952.249596
13426 268500 840047.842549
13427 268520 840143.436663
13428 268540 840239.031938
13429 268560 840334.628374
13430 268580 840430.225971
13431 268600 840525.824729
13432 268620 840621.424648
13433 268640 840717.025727
13434 268660 840812.627967
13435 268680 840908.231367
13436 268700 841003.835928
13437 268720 841099.441649
13438 268740 841195.048530
13439 268760 841290.656570
13440 268780 841386.265771
13441 268800 841481.876132
13442 268820 841577.487652
13443 268840 841673.100332
13444 268860 841768.714172
13445 268880 841864.329171
13446 268900 841959.945329
13447 268920 842055.562646
13448 268940 842151.181123
13449 268960 842246.800758
13450 268980 842342.421552
13451 269000 842438.043505
13452 269020 842533.666617
13453 269040 842629.290887
13454 269060 842724.916316
13455 269080 842820.542903
13456 269100 842916.170649
13457 269120 843011.799552
13458 269140 843107.429614
13459 269160 843203.060833
13460 269180 843298.693211
13461 269200 843394.326746
13462 269220 843489.961439
13463 269240 843585.597289
13464 269260 843681.234297
13465 269280 843776.872462
13466 269300 843872.511784
13467 269320 843968.152264
13468 269340 844063.793900
13469 269360 844159.436694
13470 269380 844255.080644
13471 269400 844350.725751
13472 269420 844446.372014
13473 269440 844542.019434
13474 269460 844637.668011
13475 269480 844733.317744
13476 269500 844828.968633
13477 269520 844924.620678
13478 269540 845020.273879
13479 269560 845115.928236
13480 269580 845211.583749
13481 269600 845307.240417
13482 269620 845402.898241
13483 269640 845498.557221
13484 269660 845594.217356
13485 269680 845689.878646
13486 269700 845785.541091
13487 269720 845881.204692
13488 269740 845976.869447
13489 269760 846072.535357
13490 269780 846168.202422
13491 269800 846263.870642
13492 269820 846359.540016
13493 269840 846455.210545
13494 269860 846550.882228
13495 269880 846646.555066
13496 269900 846742.229057
13497 269920 846837.904203
13498 269940 846933.580502
13499 269960 847029.257956
13500 269980 847124.936563
13501 270000 847220.616323

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