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
I keep seeing the same problem come up that I want to "factor" something that has an extra term e.g.:
In [130]: e =expand((x+y)**3+ z)
In [131]: e
Out[131]:3223
x +3⋅x ⋅y +3⋅x⋅y + y + z
In [132]:factor(e)
Out[132]:3223
x +3⋅x ⋅y +3⋅x⋅y + y + z
The z-term is preventing factoring so if we temporarily remove it then factoring becomes possible:
In [133]: factor(e-z) + z
Out[133]:
3
z + (x + y)
In general it would be nice if there was a way to infer which terms of an Add could be factored together and factor those. I've made a quick function using connected components that does this. Terms are grouped together based on having symbols in common. Then the separate groups are factored:
In [134]:factor_components(e)
Out[134]:3
z + (x + y)
Thefactor_components function seems to work well where you want to factor subterms that all have symbols so that there is no constant term. When there is a constant term it is not clear which component it should be factored with.
I keep seeing the same problem come up that I want to "factor" something that has an extra term e.g.:
The
z
-term is preventing factoring so if we temporarily remove it then factoring becomes possible:In general it would be nice if there was a way to infer which terms of an Add could be factored together and factor those. I've made a quick function using connected components that does this. Terms are grouped together based on having symbols in common. Then the separate groups are factored:
With that we have:
The
factor_components
function seems to work well where you want to factor subterms that all have symbols so that there is no constant term. When there is a constant term it is not clear which component it should be factored with.A contrived bigger example:
Most often when I see this issue coming up there is just a single additional term preventing factorisation.
The text was updated successfully, but these errors were encountered: