\documentclass[bigger]{beamer}

\input{header-beam} % change to header-handout for handouts

% ====================
\title[Lecture 16]{Logic I F13 Lecture 16}
\date{November 5, 2013}
% ====================

\input{header}

\setlength{\fitchprfwidth}{5em}

\section{Ambiguity}

\subsec{Types of Ambiguity}{

\bit
\item Lexical ambiguity: same word, different meaning
\item Structural ambiguity: different ways to read a phrase/sentence
\item \emph{Scope ambiguity}: which connective or quantifier is in the
  scope of which other connective or quantifier\\[2ex]

a is left of b and large or left of c
\begin{align*}
\sf LeftOf(a, b) & \sf{} \land (Large(a) \lor RightOf(a, c)) \\
\sf (LeftOf(a, b) & \sf{} \land Large(a)) \lor RightOf(a, c)
\end{align*}
\eit

}

\subsec{``Anything''}{

\bit
\item Anything {\color{blue}left of a cube} is large\pauses
\[\sf
\uncovers{3-}{\forall x(}{\color{blue}\exists y(Cube(y) \land LeftOf(x, y))} \uncovers{3-}{{}\to Large(x))}
\]\pauses
\item {\color{red}No cube is} left of anything large \pauses
\[\sf
{\color{red}\forall x(Cube(x) \to \lnot} \uncovers{5-}{\exists y(Large(y) \land LeftOf(x, y))}{\color{red})}
\]\pauses
\item {\color{red}No cube is} left of everything large \pauses
\[\sf
{\color{red}\forall x(Cube(x) \to \lnot} \forall y(Large(y) \to LeftOf(x, y)){\color{red})}
\]
\eit

}

\subsec{Negation and the Quantifiers}{

\bit
\item ``All cubes are not large''
\bit
\item Denial of ``all cubes are large''\\
(``Are all cubes large? No, all cubes are not large'')\pauses
\begin{align*}
\sf\lnot\forall x(Cube(x) & \sf{} \to Large(x)) \\
\sf\exists x(Cube(x) & \sf{} \land\lnot Large(x))
\end{align*}
\item All cubes are: not large, i.e.,\\
No cubes are large\pauses
\begin{align*}
\sf\forall x(Cube(x) & \sf{} \to \lnot Large(x)) \\
\sf\lnot\exists x(Cube(x) & \sf{}\land Large(x))
\end{align*}
\eit
\eit
}

