Functions, small query. I am interpreting the definition of a function as:' A function has a specific set of inputs (domain) and outputs (range), governed by a specific rule (function). 
Is that correct? 
What is a co-domain? 
Does a function have to be one-to-one, to be a function? 
For example:
$$f(x) =x^2 $$is not a function but $$f(x) =x^2\quad for\quad x\ge0\quad is? $$
What does the following, mean? (in the context of the definition of a function). 
$$ x\in X\quad y\in Y ,\ such\ that \ f:X\to Y$$
The only thing I can understand is $f:X \to Y$.
Which reads as the function $f$ such that $X$ results in$Y$, right? 
I don't quite understand the notation 
$$ x\in X\quad y\in Y$$
And lastly in this context, what is the difference in the use of capital letters and lowercase letters, for example if i wrote:
$$ x\in X\quad y\in Y ,\ such\ that \ f:x \to y$$,
How would this be incorrect, as usually a function is written as $f(x) =y$, right? 
I do apologise if this is all trivial and simple to understand. 
Thank you for you assistance in advance. 
 A: The idea underlying what you call a "definition of function" sounds pretty accurate to me. Given two sets $A$ and $B$, a function $f:A\rightarrow B$ is a "rule", as you wrote, which sends each element of $A$ to one and only one element of $B$. Note that this definitions is made by three components: the set $A$ (the domain), the set $B$ (the codomain) and the rule $f$.
With this definition in mind, which is a clear version of yours, some of your questions have an immediate answer, some others are just nonsense.
E.g., when you write $f(x)=x^{2}$, you do give the "rule", but who is the domain? Who is the codomain? 
ABOUT THE NOTATIONS. We often use capital letters to denote sets and lowercase letters to denote sets' elements. For example, $x \in X$ denote an element $x$ of a set $X$. With this in mind, we write as before $f:X \rightarrow Y$ to denote "a function $f$ with domain the set $X$ and codomain the set $Y$", while the notation $f: x \mapsto y$ denote "a function $f$ that sends an element $x$ to an element $y$".
A: 1) Yes, that is correct.
2) Co-domain is the superset of range. The set of elements where the values of our function can be.
3) No. One-to-one is a special kind of function. What you read somewhere is:
Relation is not a function if for some $x\in X$ there are 2 or more $y_1,y_2\in Y$ such that $f(x)=y_1$ and $f(x)=y_2$.
4) $x\in X, y\in Y$, such that $f:x\mapsto y$ means:
For every $x\in X$, there is $y\in Y$ such that $f(x)=y$.
5) Uppercase letters represent sets, for example $X=\left\{1,2,3,4,5 \right\}$, and lowercase letters represent elements, for example $x=1$. Now we want to say that function is defined for every element $x$ from set $X$.
