Definition of a function? I have been given the definition of a function as follows: "Let $A,B$ be non-empty sets. Then a function (mapping) $f:A\to B$, is a rule that associates each element $a\in A$ a unique element $b\in B$. We say $f$ maps $a$ into $b$, and write $f(a)=b$."
Is it really necessary that a unique element $b\in B$ is mapped to by an element $a\in A$. As an example consider the function $f(x)=x^2$ with $A=\mathbb{R}$ and $B=\mathbb{R^+}$, it is easily seen that elements in the codomain of the function will be mapped to twice so each element in $A$ won't map to unique elements in $B$.
 A: Try to understand functions in this manner :
$A=$Items for sale in a shop
$B=$Prices of items
So if you go to the shop to buy something , what will happen  ? 
For each item in $A$ , the shop , has a unique price.
And no item has different prices. Ex : Same pen cannot be priced as 1 Dollar and 2 Dollars. (Uniqueness of the mapping)
And a pen can be 1 Dollar and a chocolate can be 1 Dollar too. (same as $f(x)=x^2$ )
Here $f$ = What is the price of the item you gonna buy ?
And $x$ = Item you gonna buy
And $f(x)$ = Price of your item
A: I think you misunderstood the word uniquely here. Uniquely means "can be determined with no ambiguity" here. Take your example. If I give you a real number $x$, can you determine $f(x)$ without ambiguity? Of course! It's just $x^2$! 
It is true that both $2$ and $-2$ would give us $4$, but that's a different story.
Consider this example. If I want to define a function $f:\mathbb{R^+}\to\mathbb{R}$. The input is $x$ and $f(x)$ would give me $y$ such that $y^2=x$. This would not be a valid function since $f(4)=2$ but $f(4)=-2$.
A: "unique" means unique to that $a$.  $a$ gets mapped to $b$ and $a$ never gets mapped to anything else.  Now, lots of other elements might also be mapped to the very same b.  Example f(x) = b is a function.  f(a) -> b, f(c)->b, f(d) ->b, etc.
But for each a $\in$ A, f(a) has a distinct defined value.  There is no c $\ne$ b such that f(a) = b, but also f(a) = c.  That's not possible.  f(a) must be ... unique...
Okay, if it were up to me I wouldn't call it "unique" as that could lead to the misconception that if a $\ne$ c then f(a) can't be equal to f(c).  That is false.  As you showed if $f(x) = x^2$ then $f(2) = f(-2)$.  What the definitions does say is that if $g(x) = \sqrt(x)$ it is not possible to have f(4) = 2 and also have f(4) = -2. It can't be both. f(4) must have a ... unique ... value.
