#!/usr/bin/env python3
"""verify_P025.py -- Paper 25: Hodge conjecture reduction framework."""

from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent))
class Verifier:
    """Output shim: identical tolerance semantics to verify_common.Verifier,
    modern [PASS]/[FAIL] check-line output format."""

    def __init__(self, name):
        self.PASS = 0
        self.FAIL = 0
        self.n = 0
        print(name)

    def _mark(self, ok, desc):
        self.n += 1
        if ok:
            self.PASS += 1
        else:
            self.FAIL += 1
        print(f"  [{'PASS' if ok else 'FAIL'}] {self.n:>2}. {desc}")

    def check(self, label, computed, claimed, *, rel=1e-3, abs_tol=None, detail=""):
        if abs_tol is not None:
            ok = abs(computed - claimed) <= abs_tol
            err_detail = f"abs err={abs(computed - claimed):.6g}, tol={abs_tol:.6g}"
        else:
            if claimed == 0:
                ok = abs(computed) <= (rel or 1e-12)
                err_detail = f"abs value={abs(computed):.6g}, tol={rel:.6g}"
            else:
                err = (computed - claimed) / abs(claimed)
                ok = abs(err) <= (rel or 0)
                err_detail = f"rel err={100 * err:+.6g}%, tol={100 * (rel or 0):.6g}%"
        self._mark(ok, label + (f" -- {detail}" if detail else ""))
        print(f"        computed: {computed}   claimed: {claimed}   ({err_detail})")
        return ok

    def record(self, label, ok, computed="", claimed="", detail=""):
        ok = bool(ok)
        self._mark(ok, label + (f" -- {detail}" if detail else ""))
        if computed != "" or claimed != "":
            print(f"        computed: {computed}   claimed: {claimed}")
        return ok

    def summary(self):
        print(f"\n{'='*60}\nRESULT: {self.PASS} PASS / {self.FAIL} FAIL")
        return 0 if self.FAIL == 0 else 1


v = Verifier("P025 -- Hodge Conjecture")
ROOT = Path(__file__).resolve().parents[2]
TEX = (ROOT / "toe" / "25_Paper_HodgeConjecture.tex").read_text()

v.record("TeX source is present", "Hodge Conjecture" in TEX)
v.record("Lefschetz (1,1) background is standard", True)
v.record("Hard Lefschetz background is standard", True)
v.record("primitive decomposition background is standard", True)
v.record("surface case is standard", True, computed="codim 1 by Lefschetz (1,1), top class by points")
v.record("threefold case is standard", True, computed="codim 2 dual to divisors via hard Lefschetz/Poincare duality")
v.record("first genuinely open general case is fourfold middle H^{2,2}", True)
v.record("paper identifies middle-dimensional obstruction", "first non-trivial case" in TEX and "Fourfolds" in TEX)

v.record(
    "GSP annihilator argument proves W=V directly",
    False,
    computed="W^perp=0 against complementary algebraic cycles shows algebraic complementary classes separate V; it does not by itself identify every class in V with an algebraic p-cycle without a dual algebraicity/dimension argument",
    claimed="If GSP holds, W^perp=0, hence W=V",
    detail="Expected linear-algebra gap.",
)
v.record(
    "non-middle GSP is proved unconditionally",
    False,
    computed="the proof uses induction assuming Hodge in complementary lower codimension; for general codimension this is essentially the conjectural content being reduced",
    claimed="GSP holds for p != n/2",
    detail="Expected circularity/reduction gap.",
)
v.record(
    "Hodge-Riemann positivity implies every nonzero rational Hodge class pairs with an effective algebraic cycle",
    False,
    computed="positivity is for the Lefschetz form, not a guarantee of nonzero pairing with an existing algebraic cycle",
    claimed="positive energy must be grounded in edge algebraic support",
    detail="Expected interpretation gap.",
)
v.record(
    "effective cone is closed as stated",
    False,
    computed="the cone generated by effective cycles need not be closed; its closure is usually the pseudo-effective cone",
    claimed="Eff^p(X) is a closed convex cone",
    detail="Expected cone-geometry fail.",
)
v.record(
    "dual-cone span proposition is established",
    False,
    computed="Eff^vee - Eff^vee is the linear span of the dual cone, not automatically Alg^perp; no proof of the stated identification is supplied",
    claimed="Eff^(n/2)^vee - Eff^(n/2)^vee spans Alg^(n/2)^perp",
    detail="Expected cone-duality fail.",
)
v.record(
    "cone-theoretic characterization is equivalent to Hodge",
    False,
    computed="the proof assumes rational classes with positive Hodge-Riemann norm lie in interiors of effective-dual cones, which is not shown",
    claimed="GSP middle dimension equivalent to stated cone interior condition",
    detail="Expected proof gap.",
)
v.record(
    "Chow/projectivity rules out non-algebraic Hodge classes",
    False,
    computed="Chow says analytic subvarieties of projective space are algebraic; it does not imply every rational Hodge class has an analytic representative subvariety",
    claimed="projective constraint suggests ungrounded classes cannot exist",
    detail="Expected overstatement.",
)

sys.exit(v.summary())
