Classical vs DQI: polynomial intersection, GF(131), n = 64 (warm-up)
Polynomial intersection submission #26
zihan_chen · submitted · verified 7 d ago · Accepted CC BY 4.0
Verifier report
- field
- prime
- q
- 131
- n
- 64
- m
- 130
- degree
- 63
- satisfied
- 124
- signed max linsat
- 118
- check
- Q (degree 63; n = 64 coefficients) evaluated exactly at all 130 nonzero points; 124 of the 130 values lie in their target sets
- verify seconds
- 0.05
View raw report
{
"field": "prime",
"q": 131,
"n": 64,
"m": 130,
"degree": 63,
"satisfied": 124,
"signed_max_linsat": 118,
"check": "Q (degree 63; n = 64 coefficients) evaluated exactly at all 130 nonzero points; 124 of the 130 values lie in their target sets",
"verify_seconds": 0.05
}Submission file
Download submission JSON under Creative Commons Attribution 4.0 International (license file)
sha256 fbbbe29c36ec530fea9c410c04d52a5bb1dd86ae498359c32522756da1a70641 · 221 bytes · verifier 0183d00bf58d
License
License: Creative Commons Attribution 4.0 International (CC BY 4.0, the default). Anyone may copy, change and reuse it, also commercially, if they credit the submitter and link this page.
Credit: zihan_chen, QArena submission Polynomial intersection #26, with a link to this page. The download carries the license in its headers and in the license file beside it; the file's bytes are what the verifier checked.
Builds on
This submission names no earlier submission.
Cited by
No other submission names this submission yet.
Attached code
p131-n64-solve.py 21.3 KB
#!/usr/bin/env python3
"""Standalone OPI search reproduction; no network access or third-party Python deps.
Run: OPENBLAS_NUM_THREADS=1 OMP_NUM_THREADS=1 MKL_NUM_THREADS=1 TMPDIR="$PWD/.tmp" python3 -I solve.py OUTPUT.json
Requires a C++17 compiler (g++/libstdc++). On HPC, compile and run only inside a
compute allocation. Original source and fixed-trial source versions, scientific
run statistics, seed, exact replay count, and expected output hash are embedded.
The C++ search uses integer arithmetic and mt19937_64; std::shuffle is supplied
by libstdc++. Output hash verification catches any toolchain-dependent changes.
"""
import hashlib
import json
import os
from pathlib import Path
import shutil
import subprocess
import sys
import tempfile
LICENSE_TEXT='MIT License\n\nCopyright (c) 2026 this workspace\'s authors\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the "Software"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n'
RECIPE={'method': 'prime-line', 'instance': 'p131-n64', 'seed': 1018, 'replay_count': 36144657, 'count_unit': 'affine lines', 'tail_argument': '100000', 'expected_score': 124, 'expected_artifact_sha256': 'fbbbe29c36ec530fea9c410c04d52a5bb1dd86ae498359c32522756da1a70641', 'original_cpp_sha256': '87d1e7021c7d384f30438da22d0e9a1c8a897a6ada5ba773e4667c8af2e6cf93', 'fixed_trial_cpp_sha256': 'e80b7081193ba1c1304903f7b8845ee349b67a9d612d5cc403011ab91c2f9656', 'original_run': {'seed': 1018, 'satisfied': 124, 'lines': 130124576, 'candidates': 17046319456, 'bases': 1302, 'cpu_seconds': 298.937, 'elapsed_seconds': 300.009}, 'scientific_seconds_requested': 300.0, 'local_validation': {'status': 'accepted', 'score': {'satisfied': 124}, 'detail': {'field': 'prime', 'q': 131, 'n': 64, 'm': 130, 'degree': 63, 'satisfied': 124, 'signed_max_linsat': 118, 'check': 'Q (degree 63; n = 64 coefficients) evaluated exactly at all 130 nonzero points; 124 of the 130 values lie in their target sets'}}, 'incumbent_log_line': 'best=124 lines=36144657 candidates=4734950067 bases=362 elapsed_s=84.7716', 'compile_command': ['g++', '-std=c++17', '-O3', '-march=native', 'search.cpp', '-o', 'search'], 'source_provenance': 'Original implementation; Jordan et al. arXiv:2408.08292; Khattar et al. arXiv:2510.10967 (CC BY 4.0); MIT license for implementation. Official QArena instance data. No contestant artifact.'}
INSTANCE={'board': 'opi', 'instance': 'p131-n64', 'mode': 'ranked', 'cpu_seconds': 10, 'mem_mb': 128, 'field': 'prime', 'q': 131, 'n': 64, 'm': 130, 'r': 65, 'generator': 'SplitMix64 from seed (q << 32) | n, partial Fisher-Yates per point (SPEC_w2b_opi)', 'seed': 562640715840, 'convention': 'targets[i] is the target set of the evaluation point y = i + 1, a lowercase hexadecimal bitmask of fixed width ceil(q/4): bit v set means v is in F_y', 'targets': ['70e61df678c0922a554d3e9287fe31835', '20aa4959ed5bb0d3993cc98346d5e5b61', '273d93768f21a1767505f109ac14ced3a', '5fbc0576172f248de2d43f3cc803da254', '3a7035e630f1795ef3242fb05708969c3', '0e13c0582cfcf1827787d77363173a385', '5187d6698e0990de76e4cdbe0c2069aaf', '6a54dc2d116edc31043a1d499fbc9b996', '3128df6b52c3a7e799b15402bd9306659', '0ae9c6d864901d8daf2eeed528532dad8', '2d45314219c4a91298be9dd5e716e9aeb', '56a683938c43e14a1557a36a7c2e4cbbb', '5ac3978cca9a58a1ac3fec9a85244afb1', '7bc1691b73373f495250a61e8507744dc', '2a537f2db52ac484580b6eec7fd8261b0', '24dcdf5e802c3827076945d2c57197f4e', '5f07b4139836d02dbbe12f1e5a9e21a26', '328ae65e9c5215cff1c419706d291cfb8', '36614b585d29c20fecbe9554b63c2f2a8', '3f955666343f0aa95370c29e4ad54b436', '2eda779a4992c105f1a89cf0da232b2bb', '40dac270cc9d86e7ec79aa307e47e094d', '64690b0f0e69c39a767fcd00d2d3b151d', '6716861d99d7707104e6cd1137b6bc839', '12fea952cabba1f58a315c41665a34c9b', '1ea29b15f1c9c9882ee277324359dd3c2', '063d68acd5400be257cea9721c8b6abd7', '13740a665a7d8159fc0432fa8739de31d', '2aa3d6e6a042b31abf6d62b3884458dbb', '048540e3cb8be9653cd8ee2ef9603ce65', '2b58f0994c46d7c55ce9290fb3ab32a8a', '6d30765f11edd8f89d32666a087e45a48', '4fe90d3c07a47baf9223b9c17683051cb', '20a14c0f5d77e28c96bba24f58d1ef948', '5a30c5eb3cf858a907487da348df39513', '713b2a0cea045698e73b5f6307bb66d40', '2efa70c6af10c0701934a4ecd57e854fb', '609e8e9c3c7a15d831071abd935ba4da9', '0cd19d7a8716ea8d0cdc1f106fa4b6c4d', '00de7766f0ba891fa5e5f34b9710c4948', '3764ab7e0aec5fea24bccc81385f1160c', '5cc9bdf11b85812a2a4d749df10987a7a', '00f7d2a0dec683eec0c534e361f24fe1a', '3fe41315e0b465285dbaddc342a578cc9', '23951b7dc74dc68318f0725119df5615c', '25c568938636f595d41ded6a78b853232', '64477b71821d9c038bb2ef53daa2235ca', '35d6da34547b45988d12c58b171de7385', '63cfc01135a34d9daa897dba50ec532b8', '5a48b280453f47f555e078d4c58df7895', '7daa7268cd36d903e9b2de4d3c0954438', '26c89cbf425db647f170cd5a9883538e1', '2e336c0569593a826831937ecd383d6e7', '6bec97151e4d22da91bb090a70b5bf314', '4c8c2e94f803d96d93d2562363e76f40d', '45981f9d15b3ec0239723c613dcaf1745', '7d9da4e88811ee675bf11021b5179994d', '244a6d5f88ed5bbceb8a56106096f0e4b', '37b1d6be69928cf08268607cd37758a70', '4084b4c0756933bdc5943cfe95d0b71ae', '695e7e5c4c6cdf60d5470a6849296ac5c', '3b5a0a4276a54b8e7c567ecc1325d25cc', '6b21fe8677e979c070e526610a5b3885b', '4a3698fb49611a22a3aadc7e7b4d81c87', '4d68427fe9a15ce87d1672583d87d00ab', '5933d94dfae4d711b9b38c918ed360411', '2ec69c95d38724a791c02ebb4a8aaa757', '47041432c32bcca9d2db3b33c723f836b', '6cbf869d4f101702f1dd91fb81b40d435', '4bcdba0a201aafd2d41203cbd9d0b77ba', '1cc4e58e39ee2d426f6e5c2c421d8cc6b', '7aa8e8691aae7ee4cc8441b4c31e6d2f4', '633612369f9926fa402f7c83cd56583b4', '765bae38c8d5e6bf8c511aaa2d9b30141', '29f6dc805db2c8d2fcc149ee24269ed54', '60bb5169e2c2d45ab1166ea522b4dcafa', '51b47859e2fb446614fca227bc6a16a99', '220273627982a43fe8656391ebd5a0fbb', '232d9cfb8609e041736af68a7b3f34a12', '55251d4f8d69e56e03f2974c3247835b1', '274d842d709d30348273372bf7c5873e5', '3211e6c614577c5233b3e45087d62fcb5', '35e4efe790a842b4d79f247ae02d8c107', '5a70efa1439f83d7635359c150027b715', '3189889a1fb52f8b8932d66f61a7c29ca', '1da90dfa8e185e37891365a94284ff95c', '21e97be9de01322ac3df61b08ca9a33e8', '0a6802b5c1cb34f3bb0e1ca9ab5383f2f', '08423f0ec4a3a18683bf4ed945f9c0cff', '0f25a412f1add837f94e742762caa3a0d', '338f56b2c0f6d2d34ef35d485163c4330', '48e2309529ef0ca4e45d63c6a74e3d6ec', '426fcfcdd69730a990ebc819a67c6ca10', '788a287706d3aaee9e5544ff098aa62a6', '00de42bef6f830548aa9d91ce83b53379', '57a928433b9bb6429df0f7bbce3300085', '7d60651d6f9b11aa354e51e2e2712950f', '0f5d40ff73049a7e538065ce4fa1fa422', '38479fce92091143f69a3a934e5c9b539', '0296ab0610b45c1d7caa07afb7ce3ce63', '6534664b5bdd4abbb01238ab951d4c574', '572b45b36173d886dd9ba69c832d11869', '739bb3258b56d5008765d2529a0816ff7', '3f80fce3b974cbaccbe27705011c47072', '4a322e4bd457527c253ceeb1b16790734', '266aa9878a8d16cf3a7b02d61e6430cbf', '46a299bc2ce0995aa342f0d33e86f2eb6', '70ce9ecb2143f28fb6ba754c8745015a3', '1922ebeb8a24813d683c6e75f8a46eda1', '0d6e4d1529e8ea323d943a6878dab5e2a', '6e6dd946e2f61836ea19a68c303f421e3', '54fae62ee05ba1991b67567b87066802b', '26aa4b3d5aa438a98e181a75774a795c7', '6eaae3cf84cd5c3544c66845c970584fd', '5e8a8a24d0796d09b1efc019c57f82e76', '56a23dce38ac9a41049e7d31ea9aade45', '0112ab06d8c59eda2a195592def2b17fa', '20d9e1d84bc8618ceb13b993d2619dd75', '38d1c7e5804276db99b8058fbb4437762', '092c3f2647c2b306f6a7a67da3ae9340a', '4ea94387e8ad303427e79cc24c91d785f', '1cba509109c1fca63277de87d654389f2', '189842898b26fee37d1a606742f0b6f37', '0a4767f73df8667d1b19e0030095e921f', '6fbb1921e083480a137a437fed5fd9901', '29a7e14f01ff1f240106c23a0f673c7f3', '7a9caa2a8f345890fbcddb610364bf211', '6eb44198583c0fcc21ed88b3a3cd0af7d', '676443c3ee0d857fde9c003f0c2f161d8', '2e2eadce2ad2014ee4f0521c335bfe92a']}
ORIGINAL_CPP='// Original implementation of interpolation (Prange) on an affine line.\n// Algorithm provenance: Jordan et al., arXiv:2408.08292, and Khattar et al.,\n// arXiv:2510.10967 Section III.1 (CC BY 4.0). No third-party code is copied.\n// MIT license for this implementation; see README.md.\n#include <algorithm>\n#include <chrono>\n#include <cstdint>\n#include <ctime>\n#include <fstream>\n#include <iostream>\n#include <numeric>\n#include <random>\n#include <stdexcept>\n#include <string>\n#include <vector>\nusing namespace std;\n\nstatic int mod(int64_t x,int q){x%=q;return x<0?x+q:x;}\nstatic int inv(int x,int q){int a=q,b=mod(x,q),u=0,v=1;while(b){int t=a/b;int r=a-t*b;a=b;b=r;r=u-t*v;u=v;v=r;}if(a!=1)throw runtime_error("nonunit");return mod(u,q);}\nstatic vector<int> multiply_root(const vector<int>& p,int x,int q){vector<int> z(p.size()+1);for(size_t i=0;i<p.size();++i){z[i]=mod(z[i]-(int64_t)x*p[i],q);z[i+1]=mod(z[i+1]+p[i],q);}return z;}\nstatic vector<int> polynomial(const vector<int>& roots,const vector<int>& vals,int t,int q){\n vector<int> b{1};for(int x:roots)b=multiply_root(b,x,q);\n vector<int> c(b.size());for(size_t k=0;k<c.size();++k)c[k]=mod((int64_t)t*b[k],q);\n for(size_t i=0;i<roots.size();++i){\n int x=roots[i],d=1;for(size_t j=0;j<roots.size();++j)if(i!=j)d=mod((int64_t)d*(x-roots[j]),q);\n int w=mod((int64_t)vals[i]*inv(d,q),q);vector<int> z(roots.size());z.back()=b.back();\n for(int k=(int)z.size()-2;k>=0;--k)z[k]=mod(b[k+1]+(int64_t)x*z[k+1],q);\n for(size_t k=0;k<z.size();++k)c[k]=mod(c[k]+(int64_t)w*z[k],q);\n }return c;\n}\n\nint main(int argc,char**argv){\n if(argc!=6){cerr<<"usage: prange_line TARGETS.txt SEED SECONDS OUTPUT.json LINES_PER_BASIS\\n";return 2;}\n ifstream f(argv[1]);int q,n;f>>q>>n;if(!f||q>257||n<2||n>=q-1)throw runtime_error("supported pilot: prime q<=257 and 2<=n<q-1");\n int m=q-1,k=n-1,W=(q+63)/64,L=0;while((1<<L)<=m)++L;\n vector<vector<int>> target(m);vector<vector<uint8_t>> hit(m,vector<uint8_t>(q));\n for(int j=0;j<m;++j){int r;f>>r;while(r--){int x;f>>x;target[j].push_back(x);hit[j][x]=1;}}if(!f)throw runtime_error("bad targets input");\n uint64_t seed=stoull(argv[2]),lines_per_basis=stoull(argv[5]),lines=0,candidates=0;double seconds=stod(argv[3]);mt19937_64 rng(seed);\n auto start=chrono::steady_clock::now();clock_t cpu_start=clock();int best=-1;vector<int> bestc;uint64_t bases=0;\n while(chrono::duration<double>(chrono::steady_clock::now()-start).count()<seconds){\n vector<int> order(m);iota(order.begin(),order.end(),1);shuffle(order.begin(),order.end(),rng);\n vector<int> roots(order.begin(),order.begin()+k),outside(order.begin()+k,order.end()),vals(k);\n const int M=outside.size();vector<int> B(M,1),A(M,0),weight(k*M);\n for(int j=0;j<M;++j)for(int x:roots)B[j]=mod((int64_t)B[j]*(outside[j]-x),q);\n for(int i=0;i<k;++i){int d=1;for(int u=0;u<k;++u)if(i!=u)d=mod((int64_t)d*(roots[i]-roots[u]),q);int id=inv(d,q);vals[i]=target[roots[i]-1][rng()%target[roots[i]-1].size()];\n for(int j=0;j<M;++j){int w=mod((int64_t)B[j]*inv(outside[j]-roots[i],q)*id,q);weight[i*M+j]=w;A[j]=mod(A[j]+(int64_t)vals[i]*w,q);}\n }\n vector<uint16_t> changes((size_t)k*q*M);\n for(int i=0;i<k;++i)for(int d=0;d<q;++d)for(int j=0;j<M;++j)changes[((size_t)i*q+d)*M+j]=mod(d*weight[i*M+j],q);\n vector<uint64_t> lookup((size_t)M*q*W,0);\n for(int j=0;j<M;++j){int ib=inv(B[j],q);for(int a=0;a<q;++a)for(int v:target[outside[j]-1]){int t=mod((int64_t)(v-a)*ib,q);lookup[((size_t)j*q+a)*W+t/64]|=1ULL<<(t%64);}}\n ++bases;vector<uint64_t> planes((size_t)L*W),eligible(W),trial(W);uint64_t lastmask=q%64?(1ULL<<(q%64))-1:~0ULL;\n for(uint64_t step=0;step<lines_per_basis;++step){\n if((step&4095)==0&&chrono::duration<double>(chrono::steady_clock::now()-start).count()>=seconds)break;\n if(step){int i=rng()%k;const auto&tv=target[roots[i]-1];int nv=tv[rng()%tv.size()];int d=mod(nv-vals[i],q);vals[i]=nv;\n const uint16_t* change=&changes[((size_t)i*q+d)*M];for(int j=0;j<M;++j){int a=A[j]+change[j];A[j]=a>=q?a-q:a;}\n }\n fill(planes.begin(),planes.end(),0);\n for(int j=0;j<M;++j){const uint64_t* mask=&lookup[((size_t)j*q+A[j])*W];\n for(int w=0;w<W;++w){uint64_t carry=mask[w];for(int b=0;carry&&b<L;++b){uint64_t prev=planes[b*W+w];planes[b*W+w]=prev^carry;carry&=prev;}}\n }\n fill(eligible.begin(),eligible.end(),~0ULL);eligible.back()=lastmask;int value=0;\n for(int b=L-1;b>=0;--b){uint64_t any=0;for(int w=0;w<W;++w){trial[w]=eligible[w]&planes[b*W+w];any|=trial[w];}if(any){value|=1<<b;eligible=trial;}}\n ++lines;candidates+=q;\n if(value+k>best){int t=-1;for(int w=0;w<W&&t<0;++w)if(eligible[w])t=w*64+__builtin_ctzll(eligible[w]);\n auto c=polynomial(roots,vals,t,q);int score=0;for(int y=1;y<q;++y){int z=0;for(int i=n-1;i>=0;--i)z=mod((int64_t)z*y+c[i],q);score+=hit[y-1][z];}\n if(score!=value+k)throw runtime_error("independent Horner score mismatch");best=score;bestc=c;ofstream out(argv[4]);out<<"{\\"coeffs\\":[";for(int i=0;i<n;++i)out<<(i?",":"")<<c[i];out<<"]}\\n";out.close();\n cerr<<"best="<<best<<" lines="<<lines<<" candidates="<<candidates<<" bases="<<bases<<" elapsed_s="<<chrono::duration<double>(chrono::steady_clock::now()-start).count()<<"\\n";\n }\n if(best==m)break;\n }\n if(best==m)break;\n }\n cout<<"{\\"seed\\":"<<seed<<",\\"satisfied\\":"<<best<<",\\"lines\\":"<<lines<<",\\"candidates\\":"<<candidates<<",\\"bases\\":"<<bases<<",\\"cpu_seconds\\":"<<double(clock()-cpu_start)/CLOCKS_PER_SEC<<",\\"elapsed_seconds\\":"<<chrono::duration<double>(chrono::steady_clock::now()-start).count()<<"}\\n";\n}\n'
FIXED_TRIAL_CPP='// Original implementation of interpolation (Prange) on an affine line.\n// Algorithm provenance: Jordan et al., arXiv:2408.08292, and Khattar et al.,\n// arXiv:2510.10967 Section III.1 (CC BY 4.0). No third-party code is copied.\n// MIT license for this implementation; see README.md.\n#include <algorithm>\n#include <chrono>\n#include <cstdint>\n#include <ctime>\n#include <fstream>\n#include <iostream>\n#include <numeric>\n#include <random>\n#include <stdexcept>\n#include <string>\n#include <vector>\nusing namespace std;\n\nstatic int mod(int64_t x,int q){x%=q;return x<0?x+q:x;}\nstatic int inv(int x,int q){int a=q,b=mod(x,q),u=0,v=1;while(b){int t=a/b;int r=a-t*b;a=b;b=r;r=u-t*v;u=v;v=r;}if(a!=1)throw runtime_error("nonunit");return mod(u,q);}\nstatic vector<int> multiply_root(const vector<int>& p,int x,int q){vector<int> z(p.size()+1);for(size_t i=0;i<p.size();++i){z[i]=mod(z[i]-(int64_t)x*p[i],q);z[i+1]=mod(z[i+1]+p[i],q);}return z;}\nstatic vector<int> polynomial(const vector<int>& roots,const vector<int>& vals,int t,int q){\n vector<int> b{1};for(int x:roots)b=multiply_root(b,x,q);\n vector<int> c(b.size());for(size_t k=0;k<c.size();++k)c[k]=mod((int64_t)t*b[k],q);\n for(size_t i=0;i<roots.size();++i){\n int x=roots[i],d=1;for(size_t j=0;j<roots.size();++j)if(i!=j)d=mod((int64_t)d*(x-roots[j]),q);\n int w=mod((int64_t)vals[i]*inv(d,q),q);vector<int> z(roots.size());z.back()=b.back();\n for(int k=(int)z.size()-2;k>=0;--k)z[k]=mod(b[k+1]+(int64_t)x*z[k+1],q);\n for(size_t k=0;k<z.size();++k)c[k]=mod(c[k]+(int64_t)w*z[k],q);\n }return c;\n}\n\nint main(int argc,char**argv){\n if(argc!=6){cerr<<"usage: prange_line TARGETS.txt SEED SECONDS OUTPUT.json LINES_PER_BASIS\\n";return 2;}\n ifstream f(argv[1]);int q,n;f>>q>>n;if(!f||q>257||n<2||n>=q-1)throw runtime_error("supported pilot: prime q<=257 and 2<=n<q-1");\n int m=q-1,k=n-1,W=(q+63)/64,L=0;while((1<<L)<=m)++L;\n vector<vector<int>> target(m);vector<vector<uint8_t>> hit(m,vector<uint8_t>(q));\n for(int j=0;j<m;++j){int r;f>>r;while(r--){int x;f>>x;target[j].push_back(x);hit[j][x]=1;}}if(!f)throw runtime_error("bad targets input");\n uint64_t seed=stoull(argv[2]),lines_per_basis=stoull(argv[5]),lines=0,candidates=0;uint64_t replay_limit=stoull(argv[3]);mt19937_64 rng(seed);\n auto start=chrono::steady_clock::now();clock_t cpu_start=clock();int best=-1;vector<int> bestc;uint64_t bases=0;\n while(lines<replay_limit){\n vector<int> order(m);iota(order.begin(),order.end(),1);shuffle(order.begin(),order.end(),rng);\n vector<int> roots(order.begin(),order.begin()+k),outside(order.begin()+k,order.end()),vals(k);\n const int M=outside.size();vector<int> B(M,1),A(M,0),weight(k*M);\n for(int j=0;j<M;++j)for(int x:roots)B[j]=mod((int64_t)B[j]*(outside[j]-x),q);\n for(int i=0;i<k;++i){int d=1;for(int u=0;u<k;++u)if(i!=u)d=mod((int64_t)d*(roots[i]-roots[u]),q);int id=inv(d,q);vals[i]=target[roots[i]-1][rng()%target[roots[i]-1].size()];\n for(int j=0;j<M;++j){int w=mod((int64_t)B[j]*inv(outside[j]-roots[i],q)*id,q);weight[i*M+j]=w;A[j]=mod(A[j]+(int64_t)vals[i]*w,q);}\n }\n vector<uint16_t> changes((size_t)k*q*M);\n for(int i=0;i<k;++i)for(int d=0;d<q;++d)for(int j=0;j<M;++j)changes[((size_t)i*q+d)*M+j]=mod(d*weight[i*M+j],q);\n vector<uint64_t> lookup((size_t)M*q*W,0);\n for(int j=0;j<M;++j){int ib=inv(B[j],q);for(int a=0;a<q;++a)for(int v:target[outside[j]-1]){int t=mod((int64_t)(v-a)*ib,q);lookup[((size_t)j*q+a)*W+t/64]|=1ULL<<(t%64);}}\n ++bases;vector<uint64_t> planes((size_t)L*W),eligible(W),trial(W);uint64_t lastmask=q%64?(1ULL<<(q%64))-1:~0ULL;\n for(uint64_t step=0;step<lines_per_basis;++step){\n if(lines>=replay_limit)break;\n if(step){int i=rng()%k;const auto&tv=target[roots[i]-1];int nv=tv[rng()%tv.size()];int d=mod(nv-vals[i],q);vals[i]=nv;\n const uint16_t* change=&changes[((size_t)i*q+d)*M];for(int j=0;j<M;++j){int a=A[j]+change[j];A[j]=a>=q?a-q:a;}\n }\n fill(planes.begin(),planes.end(),0);\n for(int j=0;j<M;++j){const uint64_t* mask=&lookup[((size_t)j*q+A[j])*W];\n for(int w=0;w<W;++w){uint64_t carry=mask[w];for(int b=0;carry&&b<L;++b){uint64_t prev=planes[b*W+w];planes[b*W+w]=prev^carry;carry&=prev;}}\n }\n fill(eligible.begin(),eligible.end(),~0ULL);eligible.back()=lastmask;int value=0;\n for(int b=L-1;b>=0;--b){uint64_t any=0;for(int w=0;w<W;++w){trial[w]=eligible[w]&planes[b*W+w];any|=trial[w];}if(any){value|=1<<b;eligible=trial;}}\n ++lines;candidates+=q;\n if(value+k>best){int t=-1;for(int w=0;w<W&&t<0;++w)if(eligible[w])t=w*64+__builtin_ctzll(eligible[w]);\n auto c=polynomial(roots,vals,t,q);int score=0;for(int y=1;y<q;++y){int z=0;for(int i=n-1;i>=0;--i)z=mod((int64_t)z*y+c[i],q);score+=hit[y-1][z];}\n if(score!=value+k)throw runtime_error("independent Horner score mismatch");best=score;bestc=c;ofstream out(argv[4]);out<<"{\\"coeffs\\":[";for(int i=0;i<n;++i)out<<(i?",":"")<<c[i];out<<"]}\\n";out.close();\n cerr<<"best="<<best<<" lines="<<lines<<" candidates="<<candidates<<" bases="<<bases<<" elapsed_s="<<chrono::duration<double>(chrono::steady_clock::now()-start).count()<<"\\n";\n }\n if(best==m)break;\n }\n if(best==m)break;\n }\n cout<<"{\\"seed\\":"<<seed<<",\\"satisfied\\":"<<best<<",\\"lines\\":"<<lines<<",\\"candidates\\":"<<candidates<<",\\"bases\\":"<<bases<<",\\"cpu_seconds\\":"<<double(clock()-cpu_start)/CLOCKS_PER_SEC<<",\\"elapsed_seconds\\":"<<chrono::duration<double>(chrono::steady_clock::now()-start).count()<<"}\\n";\n}\n'
def main():
if len(sys.argv)>1 and sys.argv[1]=='--metadata':
print(json.dumps(RECIPE,indent=2))
return
output=Path(sys.argv[1] if len(sys.argv)>1 else 'candidate.json').resolve()
output.parent.mkdir(parents=True,exist_ok=True)
tmp_root=Path(os.environ.get('TMPDIR',str(Path.cwd()/'.opi_replay_tmp')))
tmp_root.mkdir(parents=True,exist_ok=True)
for name in ['OPENBLAS_NUM_THREADS','OMP_NUM_THREADS','MKL_NUM_THREADS']:
os.environ[name]='1'
with tempfile.TemporaryDirectory(prefix='opi-replay-',dir=tmp_root) as tmp:
work=Path(tmp)
(work/'search.cpp').write_text(FIXED_TRIAL_CPP)
table=work/'targets.txt'
with table.open('w') as f:
if INSTANCE['field']=='prime':
f.write(f"{INSTANCE['q']} {INSTANCE['n']}\n")
for mask in INSTANCE['targets']:
bits=int(mask,16)
values=[v for v in range(INSTANCE['q']) if bits>>v&1]
f.write(str(len(values))+' '+' '.join(map(str,values))+'\n')
else:
f.write(f"{INSTANCE['b']} {INSTANCE['n']} {INSTANCE['modulus']}\n")
for rows in INSTANCE['matrices']:
f.write(' '.join(map(str,rows))+'\n')
compiler=shutil.which('g++')
if not compiler:
raise RuntimeError('g++ with C++17 support is required')
subprocess.run([compiler,'-std=c++17','-O3','-march=native',str(work/'search.cpp'),'-o',str(work/'search')],check=True)
print(json.dumps({'recipe':RECIPE,'compiler':subprocess.check_output([compiler,'--version'],text=True).splitlines()[0]}),flush=True)
subprocess.run([str(work/'search'),str(table),str(RECIPE['seed']),str(RECIPE['replay_count']),str(output),RECIPE['tail_argument']],check=True)
observed=hashlib.sha256(output.read_bytes()).hexdigest()
if observed!=RECIPE['expected_artifact_sha256']:
raise RuntimeError(f"Replay hash differs: expected {RECIPE['expected_artifact_sha256']}, got {observed}. Check libstdc++ std::shuffle/compiler version.")
print(json.dumps({'output':str(output),'sha256':observed,'reproduced':True}))
if __name__=='__main__':
main()