% This file is part of the OWL project.
% Copyright 2014 the authors.

% ## notes:
% - Use ``star'' not ``source'' for the target of the OWL.

% ## to-do:
% - Should I include detrendings like PDC and median filtering?
% - Needs affiliations etc.
% - Finish zeroth draft.
% - Send for comments to Lupton, Carey, Wright, Brandner, Loredo
% - Who is in charge of the PanSTARRS variability field?

\documentclass[12pt, letterpaper, preprint]{aastex}

\usepackage{color,hyperref}
\definecolor{linkcolor}{rgb}{0,0,0.5}
\hypersetup{colorlinks=true,linkcolor=linkcolor,citecolor=linkcolor,
            filecolor=linkcolor,urlcolor=linkcolor}

\newcommand{\documentname}{\textsl{Article}}
\newcommand{\project}[1]{\textsl{#1}}
\newcommand{\foreign}[1]{\textsl{#1}}
\newcommand{\etal}{\foreign{et\,al.}}
\newcommand{\transpose}[1]{{#1}^{\!\mathsf T}}
\newcommand{\inverse}[1]{{#1}^{-1}}
\newcommand{\E}[1]{\mathrm{E}[{#1}]}
\newcommand{\Var}[1]{\mathrm{Var}[{#1}]}
\newcommand{\Covar}[1]{\mathrm{Covar}[{#1}]}
\input{vc}

% affils
\newcommand{\ccpp}{1}
\newcommand{\mpia}{2}
\newcommand{\contact}{3}
\newcommand{\courant}{4}

\begin{document}\sloppy\sloppypar

\title{
  Optimized ``soft'' aperture photometry for time-domain astronomy
}
\author{
  David W. Hogg\altaffilmark{\ccpp,\mpia,\contact},
  Dan Foreman-Mackey\altaffilmark{\mpia},
  Jonathan Goodman\altaffilmark{\courant}
}
\altaffiltext{\ccpp}{%
  Center for Cosmology and Particle Physics,
  Department of Physics, New York University}
\altaffiltext{\mpia}{%
  Max-Planck-Institut f\"ur Astronomie}
\altaffiltext{\contact}{%
  \texttt{david.hogg@nyu.edu}}
\altaffiltext{\courant}{%
  Courant Institute for Mathematical Sciences,
  New York University}

\begin{abstract}
Precise stellar photometry campaigns by \project{Kepler}, \project{Spitzer}, and \project{PanSTARRS}
  (among many others)
  create precise lightcurves by fixing the star in detector coordinates,
  and estimating brightness with a fixed linear combination of background-subtracted pixel values.
Under any complete set of assumptions about the noise in the detector,
  there is a particular choice of pixel weights for use in the brightness estimate
  that maximizes signal-to-noise.
When precision requirements are extremely high,
  the noise model must necessarily include pointing and point-spread-function variations,
  which introduce highly correlated noise at the pixel level.
Here we generalize previous results on optimized photometric estimators
  to include arbitrarily correlated pixels.
Amusingly, the approach we advocate does not in the end
  require any advance knowledge of any noise source;
  once there are enough epochs observed,
  the pixel-level data are sufficient to build an empirical data-driven correlated noise model.
The optimized pixel weights can be found analytically;
  when they are used to perform photometry, they work extremely well.
We demonstrate enormous improvements to the \project{Kepler} photometry of isolated stars.
The Optimized-Weight Linear (OWL) photometry produces photometric measurements so uniform that
  they outperform or obviate much more heuristic (and much more scientifically damaging)
  ``detrending'' schemes in many real cases.
In particular, OWL photometry minimizes instrument-induced variance
  but preserves all intrinsic stellar variability.
All the OWL code is available under an open-source license.
\end{abstract}

\keywords{
  instrumentation: photometers
  ---
  methods: data analysis
  ---
  methods: statistical
  ---
  techniques: photometric
}

\section{Rules of the photometry game}

Precise photometry is the bread-and-butter of the exoplanet community.
The unprecedented precision of the \project{Kepler} photometry has led to the discovery of
dozens of Earth-radius planets (HOGG CITES).
\project{Kepler}-level (part in $10^5$) precise photometry is, no doubt,
  going to be of great importance in many other areas as well.

Imagine you are trying to do very sensitive relative photometry on a variable source.
The most precise methodologies at present involve fixing the position of the source on the detector
  (cite examples)
  to reduce dependency of the results on the flat-field or flat-fielding errors.
They also often involve defocusing the telescope
  (cite examples),
  to illuminate the pixels more uniformly
  (and hence reduce intra-pixel sensitivity issues),
  avoid saturation,
  and make the observations less atmosphere-dependent.
There are also strategies related to calibration or the choices of comparison stars
  (cite examples).
Once all these choices are made,
  the choice of methodology for actually photometering the source remains.
Most projects choose something akin to aperture photometry
  (cite examples),
  in which the pixels within an aperture are co-added with unit weights,
  and pixels outside the aperture are not used at all.
Here we ask only about this last choice:
What is the best way to measure the brightness of a nearly constant source,
  given a set of precise images of the source taken over time?

FOR THE ABOVE CHECK TWITTER FOR REFS AND THANK TWEEPS.

We are going to answer this question using optimization, of course;
  we are going to find the ``best'' method.
We will assume that the investigator obeyed the usual rules,
  so he or she fixed the position of the star on the detector,
  possibly defocused the telescope,
  and avoided saturation.
However, we are also going to assume---%
  as is \emph{always the case}---%
  that there are some residual,
  unaccounted-for positional offsets (jitter) and point-spread-function changes.
These offsets and changes could be random or systematic over time,
  but we will assume that they are unknown \foreign{a priori}.
That is, the telescope house-keeping data are not good enough to track them at the level we care about.
We are trying to measure \emph{extremely} precise photometry,
  at the level of $10^{-4}$ or $10^{-5}$ or better.

The conditions we have assumed might seem strange,
  but they are generic for the most precise photometry systems currently operating.
\project{Kepler}, for instance, has all of these problems,
  as does [insert projects here, like Wright's].

It is possible to think of this problem as the problem of finding the best strategy in a single-player game.
\emph{The Rules} of this game are as follows:
\begin{itemize}
\item
  There is copious multi-epoch single-band imaging,
  with many epochs (many images),
  and a known position in that imaging of a star of great interest (the ``object'' star).
  There is also perhaps some ``pixel mask'' indicating what pixels are permitted for use
  in the vicinity of that star.
\item
  There may or may not be a list of ``comparison'' stars
  that are used to calibrate or ratio the photometry of the object star.
  If there aren't, then it can be assumed that the imaging is very well calibrated.
\item
  The imaging is background- and foreground-subtracted,
  such that the mean level of the smooth foregrounds and backgrounds in the imaging is zero.
  The background level might vary or the subtraction of it might not be perfect,
  but we can assume that it is has a mean of zero across pixels and epochs.
\item
  It is expected that the star is fairly stationary in device coordinates (pixel location).
  However, in each image it has been offset slightly by some amount from its fiducial position.
  There are no reliable meta-data to help you understand those small offsets.
  Any comparison stars are also subject to small offsets;
  the comparison-star offsets are not necessarily the same as the object-star offsets,
  because there is camera rotation, variable optical distortion, proper motion, and parallax.
\item
  It is expected that the point-spread function (PSF) is fairly constant.
  However, again, in each image it has a small difference from the fiducial point-spread function.
  There are no reliable meta-data to help with this,
  and the comparison star PSFs will also vary but not in precisely the same way,
  though their variations might be non-trivially correlated.
\item
  There are no reliable meta-data about read noise or gains,
  so there is no precise noise estimate for any pixel at any epoch.
\item
  When you photometer a star,
  the only operation you are permitted is linear weighted sums of pixels in the images.
  Furthermore, any weighted sums must be precisely identical from epoch to epoch.
  That is, the ``aperture''
  (which in fact may be some complicated set of pixel weights)
  is required to be identical from image to image.
\end{itemize}
These rules are generic;
  this is a common situation for precise, multi-epoch photometry.

The only rule to which we object is the last one:
In principle it should be better to do focal-plane modeling
  and perform photometry as a maximum-likelihood value
  or some statistics of a posterior PDF
  based on a parameterized likelihood function (for example, \citealt{hoggwhitepaper}).
However, there are many applications in which
  the physical information one would like for building such a model is not available.
We would parameterize and fit nonetheless,
  but most astronomical projects don't take this approach at present.
There are also situations in which the output of full likelihood fitting for the data
  shows correlations between the final photometry and nuisance parameters (such as PSF parameters).
In these cases, the investigator is left wondering if the residual photometric variance
  has contributions from nuisance-parameter variance or fit residuals or model mismatch.

There have been some previous attempts to optimize photometric estimators subject to \emph{The Rules},
  in generic (but limiting) situations.
When the pointing and point-spread function are both known precisely,
  the pixel noise variance is known for every pixel,
  and the pixel noise is independent (uncorrelated) pixel-to-pixel,
  there are simple analytic results (\citealt{naylor}).
These results reduce to the psf-as-matched-filter standard practice
  in the further simplification of sky-dominated noise.
There are no previous results (to our knowledge) that take account of
  the highly covariant noise created by variable pointing or optics.
This is the first primary novelty of this work.
The second primary novelty is the realization that the noise---%
  even the covariant part created by optics and pointing---%
  can be determined empirically from the data themselves,
  with no prior knowledge of the characteristics of the detector,
  telescope, or atmosphere.

\section{Well-calibrated data}

In the (possibly fantastical) situation in which the imaging data are all properly calibrated,
  we have no need for comparison stars.
We are going do the photometry using nothing but the pixels near the object star.

Before we say what ``properly calibrated'' means,
  it is necessary to specify what we mean by an ``image''.
Ordinarily it is our view that
  an image is a measurement of the smoothed intensity field
  or smoothed photon phase-space density.
It ought to have units of energy per time per area per solid angle
  or photons per time per area per solid angle.
The problem with this view of an image
  is that if we do aperture photometry---%
  that is, if we make linear weighted sums of image pixels---%
  to get a total stellar flux,
  the weights in the weighted sum must have units of \emph{solid angle}.
Small changes to the optics or atmosphere will change the astrometric mapping of the camera,
  changing the solid angles of the pixels.
Aperture photometry is the wrong thing to do in this formulation of an image;
  or it is an okay thing to do if the weights are permitted to vary with the astrometric distortion.
That would violate \emph{The Rules} above.

So the image we want for these purposes is not a measurement of the intensity field,
  but rather a kind of ``flux map''.
It ought to have units of energy per time per area
  or photons per time per area.
These values can be co-added with dimensionless weights to deliver a stellar flux.
The only difference between an intensity image and a flux map is a factor of
  the angular size of the pixels.
In many imagers pixels are similar in size so these differences aren't apparent.
However, at the levels of precision we care about here
  ($10^{-4}$ or $10^{-5}$ or better)
  these details matter.

What is meant by ``properly calibrated''?
The image (flux map) is properly calibrated when it is can be treated as a measurement of---%
  or is directly proportional to---%
  a smoothed map of energy or photon number per time per area.
It is ``smoothed'' because it is convolved (or correlated) with some finite
  and possibly spatially varying PSF
  (which we don't know).

Are any imaging data properly calibrated according to these criteria?
We don't know, but the \project{Kepler} Satellite may be.
The standard data products of the \project{Hubble Space Telescope}
  are given in intensity units,
  but the astrometric solution is known to high precision,
  so (with a tiny bit of work)
  these also can be properly calibrated for aperture photometry according to this definition.

We do not endorse the view that images should be presented as flux maps!
We are just sayin' that \emph{if} you need to obey \emph{The Rules},
  then you need to convert your intensity maps into flux maps before playing the game.

\section{Optimized photometry}

We have at each of $N$ epochs $n$ a set of $D$ pixels in a small patch
  that contains a star.
The set of measured, properly calibrated (see above),
  correctly background-subtracted (see above)
  pixel values at epoch $n$ form a $D$-dimensional column vector $y_n$.
According to \emph{The Rules}, all we are permitted to do at epoch $n$
  is produce a weighted sum
\begin{eqnarray}
q_n &\leftarrow& \transpose{w}\, y_n
\quad ,
\end{eqnarray}
  where $q_n$ is a scalar photometric measurement,
  $w$ is a $D$-dimensional column vector of weights,
  and (because of the transpose)
  the product is effectively an inner (scalar or dot) product.
\emph{The Rules} state that the weight vector $w$ must not depend on $n$ or anything else;
  the weights are the same at every epoch.

We can see $q_n$ as an estimator---a point estimate---of the stellar brightness.
If we knew the expectation value (mean) for the pixel data $y_n$ and also the
  variance of those data around the mean,
  we could predict the expectation and variance of the estimator.
The expectation value would be:
\begin{eqnarray}
\E{q_n} &=& \transpose{w}\, \mu_n
\\
\mu_n &\equiv& \E{y_n}
\\
\Var{q_n} &=& \transpose{w}\, C_n\, w
\\
C_n &\equiv& \Covar{y_n}
\quad ,
\end{eqnarray}
  where $\E{x}$ is the expectation value of $x$,
  $\Var{x}$ is the variance of (a scalar) $x$ around its expectation value,
  and $\Covar{x}$ is the $D\times D$ symmetric, positive definite covariance matrix
  of (a vector) $x$ around its expectation value.
In the simple case of independent noise from pixel-to-pixel,
  $\Covar{y_n}$ becomes diagonal,
  and the variance $\Var{q_n}$ becomes simply the sum of the diagonal variances,
  weighted by the squared weights.
The expected squared signal-to-noise ratio $\Sigma^2$ for $q_n$ is
\begin{eqnarray}
\Sigma^2 &=& \frac{[\transpose{w}\, \mu_n]^2}{\transpose{w}\, C_n\, w}
\quad .
\end{eqnarray}

It is almost always assumed that the pixel-to-pixel noise is independent (diagonal);
  why do we not assume this here?
The answer lies in \emph{The Rules}:
Variations of the pointing and point-spread function (and background),
  which are all unknown,
  correlate the pixels.
That is, they produce a kind of noise that is neither photon nor read noise in the detector.
They produce a jitter noise that leads to covariant variations of the individual pixel values.

We win the game if we find the weight vector $w$ that optimizes signal-to-noise.
It can't optimize the signal-to-noise at epoch $n$;
  it must optimize the mean or typical signal-to-noise across epochs.
That is, we want to find the weight vector $w$ that optimizes
\begin{eqnarray}
  \Sigma^2 &=& \frac{[\transpose{w}\, \mu]^2}{\transpose{w}\, C\, w}
  \quad ,
\end{eqnarray}
where now $\mu$ is the expectation value of the data vectors $y_n$ but now over \emph{all} epochs,
  and $C$ is the covariance matrix for the data but again over \emph{all} epochs.
The signal-to-noise-optimized weight vector is simply
\begin{eqnarray}
  w &\leftarrow& \inverse{C}\, \mu
  \quad ,
\end{eqnarray}
  where the inverse operation is the full matrix inverse.
This optimized-weight result is the natural generalization to correlated noise
  of the equivalent result (for independent pixel noise)
  obtained previously (\citealt{naylor}).

Previous work has called these weights ``optimal'' but they are only really ``optimized''.
For one, the word ``optimal'' always begs the question ``with respect to what?''
For another, we reserve the word ``optimal'' for estimators
  that have some glimmer of hope of saturating the Cram\'er--Rao bound (CITE).
The optimized estimators presented here will not do this in general
  (and nor will those of \citealt{naylor}),
  because they are not based on any reasonable likelihood function.

By assumption, we don't know the point-spread function,
  nor the noise model,
  nor the pointing or PSF jitter.
Therefore, we can't compute $\mu$ and $C$ from first principles; we have to estimate them.
Fortunately, we have $N$ epochs of data;
  we can compute a (suitably robustly estimated)
  \emph{empirical} mean $\hat{\mu}$ and \emph{empirical} covariance $\hat{C}$
  of the original data vectors $y_n$.
That is, we will do something like
\begin{eqnarray}
  \hat{\mu} &\leftarrow& \frac{1}{N}\,\sum_{n=1}^N y_n
  \\
  \hat{C} &\leftarrow& \frac{1}{N-1}\,\sum_{n=1}^N [y_n - \hat{\mu}]\,\transpose{[y_n - \hat{\mu}]}
  \\
  \hat{\Sigma}^2 &=& \frac{[\transpose{w}\, \hat{\mu}]^2}{\transpose{w}\, \hat{C}\, w}
  \\
  \hat{w} &\leftarrow& \inverse{\hat{C}}\, \hat{\mu}
  \quad ,
\end{eqnarray}
  where the operations are averages over the epochs,
  the vector product is the outer or tensor product,
  $\hat{\Sigma}^2$ is the \emph{empirical} signal-to-noise,
  and $\hat{w}$ are the weights that maximize it.
Technically we require $N \gg D$
  (far more epochs than there are pixels in the tiny patch).
It turns out that with small modifications
  (to make the means robust to outliers)
  this works well, at least for \project{Kepler} data (see below).
The Optimized-Weight Linear (OWL) photometry $q_n$ is then
\begin{eqnarray}
  q_n &\leftarrow& \transpose{\hat{w}}\, y_n
  \quad ,
\end{eqnarray}
  that is, one scalar $q_n$ per epoch $n$, obtained by a weighted sum of the $y_n$.
We have not just obeyed \emph{The Rules},
  we have come up with the best possible strategy in terms of empirical signal-to-noise.

There is one overall scale that is free;
  any scalar multiple of the weight vector $\hat{w}$ is identical in signal-to-noise
  to any other scalar multiple.
In practice it doesn't matter how we choose this unless either machine precision is an issue,
  or else some kind of absolute aspects of photometry are required.

\section{\project{Kepler} data}

For each star in the Kepler data (identified by a KIC number),
  there is a small patch of telemetered pixels,
  and some 4000 epochs per quarter and up to 17 quarters of data.
The patch of pixels has an associated mask,
  which indicates both which pixels are good data,
  and also which were summed to make the official pipeline
  Simple Aperture Photometry (SAP).
The weights used to generate the SAP photometry are constant within a quarter,
  and all snapped to either zero or unity.
\figurename~\ref{fig:pixels} shows time histories for the $D=19$ pixels relevant
  to KIC~3335426 from the fifth quarter in which it was observed.
Also shown are the three pixels that got unit weight in the SAP photometry for this star.

The \project{Kepler} data are extremely good, but there are some outliers,
  presumably from cosmic rays.
We want to compute empirical means and covariances that are not overly drawn by these outliers.
We compute the empirical statistics with an iterated sigma-clipping.
In each iteration, we censor (remove from the sum)
  any datum $y_n$ that is more than a ``4 sigma'' outlier
  given the empirical mean $\hat{\mu}$ and covariance $\hat{C}$ computed in the previous iteration.
To determine the 4-sigma criterion, we use the Gaussian approximation to the chi-squared distribution
  with the appropriate number of degrees of freedom.
We iterate this sigma-clipping through five iterations,
  which in practice seems to lead to convergence.
Importantly, we sigma-clip at the epoch level, not the pixel level.

\figurename~\ref{fig:images} shows the robustly estimated empirical mean image $\hat{\mu}$,
  the diagonal elements of the empirical covariance matrix $\hat{C}$,
  the top eigenvector of the covariance matrix,
  and the OWL weights, along with the weights used by the \project{Kepler} pipeline,
  and a few data examples.
We resolved the overall scale degeneracy for the weights (see above)
  by requiring that the OWL and SAP photometry produce identical median flux.
The optimized weight vector shown in \figurename~\ref{fig:images} might seem counterintuitive;
  it puts substantial weight off the peak of the mean intensity.
The fundamental reason is that the weight vector is trying to get as orthogonal as possible
  to the high-variance eigenvectors of the variance tensor.
In the end, the highest-weight pixels do not all deliver significant signal;
  in \figurename~\ref{fig:images} we also show
  the pixel-wise product of the OWL weights with the empirical mean values,
  which gives a sense of where the bulk of the photometric signal is coming from.

\figurename~\ref{fig:results} shows the \project{Kepler} SAP flux for KIC~3335426,
  along with the OWL and some variants thereof (described below).
The OWL photometry very effectively  detrends the data,
  even though it involves \emph{no explicit detrending}.
By ``detrending'' we mean filtering or fitting-and-subtracting
  the SAP photometry (as in the \project{Kepler} PDC or median-filtered photometry).
Detrendings remove intrinsic stellar variability and create artificial epoch-to-epoch correlations
  in the photometric noise;
  they are the bane of exoplaneteers.
That is, the OWL is just a soft-aperture aperture photometry, identical from epoch to epoch
  that obviates detrending.
It is simply the weighting of the pixels that optimizes the empirical output signal-to-noise.

In detail, this first shot at OWL photometry is a tiny bit noisier
  in an epoch-to-epoch sense
  than the SAP photometry,
  despite being far better in its overall trend.
This is coming from the fact that the OWL weights are trying to suppress the dominant
  sources of variance,
  which are entering the data on long time-scales.
The focus on the biggest variance components limits what the OWL can do.
This opens up the next area of discussion:
How do we estimate the covariance matrix $\hat{C}$ so that it is dominated by the sources of variance
  that we most want to suppress?

\section{Estimation of the covariance tensor}

HOGG:
Something about what is really happening (trying to zero out dominant eigenvectors).

HOGG:
Something about the lack of prior knowledge:
\begin{itemize}
\item
We aren't assuming \emph{anything} about the sources of variance.
\item
We aren't doing \emph{anything} about intrinsic variability of the source.
\item
Some intrinsic variability we do care about, some we don't.
\item
We aren't using the time-ordering of the data at all;
  different effects happen on different time scales.
\end{itemize}
All these issues turn into decisions or knobs that we can turn in variations.
The variations will fall into two categories:
We can change how we estimate the covariance matrix $C$,
  or we can change how we constrain or regularize the weights $w$.

HOGG:
On the covariance estimation, here are some basic ideas:
\begin{itemize}
\item
Use local differences of pixel values instead of pixel values.
\item
Mix the dominant eigenvectors from the full set of pixel values
  with the small-scale noise inferred from the local differences.
\item
Perform some kind of factor analysis that splits the variance into
  ``diagonal'' and ``covariant'' parts.
\item
Use covariances across pixel patches from different stars
  to identify extrinsic (rather than intrinsic)
  sources of variances.
\end{itemize}

HOGG:
\begin{eqnarray}
\hat{C}_S & \leftarrow & \frac{1}{N-1}\,\sum_{n=1}^N [y_n - \hat{\mu}]_\perp\,\transpose{[y_n - \hat{\mu}]}_\perp
\\
x_\perp & \equiv & x - \sum_{k=1}^K u_k\,\transpose{u}_k\,x
\\
\delta_{kk'} &=& \transpose{u}_k\,u_{k'}
\quad ,
\end{eqnarray}
where $S$ is a subspace of the full $D$-dimensional pixel space,
  the $\perp$ subscripts indicate that the vectors have been projected into the subspace $S$,
  the $u_k$ vectors are orthonormal unit vectors that span the complement of subspace $S$,
  and $\delta_{kk'}$ is the integer (index) delta function.

%% HOGG:
%% In yet another variation, we estimated $\hat{\mu}$ and $\hat{C}$ using not the
%%   straight-up data, but the \emph{differences} between each data point and
%%   its time-ordered neighbor.
%% Again with the sigma clipping.
%% This leads to the DOWL, DOPW, and DTSA, shown in \figurename~\ref{fig:dresults}.

\section{Regularization of the weight vector}

It is also the case, in the above, that
  we aren't putting in any prior knowledge about what the $w$ image ought to look like
  in sane cases.
On the weight constraints and regularization, here are some basic ideas:
\begin{itemize}
\item
Require non-negativity.
\item
Require smoothness.
\item
Require similarity to the SAP aperture or some other sensible aperture.
\item
Require that the aperture be a circular top-hat or a smoothed version of that.
\end{itemize}

After running the OWL on multiple \project{Kepler} targets,
  we developed a few intuitions that led to variations.
In one, we constrain the weights to be positive;
  this protects against the optimizer finding locations in weight-space
  that perform subtractions of large numbers to reduce variance.
This problem arises most strongly when the star being photometerd is intrisically variable
  with a large amplitude:
In these cases, the largest variance can be from the star itself;
  the OWL tries to find weights that cancel out the target star!

The Optimized Positive-Weight (OPW) photometry works still at the optimum of
\begin{eqnarray}
\hat{\Sigma}^2 &=& \frac{[\transpose{w}\, \hat{\mu}]^2}{\transpose{w}\, \hat{C}\, w}
\quad ,
\end{eqnarray}
but now subject to the constraint that every element of $w$ must be non-negative.
\figurename~\ref{fig:images_opw} and \figurename~\ref{fig:results}
 show the results of the OPW for KIC~3335426,
 and \figurename~\ref{fig:results_variable} show the results of the OPW
 for a more variable star.
The positivity constraint seems salutory when the target star is somewhat variable.

In another variation, we looked at stars that saturate the \project{Kepler} detectors.
These stars show bleed trails along the CCD columns,
  although the \project{Kepler} gains have been set cleverly
  to ensure that precise photometry of these saturated stars is nonetheless possible with SAP photometry.
In the case of saturated stars, the OWL and OPW photometry do not work well
  because the saturation leads to some pixels being exceedingly constant,
  even if the source is intrinsically moving or varying.
That is, the saturated pixels do not show much empirical variance,
  and get overly large weight in the optimization.

For these saturated cases we devised a Tweaked Simple Aperture (TSA) photometry,
  which capitalizes on the clever apertures chosen by the \project{Kepler} team
  to capture saturated signal:
In the TSA, we lump together the SAP-coadded pixels into a single super-pixel.
We then perform the OWL methodology,
  but now with the list of pixels not being the full list of pixels,
  but rather the super-pixel plus the list of all the non-SAP pixels in the patch.
The TSA is a generalization of the OWL to non-square or non-uniform pixels.

We show the TSA results in \figurename~\ref{fig:results}.
It seems to be producing better epoch-to-epoch scatter;
  this might because it represents an even stronger regularization of the weight image $\hat{w}$.

HOGG:
In yet another variation, we fix the aperture to be a circular top-hat,
  and only permit its center and radius to be adjusted in the optimization...

NOTE TO JASON WRIGHT: WE CAN HELP YOU!

\section{Comparison stars}

HOGG:  GIVE THE SETUP

HOGG:  You can operate the OWL for all $K$ stars.
Then scale each star so it predicts as well as possible the object star.
Then take robust means or medians of the $K$ predictors and divide them out.

HOGG:  Or you can use all of the pixels in all the patches around all $K$ stars
  to build a predictive model for the pixels in the object star's patch.
This permits creation of a very stable data-driven calibration of the data.
We are pursuing this in a separate project;
  it is not even close to being ready for prime time.

\section{Discussion}

What happened?
We permitted the aperture to be soft.
We optimized the aperture weighting.
We obviated detrending forever.

In the results shown in \figurename~\ref{fig:results},
  the instrumental effects on the lightcurve were removed beautifully by the OWL,
  but in detail
  the adjacent epoch-to-epoch noise was inflated a tiny bit;
  why?
The OWL knows nothing about time ordering of the data;
  it makes no distinctions between slow and fast variations;
  it is just trying to maximize signal-to-noise.
Slow variations like those shown in \figurename~\ref{fig:results}
  are just another source of total variance.
If a user knows a lot about what timescales are relevant,
  the OWL can be improved enormously.
To demonstrate, we ran an experiment in which we filtered the \project{Kepler} pixel-level data
  for KIC~XXXX in quarter XXXX
  with a 48-hour median filter to remove the long-timescale variability.
We subtracted the median filter output from each pixel lightcurve and added back in the mean.
The pixel lightcurves are shown in \figurename~\ref{fig:pixels_filter}
  and the output of the OWL photometry is shown in \figurename~\ref{fig:results_filter}.
Because the pixels were partially ``detrended'' by this process,
  the OWL weights are not putting as much effort into removing the large-scale trends.

This kind of detrending is common in the exoplanet community;
  it has been valuable for finding exoplanets.
It brings many disadvantages;
  one is that any detrending method that happens prior to exoplanet search
  distorts the transit shapes and depths.
Another is that it removes stellar variability that might be of intrinsic interest.
Another is that it correlates data that are close in time;
  it creates non-trivial noise for lightcurve fitting.
The OWL photometry---in its standard form shown in \figurename~\ref{fig:results}---%
  produces independent photometry at every epoch
  and preserves transit shapes and all intrinsic stellar variability.

In the end, a forward-modeling approach ought to win.
It won't obey \emph{The Rules}, but it is the only approach that has a chance
  of saturating the Cram\'er--Rao bound.
The forward-modeling approach is not trivial, however,
  because the usual methods of image modeling,
  which make use of simple models for the flat-field, point-spread function,
  and the ``scene''
  have (in general) model mismatch issues that project residuals
  in the calibration parameters onto the photometry of greatest interest.
That is, a forward-modeling approach that obtains photometry at the same
  precision as the OWL would be expensive and complex.
Still, it is the \emph{Right Thing To Do (tm)} and thus the One True Path for the future.
One way to see this is to note that there is no obvious or simple generalization of the OWL
  to the case of multi-instrument or multi-band imaging
  (where pixel scale or bandpass vary from epoch to epoch).

The OWL, OPW, and TSA methods all depend very strongly on good background subtraction.
The reason is that it seeks to obtain high expectation value and low variance.
If there is a constant background that hasn't been subtracted,
  the weights will choose to add in a lot of constant background
  and possibly down-weight the pixels being hit by the variable object star.
The main requirement is that the background has been subtracted such
  that the mean background level in all pixels at all epochs is negligible.
The background subtraction can be noisy and variable,
  but it must be accurate in the mean.

On a related note, the image patch under consideration ought not be \emph{far}
  bigger than the region over which a normal would perform photometry.
For example, if the number of pixels in the object-star image patch becomes
  much larger than the number of epochs,
  the OWL will be able to find linear combinations of pixels that have
  more-or-less perfectly constant flux.
This over-fitting issue is not a problem in what's shown above,
  but could start to become a problem if large patches get used,
  and would be exacerbated in the presence of non-zero mean background subtraction residuals.
This deserves further study.

The biggest (in our view) limitation of the OWL is that it cannot be used
  to accurately measure the properties of stars
  that are close enough that their point-spread functions overlap,
  or stars in crowded fields.
The issue is that the optimization procedure has no knowledge or understanding
  of the PSF or even of the fact that it is a star being observed.
In our view, the only justifiable solution to this problem is forward modeling,
  in which there are parameterized beliefs about the PSF and the scene,
  and in which the output photometry comes from analysis of a likelihood function.
The only conceivable generalizations of the OWL that might be relevant would either
  \textsl{(a)}~involve taking the optimum subject to the constraint that the weights must be
  orthogonal to some estimate of the overlapping star point-spread functions, or else
  \textsl{(b)}~require modeling and subtraction of the confusing source or sources
  in the field.
These are interesting ideas,
  but probably no easier or more reliable than full forward modeling.
Although we consider this non-isolated problem to be the most severe limitation of what we are doing,
  we note that the tremendous discoveries and measurements of the \project{Kepler} mission
  have almost all been generated with straight-up aperture photometry,
  followed by \foreign{ex post facto} checks for blending.
There certainly is a great deal that can be done in the isolated-star limit.

All of the code used in this project is available
  from \url{http://github.com/davidwhogg/OWL/} (or forks thereof)
  under the MIT open-source software license.
This code (plus some dependencies) can be run
  to re-generate all of the figures and results in this \documentname;
  this version of the paper was generated with git hash
  \texttt{\githash} (\gitdate).

\acknowledgments
It is a pleasure to thank
  Ruth Angus (Oxford),
  Morgan Fouesneau (MPIA),
  Fengji Hou (NYU),
  Christian Knigge (Southampton),
  Molei Tao (NYU), and
  Jason Wright (PSU)
for valuable comments and suggestions.
This work was partially supported by the Moore--Sloan Data Science Environment at NYU,
  by NASA (grant NNX08AJ48G).
  and by the NSF (grant AST-0908357).
This research made use of the \project{NASA Astrophysics Data System}.

\newcommand{\arxiv}[1]{\href{http://arxiv.org/abs/#1}{arXiv:#1}}
\begin{thebibliography}{}\raggedright
\bibitem[Hogg \etal(2013)]{hoggwhitepaper}
Hogg, D.~W., Angus, R., Barclay, T., et al.\ 2013,
Maximizing Kepler science return per telemetered pixel: Detailed models of the focal plane in the two-wheel era,
\arxiv{1309.0653}
\bibitem[Naylor(1998)]{naylor}
Naylor, T.\ 1998,
An optimal extraction algorithm for imaging photometry,
\mnras, 296, 339
\end{thebibliography}

\clearpage
\begin{figure}
\includegraphics[width=\textwidth]{../py/kic_03335426_05_pixels.png}
\caption{
The ``lightcurves'' (flux \foreign{vs} time) for 19 pixels near...HOGG
\label{fig:pixels}}
\end{figure}

\clearpage
\begin{figure}
\includegraphics[width=\textwidth]{../py/kic_03335426_05_images_owl.png}
\caption{
The top row shows example image patches (data $y_n$) from the \project{Kepler} data on KIC XXXX in quarter XXXX.
The middle row shows the empirical mean image $\hat{\mu}$,
  the diagonal elements of the empirical covariance matrix $\hat{C}$,
  and its dominant eigenvector.
The bottom row shows the pixel weights used in the official \project{Kepler} SAP photometry,
  and the OWL weights $\hat{w}$.
The bottom-right panels shows the OWL weights times the empirical mean;
  this shows the mean contributions of the individual pixels to the final OWL photometry.
\label{fig:images}}
\end{figure}

\clearpage
\begin{figure}
\includegraphics[width=\textwidth]{../py/kic_03335426_05_images_opw.png}
\caption{
The same as the bottom row of \figurename~\ref{fig:images}
  but for the optimized positive-weight (OPW) photometry.
In this case, the positivity constraint does not make much difference.
\label{fig:images_opw}}
\end{figure}

\clearpage
\begin{figure}
\includegraphics[width=\textwidth]{../py/kic_03335426_05_photometry.png}
\caption{
The \project{Kepler} SAP flux,
  the Optimized-Weight Linear (OWL) photometry,
  the Optimized Positive-Weight (OPW) photometry,
  and the Tweaked Simple Aperture (TSA) photometry,
  all for quarter 5 of KIC~3335426.
\label{fig:results}}
\end{figure}

\clearpage
\begin{figure}
\includegraphics[width=\textwidth]{../py/kic_03335426_05_diff_photometry.png}
\caption{
The \project{Kepler} SAP flux,
  the Difference-Optimized-Weight Linear (DOWL) photometry,
  the Difference-Optimized Positive-Weight (DOPW) photometry,
  and the Difference-Tweaked Simple Aperture (DTSA) photometry,
  all for quarter 5 of KIC~3335426.
\label{fig:dresults}}
\end{figure}

\end{document}


\section{Theorem proving using Isabelle}
\label{sec:background:theorem_proving_using_isabelle}

As mentioned before in \cref{sec:introduction:validation} all formal proofs within this paper are verified within a theorem prover, sometimes also called a proof assistant. A theorem prover is a software solution to assist with the task of proving mathematical theorems. It achieves this goal by using automated reasoning and mathematical logic to provide the user with information on the correctness of the written proof. Furthermore, a theorem prover might have tools to prove simple theorems automatically.

In this thesis, the Isabelle proof assistant is used to prove the relevant theorems. Isabelle was chosen as theorem prover for several reasons:
\begin{itemize}
    \item Isabelle stays close to mathematical definitions while still maintaining much automation in the process, which is different from other theorem provers. A comparison of theorem provers has shown that most other theorem provers which stay close to the mathematical definition do not have much automation, and vice versa \cite{wiedijk_comparing-provers}.
    \item Isabelle provides a plug-in to jEdit, a text editor, which deeply integrated Isabelle into the jEdit editor. This integration allows for interactively creating theories and checking proofs without the need to use the command-line application for this purpose.
    \item Isabelle has its own proof language Isar, which makes proofs more readable to the human reader, without giving up on automation and functionality for delivering proofs.
    \item One of the supervisors of this thesis has experience with Isabelle, meaning that there is local expertise available in case of problems.
\end{itemize}

The remaining part of this section will discuss different parts of Isabelle and its proof language Isar, to provide some background on theorem proofing in Isabelle.

\subsection{About Isabelle}
\label{subsec:background:theorem_proving_using_isabelle:about_isabelle}
Isabelle \cite{isabelle_2019} is a generic theorem prover written in \textsc{ML}. It was originally developed at the University of Cambridge and Technische Universität München, but now includes numerous contributions from institutions and individuals worldwide. It has been designed to be able to support reasoning in several object-logics, which include but are not limited to:
\begin{itemize}
    \item first-order logic, constructive and classical versions (Isabelle/FOL)
    \item higher-order logic (Isabelle/HOL)
    \item Zermelo-Fraenkel set theory (Isabelle/ZF)
\end{itemize}
Isabelle is distributed for free under a mix of open-source licenses, but the main code-base is subject to BSD-style regulations. More specifically, the binary distributions of Isabelle come with the 3-Clause BSD License \cite{bsd3clause}.

Isabelle has quite a large user base and a well-maintained community. Besides a mailing list for users, there is also a wiki \cite{isabelle_wiki} and active support on StackOverflow, when questions are tagged under `isabelle' \cite{isabelle_stack_overflow}.

The first release of Isabelle is published in 1986. Nowadays, it receives yearly releases with new updates. At the time of writing, Isabelle 2019 is the newest release, which is also the release used to prove the theorems in this thesis.

\subsection{Basics}
\label{subsec:background:theorem_proving_using_isabelle:basics}
This section will discuss some basics on Isabelle that are relevant for this thesis. The constructs mentioned here will not be discussed in much detail, as that would be a thesis on its own. The documentation provided with Isabelle does a decent job explaining all constructs in as much detail as possible.

\subsubsection{Theories}
Each document in Isabelle is a \textit{theory}, which can define a set of definitions, theorems and proofs. A theory can import other theories in order to reuse its definitions, theorems and proofs. An example of a theory is given in \cref{appendix:example_isabelle_theory}. This theory is the actual formalisation of \cref{defin:formalisations:global_definitions:multiplicity} in Isabelle used for this thesis. It will be used as an example throughout the remaining parts of this section.

\subsubsection{Datatypes}
Within an Isabelle theory, it is possible to define inductive datatypes. Inductive datatypes are the most used way to define new types in Isabelle. Famous data structures, such as lists, can be defined using datatypes.

The example provided in \cref{appendix:example_isabelle_theory} defines a new datatype for the set $\mathbb{N} \cup {\mstar}$. The definition is specified within the theory as:
\vspace{1em}\begin{isabellebody}
\isacommand{datatype}\isamarkupfalse%
\ {\isasymM}\ {\isacharequal}\ Star\ {\isacharbar}\ Nr\ nat\isanewline
\end{isabellebody}

This example defines a datatype called \isasymM{}, which can have two values: $Star$ and $Nr$. $Star$ and $Nr$ are called datatype constructors and can get arguments of different types. For example, the $Nr$ value gets an additional type, $nat$, which is Isabelle's type for representing natural numbers. On the other hand, the $Star$ constructor gets no additional arguments and is just a value for \isasymM{} on itself.

The formalisation achieved here should be straightforward. $Star$ is used to denote $\mstar$, the unbounded value, while $Nr\ nat$ is used to denote a bounded value for a multiplicity.

\subsubsection{Record types}
Another way of defining new types within Isabelle is by using record types. A record can be defined using the \textbf{record} keyword. The concept of a record is borrowed from programming languages, but it provides a way to define a named \textit{n}-tuple. Effectively, a record type is a type consisting of multiple named fields that can each have a different type. Each field of a record can be accessed using its name.

Within this thesis, records are actively used to introduce types for type models, type graphs, instance models and instance graphs. These are all named-tuples which are easiest defined using records. Sadly, the example provided in \cref{appendix:example_isabelle_theory} does not define such a record, therefore, we provide the record of an instance model (\cref{defin:formalisations:ecore_formalisation:instance_models:instance_model}) here:

\vspace{1em}\begin{isabellebody}
\isacommand{record}\isamarkupfalse%
\ {\isacharparenleft}{\isacharprime}o{\isacharcomma}\ {\isacharprime}nt{\isacharparenright}\ instance{\isacharunderscore}model\ {\isacharequal}\isanewline
\ \ Tm\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharparenleft}{\isacharprime}nt{\isacharparenright}\ type{\isacharunderscore}model{\isachardoublequoteclose}\isanewline
\ \ Object\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}o\ set{\isachardoublequoteclose}\isanewline
\ \ ObjectClass\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}o\ {\isasymRightarrow}\ {\isacharprime}nt\ Id{\isachardoublequoteclose}\isanewline
\ \ ObjectId\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}o\ {\isasymRightarrow}\ {\isacharprime}nt{\isachardoublequoteclose}\isanewline
\ \ FieldValue\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharparenleft}{\isacharprime}o\ {\isasymtimes}\ {\isacharparenleft}{\isacharprime}nt\ Id\ {\isasymtimes}\ {\isacharprime}nt{\isacharparenright}{\isacharparenright}\ {\isasymRightarrow}\ {\isacharparenleft}{\isacharprime}o{\isacharcomma}\ {\isacharprime}nt{\isacharparenright}\ ValueDef{\isachardoublequoteclose}\isanewline
\ \ DefaultValue\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}nt\ Id\ {\isasymRightarrow}\ {\isacharparenleft}{\isacharprime}o{\isacharcomma}\ {\isacharprime}nt{\isacharparenright}\ ValueDef{\isachardoublequoteclose}%
\end{isabellebody}

The record of an instance model directly shows the structure. It has 6 named fields, the corresponding type model and the 5 elements defined in \cref{defin:formalisations:ecore_formalisation:instance_models:instance_model}. Each of these fields has a corresponding type, corresponding to the type described within the definition of an instance model. This way, we have a direct formalisation of an instance graph in Isabelle.

\subsubsection{Type synonyms}
Isabelle can form new types out of existing types by using generic types. For example, \textit{list}s in Isabelle use this functionality. A list was created using a generic type that can be replaced with any concrete type on usage. For example `$nat\ list$' would represent a list of natural numbers, and `\isasymM$\ list$' a list of elements of datatype \isasymM.

To make it more convenient to use these types, it is possible to define these composed types as a type synonym. An example of such a type synonym is given in \cref{appendix:example_isabelle_theory}:

\vspace{1em}\begin{isabellebody}
\isacommand{type{\isacharunderscore}synonym}\isamarkupfalse%
\ multiplicity\ {\isacharequal}\ {\isachardoublequoteopen}{\isasymM}\ {\isasymtimes}\ {\isasymM}{\isachardoublequoteclose}
\end{isabellebody}

This type synonym defines the multiplicity type, effectively the formalisation of $\mathbb{M}$ from \cref{defin:formalisations:global_definitions:multiplicity}. It is a tuple of two elements of datatype \isasymM, thus a tuple $\mathbb{N} \cup \{\mstar\} \times \mathbb{N} \cup \{\mstar\}$. Using this type synonym, it is now possible to refer to the multiplicity type as `multiplicity'.

\subsubsection{Definitions and functions}
In an Isabelle theory, multiple definitions can be provided. The most basic definition can be created using the \textbf{definition} keyword. Effectively, a \textbf{definition} is simply an abbreviation, i.e. a new name for an existing construction.

An example of such a definition is the $upper$ definition in \cref{appendix:example_isabelle_theory}:
\vspace{1em}\begin{isabellebody}
\isacommand{definition}\isamarkupfalse%
\ upper\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}multiplicity\ {\isasymRightarrow}\ {\isasymM}{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
\ \ {\isachardoublequoteopen}upper\ m\ {\isasymequiv}\ snd\ m{\isachardoublequoteclose}
\end{isabellebody}

As can be seen, the upper definition receives one argument $m$ of type `multiplicity', a multiplicity-tuple. It returns the upper bound of the multiplicity. In other words, it returns the second element of the tuple. This behaviour matches what the definition tells us, as $snd$ is the Isabelle function to return the second element of a tuple.

Besides the \textbf{definition} keyword, it is possible to give recursive function definitions using the \textbf{fun} and \textbf{function} keywords. An example of this is given as part of the linear order of \isasymM{} in \cref{appendix:example_isabelle_theory}:
\vspace{1em}\begin{isabellebody}
\isacommand{fun}\isamarkupfalse%
\ less{\isacharunderscore}eq{\isacharunderscore}{\isasymM}\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isasymM}\ {\isasymRightarrow}\ {\isasymM}\ {\isasymRightarrow}\ bool{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
{\isachardoublequoteopen}less{\isacharunderscore}eq{\isacharunderscore}{\isasymM}\ {\isacharunderscore}\ \isactrlemph \ {\isacharequal}\ True{\isachardoublequoteclose}\ {\isacharbar}\isanewline
{\isachardoublequoteopen}less{\isacharunderscore}eq{\isacharunderscore}{\isasymM}\ {\isacharparenleft}\isactrlbold a{\isacharparenright}\ {\isacharparenleft}\isactrlbold b{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}a\ {\isasymle}\ b{\isacharparenright}{\isachardoublequoteclose}\ {\isacharbar}\ \isanewline
{\isachardoublequoteopen}less{\isacharunderscore}eq{\isacharunderscore}{\isasymM}\ {\isacharunderscore}\ {\isacharunderscore}\ {\isacharequal}\ False{\isachardoublequoteclose}
\end{isabellebody}

The function defined here, `less-eq-\isasymM', defines the less than or equal to ($\leq$) relation for \isasymM. Effectively, the function describes that any value is always smaller or equal to $\mstar$ and that two numbers (two instances of $Nr$) are only less or equal when the first number is less or equal to the second number.

The same function could also have been defined using the \textbf{function} keyword, with the only difference that for the \textbf{function} keyword, a proof for termination of the function must be provided manually. Using the \textbf{fun} keyword, Isabelle will try to automatically proof termination of the function by using the specification. This automation is very powerful and works in a variety of functions (in fact, for all functions defined in this thesis, termination is proven automatically using \textbf{fun}).

\subsubsection{Abbreviations and notation}
As can be seen from the `less-eq-\isasymM' function in \cref{appendix:example_isabelle_theory}, the $Nr$ and $Star$ constructors for \isasymM{} are not used directly. Instead, numbers and a star symbol (\isactrlemph) are used to respectively represent a value of $Nr$ and the $Star$ constructor. The use of these symbols has been achieved using the \textbf{notation} keyword:
\vspace{1em}\begin{isabellebody}
\isacommand{notation}\isamarkupfalse%
\isanewline
\ \ Star\ {\isacharparenleft}{\isachardoublequoteopen}{\isacharparenleft}\isactrlemph {\isacharparenright}{\isachardoublequoteclose}\ {\isadigit{1}}{\isadigit{0}}{\isadigit{0}}{\isadigit{0}}{\isacharparenright}\ \isakeyword{and}\isanewline
\ \ Nr\ {\isacharparenleft}{\isachardoublequoteopen}{\isacharparenleft}\isactrlbold {\isacharunderscore}{\isacharparenright}{\isachardoublequoteclose}\ {\isacharbrackleft}{\isadigit{1}}{\isadigit{0}}{\isadigit{0}}{\isadigit{0}}{\isacharbrackright}\ {\isadigit{1}}{\isadigit{0}}{\isadigit{0}}{\isadigit{0}}{\isacharparenright}
\end{isabellebody}

The notation keyword allows us to introduce a new notation for many different constructs, in this case, the $Star$ and $Nr$ constructors of \isasymM. Custom notations are very powerful, as Isabelle automatically rewrites $Star$ and $Nr$ constructors back to this notation, so introducing this notation works in two ways. It can help to make theorems and proofs more readable, as can also be seen from the example in \cref{appendix:example_isabelle_theory}.

Besides the introduction of an alternative notation for existing constructs, it is also possible to introduce a new notation with the corresponding definition of what the notation means. Such a notation is achieved using the \textbf{abbreviation} keyword. It has the same properties as the \textbf{notation} keyword, but then for a newly defined definition. An example of this is given in \cref{appendix:example_isabelle_theory}:
\vspace{1em}\begin{isabellebody}
\isacommand{abbreviation}\isamarkupfalse%
\ multiplicity{\isacharunderscore}notation\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isasymM}\ {\isasymRightarrow}\ {\isasymM}\ {\isasymRightarrow}\ multiplicity{\isachardoublequoteclose}\ {\isacharparenleft}{\isachardoublequoteopen}{\isacharparenleft}{\isacharunderscore}{\isacharslash}{\isachardot}{\isachardot}{\isacharunderscore}{\isacharparenright}{\isachardoublequoteclose}\ {\isacharbrackleft}{\isadigit{5}}{\isadigit{2}}{\isacharcomma}\ {\isadigit{5}}{\isadigit{2}}{\isacharbrackright}\ {\isadigit{5}}{\isadigit{1}}{\isacharparenright}\ \isakeyword{where}\isanewline
\ \ {\isachardoublequoteopen}l{\isachardot}{\isachardot}u\ {\isasymequiv}\ {\isacharparenleft}l{\isacharcomma}u{\isacharparenright}{\isachardoublequoteclose}
\end{isabellebody}

This example introduces a new notation for writing down a multiplicity tuple. It does so by writing the newly introduced notation on the left-hand side and writing the corresponding definition on the right-hand side. Although an \textbf{abbreviation} looks the same as a \textbf{definition}, they are different in the sense that \textbf{abbreviation} only introduces a notation. To Isabelle, it is syntactic sugar, as internally, the notation does not exist. It is only used when representing constructs to the user. This behaviour is different from \textbf{definition}, as definitions exist internally and are used by the proof reasoners.

It should be noted that there are shortcuts possible to introduce notations while defining a definition. An example of this is the `within{\isacharunderscore}multiplicity' definition in \cref{appendix:example_isabelle_theory}:
\vspace{1em}\begin{isabellebody}
\isacommand{definition}\isamarkupfalse%
\ within{\isacharunderscore}multiplicity\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}nat\ {\isasymRightarrow}\ multiplicity\ {\isasymRightarrow}\ bool{\isachardoublequoteclose}\ {\isacharparenleft}\isakeyword{infixl}\ {\isachardoublequoteopen}in{\isachardoublequoteclose}\ {\isadigit{5}}{\isadigit{0}}{\isacharparenright}\ \isakeyword{where}\isanewline
\ \ {\isachardoublequoteopen}n\ in\ m\ {\isasymequiv}\ lower\ m\ {\isasymle}\ \isactrlbold n\ {\isasymand}\ \isactrlbold n\ {\isasymle}\ upper\ m{\isachardoublequoteclose}\isanewline
\end{isabellebody}

This function uses the infix-left (\textbf{infixl}) construction to define an infix notation for the definition. Just like the \textbf{abbreviation} command, it is possible to use this definition on the left-hand side of the definition, for readability.

\subsubsection{Locales}
When defining new types, there is no way to constrain the values for any of its elements. For example, for the `multiplicity' type, there is no way to prevent the second value of the tuple to be 0, since the natural numbers include 0. In Isabelle, functions and types are always total, and there is no way to exclude specific values of a type.

A way to work around this is by using \textbf{locale}s. Locales are Isabelle's approach for dealing with parametric theories. With locales, it is possible to define a context in which specific assumptions hold. An example of a locale is given in \cref{appendix:example_isabelle_theory}:
\vspace{1em}\begin{isabellebody}
\isacommand{locale}\isamarkupfalse%
\ multiplicity\ {\isacharequal}\ \isakeyword{fixes}\ mult\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}multiplicity{\isachardoublequoteclose}\isanewline
\ \ \isakeyword{assumes}\ lower{\isacharunderscore}bound{\isacharunderscore}valid{\isacharbrackleft}simp{\isacharbrackright}{\isacharcolon}\ {\isachardoublequoteopen}lower\ mult\ {\isasymnoteq}\ \isactrlemph {\isachardoublequoteclose}\isanewline
\ \ \isakeyword{assumes}\ upper{\isacharunderscore}bound{\isacharunderscore}valid{\isacharcolon}\ {\isachardoublequoteopen}upper\ mult\ {\isasymnoteq}\ \isactrlbold {\isadigit{0}}{\isachardoublequoteclose}\isanewline
\ \ \isakeyword{assumes}\ properly{\isacharunderscore}bounded{\isacharbrackleft}simp{\isacharbrackright}{\isacharcolon}\ {\isachardoublequoteopen}lower\ mult\ {\isasymle}\ upper\ mult{\isachardoublequoteclose}
\end{isabellebody}

This example introduces the multiplicity locale. Within this locale, we introduce a named-construct `mult', which is a multiplicity. Then we make some assumptions which hold in the context of a multiplicity. In this case,  there are three assumptions. First of all, there are assumptions on the lower and upper bound, excluding specific (but invalid) values. The final assumption captures that the lower bound is always smaller or equal to the upper bound.

With this locale in place, it is possible to prove theorems and lemmas within the context of a multiplicity. That means that when proving theorems and lemmas within the multiplicity context, all introduced assumptions for `mult' hold:
\vspace{1em}\begin{isabellebody}
\isacommand{context}\isamarkupfalse%
\ multiplicity\isanewline
\isakeyword{begin}\isanewline
\isanewline
\isacommand{lemma}\isamarkupfalse%
\ upper{\isacharunderscore}bound{\isacharunderscore}valid{\isacharunderscore}alt{\isacharbrackleft}simp{\isacharbrackright}{\isacharcolon}\ {\isachardoublequoteopen}upper\ mult\ {\isasymge}\ \isactrlbold {\isadigit{1}}{\isachardoublequoteclose}\isanewline
%
\isadelimproof
\ \ %
\endisadelimproof
%
\isatagproof
\isacommand{using}\isamarkupfalse%
\ less{\isacharunderscore}{\isasymM}{\isachardot}elims\ not{\isacharunderscore}less\ upper{\isacharunderscore}bound{\isacharunderscore}valid\ \isacommand{by}\isamarkupfalse%
\ fastforce%
\endisatagproof
{\isafoldproof}%
%
\isadelimproof
\isanewline
%
\endisadelimproof
\isanewline
\isacommand{end}\isamarkupfalse%
\end{isabellebody}

In above example, it is possible to prove that `$upper\ mult \geq 1$ because the assumptions ensure that `$upper\ mult \not= 0$'. Since natural numbers cannot be negative, we have that `$upper\ mult \geq 1$. This theorem can only be proven within the multiplicity context, as otherwise, the assumptions do not hold, and `$upper\ mult$' might be $0$.

Within this thesis, \textbf{locale}s are mostly used to denote valid constructs, such as a valid type graph, type model, instance graph or instance model. These locales limit the respective \textbf{record} types for these constructs by assuming the validity constraints presented in their respective sections.

\subsubsection{Theorems and proofs}
Theorems (also called lemmas) are statements that can be proven correct. For this thesis, all theorems are either defined using the \textbf{theorem} or \textbf{lemma} keywords in Isabelle. A theorem can be defined to be only valid under certain assumptions or can be defined to be true without any assumptions.

An example of a simple \textbf{theorem} can be found in \cref{appendix:example_isabelle_theory}:
\vspace{1em}\begin{isabellebody}
\isacommand{theorem}\isamarkupfalse%
\ mult{\isacharunderscore}zero{\isacharunderscore}unbounded{\isacharunderscore}valid{\isacharbrackleft}simp{\isacharbrackright}{\isacharcolon}\ {\isachardoublequoteopen}n\ in\ \isactrlbold {\isadigit{0}}{\isachardot}{\isachardot}\isactrlemph {\isachardoublequoteclose}\isanewline
%
\isadelimproof
\ \ %
\endisadelimproof
%
\isatagproof
\isacommand{unfolding}\isamarkupfalse%
\ within{\isacharunderscore}multiplicity{\isacharunderscore}def\isanewline
\ \ \isacommand{by}\isamarkupfalse%
\ simp%
\endisatagproof
{\isafoldproof}%
%
\isadelimproof
\end{isabellebody}

This theorem states that for a multiplicity $0..\mstar$, any natural number is within bounds (any $n$ is in $0..\mstar$). It can easily be proven using the definition of a natural number within a multiplicity.

A proof for a theorem is written directly after the statement. It can either be a short proof using apply-scripts, or a proof within Isabelle's proof language Isar. In the example above, it is a short proof using apply-scripts. In this case, the proof is done within one step: by simplification of the definition.

Once lemmas or theorems are proven, they can be used in the proof of other lemmas and statements. Reusing them is done by referring to them manually, or by adding them to a set of lemmas and theorems that Isabelle will try by default. Adding theorems to a set of default rules is done by adding a specific keyword. For example, add $[simp]$ to add the theorem to the set of simplification rules, or add $[intro]$ or $[elim]$, to specify the theorem to be an introduction rule or elimination rule. Introduction and elimination rules will not be further specified here; more information on these can be found in the Isabelle documentation.

\subsubsection{Isar}
\textit{Isar} stands for \textit{Intelligible semi-automated reasoning}, and is an interpreted language environment for structured formal proof documents. It allows to write down mostly humanly readable proofs in Isabelle while still getting the advantage of semi-automated reasoning. Isar is built on the principle of writing down multiple steps of the proof, doing less automation, in favour of readability. As a consequence, writing Isar proofs is more work for the writer of the proof but eventually results in better humanly readable proofs that also have value without the automated reasoning of a theorem prover.

This section will not discuss the full Isar environment in detail. The Isabelle/Isar Reference Manual \cite{wenzel-isabelle_isar}, included with each copy of Isabelle, already contains a very detailed explanation of all features that Isar has to offer. Instead, we consider a small example of a proof written in Isar, picked directly from \cref{appendix:example_isabelle_theory}:
\vspace{1em}\begin{isabellebody}
\isatagproof
\isacommand{proof}\isamarkupfalse%
\isanewline
\ \ \isacommand{fix}\isamarkupfalse%
\ x\ y\ z\ {\isacharcolon}{\isacharcolon}\ {\isasymM}\isanewline
\ \ \isacommand{show}\isamarkupfalse%
\ {\isachardoublequoteopen}{\isacharparenleft}x\ {\isacharless}\ y{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}x\ {\isasymle}\ y\ {\isasymand}\ {\isasymnot}\ y\ {\isasymle}\ x{\isacharparenright}{\isachardoublequoteclose}\isanewline
\ \ \isacommand{proof}\isamarkupfalse%
\ {\isacharparenleft}induction\ x\ arbitrary{\isacharcolon}\ y{\isacharparenright}\isanewline
\ \ \ \ \isacommand{case}\isamarkupfalse%
\ Star\isanewline
\ \ \ \ \isacommand{then}\isamarkupfalse%
\ \isacommand{show}\isamarkupfalse%
\ {\isacharquery}case\ \isacommand{by}\isamarkupfalse%
\ simp{\isacharunderscore}all\isanewline
\ \ \isacommand{next}\isamarkupfalse%
\isanewline
\ \ \ \ \isacommand{case}\isamarkupfalse%
\ {\isacharparenleft}Nr\ x{\isacharparenright}\isanewline
\ \ \ \ \isacommand{then}\isamarkupfalse%
\ \isacommand{show}\isamarkupfalse%
\ {\isacharquery}case\ \isacommand{by}\isamarkupfalse%
\ {\isacharparenleft}cases\ y{\isacharparenright}\ auto\isanewline
\ \ \isacommand{qed}\isamarkupfalse%
\isanewline
\isanewline
\ \ \isacommand{show}\isamarkupfalse%
\ {\isachardoublequoteopen}x\ {\isasymle}\ x{\isachardoublequoteclose}\ \isacommand{by}\isamarkupfalse%
\ {\isacharparenleft}induction\ x{\isacharparenright}\ simp{\isacharunderscore}all\isanewline
\ \ \isacommand{then}\isamarkupfalse%
\ \isacommand{show}\isamarkupfalse%
\ {\isachardoublequoteopen}x\ {\isasymle}\ y\ {\isasymLongrightarrow}\ y\ {\isasymle}\ x\ {\isasymLongrightarrow}\ x\ {\isacharequal}\ y{\isachardoublequoteclose}\isanewline
\ \ \isacommand{proof}\isamarkupfalse%
\ {\isacharparenleft}induction\ x\ arbitrary{\isacharcolon}\ y{\isacharparenright}\isanewline
\ \ \ \ \isacommand{case}\isamarkupfalse%
\ Star\isanewline
\ \ \ \ \isacommand{then}\isamarkupfalse%
\ \isacommand{show}\isamarkupfalse%
\ {\isacharquery}case\ \isacommand{by}\isamarkupfalse%
\ {\isacharparenleft}cases\ y{\isacharparenright}\ simp{\isacharunderscore}all\isanewline
\ \ \isacommand{next}\isamarkupfalse%
\isanewline
\ \ \ \ \isacommand{case}\isamarkupfalse%
\ {\isacharparenleft}Nr\ x{\isacharparenright}\isanewline
\ \ \ \ \isacommand{then}\isamarkupfalse%
\ \isacommand{show}\isamarkupfalse%
\ {\isacharquery}case\ \isacommand{by}\isamarkupfalse%
\ {\isacharparenleft}cases\ y{\isacharparenright}\ simp{\isacharunderscore}all\isanewline
\ \ \isacommand{qed}\isamarkupfalse%
\isanewline
\isanewline
\ \ \isacommand{show}\isamarkupfalse%
\ {\isachardoublequoteopen}x\ {\isasymle}\ y\ {\isasymLongrightarrow}\ y\ {\isasymle}\ z\ {\isasymLongrightarrow}\ x\ {\isasymle}\ z{\isachardoublequoteclose}\isanewline
\ \ \isacommand{proof}\isamarkupfalse%
\ {\isacharparenleft}induction\ x\ arbitrary{\isacharcolon}\ y\ z{\isacharparenright}\isanewline
\ \ \ \ \isacommand{case}\isamarkupfalse%
\ Star\isanewline
\ \ \ \ \isacommand{then}\isamarkupfalse%
\ \isacommand{show}\isamarkupfalse%
\ {\isacharquery}case\ \isacommand{by}\isamarkupfalse%
\ {\isacharparenleft}cases\ y{\isacharparenright}\ simp{\isacharunderscore}all\isanewline
\ \ \isacommand{next}\isamarkupfalse%
\isanewline
\ \ \ \ \isacommand{case}\isamarkupfalse%
\ {\isacharparenleft}Nr\ x{\isacharparenright}\isanewline
\ \ \ \ \isacommand{then}\isamarkupfalse%
\ \isacommand{show}\isamarkupfalse%
\ {\isacharquery}case\isanewline
\ \ \ \ \isacommand{proof}\isamarkupfalse%
\ {\isacharparenleft}induction\ y\ arbitrary{\isacharcolon}\ z{\isacharparenright}\isanewline
\ \ \ \ \ \ \isacommand{case}\isamarkupfalse%
\ Star\isanewline
\ \ \ \ \ \ \isacommand{then}\isamarkupfalse%
\ \isacommand{show}\isamarkupfalse%
\ {\isacharquery}case\ \isacommand{by}\isamarkupfalse%
\ {\isacharparenleft}cases\ z{\isacharparenright}\ simp{\isacharunderscore}all\isanewline
\ \ \ \ \isacommand{next}\isamarkupfalse%
\isanewline
\ \ \ \ \ \ \isacommand{case}\isamarkupfalse%
\ {\isacharparenleft}Nr\ x{\isacharparenright}\isanewline
\ \ \ \ \ \ \isacommand{then}\isamarkupfalse%
\ \isacommand{show}\isamarkupfalse%
\ {\isacharquery}case\ \isacommand{by}\isamarkupfalse%
\ {\isacharparenleft}cases\ z{\isacharparenright}\ simp{\isacharunderscore}all\isanewline
\ \ \ \ \isacommand{qed}\isamarkupfalse%
\isanewline
\ \ \isacommand{qed}\isamarkupfalse%
\isanewline
\isanewline
\ \ \isacommand{show}\isamarkupfalse%
\ {\isachardoublequoteopen}x\ {\isasymle}\ y\ {\isasymor}\ y\ {\isasymle}\ x{\isachardoublequoteclose}\isanewline
\ \ \isacommand{proof}\isamarkupfalse%
\ {\isacharparenleft}induction\ x\ arbitrary{\isacharcolon}\ y{\isacharparenright}\isanewline
\ \ \ \ \isacommand{case}\isamarkupfalse%
\ Star\isanewline
\ \ \ \ \isacommand{then}\isamarkupfalse%
\ \isacommand{show}\isamarkupfalse%
\ {\isacharquery}case\ \isacommand{by}\isamarkupfalse%
\ simp\isanewline
\ \ \isacommand{next}\isamarkupfalse%
\isanewline
\ \ \ \ \isacommand{case}\isamarkupfalse%
\ {\isacharparenleft}Nr\ x{\isacharparenright}\isanewline
\ \ \ \ \isacommand{then}\isamarkupfalse%
\ \isacommand{show}\isamarkupfalse%
\ {\isacharquery}case\ \isacommand{by}\isamarkupfalse%
\ {\isacharparenleft}cases\ y{\isacharparenright}\ auto\isanewline
\ \ \isacommand{qed}\isamarkupfalse%
\isanewline
\isacommand{qed}\isamarkupfalse%
%
\endisatagproof
{\isafoldproof}%
%
\isadelimproof
%
\endisadelimproof
\end{isabellebody}

In this example, we see the proof that proves that type \isasymM{} is an instantiation of a linear order. In order to show that type \isasymM{} gives rise to a linear order, we have to proof multiple subgoals, which are:
\begin{itemize}
    \item Correctness of $<$: $(x < y) = (x \leq y \land \lnot y \leq x)$
    \item Reflexivity of $\leq$: $(x \leq x)$
    \item Transitivity of $\leq$: $x \leq y \land y \leq z \implies x \leq z$
    \item Correctness of the linear order: $x \leq y \lor y \leq x$
\end{itemize}
Each of these subgoals is proven separately within the Isar proof. The proof of each subgoal is defined by the \textbf{show} keyword. Important to see from the example above is that each subgoal is proven using a nested subproof. Such subproofs can be written as apply-scripts, or using a nested Isar proof, as we see in the example above.

\subsubsection{Proof tactics}
In order to deliver proofs, we make use of automated reasoning. Essential aspects of automated reasoning are the different proof tactics in Isabelle. Proof tactics can be applied to a proof goal to either solve the proof goal entirely or to somehow make the goal simpler to solve.

A vital proof tactic shown in the example above is `induction'. This tactic applies mathematical induction to the proof goal, splitting the goal into new subgoals that follow the structure of mathematical induction.

The following proof tactics are extensively used within this thesis:
\begin{itemize}
    \item `induction' (also called `induct'): Applies mathematical induction to the proof goal. Splits the subgoal into two or more subgoals that follow the structure of mathematical induction.
    \item `cases': Applies a case distinction to the proof goal. It will split the proof goal into multiple subgoals, one for each applicable case. This proof tactic works especially well for inductive definitions and datatypes with a finite set of possible values.
    \item `intro': Splits a proof goal and introduces new subgoals based on an introduction rule. An important example of an introduction rule is $conjI$, which splits a proof goal of $A \land B$ into the two subgoals $A$ and $B$.
    \item `elim': Splits a proof goal by eliminating operations and relations and providing smaller subgoals instead of those. For example, the elimination rule $disjE$ splits a proof goal of the form $A \lor B \implies C$ into two subgoals, $A \implies C$ and $B \implies C$.
    \item `simp' (and `simp\_all'): Apply simplification to a proof goal in order to solve the problem completely. It uses simplification rules to rewrite the statement until it arrives at `True', finishing the proof.
    \item `fastforce': Solves the proof goal by using a tactic similar to brute force. It tries all possible outcomes but tries to be smart by excluding similar cases.
    \item `fast': A classical solver which solves the proof goal by structurally checking cases based on a depth-first search algorithm. Not frequently used within this thesis.
    \item `auto': A combination of `simp' and `fastforce', which can also use introduction rules and elimination rules when rewriting. In general, this proof tactic more powerful than `simp' and `fastforce'.
    \item `blast': Solves the proof goal by using a semantic tableau. Frequently used for solving logic problems.
    \item `metis': Solves the proof goal by using resolution. Frequently used for more complex logic problems that cannot be solved by `blast'.
\end{itemize}

Isabelle is not limited to the above-discussed proof tactics, but these tactics are the most important ones for this thesis. Other tactics are not used either because they apply to a different kind of problem (number arithmetic instead of logic, for example) or because they are not transparent in solving their problem. For example, the `smt' proof tactic solves a problem by using an external SMT solver. Although these proof tactics can solve many problems, it is not transparent to the reader what steps the SMT solver has taken to solve the problem, as opposed to the proof tactics described above. Therefore these tactics have been excluded.

\subsection{Archive of Formal Proofs}
Isabelle has an Archive of Formal Proofs (AFP), which is a collection of proof libraries, examples, and larger scientific developments, mechanically checked in the theorem prover Isabelle. All theories within this archive are organised in the way of a scientific journal such that they can be referred to by new theories.

\subsubsection{Graph Theory}
The Isabelle AFP submission Graph Theory \cite{noschinski-graph_theory} is used as part of this thesis. This submission to the Isabelle AFP is a formalization of directed graphs, supporting labelled multi-edges and infinite graphs. Theorems proven for these graphs include, but are not limited to, walks, cyclicity, connectedness and some properties of isomorphisms. All the theorems proven as part of this submission are discussed in \cite{bang-jensen_gutin_2010}.

Within this thesis, the submission is used as part of the GROOVE formalisation within Isabelle. Within the GROOVE formalisation, GROOVE type graphs and instance graphs are extensions of the directed graph introduced by the Graph Theory submission. This allows Isabelle to apply theorems proven for graphs within this submission to GROOVE graphs presented in the theories of this thesis.

Within this thesis, only a small selected set of theorems from the submission is used. This set mostly includes theorems related to walks and cyclicity of graphs. These theorems are used to show the acyclicity of the containment relation for instance graphs.


% Like most advanced LaTeX files, this one begins with a lot of
% boilerplate. You don't need to understand (or even read) most of it.
% All you need to do is fill in your name, UMN ID, email address,
% and the number of the pset. (Search for "METADATA" to find the place
% for this.) Then, you can go straight to the "EXERCISE 1"
% section and start writing your solutions.
% The "VARIOUS USEFUL COMMANDS" section is probably worth taking a
% look at at some point.

%----------------------------------------------------------------------------------------
%	PACKAGES AND OTHER DOCUMENT CONFIGURATIONS
%----------------------------------------------------------------------------------------
\documentclass[paper=a4, fontsize=12pt]{scrartcl} % A4 paper and 12pt font size
\usepackage[T1]{fontenc} % Use 8-bit encoding that has 256 glyphs
\usepackage[english]{babel} % English language/hyphenation
\usepackage{amsmath,amsfonts,amsthm,amssymb} % Math packages
\usepackage{mathrsfs}    % More math packages
\usepackage{sectsty}  % Allows customizing section commands
\allsectionsfont{\centering \normalfont\scshape} % Make all section titles centered, the default font and small caps %remove this to left align section tites
\usepackage{hyperref} % Turns cross-references into hyperlinks,
                      % and defines \url and \href commands.
\usepackage{graphicx} % For embedding graphics files.
\usepackage{framed}   % For the "leftbar" environment used below.
\usepackage{ifthen}   % Used for the \powset command below.
\usepackage{lastpage} % for counting the number of pages
\usepackage[headsepline,footsepline,manualmark]{scrlayer-scrpage}
\usepackage[height=10in,a4paper,hmargin={1in,0.8in}]{geometry}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tikz}     % This is a powerful tool to draw vector
                      % graphics inside LaTeX. In particular, you can
                      % use it to draw graphs.
\usepackage{verbatim} % For the "verbatim" environment, in which
                      % special symbols can be used freely without
                      % confusing the compiler. (And it's typeset in
                      % a constant-width font.)
                      % Useful, e.g., for quoting code (or ASCII art).

%\numberwithin{table}{section} % Number tables within sections (i.e. 1.1, 1.2, 2.1, 2.2 instead of 1, 2, 3, 4)

\setlength\parindent{20pt} % Makes indentation for paragraphs longer.
                           % This makes paragraphs stand out more.

%----------------------------------------------------------------------------------------
%	VARIOUS USEFUL COMMANDS
%----------------------------------------------------------------------------------------
% The commands below might be convenient. For example, you probably
% prefer to write $\powset[2]{V}$ for the set of $2$-element subsets
% of $V$, rather than writing $\mathcal{P}_2(V)$.
% Notice that you can easily define your own commands like this.
% Caveat: Some of these commands need to be properly "guarded" when
% they occur in subscripts or superscripts. So you should not write
% $K_\CC$, but rather $K_{\CC}$.
\newcommand{\CC}{\mathbb{C}} % complex numbers
\newcommand{\RR}{\mathbb{R}} % real numbers
\newcommand{\QQ}{\mathbb{Q}} % rational numbers
\newcommand{\NN}{\mathbb{N}} % nonnegative integers
\newcommand{\PP}{\mathbb{P}} % positive integers
\newcommand{\KK}{\mathbb{K}} % my favorite notation for a commutative ring
\newcommand{\Z}[1]{\mathbb{Z}/#1\mathbb{Z}} % integers modulo k
                                            % (syntax: "\Z{k}")
\newcommand{\ZZ}{\mathbb{Z}} % integers
\newcommand{\id}{\operatorname{id}} % identity map
\newcommand{\lcm}{\operatorname{lcm}}
% Lowest common multiple. For historical reasons, LaTeX has a \gcd
% command built in, but not an \lcm command. The preceding line
% rectifies that.
\newcommand{\set}[1]{\left\{ #1 \right\}}
% $\set{...}$ compiles to {...} (set-brackets).
\newcommand{\abs}[1]{\left| #1 \right|}
% $\abs{...}$ compiles to |...| (absolute value, or size of a set).
\newcommand{\tup}[1]{\left( #1 \right)}
% $\tup{...}$ compiles to (...) (parentheses, or tuple-brackets).
\newcommand{\ive}[1]{\left[ #1 \right]}
% $\ive{...}$ compiles to [...] (Iverson bracket, aka truth value; also, set of first n integers).
\newcommand{\floor}[1]{\left\lfloor #1 \right\rfloor}
% $\floor{...}$ compiles to |_..._| (floor function).
\newcommand{\underbrack}[2]{\underbrace{#1}_{\substack{#2}}}
% $\underbrack{...1}{...2}$ yields
% $\underbrace{...1}_{\substack{...2}}$. This is useful for doing
% local rewriting transformations on mathematical expressions with
% justifications. For example, try this out:
% $ \underbrack{(a+b)^2}{= a^2 + 2ab + b^2 \\ \text{(by the binomial formula)}} $
\newcommand{\powset}[2][]{\ifthenelse{\equal{#2}{}}{\mathcal{P}\left(#1\right)}{\mathcal{P}_{#1}\left(#2\right)}}
% $\powset[k]{S}$ stands for the set of all $k$-element subsets of
% $S$. The argument $k$ is optional, and if not provided, the result
% is the whole powerset of $S$.
\newcommand{\calF}{\mathcal{F}}
\newcommand{\horrule}[1]{\rule{\linewidth}{#1}} % Create horizontal rule command with 1 argument of height
\newcommand{\nnn}{\nonumber\\} % Don't number this line in an "align" environment, and move on to the next line.

%----------------------------------------------------------------------------------------
%	MAKING SUMMATION SIGNS ALWAYS PUT THEIR BOUNDS ABOVE AND BELOW
%	THE SIGN
%----------------------------------------------------------------------------------------
% The following are hacks to ensure that sums (such as
% $\sum_{k=1}^n k$) always put their bounds (i.e., the $k=1$ and the
% $n$) underneath and above the sign, as opposed to on its right.
% Same for products (\prod), set unions (\bigcup) and set
% intersections (\bigcap). Remove the 8 lines below if you do not want
% this behavior.
\let\sumnonlimits\sum
\let\prodnonlimits\prod
\let\cupnonlimits\bigcup
\let\capnonlimits\bigcap
\renewcommand{\sum}{\sumnonlimits\limits}
\renewcommand{\prod}{\prodnonlimits\limits}
\renewcommand{\bigcup}{\cupnonlimits\limits}
\renewcommand{\bigcap}{\capnonlimits\limits}

%----------------------------------------------------------------------------------------
%	ENVIRONMENTS
%----------------------------------------------------------------------------------------
% The incantations below define how theorem environments
% (\begin{theorem} ... \end{theorem}) and their likes will look like.
\newtheoremstyle{plainsl}% <name>
  {8pt plus 2pt minus 4pt}% <Space above>
  {8pt plus 2pt minus 4pt}% <Space below>
  {\slshape}% <Body font>
  {0pt}% <Indent amount>
  {\bfseries}% <Theorem head font>
  {.}% <Punctuation after theorem head>
  {5pt plus 1pt minus 1pt}% <Space after theorem headi>
  {}% <Theorem head spec (can be left empty, meaning `normal')>

% Environments which make the text inside them slanted:
\theoremstyle{plainsl}
  \newtheorem{theorem}{Theorem}[section]
  \newtheorem{proposition}[theorem]{Proposition}
  \newtheorem{lemma}[theorem]{Lemma}
  \newtheorem{corollary}[theorem]{Corollary}
  \newtheorem{conjecture}[theorem]{Conjecture}
% Environments that don't:
\theoremstyle{definition}
  \newtheorem{definition}[theorem]{Definition}
  \newtheorem{example}[theorem]{Example}
  \newtheorem{exercise}[theorem]{Exercise}
  \newtheorem{examples}[theorem]{Examples}
  \newtheorem{algorithm}[theorem]{Algorithm}
  \newtheorem{question}[theorem]{Question}
 \theoremstyle{remark}
  \newtheorem{remark}[theorem]{Remark}
\newenvironment{statement}{\begin{quote}}{\end{quote}}
\newenvironment{fineprint}{\begin{small}}{\end{small}}

%----------------------------------------------------------------------------------------
%	METADATA
%----------------------------------------------------------------------------------------
\newcommand{\myname}{Darij Grinberg} % ENTER YOUR NAME HERE
\newcommand{\myid}{00000000} % ENTER YOUR UMN ID HERE
\newcommand{\mymail}{dgrinber@umn.edu} % ENTER YOUR EMAIL HERE
\newcommand{\psetnumber}{2} % ENTER THE NUMBER OF THIS PSET HERE

%----------------------------------------------------------------------------------------
%	HEADER AND FOOTER
%----------------------------------------------------------------------------------------
\ihead{Solutions to midterm \#\psetnumber} % Page header left
\ohead{page \thepage\ of \pageref{LastPage}} % Page header right
\ifoot{\myname, \myid} % left footer
\ofoot{\mymail} % right footer

%----------------------------------------------------------------------------------------
%	TITLE SECTION
%----------------------------------------------------------------------------------------
\title{
\normalfont \normalsize
\textsc{University of Minnesota, School of Mathematics} \\ [25pt] % Your university, school and/or department name(s)
\horrule{0.5pt} \\[0.4cm] % Thin top horizontal rule
\huge Math 4281: Introduction to Modern Algebra, \\
Spring 2019:
Midterm \psetnumber\\% The assignment title
\horrule{2pt} \\[0.5cm] % Thick bottom horizontal rule
}
\author{\myname}

\begin{document}

\maketitle % Print the title

\begin{center} % Delete this if you want to save space!
{\large due date: \textbf{Friday, 12 April 2019} at the beginning of class, \\
or before that through Canvas.

\textbf{No collaboration allowed} -- this is a midterm.

Please solve \textbf{at most 3 of the 6 exercises}!}
\end{center}

%----------------------------------------------------------------------------------------
%	EXERCISE 1
%----------------------------------------------------------------------------------------
\horrule{0.3pt} \\[0.4cm]

\section{Exercise 1: Not-quite-all-rationals}

\subsection{Problem}

Fix an integer $m$.
An \textit{$m$-integer} shall mean a rational number
$r$ such that there exists a $k \in \NN$ satisfying
$m^k r \in \ZZ$.

For example\footnote{You don't need to prove these.}:
\begin{itemize}
 \item Each integer $r$ is an $m$-integer (since $m^k r \in \ZZ$
       for $k = 0$).
 \item The rational number $\dfrac{5}{12}$
       is a $6$-integer (since $6^k \cdot \dfrac{5}{12} \in \ZZ$
       for $k = 2$), but neither a $2$-integer nor a $3$-integer
       (since multiplying it by a power of $2$ will not ``get
       rid of'' the prime factor $3$ in the denominator, and
       vice versa\footnote{You would have to be more rigorous
       than this in your solution, if you were to make an
       argument like this.}).
 \item The $1$-integers are the integers (since $1^k r = r$
       for all $r$).
 \item Every rational number $r$ is a $0$-integer (since
       $0^k r \in \ZZ$ for $k = 1$).
\end{itemize}

Let $R_m$ denote the set of all $m$-integers.
Prove the following:

\begin{enumerate}

\item[\textbf{(a)}] The set $R_m$ (endowed with the usual
addition, the usual multiplication, the usual integer $0$
as zero, and the usual integer $1$ as unity) is a
commutative ring. \\
(You don't need to prove axioms like commutativity of
multiplication, since these follow from the corresponding
facts about rational numbers, which are well-known.
You only need to check that $R_m$ is
closed under addition and multiplication\footnote{This
means that every $a, b \in R_m$ satisfy $a + b \in R_m$
and $a b \in R_m$.}, and contains
additive inverses of all its elements.)

\item[\textbf{(b)}] Let $x \in \QQ$ be nonzero.
Then, $x \in R_m$ if and only if every prime $p$ satisfying
$w_p\tup{x} < 0$ satisfies $p \mid m$.
Here, we are using the notation $w_p\tup{r}$ defined
in Exercise 3.4.1 of the
\href{http://www.cip.ifi.lmu.de/~grinberg/t/19s/notes.pdf}{class notes}.

\end{enumerate}

\subsection{Remark}

The ring $R_m$ is an example of a ring ``between $\ZZ$ and $\QQ$''.
Note that $R_1 = \ZZ$ and $R_0 = \QQ$, whereas $R_2 = R_4 = R_8 = \cdots$
is the ring of all rational numbers that can be written in the form
$a / 2^k$ with $a \in \ZZ$ and $k \in \NN$.

\subsection{Solution}

[...]

%----------------------------------------------------------------------------------------
%	EXERCISE 2
%----------------------------------------------------------------------------------------
\horrule{0.3pt} \\[0.4cm]

\section{Exercise 2: Rings with $x^2 = x$}

\subsection{Problem}

Let $\KK$ be a ring with the property that
\begin{align}
 u^2 = u \qquad \text{ for all } u \in \KK .
 \label{eq.exe.ring.xx=x.cond}
\end{align}

(Examples of such rings are $\ZZ / 2$ as well as the
``power set'' ring $\tup{\powset{S}, \triangle, \cap, \varnothing, S}$
constructed from any given set $S$.)

Prove the following:

\begin{enumerate}

\item[\textbf{(a)}]
We have $2x = 0$ for each $x \in \KK$.

\item[\textbf{(b)}]
We have $-x = x$ for each $x \in \KK$.

\item[\textbf{(c)}]
We have $xy = yx$ for all $x, y \in \KK$.
(In other words, the ring $\KK$ is commutative.)

\end{enumerate}

(As usual, ``$0$'' stands for the zero of the ring $\KK$.)

[\textbf{Hint:}
For part \textbf{(a)},
apply \eqref{eq.exe.ring.xx=x.cond} to $u = x$
but also to $u = 2x = x + x$, and see what comes out.
For part \textbf{(c)},
apply \eqref{eq.exe.ring.xx=x.cond} to $u = x + y$.]

\subsection{Remark}

You might wonder what happens if we replace
\eqref{eq.exe.ring.xx=x.cond} by
\begin{align}
 u^3 = u \qquad \text{ for all } u \in \KK .
 \label{eq.exe.ring.xx=x.cube}
\end{align}
This no longer leads to $2x = 0$ (nor to $3x = 0$ as you
might perhaps expect).
Instead, it can be shown that $6x = 0$ for all $x \in \KK$.
It can also be shown that it leads to $xy = yx$.

\subsection{Solution}

[...]

%----------------------------------------------------------------------------------------
%	EXERCISE 3
%----------------------------------------------------------------------------------------
\horrule{0.3pt} \\[0.4cm]

\section{Exercise 3: A matrix of gcds}

\subsection{Problem}

In this exercise, we shall again use
\href{https://en.wikipedia.org/wiki/Iverson_bracket}{the \textit{Iverson bracket notation}}:

Let $n \in \NN$.
Let $G$ be the $n \times n$-matrix
\[
 \tup{ \gcd\tup{i, j} }_{1 \leq i \leq n, \ 1 \leq j \leq n }
 =
 \begin{pmatrix}   % "pmatrix" stands for "parenthesis-bounded matrix".
                   % That's how we write matrices in this class.
  \gcd\tup{1, 1} & \gcd\tup{1, 2} & \cdots & \gcd\tup{1, n} \\
  \gcd\tup{2, 1} & \gcd\tup{2, 2} & \cdots & \gcd\tup{2, n} \\
  \vdots & \vdots & \ddots & \vdots \\
  \gcd\tup{n, 1} & \gcd\tup{n, 2} & \cdots & \gcd\tup{n, n}
 \end{pmatrix} .
\]

Let $L$ be the $n \times n$-matrix
\[
 \tup{ \ive{j \mid i} }_{1 \leq i \leq n, \ 1 \leq j \leq n }
 =
 \begin{pmatrix}
  \ive{1 \mid 1} & \ive{2 \mid 1} & \cdots & \ive{n \mid 1} \\
  \ive{1 \mid 2} & \ive{2 \mid 2} & \cdots & \ive{n \mid 2} \\
  \vdots & \vdots & \ddots & \vdots \\
  \ive{1 \mid n} & \ive{2 \mid n} & \cdots & \ive{n \mid n}
 \end{pmatrix} .
\]

Let $D$ be the $n \times n$-matrix
\[
 \tup{ \ive{i = j} \phi\tup{i} }_{1 \leq i \leq n, \ 1 \leq j \leq n }
 =
 \begin{pmatrix}
  \phi\tup{1} & 0 & 0 & \cdots & 0 \\
  0 & \phi\tup{2} & 0 & \cdots & 0 \\
  0 & 0 & \phi\tup{3} & \cdots & 0 \\
  \vdots & \vdots & \vdots & \ddots & \vdots \\
  0 & 0 & 0 & \cdots & \phi\tup{n}
 \end{pmatrix} .
\]

Prove that\footnote{We are using the standard notation $A^T$ for
the \textit{transpose} of a matrix $A$. This transpose is defined
as follows:
If $A = \tup{ a_{i, j} }_{1 \leq i \leq n, \ 1 \leq j \leq m }$,
then
$A^T = \tup{ a_{j, i} }_{1 \leq i \leq m, \ 1 \leq j \leq n }$.}
$G = LDL^T$.

[\textbf{Hint:} Diagonal matrices are particularly easy
to multiply with other matrices. For example, given a
diagonal matrix
$\mathbf{D} = \tup{ \ive{i = j} d_i }_{1 \leq i \leq n, \ 1 \leq j \leq n }$
(where $d_1, d_2, \ldots, d_n$ are $n$ elements of a ring $\KK$)
and an arbitrary matrix
$\mathbf{A} = \tup{ a_{i, j} }_{1 \leq i \leq n, \ 1 \leq j \leq m }$
(over the same ring $\KK$),
the product $\mathbf{D} \mathbf{A}$ is simply given by
\begin{align}
 \mathbf{D} \mathbf{A} =
 \tup{ d_i a_{i, j} }_{1 \leq i \leq n, \ 1 \leq j \leq m } .
 \label{eq.matrix.gcd-LDU.row-mult}
\end{align}
(That is, multiplying by a diagonal matrix on the left is tantamount
to rescaling each row by the corresponding entry of the diagonal
matrix.)
You can use the formula \eqref{eq.matrix.gcd-LDU.row-mult} without
proof (though its easy proof is instructive).]

\subsection{Remark}

As the names suggest, the matrix $L$ is lower-triangular
(so that the matrix $L^T$ is upper-triangular),
and the matrix $D$ is diagonal.
Thus, $G = LDL^T$ is an instance of an
\href{https://en.wikipedia.org/wiki/LU_decomposition#LDU_decomposition}{\textit{LDU decomposition}}.

\subsection{Solution}

[...]

%----------------------------------------------------------------------------------------
%	EXERCISE 4
%----------------------------------------------------------------------------------------
\horrule{0.3pt} \\[0.4cm]

\section{Exercise 4: Idempotent and involutive elements}

\subsection{Problem}

Let $\KK$ be a ring.

An element $a$ of $\KK$ is said to be \textit{idempotent}
if it satisfies $a^2 = a$.

An element $a$ of $\KK$ is said to be \textit{involutive}
if it satisfies $a^2 = 1$.

\begin{enumerate}
 \item[\textbf{(a)}] Let $a \in \KK$.
 Prove that if $a$ is idempotent, then $1 - 2a$ is
 involutive.

 \item[\textbf{(b)}] Now, assume that $2$ is
 \textit{cancellable} in $\KK$; this means that if
 $u$ and $v$ are two elements of $\KK$ satisfying
 $2u = 2v$, then $u = v$.
 Prove that the converse of the claim of part
 \textbf{(a)} holds:
 If $a \in \KK$ is such that $1 - 2a$ is involutive,
 then $a$ is idempotent.

 \item[\textbf{(c)}] Now, let $\KK = \ZZ / 4$.
 Find an element $a \in \KK$ such that $1 - 2a$
 is involutive, but $a$ is not idempotent.
\end{enumerate}

\subsection{Remark}

The idempotent elements of $\RR$ are $0$ and $1$.
The involutive elements of $\RR$ are $1$ and $-1$.
A matrix ring like $\RR^{n \times n}$ usually has
infinitely many idempotent elements (viz., all
projection matrices on subspaces of $\RR^n$) and
infinitely many involutive elements (viz., all
matrices $A$ satisfying $A^2 = I_n$; for instance,
all reflections across hyperplanes are represented
by such matrices).

Part \textbf{(a)} of this exercise assigns an involutive
element to each idempotent element of $\KK$.
If $2$ is invertible in $\KK$ (that is, if the element
$2 \cdot 1_{\KK}$ has a multiplicative inverse), then this
assignment is a bijection (as can be easily derived from
part \textbf{(b)}).
Part \textbf{(c)} shows that we cannot drop the
``$2$ is cancellable'' condition in part \textbf{(b)}.

\subsection{Solution}

[...]

%----------------------------------------------------------------------------------------
%	EXERCISE 5
%----------------------------------------------------------------------------------------
\horrule{0.3pt} \\[0.4cm]

\section{Exercise 5: The matrix approach to Fibonacci numbers}

\subsection{Problem}

Let $A$ be the $2 \times 2$-matrix
$\begin{pmatrix}
  0 & 1 \\
  1 & 1
 \end{pmatrix}$
over $\ZZ$.
Consider also the identity matrix $I_2 \in \ZZ^{2 \times 2}$.

Let $\calF$ % I have defined \calF to mean \mathcal{F} for this problem.
be the subset
\[
 \set{ aA + bI_2 \mid a, b \in \ZZ }
 =
 \set{ \begin{pmatrix} b & a \\ a & a+b \end{pmatrix} \mid a, b \in \ZZ }
\]
of the matrix ring $\ZZ^{2 \times 2}$.

\begin{enumerate}

\item[\textbf{(a)}]
Prove that $A^2 = A + I_2$.

\item[\textbf{(b)}]
Prove that the set $\calF$ (equipped with the addition of matrices,
the multiplication of matrices, the zero $0_{2 \times 2}$ and
the unity $I_2$) is a commutative ring. \\
(Again, you don't need to check the ring axioms, as we already
know that they hold for arbitrary matrices and thus all the more
for matrices in $\calF$.
But you do need to check commutativity of multiplication in
$\calF$, since it does not hold for arbitrary matrices.
You also need to check that $\calF$ is closed under addition
and multiplication and has additive inverses.)

\end{enumerate}

Let $\tup{f_0, f_1, f_2, \ldots}$ be the Fibonacci sequence (which
we have already encountered on
\href{http://www.cip.ifi.lmu.de/~grinberg/t/19s/hw5s.pdf}{homework set \#5}).
Recall that it is defined recursively by
\[
f_0 = 0, \qquad
f_1 = 1, \qquad \text{and} \qquad
f_n = f_{n-1} + f_{n-2} \text{ for all } n \geq 2 .
\]

\begin{enumerate}

\item[\textbf{(c)}]
Prove that $A^n = f_n A + f_{n-1} I_2$ for all positive
integers $n$.

\item[\textbf{(d)}]
Prove that
$f_{n+m} = f_n f_{m+1} + f_{n-1} f_m$ for all positive
integers $n$ and all $m \in \NN$.

\end{enumerate}

Now, define a further matrix $B \in \calF$ by
$B = \tup{-1}A + 1I_2 = I_2 - A$.

\begin{enumerate}

\item[\textbf{(e)}]
Prove that $B^2 = B + I_2$ and
$B^n = f_n B + f_{n-1} I_2$ for all positive
integers $n$.

\item[\textbf{(f)}]
Prove that
$A^n - B^n = f_n \tup{A - B}$ for all $n \in \NN$.

\item[\textbf{(g)}]
Prove (again!) that $f_d \mid f_{dn}$ for any nonnegative
integers $d$ and $n$.

% Prove that
% \[
%  A^n \begin{pmatrix} 0 \\ 1 \end{pmatrix}
%  = \begin{pmatrix} f_n \\ f_{n+1} \end{pmatrix}
%  \qquad \text{ for all } n \in \NN .
% \]
\end{enumerate}

[\textbf{Hint:} One way to prove \textbf{(d)} is by
comparing the $\tup{1, 1}$-th entries of the two
(equal) matrices $A^n A^{m+1}$ and $A^{n+m+1}$, after
first using part \textbf{(c)} to expand these matrices.

For part \textbf{(g)}, compare the $\tup{1, 1}$-th
entries of the matrices $A^d - B^d$ and $A^{dn} - B^{dn}$,
after first proving that $A^d - B^d \mid A^{dn} - B^{dn}$ in
the commutative ring $\calF$.
Note that divisibility is a tricky concept in general
rings, but $\calF$ is a commutative ring, which lets
many arguments from the integer setting go
through unchanged.]

\subsection{Remark}

Contrast the ring $\calF$ with the ring $\ZZ\ive{\phi}$
from Exercise 5 on
\href{http://www.cip.ifi.lmu.de/~grinberg/t/19s/hw5s.pdf}{homework set \#5}.
Both of these rings, as we see, can be used to prove that $f_d \mid f_{dn}$
for any nonnegative integers $d$ and $n$.
What else do these rings have in common?

\subsection{Solution}

[...]

%----------------------------------------------------------------------------------------
%	EXERCISE 6
%----------------------------------------------------------------------------------------
\horrule{0.3pt} \\[0.4cm]

\section{Exercise 6: ISBNs vs. fat fingers}

\subsection{Problem}

An \textit{ISBN} shall mean a $10$-tuple
$\tup{a_1, a_2, \ldots, a_{10}} \in \set{0, 1, \ldots, 10}^{10}$
such that
\[
1 a_1 + 2 a_2 + \cdots + 10 a_{10} \equiv 0 \mod 11 .
\]

\noindent
(For example, the $10$-tuple $\tup{1, 1, \ldots, 1}$ is an ISBN.)

Prove the following:

\begin{enumerate}

\item[\textbf{(a)}]
If $\mathbf{a} = \tup{a_1, a_2, \ldots, a_{10}}$ and
$\mathbf{b} = \tup{b_1, b_2, \ldots, b_{10}}$ are two ISBNs
that are equal in all but one entry (i.e.,
there exists some $k \in \set{1, 2, \ldots, 10}$
such that $a_i = b_i$ for all $i \neq k$),
then $\mathbf{a} = \mathbf{b}$.

\item[\textbf{(b)}]
If an ISBN $\mathbf{a} = \tup{a_1, a_2, \ldots, a_{10}}$ is
obtained from an ISBN
$\mathbf{b} = \tup{b_1, b_2, \ldots, b_{10}}$ by swapping
two entries (i.e., there exist $k, \ell \in \set{1, 2, \ldots, 10}$
such that $a_k = b_\ell$ and $a_\ell = b_k$ and
$a_i = b_i$ for all $i \notin \set{k, \ell}$),
then $\mathbf{a} = \mathbf{b}$.

\end{enumerate}

\subsection{Remark}

What we called ISBN here is essentially the definition
of an \href{https://en.wikipedia.org/wiki/International_Standard_Book_Number#ISBN-10_check_digits}{ISBN-10}
-- an international standard for book identifiers used from the
1970s until 2007.
For example, the ISBN-10 of the Graham/Knuth/Patashnik
book ``Concrete Mathematics'' is ``0-201-55802-5'', which corresponds
to $\tup{0, 2, 0, 1, 5, 5, 8, 0, 2, 5}$; you can check
that this is indeed an ISBN according to our definition.

(An ``X'' in a real-life ISBN stands for an entry that
is $10$.)

As this exercise shows, ISBNs have an error-detection
property:
If you make a typo in a single digit or accidentally swap
two digits, the result will not be an ISBN, so you will
know that something has gone wrong.
This helps you avoid ordering the wrong book from a bookstore
or library.
\href{https://en.wikipedia.org/wiki/Luhn_algorithm}{Credit card numbers have a similar error-detection feature}.

This is one of the simplest examples of an
\href{https://en.wikipedia.org/wiki/Error_correction_code}{error correction code}.
We may or may not see more of them in class.
For now, you can think about how to define ``ISBNs''
\begin{itemize}
\item in $\set{0, 1, \ldots, 4}^4$;
\item in $\set{0, 1, \ldots, 6}^6$;
\item in $\set{0, 1, \ldots, 8}^8$ (this is harder!).
\end{itemize}

\subsection{Solution}

[...]

\begin{thebibliography}{99999999}                                                                                %

% Feel free to add your sources -- or copy some from the source code
% of the class notes ( http://www.cip.ifi.lmu.de/~grinberg/t/19s/notes.tex ).

\end{thebibliography}

\end{document}