CSS

Thursday, August 27, 2009

Morphisms of...Morphisms? A First Look at Slice Categories

So to basically summarize the pattern that we have been using: we introduced mathematical objects, then some generalized notion of mappings between objects which we called "morphisms". We then collected a bunch of objects and morphisms together such that a bunch of nice properties were true, and we called it a category.

A category "is-a" mathematical object, so we figured out what morphisms between categories were: functors, or mathematical procedures. We then said "Hey, a functor 'is-a' mathematical object, what's a morphism between them?" It turns out it's a natural transformation.

But a morphism is-a mathematical object. So what's a "morphism" between morphisms? Is this a "meaningful" question? (It is, but first some references!)

  • Saunders Mac Lane, Categories for the Working Mathematician, Chapter II.6 "Comma Categories"
  • The Catsters, Youtube Lecture Series "Slice and Comma Categories", 1, 2

(We hope that the reader can see the pattern here, in category theory we started out with remarkably simple, almost comical, premises. We have objects, and we have morphisms. We group all objects of the same sort together into a category. But we can apply this powerful notion of a morphism to any object, and everything in math "is-a" mathematical object. We can then ask, for each object, what's the morphism of this thing? What's a morphism of this morphism? And so on...)

Category of Objects Under and Over a Specific Object

Now, to discuss morphisms between objects, we need to demand that they are the "same sort" of objects. How to do this? Well, we can demand that the morphisms are from one fixed object or dually they go to one fixed object.

More precisely, let bC be a fixed object, we can construct "the category of objects under $b$" denoted by $(b\downarrow\mathbf{C})$. Basically the objects are ordered pairs $\langle f,c\rangle$ consisting of morphisms from $b$ and the target of the morphism, and the morphisms are morphisms of the target $h:\langle f,c\rangle\to\langle f',c'\rangle$...well, this doodle should summarize things nicely:

Composition of morphisms is given by composition of these triangles. More precisely, the composition of the morphisms in the base of the triangle. To be formal, lets give the full definition:

Definition 1. Let C be a category, bC be some element. Then a "category of objects under b" consists of
  1. (Objects) the collection of ordered pairs ⟨f,c⟩ where $f:b\to{c}$ is a morphism in C, and cC is an object;
  2. (Morphisms) the morphisms are h: ⟨f,c⟩ → ⟨f',c'⟩
such that the following diagram specifies this

Consider any one point set $*$, and any other set $X$. The function $*\to{X}$ is a single element of $X$. The category of objects under $*$ consist of objects $\langle *\to{X},X\rangle$ which is a selected element of $X$, and the set $X$. This is precisely Set*, the first part of the ordered pair (the morphism) is the "base point", the second part of the ordered pair is the set itself.

Now, as alluded to earlier, we can reverse the direction of the arrows by "duality". This ends up letting us consider morphisms with the same target.

That is, if we have a category C and an object aC, then we can construct a category with the objects being ⟨c,f⟩ where f : ca is a morphism.

The morphisms in this category would be "morphisms of morphisms". More precisely, it would make the following diagram (on the right) commute:

As we reversed the direction of the arrows, we should probably distinguish this sort of category of objects over a from the category of objects under b. We denote it by (Ca), compared to (bC) for objects under b.

Formally, this is summarized in the following definition:

Definition 2. Let C be a category, aC be some element. Then a "category of objects over a" denoted by (Ca) consists of
  1. (Objects) the collection of ordered pairs ⟨f,c⟩ where $f:c\to{a}$ is a morphism in C, and cC is an object;
  2. (Morphisms) the morphisms are h: ⟨f,c⟩ → ⟨f',c'⟩
such that the following summarizes the category:

Observe that this is just the same as the category of objects under b, except we have the arrows be reversed.

We should consider, to be kosher, what (Set*) is. The objects are ordered pairs, as before, consisting of ⟨X → *,*⟩ where the first component of the ordered pair is unique. There is always a map in Set from X to a singleton *, it's very boring though -- it's the constant map. It's a unique map too (this is kind of trivial, where else could it map stuff to? There's only one choice!).

The morphisms are really just morphisms between the sets.

Lets think for a second: for each object XSet there is a unique object ⟨X → *,*⟩ in (Set*); and for each morphism fhomSet(X,Y) there is a corresponding morphism in (Set*).

Since there is a unique one-to-one correspondence between objects and between morphisms in the two categories, we can represent this by a functor which is invertible. What does this mean? It's an isomorphism...i.e. (Set*) is isomorphic to Set!!!

Remark: Notation

Apparently Mac Lane uses two notations. One is what we've seen. The other is writing C/c for (C ↓ c), and (one assumes) c/C for (c ↓ C). Just be warned there are two different notations (apparently).

