In Algebraic Geometry one usually says that "working with algebraically closed fields makes life easier". Today I stumbled over one instance of this: suppose $X$ is an irreducible projective variety over a field $K$. Over algebraically closed fields it is known that there are no non-constant (ie, $\not\in\,K$) rational functions regular on $X$. In symbols $$\Gamma(X,\mathcal{O}_X)=K.$$
It turns out that this seems to be false if $K$ is not algebraically closed: take $K=\mathbb{R}$ and look at the projective line $X=\mathbb{P}^1_{\mathbb{R}}$ and the rational function $f=\dfrac{x_0^2}{x_0^2+x_1^2}$ where $(x_0:x_1)$ are projective coordinates on $X$. It is non-constant and regular everywhere.
On the other hand, looking at Hartshorne's book on AG, I discovered Theorem III, 5.2 from where one deduces that under same assumptions on $X$ we have $$\Gamma(X,\mathcal{O}_X)=K^r,$$ for some $r\geqslant 1$ because, after all $K\subseteq \Gamma(X,\mathcal{O}_X)$ is still valid. What I was not able to find is how to compute this integer $r$.
Question: is $r=\dim_K\,\Gamma(X,\mathcal{O}_X)$ computable in terms of known invariants of $X$ for (at least) projective, irreducible curves over an arbitrary field $K$?
A generalization of course would be (in case of curves) how to compute $\dim_K\,\Gamma(X,\mathcal{O}_X(nP))$ where $P$ is a rational point of X. If relevant, I'm interested in $K=k(t)$ where $k$ is algebraically closed.
Thanks!
The given example is not a regular function on the scheme $\operatorname{Proj} \Bbb R[x_0,x_1,x_2]$ because it has a pole at $(x_0^2+x_1^2)$. As has been discussed recently, the naive definition of regularity for a function on a "classical" variety over an field which is not algebraically closed is incorrect and must be modified. One more reason to work with schemes instead of classical varieties!
Now to your main question: how do we compute $\dim_k \Gamma(X,\mathcal{O}_X)$ for $X$ an irreducible projective variety over a field $k$? By the answer here and the basic properties of the tensor product, we have that $\dim_{\overline{k}} \Gamma(X_{\overline{k}},\mathcal{O}_{X_{\overline{k}}})=\dim_k \Gamma(X,\mathcal{O}_X)$ where $k\subset \overline{k}$ is the algebraic closure. Now we can apply the result that for a connected projective scheme over an algebraically closed field $\overline{k}$, the only global sections are $\overline{k}$ (proof: a global section gives a map to $\Bbb A^1_{\overline{k}}$, the image must be closed, connected, and proper, so it is a closed point of $\Bbb A^1_{\overline{k}}$). Thus $r$ is the number of connected components of $X_{\overline{k}}$.