Current task: —

E-023-finite-height-assembly.py

Experiments: E-023 · script updated 08-19-2026

E-023-assembly.csv — 710.1 KB, updated 08-19-2026

← prev page 23 of 40 · 500/page · 20000 rows next →
# nmargin_tracedmargin_measured
11002 220020 873452.308378 894117.336437
11003 220040 873554.140788 894219.963744
11004 220060 873655.974266 894322.592085
11005 220080 873757.808813 894425.221460
11006 220100 873859.644427 894527.851869
11007 220120 873961.481109 894630.483313
11008 220140 874063.318858 894733.115791
11009 220160 874165.157675 894835.749302
11010 220180 874266.997560 894938.383848
11011 220200 874368.838511 895041.019427
11012 220220 874470.680530 895143.656039
11013 220240 874572.523617 895246.293686
11014 220260 874674.367770 895348.932366
11015 220280 874776.212990 895451.572079
11016 220300 874878.059276 895554.212825
11017 220320 874979.906630 895656.854604
11018 220340 875081.755050 895759.497417
11019 220360 875183.604536 895862.141262
11020 220380 875285.455089 895964.786140
11021 220400 875387.306708 896067.432051
11022 220420 875489.159394 896170.078995
11023 220440 875591.013145 896272.726970
11024 220460 875692.867962 896375.375979
11025 220480 875794.723845 896478.026020
11026 220500 875896.580794 896580.677092
11027 220520 875998.438808 896683.329197
11028 220540 876100.297888 896785.982334
11029 220560 876202.158033 896888.636503
11030 220580 876304.019244 896991.291704
11031 220600 876405.881519 897093.947936
11032 220620 876507.744860 897196.605200
11033 220640 876609.609266 897299.263495
11034 220660 876711.474736 897401.922822
11035 220680 876813.341272 897504.583180
11036 220700 876915.208872 897607.244569
11037 220720 877017.077536 897709.906989
11038 220740 877118.947265 897812.570441
11039 220760 877220.818058 897915.234923
11040 220780 877322.689916 898017.900435
11041 220800 877424.562837 898120.566979
11042 220820 877526.436823 898223.234553
11043 220840 877628.311872 898325.903157
11044 220860 877730.187986 898428.572792
11045 220880 877832.065163 898531.243457
11046 220900 877933.943403 898633.915153
11047 220920 878035.822707 898736.587878
11048 220940 878137.703074 898839.261633
11049 220960 878239.584505 898941.936418
11050 220980 878341.466999 899044.612233
11051 221000 878443.350556 899147.289078
11052 221020 878545.235175 899249.966952
11053 221040 878647.120858 899352.645855
11054 221060 878749.007603 899455.325788
11055 221080 878850.895411 899558.006750
11056 221100 878952.784281 899660.688741
11057 221120 879054.674214 899763.371761
11058 221140 879156.565209 899866.055810
11059 221160 879258.457266 899968.740888
11060 221180 879360.350386 900071.426994
11061 221200 879462.244567 900174.114130
11062 221220 879564.139810 900276.802293
11063 221240 879666.036115 900379.491486
11064 221260 879767.933482 900482.181706
11065 221280 879869.831910 900584.872955
11066 221300 879971.731400 900687.565231
11067 221320 880073.631951 900790.258536
11068 221340 880175.533563 900892.952869
11069 221360 880277.436236 900995.648229
11070 221380 880379.339971 901098.344618
11071 221400 880481.244766 901201.042033
11072 221420 880583.150622 901303.740477
11073 221440 880685.057539 901406.439947
11074 221460 880786.965516 901509.140445
11075 221480 880888.874554 901611.841971
11076 221500 880990.784652 901714.544523
11077 221520 881092.695811 901817.248102
11078 221540 881194.608029 901919.952708
11079 221560 881296.521308 902022.658341
11080 221580 881398.435647 902125.365001
11081 221600 881500.351045 902228.072687
11082 221620 881602.267504 902330.781400
11083 221640 881704.185022 902433.491139
11084 221660 881806.103599 902536.201904
11085 221680 881908.023236 902638.913696
11086 221700 882009.943932 902741.626513
11087 221720 882111.865688 902844.340357
11088 221740 882213.788502 902947.055226
11089 221760 882315.712376 903049.771122
11090 221780 882417.637308 903152.488043
11091 221800 882519.563300 903255.205989
11092 221820 882621.490350 903357.924961
11093 221840 882723.418458 903460.644958
11094 221860 882825.347625 903563.365981
11095 221880 882927.277851 903666.088029
11096 221900 883029.209134 903768.811102
11097 221920 883131.141476 903871.535199
11098 221940 883233.074876 903974.260322
11099 221960 883335.009334 904076.986469
11100 221980 883436.944850 904179.713641
11101 222000 883538.881423 904282.441838
11102 222020 883640.819054 904385.171059
11103 222040 883742.757743 904487.901305
11104 222060 883844.697489 904590.632574
11105 222080 883946.638292 904693.364868
11106 222100 884048.580153 904796.098186
11107 222120 884150.523070 904898.832528
11108 222140 884252.467045 905001.567894
11109 222160 884354.412077 905104.304283
11110 222180 884456.358165 905207.041696
11111 222200 884558.305310 905309.780133
11112 222220 884660.253512 905412.519593
11113 222240 884762.202770 905515.260077
11114 222260 884864.153084 905618.001583
11115 222280 884966.104455 905720.744113
11116 222300 885068.056882 905823.487666
11117 222320 885170.010365 905926.232242
11118 222340 885271.964904 906028.977841
11119 222360 885373.920498 906131.724462
11120 222380 885475.877149 906234.472106
11121 222400 885577.834855 906337.220773
11122 222420 885679.793617 906439.970462
11123 222440 885781.753434 906542.721173
11124 222460 885883.714306 906645.472907
11125 222480 885985.676234 906748.225663
11126 222500 886087.639216 906850.979440
11127 222520 886189.603254 906953.734240
11128 222540 886291.568347 907056.490062
11129 222560 886393.534494 907159.246905
11130 222580 886495.501696 907262.004770
11131 222600 886597.469953 907364.763657
11132 222620 886699.439264 907467.523565
11133 222640 886801.409629 907570.284494
11134 222660 886903.381049 907673.046444
11135 222680 887005.353523 907775.809416
11136 222700 887107.327051 907878.573409
11137 222720 887209.301633 907981.338422
11138 222740 887311.277269 908084.104457
11139 222760 887413.253958 908186.871512
11140 222780 887515.231702 908289.639588
11141 222800 887617.210498 908392.408684
11142 222820 887719.190349 908495.178801
11143 222840 887821.171252 908597.949938
11144 222860 887923.153209 908700.722095
11145 222880 888025.136219 908803.495273
11146 222900 888127.120281 908906.269470
11147 222920 888229.105397 909009.044688
11148 222940 888331.091566 909111.820925
11149 222960 888433.078787 909214.598182
11150 222980 888535.067061 909317.376459
11151 223000 888637.056387 909420.155755
11152 223020 888739.046766 909522.936071
11153 223040 888841.038197 909625.717406
11154 223060 888943.030680 909728.499760
11155 223080 889045.024215 909831.283133
11156 223100 889147.018803 909934.067525
11157 223120 889249.014442 910036.852937
11158 223140 889351.011133 910139.639367
11159 223160 889453.008875 910242.426816
11160 223180 889555.007669 910345.215283
11161 223200 889657.007515 910448.004769
11162 223220 889759.008411 910550.795273
11163 223240 889861.010360 910653.586796
11164 223260 889963.013359 910756.379337
11165 223280 890065.017409 910859.172896
11166 223300 890167.022510 910961.967473
11167 223320 890269.028662 911064.763068
11168 223340 890371.035865 911167.559681
11169 223360 890473.044118 911270.357312
11170 223380 890575.053422 911373.155960
11171 223400 890677.063776 911475.955626
11172 223420 890779.075181 911578.756309
11173 223440 890881.087636 911681.558010
11174 223460 890983.101140 911784.360728
11175 223480 891085.115695 911887.164463
11176 223500 891187.131300 911989.969215
11177 223520 891289.147954 912092.774983
11178 223540 891391.165658 912195.581769
11179 223560 891493.184412 912298.389572
11180 223580 891595.204215 912401.198391
11181 223600 891697.225068 912504.008226
11182 223620 891799.246970 912606.819079
11183 223640 891901.269921 912709.630947
11184 223660 892003.293921 912812.443832
11185 223680 892105.318970 912915.257732
11186 223700 892207.345068 913018.072649
11187 223720 892309.372214 913120.888582
11188 223740 892411.400409 913223.705531
11189 223760 892513.429653 913326.523495
11190 223780 892615.459945 913429.342475
11191 223800 892717.491286 913532.162471
11192 223820 892819.523674 913634.983482
11193 223840 892921.557111 913737.805508
11194 223860 893023.591596 913840.628550
11195 223880 893125.627129 913943.452606
11196 223900 893227.663709 914046.277678
11197 223920 893329.701338 914149.103765
11198 223940 893431.740014 914251.930866
11199 223960 893533.779737 914354.758983
11200 223980 893635.820508 914457.588114
11201 224000 893737.862326 914560.418259
11202 224020 893839.905191 914663.249419
11203 224040 893941.949103 914766.081594
11204 224060 894043.994063 914868.914782
11205 224080 894146.040069 914971.748985
11206 224100 894248.087122 915074.584202
11207 224120 894350.135221 915177.420432
11208 224140 894452.184368 915280.257677
11209 224160 894554.234560 915383.095935
11210 224180 894656.285799 915485.935207
11211 224200 894758.338085 915588.775493
11212 224220 894860.391416 915691.616792
11213 224240 894962.445794 915794.459104
11214 224260 895064.501217 915897.302430
11215 224280 895166.557686 916000.146769
11216 224300 895268.615201 916102.992121
11217 224320 895370.673762 916205.838486
11218 224340 895472.733368 916308.685864
11219 224360 895574.794020 916411.534254
11220 224380 895676.855717 916514.383657
11221 224400 895778.918459 916617.234073
11222 224420 895880.982246 916720.085501
11223 224440 895983.047079 916822.937942
11224 224460 896085.112956 916925.791395
11225 224480 896187.179878 917028.645860
11226 224500 896289.247845 917131.501337
11227 224520 896391.316856 917234.357826
11228 224540 896493.386912 917337.215327
11229 224560 896595.458012 917440.073840
11230 224580 896697.530157 917542.933364
11231 224600 896799.603345 917645.793900
11232 224620 896901.677578 917748.655448
11233 224640 897003.752855 917851.518007
11234 224660 897105.829176 917954.381577
11235 224680 897207.906540 918057.246158
11236 224700 897309.984949 918160.111751
11237 224720 897412.064400 918262.978354
11238 224740 897514.144896 918365.845969
11239 224760 897616.226434 918468.714594
11240 224780 897718.309016 918571.584230
11241 224800 897820.392641 918674.454876
11242 224820 897922.477310 918777.326533
11243 224840 898024.563021 918880.199201
11244 224860 898126.649775 918983.072878
11245 224880 898228.737571 919085.947566
11246 224900 898330.826411 919188.823264
11247 224920 898432.916293 919291.699972
11248 224940 898535.007217 919394.577690
11249 224960 898637.099184 919497.456418
11250 224980 898739.192193 919600.336156
11251 225000 898841.286244 919703.216903
11252 225020 898943.381337 919806.098659
11253 225040 899045.477472 919908.981425
11254 225060 899147.574649 920011.865201
11255 225080 899249.672868 920114.749985
11256 225100 899351.772128 920217.635779
11257 225120 899453.872430 920320.522582
11258 225140 899555.973773 920423.410394
11259 225160 899658.076158 920526.299214
11260 225180 899760.179583 920629.189043
11261 225200 899862.284050 920732.079881
11262 225220 899964.389558 920834.971728
11263 225240 900066.496107 920937.864582
11264 225260 900168.603697 921040.758446
11265 225280 900270.712327 921143.653317
11266 225300 900372.821998 921246.549197
11267 225320 900474.932710 921349.446084
11268 225340 900577.044462 921452.343980
11269 225360 900679.157254 921555.242883
11270 225380 900781.271086 921658.142795
11271 225400 900883.385959 921761.043714
11272 225420 900985.501871 921863.945640
11273 225440 901087.618823 921966.848574
11274 225460 901189.736816 922069.752515
11275 225480 901291.855847 922172.657464
11276 225500 901393.975919 922275.563419
11277 225520 901496.097030 922378.470382
11278 225540 901598.219180 922481.378352
11279 225560 901700.342370 922584.287329
11280 225580 901802.466598 922687.197312
11281 225600 901904.591866 922790.108302
11282 225620 902006.718173 922893.020299
11283 225640 902108.845519 922995.933302
11284 225660 902210.973903 923098.847312
11285 225680 902313.103326 923201.762327
11286 225700 902415.233788 923304.678349
11287 225720 902517.365288 923407.595378
11288 225740 902619.497827 923510.513412
11289 225760 902721.631404 923613.432452
11290 225780 902823.766019 923716.352498
11291 225800 902925.901672 923819.273549
11292 225820 903028.038362 923922.195606
11293 225840 903130.176091 924025.118669
11294 225860 903232.314858 924128.042737
11295 225880 903334.454662 924230.967810
11296 225900 903436.595504 924333.893889
11297 225920 903538.737383 924436.820973
11298 225940 903640.880300 924539.749062
11299 225960 903743.024254 924642.678155
11300 225980 903845.169245 924745.608254
11301 226000 903947.315273 924848.539357
11302 226020 904049.462338 924951.471465
11303 226040 904151.610439 925054.404577
11304 226060 904253.759578 925157.338694
11305 226080 904355.909753 925260.273815
11306 226100 904458.060965 925363.209941
11307 226120 904560.213213 925466.147071
11308 226140 904662.366497 925569.085204
11309 226160 904764.520818 925672.024342
11310 226180 904866.676175 925774.964483
11311 226200 904968.832568 925877.905629
11312 226220 905070.989997 925980.847778
11313 226240 905173.148461 926083.790930
11314 226260 905275.307962 926186.735086
11315 226280 905377.468498 926289.680245
11316 226300 905479.630069 926392.626408
11317 226320 905581.792676 926495.573574
11318 226340 905683.956318 926598.521743
11319 226360 905786.120996 926701.470914
11320 226380 905888.286708 926804.421089
11321 226400 905990.453456 926907.372267
11322 226420 906092.621238 927010.324447
11323 226440 906194.790056 927113.277630
11324 226460 906296.959908 927216.231815
11325 226480 906399.130794 927319.187003
11326 226500 906501.302716 927422.143193
11327 226520 906603.475671 927525.100385
11328 226540 906705.649661 927628.058579
11329 226560 906807.824685 927731.017776
11330 226580 906910.000743 927833.977974
11331 226600 907012.177836 927936.939174
11332 226620 907114.355962 928039.901376
11333 226640 907216.535122 928142.864580
11334 226660 907318.715315 928245.828785
11335 226680 907420.896543 928348.793991
11336 226700 907523.078803 928451.760199
11337 226720 907625.262098 928554.727408
11338 226740 907727.446425 928657.695618
11339 226760 907829.631786 928760.664829
11340 226780 907931.818179 928863.635042
11341 226800 908034.005606 928966.606255
11342 226820 908136.194066 929069.578469
11343 226840 908238.383558 929172.551683
11344 226860 908340.574083 929275.525898
11345 226880 908442.765641 929378.501114
11346 226900 908544.958231 929481.477330
11347 226920 908647.151854 929584.454546
11348 226940 908749.346509 929687.432762
11349 226960 908851.542196 929790.411979
11350 226980 908953.738915 929893.392195
11351 227000 909055.936666 929996.373411
11352 227020 909158.135450 930099.355628
11353 227040 909260.335265 930202.338843
11354 227060 909362.536111 930305.323059
11355 227080 909464.737989 930408.308274
11356 227100 909566.940899 930511.294488
11357 227120 909669.144840 930614.281702
11358 227140 909771.349812 930717.269915
11359 227160 909873.555816 930820.259127
11360 227180 909975.762851 930923.249338
11361 227200 910077.970916 931026.240548
11362 227220 910180.180013 931129.232757
11363 227240 910282.390140 931232.225964
11364 227260 910384.601298 931335.220171
11365 227280 910486.813486 931438.215375
11366 227300 910589.026706 931541.211579
11367 227320 910691.240955 931644.208780
11368 227340 910793.456235 931747.206980
11369 227360 910895.672545 931850.206178
11370 227380 910997.889885 931953.206374
11371 227400 911100.108255 932056.207568
11372 227420 911202.327655 932159.209760
11373 227440 911304.548084 932262.212950
11374 227460 911406.769544 932365.217137
11375 227480 911508.992033 932468.222322
11376 227500 911611.215551 932571.228505
11377 227520 911713.440099 932674.235685
11378 227540 911815.665676 932777.243862
11379 227560 911917.892282 932880.253036
11380 227580 912020.119918 932983.263208
11381 227600 912122.348582 933086.274376
11382 227620 912224.578275 933189.286541
11383 227640 912326.808997 933292.299704
11384 227660 912429.040748 933395.313863
11385 227680 912531.273527 933498.329018
11386 227700 912633.507335 933601.345170
11387 227720 912735.742171 933704.362319
11388 227740 912837.978036 933807.380464
11389 227760 912940.214928 933910.399605
11390 227780 913042.452849 934013.419742
11391 227800 913144.691798 934116.440876
11392 227820 913246.931774 934219.463005
11393 227840 913349.172779 934322.486130
11394 227860 913451.414811 934425.510251
11395 227880 913553.657870 934528.535368
11396 227900 913655.901958 934631.561480
11397 227920 913758.147072 934734.588588
11398 227940 913860.393214 934837.616691
11399 227960 913962.640383 934940.645789
11400 227980 914064.888579 935043.675883
11401 228000 914167.137802 935146.706971
11402 228020 914269.388052 935249.739055
11403 228040 914371.639329 935352.772134
11404 228060 914473.891633 935455.806207
11405 228080 914576.144963 935558.841275
11406 228100 914678.399319 935661.877338
11407 228120 914780.654702 935764.914395
11408 228140 914882.911112 935867.952447
11409 228160 914985.168547 935970.991493
11410 228180 915087.427009 936074.031533
11411 228200 915189.686496 936177.072568
11412 228220 915291.947010 936280.114596
11413 228240 915394.208549 936383.157619
11414 228260 915496.471114 936486.201635
11415 228280 915598.734704 936589.246645
11416 228300 915700.999320 936692.292649
11417 228320 915803.264962 936795.339646
11418 228340 915905.531629 936898.387637
11419 228360 916007.799321 937001.436621
11420 228380 916110.068038 937104.486599
11421 228400 916212.337780 937207.537570
11422 228420 916314.608547 937310.589534
11423 228440 916416.880339 937413.642490
11424 228460 916519.153155 937516.696440
11425 228480 916621.426996 937619.751383
11426 228500 916723.701862 937722.807318
11427 228520 916825.977752 937825.864246
11428 228540 916928.254666 937928.922166
11429 228560 917030.532605 938031.981079
11430 228580 917132.811567 938135.040984
11431 228600 917235.091554 938238.101882
11432 228620 917337.372564 938341.163771
11433 228640 917439.654599 938444.226653
11434 228660 917541.937657 938547.290527
11435 228680 917644.221739 938650.355392
11436 228700 917746.506844 938753.421249
11437 228720 917848.792972 938856.488098
11438 228740 917951.080124 938959.555939
11439 228760 918053.368300 939062.624771
11440 228780 918155.657498 939165.694594
11441 228800 918257.947719 939268.765409
11442 228820 918360.238964 939371.837215
11443 228840 918462.531231 939474.910012
11444 228860 918564.824520 939577.983800
11445 228880 918667.118833 939681.058579
11446 228900 918769.414168 939784.134349
11447 228920 918871.710525 939887.211109
11448 228940 918974.007905 939990.288861
11449 228960 919076.306307 940093.367602
11450 228980 919178.605731 940196.447335
11451 229000 919280.906177 940299.528057
11452 229020 919383.207645 940402.609770
11453 229040 919485.510135 940505.692473
11454 229060 919587.813647 940608.776166
11455 229080 919690.118180 940711.860849
11456 229100 919792.423735 940814.946522
11457 229120 919894.730311 940918.033184
11458 229140 919997.037909 941021.120837
11459 229160 920099.346528 941124.209479
11460 229180 920201.656168 941227.299110
11461 229200 920303.966829 941330.389731
11462 229220 920406.278511 941433.481341
11463 229240 920508.591214 941536.573941
11464 229260 920610.904937 941639.667529
11465 229280 920713.219682 941742.762107
11466 229300 920815.535447 941845.857673
11467 229320 920917.852232 941948.954228
11468 229340 921020.170038 942052.051773
11469 229360 921122.488864 942155.150305
11470 229380 921224.808710 942258.249827
11471 229400 921327.129576 942361.350336
11472 229420 921429.451462 942464.451835
11473 229440 921531.774368 942567.554321
11474 229460 921634.098294 942670.657796
11475 229480 921736.423239 942773.762258
11476 229500 921838.749204 942876.867709
11477 229520 921941.076189 942979.974148
11478 229540 922043.404193 943083.081574
11479 229560 922145.733216 943186.189988
11480 229580 922248.063258 943289.299390
11481 229600 922350.394320 943392.409779
11482 229620 922452.726400 943495.521156
11483 229640 922555.059500 943598.633520
11484 229660 922657.393618 943701.746871
11485 229680 922759.728755 943804.861210
11486 229700 922862.064910 943907.976535
11487 229720 922964.402084 944011.092848
11488 229740 923066.740276 944114.210147
11489 229760 923169.079487 944217.328433
11490 229780 923271.419716 944320.447706
11491 229800 923373.760963 944423.567965
11492 229820 923476.103228 944526.689211
11493 229840 923578.446511 944629.811444
11494 229860 923680.790811 944732.934662
11495 229880 923783.136130 944836.058867
11496 229900 923885.482466 944939.184058
11497 229920 923987.829819 945042.310235
11498 229940 924090.178190 945145.437398
11499 229960 924192.527578 945248.565546
11500 229980 924294.877984 945351.694681
11501 230000 924397.229406 945454.824801

