# Weakness in Maximize

Solving a minimization problem in version 13 on Windows 10, I obtain

Maximize[{Sin[x + Sin[x]] + Sin[x - Sin[x]] + (Pi/2 - 2)*Sin[Sin[x]],
x >= 0 && x < 2*Pi}, x]//FullSimplify

{2 Cos[Sin[Root[{Pi Cos[Sin[#]] - 4 Sin[Sin[#]] Sin[#]& , 0.9033391107665128473590217051048716426220.300104378161908}]]]\ Sin[Root[{Pi Cos[Sin[#]] - 4 Sin[Sin[#]] Sin[#]& , 0.9033391107665128473590217051048716426220.300104378161908}]] + 1/2 (-4 + \[Pi]) Sin[Sin[Root[{Pi Cos[Sin[#]] - 4 Sin[Sin[#]] Sin[#]& , 0.9033391107665128473590217051048716426220.300104378161908}]]]\ , {x -> Root[{Pi Cos[Sin[#]] - 4 Sin[Sin[#]] Sin[#]& , 0.9033391107665128473590217051048716426220.300104378161908}]}}

which is not very useful as a symbolic solution.

Along with that, Mathematica is able to find an optimal solution in a closed form and this is its achievement. Indeed,

Maximize[Sin[x+Sin[x]]+Sin[x-Sin[x]]+(Pi/2-2)*Sin[Sin[x]],x]

{1/2 (-2 Sqrt[2] + Sqrt[2] \[Pi]), {x -> -47 \[Pi] - ArcSin[\[Pi]/4]}}

Since the objective function has 2*Pi as its minimal positive period, the same value is taken at

Mod[-47 \[Pi] - ArcSin[\[Pi]/4], 2*Pi]

\[Pi] - ArcSin[\[Pi]/4]

N[%]

2.23825

and

Plot[Sin[x + Sin[x]] + Sin[x - Sin[x]] + (Pi/2 - 2)*Sin[Sin[x]], {x,0, 2*Pi}]

confirms it.

How to obtain {1/2 (-2 Sqrt[2] + Sqrt[2] \[Pi]), {x -> Pi-ArcSin[Pi/4]}} programmatically?

• BTW, FunctionPeriod[ Sin[x + Sin[x]] + Sin[x - Sin[x]] + (Pi/2 - 2)*Sin[Sin[x]], x] performs 0. One more a bug. Commented Apr 28, 2022 at 15:44

Clear["Global`*"]

expr = Sin[x + Sin[x]] + Sin[x - Sin[x]] + (Pi/2 - 2)*Sin[Sin[x]];

{max, arg} =
Maximize[{expr, 0 <= x < 2 Pi}, x] // FullSimplify // Quiet

Maximize will have a much easier time if you simplify the expression first.

expr2 = Simplify[expr, 0 <= x < 2 Pi]

(* 2 Cos[Sin[x]] Sin[x] + 1/2 (-4 + π) Sin[Sin[x]] *)

{max2, arg2} = Maximize[{expr2, 0 <= x < 2 Pi}, x] // FullSimplify

(* {(-2 + π)/Sqrt[2], {x -> ArcSin[π/4]}} *)

max - max2 // N[#, 20] & // Quiet

(* 0.*10^-69 *)

(x /. arg) - (x /. arg2) // N[#, 20] & // Quiet

(* 0.*10^-70 *)

EDIT: Likewise with FunctionPeriod

FunctionPeriod[expr2, x]

(* 2 π *)
• Quiet is not needed: Mathematica produces a warning, not an error. Commented Apr 28, 2022 at 16:18
• Quiet should only be used for warnings and never for error messages. It removes the clutter of the warning after it has been reviewed and determined to be of no import. Commented Apr 28, 2022 at 16:21
• Also expr2 = Simplify[expr] works. Commented Apr 28, 2022 at 16:21