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 6 of 40 · 500/page · 20000 rows next →
# nmargin_traced_6_40
2502 50020 -86661.509265
2503 50040 -86598.571242
2504 50060 -86535.623212
2505 50080 -86472.665179
2506 50100 -86409.697149
2507 50120 -86346.719128
2508 50140 -86283.731121
2509 50160 -86220.733134
2510 50180 -86157.725172
2511 50200 -86094.707240
2512 50220 -86031.679344
2513 50240 -85968.641491
2514 50260 -85905.593684
2515 50280 -85842.535929
2516 50300 -85779.468233
2517 50320 -85716.390600
2518 50340 -85653.303036
2519 50360 -85590.205547
2520 50380 -85527.098137
2521 50400 -85463.980812
2522 50420 -85400.853578
2523 50440 -85337.716441
2524 50460 -85274.569404
2525 50480 -85211.412475
2526 50500 -85148.245658
2527 50520 -85085.068959
2528 50540 -85021.882383
2529 50560 -84958.685935
2530 50580 -84895.479621
2531 50600 -84832.263447
2532 50620 -84769.037417
2533 50640 -84705.801538
2534 50660 -84642.555814
2535 50680 -84579.300250
2536 50700 -84516.034853
2537 50720 -84452.759628
2538 50740 -84389.474579
2539 50760 -84326.179712
2540 50780 -84262.875033
2541 50800 -84199.560547
2542 50820 -84136.236259
2543 50840 -84072.902174
2544 50860 -84009.558298
2545 50880 -83946.204637
2546 50900 -83882.841195
2547 50920 -83819.467977
2548 50940 -83756.084990
2549 50960 -83692.692238
2550 50980 -83629.289726
2551 51000 -83565.877461
2552 51020 -83502.455446
2553 51040 -83439.023688
2554 51060 -83375.582192
2555 51080 -83312.130963
2556 51100 -83248.670006
2557 51120 -83185.199326
2558 51140 -83121.718929
2559 51160 -83058.228820
2560 51180 -82994.729005
2561 51200 -82931.219487
2562 51220 -82867.700273
2563 51240 -82804.171369
2564 51260 -82740.632778
2565 51280 -82677.084506
2566 51300 -82613.526559
2567 51320 -82549.958942
2568 51340 -82486.381659
2569 51360 -82422.794717
2570 51380 -82359.198120
2571 51400 -82295.591873
2572 51420 -82231.975982
2573 51440 -82168.350451
2574 51460 -82104.715287
2575 51480 -82041.070493
2576 51500 -81977.416076
2577 51520 -81913.752040
2578 51540 -81850.078391
2579 51560 -81786.395134
2580 51580 -81722.702273
2581 51600 -81658.999814
2582 51620 -81595.287762
2583 51640 -81531.566123
2584 51660 -81467.834900
2585 51680 -81404.094101
2586 51700 -81340.343728
2587 51720 -81276.583788
2588 51740 -81212.814286
2589 51760 -81149.035227
2590 51780 -81085.246616
2591 51800 -81021.448457
2592 51820 -80957.640757
2593 51840 -80893.823519
2594 51860 -80829.996750
2595 51880 -80766.160454
2596 51900 -80702.314637
2597 51920 -80638.459302
2598 51940 -80574.594456
2599 51960 -80510.720104
2600 51980 -80446.836250
2601 52000 -80382.942899
2602 52020 -80319.040057
2603 52040 -80255.127729
2604 52060 -80191.205919
2605 52080 -80127.274633
2606 52100 -80063.333875
2607 52120 -79999.383651
2608 52140 -79935.423965
2609 52160 -79871.454823
2610 52180 -79807.476230
2611 52200 -79743.488190
2612 52220 -79679.490708
2613 52240 -79615.483790
2614 52260 -79551.467441
2615 52280 -79487.441665
2616 52300 -79423.406467
2617 52320 -79359.361853
2618 52340 -79295.307827
2619 52360 -79231.244395
2620 52380 -79167.171560
2621 52400 -79103.089329
2622 52420 -79038.997706
2623 52440 -78974.896696
2624 52460 -78910.786303
2625 52480 -78846.666534
2626 52500 -78782.537392
2627 52520 -78718.398883
2628 52540 -78654.251012
2629 52560 -78590.093783
2630 52580 -78525.927201
2631 52600 -78461.751272
2632 52620 -78397.565999
2633 52640 -78333.371389
2634 52660 -78269.167446
2635 52680 -78204.954174
2636 52700 -78140.731579
2637 52720 -78076.499666
2638 52740 -78012.258439
2639 52760 -77948.007903
2640 52780 -77883.748063
2641 52800 -77819.478924
2642 52820 -77755.200491
2643 52840 -77690.912769
2644 52860 -77626.615762
2645 52880 -77562.309475
2646 52900 -77497.993913
2647 52920 -77433.669082
2648 52940 -77369.334984
2649 52960 -77304.991627
2650 52980 -77240.639013
2651 53000 -77176.277149
2652 53020 -77111.906039
2653 53040 -77047.525688
2654 53060 -76983.136100
2655 53080 -76918.737280
2656 53100 -76854.329233
2657 53120 -76789.911964
2658 53140 -76725.485478
2659 53160 -76661.049779
2660 53180 -76596.604872
2661 53200 -76532.150762
2662 53220 -76467.687454
2663 53240 -76403.214952
2664 53260 -76338.733261
2665 53280 -76274.242387
2666 53300 -76209.742332
2667 53320 -76145.233103
2668 53340 -76080.714704
2669 53360 -76016.187140
2670 53380 -75951.650416
2671 53400 -75887.104535
2672 53420 -75822.549504
2673 53440 -75757.985326
2674 53460 -75693.412006
2675 53480 -75628.829549
2676 53500 -75564.237960
2677 53520 -75499.637244
2678 53540 -75435.027404
2679 53560 -75370.408447
2680 53580 -75305.780375
2681 53600 -75241.143195
2682 53620 -75176.496910
2683 53640 -75111.841526
2684 53660 -75047.177047
2685 53680 -74982.503478
2686 53700 -74917.820823
2687 53720 -74853.129087
2688 53740 -74788.428275
2689 53760 -74723.718391
2690 53780 -74658.999439
2691 53800 -74594.271426
2692 53820 -74529.534354
2693 53840 -74464.788230
2694 53860 -74400.033056
2695 53880 -74335.268839
2696 53900 -74270.495582
2697 53920 -74205.713291
2698 53940 -74140.921969
2699 53960 -74076.121622
2700 53980 -74011.312253
2701 54000 -73946.493869
2702 54020 -73881.666472
2703 54040 -73816.830068
2704 54060 -73751.984661
2705 54080 -73687.130256
2706 54100 -73622.266858
2707 54120 -73557.394471
2708 54140 -73492.513099
2709 54160 -73427.622747
2710 54180 -73362.723420
2711 54200 -73297.815122
2712 54220 -73232.897857
2713 54240 -73167.971631
2714 54260 -73103.036448
2715 54280 -73038.092312
2716 54300 -72973.139228
2717 54320 -72908.177200
2718 54340 -72843.206233
2719 54360 -72778.226331
2720 54380 -72713.237500
2721 54400 -72648.239742
2722 54420 -72583.233064
2723 54440 -72518.217468
2724 54460 -72453.192961
2725 54480 -72388.159546
2726 54500 -72323.117228
2727 54520 -72258.066011
2728 54540 -72193.005900
2729 54560 -72127.936899
2730 54580 -72062.859012
2731 54600 -71997.772245
2732 54620 -71932.676602
2733 54640 -71867.572086
2734 54660 -71802.458703
2735 54680 -71737.336457
2736 54700 -71672.205353
2737 54720 -71607.065394
2738 54740 -71541.916585
2739 54760 -71476.758931
2740 54780 -71411.592437
2741 54800 -71346.417106
2742 54820 -71281.232942
2743 54840 -71216.039951
2744 54860 -71150.838137
2745 54880 -71085.627504
2746 54900 -71020.408057
2747 54920 -70955.179800
2748 54940 -70889.942737
2749 54960 -70824.696872
2750 54980 -70759.442211
2751 55000 -70694.178758
2752 55020 -70628.906516
2753 55040 -70563.625490
2754 55060 -70498.335686
2755 55080 -70433.037106
2756 55100 -70367.729755
2757 55120 -70302.413639
2758 55140 -70237.088760
2759 55160 -70171.755124
2760 55180 -70106.412734
2761 55200 -70041.061596
2762 55220 -69975.701713
2763 55240 -69910.333090
2764 55260 -69844.955731
2765 55280 -69779.569640
2766 55300 -69714.174823
2767 55320 -69648.771282
2768 55340 -69583.359023
2769 55360 -69517.938049
2770 55380 -69452.508365
2771 55400 -69387.069976
2772 55420 -69321.622885
2773 55440 -69256.167098
2774 55460 -69190.702617
2775 55480 -69125.229448
2776 55500 -69059.747595
2777 55520 -68994.257062
2778 55540 -68928.757853
2779 55560 -68863.249972
2780 55580 -68797.733425
2781 55600 -68732.208215
2782 55620 -68666.674346
2783 55640 -68601.131823
2784 55660 -68535.580650
2785 55680 -68470.020830
2786 55700 -68404.452370
2787 55720 -68338.875272
2788 55740 -68273.289540
2789 55760 -68207.695180
2790 55780 -68142.092196
2791 55800 -68076.480591
2792 55820 -68010.860369
2793 55840 -67945.231536
2794 55860 -67879.594095
2795 55880 -67813.948051
2796 55900 -67748.293407
2797 55920 -67682.630168
2798 55940 -67616.958338
2799 55960 -67551.277921
2800 55980 -67485.588922
2801 56000 -67419.891344
2802 56020 -67354.185193
2803 56040 -67288.470471
2804 56060 -67222.747183
2805 56080 -67157.015334
2806 56100 -67091.274928
2807 56120 -67025.525968
2808 56140 -66959.768459
2809 56160 -66894.002405
2810 56180 -66828.227810
2811 56200 -66762.444679
2812 56220 -66696.653015
2813 56240 -66630.852823
2814 56260 -66565.044107
2815 56280 -66499.226870
2816 56300 -66433.401118
2817 56320 -66367.566854
2818 56340 -66301.724082
2819 56360 -66235.872807
2820 56380 -66170.013032
2821 56400 -66104.144762
2822 56420 -66038.268001
2823 56440 -65972.382752
2824 56460 -65906.489021
2825 56480 -65840.586811
2826 56500 -65774.676126
2827 56520 -65708.756970
2828 56540 -65642.829348
2829 56560 -65576.893264
2830 56580 -65510.948721
2831 56600 -65444.995723
2832 56620 -65379.034276
2833 56640 -65313.064382
2834 56660 -65247.086046
2835 56680 -65181.099272
2836 56700 -65115.104064
2837 56720 -65049.100426
2838 56740 -64983.088363
2839 56760 -64917.067877
2840 56780 -64851.038974
2841 56800 -64785.001657
2842 56820 -64718.955930
2843 56840 -64652.901798
2844 56860 -64586.839265
2845 56880 -64520.768333
2846 56900 -64454.689009
2847 56920 -64388.601294
2848 56940 -64322.505194
2849 56960 -64256.400713
2850 56980 -64190.287855
2851 57000 -64124.166623
2852 57020 -64058.037021
2853 57040 -63991.899054
2854 57060 -63925.752726
2855 57080 -63859.598040
2856 57100 -63793.435001
2857 57120 -63727.263612
2858 57140 -63661.083878
2859 57160 -63594.895803
2860 57180 -63528.699390
2861 57200 -63462.494644
2862 57220 -63396.281568
2863 57240 -63330.060166
2864 57260 -63263.830443
2865 57280 -63197.592402
2866 57300 -63131.346048
2867 57320 -63065.091384
2868 57340 -62998.828414
2869 57360 -62932.557143
2870 57380 -62866.277573
2871 57400 -62799.989710
2872 57420 -62733.693556
2873 57440 -62667.389117
2874 57460 -62601.076396
2875 57480 -62534.755396
2876 57500 -62468.426122
2877 57520 -62402.088578
2878 57540 -62335.742767
2879 57560 -62269.388694
2880 57580 -62203.026362
2881 57600 -62136.655776
2882 57620 -62070.276939
2883 57640 -62003.889855
2884 57660 -61937.494528
2885 57680 -61871.090962
2886 57700 -61804.679161
2887 57720 -61738.259129
2888 57740 -61671.830869
2889 57760 -61605.394385
2890 57780 -61538.949683
2891 57800 -61472.496764
2892 57820 -61406.035633
2893 57840 -61339.566295
2894 57860 -61273.088752
2895 57880 -61206.603009
2896 57900 -61140.109070
2897 57920 -61073.606938
2898 57940 -61007.096617
2899 57960 -60940.578112
2900 57980 -60874.051425
2901 58000 -60807.516561
2902 58020 -60740.973524
2903 58040 -60674.422318
2904 58060 -60607.862946
2905 58080 -60541.295412
2906 58100 -60474.719720
2907 58120 -60408.135874
2908 58140 -60341.543877
2909 58160 -60274.943734
2910 58180 -60208.335449
2911 58200 -60141.719024
2912 58220 -60075.094464
2913 58240 -60008.461773
2914 58260 -59941.820955
2915 58280 -59875.172013
2916 58300 -59808.514950
2917 58320 -59741.849772
2918 58340 -59675.176482
2919 58360 -59608.495083
2920 58380 -59541.805579
2921 58400 -59475.107974
2922 58420 -59408.402272
2923 58440 -59341.688477
2924 58460 -59274.966592
2925 58480 -59208.236621
2926 58500 -59141.498568
2927 58520 -59074.752436
2928 58540 -59007.998230
2929 58560 -58941.235953
2930 58580 -58874.465609
2931 58600 -58807.687202
2932 58620 -58740.900735
2933 58640 -58674.106212
2934 58660 -58607.303637
2935 58680 -58540.493014
2936 58700 -58473.674346
2937 58720 -58406.847637
2938 58740 -58340.012891
2939 58760 -58273.170112
2940 58780 -58206.319302
2941 58800 -58139.460467
2942 58820 -58072.593609
2943 58840 -58005.718733
2944 58860 -57938.835842
2945 58880 -57871.944939
2946 58900 -57805.046029
2947 58920 -57738.139115
2948 58940 -57671.224201
2949 58960 -57604.301291
2950 58980 -57537.370388
2951 59000 -57470.431496
2952 59020 -57403.484618
2953 59040 -57336.529759
2954 59060 -57269.566922
2955 59080 -57202.596110
2956 59100 -57135.617328
2957 59120 -57068.630579
2958 59140 -57001.635866
2959 59160 -56934.633194
2960 59180 -56867.622566
2961 59200 -56800.603985
2962 59220 -56733.577456
2963 59240 -56666.542982
2964 59260 -56599.500566
2965 59280 -56532.450212
2966 59300 -56465.391924
2967 59320 -56398.325706
2968 59340 -56331.251561
2969 59360 -56264.169493
2970 59380 -56197.079505
2971 59400 -56129.981601
2972 59420 -56062.875785
2973 59440 -55995.762060
2974 59460 -55928.640430
2975 59480 -55861.510898
2976 59500 -55794.373468
2977 59520 -55727.228144
2978 59540 -55660.074930
2979 59560 -55592.913828
2980 59580 -55525.744843
2981 59600 -55458.567978
2982 59620 -55391.383237
2983 59640 -55324.190623
2984 59660 -55256.990140
2985 59680 -55189.781791
2986 59700 -55122.565580
2987 59720 -55055.341511
2988 59740 -54988.109587
2989 59760 -54920.869812
2990 59780 -54853.622189
2991 59800 -54786.366723
2992 59820 -54719.103415
2993 59840 -54651.832271
2994 59860 -54584.553293
2995 59880 -54517.266485
2996 59900 -54449.971851
2997 59920 -54382.669394
2998 59940 -54315.359118
2999 59960 -54248.041026
3000 59980 -54180.715122
3001 60000 -54113.381410

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