E-023-assembly.json — 1.2 KB, updated 08-19-2026

JSON sidecar (click to expand)
{
  "experiment": "E-023",
  "task": "3.8 support: D-037 assembly (short-segment max, S_inf lower bound validation, margin/N0/N1)",
  "script": "research/numerics/scripts/E-023-finite-height-assembly.py",
  "checks": {
    "V1_sinf_lower_holds": true,
    "V2_margin_positive_convex": true,
    "V3_lambda_positive_3000": true
  },
  "key_values": {
    "M0_grid_max": 1.3323650421270834,
    "M0_lipschitz": 1.4075796709577815,
    "M0_use": 1.335180201468999,
    "C1": -1.1303307007539063,
    "C1_lower_form": -1.4189385332046727,
    "sinf_lower_min_slack": 9.520071987843544,
    "N0_measured_constants": 30217,
    "N0_traced_constants": 32871,
    "margin_N0_traced": 0.0795673057436943,
    "margin_at": {
      "32871": 0.0795673057436943,
      "100000": 287298.63095573196,
      "1000000": 5256686.503113639,
      "1000000000": 8938721534.500193,
      "1000000000000": 12396419838890.791,
      "1000000000000000000": 1.9304327085473796e+19,
      "8999999999994000000000001": 2.457962538414764e+26
    },
    "N1": 8999999999994000000000001,
    "N1_conservative_lagarias_window": 2.725978018024122e+21,
    "T0_platt_trudgian": 3000000000000.0
  },
  "elapsed_seconds": 56.2
}

