TITLE: Theoretical function question
QUESTION [6 upvotes]: Suppose we have the function $f(x)= x^2 $. This function associates real numbers with real numbers ( $f:\mathbb{R}\rightarrow \mathbb{R}$). Now, what i get confused sometimes is what exactly the function is. Sometimes textbooks compares functions with a machine that have raw material / inputs (in this case the real numbers) and then processes it into an output (which can be any number in the codomain). So, what I get confused is: the function is the operator (in this example raising to a power) or the general concept of 'transforming' a number? Like, if we use another example $f(x)= x + 2 $, is the function an operator (the addition), a process that transforms number or something else more general and the operator is part of the function, only an association of numbers from the domain to the codomain?

REPLY [6 votes]: Your confusion is quite justified, and historically accurate, even!
Historical Prelude
For some context, I'll quote a few snippets from Remmert's fantastic book, Theory of Complex Functions.

The word "function" occurs in 1692 with Leibniz as a designation for
certain magnitudes (like abscissae, radii of curvature, etc.) which depend
on the points of a curve, these points thought of as changing or varying. As early as 1698 in a letter to Leibniz, Joh. Bernoulli spoke of "[...] magnitude which is
built up from a variable and any constants whatsoever [...]"

and Euler

[...] called any analytic expression, involving a variable and
constants, a function.

So, the mathematical word "function" has its roots in these sorts of things - very nice, continuous (often enough, smooth even!) functions given to us by evaluating nice algebraic expressions at certain inputs; the "function machine" concept that we know and love.
Still getting information from Remmert's book, we learn that Dirichlet (nearly 150 years later, around the 1830s) pushed the boundaries, defining a function $f(x)$

[...] equal to a certain constant
$c$ whenever the variable $x$ takes on a rational value and equal to another
constant $d$ whenever this variable is irrational [...]"

and finally going so far as to consider functions in a very modern way, saying

[...] in fact one need not even think of the dependence as given by explicit mathematical operations."

My point here is that it's very natural to view functions in the "Take $x$, and square it" or "add $2$ to $x$" kind of way, and that it was a very long journey to begin thinking of functions as mere associations (with certain easily-fulfilled properties) between objects in two sets.

The modern interpretation is indeed that a function $f\colon X \to Y$ is simply a set of ordered pairs $\{(x, y): x \in X, y \in Y\}$ in which each element of $X$ appears as a "first coordinate" exactly once in the set of ordered pairs.
Of course, if you do have a rule such as \begin{align*}f\colon X &\to Y \\ x&\mapsto f(x) =  x^2\end{align*}
there's a great benefit to viewing the function $f$ as a sort of machine that turns input $x$'s into output $x^2$'s! The modern view simply says this isn't necessarily true of all functions (at least, it isn't necessary for a function to be summed up so tidily with a simple formula), and that it's the association of each $x$ with its $x^2$, or the set of ordered pairs $\{(x, x^2): x \in \Bbb R\}$ that's really the squaring function $f\colon \Bbb R \to \Bbb R$.
I personally only think this way when it's strictly necessary to be pedantic, and quite like the "transformation" aspect; that functions are the "movers and shakers" of the math world.