A function is declared with the arrow \to (an alias of \rightarrow) between its domain and codomain, f: A \to B, and its rule with \mapsto, as in x \mapsto x^2. Composition is f \circ g, the inverse is f^{-1}, and restriction to a subset is f|_A. Injections and surjections get their own arrows, \hookrightarrow and \twoheadrightarrow (the latter from amssymb), and a bijection is often \leftrightarrow or \xrightarrow{\sim}.
Standard functions such as \sin, \cos, \log, \ln, \exp, \lim, \max, \min and \ker are built in and typeset upright with correct spacing. Anything else (image, domain, support, sign) should be wrapped in amsmath’s \operatorname{Im} or declared once with \DeclareMathOperator{\dom}{dom}; plain Im(f) would be set as the product of two italic variables. Piecewise definitions use the amsmath cases environment: f(x) = \begin{cases} a & x > 0 \\ b & x \leq 0 \end{cases}.
Load \usepackage{amsmath} for \operatorname, \DeclareMathOperator, cases and \xrightarrow, and amssymb for \twoheadrightarrow. Our guide to math functions in LaTeX covers operators, limits and function spacing in more depth.