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 32 of 40 · 500/page · 20000 rows next →
# nmargin_traced_6_40
15502 310020 1040860.284235
15503 310040 1040958.089039
15504 310060 1041055.894822
15505 310080 1041153.701583
15506 310100 1041251.509323
15507 310120 1041349.318041
15508 310140 1041447.127737
15509 310160 1041544.938410
15510 310180 1041642.750062
15511 310200 1041740.562692
15512 310220 1041838.376299
15513 310240 1041936.190885
15514 310260 1042034.006447
15515 310280 1042131.822988
15516 310300 1042229.640506
15517 310320 1042327.459001
15518 310340 1042425.278474
15519 310360 1042523.098924
15520 310380 1042620.920351
15521 310400 1042718.742756
15522 310420 1042816.566137
15523 310440 1042914.390496
15524 310460 1043012.215831
15525 310480 1043110.042143
15526 310500 1043207.869432
15527 310520 1043305.697698
15528 310540 1043403.526940
15529 310560 1043501.357159
15530 310580 1043599.188354
15531 310600 1043697.020526
15532 310620 1043794.853674
15533 310640 1043892.687798
15534 310660 1043990.522898
15535 310680 1044088.358975
15536 310700 1044186.196027
15537 310720 1044284.034056
15538 310740 1044381.873060
15539 310760 1044479.713040
15540 310780 1044577.553996
15541 310800 1044675.395927
15542 310820 1044773.238834
15543 310840 1044871.082717
15544 310860 1044968.927575
15545 310880 1045066.773408
15546 310900 1045164.620217
15547 310920 1045262.468000
15548 310940 1045360.316759
15549 310960 1045458.166493
15550 310980 1045556.017202
15551 311000 1045653.868886
15552 311020 1045751.721545
15553 311040 1045849.575178
15554 311060 1045947.429786
15555 311080 1046045.285369
15556 311100 1046143.141926
15557 311120 1046240.999457
15558 311140 1046338.857964
15559 311160 1046436.717444
15560 311180 1046534.577898
15561 311200 1046632.439327
15562 311220 1046730.301730
15563 311240 1046828.165107
15564 311260 1046926.029458
15565 311280 1047023.894782
15566 311300 1047121.761081
15567 311320 1047219.628353
15568 311340 1047317.496598
15569 311360 1047415.365818
15570 311380 1047513.236011
15571 311400 1047611.107177
15572 311420 1047708.979316
15573 311440 1047806.852429
15574 311460 1047904.726515
15575 311480 1048002.601575
15576 311500 1048100.477607
15577 311520 1048198.354612
15578 311540 1048296.232590
15579 311560 1048394.111541
15580 311580 1048491.991465
15581 311600 1048589.872361
15582 311620 1048687.754230
15583 311640 1048785.637071
15584 311660 1048883.520885
15585 311680 1048981.405672
15586 311700 1049079.291430
15587 311720 1049177.178161
15588 311740 1049275.065864
15589 311760 1049372.954539
15590 311780 1049470.844186
15591 311800 1049568.734805
15592 311820 1049666.626396
15593 311840 1049764.518959
15594 311860 1049862.412493
15595 311880 1049960.306999
15596 311900 1050058.202477
15597 311920 1050156.098926
15598 311940 1050253.996347
15599 311960 1050351.894739
15600 311980 1050449.794102
15601 312000 1050547.694436
15602 312020 1050645.595742
15603 312040 1050743.498018
15604 312060 1050841.401266
15605 312080 1050939.305484
15606 312100 1051037.210673
15607 312120 1051135.116833
15608 312140 1051233.023964
15609 312160 1051330.932065
15610 312180 1051428.841137
15611 312200 1051526.751180
15612 312220 1051624.662192
15613 312240 1051722.574175
15614 312260 1051820.487128
15615 312280 1051918.401052
15616 312300 1052016.315945
15617 312320 1052114.231809
15618 312340 1052212.148642
15619 312360 1052310.066446
15620 312380 1052407.985219
15621 312400 1052505.904962
15622 312420 1052603.825674
15623 312440 1052701.747356
15624 312460 1052799.670008
15625 312480 1052897.593629
15626 312500 1052995.518220
15627 312520 1053093.443779
15628 312540 1053191.370308
15629 312560 1053289.297806
15630 312580 1053387.226273
15631 312600 1053485.155709
15632 312620 1053583.086114
15633 312640 1053681.017488
15634 312660 1053778.949831
15635 312680 1053876.883142
15636 312700 1053974.817422
15637 312720 1054072.752671
15638 312740 1054170.688888
15639 312760 1054268.626073
15640 312780 1054366.564227
15641 312800 1054464.503349
15642 312820 1054562.443439
15643 312840 1054660.384497
15644 312860 1054758.326524
15645 312880 1054856.269518
15646 312900 1054954.213480
15647 312920 1055052.158410
15648 312940 1055150.104308
15649 312960 1055248.051173
15650 312980 1055345.999006
15651 313000 1055443.947807
15652 313020 1055541.897575
15653 313040 1055639.848310
15654 313060 1055737.800013
15655 313080 1055835.752683
15656 313100 1055933.706320
15657 313120 1056031.660924
15658 313140 1056129.616495
15659 313160 1056227.573033
15660 313180 1056325.530538
15661 313200 1056423.489010
15662 313220 1056521.448448
15663 313240 1056619.408853
15664 313260 1056717.370225
15665 313280 1056815.332563
15666 313300 1056913.295868
15667 313320 1057011.260139
15668 313340 1057109.225376
15669 313360 1057207.191580
15670 313380 1057305.158749
15671 313400 1057403.126885
15672 313420 1057501.095986
15673 313440 1057599.066054
15674 313460 1057697.037087
15675 313480 1057795.009087
15676 313500 1057892.982051
15677 313520 1057990.955982
15678 313540 1058088.930878
15679 313560 1058186.906740
15680 313580 1058284.883567
15681 313600 1058382.861359
15682 313620 1058480.840116
15683 313640 1058578.819839
15684 313660 1058676.800527
15685 313680 1058774.782180
15686 313700 1058872.764798
15687 313720 1058970.748380
15688 313740 1059068.732928
15689 313760 1059166.718440
15690 313780 1059264.704917
15691 313800 1059362.692359
15692 313820 1059460.680765
15693 313840 1059558.670135
15694 313860 1059656.660470
15695 313880 1059754.651770
15696 313900 1059852.644033
15697 313920 1059950.637261
15698 313940 1060048.631453
15699 313960 1060146.626608
15700 313980 1060244.622728
15701 314000 1060342.619812
15702 314020 1060440.617859
15703 314040 1060538.616870
15704 314060 1060636.616845
15705 314080 1060734.617784
15706 314100 1060832.619685
15707 314120 1060930.622551
15708 314140 1061028.626380
15709 314160 1061126.631172
15710 314180 1061224.636927
15711 314200 1061322.643645
15712 314220 1061420.651327
15713 314240 1061518.659971
15714 314260 1061616.669578
15715 314280 1061714.680149
15716 314300 1061812.691682
15717 314320 1061910.704178
15718 314340 1062008.717636
15719 314360 1062106.732057
15720 314380 1062204.747440
15721 314400 1062302.763786
15722 314420 1062400.781095
15723 314440 1062498.799365
15724 314460 1062596.818598
15725 314480 1062694.838793
15726 314500 1062792.859950
15727 314520 1062890.882068
15728 314540 1062988.905149
15729 314560 1063086.929192
15730 314580 1063184.954196
15731 314600 1063282.980163
15732 314620 1063381.007090
15733 314640 1063479.034980
15734 314660 1063577.063830
15735 314680 1063675.093643
15736 314700 1063773.124416
15737 314720 1063871.156151
15738 314740 1063969.188847
15739 314760 1064067.222504
15740 314780 1064165.257122
15741 314800 1064263.292702
15742 314820 1064361.329242
15743 314840 1064459.366743
15744 314860 1064557.405204
15745 314880 1064655.444627
15746 314900 1064753.485010
15747 314920 1064851.526353
15748 314940 1064949.568657
15749 314960 1065047.611921
15750 314980 1065145.656146
15751 315000 1065243.701331
15752 315020 1065341.747476
15753 315040 1065439.794581
15754 315060 1065537.842647
15755 315080 1065635.891672
15756 315100 1065733.941657
15757 315120 1065831.992602
15758 315140 1065930.044507
15759 315160 1066028.097371
15760 315180 1066126.151195
15761 315200 1066224.205979
15762 315220 1066322.261722
15763 315240 1066420.318424
15764 315260 1066518.376086
15765 315280 1066616.434707
15766 315300 1066714.494287
15767 315320 1066812.554826
15768 315340 1066910.616324
15769 315360 1067008.678781
15770 315380 1067106.742197
15771 315400 1067204.806572
15772 315420 1067302.871906
15773 315440 1067400.938198
15774 315460 1067499.005449
15775 315480 1067597.073658
15776 315500 1067695.142826
15777 315520 1067793.212952
15778 315540 1067891.284037
15779 315560 1067989.356080
15780 315580 1068087.429081
15781 315600 1068185.503040
15782 315620 1068283.577957
15783 315640 1068381.653832
15784 315660 1068479.730665
15785 315680 1068577.808455
15786 315700 1068675.887204
15787 315720 1068773.966910
15788 315740 1068872.047574
15789 315760 1068970.129195
15790 315780 1069068.211773
15791 315800 1069166.295309
15792 315820 1069264.379803
15793 315840 1069362.465253
15794 315860 1069460.551661
15795 315880 1069558.639026
15796 315900 1069656.727348
15797 315920 1069754.816626
15798 315940 1069852.906862
15799 315960 1069950.998054
15800 315980 1070049.090204
15801 316000 1070147.183309
15802 316020 1070245.277372
15803 316040 1070343.372391
15804 316060 1070441.468366
15805 316080 1070539.565298
15806 316100 1070637.663186
15807 316120 1070735.762030
15808 316140 1070833.861831
15809 316160 1070931.962587
15810 316180 1071030.064300
15811 316200 1071128.166968
15812 316220 1071226.270592
15813 316240 1071324.375172
15814 316260 1071422.480708
15815 316280 1071520.587200
15816 316300 1071618.694647
15817 316320 1071716.803049
15818 316340 1071814.912407
15819 316360 1071913.022721
15820 316380 1072011.133989
15821 316400 1072109.246213
15822 316420 1072207.359392
15823 316440 1072305.473527
15824 316460 1072403.588616
15825 316480 1072501.704660
15826 316500 1072599.821659
15827 316520 1072697.939613
15828 316540 1072796.058521
15829 316560 1072894.178384
15830 316580 1072992.299202
15831 316600 1073090.420974
15832 316620 1073188.543701
15833 316640 1073286.667382
15834 316660 1073384.792017
15835 316680 1073482.917607
15836 316700 1073581.044151
15837 316720 1073679.171648
15838 316740 1073777.300100
15839 316760 1073875.429506
15840 316780 1073973.559866
15841 316800 1074071.691179
15842 316820 1074169.823446
15843 316840 1074267.956667
15844 316860 1074366.090841
15845 316880 1074464.225969
15846 316900 1074562.362051
15847 316920 1074660.499085
15848 316940 1074758.637073
15849 316960 1074856.776015
15850 316980 1074954.915909
15851 317000 1075053.056757
15852 317020 1075151.198557
15853 317040 1075249.341310
15854 317060 1075347.485017
15855 317080 1075445.629676
15856 317100 1075543.775288
15857 317120 1075641.921852
15858 317140 1075740.069369
15859 317160 1075838.217839
15860 317180 1075936.367261
15861 317200 1076034.517635
15862 317220 1076132.668962
15863 317240 1076230.821241
15864 317260 1076328.974472
15865 317280 1076427.128656
15866 317300 1076525.283791
15867 317320 1076623.439878
15868 317340 1076721.596917
15869 317360 1076819.754908
15870 317380 1076917.913851
15871 317400 1077016.073745
15872 317420 1077114.234591
15873 317440 1077212.396388
15874 317460 1077310.559137
15875 317480 1077408.722837
15876 317500 1077506.887489
15877 317520 1077605.053091
15878 317540 1077703.219645
15879 317560 1077801.387150
15880 317580 1077899.555607
15881 317600 1077997.725014
15882 317620 1078095.895371
15883 317640 1078194.066680
15884 317660 1078292.238940
15885 317680 1078390.412150
15886 317700 1078488.586310
15887 317720 1078586.761422
15888 317740 1078684.937483
15889 317760 1078783.114496
15890 317780 1078881.292458
15891 317800 1078979.471371
15892 317820 1079077.651234
15893 317840 1079175.832046
15894 317860 1079274.013809
15895 317880 1079372.196522
15896 317900 1079470.380185
15897 317920 1079568.564798
15898 317940 1079666.750360
15899 317960 1079764.936872
15900 317980 1079863.124334
15901 318000 1079961.312745
15902 318020 1080059.502106
15903 318040 1080157.692416
15904 318060 1080255.883676
15905 318080 1080354.075884
15906 318100 1080452.269042
15907 318120 1080550.463149
15908 318140 1080648.658205
15909 318160 1080746.854210
15910 318180 1080845.051164
15911 318200 1080943.249067
15912 318220 1081041.447919
15913 318240 1081139.647719
15914 318260 1081237.848468
15915 318280 1081336.050165
15916 318300 1081434.252811
15917 318320 1081532.456405
15918 318340 1081630.660948
15919 318360 1081728.866439
15920 318380 1081827.072878
15921 318400 1081925.280265
15922 318420 1082023.488600
15923 318440 1082121.697884
15924 318460 1082219.908115
15925 318480 1082318.119294
15926 318500 1082416.331421
15927 318520 1082514.544495
15928 318540 1082612.758517
15929 318560 1082710.973487
15930 318580 1082809.189404
15931 318600 1082907.406269
15932 318620 1083005.624081
15933 318640 1083103.842840
15934 318660 1083202.062547
15935 318680 1083300.283200
15936 318700 1083398.504801
15937 318720 1083496.727349
15938 318740 1083594.950843
15939 318760 1083693.175285
15940 318780 1083791.400673
15941 318800 1083889.627008
15942 318820 1083987.854290
15943 318840 1084086.082518
15944 318860 1084184.311693
15945 318880 1084282.541814
15946 318900 1084380.772882
15947 318920 1084479.004895
15948 318940 1084577.237856
15949 318960 1084675.471762
15950 318980 1084773.706614
15951 319000 1084871.942413
15952 319020 1084970.179157
15953 319040 1085068.416847
15954 319060 1085166.655483
15955 319080 1085264.895065
15956 319100 1085363.135592
15957 319120 1085461.377065
15958 319140 1085559.619484
15959 319160 1085657.862848
15960 319180 1085756.107157
15961 319200 1085854.352412
15962 319220 1085952.598612
15963 319240 1086050.845757
15964 319260 1086149.093847
15965 319280 1086247.342882
15966 319300 1086345.592863
15967 319320 1086443.843788
15968 319340 1086542.095658
15969 319360 1086640.348472
15970 319380 1086738.602232
15971 319400 1086836.856936
15972 319420 1086935.112584
15973 319440 1087033.369177
15974 319460 1087131.626715
15975 319480 1087229.885197
15976 319500 1087328.144623
15977 319520 1087426.404993
15978 319540 1087524.666307
15979 319560 1087622.928566
15980 319580 1087721.191768
15981 319600 1087819.455914
15982 319620 1087917.721005
15983 319640 1088015.987039
15984 319660 1088114.254016
15985 319680 1088212.521938
15986 319700 1088310.790803
15987 319720 1088409.060611
15988 319740 1088507.331363
15989 319760 1088605.603058
15990 319780 1088703.875696
15991 319800 1088802.149278
15992 319820 1088900.423803
15993 319840 1088998.699271
15994 319860 1089096.975682
15995 319880 1089195.253036
15996 319900 1089293.531332
15997 319920 1089391.810572
15998 319940 1089490.090754
15999 319960 1089588.371879
16000 319980 1089686.653947
16001 320000 1089784.936957

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