Regular functions and morphisms of varieties for field not algebraically closed Let us work over a field that is NOT algebraically closed. Specifically, $K=\mathbb R$.
We can think of the affine line $\mathbb A_K^1$ as a ringed space $(\mathbb A_K^1,\mathcal O_{\mathbb A^1_K})$, where for an open set $U\subseteq\mathbb A^1_K$, we have $\mathcal O_{\mathbb A^1_K}(U)=(\text{the ring of regular functions over $U$})=\{\frac fg\mid f,g\in K[x] \,\&amp;\,(\forall P\in\mathbb A^1_K)(g(P)\ne 0)\}$.
I think that according to this, $\frac1{1+x^2}$ should be a regular function over the entire $\mathbb A^1_K$. Moreover, it seems to me that $f:\mathbb A_K^1\to\mathbb A_K^1$ defined as $f(x)=\frac1{1+x^2}$ is a morphism from the ringed space $(\mathbb A^1_K,\mathcal O_{\mathbb A^1_K})$ to itself (in the sense that it pulls back regular functions to regular functions). Am I right?
I am probably confused by either different sources using different definitions or me seeing statements that only hold for $K$ algebraically closed. E.g. the Wikipedia article Morphism of algebraic varieties states

The regular functions on $\boldsymbol A^n$ are exactly the polynomials in $n$ variables [...]

