3
$\begingroup$

I have a long expression of the form

-(1/(12 M (2 + M - M ζ^2 - η^2))) (-2 + M (-1 + ζ^2) + η^2)(some long expr)

The expression is a result of a Mathematica command. (Here's the expression itself, for the reference.) The long expression (some long expr) is a polynomial in ζ and η, and, if simplified, the whole expression would also be a (product of) polynomial(s) — unlike its form above, which is a ratio of polynomials.

The first two factors can be simplified by Simplify successfully, but, when applied to the full expression, it leaves them unchanged. I tried FullSimplify on the full expression, but I couldn't wait until it finishes.

I'd like to direct Mathematica to simplify the first two factors to 1/(12 M), without touching the rest, so that the result would be

1/(12 M)(some long expr)

How can I achieve this?

$\endgroup$
  • $\begingroup$ Have you tried Together? $\endgroup$ – Edmund Mar 15 '17 at 23:54
3
$\begingroup$

You can define a function for that long expression and specify that as an excluded form in Simplify.

someLongExp[x_] = Expand[(1 + x)^100, x]
Simplify[-(1/(12 M (2 + M - M ζ^2 - η^2))) (-2 + M (-1 + ζ^2) + η^2) someLongExp[x],
 ExcludedForms -> {someLongExp[_]}]

Edit

As pointed out by @bbgodfrey, it does not work for all cases (for example, when someLongExp[x_] = 2 Expand[(1 + x)^100, x]). As suggested by @bbgodfrey, this can be resolved by using Hold and ReleaseHold as follows.

someLongExp[x_] = 2 Expand[(1 + x)^100, x] // Hold;
Simplify[-(1/(12 M (2 + M - M ζ^2 - η^2))) (-2 + M (-1 + ζ^2) + η^2) someLongExp[x], 
  ExcludedForms -> {someLongExp[_]}] // ReleaseHold 

Another way is by using TimeConstraintto force Simplify to use only the basic simplification rules.

Quiet@Simplify[-(1/(12 M (2 + M - M ζ^2 - η^2))) (-2 + M (-1 + ζ^2) + η^2) someLongExp[x],
TimeConstraint -> 0.0001]
$\endgroup$
  • 1
    $\begingroup$ This elegant solution works for the example given but not for 2 Expand[(1 + x)^100, x] and for some other instances. This problem can be circumvented by using Hold on the right side of the first line, and \\ ReleaseHold at the end of the second line of code. $\endgroup$ – bbgodfrey Mar 15 '17 at 23:10
  • $\begingroup$ @bbgodfrey Thanks for pointing that out. $\endgroup$ – Anjan Kumar Mar 15 '17 at 23:47
  • $\begingroup$ But what if the whole expression is the output of another command, not something you just enter/copy-paste? $\endgroup$ – Ruslan Mar 16 '17 at 5:47
  • $\begingroup$ @Ruslan Can you clarify by giving an example. $\endgroup$ – Anjan Kumar Mar 16 '17 at 11:21
  • 1
    $\begingroup$ @Ruslan I think by limiting the simplification time using TimeConstraint, we can force Simplify to use only the basic simplification rules. The above solution can be modified as follows. Quiet@Simplify[-(1/(12 M (2 + M - M ζ^2 - η^2))) (-2 + M (-1 + ζ^2) + η^2) someLongExp[x], TimeConstraint -> 0.0001] $\endgroup$ – Anjan Kumar Mar 16 '17 at 12:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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