refactor(OracleComp): make OracleComp/OracleQuery reducible over PolyFun#490
refactor(OracleComp): make OracleComp/OracleQuery reducible over PolyFun#490dtumad wants to merge 3 commits into
OracleComp/OracleQuery reducible over PolyFun#490Conversation
…PolyFun Make `OracleComp`, `OracleQuery`, and `OracleSpec.toPFunctor` reducible aliases of their `PolyFun` counterparts and delete the bespoke `Monad`/`LawfulMonad`/`MonadLift`/`Functor` instances, so PolyFun's own instances and lemmas apply directly to oracle computations. Repair the resulting breakage: restate `Traversal` over `PFunctor.FreeM.Cursor`, re-key `toPFunctor_add` off the simp set, narrow ReplayFork's local transparency to `PFunctor.Idx`, route invariant-preservation proofs via `simulateQ_spec_query`, and align the `@[vcspec]`/`@[wpStep]` registry lookups with `Sym` pattern preprocessing via `symMatchKey`. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
🤖 PR SummaryArchitectural ThrustThis PR makes Mathematical FormalizationNo new theorems or definitions are added. The core change is structural. Core Change: Reducibility
Ripple FixesTraversal
ReplayFork
Invariant Preservation Proofs
Cosmetic / Minor
Infrastructure / CITactic Engine Fix (Key Alignment)
Dependency Update
Documentation
Proof Completion (sorries removed)No Statistics
Lean Declarations ✏️ Added: 1 declaration(s)
✏️ Affected: 5 declaration(s) (line number changed)
📋 **Additional Analysis**The pull request is largely compliant with the project's contribution guidelines. The main issue is missing declaration docstrings on several new lemmas in 📄 **Per-File Summaries**
Last updated: 2026-07-17 10:56 UTC. |
Build Timing Report
Incremental Rebuild Signal
This compares a clean project build against an incremental rebuild in the same CI job; it is a lightweight variability signal, not a full cross-run benchmark. Slowest Current Clean-Build FilesShowing 20 slowest current targets, with comparison against the selected baseline when available.
|
🤖 AI ReviewOverall Summary: Errors during review:
🔗 **Cross-File Analysis**Cross-file analysis failed: 400 INVALID_ARGUMENT. {'error': {'code': 400, 'message': 'API key not valid. Please pass a valid API key.', 'status': 'INVALID_ARGUMENT', 'details': [{'@type': 'type.googleapis.com/google.rpc.ErrorInfo', 'reason': 'API_KEY_INVALID', 'domain': 'googleapis.com', 'metadata': {'service': 'generativelanguage.googleapis.com'}}, {'@type': 'type.googleapis.com/google.rpc.LocalizedMessage', 'locale': 'en-US', 'message': 'API key not valid. Please pass a valid API key.'}]}} 📄 **Review for `Examples/PRGfromPRF.lean`**An error occurred while analyzing 📄 **Review for `VCVio/CryptoFoundations/FiatShamir/Sigma/Stateful/Compatibility.lean`**An error occurred while analyzing 📄 **Review for `VCVio/CryptoFoundations/ReplayFork.lean`**An error occurred while analyzing 📄 **Review for `VCVio/OracleComp/OracleComp.lean`**An error occurred while analyzing 📄 **Review for `VCVio/OracleComp/OracleQuery.lean`**An error occurred while analyzing 📄 **Review for `VCVio/OracleComp/OracleSpec.lean`**An error occurred while analyzing 📄 **Review for `VCVio/OracleComp/SimSemantics/StateT/PreservesInv.lean`**An error occurred while analyzing 📄 **Review for `VCVio/OracleComp/SimSemantics/WriterT/PreservesInv.lean`**An error occurred while analyzing 📄 **Review for `VCVio/OracleComp/Traversal.lean`**An error occurred while analyzing 📄 **Review for `VCVio/ProgramLogic/Tactics/Common/Core.lean`**An error occurred while analyzing 📄 **Review for `VCVio/ProgramLogic/Tactics/Common/Registry.lean`**An error occurred while analyzing 📄 **Review for `VCVio/ProgramLogic/Tactics/Common/WpStepRegistry.lean`**An error occurred while analyzing 📄 **Review for `VCVio/StateSeparating/CellRef.lean`**An error occurred while analyzing |
|
@quangvdao would be good to know if you see this as the right fix for mvcgen breakage |
* refactor(OracleComp): consume generic PolyFun traversal predicates * chore: pin merged PolyFun traversal API
Motivation
OracleCompandOracleQueryare definitionally the free monadPFunctor.FreeM spec.toPFunctorand the polynomial functorPFunctor.Obj spec.toPFunctor, but as semireducible wrappers with their ownMonad/LawfulMonad/MonadLift/Functorinstances they presented a second, defeq-but-syntactically-distinct representation of the same objects. Rewriting, normalization, and matching against the machinery that already exists inPolyFunhad to cross that seam:rw/simplemmas stated onFreeMwould not fire onOracleCompgoals, instances resolved along two different paths, and generic PolyFun constructions needed bespoke VCVio shims.This PR makes
OracleComp,OracleQuery, andOracleSpec.toPFunctor@[reducible]and deletes the duplicate instances, so PolyFun's instances and lemmas apply directly and there is a single canonical representation — a step toward treating VCVio as a thin probability layer on top of PolyFun's theory of interactions. The rest of the diff repairs everything that the transparency change surfaced. All CI libraries (ToMathlib,VCVio,FFI,LatticeCrypto,HashSig,Examples,VCVioWidgets) build clean, andVCVioTest/Smoke.leanpasses.Changes
VCVio/OracleComp/OracleComp.lean,VCVio/OracleComp/OracleQuery.lean— the core change:@[reducible]on both types; the bespokeMonad/LawfulMonad/MonadLift(OracleComp) andFunctor/LawfulFunctor(OracleQuery) instances are removed in favor of thePFunctor.FreeM/PFunctor.Objinstances they were forwarding to.VCVio/OracleComp/Traversal.lean—allPathsSatisfy/somePathSatisfieswere defined by tactic-mode recursion through the bespokeOracleComp.constructeliminator, and their@[simp]lemmas used dot notation on(query q : OracleComp spec _) >>= oa. Once the types were reducible, the bind's inferred type has headPFunctor.FreeM, so generalized field resolution looked forPFunctor.FreeM.allPathsSatisfyand the statements no longer elaborated (taking four downstream proofs with them). The predicates are now stated directly over PolyFun's path-prefix machinery: a single ∀/∃ overPFunctor.FreeM.Cursor, filtered by two new generic helpers,PFunctor.TraceList.WithinOn(every recorded answer lies in the allowed fibers) andPFunctor.FreeM.Cursor.Sat(a leaf-residual cursor demands the output predicate, a node-residual cursor the query predicate). Cursors rather than completePaths because the recursion demandsqueryPredat every node reachable by possible answers even when the subtree below has no possible completion (empty ranges). The public API — names, signatures, simp attributes — is unchanged, and thesupportWhenbridges andbind_ifflemmas keep their original proofs. The two helpers are natural candidates for upstreaming into PolyFun.VCVio/OracleComp/OracleSpec.lean— two adjustments:toPFunctoris now@[reducible], matchingDomain/Range/ofPFunctor/QueryLogwhich already were. This is required forsimp/rwmatching across theQueryLog spec↔PFunctor.TraceList spec.toPFunctoridentification inReplayFork, and (see below) a file-local reducibility attribute for it is no longer viable onceOracleCompis reducible.toPFunctor_addloses its@[simp].toPFunctoroccurs inside the instance-carrying type of anOracleComp, so rewriting(spec + spec').toPFunctorunder asimulateQ/liftMstrands goals in a form thesimulateQ_queryfamily can no longer match. This single re-key is what letLoggingOracle,MacFromPRF, andFiatShamir/Sigma/Forkkeep their original proofs with zero diff.VCVio/CryptoFoundations/ReplayFork.lean— the file-wideattribute [local reducible] OracleSpec.toPFunctor PFunctor.Idxis narrowed toPFunctor.Idxonly (a Mathlib definition we cannot re-attribute globally). WithOracleCompreducible, instance-resolution queries forMonadLiftT (OracleComp spec) SetMnormalize throughtoPFunctor, so a local transparency change makes query-time keys diverge from the declaration-time discrimination-tree keys andsupport/evalDistsilently stop elaborating. ThetoPFunctorhalf of the attribute is subsumed by the global@[reducible]. Two now-redundant simp arguments (mem_support_freeM_pure_iff) are dropped.VCVio/OracleComp/SimSemantics/WriterT/PreservesInv.lean,VCVio/OracleComp/SimSemantics/StateT/PreservesInv.lean,VCVio/StateSeparating/CellRef.lean— the invariant-preservation proofs simplified queries viaOracleSpec.query_def+simulateQ_query+OracleQuery.input_apply/cont_apply. Under the reducible regime thequery_defexpansion changes normal form first and the projection lemmas no longer fire, leavingcont ⟨t, id⟩ <$> impl (input ⟨t, id⟩)stuck. Each proof now routes throughsimulateQ_spec_query, the canonical entry point that avoids the projection artifact entirely.VCVio/CryptoFoundations/FiatShamir/Sigma/Stateful/Compatibility.lean— twosimpa [monad_norm] using hclosings become plainexact h. The helper lemmas' statements and the goal now differ only by∘/eta wrappers (definitionally equal), andmonad_normover-normalization produced display-identical terms differing at implicit instance positions, which the finalsimpamatch rejected. Directexactis both simpler and robust.Examples/PRGfromPRF.lean—show→changeat one site: the goal reaching it changed shape under the new simp normal forms, so theshow-only-for-readability style linter fires.VCVio/ProgramLogic/Tactics/Common/{Core,Registry,WpStepRegistry}.lean— fixes thevcstep/vcgenengine, which failed on evenwp⟦pure x⟧/wp⟦oa >>= f⟧goals ("no matching rule applied", plus cascadingwhnftimeouts) while manualrw [wp_pure]/rw [wp_bind]worked. Root cause:@[vcspec]/@[wpStep]patterns are built viaSym.mkPatternFromDeclWithKey, whoseSym.preprocessTypestep unfolds reducible definitions — so withOracleCompreducible, stored patterns key the monad argument ofBind.bindand friends inFreeMform.Sym.DiscrTree.getMatchis purely structural and was queried with the raw goal computation, whose keys stayed inOracleCompform; the keys diverged at the monad argument and every registry lookup silently returned no candidates (a rule's own LHS failed to match its own stored pattern). The fix is a sharedsymMatchKeyhelper (=Sym.preprocessTypeon the query term) applied in all five registry query functions, restoring the registration/query symmetry theSymframework assumes. This bug was latent: it only bites when a definition occurring in rule statements is reducible.docs/agents/gotchas.md,docs/agents/program-logic.md— document the new invariants: prefix-form statements for lemmas about monadic results, thetoPFunctor_addre-key rationale, the prohibition onattribute [local reducible]for definitions occurring in instance keys, and theSymregistry pattern/query alignment invariant.Verification
lake build ToMathlib VCVio FFI LatticeCrypto HashSig Examples VCVioWidgets— clean (no errors, no new warnings).lake env lean VCVioTest/Smoke.lean— passes.sorrys introduced; pre-existingsorrycensus unchanged.🤖 Generated with Claude Code