TITLE: Is $f(x,y) = x^2 - 2e^y$ concave or convex?
QUESTION [0 upvotes]: Is $f(x,y) = x^2 - 2e^y$ concave or convex?
My thought process is as such:
$f'(x,y)=2x - 2e^y$;
$f''(x,y)=2 - 2e^y$
Thus when $y<0$ ($2e^y<2$), $f''(x,y)<0 \implies f(x,y)$ is convex.
Likewise, when $y>0$, $f''(x,y)>0 \implies f(x,y)$ is concave.
But the answer says $f(x,y)$ is neither concave nor convex - why is that?

REPLY [0 votes]: There are two things going on in your question: The first is that your calculation of derivatives for multivariable functions does not make sense; this is explained in the other answers.
The second thing is the question whether a function can be convex or concave only for certain parts of its domain. To illustrate, let me go to a one-variable example, say $f(x) = \sin x$. The second derivative is $- \sin x$ and hence positive for $x \in \cdots (-\pi, 0) \cup (\pi, 2\pi) \cup (3 \pi, 4 \pi) \cup (5\pi, 6\pi) \cup \cdots$. From this, you can conclude that $f$ is concave on each convex subset of this union (in this one-dimensional setting, the convex subsets are just the subintervals). So for example, $f$ is concave on $(\pi, 2\pi)$. It is not really concave on $(\pi, 2\pi) \cup (3\pi, 4\pi)$ because this set is not convex and the question “is a function concave (or convex) on a set” only makes sense when the set in questions in convex.
Convexity or concavity of a function is always relative to some convex subset of its domain. If no such set is given, we implicitly mean the entire domain of $f$. For $f$ to be concave then means that its second derivative is negative (well, non-positive) on its entire domain (provided $f$ is sufficiently differentiable). If the second derivative is sometimes positive and sometimes negative then specifying the subsets on which it is concave is a more precise answer, but claiming that $f$ is neither convex nor concave is technically correct.
(But also note that in the case of the function from the question, the Hessian is simply indefinite everywhere, so there is no hope for convexity or concavity at all.)
{"set_name": "stack_exchange", "score": 0, "question_id": 4149316}