Skip to content

Factorize factors a polynomial in a subexpression of its variable, through the replacement the equation solver already makes - #1422

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
factor-in-a-subtree
Sep 18, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
factor-in-a-subtree

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

The one open case of #203, per the comment there: all three original cases factor on master (1 + sqrt(2x) + x/2 → (sqrt(x/2) + 1)^2, x^2 + 2x + 1 → (x + 1)^2, 4x^2 - 4y^2 → 4 (x - y)(x + y)), and what did not was a polynomial in something other than a variable — sin(x)^2 + 2 sin(x) + 1 stayed as written.

Now the smallest subtree that holds every occurrence of the variable (TreeAnalyzer.GetMinimumSubtree, the replacement the equation solver already makes) stands in for it, the polynomial in the placeholder is handed to the polynomial layer, and the factors are read back through it. Tried after the variables themselves, so every answer Factorize gave is unchanged and this only adds.

2.5.0 now
sin(x)^2 + 2 sin(x) + 1 as written (sin(x) + 1) ^ 2
sin(x) + sin(x)^3 as written sin(x) * (sin(x) ^ 2 + 1)
sin(2x)^2 - 1 as written (sin(2 * x) - 1) * (sin(2 * x) + 1)
ln(x)^2 - 4, cos(x)^2 - sin(x)^2 already factored by the rules unchanged

Not covered: a polynomial in two subtrees (sin(x)^2 + 2 sin(x) cos(x) + cos(x)^2), and e^x + e^(2x), whose minimal subtree is x rather than e^x. Factorize is not on the Simplify path, so the benchmark gate is not concerned; the factorization tests and the doc examples are green locally.

Closes #203. Part of #185.

🤖 Generated with Claude Code

https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura

…rough the replacement the equation solver already makes

sin(x)^2 + 2 sin(x) + 1 was left as written while x^2 + 2 x + 1 is (x + 1)^2, because the
polynomial layer factors with respect to a variable and sin(x) is not one. The smallest
subtree that holds every occurrence of the variable -- TreeAnalyzer.GetMinimumSubtree, which
is how the solver reads sin(x)^2 + sin(x) + 1 = 0 as t^2 + t + 1 = 0 -- stands in for it, the
polynomial in the placeholder is factored, and the factors are read back through it:
(sin(x) + 1)^2, sin(x) * (sin(x)^2 + 1), (sin(2x) - 1) * (sin(2x) + 1). Tried after the
variables themselves, so nothing that factored before factors differently. Recorded in
BREAKING-CHANGES.md against a v2.5.0 build.

Closes #203. Part of #185.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
@Rafael-SOWNet
Rafael-SOWNet merged commit b1dac77 into master Sep 18, 2026
31 checks passed
@Rafael-SOWNet
Rafael-SOWNet deleted the factor-in-a-subtree branch September 18, 2026 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Collapse must collapse

1 participant