Theoretical function question 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?
 A: 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.
A: Formally, the function is defined to be the set of corresponding ordered pairs of numbers (that is, it is defined to be the set of points on its graph). Informally, in elementary mathematics, it is viewed intuitively as a machine which transforms, and this is of course inherently vague.
A: The formal definition say that a function $f:A\rightarrow B$ is a subset of $A\times B$ that contain only one couple $(x,y)$ for any $x \in A$.
For $A=B=\mathbb{R}$ the set of all these subsets is uncountable, so we ''suspect'' that not all functions can be expressed as machines that transform some input to an output, since the number of this machine is at most countable and this suspect become an exact statement introducing a definition of computable functions.
For our purpose this means that the concept of function is something more than some operation rules given for calculate a real number from another one.  There are function that can be expressed in such way, and are the functions that we use normally, but these are only a countable subset of all the possible functions.
A: The function is the general concept of transforming numbers. Don't be confused with functions such as $(+)$ and $(*)$ these are functions as well with range and domains. $(+):\mathbb{R}\times \mathbb{R} \mapsto  \mathbb{R}$ and $(*):\mathbb{R}\times \mathbb{R} \mapsto  \mathbb{R}$. It's just that we normally write these functions infix meaning in-between arguments rather than before.
A: According to Bourbaki's first volume of Elements of Mathematics - Theory of Sets - a function is a triple $(A, B, G)$, where $A$ and $B$ are two non-empty sets and $G$ is a subset of $A \times B$ such that for all $x \in A$ there exists $y \in B$ such that $(x, y) \in G$. $A$ is called domain, $B$ target set and $G$ graph of the function. I think the strength of this definition lies in the fact that it does not confuse a function for its graph.