\subsec{Multiple Quantifiers and Ambiguity}{

\bit
\item ``All cubes adjoin a tetrahedron''
\bit
\item ``A tetrahedron'' in the scope of ``all cubes'', i.e.,\\
``For every cube, there is a tetrahedron it adjoins''\pauses
\[
\sf\forall x(Cube(x) \to \exists y(Tet(y) \land Adjoins(x, y))
\]
\item ``All cubes'' in scope of ``a tetrahedron'', i.e.,\\
``There is a tetrahedron which every cube adjoins''\pauses
\[
\sf\exists y(Tet(y) \land \forall x(Cube(x) \to Adjoins(x, y))
\]
\eit\eit
}

\section{Anaphora and Uniqueness}

\subsec{Anaphora (Donkey Sentences)}{

``Every farmer who owns a donkey is happy''

\bits
\item Step by step translation: ``All As are Bs''
\item x is a farmer who owns a donkey \dots\[\sf
Farmer(x) \land \exists y(Donkey(y) \land Owns(x, y))
\]
\item {\color{blue}Every} farmer who owns a donkey {\color{blue}is happy}
\[\sf
{\color{blue}\forall x(}(Farmer(x) \land \exists y(Donkey(y) \land Owns(x, y))) {\color{blue}\to Happy(x))}
\]
\eit

}

\subsec{Anaphora (Donkey Sentences)}{

``Every farmer who owns a donkey beats it''

\bits
\item Step by step translation: ``All As are Bs''
\item x is a farmer who owns a donkey \dots\[\sf
Farmer(x) \land \exists y(Donkey(y) \land Owns(x, y))
\]
\item {\color{blue}Every} farmer who owns a donkey {\color{blue}beats it}
\[\sf
{\color{blue}\forall x(}(Farmer(x) \land \exists y(Donkey(y) \land Owns(x, y))) {\color{blue}\to Beats(x, {\color{red}y}))}
\]
\eit

}

\subsec{Anaphora (Donkey Sentences)}{

``Every farmer who owns a donkey beats it''\pauses

\bits
\item When is it false that every farmer who owns a donkey beats it? \pauses
If there's a farmer who owns a donkey but doesn't beat it. Deny that! \pauses
\[\sf
\lnot\exists x(Farmer(x) \land \exists y(Donkey(y) \land Owns(x, y) \land \lnot Beats(x, y)))
\]
\item For every farmer and every donkey: if the farmer owns the
  donkey, the farmer beats the donkey
\[\sf
\forall x\forall y((Farmer(x) \land Donkey(y)) \to (Owns(x, y) \to Beats(x, y)))
\]
\item Every farmer beats every donkey they own
\[\sf
\forall x(Farmer(x) \to \forall y((Donkey(y) \land Owns(x, y)) \to Beats(x, y)))
\]
\eit

}

\subsec{Uniqueness}{

\bit
\item There is at least one cube.
\[
\sf\exists x\, Cube(x)\]
\item There is exactly one cube.
\bit
\item<2-> There's at least one cube, and
\item<3-> There are no others
\begin{align*}
\uncover<2->{\sf\exists x\, (Cube(x)} & \uncover<4->{\sf\land \lnot \exists y\, (y \neq x \land Cube(y)))}\\
\uncover<3->{\sf\exists x\,(Cube(x)} & \uncover<5->{\sf\land \forall y(Cube(y) \to x = y))}
\end{align*}
\eit
\eit
}

\section{Rules for $\forall$}

\subsec{Rules for Fitch}{

\bit
\item Need rules for $\forall$ and $\exists$ for formal proofs
\item Formal proofs now more important, because no alternative (truth-table method)
\item Intro and Elim rules should be
\bit
\item simple
\item elegant (not involve other connectives or quantifiers)
\item yield only valid arguments
\eit
\eit

}

\subsec{Candidates for Rules}{
\setlength{\fitchprfwidth}{6em}

\bit
\item Only simple sentence close to $\sf \forall x\, A(x)$ is $\sf A(c)$
\item Gives simple, elegant $\forall$Elim rule:

\fitchctx{
\nline[$k.$]{\forall x\, A(x)}\\
\fpline{\quad A(c)}[\lalle{}]
}
\item Problem: corresponding ``intro rule'' isn't valid:
\fitchctx{
\nline[$k.$]{A(c)}\\
\fpline{\quad\forall x\,A(x)}[\emph{doesn't follow!}]
}
\eit

}

\subsec{Names for Arbitrary Objects}{

\bit
\item Diagnosis: the c in A(c) is a name for a \emph{specific object}
We need a name for an \emph{arbitrary, unspecified object}
\item If A(c) is true for whatever c could name, then A(x) is satisfied by \emph{every} object
\item In fact, this is what we do when we give proofs of general claims, e.g.,

\setlength{\fitchargwidth}{15em}
\fitcharg{\tline{All cubes adjoin a}\\
\tline{Only small things adjoin a}}{
\tline{All cubes are small}}

\pauses
Proof: Let Carl be any cube.  Since all cubes adjoin a, Carl adjoins
a. Since only small things adjoin a, Carl is small. But ``Carl''
stands for \emph{any} cube. So all cubes are small.
  \eit

}

\subsec{Arbitrary Objects in Fitch}{

\bit
\item Every special constant with stands for an arbitrary object is
  introduced only pro tem
\item In particular, they never appear in the premises or conclusion of an argument
\item In Fitch, this is enforced by requiring that special constants only appear in subproofs
\item To indicate that a constant names an arbitrary object, it is put in a box at the beginning of this subproof
\eit

}

\subsec{General Conditional Proof}{
\setlength{\fitchctxwidth}{11em}

\fitchctx{
\boxedsubproof[$m$.]{c}{A(c)}{\ellipsesline \\ \nline[$n.$]{B(c)}}
\fpline{\quad \forall x(A(x) \to B(x))}[\lalli{$m$--$n$}]}

\bit
\item c is special: c must not appear anywhere outside the subproof
\eit
}

\subsec{Universal Generalization}{
\setlength{\fitchprfwidth}{11em}

\fitchctx{
\boxedsubproof[$m$.]{c}{}{\ellipsesline \\ \nline[$n.$]{A(c)}}
\fpline{\quad \forall x\,A(x)}[\lalli{$m$--$n$}]}
\bit
\item c is special: c must not appear anywhere outside the subproof
\eit
}

\subsec{Example}{

\setlength{\fitchargwidth}{15em}
\fitcharg{\tline{All cubes adjoin a}\\
\tline{Only small things adjoin a}}{
\tline{All cubes are small}}

\bigskip

\fitchprf{\pline{\forall x\, (Cube(x) \to Adjoins(x, a))}\\
\pline{\forall x(Adjoins(x, a) \to Small(x))}}{
\pline{\forall x(Cube(x) \to Small(x))}}

}

\subsec{Example}{

\setlength{\fitchprfwidth}{15em}

\fitchprf{\pline[1.]{\forall x\, (Cube(x) \to Adjoins(x, a))}\\
\pline[2.]{\forall x(Adjoins(x, a) \to Small(x))}}{
\boxedsubproof[3.]{c}{Cube(c)}{\pline[4.]{Cube(c) \to Adjoins(c, a)}[\lalle{1}] \\
\pline[5.]{Adjoins(c, a)}[\life{3}{4}]\\
\pline[6.]{Adjoins(c, a) \to Small(c)}[\lalle{2}] \\
\pline[7.]{Small(c)}[\life{5}{6}]}
\pline[8.]{\forall x(Cube(x) \to Small(x))}[\lalli{3--7}]}

}

\section{Rules for $\exists$}

\subsec{Intro Rule for $\exists$}{
\setlength{\fitchprfwidth}{7em}
\bit
\item If we know of a specific object that it satisfies A(x), we know that at least one object satisfies A(x)
\item So this rule is valid:

\fitchctx{\pline[$m.$]{A(c)}\\
\fpline{\quad \exists x\, A(x)}[\lexii{$m$}]}
\item Problem: corresponding ``elim rule'' isn't valid:
\fitchctx{
\nline{\exists x\, A(x)}\\
\fpline{\quad A(c)}[\emph{doesn't follow!}]
}

\eit

}

\subsec{Arbitrary Objects Again}{

\bit
\item If we know that $\sf\exists x\, A(x)$ is true, we know that \emph{some} object(s) satisfy A(x), but not which ones
\item To use this information, we have to introduce a temporary name that stands for any one of the objects that satisfy A(x)
\item This is what we'd do if we reason informally from existential information, e.g.,

\setlength{\fitchprfwidth}{15em}
\fitchprf{\tline{There are small cubes}\\
\tline{Anything small adjoins a}}{
\tline{Some cubes adjoin a}}

\pauses
Proof: We know there are small cubes. Let Cate be an arbitrary one of them.  So
Cate is small. Since all small things adjoins a, Cate adjoins a. Since
Cate is a cube adjoining a, some cubes adjoin a.
\eit

}

\subsec{Existential Instantiation}{
\setlength{\fitchprfwidth}{7em}

\bit
\item If we know that some object satisfies A(x), we assume for the time being that c is one of them (i.e., assume A(c)), and we can prove that some claim B fololows from this assumption, then B follows already from $\sf\exists x\, A(x)$.
\item Rule for existential elimination:
\bigskip

\fitchctx{
\pline[$k$.]{\exists x\, A(x)}\\
\boxedsubproof[$m$.]{c}{A(c)}{\ellipsesline \\ \nline[$n.$]{B}}
\fpline{\quad B}[\lexie{k}{$m$--$n$}]}
\item c is special: c must not appear anywhere outside the subproof
\eit
}

\subsec{Example}{

\setlength{\fitchprfwidth}{15em}
\fitchprf{\tline{There are small cubes}\\
\tline{Anything small adjoins a}}{
\tline{Some cubes adjoin a}}

\bigskip

\fitchprf{\pline{\exists x(Small(x) \land Cube(x))}\\
\pline{\forall x(Small(x) \to Adjoins(x, a))}}{
\pline{\exists x(Cube(x) \land Adjoins(x, a)}}
}

\subsec{Example}{

\setlength{\fitchprfwidth}{15em}
\fitchprf{\pline[1.]{\exists x(Small(x) \land Cube(x))}\\
\pline[2.]{\forall x(Small(x) \to Adjoins(x, a))}}{
\boxedsubproof[3.]{c}{Small(c) \land Cube(c)}{
\pline[4.]{Small(c)}[\lande{3}] \\
\pline[5.]{Small(c) \to Adjoins(c, a)}[\lalle{2}] \\
\pline[6.]{Adjoins(c, a)}[\life{4}{5}]\\
\pline[7.]{Cube(c)}[\lande{3}] \\
\pline[8.]{Cube(c) \land Adjoins(c, a)}[\landi{6}{7}]\\
\pline[9.]{\exists x(Cube(x) \land Adjoins(x, a)}[\lexii{8}]
}
\pline[10.]{\exists x(Cube(x) \land Adjoins(x, a)}[\lexie{1}{3--9}]
}

}
\end{document}


\section{Standard Library Concepts} \label{sec:standard_library_concepts}

\subsection{The Ranges Library} \label{sec:the_ranges_library}

    \begin{lstlisting}
std::vector v { 10, 2, 6, 10, 4, 1, 9, 5, 8, 3 };
v = std::move(v) | action::sort | action::unique; \end{lstlisting}

    \begin{lstlisting}
auto r = v | view::remove_if([](int i){ return (i % 2) == 1; })
           | view::transform([](int i){ return to_string(i); })
           | view::take(4); \end{lstlisting}


\documentclass[main.tex]{subfiles}
\begin{document}

\marginpar{Wednesday\\ 2020-8-19, \\ compiled \\ \today}

Under our assumptions the electric field can be written as
%
\begin{align}
\vec{E} = E_0 \sin \omega_0 t \vec{\epsilon}
\,,
\end{align}
%
where \(\vec{\epsilon}\) is a unit vector which is perpendicular to the propagation direction: \(\vec{\epsilon} \cdot \vec{k} = 0\); while \(E_0 \) is the amplitude of the electric field and \(\omega_0\) is its frequency.

The equations of motion of the charge read
%
\begin{align}
m \ddot{\vec{r}} = e \vec{E} = e E_0 \sin \omega_0 t \vec{\epsilon}
\,,
\end{align}
%
which  we can also express through the dipole moment \(\vec{d} = e \vec{r}\): the equation for its evolution will then read
%
\begin{align}
\ddot{\vec{d}} = \frac{e^2}{m} E_0 \sin \omega_0 t \vec{\epsilon }
\,.
\end{align}

If we integrate in \(\dd{t}\) two times we find
%
\begin{align}
\vec{d} (t) = - \frac{e^2 E_0 }{m \omega_0^2} \sin \omega_0 t \vec{\epsilon}
\,,
\end{align}
%
so the response to the impinging EM wave is an oscillation of the dipole, with a frequency \(\omega_0\) equal to that of the EM wave and an amplitude equal to
%
\begin{align}
d_0 = \frac{e^2 E_0 }{m \omega_0^2}
\,.
\end{align}

The electron is accelerating, so it will radiate: the power emitted per unit solid angle will be
%
\begin{align}
\frac{ \dd{w}}{ \dd{t} \dd{\Omega }} = \frac{1}{c^3} \frac{ \ddot{d}^2}{4 \pi } \sin^2 \Theta
= \frac{1}{4 \pi c^3} \frac{e^{4}}{m^2} E_0^2 \sin^2 \omega_0 t \sin^2 \Theta
\,,
\end{align}
%
where \(\Theta \) is the angle between the direction of propagation of the wave and the direction of observation.
This oscillates in time; we can compute the average over an oscillation: this means that we substitute the square sine with a factor \(1/2\):
%
\begin{align}
\expval{\frac{ \dd{w}}{ \dd{t} \dd{\Omega }}} =
\frac{e^{4} E_0^2 \sin^2 \Theta }{8 \pi c^3 m^2}
\,.
\end{align}

Integrating over the solid angle to get the average power amounts to multiplying by \(4 \pi \) times \(2/3\), because of the solid angle in the sphere and because of the integral of \(\sin^2 \Theta\).
This yields
%
\begin{align}
\expval{\dv{w}{t}} = \frac{e^{4} E_0^2}{3 m^2 c^3}
\,.
\end{align}

Now, let us compute the flux of energy which is carried away by the incident EM wave:
%
\begin{align}
S = \frac{ \dd{w}}{ \dd{A} \dd{t}}
= \frac{c}{4 \pi } E_r^2
= \frac{c}{4 \pi R^2} E_0^2 \sin^2 \omega_0t
\,,
\end{align}
%
then the power per unit solid angle is
%
\begin{align}
\frac{ \dd{w}}{ \dd{\Omega } \dd{t}} = \frac{c}{4 \pi } E_0^2 \sin^2 \omega_0 t
\,,
\end{align}
%
whose average as before is
%
\begin{align}
\expval{ \frac{ \dd{w}}{ \dd{\Omega } \dd{t}}} = \frac{c E_0^2}{8 \pi }
\,.
\end{align}

\todo[inline]{Except this, dimensionally, is a power per unit \emph{area}!}

Now, let us define the \textbf{differential scattering cross section} as
%
\begin{align}
\dv{\sigma }{\Omega } =
\frac{
    \expval{\frac{ \dd{w}}{ \dd{t} \dd{\Omega }}}_{\text{emitted}}
    }{
    \expval{\frac{ \dd{w}}{ \dd{t} \dd{\Omega }}}_{\text{incoming}}
}
\,,
\end{align}
%
\todo[inline]{is this not dimensionally inconsistent? the differential scattering cross section should have the dimensions of an area / steradian\dots Maybe the incoming power should be considered per unit \emph{area}, since it is a plane wave whose source is at infinity?

This seems indeed to be the case, see \cite[eq.\ 3.36]{rybickiRadiativeProcessesAstrophysics1979}}
and if we compute this for our case we will have
%
\begin{align}
\dv{\sigma }{\Omega } = \frac{e^{4}E_0^2 \sin^2 \Theta }{8 \pi c^3 m^2}
\frac{8 \pi }{c E_0^2}
= \frac{e^{4}}{c^{4} m^2} \sin^2 \Theta
\,.
\end{align}

This expression can also be written through the classical electron radius:
%
\begin{align}
r_0 = \frac{e^2}{mc^2} \approx \SI{2.82e-13}{cm}
\,,
\end{align}
%
whose expression is found by equating the rest energy of the electron \(m c^2\) with its electromagnetic self-energy \(e^2 / r_0 \).
Then, the scattering cross section can be expressed as
%
\begin{align}
\dv{\sigma }{\Omega } = r_0^2 \sin^2 \Theta
\,.
\end{align}

The total cross section is found from the integral of this over all the solid angle:
%
\begin{align}
\sigma_T = \int \dv{\sigma }{\Omega } \dd{\Omega } = r_0^2 \underbrace{\int (1 - \mu^2) \dd{\mu } \times 2 \pi }_{= 8 \pi /3} = \frac{8 \pi }{3} r_0^2
\,.
\end{align}

This is the \textbf{Thomson cross section} of the electron \(\sigma_{T} \approx \SI{0.665e-24}{cm^2}\).

Now, for some observations. This cross section does not change depending on the frequency of the incoming wave: it is ``color blind''.
This formula for the scattering is not always valid, but in its regime of validity (which will be discussed later) we expect no frequency dependence.

Moreover, this scattering is \textbf{conservative} or coherent: the frequency of the scattered radiation is the same as the frequency of the incoming radiation.

It also is \textbf{not isotropic} because of the factor \(\sin^2 \Theta \). This scattering ``prefers'' for the light to go along the same direction it came from, and the probability density for it goes to zero for  \(\Theta = \pi /2\), meaning for a scattered photon orthogonal to the direction of propagation.
Also, there is forward-backward symmetry, which will be useful to simplify certain calculations.
The degree of anisotropy is also rather mild, it varies slowly over the solid angle, so in certain situations it will be alright to approximate Thomson scattering as isotropic.
This is the closest we can get to completely isotropic and coherent scattering.

We can apply this reasoning to any other particle, it does not need to be an electron: for example, let us apply it to a proton.
Their square charge is the same --- the sign does not matter. The only different is the mass, which appears with a power \(m^{-2}\) in the cross section and in the differential cross section.

So, their ratio will be
%
\begin{align}
\frac{\sigma_{p}}{\sigma_{e}} = \qty( \frac{m_e}{m_p})^2 \approx \num{3e-7}
\,.
\end{align}

This is important in astrophysical applications: if we have a plasma with protons and electron we can almost completely ignore the protons.

Our assumptions have been to treat the electromagnetic field classically, and to assume the electron moves nonrelativistically.
The first of these holds as long as the energy of the individual photons is small: \(h \nu \ll m_e c^2\). If this is the case, the \textbf{recoil} of the electron due to the scattering with the single photon is negligible.
Since \(m_e c^2 \approx \SI{511}{keV}\), we are asking that \(h \nu \ll \SI{511}{keV}\).
A rough boundary for when this works is given by considering \(h \nu \approx \SI{50}{keV}\), a tenth of the electron rest energy.
This puts us in the medium X-rays.

We also assumed that the electron started out at rest, while in practically all situations charges are moving around, if nothing else because of thermal motion.
If we are considering a plasma, it must be hot for the gas to stay ionized.

In the electron's rest frame our description works, however in order to be in that frame we must perform a Lorentz boost, apply Thomson scattering, and boost back: in this way we can describe how the energy of the photon changes.

In astrophysical settings, radiation is generally either completely unpolarized or partially polarized. Therefore, it is interesting to compute the cross section for unpolarized radiation.

Unpolarized radiation can be described as the superposition of two orthogonal polarized waves. One of them will have an angle \(\Theta \) between the polarization vector \(\vec{\epsilon}_1 \) and the observation direction \(\vec{n}\), let us suppose that \(\vec{\epsilon}_1 \), \(\vec{k}\) and \(\vec{n}\) are coplanar.
This can be done, since all we are doing is choosing a convenient basis for the plane orthogonal to the propagation direction.

If this is the case, then if \(\vec{\epsilon}_2 \perp \vec{\epsilon}_1\) we must have \(\Theta = \pi / 2\) for the second wave. This means that we have the two cross sections
%
\begin{align}
\eval{\dv{\sigma }{\Omega }}_{1} = r_0^2 \sin^2 \Theta
\qquad \text{and} \qquad
\eval{\dv{\sigma }{\Omega }}_{2} = r_0^2 \sin^2 \frac{\pi}{2} = r_0^2
\,.
\end{align}

The total differential cross section will be given by their average:
%
\begin{align}
\dv{\sigma }{\Omega } = r_0^2 \frac{1 + \sin^2 \Theta }{2} = r_0^2 \frac{1 + \cos^2 \theta }{2}
\,,
\end{align}
%
where we define \(\theta = \pi /2 - \Theta \), the angle between the propagation direction \(\vec{k}\) and the observation direction \(\vec{n}\).

The total unpolarized cross section is the same as the one we had for polarized light:
%
\begin{align}
\sigma _{\text{unpol}} = \int \dv{\sigma }{\Omega } \dd{\Omega }
= \frac{2 \pi r_0^2}{2} \int_{-1}^{1} (1 + \mu^2) \dd{\mu }
=\frac{8 \pi }{3} r_0^2 = \sigma_{T}
\,.
\end{align}

So, for the total cross section of Thomson scattering polarization does not matter, while it does change the differential cross section.

\subsubsection{The Eddington limit}

The total momentum flux of the radiation field is given by
%
\begin{align}
P = \int_{0}^{\infty } \dd{\nu } \int_{4 \pi } \dd{\Omega } \cos^2 \theta I_\nu
\,.
\end{align}

Suppose we have a differential area \(\dd{A}\), and suppose that photons only cross it in the direction of its normal \(\vec{n}\).
If this is the case, then we have
%
\begin{align}
P = \int_0^{\infty } \dd{\nu } I_\nu  = \frac{F}{c}
\,,
\end{align}
%
since then the angular distribution function is a delta on \(\theta = 0 \) on the unit sphere.

Suppose then we have a particle at the center of the area element \(\dd{A}\), and that we want to calculate the force upon it. It will be the pressure times the cross section:
%
\begin{align}
\mathscr{F} = \frac{F}{c} \sigma = P \sigma
\,.
\end{align}

Now, let us consider a source which emits photons only radially, such as a star with perfect spherical symmetry.
The flux at any radius \(r\) will be \(F = L / 4 \pi r^2\), where \(L\) is the luminosity (power) of the source.
The photons will only move radially.

Then, the force onto a test particle will be
%
\begin{align}
\mathscr{F} = \frac{L \sigma }{c 4 \pi r^2}
\,.
\end{align}

The source will have a mass \(M\), and it will attract the particles gravitationally.

Now, a typical composition for the material outside a star is a plasma, made up of dissociated hydrogen: protons and electrons.
As we have seen, the cross section of the electrons for Thomson scattering will be much larger than that of the protons, while the gravitational force will be much larger on the protons since they are more massive.

If we consider a single electron-proton pair which is bound by electrostatic forces (although not in a bound \emph{state}, since we still have a plasma), then we can calculate the equilibrium point for the forces on the pair.
We can then equate the radiative force on the electron to the gravitational force on the proton, since the other two forces are negligible in comparison. This yields:
%
\begin{align}
\frac{L \sigma_{T}}{c 4 \pi r^2} &= \frac{G M m_p}{r^2}  \\
L &= \frac{4 \pi G M m_p c}{\sigma_{T}} = L _{\text{Edd}}
\,,
\end{align}
%
the \textbf{Eddington luminosity} corresponding to a mass \(M\).
In comparison to the Sun, this is roughly
%
\begin{align}
L _{\text{Edd}} \approx \num{3e5} L_{\odot} \frac{M}{M_{\odot}}
\,.
\end{align}

This means that the Sun is well below the Eddington limit.
This is not a general limit, since it only applies if we have spherical symmetry; if this is broken the ``limit'' can be violated.
Also, we can define analogous limits for different kinds of processes, which will have different cross sections.

\end{document}


% Questions about the Fission Matrix initiated by Prof. Holloway's paper.

\documentclass[12pt]{article}
\usepackage[margin=1in]{geometry}

\title{Questions Regarding Fission Matrix ideas}
\begin{document}
\maketitle

\section{Introduction}
\begin{enumerate}
    \item Why do we need $PGPq = kq$ when we already have $Gq = kq$?  What is the difference?  What about $T$, how does he play into all this?

    I think the need for this is to map $G$ to the Monte Carlo space from ``reality'' space.  So when Holloway writes $P:Q\rightarrow T$, this means that we take a particle in ``reality'' space and map it into a ``binned'' Monte Carlo space or some other space that the computer can understand and manipulate.  \\[2in]

    \item Is the $T$ in
    \begin{equation}
        \left(T\psi = \frac{1}{k}F\psi\right)
    \end{equation}
    the same as in $P:Q\rightarrow T$?

\end{enumerate}
\subsection{The fission matrix}
\begin{enumerate}
    \item What is $\{p_n\}$?  How are $p_n$ related to $P$?

    I think $p_n$'s are the basis functions (e.g., histograms, Legendre, etc.).  The expansion coefficients are the $x_n$'s.  Using $x$'s and $p$'s we can write any $q$ as $q = \sum_n x_np_n$.\\[1in]

    \item What is the difference between $p_n$ and $p_n^{\dagger}$?  Why do we need a \emph{biorthonormal} basis instead of a simple orthonormal basis?

    \item How can I calculate $p_n$, $p_n^{\dagger}$, and $x_n$?  They all seem to depend on each other.

    If $p_n$ is one of the expansion functions, then $x_n$ is calculated during the Markov Chain.  If this is the case then we know $p_n$ and $x_n$, but how to we find $p_n^{\dagger}$?
\end{enumerate}

\section{Working with A}
No specific questions here, but I don't fully understand how one might generate the matrix $\mathbf{A}$ using FET modes.
\section{General Questions}
\begin{enumerate}
    \item Why is this different from a typical Monte Carlo kcode calculation? \\[1in]

    \item Can I really do just a simple dot product of $q$'s?

    If I understand correctly, the elements of $q$ are the expansion coefficients.  When I perform the inner product $\left\langle q_n, q_m\right\rangle$ is this really just a simple dot product?
\end{enumerate}
\end{document}


\subsection{Transactions}

\subsubsection{Definitions}

In Bitcoin, there are some transactions.
In each transaction, there are multiple inputs and outputs.
Each input is named TXFieldWithId.
The input of one transaction is the output of another transaction.
Firsts outputs are generated from coinbase transaction (created by the miner).
Each block has just one of this transaction.

\agda{Transactions}{VectorOutput}

Vector output is the vector of outputs transactions.
It is a non-empty vector, because it already starts with one element \emph{fstStart}
or it is an union from one transaction with another vector.
In its representation, it is possible to know in what time it was created (time is the position of
they in all transactions),
what is his size (quantity of outputs fields)
and the total amount spent in this transaction,

\emph{elStart} is a proof that the position of TXFieldWithId is the last one,
because its position in the vector is the same as the last position (size) of the vector.
It is used after to specify which input is in the transaction.

\agda{Transactions}{TXSigned}

A signed transaction is composed of a non-empty list of inputs and outputs.
For each input, there is a signature that confirms that he accepted every output in the list of outputs.
And in the transaction, there is proof ($in \geq out$) that the total amount of money
in all inputs is bigger than the total amount of outputs.
The remainder will be used by the miner.

\subsubsection{Raw Transaction}

Raw transactions are transactions without any explicit dependent type.
Here the definition of \emph{raw signed transaction}:

\agda{RawTransactions}{rawtxsigned}

\emph{Raw signed transactions} are a record with \emph{inputs}, \emph{outputs}
and the signature of \emph{inputs} and \emph{outputs}.

The definition of some important types:

\agda{Crypto}{cryptoTypes}

The definition of \emph{Raw Input}:

\agda{RawTransactions}{rawinput}

In each input, it is necessary to know the time, the position of it in the transaction,
the amount spent, its message, the signature, and its public key.
The signature is the signature of the message.
And the message is usually related to the amount spent in each output.

The definition of \emph{raw transaction}:

\agda{RawTransactions}{rawTransaction}

It is all inputs and all outputs.

The definition of \emph{Raw TX}:

\agda{RawTransactions}{rawTX}

The definition of \emph{raw transaction coinbase}:

\agda{RawTransactions}{rawCoinbase}

The definition of \emph{raw Vector Output}:

\agda{RawTransactions}{rawVecOut}

It has the time, its size, the total amount, the \emph{vector output}
and proof that this vector is the same as the list of outputs of this type.

The definition of the record that every input transaction is signed in a given time:

\agda{RawTransactions}{txsigall}

It has the size of vector output, the sublist of all inputs, the total amount,
the \emph{vector output} and a proof that all sublists of inputs are signed.

$rawTXSigned \to TXSigAll$ returns a signed transaction of all inputs in a given time
if \emph{rawTXSigned} has valid signatures for all these inputs:

\agda{RawTransactions}{rawtxSigToTxsigAll}

It has to validate first that the \emph{list of outputs} is a valid \emph{Vector Output}.
Second, it validates if the signature of the inputs are valid with the
\emph{raw signed transaction}.
In the last case, it validates if the time of the \emph{vector output} is equal
of the time of this transaction.
If all conditions match, it returns a proven signed transaction.
If not, it returns nothing.

\hyperref[rawToTX]{This function} transforms a \emph{raw transaction} into a \emph{signed transaction}:

\plabel{rawToTX}
\agda{RawTransactions}{txrawToTxsig}

The function $vecOut \equiv ListAmount$ returns a proof that the \emph{vector output} is equal
to the total amount of the \emph{list of transactions}.
It is impossible that the \emph{vector output} is equal to an empty list.
In case that the list has just one element, it just has to return \emph{refl}.
The another case, it is done recursively.

The proof that the amount of input transaction is greater than the amount of output
is just a rewrite from the previous proof ($vecOut≡ListAmount outputs vecOut out≡vec$).

The function \emph{sameMessage} returns a proof that the message of \emph{raw transaction}
is the same as the message of the \emph{vector output}.
In case that \emph{vector output} has just size one or two, it is a trivial case.
The other cases are doing it recursively.

\emph{sigPub} is another function that returns a proof that an input message is signed.
It validates it with its public key.

The last function returns a proof that every input was signed.
It is done in a recursive way using the function \emph{sigPub}.

This is the function that transforms a list of transactions into a possible \emph{vector output}:

\agda{RawTransactions}{listTXFieldtoVecOut}

The list has to be at least with a size one.
Because the \emph{vector output} can not be empty.
To add one element into the vector, it has to verify if the time is equal to the first time.
Another verification is that the informed position in the vector is right.
If all validations are right, it returns the vector output.
If it is not, it returns nothing.

The definition of the function that transform a \emph{raw transaction} into a
\emph{raw signed transaction}:

\agda{RawTransactions}{rawtoTXSigned}

The first validation that the function does is verifying that the outputs are not empty.
Another validation is verifying if the amount spent on inputs is greater than the amount of the outputs.
The function \emph{Signed?}, defined in the crypto library, validates if the
message was signed with the input.
After, it validates if all inputs are signed.
If all validations are right, it returns the \emph{raw transaction signed}.
If it is not, it returns nothing.


    \filetitle{hpdi}{Highest probability density interval}{tseries/hpdi}

	\paragraph{Syntax}\label{syntax}

\begin{verbatim}
int = hpdi(x,prob)
\end{verbatim}

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

\begin{itemize}
\item
  \texttt{x} {[} tseries {]} - Input data with random draws in each
  period.
\item
  \texttt{prob} {[} numeric {]} - Percent coverage of the computed
  interval, between 0 and 100.
\end{itemize}

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

\begin{itemize}
\itemsep1pt\parskip0pt\parsep0pt
\item
  \texttt{int} {[} tseries {]} - Output tseries object with two columns,
  i.e.~lower bounds and upper bounds for each period.
\end{itemize}

\paragraph{Description}\label{description}

\paragraph{Example}\label{example}


\section{Prior Work}
Having introduced the fundamentals of both processes,
it shall now be shown how existing ChIP-seq- and Hi-C data
can be used to to predict unknown Hi-C matrices.
The following subsections will thus give an overview of the
method developed by Andre Bajorat during his masterproject, hicprediction \cite{Bajorat2019},
and its foundation, HiC-Reg \cite{Zhang2019, Zhang2018}.
This is preceded by a brief introduction into random forests,
which are the common basis of both approaches.

\subsection{Random forest} \label{sec:prior:randomForests}
Random forests were conceived by Leo Breiman in 2001 \cite{Breiman2001} and are based on decision trees,
probably the most simple approach for supervised machine learning.

Decision trees take as input a set of samples with relevant features and then
``learn'' to predict a target feature by splitting the input dataset step by step,
until the target feature can be decided on.
Here, only binary decision criteria on the training features are allowed (True/False), so the decision path can be
visualized in form of a tree, see \autoref{tab:prior:dataset:decisionTree} and \autoref{fig:prior:decisionTree}.
\begin{table}[hb]
\centering
\begin{tabular}{lccc} \hline
	   & \multicolumn{2}{c}{\textbf{train. features}} & \textbf{target feature}\\
 \textbf{sample nr.} & p0  	& p2 	& interact. count\\
 \hline
 0	& 0.0	& 0.0	& 0\\
 ...	& ...	& ...	& ...\\
 40000 	& 10.0  & 10.0	& 100\\
 40001 	& 10.0  & 0.0 	& 100\\
 40002  & 10.0  & 0.0 	& 100\\
 ...	& ...	& ...	& ...\\
 \hline
\end{tabular}
\caption{excerpt of a training dataset for a decision tree} \label{tab:prior:dataset:decisionTree}
\end{table}
\begin{figure}[hb]
 \centering
 \resizebox{0.75\textwidth}{!}{
 \import{figures/}{decisionTree.pdf_tex}}
 \caption{decision tree from hicprediction}
 \label{fig:prior:decisionTree}
\end{figure}

Within this masterproject, the target feature is Hi-C interaction count
and the training features are the signal values from ChIP-seq data of several proteins,
along with the genomic distance of the interacting regions.

Because decision trees are well known for overfitting, i.\,e. having a low bias but a very high variance,
random forests contain not only one, but generally a large number of decision trees.
Each tree is trained on a random subset of the original samples, potentially using random subsets
of the features for each splitting step.
For regression problems, the final prediction is then the average output of all trees,
for classification problems usually the majority vote.
The rationale here is that random selection of the samples and features reduces the variance,
usually at the cost of increased bias.
However, in most applications, the reduction in variance more than outweighs the increase in bias.

For regression trees, the cut points, e.\,g. ``p2 $\leq$ 5.0'', cf.\;\autoref{fig:prior:decisionTree},
are usually selected such that the variance in the remaining two datasets -- here,
all samples with p2 $\leq$ 5.0 on the one hand and all samples with p2 $>$ 5.0 on
the other hand -- is reduced the most.
Searching for the optimal cut-point is computationally involved,
but meanwhile there are several open source implementations which handle the task efficiently.

Random forests have a number of tuning parameters.
Probably the most important ones are the number of trees in the forest,
the size of the subsample used to train each tree,
the maximum number of features to investigate for splitting
and the minimum number of samples allowed to remain in internal nodes, cf.\;\cite{scikitEnsemble2019}.
All of these are used by HiC-Reg and hicprediction, two random-forest-based methods
to predict unknown Hi-C matrices.

\subsection{HiC-Reg}
HiC-Reg was proposed by Shilu Zhang and colleagues at the Wisconsin Institute for Discovery in 2018 \cite{Zhang2019, Zhang2018}.
It takes known Hi-C matrices and ChIP-seq data as inputs to predict unknown Hi-C matrices using random forest regression.

HiC-reg accepts inputs as custom tab-separated text files \cite{Roy2020}.
For all pairs of (\SI{5000}{\kilo\bp})-regions within a size-adjustable window, the average
ChIP-seq read counts of all bins within the window and the distance itself
are computed and a so-called \textsc{window}-dataset is formed from the valid pairs, see \autoref{fig:priorW:hicreg2}, upper left and middle.
Such a dataset and corresponding Hi-C interaction counts are then merged into a training set
for a custom random forest regressor.

After training the regressor, predicting Hi-C interaction counts just requires feeding a test dataset,
i.\,e. processed ChIP-seq data for the target cell line, into the trained random forest,
which yields predicted interaction counts as output, \autoref{fig:priorW:hicreg2}, middle left.
The results, too, are stored in a custom tab-separated text format.
\begin{figure}[p]
\centering
  \resizebox{!}{0.7\textheight}{
  \import{figures/}{hicreg5.pdf_tex}}
 \caption{HiC-Reg principle - \textsc{window} prediction}
 \label{fig:priorW:hicreg2}
\end{figure}
\begin{figure}[p]
\tiny
\centering
 \import{figures/}{zhang2019_predictions.pdf_tex}
 \caption[Hi-C matrices predicted by HiC-Reg]{Hi-C matrices predicted by HiC-Reg in \textsc{multi-cell} mode, cf.\,\cite[p.\,9]{Zhang2019}}
 \label{fig:priorW:hicregPredictions}
\end{figure}

In case data from multiple cell lines is available for training,
the window features of all training cell lines can be concatenated into so-called \textsc{multi-cell} test sets,
cf.\,\cite[Fig. 1]{Zhang2019}, but these were not used throughout this masterproject.
By default, HiC-Reg is using five-fold cross validation on training sets,
so it actually trains five different models for each training cell line and chromosome.
These models can then be used to predict interactions for a different
chromosome in the same cell line (\textsc{cross-chromosome}) or to predict interactions for the same chromosome in
another cell line (\textsc{cross-cell}) -- which is more relevant for practical use cases of HiC-Reg.
The final predicted matrix is just the average output of the five models.

Despite the aim of predicting Hi-C interaction counts, the publication by Zhang et al. unfortunately contains only two small plots
of actual Hi-C matrix snippets, depicted in their original size in \autoref{fig:priorW:hicregPredictions},
and instead relies on statistical measures to assess the quality of the predictions.
To this end, the two main metrics used are distance stratified Pearson
correlation and the corresponding area under the correlation curve, \textsc{auc}.
While this choice is in line with other relevant publications in the field \cite{Pierro2017, Farre2018, Schwessinger2019},
it seems unfavorable to rely on Pearson correlation too much, since the correlation can be high for Hi-C matrices
of biologically unrelated origin \cite{Yang2017}.
Within this report, correlation plots are thus always used in combination with plots of Hi-C matrix snippets.

Most of HiC-Reg, including the custom random forest regression model, is implemented in C++,
complemented by python-, shell- and matlab scripts e.\,g. for converting and concatenating input data or
computing various metrics. The source code and most binaries are available from github \cite{Roy2020}.

\subsection{Hicprediction}
Hicprediction was conceived and implemented as part of Andre Bajorat's masterproject at the Bioinformatics Group of the University of Freiburg
in 2019 \cite{Bajorat2019}. It is basically a python implementation of the ideas of Zhang et al. outlined above,
yet with a few technical differences.

In distinction from HiC-Reg, hicprediction accepts the common file formats narrowPeak and cooler \cite{Abdennur2019}
as inputs for ChIP-seq and Hi-C data, respectively, and also outputs Hi-C matrices directly in cooler format.
This eliminates the need for text format conversions,
but also limits applicability to cases where appropriate input files are available.
Another major difference to HiC-Reg is that hicprediction does not perform cross-validation on the training data
for \textsc{cross-cell} and \textsc{cross-chromosome} predictions.
Instead, it always trains its random forest on the full training set,
employing HiC-Reg's \textsc{window} approach described above.
With regard to binning proteins and computing \textsc{window}-features,
hicprediction supports more aggregation methods than HiC-Reg, mean (``avg''), sum and max, see \autoref{fig:priorW:hicpredFlow}.
While this might be interesting for future research, sum and max have not been used throughout this masterproject to
maintain comparability with the results from Zhang and colleagues.

Hicprediction is made up from four main python modules, which basically implement the workflow depicted in
\autoref{fig:priorW:hicreg2}.
\begin{figure}[htb]
 \small
 \centering
 \resizebox{\textwidth}{!}{
 \import{figures/}{hicprediction_flow1.pdf_tex}}
 \caption{Flow diagram of hicprediction (cross-chromosome prediction)}
 \label{fig:priorW:hicpredFlow}
\end{figure}
First, \emph{createBaseFile.py} \cite{hicpred2020bf} aggregates the protein data for training and test into bins of fixed width and stores them in an h5py
file,
see
\autoref{fig:priorW:hicpredFlow}, upper and lower left.
Additionally, input Hi-C matrices are cut into separate matrices, one per chromosome, and stored for further usage.
Next, \emph{createTrainingSet.py} \cite{hicpred2020cts} joins binned protein data with Hi-C interaction counts, computes the \textsc{window}-features mentioned
above and
stores the resulting datasets in a compressed binary format (\autoref{fig:priorW:hicpredFlow}, right).
The training dataset is then used by \emph{training.py} \cite{hicpred2020tr} to train a scikit-learn random forest regressor \cite{Pedregosa2011},
which is again stored in binary format (\autoref{fig:priorW:hicpredFlow}, middle).
Finally, \emph{predict.py} \cite{hicpred2020pr} takes the test set with protein data from the target cell line,
runs it through the trained model and outputs a predicted Hi-C matrix in cooler format (\autoref{fig:priorW:hicpredFlow}, middle left).
Additionally, a tab-separated text file can be output, containing distance stratified Pearson correlation values and \textsc{auc},
plus some other statistical measures and parameter settings for reference.

The original version of hicprediction is available from github \cite{BajoratHicpredWWW2019} and can be
installed using conda \cite{minicondaWWW2019}.
Each of the four python modules mentioned above takes a number of options and further inputs,
which are described in detail on the readme page in github.


\documentclass[12pt, letterpaper]{article}
\usepackage{abstract}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{braket}
\usepackage[hang,small,bf]{caption}
\usepackage[margin=1in]{geometry}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{
backgrounds,
shadows.blur,
fit,
decorations.pathreplacing,
shapes}
\usepackage[frame,line,arrow,matrix,tips]{xy}	% all that is usually necessary

\renewcommand{\abstractname}{}    % clear the title
\renewcommand{\absnamepos}{empty} % originally center

% qasm2circ definitions
\def\w{\ar@{-}[l]}
\def\A#1{\save []="#1" \restore}
\def\op#1{*+[F]{\rule[-0.2ex]{0ex}{2.1ex}#1}}	% operator in box
\def\b{*={\bullet}}
\def\o{*={\oplus}}
\def\m#1{\left[\matrix{#1}\right]}		% matrix shortcut
\def\z{*+[]{\rule[-0.2ex]{0ex}{2.1ex}~|0\>}}	% re-init to |0>
\def\discard{*[]{\rule[-0.2ex]{0.75pt}{2.1ex}~}}	% vertical ``|''
\def\n{*-{}\w}
\def\>{\rangle}
\def\<{\langle}
\def\ua{\uparrow}
\def\q#1{*+{\rule[-0.2ex]{0ex}{2.1ex}|#1\>}}
\def\qv#1#2{*+{\rule[-0.2ex]{0ex}{2.1ex}|#1\>=|#2\>}}

\title{CS 269Q Lecture 4 \\ \large Programming a quantum algorithm with pyQuil\vspace{-1ex}}
\author{Peter Karalekas \\ \small peter@rigetti.com}
\date{\normalsize April 11, 2019\vspace{-3ex}}

\begin{document}
\maketitle

\begin{abstract}
\noindent
We build out our quantum computing toolbox so that we can implement our very first quantum algorithm. We begin by working through a couple foundational concepts—the wavefunction, classical logic, and quantum parallelism—and then conclude with a walkthrough of the protocol for Deutsch's algorithm. Alongside these notes, there is a Jupyter notebook that uses Rigetti Computing's open-source software development kit, called Forest, to step through the algorithm and inspect the wavefunction.
\end{abstract}

\section{The wavefunction and quantum circuits}

We represent the state of our qubit using the ``ket" $\ket{\psi}$, which is a superposition of the states $\ket{0}$ and $\ket{1}$ that form a
basis for a two-dimensional complex vector space ($\mathbb{C}^2$). We additionally have a normalization condition on our complex amplitudes $\alpha$ and $\beta$ such that their magnitudes squared must sum to 1.

\begin{equation}
\ket{\psi} = \alpha \ket{0} + \beta \ket{1} \hspace{1 cm} |\alpha|^2 + |\beta|^2 = 1
\end{equation}

\subsection{1Q states}

For our quantum virtual machine (QVM), each qubit begins in the $|\psi\rangle = |0\rangle$ state. We then apply quantum gates to evolve the state of the QVM, and each gate $U$ must be unitary, meaning that $U^{\dag}U = I$. We can use an $X$ gate to flip between $|0\rangle$ and $|1\rangle$.

\begin{equation}
X|0\rangle = |1\rangle \hspace{1 cm} X|1\rangle = |0\rangle \vspace{3 mm}
\end{equation}

\noindent
In addition to swapping between the 1Q computational basis states, we can use quantum gates to create superposition states. Here we create the 1Q superposition states $|+\rangle$ amd $|-\rangle$ using the $H$ (Hadamard) gate.\vspace{2 mm}

\begin{equation}
H|0\rangle = \dfrac{|0\rangle + |1\rangle}{\sqrt{2}} = |+\rangle \hspace{1 cm} H|1\rangle = \dfrac{|0\rangle - |1\rangle}{\sqrt{2}} = |-\rangle
\end{equation}

\subsection{2Q states}

For two-qubit states, we can create ``product states" of computational basis states, which just look like two-bit bitstrings. Here we create the 2Q computational basis state $|10\rangle$.

\begin{equation}
(X \otimes I)|00\rangle = |10\rangle \vspace{3 mm}
\end{equation}

\noindent
We can also create product states of superposition states. Here we create the 2Q superposition state $|+,+\rangle$ using two Hadamard gates.\vspace{2 mm}

\begin{equation}
(H \otimes H)|00\rangle = \left( \dfrac{|0\rangle + |1\rangle}{\sqrt{2}}\right) \otimes \left( \dfrac{|0\rangle + |1\rangle}{\sqrt{2}}\right) = |+,+\rangle \vspace{4 mm}
\end{equation}

\noindent
In addition to product states, we can create entangled states, which we can no longer factor into the tensor product of two individual qubit states. Here we create the Bell state $|\Phi^+\rangle$.

\vspace{2 mm}
\begin{equation}
\text{CNOT}_{0,1}(I \otimes H)|00\rangle = \text{CNOT}_{0,1}|0\rangle \otimes \left( \dfrac{|0\rangle + |1\rangle}{\sqrt{2}}\right) = \dfrac{|00\rangle + |11\rangle}{\sqrt{2}} = |\Phi^+\rangle
\end{equation}

\section{Classical logic and function evaluation}

In Computer Science, we learn about Boolean logic gates like \texttt{NOT},
\texttt{AND}, \texttt{OR}, and \texttt{XOR}. In quantum computing, we can implement these classical logic gates, but we must do so in a way that respects the unitarity requirements of quantum logic gates.

\subsection{Boolean functions of 1-bit domain}
\vspace{2 mm}

\begin{equation}
x \in \{0,1\} \hspace{1cm} f(x) \rightarrow \{0,1\} \vspace{2 mm}
\end{equation}

\noindent
One-bit boolean functions represent the simplest classical logic we can implement on a quantum computer. There are four possible one-bit functions $f(x)$, and we will work through all of them.

\subsubsection{Balanced functions}
\vspace{2 mm}
$$\text{Balanced-}I : (0 \rightarrow 0,  1 \rightarrow 1)
\hspace{1 cm}
\text{Balanced-}X : (0 \rightarrow 1,  1 \rightarrow 0) \vspace{2 mm}$$

\noindent
For the balanced 1-bit functions, it’s pretty easy to come up with a quantum circuit that works. If we use just an $I$ gate for Balanced-$I$ and just an $X$ gate for Balanced-$X$, we can produce a quantum circuit $U_f$ that maps $|x\rangle \rightarrow |f(x)\rangle$. Knowing the gate and and output, we can reproduce the input, which means our circuit satisfies our reversibility requirements. Below, we have the quantum circuit for Balanced-$I$ on the left, and Balanced-$X$ on the right.

% the 1-qubit balanced circuits
\def\gAxA{\op{X}\w\A{gAxA}}
\def\bA{ \q{x}}
\begin{equation}
\xymatrix@R=5pt@C=10pt{
    \bA &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n
}\hspace{1 cm}
\xymatrix@R=5pt@C=10pt{
    \bA &\n &\n &\n &\gAxA &\n &\n &\n &\n
}
\end{equation}

\subsubsection{Constant functions}
\vspace{2 mm}
$$\text{Constant-}0 : (0 \rightarrow 0,  1 \rightarrow 0)
\hspace{1 cm}
\text{Constant-}1 : (0 \rightarrow 1,  1 \rightarrow 1) \vspace{2 mm}$$

\noindent
Coming up with the circuit for the constant functions seems less trivial. We can write down a matrix $M_f$ that maps the 0 state to the 0 state and the 1 state to the 0 state.\vspace{1 mm}

\begin{equation}
M_f = \left(\begin{matrix}
    1 & 1 \\
    0 & 0
\end{matrix}\right) \vspace{3 mm}
\end{equation}

\noindent
However, this matrix has some problems. It is not invertible (determinant 0) and it is not length preserving (superposition state changes length), and therefore it is not unitary. We can also see that it is not reversible simply from the truth table—knowing the output and the gate isn’t enough to get back to the input.\vspace{1 mm}

\begin{equation}
\text{det}(M_f) = \text{det}\left(\begin{matrix}
    1 & 1 \\
    0 & 0
\end{matrix}\right) = 1\cdot0 - 1\cdot0 = 0
\end{equation}
\vspace{3 mm}
\begin{equation}
M_f|\psi\rangle = \left(\begin{matrix}
    1 & 1 \\
    0 & 0
\end{matrix}\right)
\left(\begin{matrix}
    0.6 \\
    0.8
\end{matrix}\right) =
\left(\begin{matrix}
    1.4 \\
    0.0
\end{matrix}\right)
\end{equation}

\subsubsection{Ancilla qubits}

In order to write this function as a quantum circuit, we need to introduce a new concept—the ancilla qubit. An ancilla qubit is an additional qubit used in a computation that we know the initial state of. Using an ancilla, we can produce a quantum circuit $U_f$ that maps $|0, x\rangle \rightarrow |f(x), x\rangle$. Now, we can come up with a unitary matrix (albeit a trivial one) that allows us to evaluate constant functions. For the Constant-$0$, we just simply do nothing to the ancilla, and its state encodes $f(x)$. And for the Constant-$1$, all we have to do is flip the ancilla with an $X$ gate, and we get $f(x)$ for all $x$. Below, we have the Balanced-$I$ (top left), Balanced-$X$ (bottom left), Constant-$0$ (top right), and Constant-$1$ (bottom right) functions implemented as quantum circuits with one ancilla qubit. We will continue to use this ordering for sections 2.3 and 2.4.

\begin{equation}
|0, x\rangle \rightarrow |f(x), x\rangle
\end{equation}

% ancilla qubit circuits
\def\gAxB{\op{X}\w\A{gAxB}}
\def\gBxA{\b\w\A{gBxA}}
\def\gBxB{\o\w\A{gBxB}}
\def\bA{ \q{x}}
\def\bB{ \q{0}}
$$
\xymatrix@R=5pt@C=10pt{
    \bA &\n &\n &\n &\n &\n &\n &\n &\n &\n &\gBxA &\n &\n &\n
\\  \bB &\n &\n &\n &\n &\n &\n &\n &\n &\n &\gBxB &\n &\n &\n
\ar@{-}"gBxB";"gBxA"
}\hspace{1 cm}
\xymatrix@R=5pt@C=10pt{
    \bA &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n
\\  \bB &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n
}$$
$$
\xymatrix@R=5pt@C=10pt{
    \bA &\n &\n &\n &\gBxA &\n &\n &\n
\\  \bB &\n &\n &\gAxB &\gBxB &\n &\n &\n
\ar@{-}"gBxB";"gBxA"
}\hspace{1 cm}
\xymatrix@R=5pt@C=10pt{
    \bA &\n &\n &\n &\n &\n &\n &\n &\n
\\  \bB &\n &\n &\n &\gAxB &\n &\n &\n &\n
}$$

\subsection{The Quantum \texttt{XOR} gate}

The Boolean function \texttt{XOR} (for ``exclusive or") takes in two bits $x$ and $y$ and returns 1 if and only if the values of the bits are different from one another. Otherwise, it returns 0. The operation is written as $x \oplus y$, and although it is a two-bit function, we can implement it as a quantum circuit without an ancilla, by simply using the \textrm{CNOT} gate.

\begin{equation}
\textrm{CNOT}_{0,1}|y, x\rangle = |y \oplus x, x\rangle
\end{equation}

% xor circuit
\def\gAxA{\b\w\A{gAxA}}
\def\gAxB{\o\w\A{gAxB}}
\def\bA{ \q{x}}
\def\bB{ \q{0}}
$$\xymatrix@R=5pt@C=10pt{
    \bA &\n &\n &\gAxA &\n &\n &\n
\\  \bB &\n &\n &\gAxB &\n &\n &\n
\ar@{-}"gAxB";"gAxA"
}$$

\subsection{Deutsch Oracle}

In Deutsch's algorithm, we are given something called an oracle (referred to as $U_f$), which maps $|y, x\rangle \rightarrow |y \oplus f(x), x\rangle$, and the goal is to determine a global property of the function $f(x)$ with as few queries to the oracle as possible. We can combine the two concepts above (one-bit function evaluation with ancillas, and the \texttt{XOR} gate), to produce the four implementations of the Deutsch Oracle with one ancilla qubit.

\begin{equation}
U_f : |y, 0, x\rangle \rightarrow |y \oplus f(x), 0, x\rangle
\end{equation}

% deutsch oracle circuit
\def\gAxB{\op{X}\w\A{gAxB}}
\def\gBxA{\b\w\A{gBxA}}
\def\gBxB{\o\w\A{gBxB}}
\def\gCxB{\b\w\A{gCxB}}
\def\gCxC{\o\w\A{gCxC}}
\def\gDxA{\b\w\A{gDxA}}
\def\gDxB{\o\w\A{gDxB}}
\def\gExB{\op{X}\w\A{gExB}}
\def\bA{ \q{x}}
\def\bB{ \q{0}}
\def\bC{ \q{y}}
$$\xymatrix@R=5pt@C=10pt{
    \bA &\n &\n &\n &\n &\n &\n &\gBxA &\n &\gDxA &\n &\n &\n &\n &\n &\n &\n
\\  \bB &\n &\n &\n &\n &\n &\n &\gBxB &\gCxB &\gDxB &\n &\n &\n &\n &\n &\n &\n
\\  \bC &\n &\n &\n &\n &\n &\n &\n &\gCxC &\n &\n &\n &\n &\n &\n &\n &\n
\ar@{-}"gBxB";"gBxA"
\ar@{-}"gCxC";"gCxB"
\ar@{-}"gDxB";"gDxA"
}\hspace{1 cm}
\xymatrix@R=5pt@C=10pt{
    \bA &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n & \n &\n &\n &\n
\\  \bB &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\gCxB &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n
\\  \bC &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\gCxC &\n &\n &\n &\n &\n &\n & \n &\n &\n &\n
\ar@{-}"gCxC";"gCxB"
}$$
$$\xymatrix@R=5pt@C=10pt{
    \bA &\n &\gBxA &\n &\gDxA &\n &\n
\\  \bB &\gAxB &\gBxB &\gCxB &\gDxB &\gExB &\n
\\  \bC &\n &\n &\gCxC &\n &\n &\n
\ar@{-}"gBxB";"gBxA"
\ar@{-}"gCxC";"gCxB"
\ar@{-}"gDxB";"gDxA"
}\hspace{1 cm}
\xymatrix@R=5pt@C=10pt{
    \bA &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n
\\  \bB &\gAxB &\n &\n &\n &\gCxB &\n &\n &\n &\gAxB &\n
\\  \bC &\n &\n &\n &\n &\gCxC &\n &\n &\n &\n &\n
\ar@{-}"gCxC";"gCxB"
}$$

\subsection{Optimized Deutsch Oracle}

For pedagogical reasons, it is nice to separate out the three steps in the Deutsch Oracle—evaluate $f(x)$, calculate $y \oplus f(x)$, and then return the ancilla to $|0\rangle$. But, in practice we always want to implement our circuits in as few gates as possible (this is especially important when running on a real, noisy quantum computer!). Below, we show how we can rewrite each of the four Deutsch Oracle implementations (which we call $U_f$) without the need for an ancilla qubit.

\vspace{20 mm}
\begin{equation}
U_f : |y, x\rangle \rightarrow |y \oplus f(x), x\rangle
\end{equation}

% optimized deutsch oracle circuits
\def\gAxA{\op{X}\w\A{gAxA}}
\def\gBxA{\b\w\A{gBxA}}
\def\gBxB{\o\w\A{gBxB}}
\def\gCxA{\op{X}\w\A{gCxA}}
\def\bA{ \q{x}}
\def\bB{ \q{y}}
$$\xymatrix@R=5pt@C=10pt{
    \bA &\n &\n &\n &\n &\n &\n &\gBxA &\n &\n &\n &\n &\n &\n &\n &\n
\\  \bB &\n &\n &\n &\n &\n &\n &\gBxB &\n &\n &\n &\n &\n &\n &\n &\n
\ar@{-}"gBxB";"gBxA"
}\hspace{1 cm}
\xymatrix@R=5pt@C=10pt{
    \bA &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n
\\  \bB &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n
}$$
$$\xymatrix@R=5pt@C=10pt{
    \bA &\gAxA &\gBxA &\gCxA &\n
\\  \bB &\n &\gBxB &\n &\n
\ar@{-}"gBxB";"gBxA"
}\hspace{1 cm}
\xymatrix@R=5pt@C=10pt{
    \bA &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n
\\  \bB &\n &\n &\n &\n &\n &\gAxA &\n &\n &\n &\n &\n &\n
}$$

\section{Quantum parallelism}

In the previous section, we showed that we could implement classical logic using quantum circuits. However, when using a computational basis state ($|0\rangle$ or $|1\rangle$), we don't do anything more interesting than a classical computer can do. If we instead feed a superposition state into one of these circuits, we can effectively evaluate a function $f(x)$ on multiple values of $x$ at once!

\begin{equation}
U_f : |0,+\rangle \rightarrow \dfrac{|f(0), 0\rangle + |f(1), 1\rangle}{\sqrt{2}}
\end{equation}
\vspace{1 mm}

\begin{equation}
U_f : |0,-\rangle \rightarrow \dfrac{|f(0), 0\rangle - |f(1), 1\rangle}{\sqrt{2}}
\end{equation}
\vspace{1 mm}

\noindent
It is important to note, that although this quantum parallelism concept is interesting, we are unable to learn about both $f(0)$ and $f(1)$ when the states above are in that form. This is due to the fact that we can only extract one classical bit of information from a quantum computer (of 1 qubit) when we measure it. But, as we will find in Deutsch's algorithm below, we can cleverly take advantage of quantum parallelism to do things that a classical computer cannot, even with the constraint that measurement yields only one classical bit.

\subsection{Test with Balanced-$I$}

To verify, we run the Balanced-$I$ circuit for an input that is in a superposition state.

\vspace{2 mm}
\begin{equation}
\text{CNOT}_{0,1}|0,+\rangle = \dfrac{\text{CNOT}_{0,1}|00\rangle + \text{CNOT}_{0,1}|01\rangle}{\sqrt{2}} = \dfrac{|00\rangle + |11\rangle}{\sqrt{2}} = |\Phi^+\rangle
\end{equation}
\vspace{1 mm}

\begin{equation}
\text{CNOT}_{0,1}|0,-\rangle = \dfrac{\text{CNOT}_{0,1}|00\rangle - \text{CNOT}_{0,1}|01\rangle}{\sqrt{2}} = \dfrac{|00\rangle - |11\rangle}{\sqrt{2}} = |\Phi^-\rangle
\end{equation}
\vspace{2 mm}

\noindent
In both of our output states, we can see that if we take the state of qubit 0 in each ket to be $x$, the state of qubit 1 in the corresponding ket is equal to $f(x)$ (as $f(x) = x$ for Balanced-$I$).

\section{Deutsch's algorithm}

\noindent
\textbf{Goal}: Determine if function $f(x)$ is \textit{constant} ($f(0) = f(1)$) or \textit{balanced} ($f(0) \neq f(1)$).

\vspace{1 mm}
{
% utulity text box for figuring out width of things
\newbox{\sbox}
% empty space of width determined by the text argument
\def\gspace#1{*+{\rule[-0.2ex]{0ex}{2.1ex}%
	\setbox\sbox=\hbox{$#1$}%
	\hspace*{\wd\sbox}
	\hspace*{\wd\sbox}
	\hspace*{\wd\sbox}}}
% n-qubit operation #1=box label, #2=number of qubits (eg d=2 qubits, ddd=4)
\def\gnqubit#1#2{\gspace{#1}
		 \save [].[#2]!C="qq"*[F]\frm{}\restore
		 \save "qq"*[]{#1} \restore}

% deutsch's algorithm circuit
\def\gAxA{\op{H}\w\A{gAxA}}
\def\gAxB{\op{H}\w\A{gAxB}}
\def\gBxA{\gnqubit{U_{f}}{d}\w\A{gBxA}}
\def\gBxB{\gspace{U_{f}}\w\A{gBxB}}
\def\gCxA{\op{H}\w\A{gCxA}}
\def\gCxB{\op{H}\w\A{gCxB}}
\def\bA{ \q{0}}
\def\bB{ \q{1}}
\begin{equation}
\begin{split}
\xymatrix@R=5pt@C=10pt{
    \bA &\n &\n &\gAxA &\n &\n &\gBxA &\n &\n &\gCxA &\n &\n &\n
\\  \bB &\n &\n &\gAxB &\n &\n &\gBxB &\n &\n &\gCxB &\n &\n &\n
}
\end{split}
\end{equation}
}

\vspace{2 mm}

\noindent
As part of the algorithm, we are given a Deutsch Oracle and are unaware of which one-bit Boolean function $f(x)$ it implements. We show that we can do this with only one query to the Deutsch Oracle, which is impossible on a classical computer, which would require two queries to the Deutsch Oracle to determine this global property of $f(x)$.

\subsection{Initial state}

We begin our algorithm in the computational basis state $|10\rangle$. The fact that the states for qubit 0 and qubit 1 are different proves to be important.

\begin{equation}
|\psi_0\rangle = |10\rangle
\end{equation}

\subsection{Prepare superpositions}

We cannot do anything interesting with computational basis states, so to take advantage of quantum parallelism we put our qubits in superposition states.\vspace{1 mm}

\begin{equation}
|\psi_1\rangle = (H \otimes H)|\psi_0\rangle = (H \otimes H)|10\rangle = \left( \dfrac{|0\rangle - |1\rangle}{\sqrt{2}}\right) \otimes \left( \dfrac{|0\rangle + |1\rangle}{\sqrt{2}}\right) = |-,+\rangle \vspace{1 mm}
\end{equation}

\subsection{Apply the Deutsch Oracle}

We learned earlier that the action of the Deutsch Oracle on input state $|y,x\rangle$ is $U_f|y, x\rangle \rightarrow |y \oplus f(x), x\rangle$. So, what happens if we apply the Deutsch Oracle to the input state $|-,x\rangle$?

\begin{equation}
\begin{split}
U_f|-, x\rangle
&= \dfrac{U_f|0, x\rangle - U_f|1, x\rangle}{\sqrt{2}} \\
\vspace{1 mm}\\
&= \dfrac{|0 \oplus f(x), x\rangle - |1 \oplus f(x), x\rangle}{\sqrt{2}} \\
\vspace{1 mm}\\
&= \begin{cases}
    \dfrac{|0, x\rangle - |1, x\rangle}{\sqrt{2}}  = (+1)|-,x\rangle \text{ \hspace{5 mm} if } f(x) = 0;\\
    \vspace{1 mm}\\
    \dfrac{|1, x\rangle - |0, x\rangle}{\sqrt{2}}  = (-1)|-,x\rangle \text{ \hspace{5 mm} if } f(x) = 1.
\end{cases}
\end{split}
\end{equation}
\vspace{1 mm}

\noindent
These two branches can be unified, as we see in the following equation.

\begin{equation}
U_f|-, x\rangle = (-1)^{f(x)}|-, x\rangle
\vspace{3 mm}
\end{equation}

\noindent
Thus, we get a negative sign if $f(x) = 1$, and the state is unchanged if $f(x) = 0$. However, something interesting happens when we apply $U_f$ to the state $|-,+\rangle$, which is $|\psi_1\rangle$.

\begin{equation}
\begin{split}
|\psi_2\rangle = U_f|\psi_1\rangle
&= U_f|-, +\rangle \\
\vspace{1 mm}\\
&= \dfrac{U_f|-, 0\rangle + U_f|-, 1\rangle}{\sqrt{2}} \\
\vspace{1 mm}\\
&= \dfrac{(-1)^{f(0)}|-, 0\rangle + (-1)^{f(1)}|-, 1\rangle}{\sqrt{2}} \\
\vspace{1 mm}\\
&= |-\rangle \otimes \left( \dfrac{(-1)^{f(0)}|0\rangle + (-1)^{f(1)}|1\rangle}{\sqrt{2}}\right) \\
\vspace{1 mm}\\
&= \begin{cases}
   \pm |-\rangle \otimes \left( \dfrac{|0\rangle + |1\rangle}{\sqrt{2}}\right) = \pm |-,+\rangle \text{ \hspace{5 mm} if constant;} \\
   \vspace{1 mm}\\
   \pm |-\rangle \otimes \left( \dfrac{|0\rangle - |1\rangle}{\sqrt{2}}\right) = \pm |-,-\rangle \text{ \hspace{5 mm} if balanced.}
\end{cases}
\end{split}
\end{equation}
\vspace{1 mm}

\noindent
If $f(x)$ is balanced, this has the effect of changing the relative phase between the $|0\rangle$ and $|1\rangle$ components of qubit 0's state, which flips it from $|+\rangle$ to $|-\rangle$. This is interesting, because the action of our oracle on the computational basis state $|y,x\rangle$ is to change the state of qubit 1 and leave qubit 0 alone. But, when our qubits are in superposition states, the balanced oracle actually changes the state of qubit 0 (which is the control qubit in the oracle), and leaves alone the state of qubit 1 (which is the target qubit in the oracle).

\subsection{Return to 2Q computational basis states}

We know that the outcome of the previous step is to produce one of two superposition product states, $|-, +\rangle$ or $|-, -\rangle$. However, our goal is to query the Deutsch Oracle as few times as possible, and so although we can see that these states are different, we cannot distinguish them with a single measurement (as we only get a 0 or a 1). Therefore, we use the Hadamard gate to return to 2Q computational basis states that can be distinguished in one measurement.

\begin{equation}
|\psi_3\rangle = (H \otimes H)|\psi_2\rangle =
\begin{cases}
   \pm (H \otimes H)|-, +\rangle = \pm |10\rangle \text{ \hspace{5 mm} if constant;}\\
   \\
   \pm (H \otimes H)|-, -\rangle = \pm |11\rangle \text{ \hspace{5 mm} if balanced.}
\end{cases}
\end{equation}
\vspace{1 mm}

\noindent
Thus, we are in two distinct 2Q computational basis states, dependent on the nature of $f(x)$. We could then measure the state of qubit 0 one time, and we would immediately know the answer to whether $f(x)$ is constant or balanced.

\subsection{Conclusions}

So, we were able to learn about a \textit{global property} of the function $f(x)$ in just one query to the Deutsch Oracle, which is impossible on a classical computer. Although the problem statement for Deutsch's algorithm is a bit contrived, if you can suspend your judgment, you can imagine that we could take some of the non-classical concepts of this algorithm and apply them to a more complex scenario to actually produce an interesting quantum speedup. And, later in the course, you will do exactly this!

\end{document}


\documentclass[../main.tex]{subfiles}

\begin{document}
\section{Bipolar Transistors}

\ex{2.1}
	We assume a forward voltage for the LED of 1.5\V. Then for $I_{LED}$ we have
	\[I_{LED} = \frac{V_R}{R} = \frac{3.3\V - 1.5\V}{330\Ohm} \approx \sol{5.5\m\A}\]
	To estimate the $\beta_{min}$ we need the current entering the base
	\[I_B = \frac{3.3\V - 0.6\V}{10\k\Ohm} = 0.27\m\A \]
	Thus
	\[\beta_{min} \geq \frac{I_{LED}}{I_B} = \sol{20}\]

\ex{2.2}

	\tans{NOTE: According to the errata $0.63$ should be replaced by $0.76$ and $63\u\sec$ by $76\u\sec$.}
	\\\\
	Starting from the hint that the capacitor charges from $-4.4\V$ towards $+5\V$, we would result to a total $9.4\V$ for a full charge. However, the $V_{BE}$ of $Q_2$ is clipping the charging process at only $5\V$ of the total (from $-4.4\V$ to $0.6\V$). Thus, the capacitor will be $53\%$ charged at the end. \\Solving the voltage equation for a charging capacitor gives us
	\[V_C(t) = V_f * (1 - e^{-\frac{t}{R C}})\]
	set $V_C(t_1) = 0.53 * V_f$
	\[0.53 = 1 - e^{-\frac{t_1}{R_3 C_1}}\]
	\[\Rightarrow\]
	\[t_1 = - R_3 C_1*ln(0.47) \approx \sol{0.76 * R_3 C_1}\]

\ex{2.3}

	The output voltage is reduced due to the $R_4 - R_5$ voltage divider
	\[V_\out = \frac{R_5}{R_4 + R_5} * (V_{CC} - 0.6\V) \approx \sol{4.18\V}\]
	To estimate the minimum $\beta_3$, we need first to find the maximum (worst-case) collector current for which $Q_3$ should still be in saturation. For this we can assume a $0\V$ drop across C and $Q_3$ while the current travels through the parallel connected resistors $R_2||R_3$.
	\[I_{C_3,max} = \frac{V_{CC}}{R_2||R_3} = 5.5\m\A\]
	\[\Rightarrow \beta_{3,min} = \frac{I_{C_3,max}}{I_{B_3}} = \frac{5.5\m\A}{\frac{(4.18\V - 0.6\V)} {20\k\Ohm}} \approx \sol{31}\]

\ex{2.4}

	By using KCL and the fact that the transistor is in the active region we get
	\[i_E = i_C + i_B = (\beta + 1) * i_B = (\beta + 1) \frac{v_B}{Z_{source}}\]
	For small signals $Z_\out = \frac{v_E}{i_E} = \frac{v_B}{i_E}$. Thus:
	\[ \sol{Z_\out = \frac{v_B}{(\beta + 1)\frac{v_B}{Z_{source}}} = \frac{Z_{source}}{\beta +1}}\qquad q.e.d.\]
	Note: In practice one will often see $Z_\out \approx \frac{Z_{source}}{\beta}$. When $\beta \approx 100$ the "$+ 1$" part is often being ignored to simplify calculations.

\ex{2.5}

	\begin{schematic}{fig:2.5.1}{Follower driven by voltage divider}
		(0,-1) node[ground](GND1){}
		(GND1) to[R=$R_2$] (0,2)
		to[R=$R_1$] (0,4)
		(0,4) node[vcc] {$+15\V$}

		(3,2) node[npn] (Q1) {Q}
		(0,2) to[short] (Q1.B)
		(3,2) node[npn] (Q1) {Q}
		(3,4) node[vcc] {$+15\V$}
		(3,4) to[short] (Q1.C)
		(3,-1) node[ground](GND2){}
		(Q1.E) to[R=$R_E$] (GND2)
		(Q1.E) to[short, -o] ++(2,0) node[right]{$+5\V$}
		(Q1.B) node[above]{$5.6\V$}
	\end{schematic}

	We can simplify the voltage divider with it equivalent Th\'evenin voltage source depicted in Figure~\ref{fig:2.5.2} below.

	\begin{schematic}{fig:2.5.2}{Follower driven by equivalent Th\'evenin source}
		(0,-1) node[ground](GND1){}
		(GND1) to[V, l=$V_\Th$, a={$+5.6\V$}, invert] (0,2)

		(3,2) node[npn] (Q1) {Q}
		(0,2) to[R=$R_\Th$] (Q1.B)
		(3,4) node[vcc] {$+15\V$}
		(3,4) to[short] (Q1.C)
		(3,-1) node[ground](GND2){}
		(Q1.E) to[R=$R_E$] (GND2)
		(Q1.E) to[short, -o] ++(2,0) node[right]{$+5\V$}
	\end{schematic}

	With $R_\Th = R_1||R_2$ which is also our $R_{source}$. The output impedance of our circuit then is
	\[R_\out=\frac{R_\Th}{\beta + 1} \approx \frac{R_\Th}{100} = \frac{R_1||R_2}{100}\qquad(\text{assuming}~\beta \approx 100)\]

	We also know that the following condition needs to be true in order to achieve the wished $5.6\V$ at the base:
	\[\frac{R_2}{R_1 + R_2} = \frac{5.6\V}{15\V} \Rightarrow R_2 \approx 0.6 * R_1\]

	Now let's observe the equivalent circuit \emph{with} load.

	\begin{schematic}{fig:2.5.3}{Equivalent voltage source of emitter follower with load}
		(3,-2) node[ground](GND1){}
		(0,0) node[left]{$+5\V$}
		to[R=$R_\out$, o-] (3,0)
		to[short, -o] (4,0) node[right]{$V\out$}
		(3,0) to[R=$R_L$] (GND1)
	\end{schematic}

	Our goal is to have a maximum voltage drop of 5\% with maximum load:

	\[V_\out = \frac{R_L}{R_\out + R_L} * 5\V \geq 0.95 * 5\V\]
	$\Rightarrow$
	\[R_\out \leq \frac{R_L}{19} \leq \frac{\frac{4.75\V}{25\m\A}}{19} = 10\Ohm\]
	$\Rightarrow$
	\[\frac{R_\Th}{100} \leq 10\Ohm\]
	$\Rightarrow$
	\[\frac{R_1||R_2}{100} \leq 10\Ohm\]
	$\Rightarrow$
	\[R_1 \leq 2.7\k\Ohm~\text{and}~R_2 \leq 1.62\k\Ohm\]

	We choose the following values for $R_1$ and $R_2$:
	\[\sol{R_1 = 2.7\k\Ohm}~\text{and}~\sol{R_2 = 1.6\k\Ohm}\]

	NOTE 1: We could have picked more conservative (smaller) values for the resistors. However, this would increase the idle power consumption.\\\\
	NOTE 2: We could also define a value for $R_E$ i.e. to limit the quiescent current, but this is out of the scope of this exercise. Basically we see now $R_E$ as our load or put differently, our total load is $R_E||Z_{whatever-the-user-wants}$.

\end{document}


% Prelim, Appendix C
% by Rachel Slaybaugh

\chapter{Reflecting Boundaries}
\label{sec:AppendixC}

Algorithm \ref{algo:RQI+MGkrylov} in Chapter~\ref{sec:Chp3} works for problems with vacuum boundary conditions. However, with reflecting boundary conditions some modifications must be made to the calculation of the Rayleigh quotient. To compute the correct RQ the reflected boundary terms must be excluded when computing the dot products, but their contribution to the real moments must be included properly. It was not possible to do this using the solvers in Denovo when this work was begun. How Denovo handles reflecting boundary conditions and what was done to fix this problem are detailed here. The information in this section is derived from conversations with Tom Evans \cite{Evans2011a} and a paper by Warsa et.\ al.\ \cite{Warsa2004}.

Denovo stores the boundary condition information between the flux moments in the solution vector. For the following discussion let the moments for group $g$ be held in $\phi_{g}$, which is of length $f_{g} = t \times c \times u$ (these sizes are defined in Chapter \ref{sec:Chp1}). Let the reflected angular flux for that group be $\psi_{r,g}$, which is of length $m = n \times c_{r} \times u$ where $c_{r}$ is the number of cells on the reflecting boundaries. For each group the solution vector and associated source are of length $f_{g} + m$ and look like
%
\begin{alignat}{2}
 \Phi_{g} = \begin{pmatrix} \phi_{g} & \psi_{r,g} \end{pmatrix}^{T} \:, \qquad Q = \begin{pmatrix} q & 0 \end{pmatrix}^{T} \:.
\label{eq:reflFlux}
\end{alignat}
%
To exclude the boundary terms when computing the dot products in the RQ, $\Phi_{g}$ is simply truncated to only include $\phi_{g}$.

Understanding the next issue is aided by considering what the operator form of the transport equation for one group looks like with reflecting boundary conditions. First recall the transport equation for group $g$ that \emph{does not} include reflecting boundaries, where group indices are excluded for notational brevity:
%
\begin{align}
  \mathbf{L} \psi &= \mathbf{MS}\phi + q
  \label{eq:transport} \\
  \bigl(\ve{I} - \ve{DL}^{-1}\ve{MS} \bigr) \phi &= \ve{DL}^{-1}q \:.
  \label{eq:transportMoments}
\end{align}

To include reflecting boundaries, the operators are expanded in the appropriate dimensions from $f_{g}$ to $f_{g} + m$ to act on $\Phi$. The reflecting operators will be denoted by a tilde. The transport operator is split into volume (traditional) and reflected components: $\tilde{\ve{L}} = \ve{L}_{v} + \ve{L}_{r}$. The other terms become:
%
\begin{alignat}{4}
  \ve{\tilde{I}} = \begin{pmatrix} \ve{I} & 0 \\ 0 & \ve{I}_{r} \end{pmatrix} \:, \nonumber
 \qquad
 \ve{\tilde{D}} = \begin{pmatrix} \ve{D} & 0 \\ 0 & \ve{I}_{r} \end{pmatrix} \:, \nonumber
 \qquad
 \ve{\tilde{M}} = \begin{pmatrix} \ve{M} & 0 \\ 0 & \ve{I}_{r} \end{pmatrix} \:, \nonumber
 \qquad
 \ve{\tilde{S}} = \begin{pmatrix} \ve{S} & 0 \\ 0 & \ve{I}_{r} \end{pmatrix} \:. \nonumber
\end{alignat}
%
The operators in Equation \eqref{eq:transportMoments} can now be replaced by the reflecting operators, and then doing a transport solve will converge both the moments and reflected terms at once.

When computing the Rayleigh quotient, however, the operator is applied but a full solve is not done. With Denovo's standard implementation this does not converge $\psi_{r}$ and therefore those terms do not contribute to the solution properly.

To address this the reflecting boundaries must be converged first by solving each group separately while excluding within-group scattering. Explicitly multiplying the reflecting matrices illustrates what is happening here. The inverse of the reflecting transport operator is
%
\begin{alignat}{3}
 \ve{\tilde{L}}^{-1} = \begin{pmatrix} \ve{I} \\ \ve{P}^{T} \end{pmatrix}
 \begin{pmatrix} \ve{L}_{v}^{-1} & -\ve{L}_{v}^{-1} \ve{L}_{r} \ve{P} \end{pmatrix}
 =
 \begin{pmatrix} \ve{L}_{v}^{-1} & -\ve{L}_{v}^{-1} \ve{L}_{r} \ve{P} \\
                   \ve{P}^{T}\ve{L}_{v}^{-1} & -\ \ve{P}^{T}\ve{L}_{v}^{-1} \ve{L}_{r} \ve{P} \end{pmatrix}  \:,
\label{eq:reflInverse}
\end{alignat}
%
where $\ve{P}$ is a projection operator that projects $\psi_{r} \to \psi$. The multiplication makes the system:
%
\begin{equation}
  \Bigg[ \begin{pmatrix} \ve{I} & 0 \\ 0 & \ve{I}_{r} \end{pmatrix} -
  \begin{pmatrix} \ve{DL}_{v}^{-1}\ve{MS} & -\ve{DL}_{v}^{-1}\ve{L}_{r}\ve{P} \\
                      \ve{P}^{T}\ve{L}_{v}^{-1}\ve{MS} & - \ve{P}^{T}\ve{L}_{v}^{-1} \ve{L}_{r} \ve{P} \end{pmatrix} \Bigg]
  \begin{pmatrix} \phi \\ \psi_{r} \end{pmatrix}
  =
  \begin{pmatrix} \ve{DL}_{v}^{-1} & -\ve{DL}_{v}^{-1}\ve{L}_{r}\ve{P} \\
                     \ve{P}^{T}\ve{L}_{v}^{-1} & - \ve{P}^{T}\ve{L}_{v}^{-1} \ve{L}_{r} \ve{P} \end{pmatrix}
  \begin{pmatrix} q \\ 0 \end{pmatrix} \:.
\label{eq:explicitBlocks}
\end{equation}
%

Now there are two equations with two unknowns that can be examined for similarities.
\begin{align}
  \phi - \ve{DL}_{v}^{-1}\ve{MS}\phi + \ve{DL}_{v}^{-1}\ve{L}_{r}\ve{P} \psi_{r} &= \ve{DL}_{v}^{-1} q
\label{eq:momentTE} \\
  \psi_{r} - \ve{P}^{T}\ve{L}_{v}^{-1}\ve{MS} \phi + \ve{P}^{T}\ve{L}_{v}^{-1} \ve{L}_{r} \ve{P} \psi_{r} &= 0
\label{eq:reflTE}
\end{align}
Comparing the reflecting case to the standard case, $\ve{P}^{T}$ replaces $\ve{D}$ and $-\ve{L}_{r}\ve{P}$ acts like $\ve{MS}$. Equation \eqref{eq:reflTE} can be rearranged and solved for $\psi_{r}$. In Denovo this amounts to solving each group separately to converge the reflecting flux where the group source is $\ve{P}^{T}\ve{L}_{v}^{-1}\ve{MS} \phi$. The reflecting boundaries will then contribute properly when solving Equation \eqref{eq:momentTE} where the effective source becomes $q - \ve{DL}_{v}^{-1}\ve{L}_{r}\ve{P} \psi_{r}$.

In practice, the process to apply $\ve{A}$ in Denovo when calculating the Rayleigh quotient is:
%
\begin{alignat}{2}
  \ve{\tilde{L}} z = v \:, \qquad y = \ve{\tilde{D}}z \:.
\label{eq:calcRQ}
\end{alignat}
%
Now Equation \eqref{eq:calcRQ} looks just like Equation \eqref{eq:transport} where the within-group scattering source is set to zero ($\ve{S} = 0$) and $v = q$.

An alternative way to express the same idea using the traditional operators with the $\ve{L}_{v}$ and $\ve{L}_{r}$ terms can be informative as well. This is presented in source iteration notation, where the reflecting boundaries are lagged. This is exactly the same idea as above, though iteration indices were excluded.
\begin{align}
  \psi^{l+1} &= \ve{L}_{v}^{-1} \bigl( \ve{MS} \phi^{l} - \ve{L}_{r} \ve{P} \psi_{r}^{l} \bigr) + \ve{D}q
\label{eq:laggedSI} \\
  \phi^{l+1} &= \ve{D}\psi^{l+1} \:.
\end{align}

A new solver was written that solves each group separately to converge the reflecting boundaries. This solver is used to compute the Rayleigh quotient when there are reflecting boundaries. This has worked well, but has not yet been implemented for multisets because each group must be solved separately.


\section{Numerical Illustrations}

\subsection{Examples from \citep{huang1995software}}

\subsubsection{Example A}
\begin{itemize}
  \item Mean Time Between Failures (MTBF): $12 \times 30 \times 24$ hours
  \item failure repair time:  30 minutes
  \item base longevity interval:  $7 \times 24$ hours
  \item rejuvenation time: 20 minutes
  \item average cost of unscheduled downtime: \$1700 / hour
  \item average cost of scheduled downtime: \$40 / hour
\end{itemize}

\begin{table}[h]
\begin{tabular}{ | l || c | c | c | }
  \hline
   \multicolumn{4}{|c|}{For $12 \times 30 \times 24 $ hours } \\
  \hline
    & no rejuvenation & once every 3 weeks & once every two weeks \\
   \hline
  Hours of Down Time  & 0.49 & 5.965 & 8.727 \\
  \hline
  \$Cost of Down Time & 490  & 554 & 586 \\
  \hline
\end{tabular}
  \caption{Huang etc's estimation for Example A}
\end{table}

\subsubsection{Example B}
\begin{itemize}
  \item Mean Time Between Failures (MTBF): $3 \times 30 \times 24$ hours
  \item failure repair time:  30 minutes
  \item base longevity interval:  $3 \times 24$ hours
  \item rejuvenation time: 10 minutes
  \item average cost of unscheduled downtime: \$5000 / hour
  \item average cost of scheduled downtime: \$5 / hour
\end{itemize}

\begin{table}[h]
\begin{tabular}{ | l || c | c | c | }
  \hline
   \multicolumn{4}{|c|}{For $12 \times 30 \times 24 $ hours } \\
  \hline
    & no rejuvenation & once every 2 weeks & once a week \\
   \hline
  Hours of Down Time  & 1.94 & 5.70 & 9.52 \\
  \hline
  \$Cost of Down Time & 9675.25  & 7672.43 & 5643.31 \\
  \hline
\end{tabular}
  \caption{Huang etc's estimation for Example B}
\end{table}

\begin{figure}[h]
     \begin{center}
     \subfigure[]{
\includegraphics[scale=0.18]{./plot/Huang1995B2/accumulated_cost_day.png}
        }
\subfigure[]{
\includegraphics[scale=0.18]{./plot/Huang1995B2/accumulated_cost_month.png}
        }\\
        \subfigure[]{
\includegraphics[scale=0.18]{./plot/Huang1995B3/accumulated_cost_day.png}
        }
	\subfigure[]{
\includegraphics[scale=0.18]{./plot/Huang1995B3/accumulated_downtime_month.png}
        }\\

        \subfigure[]{
\includegraphics[scale=0.18]{./plot/Huang1995B2/availability_day.png}
        }
\subfigure[]{
\includegraphics[scale=0.18]{./plot/Huang1995B2/availability_month.png}
        }\\
        \subfigure[]{
\includegraphics[scale=0.18]{./plot/Huang1995B3/availability_day.png}
        }
	\subfigure[]{
\includegraphics[scale=0.18]{./plot/Huang1995B3/availability_month.png}
        }\\

             \subfigure[]{
\includegraphics[scale=0.18]{./plot/Huang1995B2/acc_rej_time_day.png}
        }
\subfigure[]{
\includegraphics[scale=0.18]{./plot/Huang1995B2/acc_rej_time_month.png}
        }\\
        \subfigure[]{
\includegraphics[scale=0.18]{./plot/Huang1995B3/acc_rej_time_day.png}
        }
	\subfigure[]{
\includegraphics[scale=0.18]{./plot/Huang1995B3/acc_rej_time_month.png}
        }\\

    \end{center}
     \caption{Example B}
   \label{throughput}
\end{figure}

\subsubsection{Example C}
\begin{itemize}
  \item Mean Time Between Failures (MTBF): $3 \times 30 \times 24$ hours
  \item failure repair time:  $2$ hours
  \item base longevity interval (BLI):  $10 \times 24$ hours
  \item rejuvenation time: 10 minutes
  \item average cost of unscheduled downtime: \$5000 / hour
  \item average cost of scheduled downtime: \$5 / hour
\end{itemize}

\begin{table}[h]
\begin{tabular}{ | l || c | c | c | }
  \hline
   \multicolumn{4}{|c|}{For $12 \times 30 \times 24 $ hours } \\
  \hline
    & no rejuvenation & once every 2 weeks & once a week \\
   \hline
  Hours of Down Time  & 7019 & 6.83 & 6.36 \\
  \hline
  \$Cost of Down Time & 3.6K  & 2.48K & 1.11K \\
  \hline
\end{tabular}
  \caption{Huang etc's estimation for Example C}
\end{table}

\begin{figure}[h]
     \begin{center}
     \subfigure[]{
\includegraphics[scale=0.18]{./plot/Huang1995C2/accumulated_cost_day.png}
        }
\subfigure[]{
\includegraphics[scale=0.18]{./plot/Huang1995C2/accumulated_cost_month.png}
        }\\
%        \subfigure[]{
%\includegraphics[scale=0.18]{./plot/Huang1995C3/accumulated_cost_day.png}
%        }
%	\subfigure[]{
%\includegraphics[scale=0.18]{./plot/Huang1995C3/accumulated_downtime_month.png}
%        }\\

        \subfigure[]{
\includegraphics[scale=0.18]{./plot/Huang1995C2/availability_day.png}
        }
\subfigure[]{
\includegraphics[scale=0.18]{./plot/Huang1995C2/availability_month.png}
        }\\
%        \subfigure[]{
% \includegraphics[scale=0.18]{./plot/Huang1995C3/availability_day.png}
%        }
%	\subfigure[]{
% \includegraphics[scale=0.18]{./plot/Huang1995C3/availability_month.png}
%        }\\

             \subfigure[]{
\includegraphics[scale=0.18]{./plot/Huang1995C2/acc_rej_time_day.png}
        }
\subfigure[]{
\includegraphics[scale=0.18]{./plot/Huang1995C2/acc_rej_time_month.png}
        }\\
%        \subfigure[]{
%\includegraphics[scale=0.18]{./plot/Huang1995C3/acc_rej_time_day.png}
%        }
%	\subfigure[]{
%\includegraphics[scale=0.18]{./plot/Huang1995C3/acc_rej_time_month.png}
%        }\\
    \end{center}
     \caption{Example C}
\end{figure}

\subsubsection{Simulation Results}

\begin{itemize}
  \item 4 experiments for each example: two different rejuvenation schedules,
two simulated longevity (1 year and 20 years)
  \item basic time unit: 10 minutes
  \item failure distribution: uniform distributio, $U(BLI, 2\times MTBF-BLI)$
\end{itemize}

\subsubsection{Observations}

\begin{itemize}
  \item In each of the above examples, it takes more than 1.5 years to reach steady-state (see availability graph).
  the property of a reliable system 1.5 years from now is less valuable as the its property now.
  \item The cost for the first year is lower than the expected annual cost
  \item For a reliable system, the main cost is the rejuvenation cost.
\end{itemize}

\subsection{Examples from Dohi}

Use the same parameter used in the paper, assume weibull distribution as in the paper


% Created 2015-11-10 Tue 15:09
\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fixltx2e}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{float}
\usepackage{wrapfig}
\usepackage{soul}
\usepackage{textcomp}
\usepackage{marvosym}
\usepackage{wasysym}
\usepackage{latexsym}
\usepackage{amssymb}
\usepackage{hyperref}
\tolerance=1000
\usepackage{khpreamble}
\providecommand{\alert}[1]{\textbf{#1}}

\title{Computerized control - Homework 6}
\author{Kjartan Halvorsen}
\date{Due 2015-11-20}
\hypersetup{
  pdfkeywords={},
  pdfsubject={},
  pdfcreator={Emacs Org-mode version 7.9.3f}}

\begin{document}

\maketitle

\section{Controller design by state feedback}
\label{sec-1}

  Sampling the DC-motor with transfer function and state-space representation
  \[ G(s) = \frac{1}{s(s+1)} \]
   \begin{align*}
   \dot{x} &= \bbm 0 & 1\\0 & -1\ebm x + \bbm 0\\1\ebm \\
   y &= \bbm 1 & 0\ebm x
   \end{align*}
   gives the discrete-time state-space model
   \begin{align*}
   x(k+1) &= \Phi x(k) + \Gamma u(k) = \bbm \mexp{-h} & 1-\mexp{-h}\\ 0 & 1\ebm x(k) + \bbm \mexp{-h}+h-1\\ h \ebm \\
   y(k) &= Cx(k) = \bbm 1 & 0 \ebm x(k).
   \end{align*}
\subsection{Determine the pulse-transfer function}
\label{sec-1-1}

   Show that the corresponding pulse-transfer operator is given by
  \begin{equation}
  \begin{split}
   H(q) &= \frac{B(q)}{A(q)} = \frac{(q-1)(\mexp{-h}+h-1) + h(1-\mexp{-h})}{(q-1)(q-\mexp{-h})}.
  \end{split}
  \label{eq:Gd}
  \end{equation}
\subsection{Reachability and observability}
\label{sec-1-2}

   Show that the discrete-time system is both reachable and observable.
\subsection{Design the feedback control}
\label{sec-1-3}

   Choose a suitable sampling period $h$ and determine $L$ and $m_0$ in the state feedback
   \[ u(k) = -Lx(k) + m_0u_c(k) \]
   such that the closed loop system has poles in \(0.5\pm i0.5,\) and so that the closed-loop system has static gain equal to 1.
\subsection{Implement the model}
\label{sec-1-4}

   Implement the model in Simulink or in Matlab. Simulate a step-response and attach to your report. Verify that the sampling period is reasonable based on the step-response: Determine the rising time and compare it to the sampling period you chose.

\end{document}


\begin{document}
	\chapter{Conclusions}

	In this work we presented an analysis of various aspects of a newborn Bitcoin micro-payment system known as Lightning Network. We collected data from the testnet environment for a month and showed the trends in terms of size of the network, number of edges, average degree and diameter on a daily basis and on a monthly basis, evidencing a small variation over a 24h period with respect to a 31 days period. We focused on the centrality aspect of some nodes that showed a high betweenness centrality score throughout the daily and the monthly observation period, evidencing the implications on having such a high centrality degree on this particular network. Then an inherent hierarchical structure of the network has been showed through the analysis of the k-vertex components iterated over the maximal subgraph found for each step, and the process was repeated for each snapshot of the network putting in evidence the size of each vertex component. Then we investigated the features of the nodes belonging to the most connected component by computing the intersection with a list of nodes sorted by their betweenness centrality score, discovering that each highest k-connected component is mostly composed by central nodes, suggesting that there is a strong backbone that either would help in future to form a hierarchical structure similar to the one observed in ISPs infrastructures, or will cause the network.

	Based on the information gathered so far, we wanted to find out which was the best random graph model able to capture the essential structure of the network. We first observed that the network degree distribution was governed by a power-law, then we guessed the $\gamma$ value, that is the exponent of such power-law, via curve fitting over many instances of the network, computing the mean value among these fits. We finally discovered, by comparing the real information with the one gathered on the newly created model, that the random graph that was best suited to represent the Lightning Network was the Chung-Lu model, which is a model for scale-free network. Then we provided a formalization of the network behavior based on the Time Varying Graph framework by defining a directed TVG that can model the presence of an edge along the lifespan of a system; we also introduced the notion of payment channel modeled as two opposed directed edges that connects two nodes of the network and defined the conditions under which a payment is doable in both the best and worst case scenario (cooperative and uncooperative nodes).

	\section{Future works and directions}

	Bitcoin is a fairly new technology and the literature is still scarce; this determined an initial difficult approach to the topic since most of the documentation has to be found in old forums or in developers mailing-list. In addition, the Lightning Network was publicly released on November 2017 on the testnet environment and for this reason the scientific literature by the time was literally non-existent except for a proposal of a Lightning Network routing scheme known as Flare \cite{Prihodko2016}. For this reason, a survey over this technology would indeed help other researchers to get to know to the main features of this scalability solution and better orientate between the main issues.

	When we started working on this protocol there were no tools that offered network stats, thus part of this work is dedicated to trends analysis. As the network kept growing, more and more tools were developed for the user base, as well as network trackers which displayed some basic characteristic of the network, but they all lack of important network characterization metrics: thus, one direction could be further develop and ease the visualization of the metrics, like the one presented on this work, to give users more information about the network they are investing in. Furthermore, the data presented until now only applies to the testnet environment due to hardware limit, so it would be interesting to see some of the analysis presented above repeated on the main network data, in particular those about the generation of an equivalent model.

	The network route discovery protocol relies by now on the fact that each node in the graph knows the topology of the network; as the network grows it would be rather impractical for nodes to store all the information of an ever-evolving graph, thus a discussion over a Lightning Network hierarchical infrastructure has to be made, and the considerations about the k-vertex components we made so far could be used as a starting ground for future works. On the other hand, having so many central nodes belonging to the same connected component may led to the formation of payment cartels were some users would be served with much more priority by central nodes with respect to others, thus decreasing the overall fairness when it comes to transaction processing.

	Lastly, the Lightning Network so far has seen a low adoption by the users because setting up a new node is a task that requires a strong technical background, thus the network is still small in size with respect to the scalability goals that it has anticipated. With an equivalent model in mind and a formal model that describes the basic operations of the system, it would be useful to test the Lightning Network against a wider scenario, where millions of nodes are capable to process transactions and/or to fail them. Also, since the autopilot function appears to be designed around the BA-model, it would be interesting to test the network against other random graph models and see which one would fit better for the system purpose.

\end{document}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Template for a LaTex article in English.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\documentclass{article}

% AMS packages:
\usepackage{amsmath, amsthm, amsfonts}

% Theorems
%-----------------------------------------------------------------
\newtheorem{thm}{Theorem}[section]
\newtheorem{cor}[thm]{Corollary}
\newtheorem{lem}[thm]{Lemma}
\newtheorem{prop}[thm]{Proposition}
\theoremstyle{definition}
\newtheorem{defn}[thm]{Definition}
\theoremstyle{remark}
\newtheorem{rem}[thm]{Remark}

% Shortcuts.
% One can define new commands to shorten frequently used
% constructions. As an example, this defines the R and Z used
% for the real and integer numbers.
%-----------------------------------------------------------------
\def\RR{\mathbb{R}}
\def\ZZ{\mathbb{Z}}

% Similarly, one can define commands that take arguments. In this
% example we define a command for the absolute value.
% -----------------------------------------------------------------
\newcommand{\abs}[1]{\left\vert#1\right\vert}

% Operators
% New operators must defined as such to have them typeset
% correctly. As an example we define the Jacobian:
% -----------------------------------------------------------------
\DeclareMathOperator{\Jac}{Jac}

%-----------------------------------------------------------------
\title{Implementing Jarzynski Equality in Python}
\author{Lingbo Tang\\
  \small Dept. Computing Science\\
  \small University of Alberta\\
  \small Canada
}

\begin{document}
\maketitle

\abstract{Jarsynski Equality is a neat equality that reveals that the system Free Energy could be calculated even when the system is not in equilibrium state.}

\section{Introduction}

In general, the Jarzynski Equality could look like this:

\begin{equation}\label{eq:general}
  \Delta F = F(\lambda_{t}) - F(\lambda_{0}) <= < W >
\end{equation}

and the integration form looks like:

\begin{equation}\label{eq:integration}
  W_{0\rightarrow t} = \int_{0}^{t} dt^{'} \frac{\partial \lambda_t^{'}}{\partial t^{'}} [\frac{\partial \tilde{H} (r, p; \lambda)}{\partial \lambda} ]_{(r,p; \lambda)} = (r_{t^{'}}, p_{t^{'}} ; \lambda_{t^{'}})
\end{equation}

One can refer to equations like this: see equation (\ref{eq:general}). One can also
refer to sections in the same way: see section \ref{sec:nothing}. Or
to the bibliography like this: \cite{Cd94}.

\subsection{Subsection}\label{sec:nothing}

More text.

\subsubsection{Subsubsection}\label{sec:nothing2}

More text.

% Bibliography
%-----------------------------------------------------------------
\begin{thebibliography}{99}

\bibitem{Cd94} Author, \emph{Title}, Journal/Editor, (year)

\end{thebibliography}

\end{document}


%% Digital Systems
%% Digital System Models
\def\FileDate{98/11/18}
\def\FileVersion{1.0}
% ----------------------------------------------------------------
% Notes pages *********************************************************
% ----------------------------------------------------------------

\section*{Digital System Models}

\ifslidesonly
\begin{slide}\label{slide:l9sA}
\heading{Digital system models}
\input{chunk1}
\end{slide}
\fi
\input{chunk1}

\ifslidesonly
\begin{slide}\label{slide:l9sB} \heading{Difference equation}
\input{chunk2}
\end{slide}
\fi
\input{chunk2}

\ifslidesonly
\begin{slide}\label{slide:l9sC} \heading{Difference equation in terms of the delay operator}
\input{chunk3}
\end{slide}
\fi
\input{chunk3}

\ifslidesonly
\begin{slide}\label{slide:l9sD} \heading{$z$-transform of difference equation}
\input{chunk4}
\end{slide}
\fi
\input{chunk4}

\ifslidesonly
\begin{slide}\label{slide:l9s1} \heading{$z$ Transfer Function}
\input{chunk5.tex}
\end{slide}
\fi
\input{chunk5.tex}

\ifslidesonly
\begin{slide}\label{slide:l9s2} \heading{$z$ Transfer Function (2)}
\input{chunk6}
\end{slide}
\fi
\input{chunk6}

\ifslidesonly
\begin{slide}\label{slide:l9s3} \heading{$z$ Transfer Function (3)}
\input{chunk7}
\end{slide}
\fi
\input{chunk7}

\ifslidesonly
\begin{slide}\heading{Other forms of digital transfer function}
\input{chunk8}
\end{slide}
\fi
\input{chunk8}

\ifslidesonly
\begin{slide}\label{slide:l9s4} \heading{Canonical Forms}
\input{chunk9}
\end{slide}
\fi
\input{chunk9}

\ifslidesonly
\begin{slide}
\heading{End of Pre-Class Presentation}
This concludes the pre-class presentation.

In the class we will
look at system response and compute the impulse and step responses of
and example system.
\end{slide}
\fi

%% Digital Systems
%% Digital System Response

\section*{Digital System Response}

As in the case of a continuous system, the response of a digital
signal comprises the sum of a free response and a forced response.
The free response is dependent on the initial conditions of a
digital system states, and as these are taken as zero here the
free response is also zero and will not be considered further.

\ifslidesonly
\begin{slide}\label{slide:l9s5} \heading{Digital System Response}
\input{chunk10}
\end{slide}
\fi
\input{chunk10}

The inverse transform needed to determine the digital system
response is obtained using the inverse z transform methods, e.g.
polynomial division and partial fraction expansion, discussed in a
previous lecture.

\subsection*{Response to Singularity Signals}

The elemental singularity signals in a digital system response
include the digital impulse signal and the digital step input.

\subsubsection*{Impulse response}

\ifslidesonly
\begin{slide}\label{slide:l9s6} \heading{Impulse signal}
\input{chunk11}
\end{slide}
\fi
\input{chunk11}

\ifslidesonly
\begin{slide}\label{slide:l9s7} \heading{Example 1: Impulse Response}
Calculate the impulse response of the digital system with transfer function
  \[ H(z) = \frac{4z^2 - 16}{z^2 - 0.25}\]
\end{slide}
\fi
Consider the system
\[ H(z) = \frac{4z^2 - 16}{z^2 - 0.25}\]
The impulse response will be
\[ Y(z) = H(z)\times 1 = \frac{4z^2 - 16}{z^2 - 0.25}\]
We shall determine this response using the partial fraction
expansion.
\begin{eqnarray*}
Y(z) &=& \frac{4 - 16z^{-2}}{1 - 0.25 z^{-2}}\\
     &=& \frac{4(4 - 16z^{-2})}{4 - z^{-2}}\\
     &=& \frac{4(2 - 4z^{-1})(2 + 4z^{-1})}{(2 - z^{-1})(2 + z^{-1})}
\end{eqnarray*}
Assuming a partial fraction expansion of the form \[Y(z) =
\frac{A}{2 - z^{-1}} + \frac{B}{2 + z^{-1}} + C \]  we have
\begin{eqnarray*}
 \frac{4(2 - 4z^{-1})(2 + 4z^{-1})}{(2 - z^{-1})(2 + z^{-1})}
     &=& \frac{A(2 + z^{-1}) + B(2 - z^{-1}) + C(2 - z^{-1})(2 + z^{-1})}{(2 - z^{-1})(2 + z^{-1})}\\
     16 - 64z^{-2} &=& 2A + Az^{-1} + 2B - Bz^{-1} + 4C - Cz^{-2}
 \end{eqnarray*}
Gathering terms and equating coefficients
\begin{eqnarray}
16 &=& 2A +2B + 4C\\ 0 &=& A - B\\ -64 &=& -C
\end{eqnarray}
Hence
\begin{eqnarray}
C &=& 64\\ A &=& B\\ 16 &=& 4A + 256\\ A &=& B = -60
\end{eqnarray}
Thus
\begin{eqnarray*}
    Y(z) &=& 64 -\frac{60}{2-z^{-1}}-\frac{60}{2+z^{-1}}\\
    &=& 64 -\frac{30}{1-1/2 z^{-1}}-\frac{30}{1+1/2 z^{-1}}\\
     y_k& =& \left\{64\delta_k - 30\left(\frac{1}{2}\right)^k - 30
\left(-\frac{1}{2}\right)^k\right\}\\
 &=& \left\{4,\ 0,\ -15,\ 0,\ -3.75,\ 0,\ -0.9375,\ \ldots
 \right\}
\end{eqnarray*}

\subsubsection*{Step response}

\ifslidesonly
\begin{slide}\label{slide:l9s8} \heading{Step signal}
\input{chunk12}
\end{slide}
\fi
\input{chunk12}

\ifslidesonly
\begin{slide}\label{slide:l9s9} \heading{$z$-transform of step signal}
\input{chunk13}
\end{slide}
\fi
\input{chunk13}

\ifslidesonly
\begin{slide}\label{slide:l9s10} \heading{Example 2: Step Response}
Calculate the step response of the digital system with transfer function
  \[ H(z) = \frac{4z^2 - 16}{z^2 - 0.25}\]
\end{slide}
\fi

The step response of the example system is
\[ Y(z) = H(z)\times \frac{z}{z-1} = \frac{z(4z^2 - 16)}{(z-1)(z^2 - 0.25)}\]
We shall determine this response using the partial fraction
expansion.
\begin{eqnarray*}
Y(z) &=& \frac{4z^3 - 16z}{z^3 - z^2 - 0.25z + 0.25}\\
 &=& \frac{4 - 16z^{-2}}{1 - z^{-1} - 0.25z^{-2} + 0.25z^{-3}}\\
\end{eqnarray*}
Earlier we showed that the result of the partial
fraction expansion was
\[\frac{30}{1-1/2 z^{-1}} - \frac{10}{1+1/2z^{-1}} -
\frac{16}{1-z^{-1}}\] and the corresponding sequence is
\[y_k = \left\{30(1/2)^k -10(-1/2)^k -16\epsilon_k\right\}.\]

%----------------------------------------------------------------
% The end of notes
% ----------------------------------------------------------------
\endinput

% Local Variables:
% TeX-master: "lecture02"
% End: