In his excellent notes on algebraic geometry, David E. Speyer takes great care to impress upon the reader something that in most texts are handled in a very abstract and implicit manner, namely that on affine algebraic set $X \subseteq \mathbb{A}^n$, the ring of regular functions, that is, functions that can be expressed as ratios of polynomials at every point in $X$ (not necessarily as the ratio of the same polynomials everywhere!) is isomorphic to the ring of polynomials $\mathbb{F}[x_1 , \dots , x_n]$ restricted to $X$.
In the process of proving a theorem about non-trivial idempotents in the coordinate rings of an affine algebraic set, Speyer makes the point that if an affine algebraic set $X$ is disjoint, and so can be expressed as a union of two non-empty closed sets $X_1, X_2$, then you can define a regular that is 0 everywhere on $X_1$ and 1 everywhere on $X_2$, and this then corresponds to some polynomial $f \in \mathbb{F}[x_1 , \dots , x_n]$ which when restricted to $X_1$ clearly must be equal to 0, and when reduced to $X_2$ clearly must be 1. Unfortunately, he never provides an example of such a situation, nor what $f$ actually is.
This made me curious.
Let $X = X_1 \cup X_2 \subset \mathbb{A}^n$ be a disjoint affine algebraic set, and define a regular function on $X$ such that $f=g$ everywhere on $X_1$ and $f=h$ everywhere on $X_2$, and $g,h \in \mathbb{F}[x_1 , \dots , x_n]$, such that $g \neq h$. This is clearly a regular function, and so, there must exist some polynomial $p \in \mathbb{F}[x_1 , \dots , x_n]$ such that $p|_{X} = f$, that is, $p|_{X_1} = g$ and $p|_{X_2} = h$. See accompanying figure.
My question is, given such a disjoint affine algebraic set $\in \mathbb{A}^n$ and two polynomials $g,h \in \mathbb{F}[x_1 , \dots , x_n]$, does there exist some sort of general algorithm for finding this elusive $p \in \mathbb{F}[x_1 , \dots , x_n]$?
Looking forward to your responses!
