How to write Latex piecewise function with left operator or cases environment.

First of all, modifiy your preamble adding

\usepackage{amsfonts}

Latex piecewise function with left operator

\begin{equation*}
y = f(x) = \lvert x \rvert = \left\{
        \begin{array}{ll}
            -x & \quad x \leq 0 \\
            x & \quad x \geq 0
        \end{array}
    \right.
\end{equation*}
\[\begin{equation*} y = f(x) = \lvert x \rvert = \left\{ \begin{array}{ll} -x & \quad x \leq 0 \\ x & \quad x \geq 0 \end{array} \right. \end{equation*}\]

Latex piecewise function with cases environment

\begin{equation*}
g(x)=\begin{cases}
          x \quad &\text{if} \, x \in \mathbb{Q} \\
          -x \quad &\text{if} \, x \notin \mathbb{Q} \\
     \end{cases}
\end{equation*}
\[\begin{equation*} g(x)=\begin{cases} x \quad &\text{if} \, x \in \mathbb{Q} \\ -x \quad &\text{if} \, x \notin \mathbb{Q} \\ \end{cases} \end{equation*}\]