Current task: —

E-029-convexity.py

Experiments: E-029 · script updated 08-19-2026

E-029-convexity.csv — 429.7 KB, updated 08-19-2026

← prev page 36 of 40 · 500/page · 20000 rows next →
# nmargin_tilde
17502 350020 1237727.670576
17503 350040 1237827.295372
17504 350060 1237926.921017
17505 350080 1238026.547509
17506 350100 1238126.174849
17507 350120 1238225.803036
17508 350140 1238325.432071
17509 350160 1238425.061954
17510 350180 1238524.692684
17511 350200 1238624.324261
17512 350220 1238723.956686
17513 350240 1238823.589958
17514 350260 1238923.224077
17515 350280 1239022.859043
17516 350300 1239122.494857
17517 350320 1239222.131517
17518 350340 1239321.769025
17519 350360 1239421.407379
17520 350380 1239521.046580
17521 350400 1239620.686628
17522 350420 1239720.327523
17523 350440 1239819.969265
17524 350460 1239919.611853
17525 350480 1240019.255288
17526 350500 1240118.899570
17527 350520 1240218.544697
17528 350540 1240318.190672
17529 350560 1240417.837492
17530 350580 1240517.485159
17531 350600 1240617.133673
17532 350620 1240716.783032
17533 350640 1240816.433238
17534 350660 1240916.084289
17535 350680 1241015.736187
17536 350700 1241115.388931
17537 350720 1241215.042520
17538 350740 1241314.696956
17539 350760 1241414.352237
17540 350780 1241514.008364
17541 350800 1241613.665337
17542 350820 1241713.323155
17543 350840 1241812.981819
17544 350860 1241912.641328
17545 350880 1242012.301683
17546 350900 1242111.962884
17547 350920 1242211.624929
17548 350940 1242311.287820
17549 350960 1242410.951556
17550 350980 1242510.616138
17551 351000 1242610.281564
17552 351020 1242709.947836
17553 351040 1242809.614952
17554 351060 1242909.282914
17555 351080 1243008.951720
17556 351100 1243108.621371
17557 351120 1243208.291867
17558 351140 1243307.963208
17559 351160 1243407.635393
17560 351180 1243507.308423
17561 351200 1243606.982298
17562 351220 1243706.657017
17563 351240 1243806.332580
17564 351260 1243906.008988
17565 351280 1244005.686241
17566 351300 1244105.364337
17567 351320 1244205.043278
17568 351340 1244304.723063
17569 351360 1244404.403692
17570 351380 1244504.085165
17571 351400 1244603.767482
17572 351420 1244703.450643
17573 351440 1244803.134647
17574 351460 1244902.819496
17575 351480 1245002.505188
17576 351500 1245102.191725
17577 351520 1245201.879104
17578 351540 1245301.567328
17579 351560 1245401.256395
17580 351580 1245500.946305
17581 351600 1245600.637059
17582 351620 1245700.328656
17583 351640 1245800.021097
17584 351660 1245899.714380
17585 351680 1245999.408507
17586 351700 1246099.103477
17587 351720 1246198.799291
17588 351740 1246298.495947
17589 351760 1246398.193446
17590 351780 1246497.891788
17591 351800 1246597.590973
17592 351820 1246697.291001
17593 351840 1246796.991871
17594 351860 1246896.693585
17595 351880 1246996.396141
17596 351900 1247096.099539
17597 351920 1247195.803780
17598 351940 1247295.508863
17599 351960 1247395.214789
17600 351980 1247494.921557
17601 352000 1247594.629168
17602 352020 1247694.337621
17603 352040 1247794.046916
17604 352060 1247893.757053
17605 352080 1247993.468032
17606 352100 1248093.179853
17607 352120 1248192.892516
17608 352140 1248292.606021
17609 352160 1248392.320368
17610 352180 1248492.035557
17611 352200 1248591.751587
17612 352220 1248691.468459
17613 352240 1248791.186173
17614 352260 1248890.904728
17615 352280 1248990.624125
17616 352300 1249090.344364
17617 352320 1249190.065443
17618 352340 1249289.787364
17619 352360 1249389.510127
17620 352380 1249489.233730
17621 352400 1249588.958175
17622 352420 1249688.683461
17623 352440 1249788.409588
17624 352460 1249888.136555
17625 352480 1249987.864364
17626 352500 1250087.593014
17627 352520 1250187.322505
17628 352540 1250287.052836
17629 352560 1250386.784008
17630 352580 1250486.516021
17631 352600 1250586.248874
17632 352620 1250685.982568
17633 352640 1250785.717103
17634 352660 1250885.452478
17635 352680 1250985.188693
17636 352700 1251084.925749
17637 352720 1251184.663645
17638 352740 1251284.402381
17639 352760 1251384.141957
17640 352780 1251483.882373
17641 352800 1251583.623630
17642 352820 1251683.365726
17643 352840 1251783.108663
17644 352860 1251882.852439
17645 352880 1251982.597055
17646 352900 1252082.342511
17647 352920 1252182.088807
17648 352940 1252281.835942
17649 352960 1252381.583917
17650 352980 1252481.332731
17651 353000 1252581.082385
17652 353020 1252680.832879
17653 353040 1252780.584212
17654 353060 1252880.336384
17655 353080 1252980.089395
17656 353100 1253079.843246
17657 353120 1253179.597935
17658 353140 1253279.353464
17659 353160 1253379.109832
17660 353180 1253478.867039
17661 353200 1253578.625085
17662 353220 1253678.383970
17663 353240 1253778.143693
17664 353260 1253877.904256
17665 353280 1253977.665657
17666 353300 1254077.427896
17667 353320 1254177.190975
17668 353340 1254276.954891
17669 353360 1254376.719647
17670 353380 1254476.485241
17671 353400 1254576.251673
17672 353420 1254676.018943
17673 353440 1254775.787052
17674 353460 1254875.555999
17675 353480 1254975.325784
17676 353500 1255075.096407
17677 353520 1255174.867869
17678 353540 1255274.640168
17679 353560 1255374.413305
17680 353580 1255474.187280
17681 353600 1255573.962093
17682 353620 1255673.737744
17683 353640 1255773.514232
17684 353660 1255873.291558
17685 353680 1255973.069722
17686 353700 1256072.848723
17687 353720 1256172.628562
17688 353740 1256272.409238
17689 353760 1256372.190751
17690 353780 1256471.973102
17691 353800 1256571.756290
17692 353820 1256671.540315
17693 353840 1256771.325178
17694 353860 1256871.110877
17695 353880 1256970.897414
17696 353900 1257070.684787
17697 353920 1257170.472998
17698 353940 1257270.262045
17699 353960 1257370.051929
17700 353980 1257469.842650
17701 354000 1257569.634208
17702 354020 1257669.426602
17703 354040 1257769.219833
17704 354060 1257869.013901
17705 354080 1257968.808805
17706 354100 1258068.604545
17707 354120 1258168.401122
17708 354140 1258268.198535
17709 354160 1258367.996784
17710 354180 1258467.795870
17711 354200 1258567.595791
17712 354220 1258667.396549
17713 354240 1258767.198143
17714 354260 1258867.000573
17715 354280 1258966.803839
17716 354300 1259066.607940
17717 354320 1259166.412878
17718 354340 1259266.218651
17719 354360 1259366.025260
17720 354380 1259465.832705
17721 354400 1259565.640985
17722 354420 1259665.450101
17723 354440 1259765.260052
17724 354460 1259865.070839
17725 354480 1259964.882461
17726 354500 1260064.694918
17727 354520 1260164.508211
17728 354540 1260264.322339
17729 354560 1260364.137302
17730 354580 1260463.953100
17731 354600 1260563.769733
17732 354620 1260663.587201
17733 354640 1260763.405504
17734 354660 1260863.224642
17735 354680 1260963.044615
17736 354700 1261062.865423
17737 354720 1261162.687065
17738 354740 1261262.509542
17739 354760 1261362.332854
17740 354780 1261462.157000
17741 354800 1261561.981980
17742 354820 1261661.807795
17743 354840 1261761.634445
17744 354860 1261861.461929
17745 354880 1261961.290247
17746 354900 1262061.119399
17747 354920 1262160.949385
17748 354940 1262260.780206
17749 354960 1262360.611860
17750 354980 1262460.444349
17751 355000 1262560.277671
17752 355020 1262660.111828
17753 355040 1262759.946818
17754 355060 1262859.782642
17755 355080 1262959.619300
17756 355100 1263059.456791
17757 355120 1263159.295116
17758 355140 1263259.134275
17759 355160 1263358.974267
17760 355180 1263458.815092
17761 355200 1263558.656751
17762 355220 1263658.499244
17763 355240 1263758.342569
17764 355260 1263858.186728
17765 355280 1263958.031720
17766 355300 1264057.877545
17767 355320 1264157.724203
17768 355340 1264257.571694
17769 355360 1264357.420018
17770 355380 1264457.269175
17771 355400 1264557.119165
17772 355420 1264656.969987
17773 355440 1264756.821643
17774 355460 1264856.674131
17775 355480 1264956.527451
17776 355500 1265056.381604
17777 355520 1265156.236590
17778 355540 1265256.092408
17779 355560 1265355.949059
17780 355580 1265455.806542
17781 355600 1265555.664857
17782 355620 1265655.524004
17783 355640 1265755.383984
17784 355660 1265855.244795
17785 355680 1265955.106439
17786 355700 1266054.968915
17787 355720 1266154.832223
17788 355740 1266254.696362
17789 355760 1266354.561334
17790 355780 1266454.427137
17791 355800 1266554.293772
17792 355820 1266654.161239
17793 355840 1266754.029537
17794 355860 1266853.898667
17795 355880 1266953.768628
17796 355900 1267053.639421
17797 355920 1267153.511046
17798 355940 1267253.383501
17799 355960 1267353.256788
17800 355980 1267453.130906
17801 356000 1267553.005856
17802 356020 1267652.881636
17803 356040 1267752.758248
17804 356060 1267852.635691
17805 356080 1267952.513964
17806 356100 1268052.393069
17807 356120 1268152.273004
17808 356140 1268252.153770
17809 356160 1268352.035367
17810 356180 1268451.917795
17811 356200 1268551.801053
17812 356220 1268651.685142
17813 356240 1268751.570062
17814 356260 1268851.455812
17815 356280 1268951.342392
17816 356300 1269051.229803
17817 356320 1269151.118044
17818 356340 1269251.007115
17819 356360 1269350.897016
17820 356380 1269450.787748
17821 356400 1269550.679310
17822 356420 1269650.571701
17823 356440 1269750.464923
17824 356460 1269850.358975
17825 356480 1269950.253856
17826 356500 1270050.149568
17827 356520 1270150.046109
17828 356540 1270249.943480
17829 356560 1270349.841680
17830 356580 1270449.740710
17831 356600 1270549.640570
17832 356620 1270649.541259
17833 356640 1270749.442778
17834 356660 1270849.345126
17835 356680 1270949.248303
17836 356700 1271049.152310
17837 356720 1271149.057145
17838 356740 1271248.962810
17839 356760 1271348.869305
17840 356780 1271448.776628
17841 356800 1271548.684780
17842 356820 1271648.593761
17843 356840 1271748.503571
17844 356860 1271848.414210
17845 356880 1271948.325677
17846 356900 1272048.237974
17847 356920 1272148.151099
17848 356940 1272248.065052
17849 356960 1272347.979835
17850 356980 1272447.895445
17851 357000 1272547.811884
17852 357020 1272647.729152
17853 357040 1272747.647248
17854 357060 1272847.566172
17855 357080 1272947.485925
17856 357100 1273047.406505
17857 357120 1273147.327914
17858 357140 1273247.250151
17859 357160 1273347.173216
17860 357180 1273447.097109
17861 357200 1273547.021829
17862 357220 1273646.947378
17863 357240 1273746.873754
17864 357260 1273846.800959
17865 357280 1273946.728990
17866 357300 1274046.657850
17867 357320 1274146.587537
17868 357340 1274246.518052
17869 357360 1274346.449394
17870 357380 1274446.381563
17871 357400 1274546.314560
17872 357420 1274646.248384
17873 357440 1274746.183036
17874 357460 1274846.118514
17875 357480 1274946.054820
17876 357500 1275045.991953
17877 357520 1275145.929913
17878 357540 1275245.868700
17879 357560 1275345.808314
17880 357580 1275445.748755
17881 357600 1275545.690022
17882 357620 1275645.632117
17883 357640 1275745.575038
17884 357660 1275845.518785
17885 357680 1275945.463360
17886 357700 1276045.408761
17887 357720 1276145.354988
17888 357740 1276245.302042
17889 357760 1276345.249922
17890 357780 1276445.198629
17891 357800 1276545.148161
17892 357820 1276645.098521
17893 357840 1276745.049706
17894 357860 1276845.001717
17895 357880 1276944.954555
17896 357900 1277044.908218
17897 357920 1277144.862707
17898 357940 1277244.818023
17899 357960 1277344.774164
17900 357980 1277444.731131
17901 358000 1277544.688924
17902 358020 1277644.647542
17903 358040 1277744.606986
17904 358060 1277844.567256
17905 358080 1277944.528351
17906 358100 1278044.490271
17907 358120 1278144.453017
17908 358140 1278244.416589
17909 358160 1278344.380985
17910 358180 1278444.346207
17911 358200 1278544.312254
17912 358220 1278644.279127
17913 358240 1278744.246824
17914 358260 1278844.215346
17915 358280 1278944.184694
17916 358300 1279044.154866
17917 358320 1279144.125863
17918 358340 1279244.097685
17919 358360 1279344.070332
17920 358380 1279444.043803
17921 358400 1279544.018100
17922 358420 1279643.993220
17923 358440 1279743.969166
17924 358460 1279843.945935
17925 358480 1279943.923530
17926 358500 1280043.901948
17927 358520 1280143.881191
17928 358540 1280243.861258
17929 358560 1280343.842150
17930 358580 1280443.823866
17931 358600 1280543.806405
17932 358620 1280643.789769
17933 358640 1280743.773957
17934 358660 1280843.758969
17935 358680 1280943.744804
17936 358700 1281043.731464
17937 358720 1281143.718947
17938 358740 1281243.707254
17939 358760 1281343.696385
17940 358780 1281443.686340
17941 358800 1281543.677118
17942 358820 1281643.668719
17943 358840 1281743.661144
17944 358860 1281843.654392
17945 358880 1281943.648464
17946 358900 1282043.643359
17947 358920 1282143.639078
17948 358940 1282243.635619
17949 358960 1282343.632984
17950 358980 1282443.631172
17951 359000 1282543.630182
17952 359020 1282643.630016
17953 359040 1282743.630673
17954 359060 1282843.632153
17955 359080 1282943.634455
17956 359100 1283043.637580
17957 359120 1283143.641528
17958 359140 1283243.646299
17959 359160 1283343.651892
17960 359180 1283443.658308
17961 359200 1283543.665546
17962 359220 1283643.673607
17963 359240 1283743.682490
17964 359260 1283843.692195
17965 359280 1283943.702723
17966 359300 1284043.714073
17967 359320 1284143.726245
17968 359340 1284243.739239
17969 359360 1284343.753056
17970 359380 1284443.767694
17971 359400 1284543.783154
17972 359420 1284643.799437
17973 359440 1284743.816541
17974 359460 1284843.834467
17975 359480 1284943.853214
17976 359500 1285043.872784
17977 359520 1285143.893175
17978 359540 1285243.914387
17979 359560 1285343.936421
17980 359580 1285443.959277
17981 359600 1285543.982954
17982 359620 1285644.007452
17983 359640 1285744.032772
17984 359660 1285844.058913
17985 359680 1285944.085875
17986 359700 1286044.113659
17987 359720 1286144.142263
17988 359740 1286244.171689
17989 359760 1286344.201935
17990 359780 1286444.233003
17991 359800 1286544.264891
17992 359820 1286644.297600
17993 359840 1286744.331130
17994 359860 1286844.365481
17995 359880 1286944.400653
17996 359900 1287044.436645
17997 359920 1287144.473457
17998 359940 1287244.511090
17999 359960 1287344.549544
18000 359980 1287444.588818
18001 360000 1287544.628912

