Consider a point-to-point MISO WIPT system in a multipath environment. The $M$-antenna transmitter delivers information and power simultaneously to the single-antenna receiver through $N$ orthogonal subbands. It is assumed the carrier frequencies are with even spacing $\Delta f$ and equal bandwidth ${B_{\text{s}}}$. The $n$-th subband has carrier frequency ${f_n} = {f_0} + n\Delta f$ for $n = 0, \ldots ,N - 1$. To maximize the rate-energy tradeoff, we employ a superposed signal consists of a multi-carrier deterministic multisine waveform and a multi-carrier modulated waveform for WIPT. Both components are transmitted on the same frequency bands.

\subsection{Transmitted Information Waveform}\label{sec:transmitted-information-waveform}
Denoting the information symbol carried by the modulated waveform on subband $n$ as ${{\tilde x}_n}$, we assume the input symbol is with the capacity-achieving i.i.d. Circular Symmetric Complex Gaussian (CSCG) distribution with zero mean and unit variance \cite{Varasteh2017a}:

\begin{equation}\label{eqn:unmodulated_symbol}
  {{\tilde x}_n} = \left| {{{\tilde x}_n}} \right|{e^{j{\phi _{{{\tilde x}_n}}}}}\sim\mathcal{C}\mathcal{N}(0,1)
\end{equation}

Hence, the modulated signal on antenna $m = 1, \ldots ,M$, subband $n = 1, \ldots ,N$ writes as

\begin{equation}\label{eqn:modulated_symbol}
  {x_{n,m}} = {w_{I,n,m}}{{\tilde x}_n}
\end{equation}

where ${w_{I,n,m}}$ is the corresponding information weight and is a constant for a certain channel realization:

\begin{equation}\label{eqn:weight_information}
  {w_{I,n,m}} = \left| {{w_{I,n,m}}} \right|{e^{j{\phi _{I,n,m}}}} = {s_{I,n,m}}{e^{j{\phi _{I,n,m}}}}
\end{equation}

Note the amplitude and phase are separated in the optimization. Define matrices ${{\mathbf{S}}_I}$ and ${{\mathbf{\Phi }}_I}$ of size $N \times M$ such that the $(n,m)$ entries hold ${s_{I,n,m}}$ and ${\phi _{I,n,m}}$ respectively. In this way, the design of information waveform is converted into an optimization problem on both matrices, with the average WIT transmit power ${P_I} = \frac{1}{2}\left\| {{{\mathbf{S}}_I}} \right\|_F^2$. The modulated symbol \eqref{eqn:modulated_symbol} can be further expressed as

\begin{equation}\label{eqn:modulated_symbol_further}
  {x_{n,m}} = {s_{I,n,m}}{e^{j{\phi _{I,n,m}}}} \cdot \left| {{{\tilde x}_n}} \right|{e^{j{\phi _{{{\tilde x}_n}}}}} = {{\tilde s}_{I,n,m}}{e^{j{{\tilde \phi }_{I,n,m}}}}
\end{equation}

with ${{\tilde s}_{I,n,m}} = {s_{I,n,m}}\left| {{{\tilde x}_n}} \right|$ and ${{\tilde \phi }_{I,n,m}} = {\phi _{I,n,m}} + {\phi _{{{\tilde x}_n}}}$. In this way, the impact of symbol distribution and waveform design are combined. The modulated waveform also follows an i.i.d. CSCG distribution with variance equal to the subband power ${x_{n,m}}\sim\mathcal{C}\mathcal{N}\left( {0,s_{I,n,m}^2} \right)$.

Therefore, the information waveform ${x_{I,m}}(t)$ on antenna $m$ at time $t$ writes as

\begin{align}\label{eqn:information_waveform}
  {x_{I,m}}(t) &= \sum\limits_{n = 0}^{N - 1} {{{\tilde s}_{I,n,m}}(t)\cos \left( {2\pi {f_n}t + {{\tilde \phi }_{I,n,m}}(t)} \right)}  \hfill \\
   &= \Re \left\{ {\sum\limits_{n = 0}^{N - 1} {{x_{n,m}}(t){e^{j2\pi {f_n}t}}} } \right\} \hfill \\
   &= \Re \left\{ {\sum\limits_{n = 0}^{N - 1} {{w_{I,n,m}}{{\tilde x}_n}(t){e^{j2\pi {f_n}t}}} } \right\} \hfill
\end{align}

On top of this, the WIT signal vector is spread over $M$ antennas

\begin{equation}\label{eqn:wit_vector}
  {{\mathbf{x}}_I}(t) = \Re \left\{ {\sum\limits_{n = 0}^{N - 1} {{{\mathbf{w}}_{I,n}}} {{\tilde x}_n}(t){e^{j2\pi {f_n}t}}} \right\}
\end{equation}

where ${{\mathbf{w}}_{I,n}} = {\left[ {{w_{I,n,1}} \cdots {w_{I,n,M}}} \right]^T}$.

\subsection{Transmitted Power Waveform}\label{sec:transmitted-power-waveform}
Compared with the information component, the multisine power component is unmodulated and deterministic. Hence, there is no dependency on the distribution of input symbol $\tilde{x}_{n}(t)$. The power waveform on antenna $m$, subband $n$ is given by

\begin{equation}\label{eqn:unmodulated}
  {w_{P,n,m}} = {s_{P,n,m}}{e^{j{\phi _{P,n,m}}}}
\end{equation}

where ${s_{P,n,m}}$ and ${{\phi _{P,n,m}}}$ are the amplitude and phase of the multisine signal. Collecting them into the $(n,m)$ entries of matrices ${{\mathbf{S}}_P}$ and ${{\mathbf{\Phi }}_P}$, the average power of the WPT waveform equals $\frac{1}{2}\left\|\mathbf{S}_{P}\right\|_{F}^{2}$. Similarly, the power waveform ${x_{P,m}}(t)$ on antenna $m$ at time $t$ is

\begin{align}\label{eqn:power_waveform}
  {x_{P,m}}(t) &= \sum\limits_{n = 0}^{N - 1} {{s_{P,n,m}}\cos \left( {2\pi {f_n}t + {\phi _{P,n,m}}} \right)}  \hfill \\
   &= \Re \left\{ {\sum\limits_{n = 0}^{N - 1} {{w_{P,n,m}}{e^{j2\pi {f_n}t}}} } \right\} \hfill
\end{align}

Combining the power signals on all $M$ antennas, the WPT signal vector writes as

\begin{equation}\label{eqn:wpt_vector}
  {{\mathbf{x}}_P}(t) = \Re \left\{ {\sum\limits_{n = 0}^{N - 1} {{{\mathbf{w}}_{P,n}}} {e^{j2\pi {f_n}t}}} \right\}
\end{equation}

with ${{\mathbf{w}}_{P,n}} = {\left[ {{w_{P,n,1}} \cdots {w_{P,n,M}}} \right]^T}$.

\subsection{Channel and Received Waveform}\label{sec:multipath-and-received-signal}
Consider a multipath channel with $L$ paths. For the $l$-th path ($l = 1, \ldots ,L$), denote the phase shift between the receive antenna and transmit antenna $m$ of subband $n$ as ${\zeta _{n,m,l}}$. Let ${\tau _l}$ and ${\alpha _l}$ be the delay and magnitude gain, and indicate the transmit signal on subband $n$ of antenna $m$ as

\begin{equation}\label{eqn:superposed_waveform}
  {v_{n,m}}(t) = {w_{P,n,m}} + {w_{I,n,m}}{{\tilde x}_n}(t)
\end{equation}

The superposed signal containing modulated information waveform and multisine power waveform is demonstrated to bring a two-fold benefit on rate and energy \cite{Clerckx2019}. Also, the channel frequency response is expressed as

\begin{equation}\label{eqn:channel}
  {h_{n,m}} = \sum\limits_{l = 0}^{L - 1} {{\alpha _l}{e^{j\left( { - 2\pi {f_n}{\tau _l} + {\zeta _{n,m,l}}} \right)}}}  = {A_{n,m}}{e^{j{{\bar \psi }_{n,m}}}}
\end{equation}

We assume ${\max _{l \ne {l^\prime }}}\left| {{\tau _l} - {\tau _{{l^\prime }}}} \right| <  < 1/{B_{\text{s}}}$ to ensure $v_{n, m}(t)$ and $\tilde{x}_{n}(t)$ to be narrowband signals. It is also supposed that ${v_{n,m}}\left( {t - {\tau _l}} \right) = {v_{n,m}}(t)$ and ${{\tilde x}_n}\left( {t - {\tau _l}} \right) = {{\tilde x}_n}(t)$. The received component ${y_m}(t)$ corresponding to transmit antenna $m$ contains the power component $y_{P, m}(t)$ and the information component $y_{I, m}(t)$

\begin{align}\label{eqn:received_signal_component}
  {y_m}(t) &= {y_{P,m}}(t) + {y_{I,m}}(t) \hfill \\
   &= \Re \left\{ {\sum\limits_{l = 0}^{L - 1} {\sum\limits_{n = 0}^{N - 1} {{\alpha _l}} } {v_{n,m}}\left( {t - {\tau _l}} \right){e^{j2\pi {f_n}\left( {t - {\tau _l}} \right) + {\zeta _{n,m,l}}}}} \right\} \hfill \\
   &\approx \Re \left\{ {\sum\limits_{n = 0}^{N - 1} {{h_{n,m}}} {v_{n,m}}(t){e^{j2\pi {f_n}t}}} \right\} \hfill
\end{align}

Hence, the total received signal can be obtained by stacking up \eqref{eqn:received_signal_component} over all transmit signals

\begin{align}\label{eqn:received_signal}
  y(t) &= {y_P}(t) + {y_I}(t) \hfill \\
   &= \Re \left\{ {\sum\limits_{n = 0}^{N - 1} {{{\mathbf{h}}_n}} \left( {{{\mathbf{w}}_{P,n}} + {{\mathbf{w}}_{I,n}}{{\tilde x}_n}} \right){e^{j2\pi {f_n}t}}} \right\} \hfill
\end{align}

where the channel vector is defined as ${{\mathbf{h}}_n} = \left[ {{h_{n,1}} \ldots {h_{n,M}}} \right]$.

\subsection{Information Decoder}\label{sec:information-decoder}
In the superposed transmit signal ${x_m}(t)$, the modulated component ${x_{I,m}}(t)$ carries all the information while the multisine component ${x_{P,m}}(t)$ completely serves the power. Since the latter is deterministic, it creates no interference and has zero contribution to the different entropy of ${x_m}(t)$ in terms of translation. Therefore, the achievable rate is equal to

\begin{equation}\label{eqn:mutual_information}
  I\left( {{{\mathbf{S}}_I},{{\mathbf{\Phi }}_I},\rho } \right) = \sum\limits_{n = 0}^{N - 1} {{{\log }_2}} \left( {1 + \frac{{(1 - \rho ){{\left| {{{\mathbf{h}}_n}{{\mathbf{w}}_{I,n}}} \right|}^2}}}{{\sigma _n^2}}} \right)
\end{equation}

where ${\sigma _n^2}$ is the total variance of the Gaussian noise at the RF-band and the noise introduced during the RF-to-baseband conversion (assumed Gaussian) on tone $n$. It reaches the maximum rate $I\left( {{\mathbf{S}}_I^ \star ,{\mathbf{\Phi }}_I^ \star ,0} \right)$ and boils down to WIT by setting $\rho  = 0$ then performing Maximum Ratio Transmission (MRT) and Water-Filling (WF) power allocation on subbands.

A significant conclusion in \cite{Clerckx2018} is that the rate \eqref{eqn:mutual_information} is achievable with and without waveform cancellation. Since the multisine is deterministic, it can either be subtracted from the baseband signal or be used to construct the translated codebook. Conventional demodulation can be performed then.

\subsection{Energy Harvester}\label{sec:energy-harvester}
To investigate the impact of the proposed waveform on the harvested power, we apply the received signal expression \eqref{eqn:received_signal_component} to the diode current equation \eqref{eqn:output_current_function}.

First, we consider the multi-carrier multisine waveform ${y_P}(t)$. The approximated harvester DC current with multisine excitation writes as

\begin{equation}\label{eqn:current_power}
  {i_{\text{out}}} \approx k_0^\prime  + \sum\limits_{i{\text{ even }},i \geqslant 2}^{{n_o}} {k_i^\prime } {\rho ^{i/2}}R_{\text{ant}}^{i/2}\mathbb{E}\left[ {{y_P}{{(t)}^i}} \right]
\end{equation}

The expectations of the received power waveform to the second and fourth orders were derived in \cite{Clerckx2016} as

\begin{align}\label{eqn:power_waveform_second_order}
  \mathbb{E}\left[ {{y_P}{{(t)}^2}} \right] &= \frac{1}{2}\sum\limits_{n = 0}^{N - 1} {{{\left| {{{\mathbf{h}}_n}{{\mathbf{w}}_{P,n}}} \right|}^2}} \\
   &= \frac{1}{2}\sum\limits_{n = 0}^{N - 1} {\sum\limits_{{m_0},{m_1}} {{s_{P,n,{m_0}}}{s_{P,n,{m_1}}}{A_{n,{m_0}}}{A_{n,{m_1}}}\cos \left( {{\psi _{P,n,{m_0}}} - {\psi _{P,n,{m_1}}}} \right)} }
\end{align}

