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 5 of 40 · 500/page · 20000 rows next →
# nmargin_traced_6_40
2002 40020 -116744.430911
2003 40040 -116687.328181
2004 40060 -116630.211787
2005 40080 -116573.081739
2006 40100 -116515.938046
2007 40120 -116458.780719
2008 40140 -116401.609765
2009 40160 -116344.425196
2010 40180 -116287.227021
2011 40200 -116230.015249
2012 40220 -116172.789889
2013 40240 -116115.550953
2014 40260 -116058.298448
2015 40280 -116001.032384
2016 40300 -115943.752771
2017 40320 -115886.459619
2018 40340 -115829.152937
2019 40360 -115771.832734
2020 40380 -115714.499019
2021 40400 -115657.151803
2022 40420 -115599.791095
2023 40440 -115542.416903
2024 40460 -115485.029239
2025 40480 -115427.628109
2026 40500 -115370.213526
2027 40520 -115312.785497
2028 40540 -115255.344031
2029 40560 -115197.889139
2030 40580 -115140.420830
2031 40600 -115082.939113
2032 40620 -115025.443997
2033 40640 -114967.935492
2034 40660 -114910.413606
2035 40680 -114852.878350
2036 40700 -114795.329732
2037 40720 -114737.767762
2038 40740 -114680.192449
2039 40760 -114622.603802
2040 40780 -114565.001830
2041 40800 -114507.386543
2042 40820 -114449.757949
2043 40840 -114392.116059
2044 40860 -114334.460881
2045 40880 -114276.792424
2046 40900 -114219.110698
2047 40920 -114161.415711
2048 40940 -114103.707473
2049 40960 -114045.985992
2050 40980 -113988.251279
2051 41000 -113930.503342
2052 41020 -113872.742190
2053 41040 -113814.967832
2054 41060 -113757.180278
2055 41080 -113699.379535
2056 41100 -113641.565615
2057 41120 -113583.738524
2058 41140 -113525.898273
2059 41160 -113468.044871
2060 41180 -113410.178326
2061 41200 -113352.298647
2062 41220 -113294.405844
2063 41240 -113236.499925
2064 41260 -113178.580899
2065 41280 -113120.648776
2066 41300 -113062.703564
2067 41320 -113004.745272
2068 41340 -112946.773909
2069 41360 -112888.789484
2070 41380 -112830.792006
2071 41400 -112772.781483
2072 41420 -112714.757925
2073 41440 -112656.721341
2074 41460 -112598.671739
2075 41480 -112540.609128
2076 41500 -112482.533516
2077 41520 -112424.444914
2078 41540 -112366.343329
2079 41560 -112308.228771
2080 41580 -112250.101247
2081 41600 -112191.960768
2082 41620 -112133.807341
2083 41640 -112075.640975
2084 41660 -112017.461680
2085 41680 -111959.269463
2086 41700 -111901.064335
2087 41720 -111842.846302
2088 41740 -111784.615374
2089 41760 -111726.371561
2090 41780 -111668.114869
2091 41800 -111609.845309
2092 41820 -111551.562888
2093 41840 -111493.267615
2094 41860 -111434.959500
2095 41880 -111376.638550
2096 41900 -111318.304774
2097 41920 -111259.958182
2098 41940 -111201.598780
2099 41960 -111143.226579
2100 41980 -111084.841586
2101 42000 -111026.443810
2102 42020 -110968.033260
2103 42040 -110909.609944
2104 42060 -110851.173871
2105 42080 -110792.725050
2106 42100 -110734.263488
2107 42120 -110675.789194
2108 42140 -110617.302177
2109 42160 -110558.802446
2110 42180 -110500.290008
2111 42200 -110441.764872
2112 42220 -110383.227047
2113 42240 -110324.676542
2114 42260 -110266.113363
2115 42280 -110207.537521
2116 42300 -110148.949023
2117 42320 -110090.347878
2118 42340 -110031.734094
2119 42360 -109973.107680
2120 42380 -109914.468643
2121 42400 -109855.816993
2122 42420 -109797.152738
2123 42440 -109738.475885
2124 42460 -109679.786444
2125 42480 -109621.084423
2126 42500 -109562.369829
2127 42520 -109503.642672
2128 42540 -109444.902959
2129 42560 -109386.150699
2130 42580 -109327.385900
2131 42600 -109268.608571
2132 42620 -109209.818719
2133 42640 -109151.016353
2134 42660 -109092.201482
2135 42680 -109033.374112
2136 42700 -108974.534253
2137 42720 -108915.681913
2138 42740 -108856.817100
2139 42760 -108797.939822
2140 42780 -108739.050088
2141 42800 -108680.147905
2142 42820 -108621.233281
2143 42840 -108562.306226
2144 42860 -108503.366746
2145 42880 -108444.414850
2146 42900 -108385.450547
2147 42920 -108326.473844
2148 42940 -108267.484749
2149 42960 -108208.483271
2150 42980 -108149.469418
2151 43000 -108090.443197
2152 43020 -108031.404617
2153 43040 -107972.353686
2154 43060 -107913.290411
2155 43080 -107854.214801
2156 43100 -107795.126865
2157 43120 -107736.026609
2158 43140 -107676.914042
2159 43160 -107617.789172
2160 43180 -107558.652007
2161 43200 -107499.502555
2162 43220 -107440.340824
2163 43240 -107381.166821
2164 43260 -107321.980556
2165 43280 -107262.782035
2166 43300 -107203.571267
2167 43320 -107144.348259
2168 43340 -107085.113020
2169 43360 -107025.865557
2170 43380 -106966.605879
2171 43400 -106907.333993
2172 43420 -106848.049907
2173 43440 -106788.753628
2174 43460 -106729.445166
2175 43480 -106670.124527
2176 43500 -106610.791720
2177 43520 -106551.446752
2178 43540 -106492.089632
2179 43560 -106432.720366
2180 43580 -106373.338963
2181 43600 -106313.945431
2182 43620 -106254.539777
2183 43640 -106195.122010
2184 43660 -106135.692136
2185 43680 -106076.250164
2186 43700 -106016.796101
2187 43720 -105957.329956
2188 43740 -105897.851735
2189 43760 -105838.361448
2190 43780 -105778.859100
2191 43800 -105719.344701
2192 43820 -105659.818257
2193 43840 -105600.279777
2194 43860 -105540.729269
2195 43880 -105481.166739
2196 43900 -105421.592195
2197 43920 -105362.005646
2198 43940 -105302.407099
2199 43960 -105242.796561
2200 43980 -105183.174040
2201 44000 -105123.539544
2202 44020 -105063.893080
2203 44040 -105004.234656
2204 44060 -104944.564280
2205 44080 -104884.881958
2206 44100 -104825.187700
2207 44120 -104765.481512
2208 44140 -104705.763401
2209 44160 -104646.033376
2210 44180 -104586.291444
2211 44200 -104526.537613
2212 44220 -104466.771889
2213 44240 -104406.994281
2214 44260 -104347.204796
2215 44280 -104287.403442
2216 44300 -104227.590226
2217 44320 -104167.765155
2218 44340 -104107.928237
2219 44360 -104048.079479
2220 44380 -103988.218890
2221 44400 -103928.346476
2222 44420 -103868.462245
2223 44440 -103808.566204
2224 44460 -103748.658360
2225 44480 -103688.738722
2226 44500 -103628.807297
2227 44520 -103568.864091
2228 44540 -103508.909113
2229 44560 -103448.942369
2230 44580 -103388.963867
2231 44600 -103328.973615
2232 44620 -103268.971620
2233 44640 -103208.957889
2234 44660 -103148.932429
2235 44680 -103088.895248
2236 44700 -103028.846354
2237 44720 -102968.785753
2238 44740 -102908.713452
2239 44760 -102848.629460
2240 44780 -102788.533784
2241 44800 -102728.426430
2242 44820 -102668.307405
2243 44840 -102608.176719
2244 44860 -102548.034376
2245 44880 -102487.880386
2246 44900 -102427.714754
2247 44920 -102367.537489
2248 44940 -102307.348597
2249 44960 -102247.148086
2250 44980 -102186.935963
2251 45000 -102126.712235
2252 45020 -102066.476909
2253 45040 -102006.229993
2254 45060 -101945.971494
2255 45080 -101885.701418
2256 45100 -101825.419774
2257 45120 -101765.126568
2258 45140 -101704.821807
2259 45160 -101644.505498
2260 45180 -101584.177649
2261 45200 -101523.838267
2262 45220 -101463.487359
2263 45240 -101403.124932
2264 45260 -101342.750993
2265 45280 -101282.365549
2266 45300 -101221.968608
2267 45320 -101161.560176
2268 45340 -101101.140260
2269 45360 -101040.708868
2270 45380 -100980.266006
2271 45400 -100919.811682
2272 45420 -100859.345903
2273 45440 -100798.868675
2274 45460 -100738.380006
2275 45480 -100677.879903
2276 45500 -100617.368372
2277 45520 -100556.845422
2278 45540 -100496.311058
2279 45560 -100435.765288
2280 45580 -100375.208118
2281 45600 -100314.639556
2282 45620 -100254.059609
2283 45640 -100193.468284
2284 45660 -100132.865587
2285 45680 -100072.251525
2286 45700 -100011.626106
2287 45720 -99950.989336
2288 45740 -99890.341223
2289 45760 -99829.681773
2290 45780 -99769.010993
2291 45800 -99708.328890
2292 45820 -99647.635471
2293 45840 -99586.930742
2294 45860 -99526.214711
2295 45880 -99465.487385
2296 45900 -99404.748770
2297 45920 -99343.998874
2298 45940 -99283.237702
2299 45960 -99222.465263
2300 45980 -99161.681562
2301 46000 -99100.886606
2302 46020 -99040.080404
2303 46040 -98979.262960
2304 46060 -98918.434282
2305 46080 -98857.594377
2306 46100 -98796.743252
2307 46120 -98735.880913
2308 46140 -98675.007367
2309 46160 -98614.122621
2310 46180 -98553.226681
2311 46200 -98492.319555
2312 46220 -98431.401249
2313 46240 -98370.471770
2314 46260 -98309.531125
2315 46280 -98248.579320
2316 46300 -98187.616362
2317 46320 -98126.642257
2318 46340 -98065.657014
2319 46360 -98004.660637
2320 46380 -97943.653134
2321 46400 -97882.634511
2322 46420 -97821.604776
2323 46440 -97760.563934
2324 46460 -97699.511993
2325 46480 -97638.448959
2326 46500 -97577.374839
2327 46520 -97516.289640
2328 46540 -97455.193367
2329 46560 -97394.086028
2330 46580 -97332.967629
2331 46600 -97271.838177
2332 46620 -97210.697679
2333 46640 -97149.546140
2334 46660 -97088.383568
2335 46680 -97027.209970
2336 46700 -96966.025351
2337 46720 -96904.829719
2338 46740 -96843.623079
2339 46760 -96782.405439
2340 46780 -96721.176805
2341 46800 -96659.937184
2342 46820 -96598.686581
2343 46840 -96537.425004
2344 46860 -96476.152460
2345 46880 -96414.868953
2346 46900 -96353.574492
2347 46920 -96292.269083
2348 46940 -96230.952732
2349 46960 -96169.625445
2350 46980 -96108.287229
2351 47000 -96046.938091
2352 47020 -95985.578037
2353 47040 -95924.207073
2354 47060 -95862.825207
2355 47080 -95801.432443
2356 47100 -95740.028789
2357 47120 -95678.614252
2358 47140 -95617.188837
2359 47160 -95555.752551
2360 47180 -95494.305400
2361 47200 -95432.847391
2362 47220 -95371.378531
2363 47240 -95309.898825
2364 47260 -95248.408280
2365 47280 -95186.906902
2366 47300 -95125.394698
2367 47320 -95063.871675
2368 47340 -95002.337837
2369 47360 -94940.793193
2370 47380 -94879.237747
2371 47400 -94817.671507
2372 47420 -94756.094479
2373 47440 -94694.506668
2374 47460 -94632.908082
2375 47480 -94571.298727
2376 47500 -94509.678609
2377 47520 -94448.047734
2378 47540 -94386.406109
2379 47560 -94324.753739
2380 47580 -94263.090632
2381 47600 -94201.416793
2382 47620 -94139.732229
2383 47640 -94078.036945
2384 47660 -94016.330949
2385 47680 -93954.614246
2386 47700 -93892.886843
2387 47720 -93831.148746
2388 47740 -93769.399960
2389 47760 -93707.640493
2390 47780 -93645.870351
2391 47800 -93584.089539
2392 47820 -93522.298064
2393 47840 -93460.495932
2394 47860 -93398.683150
2395 47880 -93336.859723
2396 47900 -93275.025657
2397 47920 -93213.180959
2398 47940 -93151.325635
2399 47960 -93089.459692
2400 47980 -93027.583134
2401 48000 -92965.695969
2402 48020 -92903.798202
2403 48040 -92841.889840
2404 48060 -92779.970889
2405 48080 -92718.041354
2406 48100 -92656.101242
2407 48120 -92594.150560
2408 48140 -92532.189312
2409 48160 -92470.217506
2410 48180 -92408.235147
2411 48200 -92346.242242
2412 48220 -92284.238796
2413 48240 -92222.224815
2414 48260 -92160.200306
2415 48280 -92098.165275
2416 48300 -92036.119727
2417 48320 -91974.063669
2418 48340 -91911.997107
2419 48360 -91849.920046
2420 48380 -91787.832493
2421 48400 -91725.734454
2422 48420 -91663.625935
2423 48440 -91601.506941
2424 48460 -91539.377479
2425 48480 -91477.237555
2426 48500 -91415.087175
2427 48520 -91352.926345
2428 48540 -91290.755070
2429 48560 -91228.573357
2430 48580 -91166.381211
2431 48600 -91104.178639
2432 48620 -91041.965646
2433 48640 -90979.742239
2434 48660 -90917.508424
2435 48680 -90855.264205
2436 48700 -90793.009590
2437 48720 -90730.744584
2438 48740 -90668.469193
2439 48760 -90606.183423
2440 48780 -90543.887279
2441 48800 -90481.580769
2442 48820 -90419.263897
2443 48840 -90356.936669
2444 48860 -90294.599092
2445 48880 -90232.251171
2446 48900 -90169.892912
2447 48920 -90107.524321
2448 48940 -90045.145404
2449 48960 -89982.756167
2450 48980 -89920.356615
2451 49000 -89857.946754
2452 49020 -89795.526591
2453 49040 -89733.096130
2454 49060 -89670.655378
2455 49080 -89608.204341
2456 49100 -89545.743024
2457 49120 -89483.271433
2458 49140 -89420.789574
2459 49160 -89358.297453
2460 49180 -89295.795075
2461 49200 -89233.282447
2462 49220 -89170.759574
2463 49240 -89108.226461
2464 49260 -89045.683115
2465 49280 -88983.129542
2466 49300 -88920.565746
2467 49320 -88857.991734
2468 49340 -88795.407512
2469 49360 -88732.813085
2470 49380 -88670.208459
2471 49400 -88607.593640
2472 49420 -88544.968633
2473 49440 -88482.333444
2474 49460 -88419.688079
2475 49480 -88357.032543
2476 49500 -88294.366843
2477 49520 -88231.690983
2478 49540 -88169.004970
2479 49560 -88106.308809
2480 49580 -88043.602506
2481 49600 -87980.886067
2482 49620 -87918.159496
2483 49640 -87855.422801
2484 49660 -87792.675985
2485 49680 -87729.919056
2486 49700 -87667.152019
2487 49720 -87604.374879
2488 49740 -87541.587642
2489 49760 -87478.790313
2490 49780 -87415.982899
2491 49800 -87353.165404
2492 49820 -87290.337835
2493 49840 -87227.500197
2494 49860 -87164.652495
2495 49880 -87101.794736
2496 49900 -87038.926924
2497 49920 -86976.049065
2498 49940 -86913.161165
2499 49960 -86850.263230
2500 49980 -86787.355264
2501 50000 -86724.437274

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