E-029-convexity.json — 2.9 KB, updated 08-19-2026

JSON sidecar (click to expand)
{
  "experiment": "E-029",
  "task": "4.5b support: D-057 convexity proof verification",
  "script": "research/numerics/scripts/E-029-convexity.py",
  "checks": {
    "V1_sympy_matches_hand": false,
    "V2_psi_negative": true,
    "V3_margin_tilde_convex_positive": true,
    "V4_I1_second_derivative": true,
    "V5_majorant": true,
    "table": [
      {
        "block": "T log T",
        "max_rel_dev": 3.86713266584926e-16,
        "max_abs_dev": 1.1102230246251565e-16,
        "psi_max_on_grid": -9.278201041106209e-12,
        "negative_everywhere": true
      },
      {
        "block": "T",
        "max_rel_dev": 0.0,
        "max_abs_dev": 0.0,
        "psi_max_on_grid": -3.225806451613944e-13,
        "negative_everywhere": true
      },
      {
        "block": "log T",
        "max_rel_dev": 2.884096233990709e-16,
        "max_abs_dev": 1.3877787807814457e-17,
        "psi_max_on_grid": -2.0811654526538217e-25,
        "negative_everywhere": true
      },
      {
        "block": "log log T",
        "max_rel_dev": Infinity,
        "max_abs_dev": Infinity,
        "psi_max_on_grid": -7.361493795231685e-27,
        "negative_everywhere": true
      },
      {
        "block": "T L1",
        "max_rel_dev": 4.18537251328277e-16,
        "max_abs_dev": 1.1102230246251565e-16,
        "psi_max_on_grid": -9.278201041106209e-12,
        "negative_everywhere": true
      },
      {
        "block": "T L2",
        "max_rel_dev": 4.87560538773749e-16,
        "max_abs_dev": 4.163336342344337e-17,
        "psi_max_on_grid": -1.0839608294029891e-12,
        "negative_everywhere": true
      },
      {
        "block": "L1^2",
        "max_rel_dev": 3.8295728938905445e-16,
        "max_abs_dev": 1.3877787807814457e-17,
        "psi_max_on_grid": -1.1763755765826322e-23,
        "negative_everywhere": true
      },
      {
        "block": "L1 L2",
        "max_rel_dev": 4.506079009424732e-16,
        "max_abs_dev": 1.3877787807814457e-17,
        "psi_max_on_grid": -9.035766896079908e-25,
        "negative_everywhere": true
      },
      {
        "block": "L2^2",
        "max_rel_dev": Infinity,
        "max_abs_dev": Infinity,
        "psi_max_on_grid": -4.920397462312061e-26,
        "negative_everywhere": true
      },
      {
        "block": "L1",
        "max_rel_dev": 2.2639034786574087e-16,
        "max_abs_dev": 6.938893903907228e-18,
        "psi_max_on_grid": -2.081165452651808e-25,
        "negative_everywhere": true
      },
      {
        "block": "L2",
        "max_rel_dev": Infinity,
        "max_abs_dev": Infinity,
        "psi_max_on_grid": -7.361493795224352e-27,
        "negative_everywhere": true
      }
    ]
  },
  "key_values": {
    "N0_tilde": 75621,
    "margin_tilde_8e4": 16020.1971966516,
    "margin_tilde_prime_8e4": 3.6877762759686448,
    "max_2n_B4d2": 0.18932637317273204
  },
  "elapsed_seconds": 1.0
}

