Is there a way to tell Mathematica to factor
$$ \frac{1}{1-x^2} $$
from a large expression?
For instance if the expression is A_1+A_2+A_3
and I want to factor 1/(1-x^2)
from A_1+A_2
but leave A_3
alone.
Here is a very simple little function that takes two expressions k
and p
, and any function that accepts a single expression (like Expand
, Together
, Simplify
,Apart
,...). It then factors k
from p
and outputs a new expression $p=kq$. The parameter func_
operates on the form of $q$.
Here is the function:
sfactor[k_, p_, func_] := HoldForm[StandardForm[k]]*StandardForm[func@(p*1/k)]
The output is going to have unreleased hold forms in it thus limiting the usefulness of that output, but then again, I have no idea what you would want it for except to actually look at the factoring. Here are some examples:
Factor $x^2$ from $x^3+3x+1$:
sfactor[x^2, x^3 + 3 x + 1, Apart]
Output:
What it does to your abstract example:
sfactor[1/(1 - x^2), Subscript[a, 1] + Subscript[a, 2], Expand] + Subscript[a, 3]
Output:
And one more for giggles, here I know one of the binomial factors:
sfactor[x^2 + 3, 3 + 15 x + 22 x^2 + 11 x^3 + 7 x^4 + 2 x^5, Simplify]
Output:
Again, an expression involving unreleased hold forms would need to be fixed for further computations, but you know what it would simplify to in the end, the output always being $p$ expressed with the factor $k$.
sFactor[expression_, factor_, f_: Simplify, g_: Identity] := Release[Hold[g[factor]]]*f[(expression/factor)];
. Now the obtained expression may be further manipulated, if necessary. The penalty is that in some special cases it might not protect the result from automatic simplification. Then one of the functions f or g should be chosen different than the default ones.
$\endgroup$
Commented
Jun 10, 2014 at 9:00
1+2+3
then, in the absence ofHold
orUnevaluated
or the like, it will automatically evaluate to 6. $\endgroup$A1
,A2
andA3
. We cannot answer for hypothetical and general questions because the strategy will differ depending on what your terms are. I suggest looking at the link in Artes' first comment above. $\endgroup$