{"challengeId":"matmul-rank-3x3","entry":"verifier.mjs","sha256":"2c7a8e7064289394d3774676dbd8cfa722e6b95c17be0ebbf4a369c2e835d0fc","scoreDirection":"minimize","scoreLabel":"multiplications (rank R)","seedPolicy":{"mode":"fixed","testCount":1},"source":"// Frozen verifier for matmul-rank-3x3. Self-contained (no imports): it interprets\n// the candidate's bilinear-scheme artifact and returns a Verdict. It never executes\n// agent code — build() already ran in the sandbox and handed us plain data. This\n// file is part of the challenge's PROTECTED surface.\n//\n// Fixed instance: 3x3 matrix multiply over the integers Z, with every scheme\n// coefficient a small integer (|coeff| <= 64). A bilinear scheme of rank R computes\n//   m_r = (u_r . vecX) * (v_r . vecY)        for r in 0..R-1   (one multiplication)\n//   out_c = sum_r w_r[c] * m_r\n// where vecX and vecY are the nine entries of the two 3x3 inputs flattened\n// row-major (slot a = i*3+k holds X[i][k]; slot b = k*3+j holds Y[k][j]) and the\n// nine outputs out_c (c = i*3+j) are the entries of the 3x3 product:\n//   out_{i,j} = sum_k X[i][k] * Y[k][j].\n//\n// Correctness is an EXACT tensor identity over the integers. The bilinear map a\n// scheme computes has coefficient, on monomial X_a * Y_b in output c,\n//   S[a][b][c] = sum_r u_r[a] * v_r[b] * w_r[c].\n// The 3x3 matmul tensor T[a][b][c] is 1 exactly on the (a,b,c) triples where\n// a=(i,k), b=(k,j), c=(i,j) share i,j,k, and 0 otherwise. We recompute all\n// 9*9*9 = 729 coefficients with integer arithmetic and require S === T everywhere.\n// This is a total proof over the finitely many monomials — nothing to sample —\n// so seedPolicy.mode is \"fixed\".\n\nconst N = 3; // matrix order\nconst D = N * N; // 9 inputs per matrix, 9 outputs\nconst MAX_RANK = 64; // generous cap; the naive scheme is 27, Laderman is 23\nconst MAX_COEFF = 64; // bound on |coefficient|\n\nfunction gate(name, pass, detail) {\n  return { name, pass, detail };\n}\nfunction bad(name, detail) {\n  return { ok: false, score: null, gates: [gate(name, false, detail)], behavior: {}, logs: [] };\n}\n\n// The 3x3 matrix-multiplication tensor as a dense 9x9x9 array of {0,1}.\nfunction targetTensor() {\n  const T = Array.from({ length: D }, () => Array.from({ length: D }, () => new Array(D).fill(0)));\n  for (let i = 0; i < N; i++) {\n    for (let j = 0; j < N; j++) {\n      const c = i * N + j; // output slot (row i, col j)\n      for (let k = 0; k < N; k++) {\n        const a = i * N + k; // x_{i,k}\n        const b = k * N + j; // y_{k,j}\n        T[a][b][c] = 1;\n      }\n    }\n  }\n  return T;\n}\n\nfunction isCoeffVec(vec, len) {\n  if (!Array.isArray(vec) || vec.length !== len) return false;\n  for (const v of vec) {\n    if (!Number.isInteger(v) || v < -MAX_COEFF || v > MAX_COEFF) return false;\n  }\n  return true;\n}\n\nexport function verify(ctx) {\n  const sol = ctx.solution;\n  if (!sol || typeof sol !== 'object') {\n    return bad('structure', 'expected { rank, factors }');\n  }\n  const { rank, factors } = sol;\n  if (!Number.isInteger(rank) || rank < 1 || rank > MAX_RANK) {\n    return bad('structure', `rank must be an integer in 1..${MAX_RANK}`);\n  }\n  if (!Array.isArray(factors) || factors.length !== rank) {\n    return bad('structure', `factors must be an array of ${rank} terms`);\n  }\n  for (let r = 0; r < rank; r++) {\n    const f = factors[r];\n    if (!f || typeof f !== 'object') return bad('structure', `factors[${r}] must be { u, v, w }`);\n    if (!isCoeffVec(f.u, D)) return bad('structure', `factors[${r}].u must be ${D} integers with |coeff|<=${MAX_COEFF}`);\n    if (!isCoeffVec(f.v, D)) return bad('structure', `factors[${r}].v must be ${D} integers with |coeff|<=${MAX_COEFF}`);\n    if (!isCoeffVec(f.w, D)) return bad('structure', `factors[${r}].w must be ${D} integers with |coeff|<=${MAX_COEFF}`);\n  }\n\n  // Recompute the bilinear coefficient tensor S and compare to the target T.\n  const T = targetTensor();\n  let mismatch = '';\n  for (let a = 0; a < D && !mismatch; a++) {\n    for (let b = 0; b < D && !mismatch; b++) {\n      for (let c = 0; c < D && !mismatch; c++) {\n        let s = 0;\n        for (let r = 0; r < rank; r++) {\n          s += factors[r].u[a] * factors[r].v[b] * factors[r].w[c];\n        }\n        if (s !== T[a][b][c]) {\n          mismatch = `monomial X${a}*Y${b} in output ${c}: scheme gives ${s}, want ${T[a][b][c]}`;\n        }\n      }\n    }\n  }\n\n  const computesMatmul = !mismatch;\n  const gates = [\n    gate(\n      'computes-3x3-matmul',\n      computesMatmul,\n      mismatch || `all ${D * D * D} tensor coefficients match the 3x3 matmul map`,\n    ),\n  ];\n  const ok = gates.every((g) => g.pass);\n  return {\n    ok,\n    score: ok ? rank : null,\n    gates,\n    behavior: { rank },\n    logs: [`rank=${rank} integer coefficients with |coeff|<=${MAX_COEFF}`],\n  };\n}\n"}