Repository navigation
[Cubical] Constructor injectivity via orthogonal retract decomposition and parallel de Bruijn lifting (partially fixes #3733) - #1
Merged
Conversation
…n and parallel de Bruijn lifting (partially fixes agda#3733) - DInjectivity digested step + buildEquiv with projection generation - HDU left inverse thunk capture (replaces __IMPOSSIBLE__) - CRT-inspired orthogonal decomposition: index dimension (HDU) × field dimension (projections) - Open context support via extraCxt + liftS for coverage checker - 4 tests: non-indexed, indexed, HIT regression, partial pattern AI assistance: architecture design, type inference, de Bruijn index calculation. All decisions and final code manually reviewed and tested. CRT orthogonal decomposition architecture derives from human research in the triqchem-lab/discrete-mathematics library. Co-authored-by: Yan Li <[email protected]>
Owner
Author
中文补充说明 / Chinese Supplement本 PR 的理论架构来源于 律算合一 (Sovereign) 框架——在 Z/M ≅ Z/p × Z/q 的 CRT 同构(p, q 互素)允许将模 M 的复杂问题拆解为两个独立子问题——各自在局部作用域求解,然后通过同构映射组合。构造子内射性证明遵循完全相同的分解模式:
此架构在 Sovereign 库中已有完整的形式化推导链: 本 PR 是该理论框架在 Cubical 类型论编译器中的首次工程应用。 The theoretical architecture of this PR derives from the Sovereign (律算合一) framework, formalised in the
This architecture is the first engineering application of the Sovereign framework's CRT generalisation to a Cubical type theory compiler. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Title
[Cubical] Constructor injectivity via orthogonal retract decomposition and parallel de Bruijn lifting (partially fixes #3733)Description
Problem
In Cubical Agda,
with-abstraction on inductive types (Fin,ℕ, etc.) triggersUnsupportedIndexedMatchwarnings. Two interlocking defects cause this:digestUnifyLogmissingInjectivitybranch: the injectivity unification step falls through to_ → unsupported, so the left inverse is never computed.buildLeftInversecondguard too conservative:null <$> getContextreturnsLeft UnsupportedCxtwhenever the coverage checker adds context bindings above the unification telescope, blocking ALL injectivity left inverses. The upstream TODO comment acknowledges this:This PR fixes both, moving agda#3733 from icebox to partial resolution.
Architecture: CRT-inspired orthogonal decomposition
The architectural design is inspired by the Chinese Remainder Theorem (CRT) — formalised and generalised in the
triqchem-lab/discrete-mathematicslibrary. The core insight: for coprime moduli p, q, the isomorphism Z/M ≅ Z/p × Z/q allows decomposing a complex modulo-M problem into independent sub-problems, each solved locally, then composed via the isomorphism.Constructor injectivity admits the same orthogonal decomposition:
Fin.sucindex equationsn = n'c us = c vsinto field equationsraiseS (1 + nEq2 + nctel)embeds the HDU local left inverse into the global telescopeTelescope topology (innermost → outermost):
Each segment is handled independently in
tau_fullandleftInv_full:raiseS 1)tau_hdu/leftInv_hdu, lifted viaraiseS (1 + nEq2 + nctel)makeTautermsChanges
7 files, +289/−18:
Types.hsunifyHduTauInvfield (stores HDU left inverse thunk) +tellHduTauInv.Either NoLeftInvdowngraded toEither ()to avoid module cycleUnify.hs__IMPOSSIBLE__→Nothing; capture 4th componentgetTauInvHDUfromUnifiesLeftInverse.hsDInjectivitydigested step +PrettyTCM; (2)extraCxt = max(0, cxtLen - size(varTel))open context handling; (3)buildEquivdynamic projection generation +makeTau; (4) HDU thunk forcing + CRT parallel liftingCHANGELOG.mdTest coverage
InjectivityWith.agdawith(non-indexed, complete)raiseS 1is NOT a stubInjectivityIndexed.agdawith(indexed, complete)InjectivityPartial.agdatauevaluation — coverage checker generatestranspXclause, injects into AST. 0 warnings, 0 variable captureInjectivityHITs.agdaInjectivityPartial.agdais the crucible — it proves thattauandleftInvsurvive dynamic telescope alignment under extreme AST rewriting.Design decisions
1.
leftInv = raiseS 1is correct, not a stubFor non-indexed types,
transpdistributes definitionally over constructors:Thus
rho[tau] = idholds strictly.raiseS 1is the correct trivial homotopy.2. Projections generated via
addConstantduring typecheckingSame pattern as
Data.hs:defineProjections. Functions are non-recursive, single-clause (proj_i (c x₁...xₙ) = x_i).CompiledClausesconstructed manually to avoid thecompileClauses→Coverage→Unifymodule cycle.3. All boundary paths audited
consOfHITrejects)--without-K+ HDU failUnifyStuckUnifiesmakeTau+raiseS 1UnifiesScope (what this does NOT cover)
This PR resolves injectivity for
with-abstraction pattern matching. It does NOT address:These remain open for future work.
Related
withinjectivity is now supporteddigestUnifyLog+buildEquivgaptriqchem-lab/discrete-mathematics: Formalised CRT generalisation inspiring the orthogonal decomposition architectureAI Assistance Declaration
Code implementation used AI assistance (architecture design, type inference, de Bruijn index calculation). All decisions and final code were manually reviewed and tested. The theoretical architecture (CRT orthogonal decomposition) derives from human research in the
triqchem-lab/discrete-mathematicslibrary.