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 40 of 40 · 500/page · 20000 rows
# nmargin_tilde
19502 390020 1438600.686870
19503 390040 1438701.902281
19504 390060 1438803.118438
19505 390080 1438904.335342
19506 390100 1439005.552993
19507 390120 1439106.771391
19508 390140 1439207.990536
19509 390160 1439309.210427
19510 390180 1439410.431064
19511 390200 1439511.652448
19512 390220 1439612.874579
19513 390240 1439714.097456
19514 390260 1439815.321080
19515 390280 1439916.545449
19516 390300 1440017.770565
19517 390320 1440118.996428
19518 390340 1440220.223036
19519 390360 1440321.450391
19520 390380 1440422.678492
19521 390400 1440523.907339
19522 390420 1440625.136932
19523 390440 1440726.367271
19524 390460 1440827.598356
19525 390480 1440928.830186
19526 390500 1441030.062763
19527 390520 1441131.296086
19528 390540 1441232.530154
19529 390560 1441333.764968
19530 390580 1441435.000527
19531 390600 1441536.236833
19532 390620 1441637.473884
19533 390640 1441738.711680
19534 390660 1441839.950222
19535 390680 1441941.189509
19536 390700 1442042.429542
19537 390720 1442143.670320
19538 390740 1442244.911844
19539 390760 1442346.154112
19540 390780 1442447.397126
19541 390800 1442548.640886
19542 390820 1442649.885390
19543 390840 1442751.130639
19544 390860 1442852.376634
19545 390880 1442953.623373
19546 390900 1443054.870858
19547 390920 1443156.119087
19548 390940 1443257.368061
19549 390960 1443358.617780
19550 390980 1443459.868244
19551 391000 1443561.119453
19552 391020 1443662.371406
19553 391040 1443763.624104
19554 391060 1443864.877547
19555 391080 1443966.131734
19556 391100 1444067.386666
19557 391120 1444168.642342
19558 391140 1444269.898762
19559 391160 1444371.155927
19560 391180 1444472.413836
19561 391200 1444573.672490
19562 391220 1444674.931888
19563 391240 1444776.192030
19564 391260 1444877.452916
19565 391280 1444978.714547
19566 391300 1445079.976921
19567 391320 1445181.240039
19568 391340 1445282.503902
19569 391360 1445383.768508
19570 391380 1445485.033859
19571 391400 1445586.299953
19572 391420 1445687.566791
19573 391440 1445788.834372
19574 391460 1445890.102698
19575 391480 1445991.371767
19576 391500 1446092.641580
19577 391520 1446193.912136
19578 391540 1446295.183436
19579 391560 1446396.455479
19580 391580 1446497.728266
19581 391600 1446599.001796
19582 391620 1446700.276070
19583 391640 1446801.551087
19584 391660 1446902.826847
19585 391680 1447004.103351
19586 391700 1447105.380597
19587 391720 1447206.658587
19588 391740 1447307.937320
19589 391760 1447409.216796
19590 391780 1447510.497015
19591 391800 1447611.777977
19592 391820 1447713.059681
19593 391840 1447814.342129
19594 391860 1447915.625320
19595 391880 1448016.909253
19596 391900 1448118.193929
19597 391920 1448219.479348
19598 391940 1448320.765509
19599 391960 1448422.052414
19600 391980 1448523.340060
19601 392000 1448624.628449
19602 392020 1448725.917581
19603 392040 1448827.207455
19604 392060 1448928.498072
19605 392080 1449029.789430
19606 392100 1449131.081532
19607 392120 1449232.374375
19608 392140 1449333.667961
19609 392160 1449434.962288
19610 392180 1449536.257358
19611 392200 1449637.553170
19612 392220 1449738.849724
19613 392240 1449840.147020
19614 392260 1449941.445058
19615 392280 1450042.743838
19616 392300 1450144.043360
19617 392320 1450245.343623
19618 392340 1450346.644629
19619 392360 1450447.946376
19620 392380 1450549.248865
19621 392400 1450650.552095
19622 392420 1450751.856067
19623 392440 1450853.160781
19624 392460 1450954.466236
19625 392480 1451055.772432
19626 392500 1451157.079370
19627 392520 1451258.387049
19628 392540 1451359.695470
19629 392560 1451461.004632
19630 392580 1451562.314535
19631 392600 1451663.625180
19632 392620 1451764.936565
19633 392640 1451866.248692
19634 392660 1451967.561560
19635 392680 1452068.875168
19636 392700 1452170.189518
19637 392720 1452271.504609
19638 392740 1452372.820440
19639 392760 1452474.137013
19640 392780 1452575.454326
19641 392800 1452676.772380
19642 392820 1452778.091175
19643 392840 1452879.410710
19644 392860 1452980.730986
19645 392880 1453082.052003
19646 392900 1453183.373760
19647 392920 1453284.696257
19648 392940 1453386.019495
19649 392960 1453487.343474
19650 392980 1453588.668193
19651 393000 1453689.993652
19652 393020 1453791.319851
19653 393040 1453892.646791
19654 393060 1453993.974471
19655 393080 1454095.302891
19656 393100 1454196.632051
19657 393120 1454297.961951
19658 393140 1454399.292591
19659 393160 1454500.623971
19660 393180 1454601.956092
19661 393200 1454703.288951
19662 393220 1454804.622551
19663 393240 1454905.956891
19664 393260 1455007.291970
19665 393280 1455108.627789
19666 393300 1455209.964348
19667 393320 1455311.301646
19668 393340 1455412.639684
19669 393360 1455513.978462
19670 393380 1455615.317978
19671 393400 1455716.658235
19672 393420 1455817.999231
19673 393440 1455919.340966
19674 393460 1456020.683440
19675 393480 1456122.026654
19676 393500 1456223.370607
19677 393520 1456324.715299
19678 393540 1456426.060730
19679 393560 1456527.406900
19680 393580 1456628.753810
19681 393600 1456730.101458
19682 393620 1456831.449845
19683 393640 1456932.798971
19684 393660 1457034.148837
19685 393680 1457135.499440
19686 393700 1457236.850783
19687 393720 1457338.202865
19688 393740 1457439.555685
19689 393760 1457540.909244
19690 393780 1457642.263541
19691 393800 1457743.618577
19692 393820 1457844.974351
19693 393840 1457946.330864
19694 393860 1458047.688116
19695 393880 1458149.046106
19696 393900 1458250.404834
19697 393920 1458351.764300
19698 393940 1458453.124505
19699 393960 1458554.485448
19700 393980 1458655.847129
19701 394000 1458757.209548
19702 394020 1458858.572706
19703 394040 1458959.936601
19704 394060 1459061.301234
19705 394080 1459162.666606
19706 394100 1459264.032715
19707 394120 1459365.399562
19708 394140 1459466.767147
19709 394160 1459568.135469
19710 394180 1459669.504530
19711 394200 1459770.874328
19712 394220 1459872.244864
19713 394240 1459973.616137
19714 394260 1460074.988148
19715 394280 1460176.360896
19716 394300 1460277.734382
19717 394320 1460379.108606
19718 394340 1460480.483566
19719 394360 1460581.859264
19720 394380 1460683.235700
19721 394400 1460784.612872
19722 394420 1460885.990782
19723 394440 1460987.369429
19724 394460 1461088.748813
19725 394480 1461190.128934
19726 394500 1461291.509793
19727 394520 1461392.891388
19728 394540 1461494.273720
19729 394560 1461595.656789
19730 394580 1461697.040595
19731 394600 1461798.425138
19732 394620 1461899.810417
19733 394640 1462001.196433
19734 394660 1462102.583186
19735 394680 1462203.970676
19736 394700 1462305.358902
19737 394720 1462406.747865
19738 394740 1462508.137564
19739 394760 1462609.528000
19740 394780 1462710.919172
19741 394800 1462812.311081
19742 394820 1462913.703725
19743 394840 1463015.097107
19744 394860 1463116.491224
19745 394880 1463217.886078
19746 394900 1463319.281667
19747 394920 1463420.677993
19748 394940 1463522.075055
19749 394960 1463623.472853
19750 394980 1463724.871387
19751 395000 1463826.270657
19752 395020 1463927.670663
19753 395040 1464029.071405
19754 395060 1464130.472883
19755 395080 1464231.875096
19756 395100 1464333.278045
19757 395120 1464434.681730
19758 395140 1464536.086150
19759 395160 1464637.491306
19760 395180 1464738.897198
19761 395200 1464840.303825
19762 395220 1464941.711187
19763 395240 1465043.119285
19764 395260 1465144.528118
19765 395280 1465245.937687
19766 395300 1465347.347991
19767 395320 1465448.759030
19768 395340 1465550.170805
19769 395360 1465651.583314
19770 395380 1465752.996559
19771 395400 1465854.410539
19772 395420 1465955.825254
19773 395440 1466057.240703
19774 395460 1466158.656888
19775 395480 1466260.073808
19776 395500 1466361.491462
19777 395520 1466462.909852
19778 395540 1466564.328976
19779 395560 1466665.748835
19780 395580 1466767.169428
19781 395600 1466868.590756
19782 395620 1466970.012819
19783 395640 1467071.435617
19784 395660 1467172.859148
19785 395680 1467274.283415
19786 395700 1467375.708416
19787 395720 1467477.134151
19788 395740 1467578.560620
19789 395760 1467679.987824
19790 395780 1467781.415762
19791 395800 1467882.844434
19792 395820 1467984.273841
19793 395840 1468085.703981
19794 395860 1468187.134856
19795 395880 1468288.566465
19796 395900 1468389.998807
19797 395920 1468491.431884
19798 395940 1468592.865695
19799 395960 1468694.300239
19800 395980 1468795.735517
19801 396000 1468897.171529
19802 396020 1468998.608275
19803 396040 1469100.045754
19804 396060 1469201.483967
19805 396080 1469302.922914
19806 396100 1469404.362594
19807 396120 1469505.803008
19808 396140 1469607.244155
19809 396160 1469708.686036
19810 396180 1469810.128650
19811 396200 1469911.571998
19812 396220 1470013.016078
19813 396240 1470114.460892
19814 396260 1470215.906440
19815 396280 1470317.352720
19816 396300 1470418.799733
19817 396320 1470520.247480
19818 396340 1470621.695960
19819 396360 1470723.145172
19820 396380 1470824.595118
19821 396400 1470926.045796
19822 396420 1471027.497208
19823 396440 1471128.949352
19824 396460 1471230.402229
19825 396480 1471331.855839
19826 396500 1471433.310181
19827 396520 1471534.765256
19828 396540 1471636.221064
19829 396560 1471737.677604
19830 396580 1471839.134877
19831 396600 1471940.592883
19832 396620 1472042.051620
19833 396640 1472143.511090
19834 396660 1472244.971293
19835 396680 1472346.432228
19836 396700 1472447.893895
19837 396720 1472549.356294
19838 396740 1472650.819426
19839 396760 1472752.283289
19840 396780 1472853.747885
19841 396800 1472955.213213
19842 396820 1473056.679273
19843 396840 1473158.146064
19844 396860 1473259.613588
19845 396880 1473361.081844
19846 396900 1473462.550831
19847 396920 1473564.020550
19848 396940 1473665.491001
19849 396960 1473766.962184
19850 396980 1473868.434098
19851 397000 1473969.906744
19852 397020 1474071.380122
19853 397040 1474172.854231
19854 397060 1474274.329071
19855 397080 1474375.804643
19856 397100 1474477.280947
19857 397120 1474578.757982
19858 397140 1474680.235748
19859 397160 1474781.714245
19860 397180 1474883.193474
19861 397200 1474984.673434
19862 397220 1475086.154125
19863 397240 1475187.635547
19864 397260 1475289.117700
19865 397280 1475390.600584
19866 397300 1475492.084199
19867 397320 1475593.568545
19868 397340 1475695.053622
19869 397360 1475796.539430
19870 397380 1475898.025969
19871 397400 1475999.513238
19872 397420 1476101.001238
19873 397440 1476202.489969
19874 397460 1476303.979430
19875 397480 1476405.469623
19876 397500 1476506.960545
19877 397520 1476608.452198
19878 397540 1476709.944582
19879 397560 1476811.437696
19880 397580 1476912.931540
19881 397600 1477014.426115
19882 397620 1477115.921420
19883 397640 1477217.417455
19884 397660 1477318.914220
19885 397680 1477420.411716
19886 397700 1477521.909942
19887 397720 1477623.408898
19888 397740 1477724.908583
19889 397760 1477826.408999
19890 397780 1477927.910145
19891 397800 1478029.412021
19892 397820 1478130.914626
19893 397840 1478232.417962
19894 397860 1478333.922027
19895 397880 1478435.426822
19896 397900 1478536.932346
19897 397920 1478638.438601
19898 397940 1478739.945585
19899 397960 1478841.453298
19900 397980 1478942.961741
19901 398000 1479044.470913
19902 398020 1479145.980815
19903 398040 1479247.491446
19904 398060 1479349.002807
19905 398080 1479450.514897
19906 398100 1479552.027716
19907 398120 1479653.541265
19908 398140 1479755.055542
19909 398160 1479856.570549
19910 398180 1479958.086285
19911 398200 1480059.602750
19912 398220 1480161.119943
19913 398240 1480262.637866
19914 398260 1480364.156518
19915 398280 1480465.675899
19916 398300 1480567.196008
19917 398320 1480668.716846
19918 398340 1480770.238414
19919 398360 1480871.760709
19920 398380 1480973.283734
19921 398400 1481074.807487
19922 398420 1481176.331968
19923 398440 1481277.857179
19924 398460 1481379.383117
19925 398480 1481480.909784
19926 398500 1481582.437180
19927 398520 1481683.965304
19928 398540 1481785.494156
19929 398560 1481887.023737
19930 398580 1481988.554045
19931 398600 1482090.085082
19932 398620 1482191.616847
19933 398640 1482293.149341
19934 398660 1482394.682562
19935 398680 1482496.216511
19936 398700 1482597.751189
19937 398720 1482699.286594
19938 398740 1482800.822727
19939 398760 1482902.359588
19940 398780 1483003.897177
19941 398800 1483105.435493
19942 398820 1483206.974538
19943 398840 1483308.514310
19944 398860 1483410.054809
19945 398880 1483511.596037
19946 398900 1483613.137992
19947 398920 1483714.680674
19948 398940 1483816.224084
19949 398960 1483917.768221
19950 398980 1484019.313086
19951 399000 1484120.858678
19952 399020 1484222.404997
19953 399040 1484323.952044
19954 399060 1484425.499817
19955 399080 1484527.048318
19956 399100 1484628.597546
19957 399120 1484730.147502
19958 399140 1484831.698184
19959 399160 1484933.249593
19960 399180 1485034.801729
19961 399200 1485136.354593
19962 399220 1485237.908183
19963 399240 1485339.462499
19964 399260 1485441.017543
19965 399280 1485542.573314
19966 399300 1485644.129811
19967 399320 1485745.687034
19968 399340 1485847.244985
19969 399360 1485948.803662
19970 399380 1486050.363065
19971 399400 1486151.923195
19972 399420 1486253.484052
19973 399440 1486355.045635
19974 399460 1486456.607944
19975 399480 1486558.170980
19976 399500 1486659.734742
19977 399520 1486761.299230
19978 399540 1486862.864444
19979 399560 1486964.430385
19980 399580 1487065.997051
19981 399600 1487167.564444
19982 399620 1487269.132563
19983 399640 1487370.701407
19984 399660 1487472.270978
19985 399680 1487573.841275
19986 399700 1487675.412297
19987 399720 1487776.984045
19988 399740 1487878.556519
19989 399760 1487980.129719
19990 399780 1488081.703645
19991 399800 1488183.278296
19992 399820 1488284.853672
19993 399840 1488386.429775
19994 399860 1488488.006603
19995 399880 1488589.584156
19996 399900 1488691.162435
19997 399920 1488792.741439
19998 399940 1488894.321168
19999 399960 1488995.901623
20000 399980 1489097.482803
20001 400000 1489199.064708

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