# regular functions on intersection of two open sets

Consider the projective space $\mathbb{P}^n$ and let $U_i$ be the open set $x_i \neq 0$. Then $U_i \cong \mathbb{A}^n$ under the isomorphism $(a_0,\dots, a_i,\dots,a_n) \mapsto (a_0,\dots, \hat{a_i},\dots,a_n)$. Sometimes the notation $U_i \cong \mathbb{A}_i^n$ is used. Now the intersection $U_0 \cap U_1$ certainly makes sense since it is a subset of $\mathbb{P}^n$.

Question: But how about the intersection $\mathbb{A}^n_0 \cap \mathbb{A}^n_1$? Is this latter intersection subset of some affine space? In other words, can $\mathbb{A}_0^n,\mathbb{A}_1^n$ be embedded as varieties in a common affine space?

PS: This question is motivated by my effort to understand why the regular functions on $\mathbb{A}_0^n \cap \mathbb{A}^n_1$ are of the form $\frac{g}{x_0^l x_1^m}$ and what does that mean. See also Problem I.3.8 in Hartshorne for further motivation.

The variety $U_0\cap U_1$ is an affine variety. Taking coordinates $x_1,\dots,x_n$ on $U_0$, you can see $U_0\cap U_1$ as the complement of $x_1=0$. Hence, the set of regular functions on it is $k[x_1,\dots,x_n,\frac{1}{x_1}]$. It is clear that such maps are regular, and to see that these are the only ones, just write a map as $\frac{p}{q}$ where $p,q\in k[x_1,\dots,x_n]$ are polynomials without factors. If $q$ is not a power of $x_1$, then it vanishes on $U_0\cap U_1$, so you do not get a regular function.
In order to see that $U_0\cap U_1$ is affine, you need to see that it is equal to $\mathrm{Spec} (k[x_1,\dots,x_n,\frac{1}{x_1}]).$ But $k[x_1,\dots,x_n,\frac{1}{x_1}]$ is isomorphic to $k[x_1,\dots,x_n,y_1]/(x_1y_1-1)$, so you need to see that the map $$(x_1,\dots,x_n)\mapsto (x_1,\dots,x_n,\frac{1}{x_1})$$ is an isomorphism from $U_0\cap U_1$ to the affine variety $\mathrm{Spec} (k[x_1,\dots,x_n,y_1]/(x_1y_1-1))$. This is by computing the inverse, which is just the projection on the first $n$ factors.
Remark: for $n=1$, your variety is isomorphic to $\mathbb{A}^1\setminus \{0\}$ so for $n>1$ you get $\mathbb{A}^{n-1} \times \mathbb{A}^1\setminus \{0\}$.
Second remark: In general, removing a hypersurface of $\mathbb{A}^n$ always gives you an affine variety by the same trick, but this does not work for higher co-dimension subsets.