# Root merge 1 of 3: beating qt1 on the AMM puzzle (25 results merged) Credit: the solved policy, Gaussian and lattice filters, qm tables, replica (`replica2.py`), `gates.py` and engine harness are by **Taylor (gtmcknight)**, [amm-sim `research/solved` @4812a638](https://github.com/gtmcknight/amm-sim/tree/4812a6382311624e1506aca131ca35c378f930d9/research/solved). qt1 is the Solidity block of [Q](https://api.imdnotdead.fun/artifacts/8a6e303b662e1a5ea9bb47f31acedd3988ef65b3ddb66d074517aa59ad41ca40); the table compression is qm-spline's ([artifact](https://api.imdnotdead.fun/artifacts/17d249ab0c33fc44931d9b105cf3f9e3846a560bd518b67310c2a56defacdecc)). How to read this. Every figure carries the input it came from (`b01-p-choose` … `b12-cuts-1`, the files under `.imd/reads/artifacts/`; each is `artifacts/goal/batches//items//result.md`). This merge ran nothing: figures are the items' own local measurements, except the few marked "computed in this merge" (sums, ratios, one pooled mean). "Replica" is Taylor's pure-Python replica; "engine" is `amm_sim_rs.run_batch` against the 30 bps VanillaStrategy. **No figure here is a board score, and no result is a board submission.** Code, diffs, per-seed tables and raw `gas_stats()` records stay in the item results; only hashes and summaries are kept here. ## 0. Bottom line 1. **Gates on qt1 hold.** Gate P reproduced in 21 of 25 results with no failure (the other 4 did not run it); qt1's reference values, hashes, runtime size (20,605 B) and Gate F (max about 5.8e-6 to 6.7e-6 bps) all reproduce (sections 1 to 3). 2. **One candidate beats qt1 on the engine inside every limit: TwoComp on qtr2.** Two independent ports: **+0.414 (se 0.042)** with peak 201,916 gas and 21,102 B (b10-port-a), and **+0.439 (se 0.045)** with peak 213,439 gas and 21,197 B (b10-port-b); n = 128 fresh seeds each, 0 OutOfGas, Gate F passes (section 9). Its Gate Q is **+0.4248 (se 0.0122)** on the report window (b05-latt-two-comp, reproduced by four other items). That is about the size of the gap to 7th on the board (+0.44), not clearly past it. 3. **The best replica policy is COMBO** (TwoComp + pi-weighted first-trade quoting): **+0.60 (se 0.013)** over qt1-ref on the report window, in two independent implementations. It has no Solidity, gas, Gate F or engine result, and the gas figures available say a second lookup does not obviously fit (section 10). 4. **Gas headroom found:** qtr2 runs about 17–18k below qt1 at the peak; binary span search saves 2,647 more; on qt1 itself, basis edits saved 10,507 and dispatch 235. Table-loading changes saved nothing (sections 6, 7). 5. **Dead ends, measured:** max-fee quoting (−4.63), the classifier corrections (+0.008, se 0.007; and an incomplete one), DUAL_CUTS=1 (no better), the coarse lattice as specified (+0.52 like-for-like on the replica but an estimated 1.06M-gas worst callback) (sections 4, 5, 8, 11). 6. **Two things the write-up must state carefully:** "Gate F passes" means against fees after `replica2.clampf`, because `QMRef` returns uncapped fees (sections 3, 7); and the choose-window baseline of b01-p-choose is not bit-reproducible on Linux on 17 to 19 seeds (section 10). ## Status of the 25 inputs | input | kind | status | headline | |---|---|---|---| | b01-p-choose | replica | complete | Gate P pass; qt1-ref on 60000..61023: mean 529.971160 (macOS) | | b01-p-report | replica | complete | Gate P pass; qt1-ref on 10000..12047: mean 533.262831 | | b02-eb-a | engine | **blocked** (Darwin arm64) | nothing; seeds 9800000..9800127 unused | | b02-eb-b | engine | complete | qt1: mean 513.505, peak 209,112, 20,605 B | | b03-gf-a | Gate F | complete | qt1 passes, max 5.83e-6 bps (70000..70049) | | b03-gf-b | Gate F | complete | qt1 passes, max 6.71e-6 bps (70050..70099) | | b04-mix-wavg-offsets | replica screen | complete (choose half only) | +0.2773 (se 0.0215) | | b04-mix-wavg-fees | replica screen | complete (choose half only) | +0.2782 (se 0.0216) | | b04-mix-max-fee | replica screen | complete; rejected | −4.6317 (se 0.0558) | | b05-latt-c5 | replica screen + gas estimate | complete; over gas | +0.5788 (se 0.0245); est. worst callback 1.06M to 1.62M gas | | b05-latt-two-comp | replica screen + report | complete | **+0.4248 (se 0.0122) report**; this is "TC" | | b06-gas-basis | qt1 gas edit, engine | complete; 40k target missed | peak −10,507, edges identical | | b06-gas-dispatch | qt1 gas edit, engine | complete; 40k target missed | peak −235, edges identical | | b07-trunk-seed | repository seeding | complete | qt1 + Taylor references committed, hashes verified | | b08-qtr2-control | audit of qtr2 | **blocked** (setup `mkdir`, path with spaces) | nothing; seeds 9800320..9800447 unused | | b08-qtr2-spans | qtr2 gas edit, engine | complete | peak 191,821 → 189,174, edges identical to qtr2 | | b08-qtr2-loads | qtr2 gas edits, engine | **partial**; negative | empty patch; reports Gate F failed (raw reading); 64 of 128 seeds | | b09-class-size | replica | **incomplete** Gate Q (n = 32 + 32) | +0.059 (se 0.051): nothing shown | | b09-class-age | replica, Gate Q | complete; no gain | +0.0084 (se 0.0072) report | | b10-port-a | Solidity port + engine | complete | **+0.4145 (se 0.0423)**, peak 201,916, 21,102 B | | b10-port-b | Solidity port + engine | complete | **+0.4385 (se 0.0452)**, peak 213,439, 21,197 B | | b10-port-c | Solidity port | **blocked** (Darwin arm64) | nothing (243-byte result) | | b11-combo-fees | replica, Gate Q | complete | **+0.5986 (se 0.0134) report** | | b11-combo-offsets | replica, Gate Q | complete | **+0.5974 (se 0.0134) report** | | b12-cuts-1 | replica, Gate Q | complete; no gain | cuts=1 minus cuts=2: −0.0014 (se 0.0041) report | No input was missing or empty. Four produced no measurement (b02-eb-a, b08-qtr2-control, b10-port-c blocked; b09-class-size too small to conclude). **Sources that did not hold on re-read** (as reported to this merge; which individual sources failed was not given): b01-p-choose 3, b01-p-report 1, b03-gf-b 1, b04-mix-wavg-offsets 2, b08-qtr2-spans 2, b09-class-age 1, b11-combo-fees 1, b11-combo-offsets 2. In all eight the headline numbers are local runs, not quotations, and each is corroborated by at least one unflagged result (noted per section). What is weakened is the quoted context: published baselines, README statements, descriptions of other artifacts. Those are marked "as reported" where they matter. ## 1. Gate P, the qt1 reference and the replica baselines (b01-p-choose, b01-p-report, b07-trunk-seed) **Gate P: PASS, three times, on two platforms.** Unmodified `python3 -I gates.py` in Taylor's `research/solved` at 4812a638 printed the same table in all three results: ``` seed perfect-info gaussian+plain gaussian+qm lattice+qm 10000 448.261189 443.455598 443.522608 443.663520 10001 576.779199 571.463409 571.623551 571.977293 10002 531.886497 525.168028 525.865859 526.411631 ``` | result | platform | run time | note | |---|---|---|---| | b01-p-choose | CPython 3.9.6, macOS arm64, 10 cores | 5.0 s | checkout was GitHub's archive of the commit (2,109,402 bytes, sha256 `b698daa9…2bcb36`) because the sandbox refused `git clone`; 8 files byte-identical to raw.githubusercontent.com at that hash | | b01-p-report | CPython 3.12.3, Linux x86_64, 8 cores | 7.0 s | `git clone` + checkout worked | | b07-trunk-seed | not stated | not stated | ran an unchanged copy under `scratch/check`; "all expected rows matched exactly" | In all, 21 of the 25 results reproduced this table before doing anything else; b02-eb-a, b02-eb-b, b08-qtr2-control and b10-port-c did not run it. **Reference check: PASS in all three.** `replica2.run(seed, QMRef('blob.bin'))['edge']` gives 443.101741 / 571.454483 / 525.908441 for seeds 10000 / 10001 / 10002 (b01-p-choose, full precision 443.1017411146671 / 571.4544833819275 / 525.9084411612362; b01-p-report; b07-trunk-seed checked seed 10000 only). **Hashes measured** (b01-p-choose, b01-p-report and b07-trunk-seed agree on every one): | piece | bytes | sha256 | stated by source | |---|---:|---|---| | Q, the qt1 artifact (markdown) | 62,223 | `8a6e303b662e1a5ea9bb47f31acedd3988ef65b3ddb66d074517aa59ad41ca40` | artifact id: match | | qt1 `Strategy.sol` (Q's `## Strategy.sol` block, with its final newline) | 42,990 | `c68887cff61180e12ba2b1ceb333edf76a830f91f63b5d775a8806fb9ec08aca` | brief and Q: match | | `qmref.py` (Q's `## Python reference` block) | 7,739 | `1dfc9b7a3c2237ff7a93dd9f0af54b9bdab16f2ce0a7eb00784cb4432598db92` | Q states no hash; this is measured only | | qm-spline artifact (markdown) | 29,486 | `17d249ab0c33fc44931d9b105cf3f9e3846a560bd518b67310c2a56defacdecc` | artifact id: match | | `blob.bin` (QMS1, base64 under `## Data`, decoded) | 10,167 | `3ac7cb8811ecfb6a17f499aa4e9b70dd55f7fb6432b3aec3b904e11a3dece38e` | qm-spline and Q: match | b01-p-choose adds: the Strategy.sol hash only matches with the block's final newline (without it, 42,989 bytes, sha256 `f3179686…`). Taylor's files, sha256 (b01-p-choose; b07-trunk-seed lists the same values): README.md `02d2b51f…c0cef2`, gates.py `603280c1…cce604`, replica2.py `6e37b4e6…dca685`, real.py `1305b533…f2c81e`, evalpol.py `6e67667b…e6a27c`, latt.py `925c0fe9…a00cc8`, pol_mid.json `efbb5ee1…f2983b`, qm_k1e-5.json `5ff53e42…a1afd`. **qt1-ref baselines on Taylor's replica** (each seed once, `n_steps` default 10000): | window | n | mean | sd (n−1) | se | min | max | source | |---|---:|---:|---:|---:|---|---|---| | choose 60000..61023 | 1024 | 529.971160 | 91.977882 | 2.874309 | 328.751730 (seed 60317) | 849.013574 (seed 60210) | b01-p-choose; median 526.726176 | | report 10000..12047 | 2048 | 533.262831 | 94.703363 | 2.092668 | 326.727276 | 1043.984813 | b01-p-report | - Timing: 0.1451 s per seed in one process, 18.35 s wall with `Pool(10)` (b01-p-choose, macOS); 162.4 s wall with `Pool(8)`, about 0.47 CPU-s per seed (b01-p-report, Linux). - Both results print every per-seed edge to 6 decimals as a JSON block. Those 3,072 values are not copied here (they would not fit); they are in `artifacts/goal/batches/e1-gate-p/items/p-choose/result.md` and `…/p-report/result.md`. Spot values: 60000 → 486.160768, 61023 → 603.566722 (b01-p-choose); 10003 → 574.040699, 12047 → 411.369186 (b01-p-report). - Per-seed sd is about 92 to 95, so levels on different windows are not comparable; only paired differences are (b01-p-choose). - The choose window is also the window qm-spline chose its compression on (choose loss vs the full qm tables 0.0549, b01-p-choose citing qm-spline), so qt1's tables were selected on those seeds; final claims belong on the report window (b01-p-choose). - Replica levels are not board scores; Taylor's README says they do not convert (b01-p-choose). - Cross-platform: the 15 check values match to the printed digit on macOS arm64/3.9.6 and Linux/3.12.3. The 1,024 choose-window values were produced on macOS only; b01-p-choose advises reproducing the 3 reference values and a few window seeds before pairing against it, and section 10 reports what Linux recomputations found (17 to 19 seeds differ). **Source caveat.** The machines that re-read sources found 3 of b01-p-choose's sources and 1 of b01-p-report's did not hold (unreadable, or not saying what they were quoted for). Neither result's measured figures depend on a quoted page: Gate P, the hashes and the baselines are local runs. What rests on quoted sources there is provenance and context (the expected table, qm-spline's 0.0549 choose loss, the Python versions qm-spline and qt1 report, the README's "do not convert" statement); treat those as reported, not confirmed. b01-p-choose itself says its own check found all 18 quotes verbatim, which disagrees with the later re-read. **Trunk seed (b07-trunk-seed).** The goal repository was seeded, unchanged from upstream, with `reference/qt1/` (REPORT.md 62,223 B, Strategy.sol 42,990 B, blob.b64 13,692 B sha256 `83a69992…dd376`, blob.bin 10,167 B, qmref.py 7,739 B), `reference/taylor/` (README.md 10,483 B, calib_out_2048.json 2,948,144 B `fdf24c7a…08d26`, evalpol.py, gates.py 792 B, latt.py 8,893 B, pol_mid.json 780,061 B, real.py 9,586 B, replica2.py 7,503 B, trace.py 1,759 B `6300a33e…6f692`, track.py 3,890 B `69f49abd…ba486`), `tools/setup.sh` 2,045 B `2bac901b…c5a4b1`, `tools/README.md`, `README.md`, `.gitignore`. The full qm table (`qm_k1e-5.json`) is only under ignored scratch, not committed. The engine setup script was preserved, not executed; no engine seed was consumed. Later items fetch `qmref.py` and `blob.bin` from this repository ("K", `identity-md-launches/goal-3170-beat-network-s-amm-entry` at 31ff8ed1…; b11-combo-fees, b11-combo-offsets, b12-cuts-1). ## 2. Engine baseline of qt1 (b02-eb-a, b02-eb-b) - **b02-eb-a: BLOCKED**, nothing measured. `blocked={step: "setup: sh ../amm-sim/setup-fast.sh (platform check, before any download)", error: "BLOCKED platform Darwin arm64: the wheel is Linux x86_64 (exit 3)"}`. Seeds 9800000..9800127 were **not used** and remain fresh. No Rust toolchain on that machine. - **b02-eb-b: complete** on Linux x86_64. Setup passed (pyrevm 0.3.7, py-solc-x 2.1.0, solc 0.8.24; wheel sha256 `aedb6828…6887a` matched; instrumented `.so` sha256 `ff88b6353c2aad7342f0a26194f7347e78b9c3b38d683a7449006d423978cd14`; StarterStrategy validated). qt1 validated as `TaylorGaussianQMSpline`. | qt1 on the engine, seeds 9800128..9800255 (b02-eb-b) | value | |---|---| | mean edge | 513.5049728806645 | | se | 8.588810151732844 | | deployed runtime | 20,605 bytes (solc 0.8.24, optimizer 200 runs, viaIR, Paris) | | afterSwap calls / OOG / peak / mean gas | 1,371,375 / 0 / **209,112** / 138,190.16 | | afterSwap peak per 32-seed chunk | 208,981 / 204,494 / 209,112 / 208,981 | | afterInitialize calls / OOG / peak | 128 / 0 / 90,858 | Edges are `r.edges["submission"]`; configs are the `MatchRunner._build_configs` body with only the loop range changed; all revert / halt / bad-return counters were zero. Per-seed edges are in the item result (e.g. 9800128 → 575.0714848105139, 9800255 → 472.26735134111334). **Every qt1 engine measurement in this root** (qt1 alone vs VanillaStrategy; all 0 OutOfGas; 640 seeds in total): | seeds | n | afterSwap calls | peak | mean gas | mean edge | source | |---|---:|---:|---:|---:|---:|---| | 9800128..9800255 | 128 | 1,371,375 | 209,112 | 138,190.16 | 513.5049728806645 | b02-eb-b | | 9800256..9800287 | 32 | 341,010 | 206,830 | 138,283.12 | not stated | b06-gas-basis | | 9800288..9800319 | 32 | 349,704 | 206,311 | 137,967.46 | not stated | b06-gas-dispatch | | 9800448..9800575 | 128 | 1,411,141 | 208,928 | 137,877.65 | 535.869760405198 | b08-qtr2-spans | | 9800576..9800639 | 64 | 697,111 | 209,204 | ≈137,995 | not stated | b08-qtr2-loads | | 9800704..9800831 | 128 | 1,393,860 | 208,693 | 138,007.50 | 530.5619736124382 | b10-port-a | | 9800832..9800959 | 128 | 1,401,908 | 209,052 | 137,932.46 | 535.691840 | b10-port-b | **Disagreement with the brief, small:** the brief says qt1 peaks at 208,775; the measured peak ranges from 206,311 to 209,204 depending on the seeds (always under 245,000). Mean edge per 128 seeds ranges from 513.5 to 535.9, which is why only paired differences are used. **Blocked items elsewhere, same cause or setup.** b10-port-c: `blocked={step: platform, error: required Linux x86_64; this workspace reports Darwin arm64}`; no port, gate, gas probe or engine run. b08-qtr2-control: `blocked={step: "sh scratch/setup.sh: initial mkdir", error: "mkdir: /Users/…/Library/Application: Operation not permitted"}`: the setup script's unquoted `$R` split on a workspace path containing spaces (the host was also Darwin arm64). It verified neither Solidity hash, ran 0 Gate F callbacks and consumed none of engine seeds 9800320..9800447 for any arm (qt1, qtr2, candidate). It claims nothing. ## 3. Gate F on unchanged qt1 (b03-gf-a, b03-gf-b) Both ran on Linux x86_64 (Python 3.12.3, pyrevm 0.3.7, py-solc-x 2.1.0, solc 0.8.24; `.so` sha256 `ff88b635…8cd14`), both re-ran Gate P and the three reference values first (all matched), and both measured qt1's deployed runtime at **20,605 bytes**. Each seed drives the full `replica2.run` through `QMRef`, records init fees and the first 2,000 own-pool callbacks, and replays them on a fresh pyrevm deployment initialised at 100e18 / 10000e18 with 245,000 gas per call; amounts are `int(float * 1e18)`. Gas is `evm.result.gas_used` (pyrevm), **not** engine `gas_stats()`. | qt1 Gate F | seeds | runs × callbacks | max abs diff (bps) | mean abs diff (bps) | init diff | pyrevm peak | pyrevm mean | reverts / OOG | source | |---|---|---|---:|---:|---:|---:|---:|---|---| | reproduction of Q's published set | 70000..70049 | 50 × 2,000 | 5.82591715267e-06 (seed 70031) | per-run 1.5e-07 to 1.9e-07 | 0 | 194,051 (seed 70032) | 124,777 | 0 / 0 | b03-gf-a | | same set, second machine | 70000..70049 | 50 × 2,000 | 5.82591715267335e-06 (seed 70031) | not stated | not stated | 194,051 (seed 70032) | 124,776.889520 | 0 / 0 | b03-gf-b | | new set | 70050..70099 | 50 × 2,000 | 6.713282269497911e-06 (seed 70091) | 1.6990309059933327e-07 | 0.0 | 193,983 (seed 70057) | 124,961.8586 | 0 / 0 | b03-gf-b | - **Gate F: PASS for qt1** on 100 distinct replica runs; the worst fee difference is about 1,500 to 1,700 times smaller than the 0.01 bps limit. Both results say this reproduces Q's published Gate F (5.83e-6 bps, peak 194,051 at seed 70032, mean 124,777 / 124,776.9). `afterInitialize` cost 90,858 gas on every run (both). - Seed 70032 alone agrees across the two: peak 194,051, max diff 1.44775174488e-06 bps, mean gas 123,644.6815. - **Finding both hit independently: `QMRef` returns uncapped fees.** `QMRef` caps its stored `self.fb/self.fa` but returns the local values before the cap; `replica2.clampf` then caps every fee to `[0, 0.1]` before the pool uses it, and qt1's contract returns the capped value. Comparing raw returns gives a spurious failure: seed 70026, callback 1702 (timestamp 1568), raw bid 0.12000793358465078 vs contract 0.1, a 200.08 bps "error" (b03-gf-a); seed 70092, callback 853 (timestamp 860), raw ask 0.12130300605309263 vs 0.1, 213.03 bps (b03-gf-b; exactly one clipped callback in its 50 runs). Both repaired the *harness* (record the effective capped fee, forward raw fees to the replica) and re-ran all seeds; contract and reference were not edited. **Gate F as passed is equality to the fees the replica uses, cap included; literal equality to raw `QMRef` returns fails.** Any later harness must clamp the same way. - Each result embeds its complete harness `scratch/check.py` and per-run tables for its seeds (b03-gf-b also a digest over its 50 trace hashes, `14857c58…a4def8`). - **Source caveat:** 1 of b03-gf-b's sources did not hold on re-read. Its measurements are local; what it takes from sources is the published baseline it says it reproduces and the pinned compiler/interface/executor settings. b03-gf-a states the same published baseline (5.83e-6 / 194,051 / 124,777) from Q, so the two agree on what Q says. - Neither ran an engine batch; no engine seeds used. ## 4. Lead 1 screens: quoting the two-part posterior at a step's first trade (b04-mix-wavg-offsets, b04-mix-wavg-fees, b04-mix-max-fee) All three are **replica-only Python screens** on choose seeds 60000..60511 (n = 512, each policy once per seed), paired against qt1-ref (`mean_edge_base` 529.2759060654904 in all three). The changed path is a step's first own trade with `0.005 < pi < 0.995`; the filter and carried state follow qt1. No constants were tuned. None has a report-window score, a Solidity port, Gate F, or engine/gas figures. Each result embeds its complete `mix.py`. | variant | what the first-trade quote is | mean_diff vs qt1-ref | se | worst5 (seed, diff) | mean edge variant | new-path calls / run | lookups on that path | |---|---|---:|---:|---|---:|---:|---| | wavg-offsets (b04-mix-wavg-offsets) | pi-weighted average of arb offsets (phase 0, sd 0, band-clipped rival) and retail offsets (phase 1, `sqrt(vt)`, retail-updated rival), then qt1's fee conversion against the carried posterior mean | **+0.27726260379404943** | 0.021458729540657563 | 60496 −1.8159; 60210 −1.3577; 60128 −1.3037; 60144 −1.1197; 60199 −1.0858 | 529.5531686692844 | 5,824.65 | 2 offset-pair lookups (4 surface reads) | | wavg-fees (b04-mix-wavg-fees) | each branch converted to fees through the unchanged `lookup`, then `pi*fee_arb + (1−pi)*fee_ret` per side | **+0.27820510575416324** | 0.021560114887340238 | 60496 −1.8162; 60210 −1.3557; 60128 −1.3042; 60144 −1.1197; 60199 −1.0911 | 529.5541111712446 | 5,824.80 | 2 paired (4 scalar sides); 1 paired elsewhere | | max-fee (b04-mix-max-fee) | the larger bid fee and larger ask fee of the two branches; pi gates, does not weight | **−4.631679601960211** | 0.055831942178207826 | 60250 −8.6080; 60329 −7.7154; 60091 −7.6536; 60157 −7.6487; 60464 −7.5611 | 524.6442264635302 | 5,442.45 | 2 paired (4 sides) | - **wavg-offsets and wavg-fees are the same result within noise** (+0.2773 vs +0.2782, se 0.0215 each, same five worst seeds): averaging offsets or averaging fees does not matter on this window. **max-fee loses 4.63 and is rejected** by its own result ("do not promote"). - **Against the brief's lead:** the brief quotes +0.49 for whole-posterior quoting "over Gaussian + plain" on Taylor's replica. These screens measure +0.28 over qt1-ref (Gaussian + qm-spline tables), a different base, so the two numbers are not directly comparable; no result here reproduces the +0.49. - Roughly 5,800 callbacks per 10,000-step run take the two-lookup path (b04-mix-wavg-offsets, b04-mix-wavg-fees), i.e. most first trades; this is what drives the gas question in section 10. - Checks each ran: Gate P reproduced (wavg-fees and max-fee print/state it; wavg-offsets ran the copied `gates.py` and quotes its Gaussian+qm column 443.522608 / 571.623551 / 525.865859); hashes of Strategy.sol and blob matched; qt1-ref gave 443.1017411146794 / 571.454483381923 / 525.908441161234 on seeds 10000..10002 (all three; b01-p-choose prints 443.1017411146671 / 571.4544833819275 / 525.9084411612362 on macOS, a difference in the 11th decimal and beyond, the libm last-digit effect b01-p-choose warned of; equal to 6 dp). - Same-input callback checks: wavg-fees, 31,521 callbacks incl. 17,015 mixture callbacks on three baseline trajectories (seeds 10000..10002), state update equal to qt1's from the same incoming state and unchanged-path fees identical; max-fee, 8,215 callbacks incl. 5,021 new-path calls on seed 70000; wavg-offsets, 1,000 random unchanged-path fee lookups equal to qt1. - **Source caveat:** 2 of b04-mix-wavg-offsets' sources did not hold on re-read. Its screen figures are local measurements; its description of what the two components and rival updates are leans on Taylor's README and Q. b04-mix-wavg-fees and b04-mix-max-fee describe the same design from the same pages and were not flagged, and wavg-fees reproduces the number independently, so the +0.277 finding does not rest on the flagged sources. ## 5. Lead 2 screens: a cheaper lattice filter (b05-latt-c5, b05-latt-two-comp) Both are replica-only Python references screened on 60000..60511 (n = 512) against qt1-ref (`mean_edge_base` 529.275906); both re-ran Gate P, the qt1-ref values and the two hashes first (all matched). No Solidity, no Gate F, no engine in either item. Gas figures in this section are **estimates from counting rules, not EVM measurements**. ### 5a. latt-c5: Taylor's `latt.py` at 61 cells of 5 bps (b05-latt-c5) Change against `latt.py`: cell width 2.5 bps → 5 bps, 121 → 61 cells (same ±150 bps window), kernel 33 → 17 taps; everything else line for line, except the recentre trigger kept at the physical 100 bps (literal `40*HC` would be 200 bps and never fire; the two versions differ by +0.0041, se 0.0023). A full-window diffusion is 965 multiply-adds instead of 3,721. | policy, seeds 60000..60511, n = 512 | minus qt1-ref | se | note | |---|---:|---:|---| | latt-c5, full `qm_k1e-5.json` tables (the variant) | **+0.578835** | 0.024537 | ahead on 440 of 512 seeds; mean edge 529.854741; worst5 60446 −1.019152, 60205 −0.972253, 60053 −0.760694, 60202 −0.718922, 60183 −0.712195 | | latt-c5 filter, decoded qm-spline tables | **+0.5218** | 0.0254 | what a contract holding qt1's tables would get: the like-for-like figure | | Taylor's Gaussian filter (`real.py`, soft=1), full qm tables | +0.0744 | 0.0150 | the table effect alone | | unmodified `latt.py`, full qm tables | +0.5939 | 0.0251 | exact lattice; mean edge 529.8698 | - latt-c5 minus exact lattice: −0.0151 (se 0.0106, n = 512); on the first 128 seeds −0.015777 (se 0.021515). **The coarser grid costs nothing measurable.** Filter quality: misclassification 16.26% vs 16.21% exact; price rms error 13.67 vs 13.64 bps. - Lattice c5 over Gaussian with the same full tables: +0.5045 (se 0.0233), which matches the brief's +0.49 for lattice + qm over Gaussian + qm. Full over spline tables under the c5 filter: +0.0571 (se 0.0129); b05-latt-c5 quotes qm-spline's own reported holdout loss as 0.0632 (se 0.0072, n = 2048). - Split halves: +0.5618 (se 0.0357) and +0.5958 (se 0.0337). - Port check values, latt-c5 with full qm tables on replica seeds 10000 / 10001 / 10002: **443.890699 / 571.689889 / 526.388880**. - **It does not fit the gas limit as specified.** Rule: est_gas = 5,000 × state_words + 40 × (mul + div) + 2,000 × explog + 42,500 × lookups, with 11 state words assumed (8 words of 61 × 32-bit cells + 3 scalar words). Fixed part on a first trade is 164,000, leaving about 81,000 gas (≈2,025 mul/div) for the lattice. | latt-c5, 512 seeds, 5,530,283 callbacks | cells | mul | div | explog | est_gas | |---|---:|---:|---:|---:|---:| | mean per callback | 113.2 | 343.8 | 40.5 | 9.51 | 174,402 | | mean, first trade of a step (64.5% of callbacks) | | | | 12 | 187,706 | | largest seen (31 diffusions) | 4,049 | 21,032 | 1,435 | 12 | 1,062,680 | | analytic worst case | 6,104 | 34,454 | 1,941 | 12 | 1,619,800 | 29,373 callbacks (0.531%) are over 245,000, in 512 of 512 runs. The same rule on unmodified `latt.py` (19 words): mean 243,130, first-trade mean 272,265, largest seen 3,329,280, analytic worst 5,326,840, 62.4% of callbacks over 245,000. - **The cost is the silent-step loop (up to 30 diffuse + cut + renormalise passes), not the resolution.** Side measurement, same 512 seeds, cap K on that loop (not the variant; no cap was selected, none run on the holdout): | cap K | minus qt1-ref (se) | minus c5 (se) | largest est_gas seen | analytic worst | callbacks over 245,000 | |---:|---:|---:|---:|---:|---:| | 0 | −1.0291 (0.0421) | −1.6079 (0.0401) | 203,040 | 238,600 | 0 | | 1 | +0.4283 (0.0278) | −0.1505 (0.0196) | 229,200 | 284,640 | 0 | | 2 | +0.5252 (0.0262) | −0.0536 (0.0139) | 254,680 | 330,680 | 1,143 | | 3 | +0.5643 (0.0255) | −0.0145 (0.0100) | 283,840 | 376,720 | 8,690 | | 4 | +0.5760 (0.0251) | −0.0029 (0.0078) | 313,560 | 422,760 | 15,236 | | 6 | +0.5813 (0.0245) | +0.0025 (0.0035) | 373,720 | 514,840 | 28,740 | | 8 | +0.5800 (0.0244) | +0.0011 (0.0023) | 429,320 | 606,920 | 29,403 | | 12 | +0.5823 (0.0245) | +0.0035 (0.0012) | 542,120 | 791,080 | 29,378 | | 30 (c5) | +0.5788 (0.0245) | 0 | 1,062,680 | 1,619,800 | 29,373 | The first silent step carries most of the value; from cap 4 up the loss is inside noise. Under this rule only cap 0 fits in the worst case and it is worse than qt1; cap 1 stays under 245,000 on every callback seen but not analytically. Cheaper lookups or a cheaper per-step update would be needed for cap 2 to 4. - **Disagreement / unreconciled:** the brief says the exact lattice costs 453k gas a call. b05-latt-c5's rule gives the exact lattice a mean of 243,130 and could not reconcile it with 453k ("if it is a mean, this rule is low by roughly a factor of 1.9"); the author expects a Solidity inner loop to cost several times 40 gas per tap, so its estimates are more likely low than high. - Other limits it states: the 32-bit cell packing is assumed and cannot represent the float reference's 1e-12 threshold, so a contract would need its own fixed-point reference, screened again, before Gate F means anything; seeds 60512..61023 and the holdout 10003..12047 were not touched. ### 5b. two-comp-bounded: no lattice, two carried Gaussian components (b05-latt-two-comp) Design: the first own trade of a step leaves an arb point mass `(pi, lp, 0)` and a retail truncated Gaussian `(1−pi, mt, vt)`; the branches stay separate through later callbacks; at the next step's first callback each gets diffusion and up to two separate silent-step no-arb cuts, remaining silent cuts use the moment-matched Gaussian. Quoted through the mixture mean and sd. qt1's fee rule, QMS1 decoder, `.005/.995` thresholds and table constants unchanged. Proposed state: four 32-byte words `(lp, pi)`, `(mt, vt)`, `(sp, s2h)`, `(fb, fa, t, cnt, synced)` (an estimate; nothing built in this item). | window | n | mean_diff vs qt1-ref | se | mean edge variant / base | source | |---|---:|---:|---:|---|---| | choose 60000..60511 | 512 | **+0.456732859** | 0.023685742 | 529.732638925 / 529.275906065 | b05-latt-two-comp; worst5 60446 −1.049882126, 60326 −0.957574283, 60143 −0.884081568, 60139 −0.781208072, 60036 −0.775975247 | | report 10000..12047 | 2048 | **+0.424802883** | 0.012201544 | 533.687633550 / 533.262830667 | b05-latt-two-comp | - The report-window base mean 533.262830667 equals b01-p-report's 533.262831: an independent agreement on the qt1-ref report baseline. - Versus the exact lattice (first 128 seeds): −0.170538338 (se 0.038321724); that comparison is variant on compressed QMS1 tables minus exact lattice on full tables, so it mixes filter and table differences. - Cost estimate (unmeasured): worst modeled callback = 12 silent steps, 15 Gaussian truncations, about 800 mul, 285 div, 35 exp + 7 ln, 2 spline lookups, 4 state words → **239,000 gas** at 1,800 gas per exp/ln; at 3,000 per exp/ln the same rule gives about 289,400. The result says itself that 239,000 "does not establish the 245,000 gas gate". Section 9 shows what the port actually cost. - A late underflow-fallback edit was re-verified on all 2,560 variant scores (equal within 1e-9). - **This is the policy ("TC") that sections 9 to 11 port, extend and vary.** ## 6. Gas headroom in qt1's spline code, first round (b06-gas-basis, b06-gas-dispatch) Both are **lossless, gas-only edits of qt1** (no new policy, so no Gate Q), both on Linux with the pinned setup (`.so` sha256 `ff88b635…8cd14`), both re-ran Gate P (pass), both targeted a 40,000-gas peak reduction, and **neither met it**. Each ran a fresh, disjoint 32-seed engine chunk with qt1 and the fast contract once each; all per-seed edges are exactly equal (paired mean_diff 0.0, se 0.0). | | b06-gas-basis ("Qt1Fast", basis) | b06-gas-dispatch ("Qt1Fast", dispatch) | |---|---|---| | edit | 5 cumulative edits to the spline basis: shared Bernstein weights, cached knots/denominators, unrolled sd stripes, scalar accumulators, adjacent-pair basis evaluation | only `cw0..cw19`/`cw`: profile-weighted binary decision tree over the 306 packed coefficient words, 32 sub-functions of ≤16 leaves | | engine seeds | 9800256..9800287 (n = 32) | 9800288..9800319 (n = 32) | | afterSwap calls (each contract) | 341,010 | 349,704 | | qt1 peak / mean | 206,830 / 138,283.1232808422 | 206,311 / 137,967.4611614394 | | fast peak / mean | **196,323** / 126,785.55937655787 | **206,076** / 137,471.14977809804 | | peak saved / mean saved | **10,507** / 11,497.563904 | **235** / 496.31138334135176 | | OOG / other callback errors | 0 / 0 | 0 / 0 | | runtime bytes qt1 → fast | 20,605 → 21,653 (+1,048) | 20,605 → 20,772 (+167) | | afterInitialize peak qt1 / fast | 90,858 / 90,931 | 90,858 / 90,858 | | fast source sha256 | `0f1275e59f70daed05931b0c54ac5b09f08e11de19fccdda2ffa257a816c712f` | `164c979f77c702b8654b09af413e78de0bd6cec6b8834cb8612646c4cf1a00e5` | | Gate F | seeds 70000..70049, 100,000 callbacks: returns byte-identical to qt1, max error vs Python 5.825917152673353e-06 bps; extra seeds 70100..70149: byte-identical, max 9.55308224886986e-06 bps | replica seeds **0..49**, 5,000 steps each, first 2,000 callbacks: every returned fee pair identical to qt1, max error 4.5730487712586365e-06 bps | | equivalence audit | `baspair` vs original `bas` on all 1,804 adjacent grid pairs (3,608 evaluations, 5 tables, both axes): bit-identical | all 306 dispatch indices return identical 256-bit words; source outside the dispatch region identical | | delivered as | unified diff against Q's Strategy.sol (in the item result) | complete contract (in the item result) | - **b06-gas-basis per-edit attribution** (fixed 2,000-callback pyrevm trace of replica seed 70000; cumulative builds; runtime bytes / peak / mean): Qt1 20,605 / 177,859 / 126,675.5545; +shared weights 20,627 / 176,895 / 125,675.0620; +cached knots 20,633 / 177,039 / 125,820.7510; **+unrolled stripes 21,022 / 167,670 / 118,237.5170** (the big one: 9,369 peak, 7,583 mean); +scalar accumulators 21,065 / 166,832 / 117,446.2730; +adjacent-pair basis (final) 21,653 / 167,285 / 115,221.0570 (mean −2,225 but peak +453 on this trace). - **b06-gas-dispatch rejected variants** (one 1,976-callback replica trace, peak / mean; qt1 170,712 / 125,543.822368): ternary dispatch 170,337 / 125,481.202429; shared 306-word cache 179,891 / 133,112.156377 (worse); weighted original groups 169,628 / 125,093.240891; table-selected function pointers 175,036 / 129,288.420547 (worse); rolling four-word cache 192,580 / 143,746.503036 (worse); selected global tree 169,441 / 125,011.828947. Row packing raised a synthetic peak from 143,497 to 159,514 and was rejected. Its reading: fewer fetches did not offset the added compiled overhead in these implementations; a better cache design is not ruled out. - Both observe that qt1's peak on their sample (206,830; 206,311) differs from the brief's 208,775, which was on a different seed set; savings must be read against the paired baseline (table in section 2). - b06-gas-basis notes qt1's shipped code already uses binary search for the span although Q's notes describe that as future work. - b06-gas-basis hit the uncapped-`QMRef` return (seed 70026, callback 1702, raw 0.12000793358465078 vs contract 0.1) and fixed its test by passing expected fees through `replica2.clampf`: the same finding as section 3. b06-gas-dispatch does not mention it and does not say whether its comparison clamps; on its seeds 0..49 the maximum was 4.57e-06 bps either way. - **Departure from the brief's Gate F wording:** b06-gas-dispatch's Gate F used replica seeds 0..49 at 5,000 steps (2,000 steps did not yield 2,000 callbacks on seed 3), not the 70000-range seeds at the default 10,000 steps the other items used. It is still 50 × 2,000 callbacks from replica runs. - The two edits touch different code (basis arithmetic vs coefficient dispatch) and were not combined in either item. Whether the savings add (about 10.7k) is not measured here. - Setup note: b02-eb-b, b03-gf-a, b03-gf-b, both b06 items, b10-port-a and b10-port-b ran Taylor's `sh ../amm-sim/setup-fast.sh`; b04-mix-wavg-offsets, b05-latt-two-comp, b08-qtr2-spans and b08-qtr2-loads ran the brief's `scratch/setup.sh` (b08-qtr2-control failed on it). Both routes report the same wheel sha256 `aedb6828…6887a` (b02-eb-b; b08-qtr2-loads). ## 7. qtr2, a lower-gas qt1, and second-round gas work (b08-qtr2-control, b08-qtr2-spans, b08-qtr2-loads) These items start from **qtr2 ("R")**, the Solidity block of `https://api.imdnotdead.fun/artifacts/18ca35cb47390b8e8c289b240d7836804692998ad64f84ef248c43d61e199f0b`, source sha256 `7b99afae570ef1627b0163fb21411f14c496b005a07c3966cc7323906dee664f`. **None of the 25 results in this root is the item that produced qtr2**, and none describes its edits; what follows is how qtr2 measured when the e2 items compared it with qt1. The control item meant to audit it (b08-qtr2-control) was blocked at setup and verified nothing (section 2). | arm | source sha256 | runtime bytes | runtime sha256 | source | |---|---|---:|---|---| | qt1 | `c68887cf…08aca` | 20,605 | `79c8d6c3…c70189` | b08-qtr2-spans, b08-qtr2-loads (identical) | | qtr2 | `7b99afae…e664f` | 19,945 | `70158215…a4663b` | b08-qtr2-spans, b08-qtr2-loads (identical) | | qtr2-spans candidate | `bbf63364ed407fc3a94ec3b4cc02223b6855b1b9c083e6e7a7566a2ba70e24b5` | 19,965 | `33ebe81f…1e3a44` | b08-qtr2-spans | **Engine, each arm alone vs the 30 bps VanillaStrategy (two disjoint fresh seed sets):** | seeds | arm | n | afterSwap calls | peak | mean gas | OOG | paired vs qt1: mean_diff (se) | source | |---|---|---:|---:|---:|---:|---:|---|---| | 9800448..9800575 | qt1 | 128 | 1,411,141 | 208,928 | 137,877.649482 | 0 | — (mean edge 535.869760405198) | b08-qtr2-spans | | 9800448..9800575 | qtr2 | 128 | 1,411,142 | 191,821 | 127,181.894068 | 0 | +7.511789012415448e-05 (9.250347746245123e-05) | b08-qtr2-spans | | 9800448..9800575 | spans candidate | 128 | 1,411,142 | **189,174** | 125,346.709314 | 0 | same as qtr2; candidate − qtr2 = 0 exactly | b08-qtr2-spans | | 9800576..9800639 | qt1 | 64 | 697,111 | 209,204 | sum 96,198,028,898 (≈137,995) | 0 | — | b08-qtr2-loads | | 9800576..9800639 | qtr2 (= loads "candidate") | 64 | 697,111 | 191,126 | sum 88,733,214,265 (≈127,287) | 0 | −4.924018526253349e-09 (3.809185031344612e-09) | b08-qtr2-loads | (Call counts for the 128-seed set are sums of the four raw `gas_stats()` chunk records in b08-qtr2-spans; the two per-call means for the 64-seed set are sum/calls computed in this merge.) - **qtr2 saves about 17,100 to 18,100 peak gas and about 10,700 mean gas against qt1**, at 660 fewer runtime bytes, on two independent seed sets. `afterInitialize` rises 90,858 → 92,008. - **qtr2 is not edge-identical to qt1.** Differences are tiny: worst5 on 9800448..9800575 are 9800575 −0.006326762812193465, 9800523 −7.66e-08, then ~−2e-10; on 9800576..9800639 the worst is 9800588 −2.29e-07. On the first set qtr2 makes one more submission afterSwap call than qt1 in one chunk (355,914 vs 355,913), so trajectories diverge slightly. This differs from the b06 edits (section 6), which were bit-identical to qt1. Its Gate F max error is 5.8261143826e-06 bps vs qt1's 5.8259171527e-06, so it rounds differently somewhere but stays far inside 0.01 bps. - **b08-qtr2-spans (complete):** replaces the two linear span scans with upper-bound binary searches; span equivalence checked on 2,172 cases (all reachable integer positions plus each interior knot ±1, 5 tables); candidate/qtr2 outputs byte-identical on all 100,000 Gate F callbacks (aggregate digest `18198a0a…070f38` for both) and all 128 engine seeds. **Saves a further 2,647 peak (191,821 → 189,174) and about 1,835 mean** for +20 bytes. Gate F (applied fees), seeds 70000..70049, 50 × 2,000, pyrevm peak / mean: qt1 194,051 / 124,776.88952; qtr2 173,599 / 109,292.64352; candidate 171,050 / 107,433.95890; max error 5.825917152673353e-06 (qt1) and 5.8261143826010553e-06 (qtr2 = candidate). Delivered as an exact diff against R plus `prepare.py`. - **b08-qtr2-loads (negative result, partial):** patch against R is **empty**; no tested table-loading change reduced gas. Rejected on a 2,000-callback trace of seed 70000 (sum gas / peak; R baseline 221,856,196 / 161,288, runtime 19,945): bulk bytes with pointer alias 223,436,375 / 162,284 (and the validator rejects inline assembly); cached packed-word lanes 223,696,776 / 162,392; bulk bytes with `abi.decode` 245,109,222 / 173,100; lazy upper Bernstein basis 221,896,816 / 161,315. Its engine run covers only 64 of the 128 assigned seeds; **9800640..9800703 were not executed**. - **Disagreement on what counts as Gate F.** b08-qtr2-loads compared raw `QMRef` returns as literally asked, hit the uncapped return at seed 70026 callback 1702 (200.07933584650777 bps), stopped, and reports **Gate F FAILED / not claimed** with 46 of 50 seeds recorded (92,000 callbacks per arm; max recorded error q 5.82591715267335e-06, r 5.82611438260106e-06; replay peaks 194,051 and 173,599). b08-qtr2-spans ran the same seeds with applied (clamped) fees, **passes 50 × 2,000 for all three arms**, and states separately that literal raw equality fails for pinned qt1 too. b03-gf-a, b03-gf-b, b06-gas-basis all take the applied-fee reading. The two b08 results agree on every number they share (hashes, runtime sizes, per-arm maxima, peaks); they differ only in the label. This merge follows the majority reading but the write-up should say that "F passes" always means "against fees after `replica2.clampf`". - **Source caveat:** 2 of b08-qtr2-spans' sources did not hold on re-read. Its numbers are local measurements with raw `gas_stats()` records embedded; b08-qtr2-loads independently reproduces the hashes, runtime sizes and the qtr2 replay figures, so the qtr2 findings do not depend on the flagged sources. What qtr2 *is* (its provenance in artifact 18ca35cb…) is only as good as that link, which no result here describes further. ## 8. Classifier corrections to the first-trade posterior (b09-class-size, b09-class-age) Both add a small correction to the arb-vs-retail log odds on a step's first own trade, replica-only, no Solidity/engine/Gate F. **Neither shows an improvement.** | | b09-class-size | b09-class-age | |---|---|---| | status | **incomplete Gate Q** (64 of 3,072 paired differences) | Gate P/Q **complete** | | correction | `0.05*z + 0.02*(±1 by side)`, `z = clamp(ln(size_Y/20), −3, 3)`; parameters fixed, not fitted | `delta = clip(w·features, −2, 2)` with 5 features (1; pin-age `a/(a+4)`, `a = min(32, t − last_pin_t)`; fills since pin /8; same-side-as-previous ±1; fills at last active timestamp /4), offset-logistic fit on 60000..60511 (3,453,008 observations, ridge 100), strength chosen on 60512..61023 | | base | Taylor's `real.RealPolicy` with `qm_k1e-5.json` (full tables), **not qt1-ref** | qt1's `QMRef` (spline tables) | | choose | 60000..60031, n = 32: mean_diff **+0.0403682899**, se 0.0496370852; worst5 −0.6987, −0.3248, −0.3196, −0.2987, −0.2421; baseline 540.2884986808 | 60000..61023, n = 1024: **+0.003095975025**, se 0.010736473898; baseline 529.971156871193 | | report | 10000..10031, n = 32: **+0.0585722916**, se 0.0514426088; worst5 −0.4646, −0.4401, −0.3449, −0.3187, −0.3054; baseline 507.4178374219 | 10000..12047, n = 2048: **+0.008372651609**, se 0.007169143289; 95% interval [−0.005678869, +0.022424172]; baseline 533.262830666503, candidate 533.271203318112 | | classifier error on first trades | 17.3964% (choose shard), 17.6517% (report shard) | report: qmref 0.173073117 → candidate 0.172554673; Brier 0.119689619 → 0.119494796; log loss 0.388407662 → 0.389458106 (worse) | | verdict by its own author | "explicitly not Gate Q"; the full fit window did not finish in the execution budget | "does not establish an improvement over qt1; do not advance it" | - b09-class-age selection table (60512..61023, n = 512, baseline 530.666407676895): strength 0.25 → −0.001847756380 (se 0.011373650959); **0.5 → +0.010678384235 (se 0.015224212108), selected**; 1.0 → +0.009079693632 (se 0.017619097898). Selected weights `(-0.1375399840090357, 0.2301698288359973, -0.0123197046716916, -0.03605200312165081, 0.06757326693328426)`; frozen before the report runs; candidate sha256 `e240faf2…309d45`. Worst5 report: 10519 −1.6665, 11929 −1.5075, 11503 −1.3870, 11652 −1.1641, 11186 −1.1032; choose: 60036 −1.4709, 60321 −1.0546, 60446 −1.0308, 60066 −0.9731, 60004 −0.9427. - b09-class-age's pin-age diagnostic (report, candidate path) is a finding in itself: first trades 0..3 steps after a pin are 87.2% arb with 4.5% classification error; at age 16..32 (saturated; 10,705,905 of about 14.36M calls) they are 50.6% arb with 19.0% error. Most first trades happen in the hard regime, and a five-feature logistic correction moves error only from 17.31% to 17.26%. - b09-class-age's baselines agree with section 1: choose 529.971156871193 vs b01-p-choose's 529.971160 (differs in the 6th decimal: b01-p-choose ran on macOS/3.9.6, this on Linux/3.12.3; section 10 shows 17 to 19 choose seeds differ between those platforms), report 533.262830666503 vs b01-p-report's 533.262831. - b09-class-age port estimate (unmeasured): 41 extra state bits, at worst one new storage slot; one exp and a handful of multiplies on first trades; no extra lookup. - b09-class-age embeds a self-contained lzma/base64 bundle (sha256 `1ed07856…5e26c3`) with candidate, runner, qmref, replica and blob, and all 3,072 paired differences (sha256 of the float64 bytes `a09b35a1…28d3a0`); b09-class-size embeds its 64 differences (sha256 `f306a2da…6dcf56`). - **Source caveat:** 1 of b09-class-age's sources did not hold on re-read. Its figures are local runs; sources are used for provenance of T, Q and B only. - The two are not comparable head to head. b09-class-size's baseline mean on 10000..10031 is 507.4178374219, while qt1-ref's mean on those 32 seeds is 507.337177 (computed in this merge from b01-p-report's per-seed edges), so it paired against Gaussian + full qm tables rather than qt1's reference as Gate Q asks; and with n = 32 its se (0.05) is as large as the effect. ## 9. TwoComp ported to Solidity on qtr2: the first candidate that beats qt1 on the engine inside the limits (b10-port-a, b10-port-b, b10-port-c) Reference: the unchanged `TwoComp` (`DUAL_CUTS=2`) from "TC", artifact `d3c849db2ac31e567b57e52b80b86e8c24c842e5b4125b9d75c78e3cb07115b9`. That id equals the SHA-256 of the b05-latt-two-comp result handed to this merge, so TC is section 5b's policy. Base contract: qtr2 (R, section 7). The diff context in both ports shows R's own header: "Gas trim: scalar node sums, shared mirrored knot geometry, and four packed state words", contract name `TaylorGaussianQmTrim2`; both candidates are named `TaylorTwoCompQmTrim2`. Both ports change only the filter state and `update()`; tables, spline evaluation, rounding and fee conversion are R's; the quote is still one lookup on the mixture mean and sd; no assembly; both pass `amm-match validate`. **b10-port-c is blocked (Darwin arm64) and contributes nothing.** | | b10-port-a | b10-port-b | |---|---|---| | candidate source sha256 | `b87234c89e094f4955578417c1266129b0f96e6dfda68e3fb8866e00eeda71a2` | `d5e8b79423dc5c59f36559b674890f701f1a2dc8e69e2447e4d5dda702dadb5e` | | deployed runtime | **21,102 B** | **21,197 B** | | state | four words (point/weight; retail mean/variance; own/rival spot; fees + timestamp + 63-bit count + sync bit) | R's words plus `slots[4] = (lp, pi)`, `slots[5] = (mt, vt)`, two-component flag at bit 254 of `slots[3]`; both extra slots pre-written to 1 in `afterInitialize` | | Gate P | pass | pass | | Gate Q (replica, its own run) | choose 60000..61023 n = 1024: +0.4454237154410953, se 0.017637356353635045; report 10000..12047 n = 2048: **+0.42480288330208926, se 0.012201543529995695** (candidate mean 533.6876335498051, qt1 533.2628306665031); worst5 report 10146 −2.7519, 11701 −2.4266, 11062 −1.6807, 11949 −1.2202, 10394 −1.2018 | not run; cites TC's +0.4248 ± 0.0122 | | gas probe (pyrevm; seeds 70000..70009 full runs, 107,708 callbacks; 13 arrive with dt ≥ 13 and two components) | max of the 13: **177,611** (seed 70008, callback 6719) | max of the 13: **177,987** (seed 70008, callback 6719); all callbacks: peak 178,304 (seed 70002, cb 3442), mean 113,960.4 | | Gate F (effective fees; TwoComp-driven; seeds 70000..70049; 50 × 2,000) | **PASS**: max 6.304438181356162e-06 bps (seed 70021, cb 1192), mean 2.614892262531543e-07, init diff 0.0, pyrevm peak 178,312, mean 113,987.35353, 0 reverts, 0 OOG | **PASS**: max 6.304e-06 bps (seed 70021, cb 1192), mean 2.615e-07, init diff 0.0, pyrevm peak 178,766 (seed 70016, cb 899), mean 114,143.9, 0 / 0 | | engine seeds (each arm once, 4 chunks of 32) | 9800704..9800831 | 9800832..9800959 | | **paired vs qt1** | n = 128, **mean_diff +0.41446981868157895, se 0.04226126717170993**; worst5 9800815 −1.0685, 9800805 −0.7102, 9800777 −0.4350, 9800744 −0.4200, 9800760 −0.4001 | n = 128, **mean_diff +0.43850144, se 0.045223791**; worst5 9800906 −0.906648254, 9800861 −0.657203207, 9800840 −0.562222775, 9800844 −0.391086203, 9800889 −0.381883923 | | mean edge candidate / qt1 | 530.9764434311198 / 530.5619736124382 | 536.130342 / 535.691840 | | **candidate afterSwap** calls / peak / mean / OOG | 1,386,246 / **201,916** / 131,111.13028712076 / 0 | 1,394,458 / **213,439** / 137,449.28 / 0 | | qt1 afterSwap calls / peak / mean / OOG (same seeds) | 1,393,860 / 208,693 / 138,007.5024758584 / 0 | 1,401,908 / 209,052 / 137,932.46 / 0 | | afterInitialize (candidate) | 92,165 | not stated | | delivered as | unified diff against R (`patch -p1`), checked by re-applying to a fresh extraction | unified diff against R; `patch` not installed, checked with `git apply -p0` (sha matched) | - **Both ports meet every stated limit:** runtime ≤ 24,576, engine afterSwap peak ≤ 245,000, 0 OutOfGas, Gate F within 0.01 bps (effective-fee reading). Both show about **+0.41 to +0.44 edge over qt1 on 128 fresh engine seeds each**, roughly 10 se, and the engine figure agrees with the replica's +0.4248 (se 0.0122) for the same reference. - **Combined (computed in this merge, not by either item):** the two samples use disjoint seeds and two contracts that implement the same reference; inverse-variance pooling gives about +0.426 (se about 0.031), n = 256. - **Where the two disagree: gas.** Same reference, same base, but port-a peaks at 201,916 and averages 131,111 while port-b peaks at 213,439 and averages 137,449: port-a is 11,523 lower at the peak and about 6,338 lower on the mean, and 95 bytes smaller. Port-a is *below* qt1's peak on its seeds (208,693); port-b is *above* qt1's (209,052). Their pyrevm figures on the 2,000-callback replays are nearly the same (178,312 vs 178,766 peak; 113,987 vs 114,144 mean), so the gap appears in the engine runs only. Neither item explains it. One visible design difference is storage (port-b keeps two extra slots, port-a packs into four words); whether that is the cause is not measured. b10-port-b's own remark: "the engine peak includes transaction overhead, which pyrevm's does not". **On the evidence here port-a is the better base to carry forward** (43,084 gas of headroom vs 31,561). - The b05 estimate of 239,000 gas for TwoComp (section 5b) was pessimistic: measured engine peaks are 201,916 and 213,439. - TwoComp replica check values, seeds 10000 / 10001 / 10002: **443.690614 / 571.968071 / 526.124475** (b10-port-a, b10-port-b, b11-combo-fees, b12-cuts-1 agree). - Fixed-point caveats both state: the contract cannot represent the reference's 1e-300 underflow thresholds (a component whose weight underflows to 0 is dropped / the largest-weight component is chosen); no measurable effect in Gate F. Packing is sized for challenge ranges; arbitrary timestamps, counts or reserves are not claimed. - **Against the board:** the brief puts 7th at +0.44 over qt1 and 6th at +1.84 (526.777 − 524.9403). A local engine gain of +0.41 to +0.44 (se 0.04) is therefore about the size of the gap to 7th: not safely past it. Both items say local engine means are not board scores. No result in this root is a board submission. ## 10. COMBO: TwoComp filter + pi-weighted first-trade quoting (b11-combo-fees, b11-combo-offsets) Both are replica-only (CPython 3.12.3, Linux), nothing tuned, both windows complete, each seed once per policy. Filter and state are TwoComp's (`DUAL_CUTS=2`); only on an ambiguous first trade (`dt ≥ 1`, `0.005 < pi < 0.995`) the quote uses TwoComp's own two components as the branches, with the section 4 rule: combo-fees averages the two branches' *fees* (MIX = artifact `23cf289c…cb9e4`, the SHA-256 of b04-mix-wavg-fees), combo-offsets averages *offsets* then converts once against the mixture mean (MIX = `6b911ad2…c6c4`, the SHA-256 of b04-mix-wavg-offsets). | window | pair | combo-fees: mean_diff (se) | combo-offsets: mean_diff (se), seeds won | |---|---|---:|---:| | choose 60000..61023, n = 1024 | COMBO − qt1-ref | +0.637582 (0.019547) | +0.637899 (0.019626), 881/1024 | | | TwoComp − qt1-ref | +0.445424 (0.017637) | +0.445421 (0.017637), 797/1024 | | | COMBO − TwoComp | +0.192158 (0.014701) | +0.192478 (0.014753), 694/1024 | | report 10000..12047, n = 2048 | **COMBO − qt1-ref** | **+0.59864 (0.013386)** | **+0.597391 (0.013388)**, 1753/2048 | | | TwoComp − qt1-ref | +0.424803 (0.012202) | +0.424803 (0.012202), 1606/2048 | | | COMBO − TwoComp | +0.173837 (0.01077) | +0.172588 (0.010763), 1321/2048 | Mean edges, report: qt1-ref 533.262831, TwoComp 533.687634, COMBO 533.861471 (fees) / 533.860222 (offsets). Choose: qt1-ref 529.971157 (fees, recomputed) / 529.97116 (offsets, published), TwoComp 530.416581, COMBO 530.608739 / 530.609059. - **COMBO is the best Gate Q result in this root: about +0.60 over qt1-ref on the report window (about 45 se), +0.17 over TwoComp.** Fee-averaging and offset-averaging again agree within noise (+0.5986 vs +0.5974), as in section 4. The two leads are roughly additive on the replica (TwoComp +0.4248; MIX alone +0.277 on 60000..60511 only; b11-combo-offsets notes that last term is from a different seed set). - **Heavier left tail.** Worst5 COMBO − qt1, report: 10146 −3.535515, 11062 −2.334519, 11808 −1.81974, 10519 −1.783292, 11376 −1.750233 (fees); 10146 −3.552497, 11062 −2.334849, 11808 −1.822738, 10519 −1.782692, 11376 −1.750296 (offsets). Choose: 60210 −2.92036 / −2.927908, 60036, 60326, 60446, 60936. TwoComp's worst on 10146 is −2.751934. COMBO − TwoComp worst: 60210 −3.253952 (fees) / −3.261499 (offsets). - New-path callbacks per 10,000-step run: 5,861.19 choose / 5,873.06 report (fees); 5,861.14 (min 5,237, max 6,367) / 5,873.05 (min 5,176, max 6,428) (offsets). Each costs 2 paired lookups instead of 1. - Check values, seeds 10000 / 10001 (b11-combo-offsets): qt1-ref 443.101741 / 571.454483; TwoComp 443.690614 / 571.968071; COMBO-offsets 444.195330 / 572.172682. `combo.py` sha256 (offsets) `c5b711a0…ad1a796`; TC's code block as extracted is 11,202 bytes, sha256 `9d3c1833321493fb51bbde4e1b4dabc2f8978bd6d774ee2af8dc8aed13f0f0af` (b11-combo-offsets and b12-cuts-1 agree). State check (offsets): carried state bit-identical to TwoComp on 20,103 callbacks of seeds 10000 and 60000; fees identical on the 8,763 callbacks off the new path. - **Gas is open and looks tight.** Neither item has Solidity, Gate F, gas or engine figures. Both note the second lookup comes on top of TwoComp's filter. Figures available elsewhere in this root (assembled by this merge, not measured for COMBO): the best TwoComp port leaves 43,084 gas under the limit (b10-port-a); a paired lookup is two spline surfaces, which b05-latt-c5 prices at 35–43k each for qt1 (citing qt1's result), i.e. up to 85,000 before qtr2's savings; and the new path is not rare (about 5,870 of about 7,000 first trades per run). A COMBO contract therefore needs either cheaper lookups than qtr2's or a cheaper filter path on the two-lookup callbacks; whether the peak of the filter and the peak of the double lookup coincide on the same callback is not measured. - **Source caveats:** 1 of b11-combo-fees' and 2 of b11-combo-offsets' sources did not hold on re-read. Both results' numbers are local runs and they reproduce each other and TC's published figures (TwoComp − qt1 +0.424803 vs TC's +0.424802883; mean edge 533.687634 vs 533.687633550), so the headline does not rest on a quoted page. What does rest on sources: K (the goal repository's `reference/qt1/` at commit 31ff8ed1…, used for `qmref.py` and `blob.bin`; both verified the blob hash, and b11-combo-offsets the qmref hash, locally), and the published per-seed baselines PC/PR, which b11-combo-offsets used *as its qt1 base without recomputing* (see the next bullet). - **Disagreement about the choose-window baseline (PC = b01-p-choose).** b11-combo-fees recomputed qt1-ref on every seed: all 2,048 report seeds equal b01-p-report to 6 dp, but **17 of 1,024 choose seeds differ from b01-p-choose** by 0.001–0.05 (e.g. 60027: 610.629390 vs 610.588587; 60074: 375.830750 vs 375.879165; 61023: 603.564959 vs 603.566722), reproducibly. b12-cuts-1 found **19** differing (one only in the last rounding digit, seed 60100; 18 by up to 0.048). b11-combo-offsets checked only seeds 60000..60007 (all equal) and paired against the published values. Effect on paired means is at most about 4e-6 (b11-combo-fees: +0.637579 vs +0.637582; b12-cuts-1: 3e-6). b11-combo-fees did not investigate the cause; b12-cuts-1 guesses platform floating point (b01-p-choose ran on Python 3.9.6 / macOS arm64, the others on 3.12.3 / Linux), which matches the warning b01-p-choose itself gave. **Use: pair choose-window work against a same-machine recomputation, or accept a ≤ 4e-6 shift in the mean; do not treat b01-p-choose's per-seed values as bit-reproducible on Linux.** The 17-vs-19 count difference between the two checkers is not explained. ## 11. DUAL_CUTS = 1 instead of 2 (b12-cuts-1) Replica-only; the only change to TC's `TwoComp` is the class attribute `DUAL_CUTS = 1`. | window | variant − qt1 (se) | base (cuts=2) − qt1 (se) | **variant − base (se)** | mean edge variant / base / qt1 | |---|---:|---:|---:|---| | choose 60000..61023, n = 1024 | +0.433281 (0.017569) | +0.445424 (0.017637) | **−0.012143 (0.006009)** | 530.404438 / 530.416581 / 529.971157 | | report 10000..12047, n = 2048 | +0.423442 (0.012066) | +0.424803 (0.012202) | **−0.001361 (0.004091)** | 533.686272 / 533.687634 / 533.262831 | - **Verdict (its own): DUAL_CUTS=1 is not better**: about −2 se on choose, indistinguishable from zero on report. It saves one truncation at the worst callback (14 `trunc` calls vs 15 for the base; qt1 13). - **The worst-case path is rare:** first-trade callbacks arriving with two components and dt ≥ 13 average 0.9248 per run (base) and 0.918 (variant) on the report window, out of about 6,997 first trades per run, of which about 5,840 arrive with two components. So that path sets the peak, not the mean (consistent with the 13 qualifying callbacks in 107,708 of section 9's gas probes). - **Disagreement with its brief:** the brief's truncation formula "14+min(cuts,12)" gives 15 and 16; counting from the code gives 14 and 15, and TC's text also says 15 for the base. - Check values 10000 / 10001 / 10002: base 443.690614 / 571.968071 / 526.124475; variant 443.689206 / 572.317403 / 526.182894. Worst5 variant − base, report: 10499 −1.092385, 10395 −1.027609, 11661 −0.794205, 11944 −0.741795, 10184 −0.719261. - Since it is no better on edge and no gas was measured, there is no evidence here for switching the ports of section 9 to one cut; if peak gas ever needs one truncation less, the report window says the edge cost is nil within noise. ## 12. Disagreements and corrections, in one place | topic | who says what | resolution here | |---|---|---| | What "Gate F" compares | b08-qtr2-loads: raw `QMRef` returns → **fails** on qt1 itself (seed 70026, cb 1702, 200.08 bps). b03-gf-a, b03-gf-b, b06-gas-basis, b08-qtr2-spans, b10-port-a, b10-port-b: fees after `replica2.clampf` → **passes** | same data, different label; "pass" in this merge means the clamped reading (sections 3, 7) | | qt1 engine peak | brief: 208,775. Measured: 206,311 to 209,204 on seven fresh seed sets (section 2) | sample-dependent; all under 245,000 | | Choose-window qt1-ref per-seed values | b01-p-choose (macOS, 3.9.6) vs Linux recomputes: 17 seeds differ (b11-combo-fees), 19 (b12-cuts-1); b11-combo-offsets assumed equal after checking 8 | means move ≤ 4e-6; report window identical on all 2,048 (section 10) | | TwoComp port gas | b10-port-a peak 201,916 vs b10-port-b 213,439, same reference | unexplained; port-a is the lower-gas implementation (section 9) | | TwoComp gas estimate | b05-latt-two-comp estimated 239,000 to 289,400 worst case | measured engine peaks are lower (section 9) | | Exact-lattice gas | brief: 453k a call; b05-latt-c5's rule: mean 243,130 | unreconciled; b05's rule is an unmeasured estimate (section 5a) | | Lead 1 size | brief: +0.49 over Gaussian + plain; b04: +0.28 over qt1-ref; inside COMBO: +0.17 over TwoComp | different bases; the +0.49 is not reproduced by any result here | | Truncation count | brief's "14+min(cuts,12)" vs b12-cuts-1's code count 13+cuts | code count stands, TC's text agrees (section 11) | | b01-p-choose's own source check | it says all 18 quotes verified; re-read flagged 3 | unresolved; its measurements do not depend on them | ## 13. Seeds consumed (engine seeds are never to be reused) | engine seeds | used by | arms | |---|---|---| | 9800000..9800127 | b02-eb-a | **none run (blocked): still fresh** | | 9800128..9800255 | b02-eb-b | qt1 | | 9800256..9800287 | b06-gas-basis | qt1, Qt1Fast (basis) | | 9800288..9800319 | b06-gas-dispatch | qt1, Qt1Fast (dispatch) | | 9800320..9800447 | b08-qtr2-control | **none run (blocked): still fresh** | | 9800448..9800575 | b08-qtr2-spans | qt1, qtr2, spans candidate | | 9800576..9800639 | b08-qtr2-loads | qt1, qtr2 | | 9800640..9800703 | b08-qtr2-loads | **assigned, not executed: still fresh** | | 9800704..9800831 | b10-port-a | qt1, TwoComp port a | | 9800832..9800959 | b10-port-b | qt1, TwoComp port b | b10-port-c's assigned range is not stated in its result. Replica seeds (reusable, deterministic): choose 60000..61023 and report 10000..12047 (Gate Q); Gate F traces 70000..70049 (most items), 70050..70099 (b03-gf-b), 70100..70149 (b06-gas-basis), 0..49 at 5,000 steps (b06-gas-dispatch); gas probes 70000..70009 (b10-port-a, b10-port-b). the b04 screens and b05-latt-c5 used only 60000..60511 of the choose window (b05-latt-two-comp also ran the full report window); b09-class-age fitted on 60000..60511 and selected on 60512..61023. ## 14. Not found in these 25 results - **No board score** for any candidate, and no estimate of how a local engine gain maps to the board. - **No Solidity, Gate F, gas or engine result for COMBO**, the best replica policy. No report-window score for wavg-offsets / wavg-fees alone, or for latt-c5 or any capped lattice. - **No description of how qtr2 was made** beyond its one-line header comment (section 9), and no completed audit of it (b08-qtr2-control blocked). What is known is measured from outside: hashes, sizes, gas, near-identical edges. - **No combination of the gas edits**: basis (b06) + dispatch (b06) on qt1, or either of them or the spans edit (b08) applied to the TwoComp ports. The ports are built on plain qtr2, without the 2,647-gas spans saving. - **Nothing that confirms or explains the brief's 453k for the exact lattice**, and no EVM measurement of any lattice variant. - **No explanation** of the port-a / port-b gas gap, or of the 17-vs-19 seed count in the choose-baseline mismatch. - b09-class-size's Gate Q (3,008 of 3,072 paired differences missing); b08-qtr2-loads' seeds 9800640..9800703 and 4 of its 50 Gate F seeds; everything b02-eb-a, b08-qtr2-control and b10-port-c were asked for.