% Macros for The Art of Computer Programming

\input figdir.local % where the PostScript figures can be found
% figdir.local should contain a line such as the following:
% \def\figdir{/home/acp/figs} % full path name of directory for epsf figures

\tracingpages=1 % show all page-break decisions in the log file
\tracingstats=1 % show how much of TeX's capacity was used, at end of log file
\def\loggingall{\tracingall\tracingonline0}

\newif\ifproofmode
\proofmodetrue % this should be false when making camera-ready copy

\input epsf
\input rotate
\input picmac

\catcode`@=11 % borrow the private macros of PLAIN (with care)

\font\ninerm=cmr9
\font\eightrm=cmr8
\font\sixrm=cmr6

\font\ninei=cmmi9
\font\eighti=cmmi8
\font\sixi=cmmi6
\skewchar\ninei='177 \skewchar\eighti='177 \skewchar\sixi='177

\font\tenbi=cmmib10
\font\ninebi=cmmib9

\font\ninesy=cmsy9
\font\eightsy=cmsy8
\font\sixsy=cmsy6
\skewchar\ninesy='60 \skewchar\eightsy='60 \skewchar\sixsy='60

\font\tenbsy=cmbsy10
\font\sevenbsy=cmbsy7
\font\fivebsy=cmbsy5

\font\elevenex=cmex10 scaled\magstephalf
\font\nineex=cmex9
\font\eightex=cmex8
\font\sevenex=cmex7

\font\ninebf=cmbx9
\font\eightbf=cmbx8
\font\sixbf=cmbx6

\font\tenthinbf=cmb10
\font\ninethinbf=cmb10 at 9.25pt
\font\eightthinbf=cmb10 at 8.5pt

\font\twelvett=cmtt12
\font\tensltt=cmsltt10
\font\ninett=cmtt9
\font\eighttt=cmtt8
\font\seventt=cmtt8 scaled 875

\hyphenchar\twelvett=-1 % inhibit hyphenation in typewriter type
\hyphenchar\tentt=-1
\hyphenchar\ninett=-1
\hyphenchar\eighttt=-1

\font\ninesl=cmsl9
\font\eightsl=cmsl8

\font\nineit=cmti9
\font\eightit=cmti8

\font\eightss=cmssq8
\font\eightssi=cmssqi8
\font\sixss=cmssq8 scaled 800
\font\tenssbx=cmssbx10
\font\twelvess=cmss12
\font\titlefont=cmssbx10 scaled\magstep2

\font\tencsc=cmcsc10

\font\manfnt=manfnt % special symbols from the TeX project

\let\realtentt=\tentt
\def\tenpoint{\def\rm{\fam0\let\tentt=\realtentt\tenrm}%
  \clearance=4.175 pt
  \textfont0=\tenrm \scriptfont0=\sevenrm \scriptscriptfont0=\fiverm
  \textfont1=\teni \scriptfont1=\seveni \scriptscriptfont1=\fivei
  \textfont2=\tensy \scriptfont2=\sevensy \scriptscriptfont2=\fivesy
  \textfont3=\tenex \scriptfont3=\eightex \scriptscriptfont3=\sevenex
  \def\it{\fam\itfam\tenit}%
  \textfont\itfam=\tenit
  \def\sl{\fam\slfam\let\tentt=\tensltt\tensl}%
  \textfont\slfam=\tensl
  \def\bf{\fam\bffam\tenbf}%
  \textfont\bffam=\tenbf \scriptfont\bffam=\sevenbf
   \scriptscriptfont\bffam=\fivebf
  \def\tt{\fam\ttfam\tentt}%
  \let\sltt=\tensltt
  \textfont\ttfam=\tentt
  \def\oldstyle{\fam\@ne\teni}%
  \normalbaselineskip=12pt
  \def\bigfences{\textfont3=\elevenex}%
  \let\big=\tenbig
  \let\Big=\tenBig
  \let\bigg=\tenbigg
  \let\Bigg=\tenBigg
  \setbox\strutbox=\hbox{\vrule height8.5pt depth3.5pt width\z@}%
  \bitmapsize=10pt
  \let\adbcfont=\eightrm
  \let\mc=\ninerm % for slightly smaller caps
  \let\boldit=\tenbi
  \let\ii=\tenii
  \def\MF{{\manfnt META}\-{\manfnt FONT}}%
  \normalbaselines\rm}

\def\ninepoint{\def\rm{\fam0\ninerm}%
  \clearance=3.9125 pt
  \textfont0=\ninerm \scriptfont0=\sixrm \scriptscriptfont0=\fiverm
  \textfont1=\ninei \scriptfont1=\sixi \scriptscriptfont1=\fivei
  \textfont2=\ninesy \scriptfont2=\sixsy \scriptscriptfont2=\fivesy
  \textfont3=\nineex \scriptfont3=\sevenex \scriptscriptfont3=\sevenex
  \def\it{\fam\itfam\nineit}%
  \textfont\itfam=\nineit
  \def\sl{\fam\slfam\ninesl}%
  \textfont\slfam=\ninesl
  \def\bf{\fam\bffam\ninebf}%
  \textfont\bffam=\ninebf \scriptfont\bffam=\sixbf
   \scriptscriptfont\bffam=\fivebf
  \def\tt{\fam\ttfam\ninett}%
  \let\sltt=\error
  \textfont\ttfam=\ninett
  \def\oldstyle{\fam\@ne\ninei}%
  \normalbaselineskip=11pt
  \def\bigfences{\textfont3=\tenex}%
  \let\big=\ninebig
  \let\Big=\nineBig
  \let\bigg=\ninebigg
  \let\Bigg=\nineBigg
  \setbox\strutbox=\hbox{\vrule height8pt depth3pt width\z@}%
  \bitmapsize=9pt
  \let\adbcfont=\sevenrm
  \let\mc=\eightrm % for slightly smaller caps
  \let\boldit=\ninebi
  \let\ii=\error
  \def\MF{{\manfnt hijk}\-{\manfnt lmnj}}%
  \normalbaselines\rm}
\let\normalninepoint=\ninepoint
\def\flexninepoint{\normalninepoint
  \advance\baselineskip 0pt plus .2pt minus .25pt}

\def\eightpoint{\def\rm{\fam0\eightrm}%
  \clearance=3.9125 pt
  \textfont0=\eightrm \scriptfont0=\sixrm \scriptscriptfont0=\fiverm
  \textfont1=\eighti \scriptfont1=\sixi \scriptscriptfont1=\fivei
  \textfont2=\eightsy \scriptfont2=\sixsy \scriptscriptfont2=\fivesy
  \textfont3=\eightex \scriptfont3=\sevenex \scriptscriptfont3=\sevenex
  \def\it{\fam\itfam\eightit}%
  \textfont\itfam=\eightit
  \def\sl{\fam\slfam\eightsl}%
  \textfont\slfam=\eightsl
  \def\bf{\fam\bffam\eightbf}%
  \textfont\bffam=\eightbf \scriptfont\bffam=\sixbf
   \scriptscriptfont\bffam=\fivebf
  \def\tt{\fam\ttfam\eighttt}%
  \let\sltt=\error
  \textfont\ttfam=\eighttt
  \def\oldstyle{\fam\@ne\eighti}%
  \normalbaselineskip=9pt
  \def\bigfences{\textfont3=\nineex}%
  \let\big=\eightbig
  \let\Big=\eightBig
  \let\bigg=\eightbigg
  \let\Bigg=\eightBigg
  \setbox\strutbox=\hbox{\vrule height7pt depth2pt width\z@}%
  \bitmapsize=8pt
  \let\adbcfont=\sixrm
  \let\mc=\sevenrm % for slightly smaller caps
  \let\boldit=\error
  \let\ii=\eightii
  \def\MF{{\manfnt opqr}\-{\manfnt stuq}}%
  \normalbaselines\rm}

\def\tenbig#1{{\hbox{$\left#1\vbox to8.5pt{}\right.\n@space$}}}
\def\ninebig#1{{\hbox{$\textfont0=\tenrm\textfont2=\tensy
  \left#1\vbox to7.25pt{}\right.\n@space$}}}
\def\eightbig#1{{\hbox{$\textfont0=\ninerm\textfont2=\ninesy
  \left#1\vbox to6.5pt{}\right.\n@space$}}}

\def\tenBig#1{{\hbox{$\bigfences
  \left#1\vbox to11.5pt{}\right.\n@space$}}}
\def\nineBig#1{{\hbox{$\bigfences
  \left#1\vbox to10.25pt{}\right.\n@space$}}}
\def\eightBig#1{{\hbox{$\bigfences
  \left#1\vbox to9.25pt{}\right.\n@space$}}}

\def\tenbigg#1{{\hbox{$\bigfences
  \left#1\vbox to14.5pt{}\right.\n@space$}}}
\def\ninebigg#1{{\hbox{$\bigfences
  \left#1\vbox to13pt{}\right.\n@space$}}}
\def\eightbigg#1{{\hbox{$\bigfences
  \left#1\vbox to11.5pt{}\right.\n@space$}}}

\def\tenBigg#1{{\hbox{$\bigfences
  \left#1\vbox to17.5pt{}\right.\n@space$}}}
\def\nineBigg#1{{\hbox{$\bigfences
  \left#1\vbox to15.75pt{}\right.\n@space$}}}
\def\eightBigg#1{{\hbox{$\bigfences
  \left#1\vbox to14pt{}\right.\n@space$}}}

% Page layout
\newdimen\pagewidth \newdimen\pageheight \newdimen\ruleht
\hsize=29pc  \vsize=45pc  \maxdepth=2.2pt  \parindent=19pt
\pagewidth=\hsize \pageheight=\vsize \ruleht=.5pt
\abovedisplayskip=6pt plus 3pt minus 1pt
\belowdisplayskip=6pt plus 3pt minus 1pt
\abovedisplayshortskip=0pt plus 3pt
\belowdisplayshortskip=4pt plus 3pt

\hyphenpenalty=500
\vbadness=200
\widowpenalty=10000
\clubpenalty=10000

%\newinsert\footins % \footins is already defined in plain.tex
\def\footnote#1{\edef\@sf{\spacefactor\the\spacefactor}#1\@sf
      \insert\footins\bgroup\eightpoint
      \interlinepenalty100 \let\par=\endgraf
        \leftskip=\z@skip \rightskip=\z@skip
        \splittopskip=10pt plus 1pt minus 1pt \floatingpenalty=20000
        \smallskip\textindent{#1}\bgroup\strut\aftergroup\@foot\let\next}
\skip\footins=\medskipamount % space added when footnote is present
\dimen\footins=30pc % maximum footnotes per page

\newinsert\margin
\dimen\margin=\maxdimen
\count\margin=0 \skip\margin=0pt % marginal inserts take up no space

\newif\iftitle \newif\ifdrop \newif\ifrunon
\def\titlepage{\global\titletrue\global\droptrue} % for pages without headlines
\def\lhead{} % running headline on lefthand pages (usually chapter name)
\def\rhead{} % running headline on righthand pages (usually section name)

% the value of \lhead is never set automatically
% see The TeXbook, page 260, for explanation of the \mark commands below

\def\leftheadline{\hbox to \pagewidth{%
    \vbox to 10pt{}% strut to position the baseline
    \hbox to.45in{\tenrm\folio\hfil}% page number flush left
    \spaceskip=4.5pt \eightrm\lhead\hfill % then running left head
    \tenrm \expandafter\iffalse\topmark\fi % section number flush right
    }}
\def\rightheadline{\hbox to \pagewidth{%
    \vbox to 10pt{}% strut to position the baseline
    \tenrm \iftrue\botmark\fi % section number flush left
    \spaceskip=4.5pt \hfill\eightrm\rhead % then running right head
    \hbox to.45in{\hfil\tenrm\folio}% page number flush right
    }}

\newdimen\htrimsize \htrimsize=6.375in
\newdimen\vtrimsize \vtrimsize=9.25in
\newdimen\outermargin \outermargin=22mm
\newdimen\topmargin \topmargin=15mm % plus height of the headline box
\newbox\htrim \newbox\vtrim \newbox\trimmarks
\setbox\htrim=\hbox to\htrimsize{\kern-.5in
  \vrule height .2pt depth .2pt width .4in\hfil\vrule width.4in\kern-.5in}
  \wd\htrim=0pt
\setbox\vtrim=\vbox to\vtrimsize{\kern-.5in
  \moveleft.2pt\hbox{\vrule height .4in}\vfil
  \moveleft.2pt\hbox{\vrule height .4in}\kern-.5in}
  \wd\vtrim=0pt
\setbox\trimmarks=\hbox to0pt{\raise\vtrimsize\copy\htrim \copy\htrim
     \copy\vtrim \kern\htrimsize \copy\vtrim\hss}
  \ht\trimmarks=0pt \dp\trimmarks=0pt

\newif\iffinal % are we making the final copy? (pages.tex says "999")
\def\onepageout#1{\shipout\vbox{ % here we define one page of output
    \iffinal % add the trim marks
      \hbox to\htrimsize{\copy\trimmarks
         \ifodd\pageno\hss\else \hskip\outermargin\fi
         \vbox to\vtrimsize{\kern\topmargin\vbox{ \fi
    \offinterlineskip % butt the boxes together
    \vbox to 2pc{ % this part goes on top of the 45pc pages
      \iftitle % the next is used for title pages
        \global\titlefalse % reset the titlepage switch
      \else\ifodd\pageno \rightheadline\else\leftheadline\fi\fi
      \vfill} % this completes the \vbox to 3pc
    \vbox to \pageheight{
      \ifvoid\margin\else % marginal info is present
        \rlap{\kern31pc\vbox to\z@{\kern4pt\box\margin \vss}}\fi
      \ifvoid\topins\else\unvbox\topins\fi
      #1 % now insert the main information
      \ifvoid\footins\else % footnote info is present
        \vskip\skip\footins \kern-3pt
        \hrule height\ruleht width5pc \kern-\ruleht \kern3pt
        \unvbox\footins\fi
      \boxmaxdepth=\maxdepth
      } % this completes the \vbox to \pageheight
    \ifdrop % now we add the `drop folio' on title pages
      \hbox to\pagewidth{\vbox to12pt{}\hfill\eightrm\folio\hfill}
      \global\dropfalse
    \fi
    \iffinal % finish the trimmed page
      }\vfill}\ifodd\pageno\hskip\outermargin\else\hss\fi
      \rlap{\smash{\lower30pt\hbox to.5in{\hfil\twelvett\number\pageno}}}}\fi
    }
  \advancepageno}

