feat: [AI] add polynomial algebra (factor / sqrfree / discriminant / resultant)#1843
Draft
s-celles wants to merge 1 commit into
Draft
feat: [AI] add polynomial algebra (factor / sqrfree / discriminant / resultant)#1843s-celles wants to merge 1 commit into
s-celles wants to merge 1 commit into
Conversation
…resultant)
Adds four user-facing primitives for univariate polynomial algebra over ℚ
(or with symbolic coefficients treated as transcendentals):
- `resultant(f, g, var; algorithm = :euclid | :sylvester)` — single entry
point exposing both the extended-Euclidean PRS and the Sylvester-matrix
determinant; the two algorithms are guaranteed to agree on every
valid input.
- `discriminant(f, var)` — derived via the classical identity
`(-1)^(n*(n-1)/2) * Res(f, f') / lc(f)`. `disc(a*x + b) = 1`,
`disc(c) = 0`.
- `sqrfree(f, var)` — Yun's square-free decomposition in
characteristic 0; returns `(unit, Vector{(Num, Int)})` satisfying
`unit * prod(p_i^e_i) == f`.
- `Symbolics.factor(f, var)` — rational factorisation. Not exported to
avoid shadowing `Base.factor` / `Primes.factor`. Pure-Julia pipeline
handles content + square-free + rational-roots; a new
`_factor_with_nemo` extension hook in `SymbolicsNemoExt` delegates
higher-degree residuals to `Nemo.factor` when Nemo is loaded,
producing the full ℚ-irreducible decomposition.
Tidies `SymbolicsNemoExt.nemo_crude_evaluate` with explicit dispatches
for `Nemo.QQFieldElem` and `Nemo.ZZRingElem` so integer-valued
coefficients render as plain `Int`/`BigInt` rather than `n//1`. The
existing `Symbolics.factor_use_nemo` (used by the solver) is untouched
at the call-site level and gains the same cosmetic cleanup.
Documentation: new manual page `docs/src/manual/polynomial_algebra.md`
registered in `docs/make.jl` under the Algebra group.
Testing: 86 polynomial-algebra tests pass without Nemo, 102 with Nemo
loaded (16 additional Nemo-oracle tests guarded by the extension).
Version bump to 7.20.0 (MINOR — purely additive).
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.
Adds four user-facing primitives for univariate polynomial algebra over ℚ (or with symbolic coefficients treated as transcendentals):
resultant(f, g, var; algorithm = :euclid | :sylvester)— single entry point exposing both the extended-Euclidean PRS and the Sylvester-matrix determinant; the two algorithms are guaranteed to agree on every valid input.discriminant(f, var)— derived via the classical identity(-1)^(n*(n-1)/2) * Res(f, f') / lc(f).disc(a*x + b) = 1,disc(c) = 0.sqrfree(f, var)— Yun's square-free decomposition in characteristic 0; returns(unit, Vector{(Num, Int)})satisfyingunit * prod(p_i^e_i) == f.Symbolics.factor(f, var)— rational factorisation. Not exported to avoid shadowingBase.factor/Primes.factor. Pure-Julia pipeline handles content + square-free + rational-roots; a new_factor_with_nemoextension hook inSymbolicsNemoExtdelegates higher-degree residuals toNemo.factorwhen Nemo is loaded, producing the full ℚ-irreducible decomposition.Tidies
SymbolicsNemoExt.nemo_crude_evaluatewith explicit dispatches forNemo.QQFieldElemandNemo.ZZRingElemso integer-valued coefficients render as plainInt/BigIntrather thann//1. The existingSymbolics.factor_use_nemo(used by the solver) is untouched at the call-site level and gains the same cosmetic cleanup.Documentation: new manual page
docs/src/manual/polynomial_algebra.mdregistered indocs/make.jlunder the Algebra group.Testing: 86 polynomial-algebra tests pass without Nemo, 102 with Nemo loaded (16 additional Nemo-oracle tests guarded by the extension).
Version bump to 7.20.0 (MINOR — purely additive).
Be aware it's AI generated code from Claude Opus 4.7 ... it may be imperfect.
And is given as a draft for future work.
May help #59
Free to maintainers to edit.