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 34 of 40 · 500/page · 20000 rows next →
# nmargin_tilde
16502 330020 1138537.030652
16503 330040 1138635.777876
16504 330060 1138734.526009
16505 330080 1138833.275051
16506 330100 1138932.025001
16507 330120 1139030.775860
16508 330140 1139129.527627
16509 330160 1139228.280302
16510 330180 1139327.033885
16511 330200 1139425.788377
16512 330220 1139524.543777
16513 330240 1139623.300084
16514 330260 1139722.057300
16515 330280 1139820.815424
16516 330300 1139919.574455
16517 330320 1140018.334395
16518 330340 1140117.095242
16519 330360 1140215.856996
16520 330380 1140314.619659
16521 330400 1140413.383228
16522 330420 1140512.147706
16523 330440 1140610.913090
16524 330460 1140709.679382
16525 330480 1140808.446582
16526 330500 1140907.214688
16527 330520 1141005.983702
16528 330540 1141104.753622
16529 330560 1141203.524450
16530 330580 1141302.296185
16531 330600 1141401.068826
16532 330620 1141499.842375
16533 330640 1141598.616830
16534 330660 1141697.392191
16535 330680 1141796.168460
16536 330700 1141894.945635
16537 330720 1141993.723716
16538 330740 1142092.502704
16539 330760 1142191.282598
16540 330780 1142290.063399
16541 330800 1142388.845106
16542 330820 1142487.627719
16543 330840 1142586.411238
16544 330860 1142685.195663
16545 330880 1142783.980994
16546 330900 1142882.767231
16547 330920 1142981.554373
16548 330940 1143080.342422
16549 330960 1143179.131376
16550 330980 1143277.921236
16551 331000 1143376.712002
16552 331020 1143475.503673
16553 331040 1143574.296249
16554 331060 1143673.089731
16555 331080 1143771.884118
16556 331100 1143870.679411
16557 331120 1143969.475609
16558 331140 1144068.272711
16559 331160 1144167.070719
16560 331180 1144265.869632
16561 331200 1144364.669450
16562 331220 1144463.470173
16563 331240 1144562.271800
16564 331260 1144661.074333
16565 331280 1144759.877770
16566 331300 1144858.682111
16567 331320 1144957.487357
16568 331340 1145056.293508
16569 331360 1145155.100563
16570 331380 1145253.908522
16571 331400 1145352.717386
16572 331420 1145451.527154
16573 331440 1145550.337826
16574 331460 1145649.149402
16575 331480 1145747.961882
16576 331500 1145846.775267
16577 331520 1145945.589555
16578 331540 1146044.404747
16579 331560 1146143.220843
16580 331580 1146242.037842
16581 331600 1146340.855745
16582 331620 1146439.674552
16583 331640 1146538.494262
16584 331660 1146637.314876
16585 331680 1146736.136393
16586 331700 1146834.958813
16587 331720 1146933.782137
16588 331740 1147032.606364
16589 331760 1147131.431494
16590 331780 1147230.257527
16591 331800 1147329.084463
16592 331820 1147427.912302
16593 331840 1147526.741044
16594 331860 1147625.570689
16595 331880 1147724.401237
16596 331900 1147823.232687
16597 331920 1147922.065040
16598 331940 1148020.898295
16599 331960 1148119.732453
16600 331980 1148218.567513
16601 332000 1148317.403476
16602 332020 1148416.240341
16603 332040 1148515.078108
16604 332060 1148613.916778
16605 332080 1148712.756349
16606 332100 1148811.596823
16607 332120 1148910.438198
16608 332140 1149009.280476
16609 332160 1149108.123655
16610 332180 1149206.967736
16611 332200 1149305.812719
16612 332220 1149404.658604
16613 332240 1149503.505390
16614 332260 1149602.353077
16615 332280 1149701.201666
16616 332300 1149800.051157
16617 332320 1149898.901549
16618 332340 1149997.752842
16619 332360 1150096.605036
16620 332380 1150195.458132
16621 332400 1150294.312128
16622 332420 1150393.167026
16623 332440 1150492.022825
16624 332460 1150590.879524
16625 332480 1150689.737125
16626 332500 1150788.595626
16627 332520 1150887.455027
16628 332540 1150986.315330
16629 332560 1151085.176533
16630 332580 1151184.038636
16631 332600 1151282.901640
16632 332620 1151381.765545
16633 332640 1151480.630349
16634 332660 1151579.496054
16635 332680 1151678.362659
16636 332700 1151777.230165
16637 332720 1151876.098570
16638 332740 1151974.967875
16639 332760 1152073.838081
16640 332780 1152172.709186
16641 332800 1152271.581191
16642 332820 1152370.454095
16643 332840 1152469.327900
16644 332860 1152568.202604
16645 332880 1152667.078207
16646 332900 1152765.954710
16647 332920 1152864.832113
16648 332940 1152963.710415
16649 332960 1153062.589616
16650 332980 1153161.469716
16651 333000 1153260.350716
16652 333020 1153359.232614
16653 333040 1153458.115412
16654 333060 1153556.999109
16655 333080 1153655.883704
16656 333100 1153754.769199
16657 333120 1153853.655592
16658 333140 1153952.542884
16659 333160 1154051.431074
16660 333180 1154150.320164
16661 333200 1154249.210151
16662 333220 1154348.101038
16663 333240 1154446.992822
16664 333260 1154545.885505
16665 333280 1154644.779086
16666 333300 1154743.673566
16667 333320 1154842.568944
16668 333340 1154941.465219
16669 333360 1155040.362393
16670 333380 1155139.260465
16671 333400 1155238.159434
16672 333420 1155337.059302
16673 333440 1155435.960067
16674 333460 1155534.861730
16675 333480 1155633.764291
16676 333500 1155732.667749
16677 333520 1155831.572104
16678 333540 1155930.477358
16679 333560 1156029.383508
16680 333580 1156128.290556
16681 333600 1156227.198501
16682 333620 1156326.107343
16683 333640 1156425.017083
16684 333660 1156523.927719
16685 333680 1156622.839253
16686 333700 1156721.751684
16687 333720 1156820.665011
16688 333740 1156919.579235
16689 333760 1157018.494356
16690 333780 1157117.410374
16691 333800 1157216.327288
16692 333820 1157315.245099
16693 333840 1157414.163806
16694 333860 1157513.083410
16695 333880 1157612.003910
16696 333900 1157710.925307
16697 333920 1157809.847599
16698 333940 1157908.770788
16699 333960 1158007.694873
16700 333980 1158106.619855
16701 334000 1158205.545732
16702 334020 1158304.472505
16703 334040 1158403.400174
16704 334060 1158502.328738
16705 334080 1158601.258199
16706 334100 1158700.188555
16707 334120 1158799.119807
16708 334140 1158898.051954
16709 334160 1158996.984997
16710 334180 1159095.918935
16711 334200 1159194.853769
16712 334220 1159293.789498
16713 334240 1159392.726122
16714 334260 1159491.663641
16715 334280 1159590.602056
16716 334300 1159689.541365
16717 334320 1159788.481570
16718 334340 1159887.422669
16719 334360 1159986.364663
16720 334380 1160085.307552
16721 334400 1160184.251336
16722 334420 1160283.196015
16723 334440 1160382.141588
16724 334460 1160481.088055
16725 334480 1160580.035418
16726 334500 1160678.983674
16727 334520 1160777.932825
16728 334540 1160876.882870
16729 334560 1160975.833810
16730 334580 1161074.785643
16731 334600 1161173.738371
16732 334620 1161272.691992
16733 334640 1161371.646508
16734 334660 1161470.601918
16735 334680 1161569.558221
16736 334700 1161668.515418
16737 334720 1161767.473509
16738 334740 1161866.432494
16739 334760 1161965.392372
16740 334780 1162064.353144
16741 334800 1162163.314809
16742 334820 1162262.277368
16743 334840 1162361.240820
16744 334860 1162460.205165
16745 334880 1162559.170404
16746 334900 1162658.136535
16747 334920 1162757.103560
16748 334940 1162856.071478
16749 334960 1162955.040289
16750 334980 1163054.009992
16751 335000 1163152.980589
16752 335020 1163251.952078
16753 335040 1163350.924460
16754 335060 1163449.897735
16755 335080 1163548.871902
16756 335100 1163647.846962
16757 335120 1163746.822914
16758 335140 1163845.799759
16759 335160 1163944.777496
16760 335180 1164043.756125
16761 335200 1164142.735647
16762 335220 1164241.716060
16763 335240 1164340.697366
16764 335260 1164439.679564
16765 335280 1164538.662654
16766 335300 1164637.646635
16767 335320 1164736.631509
16768 335340 1164835.617274
16769 335360 1164934.603931
16770 335380 1165033.591480
16771 335400 1165132.579920
16772 335420 1165231.569252
16773 335440 1165330.559475
16774 335460 1165429.550590
16775 335480 1165528.542596
16776 335500 1165627.535493
16777 335520 1165726.529281
16778 335540 1165825.523961
16779 335560 1165924.519531
16780 335580 1166023.515993
16781 335600 1166122.513346
16782 335620 1166221.511589
16783 335640 1166320.510724
16784 335660 1166419.510749
16785 335680 1166518.511665
16786 335700 1166617.513471
16787 335720 1166716.516169
16788 335740 1166815.519756
16789 335760 1166914.524234
16790 335780 1167013.529603
16791 335800 1167112.535862
16792 335820 1167211.543011
16793 335840 1167310.551050
16794 335860 1167409.559980
16795 335880 1167508.569799
16796 335900 1167607.580509
16797 335920 1167706.592108
16798 335940 1167805.604598
16799 335960 1167904.617977
16800 335980 1168003.632246
16801 336000 1168102.647405
16802 336020 1168201.663454
16803 336040 1168300.680392
16804 336060 1168399.698219
16805 336080 1168498.716936
16806 336100 1168597.736543
16807 336120 1168696.757038
16808 336140 1168795.778423
16809 336160 1168894.800698
16810 336180 1168993.823861
16811 336200 1169092.847913
16812 336220 1169191.872855
16813 336240 1169290.898685
16814 336260 1169389.925405
16815 336280 1169488.953013
16816 336300 1169587.981510
16817 336320 1169687.010896
16818 336340 1169786.041170
16819 336360 1169885.072333
16820 336380 1169984.104385
16821 336400 1170083.137324
16822 336420 1170182.171153
16823 336440 1170281.205869
16824 336460 1170380.241474
16825 336480 1170479.277968
16826 336500 1170578.315349
16827 336520 1170677.353618
16828 336540 1170776.392776
16829 336560 1170875.432821
16830 336580 1170974.473755
16831 336600 1171073.515576
16832 336620 1171172.558285
16833 336640 1171271.601881
16834 336660 1171370.646366
16835 336680 1171469.691738
16836 336700 1171568.737997
16837 336720 1171667.785144
16838 336740 1171766.833178
16839 336760 1171865.882100
16840 336780 1171964.931909
16841 336800 1172063.982605
16842 336820 1172163.034189
16843 336840 1172262.086659
16844 336860 1172361.140016
16845 336880 1172460.194261
16846 336900 1172559.249392
16847 336920 1172658.305410
16848 336940 1172757.362315
16849 336960 1172856.420107
16850 336980 1172955.478786
16851 337000 1173054.538351
16852 337020 1173153.598802
16853 337040 1173252.660140
16854 337060 1173351.722364
16855 337080 1173450.785475
16856 337100 1173549.849472
16857 337120 1173648.914356
16858 337140 1173747.980125
16859 337160 1173847.046781
16860 337180 1173946.114322
16861 337200 1174045.182750
16862 337220 1174144.252063
16863 337240 1174243.322263
16864 337260 1174342.393348
16865 337280 1174441.465319
16866 337300 1174540.538175
16867 337320 1174639.611917
16868 337340 1174738.686545
16869 337360 1174837.762058
16870 337380 1174936.838457
16871 337400 1175035.915741
16872 337420 1175134.993910
16873 337440 1175234.072965
16874 337460 1175333.152905
16875 337480 1175432.233729
16876 337500 1175531.315439
16877 337520 1175630.398034
16878 337540 1175729.481514
16879 337560 1175828.565879
16880 337580 1175927.651128
16881 337600 1176026.737262
16882 337620 1176125.824281
16883 337640 1176224.912185
16884 337660 1176324.000973
16885 337680 1176423.090645
16886 337700 1176522.181202
16887 337720 1176621.272644
16888 337740 1176720.364969
16889 337760 1176819.458179
16890 337780 1176918.552274
16891 337800 1177017.647252
16892 337820 1177116.743114
16893 337840 1177215.839860
16894 337860 1177314.937491
16895 337880 1177414.036005
16896 337900 1177513.135403
16897 337920 1177612.235685
16898 337940 1177711.336850
16899 337960 1177810.438899
16900 337980 1177909.541832
16901 338000 1178008.645648
16902 338020 1178107.750347
16903 338040 1178206.855930
16904 338060 1178305.962397
16905 338080 1178405.069746
16906 338100 1178504.177979
16907 338120 1178603.287095
16908 338140 1178702.397094
16909 338160 1178801.507976
16910 338180 1178900.619741
16911 338200 1178999.732389
16912 338220 1179098.845919
16913 338240 1179197.960333
16914 338260 1179297.075629
16915 338280 1179396.191808
16916 338300 1179495.308869
16917 338320 1179594.426813
16918 338340 1179693.545640
16919 338360 1179792.665348
16920 338380 1179891.785940
16921 338400 1179990.907413
16922 338420 1180090.029769
16923 338440 1180189.153006
16924 338460 1180288.277126
16925 338480 1180387.402128
16926 338500 1180486.528012
16927 338520 1180585.654778
16928 338540 1180684.782426
16929 338560 1180783.910955
16930 338580 1180883.040366
16931 338600 1180982.170659
16932 338620 1181081.301833
16933 338640 1181180.433889
16934 338660 1181279.566827
16935 338680 1181378.700646
16936 338700 1181477.835346
16937 338720 1181576.970928
16938 338740 1181676.107390
16939 338760 1181775.244734
16940 338780 1181874.382959
16941 338800 1181973.522065
16942 338820 1182072.662053
16943 338840 1182171.802921
16944 338860 1182270.944669
16945 338880 1182370.087299
16946 338900 1182469.230810
16947 338920 1182568.375201
16948 338940 1182667.520473
16949 338960 1182766.666625
16950 338980 1182865.813658
16951 339000 1182964.961571
16952 339020 1183064.110365
16953 339040 1183163.260039
16954 339060 1183262.410593
16955 339080 1183361.562027
16956 339100 1183460.714342
16957 339120 1183559.867536
16958 339140 1183659.021611
16959 339160 1183758.176566
16960 339180 1183857.332400
16961 339200 1183956.489115
16962 339220 1184055.646709
16963 339240 1184154.805182
16964 339260 1184253.964536
16965 339280 1184353.124769
16966 339300 1184452.285881
16967 339320 1184551.447873
16968 339340 1184650.610745
16969 339360 1184749.774495
16970 339380 1184848.939126
16971 339400 1184948.104635
16972 339420 1185047.271023
16973 339440 1185146.438291
16974 339460 1185245.606437
16975 339480 1185344.775463
16976 339500 1185443.945367
16977 339520 1185543.116150
16978 339540 1185642.287812
16979 339560 1185741.460353
16980 339580 1185840.633773
16981 339600 1185939.808071
16982 339620 1186038.983247
16983 339640 1186138.159302
16984 339660 1186237.336236
16985 339680 1186336.514048
16986 339700 1186435.692738
16987 339720 1186534.872306
16988 339740 1186634.052753
16989 339760 1186733.234078
16990 339780 1186832.416280
16991 339800 1186931.599361
16992 339820 1187030.783320
16993 339840 1187129.968156
16994 339860 1187229.153871
16995 339880 1187328.340463
16996 339900 1187427.527933
16997 339920 1187526.716280
16998 339940 1187625.905505
16999 339960 1187725.095608
17000 339980 1187824.286588
17001 340000 1187923.478445

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