Unable to evaluate reasonable max expression



Consider the following statement:

Max[0, Sqrt[1 - Cos[4 \[Theta]]]]

You'll find that Mathematica won't evaluate this, because it doesn't know the range of $\theta$. Okay, that makes sense, so change it to:

Simplify[Max[0, Sqrt[1 - Cos[4 \[Theta]]]], {0 <= \[Theta] <= 2 \[Pi]}]

This evaluates happily. As it should. But then consider this not-impactful adjustment:

Simplify[Max[0, Sqrt[1 - Cos[4 \[Theta]]]/
  Sqrt[2]], {0 <= \[Theta] <= 2 \[Pi]}]

This doesn't evaluate. I don't know why; because it seems quite obvious that it should be exactly the same as the previous case, right? (The constant factor of 1/Sqrt[2] can't change the fact that it is still $\geq 0$). Any thoughts on how to fix this? Of course, in my case I want to actually keep the Max ..., but I don't know the exact form of the other side, so I can't just arbitrarily remove constants ...

Noon Silk

Posted 2012-09-26T06:57:20.007

Reputation: 523

1Simplify[Max[0, Simplify[Sqrt[1 - Cos[4 \[Theta]]]/Sqrt[2]]], {0 <= \[Theta] <= 2 \[Pi]}] seems to work. – Yves Klett – 2012-09-26T07:11:55.293

...and what happens if you use FullSimplify[] instead? – J. M.'s ennui – 2012-09-26T07:14:34.250

Thanks for the Accept, but I encourage all users to wait 24 hours before Accepting as answer so that other users have a chance to read and answer the question before it appears concluded. Quick Accepts may prevent the posting of other, potentially better answers. – Mr.Wizard – 2012-09-26T07:20:43.663

Thanks @Mr.Wizard; I did try and un-accept yesterday, but for some reason actions on this site occasionally don't work (like voting and commenting.) – Noon Silk – 2012-09-26T22:15:07.627



There are many potential simplifications that Simplify and FullSimplify do not make, presumably because they are deemed too costly to attempt.

In this case it appears that parts are at too deep a level for the required simplifications to be made:

expr = Max[0, Sqrt[1 - Cos[4 t]]/Sqrt[2]];
simp = FullSimplify[#, {0 <= t <= 2 Pi}] &;

simp @ expr
Max[0, 1/Sqrt[Csc[2 t]^2]]

If you apply the simplification function to all the subexpressions further transformations are made:

simp //@ expr
Abs[Sin[2 t]]


Posted 2012-09-26T06:57:20.007

Reputation: 259 163

Nice, a very rare occurrence of MapAll! – Sjoerd C. de Vries – 2012-09-26T07:16:12.797

Indeed, MapAll[] is always a good idea when simplifying tricky things. – J. M.'s ennui – 2012-09-26T07:18:03.310

@Sjoerd Thanks. I try to find uses for it.

– Mr.Wizard – 2012-09-26T07:18:09.457

1Funny enough, your solution does not work with Simplify, but the less specific (and inferior) Simplify[Max[0, Simplify[Sqrt[1 - Cos[4 \[Theta]]]/Sqrt[2]]], {0 <= \[Theta] <= 2 \[Pi]}] does? – Yves Klett – 2012-09-26T07:22:30.107

Awesome! Thanks. – Noon Silk – 2012-09-26T07:22:37.483


@Yves I am not surprised; there is a large element of chance involved in this and I certainly do not mean to imply that //@ is a panacea -- far from it in fact. It only so happens that it produces the needed string of transformations in this case. Search MathGroup for VOISimplify for a good illustration of the order dependence of Simplify that often manifests as apparent capriciousness.

– Mr.Wizard – 2012-09-26T07:36:20.770

4An insightful statement by Andrzej Kozlowski in that thread: ... there are just too many different groupings and rearrangements that would have to be tried to get to a simpler form. Moreover, Mathematica will only apply a transformation if it immediately leads to a decrease in complexity. Sometimes the only way to transform an expression to a simpler form is by first transforming it to a more complex one ... – Mr.Wizard – 2012-09-26T07:40:30.107

BTW, awesome gravatar. It becomes your new status ;-) – Yves Klett – 2012-09-26T08:47:07.507

@Yves thanks, I think. :o) – Mr.Wizard – 2012-09-26T09:02:58.333