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 7 of 40 · 500/page · 20000 rows next →
# nmargin_traced_6_40
3002 60020 -54046.039892
3003 60040 -53978.690573
3004 60060 -53911.333456
3005 60080 -53843.968544
3006 60100 -53776.595842
3007 60120 -53709.215352
3008 60140 -53641.827078
3009 60160 -53574.431023
3010 60180 -53507.027192
3011 60200 -53439.615587
3012 60220 -53372.196213
3013 60240 -53304.769072
3014 60260 -53237.334168
3015 60280 -53169.891504
3016 60300 -53102.441085
3017 60320 -53034.982913
3018 60340 -52967.516993
3019 60360 -52900.043327
3020 60380 -52832.561919
3021 60400 -52765.072772
3022 60420 -52697.575891
3023 60440 -52630.071277
3024 60460 -52562.558936
3025 60480 -52495.038871
3026 60500 -52427.511084
3027 60520 -52359.975579
3028 60540 -52292.432361
3029 60560 -52224.881431
3030 60580 -52157.322794
3031 60600 -52089.756454
3032 60620 -52022.182413
3033 60640 -51954.600675
3034 60660 -51887.011243
3035 60680 -51819.414122
3036 60700 -51751.809314
3037 60720 -51684.196822
3038 60740 -51616.576651
3039 60760 -51548.948804
3040 60780 -51481.313283
3041 60800 -51413.670094
3042 60820 -51346.019238
3043 60840 -51278.360719
3044 60860 -51210.694541
3045 60880 -51143.020708
3046 60900 -51075.339222
3047 60920 -51007.650087
3048 60940 -50939.953306
3049 60960 -50872.248883
3050 60980 -50804.536821
3051 61000 -50736.817124
3052 61020 -50669.089795
3053 61040 -50601.354838
3054 61060 -50533.612255
3055 61080 -50465.862050
3056 61100 -50398.104227
3057 61120 -50330.338788
3058 61140 -50262.565738
3059 61160 -50194.785080
3060 61180 -50126.996817
3061 61200 -50059.200952
3062 61220 -49991.397489
3063 61240 -49923.586431
3064 61260 -49855.767781
3065 61280 -49787.941544
3066 61300 -49720.107721
3067 61320 -49652.266317
3068 61340 -49584.417336
3069 61360 -49516.560779
3070 61380 -49448.696651
3071 61400 -49380.824955
3072 61420 -49312.945694
3073 61440 -49245.058872
3074 61460 -49177.164491
3075 61480 -49109.262556
3076 61500 -49041.353070
3077 61520 -48973.436036
3078 61540 -48905.511456
3079 61560 -48837.579336
3080 61580 -48769.639677
3081 61600 -48701.692484
3082 61620 -48633.737759
3083 61640 -48565.775506
3084 61660 -48497.805728
3085 61680 -48429.828429
3086 61700 -48361.843611
3087 61720 -48293.851278
3088 61740 -48225.851434
3089 61760 -48157.844081
3090 61780 -48089.829224
3091 61800 -48021.806864
3092 61820 -47953.777006
3093 61840 -47885.739653
3094 61860 -47817.694808
3095 61880 -47749.642475
3096 61900 -47681.582655
3097 61920 -47613.515354
3098 61940 -47545.440574
3099 61960 -47477.358319
3100 61980 -47409.268591
3101 62000 -47341.171394
3102 62020 -47273.066732
3103 62040 -47204.954607
3104 62060 -47136.835022
3105 62080 -47068.707982
3106 62100 -47000.573489
3107 62120 -46932.431547
3108 62140 -46864.282158
3109 62160 -46796.125326
3110 62180 -46727.961055
3111 62200 -46659.789347
3112 62220 -46591.610205
3113 62240 -46523.423634
3114 62260 -46455.229636
3115 62280 -46387.028214
3116 62300 -46318.819371
3117 62320 -46250.603112
3118 62340 -46182.379439
3119 62360 -46114.148355
3120 62380 -46045.909863
3121 62400 -45977.663967
3122 62420 -45909.410671
3123 62440 -45841.149976
3124 62460 -45772.881886
3125 62480 -45704.606405
3126 62500 -45636.323536
3127 62520 -45568.033282
3128 62540 -45499.735646
3129 62560 -45431.430631
3130 62580 -45363.118241
3131 62600 -45294.798478
3132 62620 -45226.471346
3133 62640 -45158.136849
3134 62660 -45089.794988
3135 62680 -45021.445768
3136 62700 -44953.089192
3137 62720 -44884.725262
3138 62740 -44816.353983
3139 62760 -44747.975356
3140 62780 -44679.589386
3141 62800 -44611.196075
3142 62820 -44542.795427
3143 62840 -44474.387444
3144 62860 -44405.972130
3145 62880 -44337.549489
3146 62900 -44269.119522
3147 62920 -44200.682234
3148 62940 -44132.237628
3149 62960 -44063.785706
3150 62980 -43995.326472
3151 63000 -43926.859929
3152 63020 -43858.386079
3153 63040 -43789.904927
3154 63060 -43721.416476
3155 63080 -43652.920728
3156 63100 -43584.417686
3157 63120 -43515.907354
3158 63140 -43447.389735
3159 63160 -43378.864832
3160 63180 -43310.332648
3161 63200 -43241.793186
3162 63220 -43173.246449
3163 63240 -43104.692441
3164 63260 -43036.131164
3165 63280 -42967.562622
3166 63300 -42898.986817
3167 63320 -42830.403754
3168 63340 -42761.813434
3169 63360 -42693.215861
3170 63380 -42624.611038
3171 63400 -42555.998969
3172 63420 -42487.379655
3173 63440 -42418.753101
3174 63460 -42350.119310
3175 63480 -42281.478284
3176 63500 -42212.830026
3177 63520 -42144.174541
3178 63540 -42075.511829
3179 63560 -42006.841896
3180 63580 -41938.164744
3181 63600 -41869.480375
3182 63620 -41800.788794
3183 63640 -41732.090002
3184 63660 -41663.384004
3185 63680 -41594.670802
3186 63700 -41525.950399
3187 63720 -41457.222799
3188 63740 -41388.488003
3189 63760 -41319.746017
3190 63780 -41250.996841
3191 63800 -41182.240480
3192 63820 -41113.476937
3193 63840 -41044.706214
3194 63860 -40975.928314
3195 63880 -40907.143242
3196 63900 -40838.350999
3197 63920 -40769.551588
3198 63940 -40700.745013
3199 63960 -40631.931277
3200 63980 -40563.110383
3201 64000 -40494.282334
3202 64020 -40425.447132
3203 64040 -40356.604781
3204 64060 -40287.755284
3205 64080 -40218.898644
3206 64100 -40150.034863
3207 64120 -40081.163946
3208 64140 -40012.285894
3209 64160 -39943.400711
3210 64180 -39874.508400
3211 64200 -39805.608963
3212 64220 -39736.702405
3213 64240 -39667.788727
3214 64260 -39598.867934
3215 64280 -39529.940026
3216 64300 -39461.005009
3217 64320 -39392.062885
3218 64340 -39323.113656
3219 64360 -39254.157326
3220 64380 -39185.193898
3221 64400 -39116.223374
3222 64420 -39047.245758
3223 64440 -38978.261052
3224 64460 -38909.269261
3225 64480 -38840.270385
3226 64500 -38771.264430
3227 64520 -38702.251396
3228 64540 -38633.231288
3229 64560 -38564.204109
3230 64580 -38495.169861
3231 64600 -38426.128547
3232 64620 -38357.080170
3233 64640 -38288.024733
3234 64660 -38218.962240
3235 64680 -38149.892693
3236 64700 -38080.816094
3237 64720 -38011.732448
3238 64740 -37942.641757
3239 64760 -37873.544023
3240 64780 -37804.439250
3241 64800 -37735.327441
3242 64820 -37666.208598
3243 64840 -37597.082725
3244 64860 -37527.949824
3245 64880 -37458.809899
3246 64900 -37389.662952
3247 64920 -37320.508986
3248 64940 -37251.348004
3249 64960 -37182.180010
3250 64980 -37113.005005
3251 65000 -37043.822993
3252 65020 -36974.633977
3253 65040 -36905.437959
3254 65060 -36836.234943
3255 65080 -36767.024932
3256 65100 -36697.807928
3257 65120 -36628.583934
3258 65140 -36559.352953
3259 65160 -36490.114988
3260 65180 -36420.870042
3261 65200 -36351.618118
3262 65220 -36282.359219
3263 65240 -36213.093347
3264 65260 -36143.820505
3265 65280 -36074.540697
3266 65300 -36005.253925
3267 65320 -35935.960193
3268 65340 -35866.659502
3269 65360 -35797.351856
3270 65380 -35728.037257
3271 65400 -35658.715709
3272 65420 -35589.387215
3273 65440 -35520.051776
3274 65460 -35450.709397
3275 65480 -35381.360080
3276 65500 -35312.003827
3277 65520 -35242.640643
3278 65540 -35173.270528
3279 65560 -35103.893488
3280 65580 -35034.509523
3281 65600 -34965.118637
3282 65620 -34895.720833
3283 65640 -34826.316114
3284 65660 -34756.904483
3285 65680 -34687.485942
3286 65700 -34618.060494
3287 65720 -34548.628142
3288 65740 -34479.188890
3289 65760 -34409.742738
3290 65780 -34340.289692
3291 65800 -34270.829752
3292 65820 -34201.362923
3293 65840 -34131.889207
3294 65860 -34062.408607
3295 65880 -33992.921125
3296 65900 -33923.426765
3297 65920 -33853.925529
3298 65940 -33784.417420
3299 65960 -33714.902441
3300 65980 -33645.380595
3301 66000 -33575.851884
3302 66020 -33506.316311
3303 66040 -33436.773879
3304 66060 -33367.224591
3305 66080 -33297.668450
3306 66100 -33228.105458
3307 66120 -33158.535619
3308 66140 -33088.958934
3309 66160 -33019.375408
3310 66180 -32949.785041
3311 66200 -32880.187839
3312 66220 -32810.583802
3313 66240 -32740.972934
3314 66260 -32671.355238
3315 66280 -32601.730716
3316 66300 -32532.099372
3317 66320 -32462.461207
3318 66340 -32392.816226
3319 66360 -32323.164430
3320 66380 -32253.505822
3321 66400 -32183.840405
3322 66420 -32114.168182
3323 66440 -32044.489155
3324 66460 -31974.803328
3325 66480 -31905.110703
3326 66500 -31835.411283
3327 66520 -31765.705070
3328 66540 -31695.992067
3329 66560 -31626.272278
3330 66580 -31556.545704
3331 66600 -31486.812349
3332 66620 -31417.072215
3333 66640 -31347.325305
3334 66660 -31277.571622
3335 66680 -31207.811168
3336 66700 -31138.043947
3337 66720 -31068.269960
3338 66740 -30998.489211
3339 66760 -30928.701703
3340 66780 -30858.907437
3341 66800 -30789.106418
3342 66820 -30719.298646
3343 66840 -30649.484127
3344 66860 -30579.662861
3345 66880 -30509.834851
3346 66900 -30440.000101
3347 66920 -30370.158614
3348 66940 -30300.310390
3349 66960 -30230.455435
3350 66980 -30160.593750
3351 67000 -30090.725337
3352 67020 -30020.850200
3353 67040 -29950.968342
3354 67060 -29881.079764
3355 67080 -29811.184470
3356 67100 -29741.282463
3357 67120 -29671.373744
3358 67140 -29601.458317
3359 67160 -29531.536185
3360 67180 -29461.607350
3361 67200 -29391.671814
3362 67220 -29321.729581
3363 67240 -29251.780653
3364 67260 -29181.825033
3365 67280 -29111.862724
3366 67300 -29041.893727
3367 67320 -28971.918047
3368 67340 -28901.935685
3369 67360 -28831.946644
3370 67380 -28761.950927
3371 67400 -28691.948536
3372 67420 -28621.939475
3373 67440 -28551.923745
3374 67460 -28481.901350
3375 67480 -28411.872292
3376 67500 -28341.836573
3377 67520 -28271.794197
3378 67540 -28201.745166
3379 67560 -28131.689483
3380 67580 -28061.627150
3381 67600 -27991.558170
3382 67620 -27921.482546
3383 67640 -27851.400280
3384 67660 -27781.311375
3385 67680 -27711.215833
3386 67700 -27641.113658
3387 67720 -27571.004851
3388 67740 -27500.889416
3389 67760 -27430.767355
3390 67780 -27360.638670
3391 67800 -27290.503365
3392 67820 -27220.361442
3393 67840 -27150.212903
3394 67860 -27080.057751
3395 67880 -27009.895990
3396 67900 -26939.727620
3397 67920 -26869.552646
3398 67940 -26799.371069
3399 67960 -26729.182892
3400 67980 -26658.988118
3401 68000 -26588.786750
3402 68020 -26518.578789
3403 68040 -26448.364240
3404 68060 -26378.143103
3405 68080 -26307.915382
3406 68100 -26237.681080
3407 68120 -26167.440199
3408 68140 -26097.192741
3409 68160 -26026.938710
3410 68180 -25956.678107
3411 68200 -25886.410935
3412 68220 -25816.137198
3413 68240 -25745.856897
3414 68260 -25675.570035
3415 68280 -25605.276615
3416 68300 -25534.976639
3417 68320 -25464.670110
3418 68340 -25394.357030
3419 68360 -25324.037402
3420 68380 -25253.711229
3421 68400 -25183.378513
3422 68420 -25113.039257
3423 68440 -25042.693463
3424 68460 -24972.341133
3425 68480 -24901.982271
3426 68500 -24831.616879
3427 68520 -24761.244960
3428 68540 -24690.866515
3429 68560 -24620.481548
3430 68580 -24550.090061
3431 68600 -24479.692057
3432 68620 -24409.287538
3433 68640 -24338.876507
3434 68660 -24268.458966
3435 68680 -24198.034918
3436 68700 -24127.604365
3437 68720 -24057.167311
3438 68740 -23986.723757
3439 68760 -23916.273705
3440 68780 -23845.817160
3441 68800 -23775.354122
3442 68820 -23704.884595
3443 68840 -23634.408581
3444 68860 -23563.926083
3445 68880 -23493.437103
3446 68900 -23422.941644
3447 68920 -23352.439707
3448 68940 -23281.931297
3449 68960 -23211.416415
3450 68980 -23140.895063
3451 69000 -23070.367245
3452 69020 -22999.832963
3453 69040 -22929.292219
3454 69060 -22858.745016
3455 69080 -22788.191356
3456 69100 -22717.631242
3457 69120 -22647.064676
3458 69140 -22576.491661
3459 69160 -22505.912199
3460 69180 -22435.326294
3461 69200 -22364.733946
3462 69220 -22294.135159
3463 69240 -22223.529936
3464 69260 -22152.918278
3465 69280 -22082.300189
3466 69300 -22011.675671
3467 69320 -21941.044725
3468 69340 -21870.407356
3469 69360 -21799.763564
3470 69380 -21729.113354
3471 69400 -21658.456726
3472 69420 -21587.793684
3473 69440 -21517.124230
3474 69460 -21446.448367
3475 69480 -21375.766097
3476 69500 -21305.077423
3477 69520 -21234.382346
3478 69540 -21163.680870
3479 69560 -21092.972997
3480 69580 -21022.258729
3481 69600 -20951.538069
3482 69620 -20880.811019
3483 69640 -20810.077582
3484 69660 -20739.337761
3485 69680 -20668.591557
3486 69700 -20597.838973
3487 69720 -20527.080012
3488 69740 -20456.314676
3489 69760 -20385.542967
3490 69780 -20314.764888
3491 69800 -20243.980442
3492 69820 -20173.189630
3493 69840 -20102.392456
3494 69860 -20031.588921
3495 69880 -19960.779028
3496 69900 -19889.962780
3497 69920 -19819.140179
3498 69940 -19748.311227
3499 69960 -19677.475928
3500 69980 -19606.634282
3501 70000 -19535.786293

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