Source code

Python script (click to expand)
"""E-023 — task 3.8 support: D-037 assembly computation.

Three components:
  S1. Short-segment max M0 = max |zeta'/zeta(-5/2+it)| for |t| <= 10.
      CLOSES THE D-036 GAP: the |R(s)| <= A log(t+2)+B0 bound was
      E-021-verified only for |t| >= 10; segment (III) passes within
      0.5 of the trivial pole at w = -2 (digamma pole), so the uniform
      bound fails near t = 0. Method: mpmath dps 30 grid (step 0.002)
      via the E-021 xi-route + sampled-Lipschitz correction x2 safety.
      (Only feeds an additive O(1) constant; slack is enormous.)
  S2. Validate the explicit S_inf lower bound used in D-037:
        S_inf(n) >= (1/2) n log n + (C1 - gamma/2) n - 4   (n >= 20)
      against E-021's EXACT S_inf (n <= 5000, validated 4.8e-25).
  S3. Assemble the full |S_f(n)| bound B(n) (D-036 constants, A = 0.9,
      B0 = 1.0, M0 from S1) and the margin
        margin(n) = Sinf_lower(n) - B(n) + 1;
      find N0 (margin > 0 and increasing); print margin at reference
      points and at N1 = (T0-1)^2, T0 = 3e12 (Platt-Trudgian 2021);
      conservative fallback N1* = T0^2/(4 log^2 T0) (Lagarias (1.16)).

Checks:
  V1. S_inf lower bound holds for all 20 <= n <= 5000 (exact values).
  V2. margin(n) > 0 for all n in [N0, 1e7] (grid, step 1) and margin
      convex (2nd differences > 0) on a log grid to N1 — with
      convexity + margin(N0) > 0 + margin'(N0) > 0 this gives
      margin(n) > 0 for ALL n in [N0, N1] (analytic in D-037).
  V3. lambda_n > 0 reconfirmed for n <= 3000 from E-021 exact CSV.

Outputs: research/numerics/data/E-023-assembly.csv (+ .json)
"""
import json
import sys
import time
from pathlib import Path

