%
% Only the most commonly-used macros. Needed by everything else.
%
\ifx\havemjocommon\undefined
\def\havemjocommon{1}


% Needed for \mathbb.
\usepackage{amsfonts}

% Needed for \bigtimes.
\usepackage{mathtools}

% Place the argument in matching left/right parentheses.
\newcommand*{\of}[1]{ \left({#1}\right) }

% Group terms using parentheses.
\newcommand*{\qty}[1]{ \left({#1}\right) }

% Group terms using square brackets.
\newcommand*{\sqty}[1]{ \left[{#1}\right] }

% Create a set from the given elements
\newcommand*{\set}[1]{\left\lbrace{#1}\right\rbrace}

% A set comprehension, where the ``such that...'' bar is added
% automatically. The bar was chosen over a colon to avoid ambiguity
% with the L : V -> V notation. We can't leverage \set here because \middle
% needs \left and \right present.
\newcommand*{\setc}[2]{\left\lbrace{#1}\ \middle|\ {#2} \right\rbrace}

% A pair of things.
\newcommand*{\pair}[2]{ \left({#1},{#2}\right) }

% A triple of things.
\newcommand*{\triple}[3]{ \left({#1},{#2},{#3}\right) }

% The Cartesian product of two things.
\newcommand*{\cartprod}[2]{ {#1}\times{#2} }

% The Cartesian product of three things.
\newcommand*{\cartprodthree}[3]{ \cartprod{{#1}}{\cartprod{{#2}}{{#3}}} }

% The direct sum of two things.
\newcommand*{\directsum}[2]{ {#1}\oplus{#2} }

% The direct sum of three things.
\newcommand*{\directsumthree}[3]{ \directsum{#1}{\directsum{#2}{#3}} }

% The factorial operator.
\newcommand*{\factorial}[1]{ {#1}! }

%
% Product spaces
%
% All of the product spaces (for example, R^n) that follow default to
% an exponent of ``n'', but that exponent can be changed by providing
% it as an optional argument. If the exponent given is ``1'', then it
% will be omitted entirely.
%

% The natural n-space, N x N x N x ... x N.
\newcommand*{\Nn}[1][n]{
  \mathbb{N}\if\detokenize{#1}\detokenize{1}{}\else^{#1}\fi
}

% The integral n-space, Z x Z x Z x ... x Z.
\newcommand*{\Zn}[1][n]{
  \mathbb{Z}\if\detokenize{#1}\detokenize{1}{}\else^{#1}\fi
}

% The rational n-space, Q x Q x Q x ... x Q.
\newcommand*{\Qn}[1][n]{
  \mathbb{Q}\if\detokenize{#1}\detokenize{1}{}\else^{#1}\fi
}

% The real n-space, R x R x R x ... x R.
\newcommand*{\Rn}[1][n]{
  \mathbb{R}\if\detokenize{#1}\detokenize{1}{}\else^{#1}\fi
}

% The complex n-space, C x C x C x ... x C.
\newcommand*{\Cn}[1][n]{
  \mathbb{C}\if\detokenize{#1}\detokenize{1}{}\else^{#1}\fi
}

% The space of real symmetric n-by-n matrices.
\newcommand*{\Sn}[1][n]{
  \mathcal{S}\if\detokenize{#1}\detokenize{1}{}\else^{#1}\fi
}

% The space of complex Hermitian n-by-n matrices.
\newcommand*{\Hn}[1][n]{
  \mathcal{H}\if\detokenize{#1}\detokenize{1}{}\else^{#1}\fi
}

%
% Basic set operations
%

% The union of its two arguments.
\newcommand*{\union}[2]{ {#1}\cup{#2} }

% A three-argument union.
\newcommand*{\unionthree}[3]{ \union{\union{#1}{#2}}{#3} }

% The intersection of its two arguments.
\newcommand*{\intersect}[2]{ {#1}\cap{#2} }

% A three-argument intersection.
\newcommand*{\intersectthree}[3]{ \intersect{\intersect{#1}{#2}}{#3} }

% An indexed arbitrary binary operation such as the union or
% intersection of an infinite number of sets. The first argument is
% the operator symbol to use, such as \cup for a union. The second
% argument is the lower index, for example k=1. The third argument is
% the upper index, such as \infty. Finally the fourth argument should
% contain the things (e.g. indexed sets) to be operated on.
\newcommand*{\binopmany}[4]{
  \mathchoice{ \underset{#2}{\overset{#3}{#1}}{#4} }
             { {#1}_{#2}^{#3}{#4} }
             { {#1}_{#2}^{#3}{#4} }
             { {#1}_{#2}^{#3}{#4} }
}

\newcommand*{\intersectmany}[3]{ \binopmany{\bigcap}{#1}{#2}{#3} }
\newcommand*{\cartprodmany}[3]{ \binopmany{\bigtimes}{#1}{#2}{#3} }
\newcommand*{\directsummany}[3]{ \binopmany{\bigoplus}{#1}{#2}{#3} }
\newcommand*{\unionmany}[3]{ \binopmany{\bigcup}{#1}{#2}{#3} }


% The four standard (UNLESS YOU'RE FRENCH) types of intervals along
% the real line.
\newcommand*{\intervaloo}[2]{ \left({#1},{#2}\right) } % open-open
\newcommand*{\intervaloc}[2]{ \left({#1},{#2}\right] } % open-closed
\newcommand*{\intervalco}[2]{ \left[{#1},{#2}\right) } % closed-open
\newcommand*{\intervalcc}[2]{ \left[{#1},{#2}\right] } % closed-closed


\fi
