\tracingpages=1 % TEMPORARY!
% Macros for `Concrete Mathematics'
\ifx\gkpmac\fmtversion\endinput\else\let\gkpmac=\fmtversion\fi

% Fonts for regular text

\font\textrm=ccr10		% roman
\font\textit=ccti10		% italic (emphasis)
\font\textsl=ccsl10		% slanted (titles)
\font\textbf=cmbx10			% bold
\font\textcsc=cccsc10		% caps and small caps
\font\oldsty=ccmi10		% equation numbers

% Fonts for regular math
% I'm setting \fontdimen2 to zero because AMS forgot to do it;
% they may have fixed the problem in the meantime, but no harm is done

\font\mathtext=ccr10
 \font\mathsubtext=ccr7
 \font\mathsubsubtext=ccr5
\font\mathlet=eurm10 \fontdimen2\mathlet=0pt
 \font\mathsublet=eurm7  \fontdimen2\mathsublet=0pt
 \font\mathsubsublet=eurm5 \fontdimen2\mathsubsublet=0pt
 \skewchar\mathlet='177 \skewchar\mathsublet='177 \skewchar\mathsubsublet='177
\font\mathsym=cmsy10
 \font\mathsubsym=cmsy7
 \font\mathsubsubsym=cmsy5
 \skewchar\mathsym='60 \skewchar\mathsubsym='60 \skewchar\mathsubsubsym='60
\font\mathext=cmex10
 \font\mathsubext=cmex10
 \font\mathsubsubext=cmex10
\font\mathscr=euxm10\fontdimen2\mathscr=0pt
 \font\mathsubscr=euxm7 \fontdimen2\mathsubscr=0pt
 \font\mathsubsubscr=euxm5 \fontdimen2\mathsubsubscr=0pt
 \skewchar\mathscr='60 \skewchar\mathsubscr='60 \skewchar\mathsubsubscr='60
\font\mathfr=eufm10\fontdimen2\mathfr=0pt
 \font\mathsubfr=eufm7 \fontdimen2\mathsubfr=0pt
 \font\mathsubsubfr=eufm5 \fontdimen2\mathsubsubfr=0pt
\font\matheuex=euex10\fontdimen2\matheuex=0pt

\font\eulerbf=eurb10 \fontdimen2\eulerbf=0pt % not hooked in to these macros

% Fonts for graffiti

\font\gtext=ccslc9
\font\goldstyle=ccmic9
 \fontdimen3\gtext=0pt \fontdimen4\gtext=0pt % no stretch or shrink
\font\gmathtext=ccr9
 \font\gmathsubtext=ccr6
 \font\gmathsubsubtext=ccr5
\font\gmathlet=eurm10 scaled 900 \fontdimen2\gmathlet=0pt
 \font\gmathsublet=eurm7 scaled 857 \fontdimen2\gmathsublet=0pt
 \font\gmathsubsublet=eurm5 \fontdimen2\gmathsubsublet=0pt
 \skewchar\gmathlet='177 \skewchar\gmathsublet='177
   \skewchar\gmathsubsublet='177
\font\gmathsym=cmsy9
 \font\gmathsubsym=cmsy6
 \font\gmathsubsubsym=cmsy5
 \skewchar\gmathsym='60 \skewchar\gmathsubsym='60 \skewchar\gmathsubsubsym='60
\font\gmathext=cmex9
 \font\gmathsubext=cmex9
 \font\gmathsubsubext=cmex9
\font\gmathscr=euxm10 scaled 900 \fontdimen2\gmathscr=0pt
 \font\gmathsubscr=euxm7 scaled 857 \fontdimen2\gmathsubscr=0pt
 \font\gmathsubsubscr=euxm5 \fontdimen2\gmathsubsubscr=0pt
 \skewchar\gmathscr='60 \skewchar\gmathsubscr='60 \skewchar\gmathsubsubscr='60
\font\gmathfr=eufm10 scaled 900 \fontdimen2\gmathfr=0pt
 \font\gmathsubfr=eufm7 scaled 857 \fontdimen2\gmathsubfr=0pt
 \font\gmathsubsubfr=eufm5 \fontdimen2\gmathsubsubfr=0pt
\font\gmatheuex=euex9 \fontdimen2\gmatheuex=0pt

% Fonts for headings, etc.

\font\chapfont=cmbxcd10 scaled 8000
\font\title=cmbx10 scaled \magstep5
\font\subtitle=cmbx10 scaled 1315 % that's magstep 1.5
\font\subsubtitle=cmbxsl10
\font\runhead=cmbx9
\font\foliofont=cmr9
\font\gtfont=cmmi9 % for the \t accent
\font\ninesl=ccsl9 % used in the index only

% Normal text conventions

\catcode`@=11 % borrow the private macros of PLAIN (with care)
\def\wlog#1{} % don't put allocation info into the log

\hsize=28pc
\vsize=45.25pc
\parindent=20pt
\baselineskip=13pt

\let\sc=\textcsc
\let\bf=\textbf
\def\textindent#1{\noindent\hbox to\parindent{\bf#1\hfil}\ignorespaces}
\def\exitem{\hangindent2\parindent \textindent}

\textfont0=\mathtext
 \scriptfont0=\mathsubtext
 \scriptscriptfont0=\mathsubsubtext
\textfont1=\mathlet \let\tfont=\teni
 \scriptfont1=\mathsublet
 \scriptscriptfont1=\mathsubsublet
\textfont2=\mathsym
 \scriptfont2=\mathsubsym
 \scriptscriptfont2=\mathsubsubsym
\textfont3=\mathext
 \scriptfont3=\mathsubext
 \scriptscriptfont3=\mathsubsubext
\def\rm{\fam\z@\textrm}
\def\it{\fam\itfam\textit} % \it is family 4, defined in PLAIN
\def\sl{\textsl}
\textfont\itfam=\textit
\newfam\scrfam \ifnum\scrfam=8\relax\else\error\fi % family 8, script
\textfont\scrfam=\mathscr
 \scriptfont\scrfam=\mathsubscr
 \scriptscriptfont\scrfam=\mathsubsubscr
