\chapter{The Response to Phenotypic Selection}
\marginnote{See \citet{lewontin1970units}. Note that these
  requirements are not specific to DNA, i.e. the concept of
  evolution by natural selection is substrate independent. }
Evolution by natural selection requires:
\begin{enumerate}
\item Variation in a phenotype
\item That survival is non-random with respect to this phenotypic
variation.
\item That this variation is heritable.
\end{enumerate}
Points 1 and 2 encapsulate our idea of Natural Selection, but evolution by natural
selection will only occur if the 3rd condition is also
met. \sidenote{Some people consider natural selection to only operate on heritable phenotype varation
  and so require all three conditions to say that natural selection
  occurs. This is mostly a semantic point, however, it is useful to be
able to distinguish the action of selection from a possible response.} It is the
heritable nature of variation that couples change within a generation
due to natural selection to change across generations (evolutionary
change). \\

Let's start by thinking about the change within a generation due
to directional selection, where selection acts to change the mean
phenotype within a generation. For example, a decrease in mean height within a
generation, due to taller organisms having a lower chance of surviving
to reproduction than shorter organisms. Specifically, we'll denote our mean phenotype at
reproduction by $\mu_S$, i.e. after selection has acted, and our mean
phenotype before selection acts by $\mu_{BS}$. This second quantity may be hard to
measure, as obviously selection acts throughout the life-cycle, so it
might be easier to think of this as the mean phenotype if selection
hadn't acted. So the change in mean phenotype within a generation is $\mu_{S} - \mu_{BS}= S$.  \\

