Suppose $k$ is algebraically closed, and $f\in k(\mathbb{A}^1)$ is in the field of rational functions over the variety $\mathbb{A}^1$. If we also know that $f^2$ is in the coordinate ring $k[\mathbb{A}^1]$, does it actually follow that $f\in k[\mathbb{A}^1]$ as well?
Writing $f=p/q$ as a quotient of functions $p,q\in k[\mathbb{A}^1]$, the hypothesis $f^2\in k[\mathbb{A}^1]$ implies that $p^2/q^2\in k[\mathbb{A}^1]$. Is it possible to show $q/p\in k[\mathbb{A}^1]$ as well, in order to get that $$ \frac{p^2}{q^2}\cdot\frac{q}{p}=\frac{p}{q}=f\in k[\mathbb{A}^1]? $$
Remark that for $g \in k(\mathbb A^1)$, we have that $g \in k[\mathbb A^1]$ if and only if $v_P(g)\geq 0$ for every $P \in \mathbb A^1$. Since $f^2 \in k[\mathbb A^1]$, and $v_P(f^2)=2v_P(f)$, it follows that $f \in k[\mathbb A^1]$. (This is morally equivalent to Alex's answer.)