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

page 1 of 40 · 500/page · 20000 rows next →
# nmargin_traced_6_40
2 20 -96368.582048
3 40 -103650.276505
4 60 -108242.177639
5 80 -111651.701759
6 100 -114384.425463
7 120 -116675.211544
8 140 -118653.250310
9 160 -120397.550011
10 180 -121960.105320
11 200 -123377.030942
12 220 -124674.473966
13 240 -125871.998451
14 260 -126984.640187
15 280 -128024.214552
16 300 -129000.182026
17 320 -129920.240007
18 340 -130790.738888
19 360 -131616.981678
20 380 -132403.444330
21 400 -133153.940751
22 420 -133871.748421
23 440 -134559.705420
24 460 -135220.286361
25 480 -135855.662515
26 500 -136467.749930
27 520 -137058.248331
28 540 -137628.672833
29 560 -138180.380022
30 580 -138714.589560
31 600 -139232.402210
32 620 -139734.814975
33 640 -140222.733885
34 660 -140696.984864
35 680 -141158.323011
36 700 -141607.440566
37 720 -142044.973782
38 740 -142471.508875
39 760 -142887.587200
40 780 -143293.709773
41 800 -143690.341227
42 820 -144077.913298
43 840 -144456.827900
44 860 -144827.459841
45 880 -145190.159242
46 900 -145545.253683
47 920 -145893.050129
48 940 -146233.836642
49 960 -146567.883922
50 980 -146895.446700
51 1000 -147216.764981
52 1020 -147532.065178
53 1040 -147841.561129
54 1060 -148145.455028
55 1080 -148443.938267
56 1100 -148737.192202
57 1120 -149025.388854
58 1140 -149308.691547
59 1160 -149587.255493
60 1180 -149861.228331
61 1200 -150130.750616
62 1220 -150395.956274
63 1240 -150656.973020
64 1260 -150913.922737
65 1280 -151166.921837
66 1300 -151416.081586
67 1320 -151661.508406
68 1340 -151903.304163
69 1360 -152141.566418
70 1380 -152376.388679
71 1400 -152607.860622
72 1420 -152836.068299
73 1440 -153061.094338
74 1460 -153283.018124
75 1480 -153501.915969
76 1500 -153717.861269
77 1520 -153930.924656
78 1540 -154141.174139
79 1560 -154348.675230
80 1580 -154553.491070
81 1600 -154755.682542
82 1620 -154955.308382
83 1640 -155152.425278
84 1660 -155347.087967
85 1680 -155539.349324
86 1700 -155729.260449
87 1720 -155916.870746
88 1740 -156102.227997
89 1760 -156285.378436
90 1780 -156466.366815
91 1800 -156645.236468
92 1820 -156822.029372
93 1840 -156996.786204
94 1860 -157169.546392
95 1880 -157340.348174
96 1900 -157509.228637
97 1920 -157676.223771
98 1940 -157841.368509
99 1960 -158004.696770
100 1980 -158166.241499
101 2000 -158326.034701
102 2020 -158484.107485
103 2040 -158640.490088
104 2060 -158795.211916
105 2080 -158948.301571
106 2100 -159099.786879
107 2120 -159249.694922
108 2140 -159398.052066
109 2160 -159544.883979
110 2180 -159690.215664
111 2200 -159834.071479
112 2220 -159976.475159
113 2240 -160117.449836
114 2260 -160257.018065
115 2280 -160395.201838
116 2300 -160532.022605
117 2320 -160667.501294
118 2340 -160801.658324
119 2360 -160934.513626
120 2380 -161066.086654
121 2400 -161196.396405
122 2420 -161325.461432
123 2440 -161453.299857
124 2460 -161579.929384
125 2480 -161705.367316
126 2500 -161829.630562
127 2520 -161952.735652
128 2540 -162074.698750
129 2560 -162195.535661
130 2580 -162315.261844
131 2600 -162433.892423
132 2620 -162551.442196
133 2640 -162667.925643
134 2660 -162783.356939
135 2680 -162897.749958
136 2700 -163011.118285
137 2720 -163123.475224
138 2740 -163234.833803
139 2760 -163345.206787
140 2780 -163454.606678
141 2800 -163563.045730
142 2820 -163670.535950
143 2840 -163777.089106
144 2860 -163882.716736
145 2880 -163987.430152
146 2900 -164091.240445
147 2920 -164194.158493
148 2940 -164296.194966
149 2960 -164397.360331
150 2980 -164497.664856
151 3000 -164597.118618
152 3020 -164695.731505
153 3040 -164793.513223
154 3060 -164890.473300
155 3080 -164986.621088
156 3100 -165081.965771
157 3120 -165176.516368
158 3140 -165270.281735
159 3160 -165363.270571
160 3180 -165455.491423
161 3200 -165546.952686
162 3220 -165637.662609
163 3240 -165727.629298
164 3260 -165816.860720
165 3280 -165905.364706
166 3300 -165993.148952
167 3320 -166080.221026
168 3340 -166166.588367
169 3360 -166252.258292
170 3380 -166337.237994
171 3400 -166421.534550
172 3420 -166505.154920
173 3440 -166588.105949
174 3460 -166670.394374
175 3480 -166752.026821
176 3500 -166833.009812
177 3520 -166913.349763
178 3540 -166993.052990
179 3560 -167072.125710
180 3580 -167150.574042
181 3600 -167228.404009
182 3620 -167305.621544
183 3640 -167382.232484
184 3660 -167458.242582
185 3680 -167533.657500
186 3700 -167608.482815
187 3720 -167682.724022
188 3740 -167756.386531
189 3760 -167829.475674
190 3780 -167901.996702
191 3800 -167973.954792
192 3820 -168045.355042
193 3840 -168116.202477
194 3860 -168186.502050
195 3880 -168256.258642
196 3900 -168325.477064
197 3920 -168394.162059
198 3940 -168462.318302
199 3960 -168529.950404
200 3980 -168597.062909
201 4000 -168663.660298
202 4020 -168729.746992
203 4040 -168795.327349
204 4060 -168860.405667
205 4080 -168924.986186
206 4100 -168989.073089
207 4120 -169052.670500
208 4140 -169115.782491
209 4160 -169178.413076
210 4180 -169240.566218
211 4200 -169302.245826
212 4220 -169363.455758
213 4240 -169424.199821
214 4260 -169484.481773
215 4280 -169544.305323
216 4300 -169603.674131
217 4320 -169662.591810
218 4340 -169721.061927
219 4360 -169779.088005
220 4380 -169836.673520
221 4400 -169893.821904
222 4420 -169950.536549
223 4440 -170006.820800
224 4460 -170062.677964
225 4480 -170118.111305
226 4500 -170173.124047
227 4520 -170227.719375
228 4540 -170281.900434
229 4560 -170335.670332
230 4580 -170389.032139
231 4600 -170441.988886
232 4620 -170494.543570
233 4640 -170546.699152
234 4660 -170598.458556
235 4680 -170649.824672
236 4700 -170700.800357
237 4720 -170751.388433
238 4740 -170801.591690
239 4760 -170851.412885
240 4780 -170900.854743
241 4800 -170949.919957
242 4820 -170998.611190
243 4840 -171046.931074
244 4860 -171094.882212
245 4880 -171142.467175
246 4900 -171189.688507
247 4920 -171236.548723
248 4940 -171283.050309
249 4960 -171329.195724
250 4980 -171374.987400
251 5000 -171420.427741
252 5020 -171465.519125
253 5040 -171510.263904
254 5060 -171554.664404
255 5080 -171598.722926
256 5100 -171642.441746
257 5120 -171685.823114
258 5140 -171728.869259
259 5160 -171771.582382
260 5180 -171813.964664
261 5200 -171856.018261
262 5220 -171897.745307
263 5240 -171939.147912
264 5260 -171980.228166
265 5280 -172020.988135
266 5300 -172061.429865
267 5320 -172101.555380
268 5340 -172141.366684
269 5360 -172180.865758
270 5380 -172220.054566
271 5400 -172258.935050
272 5420 -172297.509131
273 5440 -172335.778712
274 5460 -172373.745679
275 5480 -172411.411894
276 5500 -172448.779204
277 5520 -172485.849436
278 5540 -172522.624400
279 5560 -172559.105887
280 5580 -172595.295671
281 5600 -172631.195508
282 5620 -172666.807136
283 5640 -172702.132278
284 5660 -172737.172639
285 5680 -172771.929908
286 5700 -172806.405756
287 5720 -172840.601839
288 5740 -172874.519799
289 5760 -172908.161259
290 5780 -172941.527830
291 5800 -172974.621103
292 5820 -173007.442659
293 5840 -173039.994060
294 5860 -173072.276857
295 5880 -173104.292584
296 5900 -173136.042760
297 5920 -173167.528892
298 5940 -173198.752473
299 5960 -173229.714981
300 5980 -173260.417880
301 6000 -173290.862622
302 6020 -173321.050645
303 6040 -173350.983375
304 6060 -173380.662222
305 6080 -173410.088587
306 6100 -173439.263856
307 6120 -173468.189403
308 6140 -173496.866591
309 6160 -173525.296769
310 6180 -173553.481275
311 6200 -173581.421434
312 6220 -173609.118562
313 6240 -173636.573960
314 6260 -173663.788920
315 6280 -173690.764722
316 6300 -173717.502634
317 6320 -173744.003914
318 6340 -173770.269810
319 6360 -173796.301557
320 6380 -173822.100380
321 6400 -173847.667495
322 6420 -173873.004106
323 6440 -173898.111407
324 6460 -173922.990582
325 6480 -173947.642807
326 6500 -173972.069243
327 6520 -173996.271047
328 6540 -174020.249363
329 6560 -174044.005326
330 6580 -174067.540061
331 6600 -174090.854686
332 6620 -174113.950306
333 6640 -174136.828021
334 6660 -174159.488919
335 6680 -174181.934080
336 6700 -174204.164574
337 6720 -174226.181466
338 6740 -174247.985807
339 6760 -174269.578645
340 6780 -174290.961014
341 6800 -174312.133945
342 6820 -174333.098457
343 6840 -174353.855561
344 6860 -174374.406263
345 6880 -174394.751557
346 6900 -174414.892433
347 6920 -174434.829870
348 6940 -174454.564841
349 6960 -174474.098310
350 6980 -174493.431236
351 7000 -174512.564567
352 7020 -174531.499247
353 7040 -174550.236210
354 7060 -174568.776384
355 7080 -174587.120690
356 7100 -174605.270042
357 7120 -174623.225346
358 7140 -174640.987502
359 7160 -174658.557402
360 7180 -174675.935933
361 7200 -174693.123974
362 7220 -174710.122397
363 7240 -174726.932069
364 7260 -174743.553849
365 7280 -174759.988590
366 7300 -174776.237138
367 7320 -174792.300335
368 7340 -174808.179014
369 7360 -174823.874004
370 7380 -174839.386125
371 7400 -174854.716194
372 7420 -174869.865021
373 7440 -174884.833409
374 7460 -174899.622156
375 7480 -174914.232054
376 7500 -174928.663890
377 7520 -174942.918444
378 7540 -174956.996492
379 7560 -174970.898802
380 7580 -174984.626139
381 7600 -174998.179261
382 7620 -175011.558921
383 7640 -175024.765866
384 7660 -175037.800839
385 7680 -175050.664577
386 7700 -175063.357811
387 7720 -175075.881269
388 7740 -175088.235671
389 7760 -175100.421734
390 7780 -175112.440170
391 7800 -175124.291684
392 7820 -175135.976979
393 7840 -175147.496752
394 7860 -175158.851693
395 7880 -175170.042490
396 7900 -175181.069826
397 7920 -175191.934378
398 7940 -175202.636818
399 7960 -175213.177816
400 7980 -175223.558036
401 8000 -175233.778135
402 8020 -175243.838770
403 8040 -175253.740591
404 8060 -175263.484243
405 8080 -175273.070369
406 8100 -175282.499606
407 8120 -175291.772586
408 8140 -175300.889939
409 8160 -175309.852290
410 8180 -175318.660258
411 8200 -175327.314461
412 8220 -175335.815511
413 8240 -175344.164015
414 8260 -175352.360578
415 8280 -175360.405802
416 8300 -175368.300281
417 8320 -175376.044608
418 8340 -175383.639372
419 8360 -175391.085159
420 8380 -175398.382548
421 8400 -175405.532118
422 8420 -175412.534441
423 8440 -175419.390087
424 8460 -175426.099624
425 8480 -175432.663613
426 8500 -175439.082613
427 8520 -175445.357180
428 8540 -175451.487866
429 8560 -175457.475218
430 8580 -175463.319783
431 8600 -175469.022101
432 8620 -175474.582711
433 8640 -175480.002147
434 8660 -175485.280940
435 8680 -175490.419619
436 8700 -175495.418709
437 8720 -175500.278730
438 8740 -175505.000202
439 8760 -175509.583638
440 8780 -175514.029552
441 8800 -175518.338451
442 8820 -175522.510842
443 8840 -175526.547226
444 8860 -175530.448104
445 8880 -175534.213971
446 8900 -175537.845321
447 8920 -175541.342644
448 8940 -175544.706428
449 8960 -175547.937156
450 8980 -175551.035312
451 9000 -175554.001372
452 9020 -175556.835813
453 9040 -175559.539108
454 9060 -175562.111727
455 9080 -175564.554137
456 9100 -175566.866802
457 9120 -175569.050185
458 9140 -175571.104744
459 9160 -175573.030935
460 9180 -175574.829213
461 9200 -175576.500027
462 9220 -175578.043827
463 9240 -175579.461058
464 9260 -175580.752163
465 9280 -175581.917583
466 9300 -175582.957755
467 9320 -175583.873114
468 9340 -175584.664094
469 9360 -175585.331126
470 9380 -175585.874635
471 9400 -175586.295050
472 9420 -175586.592791
473 9440 -175586.768280
474 9460 -175586.821935
475 9480 -175586.754172
476 9500 -175586.565403
477 9520 -175586.256041
478 9540 -175585.826494
479 9560 -175585.277167
480 9580 -175584.608466
481 9600 -175583.820793
482 9620 -175582.914546
483 9640 -175581.890123
484 9660 -175580.747919
485 9680 -175579.488328
486 9700 -175578.111739
487 9720 -175576.618542
488 9740 -175575.009123
489 9760 -175573.283866
490 9780 -175571.443153
491 9800 -175569.487365
492 9820 -175567.416880
493 9840 -175565.232072
494 9860 -175562.933317
495 9880 -175560.520986
496 9900 -175557.995448
497 9920 -175555.357072
498 9940 -175552.606223
499 9960 -175549.743265
500 9980 -175546.768560
501 10000 -175543.682468

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