\section{Luttinger Liquid}
Last time we coupled a U(1) gauge theory with a background gauge field
\begin{align}
    \mathcal{L} &=
    -\frac{k}{2\pi}
    a_\mu \partial_\nu a_\lambda \epsilon^{\mu\nu\lambda}
    +
    \underbrace{
    \frac{8}{2\pi} A_\mu \partial_\nu a_\lambda \epsilon^{\mu\nu\lambda}
    }_{
    q A_\mu J^\mu
    }
\end{align}
There is a global U(1) current
\begin{align}
    J^\mu &=
    \frac{1}{2\pi}
    \epsilon^{\mu\nu\lambda}
    \partial_\nu a_\lambda
\end{align}
This means $2\pi/k$ flux of $a$ carries charge
\begin{align}
    Q_{2\pi/k} = \frac{q}{k}
\end{align}
Charge $\ell$ under $a$ implies that
$2\pi\ell /k$ flux of $a$

From the classical equation of motion
\begin{align}
    \frac{\delta S}{\delta a_0} &= 0
\end{align}
implies that
\begin{align}
    \frac{k}{2\pi}b &=
    -\frac{q}{2\pi}B
\end{align}
which tells us that
\begin{align}
    B &=
    -\frac{k}{q}b
\end{align}
This is another way of seeing that flux of $a$
comes with flux of $A$.

In particular,
$2\pi/k$ flux of $a$ is going to come with
$-2\pi/q$ flux of $A$.

One thing we can deduce from all of this is that this theory actually gives us a
fractional quantized Hall conductance associated with this background $U(1)$.
Let me explain.

\section{Fractional quantized Hall conductance}
So far we deuced $2\pi/k$ flux of $a$
comes with a $-2\pi/q$ flux of $A$.
But we also know that $2\pi/k$ fox of $a$ also comes with
$q/k$ charge under $A$.

So all together,
this tells us that $-2\pi$ flux of $a$
would give us charge of $q^2/k$.
This is precisely what you expect if the system had a Hall conductivity
\begin{align}
    \sigma_H &=
    - \frac{q^2}{k} \frac{1}{2\pi}
\end{align}
If your hall conductance was $\sigma_H = \nu \frac{1}{2\pi}$.

If you inserted $-2\pi$ flux of $A$,
after you inserted that,
you should get a $q^2/k$ charge.
Physically,
if you had an annulus,
inserting the electric field in the angular direction,
which causes charge to flow radially,
and if that is the amount of charge that's accumulated,
that means this is the Hall conductivity.

That means we have effective action given by the Lagrangian density
\begin{align}
    \mathcal{L} &=
    - \frac{q^2}{k}
    \frac{1}{4\pi}
    A_\mu \partial_\nu A_\lambda \epsilon^{\mu\nu\lambda}
\end{align}
Now another way of thinking about this is let's pick our spacetime manifold to
just be $M^3 = \mathbb{R}^3$.
Imagine your system is on space times time,
and space is the Euclidean plane.
Then we don't have to worry about non-trivial topological gauge configurations.
Let's define the part integral
\begin{align}
    Z\left( M^3, A \right)
    &=
    e^{iS_{eff}[A]}
    Z\left( M^3, A=0 \right)
\end{align}
where that effective action is
align
\begin{align}
    &=
    \int \mathcal{D} a\,
    e^{
    i\int_{\mathbb{R}^3}
    \left(
    \frac{k}{4\pi} a\,d a
    +
    \frac{q}{2\pi} A\, da
    \right)
    }
\end{align}
We're going to shift $a$ to absorb the second term and only get a term that
depends on $A$.
So write
\begin{align}
    S[a, A] &=
    \frac{k}{4\pi}
    \left( a + \frac{q}{k} A \right)
    d\left(
    a + \frac{q}{k}A
    \right)
    -
    \frac{1}{4\pi}
    \frac{q^2}{k}
    A\, dA
\end{align}
Now shift
\begin{align}
    a &\to
    a^1 =
    a + \frac{q}{k}A.
\end{align}
And now
\begin{align}
    Z\left( M^3, A \right) &=
    \left(
    \int \mathcal{D} a'\,
    e^{i \frac{k}{4\pi} a'\ , a'}
    \right)
    e^{-\frac{1}{4\pi} \frac{q^2}{k}
    \int_{\mathbb{R}^3 A\, dA}
    }
\end{align}
which means we can write
\begin{align}
    S_{eff} &=
    -\frac{1}{4\pi}
    \frac{q^2}{k}
    \int_{M^3}A\, dA.
\end{align}

One thing that should bother you is that this $q^2/k$ coefficient
is a fracton.
And I told you the coefficient of the CS term should be an integer.
Why is this allowed?
What happened here?

We picked $\mathbb{R}^3$ so we don't have to worry about large gauge
transformations,
we led to the quantization restriction.

Suppose I let $M^3$ be general.
What part of this derivation did we make some wrong assumption that allowed us
to get to this point where the coefficient is not integer?
One issue is that because $a$ is a $U(1)$ gauge field,
there are certain quantisations on $a$.
Fr example,
\begin{align}
    \frac{1}{2\pi}\int_{S^2} f \in \mathbb{Z}
\end{align}
But if you shift $a$ by $\frac{q}{k}A$,
you ruin all these quantisation conditions.

Another useful perspective on what goes wrong is,
this theory if you quantize n a torus has a bunch of ground sates.
Just to regularize it,
you can imagine it has a Maxwell term,
so the actual spectrum of the quantum theory
is a bunch of degenerate ground states,
and a bunch of excited states.
When we integrate out $a$,
and forget about $a$,
we're doing something not quite allowed,
because we're integrating out something that gives rise to ground state
degeneracy,
which you shouldn't do.
It's not a high energy mode anymore.
It's a zero mode in this case.
We shouldn't integrate out $a$
because of the zero does,
so at best we should split and integrate.
But because we picked $M^3=\mathbb{R}^3$,
we don't have to worry.
But it wouldn't be valid if we did it on other manifolds.

What we can conclude from all this is that this $U(1)_{-k}$
CS theory with $q=1$
gives fractional quantized hall conductance of
\begin{align}
    \sigma_H &=
    \frac{q^2}{k}\frac{1}{2\pi}.
\end{align}
If we used SI units,
\begin{align}
    \sigma_H &=
    \frac{q^2}{k} \frac{e^2}{h}.
\end{align}
This theory describes the most prominent fractional quantum Hall states.
They are gapped phase of matter but they have this fractional quantum Hall
conductance.

Note for $k=1$,
\begin{align}
    \mathcal{L}
    &=
    -\frac{1}{4\pi} a\, da
    +
    \frac{1}{2\pi} A\, da
\end{align}
This actually describes a Chern insulator with Chern number 1,
which dis a Chern insulator or integer quantum Hall state.
This describes a fermionic theory because $k$ is odd
In fact the world line of this fermion is described by
\begin{align}
    e^{i\oint_{\gamma} a\, dl}
\end{align}
with $h=\frac{1}{2}$.
Furthermore,
it has a unique ground state.
Also  $\sigma_H=1$.
Also it is gapped.

\section{Gauge-invariance and boundary theory}
This is a boundary theory.

We studied the Chern insulator,
and we know it has a chiral.
Suppose you had an action
\begin{align}
    S &=
    \frac{m}{4\pi} dx^3 \, a\, da\,
    \partial_\mu \left( f \partial_\nu g_\lambda \right)
    \epsilon_{\mu\nu\lambda}\\
    &=
    \frac{m}{4\pi}
    \int_{y=0}
    \int dx\, dt\,
     \right)
\end{align}
To define theory,
restrict $\left. f\right_{\partial M = 0}$
Some gauge degrees of freedom of $a_\mu$
become physical degrees of freedom on body.

To study the edge theory,
consider
\begin{align}
    a_t &= 0
\end{align}
Then requiring
\begin{align}
    \frac{\partial S}{\partial a_t} &= 0
\end{align}
gives
\begin{align}
    \partial_x a_y - \partial_y a_x = 0.
\end{align}
Solve the constraint
\begin{align}
    a_i &= \partial_i \phi
\end{align}
So the action is
\begin{align}
    S &=
    \frac{m}{4\pi}
    \int d^3 x\,
    a_i \partial_t a_j \epsilon^{ij}\\
    &=
    \frac{m}{4\pi}
    \in d^3x
    \partial_ii \phi \partial_t \partial_j \phi\\
    &=
    \frac{m}{4\pi} \int_{V=0}
    dx\, dt\,
    \underbrace{
    \partial_x \phi \partial_t
    }_{pq  - H}
\end{align}
but since $H=0$,
the velocity of edge modes = 0.
Instead could have set
\begin{align}
    a_\tau &= a_t + v_a_x = 0
\end{align}
which implies
\begin{align}
    S &=
    \frac{m}{4\pi} \int_{y=0}
    dx\, dt\,
    \left( \partial_t + v\partial_x \right)\phi\cdot
    \partial_x \phi
    + v'\partial_x \phi \partial_x \phi
\end{align}
so the equation of motion is
\begin{align}
    \partial_t \phi + v\partial_v \phi &= 0
\end{align}
Modes are chiral with velocity $v$

\section{Quantizing chiral boson theory}
\begin{align}
    S &=
    \frac{m}{2\pi}
    \sum_{k>0}
    dt\,
    \left(
    ik \phi_k dot{\phi}_k
    - vk^2 \phi_k\phi_k
    \right)
\end{align}
and because $\phi$ is real,
\begin{align}
    \phi_k &= \phi_{-k}^{*}