Source code

Python script (click to expand)
"""E-029 — task 4.5b support: D-057 convexity proof verification.

  V1. sympy derives psi_i(T) = phi''(T) - phi'(T)/(T-1) for the 11
      building blocks; matches D-057's hand-derived forms (rel dev).
  V2. psi_i(T) < 0 on T in [T0, 3.1e12] (log grid) — supports the
      hand sign arguments.
  V3. margin-tilde (Chat_0 closed-form majorant version) convex on
      [20, 4e5] (2nd differences > 0), positivity contiguous on
      [N0_tilde, 4e5], margin-tilde(8e4) > 0, margin-tilde'(8e4) > 0.
  V4. 2n|B4''(n)| < 1 on [20, 1e4] (I_I second-derivative bound).
  V5. B-tilde >= B pointwise on the E-028 grid (majorant sanity).

Outputs: research/numerics/data/E-029-convexity.csv (+ .json)
"""
import json
import sys
import time
from pathlib import Path

import mpmath as mp
import numpy as np
import sympy as sp

REPO = Path(__file__).resolve().parents[3]
DATA = REPO / "research" / "numerics" / "data"
CSV = DATA / "E-029-convexity.csv"
JSON = DATA / "E-029-convexity.json"

A_TR, B0_TR = 10.5, 48.0
M0 = 1.335180201468999
GAMMA = 0.577215664901532860606512090082402431
C1L = (GAMMA - 1 - np.log(2 * np.pi)) / 2 - GAMMA / 2
T0 = np.sqrt(20.0) + 1.0


