You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 9b50cd9
Browse filesBrowse the repository at this point in the historyBrowse files
Add up the like terms Expand produces (#164) (#676)
`(x+1)^2 * (x+2-1)^2` expanded to sixteen terms, of which five are distinct. The
issue is titled "cannot be expanded" and that is what it means.
The two of you had already worked out what it needs, on the issue: each term of the
result wants simplifying, but Simplify is far too expensive to call from inside
Expand -- "some kind of fast Simplify that unites terms by their common multiplier".
That is what this is. Each term is reduced to a coefficient and a product of powers,
PowerRules folds (x^2)^2 into x^4 so the two are not counted as different monomials,
and terms whose products agree are added together. Nothing else.
(x+1)^2 * (x+2-1)^2 1 + 4x + 6x^2 + 4x^3 + x^4
((x-1)*(x-2))^3 8 - 36x + 66x^2 - 63x^3 + 33x^4 - 9x^5 + x^6
The second is the case asked for in the same thread.
A term whose coefficients cancel is written out rather than dropped. That looks
wasteful, and it is the whole of the correctness here: the monomial may carry a
domain condition, and (4a - 2)/(2x) + (1 - 2a)/x is zero only where x is not.
Dropping the term collected it to a plain 0 and threw that away. Written out,
InnerSimplified turns 0 * x^-1 back into `0 provided not x = 0`. There is a test.
Four existing expectations change, all to the collected form: 3x + 2x arriving as
5x in ExpandCollapseTest, `a + 3 + 1` as `a + 4` in PolyParser, and two orderings.
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
/// y ^ 8 + 8 * x * y ^ 7 + 28 * x ^ 2 * y ^ 6 + 56 * x ^ 3 * y ^ 5 + 70 * x ^ 4 * y ^ 4 + 56 * x ^ 5 * y ^ 3 + 28 * x ^ 6 * y ^ 2 + 8 * x ^ 7 * y + x ^ 8
203
203
/// </code>
204
204
/// </example>
205
+
205
206
publicEntityExpand(intlevel=2)
206
207
{
207
208
staticEntityExpand_(Entitye,intlevel)=>
@@ -214,7 +215,89 @@ static Entity Expand_(Entity e, int level) =>
214
215
expChildren.AddRange(exp);
215
216
else
216
217
returnthis;// if one is too complicated, return the current one
0 commit comments