\newcommand{\R}{\mathbb{R}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\fref}[1]{Figure \ref{#1}}                                          % Reference style for figure.
\newcommand{\BigO}[1]{\ensuremath{\mathcal{O}\left(#1\right)}}                  % Big Oh.
\newcommand{\BigOT}[1]{\ensuremath{\widetilde{\mathcal{O}}\left(#1\right)}}     % Big Oh Tilde.
\newcommand{\BigOm}[1]{\ensuremath{\Omega\left(#1\right)}}                      % Big Omega.
\newcommand{\BigT}[1]{\ensuremath{\Theta\left(#1\right)}}                       % Big Theta.
\newcommand{\poly}{\mathrm{poly}}
\newcommand{\vect}[1]{\ensuremath{\mathbf{#1}}}                                 % vector.
\newcommand{\vectsym}[1]{\ensuremath{\boldsymbol{#1}}}                          % vector for symbols.
\newcommand{\mat}[1]{\ensuremath{\mathbf{\MakeUppercase{#1}}}}                  % Matrix for symbols.
\newcommand{\matsym}[1]{\ensuremath{\boldsymbol{\MakeUppercase{#1}}}}            % Matrix for symbols.
\newcommand{\KL}[2]{\ensuremath{\mathbb{KL} \left(#1 \middle\Vert #2 \right)}}   % KL divergence.
\newcommand{\Exp}[2][]{\ensuremath{\mathbb{E}_{#1}\left[#2\right]}}                % Expectation. \Exp[A]{X}: Expectation of X wrt A. 
																		          %              \Exp{X} is just expectation of X.
\newcommand{\ExpBig}[2][]{\ensuremath{\mathbb{E}_{#1}\Bigl[#2\Bigr]}}              % Expectation Using Big braces.
\newcommand{\Expbigg}[2][]{\ensuremath{\mathbb{E}_{#1}\biggl[#2\biggr]}}           % Expectation using bigg braces.
\newcommand{\Var}[2][]{\ensuremath{\mathrm{Var}_{#1}\left[#2\right]}}                % Variance. Usage: \Var[A]{X}: Variance of X wrt A.
\newcommand{\Cov}[2][]{\ensuremath{\mathrm{Cov}_{#1}\left[#2\right]}}                % Covariance
\newcommand{\Tr}[1]{\ensuremath{\mathrm{Tr}\left(#1\right)}}                     % Trace
\newcommand{\Ind}[1]{\ensuremath{\mathbf{1}\left[#1\right]}}                     % Indicator function.
\newcommand{\Norm}[1]{\ensuremath{\left\lVert #1 \right\rVert}}                  % Norm
\newcommand{\NormI}[1]{\ensuremath{\left\lVert #1 \right\rVert}_1}               % L1 Norm 
\newcommand{\NormII}[1]{\ensuremath{\left\lVert #1 \right\rVert}_2}              % L2 Norm 
\newcommand{\NormInfty}[1]{\ensuremath{\left\lVert #1 \right\rVert_{\infty}}}    % Infinity Norm
\newcommand{\NormMax}[1]{\ensuremath{\left\lvert #1 \right\rvert_{\mathrm{max}}}}    % Infinity Norm
\newcommand{\parg}{\makebox[1ex]{$\mathbf{\cdot}$}}                              % Place holder argument.
\newcommand{\Tp}[1]{{#1}^{\top}}												    % Transpose.
\newcommand{\Tpn}[1]{{#1}^{-\top}}	                                             % Neg. Transpose.
\newcommand{\mquad}{\kern-1em}													% Negative quad.
\newcommand{\Ineq}[2][]{\overset{#1}{#2}}                                         % Label inequality e.g. \Ineq[(a)]{=} produces an (a) over =.

% Creating matrices and vectors.
\newenvironment{brsm}
  {\left[\begin{smallmatrix}}
  {\end{smallmatrix}\right]}
\newcommand{\covExample}{\matExample{1}{1}{1}{2}}
\newcommand{\matExample}[4]{\begin{brsm} #1 & #2 \\ #3 & #4 \end{brsm}}
\newcommand{\matrx}[1]{\begin{bmatrix}#1\end{bmatrix}}                           % Short for begin/end bmatrix.         

\newcommand{\InNorm}[1]{{\left\vert\kern-0.2ex\left\vert\kern-0.2ex\left\vert #1 
    \right\vert\kern-0.2ex\right\vert\kern-0.2ex\right\vert}}                    % Induced Norm.

\newcommand{\InNormII}[1]{{\left\vert\kern-0.2ex\left\vert\kern-0.2ex\left\vert #1 
    \right\vert\kern-0.2ex\right\vert\kern-0.2ex\right\vert}_2}                    % Induced 2 Norm (Spectral Norm).

\newcommand{\InNormInfty}[1]{{\left\vert\kern-0.2ex\left\vert\kern-0.2ex\left\vert #1 
    \right\vert\kern-0.2ex\right\vert\kern-0.2ex\right\vert}_{\infty}}           % Induced Infinity norm.

\newcommand{\Abs}[1]{\ensuremath{\left \lvert #1 \right \rvert}}                 % Absolute value.
\newcommand{\Prob}[2][]{\ensuremath{\mathrm{Pr}_{#1}\left\{ #2 \right\}}}        % Probability of event.
\newcommand{\Gauss}[2]{\mathcal{N}\left(#1,\; #2\right)}                         % Gaussian distribution with mean and variance.
\newcommand{\iid}{i.i.d.~}                                                        % IID.
\newcommand{\simiid}{\overset{\mathrm{i.i.d.}}{\sim}}                            % IID distributed.
\newcommand{\Grad}{\nabla}                                                       % Gradient symbol.

% Information Theory
\newcommand{\MI}{\mathnormal{I}}                                                     % Mutual information symbol.

% Logic %
\newcommand{\Lnot}{\neg}                                                         % Logical not
\newcommand{\Land}{\wedge}                                                       % Logical And operator.
\newcommand{\Lor}{\vee}														     % Logical Or operator.
\newcommand{\what}[1]{\widehat{#1}}                                              % wide hat.
%\newcommand{\defeq}{\overset{\Delta}{=}}                                        % Defnition equality
\newcommand{\defeq}{\overset{\mathrm{def}}{=}}                                                      % Defnition equality

% Set theory
\newcommand{\Set}[1]{\{#1\}}                                                     % \Set{a,b,c} = {a,b,c}
\newcommand{\aSet}[1]{\left\{#1\right\}}                                         % Set with automatically resizing braces.
\newcommand{\emset}{\varnothing}                                                 % Empty Set.
\DeclareMathOperator*{\union}{\cup}
\DeclareMathOperator*{\intersection}{\cap}
\DeclareMathOperator*{\Union}{\bigcup}
\DeclareMathOperator*{\Intersection}{\bigcap}

% Floor and Ceil
\newcommand{\floor}[1]{\left\lfloor#1\right\rfloor}
\newcommand{\ceil}[1]{\left\lceil#1\right\rceil}


% Colors
\definecolor{gray}{rgb}{0.7,0.7,0.7}

% Commands for annotations
\newcommand{\TODO}[1]{{\color{red}TODO:}\emph{#1}}
\newcommand{\Red}[1]{{\color{red}#1}}
\newcommand{\Blue}[1]{{\color{blue}#1}}
\newcommand{\Gray}[1]{{\color{gray}#1}}
\newcommand{\Green}[1]{{\color{green}#1}}


% Math operators
\DeclareMathOperator*{\argmin}{argmin}
\DeclareMathOperator*{\argmax}{argmax}
\DeclareMathOperator*{\argsup}{argsup}
\DeclareMathOperator*{\sign}{sign}

% Theorem environments
 \newtheorem{definition}{Definition}
 \newtheorem{proposition}{Proposition}
\newtheorem{assumption}{Assumption}
\newtheorem{problem}{Problem}
 \newtheorem{lemma}{Lemma}
 \newtheorem{theorem}{Theorem}
 \newtheorem{remark}{Remark}
 \newtheorem{corollary}{Corollary}
 \theoremstyle{definition}
 \newtheorem{example}{Example}

\newenvironment{proofsketch}{%
  \renewcommand{\proofname}{Proof Sketch}\proof}{\endproof}

% Probability
\def\independenT#1#2{\mathrel{\rlap{$#1#2$}\mkern2mu{#1#2}}}
\DeclareMathOperator{\independent}{\protect\mathpalette{\protect\independenT}{\perp}}  % Independet symbol
\DeclareMathOperator{\notindependent}{\centernot{\independent}}                        % Not independent symbol

% Calculus
\newcommand{\dv}[2]{\frac{\mathrm{d} \mkern2mu #1}{\mathrm{d} \mkern1mu #2}}  % Derivative \dv{y}{x} => dy/dx
\newcommand{\ddv}[2]{\frac{\mathrm{d}^2 \mkern2mu #1}{\mathrm{d} \mkern1mu {#2}^2}}  % Derivative \ddv{y}{x} => d^2y/dx^2
\newcommand{\idv}[2]{\nicefrac{\mathrm{d} \mkern2mu #1}{\mathrm{d} \mkern1mu #2}}  % Derivative \dv{y}{x} => dy/dx (inline)
\newcommand{\pdv}[2]{\frac{\partial \mkern2mu #1}{\partial \mkern1mu #2}}     % Derivative \dv{y}{x} => dy/dx
\newcommand{\ppdv}[2]{\frac{\partial^2 \mkern2mu #1}{\partial \mkern1mu {#2}^2}}     % Derivative \dv{y}{x} => dy/dx
\newcommand{\ipdv}[2]{\nicefrac{\partial \mkern2mu #1}{\partial \mkern1mu #2}}     % Derivative \dv{y}{x} => dy/dx (inline)

% Math. Formatting.
\newcommand{\mcp}[1]{\mathclap{#1}}
