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 38 of 40 · 500/page · 20000 rows next →
# nmargin_tilde
18502 370020 1337766.766444
18503 370040 1337867.211741
18504 370060 1337967.657834
18505 370080 1338068.104720
18506 370100 1338168.552401
18507 370120 1338269.000875
18508 370140 1338369.450144
18509 370160 1338469.900207
18510 370180 1338570.351063
18511 370200 1338670.802714
18512 370220 1338771.255158
18513 370240 1338871.708397
18514 370260 1338972.162429
18515 370280 1339072.617255
18516 370300 1339173.072874
18517 370320 1339273.529287
18518 370340 1339373.986494
18519 370360 1339474.444494
18520 370380 1339574.903287
18521 370400 1339675.362874
18522 370420 1339775.823255
18523 370440 1339876.284429
18524 370460 1339976.746395
18525 370480 1340077.209156
18526 370500 1340177.672709
18527 370520 1340278.137055
18528 370540 1340378.602195
18529 370560 1340479.068127
18530 370580 1340579.534853
18531 370600 1340680.002371
18532 370620 1340780.470683
18533 370640 1340880.939787
18534 370660 1340981.409683
18535 370680 1341081.880373
18536 370700 1341182.351855
18537 370720 1341282.824130
18538 370740 1341383.297197
18539 370760 1341483.771057
18540 370780 1341584.245709
18541 370800 1341684.721154
18542 370820 1341785.197391
18543 370840 1341885.674421
18544 370860 1341986.152242
18545 370880 1342086.630856
18546 370900 1342187.110262
18547 370920 1342287.590460
18548 370940 1342388.071451
18549 370960 1342488.553233
18550 370980 1342589.035807
18551 371000 1342689.519173
18552 371020 1342790.003331
18553 371040 1342890.488281
18554 371060 1342990.974022
18555 371080 1343091.460556
18556 371100 1343191.947881
18557 371120 1343292.435997
18558 371140 1343392.924905
18559 371160 1343493.414605
18560 371180 1343593.905096
18561 371200 1343694.396378
18562 371220 1343794.888452
18563 371240 1343895.381317
18564 371260 1343995.874973
18565 371280 1344096.369421
18566 371300 1344196.864660
18567 371320 1344297.360690
18568 371340 1344397.857511
18569 371360 1344498.355123
18570 371380 1344598.853525
18571 371400 1344699.352719
18572 371420 1344799.852704
18573 371440 1344900.353479
18574 371460 1345000.855046
18575 371480 1345101.357403
18576 371500 1345201.860550
18577 371520 1345302.364488
18578 371540 1345402.869217
18579 371560 1345503.374736
18580 371580 1345603.881046
18581 371600 1345704.388146
18582 371620 1345804.896037
18583 371640 1345905.404718
18584 371660 1346005.914189
18585 371680 1346106.424450
18586 371700 1346206.935502
18587 371720 1346307.447343
18588 371740 1346407.959975
18589 371760 1346508.473397
18590 371780 1346608.987608
18591 371800 1346709.502610
18592 371820 1346810.018401
18593 371840 1346910.534982
18594 371860 1347011.052353
18595 371880 1347111.570514
18596 371900 1347212.089465
18597 371920 1347312.609205
18598 371940 1347413.129734
18599 371960 1347513.651053
18600 371980 1347614.173162
18601 372000 1347714.696060
18602 372020 1347815.219747
18603 372040 1347915.744224
18604 372060 1348016.269490
18605 372080 1348116.795545
18606 372100 1348217.322389
18607 372120 1348317.850022
18608 372140 1348418.378445
18609 372160 1348518.907656
18610 372180 1348619.437657
18611 372200 1348719.968446
18612 372220 1348820.500025
18613 372240 1348921.032392
18614 372260 1349021.565548
18615 372280 1349122.099492
18616 372300 1349222.634225
18617 372320 1349323.169747
18618 372340 1349423.706058
18619 372360 1349524.243157
18620 372380 1349624.781044
18621 372400 1349725.319720
18622 372420 1349825.859184
18623 372440 1349926.399437
18624 372460 1350026.940478
18625 372480 1350127.482307
18626 372500 1350228.024924
18627 372520 1350328.568329
18628 372540 1350429.112523
18629 372560 1350529.657504
18630 372580 1350630.203274
18631 372600 1350730.749831
18632 372620 1350831.297176
18633 372640 1350931.845309
18634 372660 1351032.394230
18635 372680 1351132.943939
18636 372700 1351233.494435
18637 372720 1351334.045719
18638 372740 1351434.597791
18639 372760 1351535.150650
18640 372780 1351635.704296
18641 372800 1351736.258730
18642 372820 1351836.813951
18643 372840 1351937.369960
18644 372860 1352037.926756
18645 372880 1352138.484339
18646 372900 1352239.042710
18647 372920 1352339.601867
18648 372940 1352440.161812
18649 372960 1352540.722543
18650 372980 1352641.284062
18651 373000 1352741.846367
18652 373020 1352842.409460
18653 373040 1352942.973339
18654 373060 1353043.538005
18655 373080 1353144.103458
18656 373100 1353244.669698
18657 373120 1353345.236724
18658 373140 1353445.804537
18659 373160 1353546.373136
18660 373180 1353646.942522
18661 373200 1353747.512694
18662 373220 1353848.083652
18663 373240 1353948.655397
18664 373260 1354049.227929
18665 373280 1354149.801246
18666 373300 1354250.375350
18667 373320 1354350.950240
18668 373340 1354451.525916
18669 373360 1354552.102378
18670 373380 1354652.679626
18671 373400 1354753.257660
18672 373420 1354853.836480
18673 373440 1354954.416085
18674 373460 1355054.996477
18675 373480 1355155.577654
18676 373500 1355256.159617
18677 373520 1355356.742366
18678 373540 1355457.325900
18679 373560 1355557.910220
18680 373580 1355658.495325
18681 373600 1355759.081216
18682 373620 1355859.667892
18683 373640 1355960.255354
18684 373660 1356060.843601
18685 373680 1356161.432633
18686 373700 1356262.022450
18687 373720 1356362.613052
18688 373740 1356463.204440
18689 373760 1356563.796613
18690 373780 1356664.389570
18691 373800 1356764.983313
18692 373820 1356865.577841
18693 373840 1356966.173153
18694 373860 1357066.769250
18695 373880 1357167.366132
18696 373900 1357267.963799
18697 373920 1357368.562251
18698 373940 1357469.161487
18699 373960 1357569.761507
18700 373980 1357670.362312
18701 374000 1357770.963902
18702 374020 1357871.566276
18703 374040 1357972.169435
18704 374060 1358072.773377
18705 374080 1358173.378104
18706 374100 1358273.983616
18707 374120 1358374.589911
18708 374140 1358475.196991
18709 374160 1358575.804854
18710 374180 1358676.413502
18711 374200 1358777.022934
18712 374220 1358877.633149
18713 374240 1358978.244149
18714 374260 1359078.855932
18715 374280 1359179.468499
18716 374300 1359280.081850
18717 374320 1359380.695985
18718 374340 1359481.310903
18719 374360 1359581.926605
18720 374380 1359682.543090
18721 374400 1359783.160359
18722 374420 1359883.778411
18723 374440 1359984.397247
18724 374460 1360085.016866
18725 374480 1360185.637268
18726 374500 1360286.258454
18727 374520 1360386.880422
18728 374540 1360487.503174
18729 374560 1360588.126709
18730 374580 1360688.751027
18731 374600 1360789.376129
18732 374620 1360890.002013
18733 374640 1360990.628679
18734 374660 1361091.256129
18735 374680 1361191.884362
18736 374700 1361292.513377
18737 374720 1361393.143175
18738 374740 1361493.773756
18739 374760 1361594.405119
18740 374780 1361695.037265
18741 374800 1361795.670194
18742 374820 1361896.303905
18743 374840 1361996.938398
18744 374860 1362097.573674
18745 374880 1362198.209732
18746 374900 1362298.846572
18747 374920 1362399.484194
18748 374940 1362500.122599
18749 374960 1362600.761786
18750 374980 1362701.401755
18751 375000 1362802.042506
18752 375020 1362902.684039
18753 375040 1363003.326353
18754 375060 1363103.969450
18755 375080 1363204.613329
18756 375100 1363305.257989
18757 375120 1363405.903431
18758 375140 1363506.549655
18759 375160 1363607.196660
18760 375180 1363707.844447
18761 375200 1363808.493015
18762 375220 1363909.142365
18763 375240 1364009.792497
18764 375260 1364110.443410
18765 375280 1364211.095104
18766 375300 1364311.747579
18767 375320 1364412.400836
18768 375340 1364513.054874
18769 375360 1364613.709693
18770 375380 1364714.365293
18771 375400 1364815.021674
18772 375420 1364915.678836
18773 375440 1365016.336780
18774 375460 1365116.995504
18775 375480 1365217.655009
18776 375500 1365318.315294
18777 375520 1365418.976361
18778 375540 1365519.638208
18779 375560 1365620.300836
18780 375580 1365720.964244
18781 375600 1365821.628433
18782 375620 1365922.293403
18783 375640 1366022.959153
18784 375660 1366123.625683
18785 375680 1366224.292994
18786 375700 1366324.961085
18787 375720 1366425.629957
18788 375740 1366526.299608
18789 375760 1366626.970040
18790 375780 1366727.641252
18791 375800 1366828.313244
18792 375820 1366928.986016
18793 375840 1367029.659568
18794 375860 1367130.333900
18795 375880 1367231.009012
18796 375900 1367331.684903
18797 375920 1367432.361575
18798 375940 1367533.039026
18799 375960 1367633.717257
18800 375980 1367734.396267
18801 376000 1367835.076058
18802 376020 1367935.756627
18803 376040 1368036.437976
18804 376060 1368137.120105
18805 376080 1368237.803013
18806 376100 1368338.486700
18807 376120 1368439.171167
18808 376140 1368539.856413
18809 376160 1368640.542438
18810 376180 1368741.229242
18811 376200 1368841.916826
18812 376220 1368942.605188
18813 376240 1369043.294330
18814 376260 1369143.984250
18815 376280 1369244.674949
18816 376300 1369345.366427
18817 376320 1369446.058684
18818 376340 1369546.751720
18819 376360 1369647.445535
18820 376380 1369748.140128
18821 376400 1369848.835500
18822 376420 1369949.531650
18823 376440 1370050.228579
18824 376460 1370150.926286
18825 376480 1370251.624772
18826 376500 1370352.324036
18827 376520 1370453.024079
18828 376540 1370553.724900
18829 376560 1370654.426499
18830 376580 1370755.128876
18831 376600 1370855.832031
18832 376620 1370956.535965
18833 376640 1371057.240676
18834 376660 1371157.946166
18835 376680 1371258.652433
18836 376700 1371359.359478
18837 376720 1371460.067301
18838 376740 1371560.775902
18839 376760 1371661.485281
18840 376780 1371762.195438
18841 376800 1371862.906372
18842 376820 1371963.618083
18843 376840 1372064.330573
18844 376860 1372165.043839
18845 376880 1372265.757884
18846 376900 1372366.472705
18847 376920 1372467.188304
18848 376940 1372567.904681
18849 376960 1372668.621834
18850 376980 1372769.339765
18851 377000 1372870.058473
18852 377020 1372970.777958
18853 377040 1373071.498220
18854 377060 1373172.219260
18855 377080 1373272.941076
18856 377100 1373373.663669
18857 377120 1373474.387039
18858 377140 1373575.111186
18859 377160 1373675.836109
18860 377180 1373776.561810
18861 377200 1373877.288287
18862 377220 1373978.015541
18863 377240 1374078.743571
18864 377260 1374179.472378
18865 377280 1374280.201961
18866 377300 1374380.932321
18867 377320 1374481.663457
18868 377340 1374582.395370
18869 377360 1374683.128058
18870 377380 1374783.861524
18871 377400 1374884.595765
18872 377420 1374985.330782
18873 377440 1375086.066576
18874 377460 1375186.803146
18875 377480 1375287.540491
18876 377500 1375388.278613
18877 377520 1375489.017511
18878 377540 1375589.757184
18879 377560 1375690.497633
18880 377580 1375791.238858
18881 377600 1375891.980859
18882 377620 1375992.723636
18883 377640 1376093.467188
18884 377660 1376194.211515
18885 377680 1376294.956618
18886 377700 1376395.702497
18887 377720 1376496.449151
18888 377740 1376597.196581
18889 377760 1376697.944786
18890 377780 1376798.693766
18891 377800 1376899.443521
18892 377820 1377000.194052
18893 377840 1377100.945358
18894 377860 1377201.697439
18895 377880 1377302.450294
18896 377900 1377403.203925
18897 377920 1377503.958331
18898 377940 1377604.713512
18899 377960 1377705.469468
18900 377980 1377806.226198
18901 378000 1377906.983703
18902 378020 1378007.741983
18903 378040 1378108.501038
18904 378060 1378209.260867
18905 378080 1378310.021471
18906 378100 1378410.782849
18907 378120 1378511.545002
18908 378140 1378612.307930
18909 378160 1378713.071631
18910 378180 1378813.836107
18911 378200 1378914.601358
18912 378220 1379015.367382
18913 378240 1379116.134181
18914 378260 1379216.901754
18915 378280 1379317.670101
18916 378300 1379418.439222
18917 378320 1379519.209117
18918 378340 1379619.979786
18919 378360 1379720.751228
18920 378380 1379821.523445
18921 378400 1379922.296436
18922 378420 1380023.070200
18923 378440 1380123.844738
18924 378460 1380224.620050
18925 378480 1380325.396135
18926 378500 1380426.172994
18927 378520 1380526.950626
18928 378540 1380627.729032
18929 378560 1380728.508211
18930 378580 1380829.288164
18931 378600 1380930.068890
18932 378620 1381030.850389
18933 378640 1381131.632662
18934 378660 1381232.415708
18935 378680 1381333.199526
18936 378700 1381433.984118
18937 378720 1381534.769483
18938 378740 1381635.555621
18939 378760 1381736.342532
18940 378780 1381837.130216
18941 378800 1381937.918673
18942 378820 1382038.707902
18943 378840 1382139.497904
18944 378860 1382240.288679
18945 378880 1382341.080227
18946 378900 1382441.872547
18947 378920 1382542.665640
18948 378940 1382643.459505
18949 378960 1382744.254143
18950 378980 1382845.049553
18951 379000 1382945.845736
18952 379020 1383046.642691
18953 379040 1383147.440418
18954 379060 1383248.238918
18955 379080 1383349.038189
18956 379100 1383449.838233
18957 379120 1383550.639049
18958 379140 1383651.440637
18959 379160 1383752.242997
18960 379180 1383853.046128
18961 379200 1383953.850032
18962 379220 1384054.654708
18963 379240 1384155.460155
18964 379260 1384256.266374
18965 379280 1384357.073365
18966 379300 1384457.881128
18967 379320 1384558.689662
18968 379340 1384659.498968
18969 379360 1384760.309045
18970 379380 1384861.119893
18971 379400 1384961.931514
18972 379420 1385062.743905
18973 379440 1385163.557068
18974 379460 1385264.371002
18975 379480 1385365.185707
18976 379500 1385466.001184
18977 379520 1385566.817431
18978 379540 1385667.634450
18979 379560 1385768.452240
18980 379580 1385869.270801
18981 379600 1385970.090133
18982 379620 1386070.910235
18983 379640 1386171.731109
18984 379660 1386272.552753
18985 379680 1386373.375168
18986 379700 1386474.198354
18987 379720 1386575.022310
18988 379740 1386675.847037
18989 379760 1386776.672535
18990 379780 1386877.498803
18991 379800 1386978.325842
18992 379820 1387079.153651
18993 379840 1387179.982230
18994 379860 1387280.811580
18995 379880 1387381.641700
18996 379900 1387482.472590
18997 379920 1387583.304251
18998 379940 1387684.136681
18999 379960 1387784.969882
19000 379980 1387885.803853
19001 380000 1387986.638593

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