5
$\begingroup$

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.

$\endgroup$
10
  • 2
    $\begingroup$ Please edit all relevant info, examples etc. into the question, comments are not well-suited for that purpose. $\endgroup$
    – Yves Klett
    Commented Jun 9, 2014 at 18:00
  • 2
    $\begingroup$ If the expression is 1+2+3 then, in the absence of Hold or Unevaluated or the like, it will automatically evaluate to 6. $\endgroup$ Commented Jun 9, 2014 at 18:04
  • 2
    $\begingroup$ @LoveLearning People are trying to help you here... please give a concrete example — i.e. actual terms for A1, A2 and A3. 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$
    – rm -rf
    Commented Jun 9, 2014 at 19:01
  • 1
    $\begingroup$ @Artes The problem is more general than the polynomial one, and the solution of such a problem is of enormous use in itself. I would upvote it. $\endgroup$ Commented Jun 10, 2014 at 8:16
  • 1
    $\begingroup$ @Love Learning. This question has been one of the discussed during the Q&A session of the last Technology Conference. The outcome is that there is no such a function in the main body of Mma, but such a function is badly needed. I can point out to the package "Presentations" of David Park, where there is a function "FactorOut" designed exactly for such a purpose. You may have a look here: home.comcast.net/~djmpark/index.html. Its advantage with respect to the solution of J.W.Perry below, is that the parts are not held. $\endgroup$ Commented Jun 10, 2014 at 8:22

1 Answer 1

14
$\begingroup$

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:

enter image description here

What it does to your abstract example:

sfactor[1/(1 - x^2), Subscript[a, 1] + Subscript[a, 2], Expand] + Subscript[a, 3]

Output:

enter image description here

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:

enter image description here

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$.

$\endgroup$
2
  • $\begingroup$ OK.... But looks complicated. $\endgroup$ Commented Jun 10, 2014 at 8:45
  • $\begingroup$ @J. W. Perry I like it very much. I would, however, propose a slightly different expression based on your approach, but without Hold in the end: 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.