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 4 of 40 · 500/page · 20000 rows next →
# nmargin_traced_6_40
1502 30020 -143343.693959
1503 30040 -143294.955771
1504 30060 -143246.196965
1505 30080 -143197.417559
1506 30100 -143148.617573
1507 30120 -143099.797027
1508 30140 -143050.955942
1509 30160 -143002.094336
1510 30180 -142953.212230
1511 30200 -142904.309644
1512 30220 -142855.386596
1513 30240 -142806.443107
1514 30260 -142757.479196
1515 30280 -142708.494883
1516 30300 -142659.490188
1517 30320 -142610.465129
1518 30340 -142561.419727
1519 30360 -142512.354001
1520 30380 -142463.267970
1521 30400 -142414.161654
1522 30420 -142365.035071
1523 30440 -142315.888242
1524 30460 -142266.721186
1525 30480 -142217.533922
1526 30500 -142168.326468
1527 30520 -142119.098845
1528 30540 -142069.851072
1529 30560 -142020.583167
1530 30580 -141971.295150
1531 30600 -141921.987040
1532 30620 -141872.658855
1533 30640 -141823.310615
1534 30660 -141773.942340
1535 30680 -141724.554046
1536 30700 -141675.145755
1537 30720 -141625.717484
1538 30740 -141576.269252
1539 30760 -141526.801079
1540 30780 -141477.312982
1541 30800 -141427.804982
1542 30820 -141378.277095
1543 30840 -141328.729342
1544 30860 -141279.161741
1545 30880 -141229.574310
1546 30900 -141179.967068
1547 30920 -141130.340034
1548 30940 -141080.693225
1549 30960 -141031.026662
1550 30980 -140981.340361
1551 31000 -140931.634342
1552 31020 -140881.908623
1553 31040 -140832.163223
1554 31060 -140782.398159
1555 31080 -140732.613450
1556 31100 -140682.809114
1557 31120 -140632.985171
1558 31140 -140583.141636
1559 31160 -140533.278530
1560 31180 -140483.395871
1561 31200 -140433.493675
1562 31220 -140383.571962
1563 31240 -140333.630750
1564 31260 -140283.670056
1565 31280 -140233.689899
1566 31300 -140183.690296
1567 31320 -140133.671266
1568 31340 -140083.632827
1569 31360 -140033.574996
1570 31380 -139983.497792
1571 31400 -139933.401231
1572 31420 -139883.285333
1573 31440 -139833.150114
1574 31460 -139782.995594
1575 31480 -139732.821788
1576 31500 -139682.628716
1577 31520 -139632.416394
1578 31540 -139582.184840
1579 31560 -139531.934073
1580 31580 -139481.664109
1581 31600 -139431.374967
1582 31620 -139381.066663
1583 31640 -139330.739215
1584 31660 -139280.392641
1585 31680 -139230.026958
1586 31700 -139179.642184
1587 31720 -139129.238335
1588 31740 -139078.815430
1589 31760 -139028.373486
1590 31780 -138977.912520
1591 31800 -138927.432549
1592 31820 -138876.933590
1593 31840 -138826.415661
1594 31860 -138775.878780
1595 31880 -138725.322962
1596 31900 -138674.748226
1597 31920 -138624.154588
1598 31940 -138573.542066
1599 31960 -138522.910676
1600 31980 -138472.260436
1601 32000 -138421.591362
1602 32020 -138370.903473
1603 32040 -138320.196783
1604 32060 -138269.471312
1605 32080 -138218.727074
1606 32100 -138167.964088
1607 32120 -138117.182371
1608 32140 -138066.381938
1609 32160 -138015.562807
1610 32180 -137964.724994
1611 32200 -137913.868517
1612 32220 -137862.993392
1613 32240 -137812.099636
1614 32260 -137761.187265
1615 32280 -137710.256296
1616 32300 -137659.306746
1617 32320 -137608.338631
1618 32340 -137557.351967
1619 32360 -137506.346772
1620 32380 -137455.323062
1621 32400 -137404.280854
1622 32420 -137353.220163
1623 32440 -137302.141006
1624 32460 -137251.043400
1625 32480 -137199.927360
1626 32500 -137148.792905
1627 32520 -137097.640049
1628 32540 -137046.468809
1629 32560 -136995.279201
1630 32580 -136944.071242
1631 32600 -136892.844947
1632 32620 -136841.600334
1633 32640 -136790.337417
1634 32660 -136739.056214
1635 32680 -136687.756740
1636 32700 -136636.439012
1637 32720 -136585.103046
1638 32740 -136533.748857
1639 32760 -136482.376462
1640 32780 -136430.985876
1641 32800 -136379.577116
1642 32820 -136328.150198
1643 32840 -136276.705137
1644 32860 -136225.241950
1645 32880 -136173.760652
1646 32900 -136122.261260
1647 32920 -136070.743788
1648 32940 -136019.208253
1649 32960 -135967.654671
1650 32980 -135916.083057
1651 33000 -135864.493428
1652 33020 -135812.885798
1653 33040 -135761.260183
1654 33060 -135709.616600
1655 33080 -135657.955064
1656 33100 -135606.275590
1657 33120 -135554.578194
1658 33140 -135502.862891
1659 33160 -135451.129698
1660 33180 -135399.378629
1661 33200 -135347.609700
1662 33220 -135295.822927
1663 33240 -135244.018325
1664 33260 -135192.195910
1665 33280 -135140.355696
1666 33300 -135088.497700
1667 33320 -135036.621936
1668 33340 -134984.728420
1669 33360 -134932.817167
1670 33380 -134880.888193
1671 33400 -134828.941513
1672 33420 -134776.977141
1673 33440 -134724.995094
1674 33460 -134672.995386
1675 33480 -134620.978033
1676 33500 -134568.943050
1677 33520 -134516.890451
1678 33540 -134464.820252
1679 33560 -134412.732469
1680 33580 -134360.627115
1681 33600 -134308.504207
1682 33620 -134256.363758
1683 33640 -134204.205785
1684 33660 -134152.030302
1685 33680 -134099.837324
1686 33700 -134047.626865
1687 33720 -133995.398942
1688 33740 -133943.153568
1689 33760 -133890.890759
1690 33780 -133838.610529
1691 33800 -133786.312893
1692 33820 -133733.997866
1693 33840 -133681.665463
1694 33860 -133629.315698
1695 33880 -133576.948587
1696 33900 -133524.564143
1697 33920 -133472.162382
1698 33940 -133419.743318
1699 33960 -133367.306966
1700 33980 -133314.853341
1701 34000 -133262.382456
1702 34020 -133209.894327
1703 34040 -133157.388968
1704 34060 -133104.866394
1705 34080 -133052.326619
1706 34100 -132999.769657
1707 34120 -132947.195524
1708 34140 -132894.604233
1709 34160 -132841.995799
1710 34180 -132789.370236
1711 34200 -132736.727559
1712 34220 -132684.067782
1713 34240 -132631.390920
1714 34260 -132578.696986
1715 34280 -132525.985995
1716 34300 -132473.257961
1717 34320 -132420.512899
1718 34340 -132367.750822
1719 34360 -132314.971746
1720 34380 -132262.175683
1721 34400 -132209.362649
1722 34420 -132156.532657
1723 34440 -132103.685721
1724 34460 -132050.821856
1725 34480 -131997.941076
1726 34500 -131945.043394
1727 34520 -131892.128826
1728 34540 -131839.197384
1729 34560 -131786.249082
1730 34580 -131733.283936
1731 34600 -131680.301958
1732 34620 -131627.303163
1733 34640 -131574.287564
1734 34660 -131521.255176
1735 34680 -131468.206012
1736 34700 -131415.140086
1737 34720 -131362.057413
1738 34740 -131308.958005
1739 34760 -131255.841876
1740 34780 -131202.709041
1741 34800 -131149.559513
1742 34820 -131096.393306
1743 34840 -131043.210434
1744 34860 -130990.010910
1745 34880 -130936.794747
1746 34900 -130883.561961
1747 34920 -130830.312563
1748 34940 -130777.046568
1749 34960 -130723.763990
1750 34980 -130670.464842
1751 35000 -130617.149137
1752 35020 -130563.816889
1753 35040 -130510.468112
1754 35060 -130457.102819
1755 35080 -130403.721024
1756 35100 -130350.322739
1757 35120 -130296.907979
1758 35140 -130243.476757
1759 35160 -130190.029086
1760 35180 -130136.564980
1761 35200 -130083.084452
1762 35220 -130029.587515
1763 35240 -129976.074182
1764 35260 -129922.544468
1765 35280 -129868.998385
1766 35300 -129815.435947
1767 35320 -129761.857166
1768 35340 -129708.262056
1769 35360 -129654.650631
1770 35380 -129601.022902
1771 35400 -129547.378885
1772 35420 -129493.718591
1773 35440 -129440.042034
1774 35460 -129386.349226
1775 35480 -129332.640182
1776 35500 -129278.914914
1777 35520 -129225.173435
1778 35540 -129171.415759
1779 35560 -129117.641897
1780 35580 -129063.851864
1781 35600 -129010.045672
1782 35620 -128956.223334
1783 35640 -128902.384864
1784 35660 -128848.530273
1785 35680 -128794.659575
1786 35700 -128740.772783
1787 35720 -128686.869910
1788 35740 -128632.950969
1789 35760 -128579.015972
1790 35780 -128525.064932
1791 35800 -128471.097862
1792 35820 -128417.114775
1793 35840 -128363.115684
1794 35860 -128309.100600
1795 35880 -128255.069538
1796 35900 -128201.022510
1797 35920 -128146.959528
1798 35940 -128092.880606
1799 35960 -128038.785755
1800 35980 -127984.674988
1801 36000 -127930.548319
1802 36020 -127876.405759
1803 36040 -127822.247322
1804 36060 -127768.073019
1805 36080 -127713.882864
1806 36100 -127659.676868
1807 36120 -127605.455045
1808 36140 -127551.217407
1809 36160 -127496.963966
1810 36180 -127442.694735
1811 36200 -127388.409727
1812 36220 -127334.108953
1813 36240 -127279.792426
1814 36260 -127225.460159
1815 36280 -127171.112164
1816 36300 -127116.748453
1817 36320 -127062.369038
1818 36340 -127007.973933
1819 36360 -126953.563149
1820 36380 -126899.136698
1821 36400 -126844.694593
1822 36420 -126790.236846
1823 36440 -126735.763470
1824 36460 -126681.274476
1825 36480 -126626.769877
1826 36500 -126572.249684
1827 36520 -126517.713911
1828 36540 -126463.162569
1829 36560 -126408.595671
1830 36580 -126354.013228
1831 36600 -126299.415252
1832 36620 -126244.801757
1833 36640 -126190.172753
1834 36660 -126135.528253
1835 36680 -126080.868268
1836 36700 -126026.192812
1837 36720 -125971.501896
1838 36740 -125916.795531
1839 36760 -125862.073731
1840 36780 -125807.336506
1841 36800 -125752.583869
1842 36820 -125697.815831
1843 36840 -125643.032405
1844 36860 -125588.233603
1845 36880 -125533.419436
1846 36900 -125478.589916
1847 36920 -125423.745056
1848 36940 -125368.884866
1849 36960 -125314.009359
1850 36980 -125259.118546
1851 37000 -125204.212440
1852 37020 -125149.291052
1853 37040 -125094.354393
1854 37060 -125039.402476
1855 37080 -124984.435312
1856 37100 -124929.452913
1857 37120 -124874.455291
1858 37140 -124819.442457
1859 37160 -124764.414423
1860 37180 -124709.371200
1861 37200 -124654.312801
1862 37220 -124599.239236
1863 37240 -124544.150518
1864 37260 -124489.046658
1865 37280 -124433.927667
1866 37300 -124378.793557
1867 37320 -124323.644340
1868 37340 -124268.480027
1869 37360 -124213.300629
1870 37380 -124158.106158
1871 37400 -124102.896626
1872 37420 -124047.672044
1873 37440 -123992.432423
1874 37460 -123937.177775
1875 37480 -123881.908111
1876 37500 -123826.623443
1877 37520 -123771.323782
1878 37540 -123716.009139
1879 37560 -123660.679525
1880 37580 -123605.334953
1881 37600 -123549.975433
1882 37620 -123494.600976
1883 37640 -123439.211594
1884 37660 -123383.807299
1885 37680 -123328.388100
1886 37700 -123272.954011
1887 37720 -123217.505041
1888 37740 -123162.041202
1889 37760 -123106.562506
1890 37780 -123051.068962
1891 37800 -122995.560584
1892 37820 -122940.037381
1893 37840 -122884.499364
1894 37860 -122828.946546
1895 37880 -122773.378937
1896 37900 -122717.796548
1897 37920 -122662.199390
1898 37940 -122606.587474
1899 37960 -122550.960812
1900 37980 -122495.319414
1901 38000 -122439.663291
1902 38020 -122383.992455
1903 38040 -122328.306916
1904 38060 -122272.606685
1905 38080 -122216.891773
1906 38100 -122161.162192
1907 38120 -122105.417951
1908 38140 -122049.659063
1909 38160 -121993.885538
1910 38180 -121938.097386
1911 38200 -121882.294619
1912 38220 -121826.477247
1913 38240 -121770.645282
1914 38260 -121714.798734
1915 38280 -121658.937614
1916 38300 -121603.061933
1917 38320 -121547.171701
1918 38340 -121491.266929
1919 38360 -121435.347629
1920 38380 -121379.413810
1921 38400 -121323.465484
1922 38420 -121267.502662
1923 38440 -121211.525353
1924 38460 -121155.533569
1925 38480 -121099.527320
1926 38500 -121043.506617
1927 38520 -120987.471470
1928 38540 -120931.421891
1929 38560 -120875.357890
1930 38580 -120819.279477
1931 38600 -120763.186663
1932 38620 -120707.079459
1933 38640 -120650.957875
1934 38660 -120594.821921
1935 38680 -120538.671609
1936 38700 -120482.506949
1937 38720 -120426.327951
1938 38740 -120370.134625
1939 38760 -120313.926983
1940 38780 -120257.705034
1941 38800 -120201.468790
1942 38820 -120145.218260
1943 38840 -120088.953455
1944 38860 -120032.674385
1945 38880 -119976.381062
1946 38900 -119920.073494
1947 38920 -119863.751693
1948 38940 -119807.415669
1949 38960 -119751.065432
1950 38980 -119694.700993
1951 39000 -119638.322361
1952 39020 -119581.929548
1953 39040 -119525.522563
1954 39060 -119469.101417
1955 39080 -119412.666120
1956 39100 -119356.216682
1957 39120 -119299.753114
1958 39140 -119243.275426
1959 39160 -119186.783627
1960 39180 -119130.277728
1961 39200 -119073.757740
1962 39220 -119017.223672
1963 39240 -118960.675535
1964 39260 -118904.113339
1965 39280 -118847.537093
1966 39300 -118790.946809
1967 39320 -118734.342495
1968 39340 -118677.724163
1969 39360 -118621.091822
1970 39380 -118564.445483
1971 39400 -118507.785155
1972 39420 -118451.110848
1973 39440 -118394.422573
1974 39460 -118337.720339
1975 39480 -118281.004157
1976 39500 -118224.274037
1977 39520 -118167.529988
1978 39540 -118110.772020
1979 39560 -118054.000143
1980 39580 -117997.214368
1981 39600 -117940.414705
1982 39620 -117883.601162
1983 39640 -117826.773751
1984 39660 -117769.932480
1985 39680 -117713.077360
1986 39700 -117656.208401
1987 39720 -117599.325613
1988 39740 -117542.429005
1989 39760 -117485.518587
1990 39780 -117428.594369
1991 39800 -117371.656361
1992 39820 -117314.704572
1993 39840 -117257.739013
1994 39860 -117200.759693
1995 39880 -117143.766622
1996 39900 -117086.759810
1997 39920 -117029.739266
1998 39940 -116972.705000
1999 39960 -116915.657022
2000 39980 -116858.595341
2001 40000 -116801.519968

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