Searching for Secluded Dark Matter with H.E.S.S., Fermi-LAT, and Planck

Abstract: Short-lived mediators are often used to describe dark matter interactions with Standard Model particles. When the dark matter mass is heavier than the mass of the mediator, it may self-annihilate into short-lived mediators, and in some cases this might be the dominant annihilation channel. This scenario is known as secluded dark matter. We use Fermi-LAT observations of dwarf spheroidal galaxies, H.E.S.S. data from the Galactic center, and Planck measurements of the Cosmic Microwave Background to constrain secluded dark matter. We explore the interplay between these experiments and we assess the impact of the mediator mass on our bounds, an often overlooked yet very important point. In particular, we exclude pair -annihilation cross-sections greater or on the order of $\sigma v \sim 4 \times 10^{-27} {\rm cm^3/s}$ for dark matter masses around $10$~GeV and greater or on the order of $\sigma v \sim \times 10^{-25} {\rm cm^3/s}$ for dark matter masses around a TeV. Our findings supersede previous constraints which use Fermi-LAT data, and constitute the first limits on secluded dark sectors using the H.E.S.S. telescope. We also show that one can fit TeV gamma-ray observations from H.E.S.S. with secluded dark matter annihilations, with the mediator mass impacting the best-fit dark matter particle mass. Our findings indicate that any assessment of secluded dark sectors in the context of indirect detection significantly depends on the choice of the mediator mass.

\section{Introduction}
\label{sec:intro}

The nature of dark matter is one of the most exciting and important open questions in science \cite{Bertone:2004pz,Strigari:2013iaa,Profumo:2013yn,Bertone:2016nfn,Queiroz:2016sxf}. The Standard Model (SM) does not have a fundamental particle capable of explaining the cold dark matter in our universe, which constitutes 27\% of the entire energy-budget.
 Among proposed dark matter candidates, Weakly Interacting Massive Particles (WIMPs) stand out as uniquely well motivated, since via the thermal freeze-out, they could naturally explain the observed dark matter abundance \cite{Arcadi:2017kky}.\\

Among different detection techniques, indirect dark matter detection, the detection of the debris of dark matter annihilations or decays, has the remarkable advantage of connecting particle physics and astrophysics: a potential dark matter signal would pinpoint the dark matter mass and annihilation cross-section, provided certain astrophysical inputs \cite{Bringmann:2012ez}.\\

Typically, indirect searches for dark matter are focused on final states belonging to the SM spectrum such as quarks, leptons and gauge bosons \cite{Bringmann:2011ye,Hooper:2012sr,Ibarra:2013zia,Bergstrom:2013jra,Lin:2014vja,Bringmann:2014lpa,Gonzalez-Morales:2014eaa,DiMauro:2015jxa,Buckley:2015doa,Giesen:2015ufa,Lu:2015pta,Cavasonza:2016qem,Belotsky:2016tja,Profumo:2016idl,Huang:2016tfo,Caputo:2016ryl,Jin:2017iwg}. However, it is also possible that WIMPs annihilate mostly into short-lived particles which later decay into SM particles \cite{Mardon:2009rc,Cerdeno:2015ega,Okawa:2016wrr,Karwin:2016tsw,Kim:2016csm,Batell:2017rol,Campos:2017odj,Arcadi:2017vis}. This setup is very common for dark matter models in the context of the $Z^\prime$ portal when the dark matter is heavier than the $Z^\prime$ \cite{Pospelov:2007mp,Mardon:2009rc,Kang:2010mh,Murase:2012xs,Alves:2013tqa,Martinez:2014ova,DEramo:2016gos,Celis:2016ayl,DeRomeri:2017oxa}, in vector dark matter models \cite{Ko:2014gha}, also in models where the dark matter is entirely confined to the dark sector but annihilates to particles that subsequently decay to SM products \cite{Kim:2016csm,Ardid:2017lry} as well as in studies where bounds states are formed \cite{Cirelli:2016rnw} (see \cite{Fortes:2015qka,Fortes:2017kca} for other scenarios where secluded dark matter arises). \\

Motivated by the presence of such ``secluded annihilations'' in several models, numerous studies have been performed in the context of indirect dark matter detection \cite{Pospelov:2008jd,Batell:2009zp,Abdullah:2014lla,Martin:2014sxa,Dutta:2015ysa,Rajaraman:2015xka,Elor:2015tva,Escudero:2017yia}. The present study differs from previous work in several key
aspects:\\

{\bf (i)} We do not focus on one specific dataset, and we consistently include Fermi-LAT, H.E.S.S. and Planck data to draw our conclusions;

{\bf (ii)} We use seven years of Fermi-LAT data in the direction of dozens of dwarf spheroidal galaxies (dSphs) with the updated instrument response function (PASS8) \cite{Ackermann:2015zua};

{\bf (iii)} We make use of 10 years of H.E.S.S. data, equivalent to 254h live-time exposure, on the Galactic center with the latitude region $|b| < 3^\circ$ removed \cite{Abdallah:2016ygi};

{\bf (iv)} We account for Planck CMB data, as such data is rather sensitive to any injection of electromagnetically interacting particles capable of producing appreciable ionization and heat, thus severely constraining dark matter annihilations at early times \cite{Slatyer:2015jla,Slatyer:2015kla};

{\bf (v)} We critically and quantitatively assess the impact of the mediator mass on our bounds. We show that the mass of the short-lived mediator does matter in the derivation of precise limits on the dark matter annihilation cross-section and in the determination of best-fit regions of parameter space. In the context of indirect dark matter detection, these mediators are typically assumed to simply be sufficiently heavier than the  SM particle pairs produced in their decay modes. However, if one departs from this particular assumption, the experimental limits change significantly;

{\bf (vi)} We discuss the possibility of explaining the TeV gamma-ray excess observed by the H.E.S.S. telescope in the Galactic center \cite{Aharonian:2009zk,Abramowski:2016mir} with secluded dark matter annihilations.\\

Our study is structured as follows: In {\it section 2}, we lay out the setup that we focus on; in {\it section 3} we discuss how we derive the production of gamma-rays and ionization induced by dark matter annihilation; in {\it section 4} we describe the dataset we use; in {\it section 5} we present our limits, {\it section 6} we address the H.E.S.S. TeV excess in terms of secluded dark matter and finally, in {\it section 7}, we draw our conclusions.

\section{Secluded Dark Matter}

Secluded dark matter refers to a scenario where the dark matter particle annihilates preferentially into particles that do not belong to the SM particle content.
Dark matter particles that annihilate directly into SM particles can be severely constrained by data since the same Feynman diagram that typically leads to dark matter annihilations is also responsible for dark matter-nucleon scattering, the subject of intense and highly constraining experimental searches \cite{Akerib:2015rjg,Amole:2016pye,Hehn:2016nll,Aalbers:2016jon,Agnese:2016cpb,Aprile:2016swn,Fu:2016ega,Akerib:2016lao,Cui:2017nnn,Aprile:2017ngb,Aprile:2017yea,Fatemighomi:2016ree}. There are ways to break this direct relation between annihilation and scattering such as via co-annihilations \cite{Edsjo:1997bg}, multi-mediators \cite{Duerr:2016tmh}, or velocity-dependent suppressions, among others \cite{DEramo:2010keq,Belanger:2012vp,Ko:2014loa,Cai:2015zza,Arcadi:2017vis}. However, one interesting possibility that does not require the existence of extra fields is to simply enforce the dark matter mass to be heavier than the mediator's mass. In this case, if the coupling between the dark matter particle and the mediator is sufficiently large, the main annihilation channel can be into a pair of short-lived mediators, which constitutes a paradigmatic secluded dark matter setup \cite{Pospelov:2007mp,Essig:2009jx,Alves:2015pea,Ducu:2015fda,Alves:2015mua,Okada:2016tci,Duerr:2016tmh,Jacques:2016dqz}. Another viable secluded dark matter scenario occurs when the dark matter particle belongs to either a $SU(N)$ group \cite{Karam:2015jta,Karam:2016rsz,Arcadi:2016kmk}, or a hidden valley setup \cite{Strassler:2006im,Cassel:2009pu}, or interacts with SM particles via the Chern-Simons portal \cite{Arcadi:2017jqd}. Either way, dark matter annihilation into short-lived mediators occur, and can be the most important final state. Therefore,  one can constrain the parameter space of such secluded dark matter models by searching for the byproducts of this $2 \rightarrow 4$ annihilation processes (see Fig.\ref{fig:annihilation}).

\begin{figure}[!h]
\centering
\includegraphics[width=0.3\columnwidth]{diag}
\caption{Feynman diagrams for dark matter annihilation into short-lived states that decay into SM particles.}
\label{fig:annihilation}
\end{figure}

There are several possible annihilation final states based on Fig.\ref{fig:annihilation}. In order to cover many possibilities in this work, we will investigate the cases which the short-lived state decays either into leptons or into quarks, and also vary the mediator mass to assess how relevant its mass is in the derivation of the bounds on the dark matter annihilation cross section. We start first describing how we compute the dark matter signal.

\section{Dark Matter Annihilation}
\label{sec:dmann}

\subsection{Gamma-rays}
The presence of dark matter in our neighborhood motivates us to search for signs of dark matter annihilations in regions where the dark matter density is expected to be very high, such as the Galactic Center and dSphs. The differential flux for dark matter annihilation in any angular direction is

\begin{equation}
\label{eq:flux}
\frac{d\Phi_\gamma(\Delta \Omega)}{dE}(E_\gamma)=\frac{1}{4\pi}\frac{\sigma v}{2 M_{DM}^2}\frac{dN_\gamma}{dE_{\gamma}}\cdot J_{ann}
\end{equation}where $J_{ann}$ is the astrophysical J-factor with,
\begin{equation}
   J_{ann} \; =\; \int_{\Delta \Omega} d\Omega \int \rho_{DM}^2 (s) ds\;,
 \label{eq:Jfac_def}
\end{equation} where $s\; =\; s(\theta )$ is a line-of-sight variable and $\theta$ is the angle between the line of sight and the line to the center of the dark matter halo, $\sigma v$ is annihilation cross section today, i.e. non-relativistic, $M_{DM}$ the dark matter mass, and $\rho_{DM}$ the dark matter density profile which we will assume to be a Navarro-Frenk-While (NFW) profile \cite{Navarro:2008kc} where,

\begin{equation}
   \rho_{DM} (r) \; =\; \frac{\rho_s}{(r/r_s) (1+ r/r_s)^2}\;,
 \label{eq:DM_profile}
\end{equation}where $r_s$ and $\rho_s$ are the scale radius and the characteristic density respectively. The integral in Eq.\eqref{eq:Jfac_def} is computed over the line of sight. \\

We  adopt a NFW profile because it is the same profile used by the Fermi-LAT collaboration. Different profiles will induce an overall change in our limits by a constant factor depending on whether a steeper \cite{Graham:2005xx} or more core-like profile is adopted \cite{Burkert:1995yz,Salucci:2000ps}.\\

The key quantity in the derivation of our limits is the energy spectrum because we are focused on $2\rightarrow 4$ annihilations. The shape of the energy spectrum will allow us to understand the results we present below. We use the PPPC4DM code to compute the energy spectra when the V decays into charged leptons \cite{Cirelli:2010xx}. We emphasize that PPPC4DM by default assumes the mediator to be just slightly heavier than its decay products. In order to derive bounds for other hadronic channels and assess the importance of the mediator mass, we generate the energy spectra with Pythia 8 \cite{Sjostrand:2014zea}. \\

