\AtBeginDocument{\mathcode`\;=\numexpr\mathcode`\;-\string"4000\relax}

\newcommand{\PFPL}{\textbf{\textsf{PFPL}}}

\newenvironment{infrules}[1]{\begin{subequations}\label{rules:#1}}{\end{subequations}\ignorespacesafterend}
\newenvironment{infrule}[1]{\begin{equation}\label{rule:#1}}{\end{equation}\ignorespacesafterend}

\newcommand{\ruleref}[1]{(\ref{rule:#1})}
\newcommand{\rulesref}[1]{(\ref{rules:#1})}

\theoremstyle{plain}
\newtheorem{theorem}{Theorem}
\newtheorem{defn}[theorem]{Definition}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{exercise}{Exercise}
\newtheorem{answer}{Answer}
\theoremstyle{remark}

\newcommand{\eqdef}{\mathrel{\triangleq}}
\newcommand{\isdef}{\eqdef}
\newcommand{\bnfdef}{\coloncolonequals}
\newcommand{\bnfalt}{\mathrel{\mid}}

\newcommand{\parens}[1]{(#1)}
\newcommand{\braces}[1]{\{#1\}}
\newcommand{\sqbracks}[1]{[#1]}
\newcommand{\ptbracks}[1]{\langle #1\rangle}
\newcommand{\brackets}[1]{\ptbracks{#1}}
\newcommand{\corners}[1]{\ulcorner #1\urcorner}
\newcommand{\dblptbracks}[1]{\langle\!\langle #1\rangle\!\rangle}
\newcommand{\dblsqbracks}[1]{[\![ #1]\!]}

\newcommand{\IsCtx}[1]{{#1}\,\textsf{ctx}}
\newcommand{\IsOf}[2]{{#1}\mathrel{:}{#2}}
\newcommand{\IsOfVar}[2]{{#1}\mathbin{:}{#2}}
\newcommand{\IsOfKd}[2]{{#1}\mathrel{\coloncolon}{#2}}
\newcommand{\IsOfKdVar}[2]{{#1}\mathbin{\coloncolon}{#2}}
\newcommand{\IsOfM}[2]{{#1}\mathrel{\altdiv}{#2}}
\newcommand{\Has}[2]{{#1}\mathbin{\twiddle}{#2}}
\newcommand{\IsType}[1]{{#1}\,\textsf{type}}

\newcommand{\IsOfVal}[2]{\IsOf{#1}{#2}}
\newcommand{\IsOfComp}[2]{\IsOfM{#1}{#2}}

\newcommand{\JPre}[2]{{#2}\;{#1}}
\newcommand{\JPost}[2]{{#1}\;{#2}}

\newcommand{\IsVal}[2][]{\JPost{#2}{\textsf{val}_{#1}}}
\newcommand{\IsErr}[2][]{\JPost{#2}{\textsf{err}_{#1}}}

% abt's
\newcommand{\OpABT}[2]{{#1}\cdparens{#2}}
\newcommand{\OpABTp}[3]{{#1}\cdbraces{#2}\cdparens{#3}}
\newcommand{\OpABTn}[2]{{#1}\cdbraces{#2}}
\newcommand{\ABT}[2]{\OpABT{#1}{#2}}

\newcommand{\ABS}[2]{{#1}\mathbin{\cddot}{#2}}
\newcommand{\AbsABT}[2]{\ABS{#1}{#2}}
\newcommand{\SymABT}[2]{\ABS{#1}{#2}}

\newcommand{\ListABT}[2]{{#1};\dots;{#2}}
\newcommand{\SeqABT}[2]{\ListABT{{#2}_1}{{#2}_{#1}}}
\newcommand{\ZeqABT}[2]{\ListABT{{#2}_0}{{#2}_{#1}}}

\newcommand{\AlphaEq}[2]{{#1}=_\alpha{#2}}

\newcommand{\Subst}[3]{\sqbracks{{#1}\mathord{/}{#2}}{#3}}
\newcommand{\SubstIs}[4]{\Subst{#1}{#2}{#3}\mathbin{=}{#4}}

\newcommand{\StepsTo}[1][]{\xmapsto[\,#1\,]{\hspace*{1em}}}
\newcommand{\UStepsTo}[1]{\xmapsto{\,#1\,}}
\newcommand{\LStepsTo}[1]{\xmapsto[\,#1\,]{\hspace*{1em}}}
\newcommand{\LLStepsTo}[2]{\xmapsto[\,#2\,]{\,#1\,}}

\newcommand{\IsState}[2][]{\JPost{#2}{\textsf{state}_{#1}}} % never used, but for overview
\newcommand{\IsFinal}[2][]{\JPost{#2}{\textsf{final}_{#1}}}
\newcommand{\IsInitial}[2][]{\JPost{#2}{\textsf{initial}_{#1}}}

\newcommand{\IsOKState}[2][]{\JPost{#2}{\textsf{ok}}_{#1}}
\newcommand{\IsReady}[2][]{\JPost{#2}{\textsf{ready}_{#1}}}
\newcommand{\IsDone}[2][]{\JPost{#2}{\textsf{done}_{#1}}}

\newcommand{\NFold}[2]{#1^{#2}}
\newcommand{\Opt}[1]{\NFold{#1}{?}}

\newcommand{\MultiStepsTo}[1][\ast]{\NFold{\StepsTo}{#1}}
\newcommand{\OptStepsTo}{\Opt{\StepsTo}}

\newcommand{\MultiLLStepsTo}[3][\ast]{\NFold{\LLStepsTo{#2}{#3}}{#1}}