import mpmath as mp
import numpy as np

REPO = Path(__file__).resolve().parents[3]
DATA = REPO / "research" / "numerics" / "data"
E021 = DATA / "E-021-sinf-sf-curve.csv"
CSV = DATA / "E-023-assembly.csv"
JSON = DATA / "E-023-assembly.json"

GAMMA = 0.577215664901532860606512090082402431
C1 = (GAMMA - 1 - np.log(2 * np.pi)) / 2          # -1.1303...
C1L = C1 - GAMMA / 2                              # -1.4189... (lower-bound form)
A_USE, B0_USE = 0.9, 1.0
T0_PLATT = 3.0e12


# ---------------------------------------------------------------- S1
def zeta_logder(s):
    """zeta'/zeta via xi'/xi minus explicit terms (E-021 route, dps 30)."""
    sm = mp.mpc(s.real, s.imag)

    def xi_mp(u):
        return 0.5 * u * (u - 1) * mp.pi ** (-u / 2) * mp.gamma(u / 2) \
            * mp.zeta(u)

    xi_log = mp.diff(xi_mp, sm) / xi_mp(sm)
    return complex(xi_log - 1 / sm - 1 / (sm - 1)
                   + mp.mpf(0.5) * mp.log(mp.pi)
                   - mp.mpf(0.5) * mp.digamma(sm / 2))


