\chapter{Localization at a prime}\label{chap:prime}

This chapter contains results by my MRC group, consisting of Dan Christensen, Morgan Opie, Luis Scoccola, and me.

In this chapter we focus on localization with respect to the \define{degree $k$
map} $\degg(k) : \sphere{1} \to \sphere{1}$, for $k : \N$, and with respect to
families of such maps.
The degree $k$ map is defined by circle induction by mapping $\base$ to $\base$
and $\lloop$ to $\lloop^k$.
Using suggestive language that mirrors the algebraic case, we call $L_{\degg(k)}$
``localization away from $k$'' and say that we are ``inverting $k$.''
We note that, for many applications, one considers localization away from $k$ for $k$ prime.
However, for the results of this chapter, $k$ can be any natural number.

As might be expected, $\degg(k)$-localizations can be combined to localize a type \emph{at}
a prime $p$, by localizing with respect to the family of maps $\degg(q)$ indexed by all
primes $q$ different from $p$.
With this case in mind, we study localization with respect to any family of degree $k$ maps
indexed by a map $S : A \to \N$ for some type $A$.
In other words, we localize with respect to the family $\degg\circ S : A \to \sphere{1} \to \sphere{1}$.
We denote the family $\degg\circ S$ by $\degg(S)$.

The main goal of this chapter is to show that, for simply connected types,
$\degg(S)$-localization localizes the homotopy groups away from $S$ (as long as $S$ indexed by $\N$),
as is true in the classical setting.

We begin in \cref{ss:localizationofgroups} by introducin uniquely $k$-divisible groups, and their localizations in the category of groups/abelian groups. \marginnote{edit}
It will follow from \cref{lemma:localizationlocalizesfirst} that every group $G$ has a localization $G \to G'$
away from $S$, obtained by applying $\pi_1$ to the $\deg(S)$-localization of $K(G, 1)$.
Similarly, if $G$ is abelian, its localization in the category of abelian groups is obtained
by applying $\pi_2$ to the $\deg(S)$-localization of $K(G,2)$.
Moreover, by \cref{theorem:localizationKgn}, these algebraic localizations agree
when restricted to abelian groups.
In \cref{ss:abelian}, we give an independent, purely algebraic construction of
the localization of an abelian group away from $S$ which also shows that the
two localizations agree.

In \cref{ss:n-conn}, we give characterizations of $\degg(S)$-localization for highly connected types. In particular, we show that the localization of a simply connected type can be computed as the nullification with respect to $M_S$, the family of cofibers of the maps $\degg(S(a))$, or as the localization with respect to $\susp \degg(S)$, the family of suspensions of these maps.
We prove that the $\degg(S)$-localization of a pointed, $(n-1)$-connected type inverts $S$ in $\pi_n$,
and deduce from this that every group has a localization away from $S$.

These characterizations of $\degg(S)$-localization are of interest to us for two reasons. First, the observation that $\degg(S)$-localization can be computed via a nullification implies that, restricted to simply connected types, $\degg(S)$-localization is a modality and therefore is better behaved than an arbitrary localization. Second, the fact that $\degg(S)$-localization can be computed as $\susp \degg(S)$-localization allows us to deduce that, for simply connected types, $\degg(S)$-localization commutes with taking loop spaces, a fact we use in the next section.

