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 20 of 40 · 500/page · 20000 rows next →
# nmargin_tilde
9502 190020 474532.769109
9503 190040 474622.776723
9504 190060 474712.786101
9505 190080 474802.797245
9506 190100 474892.810154
9507 190120 474982.824827
9508 190140 475072.841264
9509 190160 475162.859465
9510 190180 475252.879430
9511 190200 475342.901159
9512 190220 475432.924651
9513 190240 475522.949906
9514 190260 475612.976924
9515 190280 475703.005705
9516 190300 475793.036248
9517 190320 475883.068553
9518 190340 475973.102621
9519 190360 476063.138450
9520 190380 476153.176040
9521 190400 476243.215392
9522 190420 476333.256505
9523 190440 476423.299379
9524 190460 476513.344014
9525 190480 476603.390409
9526 190500 476693.438564
9527 190520 476783.488479
9528 190540 476873.540153
9529 190560 476963.593588
9530 190580 477053.648781
9531 190600 477143.705734
9532 190620 477233.764445
9533 190640 477323.824915
9534 190660 477413.887143
9535 190680 477503.951130
9536 190700 477594.016874
9537 190720 477684.084376
9538 190740 477774.153635
9539 190760 477864.224652
9540 190780 477954.297426
9541 190800 478044.371956
9542 190820 478134.448243
9543 190840 478224.526287
9544 190860 478314.606086
9545 190880 478404.687641
9546 190900 478494.770952
9547 190920 478584.856019
9548 190940 478674.942840
9549 190960 478765.031417
9550 190980 478855.121748
9551 191000 478945.213834
9552 191020 479035.307674
9553 191040 479125.403268
9554 191060 479215.500616
9555 191080 479305.599718
9556 191100 479395.700573
9557 191120 479485.803181
9558 191140 479575.907542
9559 191160 479666.013656
9560 191180 479756.121522
9561 191200 479846.231141
9562 191220 479936.342511
9563 191240 480026.455634
9564 191260 480116.570508
9565 191280 480206.687133
9566 191300 480296.805510
9567 191320 480386.925637
9568 191340 480477.047516
9569 191360 480567.171144
9570 191380 480657.296523
9571 191400 480747.423652
9572 191420 480837.552531
9573 191440 480927.683159
9574 191460 481017.815537
9575 191480 481107.949663
9576 191500 481198.085539
9577 191520 481288.223163
9578 191540 481378.362536
9579 191560 481468.503657
9580 191580 481558.646526
9581 191600 481648.791143
9582 191620 481738.937507
9583 191640 481829.085619
9584 191660 481919.235478
9585 191680 482009.387084
9586 191700 482099.540436
9587 191720 482189.695535
9588 191740 482279.852380
9589 191760 482370.010971
9590 191780 482460.171307
9591 191800 482550.333390
9592 191820 482640.497217
9593 191840 482730.662790
9594 191860 482820.830108
9595 191880 482910.999170
9596 191900 483001.169976
9597 191920 483091.342527
9598 191940 483181.516822
9599 191960 483271.692861
9600 191980 483361.870643
9601 192000 483452.050168
9602 192020 483542.231437
9603 192040 483632.414448
9604 192060 483722.599202
9605 192080 483812.785699
9606 192100 483902.973938
9607 192120 483993.163918
9608 192140 484083.355641
9609 192160 484173.549105
9610 192180 484263.744310
9611 192200 484353.941256
9612 192220 484444.139944
9613 192240 484534.340371
9614 192260 484624.542540
9615 192280 484714.746448
9616 192300 484804.952097
9617 192320 484895.159485
9618 192340 484985.368613
9619 192360 485075.579480
9620 192380 485165.792086
9621 192400 485256.006431
9622 192420 485346.222515
9623 192440 485436.440337
9624 192460 485526.659897
9625 192480 485616.881195
9626 192500 485707.104232
9627 192520 485797.329005
9628 192540 485887.555516
9629 192560 485977.783764
9630 192580 486068.013749
9631 192600 486158.245471
9632 192620 486248.478929
9633 192640 486338.714123
9634 192660 486428.951053
9635 192680 486519.189719
9636 192700 486609.430120
9637 192720 486699.672257
9638 192740 486789.916129
9639 192760 486880.161736
9640 192780 486970.409078
9641 192800 487060.658154
9642 192820 487150.908964
9643 192840 487241.161508
9644 192860 487331.415786
9645 192880 487421.671798
9646 192900 487511.929542
9647 192920 487602.189020
9648 192940 487692.450231
9649 192960 487782.713175
9650 192980 487872.977851
9651 193000 487963.244259
9652 193020 488053.512400
9653 193040 488143.782272
9654 193060 488234.053875
9655 193080 488324.327211
9656 193100 488414.602277
9657 193120 488504.879074
9658 193140 488595.157602
9659 193160 488685.437860
9660 193180 488775.719849
9661 193200 488866.003567
9662 193220 488956.289016
9663 193240 489046.576194
9664 193260 489136.865101
9665 193280 489227.155738
9666 193300 489317.448104
9667 193320 489407.742198
9668 193340 489498.038021
9669 193360 489588.335572
9670 193380 489678.634851
9671 193400 489768.935858
9672 193420 489859.238593
9673 193440 489949.543055
9674 193460 490039.849244
9675 193480 490130.157160
9676 193500 490220.466803
9677 193520 490310.778173
9678 193540 490401.091269
9679 193560 490491.406090
9680 193580 490581.722638
9681 193600 490672.040912
9682 193620 490762.360911
9683 193640 490852.682635
9684 193660 490943.006084
9685 193680 491033.331258
9686 193700 491123.658157
9687 193720 491213.986780
9688 193740 491304.317127
9689 193760 491394.649197
9690 193780 491484.982992
9691 193800 491575.318510
9692 193820 491665.655752
9693 193840 491755.994716
9694 193860 491846.335403
9695 193880 491936.677813
9696 193900 492027.021945
9697 193920 492117.367800
9698 193940 492207.715376
9699 193960 492298.064674
9700 193980 492388.415694
9701 194000 492478.768435
9702 194020 492569.122897
9703 194040 492659.479080
9704 194060 492749.836984
9705 194080 492840.196608
9706 194100 492930.557952
9707 194120 493020.921016
9708 194140 493111.285800
9709 194160 493201.652304
9710 194180 493292.020526
9711 194200 493382.390468
9712 194220 493472.762129
9713 194240 493563.135509
9714 194260 493653.510607
9715 194280 493743.887424
9716 194300 493834.265958
9717 194320 493924.646210
9718 194340 494015.028180
9719 194360 494105.411867
9720 194380 494195.797272
9721 194400 494286.184393
9722 194420 494376.573232
9723 194440 494466.963786
9724 194460 494557.356057
9725 194480 494647.750044
9726 194500 494738.145747
9727 194520 494828.543166
9728 194540 494918.942300
9729 194560 495009.343149
9730 194580 495099.745714
9731 194600 495190.149993
9732 194620 495280.555987
9733 194640 495370.963695
9734 194660 495461.373117
9735 194680 495551.784253
9736 194700 495642.197103
9737 194720 495732.611667
9738 194740 495823.027943
9739 194760 495913.445933
9740 194780 496003.865636
9741 194800 496094.287051
9742 194820 496184.710179
9743 194840 496275.135019
9744 194860 496365.561571
9745 194880 496455.989835
9746 194900 496546.419810
9747 194920 496636.851497
9748 194940 496727.284894
9749 194960 496817.720003
9750 194980 496908.156823
9751 195000 496998.595352
9752 195020 497089.035593
9753 195040 497179.477543
9754 195060 497269.921203
9755 195080 497360.366573
9756 195100 497450.813652
9757 195120 497541.262440
9758 195140 497631.712938
9759 195160 497722.165144
9760 195180 497812.619058
9761 195200 497903.074681
9762 195220 497993.532013
9763 195240 498083.991052
9764 195260 498174.451798
9765 195280 498264.914253
9766 195300 498355.378414
9767 195320 498445.844283
9768 195340 498536.311858
9769 195360 498626.781140
9770 195380 498717.252129
9771 195400 498807.724824
9772 195420 498898.199224
9773 195440 498988.675331
9774 195460 499079.153143
9775 195480 499169.632660
9776 195500 499260.113883
9777 195520 499350.596810
9778 195540 499441.081442
9779 195560 499531.567779
9780 195580 499622.055820
9781 195600 499712.545565
9782 195620 499803.037014
9783 195640 499893.530166
9784 195660 499984.025022
9785 195680 500074.521581
9786 195700 500165.019843
9787 195720 500255.519808
9788 195740 500346.021476
9789 195760 500436.524846
9790 195780 500527.029918
9791 195800 500617.536692
9792 195820 500708.045167
9793 195840 500798.555344
9794 195860 500889.067223
9795 195880 500979.580803
9796 195900 501070.096083
9797 195920 501160.613064
9798 195940 501251.131746
9799 195960 501341.652127
9800 195980 501432.174209
9801 196000 501522.697991
9802 196020 501613.223472
9803 196040 501703.750652
9804 196060 501794.279532
9805 196080 501884.810111
9806 196100 501975.342388
9807 196120 502065.876364
9808 196140 502156.412039
9809 196160 502246.949411
9810 196180 502337.488481
9811 196200 502428.029249
9812 196220 502518.571715
9813 196240 502609.115878
9814 196260 502699.661737
9815 196280 502790.209294
9816 196300 502880.758547
9817 196320 502971.309497
9818 196340 503061.862143
9819 196360 503152.416485
9820 196380 503242.972522
9821 196400 503333.530256
9822 196420 503424.089684
9823 196440 503514.650808
9824 196460 503605.213627
9825 196480 503695.778140
9826 196500 503786.344348
9827 196520 503876.912250
9828 196540 503967.481847
9829 196560 504058.053137
9830 196580 504148.626121
9831 196600 504239.200798
9832 196620 504329.777168
9833 196640 504420.355232
9834 196660 504510.934988
9835 196680 504601.516438
9836 196700 504692.099579
9837 196720 504782.684413
9838 196740 504873.270938
9839 196760 504963.859156
9840 196780 505054.449065
9841 196800 505145.040665
9842 196820 505235.633956
9843 196840 505326.228939
9844 196860 505416.825612
9845 196880 505507.423975
9846 196900 505598.024029
9847 196920 505688.625773
9848 196940 505779.229207
9849 196960 505869.834331
9850 196980 505960.441144
9851 197000 506051.049646
9852 197020 506141.659837
9853 197040 506232.271718
9854 197060 506322.885286
9855 197080 506413.500543
9856 197100 506504.117489
9857 197120 506594.736122
9858 197140 506685.356443
9859 197160 506775.978452
9860 197180 506866.602148
9861 197200 506957.227531
9862 197220 507047.854601
9863 197240 507138.483358
9864 197260 507229.113802
9865 197280 507319.745932
9866 197300 507410.379747
9867 197320 507501.015249
9868 197340 507591.652437
9869 197360 507682.291309
9870 197380 507772.931868
9871 197400 507863.574111
9872 197420 507954.218039
9873 197440 508044.863652
9874 197460 508135.510949
9875 197480 508226.159930
9876 197500 508316.810596
9877 197520 508407.462945
9878 197540 508498.116978
9879 197560 508588.772694
9880 197580 508679.430093
9881 197600 508770.089176
9882 197620 508860.749941
9883 197640 508951.412388
9884 197660 509042.076518
9885 197680 509132.742331
9886 197700 509223.409825
9887 197720 509314.079001
9888 197740 509404.749858
9889 197760 509495.422397
9890 197780 509586.096616
9891 197800 509676.772517
9892 197820 509767.450098
9893 197840 509858.129360
9894 197860 509948.810302
9895 197880 510039.492924
9896 197900 510130.177226
9897 197920 510220.863208
9898 197940 510311.550869
9899 197960 510402.240209
9900 197980 510492.931228
9901 198000 510583.623927
9902 198020 510674.318303
9903 198040 510765.014358
9904 198060 510855.712092
9905 198080 510946.411503
9906 198100 511037.112592
9907 198120 511127.815359
9908 198140 511218.519803
9909 198160 511309.225924
9910 198180 511399.933722
9911 198200 511490.643197
9912 198220 511581.354348
9913 198240 511672.067176
9914 198260 511762.781680
9915 198280 511853.497859
9916 198300 511944.215715
9917 198320 512034.935246
9918 198340 512125.656452
9919 198360 512216.379333
9920 198380 512307.103889
9921 198400 512397.830120
9922 198420 512488.558026
9923 198440 512579.287605
9924 198460 512670.018859
9925 198480 512760.751786
9926 198500 512851.486388
9927 198520 512942.222662
9928 198540 513032.960610
9929 198560 513123.700231
9930 198580 513214.441524
9931 198600 513305.184491
9932 198620 513395.929129
9933 198640 513486.675440
9934 198660 513577.423423
9935 198680 513668.173077
9936 198700 513758.924404
9937 198720 513849.677401
9938 198740 513940.432070
9939 198760 514031.188410
9940 198780 514121.946420
9941 198800 514212.706101
9942 198820 514303.467452
9943 198840 514394.230474
9944 198860 514484.995165
9945 198880 514575.761527
9946 198900 514666.529557
9947 198920 514757.299257
9948 198940 514848.070626
9949 198960 514938.843664
9950 198980 515029.618371
9951 199000 515120.394746
9952 199020 515211.172790
9953 199040 515301.952501
9954 199060 515392.733881
9955 199080 515483.516928
9956 199100 515574.301643
9957 199120 515665.088024
9958 199140 515755.876073
9959 199160 515846.665789
9960 199180 515937.457172
9961 199200 516028.250221
9962 199220 516119.044936
9963 199240 516209.841317
9964 199260 516300.639364
9965 199280 516391.439077
9966 199300 516482.240455
9967 199320 516573.043498
9968 199340 516663.848206
9969 199360 516754.654579
9970 199380 516845.462617
9971 199400 516936.272319
9972 199420 517027.083686
9973 199440 517117.896716
9974 199460 517208.711410
9975 199480 517299.527768
9976 199500 517390.345789
9977 199520 517481.165473
9978 199540 517571.986821
9979 199560 517662.809831
9980 199580 517753.634503
9981 199600 517844.460838
9982 199620 517935.288835
9983 199640 518026.118494
9984 199660 518116.949815
9985 199680 518207.782798
9986 199700 518298.617441
9987 199720 518389.453746
9988 199740 518480.291712
9989 199760 518571.131339
9990 199780 518661.972626
9991 199800 518752.815573
9992 199820 518843.660181
9993 199840 518934.506448
9994 199860 519025.354375
9995 199880 519116.203962
9996 199900 519207.055208
9997 199920 519297.908113
9998 199940 519388.762677
9999 199960 519479.618900
10000 199980 519570.476781
10001 200000 519661.336321

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