def short_segment_max():
    mp.mp.dps = 30
    ts = np.arange(-10.0, 10.0 + 1e-12, 0.002)
    vals = np.array([abs(zeta_logder(complex(-2.5, t))) for t in ts])
    gmax = float(vals.max())
    # sampled Lipschitz constant (max adjacent slope), x2 safety
    lips = float(np.max(np.abs(np.diff(vals))) / 0.002)
    m0 = gmax + 0.002 * lips          # (h/2)*L would be 0.001*L; x2
    return gmax, lips, m0


# ------------------------------------------------------- D-036 pieces
def F_count(T):
    return (T / (2 * np.pi)) * np.log(T / (2 * np.pi)) - T / (2 * np.pi) \
        + 7 / 8


def S_bound(T):
    return 0.137 * np.log(T) + 0.443 * np.log(np.log(T)) + 1.588


def C0(t):
    return (F_count(t + 1) - F_count(t)) + S_bound(t + 1) + S_bound(t)


def H_bound(T, a, b0):
    return 3 * C0(T) ** 2 + a * np.log(T + 2) + b0


def B_bound(n, m0, a=A_USE, b0=B0_USE):
    """Full |S_f(n)| upper bound (D-036, variant-B contour, T = sqrt(n)+1)."""
    n = float(n)
    T = np.sqrt(n) + 1.0
    twoN = 2 * (F_count(T) + S_bound(T))
    I3_long = 4 * T * ((2 / 3) * C0(T) + a * np.log(T + 2) + b0)
    I3_short = 40.0 * m0                      # |k|<=2, length 20, max m0
    I24 = 2 * (np.e ** 4 + 1) * (7 * H_bound(T, a, b0) + 3.3)
    # I1 in log space: log I1 = log(2 sqrt(n) (e^{sqrt(n)/2}+1) 0.5699)
    #   - (2 sqrt(n) - 2) log 2  ->  hugely negative for sqrt(n) > 60
    r = np.sqrt(n)
    logI1 = np.log(2 * r * 0.5699) + r / 2 - (2 * r - 2) * np.log(2)
    I1 = np.exp(logI1) if logI1 > -700 else 0.0
    triv = 1.0
    return twoN + I3_long + I3_short + I24 + I1 + triv


