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 15 of 40 · 500/page · 20000 rows next →
# nmargin_tracedmargin_measured
7002 140020 476117.348517 493270.256875
7003 140040 476213.723419 493367.613879
7004 140060 476310.100098 493464.972594
7005 140080 476406.478554 493562.333020
7006 140100 476502.858787 493659.695157
7007 140120 476599.240797 493757.059004
7008 140140 476695.624582 493854.424562
7009 140160 476792.010144 493951.791830
7010 140180 476888.397482 494049.160808
7011 140200 476984.786595 494146.531495
7012 140220 477081.177483 494243.903891
7013 140240 477177.570146 494341.277996
7014 140260 477273.964584 494438.653810
7015 140280 477370.360795 494536.031332
7016 140300 477466.758781 494633.410562
7017 140320 477563.158540 494730.791500
7018 140340 477659.560073 494828.174145
7019 140360 477755.963379 494925.558498
7020 140380 477852.368458 495022.944558
7021 140400 477948.775309 495120.332324
7022 140420 478045.183932 495217.721797
7023 140440 478141.594327 495315.112976
7024 140460 478238.006494 495412.505861
7025 140480 478334.420433 495509.900451
7026 140500 478430.836142 495607.296747
7027 140520 478527.253622 495704.694748
7028 140540 478623.672873 495802.094453
7029 140560 478720.093894 495899.495864
7030 140580 478816.516684 495996.898978
7031 140600 478912.941245 496094.303796
7032 140620 479009.367574 496191.710318
7033 140640 479105.795673 496289.118543
7034 140660 479202.225540 496386.528472
7035 140680 479298.657176 496483.940103
7036 140700 479395.090580 496581.353437
7037 140720 479491.525752 496678.768473
7038 140740 479587.962692 496776.185211
7039 140760 479684.401398 496873.603651
7040 140780 479780.841872 496971.023792
7041 140800 479877.284113 497068.445635
7042 140820 479973.728120 497165.869178
7043 140840 480070.173893 497263.294422
7044 140860 480166.621432 497360.721367
7045 140880 480263.070737 497458.150012
7046 140900 480359.521807 497555.580356
7047 140920 480455.974641 497653.012400
7048 140940 480552.429241 497750.446143
7049 140960 480648.885605 497847.881586
7050 140980 480745.343733 497945.318727
7051 141000 480841.803625 498042.757566
7052 141020 480938.265281 498140.198104
7053 141040 481034.728700 498237.640339
7054 141060 481131.193882 498335.084273
7055 141080 481227.660826 498432.529903
7056 141100 481324.129533 498529.977231
7057 141120 481420.600002 498627.426255
7058 141140 481517.072233 498724.876976
7059 141160 481613.546226 498822.329394
7060 141180 481710.021979 498919.783507
7061 141200 481806.499494 499017.239316
7062 141220 481902.978770 499114.696821
7063 141240 481999.459806 499212.156020
7064 141260 482095.942602 499309.616915
7065 141280 482192.427157 499407.079504
7066 141300 482288.913473 499504.543788
7067 141320 482385.401547 499602.009766
7068 141340 482481.891381 499699.477437
7069 141360 482578.382973 499796.946802
7070 141380 482674.876324 499894.417861
7071 141400 482771.371433 499991.890612
7072 141420 482867.868300 500089.365056
7073 141440 482964.366924 500186.841193
7074 141460 483060.867305 500284.319022
7075 141480 483157.369444 500381.798543
7076 141500 483253.873339 500479.279755
7077 141520 483350.378991 500576.762659
7078 141540 483446.886399 500674.247254
7079 141560 483543.395562 500771.733539
7080 141580 483639.906481 500869.221516
7081 141600 483736.419156 500966.711182
7082 141620 483832.933585 501064.202539
7083 141640 483929.449769 501161.695585
7084 141660 484025.967708 501259.190321
7085 141680 484122.487401 501356.686746
7086 141700 484219.008847 501454.184861
7087 141720 484315.532047 501551.684663
7088 141740 484412.057001 501649.186154
7089 141760 484508.583707 501746.689334
7090 141780 484605.112166 501844.194201
7091 141800 484701.642378 501941.700756
7092 141820 484798.174342 502039.208998
7093 141840 484894.708057 502136.718927
7094 141860 484991.243525 502234.230543
7095 141880 485087.780743 502331.743845
7096 141900 485184.319713 502429.258834
7097 141920 485280.860433 502526.775509
7098 141940 485377.402904 502624.293869
7099 141960 485473.947124 502721.813915
7100 141980 485570.493095 502819.335646
7101 142000 485667.040816 502916.859062
7102 142020 485763.590285 503014.384162
7103 142040 485860.141504 503111.910947
7104 142060 485956.694471 503209.439416
7105 142080 486053.249187 503306.969569
7106 142100 486149.805652 503404.501406
7107 142120 486246.363864 503502.034925
7108 142140 486342.923823 503599.570128
7109 142160 486439.485530 503697.107013
7110 142180 486536.048984 503794.645581
7111 142200 486632.614185 503892.185832
7112 142220 486729.181133 503989.727764
7113 142240 486825.749826 504087.271378
7114 142260 486922.320266 504184.816673
7115 142280 487018.892451 504282.363649
7116 142300 487115.466382 504379.912306
7117 142320 487212.042057 504477.462644
7118 142340 487308.619478 504575.014662
7119 142360 487405.198643 504672.568361
7120 142380 487501.779552 504770.123739
7121 142400 487598.362205 504867.680796
7122 142420 487694.946602 504965.239533
7123 142440 487791.532743 505062.799949
7124 142460 487888.120626 505160.362044
7125 142480 487984.710252 505257.925817
7126 142500 488081.301621 505355.491268
7127 142520 488177.894732 505453.058397
7128 142540 488274.489585 505550.627204
7129 142560 488371.086180 505648.197689
7130 142580 488467.684517 505745.769850
7131 142600 488564.284594 505843.343688
7132 142620 488660.886412 505940.919203
7133 142640 488757.489971 506038.496395
7134 142660 488854.095271 506136.075262
7135 142680 488950.702310 506233.655805
7136 142700 489047.311089 506331.238024
7137 142720 489143.921608 506428.821918
7138 142740 489240.533865 506526.407487
7139 142760 489337.147862 506623.994731
7140 142780 489433.763597 506721.583649
7141 142800 489530.381071 506819.174241
7142 142820 489627.000283 506916.766507
7143 142840 489723.621233 507014.360448
7144 142860 489820.243920 507111.956061
7145 142880 489916.868344 507209.553348
7146 142900 490013.494506 507307.152307
7147 142920 490110.122404 507404.752939
7148 142940 490206.752038 507502.355244
7149 142960 490303.383409 507599.959220
7150 142980 490400.016515 507697.564868
7151 143000 490496.651357 507795.172188
7152 143020 490593.287935 507892.781180
7153 143040 490689.926247 507990.391842
7154 143060 490786.566294 508088.004175
7155 143080 490883.208076 508185.618178
7156 143100 490979.851592 508283.233852
7157 143120 491076.496841 508380.851196
7158 143140 491173.143825 508478.470209
7159 143160 491269.792541 508576.090892
7160 143180 491366.442991 508673.713244
7161 143200 491463.095174 508771.337265
7162 143220 491559.749089 508868.962954
7163 143240 491656.404736 508966.590312
7164 143260 491753.062116 509064.219338
7165 143280 491849.721227 509161.850032
7166 143300 491946.382069 509259.482394
7167 143320 492043.044643 509357.116423
7168 143340 492139.708947 509454.752119
7169 143360 492236.374982 509552.389481
7170 143380 492333.042747 509650.028511
7171 143400 492429.712243 509747.669206
7172 143420 492526.383468 509845.311568
7173 143440 492623.056422 509942.955595
7174 143460 492719.731106 510040.601288
7175 143480 492816.407519 510138.248646
7176 143500 492913.085660 510235.897669
7177 143520 493009.765530 510333.548357
7178 143540 493106.447128 510431.200709
7179 143560 493203.130454 510528.854725
7180 143580 493299.815507 510626.510405
7181 143600 493396.502287 510724.167749
7182 143620 493493.190795 510821.826756
7183 143640 493589.881029 510919.487427
7184 143660 493686.572990 511017.149760
7185 143680 493783.266676 511114.813756
7186 143700 493879.962089 511212.479414
7187 143720 493976.659227 511310.146734
7188 143740 494073.358091 511407.815716
7189 143760 494170.058680 511505.486360
7190 143780 494266.760993 511603.158665
7191 143800 494363.465031 511700.832631
7192 143820 494460.170794 511798.508258
7193 143840 494556.878280 511896.185545
7194 143860 494653.587490 511993.864492
7195 143880 494750.298423 512091.545100
7196 143900 494847.011080 512189.227367
7197 143920 494943.725459 512286.911293
7198 143940 495040.441561 512384.596879
7199 143960 495137.159386 512482.284124
7200 143980 495233.878932 512579.973027
7201 144000 495330.600200 512677.663589
7202 144020 495427.323190 512775.355809
7203 144040 495524.047900 512873.049687
7204 144060 495620.774332 512970.745223
7205 144080 495717.502485 513068.442416
7206 144100 495814.232358 513166.141266
7207 144120 495910.963951 513263.841772
7208 144140 496007.697264 513361.543936
7209 144160 496104.432296 513459.247756
7210 144180 496201.169048 513556.953232
7211 144200 496297.907519 513654.660363
7212 144220 496394.647708 513752.369151
7213 144240 496491.389616 513850.079593
7214 144260 496588.133243 513947.791691
7215 144280 496684.878587 514045.505443
7216 144300 496781.625649 514143.220850
7217 144320 496878.374428 514240.937911
7218 144340 496975.124924 514338.656626
7219 144360 497071.877138 514436.376995
7220 144380 497168.631068 514534.099017
7221 144400 497265.386714 514631.822693
7222 144420 497362.144076 514729.548021
7223 144440 497458.903154 514827.275002
7224 144460 497555.663947 514925.003636
7225 144480 497652.426456 515022.733922
7226 144500 497749.190680 515120.465860
7227 144520 497845.956618 515218.199449
7228 144540 497942.724271 515315.934690
7229 144560 498039.493638 515413.671582
7230 144580 498136.264719 515511.410125
7231 144600 498233.037513 515609.150318
7232 144620 498329.812021 515706.892162
7233 144640 498426.588241 515804.635656
7234 144660 498523.366175 515902.380800
7235 144680 498620.145821 516000.127593
7236 144700 498716.927179 516097.876036
7237 144720 498813.710249 516195.626128
7238 144740 498910.495031 516293.377868
7239 144760 499007.281524 516391.131258
7240 144780 499104.069729 516488.886295
7241 144800 499200.859644 516586.642981
7242 144820 499297.651270 516684.401314
7243 144840 499394.444606 516782.161295
7244 144860 499491.239653 516879.922923
7245 144880 499588.036409 516977.686198
7246 144900 499684.834875 517075.451120
7247 144920 499781.635050 517173.217689
7248 144940 499878.436934 517270.985903
7249 144960 499975.240526 517368.755764
7250 144980 500072.045827 517466.527270
7251 145000 500168.852837 517564.300422
7252 145020 500265.661554 517662.075220
7253 145040 500362.471979 517759.851662
7254 145060 500459.284111 517857.629748
7255 145080 500556.097950 517955.409480
7256 145100 500652.913496 518053.190855
7257 145120 500749.730749 518150.973874
7258 145140 500846.549708 518248.758538
7259 145160 500943.370373 518346.544844
7260 145180 501040.192744 518444.332794
7261 145200 501137.016820 518542.122386
7262 145220 501233.842602 518639.913622
7263 145240 501330.670088 518737.706499
7264 145260 501427.499279 518835.501019
7265 145280 501524.330175 518933.297181
7266 145300 501621.162774 519031.094984
7267 145320 501717.997078 519128.894429
7268 145340 501814.833085 519226.695514
7269 145360 501911.670796 519324.498241
7270 145380 502008.510209 519422.302608
7271 145400 502105.351326 519520.108616
7272 145420 502202.194144 519617.916264
7273 145440 502299.038666 519715.725551
7274 145460 502395.884889 519813.536478
7275 145480 502492.732814 519911.349045
7276 145500 502589.582440 520009.163251
7277 145520 502686.433768 520106.979095
7278 145540 502783.286796 520204.796578
7279 145560 502880.141525 520302.615699
7280 145580 502976.997955 520400.436459
7281 145600 503073.856084 520498.258856
7282 145620 503170.715914 520596.082891
7283 145640 503267.577443 520693.908563
7284 145660 503364.440671 520791.735872
7285 145680 503461.305599 520889.564818
7286 145700 503558.172225 520987.395400
7287 145720 503655.040550 521085.227619
7288 145740 503751.910573 521183.061473
7289 145760 503848.782294 521280.896964
7290 145780 503945.655712 521378.734090
7291 145800 504042.530829 521476.572851
7292 145820 504139.407642 521574.413248
7293 145840 504236.286152 521672.255279
7294 145860 504333.166359 521770.098944
7295 145880 504430.048263 521867.944244
7296 145900 504526.931862 521965.791178
7297 145920 504623.817157 522063.639745
7298 145940 504720.704148 522161.489947
7299 145960 504817.592835 522259.341781
7300 145980 504914.483216 522357.195248
7301 146000 505011.375292 522455.050348
7302 146020 505108.269062 522552.907081
7303 146040 505205.164527 522650.765445
7304 146060 505302.061686 522748.625442
7305 146080 505398.960539 522846.487071
7306 146100 505495.861085 522944.350330
7307 146120 505592.763324 523042.215222
7308 146140 505689.667256 523140.081744
7309 146160 505786.572881 523237.949896
7310 146180 505883.480199 523335.819680
7311 146200 505980.389208 523433.691093
7312 146220 506077.299909 523531.564137
7313 146240 506174.212302 523629.438810
7314 146260 506271.126386 523727.315112
7315 146280 506368.042162 523825.193044
7316 146300 506464.959628 523923.072605
7317 146320 506561.878785 524020.953794
7318 146340 506658.799632 524118.836612
7319 146360 506755.722169 524216.721058
7320 146380 506852.646396 524314.607132
7321 146400 506949.572312 524412.494834
7322 146420 507046.499917 524510.384163
7323 146440 507143.429212 524608.275120
7324 146460 507240.360195 524706.167703
7325 146480 507337.292867 524804.061913
7326 146500 507434.227226 524901.957749
7327 146520 507531.163274 524999.855212
7328 146540 507628.101010 525097.754300
7329 146560 507725.040432 525195.655015
7330 146580 507821.981542 525293.557354
7331 146600 507918.924339 525391.461319
7332 146620 508015.868822 525489.366909
7333 146640 508112.814992 525587.274123
7334 146660 508209.762848 525685.182962
7335 146680 508306.712389 525783.093425
7336 146700 508403.663616 525881.005512
7337 146720 508500.616529 525978.919223
7338 146740 508597.571126 526076.834557
7339 146760 508694.527408 526174.751514
7340 146780 508791.485375 526272.670094
7341 146800 508888.445026 526370.590297
7342 146820 508985.406361 526468.512122
7343 146840 509082.369379 526566.435570
7344 146860 509179.334081 526664.360639
7345 146880 509276.300466 526762.287330
7346 146900 509373.268534 526860.215643
7347 146920 509470.238285 526958.145576
7348 146940 509567.209718 527056.077131
7349 146960 509664.182834 527154.010306
7350 146980 509761.157631 527251.945102
7351 147000 509858.134110 527349.881518
7352 147020 509955.112270 527447.819554
7353 147040 510052.092111 527545.759209
7354 147060 510149.073633 527643.700484
7355 147080 510246.056835 527741.643379
7356 147100 510343.041718 527839.587892
7357 147120 510440.028281 527937.534023
7358 147140 510537.016524 528035.481774
7359 147160 510634.006446 528133.431142
7360 147180 510730.998048 528231.382128
7361 147200 510827.991328 528329.334733
7362 147220 510924.986288 528427.288954
7363 147240 511021.982925 528525.244793
7364 147260 511118.981241 528623.202248
7365 147280 511215.981235 528721.161321
7366 147300 511312.982907 528819.122010
7367 147320 511409.986256 528917.084315
7368 147340 511506.991282 529015.048236
7369 147360 511603.997985 529113.013772
7370 147380 511701.006365 529210.980925
7371 147400 511798.016421 529308.949692
7372 147420 511895.028153 529406.920074
7373 147440 511992.041561 529504.892071
7374 147460 512089.056645 529602.865683
7375 147480 512186.073404 529700.840909
7376 147500 512283.091838 529798.817748
7377 147520 512380.111947 529896.796202
7378 147540 512477.133731 529994.776269
7379 147560 512574.157189 530092.757949
7380 147580 512671.182321 530190.741242
7381 147600 512768.209127 530288.726148
7382 147620 512865.237606 530386.712667
7383 147640 512962.267759 530484.700797
7384 147660 513059.299584 530582.690540
7385 147680 513156.333083 530680.681894
7386 147700 513253.368254 530778.674860
7387 147720 513350.405097 530876.669438
7388 147740 513447.443612 530974.665626
7389 147760 513544.483799 531072.663425
7390 147780 513641.525657 531170.662834
7391 147800 513738.569187 531268.663854
7392 147820 513835.614387 531366.666484
7393 147840 513932.661258 531464.670724
7394 147860 514029.709800 531562.676573
7395 147880 514126.760012 531660.684031
7396 147900 514223.811893 531758.693099
7397 147920 514320.865445 531856.703775
7398 147940 514417.920665 531954.716060
7399 147960 514514.977555 532052.729953
7400 147980 514612.036114 532150.745455
7401 148000 514709.096341 532248.762564
7402 148020 514806.158237 532346.781280
7403 148040 514903.221801 532444.801604
7404 148060 515000.287033 532542.823535
7405 148080 515097.353932 532640.847073
7406 148100 515194.422499 532738.872218
7407 148120 515291.492732 532836.898969
7408 148140 515388.564633 532934.927326
7409 148160 515485.638200 533032.957288
7410 148180 515582.713433 533130.988857
7411 148200 515679.790333 533229.022031
7412 148220 515776.868898 533327.056810
7413 148240 515873.949129 533425.093193
7414 148260 515971.031025 533523.131182
7415 148280 516068.114586 533621.170775
7416 148300 516165.199812 533719.211972
7417 148320 516262.286703 533817.254773
7418 148340 516359.375257 533915.299177
7419 148360 516456.465476 534013.345185
7420 148380 516553.557358 534111.392796
7421 148400 516650.650904 534209.442010
7422 148420 516747.746113 534307.492827
7423 148440 516844.842985 534405.545246
7424 148460 516941.941520 534503.599268
7425 148480 517039.041718 534601.654891
7426 148500 517136.143577 534699.712116
7427 148520 517233.247099 534797.770942
7428 148540 517330.352282 534895.831370
7429 148560 517427.459126 534993.893399
7430 148580 517524.567632 535091.957028
7431 148600 517621.677799 535190.022258
7432 148620 517718.789626 535288.089088
7433 148640 517815.903114 535386.157519
7434 148660 517913.018262 535484.227549
7435 148680 518010.135070 535582.299178
7436 148700 518107.253537 535680.372407
7437 148720 518204.373664 535778.447235
7438 148740 518301.495450 535876.523661
7439 148760 518398.618895 535974.601686
7440 148780 518495.743999 536072.681310
7441 148800 518592.870761 536170.762531
7442 148820 518689.999181 536268.845351
7443 148840 518787.129259 536366.929767
7444 148860 518884.260994 536465.015782
7445 148880 518981.394387 536563.103393
7446 148900 519078.529437 536661.192601
7447 148920 519175.666144 536759.283406
7448 148940 519272.804508 536857.375807
7449 148960 519369.944527 536955.469804
7450 148980 519467.086203 537053.565397
7451 149000 519564.229535 537151.662586
7452 149020 519661.374522 537249.761370
7453 149040 519758.521165 537347.861750
7454 149060 519855.669463 537445.963724
7455 149080 519952.819415 537544.067293
7456 149100 520049.971022 537642.172456
7457 149120 520147.124284 537740.279214
7458 149140 520244.279199 537838.387566
7459 149160 520341.435769 537936.497511
7460 149180 520438.593992 538034.609049
7461 149200 520535.753868 538132.722181
7462 149220 520632.915397 538230.836906
7463 149240 520730.078579 538328.953224
7464 149260 520827.243414 538427.071134
7465 149280 520924.409900 538525.190637
7466 149300 521021.578039 538623.311731
7467 149320 521118.747830 538721.434417
7468 149340 521215.919272 538819.558695
7469 149360 521313.092366 538917.684564
7470 149380 521410.267110 539015.812024
7471 149400 521507.443505 539113.941075
7472 149420 521604.621551 539212.071717
7473 149440 521701.801247 539310.203949
7474 149460 521798.982593 539408.337771
7475 149480 521896.165589 539506.473182
7476 149500 521993.350235 539604.610184
7477 149520 522090.536529 539702.748775
7478 149540 522187.724473 539800.888955
7479 149560 522284.914065 539899.030724
7480 149580 522382.105306 539997.174081
7481 149600 522479.298195 540095.319027
7482 149620 522576.492732 540193.465561
7483 149640 522673.688917 540291.613683
7484 149660 522770.886750 540389.763393
7485 149680 522868.086229 540487.914690
7486 149700 522965.287356 540586.067575
7487 149720 523062.490129 540684.222046
7488 149740 523159.694549 540782.378105
7489 149760 523256.900615 540880.535749
7490 149780 523354.108327 540978.694980
7491 149800 523451.317685 541076.855797
7492 149820 523548.528689 541175.018200
7493 149840 523645.741337 541273.182188
7494 149860 523742.955631 541371.347762
7495 149880 523840.171569 541469.514921
7496 149900 523937.389152 541567.683664
7497 149920 524034.608379 541665.853993
7498 149940 524131.829250 541764.025905
7499 149960 524229.051765 541862.199402
7500 149980 524326.275923 541960.374482
7501 150000 524423.501724 542058.551146

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