\end{align}
Because $\phi_k$ with $k>0$ are canonical coordinates,
The canonical momenta are
\begin{align}
    \pi_k &=
    \frac{\partial S}{\partial \dot{\phi}_k}\\
    &= \frac{m}{2\pi} ik \phi_{k}
\end{align}
Then
\begin{align}
    \left[ \phi_k, \pi_{k'} \right]
    &=
    i\delta_{k, k'}
\end{align}
which gives
\begin{align}
    [\phi_k, k'\phi_{k'}]
    &=
    \frac{2\pi}{m}\delta_{kk'}
\end{align}
We can define the density as
\begin{align}
    \rho &=
    \frac{1}{2\pi} \partial_x \phi
\end{align}
sot then
\begin{align}
    \left[ \rho_k, \pho_{k'} \right]
    &=
    -\frac{1}{4\pi^2} kk' \left[ \phi_k, \phi_{k'} \right]
\end{align}
and finally we have
\begin{align}
    \left[ \rho, \rho_{k'} \right]
    &=
    \frac{1}{2\pi m} k \delta_{k+k',0}
\end{align}
and if you have an operator that satisfy this,
you have a U(1) Kac-Moody algebra.

In real space,
if you just Fourier transform this equation,
you get
\begin{align}
    \left[
    \rho(x), \rho(y)
    \right]
    &=
    \frac{i}{2\pi m}
    \delta'\left( x - y \right)
\end{align}
which means that
\begin{align}
    \left[ \rho(x), \phi(y) \right]
    &=
    -\frac{i}{m} \delta\left( x - y \right)
\end{align}
You can actually integrate it one more time
to get the real space commutation relation for $\phi$.
This is telling us that
\begin{align}
    \left[ \partial_x \phi(x), \phi(y) \right]
    &=
    -\frac{2\pi i}{m} \delta\left( x - y \right)
\end{align}
and then
\begin{align}
    \left[ \phi(x), \phi(Y) \right]
    &=
    -\frac{i\pi}{m} \sgn\left( x - y \right)
\end{align}
And the derivative of that gives you the delta function.
This is a crucial commutation relation.
This means the field $\phi$ doesn't even commute with itself at different points
in space.
Usually it commutes with itself in different points in space.
Or anti commutes if fermionic.
No matter how far apart,
it doesn't commute with itself at different points.
This is the manifestation of the fact that particles have fractional statistics.
If you move world lines across each other gives fractional statistics,
and this is kind of a manifestation of that in the edge theory.

If you write the Hamiltonian in momentum space,
\begin{align}
    H &=
    2\pi m V
    \sum_{k> 0}
    \rho_k^\dagger \rho_k
\end{align}
There's some restriction on $m$ and $V$,
because you want it to be bound from below.
In order for $H$ to be bounded from below,
you're going to need $mV>0$ for stability.

This is interesting.
Just from the sign of $m$,
you can determine the sign of the velocity.
The direction of the propagation is determined by the sign of $m$.

So we basically completely understand this theory so far.
We have these modes with different momenta $k$,
and we can occupy different states at different modes.
The point is that this Hamiltonian looks like decoupled harmonic oscillators.

For each $k>0$,
there is a $\rho_k$ that satisfies $\rho_k^\dagger = \rho_{-k}$
and the commutation relations
\begin{align}
    \left[ \rho_k, \rho_k^\dagger \right]
    &=
    -\frac{1}{2\pi m} k\\
    \left[ \rho_k, \rho_{k'}^\dagger \right] &= 0
    \qquad\text{if }k \ne k'
\end{align}

So these $\rho_k$, $\rho_k^\dagger$ are creation and annihilation operations
for oscillator modes.

I can have the ground states of some bulk that is described by a CS theory,
ad the edge corresponds to these Luttinger Liquid modes.
They are like phonons,
with density fluctuations near the boundary of the system.
These can happen at arbitrarily low energy,
because you can have arbitrarily long wavelength excitations.

This $\rho_k$ excitations describe overall neutral density fluctuations
at the edge of the system.
If you let it go,
these excitations will travel in a particular direction along the boundary.

\begin{question}
    How is this associated with fractional statistics?
\end{question}
That's the next thing I'm going to say.

\begin{question}
    Has this been measured experimentally.
\end{question}
So far what would you measure?
You perturb it and watch it move in a chiral fashion.
Not really,
you don't have that much control,
to perturb it and image it at a  resolution high enough to see they move in a
particular direction,
so no that has not been directly seen.

Remember this overall theory has overall U(1) charge conservation associate
with the $A$ that we couple to.
Not only should we have neutral excitations,
which is what this $\rho_k$ are,
but there should also be charged excitations,
that is,
operators that carry charge.
Let's find what these operators are in this theory.

So operators that create charged excitations.
For example,
let's look for an operator $\Psi^\dagger$
that creates charge $1$.

Now in fractional quantum Hall context,
this $\Psi$ is the electron operator,
because our fundamental constituent that carries charge of unit 1 is really the
charge $e$ operator,
which is the electron operator.
What do we demand of an operator that carries charge 1?
It should have the commutation relation
\begin{align}
    \left[ \rho(x), \Psi^\dagger\left( x' \right) \right]
    &=
    \delta\left( x - x' \right)\Psi^\dagger(x')
\end{align}
You can think of this as the definition of an operator with charge 1.
Because it give you back the operator with density with coefficient 1.
And it turns out
\begin{align}
    \Psi \propto e^{im\phi}
\end{align}
and you can see this from the commutation relations for $\phi$ and $\rho$.
We previously learnt that
\begin{align}
    \left[ \rho, \phi \right]
    &=
    \frac{i}{m}
    \delta\left( x - y \right)
\end{align}
which implies
\begin{align}
    \left[ \rho, e^{im\phi} \right]
    &=
    \frac{i}{m}
    \left( im \right)
    e^{im\phi}
    \delta\left( x - x' \right)
\end{align}
I may have made a sign error.
But this is the operator that creates a charge 1 operation.
\begin{align}
    \Psi \propto e^{im\phi}
\end{align}
We can try to figure out what its statistics are.
If I look at
\begin{align}
    \Psi(x)\Psi(y)
    =
    e^{im\phi(x)}
    e^{im\phi(y)}
    =
    e^{im\phi(y)}
    e^{im\phi(x)}
    e^{-m^2\left[ \phi(x), \phi(y) \right]}
\end{align}
so then
\begin{align}
    \Psi(x) \Psi(y)
    &=
    \Psi(y) \Psi(x)
    \underbrace{e^{+im\pi \sgn(x - y)}}_{
    \left( -1 \right)^m
    }
\end{align}
so what you learn is that
\begin{align}
    \Psi(x) \Psi(y)
    &=
    \Psi(y) \Psi(x)
    (-1)^m
\end{align}
so if $m$ is odd then $\Psi$ is a fermionic operator,
and if $m$ is even then $\Psi$ is bosonic.

So the microscopic degrees of freedom that carry charge 1 are fermions.

I'm going to call this $\Psi$ the electron operator from now on.
Let's calculate the electron correlation function.
First you need to calculate the correlation function of the boson.
\begin{align}
    \left\langle
    \phi\left( x, t \right)
    \phi\left( 0, 0 \right)
    \right\rangle
    &=
    -\frac{1}{m}
    \ln
    \left|
    x - vt
    \right|
    +
    \text{constant}
\end{align}
That's the result for this correlation function.
I'll put it in the homework to derive this operator.
That means the Green function is
\begin{align}
    G(x, t) &:=
    \left\langle
    T\left(
    \Psi^\dagger(x, t)
    \Psi(0, 0)
    \right)\\
    &=
    e^{m^{2}\left\langle\phi(x, t), \phi(0, 0)\right\rangle}\\
    &\propto
    \frac{1}{\left( x - vt \right)^m}
\end{align}
so this Greens function has a non-trivial integer exponent 4$m$
For the free fermion Chern insulator,
$m$ is just 1.
The fact that the exponent here is raised to $m$
signals some much more non-trivial correlations that go beyond free fermion.

Let me write the result in momentum space we will use later.
\begin{align}
    G(k, \omega) &=
    \frac{\left( vk + \omega \right)^{m-1}}{
    \omega - vk + i\sgn(\omega) 0^+
    }
\end{align}
where $0^+$ is a positive infinitesimal used to regularize things,
which you set to zero at the end of the calculation.
Then the density of states is the imaginary part of the Greens function at
$k=0$.
\begin{align}
    N(\omega) &\propto
    \Im G(k=0, \omega)
    \propto
    |\omega|^{m-1}
\end{align}

Tunneling experiments.
You could try to tunnel into these fractional quantum hall edge modes,
and have tunnelling from  a metal from the outside.
In these experiments,
you can measure the current vs voltage across the gap.
That $I$-$V$ characteristic measure the density of states.
In particular,
\begin{align}
    \frac{dI}{dV} \propto N(v) \propto |v|^{m-1}
\end{align}
The prediction is that because you have this chiral Luttinger liquid with
nontrivial $m$,
the tunneling conductance should be quantized and non-linear.

This is a fairly traditional condensed matter experiment.
It was tested in experiment,
and it looks  like there is some non-linear conductance,
but it doesn't seem to be quantized.
There's all sorts of messy physics that ruins the quantization.
We think we know why that extra messy physics comes in.
Because I'm focusing on field theory,
I didn't set up the stuff to tell you why.

But at the end of the day,
you have some confining potential that confines your electron to some disk.
It could be sharp or smooth.
In the experiments,
it's quite smooth,
and when it's smooth,
you have extra modes that contribute to the $dI/dV$ curve
and that ruins the quantization.
In principle,
if you have sharp wells,
at low enough energy and temperature,
you should see this effect.

\begin{question}
    Smooth compared to what length scale?
\end{question}
In fractional quantum Hall,
there is a characteristic length called the magnetic length
\begin{align}
    \ell_B \sim \frac{1}{\sqrt{B}}
\end{align}
So it's smooth compared to the magnetic length.


\documentclass[10pt, a4paper]{article}

\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{cite}
\usepackage{notoccite}
\usepackage[margin=1.7cm]{geometry}

\graphicspath{ {./images/} }

\title{Computational Physics Project \\ Integrating Quantum Probability Densities}
\author{Tilman Roeder}
\date{\today}

% Uniform plots
\newcommand{\plot}[3]{\begin{figure}[htp]\centering\includegraphics[width=10cm]{#1}\caption{#2}\label{#3}\end{figure}}

% Abbreviations
\newcommand{\abbreviate}[3]{\newcommand{#1}{#3 \textit{(#2)}\renewcommand{#1}{#2}}}
\abbreviate{\apis}{APIS}{Adaptive Population Importance Sampling}
\abbreviate{\iid}{i.i.d.}{independent and identically distributed}
\abbreviate{\is}{IS}{Importance Sampling}

\newcommand{\finalval}{0.497661132 \pm 2\times10^{-9}}
\newcommand{\final}{$I = \finalval$}

\begin{document}
\maketitle
\abstract{
  Using quadrature and Monte-Carlo integration schemes it is determined that
  $\int_0^2 \frac{1}{\sqrt{\pi}} e^{-x^2} dx = \finalval$. We
  find that for this (one dimensional) problem quadrature methods
  are favorable, converging much more rapidly. The sample efficiency of the
  Monte-Carlo methods matches theoretical expectations.

  Specifically, the convergence is $\sim \max(\frac fp) \times \frac{1}{\sqrt{N}}$ for Importance Sampling
  and slightly improves using adaptive sampling methods.
}

\section{Introduction}
In this report we investigate methods for numerically computing the value of

\begin{equation}
\label{eq:target}
I = \int_a^b |\Psi(x)|^2 dx = \int_a^b \frac{1}{\sqrt{\pi}} e^{-x^2} dx,
\end{equation}
where $a = 0$, $b = 2$.

$|\Psi(x)|^2$ is a normalized Gaussian probability density for which
very accurate approximations and tabulated values exist. However, for the purposes of this report we
treat the value of $I$ as unknown and investigate how to justify confidence in the
obtained results.
A direct comparison with tabulated values can be found in appendix \ref{app:cheat}.

\section{Algorithms}
\label{sec:algo}
We explore two general classes of algorithms: quadrature methods and Monte-Carlo integration.

\subsection{Quadrature Methods}
  \subsubsection{Trapezoidal Rule}
  \label{sec:trap}
  Consider approximating the integrand $f(x)$ as a linear function going through $f(a)$, $f(b)$.
  Then, if $f$ is analytic, we have $f(x) = f_0 + f_0^\prime (x-x_0) + \mathcal{O}\left((x-x_0)^2\right)$
  and thus\footnotemark
  \begin{equation}
  \int_a^b f(x) dx =
  \int_a^b f(a) + f^\prime(a) (x-a) + \mathcal{O}(x^2) dx =
  \frac{1}{2} h (f(a) + f(b)) + \mathcal{O}(h^3),
  \end{equation}
  where $h = b-a$.

  \footnotetext{
    For analytic functions: $\forall a, b \in \mathbb{R} \exists x_0 \in [a, b]$ s.t.
    $f^\prime(x_0) = \frac{f(b)-f(a)}{b-a}$.
  }

  To compute the integral over a longer range we extend the rule by dividing the integration
  region into $N$ parts such that
  \begin{equation}
  \begin{split}
  I = \int_a^b f(x) dx & = \sum_{i=0}^{N-1} \int_{a+ih}^{a+(i+1)h} f(x) dx \\
  & = \sum_{i=0}^{N-1} \frac{1}{2} h (f(a+ih) + f(a+(i+1)h)) + \mathcal{O}(h^3) \\
  & = \frac{1}{2} h (f(a) + f(b)) + \left( \sum_{i=1}^{N-1} h f(a+ih) \right) + \mathcal{O}(h^2),
  \end{split}
  \end{equation}
  where $h = \frac{b-a}{N}$.

  Notice that given a desired accuracy $\epsilon$ in general $N \sim \frac{b-a}{\sqrt{\epsilon}}$
  function evaluations are necessary to determine the integral.

  Implementing this scheme requires $\mathcal{O}(N)$ time and $\mathcal{O}(1)$ space. However, making
  use of the strong support for parallel computing in modern CPUs and the Go programming language allows
  us to reduce the time complexity by a factor of $M$, where $M$ is the number of threads
  running concurrently\footnotemark.

  \footnotetext{This is true since $M$ is limited by the number of cores in our processing unit. Given
  a theoretically infinite amount of truly concurrent threads we would want to choose a scheme that
  combines two numbers at a time, leading to $\log_2(N)$ threads and time complexity. It is clear
  that for any interesting integral this is limited by the number of processing cores available.}

  Further, we can implement a scheme to progressively increase the number of steps until
  a desired accuracy is reached. A straight-forward way to achieve this is to add mid-way points
  between the samples taken with every iteration:
  \begin{equation}
  \label{eq:trap-rec}
  I_m = \frac{I_{m-1}}{2} + \sum_i h_m f(x^{(m)}_i),
  \end{equation}
  where $m$ denotes the refinement step, $I_0 = h_0\frac{f(a) + f(b)}{2}$, $h_0 = b-a$,
  $h_m = \frac{h_{m-1}}{2}$, and $x^{(m)}_i$
  ranges over the subdivisions at the $m^{\text{th}}$ step.

  An efficient way to estimate the error after a given step is to compute $\epsilon_m \approx |I_m - I_{m-1}|$
  \cite{nr}\footnotemark.

  \footnotetext{
    Note that on should take a number of steps before using this estimate.
    William H. Press et al. \cite{nr} recommend $5$ steps.
  }

  This algorithm is implemented in \texttt{/pkg/quad/trap.go}. The implementation parallelizes the computation
  for equation \ref{eq:trap-rec}, which is implemented in \texttt{/pkg/quad/trap\_step.go}.
  The \texttt{quad} package defines a generic \texttt{Integral} interface which the algorithm implements.

  The parallel algorithm computing the steps assumes that computing $f(x)$ is non-trivial in the sense
  that is takes longer to compute than adding the result to the integral total. Thus, the
  algorithm has a worst case runtime of $\mathcal{O}(N)$ and best case runtime of $\mathcal{O}(\frac NM)$.

  \subsubsection{Simpson Rule}
  This quadrature method is closely related to the Trapezoidal Rule\footnotemark. Consider
  $f(x)$ to be approximated by a quadratic polynomial $q(x)$, such that $f(a) = q(a)$,
  $f(\frac{a+b}{2}) = q(\frac{a+b}{2})$, and $f(b) = q(b)$.

  \footnotetext{Indeed, we may understand both as special cases of the Runge-Kutta scheme for integrating
  ordinary first order differential equations\cite{nr}.}

  Now take the following Ansatz:
  \begin{equation}
  \frac{1}{b-a} \int_a^b q(x) dx = \alpha q(a) + \beta q(\frac{a+b}{2}) + \gamma q(b),
  \end{equation}
  We can determine the coefficients $\alpha$, $\beta$, and $\gamma$ such that this holds for any
  quadratic function $q(x)$. Further, this will then hold for $q(x)$ being cubic as well\cite{nr}. Thus

  \begin{equation}
  \begin{split}
  \int_a^b f(x) dx &= \int_a^b f(a) + f^\prime(a) (x-a) + f^{\prime\prime}(a) (x-a)^2 + f^{(3)}(a) (x-a)^3 + \mathcal{O}\left((x-a)^4\right) dx \\
  &= h \left( \frac{1}{6} f(a) + \frac{4}{6} f(\frac{a+b}{2}) + \frac{1}{6} f(b) \right) + \mathcal{O}(h^5),
  \end{split}
  \end{equation}
  where $h = b-a$ and we used that $\alpha = \gamma = \frac{1}{6}$ and $\beta = \frac{4}{6}$.

  As before, the total error is $\mathcal{O}(h^4)$ summing this rule over $N$ segments, where
  $h = \frac{b-a}{N}$.

  It should be noted that employing the refinement scheme outlined in section \ref{sec:trap} one
  obtains\cite{nr}:

  \begin{equation}
  I_m^{\text{Simpson}} = \frac{4}{3} I_{m+1}^{\text{Trapezoidal}} - \frac{1}{3} I_m^{\text{Trapezoidal}}.
  \end{equation}

  This is implemented in \texttt{/pkg/quad/simp.go}, reusing the function for computing steps of the
  trapezoidal approximation.

  Higher order quadrature methods exist. E.g. Gaussian Quadrature where, for an $n^{th}$
  order method, $f(x)$ is evaluated at the roots of the $n^{th}$ order Legendre Polynomial\cite{gauss}.
  Practical gains from such methods are negligible: for equation \ref{eq:target} we can easily achieve
  machine accuracy within fractions of a second (section \ref{sec:results}).

\subsection{Monte-Carlo Integration}
  \subsubsection{Importance Sampling}
  \label{sec:mon-is}

  We start by considering
  \begin{equation}
  \int_a^b f(x) dx = \int_{a}^{b} \frac{f(x)}{p(x)} p(x) dx = \mathbb{E}_{\sim p(x)}\left[ \frac{f(x)}{p(x)} \right],
  \end{equation}
  where $p(x)dx$ is a probability measure with support $[a, b]$ and $\mathbb{E}$ denotes the expectation.
  Computing the integral reduces to determining $\mathbb{E}\left[ \frac{f(x)}{p(x)} \right]$.

  In general, an unbiased estimator for $\mathbb{E}\left[ x \right]$ is
  \begin{equation}
  \bar{x}_N = \frac{1}{N} \sum_{n=1}^N x_n,
  \end{equation}
  with $x_n \sim p(x)$. Using the central limit theorem for \iid{} samples we can also provide the
  variance of our estimate. Specifically

  \begin{equation}
  \label{eq:var}
  \operatorname{var}(\bar{x}_N) = \frac{\operatorname{var}(x)}{N}.
  \end{equation}

  And given $N$ \iid{} samples the variance is estimated by
  \begin{equation}
  \bar{\sigma}_x^2 = \frac{1}{N-1} \sum_{n=1}^N (x_n - \bar{x}_N)^2,
  \end{equation}
  where we used Bessel's Correction\cite{nr} to obtain an unbiased estimator.

  From equation \ref{eq:var} the accuracy scales as $\sim \frac{1}{\sqrt{N}}$. Thus in general we will
  require many samples to find a good estimate. This means we seek to parallelize the algorithm and need
  to utilize an online estimator, as we will be memory-limited\footnotemark.

  \footnotetext{A quick calculation reveals that to attain an accuracy of $\sigma = 10^{-5}$ we would
  require about $10^{10}$ samples. Using 64 bit floating point numbers to store the results, this would
  require about $600$ GB of storage or $60\%$ of my computers total storage capacity.}

  A numerically stable online estimator for expectation and variance is given by
  \begin{equation}
  \bar{x}_n = \bar{x}_{n-1} + \frac{x_n - \bar{x}_{n-1}}{n}
  \end{equation}
  and
  \begin{equation}
  M_{2,n} = M_{2,n-1} + (x_n - \bar{x}_{n-1})(x_n - \bar{x}_n),
  \end{equation}
  where $\bar{\sigma}_x^2 = \frac{1}{N-1} M_{2,n}$\cite{welford}.

  Further, given two estimates computed from sets $X_A$, $X_B$ of \iid{} samples the combined
  estimate is
  \begin{equation}
  \begin{split}
  \delta & = \bar{x}_B - \bar{x}_A, \\
  \bar{x}_N & = \bar{x}_A + \delta \frac{N_B}{N}, \\
  M_{2,N} & = M_{2,A} + M_{2,B} + \delta^2 \frac{N_A N_B}{N},
  \end{split}
  \end{equation}
  with $N = N_A + N_B$\cite{chan}.

  Note that this is numerically unstable for $N_A \approx N_B$ and both are large\cite{chan}. But as we
  either have $N_A \approx N_B$ and both are small, or $N_A \gg N_B$ we do not encounter this case.

  This is implemented in the \texttt{casino} package. The algorithm provides a facility to interactively
  refine an estimate using a number of concurrent workers. Each worker uses a separate \texttt{PCG XSL RR 128/64}
  random number generator. This is possible as \texttt{PCG} is very light-weight and computationally cheap\cite{pcg}.
  See appendix \ref{app:pcg} for more details.

  Using the expectation estimate \texttt{/pkg/quad/mont.go} implements integration using \is{}. For
  the \is{} integration we report the accuracy as $2\frac{\bar\sigma_N}{\sqrt N}$.

  The choice of proposal function is a very important factor in
  obtaining a small variance. Using a proposal function $\frac{f(x)}{p(x)} = constant$, we get
  $\operatorname{var}\left(\frac{f(x)}{p(x)}\right) = 0$. Unless we can integrate $p$\footnote{Which is
  equivalent to integrating $f$.}, we would need to utilize rejection based sampling. This is effectively
  equivalent to doing \is. Thus, we seek an integrable $p$ as close to $f$ as possible.

  \subsubsection{Adaptive Population Importance Sampling}
  The \apis{} algorithm is a generic algorithm for performing adaptive \is{}.

  The strategy of this class of algorithm is to use the data gathered during sampling to improve
  the efficiency of the proposal distribution, i.e. to reduce what we called
  $\operatorname{var}\left(\frac fp\right)$ in section \ref{sec:mon-is}.

  Specifically, the \apis{} algorithm estimates $I$, $Z$ for
  \begin{equation}
  I = \frac{1}{Z} \int_\chi f(\vec{x}) \pi(\vec{x}) d\vec{x},
  \end{equation}
  where $Z = \int_\chi \pi(\vec{x}) d\vec{x}$ is the partition function.

  We introduce a family of proposal distributions, for which we require that each proposal distribution
  $q_i$ is parameterized by its expectation $\mu_i$\cite{apis}\footnotemark.

  \footnotetext{
    We could also adapt higher order moments, but that would be a less stable process\cite{apis}.
  }

  Initially $q_i^{(t=0)}$ are chosen at random or based on some knowledge of the problem. Then, for a number
  of iterations $T_a$, we perform \is{} to estimate $I$, $Z$, $\mu_i \sim \pi$ by drawing a one sample from each
  proposal distribution per iteration. Then we use $\mu_i$ to update $q_i^{(t)}$. This is repeated
  until the desired convergence criterion is meet. Estimates use online formulae very similar
  to what was discussed in \ref{sec:mon-is}.

  This algorithm is implemented in \texttt{/pkg/casino/apis.go} using families of Normal distributions.
  For more details on the algorithm and the precise method of computing the estimates see\cite{apis}.

\section{Ensuring Implementation Correctness}
  \label{sec:tests}
  The source code for this project encompasses more than $3500$ lines of code\footnotemark. To ensure
  this code implements the algorithms in section \ref{sec:algo} correctly, we utilize unit-tests.
  Notice that this is separate from verifying specific results. Even when all algorithms are
  implemented correctly they may still fail to converge for a number of reasons\cite{nr}.

  \footnotetext{
    As reported by \texttt{wc -l \$(find . -name "*.go")}.
  }

  Implementing these tests we generally aim for $\ge 70\%$ coverage\footnote{Although
  we take the liberty to omit tests for some trivial parts of the code base.}. By maintaining an extensive
  suite of tests we can also confidently re-factor code during the development process, getting immediate
  feedback for obvious mistakes. Tests can be found in files named \texttt{*\_test.go}.

  We test \texttt{casino} and \texttt{quad} routines using the same approach: knowing analytic
  results for some integral or expected value and variance we compute estimates
  of these values. We then verify, that the values and accuracies reported are consistent with
  analytic results.

  The markers are invited to run tests and inspect line-by-line test coverage themselves.
  For directions consult the \texttt{README.md} file.

\section{Results}
  \label{sec:results}
  To compute values for equation \ref{eq:target} we use the algorithms outlined in section \ref{sec:algo}.
  Quadrature methods are considered converged at a reported accuracy $\epsilon \le 10^{-6}$.
  For the \is{} schemes we progressively consider accuracies of $\epsilon \le 10^{-3},10^{-4},10^{-5},10^{-6}$.
  We compare two different proposal functions: a uniform distribution with support $[a,b] = [0,2]$ and
  a slanted distribution $\gamma(\alpha x + \beta)$ with $\alpha = -0.48$, $\beta = 0.98$, and
  $\gamma$ set to the appropriate normalizing factor for support $[a,b]$.
  For the \apis{} method we use $f(x) = 1$ with support $[a,b]$ and $\pi(x) = |\Psi(x)|^2$, as this
  is the more stable choice\footnotemark.

  \footnotetext{Compared to $f(x) = |\Psi(x)|^2$, $\pi(x) = \frac{1}{b-a}$.}

  The resulting values are given in figure \ref{fig:results}. All the computed values
  are in agreement and the most accurate result is \final. The accuracies are reported such that
  $x = \bar x \pm \epsilon$, since this is easier to compare than relative accuracies.

  Note that the accuracies obtained from \is{} are worse than for quadrature methods and require
  significantly more samples. This is due to the asymptotic behavior of the error $\sim \frac{1}{N^4}$
  (Simpson) and $\sim \frac{1}{\sqrt{N}}$ (\is). For higher dimensional integrals the error on quadrature
  methods is $\sim \frac{1}{N^{\frac4D}}$ (Simpson). Starting from $D=8$ asymptotic errors for \is{}
  are favorable. Our problem is $D=1$ so quadrature methods perform better as seen in figure \ref{fig:results}.

  The parallelized \is{} implementation takes around $25-35$ns per sample. To achieve $\epsilon \sim 10^{-5}$
  at $2\sigma$ confidence $\sim 10^{8}$ samples were required, taking $\sim 3\text{ seconds}$. To improve
  by one order of magnitude and get the desired $\epsilon \sim 10^{-6}$, we expect $100\times$ the
  samples and runtime. This is indeed the case, as seen in the \is{} result taking
  $\sim 10\text{minutes}$\footnotemark.

  \footnotetext{
    Since the computations are completely independent, this could be cut this down by using multiple computers
    simultaneously. But for that one would need multiple computers. Or Google Cloud Credits. Or both.
    (Or credits with AWS, but I don't have those either.)
  }

  \apis{} is more sample efficient than \is{} but is not implemented as a parallel algorithm and
  so has significantly longer run-times.

  \begin{figure}[ht]
  \centering
  \begin{tabular}{ l | l l l l }
    \textbf{Method} &
    \textbf{Value} &
    \textbf{Accuracy (reported)} &
    \textbf{Sample Count} &
    \textbf{Runtime} \\
    \hline

    Trapezoidal & $0.4976609222761679$  & $6.306742604267335\times10^{-7}$      & $257$         & $560\mu$s     \\
    Simpson     & $0.49766113237260257$ & $2.05317862711496\times10^{-9}$       & $129$         & $331\mu$s     \\

    Uniform \is & $0.49749275093080847$ & $0.0009987888600436882$               & $606208$      & $17.8$ms      \\
    Uniform \is & $0.4976236307864889$  & $9.9988154790576\times10^{-5}$        & $60522496$    & $1.62$s       \\
    Uniform \is & $0.497647454893018$   & $7.778787976918824\times10^{-5}$      & $99991552$    & $2.49$s       \\

    Slanted \is & $0.498257793433617$   & $0.0009384751322811317$               & $81920$       & $2.59$ms      \\
    Slanted \is & $0.4977119148814941$  & $9.99393644049716\times10^{-5}$       & $7274496$     & $212.29$ms    \\
    Slanted \is & $0.49765521455387013$ & $2.695543800022229\times10^{-5}$      & $99991552$    & $2.89$s       \\

    Slanted \is & $0.4976607485895988$  & $1.9059153608037185\times10^{-6}$     & $19999997952$ & $11$min $45$s \\

    \apis{}     & $0.4975202501301652$  & $0.00021774502243$ (see\footnotemark) & $606208$      & $18.14$s      \\

  \end{tabular}
  \caption{
    Results for different algorithms. All results agree to within the quoted accuracy.
    From these, we obtain a final value of \final{} (Simpson).
  }
  \label{fig:results}
  \end{figure}

  \footnotetext{
    This value is based on the estimate for $Z \approx \bar Z = 1.0002177450224337$. Since
    $\pi = |\Psi|^2$ is normalized $\epsilon = |Z-\bar Z|$\cite{apis}.
  }

\section{Plausibility of Results}
\label{sec:verify}

  % Consider further:
  % - analyze numeric properties of quadrature method used and estimate numeric error incurred
  % - analyze numeric stability of monte-carlo method used

  All values reported (figure \ref{fig:results}) agree to within the quoted accuracy. Further, unit
  testing convinced us of the correctness of our implementation (section \ref{sec:tests}). We also note
  that the integrand is a symmetric, normalized distribution which decays exponentially in $x$.
  $I \approx \frac12$ is thus plausible.

  Physically this also makes sense. $\Psi$ is the ground state of a harmonic potential, which we expect
  to be localized around the origin.

  \subsection{Quadrature Methods}
  As seen in section \ref{sec:algo}, the Trapezoidal and Simpson's method have errors
  $\mathcal{O}\left( \frac{1}{N^2} \right)$ and $\mathcal{O}\left( \frac{1}{N^4} \right)$ respectively.

  This was for analytic functions and as $|\Psi|^2$ is analytic this analysis is valid
  for our results. Further one can show $|\Psi|^2$ is Lipschitz\footnote{For analytic functions this means
  a bounded derivative.}. Thus we expect excellent convergence
  from quadrature schemes which can be thought of as finite difference methods\footnote{They are special
  cases of the Runge-Kutta scheme\cite{nr}.}.

  This can also be seen in our reported errors, which follow the expected asymptotic behavior, shown in
  figures \ref{fig:trap} and \ref{fig:simp}.

  % Plots Quadrature
  \plot{proj-trap-accuracy}{
    Values obtained for the Trapezoidal method plotted against the number function evaluations required. The red
    error-bar graph shows the value computed for each step and the associated error, the green line
    shows the final converged value. The theoretical error bounds are shown in yellow. Reported errors
    follow the theoretical behavior very closely and all estimates lie within the theoretically expected range.
  }{fig:trap}

  \plot{proj-simp-accuracy}{
    Values obtained for the Simpson method plotted against the number function evaluations required. The red
    error-bar graph shows the value computed for each step and the associated error, the green line
    shows the final converged value. The theoretical error bounds are shown in yellow. Reported errors
    follow the theoretical behavior very closely and all estimates lie within the theoretically expected range.
  }{fig:simp}

  \subsection{Monte-Carlo Methods}
  As $|\Psi|^2$ is well-behaved, the expected value is well-defined and $= I$. As per our
  analysis in section \ref{sec:algo}, we expect the error on our estimate to behave like
  $\mathcal{O}\left( \frac{\operatorname{var}(\frac fp)}{\sqrt N} \right)$.

  It can further be noted that choosing $p$ to be more similar to $f$, in the sense of choosing $p$
  such that $\frac fp$ is bounded by the smallest possible interval, we decrease the variance and thus
  improve the error on our estimate by a constant factor.

  This theoretically expected behavior can clearly be seen in figures \ref{fig:mont-flat}, \ref{fig:mont-slant}.

  To investigate the numerical stability of the implementation
  we consider a function which returns $0,1,0,1,0,1,\dots$ sequentially and thus will have an
  exact average after even numbers of samples. The error incurred by our implementation is
  $\sim 10^{-14} \ll 10^{-6}$ \footnotemark. We
  also do not observe significant growth of this error in the number of samples processed as
  seen in figure \ref{fig:float-error}.

  \footnotetext{
    Indeed, machine accuracy is $\sim 10^{-16}$, so this value is very close to the theoretical lower bound.
  }

  % Plots Monte-Carlo
  \plot{proj-mont-flat-accuracy}{
    Values obtained for the \is{} method (uniform proposal distribution) plotted against the number
    function evaluations required. The red
    error-bar graph shows the value computed for each step and the associated error, the green line
    shows the final converged value. The theoretical error bounds are shown in yellow. Reported errors
    follow the theoretical behavior very closely and all estimates lie within the theoretically expected range.
    All reported errors correspond to a $2\sigma$ confidence interval.
  }{fig:mont-flat}

  \plot{proj-mont-slanted-accuracy}{
    Values obtained for the \is{} method (slanted proposal distribution) plotted against the number
    function evaluations required. The red
    error-bar graph shows the value computed for each step and the associated error, the green line
    shows the final converged value. The theoretical error bounds are shown in yellow. Reported errors
    follow the theoretical behavior very closely and all estimates lie within the theoretically expected range.
    All reported errors correspond to a $2\sigma$ confidence interval. This graph nicely demonstrates the
    effect of choosing a proposal more similar to the integrand: compared with figure \ref{fig:mont-flat},
    the error bounds favorably scale by a constant factor.
  }{fig:mont-slant}

  \plot{proj-mont-stab}{
    Deviation of results from exact arithmetic for our Monte-Carlo expectation estimator. The error
    does not grow significantly in the
    number of samples taken and is $\sim 10^{-14} \ll 10^{-6}$. The theoretical lower bound on this
    error is $\sim 10^{-16}$ for 64-bit floating point arithmetic and is indicated in yellow.
  }{fig:float-error}

\pagebreak
\bibliography{assignment.bib}{}
\bibliographystyle{unsrt}

\appendix{}

\section{Comparison with Tabulated Value}
\label{app:cheat}
From tables we obtain
\begin{equation}
I = \frac{\operatorname{erf}(2)}{2} = 0.49766113250947636708 \dots,
\end{equation}
where $\operatorname{erf}(x) = \frac{1}{\sqrt\pi}\int_{-x}^x e^{-t^2} dt$ is the Error function. Comparing
this to the our result \final one sees that the tabulated value is matched to within our
quoted error as expected based on the analysis in section \ref{sec:verify}.

\section{Permuted Linear Congruential Random Number Generators}
\label{app:pcg}

The PCG family of random number generators improves upon congruential generators by applying
permutations to the resulting bits\cite{pcg}. The general idea is to improve on linear congruential
generators of the form
\begin{equation}
S_{n+1} = \alpha S_n + \beta,
\end{equation}
where $S_n$, $\alpha$, and $\beta$ are part of a modular group under addition and multiplication.

We may notice that the quality of the random bits produced increases as we consider higher bits
in the result\cite{pcg}. The idea of the PCG family of generators is to use this fact by
applying families of permutations to a subset of the produced bits, where the permutation family
members are selected `randomly' using the highest order bits.

The \texttt{PCG XSL RR 128/64} generator we used applies a rotation on an XOR shifted part of the
internal state, produces 64 bit random numbers, and uses 128 bits of internal state (giving a
period of $2^{128} \approx 3.40282\times10^{38}$)\cite{pcg}.

In general, PCG family algorithms have excellent statistical and computational properties,
which make them superior to other well known generators such as the Mersenne Twister\cite{pcg}.

\end{document}


\section{Implementation}
\label{sec:implementation}

The model described in \cref{sec:model} can be implemented as a \ac{WFST}.
In particular, the model can be decomposed in two transducers, one for each term.
The final model is given by the composition of the two transducer.

\subsection{First term: $\prod_{i=1}^n P(w_i | t_i)$}
The first transducer $\lambda_{word2concept}$ assigns the tag with the highest probability to each word.
The transducer has a single state $0$ with many self transitions.
For each unique pair $(w_i, t_j)$, a self transition $w_i \rightarrow t_j$ is added to the transducer.
The cost associated to the transitions is computed as the negative logarithm of the probability of the pair $P(w_i, t_j)$:
\begin{equation*}
    cost(w_i \rightarrow t_j) = -ln(P(w_i, t_j)).
\end{equation*}

In addition, we must take care of \ac{OOV} words, i.e. words that are never observed in the training data and thus not present in lexicon.
Since we can not make any assumption about the concepts probability for unknown words, we choose a uniform distribution.
Thus, we add one extra self transition $\langle unk \rangle \rightarrow t_j$ for each concept $t_j$ with cost:
\begin{equation*}
    cost(\langle unk \rangle \rightarrow t_j) = -ln \Big( \frac{1}{n_{concepts}} \Big).
\end{equation*}
$\langle unk \rangle$ is a special token used for the \ac{OOV} words.

The model is implemented with a Bash script that computes all counts, costs and transition for the transducer.
The lexicons are computed using \texttt{OpenGrm NGram}.
The transducer is compiled to the \texttt{FST} format using \texttt{OpenFst}.

\subsection{Second term: $\prod_{i=1}^n P(t_i | t_{i-1})$}
The second transducer $\lambda_{concept\_lm}$ is a language model for the concepts.
It takes as input a sequence of concepts and computes its probability given the predecessors and the observed training data.

A general problem with language models is data sparseness:
since the language has an underlying structure and the training data is limited, not all tuples $(t_i, ..., t_m)$ are observed.
As a consequence, most probabilities have value $0$, which makes the probability of most words sequences $0$ as well.
To solve this problem, we introduce smoothing:
the unseen tuples are assigned a small probability even though the real observed probability is $0$.
The probability of frequent tuples is slightly reduced to make the joint probability sum up to $1$.

Many different smoothing methods have been proposed in the literature.
A simple technique is the Laplace smoothing:
we add imaginary training data with all possible n-gram combinations, each of them with frequency $1$.
For instance, for the bigram case, we can compute the smoothed probability as:
\begin{equation*}
    P(t_i | t_{i-1}) = \frac{C(t_{i-1}, t_i) + 1}{C(t_{i-1}) + V},
\end{equation*}
where $V$ is the size of the vocabulary of pairs $(t_i | t_{i-1})$.
\cref{sec:performances} compares the performances of different smoothing methods on our model.

Opposite to the first term, we do not need to take care of \ac{OOV} words, since the first transducer can produce only concepts in the concepts' lexicon.

\subsection{Concept tagging}
To compute the most probable sequence of tags, each sentence is first compiled to a \ac{FSA} $\lambda_{sentence}$.
For each word $w_i$, we define a state $i$ and a transition from state $i-1$ to state $i$ that translate word $w_i$ in itself.
The initial state is $0$, the final state is $n$, where $n$ is equal to the length of the sentence.
\cref{fig:fsa_sentence} shows an example.

\begin{figure}[h]
	\centering
	\includegraphics[width=0.95\columnwidth]{figures/fsa}
	\caption{\ac{FSA} for the sentence ``star of thor''.}
	\label{fig:fsa_sentence}
\end{figure}

The most probable sequence of tags can be computed as the shortest path in the \ac{FST} given by the composition:
\begin{equation*}
    \lambda_{sentence} \circ \lambda_{word2concept} \circ \lambda_{concept\_lm}.
\end{equation*}
The shortest path is computed by the \texttt{OpenFst} library using the Viterbi algorithm.
This model is implemented in the file \texttt{model/v1.sh}.


% declare document class and geometry
\documentclass[12pt]{article} % use larger type; default would be 10pt
\usepackage[margin=1in]{geometry} % handle page geometry

% import packages and commands
\input{../header2.tex}

\title{Phys 220A -- Classical Mechanics -- HW04}
\author{UCLA, Fall 2014}
\date{\formatdate{30}{10}{2014}} % Activate to display a given date or no date (if empty),
         % otherwise the current date is printed

\begin{document}
\maketitle

\section*{Problem 1 (20 pts)}
\textit{
Consider the following Lagrangian which describes the motion of a charged particle in a uniform constant electric field $\v{E}$,
\begin{eqn}
L_1 = \frac{1}{2} m \dot{\v{x}}^2 + q \v{E} \cdot \v{x}.
\end{eqn}
}

\begin{enumproblem}

% part A
\item \textit{
Even though the Lagrangian does not seem to be invariant under spatial translation show that it transforms under translations into an equivalent Lagrangian (i.e. differs by a total time derivative).
}

% part B
\item \textit{
Using Noether's theorem calculate the conserved quantity and solve the equations of motion.
}

% part C
\item \textit{
Show that the following Lagrangian is equivalent to $L_1$ and find the total time derivative which relates them
\begin{eqn}
L_2 = \frac{1}{2} m \dot{\v x}^2 - q (\v{E} \cdot \dot{\v x}) t.
\end{eqn}
}

% part D
\item \textit{
Calculate the conserved quantity from $L_2$ and compare.
}

\end{enumproblem}

\section*{Problem 2 (20 pts)}
\textit{
Consider the three dimensional symmetric harmonic oscillator with Lagrangian
\begin{eqn}
L = \frac{1}{2} \sum_{i=1}^3 (\dot{x}_i^2 - x_i^2).
\end{eqn}
(For simplicity we choose units where $m = \omega = 1$.)
}

\begin{enumproblem}

% part A
\item \textit{
Show that is invariant (up to equivalences) under the following 9 transformations
\begin{eqn}
x'_i = x_i + \epsilon \delta x_i(k, l)
\end{eqn}
with
\begin{eqn}
\delta x_i(k,l) = \frac{1}{2} (\delta_{ik} \dot{x}_l + \delta_{il} \dot{x}_k), \qquad i,k = 1,2,3.
\end{eqn}
}

% part B
\item \textit{
From the transformation in (a) calculate the conserved charges $Q_{kl}$ using Noether's theorem. How many of those are independent?
}

% part C
\item \textit{
Find an expression for the energy in terms of $Q$'s
}

% part D
\item \textit{
Find on expression for the angular momentum $(L_i)^2$ in terms of the $Q$'s.
}

\end{enumproblem}

\section*{Problem 3 (20 pts)}
\textit{
Three masses with mass $m$ are connected along a line by four identical massless springs with spring constant $k$. The left and right springs are connected to walls. Consider only the linear motion. The coordinates of the $i$-th mass is denoted $y_i (t)$.
}

\begin{enumproblem}

% part A
\item \textit{
Express the Lagrangian in terms of the displacement from equilibrium
\begin{eqn}
x_i = y_i(t) - y_i^{(0)}.
\end{eqn}
}

% part B
\item \textit{
Find the matrices $m_{ij}$ and $v_{ij}$ for the small oscillations (here this approximation is actually exact).
}

% part C
\item \textit{
Find the normal frequencies, normal modes, and identify the type of motion associated with them.
}

% part D
\item \textit{
\textbf{More difficult:} Solve the analogous problem for $N$ masses and show that the eigenfrequencies are given by
\begin{eqn}
\omega_j = 2 \sqrt{k/m} \abs{ \sin \left( \frac{j\pi}{2(N+1)} \right) }, \qquad j = 1,2, \dots, N.
\end{eqn}
\textbf{Hint:} Solve the characteristic equation in the form $D_N = \det (m\omega^2 - v) = 0$ by row expanding the determinant and derive a recursion relation for the determinants $D_N$c for lower $N$. Solve the recursion with an ansatz $D = (\beta)^N$.
}

\end{enumproblem}

\section*{Problem 4 (20 pts)}
\textit{
Consider two masses with mass $m$ which each are connected to massless springs with spring constant $k$ and equilibrium length $b$. The mass points are connected by a massless rigid rod of length $l$ (see Figure 1). Assume the motion is just in the plane and neglect gravity.
}

\begin{enumproblem}

% part A
\item \textit{
Find appropriate generalized coordinates and express the Lagrangian in terms of them.
}

% part B
\item \textit{
Calculate the characteristic frequencies of the small oscillations.
}

% part C
\item \textit{
Find the normal modes and sketch the motion they correspond to.
}

% part D
\item \textit{
What happens to the characteristic frequencies if I increase the value of the spring constants?
}

\end{enumproblem}

\end{document}


\chapter{Master equation}
\label{sec:kmc}
\index{kinetic Monte Carlo}
Having determined the list of conjugated segments (hopping sites) and charge transfer rates between them, the next task is to solve the master equation which describes the time evolution of the system
%
\begin{equation}
\label{equ:master}
\frac{\partial P_\alpha}{\partial t} = \sum_{\beta} P_\beta \Omega_{\beta \alpha} -
\sum_{\beta} P_\alpha \Omega_{\alpha \beta},
\end{equation}
%
where $P_\alpha$ is the probability of the system to be in a state $\alpha$ at time $t$ and $\Omega_{\alpha \beta}$ is the transition rate from state $\alpha$ to state $\beta$. A state $\alpha$ is specified by a set of site occupations, $\left\{ \alpha_i \right\}$, where $\alpha_i = 1 (0)$ for an occupied (unoccupied) site $i$, and the matrix $\hat{\Omega}$ can be constructed from rates $\omega_{ij}$.

\section{Kinetic Monte Carlo}
The solution of \equ{master} is be obtained by using kinetic Monte Carlo (KMC) methods. KMC explicitly simulates the dynamics of charge carriers by constructing a Markov chain in state space and can find both stationary and transient solutions of the master equation. The main advantage of KMC is that only states with a direct link to the current state need to be considered at each step. Since these can be constructed solely from current site occupations, extensions to multiple charge carriers (without the mean-field approximation), site-occupation dependent rates (needed for the explicit treatment of Coulomb interactions), and different types of interacting particles and processes, are straightforward. To optimize memory usage and efficiency, a combination of the variable step size method~\cite{bortz_new_1975} and the first reaction method is implemented.

To obtain the dynamics of charges using KMC, the program \kmcrun executes a specific \calculator after reading its options (charge carrier type, runtime, numer of carriers etc.) from \xmloptions.

\votcacommand{KMC for a single carrier in periodic boundary conditions}{\cmdkmcsin}

\votcacommand{KMC for multiple carriers of the same type in periodic boundary conditions}{\cmdkmc}


%
%

\chapter{Stochastic Petri nets}  \label{SEC:SPN}

\TBD{
  Rewrite this chapter, make it ``Petri nets'',
  cover both logical and stochastic aspects.
}

The \index{stochastic Petri net}stochastic Petri net
formalism is based on a stochastic extension of
(untimed) Petri nets \cite{Murata1989,Peterson1981,Petri1962,Reisig1985}.
The type used to declare a stochastic Petri net in {\smart} is
\index{pn}\Code{pn}.
Depending on the timing associated with the transitions of the
net and on the way they can interrupt each other,
the underlying model can be a discrete-time Markov chain, a continuous-time
Markov chain, a \index{semi-regenerative process}semi-regenerative process,
or a generalized semi-Markov process
\cite{Ajmone1984,Chiola1993b,1995StewartBook-DiscreteSPN,1993IMA-SRNs,
1994IEEETSE-SPNcharacterization,Molloy1981,Natkin1980}.
{\smart} automatically determines the type of underlying stochastic process,
and uses this information to decide the solution engines that can be
applied to it.
The conditions for this determination are as follows (see
Appendix \ref{SEC:PhaseType} for a discussion of DDP and DCP distributions):
\begin{itemize}
\item
If all the transitions in the net have a DDP distribution
(including, possibly, the degenerate case of a constant equal to zero),
the underlying process is determined to be a DTMC (discrete-time Markov chain).
\item
If all the transitions in the net have a DCP distribution,
(including, possibly, the degenerate case of a constant equal to zero),
the underlying
process is determined to be a CTMC (continuous-time Markov chain).
\item
If all the transitions in the net have a DDP or DCP distribution
(including, possibly, the degenerate case of a constant equal to zero),
and certain conditions on the concurrent enabling of the transitions
with DDP distributions are satisfied (essentially, guaranteeing that their
possible firing times are always synchronized modulo the time step
\cite{Jones-NASA-00,2001PNPM-PDPN}), the underlying process is determined
to be a SRP (\index{semi-regenerative process}semi-regenerative process), also
called MRGP (\index{Markov-regenerative process}Markov-regenerative process).
\item
In all the other cases, the process is asssumed to be a GSMP
(generalized semi-Markov process).
\end{itemize}

Note that some aspects of the timing and stochastic behavior defined for the
model do affect its logical analysis described in Chapters \ref{SEC:SSGen}
and \ref{SEC:ModelChecking}.
In particular, \emph{immediate} events (transitions of the Petri net
with a constant zero firing time distribution)
are treated in a fundamentally different way from ordinary
\emph{timed} events: the states in which they are enabled
have sojourn times equal zero, and are not considered part of
the reachable state space (\emph{tangible reachability set} in
GSPN parlance \cite{Ajmone1995book}).

\section{Defining a stochastic Petri net model in {\smart}} \label{SEC:SPNdef}

An example of a \index{pn}{stochastic Petri net} definition is:
%
\lstinputlisting[firstline=3]{examples/pn1a.sm}
%
\begin{figure}
  \centering
  \includegraphics[scale=0.75]{figures/cs1.pdf}
  ~~~~~
  \includegraphics[scale=1]{figures/cs1CTMC.pdf}
  %
  \caption{A simple Petri net (left) and its underlying CTMC (right).}
  \label{FIG:cs1}
\end{figure}
%
The code defines the stochastic Petri net \Code{cs1} illustrated
in Fig.~\ref{FIG:cs1} on the left.
Since all firing times are exponentially distributed, the underlying
process is a CTMC.
This CTMC is shown in Fig.~\ref{FIG:cs1} on the right, where the state
structure is given by the pair
``(number of tokens in \Code{p}, number of tokens in \Code{q})''.
This \Code{pn} model also defines a measure \Code{m1}, the
expected number of tokens in place \Code{p} in steady state.
This measure can be requested in output as usual:
%
\lstinputlisting[firstline=3]{examples/pn1b.sm}
%
will cause its value to be computed and printed to the current output stream.

We observe that the declarations of \Code{p} and \Code{q}, and of \Code{t},
\Code{u}, and \Code{v} are also definitions:
just like type \Code{state} for discrete or continuous-time Markov chains,
types \Code{place} and \Code{trans} cannot be assigned a value,
they are essentially \Code{void} types.

Had the distributions for the firing times been specified as
\begin{lstlisting}
  firing(t:geom(0.2), u:geom(0.3), v:geom(0.1*tk(p)));
\end{lstlisting}
the resulting underlying process would have been a DTMC and it still would
be solvable numerically.
\begin{release}
However, currently, \smart{} can numerically analyze only
\Code{expo} and 0 firing times.
\end{release}

In the presence of mixtures of \Code{ph int} and \Code{ph real} firing time
distributions, the result might be a semi-regenerative process.
This is the case if we had specified
\begin{lstlisting}
  firing(t:geom(0.2), u:expo(0.3), v:erlang(5,0.02));
\end{lstlisting}
In this case, it is still possible to compute a numerical solution.
% In this case, {\smart} is still able to compute a numerical solution.
\begin{release}
Again, the current version of \smart{} cannot handle this case.
\end{release}

In more complex cases, i.e., in the presence of complex mixtures of
\Code{ph int} and \Code{ph real} firing time distributions,
or of any \Code{rand int} or \Code{rand real} firing time distribution,
the resulting process would have to be studied using discrete-event simulation.
If a numerical solution is requested in this case, {\smart} will still
attempt to generate the correct state space;
as soon as it discovers a state where the required semi-regenerative behavior
is not present, it halts and gives and gives an error.
Thus, requiring a numerical solution when the process is not of the appropriate
type does not lead to incorrect results, but it can cause {\smart} to run for
a long time before issuing the correct error message.
\begin{release}
Currently, {\smart} does not support discrete-event simulation
of Petri nets.
\end{release}

\section{Marking-dependent expressions}
\label{SEC:spn-predefined-state-functions}

A \emph{current marking} is assumed when specifying the dynamic behavior
of the stochastic Petri net.
Thus, for example, \Code{tk(p)} is an integer quantity representing
the number of tokens in place \Code{p} as the net evolves over time:
we say its type is \Code{proc int}, where ``\Code{proc}'' stands
for ``process'', since the value of \Code{tk(p)} depends on the
state of a process evolving over time.

A statement such as
\begin{lstlisting}
  guard(t:enabled(u)|tk(p)>5);
\end{lstlisting}
can be used to specify a guard
for \Code{t} that disables \Code{t} when \Code{u} is not enabled and
when \Code{p} contains no more than five tokens.
Indeed, it is even possible in {\smart} to define nets having marking-dependent
arc cardinalities \cite{1994ICATPN-Vararcs}
(also known as \emph{self-modifying nets}):
\begin{lstlisting}
  arcs(p:t:tk(p));
\end{lstlisting}
specifies an arc from \Code{p} to \Code{t} with
cardinality equal to the (current) number of tokens in \Code{p};
thus, when \Code{t} fires, place \Code{p} becomes empty
(unless there is also an output arc from \Code{t} to \Code{p}).
When such expressions are evaluated in light of a \emph{current marking},
they are deterministic quantities, given that this marking is known.

The initial marking specification cannot be marking-dependent, thus
a statement such as
\begin{lstlisting}
  init(p:1, q:4*tk(p));
\end{lstlisting}
is illegal.
Also, there cannot be circular dependencies in the behavior of the
stochastic Petri net.
Thus, for example, we can add the statement
\begin{lstlisting}
  guard(t:!enabled(u));
\end{lstlisting}
to disable \Code{t} when \Code{u} is enabled, or add the statement
\begin{lstlisting}
  guard(u:!enabled(t));
\end{lstlisting}
to disable \Code{u} when \Code{t} is enabled.
However, adding both statements causes the behavior to be undefined, so
{\smart} issues an error in this case.

The functions \Code{avg\_ss}, \Code{avg\_at}, \Code{avg\_acc}, and their
``\Code{prob}'' siblings can be used to specify measures for the model.
They require a \Code{real} expression for their first argument
(or \Code{int}, of course, since it can be automatically promoted).
Arbitrarily complex expressions can be used for this argument:
in the example of Section \ref{SEC:SPNdef},
instead of just \Code{avg\_ss(tk(p))}, the expected number of tokens
in place \Code{p} in steady state, we could have asked for the
steady-state average of any marking-dependent expression.

The following lists the functions available to build marking-dependent
expressions for \Code{pn} models.
They all assume the notion of a current marking.
For a complete,
release-specific list of functions available for \Code{pn} models,
see the ``pn'' help topic (e.g., \Unix{smart -h pn}).

\begin{itemize}
\item
\begin{developer}
\Code{proc~bool~empty(place~p);}\\
Returns \Code{true} if place \Code{p} is empty, \Code{false} otherwise.
\end{developer}

\item
\Code{proc~bool~enabled(trans~t);}\\
Returns \Code{true} if transition \Code{t} is enabled,
\Code{false} otherwise.

\item
\Code{proc~int~tk(place p);}\\
Returns the number of tokens in place \Code{p}.

\begin{developer}
\item
\Code{proc~bool~fires(trans~t);}\\
Returns \Code{true} if transition \Code{t} fires, \Code{false} otherwise.
This is an impulse-type process, and it is required to specify timing
aspects related to structural state changes in the net, such as the
\Code{restart} behavior.
\end{developer}

\item
\Code{proc~real~rate(trans~t);}\\
Returns the rate of transition \Code{t}.
\begin{release}
Currently, it can only be used if \Code{t} has an \Code{expo}
firing distribution.
\end{release}

\end{itemize}

\begin{developer}

\section{Formalism-specific functions for stochastic Petri net models}
\label{SEC:spn-predefined-builder-functions}

\TBD{should we delete this list?  The \smart{} internal documentation
is always more up to date than what we list here}

\TBD{List needs updating, most parameters are ``proc'' now}

The block defining a stochastic Petri net can contain any number
of calls to the following predefined functions:

\begin{itemize}

\item
\Code{void~init(place:int~p1:n1,~place:int~p2:n2,~...);}\\
Sets the initial number of tokens in place \Code{p}$i$ to the value of the
(non-marking-dependent) \Code{int} expression \Code{n}$i$.
Any place for which an initial number of tokens is not explicitly set
by this function is assumed to be initially empty.
If the expression \Code{n}$i$ for a place \Code{p}$i$ evaluates to zero,
a warning is issued (since this is already the default value).

\item
\Code{void~arcs($node$:$node$:int~a1:b1:n1,~$node$:$node$:int~a2:b2:n2,~...);}\\
Sets the cardinality of the input (if $node$:$node$ is \Code{place:trans})
or output (if  $node$:$node$ is \Code{trans:place}) arc
from \Code{a}$i$ to \Code{b}$i$ to the value of the
(possibly marking-dependent) \Code{int} expression \Code{n}$i$.
If an arc is not listed, it is assumed to have cardinality zero
(i.e., there is no arc).
If a pair $node$:$node$ appears but no cardinality is specified for it, the
corresponding arc is assumed to have cardinality one.

\item
\Code{void~inhibit(place:trans:int~a1:b1:n1,~place:trans:int~a2:b2:n2,~...);}\\
Exactly analogous to \Code{arcs}, except that it specifies the cardinality of
inhibitor arcs (which can only connect places to transitions) thus,
if an arc is not listed, it is assumed to have cardinality infinity
(i.e., there is no inhibitor arc).

\DEVELOPER{
\item
\Code{void~prio(trans:trans~t1:s1,~trans:trans~t2:s2,~...);} \TBD{It's ``priority'' now}\\
Sets an acyclic preselection priority relation \cite{1995StewartBook-DiscreteSPN}
for transition \Code{t}$i$ over transition \Code{s}$i$.

\item
\Code{void~post(trans:trans~t1:s1,~trans:trans~t2:s2,~...);} \TBD{not implemented}\\
Sets an acyclic postselection priority relation \cite{1995StewartBook-DiscreteSPN}
for transition \Code{t}$i$ over transition \Code{s}$i$.
}

\item
\Code{void~guard(trans:bool~t1:b1,~trans:bool~t2:b2,~...);}\\
Sets the guard for transition \Code{t}$i$ to the value of the
(normally marking-dependent) \Code{bool} expression \Code{b}$i$.
If a guard is not specified for a transition, it is assumed to be
the constant \Code{true}.

\DEVELOPER{
\item
\Code{void~immediate(trans~t1,~trans~t2,~...);}\\
Sets the firing time distribution for the argument transitions to the constant
zero, that is, defines them as immediate transitions.
Any transition not defined to be immediate is taken to be timed,
that is, its firing time is positive with probability one.
\TBD{THIS FUNCTION IS GONE NOW}
}

\item
\Code{void~firing(trans:real~t1:f1,~trans:real~t2:f2,~...);}\\
Sets the firing time distribution for timed transition \Code{t}$i$ to the value
of the (possibly marking-dependent) expression \Code{f}$i$.
It is an error to set the firing distribution of an immediate transition.
For solution methods using any \Code{StateStorage} other than \Code{SPLAY},
each timed transition must have an exponential firing distribution,
i,e., it must be of the form \Code{expo($e$)},
where $e$ is a (possibly marking-dependent) \Code{real} expression,
which must evaluate to a positive finite value in any marking
where the transition is enabled.
When \Code{SPLAY} is used, the firing time distribution can instead be
\Code{ph int} or \Code{ph real} as well.
\DEVELOPER{For simulation, any \Code{rand int} or \Code{rand real} distribution
with non-negative support can be specified.}
\DEVELOPER{We need to be explicit about what can be used for \Code{f}$i$.}
\DEVELOPER{The value \Code{const(infinity)}
can be specified for the distribution of the firing time.
This effectively causes the transition not to fire without being disabled.
TRUE???}

\item
\Code{weight(trans:real~t1:r1,~trans:real~t2:r2,~...);}\\
Sets the firing weight for transition \Code{t}$i$ to the value of the
(possibly marking-dependent) \Code{real} expression \Code{r}$i$,
which must evaluate to a positive and finite value in any marking
where the transition is enabled.
Internally, {\smart} normalizes weights so that they sum to one.
For example, \Code{weight(t:1,u:1,v:2)} specifies that transitions
\Code{t}, \Code{u}, and \Code{v}, have firing probability proportional
to one, one and two, respectively, when any subset of them attempts
to fire at the same time.
An error occurs if a transition has weight zero.

Each call to \Code{weight} defines a new ``weight class'',
a transition can appear at most in one class,
and weights are meaningful only within a class.
If a transition does not appear in any class, it is assumed to be in a class
by itself with a weight of one.

Weights are meaningful only within a class.  A ``stochastic
confusion'' arises if two transitions in different classes can fire at
the same time, and the choice of which one to fire first affects the
measures \cite{1996MASCOTS-StochasticConfusion}.
{\smart} issues an error whenever
it detects a stochastic confusion while generating the state space.
The model must then be corrected by modifying the enabling of the
interested transitions or their weight class specification.

\DEVELOPER{
\item
\Code{void~restart(trans:bool~t1:b1,~trans:bool~t2:b2,~...);}\\
Sets the enabling policy of transition \Code{t}$i$ to the
(normally marking-dependent) boolean \Code{b}$i$.
The default policy for a transition \Code{t} is \Code{disabled(t)},
that is, the firing time of a transition is restarted whenever it becomes
disabled by the firing of some other transition.
To specify that \Code{t} is ``restarted'' \cite{1993PNPM-DSPNs}
only when \Code{u} or \Code{v} fire, use the entry
\Code{t:(fires(u)|fires(v))}.
To specify a ``continue'' \cite{1993PNPM-DSPNs},
or ``age enabling'' \cite{Ajmone1989a}, behavior, for \Code{t}, use
the entry \Code{t:false}.
When transition \Code{t} itself fires, its firing time is always restarted,
so it is not necessary to explicitly add the condition \Code{fires(t)}
to the enabling policy of transition \Code{t}.
Of course, for memoryless distributions (exponential, geometric with unit
step in a \Code{pn} having an underlying discrete-time Markov chain,
or deterministically equal zero, i.e., immediate),
the enabling policy is irrelevant.
}

\item
\Code{void assert(proc bool b1, proc bool b2, ...);}\\
Defines a set of (usually) marking-dependent \Code{bool} expressions,
or ``assertions'', which must be true in each marking.
If, at any point in the execution, assertion \Code{b}$i$ does not hold,
{\smart} issues an error message and exits.

This is particularly useful to debug a model when using explicit state-space
exploration techniques.

\item
\Code{{place}~places();}\\
Returns the set of places of the current model
(allowed inside a \Code{pn} block).

\item
\Code{{trans}~transitions();}\\
Returns the set of transitions of the current model
(allowed inside a \Code{pn} block).

\end{itemize}

\IGNORE{
Thus, the preselection priority relation must be acyclic:
\Code{prio(t:u,u:t)} is illegal.}
\IGNORE{
More subtle errors can arise as well.
For example, an arc \Code{p:t:if(enabled(u),0,1)} becomes illegal if
used in conjunction with a preselection priority \Code{t:u}, since to
determine whether \Code{t} is enabled we need to know the cardinality
of its input arc from \Code{p}, which is zero if \Code{u} is enabled, one
otherwise.
But, to determine whether \Code{u} is enabled, we need to know
whether \Code{t} itself is enabled, since \Code{t} has preselection priority
over \Code{u}.
}
\IGNORE{
I don't think this is done yet...
{\smart} takes particular care to check against any type of cyclic
dependency, hence a {\smart} language file is guaranteed to be semantically
well-defined if it compiles without errors.
}

\IGNORE{
The process underlying the \Code{ctmcSpn} \Code{cs1} remains a
continuous-time Markov chain even if,
instead of \Code{expo}, we use more complex predefined
phase-type distributions, such as \Code{erlang}, \Code{hypo}, \Code{hyper}
for the specification of one or more firing times.
We can even recall our continuous-time Markov chain \Code{c1}
defined in Section \ref{SEC:CTMC}
and set the distribution of the firing time of a transition in a
stochastic Petri net to the time to absorption of \Code{c1}.
For example, we could change the rate of transition \Code{v}
in the call of \Code{firing} for the stochastic Petri net \Code{cs1} to
\begin{lstlisting}
v:tta(c1(tk(p)*0.0004))
\end{lstlisting}

An exactly analogous discussion applies to discrete-time Markov chains
and stochastic Petri nets whose underlying process is a discrete-time
Markov chain: any DDP distribution can be used for the firing time of
the transitions \cite{1995StewartBook-DiscreteSPN}.
}

\end{developer}