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 32 of 40 · 500/page · 20000 rows next →
# nmargin_tilde
15502 310020 1040255.824975
15503 310040 1040353.629489
15504 310060 1040451.434981
15505 310080 1040549.241452
15506 310100 1040647.048901
15507 310120 1040744.857328
15508 310140 1040842.666733
15509 310160 1040940.477116
15510 310180 1041038.288477
15511 310200 1041136.100816
15512 310220 1041233.914132
15513 310240 1041331.728427
15514 310260 1041429.543699
15515 310280 1041527.359948
15516 310300 1041625.177175
15517 310320 1041722.995379
15518 310340 1041820.814560
15519 310360 1041918.634719
15520 310380 1042016.455855
15521 310400 1042114.277968
15522 310420 1042212.101058
15523 310440 1042309.925125
15524 310460 1042407.750169
15525 310480 1042505.576189
15526 310500 1042603.403187
15527 310520 1042701.231161
15528 310540 1042799.060111
15529 310560 1042896.890038
15530 310580 1042994.720942
15531 310600 1043092.552821
15532 310620 1043190.385677
15533 310640 1043288.219509
15534 310660 1043386.054318
15535 310680 1043483.890102
15536 310700 1043581.726862
15537 310720 1043679.564599
15538 310740 1043777.403311
15539 310760 1043875.242998
15540 310780 1043973.083662
15541 310800 1044070.925301
15542 310820 1044168.767915
15543 310840 1044266.611505
15544 310860 1044364.456071
15545 310880 1044462.301611
15546 310900 1044560.148127
15547 310920 1044657.995618
15548 310940 1044755.844084
15549 310960 1044853.693525
15550 310980 1044951.543941
15551 311000 1045049.395332
15552 311020 1045147.247698
15553 311040 1045245.101038
15554 311060 1045342.955353
15555 311080 1045440.810643
15556 311100 1045538.666907
15557 311120 1045636.524145
15558 311140 1045734.382358
15559 311160 1045832.241545
15560 311180 1045930.101706
15561 311200 1046027.962841
15562 311220 1046125.824950
15563 311240 1046223.688034
15564 311260 1046321.552091
15565 311280 1046419.417122
15566 311300 1046517.283127
15567 311320 1046615.150105
15568 311340 1046713.018057
15569 311360 1046810.886982
15570 311380 1046908.756881
15571 311400 1047006.627753
15572 311420 1047104.499599
15573 311440 1047202.372418
15574 311460 1047300.246210
15575 311480 1047398.120975
15576 311500 1047495.996713
15577 311520 1047593.873424
15578 311540 1047691.751107
15579 311560 1047789.629764
15580 311580 1047887.509393
15581 311600 1047985.389995
15582 311620 1048083.271569
15583 311640 1048181.154116
15584 311660 1048279.037636
15585 311680 1048376.922127
15586 311700 1048474.807591
15587 311720 1048572.694027
15588 311740 1048670.581435
15589 311760 1048768.469816
15590 311780 1048866.359168
15591 311800 1048964.249492
15592 311820 1049062.140788
15593 311840 1049160.033055
15594 311860 1049257.926294
15595 311880 1049355.820505
15596 311900 1049453.715688
15597 311920 1049551.611842
15598 311940 1049649.508967
15599 311960 1049747.407063
15600 311980 1049845.306131
15601 312000 1049943.206170
15602 312020 1050041.107180
15603 312040 1050139.009161
15604 312060 1050236.912113
15605 312080 1050334.816035
15606 312100 1050432.720929
15607 312120 1050530.626793
15608 312140 1050628.533628
15609 312160 1050726.441433
15610 312180 1050824.350209
15611 312200 1050922.259955
15612 312220 1051020.170672
15613 312240 1051118.082359
15614 312260 1051215.995016
15615 312280 1051313.908643
15616 312300 1051411.823241
15617 312320 1051509.738808
15618 312340 1051607.655345
15619 312360 1051705.572852
15620 312380 1051803.491329
15621 312400 1051901.410775
15622 312420 1051999.331191
15623 312440 1052097.252576
15624 312460 1052195.174931
15625 312480 1052293.098256
15626 312500 1052391.022549
15627 312520 1052488.947812
15628 312540 1052586.874044
15629 312560 1052684.801245
15630 312580 1052782.729415
15631 312600 1052880.658555
15632 312620 1052978.588663
15633 312640 1053076.519739
15634 312660 1053174.451785
15635 312680 1053272.384799
15636 312700 1053370.318782
15637 312720 1053468.253733
15638 312740 1053566.189652
15639 312760 1053664.126540
15640 312780 1053762.064397
15641 312800 1053860.003221
15642 312820 1053957.943014
15643 312840 1054055.883774
15644 312860 1054153.825503
15645 312880 1054251.768200
15646 312900 1054349.711864
15647 312920 1054447.656496
15648 312940 1054545.602096
15649 312960 1054643.548663
15650 312980 1054741.496198
15651 313000 1054839.444701
15652 313020 1054937.394171
15653 313040 1055035.344608
15654 313060 1055133.296013
15655 313080 1055231.248384
15656 313100 1055329.201723
15657 313120 1055427.156029
15658 313140 1055525.111302
15659 313160 1055623.067541
15660 313180 1055721.024748
15661 313200 1055818.982921
15662 313220 1055916.942061
15663 313240 1056014.902167
15664 313260 1056112.863240
15665 313280 1056210.825280
15666 313300 1056308.788286
15667 313320 1056406.752258
15668 313340 1056504.717196
15669 313360 1056602.683101
15670 313380 1056700.649971
15671 313400 1056798.617808
15672 313420 1056896.586611
15673 313440 1056994.556379
15674 313460 1057092.527113
15675 313480 1057190.498813
15676 313500 1057288.471479
15677 313520 1057386.445110
15678 313540 1057484.419707
15679 313560 1057582.395269
15680 313580 1057680.371796
15681 313600 1057778.349289
15682 313620 1057876.327747
15683 313640 1057974.307170
15684 313660 1058072.287558
15685 313680 1058170.268911
15686 313700 1058268.251229
15687 313720 1058366.234512
15688 313740 1058464.218760
15689 313760 1058562.203972
15690 313780 1058660.190149
15691 313800 1058758.177291
15692 313820 1058856.165397
15693 313840 1058954.154467
15694 313860 1059052.144502
15695 313880 1059150.135501
15696 313900 1059248.127465
15697 313920 1059346.120392
15698 313940 1059444.114283
15699 313960 1059542.109139
15700 313980 1059640.104958
15701 314000 1059738.101741
15702 314020 1059836.099488
15703 314040 1059934.098198
15704 314060 1060032.097873
15705 314080 1060130.098510
15706 314100 1060228.100111
15707 314120 1060326.102676
15708 314140 1060424.106204
15709 314160 1060522.110695
15710 314180 1060620.116149
15711 314200 1060718.122567
15712 314220 1060816.129947
15713 314240 1060914.138290
15714 314260 1061012.147597
15715 314280 1061110.157866
15716 314300 1061208.169097
15717 314320 1061306.181292
15718 314340 1061404.194449
15719 314360 1061502.208568
15720 314380 1061600.223650
15721 314400 1061698.239695
15722 314420 1061796.256701
15723 314440 1061894.274670
15724 314460 1061992.293601
15725 314480 1062090.313495
15726 314500 1062188.334350
15727 314520 1062286.356167
15728 314540 1062384.378946
15729 314560 1062482.402687
15730 314580 1062580.427389
15731 314600 1062678.453053
15732 314620 1062776.479679
15733 314640 1062874.507266
15734 314660 1062972.535815
15735 314680 1063070.565325
15736 314700 1063168.595796
15737 314720 1063266.627229
15738 314740 1063364.659622
15739 314760 1063462.692977
15740 314780 1063560.727293
15741 314800 1063658.762570
15742 314820 1063756.798807
15743 314840 1063854.836005
15744 314860 1063952.874164
15745 314880 1064050.913284
15746 314900 1064148.953364
15747 314920 1064246.994405
15748 314940 1064345.036406
15749 314960 1064443.079368
15750 314980 1064541.123289
15751 315000 1064639.168171
15752 315020 1064737.214013
15753 315040 1064835.260816
15754 315060 1064933.308578
15755 315080 1065031.357300
15756 315100 1065129.406982
15757 315120 1065227.457623
15758 315140 1065325.509225
15759 315160 1065423.561786
15760 315180 1065521.615306
15761 315200 1065619.669786
15762 315220 1065717.725226
15763 315240 1065815.781625
15764 315260 1065913.838983
15765 315280 1066011.897300
15766 315300 1066109.956576
15767 315320 1066208.016812
15768 315340 1066306.078006
15769 315360 1066404.140159
15770 315380 1066502.203272
15771 315400 1066600.267343
15772 315420 1066698.332372
15773 315440 1066796.398360
15774 315460 1066894.465307
15775 315480 1066992.533212
15776 315500 1067090.602076
15777 315520 1067188.671898
15778 315540 1067286.742678
15779 315560 1067384.814417
15780 315580 1067482.887113
15781 315600 1067580.960768
15782 315620 1067679.035380
15783 315640 1067777.110951
15784 315660 1067875.187479
15785 315680 1067973.264965
15786 315700 1068071.343409
15787 315720 1068169.422810
15788 315740 1068267.503169
15789 315760 1068365.584485
15790 315780 1068463.666759
15791 315800 1068561.749990
15792 315820 1068659.834179
15793 315840 1068757.919324
15794 315860 1068856.005427
15795 315880 1068954.092486
15796 315900 1069052.180503
15797 315920 1069150.269477
15798 315940 1069248.359407
15799 315960 1069346.450294
15800 315980 1069444.542138
15801 316000 1069542.634938
15802 316020 1069640.728695
15803 316040 1069738.823409
15804 316060 1069836.919078
15805 316080 1069935.015704
15806 316100 1070033.113287
15807 316120 1070131.211825
15808 316140 1070229.311320
15809 316160 1070327.411771
15810 316180 1070425.513177
15811 316200 1070523.615540
15812 316220 1070621.718858
15813 316240 1070719.823132
15814 316260 1070817.928362
15815 316280 1070916.034547
15816 316300 1071014.141688
15817 316320 1071112.249785
15818 316340 1071210.358837
15819 316360 1071308.468844
15820 316380 1071406.579806
15821 316400 1071504.691723
15822 316420 1071602.804596
15823 316440 1071700.918424
15824 316460 1071799.033206
15825 316480 1071897.148944
15826 316500 1071995.265636
15827 316520 1072093.383283
15828 316540 1072191.501885
15829 316560 1072289.621441
15830 316580 1072387.741952
15831 316600 1072485.863418
15832 316620 1072583.985837
15833 316640 1072682.109212
15834 316660 1072780.233540
15835 316680 1072878.358822
15836 316700 1072976.485059
15837 316720 1073074.612250
15838 316740 1073172.740394
15839 316760 1073270.869493
15840 316780 1073368.999545
15841 316800 1073467.130551
15842 316820 1073565.262511
15843 316840 1073663.395424
15844 316860 1073761.529291
15845 316880 1073859.664112
15846 316900 1073957.799885
15847 316920 1074055.936612
15848 316940 1074154.074293
15849 316960 1074252.212926
15850 316980 1074350.352513
15851 317000 1074448.493052
15852 317020 1074546.634545
15853 317040 1074644.776991
15854 317060 1074742.920389
15855 317080 1074841.064740
15856 317100 1074939.210044
15857 317120 1075037.356300
15858 317140 1075135.503509
15859 317160 1075233.651671
15860 317180 1075331.800784
15861 317200 1075429.950850
15862 317220 1075528.101869
15863 317240 1075626.253839
15864 317260 1075724.406762
15865 317280 1075822.560637
15866 317300 1075920.715464
15867 317320 1076018.871242
15868 317340 1076117.027973
15869 317360 1076215.185655
15870 317380 1076313.344289
15871 317400 1076411.503874
15872 317420 1076509.664411
15873 317440 1076607.825900
15874 317460 1076705.988340
15875 317480 1076804.151731
15876 317500 1076902.316073
15877 317520 1077000.481367
15878 317540 1077098.647612
15879 317560 1077196.814808
15880 317580 1077294.982954
15881 317600 1077393.152052
15882 317620 1077491.322101
15883 317640 1077589.493100
15884 317660 1077687.665050
15885 317680 1077785.837951
15886 317700 1077884.011802
15887 317720 1077982.186604
15888 317740 1078080.362356
15889 317760 1078178.539058
15890 317780 1078276.716711
15891 317800 1078374.895314
15892 317820 1078473.074867
15893 317840 1078571.255370
15894 317860 1078669.436823
15895 317880 1078767.619226
15896 317900 1078865.802579
15897 317920 1078963.986882
15898 317940 1079062.172134
15899 317960 1079160.358336
15900 317980 1079258.545488
15901 318000 1079356.733589
15902 318020 1079454.922639
15903 318040 1079553.112639
15904 318060 1079651.303588
15905 318080 1079749.495486
15906 318100 1079847.688334
15907 318120 1079945.882130
15908 318140 1080044.076876
15909 318160 1080142.272570
15910 318180 1080240.469214
15911 318200 1080338.666806
15912 318220 1080436.865347
15913 318240 1080535.064836
15914 318260 1080633.265274
15915 318280 1080731.466660
15916 318300 1080829.668995
15917 318320 1080927.872279
15918 318340 1081026.076510
15919 318360 1081124.281690
15920 318380 1081222.487818
15921 318400 1081320.694894
15922 318420 1081418.902918
15923 318440 1081517.111890
15924 318460 1081615.321810
15925 318480 1081713.532678
15926 318500 1081811.744493
15927 318520 1081909.957256
15928 318540 1082008.170967
15929 318560 1082106.385625
15930 318580 1082204.601231
15931 318600 1082302.817784
15932 318620 1082401.035284
15933 318640 1082499.253732
15934 318660 1082597.473126
15935 318680 1082695.693468
15936 318700 1082793.914757
15937 318720 1082892.136993
15938 318740 1082990.360176
15939 318760 1083088.584305
15940 318780 1083186.809381
15941 318800 1083285.035404
15942 318820 1083383.262374
15943 318840 1083481.490290
15944 318860 1083579.719152
15945 318880 1083677.948961
15946 318900 1083776.179716
15947 318920 1083874.411418
15948 318940 1083972.644065
15949 318960 1084070.877659
15950 318980 1084169.112199
15951 319000 1084267.347685
15952 319020 1084365.584117
15953 319040 1084463.821494
15954 319060 1084562.059817
15955 319080 1084660.299086
15956 319100 1084758.539301
15957 319120 1084856.780461
15958 319140 1084955.022567
15959 319160 1085053.265618
15960 319180 1085151.509614
15961 319200 1085249.754556
15962 319220 1085348.000443
15963 319240 1085446.247275
15964 319260 1085544.495052
15965 319280 1085642.743774
15966 319300 1085740.993441
15967 319320 1085839.244052
15968 319340 1085937.495609
15969 319360 1086035.748110
15970 319380 1086134.001556
15971 319400 1086232.255947
15972 319420 1086330.511282
15973 319440 1086428.767561
15974 319460 1086527.024785
15975 319480 1086625.282953
15976 319500 1086723.542065
15977 319520 1086821.802122
15978 319540 1086920.063122
15979 319560 1087018.325067
15980 319580 1087116.587955
15981 319600 1087214.851788
15982 319620 1087313.116564
15983 319640 1087411.382284
15984 319660 1087509.648947
15985 319680 1087607.916555
15986 319700 1087706.185105
15987 319720 1087804.454599
15988 319740 1087902.725037
15989 319760 1088000.996418
15990 319780 1088099.268742
15991 319800 1088197.542009
15992 319820 1088295.816219
15993 319840 1088394.091373
15994 319860 1088492.367469
15995 319880 1088590.644508
15996 319900 1088688.922491
15997 319920 1088787.201415
15998 319940 1088885.481283
15999 319960 1088983.762093
16000 319980 1089082.043846
16001 320000 1089180.326541

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