\output{\onepageout{\unvbox255}}

\newbox\partialpage \newdimen\outervsize
\def\begindoublecolumns{\begingroup \outervsize=\vsize
  \output={\ifnum \outputpenalty=-12345
     \global\setbox\partialpage=\vbox{\unvbox255\bigskip}%
    \else \onepageout{\unvbox255}\fi}
  \par\penalty-12345 \output={\doublecolumnout} \hsize=14pc \vsize=90pc
  \global\advance\vsize -2\ht\partialpage}
\def\enddoublecolumns{\output={\balancecolumns
  \global\vsize=\outervsize}\eject \endgroup \pagegoal=\vsize}

\def\doublecolumnout{\splittopskip=\topskip \splitmaxdepth=\maxdepth
  \dimen@=45pc \advance\dimen@ by-\ht\partialpage
  \setbox0=\vsplit255 to\dimen@ \setbox2=\vsplit255 to\dimen@
  \onepageout\pagesofar
  \global\vsize=90pc
%  \scrollmode\showbox255\errorstopmode
  \unvbox255 \penalty\outputpenalty}
\def\pagesofar{\unvbox\partialpage
  \wd0=\hsize \wd2=\hsize \hbox to\pagewidth{\box0\hfil\box2}}
\def\balancecolumns{\setbox0=\vbox{\unvbox255} \dimen@=\ht0
  \advance\dimen@ by\topskip \advance\dimen@ by-\baselineskip
  \divide\dimen@ by2 \splittopskip=\topskip
  {\vbadness=10000 \loop \global\setbox3=\copy0
    \global\setbox1=\vsplit3 to\dimen@
    \ifdim\ht3>\dimen@ \global\advance\dimen@ by1pt \repeat}
  \setbox0=\vbox to\dimen@{\unvbox1}
  \setbox2=\vbox to\dimen@{\unvbox3}
  \pagesofar}

% To produce only a subset of pages, put the page numbers on separate
% lines in a file called pages.tex
\newif\ifsubset
\let\Shipout=\shipout
\newread\pages \newcount\nextpage \openin\pages=pages
\def\getnextpage{\ifeof\pages\else
 {\endlinechar=-1\read\pages to\next
  \ifx\next\empty % in this case we should have eof now
  \else\global\nextpage=\next\fi}\fi}
