linalgjh.sty 14.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
\ProvidesPackage{linalgjh}[2001/06/08 Mathematics material for _Linear Algebra_ JH]
% linalgjh
%
%  Misc math that comes in handy for linear algebra.
%
% HISTORY
% 2001-Jun-08 Jim Hefferon  Cleaned up.

% input all the math packages
\RequirePackage{mathrsfs}
% AMS math 
12 13
% \RequirePackage[reqno]{amsmath}
\RequirePackage[reqno,disallowspaces]{mathtools}  % imports amsmath
14
\RequirePackage{amsfonts} %for Y&Y BSR AMS fonts
15
\RequirePackage{amssymb}
16
% \RequirePackage{amsthm}
17 18
\RequirePackage{array}
\RequirePackage{amscd}
Jim Hefferon's avatar
Jim Hefferon committed
19
% \RequirePackage{accents}
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36


%--------linsys
%  Use as \begin{linsys}{3}
%           x &+ &3y &+ &a &= &7 \\
%           x &- &3y &+ &a &= &7 
%         \end{linsys}
% Remark: TeXbook pp. 167-170 says to put a medmuskip around a +; and that's
% 4/18-ths of an em.  Why does 2/18-ths of an em work?  I don't know, but
% comparing to a regular displayed equation suggests it is right.
% (darseneau says LaTeX puts in half an \arraycolsep.)
\newenvironment{linsys}[2][m]{%
\setlength{\arraycolsep}{.1111em} % p. 170 TeXbook; a medmuskip
\begin{array}[#1]{@{}*{#2}{rc}r@{}} 
}{%
\end{array}}

37 38 39 40 41
% Sometimes a system has a column with no + or - in it.  LaTeX skips the space 
% in that column, and I'd like to put in a box of the right width there.
\newsavebox\boxofmathplus 
\sbox{\boxofmathplus}{$+$}
\newcommand{\spaceforemptycolumn}{\makebox[\wd\boxofmathplus]{\ }}
42 43 44 45

%--------grstep
% For denoting a Gauss' reduction step.
% Use as: \grstep{\rho_1+\rho_3} or \grstep[2\rho_5 \\ 3\rho_6]{\rho_1+\rho_3}
Jim Hefferon's avatar
Jim Hefferon committed
46 47 48 49 50 51 52 53 54 55
% \newcommand{\grstep}[2][\relax]{%
%    \ensuremath{\mathrel{
%        \mathop{\longrightarrow}\limits^{#2\mathstrut}_{
%                                    \begin{subarray}{l} #1 \end{subarray}}}}}

% Advantage of length formulation is that between adjacent 
% \grstep's you can add \hspace{-\grsteplength} to make it look not too wide
\newlength{\grsteplength}
\setlength{\grsteplength}{1.5ex plus .1ex minus .1ex}

56 57
\newcommand{\grstep}[2][\relax]{%
   \ensuremath{\mathrel{
Jim Hefferon's avatar
Jim Hefferon committed
58 59 60 61 62 63
       \hspace{\grsteplength}\mathop{\longrightarrow}\limits^{#2\mathstrut}_{
                                     \begin{subarray}{l} #1 \end{subarray}}\hspace{\grsteplength}}}}
% If two or more \grsteps are in a row then they need to be tightened
\newcommand{\repeatedgrstep}[2][\relax]{\hspace{-\grsteplength}\grstep[#1]{#2}}

% row swap operation: \rho_1\swap\rho_2
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
\newcommand{\swap}{\leftrightarrow}


%-------------amatrix
% Augmented matrix.  Usage (note the argument does not count the aug col):
% \begin{amatrix}{2}
%   1  2  3 \\  4  5  6
% \end{amatrix}
\newenvironment{amatrix}[1]{%
  \left(\begin{array}{@{}*{#1}{c}|c@{}}
}{%
  \end{array}\right)
}



%-------------pmat
% For matrices with arguments.
% Usage: \begin{pmat}{c|c|c} 1 &2 &3 \end{pmat}
\newenvironment{pmat}[1]{
  \left(\begin{array}{@{}#1@{}}
}{\end{array}\right)
}



%-------------misc matrices
91
% \newenvironment{mat}{\left(\begin{array}}{\end{array}\right)}
92 93 94 95 96 97 98 99 100 101 102
\newenvironment{detmat}{\left|\begin{array}}{\end{array}\right|}
\newcommand{\deter}[1]{ \mathchoice{\left|#1\right|}{|#1|}{|#1|}{|#1|} }
\newcommand{\generalmatrix}[3]{ %arg1: low-case letter, arg2: rows, arg3: cols 
               \left(
                  \begin{array}{cccc}
                    #1_{1,1}  &#1_{1,2}  &\ldots  &#1_{1,#2}  \\
                    #1_{2,1}  &#1_{2,2}  &\ldots  &#1_{2,#2}  \\
                              &\vdots                         \\
                    #1_{#3,1} &#1_{#3,2} &\ldots  &#1_{#3,#2}
                  \end{array}
               \right)  }
Jim Hefferon's avatar
Jim Hefferon committed
103

104
% With mathtools we can have column entries right flushed
Jim Hefferon's avatar
Jim Hefferon committed
105 106
% There is an optional argument \begin{mat}[r]{3} .. \end{mat} for
% right-flushed columns.  Perhaps the rule is that numbers are better 
107
% right-flushed but if there are any letters it is better centered?
Jim Hefferon's avatar
Jim Hefferon committed
108
\newenvironment{mat}[1][c]{\begin{pmatrix*} % disable optional arg [#1] 
Jim Hefferon's avatar
Jim Hefferon committed
109
      }{\end{pmatrix*}}
Jim Hefferon's avatar
Jim Hefferon committed
110 111
% If mat starts with &\vdots get an error; why?  No apparent macro fix, according to texexchange
\newenvironment{vmat}[1][c]{\begin{vmatrix*} % disable optional arg [#1] 
Jim Hefferon's avatar
Jim Hefferon committed
112
      }{\end{vmatrix*}}
Jim Hefferon's avatar
Jim Hefferon committed
113
\newenvironment{amat}[2][c]{%
Jim Hefferon's avatar
Jim Hefferon committed
114 115
  % disable optional arg \left(\begin{array}{@{}*{#2}{#1}|#1@{}}
  \left(\begin{array}{@{}*{#2}{c}|#1@{}}
116 117 118
}{%
  \end{array}\right)
}
119 120
% \newcommand\vdotswithin[1]{% Taken from mathtools.dtx because my TL is not 2011
%   {\mathmakebox[\widthof{\ensuremath{{}#1{}}}][c]{{\vdots}}}}
121 122 123 124 125


%------------colvec and rowvec
% Column vector and row vector.  Usage:
%  \colvec{1  \\ 2 \\ 3 \\ 4} and \rowvec{1  &2  &3}
Jim Hefferon's avatar
Jim Hefferon committed
126
% Colvec takes an optional argument \colvec[r]{x_1 \\ 0}.  Perhaps 
127 128
% digits look better right aligned, but if there are any letters it
% needs to be centered?
Jim Hefferon's avatar
Jim Hefferon committed
129
\newcommand{\colvec}[2][c]{\begin{mat}[#1] #2 \end{mat}}
130 131
% For row vectors, cannot do \newcommand{\rowvec}[1]{\begin{mat} #1 \end{mat}}
% since the delimiters come out too large.
Jim Hefferon's avatar
Jim Hefferon committed
132
\newcommand{\rowvec}[1]{\setlength{\arraycolsep}{3pt}(\begin{matrix} #1 \end{matrix})}
133 134 135 136 137 138 139 140 141 142 143 144 145


%-------------making aligned columns
% Usage: \begin{aligncolondecimal}{2} 1.2 \\ .33 \end{aligncolondecimal}
% (negative argument centers decimal pt in column).  Also Usage:
% \begin{aligncolondecimal}[0em]{2} 1.2 \\ .33 \end{aligncolondecimal}
% to make the left and right LaTeX-array padding disappear.
\RequirePackage{array}\RequirePackage{dcolumn}
\newenvironment{aligncolondecimal}[2][.1111em]{%
\setlength{\arraycolsep}{#1}
\newcolumntype{.}{D{.}{.}{#2}}\begin{array}{.}}{%
\end{array}}

Jim Hefferon's avatar
Jim Hefferon committed
146 147 148 149 150 151 152 153 154 155 156 157 158
% Matrix and vector, with numbers centered on decimal point
% Usage: \begin{dmat}{D{.}{.}{1}D{.}{.}{3}}  0  &.123 \\ .2 &.456 \end{dmat}
%  (in the D{.}{.}{number} that is the number of decimal places)
\newlength{\dmatcolsep}\setlength{\dmatcolsep}{5pt}
\newenvironment{dmat}[2][\dmatcolsep]{%
  \setlength{\arraycolsep}{#1}
  \left(\begin{array}{@{}#2@{}}
}{%
  \end{array}\right)}
% Usage: \dcolvec[2]{1.23 \\ 4.56} where the optional argument is the number
% of decimal places.
\newcommand{\dcolvec}[2][-1]{\left(\begin{array}{@{}D{.}{.}{#1}@{}} #2 \end{array}\right)}

159 160 161 162 163


%=============================================
% misc math definitions
%
Jim Hefferon's avatar
Jim Hefferon committed
164
\DeclareMathOperator{\trace}{Tr}
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
\DeclareMathOperator{\rank}{rank}
\DeclareMathOperator{\nullity}{nullity}
\newcommand{\isomorphicto}{\cong}
\newcommand{\rangespace}[1]{ \mathscr{R}(#1) }
\newcommand{\nullspace}[1]{ \mathscr{N}(#1) }
\newcommand{\genrangespace}[1]{ \mathscr{R}_\infty(#1) }
\newcommand{\gennullspace}[1]{ \mathscr{N}_\infty(#1) }
\newcommand{\zero}{ \vec{0} }
\newcommand{\polyspace}{\mathcal{P}}
\newcommand{\matspace}{\mathcal{M}}
\DeclareMathOperator{\size}{size}
\DeclareMathOperator{\adj}{adj}
\DeclareMathOperator{\sgn}{sgn}

% The term being defined.
\newcommand{\definend}[1]{\emph{#1}}

% Blackboard bold letters
Jim Hefferon's avatar
Jim Hefferon committed
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
\renewcommand{\Re}{\mathbb{R}}     
% \newcommand{\C}{\mathbb{C}}
% \newcommand{\N}{\mathbb{N}}
% \newcommand{\Q}{\mathbb{Q}}
% \newcommand{\Z}{\mathbb{Z}}

\ifdefined\Re
  \renewcommand{\Re}{\mathbb{R}}
\else
  \newcommand{\Re}{\mathbb{R}}
\fi
\newcommand{\R}{\mathbb{R}}
\ifdefined\C
  \renewcommand{\C}{\mathbb{C}}
\else
  \newcommand{\C}{\mathbb{C}} 
\fi
200 201 202 203 204 205 206 207 208 209
\newcommand{\N}{\mathbb{N}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\Z}{\mathbb{Z}}

% a field
\newcommand{\F}{\mathcal{F}}

% functions
\newcommand{\map}[3]{\mbox{$#1\colon #2\to #3$}}
\newcommand{\mapsunder}[1]{\stackrel{#1}{\longmapsto}}
Jim Hefferon's avatar
Jim Hefferon committed
210 211
% \newcommand{\mapsvia}[1]{\stackrel{#1}{\longrightarrow}}
\newcommand{\mapsvia}[1]{\xrightarrow{#1}}
212
% doesn't seem to be in mathtools: \newcommand{\mapsunder}[1]{\xrightmapsto{#1}}
213
\newcommand{\xmapsunder}[1]{\mapsunder{#1}}
214
\newcommand{\composed}[2]{#1\mathbin{\circ} #2}
215 216
% \newcommand{\identity}{\mbox{id}}
\DeclareMathOperator{\identity}{id}
217 218 219 220
\newcommand{\restrictionmap}[2]{{#1}\mathpunct\upharpoonright\hbox{}_{#2}}

% emptyset
\renewcommand{\emptyset}{\varnothing}
221 222
% sets 
% TODO: use braket.sty?
Jim Hefferon's avatar
Jim Hefferon committed
223
\newcommand{\setspacing}{0.1em}  % space between opening bbrace and set elet, and closing brace and set elet.  Note: \,=\thinspace=0.16667em
224 225 226
\newcommand{\set}[1]{\mbox{$\{\hspace{\setspacing}#1\hspace{\setspacing}\}$}} 
% \newcommand{\suchthat}{\bigm|}
\newcommand{\suchthat}{\mid}
227 228 229
\newcommand{\union}{\cup}
\newcommand{\intersection}{\cap}

230 231 232
\newcommand{\sequence}[1]{ \langle#1\rangle }  

% intervals
Jim Hefferon's avatar
Jim Hefferon committed
233
\newcommand{\interval}[2]{#1\,\ldots\, #2}
234 235 236 237 238 239
\newcommand{\setinterval}[2]{\mbox{$\{\interval{#1}{#2}\}$}} % or \set{\interval{#1}{#2}}
\newcommand{\openinterval}[2]{(\interval{#1}{#2})}
\newcommand{\closedinterval}[2]{[\interval{#1}{#2}]}
\newcommand{\clopinterval}[2]{[\interval{#1}{#2})}
\newcommand{\opclinterval}[2]{(\interval{#1}{#2}]}

240 241 242
%\newcommand{\implies}{\Longrightarrow}
\newcommand{\isimpliedby}{\Longleftarrow}

Jim Hefferon's avatar
Jim Hefferon committed
243
\newcommand{\Sage}{\textit{Sage}}
Jim Hefferon's avatar
Jim Hefferon committed
244
\newcommand{\Maple}{\textit{Maple}}
Jim Hefferon's avatar
Jim Hefferon committed
245

246 247 248 249 250 251 252 253 254 255 256 257
%\newcommand{\complement}[1]{\overline{#1}}
\newcommand{\cat}[2]{#1\!\mathbin{\raise.6ex\hbox{\( {}^\frown \)}}\!#2}
\newenvironment{strings}{\arraycolsep=.222em \begin{array}[t]}{\end{array}}

% sometimes want to have a bunch of equations
%  a = b
%  c = d
%    \vdots   <-- these should be cnetered on the `='
%  e = f
\newlength{\equalsignwd} \settowidth{\equalsignwd}{$=$}
\newcommand{\alignedvdots}[1][10pt]{\mskip2.5mu\makebox[.5\equalsignwd][r]{}%
                            \smash{\vdots}\rule{0pt}{#1}}
Jim Hefferon's avatar
Jim Hefferon committed
258
% (my version of mathtools doesn't (yet) have \shortvdotswithin)
259 260 261 262 263 264 265 266 267

\newcommand{\stdbasis}{{\cal E}}
\newcommand{\basis}[2]{\sequence{\vec{#1}_1,\ldots,\vec{#1}_{#2}}}
\newcommand{\rowspace}[1]{ \mathop{{\mbox{Rowspace}}}(#1) }
\newcommand{\colspace}[1]{ \mathop{{\mbox{Columnspace}}}(#1) }
\newcommand{\linmaps}[2]{ \mathop{{\cal L}}(#1,#2) }
\newcommand{\lincombo}[2]{
      #1_1#2_1+#1_2#2_2+\cdots +#1_n#2_n}
\newcommand{\rep}[2]{ {\rm Rep}_{#2}(#1) }
Jim Hefferon's avatar
Jim Hefferon committed
268
\newcommand{\wrt}[1]{{\mbox{\scriptsize \textit{wrt}\hspace{.25em}\( #1 \)} }}
Jim Hefferon's avatar
Jim Hefferon committed
269
% \newcommand{\trans}[1]{ {{#1}^{\rm trans}} }
Jim Hefferon's avatar
Jim Hefferon committed
270
\newcommand{\trans}[1]{ {{#1}^{\mathsf{T}}} }  % \textsf?
271 272 273 274
\newcommand{\proj}[2]{\mbox{proj}_{#2}({#1}) }

\newcommand{\spanof}[1]{\relax [#1\relax ]} % no optional argument!
\newcommand{\directsum}{\oplus}
Jim Hefferon's avatar
Jim Hefferon committed
275 276 277 278 279
% \newcommand{\norm}[1]{\|#1\|}
% \newcommand{\absval}[1]{|#1|}
% From http://tex.stackexchange.com/questions/43008/absolute-value-symbols
\DeclarePairedDelimiter\absval{\lvert}{\rvert}%
\DeclarePairedDelimiter\norm{\lVert}{\rVert}%
280 281 282 283 284 285 286 287 288 289 290
\DeclareMathOperator{\dist}{dist}

% dot product
%  I like to use a slightly different circle for dot product, for
% a visual distinction.
%  The AtBeginDocument makes pdflatex happier
\AtBeginDocument{\newlength{\heightofcdot}
\newlength{\widthofcdot}
\settoheight{\heightofcdot}{$\cdot$}
\settowidth{\widthofcdot}{$\cdot$}
\newsavebox{\dotprodcircle}       
Jim Hefferon's avatar
Jim Hefferon committed
291 292 293 294 295
% 2012-Jan-06 JH \bullet too big: 
\savebox{\dotprodcircle}{\scalebox{0.55}{$\bullet$}}  
% 2012-Jan JH  mpost won't take the graphic
% \savebox{\dotprodcircle}{\includegraphics{dotprod.1}} 
\newcommand{\dotprod}{\mathbin{\raisebox{.25\heightofcdot}{%
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
          \makebox[\widthofcdot]{$\smash{\usebox{\dotprodcircle}}$}}}}}

\newcommand{\nbyn}[1]{#1 \! \times \! #1 }       % \! is negative thinspace
\newcommand{\nbym}[2]{#1 \! \times \! #2 }       % Use in math mode.

% degrees
\newcommand{\degs}[1]{#1^\circ\relax}

% for the voting material
\newcommand{\votepreflist}[3]{\colvec{#1 \\ #2 \\ #3}}
\newcommand{\voteprefloop}[3]{%      #1 at 10 o'clock, #2 at 6, #3 at 2 o'clock
   \raisebox{.16in}{\scriptsize #1}%
   {\renewcommand{\arraystretch}{1.0}
   \begin{tabular}{@{}c@{}}
     \makebox[.32in]{\includegraphics{ch2.20}} \\[-.075in]
     \makebox[.1in]{{\scriptsize #2}}
   \end{tabular}}
   \raisebox{.16in}{\scriptsize #3}%
}
Jim Hefferon's avatar
Jim Hefferon committed
315
\newcommand{\votinggraphic}[1]{\hspace{1.15em}\mathord{\raisebox{-.2in}[.3in][.2in]{\includegraphics{voting.#1}}}\hspace{1.15em}}
316

Jim Hefferon's avatar
Jim Hefferon committed
317
% for magic squares
318 319
\newcommand{\magicsquares}{\mathscr{M}}
\newcommand{\semimagicsquares}{\mathscr{H}}
Jim Hefferon's avatar
Jim Hefferon committed
320

321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337

% for the networks topic
\newcommand{\circuitfont}{\sffamily}

% for the Nilpotence material
\newcommand{\digitinsq}[1]{\fbox{\( #1 \)} }
\newlength{\widthofdigitinsq}
\settowidth{\widthofdigitinsq}{\digitinsq{1}}
\newcommand{\digitincirc}[1]{%\mbox{\( #1 \)}
                             \makebox[\widthofdigitinsq]{%
                                \setlength{\unitlength}{1pt}%
                                \begin{picture}(0,0)(0,-3)
                                   \thinlines
                                    \put(0,0){\circle{12}}
                                    \put(0,-3){\makebox[0pt]{#1}}
                               \end{picture}}}

Jim Hefferon's avatar
Jim Hefferon committed
338 339 340
% For recurrence relations
\usepackage{xfrac}  % make proper fractions: 1/2

Jim Hefferon's avatar
Jim Hefferon committed
341 342 343 344 345 346 347 348 349
% In tables of matrices, add a bit of extra space above and below each line.
% Note that the included material is set in math mode
\newlength{\extramatrixvspace}
\setlength{\extramatrixvspace}{.75ex}
\newcommand{\matrixvenlarge}[1]{\raisebox{-0.5\height}{\vbox{
       \vspace*{\extramatrixvspace}
       \hbox{$#1$}
        \vspace*{\extramatrixvspace}
        }}}
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364


% from ltugboat.cls 2000-Apr-27 for making dashes.
% Really for 10 pt only.
%\def\thinskip{\hskip 0.16667em\relax}
%\def\endash{--}
%\def\emdash{\endash-}
%\def\d@sh#1#2{\unskip#1\thinskip#2\thinskip\ignorespaces}
%\def\dash{\d@sh\nobreak\endash}
%\def\Dash{\d@sh\nobreak\emdash}
%\def\ldash{\d@sh\empty{\hbox{\endash}\nobreak}}
%\def\rdash{\d@sh\nobreak\endash}
%\def\Ldash{\d@sh\empty{\hbox{\emdash}\nobreak}}
%\def\Rdash{\d@sh\nobreak\emdash}

365 366 367 368 369
% Vertically center graphics
% ex: \vcenteredhbox{\usegraphics{mygraph.png}}
% From http://tex.stackexchange.com/questions/7219/how-to-vertically-center-two-images
\newcommand*{\vcenteredhbox}[1]{\begingroup
\setbox0=\hbox{#1}\parbox{\wd0}{\box0}\endgroup}
370 371 372 373 374 375 376 377 378 379

%---------------------hyphenations
\hyphenation{range-space}
\hyphenation{range-spaces}
\hyphenation{null-space}
\hyphenation{null-spaces}
\hyphenation{re-la-tion}
\hyphenation{re-la-tions}
\hyphenation{re-la-tion-ship}

380

Jim Hefferon's avatar
Jim Hefferon committed
381 382 383
% In mechanics of matrix manipulation;
%  show some parts of a formula
\newcommand{\highlightcolorname}{lightgray}
Jim Hefferon's avatar
Jim Hefferon committed
384 385 386 387 388
% \newcommand{\highlight}[1]{{\setlength{\fboxsep}{.15em}% 
% \colorbox{\highlightcolorname}{#1}}}
\usepackage{calc}  % needed for \widthof
\usepackage{transparent}
% \usepackage{tikz} % for transparency
389 390 391 392 393
% \newcommand{\highlight}[1]{\makebox[\widthof{#1}]{\makebox[0pt]{\transparent{0.5}\colorbox{\highlightcolorname}{#1}}}}
\newcommand{\highlight}[1]{{%
  \setlength{\fboxsep}{1pt}%
  \setlength{\fboxrule}{0.2pt}%
  \framebox{#1}}}
Jim Hefferon's avatar
Jim Hefferon committed
394
% \newcommand{\highlight}[1]{\makebox[\widthof{#1}]{\begin{tikzpicture}[unit=1em]#1 \draw[fill=lightgray, ultra thin, lightgray, opacity=0.6] (0,0) rectangle (1,1); \end{tikzpicture}}}
Jim Hefferon's avatar
Jim Hefferon committed
395

396
\endinput