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 38 of 40 · 500/page · 20000 rows next →
# nmargin_traced_6_40
18502 370020 1338372.285575
18503 370040 1338472.731276
18504 370060 1338573.177772
18505 370080 1338673.625062
18506 370100 1338774.073146
18507 370120 1338874.522025
18508 370140 1338974.971697
18509 370160 1339075.422164
18510 370180 1339175.873424
18511 370200 1339276.325479
18512 370220 1339376.778327
18513 370240 1339477.231969
18514 370260 1339577.686405
18515 370280 1339678.141635
18516 370300 1339778.597658
18517 370320 1339879.054475
18518 370340 1339979.512086
18519 370360 1340079.970490
18520 370380 1340180.429687
18521 370400 1340280.889678
18522 370420 1340381.350463
18523 370440 1340481.812041
18524 370460 1340582.274412
18525 370480 1340682.737576
18526 370500 1340783.201534
18527 370520 1340883.666284
18528 370540 1340984.131828
18529 370560 1341084.598165
18530 370580 1341185.065295
18531 370600 1341285.533217
18532 370620 1341386.001933
18533 370640 1341486.471441
18534 370660 1341586.941743
18535 370680 1341687.412836
18536 370700 1341787.884723
18537 370720 1341888.357402
18538 370740 1341988.830874
18539 370760 1342089.305139
18540 370780 1342189.780196
18541 370800 1342290.256045
18542 370820 1342390.732687
18543 370840 1342491.210121
18544 370860 1342591.688347
18545 370880 1342692.167366
18546 370900 1342792.647176
18547 370920 1342893.127779
18548 370940 1342993.609174
18549 370960 1343094.091361
18550 370980 1343194.574340
18551 371000 1343295.058111
18552 371020 1343395.542674
18553 371040 1343496.028029
18554 371060 1343596.514175
18555 371080 1343697.001113
18556 371100 1343797.488843
18557 371120 1343897.977365
18558 371140 1343998.466678
18559 371160 1344098.956782
18560 371180 1344199.447679
18561 371200 1344299.939366
18562 371220 1344400.431845
18563 371240 1344500.925115
18564 371260 1344601.419177
18565 371280 1344701.914030
18566 371300 1344802.409674
18567 371320 1344902.906109
18568 371340 1345003.403335
18569 371360 1345103.901352
18570 371380 1345204.400161
18571 371400 1345304.899760
18572 371420 1345405.400150
18573 371440 1345505.901331
18574 371460 1345606.403302
18575 371480 1345706.906065
18576 371500 1345807.409618
18577 371520 1345907.913962
18578 371540 1346008.419096
18579 371560 1346108.925021
18580 371580 1346209.431736
18581 371600 1346309.939242
18582 371620 1346410.447538
18583 371640 1346510.956625
18584 371660 1346611.466502
18585 371680 1346711.977169
18586 371700 1346812.488626
18587 371720 1346913.000873
18588 371740 1347013.513911
18589 371760 1347114.027738
18590 371780 1347214.542356
18591 371800 1347315.057763
18592 371820 1347415.573961
18593 371840 1347516.090948
18594 371860 1347616.608725
18595 371880 1347717.127291
18596 371900 1347817.646648
18597 371920 1347918.166794
18598 371940 1348018.687729
18599 371960 1348119.209455
18600 371980 1348219.731969
18601 372000 1348320.255273
18602 372020 1348420.779367
18603 372040 1348521.304250
18604 372060 1348621.829922
18605 372080 1348722.356383
18606 372100 1348822.883634
18607 372120 1348923.411674
18608 372140 1349023.940502
18609 372160 1349124.470120
18610 372180 1349225.000527
18611 372200 1349325.531723
18612 372220 1349426.063708
18613 372240 1349526.596481
18614 372260 1349627.130044
18615 372280 1349727.664395
18616 372300 1349828.199535
18617 372320 1349928.735463
18618 372340 1350029.272180
18619 372360 1350129.809686
18620 372380 1350230.347980
18621 372400 1350330.887062
18622 372420 1350431.426933
18623 372440 1350531.967593
18624 372460 1350632.509040
18625 372480 1350733.051276
18626 372500 1350833.594300
18627 372520 1350934.138112
18628 372540 1351034.682713
18629 372560 1351135.228101
18630 372580 1351235.774277
18631 372600 1351336.321242
18632 372620 1351436.868994
18633 372640 1351537.417534
18634 372660 1351637.966862
18635 372680 1351738.516977
18636 372700 1351839.067881
18637 372720 1351939.619572
18638 372740 1352040.172050
18639 372760 1352140.725316
18640 372780 1352241.279370
18641 372800 1352341.834211
18642 372820 1352442.389840
18643 372840 1352542.946256
18644 372860 1352643.503459
18645 372880 1352744.061449
18646 372900 1352844.620227
18647 372920 1352945.179792
18648 372940 1353045.740144
18649 372960 1353146.301283
18650 372980 1353246.863209
18651 373000 1353347.425922
18652 373020 1353447.989422
18653 373040 1353548.553709
18654 373060 1353649.118782
18655 373080 1353749.684643
18656 373100 1353850.251290
18657 373120 1353950.818723
18658 373140 1354051.386944
18659 373160 1354151.955951
18660 373180 1354252.525744
18661 373200 1354353.096324
18662 373220 1354453.667691
18663 373240 1354554.239843
18664 373260 1354654.812782
18665 373280 1354755.386508
18666 373300 1354855.961019
18667 373320 1354956.536317
18668 373340 1355057.112401
18669 373360 1355157.689271
18670 373380 1355258.266927
18671 373400 1355358.845369
18672 373420 1355459.424596
18673 373440 1355560.004610
18674 373460 1355660.585410
18675 373480 1355761.166995
18676 373500 1355861.749366
18677 373520 1355962.332523
18678 373540 1356062.916465
18679 373560 1356163.501193
18680 373580 1356264.086707
18681 373600 1356364.673006
18682 373620 1356465.260090
18683 373640 1356565.847960
18684 373660 1356666.436615
18685 373680 1356767.026056
18686 373700 1356867.616281
18687 373720 1356968.207292
18688 373740 1357068.799088
18689 373760 1357169.391669
18690 373780 1357269.985035
18691 373800 1357370.579186
18692 373820 1357471.174122
18693 373840 1357571.769843
18694 373860 1357672.366349
18695 373880 1357772.963640
18696 373900 1357873.561715
18697 373920 1357974.160575
18698 373940 1358074.760220
18699 373960 1358175.360649
18700 373980 1358275.961863
18701 374000 1358376.563861
18702 374020 1358477.166644
18703 374040 1358577.770211
18704 374060 1358678.374563
18705 374080 1358778.979699
18706 374100 1358879.585619
18707 374120 1358980.192323
18708 374140 1359080.799812
18709 374160 1359181.408084
18710 374180 1359282.017141
18711 374200 1359382.626982
18712 374220 1359483.237606
18713 374240 1359583.849015
18714 374260 1359684.461207
18715 374280 1359785.074183
18716 374300 1359885.687943
18717 374320 1359986.302487
18718 374340 1360086.917814
18719 374360 1360187.533925
18720 374380 1360288.150820
18721 374400 1360388.768498
18722 374420 1360489.386960
18723 374440 1360590.006204
18724 374460 1360690.626233
18725 374480 1360791.247044
18726 374500 1360891.868639
18727 374520 1360992.491018
18728 374540 1361093.114179
18729 374560 1361193.738123
18730 374580 1361294.362851
18731 374600 1361394.988361
18732 374620 1361495.614655
18733 374640 1361596.241731
18734 374660 1361696.869591
18735 374680 1361797.498233
18736 374700 1361898.127658
18737 374720 1361998.757866
18738 374740 1362099.388856
18739 374760 1362200.020629
18740 374780 1362300.653185
18741 374800 1362401.286523
18742 374820 1362501.920644
18743 374840 1362602.555547
18744 374860 1362703.191232
18745 374880 1362803.827700
18746 374900 1362904.464950
18747 374920 1363005.102983
18748 374940 1363105.741797
18749 374960 1363206.381394
18750 374980 1363307.021773
18751 375000 1363407.662934
18752 375020 1363508.304876
18753 375040 1363608.947601
18754 375060 1363709.591108
18755 375080 1363810.235397
18756 375100 1363910.880467
18757 375120 1364011.526319
18758 375140 1364112.172953
18759 375160 1364212.820369
18760 375180 1364313.468566
18761 375200 1364414.117545
18762 375220 1364514.767305
18763 375240 1364615.417846
18764 375260 1364716.069170
18765 375280 1364816.721274
18766 375300 1364917.374160
18767 375320 1365018.027827
18768 375340 1365118.682275
18769 375360 1365219.337505
18770 375380 1365319.993515
18771 375400 1365420.650307
18772 375420 1365521.307880
18773 375440 1365621.966233
18774 375460 1365722.625368
18775 375480 1365823.285284
18776 375500 1365923.945980
18777 375520 1366024.607457
18778 375540 1366125.269715
18779 375560 1366225.932753
18780 375580 1366326.596573
18781 375600 1366427.261172
18782 375620 1366527.926553
18783 375640 1366628.592713
18784 375660 1366729.259655
18785 375680 1366829.927376
18786 375700 1366930.595878
18787 375720 1367031.265161
18788 375740 1367131.935223
18789 375760 1367232.606066
18790 375780 1367333.277689
18791 375800 1367433.950092
18792 375820 1367534.623275
18793 375840 1367635.297238
18794 375860 1367735.971981
18795 375880 1367836.647504
18796 375900 1367937.323807
18797 375920 1368038.000889
18798 375940 1368138.678752
18799 375960 1368239.357394
18800 375980 1368340.036815
18801 376000 1368440.717017
18802 376020 1368541.397998
18803 376040 1368642.079758
18804 376060 1368742.762298
18805 376080 1368843.445617
18806 376100 1368944.129716
18807 376120 1369044.814594
18808 376140 1369145.500251
18809 376160 1369246.186688
18810 376180 1369346.873904
18811 376200 1369447.561898
18812 376220 1369548.250672
18813 376240 1369648.940225
18814 376260 1369749.630557
18815 376280 1369850.321668
18816 376300 1369951.013558
18817 376320 1370051.706227
18818 376340 1370152.399674
18819 376360 1370253.093900
18820 376380 1370353.788905
18821 376400 1370454.484689
18822 376420 1370555.181251
18823 376440 1370655.878591
18824 376460 1370756.576711
18825 376480 1370857.275608
18826 376500 1370957.975284
18827 376520 1371058.675739
18828 376540 1371159.376971
18829 376560 1371260.078982
18830 376580 1371360.781771
18831 376600 1371461.485339
18832 376620 1371562.189684
18833 376640 1371662.894808
18834 376660 1371763.600709
18835 376680 1371864.307389
18836 376700 1371965.014846
18837 376720 1372065.723082
18838 376740 1372166.432095
18839 376760 1372267.141886
18840 376780 1372367.852454
18841 376800 1372468.563801
18842 376820 1372569.275924
18843 376840 1372669.988826
18844 376860 1372770.702505
18845 376880 1372871.416962
18846 376900 1372972.132196
18847 376920 1373072.848207
18848 376940 1373173.564996
18849 376960 1373274.282562
18850 376980 1373375.000905
18851 377000 1373475.720025
18852 377020 1373576.439923
18853 377040 1373677.160598
18854 377060 1373777.882050
18855 377080 1373878.604278
18856 377100 1373979.327284
18857 377120 1374080.051067
18858 377140 1374180.775626
18859 377160 1374281.500963
18860 377180 1374382.227076
18861 377200 1374482.953965
18862 377220 1374583.681632
18863 377240 1374684.410075
18864 377260 1374785.139295
18865 377280 1374885.869291
18866 377300 1374986.600063
18867 377320 1375087.331612
18868 377340 1375188.063938
18869 377360 1375288.797040
18870 377380 1375389.530918
18871 377400 1375490.265572
18872 377420 1375591.001002
18873 377440 1375691.737209
18874 377460 1375792.474192
18875 377480 1375893.211950
18876 377500 1375993.950485
18877 377520 1376094.689796
18878 377540 1376195.429882
18879 377560 1376296.170745
18880 377580 1376396.912383
18881 377600 1376497.654797
18882 377620 1376598.397987
18883 377640 1376699.141952
18884 377660 1376799.886693
18885 377680 1376900.632210
18886 377700 1377001.378502
18887 377720 1377102.125569
18888 377740 1377202.873412
18889 377760 1377303.622030
18890 377780 1377404.371424
18891 377800 1377505.121593
18892 377820 1377605.872537
18893 377840 1377706.624256
18894 377860 1377807.376750
18895 377880 1377908.130020
18896 377900 1378008.884064
18897 377920 1378109.638884
18898 377940 1378210.394478
18899 377960 1378311.150848
18900 377980 1378411.907992
18901 378000 1378512.665911
18902 378020 1378613.424604
18903 378040 1378714.184073
18904 378060 1378814.944316
18905 378080 1378915.705333
18906 378100 1379016.467126
18907 378120 1379117.229692
18908 378140 1379217.993033
18909 378160 1379318.757149
18910 378180 1379419.522039
18911 378200 1379520.287703
18912 378220 1379621.054142
18913 378240 1379721.821354
18914 378260 1379822.589341
18915 378280 1379923.358102
18916 378300 1380024.127637
18917 378320 1380124.897946
18918 378340 1380225.669029
18919 378360 1380326.440886
18920 378380 1380427.213517
18921 378400 1380527.986922
18922 378420 1380628.761101
18923 378440 1380729.536053
18924 378460 1380830.311779
18925 378480 1380931.088278
18926 378500 1381031.865551
18927 378520 1381132.643598
18928 378540 1381233.422418
18929 378560 1381334.202012
18930 378580 1381434.982379
18931 378600 1381535.763520
18932 378620 1381636.545433
18933 378640 1381737.328120
18934 378660 1381838.111580
18935 378680 1381938.895814
18936 378700 1382039.680820
18937 378720 1382140.466600
18938 378740 1382241.253152
18939 378760 1382342.040478
18940 378780 1382442.828576
18941 378800 1382543.617448
18942 378820 1382644.407092
18943 378840 1382745.197509
18944 378860 1382845.988699
18945 378880 1382946.780661
18946 378900 1383047.573396
18947 378920 1383148.366904
18948 378940 1383249.161184
18949 378960 1383349.956236
18950 378980 1383450.752061
18951 379000 1383551.548659
18952 379020 1383652.346029
18953 379040 1383753.144171
18954 379060 1383853.943085
18955 379080 1383954.742772
18956 379100 1384055.543231
18957 379120 1384156.344462
18958 379140 1384257.146465
18959 379160 1384357.949240
18960 379180 1384458.752787
18961 379200 1384559.557105
18962 379220 1384660.362196
18963 379240 1384761.168059
18964 379260 1384861.974693
18965 379280 1384962.782099
18966 379300 1385063.590277
18967 379320 1385164.399226
18968 379340 1385265.208948
18969 379360 1385366.019440
18970 379380 1385466.830704
18971 379400 1385567.642740
18972 379420 1385668.455547
18973 379440 1385769.269125
18974 379460 1385870.083474
18975 379480 1385970.898595
18976 379500 1386071.714487
18977 379520 1386172.531150
18978 379540 1386273.348585
18979 379560 1386374.166790
18980 379580 1386474.985766
18981 379600 1386575.805514
18982 379620 1386676.626032
18983 379640 1386777.447321
18984 379660 1386878.269381
18985 379680 1386979.092212
18986 379700 1387079.915813
18987 379720 1387180.740186
18988 379740 1387281.565329
18989 379760 1387382.391242
18990 379780 1387483.217926
18991 379800 1387584.045380
18992 379820 1387684.873605
18993 379840 1387785.702601
18994 379860 1387886.532366
18995 379880 1387987.362902
18996 379900 1388088.194209
18997 379920 1388189.026285
18998 379940 1388289.859132
18999 379960 1388390.692748
19000 379980 1388491.527135
19001 380000 1388592.362292

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