\ifeof\pages\finalfalse\subsetfalse\else\finaltrue\proofmodefalse
 \getnextpage
 \ifnum\nextpage=999
    \subsetfalse\message{OK, I'm making final copy, not proofs!}
    \getnextpage % this should ensure eof on the \pages file
 \else\subsettrue\message{OK, I'll ship only the requested pages!}\fi\fi
\def\shipout{\ifeof\pages\let\next=\Shipout
 \else\ifnum\pageno=\nextpage\getnextpage\let\next=\Shipout
  \else\let\next=\Tosspage\fi\fi \next}
\newbox\garbage \def\Tosspage{\deadcycles=0\setbox\garbage=}

% Chapter formatting
\def\typeset #1#2 { % in "run" directory, direct TeX to proper "chap" directory
  \dorefin #1#2
  \ifsubset
    \immediate\openout\refo=tmp.ref
    \immediate\openout\ansfile=tmp.ans
    \immediate\openout\inx=tmp.inx
  \else
    \immediate\openout\refo=../chap#1/#1#2.ref
    \immediate\openout\ansfile=../chap#1/#1#2.ans
    \immediate\openout\inx=../chap#1/#1#2.inx
  \fi
  \miscount=0
  \input ../chap#1/#1#2.tex
  \par
  \immediate\closeout\ansfile
  \immediate\closeout\refo
  \ifnum\miscount>0
    \message{(\the\miscount\space undefined references were present)}\fi
  \ifnum\changecount>0
    \message{(\the\changecount\space new references written on #1#2.ref)}\fi
  \ifnum\defcount>0
    \message{(\the\defcount\space old references dropped from #1#2.ref)}\fi
}
\def\typesetans#1#2 {\beginanswers {#1#2}.
  \dorefin #1#2
  \input ../chap#1/#1#2.ans
}

\def\currentsection{} % the number of the current section
\def\xskip{\hskip 7pt plus 3pt minus 4pt}

\def\beginchapter#1: #2.
  {\vfill\eject
    \titlepage
    \leftline{\twelvess \spaceskip=10pt \def\\{\kern1pt}#1}
    \vskip 4pc
    \rightline{\titlefont #2}
    \def\\{}
    \ifx\rhead\omitrhead\else{\ninepoint\xdef\rhead{\uppercase{#2}}}\fi
    \vskip 2pc plus 1 pc minus 1 pc
  }

\def\starred{}
\def\starit{\def\starred{\llap{*}}}
\def\omitrhead{\omit}

\def\beginsection #1. #2.
  {\mark{\currentsection \noexpand\else #1}
    \ifrunon \runonfalse\vskip 1 cm plus 1 pc minus 5 pt
    \else \vfill\eject
      {\output{\setbox0=\box255}\null\vfill\eject} % set \topmark for sure
    \fi
    \tenpoint
    \leftline{\tenssbx\starred#1. \uppercase{#2}}
    \def\starred{}
    \mark{#1\noexpand\else #1}
    \def\currentsection{#1}
    {\ninepoint\xdef\rhead{\uppercase{#2}}}
    \nobreak\smallskip\noindent}

\def\beginsectionnonumber #1.
  {\ifrunon \runonfalse\vskip 1 cm plus 1 pc minus 5 pt
    \else \vfill\eject \fi
    \tenpoint
    \leftline{\tenssbx\starred\uppercase{#1}}
    \def\starred{}
    {\ninepoint\xdef\rhead{\uppercase{#1}}}
    \nobreak\smallskip\noindent}

\def\beginsubsection #1. #2.
  {\mark{\currentsection \noexpand\else #1}
    \bigbreak
    \tenpoint
    \leftline{\tenssbx\starred#1. #2}
    \def\starred{}
    \mark{#1\noexpand\else #1}
    \def\currentsection{#1}
    {\ninepoint\xdef\rhead{\uppercase{#2}}}
    \nobreak\smallskip\noindent}

\def\beginsubsubsection #1. #2.    % set page headers: 3.2.1.3
  {\mark{\currentsection \noexpand\else #1}
    \tenpoint
    \bigbreak
    \null
    \mark{#1\noexpand\else #1}
    \def\currentsection{#1}
    {\ninepoint\xdef\rhead{\uppercase{#2}}}
    \nobreak\vskip-\baselineskip
    \noindent{\bf\starred#1.\enspace #2.\xskip}\def\starred{}\ignorespaces}

\def\beginsubsubsectionprime #1.  % don't set page headers: 3.3.1B
  {\medbreak
    \null
    \tenpoint
    \nobreak\vskip-\baselineskip
    \noindent{\bf\starred#1.\xskip}\def\starred{}\ignorespaces}

\def\fixmark #1 {\eject % output before changing \currentsection
    \mark{#1\noexpand\else #1}
    \def\currentsection{#1}
    {\output{\setbox0=\box255}\null\vfill\eject} % set \topmark for sure
  }  % use this when a subsection ends on right-hand page

\def\beginex#1:{\bigbreak
  \leftline{\tenssbx #1}
  \ninepoint
  \nobreak\smallskip}

\def\beginanswers #1.
  {\mark{\currentsection \noexpand\else #1}
    \bigbreak
    \gdef\currentsection{#1} % avoid getting random section number
                             % when page break falls between sections
    \leftline{\tenssbx SECTION #1}
    \mark{#1\noexpand\else #1}
    \nobreak\smallskip}

\def\beginanswersnosection #1.
  {\mark{\currentsection \noexpand\else #1}
    \bigbreak
    \leftline{\tenssbx #1}
    \mark{#1\noexpand\else #1}
    \nobreak\smallskip}

\def\beginconstruction{\medbreak
  \begingroup
  \noindent\hang\hangafter=-2
  \smash{\hbox to0pt{\hskip-\hangindent
    \lower\baselineskip\hbox{\epsfbox{\figdir/aux.301}}\hfill}}%
   \sl}
\let\endconstruction=\endgroup
  
\def\quoteformat{
  \baselineskip 10pt
  \parfillskip \z@
  \interlinepenalty 10000
  \leftskip \z@ plus 40pc minus \parindent
  \let\rm=\eightss \let\sl=\eightssi \let\adbcfont=\sixss
  \everypar{\sl}
  \def\\{\hskip.05em} % can say 3\\:\\16
  \obeylines}
\def\author#1(#2){\smallskip\noindent\rm--- #1\unskip\enspace(#2)}

\newwrite\ansfile
\immediate\openout\ansfile=\jobname.ans % file for answers to exercises
\outer\def\answer{\par
  \immediate\write\ansfile{}
  \ifnum\curexno>1 \immediate\write\ansfile{\string\smallbreak}\fi
  \immediate\write\ansfile{\string\ans\curexno.}
  \copytoblankline}
\outer\def\answers#1, #2.{\par
  \immediate\write\ansfile{}
  \ifnum#1>1 \immediate\write\ansfile{\string\smallbreak}\fi
  \immediate\write\ansfile{\string\anss#1, #2.}
  \copytoblankline}
\def\copytoblankline{\begingroup\setupcopy\copyans}
\def\setupcopy{\def\do##1{\catcode`##1=\other}\dospecials
  \catcode`\|=\other \obeylines}
{\obeylines \gdef\copyans#1
  {\def\next{#1}%
  \ifx\next\empty\let\next=\endgroup %
  \else\immediate\write\ansfile{\next} \let\next=\copyans\fi\next}}

% macros for verbatim scanning
% the max number of \tt chars/line is 66 (10pt), 73 (9pt), 81 (8pt), 93 (7pt)
% minus 4 or 5 characters for indentation at the left
\chardef\other=12
\def\ttverbatim{\catcode`\\=\other
  \catcode`\{=\other
  \catcode`\}=\other
  \catcode`\$=\other
  \catcode`\&=\other
  \catcode`\#=\other
  \catcode`\%=\other
  \catcode`\~=\other
  \catcode`\_=\other
  \catcode`\^=\other
  \obeyspaces \obeylines \tt}
\def\begintt{$$\ttverbatim \catcode`\|=0 \ttfinish}
{\catcode`\|=0 \catcode`|\=\other % | is temporary escape character
  |obeylines   % end of line is active
  |gdef|intt#1^^M{|noalign{#1}}%
  |gdef|ttfinish#1^^M#2\endtt{#1|let^^M=|cr %
    |halign{|hskip|parindent##|hfil|cr#2}$$}}

% Composition macros

\hyphenation{logical Mac-Mahon hyper-geo-metric hyper-geo-met-rics Ber-noulli
 Greg-ory dis-trib-uted sub-sequence sub-sequences}

{\obeyspaces\gdef {\ }}
\def\hang{\hangindent\parindent}
\def\hangin{\hangindent=2\parindent}
\def\alaligne{\par\noindent} % silvio's \`a la ligne, used in 1.3.1
\def\]{\leavevmode\hbox{\tt\char`\ }}  % visible space
\def\!{\ifmmode\mskip-\thinmuskip\else\ignorespaces\fi} % TeX78 compatibility
\def\og#1{\leavevmode\vtop{% crude approximation of Polish ogonek
  \baselineskip0pt\lineskip0pt\lineskiplimit0pt
  \ialign{##\crcr\relax#1\cr
    \hidewidth\kern.2em
    \dimen0=.0040ex \multiply\dimen0\fontdimen1\font
    \kern-.0156\dimen0`\hidewidth\cr}}}
\def\with{--}
\def\dash---{\thinspace---\hskip.16667em\relax}
\def\bigparen#1{\leavevmode\smash{$\big#1$}} % (added after Vol 1 was finished)
% In \tenpoint style, the \bigl( and \bigr) are a teeny bit bigger than 12pt,
% so smashing them is needed to prevent excessive \lineskip glue! -- 97.07.05
\def\sspace{\spacefactor3000 \space} % space between sentences
\def\eq(#1){\hbox{\rm({\oldstyle#1})}}
\let\EQNO=\eqno \def\eqno(#1){\EQNO\eq(#1)}
\def\star{\llap{*}}
\def\Sigmait{{\mit\Sigma}}
\def\losub#1{^{\vphantom\prime}_{#1}} % for contexts like $x'_n+x\lowsub n$
\def\losup#1{\raise.6ex\hbox{$\scriptstyle#1$}}
\def\slug{\hbox{\kern1.5pt\vrule width2.5pt height6pt depth1.5pt\kern1.5pt}}
\def\slugonright{\vrule width0pt\nobreak\hfill\slug}
\let\:=\. % preserve a way to get the dot accent
\def\hair{\kern.05em\relax} % teeny tiny space
\newdimen\eightx \eightx=\fontdimen5\eightrm % xheight
\def\tenii{{\edef\nxt{\the\font}\fontdimen5\eightrm=3.2333pt % macron over \i
         \eightrm\accent22\nxt\i\fontdimen5\eightrm=\eightx}} % in 10pt only!
\def\eightii{\vbox{\offinterlineskip\halign{\hfil##\hfil\cr
 \vrule height .25pt depth 0pt width 2pt\cr\noalign{\vskip.8444pt}\i\cr}}}
\def\.#1{\leavevmode\hbox{\tt#1}}
\def\[#1]{[\hbox{$\mkern1mu\thickmuskip=\thinmuskip#1\mkern1mu$}]} % Iverson
\def\bigi[#1]{\bigl[\begingroup\mkern1mu\thickmuskip=\thinmuskip
          #1\mkern1mu\endgroup\bigr]} % big Iverson brackets
\def\AD.{{\adbcfont A}.{\adbcfont D}.}
\def\BC.{{\adbcfont B}.{\adbcfont C}.}
\def\og#1{\leavevmode\vtop{\baselineskip\z@skip \lineskip-.2ex
  \lineskiplimit\z@ \ialign{##\cr\relax#1\cr
    \hidewidth\kern.3em\sh@ft{40}`\hidewidth\cr}\kern-1ex}} % ogonek
\def\em#1:{{\it#1:\/}} % \em Hint: or \em Caution: or \em Reference: etc
\def\sic/{\relax} % use this when it looks like I made a booboo but I didn't

\mathcode`\@="8000 {\catcode`\@=\active \gdef@{\mkern1mu}}
\def\?{\mkern-1mu}
\def\rising#1{^{\,\overline{\mkern-2mu#1\mkern-2mu}}}
\def\falling#1{^{\ff{#1}}}
\def\ff#1{\mkern1mu\underline{\mkern-1mu#1\mkern-2mu}\mkern2mu}
\let\plainunder=\_
\def\_{\ifmmode^{\smash-\mkern-1mu1}\else\plainunder\fi} % ^{-1} (in math mode)
\def\iter#1{^{[#1]}} % iteration of functions
\def\bbarw{\,\bar {\!\bar w}} % hand-tweaked double-bar w
\def\ostar{\vbox{\baselineskip\z@\lineskiplimit-\maxdimen % MIXAL current loc
        \halign{\hfil##\hfil\cr$\odot$\cr\lower.5556pt\hbox{\tt*}\cr}}}
\def\half{{1\over2}}
\def\frac#1/#2{\leavevmode\kern.1em
  \raise.5ex\hbox{\the\scriptfont0 #1}\kern-.1em
  /\kern-.15em\lower.25ex\hbox{\the\scriptfont0 #2}}
\def\divides{\backslash}
\def\ndivides{\mathpalette\notdiv\relax}
\def\notdiv#1#2{\setbox0=\hbox{$#1\divides$}%
 \vcenter{\hbox to\wd0{$\hss\scriptscriptstyle/\hss$}}\kern-\wd0
 \vcenter{\hbox to\wd0{$\hss\kern.5pt\scriptscriptstyle/\hss$}}\kern-\wd0
 \box0\relax}
\def\dts{\mathinner{\ldotp\ldotp}}
\def\ldotsshifted{\mkern-2mu\ldots\mkern1mu} %for use after an exponent
\def\adj{\mathrel-\joinrel\joinrel\mathrel-} % adjacent vertices
\def\precsim{\mathrel{\vcenter{\offinterlineskip
  \kern.4ex\hbox{$<$}\kern.1ex\hbox{$\sim$}}}} % special relation used in 5.1.4
\def\symord/{\vcenter{\hbox{$\scriptstyle\char"24$}}}
     % $ sign for symmetric order P$ or $P
\def\postord/{\vcenter{\hbox{$\scriptstyle\mathchar"15D$}}}
     % # sign for postorder P# or #P
\def\lcm{\mathop{\rm lcm}}
\def\cont{\mathop{\rm cont}}
\def\pp{\mathop{\rm pp}}
\def\gcrd{\mathop{\rm gcrd}}
\def\Pro{\mathop{\overline{\rm Pr}}}
\def\Pru{\mathop{\underline{\rm Pr}}}
\def\rsh{\mathbin{{-}\mkern-12mu\rlap{$\mkern8mu-$}\gg}} % left shift
\def\lsh{\mathbin{\ll\llap{$-\mkern8mu$}\mkern-12mu{-}}} % right shift
\def\interc{\mathbin{\raise.7ex\vtop{\hrule % intercalation product
      \hbox{\kern.15em\vrule height 1.1ex\kern.15em}}}}
\def\capdot{\mathchoice{\cpdt{}}{\cpdt{}}{\cpdt\scriptstyle}%
 {\cpdt\scriptscriptstyle}}
\def\bigcapdot{\mathchoice{\bcpdt\displaystyle}{\bcpdt{}}{\bcpdt{}}{\bcpdt{}}}
\def\cpdt{\gcpdt\mathbin\cap.}
\def\bcpdt{\gcpdt\mathop\bigcap{\lower.3\ht0\hbox{\bf.}}}
\def\gcpdt#1#2#3#4{#1{\setbox0=\hbox{$#4#2$}\vtop{\copy0
  \vskip-\baselineskip\kern-.2\ht0\hbox to\wd0{\hss#3\hss}}}}
\def\upr#1{\mathbin{\vbox{\tenpoint\halign % floating point interval arithmetic
  {\hfil$\vcenter{\hbox{$##$}}$\hfil\cr\bigtriangleup\cr
        \noalign{\vskip-\baselineskip}\scriptscriptstyle#1\cr}}}}
\def\lwr#1{\mathbin{\vbox{\tenpoint\halign
  {\hfil$\vcenter{\hbox{$##$}}$\hfil\cr\bigtriangledown\cr
        \noalign{\vskip-\baselineskip}\scriptscriptstyle#1\cr}}}}
\def\expcirc#1{\raise.7ex\hbox{\ooalign{\hfil\raise.07ex % circled exponent
        \hbox{$\scriptstyle#1$}\hfil\crcr\mathhexbox20D}}}
\def\circR{\mathbin{\ooalign{\hfil % binary op defined in 5.1.2
  \raise.15ex\hbox{$\scriptscriptstyle\mkern-2mu R$}\hfil\crcr\mathhexbox20D}}}
\def\ovC{\,@\overline{\!\!@@C\!@@}@}%
\def\anda{\mathbin{\vcenter{
  \hbox{$\wedge$}\nointerlineskip\vskip-.5ex\hbox{$\wedge$}}}} % double and
\def\ora{\mathbin{\vcenter{
      \hbox{$\vee$}\nointerlineskip\vskip-.5ex\hbox{$\vee$}}}} % double or
\def\mean{\mathop{\rm mean}}
\def\E{\mathop{\hbox{\rm E}}}
\def\var{\mathop{\rm var}}
\def\mod{\mkern4mu{\rm mod}\penalty900\mkern4mu}
\let\bmod=\error \let\pmod=\error % don't use plain TeX's old "mod" conventions
\def\umod{\mkern4mu\mathbin{\underline{\rm mod}}\penalty900\mkern4mu}
\def\omod{\hbox to 25pt{\hss
            \raise2.5pt\hbox{$\vcenter{\hbox{\manfnt\char'130}}$}\hss}%
         \kern-25pt\raise .3pt\hbox to 25pt{\hss
            $\vcenter{\moveleft .2pt\hbox{\sixrm mod}}$\hss}}
\def\modulo#1{\ifinner \unskip\allowbreak\ \hbox{\rm(modulo $#1$)}%
  \else \unskip\enspace\hbox{\rm(modulo $#1$)}\fi}
\def\Modulo#1){\ifinner \unskip\allowbreak\ \bigl(\hbox{\rm modulo }#1)\bigr)%
  \else \unskip\enspace\bigl(\hbox{\rm modulo }#1)\bigr)\fi}
\def\fzmod#1{\ifinner \penalty0\;\bigl($modulo $f(z)$ and~$#1\bigr)
\else \penalty0\;\bigl(\hbox{modulo $f(z)$ and $#1$}\bigr) \fi}
\def\hisqrt#1{\sqrt{\raise.2ex\hbox{\vphantom{$#1$}}\smash{#1}}} % raised \sqrt
\def\hihisqrt#1{\sqrt{\raise.5ex\hbox{\vphantom{$#1$}}\smash{#1}}}
\def\littlehisqrt#1{\sqrt{\raise.14ex\hbox{\vphantom{$\scriptstyle#1$}}\smash{#1}}}
\def\esqrt#1{\sqrt{\vphantom2\smash{#1}}}
\def\root#1\of{\setbox\rootbox\hbox{\raise1pt\hbox{$\m@th\scriptscriptstyle{#1}$}}\mathpalette\r@@t} % raise the parameter 1pt from PLAIN's version
\def\euler{\atopwithdelims<>}
\def\Euler#1#2{\mathchoice{\biggl<\mkern-7mu\biggl<{#1\atop#2}\biggr>\mkern-7mu\biggr>}%
 {\left<\!{#1\euler#2}\!\right>}{}{}}
\def\Choose#1#2{\mathchoice{\biggl(\mkern-7mu{#1\chooser#2}\mkern-7mu\biggr)}%
 {\left(\!{#1\choose#2}\!\right)}{}{}}
\def\jacobi{\overwithdelims()}
\def\smsum{\mathop{\vcenter{\hbox{\tenrm\char6}}}} % small summation sign
\def\phihat{{\mkern5mu\vbox{\halign{\hfil$##$\hfil\cr\widehat{}\cr
 \noalign{\kern-1.61803ex\nointerlineskip}\mkern-4mu\phi\cr}}\mkern3mu}}
\def\dolS{\hbox{\sl\$}} % slanted $
\def\cursor{\vcenter{\offinterlineskip\halign{\hbox to0pt{\hss##\hss}\cr
  \fivei\char'136\cr\noalign{\vskip-.5pt}
  \vrule height1.74ex depth.58ex width .2pt\cr
  \fivei\char'137\cr}}}
\def\gray#1{\vspec{.7 setgray}#1\vspec{0 setgray}}
\def\bslash{/\mkern-4.5mu/}  % for continued fractions
\def\bigbslash{\big/\mkern-6mu\big/}
\def\vpic#1{$\vcenter{\hbox{\beginpicture#1\endpicture}}$} % picture in text
\def\eqalignbot#1{\null\,\vbox{\openup\jot\m@th % useful for placing \eqno's
  \ialign{\strut\hfil$\displaystyle{##}$&$\displaystyle{{}##}$\hfil
      \crcr#1\crcr}}\,}
\def\eqaligntop#1{\null\,\vtop{\openup\jot\m@th
  \ialign{\strut\hfil$\displaystyle{##}$&$\displaystyle{{}##}$\hfil
      \crcr#1\crcr}}\,}
\def\eqalignalignno#1{\displ@y \tabskip\centering % two alignments plus eqno
  \halign to\displaywidth{\hfil$\@lign\displaystyle{##}$\tabskip\z@skip
    &$\@lign\displaystyle{{}##}$\hfil % this is what I added to \eqalignno
    &$\@lign\displaystyle{{}##}$\hfil\tabskip\centering
    &\llap{$\@lign##$}\tabskip\z@skip\crcr
    #1\crcr}}
\def\beginfieldcolon{\begingroup\mathcode`\:="8000 } % special formatting of :
\def\deweyperiod{\mathcode`\.="8000 }                % special formatting of .
\let\endfieldcolon\endgroup
{\catcode`\:=\active \gdef:{\mskip2mu minus .5mu
  \mathchar"003A \mskip2mu minus .5mu}}
{\catcode`\.=\active \gdef.{\mathchar"013A@}}
\def\adjustpar#1#2{\dimen0=\fontdimen#1\textfont2
  \advance\dimen0 by #2 \fontdimen#1\textfont2=\dimen0\relax}
\def\adjustnum{\adjustpar9} % adjust normal height of textstyle numerator
\def\adjustdenom{\adjustpar{12}} % adjust normal depth of textstyle denominator
\def\twolineadjust{\adjustpar{10}{-.1ex}\adjustpar{12}{-.3ex}}
   % that brings textstyle \atops closer together
\def\twolinerestore{\adjustpar{10}{.1ex}\adjustpar{12}{.3ex}}

% silvio's cartouche macros
\newdimen\cartouchethickness
\cartouchethickness=\fontdimen8\tencirc % thickness of lines in the circle font
\newdimen\cartoucheradius
\setbox4=\hbox{\tencirc\char7} % 8pt diameter quartercircle
\cartoucheradius\wd4
\def\cartouche#1{%
 \vcenter{\offinterlineskip
  \vskip-4pt
  \halign{##\cr
   \tencirc\char7
   \hskip-.5\cartoucheradius \leaders\hrule height\cartouchethickness\hfil
   \hskip.5\cartoucheradius \char4
   \hskip-\cartoucheradius \hskip\cartouchethickness \cr\noalign{\vskip3pt}
   \smash{\vrule depth-1.5pt height 3pt width \cartouchethickness
   \eightpoint\thinspace #1\thinspace
   \vrule depth-1.5pt height 3pt width\cartouchethickness}\cr\noalign{\vskip-1.5pt}
   \tencirc\char6
   \hskip-.5\cartoucheradius \leaders\hrule height\cartouchethickness\hfil
   \hskip.5\cartoucheradius \char5
   \hskip-\cartoucheradius \hskip\cartouchethickness \cr}
  \vskip-4pt
}}
\def\mcircle#1{$\hskip0pt minus 10pt\cartouche{#1}\!$}
%\def\ocos{\mathop{\cartouche{cos}}}
\def\ocos{\hbox to 25pt{\hss
            \raise2.5pt\hbox{$\vcenter{\hbox{\manfnt\char'130}}$}\hss}%
         \kern-25pt\raise .3pt\hbox to 25pt{\hss
            $\vcenter{\moveleft .2pt\hbox{\ninerm cos}}$\hss}}

% Silvio's mods for last part of Vol3
% 12pt circle in reference position (use with single letters and digits)
\def\cir(#1){{\unitlength=1pt\,\beginpicture(12,7.5)(-6,-1.5)
   \put(0,1){\circle{12}}
   \endpicture
   \kern-12pt
   \hbox to12pt{\hss$#1$\hss}\,}}%
% 14pt circle, moved down .3pt (use with b_i for example)
\def\cira(#1){{\unitlength=1pt\,\beginpicture(14,7.5)(-7,-1.5)
   \put(0,.7){\circle{14}}
   \endpicture
   \kern-14pt
   \hbox to14pt{\hss$#1$\hss}\,}}%
% oval in reference position (use with n+1)
\def\ov(#1){{\unitlength=1pt\,\beginpicture(21,7.5)(-10.5,-1.5)
   \put(0,1){\oval(21,12)}
   \endpicture
   \kern-21pt
   \hbox to21pt{\hss$#1$\hss}\,}}%
% big oval in reference position (use with q_i+q_j)
\def\bigov(#1){{\unitlength=1pt\,
   \beginpicture(32,7.5)(-16,-1.5)
   \put(0,1){\oval(32,12)}
   \endpicture
   \kern-32pt
   \hbox to32pt{\hss$#1$\hss}\,}}%
% 12pt square in reference position
\def\sq(#1){{\unitlength=1pt\,\beginpicture(12,7.5)(-6,-1.5)
   \put(-5.5,-4.5){\line(0,1){11}}
   \put(-5.5,-4.5){\line(1,0){11}}
   \put(5.5,6.5){\line(0,-1){11}}
   \put(5.5,6.5){\line(-1,0){11}}
   \endpicture
   \kern-12pt
   \hbox to12pt{\hss$#1$\hss}\,}}%
% square moved down .3pt
\def\sqa(#1){{\unitlength=1pt\,\beginpicture(12,7.5)(-6,-1.5)
   \put(-5.5,-4.8){\line(0,1){11}}
   \put(-5.5,-4.8){\line(1,0){11}}
   \put(5.5,6.2){\line(0,-1){11}}
   \put(5.5,6.2){\line(-1,0){11}}
   \endpicture
   \kern-12pt
   \hbox to12pt{\hss$#1$\hss}\,}}%
% square moved down 1pt (use with q_i)
\def\sqb(#1){{\unitlength=1pt\,\beginpicture(12,7.5)(-6,-1.5)
   \put(-5.5,-5.5){\line(0,1){11}}
   \put(-5.5,-5.5){\line(1,0){11}}
   \put(5.5,5.5){\line(0,-1){11}}
   \put(5.5,5.5){\line(-1,0){11}}
   \endpicture
   \kern-12pt
   \hbox to12pt{\hss$#1$\hss}\,}}%
% rectangle in reference position
\def\rect(#1){{\unitlength=1pt\,\beginpicture(22,7.5)(-11,-1.5)
   \put(-10.5,-4.5){\line(0,1){11}}
   \put(-10.5,-4.5){\line(1,0){21}}
   \put(10.5,6.5){\line(0,-1){11}}
   \put(10.5,6.5){\line(-1,0){21}}
   \endpicture
   \kern-22pt
   \hbox to22pt{\hss$#1$\hss}\,}}%

% TeX78 conventions for alignments
%
\def\lft#1{#1\hfil}
\def\ctr#1{\hfil#1\hfil}
\def\rt#1{\hfil#1}
\def\cpile#1{\vcenter{\halign{\hfill$## $\hfill\cr#1}}}
\def\lpile#1{\vcenter{\halign{$## $\hfill\cr#1}}}
\def\rpile#1{\vcenter{\halign{\hfill$## $\cr#1}}}

\newdimen\algindent
\newif\ifitempar \itempartrue % normally true unless briefly set false
\def\algindentset#1{\setbox0\hbox{{\bf #1.\kern.25em}}\algindent=\wd0\relax}
\def\algbegin #1 #2{\algindentset{#21}\alg #1 #2} % when steps all have 1 digit
\def\aalgbegin #1 #2{\algindentset{#211}\alg #1 #2} % when 10 or more steps
\def\alg#1(#2). {\medbreak % Usage: \algbegin Algorithm A (algname). This...
  \noindent{\bf#1}({\it#2\/}).\xskip\ignorespaces}
\def\algstep#1.{\ifitempar\smallskip\noindent\else\itempartrue
  \hskip-\parindent\fi
  \hbox to\algindent{\bf\hfil #1.\kern.25em}%
  \hangindent=\algindent\hangafter=1\ignorespaces}
\def\thbegin#1. {\medbreak\noindent {\bf#1.}\xskip\ignorespaces}
\def\proof.{\medbreak\noindent{\it Proof.}\xskip\ignorespaces}
\def\solution.{\medbreak\noindent{\it Solution.}\xskip\ignorespaces}

\def\caption Fig.\ #1. {\ninepoint{\bf Fig.\ #1.}\enspace}
\def\tablehead#1{\eightpoint\centerline{\tenssbx#1}\nobreak\vskip3pt}
\newskip\abovetableskip\abovetableskip=4 pt plus 2 pt minus 1 pt
\newskip\belowtableskip\belowtableskip=6 pt plus 2 pt minus 1 pt

\def\ex #1. [#2]{\ifnum #1>1 \smallbreak\fi
  \gdef\curexno{#1}%
  \textindent{\bf#1.}[{\it#2\/}]\kern6pt}
\def\EX #1. [#2]{\ifnum #1>1 \smallbreak\fi
  \gdef\curexno{#1}%
  \textindent{\llap{\manfnt x\hskip3pt}\bf{\hbox
        to 1em{\hfil#1}}.}[{\it#2\/}]\kern6pt}
\def\HM{H\kern-.1em M} % used for "higher math" exercise ratings
\def\MN{M\kern-.1em N} % used in Section 4.3.1 when $MN$ appears frequently
\def\ans #1. {\textindent{\bf#1.}}
\def\anss #1, #2. {\noindent
   \hbox to\parindent{\hss\bf#1,\enspace}\kern-.5em{\bf\thinspace#2.}\enspace}
\def\answeritem(#1){\ifitempar\par
   \else\itempartrue\fi(#1)\enspace\ignorespaces}

\def\CEE/{{\mc C\spacefactor1000}}% the C programming language
\def\FORTRAN/{{\mc FORTRAN\spacefactor1000}}% ditto for the older guy
\def\ALGOL/{{\mc ALGOL\spacefactor1000}}
\def\COBOL/{{\mc COBOL\spacefactor1000}}
\def\MIX{{\tt MIX\spacefactor1000}}
\def\MMIX{{\tt MMIX\spacefactor1000}}
\def\rA{\hbox{\rm rA}}
\def\rX{\hbox{\rm rX}}
\def\rAX{\hbox{\rm rAX}}
\def\rI{\hbox{\rm rI}}
\def\rJ{\hbox{\rm rJ}}

% for Young tableaux (see example of use in answer 51, page 3.641)
\def\cell#1{\kern-.2pt\vbox to12pt{\kern-.2pt\hrule\kern-.2pt
    \hbox{\vrule height8.5pt depth3.5pt\hbox to12pt{\hss#1\hss}\vrule}
    \kern-.2pt\hrule\kern-.2pt}\kern-.2pt}

% to typeset assembly code, use:
%  \mixtwo   for opcode and address
%  \mixthree for location, opcode, and address
%  \mixfour  for line number, location, opcode, and address
%  \mixfive  for line number, location, opcode, address, count
%  \mixsix  for line number, location, opcode, address, count, squeezed tight
% (all variations allow optional comments at end of the line)
% put \\ after \cr to indicate a logical page break
% and end the whole thing with \endmix

% Say \let\ninepoint=\flexninepoint to allow slight baselineskip variations

\def\mixtwo{\begingroup\let\ttt=\tt \ninepoint
  \def\\{\noalign{\penalty-200}}
  \halign\bgroup
          \ttt\hbox to 2.5em{##\hfil}& % op
          \ttt##\hfil\quad&            % address
          \rm##\hfil\cr}               % comment
\def\mixthree{\begingroup\let\ttt=\tt\ninepoint
  \def\\{\noalign{\penalty-200}}
  \halign\bgroup
          \ttt##\enspace\hfil&         % loc
          \ttt\hbox to 2.5em{##\hfil}& % op
          \ttt##\hfil\quad&            % address
          \rm##\hfil\cr}               % comment
\def\mixfour{\begingroup\let\ttt=\tt\ninepoint
  \def\\{\noalign{\penalty-200}}
  \halign\bgroup
          \hfil\it##\quad&             % line
          \ttt##\enspace\hfil&         % loc
          \ttt\hbox to 2.5em{##\hfil}& % op
          \ttt##\hfil\quad&            % address
          \rm##\hfil\cr}               % comment
\def\mixfive{\begingroup\let\ttt=\tt\ninepoint
  \def\\{\noalign{\penalty-200}}
  \halign\bgroup
          \hfil\it##\quad&             % line
          \ttt##\enspace\hfil&         % loc
          \ttt\hbox to 2.5em{##\hfil}& % op
          \ttt##\hfil\quad&            % address
          \hfil$ ##$\hfil\quad&        % frequency count
          \rm##\hfil\cr}               % comment
\newdimen\mixsqueeze % set this before each use of \mixsix
\def\mixsix{\begingroup\let\ttt=\tt\ninepoint %last field is flush right
  \def\\{\noalign{\penalty-200}}
  \halign to \hsize\bgroup
          \hfil\it##\quad&             % line
          \ttt##\enspace\hfil&         % loc
          \ttt\hbox to 2.5em{##\hfil}& % op
          \ttt##\hfil\quad&            % address
          \hskip-\mixsqueeze
          \hfil$ ##$\hfil\quad&        % frequency count
          \rm##\hidewidth\tabskip 0pt plus 1fil& % comment
          \medmuskip 1mu \relax \thickmuskip 3mu \relax
          \hfil##\tabskip0pt\cr}
\def\endmix{\egroup\endgroup}
% in answers, replace line numbers by 1\parindent of space
\def\ansmixtwo{\begingroup\let\ttt=\tt \ninepoint
  \def\\{\noalign{\penalty-200}}
  \halign\bgroup\hskip\parindent
          \ttt\hbox to 2.5em{##\hfil}& % op
          \ttt##\hfil\quad&            % address
          \rm##\hfil\cr}               % comment
\def\ansmixthree{\begingroup\let\ttt=\tt\ninepoint
  \def\\{\noalign{\penalty-200}}
  \halign\bgroup\hskip\parindent
          \ttt##\enspace\hfil&         % loc
          \ttt\hbox to 2.5em{##\hfil}& % op
          \ttt##\hfil\quad&            % address
          \rm##\hfil\cr}               % comment
% the ``primed'' commands expect frequency count but no location
\def\ansmixthreeprime{\begingroup\let\ttt=\tt\ninepoint
  \def\\{\noalign{\penalty-200}}
  \halign\bgroup\hskip\parindent
          \ttt\hbox to 2.5em{##\hfil}& % op
          \ttt##\hfil\quad&            % address
          \hfil$ ##$\hfil\quad&        % frequency count
          \rm##\hfil\cr}               % comment
\def\ansmixfour{\begingroup\let\ttt=\tt\ninepoint
  \def\\{\noalign{\penalty-200}}
  \halign\bgroup\hskip\parindent
          \hfil\it##\quad&             % line
          \ttt##\enspace\hfil&         % loc
          \ttt\hbox to 2.5em{##\hfil}& % op
          \ttt##\hfil\quad&            % address
          \rm##\hfil\cr}               % comment
\def\ansmixfourprime{\begingroup\let\ttt=\tt\ninepoint
  \def\\{\noalign{\penalty-200}}
  \halign\bgroup\hskip\parindent
          \ttt##\enspace\hfil&         % loc
          \ttt\hbox to 2.5em{##\hfil}& % op
          \ttt##\hfil\quad&            % address
          \hfil$ ##$\hfil\quad&        % frequency count
          \rm##\hfil\cr}               % comment
\def\ansmixfive{\begingroup\let\ttt=\tt\ninepoint
  \def\\{\noalign{\penalty-200}}
  \halign\bgroup\hskip\parindent
          \hfil\it##\quad&             % line
          \ttt##\enspace\hfil&         % loc
          \ttt\hbox to 2.5em{##\hfil}& % op
          \ttt##\hfil\quad&            % address
          \hfil$ ##$\hfil\quad&        % frequency count
          \rm##\hfil\cr}               % comment
% Use after \answer when answer starts with mix code
\def\mixans{\par\nobreak\vskip-\baselineskip}

\def\undertext{\bgroup\sl \let\\=\endundertext
  \catcode`g\active \catcode`j\active \catcode`p\active
  \catcode`q\active \catcode`y\active \catcode`,\active
  \catcode`Q\active
  \catcode`[\active \catcode`]\active
  \catcode`(\active \catcode`)\active
  \und@r}
\def\und@r{\setbox0=\hbox\bgroup}
\newdimen\underclearance \underclearance=.25pt
\def\endund@r{\egroup\dp0=\underclearance$\underline{\box0}$}
\def\endundertext{\endund@r\egroup\enspace\ignorespaces}
{\let\\=\gdef
  \catcode`g\active \\g{\endund@r\char`\g\kern-.1em\und@r\kern.1em\relax}}
{\catcode`j\active \gdef j{\endund@r\char`\j\und@r}}
{\catcode`p\active \gdef p{\kern-.05em\endund@r\kern.05em\char`\p\kern-.3em
                                  \und@r\kern.3em\relax}}
{\catcode`q\active \gdef q{\kern.25em\endund@r\kern-.25em\char`\q\und@r}}
{\catcode`y\active \gdef y{\kern.1em\endund@r\kern-.1em\char`\y\kern-.3em
                                  \und@r\kern.3em\relax}}
{\catcode`,\active \gdef ,{\kern.1em\endund@r\kern-.1em\char`\,\kern-.1em\und@r\kern.1em\relax}}
{\catcode`[\active \gdef [{\endund@r{\rm\char`\[}\und@r}}
{\catcode`]\active \gdef ]{\endund@r{\rm\char`\]}\und@r}}
{\catcode`(\active \gdef ({\endund@r{\rm\char`\(}\und@r}}
{\catcode`)\active \gdef ){\endund@r{\rm\char`\)}\und@r}}
{\catcode`Q\active \gdef Q{\kern.4em\endund@r\kern-.4em\char`\Q\und@r}}
\def\foolit#1{\setbox2=\hbox{$\smash{#1}$}} % math to be non-underlined
\def\subfoolit#1{\setbox2=\hbox{$\smash{_#1}$}}
\def\setfool{\endund@r\copy2 \kern-.2em\und@r\kern.2em\relax}
\def\setxfool{\kern-.1em\endund@r\kern.1em\copy2 \kern-.3em\und@r\kern.3em\relax}
\def\otherfoolit#1{\setbox4=\hbox{$\smash{#1}$}}
\def\othersubfoolit#1{\setbox4=\hbox{$\smash{_#1}$}}
\def\setotherfool{\kern.05em\endund@r\kern-.05em \copy4 \kern-.1em\und@r\kern.1em\relax}

\def\bracetext#1#2#3{\setbox0\vbox{\null\null}%
  \setbox1\vbox{\vskip#1\ht0\vskip#1\ht0\vskip-#2\ht0\vskip-\ht0}%{
  \setbox0\hbox{\raise.5\ht1\hbox{$\left.\vcenter{\vskip#2\ht0}\right\}$ #3}}%
  \vbox to 0pt{\vskip-\ht0\box0\vss}} % braces to group several lines of code
% \bracetext ab{text} is for b lines of text; we're currently on the a-th line

%%% Phyllis's macros for boxed bytes, vintage 1981

\def\Hedge#1{\vbox{\dimen0=#1 em \advance\dimen0 .4 pt \hrule width \dimen0}}
\def\Hed#1{\vbox{\dimen0=1.4em\relax \dimen0=#1\dimen0\relax
        \advance\dimen0 .4pt\relax \hrule width \dimen0}}

\def\hedgekk{\Hedge{1.2}}
\def\hedgeh{\Hedge{1.8}}
\def\hedgem{\Hedge{2.8}}
\def\hedgek{\Hedge{3.6}}
\def\hedgep{\Hedge{3.6}}
\def\hedgee{\Hedge{4.4}}
\def\hedgea{\Hedge{4.8}} \let\hedgej\hedgea
\def\hedged{\Hedge{5.0}}
\def\hedgeg{\Hedge{5.4}}
\def\hedgel{\Hedge{7.2}}
\def\hedgeb{\Hedge{7.6}}
\def\hedge{\Hedge{8.4}}
\def\hedgez{\Hedge{9.0}}
\def\hedgen{\Hedge{9.6}}
\def\hedgef{\Hedge{10.8}}
\def\hedgex{\Hedge{11.45}} %was 11.7
\def\hedgeyy{\Hedge{11.7}} %was 12.0
\def\hedgey{\Hedge{12.6}}
\def\hedgei{\Hedge{14.4}}
\def\hedgeo{\Hedge{15.0}}
\def\hedgeq{\Hedge{15.4}}
\def\hedgec{\Hedge{18.0}}
\def\hedger{\Hedge{31.5}}

\def\vedge{\vrule height 1.05em depth .55em} % 16pt
\def\vedgea{\vrule height .95em depth .45em} % 14pt
\def\vedgeb{\vrule height 1.75em depth 1.05em} % weird 28pt
\def\vedgec{\vrule height 1.15em depth .65em} % 18pt
\def\vedged{\vrule height .85em depth .35em} % 12pt
\def\vedgee{\vrule height 2.05em depth 1.35em} % weird 34pt
\def\vedgef{\vrule height 1.75em depth 1.45em} % weird 32pt
\def\tick{\vrule height 0.2em}
\def\untick{\vrule height .85em depth .35em} % 16pt byte
\def\unticka{\vrule height 1.55em depth .85em} % weird 28pt
\def\untickb{\vrule height .75em depth .25em} % 14pt
\def\untickc{\vrule height .95em depth .45em} % 18pt
\def\untickd{\vrule height .65em depth .15em} % 12pt
\def\unticke{\vrule height 1.85em depth 1.15em} % weird 34pt
\def\Byte#1#2{\hbox to #1em{\hfill\.{#2}\hfill\hskip.4 pt }\hskip-.4pt \vrule}
\def\bytem{\Byte{1.2}}
\def\byte{\Byte{1.4}} \let\byteb\byte \let\bytef\byte
\def\bytea{\Byte{1.5}} \let\byteo\bytea
\def\bytek{\Byte{1.8}}
\def\bytev{\Byte{1.6}} \let\bytew\bytev
\def\bytex{\Byte{1.7}}
\def\bytej{\Byte{1.8}} \let\bytejk\bytej \let\bytez\bytej
\def\bytey{\Byte{1.95}}  % was 2.0; fits two digits
\def\bytel{\Byte{2.4}} \let\byten\bytel \def\bytenn{\hskip2pt\bytel}
\def\bytes{\Byte{2.5}}
\def\bytennn{\hskip2pt\Byte{2.7}}
\def\byted{\Byte{2.8}} \let\byteq\byted
\def\bytec{\Byte{3.0}} \let\byteg\bytec \let\sbyteg\bytec \let\bytep\bytec
\def\byteh{\Byte{3.6}}  \let\bytei\byteh \let\bytet\byteh
\def\byteda{\Byte{4.2}}  \let\byter\byteda
\def\bytee{\Byte{4.8}}
\def\bytedb{\Byte{7.0}}
\def\bytedc{\Byte{8.4}}
\def\byteu{\Byte{9.6}}

\newcount\nbytes
\newdimen\byteswidth
\newdimen\clearance%(cellwidth-rulewidth-digitwidth)/2; set by \tenpoint
\def\cb{\hskip-\clearance plus 1 fill } %center bytes
% #1=number of bytes, #2=total width, #3=height to tick, #4=depth to tick,
% #5=contents
\def\multibytes#1#2#3#4#5{\nbytes=1 \byteswidth=#2em
  \hbox to \byteswidth{\hfill{\tt#5}\hskip\clearance \hskip.4pt}\hskip-\byteswidth
  \divide\byteswidth #1
  \loop\ifnum\nbytes<#1 \advance\nbytes by1
  \hskip\byteswidth
  \hskip-.4pt\vrule height -#4 em \hskip -.4pt \vrule depth -#3 em \repeat
  \hskip\byteswidth \hskip-.4pt \vrule}

\def\twobytesg{\multibytes2{2.4}{.65}{.15}}
%
\def\twobytes{\multibytes2{2.8}{.85}{.35}}
\def\twobytesa{\multibytes2{3.0}{.85}{.35}}
\def\twobytesj{\multibytes2{3.2}{.85}{.35}}
\def\twobytesb{\multibytes2{3.6}{1.55}{.85}}
\def\twobytesl{\multibytes2{3.9}{.85}{.35}} % was 4.0
\def\twobytese{\multibytes2{4.8}{.85}{.35}}
\def\twobytesc{\multibytes2{6.0}{.85}{.35}}
%
\def\twobytesf{\multibytes2{3.0}{.95}{.45}}
\def\twobytesk{\multibytes2{3.2}{.95}{.45}}
\def\twobytesd{\multibytes2{3.6}{.95}{.45}}
\def\twobytesi{\multibytes2{5.0}{.95}{.45}}
\def\twobytesh{\multibytes2{6.0}{.95}{.45}}
%

\def\threebytes{\multibytes3{4.2}{.85}{.35}}
\def\threebytesa{\multibytes3{4.5}{.85}{.35}}
\def\threebytesc{\multibytes3{4.8}{.85}{.35}}
%
\def\threebytesb{\multibytes3{7.5}{.95}{.45}}

\def\fourbytes{\multibytes4{5.6}{.85}{.35}}
\def\fourbytesb{\multibytes4{6.4}{.85}{.35}}
%
\def\fourbytesa{\multibytes4{7.2}{.95}{.45}}

\def\fivebytes{\multibytes5{7.0}{.85}{.35}}
\def\fivebytesa{\multibytes5{7.5}{.85}{.35}}
\def\fivebytesd{\multibytes5{8.0}{.85}{.35}}
\def\fivebytesx{\multibytes5{9.75}{.85}{.35}} % was 10.0
\def\fivebytesc{\multibytes5{15.0}{.85}{.35}}
%
\def\fivebytesb{\multibytes5{15.0}{.95}{.45}}

\def\sixbytesa{\multibytes6{7.2}{.65}{.15}}
%
\def\sixbytesd{\multibytes6{9.6}{.85}{.35}}
%
\def\sixbytes{\multibytes6{9.0}{.95}{.45}}
\def\sixbytese{\multibytes6{9.6}{.95}{.45}}
\def\sixbytesb{\multibytes6{10.8}{.95}{.45}}
\def\sixbytesc{\multibytes6{15.0}{.95}{.45}}

\def\opensign#1{\lower 5.5pt\vbox to 16pt{\hbox to 14pt{\hfil\tick}\vfill
\hbox to 14pt{\hfil\.{#1}\hfil}\vfill\hbox to 14pt{\hfil\tick}}}
\def\textindentindent#1{\noindent\hbox to 40pt{\hss#1\ }\!}

\def\punct#1{\ifinner \,#1 \else\rlap{\enspace#1}\fi} % punctuation after box

%%% Jeff Oldham's Illustration Macros

% Produce multiline centered text.
% input <- lines of text each ending with "\cr"
% output-> vertical box with each line centered and width of widest line
\def\jomac{\def\\{\noalign{\vskip-1pt}}}
\def\centeredBox#1{\vbox{\jomac\halign{\hfil\strut##\strut\hfil\cr#1}}}

% Produce multiline centered text.
% input <- lines of text each ending with "\cr"
% output-> vertical box with each line centered and width of widest line
\def\centeredBoxNoStrut#1{\vbox{\jomac\halign{\hfil##\hfil\cr#1}}}

% Produce multiline left-justified text.
% input <- lines of text each ending with "\cr"
% output-> vertical box with each line left-justified and width of widest line
\def\leftBox#1{\vbox{\jomac\halign{\strut##\strut\hfil\cr#1}}}

% Produce multiline left-justified text.
% input <- lines of text each ending with "\cr"
% output-> vertical box with each line left-justified and width of widest line
\def\leftBoxNoStrut#1{\vbox{\jomac\halign{##\hfil\cr#1}}}

% Produce multiline right-justified text.
% input <- lines of text each ending with "\cr"
% output-> vertical box with each line right-justified and width of widest line
\def\rightBox#1{\vbox{\jomac\halign{\strut\hfil##\strut\cr#1}}}

% Produce multiline right-justified text.
% input <- lines of text each ending with "\cr"
% output-> vertical box with each line right-justified and width of widest line
\def\rightBoxNoStrut#1{\vbox{\jomac\halign{\hfil##\cr#1}}}

% Indexing macros --- drastically simplified from manmac
%                     (but then complicated again, using unexpanded \write)

% ^{item} makes an index entry for the item and typesets the item as usual
% ^^{item} makes an index entry but doesn't typeset; it ignores space after

\newwrite\inx
\immediate\openout\inx=\jobname.inx % file for index reminders
\newif\ifsilent
\def\specialhat{\ifmmode\def\next{^}\else\let\next=\begininxref\fi\next}
\def\begininxref{\futurelet\next\begininxrefswitch}
\def\begininxrefswitch{\ifx\next\specialhat\let\next=\silentinxref
  \else\silentfalse\let\next=\inxref\fi \next}
\catcode`\^=\active \let ^=\specialhat
\def\silentinxref^{\silenttrue\inxref}

% \def\inxref{\futurelet\next\normalinxref}
% \def\normalinxref#1{\def\text{#1}\let\next=\text\makeinxref}
% \def\makeinxref{\ifproofmode\insert\margin{\hbox{\marginstyle\text}}%
%    \xdef\writeit{\write\inx{\text\space!%\inxreftype\space
%      \noexpand\number\pageno.}}\writeit
%    \else\ifhmode\kern\z@\fi\fi
%   \ifsilent\ignorespaces\else\next\fi}

\newtoks\inxtext
\def\inxref#1{\inxtext{#1}%
  \ifproofmode\insert\margin{\hbox{\marginstyle\the\inxtext}}%
   \expandafter\unxwrite\the\inxtext\endsanity
  \else\ifhmode\ifsilent\else\kern\z@\fi\fi\fi
  \ifsilent\ignorespaces\else\the\inxtext\fi}
\def\unxwrite#1\endsanity{{\aftergroup\finxwrite\aftergroup{%
  \sanitize#1\endsanity}}}
\def\\{\let\stoken= } \\ % now \stoken is a space token
\def\sanitize{\futurelet\next\sanswitch}
\def\sanswitch{\let\n@xt\endsanity \ifx\next\endsanity
  \else\ifcat\noexpand\next\stoken\aftergroup\space\let\n@xt=\eat
   \else\ifcat\noexpand\next\bgroup\aftergroup{\let\n@xt=\eat
    \else\ifcat\noexpand\next\egroup\aftergroup}\let\n@xt=\eat
     \else\let\n@xt=\copytok\fi\fi\fi\fi \n@xt}
\def\eat{\afterassignment\sanitize \let\next= }
\long\def\copytok#1{\ifcat\noexpand#1\relax\aftergroup\noexpand\fi
  \ifcat\noexpand#1\noexpand~\aftergroup\noexpand\fi
  \aftergroup#1\sanitize}
\def\endsanity\endsanity{\aftergroup\space\aftergroup!%
  \aftergroup\number\aftergroup\pageno}
\def\finxwrite{\write\inx}
% the \insert (which is done in proofmode only) suppresses hyphenation,
% so the \kern\z@ is put in to give the same effect in non-proofmode.
\def\marginstyle{\vrule height6pt depth2pt width\z@ \sevenrm}

\def\indexformat{
  \eightpoint \baselineskip=9pt
  \parskip=0pt plus .8pt
  \raggedright \tolerance=5000 \hbadness=5000 \parfillskip 0pt plus 3em
  \emergencystretch=20pt
  \hyphenpenalty=10000 \exhyphenpenalty=10000
  \def\sub{\penalty100 \vskip-\parskip \quad}
  \def\see{\kern.05em{\it see}\kern-.1em\ }
  \def\also{\kern.05em{\it see also}\ }
  \parindent=0pt
  \def\indexbreak{\hfil\break}
  \def\quoteshift{\kern-.3em} % for commas, periods, partway inside quotes
  \def\\{\kern-.05em}
  \def\period{.} \catcode`\.=\active \defineindexperiod
  \def\,{\ifmmode \mskip\thinmuskip \else \thinspace \fi}
  \hangindent 2em
}
\def\newletter{\vskip 0pt plus-1pt\penalty-50
\vskip 10pt plus 6pt minus 5pt
\hangindent 2em}

\newdimen\bitmapsize \bitmapsize=10pt
{\catcode`\.=\active
  \gdef\bitmap#1:#2:#3:#4:#5:#6<#7>% ems:cols:rows:-hoff:rows+voff<hexbitmap>
   {{\leavevmode \let.\period \hbox to#2\bitmapsize
      {\special{" 0 0 moveto currentpoint translate
                  \bitm@psize \bitm@psize scale #3 #4 true
                  [#1 0 0 -#1 #5 #6] {<#7>} imagemask}\hss}}}
  \gdef\defineindexperiod{\def.{\period\par\hangindent 2em }}}
\def\indexnoperiod{\par\hangindent 2em}
{\catcode`p=12\catcode`t=12\gdef\bm@ff#1pt{#1}}
\gdef\bitm@psize{\expandafter\bm@ff\the\bitmapsize\space}

% Cross references

% \ref value|name| gives value to |name|
% \eqref|name|(value) gives value to |name| and then does \eqno(value)
% \exref|name| value. gives value to |name| and then does \ex value.
% \EXref|name| value. gives value to |name| and then does \EX value.
% \refin foo inputs references from job foo (other than this job)
% \showmissestrue if you want to see missing references

\newif\ifshowmisses
\def\vertical{|}
\def\inref#1 #{\expandafter\def\csname\vertical#1\endcsname}

\catcode`\|=\active
\expandafter\def\expandafter\dospecials\expandafter{\dospecials\do\|}
\newcount\defcount      % number of old definitions not yet repeated
\newcount\changecount   % number of new definitions that are changed
\newcount\miscount      % number of unknown references

\newread\tempin
\def\dorefin#1#2 {\openin\tempin=../chap#1/#1#2.ref
 \ifeof\tempin\closein\tempin
 \else\closein\tempin \let|\inref \input../chap#1/#1#2.ref \let|\crossref \fi}
\def\refin#1#2 {\dorefin#1#2 \immediate\write\ansfile{\string\dorefin#1#2}}

\newwrite\refo
\immediate\openout\refo=\jobname.ref

\newtoks\mning % a new dirty trick for suppressing expansion in \write
\def\ref#1|#2|{\def\temp{#1}\expandafter\dordef\csname\vertical#2\endcsname}
\def\dordef#1{\ifx#1\temp \global\advance\defcount-1
 \else\global\advance\changecount1 \global\let#1\temp\fi
 {\expandafter\mning\expandafter{\meaning\temp}%
   \escapechar=-1\immediate\write\refo{\noexpand#1{\m@ning}}}}
\def\m@ning{\expandafter\m@@ning\the\mning}
\def\\{}\expandafter\def\expandafter\m@@ning\meaning\\{}
\def\eqref|#1|(#2){\ref#2|#1|\eqno(#2)}
\def\exref|#1|#2.{\ref#2|#1|\ex #2.}
\def\EXref|#1|#2.{\ref#2|#1|\EX #2.}
\def\crossref#1|{\expandafter\usedef\csname\vertical#1\endcsname}
\def\usedef#1{\ifx#1\relax
  \ifshowmisses\showmiss#1\fi\global\advance\miscount1 ??\else #1\fi}
\let|=\crossref
\def\showmiss#1{{\escapechar=-1%
 \message{***** WARNING: Undefined reference #1\string|! *****}}}
\showmissestrue
\def\pageref|#1|{\write\refo{\string|#1 {\number\pageno}}} % label for page no

% final considerations
\unitlength=1pt % default unit for picmac, should not be changed globally
\catcode`\@=12
\tenpoint