\begin{align}\label{eqn:power_waveform_fourth_order}
  \mathbb{E}\left[ {{y_P}{{(t)}^4}} \right] &= \frac{3}{8}\Re \left\{ {\sum\limits_{\substack{{n_0},{n_1},{n_2},{n_3} \\ {n_0} + {n_1} = {n_2} + {n_3}}} {{{\mathbf{h}}_{{n_0}}}{{\mathbf{w}}_{P,{n_0}}}{{\mathbf{h}}_{{n_1}}}{{\mathbf{w}}_{P,{n_1}}}{{\left( {{{\mathbf{h}}_{{n_2}}}{{\mathbf{w}}_{P,{n_2}}}} \right)}^*}{{\left( {{{\mathbf{h}}_{{n_3}}}{{\mathbf{w}}_{P,{n_3}}}} \right)}^*}} } \right\} \\
   &= \frac{3}{8}\sum\limits_{\substack{{n_0},{n_1},{n_2},{n_3} \\ {n_0} + {n_1} = {n_2} + {n_3}}} {\sum\limits_{{m_0},{m_1},{m_2},{m_3}} {\left[ {\prod\limits_{j = 0}^3 {{s_{{P},{n_j},{m_j}}}} {A_{{n_j},{m_j}}}} \right] }} \nonumber \\
   &\quad \cos \left( {{\psi _{{P},{n_0},{m_0}}} + {\psi _{{P},{n_1},{m_1}}} - {\psi _{{P},{n_2},{m_2}}} - {\psi _{{P},{n_3},{m_3}}}} \right)
\end{align}

We then turn to the multi-carrier modulated waveform ${y_I}(t)$. It can be treated as a multisine waveform for the input symbols $\{ {{\tilde x}_n}\} $ that vary randomly with symbol rate $1/{B_{\text{s}}}$. Similarly, the approximated DC current provided by the rectifier is given by

\begin{equation}\label{eqn:current_information}
  {i_{\text{out}}} \approx k_0^\prime  + \sum\limits_{i{\text{ even }},i \geqslant 2}^{{n_o}} {k_i^\prime } {\rho ^{i/2}}R_{\text{ant}}^{i/2}{\mathbb{E}_{\{ {{\tilde x}_n}\} }}\left[ {{y_I}{{(t)}^i}} \right]
\end{equation}

To obtain the expectation, we first extract the DC currents corresponding to a given set of amplitudes $\{ {{\tilde s}_{I,n,m}}\} $ and phases $\{ {{\tilde \phi }_{I,n,m}}\} $, then take the expectation over the distribution of the input symbol ${{\tilde x}_n}$. As an i.i.d. CSCG distribution ${{\tilde x}_n}\sim\mathcal{C}\mathcal{N}(0,1)$ is assumed, the amplitude square ${\left| {{{\tilde x}_n}} \right|^2}$ is exponentially distributed with $\mathbb{E}\left[ {{{\left| {{{\tilde x}_n}} \right|}^2}} \right] = 1$. Using the moment generating function, we have

\begin{equation}\label{eqn:modulation_gain}
  \mathbb{E}\left[ {{{\left| {{{\tilde x}_n}} \right|}^4}} \right] = \mathbb{E}\left[ {{{\left( {{{\left| {{{\tilde x}_n}} \right|}^2}} \right)}^2}} \right] = 2
\end{equation}

This modulation gain measures the contribution of modulated waveform on the output current, which does not apply to multisine waveform. Following \cite{Clerckx2018}, we can obtain the expectation of the received information waveform to the second and fourth orders

\begin{align}\label{eqn:information_waveform_second_order}
  \mathbb{E}\left[ {{y_I}{{(t)}^2}} \right] &= \frac{1}{2}\sum\limits_{n = 0}^{N - 1} {\sum\limits_{{m_0},{m_1}} {{s_{I,n,{m_0}}}} } {s_{I,n,{m_1}}}{A_{n,{m_0}}}{A_{n,{m_1}}}\cos \left( {{\psi _{I,n,{m_0}}} - {\psi _{I,n,{m_1}}}} \right) \\
   &= \frac{1}{2}\sum\limits_{n = 0}^{N - 1} {{{\left| {{{\mathbf{h}}_n}{{\mathbf{w}}_{I,n}}} \right|}^2}}
\end{align}

\begin{align}\label{eqn:information_waveform_fourth_order}
  \mathbb{E}\left[ {{y_I}{{(t)}^4}} \right] &= \frac{6}{8}\sum\limits_{{n_0},{n_1}} {\sum\limits_{{m_0},{m_1},{m_2},{m_3}} {\left[ {\prod\limits_{j = 0,2} {{s_{I,{n_0},{m_j}}}{A_{{n_0},{m_j}}}} } \right]\left[ {\prod\limits_{j = 1,3} {{s_{I,{n_1},{m_j}}}{A_{{n_1},{m_j}}}} } \right]} } \nonumber \\
   &\quad \cos \left( {{\psi _{I,{n_0},{m_0}}} + {\psi _{I,{n_1},{m_1}}} - {\psi _{I,{n_0},{m_2}}} - {\psi _{I,{n_1},{m_3}}}} \right) \\
   &= \frac{6}{8}{\left[ {\sum\limits_{n = 0}^{N - 1} {{{\left| {{{\mathbf{h}}_n}{{\mathbf{w}}_{I,n}}} \right|}^2}} } \right]^2} \label{eqn:waveform_end}
\end{align}

It is worth noting that the truncation order ${n_o}$ in \eqref{eqn:current_information} determines the relationship between the received signal and the harvested power. On top of it, \cite{Clerckx2016} proposed two diode models:

\begin{itemize}
  \item \textit{diode linear model} (${n_o} = 2$) is the conventional perspective that assumes the total output power is the sum of the subband power. It omits the rectifier nonlinearity and is typically suitable for very low input power (below -30 dBm).
  \item \textit{diode nonlinear model} (${n_o} > 2$) considers the contributions of higher-order terms to the harvested power. It captures the nonlinear behavior of the diode with the product terms
      modeling the cross contribution of different frequencies (as indicated by ${{n_0},{n_1}}$ in \eqref{eqn:information_waveform_fourth_order} and \eqref{eqn:power_waveform_fourth_order}). The model is complicated but accurate, which especially fits the low power regime between -30 dBm and 0 dBm.
\end{itemize}

In the diode linear model corresponding to \eqref{eqn:power_waveform_second_order} and \eqref{eqn:information_waveform_second_order}, the output current is only a function of $\sum\limits_{n = 0}^{N - 1} {{{\left| {{{\mathbf{h}}_n}{{\mathbf{w}}_{P/I,n}}} \right|}^2}} $. Hence, it appears that multi-carrier multisine and modulated waveforms are equally suitable for WPT. On the other hand, the diode nonlinear model highlights a clear difference between the power delivered by both waveforms. For the modulated component, the second and fourth order terms in \eqref{eqn:information_waveform_second_order} and \eqref{eqn:information_waveform_fourth_order} share same dependencies on ${\sum\limits_{n = 0}^{N - 1} {{{\left| {{{\mathbf{h}}_n}{{\mathbf{w}}_{I,n}}} \right|}^2}} }$. It implies that for a modulated waveform with CSCG inputs, the higher order terms behave similarly to the second order term, and there is no essential difference between both models. In comparison, for the multisine waveform, the parts \eqref{eqn:power_waveform_second_order} and \eqref{eqn:power_waveform_fourth_order} are decomposed as the product of contributions from different subbands. Also, the second order term is a linear sum over each frequency while the nonlinear fourth order term shows some cross correlation between different subbands.

In this paper, we set ${n_o} = 4$ to explore the fundamental nonlinear behaviour of the diode and its impact on the harvested current. Therefore, the approximated output DC current \eqref{eqn:output_current_function} reduces to

\begin{align}\label{eqn:output_current_truncated}
  {i_{\text{out}}} &\approx k_0^\prime  + k_2^\prime \rho {R_{{\text{ant}}}}\mathbb{E}\left[ {{y_P}{{(t)}^2}} \right] + k_4^\prime {\rho ^2}R_{ant}^2\mathbb{E}\left[ {{y_P}{{(t)}^4}} \right] \nonumber \\
   &\quad + k_2^\prime \rho {R_{{\text{ant}}}}\mathbb{E}\left[ {{y_I}{{(t)}^2}} \right] + k_4^\prime {\rho ^2}R_{ant}^2\mathbb{E}\left[ {{y_I}{{(t)}^4}} \right] \nonumber \\
   &\quad + 6k_4^\prime {\rho ^2}R_{{\text{ant}}}^2\mathbb{E}\left[ {{y_P}{{(t)}^2}} \right]\mathbb{E}\left[ {{y_I}{{(t)}^2}} \right]
\end{align}

whose corresponding target function is

\begin{align}\label{eqn:target_function_truncated}
  {z_{\text{DC}}} &\approx k_0  + k_2 \rho {R_{{\text{ant}}}}\mathbb{E}\left[ {{y_P}{{(t)}^2}} \right] + k_4 {\rho ^2}R_{ant}^2\mathbb{E}\left[ {{y_P}{{(t)}^4}} \right] \nonumber \\
   &\quad + k_2 \rho {R_{{\text{ant}}}}\mathbb{E}\left[ {{y_I}{{(t)}^2}} \right] + k_4 {\rho ^2}R_{ant}^2\mathbb{E}\left[ {{y_I}{{(t)}^4}} \right] \nonumber \\
   &\quad + 6k_4 {\rho ^2}R_{{\text{ant}}}^2\mathbb{E}\left[ {{y_P}{{(t)}^2}} \right]\mathbb{E}\left[ {{y_I}{{(t)}^2}} \right]
\end{align}


\documentclass[12pt]{extarticle}

\usepackage{geometry}
\geometry{
	letterpaper,
	left=20mm,
	right=20mm,
	top=20mm,
}
\usepackage{amsmath}
\usepackage{amssymb}

\begin{document}
\section{Parameters}%
\label{sec:Parameters}

\subsection{Data}
\label{sub:Data}
\begin{itemize}
	\item $P$: set of all persons (rowers),
	\item $B$: set of all boats,
	\item $T$: set of all training times of the week (day and time),
	\item $B_p$: set of boats that person $p$ can row (based on her skill and weight class),
	\item $T_p$: set of times the person $p$ is likely to row (union of her first and second choices),
	\item $nb\_asked_p$: number of training person $p$ wants to have in the week (number of first choices),
	\item $E$: set of sets of exclusive training times. Used for non-compatible training sessions, for examples training times that are directly consecutive,
	\item $u_{pt}$: utility for person $p$ of rowing at time $t$. Values used are $1$ if first choice, $0.1$ if second choice, not defined if $t$ not in choices of $p$.
\end{itemize}

\subsection{Variables}%
\label{sub:Variables}
\begin{itemize}
	\item $s \in \mathbb{R}$: minimal utility across all people,
	\item $x_{pbt} \in \{0, 1\}$: binary variable, $1$ if person $p$ is scheduled to row boat $b$ at time $t$, $0$ otherwise.
\end{itemize}

\section{Model}%
\label{sec:Model}

\begin{align}
	\max_{x, s} \quad			& \lambda s + \sum_{p \in P} \sum_{b \in B_p} \sum_{t \in T_p} u_{pt} x_{pbt}	& \label{eq:obj}\\
	\text{subject to:} \qquad	& s \leq \sum_{b \in B_p} \sum_{t \in T_p} u_{pt} x_{pbt} 						& \forall p \in P \label{eq:min-util}\\
								& \sum_{b \in B_p} \sum_{t \in T_p} x_{pbt} \leq nb\_asked_p					& \forall p \in P \label{eq:training-upper}\\
								& \sum_{b \in B_p} x_{pbt} \leq 1												& \forall p \in P, t \in T_p \label{eq:only-one-boat}\\
								& \sum_{b \in B_p} \sum_{t \in E} x_{pbt} \leq 1								& \forall p \in P \label{eq:exclusive-times}\\
								& \sum_{p \in P(b,t)} x_{pbt} \leq 1											& \forall b \in B, \forall t \in T \label{eq:only-one-person}
\end{align}

\section{Explainations}%
\label{sec:Explainations}

This model is run weekly. A few days in advance, rowers submit their schedule preferences via an online form.
These preferences consist of "first choices", that correspond to when a rowers would ideally want to row, and "second choices", which are backup times at which they would be available, in case it's not possible for them to row one of their "first choice".\\

\noindent More details about the objective function and the constraints:
\begin{itemize}
	\item \eqref{eq:obj}: The objective function is made of two components. The first one $\lambda s$ maximizes the lowest utility value that a person gets. The second one maximizes the sum of utilities across all people. The coefficient $\lambda$ should be large enough to ensure that the maximum value of $s$ is reached before optimizing the sum of utilities. This is to ensure fairness, i.e. make sure it's not possible that a small set of people receive a schedule with very low utility value, just to maximize the overall utility. The minimal value of this coefficient can be computed, but I've been using $500$ which I am sure is enough for the size of my problem, and does not hit the CPU time in a significant way,
	\item \eqref{eq:min-util}: ensure that $s$ is the minimum utility across people,
	\item \eqref{eq:training-upper}: cap the max number of training at the number of trainings asked for each person. We don't want the utility to be increased by assigning more trainings to someone than they asked,
	\item \eqref{eq:only-one-boat}: one person can only row one boat per training (otherwise, would increase utility artificially),
	\item \eqref{eq:exclusive-times}: ensure that we don't assign someone to training that are mutually exclusive (according to $E$),
	\item \eqref{eq:only-one-person}: each boat can only accommodate one person per training.
\end{itemize}

\end{document}


%---------------------------Jacobian---------------------------
\section{Jacobian}

This is the minimum determinant of the Jacobian matrix evaluated at each corner and the center of the element:
\[
q = \min\left\{\left\{\alpha_i\right\}_{i=0}^7, \frac{\alpha_8}{64} \right\}.
\]
This can also be interpreted as the minimum pointwise volume of local map
at the 8 corners and the center of the hexahedron.

\hexmetrictable{Jacobian}%
{$L^3$}%                                      Dimension
{$[0,DBL\_MAX]$}%                             Acceptable range
{$[0,DBL\_MAX]$}%                             Normal range
{$[-DBL\_MAX,DBL\_MAX]$}%                     Full range
{$1$}%                                        Cube
{\cite{knu:00}}%                              Citation
{v\_hex\_jacobian}%                           Verdict function name


