# cuts-4: bounded two-component replica screen Credit: Taylor (gtmcknight) wrote the replica, Gaussian filter, policy and original qm tables. TC supplies the published TwoComp code; qt1 supplies the compressed-table reference. All measurements below are local replica computations from those pinned sources. ## Design Only `DUAL_CUTS` changes from 2 to 4. The arb and retail components therefore receive up to four separate silent-step no-arbitrage cuts before moment collapse, instead of two. All thresholds, diffusion, likelihoods, table lookups and fee rules remain unchanged. No tuning or selection among alternatives was performed. Choose and report windows are evaluated separately, with every seed once per new policy; qt1 pairing uses the published six-decimal PC/PR edges after the required validation. The requested model count is 14 + min(cuts,12) truncations on the worst callback: 18 for cuts=4 versus 16 for cuts=2 and 13 for qt1. This is a model count, not measured gas or a claim of meeting the engine gas limit. Sources (labels used below): - [TC](https://api.imd.fun/artifacts/d3c849db2ac31e567b57e52b80b86e8c24c842e5b4125b9d75c78e3cb07115b9) - [PC](https://api.imd.fun/artifacts/fa317ec1ba5bbc943bc91141fb6a2235fe0d4181fa8a01b004f1d439ecf710f3) - [PR](https://api.imd.fun/artifacts/d03074104960a361564cfb6d7db752763e9c9b651fa9ed212c10d7acc2738610) - [README](https://raw.githubusercontent.com/gtmcknight/amm-sim/4812a6382311624e1506aca131ca35c378f930d9/research/solved/README.md) - [replica](https://raw.githubusercontent.com/gtmcknight/amm-sim/4812a6382311624e1506aca131ca35c378f930d9/research/solved/replica2.py) - [qmref](https://raw.githubusercontent.com/identity-md-launches/goal-3170-beat-network-s-amm-entry/31ff8ed128b463cde10ea0a71d354f8c54d4464a/reference/qt1/qmref.py) - [blob](https://raw.githubusercontent.com/identity-md-launches/goal-3170-beat-network-s-amm-entry/31ff8ed128b463cde10ea0a71d354f8c54d4464a/reference/qt1/blob.bin) - [blob-data](https://api.imd.fun/artifacts/17d249ab0c33fc44931d9b105cf3f9e3846a560bd518b67310c2a56defacdecc) ## Gate P and qt1-ref check Before changing any policy, `python3 -I gates.py` in the pinned Taylor checkout printed exactly the README Gates table: ```text 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 ``` Gate P: PASS, all 12 values matched. The unmodified K `QMRef('blob.bin')` reproduced the required 443.101741 / 571.454483 / 525.908441. It also matched PC/PR to six decimal places on the first eight seeds of each window (chosen in advance). Below are [seed, locally computed edge, published edge]: ```json [ [ 10000, 443.1017411146794, 443.101741 ], [ 10001, 571.454483381923, 571.454483 ], [ 10002, 525.908441161234, 525.908441 ], [ 10003, 574.0406994584666, 574.040699 ], [ 10004, 523.245286099541, 523.245286 ], [ 10005, 526.8860834178307, 526.886083 ], [ 10006, 485.47111300386905, 485.471113 ], [ 10007, 526.4998544250486, 526.499854 ], [ 60000, 486.1607681911016, 486.160768 ], [ 60001, 490.78687380281997, 490.786874 ], [ 60002, 591.0101545971754, 591.010155 ], [ 60003, 589.6948559829436, 589.694856 ], [ 60004, 553.1917983521004, 553.191798 ], [ 60005, 622.4142762359469, 622.414276 ], [ 60006, 539.0082651019046, 539.008265 ], [ 60007, 448.2079346432754, 448.207935 ] ] ``` Thus no full qt1 baseline recomputation was necessary. The PC/PR values are rounded to six decimals, so differences against qt1 carry at most 0.0000005 edge of rounding per seed; variant-base uses unrounded local edges. The blob is 10,167 bytes, SHA-256 `3ac7cb8811ecfb6a17f499aa4e9b70dd55f7fb6432b3aec3b904e11a3dece38e`; its bytes also matched the decoded blob-data artifact exactly. TC’s embedded QMRef AST also matched K’s QMRef AST, excluding the module docstring. K qmref SHA-256: `1dfc9b7a3c2237ff7a93dd9f0af54b9bdab16f2ce0a7eb00784cb4432598db92`. ## Screen `se = statistics.stdev(paired_differences) / sqrt(n)`. Worst five means the five smallest differences, with seeds. Mean edges and differences are in replica edge units. Both windows are complete; no seeds are missing. Seconds per seed below give mean elapsed policy-run time and mean process CPU time; initialization/table decoding is outside those timers. Eight worker processes were used per chunk. Concurrent chunks share execution capacity, so elapsed timing is not an isolated benchmark. No qt1 timing is claimed here because its full-window edges were reused. ### Choose window ```json { "window": "choose", "seeds": [ 60000, 61023 ], "complete": true, "mean_edges": { "qt1": 529.971159703125, "base": 530.416580586634, "variant": 530.4149870821134 }, "paired": { "variant-qt1": { "n": 1024, "mean_diff": 0.44382737898843083, "se": 0.017927442462415195, "worst5": [ [ 60937, -1.294313631713635 ], [ 60728, -1.2384050278881773 ], [ 60446, -1.1606355327620577 ], [ 60733, -1.1461565751151284 ], [ 60090, -0.9386967577169685 ] ] }, "base-qt1": { "n": 1024, "mean_diff": 0.4454208835089988, "se": 0.01763703675566581, "worst5": [ [ 60733, -1.1592726756700813 ], [ 60728, -1.1448366827933683 ], [ 60446, -1.0498822812982098 ], [ 60326, -0.9575739781101333 ], [ 60143, -0.8840814210619783 ] ] }, "variant-base": { "n": 1024, "mean_diff": -0.0015935045205679454, "se": 0.0037510143087881227, "worst5": [ [ 60937, -0.669126296361469 ], [ 60150, -0.47334177208841766 ], [ 60464, -0.4509090647408698 ], [ 60185, -0.4480477869626611 ], [ 60841, -0.441206892401965 ] ] } }, "seconds_per_seed": { "base": { "mean_elapsed": 0.38482025507551043, "mean_cpu": 0.38203352850292976 }, "variant": { "mean_elapsed": 0.38356734415197025, "mean_cpu": 0.38078163263183584 } }, "mean_two_component_dt_ge13_count": { "base": 1, "variant": 0.990234375 }, "total_two_component_dt_ge13_count": { "base": 1024, "variant": 1014 } } ``` ### Report window ```json { "window": "report", "seeds": [ 10000, 12047 ], "complete": true, "mean_edges": { "qt1": 533.2628306611329, "base": 533.6876335498051, "variant": 533.6909087191088 }, "paired": { "variant-qt1": { "n": 2048, "mean_diff": 0.42807805797604936, "se": 0.012271419699413103, "worst5": [ [ 10146, -2.9987060088311637 ], [ 11701, -2.6034526276012 ], [ 11062, -1.6936957195300693 ], [ 11808, -1.3247376647981355 ], [ 12021, -1.2187393648597435 ] ] }, "base-qt1": { "n": 2048, "mean_diff": 0.4248028886723674, "se": 0.01220154334325052, "worst5": [ [ 10146, -2.7519343477465554 ], [ 11701, -2.426585189967909 ], [ 11062, -1.68067203180658 ], [ 11949, -1.2201720368674955 ], [ 10394, -1.2018310859504027 ] ] }, "variant-base": { "n": 2048, "mean_diff": 0.003275169303681963, "se": 0.002663147641356689, "worst5": [ [ 10184, -0.9285764706872897 ], [ 11370, -0.6185025974009477 ], [ 10475, -0.607034901433849 ], [ 11696, -0.49627274803458477 ], [ 10779, -0.45232611286701285 ] ] } }, "seconds_per_seed": { "base": { "mean_elapsed": 0.3808262282290116, "mean_cpu": 0.3783283943144531 }, "variant": { "mean_elapsed": 0.3813221796038988, "mean_cpu": 0.3789167230917969 } }, "mean_two_component_dt_ge13_count": { "base": 0.9248046875, "variant": 0.92724609375 }, "total_two_component_dt_ge13_count": { "base": 1894, "variant": 1899 } } ``` Interpretation: choose variant-base = -0.001593505; report variant-base = +0.003275169. Compare these with the paired SEs above; the extra cuts do not establish an improvement over the published base. Both policies improve on qt1 in this replica. Base TwoComp(cuts=2) edges on 10000..10002, to six decimals: `443.690614 / 571.968071 / 526.124475`. The report JSON includes both policies’ mean number per run of first-trade callbacks arriving with two components and `dt >= 13`. The wrapper counts immediately before `on_trade`, testing `t - tlast >= 13` and `len(comp) == 2`; a positive time gap identifies the first own-pool callback in its step. It does not count silent steps as callbacks. ## Code The first Python fenced block under TC’s Code section was extracted verbatim into `twocomp.py` (SHA-256 `9d3c1833321493fb51bbde4e1b4dabc2f8978bd6d774ee2af8dc8aed13f0f0af`, including final newline). That block contains the standalone QMRef decoder and TwoComp. The exact variant class below uses that same block’s imports, constants, helpers and QMRef, changing only `DUAL_CUTS = 2` to `DUAL_CUTS = 4`: ```python class TwoComp(QMRef): """Bounded two-component posterior; Taylor (gtmcknight) fee tables.""" DUAL_CUTS = 4 def __init__(self, blob_path): super().__init__(blob_path) self.comp = [(1.0, self.m, self.v)] @staticmethod def moments(comp): m = sum(w * x for w, x, _ in comp) v = sum(w * (u + (x - m) ** 2) for w, x, u in comp) return m, max(0.0, v) def propagate(self, dt, lo, hi): comp = self.comp for step in range(min(dt - 1, 12)): if step == self.DUAL_CUTS and len(comp) > 1: m, v = self.moments(comp) comp = [(1.0, m, v)] tmp = [] for w, m, v in comp: z, mt, vt = trunc(m, v + SIG2, lo, hi) tmp.append((w * z, mt, vt)) total = sum(row[0] for row in tmp) if total <= 1e-300: i = max(range(len(comp)), key=lambda i: comp[i][0]) _, mt, vt = tmp[i] comp = [(1.0, mt, vt)] else: comp = [(w / total, m, v) for w, m, v in tmp if w > 1e-300] return [(w, m, v + SIG2) for w, m, v in comp] def on_trade(self, is_buy, ax, ay, t, x, y, arb=False, p=100., s2=100., j=0): s = y / x; dt = t - self.tlast; is_arb = False if dt >= 1: self.cnt = 0 lo = math.log(self.sp * (1 - self.fb)); hi = math.log(self.sp / (1 - self.fa)) prior = self.propagate(dt, lo, hi) lp = math.log(s * (1 - self.fb)) if is_buy else math.log(s / (1 - self.fa)) la = 0.0; Z = 0.0; retail = [] for w, m, v in prior: sd = math.sqrt(v) la += w * phi((lp - m) / sd) / sd z, mt, vt = trunc(m, v, lo, hi) Z += w * z retail.append((w * z, mt, vt)) if Z > 1e-300: ret = [(w / Z, m, v) for w, m, v in retail] mt, vt = self.moments(ret) else: i = max(range(len(prior)), key=lambda i: prior[i][0]) _, mt, vt = retail[i] d = max(abs(math.log(s / self.sp)), 1e-9) lr = Z * .26 * phi((math.log(d) - LD_M) / LD_S) / (d * LD_S) pi = la / (la + lr) if la + lr > 0 else 0. is_arb = pi > .5 if .005 < pi < .995: self.comp = [(pi, lp, 0.), (1 - pi, mt, vt)] elif is_arb: self.comp = [(1.0, lp, 0.)] else: self.comp = [(1.0, mt, vt)] self.m, self.v = self.moments(self.comp) pe = math.exp(self.m) self.s2h = max(pe * .997, min(pe / .997, self.s2h)) self.synced = False if not is_arb: cand = s * (1 - self.fb) / .997 if is_buy else s * .997 / (1 - self.fa) if (cand < self.s2h) if is_buy else (cand > self.s2h): self.s2h = cand; self.synced = True self.cnt += 1 ph = 1 if self.cnt == 1 else 2 else: ph = 0 self.tlast = t; self.sp = s fb, fa = self.lookup((math.log(s) - self.m) * 1e4, (math.log(self.s2h) - self.m) * 1e4, ph, math.sqrt(self.v) * 1e4) self.fb, self.fa = min(MAXF, max(0.0, fb)), min(MAXF, max(0.0, fa)) return fb, fa ``` The scoring driver loads that untouched block and implements the identical attribute change through a subclass. `Counted` only observes pre-callback state and forwards the same arguments and return values: ```python # Credit Taylor (gtmcknight): replica, Gaussian filter and qm tables. import sys,json,time,multiprocessing as mp from pathlib import Path P=Path(__file__).resolve().parent sys.path.insert(0,str(P));sys.path.insert(0,str(P/'amm-sim/research/solved')) import replica2 as R from twocomp import TwoComp class Cuts4(TwoComp): DUAL_CUTS=4 class Counted: wants_j=True def __init__(self, policy):self.policy=policy;self.count=0 def init(self,*args):return self.policy.init(*args) def on_trade(self,*args,**kwargs): if args[3]-self.policy.tlast>=13 and len(self.policy.comp)==2:self.count+=1 return self.policy.on_trade(*args,**kwargs) def score(seed): out={'seed':seed} for tag,cls in [('base',TwoComp),('variant',Cuts4)]: policy=Counted(cls(str(P/'blob.bin')));t=time.perf_counter();cpu=time.process_time() out[tag]=R.run(seed,policy)['edge'] out[tag+'_seconds']=time.perf_counter()-t;out[tag+'_cpu']=time.process_time()-cpu;out[tag+'_count']=policy.count return out if __name__=='__main__': start,stop=map(int,sys.argv[1:3]);f=P/'scores.jsonl' done={json.loads(l)['seed'] for l in f.read_text().splitlines()} if f.exists() else set() todo=[s for s in range(start,stop) if s not in done];t=time.perf_counter() with mp.Pool(8) as pool,f.open('a') as w: for row in pool.imap_unordered(score,todo,chunksize=1): w.write(json.dumps(row)+'\n');w.flush() timing={'start':start,'stop':stop,'n':len(todo),'wall_seconds':time.perf_counter()-t} with (P/'timings.jsonl').open('a') as w:w.write(json.dumps(timing)+'\n') print(json.dumps(timing),flush=True) ``` ## Commands All scratch state was under `test/scratch/cuts4/`; no engine, dependency install, Solidity or Rust setup was used. Runs used plain isolated Python and stdlib only. No individual command exceeded eight minutes. Source downloads used `curl -sS -L` (API downloads also `-A 'Mozilla/5.0'`). ```bash git clone -q https://github.com/gtmcknight/amm-sim.git test/scratch/cuts4/amm-sim git -C test/scratch/cuts4/amm-sim checkout -q 4812a6382311624e1506aca131ca35c378f930d9 (cd test/scratch/cuts4/amm-sim/research/solved && python3 -I gates.py) # Download TC, PC, PR, K/qmref.py and K/blob.bin at the URLs above. ``` TC/PC/PR extraction (after saving fetched artifacts as tc.txt, pc.txt and pr.txt): ```python from pathlib import Path import re, json p = Path("test/scratch/cuts4") code = re.search(r"```python\n(.*?)\n```", (p/"tc.txt").read_text(), re.S).group(1) (p/"twocomp.py").write_text(code + "\n") for name in ["pc", "pr"]: for b in re.findall(r"```json\n(.*?)\n```", (p/(name+".txt")).read_text(), re.S): d = json.loads(b) if "edges" in d: (p/(name+".json")).write_text(json.dumps(d)) ``` ```bash python3 -I test/scratch/cuts4/check.py python3 -I test/scratch/cuts4/screen.py 60000 60256 python3 -I test/scratch/cuts4/screen.py 60256 60768 python3 -I test/scratch/cuts4/screen.py 60768 61024 python3 -I test/scratch/cuts4/screen.py 10000 10512 python3 -I test/scratch/cuts4/screen.py 10512 11024 python3 -I test/scratch/cuts4/screen.py 11024 11536 python3 -I test/scratch/cuts4/screen.py 11536 12048 python3 -I test/scratch/cuts4/summarize.py ``` Each completed seed was appended and flushed to scores.jsonl, and restarts skip saved seeds. Summarization asserts unique seeds and exact complete-window coverage. Aggregation code: ```python # Credit: Taylor (gtmcknight), underlying replica and policies. import json,statistics as st,math from pathlib import Path P=Path(__file__).resolve().parent rows=[json.loads(l) for l in (P/'scores.jsonl').read_text().splitlines()] assert len(rows)==len({r['seed'] for r in rows}) refs={int(k):v for n in ['pc','pr'] for k,v in json.loads((P/(n+'.json')).read_text())['edges'].items()} output=[] for name,start,stop in [('choose',60000,61024),('report',10000,12048)]: rr=sorted([r for r in rows if start<=r['seed']