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 37 of 40 · 500/page · 20000 rows next →
# nmargin_tilde
18002 360020 1287644.669827
18003 360040 1287744.711562
18004 360060 1287844.754117
18005 360080 1287944.797492
18006 360100 1288044.841688
18007 360120 1288144.886703
18008 360140 1288244.932539
18009 360160 1288344.979194
18010 360180 1288445.026669
18011 360200 1288545.074964
18012 360220 1288645.124079
18013 360240 1288745.174013
18014 360260 1288845.224767
18015 360280 1288945.276341
18016 360300 1289045.328735
18017 360320 1289145.381947
18018 360340 1289245.435980
18019 360360 1289345.490831
18020 360380 1289445.546502
18021 360400 1289545.602993
18022 360420 1289645.660302
18023 360440 1289745.718431
18024 360460 1289845.777379
18025 360480 1289945.837146
18026 360500 1290045.897732
18027 360520 1290145.959137
18028 360540 1290246.021360
18029 360560 1290346.084403
18030 360580 1290446.148265
18031 360600 1290546.212945
18032 360620 1290646.278444
18033 360640 1290746.344761
18034 360660 1290846.411898
18035 360680 1290946.479852
18036 360700 1291046.548626
18037 360720 1291146.618217
18038 360740 1291246.688627
18039 360760 1291346.759856
18040 360780 1291446.831902
18041 360800 1291546.904767
18042 360820 1291646.978450
18043 360840 1291747.052952
18044 360860 1291847.128271
18045 360880 1291947.204408
18046 360900 1292047.281363
18047 360920 1292147.359136
18048 360940 1292247.437727
18049 360960 1292347.517136
18050 360980 1292447.597363
18051 361000 1292547.678407
18052 361020 1292647.760269
18053 361040 1292747.842948
18054 361060 1292847.926445
18055 361080 1292948.010760
18056 361100 1293048.095891
18057 361120 1293148.181841
18058 361140 1293248.268607
18059 361160 1293348.356191
18060 361180 1293448.444592
18061 361200 1293548.533810
18062 361220 1293648.623846
18063 361240 1293748.714698
18064 361260 1293848.806367
18065 361280 1293948.898854
18066 361300 1294048.992157
18067 361320 1294149.086277
18068 361340 1294249.181214
18069 361360 1294349.276967
18070 361380 1294449.373538
18071 361400 1294549.470924
18072 361420 1294649.569128
18073 361440 1294749.668148
18074 361460 1294849.767984
18075 361480 1294949.868637
18076 361500 1295049.970106
18077 361520 1295150.072392
18078 361540 1295250.175494
18079 361560 1295350.279412
18080 361580 1295450.384146
18081 361600 1295550.489696
18082 361620 1295650.596062
18083 361640 1295750.703245
18084 361660 1295850.811243
18085 361680 1295950.920057
18086 361700 1296051.029687
18087 361720 1296151.140133
18088 361740 1296251.251394
18089 361760 1296351.363471
18090 361780 1296451.476364
18091 361800 1296551.590073
18092 361820 1296651.704596
18093 361840 1296751.819936
18094 361860 1296851.936091
18095 361880 1296952.053061
18096 361900 1297052.170846
18097 361920 1297152.289447
18098 361940 1297252.408863
18099 361960 1297352.529094
18100 361980 1297452.650140
18101 362000 1297552.772001
18102 362020 1297652.894677
18103 362040 1297753.018168
18104 362060 1297853.142474
18105 362080 1297953.267595
18106 362100 1298053.393530
18107 362120 1298153.520281
18108 362140 1298253.647846
18109 362160 1298353.776225
18110 362180 1298453.905419
18111 362200 1298554.035428
18112 362220 1298654.166251
18113 362240 1298754.297889
18114 362260 1298854.430340
18115 362280 1298954.563607
18116 362300 1299054.697687
18117 362320 1299154.832582
18118 362340 1299254.968290
18119 362360 1299355.104813
18120 362380 1299455.242150
18121 362400 1299555.380301
18122 362420 1299655.519266
18123 362440 1299755.659045
18124 362460 1299855.799637
18125 362480 1299955.941043
18126 362500 1300056.083264
18127 362520 1300156.226297
18128 362540 1300256.370145
18129 362560 1300356.514805
18130 362580 1300456.660280
18131 362600 1300556.806568
18132 362620 1300656.953669
18133 362640 1300757.101584
18134 362660 1300857.250311
18135 362680 1300957.399853
18136 362700 1301057.550207
18137 362720 1301157.701375
18138 362740 1301257.853355
18139 362760 1301358.006149
18140 362780 1301458.159755
18141 362800 1301558.314175
18142 362820 1301658.469407
18143 362840 1301758.625453
18144 362860 1301858.782311
18145 362880 1301958.939981
18146 362900 1302059.098465
18147 362920 1302159.257761
18148 362940 1302259.417870
18149 362960 1302359.578791
18150 362980 1302459.740524
18151 363000 1302559.903070
18152 363020 1302660.066429
18153 363040 1302760.230599
18154 363060 1302860.395582
18155 363080 1302960.561377
18156 363100 1303060.727985
18157 363120 1303160.895404
18158 363140 1303261.063635
18159 363160 1303361.232679
18160 363180 1303461.402534
18161 363200 1303561.573201
18162 363220 1303661.744680
18163 363240 1303761.916971
18164 363260 1303862.090074
18165 363280 1303962.263988
18166 363300 1304062.438714
18167 363320 1304162.614251
18168 363340 1304262.790600
18169 363360 1304362.967760
18170 363380 1304463.145732
18171 363400 1304563.324515
18172 363420 1304663.504110
18173 363440 1304763.684515
18174 363460 1304863.865732
18175 363480 1304964.047760
18176 363500 1305064.230600
18177 363520 1305164.414250
18178 363540 1305264.598711
18179 363560 1305364.783983
18180 363580 1305464.970066
18181 363600 1305565.156960
18182 363620 1305665.344665
18183 363640 1305765.533180
18184 363660 1305865.722506
18185 363680 1305965.912643
18186 363700 1306066.103590
18187 363720 1306166.295348
18188 363740 1306266.487916
18189 363760 1306366.681295
18190 363780 1306466.875484
18191 363800 1306567.070483
18192 363820 1306667.266293
18193 363840 1306767.462912
18194 363860 1306867.660342
18195 363880 1306967.858582
18196 363900 1307068.057633
18197 363920 1307168.257493
18198 363940 1307268.458163
18199 363960 1307368.659643
18200 363980 1307468.861933
18201 364000 1307569.065032
18202 364020 1307669.268942
18203 364040 1307769.473661
18204 364060 1307869.679189
18205 364080 1307969.885527
18206 364100 1308070.092675
18207 364120 1308170.300632
18208 364140 1308270.509399
18209 364160 1308370.718975
18210 364180 1308470.929361
18211 364200 1308571.140555
18212 364220 1308671.352559
18213 364240 1308771.565372
18214 364260 1308871.778994
18215 364280 1308971.993425
18216 364300 1309072.208666
18217 364320 1309172.424715
18218 364340 1309272.641573
18219 364360 1309372.859240
18220 364380 1309473.077715
18221 364400 1309573.297000
18222 364420 1309673.517093
18223 364440 1309773.737995
18224 364460 1309873.959705
18225 364480 1309974.182224
18226 364500 1310074.405552
18227 364520 1310174.629687
18228 364540 1310274.854632
18229 364560 1310375.080384
18230 364580 1310475.306945
18231 364600 1310575.534314
18232 364620 1310675.762492
18233 364640 1310775.991477
18234 364660 1310876.221270
18235 364680 1310976.451872
18236 364700 1311076.683281
18237 364720 1311176.915499
18238 364740 1311277.148524
18239 364760 1311377.382357
18240 364780 1311477.616998
18241 364800 1311577.852446
18242 364820 1311678.088702
18243 364840 1311778.325766
18244 364860 1311878.563637
18245 364880 1311978.802316
18246 364900 1312079.041803
18247 364920 1312179.282096
18248 364940 1312279.523197
18249 364960 1312379.765106
18250 364980 1312480.007821
18251 365000 1312580.251344
18252 365020 1312680.495674
18253 365040 1312780.740811
18254 365060 1312880.986755
18255 365080 1312981.233506
18256 365100 1313081.481064
18257 365120 1313181.729428
18258 365140 1313281.978600
18259 365160 1313382.228578
18260 365180 1313482.479363
18261 365200 1313582.730955
18262 365220 1313682.983354
18263 365240 1313783.236559
18264 365260 1313883.490570
18265 365280 1313983.745388
18266 365300 1314084.001012
18267 365320 1314184.257443
18268 365340 1314284.514680
18269 365360 1314384.772723
18270 365380 1314485.031573
18271 365400 1314585.291229
18272 365420 1314685.551690
18273 365440 1314785.812958
18274 365460 1314886.075032
18275 365480 1314986.337912
18276 365500 1315086.601597
18277 365520 1315186.866089
18278 365540 1315287.131386
18279 365560 1315387.397489
18280 365580 1315487.664398
18281 365600 1315587.932112
18282 365620 1315688.200632
18283 365640 1315788.469957
18284 365660 1315888.740088
18285 365680 1315989.011025
18286 365700 1316089.282766
18287 365720 1316189.555313
18288 365740 1316289.828666
18289 365760 1316390.102823
18290 365780 1316490.377786
18291 365800 1316590.653554
18292 365820 1316690.930127
18293 365840 1316791.207505
18294 365860 1316891.485688
18295 365880 1316991.764675
18296 365900 1317092.044468
18297 365920 1317192.325066
18298 365940 1317292.606468
18299 365960 1317392.888675
18300 365980 1317493.171686
18301 366000 1317593.455503
18302 366020 1317693.740123
18303 366040 1317794.025549
18304 366060 1317894.311778
18305 366080 1317994.598812
18306 366100 1318094.886651
18307 366120 1318195.175294
18308 366140 1318295.464741
18309 366160 1318395.754992
18310 366180 1318496.046047
18311 366200 1318596.337907
18312 366220 1318696.630570
18313 366240 1318796.924038
18314 366260 1318897.218309
18315 366280 1318997.513384
18316 366300 1319097.809263
18317 366320 1319198.105946
18318 366340 1319298.403433
18319 366360 1319398.701723
18320 366380 1319499.000817
18321 366400 1319599.300714
18322 366420 1319699.601415
18323 366440 1319799.902920
18324 366460 1319900.205228
18325 366480 1320000.508339
18326 366500 1320100.812254
18327 366520 1320201.116971
18328 366540 1320301.422492
18329 366560 1320401.728817
18330 366580 1320502.035944
18331 366600 1320602.343874
18332 366620 1320702.652608
18333 366640 1320802.962144
18334 366660 1320903.272483
18335 366680 1321003.583625
18336 366700 1321103.895570
18337 366720 1321204.208318
18338 366740 1321304.521868
18339 366760 1321404.836221
18340 366780 1321505.151377
18341 366800 1321605.467335
18342 366820 1321705.784096
18343 366840 1321806.101659
18344 366860 1321906.420025
18345 366880 1322006.739192
18346 366900 1322107.059162
18347 366920 1322207.379935
18348 366940 1322307.701509
18349 366960 1322408.023886
18350 366980 1322508.347065
18351 367000 1322608.671046
18352 367020 1322708.995829
18353 367040 1322809.321413
18354 367060 1322909.647800
18355 367080 1323009.974988
18356 367100 1323110.302979
18357 367120 1323210.631770
18358 367140 1323310.961364
18359 367160 1323411.291759
18360 367180 1323511.622956
18361 367200 1323611.954954
18362 367220 1323712.287754
18363 367240 1323812.621356
18364 367260 1323912.955758
18365 367280 1324013.290962
18366 367300 1324113.626967
18367 367320 1324213.963774
18368 367340 1324314.301381
18369 367360 1324414.639790
18370 367380 1324514.979000
18371 367400 1324615.319010
18372 367420 1324715.659822
18373 367440 1324816.001435
18374 367460 1324916.343848
18375 367480 1325016.687062
18376 367500 1325117.031077
18377 367520 1325217.375893
18378 367540 1325317.721510
18379 367560 1325418.067927
18380 367580 1325518.415144
18381 367600 1325618.763162
18382 367620 1325719.111981
18383 367640 1325819.461600
18384 367660 1325919.812019
18385 367680 1326020.163238
18386 367700 1326120.515258
18387 367720 1326220.868078
18388 367740 1326321.221698
18389 367760 1326421.576118
18390 367780 1326521.931339
18391 367800 1326622.287359
18392 367820 1326722.644179
18393 367840 1326823.001799
18394 367860 1326923.360219
18395 367880 1327023.719439
18396 367900 1327124.079458
18397 367920 1327224.440277
18398 367940 1327324.801896
18399 367960 1327425.164314
18400 367980 1327525.527532
18401 368000 1327625.891550
18402 368020 1327726.256366
18403 368040 1327826.621982
18404 368060 1327926.988398
18405 368080 1328027.355613
18406 368100 1328127.723627
18407 368120 1328228.092440
18408 368140 1328328.462052
18409 368160 1328428.832463
18410 368180 1328529.203674
18411 368200 1328629.575683
18412 368220 1328729.948491
18413 368240 1328830.322098
18414 368260 1328930.696504
18415 368280 1329031.071709
18416 368300 1329131.447713
18417 368320 1329231.824515
18418 368340 1329332.202115
18419 368360 1329432.580515
18420 368380 1329532.959712
18421 368400 1329633.339709
18422 368420 1329733.720503
18423 368440 1329834.102096
18424 368460 1329934.484488
18425 368480 1330034.867677
18426 368500 1330135.251665
18427 368520 1330235.636451
18428 368540 1330336.022035
18429 368560 1330436.408417
18430 368580 1330536.795597
18431 368600 1330637.183575
18432 368620 1330737.572351
18433 368640 1330837.961925
18434 368660 1330938.352297
18435 368680 1331038.743466
18436 368700 1331139.135433
18437 368720 1331239.528198
18438 368740 1331339.921760
18439 368760 1331440.316120
18440 368780 1331540.711278
18441 368800 1331641.107233
18442 368820 1331741.503985
18443 368840 1331841.901534
18444 368860 1331942.299881
18445 368880 1332042.699025
18446 368900 1332143.098967
18447 368920 1332243.499705
18448 368940 1332343.901241
18449 368960 1332444.303573
18450 368980 1332544.706703
18451 369000 1332645.110630
18452 369020 1332745.515353
18453 369040 1332845.920873
18454 369060 1332946.327190
18455 369080 1333046.734304
18456 369100 1333147.142215
18457 369120 1333247.550922
18458 369140 1333347.960425
18459 369160 1333448.370726
18460 369180 1333548.781822
18461 369200 1333649.193716
18462 369220 1333749.606405
18463 369240 1333850.019891
18464 369260 1333950.434173
18465 369280 1334050.849252
18466 369300 1334151.265126
18467 369320 1334251.681797
18468 369340 1334352.099264
18469 369360 1334452.517527
18470 369380 1334552.936585
18471 369400 1334653.356440
18472 369420 1334753.777091
18473 369440 1334854.198537
18474 369460 1334954.620779
18475 369480 1335055.043817
18476 369500 1335155.467651
18477 369520 1335255.892280
18478 369540 1335356.317705
18479 369560 1335456.743926
18480 369580 1335557.170941
18481 369600 1335657.598753
18482 369620 1335758.027359
18483 369640 1335858.456761
18484 369660 1335958.886959
18485 369680 1336059.317951
18486 369700 1336159.749739
18487 369720 1336260.182321
18488 369740 1336360.615699
18489 369760 1336461.049872
18490 369780 1336561.484840
18491 369800 1336661.920603
18492 369820 1336762.357160
18493 369840 1336862.794513
18494 369860 1336963.232660
18495 369880 1337063.671602
18496 369900 1337164.111339
18497 369920 1337264.551870
18498 369940 1337364.993196
18499 369960 1337465.435316
18500 369980 1337565.878231
18501 370000 1337666.321940

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