def sinf_lower(n):
    n = np.asarray(n, dtype=np.float64)
    return 0.5 * n * np.log(n) + C1L * n - 4.0


def margin(n, m0, a=A_USE, b0=B0_USE):
    return sinf_lower(n) - B_bound(n, m0, a, b0) + 1.0


def find_N0(m0, a, b0):
    ngrid = np.arange(20, 400001)
    marg = np.array([margin(n, m0, a, b0) for n in ngrid])
    pos = ngrid[(marg > 0) & (np.gradient(marg, ngrid) > 0)]
    N0 = int(pos[0]) if len(pos) else -1
    cont = bool(np.all(marg[ngrid >= N0] > 0)) if N0 > 0 else False
    return N0, cont, float(marg[ngrid == N0][0]) if N0 > 0 else float("nan")


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("S1: short-segment max ...", flush=True)
    gmax, lips, m0 = short_segment_max()
    print(f"  grid max = {gmax:.4f}, Lipschitz {lips:.1f}, "
          f"M0 = {m0:.4f}", flush=True)

    print("S2: S_inf lower-bound validation vs E-021 exact ...", flush=True)
    import csv as csvmod
    with open(E021) as f:
        rows = list(csvmod.DictReader(f))
    ns = np.array([int(r["n"]) for r in rows])
    sinf = np.array([float(r["S_inf"]) for r in rows])
    lam = np.array([float(r["lambda_n"]) for r in rows])
    mask = ns >= 20
    slack = sinf[mask] - sinf_lower(ns[mask])
    v1 = bool(np.all(slack > 0))
    print(f"  V1: min slack = {slack.min():.4f} at n = "
          f"{ns[mask][slack.argmin()]} (bound holds: {v1})", flush=True)
    v3 = bool(np.all(lam[ns <= 3000] > 0))
    print(f"  V3: lambda_n > 0 for n <= 3000 reconfirmed: {v3}", flush=True)

    print("S3: margin assembly ...", flush=True)
    # Two constant sets: measured (0.9, 1.0) and traced (2.0, 2.0, the
    # D-036 first-estimate analytic assembly).
    N0_meas, cont_meas, margN0_meas = find_N0(m0, 0.9, 1.0)
    N0_tr, cont_tr, margN0_tr = find_N0(m0, 2.0, 2.0)
    N0, cont = N0_tr, cont_tr
    print(f"  N0 (measured 0.9/1.0) = {N0_meas} (contiguous {cont_meas})")
    print(f"  N0 (traced   2.0/2.0) = {N0_tr} (contiguous {cont_tr})")

    logn = np.unique(np.logspace(np.log10(max(N0, 20)), np.log10(9e24),
                                 4000).astype(np.float64))
    bmarg = np.array([margin(n, m0, 2.0, 2.0) for n in logn])
    conv = bool(np.all(np.diff(bmarg, 2) > -1e-6 * bmarg[:-2].max()))

    N1 = int(3_000_000_000_000 - 1) ** 2
    N1_cons = T0_PLATT ** 2 / (4 * np.log(T0_PLATT) ** 2)
    refs = {int(n): float(margin(n, m0, 2.0, 2.0)) for n in
            [N0, 100000, 10 ** 6, 10 ** 9, 10 ** 12, 10 ** 18, N1]}
    print(f"  N0 = {N0} (traced; contiguous to 4e5: {cont}, "
          f"convex: {conv})")
    print(f"  margin(N0) = {refs[N0]:.1f}")
    print(f"  N1 = (T0-1)^2 = {N1:.6e};  N1* (Lagarias window) = "
          f"{N1_cons:.6e}")
    print(f"  margin(N1) = {refs[N1]:.3e}")

    v2 = bool(N0 > 0 and cont and conv and cont_meas)

    with open(CSV, "w", newline="") as f:
        w = csvmod.writer(f)
        w.writerow(["n", "margin_traced", "margin_measured"])
        for n in range(20, 400001, 20):
            w.writerow([n, f"{margin(n, m0, 2.0, 2.0):.6f}",
                        f"{margin(n, m0, 0.9, 1.0):.6f}"])

    meta = {
        "experiment": "E-023",
        "task": "3.8 support: D-037 assembly (short-segment max, S_inf "
                "lower bound validation, margin/N0/N1)",
        "script": "research/numerics/scripts/E-023-finite-height-assembly.py",
        "checks": {"V1_sinf_lower_holds": v1,
                   "V2_margin_positive_convex": v2,
                   "V3_lambda_positive_3000": v3},
        "key_values": {
            "M0_grid_max": gmax, "M0_lipschitz": lips, "M0_use": m0,
            "C1": C1, "C1_lower_form": C1L,
            "sinf_lower_min_slack": float(slack.min()),
            "N0_measured_constants": N0_meas,
            "N0_traced_constants": N0_tr,
            "margin_N0_traced": margN0_tr,
            "margin_at": {str(k): float(v) for k, v in refs.items()},
            "N1": N1, "N1_conservative_lagarias_window": N1_cons,
            "T0_platt_trudgian": T0_PLATT,
        },
        "elapsed_seconds": round(time.time() - t0, 1),
    }
    JSON.write_text(json.dumps(meta, indent=2))
    print(f"  wrote {CSV.name}, {JSON.name}; "
          f"elapsed {meta['elapsed_seconds']}s")
    return 0 if (v1 and v2 and v3) else 1


if __name__ == "__main__":
    sys.exit(main())