-
Notifications
You must be signed in to change notification settings - Fork 1
linear: implement P0 PLU decomposition with unified result type #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Ezrnest
wants to merge
2
commits into
master
Choose a base branch
from
codex/explore-further-work-on-linear-algebra-a8120r
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| # 精确线性代数(非浮点)下一步建议 | ||
|
|
||
| > 目标:围绕整数、有理数、有限域、多项式环等模型,继续增强 `linear` 模块的可用性与可验证性。 | ||
|
|
||
| ## 1. 线性方程组能力补全 | ||
|
|
||
| 当前已有 `solveLinear(A, b)` 与 `solveHomo(A)`,下一步可补: | ||
|
|
||
| - **可逆矩阵的多右端项求解批处理**: | ||
| - 对 `AX=B` 的每一列右端复用同一消元过程,避免重复消元。 | ||
| - **解结构标准化输出**: | ||
| - 明确区分唯一解 / 无解 / 仿射解空间; | ||
| - 输出“特解 + 零空间基”。 | ||
| - **可验证证书(certificate)**: | ||
| - 返回秩、主元列、自由变量索引,方便上层做证明式检查。 | ||
|
|
||
| ## 2. 分解算法增强(以精确代数为中心) | ||
|
|
||
| 在已有 LU / LDL / Smith / Hermite 能力上,建议优先做: | ||
|
|
||
| - **PLU / LUP(带置换)**: | ||
| - 对一般矩阵更稳健,避免无主元时失败。 | ||
| - **分式自由(fraction-free)LU**: | ||
| - 在整数与多项式系数下控制中间表达式膨胀。 | ||
| - **分解结果的统一数据结构**: | ||
| - 例如 `LUResult(L, U, P, rank, pivots)`。 | ||
|
|
||
| ## 3. 标准形与模分解方向 | ||
|
|
||
| 你们已经有 Hermite/Smith 入口,这是一条很强的“符号(精确)线代”路线,可继续: | ||
|
|
||
| - **Smith Normal Form 的变换矩阵输出**: | ||
| - 不只返回对角因子,也返回 `UAV = D` 中的 `U,V`(可逆)。 | ||
| - **子模/商模不变量的直接 API**: | ||
| - 例如由 Smith 因子直接构造有限阿贝尔群分解信息。 | ||
| - **整数矩阵同余分类支持**: | ||
| - 与现有 `toCongDiagForm` 配套,补更多不变量查询。 | ||
|
|
||
| ## 4. 特征多项式与最小多项式 | ||
|
|
||
| 目前有 `charPoly`,可继续构建完整谱工具链(依旧非浮点): | ||
|
|
||
| - **最小多项式 `minimalPolynomial`**(Krylov/Frobenius 思路)。 | ||
| - **Cayley-Hamilton 证书接口**: | ||
| - 除返回 `p(A)=0` 的布尔结果,可返回验证用中间对象。 | ||
| - **有理标准形 / Frobenius 标准形**: | ||
| - 对域上线代尤其有价值,且完全精确。 | ||
|
|
||
| ## 5. 多项式矩阵与有理函数矩阵 | ||
|
|
||
| 在“非浮点”语境下非常实用: | ||
|
|
||
| - **`Matrix<Polynomial<T>>` 的行最简/列最简形**。 | ||
| - **多项式矩阵的 Smith 形(PID 条件下)**。 | ||
| - **有理函数矩阵的约化表示**(控制理论、系统理论会用到)。 | ||
|
|
||
| ## 6. 性能与复杂度改进(保持精确性) | ||
|
|
||
| - **可选算法策略**:小规模用定义式/朴素法,大规模自动切换 Bareiss/分块。 | ||
| - **稀疏矩阵路径**:为大规模精确问题提供稀疏消元接口。 | ||
| - **缓存与结构共享**:重复子式、子矩阵视图和主元轨迹复用。 | ||
|
|
||
| ## 7. 测试与性质验证(最优先) | ||
|
|
||
| 建议新增“性质测试”而不只是样例测试: | ||
|
|
||
| - **分解回代恒等式**:`A = LU`, `A = L D L^T`, `U A V = D`。 | ||
| - **秩-零度定理**:`dim ker(A) + rank(A) = n`。 | ||
| - **Smith 因子链条件**:`d_i | d_{i+1}`。 | ||
| - **跨模型一致性**: | ||
| - 同一整数矩阵在 `Z` 与 `Z/pZ` 投影后的秩关系(受模约束)。 | ||
|
|
||
| ## 8. API 体验优化建议 | ||
|
|
||
| - 用统一命名:`toRowEchelon`, `toReducedRowEchelon`, `decompPLU`。 | ||
| - 为“要求域/整环/欧几里得整环”的函数加显式文档标签。 | ||
| - 增加失败原因类型化异常(主元不存在、模型不满足、维度不匹配)。 | ||
|
|
||
| ## 9. 建议的落地优先级(两周节奏示例) | ||
|
|
||
| 1. **P0**:PLU + 统一分解结果对象 + 补测试。 | ||
| 2. **P1**:Smith 形返回 `(U,D,V)` 与不变量 API。 | ||
| 3. **P2**:最小多项式 + 有理标准形(先小规模正确性版本)。 | ||
| 4. **P3**:稀疏路径与策略切换(性能迭代)。 | ||
|
|
||
| --- | ||
|
|
||
| 如果你们希望,我下一步可以直接按 `P0` 给出一版最小可合并实现清单: | ||
| - 要改哪些文件; | ||
| - 每个函数签名怎么定; | ||
| - 对应测试用例列表(先红后绿)。 |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,16 @@ | ||
| kotlin.code.style=official | ||
| # comment out and set the following lines if you are using a proxy | ||
| systemProp.http.proxyHost=127.0.0.1 | ||
| systemProp.http.proxyPort=7890 | ||
| systemProp.https.proxyHost=127.0.0.1 | ||
| systemProp.https.proxyPort=7890 | ||
| javaToolchainVersion=21 | ||
| # Proxy settings are intentionally not enabled by default. | ||
| # If needed in your local environment, uncomment and configure the lines below: | ||
| # systemProp.http.proxyHost=127.0.0.1 | ||
| # systemProp.http.proxyPort=7890 | ||
| # systemProp.https.proxyHost=127.0.0.1 | ||
| # systemProp.https.proxyPort=7890 | ||
|
|
||
|
|
||
| ossrhUsername=yourUsername | ||
| ossrhPassword=yourPassword | ||
| signing.keyId=yourKeyId | ||
| signing.password=yourKeyPassword | ||
| signing.secretKeyRingFile=path/to/your/secring.gpg | ||
| signing.key=yourBase64EncodedPrivateKey | ||
| signing.key=yourBase64EncodedPrivateKey |
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In
decompPLU, the earlycontinuewhen columnkhas no non-zero candidate skips initialization oflower[k,k]and abandons pivot tracking for that step. On rank-deficient inputs with a zero leading column but non-zero entries later in the row (for example[[0,1],[0,0]]), this yieldsP=IandU=Abut leaves rowkofLzeroed, soP*A != L*U, andpivots/rankunderreport the matrix rank. This should handle zero-pivot columns without breaking the decomposition identity.Useful? React with 👍 / 👎.