\documentclass[11pt]{article}

\usepackage{a4wide}
\usepackage{amsmath}
\setlength{\parindent}{0pt}

\begin{document}

    \pagestyle{empty}
    \vspace*{-9em}

    \title{Useful Inequalities}
    \author{Carlos Luna-Mota}
    \date{\today}

    \begin{center}
        \section*{\Huge Useful Inequalities}
    \end{center}

    \vspace*{2em}

        For any pair of sorted sequences of real numbers of equal length ($x_0 \leq x_1 \leq \dots \leq x_n$ and $y_0 \leq y_1 \leq \dots \leq y_n$) and for any arbitrary permutation $\sigma$ of their index set:\bigskip

        \paragraph{Rearrangement Inequality:} $\displaystyle \boxed{\sum x_i y_{n-i} \;\leq\; \sum x_i y_{\sigma(i)} \;\leq\; \sum x_i y_i}$ \bigskip

        with the equality holding if and only if the permutated $y_i$ are equal. \bigskip

    \hrulefill \bigskip

        For any pair of finite or infinite sequences of real numbers ($x_1, x_2, \dots$ and $y_1, y_2, \dots$) and for any set of non-negative weights $w_i\geq0$:

        \paragraph{Weighted Cauchy-Schwarz Inequality:} $\displaystyle \boxed{\left( \sum w_i x_i y_i\right)^2 \;\leq\;\left(\sum w_i x^2_i\right) \left(\sum w_i y^2_i\right)}$ \bigskip

        with equality if and only if $\vec x$ and $\vec y$ are linearly dependent.

    \hrulefill \bigskip

        For any set of nonnegative weights $w_i \geq 0$ such that $\sum w_i = 1$ and any set $x_1, \dots, x_n$ of nonnegative real numbers:

        \paragraph{Weighted AM-GM Inequality:} $\displaystyle \boxed{{\min \{x_i\} \;\leq\;} \prod x_i^{w_i} \;\leq\; \sum w_i x_i {\;\leq\; \max \{x_i\}}}$ \bigskip

        with the middle equality holding if and only if all $x_i$ such that $w_i > 0$ are equal. \bigskip

    \hrulefill \bigskip

        For any $m\times n$ matrix of nonnegative real numbers $x_{ij} \geq 0\quad \forall\;i\in\{1,\dots, m\};\; \forall\;j\in\{1, \dots, n\}$ and any set of $n$ nonnegative weights $w_j \geq 0$ such that $\sum w_j = 1$:

        \paragraph{Generalized H\"older Inequality:} $\displaystyle \boxed{\sum_{i=1}^{m}{\left(\prod_{j=1}^{n} {x_{ij}}^{w_j}\right)} \;\leq\; \prod_{j=1}^{n}\left(\sum_{i=1}^{m} x_{ij}\right)^{w_j}}$ \bigskip

        with the equality holding if and only if two colums of the $x_{ij}$ matrix are linearly dependent. \bigskip

    \hrulefill \bigskip

        For any function $\phi(x)$ that is convex in a given interval, any set of points $x_1, x_2, \dots$ of that interval and any set of nonnegative weights $w_i \geq 0$ such that $\sum w_i = 1$:

        \paragraph{Weighted Jensen Inequality:} $\displaystyle \boxed{\phi\left(\sum w_i x_i\right) \;\leq\; \sum w_i \phi(x_i)}$ \bigskip

        A continuous function $\phi(x)$ is convex in a given interval if and only if, for any $x_1, x_2$ in the interval, it satisfies $\phi\left(\tfrac{x_1+x_2}{2}\right) \leq \tfrac{\phi(x_1)+\phi(x_2)}{2}$. In the cases where $\phi''(x)$ exists, $\phi(x)$ is convex if $\phi''(x) \;\geq\;0$ in the interval.

\end{document}


% !TEX root = ../main_lecture_notes.tex
\chapter{Decentralization of blockchain system}\label{chap:decentralization}
Decentralization represents the fairness of the distribution of the accounting right of the nodes in the blockchain network. The consensus protocol must be designed so that the decision power does not eventually concentrate on a few nodes leading to a centralized system. In leader based consensus protocols, each peer is associated to a probability of being chosen. Measuring decentrality then reduces to computing the entropy of the probability distribution of the random variable equal to the peer selected  \\

\noindent \cref{sec:decentralization_pos} focuses on the \PoS protocol by modelling the evolution of the stakes of the nodes by a stochastic process with reinforcement. \cref{sec:decentralization_pow} presents the concept of mining pool and discusses the threat they represent for the decentralized aspect of the network.

\section{Decentralization in PoS}\label{sec:decentralization_pos}
The \textit{Proof-of-Stake} protocol is a leader based consensus protocol that appoints a block validator depending on how many cryptocoins he owned which corresponds to its stake. In its most basic form a coins is drawn at random, the owner of that coin appends a block and collect a reward. The stake of each peers is governed by stochastic processes with reinforcement similar to that studied in the Polya's urn problem. In Polya's urn, there are balls of various colors. At each time step a ball is drawn, the ball is then replaced in the urn together with a ball of the same color. The coins are the balls and the color is the peer that owns the balls. This analogy has been used to study the decentralization\\

\noindent Let the network be of size $p$ and denote by $r$ the reward collected at each round $n\in\mathbb{N}$ by the lucky node $x\in \{1, \ldots, p\} = E$. At time $n=0$, each peer $x\in E$ has $Z^{(x)}_0$ coins so that the total number of coins is $Z_0 = \sum_{x\in E}Z^{(x)}_0$. The number of coins owned by each peers evolve over time as
$$
Z^{(x)}_n = Z^{(x)}_0 + r\sum_{k = 1}^n\mathbb{I}_{A_{k}^{(x)}}\text{ and }Z_n = \sum_{x\in E}Z^{(x)}_n = Z_0 + nr,
$$
where $A_{n}^{(x)}$ is the event that a coin own by peer $x\in E$ is drawn at time $n\in\mathbb{N}$. Let $(Z_n^{(x)})_{n\geq0}$ be the proportion of coins owned by peer $x$ at time $n$, given by
$$
W_n^{(x)} = \frac{Z^{(x)}_n}{Z_n}.
$$
Let $\mathcal{F}_n = \sigma(\{Y_k^{(x)}\text{ , }x\in E, k\leq n\})$. Note that
$$
\mathbb{P}\left(A_{n}^{(x)}|\mathcal{F}_{n-1}\right) = W_{n-1}^{(x)}.
$$
\subsection{Average stake owned by each peer}
The following result provide the average behaviour of the share of coins owned by each peer.
\begin{prop}\label{prop:average_stakes}
$$
\mathbb{E}(W_n^{(x)}) = \frac{Z_0^{(x)}}{Z_0},\text{ }x\in E\text{ }, n\geq0.
$$
\end{prop}
\begin{proof}
We show that $(W_n^{(x)})_{n\geq0}$ is a martingale. We have that
\begin{eqnarray*}
\mathbb{E}\left[W_n^{(x)}|\mathcal{F}_{n-1}\right]&=& \mathbb{E}\left[\frac{Z^{(x)}_{n-1} + r\mathbb{I}_{A_n^{(x)}}}{Z_0 + rn}\Big \rvert\mathcal{F}_{n-1}\right]\\
&=& \frac{Z^{(x)}_{n-1} }{Z_0 + rn}+\frac{rW_{n-1}^{x}}{Z_0 + rn}\\\
&=& \frac{Z^{(x)}[Z_0 + r(n-1)]}{Z_0 + rn}+\frac{rW_{n-1}^{x}}{Z_0 + rn}\\
&=&W_{n-1}^{x}.
\end{eqnarray*}
It then follows that
$$
\mathbb{E}\left(W_n^{(x)}\right) = \frac{Z_0^{(x)}}{Z_0},\text{ }x\in E\text{ }, n\geq0.
$$
\end{proof}
The long term average of the stake of each peer is stable, we focus on their asymptotic distribution in the following section.
\subsection{Asymptotic distribution of the stakes}\label{ssec:stakes_distribution}
To go beyond the mean and study the distribution of the stake of the peers, we have to consider the case $r = 1$. We can then show that the joint distribution of $(W_\infty^{(1)},\ldots,  W_\infty^{(p)})$ is the Dirichlet one.
% \begin{definition}\label{def:dirichlet}
% A random variable $X$ has a gamma distribution $\text{Gamma}(\alpha,\beta)$ if it has \pdf
% \[
% f(x) =
% \begin{cases}
% \frac{e^{-\beta x}x^{\alpha-1}\beta^{\alpha}}{\Gamma(\alpha)},& x>0, \\
% 0,&\text{ otherwise},
% \end{cases}
% \]
% where $\Gamma(\alpha) = \int_0^{\infty}e^{-x}x^{\alpha-1}\text{d}x$ is the gamma function.
% \end{definition}
\begin{definition}\label{def:dirichlet}
A random vector $(W_1,\ldots, W_p)$ has a Dirichlet distribution $\text{Dir}(\alpha_1,\ldots, \alpha_p)$ if it has a joint \pdf given by
\begin{equation}\label{eq:dirichlet_pdf}
f(w_1,\ldots, w_p;\alpha_1,\ldots, \alpha_p) = \frac{1}{B(\alpha)}\prod_{i=1}^p w_i^{\alpha_i-1},
\end{equation}
for $\alpha_1,\ldots, \alpha_p>0$, $0< w_1,\ldots, w_p <1$ and $\sum_{i=1}^pw_i=1$, where
$$
B(\alpha) = \frac{\prod_{i = 1}^p \Gamma(\alpha_i)}{\Gamma(\sum_{i=1}^p \alpha_i)},
$$
and $\Gamma(\alpha) = \int_{0}^{\infty}\e^{-x}x^{\alpha-1}\text{d}x$ is the gamma function.
\end{definition}
\noindent A Dirichlet random vector can be generated by independent Gamma random variables. Recall that $X\sim\GammaDist(\alpha, \beta)$ if $X$ has \pdf
\begin{equation}\label{eq:gamma_pdf}
f_{X}(x) = \begin{cases}
\frac{e^{-\beta x}x^{\alpha-1}\beta^\alpha}{\Gamma(\alpha_i)},&
x>0\\
0,&\text{otherwise}.\end{cases}
\end{equation}

\begin{prop}\label{prop:gamma_to_dirichlet}
Let $X_i\sim \GammaDist(\alpha_i,1)$ for $i = 1,\ldots, p$ be independent ranodm variables then
\[
\left(\frac{X_1}{\sum_{i=1}^{p}X_i},\ldots, \frac{X_p}{\sum_{i=1}^{p}X_i}\right)\sim\text{Dir}(\alpha_1,\ldots, \alpha_p)
\]
\end{prop}
\begin{proof}
Note that because $(w_1,\ldots, w_p)$ belongs to the $p-1$ simplex then the \pdf \eqref{eq:dirichlet_pdf} may be rewritten as
$$
f(w_1,\ldots, w_p;\alpha_1,\ldots, \alpha_p) = \frac{1}{B(\alpha)}\prod_{i=1}^{p-1} w_i^{\alpha_i-1}\left(1-\sum_{i=1}^{p-1} w_i\right)^{\alpha_p-1},
$$
which means that we are only interested in the distribution of the vector $\left(W_1,\ldots, W_{p-1}\right) = \left(X_{1}/\sum_{i=1}^{p}X_i,\ldots, X_{p-1}/\sum_{i=1}^{p}X_i\right)$.
Let $g:\mathbb{R}^p\mapsto \mathbb{R}^+$ be measurable and bounded and consider
\begin{eqnarray*}
&&\mathbb{E}\left[g\left(\frac{X_1}{\sum_{i=1}^{p}X_i},\ldots, \frac{X_{p-1}}{\sum_{i=1}^{p}X_i}\right)\right]\\
&=&\int_{\mathbb{R_+^p}}g\left(\frac{x_1}{\sum_{i=1}^{p}x_i},\ldots, \frac{x_{p-1}}{\sum_{i=1}^{p}x_i}\right)\frac{e^{-\sum_{i}^px_i}\prod_{i=1}^px_i^{\alpha_i-1}}{\prod_{i=1}^p\Gamma(\alpha_i)}\text{d}\lambda(x_1,\ldots, x_p)
\end{eqnarray*}
We use the change of variable
\[
\Phi:(w_1,\ldots, w_{p-1}, v) \mapsto \left[vw_1,\ldots, vw_{p-1}, v\left(1-\sum_{i=1}^{p-1}w_i\right)\right] = \left(x_1, \ldots, x_{p-1},\sum_{i=1}^{p}x_i\right)
\]
minding the change in the integration domain as
$$
\Phi(\Delta_{p-1}\times \mathbb{R}_+) = \mathbb{R}^p_+ ,
$$
$\Delta_{p-1}$ is the $p-1$ simplex and the Jacobian $\left|\frac{\text{d}\Phi}{\text{d}(w_1,\ldots, w_{p-1},v)}\right|=v^{p-1}$, we get
 \begin{eqnarray*}
 &&\mathbb{E}\left[g\left(\frac{X_1}{\sum_{i=1}^{p}X_i},\ldots, \frac{X_{p-1}}{\sum_{i=1}^{p}X_i}\right)\right]\\
&=&\int_{\Delta_{p-1}}\int_{\mathbb{R}_+}g\left(w_1,\ldots, w_{p-1}\right) \frac{e^{- v}\prod_{i=1}^{p-1}w_i^{\alpha_i-1}\left(1-\sum_{i=1}^{p-1}w_i\right)^{\alpha_p-1}v^{\sum_{i=1}^{p-1}\alpha_i-1}}
{\prod_{i=1}^p\Gamma(\alpha_i)}\text{d}\lambda(w_1,\ldots, w_{p-1}, v)\\
&=&\int_{\Delta_{p-1}}g\left(w_1,\ldots, w_{p-1}\right) \frac{\Gamma\left(\sum_{i =1}^{p}\alpha_i\right)}{\prod_{i=1}^p\Gamma(\alpha_i)}\prod_{i=1}^{p-1}w_i^{\alpha_i-1}\left(1-\sum_{i=1}^{p-1}w_i\right)^{\alpha_p-1}\text{d}\lambda(w_1,\ldots, w_{p-1}).
\end{eqnarray*}
\end{proof}
To show that the stochastic process $(W_n^{(1)},\ldots, W_n^{(p)})$ has a Dirichlet limiting distribution we need to introduce a counting process known as Yule process.
\begin{definition}\label{def:yule_process}
A Yule process $(Y_t)_{t\geq0}$ is a pure birth process with linear birth rate given as
\[
\mathbb{P}(Y_{t+h} = y+1|Y_{t} =y) = nh+o(h).
\]
\end{definition}
The Yule process models the population of some particle over time, assuming that there is one particle at time $0$, so $Y_0=1$ this particle will split in two after some exponential time and this going on and on, see the illustration on \cref{fig:yule_tree}.

%définitiondesstyles
\tikzstyle{lien}=[-,>=stealth',rounded corners=5pt,thick] \tikzset{individu/.style={draw,thick}, individu/.default={green}}
%définitiondel’arbre
\begin{figure}[!ht]
\begin{center}
\begin{tikzpicture}
\node[individu] (1) at (0,0) {};
\node[individu] (11) at (-3,-2) {};
\node[individu] (12) at (3,-2) {};
\node[individu] (111) at (-4.5,-4) {};
\node[individu] (112) at (-1.5,-4) {};
\node[individu] (1121) at (-2,-6.5) {};
\node[individu] (1122) at (-1,-6.5) {};
\node[individu] (121) at (1.5,-8) {};
\node[individu] (122) at (4.5,-8) {};
\draw[lien] (1) |- (-1,-1.7)  coordinate[label = {above:$\ExpDist(1)$}] -|  (11);
\draw[lien] (1) |- (1,-1.7)-| (12);
\draw[lien] (11) |- (-3.5,-3.7) coordinate[label = {above:$\ExpDist(1)$}]-| (111);
\draw[lien] (11) |- (-2.5,-3.7)-| (112);
\draw[lien] (112) |- (-1.5,-6.2) coordinate[label = {above left:$\ExpDist(1)$}]-| (1121);
\draw[lien] (112) |- (-1.5,-6.2)-| (1122);
\draw[lien] (12) |- (2.5,-7.7) coordinate[label = {above:$\ExpDist(1)$}]-| (121);
\draw[lien] (12) |- (3.5,-7.7)-| (122);
\draw (122) -- (4.5,-9);
\draw (121) -- (1.5,-9);
\draw (111) -- (-4.5,-9);
\draw (1121) -- (-2,-9);
\draw (1122) -- (-1,-9);
\draw[->] (-5,0) -- (-5,-10) coordinate[label = {below:$t$}] (xmax);
\draw[-, thick, dashed] (-5.5,-7) coordinate[label = {below left:$Y_t = 4$}] -- (5,-7)  (xmax);
\end{tikzpicture}
\caption{Yule tree}
\label{fig:yule_tree}
\end{center}
\end{figure}
Before moving forward, two remarks.
\begin{remark}\label{rem:yule_process_initial}
If we have $Y_0 = y_0$ particles at the initial state, then it is like starting $y_0$ independent copies of the Yule process with one particle and summing up at time $t$ the number of particles of all the Yule processes. Namely, let $(Y_t)_{t\geq0}$ be a Yule process such that $Y_0 = y_0$, then
$$
Y_t = \sum_{i = 1}^{y_0}Y_t^{(i)},
$$
where the $Y_t^{(i)}$'s are independent Yule processes such that $Y_t^{(i)}=1$ for $i = 1,\ldots, y_0$.
\end{remark}
\begin{remark}\label{rem:stopped_yule_process}
The Yule process $(Y_t)_{t\geq0}$ is strong Markov in the sense that for any stopping time $\tau$, the stopped process
$$
\tilde{Y}_t = Y_{\tau+t},\text{ }t\geq0
$$
is again a Yule process such that $\tilde{Y}_0 = Y_\tau$.
\end{remark}
\begin{prop}\label{prop:yule_process_dist}
Let $(Y_t)_{t\geq0}$ be a Yule process such that $Y_0 = 1$ then
$$
\mathbb{P}(Y_t = y) = \left(1-\e^{-t}\right)^{y-1}e^{-t}.
$$

\end{prop}
\begin{proof}
The inter-arrival times $(\Delta^T_n)_{n\geq1}$ of the Yule process are independent random variable such that $\Delta^T_n = \ExpDist(n)$. If we have $n$ particles at some time $t\geq0$, that's $n$ exponential $\ExpDist(1)$ competing and a new particle appears as soon as one of them ring. We then have $\Delta^T_n = \min(X_1,\ldots, X_{n})$, where $X_1,\ldots, X_n \overset{\text{i.i.d.}}{\sim}\ExpDist(1)$ and so $\Delta^T_n \sim \ExpDist(n)$. The arrival time of the $n^{th}$ particles is given by
$$
T_n = \sum_{k =1}^{n-1}\Delta^T_k,\text{ }n\geq2.
$$
By induction on $n\geq2$, we can show that
\[
\mathbb{P}(T_n\leq t) = \left(1-e^{-t}\right)^{n-1}.
\]
We further deduce that
\[
\mathbb{P}(Y_t = y) = \mathbb{P}(Y_t > y) - \mathbb{P}(Y_t > y+1) = \mathbb{P}(T_{y} \leq t) - \mathbb{P}(T_{y+1} \leq t)=\left(1-\e^{-t}\right)^{y-1}e^{-t}
\]
\end{proof}
\begin{theo}\label{theo:convergence_yule_process}
We have that
\[
e^{-t}Y_t\overset{\mathcal{D}}{\longrightarrow}\ExpDist(1),\text{ as }t\rightarrow \infty.
\]
\end{theo}
\begin{proof}
Let us show that $\left(e^{-t}Y_t\right)_{t\geq0}$ is a martingale. We have that, for $s\leq t$,
\[
\mathbb{E}(e^{-t}Y_t|\mathcal{F}_s) = e^{-t}\mathbb{E}(Y_t|\mathcal{F}_s) = e^{-t}Y_se^{t-s} = e^{-s}Y_s.
\]
Because of the martingale convergence theorem, we know that $\left(e^{-t}Y_t\right)_{t\geq0}$ has a limiting distribution. Consider the Laplace transform
\[
\mathbb{E}\left(\e^{-\theta e^{-t}Y_t}\right) = \frac{\e^{-\theta \e^{-t}}\e^{-t} }{1-\e^{-\theta \e^{-t}}(1-\e^{-t})}=\frac{1}{e^t\left(\e^{\theta\e^{-1}}-1\right)+1}\rightarrow\frac{1}{1+\theta},\text{ as }t\rightarrow\infty.
\]
which coincides with that of an exponential random variable $\ExpDist(1)$.

\end{proof}
We finally link the asymptotic behavior of the Yule processes to our initial question about the asymptotic distributions of the stakes.
\begin{theo}
We have that
\[
\left(W_\infty^{(1)},\ldots, W_\infty^{(p)}\right)\sim\text{Dir}\left(Z_0^{(1)},\ldots, Z_0^{(p)}\right).
\]
\end{theo}
\begin{proof}
Assume that each coin owned at time $n=0$ is like the initial particle of a Yule process. That's $Z_0$ Yule processes $(Y_t^{i,j})_{t\geq0}$ for $i = 1, \ldots, Z_0^{(j)}$ and $j = 1,\ldots, p$. Each time step $n$ corresponds to the jump of one of the Yule processes $\tau_n$. The number of coins owned by peer $j=1,\ldots, p$ is then
\[
Z_n^{(j)} = \sum_{i=1}^{Z_0^{(j)}} Y^{i,j}_{\tau_n},
\]
we have $\tau_n\rightarrow\infty$ as $n\rightarrow\infty$ and therefore
\[
e^{-\tau_n}Z_n^{(j)} = \sum_{i=1}^{Z_0^{(j)}} Y^{i,j}_{\tau_n}e^{-\tau_n}\overset{\mathcal{D}}{\longrightarrow} \GammaDist\left(Z_0^{(j)}, 1\right),\text{ as }n\rightarrow\infty
\]
Finally
\[
\left(W_n^{(1)},\ldots, W_n^{(p)}\right) = \left(\frac{e^{-\tau_n}Z_n^{(1)}}{\sum_{j=1}^{p}e^{-\tau_n}Z_n^{(j)}},\ldots, \frac{e^{-\tau_n}Z_n^{(p)}}{\sum_{j=1}^{p}e^{-\tau_n}Z_n^{(j)}}\right)\overset{\mathcal{D}}{\longrightarrow}\text{Dir}(Z_0^{(1)},\ldots, Z_0^{(p)})
,\text{ as }n\rightarrow\infty.
\]
\end{proof}
\begin{remark}\label{req:alternative_proof}
One can take a shorter road to show the above result. Let $(X_n)_{n\geq1}$ be the color of the ball drawn during the $n^{th}$ round. We have that
\begin{equation}\label{eq:polya_sequence_1}
\mathbb{P}(X_1=x) = \frac{Z_0^{(x)}}{Z_{0}}
\end{equation}
and
\begin{equation}\label{eq:polya_sequence_2}
\mathbb{P}(X_{n+1}=x) = \frac{Z_0^{(x)} + \sum_{i=1}^n\delta_{X_i}(x)}{Z_0+n} = \frac{Z_0^{(x)} + \lambda_n(x)}{Z_0+n} = m_n(x)
\end{equation}
where $\delta_{X_i}$ denotes the Dirac measure at $X_i$.
A sequence that satisfies \eqref{eq:polya_sequence_1} and \eqref{eq:polya_sequence_2} is said to be a Polya sequence with parameter $N_x\text{, }x\in E$.
\begin{lemma}
The following statements are equivalent:
\begin{itemize}
\item[(i)] $X_1,X_2,\ldots,$ is a Polya sequence
\item[(ii)] $\mu^{\ast}\sim \text{Dir}(N_x,x\in E)$ and $X_1,X_2,\ldots$ given $\mu^\ast$ are \iid as $\mu^\ast$
\end{itemize}
\end{lemma}
Consider the event $A_n = \{X_1 = x_1,\ldots, X_n = x_n\}$. Induction on $n$ allows us to show that (i) is equivalent to
\begin{equation}\label{eq:P_A_polya_i}
\mathbb{P}(A_n) = \frac{\prod_{x\in E} \left(Z_0^{(x)}\right)^{[\lambda_n(x)]}}{Z_0^{[n]}},
\end{equation}
where $\lambda_n(x)$ is the number of $i$'s in $1,\ldots, n$ for which $x_i = x$ and $a^{[k]} = a(a+1)\ldots(a+k-1)$.  Now assume that $(ii)$ holds true, then
$$
\mathbb{P}(A_n|\mu^\ast) = \prod_{x\in E}\mu^\ast(x)^{\lambda_n(x)},
$$
recall that $\mu^\ast$ is a random vector, indexed on $E$, We denote by $\mu^\ast(x)$ the component associated with $x\in E$. The law of total probability then yields
\begin{equation}\label{eq:P_A_polya_ii}
\mathbb{P}(A_n) = \mathbb{E}\left[\prod_{x\in E}\mu^\ast(x)^{\lambda_n(x)}\right],
\end{equation}
which is the same as \eqref{eq:P_A_polya_i}. Applying the lemma together with the law of large number yields
$$
n^{-1}\sum_{i=1}^n\delta_{X_i}(x) \rightarrow \mu^{\ast}(x)\text{ as } n\rightarrow\infty.
$$
and then $m_n(x)\rightarrow\mu^{\ast}(x)$. This proof is taken from \citet{Blackwell1973}.
\end{remark}
The asymptotic distribution of the stakes among the peers is a Dirichlet random vector denoted by $\mu^{\ast}$ which may be considered as a probability distribution over the set of peers. Decentralization is achieved when the weights do not concentrate around a few nodes. The most desirable situation corresponds to all the peers being equally likely to be selected. It would corresponds to a uniform distribution over the set of peers which would maximizes the Shannon entropy. For $\mu^{\ast}\sim \text{Dir}(Z^{(x)}_0)$, we have
$$
H(\mu^\ast) = -\mathbb{E}\left\{\sum_x \mu^\ast(x)\ln[\mu^\ast(x)]\right\} = -\sum_x\frac{Z_0}{Z_0^{(x)}}\left[\psi(Z_0^{(x)}+1)-\psi(Z_0+1)\right],
$$
where $\psi(x) = \frac{\text{d}}{\text{d}x}\ln[\Gamma(x)]$ is the digamma function, to be compared to $\ln(p)$.

\section{Decentralization in PoW}\label{sec:decentralization_pow}
In \cref{chap:security}, we have observed that mining blocks in a \PoW equipped blockchain is a risky business. Nodes may deviate from the prescribed protocol to counteract that but the most common way to mitigate the underlying risk is to join forces by forming mining pool. A mining pool is a joint initiative of miners that pool their computing ressources to make their capital gains more frequent and therefore have a steadier income. Consider a network of $n$ miners of hashpower $p_i, \text{ }i = 1,\ldots, n$ and assume that a subset $I\in \{1,\ldots, n\}$ decides to form a mining pool. The cumulated hashpower of this pool is then
\[
p_I = \sum_{i\in I}p_i.
\]
and the arrival rate of block rewards for a given miner $i$ rises from $p_i\cdot\lambda$ to $p_I\cdot\lambda$. Because the reward is shared among the pool participants, the size of the reward collected by miner $i$ decreases from $b$ to $p_i\cdot b$. The expected surplus is the same when mining solo and mining for a pool, but the variance (and therefore the risk) is smaller when mining for a pool. The management of a mining pool relies heavily on the reward distribution mechanism set up by a pool manager. For the redistribution system to be fair, each miner must be remunerated in proportion to her calculation effort. Miner $i$ must earn a share $p_i/p_I$
of the mining pool total income. The pool manager has to find a way to estimate the contribution of each pool participant. This is done by submitting \textit{shares} which are partial solutions to the cryptopuzzle easier to find than the actual solution. For instance, if the target is such that the hash value for finding a block must starts with $4$ leading zeros then a partial solution could be a hash value with $3$ leading zeros.  If the current difficulty of the cryptopuzzle is $D$, then the difficulty for finding a \textit{share} is set to $q\cdot D$ by the pool manager, where $q\in(0,1)$. The manager's cut is a fraction $f\in(0,1)$ of the block discovery reward $b$.\\

\noindent \cref{ssec:mining_pool_reward_system} presents the mining pool remuneration schemes and introduces the \textit{Pay-per-Share} (PpS) system on which we will focus. \cref{ssec:mining_pool_risk_analysis} defines risk models for miners and pool managers participating to a PpS pool.

\subsection{Mining pools and reward systems}\label{ssec:mining_pool_reward_system}
\subsubsection{Proportional reward system}
The proportional reward system splits time in \textit{rounds} which correspond to the time elapsed between two block discoveries. During these \textit{rounds}, the miners submit \textit{shares}. The ratio of the number of \textit{shares} submitted by miner $i$ over the total number of \textit{shares} submitted by her fellow mining pool participants determines her share of the reward and should converge to her share of the mining pool computing power, that is $p_i/p_I$ (for sufficiently low complexity of the shares, the latter limit will be a very good approximation for the actual situation indeed). The surplus of miner $i$ is then given
\begin{equation}\label{eq:surplus_miner_proportional}
R_t^i = u - c_i\cdot t + N^I_t\cdot (1-f)\cdot \frac{p_i}{p_I}\cdot b,\text{ }t\geq0,
\end{equation}
where $(N^I_t)$ is a Poisson proccess of intensity $p_I\cdot\lambda$ that gives the number of blocks appended to the blockchain by the mining pool. The duration of a \textit{round} is exponentially distributed $\text{Exp}\left[(p_I\lambda)^{-1}\right]$. The uncertainty on the length of the round has undesirable consequences on the time value of the \textit{shares} submitted by the miners. Indeed, if $n$ shares are submitted during a round, then the value of a given \textit{share} is $(1-f)\cdot b / n$. The longer a \textit{round} lasts, the greater the value of $n$ is. The \textit{shares} are worth less in longer rounds which triggers an exodus behavior of miners toward mining pools with shorter rounds. This phenomenon, called pool hopping, has been documented in the early work of Rosenfeld \citet{rosenfeld2011analysis}. Yet another drawback is that a miner that has found a full solution may delay the submission until her ratio of \textit{shares} submitted reflects her fraction of the mining pool computing power. The proportional system is not \textit{incentive-compatible} using the terminology of Schrijvers et al. \citet{Schrijvers2017}. A discounting factor may be applied to compensate the decreasing value of shares over time, see for instance the slush's method \citet{slush}. Now if we take a look at the risk undertaken by pool managers. Within the frame of the proportional reward system, the surplus of the pool manager is given by
\begin{equation}\label{eq:surplus_pool_manager_proportional}
R_t^I = u + N^I_t\cdot f\cdot b,\text{ }t\geq0.
\end{equation}
Model \eqref{eq:surplus_pool_manager_proportional} does not account for any mining pool operating cost. The mining costs are entirely borne by miners and the mining pool manager only serves as coordinator. A proportional-type reward system should therefore lead to a low management fee $f$. \\

\noindent Although this system provides fairness, it has weaknesses that justify the introduction of a more sophisticated distribution mechanism. In particular, if miners seek to actually transfer some of the risk associated to the mining activity to the pool manager, then they should rather turn to a mining pool based on a \textit{Pay-per-Share} system, which is the focus of the next section.
\subsubsection{Pay-per-Share reward system}\label{eq:pps}
In a \textit{Pay-per-Share} reward system, the pool manager immediately rewards the miners for each \textit{share} submitted. Let $(M_t)_{t\geq0}$ be a Poisson process of intensity $\mu$ that counts the number of \textit{shares} submitted by the entire network of miners up to time $t\geq0$. Denote by $q\in(0,1)$ the relative difficulty of finding a block compared to finding a share. Let $0<w<b$ be the reward for finding a \textit{share}. The number of \textit{shares} submitted by miner $i$ is then a (thinned) Poisson process $(M^i_t)_{t\geq0}$ with intensity $p_i\cdot\mu$, $p_i$ being the share of the individual miner's network hashpower as defined above, and her surplus when joining a PpS mining pool becomes
\begin{equation}\label{eq:surplus_miner_pps}
R_t^i = u - c_i\cdot t + M^i_t\cdot w,\text{ }t\geq0.
\end{equation}
The intensities of the processes $(N_t)_{t\geq0}$ and $(M_t)_{t\geq0}$ are linked through $\lambda  = q\cdot\mu$. By setting $w=(1-f)\cdot b\cdot q$, we observe that the surplus \eqref{eq:surplus_miner_proportional} and \eqref{eq:surplus_miner_pps} have the same expectation at time $t$, but the variance and therefore the risk associated to \eqref{eq:surplus_miner_pps} is lower. This reward system has been shown to be resistant to pool hopping and is incentive compatible. It also entails a significant transfer of risk to the pool manager whose surplus process is now given by
\begin{equation}\label{eq:surplus_manager_pps}
R^I_t = u - M_t^I\cdot w + N_t^I\cdot b,\text{ }t\geq0,
\end{equation}
making her subject to the risk of bankruptcy.

\begin{remark}\label{remark_Md}
Since the process $(M_t^I)_{t\geq 0}$ requires solving for a problem of lower complexitiy than $(N_t^I)_{t\geq 0}$, ($N_t^I)_{t\geq 0}$ is a subset of the path defined by the process $(M_t^I)_{t\geq 0}$. It means that both processes are not independent. Concretely, at the moment of the block reward payment $b$, at the same time there is a realisation of the miners' reward $w$. As we sometimes need to isolate downward jumps without the simultaneous upward jump point, we define another process with a reduced intensity. We apply the superposition theorem (see e.g. \cite{Kingman1993}) to the Poisson process $M_t^I$ by redefining the down jump process as $(M_t^{I,d})_{t\geq 0} \sim Poisson(\mu_d)$, where $\mu_d = \mu-\lambda$.
\end{remark}
\noindent In addition to the bounty for finding a new block, blockchain users usually include a small financial incentive for the network to process their transaction. These transaction fees (e.g.\ referred to as \textit{gas} within the ETHEREUM blockchain), are known to be variable as they highly depend on the network congestion at a given time. Note also that since the operational cost is paid by miners using a fiat currency, it would be more accurate to account for the exchange rate of the cryptocurrency to some fiat currency. We can therefore model the successive rewards for \textit{shares} and blocks as sequences of nonnegative random variables denoted by $(W_k)_{k\geq1}$ and $(B_k)_{k\geq1}$ respectively, which for simplicity we will both assume to be \textit{i.i.d.}\  exponential variables in these notes. A reward system that features a \textit{Pay-per-Share} mechanism and includes in the miners' reward the transaction fees is referred to as a \textit{Full Pay-per-Share} reward system by practitioners. The surplus of miner $i$ in a mining pool applying the FPpS\,system is given by
\begin{equation}\label{eq:surplus_miner_fpps}
R_t^i = u - c_i\cdot t + \sum_{k = 1}^{M^i_t}W_k,\text{ }t\geq0,
\end{equation}
and the surplus of the pool manager then becomes
\begin{equation}\label{eq:surplus_manager_fpps}
R^I_t = u - \sum_{k = 1}^{M^I_t}W_k + \sum_{l = 1}^{N_t^I}B_l,\text{ }t\geq0.
\end{equation}
The next section is devoted to deriving formulas for the ruin probability and expected surplus in case ruin did not occur up to a given time horizon for the models discussed above.

\subsection{Mining pool risk analysis}\label{ssec:mining_pool_risk_analysis}

\subsubsection{From the miners' viewpoint}\label{sssec:miner_viewpoint}
Consider miner $i\in \{1,\ldots, n\}$ with hashpower $p_i\in(0,1)$ that joined a FPpS mining pool $I\subset\{1,\ldots, n\}$ with relative difficulty $q\in(0,1)$ and management fee $f\in(0,1)$. Let $\lambda$ the average number of solutions published by the network per time unit and let $\mu = \lambda/q$ be the average number of partial solutions. The surplus of miner $i$ in a mining pool applying the FPpS\,system is given by
\begin{equation*}
R_t^i = u - c_i\cdot t + \sum_{k = 1}^{M^i_t}W_k,\text{ }t\geq0,
\end{equation*}
where $(M^i_t)_{t\geq0}$ is a Poisson process with intensity $\mu \cdot p_i$, and the $W_k$'s are \iid exponential variable with mean $w = (1-f)\cdot q\cdot b$. The ruin time is defined as
$$
\tau_u^{(i)} = \inf\{t\geq0\text{ ; } R_t^i = 0\},
$$
and the net profit condition reads as
$$
(1-f)\cdot p^{i}\cdot b\cdot \lambda>c_i.
$$
We first provide the probability distribution of $\tau_u^{i}$.
\begin{theo}\label{theo:pdf_ruin_time_miner_in_pool}
The ruin time $\tau_u^{(i)}$ takes value $t\geq u/c_i$. It has an atom of probability with
\[
\mathbb{P}(\tau_u^{(i)} = u/c_i) = \mathbb{P}(M^{(i)}_{u/c_i}=0)=\e^{-p_i\mu u/c_i}
\]
and \pdf given by
\begin{equation}\label{eq:pdf_ruin_time_miner_in_pool}
f_{\tau_u^{(i)}}(t)=\frac{u}{t}\mathbb{E}\left[f_{W}^{\ast M_t^{(i)}}(c_i t-u)\mathbb{I}_{M^{(i)}_t \geq1}\right]\text{, for }t\geq u/c_i.
\end{equation}
\end{theo}
\begin{proof}
Ruin is not possible before time $u/c_i$. It may occur exactly at time $t = u/c_i$ if no capital gain occur before that time. Hence we have
$$
\mathbb{P}(\tau_u^{(i)} = u/c_i) = \mathbb{P}(M_{u/c_i} = 0) = \exp\left(-p_i\mu \frac{u}{c_i}\right).
$$
Now consider some time $t>u/c_i$. We have that
\begin{equation*}
\{\tau_u^{(i)}\in(t,t+\text{dt})\} = \bigcup_{n = 1}^{+\infty}\left\{M_t^{(i)} = n \right\}\cap\{\tau_u^{(i)}\in(t,t+\text{dt})\},\\
\end{equation*}
and therefore
\begin{equation}\label{eq:law_of_total_prob}
\mathbb{P}\left[\tau_u^{(i)}\in(t,t+\text{dt})\right] = \sum_{n = 1}^{+\infty}\mathbb{P}\left[\tau_u^{(i)}\in(t,t+\text{dt})\big\rvert M_t^{(i)} = n\right]\mathbb{P}\left(M_t^{(i)} = n \right).
\end{equation}
Note that
\[
\left\{M_t^{(i)} = n \right\}\cap\{\tau_u^{(i)}\in(t,t+\text{dt})\} =\left\{M_t^{(i)} = n \right\}\cap\bigcap_{k = 1}^{n}\{T_k\leq\frac{S_{k-1}+u}{c_i}\}\cap\left\{\frac{S_n+u}{c_i}\in(t,t+\text{dt})\right\}.
\]
We then have
\begin{eqnarray*}
&&\mathbb{P}\left[\tau_u^{(i)}\in (t,t+\text{d}t)\big\rvert M_t^{(i)} = n \right]\\
&=&\mathbb{P}\left[\bigcap_{k = 1}^{n}\left\{T_k\leq\frac{S_{k-1}+u}{c_i}\right\}\cap\left\{\frac{S_n+u}{c_i}\in(t,t+\text{dt})\right\}\big\rvert M_t^{(i)} = n \right]\\
&=&\mathbb{P}\left[\bigcap_{k = 1}^{n}\left\{
U_{(k)}\leq\frac{S_{k-1}+u}{c_i t}
\right\}
\Big\rvert\frac{S_n+u}{c_i}\in(t,t+\text{dt})\right]
\mathbb{P}\left[\frac{S_n+u}{c_i}\in(t,t+\text{dt})\right]\\
&=&\mathbb{P}\left[\bigcap_{k = 1}^{n}\left\{
U_{(k)}\leq\frac{S_{k-1}+u}{c_i t}
\right\}
\Big\rvert S_{n}=c_i t -u\right]
c_i f_{W}^{\ast(n)}(c_i t -u)\\
&=&\mathbb{E}\left\{\mathbb{P}\left[\bigcap_{k = 1}^{n}\left\{
U_{(k)}\leq\frac{S_{k-1}+u}{c_i t}
\right\}\Big\rvert S_1,\ldots, S_n\right]
\Big\rvert S_{n}=c_i t -u\right\}
c_i f_{W}^{\ast(n)}(c_i t -u)\\
&=&\mathbb{E}\left\{(-1)^nG_n\left(0\Big\rvert \frac{S_0+u}{c_i t}, \ldots, \frac{S_{n-1}+u}{c_i t}\right)
\Big\rvert S_{n}=c_i t -u\right\}
c_i f_{W}^{\ast(n)}(c_i t -u)\\
&=&\frac{(-1)^n}{(c_it)^{n} }\mathbb{E}\left[G_n\left(-u\Big\rvert S_0, \ldots, S_{n-1}\right)
\Big\rvert S_{n}=c_i t -u\right]
c_i f_{W}^{\ast(n)}(c_i t -u)\\
&=&\frac{(-1)^n}{(c_it)^{n} }(-u)(-u-c_i t + u)^{n-1}
c_i f_{W}^{\ast(n)}(c_i t -u) \\
&=& \frac{u}{ t}f_{W}^{\ast(n)}(c_i t -u) .
\end{eqnarray*}
Reinserting in \eqref{eq:law_of_total_prob} yields the result.

\end{proof}
\noindent The infinite serie in \eqref{eq:pdf_ruin_time_miner_in_pool} is problematic for numerical purposes although a workable approximation may be otained by truncating it. Just like in \cref{chap:security}, we shall consider an exponential time horizon $T\sim\ExpDist(t)$ instead of a deterministic one and compute
\[
\widehat{\psi}(u,t) = \mathbb{P}(\tau_u \leq T),\text{ and }\widehat{V}(u,t) = \mathbb{E}(R_T\mathbb{I}_{\tau_u > T}).
\]
We start with the ruin probability
\begin{prop}\label{prop:rp_hat_miner_in_pool}
The ruin probability up to an exponential time horizon is given by
\[
\widehat{\psi}(u,t) = e^{\theta^{\ast} u}
\]
where $\theta^{\ast}$ is the solution of the equation
\[
p_i\mu + 1/t - c_i \theta = p_i\mu\mathbb{E}\left(e^{-\theta W}\right)
\]
\end{prop}
\begin{proof}
Define the process
\[
S_t^{(i)} = R^{(i)}_t-u =c_i t-\sum_{k = 1}^{N_t}W_k,
\]
as it is a Levy process then the process
\[
M_t^{(i)}=\exp\left(\theta S_t^{(i)} - t\kappa(\theta)\right),
\]
is a martingale, where
\[
\kappa(\theta) =\log \mathbb{E}(e^{\theta S_1^{(i)}}) = c_i\theta + p_i\mu \mathbb{E}\left(e^{-\theta W}\right) -\mu p_i
\]
We apply the optional stopping theorem at time $\tau_u\land T_1$, where $T_1>0$ to get
\begin{eqnarray*}
\mathbb{E}\left(M_0^{(i)}\right) &=& \mathbb{E}\left(M_{\tau_u^{(i)}\land T_1}^{(i)}\right)\\
1 &=& \mathbb{E}\left(M_{\tau_u^{(i)}}|\tau_u^{(i)} < T_1\right)\mathbb{P}(\tau_u^{(i)} < T_1)+\mathbb{E}\left(M_T|\tau_u^{(i)} \geq T_1\right)\mathbb{P}(\tau_u^{(i)} \geq T_1)
\end{eqnarray*}
By letting $T_1\rightarrow \infty$ we get
\begin{eqnarray*}
1 &=& \mathbb{E}\left(M_{\tau_u^{(i)}}|\tau_u^{(i)} < \infty\right)\mathbb{P}(\tau_u^{(i)} < \infty)\\
1 &=& \e^{\theta u}\mathbb{E}\left(\e^{-\kappa(\theta) \tau_u^{(i)}}|\tau_u^{(i)} < \infty\right)\mathbb{P}(\tau_u^{(i)} < \infty)
\end{eqnarray*}
Let $s>0$ and $\theta(s)$ be the unique positive solution of the equation $\kappa(\theta) =s$, then
\begin{eqnarray*}
1 &=& \e^{\theta(s) u}\mathbb{E}\left(\e^{-\kappa(\theta(s)) \tau_u^{(i)}}|\tau_u^{(i)} < \infty\right)\mathbb{P}(\tau_u^{(i)} < \infty)\\
1 &=& \e^{\theta(s) u}\mathbb{E}\left(\e^{-s\tau_u^{(i)}}|\tau_u^{(i)} < \infty\right)\mathbb{P}(\tau_u^{(i)} < \infty)\\
1 &=& \e^{\theta(s) u}\mathbb{E}\left(\e^{-s\tau_u^{(i)}}\right)\\
\mathbb{E}\left(\e^{-s\tau_u^{(i)}}\right) &=& \e^{-\theta(s) u}\\
\end{eqnarray*}
Note that
\[
\widehat{\psi}(u,t) = \mathbb{P}(\tau_u^{i}\geq T) = \mathbb{E}(e^{-\tau_u^{(i)}/t}) = \e^{-\theta(1/t) u}.
\]
\end{proof}
\begin{prop}\label{prop:rp_hat_miner_in_pool}
The expected wealth up to an exponential time horizon is given by
\[
\widehat{V}(u,t) = t(c_i-p_i\mu w)e^{-\theta^{\ast} u}+u +t(p_i\mu w - c_i)
\]
where $\theta^{\ast}$ is the positive solution of the equation
\[
-c_i\theta^{2}+\theta\left(\frac{1}{t}+p_i\mu-\frac{c_i}{w}\right)+\frac{1}{wt} = 0.
\]
\end{prop}
\begin{proof}
Conditionning upon the events that may occur over th time interval $(0,h)$ with
\begin{itemize}
    \item $T>h$ and no partial solution submitted
    \item $T\leq h$ and no partial solution submitted
    \item A partial solution submitted before $T$ and $h$
\end{itemize}
It then holds that
\begin{eqnarray*}
\widehat{V}(u,t) &=&\e^{-h(1/t + \mu p_i)}\widehat{V}(u-ch,t)+\int_{0}^{h}\frac{1}{t}\e^{-h(1/t + \mu p_i)}(u-cs)\text{d}s\\
&+& \int_{0}^{h}\int_{0}^{+\infty}\mu p_i\e^{-h(1/t + \mu p_i)}\widehat{V}(u-cs+x,t)\frac{\e^{-x/w}}{w}\text{d}x\text{d}s.
\end{eqnarray*}
Differentiating with respect to $h$ and letting $h\rightarrow\infty$ yields
\begin{equation}\label{eq:integro_differentiql_equation_miner_in_pool}
\left(\frac{1}{t}+p_i\mu\right)\widehat{V}(u,t)+c_i\widehat{V}'(u,t)-\frac{u}{t}-\int_0^{+\infty}\widehat{V}(u+x,t)\frac{p_i\mu}{w}\e^{-x/w}\text{d}x=0,
\end{equation}
with boundary conditions \(\widehat{V}(0,t) = 0\) and \(0\leq \widehat{V}(u,t)\leq u-c_i t +p_i\mu w\). The solution is of the form
\begin{equation}\label{eq:ansatz}
\widehat{V}(u,t) = A+Bu+C\e^{-\theta u},
\end{equation}
so that
\begin{equation}\label{eq:ansatz_derivative}
\widehat{V}'(u,t) = B-\theta C\e^{-\theta u}.
\end{equation}
Reinserting \eqref{eq:ansatz} and \eqref{eq:ansatz_derivative} into \eqref{eq:integro_differentiql_equation_miner_in_pool}, together with the boundary condition, yields the following system of equation
\begin{equation}
\begin{cases}
\frac{A}{t}-Bp_i\mu w+Bc =0\\
B\left(\frac{1}{t}+p_i\mu\right)-\frac{1}{t}-Bp_i\mu = 0\\
\left(\frac{1}{t}+p_i\mu\right)-\theta c -\frac{p_i\mu}{1+\theta w}=0\\
A+C = 0
\end{cases}
\end{equation}
It follows that $B = 1$, $A = t(p_i\mu w-c_i)$, $C = -A$ and $\theta^{\ast}$ is solution to
$$
-c_i\theta^{2}+\theta\left(\frac{1}{t}+p_i\mu-\frac{c}{w}\right)+\frac{1}{wt} = 0.
$$

\end{proof}
\begin{ex}\label{ex:miner_in_pool}
Consider a miner with haspower $p = 0.01$. Let the BTC price be $\$36347.89$, and the reward be $\text{BTC}6.25 = \$248460.12$. If the time unit is the hour then $\lambda = 6$ so that one block is generated every ten minutes on average. The network consumes $10914487\text{kWh}$ per time unit. Suppose that our miner is joining a mining pool with a management fee $f = 0.05$. The ruin probability of the miner as a function of the initial reserve $u$ for a time horizon of one week is shown in \cref{fig:rp_miner_in_pool} for various relative difficulty $q = 0.25, 0.5, 0.75$.
\begin{figure}[!ht]
  \begin{center}
      \includegraphics[width = 0.5\textwidth]{../Figures/rp_miner_in_pool}
    \caption{Ruin probability of a miner in mining pool as a function of the initial reserves depending on the relative difficulty proposed by the pool manager $q\in \{0.25, 0.5, 0.75\}$.}
    \label{fig:rp_miner_in_pool}
  \end{center}
\end{figure}
The ruin probability of a miner, mining on his own is also plotted. We see that joining a mining pool is beneficial as it reduces significantly the ruin probability.
\end{ex}

\subsubsection{From the pool manager's viewpoint}\label{ssec:manager_viewpoint}
Consider a pool manager that coordinate a FPpS mining pool $I\subset\{1,\ldots, n\}$. The manager sets the relative difficulty of finding a share compared to finding a block to $q\in(0,1)$. If we let $(N_t)_{t\geq0}$ and $(M_t)_{t\geq0}$ be Poisson processes with respective intensity $\lambda$ and $\mu$ equal to the number of block and \textit{shares} find by the network then we have $\lambda = q\mu$. Note that a \textit{share} that turns out to be a proper solution triggers a jump for both $(N_t)_{t\geq0}$ and $(M_t)_{t\geq0}$. The two processes are dependent because the paths of $(N_t)_{t\geq0}$ is a subset of the path of $(M_t)_{t\geq0}$. To isolate the jumps of the two processes we define a Poisson process $(\tilde{M}_t)_{t\geq0}$ of intensity $\mu^{\ast} = \mu -\lambda$ which corresponds to the \textit{share} that do not solve the cryptopuzzle. We have that
\[
M_t = N_t+\tilde{M}_t,\text{ }t\geq0\text{ a.s.,}
\]
where $N_t$ and $\tilde{M}_t$ are independent Poisson processes. The number of shares and blocks found by the pool are then thinned versions $(N_t^I)$ and $\tilde{M}_t^{I}$ of the former processes with respective intensity $p_I\lambda$ and $p_I\mu^{\ast}$. The wealth of the pool manager is given by
\begin{equation}\label{eq:wealth_pool_manager_fpps}
R^I_t = u - \sum_{k = 1}^{\tilde{M}^I_t}\tilde{W}_k + \sum_{l = 1}^{N_t^I}\tilde{B}_l,\text{ }t\geq0,
\end{equation}
where $\tilde{B}_l\overset{iid}{\sim}\ExpDist\left(1/b^{\ast}\right)$, $b^{\ast} = b-w$, and $W_k\overset{iid}{\sim}\ExpDist(1/w)$. The following result provides formulas for the ruin probability $\widehat{\psi}(u,t)$ and expected surplus $\widehat{V}(u,t)$ of the pool manager up to an exponential time horizon $T\sim \ExpDist(1/t)$. The ruin time is defined as
\[
\tau_u = \inf\{t\geq0\text{ ; }R^I_t<0\},
\]
which means that the pool manager may start with no initial reserves. In the following theorem we omit the superscript $I$ and remove the $p^{I}$ from the intensities of the Poisson processes
\begin{theo}
The ruin probability is given by
\begin{equation*}\label{psiexpe}
    \widehat{\psi}(u,t) = (1-Rw)  e^{-R u},\;u\ge 0,
\end{equation*}
and the expected profit is given by
\begin{equation*}\label{Vcombexpe}
    \widehat{V}(u,t) = (1 - Rw)[w-t(\lambda b^\ast-\mu^\ast w)] e^{-R u}+u+t(\lambda b^\ast-\mu^\ast w),
\end{equation*}
where $R$ is the (unique) solution with positive real part of
\begin{equation*} \label{VLunde}
    -(t^{-1}+\lambda+\mu^\ast)+\lambda(1+b^\ast r)^{-1}+\mu^\ast(1-wr)^{-1}=0.
\end{equation*}
\end{theo}
\begin{proof}
Let us consider only $\widehat{V}(u,t)$ (the reasoning is the same for $\widehat{\psi}(u,t)$).
We condition upon what happen during the time interval $(0,h)$. Four possibilities
\begin{itemize}
  \item[(i)] $T>h$ and no jump during $(0,h)$
  \item[(ii)] $T<h$ and no jump over $(0,T)$
  \item[(iii)] An upward jump in the interval $(0,h)$
  \item[(iv)] A downward jump in the interval $(0,h)$
\end{itemize}
  \begin{eqnarray*}\label{neu0}
      \widehat{V}(u,t)&=& e^{-(\frac{1}{t}+\lambda+\mu^\ast)h}\widehat{V}(u,t) + \frac{1}{t}\int_0^h e^{-{s}/{t}}e^{-(\lambda +\mu^\ast) s} u\,ds\\
      & +& \lambda\int_0^he^{-\lambda s} e^{-({1}/{t}+\mu^\ast) s} \int_0^\infty\widehat{V}(u+x,t)\,dF_{B}(x)\,ds\\
      &  +&\mu^\ast \int_0^he^{-\mu^\ast s} e^{-({1}/{t}+\lambda) s}\int_0^u \widehat{V}(u-y,t) \,dF_W(y)\,ds.
  \end{eqnarray*}
  Differentiating with respect to $h$ and letting $h\rightarrow 0$ yields the following integral equation
  \begin{equation} \label{inteq}
    \lambda\int_0^\infty\widehat{V}(u+x,t)\,dF_{B}(x)-(\lambda+\mu^\ast+{1}/{t})\widehat{V}(u,t)+\mu^\ast\int_0^u \widehat{V}(u-y,t) \,dF_W(y)+{u}/{t}=0,\quad u\ge 0,
  \end{equation}
  with boundary conditions $\widehat{V}(u,t)=0$ for all $u<0$ and $0\leq\widehat{V}(u,t)\leq u+(\lambda b^\ast - \mu^\ast w)t$. Let us plug in the ansatz
  $$
  Ae^{-ru}+Bu+C
  $$
  \begin{itemize}
    \item Comparing the terms in $e^{-r u}$ gives and equation for $r$
    $$
    -(t^{-1}+\lambda+\mu^\ast)+\lambda(1+b^\ast r)^{-1}+\mu^\ast(1-wr)^{-1}=0
    $$
    of which only the positive solution $R>0$ is valid due to the boundary conditions.
    \item Comparing the terms in $u$ yields $B = 1$
    \item Comparing the terms in $1$ yields
    $$
    C = t(\lambda b^\ast-\mu^\ast w)
    $$
    \item Comparing the terms in $e^{-u/w}$
    $$
    A = (1 - Rw)[w-t(\lambda b^\ast-\mu^\ast w)]
    $$
\end{itemize}
\end{proof}

\begin{ex}\label{ex:rp_pool_manager}
Consider a mining pool with hashpower $p_I = 0.1$ and management fee $f = 0.05$. Let the BTC price be $\$36347.89$, and the reward be $\text{BTC}6.25 = \$248460.12$. If the time unit is the hour then $\lambda = 6$ so that one block is generated every ten minutes on average. \cref{fig:rp_pool_manager} displays the ruin probability of the pool manager as a function of the initial reserves depending on the relative difficulty.
\begin{figure}[!ht]
  \begin{center}
      \includegraphics[width = 0.5\textwidth]{../Figures/rp_pool_manager}
    \caption{Ruin probability of a pool manager as a function of the initial reserves depending on the relative difficulty $q\in \{0.25, 0.5, 0.75\}$.}
    \label{fig:rp_pool_manager}
  \end{center}
\end{figure}
The ruin probability is higher for low relative difficulty.
\end{ex}
\subsubsection{Risk of centralization?}\label{ssec:numerical_illustrations}
Th risk of centralization exists because a mining pool that is growing larger canb reduce the management fee while maintaining the same profitability. Consider a mining pool with initial reserves $u = 10^6$ and relative difficulty $q=0.25$. The time horizon is $t = 168$ (one week). \cref{fig:level_plot_V_pool_manager_p_f} shows the expected wealth as a function of $p$ and $f$.
\begin{figure}[!ht]
  \begin{center}
      \includegraphics[width = 0.5\textwidth]{../Figures/level_plot_V_pool_manager_p_f}
    \caption{Expected wealth as a function of $p_I$ and $f$.}
    \label{fig:level_plot_V_pool_manager_p_f}
  \end{center}
\end{figure}
A large mining pool offers lower fees, thus attracts more miner and grows even larger. However a large mining pool cannot offer the same level of risk transfer than smaller mining pool. Consider two mining pool with respective hashpower $p_1 = 0.05$ and $p_2 = 0.2$ and initial reserves $u = 10^6$. The time horizon is $t = 168$ (one week). \cref{fig:level_plot_V_pool_manager_p_f} shows the expected wealth for each of these mining pool as a function of $q$ and $f$.
\begin{figure}[!ht]
  \begin{center}
      \includegraphics[width = \textwidth]{../Figures/level_plots_V_pool_manager_q_f}
    \caption{Expected wealth as a function of $p_I$ and $f$.}
    \label{fig:level_plots_V_pool_manager_q_f}
  \end{center}
\end{figure}
To offer the same level of risk transfer a larger mining pool needs to increase the fee. Centralization may prevail if the miner's preferences in terms of profitability and risk transfer are heterogenous. A game theoretic framework must be introduced to appropriately model the behaviors of the miners and mining pool manager, see the works of \citet{li2019mean} and \citet{Cong2020}.
\newpage


\chapter{DT Block Diagrams}

\section{The Four Basic Motifs}

Block diagrams of DT systems are similar to CT systems.

The four motifs are:

\begin{itemize}
\item A single block.\\[1em]
\begin{tikzpicture}[auto, node distance=2cm,>=latex',scale=1, every node/.style={transform shape}]
    \node [input, name=input] {};
    \node [block, right of=input] (system) {$\mathcal{S}_1$};
    \node [output, right of=system] (output) {};

    \draw [draw,->] (input) -- node {$x[n]$} (system);
    \draw [->] (system) -- node {$y[n]$} (output);
\end{tikzpicture}

\item A {\it series} connection of two blocks\\[1em]
\begin{tikzpicture}[auto, node distance=2cm,>=latex',scale=1, every node/.style={transform shape}]

    \node [input, name=input] {};
    \node [block, right of=input] (system1) {$\mathcal{S}_1$};
    \node [block, right of=system1,node distance=4cm] (system2) {$\mathcal{S}_2$};
    \node [output, right of=system2] (output) {};

    \draw [draw,->] (input) -- node {$x[n]$} (system1);
    \draw [->] (system1) -- (system2);
    \draw [->] (system2) -- node {$y[n]$} (output);
\end{tikzpicture}
\item A {\it parallel} connection of two blocks\\[1em]
\begin{tikzpicture}[auto, node distance=2cm,>=latex',scale=1, every node/.style={transform shape}]

    \node[shape=coordinate] at (1,1) (input1) {};
    \node[block] at (3,1) (block1) {$\mathcal{S}_1$};
    \node[shape=coordinate] at ($(block1.east)+(0.5,0)$) (output1) {};
    \draw[->] (input1) -- (block1);
    \draw (block1) -- (output1);

    \node[shape=coordinate] at (1,-1) (input2) {};
    \node[block] at (3,-1) (block2) {$\mathcal{S}_2$};
    \node[shape=coordinate] at ($(block2.east)+(0.5,0)$) (output2) {};
    \draw[->] (input2) -- (block2);
    \draw (block2) -- (output2);

    \node [input, name=input] at (0,0) {};
    \node [input, name=conn] at (1,0) {};
    \draw (conn) -- (input1);
    \draw (conn) -- (input2);
    \node [sum, right of=input,node distance=5cm] (sum) {$\Sigma$};
    \draw [->] (output1) -| (sum);
    \draw [->] (output2) -| (sum);

    \draw [draw] (input) -- node {$x[n]$} (conn);
    \node [output, right of=sum] (output) {};
    \draw [->] (sum) -- node {$y[n]$} (output);
\end{tikzpicture}

\item A {\it feedback} connection\\[1em]
\begin{tikzpicture}[auto, node distance=2cm,>=latex',scale=1, every node/.style={transform shape}]
    \node[block] at (4,0) (block1) {$\mathcal{S}_1$};

    \node[block] at (4,-2) (block2) {$\mathcal{S}_2$};
    \node[shape=coordinate] at (6,-2) (input2) {};

    \node [input, name=input] at (0,0) {};
    \node [shape=coordinate, name=conn] at (6,0) {};
    \draw (block1) -- (conn);
    \draw (conn) -- (input2);
    \draw [->] (input2) -- (block2);

    \node [sum, right of=input,node distance=2cm] (sum) {$\Sigma$};
    \draw [->] (block2) -| node[pos=0.95] {$-$} (sum);

    \draw [draw,->] (input) -- node {$x[n]$} (sum);
    \draw [->] (sum) -- (block1);
    \node [output, right of=conn] (output) {};
    \draw [->] (conn) -- node {$y[n]$} (output);
\end{tikzpicture}
\end{itemize}

Note the feedback is negative (the minus sign on the feedback summation input). As in CT, these can be use in various combinations.

\section{Connections to Convolution}

Each subsystem, $\mathcal{S}_i$, can be represented by a basic discrete time-domain operation (e.g. differences, running sums, addition, and scaling) or more generally by it's impulse response $h_i[n]$.

For example a block representing an system acting as a delay of one sample is typically drawn as

\begin{center}
  \begin{tikzpicture}[auto, node distance=2cm,>=latex',scale=1, every node/.style={transform shape}]
    \node [input, name=input] {};
    \node [block, right of=input] (system) {$D$};
    \node [output, right of=system] (output) {};
    \draw [draw,->] (input) -- node {$x[n]$} (system);
    \draw [->] (system) -- node[pos=2] {$y[n] = x[n-1]$} (output);
\end{tikzpicture}
\end{center}
This is equivalent to an impulse response $h[n] = \delta[n-1]$ so that it might also be drawn as
\begin{center}
  \begin{tikzpicture}[auto, node distance=2cm,>=latex',scale=1, every node/.style={transform shape}]
    \node [input, name=input] {};
    \node [block, right of=input] (system) {$h[n] = \delta[n-1]$};
    \node [output, right of=system] (output) {};

    \draw [draw,->] (input) -- node {$x[n]$} (system);
    \draw [->] (system) -- node[pos=4] {$y[n] = x[n] * \delta[n-1] = x[n-1]$} (output);
\end{tikzpicture}
\end{center}

Similarly, a block representing an system acting as an advance of one sample is typically drawn as

\begin{center}
  \begin{tikzpicture}[auto, node distance=2cm,>=latex',scale=1, every node/.style={transform shape}]
    \node [input, name=input] {};
    \node [block, right of=input] (system) {$E$};
    \node [output, right of=system] (output) {};
    \draw [draw,->] (input) -- node {$x[n]$} (system);
    \draw [->] (system) -- node[pos=2] {$y[n] = x[n+1]$} (output);
\end{tikzpicture}
\end{center}
This is equivalent to an impulse response $h[n] = \delta[n+1]$ so that it might also be drawn as
\begin{center}
  \begin{tikzpicture}[auto, node distance=2cm,>=latex',scale=1, every node/.style={transform shape}]
    \node [input, name=input] {};
    \node [block, right of=input] (system) {$h[n] = \delta[n+1]$};
    \node [output, right of=system] (output) {};

    \draw [draw,->] (input) -- node {$x[n]$} (system);
    \draw [->] (system) -- node[pos=4] {$y[n] = x[n] * \delta[n+1] = x[n+1]$} (output);
\end{tikzpicture}
\end{center}

We can use the concept of convolution to connect block diagrams to the properties of convolution

\begin{itemize}
\item A single block is equivalent to convolution with the impulse response for that subsystem\\[1em]
\begin{tikzpicture}[auto, node distance=2cm,>=latex',scale=1, every node/.style={transform shape}]

    \node [input, name=input] {};
    \node [block, right of=input] (system) {$h_1[n]$};
    \node [output, right of=system] (output) {};

    \draw [draw,->] (input) -- node {$x[n]$} (system);
    \draw [->] (system) -- node[pos=2] {$y[n] = h_1[n]*x[n]$} (output);
\end{tikzpicture}

\item Using the associative property, a series connection of two blocks becomes
  \begin{center}
\begin{tikzpicture}[auto, node distance=2cm,>=latex',scale=1, every node/.style={transform shape}]
    % We start by placing the blocks
    \node [input, name=input] {};
    \node [block, right of=input] (system1) {$h_1[n]$};
    \node [block, right of=system1,node distance=4cm] (system2) {$h_2[n]$};
    \node [output, right of=system2] (output) {};

    \draw [draw,->] (input) -- node {$x[n]$} (system1);
    \draw [->] (system1) -- (system2);
    \draw [->] (system2) -- node[pos=3] {$y[n] = \left(h_1[n]*h_2[n]\right)*x[n]$} (output);
\end{tikzpicture}
  \end{center}
  which can be reduced to a single convolution $y[n] = h_3[n]*x[n]$ where $h_3[n] = h_1[n]*h_2[n]$.
\item Using the distributive property, a parallel connection of two blocks becomes
  \begin{center}
\begin{tikzpicture}[auto, node distance=2cm,>=latex',scale=1, every node/.style={transform shape}]

    \node[shape=coordinate] at (1,1) (input1) {};
    \node[block] at (3,1) (block1) {$h_1[n]$};
    \node[shape=coordinate] at ($(block1.east)+(0.5,0)$) (output1) {};
    \draw[->] (input1) -- (block1);
    \draw (block1) -- (output1);

    \node[shape=coordinate] at (1,-1) (input2) {};
    \node[block] at (3,-1) (block2) {$h_2[n]$};
    \node[shape=coordinate] at ($(block2.east)+(0.5,0)$) (output2) {};
    \draw[->] (input2) -- (block2);
    \draw (block2) -- (output2);

    \node [input, name=input] at (0,0) {};
    \node [input, name=conn] at (1,0) {};
    \draw (conn) -- (input1);
    \draw (conn) -- (input2);
    \node [sum, right of=input,node distance=5cm] (sum) {$\Sigma$};
    \draw [->] (output1) -| (sum);
    \draw [->] (output2) -| (sum);

    \draw [draw] (input) -- node {$x[n]$} (conn);
    \node [output, right of=sum] (output) {};
    \draw [->] (sum) -- node[pos=3] {$y[n]= \left(h_1[n]*x[n]\right) +  \left(h_2[n]*x[n]\right) =  \left(h_1[n]+h_2[n]\right)*x[n]$} (output);
\end{tikzpicture}
  \end{center}
  which is equivalent to a single convolution $y[n] = h_3[n]*x[n]$ where $h_3[n] = h_1[n] + h_2[n]$.
\item In the feedback connection let $w[n]$ be the output of the summation
  \begin{center}
\begin{tikzpicture}[auto, node distance=2cm,>=latex',scale=1, every node/.style={transform shape}]
    % We start by placing the blocks
    \node[block] at (4.5,0) (block1) {$h_1[n]$};

    \node[block] at (4,-2) (block2) {$h_2[n]$};
    \node[shape=coordinate] at (6,-2) (input2) {};

    \node [input, name=input] at (0,0) {};
    \node [shape=coordinate, name=conn] at (6,0) {};
    \draw (block1) -- (conn);
    \draw (conn) -- (input2);
    \draw [->] (input2) -- (block2);

    \node [sum, right of=input,node distance=2cm] (sum) {$\Sigma$};
    \draw [->] (block2) -| node[pos=0.95] {$-$} (sum);

    \draw [draw,->] (input) -- node {$x[n]$} (sum);
    \draw [->] (sum) -- (block1);
    \node [output, right of=conn] (output) {};
    \draw [->] (conn) -- node {$y[n]$} (output);
    \draw node at (3,0.3) {$w[n]$};
\end{tikzpicture}
  \end{center}
  Then $y[n] = h_1[n]*w[n]$ and $w[n] = x[n] - h_2[n]*y[n]$. Substituting the later into the former gives $y[n] = h_1*(x-h_2[n]*y[n])$. Using the distributive property we get $y[n] = h_1[n]*x[n] - h_1[n]*h_2[n]*y[n]$. Isolating the input on the right-hand side and using $y[n] = \delta[n]*y[n]$ we get
  \[
  y[n] + h_1[n]*h_2[n]*y[n] = \left(\delta[n] + h_1[n]*h_2[n]\right)*y[n] = h_1[n]*x[n]
  \]
  We can solve this for $y[n]$ using the concept of inverse systems. Let $h_3[n]* \left(\delta[n] + h_1[n]*h_2[n]\right)= \delta[n]$, i.e. $h_3$ is the inverse system of $\delta[n] + h_1[n]*h_2[n]$. Then
  \[
  y[n] = h_3[n]*h_1[n]*x[n]
  \]
\end{itemize}

Recall, when the system is instantaneous (memoryless) the impulse response is $a\delta[n]$ for some constant $a$. This is the same as scaling the signal by $a$. We typically drop the block in such cases and draw the input-output operation as

\begin{center}
\begin{tikzpicture}[auto, node distance=2cm,>=latex',scale=1, every node/.style={transform shape}]
  \node [input, name=input] at (0,0) {};
  \node [output, name=system] at (2,0) {};
  \node [output, name=output] at (4,0) {};
  \draw [draw,->] (input) -- node {$x[n]$} (system);
  \draw [draw,->] (system) -- node[pos=1] {$y[n] = ax[n]$} (output);
  \draw [->] (input) -- node {$a$} (output);
\end{tikzpicture}
\end{center}

These properties allow us to perform transformations, either breaking up a system into subsystems, or reducing a system to a single block.

\begin{example}
  Consider a second-order system system with impulse response
  \[
  h[n] = \left(\frac{1}{2}\right)^n\, u[n] + \left(\frac{3}{4}\right)^n\, u[n]
  \]
  We can express this as a block diagram consisting of two parallel blocks
  \begin{center}
\begin{tikzpicture}[auto, node distance=2cm,>=latex',scale=1, every node/.style={transform shape}]

    \node[shape=coordinate] at (1,1) (input1) {};
    \node[block] at (3,1) (block1) {$h_1[n] = \left(\frac{1}{2}\right)^nu[n]$};
    \node[shape=coordinate] at ($(block1.east)+(0.5,0)$) (output1) {};
    \draw[->] (input1) -- (block1);
    \draw (block1) -- (output1);

    \node[shape=coordinate] at (1,-1) (input2) {};
    \node[block] at (3,-1) (block2) {$h_2[n] = \left(\frac{3}{4}\right)^nu[n]$};
    \node[shape=coordinate] at ($(block2.east)+(0.5,0)$) (output2) {};
    \draw[->] (input2) -- (block2);
    \draw (block2) -- (output2);

    \node [input, name=input] at (0,0) {};
    \node [input, name=conn] at (1,0) {};
    \draw (conn) -- (input1);
    \draw (conn) -- (input2);
    \node [sum, right of=input,node distance=5cm] (sum) {$\Sigma$};
    \draw [->] (output1) -| (sum);
    \draw [->] (output2) -| (sum);

    \draw [draw] (input) -- node {$x[n]$} (conn);
    \node [output, right of=sum] (output) {};
    \draw [->] (sum) -- node[pos=1] {$y[n]$} (output);
\end{tikzpicture}
  \end{center}
\end{example}

\section{Connections to LCCDE}

The other DT system representation we have seen are linear, constant-coefficient difference equations. These can be expressed as combinations of advance or delay blocks. This is straightforward compared the CT system case.

\subsection*{First-Order System}

To illustrate this consider the first-order LCCDE
\[
y[n+1] + ay[n]= x[n+1]
\]
We can solve this for $y[n]$
\[
y[n] = -\frac{1}{a}y[n+1]  + \frac{1}{a}x[n+1]
\]
and can express this as a feedback motif using the advance operator $E$
\begin{center}
  \tikzstyle{block} = [draw, fill=gray!20, rectangle,
      minimum height=2em, minimum width=2em]
  \begin{tikzpicture}[auto]
    \node [input, name=input] at (0,0) {};
    \node [left of=input] {$x[n]$};
    \node[block, right of=input, node distance=5em] (block1) {$E$};
    \node [sum, right of=block1, node distance=5em] (sum) {$\Sigma$};
    \node[block] at (5,-1) (block2) {$E$};
    \node [shape=coordinate, name=conn] at (6,0) {};
    \node[shape=coordinate] at (7,0) (output) {};
    \node [right of=output] {$y[n]$};

    \draw [->] (input) -- node {$\frac{1}{a}$} (block1);
    \draw [->] (block1) -- (sum);
    \draw (sum) -- (conn);
    \draw [->] (conn) -- (output);
    \draw [->] (conn) |- (block2);
    \draw [->] (block2) -| node {$-\frac{1}{a}$} (sum);
  \end{tikzpicture}
\end{center}

Alternatively we could rewrite the difference equation in recursive delay form
\[
y[n] = -ay[n-1] +x[n]
\]
which can be expressed as a block diagram using the delay operator, $D$
\begin{center}
  \tikzstyle{block} = [draw, fill=gray!20, rectangle,
      minimum height=2em, minimum width=2em]
  \begin{tikzpicture}[auto]
    \node [input, name=input] at (0,0) {};
    \node [left of=input] {$x[n]$};
    \node [sum, right of=input, node distance=5em] (sum) {$\Sigma$};
    \node[block] at (3,-1) (block2) {$D$};
    \node [shape=coordinate, name=conn] at (4,0) {};
    \node[shape=coordinate] at (5,0) (output) {};
    \node [right of=output] {$y[n]$};

    \draw [->] (input) -- (sum);
    \draw (sum) -- (conn);
    \draw [->] (conn) -- (output);
    \draw [->] (conn) |- (block2);
    \draw [->] (block2) -| node {$-a$} (sum);
  \end{tikzpicture}
\end{center}

The choice of using advance or delay blocks results in a non-causal or causal (respectively) system. Thus, delay blocks are required for real-time DT system implementations.

\subsection*{Second-Order System}

Now consider the second-order system
\[
y[n+2] + ay[n+1] + by[n] = x[n+2]
\]
Again, writing in recursive delay form
\[
y[n] = -ay[n-1] - by[n-2] + x[n]
\]
we obtain the block diagram
\begin{center}
  \tikzstyle{block} = [draw, fill=gray!20, rectangle,
      minimum height=2em, minimum width=2em]
  \begin{tikzpicture}[auto]
    \node [input, name=input] at (0,0) {};
    \node [left of=input] {$x[n]$};
    \node [sum] at (2,0) (sum1) {$\Sigma$};
    \node [block] at (4,-1) (block1) {$D$};
    \node [block] at (4,-3) (block2) {$D$};
    \node [shape=coordinate, name=conn1] at (4,-2) {};
    \node [shape=coordinate, name=conn2] at (4,-4) {};
    \node [sum] at (2,-2) (sum2) {$\Sigma$};
    \node [shape=coordinate, name=conn] at (4,0) {};
    \node [shape=coordinate] at (5,0) (output) {};
    \node [right of=output] {$y[n]$};

    \draw [->] (input) -- (sum1);
    \draw (sum1) -- (conn);
    \draw [->] (conn) -- (output);
    \draw [->] (conn) -- (block1);
    \draw (block1) -- (conn1);
    \draw [->] (conn1) -- node {$-a$} (sum2);
    \draw [->] (conn1) -- (block2);
    \draw (block2) -- (conn2);
    \draw [->] (conn2) -| node {$-b$} (sum2);
    \draw [->] (sum2) -- (sum1);
  \end{tikzpicture}
\end{center}

\section{Implementing a DT System}

As in the CT case, one of the most powerful uses of block diagrams is the implementation of a DT system in hardware. As we shall see later in the semester, designing a DT system for a particular purpose leads to a mathematical description that is equivalent to either an impulse response or a LCCDE. We have seen how these can be represented as block diagrams. Once we have reduced a system to blocks consisting of simple operations, we can then convert the block diagram to a digital circuit, implement using a digital signal processor, or write an equivalent program to run on an embedded or general purpose computer.

\begin{tabular}{cc}

  Block & Typical Digital Circuit\\
  \hline
  \tikzstyle{block} = [draw, fill=gray!20, rectangle,
    minimum height=2em, minimum width=2em]
  \tikzstyle{sum} = [draw, fill=gray!20, circle, node distance=1cm]
  \tikzstyle{input} = [coordinate]
  \tikzstyle{output} = [coordinate]
  \tikzstyle{pinstyle} = [pin edge={to-,thin,black}]

  \begin{tikzpicture}[auto]
    \node [input, name=input] at (0,0) {};
    \node [shape=coordinate, name=signal1] at (1,0) {};
    \node [shape=coordinate, name=signal2] at (2,0) {};
    \node [output, right of=signal2] (output) {};

    \draw (input) -- node {$x[n]$} (signal1);
    \draw (signal1) -- node {$a$} (signal2);
    \draw [->] (signal2) -- node[pos=1] {$y[n]$} (output);
  \end{tikzpicture}

  &
  Multiplier (ALU)
  \\[2em]

  \tikzstyle{block} = [draw, fill=gray!20, rectangle,
    minimum height=2em, minimum width=2em]
  \tikzstyle{sum} = [draw, fill=gray!20, circle, node distance=1cm]
  \tikzstyle{input} = [coordinate]
  \tikzstyle{output} = [coordinate]
  \tikzstyle{pinstyle} = [pin edge={to-,thin,black}]

  \begin{tikzpicture}[auto]
    \node [input, name=input1] at (0,0) {};
    \node [input, name=input2] at (0,-1) {};
    \node [sum] at (2,0) (sum1) {$\Sigma$};
    \node [output, right of=sum1] (output) {};

    \draw [->] (input1) -- node[pos=0] {$x_1[n]$} (sum1);
    \draw [->] (input2) -| node[pos=0] {$x_2[n]$} (sum1);
    \draw [->] (sum1) -- node[pos=1] {$y[n]$} (output);
  \end{tikzpicture}
  &
  Adder (ALU)
  \\[2em]

  \tikzstyle{block} = [draw, fill=gray!20, rectangle,
    minimum height=2em, minimum width=2em]
  \tikzstyle{sum} = [draw, fill=gray!20, circle, node distance=1cm]
  \tikzstyle{input} = [coordinate]
  \tikzstyle{output} = [coordinate]
  \tikzstyle{pinstyle} = [pin edge={to-,thin,black}]

  \begin{tikzpicture}[auto]
    \node [input, name=input] at (0,0) {};
    \node[block] at (2,0) (block1) {$D$};
    \node [output, right of=block1] (output) {};

    \draw [->] (input) -- node {$x[n]$} (block1);
    \draw [->] (block1) -- node[pos=1] {$y[n]$} (output);
  \end{tikzpicture}

  &
  Shift Register\\
  \hline
\end{tabular}

\begin{example} The following C++ code implements the second order system given by
\begin{center}
  \tikzstyle{block} = [draw, fill=gray!20, rectangle,
      minimum height=2em, minimum width=2em]
  \begin{tikzpicture}[auto]
    \node [input, name=input] at (0,0) {};
    \node [left of=input] {$x[n]$};
    \node [sum] at (2,0) (sum1) {$\Sigma$};
    \node [block] at (4,-1) (block1) {$D$};
    \node [block] at (4,-3) (block2) {$D$};
    \node [shape=coordinate, name=conn1] at (4,-2) {};
    \node [shape=coordinate, name=conn2] at (4,-4) {};
    \node [sum] at (2,-2) (sum2) {$\Sigma$};
    \node [shape=coordinate, name=conn] at (4,0) {};
    \node [shape=coordinate] at (5,0) (output) {};
    \node [right of=output] {$y[n]$};

    \draw [->] (input) -- (sum1);
    \draw (sum1) -- (conn);
    \draw [->] (conn) -- (output);
    \draw [->] (conn) -- (block1);
    \draw (block1) -- (conn1);
    \draw [->] (conn1) -- node {$-\frac{1}{2}$} (sum2);
    \draw [->] (conn1) -- (block2);
    \draw (block2) -- (conn2);
    \draw [->] (conn2) -| node {$-\frac{1}{9}$} (sum2);
    \draw [->] (sum2) -- (sum1);
  \end{tikzpicture}
\end{center}
using floating point calculations. It assumes the current input is obtained via the function \texttt{read}, and the output written using the function \texttt{write}. The delayed values of the output are stored in the array \texttt{buffer} and are initialized to zero ("at rest" prior to application of the input).
\begin{verbatim}
double buffer[2] = {0.0,0.0};
while(true){
  double x = read();
  double y = -0.5*buffer[1] - buffer[0]/9.0 + x;
  write(y);
  buffer[0] = buffer[1];
  buffer[1] = y;
}
\end{verbatim}
Note in real applications it is common to replace the floating point calculations with fixed-width (scaled integer) ones.
$\blacksquare$
\end{example}