Can the idea of a 'function of a variable' be made rigorous? Suppose that $y=x^2$. Very often people describe this relationship by saying that '$y$ is a function of $x$'. It seems that there are several logical problems with this statement:

*

*A function is simply a set of ordered pairs of numbers. It does not matter how you denote the input of a function, and there is no doubt that $x \mapsto x^2$ and $y \mapsto y^2$ are the same function. Indeed, in both cases $y$ and $x$ are simply dummy variables used to illustrate what happens when you plug in an arbitrary number into the function.

*$x$ and $y$ are often described as variables that are related in some way; in this case, with $y$ being the square of $x$. However, in this Math Overflow post  Mike Shulman states that the idea of a variable is 'not a standard part of modern formalizations of mathematics'. Strangely, the idea of a dummy variable makes much more sense to me. For instance, when we say 'consider the function $f$ defined by $f(x)=x^2$ for all $x$', it is clear that the only purpose of the letter $x$ is to declare that the second entry of the ordered pair is the square of the first.

*If $y=x^2$ and $x \geq 0$, then we just as well might write $x=\sqrt{y}$. This flexibility is not really allowed when speaking of functions: $x \mapsto x^2$ and $x \mapsto \sqrt{x}$ are certainly not the same function. Perhaps it is possible evade this by treating $x$ as the independent variable and $y$ as the dependent variable.

Some authors get around this ambiguity by saying that 'the function $y=x^2$' is just a shorthand for 'the function $y(x)=x^2$', which in turn is just a shorthand for 'the function $y$ defined by $y(x)=x^2$ for all x'. However, this doesn't seem to align with how people treat the relationship between $y$ and $x$ in practice. Even if we accept that $y=x^2$ is simply a shorthand for $y(x)=x^2$, it still seems that there is a tendency towards treating $x$ as an independent variable representing the input of $y$, as opposed to simply a dummy variable that can be replaced by any other letter.
So I ask, in formal mathematics, is it possible to interpret $y=f(x)$ in such a way that $x$ and $y$ are variables representing the inputs and outputs of a function? And if so, how should the statement '$y$ is a function of $x$' be understood?
 A: When we say “$y=f(x)$”, we are stating a typographical convention that we are going to adopt in the present context: Namely, whenever the letters $x$ and $y$ appear, the values to which they refer are connected by the functional relationship $f$. The terminology “$y$ is a function of $x$” is confusing. While it is still employed by many people who use mathematics, it is often avoided by present-day mathematicians, who are aware that $y$ and $f$ refer to quite different types of mathematical object.
For example, consider the function $$f:\Bbb R\to\Bbb R_{\geqslant0}:x\mapsto f(x):= x^2.$$ In this case, $f$ may be identified with a certain subset of $\Bbb R\times\Bbb R_{\geqslant0}$. Quite separately, and in addition, we may adopt the naming convention of using $y$ instead of $f(x)$. But $y$ is just some element of $\Bbb R_{\geqslant0}$, albeit dependent on $x$, while $f$ is a quite particular subset of  $\Bbb R\times\Bbb R_{\geqslant0}$ (which determines the relationship between $x$ and $y$).
In this context, the notation “$y=y(x)$” is often used, which further reinforces the confusion between $y$ and $f$. This sort of notation may be convenient for (say) practical engineering calculations, but it's not a good place to start when you want to maintain a clear mathematical concept of function.
In the above, for simplicity, I have adopted the convention of identifying a function with its graph. In some branches of mathematics this is inconvenient, and to specify a function it is necessary to specify a codomain for it (of which the range of the function is a subset).
A: A function is a subset $f$ of $A\times B$ with$$\forall x_1\in A\forall x_2\in B\forall x_3\in B((x_1,\,x_2)\in f\land(x_1,\,x_3)\in f\to x_2=x_3).$$(Some would say a "function" can be multivalued, but I'll address that in another paragraph.) If some $(x_1,\,x_2)\in f$, we write $x_2=f(x_1)$, thereby forgetting the set theory. But if all we know about values $x,\,y$ is $y=f(x)$ or equivalently $(x,\,y)\in f$, recalling $f$ is a set is again useful: $f$ is just the set of values of $(x,\,y)$ consistent with our knowledge. So "$y$ is a function of $x$" is shorthand for "the set of values of $(x,\,y)$ consistent with our knowledge is a function", which is a nontrivial statement because of the unique-images property of functions.
Even if a "multivalued function" is what you have in mind, knowing which function $y$ is of $x$ means knowing the set of values of $(x,\,y)$ consistent with our knowledge. (Indeed, this is true regardless of how we define "function", although in this more general case we lose the nontriviality observed above.)
Feel free to repeat this analysis for concepts other than knowledge. For example, if $x,\,y$ are related by a physical process, the "function" is the set of physically realizable values of $(x,\,y)$. (There's no need to worry about how other variables may come into play, because we can assume $x,\,y$ are tuples in their own right, thereby folding everything relevant into this discussion. Even randomness/indeterminism doesn't trip us up, if you use what are called random functions, which have a nuanced but ultimately non-ruinous effect on the discussion similar to that of multivalued functions. We might end up saying "there exists a function $f$ for which $y$ is the function $f$ of $x$, but the choice of $f$ is random, so itself has a probability space for its possible values".)
A: A formal notation is
$$f:X\to Y:x\to f(x)$$ where $X,Y$ and the expression of $f$ are specified.
When you write $y=f(x)$, it must be obvious from context that

*

*you are defining a function $y(x)$,


*$X$ and $Y$ are known (such as $\mathbb R$).
Otherwise, the identity $$y=f(x)$$ might denote an equation where $y$ is explicitly known in terms of $x$ and you could be interested to express $x$ in terms of $y$. But again, this must be clear from context.
