TITLE: Which rings are rings of continuous functions?
QUESTION [17 upvotes]: Now at MO.
This is a question for which I've found a number of "near-miss" results online, which may actually be answers but whose direct relevance I haven't been able to see.
Say that a ring $A$ is spatial iff there is some topological space $\mathcal{X}$ such that $A\cong C(\mathcal{X})$, where $C(\mathcal{X})$ is the ring of continuous functions $\mathcal{X}\rightarrow\mathbb{R}$.

Is there a purely algebraic characterization of spatiality?

I've been told that Gelfand representations are relevant here, but I don't immediately see how they answer the question; maybe I'm missing something, though. (Note however that I do mean to ask about rings, rather than more intricate structures like Banach algebras. Also note that I'm not assuming any tameness properties on the spaces which are candidates for witnessing spatiality.)

EDIT: "purely algebraic characterization" is of course some serious weasel-wordery. Here's one way to make that precise (and so make possible a rigorous negative answer):

Is there an $\mathcal{L}^2_{\infty,\infty}$-sentence characterizing the spatial rings?

Here $\mathcal{L}^2_{\infty,\infty}$ is the fully-infinitary version of second-order logic: we allow arbitrary-cardinality Boolean combinations and quantifications (over both first- and second-order objects). Of course, any specific $\mathcal{L}^2_{\infty,\infty}$-sentence can only "reach up" to a particular cardinal, so this isn't actually as overkill as it may appear.

REPLY [12 votes]: I do not know the answer to your precise formulation but here are some things you can say about characterizing spatial rings.
First, rings of bounded continuous functions can be characterized algebraically using Gelfand duality.  Namely, a commutative ring $A$ is isomorphic to the ring $C_b(X)$ of bounded continuous functions $X\to\mathbb{R}$ for some topological space $X$ iff $A$ satisfies the following properties.  First, $A$ is a $\mathbb{Q}$-algebra, and is partially ordered by the relation $x\leq y$ iff $y-x$ is a square.  Moreover, for each $r\in\mathbb{R}$, there is a unique element of $A$ which defines the same Dedekind cut in $\mathbb{Q}$ with respect to this ordering as $r$, and this makes $A$ an $\mathbb{R}$-algebra.  Finally, if you form the complexification $\mathbb{C}\otimes_\mathbb{R} A$, the spectral radius defines a norm on $\mathbb{C}\otimes_\mathbb{R} A$ which makes it a $C^*$-algebra.  (Alternatively, you can directly characterize real bounded continuous functions without going through the complexification.  For instance, for $x\in A$ you can define $\|x\|$ to be the least $r\in\mathbb{R}_{\geq 0}$ such that $-r\leq x\leq r$ and then it suffices to assume that this is a complete norm on $A$.  See IV.4.4-10 in Peter Johnstone's Stone spaces.)
Now, there is an analogue of Gelfand duality for rings of unbounded functions.  Recall that Gelfand duality says that for any topological space $X$, $C_b(X)$ is isomorphic to $C_b(Y)$ for a compact Hausdorff space $Y$ which is unique up to unique compatible homeomorphism (namely, the Stone-Cech compactification $\beta X$ of $X$), and that this gives a contravariant equivalence of categories between the category of rings of the form $C_b(X)$ and the category of compact Hausdorff spaces.  Similarly, for any topological space $X$, $C(X)$ is isomorphic $C(Y)$ for a unique realcompact space $Y$ which is unique up to unique compatible homeomorphism and this gives a contravariant equivalence of categories between the category of rings of the form $C(X)$ and the category of realcompact spaces.  This space $Y$ is called the Hewitt realcompactification $\nu X$ of $X$, and can be described as the subset of $\beta X$ to which all elements of $C(X)$ extend continuously.
Now, given a spatial ring $A\cong C(X)$, you can recover $\nu X$ and the canonical map $A\to C(\nu X)$ algebraically as follows.  First, as above, $A$ is partially ordered using squares and this gives $A$ an $\mathbb{R}$-algebra structure.  You can then define the subring $A_0$ of elements of $A$ that are bounded above and below by elements of $\mathbb{R}$ (this will be $C_b(X)$).  This subring is a ring of bounded continuous functions, as characterized above.  Now let $Y$ be the set of maximal ideals of $C_b(X)$ (this will be $\beta X$).  For every $m\in Y$, the quotient $A_0/m$ is isomorphic to $\mathbb{R}$, and in this way we can map $A_0$ to the set of functions $Y\to\mathbb{R}$.  Give $Y$ the coarsest topology that makes every element of $A_0$ continuous.
Now, we can also evaluate elements of $A$ at points of $Y$ as follows.  Given $x\in A$ and $n\in\mathbb{N}$, let $x_n=(x\wedge n)\vee -n$ with respect to our ordering on $A$.  Then $x_n\in A_0$, and we can consider $x_n$ as a function $Y\to\mathbb{R}$.  This sequence of functions $(x_n)$ then converges pointwise to a function $Y\to [-\infty,\infty]$ (this is the unique extension of $x:X\to\mathbb{R}$ to a function $\beta X\to[-\infty,\infty]$).  Let $Z\subseteq Y$ be the set of points at which every element of $A$ takes a finite value (this is $\nu X$).  We then can map $A$ to the set of functions $Z\to\mathbb{R}$.  This gives a characterization of spatial rings: a ring $A$ is spatial iff it satisfies all the above properties and this last map is a bijection from $A$ to $C(Z)$.
Unfortunately, this characterization does not appear to be "algebraic" in your sense.  Almost everything can be done in $\mathcal{L}^2_{\infty,\infty}$, but there is a problem with the very last step.  To say that our map $A\to C(Z)$ is surjective, we need to quantify over functions $Z\to\mathbb{R}$.  Elements of $Z$ are second-order over $A$ (they are maximal ideals in $A_0$), and so functions $Z\to\mathbb{R}$ are third-order over $A$.  (There are various ways you could try to get around this, but I haven't found one that works.  For instance, if you could algebraically state that $Y$ is the Stone-Cech compactification of $Z$, then instead of quantifying over arbitrary functions $Z\to\mathbb{R}$, you can just quantify over functions $Z\to\mathbb{R}$ that are a pointwise limit of a sequence of elements of $A_0$, since you know that every continuous function $Z\to\mathbb{R}$ extends to a continuous function $Y\to[-\infty,\infty]$ which is then the pointwise limit of a sequence of bounded continuous functions $Y\to\mathbb{R}$.  Alternatively, imitating the approach for bounded continuous functions above, you might try to find some more basic algebraic characterization of when a subalgebra of $C(Z)$ is all of $C(Z)$, analogous to the Stone-Weierstrass theorem which is a crucial tool in the proof of Gelfand duality.  I don't know of any such characterization, though.)
Let me finally mention the paper

Anderson, Frank W.; Blair, Robert L., Characterizations of the algebra of all real-valued continuous functions on a completely regular space, Ill. J. Math. 3, 121-133 (1959). ZBL0083.17403.

which is the only reference I have been able to find on the topic of characterizing spatial rings.  They give two characterizations (Theorem 5.6 and 5.8), but again, these are not "algebraic".  I have not read through all the details of the paper but their approach seems to be basically the same idea as mine.  They characterize the map $A\to C(Z)$ being surjective by characterizing when an extension of $A$ would consist of just adding more continuous functions on $Z$ to the ring, and require that $A$ has no nontrivial extensions of this type.