[More to follow...apologies to those who would've liked more, duty calls at my job]

Wednesday, August 19, 2009

Emacs Latex Macros

Oftentimes I write LaTeX notes in the emacs editor, and I often do it on an Asus EEE PC 900 HA. Unfortunately, the keyboard is rather small, and my hands rather large, which leads to some complications. To make things worse, the "\" key is as wide as a fingernail's width (which is a nightmare for LaTeX coding!).

Fortunately there is a solution with Emacs: macros! I've written up a few macros that simplifies my life. First I have an texHelp.el file in my ~/.emacs.d/ directory which consists of the following stuff:

;; macro to help me write stuff
(defun write (mystring)
  (insert-string mystring)
  (newline))

;; starts the document class
(defun docclass ()
  (interactive)
  (write "\\documentclass{amsart}"))

;; use a package
(defun use-package (package)
  (interactive)
  (write (concat
    "\\usepackage{"
    package
    "}")))

;; all the packages of interest
(defun my-packages ()
  (interactive)
  (use-package "url")
  (use-package "manfnt")
  (use-package "amsthm")
  (use-package "amsmath")
  (use-package "amsthm")
  (use-package "amssymb")
  (use-package "amsfonts")
  (use-package "amscd")
  (use-package "graphicx")
  (write "\\DeclareGraphicsRule{*}{mps}{*}{}")
  (use-package "mathrsfs")
  (newline))

;; amsthm package configuration
(defun thm-style ()
  (interactive)
  (write "\\theoremstyle{definition}")
  (write "\\newtheorem{defn}{Definition}")
  (write "\\newtheorem{thm}{Theorem}")
  (write "\\newtheorem{rmk}{Remark}")
  (write "\\newtheorem{lem}{Lemma}")
  (write "\\newtheorem{cor}{Corollary}")
  (write "\\newtheorem{ex}{Example}")
  (write "\\newtheorem{nonex}[ex]{NON-Example}")
  (write "\\newtheorem{prop}{Proposition}")
  (write "\\newtheorem{sch}{Scholium}")
  (write "\\newtheorem{axm}{Axiom}")
  (write "\\newtheorem*{prob}{Problem}")
  (newline))

;; number equations within the section
(defun eqn-numbering ()
  (interactive)
  (write "\\numberwithin{equation}{section}")
  (newline))

;; my custom defined macros
(defun macros ()
  (interactive)
  ;;;;;;;;;;;;;;;;;;;;;;
  ;; code snipped out ;;
  ;;;;;;;;;;;;;;;;;;;;;;
  (newline))

(defun doc-stuff ()
  (interactive)
  (write "\\title[]{}")
  (write (concat "\\date{" (format-time-string "%B %d, %Y") "}"))
  (write (concat "\\email{" user-email-address "}"))
  (write (concat "\\author{" user-full-name "}"))
  (write "\\begin{document}")
  (write "\\maketitle")
  (newline)
  (newline)
  (write "\\end{document}"))

;; call this function when starting a new LaTeX document
(defun start-tex ()
  (interactive)
  (docclass)
  (my-packages)
  (eqn-numbering)
  (thm-style)
  (macros)
  (doc-stuff)
  (previous-line 5))

I only need to create the directory (usually I have a ~/notebk directory, and subdirectories ordered in the way arXiv is ordered, so I usually create sub-sub-directories of ~/notebk/*), then create the file with C-x C-f path and start TeXnical stuff with M-x start-tex (remember that M-x means "Alt-x").

This does not solve the problem of the tex macros, I would still have to write "\begin{equation}...\end{equation". Woah is me!

Fortunately Emacs macros comes to the rescue yet again! I have another file, ~/.emacs.d/texMacros.el which consists of the helper functions:

;; for subequations
(defun subeqn()
  (interactive)
  (insert "\\begin{subequations}\n")
  (insert "\\begin{align}\n")
  (insert "\n")
  (insert "\\end{align}\n")
  (insert "\\end{subequations}")
  (previous-line 2))

;; for equations
(defun eqn()
  (interactive)
  (insert "\\begin{equation}%\\label{eq:}\n")
  (insert "\n")
  (insert "\\end{equation}")
  (previous-line 1))

;; all the amsthm environment
(defun thm()
  (interactive)
  (insert "\\begin{thm}%\\label{thm:}\n")
  (insert "\n")
  (insert "\\end{thm}\n")
  (insert "\\begin{proof}\n\n")
  (insert "\\end{proof}")
  (previous-line 4))
(defun defn()
  (interactive)
  (insert "\\begin{defn}%\\label{defn:}\n")
  (insert "\n")
  (insert "\\end{defn}")
  (previous-line 1))
(defun cor()
  (interactive)
  (insert "\\begin{cor}%\\label{cor:}\n")
  (insert "\n")
  (insert "\\end{cor}")
  (previous-line 1))
(defun lem()
  (interactive)
  (insert "\\begin{lem}%\\label{lem:}\n")
  (insert "\n")
  (insert "\\end{lem}")
  (previous-line 1))
(defun rmk()
  (interactive)
  (insert "\\begin{rmk}\n")
  (insert "\n")
  (insert "\\end{rmk}")
  (previous-line 1))
(defun prop()
  (interactive)
  (insert "\\begin{prop}%\\label{prop:}\n")
  (insert "\n")
  (insert "\\end{prop}")
  (previous-line 1))
(defun ex()
  (interactive)
  (insert "\\begin{ex}\n")
  (insert "\n")
  (insert "\\end{ex}")
  (previous-line 1))
(defun nonex()
  (interactive)
  (insert "\\begin{nonex}\n")
  (insert "\n")
  (insert "\\end{nonex}")
  (previous-line 1))

;; lists macros
(defun enumerate()
  (interactive)
  (insert "\\begin{enumerate}\n")
  (insert "\\item \n")
  (insert "\\end{enumerate}")
  (previous-line 1))
(defun itemize()
  (interactive)
  (insert "\\begin{itemize}\n")
  (insert "\\item \n")
  (insert "\\end{itemize}")
  (previous-line 1))
(defun item()
  (interactive)
  (insert "\\item "))

;; proofs, from the amsthm package
(defun pf()
  (interactive)
  (insert "\\begin{proof}\n")
  (insert "\n")
  (insert "\\end{proof}")
  (previous-line 1))
(defun axm()
  (interactive)
  (insert "\\begin{axm}%\\label{axm:}\n")
  (insert "\n")
  (insert "\\end{axm}")
  (previous-line 1))
(defun prob()
  (interactive)
  (insert "\\begin{prob}\n")
  (insert "\n")
  (insert "\\end{prob}")
  (previous-line 1))

;; reference to an equation
(defun eqref()
  (interactive)
  (insert "\\eqref{}")
  (backward-char 1))
(defun pmatrix()
  (interactive)
  (insert "\\begin{pmatrix}\n")
  (insert "\n")
  (insert "\\end{pmatrix}")
  (previous-line 1))
(defun diagram()
  (interactive)
  (insert "\\begin{figure}[H]\n")
  (insert "\\includegraphics{}\n")
  (insert "\\end{figure}")
  (previous-line 2)
  (forward-char 23))
(defun fig()
  (interactive)
  (diagram))
(defun figure()
  (interactive)
  (fig))
(defun src()
  (interactive)
  (insert "\\begin{Verbatim}[fontsize=\\footnotesize,frame=lines,numbers=left,numbersep=3pt,firstnumber=]\n")
  (insert "\n")
  (insert "\\end{Verbatim}")
  (previous-line 2)
  (forward-char 77))
(defun quotation()
  (interactive)
  (insert "\\begin{quote}\n")
  (insert "\n")
  (insert "\\end{quote}")
  (previous-line 1))

And shazam! I'm off to the races, avoiding usage of the "\" key with only a handful of exceptions.

If one wants to have a bunch of keybindings for these functions, one can use the following in their ~/.emacs file:

;; load texMacros when doing LaTeX stuff
(load "~/.emacs.d/texHelp.el")
(load-file "~/.emacs.d/texMacros.el")  ; load these LaTeX preferences
(defun my-LaTeX-startup ()
  (interactive)
  (local-unset-key "\C-c\C-e")
  (local-set-key "\C-c\C-e" 'eqn)
  (local-unset-key "\C-c\C-s")
  (local-set-key "\C-c\C-s" 'subeqn)
  (local-unset-key "\C-c\C-t")
  (local-set-key "\C-c\C-t" 'thm)
  (local-unset-key "\C-c\C-d")
  (local-set-key "\C-c\C-d" 'defn)
  (local-unset-key "\C-c\C-r")
  (local-set-key "\C-c\C-r" 'rmk)
  (local-unset-key "\C-c\C-l")
  (local-set-key "\C-c\C-l" 'lem)
  (local-unset-key "\C-c\C-k")
  (local-set-key "\C-c\C-k" 'cor)
  (local-unset-key "\C-c\C-p")
  (local-set-key "\C-c\C-p" 'prop)
  (local-unset-key "\C-c\C-x")
  (local-set-key "\C-c\C-x" 'ex)
  (local-unset-key "\C-c\C-n")
  (local-set-key "\C-c\C-n" 'nonex))
(add-hook 'LaTeX-mode-hook 'my-LaTeX-startup)
(add-hook 'latex-mode-hook 'my-LaTeX-startup)
(add-hook 'TeX-mode-hook 'my-LaTeX-startup)

Of course, one is more than welcome to change the keybindings to their own preference!

Addendum: Making the Definition Macro Better!

Recall for our object oriented approach, we have a mathematical object consist of "stuff" equipped with some "structure" such that a bunch of "properties" hold. We can modify the definition environment to simplify this format. In ~/.emacs.d/texMacros.el, change the (defun defn() ...) lines to be:

(defun defn()
  (interactive)
  (insert "\\begin{defn}%\\label{defn:}\n")
  (insert "A \\textbf{} consists of\n")
  (insert "\\begin{enumerate}\n\\item\n\\end{enumerate}")
  (insert "\n equipped with\n")
  (insert "\\begin{enumerate}\n\\item\n\\end{enumerate}")
  (insert "\n such that\n")  
  (insert "\\begin{enumerate}\n\\item\n\\end{enumerate}")
  (insert "\n\\end{defn}")
  (previous-line 10))

You're set to start defining objects left and right!

Thursday, August 13, 2009

LaTeX Macros...

So here are some LaTeX3 macros I've found or written that are pretty useful. This post covers the following packages I've written/patched together:

  • Bourbaki inspired dangerous bend environments
  • Macros for underbrackets and overbrackets, similar to underbrace and overbrace
  • Misner, Thorne, and Wheeler type equations
  • Exercises and Answers in the style of the TeXbook
  • Style like the TeXbook in LaTeX macros

Addendum (9:30 AM (PST) 15 December 2011): I have modified the danger.sty code, and it is now more robust. For more macros, see my Notebk's wiki page for others and documentation.

Dangerous Bends!

Bourbaki used Dangerous Bend symbols to indicate some tricky reasoning. Knuth used this too in his TeX book, among other places.

I too use it in my notes...but I use it as an environment. It's safer this way ;) At any rate the code is contained a file danger.sty, reproduced below:

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{danger}[2009/08/06 Danger and Double Danger Environments]

\usepackage{manfnt}
% or if manfnt is unavailable, uncomment the next two lines
%\font\manual=manfnt
%\def\dbend{{\manual\char127}} % dangerous bend sign

%%
% This macro header is what controls the ``dangerous bend''
% paragraph
%%

% Danger, Will Robinson!
\newenvironment{danger}{\medbreak\noindent\hangindent=2pc\hangafter=-2%
  \clubpenalty=10000%
  \hbox to0pt{\hskip-\hangindent\dbend\hfill}\small\ignorespaces}%
  {\medbreak\par}

% Danger! Danger!
\newenvironment{ddanger}{\medbreak\noindent\hangindent=3pc\hangafter=-2%
  \clubpenalty=10000%
  \hbox to0pt{\hskip-\hangindent\dbend\kern2pt\dbend\hfill}\small\ignorespaces}%
  {\medbreak\par}

The above code is just literally cut/paste from Knuth's TeXbook macros. On the other hand, in LaTeX a better implementation might be:

\font\manual=manfnt
\def\dbend{{\manual\char127}} % dangerous bend sign

% Danger, Will Robinson!
\newenvironment{danger}{\medbreak\noindent\hangindent=2pc\hangafter=-2%
  \clubpenalty=10000%
  \hbox to0pt{\hskip-\hangindent\dbend\hfill}\small\ignorespaces}%
  {\medbreak\par}

% Danger! Danger!
\newenvironment{ddanger}{\medbreak\noindent\hangindent=3pc\hangafter=-2%
  \clubpenalty=10000%
  \hbox to0pt{\hskip-\hangindent\dbend\kern2pt\dbend\hfill}\small\ignorespaces}%
  {\medbreak\par}

Underbrackets and Overbrackets

In math mode, you can use underbrace and overbrace, but there are no corresponding brackets macros. This is sad, because I'm more fond of brackets than I am of braces.

So I fiddled around and pieced together the brackets.sty file:

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{brackets}[2009/08/06 Overbracket and Underbracket racket]

\makeatletter
\def\overbracket{\@ifnextchar [ {\@overbracket} {\@overbracket
[\@bracketheight]}}
\def\@overbracket[#1]{\@ifnextchar [ {\@over@bracket[#1]}
{\@over@bracket[#1][0.3em]}}
\def\@over@bracket[#1][#2]#3{%\message {Overbracket: #1,#2,#3}
\mathop {\vbox {\m@th \ialign {##\crcr \noalign {\kern 3\p@
\nointerlineskip }\downbracketfill {#1}{#2}
                              \crcr \noalign {\kern 3\p@ }
                              \crcr  $!\hfil$ \displaystyle {#3}\hfil $%
                              \crcr} }}\limits}
\def\downbracketfill#1#2{$!\m@th$ \setbox \z@ \hbox {$!\braceld$$}
                  \edef\@bracketheight{\the\ht\z@}\downbracketend{#1}{#2}
                  \leaders \vrule \@height #1 \@depth \z@ \hfill
                  \leaders \vrule \@height #1 \@depth \z@ \hfill
\downbracketend{#1}{#2}$}
\def\downbracketend#1#2{\vrule depth #2 width #1\relax}


\def\underbracket{%
  \@ifnextchar[{\@underbracket}{\@underbracket [\@bracketheight]}%
}
\def\@underbracket[#1]{%
  \@ifnextchar[{\@under@bracket[#1]}{\@under@bracket[#1][0.4em]}%
}
\def\@under@bracket[#1][#2]#3{%\message {Underbracket: #1,#2,#3}
 \mathop{\vtop{\m@th \ialign {##\crcr $!\hfil$ \displaystyle {#3}\hfil $!$%
 \crcr \noalign {\kern 3\p@ \nointerlineskip }\upbracketfill {#1}{#2}
       \crcr \noalign {\kern 3\p@ }}}}\limits}
\def\upbracketfill#1#2{$!\m@th$ \setbox \z@ \hbox {$!$\braceld$!$}
                    \edef\@bracketheight{\the\ht\z@}\bracketend{#1}{#2}
                    \leaders \vrule \@height #1 \@depth \z@ \hfill
                    \leaders \vrule \@height #1 \@depth \z@ \hfill \bracketend
               {#1}{#2}$}
\def\bracketend#1#2{\vrule height #2 width #1\relax}
\makeatother


% Makes limits on sums and integrals pretty
\def\mathllap{\mathpalette\mathllapinternal}
\def\mathllapinternal#1#2{\llap{$\mathsurround=0pt#1{#2}$}}
\def\clap#1{\hbox to 0pt{\hss#1\hss}}
\def\mathclap{\mathpalette\mathclapinternal}
\def\mathclapinternal#1#2{\clap{$\mathsurround=0pt#1{#2}$}}
\def\mathrlap{\mathpalette\mathrlapinternal}
\def\mathrlapinternal#1#2{\rlap{$\mathsurround=0pt#1{#2}$}}

The other part of the code, which % Makes limits pretty, allows stuff to be written on top of the sum's limits. It's taken from Voss's math mode notes.

Equations with Misner, Thorne and Wheeler type Arrows

This is going to be a bit harder to explain (it's one of those "You have to have seen it to understand what I'm talking about" type situations). So look at page 139, equation 5.15a for example. Note the arrows pointing to the terms in the equation? Yeah, I'd like to do that in LaTeX, but how?

Unfortunately you have to use the picture environment (or, at least, that's the only way I know how to do it!). Consider the following example document:

\documentclass{amsart}
\usepackage{brackets}

\newlength\textwidthcm
\textwidthcm=.03514598035146\textwidth

\begin{document}
{\catcode`p=12 \catcode`t=12 \gdef\cm#1pt{#1cm}}
{\catcode`p=12 \catcode`t=12 \gdef\dimensionless#1pt{#1}}

\begin{equation}\label{eq:one}
E=mc^{2}
\end{equation}


\setlength{\unitlength}{1cm}
\begin{picture}(\expandafter\dimensionless\the\textwidthcm, 2.5)(0,0)
  \linethickness{0.5pt}
  \put(5,1.5){$\displaystyle Z[0]=\underbracket[0.25pt]{\int ~\mathcal{D}\phi\;\;\; }
               \!\!\!\exp(\int\mathcal{L}d^{4}x)$}
  \put(-.4,1.5){\refstepcounter{equation}{(\arabic{equation})\label{eq:four}}}
  \put(6.75,0.55){\vector(0,1){0.4}}
  \put(6.75,0.55){\line(1,0){1.4}}
  \put(8.15,0.5){\makebox{$\begin{pmatrix}
                        $!sum$$\ 
                        $!over$$\\ 
                        $!histories$$
                        \end{pmatrix}$}}
\end{picture}
Woah what is eq \eqref{eq:four} again? Don't forget the text width is \the\textwidth ~or 
equivalently \expandafter\cm\the\textwidthcm ~or 
\expandafter\dimensionless\the\textwidthcm
\end{document}

This produces the following text:

The only disadvantage is that for each equation you want to do, you have to do this by hand.

Exercises and Answers Macros From The TeXbook

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{exercises}[2009/08/06 LaTeX version of exercise macros from the TeXbook]
%%%%%%
% Options: number within either the chapter or the part
%          default is to number the exercises/answers via sections
%%%%%%%%
\newif\if@dump
\@dumpfalse
\newif\if@section
\newif\if@ch@pter
\newif\if@p@rt
\@sectiontrue\@ch@pterfalse\@p@rtfalse
\DeclareOption{chapter}{\@sectionfalse\@ch@pterfalse\@p@rtfalse}
\DeclareOption{part}{}
\def\dump@nswer{0}
\DeclareOption{dump}{\@dumptrue}
\ProcessOptions\relax

\usepackage{manfnt}


\newcounter{sectionCtr}
\newcounter{exno}
\setcounter{exno}{0}


\refstepcounter{sectionCtr}
\if@section
\newcommand{\upd@teCtr}{\ifnum \value{sectionCtr}=\value{section}%
\refstepcounter{exno}\else\setcounter{exno}{1}\setcounter{sectionCtr}{\value{section}}\fi}
\else\if@ch@pter%
\newcommand{\upd@teCtr}{\ifnum \value{sectionCtr}=\value{chapter}
\refstepcounter{exno}\else\setcounter{exno}{1}\setcounter{sectionCtr}{\value{chapter}}\fi}
\else\if@p@rt%
\newcommand{\upd@teCtr}{\ifnum \value{sectionCtr}=\value{part}%
\refstepcounter{exno}\else\setcounter{exno}{1}\setcounter{sectionCtr}{\value{part}}\fi}
\else\@sectiontrue\setcounter{exno}{1}\setcounter{sectionCtr}{\value{section}}
\newcommand{\upd@teCtr}{\ifnum \value{sectionCtr}=\value{section}%
\refstepcounter{exno}\else\setcounter{exno}{1}\setcounter{sectionCtr}{\value{section}}\fi}
\fi\fi\fi

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Exercise Environment
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% well, to make it an environment, one would instead do the following:
% \newenviornment{exercise}{\medbreak\upd@teCtr%
%  \noindent\llap{\mantriangleright\kern.15em}% triangle in margin
%  \small{\textbf{EXERCISE \thesection.\arabic{exno}}}\\%
%  \noindent}{}
% that is, stuff the command into an environment
\newcommand{\exercise}{\medbreak\upd@teCtr%
  \noindent\llap{\mantriangleright\kern.15em}% triangle in margin
  \small{\textbf{EXERCISE \thesection.\arabic{exno}}}\\%
  \noindent}
\newcommand{\dexercise}{\medbreak\upd@teCtr%
  \noindent\llap{\mantriangleright\kern.15em}% triangle in margin
  \small{\textbf{EXERCISE \arabic{sectionCtr}.\arabic{exno}}}\\%
  \noindent}
\newcommand{\dangerexercise}{\dbend \dexercise}
\newcommand{\ddangerexercise}{\dbend\dbend \dexercise}


% formatting macro
\if@dump
  \def\ansno#1.#2:{\medbreak\noindent%
    \hbox to\parindent{\bf\hss(Answer to #1.#2)\enspace}\ignorespaces}
\else
  \def\ansno#1.#2:{\medbreak\noindent%
    \hbox to \parindent{\bf\hss #1.#2.\enspace}\ignorespaces}
\fi

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Answers Command
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\if@dump % if we are dumping the answers directly where they're placed
  \def\ans{} % ans is defined as nothing
  \newcommand{\answer}[1]{\par\medbreak % \answer simply
      \ansno\arabic{sectionCtr}.\arabic{exno}: \\% prints directly
      #1} % out when it's called 
  \newcommand{\dumpanswers}{} % \dumpanswers is empty
\else % else we are dumping it into a file
  \newwrite\ans%
  \immediate\openout\ans=answers % file for answers to exercises
  \newcommand{\answer}[1]{\par\medbreak
    \immediate\write\ans{}%
    \immediate\write\ans{\string\ansno\arabic{sectionCtr}.\arabic{exno}:}%
    \immediate\write\ans{ \detokenize{#1}}}
  \newcommand{\dumpanswers}{\immediate\closeout\ans\input{answers}}
\fi

One could easily turn the exercises command into an environment, but it'd be trickier to turn the \answer command into an environment. The \answer spits out all the answers to a file answers.tex which can be included at the end of the main document.

To write the answers, one should call the \dumpanswers command in its own section/chapter. It does everything necessary to include the answers in the document.

The Poor Man's TeXbook Style

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{TeXbook}[2009/08/06 Poor man's \TeX{}book style for \LaTeX]

% the following is the TeXbook's exact specifications
%\usepackage[textheight=38pc,headsep=10pc,top=16pc,%
% textwidth=30pc,inner=6pc,marginparwidth=8pc,marginparsep=1cm]{geometry}
% the following is OUR preferred specifications!
\usepackage[top=6pc,textwidth=30pc,inner=6pc,%
marginparwidth=10pc,marginparsep=1cm]{geometry}
\normalbaselineskip=12pt
\baselineskip=12pt
\abovedisplayskip=6pt plus 3pt minus 1pt
\belowdisplayskip=6pt plus 3pt minus 1pt
\abovedisplayshortskip=0pt plus 3pt
\belowdisplayshortskip=4pt plus 3pt

\usepackage{fancyhdr,marginnote}

\pagestyle{fancy}
\if@twoside
\fancyhead[LE,RO]{\thepage}
\fancyheadoffset[OR,EL]{8pc}
\else
\fancyhead[L]{\S\thesection~\nouppercase{\rightmark}}
\fancyhead[R]{\thepage}
\fancyheadoffset[R]{8pc}
\renewcommand{\sectionmark}[1]{\markboth{}{#1}}
\fi
\cfoot{}
\renewcommand{\headrulewidth}{0.4pt}

\if@twoside
\renewcommand\marginpar[1]{\-\marginnote{\footnotesize{\emph{#1}}}}
\else
\renewcommand\marginpar[1]{\-\marginnote{\raggedright\footnotesize{\emph{#1}}}}%
\fi

This has a decent sized margin, the header is also slightly extended. It's really just a poor man's TeXbook style file, using the exact specifications from the manmac.tex macros file that is freely available from CTAN.

Note that the style file is not exactly as the TeXbook specifies, I thought the \headsep was too large. The textwidth and placement from the inner margin are the same, the marginparwidth is slightly larger so one can write annotations in the margins (I love using \marginpar).

I'm writing up some notes on slice and comma categories, as well as adjoint functors, so sit tight while I polish them up in the next couple of days...

Tuesday, August 11, 2009

Coproducts (but not Products!)

We introduced the notion of products as a sort of categorification of the "Cartesian Product". The product of $c_1$ and $c_2$ is an object $p$ equipped with projection morphisms $\pi_1:p\to{c_1}$ and $\pi_2:p\to{c_2}$ such that some diagram commutes.

We also introduced the duality principle, which allows us to "reverse the arrows" in diagrams to get some "dual" notion. So now we would like to use the duality principle to find the dual notion of a product, or the "co-product". First some references:

  • The Catsters, "Products and Coproducts" Lectures: 2, 3, 4
  • Saunders Mac Lane, Categories for the Working Mathematician Graduate Texts in Mathematics (vol 5) Springer-Verlag, Second Edition (1998);
  • Jiri Adámek, Horst Herrlich, George E. Strecker Abstract and Concrete Categories: The Joy of Cats freely available online (2004)
  • Serge Lang Algebra Springer-Verlag, Third Edition (2000)

We set up our diagram by reversing the arrows for the product. That is, in some category C, we have objects $c_1,c_2\in\mathbf{C}$, the product is an object $p$ such that given any object $d\in\mathbf{C}$ with morphisms $f:d\to{c_1}$, $g:d\to{c_2}$, then there exists a morphism $h:d\to{p}$ such that the following diagram commutes:

\begin{diagram}
      &                &      d        &                &      \\
      &\ldTo^{f}       & \dDashto_{!h} & \rdTo^{g}      &      \\
c_{1} & \lTo_{\pi_{1}} & p             & \rTo_{\pi_{2}} & c_{2}
\end{diagram}

Now we "turn the arrows around". We denote the coproduct of $c_1$ with $c_2$ as an object $c_1\sqcup\displaystyle{c_2}$. We want this object to be equipped with two morphisms, but they should be dual to the projection morphisms. Huh? They should have the codomain and the domain switched, so $i:c_1\to c_1\sqcup\displaystyle{c_2}$ and $j:c_2\to c_1\sqcup\displaystyle{c_2}$. We call these morphisms "injections" or "insertion maps" of the coproduct (although they are not required to be injective functions).

Now putting the diagram on its head, we end up with the following property that coproducts must satisfy: for each $d$ with morphisms $f:c_1\to{d}$ and $g:c_2\to{d}$, there exists a unique morphism $h:c_1\sqcup\displaystyle{c_2\to{d}}$ such that the following diagram commutes:

So to summarize what we've figured, lets write the formal definition of the coproduct:

Definition 1. Let C be some category and $c_{1},c_{2}\in\mathbf{C}$, the "Coproduct of $c_1$ with $c_2$" consists of
  • an object $c_{1}\sqcup\displaystyle{c_{2}\in\mathbf{C}}$
equipped with
  • a pair of morphisms $i:c_{1}\to c_{1}\sqcup\displaystyle{c_{2}}$ and $j:c_{2}\to c_{1} \sqcup\displaystyle{c_{2}}$ called "insertions"
such that
  • for any $d\in\mathbf{C}$ and pair of morphisms $f:c_1\to{d}$ and $g:c_2\to{d}$, there exists a unique morphism $\textstyle h:c_1\sqcup\displaystyle{c_2\to{d}}$ such that the following diagram commutes:

So the motivation for this construction was based off of the "dual" to the product, but we don't really know intuitively what this is (I mean, we want an intuition other than "it's related 'somehow' to the product"). What to do? We do what category theorists love to do in this situation: doodle!

We work in Set and set up the following problem:

We have only specified the sets $c_1,c_2,d$ and the morphisms $f$ and $g$. We want to figure out what $c_1\sqcup\displaystyle{c_{2}}$ is. We can use "universality", the fact that there is a unique morphism $h:c_1\sqcup\displaystyle{c_{2}\to{d}}$ which satisfies a commutativity property.

What can we deduce about $h$? Well, we see that since the image $g(c_2)$ is all of $d$, we need $h$ to map the image of $j(c_2)$ in $c_{1}\sqcup\displaystyle{c_{2}}$ to all of $d$. So in other words, we need at least two distinct elements in our coproduct. We can doodle at least part of what we know it could be:

On the other hand, since we also have to take into account $c_1$, we need to consider how this would affect the coproduct object. We see that all elements of $c_1$ are mapped to a single element of $d$, which implies our solution would be the following diagram:

Now what's going on? We see that since we chose a rather bad map $c_{1}\to{d}$, a constant map (it maps everything to a single element of $d$), we have a rather hard time getting an intuition about the situation, but we can still deduce something. It appears that $h$ is injective, which means that the coproduct would behave sort of like a disjoint union.

But, to play the Devil's advocate, how do we know this diagram is even the right one to describe our object $c_1\sqcup{c_2}$? Couldn't the following diagram also work:

Well, yes, this diagram also works, but it uniquely factors through our previous diagram. Or in other words, we can doodle an "intermediate step" using green:

Now, we can do this for any other guesses at what $c_{1}\sqcup{c_{2}}$ might be, which tells us that there is a unique object which all our guesses "factor" through. This unique object is precisely our $c_{1}\sqcup{c_{2}}$.

Drawing Internal Diagrams

We introduced the internal diagram, but if one wants to draw such internal diagrams in LaTeX...well, LaTeX isn't known for its powerful drawing capabilities, so it seems like we are out of luck. Right? Wrong.

We can use other software (e.g. Metapost or Asymptote) to draw them. Metapost is old-school, based off of Knuth's Metafont...except Metapost produces .eps files. Asymptote is more "new-school", modeling itself off of C++. If one is new to all of this, asymptote may be easier to learn (it wasn't for me, I prefer metapost for 2d drawing). For example, in asymptote the following code generates the diagram:

pair midpoint(pair XXX, pair YYY)
{
 real a,b;
 a = (XXX.x + YYY.x)/2;
 b = (XXX.y + YYY.y)/2;
 return (a,b);
}
//real u = 14.1732284; // the number of "size points" in 0.5 centimeters 
dotfactor=8; // changes the size of a dot
real u = 14; // (u=72)==(u=1 inch);
pair z[]; // all the points we are working with
pair c1; // select points we are making red
pair c2;

///////////////////////////////////////////////////////////////////
// this draws one "factor" of $!$P$!$
///////////////////////////////////////////////////////////////////
dot((0*u,0*u));
dot((0*u,1*u));
dot((0*u,-1*u));
draw((-1*u,0*u)..(0*u,2*u)..(1*u,0*u)..(0*u,-2*u)..cycle);
label("$!$C_{1}$!$",(0*u,-2*u),S);
c1 = (0*u,0*u);

///////////////////////////////////////////////////////////////////
// this draws the other "factor" of $!$P$!$
///////////////////////////////////////////////////////////////////
dot((13*u,0*u));
dot((14*u,0*u));
c2 = (13*u,0*u);
draw((12*u,0)..(13.5*u,1*u)..(15*u,0)..(13.5*u,-1*u)..cycle);
label("$!$C_{2}$!$",(13.5*u,-1*u),S);

///////////////////////////////////////////////////////////////////
// this draws $!$P$!$
///////////////////////////////////////////////////////////////////
label("$!$P$!$",(7*u,0),S);

///////////////////////////////////////////////////////////////////
// this draws $!$D$!$
///////////////////////////////////////////////////////////////////
label("$!$\mathbf{1}$!$",(7*u,5*u),N);
// draws $!$\<f, g\>$!$
draw((7*u,5*u)--(7*u,0*u),linetype("8 8"),EndArrow);
label("$!$\langle f,g\rangle$!$",(7*u,2.5*u),E);

///////////////////////////////////////////////////////////////////
// draw the morphisms f and g
///////////////////////////////////////////////////////////////////
z[0] =(6.5*u,5.25*u);
z[1] = c1;
//z[1] = (0*u,2*u);
draw (z[0]--z[1], EndArrow);
label("$!$f$!$", midpoint(z[0],z[1]),NW);
z[2] = (7.5*u,5.25*u);
z[3] = c2;
//z[3] = (13.5*u,1*u);
draw (z[2]--z[3], EndArrow);
label("$!$g$!$", midpoint(z[2],z[3]),NE);

///////////////////////////////////////////////////////////////////
// draw projections
///////////////////////////////////////////////////////////////////
z[4] =(6.5*u,-0.5*u);
z[5] = c1;
//z[5] =(1*u,0);
draw (z[4]--z[5], EndArrow);
label("$!$\pi_{1}$!$", midpoint(z[4],z[5]),S);
z[6] =(7.5*u,-0.5*u);
z[7] = c2;
//z[7] =(12*u,0);
draw (z[6]--z[7], EndArrow);
label("$!$\pi_{2}$!$", midpoint(z[6],z[7]),S);

/////////////////////////////////////////////////////////////////////
// Redraw the red circles
/////////////////////////////////////////////////////////////////////
dot(c2,red);
dot(c1,red);

We can translate this into a png that we can use on our blog by running on the command line (in the Ubuntu distro of Linux at least) convert -density 150 img.eps -flatten img.png which converts the file img.eps to png, the "-flatten" option makes the background white as opposed to translucent, the "-density 150" makes the png image have certain geometry (otherwise our picture ends up too small). Once we've done this, we can use our png image on our blog...huzzah!

So why did I use Asymptote for this image? Because Metapost is kind of "fudgy" with its labels, it uses TeX to translate the labels when we are "compiling" the TeX code. We can force Metapost to use Postscript fonts by making the first line of our Metapost file: prologues:=1;. It usually isn't too good in comparison to Asymptote's output, which is why I use it for blogging purposes.