Let V be a linear space (aka vector space) over R (or, more generally although not usefully, any ordered field). A subset X⊂V is called convex iff for all a,b∈X the entire segment [a,b] = {ta + (1-t)b | 0<=t<=1} ⊂ X.

That is, if X contains 2 points, it also contains every point between them.

Convex sets are much "better behaved" than arbitrary sets. One useful property is that the boundary of a convex set in Rn must be continuous, and, although not smooth, has a directional derivative. And if it has a second derivative, the second derivative is positive semidefinite (for n=2, that essentially means >=0; for n>2, that means locally like a ball, not like a saddle).

A function f:X→R is convex iff the shape above its graph is convex. A convex function RR must be continuous. It always has both one sided derivatives satisfying f-'(x) <= f+'(x), and each derivative is monotone increasing. It follows that it's derivable apart from at most countably many points, and that the derivative is an increasing function. Note that it needn't have a derivative at every point, and that even if it does, it needn't have a second derivative. But if it does, then the second derivative must be nonnegative.

We can define similarly for functions f:X→R, where X⊆Rn is a convex set.