How can we define convexity in one dimension?

Definition of a convex set: A set $S\subset\mathbb R^n$ is said to be convex if for each $x_1, x_2\in S$ the line segment $\lambda x_1 + (1-\lambda)x_2$ for $\lambda\in (0,1)$ belongs to $S$.
This says that all points on the line connecting two points in the set are in the set.

My question is: how can we define convexity in one dimension?


In $\mathbb R$, the definition is the same and you can prove that it is equivalent to connexity, or simpler : $$A\subseteq\mathbb R\text{ is convex }\iff A\text{ is an interval}.$$


The formulas in your question(as edited) work perfectly well in $\mathbb{R}$. The collection of convex sets is the collection of intervals.