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 33 of 40 · 500/page · 20000 rows next →
# nmargin_tilde
16002 320020 1089278.610178
16003 320040 1089376.894758
16004 320060 1089475.180280
16005 320080 1089573.466745
16006 320100 1089671.754151
16007 320120 1089770.042500
16008 320140 1089868.331790
16009 320160 1089966.622023
16010 320180 1090064.913197
16011 320200 1090163.205313
16012 320220 1090261.498371
16013 320240 1090359.792370
16014 320260 1090458.087311
16015 320280 1090556.383194
16016 320300 1090654.680018
16017 320320 1090752.977783
16018 320340 1090851.276490
16019 320360 1090949.576138
16020 320380 1091047.876727
16021 320400 1091146.178257
16022 320420 1091244.480728
16023 320440 1091342.784140
16024 320460 1091441.088493
16025 320480 1091539.393786
16026 320500 1091637.700021
16027 320520 1091736.007196
16028 320540 1091834.315312
16029 320560 1091932.624368
16030 320580 1092030.934364
16031 320600 1092129.245302
16032 320620 1092227.557179
16033 320640 1092325.869997
16034 320660 1092424.183754
16035 320680 1092522.498452
16036 320700 1092620.814090
16037 320720 1092719.130668
16038 320740 1092817.448186
16039 320760 1092915.766644
16040 320780 1093014.086042
16041 320800 1093112.406379
16042 320820 1093210.727656
16043 320840 1093309.049872
16044 320860 1093407.373028
16045 320880 1093505.697123
16046 320900 1093604.022158
16047 320920 1093702.348132
16048 320940 1093800.675045
16049 320960 1093899.002897
16050 320980 1093997.331688
16051 321000 1094095.661419
16052 321020 1094193.992088
16053 321040 1094292.323696
16054 321060 1094390.656243
16055 321080 1094488.989729
16056 321100 1094587.324153
16057 321120 1094685.659516
16058 321140 1094783.995817
16059 321160 1094882.333057
16060 321180 1094980.671236
16061 321200 1095079.010352
16062 321220 1095177.350407
16063 321240 1095275.691400
16064 321260 1095374.033331
16065 321280 1095472.376200
16066 321300 1095570.720008
16067 321320 1095669.064753
16068 321340 1095767.410435
16069 321360 1095865.757056
16070 321380 1095964.104614
16071 321400 1096062.453110
16072 321420 1096160.802544
16073 321440 1096259.152915
16074 321460 1096357.504223
16075 321480 1096455.856469
16076 321500 1096554.209652
16077 321520 1096652.563772
16078 321540 1096750.918830
16079 321560 1096849.274824
16080 321580 1096947.631755
16081 321600 1097045.989624
16082 321620 1097144.348429
16083 321640 1097242.708171
16084 321660 1097341.068850
16085 321680 1097439.430465
16086 321700 1097537.793017
16087 321720 1097636.156506
16088 321740 1097734.520931
16089 321760 1097832.886292
16090 321780 1097931.252590
16091 321800 1098029.619824
16092 321820 1098127.987994
16093 321840 1098226.357100
16094 321860 1098324.727142
16095 321880 1098423.098121
16096 321900 1098521.470035
16097 321920 1098619.842885
16098 321940 1098718.216671
16099 321960 1098816.591392
16100 321980 1098914.967049
16101 322000 1099013.343642
16102 322020 1099111.721170
16103 322040 1099210.099633
16104 322060 1099308.479032
16105 322080 1099406.859366
16106 322100 1099505.240636
16107 322120 1099603.622840
16108 322140 1099702.005980
16109 322160 1099800.390054
16110 322180 1099898.775064
16111 322200 1099997.161008
16112 322220 1100095.547888
16113 322240 1100193.935702
16114 322260 1100292.324450
16115 322280 1100390.714133
16116 322300 1100489.104751
16117 322320 1100587.496303
16118 322340 1100685.888790
16119 322360 1100784.282211
16120 322380 1100882.676566
16121 322400 1100981.071855
16122 322420 1101079.468079
16123 322440 1101177.865236
16124 322460 1101276.263328
16125 322480 1101374.662353
16126 322500 1101473.062313
16127 322520 1101571.463206
16128 322540 1101669.865032
16129 322560 1101768.267793
16130 322580 1101866.671487
16131 322600 1101965.076114
16132 322620 1102063.481675
16133 322640 1102161.888169
16134 322660 1102260.295597
16135 322680 1102358.703958
16136 322700 1102457.113252
16137 322720 1102555.523479
16138 322740 1102653.934639
16139 322760 1102752.346732
16140 322780 1102850.759758
16141 322800 1102949.173716
16142 322820 1103047.588608
16143 322840 1103146.004432
16144 322860 1103244.421189
16145 322880 1103342.838878
16146 322900 1103441.257500
16147 322920 1103539.677054
16148 322940 1103638.097541
16149 322960 1103736.518959
16150 322980 1103834.941310
16151 323000 1103933.364593
16152 323020 1104031.788809
16153 323040 1104130.213956
16154 323060 1104228.640035
16155 323080 1104327.067046
16156 323100 1104425.494989
16157 323120 1104523.923863
16158 323140 1104622.353670
16159 323160 1104720.784407
16160 323180 1104819.216077
16161 323200 1104917.648677
16162 323220 1105016.082209
16163 323240 1105114.516673
16164 323260 1105212.952068
16165 323280 1105311.388393
16166 323300 1105409.825650
16167 323320 1105508.263838
16168 323340 1105606.702957
16169 323360 1105705.143007
16170 323380 1105803.583988
16171 323400 1105902.025900
16172 323420 1106000.468742
16173 323440 1106098.912515
16174 323460 1106197.357218
16175 323480 1106295.802852
16176 323500 1106394.249417
16177 323520 1106492.696911
16178 323540 1106591.145336
16179 323560 1106689.594692
16180 323580 1106788.044977
16181 323600 1106886.496193
16182 323620 1106984.948338
16183 323640 1107083.401414
16184 323660 1107181.855419
16185 323680 1107280.310354
16186 323700 1107378.766219
16187 323720 1107477.223014
16188 323740 1107575.680738
16189 323760 1107674.139392
16190 323780 1107772.598975
16191 323800 1107871.059488
16192 323820 1107969.520930
16193 323840 1108067.983301
16194 323860 1108166.446602
16195 323880 1108264.910832
16196 323900 1108363.375990
16197 323920 1108461.842078
16198 323940 1108560.309095
16199 323960 1108658.777040
16200 323980 1108757.245915
16201 324000 1108855.715718
16202 324020 1108954.186450
16203 324040 1109052.658110
16204 324060 1109151.130699
16205 324080 1109249.604216
16206 324100 1109348.078662
16207 324120 1109446.554036
16208 324140 1109545.030339
16209 324160 1109643.507569
16210 324180 1109741.985728
16211 324200 1109840.464815
16212 324220 1109938.944829
16213 324240 1110037.425772
16214 324260 1110135.907643
16215 324280 1110234.390441
16216 324300 1110332.874167
16217 324320 1110431.358821
16218 324340 1110529.844402
16219 324360 1110628.330911
16220 324380 1110726.818347
16221 324400 1110825.306711
16222 324420 1110923.796002
16223 324440 1111022.286220
16224 324460 1111120.777365
16225 324480 1111219.269438
16226 324500 1111317.762437
16227 324520 1111416.256364
16228 324540 1111514.751217
16229 324560 1111613.246997
16230 324580 1111711.743704
16231 324600 1111810.241338
16232 324620 1111908.739899
16233 324640 1112007.239386
16234 324660 1112105.739799
16235 324680 1112204.241139
16236 324700 1112302.743405
16237 324720 1112401.246598
16238 324740 1112499.750717
16239 324760 1112598.255762
16240 324780 1112696.761733
16241 324800 1112795.268630
16242 324820 1112893.776453
16243 324840 1112992.285202
16244 324860 1113090.794877
16245 324880 1113189.305477
16246 324900 1113287.817003
16247 324920 1113386.329455
16248 324940 1113484.842833
16249 324960 1113583.357136
16250 324980 1113681.872364
16251 325000 1113780.388518
16252 325020 1113878.905597
16253 325040 1113977.423601
16254 325060 1114075.942531
16255 325080 1114174.462385
16256 325100 1114272.983165
16257 325120 1114371.504869
16258 325140 1114470.027499
16259 325160 1114568.551053
16260 325180 1114667.075532
16261 325200 1114765.600935
16262 325220 1114864.127264
16263 325240 1114962.654516
16264 325260 1115061.182694
16265 325280 1115159.711796
16266 325300 1115258.241822
16267 325320 1115356.772772
16268 325340 1115455.304647
16269 325360 1115553.837445
16270 325380 1115652.371168
16271 325400 1115750.905815
16272 325420 1115849.441386
16273 325440 1115947.977880
16274 325460 1116046.515299
16275 325480 1116145.053641
16276 325500 1116243.592907
16277 325520 1116342.133097
16278 325540 1116440.674210
16279 325560 1116539.216246
16280 325580 1116637.759206
16281 325600 1116736.303089
16282 325620 1116834.847896
16283 325640 1116933.393626
16284 325660 1117031.940279
16285 325680 1117130.487855
16286 325700 1117229.036354
16287 325720 1117327.585776
16288 325740 1117426.136121
16289 325760 1117524.687388
16290 325780 1117623.239579
16291 325800 1117721.792692
16292 325820 1117820.346728
16293 325840 1117918.901686
16294 325860 1118017.457567
16295 325880 1118116.014370
16296 325900 1118214.572095
16297 325920 1118313.130743
16298 325940 1118411.690313
16299 325960 1118510.250805
16300 325980 1118608.812219
16301 326000 1118707.374555
16302 326020 1118805.937813
16303 326040 1118904.501993
16304 326060 1119003.067095
16305 326080 1119101.633119
16306 326100 1119200.200064
16307 326120 1119298.767931
16308 326140 1119397.336719
16309 326160 1119495.906429
16310 326180 1119594.477060
16311 326200 1119693.048613
16312 326220 1119791.621087
16313 326240 1119890.194482
16314 326260 1119988.768798
16315 326280 1120087.344035
16316 326300 1120185.920193
16317 326320 1120284.497273
16318 326340 1120383.075273
16319 326360 1120481.654194
16320 326380 1120580.234035
16321 326400 1120678.814798
16322 326420 1120777.396480
16323 326440 1120875.979084
16324 326460 1120974.562608
16325 326480 1121073.147052
16326 326500 1121171.732417
16327 326520 1121270.318702
16328 326540 1121368.905907
16329 326560 1121467.494032
16330 326580 1121566.083078
16331 326600 1121664.673043
16332 326620 1121763.263928
16333 326640 1121861.855734
16334 326660 1121960.448459
16335 326680 1122059.042103
16336 326700 1122157.636668
16337 326720 1122256.232152
16338 326740 1122354.828555
16339 326760 1122453.425878
16340 326780 1122552.024121
16341 326800 1122650.623283
16342 326820 1122749.223364
16343 326840 1122847.824364
16344 326860 1122946.426283
16345 326880 1123045.029122
16346 326900 1123143.632879
16347 326920 1123242.237556
16348 326940 1123340.843151
16349 326960 1123439.449665
16350 326980 1123538.057098
16351 327000 1123636.665450
16352 327020 1123735.274720
16353 327040 1123833.884909
16354 327060 1123932.496016
16355 327080 1124031.108042
16356 327100 1124129.720986
16357 327120 1124228.334848
16358 327140 1124326.949628
16359 327160 1124425.565327
16360 327180 1124524.181944
16361 327200 1124622.799478
16362 327220 1124721.417931
16363 327240 1124820.037301
16364 327260 1124918.657590
16365 327280 1125017.278796
16366 327300 1125115.900920
16367 327320 1125214.523961
16368 327340 1125313.147920
16369 327360 1125411.772797
16370 327380 1125510.398590
16371 327400 1125609.025302
16372 327420 1125707.652930
16373 327440 1125806.281476
16374 327460 1125904.910939
16375 327480 1126003.541319
16376 327500 1126102.172616
16377 327520 1126200.804830
16378 327540 1126299.437960
16379 327560 1126398.072008
16380 327580 1126496.706972
16381 327600 1126595.342854
16382 327620 1126693.979651
16383 327640 1126792.617366
16384 327660 1126891.255996
16385 327680 1126989.895544
16386 327700 1127088.536007
16387 327720 1127187.177387
16388 327740 1127285.819683
16389 327760 1127384.462895
16390 327780 1127483.107024
16391 327800 1127581.752068
16392 327820 1127680.398028
16393 327840 1127779.044905
16394 327860 1127877.692697
16395 327880 1127976.341405
16396 327900 1128074.991028
16397 327920 1128173.641567
16398 327940 1128272.293022
16399 327960 1128370.945392
16400 327980 1128469.598678
16401 328000 1128568.252879
16402 328020 1128666.907996
16403 328040 1128765.564027
16404 328060 1128864.220974
16405 328080 1128962.878836
16406 328100 1129061.537613
16407 328120 1129160.197305
16408 328140 1129258.857912
16409 328160 1129357.519433
16410 328180 1129456.181870
16411 328200 1129554.845221
16412 328220 1129653.509487
16413 328240 1129752.174667
16414 328260 1129850.840762
16415 328280 1129949.507771
16416 328300 1130048.175695
16417 328320 1130146.844533
16418 328340 1130245.514286
16419 328360 1130344.184952
16420 328380 1130442.856533
16421 328400 1130541.529027
16422 328420 1130640.202436
16423 328440 1130738.876759
16424 328460 1130837.551995
16425 328480 1130936.228145
16426 328500 1131034.905209
16427 328520 1131133.583187
16428 328540 1131232.262078
16429 328560 1131330.941883
16430 328580 1131429.622601
16431 328600 1131528.304233
16432 328620 1131626.986778
16433 328640 1131725.670236
16434 328660 1131824.354607
16435 328680 1131923.039892
16436 328700 1132021.726089
16437 328720 1132120.413200
16438 328740 1132219.101224
16439 328760 1132317.790160
16440 328780 1132416.480009
16441 328800 1132515.170771
16442 328820 1132613.862446
16443 328840 1132712.555033
16444 328860 1132811.248533
16445 328880 1132909.942945
16446 328900 1133008.638270
16447 328920 1133107.334507
16448 328940 1133206.031657
16449 328960 1133304.729718
16450 328980 1133403.428692
16451 329000 1133502.128578
16452 329020 1133600.829376
16453 329040 1133699.531085
16454 329060 1133798.233707
16455 329080 1133896.937241
16456 329100 1133995.641686
16457 329120 1134094.347043
16458 329140 1134193.053311
16459 329160 1134291.760492
16460 329180 1134390.468583
16461 329200 1134489.177586
16462 329220 1134587.887501
16463 329240 1134686.598327
16464 329260 1134785.310064
16465 329280 1134884.022712
16466 329300 1134982.736271
16467 329320 1135081.450741
16468 329340 1135180.166123
16469 329360 1135278.882415
16470 329380 1135377.599618
16471 329400 1135476.317732
16472 329420 1135575.036756
16473 329440 1135673.756692
16474 329460 1135772.477537
16475 329480 1135871.199294
16476 329500 1135969.921960
16477 329520 1136068.645538
16478 329540 1136167.370025
16479 329560 1136266.095423
16480 329580 1136364.821731
16481 329600 1136463.548949
16482 329620 1136562.277077
16483 329640 1136661.006115
16484 329660 1136759.736063
16485 329680 1136858.466921
16486 329700 1136957.198689
16487 329720 1137055.931366
16488 329740 1137154.664953
16489 329760 1137253.399450
16490 329780 1137352.134856
16491 329800 1137450.871172
16492 329820 1137549.608397
16493 329840 1137648.346532
16494 329860 1137747.085575
16495 329880 1137845.825528
16496 329900 1137944.566391
16497 329920 1138043.308162
16498 329940 1138142.050842
16499 329960 1138240.794431
16500 329980 1138339.538929
16501 330000 1138438.284336

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