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 35 of 40 · 500/page · 20000 rows next →
# nmargin_tilde
17002 340020 1188022.671180
17003 340040 1188121.864792
17004 340060 1188221.059281
17005 340080 1188320.254648
17006 340100 1188419.450891
17007 340120 1188518.648012
17008 340140 1188617.846009
17009 340160 1188717.044883
17010 340180 1188816.244635
17011 340200 1188915.445263
17012 340220 1189014.646767
17013 340240 1189113.849149
17014 340260 1189213.052407
17015 340280 1189312.256541
17016 340300 1189411.461552
17017 340320 1189510.667439
17018 340340 1189609.874203
17019 340360 1189709.081843
17020 340380 1189808.290360
17021 340400 1189907.499752
17022 340420 1190006.710021
17023 340440 1190105.921165
17024 340460 1190205.133186
17025 340480 1190304.346082
17026 340500 1190403.559855
17027 340520 1190502.774503
17028 340540 1190601.990027
17029 340560 1190701.206427
17030 340580 1190800.423702
17031 340600 1190899.641853
17032 340620 1190998.860879
17033 340640 1191098.080781
17034 340660 1191197.301558
17035 340680 1191296.523211
17036 340700 1191395.745739
17037 340720 1191494.969142
17038 340740 1191594.193420
17039 340760 1191693.418573
17040 340780 1191792.644601
17041 340800 1191891.871505
17042 340820 1191991.099283
17043 340840 1192090.327936
17044 340860 1192189.557464
17045 340880 1192288.787866
17046 340900 1192388.019143
17047 340920 1192487.251295
17048 340940 1192586.484321
17049 340960 1192685.718222
17050 340980 1192784.952997
17051 341000 1192884.188647
17052 341020 1192983.425171
17053 341040 1193082.662569
17054 341060 1193181.900841
17055 341080 1193281.139987
17056 341100 1193380.380008
17057 341120 1193479.620902
17058 341140 1193578.862671
17059 341160 1193678.105313
17060 341180 1193777.348829
17061 341200 1193876.593219
17062 341220 1193975.838483
17063 341240 1194075.084620
17064 341260 1194174.331630
17065 341280 1194273.579515
17066 341300 1194372.828272
17067 341320 1194472.077904
17068 341340 1194571.328408
17069 341360 1194670.579786
17070 341380 1194769.832037
17071 341400 1194869.085161
17072 341420 1194968.339158
17073 341440 1195067.594028
17074 341460 1195166.849771
17075 341480 1195266.106387
17076 341500 1195365.363876
17077 341520 1195464.622238
17078 341540 1195563.881473
17079 341560 1195663.141580
17080 341580 1195762.402559
17081 341600 1195861.664412
17082 341620 1195960.927137
17083 341640 1196060.190734
17084 341660 1196159.455203
17085 341680 1196258.720545
17086 341700 1196357.986760
17087 341720 1196457.253846
17088 341740 1196556.521804
17089 341760 1196655.790635
17090 341780 1196755.060338
17091 341800 1196854.330912
17092 341820 1196953.602358
17093 341840 1197052.874677
17094 341860 1197152.147867
17095 341880 1197251.421928
17096 341900 1197350.696862
17097 341920 1197449.972667
17098 341940 1197549.249343
17099 341960 1197648.526891
17100 341980 1197747.805311
17101 342000 1197847.084601
17102 342020 1197946.364763
17103 342040 1198045.645797
17104 342060 1198144.927701
17105 342080 1198244.210476
17106 342100 1198343.494123
17107 342120 1198442.778641
17108 342140 1198542.064029
17109 342160 1198641.350288
17110 342180 1198740.637419
17111 342200 1198839.925419
17112 342220 1198939.214291
17113 342240 1199038.504033
17114 342260 1199137.794646
17115 342280 1199237.086129
17116 342300 1199336.378483
17117 342320 1199435.671707
17118 342340 1199534.965802
17119 342360 1199634.260767
17120 342380 1199733.556602
17121 342400 1199832.853307
17122 342420 1199932.150882
17123 342440 1200031.449327
17124 342460 1200130.748642
17125 342480 1200230.048828
17126 342500 1200329.349883
17127 342520 1200428.651807
17128 342540 1200527.954602
17129 342560 1200627.258266
17130 342580 1200726.562800
17131 342600 1200825.868203
17132 342620 1200925.174476
17133 342640 1201024.481618
17134 342660 1201123.789630
17135 342680 1201223.098511
17136 342700 1201322.408261
17137 342720 1201421.718881
17138 342740 1201521.030369
17139 342760 1201620.342727
17140 342780 1201719.655953
17141 342800 1201818.970049
17142 342820 1201918.285013
17143 342840 1202017.600847
17144 342860 1202116.917549
17145 342880 1202216.235120
17146 342900 1202315.553559
17147 342920 1202414.872867
17148 342940 1202514.193044
17149 342960 1202613.514089
17150 342980 1202712.836002
17151 343000 1202812.158784
17152 343020 1202911.482434
17153 343040 1203010.806953
17154 343060 1203110.132339
17155 343080 1203209.458594
17156 343100 1203308.785717
17157 343120 1203408.113708
17158 343140 1203507.442566
17159 343160 1203606.772293
17160 343180 1203706.102887
17161 343200 1203805.434350
17162 343220 1203904.766680
17163 343240 1204004.099877
17164 343260 1204103.433942
17165 343280 1204202.768875
17166 343300 1204302.104675
17167 343320 1204401.441342
17168 343340 1204500.778877
17169 343360 1204600.117280
17170 343380 1204699.456549
17171 343400 1204798.796685
17172 343420 1204898.137689
17173 343440 1204997.479560
17174 343460 1205096.822297
17175 343480 1205196.165902
17176 343500 1205295.510374
17177 343520 1205394.855712
17178 343540 1205494.201917
17179 343560 1205593.548989
17180 343580 1205692.896927
17181 343600 1205792.245732
17182 343620 1205891.595404
17183 343640 1205990.945942
17184 343660 1206090.297346
17185 343680 1206189.649617
17186 343700 1206289.002754
17187 343720 1206388.356757
17188 343740 1206487.711626
17189 343760 1206587.067361
17190 343780 1206686.423963
17191 343800 1206785.781430
17192 343820 1206885.139764
17193 343840 1206984.498963
17194 343860 1207083.859028
17195 343880 1207183.219959
17196 343900 1207282.581755
17197 343920 1207381.944417
17198 343940 1207481.307945
17199 343960 1207580.672338
17200 343980 1207680.037597
17201 344000 1207779.403721
17202 344020 1207878.770710
17203 344040 1207978.138565
17204 344060 1208077.507284
17205 344080 1208176.876869
17206 344100 1208276.247319
17207 344120 1208375.618635
17208 344140 1208474.990815
17209 344160 1208574.363860
17210 344180 1208673.737769
17211 344200 1208773.112544
17212 344220 1208872.488183
17213 344240 1208971.864687
17214 344260 1209071.242056
17215 344280 1209170.620289
17216 344300 1209269.999387
17217 344320 1209369.379349
17218 344340 1209468.760176
17219 344360 1209568.141867
17220 344380 1209667.524422
17221 344400 1209766.907841
17222 344420 1209866.292125
17223 344440 1209965.677272
17224 344460 1210065.063284
17225 344480 1210164.450159
17226 344500 1210263.837899
17227 344520 1210363.226502
17228 344540 1210462.615969
17229 344560 1210562.006300
17230 344580 1210661.397495
17231 344600 1210760.789553
17232 344620 1210860.182474
17233 344640 1210959.576260
17234 344660 1211058.970908
17235 344680 1211158.366420
17236 344700 1211257.762796
17237 344720 1211357.160034
17238 344740 1211456.558136
17239 344760 1211555.957101
17240 344780 1211655.356929
17241 344800 1211754.757620
17242 344820 1211854.159174
17243 344840 1211953.561591
17244 344860 1212052.964871
17245 344880 1212152.369013
17246 344900 1212251.774019
17247 344920 1212351.179887
17248 344940 1212450.586617
17249 344960 1212549.994210
17250 344980 1212649.402666
17251 345000 1212748.811984
17252 345020 1212848.222164
17253 345040 1212947.633207
17254 345060 1213047.045112
17255 345080 1213146.457879
17256 345100 1213245.871509
17257 345120 1213345.286000
17258 345140 1213444.701354
17259 345160 1213544.117569
17260 345180 1213643.534647
17261 345200 1213742.952586
17262 345220 1213842.371387
17263 345240 1213941.791049
17264 345260 1214041.211574
17265 345280 1214140.632960
17266 345300 1214240.055207
17267 345320 1214339.478317
17268 345340 1214438.902287
17269 345360 1214538.327119
17270 345380 1214637.752812
17271 345400 1214737.179367
17272 345420 1214836.606782
17273 345440 1214936.035059
17274 345460 1215035.464197
17275 345480 1215134.894196
17276 345500 1215234.325056
17277 345520 1215333.756776
17278 345540 1215433.189358
17279 345560 1215532.622801
17280 345580 1215632.057104
17281 345600 1215731.492268
17282 345620 1215830.928292
17283 345640 1215930.365177
17284 345660 1216029.802923
17285 345680 1216129.241529
17286 345700 1216228.680995
17287 345720 1216328.121322
17288 345740 1216427.562508
17289 345760 1216527.004556
17290 345780 1216626.447463
17291 345800 1216725.891230
17292 345820 1216825.335858
17293 345840 1216924.781345
17294 345860 1217024.227692
17295 345880 1217123.674899
17296 345900 1217223.122966
17297 345920 1217322.571893
17298 345940 1217422.021679
17299 345960 1217521.472325
17300 345980 1217620.923831
17301 346000 1217720.376196
17302 346020 1217819.829420
17303 346040 1217919.283504
17304 346060 1218018.738448
17305 346080 1218118.194250
17306 346100 1218217.650912
17307 346120 1218317.108433
17308 346140 1218416.566812
17309 346160 1218516.026051
17310 346180 1218615.486149
17311 346200 1218714.947106
17312 346220 1218814.408922
17313 346240 1218913.871597
17314 346260 1219013.335130
17315 346280 1219112.799522
17316 346300 1219212.264772
17317 346320 1219311.730882
17318 346340 1219411.197849
17319 346360 1219510.665675
17320 346380 1219610.134360
17321 346400 1219709.603903
17322 346420 1219809.074304
17323 346440 1219908.545563
17324 346460 1220008.017681
17325 346480 1220107.490656
17326 346500 1220206.964490
17327 346520 1220306.439182
17328 346540 1220405.914731
17329 346560 1220505.391139
17330 346580 1220604.868404
17331 346600 1220704.346527
17332 346620 1220803.825508
17333 346640 1220903.305346
17334 346660 1221002.786042
17335 346680 1221102.267595
17336 346700 1221201.750006
17337 346720 1221301.233275
17338 346740 1221400.717400
17339 346760 1221500.202383
17340 346780 1221599.688223
17341 346800 1221699.174921
17342 346820 1221798.662475
17343 346840 1221898.150887
17344 346860 1221997.640155
17345 346880 1222097.130281
17346 346900 1222196.621263
17347 346920 1222296.113102
17348 346940 1222395.605798
17349 346960 1222495.099351
17350 346980 1222594.593760
17351 347000 1222694.089026
17352 347020 1222793.585148
17353 347040 1222893.082127
17354 347060 1222992.579963
17355 347080 1223092.078654
17356 347100 1223191.578202
17357 347120 1223291.078606
17358 347140 1223390.579867
17359 347160 1223490.081983
17360 347180 1223589.584956
17361 347200 1223689.088784
17362 347220 1223788.593469
17363 347240 1223888.099009
17364 347260 1223987.605406
17365 347280 1224087.112658
17366 347300 1224186.620765
17367 347320 1224286.129729
17368 347340 1224385.639548
17369 347360 1224485.150222
17370 347380 1224584.661753
17371 347400 1224684.174138
17372 347420 1224783.687379
17373 347440 1224883.201475
17374 347460 1224982.716427
17375 347480 1225082.232233
17376 347500 1225181.748895
17377 347520 1225281.266412
17378 347540 1225380.784784
17379 347560 1225480.304011
17380 347580 1225579.824092
17381 347600 1225679.345029
17382 347620 1225778.866820
17383 347640 1225878.389466
17384 347660 1225977.912967
17385 347680 1226077.437323
17386 347700 1226176.962533
17387 347720 1226276.488597
17388 347740 1226376.015516
17389 347760 1226475.543290
17390 347780 1226575.071917
17391 347800 1226674.601399
17392 347820 1226774.131735
17393 347840 1226873.662926
17394 347860 1226973.194970
17395 347880 1227072.727868
17396 347900 1227172.261621
17397 347920 1227271.796227
17398 347940 1227371.331688
17399 347960 1227470.868002
17400 347980 1227570.405169
17401 348000 1227669.943191
17402 348020 1227769.482066
17403 348040 1227869.021795
17404 348060 1227968.562377
17405 348080 1228068.103813
17406 348100 1228167.646102
17407 348120 1228267.189244
17408 348140 1228366.733240
17409 348160 1228466.278089
17410 348180 1228565.823791
17411 348200 1228665.370346
17412 348220 1228764.917755
17413 348240 1228864.466016
17414 348260 1228964.015130
17415 348280 1229063.565098
17416 348300 1229163.115918
17417 348320 1229262.667590
17418 348340 1229362.220116
17419 348360 1229461.773494
17420 348380 1229561.327725
17421 348400 1229660.882808
17422 348420 1229760.438744
17423 348440 1229859.995532
17424 348460 1229959.553173
17425 348480 1230059.111666
17426 348500 1230158.671011
17427 348520 1230258.231208
17428 348540 1230357.792258
17429 348560 1230457.354159
17430 348580 1230556.916913
17431 348600 1230656.480518
17432 348620 1230756.044976
17433 348640 1230855.610285
17434 348660 1230955.176446
17435 348680 1231054.743459
17436 348700 1231154.311324
17437 348720 1231253.880040
17438 348740 1231353.449608
17439 348760 1231453.020027
17440 348780 1231552.591298
17441 348800 1231652.163420
17442 348820 1231751.736393
17443 348840 1231851.310218
17444 348860 1231950.884894
17445 348880 1232050.460421
17446 348900 1232150.036799
17447 348920 1232249.614028
17448 348940 1232349.192108
17449 348960 1232448.771040
17450 348980 1232548.350822
17451 349000 1232647.931454
17452 349020 1232747.512938
17453 349040 1232847.095272
17454 349060 1232946.678457
17455 349080 1233046.262493
17456 349100 1233145.847379
17457 349120 1233245.433116
17458 349140 1233345.019703
17459 349160 1233444.607140
17460 349180 1233544.195428
17461 349200 1233643.784565
17462 349220 1233743.374554
17463 349240 1233842.965392
17464 349260 1233942.557080
17465 349280 1234042.149618
17466 349300 1234141.743007
17467 349320 1234241.337245
17468 349340 1234340.932333
17469 349360 1234440.528271
17470 349380 1234540.125058
17471 349400 1234639.722695
17472 349420 1234739.321182
17473 349440 1234838.920519
17474 349460 1234938.520705
17475 349480 1235038.121740
17476 349500 1235137.723625
17477 349520 1235237.326359
17478 349540 1235336.929942
17479 349560 1235436.534375
17480 349580 1235536.139656
17481 349600 1235635.745787
17482 349620 1235735.352767
17483 349640 1235834.960596
17484 349660 1235934.569274
17485 349680 1236034.178800
17486 349700 1236133.789176
17487 349720 1236233.400400
17488 349740 1236333.012473
17489 349760 1236432.625394
17490 349780 1236532.239165
17491 349800 1236631.853783
17492 349820 1236731.469250
17493 349840 1236831.085566
17494 349860 1236930.702730
17495 349880 1237030.320742
17496 349900 1237129.939603
17497 349920 1237229.559311
17498 349940 1237329.179868
17499 349960 1237428.801273
17500 349980 1237528.423526
17501 350000 1237628.046627

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