Make a math function like a picture below

I would use array (and \colon instead of :):

\documentclass{letter}
\usepackage{amsmath}
\usepackage{array}
\begin{document}
\[
\begin{array}{l@{$\;$}c@{$\;$}c@{$\;$}c}
    \phi\colon & R &\to& R\\
    & a+b\sqrt{2}&\mapsto &a+b 
\end{array}
\]
\end{document}

enter image description here


The following requires two compilations with any change within the maximum width of every \eqmakebox[<tag>] using the same <tag>. A second (optional) argument can be specified for aligning the content to the left or right (centred is default).

enter image description here

\documentclass{article}

\usepackage{amsmath,eqparbox}

\begin{document}

\begin{align*}
  \phi \colon \eqmakebox[ab2]{$      R      $} \to     \eqmakebox[ab]{$  R  $} \\
              \eqmakebox[ab2]{$a + b\sqrt{2}$} \mapsto \eqmakebox[ab]{$a + b$}
\end{align*}

\end{document}