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 36 of 40 · 500/page · 20000 rows next →
# nmargin_traced_6_40
17502 350020 1238332.800432
17503 350040 1238432.425602
17504 350060 1238532.051620
17505 350080 1238631.678487
17506 350100 1238731.306200
17507 350120 1238830.934762
17508 350140 1238930.564171
17509 350160 1239030.194428
17510 350180 1239129.825532
17511 350200 1239229.457483
17512 350220 1239329.090282
17513 350240 1239428.723928
17514 350260 1239528.358422
17515 350280 1239627.993762
17516 350300 1239727.629950
17517 350320 1239827.266985
17518 350340 1239926.904867
17519 350360 1240026.543596
17520 350380 1240126.183172
17521 350400 1240225.823594
17522 350420 1240325.464864
17523 350440 1240425.106980
17524 350460 1240524.749943
17525 350480 1240624.393752
17526 350500 1240724.038408
17527 350520 1240823.683911
17528 350540 1240923.330260
17529 350560 1241022.977456
17530 350580 1241122.625497
17531 350600 1241222.274385
17532 350620 1241321.924120
17533 350640 1241421.574700
17534 350660 1241521.226127
17535 350680 1241620.878400
17536 350700 1241720.531518
17537 350720 1241820.185483
17538 350740 1241919.840293
17539 350760 1242019.495950
17540 350780 1242119.152452
17541 350800 1242218.809800
17542 350820 1242318.467993
17543 350840 1242418.127032
17544 350860 1242517.786917
17545 350880 1242617.447647
17546 350900 1242717.109223
17547 350920 1242816.771644
17548 350940 1242916.434910
17549 350960 1243016.099022
17550 350980 1243115.763978
17551 351000 1243215.429780
17552 351020 1243315.096427
17553 351040 1243414.763919
17554 351060 1243514.432257
17555 351080 1243614.101439
17556 351100 1243713.771465
17557 351120 1243813.442337
17558 351140 1243913.114054
17559 351160 1244012.786615
17560 351180 1244112.460020
17561 351200 1244212.134271
17562 351220 1244311.809366
17563 351240 1244411.485305
17564 351260 1244511.162089
17565 351280 1244610.839717
17566 351300 1244710.518190
17567 351320 1244810.197506
17568 351340 1244909.877667
17569 351360 1245009.558672
17570 351380 1245109.240521
17571 351400 1245208.923215
17572 351420 1245308.606752
17573 351440 1245408.291133
17574 351460 1245507.976358
17575 351480 1245607.662426
17576 351500 1245707.349339
17577 351520 1245807.037095
17578 351540 1245906.725695
17579 351560 1246006.415138
17580 351580 1246106.105425
17581 351600 1246205.796555
17582 351620 1246305.488529
17583 351640 1246405.181346
17584 351660 1246504.875006
17585 351680 1246604.569510
17586 351700 1246704.264856
17587 351720 1246803.961046
17588 351740 1246903.658079
17589 351760 1247003.355955
17590 351780 1247103.054674
17591 351800 1247202.754236
17592 351820 1247302.454640
17593 351840 1247402.155888
17594 351860 1247501.857978
17595 351880 1247601.560911
17596 351900 1247701.264686
17597 351920 1247800.969304
17598 351940 1247900.674764
17599 351960 1248000.381067
17600 351980 1248100.088213
17601 352000 1248199.796200
17602 352020 1248299.505030
17603 352040 1248399.214702
17604 352060 1248498.925217
17605 352080 1248598.636573
17606 352100 1248698.348771
17607 352120 1248798.061812
17608 352140 1248897.775694
17609 352160 1248997.490419
17610 352180 1249097.205985
17611 352200 1249196.922393
17612 352220 1249296.639642
17613 352240 1249396.357733
17614 352260 1249496.076666
17615 352280 1249595.796441
17616 352300 1249695.517056
17617 352320 1249795.238514
17618 352340 1249894.960812
17619 352360 1249994.683952
17620 352380 1250094.407934
17621 352400 1250194.132756
17622 352420 1250293.858420
17623 352440 1250393.584925
17624 352460 1250493.312270
17625 352480 1250593.040457
17626 352500 1250692.769485
17627 352520 1250792.499353
17628 352540 1250892.230063
17629 352560 1250991.961613
17630 352580 1251091.694004
17631 352600 1251191.427235
17632 352620 1251291.161307
17633 352640 1251390.896220
17634 352660 1251490.631973
17635 352680 1251590.368566
17636 352700 1251690.106000
17637 352720 1251789.844275
17638 352740 1251889.583389
17639 352760 1251989.323344
17640 352780 1252089.064138
17641 352800 1252188.805773
17642 352820 1252288.548248
17643 352840 1252388.291563
17644 352860 1252488.035718
17645 352880 1252587.780713
17646 352900 1252687.526547
17647 352920 1252787.273221
17648 352940 1252887.020735
17649 352960 1252986.769089
17650 352980 1253086.518282
17651 353000 1253186.268315
17652 353020 1253286.019187
17653 353040 1253385.770898
17654 353060 1253485.523449
17655 353080 1253585.276840
17656 353100 1253685.031069
17657 353120 1253784.786138
17658 353140 1253884.542045
17659 353160 1253984.298792
17660 353180 1254084.056378
17661 353200 1254183.814803
17662 353220 1254283.574067
17663 353240 1254383.334170
17664 353260 1254483.095111
17665 353280 1254582.856891
17666 353300 1254682.619510
17667 353320 1254782.382968
17668 353340 1254882.147264
17669 353360 1254981.912399
17670 353380 1255081.678372
17671 353400 1255181.445183
17672 353420 1255281.212833
17673 353440 1255380.981321
17674 353460 1255480.750648
17675 353480 1255580.520812
17676 353500 1255680.291815
17677 353520 1255780.063656
17678 353540 1255879.836335
17679 353560 1255979.609852
17680 353580 1256079.384206
17681 353600 1256179.159399
17682 353620 1256278.935429
17683 353640 1256378.712297
17684 353660 1256478.490003
17685 353680 1256578.268547
17686 353700 1256678.047928
17687 353720 1256777.828146
17688 353740 1256877.609202
17689 353760 1256977.391095
17690 353780 1257077.173826
17691 353800 1257176.957394
17692 353820 1257276.741800
17693 353840 1257376.527042
17694 353860 1257476.313122
17695 353880 1257576.100038
17696 353900 1257675.887792
17697 353920 1257775.676383
17698 353940 1257875.465810
17699 353960 1257975.256075
17700 353980 1258075.047176
17701 354000 1258174.839114
17702 354020 1258274.631889
17703 354040 1258374.425500
17704 354060 1258474.219948
17705 354080 1258574.015232
17706 354100 1258673.811353
17707 354120 1258773.608310
17708 354140 1258873.406104
17709 354160 1258973.204734
17710 354180 1259073.004200
17711 354200 1259172.804502
17712 354220 1259272.605641
17713 354240 1259372.407615
17714 354260 1259472.210426
17715 354280 1259572.014073
17716 354300 1259671.818555
17717 354320 1259771.623873
17718 354340 1259871.430027
17719 354360 1259971.237017
17720 354380 1260071.044843
17721 354400 1260170.853504
17722 354420 1260270.663001
17723 354440 1260370.473333
17724 354460 1260470.284501
17725 354480 1260570.096504
17726 354500 1260669.909342
17727 354520 1260769.723016
17728 354540 1260869.537525
17729 354560 1260969.352869
17730 354580 1261069.169049
17731 354600 1261168.986063
17732 354620 1261268.803913
17733 354640 1261368.622597
17734 354660 1261468.442117
17735 354680 1261568.262471
17736 354700 1261668.083660
17737 354720 1261767.905684
17738 354740 1261867.728542
17739 354760 1261967.552235
17740 354780 1262067.376763
17741 354800 1262167.202125
17742 354820 1262267.028322
17743 354840 1262366.855353
17744 354860 1262466.683218
17745 354880 1262566.511918
17746 354900 1262666.341452
17747 354920 1262766.171820
17748 354940 1262866.003022
17749 354960 1262965.835059
17750 354980 1263065.667929
17751 355000 1263165.501634
17752 355020 1263265.336172
17753 355040 1263365.171544
17754 355060 1263465.007750
17755 355080 1263564.844790
17756 355100 1263664.682663
17757 355120 1263764.521370
17758 355140 1263864.360911
17759 355160 1263964.201285
17760 355180 1264064.042493
17761 355200 1264163.884534
17762 355220 1264263.727409
17763 355240 1264363.571116
17764 355260 1264463.415657
17765 355280 1264563.261032
17766 355300 1264663.107239
17767 355320 1264762.954280
17768 355340 1264862.802153
17769 355360 1264962.650860
17770 355380 1265062.500399
17771 355400 1265162.350771
17772 355420 1265262.201976
17773 355440 1265362.054014
17774 355460 1265461.906885
17775 355480 1265561.760588
17776 355500 1265661.615124
17777 355520 1265761.470492
17778 355540 1265861.326693
17779 355560 1265961.183726
17780 355580 1266061.041592
17781 355600 1266160.900290
17782 355620 1266260.759820
17783 355640 1266360.620183
17784 355660 1266460.481377
17785 355680 1266560.343404
17786 355700 1266660.206263
17787 355720 1266760.069954
17788 355740 1266859.934476
17789 355760 1266959.799831
17790 355780 1267059.666017
17791 355800 1267159.533035
17792 355820 1267259.400885
17793 355840 1267359.269567
17794 355860 1267459.139080
17795 355880 1267559.009425
17796 355900 1267658.880601
17797 355920 1267758.752608
17798 355940 1267858.625447
17799 355960 1267958.499118
17800 355980 1268058.373619
17801 356000 1268158.248952
17802 356020 1268258.125116
17803 356040 1268358.002111
17804 356060 1268457.879938
17805 356080 1268557.758595
17806 356100 1268657.638083
17807 356120 1268757.518402
17808 356140 1268857.399552
17809 356160 1268957.281532
17810 356180 1269057.164344
17811 356200 1269157.047986
17812 356220 1269256.932459
17813 356240 1269356.817762
17814 356260 1269456.703896
17815 356280 1269556.590860
17816 356300 1269656.478654
17817 356320 1269756.367279
17818 356340 1269856.256734
17819 356360 1269956.147020
17820 356380 1270056.038136
17821 356400 1270155.930081
17822 356420 1270255.822857
17823 356440 1270355.716463
17824 356460 1270455.610899
17825 356480 1270555.506165
17826 356500 1270655.402260
17827 356520 1270755.299186
17828 356540 1270855.196941
17829 356560 1270955.095526
17830 356580 1271054.994940
17831 356600 1271154.895184
17832 356620 1271254.796258
17833 356640 1271354.698161
17834 356660 1271454.600893
17835 356680 1271554.504455
17836 356700 1271654.408846
17837 356720 1271754.314066
17838 356740 1271854.220116
17839 356760 1271954.126995
17840 356780 1272054.034702
17841 356800 1272153.943239
17842 356820 1272253.852605
17843 356840 1272353.762800
17844 356860 1272453.673823
17845 356880 1272553.585676
17846 356900 1272653.498357
17847 356920 1272753.411867
17848 356940 1272853.326205
17849 356960 1272953.241373
17850 356980 1273053.157368
17851 357000 1273153.074192
17852 357020 1273252.991845
17853 357040 1273352.910326
17854 357060 1273452.829635
17855 357080 1273552.749773
17856 357100 1273652.670739
17857 357120 1273752.592533
17858 357140 1273852.515155
17859 357160 1273952.438605
17860 357180 1274052.362883
17861 357200 1274152.287989
17862 357220 1274252.213923
17863 357240 1274352.140685
17864 357260 1274452.068274
17865 357280 1274551.996691
17866 357300 1274651.925936
17867 357320 1274751.856009
17868 357340 1274851.786909
17869 357360 1274951.718637
17870 357380 1275051.651192
17871 357400 1275151.584574
17872 357420 1275251.518784
17873 357440 1275351.453821
17874 357460 1275451.389685
17875 357480 1275551.326377
17876 357500 1275651.263896
17877 357520 1275751.202241
17878 357540 1275851.141414
17879 357560 1275951.081414
17880 357580 1276051.022240
17881 357600 1276150.963894
17882 357620 1276250.906374
17883 357640 1276350.849681
17884 357660 1276450.793815
17885 357680 1276550.738775
17886 357700 1276650.684562
17887 357720 1276750.631176
17888 357740 1276850.578616
17889 357760 1276950.526882
17890 357780 1277050.475975
17891 357800 1277150.425894
17892 357820 1277250.376639
17893 357840 1277350.328211
17894 357860 1277450.280608
17895 357880 1277550.233832
17896 357900 1277650.187882
17897 357920 1277750.142758
17898 357940 1277850.098459
17899 357960 1277950.054987
17900 357980 1278050.012340
17901 358000 1278149.970520
17902 358020 1278249.929525
17903 358040 1278349.889355
17904 358060 1278449.850011
17905 358080 1278549.811493
17906 358100 1278649.773800
17907 358120 1278749.736933
17908 358140 1278849.700891
17909 358160 1278949.665675
17910 358180 1279049.631283
17911 358200 1279149.597717
17912 358220 1279249.564976
17913 358240 1279349.533061
17914 358260 1279449.501970
17915 358280 1279549.471704
17916 358300 1279649.442263
17917 358320 1279749.413648
17918 358340 1279849.385857
17919 358360 1279949.358890
17920 358380 1280049.332749
17921 358400 1280149.307432
17922 358420 1280249.282940
17923 358440 1280349.259273
17924 358460 1280449.236430
17925 358480 1280549.214411
17926 358500 1280649.193217
17927 358520 1280749.172847
17928 358540 1280849.153302
17929 358560 1280949.134581
17930 358580 1281049.116684
17931 358600 1281149.099611
17932 358620 1281249.083362
17933 358640 1281349.067937
17934 358660 1281449.053337
17935 358680 1281549.039560
17936 358700 1281649.026607
17937 358720 1281749.014478
17938 358740 1281849.003173
17939 358760 1281948.992691
17940 358780 1282048.983033
17941 358800 1282148.974199
17942 358820 1282248.966188
17943 358840 1282348.959001
17944 358860 1282448.952637
17945 358880 1282548.947097
17946 358900 1282648.942379
17947 358920 1282748.938486
17948 358940 1282848.935415
17949 358960 1282948.933168
17950 358980 1283048.931744
17951 359000 1283148.931142
17952 359020 1283248.931364
17953 359040 1283348.932409
17954 359060 1283448.934277
17955 359080 1283548.936967
17956 359100 1283648.940481
17957 359120 1283748.944817
17958 359140 1283848.949976
17959 359160 1283948.955957
17960 359180 1284048.962761
17961 359200 1284148.970388
17962 359220 1284248.978837
17963 359240 1284348.988108
17964 359260 1284448.998202
17965 359280 1284549.009118
17966 359300 1284649.020857
17967 359320 1284749.033417
17968 359340 1284849.046800
17969 359360 1284949.061005
17970 359380 1285049.076032
17971 359400 1285149.091881
17972 359420 1285249.108552
17973 359440 1285349.126045
17974 359460 1285449.144359
17975 359480 1285549.163496
17976 359500 1285649.183454
17977 359520 1285749.204233
17978 359540 1285849.225835
17979 359560 1285949.248258
17980 359580 1286049.271502
17981 359600 1286149.295568
17982 359620 1286249.320456
17983 359640 1286349.346164
17984 359660 1286449.372694
17985 359680 1286549.400046
17986 359700 1286649.428218
17987 359720 1286749.457212
17988 359740 1286849.487026
17989 359760 1286949.517662
17990 359780 1287049.549119
17991 359800 1287149.581396
17992 359820 1287249.614495
17993 359840 1287349.648414
17994 359860 1287449.683154
17995 359880 1287549.718715
17996 359900 1287649.755096
17997 359920 1287749.792298
17998 359940 1287849.830321
17999 359960 1287949.869164
18000 359980 1288049.908827
18001 360000 1288149.949311

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