Latex function diagram

Just give the labels names and connect them.

\documentclass[10pt]{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,fit}
\begin{document}
\begin{tikzpicture}
    \foreach[count=\i] \lseti/\lsetmi in {A/{$a$,$b$,$c$},B/{5,6,$z$}} {
        \begin{scope}[local bounding box=\lseti, x=2cm, y=0.5cm]
        \foreach[count=\j] \lj in \lsetmi {
            \node[minimum width=1em] (n-\j-\lseti) at (\i,-\j) {\lj};
        }
        \end{scope}
        \node[ellipse, draw, fit=(\lseti), 
        label={[name=l-\lseti]above:$\lseti$}] {};
    }
    \draw[->] (n-1-A) -- (n-1-B);
    \draw[->] (n-2-A) -- (n-2-B);
    \draw[->] (n-3-A) -- (n-3-B);
    \draw[->] (l-A) -- node[above]{$f$}(l-A.center-|l-B.west);
\end{tikzpicture}
\end{document}

enter image description here

And here is a complement to user1146332's answer. If you want to have the vertical alignment proper, it is arguably even better to use anchor=base and to give the nodes some text height and text depth since this works also with characters that go below the baseline.

\documentclass[10pt]{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,fit}
\begin{document}
\begin{tikzpicture}
    \foreach[count=\i] \lseti/\lsetmi in {A/{$a$,$b$,$g$},B/{5,6,$z$}} {
        \begin{scope}[local bounding box=\lseti, x=2cm, y=0.5cm]
        \foreach[count=\j] \lj in \lsetmi {
            \node[minimum width=1em,anchor=base,text height=1.4ex,text
            depth=0.25ex] (n-\j-\lseti) 
            at (\i,-\j) {\lj};
        }
        \end{scope}
        \node[ellipse, draw, fit=(\lseti), 
        label={[name=l-\lseti]above:$\lseti$}] {};
    }
    \draw[->] (n-1-A) -- (n-1-B);
    \draw[->] (n-2-A) -- (n-2-B);
    \draw[->] (n-3-A) -- (n-3-B);
    \draw[->] (l-A) -- node[above]{$f$}(l-B);
\end{tikzpicture}
\end{document}

enter image description here


As a little complement to Schrödinger's answer:

If the figure is placed into a text rich context the reader's impression will most likely be disturbed because of the different vertical alignment of the characters.

To get the vertical alignment right you can set the anchor of the nodes to the baseline (i.e. base) of the characters.

enter image description here

\documentclass[10pt]{article}
\usepackage{tikz}
\usetikzlibrary{math,arrows,positioning,shapes,fit,calc}
\begin{document}
\begin{tikzpicture}[
    elems/.style = {
        minimum width=1.4em,
        anchor=base
    },
    helper/.style = {
        help lines, 
        red, 
        shorten <=-1cm, 
        shorten >= -1cm
    }
]
    \foreach[count=\i] \lseti/\lsetmi in {{A}/{$a$,$b$,$c$},{B}/{5,6,$z$}} {
        \begin{scope}[local bounding box=\lseti, x=2cm, y=0.5cm]
            \foreach[count=\j] \lj in \lsetmi {
                \node[elems] (n-\j-\lseti) at (\i,-\j) {\vphantom{5}\lj};
            }
        \end{scope}
        \node[ellipse, draw, fit=(\lseti), label={[elems, yshift=0.25em, name=\lseti]$\lseti$}]  {};
    }

    \draw[->] (A) -- node[above]{$f$} (B);
    \draw[helper](A.base) -- (B.base);

    \foreach \i in {1,2,3} {
        \draw[->] (n-\i-A) -- (n-\i-B);
        \draw[helper](n-\i-A.base) -- (n-\i-B.base);
    }
\end{tikzpicture}
\end{document}

Tags:

Tikz Pgf