Let $k$ be an algebraically closed field. Consider the Zariski-closed subset $Y=Z(xw-yz)\subset k^n$. On $U=Y\setminus Z(y,w)$ we consider the function $$ f\colon U\to k, P=(a,b,c,d)\mapsto \begin{cases} a/b &\text{if $P\in U\setminus Z(y)$,}\\ c/d & \text{if $P\in U\setminus Z(w).$} \end{cases} $$ My lectures notes claim that this is an example of a function that cannot be written as $f=g/h$ for $f,g\in k[x,y,z,w]$. I haven't been able to actually prove this. What I checked was that $xw-yz$ is an irreducible polynomial, and hence $Z(xw-yz)$ is irreducible. This would mean that if there were $g,h\in k[x,y,z,w]$, then $x/y=f/g$ on $U\setminus Z(y)$, and hence $xg=yf$ (since $U$ is also irreducible). Likewise $z/w=f/g$ yields $zg=wf$ on $U$. I can't find a contraction using this, which I need. Could someone help me out?
This question has been asked before (e.g. here: An example of a regular function over an open set), but the accepted answer talks about Cartier divisors, which I haven't seen before, so I'm actually hoping there is a more elementary argument.
NOTE. The following proof is incorrect, as indicated in the comment.
I don't think the answer you linked use anything about Cartier divisor. Note that $f$ is undefined only at points in $Z(y,w)$, so if $f=g/h$ where $g,h\in k[x,y,z,w]$, then $Z(y,w)=Z(h)$. But this is not possible.
If $y\mid h$ then any $(x,0,z,w)\in k^4$ with $w\ne 0$ lies in $Z(h)$ but not $Z(y,w)$.
If $y\nmid h$. If $\text{deg}_yh\ge 1$, i.e. $h= y^nP_n(x,z,w)+\ldots+P_0(x,z,w)$ for $n\ge 1$ and $0\ne P_n(x,z,w)$. Because $0\ne P_0,P_n$ so $Z(P_0)\cup Z(P_n)=Z(P_0P_n)\ne k^4$, meaning there exists $(x_0,z_0,w_0)\in k^3$ s.t. $P_n(x_0,z_0,w_0)\ne 0$ and $P_0(x_0,z_0,w_0)\ne 0$. Thus, $h(x_0,y,z_0,w_0)\in k[y]$ has solution $y'\ne 0$.
If $\text{deg}_yh=0$ and $y\nmid h$, then $h=h(x,z,w)\ne 0$. If we can find $(x_0,z_0,w_0)$ s.t. $h=0$, then $(x_0,y,z_0,w_0)\in P(h)$ for any $y\ne 0$, meaning $P(h)\ne P(y,w)$. Else, $P(h)=\emptyset\ne P(y,w)$.