def build_table():
    """The 11 building blocks: (name, phi(T) sympy, psi hand form)."""
    T = sp.symbols('T', positive=True)
    L1 = sp.log(T + 2)
    L2 = sp.log(sp.log(T + 2))
    phis = [
        ("T log T", T * sp.log(T),
         lambda t: 1 / t - (np.log(t) + 1) / (t - 1)),
        ("T", T,
         lambda t: -1 / (t - 1)),
        ("log T", sp.log(T),
         lambda t: -1 / t ** 2 - 1 / (t * (t - 1))),
        ("log log T", sp.log(sp.log(T)),
         lambda t: -(np.log(t) + 1) / (t * np.log(t)) ** 2
         - 1 / (t * np.log(t) * (t - 1))),
        ("T L1", T * L1,
         lambda t: (t + 4) / (t + 2) ** 2
         - np.log(t + 2) / (t - 1) - t / ((t + 2) * (t - 1))),
        ("T L2", T * L2,
         lambda t: (t * (np.log(t + 2) - 1) + 4 * np.log(t + 2))
         / ((t + 2) * np.log(t + 2)) ** 2
         - np.log(np.log(t + 2)) / (t - 1)
         - t / ((t + 2) * np.log(t + 2) * (t - 1))),
        ("L1^2", L1 ** 2,
         lambda t: 2 * (1 - np.log(t + 2)) / (t + 2) ** 2
         - 2 * np.log(t + 2) / ((t + 2) * (t - 1))),
        ("L1 L2", L1 * L2,
         lambda t: (1 / np.log(t + 2) - np.log(np.log(t + 2)) - 1)
         / (t + 2) ** 2
         - (np.log(np.log(t + 2)) + 1) / ((t + 2) * (t - 1))),
        ("L2^2", L2 ** 2,
         lambda t: 2 * (1 - np.log(np.log(t + 2))
                        * (np.log(t + 2) + 1))
         / ((t + 2) * np.log(t + 2)) ** 2
         - 2 * np.log(np.log(t + 2))
         / ((t + 2) * np.log(t + 2) * (t - 1))),
        ("L1", L1,
         lambda t: -1 / (t + 2) ** 2 - 1 / ((t + 2) * (t - 1))),
        ("L2", L2,
         lambda t: -(np.log(t + 2) + 1) / ((t + 2) * np.log(t + 2)) ** 2
         - 1 / ((t + 2) * np.log(t + 2) * (t - 1))),
    ]
    rows = []
    tpts = np.geomspace(T0, 1e6, 300)      # symbolic-match grid
    tpts_full = np.geomspace(T0, 3.1e12, 400)  # negativity grid
    for name, phi, psi_hand in phis:
        psi_sym = sp.lambdify(
            T, sp.simplify(sp.diff(phi, T, 2)
                           - sp.diff(phi, T) / (T - 1)), "numpy")
        v_sym = psi_sym(tpts)
        v_hand = psi_hand(tpts)
        diff = np.abs(v_sym - v_hand)
        rel = float(np.max(np.where(np.abs(v_hand) > 1e-15,
                                    diff / np.abs(v_hand), 0.0)))
        absd = float(np.max(diff))
        rows.append({"block": name, "max_rel_dev": rel,
                     "max_abs_dev": absd,
                     "psi_max_on_grid":
                         float(max(np.max(v_sym),
                                   np.max(psi_hand(tpts_full)))),
                     "negative_everywhere":
                         bool(np.max(v_sym) < 0
                              and np.max(psi_hand(tpts_full)) < 0)})
    return rows


