homlab_polynomial
homlab_polynomial 提供一个 Python 编程入口,用 SymPy 将包含普通变量 A 和三下标变量
C[x, y, z] 的字符串表达式整理成按不同 C[x, y, z] 分组的形式。
安装
pip install .
使用
from homlab_polynomial import organize_polynomial
expr = "A*C[1, 2, 3] + 2*C[1,2,3] + A^2*C[0,0,0]"
print(organize_polynomial(expr))
输出:
C[0, 0, 0]*(A^2) + C[1, 2, 3]*(A + 2)
负指数也支持:
organize_polynomial("A^-10*C[0,0,0] + 2*C[0,0,0]/A")
输出:
C[0, 0, 0]*(2*A^(-1) + A^(-10))
说明:
C[x, y, z]的三个下标必须是整数,可以为负数。- 输入支持用
^表示指数运算,也支持 Python/SymPy 风格的**。 - 默认输出也使用
^。如果需要**,可以传入output_power_operator="**"。 - 如果希望每个整理后的项单独占一行,可以传入
line_break_terms=True。 - 系数支持有限 Laurent 多项式,因此
A^-1、1/A、A^-10都可以使用。 C[x, y, z]项不会带外部负号;负号会保留在括号中的系数多项式里。- 不含
C的纯A项会作为最后的余项保留。
如果需要继续做 SymPy 计算,可以使用:
from homlab_polynomial import organize_polynomial_expr
sympy_expr = organize_polynomial_expr("A*C[1,2,3] + C[1,2,3]")
验算
organize_polynomial() 默认会在每次整理后进行随机代入验算。它会给 A 和所有出现过的
C[x, y, z] 赋非零有理数,检查整理前后的表达式是否一致。
也可以直接调用验算函数:
from homlab_polynomial import verify_simplification
verify_simplification(
"A*C[1,2,3] + C[1,2,3]",
"C[1, 2, 3]*(A + 1)",
)
Metadata
Release files for homlab-polynomial 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| homlab_polynomial-0.1.1.tar.gz | 9.3 kB | Without provenance | Details for homlab_polynomial-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| homlab_polynomial-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for homlab_polynomial-0.1.1-py3-none-any.whl |
Total release size: 17.1 kB
Release files / homlab_polynomial-0.1.1.tar.gz
| Download URL | homlab_polynomial-0.1.1.tar.gz |
|---|---|
| Size | 9.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1dd93dababeca1636173c14500d3784058afdb36fca7baa3adfe3a5d1eac38a6
|
|
BLAKE2b-256 checksum How to use checksums |
08eb202be414da4b38e83f08c4a1ea5f5a7da76e8a588d764dec467a4293e62f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.4.1 CPython/3.11.15 Windows/10
|
Release files / homlab_polynomial-0.1.1-py3-none-any.whl
| Download URL | homlab_polynomial-0.1.1-py3-none-any.whl |
|---|---|
| Size | 7.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
69ed29860fccf6c975c60817e0e612e0d5d01baba7bb2afc22a64030acb50038
|
|
BLAKE2b-256 checksum How to use checksums |
71370fa3a63874f85d791818e535bf84ea988a050fb069ddc3a6340d67e466ac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.4.1 CPython/3.11.15 Windows/10
|
Security for homlab-polynomial 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.