Notation of functions which get a element of a pair

Given a pair $(a, b) \in A \times B$, I would like to know how to write the functions which get the first element and the second element of the pair...

In a programming language, one can write $\textit{fst}: A \times B \rightarrow A$ and $\textit{fst} : (a,b) \mapsto a$. $\textit{snd}: A \times B \rightarrow B$ and $\textit{snd}:(a,b) \mapsto b$. Can we write same thing in mathematics?

-
sure these are well defined functions – Dominic Michaelis Feb 19 '13 at 23:58
Are you sure they are conventional in mathematics? – SoftTimur Feb 19 '13 at 23:59

Yes, those are perfectly good functions. They are called projection functions and are often (but not always) written as $\pi_1$ and $\pi_2$.

Projection functions play an important role in the definition of the primitive recursive functions of computability theory. In this context, they are often written as $P^2_1$ and $P^2_2$, where the superscript indicates the total number of arguments, and the subscript shows which of the arguments is selected.

They are also an essential component of the category-theoretic definition of products; in category theory to prove that some object $X$ is a product $A\times B$ is precisely to give its projections $\pi_A:X\to A$ and $\pi_B:X\to B$ and show that they have certain characteristic properties.

-

Generally people use $\pi$ because "projection" starts with a "p". You would want to specifically say in whatever proof you're writing that "$\pi_i$ is projection onto the $i^\text{th}$ component."

These are used quite heavily in mathematics.

-