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 34 of 40 · 500/page · 20000 rows next →
# nmargin_traced_6_40
16502 330020 1139141.804444
16503 330040 1139240.552005
16504 330060 1139339.300475
16505 330080 1139438.049853
16506 330100 1139536.800141
16507 330120 1139635.551336
16508 330140 1139734.303440
16509 330160 1139833.056452
16510 330180 1139931.810373
16511 330200 1140030.565202
16512 330220 1140129.320939
16513 330240 1140228.077584
16514 330260 1140326.835137
16515 330280 1140425.593598
16516 330300 1140524.352967
16517 330320 1140623.113244
16518 330340 1140721.874428
16519 330360 1140820.636520
16520 330380 1140919.399520
16521 330400 1141018.163428
16522 330420 1141116.928243
16523 330440 1141215.693965
16524 330460 1141314.460595
16525 330480 1141413.228132
16526 330500 1141511.996576
16527 330520 1141610.765928
16528 330540 1141709.536186
16529 330560 1141808.307352
16530 330580 1141907.079425
16531 330600 1142005.852404
16532 330620 1142104.626290
16533 330640 1142203.401084
16534 330660 1142302.176784
16535 330680 1142400.953390
16536 330700 1142499.730903
16537 330720 1142598.509323
16538 330740 1142697.288649
16539 330760 1142796.068882
16540 330780 1142894.850021
16541 330800 1142993.632066
16542 330820 1143092.415017
16543 330840 1143191.198875
16544 330860 1143289.983639
16545 330880 1143388.769308
16546 330900 1143487.555884
16547 330920 1143586.343365
16548 330940 1143685.131753
16549 330960 1143783.921046
16550 330980 1143882.711244
16551 331000 1143981.502349
16552 331020 1144080.294359
16553 331040 1144179.087274
16554 331060 1144277.881095
16555 331080 1144376.675821
16556 331100 1144475.471453
16557 331120 1144574.267990
16558 331140 1144673.065432
16559 331160 1144771.863779
16560 331180 1144870.663031
16561 331200 1144969.463188
16562 331220 1145068.264250
16563 331240 1145167.066217
16564 331260 1145265.869088
16565 331280 1145364.672865
16566 331300 1145463.477546
16567 331320 1145562.283131
16568 331340 1145661.089622
16569 331360 1145759.897016
16570 331380 1145858.705315
16571 331400 1145957.514519
16572 331420 1146056.324626
16573 331440 1146155.135638
16574 331460 1146253.947554
16575 331480 1146352.760374
16576 331500 1146451.574098
16577 331520 1146550.388726
16578 331540 1146649.204258
16579 331560 1146748.020694
16580 331580 1146846.838034
16581 331600 1146945.656277
16582 331620 1147044.475424
16583 331640 1147143.295474
16584 331660 1147242.116428
16585 331680 1147340.938285
16586 331700 1147439.761046
16587 331720 1147538.584710
16588 331740 1147637.409277
16589 331760 1147736.234748
16590 331780 1147835.061121
16591 331800 1147933.888398
16592 331820 1148032.716577
16593 331840 1148131.545660
16594 331860 1148230.375645
16595 331880 1148329.206533
16596 331900 1148428.038324
16597 331920 1148526.871018
16598 331940 1148625.704614
16599 331960 1148724.539113
16600 331980 1148823.374514
16601 332000 1148922.210817
16602 332020 1149021.048023
16603 332040 1149119.886132
16604 332060 1149218.725142
16605 332080 1149317.565055
16606 332100 1149416.405869
16607 332120 1149515.247586
16608 332140 1149614.090205
16609 332160 1149712.933725
16610 332180 1149811.778147
16611 332200 1149910.623472
16612 332220 1150009.469697
16613 332240 1150108.316825
16614 332260 1150207.164854
16615 332280 1150306.013785
16616 332300 1150404.863617
16617 332320 1150503.714350
16618 332340 1150602.565985
16619 332360 1150701.418521
16620 332380 1150800.271958
16621 332400 1150899.126296
16622 332420 1150997.981536
16623 332440 1151096.837676
16624 332460 1151195.694717
16625 332480 1151294.552659
16626 332500 1151393.411502
16627 332520 1151492.271246
16628 332540 1151591.131890
16629 332560 1151689.993436
16630 332580 1151788.855881
16631 332600 1151887.719227
16632 332620 1151986.583474
16633 332640 1152085.448620
16634 332660 1152184.314668
16635 332680 1152283.181615
16636 332700 1152382.049463
16637 332720 1152480.918210
16638 332740 1152579.787858
16639 332760 1152678.658406
16640 332780 1152777.529853
16641 332800 1152876.402201
16642 332820 1152975.275448
16643 332840 1153074.149595
16644 332860 1153173.024641
16645 332880 1153271.900588
16646 332900 1153370.777433
16647 332920 1153469.655178
16648 332940 1153568.533823
16649 332960 1153667.413367
16650 332980 1153766.293810
16651 333000 1153865.175153
16652 333020 1153964.057394
16653 333040 1154062.940535
16654 333060 1154161.824575
16655 333080 1154260.709513
16656 333100 1154359.595351
16657 333120 1154458.482087
16658 333140 1154557.369722
16659 333160 1154656.258256
16660 333180 1154755.147689
16661 333200 1154854.038020
16662 333220 1154952.929249
16663 333240 1155051.821377
16664 333260 1155150.714404
16665 333280 1155249.608328
16666 333300 1155348.503151
16667 333320 1155447.398872
16668 333340 1155546.295492
16669 333360 1155645.193009
16670 333380 1155744.091424
16671 333400 1155842.990738
16672 333420 1155941.890949
16673 333440 1156040.792058
16674 333460 1156139.694065
16675 333480 1156238.596969
16676 333500 1156337.500771
16677 333520 1156436.405471
16678 333540 1156535.311068
16679 333560 1156634.217562
16680 333580 1156733.124954
16681 333600 1156832.033244
16682 333620 1156930.942430
16683 333640 1157029.852514
16684 333660 1157128.763494
16685 333680 1157227.675372
16686 333700 1157326.588147
16687 333720 1157425.501819
16688 333740 1157524.416387
16689 333760 1157623.331853
16690 333780 1157722.248215
16691 333800 1157821.165474
16692 333820 1157920.083629
16693 333840 1158019.002681
16694 333860 1158117.922629
16695 333880 1158216.843474
16696 333900 1158315.765215
16697 333920 1158414.687853
16698 333940 1158513.611386
16699 333960 1158612.535816
16700 333980 1158711.461142
16701 334000 1158810.387364
16702 334020 1158909.314482
16703 334040 1159008.242496
16704 334060 1159107.171406
16705 334080 1159206.101211
16706 334100 1159305.031913
16707 334120 1159403.963510
16708 334140 1159502.896002
16709 334160 1159601.829390
16710 334180 1159700.763674
16711 334200 1159799.698852
16712 334220 1159898.634927
16713 334240 1159997.571896
16714 334260 1160096.509761
16715 334280 1160195.448521
16716 334300 1160294.388176
16717 334320 1160393.328726
16718 334340 1160492.270171
16719 334360 1160591.212511
16720 334380 1160690.155745
16721 334400 1160789.099875
16722 334420 1160888.044899
16723 334440 1160986.990818
16724 334460 1161085.937631
16725 334480 1161184.885339
16726 334500 1161283.833942
16727 334520 1161382.783438
16728 334540 1161481.733829
16729 334560 1161580.685115
16730 334580 1161679.637294
16731 334600 1161778.590368
16732 334620 1161877.544336
16733 334640 1161976.499198
16734 334660 1162075.454954
16735 334680 1162174.411603
16736 334700 1162273.369147
16737 334720 1162372.327584
16738 334740 1162471.286915
16739 334760 1162570.247140
16740 334780 1162669.208258
16741 334800 1162768.170270
16742 334820 1162867.133175
16743 334840 1162966.096973
16744 334860 1163065.061665
16745 334880 1163164.027250
16746 334900 1163262.993729
16747 334920 1163361.961100
16748 334940 1163460.929365
16749 334960 1163559.898522
16750 334980 1163658.868573
16751 335000 1163757.839516
16752 335020 1163856.811352
16753 335040 1163955.784081
16754 335060 1164054.757703
16755 335080 1164153.732217
16756 335100 1164252.707624
16757 335120 1164351.683923
16758 335140 1164450.661115
16759 335160 1164549.639199
16760 335180 1164648.618176
16761 335200 1164747.598044
16762 335220 1164846.578805
16763 335240 1164945.560458
16764 335260 1165044.543004
16765 335280 1165143.526441
16766 335300 1165242.510770
16767 335320 1165341.495991
16768 335340 1165440.482103
16769 335360 1165539.469108
16770 335380 1165638.457004
16771 335400 1165737.445792
16772 335420 1165836.435472
16773 335440 1165935.426042
16774 335460 1166034.417505
16775 335480 1166133.409859
16776 335500 1166232.403104
16777 335520 1166331.397240
16778 335540 1166430.392267
16779 335560 1166529.388186
16780 335580 1166628.384996
16781 335600 1166727.382696
16782 335620 1166826.381288
16783 335640 1166925.380771
16784 335660 1167024.381144
16785 335680 1167123.382408
16786 335700 1167222.384563
16787 335720 1167321.387608
16788 335740 1167420.391544
16789 335760 1167519.396370
16790 335780 1167618.402087
16791 335800 1167717.408695
16792 335820 1167816.416192
16793 335840 1167915.424580
16794 335860 1168014.433858
16795 335880 1168113.444026
16796 335900 1168212.455084
16797 335920 1168311.467033
16798 335940 1168410.479871
16799 335960 1168509.493599
16800 335980 1168608.508217
16801 336000 1168707.523724
16802 336020 1168806.540121
16803 336040 1168905.557408
16804 336060 1169004.575585
16805 336080 1169103.594651
16806 336100 1169202.614606
16807 336120 1169301.635451
16808 336140 1169400.657185
16809 336160 1169499.679808
16810 336180 1169598.703321
16811 336200 1169697.727723
16812 336220 1169796.753013
16813 336240 1169895.779193
16814 336260 1169994.806262
16815 336280 1170093.834219
16816 336300 1170192.863066
16817 336320 1170291.892801
16818 336340 1170390.923425
16819 336360 1170489.954937
16820 336380 1170588.987338
16821 336400 1170688.020627
16822 336420 1170787.054805
16823 336440 1170886.089872
16824 336460 1170985.125826
16825 336480 1171084.162669
16826 336500 1171183.200400
16827 336520 1171282.239020
16828 336540 1171381.278527
16829 336560 1171480.318922
16830 336580 1171579.360205
16831 336600 1171678.402377
16832 336620 1171777.445435
16833 336640 1171876.489382
16834 336660 1171975.534217
16835 336680 1172074.579939
16836 336700 1172173.626548
16837 336720 1172272.674045
16838 336740 1172371.722430
16839 336760 1172470.771702
16840 336780 1172569.821861
16841 336800 1172668.872908
16842 336820 1172767.924841
16843 336840 1172866.977662
16844 336860 1172966.031370
16845 336880 1173065.085965
16846 336900 1173164.141447
16847 336920 1173263.197816
16848 336940 1173362.255071
16849 336960 1173461.313214
16850 336980 1173560.372243
16851 337000 1173659.432158
16852 337020 1173758.492961
16853 337040 1173857.554649
16854 337060 1173956.617225
16855 337080 1174055.680686
16856 337100 1174154.745034
16857 337120 1174253.810268
16858 337140 1174352.876389
16859 337160 1174451.943395
16860 337180 1174551.011288
16861 337200 1174650.080067
16862 337220 1174749.149731
16863 337240 1174848.220282
16864 337260 1174947.291718
16865 337280 1175046.364040
16866 337300 1175145.437248
16867 337320 1175244.511342
16868 337340 1175343.586321
16869 337360 1175442.662186
16870 337380 1175541.738936
16871 337400 1175640.816571
16872 337420 1175739.895092
16873 337440 1175838.974498
16874 337460 1175938.054789
16875 337480 1176037.135966
16876 337500 1176136.218027
16877 337520 1176235.300974
16878 337540 1176334.384805
16879 337560 1176433.469522
16880 337580 1176532.555123
16881 337600 1176631.641609
16882 337620 1176730.728980
16883 337640 1176829.817235
16884 337660 1176928.906375
16885 337680 1177027.996400
16886 337700 1177127.087309
16887 337720 1177226.179103
16888 337740 1177325.271780
16889 337760 1177424.365343
16890 337780 1177523.459789
16891 337800 1177622.555119
16892 337820 1177721.651334
16893 337840 1177820.748433
16894 337860 1177919.846415
16895 337880 1178018.945282
16896 337900 1178118.045032
16897 337920 1178217.145666
16898 337940 1178316.247184
16899 337960 1178415.349586
16900 337980 1178514.452871
16901 338000 1178613.557040
16902 338020 1178712.662092
16903 338040 1178811.768028
16904 338060 1178910.874847
16905 338080 1179009.982549
16906 338100 1179109.091135
16907 338120 1179208.200603
16908 338140 1179307.310955
16909 338160 1179406.422190
16910 338180 1179505.534308
16911 338200 1179604.647309
16912 338220 1179703.761193
16913 338240 1179802.875959
16914 338260 1179901.991608
16915 338280 1180001.108140
16916 338300 1180100.225555
16917 338320 1180199.343852
16918 338340 1180298.463032
16919 338360 1180397.583094
16920 338380 1180496.704038
16921 338400 1180595.825865
16922 338420 1180694.948574
16923 338440 1180794.072165
16924 338460 1180893.196639
16925 338480 1180992.321994
16926 338500 1181091.448232
16927 338520 1181190.575351
16928 338540 1181289.703352
16929 338560 1181388.832235
16930 338580 1181487.962000
16931 338600 1181587.092647
16932 338620 1181686.224175
16933 338640 1181785.356585
16934 338660 1181884.489876
16935 338680 1181983.624049
16936 338700 1182082.759103
16937 338720 1182181.895039
16938 338740 1182281.031856
16939 338760 1182380.169554
16940 338780 1182479.308133
16941 338800 1182578.447593
16942 338820 1182677.587934
16943 338840 1182776.729156
16944 338860 1182875.871260
16945 338880 1182975.014244
16946 338900 1183074.158108
16947 338920 1183173.302854
16948 338940 1183272.448480
16949 338960 1183371.594987
16950 338980 1183470.742374
16951 339000 1183569.890642
16952 339020 1183669.039790
16953 339040 1183768.189819
16954 339060 1183867.340727
16955 339080 1183966.492516
16956 339100 1184065.645186
16957 339120 1184164.798735
16958 339140 1184263.953164
16959 339160 1184363.108474
16960 339180 1184462.264663
16961 339200 1184561.421732
16962 339220 1184660.579681
16963 339240 1184759.738510
16964 339260 1184858.898218
16965 339280 1184958.058806
16966 339300 1185057.220274
16967 339320 1185156.382621
16968 339340 1185255.545848
16969 339360 1185354.709954
16970 339380 1185453.874939
16971 339400 1185553.040803
16972 339420 1185652.207547
16973 339440 1185751.375170
16974 339460 1185850.543672
16975 339480 1185949.713052
16976 339500 1186048.883312
16977 339520 1186148.054451
16978 339540 1186247.226469
16979 339560 1186346.399365
16980 339580 1186445.573140
16981 339600 1186544.747794
16982 339620 1186643.923326
16983 339640 1186743.099737
16984 339660 1186842.277026
16985 339680 1186941.455193
16986 339700 1187040.634239
16987 339720 1187139.814164
16988 339740 1187238.994966
16989 339760 1187338.176647
16990 339780 1187437.359205
16991 339800 1187536.542642
16992 339820 1187635.726957
16993 339840 1187734.912150
16994 339860 1187834.098220
16995 339880 1187933.285168
16996 339900 1188032.472994
16997 339920 1188131.661698
16998 339940 1188230.851279
16999 339960 1188330.041738
17000 339980 1188429.233075
17001 340000 1188528.425288

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