,
which I only agree with for $K$ algebraically closed and not in the case I've shown above.
The definition of a regular map needs to be modified substantially when you work over a field that isn't algebraically closed. There are different ways to set things up at different levels of sophistication; one way to say it is that regular maps should have the property that they remain regular maps after extension of scalars, and your proposed map does not remain regular after extension of scalars to $\mathbb{C}$ because of the poles at $x = \pm i$.
You are implicitly thinking only in terms of what are called the $K$-points of a variety; this is only safe to do when $K$ is algebraically closed. For example if $K = \mathbb{F}_q$ is a finite field then the polynomial $f(x) = x^q - x$ vanishes on $K$-points but is not considered to be identically zero as a regular map, because it does not remain identically zero after extension of scalars, e.g. to the algebraic closure $\overline{\mathbb{F}_q}$. We also have issues such as varieties, for example $\text{Spec } \mathbb{R}[x, y]/(x^2 + y^2 + 1)$, which have no $K$-points (here $K = \mathbb{R}$) but which it would be incorrect to consider empty; here again the issue is that points exist after extension of scalars.
Here I am implicitly taking a functor of points approach which I personally find conceptually cleanest. The standard approach you will find in most textbooks is based on the Zariski spectrum of all prime ideals (which capture points over extensions of scalars but somewhat indirectly), not just maximal ideals corresponding to $K$-points.
On the other hand, there is a somewhat separate field of real algebraic geometry in which we only consider $\mathbb{R}$-points, and which is mostly not studied by algebraic geometers but by model theorists or something like that.
If you define $\mathcal{O}(\mathbb{A}^1_{\mathbb{R}})$ as the set of functions with the following property (P1):
P1. $f: \mathbb{R}^2 \rightarrow \mathbb{R}$ with the property that for any point $p\in \mathbb{R}^2$ there is an open subset $U(p)\subseteq \mathbb{R}^2$ and two polynomials $p(x),q(x)\in \mathbb{R}[x]$ such that the restriction $f_{U(p)}$ of $f$ to $U(p)$ satisfies $f_{U(p)}=\frac{p(x)}{q(x)}$,
then it follows (as you noted) the function $\frac{1}{x^2+1}$ is a regular function on $\mathbb{R}^2$. Hence $\mathcal{O}(\mathbb{A}^1_{\mathbb{R}})\neq \mathbb{R}[x]$.  If $z=a+ib \in \mathbb{C}$ with $b\neq 0$, it follows
the polynomial $p_z(x):=(x-z)(x-\overline{z})=x^2-2ax+a^2+b^2\in \mathbb{R}[x]$ is an irreducible polynomial - it has no real roots.
Hence if you use definition P1 to define the ring of regular functions, it follows the function $f(x):=\frac{1}{p_z(x)}$ is a regular function. If $S\subseteq A:=\mathbb{R}[x]$ is the set of polynomials on the form $p(x):=\prod_{z_i\in \mathbb{C}-\mathbb{R}} (x-z_i)(x-\overline{z_i})$ it follows $S$ is a multiplicatively closed subset, and the ring of fractions $S^{-1}A$ is a sub-ring of $\mathcal{O}(\mathbb{A}^1_{\mathbb{R}})$. Hence with definition P1 it follows the ring $\mathcal{O}(\mathbb{A}^1_{\mathbb{R}})$ is much larger than $A$.
Question: &quot;The regular functions on $\mathbb{A}^n$ are exactly the polynomials in n variables [...], which I only agree with for K
algebraically closed and not in the case I've shown above.&quot;
Answer: You want (for many reasons) to recover the polynomial ring $\mathbb{R}[x]$ as the ring of global sections of the structure sheaf. This problem is &quot;solved&quot; by the affine spectrum $Y:=Spec(\mathbb{R}[x])$. What you define above is a &quot;sheaf of rings&quot; on the real algebraic variety $\mathbb{A}^1_{\mathbb{R}}$ in the sense of &quot;real algebraic geometry&quot;, and this sheaf differ from the sheaf defined using the affine spectrum in the sense of Hartshornes book &quot;Algebraic geometry&quot;. The topological space of the variety $X:=\mathbb{A}^1_K$ you consider above is the set of real numbers $r\in \mathbb{R}$. The topological space of $Y$ consists of all real numbers plus the set of all maximal ideals in $A:=\mathbb{R}[x]$ with residue field the complex numbers. Hence the two topological spaces differ. Your space $X$ is by definition the set of rational points $Y(K)$ with the induced topology.
Note: There is nothing &quot;wrong&quot; with the ringed space $(X, \mathcal{O}_X)$ - it has properties different from $Y$. In real algebraic geometry it follows projective space $\mathbb{P}^n_K$ may be realised as a real affine algebraic variety - there is a closed embedding into real affine space. Moreover any real projective variety is affine. The reason for this is that the structure sheaf has more local sections, as you have observed in your comment above. Hence there are &quot;more maps&quot;. This does not happen with the Hartshorne definition: You cannot construct a closed embedding of $Proj(k[x_0,..,x_n])$ into
affine space $Spec(k[y_1,..,y_d])$.
As an example: The global section $s(x):=\frac{1}{p_z(x)}$ for $z\in\mathbb{C}-\mathbb{R}$ is a unit - the polynomial $p_z(x)$ is non-zero on $\mathbb{R}$, and with your definition of &quot;regular map&quot; it follows $s(x)$ is a global section - it lives in $\mathcal{O}_{\mathbb{A}^1_K}(\mathbb{A}^1_K)$. The function $s(x)$ is not a global section of $\mathcal{O}_Y(Y)\cong \mathbb{R}[x]$.
Real algebraic varieties are relevant for people studying complex algebraic varieties and their topology. You may for any complex projective manifold $X \subseteq \mathbb{P}^n_{\mathbb{C}}$ construct the Weil restriction $W_{\mathbb{C}/\mathbb{R}}(X)$. If $dim(X)=d$ it follows  $dim(W_{\mathbb{C}/\mathbb{R}}(X))=2d$ and $W_{\mathbb{C}/\mathbb{R}}(X)$ is a smooth scheme over $\mathbb{R}$ - the &quot;underlying&quot; real algebraic variety of $X$. The variety
$W_{\mathbb{C}/\mathbb{R}}(X)$ has the same topology as $X$ and you may realize $W_{\mathbb{C}/\mathbb{R}}(X)$ as a real affine algebraic variety. Hence the &quot;underlying&quot; real algebraic variety of $X$ is affine. Moreover: Any real affine algebraic variety may (topologically) be realized as a hypersurface. Hence if you study the topology of $X$ it follows there is a real affine hypersurface $Z(f)$ with the same topology as $X$ (here I am extremely &quot;vague&quot;).
You find this discussed here:
https://math.stackexchange.com/posts/3957121/edit
and here:
Different definitions of regular map (between affine varieties)?