Repository navigation
Factorize factors a polynomial in a subexpression of its variable, through the replacement the equation solver already makes - #1422
Merged
Conversation
…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
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.
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) + 1stayed 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 answerFactorizegave is unchanged and this only adds.sin(x)^2 + 2 sin(x) + 1(sin(x) + 1) ^ 2sin(x) + sin(x)^3sin(x) * (sin(x) ^ 2 + 1)sin(2x)^2 - 1(sin(2 * x) - 1) * (sin(2 * x) + 1)ln(x)^2 - 4,cos(x)^2 - sin(x)^2Not covered: a polynomial in two subtrees (
sin(x)^2 + 2 sin(x) cos(x) + cos(x)^2), ande^x + e^(2x), whose minimal subtree isxrather thane^x.Factorizeis not on theSimplifypath, 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