def Chat(t):
    return (0.433 * np.log(t + 2) + 0.886 * np.log(np.log(t + 2)) + 2.9)


def C0_honest(t):
    def F(u):
        return (u / (2 * np.pi)) * np.log(u / (2 * np.pi)) - u / (2 * np.pi) \
            + 7 / 8

    def Sb(u):
        return 0.137 * np.log(u) + 0.443 * np.log(np.log(u)) + 1.588
    return (F(t + 1) - F(t)) + Sb(t + 1) + Sb(t)


def B_tilde(n):
    n = np.asarray(n, dtype=np.float64)
    T = np.sqrt(n) + 1.0
    C = Chat(T)
    H = 3 * C ** 2 + A_TR * np.log(T + 2) + B0_TR
    twoN = 2 * ((T / (2 * np.pi)) * np.log(T / (2 * np.pi))
                - T / (2 * np.pi) + 7 / 8
                + 0.137 * np.log(T) + 0.443 * np.log(np.log(T)) + 1.588)
    I3 = 4 * T * ((2 / 3) * C + A_TR * np.log(T + 2) + B0_TR)
    I24 = 2 * (np.e ** 4 + 1) * (7 * H + 3.3)
    r = np.sqrt(n)
    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 + 40.0 * M0 + I24 + I1 + 1.0


