Let R be a real closed field. The Pierce–Birkhoff conjecture says that any piecewise polynomial function f on R n can be obtained from the polynomial ring R[x 1,..., x n ] by iterating the operations of maximum and minimum. The purpose of this paper is threefold. First, we state a new conjecture, called the Connectedness conjecture, which asserts, for every pair of points $${{\alpha,\beta\in\,{\rm {Sper}}\ R[x_1,\ldots,x_n]}}$$ , the existence of connected sets in the real spectrum of R[x 1,..., x n ], satisfying certain conditions. We prove that the Connectedness conjecture implies the Pierce–Birkhoff conjecture. Secondly, we construct a class of connected sets in the real spectrum which, though not in itself enough for the proof of the Pierce–Birkhoff conjecture, is the first and simplest example of the sort of connected sets we really need, and which constitutes the first step in our program for a proof of the Pierce–Birkhoff conjecture in dimension greater than 2. Thirdly, we apply these ideas to give two proofs that the Connectedness conjecture (and hence also the Pierce–Birkhoff conjecture in the abstract formulation) holds locally at any pair of points $${{\alpha,\beta\in\,{\rm {Sper}}\ R[x_1,\ldots,x_n]}}$$ , one of which is monomial. One of the proofs is elementary while the other consists in deducing this result as an immediate corollary of the main connectedness theorem of this paper.