What actually is a function? I've got confused about the definition of a function. As what the German mathematician Peter Dirichlet said is:

If a variable y is so related to a variable x that whenever a numerical value is assigned to x, there is a rule according to which a unique value of y is determined, then y is said to be a function of the independent variable x.

In this way, a function is a variable because the variable y is a function.
But here I found another definition:

A function is a relationship between a set of inputs and outputs, where each input produces only one output.

And it says that a function is a relationship.
I even saw that such a function $f : X \to Y$ can even be defined as a set of ordered pair $\{(x,y)|x \in X \land y \in Y \}$.
Doesn't this mean that a function is a set?
So what actually is a function? Is it a variable or a relationship, or another kind of mathematical object?
 A: If a variable $y$ is so related to a variable $x$ that whenever a numerical value is assigned to $x$, there $\underline{is \ \ a\ \ rule}$ according to which a unique value of $y$ is determined, then $y$ is said to be a function of the independent variable $x$.
Here function means rule.
$A=\{(x,y)|x∈X,y∈Y\}$ is graph of function $f :X \rightarrow Y$ if $y=f(x)$.
$A \subset X \times Y$ is relation in general untill we assign a rule such that unique value of $y$ is determined for a give $x$.
Function is a rule.
Function is not a variable.
If value of $y$ depends on $x$ via some rule (function) $y=x^2$ then
we say $y$ is function of $x$.
$y$ is a function of $x$ means $y$ is dependant variable $x$ is independant variable. Function is a rule by which we will gate value of $y$ for given $x$.
A: Intuitively a function is a way of mapping a set of values (the domain) to a (possibly another) set of values (the codomain) so that each element in the domain is mapped exactly once.
The issue is how do we define this concept of "a way of mapping" that's.... not a well defined mathematical thing.
Mathematicians decide well if each item in the domain is "mapped" to another the what we actually have on our hands are a bunch of pairs if $x_{input}$ somehow "mapped" or glued to a $y_{output}$.  As they are pairs we can just describe them as a set of ordered pairs where each pair is an $(x_{input},y_{output})$ ordered pair.
If it helps you do visualize it if our function is the rule $x \mapsto x^2$ or $f(x) = x^2$ we can write the function as the set of all pairs $(x,x^2)$ or $(x,f(x))$.
Thus the definition of sets is really the most concrete one.  This is actually exactly the same as relationship one because the same problems we have describing what a function is, we have defining what a "relationship" is.  Mathematicians who define "functions" as sets of ordered pairs will also define "relationship" as a set of ordered pairs.  That is if we say $a$ relates to $b$ in some way we mean they are glued together as an ordered pair $(a,b)$ and are in the set of all pairs of relatives.
(The only difference between a function and a relation is that functions must have exactly one ordered pair for each input value.  A relation may have many for a value or may have none for a value.)
The first definition?  Well, that's trying to explain the writing of a function as rule between variables.  That is $y = f(x) = someway\ of\ connecting\ values\ of\ x\ to\ values\ of\ y$.  But it is still consistent as our rule leaves us with a set of $(x, y=f(x))$ pairs on our hands.
So all three of those are basically the same thing.
A: A function is indeed a set. The idea of a function as a rule is the intuitive picture that we want to capture with the definition. The thing is that the most commonly accepted foundation theory for mathematics is Zermelo-Fraenkel Set Theory, which says that every object in mathematics is a set (almost every, there are parts of mathematics that require different foundations allowing objects that are not sets,  like category theory). This includes functions: A function $f:X\rightarrow Y$ is a subset $G$ of $X\times Y$ such that for every $x\in X$ there is a unique $y\in Y$ such that $(x,y)\in S$. The set $S$ is the function $f$.
That being said, in everyday mathematics you will give a function as an actual rule, like $$f:\mathbb N\rightarrow\{0,1\},\qquad f(n)=\begin{cases}1 & \text{ if }n\text{ even}\\
0 & \text{if }n\text{ odd}\end{cases}$$
and call the set $S$ above the "graph of $f$", when a set theorist would tell that the "graph" is $f$. So a function is intuitively and can be defined by giving a rule, but it is also a set.
A: It is a set of ordered pairs (relation) from x to y.  When you say $f(3)$ you're saying grab the $y$ corresponding to the pair (3, y).  A function is a relation with the restriction that "each input produces one output" to quote your definition.
In math there are many ways to define the same thing.  So a function is a set, but it could also be formally or intuitively understood in other ways.
