All MicroEvals
/** * Per-candidate analysis: the exact verification pipeli...
Create MicroEval

/** * Per-candidate analysis: the exact verification pipeli...

Prompt

/** * Per-candidate analysis: the exact verification pipeline that every map is * pushed through. A candidate is only reported as a counterexample when all * of the following hold: * * 1. det J(F) == 1 as a coefficient-wise identity in C[x,y]; * 2. two distinct points P1 != P2 with F(P1) == F(P2) are exhibited and * evaluated exactly; * 3. no polynomial inverse exists inside the degree bound (an inverse would * contradict non-injectivity). * * Everything printed by the engine comes from this file or from the layers * below it; no result is asserted without an exact check. */ import { Cx, cxF, cxToString } from "./gauss"; import { P2 } from "./poly2"; import { Collision, FiberReport, InjectivityCase, collisionGridSearch, detJacobianIsOne, evalMap, fiberOver, findPolynomialInverse, gaussianGrid, injectivityCertificate, jacobianDet, pointsDiffer, pointString, valueString, } from "./analyze"; export interface CandidateReportLike { label: string; source: string; F1: string; F2: string; degrees: [number, number]; terms: [number, number]; det: string; detIsOne: boolean; offending: string[]; inverseFound: boolean; inverseDegree: number; inverseG1: string | null; inverseG2: string | null; inverseVerified: boolean; composeCheck1: string; composeCheck2: string; composeCheck3: string; composeCheck4: string; collisions: string[]; collisionPairs: Array<{ P1: string; P2: string; value: string }>; fibers: FiberReport[]; injectivity: InjectivityCase[]; certifiedInjective: boolean; notes: string[]; } export interface CandidateConfig { inverseDegreeBound: number; gridRadius: number; gridDenominators: number[]; deepGridRadius: number; groebnerBudget: number; } /** the exact points at which fibres are computed */ function fiberTargets(): Array<[Cx, Cx]> { return [ [cxF(0), cxF(0)], [cxF(1), cxF(1)], [cxF(2), { re: { n: 1n, d: 2n }, im: { n: 0n, d: 1n } }], ]; } export function analyzeCandidate( F1: P2, F2: P2, label: string, source: string, cfg: CandidateConfig, runInjectivity = true, ): CandidateReportLike { const notes: string[] = []; const detCheck = detJacobianIsOne(F1, F2); const det = jacobianDet(F1, F2); /* ---- inverse search ---- */ const inv = findPolynomialInverse(F1, F2, cfg.inverseDegreeBound); let composeCheck1 = "n/a"; let composeCheck2 = "n/a"; let composeCheck3 = "n/a"; let composeCheck4 = "n/a"; if (inv.found && inv.G1 !== null && inv.G2 !== null) { const c1 = inv.G1.compose(F1, F2).sub(P2.varX()); const c2 = inv.G2.compose(F1, F2).sub(P2.varY()); const c3 = F1.compose(inv.G1, inv.G2).sub(P2.varX()); const c4 = F2.compose(inv.G1, inv.G2).sub(P2.varY()); composeCheck1 = c1.isZero() ? "0" : c1.toString(); composeCheck2 = c2.isZero() ? "0" : c2.toString(); composeCheck3 = c3.isZero() ? "0" : c3.toString(); composeCheck4 = c4.isZero() ? "0" : c4.toString(); if (inv.leftVerified && inv.rightVerified) { notes.push( `two-sided polynomial inverse found in degree ${inv.degree}: injectivity is forced, no collision can exist`, ); } } else { notes.push(`no polynomial inverse of degree <= ${cfg.inverseDegreeBound} was found`); } /* ---- collision search ---- */ let grid = gaussianGrid(cfg.gridRadius, cfg.gridDenominators); let collisions: Collision[] = collisionGridSearch(F1, F2, grid, 4); if (collisions.length === 0 && !inv.found && detCheck.isOne) { grid = gaussianGrid(cfg.deepGridRadius, [1, 2]); collisions = collisionGridSearch(F1, F2, grid, 4); notes.push(`deep exact grid used (radius ${cfg.deepGridRadius}, denominators {1,2})`); } const collisionPairs = collisions.map((c) => ({ P1: pointString(c.P1), P2: pointString(c.P2), value: valueString(c.value), })); const collisionLines: string[] = []; for (const c of collisions) { const same = pointsDiffer(c.P1, c.P2) ? "P1 != P2" : "P1 == P2 (!)"; const v1 = evalMap(F1, F2, c.P1); const v2 = evalMap(F1, F2, c.P2); const equal = (v1[0] === v2[0] || v1[0].re.n === v2[0].re.n) ? true : true; void equal; const exact = sameExact(v1[0], v2[0]) && sameExact(v1[1], v2[1]) && pointsDiffer(c.P1, c.P2); collisionLines.push( `F(${pointString(c.P1)}) = ${valueString(v1)} and F(${pointString(c.P2)}) = ${valueString(v2)} [${same}, values equal: ${exact ? "TRUE" : "FALSE"}]`, ); } /* ---- fibres ---- */ const fibers: FiberReport[] = []; for (const c of fiberTargets()) { try { fibers.push(fiberOver(F1, F2, c, gaussianGrid(3, [1]))); } catch (err) { notes.push(`fibre computation over (${cxToString(c[0])}, ${cxToString(c[1])}) failed: ${(err as Error).message}`); } } /* ---- injectivity certificate ---- */ // A two-sided polynomial inverse already proves injectivity, so the // (expensive) Groebner certificate is only computed when it adds information, // or on small maps where it doubles as a validation of the certificate code. const needsCertificate = runInjectivity && detCheck.isOne && (!inv.found || (F1.degree() <= 2 && F2.degree() <= 2)); let injectivity: InjectivityCase[] = []; let certifiedInjective = false; if (needsCertificate) { try { const rep = injectivityCertificate(F1, F2, cfg.groebnerBudget); injectivity = rep.cases; certifiedInjective = rep.certifiedInjective; if (certifiedInjective) { notes.push("Groebner injectivity certificate: both Rabinowitsch systems reduce to the unit ideal"); } } catch (err) { notes.push(`injectivity certificate raised: ${(err as Error).message}`); } } return { label, source, F1: F1.toString(), F2: F2.toString(), degrees: [F1.degree(), F2.degree()], terms: [F1.size(), F2.size()], det: det.toString(), detIsOne: detCheck.isOne, offending: detCheck.offending.map((o) => `${o.coeff}*${o.mono}`), inverseFound: inv.found, inverseDegree: inv.degree, inverseG1: inv.G1 === null ? null : inv.G1.toString(), inverseG2: inv.G2 === null ? null : inv.G2.toString(), inverseVerified: inv.leftVerified && inv.rightVerified, composeCheck1, composeCheck2, composeCheck3, composeCheck4, collisions: collisionLines, collisionPairs, fibers, injectivity, certifiedInjective, notes, }; } function sameExact(a: Cx, b: Cx): boolean { return a.re.n === b.re.n && a.re.d === b.re.d && a.im.n === b.im.n && a.im.d === b.im.d; } export { gaussianGrid }; export type { FiberReport }; List every single error in this code! In your reply, just list the things I’m looking for one after another, without including anything else.