How to draw function domain/co-domain (range) diagram?

I have seen the previous tikz example, similar with this one, but that example does not compile for me, I get 101 errors! How would one code the diagram below in tikz? Thanks, Diegis.

-

One possibility:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning,shapes,fit,calc}

\pgfdeclarelayer{background}
\pgfsetlayers{background,main}

\begin{document}

\begin{tikzpicture}[
every node/.style={on grid},
setA/.style={fill=blue,circle,inner sep=2pt},
setC/.style={fill=red,rectangle,inner sep=2pt},
every fit/.style={draw,fill=blue!15,ellipse,text width=25pt},
>=latex
]

% set A
\node[setA,label=left:$a$] (a) {};
\node [setA,below = of a,label=left:$b$] (b) {};
\node [setA,below = of b,label=left:$c$] (c) {};
\node[above=of a,anchor=south] {$A$};

% set B
\node[inner sep=0pt,right=3cm of a] (x) {$x$};
\node[below = of x] (y) {$y$};
\node[inner sep=0pt,below = of y] (z) {$z$};
\node[above=of x,anchor=south] {$B$};

% set C
\node[setC,label=right:$m$,right = 3cm of x] (m) {};
\node[setC,label=right:$n$,below = of m] (n) {};
\node[setC,label=right:$p$,below = of n] (p) {};
\node[above=of m,anchor=south] {$C$};

% the arrows
\draw[->,shorten >= 3pt] (a) -- node[label=above:$f$] {} (x);
\draw[->,shorten >= 3pt] (b) -- node[label=above:$f$] {} (x);
\draw[->] (c) -- node[label=above:$g$] {} (y);
\draw[->,shorten <= 3pt] (x) -- node[label=above:$h$] {} (m);
\draw[->] (n) -- node[label=above:$u$] {} (y);

% the boxes around the sets
\begin{pgfonlayer}{background}
\node[fit= (a)  (c) ] {};
\node[fit= (x) (z) ] {};
\node[fit= (m) (p)] {};
\end{pgfonlayer}
\end{tikzpicture}

\end{document}


-
Thank you very much, it works beautifully!! Is there a good start, a good tutorial to learn tikz? Nothing beats experience, obviously, but nothing beats a little bit of home reading either! I know nothing on the subject, while I know my way around to write pretty complex math, I am at a complete loss when it comes to drawings, and I am tired of making all visuals in Visio and then inserting them as pictures -- nothing wrong with that, but you don't get a lot of the math symbols in Visio, no Greek letters, no subscript/superscript, a lot of inconveniences... Thank you again, Diegis. –  Diegis Sep 16 '12 at 5:12
@Diegis there's the comprehensive pgfmanual (with lots of examples), the Minimal introduction to TikZ, and a good example gallery at TeXample.net. –  Gonzalo Medina Sep 16 '12 at 5:24