import { Cx, cxF, cxToString } from "./gauss"; import { P2 }...
Prompt
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[]; groebnerCertified: boolean; certifiedInjective: boolean; hasContradiction: boolean; isCounterexample: boolean; notes: string[]; } export interface CandidateConfig { inverseDegreeBound: number; gridRadius: number; gridDenominators: number[]; deepGridRadius: number; groebnerBudget: number; } function gcdBigInt(a: bigint, b: bigint): bigint { let x = a < 0n ? -a : a; let y = b < 0n ? -b : b; while (y !== 0n) { const t = x % y; x = y; y = t; } return x === 0n ? 1n : x; } function canonicalRatKey(n: bigint, d: bigint): string { if (d === 0n) { return `${n}/0`; } let num = n; let den = d; if (den < 0n) { num = -num; den = -den; } const g = gcdBigInt(num, den); return `${num / g}/${den / g}`; } function canonicalPointKey(p: [Cx, Cx]): string { return `(${canonicalRatKey(p[0].re.n, p[0].re.d)}+${canonicalRatKey(p[0].im.n, p[0].im.d)}i,${canonicalRatKey(p[1].re.n, p[1].re.d)}+${canonicalRatKey(p[1].im.n, p[1].im.d)}i)`; } function sameExact(a: Cx, b: Cx): boolean { if (a.re.d === 0n || b.re.d === 0n || a.im.d === 0n || b.im.d === 0n) { return false; } return ( a.re.n * b.re.d === b.re.n * a.re.d && a.im.n * b.im.d === b.im.d * a.im.n ); } function pointsEqual(p1: [Cx, Cx], p2: [Cx, Cx]): boolean { return sameExact(p1[0], p2[0]) && sameExact(p1[1], p2[1]); } function toErrorMessage(err: unknown): string { if (err instanceof Error) { return err.message; } if (typeof err === "string") { return err; } if (err === null) { return "null"; } if (err === undefined) { return "undefined"; } try { const s = JSON.stringify(err); return typeof s === "string" ? s : String(err); } catch { return String(err); } } 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 } }], ]; } interface VerifiedCollisionRecord { P1: [Cx, Cx]; P2: [Cx, Cx]; v1: [Cx, Cx]; v2: [Cx, Cx]; } export function analyzeCandidate( F1: P2, F2: P2, label: string, source: string, cfg: CandidateConfig, runInjectivity = true, ): CandidateReportLike { const notes: string[] = []; const det = jacobianDet(F1, F2); const detCheck = detJacobianIsOne(F1, F2); let detIsOne = detCheck.isOne; const detStr = det.toString(); if (detIsOne && detStr !== "1") { notes.push( `DISCREPANCY: detJacobianIsOne reported true, but jacobianDet stringified to "${detStr}"`, ); detIsOne = false; } else if (!detIsOne && detStr === "1") { notes.push( `DISCREPANCY: detJacobianIsOne reported false, but jacobianDet stringified to "1"`, ); } const offending = detCheck.offending.map( (o) => `${cxToString(o.coeff)}*${o.mono}`, ); const maxMapDegree = Math.max(F1.degree(), F2.degree()); const degreeBoundSufficient = cfg.inverseDegreeBound >= maxMapDegree; if (!degreeBoundSufficient) { notes.push( `inverse search bound (${cfg.inverseDegreeBound}) is strictly less than max map degree (${maxMapDegree}); search is non-exhaustive under Bass-Connell-Wright theorem`, ); } const inv = findPolynomialInverse(F1, F2, cfg.inverseDegreeBound); let composeCheck1 = "n/a"; let composeCheck2 = "n/a"; let composeCheck3 = "n/a"; let composeCheck4 = "n/a"; let inverseVerified = false; let inverseFound = false; if (inv.found) { if (inv.G1 !== null && inv.G2 !== null) { inverseFound = true; 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 (c1.isZero() && c2.isZero() && c3.isZero() && c4.isZero()) { inverseVerified = true; notes.push( `two-sided polynomial inverse verified in degree ${inv.degree}: injectivity is forced, no collision can exist`, ); } else { notes.push( `inverse candidate found in degree ${inv.degree} but failed independent residual check`, ); } } else { notes.push( "inconsistent inverse result: findPolynomialInverse returned found=true but G1/G2 is null", ); } } else { notes.push( `no polynomial inverse of degree <= ${cfg.inverseDegreeBound} was found`, ); } const verifiedCollisions: VerifiedCollisionRecord[] = []; const collisionLines: string[] = []; const seenPairKeys = new Set<string>(); function processCandidates(candidates: Collision[]): void { for (const c of candidates) { const isDistinct = !pointsEqual(c.P1, c.P2); const reportedDiffer = pointsDiffer(c.P1, c.P2); if (reportedDiffer !== isDistinct) { notes.push( `DISCREPANCY: pointsDiffer returned ${reportedDiffer} but exact rational equality returned ${!isDistinct} for ${pointString(c.P1)} and ${pointString(c.P2)}`, ); } const pointDiffLabel = isDistinct ? "P1 != P2" : "P1 == P2 (!)"; const v1 = evalMap(F1, F2, c.P1); const v2 = evalMap(F1, F2, c.P2); const valuesMatch = sameExact(v1[0], v2[0]) && sameExact(v1[1], v2[1]); collisionLines.push( `F(${pointString(c.P1)}) = ${valueString(v1)} and F(${pointString(c.P2)}) = ${valueString(v2)} [${pointDiffLabel}, values equal: ${valuesMatch ? "TRUE" : "FALSE"}]`, ); if (isDistinct && valuesMatch) { const k1 = canonicalPointKey(c.P1); const k2 = canonicalPointKey(c.P2); const canonicalKey = k1 < k2 ? `${k1}|${k2}` : `${k2}|${k1}`; if (!seenPairKeys.has(canonicalKey)) { seenPairKeys.add(canonicalKey); verifiedCollisions.push({ P1: c.P1, P2: c.P2, v1, v2, }); } } } } const initialGrid = gaussianGrid(cfg.gridRadius, cfg.gridDenominators); const initialCollisions = collisionGridSearch(F1, F2, initialGrid, 4); processCandidates(initialCollisions); if (verifiedCollisions.length === 0 && !inverseVerified && detIsOne) { const deepDenominators = Array.from( new Set([...cfg.gridDenominators.filter((d) => d > 0 && Number.isInteger(d)), 1, 2]), ).sort((a, b) => a - b); const effectiveRadius = Math.max(cfg.deepGridRadius, cfg.gridRadius); const deepGrid = gaussianGrid(effectiveRadius, deepDenominators); const deepCollisions = collisionGridSearch(F1, F2, deepGrid, 4); notes.push( `deep exact grid used (radius ${effectiveRadius}, denominators {${deepDenominators.join(",")}})`, ); processCandidates(deepCollisions); } const collisionPairs = verifiedCollisions.map((vc) => ({ P1: pointString(vc.P1), P2: pointString(vc.P2), value: valueString(vc.v1), })); const fibers: FiberReport[] = []; const sharedFiberGrid = gaussianGrid(3, [1]); for (const target of fiberTargets()) { try { fibers.push(fiberOver(F1, F2, target, sharedFiberGrid)); } catch (err) { notes.push( `fibre computation over (${cxToString(target[0])}, ${cxToString(target[1])}) failed: ${toErrorMessage(err)}`, ); } } let injectivity: InjectivityCase[] = []; let groebnerCertified = false; if (verifiedCollisions.length > 0) { notes.push( "injectivity certificate skipped: verified collision already established", ); } else if (inverseVerified) { if (F1.degree() <= 2 && F2.degree() <= 2 && runInjectivity) { try { const rep = injectivityCertificate(F1, F2, cfg.groebnerBudget); injectivity = rep.cases; groebnerCertified = rep.certifiedInjective; if (!groebnerCertified) { notes.push( `DISCREPANCY: verified polynomial inverse exists, but Groebner certificate did not confirm injectivity within budget (${cfg.groebnerBudget})`, ); } else { notes.push( "Groebner injectivity certificate validated against known polynomial inverse", ); } } catch (err) { notes.push( `injectivity certificate validation raised: ${toErrorMessage(err)}`, ); } } } else if (runInjectivity && detIsOne) { try { const rep = injectivityCertificate(F1, F2, cfg.groebnerBudget); injectivity = rep.cases; groebnerCertified = rep.certifiedInjective; if (groebnerCertified) { notes.push( "Groebner injectivity certificate: both Rabinowitsch systems reduce to the unit ideal", ); } else { notes.push( `Groebner injectivity certificate was inconclusive or exceeded budget (${cfg.groebnerBudget})`, ); } } catch (err) { notes.push(`injectivity certificate raised: ${toErrorMessage(err)}`); } } const certifiedInjective = inverseVerified || groebnerCertified; const hasContradiction = verifiedCollisions.length > 0 && certifiedInjective; if (hasContradiction) { notes.push( "CRITICAL CONTRADICTION: verified collision coexists with verified injectivity proof", ); } const isCounterexample = detIsOne && verifiedCollisions.length > 0 && !inverseVerified && degreeBoundSufficient && !hasContradiction; if (isCounterexample) { notes.push( "COUNTEREXAMPLE VERIFIED: Jacobian det is 1, distinct points collide, and no polynomial inverse exists within the theoretical degree bound", ); } else if (detIsOne && verifiedCollisions.length > 0 && !degreeBoundSufficient) { notes.push( "CANDIDATE UNVERIFIED: verified collision found, but inverse degree bound is insufficient to rule out a polynomial inverse", ); } return { label, source, F1: F1.toString(), F2: F2.toString(), degrees: [F1.degree(), F2.degree()], terms: [F1.size(), F2.size()], det: detStr, detIsOne, offending, inverseFound, inverseDegree: inv.degree, inverseG1: inv.G1 === null ? null : inv.G1.toString(), inverseG2: inv.G2 === null ? null : inv.G2.toString(), inverseVerified, composeCheck1, composeCheck2, composeCheck3, composeCheck4, collisions: collisionLines, collisionPairs, fibers, injectivity, groebnerCertified, certifiedInjective, hasContradiction, isCounterexample, notes, }; } export { gaussianGrid }; export type { FiberReport }; read the full code. list every of any type error! just list the results, nothing else.