\documentclass[leqno,11pt,a4paper]{article}
\usepackage{amsmath,amsthm}

\textheight=9.0truein
\hoffset=-0.4truein
\textwidth=6.1truein
\voffset=-0.5truein

\input{header.tex}
\input{defs_AHM.tex}

%\usepackage{mathabx} %package utilisé pour définir "\lll" comme le symbole d'absolue continuité de 2 mesures
\usepackage[toc,page]{appendix} %package utilisé pour l'appendice voir : https://texfaq.org/FAQ-appendix
\usepackage{tikz}
%\usetikzlibrary{shapes}
%"Ce document a été généré avec la version de TikZ \pgfversion ." : à mettre après "begin{document}" si affichage souhaité...
\newtheorem{rem}{Remark}
\setcounter{secnumdepth}{3} %permet de numéroter les sous-sous-sections

\begin{document}
\title{A quantitative Mac Diarmid's inequality for geometrically ergodic Markov chains}
%\title{Density estimation for RWRE : a Bayesian non-parametric approach}
%\author{A. Havet, M. Lerasle, E. Moulines and E. Vernet}
\author{D. Belomestny, E. Moulines and S. Samsonov}
\maketitle

\begin{abstract}
 We state and prove a quantitative version of the bounded difference inequality for geometrically ergodic Markov chains.
 Our proof uses the same martingale decomposition as \cite{MR3407208} but, compared to this paper, the exact coupling argument is modified to fill a gap between the strongly aperiodic case and the general aperiodic case.
\end{abstract}

\noindent
{\small {\bf Keywords:} Concentration inequalities ; Markov chains ; Geometric ergodicity ; Coupling.}

\noindent
{\small {\bf AMS MSC 2010:} 60J05; 60E15.}

\section{Introduction}
The purpose of this note is to establish a quantitative version of Mc Diarmid's inequality for geometrically ergodic Markov chains.
Let $X_0,\ldots,X_{n-1}$ denote independent random variables taking values in a measurable space $(\sX,\cX)$ and $c=(c_0,\ldots,c_{n-1})$ denote a vector of non-negative real numbers. A function  $f:\sX^n\to\Rbb$ satisfies the bounded difference inequality if for all $x=(x_0,\ldots,x_{n-1})$ and
$y=(y_0,\ldots,y_{n-1})\in \sX^{n}$, we have
\begin{equation}\label{def:BDP}
|f(x)-f(y)|\leqslant \sum_{i=0}^{n-1}c_i\indiacc{x_i\ne y_i}\eqsp.
\end{equation}
The bounded difference inequality, first established in \cite{MR1036755}, shows that for all $t > 0$,
\[
\Pbb\big(f(X_0,\ldots,X_{n-1})-\Ebb[f(X_0,\ldots,X_{n-1})]>t\big)\leqslant \rme^{-2t^2/\|c\|^2}\eqsp,
\]
where $\|c\|^2=\sum_{i=0}^{n-1}c_i^2$.
Several attempts have been made to extend this result to Markov chains.
In \cite{MR2424985}, the concentration of particular functionals of the form $f(x_0,\ldots,x_{n-1})=\sup_{g\in \cF}\sum_{i=0}^{n-1}g(x_i)$, for centered functions $g$ in a class $\cF$ is established.
The concentration of general functionals (satisfying \eqref{def:BDP}) of geometrically ergodic Markov chains was established in \cite{MR3407208}, where it is also proved that geometric ergodicity is a necessary assumption. However, the result in \cite{MR3407208} is not quantitative.
It states that for all geometrically recurrent set $C$, there exists a constant $\beta$, depending on $C$ such that for all $x \in C$ and $t > 0$,
\begin{equation}
\label{eq:mcdiarmid-markov}
\Pbb_x\big(f(X_0,\ldots,X_{n-1})-\Ebb_x[f(X_0,\ldots,X_{n-1})]>t\big)\leqslant \rme^{-\beta t^2/\|c\|^2}\eqsp,
\end{equation}
where for any $x\in\Xsigma$, $\Pbb_x$ is the distribution of the Markov chain $\{X_k\}_{k=0}^\infty$ starting from $x$ (see the precise definition below).
In many  applications, it is necessary to get the explicit dependence of the constant $\beta$ as a function of the set $C$.
In particular, this problem arises when establishing posterior concentration rates of Bayesian non-parametric estimators; see for example \cite{rousseau:2016,ghosal:vandervaart:2017} for recent accounts on this theory.
To extend these results to Markovian settings, the result of \cite{MR3407208} cannot be applied directly and a quantitative version of  \eqref{eq:mcdiarmid-markov} is required, where the dependence of $\beta$ on constants characterizing the mixing of the Markov chain is needed; see for example \cite{vernet:2015,lecorff:lerasle:vernet:2018}.

A quantitative version of Mc Diarmid's inequality for Markov chains was established in \cite{paulin:2015}, where the constant $\beta$ depends here explicitly on the mixing time of the chain.
The existence of finite mixing times requires \emph{uniform} ergodicity of the chain, see for example \cite[Section 3.3]{MR2095565}, an  assumption that typically fails when the chain takes value in general state spaces.
In this note, we prove an extension of Mc Diarmid's inequality to geometrically ergodic Markov chains.
Our proof is based on  \cite{MR3407208},
but avoids the use of \cite[Lemma~6]{MR3407208} which requires the construction of an exact coupling.
Exact coupling can actually be built in the strongly aperiodic case but there is a gap in the general aperiodic case.

The remaining of the paper is decomposed as follows, Section~\ref{sec:Setting} introduces formally the notations and the assumptions of the main result, which is stated and proved in Section~\ref{sec:Main}.

\section{Notations and assumptions}\label{sec:Setting}
Let $(\sX,\cX)$ be a measurable space.
We denote by $\tvdistsym$  the total variation distance between probability measures.
For any sequence $x=\sequence{x}[n][\Nbb]$ and any non-negative integers $a$ and $b$, with $a\leqslant b$, let $\chunk[a]{x}[b]=(x_a,x_{a+1},\ldots,x_b)$.
For any $n\geqslant 0$ and any vector $c=\chunk[0]{c}[n-1]\in \R^n$, let $\|c\|$ denote the Euclidean norm of $c$ and $\|c\|_\infty=\max_{0\leqslant i\leqslant n-1}|c_i|$ denote its sup-norm.

We denote by $(\sX^{\Zbb_+},\cX^{\otimes\Zbb_+}, (\cF_k)_{k\geqslant 0})$ the canonical filtered space,
$\{X_n\}_{n=0}^\infty$ the canonical process and $\theta: \sX^{\Zbb_+}\to\sX^{\Zbb_+}$  the shift operator on the canonical space defined, for any $x=(x_{n})_{n\geqslant 0}\in \sX^{\Zbb_+}$ by $\theta(x)\in \sX^{\Zbb_+}$, where, for any $n\geqslant 0$, $\theta(x)_n=x_{n+1}$.
Set $\theta_1=\theta$ and for $n\in \Nbb^*$, define inductively, $\theta_n=\theta_{n-1} \circ \theta$. We also need to define $\theta_\infty$. To this aim, fix an arbitrary $x^*\in \Xset$, we define $\theta_\infty:\Xset^\Nbb \to \Xset^\Nbb$ such that for $z=\sequence{z}[k][\Nbb] \in \Xset^\Nbb$, $\theta_\infty z\in \Xset^\Nbb$ is the constant sequence  $(\theta_\infty z)_k=x^*$ for all $k \in \Nbb$.

Let $P$ be a Markov kernel on $\sX \times \cX$.
For any probability measure $\xi$ on $(\Xset,\Xsigma)$, denote by $\Pbb_{\xi}$  the unique probability under which $(X_n)_{n\geqslant 0}$ is a Markov chain with Markov kernel $P$ and initial distribution $\xi$ and let $\Ebb_{\xi}$ denote the expectation under the distribution $\Pbb_{\xi}$.
Recall that $\cF_n$ denotes the $\sigma$-algebra generated by $X_0, \ldots,X_n$.
For any $x\in \sX$, let $\delta_x$ denote the Dirac mass at point $x$.
With some abuse of notation, we also denote $\Pbb_x$ (resp. $\Ebb_x$) instead of $\Pbb_{\delta_x}$ (resp. $\Ebb_{\delta_x}$).

For any $\cB\in \cX$ and any integer $i\geqslant 0$, let
\[
\tau_{\cB}^i=\inf\{n\geqslant i: X_n\in \cB\}=i+\tau_{\cB}^0\circ \theta^i
\qquad \text{and} \qquad
\sigma_{\cB}=\tau_{\cB}^1=1+\tau_{\cB}^0\circ \theta\eqsp.
\]
For $c = \chunk[0]{c}[n-1] \in \R_+^n$, we denote by  $\functionboundeddiff{\sX^n}{c}$  the set of measurable functions $f:\sX^n\to\R$ such that for all $x= (x_0,\dots,x_{n-1})$ and $y= (y_0,\dots,y_{n-1})$, $|f(x)-f(y)|\leqslant \sum_{i=0}^{n-1} c_i\indiacc{x_i\ne y_i}$
The main result is established under the following conditions.
\begin{itemize}
\item[{\bf H1}] The Markov kernel $P$ is irreducible and aperiodic, with unique invariant probability $\pi$.
\item[{\bf H2 (drift condition)}] There exist a measurable function $V: X \rightarrow [1; +\infty)$, real numbers $\lambda \in (0,1)$, $b > 0$ and a non-empty set $\cC \in \cX$ such that for any $x \in X$,
\[
PV(x) \leq \lambda V(x) + b\indiacc{x \in \cC}
\]
%\item[{\bf H2}] There exist a non-empty set $\cC \in \cX$ and two real numbers $u>1$ and $M>0$ such that
%  \[\sup_{x\in \cC}\Ebb_x[u^{\sigma_{\cC}}]\leqslant M\eqsp.\]
%\item[{\bf H3}] There exist $r\in (0,1)$ and $L\geqslant 1$ such that, for any $x$ in the set $\cC$ of {\bf H2} and any $n\geqslant 0$,
%\[
%\tvdist{\delta_xP^n}{\pi} \leqslant Lr^n\eqsp,
%\]
%where $\pi$ is the unique invariant measure granted in {\bf H1}.
\item[{\bf H3 (V-ergodicity)}] There exist $r \in (0,1)$, $L \geqslant 1$ and function $V: X \rightarrow \mathbb{R}$ such that for any $x  \in  X$ and any $n \geqslant 0$, it holds
\[
d_V(\delta_xP^n,\pi) \leqslant L V(x) r^n\eqsp,
\]
\end{itemize}
where $\pi$ is the unique invariant measure from {\bf H1}.
\par
When the Markov kernel $P$ is uniformly ergodic, then {\bf H3} holds with $V(x) = 1$.
\par
Note that \cite[Proposition 14.3.1]{douc:moulines:priouret:soulier:2018} implies that if Markov kernel $P$ satisfies the drift condition {\bf H2} with the set $\cC \in \cX$, $\cC = \{x: V(x) < d\}$, then it holds for any $x \in \cC$ that
\begin{equation}
\label{eq:exp_moment_hit}
\sup_{x\in \cC}\Ebb_x[\lambda^{-\sigma_{\cC}}]\leqslant M\eqsp
\end{equation}
with some $M$ depending on $V(x)$ and $d$.
\par
The following Lemma is a coupling result that replaces \cite[Lemma~6]{MR3407208}. It is instrumental in the sequel.
\begin{lemma}\label{lem:DMPS18}
 For any probability measures $\xi$ and $\xi'$ on $(\sX,\cX)$, any $n\geqslant 1$, any $c\in \R_+^n$ and any $h\in \bB\Dbb(\sX^n,c)$,
\begin{equation*}\label{eq:Step1}
 |\Ebb_\xi[h(\chunk[0]{X}[n-1])]-\Ebb_{\xi'}[h(\chunk[0]{X}[n-1])]|\leqslant 2\sum_{i=0}^{n-1}c_i \tvdist{\xi P^i}{\xi'P^i} \leqslant 2\sum_{i=0}^{n-1}c_i \vfuncdist{\xi P^i}{\xi'P^i} \eqsp.
\end{equation*}
\end{lemma}
\begin{remark}
 It is possible to avoid the factor $2$ in \eqref{eq:Step1} under additional technical conditions, for example, when there exists a maximal coupling for $(\Pbb_\xi,\Pbb_{\xi'})$, see \cite[Lemma 23.2.1]{douc:moulines:priouret:soulier:2018}.
\end{remark}
\begin{proof}
Fix an arbitrary
$x^* \in \Xset$. For $i \in \{1,\ldots,n-1\}$, we set $\bar{h}_i(\chunk[i]{x}[n-1])=h(x^*,\dots,x^*,\chunk[i]{x}[n-1])$. By convention,
we set $\bar{h}_n$ the constant function $\bar{h}_n=h(x^*,\ldots,x^*)$ and $\bar{h}_0=h$. With these
notations, we have the decomposition
\[
h(\chunk{x})=\sum_{i=0}^{n-1} \{\bar{h}_i(\chunk[i]{x}[n-1]) - \bar{h}_{i+1}(\chunk[i+1]{x}[n-1]) \} +\bar{h}_n \eqsp.
\]
For all $i \in \{0,\ldots,n-1\}$ and all $x_i \in \Xset$, let
\begin{align}
\bar{w}_i(x_i)&=\int \lrcb{\bar{h}_i(\chunk[i]{x}[n-1])-\bar{h}_{i+1}(\chunk[i+1]{x}[n-1])}  \prod_{\ell=i+1}^{n-1} P(x_{\ell-1}, \rmd x_{\ell})\eqsp, \nonumber \\
&=\int \lrcb{h(x^*,\ldots,x^*,\chunk[i]{x})-h(x^*,\ldots,x^*,\chunk[i+1]{x})}  \prod_{\ell=i+1}^{n-1} P(x_{\ell-1}, \rmd x_{\ell}) \eqsp. \label{eq:delta:diarmid:fond}
\end{align}
It is easily seen that $\CPE{\{\bar{h}_i(\chunk[i]{X}[n-1])-\bar{h}_{i+1}(\chunk[i+1]{X}[n-1])\}}{\cF_{i}}=\bar{w}_i(X_i)$, $\Pbb_\xi-\as$,  which implies that
\[
\Ebb_\xi \lrb{h(\chunk{X})}=\sum_{i=0}^{n-1} \xi P^i \bar{w}_i + \bar{h}_n \eqsp.
\]
Since  $h \in\functionboundeddiff{\Xset^n}{c}$, \eqref{eq:delta:diarmid:fond} shows that  $\supnorm{\bar{w}_i} \leq c_i$.
Therefore,
\[
|\Ebb_\xi \lrb{h(X^{n-1})}-\Ebb_{\xi'} \lrb{h(X^{n-1})} |\\
\leq \sum_{i=0}^{n-1} |\xi P^i \bar{w}_i-\xi' P^i \bar{w}_i| \leq 2 \sum_{i=0}^{n-1} c_{i}\tvdist{\xi P^{i}}{\xi' P^{i}} \eqsp.
\]
The result now follows from the trivial bound $\tvdist{\xi}{\eta} \leq \vfuncdist{\xi}{\eta}$ for arbitrary measures $\xi,\eta$ given that $V(x) \geq 1$ for any $x \in X$.
\end{proof}

\section{Main result}\label{sec:Main}
The main result of this paper  is the following quantitative version of Mac Diarmid's inequality for $V-$ergodic Markov chains under certain drift condition.
%\begin{theorem}\label{thm:ConcMarkQuant}
 %Assume {\bf H1}, {\bf H2}, {\bf H3}. Let $n\geqslant 1$, $c\in \R^n$ and  $f\in \functionboundeddiff{\sX^n}{c}$. Then, for all $x\in \cC$ and $t > 0$,
 %\[
%\Pbb_x\big(f( \chunk[0]{X}[n-1])-\Ebb_x[f(\chunk[0]{X}[n-1])]>t\big)\leqslant \exp\bigg(-\frac{\beta t^2}{\|c\|^2}\bigg)\eqsp,
% \]
%where $\beta$ is given by
 %\[
 %\beta=\frac{(1-r\vee u^{-1/4})^2}{16L}\bigg(\frac5{\log u}+4ML\bigg)^{-1}\eqsp.
 %\]
%\end{theorem}
\begin{theorem}\label{thm:ConcMarkVErgodic}
 Assume {\bf H1}, {\bf H2} and {\bf H3} holds with drift function $V(x)$. Let $M$ be a constant from \ref{eq:exp_moment_hit}, $\cC = \{V(x) < d\}$, $n\geqslant 1$, $c\in \R^n$ and  $f\in \functionboundeddiff{\sX^n}{c}$. Then, for all $x\in \cC$ and $t > 0$,
 \[
\Pbb_x\big(f( \chunk[0]{X}[n-1])-\Ebb_x[f(\chunk[0]{X}[n-1])]>t\big)\leqslant \exp\bigg(-\frac{\beta t^2}{\|c\|^2}\bigg)\eqsp,
 \]
where $\beta$ is given by
 \[
 \beta=\frac{(1-r\vee \lambda^{1/4})^2}{16Ld}\bigg(-\frac5{\log \lambda}+4MLd\bigg)^{-1}\eqsp.
 \]
\end{theorem}

\begin{proof}[Proof of \Cref{thm:ConcMarkVErgodic}]
Fix $c\in \Rbb^n$, $x\in\sX$ and $f\in \functionboundeddiff{\sX^n}{c}$. Note that drift condition {\bf H3} implies that
\[
\sup_{x\in \cC}\Ebb_x[\lambda^{-\sigma_{\cC}}]\leqslant M\eqsp
\]
Following \cite{MR3407208}, we decompose $f(\chunk[0]{X}[n-1])-\Ebb_x[f(\chunk[0]{X}[n-1])]$ into martingale increments by conditioning to the stopping times $\tau_{\cC}^i$, $i=0,\ldots, n-1$.
For any integer $i\in [0,n-1]$, define
\[
G_i=\Ebb_x\big[f(\chunk[0]{X}[n-1])|\cF_{\tau_{\cC}^i}\big]\eqsp.
\]
As $\tau_{\cC}^0=0$ $\Pbb_x$-a.s., it holds $\Ebb_x[f(\chunk[0]{X}[n-1])]=\Ebb_x[f(\chunk[0]{X}[n-1])|\cF_{\tau_{\cC}^0}]=G_0$.
Moreover, as $\tau_{\cC}^{n-1}\geqslant n-1$, it also holds $G_{n-1}=\Ebb_x[f(\chunk[0]{X}[n-1])|\cF_{\tau_{\cC}^{n-1}}]=f(\chunk[0]{X}[n-1])$.
Therefore, the difference $f(\chunk[0]{X}[n-1])-\Ebb_x[f(\chunk[0]{X}[n-1])]$ is decomposed into a sum of the martingale increments $G_{i+1}-G_i$ as follows
\begin{equation}\label{eq:LinkWithG}
 f(\chunk[0]{X}[n-1])-\Ebb_x[f(\chunk[0]{X}[n-1])]=G_{n-1}-G_0=\sum_{i=0}^{n-2}(G_{i+1}-G_i)\eqsp.
\end{equation}
The proof is now decomposed into three facts that aim at bounding the Laplace transform of $f(\chunk[0]{X}[n-1])-\Ebb_x[f(\chunk[0]{X}[n-1])]$.

\noindent
{\bf Fact 1.} \emph{For any $i\in \{1,\ldots,n-1\}$,}
\begin{equation}\label{eq:Fact1}
 G_i-G_{i-1}=(G_i-G_{i-1})\indiacc{\tau_{\cC}^{i-1}=i-1}\eqsp.
\end{equation}
\begin{proof}[Proof of Fact 1.] By definition $\tau_{\cC}^{i-1}\geqslant i-1$ and $\tau_{\cC}^{i-1}> i-1$ if and only if $\tau_{\cC}^{i-1}=\tau_{\cC}^{i}$.
 Therefore,
 \[
 G_i-G_{i-1}=(G_i-G_{i-1})\left(\indiacc{\tau_{\cC}^{i-1}=i-1}+\indiacc{\tau_{\cC}^{i-1}=\tau_{\cC}^{i}}\right)\eqsp.
 \]
To prove that $(G_i-G_{i-1})\indiacc{\tau_{\cC}^{i-1}=\tau_{\cC}^{i}}=0$, we decompose according to the values of $\tau_{\cC}^{i}$:
 \[
(G_i-G_{i-1})\indiacc{\tau_{\cC}^{i-1}=\tau_{\cC}^{i}}=\sum_{j\geqslant i} (G_i-G_{i-1})\indiacc{\tau_{\cC}^{i-1}=\tau_{\cC}^{i}=j}\eqsp.
 \]
Now, remark that, for any $i\geqslant 0$,
\begin{align}
 G_i\indiacc{\tau_{\cC}^{i}=j}=
\begin{cases}\label{eq:Gitaui=j}
 \Ebb_x\big[f(\chunk[0]{X}[n-1])|\cF_j\big]&\text{ if } j\leqslant n-2\eqsp,\\
 f(\chunk[0]{X}[n-1])&\text{ if } j\geqslant n-1\eqsp.
\end{cases}
\end{align}
Then, for any $j\geqslant i$,
\[
 G_i\indiacc{\tau_{\cC}^{i}=j}\indiacc{\tau_{\cC}^{i-1}=\tau_{\cC}^{i}}= G_{i-1}\indiacc{\tau_{\cC}^{i-1}=j}\indiacc{\tau_{\cC}^{i-1}=\tau_{\cC}^{i}}=G_{i-1}\indiacc{\tau_{\cC}^{i}=j}\indiacc{\tau_{\cC}^{i-1}=\tau_{\cC}^{i}}\eqsp.
\]
This proves Fact 1.
\end{proof}

Fact 2. bounds the increments $G_i-G_{i-1}$. The proof relies on the following lemma which is a consequence of the coupling result Lemma~\ref{lem:DMPS18}.
Define $g_{n-1}=g_{n-1,\pi}=f$ and, for any $i\in [0,n-2]$, let $g_i$ and $g_{i,\pi}$ denote the functions defined for any $\chunk[0]{x}[i]\in\sX^{i+1}$ by
\begin{equation}
\label{eq:definition-g-i}
g_i(\chunk[0]{x}[i])=\Ebb_{x_i}[f(\chunk[0]{x}[i],\chunk[1]{X}[n-1-i])],\qquad g_{i,\pi}(\chunk[0]{x}[i])=\Ebb_{\pi}[f(\chunk[0]{x}[i],\chunk[1]{X}[n-1-i])]\eqsp.
\end{equation}

\begin{lemma}
\label{lem:gi-gipi}
 Assume {\bf H1}, {\bf H2}, {\bf H3} and let $\cC = \{x:V(x) < d\}$.
 For any $i\in \{0,\ldots,n-1\}$ and $(\chunk[0]{x}[i-1],x_i)$ in $\sX^i\times\cC$,
\begin{equation}\label{eq:gi-gipi}
|g_i(\chunk[0]{x}[i])-g_{i,\pi}(\chunk[0]{x}[i])|\leqslant 2LV(x_i)\sum_{j=i+1}^{n-1}c_jr^{j-i} \leqslant 2Ld \sum_{j=i+1}^{n-1}c_jr^{j-i}\eqsp.
\end{equation}
\end{lemma}
\begin{proof}
 Fix $i\in\{0,\ldots,n-1\}$ and $\chunk[0]{x}[i]\in \sX^{i+1}$.
As $f\in\functionboundeddiff{\sX^n}{c}$, the function $\tilde{f}_i:\chunk[1]{y}[n-1-i]\in \sX^{n-1-i}\mapsto f(\chunk[0]{x}[i],\chunk[1]{y}[n-1-i])\in \R$ satisfies
\[
|\tilde{f}_i(\chunk[1]{y}[n-1-i])-\tilde{f}_i(\chunk[1]{z}[n-1-i])|\leqslant \sum_{k=1}^{n-1-i}c_{i+k}\indiacc{y_k\ne z_k}\eqsp.
\]
Hence, $\tilde{f}_i\in\bB\Dbb(\sX^{n-1-i},c_{i+1:n-1})$. Applying Lemma~\ref{lem:DMPS18} to the function $h=\tilde{f}_i$ yields
\begin{align*}
 |g_i(\chunk[0]{x}[i])-g_{i,\pi}(\chunk[0]{x}[i])|&=|\Ebb_{x_i}[f(\chunk[0]{x}[i],\chunk[1]{X}[n-1-i])]-\Ebb_{\pi}[f(\chunk[0]{x}[i],\chunk[1]{X}[n-1-i])]|\\
 &=|\Ebb_{x_i}[\tilde{f}_i(\chunk[1]{X}[n-1-i])]-\Ebb_{\pi}[\tilde{f}_i(\chunk[1]{X}[n-1-i])]| \leqslant 2\sum_{j=i+1}^{n-1}c_j \vfuncdist{\delta_{x_i}P^{j-i}}{\pi} \eqsp.
\end{align*}
Now inequality \eqref{eq:gi-gipi} follows from {\bf H3}.
\end{proof}

\noindent
{\bf Fact 2.} \emph{Let $\rho$ such that $r\leqslant \rho<1$ and $i\in\{1,\ldots,n-1\}$.
Then,}
\begin{align}
\label{eq:Gi-Gi-1} |G_i-G_{i-1}|&\leqslant C_1\|c\|_{\infty}\indiacc{\tau_{\cC}^{i-1}=i-1}\sigma_{\cC}\circ\theta^{i-1}\eqsp,\\
\label{eq:Gi-Gi-1Sq}  |G_i-G_{i-1}|^2&\leqslant C_2\indiacc{\tau_{\cC}^{i-1}=i-1}\frac1{\rho^{2\sigma_{\cC}\circ\theta^{i-1}}}\sum_{k=i}^{n-1}c_k^2\rho^{k-i}\eqsp.
\end{align}
\emph{where, $C_1=5Ld/(1-r)$ and $C_2=16L^2d^2/(1-\rho)$.}
\begin{proof}[Proof of Fact 2.]
For any integer $i\in\{1,\ldots,n\}$, let
\[
G_{i,1}=\Ebb_x[f(\chunk[0]{X}[n-1])|\cF_{\tau_{\cC}^{i-1}}]\indiacc{\tau_{\cC}^{i-1}=i-1},\qquad G_{i,2}=\Ebb_x[f(\chunk[0]{X}[n-1])|\cF_{\tau_{\cC}^{i}}]\indiacc{\tau_{\cC}^{i-1}=i-1}\eqsp.
\]
From Fact 1., $G_i-G_{i-1}=G_{i,2}-G_{i,1}$.
By Markov's property, for any $i\in \{0,\ldots,n-1\}$ and  $x\in \sX$,
\[
\Ebb_x[f(\chunk[0]{X}[n-1])|\cF_i]=g_i(X_{0:i}),\qquad \Pbb_{x}-\text{a.s.}\eqsp.
\]
Now, let $R_{i,1}=g_{i-1}(\chunk[0]{X}[i-1])\indiacc{\tau_{\cC}^{i-1}=i-1}-g_{i-1,\pi}(\chunk[0]{X}[i-1])\indiacc{\tau_{\cC}^{i-1}=i-1}$.
We have
\begin{align}
\notag G_{i,1}&=\Ebb_x[f(\chunk[0]{X}[n-1])|\cF_{\tau_{\cC}^{i-1}}]\indiacc{\tau_{\cC}^{i-1}=i-1}=\Ebb_x[f(\chunk[0]{X}[n-1])|\cF_{i-1}]\indiacc{\tau_{\cC}^{i-1}=i-1}\\
\label{eq:Gi1} &=g_{i-1}(\chunk[0]{X}[i-1])\indiacc{\tau_{\cC}^{i-1}=i-1}=g_{i-1,\pi}(\chunk[0]{X}[i-1])\indiacc{\tau_{\cC}^{i-1}=i-1}+R_{i,1}\eqsp.
\end{align}
Moreover, as $\tau_{\cC}^i\geqslant i$, by \eqref{eq:Gitaui=j},
\begin{align}
\notag G_{i,2}&=\sum_{j\geqslant i}\Ebb_x[f(\chunk[0]{X}[n-1])|\cF_{\tau_{\cC}^{i}}]\indiacc{\tau_{\cC}^{i-1}=i-1}\indiacc{\tau_{\cC}^i=j}\\
%\notag &=\sum_{j=i}^{n-2}\Ebb_x[f(\chunk[0]{X}[n-1])|\cF_{j}]\indiacc{\tau_{\cC}^{i-1}=i-1}\indiacc{\tau_{\cC}^i=j}+f(\chunk[0]{X}[n-1])\indiacc{\tau_{\cC}^{i-1}=i-1}\indiacc{\tau_{\cC}^i\geqslant n-1}\\
\label{eq:Gi2} &=\sum_{j=i}^{n-2}g_j(\chunk[0]{X}[j])\indiacc{\tau_{\cC}^{i-1}=i-1,\tau_{\cC}^i=j}+f(\chunk[0]{X}[n-1])\indiacc{\tau_{\cC}^{i-1}=i-1,\tau_{\cC}^i\geqslant n-1}\eqsp.
\end{align}
Let $R_{i,2}=\sum_{j=i}^{n-2}(g_j(\chunk[0]{X}[j])-g_{j,\pi}(\chunk[0]{X}[j]))\indiacc{\tau_{\cC}^{i-1}=i-1,\tau_{\cC}^i=j}$.
From \eqref{eq:Gi1} and \eqref{eq:Gi2},
\begin{align}
\label{eq:Gi1-Gi2} |G_{i,2}-G_{i,1}|=|&R_{i,2}-R_{i,1}+\sum_{j=i}^{n-2}(g_{j,\pi}(\chunk[0]{X}[j])-g_{i-1,\pi}(\chunk[0]{X}[i-1]))\indiacc{\tau_{\cC}^{i-1}=i-1,\tau_{\cC}^i=j}\\
\notag &+(f(\chunk[0]{X}[n-1])-g_{i-1,\pi}(\chunk[0]{X}[i-1]))\indiacc{\tau_{\cC}^{i-1}=i-1,\tau_{\cC}^i\geqslant n-1}|
% \\
% \leqslant 4&\indiacc{\tau_{\cC}^{i-1}=i-1}L\sum_{j=i+1}^{n-1}c_jr^{j-i}+\sum_{j=i}^{n-2}|(g_{j,\pi}(\chunk[0]{X}[j])-g_{i-1,\pi}(\chunk[0]{X}[i-1]))\indiacc{\tau_{\cC}^{i-1}=i-1,\tau_{\cC}^i=j}|\\
% &+|(f(\chunk[0]{X}[n-1])-g_{i-1,\pi}(\chunk[0]{X}[i-1]))\indiacc{\tau_{\cC}^{i-1}=i-1,\tau_{\cC}^i\geqslant n-1}|
\eqsp.
\end{align}
We bound separately all the terms in this decomposition.
First, as $\pi$ is invariant and $f\in \functionboundeddiff{\sX^n}{c}$, for any $j\in \{i+1,\ldots,n-1\}$ and any $\chunk[0]{x}[j]\in \sX^{j+1}$,
\[
|g_{j,\pi}(\chunk[0]{x}[j])-g_{i-1,\pi}(\chunk[0]{x}[i-1])|=\Ebb_{\pi}[f(\chunk[0]{x}[j],\chunk[j+1]{X}[n-1])-f(\chunk[0]{x}[i-1],\chunk[i]{X}[n-1])]\leqslant \sum_{k=i}^jc_k\eqsp.
\]
Hence,
\begin{equation}
\label{eq:Bound:Easyterms}
\begin{aligned} \sum_{j=i}^{n-2}|(g_{j,\pi}(\chunk[0]{X}[j])-g_{i-1,\pi}(\chunk[0]{X}[i-1]))|\indiacc{\tau_{\cC}^i=j}&\leqslant \sum_{j=i}^{n-2}\indiacc{\tau_{\cC}^i=j}\sum_{k=i}^jc_k=\indiacc{\tau_{\cC}^i\leqslant n-2}\sum_{k=i}^{\tau_{\cC}^i}c_k\eqsp,\\
|f(\chunk[0]{X}[n-1])-g_{i-1,\pi}(\chunk[0]{X}[i-1])|\indiacc{\tau_{\cC}^i\geqslant n-1}&\leqslant \indiacc{\tau_{\cC}^i\geqslant n-1}\sum_{k=i}^{n-1}c_k\eqsp.
\end{aligned}
\end{equation}

 %where $|R_{i,1}|$ and $|R_{i,2}|$ are respectively bounded in \eqref{eq:Bound:R1} and \eqref{eq:Bound:R2}.
%\anici{Selon moi, ta majoration de $|R_{i,1}|$ et $|R_{i,2}|$ par le même terme n'était pas juste : j'ai commenté dans le fichier source (au dessus de cette anotation) et propose donc}
%\begin{align*}
% |G_{i,2}-G_{i,1}|=|&R_{i,2}-R_{i,1}+\sum_{j=i}^{n-2}(g_{j,\pi}(\chunk[0]{X}[j])-g_{i-1,\pi}(\chunk[0]{X}[i-1]))\indiacc{\tau_{\cC}^{i-1}=i-1,\tau_{\cC}^i=j}\\
% &+(f(\chunk[0]{X}[n-1])-g_{i-1,\pi}(\chunk[0]{X}[i-1]))\indiacc{\tau_{\cC}^{i-1}=i-1,\tau_{\cC}^i\geqslant n-1}|\\
% \leqslant  |& R_{i,1}| + |R_{i,2}|+\sum_{j=i}^{n-2}|(g_{j,\pi}(\chunk[0]{X}[j])-g_{i-1,\pi}(\chunk[0]{X}[i-1]))\indiacc{\tau_{\cC}^{i-1}=i-1,\tau_{\cC}^i=j}|\\
% &+|(f(\chunk[0]{X}[n-1])-g_{i-1,\pi}(\chunk[0]{X}[i-1]))\indiacc{\tau_{\cC}^{i-1}=i-1,\tau_{\cC}^i\geqslant n-1}|\\
% \leqslant  2&\indiacc{\tau_{\cC}^{i-1}=i-1}L \left( \sum_{j=i+1}^{n-1}c_jr^{j-i} + \sum_{k=\tau_{\cC}^i+1}^{n-1}c_kr^{k-\tau_{\cC}^i} \right)\\
% & +  \sum_{j=i}^{n-2}|(g_{j,\pi}(\chunk[0]{X}[j])-g_{i-1,\pi}(\chunk[0]{X}[i-1]))\indiacc{\tau_{\cC}^{i-1}=i-1,\tau_{\cC}^i=j}|\\
% &+|(f(\chunk[0]{X}[n-1])-g_{i-1,\pi}(\chunk[0]{X}[i-1]))\indiacc{\tau_{\cC}^{i-1}=i-1,\tau_{\cC}^i\geqslant n-1}|\eqsp.
%\end{align*}
To bound $|R_{i,1}|$ and $|R_{i,2}|$ in \eqref{eq:Gi1-Gi2}, we use Lemma~\ref{lem:gi-gipi}.
First, \eqref{eq:gi-gipi} directly yields
\begin{equation}\label{eq:Bound:R1}
|R_{i,1}|\leqslant 2\indiacc{\tau_{\cC}^{i-1}=i-1}Ld\sum_{j=i+1}^{n-1}c_jr^{j-i}\eqsp.
\end{equation}
Moreover, as $\{\tau_{\cC}^i=j\}\subset \{X_j\in \cC\}$, \eqref{eq:gi-gipi} also yields
\[
(g_j(\chunk[0]{X}[j])-g_{j,\pi}(\chunk[0]{X}[j]))\indiacc{\tau_{\cC}^i=j}\leqslant 2L\sum_{k=j+1}^{n-1}c_kr^{k-j}\indiacc{\tau_{\cC}^i=j}\leqslant 2Ld\indiacc{\tau_{\cC}^i=j}\sum_{k=\tau_{\cC}^i+1}^{n-1}c_kr^{k-\tau_{\cC}^i}\eqsp.
\]
Therefore,
\begin{equation}\label{eq:Bound:R2}
|R_{i,2}|\leqslant 2Ld\indiacc{\tau_{\cC}^{i-1}=i-1}\sum_{k=\tau_{\cC}^i+1}^{n-1}c_kr^{k-\tau_{\cC}^i}\eqsp.
\end{equation}
Plugging \eqref{eq:Bound:Easyterms}, \eqref{eq:Bound:R1} and \eqref{eq:Bound:R2} in \eqref{eq:Gi1-Gi2} yields
\begin{align}
\label{eq:Gi1-Gi22} |G_{i,2}-G_{i,1}|\leqslant &2Ld\bigg(\sum_{j=i+1}^{n-1}c_jr^{j-i}+\sum_{k=\tau_{\cC}^i+1}^{n-1}c_kr^{k-\tau_{\cC}^i}+\frac1{2Ld}\sum_{k=i}^{\tau_{\cC}^i\wedge (n-1)}c_k\bigg)\indiacc{\tau_{\cC}^{i-1}=i-1}\eqsp.
\end{align}
Both \eqref{eq:Gi-Gi-1} and \eqref{eq:Gi-Gi-1Sq} follow from \eqref{eq:Gi1-Gi22} by bounding separately the $3$ terms in the right-hand side of this inequality.
Let us first establish \eqref{eq:Gi-Gi-1}.
Since $r<1$,
\[
\sum_{j=i+1}^{n-1}c_jr^{j-i}\leqslant \frac{\|c\|_\infty r}{1-r},\qquad \sum_{k=\tau_{\cC}^i+1}^{n-1}c_kr^{k-\tau_{\cC}^i}\leqslant \frac{\|c\|_\infty r}{1-r}\eqsp.
\]
%\anici{Dans toutes les équations suivantes, je pense qu'il y avait une erreur dans l'indice du $\theta$ car par définition $\tau_{\cC}^i = i + \tau_{\cC}^0 \circ \theta^i$ et $\sigma_{\cC}=1+\tau_{\cC}^0 \circ \theta$ d'où $1-i+\tau_{\cC}^i\wedge (n-1) \leqslant 1-i+\tau_{\cC}^i = 1 - i + i +\tau_{\cC}^0 \circ\theta \circ \theta^{i-1}=\sigma_{\cC}\circ\theta^{i-1}$. Cela est par ailleurs cohérent avec \eqref{eq:Gi-Gi-1} que l'on souhaite montrer. J'ai donc modifié en conséquence.}
Moreover,
\[
\sum_{k=i}^{\tau_{\cC}^i\wedge (n-1)}c_k\leqslant \|c\|_{\infty}[1-i+\tau_{\cC}^i\wedge (n-1) ]\leqslant \|c\|_{\infty}[1+\tau_{\cC}^0\circ \theta^i]=\|c\|_{\infty}\sigma_{\cC}\circ\theta^{i-1}\eqsp.
\]
As $r<1\leqslant \sigma_{\cC}\circ\theta^{i-1}$, plugging these upper bounds in \eqref{eq:Gi1-Gi22} shows
\[
|G_{i}-G_{i-1}|=|G_{i,2}-G_{i,1}|\leqslant \frac{5Ld\|c\|_{\infty}}{1-r}\sigma_{\cC}\circ\theta^{i-1}\indiacc{\tau_{\cC}^{i-1}=i-1}\eqsp.
\]
This proves \eqref{eq:Gi-Gi-1}.
We use slightly different controls to prove \eqref{eq:Gi-Gi-1Sq} from \eqref{eq:Gi1-Gi22}.
As $r\leqslant \rho<1$, $\rho^{-\sigma_{\cC}\circ\theta^{i-1}}\geqslant 1$, and
\begin{align}
\label{eq:Step1Var} \sum_{j=i+1}^{n-1}c_jr^{j-i}\leqslant \sum_{j=i}^{n-1}c_j\rho^{j-i}\leqslant \rho^{-\sigma_{\cC}\circ\theta^{i-1}}\sum_{j=i}^{n-1}c_j\rho^{j-i}\eqsp.
\end{align}
%\anici{Ci après, je pense qu'il y avait également la même erreur d'indice pour $\theta$ et j'ai modifié en conséquence.}
Moreover,
\begin{align*}
 \sum_{k=\tau_{\cC}^i+1}^{n-1}c_kr^{k-\tau_{\cC}^i}\leqslant\rho^{i-\tau_{\cC}^i}\sum_{k=\tau_{\cC}^i+1}^{n-1}c_k\rho^{k-i}\eqsp.
\end{align*}
As $\tau_{\cC}^i\geqslant i$ and $i-\tau_{\cC}^i=1-\sigma_{\cC}\circ\theta^{i-1}$,
\begin{equation}\label{eq:Step2Var}
\sum_{k=\tau_{\cC}^i+1}^{n-1}c_kr^{k-\tau_{\cC}^i}\leqslant \rho^{1-\sigma_{\cC}\circ\theta^{i-1}} \sum_{j=\tau^i_{\cC}+1}^{n-1}c_j\rho^{j-i}\leqslant \rho^{-\sigma_{\cC}\circ\theta^{i-1}}\sum_{j=\tau^i_{\cC}+1}^{n-1}c_j\rho^{j-i}\eqsp.
\end{equation}
In addition,
\begin{align}\label{eq:Step3Var}
 \sum_{k=i}^{\tau_{\cC}^i\wedge (n-1)}c_k\leqslant &\sum_{k=i}^{\tau_{\cC}^i\wedge (n-1)}c_k\rho^{k-\tau_{\cC}^i}=\sum_{k=i}^{\tau_{\cC}^i\wedge (n-1)}c_k\rho^{k-i-\sigma_{\cC}\circ\theta^{i-1}+1}\leqslant \rho^{-\sigma_{\cC}\circ\theta^{i-1}}\sum_{k=i}^{\tau_{\cC}^i\wedge (n-1)}c_k\rho^{k-i}\eqsp.
\end{align}
%\anici{Je ne sais pas si c'est important quantitativement mais dans les deux majorations précédentes, on se débarasses du $\tau_{\cC}^i$ assez "brutalement" alors que si on fait comme dans mon manuscrit de thèse, on parvient dans l'inégalité suivante non pas à $25L^2$ mais $16 L^2$ (en supposant bien évidemment comme ici que $L\geq 1$).}
Plugging \eqref{eq:Step1Var}, \eqref{eq:Step2Var} and \eqref{eq:Step3Var} in \eqref{eq:Gi1-Gi22} and applying Cauchy-Schwarz inequality shows
\begin{align*}
 |G_{i}-G_{i-1}|^2=&|G_{i,2}-G_{i,1}|^2\leqslant16L^2d^2\rho^{-2\sigma_{\cC}\circ\theta^{i-1}}\bigg(\sum_{k=i}^{n-1}c_k\rho^{k-i}\bigg)^2\indiacc{\tau_{\cC}^{i-1}=i-1}\\
 \leqslant &\frac{16L^2d^2}{1-\rho}\rho^{-2\sigma_{\cC}\circ\theta^{i-1}}\sum_{k=i}^{n-1}c_k^2\rho^{k-i}\indiacc{\tau_{\cC}^{i-1}=i-1}\eqsp.
\end{align*}
This proves \eqref{eq:Gi-Gi-1Sq} and thus {\bf Fact 2.}
\end{proof}

\noindent
{\bf Fact 3.} \emph{ Assume {\bf H1}, {\bf H2}, {\bf H3}. Let $\cC = \{x: V(x) < d\}$. Then for any $x\in \cC$,}
\begin{align}
\Ebb_x\bigg[\rme^{f(\chunk[0]{X}[n-1])-\Ebb_x[f(\chunk[0]{X}[n-1])]}\bigg]\leqslant \rme^{C_3\|c\|^2}\eqsp.
\end{align}
\emph{where $C_3=\fracaa{4Ld\left(-\fracaa{5}{\log \lambda}+4MLd\right)}{(1-r\vee \lambda^{1/4})^2}$.}
\begin{proof}[Proof of Fact 3.]
For any $t\in \Rbb$, $\rme^t\leqslant 1+t+t^2\rme^{|t|}$. Hence, as $\Ebb_{x}[G_{i+1}-G_i|\cF_{\tau_{\cC}^{i}}]=0$, for any $i\geqslant 0$, we have
\begin{align*}
 \Ebb_x[\rme^{G_{i+1}-G_i}|\cF_{\tau_{\cC}^{i}}]\leqslant 1+\Ebb_x[(G_{i+1}-G_i)^2\rme^{|G_{i+1}-G_i|}|\cF_{\tau_{\cC}^{i}}]\eqsp.
\end{align*}
By Fact 2.,
\begin{align*}
 \Ebb_x[\rme^{G_{i+1}-G_i}|\cF_{\tau_{\cC}^{i}}]&\leqslant 1+C_2\sum_{k=i+1}^{n-1}c_k^2\rho^{k-i-1}\indiacc{\tau_{\cC}^{i}=i}\Ebb_x[\rho^{-2\sigma_{\cC}\circ\theta^{i}}\rme^{C_1\|c\|_{\infty}\sigma_{\cC}\circ\theta^{i}}|\cF_{\tau_{\cC}^{i}}]\eqsp.
 \end{align*}
 Now by Markov's property,
 %
\begin{align*}
\indiacc{\tau_{\cC}^{i}=i} \Ebb_x[\rho^{-2\sigma_{\cC}\circ\theta^{i}}\rme^{C_1\|c\|_{\infty}\sigma_{\cC}\circ\theta^{i}}|\cF_{\tau_{\cC}^{i}}]&=\indiacc{\tau_{\cC}^{i}=i} \Ebb_x[\rho^{-2\sigma_{\cC}\circ\theta^{i}}\rme^{C_1\|c\|_{\infty}\sigma_{\cC}\circ\theta^{i}}|\cF_{i}]\\
&=\indiacc{\tau_{\cC}^{i}=i}\Ebb_{X_i}[\rho^{-2\sigma_{\cC}}\rme^{C_1\|c\|_{\infty}\sigma_{\cC}}]\eqsp.
\end{align*}
Hence,
 \begin{align*}
 \Ebb_x[\rme^{G_{i+1}-G_i}|\cF_{\tau_{\cC}^{i}}]
 &=1+C_2\sum_{k=i+1}^{n-1}c_k^2\rho^{k-i-1}\indiacc{\tau_{\cC}^{i}=i}\Ebb_{X_i}[\rho^{-2\sigma_{\cC}}\rme^{C_1\|c\|_{\infty}\sigma_{\cC}}]\eqsp.
 \end{align*}
Let $\rho=r\vee u^{-1/4}$, $\varepsilon=\log u/(2C_1)$ and assume first that $\|c\|_{\infty}\leqslant \varepsilon$. By {\bf H$2$},
\[
\indiacc{\tau_{\cC}^{i}=i}\Ebb_{X_i}[\rho^{-2\sigma_{\cC}}\rme^{C_1\|c\|_{\infty}\sigma_{\cC}}]\leqslant \indiacc{\tau_{\cC}^{i}=i}\sup_{x\in\cC}\Ebb_x[\rho^{-2\sigma_{\cC}}\rme^{C_1\|c\|_{\infty}\sigma_{\cC}}]\leqslant\sup_{x\in\cC}\Ebb_x[u^{\sigma_{\cC}}]\leqslant M\enspace.
\]
Hence,
\[
 \Ebb_x[\rme^{G_{i+1}-G_i}|\cF_{\tau_{\cC}^{i}}]\leqslant 1+C_2M\sum_{k=i+1}^{n-1}c_k^2\rho^{k-i-1}\leqslant \rme^{C_2M\sum_{k=i+1}^{n-1}c_k^2\rho^{k-i-1}}\eqsp.
\]
By recurrence, it follows that
\begin{align*}
\Ebb_x\bigg[\rme^{f(\chunk[0]{X}[n-1])-\Ebb_x[f(\chunk[0]{X}[n-1])]}\bigg]&\leqslant \rme^{C_2M\sum_{i=0}^{n-2}\sum_{k=i+1}^{n-1}c_k^2\rho^{k-i-1}}\\
&=\rme^{C_2M\sum_{k=1}^{n-1}c_k^2\sum_{i=0}^{k-1}\rho^{k-i-1}}\leqslant \rme^{\frac{C_2M}{1-\rho}\|c\|^2} \eqsp.
\end{align*}
Fix $\tilde{x}$ in $\sX$ and let $\tilde{f} : \sX^n \rightarrow \Rbb$ be defined, for any $x_{0:n-1}$ in $\sX^n$, by
\[
\tilde{f}(\chunk[0]{X}[n-1])
=
f(x_0\mathbbm{1}_{\{c_{0}\leq\varepsilon\}} + \tilde{x} \mathbbm{1}_{\{c_{0}>\varepsilon\}},\dots, x_{n-1}\mathbbm{1}_{\{c_{n-1}\leq\varepsilon\}} + \tilde{x} \mathbbm{1}_{\{c_{n-1}>\varepsilon\}})
\eqsp .
\]
As $f$ belongs to $\mathbb{BD}\left(\sX^n,c\right)$, $\tilde{f}$ belongs to $ \mathbb{BD}\left(\sX^n,\tilde{c}\right)$, where
\[
\tilde{c}
=
\left( c_0\mathbbm{1}_{\{c_{0}\leq\varepsilon\}},\dots,c_{n-1}\mathbbm{1}_{\{c_{n-1}\leq\varepsilon\}}\right)
\eqsp .
\]
Since $\|\tilde{c}\|_{\infty} < \varepsilon$ and $\|\tilde{c}\|\leqslant \|c\|$, $\tilde{f}$ satisfies
\begin{align}\label{ineq:max-gamma-leq-varepsilon-ftilde}
\Ebb_{x}\left[\rme^{\tilde{f}(\chunk[0]{X}[n-1])-\Ebb_{x}[\tilde{f}(\chunk[0]{X}[n-1])]}\right]
& \leqslant
\rme^{\frac{MC_2}{1-\rho}
\| \tilde{c}\|^2} \leqslant
\rme^{\frac{MC_2}{1-\rho}
\| c\|^2}
\eqsp .
\end{align}
Furthermore, by definition of $\tilde{f}$ and since $f$ is in $\mathbb{BD}(\sX^n,c)$, for any $x\in\sX^n$,
\begin{align}\label{ineq:difference-f-tildef}
|f(x)-\tilde{f}(x)|
& =
%|f(x_0,\dots,x_{n-1})-f(x_0\mathbbm{1}_{\{\gamma_{0}\leq\varepsilon\}} + \tilde{x} \mathbbm{1}_{\{\gamma_{0}>\varepsilon\}},\dots, x_{n-1}\mathbbm{1}_{\{\gamma_{n-1}\leq\varepsilon\}} + \tilde{x} \mathbbm{1}_{\{\gamma_{n-1}>\varepsilon\}})|\\
%& \leq
\sum_{i=0}^{n-1} c_i \mathbbm{1}_{\{c_i>\varepsilon\}}
\leq
\sum_{i=0}^{n-1} c_i \frac{c_i}{\varepsilon}
\leq
\frac{\|c\|^2}{\varepsilon}.
\end{align}
This implies
\[
\Ebb_x\bigg[\rme^{f(\chunk[0]{X}[n-1])-\Ebb_x[f(\chunk[0]{X}[n-1])]}\bigg]\leqslant \rme^{\frac{2\|c\|^2}{\varepsilon}}\Ebb_{x}\left[\rme^{\tilde{f}(\chunk[0]{X}[n-1])-\Ebb_{x}[\tilde{f}(\chunk[0]{X}[n-1])]}\right]\leqslant \rme^{\bigg(\frac2{\varepsilon}+\frac{MC_2}{1-\rho}\bigg)
\| c\|^2}
\eqsp .
\]
This shows {\bf Fact 3} since
\[
\frac2{\varepsilon}+\frac{MC_2}{1-\rho}\leqslant \frac{4Ld}{(1-r\vee \lambda^{1/4})^2}\bigg(-\frac5{\log \lambda}+4MLd\bigg)\eqsp.
\]
\end{proof}

\noindent
{\bf Fact 3} proves that there exists a constant $C=2C_3$ such that, for any $c\in \Rbb^n$, $f\in \functionboundeddiff{\sX^n}{c}$ and $x\in \cC$,
\begin{equation}\label{ControlLaplace}
 \Ebb_x\bigg[\rme^{f(\chunk[0]{X}[n-1])-\Ebb_x[f(\chunk[0]{X}[n-1])]}\bigg]\leqslant \rme^{C\| c\|^2/2}
\eqsp .
\end{equation}
Let $f\in \functionboundeddiff{\sX^n}{c}$ and $x\in \cC$.
For any $s>0$, $sf\in \functionboundeddiff{\sX^n}{c}$.
Hence, from \eqref{ControlLaplace}, for any $s,t>0$,
\begin{align*}
 \Pbb\big(f(\chunk[0]{X}[n-1])-\Ebb_x[f(\chunk[0]{X}[n-1])]>t\big)&\leqslant \rme^{-st+\log\Ebb_x\big[\rme^{sf(\chunk[0]{X}[n-1])-\Ebb_x[sf(\chunk[0]{X}[n-1])]}\big]}\\
 &\leqslant \rme^{-st+s^2C\| c\|^2/2}\enspace.
\end{align*}
Choosing $s=t/(C\|c\|^2)$ proves Theorem~\ref{thm:ConcMarkQuant} with
\[
\beta=\frac1{2C}=\frac1{4C_3}=\frac{(1-r\vee \lambda^{1/4})^2}{16Ld}\bigg(-\frac5{\log \lambda}+4MLd\bigg)^{-1}\eqsp.
\]
\end{proof}

\section{Applications to Unadjusted Langevin Algorithm}\label{sec:ULA}
We illustrate the applicability of the results by the example on one of the MCMC methods. Suppose that we aim at sampling from the distribution with density $\pi(x) = \frac{e^{-U(x)}}{\int\limits_{\mathbb{R}^d} e^{-U(y)}\,dy}$. One of the popular algorithms for solving this problem is the Unadjusted Langevin Algorithm, which suggests constructing the Markov Chain
$$
X_{k+1} = h_{k+1}(X_k) + \sqrt{2\gamma_{k+1}}Z_{k+1}, h_{k+1}(X_k) := X_{k} - \gamma_{k+1}\nabla U(X_{k})
$$
with some non-increasing sequence $\gamma_k \geq 0$, where $Z_k \sim \mathcal{N}(0,I)$ are i.i.d. standard normal $d$-dimensional random variables. Let us denote ULA kernel with parameter $\gamma$ as $P_{\gamma}$, that is,
\begin{equation}
\label{eq:ula_kernel}
P_{\gamma}(x,dy) = \frac{1}{(4\pi\gamma)^{\frac{d}{2}}}\exp{\left(-\frac{\|y-x+\gamma\nabla U(x)\|^2}{4\gamma}\right)}\,dy
\end{equation}
Let us also introduce the multiple steps kernel
$$
Q^{p,n} = P_{\gamma_p}\ldots P_{\gamma_n}, Q^{n} := Q^{1,n}
$$
Standard assumptions on the sequence $\{\gamma_k\}$ are $\sum\limits_{k=0}^{\infty}\gamma_k = \infty$ and $\sum\limits_{k=0}^{\infty}\gamma_k^2 < \infty$. Thus it is impossible to analyze properties of additive functionals of $\{X_k\}$ by standard tools, since the assumptions {\bf H2} and {\bf H3} fails in case $\gamma_k \rightarrow 0$.  Yet we might establish some alternative bounds on the speed of convergence to stationary distribution. We need to impose condition
\par
[{\bf C1}] Potential $U(x)$ satisfies for all $x,y \in \mathbb{R}^d$ the condition
$$
\|U(x) - U(y)\| \leq L\|x-y\|
$$
This condition obviously implies
$$
\|h_{k}(X) - h_k(Y)\| \leq (1+L\gamma_k)\|X-Y\|
$$
Hence, by \cite[Theorem~19]{durmus:moulines:2018}, we might obtain the following minorization condition
\begin{lemma} Assume that the condition {\bf C1} holds. Then for all $x,y \in \mathbb{R}^d, n\geq 1$ it holds
$$
\|\delta_xQ^n - \delta_yQ^n\|_{TV} \leq \mathbb{I}(x \neq y)\left(1 - 2\Phi\left(-\frac{\|x-y\|}{2\sqrt{b_n}}\right)\right)
$$
where $b_n := \sum\nolimits_{i=1}^{k}\frac{\gamma_i}{\prod_{j=1}^{i}(1+L\gamma_j)^2}$
\end{lemma}
Now we aim at establishing Foster-Lyapunov drift conditions for the kernel $P_{\gamma_n}$.We will say that function $V(x): \mathbb{R}^d \rightarrow [1,+\infty)$ satisfies a Foster-Lyapunov drift condition for the Markov kernel $P_\gamma$ if. there are such $\overline{\gamma} > 0, \lambda \in [0,1), C > 0$ such that for any $\gamma \in (0, \overline{\gamma}]$ it holds
\begin{equation}
\label{eq:drift}
P_{\gamma}V \leq \lambda^{\gamma}V + \gamma C
\end{equation}
Given that this condition holds, we may prove drift condition for. the kernel $Q^n$.

\begin{lemma}
\label{lem:drift_prod}
 Assume that $P_{\gamma}$ satisfies condition \ref{eq:drift} for any $0 < \gamma < \overline{\gamma}$. Then it holds
$$
Q^{n,p}V \leq \lambda^{\Gamma_{p,n}}V + C\frac{\lambda^{\Gamma_{1,p}} - \lambda^{\Gamma_{1,n}}}{\log{\frac{1}{\lambda}}}
$$
\end{lemma}
\begin{proof} For notation simplicity let us consider only $p=1$. Then by induction
$$
Q^{n}V \leq \lambda^{\Gamma_{1,n}}V + C \sum\limits_{k=1}^{n}\gamma_k \lambda^{\Gamma_{1,k-1}} \leq \lambda^{\Gamma_{1,n}}V + C \int\limits_{0}^{\Gamma_{1,n}}\lambda^{x}\,dx \leq
$$
$$
\leq \lambda^{\Gamma_{1,n}}V + C\frac{1-\lambda^{\Gamma_{1,n}}}{\log{\frac{1}{\lambda}}}
$$
\end{proof}
Let us check that ULA kernel \ref{} satisfies the drift condition \label{eq:drift}. We will need additional assumption
\par
[{\bf C2}] There exists such constants $K_1 > 0$ and $m > 0$, such that for any $x \notin B(0,K_1)$ it holds
$$
\langle \nabla U(x), x \rangle \geq \frac{m}{2}\|x\|^2
$$
Another popular condition on the potential is strong convexity outside some euclidean ball:
\par
[{\bf C3}] There exist constants $K_1 > 0$ and $m > 0$ such that for any $x \notin B(0,K_1)$ and $y \in \mathbb{R}^d$, it holds $\langle D^2U(x)y,y\rangle \geq m\|y\|^2$. Moreover, there exists $M \geq 0$ such that for any $x \in \mathbb{R}^d$, $\|D^3U(x)\| \leq M$.
\par
Yet it is possible to show that assumption {\bf C3} and {\bf C1} imply {\bf C2} (see \cite[Lemma~14]{brosse:2018:diffusion}), so in the sequel we are going to work with the condition {\bf C2}. It allows us to prove the following result

\begin{lemma} Assume that the potential $U(x)$ satisfies conditions {\bf C1} and {\bf C2} and without loss of generality consider $\nabla U(0) = 0$. Then the kernel \ref{} satisfies drift condition \ref{eq:drift} for any $0 < \gamma < \overline{\gamma} = \frac{m}{4L^2}$ with drift function $V(x) = 1 + \|x\|^2$, constants $\lambda = \exp{-\left(\frac{m}{2}\right)}$, $C = 3K_1^2 + 2d + C_1$ for some absolute constant $C_1 > 0$.
\end{lemma}

\begin{proof} Consider $V(x) = 1 + \|x\|^2$, then
$$
P_{\gamma}V(x) = \int\limits_{\mathbb{R}^d}V(y)P_{\gamma}(x,dy) = \int\limits_{\mathbb{R}^d}(1+\|y\|^2)\frac{1}{(4\pi\gamma)^{\frac{d}{2}}}\exp{\left(-\frac{\|y-x+\gamma\nabla U(x)\|^2}{4\gamma}\right)}\,dy =
$$

$$
=1 + \frac{1}{(4\pi\gamma)^{\frac{d}{2}}}\int\limits_{\mathbb{R}^d}\|z + x - \gamma \nabla U(x)\|^2 \exp{\left(-\frac{\|z\|^2}{4\gamma}\right)}\,dz
$$
Let us first consider the case $x \notin B(0,K_1)$. Note that $\|z+x-\gamma \nabla U(x)\|^2 = \|z\|^2 + 2 \langle z, x - \gamma \nabla U(x) \rangle + \gamma^2 \|x - \gamma \nabla U(x)\|^2$ and the linear term vanishes after integration, moreover, for $Z \sim \mathcal{N}(0,2\gamma I_d$, it holds $\mathbb{E}\|Z\|^2 = 2\gamma d$. It remains to notice that due to {\bf C1} and {\bf C2}
$$
\|x - \gamma \nabla U(x) \|^2 = \|x\|^2 - 2\gamma \langle \nabla U(x), x\rangle + \gamma^2 \|\nabla U(x)\|^2 \leq
$$
$$
 \leq (1-\gamma m)\|x\|^2 + 2\gamma^2 L^2 \|x\|^2
$$
Thus, plugging everything into expression for $P_{\gamma}V$ and using $\gamma < \frac{m}{4L}$, we obtain
$$
P_{\gamma}V(x) \leq (1-\gamma m + 2\gamma^2 L^2)V(x) + 2\gamma d + (\gamma m - 2\gamma^2 L^2) \leq \exp^{-\frac{\gamma m}{2}}V(x) + 2\gamma d
$$
Now let $x \in B(0,K_1)$. Then simply using $\|x-\gamma \nabla U(x)\|^2 \leq 2(1+L\gamma)^2\|x\|^2$, we obtain
$$
P_{\gamma}V(x) \leq (1-\gamma m + 2\gamma^2 L^2)V(x) + \gamma\left((m - 2\gamma L^2)(1+\|x\|^2) + 2d + 2(1+L\gamma)^2\|x\|^d\right) \leq
$$

$$
\leq \exp^{-\frac{\gamma m}{2}}V(x) + \gamma(3K_1^2 + 2d + C_1)
$$
for some absolute constant $C_1$, which does not depend on $\gamma, d, x$.
\end{proof}

Now the geometric ergodicity result readily follows from \cite[Theorem~19.4.1]{douc:moulines:priouret:soulier:2018}, namely, the following lemma holds:

\begin{lemma} Let the potential $U(x), x \in \mathbb{R}^D$ satisfy conditions {\bf C1} and {\bf C2}. Then for $0 < \gamma < \overline{\gamma}=\frac{m}{4L^2}$, for any $x \in X$ it holds
$$
d_V(\delta_xQ^n_\gamma,\pi_\gamma) \leq C\rho^n\left(V(x) + \pi_\gamma(V)\right)
$$
with $V(x) = 1 + \|x\|^2$ and constants
$$
b = \gamma(3K_1^2 + 2D + C_1); \quad \overline{b} = b\exp^{-\frac{m\gamma}{2}} + d; \quad \varepsilon = 2\Phi\left(-\frac{\sqrt{d}(1+L\gamma)}{2\sqrt{\gamma}}\right); \quad
$$

$$
C = \left(1 + \exp^{-\frac{m\gamma}{2}}\right)\left(1+\frac{\overline{b}}{(1-\varepsilon)(1-\exp^{-\frac{m\gamma}{2}} - \frac{2b}{1+d})}\right);
$$

$$
\rho = \exp^{-\gamma\left(\frac{m}{2} - 2\frac{3K_1^2 + 2D + C_1}{d}\right)\frac{\log{(1-\varepsilon)}}{\log{(1-\varepsilon)} + \log{(\exp^{-\frac{m\gamma}{2}} + \frac{2b}{d+1})}}}
$$
for some $C_1 > 0$, which does not depend on $d, \gamma$ and $n$.
\end{lemma}

\begin{proof} Note that the condition {\bf C1} implies that the Markov kernel $Q^n_\gamma$ satisfies $(1,\varepsilon)$-Doeblin condition with $\varepsilon = 2\Phi\left(-\frac{\sqrt{d}(1+L\gamma)}{2\sqrt{\gamma}}\right)$. Together with drift condition {\bf C2} it allows to apply \cite[Theorem~19.4.1]{douc:moulines:priouret:soulier:2018} with appropriate constants.
\end{proof}

\bibliographystyle{plain}
\bibliography{BiblioSource}

\end{document}


\section{Jastrow Factors}
\label{sec:jastrow}

Jastrow factors are among the simplest and most effective ways of including
dynamical correlation in the trial many body wavefunction.  The resulting many body
wavefunction is expressed as the product of an antisymmetric (in the case
of Fermions) or symmetric (for Bosons) part and a correlating Jastrow factor
like so:
\begin{equation}
\Psi(\vec{R}) = \mathcal{A}(\vec{R}) \exp\left[J(\vec{R})\right]
\end{equation}

In this section we will detail the types and forms of Jastrow factor used
in QMCPACK.  Note that each type of Jastrow factor needs to be specified using
its own individual \texttt{jastrow} XML element.  For this reason, we have repeated the
specification of the \texttt{jastrow} tag in each section, with specialization for the
options available for that given type of Jastrow.

\subsection{One-body Jastrow functions}
\label{sec:onebodyjastrow}
The one-body Jastrow factor is a form that allows for the direct inclusion
of correlations between particles that are included in the wavefunction with
particles that are not explicitly part of it.  The most common example of
this are correlations between electrons and ions.

The Jastrow function is specified within a \texttt{wavefunction} element
and must contain one or more \texttt{correlation} elements specifying
additional parameters as well as the actual coefficients. Section
\ref{sec:1bjsplineexamples} gives examples of the typical nesting of
\texttt{jastrow}, \texttt{correlation}, and \texttt{coefficient} elements.

\subsubsection{Input Specification}

\begin{table}[h]
\begin{center}
\begin{tabular}{l c c c l }
\hline
\multicolumn{5}{l}{Jastrow element} \\
\hline
\bfseries name & \bfseries datatype & \bfseries values & \bfseries defaults  & \bfseries description \\
\hline
name & text &    & (required) & Unique name for this Jastrow function \\
type & text & One-body & (required) & Define a one-body function \\
function & text & Bspline & (required) & BSpline Jastrow \\
             & text & pade2 & & Pade form \\
             & text & \ldots & & \ldots \\
source & text & name & (required) & Name of attribute of classical particle set \\
print & text & yes / no & yes & Jastrow factor printed in external file?\\
  \hline
\multicolumn{5}{l}{elements}\\ \hline
& Correlation & & & \\ \hline
\multicolumn{5}{l}{Contents}\\ \hline
& (None)  & & &  \\ \hline
\end{tabular}
%\end{tabular*}
\end{center}
\end{table}

To be more concrete, the one-body Jastrow factors used to describe correlations
between electrons and ions take the form below
\begin{equation}
J1=\sum_I^{ion0}\sum_i^e u_{ab}(|r_i-R_I|)
\end{equation}
where I runs over all of the ions in the calculation, i runs over the electrons
and $u_{ab}$ describes the functional form of the correlation between them.
Many different forms of $u_{ab}$ are implemented in QMCPACK.  We will detail
two of the most common ones below.
\include{jastrow_one_body_spline}
\include{jastrow_one_body_pade}

\subsection{Two-body Jastrow functions}
The two-body Jastrow factor is a form that allows for the explicit inclusion
of dynamic correlation between two particles included in the wavefunction.  It
is almost always given in a spin dependent form so as to satisfy the Kato cusp
condition between electrons of different spins\cite{kato}.

 The two body Jastrow function is specified within a \texttt{wavefunction} element
and must contain one or more correlation elements specifying additional parameters
as well as the actual coefficients.  Section \ref{sec:2bjsplineexamples} gives
examples of the typical nesting of \texttt{jastrow}, \texttt{correlation} and
\texttt{coefficient} elements.

\subsubsection{Input Specification}

\begin{table}[h]
\begin{center}
\begin{tabular}{l c c c l }
\hline
\multicolumn{5}{l}{Jastrow element} \\
\hline
\bfseries name & \bfseries datatype & \bfseries values & \bfseries defaults  & \bfseries description \\
\hline
name & text &    & (required) & Unique name for this Jastrow function \\
type & text & Two-body & (required) & Define a one-body function \\
function & text & Bspline & (required) & BSpline Jastrow \\
print & text & yes / no & yes & Jastrow factor printed in external file?\\
  \hline
\multicolumn{5}{l}{elements}\\ \hline
& Correlation & & & \\ \hline
\multicolumn{5}{l}{Contents}\\ \hline
& (None)  & & &  \\ \hline
\end{tabular}
%\end{tabular*}
\end{center}
\end{table}

The two-body Jastrow factors used to describe correlations between electrons take the form
\begin{equation}
J2=\sum_i^{e}\sum_{j>i}^{e} u_{ab}(|r_i-r_j|)
\end{equation}

The most commonly used form of two body Jastrow factor supported by the code is a splined
Jastrow factor, with many similarities to the one body spline Jastrow.

\include{jastrow_two_body_spline}

\subsection{Long-ranged Jastrow factors}
While short-ranged Jastrow factors capture the majority of the benefit
for minimizing the total energy and the energy variance, long-ranged
Jastrow factors are important to accurately reproduce the short-ranged
(long wavelength) behavior of quantities such as the static structure
factor, and are therefore essential for modern accurate finite size
corrections in periodic systems.

Below two types of long-ranged Jastrow factors are described.  The
first (the k-space Jastrow) is simply an expansion of the one and/or
two body correlation functions in plane waves, with the coefficients
comprising the optimizable parameters.  The second type have few
variational parameters and use the optimized breakup method of Natoli
and Ceperley\cite{Natoli1995} (the Yukawa and Gaskell RPA Jastrows).

\subsubsection{Long-ranged Jastrow: k-space Jastrow}
The k-space Jastrow introduces explicit long-ranged dependence commensurate with the periodic supercell.  This Jastrow is to be used in periodic boundary conditions only.

The input for the k-space Jastrow fuses both one and two-body forms into a single element and so they are discussed together here.  The one- and two-body terms in the k-Space Jastrow have the form:
\begin{align}
  J_1 &= \sum_{G\ne 0}b_G\rho_G^I\rho_{-G} \\
  J_2 &= \sum_{G\ne 0}a_G\rho_G\rho_{-G}
\end{align}
Here $\rho_G$ is the Fourier transform of the instantaneous electron density:
\begin{align}
  \rho_G=\sum_{n\in electrons}e^{iG\cdot r_n}
\end{align}
and $\rho_G^I$ has the same form, but for the fixed ions. In both cases the coefficients are restricted to be real, though in general the coefficients for the one-body term need not be.  See section \ref{sec:feature_kspace_jastrow} for more detail.

Input for the k-space Jastrow follows the familar nesting of \texttt{jastrow-correlation-coefficients} elements, with attributes unique to the k-space Jastrow at the \texttt{correlation} input level.

\FloatBarrier
\begin{table}[h]
\begin{center}
\begin{tabularx}{\textwidth}{l l l l l l }
\hline
\multicolumn{6}{l}{\texttt{jastrow type=kSpace} element} \\
\hline
\multicolumn{2}{l}{parent elements:} & \multicolumn{4}{l}{\texttt{wavefunction}}\\
\multicolumn{2}{l}{child  elements:} & \multicolumn{4}{l}{\texttt{correlation}}\\
\multicolumn{2}{l}{attributes}  & \multicolumn{4}{l}{}\\
   &   \bfseries name     & \bfseries datatype & \bfseries values          & \bfseries default  & \bfseries description \\
   & \texttt{type}$^r$    &  text              & \textbf{kSpace}           &                    & Must be kSpace           \\
   & \texttt{name}$^r$    &  text              & \textit{anything}         & 0                  & Unique name for Jastrow \\
   & \texttt{source}$^r$  &  text              & \texttt{particleset.name} &                    & Ion particleset name\\
  \hline
\end{tabularx}
\end{center}
\end{table}
\FloatBarrier

\FloatBarrier
\begin{table}[h]
\begin{center}
\begin{tabularx}{\textwidth}{l l l l l l }
\hline
\multicolumn{6}{l}{\texttt{correlation} element} \\
\hline
\multicolumn{2}{l}{parent elements:} & \multicolumn{4}{l}{\texttt{jastrow type=kSpace}}\\
\multicolumn{2}{l}{child  elements:} & \multicolumn{4}{l}{\texttt{coefficients}}\\
\multicolumn{2}{l}{attributes}  & \multicolumn{4}{l}{}\\
   &   \bfseries name           & \bfseries datatype & \bfseries values  & \bfseries default  & \bfseries description \\
   & \texttt{type}$^r$          &  text              & \textbf{One-Body},\textbf{Two-Body}    &                     & Must be One-Body/Two-Body     \\
   & \texttt{kc}$^r$            &  real              & kc$\ge$ 0                                & 0.0                 & k-space cutoff in a.u. \\
   & \texttt{symmetry}$^o$      &  text              & crystal,isotropic,none                 & crystal             & Symmetry of coefficients\\
   & \texttt{spinDependent}$^o$ &  boolean           & yes,no                                 & no                  & \textit{No current function} \\
  \hline
\end{tabularx}
\end{center}
\end{table}
\FloatBarrier

\FloatBarrier
\begin{table}[h]
\begin{center}
\begin{tabularx}{\textwidth}{l l l l l l }
\hline
\multicolumn{6}{l}{\texttt{coefficients} element} \\
\hline
\multicolumn{2}{l}{parent elements:} & \multicolumn{4}{l}{\texttt{correlation}}\\
\multicolumn{2}{l}{child  elements:} & \multicolumn{4}{l}{\textit{None}}\\
\multicolumn{2}{l}{attributes}  & \multicolumn{4}{l}{}\\
   &   \bfseries name     & \bfseries datatype & \bfseries values  & \bfseries default   & \bfseries description \\
   & \texttt{id}$^r$      &  text              & \textit{anything} &     cG1/cG2         & Label for coeffs     \\
   & \texttt{type}$^r$    &  text              & \texttt{Array}    &   0                 & Must be Array \\
\multicolumn{2}{l}{body text}  & \multicolumn{4}{l}{}\\
   &                           & \multicolumn{4}{l}{The body text is a list of real values for the parameters.}     \\
  \hline
\end{tabularx}
\end{center}
\end{table}
\FloatBarrier

Additional information:
\begin{itemize}
  \item{It is normal to provide no coefficients as an initial guess.  The number of coefficients will be automatically calculated according to the k-space cutoff + symmetry and set to zero. }
  \item{Providing an incorrect number of parameters also results in all parameters being set to zero.}
  \item{There is currently no way to turn optimization on/off for the k-space Jastrow.  The coefficients are always optimized.}
  \item{Spin dependence is currently not implemented for this Jastrow.}
  \item{\texttt{kc}: Parameters with G vectors magnitudes less than \texttt{kc} are included in the Jastrow.  If \texttt{kc} is zero, it is the same as excluding the k-space term.}
  \item{\texttt{symmetry=crystal}: Impose crystal symmetry on coefficients according to the structure factor.}
  \item{\texttt{symmetry=isotropic}: Impose spherical symmetry on coefficients according to G-vector magnitude.}
  \item{\texttt{symmetry=none}: Impose no symmetry on the coefficients.}
\end{itemize}

\begin{lstlisting}[style=XML,caption=k-space Jastrow with one- and two-body terms.]
  <jastrow type="kSpace" name="Jk" source="ion0">
     <correlation kc="4.0" type="One-Body" symmetry="cystal">
        <coefficients id="cG1" type="Array">
        </coefficients>
     </correlation>
     <correlation kc="4.0" type="Two-Body" symmetry="crystal">
        <coefficients id="cG2" type="Array">
        </coefficients>
     </correlation>
  </jastrow>
\end{lstlisting}

\begin{lstlisting}[style=XML,caption=k-space Jastrow with one-body term only.]
  <jastrow type="kSpace" name="Jk" source="ion0">
     <correlation kc="4.0" type="One-Body" symmetry="cystal">
        <coefficients id="cG1" type="Array">
        </coefficients>
     </correlation>
  </jastrow>
\end{lstlisting}

\begin{lstlisting}[style=XML,caption=k-space Jastrow with two-body term only.]
  <jastrow type="kSpace" name="Jk" source="ion0">
     <correlation kc="4.0" type="Two-Body" symmetry="crystal">
        <coefficients id="cG2" type="Array">
        </coefficients>
     </correlation>
  </jastrow>
\end{lstlisting}

\subsubsection{Long-ranged Jastrows: Gaskell RPA and Yukawa forms}
\label{sec:twobodyjastrowlr}
\textbf{NOTE: The Yukawa and RPA Jastrows do not work at present
and are currently being revived.  Please contact the developers if
you are interested in using them.}

The exact Jastrow correlation functions contain terms which have a
form similar to the Coulomb pair potential.  In periodic systems
the Coulomb potential is replaced by an Ewald summation of the
bare potential over all periodic image cells.  This sum is often
handled by the optimized breakup method\cite{Natoli1995} and this
same approach is applied to the long-ranged Jastrow factors in QMCPACK.

There are two main long-ranged Jastrow factors of this type
implemented in QMCPACK: the Gaskell RPA\cite{Gaskell1961,Gaskell1962}
form and the Yukawa\cite{Ceperley1978} form.  Both of these forms
were used by Ceperley in early studies of the electron gas\cite{Ceperley1978},
but they are also appropriate starting points for general solids.

The Yukawa form is defined in real space.  It's long-range form is
formally defined as
\begin{align}
  u_Y^{PBC}(r) = \sum_{L\ne 0}\sum_{i<j}u_Y(\abs{r_i-r_j+L})
\end{align}
with $u_Y(r)$ given by
\begin{align}
  u_Y(r) = \frac{a}{r}\left(1-e^{-r/b}\right)
\end{align}
In QMCPACK a slightly more restricted form is used:
\begin{align}
  u_Y(r) = \frac{r_s}{r}\left(1-e^{-r/\sqrt{r_s}}\right)
\end{align}
here ``$r_s$'' is understood to be a variational parameter.

The Gaskell RPA form--which contains correct short/long range limits
and minimizes the total energy of the electron gas within the RPA--is
defined directly in k-space:
\begin{align}
  u_{RPA}(k) = -\frac{1}{2S_0(k)}+\frac{1}{2}\left(\frac{1}{S_0(k)^2}+\frac{4m_ev_k}{\hbar^2k^2}\right)^{1/2}
\end{align}
where $v_k$ is the Fourier transform of the Coulomb potential and
$S_0(k)$ is the static structure factor of the non-interacting
electron gas:
\[
  S_0(k) = \left.
  \begin{cases}
    1 &  k>2k_F \\
    \frac{3k}{4k_F}-\frac{1}{2}\left(\frac{k}{2k_F}\right)^3 & k<2k_F
  \end{cases}
  \right.
\]
When written in atomic units, RPA Jastrow implemented in QMCPACK has the
form
\begin{align}
  u_{RPA}(k) = \frac{1}{2N_e}\left(-\frac{1}{S_0(k)}+\left(\frac{1}{S_0(k)^2}+\frac{12}{r_s^3k^4}\right)^{1/2}\right)
\end{align}
Here ``$r_s$'' is again a variational parameter and $k_F\equiv(\tfrac{9\pi}{4r_s^3})^{1/3}$.

For both the Yukawa and Gaskell RPA Jastrows, the default value for $r_s$ is $r_s=(\tfrac{3\Omega}{4\pi N_e})^{1/3}$.

\FloatBarrier
\begin{table}[h]
\begin{center}
\begin{tabularx}{\textwidth}{l l l l l l }
\hline
\multicolumn{6}{l}{\texttt{jastrow type=Two-Body function=rpa/yukawa} element} \\
\hline
\multicolumn{2}{l}{parent elements:} & \multicolumn{4}{l}{\texttt{wavefunction}}\\
\multicolumn{2}{l}{child  elements:} & \multicolumn{4}{l}{\texttt{correlation}}\\
\multicolumn{2}{l}{attributes}  & \multicolumn{4}{l}{}\\
   &   \bfseries name        & \bfseries datatype & \bfseries values             & \bfseries default  & \bfseries description   \\
   & \texttt{type}$^r$       &  text              & \textbf{Two-Body}            &                    & Must be Two-Body   \\
   & \texttt{function}$^r$   &  text              & \textbf{rpa}/\textbf{yukawa} &                    & Must be rpa or yukawa   \\
   & \texttt{name}$^r$       &  text              & \textit{anything}            & RPA\_Jee            & Unique name for Jastrow \\
   & \texttt{longrange}$^o$  &  boolean           & yes/no                       & yes                & Use long-range part     \\
   & \texttt{shortrange}$^o$ &  boolean           & yes/no                       & yes                & Use short-range part    \\
\multicolumn{2}{l}{parameters}  & \multicolumn{4}{l}{}\\
   & \texttt{rs}$^o$         &  rs                & $r_s>0$                      & $\tfrac{3\Omega}{4\pi N_e}$ & Avg. elec-elec distance \\
   & \texttt{kc}$^o$         &  kc                & $k_c>0$                      & $2\left(\tfrac{9\pi}{4}\right)^{1/3}\tfrac{4\pi N_e}{3\Omega}$ & K-space cutoff\\
  \hline
\end{tabularx}
\end{center}
\end{table}
\FloatBarrier

\begin{lstlisting}[style=XML,caption=Two body RPA Jastrow with long- and short-ranged parts.]
<jastrow name=''Jee'' type=''Two-Body'' function=''rpa''>
</jastrow>
\end{lstlisting}

% J1 RPA (intended for electron-proton system)
%   source = particleset.name
%   function = RPA
%   name = anything [Jep]
%   rs = >0 [-1]
%   kc = >0 [-1]
%
% J2 RPA
%   attributes
%     function = yukawa or rpa
%     name = anything [RPA_Jee]
%     longrange = yes/no [yes]
%     shortrange = yes/no [yes]
%   parameters
%     rs = >0 [-1]  3\Omega/4\pi N_e
%     kc = >0 [-1]  2 (9\pi/4)^1/3 * 4\pi N_e/3\Omega

\subsection{Three-body Jastrow functions}
Explicit three-body correlations can be included in the wavefunction via the three-body Jastrow factor.
The three-body electron-electron-ion correlation function ($u_{\sigma\sigma'I}$) currently used in \qmcpack is identical to the one proposed in \cite{Drummond2004}:
\begin{eqnarray}
u_{\sigma\sigma'I}(r_{\sigma I},r_{\sigma'I},r_{\sigma\sigma'}) &= \sum_{\ell=0}^{M_{eI}}\sum_{m=0}^{M_{eI}}\sum_{n=0}^{M_{ee}}\gamma_{\ell mn} r_{\sigma I}^\ell r_{\sigma'I}^m r_{\sigma\sigma'}^n \\
   &\times \left(r_{\sigma I}-\frac{r_c}{2}\right)^3 \Theta\left(r_{\sigma I}-\frac{r_c}{2}\right) \nonumber \\
   &\times \left(r_{\sigma' I}-\frac{r_c}{2}\right)^3 \Theta\left(r_{\sigma' I}-\frac{r_c}{2}\right) \nonumber
\end{eqnarray}
Here $M_{eI}$ and $M_{ee}$ are the maximum polynomial orders of the
electron-ion and electron-electron distances, respectively,
$\{\gamma_{\ell mn}\}$ are the optimizable parameters (modulo
constraints), $r_c$ is a cutoff radius, and $r_{ab}$ are the distances
between electrons or ions $a$ and $b$. i.e. The correlation function
is only a function of the interparticle distances and not a more
complex function of the particle positions, $\mathbf{r}$. As indicated by the
$\Theta$ functions, correlations are set to zero beyond a distance of
$r_c/2$ in either of the electron-ion distances and the largest
meaningful electron-electron distance is $r_c$.  This is the
highest-order Jastrow correlation function currently implemented.

Today, solid state applications of \qmcpack usually utilize one and
two-body B-spline Jastrow functions, with calculations on heavier
elements often also using the three-body term described above.

\paragraph{Example use case}
Here is an example of H2O molecule. After optimizing one and two body Jastrow factors, add the following block in the wavefunction.
The coefficients will be filled zero automatically if not given.
\begin{lstlisting}[style=XML]
<jastrow name="J3" type="eeI" function="polynomial" source="ion0" print="yes">
  <correlation ispecies="O" especies="u" isize="3" esize="3" rcut="10">
    <coefficients id="uuO" type="Array" optimize="yes"> </coefficients>
  </correlation>
  <correlation ispecies="O" especies1="u" especies2="d" isize="3" esize="3" rcut="10">
    <coefficients id="udO" type="Array" optimize="yes"> </coefficients>
  </correlation>
  <correlation ispecies="H" especies="u" isize="3" esize="3" rcut="10">
    <coefficients id="uuH" type="Array" optimize="yes"> </coefficients>
  </correlation>
  <correlation ispecies="H" especies1="u" especies2="d" isize="3" esize="3" rcut="10">
    <coefficients id="udH" type="Array" optimize="yes"> </coefficients>
  </correlation>
</jastrow>
\end{lstlisting}


\section{Preliminaries} \label{gua:sec:prelim}\label{gua:sec:definitions}
Many definitions intersect with those defined in previous chapters,
but to keep the chapter self-contained we define them here.

Notation:
$\bbB = \{\true,\false\}$ is the set of Boolean values,
$\bbN$ is the set of natural numbers (excluding $0$),
$\bbN_0 = \bbN\cup\{0\}$,
$[k]$ is the set $\{i \in \bbN \| i \leq k\}$
and $[0..k]$ is the set $[k] \cup \{0\}$ for $k \in \bbN$.
For a sequence $x=x_1x_2\ldots$ denote the $i$-$j$-subsequence as $x\slice{i}{j}$,
i.e., ${x\slice{i}{j}}=x_i \ldots x_j$.

\subsection{System Model} \label{gua:sec:model}

We consider systems $A {\parallel} B^n$, usually written $\largesys$,
consisting of
one copy of a process template $A$ and $n$ copies of a process template $B$,
in an interleaving parallel composition.%
%% AK: moved to a separate note, to be able to explain why we _cannot_ generalize for 1-conj
%\footnote{As shown in \cite{Emerson00}, cutoffs for this case generalize to cutoffs
%          for systems of the form $A^m {\parallel} B^n$, and further
%          to systems with an arbitrary number of process templates
%          $U_1^{n_1} {\parallel} \ldots {\parallel} U_m^{n_m}$.}
We distinguish objects that belong to different templates by indexing them with
the template. E.g., for process template $U \in \{A,B\}$, $Q_U$ is the set of
states of $U$. For this section, fix two disjoint finite sets $Q_A$, $Q_B$ as
sets of states of process templates $A$ and $B$, and a positive integer $n$.

\parbf{Processes} A \emph{process template}
 is a transition system
  $U=(\stateset, \init, \inputs, \delta)$ with
	\begin{itemize}
	\item $\stateset$ is a finite set of states including the
  initial state $\init$,
	\item $\inputs$ is a finite input alphabet,
	\item $\delta: \stateset \times \inputs \times \mP(Q_A \cupdot Q_B) \times \stateset$ is a guarded transition relation.
	\end{itemize}
A process template is \emph{closed} if $\inputs = \emptyset$, and otherwise \emph{open}.

By $\transition{q_i}{q_j}{e:g}$
we denote a process transition from $q_i$ to $q_j$
for input $e \in \Sigma$ and guarded by guard $g \in \mP(Q_A \cupdot Q_B)$.
We skip the input $e$ and guard $g$
if they are not important or can be inferred from the context.

We define the size $\card{U}$ of a process template $U \in \{A,B\}$ as $\card{\stateset_U}$. A copy of a template $U$ will be called a \emph{$U$-process}.
Different $B$-processes are distinguished by subscript, i.e., for $i \in [1..n]$, $B_i$ is the $i$th copy of $B$, and $\state_{B_i}$ is a state of $B_i$. A state of the $A$-process is denoted by $q_A$.

For the rest of this subsection, fix templates $A$ and $B$. We assume that $\inputs_A \cap \inputs_B = \emptyset$. We will also write $p$ for a process in $\{ A, B_1, \ldots, B_n\}$, unless $p$ is specified explicitly.
We often denote the set $\{B_1,...,B_n\}$ as $\mB$.

\parbf{Disjunctive and conjunctive systems}
In a system $\largesys$,
consider the global state $s = (\state_A,\state_{B_1},\ldots,\state_{B_n})$ and
global input $e=(\localin_A,\localin_{B_1},\ldots,\localin_{B_n})$.
We write $s(p)$ for $q_p$, and $e(p)$ for $\sigma_p$.
A local transition $(\state_p,\localin_p,g,\state_p') \in \delta_U$ of a process $p$ is \emph{enabled for $s$ and $e$}
if the \emph{guard} $g$ is satisfied by the state $s$ wrt.\ the process $p$, written $(s,p) \models g$ (defined below).
The semantics of $(s,p) \models g$ differs for disjunctive and conjunctive systems:
%
\begin{align*}
\text{In disjunctive systems: } & (s,p) \models g \text{~~~iff~~~}
\exists p' \in \{A,B_1,\ldots,B_n\} \setminus \{p\}:\ \ \state_{p'} \in g. \\
\text{In conjunctive systems: } & (s,p) \models g \text{~~~iff~~~}
\forall p' \in \{A,B_1,\ldots,B_n\} \setminus \{p\}:\ \ \state_{p'} \in g.
\end{align*}

Note that we check containment in the guard (disjunctively or conjunctively)
only for local states of processes \emph{different from} $p$. A process is \emph{enabled} for $s$ and $e$ if at least one of its transitions is enabled for $s$ and $e$, otherwise it is \emph{disabled}.

Like Emerson and Kahlon~\cite{Emerson00},
we assume that in conjunctive systems $\init_A$ and $\init_B$ are contained in all guards,
i.e., they act as neutral states.
Furthermore, we call a conjunctive system \emph{$1$-conjunctive} if every guard is of the form $(Q_A \cupdot Q_B) \setminus \{q\}$ for some $q \in Q_A\cupdot Q_B$.

Then, \largesys is defined as the transition
system $(S,\init_S,\globIn,\delta)$ with
\begin{itemize}
\item set of global states $S = \stateset_A \times \stateset_B^{n}$,
\item global initial state $\init_S = (\initstate_A,\initstate_B,\ldots,\initstate_B)$,
\item set of global inputs $\globIn = (\inputs_A) \times (\inputs_B)^{n}$,
\item and global transition relation $\delta \subseteq S \times \globIn \times S$ with $(s,e,s') \in \delta$ iff
\begin{enumerate}[label=\roman*)]
  \item $s=(\state_A,\state_{B_1},\ldots,\state_{B_n})$,
  \item $e=(\localin_A, \localin_{B_1},\ldots,\localin_{B_n})$, and
  \item $s'$ is obtained from $s$ by replacing one local state $\state_p$ with a new local state $\state_p'$, where $p$ is a $U$-process with local transition $(\state_{p},\localin_{p},g,\state_p') \in \delta_U$ and $(s,p) \models g$.
        Thus, we consider so-called interleaved systems,
        where in each step exactly one process transits.
\end{enumerate}
\end{itemize}
We say that a system $\largesys$ is \emph{of type} $(A,B)$. It is called a
\emph{conjunctive system} if guards are interpreted conjunctively, and a
\emph{disjunctive system} if guards are interpreted disjunctively.
A system is \emph{closed} if all of its templates are closed.

\parbf{Runs}
A \emph{configuration} of a system is a triple $(s,e,p)$, where $s \in S$, $e
\in \globIn$, and $p$ is either a system process, or the special symbol $\bot$.
 A \emph{path} of a system is a configuration sequence
$x = (s_1,e_1,p_1),(s_2,e_2,p_2),\ldots$ such that, for all $\time < |x|$, there is a
transition $(s_\time,e_\time,s_{\time+1}) \in \delta$ based on a local
transition of process $p_\time$. We say that process
$p_\time$ \emph{moves} at \emph{moment} $\time$.
Configuration $(s,e,\bot)$ appears
 iff all processes are disabled for $s$ and $e$.
Also, for every $p$ and $\time < |x|$:
either $e_{\time+1}(p) = e_\time(p)$ or process $p$ moves at moment $\time$.
That is, the environment keeps the input to each process unchanged until
the process can read it.\footnote{By only considering inputs that are actually processed, we
approximate an
action-based semantics. Paths that do not fulfill this requirement are not
very interesting, since the environment can violate any interesting
specification that involves input signals by manipulating them when the
corresponding process is not allowed to move.}

A system \emph{run} is a maximal path starting in the initial state. Runs are either infinite, or they end in a configuration $(s,e,\bot)$. We say that a run is \emph{initializing} if every
%$B$-process
process
that moves infinitely often also visits
%$\initstate_B$
its $\initstate$
infinitely often.

Given a system path $x = (s_1,e_1,p_1),(s_2,e_2,p_2),\ldots$ and a process $p$, the \emph{local path} of $p$ in $x$ is the projection $x(p) = (s_1(p),e_1(p)),(s_2(p),e_2(p)),\ldots$ of $x$ onto local states and inputs of $p$.
Similarly, we define the projection on two processes $p_1,p_2$ denoted by $x(p_1,p_2)$.

%The \emph{destuttering} $\destutter(x)$\ak{make it work with inf runs} of a (local) path \sj{local path not defined} $x=x_0,x_1,\ldots$ is obtained by removing stuttering steps from the sequence, i.e., $\destutter(x)$ is the maximal subsequence $x'$ of $x$ such that for every $\time$ we have $x'_\time \neq x'_{\time+1}$. Two (local) paths $x$ and $y$ are \emph{stutter-equivalent}, written $x \simeq y$, if $\destutter(x)=\destutter(y)$. Define an extension of $\destutter$ to sets of paths in the obvious way. Then two systems $S_1, S_2$ are \emph{stutter-equivalent}, written $S_1 \simeq S_2$, if $\destutter(X_1) = \destutter(X_2)$, where $X_i$ is the set of all infinite runs of system $S_i$.

\parbf{Deadlocks and fairness}
A run is \emph{globally deadlocked} if it is finite.
An infinite run is \emph{locally deadlocked} for process $p$ if there exists $\time$ such that $p$ is disabled for all $s_{\time'},e_{\time'}$ with $\time'\ge \time$. A run is \emph{deadlocked} if it is locally or globally deadlocked.
A system \emph{has a (local/global) deadlock} if it has a (locally/globally) deadlocked run. Note that the absence of local deadlocks for all $p$ implies the absence of global deadlocks, but not the other way around.

A run $(s_1,e_1,p_1), (s_2,e_2,p_2),...$ is \emph{unconditionally-fair} if every process moves infinitely often.
A run is \emph{strong-fair} if it is infinite and, for every process $p$, if $p$ is enabled infinitely often, then $p$ moves infinitely often.
%\sj{weak fairness needed?} Finally, $x$ is \emph{weak-fair} if it is infinite and for every process $p$, if there exists $t$ such that $p$ is enabled for every $s_{\time'}, e_{\time'}$ with $\time' \ge \time$, then $p$ moves infinitely often.
We will discuss the role of deadlocks and fairness in synthesis in Section~\ref{gua:sec:paramsynt}.

\begin{remark}[$A^m {\parallel} B^n$]
One usually starts with studying parameterized systems of the form $A^n$ (having one process template),
then proceeds to systems of the form $A^m {\parallel} B^n$ (having two templates)
and $U_1^{n_1} {\parallel} \ldots {\parallel} U_m^{n_m}$ (having an arbitrary fixed number of templates).
Our work studies systems $A {\parallel} B^n$,
which have one $A$-process and a parameterized number of $B$-processes,
because the results for such systems can be generalized to systems $U_1^{n_1} {\parallel} \ldots {\parallel} U_m^{n_m}$
(see~\cite{Emerson00} for details).
This generalization works for our results as well,
except for the cutoffs for deadlock detection that are restricted to 1-conjunctive systems of the form $A\parallel B^n$
(Section~\ref{gua:sec:cutoffs}).
\end{remark}

\subsection{Specifications}
\label{gua:sec:semantics}
Fix templates $(A,B)$.
We consider formulas in $\LTLmX$---$\LTL$ without the next-time operator $\nextt$---%
that are prefixed by path quantifiers $\E$ or $\A$
(for LTL and path quantifiers see Section~\ref{defs:ctlstar}).
Let $h(A,B_{i_1},\ldots,B_{i_k})$ be an $\LTLmX$ formula over atomic propositions from $Q_A \cup \Sigma_A$ and indexed propositions from $(Q_B \cup \Sigma_B) \times \{i_1,\ldots,i_k\}$.
For a system $\largesys$ with $n \geq k$ and every $i_j \in [1..n]$,
satisfaction of $\A h(A,B_{i_1},\ldots,B_{i_k})$ and $\E h(A,B_{i_1},\ldots,B_{i_k})$ is defined in the usual way.

\parbf{Parameterized specifications} \label{gua:sec:parameterized}
A \emph{parameterized specification} is a temporal logic formula
with indexed atomic propositions and quantification over indices.
We consider formulas of the forms
$\forall{i_1,\ldots,i_k.} \A h(A,B_{i_1},\ldots,B_{i_k})$ and\\
$\forall{i_1,\ldots,i_k.} \E h(A,B_{i_1},\ldots,B_{i_k})$.
For a given $n \geq k$,
$$
\largesys \models \forall{i_1,{\ldots},i_k.} \A h(A,B_{i_1},{\ldots},B_{i_k})
$$
~iff~
$$
\largesys \models \!\!\!\!\!\!\!\!\bigwedge_{j_1 \neq {\ldots} \neq j_k \in [1..n]}\!\!\!\!\!\!\!\!\A h(A,B_{j_1},{\ldots},B_{j_k}).
$$
By symmetry of guarded systems (see~\cite{Emerson00}),
the second formula is equivalent to
$\largesys \models \A h(A,B_1,\ldots,B_k)$.
The formula $\A h(A,B_1,\ldots,B_k)$ is denoted by $\A h(A,B^{(k)})$,
and we often use it instead of the original $\forall{i_1,\ldots,i_k.} \A h(A,B_{i_1},...,B_{i_k})$.
For formulas with the path quantifier $\E$,
satisfaction is defined analogously
and is equivalent to satisfaction of $\E h(A,B^{(k)})$.
\begin{example}
Consider the formula
$$
\forall{i_1,i_2}.\A \big(\G (r_{i_1} \impl \F g_{i_1}) \land \G \neg (g_{i_1} \land g_{i_2})\big).
$$
By our definition, its satisfaction by a system $(A,B)^{(1,3)}$ means
\begin{align*}
(A,B)^{(1,3)} \models
\A \left(
\begin{aligned}
&\G(r_1 \impl \F g_1) \land \G(r_2 \impl \F g_2) \land \G(r_3 \impl \F g_3) \land \\
&\G \neg (g_1 \land g_2) \land \G \neg (g_1 \land g_3) \land \G \neg (g_2 \land g_3)
\end{aligned}
\right),
\end{align*}
where $g_1$ and $r_1$ refer to the propositions $g$ and $r$ of the process $B_1$,
$g_2$ and $r_2$ belong to $B_2$, and so on.
By symmetry, the latter satisfaction is equivalent to
\begin{align*}
(A,B)^{(1,3)} \models
\A \left(
\begin{aligned}
&\G(r_1 \impl \F g_1) \land \G(r_2 \impl \F g_2) \land \\
&\G \neg (g_1 \land g_2)
\end{aligned}
\right).
\end{align*}
Note that this formula talks about processes $B_1$ and $B_2$, but does not mention $B_3$.
\end{example}

\parbf{Specification of fairness and local deadlocks}
It is often convenient to express fairness assumptions and local deadlocks
as parameterized specifications.
To this end,
define auxiliary atomic propositions $\sched_p$ and $\enabled_p$ for every process $p$ of system $(A,B)^{(1,n)}$. At moment $\time$ of a given run $(s_1,e_1,p_1),(s_2,e_2,p_2), \ldots$, let $\sched_p$ be true whenever $p_\time = p$, and let $\enabled_p$ be true if $p$ is enabled for $s_\time, e_\time$. Note that we only allow the use of these propositions to define fairness, but not in general specifications.
Then, an infinite run is
\begin{itemize}
\item \emph{local-deadlock-free} if it satisfies $\forall{p}. \GF \enabled_p$, abbreviated as $\spec_{\neg dead}$,
\item \emph{strong-fair} if it satisfies $\forall{p}. \GF \enabled_p \impl \GF \sched_p$, abbreviated as $\spec_{strong}$, and
\item \emph{unconditionally-fair} if it satisfies $\forall{p}. \GF \sched_p$, abbreviated as $\spec_{uncond}$.
%\item \sj{needed?:}\emph{weak-fair} if it satisfies $\forall{p}. \A \spec_{weak}$, where $\spec_{weak} = \FG \enabled_p \impl \GF \sched_p$.
\end{itemize}

If $f \in \{strong, uncond\}$ is a fairness notion and
$\A h(A,B^{(k)})$
a specification, then we write
$\A_{f} h(A,B^{(k)})$ for $\A (\spec_{f}
\rightarrow h(A,B^{(k)}))$.
Similarly, we write $\E_{f} h(A,B^{(k)})$ for $\E (\spec_{f} \land h(A,B^{(k)}))$.

\subsection{Model Checking and Synthesis Problems}
\label{gua:sec:nonparameterized_synthesis}
%
Given a system $\largesys$ and a specification $\A h(A,B^{(k)})$, where $n \ge k$. Then:
\begin{itemize}
\item the \emph{model checking problem} is to decide whether $\largesys \models \A h(A,B^{(k)})$,
\item the \emph{deadlock detection problem} is to decide whether $\largesys$
      does not have global nor local deadlocks,
%\item the \emph{deadlock detection problem} is to decide whether all runs of $\largesys$
%are infinite and $\largesys \models \A \spec_{\neg dead}$,
%i.e., there are no local deadlocks,
\item the \emph{parameterized model checking problem} (PMCP) is to decide whether $\forall m \ge n:\ (A,B)^{(1,m)} \models \A h(A,B^{(k)})$, and
%\item the \emph{parameterized deadlock detection problem} is to decide whether for all $m \ge n$, all runs of $(A,B)^{(1,m)}$ are infinite and $(A,B)^{(1,m)} \models \A \spec_{\neg dead}$.
\item the \emph{parameterized deadlock detection problem} is to decide whether,
      for all $m \ge n$, $(A,B)^{(1,m)}$ does not have global nor local deadlocks.
\end{itemize}
For a given number $n \in \bbN$ and specification $\A h(A,B^{(k)})$ with $n \ge k$,
\begin{itemize}
\item the \emph{template synthesis problem} is to find process templates $A,B$ such that
$\largesys \models \A h(A,B^{(k)})$ and $\largesys$ does not have global deadlocks\footnote{\label{footnote:local-deadlocks}Here we do not explicitly mention local deadlocks because they can be specified as a part of $\A h(A,B^{(k)})$.}
\item
the \emph{bounded template synthesis problem} for a pair of bounds $(\bound_A,\bound_B) \in \bbN \times \bbN$
is to solve the template synthesis problem with
$\card{A} \leq \bound_A$ and $\card{B} \leq \bound_B$.
\item the \emph{parameterized template synthesis problem} is to find process templates $A,B$ such that $\forall m \ge n:\ (A,B)^{(1,m)} \models \A h(A,B^{(k)})$ and $(A,B)^{(1,m)}$ does not have global deadlocks\footnoteref{footnote:local-deadlocks}.
\end{itemize}
Similarly, we define problems for specifications having $\E$ instead of $\A$.
The definitions can be flavored with different notions of fairness.


\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{quantikz}
\usepackage{physics}
\usepackage{pgfplots}
\usepgfplotslibrary{units}
\usetikzlibrary{patterns}
\usepackage{siunitx}
\usetikzlibrary{angles, quotes}
\usepackage{amssymb}
\usetikzlibrary{angles, arrows.meta, quotes}
\pgfplotsset{compat=1.17}

\usepackage{minted}
\usepackage[most]{tcolorbox}
\definecolor{lightgreen}{rgb}{0.56, 0.93, 0.56}
\definecolor{moonstoneblue}{rgb}{0.45, 0.66, 0.76}

\newtcblisting{myminted}{%
    listing engine=minted,
    minted language=c,
    listing only,
    breakable,
    enhanced,
    minted options = {
        linenos,
        breaklines=true,
        breakbefore=.,
        fontsize=\footnotesize,
        numbersep=2mm
    },
    overlay={%
        \begin{tcbclipinterior}
            \fill[gray!25] (frame.south west) rectangle ([xshift=4mm]frame.north west);
        \end{tcbclipinterior}
    }
}
\begin{document}
	\title{

	\vspace{1cm}
	\Huge Grover's Algorithm
	}

	\vspace{1cm}

	% if you are the only author, you might use the following
	% \author{Name of student}

	% Insert here your name and correct mail address
	\author{\Large {Rahul Goel} \Large \\  \ \ 2019111034
	\date{November 2020}
	\vspace{0.5cm}}

	% name of the course and module
	\date{
	\large Algorithm Analysis And Design \\
	\vspace{1cm}
	}

	\maketitle
	\setlength{\parindent}{0pt}

\vspace{8cm}
\begin{abstract}
\begin{center}
\normalsize
This document can be used as an introductory tutorial to Grover's Algorithm. It also includes certain peculiar observations that help to deepen the understanding about the differences between Quantum Computing and Classical Computing.
\end{center}
\end{abstract}
	\newpage
	\tableofcontents
	\newpage

\maketitle

\textbf{Note - It has been assumed that $N = 2 ^ n$ throughout this sheet.}

\section{The Problem - Needle in a Haystack}
\indent The problem that Grover's Algorithm solves is the unstructured search problem. In simple words, among $N$ given entities, our task is to find one unique entity that satisfies a particular property.

In most cases, the situation is random and the only way a classical computer knows how to solve it is by brute force. This can take $O(N / 2)$ on average and up to $O(N)$ time in the worst case.

The problem of unstructured search is considered to be a hard problem for a classical computer as $N$ gets bigger in size. Grover's Algorithm provides a quadratic speedup to this and reduces the number of queries (time taken) to $O(\sqrt{N})$. In fact, it has been proven that for a quantum computer, this is the best possible time complexity.

Note - The problem gets easier and the complexity gets reduced by a constant factor when the entities that satisfy the property are more in number.

\section{How the Algorithm works}
\subsection{Intution 1}
Initially, we start with $n$ qubits in such a way that in their superposition, all the $N$ states have equal amplitude (each has an equal probability of popping up when we measure the state).
$$\ket{\psi_{initial}} = \sum_{0}^{N-1} {\alpha_i}\ket{i} \text{ where } \alpha_i = \frac{1} {\sqrt{N}}$$

Let $\ket{j}$ be our needle in the haystack.
Now, by means of certain quantum gates, the amplitude $\alpha_j$ is first negated i.e. it becomes $-\alpha_j$. And then every single $\alpha_i$ is flipped about the mean of all amplitudes. As a result, $\alpha_j$ stands out more than every other $\alpha_i$.
\\[3cm]
\indent This has been explained by means of the following diagrams (Not to scale).
Initially the amplitudes of all the states are equal and the sum of their squares is equal to $1$.

\begin{tikzpicture}
\begin{axis}[ybar interval, ymax=0.8,ymin=-0.5, minor y tick num = 1, xmax = 8]
\addplot coordinates { (0, 0.353) (1, 0.353) (2, 0.353) (3, 0.353) (4, 0.353) (5, 0.353) (6, 0.353) (7,0.353)};
\draw [dashed] (0,0.353) -- (7, 0.353);

\end{axis}
\end{tikzpicture}

Then a quantum circuit is applied to the state which flips the amplitude of the desired state.

\begin{tikzpicture}
\begin{axis}[ybar interval, ymax=0.8,ymin=-0.5, minor y tick num = 1, xmax = 8]
\addplot coordinates { (0, 0.353) (1, 0.353) (2, -0.353) (3, 0.353) (4, 0.353) (5, 0.353) (6, 0.353) (7,0.353)};
\draw [dashed] (0,0.3) -- (7, 0.3);
\end{axis}
\end{tikzpicture}

Now the inversion of one of the amplitudes results in a slight decrement of the mean of all the amplitudes. If we now flip the amplitudes about their mean, we land up in the following state.

\begin{tikzpicture}
\begin{axis}[ybar interval, ymax=0.8,ymin=-0.5, minor y tick num = 1, xmax = 8]
\addplot coordinates { (0, 0.25) (1, 0.25) (2, 0.65) (3, 0.25) (4, 0.25) (5, 0.25) (6, 0.25) (7,0.25)};
\draw [dashed] (0,0.3) -- (7, 0.3);
\end{axis}
\end{tikzpicture}

The amplitude of the needle in the haystack has increased and hence if we measure the state now, the chance of getting the correct value is more than it was previously. However, the sum of probabilities of getting other states is still greater than the probability of getting the answer.\\[4pt]

Hence, we repeat the negation and inversion steps a number of times so that when we measure the state, we can be pretty sure that the outcome is the answer (the desirable state).\\[4pt]

Initially $\alpha_j = \dfrac{1}{\sqrt{N}}$. As we run iterations of the algorithm, $\alpha_j$ increases and $\alpha_i$, $\forall$ $i \neq j$, decreases, all in such a way that $\sum_0 ^{N-1} {\alpha_i}^2 = 1$.
If we want the probability of getting $\ket{j}$ to be at least half, we need to pump up the magnitude $\alpha_j$ to $\dfrac{1}{\sqrt{2}}$. At the point in time when $\alpha_j = \dfrac{1}{\sqrt{2}}$, $\alpha_i \approx \dfrac{1}{\sqrt{2N}}$ $\forall$ $i \neq j$. Because the amplitude of the other states decreases continuously, we can say that throughout our iterations $\alpha_i \geq \dfrac{1}{\sqrt{2N}}$. Since in one iteration, the amplitude $\alpha_j$ increases by at least by $2 \alpha_i$ $\left( i \neq j\right)$, the increment is at least $\sqrt{\dfrac{2}{N}}$. Therefore the number of iterations required is at least $\dfrac{1 / \sqrt{2}}{\sqrt{2 / N}}$ $=$ $\sqrt{N}$.\\
When the number of favourable states is $M$, the number of iterations comes out to be $\sqrt{\dfrac{N}{M}}$.

\subsection{Intution 2}

Let $\ket{a}$ represent our desirable state i.e. $\ket{j}$. And $\ket{b}$ represent the superposition of all the remaining states with equal amplitudes i.e. $\ket{b} = \sum_{i \neq j} \dfrac{1}{\sqrt{N - 1}} \ket{i}$. It can be easily noticed that $\ket{a}$ and $\ket{b}$ are orthogonal to each other. Let $\psi_0$ be our initial state which is $\sum_{0}^{N - 1} \dfrac{1}{\sqrt{N}} \ket{i}$. Now initially $\ket{\psi_0}$ lies really close to $\ket{b}$ and it is the task of Grover's Algorithm to move it closer to $\ket{a}$.\\[4pt]

\begin{tikzpicture}[
            > = Straight Barb,
phasor/.style = {very thick,-{Stealth}},
angles/.style = {draw, <->, angle eccentricity=1,
                 right, angle radius=15mm}
                        ]
% coordinates
    \draw[->, thick] (-0.5,0) -- (4,0) coordinate (x) node[below left] {$\ket{b}$};
    \draw[->, thick] (0,-0.5) -- (0,4) node[below left] (y) {$\ket{a}$};
% phasors
    \draw[phasor] (0,0) -- (15:4) coordinate (i)  node[right] {$\psi_0$};% used polar coordinates
% angles drawn by pic
\coordinate (X)   at (0,0);
\draw
    pic["$\theta$",angles] {angle=x--X--i}
    ;
\end{tikzpicture}

The amplitude negation step leads to reflection of $\ket{\psi_0}$ about $\ket{b}$. This is true because $\ket{b}$ represents the superposition of all the undesirable states of equal amplitude. So the projection of $\ket{\psi_0}$ on $\ket{b}$ will remain as it is while the projection of $\ket{\psi_0}$ perpendicular to $\ket{b}$ will get negated. This is nothing but reflection about $\ket{b}$.

\begin{tikzpicture}[
            > = Straight Barb,
phasor/.style = {very thick,-{Stealth}},
angles/.style = {draw, <->, angle eccentricity=1,
                 right, angle radius=15mm}
                        ]
% coordinates
    \draw[->, thick] (-0.5,0) -- (4,0) coordinate (x) node[below left] {$\ket{b}$};
    \draw[->, thick] (0,-0.5) -- (0,4) node[below left] (y) {$\ket{a}$};
% phasors
    \draw[phasor, dotted] (0,0) -- (15:4) coordinate (i)  node[right] {$\psi_0$};% used polar coordinates
    \draw[phasor] (0,0) -- (-15:4) coordinate (j)  node[right] {$\psi$};% used polar coordinates
% angles drawn by pic
\coordinate (X)   at (0,0);
\draw
    pic["$\theta$",angles] {angle=x--X--i}
    pic["$\theta$",angles] {angle=j--X--x}
    ;
\end{tikzpicture}

Now, we need to do inversion about the mean which is equivalent to reflection about the the equal amplitude state $\sum_{0}^{N - 1} \dfrac{1}{\sqrt{N}} \ket{i}$.

\begin{tikzpicture}[
            > = Straight Barb,
phasor/.style = {very thick,-{Stealth}},
angles/.style = {draw, <->, angle eccentricity=1,
                 right, angle radius=15mm}
                        ]
% coordinates
    \draw[->, thick] (-0.5,0) -- (4,0) coordinate (x) node[below left] {$\ket{b}$};
    \draw[->, thick] (0,-0.5) -- (0,4) node[below left] (y) {$\ket{a}$};
% phasors
    \draw[phasor, dotted] (0,0) -- (15:4) coordinate (i)  node[right] {$\psi_0$};% used polar coordinates
    \draw[phasor, dotted] (0,0) -- (-15:4) coordinate (j)  node[right] {$\psi$};% used polar coordinates
    \draw[phasor] (0,0) -- (45:4) coordinate (k)  node[right] {$\psi$};% used polar coordinates
% angles drawn by pic
\coordinate (X)   at (0,0);
\draw
    pic["$\theta$",angles] {angle=x--X--i}
    pic["$\theta$",angles] {angle=j--X--x}
    pic["",angles] {angle=x--X--k}
;
\end{tikzpicture}

So, after one iteration we have moved closer to the required state. We need to carry these iterations certain number of times so that when we measure a state, it collapses to the desirable state with high probability.

Every time the inversion about mean is done using the equal amplitude state only. It happens to be our initial state too but this is true only for the first iteration and not for further iterations.

\section{How to Implement the circuit?}

Now that we know what to do, we have to question how to do it.
\subsection{Negation of Amplitude}
Our first task is to negate the amplitude of the desirable quantum state.
The situation is like this that we have been given a quantum black box that outputs 1 for the desirable states and 0 for the undesirable states.

Insert diagram here.

In other words, given the superposition $\ket{x}\ket{0}$, the circuit spits out the superposition $\ket{x}\ket{f(x)}$. We know the quantum circuits are designed in such a way that the answer register gets XORed with the output $f(x)$. So if the input superposition is $\ket{x}\ket{y}$, then the output superposition will be $\ket{x}\ket{y \oplus{f(x)}}$.

With this knowledge, we can apply neat little hack and trick our black box into doing the task for us. We will initialise the answer register to $\ket{-}$. Since

\begin{align*}
\ket{-} &= \dfrac{1}{\sqrt{2}} ( \ket{0} - \ket{1} )\\
\ket{- \oplus {f(x)}} &= \dfrac{1}{\sqrt{2}} \left( \ket{0 \oplus {f(x)}} - \ket{0 \oplus {f(x)}} \right)\\
\ket{- \oplus {f(x)}} &= \dfrac{1}{\sqrt{2}} \left( \ket{{f(x)}} - \ket{\overline{f(x)}} \right)\\
\ket{- \oplus {f(x)}} &= \dfrac{1}{\sqrt{2}} \left( -1 \right) ^ {f(x)} \left( \ket{0} - \ket{1} \right)\\
\ket{- \oplus {f(x)}} &= \left( -1 \right) ^ {f(x)} \ket{-}\\
\end{align*}

Therefore, the entire transition will be
$$\ket{x}\ket{-} \longrightarrow \left( -1 \right) ^ {f(x)} \ket{x} \ket{-}$$

Now, since it is a superposition that is being looked at as a whole, the term $\left( -1 \right) ^ {f(x)}$ can be associated with either $\ket{x}$ or $\ket{-}$.
Putting $\ket{x}  = \sum_0^{N-1}\alpha_i\ket{i}$, we get the output from the black box as $\sum_0^{N-1}\alpha_i\ket{i} \left( -1 \right) ^ {f(x)}$. Now since $f(x) = 1$ for $\ket{j}$ and $0$ for all others, the amplitude is negated only for $\ket{j}$. Thus we can do the amplitude negation easily.
\subsection{Inversion about mean}
Inversion about mean is the same as reflection about the uniform state i.e. reflection about the state $\sum_0 ^{N - 1} \dfrac{1}{\sqrt{N}}$. Now for reflection about the uniform state, we can first map the uniform state to the all-zero state using a Hadamard Gate and then reflect about the all-zero state and then map the state back to the uniform state using another Hadamard Gate (Since Hadamard Gate is it's own inverse). So now we need a method to reflect about the all-zero state ($\ket{00\dots0}$ or simply $\ket{0}$). Consider the following matrix :-

\[
A = \begin{bmatrix}
    1       & 0      & \dots & 0 \\
    0       & -1     & \dots & 0 \\
    \vdots  & \vdots & \ddots & \vdots \\
    0       & 0      & \dots  & -1
    \end{bmatrix}
\]

This matrix maps negates all the states except for the state $\ket{0}$. This is the same as reflection about $\ket{0}$. This matrix is also a unitary matrix because $A A^{\dagger} = I$ i.e. the conjugate transpose is its inverse. So we can conclude that the sequence of matrices $H_N A H_N$ (where $H_N$ stands for the unitary matrix corresponding to Hadamard Gate applied to n qubits.) does a reflection about the mean. And since all the matrices are unitary, they can be implemented using quantum gates.

So when we apply the operations of amplitude negation and inversion about mean repeatedly for around $\sqrt{N}$ times, the probability of getting the correct answer exceeds half and we are highly likely to get the current answer. We can perform this several times to be sure of the answer since the method is probabilistic.

\section{Qiskit Code}
\textbf{Note - Please refer to the Jupyter Notebook for the output of the program and the explanatory comments and further experimentation.}

\begin{tcolorbox}[
    enhanced,
    attach boxed title to top left={xshift=6mm,yshift=-3mm},
    title=Simulation Code,
    boxed title style={size=small,sharp corners},
    sharp corners,
]
\begin{minted}{python}
import matplotlib.pyplot as plt
import numpy as np

from qiskit import IBMQ, Aer, QuantumCircuit,
    ClassicalRegister, QuantumRegister, execute
from qiskit.providers.ibmq import least_busy
from qiskit.quantum_info import Statevector
from qiskit.visualization import plot_histogram
from qiskit.extensions import UnitaryGate
from math import sqrt

n = 5
N = 2 ** n

def initialize(qc, qubits):
    for q in qubits:
        qc.h(q)
    return qc

def get_oracle_matrix(N, values):
    oracle_matrix = np.identity(N)
    for value in values:
        oracle_matrix[value][value] = -1
    return oracle_matrix

def get_diffusion_matrix(N):
    diffusion_matrix = np.zeros((N, N), dtype = float)
    diffusion_matrix.fill(2 / N)
    diffusion_matrix -= np.identity(N)
    return diffusion_matrix

\end{minted}
\end{tcolorbox}
\begin{tcolorbox}[
    enhanced,
    attach boxed title to top left={xshift=6mm,yshift=-3mm},
    title=Simulation Code,
    boxed title style={size=small,sharp corners},
    sharp corners,
]
\begin{minted}{python}

oracle_matrix = get_oracle_matrix(N, values = [2])
oracle_unitary_gate = UnitaryGate(oracle_matrix)

diffusion_matrix = get_diffusion_matrix(N)
diffusion_unitary_gate = UnitaryGate(diffusion_matrix)

qc = QuantumCircuit(n)
qc = initialize(qc, [x for x in range(n)])

for i in range(5):
    qc.unitary(oracle_matrix, [x for x in range(n)])
    qc.unitary(diffusion_matrix, [x for x in range(n)])
qc.draw()

qc.measure_all()

qasm_simulator = Aer.get_backend('qasm_simulator')
shots = 1024
results = execute(qc, backend=qasm_simulator,
                    shots=shots).result()
answer = results.get_counts()
plot_histogram(answer, figsize = (15, 12))
\end{minted}
\end{tcolorbox}

\section{Findings}
While it was mostly studying stuff discovered by others, I did observe some things on my own that most probably have already been observed.

\subsection{Going beyond $\sqrt{N}$ queries}

In classical computers, it just doesn't hurt to go a few extra steps (since they don't harm the overall time complexity) just to be sure of our result.
I tried this out on the implementation that I wrote and the results surprised me. After exceeding the required number of queries the amplitude of the desired state starts to decrease again and reaches a certain value and increases again and oscillates like this. Also, the period of this oscillation varies along with the number of qubits we are dealing with. When the number of qubits is small, the value decreases quite suddenly and even deviating by 1 query can alter the probability of the outcome easily. However, when the number of qubits is large this is smoothened out, and a query or two give or take doesn't affect the outcome by much.

All in all, minimum $\sqrt{N}$ queries are required and should be sufficient to give the answer. One should not go beyond this limit. Rather, one should re-conduct the experiment from the initial state to verify the answer.

So, what may be happening has been attempted to be explained with the following diagrams.\\
After $\sqrt{N}$ iterations, the state $\psi$ is quite close to the desirable state. The probability of collapsing to the desirable state is as high as $80\% - 90\%$ (usual number as seen from the simulator code).

\begin{tikzpicture}[
            > = Straight Barb,
phasor/.style = {very thick,-{Stealth}},
angles/.style = {draw, <->, angle eccentricity=1,
                 right, angle radius=15mm}
                        ]
% coordinates
    \draw[->, thick] (-4,0) -- (4,0) coordinate (x) node[below left] {$\ket{b}$};
    \draw[->, thick] (0,-1) -- (0,4) node[below left] (y) {$\ket{a}$};
% phasors
    \draw[phasor, dotted] (0,0) -- (15:4) coordinate (i)  node[right] {$\psi_0$};% used polar coordinates
    \draw[phasor] (0,0) -- (80:4) coordinate (k)  node[right] {$\psi$};% used polar coordinates
% angles drawn by pic
\coordinate (X)   at (0,0);
\draw
    pic["",angles] {angle=x--X--i}
    pic["$\theta$",angles] {angle=x--X--k}
;
\end{tikzpicture}

Now, when we do amplitude negation by reflecting about $\ket{b}$, we get state as shown.

\begin{tikzpicture}[
            > = Straight Barb,
phasor/.style = {very thick,-{Stealth}},
angles/.style = {draw, <->, angle eccentricity=1,
                 right, angle radius=15mm}
                        ]
% coordinates
    \draw[->, thick] (-4,0) -- (4,0) coordinate (x) node[below left] {$\ket{b}$};
    \draw[->, thick] (0,-4) -- (0,4) node[below left] (y) {$\ket{a}$};
% phasors
    \draw[phasor, dotted] (0,0) -- (15:4) coordinate (i)  node[right] {$\psi_0$};% used polar coordinates
    \draw[phasor] (0,0) -- (-80:4) coordinate (k)  node[right] {$\psi$};% used polar coordinates
% angles drawn by pic
\coordinate (X)   at (0,0);
\draw
    pic["",angles] {angle=x--X--i}
    pic["$\theta$",angles] {angle=k--X--x}
;
\end{tikzpicture}

And when we do the inversion about mean, we get the state as shown.

\begin{tikzpicture}[
            > = Straight Barb,
phasor/.style = {very thick,-{Stealth}},
angles/.style = {draw, <->, angle eccentricity=1,
                 right, angle radius=15mm}
                        ]
% coordinates
    \draw[->, thick] (-4,0) -- (4,0) coordinate (x) node[below left] {$\ket{b}$};
    \draw[->, thick] (0,-1) -- (0,4) node[below left] (y) {$\ket{a}$};
% phasors
    \draw[phasor, dotted] (0,0) -- (15:4) coordinate (i)  node[right] {$\psi_0$};% used polar coordinates
    \draw[phasor] (0,0) -- (105:4) coordinate (k)  node[right] {$\psi$};% used polar coordinates
% angles drawn by pic
\coordinate (X)   at (0,0);
\draw
    pic["",angles] {angle=x--X--i}
    pic["$\theta$",angles] {angle=x--X--k}
;
\end{tikzpicture}

So exceeding one query does not make much difference, but when we do this a few number of times, $\psi$ keeps on deviating from the required state. And then after some number of such iterations, it again starts to return to the position. And this "some number of iterations" is less than $\sqrt{N}$ because since the angle made from $\ket{b}$ is large, the iterations of the algorithm make huge changes in the states and thus requires fewer steps.

\textbf{Note - This was observed when there was only one desirable state. With multiple desirable states a similar pattern was followed but not accurately.}

\subsection{Assumption about the given black box}
It is assumed that a quantum circuit has already been implemented that identifies the answer that we use as a black box. Well, if such a black box has been implemented, the maker of the black box would already know about the desired state.\\
I think that maybe in future a situation may arise when the implemented black box is provided by nature and the algorithm may be used to find the desirable state.\\

\section{Conclusion}

Regardless of the black-box property mentioned above, this amazing algorithm does give an idea about the power of Quantum Computing. It gives a quadratic speed up in searching which can be used in database searching. The quadratic speed up can be used to solve some NP-Complete Problems by doing exhaustive searching over the set of all possible solutions (though not for large $N$ as exponential term still dominates).

\end{document}.