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 39 of 40 · 500/page · 20000 rows next →
# nmargin_tilde
19002 380020 1388087.474104
19003 380040 1388188.310385
19004 380060 1388289.147435
19005 380080 1388389.985255
19006 380100 1388490.823845
19007 380120 1388591.663205
19008 380140 1388692.503334
19009 380160 1388793.344233
19010 380180 1388894.185902
19011 380200 1388995.028340
19012 380220 1389095.871548
19013 380240 1389196.715525
19014 380260 1389297.560271
19015 380280 1389398.405787
19016 380300 1389499.252072
19017 380320 1389600.099126
19018 380340 1389700.946950
19019 380360 1389801.795542
19020 380380 1389902.644904
19021 380400 1390003.495035
19022 380420 1390104.345935
19023 380440 1390205.197603
19024 380460 1390306.050041
19025 380480 1390406.903248
19026 380500 1390507.757223
19027 380520 1390608.611967
19028 380540 1390709.467480
19029 380560 1390810.323761
19030 380580 1390911.180811
19031 380600 1391012.038630
19032 380620 1391112.897217
19033 380640 1391213.756573
19034 380660 1391314.616697
19035 380680 1391415.477590
19036 380700 1391516.339251
19037 380720 1391617.201680
19038 380740 1391718.064877
19039 380760 1391818.928843
19040 380780 1391919.793577
19041 380800 1392020.659079
19042 380820 1392121.525348
19043 380840 1392222.392386
19044 380860 1392323.260192
19045 380880 1392424.128766
19046 380900 1392524.998108
19047 380920 1392625.868218
19048 380940 1392726.739095
19049 380960 1392827.610740
19050 380980 1392928.483153
19051 381000 1393029.356333
19052 381020 1393130.230281
19053 381040 1393231.104996
19054 381060 1393331.980479
19055 381080 1393432.856730
19056 381100 1393533.733748
19057 381120 1393634.611533
19058 381140 1393735.490085
19059 381160 1393836.369405
19060 381180 1393937.249492
19061 381200 1394038.130346
19062 381220 1394139.011968
19063 381240 1394239.894356
19064 381260 1394340.777511
19065 381280 1394441.661434
19066 381300 1394542.546123
19067 381320 1394643.431579
19068 381340 1394744.317802
19069 381360 1394845.204792
19070 381380 1394946.092548
19071 381400 1395046.981072
19072 381420 1395147.870361
19073 381440 1395248.760418
19074 381460 1395349.651241
19075 381480 1395450.542830
19076 381500 1395551.435186
19077 381520 1395652.328309
19078 381540 1395753.222197
19079 381560 1395854.116852
19080 381580 1395955.012274
19081 381600 1396055.908461
19082 381620 1396156.805415
19083 381640 1396257.703135
19084 381660 1396358.601621
19085 381680 1396459.500873
19086 381700 1396560.400891
19087 381720 1396661.301675
19088 381740 1396762.203225
19089 381760 1396863.105540
19090 381780 1396964.008622
19091 381800 1397064.912469
19092 381820 1397165.817082
19093 381840 1397266.722461
19094 381860 1397367.628605
19095 381880 1397468.535515
19096 381900 1397569.443190
19097 381920 1397670.351631
19098 381940 1397771.260837
19099 381960 1397872.170808
19100 381980 1397973.081545
19101 382000 1398073.993048
19102 382020 1398174.905315
19103 382040 1398275.818348
19104 382060 1398376.732145
19105 382080 1398477.646708
19106 382100 1398578.562036
19107 382120 1398679.478129
19108 382140 1398780.394987
19109 382160 1398881.312610
19110 382180 1398982.230998
19111 382200 1399083.150150
19112 382220 1399184.070067
19113 382240 1399284.990749
19114 382260 1399385.912196
19115 382280 1399486.834407
19116 382300 1399587.757383
19117 382320 1399688.681123
19118 382340 1399789.605628
19119 382360 1399890.530898
19120 382380 1399991.456931
19121 382400 1400092.383730
19122 382420 1400193.311292
19123 382440 1400294.239619
19124 382460 1400395.168710
19125 382480 1400496.098565
19126 382500 1400597.029184
19127 382520 1400697.960567
19128 382540 1400798.892714
19129 382560 1400899.825625
19130 382580 1401000.759301
19131 382600 1401101.693740
19132 382620 1401202.628942
19133 382640 1401303.564909
19134 382660 1401404.501640
19135 382680 1401505.439134
19136 382700 1401606.377391
19137 382720 1401707.316413
19138 382740 1401808.256198
19139 382760 1401909.196746
19140 382780 1402010.138058
19141 382800 1402111.080133
19142 382820 1402212.022972
19143 382840 1402312.966574
19144 382860 1402413.910939
19145 382880 1402514.856068
19146 382900 1402615.801959
19147 382920 1402716.748614
19148 382940 1402817.696032
19149 382960 1402918.644213
19150 382980 1403019.593157
19151 383000 1403120.542864
19152 383020 1403221.493334
19153 383040 1403322.444566
19154 383060 1403423.396562
19155 383080 1403524.349320
19156 383100 1403625.302841
19157 383120 1403726.257125
19158 383140 1403827.212171
19159 383160 1403928.167980
19160 383180 1404029.124551
19161 383200 1404130.081885
19162 383220 1404231.039981
19163 383240 1404331.998840
19164 383260 1404432.958461
19165 383280 1404533.918844
19166 383300 1404634.879990
19167 383320 1404735.841898
19168 383340 1404836.804568
19169 383360 1404937.768000
19170 383380 1405038.732194
19171 383400 1405139.697150
19172 383420 1405240.662868
19173 383440 1405341.629348
19174 383460 1405442.596590
19175 383480 1405543.564594
19176 383500 1405644.533359
19177 383520 1405745.502887
19178 383540 1405846.473176
19179 383560 1405947.444226
19180 383580 1406048.416038
19181 383600 1406149.388612
19182 383620 1406250.361947
19183 383640 1406351.336044
19184 383660 1406452.310902
19185 383680 1406553.286522
19186 383700 1406654.262903
19187 383720 1406755.240045
19188 383740 1406856.217948
19189 383760 1406957.196613
19190 383780 1407058.176039
19191 383800 1407159.156225
19192 383820 1407260.137173
19193 383840 1407361.118882
19194 383860 1407462.101352
19195 383880 1407563.084583
19196 383900 1407664.068574
19197 383920 1407765.053327
19198 383940 1407866.038840
19199 383960 1407967.025114
19200 383980 1408068.012148
19201 384000 1408168.999943
19202 384020 1408269.988499
19203 384040 1408370.977815
19204 384060 1408471.967892
19205 384080 1408572.958729
19206 384100 1408673.950327
19207 384120 1408774.942685
19208 384140 1408875.935803
19209 384160 1408976.929682
19210 384180 1409077.924320
19211 384200 1409178.919719
19212 384220 1409279.915878
19213 384240 1409380.912797
19214 384260 1409481.910476
19215 384280 1409582.908916
19216 384300 1409683.908115
19217 384320 1409784.908074
19218 384340 1409885.908792
19219 384360 1409986.910271
19220 384380 1410087.912509
19221 384400 1410188.915507
19222 384420 1410289.919265
19223 384440 1410390.923782
19224 384460 1410491.929059
19225 384480 1410592.935095
19226 384500 1410693.941891
19227 384520 1410794.949446
19228 384540 1410895.957761
19229 384560 1410996.966835
19230 384580 1411097.976668
19231 384600 1411198.987261
19232 384620 1411299.998613
19233 384640 1411401.010723
19234 384660 1411502.023593
19235 384680 1411603.037222
19236 384700 1411704.051610
19237 384720 1411805.066757
19238 384740 1411906.082663
19239 384760 1412007.099328
19240 384780 1412108.116752
19241 384800 1412209.134934
19242 384820 1412310.153875
19243 384840 1412411.173575
19244 384860 1412512.194033
19245 384880 1412613.215250
19246 384900 1412714.237226
19247 384920 1412815.259960
19248 384940 1412916.283453
19249 384960 1413017.307704
19250 384980 1413118.332713
19251 385000 1413219.358481
19252 385020 1413320.385007
19253 385040 1413421.412291
19254 385060 1413522.440333
19255 385080 1413623.469134
19256 385100 1413724.498692
19257 385120 1413825.529009
19258 385140 1413926.560083
19259 385160 1414027.591916
19260 385180 1414128.624506
19261 385200 1414229.657855
19262 385220 1414330.691961
19263 385240 1414431.726825
19264 385260 1414532.762446
19265 385280 1414633.798826
19266 385300 1414734.835963
19267 385320 1414835.873857
19268 385340 1414936.912509
19269 385360 1415037.951919
19270 385380 1415138.992086
19271 385400 1415240.033010
19272 385420 1415341.074692
19273 385440 1415442.117131
19274 385460 1415543.160327
19275 385480 1415644.204281
19276 385500 1415745.248991
19277 385520 1415846.294459
19278 385540 1415947.340684
19279 385560 1416048.387666
19280 385580 1416149.435405
19281 385600 1416250.483901
19282 385620 1416351.533154
19283 385640 1416452.583163
19284 385660 1416553.633930
19285 385680 1416654.685453
19286 385700 1416755.737733
19287 385720 1416856.790769
19288 385740 1416957.844562
19289 385760 1417058.899112
19290 385780 1417159.954418
19291 385800 1417261.010481
19292 385820 1417362.067300
19293 385840 1417463.124876
19294 385860 1417564.183208
19295 385880 1417665.242296
19296 385900 1417766.302140
19297 385920 1417867.362741
19298 385940 1417968.424098
19299 385960 1418069.486211
19300 385980 1418170.549080
19301 386000 1418271.612705
19302 386020 1418372.677086
19303 386040 1418473.742223
19304 386060 1418574.808116
19305 386080 1418675.874764
19306 386100 1418776.942169
19307 386120 1418878.010329
19308 386140 1418979.079245
19309 386160 1419080.148917
19310 386180 1419181.219344
19311 386200 1419282.290527
19312 386220 1419383.362465
19313 386240 1419484.435159
19314 386260 1419585.508608
19315 386280 1419686.582813
19316 386300 1419787.657772
19317 386320 1419888.733488
19318 386340 1419989.809958
19319 386360 1420090.887184
19320 386380 1420191.965165
19321 386400 1420293.043901
19322 386420 1420394.123392
19323 386440 1420495.203638
19324 386460 1420596.284639
19325 386480 1420697.366394
19326 386500 1420798.448905
19327 386520 1420899.532171
19328 386540 1421000.616191
19329 386560 1421101.700966
19330 386580 1421202.786496
19331 386600 1421303.872781
19332 386620 1421404.959820
19333 386640 1421506.047614
19334 386660 1421607.136162
19335 386680 1421708.225465
19336 386700 1421809.315522
19337 386720 1421910.406333
19338 386740 1422011.497899
19339 386760 1422112.590219
19340 386780 1422213.683293
19341 386800 1422314.777122
19342 386820 1422415.871705
19343 386840 1422516.967041
19344 386860 1422618.063132
19345 386880 1422719.159977
19346 386900 1422820.257576
19347 386920 1422921.355929
19348 386940 1423022.455035
19349 386960 1423123.554896
19350 386980 1423224.655510
19351 387000 1423325.756878
19352 387020 1423426.859000
19353 387040 1423527.961875
19354 387060 1423629.065504
19355 387080 1423730.169887
19356 387100 1423831.275023
19357 387120 1423932.380912
19358 387140 1424033.487555
19359 387160 1424134.594951
19360 387180 1424235.703101
19361 387200 1424336.812004
19362 387220 1424437.921660
19363 387240 1424539.032070
19364 387260 1424640.143232
19365 387280 1424741.255148
19366 387300 1424842.367816
19367 387320 1424943.481238
19368 387340 1425044.595413
19369 387360 1425145.710340
19370 387380 1425246.826021
19371 387400 1425347.942454
19372 387420 1425449.059640
19373 387440 1425550.177579
19374 387460 1425651.296271
19375 387480 1425752.415715
19376 387500 1425853.535912
19377 387520 1425954.656861
19378 387540 1426055.778563
19379 387560 1426156.901017
19380 387580 1426258.024224
19381 387600 1426359.148183
19382 387620 1426460.272894
19383 387640 1426561.398358
19384 387660 1426662.524574
19385 387680 1426763.651542
19386 387700 1426864.779263
19387 387720 1426965.907735
19388 387740 1427067.036960
19389 387760 1427168.166936
19390 387780 1427269.297665
19391 387800 1427370.429145
19392 387820 1427471.561377
19393 387840 1427572.694362
19394 387860 1427673.828098
19395 387880 1427774.962585
19396 387900 1427876.097825
19397 387920 1427977.233816
19398 387940 1428078.370558
19399 387960 1428179.508052
19400 387980 1428280.646298
19401 388000 1428381.785295
19402 388020 1428482.925044
19403 388040 1428584.065544
19404 388060 1428685.206795
19405 388080 1428786.348798
19406 388100 1428887.491552
19407 388120 1428988.635057
19408 388140 1429089.779313
19409 388160 1429190.924321
19410 388180 1429292.070079
19411 388200 1429393.216588
19412 388220 1429494.363849
19413 388240 1429595.511860
19414 388260 1429696.660622
19415 388280 1429797.810135
19416 388300 1429898.960399
19417 388320 1430000.111414
19418 388340 1430101.263179
19419 388360 1430202.415695
19420 388380 1430303.568962
19421 388400 1430404.722979
19422 388420 1430505.877747
19423 388440 1430607.033265
19424 388460 1430708.189533
19425 388480 1430809.346552
19426 388500 1430910.504322
19427 388520 1431011.662841
19428 388540 1431112.822111
19429 388560 1431213.982131
19430 388580 1431315.142902
19431 388600 1431416.304422
19432 388620 1431517.466692
19433 388640 1431618.629713
19434 388660 1431719.793483
19435 388680 1431820.958004
19436 388700 1431922.123274
19437 388720 1432023.289294
19438 388740 1432124.456064
19439 388760 1432225.623584
19440 388780 1432326.791853
19441 388800 1432427.960872
19442 388820 1432529.130641
19443 388840 1432630.301159
19444 388860 1432731.472427
19445 388880 1432832.644444
19446 388900 1432933.817211
19447 388920 1433034.990727
19448 388940 1433136.164992
19449 388960 1433237.340007
19450 388980 1433338.515771
19451 389000 1433439.692285
19452 389020 1433540.869547
19453 389040 1433642.047559
19454 389060 1433743.226319
19455 389080 1433844.405829
19456 389100 1433945.586088
19457 389120 1434046.767095
19458 389140 1434147.948852
19459 389160 1434249.131357
19460 389180 1434350.314611
19461 389200 1434451.498614
19462 389220 1434552.683366
19463 389240 1434653.868866
19464 389260 1434755.055115
19465 389280 1434856.242113
19466 389300 1434957.429859
19467 389320 1435058.618354
19468 389340 1435159.807597
19469 389360 1435260.997588
19470 389380 1435362.188328
19471 389400 1435463.379816
19472 389420 1435564.572053
19473 389440 1435665.765037
19474 389460 1435766.958770
19475 389480 1435868.153251
19476 389500 1435969.348480
19477 389520 1436070.544457
19478 389540 1436171.741182
19479 389560 1436272.938655
19480 389580 1436374.136876
19481 389600 1436475.335845
19482 389620 1436576.535562
19483 389640 1436677.736026
19484 389660 1436778.937239
19485 389680 1436880.139199
19486 389700 1436981.341906
19487 389720 1437082.545361
19488 389740 1437183.749564
19489 389760 1437284.954514
19490 389780 1437386.160212
19491 389800 1437487.366657
19492 389820 1437588.573849
19493 389840 1437689.781789
19494 389860 1437790.990476
19495 389880 1437892.199911
19496 389900 1437993.410092
19497 389920 1438094.621021
19498 389940 1438195.832697
19499 389960 1438297.045119
19500 389980 1438398.258289
19501 390000 1438499.472206

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