\begin{marginfigure}
\begin{center}
\includegraphics[width=\textwidth]{figures/Response_to_sel/QT3.pdf}
\end{center}
\caption{{\bf Top.} Distribution of a phenotype in the parental population
  prior to selection, $V_A=V_E=1$. {\bf Middle.} Only individuals in the top $10\%$
  of the phenotypic distribution are selected to reproduce; the resulting shift
  in the phenotypic mean is $S$. {\bf Bottom.}  Phenotypic distribution of
  children of the selected parents; the shift in the mean phenotype is
$R$. \gitcode{https://github.com/cooplab/popgen-notes/blob/master/Rcode/Quant_gen/QT3.R}}
\end{marginfigure}

We are interested in predicting the distribution of phenotypes in the next
generation. In particular, we are interested in the mean phenotype in
the next generation to understand how directional selection has
contributed to evolutionary change. We'll denote the mean phenotype in
offspring, i.e. the mean phenotype in the next generation before selection acts,
as $\mu_{NG}$. The change across generations we'll call the response
to selection $R$ and put this equal to $\mu_{NG}- \mu_{BS}$. \\

The mean phenotype in the next generation is
\begin{equation}
\mu_{NG} = \E \left( \E(X_{kid} | X_{mum},X_{dad}) \right)
\end{equation}
where the outer expectation is over possible pairs of randomly mating individuals
who survive to reproduce. We can use eqn. \ref{predict_kid} to obtain
an expression for this expectation:
\begin{equation}
\mu_{NG} = \mu_{BS} +
\beta_{mid,kid} ( \E(X_{mid}) - \mu_{BS})
\end{equation}

\begin{marginfigure}
\begin{center}
\includegraphics[width=\textwidth]{figures/Response_to_sel/Breeders_eqn.pdf}
\end{center}
\caption{A visual representation of the Breeder's equation. Regression
  of child's phenotype on parental mid-point phenotype
  ($V_A=V_E=1$). The parents and children of all families are shown as
  grey or red points, However, under truncation selection, only individuals
  with phenotypes $>1$ (red) are bred. The use of the red families
  only results in a phenotypic shift $S$ in the parental generation,
  which drives a shift $R$ in the offspring generation.
  \gitcode{https://github.com/cooplab/popgen-notes/blob/master/Rcode/Quant_gen/QT2.R}}
\end{marginfigure}

So to obtain $\mu_{NG}$ we need to compute $\E(X_{mid})$, the expected
mid-point phenotype of pairs of individuals who survive to
reproduce. Well this is just the expected phenotype in the individuals
who survived to reproduce ($\mu_{S}$), so
\begin{equation}
\mu_{NG} = \mu_{BS} +
h^2 (\mu_S - \mu_{BS})
\end{equation}
So we can write our response to selection as
\begin{equation}
R = \mu_{NG} -\mu_{BS}  =
h^2 (\mu_S - \mu_{BS}) = h^2 S \label{breeders_eqn}
\end{equation}
So our response to selection is proportional to our selection
differential, and the constant of proportionality is the narrow sense
heritability. This equation is sometimes termed the Breeder's
equation. It is a statement that the evolutionary change across
generations ($R$) is proportional to the change caused by directional selection
within a generation ($S$), and that the strength of this relationship is
determined by the narrow sense heritability ($h^2$). \\

%\graham{Lost the barncle question, put it back in.}

\begin{figure}
\begin{center}
\includegraphics[width= 0.6 \textwidth]{Journal_figs/Quant_gen/Galen_flower_herit/Galen_corolla_flare.pdf}
\end{center}
\caption{The relationship between maternal and offspring corolla flare (flower
  width) in P. viscosum. From \citeauthor{galen:96}'s data the
  covariance of mother and child is 1.3, while the variance of the
  mother is 2.8. Data from \citet{galen:96}. \gitcode{https://github.com/cooplab/popgen-notes/blob/master/Journal_figs/Quant_gen/Galen_flower_herit/Gallen_analysis.R}} \label{fig:Galen_corolla}
\end{figure}

\begin{marginfigure}
\begin{center}
\includegraphics[width=0.75\textwidth]{illustration_images/Quant_gen/Polemonium_viscosum_Galen/Polemonium_viscosum.jpg}
\end{center}
\caption{Sticky jacob's ladder ({\it Polemonium viscosum}). \BHLNC{Flowers of Mountain and
    Plain (1920). Clements, E.}{https://www.biodiversitylibrary.org/page/40791993\#page/49/mode/1up}{New York Botanical Garden, Mertz Library}
Cropped from original.}
\end{marginfigure}

\begin{question}
\citet{galen:96} explored selection on flower shape in
{\it Polemonium viscosum}.  She found that plants with larger corolla flare
had more bumblebee visits, which resulted in higher seed set and a
$17\%$ increase in corolla flare in the plants contributing to the
next generation. Based on the data in the caption of Figure \ref{fig:Galen_corolla}
what is the expected response in the next generation?
\end{question}

\begin{marginfigure}
\begin{center}
\includegraphics[width=\textwidth]{Journal_figs/Quant_gen/Illinois_long_term_selection_corn/Illinois_LTS_breeders_eq.pdf}
\end{center}
\caption{{\bf Top.} Phenotypic distribution of oil content in corn in
  1897, and the individuals who were selected to breed for the next
  generation are marked in blue.   {\bf Bottom.} The distribution in the next generation. Data from the
  Illinois selection experiment available \href{https://www.ideals.illinois.edu/handle/2142/3525}{here}, \gitcode{https://github.com/cooplab/popgen-notes/blob/master/Journal_figs/Quant_gen/Illinois_long_term_selection_corn/corn_LTS.R}}  \label{Fig:Illinois_LTS_breeders_eq}
\end{marginfigure}

If we know $R$ and $S$ we can estimate $h^2$. Heritabilities estimated
like this are called `realized heritability'. Estimates of the
`realized heritability' can readily be produced in artificial selection experiments:
\begin{question}
  From the experiment shown in Figure \ref{Fig:Illinois_LTS_breeders_eq},
  the mean corn oil content in 1897 was $4.78$, among the $24$ individuals
chosen to breed to for the next generation the mean was $5.2$. The
offspring of these individuals had a mean kernel oil content of
$5.1$. What is the narrow sense realized heritability?
\end{question}

To understand the genetic basis of the response to selection take a
look at Figure \ref{Fig:Response_num_alleles}. The setup is the same as in our previous
simulation figures.
\begin{figure}
\begin{center}
\includegraphics[width=\textwidth]{figures/QT3_w_genosums.pdf}
\end{center}
\caption[][4cm]{{\bf Top.} Distribution of the number of up alleles in the parental population
  prior to selection (red), for the selected individuals in the top
  $10\%$ phenotypic tail of the population (blue) {\bf Bottom.}  The same distribution
for the offspring of the selected parents in the next generation
(green). \gitcode{https://github.com/cooplab/popgen-notes/blob/master/Rcode/Quant_gen/QT3.R}}  \label{Fig:Response_num_alleles}
\end{figure}
 The individuals who are selected to form our next generation carry
 more alleles that increase the phenotype in the current range of
 environments currently experienced by the population. The average
 individual before selection carried 100 of these `up' alleles, while the average
 individual surviving selection carries 108 `up' alleles.
 \begin{marginfigure}[4cm]
 \begin{center}
   \includegraphics[width = 0.7 \textwidth]{illustration_images/Genetic_drift/maize/7845339168_66aa3d8ccc_z.jpg}
 \end{center}
 \caption{Maize ({\it Zea mays}.) \BHLNC{Prof. Dr. Thomé's Flora von
   Deutschland. 1886. Thomé, O. W.}{https://www.biodiversitylibrary.org/page/12306602\#page/669/mode/1up}{New York Botanical Garden}} \label{fig:maize}  %é
 \end{marginfigure}  %%possible different fig https://peerj.com/preprints/26502.pdf from Jeff's paper

 As individuals
 faithfully transmit their alleles to the next generation the average
 child of the selected parents carries $108$ up alleles. Note that the
 variance has changed little, the children have plenty of variation in
 their genotype, such that selection can readily drive evolution in future generations. The average frequency of an `up' allele has changed
 from $50\%$ to $54\%$. Gains due to selection will be stably
 inherited to future generations and can be compounded on generation
 after generation if selection pressures were to remain constant.

 \subsection{The Long-Term Response to Selection}
   \begin{marginfigure}
 \begin{center}
 \includegraphics[width=\textwidth]{Journal_figs/Quant_gen/Illinois_long_term_selection_corn/Illinois_LTS_means.pdf} \end{center}
 \caption[2cm]{The mean oil content of corn in the Illinois long term
   selection experiment. Two populations were established in 1896 from
 the same inital population. Two secondary populations were
 established in 1948 where the direction of selection was reversed.
 Linear fit to the up experiment shown as a red line. Data available \href{https://www.ideals.illinois.edu/handle/2142/3525}{here}, \gitcode{https://github.com/cooplab/popgen-notes/blob/master/Journal_figs/Quant_gen/Illinois_long_term_selection_corn/corn_LTS.R}}\label{Fig:Illinois_LTS_means}
\end{marginfigure}

If our selection pressure is sustained over many generations, we can
use our breeder's equation to predict the response. If we are willing
to assume that our heritability does not change and we maintain a constant selection
differential ($S$), then after $n$ generations our phenotype mean will have
shifted
\begin{equation}
n h^2 S
\end{equation}
i.e. our population will keep up a linear response to selection.
 \begin{figure}
 \begin{center}
   \includegraphics[width=\textwidth]{Journal_figs/Quant_gen/Illinois_long_term_selection_corn/Illinois_LTS_ggridges_distribution.pdf}\end{center}
 \caption[][5.5cm]{Density plots showing the phenotypic distributions of the
   up- and down-selection populations of the Illinois long term
   selection experiment over time. Data available
   \href{https://www.ideals.illinois.edu/handle/2142/3525}{here}, \gitcode{https://github.com/cooplab/popgen-notes/blob/master/Journal_figs/Quant_gen/Illinois_long_term_selection_corn/corn_LTS.R}}\label{Fig:Illinois_LTS_dists}
 \end{figure}
Therefore, long-term, consistent selection can drive impressive
evolutionary change. One example of this comes from a field experiment
in Illinois, where plant breeders have systematically selected for
higher and lower oil content in corn (see our previous Figure
\ref{Fig:Illinois_LTS_breeders_eq} for one generation of up selection). For over a century, they have taking seeds from the plants
in the extremes of the distribution and using them to form the next
generation. They have achieved impressive long-term responses, pushing
the population distributions well beyond their initial range (Figure
\ref{Fig:Illinois_LTS_dists}. For example, the oil up-selection line went from a mean oil content of
$4.7\%$ in 1896 to $22.1\%$ in 2004.  They've established
two secondary populations where the selection differential was reversed. In the up-selection population they have maintained an
impressively linear increase in oil content, shown by red line in
Figure \ref{Fig:Illinois_LTS_means}, but while the
response is linear at first in the down line but they quickly reach
very low oil content.

%%single episide of selection in cliff swallows https://www.jstor.org/stable/2411315?mag=driving-evolution-cliff-swallows&seq=1#metadata_info_tab_contents
% http://mooselab.cropsci.illinois.edu/longterm.html
% https://www.ideals.illinois.edu/handle/2142/3525

\begin{question} \label{question:red_deer}
A population of red deer were trapped on Jersey (an island off of
England) during the last inter-glacial period. From the fossil record \cite{lister:89}
we can see that the population rapidly adapted to their new
conditions, perhaps due to selection for shorter reproductive times in
the absence of predation. Within 6,000 years they evolved from an estimated mean weight of
the population of 200kg to an estimated mean weight of 36kg (a 6 fold
reduction)! You estimate that the generation time
of red deer is 5 years and, from a current day population, that the narrow sense heritability of the
phenotype is 0.5.\\

 \begin{marginfigure}
 \begin{center}
 \includegraphics[width=\textwidth]{illustration_images/Quant_gen/dwarf_elephant/M_exilis_skeletal.pdf} \end{center}
 \caption{It's not just deer that evolve to be small on islands,
  pygmy mammoths and elephants have evolved from large mainland species
  on numerous islands. For example, the
   California Channel Islands were home to a dwarf mammoth until about 13,000 years
   ago. \newline \noindent \tiny{Santa
   Rosa {\it Mammuthus exilis}. \href{https://en.wikipedia.org/wiki/Pygmy_mammoth\#/media/File:M._exilis_skeletal.png}{wikimedia}, CC BY 3.0.} }\label{Fig:Pygmy_mammoth}
 \end{marginfigure}
{\bf A)}	Estimate the mean change per generation in the mean body weight. \\

{\bf B)}	Estimate the change in mean body weight caused by
selection within a generation. State your assumptions.\\

{\bf C)}	Assuming we only have fossils from the founding population and the population after 6000 years, should we assume that the calculations accurately reflect what actually occurred within our population?
\end{question}

In wild populations, selection pressures are likely rarely sustained
for large numbers of generations. For example, the Grants' have
measured phenotypic selection in Darwin's Finches over multiple
decades on the island of Daphne Major. They have seen that
selection pressures in the Medium ground-finch ({\it Geospiza fortis})
have reversed a number of times over the years (Figure
\ref{fig:Darwins_Finches_unpred}).
\graham{change to selection diff}
\begin{figure}
\begin{center}
\includegraphics[width= 0.8 \textwidth]{Journal_figs/Quant_gen/Darwins_Finches_unpred/Darwins_Finches_unpred.pdf}
\end{center}
\caption[4cm]{{\bf Top)} Mean body size of the Medium ground-finch
  population measured each year. The 1973 $95\%$ confidence intervals
  are shown as horizontal bars. {\bf Bottom)} Standardized
  selection differentials on body size. The statistical significance of
  the selection differentials is shown, black points are $p<0.001$ and grey $p<0.05$.
  Data from \citet{grant2002unpredictable} \gitcode{https://github.com/cooplab/popgen-notes/blob/master/Journal_figs/Quant_gen/Darwins_Finches_unpred/Darwins_Finches_unpred.R}} \label{fig:Darwins_Finches_unpred}
\end{figure}

\begin{marginfigure}[1cm]
\begin{center}
\includegraphics[width= \textwidth]{illustration_images/Quant_gen/Darwins_Finch/Geospiza_fortis.png}
\end{center}
\caption{Medium ground-finch ({\it Geospiza fortis}). \BHLNC{The zoology of
  the voyage of H.M.S. Beagle. Birds Part 3. (1841) Gould G. Edited by
  Darwin, C. Illustration by Elizabeth Gould.}{https://www.flickr.com/photos/biodivlibrary/8429528265/in/album-72157632647903291/}{Natural History Museum Library, London
}} \label{fig:Geospiza_fortis}
\end{marginfigure}
%% Gingrich style data https://datadryad.org/resource/doi:10.5061/dryad.1tn7123?show=full
%% https://datadryad.org/resource/doi:10.5061/dryad.7d580

\paragraph{Patterns of long-term phenotypic change in the wild.}
Looking across the diversity of plants and animals we see huge changes
in size and form, can the strengths of selection we can observe over short time periods possibly explain
these changes?

To compare phenotypic changes over various time periods we need some measure of the rate of phenotypic
change. \citep{haldane1949suggestions} proposed the rate of change from
$X_1$ to $X_2$ in time interval $\Delta t$, measured in Millions of years, be quantified as
\begin{equation}
\frac{\log \left(\nicefrac{X_2}{X_1} \right) }{\Delta t}  = \frac{\log
  \left(X_2 \right) -\log \left(X_1 \right)  }{\Delta t}
\end{equation}
by expressing this the log of the ratio\sidenote{Note that here, as
  elsewhere, $\log$ refers the natural logarithm, i.e. $\log$ base
  $e$. We'll make it clear if we using $\log$ in a different base,
  e.g. we'll use $\log_{10}$ for $\log$ in base 10.}, we are looking at the
proportional fold change, which makes sense as a
evolutionary change of 1cm in length is more impressive if you're a
mouse than an elephant. By putting this on a $\log$-scale we are
looking at the fold relative
change \citeauthor{haldane1949suggestions} called the
units of this measure {\emph`the Darwin'}, with a one Darwin change
corresponding to a $e\approx 2.71$
fold change in a Million years, a two Darwin change corresponding to a
$e^2\approx  7.34$ fold change in a Million years and so on.

\begin{marginfigure}
  \begin{center}
    \includegraphics[width= \textwidth]{illustration_images/Quant_gen/dog_whelks/dog_whelks.jpg}
\end{center}
\caption{Variation in Atlantic dog whelks ({\it Nucella lapillus}, synonym {\it Purrpura lapukkus})
  along the coast of Great Britain.  \BHLNC{The Cambridge natural history, Molluscs and Brachiopods
    (1895). Cooke AH, Shipley AE, Reed FRC.}{https://archive.org/stream/cambridgenatural03har/cambridgenatural03har\#page/89/mode/1up}{University of Toronto - Earth Sciences Library}} \label{fig:dg_whelks}
\end{marginfigure}

\begin{question}
Calculate the rate of change in body size in the Jersey red deer from
Question \ref{question:red_deer} in Darwins. Do the same for the total
change in corn oil content in the up lines in Figure \ref{Fig:Illinois_LTS_means}.
  \end{question}

\citet{gingerich1983rates} examined the absolute rate of phenotypic
change in field study data and the fossil record, a dataset
considerably expanded by \citet{uyeda2011million}. In Figure
\ref{fig:uyeda_gingerich} each point is an observation of phenotype
evolution. The x-axis shows the time period in years over which the
evolutionary change was observed, the x-axis is plotted on a
$\log_{10}$ scale.  The y-axis shows absolute rate of phenotypic
change, measured in Darwins, again on a $\log_{10}$,

\begin{figure}
  \begin{center}
    \includegraphics[width= \textwidth]{Journal_figs/Quant_gen/Uyeda_evol_rates/Uyeda_evol_rates.pdf}
\end{center}
\caption[][4cm]{The absolute rate of phenotypic evolution, measured in
  Darwins, plotted against the time interval over which the evolution
  was observed. The green points show direct observations of
  phenotypic change in historical and contemporary populations. The
  orange dots give changes observed in the fossil record. The three
  black dots left to right give examples from Dog whelks, our Red deer example, and  {\it Triceratops}. Based on an original plot by
  \citet{gingerich1983rates} using an expanded dataset from
  \citet{uyeda2011million}. \gitcode{https://github.com/cooplab/popgen-notes/blob/master/Journal_figs/Quant_gen/Uyeda_evol_rates/Uyeda_evol_rates.R}} \label{fig:uyeda_gingerich}
\end{figure}
Over short timescales we see incredibly rapid evolution, note the high
rates on the left of Figure \ref{fig:uyeda_gingerich}.
For example, the first black dot from the left is a case of evolution
over decades in dog whelks. The invasion the green crab ({\it Carcinus maenas})
drove the evolution of more robust shells in Atlantic dog
whelk ({\it Nucella lapillus}) in response to predation
along the North American coast \citep{vermeij1982phenotypic}. The shell lip thickness of dog whelks
in the St. Andrews, New Brunswick population had changed from 0.94mm
to 1.44mm in just 25 years. That's a 50\% increase, and a rate of
17060 Darwins.  \graham{is time interval wrong its 1920 to 1963 in
  Vermeij. }
\begin{marginfigure}
  \begin{center}
    \includegraphics[width= \textwidth]{illustration_images/Quant_gen/Triceratops/Triceratops_phylo.png}
\end{center}
\caption{The evolution of {\it Triceratops} from {\it Protoceratops},
  see
  \href{https://www.geol.umd.edu/~tholtz/G104/lectures/104margino.html}{here}
  for a fun updated view of the {\it Coronosauria} phylogeny. See
  these
  \href{https://www.geol.umd.edu/~tholtz/G104/lectures/104margino.html}{figures}
  from Holtz for an updated \& fuller phylogeny. \IANC{The dinosaur book : the ruling reptiles and their
    relatives. (1951) Colbert, E.H.}{https://www.biodiversitylibrary.org/ia/bookruli00colb\#page/86/mode/1up}{American Museum of Natural History Library}} \label{fig:Triceratops_phyl}
\end{marginfigure}
%% http://marsh.dinodb.com/marsh/Marsh%201891%20-%20Restoration%20of%20Triceratops%20(and%20Brontosaurus).pdf Marsh original pic of Triceratops
%https://www.geol.umd.edu/~tholtz/G104/lectures/104margino.html

However, when we observe phenotypic evolution over longer time periods
it is usually much
slower. For example, the rightmost black dot in Figure
\ref{fig:uyeda_gingerich} shows the phenotypic evolution along the
lineage leading to  {\it
  Triceratops}.   {\it Triceratops} measured in an impressive 25.9–29.5 ft in length. They evolved from a close
relative of {\it Protoceratops}, which was a bit bigger than a sheep
at $\sim$5.9 ft in about 7.5 million years
\citep{colbert1948evolution}. However, that's only a phenotypic change
of $0.143$ Darwins, its only a roughly four fold change in millions of
years. These rates of change in Dinosaurs have nothing on our dog
whelks, or many other examples of evolution on short time scales.    %https://www.geol.umd.edu/~tholtz/G104/lectures/104margino.html
Thus evolutionary changes we can observe over short timescales
readily explain long term changes in quantitative phenotypes.

\section{Fitness and the Breeder's Equation.}
So directional evolution occurs as selection drives a change in
the mean phenotype within a generation. But precisely how does this relate to
the natural-selection requirement that organisms vary in their
fitness? Some different ways of formulating the Breeder's equation
give us insight into the conditions for directional selection and the
relationship to fitness landscapes.

\subsection{Directional selection as the covariance between fitness and
phenotype.}
To think more carefully about this change within a
generation, let's think about a simple fitness model where our phenotype affects the
viability of our organisms (i.e. the probability they survive to
reproduce). The probability that an individual has a phenotype $X$
before selection is $p(X=x)$, so that the mean phenotype before
selection is
\begin{equation}
\mu_{BS} = \E[X] =  \int_{-\infty}^{\infty} x p(x) dx
\end{equation}
The probability that an organism with a phenotype $X$ survives to
reproduce is $w(X)$, and we'll think about this as the fitness of
our organism. The probability distribution of phenotypes in those who
do survive to reproduce is
\begin{equation}
\P(X | \textrm{survive}) =  \frac{p(x) w(x)}{
\int_{-\infty}^{\infty} p(x) w(x) dx}.
\end{equation}
where the denominator is a normalization constant which ensures that
our phenotypic distribution integrates to one. The denominator also
has the interpretation of being the mean fitness of the population,
which we'll call $\wbar$, i.e.
\begin{equation}
\wbar =  \int_{-\infty}^{\infty} p(x) w(x) dx. \label{eqn:pheno_mean_fitness}
\end{equation}
Therefore, we can write the mean phenotype in those who survive to
reproduce as
\begin{equation}
\mu_S = \frac{1}{\wbar}\int_{-\infty}^{\infty} x p(x) w(x) dx
\end{equation}
\begin{marginfigure}
  \begin{center}
    \includegraphics[width= \textwidth]{illustration_images/Quant_gen/red_deer/Red_deer.png}
\end{center}
\caption{Red deer ({\it Cervus elaphus}). \BHLCC{British
    mammals. Thorburn, A. (1920)}{https://www.flickr.com/photos/biodivlibrary/21269550204}{Field Museum of Natural History Library}{2.0}} \label{fig:red_deer}
\end{marginfigure}

If we mean center the distribution of phenotypes in our population, i.e. set the phenotype before
selection to zero, then
\begin{equation}
S=\mu_S= \frac{1}{\wbar}\int_{-\infty}^{\infty} x p(x) w(x) dx = \frac{1}{\wbar}\E \left (X
  w(X) \right)
\end{equation}
% if $\mu_S=0$. \erin{do you mean $\mu_{BS}=0$?}
where the final part follows from the fact that the integral is taking
the mean of $X w(X)$ over the population.

As our phenotype is mean centered ($\E(X)=0$), we can see that $S$ has
the form of a covariance\sidenote{See our math appendix Equation \ref{eqn:def_covar} for the
definition of covariance.} between our phenotype $X$ and our relative fitness
$\nicefrac{w(X)}{\wbar} $.
\begin{equation}
  S =  \E \left (X
  \nicefrac{w(X)}{\wbar} \right) =Cov \left(X, \nicefrac{w(X)}{\wbar} \right) \label{S_covar}
\end{equation}

  Thus our change in mean phenotype is directly a measure of the
  covariance of our phenotype and our fitness.
  Rewriting our breeder's
equation using this observation we see
\begin{equation}
R = \frac{V_A}{V}  Cov \left(X, \nicefrac{w(X)}{\wbar} \right)
\end{equation}

we see that the response to selection is due to the fact that our
fitness (viability) of our organisms/parents covaries with our phenotype, and
that our child's phenotype covaries with our parent's phenotype.

\paragraph{Fitness Gradients and linear regressions}

To understand this in more detail let imagine that we calculate the
linear regression of an individual $i$'s mean-centered phenotype ($X_i$) on fitness ($W_i$), i.e.
\begin{equation}
W_i \sim \beta X_i + \wbar \label{fitness_regression}
\end{equation}
The best fitting slope of this regression ($\beta$), see math appendix
around eqn \ref{eqn:def_linear_regression} for more on linear regression, lets call it the
`fitness gradient', is given by
\begin{equation}
  \beta = Cov(X, \nicefrac{w(X)}{\wbar} )/ V  \label{beta_covar}
\end{equation}

  i.e. the fitness gradient is the phenotype-fitness
 covariance divided by the phenotypic variance. Using this result we can rewrite the breeder's equation as
\begin{equation}
R= V_A \beta \label{eqn:R_beta}
\end{equation}
i.e. we'll see a directional response to selection if there is a linear relationship of phenotype on fitness, and if there is additive genetic variance for the phenotype. As one example of a fitness gradient, in Figure \ref{fig:red_deer_fitness_grad}  the lifetime reproductive success (LRS) of male Red Deer is plotted against the weight of their antlers. The red line gives the linear regression of fitness (LRS) on antler mass and the slope of this line is the fitness gradient ($\beta$).
\begin{marginfigure}[2cm]
\begin{center}
\includegraphics[width= \textwidth]{Journal_figs/Quant_gen/red_deer_selection_gradient/selection_grad_deer.pdf}
\end{center}
\caption{Lifetime reproductive success (LRS) of male Red Deer as a
  function of their antler mass. Data from \citet{kruuk2002antler};
  see the paper for discussion of the complexities of equating this
  selection gradient with the evolutionary response. \gitcode{https://github.com/cooplab/popgen-notes/blob/master/Journal_figs/Quant_gen/red_deer_selection_gradient/selection_grad_deer.R}. } \label{fig:red_deer_fitness_grad}
\end{marginfigure}

\graham{add pic of relationship between slope and S?}

\paragraph{Fisher's fundamental theorem of natural selection}
Finally how does the mean fitness of our population evolve?
If we choose relative fitness to be our phenotype
  ($X=\nicefrac{w(X)}{\wbar}$), then the response in fitness is
\begin{align}
  R &= \frac{V_A}{V}  Cov \left(\nicefrac{w(X)}{\wbar} ,
  \nicefrac{w(X)}{\wbar} \right) = \frac{V_A}{V} V \nonumber\\
  &=V_A
\end{align}
i.e. the response to selection is equal to the additive genetic
variance for relative fitness. Or as Fisher put it
\begin{quote}
``The rate of increase in fitness of any organism at any time is equal
to its genetic variance in fitness at that time.'' -\citet{fisher1930} (pg 37)
\end{quote}
Fisher called this `the fundamental theorem of natural
selection'. Our proof here is just a sketch, and more formal
approaches are needed to show it in generality. There has been much gnashing of teeth over exactly how broadly this result holds, and exactly what
Fisher meant \citep[see ][ for a recent overview]{ewens2010gene}.
% Ruth shaw FFTNS https://www.biorxiv.org/content/biorxiv/early/2019/04/07/601682.full.pdf
% https://commons.wikimedia.org/wiki/File:A_guide_to_the_wild_flowers_(Plate_CXXV)_BHL23798491.jpg

\subsection{Directional Selection on Fitness Landscapes.}  \label{section:pheno_fitness_landscapes}

 \begin{figure*}
 \begin{center}
 \includegraphics[width= 0.8 \textwidth]{figures/Response_to_sel/fitness_landscape_1D.pdf}
 \end{center}
 \caption{An example of a fitness landscape, showing the mean fitness
   of the population ($\wbar$) as a function of the mean phenotype of the
   population ($\bar{x}$. The arrows show the expected direction of movement
of our population on the fitness landscape, with natural selection moving
our population toward local fitness optima. The coloured bar shows the
derivative (slope) of the mean fitness with respect to mean
phenotype (eqn. \eqref{eqn:pheno_fitness_landscape}). Red values are positive slopes corresponding to the population evolving
towards the right of the page, blue is a negative slope with the
population moving to the left. } \label{fig:fitness_landscape_1D}
\end{figure*}

One common metaphor when we talk about evolution is that of a population exploring an adaptive landscape with natural selection pushing a population
towards higher fitness states corresponding to peaks in this landscape
(see e.g. Figure \ref{fig:fitness_landscape_1D}).  \graham{Simpson/Wright.}
\citet{lande1976natural} found an evocative formulation of the
Breeder's equation which aids our intuition of phenotypic fitness
landscapes. \graham{need note about when this breaks down}
\citeauthor{lande1976natural} showed that,
if the phenotype is
normally distributed, the response to
selection ($R$) could be written in terms of the gradient (derivative) of the
mean fitness ($\wbar$) of the population\sidenote[][-3cm]{
  This follows from the fact that we can then move the
  derivative inside the integral of $\wbar$, eqn \eqref{eqn:pheno_mean_fitness}, %$\nicefrac{\partial \log\wbar}{\partial \bar{x}} = \nicefrac{1}{\wbar} \nicefrac{\partial\wbar}{\partial \bar{x}}$.
to write the new term in eqn \eqref{eqn:pheno_fitness_landscape} as
  \begin{align}
\frac{1}{\wbar}  \frac{\partial \wbar}{\partial \bar{x}} &=
                                                                   \frac{1}{\wbar}
                                                                   \int_{-\infty}^{\infty}w(x)
                               \frac{\partial p(x)}{\partial \bar{x}}  dx \nonumber\\
& =\int_{-\infty}^{\infty} \frac{w(x)}{\wbar}  \frac{(x-\bar{x})}{V}  dx  \nonumber\\
                             & = \frac{cov(w(x),x) }{var(x)} \label{eqn:proof_landscape}
\end{align}
which is $\beta$, so that eqns \eqref{eqn:R_beta} and
\eqref{eqn:pheno_fitness_landscape} are equivalent. For this equivalence
to hold, in the first line we assume that $w(x)$ is not a function
of $\bar{x}$, while the middle line is true when $p(x)$ is the normal distribution.
}
as a function of the mean phenotype:
\begin{equation}
  R = \frac{V_A}{\wbar} \frac{\partial \wbar}{\partial \bar{x}}  \label{eqn:pheno_fitness_landscape}  %V_A
 % \frac{\partial \log \left(\wbar \right)}{\partial \bar{z}}
\end{equation}

What does this mean? Well $\nicefrac{V_A}{\wbar}$ is always positive,
so the direction our population responds to selection is
predicted by the sign of the derivative (see Appendix Section
\ref{section:calculus} for more on derivatives). If increasing the mean
phenotype of the population slightly would
increase mean fitness ($ \nicefrac{\partial \wbar}{\partial \bar{x}}
>0$) our population will respond that generation by evolving toward
higher values of the trait ($R>0$), left panel of Figure \ref{fig:fitness_landscape_1D_w_wbar}. Conversely, if decreasing the
population mean phenotype slightly would increase the mean fitness ($ \nicefrac{\partial \wbar}{\partial \bar{x}}
<0$) the population will that generation evolve towards lower values
of the phenotype  (middle panel of Figure
\ref{fig:fitness_landscape_1D_w_wbar}). Thus, if selection pressures
remain constant, we can think of the population as evolving on
an adaptive landscape where the elevation is given by the population mean
fitness. Natural selection operates on the basis of individual-level
fitness, but as a result of this our population is increasing in its
average fitness, i.e. our population is becoming better adapted. We'll
discuss the caveats of this hill-climbing interpretation below.

 \begin{figure*}
 \begin{center}
 \includegraphics[width= 0.8 \textwidth]{figures/Response_to_sel/fitness_landscape_1D_w_wbar.pdf}
 \end{center}
 \caption{A population evolving on a (guassian) fitness surface. The
   bottom panel shows the expected individual fitness ($w()$) and mean
   fitess as a function of phenotype. The red line shows the best
   fitting linear approximation to the relationship between phenotype
   and individual fitness, eqn \eqref{fitness_regression}, whose slope is
   $\beta$. The top panel shows the distribution of the phenotype
   before and after selection. \gitcode{https://github.com/cooplab/popgen-notes/blob/master/Rcode/Quant_gen/fitness_landscape_1D_animated.R}.} \label{fig:fitness_landscape_1D_w_wbar}
 \end{figure*}

What happens when it
reaches the top of a peak? Well at the top of a peak $ \nicefrac{\partial
  \wbar}{\partial \bar{x}}=0$, as it is a local maximum, and so
$R=0$. Assuming that the relationship between fitness and phenotype
stays constant, our population will stay at the top of the fitness
peak. This view of natural selection does not imply that the population
is evolving to the best possible state. Our population is just
marching up the hill of mean fitness (end panel Figure
\ref{fig:fitness_landscape_1D_w_wbar}). However, this peak isn't
necessarily the highest fitness peak but simply whichever peak was closest. So our population can become trapped
on a local, but not global peak of fitness (see, for example Figure \ref{fig:fitness_landscape_1D}).

% % \animategraphics[height=2.8in,autoplay,controls]{12}{/Users/gcoop/Downloads/latex_gif/animate_gall_}{0}{14}

\begin{marginfigure}[3cm]
\begin{center}
\includegraphics[width= \textwidth]{Journal_figs/Quant_gen/Stickleback_fossil_traj/Stickleback_fossil_traj.pdf}
\end{center}
\caption{{\bf Top)} A time series of stickleback phenotypic evolution from the
  fossil record. After a heavily armoured stickleback invades the lake
  it quickly evolves towards fewer touching pterygiophores (the bones
  supporting the dorsal spines).  Fossil measurements means are
  calculated in 250 year bins. {\bf Bottom)} How our population moves
  on the Inferred fitness landscape. The arrows show each move made by
  the population in the 250 intervals. Data from
  \citet{bell2006inferring} and \citet{hunt2008evolution}  \gitcode{https://github.com/cooplab/popgen-notes/blob/master/Journal_figs/Quant_gen/Stickleback_fossil_traj/Stickleback_traj.R} } \label{fig:Stickleback_fossil_traj}
\end{marginfigure}

One dramatic example documenting adaptive evolution to a new
fitness optimum is offered by a remarkable time-series of
stickleback evolution from a fossil lake-bed in Nevada \citep{bell2006inferring}. In this lake
the layers of sediment are laid down each year allowing a very detailed
time series with over five thousand fossils measured. The time-series
documents the evolution towards a new set of optimum phenotypes in the
fifteen thousand years after the initial invasion of the lake by a
heavily armoured stickleback species. In Figure \ref{fig:Stickleback_fossil_traj} the population mean number of
touching pterygiophores, the bones supporting the dorsal spines,
through the fossil record (Figure \ref{fig:Stickleback_fossil}). Note how quickly the species evolves toward
its new value, presumably a fitness optimum in their new environment, and the long subsequent time interval over which
the population mean phenotype fluctuates about its new value.
\begin{marginfigure}
 \begin{center}
 \includegraphics[width= \textwidth]{illustration_images/Quant_gen/Fossil_stickleback/journal.pbio.1001466.g003.eps}
 \end{center}
 \caption{Fossil stickleback. Photo by Peter J. Park from \citet{losos2013evolutionary}, \PLOSccBY.} \label{fig:Stickleback_fossil}
\end{marginfigure}

\citet{hunt2008evolution} fitted a model of a population adapting to a
fitness landscape, with a single peak, to these time-series data. Their fitted fitness
surface is shown in the lower panel of Figure \ref{fig:Stickleback_fossil_traj} . The arrows show the moves that the
population mean phenotype is making on this inferred fitness
surface. The population initially takes large steps up toward the peak
of this surface and subsequently fluctuates around the peak. Under the
interpretation that there is a single stationary peak these
fluctuations represent genetic drift randomly knocking the population
off its optimum, with selection acting to restore
the population towards this local optimum.

\paragraph{Issues with the interpretation of fitness landscapes.}
In practice, fitness landscapes may not be constant. The environment
may be constantly changing so our population is constantly forced to change to keep
up with the fitness peak. Indeed our environment may change so quickly
that our population cannot keep up with the peak. Our
population is still trying to increase its mean fitness, to `adapt', but
the landscape itself is evolving.%\sidenote[][1cm]{
  In
the case of very rapid environmental change our population may slide
further and further away the peak, and as a consequence its mean fitness
decreases which may drive the population to extinction if our
population drops below $\wbar<1$ for long enough. The conditions for
extinction are an active area of research in the field of
`Evolutionary rescue'. %}
More generally, for our fitness landscape result (eqn \eqref{eqn:pheno_fitness_landscape}) to hold, and
for us to be able to talk of our population attempting to evolve to
higher mean fitness states,  we need the fitness of our phenotypes to be independent of the
frequency of other phenotypes in the population. (This independence allows us to
assume that the fitness of individuals is not a function of the mean
phenotype, as needed in eqn \eqref{eqn:proof_landscape}).  The
assumption of frequency independence may not hold when there is competition between individuals, e.g. for resources or
mates, as then the fitness of an individual depends on the strategies pursued
by other individuals in the populations.
%A classic example of this is
%the fact that sexual selection may drive our
%population towards pursing mate choice strategies that actively lower
%the mean fitness of the population.
% \graham{Thinking of a marble
% rolling around in the bottom of a bowl
% You could think about the
% population phenotype as a marble rolling around  }

%\paragraph{Different populations potentially sit on top of different peaks in the fitness landscape}
 % https://journals.plos.org/plosbiology/article?id=10.1371/journal.pbio.1000529

 \subsection{Stabilizing and Disruptive selection}

Up to now we have just looked at directional selection, where
selection acts to change the mean phenotype. However, we
can also use quantitative genetic models to describe other modes of
selection, extending from effects on the population mean the next
natural step is to think about selection which acts on the
population variance. Selection might act more strongly against
individuals in the tails of the distribution, with those closer
to the mean phenotype having higher fitness, which lowers the
variance. Selection could also disfavour individuals close to the
population mean, with individuals with extreme phenotypes having
higher fitness, which acts to increase the variance of the population.

Directional selection occurs because of the covariance
between our phenotype and fitness, eqn \eqref{S_covar}. Just as expressing directional selection as a covariance allowed us to
characterize directional selection as the linear relationship between
fitness and phenotype, $\beta$, we can summarize the variance
reducing selection by including a quadratic term in the regression of
fitness on phenotype
\begin{equation}
w_i \sim \beta x_i + \nicefrac{1}{2}  \gamma x_i^2  + \wbar \label{fitness_regression_stab}
\end{equation}
This $\gamma$, the coefficient of the quadratic term in our model, is the
quadratic selection gradient: the covariance of fitness and the squared
deviation from the phenotypic mean ($\mu_{BS}$), i.e.
\begin{equation}
\gamma = \frac{Cov\left(w(X), (X-\mu_{BS})^2 \right)}{V^2}
\end{equation}
Our $\gamma$ describes the curvature of the fitness surface around the
mean. \marginnote[-1.5cm]{Just like how $\beta$ could be interpreted
as the mean gradient of the fitness surface, our $\gamma$ is the
mean curvature of the fitness surface
  \begin{equation}
\gamma = \E \left[\nicefrac{\partial^2 w(x)}{\partial x^2}  \right] =
\int \nicefrac{\partial^2 w(x)}{\partial x^2} p(x) dx
\end{equation}
see Appendix Section \ref{section:calculus} for more on 2nd derivatives.
\graham{Need to straighten out issues with mean fitness vs fitness in
  these sections}
}
Values of $\gamma<0$  are consistent with stabilizing selection,
reducing the variance. While values of $\gamma>0$ are consistent with disruptive
selection, increasing the variance. \graham{add refs about this not being sufficient}

%To do this we can think about how selection acts

% https://onlinelibrary.wiley.com/doi/pdf/10.1111/j.1469-1809.1951.tb02469.x

\begin{figure}
\begin{center}
\includegraphics[width= 0.6 \textwidth]{Journal_figs/Quant_gen/birth_weight/Karn_Penrose_birth_weight.pdf}
\end{center}
\caption{Bars show the total number of births with different birth
  weights (left axis)  Dots show the mortality probability for different
  birth-weight bins (right axis), the red line shows a fitted
  quadratic model to mortality. Data from \citet{karn1951birth}
  Table 2, collapsing male and female births, \gitcode{https://github.com/cooplab/popgen-notes/blob/master/Journal_figs/Quant_gen/birth_weight/birth_weight_selection.R} } \label{fig:Birth_weight}
\end{figure}

Under stabilizing selection the individuals with extreme phenotypes in
either tail have lower fitness, the result of which is to reduce the
phenotypic variance within a generation. A classic case of stabilizing selection
is birth weight in humans \citep{karn1951birth}. Mary Karn collected
data for nearly fourteen thousand pregnancies from 1935-46 for birth
weight and mortality. These data are replotted in Figure
\ref{fig:Birth_weight}. The variance of all births is $1.575$lb$^2$, while in live births this
was reduced to $1.26$lb$^2$, a 20\% reduction in variance due to
stabilizing selection. It is worth noting that this selection
pressure has been greatly reduced over the decades in societies with
access to good prenatal care \citep{ulizzi1992natural}.  %, a large effect of which has been to
%reduce the variance in birth weights due to better nutrition

%womb https://www.google.com/search?q=leonardo+da+vinci+baby&tbm=isch&source=iu&ictx=1&fir=pl1GYGee8iN0gM%253A%252CEdMTKcL8foK_hM%252C_&vet=1&usg=AI4_-kRCaAAUfKDX5AEtEm6lUZ5hjWMPlw&sa=X&ved=2ahUKEwjkluyapsniAhVWs54KHX7GBFsQ9QEwA3oECAMQCg#imgrc=W3ZPdyKQE9YkRM:&vet=1

\begin{marginfigure}
\begin{center}
\includegraphics[width= \textwidth]{illustration_images/Quant_gen/Pyrenestes_seedcracker/Pyrenestes_minor.jpg}
\end{center}
\caption{Lesser seedcracker {\it Pyrenestes minor} a close relative of
  the Black-bellied seedcracker, whose beak is about the same size as
  the smallest Black-bellied individuals. \BHLNC{The birds of Africa, comprising all the species
    which occur in the Ethiopian region. (1986) Sclater, W. L Plate by  H. Gr{\"o}nvold}{https://archive.org/stream/birdsofafricacom41shel/birdsofafricacom41shel\#page/n306/mode/1up}{Smithsonian Libraries} }
\end{marginfigure}
In Central Africa, Black-bellied seedcrackers ({\it
  Pyrenestes ostrinus}) show disruptive selection on a remarkable beak-size polymorphism (Figure \ref{Black_bellied_seedcrackers_beaks}).  The small-beaked individuals feed on
soft  seeds from one species of marsh sedge while the big-beaked
individuals feed on hard seeds from another sedge, which
requires ten times the force to crack. \citet{smith1993disruptive}
recorded the fates of hundreds of juveniles, and found that
individuals with intermediate beak sizes survived at much lower rates
(Figure \ref{Black_bellied_seedcrackers_beaks}) because they were not
well adapted to either seed resource.  Break length is subject to
disruptive selection, as can also be seen by the significant negative quadratic
term in the regression of survival probability on break length. The
variance of mandible length in the total sample of individuals was
$0.5$mm$^2$ in the survivors this variance increased by a factor of $2.5$ to $1.3$mm$^2$.

\begin{figure}
\begin{center}
\includegraphics[width= \textwidth]{Journal_figs/Quant_gen/Smith_black_bellied_seed_cracker/Smith_black_bellied.pdf}
\end{center}
\caption{ {\bf Left} An illustration of the the remarkable variation
  in beak size within Black-bellied seedcrackers ({\it  P.
    ostrinus}). {\bf Right} A histogram of a beak size measurement in
  Black-bellied seedcrackers. All juveniles are shown in grey, while the
  black bars show the survivors. The red curve shows the best fitting
  linear and quadratic model to the probability of survival, fitted
  using a binomial generalized linear model with a logit link function.
  \BHLNC{Left illustration from: Size variation in {\it Pyrenestes} by
    Chapin J.P. in the Bulletin of the
    American Museum of Natural History (Vol. XLIX
    1923)}{https://archive.org/stream/bulletinofameric49alleuoft/\#page/417/mode/1up}{Toronto
    Library}   } \label{Black_bellied_seedcrackers_beaks}
\end{figure}

To illustrate how directional selection and quadratic terms play off
during adaptation, lets consider the goldenrod gall fly ({\it Eurosta solidaginis}), aka the goldenrod
ball gallmaker. See Figure \ref{gall_size_stab}. As it's wonderful name
implies this insect lays its eggs in Goldenrod plants, and the larvae
release chemicals forcing the plant to form a gall that forms a home
for the larvae as they develop. While this seems like a pretty sweet
deal for the larvae, it is not without its perils. \begin{marginfigure}[2cm]
\begin{center}
\includegraphics[width= 0.7 \textwidth]{illustration_images/Quant_gen/goldenrod_ball_gall_maker/goldenrod_ball_gall_maker.png}
\end{center}
\caption{The gall formed by the goldenrod
ball gallmaker ({\it Eurosta solidaginis}) in a goldenrod plant. The
one on the right is cut to show a partial cross-section. \BHLNC{Annual report of the New York State Museum (1917)}{https://archive.org/stream/annualreport71newy/\#page/196/mode/1upp}{The LuEsther T Mertz Library, the New York Botanical Garden} }
\end{marginfigure}
When the small, ball galls fall risk of parasitism from parasitoid
wasps. When all the ball galls are small in the population selection drives strong positive directional selection on
gall size, with little stabilizing selection. Notice in the left panel
of Figure \ref{gall_size_stab} the good
agreement between the linear selection gradient and the fit including
a linear and quadratic term. However, bigger galls fall under the pall of predation from downy
woodpeckers and black-capped chickadees, who seek out the tasty
larvae. Thus intermediate size galls are favoured, a fitness peak that
the population quickly reaches. Once on this peak,
as shown in the right panel of Figure \ref{gall_size_stab} there is no directional selection, i.e. no linear slope, but there
is strong stabilizing selection, i.e. a quadratic term. Thus the
population will be maintained at this fitness peak indefinitely if the
environment remains unchanged.

\begin{figure}
\begin{center}
\includegraphics[width= \textwidth]{Journal_figs/Quant_gen/Weis_Gorman_gall_size_stablizing_sel/gall_size.pdf}
\end{center}
\caption[][4cm]{Fitness surface for gall diameter in goldenrod
ball gallmakers. The dots are the measured survival probabilities of
bins of different sized galls.The solid line is a fitted individual fitness
  surface ($w(~)$). Dotted line is $\wbar$ plotted as a function of
  the population mean assuming a normal distribution with a standard
  deviation of $2$mm. Data from \citet{weis1990measuring}, \gitcode{https://github.com/cooplab/popgen-notes/blob/master/Journal_figs/Quant_gen/Weis_Gorman_gall_size_stablizing_sel/gall_size_fitness_landscape.R}} \label{gall_size_stab}
\end{figure}

%%% selection on gall size https://sci-hub.tw/https://onlinelibrary.wiley.com/doi/abs/10.1111/j.1558-5646.1990.tb03807.x
% https://www.flickr.com/photos/internetarchivebookimages/18429735991/
%https://archive.org/stream/annualreport71newy/#page/196/mode/1up

%black beelied seed cracker
%https://sci-hub.tw/https://www.nature.com/articles/363618a0
%https://www.flickr.com/photos/internetarchivebookimages/20416920856/in/photolist-otagrj-xVVxst-wRSxF1-x7b4fQ-x9uxzB
%https://www.flickr.com/photos/internetarchivebookimages/14755609045/

% Cross bill https://www.google.com/search?q=loxia+curvirostra+biodiversity+heritage+library&source=lnms&tbm=isch&sa=X&ved=0ahUKEwjItfbRm87iAhUyMn0KHZDNDlIQ_AUIECgB&biw=1440&bih=726#imgrc=cfi-GvhZRX1zxM:
% https://sci-hub.tw/https://www.jstor.org/stable/2937103?seq=1#metadata_info_tab_contents

%file:///Users/gcoop/Downloads/calsbeek2008.pdf  disruptive selection
%on leg length in anoles


\documentclass{article}

\usepackage{amsmath}
\usepackage{graphicx}

\title{Performance analysis of Statime as compared to LinuxPTP}
\author{Dion Dokter \and Ruben Nijveld \and David Venhoek}

\begin{document}

\maketitle

\section{Introduction}

In this paper, we present a quantitative comparison of statime synchronization performance as compared to the LinuxPTP implementation of PTP. In particular, we focus on comparing the precision and offset of the time synchronization of both setups.

The comparison was done over relatively short time intervals of about two hours. Over these periods we find that, due to incomplete support for hardware timestamping, the precision of statime is still $2$ orders of magnitude larger than that of LinuxPTP.

\section{Measurement setup}

Our measurement setup consists of 3 main parts:
\begin{itemize}
    \item An endrun ninja ptp grandmaster clock synchronized via GPS.
    \item A raspberry pi 4 compute module with an Intel i210 NIC
    \item A Basys-3 FPGA development board setup to measure pps pulses.
\end{itemize}

The ptp grandmaster is connected via a direct ethernet cable to the i210 nic, and this connection is used to carry the PTP messages. Both the ptp grandmaster and the intel nic are configured to produce pulse-per-second outputs. Furthermore, the raspberry pi is also configured to produce a pulse-per-second output on its gpio pins.

All these pulses are measured by the FPGA relative to its internal clock. Although this internal clock is not precise, we can estimate its frequency using the pulse-per-second signal from the ptp grandmaster.

The grandmaster configuration is the default provided by endrun, and the grandmaster is given time to fully lock onto the GPS signal before start of measurement (specifically, we wait until the clock quality reported by gpsstat is at level 3).

On the raspberry pi, depending on the run we either start the LinuxPTP stack or statime. We then wait with starting the measurement until the self-reported offset to the grandmaster appears stable.

\section{Error estimates}

In our analysis we have included the following 4 main error sources: Cable length differences, fpga input path differences, discretization error, and fpga clock instability. Below we will discuss each, including their contributions to our estimated error.
\subsection{Cable length}
The setup contains cables of multiple lengths and varying electrical characteristics. We will estimate these errors pessimistically and assume maximum systematic errors up to the propagation delay of our longest possible cable. As all our cables are below 1.5 meters in length, this gives us an estimated 15ns of systematic error.
\subsection{FPGA input architecture}
Although care has been taken in the VHDL code the fpga has been programmed with to keep the input path for all of the signals identical, due to the fact that these interact with different pieces of the physical hardware there can still be offsets between processing delays for the inputs. Based on the documentation of the FPGA's architecture, we assume these to contribute 1 fpga clock cycle of systematic error.
\subsection{Discretization error}
The pulse per second signals arrive at the fpga unsynchronized with the fpga's clock. Due to this, their measured arrival time may be off by up to 1 clock cycle, giving us a statistical error of 1 fpga clock cycle.
\subsection{FPGA clock instability}
The clock in the fpga is of relatively low quality, and may therefore be somewhat unstable. We will use the pulse-per-second signal measured from the grandmaster clock to estimate the frequency instability of the fpga's clock, which will provide us with an additional statistical error component.

\section{FPGA clock callibration}

We callibrate the FPGA clock using the data from the GM pulse-per-second signal. This process purely uses difference between arrival times of these pulses, hence errors from cable length can be ignored in the following analysis. Note that over short time intervals, the clock frequency seems quite stable, with the second interval only varying by 1 clock cycle around a central value over short time periods. To compensate for any longer-term drift of the FPGA clock frequency, we do this calibration on a per-run basis.

\begin{figure}[h]
\includegraphics[width=0.5\textwidth]{gm_clocks_overtime_ref.pdf}\includegraphics[width=0.5\textwidth]{gm_clocks_overtime_statime.pdf}
\caption{FPGA clock cycles per second over time, time axis is arbitrary. On the left is data from the LinuxPTP run, on the right from the statime run. Glitch marks points where some seconds of data have been removed due to jiggling of connectors causing spurious edges.}
\label{fig:gm_cycles_over_time}
\end{figure}

\begin{figure}[h]
\includegraphics[width=0.5\textwidth]{gm_clocks_per_sec_ref.pdf}\includegraphics[width=0.5\textwidth]{gm_clocks_per_sec_statime.pdf}
\caption{FPGA clock cycles per second as measured using the GM pulse-per-second output. On the left is data from the LinuxPTP run, on the right from the statime run.}
\label{fig:gm_cycles_per_second}
\end{figure}

For the LinuxPTP run, the measurement data are plotted in Figure~\ref{fig:gm_cycles_per_second}. Analysing this shows the fpga clock ticks $99999599\pm 1.7 (\text{stat.}) \pm 1.0 (\text{sys.})$ per second. Hence, a single clock tick of the fpga clock takes $10.00004010 \pm 0.00000017 (\text{stat.}) \pm 0.00000010 (\text{sys.})$ nanoseconds during the LinuxPTP run.

For the statime run, analysis shows the fpga clock ticks $ 99999638 \pm 7.8 (\text{stat.}) \pm 1.0 (\text{sys.})$ per second. Hence, a single clock tick of the fpga clock takes $10.00003620 \pm 0.00000078 (\text{stat.}) \pm 0.00000010 (\text{sys.})$ nanoseconds during the statime run.

\section {LinuxPTP performance analysis}

\begin{figure}[h]
\includegraphics[width=0.5\textwidth]{gm_ref_offset_overtime.pdf}\includegraphics[width=0.5\textwidth]{gm_ref_offset.pdf}
\caption{System clock offset to GM, both overtime and frequency of observations, as synchronized by LinuxPTP. (Negative values indicate that the clock is ahead of the GM.)}
\label{fig:ref_sys_offset}
\end{figure}

Analysing the offset data for the system clock synchronized by LinuxPTP, we find that this gives a constant offset $-3576,40\pm 0.95 (\text{stat.}) \pm 25(\text{sys.})$ nanoseconds, which could be eliminated by tuning the port assymetry. Furthermore, we see 90\% of all observations fall within $126 \pm 10 (\text{stat.})$ nanoseconds of this constant offset.

\section{Statime performance analysis}

\begin{figure}[h]
\includegraphics[width=0.5\textwidth]{gm_statime_offset_overtime.pdf}\includegraphics[width=0.5\textwidth]{gm_statime_offset.pdf}
\caption{System clock offset to GM, both overtime and frequency of observations, as synchronized by Statime. (Negative values indicate that the clock is ahead of the GM.)}
\label{fig:statime_sys_offset}
\end{figure}

Analysing the offset data for the system clock synchronized by Statime, we find that this gives a constant offset $-23570\pm 90(\text{stat.})\pm 25 (\text{sys.})$ nanoseconds, which could be eliminated by tuning the port assymetry. Furthermore, we see 90\% of all observations fall within $11250 \pm 10(\text{stat.})$ nanoseconds of this constant offset.

\section{Conclusions}

Comparing the results of the statime and LinuxPTP, we observe that statime is $2$ orders of magnitude less precise. We think that this is primarily the result of the fact that statime does not yet have support for hardware timestamping.

In line with the observed decreased precision, we also see an associated increase in fixed offset. This is likely primarily due to assymetry within the linux kernel's networking stack, which becomes more significant when relying on software timestamping.
\end{document}


%------------------------------------------------------------------------------
\chapter{Orbit Propagation}
\label{cha:OrbitPropagation}
%------------------------------------------------------------------------------

%------------------------------------------------------------------------------
\section{Overview}
%------------------------------------------------------------------------------

One of the key elements of a space surveillance system is the propagation technique used in the orbit determination process. While the first surveillance systems in the \acrshort{acr:us} and the Soviet Union
employed fast analytical techniques, also known as \gls{acr:gp} methods, with today's computational limitations virtually non-existing, it is common to use so-called \gls{acr:sp} techniques,
which perform the numerical integration of a detailed force model. The numerical propagation tool \neptune (\acrlong{acr:neptune}) was designed to be used in the context of a space surveillance system and is described in detail in the following.
\begin{figure}[h!]
 \centering
 \includegraphics[width=0.5\textwidth]{neptune_logo.png}
 \caption{\neptune logo.\label{fig:neptune-logo}}
\end{figure}
The first step was to define the required force model and select state-of-the-art methods that would be implemented to meet the need in the intended context. Therefore, besides a 3 \gls{acr:dof} propagation for the state vector, \neptune has also
the capability to propagate the covariance matrix, which is an essential step in the filtering process within the statistical orbit determination. Finally, the concept of
including time-correlated (coloured) noise into the filtering application was studied in detail and shall be presented here, based on the work of
\citet{nazarenko2010}.

The coordinate and time systems implemented in \neptune are based on the \gls{acr:iau} recommendations and will be outlined in \sect{sec:propagation-coordinates}. Especially the
conversion from the inertial to the Earth-fixed frame and vice versa is computationally expensive, so that a method has been devised to significantly improve
computation speed without significant performance loss.

It is possible to define the shape of the satellite used in a \neptune propagation with a very simple geometry, which shall be described in
\sect{sec:propagation-satellite-model}. That approach served as a simple method to simulate box-wing configurations in the validation of \neptune (see \cha{cha:validation}).

The numerical integrator and the force model will be given in detail in \sect{sec:propagation-state}, while the details for the covariance matrix propagation are provided in
\sect{sec:propagation-covariance}.

Finally, the process noise, which results in additional contributions to the covariance propagation due to uncertainties in the force model, will be detailed in \sect{sec:noise}.
Different methods to incorporate noise into filtering applications shall be described with a focus on coloured noise, as especially the geopotential shows significant time-correlations.

%------------------------------------------------------------------------------

\input{02-Propagation/coordinates}
\input{02-Propagation/satmodel}
\input{02-Propagation/state}
\input{02-Propagation/covariance}
\input{02-Propagation/noise}

%------------------------------------------------------------------------------
%\bibliographystyle{plain}
%\bibliography{wp2report}
%------------------------------------------------------------------------------


%auto-ignore
\providecommand{\MainFolder}{..}
\documentclass[\MainFolder/Text.tex]{subfiles}

\begin{document}

\section{Dual cyclic bar complex and cyclic (co)homology
%for the \texorpdfstring{$\IBLInfty$-theory}{IBL-infinity-theory}
}
\allowdisplaybreaks
\label{Sec:Alg2}
\Correct[caption={DONE Notation for cyclic Hochschild}]{Notation for cyclic Hochschild}
\Correct[caption={DONE Reduced is defined wrt. normalized!},inline]{Reduced is defined as coker or ker in normalized and not in the full complex! It is OK because we have the cyclic symmetry!}
\Modify[caption={DONE Convention for duals},inline]{The convention for cochain complexes will be as follows. Chain complex will be denoted by $C$ and cochain complex by $C^*$. The components will be denoted by $C_q$ and $C^q$. }
%\begin{Notation}[Chain and cochain complexes]
%If $C$ is a chain complex, we will often denote by $C^*$ the
%because $*$.
%$\H(C)$ and by $\H^*(C)=\H(C^*)$ the cohomology of the dual. In fact,
%\end{Notation}
\begin{Definition}[Bar complexes] \label{Def:BarComplex}
Let $V$ be a graded vector space. The \emph{bar- and dual bar-complex of $V$} are the weight-graded vector spaces defined by
$$ \B V\coloneqq \RTen(V[1])\quad\text{and}\quad\DB V \coloneqq (\B V)^{\WGD}, $$
respectively, where $\bar{T}V \coloneqq \bigoplus_{k=1}^\infty V^{\otimes k}$ is the weight-reduced tensor algebra. For every $k\in \N$, let $t_k \in \Perm_k$ be the cyclic permutation $t_k : (1,\dotsc,k) \mapsto (2,\dotsc,k,1)$,
so that for all $v_1$, $\dotsc$, $v_k \in V[1]$ we have
\begin{equation*}
%\label{Eq:tk}
t_k(v_1 \otimes \dotsb \otimes v_k) = (-1)^{\Abs{v_k}(\Abs{v_1} + \dotsb + \Abs{v_{k-1}})} v_k \otimes v_1 \otimes \dotsb \otimes v_{k-1}.
\end{equation*}
%We also let $t_0: V[1]^{\otimes 0} \rightarrow V[1]^{\otimes 0}$ be the identity $\R[1] \rightarrow \R[1]$ and set
We set
$$ t\coloneqq \sum_{k=1}^\infty t_k : \B V \longrightarrow \B V. $$
The \emph{cyclic bar-complex} is defined by
$$ \BCyc V \coloneqq \B V / \Im(1-t). $$
%It can be written as
%$$ \BCyc V = \bigoplus_{\substack{k\in \N \\ d\in \Z}} (\BCyc V)^d_k $$
%with
%$$ (\BCyc V)^d_k \coloneqq (\B V)_k^d/\Im(1-t_k), $$
%and hence it is a weight-graded vector space.
We denote the image of $v_1 \otimes \dotsb \otimes v_k \in \B V$ under the canonical projection $\pi: \B V \rightarrow \BCyc V$ by $v_1\dots v_k$. If $v_i\in V[1]$ are homogenous, then $v_1\dots v_k$ is called a \emph{generating word}; we have
\begin{equation*}
v_1 \dots v_k = (-1)^{\Abs{v_k}(\Abs{v_1}+\dotsb + \Abs{v_{k-1}})} v_k v_1 \dots v_{k-1}.
\end{equation*}
We define the section $\iota: \BCyc V \rightarrow \B V$ of $\pi$ by
$$ \iota(v_1\dots v_k) \coloneqq \frac{1}{k} \sum_{i=0}^{k-1} \underbrace{t_k^i}_{\mathrlap{\displaystyle \eqqcolon t_k \circ \dotsb \circ t_k\ i\text{-times}}}(v_1\otimes\dotsb \otimes v_k) $$
and use it to identify $\BCyc V$ with the subspace $\Im \iota = \Ker(1-t) \subset \B V$ consisting of cyclic symmetric tensors.

We define the \emph{dual cyclic bar-complex} by
$$ \DBCyc V \coloneqq \{ \psi\in \DB V \mid \psi \circ t = \psi \}. $$
%and identify it with $(\BCyc V)^{\WGD}$ by defining
%\begin{equation} \label{Eq:PairingCyc}
%\psi(v_1\dots v_k) \coloneqq \psi(v_1\otimes \dotsb \otimes v_k)
%\end{equation}
%for all $\psi \in \DBCyc V$ and generating words $v_1\dots v_k\in \BCyc V$.
\end{Definition}

\begin{Remark}[Non-weight-reduced bar complex]\label{Rem:NWG}
In fact, our $\DBCyc V$ is weight-reduced. The non-weight-reduced version would be $\DBCyc V \oplus \R$ with $\R$ of degree~$0$. This might play a role in the theory of  weak $\AInfty$-algebras ($\coloneqq$\,operation $\mu_0$ added; c.f., Definition~\ref{Def:CyclicAinfty}), and it might also be possible to consider $\IBLInfty$-algebras on non-weight-reduced cyclic cochains (c.f., Section~\ref{Sec:Alg3}).
%However, this is outside of the scope of our text.
\end{Remark}

Notice that $\psi \in \DB V$ is homogenous of degree $\Abs{\psi}\in \Z$ if and only if for all homogenous $v_1$,~$\dotsc$, $v_k \in V[1]$ the following implication holds:
\begin{equation*}
\Abs{v_1} + \dotsb + \Abs{v_k} \neq \Abs{\psi}\quad\Implies\quad \psi(v_1\otimes \dotsb \otimes v_k) = 0.
\end{equation*}
This is the cohomological grading convention.

\begin{Notation}[Degree shifts of bar complexes] \label{Def:Notation}
Let $A\in \Z$. In the following, we write $\DBCyc V$, but the convention applies to all complexes from Definition\,\ref{Def:BarComplex}. We denote by $\Susp_A$ and $\SuspU$ the formal symbols of degrees
$$ \Abs{\Susp_A} = -A \quad \text{and}\quad\Abs{\SuspU} = -1, $$
respectively. The degree shift $V \mapsto V[1]$ will be realized as  multiplication with~$\SuspU$ and the degree shift $\DBCyc V\mapsto \DBCyc V[A]$ as multiplication with~$\Susp_A$. In addition, the following notation will be used consistently:
\begin{itemize}
 \item $\tilde{v}\in V \longleftrightarrow v = \SuspU \tilde{v} \in V[1]$

  To clarify this, given $\tilde{v} \in V$, then~$v$ automatically means $v = \SuspU \tilde{v} \in V[1]$, and the other way round. Recall that the degree of $\tilde{v}\in V$ is denoted by~$\Deg(\tilde{v})$ or simply by $\tilde{v}$ in the exponent, e.g., $(-1)^{\tilde{v}}$.
 \item  $\psi\in\DBCyc V\longleftrightarrow \Psi = \Susp_A \psi\in \DBCyc V[A]$.
 \item A generating word of $\BCyc V$ of weight $k$ will be denoted by the symbol $w$ and written as $w= v_1 \dots v_k$, where $v_i = \SuspU \tilde{v}_i \in V[1]$. A generating word of $\Ext_k \BCyc V$ is an element $w_1 \dotsb w_k \in \Ext_k \BCyc V$ such that each~$w_i$ is a generating word of $\BCyc V$.
 \item $w\in \BCyc V\longleftrightarrow \text{\footnotesize W} = \Susp_A w \in \BCyc V[A]$.
\end{itemize}
We abbreviate
$$ \DBCyc V[A]\coloneqq (\DBCyc V)[A]. $$
%,\quad \Ext \DBCyc V[A]\coloneqq \Ext(\DBCyc V[A]).
In contrast to this, we would write $\DBCyc(V[A])$ for the dual cyclic bar-complex of~$V[A]$. We also identify $(\DBCyc V[A])[1] = \DBCyc V[A+1]$ in $\Ext \DBCyc V[A]$.
\end{Notation}

%and $(\Ext\DBCyc V)[A]$ for the degree shift of~$\Ext\DBCyc V$ by~$A$.
\begin{Definition}[Pairing of tensor powers of bar complexes]\label{Def:Pairings}
For every $A\in \Z$ and  $k\in \N$, we define the pairing as follows:
\begin{equation} \label{Eq:Pairing}
\begin{aligned}
(\DB V[A])^{\otimes k} \otimes (\B V[A])^{\otimes k} & \longrightarrow \R \\
(\Psi_1 \otimes \dotsb \otimes \Psi_k, \W_1 \otimes \dotsb \otimes \W_k) & \longmapsto \underbrace{\psi_1(w_1) \dots \psi(w_k)}_{\mathllap{\textstyle{(\Psi_1 \otimes \dotsb \otimes \Psi_k)(\W_1\otimes \dotsb\otimes \W_k)\coloneqq}}}.
\end{aligned}
\end{equation}
This means that we evaluate elements from the left-hand side on the elements from the right-hand side in this way without any signs (see the discussion in Remark~\ref{Rem:BadConvention}). We extend the pairing by $0$ if the number of $\Psi_i$'s and the number of $\W_i$'s differ.
\end{Definition}

\begin{Remark}[Dual bar complex and dual of the bar complex] \label{Rem:Identifications}
Because the pairing~\eqref{Eq:Pairing} is non-degenerate, we can embed the space on the left into the the linear dual of the space on the right.
%; this is used in the proof of Lemma \eqref{Lemma:GraphPairing}.
From Definition~\ref{Def:BarComplex} we have $\DBCyc V \subset \DB V$, and $\BCyc V$ is identified with $\Im \iota \subset \B V$. Therefore, we can restrict \eqref{Eq:Pairing} to obtain the pairing of $\DBCyc V$ and $\BCyc V$. It is easy to see that for any $\psi\in \DBCyc V$ and any generating word $v_1\dots v_k \in \BCyc V$, we have
\begin{equation*}
%\label{Eq:BCycIdent}
\psi(v_1\dots v_k) = \psi(v_1 \otimes \dotsb \otimes v_k).
\end{equation*}
The subspace of $(\BCyc V)^{\LD}$ corresponding to $\DBCyc V$ is then precisely $(\BCyc V)^{\WGD}$.

More generally, for every $k\in \N$, the spaces $\Ext_k \DBCyc V$ and $\Ext_k \BCyc V$ are embedded into $(\DBCyc V[1])^{\otimes k}$ and $(\BCyc V[1])^{\otimes k}$, respectively, using $\iota$ and $\pi$ from Definition~\ref{Def:SymAlgebra}. Therefore, the restriction of~\eqref{Eq:Pairing} gives the pairing of $\Ext_k \DBCyc V$ and $\Ext_k \BCyc V$. It is easy to see that for any generating word $w_1\dotsb w_k \in \Ext_k \BCyc V$ and any $\psi_1\dotsb \psi_k\in \Ext_k \DBCyc V$, we have
$$ (\psi_1\dotsb \psi_k)(w_1\dotsb w_k) = \frac{1}{k!}\sum_{\sigma\in \Perm_k} \varepsilon(\sigma,w) \psi_1(w_{\sigma_1^{-1}})\dotsc \psi_k(w_{\sigma_k^{-1}}). $$
The subspace of $(\Ext_k \BCyc V)^{\LD}$ corresponding to $\Ext_k \DBCyc V$  lies in $(\Ext_k \BCyc V)^{\WGD}$; it is equal to $(\Ext_k \BCyc V)^{\WGD}$, provided that $V$ is finite-dimensional.\footnote{The problem is that if $\dim(V) = \infty$, then $(V\otimes V)^* \neq V^* \otimes V^*$.}
\end{Remark}

The weight-graded vector spaces $\B V$ and $\BCyc V$ are canonically filtered by the filtration by weights \eqref{Eq:FiltrWeights}. Their weight-graded duals $\DB V$ and $\DBCyc V$ are filtered by the dual filtrations and the exterior powers $\Ext_k \DB V$ and $\Ext_k \DBCyc V$ by the induced filtration from Definition~\ref{Def:Filtrations}.

\begin{Proposition}[Completed dual cyclic bar complex] \label{Prop:Compl}
Let $V$ be a graded vector space and $A\in \Z$. The filtration of $\DBCyc V$ dual to the weight-filtration of $\BCyc V$ is $\Z$-gapped, Hausdorff,  decreasing and bounded from above. Moreover, the following holds:
$$ \dim(V)<\infty\quad\Implies\quad (WG1)\ \&\ (WG2)\text{ are satisfied.} $$
The same holds for the induced filtration of $\Ext_k \DBCyc V[A]$.

In the sense of Remark~\ref{Rem:Identifications}, we have\Correct[caption={E},noline]{Here should be $A$ instead of $A+1$}
$$ \nCDBCyc V \simeq (\BCyc V)^{\GD}\quad\text{and}\quad \hat{\Ext}_k \DBCyc V[A] \subset (\Ext_k \BCyc V[A+1])^{\GD}, $$
where ``='' holds if $V$ is finite-dimensional.

The \emph{filtration degree} of $\Psi\in \hat{\Ext}_m \DBCyc V[A]$ satisfies
$$ \Norm{\Psi} = \min\{k\in \N_0 \mid \exists \W\in (\Ext_m \BCyc V[A])_k: \Psi(\!\W)\neq 0 \}.$$
\end{Proposition}

\begin{proof}
The proof is clear.
\end{proof}

\begin{Def}[Cyclic $\AInfty$-algebra] \label{Def:CyclicAinfty}
A graded vector space $V$ together with a pairing\Correct[noline,caption={Degree of pairing}]{This should be standardized with the degree of Poincare duality algebra, canonical dIBL algebra, .... The degree should be probably minus the degree of the pairing on $V$ (not $V[1]$)}
$$ \Pair: V[1]\otimes V[1] \rightarrow \R $$
of degree $d\in \Z$ and a collection of homogenous linear maps
$$\mu_k: V[1]^{\otimes k} \rightarrow V[1]\quad\text{for }k\ge 1$$
is called a \emph{cyclic $\AInfty$-algebra of degree~$d$} if the following conditions are satisfied:
\begin{PlainList}
 \item The pairing $\Pair$ is non-degenerate and graded antisymmetric; i.e., we have
  $$ \Pair(v_1,v_2) = (-1)^{1+\Abs{v_1}\Abs{v_2}} \Pair(v_2,v_1) \quad\text{for all }v_1, v_2 \in V[1]. $$
 \item The degrees satisfy $\Abs{\mu_k}=1$ for all $k\ge 1$.
 \item The \emph{$\AInfty$-relations} are satisfied: for all $k\ge 1$, we have
\begin{equation} \label{Eq:AInftyDef}
 \sum_{\substack{k_1, k_2 \ge 1 \\ k_1+k_2 = k+1}} \sum_{p=1}^{k_1} \mu_{k_1} \circ_1^p \mu_{k_2} = 0,
 \end{equation}
where for all $p=1$, $\dotsc$, $k$ and $v_1$, $\dotsc$, $v_{k}\in V[1]$ we define
$$(\mu_{k_1} \circ_1^p \mu_{k_2})(v_1, \dotsc, v_{k}) \coloneqq \begin{multlined}[t] (-1)^{\Abs{v_1} + \dotsb + \Abs{v_{p-1}}} \mu_{k_1}(v_1, \dotsc, v_{p-1},\\ \mu_{k_2}(v_p,\dotsc,v_{p+k_2-1}),v_{p+k_2}\dotsc,v_{k}). \end{multlined}$$

 \item The operations $\mu_k^+: V[1]^{\otimes k+1} \rightarrow \R$ defined by
 $$ \mu_k^+\coloneqq \Pair\circ (\mu_k \otimes \Id) $$
 for all $k\ge 1$ are cyclic symmetric; i.e., we have
 $$ \mu_k^+ \circ t_{k+1} = \mu_k^+. $$
\end{PlainList}
We denote by $\tilde{\Pair}: V\otimes V \rightarrow \R$ and $\tilde{\mu}_k: V^{\otimes k} \rightarrow \R$ the operations before the degree shift; i.e., for all $k\ge 1$ and $\tilde{v}_1$, $\dotsc$, $\tilde{v}_k \in V$ with $v_i = \SuspU \tilde{v}_i$, we have
\begin{align*}
\tilde{\Pair}(\tilde{v}_1, \tilde{v}_2) &\coloneqq (-1)^{\tilde{v}_1} \Pair(v_1, v_2)\quad\text{and} \\[\jot]
\tilde{\mu}_k(\tilde{v}_1, \dotsc, \tilde{v}_k) &\coloneqq \varepsilon(\SuspU,\tilde{v}) \mu_k(v_1,\dotsc, v_k).
\end{align*}
We define $\tilde{\mu}_k^+: V^{\otimes k+1}\rightarrow \R$ similarly.

If $\mu_k \equiv 0$ for all $k\ge 2$, then $(V,\Pair, \mu_1)$ is called a \emph{cyclic cochain complex}. If $\mu_k \equiv 0$ for all $k\ge 3$, then $(V,\Pair,\mu_1,\mu_2)$ is called a \emph{cyclic dga}. We use the same terminology but omit ``cyclic'' if there is no pairing $\Pair$ and 1) and 4) are thus irrelevant.
\end{Def}

\begin{Remark}[A difference in sign conventions]\label{Rem:mukplus}
Our definition of $\mu_k^+$ differs from the definition of $\mathrm{m}_k^+$ in~\cite[Definition 12.1]{Cieliebak2015} by a sign. To compensate this, we have to add this artificial sign in the definitions of Maurer-Cartan elements later; e.g., in Definition~\ref{Def:CanonMC} or in the formula~\eqref{Eq:PushforwardMC}.
\end{Remark}
\Correct[caption={DONE Change sub to sup},noline]{Change $\Hd^k$ to $\Hd_k$ and so on. Why are the indices upstairs?}
\begin{Definition}[Cyclic (co)homology of an $\AInfty$-algebra]\label{Def:CycHom}
Let $\mathcal{A}=(V,(\mu_k))$ be an $\AInfty$-algebra. For every $k\ge 1$, we consider the maps $\Hd'_k$, $R_k: V[1]^{\otimes k} \rightarrow \B V$ given by
\begin{equation}\label{Eq:bRH} \begin{aligned}\Hd'_k & \coloneqq \sum_{j=1}^k \sum_{i=0}^{k-j} t^i_{k-j+1}\circ(\mu_j \otimes \Id^{k-j})\circ t_k^{-i}\quad\text{and}\\
R_k &\coloneqq \sum_{j=2}^k \sum_{i=1}^{j-1} (\mu_j\otimes \Id^{k-j})\circ t_k^{i}, \end{aligned}
\end{equation}
respectively, and define the following maps $\B V \rightarrow \B V$:
\begin{equation*}
\Hd'\coloneqq \sum_{k=1}^{\infty} \Hd'_k, \quad R\coloneqq \sum_{k=2}^\infty R_k\quad\text{and}\quad \Hd\coloneqq \Hd' + R.
%\label{Eq:b}
\end{equation*}
We denote by $\Hd^*: \CDB V = (\B V)^{\GD} \rightarrow \CDB V$ the dual map to $\Hd: \B V \rightarrow \B V$.  The following holds:\footnote{The facts~\eqref{Eq:HH}, in some form, are generally known; see \cite{Mescher2016} or \cite{Lazarev2003}. We prove them in our setting in Appendix~\ref{App:AInfty}.}
\begin{equation} \label{Eq:HH}
\Abs{\Hd} = 1\ (\Abs{\Hd^*}=-1), \quad \Hd\circ \Hd = 0 \quad\text{and}\quad \Hd(1-t) = (1-t)\Hd'.
\end{equation}
From the last equation we see that $\Hd$ restricts to $\BCyc V = \B V / \Im(1-t)$.
%For all $q\in \Z$, we define the vector spaces
%$$ \begin{aligned}
%D_q(V) &\coloneqq (\B V)^{-q-1}, & D^q(V) &\coloneqq (\CDB V)^{-q-1}, \\
%D^\lambda_q(V) &\coloneqq (\BCyc V)^{-q-1}, & D_\lambda^q(V) &\coloneqq (\CDBCyc V)^{-q-1}
%\end{aligned} $$
%and the corresponding graded vector spaces
We define the following graded vector spaces:
\begin{align*}
D(V) &\coloneqq r(\B V)[1], & D^*(V) &\coloneqq r(\CDB V)[1], \\ D^\lambda(V) &\coloneqq r(\BCyc V)[1], & D_\lambda^*(V) &\coloneqq r(\CDBCyc V)[1], \end{align*}
where $r$ denotes the grading reversal.
For instance, we have
$$ D_\lambda^q(V) = r(\CDBCyc V)^{q+1} = (\CDBCyc V)^{-q-1}\quad \text{for all } q\in \Z.$$
Then $(D(V),\Hd)$ and $(D^\lambda(V),\Hd)$ are chain complexes and $(D^*(V),\Hd^*)$ and $(D_\lambda^*(V),\Hd^*)$ the dual cochain complexes, respectively.
We define the following (co)homologies:
\begin{align*}
\H\H(\mathcal{A};\R)& \coloneqq \H(D(V), \Hd), & \H\H^*(\mathcal{A};\R) &\coloneqq \H(D^*(V),\Hd^*),\\
\H^\lambda(\mathcal{A};\R)& \coloneqq \H(D^\lambda(V), \Hd), & \H^*_\lambda(\mathcal{A};\R), &\coloneqq \H(D^*_\lambda(V),\Hd^*).
\end{align*}
We call $\H\H$ the \emph{Hochschild homology} and $\H^\lambda$ the \emph{cyclic homology} of the $\AInfty$-algebra $\mathcal{A}$. We call $\H\H^*$ the \emph{Hochschild cohomology} and $\H_\lambda^*$ the \emph{cyclic cohomology} of~$\mathcal{A}$.
\end{Definition}

For a dga $\mathcal{A} = (V,\mu_1,\mu_2)$, we have for all $v_1$, $\dotsc$, $v_k\in V[1]$ the formula
\begin{align*}
 \Hd(v_1 \dots v_k) &= \sum_{i=1}^k (-1)^{\Abs{v_1} + \dotsb + \Abs{v_{i-1}}} v_1 \dots \mu_1(v_i) \dots v_k  \\
   &+ \sum_{i=1}^{k-1} (-1)^{\Abs{v_1} + \dotsb + \Abs{v_{i-1}}} v_1 \dots \mu_2(v_i,v_{i+1}) \dots v_k \\
   &+ (-1)^{\Abs{v_k}(\Abs{v_1} + \dotsb + \Abs{v_{k-1}})} \mu_2(v_k,v_1)v_2\dots v_{k-1}.
\end{align*}

\begin{Definition}[Strict units and strict augmentations]\label{Def:AugUnit}
Let $\mathcal{A}= (V, (\mu_k))$ be an $\AInfty$-algebra. A non-zero homogenous element $\NOne \in V[1]$ with $\Abs{\NOne} = -1$ is called a \emph{strict unit} for $\mathcal{A}$ if the following holds:
\begin{align*} \mu_2(\NOne, v) = (-1)^{\Abs{v} + 1}\mu_2(v,\NOne) &= v\qquad\forall v\in V[1], \\[\jot]
\mu_k(v_1, \dotsc, v_{i-1}, \NOne, v_{i+1}, \dotsc, v_k) &= 0\qquad\forall\ k\neq 2,\ 1\le i \le k,\ v_j \in V[1]. \end{align*}
The pair $(\mathcal{A},\NOne)$ is called a \emph{strictly unital  $\AInfty$-algebra.}

A strictly unital $\AInfty$-algebra $(\mathcal{A},\NOne)$ is called \emph{strictly augmented} if it is equipped with a linear map $\varepsilon: V[1] \rightarrow \R[1]$ which satisfies
$$ \varepsilon(\NOne_V) = \NOne_\R, \quad \varepsilon \circ \mu_1 = 0\quad\text{and}\quad \varepsilon \circ \mu_2 = \mu_2\circ(\varepsilon \otimes \varepsilon), $$
where $\NOne_\R$ is the strict unit for~$\R$ endowed with the standard multiplication. The map $\varepsilon$ is called a \emph{strict augmentation.}.

If the \emph{homological dga} $\H(\mathcal{A})\coloneqq (\H(V,\tilde{\mu}_1), \mu_1 \equiv 0, \mu_2)$ of $\mathcal{A}$ is strictly unital and strictly augmented, then~$\mathcal{A}$ is called \emph{homologically unital} and \emph{homologically augmented}, respectively. A strictly unital and strictly augmented cochain complex $(V,\mu_1,\NOne,\varepsilon)$ is called just augmented.
\end{Definition}

We denote by $u: \R[1] \rightarrow V[1]$ the injective linear map defined by $u(\NOne_\R)\coloneqq \NOne_V$, and by $u^*: \DBCyc V \rightarrow \DBCyc \R$ and $\varepsilon^*: \DBCyc \R \rightarrow \DBCyc V$ the precompositions with $u^{\otimes k}$ and $\varepsilon^{\otimes k}$ in every weight-$k$ component, respectively.

\begin{Remark}[On units and augmentations]\phantomsection\label{Rem:AugUnit}
\begin{RemarkList}
\item A strict unit $\NOne_V$ for $\mathcal{A}$ induces an $\AInfty$-morphism $(u_k): \R \rightarrow V$ given by $u_1(\NOne_\R)\coloneqq \NOne_V$ and $u_k \equiv 0$ for all $k\ge 2$. A (general) augmentation of $(\mathcal{A},\NOne_V)$ is by definition any $\AInfty$-morphism $(\varepsilon_k): V \rightarrow \R$ such that $(\varepsilon_k) \circ (u_k) = \Id$ as $\AInfty$-morphisms (see~\cite{Keller1999}). Strict augmentations are precisely the maps $\varepsilon_1$ coming from augmentations $(\varepsilon_k)$ with $\varepsilon_k \equiv 0$ for all~$k\ge 2$.

\item As for $(V,\mu_1,\NOne,\varepsilon)$, we need the chain map $\varepsilon$ to provide the splitting of the short exact sequence of chain complexes
$$\begin{tikzcd}
0 \arrow{r} & \R[1] \arrow[hook]{r}{u} & \arrow[bend left=50]{l}{\varepsilon} V[1] \arrow[two heads]{r} & \coker(u) \arrow{r} & 0,
\end{tikzcd}$$
so that we get $\H(V) \simeq \H_{\RedMRM}(V)\oplus \R$, where $\H_{\RedMRM}(V)\coloneqq \H(\coker(u))$. If $(V,\mu_1)$ is non-negatively graded and we are given an injective chain map $u: \R[1] \rightarrow V[1]$ ($\eqqcolon$\,the classical augmentation), then one can show that such $\varepsilon$ always exists. \qedhere
\end{RemarkList}
\end{Remark}

\begin{Definition}[Reduced dual cyclic bar complex]\label{Def:ReducedDual}
Let $(\mathcal{A}, \NOne)$ be a strictly unital $\AInfty$-algebra. Consider the injection $\iota_{\NOne}: \B V \rightarrow \B V$, $v_1 \otimes \dotsb \otimes v_k \mapsto \NOne \otimes v_1 \otimes \dotsb \otimes v_k$. We define the \emph{reduced dual cyclic bar-complex} by
$$ \RedDBCyc V \coloneqq \{\psi \in \DBCyc V \mid \psi\circ \iota_{\NOne} = 0\}. $$
Under the assumption of strict unitality, $\Hd^*$ preserves $\RedDBCyc V$, and hence we can consider the reduced cyclic cochain complex\Correct[caption={DONE Missing red},noline]{Correct missing red in the definition of $D_r$}
$$ D_{\lambda,\RedMRM}^*(V) \coloneqq r(\CRedDBCyc V)[1]$$
and define the \emph{reduced cyclic cohomology of $\mathcal{A}$} by
$$ \H_{\lambda, \RedMRM}^*(\mathcal{A};\R)\coloneqq \H(D_{\lambda, \RedMRM}^*(V), \Hd^*). $$
\end{Definition}

\begin{Proposition}[Reduction to the reduced cyclic cohomology]\label{Prop:Reduced}
Let $\mathcal{A}= (V,(\mu_k))$ be an $\AInfty$-algebra with a strict unit $\NOne$ and a strict augmentation $\varepsilon$. Then the inclusions $\RedDBCyc V$, $\varepsilon^*(\DBCyc \R) \subset \DBCyc V$ induce the decomposition
\begin{align*}
\H_\lambda^*(\mathcal{A};\R) &\simeq \H_{\lambda, \RedMRM}^*(\mathcal{A};\R) \oplus \H_\lambda^*(\R;\R).
\end{align*}
Here we have
\begin{equation*}
%\label{Eq:Field}
 \H_\lambda^{q}(\R; \R) = \begin{cases} \langle \NOne^{q+1*} \rangle & \text{for }q\ge 0 \text{ even}, \\
0 & \text{for }q> 0 \text{ odd and }q<0, \\
\end{cases}
\end{equation*}
where $\NOne^{i*}: \R[1]^{\otimes i} \rightarrow \R$ is defined by $\NOne^{i*}(\NOne^{i}) \coloneqq 1$.
\end{Proposition}
\begin{proof}[Sketch of the proof]
The maps $\varepsilon^*: D_\lambda(\R) \rightarrow D_\lambda(V)$ and $u^*: D_\lambda(V) \rightarrow D_\lambda(\R)$ are chain maps with $u^*\circ \varepsilon^* = \Id$. Therefore, we have the sequence of cochain complexes
\begin{equation}\label{Eq:UnitAugSS}
\begin{tikzcd}
 0 \arrow{r} &D_{\lambda,\RedMRM}(V) \arrow[hook]{r} & D_\lambda(V) \arrow[two heads]{r}{u^*} & \arrow[bend left=50]{l}{\varepsilon^*} D_\lambda(\R) \arrow{r} & 0,
\end{tikzcd}
\end{equation}
which is exact everywhere except for the middle, and where $\varepsilon^*$ is a splitting map. The idea of \cite{LodayCyclic} is to replace these cochain complexes with quasi-isomorphic bicomplexes consisting of normalized Hochschild cochains $\bar{D}(V)$ such that the sequence becomes exact. The work then reduces to proving that $\bar{D}(V)$ computes $\H\H(\mathcal{A};\R)$; a variant of this result for $\AInfty$-algebras was proven in~\cite{Lazarev2003}.
See Appendix~\ref{App:AInfty} for the full proof.
%The version for a dga, which is in fact enough for the examples in this article, also follows directly from \cite{LodayCyclic} using Lemma \ref{Lem:DGA} below.
\end{proof}

We will now compare our version of the cyclic cohomology of a dga $(V,\mu_1, \mu_2)$ to the version from~\cite[Section 5]{LodayCyclic}.
In order to do this, we have to undo the degree shift~$V[1]$ first since it is not considered in \cite{LodayCyclic}.

Let $\tilde{\Hd}$, $\tilde{\delta}: \bar{T}V \rightarrow \bar{T}V$ be the linear maps defined for all $\tilde{v}_1$, $\dotsc$, $\tilde{v}_k \in V$ by
\allowdisplaybreaks
\begin{align*}
   \tilde{\Hd}(\tilde{v}_1\otimes \dotsb \otimes \tilde{v}_k) & \coloneqq \begin{multlined}[t] \sum_{i=1}^{k-1} (-1)^{i-1} \tilde{v}_1 \otimes \dotsb \otimes \tilde{\mu}_2(\tilde{v}_i, \tilde{v}_{i+1}) \otimes \dotsb \otimes \tilde{v}_k  \\ {}+ (-1)^{k-1+ \tilde{v}_k(\tilde{v}_1 + \dotsb + \tilde{v}_{k-1})}\tilde{\mu}_2(\tilde{v}_k, \tilde{v}_1)\otimes\tilde{v}_2\otimes\dotsb\otimes\tilde{v}_{k-1},
\end{multlined} \\
\tilde{\delta}(\tilde{v}_1\otimes \dotsb \otimes \tilde{v}_k) & \coloneqq  \sum_{i=1}^k (-1)^{\tilde{v}_1 + \dotsb + \tilde{v}_{i-1}} \tilde{v}_1\otimes\dotsb \otimes \tilde{\mu}_1(\tilde{v}_i)\otimes \dotsb \otimes \tilde{v}_k.
\end{align*}
For all $q\ge 0$, we define
\begin{equation}\label{Eq:NDSComplex}
\tilde{D}_q(V) \coloneqq \bigoplus_{\substack{k\ge 1 \\ d\in \Z \\k-d= q + 1}} (V^{\otimes k})^d
\end{equation}
and $\tilde{\Bdd}: \tilde{D}_{q+1}(V) \rightarrow \tilde{D}_{q}(V)$ by
$$ \tilde{\Bdd}(\tilde{v}_1\dotsb \tilde{v}_k) = \tilde{\Hd}(\tilde{v}_1\dotsb \tilde{v}_k) + (-1)^{k+1} \tilde{\delta}(\tilde{v}_1\dotsb \tilde{v}_k). $$
It can be checked that $\tilde{\Bdd}\circ\tilde{\Bdd}=0$ and $\tilde{\Bdd}(\Im(1-\tilde{t}))\subset \Im(1-\tilde{t})$, so that $\tilde{\Bdd}$ induces a boundary operator on
the chain complexes \Correct[caption={DONE Wrong cyclic permutation}]{Here the $t$ is modified i.e. $\tilde{t}(v_1\dotsc v_k) = (-1)^{k-1} t(v_1 \dotsc v_k)$}
$$ \tilde{D}(V)\coloneqq \bigoplus_{q\in \Z} \tilde{D}_q(V)\quad\text{and}\quad\tilde{D}^\lambda(V) \coloneqq \tilde{D}(V)/\Im(1-\tilde{t}). $$
Here, we have $\tilde{t}(\tilde{v}_1 \dotsb \tilde{v}_k) \coloneqq (-1)^{k + \Abs{\tilde{v}_k}(\Abs{\tilde{v}_1} + \dotsb + \Abs{\tilde{v}_{k-1}})} \tilde{v}_k \tilde{v}_1 \dotsb \tilde{v}_{k-1}$.

We call $(\tilde{D}(V),\tilde{\Bdd})$ the \emph{non-degree-shifted Hochschild complex} and $(\tilde{D}^\lambda(V), \tilde{\Bdd})$ the \emph{non-degree-shifted cyclic complex} of the dga $(V,\mu_1,\mu_2)$.
We denote their homologies by $\ClasHH(V)$ and $\ClasCycH(V)$, respectively.

Looking at \eqref{Eq:NDSComplex}, the chain complex $(\tilde{D}(V),\tilde{\Bdd})$ is the total complex of the bicomplex
\begin{equation}\label{Eq:TotComplNDS}
\begin{tikzcd}
{} & \arrow{d} &\arrow{d} & \arrow{d} \\
{} &\arrow{l} \arrow{d}{\tilde{\Hd}} (V^{\otimes 3})^2 & \arrow{l}{\tilde{\delta}} \arrow{d}{\tilde{\Hd}} (V^{\otimes 3})^1 & \arrow{l}{\tilde{\delta}} \arrow{d}{\tilde{\Hd}} (V^{\otimes 3})^{0}  \\
{} &\arrow{l} \arrow{d}{\tilde{\Hd}} (V^{\otimes 2})^2 & \arrow{l}{-\tilde{\delta}} \arrow{d}{\tilde{\Hd}} (V^{\otimes 2})^1 & \arrow{l}{-\tilde{\delta}} \arrow{d}{\tilde{\Hd}} (V^{\otimes 2})^{0} \\
{} &\arrow{l} V^2 & \arrow{l}{\tilde{\delta}} V^1 & \arrow{l}{\tilde{\delta}} V^{0}
\end{tikzcd}
\end{equation}
with chain groups being the direct sums of the top-left/right-bottom diagonals.
This differs from the bicomplex \cite[Equation (5.3.2.1)]{LodayCyclic}, whose total complex is used to define the Hochschild homology of $V$ in \cite{LodayCyclic}, by the reversed grading in degree.
The convention of \cite{LodayCyclic} is namely $\Abs{\tilde{\mu}_1} = -1$, whereas ours is $\Abs{\tilde{\mu}_1}=1$.
The total complex of \cite{LodayCyclic} corresponds to the bottom-left/right-top diagonal in \eqref{Eq:TotComplNDS}.
Therefore, the homologies might differ!

We also warn the careful reader that the degree is called ``weight'' in \cite{LodayCyclic}.

The next proposition shows that our $\CycH(V)$ indeed computes $\ClasCycH(V)$.

\begin{Proposition}[Non-degree-shifted case] \label{Prop:DGA}
Let $\mathcal{A} = (V,\mu_1,\mu_2)$ be a dga. Then the degree shift map
\begin{align*}
 U: \tilde{D}_q (V) & \longrightarrow D_q(V), \\
        \tilde{v}_1 \otimes \dotsb \otimes \tilde{v}_k & \longmapsto \varepsilon(\SuspU, \tilde{v}) v_1 \otimes \dotsb \otimes v_k,  \end{align*}
where we denote $v_i = \SuspU \tilde{v}_i$ for a formal symbol $\theta$ with $\Abs{\theta}=-1$, is an isomorphism of the chain complexes $(\tilde{D}(V),\tilde{\Bdd})$ and $(D(V), \Hd)$, resp.~$(\tilde{D}^\lambda(V),\tilde{\Bdd})$ and $(D^\lambda(V),\Hd)$.
\end{Proposition}

\begin{proof}
First of all, it holds $\Abs{\tilde{\mu}_j} = 2 - j$ for every $j\ge 1$. For every $j$, $k$, $l\ge 1$ such that $j+l \le k+1$ and for every $\tilde{v}_1$, $\dotsc$, $\tilde{v}_k \in V$, we compute
\begin{align*}
&\bigl[U^{-1}(\Id^{l-1}\otimes \mu_j \otimes \Id^{k-j-l+1})U\bigr](\tilde{v}_1\dotsb \tilde{v}_k) \\[\jot] &\quad = (-1)^{l-1 + (j-2)(\tilde{v}_1 + \dotsb + \tilde{v}_{l-1} + k - l - j +1)} \tilde{v}_1\dotsb\tilde{v}_{l-1}\tilde{\mu}_j(\tilde{v}_l\dotsb \tilde{v}_{l+j-1})\tilde{v}_{l+j}\dotsb \tilde{v}_k, \\[\jot]
& [U^{-1} t_k U](\tilde{v}_1\dotsb \tilde{v}_k) = (-1)^{k-1} \tilde{v}_1 \dotsb \tilde{v}_k,
\end{align*}
where we use the Koszul convention $(f_1\otimes f_2)(v_1\otimes v_2) = (-1)^{\Abs{f_2}\Abs{v_1}} f_1(v_1)\otimes f_2(v_2)$. Using this, we obtain
\begin{align*}
U^{-1} \Hd'_k U &= \sum_{j=1}^k \sum_{i=0}^{k-1} (-1)^{i+j(i+k+1)} t^i_{k-j+1}(\tilde{\mu}_j \otimes \Id^{k-j})t_k^{-i}\quad\text{and} \\
U^{-1} R_k U &= \sum_{j=1}^k \sum_{i=1}^{j-1} (-1)^{(i+j)(k+1)} (\tilde{\mu}_j\otimes \Id^{k-j})t_k^i.
\end{align*}
It is now easy to check that $U^{-1}\circ \Hd\circ U = \tilde{\Bdd}$.

If $k\in \N$ is a weight and $d\in\Z$ a degree such that $k-d-1 = q$ for some $q\in \Z$, we have schematically $U: (k,d)\mapsto (k, d - k) = (k,-q-1)$. Therefore, $U$ preserves the grading of chain complexes. This finishes the proof.
\end{proof}

\begin{Proposition}[Reduced cochains are complete in $0$,\,$1$-connected case]\label{Prop:SimplCon}
Suppose that $V = \bigoplus_{d\ge 0} V^d$ is a non-negatively graded vector space with $V^0=\langle 1 \rangle$ for some $1\in V$ ($\eqqcolon$\,$V$ is \emph{connected}) and $V^1 = 0$ ($\eqqcolon$\,$V$ is \emph{simply-connected}). Then for all $m\ge 1$, we have
$$ \hat{\Ext}_m \RedDBCyc V = \Ext_m \RedDBCyc V. $$
\end{Proposition}
\begin{proof}
Let $\bar{V}\coloneqq \bigoplus_{d\ge 2} V^d$. We clearly have $\RedDBCyc V \simeq \DBCyc \bar{V}$. Since $\bar{V}[1]$ is positively graded, we have $(\B \bar{V})_{k}^d = 0$ whenever $k>d$. Therefore, a map $\Psi\in \hat{\Ext}_m \bar{V}$, which is non-zero only on finitely many homogenous components of $\BCyc V[1]^{\otimes m}$, will be non-zero only on finitely many weights. This implies that $\Psi\in \Ext_m \bar{V}$.
\end{proof}

\begin{Remark}[Universal coefficient theorem]\label{Rem:UCT}
We have
$$ \B V = \bigoplus_{d\in\Z} \bigoplus_{k=1}^\infty (V[1]^{\otimes k})^d\quad\text{and}\quad \DB V = \bigoplus_{d\in \Z} \bigoplus_{k=1}^\infty (V[1]^{\otimes k})^{d*}, $$
and hence
$$ (\B V)^{\GD} = \bigoplus_{d\in\Z} \prod_{k=1}^\infty (V[1]^{\otimes k})^{d*} = \bigoplus_{d\in \Z} \reallywidehat{(\DB V)^d} = \CDB V. $$
Therefore, $(D^*_\lambda(V), \Hd^*)$ is dual to $(D^\lambda(V), \Hd)$ as a chain complex. Now, because we work over $\R$, the universal coefficient theorem gives
\begin{equation*}
%\label{Eq:UCT}
 \H^q_\lambda(\mathcal{A},\Hd^*) \simeq [\H_q^\lambda(\mathcal{A},\Hd)]^*\quad\text{for all } q\in \Z.
\end{equation*}
Suppose that we have found closed homogenous elements $(w_i)_{i\in I}\subset D^\lambda(V)$ for some index set~$I$ which induce a basis of $\H^\lambda(\mathcal{A}; \R)$. For every $i\in I$, we define the linear map $w_i^*: D^\lambda(V) \rightarrow \R$ by prescribing
$$ w_i^*(w_j) = \delta_{ij}\qquad\text{for all }j\in I $$
and $w_i^* \equiv 0$ on $\Im \Hd$ and on a complement \Correct[caption={DONE Universal coefficient theorem}]{Here is enough an arbitrary complement of $\Ker)(b)$. That means that for every $i$, we can have a different complement $Z_i$} of $\Ker(\Hd)$ in $D^\lambda(V)$. Then $(w_i^*)_{i\in I} \subset D_\lambda^*(V)$ are closed homogenous elements which generate linearly independent cohomology classes in $\H_\lambda^*(\mathcal{A}; \R)$; if we denote $I_q \coloneqq \{i\in I \mid w_i \in C^\lambda_q(V)\}$, then we can write
\begin{equation*}
\H_\lambda^q(\mathcal{A}; \R) = \Bigl\{ \sum_{i\in I_q} \alpha_i w_i^* \bigMid \alpha_i\in \R \Bigr\}\quad\text{for all }q\in\Z.\qedhere
\end{equation*}
\end{Remark}

\end{document}


\chapter{Linear algebra\\(intuitive approach)}\label{chapter:linear algebra intuitive}
Linear algebra is one of the most important and often used fields, both in theoretical and applied mathematics. It brings together the analysis of systems of linear equations and the analysis of linear functions (in this context usually called linear transformations), and is employed extensively in almost any modern mathematical field, e.g. approximation theory, vector analysis, signal analysis, error correction, 3-dimensional computer graphics and many, many more.

In this book, we divide our discussion of linear algebra into to chapters: the first (this chapter) deals with a wider, birds-eye view of the topic: it aims to give an intuitive understanding of the major ideas of the topic. For this reason, in this chapter we limit ourselves almost exclusively to discussing linear algebra using 2- and 3-dimensional analysis (and higher dimensions when relevant) using real numbers only. This allows us to first create an intuitive picture of what is linear algebra all about, and how to use correctly the tools it provides us with.

The next chapter takes the opposite approach: it builds all concepts from the ground-up, defining precisely (almost) all basic concepts and proving them rigorously, and only then using them to build the next steps. This approach has two major advantages: it guarantees that what we build has firm foundations and does not fall apart at any future point, and it also allows us to generalize the ideas constructed during the process to such extent that they can be used as foundation to build ever newer tools we can apply in a wide range of cases.