12
$\begingroup$

Bug introduced in 12.2, Fixed in 12.3

Something changed in NMaximze in v12.2:

NMaximize[E^(-x^2) - 1, x]
(* {(-1 + E^#1)[0.], {x -> 0.}} *)

v12.1 works as expected:

NMaximize[E^(-x^2) - 1, x]
(* {0., {x -> 0.}} *)

as does Maximize in v12.2:

Maximize[E^(-x^2) - 1, x]
(* {0, {x -> 0}} *)

Do you all agree this is a bug? Any ideas on a workaround?

$Version
(* "12.2.0 for Mac OS X x86 (64-bit) (December 12, 2020)" *)
$\endgroup$
4
  • 1
    $\begingroup$ Consider: NMaximize[E^(-x^2.) - 1, x] This seems to return a reasonable numerical answer, so maybe this narrows down the location of the bug. $\endgroup$
    – bill s
    Commented May 1, 2021 at 22:56
  • 4
    $\begingroup$ This is fixed in the 12.3 prerelease version 12.3.0 for Mac OS X x86 (64-bit) (April 13, 2021) $\endgroup$ Commented May 2, 2021 at 3:05
  • $\begingroup$ Here's a cute fix: MapAt[Function, NMaximize[E^(-x^2) - 1, x], {1, 0}]. Not as good as Optimization`UseConvexMinimize = False though. (Not nearly, since it fails whenever NMaximize succeeds.) BTW, @bills, the convex minimizer rejects the problem with the exponent 2. as "not transformable," and NMaximize falls back onto the old automatic method. $\endgroup$
    – Michael E2
    Commented May 2, 2021 at 16:13
  • 1
    $\begingroup$ Since this is for a shared package, I used If[$VersionNumber==12.2, Block[{Optimization`UseConvexMinimize=False}, ...] because you can never be sure what version of Mathematica people will be using. $\endgroup$
    – Chris K
    Commented May 2, 2021 at 16:56

1 Answer 1

13
$\begingroup$

It seems (clearly!) to be a bug in the preprocessing for the new convex optimizer. Use one of the other methods (e.g. "DifferentialEvolution"):

Trace[
 NMaximize[E^(-x^2) - 1, x],
 _Optimization`MinimizationProblem,
 TraceForward -> True,
 TraceInternal -> True
 ]

Workaround:

NMaximize[E^(-x^2) - 1, x, Method -> "DifferentialEvolution"]

(*  {0., {x -> -5.45643*10^-9}}  *)

Alternatively, you can turn off the convex minimizer:

Block[{Optimization`UseConvexMinimize = False},
 NMinimize[-(E^(-x^2) - 1), x]
 ]

(*   {0., {x -> -5.45643*10^-9}}  *)
$\endgroup$
3
  • 1
    $\begingroup$ Maybe just a missing & in there. Thanks for the workarounds and I'll report to WRI. $\endgroup$
    – Chris K
    Commented May 1, 2021 at 19:37
  • $\begingroup$ @ChrisK Seems to be the added constant ("vertical shift") that triggers the bug. Also occurs here: NMinimize[1 + Log[1 + x^2], x]. $\endgroup$
    – Michael E2
    Commented May 1, 2021 at 19:52
  • 4
    $\begingroup$ This is fixed in the 12.3 prerelease version 12.3.0 for Mac OS X x86 (64-bit) (April 13, 2021) $\endgroup$ Commented May 2, 2021 at 3:07

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.