In \cref{ss:localizingKgn}, we give a method for computing the $\degg(S)$-localization of a loop space via a mapping telescope construction. This allows us to show that the localization of an Eilenberg-Mac Lane space $K(G,n)$, for $n \geq 1$ and $G$ abelian, is $K(G',n)$, where $G'$ is the algebraic localization of $G$ away from $S$.

In \cref{ss:localization-of-homotopy-groups}, we combine the results of \cref{ss:localizingKgn} and observations about the interaction between $\degg(S)$-localization and truncation to show that localizing a simply connected type at $\degg(S)$ localizes all of the homotopy groups away from $S$.
The results of the last two sections assume that the family $S$ is indexed by the natural numbers.

Finally, in \cref{ss:abelian} we give a direct proof of the fact that
the localization of an abelian group in the category of groups coincides with
its localization in the category of abelian groups, which also follows from
\cref{theorem:localizationKgn}.

\section{Localizing highly connected types}\label{ss:n-conn}

We continue to fix a family $S : A \to \N$ of natural numbers and the associated family
of maps $\degg(S) : A \to \sphere{1} \to \sphere{1}$ sending $a$ to $\degg(S(a))$.
We write $M_S$ for the family of cofibers, which sends $a$ to the cofiber
of $\degg(S(a))$, a ``Moore space.''
We write $\susp{\degg(S)}$ for the family of suspensions of the maps $\degg(S(a))$,
and similarly consider $\suspsym^n M_S$ and $\suspsym^n \degg(S)$.

The main result of this section is:

\begin{thm}\label{theorem:localizationisnullification}
    Let $n\geq 1$.
    If $X$ is $n$-connected, then its
    $\degg(S)$-localization, its $\suspsym^{n-1} M_S$-nullification and
    its $\suspsym^n \degg(S)$-localization coincide.
\end{thm}

Note that this implies that the same is true for the other localizations ``between''
$\degg(S)$ and $\suspsym^n \degg(S)$.
% E.g. N_{\suspsym^i M_S} for various i.

\begin{proof}
By \cref{cor:preserve-n-connected},
$L_{\susp[n] \degg(S)} X$ is $n$-connected,
since $\trunc{n}{\suspsym^n \, \sphere{1}} \eqvsym 1$.
Thus, by \cref{theorem:characterizinglocalness}, $L_{\susp[n] \degg(S)} X$
is $\degg(S)$-local and $\suspsym^{n-1} M_S$-local.
So the natural maps
\[
  L_{\susp[n] \degg(S)} X \lra L_{\suspsym^{n-1} M_S} X \lra L_{\degg(S)} X
\]
are equivalences, by \cref{lemma:comparelocalization}(3).
\end{proof}

This theorem fails without the connectedness hypothesis, as the next example shows.

\begin{eg}
    The type $\sphere{1}$ is not $\degg(k)$-local for $k > 1$ but it is $M_k$-null.
    On the one hand, $\loopspacesym \sphere{1}$ is equivalent to the integers, and the $k$-fold map
    is multiplication by $k$, which is not an equivalence.
    On the other, mapping from the cofiber sequence $\sphere{1}\to \sphere{1} \to M_k$ into $\sphere{1}$ we
    obtain the fiber sequence:
    \[
        (M_k \to_\ast \sphere{1}) \longhookrightarrow (\sphere{1} \to_\ast \sphere{1}) \xrightarrow{k} (\sphere{1}\to_\ast \sphere{1}),
    \]
    and the multiplication by $k$ map on the integers is injective, so the pointed mapping space $M_k \to_\ast \sphere{1}$ is contractible. Therefore $\sphere{1}$ is $M_k$-null by \cref{cor:pointed_null}.
\end{eg}

As an application of \cref{theorem:localizationisnullification}, we have:

\begin{cor}\label{corollary:commutativitylooplocalizationsimpconn}
    For a pointed, simply connected type $X$, we have
    \[
        \loopspacesym L_{\degg(S)} X \simeq L_{\degg(S)} \loopspacesym X.
    \]
\end{cor}

\begin{proof}
This follows from \cref{remark:commutativitylooplocalization} and \cref{theorem:localizationisnullification}.
\end{proof}

\cref{example:notlex} shows that the assumption that $X$ is simply connected cannot be removed.
Note that we cannot necessarily iterate the interchange of $\loopspacesym$ and $\degg(S)$-localization,
since $\loopspacesym X$ might fail to be simply connected.

\medskip

It also follows that these localizations preserve $l$-connected types.

\begin{cor}\label{corollary:plocalizationpreservesconnectedness}
    For $l \geq -2$ and $n \geq 0$, if $X$ is $l$-connected, then $L_{\susp[n] \degg(S)} X$ is $l$-connected.
\end{cor}
% We really only need the case n = 0 of this result.
% This lemma can also be proved using lemma:truncationpreserveslocal,
% and can then be used to prove theorem:localizationisnullification.

\begin{proof}
    If $n \geq l$, this follows from \cref{cor:preserve-n-connected}.
    If $n < l$, then \cref{theorem:localizationisnullification} implies
    that $L_{\susp[n] \degg(S)} X \eqvsym L_{\susp[l] \degg(S)} X$, putting us
    in the situation where $n = l$.
%\note{Having to break into cases makes me think we still haven't
%captured the cleanest way of organizing this.}
\end{proof}

The following proposition implies that localizations of groups always exist
(see \cref{rmk:localizationofgroups})
and is also used to prove \cref{theorem:localizationKgn}.

\begin{prp}\label{lemma:localizationlocalizesfirst}
    For $n \geq 1$,
    the $\degg(S)$-localization of a pointed, $(n-1)$-connected type $X$ localizes $\pi_n(X)$ away from $S$.
    The algebraic localization takes place in the category of groups if $n = 1$ and
    abelian groups otherwise.
\end{prp}

\begin{proof}
    By \cref{prop:homotopygroupsoflocalarelocal},
    we know that $\pi_n(L_{\degg(S)} X)$ is uniquely $S$-divisible.
    So it remains to show that precomposition with $\pi_n(\eta) : \pi_n(X) \to \pi_n(L_{\degg(S)} X)$
    induces an equivalence
    \[
        \precomp{\pi_n(\eta)} : \Hom(\pi_n(L_{\degg(S)} X),  H) \lra \Hom(\pi_n(X), H)
    \]
    for every uniquely $S$-divisible group $H$ (where $H$ is assumed to be abelian if $n>1$).
    Notice that this map is equivalent to
    \[
        \precomp{\pi_n(\ttrunc{n}{\eta})} : \Hom(\pi_n(\ttrunc{n}{L_{\degg(S)} X}),  H) \lra \Hom(\pi_n(\ttrunc{n}{X}), H)
    \]
    which in turn is equivalent to
    \[
        \precomp{\ttrunc{n}{\eta}} : \left( \ttrunc{n}{L_{\degg(S)}X} \pto K(H, n) \right) \lra \left( \ttrunc{n}{X} \pto K(H, n) \right)
    \]
    by \cref{theorem:catofgroups}, using the fact that $\ttrunc{n}{L_{\degg(S)}X}$ is still $(n-1)$-connected (\cref{corollary:plocalizationpreservesconnectedness}).
    Finally, this last map is equivalent to
    \[
        \precomp{\eta} : \left( L_{\degg(S)}X \pto K(H, n) \right) \lra \left( X \pto K(H, n) \right),
    \]
    since $K(H,n)$ is $n$-truncated.
    And this map is an equivalence, since $K(H,n)$ is $\degg(S)$-local by \cref{corollary:characterizationpdivisible}.
\end{proof}

The results of this section also let us deduce the following lemma,
which will be used in \cref{ss:localization-of-homotopy-groups}.

\begin{lem}\label{lemma:lex}
    $\degg(S)$-localization maps fiber sequences of simply connected types to fiber sequences.
\end{lem}

Note that this lemma cannot be used to prove \cref{corollary:commutativitylooplocalizationsimpconn},
since the fiber that arises in that case is $\loopspacesym X$, which is not assumed to be
simply connected.
%\note{But maybe it's enough to assume that $E$ and $X$ are simply connected?}

\begin{proof}
    Let $F \to E \to X$ be a fiber sequence of simply connected types, with $F$ the fiber over $x_0$.
    By \cref{theorem:localizationisnullification}, the $L$- and $L'$-localizations
    of these types agree, where $L \defeq L_{\degg(S)}$.
    Applying \cref{proposition:preservationfibersequences},\marginnote{I don't know where this proposition went. Need to fix} we get a diagram
\begin{equation*}
\begin{tikzcd}
F \arrow[d,swap,"\eta"] \arrow[r,hookrightarrow] & E \arrow[d,swap,"l"] \arrow[r] & X \arrow[d,"\eta=\eta'"] \\
LF \arrow[r,hookrightarrow] & E' \arrow[r] & L'X \mathrlap{\,\,=\, L X ,}
\end{tikzcd}
\end{equation*}
    in which the rows are fiber sequences, with $L F$ the fiber over $\eta(x_0)$.
    To show that $l$ is an $L$-localization, it is enough to show that $E'$ is $L$-local.
    Since it is the total space of a fibration of simply connected spaces,
    it is simply connected. And since it is $L'$-local,
    by the same proposition, we deduce that it is $L$-local, as needed.
\end{proof}

\cref{example:nonlocalfib} shows that the $\degg(S)$-localization of a
fiber sequence is not a fiber sequence in general.

\medskip

We end this section with the following lemma, which is of a similar
flavor and which will be used in \cref{ss:localization-of-homotopy-groups}.

\begin{lem}\label{lemma:truncationpreserveslocal}
    For $l \geq -2$ and $n \geq 0$, the $l$-truncation of a $\suspsym^n \degg(S)$-local type is $\suspsym^n \degg(S)$-local.
\end{lem}
% I think we only need the n = 0 case of this later.

\begin{proof}
    Let $X$ be a $\suspsym^n \degg(S)$-local type.
    Fix $a : A$ and let $k = S(a)$.
    We must show that $k : \loopspacesym^{n+1} \ttrunc{l}{X} \to \loopspacesym^{n+1} \ttrunc{l}{X}$
    is an equivalence for each basepoint $x' : \ttrunc{l}{X}$.
    If $l - (n+1) \leq -2$, then $\loopspacesym^{n+1} \ttrunc{l}{X}$ is
    contractible, so this is clear.
    So assume that $l - (n+1) > -2$, and in particular that $l > -2$.
    Since being an equivalence is a mere proposition,
    we can assume that $x' = \tproj{l}{x}$ for some $x : X$.
    Recall that $l$-truncation
    is the subuniverse of separated types for $(l-1)$-truncation (\cref{example:truncationisseparated}).
    Applying \cref{thm:separation_characterization} $n+1$ times gives the equivalences
    in the square
\begin{equation*}
\begin{tikzcd}
\trunc{l-n-1}{\loopspacesym^{n+1} X} \arrow[d,swap,"\trunc{l-n-1}{k}"] \arrow[r,"\eqvsym"] & \loopspacesym^{n+1} \trunc{l}X \arrow[d,"k"] \\
\trunc{l-n-1}{\loopspacesym^{n+1} X}. \arrow[r,"\eqvsym"] & \loopspacesym^{n+1} \trunc{l} X
\end{tikzcd}
\end{equation*}
    To show that the square commutes, it suffices to check this after precomposing
    with the truncation map $\loopspacesym^{n+1} X \to \trunc{l-n-1}{\loopspacesym^{n+1} X}$.
    And this follows since the equivalences commute with the natural maps from
    $\loopspacesym^{n+1} X$ and
    both vertical maps commute with $k : \loopspacesym^{n+1} X \to \loopspacesym^{n+1} X$.
    Since $X$ is $\suspsym^n \degg(k)$-local, the map on the right hand side is an equivalence,
    so the result follows.
\end{proof}

\section{Localization of groups}\label{ss:localizationofgroups}

We fix a family $S : A \to \N$ of natural numbers and consider the family
of maps $\degg(S) : A \to \sphere{1} \to \sphere{1}$ sending $a$ to $\degg(S(a))$.

\begin{defn}
    For $k : \N$, a group $G$ is \define{uniquely $k$-divisible} if the $k$-th power map
    $g \mapsto g^k$ is a bijection.
    A group $G$ is \define{uniquely $S$-divisible} if it is uniquely $S(a)$-divisible for every $a : A$.

    Given a group $G$, a group homomorphism $\eta : G \to G'$ is said to be a \define{localization of $G$ away from $S$
    in the category of groups} if $G'$ is uniquely $S$-divisible, and for every group $H$
    which is uniquely $S$-divisible the precomposition map $\precomp{\eta} : \mathsf{Grp}(G', H) \to \mathsf{Grp}(G, H)$ is an equivalence.
    If $G$ is abelian and $\eta : G \to G'$ has the universal property only with respect to uniquely
    $S$-divisible abelian groups, we say $\eta$ is a \define{localization of $G$ away from $S$ in the category
    of abelian groups}.
\end{defn}

\begin{rmk}
When the group is additive, the $k$-th power map is usually called the \define{multiplication-by-$k$ map}.
Notice that for non-abelian groups the $k$-th power map is not in general a group homomorphism.
\end{rmk}

Our first goal is to show that the homotopy groups of a $\degg(S)$-local type
are uniquely $S$-divisible.
In order to do this, we begin by characterizing the $\degg(S)$-local types.

\begin{lem}\label{lem:deglocal_char}
A type $X$ is $\degg(S)$-local if and only if, for each $x:X$ and $a:A$, the map
$S(a) : \loopspace{X,x} \to \loopspace{X,x}$ sending
$\omega$ to $\omega^{S(a)}$ is an equivalence.
\end{lem}

\begin{proof}
We apply \cref{lemma:pointed}.
Let $x:X$ and $a:A$.
By the universal property of the circle, we have an equivalence
$(\sphere{1} \pto X) \eqvsym \loopspace{X,x}$.
Moreover, the square
\[
  \begin{tikzcd}
    (\sphere{1} \pto X) \arrow[r,"\simeq"] \arrow[d,swap,"\precomp{\degg(S(a))}"] & \loopspace{X,x} \arrow[d,"S(a)"] \\
    (\sphere{1} \pto X) \arrow[r,swap,"\simeq"] & \loopspace{X,x}
  \end{tikzcd}
\]
commutes, so we conclude that $\precomp{\degg(S(a))}$ is an equivalence if and only if $S(a)$ is an equivalence.
\end{proof}

\begin{prp}\label{prop:homotopygroupsoflocalarelocal}
    If $X$ is a pointed, $\degg(S)$-local type, then $\pi_{m+1}(X)$ is uniquely $S$-divisible
    for each $m : \N$.
    Conversely, if for some $n \geq 0$, $X$ is a pointed, simply connected $n$-type
    such that $\pi_{m+1}(X)$ is uniquely $S$-divisible for each $m : \N$,
    then $X$ is $\degg(S)$-local.
\end{prp}

For the converse, the requirement that $X$ be truncated is needed because
we need to use Whitehead's theorem.

\begin{proof}
If $X$ is a pointed, $\degg(S)$-local type, then it follows immediately from \cref{lem:deglocal_char} that $\pi_1(X)$ is uniquely $S$-divisible. Moreover, since the loop space of a pointed $\degg(S)$-local type is again $\degg(S)$-local, it follows that $\pi_m(X)$ is uniquely $S$-divisible for all $m\geq 1$.
\end{proof}

\begin{proof}
    Let $X$ be a pointed, $\degg(S)$-local type and let $a : A$.
    In this proof, we write $\degg(k, Y)$ for the degree $k$ map on $\loopspacesym Y$,
    where $k = S(a)$.
    For every $m : \N$,
    the map $\degg(k, X) : \loopspacesym X \to \loopspacesym X$ induces
    the map $\degg(k, \loopspacesym^m X) : \loopspacesym^m \loopspacesym X \to \loopspacesym^m \loopspacesym X$,
    by the Eckmann-Hilton argument~\cite[Theorem~2.1.6]{hottbook}.
    That is, $\loopspacesym^m \degg(k, X) = \degg(k, \loopspacesym^m X)$.
    It follows that $\loopspacesym^m \degg(k, X)$ induces the $k$-th power map on $\pi_{m+1}( X )$.
    Since $\degg(k, X)$ is an equivalence, the $k$-th power map on $\pi_{m+1}( X )$
    must be an equivalence for each $m$.
    In other words, $\pi_{m+1}( X )$ is uniquely $S$-divisible for each $m$.

    Conversely, suppose that, for some $n \geq 0$, $X$ is a pointed,
    simply connected $n$-type such that $\pi_{m+1}(X)$ is uniquely $S$-divisible
    for each $m : \N$.
    Let $a : A$ and let $k = S(a)$.
    Since $X$ is pointed and connected, it suffices to show that
    $\degg(k, X) : \loopspacesym X \to \loopspacesym X$ is an equivalence.
    By the above argument, $\degg(k, X)$ induces the $k$-th power map on each
    $\pi_{m+1}(X) = \pi_m(\loopspacesym X)$.
    By assumption, these $k$-th power maps are bijections.
    Since $\loopspacesym X$ is a pointed, connected $(n-1)$-type, it follows from the
    truncated Whitehead theorem~\cite[Theorem~8.8.3]{hottbook} that
    $\degg(k, X)$ is an equivalence.
    % This last step is where we use that X is simply connected.  Otherwise,
    % we'd need to study pi_m(\loopspacesym X) at other base points.
\end{proof}

\begin{cor}\label{corollary:characterizationpdivisible}
    For any $n > 1$, an abelian group $G$ is uniquely $S$-divisible if and only if its classifying space $K(G,n)$
    is $\degg(S)$-local. An arbitrary group $G$ is uniquely $S$-divisible if and only if $K(G,1)$ is $\degg(S)$-local.
\end{cor}

\begin{proof}
    As argued in the proof of \cref{prop:homotopygroupsoflocalarelocal}, $\degg(k)$ induces the $k$-th power map under the equivalence of categories, so one morphism is an equivalence if and only if the other is.
\end{proof}

We conclude this section with three examples.
The first one shows that $\degg(k)$-localization does not preserve fiber sequences in general.
The second one shows the stronger statement that $\degg(k)$-localization is not a modality,
by giving an example showing that uniquely $k$-divisible groups are not closed under extensions.
(It is an easy exercise that if a localization $L$ preserves fiber sequences,
then $L$ is a modality.)
The third one shows that the $\degg(k)$-local types are not the separated types
for any reflective subuniverse $L$.

\begin{eg}\label{example:notlex}
    We show that for $k > 1$, $\degg(k)$-localization
    does not preserve all fiber sequences.
    We first make some general observations.
    By \cref{lemma:setsarelocal}, we know that if $f$ is a map between pointed,
    connected types, then sets are $f$-local.
    It follows that if $L_f$ preserves the fiber sequence
    \[
        G \longhookrightarrow \unit \lra K(G,1),
    \]
    then $K(G,1)$ is $f$-local.
    Indeed, the $f$-localization map between the fiber sequences gives
\begin{equation*}
\begin{tikzcd}
G \arrow[d,swap,"\eqvsym"] \arrow[r,hookrightarrow] & \unit \arrow[d,swap,"\eqvsym"] \arrow[r] & K(G,1) \arrow[d] \\
L_f G \arrow[r,hookrightarrow] & L_f\unit \arrow[r] & L_f K(G,1).
\end{tikzcd}
\end{equation*}
    which implies that $K(G,1) \simeq L_f K(G,1)$, since $L_f K(G,1)$ is connected
    by \cref{cor:preserve-n-connected}.
    Now take $f$ to be the degree $k$ map.
    By \cref{corollary:characterizationpdivisible}, $K(G,1)$ is $\degg(k)$-local if and only if
    $G$ is uniquely $k$-divisible.
    In particular, if $G = \Z/k\Z$, then $K(G,1)$ is not $\degg(k)$-local.
    So $\degg(k)$-localization does not preserve all fiber sequences.
\end{eg}

\note{Added the following example. It is much simpler than the next one. Should we keep both?}
\note{Haven't modified the intro to these examples.}

\begin{eg}\label{example:nonlocalfib2}
    Consider the map $K(\Z,1) \to K(\Q,1)$, induced by the inclusion of groups $\Z \to \Q$.
    Using the long exact sequence of homotopy groups, one sees that the fiber over any point is
    (merely) equivalent to the set $\Q/\Z$. Recall that sets are $\degg(k)$-local for any $k : \N$,
    so as long as $k > 0$, the type $K(\Z,1)$ is the total space of a fibration with $\degg(k)$-local fibers and $\degg(k)$-local base.
    On the other hand, if $k > 1$, $K(\Z,1)$ is not $\degg(k)$-local, so we see that $\degg(k)$-localization
    is not a modality in general.
\end{eg}

\begin{eg}\label{example:nonlocalfib}
    Let $B$ be the subtype of $\Q \to \Q$ consisting of functions with bounded support.
    We can define this type constructively as the type of functions together with
    a mere bound for their support:
    \[
         B \defeq \sm{f : \Q \to \Q} \, \ttrunc{-1}{\sm{b : \Q} \prd{x : \Q} (x > b) \to (f(x) = 0) \times (f(-x) = 0)}.
    \]
    The group operation is given by $(f + g)(x) = f(x) + g(x)$.
    Notice that both $\Q$ and $B$ are uniquely $k$-divisible for any $k > 0$.

    Consider the semidirect product $P \defeq B \rtimes \Q$, where $\Q$ acts by translation:
    \[
        (r \cdot f)(x) = f(x+r).
    \]
    We claim that $(\delta_0, 2) : P$ does not have a square root. To see
    this, assume we have $(f,r)$ such that $(f,r)^2 = (f + r\cdot f,2r) = (\delta_0, 2)$.
    Then it must be the case that $r = 1$ and thus $f(x) + f(x+1) = \delta_0(x)$ for all $x : \Q$.
    But then $f(x) = - f(x+1)$ if $x \neq 0$.
    We can now contradict our assumption by proving that $f(x) = 0$ for all $x$.
    To do this, notice that this fact is a mere proposition, so we
    can use the mere bound for the support of $f$ to conclude that $f(x+1)$ is $0$ if $x>0$ is large enough,
    and then induct backwards using $f(x) = - f(x+1)$ if $x>0$. The case $x<0$ is analogous.
    Thus we have obtained a short exact sequence of groups
    \[
        1 \lra B \lra P \lra \Q \lra 1
    \]
    in which the kernel and cokernel are uniquely $2$-divisible, but the middle group is not.

    It follows that if we apply the functor $K(\blank, 1)$ to this short exact sequence of groups,
    we obtain a fiber sequence with connected, $\degg(2)$-local base and fiber,
    but for which the total space is not $\degg(2)$-local.
    Phrased differently, a dependent sum of $\degg(2)$-local types, indexed by
    a $\degg(2)$-local type, is not necessarily $\degg(2)$-local.
    So $\degg(2)$-localization is not a modality.

    A similar argument shows that for any $k > 1$, $P$ is not uniquely $k$-divisible
    and therefore that $\degg(k)$-localization is also not a modality.
\end{eg}

\begin{eg}
As a final example in a similar spirit, we show that for $k > 1$, $L_{\degg(k)}$ is not
of the form $L'$ for any reflective subuniverse $L$.
For any $L$, the $L$-separated types are determined by their identity types.
However, the identity types of $K(\Q,1)$ and $K(\Z,1)$ are equivalent,
and the former is $L_{\degg(k)}$-local while the latter is not.
\end{eg}

\section{Localization of Eilenberg--Mac Lane spaces}\label{ss:localizingKgn}

In this section, we compute the localization of a loop space as a mapping telescope,
in a way that is familiar from classical topology.
This specializes to give a concrete description of the
localization of an Eilenberg--Mac Lane space for an abelian group.
This is the key ingredient in the proofs of the results in the next section.

For the remainder of \cref{section:localizationaway}, we assume that our family
$S$ is indexed by the natural numbers, i.e., we have $S : \N \to \N$ and
$\degg(S)$ sends $i$ to $\degg(S(i))$.

For example, if we want to invert a decidable subset of the natural numbers
$T : \N \to \bool$, we can define a family $S : \N \to \N$ by
\[
    S(k) \defeq \begin{cases} k, & \text{if $T(k)$} \\
                              1, & \text{otherwise.}
                \end{cases}
\]
It is easy to see that a type is $\degg(S)$-local if and only if it is $\degg(k)$-local for every $k$ such that $T(k)$ is true.
The most important example of this form is the case of localizing \emph{at} a prime $p$,
in which we take $T$ to be the subset of primes different from $p$.

\begin{lem}\label{lemma:pmapisorthogonal}
    Given a pointed, simply connected type $X$, the $k$-fold map $k : \loopspacesym X \to \loopspacesym X$
    is an $L_{\degg(k)}$-equivalence.
\end{lem}

\begin{proof}
    We have the usual square
\begin{equation*}
\begin{tikzcd}
\loopspacesym X \arrow[d,swap,"k"] \arrow[r,"\eta"] & L_{\degg(k)} \loopspacesym X \arrow[d,"L_{\degg(k)} k"] \\
\loopspacesym X \arrow[r,swap,"\eta"] & L_{\degg(k)} \loopspacesym X
\end{tikzcd}
\end{equation*}
    Recall that the right vertical map is the unique map equipped with a homotopy witnessing that the square commutes.
    Now, by \cref{corollary:commutativitylooplocalizationsimpconn}, we know that for pointed, simply connected types we have
    $L_{\degg(k)} \loopspacesym X \simeq \loopspacesym L_{\degg(k)} X$ so that,
    by the uniqueness of the right vertical map, the above square is equivalent to the square
\begin{equation*}
\begin{tikzcd}
\loopspacesym X \arrow[d,swap,"k"] \arrow[r,"\loopspacesym \eta"] & \loopspacesym L_{\degg(k)} X \arrow[d,"k"] \\
\loopspacesym X \arrow[r,swap,"\loopspacesym \eta"] & \loopspacesym L_{\degg(k)} X
\end{tikzcd}
\end{equation*}
    where the map on the right is the usual $k$-fold map.
    But in this square the right vertical map is an equivalence, since $L_{\degg(k)} X$
    is $\degg(k)$-local.
\end{proof}

We are almost ready to localize the loop space of a simply connected type away from $S : \N \to \N$.
Before doing this we need a general fact about sequential colimits.

\begin{rmk}\label{remark:equivalenceofseqcolim}
Given a sequential diagram $X$:
\begin{equation*}
\begin{tikzcd}
X_0 \arrow[r,"h_0"] & X_1 \arrow[r,"h_1"] & X_2 \arrow[r,"h_2"] & \cdots
\end{tikzcd}
\end{equation*}
we can consider the shifted sequential diagram $\mathsf{shift}(X)$ given by $X_1 \to X_2 \to \cdots$.
Analogously, we can shift a natural transformation $f : X \to Y$ between sequential
diagrams to obtain a natural transformation $\mathsf{shift}(f):\mathsf{shift}(X)\to\mathsf{shift}(Y)$.
Notice that the transition maps $h_n$ induce a natural transformation $h : X \to \mathsf{shift}(X)$, and that moreover, the
induced map $\colim(h) : \colim(X) \to \colim(\mathsf{shift}(X))$ is an equivalence.
It then follows that if $f : X \to X$ is a natural transformation such that there exist $g, g' : X \to \mathsf{shift}(X)$
with $g \circ f = h$ and $\mathsf{shift}(f) \circ g' = h$, then $f$ induces an self-equivalence $\colim(f) : \colim(X) \eqvsym \colim(X)$.
\end{rmk}

\begin{prp}\label{theorem:localizationastelescope}
    Let $X$ be pointed and simply connected, and
    define $s : \N \to \N$ by $s(n) = \prod_{i=0}^n S(i)$.
    Then the $\degg(S)$-localization of $\loopspacesym X$ is equivalent to the colimit of the sequence
\begin{equation*}
\begin{tikzcd}
\loopspacesym X \arrow[r,"s(0)"] & \loopspacesym X \arrow[r,"s(1)"] & \loopspacesym X \arrow[r,"s(2)"] & \cdots,
\end{tikzcd}
\end{equation*}
    where as usual a natural number $k$ is used to denote the $k$-fold map.
\end{prp}

\begin{proof}
    We will show that the colimit is $\degg(S)$-local and that
    the map $\loopspacesym X \to \colim\, \loopspacesym X$ is an $L_{\degg(S)}$-equivalence.
    % Being a deg(S)-equivalence is not the same as being a deg(S(k))-equivalence
    % for every k.

    To prove that $\loopspacesym X \to \colim\, \loopspacesym X$ is an $L_{\degg(S)}$-equivalence
    we use \cref{lemma:orthogonalcomposition}, so it is enough to show that all the maps in the
    diagram are $L_{\degg(S)}$-equivalences. To prove this last fact notice that \cref{lemma:pmapisorthogonal}
    implies that the $s(k)$-fold map is an $L_{\degg(s(k))}$-equivalence. But in particular this implies that it is also an
    $L_{\degg(S)}$-equivalence, since every $\degg(S)$-local type is $\degg(s(k))$-local for every $k$.
    % The map s(0) is not a deg(S(1))-equivalence in general, so we can't work
    % one k at a time above.  But it works to handle all k at once.

    Now we must show that the colimit is $\degg(S(k))$-local for each $k$.
    So fix $k$ and recall that
    the colimit is equivalent to the colimit of the sequence starting at $k$.
    That is, we consider the colimit of the sequential diagram with objects
    $C_n = \loopspacesym X$ and transition maps $h_n : C_n \to C_{n+1}$ given by $s(n+k)$.
    Then $\colim_n C_n$ is pointed and connected by \cite{DoornRijkeSojakova},
    so it is enough to check that the map $S(k) : \loopspacesym \colim_n C_n \to \loopspacesym \colim_n C_n$ is an equivalence.
    By the commutativity of loop spaces and sequential colimits \cite{DoornRijkeSojakova},
    it is then enough to show that the natural transformation $S(k) : \loopspacesym C_n \to \loopspacesym C_n$
    induces an equivalence in the colimit.

    By the Eckmann-Hilton argument~\cite[Theorem~2.1.6]{hottbook}, the transition map
    $\loopspacesym h_n : \loopspacesym C_n \to \loopspacesym C_{n+1}$ is homotopic to $s(n+k)$.
    We can then apply \cref{remark:equivalenceofseqcolim},
    taking $f$ to be the natural transformation given by
    $S(k)$ in every degree, and both $g$ and $g'$ to be the natural transformation given by
    $s(n + k)/S(k) : \loopspacesym C_n \to \loopspacesym C_{n+1}$ in degree $n$.
    We have that $g_n \circ f_n = f_{n+1} \circ g'_n = s(n + k)$, and moreover that
    $g \circ f = f[1] \circ g' = h$ as natural transformations.
    So $S(k) : \loopspacesym C_n \to \loopspacesym C_n$ induces an equivalence in the colimit,
    as needed.
\end{proof}

Using the fact that $K(G,n)$ is the loop space of a simply connected space
when $G$ is abelian we deduce:

\begin{cor}\label{corollary:localizationKgn}
    For $n \geq 1$ and $G$ abelian,
    the $\degg(S)$-localization of $K(G,n)$ is equivalent to the colimit of the sequence
    \[
      K(G,n) \xrightarrow{s(0)} K(G,n) \xrightarrow{s(1)} \cdots .  \tag*{\qed}
    \]
\end{cor}

In particular, it follows from \cite{DoornRijkeSojakova} that the
$\deg(S)$-localization of $K(G,n)$ is $n$-truncated and $(n-1)$-connected,
so it is again a $K(G',n)$ for some group $G'$.
By \cref{lemma:localizationlocalizesfirst}, $G'$ is the algebraic localization of $G$
away from $S$ (in the category of groups if $n = 1$ and abelian groups otherwise).
We deduce:

\begin{thm}\label{theorem:localizationKgn}
    Let $n\geq 1$ and let $G$ be any abelian group.
    Then the $\degg(S)$-localization map $K(G,n) \to L_{\degg(S)} K(G,n)$ is a map between Eilenberg--Mac Lane spaces and
    is induced by an algebraic localization of $G$ away from $S$.
    Moreover, the algebraic localization of $G$ is equivalent to the colimit
    \[
      G \xrightarrow{s(0)} G \xrightarrow{s(1)} \cdots
    \]
    and is therefore abelian, even when $n = 1$.  \qed
\end{thm}

It follows that the two types of algebraic localization agree for abelian groups,
so we do not need to distinguish between them in what follows.

\section{Localization of homotopy groups}\label{ss:localization-of-homotopy-groups}

In this section we prove the main theorem of the paper:
for simply connected types, $\degg(S)$-localization localizes all homotopy groups away from $S$.
We continue to assume that our family $S$ is indexed by the natural numbers,
as the essential ingredient is our result on the localization of Eilenberg--Mac Lane spaces from the previous section.
%We use this and \cref{lemma:lex} to induct over the Postnikov tower.
The other ingredient we need is that for simply connected types,
truncation commutes with $\degg(S)$-localization, which follows
from the next lemma.

\begin{lem}\label{lemma:locofscntrunc}
    The $\degg(S)$-localization of a simply connected, $n$-truncated type is $n$-truncated.
\end{lem}

\begin{proof}
    First, we show that it suffices to prove the statement for pointed types.
    Let us assume given a simply connected and $n$-truncated type $X$, and let us denote the statement
    of the theorem by $P(X)$. If we prove $X \to P(X)$ it follows that $\ttrunc{-1}{X} \to P(X)$,
    since being $n$-truncated is a mere proposition. But this is enough, for $X$ is
    simply connected, which implies that $\ttrunc{1}{X}$ is contractible, and hence that
    $\ttrunc{-1}{X}$ is inhabited.

    We now assume that $X$ is pointed and proceed by induction.
    If $X$ is $-2$, $-1$, $0$ or $1$-truncated, we are done, since $X$ is also simply connected, and thus contractible.
    If $X$ is $(n+1)$-truncated and $n > 0$, consider the fiber sequence
    \[ K(G,n+1) \longhookrightarrow X \lra \ttrunc{n}{X}. \]
    Since the types in the fiber sequence are simply connected, $\degg(S)$-localization
    preserves this fiber sequence, by \cref{lemma:lex}. So we obtain a fiber sequence
    \[L_{\degg(S)} K(G,n+1) \longhookrightarrow L_{\degg(S)}X \lra L_{\degg(S)} \ttrunc{n}{X}. \]
    The type $L_{\degg(S)} \ttrunc{n}{X}$ is $n$-truncated by the induction hypothesis
    and $L_{\degg(S)} K(G,n+1)$ is $(n+1)$-truncated by \cref{theorem:localizationKgn}.
    So $L_{\degg(S)} X$ must be $(n+1)$-truncated as well.
\end{proof}

The proof of \cref{lemma:locofscntrunc} shows that we can compute
the $\degg(S)$-localization of a simply connected $n$-type $X$ by
localizing the Postnikov tower of $X$.

From \cref{lemma:locofscntrunc}, \cref{lemma:truncationpreserveslocal} and
the argument used in \cref{lemma:commutelocalization}, but restricted to simply connected types,
we deduce:

\begin{cor}\label{corollary:localizationandtruncationcommute}
    For simply connected types, $\degg(S)$-localization and $n$-trunca\-tion commute.\qed
\end{cor}

We now give the main theorem of the paper.

\begin{thm}\label{theorem:localizationlocalizes}
    The $\degg(S)$-localization of a pointed, simply connected type $X$ localizes all of the
    homotopy groups away from $S$.
\end{thm}

\begin{proof}
    Since $\degg(S)$-localization preserves simply connectedness, it is immediate that $\pi_1(L_{\degg(S)} X)$ is trivial.
    Now fix $n \geq 1$ and consider the fiber sequence
    \[
        K(\pi_{n+1}(X),n+1) \longhookrightarrow \ttrunc{n+1}{X} \lra \ttrunc{n}{X}.
    \]
    Notice that all of the types in the fiber sequence are simply connected.
    Applying $\degg(S)$-localization we obtain a map of fiber sequences
\begin{equation*}
\begin{tikzcd}
K(\pi_{n+1}(X),n+1) \arrow[d] \arrow[r,hookrightarrow] & \ttrunc{n+1}{X} \arrow[d] \arrow[r] & \ttrunc{n}{X} \arrow[d] \\
L_{\degg(S)} K(\pi_{n+1}(X),n+1) \arrow[r,hookrightarrow] & \ttrunc{n+1}{L_{\degg(S)}X} \arrow[r] & \ttrunc{n}{L_{\degg(S)} X}
\end{tikzcd}
\end{equation*}
    by \cref{lemma:lex} combined with the commutativity of truncation and
    $\degg(S)$-localization (\cref{corollary:localizationandtruncationcommute}).
    The result now follows from \cref{theorem:localizationKgn}.
\end{proof}

We also have a partial converse to \cref{theorem:localizationlocalizes}.

\begin{thm}\label{theorem:characterize-localization}
  Let $X$ and $X'$ be pointed, simply connected $n$-types, for some $n \geq 0$.
  If $f : X \to X'$ is a pointed map such that $\pi_m(f) : \pi_m(X) \to \pi_m(X')$ is
  an algebraic localization away from $S$ for each $m > 1$,
  then $f$ is a $\degg(S)$-localization of $X$.
\end{thm}

\begin{proof}
  By \cref{prop:homotopygroupsoflocalarelocal}, $X'$ is $\degg(S)$-local.
  Therefore, we have a commuting triangle
  \[
    \begin{tikzcd}
      X \arrow[r,"f"] \arrow[d,swap,"\eta"] & X' \\
      L_{\degg(S)} X \arrow[ur,dashed,swap,"f'"]
    \end{tikzcd}
  \]
  and it suffices to show that $f'$ is an equivalence.
  Since $L_{\degg(S)} X$ is also a pointed, simply connected $n$-type,
  if we show that $\pi_m(f')$ is a bijection for each $m > 1$,
  the truncated Whitehead theorem~\cite[Theorem~8.8.3]{hottbook} implies
  that $f'$ is an equivalence.
  By assumption, $\pi_m(f)$ is an algebraic localization of $\pi_m(X)$.
  By \cref{theorem:localizationlocalizes}, the same is true of $\pi_m(\eta)$.
  Since $\pi_m(f') \circ \pi_m(\eta) = \pi_m(f)$, it follows that
  $\pi_m(f')$ is a bijection.
\end{proof}

\section{Algebraic localization of abelian groups}\label{ss:abelian}

As observed in \cref{rmk:localizationofgroups},
\cref{theorem:localizationKgn} implies that the localization of an abelian group
away from a set $S$, in the category of groups, coincides with its localization in
the category of abelian groups. It moreover provides a construction of the localization.
Since we could not find these results in the literature, and since \cref{theorem:localizationKgn}
has an indirect, homotopical proof, in this section we give a short, independent, algebraic proof
of these results.

The following elementary lemma is the key ingredient.

\begin{lem}
    Let $H$ be a group, let $n,m : \N$, and let $x$, $y$, $\hat{x}$ and $\hat{y}$ be
    elements of $H$ with the property that
    $\hat{x}$ is the unique element of $H$ such that $\hat{x}^n = x$ and
    $\hat{y}$ is the unique element of $H$ such that $\hat{y}^m = y$.
    If $x$ and $y$ commute, then $\hat{x}$ and $\hat{y}$ commute.
\end{lem}

\begin{proof}
    We first show that $x$ and $\hat{y}$ commute.
    The $m$-th power of $x \hat{y} x^{-1}$ is $x \hat{y}^m x^{-1} = x y x^{-1} = y$,
    so by the uniqueness of $\hat{y}$, it must be the case that $x \hat{y} x^{-1} = \hat{y}$.

    Similarly, we have that
    the $n$-th power of $\hat{y} \hat{x} \hat{y}^{-1}$ is
    $\hat{y} \hat{x}^n \hat{y}^{-1} = \hat{y} x \hat{y}^{-1} = x$,
    so by the uniqueness of $\hat{x}$, we have $\hat{y} \hat{x} \hat{y}^{-1} = \hat{x}$.
\end{proof}

\begin{prp}
    Let $G$ be an abelian group, let $n : \N$, and let $n : G \to G$ be the multiplication by $n$ map.
    Then, for every uniquely $n$-divisible group $H$, the precomposition map
    \[
        n^* : \Hom(G,H) \lra \Hom(G,H)
    \]
    is an equivalence.
\end{prp}

\begin{proof}
    Given a map $f : G \to H$, we have to show that there exists a unique $\hat{f} : G \to H$ such that
    $\hat{f} \circ n = f$.
    Since $H$ is uniquely $n$-divisible, we have an inverse function $\phi : H \to H$ to the $n$-th power map $n : H \to H$.
    It follows that if $\hat{f}$ exists, then $\hat{f} = \phi \circ f$.
    So we only have to check that $\hat{f}$ is a group homomorphism.

    It is clear that $\hat{f}$ preserves the identity element, so it remains to show that it preserves
    the group operation. Take two elements $a,b : G$, and consider $f(a),f(b) : H$. These are two commuting
    elements that have unique $n$-th roots. So their $n$-th roots $\phi(f(a)), \phi(f(b)) : H$ must also
    commute. This implies that
    \[
        (\hat{f}(a) \cdot \hat{f}(b))^n = \hat{f}(a)^n \cdot \hat{f}(b)^n = f(a) \cdot f(b) = f(a + b) .
    \]
    So by the uniqueness of $n$-th roots, $\hat{f}(a) \cdot \hat{f}(b) = \phi(f(a + b)) = \hat{f}(a+b)$.
\end{proof}

Using this result, given an abelian group $G$,
it is straightforward to prove that the colimit of the sequence displayed in
\cref{theorem:localizationKgn} is a localization of $G$ away from the family $S$
in the category of groups.
Moreover, this colimit is abelian, so it is also the localization of $G$
in the category of abelian groups.


\section{Evaluation on retrieval systems}

The goal of evaluation is to assess the quality of the results
obtained by an IR system.
There's the need of knowing a \emph{ground truth}, so an annotated corpus
where for each task we know what documents are relevant. The annotations
could be created manually or derived from the data, if it contains
annotations.

\subsection{The notion of quality}
Given a corpus $C$ and a query $q$, the task is to find a set of
documents $A_{q,C}$ that match $q$, but after retrieving such documents,
there's the need to estimate the quality of results.

\paragraph{Precision}
To formalise the quality of the retrieved documents $A_{q,C}$ we could
count how many of these documents are relevant to $q$, this
is the notion of precision:
$$\mathit{Prec} = \frac{\mathit{relevant\;retrieved}}{\mathit{retrieved}}$$
Note that in order to know if a document is relevant or not we need the
ground truth or a user feedback.

This measure does not suffice, as for instance, if we retrieve
only one correct document we would have maximum precision.

\paragraph{Recall}
The precision measure does not take in consideration how many relevant
documents are there, that is crucial to assess quality of a query result.
So we can consider another measure, called Recall:
$$\mathit{Rec} = \frac{\mathit{relevan\;retrieved}}{\mathit{relevant}}$$

\paragraph{Information need}
Given the two quality measures, should we aim at better precision or more
recall? Trivially both, but it actually depends on the information need.\\
In some cases a really high recall is not necessary, while other times
a lower precision could be accepted while not missing anything relevant.

\paragraph{F1 Score}
To take into consideration both precision and recall, we could take
a weighted mean, so a tradeoff between the twos
$$\mathit{F1} = \frac{2\cdot\mathit{Prec}\cdot\mathit{Rec}}
{\mathit{Prec} + \mathit{Rec}}$$

\paragraph{Baseline system}
To assess the quality of an IR system, we need a baseline system,
something trivial such as tossing a coin to decide whereas a document
is relevant or not.
Given its quality measure, we can infer the quality of our, hopefully,
more complex system, in fact, quality measures can't be seen as absolute
values, there's always the need to compare.

\subsection{Quality measures}
To formally define the notions introduced in the previous section, we need
to take into consideration a more detail measure for errors.

\paragraph{Confusion Matrix}
Given a query $q$, a ground truth $E_q$ of relevant documents with respect
to $q$, and a set of retrieved documents $A_q$, we define this matrix:
\begin{center}
    \begin{tabular}{c | c |c}
            & $d \in E_q$ & $d \notin E_q$\\
            \hline
            $d \in A_q$ & True positive & False positive\\
            \hline
            $d \notin A_q$ & False Negative & True Negative\\
    \end{tabular}
\end{center}
So now we can redefine the \emph{precision}, \emph{recall} and \emph{F1}
measures as follows
$$\mathit{Prec} = \frac{\mathit{TP}}{\mathit{TP} + \mathit{FP}}\;\;\;
\mathit{Rec} = \frac{\mathit{TP}}{\mathit{TP} + \mathit{FN}}\;\;\;
\mathit{F1} = \frac{\mathit{TP}}{\mathit{TP} + \frac{1}{2}(\mathit{FP} + \mathit{FN})}$$
The actual confusion matrix is obtained by counting the documents given the retrieved
ones and the ground truth.

The matrix can be useful to estimate the system parameters, for instance,
if the number of retrieved documents is set to a certain value $k$ and
the value of true positives is really high, probably a smaller $k$ would do the job,
while if a lot positives are left out, i.e, the matrix has a high number of
false negatives, maybe an higher $k$ would make the system better.

\paragraph{Other measures}
The are a lot of measures to estimate the quality of a system, such as
\emph{specificity}, \emph{negative predictive value}, \emph{miss-rate},
\emph{fall-out} and \emph{accuracy}.
Finding the right measure is really important, for instance, using accuracy with
an unbalanced dataset is not better than precision, recall and F1.

\subsection{Evaluation of ranking systems}
We talked about boolean retrieval systems and we took into consideration
if a document is retrieved or not.

In a raking scenario, we want to give importance not only to precision and recall,
but also to the rank assigned by the system.

\paragraph{Setting a threshold}
One way to go is to set a specific threshold and compute the precision and recall
of those top documents.
This method does not take into consideration the ranking of the documents.

\paragraph{Precision at K}
If we take the first $K$ retrieved documents, ordered by rank, we can estimate
the quality of the rank by computing the precision for the top $K$ documents.
By iterating the threshold we can better estimate the performances, opposed to
setting a unique threshold.\\
To decide what thresholds to use we could use the distribution of the system ranking.

\paragraph{Discounted cumulative gain}
This approach takes into consideration the ranking and discount the gain given by
a document with respect to its position in it.
$$\mathit{DCG} = \sum_{i = 1}^n\frac{R_j}{\log(i+1)}$$
where $R_j$ is the rank assigned to a document.

\paragraph{Precision vs Recall curve}
Another approach is to compute precision and recall measures at each point in the ranking.
If we take the measurements and plot them, we find a correlation between precision
and recall and if we compute the integral of that function, we obtain the average precision.

To have a smoother curve, it's possible to interpolate the precision, so for each
point in the recall axis, we take the maximum precision of consecutive points.

\begin{figure}[h]
    \centering
    \includegraphics[width=0.7\textwidth]{images/precision-recall.png}
    \caption{Example of a non-interpolated precision and recall curve}
\end{figure}


\documentstyle[11pt,reduce]{article}
\date{July 1994}
\title{A Definite Integration Interface for REDUCE}
\author{Kerry Gaskell \\
Konrad--Zuse--Zentrum f\"ur Informationstechnik Berlin\\
Takustra\"se 7 \\
D--14195 Berlin -- Dahlem \\
Federal Republic of Germany \\[0.05in]
E--mail: neun@zib.de\footnotemark[1]}

\begin{document}
\maketitle
\footnotetext[1]{This definite integration interface was written
during my one year placement at ZIB. Any comments and/or
problems should therefore be directed to Winfried Neun at
neun@zib.de.}

\section{Introduction}
This documentation describes part of \REDUCE's definite
integration package that is able to calculate the definite integrals of
many functions, including several special functions.  There are other
parts of this package, such as Stan Kameny's code for contour integration,
that are not included here.  The integration process described here is not
the more normal approach of initially calculating the indefinite integral,
but is instead the rather unusual idea of representing each function as a
Meijer G-function (a formal definition of the Meijer G-function can be
found in \cite {Prudnikov}), and then calculating the integral by using
the following Meijer G integration formula.

\begin{displaymath}
\int_{0}^{\infty} x^{\alpha-1} G^{s t}_{u v}
\left( \sigma x \  \Bigg\vert \  {( c_u) \atop (d_v)} \right)
G^{m n}_{p q} \left( \omega x^{l/k} \  \Bigg\vert \ {(a_p) \atop (b_q)}
\right) dx = k G^{i j}_{k l} \left( \xi \ \Bigg\vert \
{(g_k) \atop (h_l)} \right)  \hspace{5mm} (1)
\end{displaymath}

The resulting Meijer G-function is then retransformed, either directly
or via a hypergeometric function simplification, to give
the answer. A more detailed account of this theory can be found in
\cite {Adamchik:90}.

\section{Integration between zero and infinity}

As an example, if one wishes to calculate the following integral

\begin{displaymath}
\int_{0}^{\infty} x^{-1} e^{-x} sin(x) \, dx
\end{displaymath}

then initially the  correct Meijer G-functions are found, via a
pattern matching
process, and are substituted into (1) to give

\begin{displaymath}
\sqrt{\pi} \int_{0}^{\infty} x^{-1} G^{1 0}_{0 1} \left(x
\ \Bigg\vert \
{. \atop 0}\right) G^{1 0}_{0 2}\left(\frac{x^{2}}{4}
\ \Bigg\vert \ {. \; .  \atop \frac{1}{2} \; 0} \right) dx
\end{displaymath}

The cases for validity of the integral are then checked. If these
are found to be satisfactory then the formula is calculated and we
obtain the following Meijer G-function

\begin{displaymath}
G^{1 2}_{2 2} \left(1 \ \Bigg\vert \ {\frac{1}{2} \; 1 \atop
\frac{1}{2} \; 0} \right)
\end{displaymath}

This is reduced to the following hypergeometric function

\begin{math}
\hspace{50mm} _2F_1 (\frac{1}{2},1;\frac{3}{2};-1 )
\end{math}

which is then calculated to give the correct answer of

\begin{displaymath}
\frac{\pi}{4}
\end{displaymath}

The above formula (1) is also true for the integration of a single
Meijer G-function by replacing the second Meijer G-function
with a trivial Meijer G-function.

A list of numerous particular Meijer G-functions is available in
\cite {Prudnikov}.

\section{Integration over other ranges}

Although the description so far has been limited to the computation of
definite integrals between 0 and infinity, it can also be extended to
calculate integrals between 0 and some specific upper bound, and
by further extension, integrals between any two bounds.  One approach is
to use the Heaviside function, i.e.

\begin{displaymath}
\int_{0}^{\infty} x^{2} e^{-x} H(1-x)\,dx = \int_{0}^{1} x^{2} e^{-x}dx
\end{displaymath}

Another approach, again not involving the normal indefinite integration
process, again uses Meijer G-functions, this time by means of the
following formula

\begin{displaymath}
\int_{0}^{y} x^{\alpha-1} G^{m n}_{p q}
\left( \sigma x \  \Bigg\vert \  {( a_u) \atop (b_v)} \right) dx=%
y^{\alpha}\,G^{m \; n+1}_{p+1 \; q+1} \left( \sigma y \  \Bigg\vert \
{( a_1..a_n,1-\alpha,a_{n+1}..a_p)
\atop (b_1..b_m,-\alpha,b_{m+1}..b_q)} \right) (2)
\end{displaymath}

For a more detailed look at the theory behind this see
\cite{Adamchik:90}.

For example, if one wishes to calculate the following integral

\begin{displaymath}
\int_{0}^{y} sin(2 \sqrt{x}) \, dx
\end{displaymath}

then initially the correct Meijer G-function is found, by a pattern
matching process, and is substituted
into (2) to give

\begin{displaymath}
\int_{0}^{y} G^{1 0}_{0 2}\left(x
\ \Bigg\vert \ {. \; .  \atop \frac{1}{2} \; 0} \right) dx
\end{displaymath}

which then in turn gives

\begin{displaymath}
y \; G^{1 1}_{1 3}\left(y \ \Bigg\vert \ {0 \atop
\frac{1}{2} -\!1 \; 0} \right) dx
\end{displaymath}

and returns the result

\begin{displaymath}
\frac{\sqrt{\pi} \, J_{3/2}(2 \, \sqrt{\,y}) \, y}{y^{1/4}}
\end{displaymath}

\section{Using the definite integration package}
To use this package, you must first load it by the command
\begin{verbatim}
load_package defint;
\end{verbatim}
Definite integration is then possible using the \verb+int+
command with the syntax:
\begin{verbatim}
   INT(EXPRN:algebraic,VAR:kernel,LOW:algebraic,UP:algebraic)
       :algebraic.
\end{verbatim}
where LOW and UP are the lower and upper bounds respectively for
the definite integration of EXPRN with respect to VAR.

\subsection{Examples}

\begin{displaymath}
\int_{0}^{\infty} e^{-x} dx
\end{displaymath}

\begin{verbatim}
 int(e^(-x),x,0,infinity);

 1
\end{verbatim}

\begin{displaymath}
\int_{0}^{\infty} x sin(1/x) \, dx
\end{displaymath}

\begin{verbatim}
 int(x*sin(1/x),x,0,infinity);

           1
INT(X*SIN(---),X,0,INFINITY)
           X
\end{verbatim}

\begin{displaymath}
\int_{0}^{\infty} x^2 cos(x) \, e^{-2x} dx
\end{displaymath}

\begin{verbatim}
 int(x^2*cos(x)*e^(-2*x),x,0,infinity);

   4
 -----
  125
\end{verbatim}

\begin{displaymath}
\int_{0}^{\infty} x e^{-1/2x} H(1-x) \,dx = \int_{0}^{1} x e^{-1/2x} dx
\end{displaymath}

\begin{verbatim}
 int(x*e^(-1/2x)*Heaviside(1-x),x,0,infinity);

  2*(2*SQRT(E) - 3)
 -------------------
       SQRT(E)
\end{verbatim}

\begin{displaymath}
\int_{0}^{1} x \,log(1+x) \,dx
\end{displaymath}

\begin{verbatim}
 int(x*log(1+x),x,0,1);

  1
 ---
  4
\end{verbatim}

\begin{displaymath}
\int_{0}^{y} cos(2x) \,dx
\end{displaymath}

\begin{verbatim}
 int(cos(2x),x,y,2y);

 SIN(4*Y) - SIN(2*Y)
---------------------
          2
\end{verbatim}

\section{Integral Transforms}

A useful application of the definite integration package is in the
calculation of various integral transforms. The transforms
available are as follows:

\begin{itemize}
\item Laplace transform
\item Hankel transform
\item Y-transform
\item K-transform
\item StruveH transform
\item Fourier sine transform
\item Fourier cosine transform
\end{itemize}

\subsection{Laplace transform}

The Laplace transform

$\hspace{20 mm} f(s) = \cal L$ \{F(t)\} =
$\int_{0}^{\infty} e^{-st}F(t)\,dt$

can be calculated by using the \verb+laplace_transform+ command.

This requires as parameters

\begin{itemize}
\item the function to be integrated
\item the integration variable.
\end{itemize}

For example

$\hspace{56 mm} \cal L$ $\{e^{-at}\} \\$
is entered as

\begin{verbatim}
        laplace_transform(e^(-a*x),x);
\end{verbatim}

and returns the result

\begin{displaymath}
\frac{1}{s+a}
\end{displaymath}

\subsection{Hankel transform}

The Hankel transform

\begin{displaymath}
f(\omega) = \int_{0}^{\infty} F(t) \,J_{\nu}(2\sqrt{\omega t}) \,dt
\end{displaymath}

can be calculated by using the \verb+hankel_transform+ command e.g.

\begin{verbatim}
        hankel_transform(f(x),x);
\end{verbatim}

This is used in the same way as the \verb+laplace_transform+ command.

\subsection{Y-transform}

The Y-transform

\begin{displaymath}
f(\omega) = \int_{0}^{\infty} F(t) \,Y_{\nu}(2\sqrt{\omega t}) \,dt
\end{displaymath}

can be calculated by using the \verb+Y_transform+ command e.g.

\begin{verbatim}
        Y_transform(f(x),x);
\end{verbatim}

This is used in the same way as the \verb+laplace_transform+ command.

\subsection{K-transform}

The K-transform

\begin{displaymath}
f(\omega) = \int_{0}^{\infty} F(t) \,K_{\nu}(2\sqrt{\omega t}) \,dt
\end{displaymath}

can be calculated by using the \verb+K_transform+ command e.g.

\begin{verbatim}
        K_transform(f(x),x);
\end{verbatim}

This is used in the same way as the \verb+laplace_transform+ command.

\subsection{StruveH transform}

The StruveH transform

\begin{displaymath}
f(\omega) = \int_{0}^{\infty} F(t) \,StruveH(\nu,2\sqrt{\omega t}) \,dt
\end{displaymath}

can be calculated by using the \verb+struveh_transform+ command e.g.

\begin{verbatim}
        struveh_transform(f(x),x);
\end{verbatim}

This is used in the same way as the \verb+laplace_transform+ command.

\subsection{Fourier sine transform}

The Fourier sine transform

\begin{displaymath}
f(s) = \int_{0}^{\infty} F(t) \,sin (st) \,dt
\end{displaymath}

can be calculated by using the \verb+fourier_sin+ command e.g.
\begin{verbatim}
        fourier_sin(f(x),x);
\end{verbatim}

This is used in the same way as the \verb+laplace_transform+ command.

\subsection{Fourier cosine transform}

The Fourier cosine transform

\begin{displaymath}
f(s) = \int_{0}^{\infty} F(t) \,cos (st) \,dt
\end{displaymath}

can be calculated by using the \verb+fourier_cos+ command e.g.
\begin{verbatim}
        fourier_cos(f(x),x);
\end{verbatim}

This is used in the same way as the \verb+laplace_transform+ command.

\section{Additional Meijer G-function Definitions}

The relevant Meijer G representation for any function is found by a
pattern-matching process which is carried out on a list of Meijer
G-function definitions. This list, although extensive, can never hope
to be complete and therefore the user may wish to add more definitions.
Definitions can be added by adding the following lines:

\begin{verbatim}
  defint_choose(f(~x),~var => f1(n,x);

  symbolic putv(mellin!-transforms!*,n,'
                (() (m n p q) (ai) (bj) (C) (var)));

\end{verbatim}
     where f(x) is the new function, i = 1..p, j=1..q, C = a constant,
%where i = 1..p, j=1..q, C = a constant,
     var = variable, n = an indexing number.

For example when considering $cos (x)$ we have

\it Meijer G representation  -
\begin{displaymath}
\sqrt{\pi} \,G^{1 0}_{0 2}\left(\frac{x^{2}}{4} \ \Bigg\vert
\ { . \; . \atop 0 \; \frac{1}{2}} \right) dx
\end{displaymath}

\it Internal definite integration package representation  -
\begin{verbatim}
  defint_choose(cos(~x),~var)   => f1(3,x);
\end{verbatim}

\rm where 3 is the indexing number corresponding to the 3
in the following formula

\begin{verbatim}
  symbolic putv(mellin!-transforms!*,3,'
                (() (1 0 0 2) () (nil (quotient 1 2))
                (sqrt pi) (quotient (expt x 2) 4)));
\end{verbatim}

or the more interesting example of $J_{n}(x)$:

\it Meijer G representation  -
\begin{displaymath}
G^{1 0}_{0 2} \left(\frac{x^{2}}{4} \ \Bigg\vert
\ {. \; .  \atop \frac{n}{2} \; {\frac{-n}{2}}} \right) dx
\end{displaymath}

\it Internal definite integration package representation  -

\begin{verbatim}
  defint_choose(besselj(~n,~x),~var) => f1(50,x,n);

  symbolic putv(mellin!-transforms!*,50,'
                ((n) (1 0 0 2) () ((quotient n 2)
                                   (minus quotient n 2)) 1
                                   (quotient (expt x 2) 4)));
\end{verbatim}

\section{The print\_conditions function}

\rm The required conditions for the validity of the transform integrals
can be viewed using the following command:

\begin{verbatim}
        print_conditions().
\end{verbatim}

For example after calculating the following laplace transform

\begin{verbatim}
        laplace_transform(x^k,x);
\end{verbatim}

using the \verb+print_conditions+ command would produce

\begin{verbatim}

repart(sum(ai) - sum(bj)) + 1/2 (q + 1 - p)>(q - p) repart(s)

 and ( - min(repart(bj))<repart(s))<1 - max(repart(ai))

 or mod(arg(eta))=pi*delta

 or ( - min(repart(bj))<repart(s))<1 - max(repart(ai))

 or mod(arg(eta))<pi*delta

\end{verbatim}

where
\begin{displaymath}
\begin{array}{ll}
delta = s+t-\frac{u-v}{2}\\
eta = 1-\alpha(v-u)-\mu-\rho\\
\mu = \sum_{j=1}^{q} b_{j} - \sum_{i=1}^{p} a_{i} + \frac{p-q}{2} + 1\\
\rho = \sum_{j=1}^{v} d{j} - \sum_{i=1}^{u} c_{i} + \frac{u-v}{2} + 1\\
s,t,u,v,p,q,\alpha \; {\rm as \; in \; (1)}
\end{array}
\end{displaymath}

\section{Acknowledgements}
I would like to thank Victor Adamchik whose implementation of the
definite integration package for \REDUCE is vital to this
interface.

\begin{thebibliography}{}

\bibitem{Prudnikov} A.P. Prudnikov, Yu.A. Brychkov and O.I. Marichev,
{\em Integrals and Series, Volume 3: More Special Functions} Gordon
and Breach Science Publishers (1990)

\bibitem{Adamchik:90} V.S. Adamchik and O.I. Marichev, {\em The
Algorithm for Calculating Integrals of Hypergeometric Type Functions
and its Realization in Reduce System} from {\em ISSAC 90:Symbolic and
Algebraic Computation} Addison-Wesley Publishing Company (1990)

\bibitem{Luke} Yudell L. Luke, {\em The Special Functions and their
Approximations, Volume 1} Academic Press (1969).

\end{thebibliography}

\end{document}


    \filetitle{isexplosive}{True if any eigenvalue is outside unit circle}{VAR/isexplosive}

	\paragraph{Syntax}\label{syntax}

\begin{verbatim}
Flag = isexplosive(V)
\end{verbatim}

\paragraph{Input arguments}\label{input-arguments}

\begin{itemize}
\itemsep1pt\parskip0pt\parsep0pt
\item
  \texttt{V} {[} VAR {]} - VAR object whose eigenvalues will be tested
  for explosiveness.
\end{itemize}

\paragraph{Output arguments}\label{output-arguments}

\begin{itemize}
\itemsep1pt\parskip0pt\parsep0pt
\item
  \texttt{Flag} {[} \texttt{true} \textbar{} \texttt{false} {]} - True
  if at least one eigenvalue is outside unit circle.
\end{itemize}

\paragraph{Options}\label{options}

\begin{itemize}
\itemsep1pt\parskip0pt\parsep0pt
\item
  \texttt{'tolerance='} {[} numeric \textbar{}
  \emph{\texttt{getrealsmall()}} {]} - Tolerance for the eigenvalue
  test.
\end{itemize}

\paragraph{Description}\label{description}

\paragraph{Example}\label{example}