% -*- Mode:LaTeX -*-

% Include the file header.tex to setup the page sizes etc.
% Shail Aditya 16:09 02/17/94 

% SHORT FORMS FOR ITALICIZED ``i.e.'', ``e.g.'', ``etc.''
\newcommand{\ie}{{\it i.e.}}
\newcommand{\Ie}{{\it I.e.}}
\newcommand{\eg}{{\it e.g.}}
\newcommand{\Eg}{{\it E.g.}}
\newcommand{\etc}{{\rm etc}\abbreviationperiod}
\newcommand{\via}{{\it via\/ }}
\newcommand{\etal}{{\it et al}\abbreviationperiod}
\newcommand{\adhoc}{{\it ad hoc\/}}
\newcommand{\vs}{{\it vs.\/ }}
\newcommand{\cmp}{{\it c.f.\/ }}
\newcommand{\ala}{{\it \`{a} la\/ }}
% ----------------
% STRUTS
% HORIZONTAL STRUT.  One argument (width).
\newcommand{\hstrut}[1]{\hspace*{#1}}
% VERTICAL STRUT. Two arguments (offset from baseline, height).
\newcommand{\vstrut}[2]{\rule[#1]{0in}{#2}}
% ----------------
% EMPTY BOXES OF VARIOUS WIDTHS, FOR INDENTATION
\newcommand{\hm}{\hspace*{1em}}
\newcommand{\hmm}{\hspace*{2em}}
\newcommand{\hmmm}{\hspace*{3em}}
\newcommand{\hmmmm}{\hspace*{4em}}
\newcommand{\vsp}{\vspace*{.1in}}

% ----------------
% VARIOUS CONVENIENT WIDTHS RELATIVE TO THE TEXT WIDTH, FOR BOXES.
\newlength{\hlessm}
\setlength{\hlessm}{\textwidth}
\addtolength{\hlessm}{-1em}
\addtolength{\hlessm}{-2pt}%-1.05pt
\newlength{\hlessmm}
\setlength{\hlessmm}{\textwidth}
\addtolength{\hlessmm}{-2em}
\addtolength{\hlessmm}{-4pt}%-2.1pt
\newlength{\hlessmmm}
\setlength{\hlessmmm}{\textwidth}
\addtolength{\hlessmmm}{-3em}
\addtolength{\hlessmmm}{-6pt}%-3.15pt
\newlength{\hlessmmmm}
\setlength{\hlessmmmm}{\textwidth}
\addtolength{\hlessmmmm}{-4em}
\addtolength{\hlessmmmm}{-8pt}%4.2pt

\newlength{\hhalfmm}
\setlength{\hhalfmm}{.5\hlessmm}
\newlength{\hthirdmmm}
\setlength{\hthirdmmm}{.333\hlessmmm}
\newlength{\heqlhs}
\setlength{\heqlhs}{.3\hlessm}

% ----------------
%%% spacing macros

\def\varspace#1{\def\baselinestretch{#1}\large\normalsize}
\def\dspace{\def\baselinestretch{1.5}\large\normalsize}
\def\mspace{\def\baselinestretch{1.25}\large\normalsize}
\def\sspace{\def\baselinestretch{1.0}\large\normalsize}
\def\tspace{\def\baselinestretch{.85}\large\normalsize}
\let\double=\dspace
\let\single=\sspace
\let\middle=\mspace

% Figures and Illustrations.

%%% Boxing a figure

\newenvironment{boxit}%
{\begin{tabular}{|p{\hlessm}|}
\hline
\begin{center}}%
{\end{center} \\
\hline
\end{tabular}}

%%% Sandwitches a figure between two horizontal lines.
%%% Usage:  \begin{myfig}{LABEL}{CAPTION}

\newenvironment{myfig}[2]
  {\begin{figure}[tp]%
   \def\figlabel{#1}%
   \def\figcaption{#2}%
   \hrule width\linewidth height1pt%
   \vskip \fboxsep}%
  {\caption{\label{\figlabel}\figcaption}%
   \vskip \fboxsep
   \hrule width\linewidth height1pt%
   \end{figure}}

\newenvironment{myfig*}[2]
  {\begin{figure*}[tp]%
   \def\figlabel{#1}%
   \def\figcaption{#2}%
   \hrule width\linewidth height1pt%
   \vskip \fboxsep}%
  {\caption{\label{\figlabel}\figcaption}%
   \vskip \fboxsep
   \hrule width\linewidth height1pt%
   \end{figure*}}

%%% Put a horizontal line below the table.
%%% Usage:  \begin{mytab}{LABEL}{CAPTION}

\newenvironment{mytab}[2]
  {\begin{table}[tp]%
   \def\tablabel{#1}%
   \def\tabcaption{#2}}%
  {\caption{\label{\tablabel}\tabcaption}%
   \vskip \fboxsep
   \hrule width\linewidth height1pt%
   \end{table}}

\newenvironment{mytab*}[2]
  {\begin{table*}[tp]%
   \def\tablabel{#1}%
   \def\tabcaption{#2}}%
  {\caption{\label{\tablabel}\tabcaption}%
   \vskip \fboxsep
   \hrule width\linewidth height1pt%
   \end{table*}}

% \input{illustrations} -- defines psadobe illustration macros
% \def\illustrationfileprefix{/jj/shail/tex/}
% \illustration{filename}[\hsize][\vsize]
% \illustrationpercent{filename}{percent}
% 
% The illustration macro tries to fill horizontal width of the page. 
% This is very annoying, so we redefine it here with optional resizing.
% (brought from /home/srco/new/lib/tex/localinputs/illustrations.tex) 

\makeatletter
\def\illustration#1{\@ifnextchar [{\@illustx{#1}}{\@illust{#1}}}
\def\@illustx#1[#2]{\@ifnextchar [{\@illustxy{#1}{#2}}{\illustrationx{#1}{#2}}}
\def\@illustxy#1#2[#3]{\illustrationxy{#1}{#2}{#3}}
\def\@illust#1{\ifillustrationcenter\begin{center}
 \leavevmode\fi
 {\epsfbox{\illustrationfileprefix#1\illustrationfilesuffix}}
  \ifillustrationcenter\end{center}\fi}
\makeatother

% \illfigure{filename}{Title}: Standard figure.
\def\illfigure#1#2{\begin{figure}[tp]
                        \illustration{#1}
                        \caption{#2}
                        \label{fig:#1}
                        \end{figure}}

%% Put text on page with figures, even if text is at least .25 of page
\def\topfraction{.75}
\def\bottomfraction{.5}
\def\textfraction{.25}
\def\floatpagefraction{.75}
\def\dbltopfraction{.75}
\def\dblfloatpagefraction{.5}

% References 

% \fig{name} -- reference a figure.
\def\fig#1{Figure~\ref{fig:#1}}

% \tab{name} -- reference a table.
\def\tab#1{Table~\ref{tab:#1}}

% \ex{name} -- reference an example.
\def\ex#1{Example~\ref{ex:#1}}

% \partref{name} -- reference a part.
\def\partref#1{Part~\ref{part:#1}}

% \chap{name} -- reference a chapter.
\def\chap#1{Chapter~\ref{chap:#1}}

% \sec{name} -- reference a section.
\def\sec#1{Section~\ref{sec:#1}}

% \defn{name} -- reference a definition.
\def\defn#1{Definition~\ref{defn:#1}}

% \notn{name} -- reference a notation.
\def\notn#1{Notation~\ref{notn:#1}}

% \prop{name} -- reference a proposition.
\def\prop#1{Proposition~\ref{prop:#1}}

% \cor{name} -- reference a corollary.
\def\cor#1{Corollary~\ref{cor:#1}}

% \case{name} -- reference a case.
\def\case#1{Case~\ref{case:#1}}

% \eqn{name} -- reference an equation.
\def\eqn#1{Equation~\ref{eqn:#1}}

% \line{name} -- reference a line.
\def\line#1{Line~\ref{line:#1}}

% ``TIGHTLIST'' ENVIRONMENT (no para space between items, small indent)
\newenvironment{tightlist}%
{\begin{list}{$\bullet$}{%
    \setlength{\topsep}{1ex}
    \setlength{\partopsep}{0in}
    \setlength{\itemsep}{0in}
    \setlength{\parsep}{0in}
    \setlength{\leftmargin}{1.5em}
    \setlength{\rightmargin}{0in}
    \setlength{\itemindent}{0in}}}%
{\end{list}}

% ``TightDescription'' ENVIRONMENT (no para space between items, small indent)
\newenvironment{tightdesc}%
{\begin{list}{}{%
    \setlength{\topsep}{1ex}
    \setlength{\partopsep}{0in}
    \setlength{\itemindent}{0in}
    \setlength{\itemsep}{0in}
    \setlength{\labelwidth}{1em}
    \setlength{\leftmargin}{1.5em}
    \setlength{\rightmargin}{0in}
    \setlength{\itemindent}{0in}}}%
{\end{list}}

% ``TightEnumeration'' (small space between items, with counter)
\newcounter{enum}
\newenvironment{tightenum}%
{\begin{list}{\arabic{enum}.}{%
    \usecounter{enum}
    \setlength{\topsep}{1ex}
    \setlength{\partopsep}{0in}
    \setlength{\parsep}{0in}
    \setlength{\itemsep}{0in}
    \setlength{\leftmargin}{1.5em}
    \setlength{\rightmargin}{0in}
    \setlength{\itemindent}{0in}}}%
{\end{list}}

% ``DEFINITION'' and ``LEMMA'' ENVIRONMENT
\makeatletter
\@ifundefined{thechapter}%
{\newtheorem{definition}{Definition}}%
{\newtheorem{definition}{Definition}[chapter]}
\makeatother
\newtheorem{notation}[definition]{Notation}
\newtheorem{lemma}[definition]{Lemma}
\newtheorem{theorem}[definition]{Theorem}
\newtheorem{proposition}[definition]{Proposition}
\newtheorem{corollary}[definition]{Corollary}
\newtheorem{property}[definition]{Property}
\newtheorem{fact}{Fact}
\newtheorem{assumption}{Assumption}
\newtheorem{term-strategy}{Termination Strategy}
\newtheorem{close-strategy}{Closing Strategy}

% ``CASE'' ENVIRONMENT
\newcounter{case}
\newenvironment{mycases}%
{\begin{list}{{\bf Case}\ \thecase:}{%
    \usecounter{case}
    \setlength{\topsep}{0in}
    \setlength{\partopsep}{0in}
    \setlength{\labelwidth}{0.5em}
    \setlength{\listparindent}{1.5em}
    \setlength{\itemsep}{0in}
    \setlength{\rightmargin}{0in}
    \setlength{\leftmargin}{1em}}}%
{\end{list}}


% SUBCASE ENVIRONMENT
\newcounter{subcase}
\renewcommand{\thesubcase}{\thecase.\arabic{subcase}}
\newenvironment{mysubcases}%
{\begin{list}{{\bf SubCase}\ \thesubcase:}{%
    \usecounter{subcase}
    \setlength{\topsep}{0in}
    \setlength{\partopsep}{0in}
    \setlength{\labelwidth}{0.5em}
    \setlength{\listparindent}{1.5em}
    \setlength{\itemsep}{0in}
    \setlength{\rightmargin}{0in}
    \setlength{\leftmargin}{1em}}}%
{\end{list}}

% ``PROOF'' Environment
\newenvironment{proof}%
{%\setcounter{proofref}{0}
\begin{list}{{\bf Proof:}}{%
    \setlength{\topsep}{0in}
    \setlength{\itemsep}{0in}
    \setlength{\labelwidth}{0.5em}
    \setlength{\listparindent}{1.5em}
    \setlength{\rightmargin}{0in}
    \setlength{\leftmargin}{1em}
    \setlength{\rightmargin}{0in}}
\item}%
{\hspace*{\fill}$\Box$\end{list}}

% Inference Rules are tables with premises and conclusions as entries.

\newcommand{\stmt}[1]{\mbox{$#1$}}

\newcommand{\inference}[2]{%
\begin{tabular}{c}
#1 \\
\hline
#2 
\end{tabular}}

% ``IMPLICATION'' ENVIRONMENT (tabular* with some special formatting).
% pre,    rightadjusted centered leftadjusted     rightadjusted  post
% 
\newmath\implies{\Longrightarrow}
\newlength{\implylength}
\settowidth{\implylength}{$\Longrightarrow$}
\newcommand{\arrowbox}{\makebox[\implylength]{}}
\newcommand{\rjust}{\mbox{}\hfill}
%\newcounter{proofref}
%\renewcommand{\theproofref}{\Roman{proofref}}
%\def\proofrefcount#1{\refstepcounter{equation}(\theequation)\label{#1}}
\def\proofrefcount#1{\refstepcounter{equation}(\theequation)\label{#1}}
\newenvironment{implication}%
{\medskip\begin{trivlist}\item[]
%\hspace*{-1.5em}
%\begin{tabular*}{\linewidth}{@{}l@{}p{\heqlhs}cl@{\extracolsep{\fill}}rr@{}}}%
\begin{tabular*}{\linewidth}{@{}l@{\extracolsep{\fill}}r@{\extracolsep{0pt}}@{\hspace{\tabcolsep}\hspace{\tabcolsep}}cl@{\extracolsep{\fill}}rr@{}}}%
{\end{tabular*}\end{trivlist}\medskip}

% ----------------
%Display Environment
{\catcode`\`=\active \gdef`{\relax\lq}}

\countdef\typett=255
\def\startdisplay#1
  {\bgroup\catcode`\`=\active\obeyspaces\obeylines\penalty-300
     \def\i##1{{\it ##1}}
     \setlength{\topsep}{0in}
     \setlength{\partopsep}{0in}
     \setlength{\itemsep}{0in}
     \setlength{\parsep}{0in}
     \setlength{\leftmargin}{6.5em}
     \setlength{\rightmargin}{0in}
     \setlength{\itemindent}{0in}
     \single%\small
     %\medskip
     \parskip=0pt\ifnum\typett>0 \tt\else\it\fi}

\global\def\enddisp{\smallskip\egroup\catcode`\^^M=5}
 {\obeyspaces\global\let \ }


% CODE FONT (e.g. {\cf x := 0}).
\newcommand{\cf}{\small\tt}

% ----------------
% ``CODE'' ENVIRONMENT typewriter font, literal spacing, line-breaking.
% ``DISPLAY'' ENVIRONMENT -- just like code except default italics font.
\newenvironment{code}{\bgroup\typett=1\startdisplay}{\enddisp\egroup}
\newenvironment{display}{\bgroup\typett=0\startdisplay}{\enddisp\egroup}

% MYEXAMPLE ENVIRONMENT - uses CODE environment, keeps an internal counter.
% \begin{myexample}{label}
% In order to allow repeating previous examples numbers, we provide a
% flag \prevref that should be set to true (\prevreftrue) before the
% example and unset (\prevreffalse) after the example. This allows you
% to supply the previous reference within the label argument. The
% counter is not stepped. 

% The following strategy is no longer used: 
% If the supplied argument is alphabetic (catcode 11) then the counter
% is stepped and the argument is used as the label, otherwise the
% argument must be a number (catcode 12) which is used as the example
% number. 

\newif\ifprevref
\prevreffalse
\makeatletter
\@ifundefined{thechapter}%
{\newcounter{examplectr}}%
{\newcounter{examplectr}[chapter]
\renewcommand{\theexamplectr}{\thechapter.\arabic{examplectr}}}
\makeatother
\newenvironment{myexample}[1]%
{\begin{list}{}{%
    \setlength{\topsep}{1ex}
    \setlength{\labelsep}{0in}
    \setlength{\parskip}{0in}
    \setlength{\labelwidth}{1em}
    \setlength{\itemindent}{0in}
    \setlength{\partopsep}{0in}
    \setlength{\listparindent}{0in}
    \setlength{\rightmargin}{0in}
    \setlength{\leftmargin}{1em}}
 \item[\ifprevref {\bf{}Example #1:}
       \else \refstepcounter{examplectr}\label{#1}
             {\bf{}Example \theexamplectr:}
       \fi] \hfill\mbox{}\linebreak
 \begin{code}}%
{\end{code}
 \end{list}}

% MYEXAMPLENOCODE - is similar to MYEXAMPLE environment except that it
% does not start a CODE environment. You can therefore use tables etc.
% within it. 
 
\newenvironment{myexamplenocode}[1]%
{\begin{list}{}{%
    \setlength{\topsep}{1ex}
    \setlength{\labelsep}{0in}
    \setlength{\parskip}{0in}
    \setlength{\labelwidth}{1em}
    \setlength{\itemindent}{0in}
    \setlength{\partopsep}{0in}
    \setlength{\listparindent}{0in}
    \setlength{\rightmargin}{0in}
    \setlength{\leftmargin}{1em}}
 \item[\ifprevref {\bf{}Example #1:}
       \else \refstepcounter{examplectr}\label{#1}
             {\bf{}Example \theexamplectr:}
       \fi] \hfill\mbox{}\linebreak}%
{\end{list}}


\newcounter{mycaption}
\setcounter{mycaption}{0}

\newenvironment{mycaption}{\captionstuff}{}

\def\captionstuff#1#2{\begingroup\flushleft{\bf Figure}
               \refstepcounter{mycaption}
               \arabic{mycaption} : #1%
               \label{#2} % 
               \addcontentsline{lof}{figure}{\protect\numberline{}{#1}}
               \endgroup\medskip\par}

% program environment
\def\^^I{\ \ \ \ \ }

\def\space{ } \def\empty{} \def\null{\hbox{}}
%

\def\handout#1#2{
   {\bf
     \begin{center}
        Massachusetts Institute of Technology
        Department of Electrical Engineering and Computer Science
        6.847 --- Dataflow and Reduction Architectures
     \end{center}}
   \medskip
   \mbox{#1\ \# #2}\hfill\mbox{\today}\\
   \mbox{}\hrulefill\mbox{}
   \smallskip}

% INCLUDE AND INPUT PREFIX
\newcommand{\inc}[2]{\include{#1/#2}}
\newcommand{\inp}[2]{\input{#1/#2}}

%%% Includeonly command 
\newcommand{\ino}[1]{\includeonly{#1}}

%%Various new symbols

\def\mjoin{\mkern -4mu}
\def\mbar{\raise .25pt \hbox{$\smash-$}}
\def\sra{\makebox[.5mm][l]{\mbar}\mbar\mjoin\mbox{$\rightarrow$}}
\def\dra{\mbar\mjoin\mbox{$\rightarrow$}\makebox[.5mm][r]{$\rightarrow$}}
\def\sla{\mbox{$\leftarrow$}\mjoin\mbar\makebox[.5mm][r]{\mbar}}
\def\dla{\makebox[.5mm][l]{$\leftarrow$}\mbox{$\leftarrow$}\mjoin\mbar}
\newcommand{\reduces}[2]{\mathrel{\mathop{\dra}\limits_{#1}^{#2}}}
\newcommand{\reduce}[2]{\mathrel{\mathop{\sra}\limits_{#1}^{#2}}}
\newcommand{\lreduces}[2]{\mathrel{\mathop{\dla}\limits_{#1}^{#2}}}
\newcommand{\lreduce}[2]{\mathrel{\mathop{\sla}\limits_{#1}^{#2}}}
\newcommand{\dlb}{[\![}
\newcommand{\drb}{]\!]}
\newcommand{\length}[1]{\vert#1\vert}
\newcommand{\mmin}{{\rm Min}}
\newcommand{\cnum}[1]{^{\scriptscriptstyle \lceil}#1^{\scriptscriptstyle \rceil}}

%%% define a command to produce tilde (~)
{\catcode`\~=12\gdef\tld{\begingroup\sc{}~\endgroup}\catcode`\~=13}

%%% Help commands, New math (KT) helps wrapping a mathmode if there isn't one.

%%% Various font boxes 
\newcommand{\bx}[1]{\mbox{\rm{}#1}}
\newcommand{\ibx}[1]{\mbox{\it{}#1\/}}
\newcommand{\tbx}[1]{\mbox{\tt{}#1}}
\newcommand{\cbx}[1]{\mbox{\sc{}#1}}
\newcommand{\fbx}[1]{\mbox{\sf{}#1}}
\newcommand{\bbx}[1]{\mbox{\bf{}#1}}
\newcommand{\lbx}[1]{\mbox{$\cal{}#1$}}
\newcommand\sibx[1]{\mbox{\scriptsize\it{}#1}}
\newcommand\stbx[1]{\mbox{\scriptsize\tt{}#1}}
\newcommand\ssibx[1]{\mbox{\tiny\it{}#1}}
\newcommand\sstbx[1]{\mbox{\tiny\tt{}#1}}
\newcommand\ssbx[1]{\mbox{\tiny\rm{}#1}}

%%% Various symbols and operators
\newmath\goesto[1]{\reduce{}{\scriptstyle{}#1}}
\newmath\finmapsto[2]{\bx{#1}\goesto{\sibx{fin}}\bx{#2}}
\newmath\goto[1]{\reduces{}{\scriptstyle{}#1}}
\newmath\fn[2]{\mbox{\it #1\/}(#2)}
\newmath\larrow{\mbox{$\,-\!\langle$}}
\newmath\rarrow{\mbox{$\rangle\!\!\!\rightarrow\,$}}
\newmath\fvar[1]{\lbx{F}(#1)}
\newmath\pvar[1]{\lbx{F'}(#1)}
\newmath\bvar[1]{\lbx{B}(#1)}
\newmath\dvar[1]{\lbx{D}(#1)}
\newmath\vvar[1]{\lbx{V}(#1)}
\newmath\rvar[1]{\lbx{R}(#1)}
\newmath\cvar[1]{\lbx{C}(#1)}
\newmath\rpvar[1]{\lbx{R'}(#1)}
\newmath\lvar[1]{\lbx{L}(#1)}
\newmath\lpvar[1]{\lbx{L'}(#1)}
\newmath\tval[1]{\langle\mbox{\sf{}n-tup}\;#1\rangle}
\newmath\cval[1]{\langle\mbox{\sf{}clsr}\;#1\rangle}
\newmath\aval[1]{\langle\mbox{\sf{}vect}\;#1\rangle}
\newmath\gval[1]{\langle{}#1\rangle}
\newmath\ul[1]{\underline{#1}}
\newmath\ol[1]{\overline{#1}}
\newmath\mod[1]{|#1|}
\newmath\sch[1]{\dlb#1\drb}
\newmath\texp[1]{{\bf{}TExp}\dlb#1\drb}
\newmath\tenc[1]{{\bf{}TEnc}\dlb#1\drb}
\newmath\tdec[1]{{\bf{}TDec}\dlb#1\drb}
\newmath\tdecaux[1]{{\bf{}TDec}'\dlb#1\drb}
\newmath\compile[1]{{\bf{}Compile}\dlb#1\drb}
\newmath\interpret[1]{{\bf{}Interpret}\dlb#1\drb}
\newcommand{\rw}{\bx{rw}}
\newcommand{\ro}{\bx{ro}}

\newmath{\set}[1]{\left\{ #1 \right\}}
\newmath{\abs}[1]{\left| #1\right|}
\newmath{\card}[1]{\left| #1\right|}
\newmath{\floor}[1]{\left\lfloor #1 \right\rfloor}
\newmath{\ceil}[1]{\left\lceil #1 \right\rceil}
\newmath{\ang}[1]{\left\langle #1 \right\rangle}

%\newcommand{\prob}[1]{\Pr\left\{ #1 \right\}}
%\newcommand{\Var}{\mathop{\rm Var}\nolimits}
%\renewcommand{\choose}[2]{{{#1}\atopwithdelims(){#2}}}
%\def\pmod#1{\allowbreak\mkern12mu({\rm mod}\,\,#1)}
%\def\squarebox#1{\hbox to #1{\hfill\vbox to #1{\vfill}}}
%\newcommand{\qed}{\hfill\hfill\vbox{\hrule\hbox{\vrule\squarebox{.667em}\vrule}\hrule}\smallskip}

% Environment like description, but without a label.  Makes each item
% have a hanging indent.
%\def\hanglistlabel#1{\hspace\labelsep}
%\def\hanglist{\leftmarginii=1pc
%\list{}{\labelsep=0pt\labelwidth\z@ \itemindent-1pc%\leftmargin
%\let\makelabel\hanglistlabel}}
%\let\endhanglist\endlist

\newcommand{\start}{\begin{description}}
\newcommand{\finish}{\end{description}}
