To address your first question, this:
Simplify[Abs[Sin[x]], Assumptions -> {x >= \[Pi], x < 2 \[Pi]},
ComplexityFunction -> (StringLength[ToString[#]] &)]
(* -Sin[x] *)
does the job. It is just since
StringLength[ToString[#]] &[Abs[Sin[x]]]
(* 11 *)
StringLength[ToString[#]] &[-Sin[x]]
(* 7 *)
It is more difficult with your second question. This is your initial expression
expr1 = Sqrt[1 + Sin[x]] + Sqrt[1 - Sin[x]];
Here we transform the terms under the radicals:
expr2 = MapAt[TrigFactor, expr1, {{1, 1}, {2, 1}}]
(* Sqrt[2] Sqrt[Sin[\[Pi]/4 - x/2]^2] +
Sqrt[2] Sqrt[Sin[\[Pi]/4 + x/2]^2] *)
Now let us introduce a complexity function:
Clear[cf];
cf[e_] := (Count[e, _Abs, Infinity]);
and try to simplify each radical separately:
expr3 = MapAt[
Simplify[#, -2 \[Pi] < x < -3 \[Pi]/2, ComplexityFunction -> cf] &,
expr2, {{1, 2}, {2, 2}}]
The outcome is strange:
(* Sqrt[2] Abs[Sin[\[Pi]/4 + x/2]] - Sqrt[2] Sin[\[Pi]/4 - x/2] *)
The Abs is removed in one case, but did not disappear in the other. It is even more strange taking into account that Sin[\[Pi]/4 + x/2] in the interval in question is strictly negative. One can make sure of this by plotting it:
Plot[{Sin[\[Pi]/4 + x/2],
Abs[Sin[\[Pi]/4 + x/2]]}, {x, -2 \[Pi], -3 \[Pi]/2},
PlotStyle -> {{Blue, Thickness[0.005]}, {Red, Thickness[0.005]}},
PlotRange -> {-1.2, 1.2}]
Here Sin[\[Pi]/4 + x/2]is shown in blue and Abs[Sin[\[Pi]/4 + x/2]]- in red.
It is not clear what this complexity function does at all, since evaluation of this:
cf[Abs[Sin[\[Pi]/4 + x/2]]]
cf[Abs[Sin[\[Pi]/4 - x/2]]]
returns 0 in both cases. However, it works in the one case in the expression above. I do not understand it, and would be grateful for explanations.
Nevertheless, this operation did not work as expected, but we know what it should have done, let us make a substitution:
expr4 = expr3 /. Abs[a_] -> -a // Simplify
(* -2 Cos[x/2] *)
Abs[Sin[x]]to be simpler thanTimes[-1, Sin[x]](see e.g. this and this). That aside, there does seem to be a problem with simplifying the sign of trig functions. CompareSimplify[Sign[Sin[x]], 0 < x < Pi]andSimplify[Sign[Sin[x]], -Pi < x < 0]– Simon Woods Apr 22 '14 at 09:34f[e_] := 100 Count[e, _Abs | _Sqrt, {0, Infinity}] + LeafCount[e]; FullSimplify[Abs[Sin[x]], -3 Pi/4 < x < -Pi/2, ComplexityFunction -> f]doesn't seem to work either. Did I miss anything? – Yi Wang Apr 22 '14 at 09:46ComplexityFunctionto forbidAbs, the result isSqrt[Sin[x]^2]. If further forbidPower, the result is a piecewise function. If further forbidPiecewise, the result returns toAbs[Sin[x]]. So it appears like it's not a complexity function problem. – Yi Wang Apr 22 '14 at 09:53FullSimplify[Abs[Sin[x]] == -Sin[x], Assumptions -> -3 Pi/4 < x < -Pi/2]does not simplify it either. Thus this should not be a complexity function issue. – Yi Wang Apr 22 '14 at 09:56