In fig.\ref{fig1} we show the energy spectra of a $1$~TeV dark matter particle annihilating into short-lived mediators with these decaying into charged leptons (left-panel) or hadrons (right-panel). Thus far, we are assuming the dark matter particle to be much heavier than the mediator, i.e. $M_{DM} \gg M_V$.\\

\begin{figure}[!h]
\centering
\includegraphics[width=0.49\columnwidth]{plot1dNdElepstdv2}
\includegraphics[width=0.49\columnwidth]{plot2dNdEquarksstdv2}
\caption{Energy spectrum for a $1$~TeV dark matter annihilating into VV, with the V mass much larger than the final state's. Left-panel: V decays either into $ee$ or $\mu \bar{\mu}$ or $\tau \bar{\tau}$. Right-panel: V decays either into $u\bar{u}$ or $b \bar{b}$ or $t\bar{t}$. Moreover, we superimpose the direct annihilation channel ${\rm DM\, DM}\rightarrow \tau \bar{\tau}$ on the left-panel, and ${\rm DM\, DM} \rightarrow b\bar{b}$ on the right-panel for comparison.}
\label{fig1}
\end{figure}

By comparing the energy spectra for the dark matter annihilations into $2 \tau$ and $4\tau$ we notice that the energy spectrum is harder for the latter at lower energies between $1-100$~GeV. This occurs for the annihilations into $4b$ only during a smaller energy region, $E=20-100$~GeV, and it is much less prominent. In these figures, we take the mediator mass to be much heavier than its decay modes.\\

We will repeat the same procedure but take the mediator mass to be comparable to the dark matter mass. The result is displayed in Fig.\ref{fig2}. For the leptonic case, the difference in the overall energy spectrum is mild, but for the case which the mediator decays into hadrons, the difference is clearly visible, making the annihilation into $4b$ mimic the one into $2b$. \\

\begin{figure}[!h]
\centering
\includegraphics[width=0.49\columnwidth]{plot4dNdElepdegstdv2}
\includegraphics[width=0.49\columnwidth]{plot5dNdEquarksdegstdv2}
\caption{Energy spectrum for a $1$~TeV dark matter annihilating into $VV$, with $V$ being nearly degenerate in mass. Left-panel: $V$ decays either into $ee$ or $\mu \bar{\mu}$ or $\tau \bar{\tau}$. Right-panel: $V$ decays either into $u\bar{u}$ or $b \bar{b}$ or $t\bar{t}$. Moreover, we superimpose the direct annihilation channel ${\rm DM\, DM} \rightarrow \tau \bar{\tau}$ on the left-panel, and ${\rm DM\, DM} \rightarrow b\bar{b}$ on the right-panel for comparison.}
\label{fig2}
\end{figure}

In order to have a clearer picture of the relevance of the mediator mass in our computation, in Fig.\ref{fig3}, we derive the energy spectra for two leptonic decay modes of the mediator, $e\bar{e}$ on the left-panel and $\tau \bar{\tau}$ on the right-panel, and vary the mediator mass, while keeping $M_{DM}=1$~TeV. Notice that the mediator yields very mild differences in the energy spectra. We will see further that this does not hold true for annihilations into $4e$ and $4\mu$. Moreover, when the $V$ particle decays hadronically the mediator mass is very important. Notice in Fig.\ref{fig4} that the assumption made on the mediator mass can significantly change the energy spectra, especially towards lower energies. Therefore, any assessment of secluded dark sectors in the context of indirect detection cannot be regarded as model-independent since they rely significantly on choice for the mediator mass. \\

\begin{figure}[!h]
\centering
\includegraphics[width=0.49\columnwidth]{dNdEMVee}
\includegraphics[width=0.49\columnwidth]{dNdEMVtau}
\caption{Left-panel: energy spectrum for a $1$~TeV dark matter annihilating into $4e$ for $M_V=5, 100, 970$~GeV; Right-panel: energy spectrum for a $1$~TeV dark matter annihilating into $4\tau$ for $M_V=5, 100, 970$~GeV. We superimposed the direct annihilation channel ${\rm DM\, DM} \rightarrow e \bar{e}$ on the left-panel, and ${\rm DM\, DM} \rightarrow \tau\bar{\tau}$ on the right-panel for comparison.}
\label{fig3}
\end{figure}

\begin{figure}[!h]
\centering
\includegraphics[width=0.49\columnwidth]{dNdEMVuu}
\includegraphics[width=0.49\columnwidth]{dNdEMVbb}
\caption{Left-panel: energy spectrum for a $1$~TeV dark matter annihilating into $4u$ for $M_V=5, 100, 970$~GeV; Right-panel: energy spectrum for a $1$~TeV dark matter annihilating into $4b$ for $M_V=5, 100, 970$~GeV. We superimposed the direct annihilation channel ${\rm DM\, DM} \rightarrow u \bar{u}$ on the left-panel, and ${\rm DM\, DM} \rightarrow b\bar{b}$ on the right-panel for comparison.}
\label{fig4}
\end{figure}

Now we have the gamma-ray yield for different dark matter annihilation setups, we discuss dark matter signals in the CMB.

\subsection{Cosmic Microwave Background}

In the context of thermal freeze out, dark matter annihilations are efficient in the  dark ages,  $z \leq 1200$. However, such energy injection produced by dark matter annihilations heats and ionizes the photon-baryon plasma, perturbing the ionization history precisely measured  by Planck \cite{Padmanabhan:2005es}. Such dark matter annihilations, while  not necessarily capable of changing the redshift of recombination, may alter the residual ionization after recombination which is subject to tight constraints.\\

These constraints are based on the following procedure: The energy density injection rate is determined by the product of the number density of pairs of DM particles which is $n_{DM}/2$ for Majorana particles, the
annihilation probability per time unit $P_{ann}=  \langle\sigma v \rangle n_{DM},$ and the energy released per dark matter annihilation $E_{ann}= 2 M_{DM}$. Therefore, we obtain

\begin{equation}
\frac{dE}{dt \, dV}_{inj}(z) = \left(\frac{n_{DM}}{2}\right) \, \left(\langle\sigma v \rangle n_{DM}\right)\,  \left( 2m_{DM} \right).
\label{Einj}
\end{equation}
\\
Assuming the dark matter particle to be non-relativistic and considering only the smooth cosmological dark matter halo, we find

\begin{equation}
n_{DM}= \rho_{DM} M_{DM}= \rho_c\, \Omega_{DM}\, M_{DM}= \rho_c\, \Omega_{DM \, o} \, (1+z)^3 \, M_{DM},
\label{eqnDM}
\end{equation}where $\Omega_{DM \, o}$ is the dark matter abundance today.\\

Substituting Eq.\eqref{eqnDM} into Eq.\eqref{Einj} we obtain

\begin{equation}
\frac{dE}{dt \, dV}_{inj}(z) = \rho_c^2 \, \Omega_{DM \, o}^2 \, (1+z)^6 \left( \frac{\langle\sigma v \rangle}{M_{DM}} \right).
\label{Einj}
\end{equation}

The injected energy is, however, not equal to the energy  deposited in the inter-galactic medium, because the response of the medium to energy injection does depend on the final states produced in the dark matter as well as when this took place. Hence, in order to account for this effect, we add an efficiency function which is redshift dependent, $f(z)$. In this way,
\begin{equation}
\frac{dE}{dt \, dV}_{dep} (z)= f(z)\frac{dE}{dt \, dV}_{inj}(z),
\end{equation}which means that the particle physics input of this effect is encompassed in $f(z) \langle\sigma v\rangle /M_{DM}$. However $f(z)$ is non-trivial to compute. Recently, the redshift dependence has been averaged over and the efficiency deposition has been separated from the energy spectrum \cite{Slatyer:2015jla}, as follows,

\begin{equation}
f_{eff}=\frac{1}{2 M_{DM}}\int_0^{M_{DM}}EdE\left(f_{eff}^{\gamma}(E)\frac{dN}{dE^{\gamma}}+2 f_{eff}^{e^+}(E)\frac{dN}{dE^{e^+}}\right),
\label{feeEq}
\end{equation}where the effect of dark matter annihilations on the CMB for any annihilation final states is determined by,

\begin{equation}
p_{ann}=f_{eff} \frac{\langle \sigma v \rangle}{m_{DM}}.
\label{annifactCMB}
\end{equation}

We highlight that $\langle \sigma v \rangle$ in Eq.\eqref{annifactCMB} is the thermally-averaged dark matter annihilation cross-section which can be very different from the dark matter annihilation cross-section today that enters into the  gamma-ray flux.\\

In Eq.\eqref{feeEq}, E is the energy of the electron-positron or photon, and $dN/dE^\gamma$ and $dN/dE^{e^+}$ are the photon and positron energy spectra produced per dark matter annihilation. Throughout we assume that the electrons and positrons have the same energy spectra. The energy and positron spectra produced per dark matter annihilation depends on the dark matter mass and annihilation final state. For instance, dark matter annihilations into VV which eventually decay into $e^+e^-$ produce an energy spectrum different from the direct annihilation into $e^+e^-$. In order to obtain CMB bounds for this $2\rightarrow 4$ annihilation process, we feed the energy spectrum obtained using Pythia \cite{Sjostrand:2014zea} into the code presented in \cite{Slatyer:2015jla,Slatyer:2015kla} who computed the new physics effects on the CMB.\\

Now we have reviewed the dark matter annihilation signatures in gamma-rays and for the CMB, we describe the dataset used in our analysis.

\begin{figure}[!h]
\centering
\includegraphics[width=1\columnwidth]{Vlep}
\caption{95\% C.L. upper limits on the dark matter annihilation cross-section as a function of the dark matter mass for the process ${\rm DM \, DM} \rightarrow V V$, with $V$ decaying into $e\bar{e}$, $\mu\bar{\mu}$, $\tau\bar{\tau}$. We assumed $M_{DM} \gg M_V$, with the $V$ mass being just sufficiently heavier than the decays modes.}
\label{bound1}
\end{figure}

\section{Dataset}

\subsection{Fermi-LAT}

Fermi-LAT, the NASA gamma-ray telescope, has given rise to a new area of gamma-rays studies due to the precision achieved, far better than its predecessors, and for making the data publicly available to the community via user-friendly  tools \cite{Gehrels:1999ri}. In the context of dark matter, several important steps have been taken with the publication of several  studies of sensitivity to dark matter annihilations, for instance, in dSphs \cite{Abdo:2010ex,Ackermann:2011wa,Ackermann:2012nb,Ackermann:2013yva,Ackermann:2015zua,Drlica-Wagner:2015xua,Rico:2015nya,Ahnen:2016qkx}. \\

Since dSphs are dark matter-dominated objects and are located away from the large diffuse gamma-ray emission stemming from the galactic center, they are regarded as a ``holy grail'' as far as dark matter signals are concerned \cite{Blumenthal:1984bp,Peebles:1984zz,Dekek:1986gu,Kent:1987zz,Moore:1995pb,Ferrara:1999ry,Firmani:2000qe,vandenBosch:2000rza}. Be that as it may, there are still uncertainties on dark matter content in dSphs and these are subject of intense discussions \cite{Walker:2009zp,Pasetto:2010se,DelPopolo:2011cj,Charbonnier:2011ft,Jardel:2012am,Collins:2013eek,Laporte:2013fwa,Geringer-Sameth:2014yza,Adams:2014bda,Bonnivard:2015tta,Chiappo:2016xfs}. Therefore, in order to gain statistics and perform a more robust analysis, the datasets of dSph galaxies have been combined and treated using a maximum likelihood analysis \cite{Ackermann:2011wa}. After collecting seven years of gamma-ray data with energies between $500$~MeV-$500$~GeV belonging to the event class P8R2SOURCEV6 using the up-to-date software PASS-8, no significant excess has been observed leading to the exclusion of the thermal dark matter annihilation cross-section of $3\times 10^{-26}$ for dark matter masses below $100$~GeV, for annihilations solely into $b\bar{b}$ \cite{Ackermann:2015zua}.\\

The collaboration has publicly shared individual likelihood functions which one can use to perform their own independent analysis for a given dSph\footnote{http://www-glast.stanford.edu/pub\_data/1048/}. However, we emphasize that such likelihood functions are for individual dphs and since we are interested in repeating Fermi-LAT procedure in a more robust way using a stacked analysis of the sample of 15 dSphs used by Fermi-LAT, we have to build a combined likelihood function following the receipt provided in \cite{Ackermann:2015zua}. Moreover, we build a likelihood function to marginalize the statistical uncertainties on the J-factor with the J-factor likelihood function defined as,

\begin{eqnarray}
\mathcal{L}_J (J_i| J_{obs,i}, \sigma_i) &= & \frac{1}{\ln(10)J_{obs,i}\sqrt{2\pi} \sigma_i}\nonumber\\
& \times  & \exp \left\{ -\frac{(\log_{10}(J_i)-\log_{10}(J_{obs,i}))^2}{2\sigma_i^2} \right\}\nonumber\;,
\end{eqnarray}where $J_{obs,i}$ is the measured J-factor with statistical error $\sigma_i$ of a dSph $i$, while $J_i$ is the correct J-factor value.\\

Therefore, one can compute the joint-likelihood function by multiplying each individual likelihood, having in mind that the likelihood of an individual dSph $i$ is,

\begin{equation}
   \tilde{\mathcal{L}_i}(\mu,\theta_i =
   \lbrace\alpha_i,J_i\rbrace |D_i)=\mathcal{L}_i(\mu,\theta_i|D_i)\mathcal{L}_J (J_i|J_{obs,i},\sigma_i)\;,
\end{equation}where $\mu$ accounts for particle physics input, dark matter mass and annihilation cross-section, $\theta_i$ for the set of nuisance parameters from the LAT study ($\alpha_i$) as well as the J-factors of the dSphs $J_i$, where $D_i$ is the gamma-ray data set used in the analysis. Thus, after performing a joint-likelihood function and accounting for the statistical errors on the J-factors with the likelihood function defined above we were able to do test statistics and obtain 95\% C.L. upper limits on the dark matter annihilation cross-section by finding a change in the log-likelihood of $2.71/2$ as described in \cite{Ackermann:2015zua}. We highlight were able to nicely reproduce Fermi-LAT limits as shown in \cite{Queiroz:2016zwd,Profumo:2016idl}. \\

In summary, we computed a joint-likelihood function for different energy spectra to take into account the fact we are now investigating secluded annihilations. The results are exhibit in green curves in Fig.\ref{bound1}-\ref{bound4} for two different mass regimes, $M_{DM} \gg M_V$ and $M_{DM} \sim M_V$.

\begin{figure}[!h]
\centering
\includegraphics[width=1\columnwidth]{Vlepdeg}
\caption{95\% C.L. upper limits on the dark matter annihilation cross-section as a function of the dark matter mass for the process ${\rm DM \, DM} \rightarrow V V$, with $V$ decaying into $e\bar{e}$, $\mu \bar{\mu}$, $\tau \bar{\tau}$. We assumed $M_{DM} \sim M_V$.}
\label{bound2}
\end{figure}

\subsection{H.E.S.S.}
\label{sec:hess}

The H.E.S.S. telescope has expanded our knowledge concerning gamma-ray emitters for energies greater than $200$~GeV. In comparison to Fermi-LAT, H.E.S.S. lacks in exposure but overcomes this fact with its large effective area. As far as dark matter searches are concerned the most stringent limits on the dark matter annihilation cross-section come from observations of the Galactic Center. In particular, with 112h of data, upper limits were placed on the dark matter annihilation cross-section adopting an Einasto profile \cite{Abramowski:2011hc} still far from the thermal annihilation cross-section. A more recent study, with 10 years of observation that is equivalent to  254h of live-time exposure, H.E.S.S. has significantly improved their sensitivity, excluding the thermal annihilation cross-section for dark matter masses between $1-2$~TeV, annihilating solely into $\tau\bar{\tau}$ \cite{Abdallah:2016ygi}, again using a Einasto dark matter density profile. The substantial improvement on the bound is a result of more statistics and an improved analysis of the signal and background events \cite{Lefranc:2015vza}.\\

\begin{figure}[!h]
\centering
\includegraphics[width=1\columnwidth]{Comparison}
\caption{Comparison between our results (continuous) and the results reported by H.E.S.S. Collaboration (dotted) for $\bar{b}b$ (blue) and $WW$ (magenta) channels \cite{Abdallah:2016ygi}. As one can see, we could reproduce their results in a more conservative way.}
\label{comparison}
\end{figure}

We duplicated the H.E.S.S. analysis and  were able to reproduce their results, as demonstrated in \cite{Profumo:2016idl}. We then fed the energy spectrum for secluded dark matter annihilations into the likelihood functions provided in \cite{Lefranc:2015vza} and changed the choice for the dark matter density profile to NFW, to put H.E.S.S. constraints on an equal footing with Fermi-LAT's. By performing a test-statistic as described in \cite{Lefranc:2015vza} we derive 95\% C.L. limits on the pair {\it dark matter annihilation cross section vs mass} for all channels here under consideration. The results are shown as blue curves in Fig.\ref{bound1}-\ref{bound4}  for various annihilation channels and two different mass regimes, $M_{DM} \gg M_V$ and $M_{DM} \sim M_V$.

\begin{figure}[!h]
\centering
\includegraphics[width=1\columnwidth]{Vquarks}
\caption{95\% C.L. upper limits on the dark matter annihilation cross-section as a function of the dark matter mass for the process ${\rm DM \, DM} \rightarrow V V$, with $V$ decaying into $u\bar{u}$, $b \bar{b}$, $t \bar{t}$. We assumed $M_{DM} \gg M_V$, with the $V$ mass being just sufficiently heavier than the decays modes.}
\label{bound3}
\end{figure}

\subsection{Planck}

The precision achieved by Planck has greatly impacted our knowledge about the Universe's constituents. The precise measurements of the CMB have resulted in a very precise estimate of the dark matter abundance and allowed us to make robust assessments on the impact of new physics effects on the CMB \cite{Ade:2013zuv,Planck:2013nga,Ade:2015xua}. \\

In particular, the precise measurements on the CMB temperature and polarization angular power spectra severely restrict potential new physics contributions that might change the ionization history \cite{Padmanabhan:2005es,Galli:2009zc,Galli:2011rz,Finkbeiner:2011dx,Madhavacheril:2013cna,Lopez-Honorez:2013lcm,Poulin:2015pna}. After integrating out all the cosmological factors, this affect can be described in terms of the annihilation factor $p_{ann}$ defined in Eq.\eqref{annifactCMB}. Currently, Planck places a 95\% C.L. limit on this parameter that reads,

\begin{equation}
p_{ann} < 4.1 \times 10^{-28} cm^3 s^{-1} GeV^{-1} .
\label{CMBbound}
\end{equation}

Therefore, one can use this bound to constrain the ratio $\langle\sigma v \rangle/ M_{DM}$ for a given energy spectrum. Using the code in \cite{Slatyer:2015jla,Slatyer:2015kla}, we introduced the energy spectrum resulted from the various secluded dark matter scenarios we study, and compared to Eq.\eqref{CMBbound} to place 95\% C.L. on the dark matter annihilation cross-section. The limits are shown with black curves in Fig.\ref{bound1}-\ref{bound4} under two different mass regimes, $M_{DM} \gg M_V$ and $M_{DM} \sim M_V$.

\begin{table}
\begin{center}
{\color{Green} \bf \large Fermi-LAT PASS8}\\[0.5cm]
\begin{tabular}{|c|c|}
\hline
{\color{Green} \bf dSph 4b, $M_{DM}=100$~GeV } &  {\color{Green} \bf dSph 4b, $M_{DM}=1$~TeV}\\
$M_{DM}\gg M_V \rightarrow \sigma v \simeq 2 \times 10^{-26}\, cm^3/s$ & $M_{DM}\gg M_V \rightarrow \sigma v \simeq 2 \times 10^{-25}\, cm^3/s$  \\
$M_{DM}\sim M_V \rightarrow \sigma v \simeq 2.8 \times 10^{-26}\, cm^3/s$ & $M_{DM}\sim M_V \rightarrow \sigma v \simeq 2 \times 10^{-25}\, cm^3/s$  \\
\hline
{\color{Green} \bf dSph 4e, $M_{DM}=100$~GeV } &  {\color{Green} \bf dSph 4e, $M_{DM}=1$~TeV}\\
$M_{DM}\gg M_V \rightarrow \sigma v \simeq 3 \times 10^{-25}\, cm^3/s$ & $M_{DM}\gg M_V \rightarrow \sigma v \simeq 7 \times 10^{-24}\, cm^3/s$  \\
$M_{DM}\sim M_V \rightarrow \sigma v \simeq 1.5 \times 10^{-25}\, cm^3/s$ & $M_{DM}\sim M_V \rightarrow \sigma v \simeq 3.5 \times 10^{-24}\, cm^3/s$  \\
\hline
\end{tabular}\\
\vspace*{0.5cm}
{\color{blue} \bf \large H.E.S.S.}\\[0.5cm]
\begin{tabular}{|c|c|}
\hline
{\color{blue} \bf GC 4b, $M_{DM}=1$~TeV } &  {\color{blue} \bf GC 4b, $M_{DM}=10$~TeV}\\
$M_{DM}\gg M_V \rightarrow \sigma v \simeq  4.1 \times 10^{-25}\, cm^3/s$ & $M_{DM}\gg M_V \rightarrow \sigma v \simeq  2.0 \times 10^{-25}\, cm^3/s$  \\
$M_{DM}\sim M_V \rightarrow \sigma v \simeq  2.5 \times 10^{-24}\, cm^3/s$ & $M_{DM}\sim M_V \rightarrow \sigma v \simeq 3.6 \times 10^{-25}\, cm^3/s$  \\
\hline
{\color{blue} \bf GC $4 e$, $M_{DM}=1$~TeV } &  {\color{blue} \bf GC $4e$, $M_{DM}=10$~TeV}\\
$M_{DM}\gg M_V \rightarrow \sigma v \simeq  3.2 \times 10^{-25}\, cm^3/s$ & $M_{DM}\gg M_V \rightarrow \sigma v \simeq  1.3 \times 10^{-23}\, cm^3/s$  \\
$M_{DM}\sim M_V \rightarrow \sigma v \simeq 1.4 \times 10^{-25}\, cm^3/s$ & $M_{DM}\sim M_V \rightarrow \sigma v \simeq 2.4 \times 10^{-24}\, cm^3/s$  \\
\hline
{\color{blue} \bf GC $4\mu$, $M_{DM}=1$~TeV } &  {\color{blue} \bf GC $4\mu$, $M_{DM}=10$~TeV}\\
$M_{DM}\gg M_V \rightarrow \sigma v \simeq  1.7 \times 10^{-24}\, cm^3/s$ & $M_{DM}\gg M_V \rightarrow \sigma v \simeq  4.0 \times 10^{-23}\, cm^3/s$  \\
$M_{DM}\sim M_V \rightarrow \sigma v \simeq 2.5 \times 10^{-25}\, cm^3/s$ & $M_{DM}\sim M_V \rightarrow \sigma v \simeq 3.0 \times 10^{-24}\, cm^3/s$  \\
\hline
{\color{blue} \bf GC $4\tau$, $M_{DM}=1$~TeV } &  {\color{blue} \bf GC $4\tau$, $M_{DM}=10$~TeV}\\
$M_{DM}\gg M_V \rightarrow \sigma v \simeq  7.9 \times 10^{-26}\, cm^3/s$ & $M_{DM}\gg M_V \rightarrow \sigma v \simeq  7.4 \times 10^{-25}\, cm^3/s$  \\
$M_{DM}\sim M_V \rightarrow \sigma v \simeq 7.6 \times 10^{-26}\, cm^3/s$ & $M_{DM}\sim M_V \rightarrow \sigma v \simeq 4.4 \times 10^{-25}\, cm^3/s$  \\
\hline
\end{tabular}\\
\vspace*{0.5cm}
{\color{black} \bf \large Planck}\\[0.5cm]
\begin{tabular}{|c|c|}
\hline
{\color{black} \bf CMB 4b, $M_{DM}=100$~GeV } &  {\color{black} \bf CMB 4b, $M_{DM}=1$~TeV}\\
$M_{DM}\gg M_V \rightarrow \langle \sigma v\rangle \simeq 2.5  \times 10^{-25}\, cm^3/s$ & $M_{DM}\gg M_V \rightarrow \langle \sigma v \rangle\simeq 3 \times 10^{-24}\, cm^3/s$  \\
$M_{DM}\sim M_V \rightarrow \langle \sigma v \rangle \simeq 2.5 \times 10^{-25}\, cm^3/s$ & $M_{DM}\sim M_V \rightarrow \langle \sigma v\rangle \simeq 2.5 \times 10^{-24}\, cm^3/s$  \\
\hline
{\color{black} \bf CMB 4e, $M_{DM}=100$~GeV } &  {\color{black} \bf CMB 4e, $M_{DM}=1$~TeV}\\
$M_{DM}\gg M_V \rightarrow \langle\sigma v\rangle \simeq  10^{-25}\, cm^3/s$ & $M_{DM}\gg M_V \rightarrow \langle\sigma v\rangle \simeq  10^{-24}\, cm^3/s$  \\
$M_{DM}\sim M_V \rightarrow \langle\sigma v\rangle \simeq 1.5 \times 10^{-25}\, cm^3/s$ & $M_{DM}\sim M_V \rightarrow \langle\sigma v\rangle \simeq 1.5 \times 10^{-24}\, cm^3/s$  \\
\hline
\end{tabular}
\end{center}
\caption{95\% C.L. limits on the dark matter annihilation cross-section for several secluded dark matter scenarios. For easy comparison, we show the bounds for $M_{DM} \gg M_V$ and $M_{DM} \sim M_V$. All annihilations were individually analyzed, i.e. we assumed that the dark matter particle annihilates solely into each final state. Notice that Fermi-LAT and H.E.S.S. are sensitive to the dark matter annihilation cross-section today, whereas CMB is sensitive to the thermally averaged cross-section.}
\label{table2}
\end{table}

\section{Results}
\label{sec:results}

In Fig.\ref{bound1} we exhibit the 95\% C.L. limits on the dark matter annihilation cross-section for the case that $M_{DM} \gg M_V$, with the mediator being just sufficiently heavier than its decay channels. We remind the Reader that the CMB bounds are placed on the thermally-averaged dark matter annihilation cross-section, whereas Fermi-LAT and H.E.S.S. bounds are on the dark matter annihilation cross-section today. In the figures, we keep the average dark matter annihilation on the y-axis, but the reader should interpret the plots with caution.\\

The bounds from CMB are shown in black lines for the $4e$ (solid), $4 \mu$(dotted) and $4\tau$ (dashed) channels. A similar pattern is used for Fermi-LAT (green) and H.E.S.S. (blue) bounds.\\

As expected, the  CMB is a powerful probe of dark matter annihilations into electron and muons. For annihilations into VV, with each V decaying into $\bar{\tau}\tau$ Fermi-LAT takes the lead since $\tau$ decays hadronically and efficiently produces gamma-rays. For dark matter masses above $400$~GeV, the complementarity among these three telescopes is very encouraging. For annihilations into $4e$ and $4\mu$, the CMB is still more restrictive, but the $4\tau$ Fermi-LAT bound is the most stringent for $M_{DM} < 800$~GeV, with H.E.S.S. taking the lead for larger masses.\\

Similarly to what has been typically assumed in the literature, we adopted $M_{DM} \gg M_V$. We now assume that the dark matter and the mediator are nearly
mass-degenerate and show the new bounds on the annihilation cross-section in Fig.\ref{bound2}. Our choice for this assumption of a mass-degenerate regime is motivated by its presence in several dark sector models. On a theoretical note, if the dark matter particle has both vector and axial vector couplings to the mediator then we anticipate that the dark matter particle cannot be much heavier than the mediator, so as not to spoil perturbativity unitarity \cite{Shu:2007wg,Kahlhoefer:2015bea}. Thus  it is reasonable to assume that the dark matter and the mediator have comparable masses. \\

H.E.S.S. sensitivity to annihilations into $4\tau$ is not much affected, but those into $4e$ and $4\mu$ are visibly changed. For instance, with $M_{DM}=1$~TeV, for $e\bar{e}$ final state, H.E.S.S. could exclude $\sigma v \simeq 3.2 \times 10^{-25} cm^3/s$ for $M_{DM} \gg M_{V}$, but with  $M_{DM} \sim M_{V}$ now excludes $\sigma v \simeq 1.4 \times 10^{-25} cm^3/s$. Moreover, still keeping $M_{DM}=1$~TeV, H.E.S.S. upper bound on dark matter annihilation cross-sections, for $\mu\bar{\mu}$ final state, goes from  $\sigma v \simeq 1.7 \times 10^{-24} cm^3/s$ for $M_{DM} \gg M_V$, to $\sigma v \simeq 2.5 \times 10^{-25} cm^3/s$ for $M_{DM} \sim M_{V}$, clearly showing that the mediator mass is important in the derivation of robust limits on the dark matter annihilation cross-section. A similar reasoning can be applied to the other experiments. On Table \ref{table2} we show several benchmark models for comparison.\\

\begin{figure}[!h]
\centering
\includegraphics[width=1\columnwidth]{Vquarksdeg}
\caption{95\% C.L. upper limits on the dark matter annihilation cross as a function of the dark matter mass for the process ${\rm DM DM} \rightarrow V V$, with $V$ decaying into $u\bar{u}$, $b \bar{b}$, $t \bar{t}$. We assumed $M_{DM} \sim M_V$.}
\label{bound4}
\end{figure}

In Fig.\ref{bound3} we exhibit the 95\% C.L. limits on the dark matter annihilation cross-section into hadrons for the case that $M_{DM} \gg M_V$, with the mediator being just sufficiently heavier than its decay final states. The CMB bounds are shown in black lines for the annihilations into $4 t$ (solid), $4 b$ (dotted) and $4 u$ (dashed) channels. A similar pattern is used for Fermi-LAT (green) and H.E.S.S. (blue) bounds.\\

For $M_{DM}=1$~TeV and annihilations into $4b$ with $M_{DM} \gg M_V$, Fermi-LAT excludes $\sigma v \simeq 2 \times 10^{-25} cm^3/s$, Planck rules out $\langle\sigma v \rangle \simeq 3 \times 10^{-24} cm^3/s$, and lastly H.E.S.S. excludes $\sigma v \simeq 4.1 \times 10^{-25} cm^3/s$. If we ramp up the mediator mass to $M_V \sim M_{DM}$, the H.E.S.S. sensitivity significantly changes, whereas Planck and Fermi-LAT sensitivities are mildly changed. In particular, the H.E.S.S. upper bound on the dark matter annihilation cross-section worsens now ruling out $\sigma v \simeq 2.5 \times 10^{-24} cm^3/s$. A multitude of other setups are explicitly presented in Table \ref{table2} to facilitate the comparisons and easily assess the impact of the mediator mass in the derivation of the bounds.\\

In summary, one can see the mediator mass is more relevant for  heavy dark matter, with masses much larger than $100$~GeV. In some cases, the difference in the upper limit on the dark matter annihilation cross-section reaches a factor of seven, as in the $M_{DM}=1$~TeV case for annihilations into $4\mu$, for the H.E.S.S. telescope. To illustrate even further the importance of the mediator mass we paired the results for $M_{DM} \gg M_V$ and $M_{DM} \sim M_V$ for the $4b$ and $4\tau$ channels in Fig.\ref{boundcomparison}. As noted previously, the upper limits change significantly specially for H.E.S.S. observation of the GC.\\

\begin{figure}[!h]
\centering
\includegraphics[width=0.49\columnwidth]{bbchannels}
\includegraphics[width=0.49\columnwidth]{tauchannels}
\caption{95\% C.L. upper limits on the dark matter annihilation cross section for $M_{DM} \gg M_V$ and $M_{DM} \sim M_V$ to easy comparison based on the observation from the CMB (black), GC (blue) and dSph (green). {\it Left-panel:} annihilation into $4b$; {\it Right-panel:} annihilation into $4\tau$. We also overlay the canonical dark matter annihilation into $2b$ and $2\tau$ respectively. }
\label{boundcomparison}
\end{figure}

To summarize, our work derives  new and updated limits on the dark matter annihilation cross-section for the  secluded dark matter sector, and shows that these bounds rely on the mass of the mediator.

\section*{Discussion}

CMB and gamma-ray constraints do not probe the same annihilation rates, as they probe annihilation rates at different times in the history of the universe. The annihilation cross-section today drives gamma-ray signals, whereas the thermal averaged annihilation cross-section at CMB decoupling drives CMB constraints. Some dark matter models feature velocity-dependent annihilation rates, and in these models the assessment of which experiment is the most restrictive is model-dependent \cite{Robertson:2009bh,Campbell:2010xc,Hisano:2011dc,Arina:2014yna,Zhao:2016xie,Goncalves:2016iyg,Gonzalez-Morales:2017jkx}. Here, we have highlighted  that  bounds on the dark matter annihilation cross-section do not depend on  specific particle physics models and in this respect they can be regarded as model-independent.

\section{TeV Gamma-ray Excess Observed by H.E.S.S.}

Gamma ray observations performed by the ground-based H.E.S.S. telescope within the $15$~pc from the Galactic Center revealed a very high energy point-like source known as J1745-290 which features a significant deviation from a pure power-law (PL) emission in the few TeV energy region \cite{Aharonian:2009zk,Abramowski:2016mir}.\\

We followed the procedure described in \cite{Abramowski:2016mir} and assumed that the annular region within $0.15^o$ and $0.45^o$ that has a solid angle of $1.4 \times 10^{-4}$~sr is well-fitted by the PL spectrum $dN/dE= A_b (E/1{\rm TeV})^{\Gamma_b}$, with $A_b= (1.92 \pm 0.08_{stat} \pm 0.28_{sys})\times 10^{-12} {\rm  cm^{-2} s^{-1} TeV^{-1} }$ and $\Gamma_b = 2.32 \pm 0.05_{stat} \pm 0.11_{syst}$. The result is shown with a dotted coral line in Fig. \ref{figHESSexcess}.\\

Moreover, we generated the energy spectrum of secluded dark matter annihilations using Pythia 8 \cite{Sjostrand:2014zea} and derived the gamma-ray fluxes for dark matter annihilations into $4\tau$ e $4b$ for $M_{DM} \sim M_V$ (left-panel) and $M_{DM} \gg M_V$ (right-panel), as displayed in in Fig.\ref{figHESSexcess} with green and purple curves, respectively. \\

After summing the background contribution to the power-law emission above, we obtain the black curve which is the gamma-ray flux produced by the dark matter plus background. In the left panel, where $M_{DM} \sim M_V$, the minimum $\chi^2$ procedure yields $\chi^2/d.o.f=2.95$. It favors $\sigma v =  3.87\times 10^{-26} cm^3 s^{-1}$ and $M_{DM}=20$~TeV with an annihilation branching ratio of 60\% into $4b$ and 40\% into $4\tau$. We also investigated the possibility to  improve the $\chi^2$ for different branching ratios but the aforementioned scenario provided the best-fit.\\

\begin{figure}[!h]
\centering
\includegraphics[width=0.49\columnwidth]{constHESSGCdeg}
\includegraphics[width=0.49\columnwidth]{constHESSGC}
\caption{H.E.S.S. TeV gamma-ray observation within $15$~pc of the Galactic Center. In blue are the data points. The dotted coral line is the background emission assumed to be a simple PL. In black in the total gamma-ray emission obtained by summing the dark matter component with the background. In green (purple), the gamma-ray emission produced by the dark matter particle annihilating into $4b$ ($4\tau$). {\it Left-panel}: 20 TeV dark matter particle, with $\sigma v = 3.87\times 10^{-26} cm^3 s^{-1}$, annihilating with 60\% branching ratio into $4b$ and 40\% into $4\tau$ for $M_{DM} \sim M_V$. {\it Right-panel}:  10 TeV DM particle, with $\sigma v = 1.64\times 10^{-26} cm^3 s^{-1}$, annihilating 50\% into $4b$ and 50\% into $4\tau$  for $M_{DM} \gg M_V$. One can quantitatively see the impact of the mediator mass.}
\label{figHESSexcess}
\end{figure}

In the right panel, where $M_{DM} \gg M_V$, the minimum $\chi^2$ procedure yields $\chi^2/d.o.f=9.73$. It favors $\sigma v =  1.64\times 10^{-26} cm^3 s^{-1}$ and $M_{DM}=10$~TeV with the branching ratio of 50\% into $4b$ and 50\% into $4\tau$.\\

It is important to highlight that the dark matter annihilation cross-section serves as an overall rescaling of the energy spectrum, whereas the dark matter mass changes the energy spectrum behavior at lower and larger energies. Furthermore, dark matter annihilations in the mass degenerate case lead to a harder gamma-ray spectrum at lower energies proving a better fit to the data where the error is relatively smaller. The trade-off between dark matter mass, annihilation cross-section, annihilation final states led to the best-fit parameters found above.\\

In summary, the TeV gamma-ray excess observed the H.E.S.S. telescope is also well-fitted by secluded dark matter annihilations, and mediator mass has an important impact on what dark matter mass provides a best-fit to the data, ratifying our conclusions. \\

A similar study but in the context of $2\rightarrow 2$ dark matter annihilations was carried out in \cite{Belikov:2012ty,Belikov:2013laa}. It is important to emphasize though that one could also nicely explain the H.E.S.S. observation by assuming that the background emission departs from the pure power-law spectrum, and is actually described by a power-law function with an exponential cut-off \cite{Belikov:2016fwv}.

\section{Conclusions}
\label{sec:con}

Secluded dark sectors are often investigated in a model-dependent fashion. Motivated by their relevance, we used seven years of Fermi-LAT observations of dwarf spheroidal galaxies, 10 years of H.E.S.S. data from the  Galactic center, and the most recent Planck measurements on the Cosmic Microwave Background to constrain secluded dark sectors. We showed here that these datasets are highly complementary to each other, especially when the dark matter mass is above $\sim 400$~GeV. We derived 95\% C.L. limits on the dark matter annihilation cross-section for several scenarios. We sifted annihilations into $4e,4\mu,4\tau, 4u, 4b, 4t$ and also assessed the impact of the mediator mass on our bounds. As far as indirect searches for dark matter are concerned, these mediators are often assumed to be very light and just sufficiently heavier than the decay modes' particle masses. We showed that their masses can lead to sizeable changes on the overall upper limits on the dark matter annihilation
cross-section. Our bounds supersede previous constraints using Fermi-LAT data, and they constitute the first limits on secluded dark sectors using the H.E.S.S. telescope. We also showed that secluded dark matter can also fit the TeV gamma-ray observation observed by H.E.S.S., with the mediator mass driving the location of the best-fit points. \\

In conclusion, our results clearly show that any robust assessment of secluded dark sectors in the context of indirect detection relies not only the dark matter annihilation cross-section and annihilation final states, but also on the mediator mass.

\section*{Acknowledgments}

We are grateful to the Fermi-LAT team for the publicly available likelihood functions used in this study. The authors thank Marco Cirelli and Tathagata Gosh for correspondence. We are also grateful to Giorgio Arcadi, Carlos Yaguna, Stefan Vogl, Yann Mambrini, Miguel Campos, Aion Viana, and Torsten Bringmann for discussions. We thank Filippo Sala for reminding us of the updated limits from HESS collaboration that were missing in a earlier version. FSQ acknowledges support from MEC and ICTP-SAIFR FAPESP grant 2016/01343-7. CS is supported by CAPES/PDSE Process 88881.134759/2016-01.

\bibliographystyle{JHEPfixed}


Tabling as a Library with Delimited Control

Abstract: Tabling is probably the most widely studied extension of Prolog. But despite its importance and practicality, tabling is not implemented by most Prolog systems. Existing approaches require substantial changes to the Prolog engine, which is an investment out of reach of most systems. To enable more widespread adoption, we present a new implementation of tabling in under 600 lines of Prolog code. Our lightweight approach relies on delimited control and provides reasonable performance.

\subsection{Delimited Continuations}
Delimited control~\cite{felleisen,danvy} is the key ingredient of our lightweight tabling approach. This technique originates in functional programming and was recently introduced in Prolog by Schrijvers et al.~\shortcite{iclp2013,reset} in the form
of two built-ins:
\verb!reset/3! and \verb!shift/1! for delimiting and capturing the
continuation respectively.
\begin{itemize}
	\item \texttt{reset(Goal,Cont,Term1)} executes \texttt{Goal}. If \texttt{Goal} calls \texttt{shift(Term2)}, its further execution is suspended and unified with continuation \texttt{Cont}. A continuation is an unspecified Prolog term, which can be resumed using \verb!call/1!. It can be called, saved, copied and compared like any other term, but it is opaque: from its representation we cannot determine anything about the actual goals it represents.

	\item \texttt{shift(Term2)} unifies the remainder of \texttt{Goal}
	up to the nearest call to \texttt{reset/3} (i.e., the delimited continuation) with \texttt{Cont}, and its return value \texttt{Term2} with \texttt{Term1}. Finally, it returns control to just after the \texttt{reset/3} goal.

\end{itemize}

We start with an example that does not call the continuation.
\begin{figure}[ht]
\begin{minipage}{0.30\linewidth}
\begin{Verbatim}[fontsize=\footnotesize]
p :-
  reset(q,Cont,Term1),
  writeln(Term1),
  writeln(Cont),
  writeln(end).
\end{Verbatim}
\end{minipage}
\quad
\begin{minipage}{0.30\linewidth}
\begin{Verbatim}[fontsize=\footnotesize]
q :-
  writeln('before shift'),
  shift('return value'),
  writeln('after shift').

\end{Verbatim}
\end{minipage}
\quad
\begin{minipage}{0.30\linewidth}
\begin{Verbatim}[fontsize=\footnotesize]
?- p.
before shift
return value
[$cont$(785488,[])]
end
\end{Verbatim}
\end{minipage}
\end{figure}

This example shows that \verb!shift/1! instantiates the last two arguments
of \verb!reset/3!. \texttt{Cont} represents the \texttt{writeln('after shift')} goal in the
context of the activation of the clause for \texttt{q/0}. But since the continuation is not called, this goal has no effect. \texttt{Term1} is unified with the term \texttt{'return value'}. The execution continues after the \texttt{reset/3}.

The following example shows what happens if the continuation is called:

\begin{figure}[ht]
\begin{minipage}{0.30\linewidth}
\begin{Verbatim}[fontsize=\footnotesize]
p :-
  reset(q,Cont,Term1),
  writeln(Term1),
  call(Cont),
  writeln(end).
\end{Verbatim}
\end{minipage}
\quad
\begin{minipage}{0.30\linewidth}
\begin{Verbatim}[fontsize=\footnotesize]
q :-
  writeln('before shift'),
  shift('return value'),
  writeln('after shift').

\end{Verbatim}
\end{minipage}
\quad
\begin{minipage}{0.30\linewidth}
\begin{Verbatim}[fontsize=\footnotesize]
?- p.
before shift
return value
after shift
end
\end{Verbatim}
\end{minipage}
\end{figure}

\subsection{Implementation Effort}

Table~\ref{tab:codeSize} summarizes the implementation effort in lines of
Prolog (LoC).  The control flow shown in this paper comprises 60 LoC, or
less than 11\% of the overall effort.  The majority goes to the two kinds of
data structures, the tries (40\%) and the worklists (45\%). Adding 25 lines of
glue code, this amounts to an implementation for 577 Prolog LoC.

\begin{table}[b]
\begin{center}
{ \footnotesize
\ra{1.3}
\begin{tabular}{lr@{\qquad}lr}
\toprule
\textbf{Category} & \textbf{LoC} & \textbf{Category} & \textbf{LoC} \\
\midrule
Control flow          & 60  & Completion Worklists & 259 \\
Call and Answer Tries & 233 & Miscellaneous        & 25 \\
\midrule
Total                                  & 577 \\
\bottomrule
\end{tabular}
}
\caption{Code size in lines of code.\label{tab:codeSize}}
\end{center}
\end{table}

\subsection{Performance}

While raw efficiency is not the main objective of our lightweight
implementation, it is nevertheless important to achieve a reasonable
performance compared to the existing state-of-the-art tabling systems.
In order to evaluate this, we compare our implementation in hProlog 3.2.38
against XSB 3.4.0 \cite{swift2012}, B-Prolog 8.1 \cite{bprolog}, Yap 6.3.4 \cite{yap} and Ciao 1.15-2731-g3749edd \cite{ciao} on a
number of benchmarks.\footnote{The description and code of the benchmarks can be found at \url{http://users.ugent.be/~bdsouter/tabling/}.}  Table~\ref{tab:grandTableTimings} summarizes the results
(in ms) obtained on a Dell PowerEdge R410 server (2.4 GHz, 32 GB RAM) running Debian 7.6. In parentheses, we have indicated the maximum resident set size (RSS) in megabytes and the proportion of hProlog to XSB.

\paragraph{Discussion}

The XSB system is the reference system for tabling; it has invested most time
and resources in the development of its tabling infrastructure. We see that it
is 8 to 38 times faster than our implementation, but
45 to 78 times faster for two outliers (path right last: binary tree 18 and 10k pingpong). It has a maximum RSS that is up to 7 times as large, and 14 times for path double first 500.
In general, standard trie-based structures overload the memory because representation sharing is poor. This has been addressed by Raimundo and Rocha~\shortcite{raimundo11}.

Since XSB does not support big integers, it was not meaningful to run
the Fibonacci benchmark, recorded as O/F (for overflow).
This is a case in point for wider tabling support in other
systems: often we need both tabling and other non-standard
features.

B-Prolog is only half as fast as XSB on many benchmarks, but is architecturally different: BProlog implements linear tabling and uses hash tables instead of tries.
Moreover, in several
cases B-Prolog is notably slower than XSB (i.e., n-reverse) and even much
slower than our own implementation (recognize, shuttle, ping pong). Yet, unlike
XSB, B-Prolog does support big integers and is substantially faster than
our approach for the fib benchmark.
All in all the results are mixed and point out several weaknesses in the B-Prolog
implementation compared to our all Prolog implementation.

\newcommand{\millis}[1]{#1}

\newcommand{\megabyte}[1]{ (#1)}

\begin{table}[t]
\begin{center}
\begin{minipage}{\linewidth}
{ \footnotesize
\ra{1.3}
\begin{tabular}{l@{}rr@{}r@{}r@{}r@{}r}
\toprule
\textbf{Benchmark} &\textbf{Size}  &  \multicolumn{1}{l}{\textbf{hProlog}} & $\frac{\mathbf{hProlog}}{\mathbf{XSB}}$  & $\frac{\mathbf{hProlog}}{\mathbf{B-Prolog}}$ & $\frac{\mathbf{hProlog}}{\mathbf{Yap}}$  & $\frac{\mathbf{hProlog}}{\mathbf{Ciao}}$\\
\midrule
\multicolumn{1}{l}{\textbf{fib$^{a}$}}
  & 500    & \millis{24}  \megabyte{13} & O/F (---) & $\infty$ & $\infty$  & --- \\
  & 750    & \millis{33}  \megabyte{13} & O/F (---) & 17      & 41    & --- \\
  & 1,000  & \millis{46}  \megabyte{13} & O/F (---) & 46      & 19    & --- \\
  & 10,000 & \millis{982} \megabyte{66} & O/F (---) & 3       & 44    & --- \\
\multicolumn{1}{l}{\textbf{recognize$^{a}$}} &
  20,000        & \millis{205} \megabyte{73}   & 26 (1) &  0.003  & 11 & 4 \\
& 50,000        & \millis{503} \megabyte{221}   & 30 (2) &  0.001  & 14 & 4 \\
\multicolumn{1}{l}{\textbf{n-reverse$^{a}$}} &
     500     & \millis{767}  \megabyte{138}  & 38  (5)   & 11     & 15  & 45 \\
 & 1,000    & \millis{2,800} \megabyte{537} & 31  (6)    & 6      & 8   & 34 \\
\multicolumn{1}{l}{\textbf{shuttle$^{b}$}} &
   2,000  & \millis{44}    \megabyte{12} & $\infty$ (2) & 0.1  & $\infty$ & 9 \\
 & 5,000  & \millis{138}   \megabyte{14} & 23       (2) & 0.08 & $\infty$ & 12 \\
 & 20,000 & \millis{582}   \megabyte{29} & 24       (4) & 0.02 & $\infty$ & 10 \\
 & 50,000 & \millis{1,586} \megabyte{72} & 29       (6) & 0.01 & $\infty$ & 12 \\
\multicolumn{1}{l}{\textbf{ping pong}} &
     10,000 & \millis{271} \megabyte{16} & 45 (2) & 0.07 & $\infty$ & 14 \\
   & 20,000 & \millis{490} \megabyte{28} & 35 (4) & 0.03 & $\infty$ & 8 \\
\multicolumn{1}{p{2.5cm}}{\textbf{path double first loop}} &
  50  & \millis{653}   \megabyte{14} & 19 (2) & 13 & $\infty$ & 7 \\
& 100 & \millis{4,638} \megabyte{29} & 17 (4) & 10 & $\infty$ & 6 \\
\multicolumn{1}{l}{\textbf{path double first}} &
     50  & \millis{162}     \megabyte{12}  & 27 (2) & 15 & $\infty$ & 14 \\
   & 100 & \millis{989}     \megabyte{16}  & 20 (3) & 12 & $\infty$ & 10 \\
   & 200 & \millis{6,785}   \megabyte{53}  & 18 (7) & 16 & $\infty$ & 10 \\
   & 500 & \millis{110,463} \megabyte{267} & 25 (14) & 19 & $\infty$ & 14 \\
\multicolumn{1}{p{2.5cm}}{\textbf{path right last: pyramid 500}} &
  500 & \millis{1,914}  \megabyte{104} & 35   (7)   & 29   & $\infty$ & 27 \\
\multicolumn{1}{p{2.5cm}}{\textbf{path right last: binary tree 18}} &
18 & \millis{108,662} \megabyte{4,120} & 78 (5) & 50 & 3,461 & 42 \\
\multicolumn{1}{l}{\textbf{test large joins 2$^{c}$}} &
  12 & \millis{3,001} \megabyte{237} & 10 (5)   & 4    & $\infty$ & 12 \\
\multicolumn{1}{l}{\textbf{joins mondial}} &
  & \millis{6,444} \megabyte{399} & 8 (2) & 7 & 224 & 6 \\
\bottomrule\\
	\end{tabular}
	}

	\caption{Results of the performance benchmarks.\label{tab:grandTableTimings}}
	\smallskip
	{ \footnotesize
  Source:
  \textit{a} \cite{fan1992} \quad
  \textit{b} \cite{cat1998} \quad
  \textit{c} Yap benchmark suite
  }
	\end{minipage}
	\end{center}
	\end{table}

The Yap tabling implementation, which is based on that of XSB, is clearly the
fastest: the underlying engine is much faster~\cite{yaptab2000}. It outperforms our approach on all benchmarks, and the other
systems on most. Many benchmarks take less than \unit{1}{\milli\second}, rounded down to \unit{0}{\milli\second}, hence the factor $\infty$ in the table.

The performance of Ciao lies between that of XSB and B-Prolog. Performance of our implementation is within a factor 4 to 14 of Ciao, with reverse and path right last as outliers. Running the Fibonacci benchmarks is currently not possible, as tabling and bignums currently do not operate together\footnote{Personal email communication with Manuel Carro.}.

\paragraph{Summary}
We consider the performance results of our implementation very reasonable,
especially if we take into account the stark contrast between our lightweight
pure Prolog implementation and the complex integration in other systems.
As part of future work, we think that advances in three areas may
positively affect performance.
Firstly, continuations are copied with \texttt{copy\_term/2}. A special-purpose \texttt{copy\_continuation/2} could do better by exploiting the known structure of these terms. Other applications using delimited control could
benefit from this optimization as well.
Secondly, we don't statically identify strongly connected components in the scheduling component.
Doing so would allow the specialisation of completion.
Finally, in contrast with state-of-the art implementations, our tries do not use
substitution factoring.

\section{Implementation of the Tabling Library}

This section explains how we implement tabling as a library.

\subsection{The \texttt{table/2} Predicate} \label{subsec:table2predicate}

\begin{figure}
\begin{center}
\begin{minipage}{0.6\textwidth}
\begin{MyFloatingVerbatim}
table(Wrapper,Worker) :-
  get_table_for_variant(Wrapper,Table),
  table_get_status(Table,Status)
  ( Status = complete ->
    get_answer_from_table(Table,Wrapper)
  ;
    ( exists_scheduling_component ->
      run_leader(Wrapper,Worker,Table),
      get_answer_from_table(Table,Wrapper)
    ;
      run_follower(Status,Wrapper,Worker,Table)
    )
  ).
\end{MyFloatingVerbatim}
\end{minipage}
\end{center}
\caption{The \texttt{table/2} predicate.\label{fig:tablePredicate}}
\end{figure}

Thanks to the shallow program transformation, the \texttt{table/2} predicate
intercepts every call to a tabled predicate. Figure~\ref{fig:tablePredicate}
shows that \texttt{table/2} retrieves the \texttt{Table} data structure for the
given \texttt{Wrapper} call pattern. There is one table for every
distinct call pattern encountered so far; if the current call pattern has not
been encountered before, \texttt{get\_table\_for\_variant/2} allocates a fresh
data structure for it.

Then \texttt{table/2} switches on the \texttt{Table}'s status. If the status is
\texttt{complete}, it means that all answers for the \texttt{Wrapper} call
pattern are already available in the table. The call is then answered by
consuming the answers with the
\texttt{get\_answer\_from\_table/2} predicate.

Otherwise, we either start collecting answers (\texttt{run\_leader/3}), or we are already in the process
of collecting answers and simply proceed (\texttt{run\_follower/4}). The call that initiates answer
collection is called the \emph{leader}. A leader is a call to a tabled
predicate that has only non-tabled ancestors in the dynamic call graph. Other
calls to tabled predicates during answer collection are called
\emph{followers}. Every follower has a leader as its ancestor.  The leader and
its followers make up a \emph{scheduling component}. Multiple scheduling components can occur during
program execution.

\begin{example}
Consider the top-level call \texttt{?- p(X,Y).} for our running example. Then
\texttt{p(X,Y)} clearly is the leader of a new scheduling component. The recursive call \texttt{p(X,Z)} in the
first clause constitutes a follower in its scheduling component.
\end{example}

\paragraph{The Leader} \label{subsubsec:leader}

The leader, defined in Figure~\ref{fig:handleLeader}, takes responsibility for
computing all the answers of its scheduling component. To quickly identify whether
there currently is a leader, we use a global non-backtrackable variable.
The predicates
\texttt{exists\_scheduling\_component/0} and
\texttt{create\_scheduling\_component/0} check and set this variable. The predicate
\texttt{unset\_scheduling\_component/0} unsets it.

The job of the leader consists of two tasks: 1) it starts computing the answers of
the scheduling component with \texttt{activate/3}, and 2) it computes the least fixpoint for the
whole scheduling component with \texttt{completion/0}.

\begin{figure}
\begin{minipage}{0.43\textwidth}
\begin{MyFloatingVerbatim}
run_leader(Wrapper,Worker,Table) :-
  create_scheduling_component,
  activate(Wrapper,Worker,Table),
  completion,
  unset_scheduling_component.

\end{MyFloatingVerbatim}
\caption{Handling the leader call.\label{fig:handleLeader}}
\end{minipage}
\enskip
\begin{minipage}{0.54\textwidth}
\begin{MyFloatingVerbatim}
run_follower(fresh,Wrapper,Worker,Table) :-
  activate(Wrapper,Worker,Table),
  shift(call_info(Wrapper,Table)).

run_follower(active,Wrapper,Worker,Table) :-
  shift(call_info(Wrapper,Table)).
\end{MyFloatingVerbatim}
\caption{Handling a follower call.\label{fig:handleNonLeader}}
\end{minipage}
\end{figure}

\paragraph{Followers} \label{subsubsec:nonleader}

Followers, defined in Figure~\ref{fig:handleNonLeader}, have fewer
responsibilities than the leader.  If the table of the follower is \texttt{fresh}, i.e. it is
the first time the call pattern occurs, then the follower \texttt{activate}s
the answer computation. Subsequently, it yields control with \texttt{shift/1};
this is explained in more detail in the next subsection. If the table is already \texttt{active}ly
collecting answers, the follower immediately yields control.

\subsection{Activation and Delimited Answer Computation}
\label{subsec:activation}

When a call pattern is encountered for the first time, the computation of its
answers is activated with the predicate \texttt{activate/3}. This predicate,
defined in Figure~\ref{fig:activation}, alters the table status from
\texttt{fresh}ly allocated to \texttt{active} and puts the \texttt{Worker} to
work with the auxiliary \texttt{delim/3} predicate. Note that a failure driven loop
is used to backtrack over all the alternatives of \texttt{Worker}.

\begin{figure}[h]
\begin{center}
\begin{minipage}{0.65\textwidth}
\begin{MyFloatingVerbatim}
activate(Wrapper,Worker,Table) :-
  table_set_status(Table,active),
  (
    delim(Wrapper,Worker,Table),
    fail
  ;
    true
  ).
\end{MyFloatingVerbatim}
\end{minipage}
\end{center}
\caption{Activation.\label{fig:activation}}
\end{figure}

\begin{figure}
\begin{center}
\begin{minipage}{0.9\textwidth}
\begin{MyFloatingVerbatim}
delim(Wrapper,Worker,Table) :-
   reset(Worker,Continuation,SourceCall),
   ( Continuation == 0 ->
     store_answer(Table,Wrapper)
   ;
     SourceCall = call_info(_,SourceTable),
     TargetCall = call_info(Wrapper,Table),
     Dependency = dependency(SourceCall,Continuation,TargetCall),
     store_dependency(SourceTable,Dependency)
   ).
\end{MyFloatingVerbatim}
\end{minipage}
\end{center}
\caption{Delimited execution.\label{fig:delimCode}}
\end{figure}

The body of a tabled predicate $p/n$ is actually executed by predicate
\texttt{delim/3}, defined in Figure~\ref{fig:delimCode}. This predicate runs
$p/n$'s \texttt{Worker} in the context of a \texttt{reset/3}. If
the \texttt{Worker} succeeds normally, the answer is added to the table with
\texttt{store\_answer/2}.

However, if the \texttt{Worker} calls a tabled predicate $q/m$ ---
with either the same or a different call pattern as $p/n$ --- then
\texttt{Worker} does not terminate normally. The reason is that the $q/m$ call
is a follower, and \texttt{run\_follower/4} always ends in a \texttt{shift/1}
without producing an answer. Instead the \texttt{Worker}
suspends, capturing the remainder in \texttt{Continuation}.

\begin{example}
Consider the following clause from our running example:
\begin{MyNonFloatingVerbatim}
p_aux(X,Y) :- p(X,Z), e(Z,Y).
\end{MyNonFloatingVerbatim}
The worker \texttt{p\_aux(X,Y)} for the call \texttt{p(X,Y)} immediately suspends at the recursive call
\texttt{p(X,Z)} with \texttt{Continuation = e(Z,Y)}.
\end{example}

Through this suspension, we bypass the regular depth-first execution mechanism of Prolog and avoid
its potential non-termination. We replace the depth-first search by the least
fixpoint computation of the \texttt{completion} phase. For this purpose, we
record the suspended computation in the form of a \texttt{dependency/3}
structure. This structure expresses that given an answer for the $q/m$ call, one
may obtain answers for the $p/n$ call by resuming the suspended continuation.
We name $q/m$ the \emph{source call} and $p/n$ the
\emph{target call}. For the source call, it is sufficient to hold on to the
\texttt{SourceTable} to be able to retrieve an answer later. For the target
call, we need the \texttt{Wrapper} in addition to the table, as the
\texttt{Wrapper} contains the partial answer that the continuation will
instantiate. This explains the form of the \texttt{dependency/3} structure,
which is stored in the table of the source call to be
triggered whenever a new answer is added.

\begin{example}
The dependency for our example above expresses that, given an answer for \texttt{p(X,Z)},
we may obtain answers for \texttt{p(X,Y)} by executing \texttt{e(Z,Y)}. For instance,
if we get the answer \texttt{X = a, Z = b} for \texttt{p(X,Z)}, and we have the fact \texttt{e(b,c)}
then we obtain the answer \texttt{X = a, Y = c} for \texttt{p(X,Y)}.
\end{example}

\begin{example}\label{ex:4}
Assume that \texttt{e/2} is defined by the facts \texttt{e(a,b)} and
\texttt{e(b,c)}.  Then the query \texttt{?- p(X,Y)} yields not only the
dependency on \texttt{p(X,Z)} through the first clause of \texttt{p\_aux/2} but
also the answers \texttt{p(a,b)} and \texttt{p(b,c)} through the second clause
of \texttt{p\_aux/2}.  Since \texttt{p(X,Z)} is a variant of \texttt{p(X,Y)}, the dependency and the two answers
are all associated with the same table.
\end{example}

\subsection{Completion}\label{sec:completion}

\begin{figure}[b]
\begin{minipage}{0.99\textwidth}
\begin{MyFloatingVerbatim}
completion :-                  completion_step(SourceTable) :-
  ( worklist_empty ->            (
      set_all_complete,            table_get_work(SourceTable,Answer,
      cleanup_tables                 dependency(Source,Continuation,Target)),
  ;                                Source = call_info(Answer,_),
      pop_worklist(Table),         Target = call_info(Wrapper,TargetTable),
      completion_step(Table),      delim(Wrapper,Continuation,TargetTable),
      completion                   fail
  ).                             ;
                                   true
                                 ).
\end{MyFloatingVerbatim}
\end{minipage}
\caption{The completion fixpoint.\label{fig:fixpoint}}
\end{figure}

The completion phase, defined in Figure~\ref{fig:fixpoint}, computes the
fixpoint over all answers and dependencies of the scheduling component. Just like Datalog's
semi-naive approach~\cite{datalogNeverAsk}, our implementation tries to avoid unnecessary
recomputation. More code details are available in~Appendix~C.

We maintain a worklist of all tables for which at least one associated
answer has not been fed into at least one associated dependency. This worklist
is updated whenever a new answer or new dependency is associated with a table.

Predicate \texttt{completion/0} is the driving loop of the completion phase.
It repeatedly pops a table from the worklist and calls \texttt{completion\_step/1} to process
answer/dependency pairs that have not yet been combined.
When the worklist is empty, the completion fixpoint has been reached. Then \texttt{set\_all\_complete/0} sets the status of every table in the scheduling component to \texttt{complete}. Finally \texttt{cleanup\_tables/0} erases all the dependencies, as they are no longer necessary.

Predicate \texttt{completion\_step/1} retrieves an unprocessed pair \texttt{Answer}/\texttt{Dependency} from
the table by calling \texttt{table\_get\_work/3}. It instantiates the source of
the dependency with the answer and resumes the dependency's continuation with
\texttt{delim/3}, binding the variables in the partial answer \texttt{Wrapper} along the way. This process may lead to new answers or new dependencies that spur
the fixpoint computation on. Here, a failure-driven loop is used to iterate over
all answer/dependency pairs.

\begin{example}
Let us consider the completion that follows Example~\ref{ex:4}. There is one entry in
the worklist: the table for call variant \texttt{p(X,Y)}. This table has two unprocessed
pairs:\footnote{We have abbreviated the call information for the sake of clarity.}
\[ \begin{array}{c}
    \texttt{p(a,b)}~/~\texttt{dependency(p(X,Z),e(Z,Y),p(X,Y))} \\
    \texttt{p(b,c)}~/~\texttt{dependency(p(X,Z),e(Z,Y),p(X,Y))}
   \end{array}\]
The first pair yields the new answer \texttt{p(a,c)} with the help of the
fact \texttt{e(b,c)}. The second pair yields nothing.
The production of a new answer reschedules the table for \texttt{p(X,Y)} in the worklist. Yet the second
completion round yields no new answers or dependencies and the fixpoint computation
terminates with answer set \{\texttt{p(a,b)}, \texttt{p(b,c)}, \texttt{p(a,c)}\} for call \texttt{p(X,Y)}.
\end{example}
\TIKZ{\tikzset{batch/.style={shape=ellipse,inner sep=0,draw}}}

\TIKZ{\tikzset{dequeue/.style={
  matrix of math nodes,
  column sep=5mm,
  nodes={anchor=base, text height=1mm,text width=3mm,align=center},row sep=0mm}}}

\TIKZ{\tikzset{new/.style={fill=black!10}}}
\TIKZ{\tikzset{old/.style={}}}

\subsection{The Table Data Structures}
\TIKZ{\tikzset{combine/.style={line width=0.3mm,decorate}}}
\TIKZ{\tikzset{emit/.style={color=black!60,-{Stealth[]},decorate,decoration={snake,amplitude=0.5mm,segment length=2mm, post length=2mm},text=black}} \tikzset{dep/.style={-{Stealth[]},dotted,color=black!60,line width=0.2mm}}}

The central data structure used by the tabling control flow explained above is the \emph{table}. We maintain one such table per call
variant, which can be retrieved from a global repository of all tables.  This
global repository is implemented in the form of a trie data structure, also
known as the call trie, that maps call patterns to tables.

There is a second global data structure, the global worklist, which maintains a
simple queue of tables for the algorithm explained in
the previous subsection.

The table itself consists of two parts: the answer trie and the local worklist:
\begin{itemize}
\item
The answer trie is where \texttt{get\_answer\_from\_table/2}
finds its answers. Moreover, the trie allows \texttt{store\_answer/2} to
quickly check whether a newly produced answer has already been computed before,
and to only store it in case it has not.
\item
The local worklist serves the \texttt{table\_get\_work/3} predicate. It
retrieves pairs of answers and dependencies that have not
been combined before. For this purpose we use a dequeue (i.e., a double-ended
queue) that contains answers and dependencies.

The dequeue maintains the invariant that an answer is to the left of a dependency
if and only if they have not been combined. New answers are added on the
left, because they have not been combined with any dependency yet.
New dependencies are added on the right.

For performance reasons, the dequeue batches consecutive answers into
a single entry on insertion; the same happens to consecutive dependencies. Every batch
contains homogeneous elements (either answers or dependencies) and is
implemented as a list --- the position of the elements in the list is
insignificant. Batches of the same type are not merged if they become adjacent during the combination of answers and dependencies. Doing so would reduce the number of swaps, but at the cost of merging the lists.

The \texttt{table\_get\_work/3} predicate retrieves a batch of answers
immediately to the left of a batch of dependencies, swaps their positions and yields the elements of
their Cartesian products for processing.
Dependencies and answers that are created by the combination are also sent to the appropriate tables. A single step of this process is illustrated in Figure~\ref{fig:localWorklist}. The solid arrow denotes the transformation of the local worklist. The wavy line denotes the emission of new answers and dependencies that are generated by the completion step. The answers in the gray ellipse have been added to the local worklist, and will eventually move to the right of all dependencies.

\begin{figure}
\TIKZ{
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
\begin{tikzpicture}
\node (a) {
 \begin{tikzpicture}
 \matrix (m) [dequeue]
 {
  a_{1} & d_{1} & d_{1} & a_{1} & a_{1}\\
  \ldots & \ldots & \ldots & \ldots & \ldots \\
  a_{m} & d_{n} & d_{o} & a_{p} & a_{q}\\
 };
 \begin{pgfonlayer}{background}
 \foreach \i in {1,...,1} {
   \node [new,name path = col\i,batch,fit=(m-1-\i) (m-3-\i)] {};
 }
 \foreach \i in {2,...,5} {
   \node [old,name path = col\i,batch,fit=(m-1-\i) (m-3-\i)] {};
 }
 \end{pgfonlayer}
 \foreach \i in {1,...,4} {
  \pgfmathparse{int(\i + 1)}
  \path [name path=coltop](m-1-\i.east) -- (m-1-\pgfmathresult.west);
  \path [name intersections={of=coltop and col\i}];
  \coordinate (left) at (intersection-1);
  \path [name intersections={of=coltop and col\pgfmathresult}];
  \draw (left) -- (intersection-1);
 }
\node[fit=(m),inner sep=2mm,draw] {};
 \end{tikzpicture}
};
\node [right=10mm of a.east,anchor=west] (b) {
 \begin{tikzpicture}
 \matrix (m) [dequeue]
 {
  d_{1} & a_{1} & d_{1} & a_{1} & a_{1}\\
  \ldots & \ldots & \ldots & \ldots & \ldots \\
  d_{n} & a_{m} & d_{o} & a_{p} & a_{q}\\
 };
 \begin{pgfonlayer}{background}
 \foreach \i in {2,...,2} {
   \node [new,name path = col\i,batch,fit=(m-1-\i) (m-3-\i)] {};
 }
 \foreach \i in {1,3,4,5} {
   \node [old,name path = col\i,batch,fit=(m-1-\i) (m-3-\i)] {};
 }
 \end{pgfonlayer}
 \foreach \i in {1,...,4} {
  \pgfmathparse{int(\i + 1)}
  \path [name path=coltop](m-1-\i.east) -- (m-1-\pgfmathresult.west);
  \path [name intersections={of=coltop and col\i}];
  \coordinate (left) at (intersection-1);
  \path [name intersections={of=coltop and col\pgfmathresult}];
  \draw (left) -- (intersection-1);
 }
\node[fit=(m),inner sep=2mm,draw] {};
 \end{tikzpicture}
};

\draw [combine,decoration={markings,mark=at position 0.5 with \coordinate (V);}] (a.east) to (b.west);
\draw [combine,-{Stealth[scale=0.8]}] (a.east) to (b.west);
\coordinate (ab) at ($0.5*(a.east)+0.5*(b.west)$);
\node [below = 15mm of ab,align=center] (abanswer){Answers \& Dependencies};
\draw [emit,decoration={pre length=1mm}] (V) -- (abanswer);

\end{tikzpicture}
}
\includegraphics{main-figure0.pdf}
\caption{Combining answers and dependencies in a local worklist.\label{fig:localWorklist}}
\end{figure}

\end{itemize}

\paragraph{Implementation Support}
The key Prolog implementation support for these tables are mutable terms and
non-backtrackable mutations (Appendix~B). We also use a global variable for the table
repository. These features are widely available. The non-backtrackable
nature is essential to retain the collected answers and
dependencies across disjunctions.

\subsection{Completion of a Double Recursive Call}

\newcommand{r}{r}

\begin{example}
Consider a variant of our running example where the recursive clause is replaced by:
\begin{MyNonFloatingVerbatim}
r(X,Y) :- r(X,Z), r(Z,Y).
\end{MyNonFloatingVerbatim}
Figure~\ref{fig:ex:r} illustrates the computation of \texttt{?- r(a,Y)}. Each table is a rectangle. The consecutive states of its worklist are shown from top to bottom. A dotted arrow shows the target of a dependency. The solid and wavy lines are as in Figure~\ref{fig:localWorklist}. In the explanation, the labels of the completion steps in the figure are written between parentheses.
The call \texttt{?- r(a,Y).} gives rise to the dependency
\texttt{D1 = dependency(r(a,Z),r(Z,Y),r(a,Y))} and the answer \texttt{r(a,b)} (left rectangle).

\paragraph{Iteration 1} In the first iteration of completion (1), the answer is fed into the dependency (wavy arrow $\alpha$), hence \texttt{D1} and \texttt{r(a,b)} are swapped.
This exposes the call \texttt{r(b,Y)} (middle rectangle). For this new call we immediately obtain the
dependency \texttt{D2 = dependency(r(b,Z1),r(Z1,Y),r(b,Y))} and the answer \texttt{r(b,c)}.
We also record dependency \texttt{D3 = dependency(r(b,Y),true,r(a,Y))} between
\texttt{r(b,Y)} and \texttt{r(a,Y)}. The \texttt{true} in \texttt{D3} represents the empty continuation: finding an answer for \texttt{r(b,Y)} gives an answer for \texttt{r(a,Y)} for free!

\TIKZ{\tikzset{table/.style={draw,matrix of nodes,nodes={batch,inner sep=0.5mm,anchor=base,outer sep =0mm, align=center},column sep=0mm,row sep=6mm}}}
\begin{figure}
 \vspace{-5mm}\includegraphics{main-figure1.pdf}
 \TIKZ{
 \begin{tikzpicture}[text depth=0pt]
 \matrix(l) [table]{
 |[rectangle,draw=none,inner sep=0mm,outer sep=0mm]| \textbf{\fbox{r(a,Y)}} \\[-3mm]
r(a,b)&D1&[2mm]\\
 D1&r(a,b)\\
 r(a,c)&D1& r(a,b)\\
 D1& r(a,c)& r(a,b)\\
 };
 \draw (l-2-1) -- (l-2-2);
 \draw (l-3-1) -- (l-3-2);
 \draw (l-4-1) -- (l-4-2) -- (l-4-3);
 \draw (l-5-1) -- (l-5-2) -- (l-5-3);

 \matrix[right = 3mm of l.north east, anchor=north west,table]  (m)
 {
 |[rectangle,draw=none,inner sep=0mm]|\textbf{\fbox{r(b,Y)}}\\[-3mm]
 r(b,c)& D2& D3\\
 D2& r(b,c)& D3\\
 D2& D3& r(b,c)\\
 };
 \draw (m-2-1) -- (m-2-2)-- (m-2-3);
 \draw (m-3-1) -- (m-3-2)-- (m-3-3);
 \draw (m-4-1) -- (m-4-2) -- (m-4-3);

 \matrix[right = 3mm of m.north east, anchor=north west,table] (r)
 {
 |[rectangle,draw=none,inner sep=0mm]| \textbf{\fbox{r(c,Y)}}\\[-3mm]
 D4& D5&[2mm]\\
 D4& D5& D6\\
 };
 \draw (r-2-1) -- (r-2-2);
 \draw (r-3-1) -- (r-3-2)-- (r-3-3);

 \draw [name path=pluk] (l-2-1) edge [combine,decoration={markings,mark=at position 0.5 with \coordinate (X);}] node[left] {\textbf{1}}  (l-3-1);
 \draw (l-2-1) edge [-{Stealth[scale=0.8]},combine] node[left] {\textbf{1}}  (l-3-1);
 \draw (l-4-1) edge [combine,decoration={markings,mark=at position 0.5 with \coordinate (Y);}] (l-5-1);
 \draw (l-4-1) edge [-{Stealth[scale=0.8]},combine] node[left] {\textbf{3}} (l-5-1);
 \draw (m-2-1) edge [combine,decoration={markings,mark=at position 0.5 with \coordinate (Z);}] (m-3-1);
 \draw (m-2-1) edge [-{Stealth[scale=0.8]},combine] node[left] {\textbf{2.a}} (m-3-1);
 \draw (m-3-1) edge [combine,decoration={markings,mark=at position 0.5 with \coordinate (V);}] (m-4-1);
 \draw (m-3-1) edge [-{Stealth[scale=0.8]},combine] node[right,label] {\textbf{2.b}} (m-4-1);
 \draw  (X) edge[emit,out=0,in=195] node[above] {$\alpha$} (m-2-1);
 \draw  (Z) edge[emit,out=-5,in=205,out distance=30mm] node[above] {$\beta$} (r-2-1);
 \draw  (V) edge[emit,out=180,in=30,in distance=5mm] node[above] {$\gamma$} (l-4-1);
 \draw  (Y) edge[emit,out=0,in=235, out distance=80mm, in distance=30mm] node[below] {$\delta$} (r-3-3);
 \draw [dep] (l-2-2) edge [bend right] (l.north);
 \draw [dep] (m-2-2) edge [bend right] (m.north);
 \draw [dep] (r-2-1) edge [out=25,in=305] ($(r.north)!0.2!(r.north west)$);
 \draw [dep] (m-2-3) edge [out=100,in=10] ($(l.north)!0.5!(l.north east)$);
 \draw [dep] (r-2-2) edge [out=90,in=30,out distance=13.5mm] ($(m.north)!0.6!(m.north east)$);
 \draw [dep] (r-3-3) edge [out=95,in=10] ($(l.north)!0.5!(l.north east)$);
 \end{tikzpicture}
}
 \caption{\label{fig:ex:r}Illustration of the computation of \texttt{r(a,Y)}.}
\end{figure}

\paragraph{Iteration 2}
During the second iteration, we feed the answer \texttt{r(b,c)} into the two
dependencies \texttt{D2} (2.a, wavy arrow $\beta$) and \texttt{D3} (2.b, wavy arrow $\gamma$).
\begin{enumerate}
\item[$\beta$]
In the \texttt{D2} case, we expose a new
call \texttt{r(c,Y)} (right rectangle) yielding no direct answer, but a new dependency
\texttt{D4 = dependency(r(c,Z2),r(Z2,Y),r(c,Y))} and a derived dependency
\texttt{D5 = dependency(r(c,Y),true,r(b,Y))}.
\item[$\gamma$]
In the \texttt{D3} case, we obtain the new answer \texttt{r(a,c)} for the top-level call.
\end{enumerate}

\paragraph{Iteration 3}
During the third iteration (3), we feed the new answer into dependency \texttt{D1} (wavy arrow $\delta$).
This yields the call \texttt{r(c,Y)} and the dependency \texttt{D6 = dependency(r(c,Y),true,r(a,Y))}.

\paragraph{The fixpoint}
Finally, there is no more work to be done: at the bottom of each rectangle, all D$i$ are left of all answers. Hence, the fixpoint comprises the
answer table $\{\texttt{r(a,b)}, \texttt{r(a,c)}\}$ for the call pattern \texttt{r(a,Y)},
the answer table $\{\texttt{r(b,c)}\}$ for the call pattern \texttt{r(b,Y)} and the
empty answer table for \texttt{r(c,Y)}.

\end{example}

\section{Introduction}
\input{introduction}
\section{Background: Delimited Continuations}
\label{sec:background}
\input{background}
\section{Shallow Program Transformation}
\input{implementation}
\section{Evaluation}
\input{evaluation}
\section{Related Work}
\input{relatedWork}
\section{Conclusion}
\input{conclusion}

\paragraph{Acknowledgements}
We are grateful to Bart Demoen for supporting hProlog and to the anonymous reviewers for their helpful feedback. This work was partly funded by the Flemish Fund for Scientific Research (FWO).

\bibliographystyle{acmtrans}