% CUP definitions for LATeX documents

% The following changes are to center the output on an
% 8.5x11 sheet of paper

\setlength{\hoffset}{-0.95in}
\setlength{\voffset}{-.9in}
\setlength{\oddsidemargin}{20mm}
\setlength{\evensidemargin}{20mm}
\setlength{\topmargin}{10mm}



% NEWCOMMANDS


\newcommand{\com}{\newcommand}
\newcommand{\rcom}{\renewcommand}
\newcommand{\newenv}{\newenvironment}

\newcommand{\ignore}[1]{}
\newcommand{\maybe}[1]{}



\newcommand{\head}[1]{\bc \underline{\Huge\bf#1}\ec}
\newcommand{\thm}[1]{\fl{\bf Theorem} #1}
\newcommand{\lem}[1]{\fl{\bf Lemma} #1}
\newcommand{\dfn}[1]{\fl{\bf Definition} #1}


\newcommand{\judge}[3]
{\pgt{p},\,\mbox{$#1$}\mbox{$\,\vdash\,${\tt#2}}\mbox{$\rightarrow#3$}}

\newcommand{\judgenull}[2]
{\mbox{$\,\vdash^{null}\,#1\rightarrow#2$}}


\newcommand{\judgeif}[5]
{\pgt{p},$\,#1\,\vdash^{if}\,${\tt#3},{\tt#4},$\,#2\rightarrow#5$}


\newcommand{\judgecall}[3]
{\pgt{p}$\,\vdash^{call}\,#1,#2\rightarrow#3$}


\newcommand{\judget}[4]
{\pgt{p},\,\mbox{$#1$}\mbox{$\,\vdash\,${\tt#2}}\mbox{$\rightarrow#3,#4$}}

\newcommand{\judgetcall}[5]
{\pgt{p},$\,#1\,\vdash^{call}\,#2,#3\rightarrow#4,#5$}

\newcommand{\judgec}[5]
{\pgt{p},\,\mbox{$#1,#2$}\mbox{$\,\vdash\,${\tt#3}}\mbox{$\rightarrow#4,#5$}}

\newcommand{\judgeccall}[5]
{\pgt{p},$\,#1\,\vdash^{call}\,#2,#3\rightarrow#4,#5$}

\newcommand{\judgeio}
{\pgt{p}$^{in},\,env^{in}\,\vdash\,{\tt e}^{in}\rightarrow v^{out}$}

\newcommand{\judgetio}
{\pgt{p}$^{in},\,s^{in}\,\vdash\,{\tt e}^{in}\rightarrow v^{out},s'^{out}$}

\newcommand{\judgecio}
{\pgt{p}$^{in},\,env^{in},\,c^{in}\,\vdash\,
{\tt e}^{in}\rightarrow v^{out},c'^{out}$}



\newcommand{\un}[1]{\underline{#1}}

\newcommand{\fl}{\noindent}
\newcommand{\hair}{\hspace{3mm}}
\newcommand{\vair}{\vspace{3mm}}
\newcommand{\lngth}[1]{\mbox{$\mid$#1$\mid$}}
\newcommand{\nat}{{I\!\!N}}
\newcommand{\ints} { Z\!\!\!Z}
\newcommand{\bools}{{I\!\!B}}
\newcommand{\lwhile}{{\tt WHILE}}
\newcommand{\pairs}{I\!\!D}
\newcommand{\startprog}{\begin{program}}
\newcommand{\stopprog}{\vspace{0.5cm}\end{program}}



\newcommand{\bpic}{\begin{center} \begin{picture}(50,50)(-25,-25)}
\newcommand{\epic}{\end{picture} \end{center}}
\newcommand{\ptext}[1]{\makebox(0,0){#1}}

\newcommand{\lsem}{\mbox{$\lbrack\hspace{-0.3ex}\lbrack$}}
\newcommand{\rsem}{\mbox{$\rbrack\hspace{-0.3ex}\rbrack$}}
\newcommand{\sempar}[1]{\mbox{\lsem\pgt{#1}\rsem}}
\newcommand{\semparlang}[2]{\sempar{#1}$^\pgt{#2}$}

\newcommand{\bq}{\begin{quote}}
\newcommand{\eq}{\end{quote}}

\newcommand{\bc}{\begin{center}}
\newcommand{\ec}{\end{center}}

\newcommand{\bi}{\begin{itemize}}
\newcommand{\ei}{\end{itemize}}

\newcommand{\be}{\begin{enumerate}}
\newcommand{\ee}{\end{enumerate}}

\newcommand{\ba}{\begin{array}}
\newcommand{\ea}{\end{array}}

\newcommand{\bd}{\begin{description}}
\newcommand{\ed}{\end{description}}

\newcommand{\bdfn}{\begin{definition}}
\newcommand{\edfn}{\end{definition}}

\newcommand{\blem}{\begin{lemma}}
\newcommand{\elem}{\end{lemma}}

\newcommand{\bcor}{\begin{corollary}}
\newcommand{\ecor}{\end{corollary}}

\newcommand{\bprf}{\begin{proof}}
\newcommand{\eprf}{\end{proof}}

\newcommand{\bthm}{\begin{theorem}}
\newcommand{\ethm}{\end{theorem}}

\newcommand{\bp}{\begin{program}}
\newcommand{\ep}{\end{program}}

\newcommand{\bt}{\begin{tabular}}
\newcommand{\et}{\end{tabular}}


\newcommand{\runpgm}[2]{\mbox{\lsem\pgt{#1}\rsem}(\pgt{#2})}
\newcommand{\runpgmlang}[3]{\mbox{\lsem\pgt{#1}\rsem$^\pgt{#3}({\pgt#2})$}}

\newcommand{\runpgmlangnest}[3]{\mbox{\lsem#1\rsem$^\pgt{#3}(\pgt{#2})$}}


\newcommand{\timepgm}[2]{\mbox{{\em time}$_\pgt{#1}(\pgt{#2})$}} 
\newcommand{\timepgmlang}[3]{\mbox{{\em
time}$^\pgt{#3}_\pgt{#1}(\pgt{#2})$}}

\newcommand{\spacepgm}[2]{\mbox{{\em space}$_\pgt{#1}(\pgt{#2})$}} 
\newcommand{\spacepgmlang}[3]{\mbox{{\em
space}$^\pgt{#3}_\pgt{#1}(\pgt{#2})$}}

\com{\pgt}[1]{{\tt #1}}



\newcommand{\startproof}{\par\noindent{\bf Proof\ \ }}

\newcommand{\stopproof}{}



% Latex Examples and Propositions




\newtheorem{example-thm}{Example}[section]
\newenvironment{example}{\begin{example-thm}\rm}%
	{\end{example-thm}}

\newtheorem{proposition-thm}[example-thm]{Proposition}
\newenvironment{proposition}{\begin{proposition-thm}\rm}%
	{\end{proposition-thm}}

\newtheorem{theorem-thm}[example-thm]{Theorem}
\newenvironment{theorem}{\begin{theorem-thm}\rm}%
	{\end{theorem-thm}}

\newtheorem{corollary-thm}[example-thm]{Corollary}
\newenvironment{corollary}{\begin{corollary-thm}\rm}%
	{ \end{corollary-thm}}

\newtheorem{observation-thm}[example-thm]{Observation}
\newenvironment{observation}{\begin{observation-thm}\rm}%
	{ \end{observation-thm}}

\newtheorem{lemma-thm}[example-thm]{Lemma}
\newenvironment{lemma}{\begin{lemma-thm}\rm}%
	{ \end{lemma-thm}}

\newtheorem{definition-thm}[example-thm]{Definition}
\newenvironment{definition}{\begin{definition-thm}\rm}%
	{\end{definition-thm}}



\newcommand{\programenvironment}{\programmode%
	\def\par{\leavevmode\endgraf}\obeylines\nobreak%
	\programmode}
\newcommand{\programinfig}{%
	 \parindent 0em
	 \nobreak\programenvironment}
\newcommand{\programmode}{\small\tt%   Is: \small\tt, PS 1992-09-23
	\catcode`\_=12 \catcode`\?=12 \catcode`\.=12 \catcode`\,=12
	\catcode`\;=12 \catcode`\:=12 \catcode`\@=12 \catcode`\~=12
        \catcode`\#=12 \catcode`\&=12      % Added by PS 1991-06-17
	\obeyspaces\frenchspacing}%

\newenvironment{programintext}{\programenvironment}{}

\newenvironment{program}{\setlength{\partopsep}{0mm}\setlength{\topsep}{0mm}
	\begin{trivlist}\item[]
	\hspace*{\mathindent}\begin{minipage}{0.90\textwidth}
	\vspace{1mm}
	\begin{programintext}
	}{\end{programintext}
	\vspace{1mm}
	\end{minipage}
	\end{trivlist}
	\noindent}

% The following code makes Tex respect spaces and tabs in the source text, 
% which is useful for program layout.

{\catcode`\^^I=\active \obeyspaces\global\def^^I{ }}
{\obeyspaces\global\let =\ } % let active space = control space
{\catcode`\`=\active \gdef`{\relax\lq}}
% Environment for displaying material (to replace quote and vair
% etc.).  Indents the same amount as displaymath, equations, etc.

\newenvironment{quot}{\begin{list}{{}}{
	\setlength{\partopsep}{0mm}\setlength{\topsep}{3mm}
	\setlength{\leftmargin}{\mathindent}\setlength{\rightmargin}{0mm}}
	\item[]}{\end{list}}

  %% doframeit draws a box around it argument by manipulating boxes.  It
  %% is used in the frame environments.
  %% 
  %%  Rene' Seindal (seindal@diku.denet) Fri Feb 12 16:03:07 1988
  %%  added \fboxrule and \fboxsep to \doframeit

\def\doframeit#1{\vbox{%
  \hrule height\fboxrule
    \hbox{%
      \vrule width\fboxrule \kern\fboxsep
      \vbox{\kern\fboxsep #1\kern\fboxsep }%
      \kern\fboxsep \vrule width\fboxrule }%
    \hrule height\fboxrule }}

  %% The frameit and Frameit environments formats text within a single 
  %% Anything can be framed, including verbatim text.

\def\frameit{\smallskip \advance \linewidth by -7.5pt \setbox0=\vbox \bgroup
\strut \ignorespaces }

\def\endframeit{\ifhmode \par \nointerlineskip \fi \egroup
\doframeit{\box0}}


%
%-----------------------------------------------------------------------------
%     figure environment
%
%  #1 = caption, #2 = location, #3 = label
%

\newcounter{figur}[section]
\def\thefigur{\thesection.\arabic{figur}}
\newsavebox{\fighack}

\newenvironment{fig}[3]
{
\refstepcounter{figur}
\label{#3}
\sbox{\fighack}{{\it Figure \ref{#3}: #1}}
\begin{figure}[#2]
\begin{frameit}
\hspace*{3mm}\begin{minipage}{0.95\textwidth}}{\end{minipage}\end{frameit}
\usebox{\fighack}\end{figure}}




\newenvironment{fig0}[3]
{
\refstepcounter{figur}
\label{#3}
\sbox{\fighack}{{\it Figure \ref{#3}: #1}}
\begin{figure}[#2]
%\begin{frameit}
\hspace*{3mm}\begin{minipage}{0.95\textwidth}}{\end{minipage} 
%\end{frameit}
\usebox{\fighack}\end{figure}}


% \monus that works in tt-mode too Arne J. Glenstrup <panic@diku.dk>:
\def\monus{\ifmmode\def\next{\mathpalette\m@thmonus\relax}\else
  \let\next\m@nus\fi\next}
\def\m@nus{\hbox{\vbox{{\baselineskip=-1000pt\lineskip=-.25ex
  \halign{\hfil##\hfil\cr.\cr-\cr}}}}}
\def\m@thmonus#1#2{\setbox0=\hbox{$\m@th#1-$}\@tempdima=\ht0
  \setbox0=\hbox{\vbox{{\baselineskip=-1000pt\lineskip=-.3\wd0
  \halign{\hfil##\hfil\cr$\m@th#1.$\cr\box0\cr}}}}\ht0=\@tempdima\mathbin{\box0}}


%%      Contents: Macros for drawing T and I diagrams.
%%
%% Use:
%%   \begin{TIdiagram}(80,40)(-40,0)
%%        \drawT{(X,Y)}{A}{B}{C}
%%        \drawI{(X,Y)}{A}{B}
%%   \end{diagram}
%%
%% Environment TIdiagram is a picture environment.
%% The diagrams have the following dimensions:
%% (-40,40)      (40,40)    (-10,40) (10,40)
%%       ---------                ---
%%       |A --> B|                |A|
%%       ---|C|---                |C|
%%          ---                   ---
%%         (0,0)                 (0,0)

\setlength{\unitlength}{2.0pt}

\newcommand{\drawT}[4]{\put#1{\Tdiam{#2}{#3}{#4}}}
\newcommand{\Tdiam}[3]{%
 \begin{picture}(80,40)(-40,0)
  \put(-40,40){\line(1,0){80}}
  \put(-40,40){\line(0,-1){20}}
  \put(-40,20){\line(1,0){30}}
  \put(-10,20){\line(0,-1){20}}
  \put(-10,0){\line(1,0){20}}
  \put(10,0){\line(0,1){20}}
  \put(10,20){\line(1,0){30}}
  \put(40,20){\line(0,1){20}}
  \put(-29,27){{\tt #1}}
  \put(21,27){{\tt #2}}
  \put(-3,7){{\tt #3}}
  \put(-6, 30){\vector(1,0){12}}
 \end{picture}
}

\newcommand{\drawI}[3]{\put#1{\Idiam{#2}{#3}}}
\newcommand{\Idiam}[2]{%
 \begin{picture}(20,40)(-10,0)
   \put(-10,0){\framebox(20,40){}}
   \put(0,10){\makebox(0,0){\tt #2}}
   \put(0,30){\makebox(0,0){\tt #1}}
 \end{picture}
}

\newcommand{\drawDI}[3]{\put#1{\DIdiam{#2}{#3}}}
\newcommand{\DIdiam}[2]{%
 \begin{picture}(20,40)(-10,0)
   \put(-10,0){\dashbox(20,40){}}
   \put(0,10){\makebox(0,0){\tt #2}}
   \put(0,30){\makebox(0,0){\tt #1}}
 \end{picture}
}

\newenvironment{TIdiagram}{%
  \begin{picture}}{\end{picture}}



\com{\irule}[2]{{\m@th$\frac{\mbox{\strut\raisebox{.0ex}{#1}}}{\mbox{\strut\raisebox{-.0ex}{#2}}}$}}


