I try to test Maximize[f[x],x] with some function f[x] containing parameters.
I use a simple parabola f[x_]=-a (x-1)^2+b with parameters a and b.
It’s maximum value is b at x=1 for a>0.
First, from the documentation for Maximize (“Details and Options”):
If the constraints cannot be satisfied, Maximize returns {-Infinity, {x->Indeterminate,...}}.
Why would -Infinity be an appropriate choice? A real-valued function cannot have -Infinity as a maximum (or least upper bound), so it would seem ridiculous. Maybe just for that reason, to indicate a problem. But actually, it follows from a certain definition: An upper bound for f(x) over a domain is a number B such that for all x in the domain, f(x) \le B. If the domain is empty, then by standard logic the proposition “for all x in the domain, f(x) \le B” is true (sometimes said to be vacuously true). If the constraint cannot be satisfied, the domain is empty; therefore any real number B is an upper bound for f(x) and the least upper bound in some sense is -Infinity. (It would be more proper to say the least upper bound does not exist. If we allow some latitude, -Infinity does capture the idea in a way, and it can be dealt with programmatically in an unambiguous way. To me it seems a reasonable choice for the result.)
Second, the constraint a > 0 is not treated the same as an assumption. The answer that is produced consists of two parts, one for when the constraint is satisfied (maximum b, x -> 1), and the other for when the constraint is not satisfied (in which case the answer agrees with the documentation above).
If you wish to consider only the case a > 0, then use Simplify or FullSimplify to apply the assumption:
Simplify[Maximize[{-a (x - 1)^2 + b, a > 0}, x], a > 0]
(* {b, {x -> 1}} *)
Your explanations were very helpful for me. Actually I had read the docs, but did not really understand them. And I was not really familiar with Piecewise. In particular I did not understand how the constraints in Maximize are handled. Now I got it.
BTW: Instead of your Simplify one can use Refine:
In[970]:= Simplify[Maximize[{-a (x - 1)^2 + b, a > 0}, x], a > 0]
Out[970]= {b, {x -> 1}}
In[971]:= Refine[Maximize[{-a (x - 1)^2 + b, a > 0}, x], a > 0]
Out[971]= {b, {x -> 1}}