def B_honest(n):
    n = np.asarray(n, dtype=np.float64)
    T = np.sqrt(n) + 1.0
    C = C0_honest(T)
    H = 3 * C ** 2 + A_TR * np.log(T + 2) + B0_TR
    twoN = 2 * ((T / (2 * np.pi)) * np.log(T / (2 * np.pi))
                - T / (2 * np.pi) + 7 / 8
                + 0.137 * np.log(T) + 0.443 * np.log(np.log(T)) + 1.588)
    I3 = 4 * T * ((2 / 3) * C + A_TR * np.log(T + 2) + B0_TR)
    I24 = 2 * (np.e ** 4 + 1) * (7 * H + 3.3)
    r = np.sqrt(n)
    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 + 40.0 * M0 + I24 + I1 + 1.0


def margin_tilde(n):
    n = np.asarray(n, dtype=np.float64)
    return 0.5 * n * np.log(n) + C1L * n - 4.0 - B_tilde(n) + 1.0


def B4_d2(n):
    """Second derivative of I_I(n) = 2(sqrt(n)+1)(e^{sqrt(n)/2}+1)*0.57
    * 2^{-(2 sqrt(n)-2)} via complex-step-free central differences at
    dps 40."""
    mp.mp.dps = 40

    def f(x):
        r = mp.sqrt(x)
        return 2 * (r + 1) * (mp.e ** (r / 2) + 1) * mp.mpf("0.57") \
            * 2 ** (-(2 * r - 2))

    h = mp.mpf("0.01")
    return float((f(n + h) - 2 * f(n) + f(n - h)) / h ** 2)


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

    print("V1/V2: building-block table ...", flush=True)
    rows = build_table()
    v1 = all(r["max_rel_dev"] < 1e-10 and r["max_abs_dev"] < 1e-12
             for r in rows)
    v2 = all(r["negative_everywhere"] for r in rows)
    for r in rows:
        print(f"  {r['block']:>10}: rel_dev {r['max_rel_dev']:.2e}, "
              f"psi_max {r['psi_max_on_grid']:.3e}", flush=True)

    print("V3: margin-tilde convexity/positivity ...", flush=True)
    ngrid = np.arange(20, 400001)
    mt = margin_tilde(ngrid)
    conv = bool(np.all(np.diff(mt, 2) > 0))
    pos = ngrid[(mt > 0) & (np.gradient(mt, ngrid) > 0)]
    N0t = int(pos[0]) if len(pos) else -1
    cont = bool(np.all(mt[ngrid >= N0t] > 0)) if N0t > 0 else False
    m8 = float(margin_tilde(80000.0))
    d8 = float((margin_tilde(80000.5) - margin_tilde(79999.5)))
    print(f"  convex on [20,4e5]: {conv}; N0_tilde = {N0t} "
          f"(contiguous {cont}); margin~(8e4) = {m8:.1f}, "
          f"margin~'(8e4) = {d8:.1f}", flush=True)
    v3 = bool(conv and cont and m8 > 0 and d8 > 0)

    print("V4: I_I second-derivative bound ...", flush=True)
    n4 = np.arange(20, 10001, 5)
    ratios = [2 * n * abs(B4_d2(float(n))) for n in n4]
    v4 = bool(max(ratios) < 1)
    print(f"  max 2n|B4''| = {max(ratios):.4f} at n = "
          f"{n4[int(np.argmax(ratios))]} (< 1: {v4})", flush=True)

    print("V5: majorant sanity ...", flush=True)
    ng = np.arange(20, 400001, 20)
    v5 = bool(np.all(B_tilde(ng) >= B_honest(ng)))
    print(f"  B_tilde >= B_honest on grid: {v5}", flush=True)

    with open(CSV, "w", newline="") as f:
        import csv as csvmod
        w = csvmod.writer(f)
        w.writerow(["n", "margin_tilde"])
        for n in range(20, 400001, 20):
            w.writerow([n, f"{float(margin_tilde(n)):.6f}"])

    meta = {
        "experiment": "E-029",
        "task": "4.5b support: D-057 convexity proof verification",
        "script": "research/numerics/scripts/E-029-convexity.py",
        "checks": {
            "V1_sympy_matches_hand": v1,
            "V2_psi_negative": v2,
            "V3_margin_tilde_convex_positive": v3,
            "V4_I1_second_derivative": v4,
            "V5_majorant": v5,
            "table": rows,
        },
        "key_values": {"N0_tilde": N0t, "margin_tilde_8e4": m8,
                       "margin_tilde_prime_8e4": d8,
                       "max_2n_B4d2": float(max(ratios))},
        "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 all([v1, v2, v3, v4, v5]) else 1


if __name__ == "__main__":
    sys.exit(main())