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 40 of 40 · 500/page · 20000 rows
# nmargin_traced_6_40
19502 390020 1439206.621920
19503 390040 1439307.837759
19504 390060 1439409.054343
19505 390080 1439510.271675
19506 390100 1439611.489754
19507 390120 1439712.708579
19508 390140 1439813.928151
19509 390160 1439915.148469
19510 390180 1440016.369535
19511 390200 1440117.591346
19512 390220 1440218.813905
19513 390240 1440320.037209
19514 390260 1440421.261260
19515 390280 1440522.486058
19516 390300 1440623.711602
19517 390320 1440724.937892
19518 390340 1440826.164928
19519 390360 1440927.392710
19520 390380 1441028.621239
19521 390400 1441129.850514
19522 390420 1441231.080535
19523 390440 1441332.311301
19524 390460 1441433.542814
19525 390480 1441534.775073
19526 390500 1441636.008077
19527 390520 1441737.241828
19528 390540 1441838.476324
19529 390560 1441939.711566
19530 390580 1442040.947554
19531 390600 1442142.184287
19532 390620 1442243.421766
19533 390640 1442344.659990
19534 390660 1442445.898960
19535 390680 1442547.138676
19536 390700 1442648.379137
19537 390720 1442749.620343
19538 390740 1442850.862294
19539 390760 1442952.104991
19540 390780 1443053.348434
19541 390800 1443154.592621
19542 390820 1443255.837554
19543 390840 1443357.083231
19544 390860 1443458.329654
19545 390880 1443559.576822
19546 390900 1443660.824734
19547 390920 1443762.073392
19548 390940 1443863.322795
19549 390960 1443964.572942
19550 390980 1444065.823835
19551 391000 1444167.075472
19552 391020 1444268.327853
19553 391040 1444369.580980
19554 391060 1444470.834851
19555 391080 1444572.089466
19556 391100 1444673.344827
19557 391120 1444774.600931
19558 391140 1444875.857780
19559 391160 1444977.115374
19560 391180 1445078.373712
19561 391200 1445179.632794
19562 391220 1445280.892621
19563 391240 1445382.153191
19564 391260 1445483.414506
19565 391280 1445584.676565
19566 391300 1445685.939369
19567 391320 1445787.202916
19568 391340 1445888.467207
19569 391360 1445989.732242
19570 391380 1446090.998021
19571 391400 1446192.264544
19572 391420 1446293.531811
19573 391440 1446394.799822
19574 391460 1446496.068576
19575 391480 1446597.338074
19576 391500 1446698.608316
19577 391520 1446799.879301
19578 391540 1446901.151030
19579 391560 1447002.423502
19580 391580 1447103.696718
19581 391600 1447204.970678
19582 391620 1447306.245380
19583 391640 1447407.520826
19584 391660 1447508.797016
19585 391680 1447610.073948
19586 391700 1447711.351624
19587 391720 1447812.630043
19588 391740 1447913.909205
19589 391760 1448015.189110
19590 391780 1448116.469759
19591 391800 1448217.751150
19592 391820 1448319.033284
19593 391840 1448420.316161
19594 391860 1448521.599781
19595 391880 1448622.884144
19596 391900 1448724.169249
19597 391920 1448825.455097
19598 391940 1448926.741688
19599 391960 1449028.029022
19600 391980 1449129.317098
19601 392000 1449230.605916
19602 392020 1449331.895477
19603 392040 1449433.185781
19604 392060 1449534.476827
19605 392080 1449635.768615
19606 392100 1449737.061146
19607 392120 1449838.354419
19608 392140 1449939.648434
19609 392160 1450040.943192
19610 392180 1450142.238691
19611 392200 1450243.534933
19612 392220 1450344.831917
19613 392240 1450446.129643
19614 392260 1450547.428110
19615 392280 1450648.727320
19616 392300 1450750.027272
19617 392320 1450851.327965
19618 392340 1450952.629400
19619 392360 1451053.931577
19620 392380 1451155.234496
19621 392400 1451256.538156
19622 392420 1451357.842558
19623 392440 1451459.147701
19624 392460 1451560.453586
19625 392480 1451661.760213
19626 392500 1451763.067581
19627 392520 1451864.375690
19628 392540 1451965.684541
19629 392560 1452066.994133
19630 392580 1452168.304466
19631 392600 1452269.615541
19632 392620 1452370.927356
19633 392640 1452472.239913
19634 392660 1452573.553211
19635 392680 1452674.867250
19636 392700 1452776.182030
19637 392720 1452877.497551
19638 392740 1452978.813813
19639 392760 1453080.130815
19640 392780 1453181.448559
19641 392800 1453282.767043
19642 392820 1453384.086268
19643 392840 1453485.406234
19644 392860 1453586.726940
19645 392880 1453688.048387
19646 392900 1453789.370575
19647 392920 1453890.693503
19648 392940 1453992.017171
19649 392960 1454093.341580
19650 392980 1454194.666730
19651 393000 1454295.992619
19652 393020 1454397.319249
19653 393040 1454498.646620
19654 393060 1454599.974730
19655 393080 1454701.303581
19656 393100 1454802.633171
19657 393120 1454903.963502
19658 393140 1455005.294573
19659 393160 1455106.626384
19660 393180 1455207.958935
19661 393200 1455309.292225
19662 393220 1455410.626256
19663 393240 1455511.961026
19664 393260 1455613.296536
19665 393280 1455714.632786
19666 393300 1455815.969776
19667 393320 1455917.307505
19668 393340 1456018.645974
19669 393360 1456119.985182
19670 393380 1456221.325130
19671 393400 1456322.665817
19672 393420 1456424.007244
19673 393440 1456525.349410
19674 393460 1456626.692315
19675 393480 1456728.035960
19676 393500 1456829.380344
19677 393520 1456930.725467
19678 393540 1457032.071329
19679 393560 1457133.417930
19680 393580 1457234.765271
19681 393600 1457336.113350
19682 393620 1457437.462169
19683 393640 1457538.811726
19684 393660 1457640.162023
19685 393680 1457741.513058
19686 393700 1457842.864832
19687 393720 1457944.217344
19688 393740 1458045.570596
19689 393760 1458146.924586
19690 393780 1458248.279315
19691 393800 1458349.634782
19692 393820 1458450.990988
19693 393840 1458552.347932
19694 393860 1458653.705615
19695 393880 1458755.064036
19696 393900 1458856.423196
19697 393920 1458957.783094
19698 393940 1459059.143730
19699 393960 1459160.505104
19700 393980 1459261.867217
19701 394000 1459363.230068
19702 394020 1459464.593657
19703 394040 1459565.957984
19704 394060 1459667.323049
19705 394080 1459768.688851
19706 394100 1459870.055392
19707 394120 1459971.422671
19708 394140 1460072.790688
19709 394160 1460174.159442
19710 394180 1460275.528934
19711 394200 1460376.899164
19712 394220 1460478.270131
19713 394240 1460579.641837
19714 394260 1460681.014279
19715 394280 1460782.387460
19716 394300 1460883.761377
19717 394320 1460985.136033
19718 394340 1461086.511425
19719 394360 1461187.887555
19720 394380 1461289.264422
19721 394400 1461390.642027
19722 394420 1461492.020369
19723 394440 1461593.399448
19724 394460 1461694.779264
19725 394480 1461796.159817
19726 394500 1461897.541107
19727 394520 1461998.923135
19728 394540 1462100.305899
19729 394560 1462201.689400
19730 394580 1462303.073638
19731 394600 1462404.458613
19732 394620 1462505.844325
19733 394640 1462607.230773
19734 394660 1462708.617958
19735 394680 1462810.005880
19736 394700 1462911.394539
19737 394720 1463012.783934
19738 394740 1463114.174065
19739 394760 1463215.564933
19740 394780 1463316.956538
19741 394800 1463418.348879
19742 394820 1463519.741956
19743 394840 1463621.135769
19744 394860 1463722.530319
19745 394880 1463823.925605
19746 394900 1463925.321628
19747 394920 1464026.718386
19748 394940 1464128.115880
19749 394960 1464229.514111
19750 394980 1464330.913077
19751 395000 1464432.312780
19752 395020 1464533.713218
19753 395040 1464635.114393
19754 395060 1464736.516303
19755 395080 1464837.918949
19756 395100 1464939.322331
19757 395120 1465040.726448
19758 395140 1465142.131301
19759 395160 1465243.536890
19760 395180 1465344.943214
19761 395200 1465446.350274
19762 395220 1465547.758069
19763 395240 1465649.166600
19764 395260 1465750.575866
19765 395280 1465851.985868
19766 395300 1465953.396604
19767 395320 1466054.808077
19768 395340 1466156.220284
19769 395360 1466257.633226
19770 395380 1466359.046904
19771 395400 1466460.461317
19772 395420 1466561.876465
19773 395440 1466663.292347
19774 395460 1466764.708965
19775 395480 1466866.126318
19776 395500 1466967.544406
19777 395520 1467068.963228
19778 395540 1467170.382785
19779 395560 1467271.803077
19780 395580 1467373.224104
19781 395600 1467474.645865
19782 395620 1467576.068361
19783 395640 1467677.491592
19784 395660 1467778.915557
19785 395680 1467880.340256
19786 395700 1467981.765691
19787 395720 1468083.191859
19788 395740 1468184.618762
19789 395760 1468286.046399
19790 395780 1468387.474770
19791 395800 1468488.903876
19792 395820 1468590.333716
19793 395840 1468691.764290
19794 395860 1468793.195598
19795 395880 1468894.627640
19796 395900 1468996.060416
19797 395920 1469097.493926
19798 395940 1469198.928170
19799 395960 1469300.363148
19800 395980 1469401.798860
19801 396000 1469503.235305
19802 396020 1469604.672485
19803 396040 1469706.110398
19804 396060 1469807.549045
19805 396080 1469908.988425
19806 396100 1470010.428539
19807 396120 1470111.869386
19808 396140 1470213.310967
19809 396160 1470314.753282
19810 396180 1470416.196329
19811 396200 1470517.640111
19812 396220 1470619.084625
19813 396240 1470720.529873
19814 396260 1470821.975854
19815 396280 1470923.422568
19816 396300 1471024.870016
19817 396320 1471126.318196
19818 396340 1471227.767110
19819 396360 1471329.216756
19820 396380 1471430.667136
19821 396400 1471532.118248
19822 396420 1471633.570094
19823 396440 1471735.022672
19824 396460 1471836.475983
19825 396480 1471937.930027
19826 396500 1472039.384803
19827 396520 1472140.840312
19828 396540 1472242.296554
19829 396560 1472343.753529
19830 396580 1472445.211236
19831 396600 1472546.669675
19832 396620 1472648.128847
19833 396640 1472749.588751
19834 396660 1472851.049388
19835 396680 1472952.510757
19836 396700 1473053.972858
19837 396720 1473155.435692
19838 396740 1473256.899258
19839 396760 1473358.363556
19840 396780 1473459.828586
19841 396800 1473561.294348
19842 396820 1473662.760842
19843 396840 1473764.228068
19844 396860 1473865.696026
19845 396880 1473967.164716
19846 396900 1474068.634138
19847 396920 1474170.104292
19848 396940 1474271.575177
19849 396960 1474373.046795
19850 396980 1474474.519143
19851 397000 1474575.992224
19852 397020 1474677.466036
19853 397040 1474778.940580
19854 397060 1474880.415855
19855 397080 1474981.891862
19856 397100 1475083.368600
19857 397120 1475184.846069
19858 397140 1475286.324270
19859 397160 1475387.803202
19860 397180 1475489.282865
19861 397200 1475590.763260
19862 397220 1475692.244386
19863 397240 1475793.726243
19864 397260 1475895.208831
19865 397280 1475996.692150
19866 397300 1476098.176200
19867 397320 1476199.660981
19868 397340 1476301.146493
19869 397360 1476402.632735
19870 397380 1476504.119709
19871 397400 1476605.607413
19872 397420 1476707.095848
19873 397440 1476808.585014
19874 397460 1476910.074911
19875 397480 1477011.565538
19876 397500 1477113.056895
19877 397520 1477214.548983
19878 397540 1477316.041802
19879 397560 1477417.535351
19880 397580 1477519.029631
19881 397600 1477620.524640
19882 397620 1477722.020381
19883 397640 1477823.516851
19884 397660 1477925.014052
19885 397680 1478026.511983
19886 397700 1478128.010644
19887 397720 1478229.510035
19888 397740 1478331.010156
19889 397760 1478432.511007
19890 397780 1478534.012588
19891 397800 1478635.514899
19892 397820 1478737.017940
19893 397840 1478838.521711
19894 397860 1478940.026211
19895 397880 1479041.531442
19896 397900 1479143.037402
19897 397920 1479244.544091
19898 397940 1479346.051511
19899 397960 1479447.559660
19900 397980 1479549.068538
19901 398000 1479650.578146
19902 398020 1479752.088483
19903 398040 1479853.599550
19904 398060 1479955.111347
19905 398080 1480056.623872
19906 398100 1480158.137127
19907 398120 1480259.651111
19908 398140 1480361.165824
19909 398160 1480462.681267
19910 398180 1480564.197438
19911 398200 1480665.714339
19912 398220 1480767.231968
19913 398240 1480868.750327
19914 398260 1480970.269415
19915 398280 1481071.789231
19916 398300 1481173.309776
19917 398320 1481274.831051
19918 398340 1481376.353053
19919 398360 1481477.875785
19920 398380 1481579.399245
19921 398400 1481680.923434
19922 398420 1481782.448352
19923 398440 1481883.973998
19924 398460 1481985.500373
19925 398480 1482087.027476
19926 398500 1482188.555307
19927 398520 1482290.083867
19928 398540 1482391.613156
19929 398560 1482493.143172
19930 398580 1482594.673917
19931 398600 1482696.205390
19932 398620 1482797.737592
19933 398640 1482899.270521
19934 398660 1483000.804178
19935 398680 1483102.338564
19936 398700 1483203.873677
19937 398720 1483305.409519
19938 398740 1483406.946088
19939 398760 1483508.483386
19940 398780 1483610.021411
19941 398800 1483711.560164
19942 398820 1483813.099644
19943 398840 1483914.639853
19944 398860 1484016.180789
19945 398880 1484117.722453
19946 398900 1484219.264844
19947 398920 1484320.807963
19948 398940 1484422.351809
19949 398960 1484523.896383
19950 398980 1484625.441684
19951 399000 1484726.987712
19952 399020 1484828.534468
19953 399040 1484930.081951
19954 399060 1485031.630162
19955 399080 1485133.179099
19956 399100 1485234.728764
19957 399120 1485336.279156
19958 399140 1485437.830275
19959 399160 1485539.382121
19960 399180 1485640.934693
19961 399200 1485742.487993
19962 399220 1485844.042020
19963 399240 1485945.596774
19964 399260 1486047.152254
19965 399280 1486148.708461
19966 399300 1486250.265395
19967 399320 1486351.823056
19968 399340 1486453.381443
19969 399360 1486554.940557
19970 399380 1486656.500397
19971 399400 1486758.060964
19972 399420 1486859.622258
19973 399440 1486961.184278
19974 399460 1487062.747024
19975 399480 1487164.310496
19976 399500 1487265.874695
19977 399520 1487367.439620
19978 399540 1487469.005272
19979 399560 1487570.571649
19980 399580 1487672.138753
19981 399600 1487773.706583
19982 399620 1487875.275139
19983 399640 1487976.844421
19984 399660 1488078.414428
19985 399680 1488179.985162
19986 399700 1488281.556622
19987 399720 1488383.128807
19988 399740 1488484.701718
19989 399760 1488586.275355
19990 399780 1488687.849718
19991 399800 1488789.424807
19992 399820 1488891.000621
19993 399840 1488992.577160
19994 399860 1489094.154425
19995 399880 1489195.732416
19996 399900 1489297.311132
19997 399920 1489398.890574
19998 399940 1489500.470740
19999 399960 1489602.051633
20000 399980 1489703.633250
20001 400000 1489805.215593

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