\def\scr{\fam8 }
\mathcode`0="7130
\mathcode`1="7131
\mathcode`2="7132
\mathcode`3="7133
\mathcode`4="7134
\mathcode`5="7135
\mathcode`6="7136
\mathcode`7="7137
\mathcode`8="7138
\mathcode`9="7139
\newfam\frfam % family 9, fraktur
\textfont\frfam=\mathfr
 \scriptfont\frfam=\mathsubfr
 \scriptscriptfont\frfam=\mathsubsubfr
\def\frak{\fam9 }
\newfam\euexfam % family 10, substitions for euler symbols
\newfam\eqfam % family 11, cmr equal signs for Relbar (!)
\font\teneq=cmr10 \textfont\eqfam=\teneq 
\font\nineeq=cmr9
% I'm not using Relbar except in 9&10pt, so this family is very incomplete...

\mathchardef\intop="1A52
\mathchardef\ointop="1A48
\mathchardef\coprod="1A60
\mathchardef\prod="1A51
\mathchardef\sum="1A50
\mathchardef\braceld="A7A \mathchardef\bracerd="A7B
\mathchardef\bracelu="A7C \mathchardef\braceru="A7D
\mathchardef\infty="0A31

\mathchardef\nearrow="3A25
\mathchardef\searrow="3A26
\mathchardef\nwarrow="3A2D
\mathchardef\swarrow="3A2E
\mathchardef\Leftrightarrow="3A2C
\mathchardef\Leftarrow="3A28
\mathchardef\Rightarrow="3A29
\mathchardef\leftrightarrow="3A24 \mathcode`\^^W="3A24
\mathchardef\leftarrow="3A20 \let\gets=\leftarrow \mathcode`\^^X="3A20
\mathchardef\rightarrow="3A21 \let\to=\rightarrow \mathcode`\^^Y="3A21
\def\uparrow{\delimiter"3A22378 } \mathcode`\^^K="3A22
\def\downarrow{\delimiter"3A23379 } \mathcode`\^^A="3A23
\def\updownarrow{\delimiter"3A6C33F }
\def\Uparrow{\delimiter"3A2A37E }
\def\Downarrow{\delimiter"3A2B37F }
\def\Updownarrow{\delimiter"3A6D377 }
\mathchardef\leftharpoonup="3A18
\mathchardef\leftharpoondown="3A19
\mathchardef\rightharpoonup="3A1A
\mathchardef\rightharpoondown="3A1B

\textfont\euexfam=\matheuex
\scriptfont\euexfam=\mathsubsym % this is OK since I don't use all characters
% of euex in subscripts/superscripts; otherwise I'd have to make euex7 and euex6
\scriptscriptfont\euexfam=\mathsubsym % only for \mathchoice, not really chosen
\mathcode`+="292B
\mathcode`-="292D
\mathcode`!="0921
\mathcode`(="4928 \delcode`(="928300
\mathcode`)="5929 \delcode`)="929301
\mathcode`[="495B \delcode`[="95B302
\mathcode`]="595D \delcode`]="95D303
\mathcode`=="393D
\mathchardef\Relbar="3B3D % we need the old = to match \Arrows
\mathchardef\Gamma="7100
\mathchardef\Delta="7101
\mathchardef\Theta="7102
\mathchardef\Lambda="7103
\mathchardef\Xi="7104
\mathchardef\Pi="7105
\mathchardef\Sigma="7106
\mathchardef\Upsilon="7107
\mathchardef\Phi="7108
\mathchardef\Psi="7109
\mathchardef\Omega="710A
\let\varsigma=\sigma \let\varrho=\rho % Euler doesn't have these
\mathchardef\aleph="0840
\def\rbrace{\delimiter"5867A09 } \let\}=\rbrace
\def\lbrace{\delimiter"4866A08 } \let\{=\lbrace
%\mathchardef\equiv="3811 \let\cong=\equiv % lowres bars weren't spaced right
\mathchardef\leq="3814 \let\le=\leq
\mathchardef\geq="3815 \let\ge=\geq
\mathchardef\Re="083C
\mathchardef\Im="083D
\def\vert{\delimiter"86A30C }
\def\backslash{\delimiter"86E30F }

\setbox\strutbox=\hbox{\vrule height9pt depth4pt width\z@}%
\newbox\bigstrutbox \newbox\biggstrutbox
\setbox\bigstrutbox=\hbox{\vrule height11pt depth4pt width\z@}%
\def\bigstrut{\relax\ifmmode\copy\bigstrutbox\else\unhcopy\bigstrutbox\fi}
\setbox\biggstrutbox=\hbox{\vrule height17pt depth10pt width\z@}%
\def\biggstrut{\relax\ifmmode\copy\biggstrutbox\else\unhcopy\biggstrutbox\fi}
\rm

\newmuskip\normalthick \normalthick=5mu plus 5mu
\newmuskip\normalmedmu \normalmedmu=\medmuskip
\newmuskip\displaythick \displaythick=10mu minus 3mu
\everymath{\thickmuskip=\normalthick}

\abovedisplayskip=8pt plus 3pt minus 2pt % there's 2pt more (opened up)
\belowdisplayskip=10pt plus 3pt minus 2pt

% displays not centered; all have capability of \eqalign
\outer\def\begindisplay{\obeylines\startdisplay}
{\obeylines\gdef\startdisplay#1
  {\catcode`\^^M=5$$%
   \advance\displayindent\parindent\advance\displaywidth-\parindent%
   \openup2pt #1\halign\bgroup\span\preamble\cr}}
\outer\def\enddisplay{\crcr\egroup$$}
\jot=\z@  % we do our own opening up

\def\displaymath{$\thickmuskip=\displaythick\displaystyle}
\def\preamble{\hfil\displaymath{##}$&&\displaymath{{}##}$\hfil}
\def\tablepreamble{\bigstrut\hfil$##$\hfil\ &\vrule##&&\quad\hfil$##$\hfil}
\def\xbox{\qquad\hbox} % for third column of explanation

\newcount\eqcount
\def\equ(#1.#2){{\rm({\oldsty#1}.{\oldsty#2})}}
\def\eq(#1){\equ(\chapno.#1)}
\def\thiseq{\xdef\next{(\chapno.\number\eqcount)}\expandafter\equ\next}
\def\eqno{\global\advance\eqcount 1 \global\everycr{\makeeqno\thiseq}}
\newdimen\backup
\def\makeeqno#1{\noalign{\global\everycr{}%
  \advance\displaywidth\displayindent
  \setbox0=\hbox to\displaywidth{\hfil#1}%
  \backup=\prevdepth \advance\backup\ht0
  \setbox0=\vbox{\kern-\backup\box0}\ht0=\z@ \dp0=\z@
  \setbox0=\vbox{\box0}\unvbox0}} % that puts equation number on prev line!

\newif\iftitle
\def\beginchapter#1 #2 \par{ % we should be at top of a page
  \titletrue \eqcount=0
  \ifodd\pageno
   \rightline{\chapfont#1\kern-.05em}
   \vskip 1in minus 5pt
   \rightline{\title#2}
   \moveleft7pc % this applies to the \vbox after the \fi
  \else % left-hand page
   \leftline{\kern-.05em\chapfont#1}
   \vskip 1in minus 5pt
   \leftline{\title#2} \fi
  \vbox{\hrule width 35pc}
  \def\chapno{#1} \edef\chaptitle{#2}
  \mark{#1\enspace #2}
  \smallskip\noindent}

\def\beginsection#1 #2 \par{ % should not be first in the chapter
  \backup=\lastskip	% but should come on first or second page of chapter
  \mark{#1\enspace #2}	% because the mark gives running head on right page
  \nobreak\vskip-\backup\penalty-200
  {\subtitle\baselineskip=34pt
    \noindent\hbox to2\parindent{#1\hfil}\uppercase{\kern-.05em#2}\par}
  \nobreak\vskip5pt\noindent\hbox to2\parindent{}}

\newcount\excount
\def\beginexercises{\backup=\lastskip \excount=0
  \mark{\chapno\enspace Exercises}
  \nobreak\vskip-\backup\penalty-200
  {\subtitle\baselineskip=34pt\noindent Exercises\par}\nobreak}

{\catcode`\|=\active
\gdef\table#1\tabref|#2|{\hrule height1pt width\hsize \kern2pt
 \noindent\strut{\bf Table |#2|\enspace}#1\par
 \hrule height.5pt width\hsize\tabref|#2|}}

\def\medbr{\ifnum\lastpenalty>9999 \medskip \else\medbreak\fi}
\def\subhead#1\par{\medbr
  {\subsubtitle\noindent#1\par}\nobreak}
\def\ex:{\par{\advance\medskipamount-1pt\medbr}%
  \advance\excount 1 \item{\number\excount}}

\def\dash---{\thinspace---\hskip.16667em\relax}
\def\qback{\kern-.15em} % between , or . and ''
\def\undertext#1{$\underline{\smash{\hbox{#1}}}$}
\def\newline{\hfil\break}
\def\Hint:{{\it Hint:\/}}
\let\macron=\= % we will use \= for congruence relation
\def\t#1{{\edef\next{\the\font}\tfont\accent"7F\next#1}}

% Here's a definition that was corrected in plain.tex version 3.14159;
% I'm keeping the old version here, because I had already been compensating
% for its deficiencies in script and scriptscript styles; without this
% buggy version, it would be hard for me to match the old pages precisely
\def\bmod{\mskip-\medmuskip\mkern5mu
  \mathbin{\rm mod}\penalty900\mkern5mu\mskip-\medmuskip}

% Graffiti macros
\chardef\other=12
\newread\grfi \openin\grfi=\jobname.grf
%\newwrite\grfo \immediate\openout\grfo=\jobname.grf % let's hope no conflict
%% Hmmm...; that doesn't work on Unix.
%% Here's my first solution, a kludge where I alternated between .grf and .gr
%\newif\ifgrf  \newwrite\grfo \newwrite\grfempty
%\ifeof\grfi \grffalse
%\else\read\grfi to\grfitest \ifeof\grfi \grffalse \else \grftrue \fi\fi
%\ifgrf\else \openin\grfi=\jobname.gr
%  \ifeof\grfi\else\read\grfi to\grfitest \fi\fi
%\immediate\openout\grfo=\jobname.gr\ifgrf\else f\fi
%\immediate\write\grfo{} % an empty line will start a nonempty file (Unix only)
%% and then at the end I said
% \immediate\openout\grfempty=\jobname.gr\ifgrf f\fi % clear the input file
%% That solution worked with the following original macros
%\def\testnextgrf{{\def\do##1{\catcode`##1=\other}\dospecials
%  \global\read\grfi to\next}\expandafter\testgrf\meaning\next\testgrf}
%\expandafter\def\expandafter\testgrf\meaning\empty#1 #2\testgrf{%
%  \setup#2!!!!!$\ifx\thisone\thatone\if#1R\Rtrue\else\Rfalse\fi\else\Rguess\fi}
%% Anyway, here's my second approach to Unix: (order n^2 algorithm)
\def\\{{\def\do##1{\catcode`##1=\other}\dospecials \endlinechar=-1 \let\eol=0
  \gdef\grfmem{}
  \expandafter\def\expandafter\gbbl\meaning\empty{}
  \def\appgrf{\read\grfi to\g
    \ifx\g\empty\else\xdef\grfmem{\grfmem\expandafter\gbbl\meaning\g\eol}\fi}
  \def\next{\ifeof\grfi\let\next\relax\else\appgrf\fi\next}\next}}
\\ % now \grfmem is "L aaaaa\eol R bbbbb\eol ... R zzzzz\eol".
\def\testnextgrf#1 #2\eol#3\\{\gdef\grfmem{#3}\setup#2!!!!!$%
  \ifx\thisone\thatone\if#1R\Rtrue\else\Rfalse\fi\else\Rguess\fi}
\newwrite\grfo \immediate\openout\grfo=\jobname.grf % no conflict now

\def\graffiti{% set up graffiti style
 \hsize=6pc
 \baselineskip=10pt \lineskip=0pt \lineskiplimit=0pt
 \parindent=0pt
 \mathsurround=1pt
 \textfont0=\gmathtext
  \scriptfont0=\gmathsubtext
  \scriptscriptfont0=\gmathsubsubtext
 \textfont1=\gmathlet \let\tfont=\gtfont
  \scriptfont1=\gmathsublet
  \scriptscriptfont1=\gmathsubsublet
 \textfont2=\gmathsym
  \scriptfont2=\gmathsubsym
  \scriptscriptfont2=\gmathsubsubsym
 \textfont3=\gmathext
  \scriptfont3=\gmathsubext
  \scriptscriptfont3=\gmathsubsubext
\textfont\scrfam=\gmathscr
 \scriptfont\scrfam=\gmathsubscr
 \scriptscriptfont\scrfam=\gmathsubsubscr
\textfont\frfam=\gmathfr
 \scriptfont\frfam=\gmathsubfr
 \scriptscriptfont\frfam=\gmathsubsubfr
\textfont\euexfam=\gmatheuex
\scriptfont\euexfam=\gmathsubsym % OK since I don't use all chars in this size
\textfont\eqfam=\nineeq
 \def\rm{\fam\z@\gtext}%
 \let\oldsty=\goldstyle
 \let\big=\ninebig
 \setbox\strutbox=\hbox{\vrule height7.25pt depth2.75pt width\z@}%
 \gtext
 \rightskip=\z@ plus2em % ragged right
 \tolerance=2000
 \hyphenpenalty=300
 \exhyphenpenalty=300
 \doublehyphendemerits=100000
 \finalhyphendemerits=\doublehyphendemerits
 }
\def\ninebig#1{{\hbox{$\textfont0=\tenrm\textfont2=\tensy
  \left#1\vbox to7.25pt{}\right.\n@space$}}}
\def\grafctr{\hbox to4.5pc{\hfil##\hfil}}

\newif\ifR % does this entry go on a right-hand page?
\def\Rguess{\def\ifR{\ifodd\pageno}}
\long\def\g#1\g{\def\next{#1!!!!!}\expandafter\writegrf\meaning\next$%
  \ifx\grfmem\empty\Rguess\else\expandafter\testnextgrf\grfmem\\\fi
% pre-Unix, that line was  \ifeof\grfi\Rguess\else\testnextgrf\fi
  \setbox0=\vtop{\graffiti#1%
  \write\m@ne\ifR{\Rcheck}\else{\Lcheck}\fi}% log file records successes
  \ifvmode\kern-\prevdepth\kern-\ht0\dp0=\z@\nointerlineskip\bgroup
  \else\dp0=\dp\strutbox\strut\vadjust{\kern-\dp\strutbox\kern-\ht0\fi
   \ifR\moveleft7\else\moveright29\fi pc\box0}}
\expandafter\def\expandafter\writegrf\meaning\empty#1#2#3#4#5#6${%
  \write\grfo{\LorR #1#2#3#4#5}\def\thisone{#1#2#3#4#5}}
\def\setup#1#2#3#4#5#6${\def\thatone{#1#2#3#4#5}}
\def\LorR{\ifodd\pageno R \else L \fi}
\def\Lcheck{\ifodd\pageno Bad guess!\fi}
\def\Rcheck{\ifodd\pageno\else Bad guess!\fi}

% Page layout
\newif\ifpreprint \preprinttrue % should be false when making the final copy
\newdimen\pageheight \pageheight=\vsize
\newdimen\totheight \totheight=49.5pc
\newdimen\folioht \setbox0=\hbox{\foliofont0} \folioht=\ht0
\def\leftheadline{\hbox to35pc{\vbox to 10pt{}% strut to position the baseline
    \llap{\kern-2pc\iftitle\leftcorner\else\foliofont\folio\fi\hfil}%
    \iftitle\hfil\copyrite\else\runhead\uppercase\expandafter{\chaptitle}\hfil\fi}}
\def\rightheadline{\hbox to35pc{\iftitle\copyrite\fi\hfil
    \vbox to 10pt{}% strut to position the baseline
    \runhead\uppercase\expandafter{\topmark}%
    \rlap{\hfil\iftitle\rightcorner\else\foliofont\folio\fi\kern-2pc}}}
\def\leftcorner{\vrule\vbox to\folioht{\hrule width9pt\vfil}}
\def\rightcorner{\vbox to\folioht{\hrule width9pt\vfil}\vrule}
\def\copyrite{\ifpreprint{\textfont2=\sevensy\sevenrm\copyright\ 1988
   Addison-Wesley Publishing Company; all rights reserved}\fi}

\def\onepageout#1{\escapechar=-1 % for writing \tabrefs
    \shipout\vbox to\totheight{ % here we define one page of output
    \offinterlineskip % butt the boxes together
    \vbox to 2pc{ % this part goes on top of the regular pages
      \ifodd\pageno \rightheadline\else\leftheadline\fi
      \vfill} % this completes the \vbox to 2pc
    \ifodd\pageno\moveright7pc\fi #1
    \vfill
    \iftitle \global\titlefalse % reset the titlepage switch
	\ifodd\pageno \hbox to35pc{\hfil\foliofont\folio}
	\else\hbox{\foliofont\folio}\fi\fi
    \ifpreprint\ifinxmode\makeinxfooter\fi\fi
    }
  \advancepageno}

\output{\onepageout{\pagebody}}

\newbox\inxfootbanner
\def\hours{\count0=\time \divide\count0 by60 % find the o'clock
  \multiply\count0 by40 \advance\count0\time % convert to hhmm
  \advance\count0 10000 \expandafter\gobbleone\number\count0\relax}
\def\gobbleone1{}
\setbox\inxfootbanner=\rlap{\hbox to 6.5in{\hrulefill\sevenrm\quad
 Author's page proof produced by \TeX\ at
 \hours\space on \ifcase\month\or
   January\or February\or March\or April\or May\or June\or
   July\or August\or September\or October\or November\or December\fi
  \space\number\day}}
\def\makeinxfooter{\vbox to0pt{\kern10pt\copy\inxfootbanner\kern4pt
  \rlap{\vbadness=\maxdimen \inxcolumns}\vss}}
\def\inxcolumns{\ifvoid\inxbox\let\next\relax\else\let\next\contribcol\fi\next}
\def\contribcol{\setbox0=\vsplit\inxbox to54pt
  \vtop{\unvbox0}\kern20pt \inxcolumns}
\def\inxstyle{\vrule height6pt depth2pt width\z@ \sevenrm}
\splittopskip=6pt

% Cross references

% \ref{value}|name| gives value to |name|
% \eqref|name| gives \eqcount to |name|
% \exref|name| gives \excount to |name|
% \tabref|name| gives appropriate page number to |name|
% \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\refin#1 {\openin\tempin=#1.ref
 \ifeof\tempin\closein\tempin
 \else\closein\tempin \let|\inref \input#1.ref \let|\crossref \fi}

{\let\|=\jobname
 \def\def{\global\advance\defcount1 \gdef}\expandafter\refin\| }
\newwrite\refo \immediate\openout\refo=\jobname.ref

\def\ref#1|#2|{\xdef\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
 {\escapechar=-1\immediate\write\refo{\noexpand#1{\temp}}}}
\def\eqref{\ref{\number\eqcount}}
\def\exref{\ref{\number\excount}}
\def\tabref|#1|{\expandafter\pageref\csname\vertical#1\endcsname}
\def\pageref#1{\ifx#1\relax\else\global\advance\defcount-1 \fi
 \write\refo{\noexpand#1{\number\pageno}}%
 \write\m@ne{\ifx#1\relax New Pageref!\else
  \ifnum#1=\pageno\else Changed Pageref!\fi\fi}}
\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|! *****}}}

\def\cite#1.{\ifinxmode\write\bnx{[#1] \number\pageno.}\fi#1}
{\catcode`\@=\active
\gdef\newcite#1.{\ifinxmode\write\bnx{[#1'] \number\pageno.}\fi#1$'@$}}

\outer\def\bye{
 \ifnum\miscount>0
  \message{(\the\miscount\space undefined references were present)}\fi
 \ifnum\changecount>0
  \message{(\the\changecount\space new references written on \jobname.ref)}\fi
 \ifnum\defcount>0
  \message{(\the\defcount\space old references dropped from \jobname.ref)}\fi
 \par\vfill\supereject
 \end}

% Exercises

\newwrite\ans
\immediate\openout\ans=\jobname.ans

\outer\def\answer{\par
  \immediate\write\ans{}
  \immediate\write\ans{\string\ansno\chapno.\the\excount:}
  \copytoblankline}
\def\copytoblankline{\begingroup\setupcopy\copyans}
\def\setupcopy{\def\do##1{\catcode`##1=\other}\dospecials \obeylines}
{\obeylines \gdef\copyans#1
  {\def\next{#1}%
  \ifx\next\empty\let\next=\endgroup %
  \else\immediate\write\ans{\next} \let\next=\copyans\fi\next}}

\def\ansno#1:{\par\medbreak\def\thisansno{\source#1}%
 \noindent\hbox to\parindent{\bf #1\hfil}\ignorespaces}

% Pictures (a subset of \LaTeX's conventions)
\newskip\hsssglue \hsssglue=0pt plus 1fill minus 1fill \def\hsss{\hskip\hsssglue}

\newdimen\unitlength \newdimen\linethickness
\newdimen\@picheight \newdimen\@xdim \newdimen\@ydim \newdimen\@len \newdimen\@save
\newcount\@multicount \newcount\@xarg \newcount\@yarg
\newbox\@picbox \newbox\@mpbox

\font\tenln=line10     \font\tenlnw=linew10
\font\tencirc=lcircle10 \font\tencircw=lcirclew10
\font\smallln=linew10 scaled 483 % that's magstep-4

\def\thinlines{\let\linefont=\tenln \let\circlefont=\tencirc
  \linethickness=\fontdimen8\linefont}
\def\thicklines{\let\linefont=\tenlnw \let\circlefont=\tencircw
  \linethickness=\fontdimen8\linefont}
\thinlines

\def\beginpicture(#1,#2)(#3,#4){\@picheight=#2\unitlength \let\line=\@line
  \setbox\@picbox=\hbox to#1\unitlength\bgroup
    \kern-#3\unitlength \lower#4\unitlength\hbox\bgroup\ignorespaces}
\def\endpicture{\egroup\hss\egroup
  \ht\@picbox=\@picheight \dp\@picbox=\z@
  \leavevmode\box\@picbox}

\def\put(#1,#2)#3{\raise#2\unitlength\rlap{\kern#1\unitlength #3}\ignorespaces}

\def\multiput(#1,#2)(#3,#4)#5#6{\@multicount=#5
 \@xdim=#1\unitlength \@ydim=#2\unitlength \setbox\@mpbox=\hbox{#6}%
 \loop\ifnum\@multicount>0
   \raise\@ydim\rlap{\kern\@xdim \unhcopy\@mpbox}%
   \advance\@xdim#3\unitlength \advance\@ydim#4\unitlength
   \advance\@multicount\m@ne \repeat\ignorespaces}

\def\makebox(#1,#2)#3{\setbox\@picbox=\hbox to#1\unitlength{\hss#3\hss}%
  \@ydim=\ht\@picbox \advance\@ydim-\dp\@picbox
  \ht\@picbox=#2\unitlength \dp\@picbox=\z@
  \leavevmode\lower.5\@ydim\box\@picbox}

\newif\ifneg
\def\@line(#1,#2)#3{\@xarg=#1 \@yarg=#2 \@len=#3\unitlength \leavevmode
 \ifnum\@xarg<0 \reverseline \else \negfalse \@ydim=\z@\fi
 \ifnum\@xarg=0 \@vline
 \else\ifnum\@yarg=0 \@hline \else\@sline\fi\fi
 \ifneg\kern-\@len\else\@save=\@ydim\fi}
\def\reverseline{\negtrue \kern-\@len \@xarg=-\@xarg
 \@ydim=\@len \multiply\@ydim\@yarg \divide\@ydim\@xarg \@yarg=-\@yarg}

\def\@hline{\vrule height.5\linethickness depth.5\linethickness width\@len}
\def\@vline{\kern-.5\linethickness\vrule width\linethickness
  \ifnum\@yarg<0 height\z@ depth\else depth\z@ height\fi\@len
  \kern-.5\linethickness}

\def\@sline{\setbox\@picbox=\hbox{\linefont \count@=\@xarg \multiply\count@ 8
 \ifnum\@yarg>0 \advance\count@\@yarg \advance\count@-9
 \else \advance\count@-\@yarg \advance\count@ 55 \fi \char\count@}%
 \ifnum\@yarg<0 \@picheight=-\ht\@picbox \advance\@ydim\@picheight
 \else \@picheight=\ht\@picbox \fi
 \@xdim=\wd\@picbox \@save=\@ydim
 \loop\ifdim\@xdim<\@len \raise\@ydim\copy\@picbox
  \advance\@xdim\wd\@picbox \advance\@ydim\@picheight \repeat
 \advance\@xdim-\@len \kern-\@xdim
 \multiply\@xdim\@yarg \divide\@xdim\@xarg \advance\@ydim-\@xdim
 \raise\@ydim\box\@picbox}

\def\vector(#1,#2)#3{\@line(#1,#2){#3}%
 \ifnum\@xarg=0 \@vvector \else\ifnum\@yarg=0 \@hvector \else\@svector\fi\fi}
\def\@hvector{\ifneg\rlap{\linefont\char27}\else
 \smash{\llap{\linefont\char45}}\fi} % we have to smash because of font bug
\def\@vvector{\ifnum\@yarg<0 \raise-\@len\rlap{\linefont\char63}%
 \else\setbox\@picbox=\rlap{\linefont\char54}\advance\@len-\ht\@picbox
 \raise\@len\box\@picbox\fi}

\def\@svector{\setbox\@picbox=\hbox to\z@{\linefont
 \ifnum\@yarg<0 \count@=55 \@yarg=-\@yarg \else\count@=-9 \fi
 \ifneg\multiply\@xarg16 \multiply\@yarg2
 \else\hss % \llap
  \ifnum\@xarg>2 \multiply\@xarg9 \multiply\@yarg2 \advance\count@29
  \else\ifnum\@yarg>2 \multiply\@xarg16 \multiply\@yarg9 \advance\count@-20
   \else\multiply\@xarg24 \multiply\@yarg3 \fi\fi\fi
  \advance\count@\@xarg \advance\count@\@yarg \char\count@
  \ifneg\hss\fi}% \rlap
 \raise\@save\box\@picbox}

\def\disk#1{\@len=#1\unitlength \count@='160 \@diskcirc}
\def\circle#1{\@len=#1\unitlength \count@='140 \@diskcirc}
\def\@diskcirc{\setbox\@picbox=\hbox{\circlefont\char\count@}\@xdim=\wd\@picbox
 \leavevmode \ifdim\@len>15.499\@xdim \@bigdc \else \@smalldc\fi}
\def\@bigdc{\ifnum\count@<'160 \@bigcirc
 \else \@len=15\@xdim \@diskcirc\fi}
\def\@smalldc{{\advance\@len-.5\@xdim
 \loop\ifdim\@xdim<\@len \advance\count@\@ne \advance\@xdim\wd\@picbox\repeat
 \hbox{\circlefont\char\count@}}}
\def\@bigcirc{{\circlefont\count@=15
 \setbox\@picbox=\hbox{\char\count@}\@xdim=\wd\@picbox
 \ifdim\@len>2.5\@xdim \@len=2.5\@xdim\fi
 \advance\@len-.125\wd\@picbox
 \loop\ifdim\@xdim<\@len \advance\count@ 4 \advance\@xdim.25\wd\@picbox\repeat
 \@ydim=.5\@xdim \advance\@ydim.5\linethickness
 \setbox\@picbox=\vbox{\hbox{\char\count@\advance\count@-3\char\count@}%
  \nointerlineskip
  \hbox{\advance\count@\m@ne\char\count@\advance\count@\m@ne\char\count@}}%
 \kern-\@ydim\lower\@ydim\box\@picbox}}

\newif\ifovaltl \newif\ifovaltr \newif\ifovalbl \newif\ifovalbr
\ovaltltrue \ovaltrtrue \ovalbltrue \ovalbrtrue
\def\oval(#1,#2){\@xdim=#1\unitlength \@ydim=#2\unitlength
 {\circlefont \setbox\@picbox=\hbox{\char0}
 \ifdim\@xdim<\wd\@picbox \@xdim=\wd\@picbox\fi
 \ifdim\@ydim<\wd\@picbox \@ydim=\wd\@picbox\fi
 \@save=\@xdim \ifdim\@ydim<\@save \@save=\@ydim \fi
 \count@=39
 \loop \setbox\@picbox=\hbox{\char\count@}\ifdim\@save<\wd\@picbox
  \advance\count@-4 \repeat
 \setbox\strutbox=\hbox{\vrule height\ht\@picbox depth\dp\@picbox width\z@
   \kern\wd\@picbox}%
 \@save=.5\wd\@picbox \advance\@save-.5\linethickness
 \setbox0=\hbox to\@xdim{\ifovaltl\char\count@\else\strut\fi
  \kern-\@save\leaders\hrule height\ifovaltl\linethickness\else\z@\fi\hfil
  \leaders\hrule height\ifovaltr\linethickness\else\z@\fi\hfil\kern\@save
  \ifovaltr\advance\count@-3\char\count@\else\strut\fi\kern-\wd\@picbox}%
  \advance\count@\m@ne
 \setbox2=\hbox to\@xdim{\ifovalbl\char\count@\else\strut\fi
  \kern-\@save\leaders\hrule height\ifovalbl\linethickness\else\z@\fi\hfil
  \leaders\hrule height\ifovalbr\linethickness\else\z@\fi\hfil\kern\@save
  \ifovalbr\advance\count@\m@ne\char\count@\else\strut\fi\kern-\wd\@picbox}%
 \@save=\@ydim \advance\@save-\wd\@picbox \divide\@save 2
 \setbox\@picbox=\vbox{\box0\nointerlineskip
  \hbox to\@xdim{\vrule height\@save width\ifovaltl\linethickness\else\z@\fi
    \hfil\ifovaltr\vrule width\linethickness\kern-\linethickness\fi}%
  \nointerlineskip
  \hbox to\@xdim{\vrule height\@save width\ifovalbl\linethickness\else\z@\fi
    \hfil\ifovalbr\vrule width\linethickness\kern-\linethickness\fi}%
  \nointerlineskip\box2}%
  \@save=.5\@ydim \advance\@save.5\linethickness \leavevmode
  \kern-.5\@xdim \kern-.5\linethickness \lower\@save\box\@picbox}}

\def\cpic#1\endcpic{\vcenter{\hbox{\beginpicture#1\endpicture}}}

% Squines (quadratic splines)
% example of use: to plot f(x) between x0 and x1, you can say
% \put(0,0){\squine(x0,xm,x1,y0,ym,y1)}, where y0=f(x0), y1=f(x1)
% xm=(y0-y1+s1x1-s0x0)/(s1-s0), ym=(s0(s1x1-y1)-s1(s0x0-y0))/(s1-s0),
% s0=f'(x0), and s1=f'(x1).

\newdimen\@xi \newdimen\@xii \newdimen\@xiii \newdimen\@xiv
\newdimen\@xpt \newdimen\@xoldpt
\newdimen\@yi \newdimen\@yii \newdimen\@yiii \newdimen\@yiv
\newdimen\@ypt \newdimen\@yoldpt
\def\squine(#1,#2,#3,#4,#5,#6){\setbox\@picbox\hbox{\tencirc q}%
 \global\@xoldpt=#1\unitlength \global\@yoldpt=#4\unitlength \kern\@xoldpt
 \@xi=\@xoldpt \@xii=#2\unitlength \@xiii=#3\unitlength
 \@yi=\@yoldpt \@yii=#5\unitlength \@yiii=#6\unitlength
 \squinerec
 \@xpt=#3\unitlength \@ypt=#6\unitlength \@addpoint
 \raise\@ypt\copy\@picbox}
\newif\iffar
\def\squinerec{\farfalse \testnear\@xi\@xiii \testnear\@yi\@yiii
 \iffar \decast \fi}
\def\testnear#1#2{\@save=#1\advance\@save-#2%
 \ifdim\@save<\z@ \@save=-\@save\fi \ifdim\@save>\p@ \fartrue \fi}
\def\decast{\@xpt=\@xi \advance\@xpt\@xii \divide\@xpt2
 \advance\@xii\@xiii \divide\@xii2
 \@xiv=\@xpt \advance\@xiv\@xii \divide\@xiv2
 \@ypt=\@yi \advance\@ypt\@yii \divide\@ypt2
 \advance\@yii\@yiii \divide\@yii2
 \@yiv=\@ypt \advance\@yiv\@yii \divide\@yiv2
 \begingroup\@xii=\@xpt \@xiii=\@xiv
  \@yii=\@ypt \@yiii=\@yiv \squinerec\endgroup
 \@xpt=\@xiv \@ypt=\@yiv \@addpoint
 \@xi=\@xiv \@yi=\@yiv \squinerec}
\def\@addpoint{%\message{(\the\@xpt,\the\@ypt)}%
 \global\advance\@xoldpt-\@xpt \wd\@picbox=-\@xoldpt
 \raise\@yoldpt\copy\@picbox \global\@xoldpt=\@xpt \global\@yoldpt=\@ypt}

% Math operators
\def\2{\mskip-.5mu2\mskip.5mu}
\newmuskip\lessfortimes \lessfortimes=-2mu minus -2mu
\def\cdt{\mskip\lessfortimes\cdot\mskip\lessfortimes}
\def\nullnum{\phantom{0}}
\def\twonullnum{\phantom{00}}
\def\bex{\mskip-2mu}
\def\twoconditions#1#2{_{\scriptstyle#1\atop\scriptstyle#2}}
\def\tworestrictions#1#2{\vcenter{\offinterlineskip
  \halign{\strut\hfil##\hfil\cr#1\cr#2\cr}}}
\def\dts{\mathinner{\ldotp\ldotp}}
\def\[#1]{[\hbox{$\mskip1mu\thickmuskip=\thinmuskip#1\mskip1mu$}]}
\def\bigi[#1\bigr]{\bigl[\hbox{$\thickmuskip=\thinmuskip#1$}\bigr]}
\def\Bigi[#1\Bigr]{\Bigl[\hbox{$\thickmuskip=\thinmuskip#1$}\Bigr]}
\def\prp(#1){(\hbox{$\thickmuskip=\thinmuskip#1$})}
\def\pbigi(#1\bigr){\bigl(\hbox{$\thickmuskip=\thinmuskip#1$}\bigr)}
\def\_#1{\def\next{#1}%
 \ifx\next\risingsign\expandafter\rising\else^{\underline{#1}}\fi}
\def\risingsign{^}
\def\rising#1{^{\overline{#1}}}
\def\dotminus{\mathbin{\buildrel{\hbox{\runhead.}}\over{\smash{-}\vphantom{_2}}}}
\let\divides=\backslash
\def\edivides{\divides\mskip-4mu\divides}
\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\spec{\mathop{\rm Spec}}
\def\half{{1\over2}}
\def\rp{\mathchar"323F } % relatively prime
\def\lcm{\mathop{\rm lcm}}
\def\And{\quad{\rm and}\quad}
\let\==\equiv
\def\tmod#1{(mod~$#1$)}
\let\implies=\Longrightarrow
\def\?{\hbox{!`}} % subfactorial
\def\hyp{\mathop{F{}}\nolimits\hyper}
\def\tightplus{\medmuskip=1.5mu\relax}
\def\hyper#1#2#3{\mathchoice{\tightplus
   \hbox{$\displaystyle\biggl({#1\atop#2}\Big\vert\,{#3}\!\biggr)$}}%
 {\bigl({#1\atop#2}\vert\mskip2mu#3\bigr)}%
 {}{}}	% used only in D and T styles
%\def\hypk_#1{\mathop{F{}}_{#1}\nolimits\hyper} % confl with mFn convention
\def\hypk_#1#2#3#4{\mathop{F{}}\mathchoice{\tightplus
  \hbox{$\displaystyle\biggl({#2\atop#3}\Big\vert\,{#4}\!\biggr)$}%
  \lower\fontdimen11\mathsym\hbox{$\scriptstyle\!#1$}}%
 {\bigl({#2\atop#3}\vert\mskip2mu#4\bigr)\lower\fontdimen12\mathsym
   \hbox{$\scriptstyle\!#1$}}%
 {}{}}	% used only in D and T styles
\def\double(#1\choose#2){\mathchoice{\biggl(\!\!{#1\choose#2}\!\!\biggr)}
 {\bigl(\!{#1\choose#2}\!\bigr)}{}{}} % only D and T styles
\def\hypstrut{\vphantom{_1\_^k}} % if there's another denominator with \_^k
\def\deg{\mathop{\rm deg}}
\def\Bscr{{\scr B}}
\def\Escr{{\scr E}}
\def\Fscr{{\scr F}}
\def\Pscr{{\scr P}}
\def\Sscr{{\scr S}}
\def\adj{\relbar\joinrel\relbar} % adjacent in a graph
\let\<=\langle \let \>=\rangle
\def\Pr{\mathop{\rm Pr}\nolimits}
\def\Mean{\mathop{\rm Mean}\nolimits}
\def\Var{\mathop{\rm Var}\nolimits}
\def\between{\big\vert\hbox{\vphantom)}} % \between_a^b
{\catcode`\'=\active \gdef'{^\bgroup\mskip2mu\prim@s}} % more space before '
\def\array#1[#2]{\hbox{\tt#1[$#2$]}}
\def\given{\mskip1mu\vert\mskip1mu}
\def\euler{\atopwithdelims<>}
\def\Euler#1#2{\mathchoice{\biggl<\mskip-7mu{#1\euler#2}\mskip-7mu\biggr>}%
 {\bigl<\!{#1\euler#2}\!\bigr>}{}{}}

\newbox\phihatbox \newbox\scrphihatbox
\setbox\phihatbox=\hbox{$\phi$} \ht\phihatbox=1ex
\setbox\scrphihatbox=\hbox{$\scriptstyle\phi$}
  \ht\scrphihatbox=\fontdimen5\mathsublet
\setbox\phihatbox=\hbox{$\widehat{\box\phihatbox}$}
\setbox\scrphihatbox=\hbox{$\hat{\box\scrphihatbox}$}
\def\phihat{\mathchoice{\copy\phihatbox}{\copy\phihatbox}%
 {\copy\scrphihatbox}{{\hat\phi}}}

\newbox\mathsizebox
\def\setmathsize#1{\global\setbox\mathsizebox=\hbox{\displaymath#1$}}
\def\mathsize#1{\hbox to\wd\mathsizebox{\displaymath#1$\hss}}

\newbox\sqrtstrutbox
\setbox\sqrtstrutbox=\hbox{\vrule height10.5pt width\z@}
\def\strutsqrt#1{\copy\sqrtstrutbox\sqrt{{}^{\mathstrut}#1}}

\newbox\Sqbox % for sum of squares
\setbox\Sqbox=\vbox{\tenrm\hrule height.6pt\kern-.6pt
  \hbox to1.5ex{\vrule height1.5ex width.6pt\hss\vrule width.6pt}\kern-.6pt
  \hrule height.3pt depth.3pt}
\def\Sq{\mskip1.5mu\copy\Sqbox\mskip1.5mu}

% primitive index macros
% "stuff for index" will go into a file for sorting and into normal text
% "!stuff for index" will go into the file only
\expandafter\def\expandafter\dospecials\expandafter{\dospecials\do\"}
\def\hexcode{"} \catcode`\"=\active

\newif\ifinxmode
\newwrite\inx \newwrite\bnx
\newbox\inxbox

\newif\ifsilent
\def\beginxref{\futurelet\next\beginxrefswitch}
\def\beginxrefswitch{\ifx\next!\let\next=\silentxref
  \else\silentfalse\let\next=\xref\fi \next}
\def\silentxref!{\silenttrue\xref}
\let"=\beginxref

\def\xref#1"{\ifinxmode\edef\text{#1}\makexref\fi
  \ifsilent\ignorespaces\else#1\fi}
\def\makexref{\global\setbox\inxbox=%
   \vbox{\unvbox\inxbox\allowbreak\hbox{\inxstyle\text}}%
  \xdef\writeit{\write\inx{\text\space!\space
     \noexpand\number\pageno.}}\writeit}

% Final considerations
\catcode`\@=\active \def@{\mskip1mu\relax}
\expandafter\def\expandafter\dospecials\expandafter{\dospecials\do\@}

\hyphenation{logical Mac-Mahon hyper-geo-metric hyper-geo-met-rics Ber-noulli}

\preprintfalse		% WE ARE MAKING THE REAL BOOK!
\inxmodetrue		% WE ARE PREPARING A ROUGH INDEX
\showmissestrue		% THE REFERENCES SHOULD ALL BE READY NOW

\ifinxmode\immediate\openout\inx=\jobname.inx \fi % file for index reminders
\ifinxmode\immediate\openout\bnx=\jobname.bnx \fi % file for bib reminders

% To make the book:
% First TeX BIB, to get BIB.REF correct. (Must have \cite entries.)
% Then TeX CHAP1..CHAP9, PREF, ANS, CRED, FRONT, CONT.
% Then make BNX file from individual *.BNX files including BIB.BNX.
% Then reTeX BIB.
% *.INX files are raw data only. Index and Contents are prepared by hand.

% To produce only a subset of pages, put the page numbers on separate
% lines in a file called pages.tex, ended by 999
% WARNING: This will screw up the .grf file! Save it, then restore it.
% WARNING: This may screw up the .ref file (if there are \tabrefs). Ditto.
\let\Shipout=\shipout
\newread\pages \newcount\nxtpg \openin\pages=pages
\def\getnxtpg{\ifeof\pages\else
 {\endlinechar=-1\read\pages to\next
  \ifx\next\empty % in this case we should have eof now
  \else\global\nxtpg=\next\fi}\fi}
\ifeof\pages\else\message{OK, I'll ship only the requested pages!}
 \getnxtpg\fi
\def\shipout{\ifeof\pages\let\next=\Shipout
 \else\ifnum\pageno=\nxtpg\getnxtpg\let\next=\Shipout
  \else\let\next=\Tosspage\fi\fi \next}
\newbox\garbage \def\Tosspage{\deadcycles=0\setbox\garbage=}
