1
$\begingroup$

Using Mathematica 10,

Simplify[Sqrt[Sin[x]^6 ((a^2 + r[]^2)^2 - 
  a^2 (q^2 + a^2 - 2 m r[] + r[]^2) Sin[x]^2)^2]/((a^2 + 
  a^2 Cos[2 x] + 2 r[]^2)^2 (-a^2 q^2 + a^4 + 
  2 m a^2 r[] + 3 a^2 r[]^2 + 2 r[]^4 + a^2 Cos[2 x] (q^2 + a^2 - 2 m r[] + r[]^2))),
 Assumptions -> {(a^2 + r[]^2)^2 - a^2 (q^2 + a^2 - 2 m r[] + 
    r[]^2) Sin[x]^2 > 0}]

yields the weird expression: $$\begin{cases} \frac{\sin ^3(x)}{2 \left(a^2 \cos (2 x)+a^2+2r()^2\right)^2} & \sin (x)\geq 0 \\ -\frac{\sin ^3(x)}{2 \left(a^2 \cos (2 x)+a^2+2r()^2\right)^2} & \text{True} \\ \end{cases}.$$ If I add the assumption $0 \leq x \leq \pi$, then the result becomes: $$\begin{cases} \frac{\sin ^3(x)}{2 \left(a^2 \cos (2 x)+a^2+2r()^2\right)^2} & a^2 (a^2+q^2 -2 m r() +r^2) \sin^2(x)\leq (a^2 + r()^2)^2\\ -\frac{\sin ^3(x)}{2 \left(a^2 \cos (2 x)+a^2+2r()^2\right)^2} & \text{True} \\ \end{cases},$$ in which the first conditional is actually the first assumption! The correct result is of course the first without the extra conditional.

What does the "True" conditional mean? Why is the second result still not sufficiently simplified?

Another example (2):

Simplify[Conjugate[a + I Cos[θ] r], Assumptions -> {a > 0, θ > 0, r > 0}]

yields Conjugate[a + I r Cos[θ]]. If I attempt simplification of each part in the sum, the result is the expected one!

Simplify seems to be a extremely sensitive to input. Is there any advice to work around these issues?

Another example (3):

Is it possible to make FullSimplify apply only to expressions that include Conjugate, so that the expression can be simplified quickly? I have a long expression and only simplification of the Conjugate is necessary; FullSimplify on the full expression takes more than an hour. Any ideas?

Solution The fastest way (mere seconds) I could find to simplify an expression enclosed in Conjugate is to define the expression as Map[Simplify[Conjugate[#]]&, expr,{-1}]. This has the drawback that the simplified Conjugate is mapped only on "objects that have no subparts", according to the documentation, which suits my purpose fine at the moment.

Another example (4):

When trying to simplify a very long expression, Simplify and FullSimplify cache intermediate results of the simplification in order to speed up the process, but this has certain disadvantages:

  1. Long expressions tend to create extremely big caches, which is apparent as the memory size of the kernel reaches many GB and is never released after the simplification is aborted.
  2. The result changes depending on the cache created earlier, which reduces the determinism of the process.
  3. The cache created earlier may cause next simplifications to last too long for various reasons.

Is there a way to disable or control the cache created by Simplify and FullSimplify?

$\endgroup$
11
  • $\begingroup$ "What does the True conditional mean?" - it's what we often refer to as the "otherwise" case for piecewise-defined functions. $\endgroup$ Aug 13, 2015 at 10:29
  • $\begingroup$ Doesn't this explanation assume a specific order of reading the result? Is this standard behaviour in Mathematica? $\endgroup$
    – auxsvr
    Aug 13, 2015 at 10:36
  • $\begingroup$ Sometimes, Mathematica finds it convenient to return piecewise results; in your case, the "specific order" seems to be quite apparent: "first result if the first condition is met, and the second result otherwise". $\endgroup$ Aug 13, 2015 at 10:38
  • 2
    $\begingroup$ According to the documentation for Piecewise, the conditions are evaluated in order, until one evaluates to True; the value displayed with the condition True is in fact the default value val (where val is the term in the docs). (The last value displayed will always be the default and be accompanied by True.) $\endgroup$
    – Michael E2
    Aug 13, 2015 at 12:08
  • 1
    $\begingroup$ @auxsvr Use InputForm or FullForm to see enough of the internal form of something that you can use Part or Extract on it. $\endgroup$ Aug 22, 2015 at 16:56

1 Answer 1

2
$\begingroup$

To address your practical examples:

For the first question, you can just simplify in an additional step:

Simplify[
  Sqrt[Sin[x]^6 ((a^2 + r[]^2)^2 - 
       a^2 (q^2 + a^2 - 2 m r[] + r[]^2) Sin[x]^2)^2]/((a^2 + 
       a^2 Cos[2 x] + 2 r[]^2)^2 (-a^2 q^2 + a^4 + 2 m a^2 r[] + 
      3 a^2 r[]^2 + 2 r[]^4 + 
      a^2 Cos[2 x] (q^2 + a^2 - 2 m r[] + r[]^2))), 
  (a^2 + r[]^2)^2 - a^2 (q^2 + a^2 - 2 m r[] + r[]^2) Sin[x]^2 > 0
];

Simplify[%, 0 <= x <= π]

(* Sin[x]^3/(2 (a^2 + a^2 Cos[2 x] + 2 r[]^2)^2) *)

For the second question, you can use FullSimplify

FullSimplify[Conjugate[a + I Cos[θ] r], Assumptions -> {a > 0, θ > 0, r > 0}]

(* a - I r Cos[θ] *)

or ComplexExpand, which is usually more efficient for this kind of simplification:

ComplexExpand[Conjugate[a + I Cos[θ] r]]
(* a - I r Cos[θ] *)

For the third question, if you want to simplify just the Conjugate expressions, you can do

expr /. c_Conjguate :> FullSimplify[c] 

You could also create more sophisticated rules based on the specific form of the expression that you're trying to simplify.

$\endgroup$
3
  • $\begingroup$ The problem with your answer to the first question is that it is very unreliable; Simplify fails to work with the same condition against a different expression in many cases. The most reliable way I've found so far is to use a rule to replace the expression in the condition with a variable x, Simplify with respect to x satisfying certain conditions, then replace x with the original expression. $\endgroup$
    – auxsvr
    Aug 19, 2015 at 9:24
  • $\begingroup$ ComplexExpand does not work in my case, probably because certain variables have special properties in xAct. It throws error messages such as "$RecursionLimit::reclim: Recursion depth of 1024 Exceeded". FullSimplify works, though. Thanks! $\endgroup$
    – auxsvr
    Aug 19, 2015 at 9:28
  • $\begingroup$ Your answer for the third question does not work if the expression wrapped in Conjugate is too long, which is the case I was stuck with. I'm sorry if I didn't explain this clearly. $\endgroup$
    – auxsvr
    Aug 22, 2015 at 17:32

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.